Run the cline extension as a standalone process outside of vscode. (#3535)

* Add standalone cline server.

Add directory standalone/ with the scripts to generate
a cline instance that runs a gRPC service for the proto bus.

* Rm unused dependencies

* Build standalone extension

Build stubs for the whole vscode SDK.

Import extension.js instead of putting everything in one file.

Move all the files the extension needs at runtime in files/
  Use local packages for vscode and stub-utils instead of module alias.
  Move vscode-impls into the vscode module.
  Create separate package.json for the standalone extension in files/.

* Handlers for gRPC requests

Add code to the bottom of extension.js to export the gRPC handlers.
Add a wrapper to the handlers to catch and log extensions, otherwise the whole server process fails.
Fix use of open module.

* Standalone gRPC server

Export handers from the extension.
Add reflection and healthcheck to the server.
Add vscode launch file for standalone server.

* Fix formatting

* Better error handling in the server template.

Exit if the server could not bind to the port.
Use internal error code if exception is thrown.

* Formatting

* Stop using google-protobuf npm module to generate JS for protos

The code generated by google-protobuf cannot serialize protos from plain objects. It needs the protos to be class instances created with ProtoExample.create().
But, the protos created in the extension are just POJOs.
Use protoLoader instead which is fine with plain objects.
Protoloader is also the method used in the grpc JS documentation: https://grpc.io/docs/languages/node/basics/#loading-service-descriptors-from-proto-files

* Rm proto that was removed in cline/cline

* Rm old protos when building standalone extension.

* Log gRPC requests

* feat(standalone): implement TypeScript gRPC-based standalone extension

The major improvement is that the gRPC implementation is now written in TypeScript instead of JavaScript, and the standalone extension is compiled together with the original extension rather than using the compiled JS output. This provides full type safety throughout the codebase and prevents issues with the TypeScript compiler renaming handlers during compilation, making the system more robust and maintainable.

- Add new standalone implementation files in src/standalone/ directory using TypeScript
- Implement gRPC server setup in extension-standalone.ts with full type safety
- Generate server setup code with service registrations
- Update build script to support the new standalone architecture
- Reorganize runtime files from standalone/files/ to standalone/runtime-files/
- Replace template-based server generation with gRPC service registration

* Fix issues when doing clean build

Use correct build dir in esbuild.js
Remove undefined type.

* Add handler for gRPC methods with streaming response.

Add a handler-wrapper for rpc's with streaming responses.

Fix issue where grpc-js won't deserialize protos in camelcase. It is the default
for generated code for protos to use camelcase (keepCase: false), but I cannot find
where is being set for the proto serializations to keep the case. For now, just convert the
properties of the proto messages to snake case. This is not a good
solution, but trying to fix this is time sink.

* Formatting

* Add streaming response support to the script that generates setup-server.ts

Add types for the handlers.

* Formatting

* Fix case conversion for gRPC requset protos as well.

Convert snake case to camelcase for incoming request protos.

* formatting

* Improve build process / building for standalone extension

Add separate configs for the extension and the standalone in the esbuild config.
Modules that use __dirname to load files at runtime are marked as external in the build config.
Rename vscode-impls to vscode-context.
Remove unecessary files from the standalone runtime.

* Rename extension-standalone.js to standalone.js

* Move generate-server-setup script to protos dir.

Add the script the npm target `protos`, so it is run when the protos are regenerated.

* formatting

* Add a post build step for the npm run target `protos` to format the generated files.

* Move generate-server-setup to scripts directory

* Add a JS script to package the standalone build, replacing the shell script.

Add a post build step for the standalone target that:
    * copies the vscode module files into the output directory.
    * checks that native modules are not included in the output
    * creates a zip of the build.

* Rm files that were included from merge by mistake

* Move scripts from standalone in scripts directory

Remove unused package.json files from standalone/

* Update scripts and launch.json to use correct paths

* During build install external modules in the dist directory.

Add package.json for the distribution.
Set the node path for the vscode launch config.
Make the prettier silent during `npm run protos`

* Fix ellipsis suggestions
This commit is contained in:
Sarah Fortune 2025-05-15 20:04:46 +01:00 committed by GitHub
parent cd1ff2ad25
commit 8c565b5a7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 3913 additions and 99 deletions

2
.gitignore vendored
View File

@ -19,4 +19,4 @@ coverage
# But don't ignore the coverage scripts in .github/scripts/
!.github/scripts/coverage/
*evals.env
*evals.env

17
.vscode/launch.json vendored
View File

@ -38,6 +38,23 @@
"IS_DEV": "true",
"DEV_WORKSPACE_FOLDER": "${workspaceFolder}"
}
},
{
"type": "node",
"request": "launch",
"name": "Run Standalone Extension",
"skipFiles": ["<node_internals>/**"],
"sourceMaps": true,
"resolveSourceMapLocations": ["${workspaceFolder}/**", "!**/node_modules/**"],
"cwd": "${workspaceFolder}/dist-standalone",
"outFiles": ["${workspaceFolder}/dist-standalone/**/*.js"],
"preLaunchTask": "compile-standalone",
"env": {
"GRPC_TRACE": "all",
"GRPC_VERBOSITY": "DEBUG",
"NODE_PATH": "${workspaceFolder}/dist-standalone/node_modules"
},
"program": "standalone.js"
}
]
}

10
.vscode/tasks.json vendored
View File

