@di-code/coding-agent 0.1.6 → 0.1.8
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/README.md +112 -68
- package/compositions/base.yml +54 -0
- package/compositions/interactive.yml +14 -0
- package/compositions/json.yml +6 -0
- package/compositions/print.yml +5 -0
- package/compositions/rpc.yml +12 -0
- package/compositions/webui.yml +9 -0
- package/dist/cli.d.ts +22 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +97 -3
- package/dist/cli.js.map +1 -1
- package/dist/composition-loader-entry.d.ts +11 -0
- package/dist/composition-loader-entry.d.ts.map +1 -0
- package/dist/composition-loader-entry.js +12 -0
- package/dist/composition-loader-entry.js.map +1 -0
- package/dist/compositions.d.ts +32 -0
- package/dist/compositions.d.ts.map +1 -0
- package/dist/compositions.js +173 -0
- package/dist/compositions.js.map +1 -0
- package/dist/core/session/session-manager.d.ts +9 -2
- package/dist/core/session/session-manager.d.ts.map +1 -1
- package/dist/core/session/session-manager.js +28 -0
- package/dist/core/session/session-manager.js.map +1 -1
- package/dist/core/session/session-storage.d.ts.map +1 -1
- package/dist/core/session/session-storage.js +20 -3
- package/dist/core/session/session-storage.js.map +1 -1
- package/dist/core/session/types.d.ts +11 -2
- package/dist/core/session/types.d.ts.map +1 -1
- package/dist/core/session/types.js.map +1 -1
- package/dist/core/session-tools.d.ts +5 -0
- package/dist/core/session-tools.d.ts.map +1 -0
- package/dist/core/session-tools.js +17 -0
- package/dist/core/session-tools.js.map +1 -0
- package/dist/core/session.d.ts +21 -7
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +77 -41
- package/dist/core/session.js.map +1 -1
- package/dist/core/tools/bash.d.ts +1 -38
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +1 -207
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +1 -24
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +1 -135
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts +1 -26
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +1 -140
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js +1 -23
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/file-search.d.ts +1 -13
- package/dist/core/tools/file-search.d.ts.map +1 -1
- package/dist/core/tools/file-search.js +1 -98
- package/dist/core/tools/file-search.js.map +1 -1
- package/dist/core/tools/glob.d.ts +1 -10
- package/dist/core/tools/glob.d.ts.map +1 -1
- package/dist/core/tools/glob.js +1 -43
- package/dist/core/tools/glob.js.map +1 -1
- package/dist/core/tools/grep.d.ts +1 -12
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +1 -66
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/load-skill.d.ts +1 -9
- package/dist/core/tools/load-skill.d.ts.map +1 -1
- package/dist/core/tools/load-skill.js +1 -21
- package/dist/core/tools/load-skill.js.map +1 -1
- package/dist/core/tools/path-boundary.d.ts +1 -4
- package/dist/core/tools/path-boundary.d.ts.map +1 -1
- package/dist/core/tools/path-boundary.js +1 -65
- package/dist/core/tools/path-boundary.js.map +1 -1
- package/dist/core/tools/read.d.ts +1 -16
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +1 -131
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/write.d.ts +1 -16
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +1 -44
- package/dist/core/tools/write.js.map +1 -1
- package/dist/entry.js +30 -28
- package/dist/entry.js.map +1 -1
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +2 -0
- package/dist/i18n.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/interactive/builtin.d.ts +17 -0
- package/dist/interactive/builtin.d.ts.map +1 -0
- package/dist/interactive/builtin.js +47 -0
- package/dist/interactive/builtin.js.map +1 -0
- package/dist/interactive/controller.d.ts +85 -0
- package/dist/interactive/controller.d.ts.map +1 -0
- package/dist/interactive/controller.js +211 -0
- package/dist/interactive/controller.js.map +1 -0
- package/dist/interactive/index.d.ts +3 -0
- package/dist/interactive/index.d.ts.map +1 -0
- package/dist/interactive/index.js +3 -0
- package/dist/interactive/index.js.map +1 -0
- package/dist/interactive-host-entry.d.ts +7 -0
- package/dist/interactive-host-entry.d.ts.map +1 -0
- package/dist/interactive-host-entry.js +123 -0
- package/dist/interactive-host-entry.js.map +1 -0
- package/dist/interactive-profile.d.ts +18 -0
- package/dist/interactive-profile.d.ts.map +1 -0
- package/dist/interactive-profile.js +290 -0
- package/dist/interactive-profile.js.map +1 -0
- package/dist/interactive-resources-entry.d.ts +7 -0
- package/dist/interactive-resources-entry.d.ts.map +1 -0
- package/dist/interactive-resources-entry.js +42 -0
- package/dist/interactive-resources-entry.js.map +1 -0
- package/dist/legacy-main.d.ts +39 -0
- package/dist/legacy-main.d.ts.map +1 -0
- package/dist/legacy-main.js +611 -0
- package/dist/legacy-main.js.map +1 -0
- package/dist/main.d.ts +15 -34
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +130 -513
- package/dist/main.js.map +1 -1
- package/dist/mcp/entries.d.ts +42 -0
- package/dist/mcp/entries.d.ts.map +1 -0
- package/dist/mcp/entries.js +98 -0
- package/dist/mcp/entries.js.map +1 -0
- package/dist/mcp-client-entry.d.ts +5 -0
- package/dist/mcp-client-entry.d.ts.map +1 -0
- package/dist/mcp-client-entry.js +6 -0
- package/dist/mcp-client-entry.js.map +1 -0
- package/dist/mcp-config-entry.d.ts +5 -0
- package/dist/mcp-config-entry.d.ts.map +1 -0
- package/dist/mcp-config-entry.js +6 -0
- package/dist/mcp-config-entry.js.map +1 -0
- package/dist/mcp-tools-entry.d.ts +5 -0
- package/dist/mcp-tools-entry.d.ts.map +1 -0
- package/dist/mcp-tools-entry.js +6 -0
- package/dist/mcp-tools-entry.js.map +1 -0
- package/dist/mcp-transport-entry.d.ts +5 -0
- package/dist/mcp-transport-entry.d.ts.map +1 -0
- package/dist/mcp-transport-entry.js +6 -0
- package/dist/mcp-transport-entry.js.map +1 -0
- package/dist/modes/interactive-entry.d.ts +18 -0
- package/dist/modes/interactive-entry.d.ts.map +1 -0
- package/dist/modes/interactive-entry.js +21 -0
- package/dist/modes/interactive-entry.js.map +1 -0
- package/dist/modes/interactive-state.js +1 -1
- package/dist/modes/interactive-state.js.map +1 -1
- package/dist/modes/interactive.d.ts +16 -6
- package/dist/modes/interactive.d.ts.map +1 -1
- package/dist/modes/interactive.js +99 -33
- package/dist/modes/interactive.js.map +1 -1
- package/dist/modes/json-entry.d.ts +13 -0
- package/dist/modes/json-entry.d.ts.map +1 -0
- package/dist/modes/json-entry.js +14 -0
- package/dist/modes/json-entry.js.map +1 -0
- package/dist/modes/json.d.ts +4 -1
- package/dist/modes/json.d.ts.map +1 -1
- package/dist/modes/json.js +3 -3
- package/dist/modes/json.js.map +1 -1
- package/dist/modes/print-entry.d.ts +10 -0
- package/dist/modes/print-entry.d.ts.map +1 -0
- package/dist/modes/print-entry.js +11 -0
- package/dist/modes/print-entry.js.map +1 -0
- package/dist/modes/tree-selector.d.ts.map +1 -1
- package/dist/modes/tree-selector.js +4 -0
- package/dist/modes/tree-selector.js.map +1 -1
- package/dist/plugin-dump-composition.d.ts +6 -0
- package/dist/plugin-dump-composition.d.ts.map +1 -0
- package/dist/plugin-dump-composition.js +7 -0
- package/dist/plugin-dump-composition.js.map +1 -0
- package/dist/plugin-inventory.d.ts +7 -0
- package/dist/plugin-inventory.d.ts.map +1 -0
- package/dist/plugin-inventory.js +8 -0
- package/dist/plugin-inventory.js.map +1 -0
- package/dist/plugin-manager.d.ts +6 -0
- package/dist/plugin-manager.d.ts.map +1 -0
- package/dist/plugin-manager.js +7 -0
- package/dist/plugin-manager.js.map +1 -0
- package/dist/plugin-trace.d.ts +6 -0
- package/dist/plugin-trace.d.ts.map +1 -0
- package/dist/plugin-trace.js +7 -0
- package/dist/plugin-trace.js.map +1 -0
- package/dist/plugins/dynamic-broker.d.ts +76 -0
- package/dist/plugins/dynamic-broker.d.ts.map +1 -0
- package/dist/plugins/dynamic-broker.js +852 -0
- package/dist/plugins/dynamic-broker.js.map +1 -0
- package/dist/plugins/profile.d.ts +15 -0
- package/dist/plugins/profile.d.ts.map +1 -0
- package/dist/plugins/profile.js +34 -0
- package/dist/plugins/profile.js.map +1 -0
- package/dist/plugins/runtime-host.d.ts +37 -0
- package/dist/plugins/runtime-host.d.ts.map +1 -0
- package/dist/plugins/runtime-host.js +95 -0
- package/dist/plugins/runtime-host.js.map +1 -0
- package/dist/plugins/trust.d.ts +8 -0
- package/dist/plugins/trust.d.ts.map +1 -0
- package/dist/plugins/trust.js +59 -0
- package/dist/plugins/trust.js.map +1 -0
- package/dist/project-trust-entry.d.ts +15 -0
- package/dist/project-trust-entry.d.ts.map +1 -0
- package/dist/project-trust-entry.js +15 -0
- package/dist/project-trust-entry.js.map +1 -0
- package/dist/rpc/client.d.ts +78 -6
- package/dist/rpc/client.d.ts.map +1 -1
- package/dist/rpc/client.js +172 -4
- package/dist/rpc/client.js.map +1 -1
- package/dist/rpc/dispatcher.d.ts +121 -0
- package/dist/rpc/dispatcher.d.ts.map +1 -0
- package/dist/rpc/dispatcher.js +994 -0
- package/dist/rpc/dispatcher.js.map +1 -0
- package/dist/rpc/index.d.ts +2 -0
- package/dist/rpc/index.d.ts.map +1 -1
- package/dist/rpc/index.js +2 -0
- package/dist/rpc/index.js.map +1 -1
- package/dist/rpc/lifecycle.d.ts +6 -0
- package/dist/rpc/lifecycle.d.ts.map +1 -0
- package/dist/rpc/lifecycle.js +24 -0
- package/dist/rpc/lifecycle.js.map +1 -0
- package/dist/rpc/protocol.d.ts +112 -31
- package/dist/rpc/protocol.d.ts.map +1 -1
- package/dist/rpc/protocol.js +569 -117
- package/dist/rpc/protocol.js.map +1 -1
- package/dist/rpc/server-service.d.ts +7 -0
- package/dist/rpc/server-service.d.ts.map +1 -0
- package/dist/rpc/server-service.js +3 -0
- package/dist/rpc/server-service.js.map +1 -0
- package/dist/rpc/server.d.ts +16 -19
- package/dist/rpc/server.d.ts.map +1 -1
- package/dist/rpc/server.js +59 -115
- package/dist/rpc/server.js.map +1 -1
- package/dist/rpc-client-sdk-entry.d.ts +12 -0
- package/dist/rpc-client-sdk-entry.d.ts.map +1 -0
- package/dist/rpc-client-sdk-entry.js +11 -0
- package/dist/rpc-client-sdk-entry.js.map +1 -0
- package/dist/rpc-entry.js +50 -18
- package/dist/rpc-entry.js.map +1 -1
- package/dist/rpc-server-entry.d.ts +8 -0
- package/dist/rpc-server-entry.d.ts.map +1 -0
- package/dist/rpc-server-entry.js +67 -0
- package/dist/rpc-server-entry.js.map +1 -0
- package/dist/runtime/attachment-store.d.ts +13 -0
- package/dist/runtime/attachment-store.d.ts.map +1 -0
- package/dist/runtime/attachment-store.js +93 -0
- package/dist/runtime/attachment-store.js.map +1 -0
- package/dist/runtime/bootstrap.d.ts +14 -0
- package/dist/runtime/bootstrap.d.ts.map +1 -0
- package/dist/runtime/bootstrap.js +29 -0
- package/dist/runtime/bootstrap.js.map +1 -0
- package/dist/runtime/interactive-host-service.d.ts +22 -0
- package/dist/runtime/interactive-host-service.d.ts.map +1 -0
- package/dist/runtime/interactive-host-service.js +2 -0
- package/dist/runtime/interactive-host-service.js.map +1 -0
- package/dist/runtime/interactive-resource-service.d.ts +11 -0
- package/dist/runtime/interactive-resource-service.d.ts.map +1 -0
- package/dist/runtime/interactive-resource-service.js +3 -0
- package/dist/runtime/interactive-resource-service.js.map +1 -0
- package/dist/runtime/plugin-inventory-entry.d.ts +5 -0
- package/dist/runtime/plugin-inventory-entry.d.ts.map +1 -0
- package/dist/runtime/plugin-inventory-entry.js +18 -0
- package/dist/runtime/plugin-inventory-entry.js.map +1 -0
- package/dist/runtime/plugin-inventory-service.d.ts +8 -0
- package/dist/runtime/plugin-inventory-service.d.ts.map +1 -0
- package/dist/runtime/plugin-inventory-service.js +3 -0
- package/dist/runtime/plugin-inventory-service.js.map +1 -0
- package/dist/runtime/plugin-manager-entry.d.ts +20 -0
- package/dist/runtime/plugin-manager-entry.d.ts.map +1 -0
- package/dist/runtime/plugin-manager-entry.js +96 -0
- package/dist/runtime/plugin-manager-entry.js.map +1 -0
- package/dist/runtime/plugin-observability-entry.d.ts +12 -0
- package/dist/runtime/plugin-observability-entry.d.ts.map +1 -0
- package/dist/runtime/plugin-observability-entry.js +73 -0
- package/dist/runtime/plugin-observability-entry.js.map +1 -0
- package/dist/runtime/product-host.d.ts +91 -0
- package/dist/runtime/product-host.d.ts.map +1 -0
- package/dist/runtime/product-host.js +529 -0
- package/dist/runtime/product-host.js.map +1 -0
- package/dist/runtime/session-factory.d.ts +17 -0
- package/dist/runtime/session-factory.d.ts.map +1 -0
- package/dist/runtime/session-factory.js +75 -0
- package/dist/runtime/session-factory.js.map +1 -0
- package/dist/runtime/session-host.d.ts +152 -0
- package/dist/runtime/session-host.d.ts.map +1 -0
- package/dist/runtime/session-host.js +895 -0
- package/dist/runtime/session-host.js.map +1 -0
- package/dist/runtime-core-entry.d.ts +11 -0
- package/dist/runtime-core-entry.d.ts.map +1 -0
- package/dist/runtime-core-entry.js +9 -0
- package/dist/runtime-core-entry.js.map +1 -0
- package/dist/session-factory-entry.d.ts +7 -0
- package/dist/session-factory-entry.d.ts.map +1 -0
- package/dist/session-factory-entry.js +9 -0
- package/dist/session-factory-entry.js.map +1 -0
- package/dist/session-store-jsonl-entry.d.ts +7 -0
- package/dist/session-store-jsonl-entry.d.ts.map +1 -0
- package/dist/session-store-jsonl-entry.js +33 -0
- package/dist/session-store-jsonl-entry.js.map +1 -0
- package/dist/startup.d.ts +21 -1
- package/dist/startup.d.ts.map +1 -1
- package/dist/startup.js +179 -10
- package/dist/startup.js.map +1 -1
- package/dist/subagents/index.d.ts +2 -0
- package/dist/subagents/index.d.ts.map +1 -0
- package/dist/subagents/index.js +2 -0
- package/dist/subagents/index.js.map +1 -0
- package/dist/subagents/service.d.ts +50 -0
- package/dist/subagents/service.d.ts.map +1 -0
- package/dist/subagents/service.js +521 -0
- package/dist/subagents/service.js.map +1 -0
- package/dist/ui-host.d.ts +125 -0
- package/dist/ui-host.d.ts.map +1 -0
- package/dist/ui-host.js +275 -0
- package/dist/ui-host.js.map +1 -0
- package/dist/web/assets/index-BwfuGMvv.css +1 -0
- package/dist/web/assets/index-DPUaJqFJ.js +41 -0
- package/dist/web/assets/index-DPUaJqFJ.js.map +1 -0
- package/dist/web/index.html +14 -0
- package/dist/web-command.d.ts +11 -0
- package/dist/web-command.d.ts.map +1 -0
- package/dist/web-command.js +114 -0
- package/dist/web-command.js.map +1 -0
- package/dist/web-frontend.d.ts +73 -0
- package/dist/web-frontend.d.ts.map +1 -0
- package/dist/web-frontend.js +249 -0
- package/dist/web-frontend.js.map +1 -0
- package/dist/web.d.ts +254 -0
- package/dist/web.d.ts.map +1 -0
- package/dist/web.js +740 -0
- package/dist/web.js.map +1 -0
- package/dist/webui-entry.d.ts +3 -0
- package/dist/webui-entry.d.ts.map +1 -0
- package/dist/webui-entry.js +73 -0
- package/dist/webui-entry.js.map +1 -0
- package/dist/webui.d.ts +91 -0
- package/dist/webui.d.ts.map +1 -0
- package/dist/webui.js +882 -0
- package/dist/webui.js.map +1 -0
- package/package.json +89 -8
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,C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W,EAAE,CAAC,CAAC;YACxE,IAAI,CAAC;gBACJ,OAAO,MAAM,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;YAClE,CAAC;oBAAS,CAAC;gBACV,MAAM,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;gBACzE,MAAM,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YAC3B,CAAC;QACF,CAAC;KACD,CAAC;IAEF,OAAO,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;AACnC,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { access, readdir, stat } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { basename, dirname, extname, join, resolve } from \"node:path\";\nimport type { Model, Provider } from \"@di-code/ai\";\nimport type { McpServerConnectionStatus } from \"@di-code/mcp\";\nimport { ProcessTerminal, TUI, truncateToWidth } from \"@di-code/tui\";\nimport { type CliCommand, type CliDependencies, runCli } from \"./cli.ts\";\nimport { loadImageInputs } from \"./core/image-input.ts\";\nimport { loadResources } from \"./core/resources/loader.ts\";\nimport { SessionManager } from \"./core/session/session-manager.ts\";\nimport { AgentSession } from \"./core/session.ts\";\nimport { buildSystemPrompt } from \"./core/system-prompt.ts\";\nimport { workspaceStorageKey } from \"./core/user-data.ts\";\nimport { ProjectTrustManager } from \"./extensions/trust.ts\";\nimport { DEFAULT_LOCALE, type Locale, translate } from \"./i18n.ts\";\nimport { addMcpConfig, getMcpConfig, listMcpConfig, type McpConfigScope, removeMcpConfig } from \"./mcp/config.ts\";\nimport { loadProjectMcp } from \"./mcp/loader.ts\";\nimport { InteractiveMode } from \"./modes/interactive.ts\";\nimport { runJsonMode } from \"./modes/json.ts\";\nimport { type PrintIo, runPrintMode } from \"./modes/print.ts\";\nimport { loadPlugins, type PluginLoadStatus } from \"./plugins/loader.ts\";\nimport { PluginManager } from \"./plugins/manager.ts\";\nimport type { StartupConfiguration } from \"./startup.ts\";\n\nexport interface MainRuntime {\n\treadonly provider: Provider;\n\treadonly model: Model;\n}\n\nexport interface MainOptions extends PrintIo {\n\treadonly version: string;\n\treadonly createRuntime: (\n\t\tcommand: Extract<CliCommand, { kind: \"run\" }>,\n\t) => MainRuntime | undefined | Promise<MainRuntime | undefined>;\n\treadonly allowedRoot?: string;\n\treadonly agentDir?: string;\n\treadonly startupConfiguration?: StartupConfiguration;\n\t/** Language for built-in human-facing CLI and terminal text. */\n\treadonly locale?: Locale;\n\treadonly now?: () => number;\n\t/** Whether stdin and stdout are interactive terminals. */\n\treadonly isInteractiveTerminal?: boolean;\n\t/** Ask whether project-local Skills, plugins, and extensions may be loaded. */\n\treadonly promptProjectTrust?: (cwd: string) => Promise<boolean>;\n}\n\nconst MAX_SESSION_QUESTION_LENGTH = 72;\n\nfunction defaultSessionDirectory(agentDir: string, cwd: string): string {\n\treturn join(agentDir, \"sessions\", workspaceStorageKey(cwd));\n}\n\nconst STARTUP_STATUS_COLORS = {\n\terror: \"\\x1b[31m\",\n\tsuccess: \"\\x1b[32m\",\n\twarning: \"\\x1b[33m\",\n\treset: \"\\x1b[0m\",\n} as const;\n\nfunction formatMcpStatus(status: McpServerConnectionStatus): string {\n\tswitch (status.state) {\n\t\tcase \"connecting\":\n\t\t\treturn `${STARTUP_STATUS_COLORS.warning}MCP [loading]${STARTUP_STATUS_COLORS.reset} ${status.serverId}`;\n\t\tcase \"connected\":\n\t\t\treturn `${STARTUP_STATUS_COLORS.success}MCP [ok]${STARTUP_STATUS_COLORS.reset} ${status.serverId} (${status.tools} tools, ${status.resources} resources, ${status.prompts} prompts)`;\n\t\tcase \"failed\":\n\t\t\treturn `${STARTUP_STATUS_COLORS.error}MCP [error]${STARTUP_STATUS_COLORS.reset} ${status.serverId} (${status.stage}): ${status.message}`;\n\t}\n}\n\nfunction formatMcpDiagnostic(serverId: string | undefined, stage: string, message: string): string {\n\treturn `${STARTUP_STATUS_COLORS.error}MCP [error]${STARTUP_STATUS_COLORS.reset} ${serverId ?? \"configuration\"} (${stage}): ${message}\\n`;\n}\n\nfunction formatPluginStatus(status: PluginLoadStatus): string {\n\tswitch (status.state) {\n\t\tcase \"loading\":\n\t\t\treturn `${STARTUP_STATUS_COLORS.warning}Plugin [loading]${STARTUP_STATUS_COLORS.reset} ${status.pluginId}`;\n\t\tcase \"loaded\":\n\t\t\treturn `${STARTUP_STATUS_COLORS.success}Plugin [ok]${STARTUP_STATUS_COLORS.reset} ${status.pluginId} (${status.tools} tools, ${status.commands} commands)`;\n\t\tcase \"failed\":\n\t\t\treturn `${STARTUP_STATUS_COLORS.error}Plugin [error]${STARTUP_STATUS_COLORS.reset} ${status.pluginId ?? \"plugin\"} (${status.stage}): ${status.message}`;\n\t}\n}\n\nfunction formatPluginDiagnostic(pluginId: string | undefined, stage: string, message: string): string {\n\treturn `${STARTUP_STATUS_COLORS.error}Plugin [error]${STARTUP_STATUS_COLORS.reset} ${pluginId ?? \"plugin\"} (${stage}): ${message}\\n`;\n}\n\nfunction pluginStatusKey(status: PluginLoadStatus): string {\n\tif (status.state === \"failed\" && status.pluginId === undefined) return `plugin:${status.sourcePath}`;\n\treturn `plugin:${status.pluginId}`;\n}\n\n/** Renders startup states in place so terminal history retains only their final outcome. */\nexport class StartupStatusRenderer {\n\tprivate readonly lines: string[] = [];\n\tprivate readonly indexes = new Map<string, number>();\n\tprivate readonly write: (text: string) => void;\n\tprivate readonly replaceInPlace: boolean;\n\tprivate readonly width: number;\n\n\tconstructor(write: (text: string) => void, replaceInPlace: boolean, width = 80) {\n\t\tthis.write = write;\n\t\tthis.replaceInPlace = replaceInPlace;\n\t\tthis.width = width;\n\t}\n\n\tupdate(key: string, text: string): void {\n\t\tconst line = truncateToWidth(text.replace(/[\\r\\n]+/g, \" \"), Math.max(1, this.width), \"...\");\n\t\tconst index = this.indexes.get(key);\n\t\tif (index === undefined || !this.replaceInPlace) {\n\t\t\tthis.indexes.set(key, this.lines.length);\n\t\t\tthis.lines.push(line);\n\t\t\tthis.write(`${line}\\n`);\n\t\t\treturn;\n\t\t}\n\t\tthis.lines[index] = line;\n\t\tconst offset = this.lines.length - index;\n\t\tthis.write(`\\x1b[${offset}A\\r\\x1b[2K${line}\\x1b[${offset}B\\r`);\n\t}\n}\n\nfunction startupStatusRenderer(write: (text: string) => void, interactive: boolean): StartupStatusRenderer {\n\tconst width = typeof process.stderr.columns === \"number\" && process.stderr.columns > 0 ? process.stderr.columns : 80;\n\treturn new StartupStatusRenderer(write, interactive && process.stderr.isTTY === true, width);\n}\n\nasync function openOrCreateSession(filePath: string, cwd: string, now: () => number): Promise<SessionManager> {\n\ttry {\n\t\tawait access(filePath);\n\t\treturn await SessionManager.open(filePath, { now });\n\t} catch (cause) {\n\t\tif (!(cause instanceof Error && \"code\" in cause && cause.code === \"ENOENT\")) throw cause;\n\t\treturn SessionManager.create({ filePath, cwd, now, deferCreate: true });\n\t}\n}\n\nfunction newSessionPath(sessionDirectory: string, now: () => number): string {\n\treturn join(sessionDirectory, `session-${now()}-${randomUUID().slice(0, 8)}.jsonl`);\n}\n\nasync function mostRecentSessionPath(sessionDirectory: string): Promise<string | undefined> {\n\tlet names: string[];\n\ttry {\n\t\tnames = (await readdir(sessionDirectory, { withFileTypes: true }))\n\t\t\t.filter((entry) => entry.isFile() && extname(entry.name) === \".jsonl\")\n\t\t\t.map((entry) => entry.name);\n\t} catch (cause) {\n\t\tif (cause instanceof Error && \"code\" in cause && cause.code === \"ENOENT\") return undefined;\n\t\tthrow cause;\n\t}\n\n\tconst candidates = await Promise.all(\n\t\tnames.map(async (name) => {\n\t\t\tconst filePath = join(sessionDirectory, name);\n\t\t\ttry {\n\t\t\t\treturn { filePath, modifiedAt: (await stat(filePath)).mtimeMs };\n\t\t\t} catch (cause) {\n\t\t\t\tif (cause instanceof Error && \"code\" in cause && cause.code === \"ENOENT\") return undefined;\n\t\t\t\tthrow cause;\n\t\t\t}\n\t\t}),\n\t);\n\treturn candidates\n\t\t.filter((candidate): candidate is { filePath: string; modifiedAt: number } => candidate !== undefined)\n\t\t.sort((left, right) => right.modifiedAt - left.modifiedAt || right.filePath.localeCompare(left.filePath))[0]\n\t\t?.filePath;\n}\n\nasync function hasProjectLocalCapabilities(cwd: string): Promise<boolean> {\n\tconst directories = [\n\t\tjoin(cwd, \".di-code\", \"skills\"),\n\t\tjoin(cwd, \".agents\", \"skills\"),\n\t\tjoin(cwd, \".di-code\", \"extensions\"),\n\t\tjoin(cwd, \".di-code\", \"plugins\"),\n\t\tjoin(cwd, \".di-code\", \"mcp.local.json\"),\n\t\tjoin(cwd, \".mcp.json\"),\n\t];\n\tconst results = await Promise.all(\n\t\tdirectories.map(async (directory) => {\n\t\t\ttry {\n\t\t\t\tconst metadata = await stat(directory);\n\t\t\t\treturn metadata.isDirectory() || metadata.isFile();\n\t\t\t} catch (cause) {\n\t\t\t\tif (cause instanceof Error && \"code\" in cause && cause.code === \"ENOENT\") return false;\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}),\n\t);\n\treturn results.some(Boolean);\n}\n\nasync function selectStartupSession(\n\tcommand: Extract<CliCommand, { kind: \"run\" }>,\n\tallowedRoot: string,\n\tagentDir: string,\n\tnow: () => number,\n): Promise<SessionManager> {\n\tconst sessionDirectory = defaultSessionDirectory(agentDir, allowedRoot);\n\tif (command.sessionPath !== undefined) {\n\t\treturn openOrCreateSession(resolve(allowedRoot, command.sessionPath), allowedRoot, now);\n\t}\n\tif (command.continueSession) {\n\t\tconst recentPath = await mostRecentSessionPath(sessionDirectory);\n\t\tif (recentPath !== undefined) return SessionManager.open(recentPath, { now });\n\t}\n\treturn SessionManager.create({\n\t\tfilePath: newSessionPath(sessionDirectory, now),\n\t\tcwd: allowedRoot,\n\t\tnow,\n\t\tdeferCreate: true,\n\t});\n}\n\nfunction formatSessionTimestamp(timestamp: number, fallback: string, timeZone?: string): string {\n\tconst date = new Date(timestamp);\n\tif (Number.isNaN(date.getTime())) return fallback;\n\ttry {\n\t\tconst parts = new Map(\n\t\t\tnew Intl.DateTimeFormat(\"en-CA\", {\n\t\t\t\ttimeZone: timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone,\n\t\t\t\tyear: \"numeric\",\n\t\t\t\tmonth: \"2-digit\",\n\t\t\t\tday: \"2-digit\",\n\t\t\t\thour: \"2-digit\",\n\t\t\t\tminute: \"2-digit\",\n\t\t\t\thourCycle: \"h23\",\n\t\t\t})\n\t\t\t\t.formatToParts(date)\n\t\t\t\t.filter((part) => part.type !== \"literal\")\n\t\t\t\t.map((part) => [part.type, part.value]),\n\t\t);\n\t\tconst year = parts.get(\"year\");\n\t\tconst month = parts.get(\"month\");\n\t\tconst day = parts.get(\"day\");\n\t\tconst hour = parts.get(\"hour\");\n\t\tconst minute = parts.get(\"minute\");\n\t\tif (!year || !month || !day || !hour || !minute) return fallback;\n\t\treturn `${year}-${month}-${day} ${hour}:${minute}`;\n\t} catch {\n\t\treturn fallback;\n\t}\n}\n\nexport function formatSessionLabel(manager: SessionManager, timeZone?: string): string {\n\tconst firstUserEntry = manager.entries.find((entry) => entry.type === \"message\" && entry.message.role === \"user\");\n\tconst fileName = basename(manager.filePath, extname(manager.filePath));\n\tif (firstUserEntry?.type !== \"message\" || firstUserEntry.message.role !== \"user\") {\n\t\treturn `${fileName} (${formatSessionTimestamp(Date.parse(manager.header.timestamp), manager.header.timestamp, timeZone)})`;\n\t}\n\n\tconst question = firstUserEntry.message.content\n\t\t.filter((content) => content.type === \"text\")\n\t\t.map((content) => content.text)\n\t\t.join(\" \")\n\t\t.replace(/\\s+/g, \" \")\n\t\t.trim();\n\tconst label =\n\t\tquestion.length > MAX_SESSION_QUESTION_LENGTH\n\t\t\t? `${question.slice(0, MAX_SESSION_QUESTION_LENGTH - 3)}...`\n\t\t\t: question || fileName;\n\tconst timestamp = formatSessionTimestamp(firstUserEntry.message.timestamp, firstUserEntry.timestamp, timeZone);\n\treturn `${label} (${timestamp})`;\n}\n\nasync function sessionChoices(\n\tsessionDirectory: string,\n\tcurrentFile: string,\n\topen: (filePath: string) => Promise<AgentSession>,\n): Promise<readonly { id: string; label: string; description: string; open: () => Promise<AgentSession> }[]> {\n\tlet names: string[] = [];\n\ttry {\n\t\tnames = (await readdir(sessionDirectory, { withFileTypes: true }))\n\t\t\t.filter((entry) => entry.isFile() && extname(entry.name) === \".jsonl\")\n\t\t\t.map((entry) => entry.name)\n\t\t\t.sort();\n\t} catch (cause) {\n\t\tif (!(cause instanceof Error && \"code\" in cause && cause.code === \"ENOENT\")) throw cause;\n\t}\n\n\treturn Promise.all(\n\t\tnames\n\t\t\t.filter((name) => resolve(sessionDirectory, name) !== resolve(currentFile))\n\t\t\t.map(async (name) => {\n\t\t\t\tconst filePath = join(sessionDirectory, name);\n\t\t\t\tconst id = basename(name, extname(name));\n\t\t\t\tlet label = id;\n\t\t\t\ttry {\n\t\t\t\t\tlabel = formatSessionLabel(await SessionManager.open(filePath));\n\t\t\t\t} catch {\n\t\t\t\t\t// Keep damaged sessions selectable so opening one can report the detailed load error.\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tid,\n\t\t\t\t\tlabel,\n\t\t\t\t\tdescription: filePath,\n\t\t\t\t\topen: () => open(filePath),\n\t\t\t\t};\n\t\t\t}),\n\t);\n}\n\nexport async function runMain(args: readonly string[], options: MainOptions): Promise<number> {\n\tconst dependencies: CliDependencies = {\n\t\tstdout: options.stdout,\n\t\tstderr: options.stderr,\n\t\tversion: options.version,\n\t\tlocale: options.locale ?? options.startupConfiguration?.locale ?? DEFAULT_LOCALE,\n\t\tplugin: async (command) => {\n\t\t\tconst agentDir = resolve(options.agentDir ?? join(homedir(), \".di-code\"));\n\t\t\tconst manager = new PluginManager({ agentDir });\n\t\t\ttry {\n\t\t\t\tswitch (command.action) {\n\t\t\t\t\tcase \"list\":\n\t\t\t\t\t\tfor (const plugin of await manager.list())\n\t\t\t\t\t\t\toptions.stdout(`${plugin.id}\\t${plugin.enabled ? \"enabled\" : \"disabled\"}\\t${plugin.manifest.version}\\n`);\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\tcase \"install\": {\n\t\t\t\t\t\tconst plugin = await manager.install(command.argument as string);\n\t\t\t\t\t\toptions.stdout(`Installed ${plugin.id}\\n`);\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"enable\":\n\t\t\t\t\t\tawait manager.enable(command.argument as string);\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\tcase \"disable\":\n\t\t\t\t\t\tawait manager.disable(command.argument as string);\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\tcase \"update\":\n\t\t\t\t\t\tawait manager.update(command.argument as string);\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\tcase \"remove\":\n\t\t\t\t\t\tawait manager.remove(command.argument as string);\n\t\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t} catch (cause) {\n\t\t\t\toptions.stderr(`${cause instanceof Error ? cause.message : String(cause)}\\n`);\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t},\n\t\tmcp: async (command) => {\n\t\t\tconst cwd = resolve(options.allowedRoot ?? process.cwd());\n\t\t\tconst scope = command.scope;\n\t\t\tconst trustManager = new ProjectTrustManager(join(options.agentDir ?? join(homedir(), \".di-code\"), \"trust.json\"));\n\t\t\tconst requireProjectTrust = async (selected: McpConfigScope): Promise<void> => {\n\t\t\t\tif ((selected === \"local\" || selected === \"project\") && (await trustManager.get(cwd)) !== true)\n\t\t\t\t\tthrow new Error(`Project trust is required to modify the ${selected} MCP scope.`);\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tswitch (command.action) {\n\t\t\t\t\tcase \"add\": {\n\t\t\t\t\t\tconst selected = scope ?? \"local\";\n\t\t\t\t\t\tawait requireProjectTrust(selected);\n\t\t\t\t\t\tconst config =\n\t\t\t\t\t\t\tcommand.transport === \"stdio\"\n\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\tcommand: command.command,\n\t\t\t\t\t\t\t\t\t\t...(command.args && command.args.length > 0 ? { args: command.args } : {}),\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t: { type: \"http\", url: command.url };\n\t\t\t\t\t\tawait addMcpConfig(cwd, selected, command.serverId as string, config);\n\t\t\t\t\t\toptions.stdout(`Added MCP server \"${command.serverId}\" to ${selected} scope.\\n`);\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"list\": {\n\t\t\t\t\t\tconst scopes: readonly McpConfigScope[] = scope ? [scope] : [\"local\", \"project\", \"user\"];\n\t\t\t\t\t\tfor (const selected of scopes) {\n\t\t\t\t\t\t\tfor (const entry of await listMcpConfig(cwd, selected))\n\t\t\t\t\t\t\t\toptions.stdout(`${entry.id}\\t${entry.scope}\\t${JSON.stringify(entry.config)}\\n`);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"get\": {\n\t\t\t\t\t\tconst entry = await getMcpConfig(cwd, command.serverId as string, scope);\n\t\t\t\t\t\tif (!entry) throw new Error(`MCP server \"${command.serverId}\" was not found.`);\n\t\t\t\t\t\toptions.stdout(`${JSON.stringify({ id: entry.id, scope: entry.scope, config: entry.config })}\\n`);\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"remove\": {\n\t\t\t\t\t\tconst selected = scope ?? \"local\";\n\t\t\t\t\t\tawait requireProjectTrust(selected);\n\t\t\t\t\t\tawait removeMcpConfig(cwd, selected, command.serverId as string);\n\t\t\t\t\t\toptions.stdout(`Removed MCP server \"${command.serverId}\" from ${selected} scope.\\n`);\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (cause) {\n\t\t\t\toptions.stderr(`${cause instanceof Error ? cause.message : String(cause)}\\n`);\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t},\n\t\trun: async (command) => {\n\t\t\tconst allowedRoot = resolve(options.allowedRoot ?? process.cwd());\n\t\t\tconst now = options.now ?? Date.now;\n\t\t\tconst agentDir = resolve(options.agentDir ?? join(homedir(), \".di-code\"));\n\t\t\tconst trustManager = new ProjectTrustManager(join(agentDir, \"trust.json\"));\n\t\t\tif (command.projectTrust !== undefined) await trustManager.set(allowedRoot, command.projectTrust);\n\t\t\tlet persistedTrust = await trustManager.get(allowedRoot);\n\t\t\tconst shouldPromptForTrust =\n\t\t\t\tcommand.mode === \"interactive\" &&\n\t\t\t\toptions.isInteractiveTerminal === true &&\n\t\t\t\tcommand.projectTrust === undefined &&\n\t\t\t\tpersistedTrust === null &&\n\t\t\t\toptions.promptProjectTrust !== undefined &&\n\t\t\t\t(await hasProjectLocalCapabilities(allowedRoot));\n\t\t\tif (shouldPromptForTrust) {\n\t\t\t\tlet decision = false;\n\t\t\t\ttry {\n\t\t\t\t\tdecision = await options.promptProjectTrust(allowedRoot);\n\t\t\t\t} catch {\n\t\t\t\t\t// Fail closed when the prompt is interrupted or unavailable.\n\t\t\t\t}\n\t\t\t\tawait trustManager.set(allowedRoot, decision);\n\t\t\t\tpersistedTrust = decision;\n\t\t\t}\n\t\t\tconst runtime = await options.createRuntime(command);\n\t\t\tif (runtime === undefined) return 0;\n\t\t\tconst resources = await loadResources({\n\t\t\t\tcwd: allowedRoot,\n\t\t\t\tagentDir,\n\t\t\t\tprojectTrusted: persistedTrust === true,\n\t\t\t\tnoSkills: command.noSkills,\n\t\t\t\tnoContextFiles: command.noContextFiles,\n\t\t\t\tskillPaths: command.skillPaths,\n\t\t\t});\n\t\t\tfor (const diagnostic of resources.diagnostics) {\n\t\t\t\tif (diagnostic.kind !== \"skill\") continue;\n\t\t\t\toptions.stderr(\n\t\t\t\t\t`${JSON.stringify({ type: \"skill_diagnostic\", path: diagnostic.path, stage: diagnostic.stage, severity: diagnostic.severity, message: diagnostic.message })}\\n`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst interactivePluginStatus = command.mode === \"interactive\";\n\t\t\tconst startupStatus = startupStatusRenderer(options.stderr, interactivePluginStatus);\n\t\t\tconst pluginStatusFailures = new Set<string>();\n\t\t\tconst extensions = await loadPlugins({\n\t\t\t\tcwd: allowedRoot,\n\t\t\t\tagentDir,\n\t\t\t\ttrustManager,\n\t\t\t\tmode: command.mode,\n\t\t\t\t...(interactivePluginStatus\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tonPluginLoadStatus: (status) => {\n\t\t\t\t\t\t\t\tif (status.state === \"failed\") pluginStatusFailures.add(status.sourcePath);\n\t\t\t\t\t\t\t\tstartupStatus.update(pluginStatusKey(status), formatPluginStatus(status));\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t});\n\t\t\tfor (const diagnostic of extensions.diagnostics) {\n\t\t\t\tif (interactivePluginStatus) {\n\t\t\t\t\tif (pluginStatusFailures.has(diagnostic.sourcePath)) continue;\n\t\t\t\t\toptions.stderr(formatPluginDiagnostic(diagnostic.pluginId, diagnostic.stage, diagnostic.message));\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\toptions.stderr(\n\t\t\t\t\t`${JSON.stringify({ type: \"plugin_diagnostic\", pluginId: diagnostic.pluginId, stage: diagnostic.stage, sourcePath: diagnostic.sourcePath, severity: diagnostic.severity, message: diagnostic.message })}\\n`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst interactiveMcpStatus = command.mode === \"interactive\";\n\t\t\tconst mcp = await loadProjectMcp({\n\t\t\t\tcwd: allowedRoot,\n\t\t\t\tprojectTrusted: persistedTrust === true,\n\t\t\t\thomeDirectory: homedir(),\n\t\t\t\treservedToolNames: [\n\t\t\t\t\t\"read\",\n\t\t\t\t\t\"write\",\n\t\t\t\t\t\"edit\",\n\t\t\t\t\t\"bash\",\n\t\t\t\t\t\"load_skill\",\n\t\t\t\t\t...extensions.host.listTools().map((tool) => tool.name),\n\t\t\t\t],\n\t\t\t\t...(interactiveMcpStatus\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tonServerConnectionStatus: (status) =>\n\t\t\t\t\t\t\t\tstartupStatus.update(`mcp:${status.serverId}`, formatMcpStatus(status)),\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t});\n\t\t\tfor (const diagnostic of mcp.diagnostics) {\n\t\t\t\tif (interactiveMcpStatus) {\n\t\t\t\t\tif (diagnostic.serverId && (diagnostic.stage === \"connect\" || diagnostic.stage === \"list_tools\")) continue;\n\t\t\t\t\toptions.stderr(formatMcpDiagnostic(diagnostic.serverId, diagnostic.stage, diagnostic.message));\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\toptions.stderr(\n\t\t\t\t\t`${JSON.stringify({ type: \"mcp_diagnostic\", serverId: diagnostic.serverId, stage: diagnostic.stage, message: diagnostic.message })}\\n`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst systemPrompt = buildSystemPrompt({ cwd: allowedRoot, ...resources });\n\t\t\tconst manager = await selectStartupSession(command, allowedRoot, agentDir, now);\n\t\t\tconst sessionFile = manager.filePath;\n\t\t\tconst session = new AgentSession({\n\t\t\t\tallowedRoot,\n\t\t\t\tprovider: runtime.provider,\n\t\t\t\tmodel: runtime.model,\n\t\t\t\tsystemPrompt,\n\t\t\t\tskills: resources.skills,\n\t\t\t\tnow: options.now,\n\t\t\t\tsessionManager: manager,\n\t\t\t\textensionHost: extensions.host,\n\t\t\t\texternalTools: mcp.tools,\n\t\t\t});\n\t\t\tconst imagePaths = command.imagePaths ?? [];\n\t\t\tconst promptRunner = {\n\t\t\t\tprompt: async (text: string) => session.promptWithImages(text, await loadImageInputs(imagePaths, allowedRoot)),\n\t\t\t\tsubscribe: session.subscribe.bind(session),\n\t\t\t};\n\t\t\tif (command.mode === \"json\") {\n\t\t\t\tawait extensions.host.emit({ type: \"session_start\", cwd: allowedRoot });\n\t\t\t\ttry {\n\t\t\t\t\treturn await runJsonMode(command.prompt, promptRunner, options);\n\t\t\t\t} finally {\n\t\t\t\t\tawait extensions.host.emit({ type: \"session_shutdown\", reason: \"user\" });\n\t\t\t\t\tawait mcp.manager.close();\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (command.mode === \"interactive\") {\n\t\t\t\tconst terminal = new ProcessTerminal();\n\t\t\t\tconst tui = new TUI(terminal);\n\t\t\t\tconst mode = new InteractiveMode({\n\t\t\t\t\tsession,\n\t\t\t\t\ttui,\n\t\t\t\t\tagentDir,\n\t\t\t\t\tlocale: options.locale ?? options.startupConfiguration?.locale ?? DEFAULT_LOCALE,\n\t\t\t\t\tonExit: () => {\n\t\t\t\t\t\tvoid mcp.manager.close();\n\t\t\t\t\t},\n\t\t\t\t\textensionHost: extensions.host,\n\t\t\t\t\t...(options.startupConfiguration\n\t\t\t\t\t\t? { providerOnboarding: { configuration: options.startupConfiguration, agentDir } }\n\t\t\t\t\t\t: {}),\n\t\t\t\t\tsessions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"new-session\",\n\t\t\t\t\t\t\tlabel: translate(options.locale ?? options.startupConfiguration?.locale ?? DEFAULT_LOCALE, \"newSession\"),\n\t\t\t\t\t\t\tdescription: translate(\n\t\t\t\t\t\t\t\toptions.locale ?? options.startupConfiguration?.locale ?? DEFAULT_LOCALE,\n\t\t\t\t\t\t\t\t\"newSessionDescription\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\topen: async () => {\n\t\t\t\t\t\t\t\tconst filePath = newSessionPath(dirname(sessionFile), now);\n\t\t\t\t\t\t\t\tconst nextManager = await SessionManager.create({\n\t\t\t\t\t\t\t\t\tfilePath,\n\t\t\t\t\t\t\t\t\tcwd: allowedRoot,\n\t\t\t\t\t\t\t\t\tnow,\n\t\t\t\t\t\t\t\t\tdeferCreate: true,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\treturn new AgentSession({\n\t\t\t\t\t\t\t\t\tallowedRoot,\n\t\t\t\t\t\t\t\t\tprovider: runtime.provider,\n\t\t\t\t\t\t\t\t\tmodel: runtime.model,\n\t\t\t\t\t\t\t\t\tsystemPrompt,\n\t\t\t\t\t\t\t\t\tskills: resources.skills,\n\t\t\t\t\t\t\t\t\tnow: options.now,\n\t\t\t\t\t\t\t\t\tsessionManager: nextManager,\n\t\t\t\t\t\t\t\t\textensionHost: extensions.host,\n\t\t\t\t\t\t\t\t\texternalTools: mcp.tools,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t...(await sessionChoices(dirname(sessionFile), sessionFile, async (filePath) => {\n\t\t\t\t\t\t\tconst nextManager = await SessionManager.open(filePath, { now });\n\t\t\t\t\t\t\treturn new AgentSession({\n\t\t\t\t\t\t\t\tallowedRoot,\n\t\t\t\t\t\t\t\tprovider: runtime.provider,\n\t\t\t\t\t\t\t\tmodel: runtime.model,\n\t\t\t\t\t\t\t\tsystemPrompt,\n\t\t\t\t\t\t\t\tskills: resources.skills,\n\t\t\t\t\t\t\t\tnow: options.now,\n\t\t\t\t\t\t\t\tsessionManager: nextManager,\n\t\t\t\t\t\t\t\textensionHost: extensions.host,\n\t\t\t\t\t\t\t\texternalTools: mcp.tools,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t})),\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t\tmode.start(command.prompt);\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tawait extensions.host.emit({ type: \"session_start\", cwd: allowedRoot });\n\t\t\ttry {\n\t\t\t\treturn await runPrintMode(command.prompt, promptRunner, options);\n\t\t\t} finally {\n\t\t\t\tawait extensions.host.emit({ type: \"session_shutdown\", reason: \"user\" });\n\t\t\t\tawait mcp.manager.close();\n\t\t\t}\n\t\t},\n\t};\n\n\treturn runCli(args, dependencies);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,O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AAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7D,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACpD,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC1B,OAAO,WAAW,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,qCAAqC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;QAC9F,OAAO,CAAC,CAAC;IACV,CAAC;YAAS,CAAC;QACV,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAC5C,IAAI,CAAC;YACJ,IAAI,CAAC;gBACJ,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;YACxB,CAAC;oBAAS,CAAC;gBACV,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;YACzB,CAAC;QACF,CAAC;gBAAS,CAAC;YACV,WAAW,EAAE,CAAC;YACd,IAAI,MAAM,EAAE,CAAC;gBACZ,MAAM,CAAC,OAAO,EAAE,CAAC;gBACjB,IAAI,MAAM,CAAC,QAAQ,EAAE;oBAAE,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC;YACtD,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { access } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { join, resolve } from \"node:path\";\nimport { hostCommandRegistryKey, processExitKey, sessionStoreKey } from \"@di-code/builtins\";\nimport { createCompositionLoader, type PluginModule } from \"@di-code/plugin-loader\";\nimport { createRootContext, type RuntimeEvent, redactSensitiveText } from \"@di-code/plugin-runtime\";\nimport { type CliCommand, createCliParser } from \"./cli.ts\";\nimport {\n\timportCompositionModule,\n\tresolveCompositionEntries,\n\tresolveManagedCompositionEntries,\n} from \"./compositions.ts\";\nimport { createProjectTrustStore } from \"./project-trust-entry.ts\";\nimport type { InteractiveBootstrapOptions } from \"./runtime/interactive-host-service.ts\";\nimport { pluginInventoryKey } from \"./runtime/plugin-inventory-service.ts\";\n\nexport interface MinimalProfileOptions {\n\treadonly version: string;\n\treadonly allowedRoot?: string;\n\t/** User data root used to resolve managed plugin state. */\n\treadonly agentDir?: string;\n\treadonly stdout: (text: string) => void;\n\treadonly stderr: (text: string) => void;\n\treadonly onRuntimeEvent?: (event: RuntimeEvent) => void;\n\treadonly onSessionDisposed?: () => void;\n\t/** Terminal-only facilities supplied by the executable bootstrap. */\n\treadonly interactive?: InteractiveBootstrapOptions;\n\t/** Test-only namespace importer; production uses package-aware composition imports. */\n\treadonly importModule?: (name: string) => Promise<PluginModule>;\n}\n\nfunction errorMessage(cause: unknown): string {\n\treturn redactSensitiveText(cause instanceof Error ? cause.message : String(cause));\n}\n\nfunction isRun(command: CliCommand): command is Extract<CliCommand, { kind: \"run\" }> {\n\treturn command.kind === \"run\";\n}\n\nfunction isMinimalCommand(command: CliCommand): command is Extract<CliCommand, { kind: \"run\" | \"plugin\" | \"observe\" }> {\n\treturn command.kind === \"run\" || command.kind === \"plugin\" || command.kind === \"observe\";\n}\n\nasync function hasTrustedProjectContent(cwd: string): Promise<boolean> {\n\tfor (const path of [\n\t\tjoin(cwd, \".di-code\", \"skills\"),\n\t\tjoin(cwd, \".agents\", \"skills\"),\n\t\tjoin(cwd, \".di-code\", \"mcp.local.json\"),\n\t\tjoin(cwd, \".mcp.json\"),\n\t]) {\n\t\ttry {\n\t\t\tawait access(path);\n\t\t\treturn true;\n\t\t} catch (cause) {\n\t\t\tif (!(cause instanceof Error && \"code\" in cause && cause.code === \"ENOENT\")) throw cause;\n\t\t}\n\t}\n\treturn false;\n}\n\n/** Starts a composition profile and executes its registered host command. */\nexport async function runMinimalProfile(args: readonly string[], options: MinimalProfileOptions): Promise<number> {\n\tconst parser = createCliParser();\n\tlet command: CliCommand;\n\ttry {\n\t\tcommand = parser.parse(args);\n\t} catch (cause) {\n\t\toptions.stderr(`${errorMessage(cause)}\\n`);\n\t\treturn 1;\n\t}\n\tif (command.kind === \"help\") {\n\t\toptions.stdout(`${parser.help(\"en\")}\\n`);\n\t\treturn 0;\n\t}\n\tif (command.kind === \"version\") {\n\t\toptions.stdout(`${options.version}\\n`);\n\t\treturn 0;\n\t}\n\tif (!isMinimalCommand(command)) {\n\t\toptions.stderr(\"MCP commands are unavailable in the minimal profile.\\n\");\n\t\treturn 1;\n\t}\n\tif (isRun(command) && command.mode === \"interactive\" && !options.interactive?.isInteractiveTerminal) {\n\t\toptions.stderr(\"Interactive mode requires an interactive TTY.\\n\");\n\t\treturn 1;\n\t}\n\tconst mode = isRun(command) ? command.mode : \"print\";\n\tconst observability = command.kind === \"observe\";\n\tconst allowedRoot = resolve(options.allowedRoot ?? process.cwd());\n\tconst agentDir = resolve(options.agentDir ?? join(homedir(), \".di-code\"));\n\tconst trustStore = createProjectTrustStore(join(agentDir, \"trust.json\"));\n\tif (isRun(command) && command.projectTrust !== undefined) await trustStore.set(allowedRoot, command.projectTrust);\n\tlet projectTrusted = isRun(command) && !command.noProjectPlugins && (await trustStore.get(allowedRoot)) === true;\n\tif (\n\t\tisRun(command) &&\n\t\tcommand.mode === \"interactive\" &&\n\t\t!projectTrusted &&\n\t\tcommand.projectTrust === undefined &&\n\t\toptions.interactive?.promptProjectTrust &&\n\t\t(await hasTrustedProjectContent(allowedRoot))\n\t) {\n\t\tprojectTrusted = await options.interactive.promptProjectTrust(allowedRoot);\n\t\tawait trustStore.set(allowedRoot, projectTrusted);\n\t}\n\tconst managedEntries = await resolveManagedCompositionEntries(agentDir);\n\tconst compositionEntries = await resolveCompositionEntries(\n\t\tisRun(command) ? (command.profile ?? command.mode) : \"base\",\n\t\t{\n\t\t\tcwd: allowedRoot,\n\t\t\tagentDir,\n\t\t\t...(isRun(command) && command.compositionPath ? { compositionPath: command.compositionPath } : {}),\n\t\t\tincludeProjectComposition: projectTrusted,\n\t\t\tobservability,\n\t\t\tallowedRoot,\n\t\t},\n\t);\n\tconst context = createRootContext({ id: \"minimal-profile\", mode, trustedProject: projectTrusted });\n\tconst unsubscribe = context.events.subscribe((event) => options.onRuntimeEvent?.(event));\n\tconst loader = createCompositionLoader({\n\t\tcontext,\n\t\tentries: [...compositionEntries, ...managedEntries],\n\t\timportModule: options.importModule ?? importCompositionModule,\n\t\tprojectTrusted,\n\t});\n\ttry {\n\t\tawait loader.load();\n\t\tcontext.require(pluginInventoryKey).set(loader.tree.snapshot());\n\t\tconst host = context.require(hostCommandRegistryKey);\n\t\tlet name: string;\n\t\tlet input: unknown;\n\t\tif (command.kind === \"observe\") {\n\t\t\tname = command.action === \"trace\" ? \"trace-plugins\" : \"dump-composition\";\n\t\t\tinput = { stdout: options.stdout };\n\t\t} else if (command.kind === \"plugin\") {\n\t\t\tname = \"plugin\";\n\t\t\tinput = { ...command, stdout: options.stdout, stderr: options.stderr };\n\t\t} else if (command.mode === \"interactive\") {\n\t\t\tname = \"interactive\";\n\t\t\tinput = {\n\t\t\t\tcommand,\n\t\t\t\tcwd: allowedRoot,\n\t\t\t\tagentDir,\n\t\t\t\tprojectTrusted,\n\t\t\t\tstderr: options.stderr,\n\t\t\t\t...(options.interactive?.startInteractiveMode\n\t\t\t\t\t? { startInteractiveMode: options.interactive.startInteractiveMode }\n\t\t\t\t\t: {}),\n\t\t\t};\n\t\t} else {\n\t\t\tname = command.mode;\n\t\t\tinput = { prompt: command.prompt, stdout: options.stdout };\n\t\t}\n\t\tconst code = await host.execute(name, input, context.signal);\n\t\tconst processExit = context.require(processExitKey);\n\t\tprocessExit.setCode(code);\n\t\treturn processExit.code();\n\t} catch (cause) {\n\t\toptions.stderr(`${errorMessage(cause).replace(/^Required entry agent-loop failed: /, \"\")}\\n`);\n\t\treturn 1;\n\t} finally {\n\t\tconst memory = context.get(sessionStoreKey);\n\t\ttry {\n\t\t\ttry {\n\t\t\t\tawait loader.dispose();\n\t\t\t} finally {\n\t\t\t\tawait context.dispose();\n\t\t\t}\n\t\t} finally {\n\t\t\tunsubscribe();\n\t\t\tif (memory) {\n\t\t\t\tmemory.dispose();\n\t\t\t\tif (memory.disposed()) options.onSessionDisposed?.();\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AgentTool } from "@di-code/agent";
|
|
2
|
+
import { type McpClient, type McpConnectedServer, McpManager, type McpManagerOptions, type McpServerConfig } from "@di-code/mcp";
|
|
3
|
+
import { type PluginDefinition } from "@di-code/plugin-runtime";
|
|
4
|
+
export interface McpConfigService {
|
|
5
|
+
readonly load: (options: {
|
|
6
|
+
readonly cwd: string;
|
|
7
|
+
readonly homeDirectory?: string;
|
|
8
|
+
readonly environment?: Readonly<Record<string, string | undefined>>;
|
|
9
|
+
readonly projectTrusted: boolean;
|
|
10
|
+
}) => Promise<readonly McpServerConfig[]>;
|
|
11
|
+
}
|
|
12
|
+
export interface McpClientService {
|
|
13
|
+
readonly connect: (configurations: readonly McpServerConfig[], options?: Partial<Pick<McpManagerOptions, "onServerConnectionStatus">> & {
|
|
14
|
+
readonly signal?: AbortSignal;
|
|
15
|
+
}) => Promise<{
|
|
16
|
+
readonly manager: McpManager;
|
|
17
|
+
readonly servers: readonly McpConnectedServer[];
|
|
18
|
+
readonly diagnostics: Awaited<ReturnType<McpManager["connect"]>>["diagnostics"];
|
|
19
|
+
}>;
|
|
20
|
+
/** Releases a connected manager before the owning Fiber is disposed. */
|
|
21
|
+
readonly close: (manager: McpManager) => Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export interface McpToolService {
|
|
24
|
+
readonly create: (servers: readonly McpConnectedServer[], reservedNames?: Iterable<string>) => readonly AgentTool[];
|
|
25
|
+
}
|
|
26
|
+
export interface McpTransportRegistry {
|
|
27
|
+
readonly register: (type: "stdio" | "streamable-http", create: (config: McpServerConfig) => McpClient) => () => void;
|
|
28
|
+
readonly create: (config: McpServerConfig) => McpClient;
|
|
29
|
+
readonly snapshot: () => readonly string[];
|
|
30
|
+
}
|
|
31
|
+
export declare const mcpConfigServiceKey: import("@di-code/plugin-runtime").ServiceKey<McpConfigService>;
|
|
32
|
+
export declare const mcpClientServiceKey: import("@di-code/plugin-runtime").ServiceKey<McpClientService>;
|
|
33
|
+
export declare const mcpToolServiceKey: import("@di-code/plugin-runtime").ServiceKey<McpToolService>;
|
|
34
|
+
export declare const mcpTransportRegistryKey: import("@di-code/plugin-runtime").ServiceKey<McpTransportRegistry>;
|
|
35
|
+
/** Loads MCP configuration through the composition service while retaining config boundary validation. */
|
|
36
|
+
export declare const mcpConfig: PluginDefinition;
|
|
37
|
+
export declare const mcpTransport: PluginDefinition;
|
|
38
|
+
/** Owns managers created by this entry and closes any remaining connection during Fiber disposal. */
|
|
39
|
+
export declare const mcpClient: PluginDefinition;
|
|
40
|
+
/** Converts connected MCP capabilities into the single Agent ToolRegistry input surface. */
|
|
41
|
+
export declare const mcpTools: PluginDefinition;
|
|
42
|
+
//# sourceMappingURL=entries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entries.d.ts","sourceRoot":"","sources":["../../src/mcp/entries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EACN,KAAK,SAAS,EACd,KAAK,kBAAkB,EACvB,UAAU,EACV,KAAK,iBAAiB,EACtB,KAAK,eAAe,EAGpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAoB,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAIlF,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE;QACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;QAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SA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AAO,MAAM,mBAAmB,gEAAmD,CAAC;AACpF,eAAO,MAAM,mBAAmB,gEAAmD,CAAC;AACpF,eAAO,MAAM,iBAAiB,8DAAgD,CAAC;AAC/E,eAAO,MAAM,uBAAuB,oEAA2D,CAAC;AAEhG,0GAA0G;AAC1G,eAAO,MAAM,SAAS,EAAE,gBAOvB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,gBAyB1B,CAAC;AAEF,qGAAqG;AACrG,eAAO,MAAM,SAAS,EAAE,gBAmCvB,CAAC;AAEF,4FAA4F;AAC5F,eAAO,MAAM,QAAQ,EAAE,gBAStB,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { McpManager, StdioMcpClient, StreamableHttpMcpClient, } from "@di-code/mcp";
|
|
2
|
+
import { createServiceKey } from "@di-code/plugin-runtime";
|
|
3
|
+
import { loadEffectiveMcpConfig } from "./config.js";
|
|
4
|
+
import { createMcpAgentTools } from "./tool-adapter.js";
|
|
5
|
+
export const mcpConfigServiceKey = createServiceKey("mcp-config");
|
|
6
|
+
export const mcpClientServiceKey = createServiceKey("mcp-client");
|
|
7
|
+
export const mcpToolServiceKey = createServiceKey("mcp-tools");
|
|
8
|
+
export const mcpTransportRegistryKey = createServiceKey("mcp-transports");
|
|
9
|
+
/** Loads MCP configuration through the composition service while retaining config boundary validation. */
|
|
10
|
+
export const mcpConfig = {
|
|
11
|
+
apiVersion: 1,
|
|
12
|
+
name: "mcp-config",
|
|
13
|
+
version: "0.1.7",
|
|
14
|
+
apply(context) {
|
|
15
|
+
context.set(mcpConfigServiceKey, { load: loadEffectiveMcpConfig });
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
export const mcpTransport = {
|
|
19
|
+
apiVersion: 1,
|
|
20
|
+
name: "mcp-transport",
|
|
21
|
+
version: "0.1.7",
|
|
22
|
+
apply(context, _config, fiber) {
|
|
23
|
+
const transports = new Map();
|
|
24
|
+
const registry = {
|
|
25
|
+
register(type, create) {
|
|
26
|
+
if (transports.has(type))
|
|
27
|
+
throw new Error(`Duplicate MCP transport: ${type}`);
|
|
28
|
+
transports.set(type, create);
|
|
29
|
+
return () => {
|
|
30
|
+
if (transports.get(type) === create)
|
|
31
|
+
transports.delete(type);
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
create(config) {
|
|
35
|
+
const factory = transports.get(config.transport.type);
|
|
36
|
+
if (!factory)
|
|
37
|
+
throw new Error(`MCP transport is unavailable: ${config.transport.type}`);
|
|
38
|
+
return factory(config);
|
|
39
|
+
},
|
|
40
|
+
snapshot: () => Object.freeze([...transports.keys()]),
|
|
41
|
+
};
|
|
42
|
+
context.set(mcpTransportRegistryKey, registry);
|
|
43
|
+
fiber.addDisposer(registry.register("stdio", (config) => new StdioMcpClient(config)));
|
|
44
|
+
fiber.addDisposer(registry.register("streamable-http", (config) => new StreamableHttpMcpClient(config)));
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
/** Owns managers created by this entry and closes any remaining connection during Fiber disposal. */
|
|
48
|
+
export const mcpClient = {
|
|
49
|
+
apiVersion: 1,
|
|
50
|
+
name: "mcp-client",
|
|
51
|
+
version: "0.1.7",
|
|
52
|
+
apply(context, _config, fiber) {
|
|
53
|
+
context.require(mcpConfigServiceKey);
|
|
54
|
+
const transportRegistry = context.require(mcpTransportRegistryKey);
|
|
55
|
+
const managers = new Set();
|
|
56
|
+
const close = async (manager) => {
|
|
57
|
+
if (!managers.delete(manager))
|
|
58
|
+
return;
|
|
59
|
+
await manager.close();
|
|
60
|
+
};
|
|
61
|
+
context.set(mcpClientServiceKey, {
|
|
62
|
+
async connect(configurations, options = {}) {
|
|
63
|
+
const manager = new McpManager({
|
|
64
|
+
onServerConnectionStatus: options.onServerConnectionStatus,
|
|
65
|
+
createClient: (config) => transportRegistry.create(config),
|
|
66
|
+
});
|
|
67
|
+
managers.add(manager);
|
|
68
|
+
try {
|
|
69
|
+
const result = await manager.connect(configurations, options.signal);
|
|
70
|
+
return { manager, ...result };
|
|
71
|
+
}
|
|
72
|
+
catch (cause) {
|
|
73
|
+
await close(manager);
|
|
74
|
+
throw cause;
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
close,
|
|
78
|
+
});
|
|
79
|
+
fiber.addDisposer(async () => {
|
|
80
|
+
const results = await Promise.allSettled([...managers].map(close));
|
|
81
|
+
const failures = results.flatMap((result) => (result.status === "rejected" ? [result.reason] : []));
|
|
82
|
+
if (failures.length > 0)
|
|
83
|
+
throw new AggregateError(failures, "Failed to close MCP managers");
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
/** Converts connected MCP capabilities into the single Agent ToolRegistry input surface. */
|
|
88
|
+
export const mcpTools = {
|
|
89
|
+
apiVersion: 1,
|
|
90
|
+
name: "mcp-tools",
|
|
91
|
+
version: "0.1.7",
|
|
92
|
+
apply(context) {
|
|
93
|
+
context.require(mcpConfigServiceKey);
|
|
94
|
+
context.require(mcpClientServiceKey);
|
|
95
|
+
context.set(mcpToolServiceKey, { create: createMcpAgentTools });
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=entries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entries.js","sourceRoot":"","sources":["../../src/mcp/entries.ts"],"names":[],"mappings":"AACA,OAAO,EAGN,UAAU,EAGV,cAAc,EACd,uBAAuB,GACvB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAyB,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAkCxD,MAAM,CAAC,MAAM,mBAAmB,GAAG,gBAAgB,CAAmB,YAAY,CAAC,CAAC;AACpF,MAAM,CAAC,MAAM,mBAAmB,GAAG,gBAAgB,CAAmB,YAAY,CAAC,CAAC;AACpF,MAAM,CAAC,MAAM,iBAAiB,GAAG,gB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AAC,mBAAmB,CAAC,CAAC;QACrC,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;QACrC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC,CAAC;IACjE,CAAC;CACD,CAAC","sourcesContent":["import type { AgentTool } from \"@di-code/agent\";\nimport {\n\ttype McpClient,\n\ttype McpConnectedServer,\n\tMcpManager,\n\ttype McpManagerOptions,\n\ttype McpServerConfig,\n\tStdioMcpClient,\n\tStreamableHttpMcpClient,\n} from \"@di-code/mcp\";\nimport { createServiceKey, type PluginDefinition } from \"@di-code/plugin-runtime\";\nimport { loadEffectiveMcpConfig } from \"./config.ts\";\nimport { createMcpAgentTools } from \"./tool-adapter.ts\";\n\nexport interface McpConfigService {\n\treadonly load: (options: {\n\t\treadonly cwd: string;\n\t\treadonly homeDirectory?: string;\n\t\treadonly environment?: Readonly<Record<string, string | undefined>>;\n\t\treadonly projectTrusted: boolean;\n\t}) => Promise<readonly McpServerConfig[]>;\n}\n\nexport interface McpClientService {\n\treadonly connect: (\n\t\tconfigurations: readonly McpServerConfig[],\n\t\toptions?: Partial<Pick<McpManagerOptions, \"onServerConnectionStatus\">> & { readonly signal?: AbortSignal },\n\t) => Promise<{\n\t\treadonly manager: McpManager;\n\t\treadonly servers: readonly McpConnectedServer[];\n\t\treadonly diagnostics: Awaited<ReturnType<McpManager[\"connect\"]>>[\"diagnostics\"];\n\t}>;\n\t/** Releases a connected manager before the owning Fiber is disposed. */\n\treadonly close: (manager: McpManager) => Promise<void>;\n}\n\nexport interface McpToolService {\n\treadonly create: (servers: readonly McpConnectedServer[], reservedNames?: Iterable<string>) => readonly AgentTool[];\n}\n\nexport interface McpTransportRegistry {\n\treadonly register: (type: \"stdio\" | \"streamable-http\", create: (config: McpServerConfig) => McpClient) => () => void;\n\treadonly create: (config: McpServerConfig) => McpClient;\n\treadonly snapshot: () => readonly string[];\n}\n\nexport const mcpConfigServiceKey = createServiceKey<McpConfigService>(\"mcp-config\");\nexport const mcpClientServiceKey = createServiceKey<McpClientService>(\"mcp-client\");\nexport const mcpToolServiceKey = createServiceKey<McpToolService>(\"mcp-tools\");\nexport const mcpTransportRegistryKey = createServiceKey<McpTransportRegistry>(\"mcp-transports\");\n\n/** Loads MCP configuration through the composition service while retaining config boundary validation. */\nexport const mcpConfig: PluginDefinition = {\n\tapiVersion: 1,\n\tname: \"mcp-config\",\n\tversion: \"0.1.7\",\n\tapply(context) {\n\t\tcontext.set(mcpConfigServiceKey, { load: loadEffectiveMcpConfig });\n\t},\n};\n\nexport const mcpTransport: PluginDefinition = {\n\tapiVersion: 1,\n\tname: \"mcp-transport\",\n\tversion: \"0.1.7\",\n\tapply(context, _config, fiber) {\n\t\tconst transports = new Map<\"stdio\" | \"streamable-http\", (config: McpServerConfig) => McpClient>();\n\t\tconst registry: McpTransportRegistry = {\n\t\t\tregister(type, create) {\n\t\t\t\tif (transports.has(type)) throw new Error(`Duplicate MCP transport: ${type}`);\n\t\t\t\ttransports.set(type, create);\n\t\t\t\treturn () => {\n\t\t\t\t\tif (transports.get(type) === create) transports.delete(type);\n\t\t\t\t};\n\t\t\t},\n\t\t\tcreate(config) {\n\t\t\t\tconst factory = transports.get(config.transport.type);\n\t\t\t\tif (!factory) throw new Error(`MCP transport is unavailable: ${config.transport.type}`);\n\t\t\t\treturn factory(config);\n\t\t\t},\n\t\t\tsnapshot: () => Object.freeze([...transports.keys()]),\n\t\t};\n\t\tcontext.set(mcpTransportRegistryKey, registry);\n\t\tfiber.addDisposer(registry.register(\"stdio\", (config) => new StdioMcpClient(config)));\n\t\tfiber.addDisposer(registry.register(\"streamable-http\", (config) => new StreamableHttpMcpClient(config)));\n\t},\n};\n\n/** Owns managers created by this entry and closes any remaining connection during Fiber disposal. */\nexport const mcpClient: PluginDefinition = {\n\tapiVersion: 1,\n\tname: \"mcp-client\",\n\tversion: \"0.1.7\",\n\tapply(context, _config, fiber) {\n\t\tcontext.require(mcpConfigServiceKey);\n\t\tconst transportRegistry = context.require(mcpTransportRegistryKey);\n\t\tconst managers = new Set<McpManager>();\n\t\tconst close = async (manager: McpManager): Promise<void> => {\n\t\t\tif (!managers.delete(manager)) return;\n\t\t\tawait manager.close();\n\t\t};\n\t\tcontext.set(mcpClientServiceKey, {\n\t\t\tasync connect(configurations, options = {}) {\n\t\t\t\tconst manager = new McpManager({\n\t\t\t\t\tonServerConnectionStatus: options.onServerConnectionStatus,\n\t\t\t\t\tcreateClient: (config) => transportRegistry.create(config),\n\t\t\t\t});\n\t\t\t\tmanagers.add(manager);\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await manager.connect(configurations, options.signal);\n\t\t\t\t\treturn { manager, ...result };\n\t\t\t\t} catch (cause) {\n\t\t\t\t\tawait close(manager);\n\t\t\t\t\tthrow cause;\n\t\t\t\t}\n\t\t\t},\n\t\t\tclose,\n\t\t});\n\t\tfiber.addDisposer(async () => {\n\t\t\tconst results = await Promise.allSettled([...managers].map(close));\n\t\t\tconst failures = results.flatMap((result) => (result.status === \"rejected\" ? [result.reason] : []));\n\t\t\tif (failures.length > 0) throw new AggregateError(failures, \"Failed to close MCP managers\");\n\t\t});\n\t},\n};\n\n/** Converts connected MCP capabilities into the single Agent ToolRegistry input surface. */\nexport const mcpTools: PluginDefinition = {\n\tapiVersion: 1,\n\tname: \"mcp-tools\",\n\tversion: \"0.1.7\",\n\tapply(context) {\n\t\tcontext.require(mcpConfigServiceKey);\n\t\tcontext.require(mcpClientServiceKey);\n\t\tcontext.set(mcpToolServiceKey, { create: createMcpAgentTools });\n\t},\n};\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const apiVersion: number | undefined;
|
|
2
|
+
export declare const name: string;
|
|
3
|
+
export declare const version: string | undefined;
|
|
4
|
+
export declare const apply: import("@di-code/plugin-runtime").PluginApply<unknown>;
|
|
5
|
+
//# sourceMappingURL=mcp-client-entry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-client-entry.d.ts","sourceRoot":"","sources":["../src/mcp-client-entry.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,oBAAuB,CAAC;AAC/C,eAAO,MAAM,IAAI,QAAiB,CAAC;AACnC,eAAO,MAAM,OAAO,oBAAoB,CAAC;AACzC,eAAO,MAAM,KAAK,wDAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-client-entry.js","sourceRoot":"","sources":["../src/mcp-client-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC,UAAU,CAAC;AAC/C,MAAM,CAAC,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;AACnC,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC;AACzC,MAAM,CAAC,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC","sourcesContent":["import { mcpClient } from \"./mcp/entries.ts\";\nexport const apiVersion = mcpClient.apiVersion;\nexport const name = mcpClient.name;\nexport const version = mcpClient.version;\nexport const apply = mcpClient.apply;\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const apiVersion: number | undefined;
|
|
2
|
+
export declare const name: string;
|
|
3
|
+
export declare const version: string | undefined;
|
|
4
|
+
export declare const apply: import("@di-code/plugin-runtime").PluginApply<unknown>;
|
|
5
|
+
//# sourceMappingURL=mcp-config-entry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-config-entry.d.ts","sourceRoot":"","sources":["../src/mcp-config-entry.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,oBAAuB,CAAC;AAC/C,eAAO,MAAM,IAAI,QAAiB,CAAC;AACnC,eAAO,MAAM,OAAO,oBAAoB,CAAC;AACzC,eAAO,MAAM,KAAK,wDAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-config-entry.js","sourceRoot":"","sources":["../src/mcp-config-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC,UAAU,CAAC;AAC/C,MAAM,CAAC,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;AACnC,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC;AACzC,MAAM,CAAC,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC","sourcesContent":["import { mcpConfig } from \"./mcp/entries.ts\";\nexport const apiVersion = mcpConfig.apiVersion;\nexport const name = mcpConfig.name;\nexport const version = mcpConfig.version;\nexport const apply = mcpConfig.apply;\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const apiVersion: number | undefined;
|
|
2
|
+
export declare const name: string;
|
|
3
|
+
export declare const version: string | undefined;
|
|
4
|
+
export declare const apply: import("@di-code/plugin-runtime").PluginApply<unknown>;
|
|
5
|
+
//# sourceMappingURL=mcp-tools-entry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tools-entry.d.ts","sourceRoot":"","sources":["../src/mcp-tools-entry.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,oBAAsB,CAAC;AAC9C,eAAO,MAAM,IAAI,QAAgB,CAAC;AAClC,eAAO,MAAM,OAAO,oBAAmB,CAAC;AACxC,eAAO,MAAM,KAAK,wDAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tools-entry.js","sourceRoot":"","sources":["../src/mcp-tools-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;AAC9C,MAAM,CAAC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;AAClC,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;AACxC,MAAM,CAAC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC","sourcesContent":["import { mcpTools } from \"./mcp/entries.ts\";\nexport const apiVersion = mcpTools.apiVersion;\nexport const name = mcpTools.name;\nexport const version = mcpTools.version;\nexport const apply = mcpTools.apply;\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const apiVersion: number | undefined;
|
|
2
|
+
export declare const name: string;
|
|
3
|
+
export declare const version: string | undefined;
|
|
4
|
+
export declare const apply: import("@di-code/plugin-runtime").PluginApply<unknown>;
|
|
5
|
+
//# sourceMappingURL=mcp-transport-entry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-transport-entry.d.ts","sourceRoot":"","sources":["../src/mcp-transport-entry.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,oBAA0B,CAAC;AAClD,eAAO,MAAM,IAAI,QAAoB,CAAC;AACtC,eAAO,MAAM,OAAO,oBAAuB,CAAC;AAC5C,eAAO,MAAM,KAAK,wDAAqB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { mcpTransport } from "./mcp/entries.js";
|
|
2
|
+
export const apiVersion = mcpTransport.apiVersion;
|
|
3
|
+
export const name = mcpTransport.name;
|
|
4
|
+
export const version = mcpTransport.version;
|
|
5
|
+
export const apply = mcpTransport.apply;
|
|
6
|
+
//# sourceMappingURL=mcp-transport-entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-transport-entry.js","sourceRoot":"","sources":["../src/mcp-transport-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC;AAClD,MAAM,CAAC,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC;AACtC,MAAM,CAAC,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC;AAC5C,MAAM,CAAC,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC","sourcesContent":["import { mcpTransport } from \"./mcp/entries.ts\";\nexport const apiVersion = mcpTransport.apiVersion;\nexport const name = mcpTransport.name;\nexport const version = mcpTransport.version;\nexport const apply = mcpTransport.apply;\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CommandRegistry, InteractiveContextService } from "@di-code/builtins";
|
|
2
|
+
import type { Locale } from "../i18n.ts";
|
|
3
|
+
import type { InteractiveProviderOnboardingOptions } from "../provider-onboarding.ts";
|
|
4
|
+
import { InteractiveMode, type InteractiveSessionHandle } from "./interactive.ts";
|
|
5
|
+
export interface InteractiveModeEntryOptions {
|
|
6
|
+
readonly session: InteractiveSessionHandle;
|
|
7
|
+
readonly agentDir: string;
|
|
8
|
+
readonly locale: Locale;
|
|
9
|
+
readonly commandRegistry: CommandRegistry;
|
|
10
|
+
readonly context: InteractiveContextService;
|
|
11
|
+
readonly onExit: () => void;
|
|
12
|
+
readonly providerOnboarding?: Omit<InteractiveProviderOnboardingOptions, "tui">;
|
|
13
|
+
readonly initialPrompt: string;
|
|
14
|
+
readonly onCreated?: (mode: InteractiveMode) => void;
|
|
15
|
+
}
|
|
16
|
+
/** Product mode entry owns terminal construction; the CLI only selects this registered mode. */
|
|
17
|
+
export declare function runInteractiveMode(options: InteractiveModeEntryOptions): number;
|
|
18
|
+
//# sourceMappingURL=interactive-entry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactive-entry.d.ts","sourceRoot":"","sources":["../../src/modes/interactive-entry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAEpF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,2BAA2B,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,KAAK,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAElF,MAAM,WAAW,2BAA2B;IAC3C,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC;IAC3C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IAC1C,QAAQ,CAAC,OAAO,EAAE,yBAAyB,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC;IAC5B,QAAQ,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;IAChF,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAC;CACrD;AAED,gGAAgG;AAChG,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,2BAA2B,GAAG,MAAM,CAgB/E"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ProcessTerminal, TUI } from "@di-code/tui";
|
|
2
|
+
import { InteractiveMode } from "./interactive.js";
|
|
3
|
+
/** Product mode entry owns terminal construction; the CLI only selects this registered mode. */
|
|
4
|
+
export function runInteractiveMode(options) {
|
|
5
|
+
const terminal = new ProcessTerminal();
|
|
6
|
+
const tui = new TUI(terminal);
|
|
7
|
+
const mode = new InteractiveMode({
|
|
8
|
+
session: options.session,
|
|
9
|
+
tui,
|
|
10
|
+
agentDir: options.agentDir,
|
|
11
|
+
locale: options.locale,
|
|
12
|
+
commandRegistry: options.commandRegistry,
|
|
13
|
+
context: options.context,
|
|
14
|
+
onExit: options.onExit,
|
|
15
|
+
...(options.providerOnboarding ? { providerOnboarding: options.providerOnboarding } : {}),
|
|
16
|
+
});
|
|
17
|
+
options.onCreated?.(mode);
|
|
18
|
+
mode.start(options.initialPrompt);
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=interactive-entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactive-entry.js","sourceRoot":"","sources":["../../src/modes/interactive-entry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGpD,OAAO,EAAE,eAAe,EAAiC,MAAM,kBAAkB,CAAC;AAclF,gGAAgG;AAChG,MAAM,UAAU,kBAAkB,CAAC,OAAoC;IACtE,MAAM,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAC;IACvC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,MAAM,IAAI,GAAG,IAAI,eAAe,CAAC;QAChC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,GAAG;QACH,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,eAAe,EAAE,OAAO,CAAC,eAAe;QACxC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACzF,CAAC,CAAC;IACH,OAAO,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,CAAC;IAC1B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAClC,OAAO,CAAC,CAAC;AACV,CAAC","sourcesContent":["import type { CommandRegistry, InteractiveContextService } from \"@di-code/builtins\";\nimport { ProcessTerminal, TUI } from \"@di-code/tui\";\nimport type { Locale } from \"../i18n.ts\";\nimport type { InteractiveProviderOnboardingOptions } from \"../provider-onboarding.ts\";\nimport { InteractiveMode, type InteractiveSessionHandle } from \"./interactive.ts\";\n\nexport interface InteractiveModeEntryOptions {\n\treadonly session: InteractiveSessionHandle;\n\treadonly agentDir: string;\n\treadonly locale: Locale;\n\treadonly commandRegistry: CommandRegistry;\n\treadonly context: InteractiveContextService;\n\treadonly onExit: () => void;\n\treadonly providerOnboarding?: Omit<InteractiveProviderOnboardingOptions, \"tui\">;\n\treadonly initialPrompt: string;\n\treadonly onCreated?: (mode: InteractiveMode) => void;\n}\n\n/** Product mode entry owns terminal construction; the CLI only selects this registered mode. */\nexport function runInteractiveMode(options: InteractiveModeEntryOptions): number {\n\tconst terminal = new ProcessTerminal();\n\tconst tui = new TUI(terminal);\n\tconst mode = new InteractiveMode({\n\t\tsession: options.session,\n\t\ttui,\n\t\tagentDir: options.agentDir,\n\t\tlocale: options.locale,\n\t\tcommandRegistry: options.commandRegistry,\n\t\tcontext: options.context,\n\t\tonExit: options.onExit,\n\t\t...(options.providerOnboarding ? { providerOnboarding: options.providerOnboarding } : {}),\n\t});\n\toptions.onCreated?.(mode);\n\tmode.start(options.initialPrompt);\n\treturn 0;\n}\n"]}
|
|
@@ -215,7 +215,7 @@ export class InteractiveProjection {
|
|
|
215
215
|
if (content.type === "tool_call")
|
|
216
216
|
this.storeFileChange(content.id, content.name, content.arguments);
|
|
217
217
|
}
|
|
218
|
-
if (message.stopReason === "error"
|
|
218
|
+
if (message.stopReason === "error")
|
|
219
219
|
this.error = message.errorMessage;
|
|
220
220
|
this.streamingText = "";
|
|
221
221
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactive-state.js","sourceRoot":"","sources":["../../src/modes/interactive-state.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAa,MAAM,4BAA4B,CAAC;AA0CzE,SAAS,MAAM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,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAChE,CAAC;QACD,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7C,CAAC;IACD,OAAO,OAAO,cAAc,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,cAAc,CAAC,OAAO,KAAK,QAAQ;QAC9F,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,CAAC,OAAO,EAAE,CAAC;QACxE,CAAC,CAAC,SAAS,CAAC;AACd,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACpD,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACpC,OAAO,CACN,QAAQ,CAAC,KAAK,CAAC;QACf,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAC9B,CAAC,KAAK,CAAC,gBAAgB,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,gBAAgB,KAAK,QAAQ,CAAC,CACpF,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,QAAgB,EAAE,cAAuC;IACnF,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAClD,OAAO,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,UAAU,EAAE,CAAC;AACrE,CAAC","sourcesContent":["import type { Message } from \"@di-code/ai\";\nimport type { AgentSessionEvent, SessionUsage } from \"../core/session.ts\";\nimport { computeEditsDiff, type Edit } from \"../core/tools/edit-diff.ts\";\n\nexport type InteractiveMessage =\n\t| { readonly role: \"user\" | \"assistant\"; readonly text: string }\n\t| {\n\t\t\treadonly role: \"file_change\";\n\t\t\treadonly id: string;\n\t\t\treadonly path: string;\n\t\t\treadonly kind: \"edit\" | \"write\";\n\t\t\treadonly removed: readonly string[];\n\t\t\treadonly added: readonly string[];\n\t\t\treadonly diff?: string;\n\t\t\treadonly firstChangedLine?: number;\n\t };\n\ntype FileChangeCandidate = Extract<InteractiveMessage, { role: \"file_change\" }>;\n\nexport type InteractiveProcessItem =\n\t| { readonly type: \"thinking\"; readonly id: \"thinking\" }\n\t| {\n\t\t\treadonly type: \"tool\";\n\t\t\treadonly id: string;\n\t\t\treadonly command: string;\n\t\t\treadonly status: \"running\" | \"done\" | \"error\";\n\t };\n\nexport interface InteractiveState {\n\treadonly messages: readonly string[];\n\treadonly messageItems: readonly InteractiveMessage[];\n\treadonly processItems: readonly InteractiveProcessItem[];\n\treadonly spinnerFrame: number;\n\treadonly streamingText: string;\n\treadonly toolStatus: readonly string[];\n\treadonly busy: boolean;\n\treadonly error?: string;\n\treadonly queue: readonly string[];\n\treadonly status?: string;\n\treadonly compacting: boolean;\n\treadonly retrying: boolean;\n\treadonly usage: SessionUsage;\n}\n\nfunction textOf(message: Message): string {\n\ttype TextBlock = Extract<Message[\"content\"][number], { type: \"text\" }>;\n\treturn message.content\n\t\t.filter((content): content is TextBlock => content.type === \"text\")\n\t\t.map((content) => content.text)\n\t\t.join(\"\");\n}\n\nexport class InteractiveProjection {\n\tprivate readonly messages: string[] = [];\n\tprivate readonly messageItems: InteractiveMessage[] = [];\n\tprivate readonly pendingFileChanges = new Map<string, FileChangeCandidate>();\n\tprivate readonly processItems: InteractiveProcessItem[] = [];\n\tprivate readonly toolStatus = new Map<string, string>();\n\tprivate spinnerFrame = 0;\n\tprivate streamingText = \"\";\n\tprivate busy = false;\n\tprivate error: string | undefined;\n\tprivate queue: string[] = [];\n\tprivate status: string | undefined;\n\tprivate compacting = false;\n\tprivate retrying = false;\n\tprivate previewRoot: string | undefined;\n\tprivate previewChange: (() => void) | undefined;\n\tprivate usage: SessionUsage = {\n\t\trequestCount: 0,\n\t\tinputTokens: 0,\n\t\toutputTokens: 0,\n\t\tcacheReadTokens: 0,\n\t\tcacheWriteTokens: 0,\n\t\ttotalTokens: 0,\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\testimatedContextTokens: 0,\n\t\tcontextWindow: 0,\n\t\treserveTokens: 0,\n\t\ttriggerTokens: 0,\n\t};\n\n\tget state(): InteractiveState {\n\t\tconst visibleMessageItems = [...this.messageItems, ...this.pendingFileChanges.values()];\n\t\treturn {\n\t\t\tmessages: [...this.messages],\n\t\t\tmessageItems: visibleMessageItems.map((message) =>\n\t\t\t\tmessage.role === \"file_change\"\n\t\t\t\t\t? { ...message, removed: [...message.removed], added: [...message.added] }\n\t\t\t\t\t: { ...message },\n\t\t\t),\n\t\t\tprocessItems: this.processItems.map((item) => ({ ...item })),\n\t\t\tspinnerFrame: this.spinnerFrame,\n\t\t\tstreamingText: this.streamingText,\n\t\t\ttoolStatus: [...this.toolStatus.values()],\n\t\t\tbusy: this.busy,\n\t\t\terror: this.error,\n\t\t\tqueue: [...this.queue],\n\t\t\tstatus: this.status,\n\t\t\tcompacting: this.compacting,\n\t\t\tretrying: this.retrying,\n\t\t\tusage: { ...this.usage, cost: { ...this.usage.cost } },\n\t\t};\n\t}\n\n\tsetError(message: string | undefined): void {\n\t\tthis.error = message;\n\t}\n\n\tclearVisibleMessages(): void {\n\t\tthis.messages.length = 0;\n\t\tthis.messageItems.length = 0;\n\t\tthis.pendingFileChanges.clear();\n\t\tthis.streamingText = \"\";\n\t\tthis.processItems.length = 0;\n\t\tthis.toolStatus.clear();\n\t\tthis.error = undefined;\n\t}\n\n\tsetQueue(queue: readonly string[]): void {\n\t\tthis.queue = [...queue];\n\t}\n\n\tsetStatus(status: string | undefined): void {\n\t\tthis.status = status;\n\t}\n\n\tsetCompacting(value: boolean): void {\n\t\tthis.compacting = value;\n\t}\n\n\tsetRetrying(value: boolean): void {\n\t\tthis.retrying = value;\n\t}\n\n\tsetUsage(usage: SessionUsage): void {\n\t\tthis.usage = structuredClone(usage);\n\t}\n\n\tconfigureFilePreview(root: string, onChange: () => void): void {\n\t\tthis.previewRoot = root;\n\t\tthis.previewChange = onChange;\n\t}\n\n\tadvanceSpinner(): boolean {\n\t\tif (!this.busy) return false;\n\t\tthis.spinnerFrame = (this.spinnerFrame + 1) % 4;\n\t\treturn true;\n\t}\n\n\tclearTransientProcess(): void {\n\t\tthis.processItems.length = 0;\n\t\tthis.toolStatus.clear();\n\t\tthis.spinnerFrame = 0;\n\t}\n\n\treplaceTranscript(messages: readonly Message[]): void {\n\t\tthis.messages.length = 0;\n\t\tthis.messageItems.length = 0;\n\t\tthis.pendingFileChanges.clear();\n\t\tthis.processItems.length = 0;\n\t\tthis.toolStatus.clear();\n\t\tthis.spinnerFrame = 0;\n\t\tthis.streamingText = \"\";\n\t\tthis.busy = false;\n\t\tthis.error = undefined;\n\t\tfor (const message of messages) this.appendCompletedMessage(message);\n\t}\n\n\tapply(event: AgentSessionEvent): void {\n\t\tswitch (event.type) {\n\t\t\tcase \"agent_start\":\n\t\t\t\tthis.busy = true;\n\t\t\t\tthis.error = undefined;\n\t\t\t\tthis.retrying = false;\n\t\t\t\tthis.processItems.length = 0;\n\t\t\t\tthis.processItems.push({ type: \"thinking\", id: \"thinking\" });\n\t\t\t\tthis.toolStatus.clear();\n\t\t\t\tthis.spinnerFrame = 0;\n\t\t\t\treturn;\n\t\t\tcase \"compaction_start\":\n\t\t\t\tthis.compacting = true;\n\t\t\t\treturn;\n\t\t\tcase \"compaction_end\":\n\t\t\t\tthis.compacting = false;\n\t\t\t\tif (!event.success) this.error = event.errorMessage;\n\t\t\t\treturn;\n\t\t\tcase \"usage_update\":\n\t\t\t\tthis.setUsage(event.usage);\n\t\t\t\treturn;\n\t\t\tcase \"queue_update\":\n\t\t\tcase \"tree_navigated\":\n\t\t\t\treturn;\n\t\t\tcase \"message_start\":\n\t\t\t\tif (event.message.role === \"assistant\") this.streamingText = \"\";\n\t\t\t\treturn;\n\t\t\tcase \"message_update\":\n\t\t\t\tif (event.event.type === \"text_delta\") {\n\t\t\t\t\tif (event.event.delta.length > 0) this.removeThinking();\n\t\t\t\t\tthis.streamingText += event.event.delta;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\tcase \"tool_execution_start\":\n\t\t\t\tthis.removeThinking();\n\t\t\t\tthis.processItems.push({\n\t\t\t\t\ttype: \"tool\",\n\t\t\t\t\tid: event.toolCallId,\n\t\t\t\t\tcommand: formatToolCommand(event.toolName, event.arguments),\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t});\n\t\t\t\tthis.toolStatus.set(event.toolCallId, `${event.toolName}: running`);\n\t\t\t\tthis.storeFileChange(event.toolCallId, event.toolName, event.arguments);\n\t\t\t\treturn;\n\t\t\tcase \"tool_execution_end\":\n\t\t\t\tthis.updateToolStatus(event.toolCallId, event.result.isError ? \"error\" : \"done\");\n\t\t\t\tthis.toolStatus.set(event.toolCallId, `${event.toolName}: ${event.result.isError ? \"error\" : \"done\"}`);\n\t\t\t\tthis.commitFileChange(event.toolCallId, event.result.isError, event.result.details);\n\t\t\t\treturn;\n\t\t\tcase \"message_end\":\n\t\t\t\tthis.appendCompletedMessage(event.message);\n\t\t\t\treturn;\n\t\t\tcase \"agent_end\":\n\t\t\t\tthis.busy = false;\n\t\t\t\tthis.retrying = false;\n\t\t\t\tthis.pendingFileChanges.clear();\n\t\t\t\tthis.processItems.length = 0;\n\t\t\t\tthis.toolStatus.clear();\n\t\t\t\tthis.spinnerFrame = 0;\n\t\t\t\treturn;\n\t\t\tcase \"turn_start\":\n\t\t\t\tif (this.busy && !this.processItems.some((item) => item.type === \"thinking\")) {\n\t\t\t\t\tthis.processItems.push({ type: \"thinking\", id: \"thinking\" });\n\t\t\t\t\tthis.spinnerFrame = 0;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\tcase \"turn_end\":\n\t\t\t\treturn;\n\t\t}\n\t}\n\n\tprivate removeThinking(): void {\n\t\tconst index = this.processItems.findIndex((item) => item.type === \"thinking\");\n\t\tif (index >= 0) this.processItems.splice(index, 1);\n\t}\n\n\tprivate updateToolStatus(id: string, status: \"done\" | \"error\"): void {\n\t\tconst index = this.processItems.findIndex((item) => item.type === \"tool\" && item.id === id);\n\t\tconst item = this.processItems[index];\n\t\tif (index < 0 || item?.type !== \"tool\") return;\n\t\tthis.processItems[index] = { ...item, status };\n\t}\n\n\tprivate appendCompletedMessage(message: Message): void {\n\t\tif (message.role === \"tool_result\") {\n\t\t\tthis.commitFileChange(message.toolCallId, message.isError, message.details);\n\t\t\treturn;\n\t\t}\n\t\tconst text = textOf(message);\n\t\tif (message.role === \"user\") {\n\t\t\tif (text.length > 0) {\n\t\t\t\tthis.messages.push(text);\n\t\t\t\tthis.messageItems.push({ role: \"user\", text });\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (text.length > 0 && message.stopReason !== \"tool_use\") {\n\t\t\tthis.messages.push(text);\n\t\t\tthis.messageItems.push({ role: \"assistant\", text });\n\t\t}\n\t\tfor (const content of message.content) {\n\t\t\tif (content.type === \"tool_call\") this.storeFileChange(content.id, content.name, content.arguments);\n\t\t}\n\t\tif (message.stopReason === \"error\" || message.stopReason === \"aborted\") this.error = message.errorMessage;\n\t\tthis.streamingText = \"\";\n\t}\n\n\tprivate storeFileChange(id: string, toolName: string, argumentsValue: Record<string, unknown>): void {\n\t\tconst path = argumentsValue.path;\n\t\tif (typeof path !== \"string\") return;\n\t\tif (toolName === \"edit\") {\n\t\t\tconst edits = parseEditArguments(argumentsValue);\n\t\t\tif (!edits) return;\n\t\t\tconst fallback = edits.flatMap((edit) => ({\n\t\t\t\tremoved: edit.oldText.replaceAll(\"\\r\\n\", \"\\n\").split(\"\\n\"),\n\t\t\t\tadded: edit.newText.replaceAll(\"\\r\\n\", \"\\n\").split(\"\\n\"),\n\t\t\t}));\n\t\t\tthis.pendingFileChanges.set(id, {\n\t\t\t\trole: \"file_change\",\n\t\t\t\tid,\n\t\t\t\tpath,\n\t\t\t\tkind: \"edit\",\n\t\t\t\tremoved: fallback.flatMap((edit) => edit.removed),\n\t\t\t\tadded: fallback.flatMap((edit) => edit.added),\n\t\t\t});\n\t\t\tif (this.previewRoot) {\n\t\t\t\tvoid computeEditsDiff(path, edits, this.previewRoot).then((preview) => {\n\t\t\t\t\tconst current = this.pendingFileChanges.get(id);\n\t\t\t\t\tif (!current || \"error\" in preview) return;\n\t\t\t\t\tthis.pendingFileChanges.set(id, {\n\t\t\t\t\t\t...current,\n\t\t\t\t\t\tdiff: preview.diff,\n\t\t\t\t\t\tfirstChangedLine: preview.firstChangedLine,\n\t\t\t\t\t});\n\t\t\t\t\tthis.previewChange?.();\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tif (toolName === \"write\" && typeof argumentsValue.content === \"string\") {\n\t\t\tthis.pendingFileChanges.set(id, {\n\t\t\t\trole: \"file_change\",\n\t\t\t\tid,\n\t\t\t\tpath,\n\t\t\t\tkind: \"write\",\n\t\t\t\tremoved: [],\n\t\t\t\tadded: argumentsValue.content.replaceAll(\"\\r\\n\", \"\\n\").split(\"\\n\"),\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate commitFileChange(id: string, isError: boolean, details: unknown = undefined): void {\n\t\tconst change = this.pendingFileChanges.get(id);\n\t\tthis.pendingFileChanges.delete(id);\n\t\tif (!change || isError) return;\n\t\tconst metadata = isEditDetails(details) ? details : undefined;\n\t\tthis.messageItems.push(\n\t\t\tmetadata ? { ...change, diff: metadata.diff, firstChangedLine: metadata.firstChangedLine } : change,\n\t\t);\n\t}\n}\n\nfunction parseEditArguments(argumentsValue: Record<string, unknown>): Edit[] | undefined {\n\tif (Array.isArray(argumentsValue.edits)) {\n\t\tconst edits: Edit[] = [];\n\t\tfor (const value of argumentsValue.edits) {\n\t\t\tif (!isRecord(value) || typeof value.oldText !== \"string\" || typeof value.newText !== \"string\") return undefined;\n\t\t\tedits.push({ oldText: value.oldText, newText: value.newText });\n\t\t}\n\t\treturn edits.length > 0 ? edits : undefined;\n\t}\n\treturn typeof argumentsValue.oldText === \"string\" && typeof argumentsValue.newText === \"string\"\n\t\t? [{ oldText: argumentsValue.oldText, newText: argumentsValue.newText }]\n\t\t: undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction isEditDetails(value: unknown): value is { diff: string; firstChangedLine?: number } {\n\treturn (\n\t\tisRecord(value) &&\n\t\ttypeof value.diff === \"string\" &&\n\t\t(value.firstChangedLine === undefined || typeof value.firstChangedLine === \"number\")\n\t);\n}\n\nfunction formatToolCommand(toolName: string, argumentsValue: Record<string, unknown>): string {\n\tconst serialized = JSON.stringify(argumentsValue);\n\treturn serialized === \"{}\" ? toolName : `${toolName} ${serialized}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"interactive-state.js","sourceRoot":"","sources":["../../src/modes/interactive-state.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAa,MAAM,4BAA4B,CAAC;AA0CzE,SAAS,MAAM,CAAC,OAAgB;IAE/B,OAAO,OAAO,CAAC,OAAO;SACpB,MAAM,CAAC,CAAC,OAAO,EAAwB,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC;SAClE,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;SAC9B,IAAI,CAAC,EAAE,CAAC,CAAC;AACZ,CAAC;AAED,MAAM,OAAO,qBAAqB;IAChB,QAAQ,GAAa,EAAE,CAAC;IACxB,YAAY,GAAyB,EAAE,CAAC;IACxC,kBAAkB,GAAG,IAAI,GAAG,EAA+B,CAAC;IAC5D,YAAY,GAA6B,EAAE,CAAC;IAC5C,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAChD,YAAY,GAAG,CAAC,CAAC;IACjB,aAAa,GAAG,EAAE,CAAC;IACnB,IAAI,GAAG,KAAK,CAAC;IACb,KAAK,CAAqB;IAC1B,KAAK,GAAa,EAAE,CAAC;IACrB,MAAM,CAAqB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AAK,SAAS,IAAI,OAAO,KAAK,CAAC,gBAAgB,KAAK,QAAQ,CAAC,CACpF,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,QAAgB,EAAE,cAAuC;IACnF,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAClD,OAAO,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,UAAU,EAAE,CAAC;AACrE,CAAC","sourcesContent":["import type { Message } from \"@di-code/ai\";\nimport type { AgentSessionEvent, SessionUsage } from \"../core/session.ts\";\nimport { computeEditsDiff, type Edit } from \"../core/tools/edit-diff.ts\";\n\nexport type InteractiveMessage =\n\t| { readonly role: \"user\" | \"assistant\"; readonly text: string }\n\t| {\n\t\t\treadonly role: \"file_change\";\n\t\t\treadonly id: string;\n\t\t\treadonly path: string;\n\t\t\treadonly kind: \"edit\" | \"write\";\n\t\t\treadonly removed: readonly string[];\n\t\t\treadonly added: readonly string[];\n\t\t\treadonly diff?: string;\n\t\t\treadonly firstChangedLine?: number;\n\t };\n\ntype FileChangeCandidate = Extract<InteractiveMessage, { role: \"file_change\" }>;\n\nexport type InteractiveProcessItem =\n\t| { readonly type: \"thinking\"; readonly id: \"thinking\" }\n\t| {\n\t\t\treadonly type: \"tool\";\n\t\t\treadonly id: string;\n\t\t\treadonly command: string;\n\t\t\treadonly status: \"running\" | \"done\" | \"error\";\n\t };\n\nexport interface InteractiveState {\n\treadonly messages: readonly string[];\n\treadonly messageItems: readonly InteractiveMessage[];\n\treadonly processItems: readonly InteractiveProcessItem[];\n\treadonly spinnerFrame: number;\n\treadonly streamingText: string;\n\treadonly toolStatus: readonly string[];\n\treadonly busy: boolean;\n\treadonly error?: string;\n\treadonly queue: readonly string[];\n\treadonly status?: string;\n\treadonly compacting: boolean;\n\treadonly retrying: boolean;\n\treadonly usage: SessionUsage;\n}\n\nfunction textOf(message: Message): string {\n\ttype TextBlock = Extract<Message[\"content\"][number], { type: \"text\" }>;\n\treturn message.content\n\t\t.filter((content): content is TextBlock => content.type === \"text\")\n\t\t.map((content) => content.text)\n\t\t.join(\"\");\n}\n\nexport class InteractiveProjection {\n\tprivate readonly messages: string[] = [];\n\tprivate readonly messageItems: InteractiveMessage[] = [];\n\tprivate readonly pendingFileChanges = new Map<string, FileChangeCandidate>();\n\tprivate readonly processItems: InteractiveProcessItem[] = [];\n\tprivate readonly toolStatus = new Map<string, string>();\n\tprivate spinnerFrame = 0;\n\tprivate streamingText = \"\";\n\tprivate busy = false;\n\tprivate error: string | undefined;\n\tprivate queue: string[] = [];\n\tprivate status: string | undefined;\n\tprivate compacting = false;\n\tprivate retrying = false;\n\tprivate previewRoot: string | undefined;\n\tprivate previewChange: (() => void) | undefined;\n\tprivate usage: SessionUsage = {\n\t\trequestCount: 0,\n\t\tinputTokens: 0,\n\t\toutputTokens: 0,\n\t\tcacheReadTokens: 0,\n\t\tcacheWriteTokens: 0,\n\t\ttotalTokens: 0,\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\testimatedContextTokens: 0,\n\t\tcontextWindow: 0,\n\t\treserveTokens: 0,\n\t\ttriggerTokens: 0,\n\t};\n\n\tget state(): InteractiveState {\n\t\tconst visibleMessageItems = [...this.messageItems, ...this.pendingFileChanges.values()];\n\t\treturn {\n\t\t\tmessages: [...this.messages],\n\t\t\tmessageItems: visibleMessageItems.map((message) =>\n\t\t\t\tmessage.role === \"file_change\"\n\t\t\t\t\t? { ...message, removed: [...message.removed], added: [...message.added] }\n\t\t\t\t\t: { ...message },\n\t\t\t),\n\t\t\tprocessItems: this.processItems.map((item) => ({ ...item })),\n\t\t\tspinnerFrame: this.spinnerFrame,\n\t\t\tstreamingText: this.streamingText,\n\t\t\ttoolStatus: [...this.toolStatus.values()],\n\t\t\tbusy: this.busy,\n\t\t\terror: this.error,\n\t\t\tqueue: [...this.queue],\n\t\t\tstatus: this.status,\n\t\t\tcompacting: this.compacting,\n\t\t\tretrying: this.retrying,\n\t\t\tusage: { ...this.usage, cost: { ...this.usage.cost } },\n\t\t};\n\t}\n\n\tsetError(message: string | undefined): void {\n\t\tthis.error = message;\n\t}\n\n\tclearVisibleMessages(): void {\n\t\tthis.messages.length = 0;\n\t\tthis.messageItems.length = 0;\n\t\tthis.pendingFileChanges.clear();\n\t\tthis.streamingText = \"\";\n\t\tthis.processItems.length = 0;\n\t\tthis.toolStatus.clear();\n\t\tthis.error = undefined;\n\t}\n\n\tsetQueue(queue: readonly string[]): void {\n\t\tthis.queue = [...queue];\n\t}\n\n\tsetStatus(status: string | undefined): void {\n\t\tthis.status = status;\n\t}\n\n\tsetCompacting(value: boolean): void {\n\t\tthis.compacting = value;\n\t}\n\n\tsetRetrying(value: boolean): void {\n\t\tthis.retrying = value;\n\t}\n\n\tsetUsage(usage: SessionUsage): void {\n\t\tthis.usage = structuredClone(usage);\n\t}\n\n\tconfigureFilePreview(root: string, onChange: () => void): void {\n\t\tthis.previewRoot = root;\n\t\tthis.previewChange = onChange;\n\t}\n\n\tadvanceSpinner(): boolean {\n\t\tif (!this.busy) return false;\n\t\tthis.spinnerFrame = (this.spinnerFrame + 1) % 4;\n\t\treturn true;\n\t}\n\n\tclearTransientProcess(): void {\n\t\tthis.processItems.length = 0;\n\t\tthis.toolStatus.clear();\n\t\tthis.spinnerFrame = 0;\n\t}\n\n\treplaceTranscript(messages: readonly Message[]): void {\n\t\tthis.messages.length = 0;\n\t\tthis.messageItems.length = 0;\n\t\tthis.pendingFileChanges.clear();\n\t\tthis.processItems.length = 0;\n\t\tthis.toolStatus.clear();\n\t\tthis.spinnerFrame = 0;\n\t\tthis.streamingText = \"\";\n\t\tthis.busy = false;\n\t\tthis.error = undefined;\n\t\tfor (const message of messages) this.appendCompletedMessage(message);\n\t}\n\n\tapply(event: AgentSessionEvent): void {\n\t\tswitch (event.type) {\n\t\t\tcase \"agent_start\":\n\t\t\t\tthis.busy = true;\n\t\t\t\tthis.error = undefined;\n\t\t\t\tthis.retrying = false;\n\t\t\t\tthis.processItems.length = 0;\n\t\t\t\tthis.processItems.push({ type: \"thinking\", id: \"thinking\" });\n\t\t\t\tthis.toolStatus.clear();\n\t\t\t\tthis.spinnerFrame = 0;\n\t\t\t\treturn;\n\t\t\tcase \"compaction_start\":\n\t\t\t\tthis.compacting = true;\n\t\t\t\treturn;\n\t\t\tcase \"compaction_end\":\n\t\t\t\tthis.compacting = false;\n\t\t\t\tif (!event.success) this.error = event.errorMessage;\n\t\t\t\treturn;\n\t\t\tcase \"usage_update\":\n\t\t\t\tthis.setUsage(event.usage);\n\t\t\t\treturn;\n\t\t\tcase \"queue_update\":\n\t\t\tcase \"tree_navigated\":\n\t\t\t\treturn;\n\t\t\tcase \"message_start\":\n\t\t\t\tif (event.message.role === \"assistant\") this.streamingText = \"\";\n\t\t\t\treturn;\n\t\t\tcase \"message_update\":\n\t\t\t\tif (event.event.type === \"text_delta\") {\n\t\t\t\t\tif (event.event.delta.length > 0) this.removeThinking();\n\t\t\t\t\tthis.streamingText += event.event.delta;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\tcase \"tool_execution_start\":\n\t\t\t\tthis.removeThinking();\n\t\t\t\tthis.processItems.push({\n\t\t\t\t\ttype: \"tool\",\n\t\t\t\t\tid: event.toolCallId,\n\t\t\t\t\tcommand: formatToolCommand(event.toolName, event.arguments),\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t});\n\t\t\t\tthis.toolStatus.set(event.toolCallId, `${event.toolName}: running`);\n\t\t\t\tthis.storeFileChange(event.toolCallId, event.toolName, event.arguments);\n\t\t\t\treturn;\n\t\t\tcase \"tool_execution_end\":\n\t\t\t\tthis.updateToolStatus(event.toolCallId, event.result.isError ? \"error\" : \"done\");\n\t\t\t\tthis.toolStatus.set(event.toolCallId, `${event.toolName}: ${event.result.isError ? \"error\" : \"done\"}`);\n\t\t\t\tthis.commitFileChange(event.toolCallId, event.result.isError, event.result.details);\n\t\t\t\treturn;\n\t\t\tcase \"message_end\":\n\t\t\t\tthis.appendCompletedMessage(event.message);\n\t\t\t\treturn;\n\t\t\tcase \"agent_end\":\n\t\t\t\tthis.busy = false;\n\t\t\t\tthis.retrying = false;\n\t\t\t\tthis.pendingFileChanges.clear();\n\t\t\t\tthis.processItems.length = 0;\n\t\t\t\tthis.toolStatus.clear();\n\t\t\t\tthis.spinnerFrame = 0;\n\t\t\t\treturn;\n\t\t\tcase \"turn_start\":\n\t\t\t\tif (this.busy && !this.processItems.some((item) => item.type === \"thinking\")) {\n\t\t\t\t\tthis.processItems.push({ type: \"thinking\", id: \"thinking\" });\n\t\t\t\t\tthis.spinnerFrame = 0;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\tcase \"turn_end\":\n\t\t\t\treturn;\n\t\t}\n\t}\n\n\tprivate removeThinking(): void {\n\t\tconst index = this.processItems.findIndex((item) => item.type === \"thinking\");\n\t\tif (index >= 0) this.processItems.splice(index, 1);\n\t}\n\n\tprivate updateToolStatus(id: string, status: \"done\" | \"error\"): void {\n\t\tconst index = this.processItems.findIndex((item) => item.type === \"tool\" && item.id === id);\n\t\tconst item = this.processItems[index];\n\t\tif (index < 0 || item?.type !== \"tool\") return;\n\t\tthis.processItems[index] = { ...item, status };\n\t}\n\n\tprivate appendCompletedMessage(message: Message): void {\n\t\tif (message.role === \"tool_result\") {\n\t\t\tthis.commitFileChange(message.toolCallId, message.isError, message.details);\n\t\t\treturn;\n\t\t}\n\t\tconst text = textOf(message);\n\t\tif (message.role === \"user\") {\n\t\t\tif (text.length > 0) {\n\t\t\t\tthis.messages.push(text);\n\t\t\t\tthis.messageItems.push({ role: \"user\", text });\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (text.length > 0 && message.stopReason !== \"tool_use\") {\n\t\t\tthis.messages.push(text);\n\t\t\tthis.messageItems.push({ role: \"assistant\", text });\n\t\t}\n\t\tfor (const content of message.content) {\n\t\t\tif (content.type === \"tool_call\") this.storeFileChange(content.id, content.name, content.arguments);\n\t\t}\n\t\tif (message.stopReason === \"error\") this.error = message.errorMessage;\n\t\tthis.streamingText = \"\";\n\t}\n\n\tprivate storeFileChange(id: string, toolName: string, argumentsValue: Record<string, unknown>): void {\n\t\tconst path = argumentsValue.path;\n\t\tif (typeof path !== \"string\") return;\n\t\tif (toolName === \"edit\") {\n\t\t\tconst edits = parseEditArguments(argumentsValue);\n\t\t\tif (!edits) return;\n\t\t\tconst fallback = edits.flatMap((edit) => ({\n\t\t\t\tremoved: edit.oldText.replaceAll(\"\\r\\n\", \"\\n\").split(\"\\n\"),\n\t\t\t\tadded: edit.newText.replaceAll(\"\\r\\n\", \"\\n\").split(\"\\n\"),\n\t\t\t}));\n\t\t\tthis.pendingFileChanges.set(id, {\n\t\t\t\trole: \"file_change\",\n\t\t\t\tid,\n\t\t\t\tpath,\n\t\t\t\tkind: \"edit\",\n\t\t\t\tremoved: fallback.flatMap((edit) => edit.removed),\n\t\t\t\tadded: fallback.flatMap((edit) => edit.added),\n\t\t\t});\n\t\t\tif (this.previewRoot) {\n\t\t\t\tvoid computeEditsDiff(path, edits, this.previewRoot).then((preview) => {\n\t\t\t\t\tconst current = this.pendingFileChanges.get(id);\n\t\t\t\t\tif (!current || \"error\" in preview) return;\n\t\t\t\t\tthis.pendingFileChanges.set(id, {\n\t\t\t\t\t\t...current,\n\t\t\t\t\t\tdiff: preview.diff,\n\t\t\t\t\t\tfirstChangedLine: preview.firstChangedLine,\n\t\t\t\t\t});\n\t\t\t\t\tthis.previewChange?.();\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tif (toolName === \"write\" && typeof argumentsValue.content === \"string\") {\n\t\t\tthis.pendingFileChanges.set(id, {\n\t\t\t\trole: \"file_change\",\n\t\t\t\tid,\n\t\t\t\tpath,\n\t\t\t\tkind: \"write\",\n\t\t\t\tremoved: [],\n\t\t\t\tadded: argumentsValue.content.replaceAll(\"\\r\\n\", \"\\n\").split(\"\\n\"),\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate commitFileChange(id: string, isError: boolean, details: unknown = undefined): void {\n\t\tconst change = this.pendingFileChanges.get(id);\n\t\tthis.pendingFileChanges.delete(id);\n\t\tif (!change || isError) return;\n\t\tconst metadata = isEditDetails(details) ? details : undefined;\n\t\tthis.messageItems.push(\n\t\t\tmetadata ? { ...change, diff: metadata.diff, firstChangedLine: metadata.firstChangedLine } : change,\n\t\t);\n\t}\n}\n\nfunction parseEditArguments(argumentsValue: Record<string, unknown>): Edit[] | undefined {\n\tif (Array.isArray(argumentsValue.edits)) {\n\t\tconst edits: Edit[] = [];\n\t\tfor (const value of argumentsValue.edits) {\n\t\t\tif (!isRecord(value) || typeof value.oldText !== \"string\" || typeof value.newText !== \"string\") return undefined;\n\t\t\tedits.push({ oldText: value.oldText, newText: value.newText });\n\t\t}\n\t\treturn edits.length > 0 ? edits : undefined;\n\t}\n\treturn typeof argumentsValue.oldText === \"string\" && typeof argumentsValue.newText === \"string\"\n\t\t? [{ oldText: argumentsValue.oldText, newText: argumentsValue.newText }]\n\t\t: undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction isEditDetails(value: unknown): value is { diff: string; firstChangedLine?: number } {\n\treturn (\n\t\tisRecord(value) &&\n\t\ttypeof value.diff === \"string\" &&\n\t\t(value.firstChangedLine === undefined || typeof value.firstChangedLine === \"number\")\n\t);\n}\n\nfunction formatToolCommand(toolName: string, argumentsValue: Record<string, unknown>): string {\n\tconst serialized = JSON.stringify(argumentsValue);\n\treturn serialized === \"{}\" ? toolName : `${toolName} ${serialized}`;\n}\n"]}
|