@f5-sales-demo/xcsh 19.51.2
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/CHANGELOG.md +7073 -0
- package/README.md +14 -0
- package/examples/README.md +21 -0
- package/examples/custom-tools/README.md +109 -0
- package/examples/custom-tools/hello/index.ts +20 -0
- package/examples/custom-tools/todo/index.ts +206 -0
- package/examples/extensions/README.md +143 -0
- package/examples/extensions/api-demo.ts +89 -0
- package/examples/extensions/chalk-logger.ts +25 -0
- package/examples/extensions/hello.ts +32 -0
- package/examples/extensions/pirate.ts +43 -0
- package/examples/extensions/plan-mode.ts +551 -0
- package/examples/extensions/reload-runtime.ts +37 -0
- package/examples/extensions/todo.ts +296 -0
- package/examples/extensions/tools.ts +145 -0
- package/examples/extensions/with-deps/index.ts +36 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +16 -0
- package/examples/hooks/README.md +56 -0
- package/examples/hooks/auto-commit-on-exit.ts +48 -0
- package/examples/hooks/confirm-destructive.ts +58 -0
- package/examples/hooks/custom-compaction.ts +115 -0
- package/examples/hooks/dirty-repo-guard.ts +51 -0
- package/examples/hooks/file-trigger.ts +40 -0
- package/examples/hooks/git-checkpoint.ts +52 -0
- package/examples/hooks/handoff.ts +149 -0
- package/examples/hooks/permission-gate.ts +33 -0
- package/examples/hooks/protected-paths.ts +29 -0
- package/examples/hooks/qna.ts +118 -0
- package/examples/hooks/status-line.ts +39 -0
- package/examples/sdk/01-minimal.ts +21 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +43 -0
- package/examples/sdk/04-skills.ts +43 -0
- package/examples/sdk/06-extensions.ts +80 -0
- package/examples/sdk/06-hooks.ts +61 -0
- package/examples/sdk/07-context-files.ts +35 -0
- package/examples/sdk/08-prompt-templates.ts +41 -0
- package/examples/sdk/08-slash-commands.ts +46 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +54 -0
- package/examples/sdk/11-sessions.ts +47 -0
- package/examples/sdk/README.md +172 -0
- package/package.json +539 -0
- package/scripts/build-info/resolvers.ts +51 -0
- package/scripts/capture-ax-fixture.ts +84 -0
- package/scripts/capture-login-fixture.ts +30 -0
- package/scripts/check-workflow-field-coverage.ts +101 -0
- package/scripts/extension-uat-harness.ts +340 -0
- package/scripts/format-prompts.ts +68 -0
- package/scripts/generate-api-spec-index.ts +580 -0
- package/scripts/generate-branding-index.ts +81 -0
- package/scripts/generate-build-info.ts +106 -0
- package/scripts/generate-console-catalog.ts +88 -0
- package/scripts/generate-console-field-metadata.ts +74 -0
- package/scripts/generate-docs-index.ts +40 -0
- package/scripts/generate-template.ts +32 -0
- package/scripts/generate-terraform-index.ts +81 -0
- package/scripts/mermaid-gallery.ts +132 -0
- package/scripts/uat-matrix-modalities.ts +451 -0
- package/scripts/uat-matrix-report.ts +175 -0
- package/scripts/uat-matrix.ts +353 -0
- package/src/async/index.ts +2 -0
- package/src/async/job-manager.ts +416 -0
- package/src/async/support.ts +5 -0
- package/src/autoresearch/apply-contract-to-state.ts +1 -0
- package/src/autoresearch/command-resume.md +17 -0
- package/src/autoresearch/contract.ts +205 -0
- package/src/autoresearch/dashboard.ts +374 -0
- package/src/autoresearch/git.ts +191 -0
- package/src/autoresearch/helpers.ts +328 -0
- package/src/autoresearch/index.ts +402 -0
- package/src/autoresearch/prompt.md +236 -0
- package/src/autoresearch/resume-message.md +16 -0
- package/src/autoresearch/state.ts +303 -0
- package/src/autoresearch/tools/init-experiment.ts +400 -0
- package/src/autoresearch/tools/log-experiment.ts +793 -0
- package/src/autoresearch/tools/run-experiment.ts +679 -0
- package/src/autoresearch/types.ts +114 -0
- package/src/browser/acquire.ts +249 -0
- package/src/browser/actions.ts +126 -0
- package/src/browser/auth.ts +176 -0
- package/src/browser/ax.ts +134 -0
- package/src/browser/cdp-core.ts +45 -0
- package/src/browser/cdp-page-actions.ts +51 -0
- package/src/browser/chrome-locate.ts +66 -0
- package/src/browser/dom-context.ts +89 -0
- package/src/browser/dt-context.ts +100 -0
- package/src/browser/extension-bridge.ts +182 -0
- package/src/browser/extension-page-actions.ts +397 -0
- package/src/browser/extension-provider.ts +373 -0
- package/src/browser/index.ts +17 -0
- package/src/browser/input-commit.ts +74 -0
- package/src/browser/native-messaging.ts +20 -0
- package/src/browser/page-actions.ts +18 -0
- package/src/browser/provider.ts +155 -0
- package/src/browser/resolver.ts +126 -0
- package/src/browser/selector.ts +40 -0
- package/src/bun-imports.d.ts +22 -0
- package/src/capability/context-file.ts +43 -0
- package/src/capability/extension-module.ts +34 -0
- package/src/capability/extension.ts +47 -0
- package/src/capability/fs.ts +107 -0
- package/src/capability/hook.ts +40 -0
- package/src/capability/index.ts +438 -0
- package/src/capability/instruction.ts +37 -0
- package/src/capability/mcp.ts +74 -0
- package/src/capability/prompt.ts +35 -0
- package/src/capability/rule.ts +224 -0
- package/src/capability/settings.ts +34 -0
- package/src/capability/skill.ts +50 -0
- package/src/capability/slash-command.ts +40 -0
- package/src/capability/ssh.ts +41 -0
- package/src/capability/system-prompt.ts +34 -0
- package/src/capability/tool.ts +38 -0
- package/src/capability/types.ts +168 -0
- package/src/cli/agents-cli.ts +138 -0
- package/src/cli/args.ts +286 -0
- package/src/cli/chrome-cli.ts +88 -0
- package/src/cli/classify-install-target.ts +50 -0
- package/src/cli/commands/init-xdg.ts +27 -0
- package/src/cli/config-cli.ts +418 -0
- package/src/cli/file-processor.ts +121 -0
- package/src/cli/grep-cli.ts +160 -0
- package/src/cli/grievances-cli.ts +78 -0
- package/src/cli/initial-message.ts +58 -0
- package/src/cli/jupyter-cli.ts +106 -0
- package/src/cli/list-models.ts +128 -0
- package/src/cli/plugin-cli.ts +964 -0
- package/src/cli/read-cli.ts +68 -0
- package/src/cli/session-picker.ts +52 -0
- package/src/cli/setup-cli.ts +479 -0
- package/src/cli/shell-cli.ts +174 -0
- package/src/cli/ssh-cli.ts +179 -0
- package/src/cli/stats-cli.ts +182 -0
- package/src/cli/update-cli.ts +446 -0
- package/src/cli/web-search-cli.ts +203 -0
- package/src/cli.ts +123 -0
- package/src/commands/agents.ts +57 -0
- package/src/commands/chrome-host.ts +71 -0
- package/src/commands/chrome.ts +28 -0
- package/src/commands/commit.ts +36 -0
- package/src/commands/config.ts +51 -0
- package/src/commands/grep.ts +48 -0
- package/src/commands/grievances.ts +20 -0
- package/src/commands/jupyter.ts +32 -0
- package/src/commands/launch.ts +144 -0
- package/src/commands/plugin.ts +78 -0
- package/src/commands/read.ts +33 -0
- package/src/commands/setup.ts +42 -0
- package/src/commands/shell.ts +29 -0
- package/src/commands/ssh.ts +60 -0
- package/src/commands/stats.ts +29 -0
- package/src/commands/update.ts +21 -0
- package/src/commands/web-search.ts +46 -0
- package/src/commit/agentic/agent.ts +314 -0
- package/src/commit/agentic/fallback.ts +96 -0
- package/src/commit/agentic/index.ts +354 -0
- package/src/commit/agentic/prompts/analyze-file.md +22 -0
- package/src/commit/agentic/prompts/session-user.md +25 -0
- package/src/commit/agentic/prompts/split-confirm.md +1 -0
- package/src/commit/agentic/prompts/system.md +38 -0
- package/src/commit/agentic/state.ts +60 -0
- package/src/commit/agentic/tools/analyze-file.ts +127 -0
- package/src/commit/agentic/tools/git-file-diff.ts +191 -0
- package/src/commit/agentic/tools/git-hunk.ts +50 -0
- package/src/commit/agentic/tools/git-overview.ts +81 -0
- package/src/commit/agentic/tools/index.ts +54 -0
- package/src/commit/agentic/tools/propose-changelog.ts +139 -0
- package/src/commit/agentic/tools/propose-commit.ts +122 -0
- package/src/commit/agentic/tools/recent-commits.ts +81 -0
- package/src/commit/agentic/tools/schemas.ts +31 -0
- package/src/commit/agentic/tools/split-commit.ts +251 -0
- package/src/commit/agentic/topo-sort.ts +44 -0
- package/src/commit/agentic/trivial.ts +51 -0
- package/src/commit/agentic/validation.ts +183 -0
- package/src/commit/analysis/conventional.ts +122 -0
- package/src/commit/analysis/index.ts +4 -0
- package/src/commit/analysis/scope.ts +242 -0
- package/src/commit/analysis/summary.ts +105 -0
- package/src/commit/analysis/validation.ts +66 -0
- package/src/commit/changelog/detect.ts +40 -0
- package/src/commit/changelog/generate.ts +101 -0
- package/src/commit/changelog/index.ts +234 -0
- package/src/commit/changelog/parse.ts +44 -0
- package/src/commit/cli.ts +85 -0
- package/src/commit/git/diff.ts +148 -0
- package/src/commit/index.ts +5 -0
- package/src/commit/map-reduce/index.ts +69 -0
- package/src/commit/map-reduce/map-phase.ts +193 -0
- package/src/commit/map-reduce/reduce-phase.ts +108 -0
- package/src/commit/map-reduce/utils.ts +9 -0
- package/src/commit/message.ts +11 -0
- package/src/commit/model-selection.ts +66 -0
- package/src/commit/pipeline.ts +242 -0
- package/src/commit/prompts/analysis-system.md +148 -0
- package/src/commit/prompts/analysis-user.md +38 -0
- package/src/commit/prompts/changelog-system.md +50 -0
- package/src/commit/prompts/changelog-user.md +18 -0
- package/src/commit/prompts/file-observer-system.md +24 -0
- package/src/commit/prompts/file-observer-user.md +8 -0
- package/src/commit/prompts/reduce-system.md +50 -0
- package/src/commit/prompts/reduce-user.md +17 -0
- package/src/commit/prompts/summary-retry.md +3 -0
- package/src/commit/prompts/summary-system.md +38 -0
- package/src/commit/prompts/summary-user.md +13 -0
- package/src/commit/prompts/types-description.md +2 -0
- package/src/commit/types.ts +118 -0
- package/src/commit/utils/exclusions.ts +42 -0
- package/src/commit/utils.ts +44 -0
- package/src/config/auto-config.ts +698 -0
- package/src/config/context-schema.json +115 -0
- package/src/config/file-lock.ts +121 -0
- package/src/config/keybindings.ts +493 -0
- package/src/config/mcp-schema.json +230 -0
- package/src/config/model-equivalence.ts +675 -0
- package/src/config/model-registry.ts +2265 -0
- package/src/config/model-resolver.ts +1289 -0
- package/src/config/prompt-templates.ts +271 -0
- package/src/config/resolve-config-value.ts +110 -0
- package/src/config/settings-schema.ts +2155 -0
- package/src/config/settings.ts +730 -0
- package/src/config.ts +418 -0
- package/src/cursor.ts +323 -0
- package/src/dap/client.ts +674 -0
- package/src/dap/config.ts +150 -0
- package/src/dap/defaults.json +211 -0
- package/src/dap/index.ts +4 -0
- package/src/dap/session.ts +1255 -0
- package/src/dap/types.ts +600 -0
- package/src/debug/index.ts +440 -0
- package/src/debug/log-formatting.ts +58 -0
- package/src/debug/log-viewer.ts +908 -0
- package/src/debug/profiler.ts +158 -0
- package/src/debug/report-bundle.ts +365 -0
- package/src/debug/system-info.ts +107 -0
- package/src/discovery/agents-md.ts +67 -0
- package/src/discovery/agents.ts +219 -0
- package/src/discovery/builtin.ts +851 -0
- package/src/discovery/claude-plugins.ts +297 -0
- package/src/discovery/claude.ts +543 -0
- package/src/discovery/cline.ts +83 -0
- package/src/discovery/codex.ts +535 -0
- package/src/discovery/cursor.ts +220 -0
- package/src/discovery/gemini.ts +396 -0
- package/src/discovery/github.ts +118 -0
- package/src/discovery/helpers.ts +934 -0
- package/src/discovery/index.ts +79 -0
- package/src/discovery/language.ts +46 -0
- package/src/discovery/mcp-json.ts +171 -0
- package/src/discovery/opencode.ts +393 -0
- package/src/discovery/plugin-dir-roots.ts +28 -0
- package/src/discovery/ssh.ts +153 -0
- package/src/discovery/substitute-plugin-root.ts +29 -0
- package/src/discovery/vscode.ts +105 -0
- package/src/discovery/windsurf.ts +147 -0
- package/src/edit/diff.ts +818 -0
- package/src/edit/index.ts +481 -0
- package/src/edit/line-hash.ts +67 -0
- package/src/edit/modes/chunk.ts +762 -0
- package/src/edit/modes/hashline.ts +1366 -0
- package/src/edit/modes/patch.ts +1791 -0
- package/src/edit/modes/replace.ts +1115 -0
- package/src/edit/normalize.ts +375 -0
- package/src/edit/renderer.ts +627 -0
- package/src/exa/factory.ts +61 -0
- package/src/exa/index.ts +27 -0
- package/src/exa/mcp-client.ts +293 -0
- package/src/exa/render.ts +232 -0
- package/src/exa/researcher.ts +47 -0
- package/src/exa/search.ts +86 -0
- package/src/exa/types.ts +166 -0
- package/src/exa/websets.ts +247 -0
- package/src/exec/bash-executor.ts +332 -0
- package/src/exec/exec.ts +53 -0
- package/src/exec/idle-timeout-watchdog.ts +126 -0
- package/src/exec/non-interactive-env.ts +48 -0
- package/src/export/custom-share.ts +65 -0
- package/src/export/html/index.ts +161 -0
- package/src/export/html/template.css +1001 -0
- package/src/export/html/template.generated.ts +2 -0
- package/src/export/html/template.html +46 -0
- package/src/export/html/template.js +1950 -0
- package/src/export/html/template.macro.ts +24 -0
- package/src/export/html/vendor/highlight.min.js +1213 -0
- package/src/export/html/vendor/marked.min.js +6 -0
- package/src/export/ttsr.ts +434 -0
- package/src/extensibility/custom-commands/bundled/ci-green/index.ts +25 -0
- package/src/extensibility/custom-commands/bundled/review/index.ts +456 -0
- package/src/extensibility/custom-commands/index.ts +2 -0
- package/src/extensibility/custom-commands/loader.ts +236 -0
- package/src/extensibility/custom-commands/types.ts +111 -0
- package/src/extensibility/custom-tools/index.ts +7 -0
- package/src/extensibility/custom-tools/loader.ts +238 -0
- package/src/extensibility/custom-tools/types.ts +251 -0
- package/src/extensibility/custom-tools/wrapper.ts +47 -0
- package/src/extensibility/extensions/index.ts +15 -0
- package/src/extensibility/extensions/loader.ts +572 -0
- package/src/extensibility/extensions/runner.ts +848 -0
- package/src/extensibility/extensions/types.ts +1394 -0
- package/src/extensibility/extensions/wrapper.ts +191 -0
- package/src/extensibility/hooks/index.ts +5 -0
- package/src/extensibility/hooks/loader.ts +255 -0
- package/src/extensibility/hooks/runner.ts +425 -0
- package/src/extensibility/hooks/tool-wrapper.ts +108 -0
- package/src/extensibility/hooks/types.ts +826 -0
- package/src/extensibility/plugins/doctor.ts +66 -0
- package/src/extensibility/plugins/git-url.ts +281 -0
- package/src/extensibility/plugins/index.ts +9 -0
- package/src/extensibility/plugins/installer.ts +192 -0
- package/src/extensibility/plugins/loader.ts +267 -0
- package/src/extensibility/plugins/manager.ts +731 -0
- package/src/extensibility/plugins/marketplace/cache.ts +136 -0
- package/src/extensibility/plugins/marketplace/fetcher.ts +318 -0
- package/src/extensibility/plugins/marketplace/index.ts +6 -0
- package/src/extensibility/plugins/marketplace/manager.ts +781 -0
- package/src/extensibility/plugins/marketplace/prerequisites.ts +255 -0
- package/src/extensibility/plugins/marketplace/registry.ts +196 -0
- package/src/extensibility/plugins/marketplace/source-resolver.ts +147 -0
- package/src/extensibility/plugins/marketplace/types.ts +201 -0
- package/src/extensibility/plugins/parser.ts +105 -0
- package/src/extensibility/plugins/types.ts +194 -0
- package/src/extensibility/skills.ts +269 -0
- package/src/extensibility/slash-commands.ts +246 -0
- package/src/extensibility/tool-proxy.ts +25 -0
- package/src/extensibility/utils.ts +38 -0
- package/src/index.ts +61 -0
- package/src/internal-urls/agent-protocol.ts +136 -0
- package/src/internal-urls/api-catalog-resolve.ts +495 -0
- package/src/internal-urls/api-catalog-types.ts +94 -0
- package/src/internal-urls/api-spec-resolve.ts +1036 -0
- package/src/internal-urls/api-spec-types.ts +239 -0
- package/src/internal-urls/artifact-protocol.ts +97 -0
- package/src/internal-urls/branding-index.generated.ts +88 -0
- package/src/internal-urls/build-info-runtime.ts +302 -0
- package/src/internal-urls/build-info.generated.ts +33 -0
- package/src/internal-urls/computer-profile.ts +692 -0
- package/src/internal-urls/console-catalog-types.ts +21 -0
- package/src/internal-urls/console-catalog.generated.ts +532 -0
- package/src/internal-urls/console-field-metadata-types.ts +59 -0
- package/src/internal-urls/console-field-metadata.generated.ts +4841 -0
- package/src/internal-urls/console-resolve.ts +178 -0
- package/src/internal-urls/docs-index.generated.ts +698 -0
- package/src/internal-urls/extension-api.md +147 -0
- package/src/internal-urls/index.ts +46 -0
- package/src/internal-urls/jobs-protocol.ts +119 -0
- package/src/internal-urls/json-query.ts +126 -0
- package/src/internal-urls/local-protocol.ts +206 -0
- package/src/internal-urls/mcp-protocol.ts +156 -0
- package/src/internal-urls/memory-protocol.ts +133 -0
- package/src/internal-urls/parse.ts +72 -0
- package/src/internal-urls/profile-collectors.ts +106 -0
- package/src/internal-urls/router.ts +55 -0
- package/src/internal-urls/rule-protocol.ts +55 -0
- package/src/internal-urls/skill-protocol.ts +111 -0
- package/src/internal-urls/terraform-index.generated.ts +1852 -0
- package/src/internal-urls/terraform-resolve.ts +184 -0
- package/src/internal-urls/terraform-types.ts +45 -0
- package/src/internal-urls/types.ts +52 -0
- package/src/internal-urls/user-profile.ts +363 -0
- package/src/internal-urls/xcsh-protocol.ts +644 -0
- package/src/ipy/cancellation.ts +28 -0
- package/src/ipy/executor.ts +1155 -0
- package/src/ipy/gateway-coordinator.ts +424 -0
- package/src/ipy/kernel.ts +1091 -0
- package/src/ipy/modules.ts +144 -0
- package/src/ipy/prelude.py +849 -0
- package/src/ipy/prelude.ts +3 -0
- package/src/ipy/runtime.ts +221 -0
- package/src/locales/ar.json +512 -0
- package/src/locales/de.json +512 -0
- package/src/locales/en.json +549 -0
- package/src/locales/es.json +512 -0
- package/src/locales/fr.json +512 -0
- package/src/locales/hi.json +512 -0
- package/src/locales/index.ts +29 -0
- package/src/locales/it.json +512 -0
- package/src/locales/ja.json +512 -0
- package/src/locales/ko.json +512 -0
- package/src/locales/pt-br.json +512 -0
- package/src/locales/th.json +512 -0
- package/src/locales/zh-cn.json +512 -0
- package/src/locales/zh-tw.json +512 -0
- package/src/lsp/client.ts +941 -0
- package/src/lsp/clients/biome-client.ts +202 -0
- package/src/lsp/clients/index.ts +50 -0
- package/src/lsp/clients/lsp-linter-client.ts +93 -0
- package/src/lsp/clients/swiftlint-client.ts +120 -0
- package/src/lsp/config.ts +418 -0
- package/src/lsp/defaults.json +999 -0
- package/src/lsp/edits.ts +109 -0
- package/src/lsp/index.ts +1746 -0
- package/src/lsp/lspmux.ts +233 -0
- package/src/lsp/render.ts +692 -0
- package/src/lsp/startup-events.ts +13 -0
- package/src/lsp/types.ts +444 -0
- package/src/lsp/utils.ts +691 -0
- package/src/main.ts +944 -0
- package/src/mcp/client.ts +482 -0
- package/src/mcp/config-writer.ts +225 -0
- package/src/mcp/config.ts +365 -0
- package/src/mcp/discoverable-tool-metadata.ts +202 -0
- package/src/mcp/index.ts +29 -0
- package/src/mcp/json-rpc.ts +84 -0
- package/src/mcp/loader.ts +124 -0
- package/src/mcp/manager.ts +1152 -0
- package/src/mcp/oauth-discovery.ts +349 -0
- package/src/mcp/oauth-flow.ts +387 -0
- package/src/mcp/render.ts +157 -0
- package/src/mcp/smithery-auth.ts +104 -0
- package/src/mcp/smithery-connect.ts +145 -0
- package/src/mcp/smithery-registry.ts +477 -0
- package/src/mcp/tool-bridge.ts +417 -0
- package/src/mcp/tool-cache.ts +117 -0
- package/src/mcp/transports/http.ts +475 -0
- package/src/mcp/transports/index.ts +6 -0
- package/src/mcp/transports/stdio.ts +325 -0
- package/src/mcp/types.ts +423 -0
- package/src/memories/index.ts +1115 -0
- package/src/memories/storage.ts +577 -0
- package/src/modes/acp/acp-agent.ts +1361 -0
- package/src/modes/acp/acp-event-mapper.ts +538 -0
- package/src/modes/acp/acp-mode.ts +15 -0
- package/src/modes/acp/index.ts +2 -0
- package/src/modes/components/agent-dashboard.ts +1124 -0
- package/src/modes/components/assistant-message.ts +213 -0
- package/src/modes/components/bash-execution.ts +345 -0
- package/src/modes/components/bordered-loader.ts +41 -0
- package/src/modes/components/branch-summary-message.ts +45 -0
- package/src/modes/components/btw-panel.ts +103 -0
- package/src/modes/components/compaction-summary-message.ts +51 -0
- package/src/modes/components/context-add-wizard.ts +534 -0
- package/src/modes/components/countdown-timer.ts +75 -0
- package/src/modes/components/custom-editor.ts +238 -0
- package/src/modes/components/custom-message.ts +91 -0
- package/src/modes/components/diff.ts +210 -0
- package/src/modes/components/dynamic-border.ts +25 -0
- package/src/modes/components/extensions/extension-dashboard.ts +326 -0
- package/src/modes/components/extensions/extension-list.ts +492 -0
- package/src/modes/components/extensions/index.ts +9 -0
- package/src/modes/components/extensions/inspector-panel.ts +317 -0
- package/src/modes/components/extensions/state-manager.ts +587 -0
- package/src/modes/components/extensions/types.ts +191 -0
- package/src/modes/components/footer.ts +262 -0
- package/src/modes/components/gutter-block.ts +315 -0
- package/src/modes/components/history-search.ts +158 -0
- package/src/modes/components/hook-editor.ts +151 -0
- package/src/modes/components/hook-input.ts +81 -0
- package/src/modes/components/hook-message.ts +100 -0
- package/src/modes/components/hook-selector.ts +192 -0
- package/src/modes/components/index.ts +36 -0
- package/src/modes/components/keybinding-hints.ts +65 -0
- package/src/modes/components/login-dialog.ts +164 -0
- package/src/modes/components/mcp-add-wizard.ts +1314 -0
- package/src/modes/components/model-selector.ts +946 -0
- package/src/modes/components/oauth-selector.ts +211 -0
- package/src/modes/components/plugin-selector.ts +95 -0
- package/src/modes/components/plugin-settings.ts +477 -0
- package/src/modes/components/plugins/index.ts +5 -0
- package/src/modes/components/plugins/plugin-dashboard.ts +523 -0
- package/src/modes/components/plugins/plugin-inspector-pane.ts +84 -0
- package/src/modes/components/plugins/plugin-list-pane.ts +109 -0
- package/src/modes/components/plugins/state-manager.ts +229 -0
- package/src/modes/components/plugins/types.ts +51 -0
- package/src/modes/components/plugins/utils.ts +6 -0
- package/src/modes/components/python-execution.ts +244 -0
- package/src/modes/components/queue-mode-selector.ts +56 -0
- package/src/modes/components/read-tool-group.ts +137 -0
- package/src/modes/components/session-observer-overlay.ts +483 -0
- package/src/modes/components/session-selector.ts +343 -0
- package/src/modes/components/settings-defs.ts +568 -0
- package/src/modes/components/settings-selector.ts +641 -0
- package/src/modes/components/show-images-selector.ts +45 -0
- package/src/modes/components/skill-message.ts +90 -0
- package/src/modes/components/status-line/context-gradient.ts +64 -0
- package/src/modes/components/status-line/git-utils.ts +42 -0
- package/src/modes/components/status-line/hex-ansi.ts +29 -0
- package/src/modes/components/status-line/index.ts +4 -0
- package/src/modes/components/status-line/presets.ts +174 -0
- package/src/modes/components/status-line/segments.ts +494 -0
- package/src/modes/components/status-line/separators.ts +55 -0
- package/src/modes/components/status-line/token-rate.ts +66 -0
- package/src/modes/components/status-line/types.ts +96 -0
- package/src/modes/components/status-line-segment-editor.ts +361 -0
- package/src/modes/components/status-line.ts +729 -0
- package/src/modes/components/theme-selector.ts +63 -0
- package/src/modes/components/thinking-selector.ts +52 -0
- package/src/modes/components/todo-reminder.ts +54 -0
- package/src/modes/components/tool-execution.ts +781 -0
- package/src/modes/components/tree-selector.ts +908 -0
- package/src/modes/components/ttsr-notification.ts +80 -0
- package/src/modes/components/user-message-selector.ts +141 -0
- package/src/modes/components/user-message.ts +100 -0
- package/src/modes/components/visual-truncate.ts +63 -0
- package/src/modes/components/welcome-checks.ts +313 -0
- package/src/modes/components/welcome.ts +270 -0
- package/src/modes/controllers/btw-controller.ts +193 -0
- package/src/modes/controllers/chord-routing.ts +37 -0
- package/src/modes/controllers/command-controller.ts +1293 -0
- package/src/modes/controllers/context-command-controller.ts +61 -0
- package/src/modes/controllers/event-controller.ts +743 -0
- package/src/modes/controllers/extension-ui-controller.ts +983 -0
- package/src/modes/controllers/input-controller.ts +877 -0
- package/src/modes/controllers/mcp-command-controller.ts +1940 -0
- package/src/modes/controllers/selector-controller.ts +1292 -0
- package/src/modes/controllers/ssh-command-controller.ts +421 -0
- package/src/modes/index.ts +34 -0
- package/src/modes/interactive-mode.ts +1781 -0
- package/src/modes/oauth-manual-input.ts +42 -0
- package/src/modes/print-mode.ts +196 -0
- package/src/modes/prompt-action-autocomplete.ts +231 -0
- package/src/modes/rpc/host-tools.ts +186 -0
- package/src/modes/rpc/rpc-client.ts +762 -0
- package/src/modes/rpc/rpc-mode.ts +877 -0
- package/src/modes/rpc/rpc-types.ts +322 -0
- package/src/modes/session-observer-registry.ts +146 -0
- package/src/modes/shared.ts +30 -0
- package/src/modes/theme/defaults/index.ts +7 -0
- package/src/modes/theme/defaults/xcsh-dark.json +113 -0
- package/src/modes/theme/defaults/xcsh-light.json +115 -0
- package/src/modes/theme/mermaid-cache.ts +151 -0
- package/src/modes/theme/mermaid-palette.ts +39 -0
- package/src/modes/theme/theme-schema.json +553 -0
- package/src/modes/theme/theme.ts +2563 -0
- package/src/modes/types.ts +273 -0
- package/src/modes/utils/hotkeys-markdown.ts +60 -0
- package/src/modes/utils/keybinding-matchers.ts +30 -0
- package/src/modes/utils/read-group-outcome-aggregator.ts +55 -0
- package/src/modes/utils/sanitize-error-message.ts +60 -0
- package/src/modes/utils/tools-markdown.ts +28 -0
- package/src/modes/utils/ui-helpers.ts +734 -0
- package/src/plan-mode/approved-plan.ts +55 -0
- package/src/plan-mode/state.ts +6 -0
- package/src/priority.json +37 -0
- package/src/prompts/agents/designer.md +67 -0
- package/src/prompts/agents/explore.md +61 -0
- package/src/prompts/agents/frontmatter.md +10 -0
- package/src/prompts/agents/init.md +36 -0
- package/src/prompts/agents/librarian.md +121 -0
- package/src/prompts/agents/plan.md +49 -0
- package/src/prompts/agents/reviewer.md +127 -0
- package/src/prompts/agents/task.md +16 -0
- package/src/prompts/ci-green-request.md +35 -0
- package/src/prompts/compaction/branch-summary-context.md +5 -0
- package/src/prompts/compaction/branch-summary-preamble.md +2 -0
- package/src/prompts/compaction/branch-summary.md +30 -0
- package/src/prompts/compaction/compaction-short-summary.md +9 -0
- package/src/prompts/compaction/compaction-summary-context.md +5 -0
- package/src/prompts/compaction/compaction-summary.md +38 -0
- package/src/prompts/compaction/compaction-turn-prefix.md +17 -0
- package/src/prompts/compaction/compaction-update-summary.md +45 -0
- package/src/prompts/memories/consolidation.md +30 -0
- package/src/prompts/memories/read-path.md +11 -0
- package/src/prompts/memories/stage_one_input.md +6 -0
- package/src/prompts/memories/stage_one_system.md +21 -0
- package/src/prompts/review-request.md +70 -0
- package/src/prompts/system/agent-creation-architect.md +65 -0
- package/src/prompts/system/agent-creation-user.md +6 -0
- package/src/prompts/system/auto-handoff-threshold-focus.md +1 -0
- package/src/prompts/system/btw-user.md +8 -0
- package/src/prompts/system/commit-message-system.md +2 -0
- package/src/prompts/system/custom-system-prompt.md +82 -0
- package/src/prompts/system/eager-todo.md +13 -0
- package/src/prompts/system/file-operations.md +10 -0
- package/src/prompts/system/handoff-document.md +48 -0
- package/src/prompts/system/plan-mode-active.md +114 -0
- package/src/prompts/system/plan-mode-approved.md +23 -0
- package/src/prompts/system/plan-mode-reference.md +14 -0
- package/src/prompts/system/plan-mode-subagent.md +34 -0
- package/src/prompts/system/plan-mode-tool-decision-reminder.md +9 -0
- package/src/prompts/system/subagent-submit-reminder.md +7 -0
- package/src/prompts/system/subagent-system-prompt.md +36 -0
- package/src/prompts/system/subagent-user-prompt.md +12 -0
- package/src/prompts/system/summarization-system.md +3 -0
- package/src/prompts/system/system-prompt.md +698 -0
- package/src/prompts/system/title-system.md +2 -0
- package/src/prompts/system/ttsr-interrupt.md +7 -0
- package/src/prompts/system/web-search.md +28 -0
- package/src/prompts/tools/ask.md +28 -0
- package/src/prompts/tools/ast-edit.md +48 -0
- package/src/prompts/tools/ast-grep.md +54 -0
- package/src/prompts/tools/async-result.md +5 -0
- package/src/prompts/tools/bash.md +67 -0
- package/src/prompts/tools/browser.md +26 -0
- package/src/prompts/tools/calculator.md +10 -0
- package/src/prompts/tools/cancel-job.md +5 -0
- package/src/prompts/tools/catalog-workflow-runner.md +13 -0
- package/src/prompts/tools/checkpoint.md +16 -0
- package/src/prompts/tools/chunk-edit.md +279 -0
- package/src/prompts/tools/debug.md +43 -0
- package/src/prompts/tools/display-image.md +23 -0
- package/src/prompts/tools/exit-plan-mode.md +41 -0
- package/src/prompts/tools/find.md +26 -0
- package/src/prompts/tools/gemini-image.md +7 -0
- package/src/prompts/tools/grep.md +29 -0
- package/src/prompts/tools/hashline.md +131 -0
- package/src/prompts/tools/inspect-image-system.md +20 -0
- package/src/prompts/tools/inspect-image.md +32 -0
- package/src/prompts/tools/lsp.md +33 -0
- package/src/prompts/tools/patch.md +77 -0
- package/src/prompts/tools/poll.md +5 -0
- package/src/prompts/tools/python.md +60 -0
- package/src/prompts/tools/read-chunk.md +35 -0
- package/src/prompts/tools/read.md +63 -0
- package/src/prompts/tools/render-mermaid.md +9 -0
- package/src/prompts/tools/replace.md +36 -0
- package/src/prompts/tools/resolve.md +8 -0
- package/src/prompts/tools/rewind.md +13 -0
- package/src/prompts/tools/search-tool-bm25.md +34 -0
- package/src/prompts/tools/ssh.md +44 -0
- package/src/prompts/tools/task-summary.md +28 -0
- package/src/prompts/tools/task.md +131 -0
- package/src/prompts/tools/todo-write.md +89 -0
- package/src/prompts/tools/vim.md +98 -0
- package/src/prompts/tools/web-search.md +10 -0
- package/src/prompts/tools/write.md +14 -0
- package/src/prompts/tools/xcsh-api.md +283 -0
- package/src/resource-management/index.ts +42 -0
- package/src/sdk.ts +2123 -0
- package/src/secrets/index.ts +146 -0
- package/src/secrets/obfuscator.ts +290 -0
- package/src/secrets/regex.ts +21 -0
- package/src/services/context-env.ts +102 -0
- package/src/services/xcsh-api-client.ts +230 -0
- package/src/services/xcsh-context-command.ts +803 -0
- package/src/services/xcsh-context-display.ts +49 -0
- package/src/services/xcsh-context-indicators.ts +17 -0
- package/src/services/xcsh-context-segment.ts +39 -0
- package/src/services/xcsh-context.ts +1410 -0
- package/src/services/xcsh-env.ts +107 -0
- package/src/services/xcsh-knowledge.ts +177 -0
- package/src/services/xcsh-table.ts +164 -0
- package/src/session/agent-session.ts +6690 -0
- package/src/session/agent-storage.ts +451 -0
- package/src/session/artifacts.ts +132 -0
- package/src/session/auth-storage.ts +17 -0
- package/src/session/blob-store.ts +135 -0
- package/src/session/compaction/branch-summarization.ts +322 -0
- package/src/session/compaction/compaction.ts +1388 -0
- package/src/session/compaction/index.ts +7 -0
- package/src/session/compaction/pruning.ts +91 -0
- package/src/session/compaction/utils.ts +184 -0
- package/src/session/history-storage.ts +253 -0
- package/src/session/messages.ts +597 -0
- package/src/session/session-dump-format.ts +203 -0
- package/src/session/session-manager.ts +2816 -0
- package/src/session/session-storage.ts +370 -0
- package/src/session/streaming-output.ts +770 -0
- package/src/session/tool-choice-queue.ts +213 -0
- package/src/slash-commands/builtin-registry.ts +1614 -0
- package/src/slash-commands/export-command.ts +178 -0
- package/src/slash-commands/marketplace-install-parser.ts +99 -0
- package/src/slash-commands/resource-commands.ts +250 -0
- package/src/ssh/config-writer.ts +183 -0
- package/src/ssh/connection-manager.ts +445 -0
- package/src/ssh/ssh-executor.ts +131 -0
- package/src/ssh/sshfs-mount.ts +137 -0
- package/src/ssh/utils.ts +8 -0
- package/src/stt/downloader.ts +71 -0
- package/src/stt/index.ts +3 -0
- package/src/stt/recorder.ts +351 -0
- package/src/stt/setup.ts +52 -0
- package/src/stt/stt-controller.ts +160 -0
- package/src/stt/transcribe.py +70 -0
- package/src/stt/transcriber.ts +91 -0
- package/src/system-prompt.ts +688 -0
- package/src/task/agents.ts +166 -0
- package/src/task/commands.ts +131 -0
- package/src/task/discovery.ts +126 -0
- package/src/task/executor.ts +1324 -0
- package/src/task/index.ts +1197 -0
- package/src/task/isolation-backend.ts +72 -0
- package/src/task/name-generator.ts +1577 -0
- package/src/task/output-manager.ts +107 -0
- package/src/task/parallel.ts +116 -0
- package/src/task/render.ts +1035 -0
- package/src/task/subprocess-tool-registry.ts +88 -0
- package/src/task/template.ts +33 -0
- package/src/task/types.ts +230 -0
- package/src/task/worktree.ts +580 -0
- package/src/task/xcsh-command.ts +26 -0
- package/src/thinking.ts +87 -0
- package/src/tools/action-renderer.ts +198 -0
- package/src/tools/archive-reader.ts +315 -0
- package/src/tools/ask.ts +791 -0
- package/src/tools/ast-edit.ts +492 -0
- package/src/tools/ast-grep.ts +453 -0
- package/src/tools/auto-generated-guard.ts +305 -0
- package/src/tools/bash-interactive.ts +383 -0
- package/src/tools/bash-interceptor.ts +67 -0
- package/src/tools/bash-normalize.ts +107 -0
- package/src/tools/bash-skill-urls.ts +246 -0
- package/src/tools/bash.ts +878 -0
- package/src/tools/browser-renderer.ts +129 -0
- package/src/tools/browser.ts +1366 -0
- package/src/tools/calculator.ts +543 -0
- package/src/tools/cancel-job.ts +100 -0
- package/src/tools/catalog-workflow-runner.ts +718 -0
- package/src/tools/checkpoint.ts +133 -0
- package/src/tools/context.ts +39 -0
- package/src/tools/debug.ts +1004 -0
- package/src/tools/display-image-renderer.ts +96 -0
- package/src/tools/display-image.ts +109 -0
- package/src/tools/exit-plan-mode.ts +101 -0
- package/src/tools/fetch.ts +1462 -0
- package/src/tools/find.ts +437 -0
- package/src/tools/fs-cache-invalidation.ts +33 -0
- package/src/tools/gemini-image.ts +1004 -0
- package/src/tools/grep.ts +705 -0
- package/src/tools/index.ts +442 -0
- package/src/tools/inspect-image-renderer.ts +101 -0
- package/src/tools/inspect-image.ts +176 -0
- package/src/tools/json-tree.ts +266 -0
- package/src/tools/jtd-to-json-schema.ts +199 -0
- package/src/tools/jtd-to-typescript.ts +136 -0
- package/src/tools/jtd-utils.ts +102 -0
- package/src/tools/list-limit.ts +40 -0
- package/src/tools/mermaid-renderer.ts +127 -0
- package/src/tools/notebook.ts +288 -0
- package/src/tools/output-meta.ts +588 -0
- package/src/tools/path-utils.ts +560 -0
- package/src/tools/plan-mode-guard.ts +41 -0
- package/src/tools/poll-tool.ts +177 -0
- package/src/tools/puppeteer/00_stealth_tampering.txt +63 -0
- package/src/tools/puppeteer/01_stealth_activity.txt +20 -0
- package/src/tools/puppeteer/02_stealth_hairline.txt +11 -0
- package/src/tools/puppeteer/03_stealth_botd.txt +384 -0
- package/src/tools/puppeteer/04_stealth_iframe.txt +81 -0
- package/src/tools/puppeteer/05_stealth_webgl.txt +75 -0
- package/src/tools/puppeteer/06_stealth_screen.txt +72 -0
- package/src/tools/puppeteer/07_stealth_fonts.txt +97 -0
- package/src/tools/puppeteer/08_stealth_audio.txt +51 -0
- package/src/tools/puppeteer/09_stealth_locale.txt +46 -0
- package/src/tools/puppeteer/10_stealth_plugins.txt +206 -0
- package/src/tools/puppeteer/11_stealth_hardware.txt +8 -0
- package/src/tools/puppeteer/12_stealth_codecs.txt +40 -0
- package/src/tools/puppeteer/13_stealth_worker.txt +74 -0
- package/src/tools/python.ts +1184 -0
- package/src/tools/read.ts +1591 -0
- package/src/tools/render-mermaid.ts +93 -0
- package/src/tools/render-utils.ts +677 -0
- package/src/tools/renderers.ts +82 -0
- package/src/tools/report-tool-issue.ts +80 -0
- package/src/tools/resolve.ts +196 -0
- package/src/tools/review.ts +238 -0
- package/src/tools/search-tool-bm25.ts +288 -0
- package/src/tools/sqlite-reader.ts +623 -0
- package/src/tools/ssh.ts +322 -0
- package/src/tools/submit-result.ts +229 -0
- package/src/tools/todo-render.ts +33 -0
- package/src/tools/todo-write.ts +440 -0
- package/src/tools/tool-errors.ts +62 -0
- package/src/tools/tool-result.ts +93 -0
- package/src/tools/tool-timeouts.ts +30 -0
- package/src/tools/vim.ts +981 -0
- package/src/tools/write.ts +671 -0
- package/src/tools/xcsh-api-renderer.ts +402 -0
- package/src/tools/xcsh-api.ts +887 -0
- package/src/tui/code-cell.ts +101 -0
- package/src/tui/file-list.ts +47 -0
- package/src/tui/index.ts +11 -0
- package/src/tui/output-block.ts +175 -0
- package/src/tui/status-line.ts +39 -0
- package/src/tui/tree-list.ts +84 -0
- package/src/tui/types.ts +15 -0
- package/src/tui/utils.ts +103 -0
- package/src/utils/changelog.ts +98 -0
- package/src/utils/clipboard.ts +80 -0
- package/src/utils/command-args.ts +76 -0
- package/src/utils/commit-message-generator.ts +137 -0
- package/src/utils/edit-mode.ts +50 -0
- package/src/utils/event-bus.ts +33 -0
- package/src/utils/external-editor.ts +65 -0
- package/src/utils/file-display-mode.ts +37 -0
- package/src/utils/file-mentions.ts +376 -0
- package/src/utils/fuzzy.ts +108 -0
- package/src/utils/git.ts +1495 -0
- package/src/utils/gitstatus.ts +140 -0
- package/src/utils/image-convert.ts +27 -0
- package/src/utils/image-loading.ts +98 -0
- package/src/utils/image-passthrough.ts +118 -0
- package/src/utils/image-resize.ts +272 -0
- package/src/utils/image-viewer.ts +17 -0
- package/src/utils/lang-from-path.ts +239 -0
- package/src/utils/markit.ts +81 -0
- package/src/utils/open.ts +20 -0
- package/src/utils/session-color.ts +55 -0
- package/src/utils/shell-snapshot.ts +188 -0
- package/src/utils/title-generator.ts +193 -0
- package/src/utils/tool-choice.ts +28 -0
- package/src/utils/tools-manager.ts +356 -0
- package/src/vim/buffer.ts +309 -0
- package/src/vim/commands.ts +382 -0
- package/src/vim/engine.ts +2426 -0
- package/src/vim/parser.ts +151 -0
- package/src/vim/render.ts +252 -0
- package/src/vim/types.ts +197 -0
- package/src/web/kagi.ts +174 -0
- package/src/web/parallel.ts +346 -0
- package/src/web/scrapers/artifacthub.ts +207 -0
- package/src/web/scrapers/arxiv.ts +83 -0
- package/src/web/scrapers/aur.ts +162 -0
- package/src/web/scrapers/biorxiv.ts +133 -0
- package/src/web/scrapers/bluesky.ts +262 -0
- package/src/web/scrapers/brew.ts +172 -0
- package/src/web/scrapers/cheatsh.ts +68 -0
- package/src/web/scrapers/chocolatey.ts +196 -0
- package/src/web/scrapers/choosealicense.ts +95 -0
- package/src/web/scrapers/cisa-kev.ts +87 -0
- package/src/web/scrapers/clojars.ts +154 -0
- package/src/web/scrapers/coingecko.ts +177 -0
- package/src/web/scrapers/crates-io.ts +110 -0
- package/src/web/scrapers/crossref.ts +136 -0
- package/src/web/scrapers/devto.ts +147 -0
- package/src/web/scrapers/discogs.ts +306 -0
- package/src/web/scrapers/discourse.ts +197 -0
- package/src/web/scrapers/dockerhub.ts +138 -0
- package/src/web/scrapers/docs-rs.ts +653 -0
- package/src/web/scrapers/fdroid.ts +134 -0
- package/src/web/scrapers/firefox-addons.ts +191 -0
- package/src/web/scrapers/flathub.ts +223 -0
- package/src/web/scrapers/github-gist.ts +58 -0
- package/src/web/scrapers/github.ts +452 -0
- package/src/web/scrapers/gitlab.ts +401 -0
- package/src/web/scrapers/go-pkg.ts +266 -0
- package/src/web/scrapers/hackage.ts +140 -0
- package/src/web/scrapers/hackernews.ts +189 -0
- package/src/web/scrapers/hex.ts +105 -0
- package/src/web/scrapers/huggingface.ts +321 -0
- package/src/web/scrapers/iacr.ts +89 -0
- package/src/web/scrapers/index.ts +252 -0
- package/src/web/scrapers/jetbrains-marketplace.ts +159 -0
- package/src/web/scrapers/lemmy.ts +203 -0
- package/src/web/scrapers/lobsters.ts +175 -0
- package/src/web/scrapers/mastodon.ts +292 -0
- package/src/web/scrapers/maven.ts +138 -0
- package/src/web/scrapers/mdn.ts +169 -0
- package/src/web/scrapers/metacpan.ts +222 -0
- package/src/web/scrapers/musicbrainz.ts +250 -0
- package/src/web/scrapers/npm.ts +98 -0
- package/src/web/scrapers/nuget.ts +183 -0
- package/src/web/scrapers/nvd.ts +222 -0
- package/src/web/scrapers/ollama.ts +239 -0
- package/src/web/scrapers/open-vsx.ts +106 -0
- package/src/web/scrapers/opencorporates.ts +292 -0
- package/src/web/scrapers/openlibrary.ts +336 -0
- package/src/web/scrapers/orcid.ts +286 -0
- package/src/web/scrapers/osv.ts +176 -0
- package/src/web/scrapers/packagist.ts +160 -0
- package/src/web/scrapers/pub-dev.ts +143 -0
- package/src/web/scrapers/pubmed.ts +211 -0
- package/src/web/scrapers/pypi.ts +112 -0
- package/src/web/scrapers/rawg.ts +110 -0
- package/src/web/scrapers/readthedocs.ts +120 -0
- package/src/web/scrapers/reddit.ts +95 -0
- package/src/web/scrapers/repology.ts +251 -0
- package/src/web/scrapers/rfc.ts +201 -0
- package/src/web/scrapers/rubygems.ts +103 -0
- package/src/web/scrapers/searchcode.ts +190 -0
- package/src/web/scrapers/sec-edgar.ts +261 -0
- package/src/web/scrapers/semantic-scholar.ts +171 -0
- package/src/web/scrapers/snapcraft.ts +187 -0
- package/src/web/scrapers/sourcegraph.ts +336 -0
- package/src/web/scrapers/spdx.ts +108 -0
- package/src/web/scrapers/spotify.ts +198 -0
- package/src/web/scrapers/stackoverflow.ts +120 -0
- package/src/web/scrapers/terraform.ts +277 -0
- package/src/web/scrapers/tldr.ts +47 -0
- package/src/web/scrapers/twitter.ts +93 -0
- package/src/web/scrapers/types.ts +267 -0
- package/src/web/scrapers/utils.ts +109 -0
- package/src/web/scrapers/vimeo.ts +133 -0
- package/src/web/scrapers/vscode-marketplace.ts +187 -0
- package/src/web/scrapers/w3c.ts +156 -0
- package/src/web/scrapers/wikidata.ts +344 -0
- package/src/web/scrapers/wikipedia.ts +84 -0
- package/src/web/scrapers/youtube.ts +313 -0
- package/src/web/search/errors.ts +120 -0
- package/src/web/search/index.ts +346 -0
- package/src/web/search/params.ts +129 -0
- package/src/web/search/provider.ts +97 -0
- package/src/web/search/providers/anthropic.ts +339 -0
- package/src/web/search/providers/base.ts +35 -0
- package/src/web/search/providers/brave.ts +150 -0
- package/src/web/search/providers/codex.ts +402 -0
- package/src/web/search/providers/exa.ts +264 -0
- package/src/web/search/providers/firecrawl.ts +115 -0
- package/src/web/search/providers/gemini.ts +566 -0
- package/src/web/search/providers/jina.ts +99 -0
- package/src/web/search/providers/kagi.ts +70 -0
- package/src/web/search/providers/kimi.ts +157 -0
- package/src/web/search/providers/parallel.ts +63 -0
- package/src/web/search/providers/perplexity.ts +546 -0
- package/src/web/search/providers/synthetic.ts +113 -0
- package/src/web/search/providers/tavily.ts +162 -0
- package/src/web/search/providers/utils.ts +36 -0
- package/src/web/search/providers/zai.ts +311 -0
- package/src/web/search/render.ts +348 -0
- package/src/web/search/types.ts +438 -0
- package/src/web/search/utils.ts +17 -0
|
@@ -0,0 +1,1361 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import {
|
|
3
|
+
type Agent,
|
|
4
|
+
type AgentSideConnection,
|
|
5
|
+
type AuthenticateRequest,
|
|
6
|
+
type AuthenticateResponse,
|
|
7
|
+
type AvailableCommand,
|
|
8
|
+
type CloseSessionRequest,
|
|
9
|
+
type CloseSessionResponse,
|
|
10
|
+
type ForkSessionRequest,
|
|
11
|
+
type ForkSessionResponse,
|
|
12
|
+
type InitializeRequest,
|
|
13
|
+
type InitializeResponse,
|
|
14
|
+
type ListSessionsRequest,
|
|
15
|
+
type ListSessionsResponse,
|
|
16
|
+
type LoadSessionRequest,
|
|
17
|
+
type LoadSessionResponse,
|
|
18
|
+
type McpServer,
|
|
19
|
+
type NewSessionRequest,
|
|
20
|
+
type NewSessionResponse,
|
|
21
|
+
PROTOCOL_VERSION,
|
|
22
|
+
type PromptRequest,
|
|
23
|
+
type PromptResponse,
|
|
24
|
+
type ResumeSessionRequest,
|
|
25
|
+
type ResumeSessionResponse,
|
|
26
|
+
type SessionConfigOption,
|
|
27
|
+
type SessionInfo,
|
|
28
|
+
type SessionModelState,
|
|
29
|
+
type SessionModeState,
|
|
30
|
+
type SessionNotification,
|
|
31
|
+
type SessionUpdate,
|
|
32
|
+
type SetSessionConfigOptionRequest,
|
|
33
|
+
type SetSessionConfigOptionResponse,
|
|
34
|
+
type SetSessionModelRequest,
|
|
35
|
+
type SetSessionModelResponse,
|
|
36
|
+
type SetSessionModeRequest,
|
|
37
|
+
type SetSessionModeResponse,
|
|
38
|
+
type Usage,
|
|
39
|
+
} from "@agentclientprotocol/sdk";
|
|
40
|
+
import type { Model } from "@f5xc-salesdemos/pi-ai";
|
|
41
|
+
import { logger, VERSION } from "@f5xc-salesdemos/pi-utils";
|
|
42
|
+
import type { ExtensionUIContext } from "../../extensibility/extensions";
|
|
43
|
+
import { loadSlashCommands } from "../../extensibility/slash-commands";
|
|
44
|
+
import { MCPManager } from "../../mcp/manager";
|
|
45
|
+
import type { MCPServerConfig } from "../../mcp/types";
|
|
46
|
+
import { theme } from "../../modes/theme/theme";
|
|
47
|
+
import type { AgentSession, AgentSessionEvent } from "../../session/agent-session";
|
|
48
|
+
import {
|
|
49
|
+
SessionManager,
|
|
50
|
+
type SessionInfo as StoredSessionInfo,
|
|
51
|
+
type UsageStatistics,
|
|
52
|
+
} from "../../session/session-manager";
|
|
53
|
+
import { parseThinkingLevel } from "../../thinking";
|
|
54
|
+
import { mapAgentSessionEventToAcpSessionUpdates, mapToolKind } from "./acp-event-mapper";
|
|
55
|
+
|
|
56
|
+
const ACP_MODE_ID = "default";
|
|
57
|
+
const MODE_CONFIG_ID = "mode";
|
|
58
|
+
const MODEL_CONFIG_ID = "model";
|
|
59
|
+
const THINKING_CONFIG_ID = "thinking";
|
|
60
|
+
const THINKING_OFF = "off";
|
|
61
|
+
const SESSION_PAGE_SIZE = 50;
|
|
62
|
+
|
|
63
|
+
type AgentImageContent = {
|
|
64
|
+
type: "image";
|
|
65
|
+
data: string;
|
|
66
|
+
mimeType: string;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
type PromptTurnState = {
|
|
70
|
+
userMessageId: string;
|
|
71
|
+
cancelRequested: boolean;
|
|
72
|
+
settled: boolean;
|
|
73
|
+
usageBaseline: UsageStatistics;
|
|
74
|
+
unsubscribe: (() => void) | undefined;
|
|
75
|
+
resolve: (value: PromptResponse) => void;
|
|
76
|
+
reject: (reason?: unknown) => void;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
type ManagedSessionRecord = {
|
|
80
|
+
session: AgentSession;
|
|
81
|
+
mcpManager: MCPManager | undefined;
|
|
82
|
+
promptTurn: PromptTurnState | undefined;
|
|
83
|
+
liveMessageIds: WeakMap<object, string>;
|
|
84
|
+
extensionsConfigured: boolean;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
type ReplayableMessage = {
|
|
88
|
+
role: string;
|
|
89
|
+
content?: unknown;
|
|
90
|
+
errorMessage?: string;
|
|
91
|
+
toolCallId?: string;
|
|
92
|
+
toolName?: string;
|
|
93
|
+
details?: unknown;
|
|
94
|
+
isError?: boolean;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
type MCPConfigMap = {
|
|
98
|
+
[name: string]: MCPServerConfig;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
type MCPSource = {
|
|
102
|
+
provider: string;
|
|
103
|
+
providerName: string;
|
|
104
|
+
path: string;
|
|
105
|
+
level: "project";
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
type MCPSourceMap = {
|
|
109
|
+
[name: string]: MCPSource;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
type CreateAcpSession = (cwd: string) => Promise<AgentSession>;
|
|
113
|
+
|
|
114
|
+
const acpExtensionUiContext: ExtensionUIContext = {
|
|
115
|
+
select: async () => undefined,
|
|
116
|
+
confirm: async () => false,
|
|
117
|
+
input: async () => undefined,
|
|
118
|
+
notify: (message, type) => {
|
|
119
|
+
logger.debug("ACP extension notification", { message, type });
|
|
120
|
+
},
|
|
121
|
+
onTerminalInput: () => () => {},
|
|
122
|
+
setStatus: () => {},
|
|
123
|
+
setWorkingMessage: () => {},
|
|
124
|
+
setWidget: () => {},
|
|
125
|
+
setFooter: () => {},
|
|
126
|
+
setHeader: () => {},
|
|
127
|
+
setTitle: () => {},
|
|
128
|
+
custom: async () => undefined as never,
|
|
129
|
+
pasteToEditor: () => {},
|
|
130
|
+
setEditorText: () => {},
|
|
131
|
+
getEditorText: () => "",
|
|
132
|
+
editor: async () => undefined,
|
|
133
|
+
setEditorComponent: () => {},
|
|
134
|
+
get theme() {
|
|
135
|
+
return theme;
|
|
136
|
+
},
|
|
137
|
+
getAllThemes: async () => [],
|
|
138
|
+
getTheme: async () => undefined,
|
|
139
|
+
setTheme: async () => ({ success: false, error: "Theme changes are unavailable in ACP mode" }),
|
|
140
|
+
getToolsExpanded: () => false,
|
|
141
|
+
setToolsExpanded: () => {},
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export class AcpAgent implements Agent {
|
|
145
|
+
#connection: AgentSideConnection;
|
|
146
|
+
#initialSession: AgentSession | undefined;
|
|
147
|
+
#createSession: CreateAcpSession;
|
|
148
|
+
#sessions = new Map<string, ManagedSessionRecord>();
|
|
149
|
+
#disposePromise: Promise<void> | undefined;
|
|
150
|
+
#cleanupRegistered = false;
|
|
151
|
+
|
|
152
|
+
constructor(connection: AgentSideConnection, initialSession: AgentSession, createSession: CreateAcpSession) {
|
|
153
|
+
this.#connection = connection;
|
|
154
|
+
this.#initialSession = initialSession;
|
|
155
|
+
this.#createSession = createSession;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async initialize(_params: InitializeRequest): Promise<InitializeResponse> {
|
|
159
|
+
this.#registerConnectionCleanup();
|
|
160
|
+
return {
|
|
161
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
162
|
+
agentInfo: {
|
|
163
|
+
name: "xcsh",
|
|
164
|
+
title: "xcsh",
|
|
165
|
+
version: VERSION,
|
|
166
|
+
},
|
|
167
|
+
authMethods: [
|
|
168
|
+
{
|
|
169
|
+
id: "agent",
|
|
170
|
+
name: "Agent-managed authentication",
|
|
171
|
+
description: "xcsh uses its existing local authentication and provider configuration.",
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
agentCapabilities: {
|
|
175
|
+
loadSession: true,
|
|
176
|
+
mcpCapabilities: {
|
|
177
|
+
http: true,
|
|
178
|
+
sse: true,
|
|
179
|
+
},
|
|
180
|
+
promptCapabilities: {
|
|
181
|
+
embeddedContext: true,
|
|
182
|
+
image: true,
|
|
183
|
+
},
|
|
184
|
+
sessionCapabilities: {
|
|
185
|
+
list: {},
|
|
186
|
+
fork: {},
|
|
187
|
+
resume: {},
|
|
188
|
+
close: {},
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async authenticate(_params: AuthenticateRequest): Promise<AuthenticateResponse> {
|
|
195
|
+
return {};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async newSession(params: NewSessionRequest): Promise<NewSessionResponse> {
|
|
199
|
+
this.#assertAbsoluteCwd(params.cwd);
|
|
200
|
+
const record = await this.#createNewSessionRecord(params.cwd, params.mcpServers);
|
|
201
|
+
const response: NewSessionResponse = {
|
|
202
|
+
sessionId: record.session.sessionId,
|
|
203
|
+
configOptions: this.#buildConfigOptions(record.session),
|
|
204
|
+
models: this.#buildModelState(record.session),
|
|
205
|
+
modes: this.#buildModeState(),
|
|
206
|
+
};
|
|
207
|
+
this.#scheduleBootstrapUpdates(record.session.sessionId);
|
|
208
|
+
return response;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async loadSession(params: LoadSessionRequest): Promise<LoadSessionResponse> {
|
|
212
|
+
this.#assertAbsoluteCwd(params.cwd);
|
|
213
|
+
const record = await this.#loadManagedSession(params.sessionId, params.cwd, params.mcpServers);
|
|
214
|
+
await this.#replaySessionHistory(record);
|
|
215
|
+
const response: LoadSessionResponse = {
|
|
216
|
+
configOptions: this.#buildConfigOptions(record.session),
|
|
217
|
+
models: this.#buildModelState(record.session),
|
|
218
|
+
modes: this.#buildModeState(),
|
|
219
|
+
};
|
|
220
|
+
this.#scheduleBootstrapUpdates(record.session.sessionId);
|
|
221
|
+
return response;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async listSessions(params: ListSessionsRequest): Promise<ListSessionsResponse> {
|
|
225
|
+
if (params.cwd) {
|
|
226
|
+
this.#assertAbsoluteCwd(params.cwd);
|
|
227
|
+
}
|
|
228
|
+
for (const record of this.#sessions.values()) {
|
|
229
|
+
await record.session.sessionManager.flush();
|
|
230
|
+
}
|
|
231
|
+
const sessions = await this.#listStoredSessions(params.cwd ?? undefined);
|
|
232
|
+
const offset = this.#parseCursor(params.cursor ?? undefined);
|
|
233
|
+
const paged = sessions.slice(offset, offset + SESSION_PAGE_SIZE);
|
|
234
|
+
const nextOffset = offset + paged.length;
|
|
235
|
+
return {
|
|
236
|
+
sessions: paged.map(session => this.#toSessionInfo(session)),
|
|
237
|
+
nextCursor: nextOffset < sessions.length ? String(nextOffset) : undefined,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async unstable_resumeSession(params: ResumeSessionRequest): Promise<ResumeSessionResponse> {
|
|
242
|
+
this.#assertAbsoluteCwd(params.cwd);
|
|
243
|
+
const record = await this.#resumeManagedSession(params.sessionId, params.cwd, params.mcpServers ?? []);
|
|
244
|
+
const response: ResumeSessionResponse = {
|
|
245
|
+
configOptions: this.#buildConfigOptions(record.session),
|
|
246
|
+
models: this.#buildModelState(record.session),
|
|
247
|
+
modes: this.#buildModeState(),
|
|
248
|
+
};
|
|
249
|
+
this.#scheduleBootstrapUpdates(record.session.sessionId);
|
|
250
|
+
return response;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async unstable_forkSession(params: ForkSessionRequest): Promise<ForkSessionResponse> {
|
|
254
|
+
this.#assertAbsoluteCwd(params.cwd);
|
|
255
|
+
const record = await this.#forkManagedSession(params);
|
|
256
|
+
const response: ForkSessionResponse = {
|
|
257
|
+
sessionId: record.session.sessionId,
|
|
258
|
+
configOptions: this.#buildConfigOptions(record.session),
|
|
259
|
+
models: this.#buildModelState(record.session),
|
|
260
|
+
modes: this.#buildModeState(),
|
|
261
|
+
};
|
|
262
|
+
this.#scheduleBootstrapUpdates(record.session.sessionId);
|
|
263
|
+
return response;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
async unstable_closeSession(params: CloseSessionRequest): Promise<CloseSessionResponse> {
|
|
267
|
+
const record = this.#sessions.get(params.sessionId);
|
|
268
|
+
if (!record) {
|
|
269
|
+
return {};
|
|
270
|
+
}
|
|
271
|
+
await this.#closeManagedSession(params.sessionId, record);
|
|
272
|
+
return {};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async setSessionMode(params: SetSessionModeRequest): Promise<SetSessionModeResponse> {
|
|
276
|
+
const record = this.#getSessionRecord(params.sessionId);
|
|
277
|
+
if (params.modeId !== ACP_MODE_ID) {
|
|
278
|
+
throw new Error(`Unsupported ACP mode: ${params.modeId}`);
|
|
279
|
+
}
|
|
280
|
+
await this.#connection.sessionUpdate({
|
|
281
|
+
sessionId: record.session.sessionId,
|
|
282
|
+
update: this.#buildCurrentModeUpdate(),
|
|
283
|
+
});
|
|
284
|
+
return {};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
async setSessionConfigOption(params: SetSessionConfigOptionRequest): Promise<SetSessionConfigOptionResponse> {
|
|
288
|
+
const record = this.#getSessionRecord(params.sessionId);
|
|
289
|
+
if (typeof params.value === "boolean") {
|
|
290
|
+
throw new Error(`Unsupported boolean ACP config option: ${params.configId}`);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
switch (params.configId) {
|
|
294
|
+
case MODE_CONFIG_ID:
|
|
295
|
+
if (params.value !== ACP_MODE_ID) {
|
|
296
|
+
throw new Error(`Unsupported ACP mode config value: ${params.value}`);
|
|
297
|
+
}
|
|
298
|
+
break;
|
|
299
|
+
case MODEL_CONFIG_ID:
|
|
300
|
+
await this.#setModelById(record.session, params.value);
|
|
301
|
+
break;
|
|
302
|
+
case THINKING_CONFIG_ID:
|
|
303
|
+
this.#setThinkingLevelById(record.session, params.value);
|
|
304
|
+
break;
|
|
305
|
+
default:
|
|
306
|
+
throw new Error(`Unknown ACP config option: ${params.configId}`);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const configOptions = this.#buildConfigOptions(record.session);
|
|
310
|
+
await this.#connection.sessionUpdate({
|
|
311
|
+
sessionId: record.session.sessionId,
|
|
312
|
+
update: {
|
|
313
|
+
sessionUpdate: "config_option_update",
|
|
314
|
+
configOptions,
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
return { configOptions };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
async unstable_setSessionModel(params: SetSessionModelRequest): Promise<SetSessionModelResponse> {
|
|
321
|
+
const record = this.#getSessionRecord(params.sessionId);
|
|
322
|
+
await this.#setModelById(record.session, params.modelId);
|
|
323
|
+
await this.#connection.sessionUpdate({
|
|
324
|
+
sessionId: record.session.sessionId,
|
|
325
|
+
update: {
|
|
326
|
+
sessionUpdate: "config_option_update",
|
|
327
|
+
configOptions: this.#buildConfigOptions(record.session),
|
|
328
|
+
},
|
|
329
|
+
});
|
|
330
|
+
return {};
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
async prompt(params: PromptRequest): Promise<PromptResponse> {
|
|
334
|
+
const record = this.#getSessionRecord(params.sessionId);
|
|
335
|
+
if (record.promptTurn && !record.promptTurn.settled) {
|
|
336
|
+
throw new Error("ACP prompt already in progress for this session");
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const converted = this.#convertPromptBlocks(params.prompt);
|
|
340
|
+
const pendingPrompt = Promise.withResolvers<PromptResponse>();
|
|
341
|
+
record.promptTurn = {
|
|
342
|
+
userMessageId: params.messageId ?? crypto.randomUUID(),
|
|
343
|
+
cancelRequested: false,
|
|
344
|
+
settled: false,
|
|
345
|
+
usageBaseline: this.#cloneUsageStatistics(record.session.sessionManager.getUsageStatistics()),
|
|
346
|
+
unsubscribe: undefined,
|
|
347
|
+
resolve: pendingPrompt.resolve,
|
|
348
|
+
reject: pendingPrompt.reject,
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
record.promptTurn.unsubscribe = record.session.subscribe(event => {
|
|
352
|
+
void this.#handlePromptEvent(record, event);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
record.session.prompt(converted.text, { images: converted.images }).catch((error: unknown) => {
|
|
356
|
+
this.#finishPrompt(record, undefined, error);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
return await pendingPrompt.promise;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
async cancel(params: { sessionId: string }): Promise<void> {
|
|
363
|
+
const record = this.#getSessionRecord(params.sessionId);
|
|
364
|
+
const promptTurn = record.promptTurn;
|
|
365
|
+
if (!promptTurn || promptTurn.settled) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
promptTurn.cancelRequested = true;
|
|
369
|
+
try {
|
|
370
|
+
await record.session.abort();
|
|
371
|
+
this.#finishPrompt(record, {
|
|
372
|
+
stopReason: "cancelled",
|
|
373
|
+
usage: this.#buildTurnUsage(promptTurn.usageBaseline, record.session.sessionManager.getUsageStatistics()),
|
|
374
|
+
userMessageId: promptTurn.userMessageId,
|
|
375
|
+
});
|
|
376
|
+
} catch (error: unknown) {
|
|
377
|
+
this.#finishPrompt(record, undefined, error);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
async extMethod(_method: string, _params: { [key: string]: unknown }): Promise<{ [key: string]: unknown }> {
|
|
382
|
+
throw new Error("ACP extension methods are not implemented");
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
async extNotification(_method: string, _params: { [key: string]: unknown }): Promise<void> {}
|
|
386
|
+
|
|
387
|
+
get signal(): AbortSignal {
|
|
388
|
+
return this.#connection.signal;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
get closed(): Promise<void> {
|
|
392
|
+
return this.#connection.closed;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
#registerConnectionCleanup(): void {
|
|
396
|
+
if (this.#cleanupRegistered) {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
this.#cleanupRegistered = true;
|
|
400
|
+
this.#connection.signal.addEventListener(
|
|
401
|
+
"abort",
|
|
402
|
+
() => {
|
|
403
|
+
void this.#disposeAllSessions();
|
|
404
|
+
},
|
|
405
|
+
{ once: true },
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
async #createNewSessionRecord(cwd: string, mcpServers: McpServer[]): Promise<ManagedSessionRecord> {
|
|
410
|
+
const session = await this.#createSession(path.resolve(cwd));
|
|
411
|
+
try {
|
|
412
|
+
await session.sessionManager.ensureOnDisk();
|
|
413
|
+
} catch (error) {
|
|
414
|
+
await this.#disposeStandaloneSession(session);
|
|
415
|
+
throw error;
|
|
416
|
+
}
|
|
417
|
+
return await this.#registerPreparedSession(session, mcpServers);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
async #loadManagedSession(sessionId: string, cwd: string, mcpServers: McpServer[]): Promise<ManagedSessionRecord> {
|
|
421
|
+
const existing = this.#sessions.get(sessionId);
|
|
422
|
+
if (existing) {
|
|
423
|
+
this.#assertMatchingCwd(existing.session, cwd);
|
|
424
|
+
await this.#configureMcpServers(existing, mcpServers);
|
|
425
|
+
return existing;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const storedSession = await this.#findStoredSession(sessionId, cwd);
|
|
429
|
+
if (!storedSession) {
|
|
430
|
+
throw new Error(`ACP session not found: ${sessionId}`);
|
|
431
|
+
}
|
|
432
|
+
return await this.#openStoredSession(storedSession.path, cwd, mcpServers, sessionId);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
async #resumeManagedSession(sessionId: string, cwd: string, mcpServers: McpServer[]): Promise<ManagedSessionRecord> {
|
|
436
|
+
const existing = this.#sessions.get(sessionId);
|
|
437
|
+
if (existing) {
|
|
438
|
+
this.#assertMatchingCwd(existing.session, cwd);
|
|
439
|
+
await this.#configureMcpServers(existing, mcpServers);
|
|
440
|
+
return existing;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const storedSession = await this.#findStoredSession(sessionId, cwd);
|
|
444
|
+
if (!storedSession) {
|
|
445
|
+
throw new Error(`ACP session not found: ${sessionId}`);
|
|
446
|
+
}
|
|
447
|
+
return await this.#openStoredSession(storedSession.path, cwd, mcpServers, sessionId);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
async #forkManagedSession(params: ForkSessionRequest): Promise<ManagedSessionRecord> {
|
|
451
|
+
const sourcePath = await this.#resolveForkSourceSessionPath(params.sessionId);
|
|
452
|
+
const session = await this.#createSession(path.resolve(params.cwd));
|
|
453
|
+
try {
|
|
454
|
+
const success = await session.switchSession(sourcePath);
|
|
455
|
+
if (!success) {
|
|
456
|
+
throw new Error(`ACP session fork was cancelled: ${params.sessionId}`);
|
|
457
|
+
}
|
|
458
|
+
const forked = await session.fork();
|
|
459
|
+
if (!forked) {
|
|
460
|
+
throw new Error(`ACP session fork failed: ${params.sessionId}`);
|
|
461
|
+
}
|
|
462
|
+
} catch (error) {
|
|
463
|
+
await this.#disposeStandaloneSession(session);
|
|
464
|
+
throw error;
|
|
465
|
+
}
|
|
466
|
+
return await this.#registerPreparedSession(session, params.mcpServers ?? []);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
async #openStoredSession(
|
|
470
|
+
sessionPath: string,
|
|
471
|
+
cwd: string,
|
|
472
|
+
mcpServers: McpServer[],
|
|
473
|
+
sessionId: string,
|
|
474
|
+
): Promise<ManagedSessionRecord> {
|
|
475
|
+
const session = await this.#createSession(path.resolve(cwd));
|
|
476
|
+
try {
|
|
477
|
+
const success = await session.switchSession(sessionPath);
|
|
478
|
+
if (!success) {
|
|
479
|
+
throw new Error(`ACP session load was cancelled: ${sessionId}`);
|
|
480
|
+
}
|
|
481
|
+
} catch (error) {
|
|
482
|
+
await this.#disposeStandaloneSession(session);
|
|
483
|
+
throw error;
|
|
484
|
+
}
|
|
485
|
+
return await this.#registerPreparedSession(session, mcpServers);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
async #registerPreparedSession(session: AgentSession, mcpServers: McpServer[]): Promise<ManagedSessionRecord> {
|
|
489
|
+
const record = this.#createManagedSessionRecord(session);
|
|
490
|
+
try {
|
|
491
|
+
await this.#configureExtensions(record);
|
|
492
|
+
await this.#configureMcpServers(record, mcpServers);
|
|
493
|
+
this.#sessions.set(session.sessionId, record);
|
|
494
|
+
return record;
|
|
495
|
+
} catch (error) {
|
|
496
|
+
await this.#disposeSessionRecord(record);
|
|
497
|
+
throw error;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
#createManagedSessionRecord(session: AgentSession): ManagedSessionRecord {
|
|
502
|
+
return {
|
|
503
|
+
session,
|
|
504
|
+
mcpManager: undefined,
|
|
505
|
+
promptTurn: undefined,
|
|
506
|
+
liveMessageIds: new WeakMap<object, string>(),
|
|
507
|
+
extensionsConfigured: false,
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
#getSessionRecord(sessionId: string): ManagedSessionRecord {
|
|
512
|
+
const record = this.#sessions.get(sessionId);
|
|
513
|
+
if (!record) {
|
|
514
|
+
throw new Error(`Unsupported ACP session: ${sessionId}`);
|
|
515
|
+
}
|
|
516
|
+
return record;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
#assertMatchingCwd(session: AgentSession, cwd: string): void {
|
|
520
|
+
const expected = path.resolve(cwd);
|
|
521
|
+
const actual = path.resolve(session.sessionManager.getCwd());
|
|
522
|
+
if (actual !== expected) {
|
|
523
|
+
throw new Error(`ACP session ${session.sessionId} is already loaded for ${actual}, not ${expected}`);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
async #resolveForkSourceSessionPath(sessionId: string): Promise<string> {
|
|
528
|
+
const loaded = this.#sessions.get(sessionId);
|
|
529
|
+
if (loaded) {
|
|
530
|
+
const promptTurn = loaded.promptTurn;
|
|
531
|
+
if (promptTurn && !promptTurn.settled) {
|
|
532
|
+
throw new Error(`ACP session fork is unavailable while a prompt is in progress: ${sessionId}`);
|
|
533
|
+
}
|
|
534
|
+
await loaded.session.sessionManager.flush();
|
|
535
|
+
const sessionPath = loaded.session.sessionManager.getSessionFile();
|
|
536
|
+
if (!sessionPath) {
|
|
537
|
+
throw new Error(`ACP session cannot be forked before it is persisted: ${sessionId}`);
|
|
538
|
+
}
|
|
539
|
+
return sessionPath;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const storedSession = await this.#findStoredSessionById(sessionId);
|
|
543
|
+
if (!storedSession) {
|
|
544
|
+
throw new Error(`ACP session not found: ${sessionId}`);
|
|
545
|
+
}
|
|
546
|
+
return storedSession.path;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
async #handlePromptEvent(record: ManagedSessionRecord, event: AgentSessionEvent): Promise<void> {
|
|
550
|
+
const promptTurn = record.promptTurn;
|
|
551
|
+
if (!promptTurn || promptTurn.settled) {
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
for (const notification of mapAgentSessionEventToAcpSessionUpdates(event, record.session.sessionId, {
|
|
556
|
+
getMessageId: message => this.#getLiveMessageId(record, message),
|
|
557
|
+
})) {
|
|
558
|
+
await this.#connection.sessionUpdate(notification);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (event.type === "agent_end") {
|
|
562
|
+
await this.#emitEndOfTurnUpdates(record);
|
|
563
|
+
this.#finishPrompt(record, {
|
|
564
|
+
stopReason: promptTurn.cancelRequested ? "cancelled" : "end_turn",
|
|
565
|
+
usage: this.#buildTurnUsage(promptTurn.usageBaseline, record.session.sessionManager.getUsageStatistics()),
|
|
566
|
+
userMessageId: promptTurn.userMessageId,
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
#getLiveMessageId(record: ManagedSessionRecord, message: unknown): string | undefined {
|
|
572
|
+
if (typeof message !== "object" || message === null) {
|
|
573
|
+
return undefined;
|
|
574
|
+
}
|
|
575
|
+
const existing = record.liveMessageIds.get(message);
|
|
576
|
+
if (existing) {
|
|
577
|
+
return existing;
|
|
578
|
+
}
|
|
579
|
+
const nextMessageId = crypto.randomUUID();
|
|
580
|
+
record.liveMessageIds.set(message, nextMessageId);
|
|
581
|
+
return nextMessageId;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
#finishPrompt(record: ManagedSessionRecord, response?: PromptResponse, error?: unknown): void {
|
|
585
|
+
const promptTurn = record.promptTurn;
|
|
586
|
+
if (!promptTurn || promptTurn.settled) {
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
promptTurn.settled = true;
|
|
590
|
+
promptTurn.unsubscribe?.();
|
|
591
|
+
record.promptTurn = undefined;
|
|
592
|
+
if (error !== undefined) {
|
|
593
|
+
promptTurn.reject(error);
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
promptTurn.resolve(response ?? { stopReason: "end_turn" });
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
#assertAbsoluteCwd(cwd: string): void {
|
|
600
|
+
if (!path.isAbsolute(cwd)) {
|
|
601
|
+
throw new Error(`ACP cwd must be absolute: ${cwd}`);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
#convertPromptBlocks(blocks: PromptRequest["prompt"]): { text: string; images: AgentImageContent[] } {
|
|
606
|
+
const textParts: string[] = [];
|
|
607
|
+
const images: AgentImageContent[] = [];
|
|
608
|
+
for (const block of blocks) {
|
|
609
|
+
switch (block.type) {
|
|
610
|
+
case "text":
|
|
611
|
+
textParts.push(block.text);
|
|
612
|
+
break;
|
|
613
|
+
case "image":
|
|
614
|
+
images.push({ type: "image", data: block.data, mimeType: block.mimeType });
|
|
615
|
+
break;
|
|
616
|
+
case "resource":
|
|
617
|
+
if ("text" in block.resource) {
|
|
618
|
+
textParts.push(block.resource.text);
|
|
619
|
+
} else {
|
|
620
|
+
textParts.push(`[embedded resource: ${block.resource.uri}]`);
|
|
621
|
+
}
|
|
622
|
+
break;
|
|
623
|
+
case "resource_link":
|
|
624
|
+
textParts.push(block.title ?? block.name ?? block.uri);
|
|
625
|
+
break;
|
|
626
|
+
case "audio":
|
|
627
|
+
textParts.push("[audio omitted]");
|
|
628
|
+
break;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return {
|
|
632
|
+
text: textParts.join("\n\n").trim(),
|
|
633
|
+
images,
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
#buildConfigOptions(session: AgentSession): SessionConfigOption[] {
|
|
638
|
+
const configOptions: SessionConfigOption[] = [
|
|
639
|
+
{
|
|
640
|
+
id: MODE_CONFIG_ID,
|
|
641
|
+
name: "Mode",
|
|
642
|
+
category: "mode",
|
|
643
|
+
type: "select",
|
|
644
|
+
currentValue: ACP_MODE_ID,
|
|
645
|
+
options: [{ value: ACP_MODE_ID, name: "Default", description: "Standard ACP headless mode" }],
|
|
646
|
+
},
|
|
647
|
+
];
|
|
648
|
+
|
|
649
|
+
const models = session.getAvailableModels();
|
|
650
|
+
const currentModel = session.model;
|
|
651
|
+
if (models.length > 0) {
|
|
652
|
+
configOptions.push({
|
|
653
|
+
id: MODEL_CONFIG_ID,
|
|
654
|
+
name: "Model",
|
|
655
|
+
category: "model",
|
|
656
|
+
type: "select",
|
|
657
|
+
currentValue: currentModel ? this.#toModelId(currentModel) : this.#toModelId(models[0]),
|
|
658
|
+
options: models.map(model => ({
|
|
659
|
+
value: this.#toModelId(model),
|
|
660
|
+
name: model.name,
|
|
661
|
+
description: `${model.provider}/${model.id}`,
|
|
662
|
+
})),
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
configOptions.push({
|
|
667
|
+
id: THINKING_CONFIG_ID,
|
|
668
|
+
name: "Thinking",
|
|
669
|
+
category: "thought_level",
|
|
670
|
+
type: "select",
|
|
671
|
+
currentValue: this.#toThinkingConfigValue(session.thinkingLevel),
|
|
672
|
+
options: this.#buildThinkingOptions(session),
|
|
673
|
+
});
|
|
674
|
+
return configOptions;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
#buildModelState(session: AgentSession): SessionModelState | undefined {
|
|
678
|
+
const models = session.getAvailableModels();
|
|
679
|
+
if (models.length === 0) {
|
|
680
|
+
return undefined;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
const availableModels = models.map(model => ({
|
|
684
|
+
modelId: this.#toModelId(model),
|
|
685
|
+
name: model.name,
|
|
686
|
+
description: `${model.provider}/${model.id}`,
|
|
687
|
+
}));
|
|
688
|
+
const currentModelId = session.model ? this.#toModelId(session.model) : availableModels[0]?.modelId;
|
|
689
|
+
if (!currentModelId) {
|
|
690
|
+
return undefined;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
return {
|
|
694
|
+
availableModels,
|
|
695
|
+
currentModelId,
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
#buildThinkingOptions(session: AgentSession): Array<{ value: string; name: string; description?: string }> {
|
|
700
|
+
return [
|
|
701
|
+
{ value: THINKING_OFF, name: "Off" },
|
|
702
|
+
...session.getAvailableThinkingLevels().map(level => ({
|
|
703
|
+
value: level,
|
|
704
|
+
name: level,
|
|
705
|
+
})),
|
|
706
|
+
];
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
#toThinkingConfigValue(value: string | undefined): string {
|
|
710
|
+
return value && value !== "inherit" ? value : THINKING_OFF;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
async #setModelById(session: AgentSession, modelId: string): Promise<void> {
|
|
714
|
+
const model = session.getAvailableModels().find(candidate => this.#toModelId(candidate) === modelId);
|
|
715
|
+
if (!model) {
|
|
716
|
+
throw new Error(`Unknown ACP model: ${modelId}`);
|
|
717
|
+
}
|
|
718
|
+
await session.setModel(model);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
#setThinkingLevelById(session: AgentSession, value: string): void {
|
|
722
|
+
const thinkingLevel = parseThinkingLevel(value);
|
|
723
|
+
if (!thinkingLevel) {
|
|
724
|
+
throw new Error(`Unknown ACP thinking level: ${value}`);
|
|
725
|
+
}
|
|
726
|
+
session.setThinkingLevel(thinkingLevel);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
#toModelId(model: Model): string {
|
|
730
|
+
return `${model.provider}/${model.id}`;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
#buildModeState(): SessionModeState {
|
|
734
|
+
return {
|
|
735
|
+
availableModes: [{ id: ACP_MODE_ID, name: "Default", description: "Standard ACP headless mode" }],
|
|
736
|
+
currentModeId: ACP_MODE_ID,
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
#buildCurrentModeUpdate(): SessionUpdate {
|
|
741
|
+
return {
|
|
742
|
+
sessionUpdate: "current_mode_update",
|
|
743
|
+
currentModeId: ACP_MODE_ID,
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
async #buildAvailableCommands(session: AgentSession): Promise<AvailableCommand[]> {
|
|
748
|
+
const commands: AvailableCommand[] = [];
|
|
749
|
+
const seenNames = new Set<string>();
|
|
750
|
+
const appendCommand = (command: AvailableCommand): void => {
|
|
751
|
+
if (seenNames.has(command.name)) {
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
seenNames.add(command.name);
|
|
755
|
+
commands.push(command);
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
for (const command of session.customCommands) {
|
|
759
|
+
appendCommand({
|
|
760
|
+
name: command.command.name,
|
|
761
|
+
description: command.command.description,
|
|
762
|
+
input: { hint: "arguments" },
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
for (const command of await loadSlashCommands({ cwd: session.sessionManager.getCwd() })) {
|
|
767
|
+
appendCommand({
|
|
768
|
+
name: command.name,
|
|
769
|
+
description: command.description,
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
return commands;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
#toSessionInfo(session: StoredSessionInfo): SessionInfo {
|
|
777
|
+
return {
|
|
778
|
+
sessionId: session.id,
|
|
779
|
+
cwd: session.cwd,
|
|
780
|
+
title: session.title,
|
|
781
|
+
updatedAt: session.modified.toISOString(),
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
#scheduleBootstrapUpdates(sessionId: string): void {
|
|
786
|
+
setTimeout(() => {
|
|
787
|
+
if (this.#connection.signal.aborted) {
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
const record = this.#sessions.get(sessionId);
|
|
791
|
+
if (!record) {
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
void this.#emitBootstrapUpdates(sessionId, record);
|
|
795
|
+
}, 0);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
async #emitBootstrapUpdates(sessionId: string, record: ManagedSessionRecord): Promise<void> {
|
|
799
|
+
if (this.#sessions.get(sessionId) !== record) {
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
await this.#connection.sessionUpdate({
|
|
803
|
+
sessionId,
|
|
804
|
+
update: {
|
|
805
|
+
sessionUpdate: "available_commands_update",
|
|
806
|
+
availableCommands: await this.#buildAvailableCommands(record.session),
|
|
807
|
+
},
|
|
808
|
+
});
|
|
809
|
+
await this.#connection.sessionUpdate({
|
|
810
|
+
sessionId,
|
|
811
|
+
update: {
|
|
812
|
+
sessionUpdate: "session_info_update",
|
|
813
|
+
title: record.session.sessionName,
|
|
814
|
+
updatedAt: record.session.sessionManager.getHeader()?.timestamp,
|
|
815
|
+
},
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
async #emitEndOfTurnUpdates(record: ManagedSessionRecord): Promise<void> {
|
|
820
|
+
const sessionId = record.session.sessionId;
|
|
821
|
+
|
|
822
|
+
const contextUsage = record.session.getContextUsage();
|
|
823
|
+
if (contextUsage) {
|
|
824
|
+
const usageStats = record.session.sessionManager.getUsageStatistics();
|
|
825
|
+
await this.#connection.sessionUpdate({
|
|
826
|
+
sessionId,
|
|
827
|
+
update: {
|
|
828
|
+
sessionUpdate: "usage_update",
|
|
829
|
+
size: contextUsage.contextWindow,
|
|
830
|
+
used: contextUsage.tokens ?? 0,
|
|
831
|
+
cost: usageStats.cost > 0 ? { amount: usageStats.cost, currency: "USD" } : undefined,
|
|
832
|
+
},
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
await this.#connection.sessionUpdate({
|
|
837
|
+
sessionId,
|
|
838
|
+
update: {
|
|
839
|
+
sessionUpdate: "session_info_update",
|
|
840
|
+
title: record.session.sessionName,
|
|
841
|
+
updatedAt: new Date().toISOString(),
|
|
842
|
+
},
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
#cloneUsageStatistics(usage: UsageStatistics): UsageStatistics {
|
|
847
|
+
return {
|
|
848
|
+
input: usage.input,
|
|
849
|
+
output: usage.output,
|
|
850
|
+
cacheRead: usage.cacheRead,
|
|
851
|
+
cacheWrite: usage.cacheWrite,
|
|
852
|
+
premiumRequests: usage.premiumRequests,
|
|
853
|
+
cost: usage.cost,
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
#buildTurnUsage(previous: UsageStatistics, current: UsageStatistics): Usage | undefined {
|
|
858
|
+
const inputTokens = Math.max(0, current.input - previous.input);
|
|
859
|
+
const outputTokens = Math.max(0, current.output - previous.output);
|
|
860
|
+
const cachedReadTokens = Math.max(0, current.cacheRead - previous.cacheRead);
|
|
861
|
+
const cachedWriteTokens = Math.max(0, current.cacheWrite - previous.cacheWrite);
|
|
862
|
+
const totalTokens = inputTokens + outputTokens + cachedReadTokens + cachedWriteTokens;
|
|
863
|
+
|
|
864
|
+
if (totalTokens === 0) {
|
|
865
|
+
return undefined;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
const usage: Usage = {
|
|
869
|
+
inputTokens,
|
|
870
|
+
outputTokens,
|
|
871
|
+
totalTokens,
|
|
872
|
+
};
|
|
873
|
+
if (cachedReadTokens > 0) {
|
|
874
|
+
usage.cachedReadTokens = cachedReadTokens;
|
|
875
|
+
}
|
|
876
|
+
if (cachedWriteTokens > 0) {
|
|
877
|
+
usage.cachedWriteTokens = cachedWriteTokens;
|
|
878
|
+
}
|
|
879
|
+
return usage;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
async #listStoredSessions(cwd?: string): Promise<StoredSessionInfo[]> {
|
|
883
|
+
const sessions = cwd ? await SessionManager.list(cwd) : await SessionManager.listAll();
|
|
884
|
+
return sessions.sort((left, right) => right.modified.getTime() - left.modified.getTime());
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
async #findStoredSession(sessionId: string, cwd: string): Promise<StoredSessionInfo | undefined> {
|
|
888
|
+
const sessions = await this.#listStoredSessions(cwd);
|
|
889
|
+
return sessions.find(session => session.id === sessionId);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
async #findStoredSessionById(sessionId: string): Promise<StoredSessionInfo | undefined> {
|
|
893
|
+
const sessions = await this.#listStoredSessions();
|
|
894
|
+
return sessions.find(session => session.id === sessionId);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
#parseCursor(cursor: string | undefined): number {
|
|
898
|
+
if (!cursor) {
|
|
899
|
+
return 0;
|
|
900
|
+
}
|
|
901
|
+
const parsed = Number.parseInt(cursor, 10);
|
|
902
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
903
|
+
throw new Error(`Invalid ACP session cursor: ${cursor}`);
|
|
904
|
+
}
|
|
905
|
+
return parsed;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
async #replaySessionHistory(record: ManagedSessionRecord): Promise<void> {
|
|
909
|
+
for (const message of record.session.sessionManager.buildSessionContext().messages as ReplayableMessage[]) {
|
|
910
|
+
for (const notification of this.#messageToReplayNotifications(record.session.sessionId, message)) {
|
|
911
|
+
await this.#connection.sessionUpdate(notification);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
#messageToReplayNotifications(sessionId: string, message: ReplayableMessage): SessionNotification[] {
|
|
917
|
+
if (message.role === "assistant") {
|
|
918
|
+
return this.#replayAssistantMessage(sessionId, message);
|
|
919
|
+
}
|
|
920
|
+
if (
|
|
921
|
+
message.role === "user" ||
|
|
922
|
+
message.role === "developer" ||
|
|
923
|
+
message.role === "custom" ||
|
|
924
|
+
message.role === "hookMessage"
|
|
925
|
+
) {
|
|
926
|
+
return this.#wrapReplayContent(
|
|
927
|
+
sessionId,
|
|
928
|
+
this.#extractReplayContent(message.content, undefined),
|
|
929
|
+
"user_message_chunk",
|
|
930
|
+
crypto.randomUUID(),
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
if (
|
|
934
|
+
message.role === "toolResult" &&
|
|
935
|
+
typeof message.toolCallId === "string" &&
|
|
936
|
+
typeof message.toolName === "string"
|
|
937
|
+
) {
|
|
938
|
+
return this.#replayToolResult(sessionId, {
|
|
939
|
+
...message,
|
|
940
|
+
toolCallId: message.toolCallId,
|
|
941
|
+
toolName: message.toolName,
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
if (
|
|
945
|
+
message.role === "bashExecution" ||
|
|
946
|
+
message.role === "pythonExecution" ||
|
|
947
|
+
message.role === "compactionSummary"
|
|
948
|
+
) {
|
|
949
|
+
return this.#wrapReplayContent(
|
|
950
|
+
sessionId,
|
|
951
|
+
this.#extractReplayContent(message.content, undefined),
|
|
952
|
+
"user_message_chunk",
|
|
953
|
+
crypto.randomUUID(),
|
|
954
|
+
);
|
|
955
|
+
}
|
|
956
|
+
return [];
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
#replayAssistantMessage(sessionId: string, message: ReplayableMessage): SessionNotification[] {
|
|
960
|
+
const notifications: SessionNotification[] = [];
|
|
961
|
+
const messageId = crypto.randomUUID();
|
|
962
|
+
if (Array.isArray(message.content)) {
|
|
963
|
+
for (const item of message.content) {
|
|
964
|
+
if (typeof item !== "object" || item === null || !("type" in item)) {
|
|
965
|
+
continue;
|
|
966
|
+
}
|
|
967
|
+
if (item.type === "text" && "text" in item && typeof item.text === "string" && item.text.length > 0) {
|
|
968
|
+
notifications.push({
|
|
969
|
+
sessionId,
|
|
970
|
+
update: {
|
|
971
|
+
sessionUpdate: "agent_message_chunk",
|
|
972
|
+
content: { type: "text", text: item.text },
|
|
973
|
+
messageId,
|
|
974
|
+
},
|
|
975
|
+
});
|
|
976
|
+
continue;
|
|
977
|
+
}
|
|
978
|
+
if (
|
|
979
|
+
item.type === "thinking" &&
|
|
980
|
+
"thinking" in item &&
|
|
981
|
+
typeof item.thinking === "string" &&
|
|
982
|
+
item.thinking.length > 0
|
|
983
|
+
) {
|
|
984
|
+
notifications.push({
|
|
985
|
+
sessionId,
|
|
986
|
+
update: {
|
|
987
|
+
sessionUpdate: "agent_thought_chunk",
|
|
988
|
+
content: { type: "text", text: item.thinking },
|
|
989
|
+
messageId,
|
|
990
|
+
},
|
|
991
|
+
});
|
|
992
|
+
continue;
|
|
993
|
+
}
|
|
994
|
+
if (
|
|
995
|
+
(item.type === "toolCall" || item.type === "tool_use") &&
|
|
996
|
+
"id" in item &&
|
|
997
|
+
typeof item.id === "string" &&
|
|
998
|
+
"name" in item &&
|
|
999
|
+
typeof item.name === "string"
|
|
1000
|
+
) {
|
|
1001
|
+
const update: SessionUpdate = {
|
|
1002
|
+
sessionUpdate: "tool_call",
|
|
1003
|
+
toolCallId: item.id,
|
|
1004
|
+
title: item.name,
|
|
1005
|
+
kind: mapToolKind(item.name),
|
|
1006
|
+
status: "completed",
|
|
1007
|
+
};
|
|
1008
|
+
if ("arguments" in item && typeof item.arguments === "string") {
|
|
1009
|
+
update.rawInput = item.arguments;
|
|
1010
|
+
}
|
|
1011
|
+
notifications.push({ sessionId, update });
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
if (notifications.length === 0 && message.errorMessage) {
|
|
1016
|
+
notifications.push({
|
|
1017
|
+
sessionId,
|
|
1018
|
+
update: {
|
|
1019
|
+
sessionUpdate: "agent_message_chunk",
|
|
1020
|
+
content: { type: "text", text: message.errorMessage },
|
|
1021
|
+
messageId,
|
|
1022
|
+
},
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
return notifications;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
#replayToolResult(
|
|
1029
|
+
sessionId: string,
|
|
1030
|
+
message: Required<Pick<ReplayableMessage, "toolCallId" | "toolName">> & ReplayableMessage,
|
|
1031
|
+
): SessionNotification[] {
|
|
1032
|
+
const args = this.#buildReplayToolArgs(message.details);
|
|
1033
|
+
const startEvent: AgentSessionEvent = {
|
|
1034
|
+
type: "tool_execution_start",
|
|
1035
|
+
toolCallId: message.toolCallId,
|
|
1036
|
+
toolName: message.toolName,
|
|
1037
|
+
args,
|
|
1038
|
+
};
|
|
1039
|
+
const endEvent: AgentSessionEvent = {
|
|
1040
|
+
type: "tool_execution_end",
|
|
1041
|
+
toolCallId: message.toolCallId,
|
|
1042
|
+
toolName: message.toolName,
|
|
1043
|
+
isError: message.isError === true,
|
|
1044
|
+
result: {
|
|
1045
|
+
content: message.content,
|
|
1046
|
+
details: message.details,
|
|
1047
|
+
errorMessage: message.errorMessage,
|
|
1048
|
+
},
|
|
1049
|
+
};
|
|
1050
|
+
return [
|
|
1051
|
+
...mapAgentSessionEventToAcpSessionUpdates(startEvent, sessionId),
|
|
1052
|
+
...mapAgentSessionEventToAcpSessionUpdates(endEvent, sessionId),
|
|
1053
|
+
];
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
#buildReplayToolArgs(details: unknown): { path?: string } {
|
|
1057
|
+
if (typeof details !== "object" || details === null || !("path" in details)) {
|
|
1058
|
+
return {};
|
|
1059
|
+
}
|
|
1060
|
+
const value = (details as { path?: unknown }).path;
|
|
1061
|
+
return typeof value === "string" && value.length > 0 ? { path: value } : {};
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
#wrapReplayContent(
|
|
1065
|
+
sessionId: string,
|
|
1066
|
+
content: PromptRequest["prompt"],
|
|
1067
|
+
kind: "agent_message_chunk" | "user_message_chunk",
|
|
1068
|
+
messageId: string,
|
|
1069
|
+
): SessionNotification[] {
|
|
1070
|
+
return content.map(block => ({
|
|
1071
|
+
sessionId,
|
|
1072
|
+
update: {
|
|
1073
|
+
sessionUpdate: kind,
|
|
1074
|
+
content: block,
|
|
1075
|
+
messageId,
|
|
1076
|
+
},
|
|
1077
|
+
}));
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
#extractReplayContent(content: unknown, errorMessage: string | undefined): PromptRequest["prompt"] {
|
|
1081
|
+
const replay: PromptRequest["prompt"] = [];
|
|
1082
|
+
if (Array.isArray(content)) {
|
|
1083
|
+
for (const item of content) {
|
|
1084
|
+
if (typeof item !== "object" || item === null || !("type" in item)) {
|
|
1085
|
+
continue;
|
|
1086
|
+
}
|
|
1087
|
+
if (item.type === "text" && "text" in item && typeof item.text === "string" && item.text.length > 0) {
|
|
1088
|
+
replay.push({ type: "text", text: item.text });
|
|
1089
|
+
continue;
|
|
1090
|
+
}
|
|
1091
|
+
if (
|
|
1092
|
+
item.type === "image" &&
|
|
1093
|
+
"data" in item &&
|
|
1094
|
+
"mimeType" in item &&
|
|
1095
|
+
typeof item.data === "string" &&
|
|
1096
|
+
typeof item.mimeType === "string"
|
|
1097
|
+
) {
|
|
1098
|
+
replay.push({ type: "image", data: item.data, mimeType: item.mimeType });
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
if (replay.length === 0 && errorMessage) {
|
|
1103
|
+
replay.push({ type: "text", text: errorMessage });
|
|
1104
|
+
}
|
|
1105
|
+
return replay;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
async #configureExtensions(record: ManagedSessionRecord): Promise<void> {
|
|
1109
|
+
if (record.extensionsConfigured) {
|
|
1110
|
+
return;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
const extensionRunner = record.session.extensionRunner;
|
|
1114
|
+
if (!extensionRunner) {
|
|
1115
|
+
record.extensionsConfigured = true;
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
extensionRunner.initialize(
|
|
1120
|
+
{
|
|
1121
|
+
sendMessage: (message, options) => {
|
|
1122
|
+
record.session.sendCustomMessage(message, options).catch((error: unknown) => {
|
|
1123
|
+
logger.warn("ACP extension sendMessage failed", { error });
|
|
1124
|
+
});
|
|
1125
|
+
},
|
|
1126
|
+
sendUserMessage: (content, options) => {
|
|
1127
|
+
record.session.sendUserMessage(content, options).catch((error: unknown) => {
|
|
1128
|
+
logger.warn("ACP extension sendUserMessage failed", { error });
|
|
1129
|
+
});
|
|
1130
|
+
},
|
|
1131
|
+
appendEntry: (customType, data) => {
|
|
1132
|
+
record.session.sessionManager.appendCustomEntry(customType, data);
|
|
1133
|
+
},
|
|
1134
|
+
setLabel: (targetId, label) => {
|
|
1135
|
+
record.session.sessionManager.appendLabelChange(targetId, label);
|
|
1136
|
+
},
|
|
1137
|
+
getActiveTools: () => record.session.getActiveToolNames(),
|
|
1138
|
+
getAllTools: () => record.session.getAllToolNames(),
|
|
1139
|
+
setActiveTools: toolNames => record.session.setActiveToolsByName(toolNames),
|
|
1140
|
+
getCommands: () => [],
|
|
1141
|
+
setModel: async model => {
|
|
1142
|
+
const apiKey = await record.session.modelRegistry.getApiKey(model);
|
|
1143
|
+
if (!apiKey) {
|
|
1144
|
+
return false;
|
|
1145
|
+
}
|
|
1146
|
+
await record.session.setModel(model);
|
|
1147
|
+
return true;
|
|
1148
|
+
},
|
|
1149
|
+
getThinkingLevel: () => record.session.thinkingLevel,
|
|
1150
|
+
setThinkingLevel: level => record.session.setThinkingLevel(level),
|
|
1151
|
+
getSessionName: () => record.session.sessionManager.getSessionName(),
|
|
1152
|
+
setSessionName: async name => {
|
|
1153
|
+
await record.session.sessionManager.setSessionName(name, "user");
|
|
1154
|
+
},
|
|
1155
|
+
},
|
|
1156
|
+
{
|
|
1157
|
+
getModel: () => record.session.model,
|
|
1158
|
+
isIdle: () => !record.session.isStreaming,
|
|
1159
|
+
abort: () => {
|
|
1160
|
+
void record.session.abort();
|
|
1161
|
+
},
|
|
1162
|
+
hasPendingMessages: () => record.session.queuedMessageCount > 0,
|
|
1163
|
+
shutdown: () => {},
|
|
1164
|
+
getContextUsage: () => record.session.getContextUsage(),
|
|
1165
|
+
getSystemPrompt: () => record.session.systemPrompt,
|
|
1166
|
+
compact: async instructionsOrOptions => {
|
|
1167
|
+
const instructions = typeof instructionsOrOptions === "string" ? instructionsOrOptions : undefined;
|
|
1168
|
+
const options =
|
|
1169
|
+
instructionsOrOptions && typeof instructionsOrOptions === "object"
|
|
1170
|
+
? instructionsOrOptions
|
|
1171
|
+
: undefined;
|
|
1172
|
+
await record.session.compact(instructions, options);
|
|
1173
|
+
},
|
|
1174
|
+
},
|
|
1175
|
+
{
|
|
1176
|
+
getContextUsage: () => record.session.getContextUsage(),
|
|
1177
|
+
waitForIdle: () => record.session.agent.waitForIdle(),
|
|
1178
|
+
newSession: async options => {
|
|
1179
|
+
const success = await record.session.newSession({ parentSession: options?.parentSession });
|
|
1180
|
+
if (success && options?.setup) {
|
|
1181
|
+
await options.setup(record.session.sessionManager);
|
|
1182
|
+
}
|
|
1183
|
+
return { cancelled: !success };
|
|
1184
|
+
},
|
|
1185
|
+
branch: async entryId => {
|
|
1186
|
+
const result = await record.session.branch(entryId);
|
|
1187
|
+
return { cancelled: result.cancelled };
|
|
1188
|
+
},
|
|
1189
|
+
navigateTree: async (targetId, options) => {
|
|
1190
|
+
const result = await record.session.navigateTree(targetId, { summarize: options?.summarize });
|
|
1191
|
+
return { cancelled: result.cancelled };
|
|
1192
|
+
},
|
|
1193
|
+
switchSession: async sessionPath => {
|
|
1194
|
+
const success = await record.session.switchSession(sessionPath);
|
|
1195
|
+
return { cancelled: !success };
|
|
1196
|
+
},
|
|
1197
|
+
reload: async () => {
|
|
1198
|
+
await record.session.reload();
|
|
1199
|
+
},
|
|
1200
|
+
compact: async instructionsOrOptions => {
|
|
1201
|
+
const instructions = typeof instructionsOrOptions === "string" ? instructionsOrOptions : undefined;
|
|
1202
|
+
const options =
|
|
1203
|
+
instructionsOrOptions && typeof instructionsOrOptions === "object"
|
|
1204
|
+
? instructionsOrOptions
|
|
1205
|
+
: undefined;
|
|
1206
|
+
await record.session.compact(instructions, options);
|
|
1207
|
+
},
|
|
1208
|
+
},
|
|
1209
|
+
acpExtensionUiContext,
|
|
1210
|
+
);
|
|
1211
|
+
await extensionRunner.emit({ type: "session_start" });
|
|
1212
|
+
record.extensionsConfigured = true;
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
async #configureMcpServers(record: ManagedSessionRecord, servers: McpServer[]): Promise<void> {
|
|
1216
|
+
if (record.mcpManager) {
|
|
1217
|
+
await record.mcpManager.disconnectAll();
|
|
1218
|
+
}
|
|
1219
|
+
if (servers.length === 0) {
|
|
1220
|
+
record.mcpManager = undefined;
|
|
1221
|
+
await record.session.refreshMCPTools([]);
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
const manager = new MCPManager(record.session.sessionManager.getCwd());
|
|
1226
|
+
const configs: MCPConfigMap = {};
|
|
1227
|
+
const sources: MCPSourceMap = {};
|
|
1228
|
+
for (const server of servers) {
|
|
1229
|
+
configs[server.name] = this.#toMcpConfig(server);
|
|
1230
|
+
sources[server.name] = {
|
|
1231
|
+
provider: "acp",
|
|
1232
|
+
providerName: "ACP Client",
|
|
1233
|
+
path: `acp://${server.name}`,
|
|
1234
|
+
level: "project",
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
const result = await manager.connectServers(configs, sources);
|
|
1239
|
+
if (result.errors.size > 0) {
|
|
1240
|
+
throw new Error(
|
|
1241
|
+
Array.from(result.errors.entries())
|
|
1242
|
+
.map(([name, message]) => `${name}: ${message}`)
|
|
1243
|
+
.join("; "),
|
|
1244
|
+
);
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
record.mcpManager = manager;
|
|
1248
|
+
await record.session.refreshMCPTools(result.tools);
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
#toMcpConfig(server: McpServer): MCPServerConfig {
|
|
1252
|
+
if ("command" in server) {
|
|
1253
|
+
return {
|
|
1254
|
+
type: "stdio",
|
|
1255
|
+
command: server.command,
|
|
1256
|
+
args: server.args,
|
|
1257
|
+
env: this.#toNameValueMap(server.env),
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
if (server.type === "http") {
|
|
1261
|
+
return {
|
|
1262
|
+
type: "http",
|
|
1263
|
+
url: server.url,
|
|
1264
|
+
headers: this.#toNameValueMap(server.headers),
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
return {
|
|
1268
|
+
type: "sse",
|
|
1269
|
+
url: server.url,
|
|
1270
|
+
headers: this.#toNameValueMap(server.headers),
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
#toNameValueMap(values: Array<{ name: string; value: string }>): { [name: string]: string } {
|
|
1275
|
+
const mapped: { [name: string]: string } = {};
|
|
1276
|
+
for (const value of values) {
|
|
1277
|
+
mapped[value.name] = value.value;
|
|
1278
|
+
}
|
|
1279
|
+
return mapped;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
async #closeManagedSession(sessionId: string, record: ManagedSessionRecord): Promise<void> {
|
|
1283
|
+
this.#sessions.delete(sessionId);
|
|
1284
|
+
await this.#cancelPromptForClose(record);
|
|
1285
|
+
await this.#disposeSessionRecord(record);
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
async #cancelPromptForClose(record: ManagedSessionRecord): Promise<void> {
|
|
1289
|
+
const promptTurn = record.promptTurn;
|
|
1290
|
+
if (!promptTurn || promptTurn.settled) {
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
promptTurn.cancelRequested = true;
|
|
1295
|
+
promptTurn.unsubscribe?.();
|
|
1296
|
+
try {
|
|
1297
|
+
await record.session.abort();
|
|
1298
|
+
} catch (error) {
|
|
1299
|
+
logger.warn("Failed to abort ACP prompt during session close", { error });
|
|
1300
|
+
}
|
|
1301
|
+
this.#finishPrompt(record, {
|
|
1302
|
+
stopReason: "cancelled",
|
|
1303
|
+
usage: this.#buildTurnUsage(promptTurn.usageBaseline, record.session.sessionManager.getUsageStatistics()),
|
|
1304
|
+
userMessageId: promptTurn.userMessageId,
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
async #disposeSessionRecord(record: ManagedSessionRecord): Promise<void> {
|
|
1309
|
+
if (record.mcpManager) {
|
|
1310
|
+
try {
|
|
1311
|
+
await record.mcpManager.disconnectAll();
|
|
1312
|
+
} catch (error) {
|
|
1313
|
+
logger.warn("Failed to disconnect ACP MCP servers", { error });
|
|
1314
|
+
}
|
|
1315
|
+
record.mcpManager = undefined;
|
|
1316
|
+
}
|
|
1317
|
+
try {
|
|
1318
|
+
await record.session.dispose();
|
|
1319
|
+
} catch (error) {
|
|
1320
|
+
logger.warn("Failed to dispose ACP session", { error });
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
async #disposeStandaloneSession(session: AgentSession): Promise<void> {
|
|
1325
|
+
try {
|
|
1326
|
+
await session.dispose();
|
|
1327
|
+
} catch (error) {
|
|
1328
|
+
logger.warn("Failed to dispose ACP session", { error });
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
async #disposeAllSessions(): Promise<void> {
|
|
1333
|
+
if (this.#disposePromise) {
|
|
1334
|
+
await this.#disposePromise;
|
|
1335
|
+
return;
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
this.#disposePromise = (async () => {
|
|
1339
|
+
const records = Array.from(this.#sessions.entries());
|
|
1340
|
+
this.#sessions.clear();
|
|
1341
|
+
await Promise.all(
|
|
1342
|
+
records.map(async ([sessionId, record]) => {
|
|
1343
|
+
try {
|
|
1344
|
+
await this.#cancelPromptForClose(record);
|
|
1345
|
+
await this.#disposeSessionRecord(record);
|
|
1346
|
+
} catch (error) {
|
|
1347
|
+
logger.warn("Failed to clean up ACP session", { sessionId, error });
|
|
1348
|
+
}
|
|
1349
|
+
}),
|
|
1350
|
+
);
|
|
1351
|
+
|
|
1352
|
+
const initialSession = this.#initialSession;
|
|
1353
|
+
this.#initialSession = undefined;
|
|
1354
|
+
if (initialSession) {
|
|
1355
|
+
await this.#disposeStandaloneSession(initialSession);
|
|
1356
|
+
}
|
|
1357
|
+
})();
|
|
1358
|
+
|
|
1359
|
+
await this.#disposePromise;
|
|
1360
|
+
}
|
|
1361
|
+
}
|