@ -3,6 +3,16 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "compile-standalone",
"type": "npm",
"script": "compile-standalone",
"group": "build",
"problemMatcher": [],
"presentation": {
"reveal": "always"
}
},
{
"label": "npm: protos",
"type": "npm",

View File

@ -4,6 +4,8 @@ const path = require("path")
const production = process.argv.includes("--production")
const watch = process.argv.includes("--watch")
const standalone = process.argv.includes("--standalone")
const destDir = standalone ? "dist-standalone" : "dist"
/**
* @type {import('esbuild').Plugin}
@ -85,7 +87,7 @@ const copyWasmFiles = {
build.onEnd(() => {
// tree sitter
const sourceDir = path.join(__dirname, "node_modules", "web-tree-sitter")
const targetDir = path.join(__dirname, "dist")
const targetDir = path.join(__dirname, destDir)
// Copy tree-sitter.wasm
fs.copyFileSync(path.join(sourceDir, "tree-sitter.wasm"), path.join(targetDir, "tree-sitter.wasm"))
@ -117,7 +119,8 @@ const copyWasmFiles = {
},
}
const extensionConfig = {
// Base configuration shared between extension and standalone builds
const baseConfig = {
bundle: true,
minify: production,
sourcemap: !production,
@ -140,16 +143,32 @@ const extensionConfig = {
},
},
],
entryPoints: ["src/extension.ts"],
format: "cjs",
sourcesContent: false,
platform: "node",
outfile: "dist/extension.js",
}
// Extension-specific configuration
const extensionConfig = {
...baseConfig,
entryPoints: ["src/extension.ts"],
outfile: `${destDir}/extension.js`,
external: ["vscode"],
}
// Standalone-specific configuration
const standaloneConfig = {
...baseConfig,
entryPoints: ["src/standalone/standalone.ts"],
outfile: `${destDir}/standalone.js`,
// These gRPC protos need to load files from the module directory at runtime,
// so they cannot be bundled.
external: ["vscode", "@grpc/reflection", "grpc-health-check"],
}
async function main() {
const extensionCtx = await esbuild.context(extensionConfig)
const config = standalone ? standaloneConfig : extensionConfig
const extensionCtx = await esbuild.context(config)
if (watch) {
await extensionCtx.watch()
} else {

1122
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -242,11 +242,14 @@
"scripts": {
"vscode:prepublish": "npm run package",
"compile": "npm run check-types && npm run lint && node esbuild.js",
"compile-standalone": "npm run protos && npm run check-types && npm run lint && node esbuild.js --standalone",
"postcompile-standalone": "node scripts/package-standalone.mjs",
"watch": "npm-run-all -p watch:*",
"watch:esbuild": "node esbuild.js --watch",
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
"package": "npm run build:webview && npm run check-types && npm run lint && node esbuild.js --production",
"protos": "node proto/build-proto.js && prettier src/shared/proto src/core/controller webview-ui/src/services --write",
"protos": "node proto/build-proto.js && node scripts/generate-server-setup.mjs",
"postprotos": "prettier src/shared/proto src/core/controller webview-ui/src/services src/standalone/server-setup.ts --write --log-level silent",
"compile-tests": "node ./scripts/build-tests.js",
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "npm run compile-tests && npm run compile && npm run lint",
@ -318,6 +321,7 @@
"@google-cloud/vertexai": "^1.9.3",
"@google/genai": "^0.9.0",
"@grpc/grpc-js": "^1.9.15",
"@grpc/reflection": "^1.0.4",
"@mistralai/mistralai": "^1.5.0",
"@modelcontextprotocol/sdk": "^1.7.0",
"@opentelemetry/api": "^1.4.1",
@ -328,6 +332,7 @@
"@opentelemetry/semantic-conventions": "^1.30.0",
"@sentry/browser": "^9.12.0",
"@vscode/codicons": "^0.0.36",
"archiver": "^7.0.1",
"axios": "^1.8.2",
"cheerio": "^1.0.0",
"chokidar": "^4.0.1",
@ -341,6 +346,7 @@
"fzf": "^0.5.2",
"get-folder-size": "^5.0.0",
"globby": "^14.0.2",
"grpc-health-check": "^2.0.2",
"iconv-lite": "^0.6.3",
"ignore": "^7.0.3",
"image-size": "^2.0.2",
@ -349,6 +355,7 @@
"mammoth": "^1.8.0",
"monaco-vscode-textmate-theme-converter": "^0.1.7",
"ollama": "^0.5.13",
"open": "^10.1.2",
"open-graph-scraper": "^6.9.0",
"openai": "^4.83.0",
"os-name": "^6.0.0",
@ -362,6 +369,7 @@
"simple-git": "^3.27.0",
"strip-ansi": "^7.1.0",
"tree-sitter-wasms": "^0.1.11",
"ts-morph": "^25.0.1",
"turndown": "^7.2.0",
"web-tree-sitter": "^0.22.6",
"zod": "^3.24.2"

View File

@ -0,0 +1,79 @@
import * as fs from "fs"
import * as grpc from "@grpc/grpc-js"
import * as protoLoader from "@grpc/proto-loader"
import * as health from "grpc-health-check"
import { fileURLToPath } from "url"
import path from "path"
const OUT_FILE = path.resolve("src/standalone/server-setup.ts")
const DESCRIPTOR_SET = path.resolve("dist-standalone/proto/descriptor_set.pb")
// Load service definitions.
const clineDef = protoLoader.loadFileDescriptorSetFromBuffer(fs.readFileSync(DESCRIPTOR_SET))
const healthDef = protoLoader.loadSync(health.protoPath)
const packageDefinition = { ...clineDef, ...healthDef }
const proto = grpc.loadPackageDefinition(packageDefinition)
/**
* Generate imports and function to add all the handlers to the server for all services defined in the proto files.
*/
function generateHandlersAndExports() {
let imports = []
let handlerSetup = []
for (const [name, def] of Object.entries(proto.cline)) {
if (!def || !("service" in def)) {
continue
}
const domain = name.replace(/Service$/, "")
const dir = domain.charAt(0).toLowerCase() + domain.slice(1)
imports.push(`// ${domain} Service`)
handlerSetup.push(` // ${domain} Service`)
handlerSetup.push(` server.addService(proto.cline.${name}.service, {`)
for (const [rpcName, rpc] of Object.entries(def.service)) {
imports.push(`import { ${rpcName} } from "../core/controller/${dir}/${rpcName}"`)
if (rpc.requestStream) {
throw new Error("Request streaming is not supported")
}
if (rpc.responseStream) {
handlerSetup.push(` ${rpcName}: wrapStreamingResponse(${rpcName}, controller),`)
} else {
handlerSetup.push(` ${rpcName}: wrapper(${rpcName}, controller),`)
}
}
handlerSetup.push(` });`)
imports.push("")
handlerSetup.push("")
}
return {
imports: imports.join("\n"),
handlerSetup: handlerSetup.join("\n"),
}
}
const { imports, handlerSetup } = generateHandlersAndExports()
const scriptName = path.basename(fileURLToPath(import.meta.url))
// Create output file
let output = `// GENERATED CODE -- DO NOT EDIT!
// Generated by ${scriptName}
import * as grpc from "@grpc/grpc-js"
import { Controller } from "../core/controller"
import { GrpcHandlerWrapper, GrpcStreamingResponseHandlerWrapper } from "./grpc-types"
${imports}
export function addServices(
server: grpc.Server,
proto: any,
controller: Controller,
wrapper: GrpcHandlerWrapper,
wrapStreamingResponse: GrpcStreamingResponseHandlerWrapper,
): void {
${handlerSetup}
}
`
// Write output file
fs.writeFileSync(OUT_FILE, output)
console.log(`Generated service handlers in ${OUT_FILE}.`)

96
scripts/generate-stubs.js Normal file
View File

@ -0,0 +1,96 @@
const fs = require("fs")
const path = require("path")
const { Project, SyntaxKind } = require("ts-morph")
function traverse(container, output, prefix = "") {
for (const node of container.getStatements()) {
const kind = node.getKind()
if (kind === SyntaxKind.ModuleDeclaration) {
const name = node.getName().replace(/^['"]|['"]$/g, "")
var fullPrefix
if (prefix) {
fullPrefix = `${prefix}.${name}`
} else {
fullPrefix = name
}
output.push(`${fullPrefix} = {};`)
const body = node.getBody()
if (body && body.getKind() === SyntaxKind.ModuleBlock) {
traverse(body, output, fullPrefix)
}
} else if (kind === SyntaxKind.FunctionDeclaration) {
const name = node.getName()
const params = node.getParameters().map((p, i) => sanitizeParam(p.getName(), i))
const typeNode = node.getReturnTypeNode()
const returnType = typeNode ? typeNode.getText() : ""
const ret = mapReturn(returnType)
output.push(
`${prefix}.${name} = function(${params.join(", ")}) { console.log('Called stubbed function: ${prefix}.${name}'); ${ret} };`,
)
} else if (kind === SyntaxKind.EnumDeclaration) {
const name = node.getName()
const members = node.getMembers().map((m) => m.getName())
output.push(`${prefix}.${name} = { ${members.map((m) => `${m}: 0`).join(", ")} };`)
} else if (kind === SyntaxKind.VariableStatement) {
for (const decl of node.getDeclarations()) {
const name = decl.getName()
output.push(`${prefix}.${name} = createStub("${prefix}.${name}");`)
}
} else if (kind == SyntaxKind.ClassDeclaration) {
const name = node.getName()
output.push(
`${prefix}.${name} = class { constructor(...args) {
console.log('Constructed stubbed class: new ${prefix}.${name}(', args, ')');
return createStub(${prefix}.${name});
}};`,
)
} else if (kind === SyntaxKind.TypeAliasDeclaration || kind === SyntaxKind.InterfaceDeclaration) {
//console.log("Skipping", SyntaxKind[kind], node.getName())
// Skip interfaces and type aliases because they are only used at compile time by typescript.
} else {
console.log("Can't handle: ", SyntaxKind[kind])
}
}
}
function mapReturn(typeStr) {
if (!typeStr) return ""
if (typeStr.includes("void")) return ""
if (typeStr.includes("string")) return `return '';`
if (typeStr.includes("number")) return `return 0;`
if (typeStr.includes("boolean")) return `return false;`
if (typeStr.includes("[]")) return `return [];`
if (typeStr.includes("Thenable")) return `return Promise.resolve(null);`
return `return createStub("unknown");`
}
function sanitizeParam(name, index) {
return name || `arg${index}`
}
async function main() {
const inputPath = "node_modules/@types/vscode/index.d.ts"
const outputPath = "standalone/runtime-files/vscode/vscode-stubs.js"
const project = new Project()
const sourceFile = project.addSourceFileAtPath(inputPath)
const output = []
output.push("// GENERATED CODE -- DO NOT EDIT!")
output.push('console.log("Loading stubs...");')
output.push('const { createStub } = require("./stub-utils")')
traverse(sourceFile, output)
output.push("module.exports = vscode;")
output.push('console.log("Finished loading stubs");')
fs.mkdirSync(path.dirname(outputPath), { recursive: true })
fs.writeFileSync(outputPath, output.join("\n"))
console.log(`Wrote vscode SDK stubs to ${outputPath}`)
}
main().catch((err) => {
console.error(err)
process.exit(1)
})

18
scripts/get-vscode-usages.sh Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -eu
DIR=${1:-src/}
DEST_DIR=dist-standalone
DEST=dist-standalone/vscode-uses.txt
mkdir -p $DEST_DIR
{
git grep -h 'vscode\.' $DIR |
grep -Ev '//.*vscode' | # remove commented out code
sed 's|.*vscode\.|vscode.|'| # remove everything before vscode.
sed 's/[^a-zA-Z0-9_.].*$//' | # remove everything after last identifier
sort | uniq > $DEST
}
echo Done, wrote uses of the vscode SDK to $(realpath $DEST)

View File

@ -0,0 +1,51 @@
import fs from "fs"
import path from "path"
import { glob } from "glob"
import archiver from "archiver"
import { cp } from "fs/promises"
import { execSync } from "child_process"
const BUILD_DIR = "dist-standalone"
const SOURCE_DIR = "standalone/runtime-files"
await cp(SOURCE_DIR, BUILD_DIR, { recursive: true })
// Run npm install in the distribution directory
console.log("Running npm install in distribution directory...")
const cwd = process.cwd()
process.chdir(BUILD_DIR)
try {
execSync("npm install", { stdio: "inherit" })
} catch (error) {
console.error("Error running npm install:", error)
process.exit(1)
} finally {
process.chdir(cwd)
}
// Check for native .node modules.
const nativeModules = await glob("**/*.node", { cwd: BUILD_DIR, nodir: true })
if (nativeModules.length > 0) {
console.error("Native node modules cannot be included in the standalone distribution:\n", nativeModules.join("\n"))
process.exit(1)
}
// Zip the build directory (excluding any pre-existing output zip).
const zipPath = path.join(BUILD_DIR, "standalone.zip")
const output = fs.createWriteStream(zipPath)
const archive = archiver("zip", { zlib: { level: 9 } })
output.on("close", () => {
console.log(`Created ${zipPath} (${archive.pointer()} bytes)`)
})
archive.on("error", (err) => {
throw err
})
archive.pipe(output)
archive.glob("**/*", {
cwd: BUILD_DIR,
ignore: ["standalone.zip"],
})
await archive.finalize()

View File

@ -0,0 +1,38 @@
import * as grpc from "@grpc/grpc-js"
import { Controller } from "../core/controller"
/**
* Type definition for a gRPC handler function.
* This represents a function that takes a Controller instance and a request object,
* and returns a Promise of the response type.
*
* @template TRequest - The type of the request object
* @template TResponse - The type of the response object
*/
export type GrpcHandler<TRequest, TResponse> = (controller: Controller, req: TRequest) => Promise<TResponse>
export type GrpcStreamingResponseHandler<TRequest, TResponse> = (
controller: Controller,
req: TRequest,
streamResponseHandler: StreamingResponseWriter<TResponse>,
requestId?: string,
) => Promise<TResponse>
/**
* Type definition for the wrapper function that converts a Promise-based handler
* to a gRPC callback-style handler.
*
* @template TRequest - The type of the request object
* @template TResponse - The type of the response object
*/
export type GrpcHandlerWrapper = <TRequest, TResponse>(
handler: GrpcHandler<TRequest, TResponse>,
controller: Controller,
) => grpc.handleUnaryCall<TRequest, TResponse>
export type GrpcStreamingResponseHandlerWrapper = <TRequest, TResponse>(
handler: GrpcStreamingResponseHandler<TRequest, TResponse>,
controller: Controller,
) => grpc.handleServerStreamingCall<TRequest, TResponse>
export type StreamingResponseWriter<TResponse> = (response: TResponse, isLast?: boolean, sequenceNumber?: number) => Promise<void>

View File

@ -0,0 +1,153 @@
// GENERATED CODE -- DO NOT EDIT!
// Generated by generate-server-setup.mjs
import * as grpc from "@grpc/grpc-js"
import { Controller } from "../core/controller"
import { GrpcHandlerWrapper, GrpcStreamingResponseHandlerWrapper } from "./grpc-types"
// Account Service
import { accountLoginClicked } from "../core/controller/account/accountLoginClicked"
// Browser Service
import { getBrowserConnectionInfo } from "../core/controller/browser/getBrowserConnectionInfo"
import { testBrowserConnection } from "../core/controller/browser/testBrowserConnection"
import { discoverBrowser } from "../core/controller/browser/discoverBrowser"
import { getDetectedChromePath } from "../core/controller/browser/getDetectedChromePath"
import { updateBrowserSettings } from "../core/controller/browser/updateBrowserSettings"
// Checkpoints Service
import { checkpointDiff } from "../core/controller/checkpoints/checkpointDiff"
import { checkpointRestore } from "../core/controller/checkpoints/checkpointRestore"
// File Service
import { openFile } from "../core/controller/file/openFile"
import { openImage } from "../core/controller/file/openImage"
import { deleteRuleFile } from "../core/controller/file/deleteRuleFile"
import { createRuleFile } from "../core/controller/file/createRuleFile"
import { searchCommits } from "../core/controller/file/searchCommits"
import { getRelativePaths } from "../core/controller/file/getRelativePaths"
import { searchFiles } from "../core/controller/file/searchFiles"
// Mcp Service
import { toggleMcpServer } from "../core/controller/mcp/toggleMcpServer"
import { updateMcpTimeout } from "../core/controller/mcp/updateMcpTimeout"
import { addRemoteMcpServer } from "../core/controller/mcp/addRemoteMcpServer"
import { downloadMcp } from "../core/controller/mcp/downloadMcp"
// Models Service
import { getOllamaModels } from "../core/controller/models/getOllamaModels"
import { getLmStudioModels } from "../core/controller/models/getLmStudioModels"
import { getVsCodeLmModels } from "../core/controller/models/getVsCodeLmModels"
import { refreshOpenRouterModels } from "../core/controller/models/refreshOpenRouterModels"
import { refreshOpenAiModels } from "../core/controller/models/refreshOpenAiModels"
import { refreshRequestyModels } from "../core/controller/models/refreshRequestyModels"
// Slash Service
import { reportBug } from "../core/controller/slash/reportBug"
import { condense } from "../core/controller/slash/condense"
// State Service
import { getLatestState } from "../core/controller/state/getLatestState"
import { subscribeToState } from "../core/controller/state/subscribeToState"
import { toggleFavoriteModel } from "../core/controller/state/toggleFavoriteModel"
// Task Service
import { cancelTask } from "../core/controller/task/cancelTask"
import { clearTask } from "../core/controller/task/clearTask"
import { deleteTasksWithIds } from "../core/controller/task/deleteTasksWithIds"
import { newTask } from "../core/controller/task/newTask"
import { showTaskWithId } from "../core/controller/task/showTaskWithId"
import { exportTaskWithId } from "../core/controller/task/exportTaskWithId"
import { toggleTaskFavorite } from "../core/controller/task/toggleTaskFavorite"
import { deleteNonFavoritedTasks } from "../core/controller/task/deleteNonFavoritedTasks"
import { getTaskHistory } from "../core/controller/task/getTaskHistory"
// Web Service
import { checkIsImageUrl } from "../core/controller/web/checkIsImageUrl"
export function addServices(
server: grpc.Server,
proto: any,
controller: Controller,
wrapper: GrpcHandlerWrapper,
wrapStreamingResponse: GrpcStreamingResponseHandlerWrapper,
): void {
// Account Service
server.addService(proto.cline.AccountService.service, {
accountLoginClicked: wrapper(accountLoginClicked, controller),
})
// Browser Service
server.addService(proto.cline.BrowserService.service, {
getBrowserConnectionInfo: wrapper(getBrowserConnectionInfo, controller),
testBrowserConnection: wrapper(testBrowserConnection, controller),
discoverBrowser: wrapper(discoverBrowser, controller),
getDetectedChromePath: wrapper(getDetectedChromePath, controller),
updateBrowserSettings: wrapper(updateBrowserSettings, controller),
})
// Checkpoints Service
server.addService(proto.cline.CheckpointsService.service, {
checkpointDiff: wrapper(checkpointDiff, controller),
checkpointRestore: wrapper(checkpointRestore, controller),
})
// File Service
server.addService(proto.cline.FileService.service, {
openFile: wrapper(openFile, controller),
openImage: wrapper(openImage, controller),
deleteRuleFile: wrapper(deleteRuleFile, controller),
createRuleFile: wrapper(createRuleFile, controller),
searchCommits: wrapper(searchCommits, controller),
getRelativePaths: wrapper(getRelativePaths, controller),
searchFiles: wrapper(searchFiles, controller),
})
// Mcp Service
server.addService(proto.cline.McpService.service, {
toggleMcpServer: wrapper(toggleMcpServer, controller),
updateMcpTimeout: wrapper(updateMcpTimeout, controller),
addRemoteMcpServer: wrapper(addRemoteMcpServer, controller),
downloadMcp: wrapper(downloadMcp, controller),
})
// Models Service
server.addService(proto.cline.ModelsService.service, {
getOllamaModels: wrapper(getOllamaModels, controller),
getLmStudioModels: wrapper(getLmStudioModels, controller),
getVsCodeLmModels: wrapper(getVsCodeLmModels, controller),
refreshOpenRouterModels: wrapper(refreshOpenRouterModels, controller),
refreshOpenAiModels: wrapper(refreshOpenAiModels, controller),
refreshRequestyModels: wrapper(refreshRequestyModels, controller),
})
// Slash Service
server.addService(proto.cline.SlashService.service, {
reportBug: wrapper(reportBug, controller),
condense: wrapper(condense, controller),
})
// State Service
server.addService(proto.cline.StateService.service, {
getLatestState: wrapper(getLatestState, controller),
subscribeToState: wrapStreamingResponse(subscribeToState, controller),
toggleFavoriteModel: wrapper(toggleFavoriteModel, controller),
})
// Task Service
server.addService(proto.cline.TaskService.service, {
cancelTask: wrapper(cancelTask, controller),
clearTask: wrapper(clearTask, controller),
deleteTasksWithIds: wrapper(deleteTasksWithIds, controller),
newTask: wrapper(newTask, controller),
showTaskWithId: wrapper(showTaskWithId, controller),
exportTaskWithId: wrapper(exportTaskWithId, controller),
toggleTaskFavorite: wrapper(toggleTaskFavorite, controller),
deleteNonFavoritedTasks: wrapper(deleteNonFavoritedTasks, controller),
getTaskHistory: wrapper(getTaskHistory, controller),
})
// Web Service
server.addService(proto.cline.WebService.service, {
checkIsImageUrl: wrapper(checkIsImageUrl, controller),
})
}

View File

@ -0,0 +1,111 @@
import * as grpc from "@grpc/grpc-js"
import { ReflectionService } from "@grpc/reflection"
import * as health from "grpc-health-check"
import { activate } from "../extension"
import { Controller } from "../core/controller"
import { extensionContext, outputChannel, postMessage } from "./vscode-context"
import { packageDefinition, proto, log, camelToSnakeCase, snakeToCamelCase } from "./utils"
import { GrpcHandler, GrpcStreamingResponseHandler } from "./grpc-types"
import { addServices } from "./server-setup"
import { StreamingResponseHandler } from "@/core/controller/grpc-handler"
function main() {
log("Starting service...")
activate(extensionContext)
const controller = new Controller(extensionContext, outputChannel, postMessage)
const server = new grpc.Server()
// Set up health check.
const healthImpl = new health.HealthImplementation({ "": "SERVING" })
healthImpl.addToServer(server)
// Add all the handlers for the ProtoBus services to the server.
addServices(server, proto, controller, wrapHandler, wrapStreamingResponseHandler)
// Set up reflection.
const reflection = new ReflectionService(packageDefinition)
reflection.addToServer(server)
// Start the server.
const host = "127.0.0.1:50051"
server.bindAsync(host, grpc.ServerCredentials.createInsecure(), (err) => {
if (err) {
log(`Error: Failed to bind to ${host}, port may be unavailable ${err.message}`)
process.exit(1)
} else {
server.start()
log(`gRPC server listening on ${host}`)
}
})
}
/**
* Wraps a Promise-based handler function to make it compatible with gRPC's callback-based API.
* This function converts an async handler that returns a Promise into a function that uses
* the gRPC callback pattern.
*
* @template TRequest - The type of the request object
* @template TResponse - The type of the response object
* @param handler - The Promise-based handler function to wrap
* @param controllerInstance - The controller instance to pass to the handler
* @returns A gRPC-compatible callback-style handler function
*/
function wrapHandler<TRequest, TResponse>(
handler: GrpcHandler<TRequest, TResponse>,
controller: Controller,
): grpc.handleUnaryCall<TRequest, TResponse> {
return async (call: grpc.ServerUnaryCall<TRequest, TResponse>, callback: grpc.sendUnaryData<TResponse>) => {
try {
log(`gRPC request: ${call.getPath()}`)
const result = await handler(controller, snakeToCamelCase(call.request))
// The grpc-js serializer expects the proto message to be in the same
// case as the proto file. This is a work around until we find a solution.
callback(null, camelToSnakeCase(result))
} catch (err: any) {
log(`gRPC handler error: ${call.getPath()}\n${err.stack}`)
callback({
code: grpc.status.INTERNAL,
message: err.message || "Internal error",
} as grpc.ServiceError)
}
}
}
function wrapStreamingResponseHandler<TRequest, TResponse>(
handler: GrpcStreamingResponseHandler<TRequest, TResponse>,
controller: Controller,
): grpc.handleServerStreamingCall<TRequest, TResponse> {
return async (call: grpc.ServerWritableStream<TRequest, TResponse>) => {
try {
const requestId = call.metadata.get("request-id").pop()?.toString()
log(`gRPC streaming request: ${call.getPath()}`)
const responseHandler: StreamingResponseHandler = (response, isLast, sequenceNumber) => {
try {
// The grpc-js serializer expects the proto message to be in the same
// case as the proto file. This is a work around until we find a solution.
call.write(camelToSnakeCase(response)) // Use a bound version of call.write to maintain proper 'this' context
if (isLast === true) {
log(`Closing stream for ${requestId}`)
call.end()
}
return Promise.resolve()
} catch (error) {
return Promise.reject(error)
}
}
await handler(controller, snakeToCamelCase(call.request), responseHandler, requestId)
} catch (err: any) {
log(`gRPC handler error: ${call.getPath()}\n${err.stack}`)
call.destroy({
code: grpc.status.INTERNAL,
message: err.message || "Internal error",
} as grpc.ServiceError)
}
}
}
main()

65
src/standalone/utils.ts Normal file
View File

@ -0,0 +1,65 @@
import * as fs from "fs"
import * as grpc from "@grpc/grpc-js"
import * as protoLoader from "@grpc/proto-loader"
import * as health from "grpc-health-check"
const log = (...args: unknown[]) => {
const timestamp = new Date().toISOString()
console.log(`[${timestamp}]`, "#bot.cline.server.ts", ...args)
}
// Load service definitions.
const descriptorSet = fs.readFileSync("proto/descriptor_set.pb")
const clineDef = protoLoader.loadFileDescriptorSetFromBuffer(descriptorSet)
const healthDef = protoLoader.loadSync(health.protoPath)
const packageDefinition = { ...clineDef, ...healthDef }
const proto = grpc.loadPackageDefinition(packageDefinition) as unknown
// Helper function to convert camelCase to snake_case
function camelToSnakeCase(obj: any): any {
if (obj === null || typeof obj !== "object") {
return obj
}
if (Array.isArray(obj)) {
return obj.map(camelToSnakeCase)
}
return Object.keys(obj).reduce((acc: any, key: string) => {
// Convert key from camelCase to snake_case
const snakeKey = key
.replace(/([A-Z])/g, "_$1")
.replace(/^_+/, "")
.toLowerCase()
// Convert value recursively if it's an object
const value = obj[key]
acc[snakeKey] = camelToSnakeCase(value)
return acc
}, {})
}
// Helper function to convert snake_case to camelCase
function snakeToCamelCase(obj: any): any {
if (obj === null || typeof obj !== "object") {
return obj
}
if (Array.isArray(obj)) {
return obj.map(snakeToCamelCase)
}
return Object.keys(obj).reduce((acc: any, key: string) => {
// Convert key from snake_case to camelCase
const camelKey = key.replace(/_([a-z0-9])/g, (_, char) => char.toUpperCase())
// Convert value recursively if it's an object
const value = obj[key]
acc[camelKey] = snakeToCamelCase(value)
return acc
}, {})
}
export { packageDefinition, proto, log, camelToSnakeCase, snakeToCamelCase }

View File

@ -0,0 +1,164 @@
// @ts-nocheck
import * as vscode from "vscode"
import open from "open"
import { log } from "./utils"
function stubUri(path: string): vscode.Uri {
console.log(`Using file path: ${path}`)
return {
fsPath: path,
scheme: "",
authority: "",
path: "",
query: "",
fragment: "",
with: function (change: {
scheme?: string
authority?: string
path?: string
query?: string
fragment?: string
}): vscode.Uri {
return stubUri(path)
},
toString: function (skipEncoding?: boolean): string {
return path
},
toJSON: function () {
return {}
},
}
}
function createMemento(): vscode.Memento {
const store = {}
return {
keys: function (): readonly string[] {
return Object.keys(store)
},
get: function <T>(key: string): T | undefined {
return key in store ? store[key] : undefined
},
update: function (key: string, value: any): Thenable<void> {
store[key] = value
return Promise.resolve()
},
}
}
const extensionContext: vscode.ExtensionContext = {
extensionPath: "/tmp/vscode/extension",
extensionUri: stubUri("/tmp/vscode/extension"),
globalStoragePath: "/tmp/vscode/global",
globalStorageUri: stubUri("/tmp/vscode/global"),
storagePath: "/tmp/vscode/storage",
storageUri: stubUri("/tmp/vscode/storage"),
logPath: "/tmp/vscode/log",
logUri: stubUri("/tmp/vscode/log"),
globalState: createMemento(),
workspaceState: createMemento(),
storageState: createMemento(),
environmentVariableCollection: {
getScoped: function (scope: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableCollection {
return {
persistent: false,
description: undefined,
replace: function (variable: string, value: string, options?: vscode.EnvironmentVariableMutatorOptions): void {},
append: function (variable: string, value: string, options?: vscode.EnvironmentVariableMutatorOptions): void {},
prepend: function (variable: string, value: string, options?: vscode.EnvironmentVariableMutatorOptions): void {},
get: function (variable: string): vscode.EnvironmentVariableMutator | undefined {
return undefined
},
forEach: function (
callback: (
variable: string,
mutator: vscode.EnvironmentVariableMutator,
collection: vscode.EnvironmentVariableCollection,
) => any,
thisArg?: any,
): void {},
delete: function (variable: string): void {},
clear: function (): void {},
[Symbol.iterator]: function (): Iterator<
[variable: string, mutator: vscode.EnvironmentVariableMutator],
any,
any
> {
throw new Error("environmentVariableCollection.getScoped.Iterator not implemented")
},
}
},
persistent: false,
description: undefined,
replace: function (variable: string, value: string, options?: vscode.EnvironmentVariableMutatorOptions): void {},
append: function (variable: string, value: string, options?: vscode.EnvironmentVariableMutatorOptions): void {},
prepend: function (variable: string, value: string, options?: vscode.EnvironmentVariableMutatorOptions): void {},
get: function (variable: string): vscode.EnvironmentVariableMutator | undefined {
return undefined
},
forEach: function (
callback: (
variable: string,
mutator: vscode.EnvironmentVariableMutator,
collection: vscode.EnvironmentVariableCollection,
) => any,
thisArg?: any,
): void {
throw new Error("environmentVariableCollection.forEach not implemented")
},
delete: function (variable: string): void {},
clear: function (): void {},
[Symbol.iterator]: function (): Iterator<[variable: string, mutator: vscode.EnvironmentVariableMutator], any, any> {
throw new Error("environmentVariableCollection.Iterator not implemented")
},
},
extensionMode: 1, // Development
extension: {
id: "your.extension.id",
isActive: true,
extensionPath: "/tmp/vscode/extension",
extensionUri: stubUri("/tmp/vscode/extension"),
packageJSON: {},
exports: {},
activate: async () => {},
extensionKind: vscode.ExtensionKind.UI,
},
subscriptions: [],
asAbsolutePath: (relPath) => `/tmp/vscode/extension/${relPath}`,
secrets: {
store: async () => {},
get: async () => undefined,
delete: async () => {},
onDidChange: {},
},
}
const outputChannel: vscode.OutputChannel = {
append: (text) => process.stdout.write(text),
appendLine: (line) => console.log(line),
clear: () => {},
show: () => {},
hide: () => {},
dispose: () => {},
name: "",
replace: function (value: string): void {},
}
function postMessage(message: ExtensionMessage): Promise<boolean> {
log("postMessage called:", message)
return Promise.resolve(true)
}
console.log("Finished loading vscode context...")
export { extensionContext, outputChannel, postMessage }

514
standalone/runtime-files/package-lock.json generated Normal file
View File

@ -0,0 +1,514 @@
{
"name": "Cline standalone",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "Cline standalone",
"version": "1.0.0",
"dependencies": {
"@grpc/grpc-js": "^1.13.3",
"@grpc/reflection": "^1.0.4",
"grpc-health-check": "^2.0.2",
"open": "^10.1.2",
"vscode": "file:./vscode"
}
},
"node_modules/@grpc/grpc-js": {
"version": "1.13.3",
"resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.13.3.tgz",
"integrity": "sha512-FTXHdOoPbZrBjlVLHuKbDZnsTxXv2BlHF57xw6LuThXacXvtkahEPED0CKMk6obZDf65Hv4k3z62eyPNpvinIg==",
"license": "Apache-2.0",
"dependencies": {
"@grpc/proto-loader": "^0.7.13",
"@js-sdsl/ordered-map": "^4.4.2"
},
"engines": {
"node": ">=12.10.0"
}
},
"node_modules/@grpc/proto-loader": {
"version": "0.7.15",
"resolved": "https://registry.npmjs.org/@grpc/proto-loader/-/proto-loader-0.7.15.tgz",
"integrity": "sha512-tMXdRCfYVixjuFK+Hk0Q1s38gV9zDiDJfWL3h1rv4Qc39oILCu1TRTDt7+fGUI8K4G1Fj125Hx/ru3azECWTyQ==",
"license": "Apache-2.0",
"dependencies": {
"lodash.camelcase": "^4.3.0",
"long": "^5.0.0",
"protobufjs": "^7.2.5",
"yargs": "^17.7.2"
},
"bin": {
"proto-loader-gen-types": "build/bin/proto-loader-gen-types.js"
},
"engines": {
"node": ">=6"
}
},
"node_modules/@grpc/reflection": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@grpc/reflection/-/reflection-1.0.4.tgz",
"integrity": "sha512-znA8v4AviOD3OPOxy11pxrtP8k8DanpefeTymS8iGW1fVr1U2cHuzfhYqDPHnVNDf4qvF9E25KtSihPy2DBWfQ==",
"license": "Apache-2.0",
"dependencies": {
"@grpc/proto-loader": "^0.7.13",
"protobufjs": "^7.2.5"
},
"peerDependencies": {
"@grpc/grpc-js": "^1.8.21"
}
},
"node_modules/@js-sdsl/ordered-map": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/@js-sdsl/ordered-map/-/ordered-map-4.4.2.tgz",
"integrity": "sha512-iUKgm52T8HOE/makSxjqoWhe95ZJA1/G1sYsGev2JDKUSS14KAgg1LHb+Ba+IPow0xflbnSkOsZcO08C7w1gYw==",
"license": "MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/js-sdsl"
}
},
"node_modules/@protobufjs/aspromise": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz",
"integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==",
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/base64": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz",
"integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==",
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/codegen": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.4.tgz",
"integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==",
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/eventemitter": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz",
"integrity": "sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==",
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/fetch": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.0.tgz",
"integrity": "sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==",
"license": "BSD-3-Clause",
"dependencies": {
"@protobufjs/aspromise": "^1.1.1",
"@protobufjs/inquire": "^1.1.0"
}
},
"node_modules/@protobufjs/float": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz",
"integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==",
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/inquire": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@protobufjs/inquire/-/inquire-1.1.0.tgz",
"integrity": "sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==",
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/path": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz",
"integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==",
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/pool": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz",
"integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==",
"license": "BSD-3-Clause"
},
"node_modules/@protobufjs/utf8": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz",
"integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==",
"license": "BSD-3-Clause"
},
"node_modules/@types/node": {
"version": "22.15.18",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.15.18.tgz",
"integrity": "sha512-v1DKRfUdyW+jJhZNEI1PYy29S2YRxMV5AOO/x/SjKmW0acCIOqmbj6Haf9eHAhsPmrhlHSxEhv/1WszcLWV4cg==",
"license": "MIT",
"dependencies": {
"undici-types": "~6.21.0"
}
},
"node_modules/ansi-regex": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"license": "MIT",
"dependencies": {
"color-convert": "^2.0.1"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/bundle-name": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/bundle-name/-/bundle-name-4.1.0.tgz",
"integrity": "sha512-tjwM5exMg6BGRI+kNmTntNsvdZS1X8BFYS6tnJ2hdH0kVxM6/eVZ2xy+FqStSWvYmtfFMDLIxurorHwDKfDz5Q==",
"license": "MIT",
"dependencies": {
"run-applescript": "^7.0.0"
},
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/cliui": {
"version": "8.0.1",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz",
"integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==",
"license": "ISC",
"dependencies": {
"string-width": "^4.2.0",
"strip-ansi": "^6.0.1",
"wrap-ansi": "^7.0.0"
},
"engines": {
"node": ">=12"
}
},
"node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"license": "MIT",
"dependencies": {
"color-name": "~1.1.4"
},
"engines": {
"node": ">=7.0.0"
}
},
"node_modules/color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"license": "MIT"
},
"node_modules/default-browser": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/default-browser/-/default-browser-5.2.1.tgz",
"integrity": "sha512-WY/3TUME0x3KPYdRRxEJJvXRHV4PyPoUsxtZa78lwItwRQRHhd2U9xOscaT/YTf8uCXIAjeJOFBVEh/7FtD8Xg==",
"license": "MIT",
"dependencies": {
"bundle-name": "^4.1.0",
"default-browser-id": "^5.0.0"
},
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/default-browser-id": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/default-browser-id/-/default-browser-id-5.0.0.tgz",
"integrity": "sha512-A6p/pu/6fyBcA1TRz/GqWYPViplrftcW2gZC9q79ngNCKAeR/X3gcEdXQHl4KNXV+3wgIJ1CPkJQ3IHM6lcsyA==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/define-lazy-prop": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-3.0.0.tgz",
"integrity": "sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg==",
"license": "MIT",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/emoji-regex": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
"license": "MIT"
},
"node_modules/escalade": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz",
"integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==",
"license": "MIT",
"engines": {
"node": ">=6"
}
},
"node_modules/get-caller-file": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
"integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==",
"license": "ISC",
"engines": {
"node": "6.* || 8.* || >= 10.*"
}
},
"node_modules/grpc-health-check": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/grpc-health-check/-/grpc-health-check-2.0.2.tgz",
"integrity": "sha512-5XKOdg/gIlTsZZR+8QJjzmW2CHBnn+NfM8zevIpzg+96i9dAuoH+Guu/L/5vuUkSbVZG69wVPnLpEnW+Smon1A==",
"license": "Apache-2.0",
"dependencies": {
"@grpc/proto-loader": "^0.7.13"
}
},
"node_modules/is-docker": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/is-docker/-/is-docker-3.0.0.tgz",
"integrity": "sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==",
"license": "MIT",
"bin": {
"is-docker": "cli.js"
},
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/is-fullwidth-code-point": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/is-inside-container": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-inside-container/-/is-inside-container-1.0.0.tgz",
"integrity": "sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA==",
"license": "MIT",
"dependencies": {
"is-docker": "^3.0.0"
},
"bin": {
"is-inside-container": "cli.js"
},
"engines": {
"node": ">=14.16"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/is-wsl": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-3.1.0.tgz",
"integrity": "sha512-UcVfVfaK4Sc4m7X3dUSoHoozQGBEFeDC+zVo06t98xe8CzHSZZBekNXH+tu0NalHolcJ/QAGqS46Hef7QXBIMw==",
"license": "MIT",
"dependencies": {
"is-inside-container": "^1.0.0"
},
"engines": {
"node": ">=16"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/lodash.camelcase": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz",
"integrity": "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==",
"license": "MIT"
},
"node_modules/long": {
"version": "5.3.2",
"resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz",
"integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==",
"license": "Apache-2.0"
},
"node_modules/open": {
"version": "10.1.2",
"resolved": "https://registry.npmjs.org/open/-/open-10.1.2.tgz",
"integrity": "sha512-cxN6aIDPz6rm8hbebcP7vrQNhvRcveZoJU72Y7vskh4oIm+BZwBECnx5nTmrlres1Qapvx27Qo1Auukpf8PKXw==",
"license": "MIT",
"dependencies": {
"default-browser": "^5.2.1",
"define-lazy-prop": "^3.0.0",
"is-inside-container": "^1.0.0",
"is-wsl": "^3.1.0"
},
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/protobufjs": {
"version": "7.5.2",
"resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.5.2.tgz",
"integrity": "sha512-f2ls6rpO6G153Cy+o2XQ+Y0sARLOZ17+OGVLHrc3VUKcLHYKEKWbkSujdBWQXM7gKn5NTfp0XnRPZn1MIu8n9w==",
"hasInstallScript": true,
"license": "BSD-3-Clause",
"dependencies": {
"@protobufjs/aspromise": "^1.1.2",
"@protobufjs/base64": "^1.1.2",
"@protobufjs/codegen": "^2.0.4",
"@protobufjs/eventemitter": "^1.1.0",
"@protobufjs/fetch": "^1.1.0",
"@protobufjs/float": "^1.0.2",
"@protobufjs/inquire": "^1.1.0",
"@protobufjs/path": "^1.1.2",
"@protobufjs/pool": "^1.1.0",
"@protobufjs/utf8": "^1.1.0",
"@types/node": ">=13.7.0",
"long": "^5.0.0"
},
"engines": {
"node": ">=12.0.0"
}
},
"node_modules/require-directory": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
"integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/run-applescript": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/run-applescript/-/run-applescript-7.0.0.tgz",
"integrity": "sha512-9by4Ij99JUr/MCFBUkDKLWK3G9HVXmabKz9U5MlIAIuvuzkiOicRYs8XJLxX+xahD+mLiiCYDqF9dKAgtzKP1A==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/string-width": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
"license": "MIT",
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/strip-ansi": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
"license": "MIT",
"dependencies": {
"ansi-regex": "^5.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/undici-types": {
"version": "6.21.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
"license": "MIT"
},
"node_modules/vscode": {
"resolved": "vscode",
"link": true
},
"node_modules/wrap-ansi": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
"integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
"license": "MIT",
"dependencies": {
"ansi-styles": "^4.0.0",
"string-width": "^4.1.0",
"strip-ansi": "^6.0.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
}
},
"node_modules/y18n": {
"version": "5.0.8",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
"integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==",
"license": "ISC",
"engines": {
"node": ">=10"
}
},
"node_modules/yargs": {
"version": "17.7.2",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",
"integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==",
"license": "MIT",
"dependencies": {
"cliui": "^8.0.1",
"escalade": "^3.1.1",
"get-caller-file": "^2.0.5",
"require-directory": "^2.1.1",
"string-width": "^4.2.3",
"y18n": "^5.0.5",
"yargs-parser": "^21.1.1"
},
"engines": {
"node": ">=12"
}
},
"node_modules/yargs-parser": {
"version": "21.1.1",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz",
"integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==",
"license": "ISC",
"engines": {
"node": ">=12"
}
},
"vscode": {
"version": "1.0.0"
}
}
}

