@alanwchat/coder 0.1.108 → 0.1.112
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.
- package/cli.mjs +50 -0
- package/package.json +11 -22
- package/README.md +0 -289
- package/bin +0 -2
- package/dist/index.cjs +0 -3471
- package/dist/index.cjs.map +0 -7
package/dist/index.cjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/config/index.ts", "../src/handlers/list-dir.ts", "../src/handlers/result.ts", "../src/handlers/read-file.ts", "../src/handlers/write-file.ts", "../src/handlers/replace-file.ts", "../src/handlers/edit-file.ts", "../src/handlers/replace-lines.ts", "../src/handlers/glob.ts", "../src/handlers/grep.ts", "../src/handlers/shell-manager.ts", "../src/handlers/shell.ts", "../src/handlers/await-shell.ts", "../src/handlers/list-shells.ts", "../src/handlers/kill-shell.ts", "../src/handlers/read-shell-logs.ts", "../src/handlers/web-search.ts", "../src/handlers/browse-page.ts", "../src/handlers/todos.ts", "../src/handlers/workspace-tree.ts", "../src/handlers/ask-question.ts", "../src/handlers/spawn-subagent.ts", "../src/handlers/index.ts", "../src/agent/thinking-config.ts", "../src/agent/llm-stream.ts", "../src/agent/runner.ts", "../src/agent/environment/index.ts", "../../src/features/skills/system/registry.ts", "../src/agent/session.ts", "../src/ui/index.ts", "../src/commands/run.ts", "../src/commands/ask.ts", "../src/commands/repl.ts", "../src/commands/config.ts", "../src/commands/common.ts", "../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Coder CLI Configuration System\n *\n * Stores provider settings, API keys, model preferences, and CLI options\n * in ~/.coder/cli/settings.json, alongside the desktop app's ~/.coder/ data.\n */\n\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { mkdirSync, existsSync, readFileSync, writeFileSync } from \"node:fs\";\n\n// ---------------------------------------------------------------------------\n// Config directory resolution\n// ---------------------------------------------------------------------------\n\nfunction getConfigDir(): string {\n const home = homedir();\n return join(home, \".coder\", \"cli\");\n}\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport type ApiKeySource = \"manual\" | \"env\";\n\nexport type ProviderSettings = {\n apiKeySource: ApiKeySource;\n apiKey: string;\n apiKeyEnvVar: string;\n customBaseUrl: string;\n /** Whether the custom provider/model supports deep thinking. */\n supportsThinking?: boolean;\n /**\n * Custom API parameters for enabling thinking (JSON object).\n * Only meaningful for the \"custom\" provider. Set by editing\n * ~/.coder/cli/settings.json directly, not via `coder config`.\n */\n thinkingEnabledParams?: Record<string, unknown>;\n /** Custom API parameters for disabling thinking. */\n thinkingDisabledParams?: Record<string, unknown>;\n};\n\nexport type ProviderId =\n | \"deepseek\"\n | \"glm\"\n | \"agnes\"\n | \"nvidia\"\n | \"minimax\"\n | \"custom\";\n\nexport type ModelDefinition = {\n id: string;\n label?: string;\n contextWindow: number;\n supportsThinking: boolean;\n supportsMultimodal: boolean;\n};\n\nexport type ResolvedProviderConfig = {\n provider: ProviderId;\n baseUrl: string;\n apiKeySource: ApiKeySource;\n apiKey: string;\n apiKeyEnvVar: string;\n models: ModelDefinition[];\n};\n\nexport type CoderCliConfig = {\n /** Active provider ID */\n activeProvider: ProviderId;\n /** Provider-specific settings */\n providers: Record<ProviderId, ProviderSettings>;\n /** Last used model ID */\n lastModel: string;\n /** Tavily API key for web search (falls back to TAVILY_API_KEY env var) */\n tavilyApiKey: string;\n};\n\n// ---------------------------------------------------------------------------\n// Defaults\n// ---------------------------------------------------------------------------\n\nconst PRESET_PROVIDERS: Record<Exclude<ProviderId, \"custom\">, { baseUrl: string; defaultApiKeyEnvVar: string }> = {\n deepseek: { baseUrl: \"https://api.deepseek.com\", defaultApiKeyEnvVar: \"DEEPSEEK_API_KEY\" },\n glm: { baseUrl: \"https://open.bigmodel.cn/api/paas/v4\", defaultApiKeyEnvVar: \"GLM_API_KEY\" },\n agnes: { baseUrl: \"https://api.agnesai.com\", defaultApiKeyEnvVar: \"AGNES_API_KEY\" },\n nvidia: { baseUrl: \"https://integrate.api.nvidia.com/v1\", defaultApiKeyEnvVar: \"NVIDIA_API_KEY\" },\n minimax: { baseUrl: \"https://api.minimax.chat/v1\", defaultApiKeyEnvVar: \"MINIMAX_API_KEY\" },\n};\n\nconst PRESET_MODELS: Record<Exclude<ProviderId, \"custom\">, ModelDefinition[]> = {\n deepseek: [\n { id: \"deepseek-v4-flash\", label: \"DeepSeek V4 Flash\", contextWindow: 1_000_000, supportsThinking: true, supportsMultimodal: false },\n { id: \"deepseek-chat\", label: \"DeepSeek Chat\", contextWindow: 1_000_000, supportsThinking: false, supportsMultimodal: true },\n ],\n glm: [\n { id: \"glm-4\", label: \"GLM-4\", contextWindow: 128_000, supportsThinking: false, supportsMultimodal: true },\n { id: \"glm-4-plus\", label: \"GLM-4 Plus\", contextWindow: 128_000, supportsThinking: true, supportsMultimodal: true },\n ],\n agnes: [\n { id: \"agnes-v3\", label: \"Agnes V3\", contextWindow: 128_000, supportsThinking: false, supportsMultimodal: true },\n ],\n nvidia: [],\n minimax: [\n { id: \"minimax-m1\", label: \"MiniMax M1\", contextWindow: 200_000, supportsThinking: true, supportsMultimodal: false },\n ],\n};\n\nfunction createDefaultProviderSettings(provider: ProviderId): ProviderSettings {\n const isCustom = provider === \"custom\";\n return {\n apiKeySource: \"env\",\n apiKey: \"\",\n apiKeyEnvVar: isCustom ? \"CUSTOM_API_KEY\" : PRESET_PROVIDERS[provider]?.defaultApiKeyEnvVar ?? \"API_KEY\",\n customBaseUrl: isCustom ? \"https://api.example.com/v1\" : \"\",\n };\n}\n\nconst PROVIDER_IDS: ProviderId[] = [\"deepseek\", \"glm\", \"agnes\", \"nvidia\", \"minimax\", \"custom\"];\n\nfunction createDefaultConfig(): CoderCliConfig {\n const providers = {} as Record<ProviderId, ProviderSettings>;\n for (const id of PROVIDER_IDS) {\n providers[id] = createDefaultProviderSettings(id);\n }\n return {\n activeProvider: \"deepseek\",\n providers,\n lastModel: \"deepseek-v4-flash\",\n tavilyApiKey: \"\",\n };\n}\n\n// ---------------------------------------------------------------------------\n// Config file I/O\n// ---------------------------------------------------------------------------\n\nconst CONFIG_FILE = \"settings.json\";\n\nfunction getConfigFilePath(): string {\n return join(getConfigDir(), CONFIG_FILE);\n}\n\nfunction ensureConfigDir(): void {\n const dir = getConfigDir();\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n}\n\nexport function loadConfig(): CoderCliConfig {\n const configPath = getConfigFilePath();\n if (!existsSync(configPath)) {\n const defaults = createDefaultConfig();\n saveConfig(defaults);\n return defaults;\n }\n\n try {\n const raw = readFileSync(configPath, \"utf-8\");\n const parsed = JSON.parse(raw);\n return mergeWithDefaults(parsed);\n } catch {\n const defaults = createDefaultConfig();\n saveConfig(defaults);\n return defaults;\n }\n}\n\nfunction mergeWithDefaults(raw: Record<string, unknown>): CoderCliConfig {\n const defaults = createDefaultConfig();\n return {\n activeProvider: (PROVIDER_IDS as readonly string[]).includes(String(raw.activeProvider ?? \"\"))\n ? (raw.activeProvider as ProviderId)\n : defaults.activeProvider,\n providers: mergeProviders(raw.providers as Record<string, unknown> | undefined, defaults.providers),\n lastModel: typeof raw.lastModel === \"string\" ? raw.lastModel : defaults.lastModel,\n tavilyApiKey: typeof raw.tavilyApiKey === \"string\" ? raw.tavilyApiKey : defaults.tavilyApiKey,\n };\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction mergeProviders(\n raw: Record<string, unknown> | undefined,\n defaults: Record<ProviderId, ProviderSettings>,\n): Record<ProviderId, ProviderSettings> {\n const result = { ...defaults };\n if (!raw || typeof raw !== \"object\") {\n return result;\n }\n\n for (const id of PROVIDER_IDS) {\n const p = (raw as Record<string, Record<string, unknown>>)[id];\n if (p && typeof p === \"object\") {\n result[id] = {\n apiKeySource: p.apiKeySource === \"manual\" ? \"manual\" : \"env\",\n apiKey: typeof p.apiKey === \"string\" ? p.apiKey : result[id].apiKey,\n apiKeyEnvVar: typeof p.apiKeyEnvVar === \"string\" ? p.apiKeyEnvVar : result[id].apiKeyEnvVar,\n customBaseUrl: typeof p.customBaseUrl === \"string\" ? p.customBaseUrl : result[id].customBaseUrl,\n ...(typeof p.supportsThinking === \"boolean\"\n ? { supportsThinking: p.supportsThinking }\n : {}),\n ...(isPlainObject(p.thinkingEnabledParams)\n ? { thinkingEnabledParams: p.thinkingEnabledParams }\n : {}),\n ...(isPlainObject(p.thinkingDisabledParams)\n ? { thinkingDisabledParams: p.thinkingDisabledParams }\n : {}),\n };\n }\n }\n\n return result;\n}\n\nexport function saveConfig(config: CoderCliConfig): void {\n ensureConfigDir();\n const configPath = getConfigFilePath();\n writeFileSync(configPath, JSON.stringify(config, null, 2), \"utf-8\");\n}\n\n// ---------------------------------------------------------------------------\n// Provider config resolution\n// ---------------------------------------------------------------------------\n\nexport function resolveProviderConfig(config: CoderCliConfig, providerId?: ProviderId): ResolvedProviderConfig {\n const provider = providerId ?? config.activeProvider;\n const settings = config.providers[provider];\n\n if (provider === \"custom\") {\n if (!settings.customBaseUrl.trim()) {\n throw new Error(\n \"Custom provider selected but no base URL configured. \" +\n \"Run `coder config` or manually edit the config file.\"\n );\n }\n return {\n provider,\n baseUrl: settings.customBaseUrl.trim(),\n apiKeySource: settings.apiKeySource,\n apiKey: settings.apiKey,\n apiKeyEnvVar: settings.apiKeyEnvVar.trim(),\n models: [],\n };\n }\n\n const preset = PRESET_PROVIDERS[provider];\n if (!preset) {\n throw new Error(`Unknown provider: ${provider}`);\n }\n\n return {\n provider,\n baseUrl: settings.customBaseUrl.trim() || preset.baseUrl,\n apiKeySource: settings.apiKeySource,\n apiKey: settings.apiKey,\n apiKeyEnvVar: settings.apiKeyEnvVar.trim() || preset.defaultApiKeyEnvVar,\n models: settings.customBaseUrl.trim()\n ? []\n : PRESET_MODELS[provider] ?? [],\n };\n}\n\nexport function resolveApiKey(resolved: ResolvedProviderConfig): string {\n if (resolved.apiKeySource === \"manual\") {\n if (!resolved.apiKey.trim()) {\n throw new Error(\n `API key for ${resolved.provider} is not configured. ` +\n \"Set it with: coder config providers.<provider>.apiKey <key>\"\n );\n }\n return resolved.apiKey.trim();\n }\n\n // Read from environment variable\n const envVar = resolved.apiKeyEnvVar;\n const envValue = process.env[envVar]?.trim();\n if (!envValue) {\n throw new Error(\n `Environment variable ${envVar} is not set. ` +\n `Set it with: export ${envVar}=<your-api-key>`\n );\n }\n return envValue;\n}\n\n// ---------------------------------------------------------------------------\n// Tavily config resolution\n// ---------------------------------------------------------------------------\n\n/** Resolve Tavily API key: config key takes priority, then env var. */\nexport function resolveTavilyApiKey(config: CoderCliConfig): string {\n if (config.tavilyApiKey.trim()) {\n return config.tavilyApiKey.trim();\n }\n return process.env.TAVILY_API_KEY?.trim() ?? \"\";\n}\n\n// ---------------------------------------------------------------------------\n// Config directory path (exported for diagnostics)\n// ---------------------------------------------------------------------------\n\nexport function getConfigDirPath(): string {\n return getConfigDir();\n}\n\nexport function getConfigFilePathExplicit(): string {\n return getConfigFilePath();\n}\n", "import { readdirSync, statSync } from \"node:fs\";\nimport { resolve, relative } from \"node:path\";\nimport { toolFailure, toolSuccess } from \"./result\";\nimport type { ListDirEntry, ToolHandler } from \"./types\";\n\ntype ListDirArgs = {\n path: string;\n recursive?: boolean;\n max_depth?: number;\n show_hidden?: boolean;\n};\n\nexport const listDirHandler: ToolHandler = async (rawArgs, context) => {\n const args = rawArgs as ListDirArgs;\n\n if (!context.workspaceDir) {\n return toolFailure(\"list_dir\", \"workspace_required\", \"No workspace directory set\");\n }\n\n const dirPath = resolve(context.workspaceDir, args.path);\n const maxDepth = args.recursive ? (args.max_depth ?? 1) : 1;\n\n try {\n const entries = walkDirectory(dirPath, 0, maxDepth, args.show_hidden ?? false);\n return toolSuccess(\"list_dir\", {\n path: relative(context.workspaceDir, dirPath),\n entries,\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return toolFailure(\"list_dir\", \"read_error\", message);\n }\n};\n\nfunction walkDirectory(\n dirPath: string,\n currentDepth: number,\n maxDepth: number,\n showHidden: boolean,\n): ListDirEntry[] {\n const results: ListDirEntry[] = [];\n\n let entries: string[];\n try {\n entries = readdirSync(dirPath);\n } catch {\n return results;\n }\n\n for (const name of entries) {\n if (!showHidden && name.startsWith(\".\")) {\n continue;\n }\n\n const fullPath = resolve(dirPath, name);\n let stats: ReturnType<typeof statSync>;\n try {\n stats = statSync(fullPath);\n } catch {\n continue;\n }\n\n results.push({\n name,\n path: fullPath,\n isDir: stats.isDirectory(),\n size: stats.isFile() ? stats.size : undefined,\n });\n\n if (stats.isDirectory() && currentDepth < maxDepth) {\n results.push(...walkDirectory(fullPath, currentDepth + 1, maxDepth, showHidden));\n }\n }\n\n return results;\n}\n", "export function toolSuccess(tool: string, data: unknown): { ok: true; tool: string; data: unknown } {\n return { ok: true, tool, data };\n}\n\nexport function toolFailure(\n tool: string,\n code: string,\n message: string,\n): { ok: false; tool: string; error: { code: string; message: string } } {\n return {\n ok: false,\n tool,\n error: { code, message },\n };\n}\n", "import { readFileSync, statSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { toolFailure, toolSuccess } from \"./result\";\nimport type { ToolHandler } from \"./types\";\n\ntype ReadFileArgs = {\n path: string;\n start_line?: number;\n max_lines?: number;\n respect_gitignore?: boolean;\n};\n\nexport const readFileHandler: ToolHandler = async (rawArgs, context) => {\n const args = rawArgs as ReadFileArgs;\n\n if (!context.workspaceDir) {\n return toolFailure(\"read_file\", \"workspace_required\", \"No workspace directory set\");\n }\n\n const filePath = resolve(context.workspaceDir, args.path);\n const startLine = args.start_line ?? 1;\n const maxLines = args.max_lines ?? 500;\n\n try {\n statSync(filePath); // Check file exists\n const content = readFileSync(filePath, \"utf-8\");\n const lines = content.split(\"\\n\");\n const totalLines = lines.length;\n\n // Pagination\n const endLine = Math.min(startLine + maxLines - 1, totalLines);\n const paginatedContent = lines.slice(startLine - 1, endLine).join(\"\\n\");\n\n return toolSuccess(\"read_file\", {\n path: filePath,\n encoding: \"utf-8\",\n mimeType: \"text/plain\",\n content: paginatedContent,\n totalLines,\n startLine,\n endLine,\n truncated: endLine < totalLines,\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (message.includes(\"ENOENT\")) {\n return toolFailure(\"read_file\", \"not_found\", `File not found: ${filePath}`);\n }\n return toolFailure(\"read_file\", \"read_error\", message);\n }\n};\n", "import { writeFileSync, mkdirSync, existsSync } from \"node:fs\";\nimport { resolve, dirname } from \"node:path\";\nimport { toolFailure, toolSuccess } from \"./result\";\nimport type { ToolHandler } from \"./types\";\n\ntype WriteFileArgs = {\n path: string;\n content: string;\n create_parent_dirs?: boolean;\n};\n\nexport const writeFileHandler: ToolHandler = async (rawArgs, context) => {\n const args = rawArgs as WriteFileArgs;\n\n if (!context.workspaceDir) {\n return toolFailure(\"write_file\", \"workspace_required\", \"No workspace directory set\");\n }\n\n const filePath = resolve(context.workspaceDir, args.path);\n\n // Prevent writing outside workspace\n if (!filePath.startsWith(context.workspaceDir.replace(/\\\\/g, \"/\").replace(/\\\\/g, \"/\"))) {\n return toolFailure(\"write_file\", \"path_escape\", \"Path escapes workspace directory\");\n }\n\n if (existsSync(filePath)) {\n return toolFailure(\"write_file\", \"file_exists\", `File already exists: ${args.path}. Use replace_file to overwrite.`);\n }\n\n try {\n if (args.create_parent_dirs !== false) {\n const parentDir = dirname(filePath);\n if (!existsSync(parentDir)) {\n mkdirSync(parentDir, { recursive: true });\n }\n }\n\n const lines = args.content.split(\"\\n\");\n writeFileSync(filePath, args.content, \"utf-8\");\n\n return toolSuccess(\"write_file\", {\n path: args.path,\n action: \"created\",\n bytesWritten: Buffer.byteLength(args.content, \"utf-8\"),\n linesAdded: lines.length,\n linesRemoved: 0,\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return toolFailure(\"write_file\", \"write_error\", message);\n }\n};\n", "import { writeFileSync, readFileSync, existsSync, mkdirSync } from \"node:fs\";\nimport { resolve, dirname } from \"node:path\";\nimport { createHash } from \"node:crypto\";\nimport { toolFailure, toolSuccess } from \"./result\";\nimport type { ToolHandler } from \"./types\";\n\ntype ReplaceFileArgs = {\n path: string;\n content: string;\n expected_sha256?: string;\n create_backup?: boolean;\n respect_gitignore?: boolean;\n};\n\nexport const replaceFileHandler: ToolHandler = async (rawArgs, context) => {\n const args = rawArgs as ReplaceFileArgs;\n\n if (!context.workspaceDir) {\n return toolFailure(\"replace_file\", \"workspace_required\", \"No workspace directory set\");\n }\n\n const filePath = resolve(context.workspaceDir, args.path);\n\n if (!existsSync(filePath)) {\n return toolFailure(\"replace_file\", \"not_found\", `File not found: ${args.path}`);\n }\n\n try {\n const oldContent = readFileSync(filePath, \"utf-8\");\n const oldLines = oldContent.split(\"\\n\");\n const newLines = args.content.split(\"\\n\");\n\n // Verify SHA256 if provided\n if (args.expected_sha256) {\n const actualHash = createHash(\"sha256\").update(oldContent).digest(\"hex\");\n if (actualHash !== args.expected_sha256) {\n return toolFailure(\n \"replace_file\",\n \"content_changed\",\n `File content changed since last read. Expected SHA256: ${args.expected_sha256}, got: ${actualHash}. Read the file again to get the latest content.`,\n );\n }\n }\n\n writeFileSync(filePath, args.content, \"utf-8\");\n\n return toolSuccess(\"replace_file\", {\n path: args.path,\n action: \"replaced\",\n bytesWritten: Buffer.byteLength(args.content, \"utf-8\"),\n linesAdded: newLines.length,\n linesRemoved: oldLines.length,\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return toolFailure(\"replace_file\", \"write_error\", message);\n }\n};\n", "import { readFileSync, writeFileSync, existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { createHash } from \"node:crypto\";\nimport { toolFailure, toolSuccess } from \"./result\";\nimport type { ToolHandler } from \"./types\";\n\ntype EditFileArgs = {\n path: string;\n old_string: string;\n new_string: string;\n expected_sha256?: string;\n replace_all?: boolean;\n create_backup?: boolean;\n respect_gitignore?: boolean;\n};\n\nexport const editFileHandler: ToolHandler = async (rawArgs, context) => {\n const args = rawArgs as EditFileArgs;\n\n if (!context.workspaceDir) {\n return toolFailure(\"edit_file\", \"workspace_required\", \"No workspace directory set\");\n }\n\n const filePath = resolve(context.workspaceDir, args.path);\n\n if (!existsSync(filePath)) {\n return toolFailure(\"edit_file\", \"not_found\", `File not found: ${args.path}`);\n }\n\n try {\n const oldContent = readFileSync(filePath, \"utf-8\");\n const oldLines = oldContent.split(\"\\n\");\n\n // Verify SHA256 if provided\n if (args.expected_sha256) {\n const actualHash = createHash(\"sha256\").update(oldContent).digest(\"hex\");\n if (actualHash !== args.expected_sha256) {\n return toolFailure(\n \"edit_file\",\n \"content_changed\",\n `File content changed since last read. Expected SHA256: ${args.expected_sha256}, got: ${actualHash}.`,\n );\n }\n }\n\n // Apply search-and-replace\n let newContent: string;\n if (args.replace_all) {\n newContent = oldContent.split(args.old_string).join(args.new_string);\n } else {\n const index = oldContent.indexOf(args.old_string);\n if (index === -1) {\n return toolFailure(\n \"edit_file\",\n \"string_not_found\",\n `Could not find the exact text to replace in ${args.path}. The text must match exactly.`,\n );\n }\n newContent = oldContent.slice(0, index) + args.new_string + oldContent.slice(index + args.old_string.length);\n }\n\n const newLines = newContent.split(\"\\n\");\n writeFileSync(filePath, newContent, \"utf-8\");\n\n // Calculate diff stats\n const linesAdded = newLines.length - oldLines.length;\n const linesRemoved = oldLines.length - newLines.length;\n\n return toolSuccess(\"edit_file\", {\n path: args.path,\n action: \"modified\",\n bytesWritten: Buffer.byteLength(newContent, \"utf-8\"),\n linesAdded: linesAdded > 0 ? linesAdded : 0,\n linesRemoved: linesRemoved > 0 ? linesRemoved : 0,\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return toolFailure(\"edit_file\", \"write_error\", message);\n }\n};\n", "import { readFileSync, writeFileSync, existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { createHash } from \"node:crypto\";\nimport { toolFailure, toolSuccess } from \"./result\";\nimport type { ToolHandler } from \"./types\";\n\ntype ReplaceLinesArgs = {\n path: string;\n start_line: number;\n end_line: number;\n content: string;\n expected_sha256?: string;\n create_backup?: boolean;\n respect_gitignore?: boolean;\n};\n\nexport const replaceLinesHandler: ToolHandler = async (rawArgs, context) => {\n const args = rawArgs as ReplaceLinesArgs;\n\n if (!context.workspaceDir) {\n return toolFailure(\"replace_lines\", \"workspace_required\", \"No workspace directory set\");\n }\n\n const filePath = resolve(context.workspaceDir, args.path);\n\n if (!existsSync(filePath)) {\n return toolFailure(\"replace_lines\", \"not_found\", `File not found: ${args.path}`);\n }\n\n try {\n const oldContent = readFileSync(filePath, \"utf-8\");\n const oldLines = oldContent.split(\"\\n\");\n\n // Verify SHA256 if provided\n if (args.expected_sha256) {\n const actualHash = createHash(\"sha256\").update(oldContent).digest(\"hex\");\n if (actualHash !== args.expected_sha256) {\n return toolFailure(\n \"replace_lines\",\n \"content_changed\",\n `File content changed since last read. Expected SHA256: ${args.expected_sha256}, got: ${actualHash}.`,\n );\n }\n }\n\n // Validate line range\n if (args.start_line < 1 || args.end_line < args.start_line || args.start_line > oldLines.length) {\n return toolFailure(\n \"replace_lines\",\n \"invalid_range\",\n `Invalid line range: ${args.start_line}-${args.end_line}. File has ${oldLines.length} lines.`,\n );\n }\n\n const endLine = Math.min(args.end_line, oldLines.length);\n const replacementLines = args.content === \"\" ? [] : args.content.split(\"\\n\");\n\n // Build new content: lines before start + replacement + lines after end\n const before = oldLines.slice(0, args.start_line - 1);\n const after = oldLines.slice(endLine);\n const newContent = [...before, ...replacementLines, ...after].join(\"\\n\");\n\n writeFileSync(filePath, newContent, \"utf-8\");\n\n return toolSuccess(\"replace_lines\", {\n path: args.path,\n action: \"modified\",\n bytesWritten: Buffer.byteLength(newContent, \"utf-8\"),\n linesAdded: replacementLines.length,\n linesRemoved: endLine - args.start_line + 1,\n warning:\n \"Rows may have shifted \u2014 re-read the file with read_file before your next edit.\",\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return toolFailure(\"replace_lines\", \"write_error\", message);\n }\n};\n", "import { readdirSync, statSync } from \"node:fs\";\nimport { resolve, relative, sep } from \"node:path\";\nimport { toolFailure, toolSuccess } from \"./result\";\nimport type { ToolHandler } from \"./types\";\n\ntype GlobArgs = {\n glob_pattern: string;\n target_directory?: string;\n head_limit?: number;\n respect_gitignore?: boolean;\n};\n\n/**\n * Simple glob matching \u2014 converts glob patterns to regex and walks directories.\n * For complex patterns, the CLI agent can use the shell tool to call the real `find` or `dir` command.\n */\nexport const globHandler: ToolHandler = async (rawArgs, context) => {\n const args = rawArgs as GlobArgs;\n\n if (!context.workspaceDir) {\n return toolFailure(\"glob\", \"workspace_required\", \"No workspace directory set\");\n }\n\n const searchDir = args.target_directory\n ? resolve(context.workspaceDir, args.target_directory)\n : context.workspaceDir;\n\n const headLimit = args.head_limit ?? 100;\n const pattern = args.glob_pattern;\n\n try {\n const matches = simpleGlob(searchDir, pattern, context.workspaceDir, headLimit);\n return toolSuccess(\"glob\", {\n pattern,\n targetDirectory: relative(context.workspaceDir, searchDir),\n matches: matches.slice(0, headLimit),\n totalMatches: matches.length,\n truncated: matches.length > headLimit,\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return toolFailure(\"glob\", \"search_error\", message);\n }\n};\n\nfunction simpleGlob(\n rootDir: string,\n pattern: string,\n workspaceDir: string,\n limit: number,\n): string[] {\n const results: string[] = [];\n\n // Simple recursive walk \u2014 for production, use a proper glob library\n function walk(dir: string): void {\n if (results.length >= limit) return;\n\n let entries: string[];\n try {\n entries = readdirSync(dir);\n } catch {\n return;\n }\n\n for (const name of entries) {\n if (results.length >= limit) return;\n if (name.startsWith(\".\")) continue;\n\n const fullPath = resolve(dir, name);\n const relPath = relative(workspaceDir, fullPath).replace(/\\\\/g, \"/\");\n\n let stats: ReturnType<typeof statSync>;\n try {\n stats = statSync(fullPath);\n } catch {\n continue;\n }\n\n // Simple glob matching: check if pattern matches the relative path\n const regex = globToRegex(pattern);\n if (regex.test(relPath)) {\n results.push(relPath);\n }\n\n if (stats.isDirectory()) {\n walk(fullPath);\n }\n }\n }\n\n walk(rootDir);\n\n // Sort for consistent output\n results.sort();\n return results;\n}\n\nfunction globToRegex(pattern: string): RegExp {\n let regexStr = \"^\";\n let i = 0;\n\n while (i < pattern.length) {\n const ch = pattern[i];\n if (ch === \"*\") {\n if (i + 1 < pattern.length && pattern[i + 1] === \"*\") {\n // ** \u2014 match everything including path separators\n regexStr += \".*\";\n i += 2;\n // Handle **/ pattern\n if (i < pattern.length && pattern[i] === \"/\") {\n regexStr += \"/?\";\n i++;\n }\n } else {\n // * \u2014 match anything except path separator\n regexStr += \"[^/]*\";\n i++;\n }\n } else if (ch === \"?\") {\n regexStr += \"[^/]\";\n i++;\n } else if (ch === \".\" || ch === \"+\" || ch === \"(\" || ch === \")\" || ch === \"[\" || ch === \"]\" || ch === \"{\"\n || ch === \"}\" || ch === \"\\\\\" || ch === \"^\" || ch === \"$\" || ch === \"|\") {\n regexStr += \"\\\\\" + ch;\n i++;\n } else {\n regexStr += ch;\n i++;\n }\n }\n\n regexStr += \"$\";\n return new RegExp(regexStr, \"i\");\n}\n", "import { readFileSync, readdirSync, statSync } from \"node:fs\";\nimport { resolve, relative } from \"node:path\";\nimport { toolFailure, toolSuccess } from \"./result\";\nimport type { GrepData, ToolHandler } from \"./types\";\n\ntype GrepArgs = {\n pattern: string;\n path?: string;\n glob?: string;\n output_mode?: \"content\" | \"files_with_matches\" | \"count\";\n case_insensitive?: boolean;\n context_before?: number;\n context_after?: number;\n context?: number;\n head_limit?: number;\n offset?: number;\n multiline?: boolean;\n respect_gitignore?: boolean;\n};\n\nexport const grepHandler: ToolHandler = async (rawArgs, context) => {\n const args = rawArgs as GrepArgs;\n\n if (!context.workspaceDir) {\n return toolFailure(\"grep\", \"workspace_required\", \"No workspace directory set\");\n }\n\n const searchPath = args.path\n ? resolve(context.workspaceDir, args.path)\n : context.workspaceDir;\n\n const headLimit = args.head_limit ?? 200;\n const offset = args.offset ?? 0;\n const ctxBefore = args.context_before ?? args.context ?? 0;\n const ctxAfter = args.context_after ?? args.context ?? 0;\n const flags = args.case_insensitive ? \"gi\" : \"g\";\n const outputMode = args.output_mode ?? \"content\";\n const multiline = args.multiline ?? false;\n\n try {\n let searchRegex: RegExp;\n try {\n // For multiline, use s flag so . matches newlines\n const regexFlags = multiline ? `${flags}s` : flags;\n searchRegex = new RegExp(args.pattern, regexFlags);\n } catch {\n return toolFailure(\"grep\", \"invalid_pattern\", `Invalid regex pattern: ${args.pattern}`);\n }\n\n const files = collectFiles(searchPath);\n const matches: NonNullable<GrepData[\"matches\"]> = [];\n const fileMatchSet: Set<string> = new Set();\n /** Per-file match count for \"count\" mode. */\n const fileCountMap: Record<string, number> = {};\n let totalMatches = 0;\n let skippedFiles = 0;\n\n for (const file of files) {\n if (totalMatches >= headLimit + offset) break;\n\n let content: string;\n try {\n content = readFileSync(file, \"utf-8\");\n } catch {\n skippedFiles++;\n continue;\n }\n\n const relativePath = relative(context.workspaceDir, file);\n let fileHasMatch = false;\n let fileMatchCount = 0;\n\n if (multiline) {\n // Multiline mode: test the regex against the full content\n const lines = content.split(\"\\n\");\n searchRegex.lastIndex = 0;\n const fullMatch = searchRegex.exec(content);\n if (fullMatch) {\n fileHasMatch = true;\n // Count matches across the full content\n do {\n totalMatches++;\n fileMatchCount++;\n searchRegex.lastIndex = fullMatch.index + 1;\n } while (searchRegex.exec(content));\n searchRegex.lastIndex = 0;\n\n if (outputMode === \"content\") {\n matches.push({\n path: relativePath,\n lineNumber: 1,\n line: fullMatch[0].slice(0, 200),\n });\n }\n }\n } else {\n // Line-by-line mode\n const lines = content.split(\"\\n\");\n for (let lineNum = 0; lineNum < lines.length; lineNum++) {\n searchRegex.lastIndex = 0;\n if (searchRegex.test(lines[lineNum])) {\n totalMatches++;\n fileMatchCount++;\n\n if (outputMode === \"files_with_matches\") {\n fileMatchSet.add(relativePath);\n fileHasMatch = true;\n continue;\n }\n\n if (outputMode === \"count\") {\n fileHasMatch = true;\n continue;\n }\n\n // content mode\n if (totalMatches > offset && totalMatches <= offset + headLimit) {\n const contextBeforeLines = ctxBefore > 0\n ? lines.slice(Math.max(0, lineNum - ctxBefore), lineNum)\n : undefined;\n const contextAfterLines = ctxAfter > 0\n ? lines.slice(lineNum + 1, lineNum + 1 + ctxAfter)\n : undefined;\n\n matches.push({\n path: relativePath,\n lineNumber: lineNum + 1,\n line: lines[lineNum],\n contextBefore: contextBeforeLines?.length ? contextBeforeLines : undefined,\n contextAfter: contextAfterLines?.length ? contextAfterLines : undefined,\n });\n }\n }\n }\n }\n\n if (fileHasMatch || fileMatchCount > 0) {\n fileMatchSet.add(relativePath);\n fileCountMap[relativePath] = fileMatchCount;\n }\n\n if (outputMode === \"files_with_matches\" && fileMatchSet.size >= headLimit) {\n break;\n }\n }\n\n const result: GrepData = {\n pattern: args.pattern,\n path: relative(context.workspaceDir, searchPath),\n outputMode,\n totalMatches,\n truncated: totalMatches > headLimit,\n };\n\n if (outputMode === \"content\") {\n result.matches = matches;\n } else if (outputMode === \"files_with_matches\") {\n result.files = [...fileMatchSet];\n } else if (outputMode === \"count\") {\n result.files = [...fileMatchSet];\n result.fileCounts = fileCountMap;\n }\n\n if (skippedFiles > 0) {\n result.skippedFiles = skippedFiles;\n }\n\n return toolSuccess(\"grep\", result);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return toolFailure(\"grep\", \"search_error\", message);\n }\n};\n\nfunction collectFiles(dirPath: string): string[] {\n // If the path points directly to a file, return it as-is\n try {\n const stats = statSync(dirPath);\n if (stats.isFile()) {\n return [dirPath];\n }\n } catch {\n return [];\n }\n\n // Otherwise walk the directory tree\n const results: string[] = [];\n\n function walk(dir: string): void {\n let entries: string[];\n try {\n entries = readdirSync(dir);\n } catch {\n return;\n }\n\n for (const name of entries) {\n if (name === \".git\" || name === \"node_modules\") continue;\n\n const fullPath = resolve(dir, name);\n let stats: ReturnType<typeof statSync>;\n try {\n stats = statSync(fullPath);\n } catch {\n continue;\n }\n\n if (stats.isDirectory()) {\n walk(fullPath);\n } else if (stats.isFile() && stats.size > 0) {\n results.push(fullPath);\n }\n }\n }\n\n walk(dirPath);\n return results;\n}\n", "/**\n * Shell process registry for the Coder CLI.\n * Tracks shell processes started by the agent.\n */\n\nimport { spawn, type ChildProcess } from \"node:child_process\";\nimport type { ShellData, ShellInfo, ShellStatus } from \"./types\";\nimport { resolve } from \"node:path\";\n\ntype ManagedShell = {\n shellId: string;\n command: string;\n description?: string;\n process: ChildProcess;\n status: ShellStatus;\n exitCode?: number;\n stdout: string;\n stderr: string;\n workingDirectory: string;\n startedAtMs: number;\n taskId?: string;\n};\n\nconst shells = new Map<string, ManagedShell>();\n\nlet shellCounter = 0;\n\nfunction generateShellId(): string {\n shellCounter++;\n return `shell-${Date.now()}-${shellCounter}`;\n}\n\nexport async function executeShell(\n command: string,\n options: {\n workingDirectory?: string;\n description?: string;\n blockUntilMs?: number;\n taskId?: string;\n workspaceDir?: string | null;\n },\n): Promise<ShellData> {\n const shellId = generateShellId();\n const cwd = options.workspaceDir\n ? options.workingDirectory\n ? resolve(options.workspaceDir, options.workingDirectory)\n : options.workspaceDir\n : process.cwd();\n\n const startTime = Date.now();\n const blockMs = options.blockUntilMs ?? 30000;\n\n // Determine shell\n const isWindows = process.platform === \"win32\";\n const shellCmd = isWindows ? \"cmd.exe\" : \"/bin/sh\";\n const shellArgs = isWindows ? [\"/c\", command] : [\"-c\", command];\n\n return new Promise((resolvePromise) => {\n const child = spawn(shellCmd, shellArgs, {\n cwd,\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n shell: false,\n env: { ...process.env },\n });\n\n let stdout = \"\";\n let stderr = \"\";\n let settled = false;\n\n const shell: ManagedShell = {\n shellId,\n command,\n description: options.description,\n process: child,\n status: \"running\",\n stdout,\n stderr,\n workingDirectory: cwd,\n startedAtMs: startTime,\n taskId: options.taskId,\n };\n\n child.stdout?.on(\"data\", (data: Buffer) => {\n stdout += data.toString();\n shell.stdout = stdout;\n });\n\n child.stderr?.on(\"data\", (data: Buffer) => {\n stderr += data.toString();\n shell.stderr = stderr;\n });\n\n const finish = (status: ShellStatus, code?: number) => {\n if (settled) return;\n settled = true;\n shell.status = status;\n shell.exitCode = code;\n const duration = Date.now() - startTime;\n\n const stdoutBytes = Buffer.byteLength(stdout);\n const stderrBytes = Buffer.byteLength(stderr);\n\n // Remove from registry if background shell\n // (sync shells are removed automatically)\n if (blockMs <= 0) {\n // Background \u2014 keep in registry\n shells.set(shellId, shell);\n } else {\n shells.delete(shellId);\n }\n\n resolvePromise({\n command,\n description: options.description,\n workingDirectory: cwd,\n stdout,\n stderr,\n stdoutTruncated: stdoutBytes > 65536,\n stderrTruncated: stderrBytes > 65536,\n stdoutTotalBytes: stdoutBytes,\n stderrTotalBytes: stderrBytes,\n exitCode: code,\n durationMs: duration,\n status,\n shellId: blockMs <= 0 ? shellId : undefined,\n });\n };\n\n child.on(\"error\", (err) => {\n stderr += err.message;\n finish(\"failed\", 1);\n });\n\n child.on(\"close\", (code) => {\n finish(code === 0 ? \"completed\" : \"failed\", code ?? undefined);\n });\n\n // Timeout handling\n if (blockMs > 0) {\n const timeout = setTimeout(() => {\n if (!settled) {\n child.kill();\n finish(\"timeout\", undefined);\n }\n }, blockMs);\n\n child.on(\"close\", () => clearTimeout(timeout));\n }\n\n if (blockMs <= 0) {\n // Background mode \u2014 return immediately\n shells.set(shellId, shell);\n const stdoutBytes = Buffer.byteLength(stdout);\n const stderrBytes = Buffer.byteLength(stderr);\n resolvePromise({\n command,\n description: options.description,\n workingDirectory: cwd,\n stdout: \"\",\n stderr: \"\",\n stdoutTruncated: false,\n stderrTruncated: false,\n stdoutTotalBytes: 0,\n stderrTotalBytes: 0,\n exitCode: undefined,\n durationMs: 0,\n status: \"running\",\n shellId,\n });\n }\n });\n}\n\nexport async function awaitShell(\n shellId: string,\n blockUntilMs: number = 30000,\n): Promise<ShellData> {\n const shell = shells.get(shellId);\n if (!shell) {\n return {\n command: \"\",\n workingDirectory: \"\",\n stdout: \"\",\n stderr: \"\",\n stdoutTruncated: false,\n stderrTruncated: false,\n stdoutTotalBytes: 0,\n stderrTotalBytes: 0,\n durationMs: 0,\n status: \"completed\",\n shellId,\n };\n }\n\n // Wait for the process to complete (or timeout)\n return new Promise((resolvePromise) => {\n const startTime = Date.now();\n\n const checkProcess = () => {\n if (shell.exitCode !== undefined || shell.status !== \"running\") {\n const duration = Date.now() - startTime;\n const stdoutBytes = Buffer.byteLength(shell.stdout);\n const stderrBytes = Buffer.byteLength(shell.stderr);\n resolvePromise({\n command: shell.command,\n description: shell.description,\n workingDirectory: shell.workingDirectory,\n stdout: shell.stdout,\n stderr: shell.stderr,\n stdoutTruncated: stdoutBytes > 65536,\n stderrTruncated: stderrBytes > 65536,\n stdoutTotalBytes: stdoutBytes,\n stderrTotalBytes: stderrBytes,\n exitCode: shell.exitCode,\n durationMs: duration,\n status: shell.status,\n shellId,\n });\n return;\n }\n\n if (Date.now() - startTime > blockUntilMs) {\n const duration = Date.now() - startTime;\n const stdoutBytes = Buffer.byteLength(shell.stdout);\n const stderrBytes = Buffer.byteLength(shell.stderr);\n resolvePromise({\n command: shell.command,\n description: shell.description,\n workingDirectory: shell.workingDirectory,\n stdout: shell.stdout,\n stderr: shell.stderr,\n stdoutTruncated: stdoutBytes > 65536,\n stderrTruncated: stderrBytes > 65536,\n stdoutTotalBytes: stdoutBytes,\n stderrTotalBytes: stderrBytes,\n exitCode: shell.exitCode,\n durationMs: duration,\n status: shell.status,\n shellId,\n });\n return;\n }\n\n setTimeout(checkProcess, 50);\n };\n\n // Also listen for close event\n shell.process.on(\"close\", () => {\n checkProcess();\n });\n\n checkProcess();\n });\n}\n\nexport function listShells(statusFilter?: string): ShellInfo[] {\n const result: ShellInfo[] = [];\n\n for (const shell of shells.values()) {\n if (statusFilter && shell.status !== statusFilter && statusFilter !== \"all\") {\n continue;\n }\n\n result.push({\n shellId: shell.shellId,\n command: shell.command,\n description: shell.description,\n workingDirectory: shell.workingDirectory,\n status: shell.status,\n exitCode: shell.exitCode,\n startedAtMs: shell.startedAtMs,\n taskId: shell.taskId,\n stdout: shell.stdout,\n stderr: shell.stderr,\n stdoutTruncated: Buffer.byteLength(shell.stdout) > 65536,\n stderrTruncated: Buffer.byteLength(shell.stderr) > 65536,\n });\n }\n\n return result;\n}\n\nexport function killShell(shellId: string): boolean {\n const shell = shells.get(shellId);\n if (!shell) return false;\n\n try {\n shell.process.kill(\"SIGTERM\");\n shell.status = \"cancelled\";\n setTimeout(() => {\n try {\n shell.process.kill(\"SIGKILL\");\n } catch {\n // Already dead\n }\n }, 2000);\n return true;\n } catch {\n return false;\n }\n}\n\nexport function readShellLogs(\n shellId: string,\n stream: \"stdout\" | \"stderr\",\n offset: number = 0,\n limit: number = 4096,\n): { data: string; offset: number; totalBytes: number; truncated: boolean } {\n const shell = shells.get(shellId);\n if (!shell) {\n return { data: \"\", offset: 0, totalBytes: 0, truncated: false };\n }\n\n const content = stream === \"stdout\" ? shell.stdout : shell.stderr;\n const totalBytes = Buffer.byteLength(content);\n const sliced = content.slice(offset, offset + limit);\n\n return {\n data: sliced,\n offset: offset + sliced.length,\n totalBytes,\n truncated: offset + limit < totalBytes,\n };\n}\n\n/**\n * Kill all running background shells. Used on exit to prevent orphan processes.\n */\nexport function killAllShells(): void {\n for (const shell of shells.values()) {\n if (shell.status === \"running\") {\n try {\n shell.process.kill(\"SIGTERM\");\n } catch {\n // Process already dead\n }\n }\n }\n shells.clear();\n}\n\n/**\n * Kill all shells associated with a given task. Used on cancellation.\n */\nexport function killShellsByTask(taskId: string): void {\n for (const [id, shell] of shells) {\n if (shell.taskId === taskId && shell.status === \"running\") {\n try {\n shell.process.kill(\"SIGTERM\");\n } catch {\n // Process already dead\n }\n }\n }\n}\n", "import { toolFailure, toolSuccess } from \"./result\";\nimport type { ShellData, ToolHandler } from \"./types\";\nimport { executeShell } from \"./shell-manager\";\n\ntype ShellArgs = {\n command: string;\n description?: string;\n working_directory?: string;\n block_until_ms?: number;\n};\n\nexport const shellHandler: ToolHandler = async (rawArgs, context) => {\n const args = rawArgs as ShellArgs;\n\n if (!args.command?.trim()) {\n return toolFailure(\"shell\", \"invalid_arguments\", \"Command is required\");\n }\n\n try {\n const result = await executeShell(args.command.trim(), {\n workingDirectory: args.working_directory,\n description: args.description,\n blockUntilMs: args.block_until_ms ?? 30000,\n taskId: context.taskId,\n workspaceDir: context.workspaceDir,\n });\n\n return toolSuccess(\"shell\", result);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return toolFailure(\"shell\", \"execution_error\", message);\n }\n};\n", "import { toolFailure, toolSuccess } from \"./result\";\nimport type { ToolHandler } from \"./types\";\nimport { awaitShell } from \"./shell-manager\";\n\ntype AwaitArgs = {\n shell_id: string;\n block_until_ms?: number;\n};\n\nexport const awaitShellHandler: ToolHandler = async (rawArgs, _context) => {\n const args = rawArgs as AwaitArgs;\n\n if (!args.shell_id?.trim()) {\n return toolFailure(\"await\", \"invalid_arguments\", \"shell_id is required\");\n }\n\n try {\n const result = await awaitShell(args.shell_id.trim(), args.block_until_ms ?? 30000);\n return toolSuccess(\"await\", result);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return toolFailure(\"await\", \"error\", message);\n }\n};\n", "import { toolFailure, toolSuccess } from \"./result\";\nimport type { ToolHandler } from \"./types\";\nimport { listShells } from \"./shell-manager\";\n\ntype ListShellsArgs = {\n status_filter?: string;\n};\n\nexport const listShellsHandler: ToolHandler = async (rawArgs, _context) => {\n const args = rawArgs as ListShellsArgs;\n\n const shells = listShells(args.status_filter);\n\n return toolSuccess(\"list_shells\", {\n shells,\n total: shells.length,\n });\n};\n", "import { toolFailure, toolSuccess } from \"./result\";\nimport type { ToolHandler } from \"./types\";\nimport { killShell, readShellLogs } from \"./shell-manager\";\n\ntype KillShellArgs = {\n shell_id: string;\n};\n\nexport const killShellHandler: ToolHandler = async (rawArgs, _context) => {\n const args = rawArgs as KillShellArgs;\n\n if (!args.shell_id?.trim()) {\n return toolFailure(\"kill_shell\", \"invalid_arguments\", \"shell_id is required\");\n }\n\n const killed = killShell(args.shell_id.trim());\n return toolSuccess(\"kill_shell\", {\n shellId: args.shell_id.trim(),\n killed,\n });\n};\n", "import { toolFailure, toolSuccess } from \"./result\";\nimport type { ToolHandler } from \"./types\";\nimport { readShellLogs } from \"./shell-manager\";\n\ntype ReadShellLogsArgs = {\n shell_id: string;\n stream?: \"stdout\" | \"stderr\";\n offset?: number;\n limit?: number;\n};\n\nexport const readShellLogsHandler: ToolHandler = async (rawArgs, _context) => {\n const args = rawArgs as ReadShellLogsArgs;\n\n if (!args.shell_id?.trim()) {\n return toolFailure(\"read_shell_logs\", \"invalid_arguments\", \"shell_id is required\");\n }\n\n const result = readShellLogs(\n args.shell_id.trim(),\n args.stream ?? \"stdout\",\n args.offset ?? 0,\n args.limit ?? 4096,\n );\n\n return toolSuccess(\"read_shell_logs\", {\n shellId: args.shell_id.trim(),\n stream: args.stream ?? \"stdout\",\n data: result.data,\n offset: result.offset,\n totalBytes: result.totalBytes,\n truncated: result.truncated,\n });\n};\n", "import { toolFailure, toolSuccess } from \"./result\";\nimport type { ToolHandler } from \"./types\";\nimport { loadConfig, resolveTavilyApiKey } from \"../config\";\n\ntype WebSearchArgs = {\n search_term: string;\n max_results?: number;\n explanation?: string;\n};\n\nexport const webSearchHandler: ToolHandler = async (rawArgs, _context) => {\n const args = rawArgs as WebSearchArgs;\n\n if (!args.search_term?.trim()) {\n return toolFailure(\"web_search\", \"invalid_arguments\", \"search_term is required\");\n }\n\n const config = loadConfig();\n const tavilyKey = resolveTavilyApiKey(config);\n\n try {\n const results = await performWebSearch(args.search_term, args.max_results ?? 5, tavilyKey);\n\n return toolSuccess(\"web_search\", {\n query: args.search_term,\n results,\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return toolFailure(\"web_search\", \"search_error\", message);\n }\n};\n\nasync function performWebSearch(\n query: string,\n maxResults: number,\n tavilyKey: string,\n): Promise<Array<{ title: string; url: string; snippet: string }>> {\n // Try Tavily API first if a key is available\n if (tavilyKey) {\n try {\n const response = await fetch(\"https://api.tavily.com/search\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n api_key: tavilyKey,\n query,\n max_results: maxResults,\n search_depth: \"basic\",\n }),\n signal: AbortSignal.timeout(15000),\n });\n\n if (response.ok) {\n const data = (await response.json()) as {\n results?: Array<{ title: string; url: string; content: string }>;\n };\n if (data.results && data.results.length > 0) {\n return data.results.map((r) => ({\n title: r.title,\n url: r.url,\n snippet: r.content,\n }));\n }\n }\n } catch {\n // Fall through to DuckDuckGo\n }\n }\n\n // Fallback: DuckDuckGo instant answer API\n try {\n const url = `https://api.duckduckgo.com/?q=${encodeURIComponent(query)}&format=json&no_html=1&skip_disambig=1`;\n const response = await fetch(url, {\n signal: AbortSignal.timeout(10000),\n });\n\n if (!response.ok) throw new Error(`HTTP ${response.status}`);\n\n const data = (await response.json()) as {\n AbstractText?: string;\n AbstractSource?: string;\n AbstractURL?: string;\n RelatedTopics?: Array<{ Text?: string; FirstURL?: string; Result?: string }>;\n };\n\n const results: Array<{ title: string; url: string; snippet: string }> = [];\n\n if (data.AbstractText) {\n results.push({\n title: data.AbstractSource ?? \"Result\",\n url: data.AbstractURL ?? \"\",\n snippet: data.AbstractText,\n });\n }\n\n if (data.RelatedTopics) {\n for (const topic of data.RelatedTopics.slice(0, maxResults)) {\n if (topic.Text && topic.FirstURL) {\n results.push({\n title: topic.Text.split(\" - \")[0] ?? \"Result\",\n url: topic.FirstURL,\n snippet: topic.Text,\n });\n }\n }\n }\n\n if (results.length === 0) {\n throw new Error(\"No results\");\n }\n\n return results.slice(0, maxResults);\n } catch {\n throw new Error(\n \"Web search is currently unavailable. Configure a Tavily API key via `coder config tavilyApiKey <key>` or set the TAVILY_API_KEY environment variable.\",\n );\n }\n}\n", "import { toolFailure, toolSuccess } from \"./result\";\nimport type { ToolHandler } from \"./types\";\n\ntype BrowsePageArgs = {\n url: string;\n max_lines?: number;\n start_line?: number;\n explanation?: string;\n};\n\nexport const browsePageHandler: ToolHandler = async (rawArgs, _context) => {\n const args = rawArgs as BrowsePageArgs;\n\n if (!args.url?.trim()) {\n return toolFailure(\"browse_page\", \"invalid_arguments\", \"url is required\");\n }\n\n try {\n const response = await fetch(args.url.trim(), {\n headers: {\n \"User-Agent\": \"Mozilla/5.0 (compatible; CoderCLI/1.0)\",\n Accept: \"text/html,text/plain,*/*\",\n },\n signal: AbortSignal.timeout(15000),\n });\n\n const contentType = response.headers.get(\"content-type\") ?? \"text/plain\";\n const finalUrl = response.url;\n const title = extractTitleFromUrl(finalUrl);\n\n let content = await response.text();\n\n // Truncate if needed\n const startLine = args.start_line ?? 1;\n const maxLines = args.max_lines ?? 500;\n const lines = content.split(\"\\n\");\n const totalLines = lines.length;\n const endLine = Math.min(startLine + maxLines - 1, totalLines);\n const paginatedContent = lines.slice(startLine - 1, endLine).join(\"\\n\");\n\n return toolSuccess(\"browse_page\", {\n url: args.url,\n finalUrl,\n title,\n content: paginatedContent,\n truncated: endLine < totalLines,\n statusCode: response.status,\n contentType,\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (message.includes(\"fetch\")) {\n return toolFailure(\"browse_page\", \"network_error\", `Failed to fetch URL: ${message}`);\n }\n return toolFailure(\"browse_page\", \"error\", message);\n }\n};\n\nfunction extractTitleFromUrl(url: string): string | undefined {\n try {\n const parsed = new URL(url);\n return parsed.hostname;\n } catch {\n return undefined;\n }\n}\n", "import { existsSync, readFileSync, writeFileSync, mkdirSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { toolFailure, toolSuccess } from \"./result\";\nimport type { ToolHandler, TodoSnapshotItem } from \"./types\";\nimport { getConfigDirPath } from \"../config\";\n\n// Todos storage \u2014 per-session JSON files\nfunction getTodosFilePath(sessionId?: string): string {\n const dir = join(getConfigDirPath(), \"todos\");\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n const safeSessionId = (sessionId ?? \"default\").replace(/[^a-z0-9-]/gi, \"\");\n return join(dir, `${safeSessionId}.json`);\n}\n\ntype TodoRecord = {\n id: string;\n content: string;\n status: \"pending\" | \"in_progress\" | \"completed\" | \"cancelled\";\n order: number;\n createdAt: number;\n updatedAt: number;\n};\n\nfunction readTodos(sessionId?: string): TodoRecord[] {\n const filePath = getTodosFilePath(sessionId);\n if (!existsSync(filePath)) return [];\n try {\n return JSON.parse(readFileSync(filePath, \"utf-8\"));\n } catch {\n return [];\n }\n}\n\nfunction writeTodos(todos: TodoRecord[], sessionId?: string): void {\n writeFileSync(getTodosFilePath(sessionId), JSON.stringify(todos, null, 2), \"utf-8\");\n}\n\n// Handlers\ntype TodoReadArgs = { session_id?: string };\n\nexport const todoReadHandler: ToolHandler = async (rawArgs, context) => {\n const args = rawArgs as TodoReadArgs;\n const sessionId = args.session_id ?? context.sessionId;\n const todos = readTodos(sessionId);\n\n const snapshot: TodoSnapshotItem[] = todos\n .sort((a, b) => a.order - b.order)\n .map((t) => ({\n id: t.id,\n content: t.content,\n status: t.status,\n }));\n\n return toolSuccess(\"todo_read\", {\n sessionId: sessionId ?? null,\n todos: snapshot,\n total: snapshot.length,\n active: snapshot.filter((t) => t.status === \"pending\" || t.status === \"in_progress\").length,\n completed: snapshot.filter((t) => t.status === \"completed\").length,\n });\n};\n\ntype TodoWriteArgs = {\n todos: Array<{\n id: string;\n content: string;\n status: \"pending\" | \"in_progress\" | \"completed\" | \"cancelled\";\n }>;\n session_id?: string;\n};\n\nexport const todoWriteHandler: ToolHandler = async (rawArgs, context) => {\n const args = rawArgs as TodoWriteArgs;\n const sessionId = args.session_id ?? context.sessionId;\n\n if (!args.todos || !Array.isArray(args.todos)) {\n return toolFailure(\"todo_write\", \"invalid_arguments\", \"todos array is required\");\n }\n\n const existing = readTodos(sessionId);\n const existingMap = new Map(existing.map((t) => [t.id, t]));\n\n // Merge: update existing, add new\n for (let i = 0; i < args.todos.length; i++) {\n const input = args.todos[i];\n const existingRecord = existingMap.get(input.id);\n if (existingRecord) {\n existingRecord.content = input.content;\n existingRecord.status = input.status;\n existingRecord.updatedAt = Date.now();\n } else {\n existing.push({\n id: input.id,\n content: input.content,\n status: input.status,\n order: i,\n createdAt: Date.now(),\n updatedAt: Date.now(),\n });\n }\n }\n\n writeTodos(existing, sessionId);\n\n return toolSuccess(\"todo_write\", {\n total: existing.length,\n updated: args.todos.length,\n });\n};\n", "import { readdirSync, statSync } from \"node:fs\";\nimport { resolve, relative } from \"node:path\";\nimport { toolFailure, toolSuccess } from \"./result\";\nimport type { ToolHandler } from \"./types\";\n\ntype GetWorkspaceTreeArgs = {\n max_lines?: number;\n start_line?: number;\n};\n\nconst EXCLUDED_DIRS = new Set([\n \"node_modules\", \".git\", \"dist\", \"build\", \"target\", \".next\",\n \"out\", \".cache\", \".turbo\", \"coverage\", \".nyc_output\",\n \"__pycache__\", \".venv\", \"venv\", \".history\",\n]);\n\nexport const getWorkspaceTreeHandler: ToolHandler = async (rawArgs, context) => {\n const args = rawArgs as GetWorkspaceTreeArgs;\n\n if (!context.workspaceDir) {\n return toolFailure(\"get_workspace_tree\", \"workspace_required\", \"No workspace directory set\");\n }\n\n try {\n const rootDir = context.workspaceDir;\n const treeLines = buildTree(rootDir, rootDir, 0);\n const fullText = treeLines.join(\"\\n\");\n const totalLines = treeLines.length;\n const startLine = args.start_line ?? 1;\n const maxLines = args.max_lines ?? 500;\n const endLine = Math.min(startLine + maxLines - 1, totalLines);\n const paginatedText = treeLines.slice(startLine - 1, endLine).join(\"\\n\");\n\n return toolSuccess(\"get_workspace_tree\", {\n treeText: paginatedText,\n totalLines,\n startLine,\n endLine,\n truncated: endLine < totalLines,\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return toolFailure(\"get_workspace_tree\", \"error\", message);\n }\n};\n\nfunction buildTree(rootDir: string, currentDir: string, depth: number): string[] {\n const lines: string[] = [];\n const relPath = relative(rootDir, currentDir);\n\n if (depth === 0) {\n lines.push(relative(rootDir, currentDir) || \".\");\n }\n\n let entries: string[];\n try {\n entries = readdirSync(currentDir);\n } catch {\n return lines;\n }\n\n // Sort: directories first, then files, alphabetical\n const dirs: string[] = [];\n const files: string[] = [];\n\n for (const name of entries) {\n if (name.startsWith(\".\") && depth === 0 && name === \".git\") continue;\n if (EXCLUDED_DIRS.has(name)) continue;\n if (name.startsWith(\".\") && depth > 0) continue;\n\n const fullPath = resolve(currentDir, name);\n try {\n const stats = statSync(fullPath);\n if (stats.isDirectory()) {\n dirs.push(name);\n } else {\n files.push(name);\n }\n } catch {\n // skip\n }\n }\n\n dirs.sort();\n files.sort();\n\n const allEntries = [...dirs, ...files];\n\n for (let i = 0; i < allEntries.length; i++) {\n const name = allEntries[i];\n const isLast = i === allEntries.length - 1;\n const prefix = depth === 0 ? (isLast ? \"\u2514\u2500\u2500 \" : \"\u251C\u2500\u2500 \") : \"\";\n const childPrefix = depth === 0 ? (isLast ? \" \" : \"\u2502 \") : \"\";\n const fullPath = resolve(currentDir, name);\n\n lines.push(`${prefix}${name}`);\n\n try {\n const stats = statSync(fullPath);\n if (stats.isDirectory()) {\n const childLines = buildTreeFromDepth(rootDir, fullPath, depth + 1, prefix || \"\", childPrefix);\n lines.push(...childLines);\n }\n } catch {\n // skip\n }\n }\n\n return lines;\n}\n\nfunction buildTreeFromDepth(\n rootDir: string,\n currentDir: string,\n depth: number,\n parentPrefix: string,\n prefix: string,\n): string[] {\n const lines: string[] = [];\n\n let entries: string[];\n try {\n entries = readdirSync(currentDir);\n } catch {\n return lines;\n }\n\n const dirs: string[] = [];\n const files: string[] = [];\n\n for (const name of entries) {\n if (EXCLUDED_DIRS.has(name)) continue;\n if (name.startsWith(\".\")) continue;\n\n const fullPath = resolve(currentDir, name);\n try {\n const stats = statSync(fullPath);\n if (stats.isDirectory()) {\n dirs.push(name);\n } else {\n files.push(name);\n }\n } catch {\n // skip\n }\n }\n\n dirs.sort();\n files.sort();\n\n const allEntries = [...dirs, ...files];\n\n for (let i = 0; i < allEntries.length; i++) {\n const name = allEntries[i];\n const isLast = i === allEntries.length - 1;\n const linePrefix = `${prefix}${isLast ? \"\u2514\u2500\u2500 \" : \"\u251C\u2500\u2500 \"}`;\n const childPrefix = `${prefix}${isLast ? \" \" : \"\u2502 \"}`;\n\n lines.push(`${linePrefix}${name}`);\n\n const fullPath = resolve(currentDir, name);\n try {\n const stats = statSync(fullPath);\n if (stats.isDirectory()) {\n const childLines = buildTreeFromDepth(rootDir, fullPath, depth + 1, \"\", childPrefix);\n lines.push(...childLines);\n }\n } catch {\n // skip\n }\n }\n\n return lines;\n}\n", "import { createInterface } from \"node:readline\";\nimport { toolFailure, toolSuccess } from \"./result\";\nimport type { ToolHandler } from \"./types\";\n\nexport const askQuestionHandler: ToolHandler = async (rawArgs, _context) => {\n const args = rawArgs as { question: string };\n\n if (!args.question?.trim()) {\n return toolFailure(\"ask_question\", \"invalid_arguments\", \"question is required\");\n }\n\n // In non-interactive mode, return a placeholder\n const rl = createInterface({\n input: process.stdin,\n output: process.stderr,\n });\n\n const answer = await new Promise<string>((resolve) => {\n process.stderr.write(`\\n\\x1b[33m\u2753 ${args.question}\\x1b[0m\\n> `);\n rl.once(\"line\", (line) => {\n resolve(line.trim());\n });\n });\n\n rl.close();\n\n if (!answer) {\n return toolFailure(\"ask_question\", \"no_answer\", \"User did not provide an answer\");\n }\n\n return toolSuccess(\"ask_question\", {\n question: args.question,\n answer,\n });\n};\n", "import { toolFailure, toolSuccess } from \"./result\";\nimport type { ToolHandler } from \"./types\";\nimport type { AgentMode } from \"../agent/types\";\n\n// Forward reference \u2014 will be set when the agent system initializes\nlet spawnAgentFunction: ((task: string, context?: string, tools?: string[]) => Promise<unknown>) | null = null;\n\nexport function setSpawnAgentFunction(\n fn: (task: string, context?: string, tools?: string[]) => Promise<unknown>,\n): void {\n spawnAgentFunction = fn;\n}\n\ntype SpawnSubAgentArgs = {\n task: string;\n context?: string;\n tools?: string[];\n};\n\nexport const spawnSubAgentHandler: ToolHandler = async (rawArgs, _context) => {\n const args = rawArgs as SpawnSubAgentArgs;\n\n if (!args.task?.trim()) {\n return toolFailure(\"spawn_subagent\", \"invalid_arguments\", \"task is required\");\n }\n\n if (!spawnAgentFunction) {\n return toolFailure(\n \"spawn_subagent\",\n \"not_available\",\n \"Sub-agent spawning is not available in the current configuration.\",\n );\n }\n\n try {\n const result = await spawnAgentFunction(args.task, args.context, args.tools);\n return toolSuccess(\"spawn_subagent\", result);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return toolFailure(\"spawn_subagent\", \"execution_error\", message);\n }\n};\n", "/**\n * Tool handler registry \u2014 maps tool names to their CLI-native handlers.\n */\n\nimport type { ToolHandler, ToolResultEnvelope, ToolExecutionContext } from \"./types\";\nimport { listDirHandler } from \"./list-dir\";\nimport { readFileHandler } from \"./read-file\";\nimport { writeFileHandler } from \"./write-file\";\nimport { replaceFileHandler } from \"./replace-file\";\nimport { editFileHandler } from \"./edit-file\";\nimport { replaceLinesHandler } from \"./replace-lines\";\nimport { globHandler } from \"./glob\";\nimport { grepHandler } from \"./grep\";\nimport { shellHandler } from \"./shell\";\nimport { awaitShellHandler } from \"./await-shell\";\nimport { listShellsHandler } from \"./list-shells\";\nimport { killShellHandler } from \"./kill-shell\";\nimport { readShellLogsHandler } from \"./read-shell-logs\";\nimport { webSearchHandler } from \"./web-search\";\nimport { browsePageHandler } from \"./browse-page\";\nimport { todoReadHandler, todoWriteHandler } from \"./todos\";\nimport { getWorkspaceTreeHandler } from \"./workspace-tree\";\nimport { askQuestionHandler } from \"./ask-question\";\n\nimport { spawnSubAgentHandler } from \"./spawn-subagent\";\n\n// ---------------------------------------------------------------------------\n// Tool definitions (matching existing AgentToolDefinition format)\n// ---------------------------------------------------------------------------\n\nexport type ToolDefinition = {\n type: \"function\";\n function: {\n name: string;\n description: string;\n parameters: Record<string, unknown>;\n };\n};\n\nconst AGENT_TOOL_DEFINITIONS: ToolDefinition[] = [\n {\n type: \"function\",\n function: {\n name: \"list_dir\",\n description: \"List files and directories under a path. Relative paths are resolved against the workspace root.\",\n parameters: {\n type: \"object\",\n properties: {\n path: { type: \"string\", description: \"Relative or absolute path within the workspace.\" },\n recursive: { type: \"boolean\", description: \"Whether to list entries recursively.\", default: false },\n max_depth: { type: \"integer\", description: \"Maximum recursion depth when recursive is true.\", default: 1 },\n show_hidden: { type: \"boolean\", description: \"Whether to include dotfiles and dot-directories.\", default: false },\n },\n required: [\"path\"],\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"read_file\",\n description: \"Read a text file with line numbers and pagination. Relative paths are resolved against the workspace root.\",\n parameters: {\n type: \"object\",\n properties: {\n path: { type: \"string\", description: \"Relative or absolute path to the file within the workspace.\" },\n start_line: { type: \"integer\", description: \"First line to read (1-based).\", default: 1 },\n max_lines: { type: \"integer\", description: \"Maximum number of lines to return.\", default: 500 },\n respect_gitignore: { type: \"boolean\", description: \"Whether to refuse reading paths ignored by .gitignore.\", default: true },\n },\n required: [\"path\"],\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"write_file\",\n description: \"Create a new text file. Fails if the file already exists. Use edit_file or replace_lines to modify existing files.\",\n parameters: {\n type: \"object\",\n properties: {\n path: { type: \"string\", description: \"Relative or absolute path to the new file within the workspace.\" },\n content: { type: \"string\", description: \"Full file content to write.\" },\n create_parent_dirs: { type: \"boolean\", description: \"Whether to create missing parent directories.\", default: true },\n },\n required: [\"path\", \"content\"],\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"replace_file\",\n description: \"Replace an existing text file with new content. Use as a last resort \u2014 prefer edit_file or replace_lines first.\",\n parameters: {\n type: \"object\",\n properties: {\n path: { type: \"string\", description: \"Relative or absolute path to the file within the workspace.\" },\n content: { type: \"string\", description: \"Full replacement file content.\" },\n expected_sha256: { type: \"string\", description: \"SHA256 hash from read_file. Rejects the write if the file changed.\" },\n create_backup: { type: \"boolean\", description: \"Whether to save a backup copy under .history before writing.\", default: false },\n respect_gitignore: { type: \"boolean\", description: \"Whether to refuse editing paths ignored by .gitignore.\", default: true },\n },\n required: [\"path\", \"content\"],\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"edit_file\",\n description: \"Apply a search-and-replace edit to an existing text file. The primary file editing tool \u2014 use this first.\",\n parameters: {\n type: \"object\",\n properties: {\n path: { type: \"string\", description: \"Relative or absolute path to the file within the workspace.\" },\n old_string: { type: \"string\", description: \"Exact text to replace. Must match uniquely unless replace_all is true.\" },\n new_string: { type: \"string\", description: \"Replacement text.\" },\n expected_sha256: { type: \"string\", description: \"SHA256 hash from read_file. Rejects the edit if the file changed.\" },\n replace_all: { type: \"boolean\", description: \"Whether to replace every occurrence of old_string.\", default: false },\n create_backup: { type: \"boolean\", description: \"Whether to save a backup copy under .history before writing.\", default: false },\n respect_gitignore: { type: \"boolean\", description: \"Whether to refuse editing paths ignored by .gitignore.\", default: true },\n },\n required: [\"path\", \"old_string\", \"new_string\"],\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"replace_lines\",\n description: \"Replace a range of lines in an existing text file by line number. Read the file with read_file first to see line numbers.\",\n parameters: {\n type: \"object\",\n properties: {\n path: { type: \"string\", description: \"Relative or absolute path to the file within the workspace.\" },\n start_line: { type: \"integer\", description: \"First line to replace (1-based).\" },\n end_line: { type: \"integer\", description: \"Last line to replace (inclusive, 1-based).\" },\n content: { type: \"string\", description: \"Replacement content for the specified line range.\" },\n expected_sha256: { type: \"string\", description: \"SHA256 hash from read_file. Rejects the edit if the file changed.\" },\n create_backup: { type: \"boolean\", description: \"Whether to save a backup copy under .history before writing.\", default: false },\n respect_gitignore: { type: \"boolean\", description: \"Whether to refuse editing paths ignored by .gitignore.\", default: true },\n },\n required: [\"path\", \"start_line\", \"end_line\", \"content\"],\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"glob\",\n description: \"Find files by glob pattern under a directory. Relative paths are resolved against the workspace root.\",\n parameters: {\n type: \"object\",\n properties: {\n glob_pattern: { type: \"string\", description: \"Glob pattern such as **/*.tsx or src/**/*.rs.\" },\n target_directory: { type: \"string\", description: \"Directory to search from. Defaults to the workspace root.\" },\n head_limit: { type: \"integer\", description: \"Maximum number of matching paths to return.\", default: 100 },\n respect_gitignore: { type: \"boolean\", description: \"Whether to skip paths ignored by .gitignore.\", default: true },\n },\n required: [\"glob_pattern\"],\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"grep\",\n description: \"Search file contents with a regex pattern. Relative paths are resolved against the workspace root.\",\n parameters: {\n type: \"object\",\n properties: {\n pattern: { type: \"string\", description: \"Regular expression pattern to search for.\" },\n path: { type: \"string\", description: \"File or directory to search. Defaults to the workspace root.\" },\n glob: { type: \"string\", description: \"Optional glob filter to limit searched files.\" },\n output_mode: { type: \"string\", enum: [\"content\", \"files_with_matches\", \"count\"], default: \"content\" },\n case_insensitive: { type: \"boolean\", description: \"Whether to ignore letter case while matching.\", default: false },\n context_before: { type: \"integer\", description: \"Number of lines to include before each match.\" },\n context_after: { type: \"integer\", description: \"Number of lines to include after each match.\" },\n context: { type: \"integer\", description: \"Number of lines to include before and after each match.\" },\n head_limit: { type: \"integer\", description: \"Maximum number of results to return.\", default: 200 },\n offset: { type: \"integer\", description: \"Number of results to skip in content mode.\", default: 0 },\n multiline: { type: \"boolean\", description: \"Whether . should match newlines.\", default: false },\n respect_gitignore: { type: \"boolean\", description: \"Whether to skip paths ignored by .gitignore.\", default: true },\n },\n required: [\"pattern\"],\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"shell\",\n description: \"Execute a shell command in the workspace. Use for builds, tests, git, and other CLI tasks.\",\n parameters: {\n type: \"object\",\n properties: {\n command: { type: \"string\", description: \"The shell command to execute.\" },\n description: { type: \"string\", description: \"Short human-readable description for display only.\" },\n working_directory: { type: \"string\", description: \"Directory to run the command in, relative to workspace root.\" },\n block_until_ms: { type: \"integer\", description: \"Max wait time in ms. Default 30000. Use 0 for background mode.\", default: 30000 },\n },\n required: [\"command\"],\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"await\",\n description: \"Poll a background shell started with shell(block_until_ms=0) until it completes or times out.\",\n parameters: {\n type: \"object\",\n properties: {\n shell_id: { type: \"string\", description: \"The shell_id returned from a background shell invocation.\" },\n block_until_ms: { type: \"integer\", description: \"Max wait time in ms before returning current output.\", default: 30000 },\n },\n required: [\"shell_id\"],\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"list_shells\",\n description: \"List background shell processes started by the agent.\",\n parameters: {\n type: \"object\",\n properties: {\n status_filter: { type: \"string\", description: 'Filter by status. Default \"running\". Use \"all\" to include completed and failed shells.' },\n },\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"kill_shell\",\n description: \"Kill a running background shell process by shell_id.\",\n parameters: {\n type: \"object\",\n properties: {\n shell_id: { type: \"string\", description: \"The shell_id to terminate.\" },\n },\n required: [\"shell_id\"],\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"read_shell_logs\",\n description: \"Read logs from a shell process in batches.\",\n parameters: {\n type: \"object\",\n properties: {\n shell_id: { type: \"string\", description: \"The shell_id to read logs from.\" },\n stream: { type: \"string\", enum: [\"stdout\", \"stderr\"], default: \"stdout\" },\n offset: { type: \"integer\", description: \"Byte offset to start reading from.\", default: 0 },\n limit: { type: \"integer\", description: \"Maximum bytes to return.\", default: 4096 },\n },\n required: [\"shell_id\"],\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"web_search\",\n description: \"Search the web for real-time information outside training data.\",\n parameters: {\n type: \"object\",\n properties: {\n search_term: { type: \"string\", description: \"The search term to look up on the web.\" },\n max_results: { type: \"integer\", description: \"Maximum number of search results to return.\", default: 5 },\n explanation: { type: \"string\", description: \"One sentence explanation of why this search is being used.\" },\n },\n required: [\"search_term\"],\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"browse_page\",\n description: \"Fetch a public web page and return readable Markdown content.\",\n parameters: {\n type: \"object\",\n properties: {\n url: { type: \"string\", description: \"The URL to fetch. Must be http or https.\" },\n max_lines: { type: \"integer\", description: \"Maximum number of lines to return.\", default: 500 },\n start_line: { type: \"integer\", description: \"First line to read (1-based).\", default: 1 },\n explanation: { type: \"string\", description: \"One sentence explanation of why this page is being fetched.\" },\n },\n required: [\"url\"],\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"todo_read\",\n description: \"Read the current structured todo list for the session.\",\n parameters: {\n type: \"object\",\n properties: {\n session_id: { type: \"string\", description: \"Optional session ID.\" },\n },\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"todo_write\",\n description: \"Create and update a structured todo list for the session.\",\n parameters: {\n type: \"object\",\n properties: {\n todos: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n id: { type: \"string\" },\n content: { type: \"string\" },\n status: { type: \"string\", enum: [\"pending\", \"in_progress\", \"completed\", \"cancelled\"] },\n },\n required: [\"id\", \"content\", \"status\"],\n },\n },\n session_id: { type: \"string\", description: \"Optional session ID.\" },\n },\n required: [\"todos\"],\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"get_workspace_tree\",\n description: \"Display the workspace directory tree structure with depth recursion.\",\n parameters: {\n type: \"object\",\n properties: {\n max_lines: { type: \"integer\", description: \"Maximum number of lines to return.\", default: 500 },\n start_line: { type: \"integer\", description: \"First line to return (1-based).\", default: 1 },\n },\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"spawn_subagent\",\n description: \"Spawn a sub-agent to complete an independent sub-task.\",\n parameters: {\n type: \"object\",\n properties: {\n task: { type: \"string\", description: \"The task description for the sub-agent.\" },\n context: { type: \"string\", description: \"Optional additional context or constraints.\" },\n tools: { type: \"array\", items: { type: \"string\" }, description: \"Optional whitelist of tool names.\" },\n },\n required: [\"task\"],\n additionalProperties: false,\n },\n },\n },\n {\n type: \"function\",\n function: {\n name: \"ask_question\",\n description: \"Ask the user a question when you need additional information to proceed.\",\n parameters: {\n type: \"object\",\n properties: {\n question: { type: \"string\", description: \"The question to ask the user.\" },\n },\n required: [\"question\"],\n additionalProperties: false,\n },\n },\n },\n];\n\n// ---------------------------------------------------------------------------\n// Handler map\n// ---------------------------------------------------------------------------\n\nconst HANDLER_MAP: Record<string, ToolHandler> = {\n list_dir: listDirHandler,\n read_file: readFileHandler,\n write_file: writeFileHandler,\n replace_file: replaceFileHandler,\n edit_file: editFileHandler,\n replace_lines: replaceLinesHandler,\n glob: globHandler,\n grep: grepHandler,\n shell: shellHandler,\n await: awaitShellHandler,\n list_shells: listShellsHandler,\n kill_shell: killShellHandler,\n read_shell_logs: readShellLogsHandler,\n web_search: webSearchHandler,\n browse_page: browsePageHandler,\n todo_read: todoReadHandler,\n todo_write: todoWriteHandler,\n get_workspace_tree: getWorkspaceTreeHandler,\n spawn_subagent: spawnSubAgentHandler,\n ask_question: askQuestionHandler,\n};\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n// ---------------------------------------------------------------------------\n// Mode-based tool filtering\n// ---------------------------------------------------------------------------\n\nconst ASK_QUESTION_TOOL_NAME = \"ask_question\";\n\n/** Tools excluded from default \"agent\" mode. */\nconst AGENT_MODE_EXCLUDED_TOOL_NAMES = new Set([\n ASK_QUESTION_TOOL_NAME,\n]);\n\n/** Tools allowed in \\\"ask\\\" mode \u2014 only read-only / information-gathering. */\nconst ASK_MODE_TOOL_NAMES = new Set([\n \"list_dir\",\n \"read_file\",\n \"glob\",\n \"grep\",\n \"web_search\",\n \"browse_page\",\n \"todo_read\",\n \"list_shells\",\n \"read_shell_logs\",\n \"get_workspace_tree\",\n]);\n\n/**\n * Returns tool definitions filtered by agent mode.\n * - \"agent\": all tools except ask_question.\n * - \"ask\": only read-only tools.\n * - undefined: all tools (backward-compatible).\n */\nexport function getToolDefinitions(agentMode?: string): ToolDefinition[] {\n if (agentMode === \"ask\") {\n return AGENT_TOOL_DEFINITIONS.filter((t) =>\n ASK_MODE_TOOL_NAMES.has(t.function.name),\n );\n }\n\n // Default agent mode: exclude ask_question\n return AGENT_TOOL_DEFINITIONS.filter(\n (t) => !AGENT_MODE_EXCLUDED_TOOL_NAMES.has(t.function.name),\n );\n}\n\nexport function getToolHandler(name: string): ToolHandler | undefined {\n return HANDLER_MAP[name];\n}\n\nexport async function executeToolCall(\n name: string,\n rawArguments: string,\n context: ToolExecutionContext,\n): Promise<ToolResultEnvelope> {\n const handler = getToolHandler(name);\n if (!handler) {\n return {\n ok: false,\n tool: name,\n error: {\n code: \"unknown_tool\",\n message: `Unknown tool: ${name}`,\n },\n };\n }\n\n let parsedArgs: unknown;\n try {\n parsedArgs = rawArguments.trim() ? JSON.parse(rawArguments) : {};\n } catch {\n return {\n ok: false,\n tool: name,\n error: {\n code: \"invalid_arguments\",\n message: \"Tool arguments must be valid JSON\",\n },\n };\n }\n\n return handler(parsedArgs, context);\n}\n", "/**\n * Thinking config \u2014 per-provider API parameters for toggling deep thinking.\n *\n * Mirrors the web app's @/lib/model-provider/thinking-config.ts.\n * Each provider uses a different API convention for enabling/disabling reasoning.\n */\n\nexport type ThinkingParamsOverride = {\n enabled: Record<string, unknown>;\n disabled: Record<string, unknown>;\n};\n\n/**\n * Resolve the thinking extension parameters to merge into the chat completions\n * request body. Returns undefined when no parameters are needed (provider does\n * not have a preset and no custom override was supplied).\n */\nexport function resolveThinkingParams(\n provider: string,\n thinkingEnabled: boolean,\n override?: ThinkingParamsOverride,\n): Record<string, unknown> | undefined {\n // Custom override takes precedence (for e.g. custom provider)\n if (override) {\n return thinkingEnabled ? override.enabled : override.disabled;\n }\n const preset = THINKING_PRESETS[provider];\n if (!preset) return undefined;\n return thinkingEnabled ? preset.enabled : preset.disabled;\n}\n\nconst THINKING_PRESETS: Record<string, { enabled: Record<string, unknown>; disabled: Record<string, unknown> }> = {\n deepseek: {\n // @see https://api-docs.deepseek.com/guides/thinking_mode\n enabled: {\n thinking: { type: \"enabled\" },\n reasoning_effort: \"high\",\n },\n disabled: { thinking: { type: \"disabled\" } },\n },\n glm: {\n enabled: { thinking: { type: \"enabled\" } },\n disabled: { thinking: { type: \"disabled\" } },\n },\n agnes: {\n enabled: { chat_template_kwargs: { enable_thinking: true } },\n disabled: {},\n },\n nvidia: {\n enabled: { chat_template_kwargs: { enable_thinking: true } },\n disabled: { chat_template_kwargs: { enable_thinking: false } },\n },\n minimax: {\n enabled: {\n thinking: { type: \"adaptive\" },\n reasoning_split: true,\n },\n disabled: { thinking: { type: \"disabled\" } },\n },\n};\n", "/**\n * LLM Stream \u2014 handles SSE streaming from OpenAI-compatible chat completions API.\n */\n\nimport type { AgentChatMessage } from \"./types\";\nimport type { ToolDefinition } from \"../handlers\";\nimport { resolveThinkingParams, type ThinkingParamsOverride } from \"./thinking-config\";\n\ntype StreamCallbacks = {\n onContent: (delta: string) => void;\n onReasoning: (delta: string) => void;\n onToolCall: (id: string, name: string, args: string) => void;\n onUsage: (usage: { promptTokens: number; completionTokens: number; totalTokens: number }) => void;\n onDone: () => void;\n onError: (error: Error) => void;\n};\n\ntype StreamOptions = {\n baseUrl: string;\n apiKey: string;\n model: string;\n messages: AgentChatMessage[];\n tools?: ToolDefinition[];\n /** Provider ID used to resolve the correct thinking API params. */\n thinkingProvider?: string;\n /** When set, explicitly enable/disable deep thinking at the API level. */\n thinkingEnabled?: boolean;\n /** Custom override for thinking params (used by custom providers). */\n thinkingOverride?: ThinkingParamsOverride;\n /** Signal to cancel the stream mid-response. */\n signal?: AbortSignal;\n};\n\nfunction chatCompletionsUrl(baseUrl: string): string {\n const trimmed = baseUrl.trim().replace(/\\/+$/, \"\");\n if (trimmed.endsWith(\"/v1\")) {\n return `${trimmed}/chat/completions`;\n }\n return `${trimmed}/v1/chat/completions`;\n}\n\nexport async function startLLMStream(\n options: StreamOptions,\n callbacks: StreamCallbacks,\n): Promise<void> {\n const url = chatCompletionsUrl(options.baseUrl);\n\n // Build request body\n const body: Record<string, unknown> = {\n model: options.model,\n messages: options.messages.map(formatMessage),\n stream: true,\n stream_options: { include_usage: true },\n };\n\n if (options.tools && options.tools.length > 0) {\n body.tools = options.tools;\n body.tool_choice = \"auto\";\n }\n\n // Merge thinking extension params when explicitly requested\n if (\n options.thinkingEnabled !== undefined &&\n options.thinkingProvider\n ) {\n const thinkingParams = resolveThinkingParams(\n options.thinkingProvider,\n options.thinkingEnabled,\n options.thinkingOverride,\n );\n if (thinkingParams) {\n Object.assign(body, thinkingParams);\n }\n }\n\n try {\n const response = await fetch(url, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${options.apiKey}`,\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n },\n body: JSON.stringify(body),\n signal: options.signal,\n });\n\n if (!response.ok) {\n const errorBody = await response.text().catch(() => \"\");\n throw new Error(`API error (${response.status}): ${errorBody || response.statusText}`);\n }\n\n if (!response.body) {\n throw new Error(\"Response body is empty\");\n }\n\n const reader = response.body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n const toolCallAccumulator = new ToolCallAccumulator({\n onIdentified: (id, name) => {\n // Called when a tool call is first identified\n },\n });\n let hasToolCalls = false;\n\n // Cancel the reader when the signal is aborted mid-stream,\n // since reader.read() does not observe the AbortSignal automatically.\n const onAbort = () => {\n reader.cancel().catch(() => {});\n };\n options.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\n while (true) {\n if (options.signal?.aborted) {\n break;\n }\n let chunk: ReadableStreamReadResult<Uint8Array>;\n try {\n chunk = await reader.read();\n } catch {\n // Stream errored (e.g. from the underlying fetch abort), stop\n break;\n }\n const { done, value } = chunk;\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n\n while (true) {\n const lineBreak = buffer.indexOf(\"\\n\");\n if (lineBreak === -1) break;\n\n const line = buffer.slice(0, lineBreak).trim();\n buffer = buffer.slice(lineBreak + 1);\n processLine(line, callbacks, toolCallAccumulator);\n }\n }\n\n // Process any remaining data\n if (buffer.trim()) {\n processLine(buffer.trim(), callbacks, toolCallAccumulator);\n }\n\n // Finalize tool calls\n const finalToolCalls = toolCallAccumulator.finalize();\n for (const call of finalToolCalls) {\n callbacks.onToolCall(call.id, call.name, call.arguments);\n }\n\n callbacks.onDone();\n } catch (error) {\n if (error instanceof Error) {\n callbacks.onError(error);\n } else {\n callbacks.onError(new Error(String(error)));\n }\n }\n}\n\nfunction processLine(\n line: string,\n callbacks: StreamCallbacks,\n toolCalls: ToolCallAccumulator,\n): void {\n if (!line || line.startsWith(\":\")) return;\n\n const payload = line.startsWith(\"data:\") ? line.slice(5).trim() : line;\n if (payload === \"[DONE]\") return;\n\n let parsed: Record<string, unknown>;\n try {\n parsed = JSON.parse(payload) as Record<string, unknown>;\n } catch {\n return;\n }\n\n const choices = parsed.choices as Array<Record<string, unknown>> | undefined;\n const choice = choices?.[0];\n const delta = choice?.delta as Record<string, unknown> | undefined;\n\n if (delta) {\n // Reasoning content\n if (delta.reasoning_content) {\n callbacks.onReasoning(delta.reasoning_content as string);\n }\n\n // Text content\n if (delta.content) {\n callbacks.onContent(delta.content as string);\n }\n\n // Tool calls\n const toolCallDeltas = delta.tool_calls as Array<Record<string, unknown>> | undefined;\n if (toolCallDeltas) {\n for (const tcDelta of toolCallDeltas) {\n const index = tcDelta.index as number;\n const fn = tcDelta.function as Record<string, unknown> | undefined;\n const id = tcDelta.id as string | undefined;\n\n if (id) {\n toolCalls.startToolCall(index, id, fn?.name as string);\n } else if (fn?.arguments) {\n toolCalls.appendArguments(index, fn.arguments as string);\n }\n }\n }\n }\n\n // Usage\n const usage = parsed.usage as Record<string, unknown> | undefined;\n if (usage?.prompt_tokens !== undefined) {\n callbacks.onUsage({\n promptTokens: usage.prompt_tokens as number,\n completionTokens: usage.completion_tokens as number,\n totalTokens: usage.total_tokens as number,\n });\n }\n}\n\n// ---------------------------------------------------------------------------\n// Tool Call Accumulator\n// ---------------------------------------------------------------------------\n\ntype PendingToolCall = {\n index: number;\n id: string;\n name: string;\n arguments: string;\n};\n\nclass ToolCallAccumulator {\n private pending: Map<number, PendingToolCall> = new Map();\n private finalized = false;\n private onIdentified: (id: string, name: string) => void;\n\n constructor(opts: { onIdentified: (id: string, name: string) => void }) {\n this.onIdentified = opts.onIdentified;\n }\n\n startToolCall(index: number, id: string, name: string): void {\n this.pending.set(index, { index, id, name, arguments: \"\" });\n }\n\n appendArguments(index: number, args: string): void {\n const existing = this.pending.get(index);\n if (existing) {\n existing.arguments += args;\n }\n }\n\n finalize(): Array<{ id: string; name: string; arguments: string }> {\n if (this.finalized) return [];\n this.finalized = true;\n const calls = Array.from(this.pending.values())\n .sort((a, b) => a.index - b.index)\n .map((c) => ({\n id: c.id,\n name: c.name,\n arguments: c.arguments,\n }));\n return calls;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Message formatter for OpenAI API\n// ---------------------------------------------------------------------------\n\nfunction formatMessage(msg: AgentChatMessage): Record<string, unknown> {\n const formatted: Record<string, unknown> = {\n role: msg.role,\n };\n\n if (msg.content !== undefined) {\n formatted.content = msg.content;\n }\n\n if (msg.reasoning_content) {\n formatted.reasoning_content = msg.reasoning_content;\n }\n\n if (msg.tool_calls) {\n formatted.tool_calls = msg.tool_calls;\n }\n\n if (msg.tool_call_id) {\n formatted.tool_call_id = msg.tool_call_id;\n }\n\n if (msg.name) {\n formatted.name = msg.name;\n }\n\n return formatted;\n}\n", "/**\n * CLI Agent Runner\n *\n * Manages the multi-turn agent loop. This is a CLI-native implementation\n * that bypasses Tauri entirely and uses direct API calls + Node.js tool handlers.\n */\n\nimport { executeToolCall, getToolDefinitions } from \"../handlers\";\nimport type { ToolExecutionContext, ToolResultEnvelope } from \"../handlers/types\";\nimport type { AgentChatMessage, AgentEvent, AgentEventHandler, AgentStartInput, AgentMode } from \"./types\";\nimport { startLLMStream } from \"./llm-stream\";\nimport type { ThinkingParamsOverride } from \"./thinking-config\";\nimport { killShellsByTask } from \"../handlers/shell-manager\";\n\n// ---------------------------------------------------------------------------\n// Multi-turn agent loop\n// ---------------------------------------------------------------------------\n\ntype AgentTurnResult = {\n toolCalls: Array<{ id: string; name: string; arguments: string }>;\n content: string;\n reasoningContent: string;\n usage?: { promptTokens: number; completionTokens: number; totalTokens: number };\n};\n\nexport async function runAgentWithTools(\n input: AgentStartInput,\n toolContext: ToolExecutionContext,\n onEvent: AgentEventHandler,\n): Promise<AgentChatMessage[]> {\n let messages = [...input.messages];\n let cumulativeUsage: AgentTurnResult[\"usage\"] | undefined;\n\n while (true) {\n // Check for cancellation before each turn\n if (input.signal?.aborted) {\n killShellsByTask(input.taskId);\n onEvent({ type: \"status\", taskId: input.taskId, status: \"cancelled\" });\n onEvent({ type: \"done\", taskId: input.taskId, usage: cumulativeUsage });\n return messages;\n }\n\n let turn: AgentTurnResult;\n try {\n turn = await runSingleAgentTurn(input, messages, onEvent);\n } catch (err) {\n // Treat abort errors as graceful cancellation\n if (err instanceof Error && err.name === \"AbortError\") {\n killShellsByTask(input.taskId);\n onEvent({ type: \"status\", taskId: input.taskId, status: \"cancelled\" });\n onEvent({ type: \"done\", taskId: input.taskId, usage: cumulativeUsage });\n return messages;\n }\n throw err;\n }\n\n // Accumulate usage\n if (turn.usage) {\n cumulativeUsage = cumulativeUsage\n ? {\n promptTokens: cumulativeUsage.promptTokens + turn.usage.promptTokens,\n completionTokens: cumulativeUsage.completionTokens + turn.usage.completionTokens,\n totalTokens: cumulativeUsage.totalTokens + turn.usage.totalTokens,\n }\n : turn.usage;\n }\n\n // No tool calls \u2014 agent is done\n if (turn.toolCalls.length === 0) {\n // Append the final assistant response to messages for context persistence\n if (turn.content || turn.reasoningContent) {\n const assistantMessage: AgentChatMessage = { role: \"assistant\" };\n if (turn.content.trim()) {\n assistantMessage.content = turn.content;\n }\n if (turn.reasoningContent.trim()) {\n assistantMessage.reasoning_content = turn.reasoningContent;\n }\n messages = [...messages, assistantMessage];\n }\n onEvent({ type: \"done\", taskId: input.taskId, usage: cumulativeUsage ?? turn.usage });\n onEvent({ type: \"status\", taskId: input.taskId, status: \"completed\" });\n return messages;\n }\n\n // Execute tools and append results\n messages = await appendToolResults(messages, turn, toolContext, onEvent);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Single turn \u2014 stream from LLM and collect tool calls\n// ---------------------------------------------------------------------------\n\nasync function runSingleAgentTurn(\n input: AgentStartInput,\n messages: AgentChatMessage[],\n onEvent: AgentEventHandler,\n): Promise<AgentTurnResult> {\n return new Promise<AgentTurnResult>((resolve, reject) => {\n let content = \"\";\n let reasoningContent = \"\";\n const toolCalls: Array<{ id: string; name: string; arguments: string }> = [];\n let turnUsage: AgentTurnResult[\"usage\"] | undefined;\n\n startLLMStream(\n {\n baseUrl: input.baseUrl,\n apiKey: input.apiKey,\n model: input.model,\n messages,\n tools: getToolDefinitions(input.agentMode),\n thinkingProvider: input.provider,\n thinkingEnabled: input.thinkingEnabled,\n thinkingOverride: input.thinkingParams,\n signal: input.signal,\n },\n {\n onContent: (delta: string) => {\n content += delta;\n onEvent({ type: \"content_delta\", taskId: input.taskId, delta });\n },\n onReasoning: (delta: string) => {\n reasoningContent += delta;\n onEvent({ type: \"thinking_delta\", taskId: input.taskId, delta });\n },\n onToolCall: (id: string, name: string, args: string) => {\n toolCalls.push({ id, name, arguments: args });\n onEvent({ type: \"tool_call_pending\", taskId: input.taskId, toolCallId: id, name });\n },\n onUsage: (usage) => {\n turnUsage = usage;\n },\n onDone: () => {\n if (toolCalls.length > 0) {\n // Emit tool started events\n for (const call of toolCalls) {\n let parsedInput: unknown;\n try {\n parsedInput = call.arguments.trim() ? JSON.parse(call.arguments) : {};\n } catch {\n parsedInput = {};\n }\n onEvent({\n type: \"tool_call_started\",\n taskId: input.taskId,\n toolCallId: call.id,\n name: call.name,\n input: parsedInput,\n });\n }\n }\n resolve({ toolCalls, content, reasoningContent, usage: turnUsage });\n },\n onError: (error: Error) => {\n reject(error);\n },\n },\n );\n });\n}\n\n// ---------------------------------------------------------------------------\n// Tool result appending\n// ---------------------------------------------------------------------------\n\nasync function appendToolResults(\n messages: AgentChatMessage[],\n turn: AgentTurnResult,\n context: ToolExecutionContext,\n onEvent: AgentEventHandler,\n): Promise<AgentChatMessage[]> {\n // Build assistant message with tool calls\n const assistantMessage: AgentChatMessage = {\n role: \"assistant\",\n content: turn.content || undefined,\n reasoning_content: turn.reasoningContent || undefined,\n tool_calls: turn.toolCalls.map((tc) => ({\n id: tc.id,\n type: \"function\" as const,\n function: { name: tc.name, arguments: tc.arguments },\n })),\n };\n\n const nextMessages = [...messages, assistantMessage];\n\n // Execute all tools in parallel\n const results = await Promise.all(\n turn.toolCalls.map(async (call) => {\n try {\n const result = await executeToolCall(call.name, call.arguments, context);\n // Emit tool finished event\n if (result.ok) {\n onEvent({\n type: \"tool_call_finished\",\n taskId: context.taskId ?? \"\",\n toolCallId: call.id,\n output: result.data,\n });\n } else {\n onEvent({\n type: \"tool_call_finished\",\n taskId: context.taskId ?? \"\",\n toolCallId: call.id,\n errorText: result.error?.message,\n });\n }\n return { id: call.id, result };\n } catch (error) {\n const errorText = error instanceof Error ? error.message : String(error);\n onEvent({\n type: \"tool_call_finished\",\n taskId: context.taskId ?? \"\",\n toolCallId: call.id,\n errorText,\n });\n return {\n id: call.id,\n result: {\n ok: false,\n tool: call.name,\n error: { code: \"execution_error\", message: errorText },\n },\n };\n }\n }),\n );\n\n // Add tool result messages\n for (const { id, result } of results) {\n const content = result.ok\n ? JSON.stringify(result.data, null, 2)\n : JSON.stringify({ error: result.error }, null, 2);\n\n nextMessages.push({\n role: \"tool\",\n tool_call_id: id,\n content,\n });\n }\n\n return nextMessages;\n}\n", "/**\n * CLI Environment Resolver\n *\n * Resolves the runtime environment for the agent system prompt.\n * Aligned with the desktop version in src/features/agent/environment/.\n */\n\nimport { platform, release } from \"node:os\";\nimport { execSync } from \"node:child_process\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\nimport { SYSTEM_SKILLS } from \"@/features/skills/system/registry\";\nimport type { AgentMode } from \"../types\";\n\nexport type AgentEnvironment = {\n workspaceDir: string | null;\n os: string;\n shell: string;\n isGitRepository: boolean;\n today: string;\n agentsMd: { path: string; content: string; truncated: boolean } | null;\n enabledSystemSkills: Array<{ slug: string; name: string; content: string }>;\n};\n\nexport function resolveAgentEnvironment(\n workspaceDir: string | null\n): AgentEnvironment {\n const os = `${platform()} (${release()})`;\n const shell = resolveShell();\n const isGitRepository = workspaceDir\n ? checkIsGitRepository(workspaceDir)\n : false;\n const today = formatToday(new Date());\n\n let agentsMd: {\n path: string;\n content: string;\n truncated: boolean;\n } | null = null;\n\n if (workspaceDir) {\n const agentsMdPath = resolve(workspaceDir, \"AGENTS.md\");\n if (existsSync(agentsMdPath)) {\n const content = readFileSync(agentsMdPath, \"utf-8\");\n agentsMd = {\n path: agentsMdPath,\n content:\n content.length > 32_000\n ? content.slice(0, 32_000) + \"\\n... [truncated]\"\n : content,\n truncated: content.length > 32_000,\n };\n }\n }\n\n // System skills: use defaultEnabled since CLI has no database for preferences\n const enabledSystemSkills = SYSTEM_SKILLS.filter(\n (skill) => skill.defaultEnabled\n ).map((skill) => ({\n slug: skill.slug,\n name: skill.name,\n content: skill.content,\n }));\n\n return {\n workspaceDir,\n os,\n shell,\n isGitRepository,\n today,\n agentsMd,\n enabledSystemSkills,\n };\n}\n\nexport function buildSystemPrompt(\n env: AgentEnvironment,\n agentMode?: AgentMode\n): string {\n const workspaceLine = env.workspaceDir ?? \"not selected\";\n const gitLine = env.isGitRepository\n ? \"yes\"\n : env.workspaceDir\n ? \"no\"\n : \"unknown\";\n\n const modeLine = buildModeLine(agentMode);\n const modeGuidance = buildModeGuidance(agentMode, env.workspaceDir);\n\n const allBlocks: string[] = [];\n\n // Block 1: Identity + Environment\n allBlocks.push(\n [\n \"You are Coder, a helpful terminal AI assistant.\",\n \"\",\n \"## Environment\",\n \"\",\n `- workspaceDir: ${workspaceLine}`,\n `- os: ${env.os}`,\n `- shell: ${env.shell}`,\n `- gitRepository: ${gitLine}`,\n `- date: ${env.today}`,\n `- mode: ${modeLine}`,\n ].join(\"\\n\")\n );\n\n // Block 2: Communication Rules\n allBlocks.push(\n [\n \"## Communication Rules\",\n \"\",\n \"1. Reply in the same language the user uses. Be concise, accurate, and friendly.\",\n '2. Do not act unless the user has clearly asked you to. Answering questions, explaining, and analyzing do not require action \u2014 stop before reaching for tools.',\n ].join(\"\\n\")\n );\n\n // Blocks 3+: System Skills (one block per skill)\n for (const skill of env.enabledSystemSkills) {\n allBlocks.push(\n `## ${skill.name}\\n\\n${stripLeadingMarkdownH1(skill.content)}`\n );\n }\n\n // Block: Project Instructions (AGENTS.md)\n if (env.agentsMd?.content.trim()) {\n allBlocks.push(buildProjectInstructionsSection(env.agentsMd));\n }\n\n // Block: Mode Guidance (ask/plan only)\n if (modeGuidance.length > 0) {\n allBlocks.push(modeGuidance.join(\"\\n\"));\n }\n\n return allBlocks.join(\"\\n\\n---\\n\\n\");\n}\n\nfunction buildModeLine(agentMode?: AgentMode): string {\n switch (agentMode) {\n case \"ask\":\n return \"ask (read-only: can read files, search code, browse the web, and list skills \u2014 cannot modify files or run shell commands)\";\n default:\n return \"agent (full tool access)\";\n }\n}\n\nfunction buildModeGuidance(\n agentMode: AgentMode | undefined,\n _workspaceDir: string | null\n): string[] {\n if (agentMode === \"ask\") {\n return buildAskModeGuidance();\n }\n return [];\n}\n\nfunction buildAskModeGuidance(): string[] {\n return [\n \"## Mode Guidance\",\n \"\",\n \"You are in Ask mode \u2014 you can only read files, search, and browse.\",\n \"When the user asks you to modify files, run commands, or perform any write operation:\",\n ' - Explain that the task requires write access.',\n ' - Tell the user they can switch to Agent mode by using `coder run` instead of `coder ask` to give you full tool access.',\n \"Do NOT silently refuse or just say \\\"I can't do that.\\\" Always provide a clear path forward.\",\n ];\n}\n\nfunction buildProjectInstructionsSection(\n agentsMd: NonNullable<AgentEnvironment[\"agentsMd\"]>\n): string {\n const lines = [\n \"## Project instructions (AGENTS.md)\",\n \"\",\n \"Follow these project-specific rules when they do not conflict with the user's current message.\",\n agentsMd.content.trimEnd(),\n ];\n\n if (agentsMd.truncated) {\n lines.push(\n \"\",\n `Note: ${agentsMd.path} was truncated to 32 KB. Use read_file on ${agentsMd.path} to read the full file if needed.`\n );\n }\n\n return lines.join(\"\\n\");\n}\n\nfunction stripLeadingMarkdownH1(content: string): string {\n return content.replace(/^#\\s+[^\\n]+\\n+/, \"\").trim();\n}\n\nfunction formatToday(date: Date): string {\n return new Intl.DateTimeFormat(\"en-CA\", {\n year: \"numeric\",\n month: \"2-digit\",\n day: \"2-digit\",\n weekday: \"long\",\n timeZoneName: \"longOffset\",\n }).format(date);\n}\n\nfunction resolveShell(): string {\n const p = platform();\n if (p === \"win32\") {\n return process.env.COMSPEC || \"cmd.exe\";\n }\n return process.env.SHELL || \"/bin/sh\";\n}\n\nfunction checkIsGitRepository(dir: string): boolean {\n try {\n execSync(\"git rev-parse --is-inside-work-tree\", {\n cwd: dir,\n stdio: \"pipe\",\n timeout: 3000,\n });\n return true;\n } catch {\n return false;\n }\n}\n", "import type { SystemSkillDefinition } from \"../types\";\n\n/*\n * \u3010Agent \u64CD\u4F5C\u539F\u5219\u3011\n *\n * \u4F60\u662F\u4E00\u4E2A\u8F6F\u4EF6\u5DE5\u7A0B Agent\u3002\u4F60\u7684\u804C\u8D23\u662F\u7406\u89E3\u7528\u6237\u610F\u56FE\u3001\u505A\u51FA\u6B63\u786E\u4FEE\u6539\u3001\u9A8C\u8BC1\u7ED3\u679C\u3001\u51C6\u786E\u6C9F\u901A\u3002\n *\n * \u6838\u5FC3\u89C4\u5219\uFF1A\n * - \u9075\u5FAA\u7528\u6237\u8BF7\u6C42\uFF0C\u6CA1\u6709\u660E\u786E\u7406\u7531\u4E0D\u8981\u6269\u5927\u8303\u56F4\u3002\n * - \u8BC1\u636E\u4F18\u5148\u4E8E\u81EA\u4FE1\uFF0C\u5DE5\u5177\u8F93\u51FA\u6BD4\u5047\u8BBE\u66F4\u53EF\u9760\u3002\n * - \u4E0D\u8981\u628A\u731C\u6D4B\u8BF4\u6210\u4E8B\u5B9E\uFF1B\u8BC1\u636E\u4E0D\u8DB3\u65F6\u8981\u660E\u786E\u6807\u6CE8\u4E0D\u786E\u5B9A\u6027\u3002\n * - \u5173\u6CE8\u7528\u6237\u53EF\u89C1\u7684\u7ED3\u679C\uFF0C\u800C\u4E0D\u662F\u5185\u90E8\u6D3B\u52A8\u3002\n * - \u4FDD\u6301\u4FEE\u6539\u6B63\u786E\u3001\u53EF\u8BFB\u3001\u53EF\u7EF4\u62A4\u3001\u53EF\u6D4B\u8BD5\u3001\u5B89\u5168\u3002\n * - \u9664\u975E\u7528\u6237\u660E\u786E\u8981\u6C42\uFF0C\u5426\u5219\u4E0D\u8981 push\u3001\u6539\u5199\u5386\u53F2\u6216\u6267\u884C\u7834\u574F\u6027\u64CD\u4F5C\u3002\n *\n * \u51B3\u7B56\u987A\u5E8F\uFF1A\n * 0. \u5148\u5224\u65AD\u662F\u63D0\u95EE\u3001\u63A2\u7D22\u8FD8\u662F\u4FEE\u6539\u6307\u4EE4\u3002\u56DE\u7B54\u95EE\u9898\uFF1B\u53EA\u6709\u660E\u786E\u7684\u9700\u6C42\u624D\u884C\u52A8\u3002\n * 1. \u7406\u89E3\u8BF7\u6C42\u3002\n * 2. \u53EA\u6536\u96C6\u5B89\u5168\u884C\u52A8\u6240\u9700\u7684\u4E0A\u4E0B\u6587\u3002\n * 3. \u5DE5\u4F5C\u6709\u660E\u663E\u9636\u6BB5\u65F6\u518D\u89C4\u5212\u3002\n * 4. \u7528\u6700\u5C0F\u6539\u52A8\u9762\u89E3\u51B3\u95EE\u9898\u3002\n * 5. \u9A8C\u8BC1\u540E\u518D\u5BA3\u79F0\u6210\u529F\u3002\n * 6. \u62A5\u544A\u7ED3\u679C\u3001\u9A8C\u8BC1\u60C5\u51B5\u548C\u5269\u4F59\u98CE\u9669\u3002\n */\nconst OPERATING_PRINCIPLES_CONTENT = `# Agent Operating Principles\n\nYour job is to understand the user's intent, make correct changes, verify the result, and communicate accurately.\n\n### Core rules\n\n- Follow the user's request. Do not expand scope without a clear reason.\n- When the request has multiple valid interpretations, state your assumption\n explicitly and proceed. Only ask when the decision is costly to reverse.\n- Prefer evidence over confidence. Tool output is more reliable than assumptions.\n- Never present guesses as facts. Mark uncertainty plainly when evidence is incomplete.\n- Optimize for user-visible outcomes, not internal activity.\n- Keep changes correct, readable, maintainable, testable, and secure.\n- Do not push commits, rewrite history, or perform destructive actions unless explicitly instructed.\n\n### Decision order\n\n0. Determine whether this is a question, an exploration, or a change request.\n Answer questions directly; act only on clear instructions.\n1. Understand the request.\n2. Gather only the context needed to act safely.\n3. Plan when the work has meaningful phases.\n4. Modify the smallest surface that solves the problem.\n5. Verify before claiming success.\n6. Report the outcome, verification, and any remaining risk.\n`;\n\n/*\n * \u3010\u4E0A\u4E0B\u6587\u4E0E\u8BC1\u636E\u3011\n *\n * \u628A\u63D0\u4F9B\u7684\u4E0A\u4E0B\u6587\u5F53\u4F5C\u6709\u7528\u4FE1\u53F7\uFF0C\u800C\u4E0D\u662F\u7EDD\u5BF9\u771F\u7406\u3002\n *\n * \u4E0D\u8981\u5047\u8BBE\uFF1A\n * - \u6587\u4EF6\u5185\u5BB9\n * - \u4ED3\u5E93\u7ED3\u6784\n * - \u547D\u4EE4\u8F93\u51FA\n * - \u6D4B\u8BD5\u7ED3\u679C\n * - git \u72B6\u6001\n * - API \u884C\u4E3A\n * - \u7F51\u9875\u5185\u5BB9\n *\n * \u53EA\u8981\u7B54\u6848\u6216\u4FEE\u6539\u4F9D\u8D56\u8FD9\u4E9B\u4E8B\u5B9E\uFF0C\u5C31\u7528\u5DE5\u5177\u786E\u8BA4\u3002\n *\n * \u8BC1\u636E\u5904\u7406\uFF1A\n * - \u7F16\u8F91\u524D\u5148\u8BFB\u53D6\u76F8\u5173\u6587\u4EF6\u3002\n * - \u641C\u7D22\u7ED3\u679C\u7528\u4E8E\u51B3\u5B9A\u8BFB\u4EC0\u4E48\uFF0C\u4E0D\u80FD\u66FF\u4EE3\u5B9E\u9645\u68C0\u67E5\u3002\n * - shell\u3001linter\u3001\u6D4B\u8BD5\u3001git \u7684\u8F93\u51FA\u662F\u5F53\u524D\u5DE5\u4F5C\u533A\u72B6\u6001\u7684\u4E8B\u5B9E\u6765\u6E90\u3002\n * - \u8BC1\u636E\u4E0E\u9884\u671F\u77DB\u76FE\u65F6\uFF0C\u7ACB\u5373\u66F4\u65B0\u7406\u89E3\u3002\n * - \u7F3A\u5C11\u5FC5\u8981\u8BC1\u636E\u65F6\uFF0C\u8BF4\u660E\u7F3A\u4EC0\u4E48\uFF0C\u4E0D\u8981\u5047\u88C5\u5DF2\u5B8C\u5168\u9A8C\u8BC1\u3002\n */\nconst CONTEXT_AND_EVIDENCE_CONTENT = `# Context and Evidence\n\nTreat provided context as useful signal, not guaranteed truth.\n\nDo not assume:\n\n- file contents\n- repository structure\n- command output\n- test results\n- git state\n- API behavior\n- web content\n\nUse tools to confirm facts whenever the answer or change depends on them.\n\n### Evidence handling\n\n- Read the relevant file before editing it.\n- Use search results to decide what to inspect, not as a substitute for inspection.\n- Treat shell output, linter output, test output, and git output as source-of-truth for the current workspace state.\n- If evidence contradicts your expectation, update your understanding immediately.\n- If required evidence is unavailable, say what is missing and avoid pretending the task is fully verified.\n`;\n\n/*\n * \u3010\u5DE5\u5177\u4F7F\u7528\u3011\n *\n * \u5F53\u5DE5\u5177\u80FD\u63D0\u4F9B\u672C\u9700\u731C\u6D4B\u7684\u8BC1\u636E\u65F6\uFF0C\u5C31\u4F7F\u7528\u5DE5\u5177\u3002\n *\n * \u672C\u5730\u5DE5\u5177\uFF1A\n * - glob\uFF1A\u6309\u6587\u4EF6\u540D\u6A21\u5F0F\u627E\u6587\u4EF6\u3002\n * - grep\uFF1A\u6309\u552F\u4E00\u5B57\u7B26\u4E32\u3001\u7B26\u53F7\u3001\u8DEF\u5F84\u3001\u8DEF\u7531\u3001\u914D\u7F6E\u952E\u3001\u9519\u8BEF\u4FE1\u606F\u641C\u7D22\u5185\u5BB9\u3002\n * - shell\uFF1A\u6784\u5EFA\u3001\u6D4B\u8BD5\u3001git\u3001\u5305\u7BA1\u7406\u3001\u4ED3\u5E93\u68C0\u67E5\u3002\n * - \u547D\u4EE4\u975E\u4EA4\u4E92\u8FD0\u884C\uFF0C\u907F\u514D\u9700\u8981\u4EA4\u4E92\u8F93\u5165\u7684\u547D\u4EE4\u3002\n * - \u957F\u65F6\u95F4\u547D\u4EE4\uFF08dev server\u3001watch\uFF09\u7528 block_until_ms=0 \u542F\u52A8\uFF0C\u9700\u8981\u65F6\u518D await shell_id\u3002\n *\n * Web \u4E0E Skills\uFF1A\n * - web_search\uFF1A\u67E5\u7248\u672C\u76F8\u5173\u884C\u4E3A\u3001\u6700\u65B0\u6587\u6863\u7B49\u5916\u90E8\u4FE1\u606F\u3002\n * - browse_page\uFF1Aweb_search \u627E\u5230\u53EF\u9760\u6765\u6E90\u540E\u8BFB\u53D6\u5177\u4F53 URL\u3002\n * - browse_page \u53EF\u80FD\u65E0\u6CD5\u6E32\u67D3 JS \u91CD\u9875\u9762\uFF0C\u5F15\u7528\u68C0\u7D22\u5185\u5BB9\uFF0C\u4E0D\u8981\u7F16\u9020\u7EC6\u8282\u3002\n * - list_skills\uFF1A\u67E5\u770B\u53EF\u7528 skills\u3002\n * - read_skill\uFF1A\u9075\u5FAA skill \u524D\u5148\u8BFB\u53D6\u5B8C\u6574\u8BF4\u660E\u3002\n * - create_skill\uFF1A\u4EC5\u5F53\u7528\u6237\u8981\u6C42\u4FDD\u5B58\u53EF\u590D\u7528\u6307\u4EE4\u65F6\u4F7F\u7528\u3002\n *\n * \u5B50 Agent\uFF1A\n * - spawn_subagent\uFF1A\u5C06\u72EC\u7ACB\u5B50\u4EFB\u52A1\u59D4\u6258\u7ED9\u5B50 Agent\uFF0C\u9002\u7528\u4E8E\u591A\u6B65\u63A2\u7D22\u3001\u9A8C\u8BC1\u6216\u8C03\u7814\u3002\n *\n * \u5931\u8D25\u5904\u7406\uFF1A\n * 1. \u8BFB\u9519\u8BEF\u7801\u548C\u9519\u8BEF\u4FE1\u606F\u3002\n * 2. \u5F62\u6210\u65B0\u5047\u8BBE\u3002\n * 3. \u8C03\u6574\u65B9\u6848\u3002\n * \u4E0D\u8981\u5728\u4E0D\u5438\u53D6\u5931\u8D25\u6559\u8BAD\u7684\u60C5\u51B5\u4E0B\u91CD\u590D\u540C\u4E00\u5931\u8D25\u64CD\u4F5C\u3002\n */\nconst TOOL_USAGE_CONTENT = `# Tool Usage\n\nUse tools when they provide evidence that would otherwise be guessed.\n\n### Local tools\n\n- Use glob to find files by name pattern.\n- Use grep to search file contents by unique strings, symbols, paths, routes, config keys, or errors.\n- Use shell for builds, tests, git operations, package commands, and repository inspection.\n- Commands run non-interactively. Avoid commands that require interactive input.\n- For long-running commands such as dev servers or watch mode, run shell with \\`block_until_ms=0\\`, then await the returned \\`shell_id\\` when needed.\n- Use \\`get_workspace_tree\\` for a bird's-eye view of the project structure. It respects \\`.gitignore\\`, excludes large directories (\\`node_modules\\`, \\`.git\\`, \\`dist\\`, etc.) automatically, and paginates like \\`read_file\\` via \\`start_line\\` and \\`max_lines\\`. Prefer this over manually calling \\`list_dir\\` on every subdirectory.\n- **File editing workflow:** \\`edit_file\\` (search-and-replace, text-anchored) is the most common file editing tool \u2014 highest priority. If escaping issues arise, fall back to \\`replace_lines\\` (by line number, read the file again first to avoid line number drift). Last resort: \\`replace_file\\` (supports both partial and full replacement, but full replacement consumes many tokens \u2014 use sparingly). Use \\`write_file\\` to create new files. Use \\`read_file\\`'s \\`sha256\\` as \\`expected_sha256\\` for concurrent safety.\n\n### Web and skills\n\n- Use web_search for current or external information, such as version-specific behavior or recent documentation.\n- Use browse_page to read a specific URL after web_search finds a promising primary source.\n- browse_page may not render JavaScript-heavy pages. Quote retrieved content instead of inventing details.\n- Use list_skills to inspect available skills.\n- Use read_skill before following a skill's instructions.\n- Use create_skill only when the user asks to save reusable instructions.\n\n### Failure handling\n\nWhen a tool fails:\n\n1. Read the error code and message.\n2. Form a new hypothesis.\n3. Adjust the approach.\n\nDo not repeat the same failing action without learning from the failure.\n\n### Shell tools\n\nYou have 5 shell tools. Use them together:\n\n- **shell** \u2014 run a command. Set \\`block_until_ms=0\\` for background mode; returns a \\`shell_id\\`.\n- **await** \u2014 poll a background shell to completion. Pass the \\`shell_id\\` from shell.\n- **list_shells** \u2014 list active shells. Default shows running only; use \\`status_filter=\"all\"\\` to see all states.\n- **read_shell_logs** \u2014 read stdout/stderr from any shell. Paginate with \\`offset\\` and \\`limit\\`.\n- **kill_shell** \u2014 kill a running shell by \\`shell_id\\`. Cannot kill human terminals.\n\nWorkflows:\n1. **background + await**: \\`shell(cmd, {block_until_ms: 0})\\` \u2192 do other work \u2192 \\`await({shell_id})\\`\n2. **monitor progress**: \\`shell(background)\\` \u2192 \\`read_shell_logs\\` to peek \u2192 \\`await\\` when done\n3. **clean up**: \\`list_shells({status_filter: \"all\"})\\` \u2192 \\`read_shell_logs\\` \u2192 \\`kill_shell\\` if stuck\n\n**Remote target limitation:** When using \\`shell(target: \"<alias>\")\\`, background mode does NOT return a usable \\`shell_id\\`, so companion tools (\\`await\\`, \\`list_shells\\`, \\`kill_shell\\`, \\`read_shell_logs\\`) are not supported. Only blocking mode works for remote commands.\n\n### spawn_subagent\n\nUse spawn_subagent for independent tasks that require multi-step exploration, verification, or research.\n\nDo not use it for simple lookups, single-file reads, or tasks that can be completed with a few direct tool calls.\n\nBefore spawning, ask:\n1. Is the task independent?\n2. Does it require significant exploration?\n3. Would delegation improve focus?\n\nIf not, do the work yourself.\n\nProvide a clear task description and expected output. Sub-agents should return findings, evidence, and uncertainties.\n`;\n\n/*\n * \u3010\u4EE3\u7801\u5BFC\u822A\u3011\n *\n * \u4F18\u5148\u7528\u76F4\u63A5\u4FE1\u53F7\u5B9A\u4F4D\u4EE3\u7801\uFF0C\u4E0D\u8981\u6F2B\u65E0\u76EE\u7684\u6CBF\u4F9D\u8D56\u94FE\u8FFD\u8E2A\u3002\n *\n * \u9ED8\u8BA4\u6D41\u7A0B\uFF1Asearch -> inspect -> modify\uFF08\u641C\u7D22 -> \u68C0\u67E5 -> \u4FEE\u6539\uFF09\n *\n * \u9664\u975E\u76F4\u63A5\u641C\u7D22\u4E0D\u591F\uFF0C\u5426\u5219\u4E0D\u8981\u4ECE\u5165\u53E3\u4E00\u8DEF\u624B\u52A8 import \u8FFD\u8E2A\u3002\n *\n * \u641C\u7D22\u4FE1\u53F7\uFF08\u627E\u76EE\u6807\u4EE3\u7801\u6700\u72EC\u7279\u7684\u6807\u8BC6\uFF09\uFF1A\n * - \u51FD\u6570/\u65B9\u6CD5\u540D\uFF1AcalculateTotal\u3001handleSubmit\n * - \u5E38\u91CF/\u53D8\u91CF\u540D\uFF1AMAX_RETRY_COUNT\u3001workspaceName\n * - \u8DEF\u7531\u5B57\u7B26\u4E32\uFF1A\"/api/users\"\u3001\"/login\"\n * - \u6846\u67B6\u6CE8\u89E3\uFF1A@RestController\u3001@Service\n * - trait/\u63A5\u53E3/\u7C7B\u540D\uFF1AUserRepository\u3001impl Iterator\n * - \u6D4B\u8BD5\u63CF\u8FF0\uFF1A\"should return 401\"\u3001testShould\n * - \u914D\u7F6E\u952E\uFF1Adatabase.url\u3001logging.level\n * - \u6A21\u578B/\u8868/\u6A21\u5F0F\u540D\uFF1Ausers\u3001class User\n * - \u65E5\u5FD7\u3001\u6D4B\u8BD5\u3001\u7528\u6237\u63D0\u4F9B\u7684\u7CBE\u786E\u9519\u8BEF\u4FE1\u606F\n *\n * \u9605\u8BFB\u7EAA\u5F8B\uFF1A\n * - \u53EA\u8BFB\u7406\u89E3\u6216\u4FEE\u6539\u76EE\u6807\u884C\u4E3A\u6240\u9700\u7684\u6587\u4EF6\u3002\n * - \u5927\u6587\u4EF6\u4F18\u5148\u7A84\u8303\u56F4\u8BFB\u53D6\u76F8\u5173\u7247\u6BB5\u3002\n * - \u53EA\u6709\u5C40\u90E8\u4E0A\u4E0B\u6587\u4E0D\u591F\u65F6\u624D\u5411\u5916\u6269\u5C55\u3002\n */\nconst CODE_NAVIGATION_CONTENT = `# Code Navigation\n\nPrefer direct signals over dependency wandering.\n\n### Default flow\n\n\\`\\`\\`text\nsearch -> inspect -> modify\n\\`\\`\\`\n\nAvoid manually tracing long chains from entry point to imports unless direct search is insufficient.\n\n### Search signals\n\nSearch for the most unique signal the target code would contain:\n\n- function or method names: \\`calculateTotal\\`, \\`handleSubmit\\`\n- constants or variables: \\`MAX_RETRY_COUNT\\`, \\`workspaceName\\`\n- route strings: \\`\"/api/users\"\\`, \\`\"/login\"\\`\n- framework annotations: \\`@RestController\\`, \\`@Service\\`\n- trait, interface, or class names: \\`UserRepository\\`, \\`impl Iterator\\`\n- test descriptions: \\`\"should return 401\"\\`, \\`testShould\\`\n- config keys: \\`database.url\\`, \\`logging.level\\`\n- model, table, or schema names: \\`users\\`, \\`class User\\`\n- exact error messages from logs, tests, or users\n\n### Reading discipline\n\n- Read only files needed to understand or modify the target behavior.\n- Prefer narrow reads around relevant code when files are large.\n- Expand outward only when the local context is insufficient.\n`;\n\n/*\n * \u3010\u4EFB\u52A1\u89C4\u5212\u3011\n *\n * \u7528\u4EFB\u52A1\u8FDB\u5EA6\u5217\u8868\u8BA9\u6709\u610F\u4E49\u7684\u591A\u6B65\u9AA4\u5DE5\u4F5C\u6E05\u6670\u53EF\u89C1\u3002\n *\n * \u5E94\u521B\u5EFA\u4EFB\u52A1\u5217\u8868\u7684\u60C5\u51B5\uFF1A\n * - \u8DE8\u63A2\u7D22\u3001\u4FEE\u6539\u3001\u9A8C\u8BC1\u7684\u529F\u80FD\u5B9E\u73B0\n * - \u9700\u8981\u9A8C\u8BC1\u591A\u4E2A\u5047\u8BBE\u7684\u8C03\u8BD5\n * - \u8DE8\u591A\u6587\u4EF6/\u591A\u5C42\u7684\u91CD\u6784\u6216\u8FC1\u79FB\n * - \u6709\u660E\u663E\u9636\u6BB5\u7684\u5DE5\u4F5C\uFF1A\u8BBE\u8BA1\u3001\u5B9E\u73B0\u3001\u6D4B\u8BD5\u3001\u6253\u78E8\n * - \u7528\u6237\u53EF\u80FD\u4E2D\u9014\u79BB\u5F00\u7684\u957F\u4EFB\u52A1\n *\n * \u4E0D\u9700\u8981\u4EFB\u52A1\u5217\u8868\u7684\u60C5\u51B5\uFF1A\n * - \u7B80\u77ED\u56DE\u7B54\u6216\u89E3\u91CA\n * - \u5355\u6761\u547D\u4EE4\u8BF7\u6C42\n * - \u5355\u4E00\u660E\u663E\u7684\u5C0F\u6539\u52A8\n * - \u7EAF\u63A2\u7D22\u6027\u95EE\u9898\n * - \u7410\u788E\u7684\u540E\u7EED\u64CD\u4F5C\n *\n * \u4E0D\u786E\u5B9A\u65F6\uFF0C\u5B81\u53EF\u4E0D\u8981\u5217\u8868\uFF0C\u4E5F\u4E0D\u8981\u566A\u97F3\u8FC7\u591A\u7684\u5217\u8868\u3002\n *\n * \u4EFB\u52A1\u8BBE\u8BA1\uFF1A\n * - \u5199\u7ED3\u679C\u5BFC\u5411\u4EFB\u52A1\uFF0C\u5982\u300C\u6DFB\u52A0 OAuth \u56DE\u8C03\u6821\u9A8C\u300D\uFF0C\u800C\u4E0D\u662F\u300C\u8BFB auth \u6587\u4EF6\u300D\u3002\n * - \u7C92\u5EA6\u9002\u4E2D\uFF0C\u901A\u5E38 3-5 \u9879\uFF0C\u65B9\u4FBF\u7528\u6237\u8DDF\u8E2A\u3002\n * - \u540C\u65F6\u6700\u591A\u4E00\u4E2A\u4EFB\u52A1\u8FDB\u884C\u4E2D\u3002\n * - \u4EFB\u52A1\u771F\u6B63\u5B8C\u6210\u65F6\u7ACB\u5373\u6807\u8BB0\u5B8C\u6210\u3002\n * - \u8303\u56F4\u53D8\u5316\u65F6\u91CD\u547D\u540D\u3001\u589E\u5220\u3001\u53D6\u6D88\u4EFB\u52A1\u3002\n */\nconst TASK_PLANNING_CONTENT = `# Task Planning\n\nUse the task-progress list to make meaningful multi-step work legible.\n\n### Create a task list when\n\n- implementing a feature across exploration, edits, and verification\n- debugging with multiple hypotheses\n- refactoring or migrating several files or layers\n- finishing work with clear phases such as design, implement, test, polish\n- running long work where the user may return later\n\n### Skip a task list for\n\n- short answers or explanations\n- one-command requests\n- a single obvious edit\n- pure exploration questions\n- trivial follow-ups\n\nWhen unsure, prefer no list over a noisy one.\n\n### Task design\n\n- Write outcome-oriented tasks: \"Add OAuth callback validation\", not \"Read auth file\".\n- Keep tasks coarse enough for the user to follow, usually 3-5 items.\n- Keep at most one task in progress.\n- Mark tasks complete as soon as they are actually complete.\n- Rename, add, cancel, or remove tasks when scope changes.\n`;\n\n/*\n * \u3010\u4EE3\u7801\u4FEE\u6539\u3011\n *\n * \u50CF\u7EF4\u62A4\u8005\u4E00\u6837\u6539\u4EE3\u7801\uFF0C\u4E0D\u8981\u50CF\u8865\u4E01\u751F\u6210\u5668\u3002\n *\n * \u7F16\u8F91\u524D\uFF1A\n * 1. \u5B9A\u4F4D\u76F8\u5173\u5B9E\u73B0\u3002\n * 2. \u7406\u89E3\u5468\u8FB9\u4E0A\u4E0B\u6587\u3002\n * 3. \u627E\u51FA\u89E3\u51B3\u8BF7\u6C42\u95EE\u9898\u7684\u6700\u5C0F\u6539\u52A8\u3002\n *\n * \u7F16\u8F91\u89C4\u5219\uFF1A\n * - \u4F18\u5148\u6700\u5C0F\u3001\u9488\u5BF9\u6027\u7684\u6539\u52A8\u3002\n * - \u9075\u5FAA\u73B0\u6709\u547D\u540D\u3001\u67B6\u6784\u3001\u683C\u5F0F\u3001\u6D4B\u8BD5\u3001\u9519\u8BEF\u5904\u7406\u6A21\u5F0F\u3002\n * - \u4E0D\u8981\u65E0\u8C13\u91CD\u5199\u53EF\u7528\u4EE3\u7801\u3002\n * - \u4E0D\u8981\u6539\u65E0\u5173\u884C\u4E3A\u3002\n * - \u9664\u975E\u7528\u6237\u8981\u6C42\uFF0C\u4E0D\u8981\u53EA\u505A\u98CE\u683C\u6539\u52A8\u3002\n * - \u6CA1\u6709\u660E\u786E\u7406\u7531\u4E0D\u8981\u5220\u529F\u80FD\u3002\n * - \u4E0D\u8981\u8986\u76D6\u7528\u6237\u6539\u52A8\uFF1B\u5DE5\u4F5C\u533A\u810F\u65F6\u4E0E\u73B0\u6709\u6539\u52A8\u534F\u4F5C\uFF0C\u4E0D\u8981 revert\u3002\n * - \u7ED3\u6784\u5316\u6570\u636E\u4F18\u5148\u7528\u7ED3\u6784\u5316 API \u6216\u89E3\u6790\u5668\u3002\n *\n * \u9AD8\u98CE\u9669\u533A\u57DF\uFF1A\n * \u8BA4\u8BC1\u3001\u6388\u6743\u3001\u6301\u4E45\u5316\u3001\u8FC1\u79FB\u3001\u751F\u4EA7\u914D\u7F6E\u3001\u5BC6\u94A5\u3001\u7834\u574F\u6027\u64CD\u4F5C\u9700\u683C\u5916\u8C28\u614E\u3002\n */\nconst CODE_MODIFICATION_CONTENT = `# Code Modification\n\nMake changes as a maintainer, not as a patch generator.\n\n### Before editing\n\n1. Locate the relevant implementation.\n2. Understand surrounding context.\n3. Identify the smallest change that solves the requested problem.\n\n### Editing rules\n\n- Prefer minimal, targeted changes.\n- Follow existing naming, architecture, formatting, testing, and error-handling patterns.\n- Do not rewrite working code unnecessarily.\n- Do not change unrelated behavior.\n- Do not introduce style-only edits unless requested.\n- Do not remove functionality without a clear reason.\n- Do not overwrite user changes. If the working tree is dirty, work with existing changes instead of reverting them.\n- Use structured APIs or parsers for structured data when available.\n\n### High-risk areas\n\nBe extra careful with authentication, authorization, persistence, migrations, production configuration, secrets, and destructive operations.\n`;\n\n/*\n * \u3010\u9A8C\u8BC1\u3011\n *\n * \u4E0D\u8981\u53EA\u56E0\u4E3A\u6539\u4E86\u4EE3\u7801\u5C31\u5BA3\u79F0\u6210\u529F\u3002\n *\n * \u6539\u4EE3\u7801\u540E\uFF1A\n * 1. \u53EF\u884C\u65F6\u91CD\u8BFB\u6539\u52A8\u533A\u57DF\u3002\n * 2. \u5BA1\u67E5 diff\uFF0C\u786E\u8BA4\u53EA\u6709\u9884\u671F\u6539\u52A8\u3002\n * 3. \u8FD0\u884C\u6700\u76F8\u5173\u7684\u9A8C\u8BC1\u3002\n * 4. \u62A5\u544A\u5DF2\u9A8C\u8BC1\u548C\u672A\u9A8C\u8BC1\u7684\u5185\u5BB9\u3002\n *\n * \u4F18\u5148\u76F8\u5173\u68C0\u67E5\uFF1A\n * - TypeScript\uFF1Atsc --noEmit\u3001\u6846\u67B6\u7C7B\u578B\u68C0\u67E5\u6216\u9879\u76EE\u811A\u672C\u3002\n * - \u6D4B\u8BD5\uFF1A\u5148\u505A\u805A\u7126\u6D4B\u8BD5\uFF0C\u98CE\u9669\u9AD8\u65F6\u518D\u8DD1\u66F4\u5927\u5957\u4EF6\u3002\n * - \u6784\u5EFA\uFF1A\u5F71\u54CD\u6253\u5305\u3001\u8DEF\u7531\u3001\u751F\u6210\u7269\u3001\u8FD0\u884C\u65F6\u63A5\u7EBF\u65F6\u8FD0\u884C\u3002\n * - Linter\uFF1A\u8FD0\u884C\u6216\u67E5\u770B\u6539\u52A8\u6587\u4EF6\u7684\u8BCA\u65AD\u3002\n *\n * \u9A8C\u8BC1\u5931\u8D25\uFF1A\u8BFB\u9519\u8BEF\u3001\u4FEE\u590D\u8303\u56F4\u5185\u95EE\u9898\u3001\u91CD\u8DD1\u76F8\u5173\u68C0\u67E5\u3002\n * \u65E0\u6CD5\u9A8C\u8BC1\uFF1A\u660E\u786E\u8BF4\u660E\u3002\n */\nconst VERIFICATION_CONTENT = `# Verification\n\nDo not claim success solely because code was changed.\n\n### After changing code\n\n1. Re-read the changed area when practical.\n2. Review the diff to confirm only intended changes are included.\n3. Before running any verification command, call list_shells first to check whether the user already has a running dev server or relevant process. If one exists, prefer telling the user to reload over starting a new instance. Only run a new verification command when no relevant process is already running.\n4. Run the most relevant verification available.\n5. Report what was verified and what was not.\n\n### Prefer relevant checks\n\n- TypeScript: \\`tsc --noEmit\\`, framework type checks, or project scripts.\n- Tests: focused tests first, broader suites when risk is high.\n- Builds: run when the change can affect packaging, routing, generated output, or runtime wiring.\n- Linters: run or inspect diagnostics for changed files.\n\nIf verification fails, read the error, fix what is in scope, and rerun the relevant check. If verification cannot be run, state that clearly.\n`;\n\n/*\n * \u3010Git \u5DE5\u4F5C\u6D41\u3011\n *\n * Git \u64CD\u4F5C\u5FC5\u987B\u53CD\u6620\u4ED3\u5E93\u771F\u5B9E\u72B6\u6001\u3002\n *\n * \u63D0\u4EA4\u524D\uFF1A\n * - \u67E5\u770B git status\u3002\n * - \u89C6\u60C5\u51B5\u67E5\u770B git diff \u548C git diff --staged\u3002\n * - \u4E0D\u8981\u5047\u8BBE\u6682\u5B58\u533A\u5185\u5BB9\u4E0E\u5F53\u524D\u4EFB\u52A1\u4E00\u81F4\u3002\n * - \u4E0D\u8981\u63D0\u4EA4\u5BC6\u94A5\u6216\u51ED\u8BC1\u3002\n *\n * \u6682\u5B58\uFF1A\n * - \u53EA stage \u4E0E\u672C\u6B21\u6539\u52A8\u76F8\u5173\u7684\u6587\u4EF6\u3002\n * - \u9664\u975E\u7528\u6237\u660E\u786E\u8981\u6C42\u5168\u90E8\u7EB3\u5165\uFF0C\u5426\u5219\u907F\u514D git add . \u548C git add -A\u3002\n * - \u65E0\u5173\u4FEE\u6539\u4FDD\u6301 unstaged\u3002\n *\n * \u63D0\u4EA4\uFF1A\n * - commit message \u53EA\u57FA\u4E8E staged \u53D8\u66F4\u751F\u6210\u3002\n * - \u4F7F\u7528 Conventional Commits\uFF1Atype(scope): summary\u3002\n * - subject \u5C11\u4E8E 72 \u5B57\u7B26\u3002\n * - \u4FDD\u6301 commit \u903B\u8F91\u8FDE\u8D2F\u3002\n *\n * Push \u884C\u4E3A\uFF1A\n * - \u300Ccommit\u300D= \u53EA\u63D0\u4EA4\u3002\n * - \u300Cpush\u300D= \u53EA\u63A8\u9001\u3002\n * - \u300Ccommit and push\u300D= \u4E24\u8005\u90FD\u505A\u3002\n * - \u672A\u660E\u786E\u6307\u793A\u65F6\u7EDD\u4E0D push\u3002\n */\nconst GIT_WORKFLOW_CONTENT = `# Git Workflow\n\nGit operations must reflect actual repository state.\n\n### Before committing\n\n- Review \\`git status\\`.\n- Review \\`git diff\\` and \\`git diff --staged\\` as appropriate.\n- Do not assume staged content matches the current task.\n- Do not commit secrets or credentials.\n\n### Staging\n\n- Stage only files related to the intended change.\n- Avoid \\`git add .\\` and \\`git add -A\\` unless the user explicitly wants all changes included.\n- Leave unrelated modifications unstaged.\n\n### Commits\n\n- Generate commit messages from staged changes only.\n- Use Conventional Commits: \\`type(scope): summary\\`.\n- Keep the subject under 72 characters.\n- Keep commits logically coherent.\n\n### Push behavior\n\n- \"commit\" means commit only.\n- \"push\" means push only.\n- \"commit and push\" means both.\n- Never push unless explicitly instructed.\n`;\n\n/*\n * \u3010\u6C9F\u901A\u3011\n *\n * \u4F20\u8FBE\u7ED3\u8BBA\u3001\u51B3\u7B56\u3001\u963B\u585E\u70B9\u548C\u9A8C\u8BC1\u7ED3\u679C\u3002\n *\n * \u98CE\u683C\uFF1A\n * - \u7B80\u6D01\u76F4\u63A5\u3002\n * - \u4E0D\u8981\u53D9\u8FF0\u6BCF\u4E2A\u5DE5\u5177\u8C03\u7528\u3002\n * - \u4E0D\u8981\u66B4\u9732\u9690\u85CF\u63A8\u7406\u94FE\u3002\n * - \u4E0D\u8981\u628A\u5185\u90E8\u6D3B\u52A8\u5305\u88C5\u6210\u6210\u679C\u3002\n * - \u8BDA\u5B9E\u8BF4\u660E\u4E0D\u786E\u5B9A\u6027\u548C\u963B\u585E\u3002\n * - \u62A5\u544A\u5B8C\u6210\u65F6\u5305\u542B\u7528\u6237\u53EF\u89C1\u7ED3\u679C\u548C\u5DF2\u505A\u9A8C\u8BC1\u3002\n *\n * \u5BA1\u67E5\u7C7B\u56DE\u590D\uFF1A\n * \u7528\u6237\u8981\u6C42 review \u65F6\uFF0C\u4F18\u5148\u62A5\u544A\u53D1\u73B0\uFF1A\n * - \u6B63\u786E\u6027 bug\n * - \u5B89\u5168\u98CE\u9669\n * - \u884C\u4E3A\u56DE\u5F52\n * - \u6709\u610F\u4E49\u98CE\u9669\u4E0B\u7F3A\u5931\u7684\u6D4B\u8BD5\n *\n * \u6309\u4E25\u91CD\u7A0B\u5EA6\u6392\u5E8F\u3002\u82E5\u65E0\u95EE\u9898\uFF0C\u660E\u786E\u8BF4\u660E\uFF0C\u5E76\u63D0\u53CA\u6B8B\u7559\u98CE\u9669\u6216\u672A\u8DD1\u68C0\u67E5\u3002\n */\nconst COMMUNICATION_CONTENT = `# Communication\n\nCommunicate conclusions, decisions, blockers, and verification results.\n\n### Style\n\n- Be concise and direct.\n- Do not narrate every tool call.\n- Do not reveal hidden chain-of-thought.\n- Do not frame internal activity as an accomplishment.\n- Explain uncertainty and blockers honestly.\n- When reporting completion, include the user-visible result and verification performed.\n\n### Reviews\n\nWhen the user asks for a review, prioritize findings first:\n\n- correctness bugs\n- security risks\n- behavioral regressions\n- missing tests for meaningful risk\n\nOrder findings by severity. If no issues are found, say so and mention residual risk or unrun checks.\n`;\n\n/*\n * \u3010\u4EE3\u7801\u5BA1\u67E5\u5DE5\u4F5C\u6D41\u3011\n *\n * \u5BA1\u67E5\u4EE3\u7801\u65F6\u4F7F\u7528\u6B64\u6D41\u7A0B\uFF0C\u800C\u4E0D\u662F\u5B9E\u73B0\u6539\u52A8\u3002\n *\n * \u5BA1\u67E5\u91CD\u70B9\uFF1A\n * 1. \u6B63\u786E\u6027\u4E0E\u8FB9\u754C\u60C5\u51B5\u3002\n * 2. \u5B89\u5168\u95EE\u9898\uFF1A\u6CE8\u5165\u3001XSS\u3001\u6388\u6743\u6F0F\u6D1E\u3001\u5BC6\u94A5\u6CC4\u9732\u3002\n * 3. \u884C\u4E3A\u56DE\u5F52\u3002\n * 4. \u9519\u8BEF\u5904\u7406\u4E0E\u5931\u8D25\u6A21\u5F0F\u3002\n * 5. \u6709\u610F\u4E49\u884C\u4E3A\u7684\u6D4B\u8BD5\u8986\u76D6\u3002\n * 6. \u5F71\u54CD\u672A\u6765\u6B63\u786E\u6027\u7684\u53EF\u8BFB\u6027\u4E0E\u53EF\u7EF4\u62A4\u6027\u3002\n *\n * \u53CD\u9988\u683C\u5F0F\uFF1A\n * - \u5148\u5217\u53D1\u73B0\uFF0C\u6309\u4E25\u91CD\u7A0B\u5EA6\u6392\u5E8F\u3002\n * - \u5F15\u7528\u5177\u4F53\u6587\u4EF6\u6216\u7B26\u53F7\u3002\n * - \u8BF4\u660E\u5F71\u54CD\uFF0C\u800C\u4E0D\u53EA\u662F\u504F\u597D\u3002\n * - \u603B\u7ED3\u7B80\u77ED\u3001\u6B21\u8981\u3002\n * - \u65E0\u53D1\u73B0\u65F6\u660E\u786E\u8BF4\u660E\uFF0C\u5E76\u5217\u51FA\u9A8C\u8BC1\u7F3A\u53E3\u3002\n */\nconst CODE_REVIEW_CONTENT = `# Code Review Workflow\n\nUse this workflow when reviewing code rather than implementing changes.\n\n### Review focus\n\n1. Correctness and edge cases.\n2. Security issues such as injection, XSS, authorization gaps, and leaked secrets.\n3. Behavioral regressions.\n4. Error handling and failure modes.\n5. Test coverage for meaningful behavior.\n6. Readability and maintainability when it affects future correctness.\n\n### Feedback format\n\n- Lead with findings, ordered by severity.\n- Cite the specific file or symbol involved.\n- Explain the impact, not just the preference.\n- Keep summaries brief and secondary.\n- If there are no findings, say that clearly and list any verification gaps.\n`;\n\nexport const SYSTEM_SKILLS: SystemSkillDefinition[] = [\n {\n id: \"agent-operating-principles\",\n slug: \"agent-operating-principles\",\n name: \"Agent Operating Principles\",\n description:\n \"Core identity, priorities, and decision order for software engineering agent work.\",\n content: OPERATING_PRINCIPLES_CONTENT,\n defaultEnabled: true,\n category: \"core\",\n },\n {\n id: \"context-and-evidence\",\n slug: \"context-and-evidence\",\n name: \"Context and Evidence\",\n description:\n \"How to treat workspace context, tool output, uncertainty, and evidence before acting.\",\n content: CONTEXT_AND_EVIDENCE_CONTENT,\n defaultEnabled: true,\n category: \"core\",\n },\n {\n id: \"tool-usage\",\n slug: \"tool-usage\",\n name: \"Tool Usage\",\n description:\n \"When and how to use filesystem, shell, web, and skill tools for reliable evidence.\",\n content: TOOL_USAGE_CONTENT,\n defaultEnabled: true,\n category: \"core\",\n },\n {\n id: \"code-navigation\",\n slug: \"code-navigation\",\n name: \"Code Navigation\",\n description:\n \"Search-first navigation rules for locating relevant code without wasting context.\",\n content: CODE_NAVIGATION_CONTENT,\n defaultEnabled: true,\n category: \"development\",\n },\n {\n id: \"task-planning\",\n slug: \"task-planning\",\n name: \"Task Planning\",\n description:\n \"When and how to use the session task-progress list for multi-step work.\",\n content: TASK_PLANNING_CONTENT,\n defaultEnabled: true,\n category: \"workflow\",\n },\n {\n id: \"code-modification\",\n slug: \"code-modification\",\n name: \"Code Modification\",\n description:\n \"Rules for making minimal, maintainable, and project-consistent code changes.\",\n content: CODE_MODIFICATION_CONTENT,\n defaultEnabled: true,\n category: \"development\",\n },\n {\n id: \"verification\",\n slug: \"verification\",\n name: \"Verification\",\n description:\n \"How to validate changes before claiming success and how to report unverified work.\",\n content: VERIFICATION_CONTENT,\n defaultEnabled: true,\n category: \"workflow\",\n },\n {\n id: \"git-workflow\",\n slug: \"git-workflow\",\n name: \"Git Workflow\",\n description:\n \"Safe staging, commit, and push boundaries based on actual git state.\",\n content: GIT_WORKFLOW_CONTENT,\n defaultEnabled: true,\n category: \"workflow\",\n },\n {\n id: \"communication\",\n slug: \"communication\",\n name: \"Communication\",\n description:\n \"How to communicate outcomes, uncertainty, blockers, verification, and review findings.\",\n content: COMMUNICATION_CONTENT,\n defaultEnabled: true,\n category: \"core\",\n },\n {\n id: \"code-review\",\n slug: \"code-review\",\n name: \"Code Review Workflow\",\n description:\n \"Specialized workflow for reviewing code for correctness, security, regressions, and tests.\",\n content: CODE_REVIEW_CONTENT,\n defaultEnabled: false,\n category: \"review\",\n },\n];\n\nconst slugSet = new Set<string>();\n\nfor (const skill of SYSTEM_SKILLS) {\n if (slugSet.has(skill.slug)) {\n throw new Error(`Duplicate system skill slug: ${skill.slug}`);\n }\n slugSet.add(skill.slug);\n}\n\nexport function getSystemSkillBySlug(\n slug: string\n): SystemSkillDefinition | null {\n return SYSTEM_SKILLS.find((skill) => skill.slug === slug) ?? null;\n}\n\nexport function getSystemSkillById(id: string): SystemSkillDefinition | null {\n return SYSTEM_SKILLS.find((skill) => skill.id === id) ?? null;\n}\n\nexport function getAllSystemSkillSlugs(): Set<string> {\n return new Set(SYSTEM_SKILLS.map((skill) => skill.slug));\n}\n", "/**\n * Agent Session \u2014 manages a single agent session lifecycle.\n * Connects the agent loop to the CLI output.\n */\n\nimport type { AgentMode, AgentChatMessage, AgentEvent } from \"./types\";\nimport { runAgentWithTools } from \"./runner\";\nimport { resolveAgentEnvironment, buildSystemPrompt } from \"./environment\";\nimport { resolveProviderConfig, resolveApiKey, loadConfig } from \"../config\";\nimport type { ToolExecutionContext } from \"../handlers/types\";\nimport type { ThinkingParamsOverride } from \"./thinking-config\";\nimport { error, warning, info, dim, bold, success, writeStream, writeLine, writeError } from \"../ui\";\nimport { killAllShells } from \"../handlers/shell-manager\";\n\nexport type SessionOptions = {\n agentMode: AgentMode;\n workspaceDir: string;\n interactive: boolean;\n model?: string;\n provider?: string;\n stream?: boolean;\n /** Explicitly enable or disable deep thinking. When undefined, model defaults apply. */\n thinking?: boolean;\n /**\n * Existing conversation history to continue from.\n * When provided, the system prompt is assumed to already be in the messages.\n * The new user prompt will be appended.\n */\n existingMessages?: AgentChatMessage[];\n /** Signal to cancel the agent mid-session. */\n signal?: AbortSignal;\n};\n\n/**\n * Run an agent session.\n * Returns the updated messages array so callers (e.g. REPL) can persist context.\n */\nexport async function runAgentSession(\n prompt: string,\n options: SessionOptions,\n): Promise<AgentChatMessage[]> {\n const config = loadConfig();\n const workspaceDir = options.workspaceDir || null;\n\n // Resolve provider\n const providerId = (options.provider as any) ?? config.activeProvider;\n const resolvedConfig = resolveProviderConfig(config, providerId);\n const apiKey = resolveApiKey(resolvedConfig);\n\n // Resolve model\n const modelId = options.model ?? config.lastModel;\n\n // Determine whether thinking is supported for the resolved model\n const modelDef = resolvedConfig.models.find((m) => m.id === modelId);\n const supportsThinking =\n modelDef?.supportsThinking === true ||\n config.providers[resolvedConfig.provider]?.supportsThinking === true;\n const thinkingEnabled =\n options.thinking !== undefined && supportsThinking\n ? options.thinking\n : undefined;\n\n // Build custom thinking params override from config (for custom providers)\n let thinkingParamsOverride: ThinkingParamsOverride | undefined;\n if (thinkingEnabled !== undefined) {\n const settings = config.providers[resolvedConfig.provider];\n if (settings?.thinkingEnabledParams && settings?.thinkingDisabledParams) {\n thinkingParamsOverride = {\n enabled: settings.thinkingEnabledParams,\n disabled: settings.thinkingDisabledParams,\n };\n }\n }\n\n // Build messages \u2014 either continue from existing or start fresh\n let messages: AgentChatMessage[];\n\n if (options.existingMessages && options.existingMessages.length > 0) {\n // Continue conversation: existing messages already contain the system prompt.\n // Sanitize the history before reusing it \u2014 filter out assistant messages\n // that have neither content nor tool_calls (e.g. reasoning-only turns).\n messages = [\n ...sanitizeMessages(options.existingMessages),\n { role: \"user\", content: prompt },\n ];\n } else {\n // Fresh session: build system prompt\n const env = resolveAgentEnvironment(workspaceDir);\n const systemPrompt = buildSystemPrompt(env, options.agentMode);\n messages = [\n { role: \"system\", content: systemPrompt },\n { role: \"user\", content: prompt },\n ];\n }\n\n const taskId = `task-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;\n const isStreaming = options.stream !== false;\n\n let currentContent = \"\";\n let currentThinking = \"\";\n let hasContent = false;\n let streamStarted = false;\n\n // Tool execution context\n const toolContext: ToolExecutionContext = {\n workspaceDir,\n sessionId: taskId,\n taskId,\n agentMode: options.agentMode,\n };\n\n if (!isStreaming) {\n writeLine(`${info(\"\u2139\")} Running agent in ${bold(options.agentMode)} mode...\\n`);\n }\n\n try {\n const finalMessages = await runAgentWithTools(\n {\n taskId,\n baseUrl: resolvedConfig.baseUrl,\n apiKey,\n apiKeySource: resolvedConfig.apiKeySource,\n apiKeyEnvVar: resolvedConfig.apiKeyEnvVar,\n model: modelId,\n messages,\n agentMode: options.agentMode,\n provider: providerId,\n thinkingEnabled,\n thinkingParams: thinkingParamsOverride,\n signal: options.signal,\n },\n toolContext,\n (event: AgentEvent) => {\n switch (event.type) {\n case \"thinking_delta\": {\n currentThinking += event.delta;\n if (isStreaming && !hasContent) {\n if (!streamStarted) {\n streamStarted = true;\n writeLine(\"\");\n }\n writeStream(dim(event.delta));\n }\n break;\n }\n\n case \"content_delta\": {\n if (isStreaming) {\n if (!streamStarted) {\n streamStarted = true;\n }\n if (!hasContent && currentThinking) {\n // Transition from thinking to content\n writeLine(\"\");\n }\n hasContent = true;\n currentContent += event.delta;\n writeStream(event.delta);\n }\n break;\n }\n\n case \"tool_call_started\": {\n if (isStreaming) {\n if (!streamStarted) {\n streamStarted = true;\n writeLine(\"\");\n } else if (hasContent || currentThinking) {\n // Separator from content or thinking before showing tool\n writeLine(\"\");\n }\n writeLine(`${dim(\"\uD83D\uDD27\")} ${bold(event.name)}${dim(\"...\")}`);\n }\n break;\n }\n\n case \"tool_call_finished\": {\n if (event.errorText) {\n writeLine(` ${error(\"\u2717\")} ${dim(event.errorText.slice(0, 200))}`);\n } else if (isStreaming) {\n writeLine(` ${success(\"\u2713\")} ${dim(\"done\")}`);\n }\n break;\n }\n\n case \"status\": {\n if (event.status === \"completed\") {\n if (isStreaming) {\n writeLine(\"\");\n writeLine(success(\"\u2713 Task completed\"));\n } else {\n writeLine(success(\"\u2713 Task completed\"));\n if (currentContent) {\n writeLine(\"\\n\" + currentContent);\n }\n }\n } else if (event.status === \"failed\") {\n writeLine(error(`\u2717 Task failed`));\n } else if (event.status === \"cancelled\") {\n writeLine(warning(`\u26A0 Task cancelled`));\n }\n break;\n }\n\n case \"done\": {\n break;\n }\n\n case \"error\": {\n writeLine(error(`\u2717 Error: ${event.message}`));\n break;\n }\n }\n },\n );\n return finalMessages;\n } catch (err) {\n killAllShells();\n const message = err instanceof Error ? err.message : String(err);\n writeError(error(`Fatal error: ${message}`));\n process.exit(1);\n }\n}\n\n/**\n * Sanitize conversation history before reusing it.\n * Filters out assistant messages that have neither content, reasoning_content,\n * nor tool_calls \u2014 these would cause API 400 errors on the next request.\n * Mirrors the desktop's hasMessagePayload filter in build-agent-messages.ts.\n */\nfunction sanitizeMessages(messages: AgentChatMessage[]): AgentChatMessage[] {\n return messages.filter((msg) => {\n if (msg.role !== \"assistant\") return true;\n const text = typeof msg.content === \"string\" ? msg.content : undefined;\n return (\n Boolean(text?.trim()) ||\n Boolean(msg.reasoning_content?.trim()) ||\n Boolean(msg.tool_calls?.length)\n );\n });\n}\n", "/**\n * Terminal output utilities for Coder CLI.\n * Provides colored output, progress indication, and streaming helpers.\n */\n\nimport { isatty } from \"node:tty\";\n\nconst stdoutIsTTY = isatty(process.stdout.fd);\nconst stderrIsTTY = isatty(process.stderr.fd);\n\n// ANSI color codes (no dependency on chalk for speed)\nconst colors = {\n reset: \"\\x1b[0m\",\n bold: \"\\x1b[1m\",\n dim: \"\\x1b[2m\",\n italic: \"\\x1b[3m\",\n red: \"\\x1b[31m\",\n green: \"\\x1b[32m\",\n yellow: \"\\x1b[33m\",\n blue: \"\\x1b[34m\",\n magenta: \"\\x1b[35m\",\n cyan: \"\\x1b[36m\",\n gray: \"\\x1b[90m\",\n};\n\nexport function colorize(text: string, color: keyof typeof colors): string {\n if (!stdoutIsTTY) return text;\n return `${colors[color]}${text}${colors.reset}`;\n}\n\nexport function dim(text: string): string {\n return colorize(text, \"dim\");\n}\n\nexport function bold(text: string): string {\n if (!stdoutIsTTY) return text;\n return `${colors.bold}${text}${colors.reset}`;\n}\n\nexport function error(text: string): string {\n return colorize(text, \"red\");\n}\n\nexport function success(text: string): string {\n return colorize(text, \"green\");\n}\n\nexport function warning(text: string): string {\n return colorize(text, \"yellow\");\n}\n\nexport function info(text: string): string {\n return colorize(text, \"cyan\");\n}\n\n// ---------------------------------------------------------------------------\n// Streaming output\n// ---------------------------------------------------------------------------\n\nexport function writeStream(text: string): void {\n process.stdout.write(text);\n}\n\nexport function writeLine(text: string): void {\n process.stdout.write(text + \"\\n\");\n}\n\nexport function writeError(text: string): void {\n process.stderr.write(text + \"\\n\");\n}\n\n// ---------------------------------------------------------------------------\n// Spinner / progress\n// ---------------------------------------------------------------------------\n\nconst SPINNER_FRAMES = [\"\u280B\", \"\u2819\", \"\u2839\", \"\u2838\", \"\u283C\", \"\u2834\", \"\u2826\", \"\u2827\", \"\u2807\", \"\u280F\"];\n\nexport class Spinner {\n private frame = 0;\n private interval: ReturnType<typeof setInterval> | null = null;\n private message = \"\";\n private running = false;\n\n start(message: string): void {\n if (!stderrIsTTY) {\n writeError(`\u23F3 ${message}`);\n return;\n }\n\n this.message = message;\n this.running = true;\n this.frame = 0;\n process.stderr.write(`${SPINNER_FRAMES[0]} ${message}`);\n this.interval = setInterval(() => {\n this.frame = (this.frame + 1) % SPINNER_FRAMES.length;\n process.stderr.write(`\\r${SPINNER_FRAMES[this.frame]} ${this.message}`);\n }, 80);\n }\n\n update(message: string): void {\n this.message = message;\n if (this.interval) {\n process.stderr.write(`\\r${SPINNER_FRAMES[this.frame]} ${this.message}`);\n }\n }\n\n stop(finalMessage?: string): void {\n if (this.interval) {\n clearInterval(this.interval);\n this.interval = null;\n }\n this.running = false;\n // Clear the spinner line\n if (stderrIsTTY) {\n process.stderr.write(\"\\r\\x1b[K\");\n }\n if (finalMessage) {\n writeError(finalMessage);\n }\n }\n\n succeed(text: string): void {\n this.stop(`${success(\"\u2713\")} ${text}`);\n }\n\n fail(text: string): void {\n this.stop(`${error(\"\u2717\")} ${text}`);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Thinking block rendering (like Claude Code's thinking animation)\n// ---------------------------------------------------------------------------\n\nexport class ThinkingDisplay {\n private spinner: Spinner;\n private lines: string[] = [];\n private expanded = false;\n\n constructor() {\n this.spinner = new Spinner();\n }\n\n start(): void {\n this.spinner.start(\"Thinking...\");\n }\n\n update(delta: string): void {\n this.spinner.update(\"Thinking...\");\n }\n\n stop(): void {\n this.spinner.stop();\n }\n}\n\n// ---------------------------------------------------------------------------\n// Confirm prompt\n// ---------------------------------------------------------------------------\n\nexport async function confirmPrompt(question: string, autoYes: boolean = false): Promise<boolean> {\n if (autoYes) {\n return true;\n }\n\n if (!stderrIsTTY) {\n // Non-interactive: assume yes for piped input\n writeError(`${warning(\"\u26A0\")} ${question} ${dim(\"(assuming yes for non-interactive)\")}`);\n return true;\n }\n\n writeError(`${question} ${dim(\"[y/N]\")} `);\n\n return new Promise((resolve) => {\n process.stdin.once(\"data\", (data: Buffer) => {\n const input = data.toString().trim().toLowerCase();\n resolve(input === \"y\" || input === \"yes\");\n });\n });\n}\n\n// ---------------------------------------------------------------------------\n// Box / separator\n// ---------------------------------------------------------------------------\n\nexport function separator(title?: string): string {\n const width = Math.min(process.stdout.columns || 80, 80);\n if (!title) {\n return dim(\"\u2500\".repeat(width));\n }\n const titleStr = ` ${title} `;\n const half = Math.floor((width - titleStr.length) / 2);\n return dim(\"\u2500\".repeat(Math.max(0, half))) + bold(titleStr) + dim(\"\u2500\".repeat(Math.max(0, width - half - titleStr.length)));\n}\n", "/**\n * coder run <prompt> \u2014 Run the agent in full agent mode.\n */\n\nimport type { GlobalOptions } from \"./common\";\nimport { runAgentSession } from \"../agent/session\";\n\nexport async function runCommand(\n prompt: string,\n options: GlobalOptions,\n): Promise<void> {\n await runAgentSession(prompt, {\n ...options,\n agentMode: \"agent\",\n workspaceDir: options.workspace ?? process.cwd(),\n interactive: false,\n });\n}\n", "/**\n * coder ask <prompt> \u2014 Run in ask (read-only) mode.\n */\n\nimport type { GlobalOptions } from \"./common\";\nimport { runAgentSession } from \"../agent/session\";\n\nexport async function askCommand(\n prompt: string,\n options: GlobalOptions,\n): Promise<void> {\n await runAgentSession(prompt, {\n ...options,\n agentMode: \"ask\",\n workspaceDir: options.workspace ?? process.cwd(),\n interactive: false,\n });\n}\n", "/**\n * coder repl \u2014 Start interactive REPL session.\n */\n\nimport { createInterface } from \"node:readline\";\nimport type { GlobalOptions } from \"./common\";\nimport { runAgentSession } from \"../agent/session\";\nimport type { AgentChatMessage } from \"../agent/types\";\nimport { bold, dim, info, error, warning, writeLine, writeError } from \"../ui\";\nimport { loadConfig } from \"../config\";\nimport { killAllShells } from \"../handlers/shell-manager\";\n\nexport async function replCommand(options: GlobalOptions): Promise<void> {\n const config = loadConfig();\n const workspaceDir = options.workspace ?? process.cwd();\n\n writeLine(\"\");\n writeLine(bold(\"Coder CLI \u2014 Interactive REPL\"));\n writeLine(dim(\"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\"));\n writeLine(dim(` Model: ${config.lastModel || \"not set\"}`));\n writeLine(dim(` Provider: ${config.activeProvider}`));\n writeLine(dim(` Workspace: ${workspaceDir}`));\n writeLine(dim(` Type '/help' for commands, '/exit' or Ctrl+C to quit`));\n writeLine(dim(\"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\"));\n writeLine(\"\");\n\n // Persistent conversation context across REPL turns\n let conversationMessages: AgentChatMessage[] | undefined;\n let thinkingEnabled = true; // default to enabled for providers that support it\n let abortController = new AbortController();\n let agentRunning = false; // guards against re-entrance\n\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n prompt: `${bold(\"coder\")}> `,\n terminal: true,\n });\n\n rl.prompt();\n\n rl.on(\"line\", async (line: string) => {\n const trimmed = line.trim();\n\n if (!trimmed) {\n rl.prompt();\n return;\n }\n\n // Re-entrance guard: if the agent is already running (e.g. user pressed\n // Enter twice), ignore the input rather than pausing stdin \u2014 pausing\n // stdin prevents readline from detecting Ctrl+C in raw mode.\n if (agentRunning) {\n rl.prompt();\n return;\n }\n\n if (trimmed === \"/exit\" || trimmed === \"/quit\") {\n rl.close();\n return;\n }\n\n if (trimmed === \"/clear\") {\n console.clear();\n rl.prompt();\n return;\n }\n\n if (trimmed === \"/new\") {\n conversationMessages = undefined;\n abortController = new AbortController();\n writeLine(info(\"Started a new session. Context has been cleared.\"));\n rl.prompt();\n return;\n }\n\n if (trimmed === \"/help\") {\n writeLine(bold(\"\\nREPL Commands:\"));\n writeLine(\" <prompt> Ask the agent anything\");\n writeLine(\" /exit, /quit Exit REPL\");\n writeLine(\" /clear Clear screen\");\n writeLine(\" /new Clear context, start a new session\");\n writeLine(\" /help Show this help\");\n writeLine(\" /model <id> Switch model\");\n writeLine(` /thinking <on|off> Toggle deep thinking (currently: ${thinkingEnabled ? \"on\" : \"off\"})`);\n writeLine(\"\");\n rl.prompt();\n return;\n }\n\n if (trimmed.startsWith(\"/model \")) {\n const modelId = trimmed.slice(7).trim();\n if (modelId) {\n config.lastModel = modelId;\n const { saveConfig } = await import(\"../config\");\n saveConfig(config);\n writeLine(info(`Model set to: ${modelId}`));\n }\n rl.prompt();\n return;\n }\n\n if (trimmed.startsWith(\"/thinking \")) {\n const value = trimmed.slice(10).trim().toLowerCase();\n if (value === \"on\" || value === \"true\") {\n thinkingEnabled = true;\n writeLine(info(\"Deep thinking: on\"));\n } else if (value === \"off\" || value === \"false\") {\n thinkingEnabled = false;\n writeLine(info(\"Deep thinking: off\"));\n } else {\n writeLine(error(`Usage: /thinking <on|off> (currently: ${thinkingEnabled ? \"on\" : \"off\"})`));\n }\n rl.prompt();\n return;\n }\n\n // Run the agent with the given prompt\n agentRunning = true;\n\n try {\n conversationMessages = await runAgentSession(trimmed, {\n agentMode: \"agent\",\n workspaceDir,\n interactive: true,\n thinking: thinkingEnabled,\n existingMessages: conversationMessages,\n signal: abortController.signal,\n });\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n writeError(error(`Error: ${message}`));\n }\n agentRunning = false;\n // Reset the abort controller for the next turn \u2014 once aborted,\n // a signal stays aborted permanently and would cancel the next\n // request immediately.\n abortController = new AbortController();\n\n writeLine(\"\");\n rl.prompt();\n });\n\n rl.on(\"close\", () => {\n killAllShells();\n writeLine(dim(\"\\nGoodbye! \uD83D\uDC4B\"));\n process.exit(0);\n });\n\n rl.on(\"SIGINT\", () => {\n if (agentRunning) {\n // Cancel current request\n abortController.abort();\n writeLine(\"\");\n writeLine(warning(\"\u26A0 Cancelled\"));\n // Don't prompt here \u2014 the line handler will show the prompt\n // when the agent finishes unwinding from the abort.\n } else {\n // Not running \u2014 Ctrl+C exits\n rl.close();\n }\n });\n}\n", "/**\n * coder config \u2014 View or edit configuration.\n */\n\nimport { bold, dim, error, info, warning, writeLine } from \"../ui\";\nimport {\n loadConfig,\n saveConfig,\n getConfigDirPath,\n getConfigFilePathExplicit,\n resolveTavilyApiKey,\n type ProviderId,\n type ProviderSettings,\n} from \"../config\";\n\nconst PROVIDER_IDS: ProviderId[] = [\"deepseek\", \"glm\", \"agnes\", \"nvidia\", \"minimax\", \"custom\"];\n\nexport async function configCommand(key?: string, value?: string): Promise<void> {\n const config = loadConfig();\n\n // If no args, show full config\n if (!key) {\n showConfig(config);\n return;\n }\n\n // If both key and value, set a value\n if (key && value !== undefined) {\n await setConfigValue(config, key, value);\n return;\n }\n\n // If only key, show that specific value\n showConfigValue(config, key);\n}\n\nfunction showConfig(config: ReturnType<typeof loadConfig>): void {\n writeLine(bold(\"\\nCoder CLI Configuration\"));\n writeLine(dim(\"\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\"));\n writeLine(`Config directory: ${getConfigDirPath()}`);\n writeLine(`Config file: ${getConfigFilePathExplicit()}`);\n writeLine(\"\");\n writeLine(bold(\"Active Settings:\"));\n writeLine(` Active provider: ${config.activeProvider}`);\n writeLine(` Last model: ${config.lastModel}`);\n const tavilyKey = resolveTavilyApiKey(config);\n writeLine(` Web search: ${tavilyKey ? \"configured\" : \"not configured (set via coder config tavilyApiKey <key> or TAVILY_API_KEY env var)\"}`);\n writeLine(\"\");\n\n for (const providerId of PROVIDER_IDS) {\n const p = config.providers[providerId];\n writeLine(bold(`Provider: ${providerId}`));\n writeLine(` API Key Source: ${p.apiKeySource}`);\n writeLine(` API Key Env Var: ${p.apiKeyEnvVar}`);\n writeLine(` API Key (stored): ${p.apiKey ? \"***\" : \"(not set)\"}`);\n writeLine(` Custom Base URL: ${p.customBaseUrl || \"(default)\"}`);\n if (providerId === \"custom\") {\n writeLine(` Deep Thinking: ${p.supportsThinking ? \"supported\" : \"not declared\"}`);\n if (p.thinkingEnabledParams) {\n writeLine(` Thinking (on): ${JSON.stringify(p.thinkingEnabledParams)}`);\n }\n if (p.thinkingDisabledParams) {\n writeLine(` Thinking (off): ${JSON.stringify(p.thinkingDisabledParams)}`);\n }\n }\n writeLine(\"\");\n }\n\n writeLine(dim(\"To change a value: coder config <key> <value>\"));\n writeLine(dim(\"\"));\n writeLine(dim(\"Quick start \u2014 custom provider:\"));\n writeLine(dim(' coder config activeProvider custom'));\n writeLine(dim(' coder config providers.custom.customBaseUrl \"https://api.openai.com/v1\"'));\n writeLine(dim(' coder config providers.custom.supportsThinking true'));\n writeLine(dim(' coder config lastModel \"gpt-4o\"'));\n writeLine(dim(\"\"));\n writeLine(dim(\" # Way 1: env var (recommended)\"));\n writeLine(dim(' coder config providers.custom.apiKeySource env'));\n writeLine(dim(' coder config providers.custom.apiKeyEnvVar \"OPENAI_API_KEY\"'));\n writeLine(dim(' export OPENAI_API_KEY=sk-xxx'));\n writeLine(dim(\"\"));\n writeLine(dim(\" # Way 2: stored in config\"));\n writeLine(dim(' coder config providers.custom.apiKeySource manual'));\n writeLine(dim(' coder config providers.custom.apiKey \"sk-xxx\"'));\n writeLine(dim(\"\"));\n writeLine(dim(\"View a value:\"));\n writeLine(dim(\" coder config activeProvider\"));\n writeLine(dim(\" coder config providers.deepseek.customBaseUrl\"));\n writeLine(dim(\" coder config providers.custom.thinkingEnabledParams\"));\n writeLine(\"\");\n}\n\nfunction showConfigValue(config: ReturnType<typeof loadConfig>, key: string): void {\n const value = getNestedValue(config, key);\n if (value === undefined) {\n writeLine(warning(`Config key not found: ${key}`));\n return;\n }\n writeLine(String(value));\n}\n\nasync function setConfigValue(\n config: ReturnType<typeof loadConfig>,\n key: string,\n value: string,\n): Promise<void> {\n // Validate activeProvider\n if (key === \"activeProvider\" && !PROVIDER_IDS.includes(value as any)) {\n writeLine(error(`Invalid provider \"${value}\". Valid providers: ${PROVIDER_IDS.join(\", \")}`));\n return;\n }\n // Validate apiKeySource\n if (key.endsWith(\".apiKeySource\") || key === \"apiKeySource\") {\n if (value !== \"env\" && value !== \"manual\") {\n writeLine(error(`Invalid apiKeySource \"${value}\". Must be \"env\" or \"manual\".`));\n return;\n }\n }\n setNestedValue(config, key, parseValue(value));\n saveConfig(config);\n writeLine(info(`Config updated: ${key} = ${value}`));\n}\n\nfunction getNestedValue(obj: Record<string, unknown>, path: string): unknown {\n const parts = path.split(\".\");\n let current: unknown = obj;\n\n for (const part of parts) {\n if (current === null || current === undefined || typeof current !== \"object\") {\n return undefined;\n }\n current = (current as Record<string, unknown>)[part];\n }\n\n return current;\n}\n\nfunction setNestedValue(obj: Record<string, unknown>, path: string, value: unknown): void {\n const parts = path.split(\".\");\n let current = obj;\n\n for (let i = 0; i < parts.length - 1; i++) {\n if (!(parts[i] in current)) {\n current[parts[i]] = {};\n }\n current = current[parts[i]] as Record<string, unknown>;\n }\n\n current[parts[parts.length - 1]] = value;\n}\n\nfunction parseValue(value: string): unknown {\n // Try to parse as boolean\n if (value === \"true\") return true;\n if (value === \"false\") return false;\n // Try to parse as number\n const num = Number(value);\n if (!isNaN(num) && value.trim() !== \"\") return num;\n // Keep as string\n return value;\n}\n", "/**\n * Shared types and helpers for CLI commands.\n */\n\nimport type { AgentMode } from \"../agent/types\";\n\nexport type GlobalOptions = {\n workspace?: string;\n stream?: boolean;\n thinking?: boolean;\n};\n\nexport type CommandContext = GlobalOptions & {\n agentMode: AgentMode;\n};\n\nlet _globalOptions: GlobalOptions = {};\n\nexport function setGlobalOptions(opts: GlobalOptions): void {\n _globalOptions = opts;\n}\n\nexport function getGlobalOptions(): GlobalOptions {\n return _globalOptions;\n}\n", "/**\n * Coder CLI \u2014 Entrypoint\n *\n * Usage:\n * coder Start interactive REPL\n * coder ask <prompt> Run in ask (read-only) mode\n * coder run <prompt> Run in agent (full access) mode\n * coder config Show/edit configuration\n * coder --version Show version\n * coder --help Show help\n */\n\nimport { runCommand } from \"./commands/run\";\nimport { askCommand } from \"./commands/ask\";\nimport { replCommand } from \"./commands/repl\";\nimport { configCommand } from \"./commands/config\";\nimport { setGlobalOptions } from \"./commands/common\";\nimport { error, info, writeError, writeLine } from \"./ui\";\n\nconst VERSION = process.env.CLI_VERSION ?? \"0.0.0\";\n\nasync function main() {\n // Quick help/version check before commander\n const rawArgs = process.argv.slice(2);\n\n if (rawArgs.includes(\"--help\") || rawArgs.includes(\"-h\")) {\n printHelp();\n return;\n }\n\n if (rawArgs.includes(\"--version\") || rawArgs.includes(\"-v\")) {\n console.log(VERSION);\n return;\n }\n\n // Extract global options from raw args (must be done before subcommand dispatch)\n const globalOpts = extractGlobalOptions(rawArgs);\n setGlobalOptions(globalOpts);\n\n // If no args, start REPL\n if (rawArgs.length === 0) {\n await replCommand({});\n return;\n }\n\n // Find known subcommands\n const firstNonFlag = rawArgs.find((a) => !a.startsWith(\"-\"));\n const knownSubcommands: Record<string, (args: string[], opts: Record<string, unknown>) => Promise<void>> = {\n ask: async (args, opts) => { await askCommand(args.join(\" \"), opts); },\n run: async (args, opts) => { await runCommand(args.join(\" \"), opts); },\n config: async (args) => { await configCommand(args[0], args[1]); },\n };\n\n if (firstNonFlag && knownSubcommands[firstNonFlag]) {\n const cmdArgs = rawArgs.slice(rawArgs.indexOf(firstNonFlag) + 1).filter((a) => !a.startsWith(\"-\"));\n await knownSubcommands[firstNonFlag](cmdArgs, globalOpts);\n return;\n }\n\n // Unknown subcommand \u2014 show error\n writeLine(error(`Unknown subcommand \"${firstNonFlag}\".`));\n writeLine(\"\");\n writeLine(info(\"Usage: coder <command> [options] [prompt...]\"));\n writeLine(info(\"Run 'coder --help' for available commands.\"));\n process.exit(1);\n}\n\nfunction extractGlobalOptions(args: string[]): Record<string, unknown> {\n const opts: Record<string, unknown> = {};\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (arg === \"-w\" || arg === \"--workspace\") {\n opts.workspace = args[++i] ?? \"\";\n } else if (arg === \"--no-stream\") {\n opts.stream = false;\n } else if (arg === \"--stream\") {\n opts.stream = true;\n } else if (arg === \"--thinking\") {\n opts.thinking = true;\n } else if (arg === \"--no-thinking\") {\n opts.thinking = false;\n }\n }\n return opts;\n}\n\nfunction printHelp(): void {\n console.log(`\nUsage: coder <command> [options] [prompt...]\n\nCoder CLI \u2014 AI-powered coding assistant in the terminal\n\nOptions:\n -v, --version output the version number\n -w, --workspace <path> Workspace directory\n --no-stream Disable streaming output\n --thinking Enable deep thinking (for supported models)\n --no-thinking Disable deep thinking\n -h, --help display help for command\n\nCommands:\n ask [prompt...] Ask a question (read-only mode)\n run [prompt...] Run in full agent mode (can modify files, run commands)\n config [key] [value] View or edit configuration\n`);\n}\n\nmain().catch((err: unknown) => {\n const message = err instanceof Error ? err.message : String(err);\n writeError(error(`Fatal: ${message}`));\n process.exit(1);\n});\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,SAAS,eAAuB;AAC9B,QAAM,WAAO,wB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AClB,QAAI,QAAQ,QAAQ,QAAQ,eAAe;AACzC,WAAK,YAAY,KAAK,EAAE,CAAC,KAAK;AAAA,IAChC,WAAW,QAAQ,eAAe;AAChC,WAAK,SAAS;AAAA,IAChB,WAAW,QAAQ,YAAY;AAC7B,WAAK,SAAS;AAAA,IAChB,WAAW,QAAQ,cAAc;AAC/B,WAAK,WAAW;AAAA,IAClB,WAAW,QAAQ,iBAAiB;AAClC,WAAK,WAAW;AAAA,IAClB;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,YAAkB;AACzB,UAAQ,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAiBb;AACD;AAEA,KAAK,EAAE,MAAM,CAAC,QAAiB;AAC7B,QAAM,UAAU,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC/D,aAAW,MAAM,UAAU,OAAO,EAAE,CAAC;AACrC,UAAQ,KAAK,CAAC;AAChB,CAAC;",
|
|
6
|
-
"names": ["import_node_path", "import_node_fs", "error", "import_node_fs", "import_node_path", "error", "import_node_fs", "import_node_path", "error", "import_node_fs", "import_node_path", "error", "import_node_fs", "import_node_path", "import_node_crypto", "error", "import_node_fs", "import_node_path", "import_node_crypto", "error", "import_node_fs", "import_node_path", "error", "import_node_fs", "import_node_path", "error", "import_node_path", "error", "error", "shells", "error", "error", "import_node_fs", "import_node_path", "import_node_fs", "import_node_path", "error", "resolve", "error", "error", "resolve", "error", "import_node_os", "import_node_child_process", "import_node_fs", "import_node_path", "import_node_readline", "saveConfig", "PROVIDER_IDS"]
|
|
7
|
-
}
|