@fleetagent/pi-coding-agent 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"operations.js","sourceRoot":"","sources":["../../../src/core/tools/operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EACN,MAAM,IAAI,QAAQ,EAClB,KAAK,IAAI,OAAO,EAChB,OAAO,IAAI,SAAS,EACpB,QAAQ,IAAI,UAAU,EACtB,IAAI,IAAI,MAAM,EACd,SAAS,IAAI,WAAW,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,oCAAoC,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EACN,cAAc,EACd,WAAW,EACX,eAAe,EACf,qBAAqB,EACrB,uBAAuB,GACvB,MAAM,sBAAsB,CAAC;AAmF9B,SAAS,kBAAkB,CAAC,IAAgC,EAAU;IACrE,QAAQ,IAAI,EAAE,CAAC;QACd,KAAK,MAAM;YACV,OAAO,SAAS,CAAC,IAAI,CAAC;QACvB,KAAK,OAAO;YACX,OAAO,SAAS,CAAC,IAAI,CAAC;QACvB,KAAK,WAAW;YACf,OAAO,SAAS,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;QACxC,KAAK,QAAQ,CAAC;QACd,KAAK,SAAS;YACb,OAAO,SAAS,CAAC,IAAI,CAAC;IACxB,CAAC;AAAA,CACD;AAED,SAAS,UAAU,CAAC,KAAa,EAAU;IAC1C,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC;AAAA,CAC3C;AAED,SAAS,cAAc,CAAC,KAAa,EAAmB;IACvD,MAAM,cAAc,G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C;YAAA,CAC5E,CAAC;SACF,CAAC;IAAA,CACF;IAED,KAAK,CAAC,mBAAmB,CAAC,IAAY,EAAsC;QAC3E,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QACnE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,OAAO,SAAS,CAAC;QACxC,MAAM,QAAQ,GAAG,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACjD,OAAO,QAAQ,IAAI,CAAC,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IAAA,CAC/G;IAED,cAAc,GAAoB;QACjC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IAAA,CACnG;IAED,KAAK,CAAC,OAAO,GAAkB;QAC9B,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAAA,CACpB;CACD;AAED,MAAM,UAAU,0BAA0B,CAAC,GAAW,EAAiC;IACtF,OAAO,oBAAoB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAAA,CACzC;AAED,MAAM,UAAU,uBAAuB,CAAC,MAAc,EAA8B;IACnF,OAAO,iBAAiB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAAA,CAC5C","sourcesContent":["import { spawn } from \"node:child_process\";\nimport type { Stats } from \"node:fs\";\nimport { constants } from \"node:fs\";\nimport {\n\taccess as fsAccess,\n\tmkdir as fsMkdir,\n\treaddir as fsReaddir,\n\treadFile as fsReadFile,\n\tstat as fsStat,\n\twriteFile as fsWriteFile,\n} from \"node:fs/promises\";\nimport { waitForChildProcess } from \"../../utils/child-process.ts\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.ts\";\nimport {\n\tgetShellConfig,\n\tgetShellEnv,\n\tkillProcessTree,\n\ttrackDetachedChildPid,\n\tuntrackDetachedChildPid,\n} from \"../../utils/shell.ts\";\n\nexport type ToolAccessMode = \"exists\" | \"read\" | \"write\" | \"readwrite\";\n\nexport interface ToolFileStat {\n\tisDirectory: () => boolean;\n\tisFile: () => boolean;\n}\n\nexport interface ToolExecOptions {\n\tcwd?: string;\n\tonData: (data: Buffer) => void;\n\tsignal?: AbortSignal;\n\ttimeout?: number;\n\tenv?: NodeJS.ProcessEnv;\n}\n\nexport interface ToolGlobOptions {\n\tignore: string[];\n\tlimit: number;\n}\n\nexport interface ToolGrepOptions {\n\tpattern: string;\n\tpath: string;\n\tglob?: string;\n\tignoreCase?: boolean;\n\tliteral?: boolean;\n\tlimit: number;\n}\n\nexport interface ToolGrepMatch {\n\tfilePath: string;\n\tlineNumber: number;\n\tlineText?: string;\n}\n\nexport interface ToolGrepResult {\n\tisDirectory: boolean;\n\tmatches: ToolGrepMatch[];\n}\n\nexport type ToolBackendInfo =\n\t| { type: \"local\"; cwd: string }\n\t| { type: \"ssh\"; cwd: string; remote: string; configured: true }\n\t| { type: \"remote\"; cwd: string; configured: false }\n\t| { type: \"remote\"; cwd: string; url: string; protocol: \"ws\"; configured: true };\n\nexport interface ToolOperations {\n\tcwd: string;\n\texec(command: string, options: ToolExecOptions): Promise<{ exitCode: number | null }>;\n\taccess(path: string, mode?: ToolAccessMode): Promise<void>;\n\treadFile(path: string): Promise<Buffer>;\n\twriteFile(path: string, content: string | Buffer): Promise<void>;\n\tmkdir(path: string, options?: { recursive?: boolean }): Promise<void>;\n\tstat(path: string): Promise<ToolFileStat>;\n\treaddir(path: string): Promise<string[]>;\n\tglob?(pattern: string, cwd: string, options: ToolGlobOptions): Promise<string[]>;\n\tgrep?(options: ToolGrepOptions): Promise<ToolGrepResult>;\n\tdetectImageMimeType?(path: string): Promise<string | null | undefined>;\n\tgetBackendInfo?(): ToolBackendInfo;\n\tdispose?(): Promise<void>;\n}\n\nexport interface LocalToolOperationsOptions {\n\tshellPath?: string;\n}\n\nexport interface SshToolOperationsOptions {\n\tremote: string;\n\tcwd: string;\n}\n\nexport interface DeferredRemoteToolOperationsConfigureSshOptions {\n\tremote: string;\n\tcwd?: string;\n}\n\nexport interface ParsedSshTarget {\n\tremote: string;\n\tcwd?: string;\n}\n\nfunction accessModeToFsMode(mode: ToolAccessMode | undefined): number {\n\tswitch (mode) {\n\t\tcase \"read\":\n\t\t\treturn constants.R_OK;\n\t\tcase \"write\":\n\t\t\treturn constants.W_OK;\n\t\tcase \"readwrite\":\n\t\t\treturn constants.R_OK | constants.W_OK;\n\t\tcase \"exists\":\n\t\tcase undefined:\n\t\t\treturn constants.F_OK;\n\t}\n}\n\nfunction shellQuote(value: string): string {\n\treturn `'${value.replace(/'/g, `'\\\\''`)}'`;\n}\n\nfunction parseSshTarget(value: string): ParsedSshTarget {\n\tconst separatorIndex = value.indexOf(\":\");\n\tif (separatorIndex === -1) {\n\t\treturn { remote: value };\n\t}\n\tconst remote = value.slice(0, separatorIndex);\n\tconst cwd = value.slice(separatorIndex + 1);\n\treturn cwd ? { remote, cwd } : { remote };\n}\n\nfunction validateSshRemote(remote: string): void {\n\tif (!remote) {\n\t\tthrow new Error(\"--ssh requires a remote target like user@host or user@host:/path\");\n\t}\n\tif (remote.startsWith(\"-\")) {\n\t\tthrow new Error(\"--ssh remote target must not start with '-'\");\n\t}\n}\n\nfunction sshArgs(remote: string, command: string): string[] {\n\tvalidateSshRemote(remote);\n\treturn [\"--\", remote, command];\n}\n\nfunction buildFdArgs(pattern: string, searchPath: string, limit: number): string[] {\n\tconst args: string[] = [\"--glob\", \"--color=never\", \"--hidden\", \"--no-require-git\", \"--max-results\", String(limit)];\n\tlet effectivePattern = pattern;\n\tif (pattern.includes(\"/\")) {\n\t\targs.push(\"--full-path\");\n\t\tif (!pattern.startsWith(\"/\") && !pattern.startsWith(\"**/\") && pattern !== \"**\") {\n\t\t\teffectivePattern = `**/${pattern}`;\n\t\t}\n\t}\n\targs.push(\"--\", effectivePattern, searchPath);\n\treturn args;\n}\n\nfunction buildRgArgs(options: ToolGrepOptions): string[] {\n\tconst args: string[] = [\"--json\", \"--line-number\", \"--color=never\", \"--hidden\"];\n\tif (options.ignoreCase) args.push(\"--ignore-case\");\n\tif (options.literal) args.push(\"--fixed-strings\");\n\tif (options.glob) args.push(\"--glob\", options.glob);\n\targs.push(\"--\", options.pattern, options.path);\n\treturn args;\n}\n\nfunction commandWithArgs(command: string, args: string[]): string {\n\treturn [command, ...args.map(shellQuote)].join(\" \");\n}\n\nasync function runSshBuffer(\n\tremote: string,\n\tcommand: string,\n\toptions: { input?: Buffer | string; signal?: AbortSignal; timeout?: number } = {},\n): Promise<Buffer> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst child = spawn(\"ssh\", sshArgs(remote, command), { stdio: [\"pipe\", \"pipe\", \"pipe\"] });\n\t\tconst stdout: Buffer[] = [];\n\t\tconst stderr: Buffer[] = [];\n\t\tlet timedOut = false;\n\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\tif (options.timeout !== undefined && options.timeout > 0) {\n\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\ttimedOut = true;\n\t\t\t\tchild.kill();\n\t\t\t}, options.timeout * 1000);\n\t\t}\n\t\tchild.stdout.on(\"data\", (data: Buffer) => stdout.push(data));\n\t\tchild.stderr.on(\"data\", (data: Buffer) => stderr.push(data));\n\t\tchild.on(\"error\", reject);\n\t\tconst onAbort = () => child.kill();\n\t\toptions.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\tif (options.input !== undefined) {\n\t\t\tchild.stdin.end(options.input);\n\t\t} else {\n\t\t\tchild.stdin.end();\n\t\t}\n\t\tchild.on(\"close\", (code) => {\n\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\toptions.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\tif (options.signal?.aborted) {\n\t\t\t\treject(new Error(\"aborted\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (timedOut) {\n\t\t\t\treject(new Error(`timeout:${options.timeout}`));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (code !== 0) {\n\t\t\t\treject(new Error(Buffer.concat(stderr).toString(\"utf-8\").trim() || `ssh exited with code ${code}`));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresolve(Buffer.concat(stdout));\n\t\t});\n\t});\n}\n\nexport class LocalToolOperations implements ToolOperations {\n\tcwd: string;\n\tprivate shellPath: string | undefined;\n\n\tconstructor(cwd: string, options: LocalToolOperationsOptions = {}) {\n\t\tthis.cwd = cwd;\n\t\tthis.shellPath = options.shellPath;\n\t}\n\n\tasync exec(command: string, options: ToolExecOptions): Promise<{ exitCode: number | null }> {\n\t\tconst cwd = options.cwd ?? this.cwd;\n\t\tconst { shell, args } = getShellConfig(this.shellPath);\n\t\ttry {\n\t\t\tawait fsAccess(cwd, constants.F_OK);\n\t\t} catch {\n\t\t\tthrow new Error(`Working directory does not exist: ${cwd}\\nCannot execute bash commands.`);\n\t\t}\n\t\tif (options.signal?.aborted) {\n\t\t\tthrow new Error(\"aborted\");\n\t\t}\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst child = spawn(shell, [...args, command], {\n\t\t\t\tcwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: options.env ?? getShellEnv(),\n\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\t\t\tlet timedOut = false;\n\t\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\t\tif (options.timeout !== undefined && options.timeout > 0) {\n\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\ttimedOut = true;\n\t\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t\t}, options.timeout * 1000);\n\t\t\t}\n\t\t\tchild.stdout?.on(\"data\", options.onData);\n\t\t\tchild.stderr?.on(\"data\", options.onData);\n\t\t\tconst onAbort = () => {\n\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t};\n\t\t\tif (options.signal) {\n\t\t\t\tif (options.signal.aborted) onAbort();\n\t\t\t\telse options.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t}\n\t\t\twaitForChildProcess(child)\n\t\t\t\t.then((code) => {\n\t\t\t\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\t\tif (options.signal) options.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\tif (options.signal?.aborted) {\n\t\t\t\t\t\treject(new Error(\"aborted\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (timedOut) {\n\t\t\t\t\t\treject(new Error(`timeout:${options.timeout}`));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tresolve({ exitCode: code });\n\t\t\t\t})\n\t\t\t\t.catch((error: unknown) => {\n\t\t\t\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\t\tif (options.signal) options.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\treject(error);\n\t\t\t\t});\n\t\t});\n\t}\n\n\tasync access(path: string, mode?: ToolAccessMode): Promise<void> {\n\t\tawait fsAccess(path, accessModeToFsMode(mode));\n\t}\n\n\tasync readFile(path: string): Promise<Buffer> {\n\t\treturn fsReadFile(path);\n\t}\n\n\tasync writeFile(path: string, content: string | Buffer): Promise<void> {\n\t\tawait fsWriteFile(path, content, typeof content === \"string\" ? \"utf-8\" : undefined);\n\t}\n\n\tasync mkdir(path: string, options: { recursive?: boolean } = {}): Promise<void> {\n\t\tawait fsMkdir(path, { recursive: options.recursive ?? false });\n\t}\n\n\tasync stat(path: string): Promise<Stats> {\n\t\treturn fsStat(path);\n\t}\n\n\tasync readdir(path: string): Promise<string[]> {\n\t\treturn fsReaddir(path);\n\t}\n\n\tasync detectImageMimeType(path: string): Promise<string | null | undefined> {\n\t\treturn detectSupportedImageMimeTypeFromFile(path);\n\t}\n\n\tgetBackendInfo(): ToolBackendInfo {\n\t\treturn { type: \"local\", cwd: this.cwd };\n\t}\n}\n\nexport class SshToolOperations implements ToolOperations {\n\treadonly remote: string;\n\tcwd: string;\n\n\tconstructor(options: SshToolOperationsOptions) {\n\t\tthis.remote = options.remote;\n\t\tthis.cwd = options.cwd;\n\t}\n\n\tstatic async fromTarget(target: string): Promise<SshToolOperations> {\n\t\tconst parsed = parseSshTarget(target);\n\t\tvalidateSshRemote(parsed.remote);\n\t\tconst cwd = parsed.cwd ?? (await runSshBuffer(parsed.remote, \"pwd\")).toString(\"utf-8\").trim();\n\t\treturn new SshToolOperations({ remote: parsed.remote, cwd });\n\t}\n\n\tasync exec(command: string, options: ToolExecOptions): Promise<{ exitCode: number | null }> {\n\t\tconst cwd = options.cwd ?? this.cwd;\n\t\tconst remoteCommand = `cd ${shellQuote(cwd)} && bash -s`;\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst child = spawn(\"ssh\", sshArgs(this.remote, remoteCommand), {\n\t\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\t});\n\t\t\tlet timedOut = false;\n\t\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\t\tif (options.timeout !== undefined && options.timeout > 0) {\n\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\ttimedOut = true;\n\t\t\t\t\tchild.kill();\n\t\t\t\t}, options.timeout * 1000);\n\t\t\t}\n\t\t\tchild.stdout?.on(\"data\", options.onData);\n\t\t\tchild.stderr?.on(\"data\", options.onData);\n\t\t\tchild.on(\"error\", reject);\n\t\t\tchild.stdin.end(command);\n\t\t\tconst onAbort = () => child.kill();\n\t\t\toptions.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\tchild.on(\"close\", (code) => {\n\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\toptions.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\tif (options.signal?.aborted) {\n\t\t\t\t\treject(new Error(\"aborted\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (timedOut) {\n\t\t\t\t\treject(new Error(`timeout:${options.timeout}`));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tresolve({ exitCode: code });\n\t\t\t});\n\t\t});\n\t}\n\n\tasync access(path: string, mode?: ToolAccessMode): Promise<void> {\n\t\tconst remotePath = shellQuote(path);\n\t\tif (mode === \"readwrite\") {\n\t\t\tawait runSshBuffer(this.remote, `test -r ${remotePath} && test -w ${remotePath}`);\n\t\t\treturn;\n\t\t}\n\t\tconst flag = mode === \"read\" ? \"-r\" : mode === \"write\" ? \"-w\" : \"-e\";\n\t\tawait runSshBuffer(this.remote, `test ${flag} ${remotePath}`);\n\t}\n\n\tasync readFile(path: string): Promise<Buffer> {\n\t\treturn runSshBuffer(this.remote, `cat ${shellQuote(path)}`);\n\t}\n\n\tasync writeFile(path: string, content: string | Buffer): Promise<void> {\n\t\tawait runSshBuffer(this.remote, `base64 -d > ${shellQuote(path)}`, {\n\t\t\tinput: Buffer.from(content).toString(\"base64\"),\n\t\t});\n\t}\n\n\tasync mkdir(path: string, options: { recursive?: boolean } = {}): Promise<void> {\n\t\tconst flag = options.recursive ? \"-p \" : \"\";\n\t\tawait runSshBuffer(this.remote, `mkdir ${flag}${shellQuote(path)}`);\n\t}\n\n\tasync stat(path: string): Promise<ToolFileStat> {\n\t\tconst output = await runSshBuffer(\n\t\t\tthis.remote,\n\t\t\t`if test -d ${shellQuote(path)}; then echo d; elif test -f ${shellQuote(path)}; then echo f; else test -e ${shellQuote(path)} && echo o || exit 1; fi`,\n\t\t);\n\t\tconst kind = output.toString(\"utf-8\").trim();\n\t\treturn {\n\t\t\tisDirectory: () => kind === \"d\",\n\t\t\tisFile: () => kind === \"f\",\n\t\t};\n\t}\n\n\tasync readdir(path: string): Promise<string[]> {\n\t\tconst output = await runSshBuffer(\n\t\t\tthis.remote,\n\t\t\t`find ${shellQuote(path)} -maxdepth 1 -mindepth 1 -printf '%f\\\\n'`,\n\t\t);\n\t\treturn output.toString(\"utf-8\").split(\"\\n\").filter(Boolean);\n\t}\n\n\tasync glob(pattern: string, cwd: string, options: ToolGlobOptions): Promise<string[]> {\n\t\tconst command = commandWithArgs(\"fd\", buildFdArgs(pattern, cwd, options.limit));\n\t\tconst output = await runSshBuffer(this.remote, command);\n\t\treturn output.toString(\"utf-8\").split(\"\\n\").filter(Boolean);\n\t}\n\n\tasync grep(options: ToolGrepOptions): Promise<ToolGrepResult> {\n\t\tconst isDirectory = (await this.stat(options.path)).isDirectory();\n\t\tconst command = commandWithArgs(\"rg\", buildRgArgs(options));\n\t\tconst output = await runSshBuffer(this.remote, command).catch((error: unknown) => {\n\t\t\tif (error instanceof Error && error.message.includes(\"ssh exited with code 1\")) {\n\t\t\t\treturn Buffer.alloc(0);\n\t\t\t}\n\t\t\tthrow error;\n\t\t});\n\t\tconst matches: ToolGrepMatch[] = [];\n\t\tfor (const line of output.toString(\"utf-8\").split(\"\\n\")) {\n\t\t\tif (!line.trim() || matches.length >= options.limit) continue;\n\t\t\tlet event: unknown;\n\t\t\ttry {\n\t\t\t\tevent = JSON.parse(line);\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!event || typeof event !== \"object\" || !(\"type\" in event) || event.type !== \"match\") continue;\n\t\t\tconst data = \"data\" in event && event.data && typeof event.data === \"object\" ? event.data : undefined;\n\t\t\tconst filePath =\n\t\t\t\tdata && \"path\" in data && data.path && typeof data.path === \"object\" && \"text\" in data.path\n\t\t\t\t\t? data.path.text\n\t\t\t\t\t: undefined;\n\t\t\tconst lineNumber = data && \"line_number\" in data ? data.line_number : undefined;\n\t\t\tconst lineText =\n\t\t\t\tdata && \"lines\" in data && data.lines && typeof data.lines === \"object\" && \"text\" in data.lines\n\t\t\t\t\t? data.lines.text\n\t\t\t\t\t: undefined;\n\t\t\tif (typeof filePath === \"string\" && typeof lineNumber === \"number\") {\n\t\t\t\tmatches.push({ filePath, lineNumber, lineText: typeof lineText === \"string\" ? lineText : undefined });\n\t\t\t}\n\t\t}\n\t\treturn { isDirectory, matches };\n\t}\n\n\tasync detectImageMimeType(path: string): Promise<string | null | undefined> {\n\t\ttry {\n\t\t\tconst output = await runSshBuffer(this.remote, `file --mime-type -b ${shellQuote(path)}`);\n\t\t\tconst mimeType = output.toString(\"utf-8\").trim();\n\t\t\treturn [\"image/jpeg\", \"image/png\", \"image/gif\", \"image/webp\"].includes(mimeType) ? mimeType : null;\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tgetBackendInfo(): ToolBackendInfo {\n\t\treturn { type: \"ssh\", remote: this.remote, cwd: this.cwd, configured: true };\n\t}\n\n\tasync dispose(): Promise<void> {}\n}\n\nexport class DeferredRemoteToolOperations implements ToolOperations {\n\tcwd: string;\n\tprivate operations: SshToolOperations | RemoteToolOperations | undefined;\n\n\tconstructor(cwd: string) {\n\t\tthis.cwd = cwd;\n\t}\n\n\tasync configure(options: DeferredRemoteToolOperationsConfigureSshOptions): Promise<ToolBackendInfo> {\n\t\tconst next = new SshToolOperations({ remote: options.remote, cwd: options.cwd ?? this.cwd });\n\t\tconst stat = await next.stat(next.cwd);\n\t\tif (!stat.isDirectory()) {\n\t\t\tthrow new Error(`SSH backend cwd is not a directory: ${next.cwd}`);\n\t\t}\n\t\tawait this.operations?.dispose?.();\n\t\tthis.cwd = next.cwd;\n\t\tthis.operations = next;\n\t\treturn this.getBackendInfo();\n\t}\n\n\tasync configureRemote(url: string): Promise<ToolBackendInfo> {\n\t\tconst next = await createRemoteToolOperations(url);\n\t\tconst stat = await next.stat(next.cwd);\n\t\tif (!stat.isDirectory()) {\n\t\t\tthrow new Error(`Remote daemon cwd is not a directory: ${next.cwd}`);\n\t\t}\n\t\tawait this.operations?.dispose?.();\n\t\tthis.cwd = next.cwd;\n\t\tthis.operations = next;\n\t\treturn this.getBackendInfo();\n\t}\n\n\tclear(): void {\n\t\tvoid this.operations?.dispose?.();\n\t\tthis.operations = undefined;\n\t}\n\n\tprivate requireOperations(): SshToolOperations | RemoteToolOperations {\n\t\tif (!this.operations) {\n\t\t\tthrow new Error(\"Remote backend is not configured. Configure it over RPC or with /remote before using tools.\");\n\t\t}\n\t\treturn this.operations;\n\t}\n\n\tasync exec(command: string, options: ToolExecOptions): Promise<{ exitCode: number | null }> {\n\t\treturn this.requireOperations().exec(command, options);\n\t}\n\n\tasync access(path: string, mode?: ToolAccessMode): Promise<void> {\n\t\tawait this.requireOperations().access(path, mode);\n\t}\n\n\tasync readFile(path: string): Promise<Buffer> {\n\t\treturn this.requireOperations().readFile(path);\n\t}\n\n\tasync writeFile(path: string, content: string | Buffer): Promise<void> {\n\t\tawait this.requireOperations().writeFile(path, content);\n\t}\n\n\tasync mkdir(path: string, options?: { recursive?: boolean }): Promise<void> {\n\t\tawait this.requireOperations().mkdir(path, options);\n\t}\n\n\tasync stat(path: string): Promise<ToolFileStat> {\n\t\treturn this.requireOperations().stat(path);\n\t}\n\n\tasync readdir(path: string): Promise<string[]> {\n\t\treturn this.requireOperations().readdir(path);\n\t}\n\n\tasync glob(pattern: string, cwd: string, options: ToolGlobOptions): Promise<string[]> {\n\t\treturn this.requireOperations().glob(pattern, cwd, options);\n\t}\n\n\tasync grep(options: ToolGrepOptions): Promise<ToolGrepResult> {\n\t\treturn this.requireOperations().grep(options);\n\t}\n\n\tasync detectImageMimeType(path: string): Promise<string | null | undefined> {\n\t\treturn this.requireOperations().detectImageMimeType(path);\n\t}\n\n\tgetBackendInfo(): ToolBackendInfo {\n\t\treturn this.operations?.getBackendInfo() ?? { type: \"remote\", cwd: this.cwd, configured: false };\n\t}\n}\n\ntype RemoteResponse = { id: string; result: unknown } | { id: string; error: { message?: unknown } | string };\n\ntype RemoteExecEvent =\n\t| { id: string; event: \"data\"; dataBase64?: unknown; data?: unknown; stream?: unknown }\n\t| { id: string; event: \"exit\"; exitCode?: unknown; cancelled?: unknown }\n\t| { id: string; event: \"error\"; error?: { message?: unknown } | string };\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction remoteErrorMessage(error: unknown): string {\n\tif (typeof error === \"string\") return error;\n\tif (isRecord(error) && typeof error.message === \"string\") return error.message;\n\treturn \"remote operation failed\";\n}\n\nfunction requireString(value: unknown, name: string): string {\n\tif (typeof value !== \"string\") throw new Error(`Remote response missing string ${name}`);\n\treturn value;\n}\n\nfunction optionalString(value: unknown): string | undefined {\n\treturn typeof value === \"string\" ? value : undefined;\n}\n\nfunction optionalNumber(value: unknown): number | undefined {\n\treturn typeof value === \"number\" ? value : undefined;\n}\n\nfunction normalizeRemoteUrl(url: string): { url: string; protocol: \"ws\" } {\n\tconst parsed = new URL(url);\n\tif (parsed.protocol !== \"ws:\" && parsed.protocol !== \"wss:\") {\n\t\tthrow new Error(`--remote currently supports ws:// and wss:// URLs, got ${parsed.protocol}`);\n\t}\n\treturn { url, protocol: \"ws\" };\n}\n\nexport class RemoteToolOperations implements ToolOperations {\n\treadonly url: string;\n\treadonly protocol: \"ws\";\n\tcwd: string;\n\tprivate socket: WebSocket;\n\tprivate nextId = 1;\n\tprivate pending = new Map<\n\t\tstring,\n\t\t{\n\t\t\tresolve: (value: unknown) => void;\n\t\t\treject: (error: Error) => void;\n\t\t}\n\t>();\n\tprivate execPending = new Map<\n\t\tstring,\n\t\t{\n\t\t\tonData: (data: Buffer) => void;\n\t\t\tresolve: (value: { exitCode: number | null }) => void;\n\t\t\treject: (error: Error) => void;\n\t\t}\n\t>();\n\tprivate keepAliveInterval: NodeJS.Timeout | undefined;\n\tprivate lastPongAt = Date.now();\n\n\tprivate constructor(url: string, protocol: \"ws\", socket: WebSocket, cwd: string) {\n\t\tthis.url = url;\n\t\tthis.protocol = protocol;\n\t\tthis.socket = socket;\n\t\tthis.cwd = cwd;\n\t\tthis.socket.addEventListener(\"message\", (event) => this.handleMessage(event.data));\n\t\tthis.socket.addEventListener(\"close\", () => {\n\t\t\tthis.stopKeepAlive();\n\t\t\tthis.rejectAll(new Error(\"remote connection closed\"));\n\t\t});\n\t\tthis.socket.addEventListener(\"error\", () => {\n\t\t\tthis.stopKeepAlive();\n\t\t\tthis.rejectAll(new Error(\"remote connection error\"));\n\t\t});\n\t\tthis.startKeepAlive();\n\t}\n\n\tstatic async connect(url: string): Promise<RemoteToolOperations> {\n\t\tconst normalized = normalizeRemoteUrl(url);\n\t\tconst socket = await new Promise<WebSocket>((resolveSocket, rejectSocket) => {\n\t\t\tconst ws = new WebSocket(normalized.url);\n\t\t\tconst cleanup = () => {\n\t\t\t\tws.removeEventListener(\"open\", onOpen);\n\t\t\t\tws.removeEventListener(\"error\", onError);\n\t\t\t};\n\t\t\tconst onOpen = () => {\n\t\t\t\tcleanup();\n\t\t\t\tresolveSocket(ws);\n\t\t\t};\n\t\t\tconst onError = () => {\n\t\t\t\tcleanup();\n\t\t\t\trejectSocket(new Error(`failed to connect remote commander: ${normalized.url}`));\n\t\t\t};\n\t\t\tws.addEventListener(\"open\", onOpen, { once: true });\n\t\t\tws.addEventListener(\"error\", onError, { once: true });\n\t\t});\n\t\tconst operations = new RemoteToolOperations(normalized.url, normalized.protocol, socket, \"/\");\n\t\tconst capabilities = await operations.request(\"capabilities\", {});\n\t\tif (isRecord(capabilities) && typeof capabilities.cwd === \"string\") {\n\t\t\toperations.cwd = capabilities.cwd;\n\t\t}\n\t\treturn operations;\n\t}\n\n\tprivate startKeepAlive(): void {\n\t\tthis.keepAliveInterval = setInterval(() => {\n\t\t\tif (Date.now() - this.lastPongAt > 90_000) {\n\t\t\t\tthis.stopKeepAlive();\n\t\t\t\tthis.rejectAll(new Error(\"remote connection heartbeat timed out\"));\n\t\t\t\tthis.socket.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tthis.send({ type: \"ping\", timestamp: Date.now() });\n\t\t\t} catch (error) {\n\t\t\t\tthis.stopKeepAlive();\n\t\t\t\tthis.rejectAll(error instanceof Error ? error : new Error(String(error)));\n\t\t\t}\n\t\t}, 30_000);\n\t\tthis.keepAliveInterval.unref?.();\n\t}\n\n\tprivate stopKeepAlive(): void {\n\t\tif (this.keepAliveInterval) {\n\t\t\tclearInterval(this.keepAliveInterval);\n\t\t\tthis.keepAliveInterval = undefined;\n\t\t}\n\t}\n\n\tprivate rejectAll(error: Error): void {\n\t\tfor (const pending of this.pending.values()) pending.reject(error);\n\t\tthis.pending.clear();\n\t\tfor (const pending of this.execPending.values()) pending.reject(error);\n\t\tthis.execPending.clear();\n\t}\n\n\tprivate send(message: Record<string, unknown>): void {\n\t\tif (this.socket.readyState !== WebSocket.OPEN) {\n\t\t\tthrow new Error(\"remote connection is not open\");\n\t\t}\n\t\tthis.socket.send(JSON.stringify(message));\n\t}\n\n\tprivate request(method: string, params: Record<string, unknown>): Promise<unknown> {\n\t\tconst id = `remote-${this.nextId++}`;\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.pending.set(id, { resolve, reject });\n\t\t\ttry {\n\t\t\t\tthis.send({ id, method, params });\n\t\t\t} catch (error) {\n\t\t\t\tthis.pending.delete(id);\n\t\t\t\treject(error instanceof Error ? error : new Error(String(error)));\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate handleMessage(data: unknown): void {\n\t\tif (typeof data !== \"string\") return;\n\t\tlet parsed: unknown;\n\t\ttry {\n\t\t\tparsed = JSON.parse(data);\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\t\tif (!isRecord(parsed)) return;\n\t\tif (parsed.type === \"pong\") {\n\t\t\tthis.lastPongAt = Date.now();\n\t\t\treturn;\n\t\t}\n\t\tif (typeof parsed.id !== \"string\") return;\n\t\tif (typeof parsed.event === \"string\") {\n\t\t\tthis.handleExecEvent(parsed as RemoteExecEvent);\n\t\t\treturn;\n\t\t}\n\t\tconst pending = this.pending.get(parsed.id);\n\t\tif (!pending) return;\n\t\tthis.pending.delete(parsed.id);\n\t\tconst response = parsed as RemoteResponse;\n\t\tif (\"error\" in response) {\n\t\t\tpending.reject(new Error(remoteErrorMessage(response.error)));\n\t\t\treturn;\n\t\t}\n\t\tpending.resolve(response.result);\n\t}\n\n\tprivate handleExecEvent(event: RemoteExecEvent): void {\n\t\tconst pending = this.execPending.get(event.id);\n\t\tif (!pending) return;\n\t\tif (event.event === \"data\") {\n\t\t\tconst encoded = optionalString(event.dataBase64);\n\t\t\tconst text = optionalString(event.data);\n\t\t\tif (encoded !== undefined) pending.onData(Buffer.from(encoded, \"base64\"));\n\t\t\telse if (text !== undefined) pending.onData(Buffer.from(text));\n\t\t\treturn;\n\t\t}\n\t\tthis.execPending.delete(event.id);\n\t\tif (event.event === \"error\") {\n\t\t\tpending.reject(new Error(remoteErrorMessage(event.error)));\n\t\t\treturn;\n\t\t}\n\t\tconst exitCode = optionalNumber(event.exitCode) ?? null;\n\t\tpending.resolve({ exitCode });\n\t}\n\n\tasync exec(command: string, options: ToolExecOptions): Promise<{ exitCode: number | null }> {\n\t\tconst id = `remote-${this.nextId++}`;\n\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst cleanup = () => {\n\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\toptions.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\t};\n\t\t\tconst onAbort = () => {\n\t\t\t\ttry {\n\t\t\t\t\tthis.send({ id, method: \"cancel\" });\n\t\t\t\t} catch {}\n\t\t\t\tconst pending = this.execPending.get(id);\n\t\t\t\tif (pending) {\n\t\t\t\t\tthis.execPending.delete(id);\n\t\t\t\t\tcleanup();\n\t\t\t\t\tpending.reject(new Error(\"aborted\"));\n\t\t\t\t}\n\t\t\t};\n\t\t\tthis.execPending.set(id, {\n\t\t\t\tonData: options.onData,\n\t\t\t\tresolve: (value) => {\n\t\t\t\t\tcleanup();\n\t\t\t\t\tresolve(value);\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tcleanup();\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\t\t\toptions.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\tif (options.timeout !== undefined && options.timeout > 0) {\n\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tthis.send({ id, method: \"cancel\" });\n\t\t\t\t\t} catch {}\n\t\t\t\t\tconst pending = this.execPending.get(id);\n\t\t\t\t\tif (pending) {\n\t\t\t\t\t\tthis.execPending.delete(id);\n\t\t\t\t\t\tcleanup();\n\t\t\t\t\t\tpending.reject(new Error(`timeout:${options.timeout}`));\n\t\t\t\t\t}\n\t\t\t\t}, options.timeout * 1000);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tthis.send({\n\t\t\t\t\tid,\n\t\t\t\t\tmethod: \"exec\",\n\t\t\t\t\tparams: { command, cwd: options.cwd ?? this.cwd, env: options.env, timeout: options.timeout },\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthis.execPending.delete(id);\n\t\t\t\tcleanup();\n\t\t\t\treject(error instanceof Error ? error : new Error(String(error)));\n\t\t\t}\n\t\t});\n\t}\n\n\tasync access(path: string, mode?: ToolAccessMode): Promise<void> {\n\t\tawait this.request(\"access\", { path, mode });\n\t}\n\n\tasync readFile(path: string): Promise<Buffer> {\n\t\tconst result = await this.request(\"readFile\", { path });\n\t\tif (!isRecord(result)) throw new Error(\"Invalid remote readFile response\");\n\t\treturn Buffer.from(requireString(result.contentBase64, \"contentBase64\"), \"base64\");\n\t}\n\n\tasync writeFile(path: string, content: string | Buffer): Promise<void> {\n\t\tawait this.request(\"writeFile\", { path, contentBase64: Buffer.from(content).toString(\"base64\") });\n\t}\n\n\tasync mkdir(path: string, options: { recursive?: boolean } = {}): Promise<void> {\n\t\tawait this.request(\"mkdir\", { path, recursive: options.recursive ?? false });\n\t}\n\n\tasync stat(path: string): Promise<ToolFileStat> {\n\t\tconst result = await this.request(\"stat\", { path });\n\t\tif (!isRecord(result)) throw new Error(\"Invalid remote stat response\");\n\t\tconst kind = optionalString(result.kind) ?? optionalString(result.type);\n\t\tconst isDirectory = result.isDirectory === true || kind === \"directory\" || kind === \"dir\";\n\t\tconst isFile = result.isFile === true || kind === \"file\";\n\t\treturn { isDirectory: () => isDirectory, isFile: () => isFile };\n\t}\n\n\tasync readdir(path: string): Promise<string[]> {\n\t\tconst result = await this.request(\"readdir\", { path });\n\t\tif (Array.isArray(result)) return result.filter((entry): entry is string => typeof entry === \"string\");\n\t\tif (!isRecord(result) || !Array.isArray(result.entries)) throw new Error(\"Invalid remote readdir response\");\n\t\treturn result.entries.filter((entry): entry is string => typeof entry === \"string\");\n\t}\n\n\tasync glob(pattern: string, cwd: string, options: ToolGlobOptions): Promise<string[]> {\n\t\tconst result = await this.request(\"glob\", { pattern, cwd, ignore: options.ignore, limit: options.limit });\n\t\tif (Array.isArray(result)) return result.filter((entry): entry is string => typeof entry === \"string\");\n\t\tif (!isRecord(result) || !Array.isArray(result.matches)) throw new Error(\"Invalid remote glob response\");\n\t\treturn result.matches.filter((entry): entry is string => typeof entry === \"string\");\n\t}\n\n\tasync grep(options: ToolGrepOptions): Promise<ToolGrepResult> {\n\t\tconst result = await this.request(\"grep\", options as unknown as Record<string, unknown>);\n\t\tif (!isRecord(result)) throw new Error(\"Invalid remote grep response\");\n\t\tconst matches = Array.isArray(result.matches) ? result.matches : [];\n\t\treturn {\n\t\t\tisDirectory: result.isDirectory === true,\n\t\t\tmatches: matches.flatMap((entry): ToolGrepMatch[] => {\n\t\t\t\tif (!isRecord(entry)) return [];\n\t\t\t\tconst filePath = optionalString(entry.filePath);\n\t\t\t\tconst lineNumber = optionalNumber(entry.lineNumber);\n\t\t\t\tif (!filePath || lineNumber === undefined) return [];\n\t\t\t\treturn [{ filePath, lineNumber, lineText: optionalString(entry.lineText) }];\n\t\t\t}),\n\t\t};\n\t}\n\n\tasync detectImageMimeType(path: string): Promise<string | null | undefined> {\n\t\tconst result = await this.request(\"detectImageMimeType\", { path });\n\t\tif (!isRecord(result)) return undefined;\n\t\tconst mimeType = optionalString(result.mimeType);\n\t\treturn mimeType && [\"image/jpeg\", \"image/png\", \"image/gif\", \"image/webp\"].includes(mimeType) ? mimeType : null;\n\t}\n\n\tgetBackendInfo(): ToolBackendInfo {\n\t\treturn { type: \"remote\", cwd: this.cwd, url: this.url, protocol: this.protocol, configured: true };\n\t}\n\n\tasync dispose(): Promise<void> {\n\t\tthis.stopKeepAlive();\n\t\tthis.socket.close();\n\t}\n}\n\nexport function createRemoteToolOperations(url: string): Promise<RemoteToolOperations> {\n\treturn RemoteToolOperations.connect(url);\n}\n\nexport function createSshToolOperations(target: string): Promise<SshToolOperations> {\n\treturn SshToolOperations.fromTarget(target);\n}\n"]}
1
+ {"version":3,"file":"operations.js","sourceRoot":"","sources":["../../../src/core/tools/operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,iBAAiB,EAAgC,MAAM,SAAS,CAAC;AACvG,OAAO,EACN,MAAM,IAAI,QAAQ,EAClB,KAAK,IAAI,OAAO,EAChB,OAAO,IAAI,SAAS,EACpB,QAAQ,IAAI,UAAU,EACtB,IAAI,IAAI,MAAM,EACd,SAAS,IAAI,WAAW,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,E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AC,CAAC,CAAC,IAAI,CAAC;IAAA,CAC/G;IAED,cAAc,GAAoB;QACjC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IAAA,CACnG;IAED,KAAK,CAAC,OAAO,GAAkB;QAC9B,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAAA,CACpB;CACD;AAED,MAAM,UAAU,0BAA0B,CAAC,GAAW,EAAiC;IACtF,OAAO,oBAAoB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAAA,CACzC;AAED,MAAM,UAAU,uBAAuB,CAAC,MAAc,EAA8B;IACnF,OAAO,iBAAiB,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAAA,CAC5C","sourcesContent":["import { spawn } from \"node:child_process\";\nimport { constants, createReadStream, createWriteStream, type Stats, type WriteStream } from \"node:fs\";\nimport {\n\taccess as fsAccess,\n\tmkdir as fsMkdir,\n\treaddir as fsReaddir,\n\treadFile as fsReadFile,\n\tstat as fsStat,\n\twriteFile as fsWriteFile,\n} from \"node:fs/promises\";\nimport { pipeline } from \"node:stream/promises\";\nimport { waitForChildProcess } from \"../../utils/child-process.ts\";\nimport { detectSupportedImageMimeTypeFromFile } from \"../../utils/mime.ts\";\nimport {\n\tgetShellConfig,\n\tgetShellEnv,\n\tkillProcessTree,\n\ttrackDetachedChildPid,\n\tuntrackDetachedChildPid,\n} from \"../../utils/shell.ts\";\n\nexport type ToolAccessMode = \"exists\" | \"read\" | \"write\" | \"readwrite\";\n\nexport interface ToolFileStat {\n\tisDirectory: () => boolean;\n\tisFile: () => boolean;\n}\n\nexport interface ToolExecOptions {\n\tcwd?: string;\n\tonData: (data: Buffer) => void;\n\tsignal?: AbortSignal;\n\ttimeout?: number;\n\tenv?: NodeJS.ProcessEnv;\n}\n\nexport interface ToolGlobOptions {\n\tignore: string[];\n\tlimit: number;\n}\n\nexport interface ToolGrepOptions {\n\tpattern: string;\n\tpath: string;\n\tglob?: string;\n\tignoreCase?: boolean;\n\tliteral?: boolean;\n\tlimit: number;\n}\n\nexport interface ToolGrepMatch {\n\tfilePath: string;\n\tlineNumber: number;\n\tlineText?: string;\n}\n\nexport interface ToolGrepResult {\n\tisDirectory: boolean;\n\tmatches: ToolGrepMatch[];\n}\n\nexport type ToolBackendInfo =\n\t| { type: \"local\"; cwd: string }\n\t| { type: \"ssh\"; cwd: string; remote: string; configured: true }\n\t| { type: \"remote\"; cwd: string; configured: false }\n\t| { type: \"remote\"; cwd: string; url: string; protocol: \"ws\"; configured: true };\n\nexport interface ToolOperations {\n\tcwd: string;\n\texec(command: string, options: ToolExecOptions): Promise<{ exitCode: number | null }>;\n\taccess(path: string, mode?: ToolAccessMode): Promise<void>;\n\treadFile(path: string): Promise<Buffer>;\n\twriteFile(path: string, content: string | Buffer): Promise<void>;\n\tuploadFile?(sourcePath: string, destinationPath: string): Promise<void>;\n\tdownloadFile?(sourcePath: string, destinationPath: string): Promise<void>;\n\tmkdir(path: string, options?: { recursive?: boolean }): Promise<void>;\n\tstat(path: string): Promise<ToolFileStat>;\n\treaddir(path: string): Promise<string[]>;\n\tglob?(pattern: string, cwd: string, options: ToolGlobOptions): Promise<string[]>;\n\tgrep?(options: ToolGrepOptions): Promise<ToolGrepResult>;\n\tdetectImageMimeType?(path: string): Promise<string | null | undefined>;\n\tgetBackendInfo?(): ToolBackendInfo;\n\tdispose?(): Promise<void>;\n}\n\nexport interface LocalToolOperationsOptions {\n\tshellPath?: string;\n}\n\nexport interface SshToolOperationsOptions {\n\tremote: string;\n\tcwd: string;\n}\n\nexport interface DeferredRemoteToolOperationsConfigureSshOptions {\n\tremote: string;\n\tcwd?: string;\n}\n\nexport interface ParsedSshTarget {\n\tremote: string;\n\tcwd?: string;\n}\n\nfunction accessModeToFsMode(mode: ToolAccessMode | undefined): number {\n\tswitch (mode) {\n\t\tcase \"read\":\n\t\t\treturn constants.R_OK;\n\t\tcase \"write\":\n\t\t\treturn constants.W_OK;\n\t\tcase \"readwrite\":\n\t\t\treturn constants.R_OK | constants.W_OK;\n\t\tcase \"exists\":\n\t\tcase undefined:\n\t\t\treturn constants.F_OK;\n\t}\n}\n\nfunction shellQuote(value: string): string {\n\treturn `'${value.replace(/'/g, `'\\\\''`)}'`;\n}\n\nfunction parseSshTarget(value: string): ParsedSshTarget {\n\tconst separatorIndex = value.indexOf(\":\");\n\tif (separatorIndex === -1) {\n\t\treturn { remote: value };\n\t}\n\tconst remote = value.slice(0, separatorIndex);\n\tconst cwd = value.slice(separatorIndex + 1);\n\treturn cwd ? { remote, cwd } : { remote };\n}\n\nfunction validateSshRemote(remote: string): void {\n\tif (!remote) {\n\t\tthrow new Error(\"--ssh requires a remote target like user@host or user@host:/path\");\n\t}\n\tif (remote.startsWith(\"-\")) {\n\t\tthrow new Error(\"--ssh remote target must not start with '-'\");\n\t}\n}\n\nfunction sshArgs(remote: string, command: string): string[] {\n\tvalidateSshRemote(remote);\n\treturn [\"--\", remote, command];\n}\n\nfunction buildFdArgs(pattern: string, searchPath: string, limit: number): string[] {\n\tconst args: string[] = [\"--glob\", \"--color=never\", \"--hidden\", \"--no-require-git\", \"--max-results\", String(limit)];\n\tlet effectivePattern = pattern;\n\tif (pattern.includes(\"/\")) {\n\t\targs.push(\"--full-path\");\n\t\tif (!pattern.startsWith(\"/\") && !pattern.startsWith(\"**/\") && pattern !== \"**\") {\n\t\t\teffectivePattern = `**/${pattern}`;\n\t\t}\n\t}\n\targs.push(\"--\", effectivePattern, searchPath);\n\treturn args;\n}\n\nfunction buildRgArgs(options: ToolGrepOptions): string[] {\n\tconst args: string[] = [\"--json\", \"--line-number\", \"--color=never\", \"--hidden\"];\n\tif (options.ignoreCase) args.push(\"--ignore-case\");\n\tif (options.literal) args.push(\"--fixed-strings\");\n\tif (options.glob) args.push(\"--glob\", options.glob);\n\targs.push(\"--\", options.pattern, options.path);\n\treturn args;\n}\n\nfunction commandWithArgs(command: string, args: string[]): string {\n\treturn [command, ...args.map(shellQuote)].join(\" \");\n}\n\nasync function copyFileStream(sourcePath: string, destinationPath: string): Promise<void> {\n\tawait pipeline(createReadStream(sourcePath), createWriteStream(destinationPath));\n}\n\nfunction writeStreamChunk(stream: WriteStream, chunk: Buffer): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst onError = (error: Error) => {\n\t\t\tstream.off(\"error\", onError);\n\t\t\treject(error);\n\t\t};\n\t\tstream.once(\"error\", onError);\n\t\tstream.write(chunk, (error) => {\n\t\t\tstream.off(\"error\", onError);\n\t\t\tif (error) {\n\t\t\t\treject(error);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresolve();\n\t\t});\n\t});\n}\n\nfunction endWriteStream(stream: WriteStream): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst onError = (error: Error) => {\n\t\t\tstream.off(\"error\", onError);\n\t\t\treject(error);\n\t\t};\n\t\tstream.once(\"error\", onError);\n\t\tstream.end(() => {\n\t\t\tstream.off(\"error\", onError);\n\t\t\tresolve();\n\t\t});\n\t});\n}\n\nfunction waitForSshFileTransfer(\n\tremote: string,\n\tcommand: string,\n\twireStreams: (child: ReturnType<typeof spawn>) => Promise<void>,\n): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst child = spawn(\"ssh\", sshArgs(remote, command), { stdio: [\"pipe\", \"pipe\", \"pipe\"] });\n\t\tconst stderr: Buffer[] = [];\n\t\tchild.stderr.on(\"data\", (data: Buffer) => stderr.push(data));\n\t\tchild.on(\"error\", reject);\n\t\twireStreams(child).catch((error: unknown) => {\n\t\t\tchild.kill();\n\t\t\treject(error instanceof Error ? error : new Error(String(error)));\n\t\t});\n\t\tchild.on(\"close\", (code) => {\n\t\t\tif (code !== 0) {\n\t\t\t\treject(new Error(Buffer.concat(stderr).toString(\"utf-8\").trim() || `ssh exited with code ${code}`));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresolve();\n\t\t});\n\t});\n}\n\nasync function runSshBuffer(\n\tremote: string,\n\tcommand: string,\n\toptions: { input?: Buffer | string; signal?: AbortSignal; timeout?: number } = {},\n): Promise<Buffer> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst child = spawn(\"ssh\", sshArgs(remote, command), { stdio: [\"pipe\", \"pipe\", \"pipe\"] });\n\t\tconst stdout: Buffer[] = [];\n\t\tconst stderr: Buffer[] = [];\n\t\tlet timedOut = false;\n\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\tif (options.timeout !== undefined && options.timeout > 0) {\n\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\ttimedOut = true;\n\t\t\t\tchild.kill();\n\t\t\t}, options.timeout * 1000);\n\t\t}\n\t\tchild.stdout.on(\"data\", (data: Buffer) => stdout.push(data));\n\t\tchild.stderr.on(\"data\", (data: Buffer) => stderr.push(data));\n\t\tchild.on(\"error\", reject);\n\t\tconst onAbort = () => child.kill();\n\t\toptions.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\tif (options.input !== undefined) {\n\t\t\tchild.stdin.end(options.input);\n\t\t} else {\n\t\t\tchild.stdin.end();\n\t\t}\n\t\tchild.on(\"close\", (code) => {\n\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\toptions.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\tif (options.signal?.aborted) {\n\t\t\t\treject(new Error(\"aborted\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (timedOut) {\n\t\t\t\treject(new Error(`timeout:${options.timeout}`));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (code !== 0) {\n\t\t\t\treject(new Error(Buffer.concat(stderr).toString(\"utf-8\").trim() || `ssh exited with code ${code}`));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresolve(Buffer.concat(stdout));\n\t\t});\n\t});\n}\n\nexport class LocalToolOperations implements ToolOperations {\n\tcwd: string;\n\tprivate shellPath: string | undefined;\n\n\tconstructor(cwd: string, options: LocalToolOperationsOptions = {}) {\n\t\tthis.cwd = cwd;\n\t\tthis.shellPath = options.shellPath;\n\t}\n\n\tasync exec(command: string, options: ToolExecOptions): Promise<{ exitCode: number | null }> {\n\t\tconst cwd = options.cwd ?? this.cwd;\n\t\tconst { shell, args } = getShellConfig(this.shellPath);\n\t\ttry {\n\t\t\tawait fsAccess(cwd, constants.F_OK);\n\t\t} catch {\n\t\t\tthrow new Error(`Working directory does not exist: ${cwd}\\nCannot execute bash commands.`);\n\t\t}\n\t\tif (options.signal?.aborted) {\n\t\t\tthrow new Error(\"aborted\");\n\t\t}\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst child = spawn(shell, [...args, command], {\n\t\t\t\tcwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: options.env ?? getShellEnv(),\n\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\t\t\tlet timedOut = false;\n\t\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\t\tif (options.timeout !== undefined && options.timeout > 0) {\n\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\ttimedOut = true;\n\t\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t\t}, options.timeout * 1000);\n\t\t\t}\n\t\t\tchild.stdout?.on(\"data\", options.onData);\n\t\t\tchild.stderr?.on(\"data\", options.onData);\n\t\t\tconst onAbort = () => {\n\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t};\n\t\t\tif (options.signal) {\n\t\t\t\tif (options.signal.aborted) onAbort();\n\t\t\t\telse options.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t}\n\t\t\twaitForChildProcess(child)\n\t\t\t\t.then((code) => {\n\t\t\t\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\t\tif (options.signal) options.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\tif (options.signal?.aborted) {\n\t\t\t\t\t\treject(new Error(\"aborted\"));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (timedOut) {\n\t\t\t\t\t\treject(new Error(`timeout:${options.timeout}`));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tresolve({ exitCode: code });\n\t\t\t\t})\n\t\t\t\t.catch((error: unknown) => {\n\t\t\t\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\t\tif (options.signal) options.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\treject(error);\n\t\t\t\t});\n\t\t});\n\t}\n\n\tasync access(path: string, mode?: ToolAccessMode): Promise<void> {\n\t\tawait fsAccess(path, accessModeToFsMode(mode));\n\t}\n\n\tasync readFile(path: string): Promise<Buffer> {\n\t\treturn fsReadFile(path);\n\t}\n\n\tasync writeFile(path: string, content: string | Buffer): Promise<void> {\n\t\tawait fsWriteFile(path, content, typeof content === \"string\" ? \"utf-8\" : undefined);\n\t}\n\n\tasync uploadFile(sourcePath: string, destinationPath: string): Promise<void> {\n\t\tawait copyFileStream(sourcePath, destinationPath);\n\t}\n\n\tasync downloadFile(sourcePath: string, destinationPath: string): Promise<void> {\n\t\tawait copyFileStream(sourcePath, destinationPath);\n\t}\n\n\tasync mkdir(path: string, options: { recursive?: boolean } = {}): Promise<void> {\n\t\tawait fsMkdir(path, { recursive: options.recursive ?? false });\n\t}\n\n\tasync stat(path: string): Promise<Stats> {\n\t\treturn fsStat(path);\n\t}\n\n\tasync readdir(path: string): Promise<string[]> {\n\t\treturn fsReaddir(path);\n\t}\n\n\tasync detectImageMimeType(path: string): Promise<string | null | undefined> {\n\t\treturn detectSupportedImageMimeTypeFromFile(path);\n\t}\n\n\tgetBackendInfo(): ToolBackendInfo {\n\t\treturn { type: \"local\", cwd: this.cwd };\n\t}\n}\n\nexport class SshToolOperations implements ToolOperations {\n\treadonly remote: string;\n\tcwd: string;\n\n\tconstructor(options: SshToolOperationsOptions) {\n\t\tthis.remote = options.remote;\n\t\tthis.cwd = options.cwd;\n\t}\n\n\tstatic async fromTarget(target: string): Promise<SshToolOperations> {\n\t\tconst parsed = parseSshTarget(target);\n\t\tvalidateSshRemote(parsed.remote);\n\t\tconst cwd = parsed.cwd ?? (await runSshBuffer(parsed.remote, \"pwd\")).toString(\"utf-8\").trim();\n\t\treturn new SshToolOperations({ remote: parsed.remote, cwd });\n\t}\n\n\tasync exec(command: string, options: ToolExecOptions): Promise<{ exitCode: number | null }> {\n\t\tconst cwd = options.cwd ?? this.cwd;\n\t\tconst remoteCommand = `cd ${shellQuote(cwd)} && bash -s`;\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst child = spawn(\"ssh\", sshArgs(this.remote, remoteCommand), {\n\t\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\t});\n\t\t\tlet timedOut = false;\n\t\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\t\tif (options.timeout !== undefined && options.timeout > 0) {\n\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\ttimedOut = true;\n\t\t\t\t\tchild.kill();\n\t\t\t\t}, options.timeout * 1000);\n\t\t\t}\n\t\t\tchild.stdout?.on(\"data\", options.onData);\n\t\t\tchild.stderr?.on(\"data\", options.onData);\n\t\t\tchild.on(\"error\", reject);\n\t\t\tchild.stdin.end(command);\n\t\t\tconst onAbort = () => child.kill();\n\t\t\toptions.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\tchild.on(\"close\", (code) => {\n\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\toptions.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\tif (options.signal?.aborted) {\n\t\t\t\t\treject(new Error(\"aborted\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (timedOut) {\n\t\t\t\t\treject(new Error(`timeout:${options.timeout}`));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tresolve({ exitCode: code });\n\t\t\t});\n\t\t});\n\t}\n\n\tasync access(path: string, mode?: ToolAccessMode): Promise<void> {\n\t\tconst remotePath = shellQuote(path);\n\t\tif (mode === \"readwrite\") {\n\t\t\tawait runSshBuffer(this.remote, `test -r ${remotePath} && test -w ${remotePath}`);\n\t\t\treturn;\n\t\t}\n\t\tconst flag = mode === \"read\" ? \"-r\" : mode === \"write\" ? \"-w\" : \"-e\";\n\t\tawait runSshBuffer(this.remote, `test ${flag} ${remotePath}`);\n\t}\n\n\tasync readFile(path: string): Promise<Buffer> {\n\t\treturn runSshBuffer(this.remote, `cat ${shellQuote(path)}`);\n\t}\n\n\tasync writeFile(path: string, content: string | Buffer): Promise<void> {\n\t\tawait runSshBuffer(this.remote, `base64 -d > ${shellQuote(path)}`, {\n\t\t\tinput: Buffer.from(content).toString(\"base64\"),\n\t\t});\n\t}\n\n\tasync uploadFile(sourcePath: string, destinationPath: string): Promise<void> {\n\t\tawait waitForSshFileTransfer(this.remote, `cat > ${shellQuote(destinationPath)}`, async (child) => {\n\t\t\tif (!child.stdin) throw new Error(\"ssh stdin is unavailable\");\n\t\t\tawait pipeline(createReadStream(sourcePath), child.stdin);\n\t\t});\n\t}\n\n\tasync downloadFile(sourcePath: string, destinationPath: string): Promise<void> {\n\t\tawait waitForSshFileTransfer(this.remote, `cat ${shellQuote(sourcePath)}`, async (child) => {\n\t\t\tif (!child.stdout) throw new Error(\"ssh stdout is unavailable\");\n\t\t\tawait pipeline(child.stdout, createWriteStream(destinationPath));\n\t\t});\n\t}\n\n\tasync mkdir(path: string, options: { recursive?: boolean } = {}): Promise<void> {\n\t\tconst flag = options.recursive ? \"-p \" : \"\";\n\t\tawait runSshBuffer(this.remote, `mkdir ${flag}${shellQuote(path)}`);\n\t}\n\n\tasync stat(path: string): Promise<ToolFileStat> {\n\t\tconst output = await runSshBuffer(\n\t\t\tthis.remote,\n\t\t\t`if test -d ${shellQuote(path)}; then echo d; elif test -f ${shellQuote(path)}; then echo f; else test -e ${shellQuote(path)} && echo o || exit 1; fi`,\n\t\t);\n\t\tconst kind = output.toString(\"utf-8\").trim();\n\t\treturn {\n\t\t\tisDirectory: () => kind === \"d\",\n\t\t\tisFile: () => kind === \"f\",\n\t\t};\n\t}\n\n\tasync readdir(path: string): Promise<string[]> {\n\t\tconst output = await runSshBuffer(\n\t\t\tthis.remote,\n\t\t\t`find ${shellQuote(path)} -maxdepth 1 -mindepth 1 -printf '%f\\\\n'`,\n\t\t);\n\t\treturn output.toString(\"utf-8\").split(\"\\n\").filter(Boolean);\n\t}\n\n\tasync glob(pattern: string, cwd: string, options: ToolGlobOptions): Promise<string[]> {\n\t\tconst command = commandWithArgs(\"fd\", buildFdArgs(pattern, cwd, options.limit));\n\t\tconst output = await runSshBuffer(this.remote, command);\n\t\treturn output.toString(\"utf-8\").split(\"\\n\").filter(Boolean);\n\t}\n\n\tasync grep(options: ToolGrepOptions): Promise<ToolGrepResult> {\n\t\tconst isDirectory = (await this.stat(options.path)).isDirectory();\n\t\tconst command = commandWithArgs(\"rg\", buildRgArgs(options));\n\t\tconst output = await runSshBuffer(this.remote, command).catch((error: unknown) => {\n\t\t\tif (error instanceof Error && error.message.includes(\"ssh exited with code 1\")) {\n\t\t\t\treturn Buffer.alloc(0);\n\t\t\t}\n\t\t\tthrow error;\n\t\t});\n\t\tconst matches: ToolGrepMatch[] = [];\n\t\tfor (const line of output.toString(\"utf-8\").split(\"\\n\")) {\n\t\t\tif (!line.trim() || matches.length >= options.limit) continue;\n\t\t\tlet event: unknown;\n\t\t\ttry {\n\t\t\t\tevent = JSON.parse(line);\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!event || typeof event !== \"object\" || !(\"type\" in event) || event.type !== \"match\") continue;\n\t\t\tconst data = \"data\" in event && event.data && typeof event.data === \"object\" ? event.data : undefined;\n\t\t\tconst filePath =\n\t\t\t\tdata && \"path\" in data && data.path && typeof data.path === \"object\" && \"text\" in data.path\n\t\t\t\t\t? data.path.text\n\t\t\t\t\t: undefined;\n\t\t\tconst lineNumber = data && \"line_number\" in data ? data.line_number : undefined;\n\t\t\tconst lineText =\n\t\t\t\tdata && \"lines\" in data && data.lines && typeof data.lines === \"object\" && \"text\" in data.lines\n\t\t\t\t\t? data.lines.text\n\t\t\t\t\t: undefined;\n\t\t\tif (typeof filePath === \"string\" && typeof lineNumber === \"number\") {\n\t\t\t\tmatches.push({ filePath, lineNumber, lineText: typeof lineText === \"string\" ? lineText : undefined });\n\t\t\t}\n\t\t}\n\t\treturn { isDirectory, matches };\n\t}\n\n\tasync detectImageMimeType(path: string): Promise<string | null | undefined> {\n\t\ttry {\n\t\t\tconst output = await runSshBuffer(this.remote, `file --mime-type -b ${shellQuote(path)}`);\n\t\t\tconst mimeType = output.toString(\"utf-8\").trim();\n\t\t\treturn [\"image/jpeg\", \"image/png\", \"image/gif\", \"image/webp\"].includes(mimeType) ? mimeType : null;\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tgetBackendInfo(): ToolBackendInfo {\n\t\treturn { type: \"ssh\", remote: this.remote, cwd: this.cwd, configured: true };\n\t}\n\n\tasync dispose(): Promise<void> {}\n}\n\nexport class DeferredRemoteToolOperations implements ToolOperations {\n\tcwd: string;\n\tprivate operations: SshToolOperations | RemoteToolOperations | undefined;\n\n\tconstructor(cwd: string) {\n\t\tthis.cwd = cwd;\n\t}\n\n\tasync configure(options: DeferredRemoteToolOperationsConfigureSshOptions): Promise<ToolBackendInfo> {\n\t\tconst next = new SshToolOperations({ remote: options.remote, cwd: options.cwd ?? this.cwd });\n\t\tconst stat = await next.stat(next.cwd);\n\t\tif (!stat.isDirectory()) {\n\t\t\tthrow new Error(`SSH backend cwd is not a directory: ${next.cwd}`);\n\t\t}\n\t\tawait this.operations?.dispose?.();\n\t\tthis.cwd = next.cwd;\n\t\tthis.operations = next;\n\t\treturn this.getBackendInfo();\n\t}\n\n\tasync configureRemote(url: string): Promise<ToolBackendInfo> {\n\t\tconst next = await createRemoteToolOperations(url);\n\t\tconst stat = await next.stat(next.cwd);\n\t\tif (!stat.isDirectory()) {\n\t\t\tthrow new Error(`Remote daemon cwd is not a directory: ${next.cwd}`);\n\t\t}\n\t\tawait this.operations?.dispose?.();\n\t\tthis.cwd = next.cwd;\n\t\tthis.operations = next;\n\t\treturn this.getBackendInfo();\n\t}\n\n\tclear(): void {\n\t\tvoid this.operations?.dispose?.();\n\t\tthis.operations = undefined;\n\t}\n\n\tprivate requireOperations(): SshToolOperations | RemoteToolOperations {\n\t\tif (!this.operations) {\n\t\t\tthrow new Error(\"Remote backend is not configured. Configure it over RPC or with /remote before using tools.\");\n\t\t}\n\t\treturn this.operations;\n\t}\n\n\tasync exec(command: string, options: ToolExecOptions): Promise<{ exitCode: number | null }> {\n\t\treturn this.requireOperations().exec(command, options);\n\t}\n\n\tasync access(path: string, mode?: ToolAccessMode): Promise<void> {\n\t\tawait this.requireOperations().access(path, mode);\n\t}\n\n\tasync readFile(path: string): Promise<Buffer> {\n\t\treturn this.requireOperations().readFile(path);\n\t}\n\n\tasync writeFile(path: string, content: string | Buffer): Promise<void> {\n\t\tawait this.requireOperations().writeFile(path, content);\n\t}\n\n\tasync uploadFile(sourcePath: string, destinationPath: string): Promise<void> {\n\t\tconst operations = this.requireOperations();\n\t\tif (!operations.uploadFile) throw new Error(\"Remote backend does not support file upload\");\n\t\tawait operations.uploadFile(sourcePath, destinationPath);\n\t}\n\n\tasync downloadFile(sourcePath: string, destinationPath: string): Promise<void> {\n\t\tconst operations = this.requireOperations();\n\t\tif (!operations.downloadFile) throw new Error(\"Remote backend does not support file download\");\n\t\tawait operations.downloadFile(sourcePath, destinationPath);\n\t}\n\n\tasync mkdir(path: string, options?: { recursive?: boolean }): Promise<void> {\n\t\tawait this.requireOperations().mkdir(path, options);\n\t}\n\n\tasync stat(path: string): Promise<ToolFileStat> {\n\t\treturn this.requireOperations().stat(path);\n\t}\n\n\tasync readdir(path: string): Promise<string[]> {\n\t\treturn this.requireOperations().readdir(path);\n\t}\n\n\tasync glob(pattern: string, cwd: string, options: ToolGlobOptions): Promise<string[]> {\n\t\treturn this.requireOperations().glob(pattern, cwd, options);\n\t}\n\n\tasync grep(options: ToolGrepOptions): Promise<ToolGrepResult> {\n\t\treturn this.requireOperations().grep(options);\n\t}\n\n\tasync detectImageMimeType(path: string): Promise<string | null | undefined> {\n\t\treturn this.requireOperations().detectImageMimeType(path);\n\t}\n\n\tgetBackendInfo(): ToolBackendInfo {\n\t\treturn this.operations?.getBackendInfo() ?? { type: \"remote\", cwd: this.cwd, configured: false };\n\t}\n}\n\ntype RemoteResponse = { id: string; result: unknown } | { id: string; error: { message?: unknown } | string };\n\ntype RemoteExecEvent =\n\t| { id: string; event: \"data\"; dataBase64?: unknown; data?: unknown; stream?: unknown }\n\t| { id: string; event: \"exit\"; exitCode?: unknown; cancelled?: unknown }\n\t| { id: string; event: \"error\"; error?: { message?: unknown } | string };\n\ntype RemoteFileEvent =\n\t| { id: string; event: \"fileData\"; dataBase64?: unknown }\n\t| { id: string; event: \"fileEnd\" }\n\t| { id: string; event: \"fileError\"; error?: { message?: unknown } | string };\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction remoteErrorMessage(error: unknown): string {\n\tif (typeof error === \"string\") return error;\n\tif (isRecord(error) && typeof error.message === \"string\") return error.message;\n\treturn \"remote operation failed\";\n}\n\nfunction requireString(value: unknown, name: string): string {\n\tif (typeof value !== \"string\") throw new Error(`Remote response missing string ${name}`);\n\treturn value;\n}\n\nfunction optionalString(value: unknown): string | undefined {\n\treturn typeof value === \"string\" ? value : undefined;\n}\n\nfunction optionalNumber(value: unknown): number | undefined {\n\treturn typeof value === \"number\" ? value : undefined;\n}\n\nfunction normalizeRemoteUrl(url: string): { url: string; protocol: \"ws\" } {\n\tconst parsed = new URL(url);\n\tif (parsed.protocol !== \"ws:\" && parsed.protocol !== \"wss:\") {\n\t\tthrow new Error(`--remote currently supports ws:// and wss:// URLs, got ${parsed.protocol}`);\n\t}\n\treturn { url, protocol: \"ws\" };\n}\n\nexport class RemoteToolOperations implements ToolOperations {\n\treadonly url: string;\n\treadonly protocol: \"ws\";\n\tcwd: string;\n\tprivate socket: WebSocket;\n\tprivate nextId = 1;\n\tprivate pending = new Map<\n\t\tstring,\n\t\t{\n\t\t\tresolve: (value: unknown) => void;\n\t\t\treject: (error: Error) => void;\n\t\t}\n\t>();\n\tprivate execPending = new Map<\n\t\tstring,\n\t\t{\n\t\t\tonData: (data: Buffer) => void;\n\t\t\tresolve: (value: { exitCode: number | null }) => void;\n\t\t\treject: (error: Error) => void;\n\t\t}\n\t>();\n\tprivate fileDownloadPending = new Map<\n\t\tstring,\n\t\t{\n\t\t\tstream: WriteStream;\n\t\t\twritePromise: Promise<void>;\n\t\t\tresolve: () => void;\n\t\t\treject: (error: Error) => void;\n\t\t}\n\t>();\n\tprivate keepAliveInterval: NodeJS.Timeout | undefined;\n\tprivate lastPongAt = Date.now();\n\n\tprivate constructor(url: string, protocol: \"ws\", socket: WebSocket, cwd: string) {\n\t\tthis.url = url;\n\t\tthis.protocol = protocol;\n\t\tthis.socket = socket;\n\t\tthis.cwd = cwd;\n\t\tthis.socket.addEventListener(\"message\", (event) => this.handleMessage(event.data));\n\t\tthis.socket.addEventListener(\"close\", () => {\n\t\t\tthis.stopKeepAlive();\n\t\t\tthis.rejectAll(new Error(\"remote connection closed\"));\n\t\t});\n\t\tthis.socket.addEventListener(\"error\", () => {\n\t\t\tthis.stopKeepAlive();\n\t\t\tthis.rejectAll(new Error(\"remote connection error\"));\n\t\t});\n\t\tthis.startKeepAlive();\n\t}\n\n\tstatic async connect(url: string): Promise<RemoteToolOperations> {\n\t\tconst normalized = normalizeRemoteUrl(url);\n\t\tconst socket = await new Promise<WebSocket>((resolveSocket, rejectSocket) => {\n\t\t\tconst ws = new WebSocket(normalized.url);\n\t\t\tconst cleanup = () => {\n\t\t\t\tws.removeEventListener(\"open\", onOpen);\n\t\t\t\tws.removeEventListener(\"error\", onError);\n\t\t\t};\n\t\t\tconst onOpen = () => {\n\t\t\t\tcleanup();\n\t\t\t\tresolveSocket(ws);\n\t\t\t};\n\t\t\tconst onError = () => {\n\t\t\t\tcleanup();\n\t\t\t\trejectSocket(new Error(`failed to connect remote commander: ${normalized.url}`));\n\t\t\t};\n\t\t\tws.addEventListener(\"open\", onOpen, { once: true });\n\t\t\tws.addEventListener(\"error\", onError, { once: true });\n\t\t});\n\t\tconst operations = new RemoteToolOperations(normalized.url, normalized.protocol, socket, \"/\");\n\t\tconst capabilities = await operations.request(\"capabilities\", {});\n\t\tif (isRecord(capabilities) && typeof capabilities.cwd === \"string\") {\n\t\t\toperations.cwd = capabilities.cwd;\n\t\t}\n\t\treturn operations;\n\t}\n\n\tprivate startKeepAlive(): void {\n\t\tthis.keepAliveInterval = setInterval(() => {\n\t\t\tif (Date.now() - this.lastPongAt > 90_000) {\n\t\t\t\tthis.stopKeepAlive();\n\t\t\t\tthis.rejectAll(new Error(\"remote connection heartbeat timed out\"));\n\t\t\t\tthis.socket.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tthis.send({ type: \"ping\", timestamp: Date.now() });\n\t\t\t} catch (error) {\n\t\t\t\tthis.stopKeepAlive();\n\t\t\t\tthis.rejectAll(error instanceof Error ? error : new Error(String(error)));\n\t\t\t}\n\t\t}, 30_000);\n\t\tthis.keepAliveInterval.unref?.();\n\t}\n\n\tprivate stopKeepAlive(): void {\n\t\tif (this.keepAliveInterval) {\n\t\t\tclearInterval(this.keepAliveInterval);\n\t\t\tthis.keepAliveInterval = undefined;\n\t\t}\n\t}\n\n\tprivate rejectAll(error: Error): void {\n\t\tfor (const pending of this.pending.values()) pending.reject(error);\n\t\tthis.pending.clear();\n\t\tfor (const pending of this.execPending.values()) pending.reject(error);\n\t\tthis.execPending.clear();\n\t\tfor (const pending of this.fileDownloadPending.values()) {\n\t\t\tpending.stream.destroy(error);\n\t\t\tpending.reject(error);\n\t\t}\n\t\tthis.fileDownloadPending.clear();\n\t}\n\n\tprivate send(message: Record<string, unknown>): void {\n\t\tif (this.socket.readyState !== WebSocket.OPEN) {\n\t\t\tthrow new Error(\"remote connection is not open\");\n\t\t}\n\t\tthis.socket.send(JSON.stringify(message));\n\t}\n\n\tprivate request(method: string, params: Record<string, unknown>): Promise<unknown> {\n\t\tconst id = `remote-${this.nextId++}`;\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.pending.set(id, { resolve, reject });\n\t\t\ttry {\n\t\t\t\tthis.send({ id, method, params });\n\t\t\t} catch (error) {\n\t\t\t\tthis.pending.delete(id);\n\t\t\t\treject(error instanceof Error ? error : new Error(String(error)));\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate handleMessage(data: unknown): void {\n\t\tif (typeof data !== \"string\") return;\n\t\tlet parsed: unknown;\n\t\ttry {\n\t\t\tparsed = JSON.parse(data);\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\t\tif (!isRecord(parsed)) return;\n\t\tif (parsed.type === \"pong\") {\n\t\t\tthis.lastPongAt = Date.now();\n\t\t\treturn;\n\t\t}\n\t\tif (typeof parsed.id !== \"string\") return;\n\t\tif (typeof parsed.event === \"string\") {\n\t\t\tif (parsed.event === \"fileData\" || parsed.event === \"fileEnd\" || parsed.event === \"fileError\") {\n\t\t\t\tthis.handleFileEvent(parsed as RemoteFileEvent);\n\t\t\t} else {\n\t\t\t\tthis.handleExecEvent(parsed as RemoteExecEvent);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tconst pending = this.pending.get(parsed.id);\n\t\tif (!pending) return;\n\t\tthis.pending.delete(parsed.id);\n\t\tconst response = parsed as RemoteResponse;\n\t\tif (\"error\" in response) {\n\t\t\tpending.reject(new Error(remoteErrorMessage(response.error)));\n\t\t\treturn;\n\t\t}\n\t\tpending.resolve(response.result);\n\t}\n\n\tprivate handleExecEvent(event: RemoteExecEvent): void {\n\t\tconst pending = this.execPending.get(event.id);\n\t\tif (!pending) return;\n\t\tif (event.event === \"data\") {\n\t\t\tconst encoded = optionalString(event.dataBase64);\n\t\t\tconst text = optionalString(event.data);\n\t\t\tif (encoded !== undefined) pending.onData(Buffer.from(encoded, \"base64\"));\n\t\t\telse if (text !== undefined) pending.onData(Buffer.from(text));\n\t\t\treturn;\n\t\t}\n\t\tthis.execPending.delete(event.id);\n\t\tif (event.event === \"error\") {\n\t\t\tpending.reject(new Error(remoteErrorMessage(event.error)));\n\t\t\treturn;\n\t\t}\n\t\tconst exitCode = optionalNumber(event.exitCode) ?? null;\n\t\tpending.resolve({ exitCode });\n\t}\n\n\tprivate handleFileEvent(event: RemoteFileEvent): void {\n\t\tconst pending = this.fileDownloadPending.get(event.id);\n\t\tif (!pending) return;\n\t\tif (event.event === \"fileData\") {\n\t\t\tconst encoded = optionalString(event.dataBase64);\n\t\t\tif (encoded === undefined) return;\n\t\t\tpending.writePromise = pending.writePromise.then(() =>\n\t\t\t\twriteStreamChunk(pending.stream, Buffer.from(encoded, \"base64\")),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tthis.fileDownloadPending.delete(event.id);\n\t\tif (event.event === \"fileError\") {\n\t\t\tconst error = new Error(remoteErrorMessage(event.error));\n\t\t\tpending.reject(error);\n\t\t\tpending.stream.destroy(error);\n\t\t\treturn;\n\t\t}\n\t\tpending.writePromise.then(() => endWriteStream(pending.stream)).then(pending.resolve, pending.reject);\n\t}\n\n\tasync exec(command: string, options: ToolExecOptions): Promise<{ exitCode: number | null }> {\n\t\tconst id = `remote-${this.nextId++}`;\n\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst cleanup = () => {\n\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\toptions.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\t};\n\t\t\tconst onAbort = () => {\n\t\t\t\ttry {\n\t\t\t\t\tthis.send({ id, method: \"cancel\" });\n\t\t\t\t} catch {}\n\t\t\t\tconst pending = this.execPending.get(id);\n\t\t\t\tif (pending) {\n\t\t\t\t\tthis.execPending.delete(id);\n\t\t\t\t\tcleanup();\n\t\t\t\t\tpending.reject(new Error(\"aborted\"));\n\t\t\t\t}\n\t\t\t};\n\t\t\tthis.execPending.set(id, {\n\t\t\t\tonData: options.onData,\n\t\t\t\tresolve: (value) => {\n\t\t\t\t\tcleanup();\n\t\t\t\t\tresolve(value);\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tcleanup();\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\t\t\toptions.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\tif (options.timeout !== undefined && options.timeout > 0) {\n\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tthis.send({ id, method: \"cancel\" });\n\t\t\t\t\t} catch {}\n\t\t\t\t\tconst pending = this.execPending.get(id);\n\t\t\t\t\tif (pending) {\n\t\t\t\t\t\tthis.execPending.delete(id);\n\t\t\t\t\t\tcleanup();\n\t\t\t\t\t\tpending.reject(new Error(`timeout:${options.timeout}`));\n\t\t\t\t\t}\n\t\t\t\t}, options.timeout * 1000);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tthis.send({\n\t\t\t\t\tid,\n\t\t\t\t\tmethod: \"exec\",\n\t\t\t\t\tparams: { command, cwd: options.cwd ?? this.cwd, env: options.env, timeout: options.timeout },\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthis.execPending.delete(id);\n\t\t\t\tcleanup();\n\t\t\t\treject(error instanceof Error ? error : new Error(String(error)));\n\t\t\t}\n\t\t});\n\t}\n\n\tasync access(path: string, mode?: ToolAccessMode): Promise<void> {\n\t\tawait this.request(\"access\", { path, mode });\n\t}\n\n\tasync readFile(path: string): Promise<Buffer> {\n\t\tconst result = await this.request(\"readFile\", { path });\n\t\tif (!isRecord(result)) throw new Error(\"Invalid remote readFile response\");\n\t\treturn Buffer.from(requireString(result.contentBase64, \"contentBase64\"), \"base64\");\n\t}\n\n\tasync writeFile(path: string, content: string | Buffer): Promise<void> {\n\t\tawait this.request(\"writeFile\", { path, contentBase64: Buffer.from(content).toString(\"base64\") });\n\t}\n\n\tasync uploadFile(sourcePath: string, destinationPath: string): Promise<void> {\n\t\tconst uploadId = `remote-${this.nextId++}`;\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tthis.pending.set(uploadId, { resolve: () => resolve(), reject });\n\t\t\ttry {\n\t\t\t\tthis.send({ id: uploadId, method: \"uploadFileStart\", params: { path: destinationPath } });\n\t\t\t} catch (error) {\n\t\t\t\tthis.pending.delete(uploadId);\n\t\t\t\treject(error instanceof Error ? error : new Error(String(error)));\n\t\t\t}\n\t\t});\n\t\ttry {\n\t\t\tfor await (const chunk of createReadStream(sourcePath, { highWaterMark: 64 * 1024 })) {\n\t\t\t\tconst buffer = typeof chunk === \"string\" ? Buffer.from(chunk) : chunk;\n\t\t\t\tawait this.request(\"uploadFileChunk\", { uploadId, dataBase64: buffer.toString(\"base64\") });\n\t\t\t}\n\t\t\tawait this.request(\"uploadFileEnd\", { uploadId });\n\t\t} catch (error) {\n\t\t\tawait this.request(\"uploadFileCancel\", { uploadId }).catch(() => undefined);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync downloadFile(sourcePath: string, destinationPath: string): Promise<void> {\n\t\tconst id = `remote-${this.nextId++}`;\n\t\tconst stream = createWriteStream(destinationPath);\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tconst cleanup = () => stream.off(\"error\", onStreamError);\n\t\t\tconst onStreamError = (error: Error) => {\n\t\t\t\tcleanup();\n\t\t\t\tthis.fileDownloadPending.delete(id);\n\t\t\t\treject(error);\n\t\t\t};\n\t\t\tstream.once(\"error\", onStreamError);\n\t\t\tthis.fileDownloadPending.set(id, {\n\t\t\t\tstream,\n\t\t\t\twritePromise: Promise.resolve(),\n\t\t\t\tresolve: () => {\n\t\t\t\t\tcleanup();\n\t\t\t\t\tresolve();\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tcleanup();\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\t\t\ttry {\n\t\t\t\tthis.send({ id, method: \"downloadFile\", params: { path: sourcePath } });\n\t\t\t} catch (error) {\n\t\t\t\tcleanup();\n\t\t\t\tthis.fileDownloadPending.delete(id);\n\t\t\t\tstream.destroy();\n\t\t\t\treject(error instanceof Error ? error : new Error(String(error)));\n\t\t\t}\n\t\t});\n\t}\n\n\tasync mkdir(path: string, options: { recursive?: boolean } = {}): Promise<void> {\n\t\tawait this.request(\"mkdir\", { path, recursive: options.recursive ?? false });\n\t}\n\n\tasync stat(path: string): Promise<ToolFileStat> {\n\t\tconst result = await this.request(\"stat\", { path });\n\t\tif (!isRecord(result)) throw new Error(\"Invalid remote stat response\");\n\t\tconst kind = optionalString(result.kind) ?? optionalString(result.type);\n\t\tconst isDirectory = result.isDirectory === true || kind === \"directory\" || kind === \"dir\";\n\t\tconst isFile = result.isFile === true || kind === \"file\";\n\t\treturn { isDirectory: () => isDirectory, isFile: () => isFile };\n\t}\n\n\tasync readdir(path: string): Promise<string[]> {\n\t\tconst result = await this.request(\"readdir\", { path });\n\t\tif (Array.isArray(result)) return result.filter((entry): entry is string => typeof entry === \"string\");\n\t\tif (!isRecord(result) || !Array.isArray(result.entries)) throw new Error(\"Invalid remote readdir response\");\n\t\treturn result.entries.filter((entry): entry is string => typeof entry === \"string\");\n\t}\n\n\tasync glob(pattern: string, cwd: string, options: ToolGlobOptions): Promise<string[]> {\n\t\tconst result = await this.request(\"glob\", { pattern, cwd, ignore: options.ignore, limit: options.limit });\n\t\tif (Array.isArray(result)) return result.filter((entry): entry is string => typeof entry === \"string\");\n\t\tif (!isRecord(result) || !Array.isArray(result.matches)) throw new Error(\"Invalid remote glob response\");\n\t\treturn result.matches.filter((entry): entry is string => typeof entry === \"string\");\n\t}\n\n\tasync grep(options: ToolGrepOptions): Promise<ToolGrepResult> {\n\t\tconst result = await this.request(\"grep\", options as unknown as Record<string, unknown>);\n\t\tif (!isRecord(result)) throw new Error(\"Invalid remote grep response\");\n\t\tconst matches = Array.isArray(result.matches) ? result.matches : [];\n\t\treturn {\n\t\t\tisDirectory: result.isDirectory === true,\n\t\t\tmatches: matches.flatMap((entry): ToolGrepMatch[] => {\n\t\t\t\tif (!isRecord(entry)) return [];\n\t\t\t\tconst filePath = optionalString(entry.filePath);\n\t\t\t\tconst lineNumber = optionalNumber(entry.lineNumber);\n\t\t\t\tif (!filePath || lineNumber === undefined) return [];\n\t\t\t\treturn [{ filePath, lineNumber, lineText: optionalString(entry.lineText) }];\n\t\t\t}),\n\t\t};\n\t}\n\n\tasync detectImageMimeType(path: string): Promise<string | null | undefined> {\n\t\tconst result = await this.request(\"detectImageMimeType\", { path });\n\t\tif (!isRecord(result)) return undefined;\n\t\tconst mimeType = optionalString(result.mimeType);\n\t\treturn mimeType && [\"image/jpeg\", \"image/png\", \"image/gif\", \"image/webp\"].includes(mimeType) ? mimeType : null;\n\t}\n\n\tgetBackendInfo(): ToolBackendInfo {\n\t\treturn { type: \"remote\", cwd: this.cwd, url: this.url, protocol: this.protocol, configured: true };\n\t}\n\n\tasync dispose(): Promise<void> {\n\t\tthis.stopKeepAlive();\n\t\tthis.socket.close();\n\t}\n}\n\nexport function createRemoteToolOperations(url: string): Promise<RemoteToolOperations> {\n\treturn RemoteToolOperations.connect(url);\n}\n\nexport function createSshToolOperations(target: string): Promise<SshToolOperations> {\n\treturn SshToolOperations.fromTarget(target);\n}\n"]}
@@ -191,6 +191,18 @@ export declare class RpcClient {
191
191
  * Clear the deferred remote sandbox configuration.
192
192
  */
193
193
  clearRemoteSandbox(): Promise<ToolBackendInfo>;
194
+ /**
195
+ * Upload a file from the RPC process filesystem to the active sandbox backend.
196
+ */
197
+ uploadFile(sourcePath: string, destinationPath: string): Promise<{
198
+ bytes: number;
199
+ }>;
200
+ /**
201
+ * Download a file from the active sandbox backend to the RPC process filesystem.
202
+ */
203
+ downloadFile(sourcePath: string, destinationPath: string): Promise<{
204
+ bytes: number;
205
+ }>;
194
206
  /**
195
207
  * Get session statistics.
196
208
  */
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-client.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACzF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACpF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAEvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,KAAK,EACX,6BAA6B,EAE7B,sBAAsB,EAGtB,eAAe,EACf,eAAe,EACf,MAAM,gBAAgB,CAAC;AAYxB,MAAM,WAAW,qBAAqB;IACrC,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,EAAE,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAChC,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,YAAY,CAAC,EA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,IAAI,CAAC,CAqBlD;IAED;;;OAGG;IACH,aAAa,CAAC,OAAO,SAAgB,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAuB5D;IAED;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,EAAE,EAAE,OAAO,SAAgB,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAI5G;IAMD,OAAO,CAAC,UAAU;IAqBlB,OAAO,CAAC,sBAAsB;IAI9B,OAAO,CAAC,qBAAqB;YAOf,IAAI;IAmDlB,OAAO,CAAC,OAAO;CAUf","sourcesContent":["/**\n * RPC Client for programmatic access to the coding agent.\n *\n * Spawns the agent in RPC mode and provides a typed API for all operations.\n */\n\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport type { AgentEvent, AgentMessage, ThinkingLevel } from \"@fleetagent/pi-agent-core\";\nimport type { ImageContent } from \"@fleetagent/pi-ai\";\nimport type { Static, TSchema } from \"typebox\";\nimport type { SessionStats, StructuredResponse } from \"../../core/agent-session.ts\";\nimport type { BashResult } from \"../../core/bash-executor.ts\";\nimport type { CompactionResult } from \"../../core/compaction/index.ts\";\nimport type { SessionInfo } from \"../../core/session/types.ts\";\nimport type { ToolBackendInfo } from \"../../core/tools/index.ts\";\nimport { attachJsonlLineReader, serializeJsonLine } from \"./jsonl.ts\";\nimport type {\n\tRpcClientListSessionsResponse,\n\tRpcCommand,\n\tRpcListSessionsOptions,\n\tRpcListSessionsResponse,\n\tRpcResponse,\n\tRpcSessionState,\n\tRpcSlashCommand,\n} from \"./rpc-types.ts\";\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/** Distributive Omit that works with union types */\ntype DistributiveOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never;\n\n/** RpcCommand without the id field (for internal send) */\ntype RpcCommandBody = DistributiveOmit<RpcCommand, \"id\">;\n\nexport interface RpcClientStartCommand {\n\t/** Executable to spawn. */\n\tcommand: string;\n\t/** Arguments passed to the executable. */\n\targs: string[];\n}\n\nexport interface RpcClientOptions {\n\t/** Path to the CLI entry point (default: searches for dist/cli.js) */\n\tcliPath?: string;\n\t/** Override the process command used to start the RPC agent. */\n\tstartCommand?: RpcClientStartCommand | ((defaultCommand: RpcClientStartCommand) => RpcClientStartCommand);\n\t/** Working directory for the agent */\n\tcwd?: string;\n\t/** Environment variables */\n\tenv?: Record<string, string>;\n\t/** Provider to use */\n\tprovider?: string;\n\t/** Model ID to use */\n\tmodel?: string;\n\t/** Additional CLI arguments */\n\targs?: string[];\n}\n\nexport interface ModelInfo {\n\tprovider: string;\n\tid: string;\n\tcontextWindow: number;\n\treasoning: boolean;\n}\n\nexport type RpcEventListener = (event: AgentEvent) => void;\n\n// ============================================================================\n// RPC Client\n// ============================================================================\n\nexport class RpcClient {\n\tprivate process: ChildProcess | null = null;\n\tprivate stopReadingStdout: (() => void) | null = null;\n\tprivate eventListeners: RpcEventListener[] = [];\n\tprivate pendingRequests: Map<string, { resolve: (response: RpcResponse) => void; reject: (error: Error) => void }> =\n\t\tnew Map();\n\tprivate requestId = 0;\n\tprivate stderr = \"\";\n\tprivate exitError: Error | null = null;\n\tprivate options: RpcClientOptions;\n\n\tconstructor(options: RpcClientOptions = {}) {\n\t\tthis.options = options;\n\t}\n\n\t/**\n\t * Start the RPC agent process.\n\t */\n\tasync start(): Promise<void> {\n\t\tif (this.process) {\n\t\t\tthrow new Error(\"Client already started\");\n\t\t}\n\n\t\tthis.exitError = null;\n\n\t\tconst cliPath = this.options.cliPath ?? \"dist/cli.ts\";\n\t\tconst args = [\"--mode\", \"rpc\"];\n\n\t\tif (this.options.provider) {\n\t\t\targs.push(\"--provider\", this.options.provider);\n\t\t}\n\t\tif (this.options.model) {\n\t\t\targs.push(\"--model\", this.options.model);\n\t\t}\n\t\tif (this.options.args) {\n\t\t\targs.push(...this.options.args);\n\t\t}\n\n\t\tconst defaultStartCommand: RpcClientStartCommand = { command: \"node\", args: [cliPath, ...args] };\n\t\tconst startCommand =\n\t\t\ttypeof this.options.startCommand === \"function\"\n\t\t\t\t? this.options.startCommand(defaultStartCommand)\n\t\t\t\t: (this.options.startCommand ?? defaultStartCommand);\n\n\t\tconst childProcess = spawn(startCommand.command, startCommand.args, {\n\t\t\tcwd: this.options.cwd,\n\t\t\tenv: { ...process.env, ...this.options.env },\n\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t});\n\t\tthis.process = childProcess;\n\n\t\t// Collect stderr for debugging\n\t\tchildProcess.stderr?.on(\"data\", (data) => {\n\t\t\tthis.stderr += data.toString();\n\t\t\tprocess.stderr.write(data);\n\t\t});\n\n\t\tchildProcess.once(\"exit\", (code, signal) => {\n\t\t\tif (this.process !== childProcess) return;\n\t\t\tconst error = this.createProcessExitError(code, signal);\n\t\t\tthis.exitError = error;\n\t\t\tthis.rejectPendingRequests(error);\n\t\t});\n\t\tchildProcess.once(\"error\", (error) => {\n\t\t\tif (this.process !== childProcess) return;\n\t\t\tconst processError = new Error(`Agent process error: ${error.message}. Stderr: ${this.stderr}`);\n\t\t\tthis.exitError = processError;\n\t\t\tthis.rejectPendingRequests(processError);\n\t\t});\n\t\tchildProcess.stdin?.on(\"error\", (error) => {\n\t\t\tif (this.process !== childProcess) return;\n\t\t\tconst stdinError =\n\t\t\t\tthis.exitError ?? new Error(`Agent process stdin error: ${error.message}. Stderr: ${this.stderr}`);\n\t\t\tthis.exitError = stdinError;\n\t\t\tthis.rejectPendingRequests(stdinError);\n\t\t});\n\n\t\t// Set up strict JSONL reader for stdout.\n\t\tthis.stopReadingStdout = attachJsonlLineReader(childProcess.stdout!, (line) => {\n\t\t\tthis.handleLine(line);\n\t\t});\n\n\t\t// Wait a moment for process to initialize\n\t\tawait new Promise((resolve) => setTimeout(resolve, 100));\n\n\t\tif (this.process.exitCode !== null) {\n\t\t\tconst error = this.exitError ?? this.createProcessExitError(this.process.exitCode, this.process.signalCode);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Stop the RPC agent process.\n\t */\n\tasync stop(): Promise<void> {\n\t\tif (!this.process) return;\n\n\t\tthis.stopReadingStdout?.();\n\t\tthis.stopReadingStdout = null;\n\t\tthis.process.kill(\"SIGTERM\");\n\n\t\t// Wait for process to exit\n\t\tawait new Promise<void>((resolve) => {\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tthis.process?.kill(\"SIGKILL\");\n\t\t\t\tresolve();\n\t\t\t}, 1000);\n\n\t\t\tthis.process?.on(\"exit\", () => {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\n\t\tthis.process = null;\n\t\tthis.pendingRequests.clear();\n\t}\n\n\t/**\n\t * Subscribe to agent events.\n\t */\n\tonEvent(listener: RpcEventListener): () => void {\n\t\tthis.eventListeners.push(listener);\n\t\treturn () => {\n\t\t\tconst index = this.eventListeners.indexOf(listener);\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.eventListeners.splice(index, 1);\n\t\t\t}\n\t\t};\n\t}\n\n\t/**\n\t * Get collected stderr output (useful for debugging).\n\t */\n\tgetStderr(): string {\n\t\treturn this.stderr;\n\t}\n\n\t// =========================================================================\n\t// Command Methods\n\t// =========================================================================\n\n\t/**\n\t * Send a prompt to the agent.\n\t * Returns immediately after sending; use onEvent() to receive streaming events.\n\t * Use waitForIdle() to wait for completion.\n\t */\n\tasync prompt(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"prompt\", message, images });\n\t}\n\n\t/**\n\t * Extract a structured response from the latest assistant response.\n\t */\n\tasync getStructuredResponse<TSchemaValue extends TSchema>(options: {\n\t\tschema: TSchemaValue;\n\t\tname?: string;\n\t\tdescription?: string;\n\t\tmaxCorrections?: number;\n\t\tscope?: \"latest\" | \"conversation\";\n\t}): Promise<StructuredResponse<Static<TSchemaValue>>> {\n\t\tconst response = await this.send({ type: \"get_structured_response\", ...options });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Queue a steering message to interrupt the agent mid-run.\n\t */\n\tasync steer(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"steer\", message, images });\n\t}\n\n\t/**\n\t * Queue a follow-up message to be processed after the agent finishes.\n\t */\n\tasync followUp(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"follow_up\", message, images });\n\t}\n\n\t/**\n\t * Abort current operation.\n\t */\n\tasync abort(): Promise<void> {\n\t\tawait this.send({ type: \"abort\" });\n\t}\n\n\t/**\n\t * Start a new session, optionally with an explicit id and parent tracking.\n\t * @returns Object with `cancelled: true` if an extension cancelled the new session\n\t */\n\tasync newSession(\n\t\toptions?: string | { sessionId?: string; parentSession?: string },\n\t): Promise<{ cancelled: boolean }> {\n\t\tconst sessionOptions = typeof options === \"string\" ? { parentSession: options } : options;\n\t\tconst response = await this.send({\n\t\t\ttype: \"new_session\",\n\t\t\tsessionId: sessionOptions?.sessionId,\n\t\t\tparentSession: sessionOptions?.parentSession,\n\t\t});\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * List sessions visible to this runtime. Results are paginated to avoid large RPC responses.\n\t */\n\tasync listSessions(options: RpcListSessionsOptions = {}): Promise<RpcClientListSessionsResponse> {\n\t\tconst response = await this.send({ type: \"list_sessions\", cursor: options.cursor, limit: options.limit });\n\t\tconst data = this.getData<RpcListSessionsResponse>(response);\n\t\treturn {\n\t\t\tsessions: data.sessions.map((session) => reviveSessionInfo(session)),\n\t\t\tnextCursor: data.nextCursor,\n\t\t};\n\t}\n\n\t/**\n\t * Get current session state.\n\t */\n\tasync getState(): Promise<RpcSessionState> {\n\t\tconst response = await this.send({ type: \"get_state\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Set model by provider and ID.\n\t */\n\tasync setModel(provider: string, modelId: string): Promise<{ provider: string; id: string }> {\n\t\tconst response = await this.send({ type: \"set_model\", provider, modelId });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Cycle to next model.\n\t */\n\tasync cycleModel(): Promise<{\n\t\tmodel: { provider: string; id: string };\n\t\tthinkingLevel: ThinkingLevel;\n\t\tisScoped: boolean;\n\t} | null> {\n\t\tconst response = await this.send({ type: \"cycle_model\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get list of available models.\n\t */\n\tasync getAvailableModels(): Promise<ModelInfo[]> {\n\t\tconst response = await this.send({ type: \"get_available_models\" });\n\t\treturn this.getData<{ models: ModelInfo[] }>(response).models;\n\t}\n\n\t/**\n\t * Set thinking level.\n\t */\n\tasync setThinkingLevel(level: ThinkingLevel): Promise<void> {\n\t\tawait this.send({ type: \"set_thinking_level\", level });\n\t}\n\n\t/**\n\t * Cycle thinking level.\n\t */\n\tasync cycleThinkingLevel(): Promise<{ level: ThinkingLevel } | null> {\n\t\tconst response = await this.send({ type: \"cycle_thinking_level\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Set steering mode.\n\t */\n\tasync setSteeringMode(mode: \"all\" | \"one-at-a-time\"): Promise<void> {\n\t\tawait this.send({ type: \"set_steering_mode\", mode });\n\t}\n\n\t/**\n\t * Set follow-up mode.\n\t */\n\tasync setFollowUpMode(mode: \"all\" | \"one-at-a-time\"): Promise<void> {\n\t\tawait this.send({ type: \"set_follow_up_mode\", mode });\n\t}\n\n\t/**\n\t * Compact session context.\n\t */\n\tasync compact(customInstructions?: string): Promise<CompactionResult> {\n\t\tconst response = await this.send({ type: \"compact\", customInstructions });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Set auto-compaction enabled/disabled.\n\t */\n\tasync setAutoCompaction(enabled: boolean): Promise<void> {\n\t\tawait this.send({ type: \"set_auto_compaction\", enabled });\n\t}\n\n\t/**\n\t * Set auto-retry enabled/disabled.\n\t */\n\tasync setAutoRetry(enabled: boolean): Promise<void> {\n\t\tawait this.send({ type: \"set_auto_retry\", enabled });\n\t}\n\n\t/**\n\t * Abort in-progress retry.\n\t */\n\tasync abortRetry(): Promise<void> {\n\t\tawait this.send({ type: \"abort_retry\" });\n\t}\n\n\t/**\n\t * Execute a bash command.\n\t */\n\tasync bash(command: string): Promise<BashResult> {\n\t\tconst response = await this.send({ type: \"bash\", command });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Abort running bash command.\n\t */\n\tasync abortBash(): Promise<void> {\n\t\tawait this.send({ type: \"abort_bash\" });\n\t}\n\n\t/**\n\t * Configure or reconfigure the deferred remote sandbox.\n\t */\n\tasync setRemoteSandbox(\n\t\toptions: { backend: \"ssh\"; remote: string; cwd?: string } | { backend: \"daemon\"; url: string },\n\t): Promise<ToolBackendInfo> {\n\t\tconst response = await this.send({ type: \"set_remote_sandbox\", ...options });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Clear the deferred remote sandbox configuration.\n\t */\n\tasync clearRemoteSandbox(): Promise<ToolBackendInfo> {\n\t\tconst response = await this.send({ type: \"clear_remote_sandbox\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get session statistics.\n\t */\n\tasync getSessionStats(): Promise<SessionStats> {\n\t\tconst response = await this.send({ type: \"get_session_stats\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Export session to HTML.\n\t */\n\tasync exportHtml(outputPath?: string): Promise<{ path: string }> {\n\t\tconst response = await this.send({ type: \"export_html\", outputPath });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Switch to a different session file.\n\t * @returns Object with `cancelled: true` if an extension cancelled the switch\n\t */\n\tasync switchSession(sessionPath: string): Promise<{ cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"switch_session\", sessionPath });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Fork from a specific message.\n\t * @returns Object with `text` (the message text) and `cancelled` (if extension cancelled)\n\t */\n\tasync fork(entryId: string): Promise<{ text: string; cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"fork\", entryId });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Clone the current active branch into a new session.\n\t * @returns Object with `cancelled: true` if an extension cancelled the clone\n\t */\n\tasync clone(): Promise<{ cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"clone\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get messages available for forking.\n\t */\n\tasync getForkMessages(): Promise<Array<{ entryId: string; text: string }>> {\n\t\tconst response = await this.send({ type: \"get_fork_messages\" });\n\t\treturn this.getData<{ messages: Array<{ entryId: string; text: string }> }>(response).messages;\n\t}\n\n\t/**\n\t * Get text of last assistant message.\n\t */\n\tasync getLastAssistantText(): Promise<string | null> {\n\t\tconst response = await this.send({ type: \"get_last_assistant_text\" });\n\t\treturn this.getData<{ text: string | null }>(response).text;\n\t}\n\n\t/**\n\t * Set the session display name.\n\t */\n\tasync setSessionName(name: string): Promise<void> {\n\t\tawait this.send({ type: \"set_session_name\", name });\n\t}\n\n\t/**\n\t * Get all messages in the session.\n\t */\n\tasync getMessages(): Promise<AgentMessage[]> {\n\t\tconst response = await this.send({ type: \"get_messages\" });\n\t\treturn this.getData<{ messages: AgentMessage[] }>(response).messages;\n\t}\n\n\t/**\n\t * Get available commands (extension commands, prompt templates, skills).\n\t */\n\tasync getCommands(): Promise<RpcSlashCommand[]> {\n\t\tconst response = await this.send({ type: \"get_commands\" });\n\t\treturn this.getData<{ commands: RpcSlashCommand[] }>(response).commands;\n\t}\n\n\t// =========================================================================\n\t// Helpers\n\t// =========================================================================\n\n\t/**\n\t * Wait for agent to become idle (no streaming).\n\t * Resolves when agent_end event is received.\n\t * The timeout is an inactivity timeout that resets each time an event is received.\n\t */\n\twaitForIdle(timeout = 5 * 60 * 1000): Promise<void> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\t\tconst resetTimer = () => {\n\t\t\t\tif (timer) clearTimeout(timer);\n\t\t\t\ttimer = setTimeout(() => {\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\treject(new Error(`Timeout waiting for agent to become idle. Stderr: ${this.stderr}`));\n\t\t\t\t}, timeout);\n\t\t\t};\n\n\t\t\tconst unsubscribe = this.onEvent((event) => {\n\t\t\t\tresetTimer();\n\t\t\t\tif (event.type === \"agent_end\") {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t});\n\t\t\tresetTimer();\n\t\t});\n\t}\n\n\t/**\n\t * Collect events until agent becomes idle.\n\t * The timeout is an inactivity timeout that resets each time an event is received.\n\t */\n\tcollectEvents(timeout = 5 * 60 * 1000): Promise<AgentEvent[]> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst events: AgentEvent[] = [];\n\t\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\t\tconst resetTimer = () => {\n\t\t\t\tif (timer) clearTimeout(timer);\n\t\t\t\ttimer = setTimeout(() => {\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\treject(new Error(`Timeout collecting events. Stderr: ${this.stderr}`));\n\t\t\t\t}, timeout);\n\t\t\t};\n\n\t\t\tconst unsubscribe = this.onEvent((event) => {\n\t\t\t\tevents.push(event);\n\t\t\t\tresetTimer();\n\t\t\t\tif (event.type === \"agent_end\") {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\tresolve(events);\n\t\t\t\t}\n\t\t\t});\n\t\t\tresetTimer();\n\t\t});\n\t}\n\n\t/**\n\t * Send prompt and wait for completion, returning all events.\n\t */\n\tasync promptAndWait(message: string, images?: ImageContent[], timeout = 5 * 60 * 1000): Promise<AgentEvent[]> {\n\t\tconst eventsPromise = this.collectEvents(timeout);\n\t\tawait this.prompt(message, images);\n\t\treturn eventsPromise;\n\t}\n\n\t// =========================================================================\n\t// Internal\n\t// =========================================================================\n\n\tprivate handleLine(line: string): void {\n\t\ttry {\n\t\t\tconst data = JSON.parse(line);\n\n\t\t\t// Check if it's a response to a pending request\n\t\t\tif (data.type === \"response\" && data.id && this.pendingRequests.has(data.id)) {\n\t\t\t\tconst pending = this.pendingRequests.get(data.id)!;\n\t\t\t\tthis.pendingRequests.delete(data.id);\n\t\t\t\tpending.resolve(data as RpcResponse);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Otherwise it's an event\n\t\t\tfor (const listener of this.eventListeners) {\n\t\t\t\tlistener(data as AgentEvent);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore non-JSON lines\n\t\t}\n\t}\n\n\tprivate createProcessExitError(code: number | null, signal: NodeJS.Signals | null): Error {\n\t\treturn new Error(`Agent process exited (code=${code} signal=${signal}). Stderr: ${this.stderr}`);\n\t}\n\n\tprivate rejectPendingRequests(error: Error): void {\n\t\tfor (const pending of this.pendingRequests.values()) {\n\t\t\tpending.reject(error);\n\t\t}\n\t\tthis.pendingRequests.clear();\n\t}\n\n\tprivate async send(command: RpcCommandBody): Promise<RpcResponse> {\n\t\tconst childProcess = this.process;\n\t\tconst stdin = childProcess?.stdin;\n\t\tif (!childProcess || !stdin) {\n\t\t\tthrow new Error(\"Client not started\");\n\t\t}\n\t\tif (this.exitError) {\n\t\t\tthrow this.exitError;\n\t\t}\n\t\tif (childProcess.exitCode !== null) {\n\t\t\tconst error = this.createProcessExitError(childProcess.exitCode, childProcess.signalCode);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\t\tif (stdin.destroyed || !stdin.writable) {\n\t\t\tconst error = new Error(`Agent process stdin is not writable. Stderr: ${this.stderr}`);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\n\t\tconst id = `req_${++this.requestId}`;\n\t\tconst fullCommand = { ...command, id } as RpcCommand;\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tthis.pendingRequests.delete(id);\n\t\t\t\treject(new Error(`Timeout waiting for response to ${command.type}. Stderr: ${this.stderr}`));\n\t\t\t}, 30000);\n\n\t\t\tthis.pendingRequests.set(id, {\n\t\t\t\tresolve: (response) => {\n\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\tresolve(response);\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\tstdin.write(serializeJsonLine(fullCommand));\n\t\t\t} catch (error: unknown) {\n\t\t\t\tconst writeError = error instanceof Error ? error : new Error(String(error));\n\t\t\t\tconst pending = this.pendingRequests.get(id);\n\t\t\t\tthis.pendingRequests.delete(id);\n\t\t\t\tpending?.reject(writeError);\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate getData<T>(response: RpcResponse): T {\n\t\tif (!response.success) {\n\t\t\tconst errorResponse = response as Extract<RpcResponse, { success: false }>;\n\t\t\tthrow new Error(errorResponse.error);\n\t\t}\n\t\t// Type assertion: we trust response.data matches T based on the command sent.\n\t\t// This is safe because each public method specifies the correct T for its command.\n\t\tconst successResponse = response as Extract<RpcResponse, { success: true; data: unknown }>;\n\t\treturn successResponse.data as T;\n\t}\n}\n\nfunction reviveSessionInfo(session: SessionInfo): SessionInfo {\n\treturn {\n\t\t...session,\n\t\tcreated: new Date(session.created),\n\t\tmodified: new Date(session.modified),\n\t};\n}\n"]}
1
+ {"version":3,"file":"rpc-client.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACzF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACpF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KA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;IACG,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC,CAGzE;IAED;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC,CAG7C;IAED;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAGzE;IAED;;OAEG;IACG,oBAAoB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAGnD;IAED;;OAEG;IACG,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhD;IAED;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,CAG3C;IAED;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC,CAG9C;IAMD;;;;OAIG;IACH,WAAW,CAAC,OAAO,SAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBlD;IAED;;;OAGG;IACH,aAAa,CAAC,OAAO,SAAgB,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAuB5D;IAED;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,EAAE,EAAE,OAAO,SAAgB,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAI5G;IAMD,OAAO,CAAC,UAAU;IAqBlB,OAAO,CAAC,sBAAsB;IAI9B,OAAO,CAAC,qBAAqB;YAOf,IAAI;IAmDlB,OAAO,CAAC,OAAO;CAUf","sourcesContent":["/**\n * RPC Client for programmatic access to the coding agent.\n *\n * Spawns the agent in RPC mode and provides a typed API for all operations.\n */\n\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport type { AgentEvent, AgentMessage, ThinkingLevel } from \"@fleetagent/pi-agent-core\";\nimport type { ImageContent } from \"@fleetagent/pi-ai\";\nimport type { Static, TSchema } from \"typebox\";\nimport type { SessionStats, StructuredResponse } from \"../../core/agent-session.ts\";\nimport type { BashResult } from \"../../core/bash-executor.ts\";\nimport type { CompactionResult } from \"../../core/compaction/index.ts\";\nimport type { SessionInfo } from \"../../core/session/types.ts\";\nimport type { ToolBackendInfo } from \"../../core/tools/index.ts\";\nimport { attachJsonlLineReader, serializeJsonLine } from \"./jsonl.ts\";\nimport type {\n\tRpcClientListSessionsResponse,\n\tRpcCommand,\n\tRpcListSessionsOptions,\n\tRpcListSessionsResponse,\n\tRpcResponse,\n\tRpcSessionState,\n\tRpcSlashCommand,\n} from \"./rpc-types.ts\";\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/** Distributive Omit that works with union types */\ntype DistributiveOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never;\n\n/** RpcCommand without the id field (for internal send) */\ntype RpcCommandBody = DistributiveOmit<RpcCommand, \"id\">;\n\nexport interface RpcClientStartCommand {\n\t/** Executable to spawn. */\n\tcommand: string;\n\t/** Arguments passed to the executable. */\n\targs: string[];\n}\n\nexport interface RpcClientOptions {\n\t/** Path to the CLI entry point (default: searches for dist/cli.js) */\n\tcliPath?: string;\n\t/** Override the process command used to start the RPC agent. */\n\tstartCommand?: RpcClientStartCommand | ((defaultCommand: RpcClientStartCommand) => RpcClientStartCommand);\n\t/** Working directory for the agent */\n\tcwd?: string;\n\t/** Environment variables */\n\tenv?: Record<string, string>;\n\t/** Provider to use */\n\tprovider?: string;\n\t/** Model ID to use */\n\tmodel?: string;\n\t/** Additional CLI arguments */\n\targs?: string[];\n}\n\nexport interface ModelInfo {\n\tprovider: string;\n\tid: string;\n\tcontextWindow: number;\n\treasoning: boolean;\n}\n\nexport type RpcEventListener = (event: AgentEvent) => void;\n\n// ============================================================================\n// RPC Client\n// ============================================================================\n\nexport class RpcClient {\n\tprivate process: ChildProcess | null = null;\n\tprivate stopReadingStdout: (() => void) | null = null;\n\tprivate eventListeners: RpcEventListener[] = [];\n\tprivate pendingRequests: Map<string, { resolve: (response: RpcResponse) => void; reject: (error: Error) => void }> =\n\t\tnew Map();\n\tprivate requestId = 0;\n\tprivate stderr = \"\";\n\tprivate exitError: Error | null = null;\n\tprivate options: RpcClientOptions;\n\n\tconstructor(options: RpcClientOptions = {}) {\n\t\tthis.options = options;\n\t}\n\n\t/**\n\t * Start the RPC agent process.\n\t */\n\tasync start(): Promise<void> {\n\t\tif (this.process) {\n\t\t\tthrow new Error(\"Client already started\");\n\t\t}\n\n\t\tthis.exitError = null;\n\n\t\tconst cliPath = this.options.cliPath ?? \"dist/cli.ts\";\n\t\tconst args = [\"--mode\", \"rpc\"];\n\n\t\tif (this.options.provider) {\n\t\t\targs.push(\"--provider\", this.options.provider);\n\t\t}\n\t\tif (this.options.model) {\n\t\t\targs.push(\"--model\", this.options.model);\n\t\t}\n\t\tif (this.options.args) {\n\t\t\targs.push(...this.options.args);\n\t\t}\n\n\t\tconst defaultStartCommand: RpcClientStartCommand = { command: \"node\", args: [cliPath, ...args] };\n\t\tconst startCommand =\n\t\t\ttypeof this.options.startCommand === \"function\"\n\t\t\t\t? this.options.startCommand(defaultStartCommand)\n\t\t\t\t: (this.options.startCommand ?? defaultStartCommand);\n\n\t\tconst childProcess = spawn(startCommand.command, startCommand.args, {\n\t\t\tcwd: this.options.cwd,\n\t\t\tenv: { ...process.env, ...this.options.env },\n\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t});\n\t\tthis.process = childProcess;\n\n\t\t// Collect stderr for debugging\n\t\tchildProcess.stderr?.on(\"data\", (data) => {\n\t\t\tthis.stderr += data.toString();\n\t\t\tprocess.stderr.write(data);\n\t\t});\n\n\t\tchildProcess.once(\"exit\", (code, signal) => {\n\t\t\tif (this.process !== childProcess) return;\n\t\t\tconst error = this.createProcessExitError(code, signal);\n\t\t\tthis.exitError = error;\n\t\t\tthis.rejectPendingRequests(error);\n\t\t});\n\t\tchildProcess.once(\"error\", (error) => {\n\t\t\tif (this.process !== childProcess) return;\n\t\t\tconst processError = new Error(`Agent process error: ${error.message}. Stderr: ${this.stderr}`);\n\t\t\tthis.exitError = processError;\n\t\t\tthis.rejectPendingRequests(processError);\n\t\t});\n\t\tchildProcess.stdin?.on(\"error\", (error) => {\n\t\t\tif (this.process !== childProcess) return;\n\t\t\tconst stdinError =\n\t\t\t\tthis.exitError ?? new Error(`Agent process stdin error: ${error.message}. Stderr: ${this.stderr}`);\n\t\t\tthis.exitError = stdinError;\n\t\t\tthis.rejectPendingRequests(stdinError);\n\t\t});\n\n\t\t// Set up strict JSONL reader for stdout.\n\t\tthis.stopReadingStdout = attachJsonlLineReader(childProcess.stdout!, (line) => {\n\t\t\tthis.handleLine(line);\n\t\t});\n\n\t\t// Wait a moment for process to initialize\n\t\tawait new Promise((resolve) => setTimeout(resolve, 100));\n\n\t\tif (this.process.exitCode !== null) {\n\t\t\tconst error = this.exitError ?? this.createProcessExitError(this.process.exitCode, this.process.signalCode);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Stop the RPC agent process.\n\t */\n\tasync stop(): Promise<void> {\n\t\tif (!this.process) return;\n\n\t\tthis.stopReadingStdout?.();\n\t\tthis.stopReadingStdout = null;\n\t\tthis.process.kill(\"SIGTERM\");\n\n\t\t// Wait for process to exit\n\t\tawait new Promise<void>((resolve) => {\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tthis.process?.kill(\"SIGKILL\");\n\t\t\t\tresolve();\n\t\t\t}, 1000);\n\n\t\t\tthis.process?.on(\"exit\", () => {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\n\t\tthis.process = null;\n\t\tthis.pendingRequests.clear();\n\t}\n\n\t/**\n\t * Subscribe to agent events.\n\t */\n\tonEvent(listener: RpcEventListener): () => void {\n\t\tthis.eventListeners.push(listener);\n\t\treturn () => {\n\t\t\tconst index = this.eventListeners.indexOf(listener);\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.eventListeners.splice(index, 1);\n\t\t\t}\n\t\t};\n\t}\n\n\t/**\n\t * Get collected stderr output (useful for debugging).\n\t */\n\tgetStderr(): string {\n\t\treturn this.stderr;\n\t}\n\n\t// =========================================================================\n\t// Command Methods\n\t// =========================================================================\n\n\t/**\n\t * Send a prompt to the agent.\n\t * Returns immediately after sending; use onEvent() to receive streaming events.\n\t * Use waitForIdle() to wait for completion.\n\t */\n\tasync prompt(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"prompt\", message, images });\n\t}\n\n\t/**\n\t * Extract a structured response from the latest assistant response.\n\t */\n\tasync getStructuredResponse<TSchemaValue extends TSchema>(options: {\n\t\tschema: TSchemaValue;\n\t\tname?: string;\n\t\tdescription?: string;\n\t\tmaxCorrections?: number;\n\t\tscope?: \"latest\" | \"conversation\";\n\t}): Promise<StructuredResponse<Static<TSchemaValue>>> {\n\t\tconst response = await this.send({ type: \"get_structured_response\", ...options });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Queue a steering message to interrupt the agent mid-run.\n\t */\n\tasync steer(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"steer\", message, images });\n\t}\n\n\t/**\n\t * Queue a follow-up message to be processed after the agent finishes.\n\t */\n\tasync followUp(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"follow_up\", message, images });\n\t}\n\n\t/**\n\t * Abort current operation.\n\t */\n\tasync abort(): Promise<void> {\n\t\tawait this.send({ type: \"abort\" });\n\t}\n\n\t/**\n\t * Start a new session, optionally with an explicit id and parent tracking.\n\t * @returns Object with `cancelled: true` if an extension cancelled the new session\n\t */\n\tasync newSession(\n\t\toptions?: string | { sessionId?: string; parentSession?: string },\n\t): Promise<{ cancelled: boolean }> {\n\t\tconst sessionOptions = typeof options === \"string\" ? { parentSession: options } : options;\n\t\tconst response = await this.send({\n\t\t\ttype: \"new_session\",\n\t\t\tsessionId: sessionOptions?.sessionId,\n\t\t\tparentSession: sessionOptions?.parentSession,\n\t\t});\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * List sessions visible to this runtime. Results are paginated to avoid large RPC responses.\n\t */\n\tasync listSessions(options: RpcListSessionsOptions = {}): Promise<RpcClientListSessionsResponse> {\n\t\tconst response = await this.send({ type: \"list_sessions\", cursor: options.cursor, limit: options.limit });\n\t\tconst data = this.getData<RpcListSessionsResponse>(response);\n\t\treturn {\n\t\t\tsessions: data.sessions.map((session) => reviveSessionInfo(session)),\n\t\t\tnextCursor: data.nextCursor,\n\t\t};\n\t}\n\n\t/**\n\t * Get current session state.\n\t */\n\tasync getState(): Promise<RpcSessionState> {\n\t\tconst response = await this.send({ type: \"get_state\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Set model by provider and ID.\n\t */\n\tasync setModel(provider: string, modelId: string): Promise<{ provider: string; id: string }> {\n\t\tconst response = await this.send({ type: \"set_model\", provider, modelId });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Cycle to next model.\n\t */\n\tasync cycleModel(): Promise<{\n\t\tmodel: { provider: string; id: string };\n\t\tthinkingLevel: ThinkingLevel;\n\t\tisScoped: boolean;\n\t} | null> {\n\t\tconst response = await this.send({ type: \"cycle_model\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get list of available models.\n\t */\n\tasync getAvailableModels(): Promise<ModelInfo[]> {\n\t\tconst response = await this.send({ type: \"get_available_models\" });\n\t\treturn this.getData<{ models: ModelInfo[] }>(response).models;\n\t}\n\n\t/**\n\t * Set thinking level.\n\t */\n\tasync setThinkingLevel(level: ThinkingLevel): Promise<void> {\n\t\tawait this.send({ type: \"set_thinking_level\", level });\n\t}\n\n\t/**\n\t * Cycle thinking level.\n\t */\n\tasync cycleThinkingLevel(): Promise<{ level: ThinkingLevel } | null> {\n\t\tconst response = await this.send({ type: \"cycle_thinking_level\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Set steering mode.\n\t */\n\tasync setSteeringMode(mode: \"all\" | \"one-at-a-time\"): Promise<void> {\n\t\tawait this.send({ type: \"set_steering_mode\", mode });\n\t}\n\n\t/**\n\t * Set follow-up mode.\n\t */\n\tasync setFollowUpMode(mode: \"all\" | \"one-at-a-time\"): Promise<void> {\n\t\tawait this.send({ type: \"set_follow_up_mode\", mode });\n\t}\n\n\t/**\n\t * Compact session context.\n\t */\n\tasync compact(customInstructions?: string): Promise<CompactionResult> {\n\t\tconst response = await this.send({ type: \"compact\", customInstructions });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Set auto-compaction enabled/disabled.\n\t */\n\tasync setAutoCompaction(enabled: boolean): Promise<void> {\n\t\tawait this.send({ type: \"set_auto_compaction\", enabled });\n\t}\n\n\t/**\n\t * Set auto-retry enabled/disabled.\n\t */\n\tasync setAutoRetry(enabled: boolean): Promise<void> {\n\t\tawait this.send({ type: \"set_auto_retry\", enabled });\n\t}\n\n\t/**\n\t * Abort in-progress retry.\n\t */\n\tasync abortRetry(): Promise<void> {\n\t\tawait this.send({ type: \"abort_retry\" });\n\t}\n\n\t/**\n\t * Execute a bash command.\n\t */\n\tasync bash(command: string): Promise<BashResult> {\n\t\tconst response = await this.send({ type: \"bash\", command });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Abort running bash command.\n\t */\n\tasync abortBash(): Promise<void> {\n\t\tawait this.send({ type: \"abort_bash\" });\n\t}\n\n\t/**\n\t * Configure or reconfigure the deferred remote sandbox.\n\t */\n\tasync setRemoteSandbox(\n\t\toptions: { backend: \"ssh\"; remote: string; cwd?: string } | { backend: \"daemon\"; url: string },\n\t): Promise<ToolBackendInfo> {\n\t\tconst response = await this.send({ type: \"set_remote_sandbox\", ...options });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Clear the deferred remote sandbox configuration.\n\t */\n\tasync clearRemoteSandbox(): Promise<ToolBackendInfo> {\n\t\tconst response = await this.send({ type: \"clear_remote_sandbox\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Upload a file from the RPC process filesystem to the active sandbox backend.\n\t */\n\tasync uploadFile(sourcePath: string, destinationPath: string): Promise<{ bytes: number }> {\n\t\tconst response = await this.send({ type: \"upload_file\", sourcePath, destinationPath });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Download a file from the active sandbox backend to the RPC process filesystem.\n\t */\n\tasync downloadFile(sourcePath: string, destinationPath: string): Promise<{ bytes: number }> {\n\t\tconst response = await this.send({ type: \"download_file\", sourcePath, destinationPath });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get session statistics.\n\t */\n\tasync getSessionStats(): Promise<SessionStats> {\n\t\tconst response = await this.send({ type: \"get_session_stats\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Export session to HTML.\n\t */\n\tasync exportHtml(outputPath?: string): Promise<{ path: string }> {\n\t\tconst response = await this.send({ type: \"export_html\", outputPath });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Switch to a different session file.\n\t * @returns Object with `cancelled: true` if an extension cancelled the switch\n\t */\n\tasync switchSession(sessionPath: string): Promise<{ cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"switch_session\", sessionPath });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Fork from a specific message.\n\t * @returns Object with `text` (the message text) and `cancelled` (if extension cancelled)\n\t */\n\tasync fork(entryId: string): Promise<{ text: string; cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"fork\", entryId });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Clone the current active branch into a new session.\n\t * @returns Object with `cancelled: true` if an extension cancelled the clone\n\t */\n\tasync clone(): Promise<{ cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"clone\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get messages available for forking.\n\t */\n\tasync getForkMessages(): Promise<Array<{ entryId: string; text: string }>> {\n\t\tconst response = await this.send({ type: \"get_fork_messages\" });\n\t\treturn this.getData<{ messages: Array<{ entryId: string; text: string }> }>(response).messages;\n\t}\n\n\t/**\n\t * Get text of last assistant message.\n\t */\n\tasync getLastAssistantText(): Promise<string | null> {\n\t\tconst response = await this.send({ type: \"get_last_assistant_text\" });\n\t\treturn this.getData<{ text: string | null }>(response).text;\n\t}\n\n\t/**\n\t * Set the session display name.\n\t */\n\tasync setSessionName(name: string): Promise<void> {\n\t\tawait this.send({ type: \"set_session_name\", name });\n\t}\n\n\t/**\n\t * Get all messages in the session.\n\t */\n\tasync getMessages(): Promise<AgentMessage[]> {\n\t\tconst response = await this.send({ type: \"get_messages\" });\n\t\treturn this.getData<{ messages: AgentMessage[] }>(response).messages;\n\t}\n\n\t/**\n\t * Get available commands (extension commands, prompt templates, skills).\n\t */\n\tasync getCommands(): Promise<RpcSlashCommand[]> {\n\t\tconst response = await this.send({ type: \"get_commands\" });\n\t\treturn this.getData<{ commands: RpcSlashCommand[] }>(response).commands;\n\t}\n\n\t// =========================================================================\n\t// Helpers\n\t// =========================================================================\n\n\t/**\n\t * Wait for agent to become idle (no streaming).\n\t * Resolves when agent_end event is received.\n\t * The timeout is an inactivity timeout that resets each time an event is received.\n\t */\n\twaitForIdle(timeout = 5 * 60 * 1000): Promise<void> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\t\tconst resetTimer = () => {\n\t\t\t\tif (timer) clearTimeout(timer);\n\t\t\t\ttimer = setTimeout(() => {\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\treject(new Error(`Timeout waiting for agent to become idle. Stderr: ${this.stderr}`));\n\t\t\t\t}, timeout);\n\t\t\t};\n\n\t\t\tconst unsubscribe = this.onEvent((event) => {\n\t\t\t\tresetTimer();\n\t\t\t\tif (event.type === \"agent_end\") {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t});\n\t\t\tresetTimer();\n\t\t});\n\t}\n\n\t/**\n\t * Collect events until agent becomes idle.\n\t * The timeout is an inactivity timeout that resets each time an event is received.\n\t */\n\tcollectEvents(timeout = 5 * 60 * 1000): Promise<AgentEvent[]> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst events: AgentEvent[] = [];\n\t\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\t\tconst resetTimer = () => {\n\t\t\t\tif (timer) clearTimeout(timer);\n\t\t\t\ttimer = setTimeout(() => {\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\treject(new Error(`Timeout collecting events. Stderr: ${this.stderr}`));\n\t\t\t\t}, timeout);\n\t\t\t};\n\n\t\t\tconst unsubscribe = this.onEvent((event) => {\n\t\t\t\tevents.push(event);\n\t\t\t\tresetTimer();\n\t\t\t\tif (event.type === \"agent_end\") {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\tresolve(events);\n\t\t\t\t}\n\t\t\t});\n\t\t\tresetTimer();\n\t\t});\n\t}\n\n\t/**\n\t * Send prompt and wait for completion, returning all events.\n\t */\n\tasync promptAndWait(message: string, images?: ImageContent[], timeout = 5 * 60 * 1000): Promise<AgentEvent[]> {\n\t\tconst eventsPromise = this.collectEvents(timeout);\n\t\tawait this.prompt(message, images);\n\t\treturn eventsPromise;\n\t}\n\n\t// =========================================================================\n\t// Internal\n\t// =========================================================================\n\n\tprivate handleLine(line: string): void {\n\t\ttry {\n\t\t\tconst data = JSON.parse(line);\n\n\t\t\t// Check if it's a response to a pending request\n\t\t\tif (data.type === \"response\" && data.id && this.pendingRequests.has(data.id)) {\n\t\t\t\tconst pending = this.pendingRequests.get(data.id)!;\n\t\t\t\tthis.pendingRequests.delete(data.id);\n\t\t\t\tpending.resolve(data as RpcResponse);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Otherwise it's an event\n\t\t\tfor (const listener of this.eventListeners) {\n\t\t\t\tlistener(data as AgentEvent);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore non-JSON lines\n\t\t}\n\t}\n\n\tprivate createProcessExitError(code: number | null, signal: NodeJS.Signals | null): Error {\n\t\treturn new Error(`Agent process exited (code=${code} signal=${signal}). Stderr: ${this.stderr}`);\n\t}\n\n\tprivate rejectPendingRequests(error: Error): void {\n\t\tfor (const pending of this.pendingRequests.values()) {\n\t\t\tpending.reject(error);\n\t\t}\n\t\tthis.pendingRequests.clear();\n\t}\n\n\tprivate async send(command: RpcCommandBody): Promise<RpcResponse> {\n\t\tconst childProcess = this.process;\n\t\tconst stdin = childProcess?.stdin;\n\t\tif (!childProcess || !stdin) {\n\t\t\tthrow new Error(\"Client not started\");\n\t\t}\n\t\tif (this.exitError) {\n\t\t\tthrow this.exitError;\n\t\t}\n\t\tif (childProcess.exitCode !== null) {\n\t\t\tconst error = this.createProcessExitError(childProcess.exitCode, childProcess.signalCode);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\t\tif (stdin.destroyed || !stdin.writable) {\n\t\t\tconst error = new Error(`Agent process stdin is not writable. Stderr: ${this.stderr}`);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\n\t\tconst id = `req_${++this.requestId}`;\n\t\tconst fullCommand = { ...command, id } as RpcCommand;\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tthis.pendingRequests.delete(id);\n\t\t\t\treject(new Error(`Timeout waiting for response to ${command.type}. Stderr: ${this.stderr}`));\n\t\t\t}, 30000);\n\n\t\t\tthis.pendingRequests.set(id, {\n\t\t\t\tresolve: (response) => {\n\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\tresolve(response);\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\tstdin.write(serializeJsonLine(fullCommand));\n\t\t\t} catch (error: unknown) {\n\t\t\t\tconst writeError = error instanceof Error ? error : new Error(String(error));\n\t\t\t\tconst pending = this.pendingRequests.get(id);\n\t\t\t\tthis.pendingRequests.delete(id);\n\t\t\t\tpending?.reject(writeError);\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate getData<T>(response: RpcResponse): T {\n\t\tif (!response.success) {\n\t\t\tconst errorResponse = response as Extract<RpcResponse, { success: false }>;\n\t\t\tthrow new Error(errorResponse.error);\n\t\t}\n\t\t// Type assertion: we trust response.data matches T based on the command sent.\n\t\t// This is safe because each public method specifies the correct T for its command.\n\t\tconst successResponse = response as Extract<RpcResponse, { success: true; data: unknown }>;\n\t\treturn successResponse.data as T;\n\t}\n}\n\nfunction reviveSessionInfo(session: SessionInfo): SessionInfo {\n\treturn {\n\t\t...session,\n\t\tcreated: new Date(session.created),\n\t\tmodified: new Date(session.modified),\n\t};\n}\n"]}
@@ -293,6 +293,20 @@ export class RpcClient {
293
293
  const response = await this.send({ type: "clear_remote_sandbox" });
294
294
  return this.getData(response);
295
295
  }
296
+ /**
297
+ * Upload a file from the RPC process filesystem to the active sandbox backend.
298
+ */
299
+ async uploadFile(sourcePath, destinationPath) {
300
+ const response = await this.send({ type: "upload_file", sourcePath, destinationPath });
301
+ return this.getData(response);
302
+ }
303
+ /**
304
+ * Download a file from the active sandbox backend to the RPC process filesystem.
305
+ */
306
+ async downloadFile(sourcePath, destinationPath) {
307
+ const response = await this.send({ type: "download_file", sourcePath, destinationPath });
308
+ return this.getData(response);
309
+ }
296
310
  /**
297
311
  * Get session statistics.
298
312
  */