View File

@ -0,0 +1,12 @@
{
"name": "Cline standalone",
"version": "1.0.0",
"main": "standalone.js",
"dependencies": {
"@grpc/grpc-js": "^1.13.3",
"@grpc/reflection": "^1.0.4",
"grpc-health-check": "^2.0.2",
"open": "^10.1.2",
"vscode": "file:./vscode"
}
}

View File

@ -0,0 +1,7 @@
const stubs = require("./vscode-stubs.js")
const impls = require("./vscode-impls.js")
module.exports = {
...stubs,
...impls,
}

View File

@ -0,0 +1,5 @@
{
"name": "vscode",
"version": "1.0.0",
"main": "index.js"
}

View File

@ -0,0 +1,19 @@
function createStub(path) {
return new Proxy(function () {}, {
get: (target, prop) => {
const fullPath = `${path}.${String(prop)}`
console.log(`Accessed stub: ${fullPath}`)
return createStub(fullPath)
},
apply: (target, thisArg, args) => {
console.log(`Called stub: ${path} with args:`, args)
return createStub(path)
},
construct: (target, args) => {
console.log(`Constructed stub: ${path} with args:`, args)
return createStub(path)
},
})
}
module.exports = { createStub }

View File

@ -0,0 +1,149 @@
console.log("Loading stub impls...")
const { createStub } = require("./stub-utils")
const open = require("open").default
vscode.window = {
showInformationMessage: (...args) => {
console.log("Stubbed showInformationMessage:", ...args)
return Promise.resolve(undefined)
},
showWarningMessage: (...args) => {
console.log("Stubbed showWarningMessage:", ...args)
return Promise.resolve(undefined)
},
showErrorMessage: (...args) => {
console.log("Stubbed showErrorMessage:", ...args)
return Promise.resolve(undefined)
},
showInputBox: async (options) => {
console.log("Stubbed showInputBox:", options)
return ""
},
showOpenDialog: async (options) => {
console.log("Stubbed showOpenDialog:", options)
return []
},
showSaveDialog: async (options) => {
console.log("Stubbed showSaveDialog:", options)
return undefined
},
showTextDocument: async (...args) => {
console.log("Stubbed showTextDocument:", ...args)
return {}
},
createOutputChannel: (name) => {
console.log("Stubbed createOutputChannel:", name)
return {
appendLine: console.log,
show: () => {},
dispose: () => {},
}
},
createTerminal: (...args) => {
console.log("Stubbed createTerminal:", ...args)
return {
sendText: console.log,
show: () => {},
dispose: () => {},
}
},
activeTextEditor: undefined,
visibleTextEditors: [],
tabGroups: {
all: [],
close: async () => {},
},
withProgress: async (_options, task) => {
console.log("Stubbed withProgress")
return task({ report: () => {} })
},
registerUriHandler: () => ({ dispose: () => {} }),
registerWebviewViewProvider: () => ({ dispose: () => {} }),
onDidChangeActiveTextEditor: () => ({ dispose: () => {} }),
createTextEditorDecorationType: () => ({ dispose: () => {} }),
createWebviewPanel: (...args) => {
console.log("Stubbed createWebviewPanel:", ...args)
return {
webview: {},
reveal: () => {},
dispose: () => {},
}
},
}
vscode.env = {
uriScheme: "vscode",
appName: "Visual Studio Code",
appRoot: "/tmp/vscode/appRoot",
language: "en",
machineId: "stub-machine-id",
remoteName: undefined,
sessionId: "stub-session-id",
shell: "/bin/bash",
clipboard: createStub("vscode.env.clipboard"),
openExternal: createStub("vscode.env.openExternal"),
getQueryParameter: createStub("vscode.env.getQueryParameter"),
onDidChangeTelemetryEnabled: createStub("vscode.env.onDidChangeTelemetryEnabled"),
isTelemetryEnabled: createStub("vscode.env.isTelemetryEnabled"),
telemetryConfiguration: createStub("vscode.env.telemetryConfiguration"),
onDidChangeTelemetryConfiguration: createStub("vscode.env.onDidChangeTelemetryConfiguration"),
createTelemetryLogger: createStub("vscode.env.createTelemetryLogger"),
}
vscode.Uri = {
parse: (uriString) => {
const url = new URL(uriString)
return {
scheme: url.protocol.replace(":", ""),
authority: url.hostname,
path: url.pathname,
query: url.search.slice(1),
fragment: url.hash.slice(1),
fsPath: `/tmp${url.pathname}`,
toString: () => uriString,
toJSON: () => uriString,
with: (change) => {
const newUrl = new URL(uriString)
if (change.scheme) newUrl.protocol = change.scheme + ":"
if (change.authority) newUrl.hostname = change.authority
if (change.path) newUrl.pathname = change.path
if (change.query) newUrl.search = "?" + change.query
if (change.fragment) newUrl.hash = "#" + change.fragment
return vscode.Uri.parse(newUrl.toString())
},
}
},
file: (path) => {
return {
scheme: "file",
authority: "",
path,
fsPath: path,
query: "",
fragment: "",
toString: () => `file://${path}`,
toJSON: () => `file://${path}`,
with: (change) => {
const modified = Object.assign({}, vscode.Uri.file(path), change)
return modified
},
}
},
joinPath: (...segments) => {
const joined = segments.map((s) => (typeof s === "string" ? s : s.path)).join("/")
return vscode.Uri.file("/" + joined.replace(/\/+/g, "/"))
},
}
vscode.env.openExternal = async (uri) => {
const url = typeof uri === "string" ? uri : (uri.toString?.() ?? "")
console.log("Opening browser:", url)
await open(url)
return true
}
console.log("Finished loading stub impls...")

File diff suppressed because it is too large Load Diff