@prestyj/cli 5.9.0 → 5.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -5
- package/assets/skills/evidence-led-ui/SKILL.md +1 -1
- package/dist/app-sidecar-auth-broadcast.test.d.ts +2 -0
- package/dist/app-sidecar-auth-broadcast.test.d.ts.map +1 -0
- package/dist/app-sidecar-auth-broadcast.test.js +282 -0
- package/dist/app-sidecar-auth-broadcast.test.js.map +1 -0
- package/dist/app-sidecar-sessions.d.ts +5 -2
- package/dist/app-sidecar-sessions.d.ts.map +1 -1
- package/dist/app-sidecar-sessions.js +34 -8
- package/dist/app-sidecar-sessions.js.map +1 -1
- package/dist/app-sidecar-sessions.test.js +95 -0
- package/dist/app-sidecar-sessions.test.js.map +1 -1
- package/dist/app-sidecar.js +871 -142
- package/dist/app-sidecar.js.map +1 -1
- package/dist/chat-agents/general.test.js +5 -3
- package/dist/chat-agents/general.test.js.map +1 -1
- package/dist/chat-agents/memory.d.ts.map +1 -1
- package/dist/chat-agents/memory.js +14 -5
- package/dist/chat-agents/memory.js.map +1 -1
- package/dist/chat-agents/memory.test.js +11 -1
- package/dist/chat-agents/memory.test.js.map +1 -1
- package/dist/chat-agents/shared.js +1 -1
- package/dist/chat-agents/shared.js.map +1 -1
- package/dist/chat-agents/specialists.test.js +3 -2
- package/dist/chat-agents/specialists.test.js.map +1 -1
- package/dist/cli/command-routing.d.ts +1 -1
- package/dist/cli/command-routing.d.ts.map +1 -1
- package/dist/cli/command-routing.js +1 -0
- package/dist/cli/command-routing.js.map +1 -1
- package/dist/cli/command-routing.test.js +1 -0
- package/dist/cli/command-routing.test.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +183 -51
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +16 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +51 -2
- package/dist/config.js.map +1 -1
- package/dist/config.test.js +71 -2
- package/dist/config.test.js.map +1 -1
- package/dist/core/agent-mcp-passthrough.test.d.ts +2 -0
- package/dist/core/agent-mcp-passthrough.test.d.ts.map +1 -0
- package/dist/core/agent-mcp-passthrough.test.js +61 -0
- package/dist/core/agent-mcp-passthrough.test.js.map +1 -0
- package/dist/core/agent-notifications.d.ts +62 -0
- package/dist/core/agent-notifications.d.ts.map +1 -0
- package/dist/core/agent-notifications.js +92 -0
- package/dist/core/agent-notifications.js.map +1 -0
- package/dist/core/agent-notifications.test.d.ts +2 -0
- package/dist/core/agent-notifications.test.d.ts.map +1 -0
- package/dist/core/agent-notifications.test.js +97 -0
- package/dist/core/agent-notifications.test.js.map +1 -0
- package/dist/core/agent-session-add-dir.test.d.ts +2 -0
- package/dist/core/agent-session-add-dir.test.d.ts.map +1 -0
- package/dist/core/agent-session-add-dir.test.js +110 -0
- package/dist/core/agent-session-add-dir.test.js.map +1 -0
- package/dist/core/agent-session-checkpoint-flush.test.d.ts +2 -0
- package/dist/core/agent-session-checkpoint-flush.test.d.ts.map +1 -0
- package/dist/core/agent-session-checkpoint-flush.test.js +201 -0
- package/dist/core/agent-session-checkpoint-flush.test.js.map +1 -0
- package/dist/core/agent-session-compaction.test.js +327 -13
- package/dist/core/agent-session-compaction.test.js.map +1 -1
- package/dist/core/agent-session-crash-durability.test.d.ts +2 -0
- package/dist/core/agent-session-crash-durability.test.d.ts.map +1 -0
- package/dist/core/agent-session-crash-durability.test.js +102 -0
- package/dist/core/agent-session-crash-durability.test.js.map +1 -0
- package/dist/core/agent-session-marker-anchors.test.d.ts +2 -0
- package/dist/core/agent-session-marker-anchors.test.d.ts.map +1 -0
- package/dist/core/agent-session-marker-anchors.test.js +326 -0
- package/dist/core/agent-session-marker-anchors.test.js.map +1 -0
- package/dist/core/agent-session-memory-tail.test.js +4 -7
- package/dist/core/agent-session-memory-tail.test.js.map +1 -1
- package/dist/core/agent-session-model-switch.test.d.ts +2 -0
- package/dist/core/agent-session-model-switch.test.d.ts.map +1 -0
- package/dist/core/agent-session-model-switch.test.js +161 -0
- package/dist/core/agent-session-model-switch.test.js.map +1 -0
- package/dist/core/agent-session-notifications.test.d.ts +2 -0
- package/dist/core/agent-session-notifications.test.d.ts.map +1 -0
- package/dist/core/agent-session-notifications.test.js +114 -0
- package/dist/core/agent-session-notifications.test.js.map +1 -0
- package/dist/core/agent-session-process-gate.test.d.ts +2 -0
- package/dist/core/agent-session-process-gate.test.d.ts.map +1 -0
- package/dist/core/agent-session-process-gate.test.js +92 -0
- package/dist/core/agent-session-process-gate.test.js.map +1 -0
- package/dist/core/agent-session-queue.test.js +69 -7
- package/dist/core/agent-session-queue.test.js.map +1 -1
- package/dist/core/agent-session-review-coverage.test.js +80 -23
- package/dist/core/agent-session-review-coverage.test.js.map +1 -1
- package/dist/core/agent-session-slash-restore.test.d.ts +2 -0
- package/dist/core/agent-session-slash-restore.test.d.ts.map +1 -0
- package/dist/core/agent-session-slash-restore.test.js +121 -0
- package/dist/core/agent-session-slash-restore.test.js.map +1 -0
- package/dist/core/agent-session-subagent-policy.test.js +7 -3
- package/dist/core/agent-session-subagent-policy.test.js.map +1 -1
- package/dist/core/agent-session.d.ts +256 -10
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +1071 -219
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/agent-tools-allowlist.test.js +5 -3
- package/dist/core/agent-tools-allowlist.test.js.map +1 -1
- package/dist/core/agents.d.ts +11 -0
- package/dist/core/agents.d.ts.map +1 -1
- package/dist/core/agents.js +21 -0
- package/dist/core/agents.js.map +1 -1
- package/dist/core/agents.test.d.ts +2 -0
- package/dist/core/agents.test.d.ts.map +1 -0
- package/dist/core/agents.test.js +67 -0
- package/dist/core/agents.test.js.map +1 -0
- package/dist/core/auth-providers.js +1 -1
- package/dist/core/auth-providers.js.map +1 -1
- package/dist/core/compaction/active-context.test.js +21 -0
- package/dist/core/compaction/active-context.test.js.map +1 -1
- package/dist/core/compaction/compactor.d.ts +108 -8
- package/dist/core/compaction/compactor.d.ts.map +1 -1
- package/dist/core/compaction/compactor.js +423 -119
- package/dist/core/compaction/compactor.js.map +1 -1
- package/dist/core/compaction/compactor.test.js +361 -9
- package/dist/core/compaction/compactor.test.js.map +1 -1
- package/dist/core/compaction/policy.d.ts +17 -0
- package/dist/core/compaction/policy.d.ts.map +1 -0
- package/dist/core/compaction/policy.js +22 -0
- package/dist/core/compaction/policy.js.map +1 -0
- package/dist/core/compaction/policy.test.d.ts +2 -0
- package/dist/core/compaction/policy.test.d.ts.map +1 -0
- package/dist/core/compaction/policy.test.js +35 -0
- package/dist/core/compaction/policy.test.js.map +1 -0
- package/dist/core/compaction/query-aware-selector.d.ts +33 -0
- package/dist/core/compaction/query-aware-selector.d.ts.map +1 -0
- package/dist/core/compaction/query-aware-selector.js +202 -0
- package/dist/core/compaction/query-aware-selector.js.map +1 -0
- package/dist/core/compaction/query-aware-selector.test.d.ts +2 -0
- package/dist/core/compaction/query-aware-selector.test.d.ts.map +1 -0
- package/dist/core/compaction/query-aware-selector.test.js +96 -0
- package/dist/core/compaction/query-aware-selector.test.js.map +1 -0
- package/dist/core/compaction/token-estimator.test.js +1 -1
- package/dist/core/compaction/token-estimator.test.js.map +1 -1
- package/dist/core/compaction/tool-result-pruner.d.ts +24 -11
- package/dist/core/compaction/tool-result-pruner.d.ts.map +1 -1
- package/dist/core/compaction/tool-result-pruner.js +98 -26
- package/dist/core/compaction/tool-result-pruner.js.map +1 -1
- package/dist/core/compaction/tool-result-pruner.test.js +178 -6
- package/dist/core/compaction/tool-result-pruner.test.js.map +1 -1
- package/dist/core/encode-cwd.d.ts +17 -0
- package/dist/core/encode-cwd.d.ts.map +1 -1
- package/dist/core/encode-cwd.js +20 -7
- package/dist/core/encode-cwd.js.map +1 -1
- package/dist/core/encode-cwd.test.js +20 -1
- package/dist/core/encode-cwd.test.js.map +1 -1
- package/dist/core/event-bus.d.ts +23 -0
- package/dist/core/event-bus.d.ts.map +1 -1
- package/dist/core/event-bus.js +10 -0
- package/dist/core/event-bus.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +28 -8
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/plugin-bundles.d.ts +23 -0
- package/dist/core/extensions/plugin-bundles.d.ts.map +1 -0
- package/dist/core/extensions/plugin-bundles.js +228 -0
- package/dist/core/extensions/plugin-bundles.js.map +1 -0
- package/dist/core/extensions/plugin-bundles.test.d.ts +2 -0
- package/dist/core/extensions/plugin-bundles.test.d.ts.map +1 -0
- package/dist/core/extensions/plugin-bundles.test.js +110 -0
- package/dist/core/extensions/plugin-bundles.test.js.map +1 -0
- package/dist/core/foreign-session-import.d.ts +120 -0
- package/dist/core/foreign-session-import.d.ts.map +1 -0
- package/dist/core/foreign-session-import.js +598 -0
- package/dist/core/foreign-session-import.js.map +1 -0
- package/dist/core/foreign-session-import.test.d.ts +2 -0
- package/dist/core/foreign-session-import.test.d.ts.map +1 -0
- package/dist/core/foreign-session-import.test.js +220 -0
- package/dist/core/foreign-session-import.test.js.map +1 -0
- package/dist/core/foreign-transcript-blocks.d.ts +51 -0
- package/dist/core/foreign-transcript-blocks.d.ts.map +1 -0
- package/dist/core/foreign-transcript-blocks.js +151 -0
- package/dist/core/foreign-transcript-blocks.js.map +1 -0
- package/dist/core/ideal-review.d.ts +20 -1
- package/dist/core/ideal-review.d.ts.map +1 -1
- package/dist/core/ideal-review.js +43 -3
- package/dist/core/ideal-review.js.map +1 -1
- package/dist/core/ideal-review.test.js +106 -5
- package/dist/core/ideal-review.test.js.map +1 -1
- package/dist/core/local-endpoint-store.d.ts +50 -0
- package/dist/core/local-endpoint-store.d.ts.map +1 -0
- package/dist/core/local-endpoint-store.js +201 -0
- package/dist/core/local-endpoint-store.js.map +1 -0
- package/dist/core/local-endpoint-store.test.d.ts +2 -0
- package/dist/core/local-endpoint-store.test.d.ts.map +1 -0
- package/dist/core/local-endpoint-store.test.js +131 -0
- package/dist/core/local-endpoint-store.test.js.map +1 -0
- package/dist/core/loop-breaker.d.ts.map +1 -1
- package/dist/core/loop-breaker.js +1 -0
- package/dist/core/loop-breaker.js.map +1 -1
- package/dist/core/lsp/client.d.ts +65 -0
- package/dist/core/lsp/client.d.ts.map +1 -1
- package/dist/core/lsp/client.js +197 -14
- package/dist/core/lsp/client.js.map +1 -1
- package/dist/core/lsp/jsonrpc.d.ts +38 -1
- package/dist/core/lsp/jsonrpc.d.ts.map +1 -1
- package/dist/core/lsp/jsonrpc.js +13 -1
- package/dist/core/lsp/jsonrpc.js.map +1 -1
- package/dist/core/lsp/manager.d.ts +47 -9
- package/dist/core/lsp/manager.d.ts.map +1 -1
- package/dist/core/lsp/manager.js +107 -59
- package/dist/core/lsp/manager.js.map +1 -1
- package/dist/core/lsp/manager.test.js +50 -1
- package/dist/core/lsp/manager.test.js.map +1 -1
- package/dist/core/lsp/pool.d.ts +113 -0
- package/dist/core/lsp/pool.d.ts.map +1 -0
- package/dist/core/lsp/pool.js +255 -0
- package/dist/core/lsp/pool.js.map +1 -0
- package/dist/core/lsp/pool.test.d.ts +2 -0
- package/dist/core/lsp/pool.test.d.ts.map +1 -0
- package/dist/core/lsp/pool.test.js +286 -0
- package/dist/core/lsp/pool.test.js.map +1 -0
- package/dist/core/lsp/servers.d.ts.map +1 -1
- package/dist/core/lsp/servers.js +43 -3
- package/dist/core/lsp/servers.js.map +1 -1
- package/dist/core/lsp/servers.test.d.ts +2 -0
- package/dist/core/lsp/servers.test.d.ts.map +1 -0
- package/dist/core/lsp/servers.test.js +67 -0
- package/dist/core/lsp/servers.test.js.map +1 -0
- package/dist/core/lsp/test-support.d.ts +18 -0
- package/dist/core/lsp/test-support.d.ts.map +1 -0
- package/dist/core/lsp/test-support.js +27 -0
- package/dist/core/lsp/test-support.js.map +1 -0
- package/dist/core/lsp/uri.test.d.ts +2 -0
- package/dist/core/lsp/uri.test.d.ts.map +1 -0
- package/dist/core/lsp/uri.test.js +56 -0
- package/dist/core/lsp/uri.test.js.map +1 -0
- package/dist/core/lsp/windows.test.d.ts +2 -0
- package/dist/core/lsp/windows.test.d.ts.map +1 -0
- package/dist/core/lsp/windows.test.js +239 -0
- package/dist/core/lsp/windows.test.js.map +1 -0
- package/dist/core/mcp/catalog-cache.d.ts +63 -0
- package/dist/core/mcp/catalog-cache.d.ts.map +1 -0
- package/dist/core/mcp/catalog-cache.js +163 -0
- package/dist/core/mcp/catalog-cache.js.map +1 -0
- package/dist/core/mcp/catalog-cache.test.d.ts +2 -0
- package/dist/core/mcp/catalog-cache.test.d.ts.map +1 -0
- package/dist/core/mcp/catalog-cache.test.js +99 -0
- package/dist/core/mcp/catalog-cache.test.js.map +1 -0
- package/dist/core/mcp/client-session-recovery.test.d.ts +2 -0
- package/dist/core/mcp/client-session-recovery.test.d.ts.map +1 -0
- package/dist/core/mcp/client-session-recovery.test.js +231 -0
- package/dist/core/mcp/client-session-recovery.test.js.map +1 -0
- package/dist/core/mcp/client.d.ts +158 -0
- package/dist/core/mcp/client.d.ts.map +1 -1
- package/dist/core/mcp/client.js +476 -35
- package/dist/core/mcp/client.js.map +1 -1
- package/dist/core/mcp/elicitation-bridge.d.ts +41 -0
- package/dist/core/mcp/elicitation-bridge.d.ts.map +1 -0
- package/dist/core/mcp/elicitation-bridge.js +52 -0
- package/dist/core/mcp/elicitation-bridge.js.map +1 -0
- package/dist/core/mcp/elicitation.test.d.ts +2 -0
- package/dist/core/mcp/elicitation.test.d.ts.map +1 -0
- package/dist/core/mcp/elicitation.test.js +158 -0
- package/dist/core/mcp/elicitation.test.js.map +1 -0
- package/dist/core/mcp/index.d.ts +5 -1
- package/dist/core/mcp/index.d.ts.map +1 -1
- package/dist/core/mcp/index.js +2 -0
- package/dist/core/mcp/index.js.map +1 -1
- package/dist/core/mcp/legacy-negotiation.test.d.ts +2 -0
- package/dist/core/mcp/legacy-negotiation.test.d.ts.map +1 -0
- package/dist/core/mcp/legacy-negotiation.test.js +80 -0
- package/dist/core/mcp/legacy-negotiation.test.js.map +1 -0
- package/dist/core/mcp/oauth-provider.d.ts +1 -2
- package/dist/core/mcp/oauth-provider.d.ts.map +1 -1
- package/dist/core/mcp/oauth-provider.js +6 -2
- package/dist/core/mcp/oauth-provider.js.map +1 -1
- package/dist/core/mcp/oauth-store.d.ts +1 -1
- package/dist/core/mcp/oauth-store.d.ts.map +1 -1
- package/dist/core/mcp/oauth-store.js.map +1 -1
- package/dist/core/mcp/resolve-stdio.d.ts +35 -0
- package/dist/core/mcp/resolve-stdio.d.ts.map +1 -1
- package/dist/core/mcp/resolve-stdio.js +80 -1
- package/dist/core/mcp/resolve-stdio.js.map +1 -1
- package/dist/core/mcp/resolve-stdio.test.js +99 -4
- package/dist/core/mcp/resolve-stdio.test.js.map +1 -1
- package/dist/core/mcp/session-elicitation-wiring.test.d.ts +2 -0
- package/dist/core/mcp/session-elicitation-wiring.test.d.ts.map +1 -0
- package/dist/core/mcp/session-elicitation-wiring.test.js +138 -0
- package/dist/core/mcp/session-elicitation-wiring.test.js.map +1 -0
- package/dist/core/mcp/shared-pool.d.ts +158 -0
- package/dist/core/mcp/shared-pool.d.ts.map +1 -0
- package/dist/core/mcp/shared-pool.js +235 -0
- package/dist/core/mcp/shared-pool.js.map +1 -0
- package/dist/core/mcp/shared-pool.test.d.ts +2 -0
- package/dist/core/mcp/shared-pool.test.d.ts.map +1 -0
- package/dist/core/mcp/shared-pool.test.js +425 -0
- package/dist/core/mcp/shared-pool.test.js.map +1 -0
- package/dist/core/mcp/types.d.ts +12 -0
- package/dist/core/mcp/types.d.ts.map +1 -1
- package/dist/core/mcp/when-connected.test.d.ts +2 -0
- package/dist/core/mcp/when-connected.test.d.ts.map +1 -0
- package/dist/core/mcp/when-connected.test.js +46 -0
- package/dist/core/mcp/when-connected.test.js.map +1 -0
- package/dist/core/network-guard.d.ts +47 -0
- package/dist/core/network-guard.d.ts.map +1 -0
- package/dist/core/network-guard.js +208 -0
- package/dist/core/network-guard.js.map +1 -0
- package/dist/core/network-guard.test.d.ts +2 -0
- package/dist/core/network-guard.test.d.ts.map +1 -0
- package/dist/core/network-guard.test.js +72 -0
- package/dist/core/network-guard.test.js.map +1 -0
- package/dist/core/nolan-context.d.ts.map +1 -1
- package/dist/core/nolan-context.js +8 -0
- package/dist/core/nolan-context.js.map +1 -1
- package/dist/core/nolan-context.test.js +40 -0
- package/dist/core/nolan-context.test.js.map +1 -1
- package/dist/core/nolan-prompt.js +3 -0
- package/dist/core/nolan-prompt.js.map +1 -1
- package/dist/core/nolan-prompt.test.js +5 -0
- package/dist/core/nolan-prompt.test.js.map +1 -1
- package/dist/core/persistent-shell.d.ts +4 -1
- package/dist/core/persistent-shell.d.ts.map +1 -1
- package/dist/core/persistent-shell.js +21 -4
- package/dist/core/persistent-shell.js.map +1 -1
- package/dist/core/process-gate.d.ts +45 -0
- package/dist/core/process-gate.d.ts.map +1 -0
- package/dist/core/process-gate.js +79 -0
- package/dist/core/process-gate.js.map +1 -0
- package/dist/core/process-gate.test.d.ts +2 -0
- package/dist/core/process-gate.test.d.ts.map +1 -0
- package/dist/core/process-gate.test.js +87 -0
- package/dist/core/process-gate.test.js.map +1 -0
- package/dist/core/process-manager-dev-server-repro.test.js +34 -12
- package/dist/core/process-manager-dev-server-repro.test.js.map +1 -1
- package/dist/core/process-manager-notifications.test.d.ts +2 -0
- package/dist/core/process-manager-notifications.test.d.ts.map +1 -0
- package/dist/core/process-manager-notifications.test.js +217 -0
- package/dist/core/process-manager-notifications.test.js.map +1 -0
- package/dist/core/process-manager.d.ts +51 -2
- package/dist/core/process-manager.d.ts.map +1 -1
- package/dist/core/process-manager.js +212 -15
- package/dist/core/process-manager.js.map +1 -1
- package/dist/core/project-discovery.d.ts +38 -6
- package/dist/core/project-discovery.d.ts.map +1 -1
- package/dist/core/project-discovery.js +327 -40
- package/dist/core/project-discovery.js.map +1 -1
- package/dist/core/project-discovery.test.js +226 -1
- package/dist/core/project-discovery.test.js.map +1 -1
- package/dist/core/prompt-commands.d.ts.map +1 -1
- package/dist/core/prompt-commands.js +89 -156
- package/dist/core/prompt-commands.js.map +1 -1
- package/dist/core/prompt-commands.test.js +4 -10
- package/dist/core/prompt-commands.test.js.map +1 -1
- package/dist/core/radio.test.js +4 -1
- package/dist/core/radio.test.js.map +1 -1
- package/dist/core/regrounding.d.ts.map +1 -1
- package/dist/core/regrounding.js +1 -0
- package/dist/core/regrounding.js.map +1 -1
- package/dist/core/run-claim.d.ts +37 -0
- package/dist/core/run-claim.d.ts.map +1 -0
- package/dist/core/run-claim.js +46 -0
- package/dist/core/run-claim.js.map +1 -0
- package/dist/core/run-claim.test.d.ts +2 -0
- package/dist/core/run-claim.test.d.ts.map +1 -0
- package/dist/core/run-claim.test.js +107 -0
- package/dist/core/run-claim.test.js.map +1 -0
- package/dist/core/run-journal.test.d.ts +2 -0
- package/dist/core/run-journal.test.d.ts.map +1 -0
- package/dist/core/run-journal.test.js +195 -0
- package/dist/core/run-journal.test.js.map +1 -0
- package/dist/core/run-lifecycle.d.ts +22 -3
- package/dist/core/run-lifecycle.d.ts.map +1 -1
- package/dist/core/run-lifecycle.js +12 -3
- package/dist/core/run-lifecycle.js.map +1 -1
- package/dist/core/runtime-mode.d.ts +2 -0
- package/dist/core/runtime-mode.d.ts.map +1 -1
- package/dist/core/runtime-mode.js +4 -0
- package/dist/core/runtime-mode.js.map +1 -1
- package/dist/core/sandbox-domains.d.ts +14 -0
- package/dist/core/sandbox-domains.d.ts.map +1 -0
- package/dist/core/sandbox-domains.js +76 -0
- package/dist/core/sandbox-domains.js.map +1 -0
- package/dist/core/sandbox-feedback.d.ts +22 -0
- package/dist/core/sandbox-feedback.d.ts.map +1 -0
- package/dist/core/sandbox-feedback.js +69 -0
- package/dist/core/sandbox-feedback.js.map +1 -0
- package/dist/core/sandbox-feedback.test.d.ts +2 -0
- package/dist/core/sandbox-feedback.test.d.ts.map +1 -0
- package/dist/core/sandbox-feedback.test.js +32 -0
- package/dist/core/sandbox-feedback.test.js.map +1 -0
- package/dist/core/sandbox.d.ts +91 -0
- package/dist/core/sandbox.d.ts.map +1 -0
- package/dist/core/sandbox.js +254 -0
- package/dist/core/sandbox.js.map +1 -0
- package/dist/core/sandbox.test.d.ts +2 -0
- package/dist/core/sandbox.test.d.ts.map +1 -0
- package/dist/core/sandbox.test.js +157 -0
- package/dist/core/sandbox.test.js.map +1 -0
- package/dist/core/session-compaction.d.ts +6 -0
- package/dist/core/session-compaction.d.ts.map +1 -1
- package/dist/core/session-compaction.js +11 -1
- package/dist/core/session-compaction.js.map +1 -1
- package/dist/core/session-compaction.test.js +18 -1
- package/dist/core/session-compaction.test.js.map +1 -1
- package/dist/core/session-export.d.ts +98 -0
- package/dist/core/session-export.d.ts.map +1 -0
- package/dist/core/session-export.js +364 -0
- package/dist/core/session-export.js.map +1 -0
- package/dist/core/session-export.test.d.ts +2 -0
- package/dist/core/session-export.test.d.ts.map +1 -0
- package/dist/core/session-export.test.js +353 -0
- package/dist/core/session-export.test.js.map +1 -0
- package/dist/core/session-history.d.ts +95 -6
- package/dist/core/session-history.d.ts.map +1 -1
- package/dist/core/session-history.js +261 -17
- package/dist/core/session-history.js.map +1 -1
- package/dist/core/session-history.test.js +173 -2
- package/dist/core/session-history.test.js.map +1 -1
- package/dist/core/session-manager.d.ts +223 -6
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +515 -26
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/session-manager.test.js +147 -3
- package/dist/core/session-manager.test.js.map +1 -1
- package/dist/core/session-notification-visibility.test.d.ts +2 -0
- package/dist/core/session-notification-visibility.test.d.ts.map +1 -0
- package/dist/core/session-notification-visibility.test.js +113 -0
- package/dist/core/session-notification-visibility.test.js.map +1 -0
- package/dist/core/session-preview.d.ts +5 -4
- package/dist/core/session-preview.d.ts.map +1 -1
- package/dist/core/session-preview.js +12 -5
- package/dist/core/session-preview.js.map +1 -1
- package/dist/core/session-restore-display.test.js +25 -0
- package/dist/core/session-restore-display.test.js.map +1 -1
- package/dist/core/session-storage.d.ts.map +1 -1
- package/dist/core/session-storage.js +64 -4
- package/dist/core/session-storage.js.map +1 -1
- package/dist/core/session-storage.test.js +10 -2
- package/dist/core/session-storage.test.js.map +1 -1
- package/dist/core/settings-manager.d.ts +13 -2
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +36 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/setup-history.d.ts +0 -6
- package/dist/core/setup-history.d.ts.map +1 -1
- package/dist/core/setup-history.js +2 -18
- package/dist/core/setup-history.js.map +1 -1
- package/dist/core/setup-history.test.js +11 -26
- package/dist/core/setup-history.test.js.map +1 -1
- package/dist/core/skills-routing.test.js +3 -1
- package/dist/core/skills-routing.test.js.map +1 -1
- package/dist/core/slash-commands.d.ts +18 -0
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +42 -10
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/slash-commands.test.d.ts +2 -0
- package/dist/core/slash-commands.test.d.ts.map +1 -0
- package/dist/core/slash-commands.test.js +59 -0
- package/dist/core/slash-commands.test.js.map +1 -0
- package/dist/core/speed-benchmark.test.js +9 -3
- package/dist/core/speed-benchmark.test.js.map +1 -1
- package/dist/core/steering.d.ts +12 -0
- package/dist/core/steering.d.ts.map +1 -1
- package/dist/core/steering.js +16 -0
- package/dist/core/steering.js.map +1 -1
- package/dist/core/subagent-manager.d.ts +14 -1
- package/dist/core/subagent-manager.d.ts.map +1 -1
- package/dist/core/subagent-manager.js +48 -1
- package/dist/core/subagent-manager.js.map +1 -1
- package/dist/core/subagent-manager.test.js +43 -7
- package/dist/core/subagent-manager.test.js.map +1 -1
- package/dist/core/subagent-store.test.js +14 -2
- package/dist/core/subagent-store.test.js.map +1 -1
- package/dist/core/verification-evidence.d.ts +17 -0
- package/dist/core/verification-evidence.d.ts.map +1 -0
- package/dist/core/verification-evidence.js +283 -0
- package/dist/core/verification-evidence.js.map +1 -0
- package/dist/core/verification-evidence.test.d.ts +2 -0
- package/dist/core/verification-evidence.test.d.ts.map +1 -0
- package/dist/core/verification-evidence.test.js +103 -0
- package/dist/core/verification-evidence.test.js.map +1 -0
- package/dist/core/workspace-guard.d.ts +2 -0
- package/dist/core/workspace-guard.d.ts.map +1 -1
- package/dist/core/workspace-guard.js +4 -1
- package/dist/core/workspace-guard.js.map +1 -1
- package/dist/core/workspace-guard.test.js +21 -0
- package/dist/core/workspace-guard.test.js.map +1 -1
- package/dist/interactive.d.ts.map +1 -1
- package/dist/interactive.js +17 -3
- package/dist/interactive.js.map +1 -1
- package/dist/modes/acp-mode.d.ts +122 -0
- package/dist/modes/acp-mode.d.ts.map +1 -0
- package/dist/modes/acp-mode.js +1366 -0
- package/dist/modes/acp-mode.js.map +1 -0
- package/dist/modes/acp-mode.test.d.ts +2 -0
- package/dist/modes/acp-mode.test.d.ts.map +1 -0
- package/dist/modes/acp-mode.test.js +1065 -0
- package/dist/modes/acp-mode.test.js.map +1 -0
- package/dist/modes/index.d.ts +1 -0
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/index.js +1 -0
- package/dist/modes/index.js.map +1 -1
- package/dist/modes/json-mode.d.ts +35 -0
- package/dist/modes/json-mode.d.ts.map +1 -1
- package/dist/modes/json-mode.js +38 -0
- package/dist/modes/json-mode.js.map +1 -1
- package/dist/modes/json-mode.test.d.ts +2 -0
- package/dist/modes/json-mode.test.d.ts.map +1 -0
- package/dist/modes/json-mode.test.js +84 -0
- package/dist/modes/json-mode.test.js.map +1 -0
- package/dist/modes/subagent-worker-mode.d.ts +5 -0
- package/dist/modes/subagent-worker-mode.d.ts.map +1 -1
- package/dist/modes/subagent-worker-mode.js +91 -11
- package/dist/modes/subagent-worker-mode.js.map +1 -1
- package/dist/modes/subagent-worker-mode.test.d.ts +2 -0
- package/dist/modes/subagent-worker-mode.test.d.ts.map +1 -0
- package/dist/modes/subagent-worker-mode.test.js +52 -0
- package/dist/modes/subagent-worker-mode.test.js.map +1 -0
- package/dist/session.d.ts +29 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +41 -0
- package/dist/session.js.map +1 -1
- package/dist/system-prompt.d.ts +11 -1
- package/dist/system-prompt.d.ts.map +1 -1
- package/dist/system-prompt.js +39 -18
- package/dist/system-prompt.js.map +1 -1
- package/dist/system-prompt.test.js +33 -17
- package/dist/system-prompt.test.js.map +1 -1
- package/dist/test-support/fake-home.d.ts +20 -0
- package/dist/test-support/fake-home.d.ts.map +1 -0
- package/dist/test-support/fake-home.js +37 -0
- package/dist/test-support/fake-home.js.map +1 -0
- package/dist/tools/bash.d.ts +3 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +70 -14
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/bash.test.js +122 -7
- package/dist/tools/bash.test.js.map +1 -1
- package/dist/tools/edit-robustness.test.js +3 -1
- package/dist/tools/edit-robustness.test.js.map +1 -1
- package/dist/tools/find.d.ts.map +1 -1
- package/dist/tools/find.js +4 -1
- package/dist/tools/find.js.map +1 -1
- package/dist/tools/goals.d.ts +2 -2
- package/dist/tools/grep.d.ts +3 -1
- package/dist/tools/grep.d.ts.map +1 -1
- package/dist/tools/grep.js +137 -12
- package/dist/tools/grep.js.map +1 -1
- package/dist/tools/grep.test.js +53 -0
- package/dist/tools/grep.test.js.map +1 -1
- package/dist/tools/index.d.ts +19 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +22 -19
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/index.test.d.ts +2 -0
- package/dist/tools/index.test.d.ts.map +1 -0
- package/dist/tools/index.test.js +55 -0
- package/dist/tools/index.test.js.map +1 -0
- package/dist/tools/overflow.test.js +4 -7
- package/dist/tools/overflow.test.js.map +1 -1
- package/dist/tools/path-utils.d.ts +15 -0
- package/dist/tools/path-utils.d.ts.map +1 -1
- package/dist/tools/path-utils.js +17 -0
- package/dist/tools/path-utils.js.map +1 -1
- package/dist/tools/path-utils.test.js +7 -2
- package/dist/tools/path-utils.test.js.map +1 -1
- package/dist/tools/prompt-hints.js +1 -1
- package/dist/tools/prompt-hints.js.map +1 -1
- package/dist/tools/read-only-bash.d.ts +3 -0
- package/dist/tools/read-only-bash.d.ts.map +1 -1
- package/dist/tools/read-only-bash.js +7 -9
- package/dist/tools/read-only-bash.js.map +1 -1
- package/dist/tools/search-code.d.ts.map +1 -1
- package/dist/tools/search-code.js +6 -4
- package/dist/tools/search-code.js.map +1 -1
- package/dist/tools/subagent-control.d.ts.map +1 -1
- package/dist/tools/subagent-control.js +6 -2
- package/dist/tools/subagent-control.js.map +1 -1
- package/dist/tools/subagent-shared.d.ts +6 -0
- package/dist/tools/subagent-shared.d.ts.map +1 -1
- package/dist/tools/subagent-shared.js +6 -0
- package/dist/tools/subagent-shared.js.map +1 -1
- package/dist/tools/subagent.d.ts +1 -1
- package/dist/tools/subagent.d.ts.map +1 -1
- package/dist/tools/subagent.js +51 -8
- package/dist/tools/subagent.js.map +1 -1
- package/dist/tools/subagent.test.js +65 -3
- package/dist/tools/subagent.test.js.map +1 -1
- package/dist/tools/task-output.d.ts.map +1 -1
- package/dist/tools/task-output.js +3 -1
- package/dist/tools/task-output.js.map +1 -1
- package/dist/tools/tool-search.d.ts +12 -1
- package/dist/tools/tool-search.d.ts.map +1 -1
- package/dist/tools/tool-search.js +22 -3
- package/dist/tools/tool-search.js.map +1 -1
- package/dist/tools/tool-search.test.d.ts +2 -0
- package/dist/tools/tool-search.test.d.ts.map +1 -0
- package/dist/tools/tool-search.test.js +69 -0
- package/dist/tools/tool-search.test.js.map +1 -0
- package/dist/tools/web-fetch.d.ts +3 -2
- package/dist/tools/web-fetch.d.ts.map +1 -1
- package/dist/tools/web-fetch.js +22 -8
- package/dist/tools/web-fetch.js.map +1 -1
- package/dist/tools/web-fetch.test.js +34 -0
- package/dist/tools/web-fetch.test.js.map +1 -1
- package/dist/tools/web-search.d.ts +2 -1
- package/dist/tools/web-search.d.ts.map +1 -1
- package/dist/tools/web-search.js +21 -5
- package/dist/tools/web-search.js.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/App.d.ts.map +1 -1
- package/dist/ui/App.js +32 -81
- package/dist/ui/App.js.map +1 -1
- package/dist/ui/app-items.d.ts +1 -12
- package/dist/ui/app-items.d.ts.map +1 -1
- package/dist/ui/app-items.js.map +1 -1
- package/dist/ui/components/Footer.d.ts +1 -1
- package/dist/ui/components/Footer.js +2 -2
- package/dist/ui/components/Footer.js.map +1 -1
- package/dist/ui/hooks/useAgentLoop.d.ts.map +1 -1
- package/dist/ui/hooks/useAgentLoop.js +18 -4
- package/dist/ui/hooks/useAgentLoop.js.map +1 -1
- package/dist/ui/hooks/usePixelFixFlow.d.ts +1 -2
- package/dist/ui/hooks/usePixelFixFlow.d.ts.map +1 -1
- package/dist/ui/hooks/usePixelFixFlow.js +2 -5
- package/dist/ui/hooks/usePixelFixFlow.js.map +1 -1
- package/dist/ui/login.js +1 -1
- package/dist/ui/login.js.map +1 -1
- package/dist/ui/terminal-history-status-renderers.d.ts +1 -2
- package/dist/ui/terminal-history-status-renderers.d.ts.map +1 -1
- package/dist/ui/terminal-history-status-renderers.js +2 -15
- package/dist/ui/terminal-history-status-renderers.js.map +1 -1
- package/dist/ui/terminal-history.d.ts.map +1 -1
- package/dist/ui/terminal-history.js +2 -4
- package/dist/ui/terminal-history.js.map +1 -1
- package/dist/ui/thinking-level-cycle.test.js +8 -8
- package/dist/ui/thinking-level-cycle.test.js.map +1 -1
- package/dist/ui/transcript/MiscRows.d.ts +1 -4
- package/dist/ui/transcript/MiscRows.d.ts.map +1 -1
- package/dist/ui/transcript/MiscRows.js +2 -7
- package/dist/ui/transcript/MiscRows.js.map +1 -1
- package/dist/ui/transcript/TranscriptRenderer.d.ts.map +1 -1
- package/dist/ui/transcript/TranscriptRenderer.js +1 -3
- package/dist/ui/transcript/TranscriptRenderer.js.map +1 -1
- package/dist/ui/transcript/presentation.d.ts +1 -9
- package/dist/ui/transcript/presentation.d.ts.map +1 -1
- package/dist/ui/transcript/presentation.js +0 -9
- package/dist/ui/transcript/presentation.js.map +1 -1
- package/dist/ui/transcript/spacing.d.ts +2 -2
- package/dist/ui/transcript/spacing.d.ts.map +1 -1
- package/dist/ui/transcript/spacing.js +0 -1
- package/dist/ui/transcript/spacing.js.map +1 -1
- package/dist/ui/transcript/spacing.test.js +1 -3
- package/dist/ui/transcript/spacing.test.js.map +1 -1
- package/dist/ui/tui-history-parity.test.js +2 -9
- package/dist/ui/tui-history-parity.test.js.map +1 -1
- package/dist/utils/github.d.ts +20 -0
- package/dist/utils/github.d.ts.map +1 -0
- package/dist/utils/github.js +65 -0
- package/dist/utils/github.js.map +1 -0
- package/dist/utils/github.test.d.ts +2 -0
- package/dist/utils/github.test.d.ts.map +1 -0
- package/dist/utils/github.test.js +23 -0
- package/dist/utils/github.test.js.map +1 -0
- package/dist/utils/image.d.ts +26 -3
- package/dist/utils/image.d.ts.map +1 -1
- package/dist/utils/image.js +83 -14
- package/dist/utils/image.js.map +1 -1
- package/dist/utils/image.test.d.ts +2 -0
- package/dist/utils/image.test.d.ts.map +1 -0
- package/dist/utils/image.test.js +139 -0
- package/dist/utils/image.test.js.map +1 -0
- package/dist/utils/process.d.ts +26 -3
- package/dist/utils/process.d.ts.map +1 -1
- package/dist/utils/process.js +68 -10
- package/dist/utils/process.js.map +1 -1
- package/dist/utils/process.test.d.ts +2 -0
- package/dist/utils/process.test.d.ts.map +1 -0
- package/dist/utils/process.test.js +42 -0
- package/dist/utils/process.test.js.map +1 -0
- package/package.json +6 -5
|
@@ -0,0 +1,1366 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP mode: expose EZ Coder as an Agent Client Protocol agent over stdio.
|
|
3
|
+
*
|
|
4
|
+
* This is the integration surface for ACP clients (Zed, pew2, any editor that
|
|
5
|
+
* speaks the protocol). It is deliberately a sibling of `rpc-mode.ts` — same
|
|
6
|
+
* shape, same `AgentSession`, same NDJSON-on-stdio transport — but the frames
|
|
7
|
+
* are the standard protocol instead of ezcoder's bespoke one, so a client
|
|
8
|
+
* written against the spec works with no ezcoder-specific code.
|
|
9
|
+
*
|
|
10
|
+
* Spec: https://agentclientprotocol.com/protocol/overview
|
|
11
|
+
*
|
|
12
|
+
* Scope: `initialize`, `session/new`, `session/prompt`, `session/cancel`,
|
|
13
|
+
* `session/list`, `session/load`, `session/resume`, `session/close`,
|
|
14
|
+
* `session/delete`, `session/set_mode` and `session/set_config_option`.
|
|
15
|
+
* Everything advertised in `agentCapabilities` is implemented, because a client
|
|
16
|
+
* must be able to trust that list — advertising a method that then errors is
|
|
17
|
+
* worse than advertising nothing.
|
|
18
|
+
*
|
|
19
|
+
* stdout carries protocol frames ONLY. Anything diagnostic goes to stderr or
|
|
20
|
+
* the log file; a stray `console.log` anywhere in the process corrupts the
|
|
21
|
+
* stream and the client disconnects.
|
|
22
|
+
*/
|
|
23
|
+
import readline from "node:readline";
|
|
24
|
+
import path from "node:path";
|
|
25
|
+
import { readFileSync, statSync } from "node:fs";
|
|
26
|
+
import { rm } from "node:fs/promises";
|
|
27
|
+
import { isAbortError } from "@prestyj/agent";
|
|
28
|
+
import { getAllModels, getMaxThinkingLevel, getModel } from "@prestyj/core";
|
|
29
|
+
import { AgentSession } from "../core/agent-session.js";
|
|
30
|
+
import { PROMPT_COMMANDS } from "../core/prompt-commands.js";
|
|
31
|
+
import { loadCustomCommands } from "../core/custom-commands.js";
|
|
32
|
+
import { findSessionById, listAllSessions, listSessionSummaries, loadSessionCheckpointChain, } from "../session.js";
|
|
33
|
+
import { getHistoryMessageVisibility, reconstructCheckpointHistory, restoreUserRow, } from "../core/session-history.js";
|
|
34
|
+
import { findUserSessionPrompt } from "../core/session-preview.js";
|
|
35
|
+
import { sessionGroupPaths } from "../core/session-storage.js";
|
|
36
|
+
import { extractPlanSteps, findCompletedMarkers, markStepsCompleted, rebasePlanSteps, } from "../utils/plan-steps.js";
|
|
37
|
+
import { formatUserError } from "../utils/error-handler.js";
|
|
38
|
+
import { closeLogger } from "../core/logger.js";
|
|
39
|
+
/** The ACP major version this mode implements. Bumped only for breaking changes. */
|
|
40
|
+
export const ACP_PROTOCOL_VERSION = 1;
|
|
41
|
+
/** JSON-RPC 2.0 reserved codes. ACP adds no codes of its own. */
|
|
42
|
+
const RPC_PARSE_ERROR = -32700;
|
|
43
|
+
const RPC_INVALID_REQUEST = -32600;
|
|
44
|
+
const RPC_METHOD_NOT_FOUND = -32601;
|
|
45
|
+
const RPC_INVALID_PARAMS = -32602;
|
|
46
|
+
const RPC_INTERNAL_ERROR = -32603;
|
|
47
|
+
/**
|
|
48
|
+
* The client asked for something impossible, as opposed to the agent failing.
|
|
49
|
+
*
|
|
50
|
+
* Typed rather than sniffed from the message text, so that a client can tell a
|
|
51
|
+
* bug in its own sequencing from an agent that fell over — and so that a later
|
|
52
|
+
* reworded message cannot silently change the code on the wire.
|
|
53
|
+
*/
|
|
54
|
+
class InvalidParams extends Error {
|
|
55
|
+
}
|
|
56
|
+
// ── Tool mapping ───────────────────────────────────────────
|
|
57
|
+
/**
|
|
58
|
+
* ezcoder tool name → ACP `ToolKind`.
|
|
59
|
+
*
|
|
60
|
+
* Purely cosmetic on the client (icon + progress treatment), so an unmapped
|
|
61
|
+
* tool falls back to `other` rather than failing. Keep in step with
|
|
62
|
+
* `src/tools/index.ts` as tools are added.
|
|
63
|
+
*/
|
|
64
|
+
const TOOL_KINDS = {
|
|
65
|
+
read: "read",
|
|
66
|
+
ls: "read",
|
|
67
|
+
find: "read",
|
|
68
|
+
grep: "search",
|
|
69
|
+
code_search: "search",
|
|
70
|
+
web_search: "search",
|
|
71
|
+
edit: "edit",
|
|
72
|
+
write: "edit",
|
|
73
|
+
bash: "execute",
|
|
74
|
+
screenshot: "execute",
|
|
75
|
+
web_fetch: "fetch",
|
|
76
|
+
source_path: "fetch",
|
|
77
|
+
subagent: "think",
|
|
78
|
+
spawn_agent: "think",
|
|
79
|
+
enter_plan: "switch_mode",
|
|
80
|
+
exit_plan: "switch_mode",
|
|
81
|
+
};
|
|
82
|
+
function toolKind(name) {
|
|
83
|
+
return TOOL_KINDS[name] ?? "other";
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A one-line tool title for the client's activity list.
|
|
87
|
+
*
|
|
88
|
+
* The first string-ish argument is nearly always the interesting one (a path, a
|
|
89
|
+
* command, a query), and it is truncated because this renders on a phone.
|
|
90
|
+
*/
|
|
91
|
+
function toolTitle(name, args) {
|
|
92
|
+
for (const value of Object.values(args)) {
|
|
93
|
+
if (typeof value !== "string" || value.length === 0)
|
|
94
|
+
continue;
|
|
95
|
+
const flat = value.replace(/\s+/g, " ").trim();
|
|
96
|
+
const clipped = flat.length > 80 ? `${flat.slice(0, 79)}…` : flat;
|
|
97
|
+
return `${name}(${clipped})`;
|
|
98
|
+
}
|
|
99
|
+
return name;
|
|
100
|
+
}
|
|
101
|
+
// ── Tool locations ─────────────────────────────────────────
|
|
102
|
+
/**
|
|
103
|
+
* Argument names that hold the path a tool works on, most specific first.
|
|
104
|
+
*
|
|
105
|
+
* Deliberately a small allowlist rather than "any string that looks like a
|
|
106
|
+
* path": `bash`'s command and `web_fetch`'s url would both pass a heuristic and
|
|
107
|
+
* both would send the client's editor somewhere that does not exist.
|
|
108
|
+
*/
|
|
109
|
+
const PATH_ARG_KEYS = ["file_path", "path", "out_path"];
|
|
110
|
+
/**
|
|
111
|
+
* The file a tool call touches, which is what drives "follow the agent" in a
|
|
112
|
+
* client: the editor jumps to whatever GG is reading or editing right now.
|
|
113
|
+
*
|
|
114
|
+
* Paths are resolved to absolute against the session cwd, because the client
|
|
115
|
+
* runs somewhere else entirely and cannot know what a relative path was
|
|
116
|
+
* relative to. A wrong location is worse than none, so anything unrecognised
|
|
117
|
+
* reports nothing.
|
|
118
|
+
*/
|
|
119
|
+
function toolLocations(args, cwd) {
|
|
120
|
+
for (const key of PATH_ARG_KEYS) {
|
|
121
|
+
const value = args[key];
|
|
122
|
+
if (typeof value !== "string" || !value)
|
|
123
|
+
continue;
|
|
124
|
+
const absolute = path.isAbsolute(value) ? value : path.resolve(cwd, value);
|
|
125
|
+
// `read`'s offset is a 1-based line, which is exactly what ACP wants for
|
|
126
|
+
// scrolling the client to the region being looked at.
|
|
127
|
+
const offset = args.offset;
|
|
128
|
+
return typeof offset === "number" && Number.isInteger(offset) && offset > 0
|
|
129
|
+
? [{ path: absolute, line: offset }]
|
|
130
|
+
: [{ path: absolute }];
|
|
131
|
+
}
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
// ── File diffs ─────────────────────────────────────────────
|
|
135
|
+
/** Tools whose whole purpose is changing a file's contents. */
|
|
136
|
+
const DIFF_TOOLS = new Set(["edit", "write"]);
|
|
137
|
+
/**
|
|
138
|
+
* Largest file we will snapshot to build a diff.
|
|
139
|
+
*
|
|
140
|
+
* The contents cross the wire twice (old and new) and are read on the event
|
|
141
|
+
* loop, so a generated bundle or lockfile would stall the turn and flood the
|
|
142
|
+
* client with a diff no human is going to read.
|
|
143
|
+
*/
|
|
144
|
+
const MAX_DIFF_BYTES = 256 * 1024;
|
|
145
|
+
/**
|
|
146
|
+
* Read a file for diffing, SYNCHRONOUSLY and on purpose.
|
|
147
|
+
*
|
|
148
|
+
* The "before" snapshot is taken inside the `tool_call_start` handler, and the
|
|
149
|
+
* tool it belongs to begins writing in the same tick. An async read would race
|
|
150
|
+
* that write and could capture the file as it is AFTER the edit, which renders
|
|
151
|
+
* in the client as a real change with an empty diff.
|
|
152
|
+
*/
|
|
153
|
+
function snapshotForDiff(filePath) {
|
|
154
|
+
let size;
|
|
155
|
+
try {
|
|
156
|
+
size = statSync(filePath).size;
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// Missing: `write` creating a new file. ACP represents that as a null
|
|
160
|
+
// `oldText`, which clients render as an all-additions diff.
|
|
161
|
+
return { text: null };
|
|
162
|
+
}
|
|
163
|
+
if (size > MAX_DIFF_BYTES)
|
|
164
|
+
return undefined;
|
|
165
|
+
try {
|
|
166
|
+
return { text: readFileSync(filePath, "utf8") };
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// ── Plans ──────────────────────────────────────────────────
|
|
173
|
+
/**
|
|
174
|
+
* GG's plan steps as ACP plan entries.
|
|
175
|
+
*
|
|
176
|
+
* ACP requires a priority per entry and GG's plans have no such concept, so
|
|
177
|
+
* every entry reports `medium` rather than inventing a ranking the user never
|
|
178
|
+
* expressed. The first unfinished step is reported `in_progress`: entries are
|
|
179
|
+
* worked in order, so this is what the agent is actually doing now, and it
|
|
180
|
+
* gives the client a live marker instead of a list that only ever flips from
|
|
181
|
+
* pending to completed.
|
|
182
|
+
*/
|
|
183
|
+
function planEntries(steps) {
|
|
184
|
+
let activeMarked = false;
|
|
185
|
+
return steps.map((step) => {
|
|
186
|
+
let status;
|
|
187
|
+
if (step.completed) {
|
|
188
|
+
status = "completed";
|
|
189
|
+
}
|
|
190
|
+
else if (activeMarked) {
|
|
191
|
+
status = "pending";
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
activeMarked = true;
|
|
195
|
+
status = "in_progress";
|
|
196
|
+
}
|
|
197
|
+
return { content: step.text, priority: "medium", status };
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/** Read a plan markdown file, or empty string when it has gone missing. */
|
|
201
|
+
function readPlanFile(planPath) {
|
|
202
|
+
try {
|
|
203
|
+
return readFileSync(planPath, "utf8");
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return "";
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Why the current prompt turn ended.
|
|
211
|
+
*
|
|
212
|
+
* ACP has a closed set; ezcoder's `turn_end` carries whatever the provider
|
|
213
|
+
* said. Only the reasons that map cleanly are translated — everything else is
|
|
214
|
+
* a normal completion, which is what the client renders anyway.
|
|
215
|
+
*/
|
|
216
|
+
function stopReasonFor(truncation, hitMaxTurns) {
|
|
217
|
+
if (hitMaxTurns)
|
|
218
|
+
return "max_turn_requests";
|
|
219
|
+
if (truncation === "max_tokens")
|
|
220
|
+
return "max_tokens";
|
|
221
|
+
if (truncation === "refusal")
|
|
222
|
+
return "refusal";
|
|
223
|
+
return "end_turn";
|
|
224
|
+
}
|
|
225
|
+
// ── Config options ─────────────────────────────────────
|
|
226
|
+
/** The selectors this agent exposes. Ids are part of the wire contract. */
|
|
227
|
+
export const MODEL_CONFIG_ID = "model";
|
|
228
|
+
export const THINKING_CONFIG_ID = "thinking";
|
|
229
|
+
export const MODE_CONFIG_ID = "mode";
|
|
230
|
+
/** ACP session modes, mapped onto GG's plan mode. */
|
|
231
|
+
const MODE_DEFAULT = "default";
|
|
232
|
+
const MODE_PLAN = "plan";
|
|
233
|
+
/** Thinking off is a real choice, so it needs a value id of its own. */
|
|
234
|
+
const THINKING_OFF = "off";
|
|
235
|
+
const THINKING_LADDER = [
|
|
236
|
+
"low",
|
|
237
|
+
"medium",
|
|
238
|
+
"high",
|
|
239
|
+
"xhigh",
|
|
240
|
+
"max",
|
|
241
|
+
"ultra",
|
|
242
|
+
];
|
|
243
|
+
/**
|
|
244
|
+
* Thinking levels this model actually honours, hardest last.
|
|
245
|
+
*
|
|
246
|
+
* Offering levels above the model's ceiling would let a phone pick a setting
|
|
247
|
+
* that silently degrades to something else — a control that lies.
|
|
248
|
+
*/
|
|
249
|
+
function thinkingOptionsFor(modelId) {
|
|
250
|
+
const ceiling = getMaxThinkingLevel(modelId);
|
|
251
|
+
const top = THINKING_LADDER.indexOf(ceiling);
|
|
252
|
+
const levels = THINKING_LADDER.slice(0, top < 0 ? THINKING_LADDER.length : top + 1);
|
|
253
|
+
return [
|
|
254
|
+
{ value: THINKING_OFF, name: "Off", description: "No extended reasoning" },
|
|
255
|
+
...levels.map((level) => ({ value: level, name: level })),
|
|
256
|
+
];
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* The selectors a client renders for a session, with their live values.
|
|
260
|
+
*
|
|
261
|
+
* Model and thinking come from ezcoder's own registry rather than anything
|
|
262
|
+
* pew2- or Zed-specific, which is what lets a phone show EZ Coder's real model
|
|
263
|
+
* list without either side hard-coding the other's.
|
|
264
|
+
*/
|
|
265
|
+
function configOptionsFor(session) {
|
|
266
|
+
const { model } = session.getState();
|
|
267
|
+
const thinking = session.getThinkingLevel();
|
|
268
|
+
return [
|
|
269
|
+
{
|
|
270
|
+
id: MODEL_CONFIG_ID,
|
|
271
|
+
name: "Model",
|
|
272
|
+
category: "model",
|
|
273
|
+
type: "select",
|
|
274
|
+
currentValue: model,
|
|
275
|
+
options: getAllModels().map((entry) => ({
|
|
276
|
+
value: entry.id,
|
|
277
|
+
name: entry.name,
|
|
278
|
+
description: entry.provider,
|
|
279
|
+
})),
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
id: THINKING_CONFIG_ID,
|
|
283
|
+
name: "Thinking",
|
|
284
|
+
description: "Extended reasoning effort",
|
|
285
|
+
category: "thought_level",
|
|
286
|
+
type: "select",
|
|
287
|
+
// A model that cannot think reports `off`, which is the truth rather than
|
|
288
|
+
// a level it would ignore.
|
|
289
|
+
currentValue: getModel(model)?.supportsThinking ? (thinking ?? THINKING_OFF) : THINKING_OFF,
|
|
290
|
+
options: thinkingOptionsFor(model),
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
id: MODE_CONFIG_ID,
|
|
294
|
+
name: "Mode",
|
|
295
|
+
description: "Plan mode is read-only research until a plan is approved",
|
|
296
|
+
category: "mode",
|
|
297
|
+
type: "select",
|
|
298
|
+
currentValue: session.getPlanMode() ? MODE_PLAN : MODE_DEFAULT,
|
|
299
|
+
options: [
|
|
300
|
+
{ value: MODE_DEFAULT, name: "Default", description: "Full tool access" },
|
|
301
|
+
{ value: MODE_PLAN, name: "Plan", description: "Read-only until exit_plan" },
|
|
302
|
+
],
|
|
303
|
+
},
|
|
304
|
+
];
|
|
305
|
+
}
|
|
306
|
+
/** What a prompt-template command does with whatever follows the name. */
|
|
307
|
+
const TEMPLATE_ARG_HINT = "extra instructions (optional)";
|
|
308
|
+
/**
|
|
309
|
+
* The argument hint for a registry command, taken from its own usage string.
|
|
310
|
+
*
|
|
311
|
+
* `/add-dir [path] — no path lists the current roots` becomes `[path]`: the
|
|
312
|
+
* client renders a hint, not a man page, and the prose after the dash is the
|
|
313
|
+
* description's job.
|
|
314
|
+
*/
|
|
315
|
+
function hintFromUsage(name, usage) {
|
|
316
|
+
const withoutName = usage.replace(new RegExp(`^\\s*/${name}\\b`), "").trim();
|
|
317
|
+
const hint = withoutName.split("—")[0].split(" - ")[0].trim();
|
|
318
|
+
return hint ? { hint } : undefined;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Every slash command this session would actually honour, in the precedence
|
|
322
|
+
* `AgentSession.resolveSlashInput` uses: built-in prompt templates, then
|
|
323
|
+
* `.ezcoder/commands/*.md` from the project, then registry commands.
|
|
324
|
+
*
|
|
325
|
+
* That order is not cosmetic. `resolveSlashInput` looks for a template body
|
|
326
|
+
* FIRST and only falls through to the registry when there is none, so a project
|
|
327
|
+
* file named `new.md` really does shadow the registry's `/new`. Listing the
|
|
328
|
+
* registry entry for that name would point a client's user at a description of
|
|
329
|
+
* something the agent will not run.
|
|
330
|
+
*
|
|
331
|
+
* Names already claimed — including a built-in's ALIASES, which
|
|
332
|
+
* `getPromptCommand` matches — are dropped rather than listed twice.
|
|
333
|
+
*/
|
|
334
|
+
async function availableCommands(session, cwd) {
|
|
335
|
+
const commands = [];
|
|
336
|
+
const taken = new Set();
|
|
337
|
+
const add = (command) => {
|
|
338
|
+
if (taken.has(command.name))
|
|
339
|
+
return;
|
|
340
|
+
taken.add(command.name);
|
|
341
|
+
commands.push(command);
|
|
342
|
+
};
|
|
343
|
+
for (const command of PROMPT_COMMANDS) {
|
|
344
|
+
for (const alias of command.aliases)
|
|
345
|
+
taken.add(alias);
|
|
346
|
+
add({
|
|
347
|
+
name: command.name,
|
|
348
|
+
description: command.description,
|
|
349
|
+
input: { hint: TEMPLATE_ARG_HINT },
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
// Project commands are files on disk, so a client that never rescans still
|
|
353
|
+
// gets whatever existed when the session opened.
|
|
354
|
+
for (const command of await loadCustomCommands(cwd)) {
|
|
355
|
+
add({
|
|
356
|
+
name: command.name,
|
|
357
|
+
description: command.description,
|
|
358
|
+
input: { hint: TEMPLATE_ARG_HINT },
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
// Last: anything above with the same NAME beats a registry command. An alias
|
|
362
|
+
// collision does not, so aliases are deliberately not claimed here — a
|
|
363
|
+
// project `q.md` shadows `/q` without hiding `/quit` itself.
|
|
364
|
+
for (const command of session.slashCommands?.getAll() ?? []) {
|
|
365
|
+
add({
|
|
366
|
+
name: command.name,
|
|
367
|
+
description: command.description,
|
|
368
|
+
input: hintFromUsage(command.name, command.usage),
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
return commands;
|
|
372
|
+
}
|
|
373
|
+
/** The `modes` block ACP clients like Zed read from session/new and session/load. */
|
|
374
|
+
function sessionModes(session) {
|
|
375
|
+
return {
|
|
376
|
+
currentModeId: session.getPlanMode() ? MODE_PLAN : MODE_DEFAULT,
|
|
377
|
+
availableModes: [
|
|
378
|
+
{ id: MODE_DEFAULT, name: "Default", description: "Full tool access" },
|
|
379
|
+
{ id: MODE_PLAN, name: "Plan", description: "Read-only research until a plan is approved" },
|
|
380
|
+
],
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
// ── History replay ───────────────────────────────────
|
|
384
|
+
/** Flatten a persisted message's content to the text a client would show. */
|
|
385
|
+
function messageText(content) {
|
|
386
|
+
if (typeof content === "string")
|
|
387
|
+
return content;
|
|
388
|
+
if (!Array.isArray(content))
|
|
389
|
+
return "";
|
|
390
|
+
return content
|
|
391
|
+
.filter((block) => block?.type === "text")
|
|
392
|
+
.map((block) => block.text ?? "")
|
|
393
|
+
.join("");
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Turn a restored conversation into the `session/update` stream a client needs
|
|
397
|
+
* to draw it.
|
|
398
|
+
*
|
|
399
|
+
* ACP has no "here is the transcript" response: a loaded session is replayed as
|
|
400
|
+
* the same notifications a live turn produces, so the client needs no second
|
|
401
|
+
* rendering path. Thinking is deliberately NOT replayed — it is transient by
|
|
402
|
+
* design, and a wall of stale reasoning above a resumed conversation buries the
|
|
403
|
+
* thing the user came back for.
|
|
404
|
+
*
|
|
405
|
+
* Each replayed chunk carries a `messageId` so a client can group chunks into
|
|
406
|
+
* the messages they came from; ids are per-replay and positional, which is all
|
|
407
|
+
* the protocol needs of them.
|
|
408
|
+
*/
|
|
409
|
+
export function historyUpdates(messages) {
|
|
410
|
+
const updates = [];
|
|
411
|
+
let replayed = 0;
|
|
412
|
+
const nextMessageId = () => `hist-${++replayed}`;
|
|
413
|
+
for (const message of messages) {
|
|
414
|
+
if (getHistoryMessageVisibility(message) === "hidden")
|
|
415
|
+
continue;
|
|
416
|
+
if (message.role === "user") {
|
|
417
|
+
const restored = restoreUserRow(message.content, message.provenance);
|
|
418
|
+
if (restored.autopilotInjected || restored.notification)
|
|
419
|
+
continue;
|
|
420
|
+
if (restored.text) {
|
|
421
|
+
updates.push({
|
|
422
|
+
sessionUpdate: "user_message_chunk",
|
|
423
|
+
messageId: nextMessageId(),
|
|
424
|
+
content: { type: "text", text: restored.text },
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
if (message.role === "assistant") {
|
|
430
|
+
const text = messageText(message.content);
|
|
431
|
+
if (text) {
|
|
432
|
+
updates.push({
|
|
433
|
+
sessionUpdate: "agent_message_chunk",
|
|
434
|
+
messageId: nextMessageId(),
|
|
435
|
+
content: { type: "text", text },
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
if (Array.isArray(message.content)) {
|
|
439
|
+
for (const block of message.content) {
|
|
440
|
+
if (block.type !== "tool_call")
|
|
441
|
+
continue;
|
|
442
|
+
const call = block;
|
|
443
|
+
const args = call.args ?? {};
|
|
444
|
+
updates.push({
|
|
445
|
+
sessionUpdate: "tool_call",
|
|
446
|
+
toolCallId: call.id,
|
|
447
|
+
title: toolTitle(call.name, args),
|
|
448
|
+
name: call.name,
|
|
449
|
+
kind: toolKind(call.name),
|
|
450
|
+
// History is settled: a replayed call that still said `in_progress`
|
|
451
|
+
// would leave a spinner running forever on a resumed session.
|
|
452
|
+
status: "completed",
|
|
453
|
+
rawInput: args,
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
for (const result of message.content) {
|
|
460
|
+
const entry = result;
|
|
461
|
+
updates.push({
|
|
462
|
+
sessionUpdate: "tool_call_update",
|
|
463
|
+
toolCallId: entry.toolCallId,
|
|
464
|
+
status: entry.isError ? "failed" : "completed",
|
|
465
|
+
content: [
|
|
466
|
+
{
|
|
467
|
+
type: "content",
|
|
468
|
+
content: { type: "text", text: messageText(entry.content) },
|
|
469
|
+
},
|
|
470
|
+
],
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return updates;
|
|
475
|
+
}
|
|
476
|
+
// ── Mode ───────────────────────────────────────────────────
|
|
477
|
+
/**
|
|
478
|
+
* Serve ACP on stdio until the input stream ends.
|
|
479
|
+
*
|
|
480
|
+
* Resolves when the client disconnects; the caller owns process exit.
|
|
481
|
+
*/
|
|
482
|
+
export async function runAcpMode(options) {
|
|
483
|
+
const input = options.input ?? process.stdin;
|
|
484
|
+
const output = options.output ?? process.stdout;
|
|
485
|
+
function write(frame) {
|
|
486
|
+
output.write(`${JSON.stringify(frame)}\n`);
|
|
487
|
+
}
|
|
488
|
+
function respond(id, result) {
|
|
489
|
+
write({ jsonrpc: "2.0", id, result });
|
|
490
|
+
}
|
|
491
|
+
function fail(id, code, message) {
|
|
492
|
+
write({ jsonrpc: "2.0", id, error: { code, message } });
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* The single session this process serves.
|
|
496
|
+
*
|
|
497
|
+
* ACP allows many per connection, but an ACP client spawns one agent process
|
|
498
|
+
* per session anyway, and `AgentSession` owns process-wide state (cwd, tool
|
|
499
|
+
* registry, session file). One-per-process is the honest model; a second
|
|
500
|
+
* `session/new` replaces the first rather than pretending to multiplex.
|
|
501
|
+
*/
|
|
502
|
+
let session = null;
|
|
503
|
+
let sessionId = "";
|
|
504
|
+
let abort = new AbortController();
|
|
505
|
+
/** Set while a `session/prompt` is in flight, so a second one is rejected. */
|
|
506
|
+
let running = false;
|
|
507
|
+
let cancelled = false;
|
|
508
|
+
let truncation;
|
|
509
|
+
let hitMaxTurns = false;
|
|
510
|
+
/** Detaches every event listener when the session is replaced or disposed. */
|
|
511
|
+
let unwire = [];
|
|
512
|
+
/**
|
|
513
|
+
* Chunk grouping. A message runs until something interrupts it — a tool call
|
|
514
|
+
* or the end of the turn — so the id is minted lazily on the first chunk and
|
|
515
|
+
* dropped at those boundaries, which is exactly where the client should start
|
|
516
|
+
* a new bubble.
|
|
517
|
+
*/
|
|
518
|
+
let messageSeq = 0;
|
|
519
|
+
let currentMessageId = null;
|
|
520
|
+
/** Before-snapshots for in-flight `edit`/`write` calls, keyed by tool call. */
|
|
521
|
+
const diffSnapshots = new Map();
|
|
522
|
+
/** The approved plan being implemented, and how far through it the agent is. */
|
|
523
|
+
let planPath;
|
|
524
|
+
let planSteps = [];
|
|
525
|
+
const completedSteps = new Set();
|
|
526
|
+
/** This turn's assistant text, scanned for `[DONE:n]` markers. */
|
|
527
|
+
let turnText = "";
|
|
528
|
+
/** Whether this session has already announced a title to the client. */
|
|
529
|
+
let titleAnnounced = false;
|
|
530
|
+
function notifyUpdate(update) {
|
|
531
|
+
write({
|
|
532
|
+
jsonrpc: "2.0",
|
|
533
|
+
method: "session/update",
|
|
534
|
+
params: { sessionId, update },
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Report context-window usage to the client.
|
|
539
|
+
*
|
|
540
|
+
* Sent whenever token accounting moves — after each model response and after
|
|
541
|
+
* a compaction — because a client's context meter is otherwise frozen at
|
|
542
|
+
* whatever it last inferred. Compaction is only visible to a client as a drop
|
|
543
|
+
* in `used` at unchanged `size`, so the post-compaction emit is what makes
|
|
544
|
+
* that detectable at all.
|
|
545
|
+
*
|
|
546
|
+
* `used`/`size` are required by the schema; a session that cannot count
|
|
547
|
+
* tokens sends nothing rather than a zero, which would render as an empty
|
|
548
|
+
* context the user does not have.
|
|
549
|
+
*/
|
|
550
|
+
function notifyUsage(target = session) {
|
|
551
|
+
if (!target || target !== session || !sessionId)
|
|
552
|
+
return;
|
|
553
|
+
const usage = target.getContextUsage?.();
|
|
554
|
+
if (!usage || !Number.isFinite(usage.used) || !Number.isFinite(usage.size))
|
|
555
|
+
return;
|
|
556
|
+
notifyUpdate({
|
|
557
|
+
sessionUpdate: "usage_update",
|
|
558
|
+
used: usage.used,
|
|
559
|
+
size: usage.size,
|
|
560
|
+
...(usage.costUsd === undefined ? {} : { cost: { amount: usage.costUsd, currency: "USD" } }),
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* State for a session that was just created or restored, sent after the
|
|
565
|
+
* response that told the client the session exists.
|
|
566
|
+
*
|
|
567
|
+
* Same deferral (and same staleness guard) as {@link notifyAvailableCommands}:
|
|
568
|
+
* a notification addressed to a sessionId the client has not seen yet has
|
|
569
|
+
* nowhere to land. Without this a resumed conversation shows no usage and no
|
|
570
|
+
* title until its first reply, which is exactly when they matter least.
|
|
571
|
+
*/
|
|
572
|
+
function announceSessionSoon(target) {
|
|
573
|
+
const forSession = sessionId;
|
|
574
|
+
setTimeout(() => {
|
|
575
|
+
if (session !== target || sessionId !== forSession)
|
|
576
|
+
return;
|
|
577
|
+
notifyUsage(target);
|
|
578
|
+
notifySessionInfo(target);
|
|
579
|
+
}, 0);
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* The id chunks of the current agent message share, minted on demand.
|
|
583
|
+
*/
|
|
584
|
+
function messageId() {
|
|
585
|
+
currentMessageId ??= `msg-${++messageSeq}`;
|
|
586
|
+
return currentMessageId;
|
|
587
|
+
}
|
|
588
|
+
/** Start a new message at the next chunk (tool call, or end of turn). */
|
|
589
|
+
function endMessage() {
|
|
590
|
+
currentMessageId = null;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Send the whole plan, which is what ACP requires: the client REPLACES its
|
|
594
|
+
* copy on every update rather than patching it, so a partial list would
|
|
595
|
+
* silently delete steps.
|
|
596
|
+
*/
|
|
597
|
+
function notifyPlan() {
|
|
598
|
+
if (planSteps.length === 0)
|
|
599
|
+
return;
|
|
600
|
+
notifyUpdate({ sessionUpdate: "plan", entries: planEntries(planSteps) });
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Adopt a freshly approved plan and show it to the client as a to-do list.
|
|
604
|
+
*
|
|
605
|
+
* Progress resets with the plan: `[DONE:n]` markers are relative to the plan
|
|
606
|
+
* that was approved, so carrying completions across a new one would mark
|
|
607
|
+
* steps of the new plan done that nobody has started.
|
|
608
|
+
*/
|
|
609
|
+
function adoptPlan(approvedPath) {
|
|
610
|
+
planPath = approvedPath;
|
|
611
|
+
planSteps = extractPlanSteps(readPlanFile(approvedPath));
|
|
612
|
+
completedSteps.clear();
|
|
613
|
+
notifyPlan();
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Advance the plan from `[DONE:n]` markers in the agent's own text.
|
|
617
|
+
*
|
|
618
|
+
* The plan is re-read rather than trusted from approval time because the
|
|
619
|
+
* agent is allowed to rewrite it while implementing (a 2-step plan becoming
|
|
620
|
+
* 12 is normal), and a frozen snapshot would report the wrong total and drop
|
|
621
|
+
* markers for steps it has never heard of.
|
|
622
|
+
*/
|
|
623
|
+
function refreshPlanProgress() {
|
|
624
|
+
if (planSteps.length === 0)
|
|
625
|
+
return;
|
|
626
|
+
let advanced = false;
|
|
627
|
+
for (const step of findCompletedMarkers(turnText)) {
|
|
628
|
+
if (completedSteps.has(step))
|
|
629
|
+
continue;
|
|
630
|
+
completedSteps.add(step);
|
|
631
|
+
advanced = true;
|
|
632
|
+
}
|
|
633
|
+
if (!advanced)
|
|
634
|
+
return;
|
|
635
|
+
const fresh = planPath ? extractPlanSteps(readPlanFile(planPath)) : [];
|
|
636
|
+
planSteps = markStepsCompleted(rebasePlanSteps(planSteps, fresh), completedSteps);
|
|
637
|
+
notifyPlan();
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Give the session a human-readable title, once.
|
|
641
|
+
*
|
|
642
|
+
* ACP expects this "after the first meaningful exchange", and GG already
|
|
643
|
+
* derives the same first-prompt title for its own session list — reusing it
|
|
644
|
+
* means a session is named identically on a phone, in the picker, and on
|
|
645
|
+
* disk instead of three near-misses.
|
|
646
|
+
*/
|
|
647
|
+
function notifySessionInfo(target) {
|
|
648
|
+
if (titleAnnounced || target !== session || !sessionId)
|
|
649
|
+
return;
|
|
650
|
+
const prompt = findUserSessionPrompt(target.getMessages()).replace(/\s+/g, " ").trim();
|
|
651
|
+
if (!prompt)
|
|
652
|
+
return;
|
|
653
|
+
titleAnnounced = true;
|
|
654
|
+
notifyUpdate({
|
|
655
|
+
sessionUpdate: "session_info_update",
|
|
656
|
+
title: prompt.length > 80 ? `${prompt.slice(0, 79)}…` : prompt,
|
|
657
|
+
updatedAt: new Date().toISOString(),
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Tell the client the session mode changed outside a request it made — the
|
|
662
|
+
* model itself can enter/exit plan mode mid-run via the enter_plan/exit_plan
|
|
663
|
+
* tools, and a picker that only tracks its own changes would lie.
|
|
664
|
+
*/
|
|
665
|
+
function notifyModeChange(modeId) {
|
|
666
|
+
if (!session)
|
|
667
|
+
return;
|
|
668
|
+
notifyUpdate({ sessionUpdate: "current_mode_update", currentModeId: modeId });
|
|
669
|
+
notifyUpdate({
|
|
670
|
+
sessionUpdate: "config_option_update",
|
|
671
|
+
configOptions: configOptionsFor(session),
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Tell the client which slash commands exist, once the session is up.
|
|
676
|
+
*
|
|
677
|
+
* Sent as a notification AFTER the response that created the session (a
|
|
678
|
+
* timer, not a microtask, so it cannot overtake it): the payload is addressed
|
|
679
|
+
* by sessionId, and a client that has not yet seen its own session/new result
|
|
680
|
+
* has nowhere to put it. The agent is the only party that can know its
|
|
681
|
+
* built-ins, so a client scanning `.ezcoder/commands` on its own would miss them.
|
|
682
|
+
*/
|
|
683
|
+
function notifyAvailableCommands(target) {
|
|
684
|
+
const forSession = sessionId;
|
|
685
|
+
setTimeout(() => {
|
|
686
|
+
// A second session/new (or a dispose) beat us here; that session will
|
|
687
|
+
// announce its own commands.
|
|
688
|
+
if (session !== target || sessionId !== forSession)
|
|
689
|
+
return;
|
|
690
|
+
void availableCommands(target, options.cwd)
|
|
691
|
+
.then((commands) => {
|
|
692
|
+
if (session !== target || sessionId !== forSession)
|
|
693
|
+
return;
|
|
694
|
+
notifyUpdate({
|
|
695
|
+
sessionUpdate: "available_commands_update",
|
|
696
|
+
availableCommands: commands,
|
|
697
|
+
});
|
|
698
|
+
})
|
|
699
|
+
// Command discovery reads the disk. A failure there must not take down
|
|
700
|
+
// a session that is otherwise fine.
|
|
701
|
+
.catch(() => { });
|
|
702
|
+
}, 0);
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* The finished tool call's result as an ACP file diff, or undefined when we
|
|
706
|
+
* cannot honestly produce one.
|
|
707
|
+
*
|
|
708
|
+
* A real diff is what lets a client render a reviewable side-by-side edit
|
|
709
|
+
* instead of a wall of text. It REPLACES the tool's text result rather than
|
|
710
|
+
* accompanying it: `edit` already returns a unified diff as prose, and
|
|
711
|
+
* showing both means the same change twice in two formats.
|
|
712
|
+
*
|
|
713
|
+
* A failed call is left as text on purpose — the error message is the useful
|
|
714
|
+
* output, and the file on disk did not change.
|
|
715
|
+
*/
|
|
716
|
+
function diffContent(toolCallId, isError) {
|
|
717
|
+
const snapshot = diffSnapshots.get(toolCallId);
|
|
718
|
+
if (!snapshot)
|
|
719
|
+
return undefined;
|
|
720
|
+
diffSnapshots.delete(toolCallId);
|
|
721
|
+
if (isError || !snapshot.before)
|
|
722
|
+
return undefined;
|
|
723
|
+
const after = snapshotForDiff(snapshot.path);
|
|
724
|
+
// `newText` is required by the schema, so a file that vanished or grew past
|
|
725
|
+
// the diff budget mid-call falls back to the tool's own text output.
|
|
726
|
+
if (!after || after.text === null)
|
|
727
|
+
return undefined;
|
|
728
|
+
return [
|
|
729
|
+
{
|
|
730
|
+
type: "diff",
|
|
731
|
+
path: snapshot.path,
|
|
732
|
+
oldText: snapshot.before.text,
|
|
733
|
+
newText: after.text,
|
|
734
|
+
},
|
|
735
|
+
];
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Bridge ezcoder's event bus onto `session/update` notifications.
|
|
739
|
+
*
|
|
740
|
+
* Every handler is synchronous and writes immediately, which is what keeps
|
|
741
|
+
* updates ordered ahead of the `session/prompt` response — a client that sees
|
|
742
|
+
* the result before the chunks renders an empty turn.
|
|
743
|
+
*/
|
|
744
|
+
function wire(target) {
|
|
745
|
+
const bus = target.eventBus;
|
|
746
|
+
unwire = [
|
|
747
|
+
bus.on("text_delta", ({ text }) => {
|
|
748
|
+
notifyUpdate({
|
|
749
|
+
sessionUpdate: "agent_message_chunk",
|
|
750
|
+
messageId: messageId(),
|
|
751
|
+
content: { type: "text", text },
|
|
752
|
+
});
|
|
753
|
+
// Plan markers arrive inside this text and can straddle two deltas, so
|
|
754
|
+
// the scan runs over the turn's accumulated text rather than the chunk.
|
|
755
|
+
// Only a delta that closes a bracket can complete a marker, which keeps
|
|
756
|
+
// this from re-scanning the whole turn on every token.
|
|
757
|
+
turnText += text;
|
|
758
|
+
if (text.includes("]"))
|
|
759
|
+
refreshPlanProgress();
|
|
760
|
+
}),
|
|
761
|
+
bus.on("thinking_delta", ({ text }) => {
|
|
762
|
+
notifyUpdate({
|
|
763
|
+
sessionUpdate: "agent_thought_chunk",
|
|
764
|
+
content: { type: "text", text },
|
|
765
|
+
});
|
|
766
|
+
}),
|
|
767
|
+
bus.on("tool_call_start", ({ toolCallId, name, args }) => {
|
|
768
|
+
// A tool call ends the message it interrupted; whatever the agent says
|
|
769
|
+
// afterwards is a new one.
|
|
770
|
+
endMessage();
|
|
771
|
+
const locations = toolLocations(args, options.cwd);
|
|
772
|
+
// Snapshot BEFORE the tool runs. This handler is synchronous and the
|
|
773
|
+
// tool starts writing immediately after it, which is the only window
|
|
774
|
+
// where the file still holds its pre-edit contents.
|
|
775
|
+
if (DIFF_TOOLS.has(name) && locations[0]) {
|
|
776
|
+
diffSnapshots.set(toolCallId, {
|
|
777
|
+
path: locations[0].path,
|
|
778
|
+
before: snapshotForDiff(locations[0].path),
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
notifyUpdate({
|
|
782
|
+
sessionUpdate: "tool_call",
|
|
783
|
+
toolCallId,
|
|
784
|
+
title: toolTitle(name, args),
|
|
785
|
+
name,
|
|
786
|
+
kind: toolKind(name),
|
|
787
|
+
status: "in_progress",
|
|
788
|
+
rawInput: args,
|
|
789
|
+
...(locations.length > 0 ? { locations } : {}),
|
|
790
|
+
});
|
|
791
|
+
}),
|
|
792
|
+
// Mid-flight tool progress. The payload is tool-defined, so it rides in
|
|
793
|
+
// `rawOutput` rather than being invented into content the client would
|
|
794
|
+
// then render as if it were final.
|
|
795
|
+
bus.on("tool_call_update", ({ toolCallId, update }) => {
|
|
796
|
+
notifyUpdate({
|
|
797
|
+
sessionUpdate: "tool_call_update",
|
|
798
|
+
toolCallId,
|
|
799
|
+
status: "in_progress",
|
|
800
|
+
rawOutput: update,
|
|
801
|
+
});
|
|
802
|
+
}),
|
|
803
|
+
bus.on("tool_call_end", ({ toolCallId, result, isError }) => {
|
|
804
|
+
notifyUpdate({
|
|
805
|
+
sessionUpdate: "tool_call_update",
|
|
806
|
+
toolCallId,
|
|
807
|
+
status: isError ? "failed" : "completed",
|
|
808
|
+
content: diffContent(toolCallId, isError) ?? [
|
|
809
|
+
{ type: "content", content: { type: "text", text: result } },
|
|
810
|
+
],
|
|
811
|
+
});
|
|
812
|
+
}),
|
|
813
|
+
// Turn-level outcomes are remembered rather than sent: ACP reports them
|
|
814
|
+
// once, as the `stopReason` of the prompt response.
|
|
815
|
+
bus.on("truncated", ({ reason }) => {
|
|
816
|
+
truncation = reason;
|
|
817
|
+
}),
|
|
818
|
+
bus.on("max_turns", () => {
|
|
819
|
+
hitMaxTurns = true;
|
|
820
|
+
}),
|
|
821
|
+
// Token accounting changes: after every model response, and after a
|
|
822
|
+
// compaction rebuilds the context. `compaction_end` fires once the
|
|
823
|
+
// compacted messages are installed, so the emit carries the POST-
|
|
824
|
+
// compaction count — the drop the client watches for.
|
|
825
|
+
bus.on("turn_end", () => {
|
|
826
|
+
notifyUsage(target);
|
|
827
|
+
notifySessionInfo(target);
|
|
828
|
+
// The turn is over: the next chunk starts a new message, and the next
|
|
829
|
+
// turn's markers are scanned against its own text.
|
|
830
|
+
endMessage();
|
|
831
|
+
turnText = "";
|
|
832
|
+
}),
|
|
833
|
+
bus.on("compaction_end", () => {
|
|
834
|
+
notifyUsage(target);
|
|
835
|
+
}),
|
|
836
|
+
];
|
|
837
|
+
}
|
|
838
|
+
function unwireAll() {
|
|
839
|
+
for (const off of unwire)
|
|
840
|
+
off();
|
|
841
|
+
unwire = [];
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Drop everything scoped to one session's lifetime. A new session inherits
|
|
845
|
+
* none of it: another session's plan progress, half-finished diffs or message
|
|
846
|
+
* numbering would all be reported as if they were its own.
|
|
847
|
+
*/
|
|
848
|
+
function resetSessionState() {
|
|
849
|
+
diffSnapshots.clear();
|
|
850
|
+
planPath = undefined;
|
|
851
|
+
planSteps = [];
|
|
852
|
+
completedSteps.clear();
|
|
853
|
+
turnText = "";
|
|
854
|
+
titleAnnounced = false;
|
|
855
|
+
currentMessageId = null;
|
|
856
|
+
messageSeq = 0;
|
|
857
|
+
}
|
|
858
|
+
async function disposeSession() {
|
|
859
|
+
if (!session)
|
|
860
|
+
return;
|
|
861
|
+
unwireAll();
|
|
862
|
+
resetSessionState();
|
|
863
|
+
const previous = session;
|
|
864
|
+
session = null;
|
|
865
|
+
sessionId = "";
|
|
866
|
+
await previous.dispose();
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Plan mode. Supplying these callbacks is what registers the
|
|
870
|
+
* enter_plan/exit_plan tools at all — without them the mode exists but the
|
|
871
|
+
* model cannot move between states. EZ Coder runs without approvals, so a
|
|
872
|
+
* submitted plan is auto-approved, the [DONE:n] contract is baked in so
|
|
873
|
+
* progress markers work as on the desktop, and the client is told about every
|
|
874
|
+
* mode change.
|
|
875
|
+
*
|
|
876
|
+
* They act on the CURRENT session rather than closing over one: a tool can
|
|
877
|
+
* only run inside a prompt, which is long after `startSession` published it.
|
|
878
|
+
*/
|
|
879
|
+
const planHooks = {
|
|
880
|
+
onEnterPlan: async () => {
|
|
881
|
+
await session?.setPlanMode(true);
|
|
882
|
+
notifyModeChange(MODE_PLAN);
|
|
883
|
+
},
|
|
884
|
+
onExitPlan: async (approvedPath) => {
|
|
885
|
+
await session?.setPlanMode(false);
|
|
886
|
+
await session?.setApprovedPlan(approvedPath);
|
|
887
|
+
notifyModeChange(MODE_DEFAULT);
|
|
888
|
+
// The approved plan becomes the client's to-do list, which then advances
|
|
889
|
+
// from the [DONE:n] markers the returned instruction asks for.
|
|
890
|
+
adoptPlan(approvedPath);
|
|
891
|
+
return "Plan approved. Proceed with implementation, marking each completed step with [DONE:n].";
|
|
892
|
+
},
|
|
893
|
+
};
|
|
894
|
+
const createSession = options.createSession ??
|
|
895
|
+
((signal, hooks) => new AgentSession({
|
|
896
|
+
provider: options.provider,
|
|
897
|
+
model: options.model,
|
|
898
|
+
cwd: options.cwd,
|
|
899
|
+
baseUrl: options.baseUrl,
|
|
900
|
+
systemPrompt: options.systemPrompt,
|
|
901
|
+
thinkingLevel: options.thinkingLevel,
|
|
902
|
+
// MCP connect (spawning stdio servers, HTTP handshakes) takes seconds
|
|
903
|
+
// and would otherwise sit on the critical path of session/new and
|
|
904
|
+
// session/load. The desktop sidecar already ships this path: the tool
|
|
905
|
+
// catalog is seeded from the disk cache so tools are visible
|
|
906
|
+
// immediately, and live connections promote in the background. A phone
|
|
907
|
+
// client gets its session in milliseconds and the same tools a moment
|
|
908
|
+
// later.
|
|
909
|
+
backgroundMcpConnect: true,
|
|
910
|
+
onEnterPlan: hooks.onEnterPlan,
|
|
911
|
+
onExitPlan: hooks.onExitPlan,
|
|
912
|
+
signal,
|
|
913
|
+
}));
|
|
914
|
+
// ── Method handlers ──────────────────────────────────────
|
|
915
|
+
function handleInitialize() {
|
|
916
|
+
return {
|
|
917
|
+
protocolVersion: ACP_PROTOCOL_VERSION,
|
|
918
|
+
agentCapabilities: {
|
|
919
|
+
loadSession: true,
|
|
920
|
+
promptCapabilities: { image: false, audio: false, embeddedContext: false },
|
|
921
|
+
mcpCapabilities: { http: false, sse: false, acp: false },
|
|
922
|
+
// `{}` is how ACP says "supported" for a capability with no options of
|
|
923
|
+
// its own. Omitting the key means unsupported, so this is not cosmetic.
|
|
924
|
+
sessionCapabilities: { list: {}, resume: {}, close: {}, delete: {} },
|
|
925
|
+
},
|
|
926
|
+
authMethods: [],
|
|
927
|
+
agentInfo: { name: "ezcoder", title: "EZ Coder", version: options.version },
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Start a session, optionally replaying a stored one into it.
|
|
932
|
+
*
|
|
933
|
+
* `session/new` and `session/load` differ only in whether history is
|
|
934
|
+
* restored first, so they share this path rather than drifting apart.
|
|
935
|
+
*/
|
|
936
|
+
async function startSession(restorePath) {
|
|
937
|
+
// Replacing an in-flight session would strand the prompt that is running
|
|
938
|
+
// on it, so the old one is stopped first, deliberately and visibly.
|
|
939
|
+
await disposeSession();
|
|
940
|
+
abort = new AbortController();
|
|
941
|
+
const created = createSession(abort.signal, planHooks);
|
|
942
|
+
await created.initialize();
|
|
943
|
+
if (restorePath)
|
|
944
|
+
await created.loadSession(restorePath);
|
|
945
|
+
session = created;
|
|
946
|
+
sessionId = created.getState().sessionId;
|
|
947
|
+
wire(created);
|
|
948
|
+
return created;
|
|
949
|
+
}
|
|
950
|
+
async function handleNewSession() {
|
|
951
|
+
const created = await startSession();
|
|
952
|
+
notifyAvailableCommands(created);
|
|
953
|
+
announceSessionSoon(created);
|
|
954
|
+
return { sessionId, configOptions: configOptionsFor(created), modes: sessionModes(created) };
|
|
955
|
+
}
|
|
956
|
+
/** The directory a request is about, defaulting to the one we were started in. */
|
|
957
|
+
function requestCwd(params) {
|
|
958
|
+
const cwd = params?.cwd;
|
|
959
|
+
return typeof cwd === "string" && cwd ? cwd : options.cwd;
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Stored sessions, newest first.
|
|
963
|
+
*
|
|
964
|
+
* This is the answer to "see everything that was on EZ Coder": the phone asks
|
|
965
|
+
* the agent, and the agent reads the same `~/.ezcoder/sessions` files the desktop
|
|
966
|
+
* browses — no separate index to fall out of step.
|
|
967
|
+
*
|
|
968
|
+
* ACP makes `cwd` nullable here on purpose. Omitted means EVERY project, not
|
|
969
|
+
* the agent's own directory: a remote client is asking what you have been
|
|
970
|
+
* working on, and that spans checkouts. Each entry carries its own `cwd` so
|
|
971
|
+
* the client can group by project.
|
|
972
|
+
*/
|
|
973
|
+
async function handleListSessions(params) {
|
|
974
|
+
const scope = params?.cwd;
|
|
975
|
+
const stored = typeof scope === "string" && scope
|
|
976
|
+
? await listSessionSummaries(scope)
|
|
977
|
+
: await listAllSessions();
|
|
978
|
+
return {
|
|
979
|
+
sessions: stored
|
|
980
|
+
// An empty session has nothing to resume and nothing to title; listing
|
|
981
|
+
// it would fill the phone with identical blank rows.
|
|
982
|
+
.filter((entry) => entry.hasMessages)
|
|
983
|
+
.map((entry) => ({
|
|
984
|
+
sessionId: entry.id,
|
|
985
|
+
cwd: entry.cwd,
|
|
986
|
+
// Captured during the listing pass, so titling the whole machine's
|
|
987
|
+
// history costs no extra reads.
|
|
988
|
+
title: entry.preview ?? null,
|
|
989
|
+
updatedAt: entry.lastActivity,
|
|
990
|
+
})),
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
/**
|
|
994
|
+
* Resume a stored session and replay it to the client.
|
|
995
|
+
*
|
|
996
|
+
* The transcript is streamed as `session/update` notifications BEFORE this
|
|
997
|
+
* resolves, which is what the protocol requires and what lets a client draw a
|
|
998
|
+
* resumed conversation with its normal live-turn rendering.
|
|
999
|
+
*/
|
|
1000
|
+
async function handleLoadSession(params) {
|
|
1001
|
+
const requested = params?.sessionId;
|
|
1002
|
+
if (typeof requested !== "string" || !requested) {
|
|
1003
|
+
throw new InvalidParams("session/load requires a sessionId.");
|
|
1004
|
+
}
|
|
1005
|
+
// Searched by id across every project directory, not just `cwd`: a client
|
|
1006
|
+
// lists sessions from wherever it probed and reopens them against the
|
|
1007
|
+
// directory the session belongs to, so those two rarely match.
|
|
1008
|
+
const sessionPath = await findSessionById(requested, requestCwd(params));
|
|
1009
|
+
if (!sessionPath)
|
|
1010
|
+
throw new InvalidParams(`Unknown session '${requested}'.`);
|
|
1011
|
+
const restored = await startSession(sessionPath);
|
|
1012
|
+
// Display history is reconstructed separately. The live AgentSession above
|
|
1013
|
+
// deliberately keeps only the canonical newest checkpoint as model context.
|
|
1014
|
+
const checkpoints = await loadSessionCheckpointChain(sessionPath);
|
|
1015
|
+
const displayMessages = reconstructCheckpointHistory(checkpoints);
|
|
1016
|
+
// The id the client asked for is the id it keeps using; `loadSession` may
|
|
1017
|
+
// adopt a different internal one, and answering with that would leave the
|
|
1018
|
+
// client addressing a session it never heard of.
|
|
1019
|
+
sessionId = requested;
|
|
1020
|
+
for (const update of historyUpdates(displayMessages))
|
|
1021
|
+
notifyUpdate(update);
|
|
1022
|
+
notifyAvailableCommands(restored);
|
|
1023
|
+
announceSessionSoon(restored);
|
|
1024
|
+
return { configOptions: configOptionsFor(restored), modes: sessionModes(restored) };
|
|
1025
|
+
}
|
|
1026
|
+
/**
|
|
1027
|
+
* Abort the running turn and WAIT for it to unwind.
|
|
1028
|
+
*
|
|
1029
|
+
* `handleCancel` only signals: `session.prompt()` keeps unwinding after it
|
|
1030
|
+
* returns, and its last act is persisting the turn. Disposing before that
|
|
1031
|
+
* finishes clears the session path out from under the write, so the final
|
|
1032
|
+
* exchange is silently dropped and the session is missing its tail when the
|
|
1033
|
+
* user comes back to it. The read loop's own teardown already waits like
|
|
1034
|
+
* this; a lifecycle request that tears a session down mid-turn must too.
|
|
1035
|
+
*/
|
|
1036
|
+
async function cancelAndSettle() {
|
|
1037
|
+
handleCancel();
|
|
1038
|
+
await Promise.allSettled([...inFlight]);
|
|
1039
|
+
}
|
|
1040
|
+
/** The sessionId a lifecycle request names, validated. */
|
|
1041
|
+
function requestedSessionId(params, method) {
|
|
1042
|
+
const requested = params?.sessionId;
|
|
1043
|
+
if (typeof requested !== "string" || !requested) {
|
|
1044
|
+
throw new InvalidParams(`${method} requires a sessionId.`);
|
|
1045
|
+
}
|
|
1046
|
+
return requested;
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Reconnect to a stored session WITHOUT replaying it.
|
|
1050
|
+
*
|
|
1051
|
+
* The difference from `session/load` is the whole point: a client that still
|
|
1052
|
+
* holds the transcript (it was showing this session a moment ago) wants the
|
|
1053
|
+
* agent-side context back, not a second copy of every message pushed at it.
|
|
1054
|
+
*/
|
|
1055
|
+
async function handleResumeSession(params) {
|
|
1056
|
+
const requested = requestedSessionId(params, "session/resume");
|
|
1057
|
+
const sessionPath = await findSessionById(requested, requestCwd(params));
|
|
1058
|
+
if (!sessionPath)
|
|
1059
|
+
throw new InvalidParams(`Unknown session '${requested}'.`);
|
|
1060
|
+
const restored = await startSession(sessionPath);
|
|
1061
|
+
// As in session/load: the client keeps addressing the id it asked for.
|
|
1062
|
+
sessionId = requested;
|
|
1063
|
+
notifyAvailableCommands(restored);
|
|
1064
|
+
announceSessionSoon(restored);
|
|
1065
|
+
return { configOptions: configOptionsFor(restored), modes: sessionModes(restored) };
|
|
1066
|
+
}
|
|
1067
|
+
/**
|
|
1068
|
+
* Close the active session, cancelling whatever it is doing.
|
|
1069
|
+
*
|
|
1070
|
+
* The spec requires the in-flight turn to be cancelled exactly as
|
|
1071
|
+
* `session/cancel` would, so this reuses that path rather than tearing the
|
|
1072
|
+
* session down underneath a running agent loop.
|
|
1073
|
+
*/
|
|
1074
|
+
async function handleCloseSession(params) {
|
|
1075
|
+
const requested = requestedSessionId(params, "session/close");
|
|
1076
|
+
if (!session || requested !== sessionId) {
|
|
1077
|
+
throw new InvalidParams(`Session '${requested}' is not active.`);
|
|
1078
|
+
}
|
|
1079
|
+
await cancelAndSettle();
|
|
1080
|
+
await disposeSession();
|
|
1081
|
+
return {};
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Delete a stored session from disk.
|
|
1085
|
+
*
|
|
1086
|
+
* Hard delete, including the archive and asset siblings, because a session
|
|
1087
|
+
* left half-present would come back as a broken row in the next
|
|
1088
|
+
* `session/list`. Deleting something that is not there succeeds silently:
|
|
1089
|
+
* the spec asks for idempotence, and the user's intent is already satisfied.
|
|
1090
|
+
*/
|
|
1091
|
+
async function handleDeleteSession(params) {
|
|
1092
|
+
const requested = requestedSessionId(params, "session/delete");
|
|
1093
|
+
const sessionPath = await findSessionById(requested, requestCwd(params));
|
|
1094
|
+
if (!sessionPath)
|
|
1095
|
+
return {};
|
|
1096
|
+
// Deleting the session we are serving would leave a live AgentSession
|
|
1097
|
+
// appending to a file that no longer exists, quietly recreating it.
|
|
1098
|
+
if (session && requested === sessionId) {
|
|
1099
|
+
await cancelAndSettle();
|
|
1100
|
+
await disposeSession();
|
|
1101
|
+
}
|
|
1102
|
+
const group = sessionGroupPaths(sessionPath);
|
|
1103
|
+
for (const target of [group.plainPath, group.archivePath, group.assetsPath]) {
|
|
1104
|
+
await rm(target, { recursive: true, force: true });
|
|
1105
|
+
}
|
|
1106
|
+
return {};
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Switch session mode (ACP `session/set_mode`; Zed's mode picker uses this,
|
|
1110
|
+
* pew2 routes it through session/set_config_option with configId "mode").
|
|
1111
|
+
*/
|
|
1112
|
+
async function handleSetMode(params) {
|
|
1113
|
+
if (!session)
|
|
1114
|
+
throw new InvalidParams("No session. Call session/new first.");
|
|
1115
|
+
const modeId = params?.modeId;
|
|
1116
|
+
if (modeId !== MODE_DEFAULT && modeId !== MODE_PLAN) {
|
|
1117
|
+
throw new InvalidParams(`Unknown mode '${String(modeId)}'.`);
|
|
1118
|
+
}
|
|
1119
|
+
const plan = modeId === MODE_PLAN;
|
|
1120
|
+
if (session.getPlanMode() !== plan) {
|
|
1121
|
+
await session.setPlanMode(plan);
|
|
1122
|
+
notifyModeChange(modeId);
|
|
1123
|
+
}
|
|
1124
|
+
return {};
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Apply a selector change from the client.
|
|
1128
|
+
*
|
|
1129
|
+
* Replies with the COMPLETE option set rather than the one that changed:
|
|
1130
|
+
* switching model can move the thinking ceiling, and a client that only
|
|
1131
|
+
* patched the field it sent would keep offering levels the new model ignores.
|
|
1132
|
+
*/
|
|
1133
|
+
async function handleSetConfigOption(params) {
|
|
1134
|
+
if (!session)
|
|
1135
|
+
throw new InvalidParams("No session. Call session/new first.");
|
|
1136
|
+
const { configId, value } = (params ?? {});
|
|
1137
|
+
if (typeof configId !== "string" || typeof value !== "string") {
|
|
1138
|
+
throw new InvalidParams("session/set_config_option requires a configId and a string value.");
|
|
1139
|
+
}
|
|
1140
|
+
if (configId === MODEL_CONFIG_ID) {
|
|
1141
|
+
const target = getModel(value);
|
|
1142
|
+
if (!target)
|
|
1143
|
+
throw new InvalidParams(`Unknown model '${value}'.`);
|
|
1144
|
+
await session.switchModel(target.provider, target.id);
|
|
1145
|
+
// Thinking levels are per-model, so a level the previous model allowed can
|
|
1146
|
+
// be above the new one's ceiling. Clamping here keeps the session's actual
|
|
1147
|
+
// effort equal to what the client is about to be told it is.
|
|
1148
|
+
const current = session.getThinkingLevel();
|
|
1149
|
+
if (current) {
|
|
1150
|
+
const allowed = thinkingOptionsFor(target.id).map((option) => option.value);
|
|
1151
|
+
if (!allowed.includes(current))
|
|
1152
|
+
session.setThinkingLevel(getMaxThinkingLevel(target.id));
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
else if (configId === MODE_CONFIG_ID) {
|
|
1156
|
+
// Share the dedicated handler so both entry points behave identically.
|
|
1157
|
+
await handleSetMode({
|
|
1158
|
+
sessionId: params?.sessionId,
|
|
1159
|
+
modeId: value,
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
else if (configId === THINKING_CONFIG_ID) {
|
|
1163
|
+
if (value === THINKING_OFF) {
|
|
1164
|
+
session.setThinkingLevel(undefined);
|
|
1165
|
+
}
|
|
1166
|
+
else {
|
|
1167
|
+
const { model } = session.getState();
|
|
1168
|
+
const allowed = thinkingOptionsFor(model).map((option) => option.value);
|
|
1169
|
+
if (!allowed.includes(value)) {
|
|
1170
|
+
throw new InvalidParams(`Model '${model}' does not support thinking level '${value}'.`);
|
|
1171
|
+
}
|
|
1172
|
+
session.setThinkingLevel(value);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
else {
|
|
1176
|
+
throw new InvalidParams(`Unknown config option '${configId}'.`);
|
|
1177
|
+
}
|
|
1178
|
+
return { configOptions: configOptionsFor(session) };
|
|
1179
|
+
}
|
|
1180
|
+
/** Flatten ACP prompt blocks to the plain text `AgentSession` accepts. */
|
|
1181
|
+
function promptText(params) {
|
|
1182
|
+
const blocks = params?.prompt;
|
|
1183
|
+
if (!Array.isArray(blocks))
|
|
1184
|
+
return "";
|
|
1185
|
+
return blocks
|
|
1186
|
+
.map((block) => {
|
|
1187
|
+
const entry = block;
|
|
1188
|
+
return entry?.type === "text" && typeof entry.text === "string" ? entry.text : "";
|
|
1189
|
+
})
|
|
1190
|
+
.filter(Boolean)
|
|
1191
|
+
.join("\n")
|
|
1192
|
+
.trim();
|
|
1193
|
+
}
|
|
1194
|
+
async function handlePrompt(params) {
|
|
1195
|
+
if (!session)
|
|
1196
|
+
throw new InvalidParams("No session. Call session/new first.");
|
|
1197
|
+
if (running)
|
|
1198
|
+
throw new InvalidParams("A prompt is already running in this session.");
|
|
1199
|
+
const text = promptText(params);
|
|
1200
|
+
if (!text)
|
|
1201
|
+
throw new InvalidParams("prompt must contain at least one non-empty text block.");
|
|
1202
|
+
running = true;
|
|
1203
|
+
cancelled = false;
|
|
1204
|
+
truncation = undefined;
|
|
1205
|
+
hitMaxTurns = false;
|
|
1206
|
+
try {
|
|
1207
|
+
await session.prompt(text);
|
|
1208
|
+
}
|
|
1209
|
+
catch (err) {
|
|
1210
|
+
// A cancel aborts the loop, which surfaces here. The spec requires the
|
|
1211
|
+
// turn to still resolve with `cancelled` rather than reject — the client
|
|
1212
|
+
// is confirming its own cancel, not being told something went wrong.
|
|
1213
|
+
if (cancelled || isAbortError(err))
|
|
1214
|
+
return { stopReason: "cancelled" };
|
|
1215
|
+
throw err;
|
|
1216
|
+
}
|
|
1217
|
+
finally {
|
|
1218
|
+
running = false;
|
|
1219
|
+
// Drop any before-snapshot whose tool never reported an end. A cancelled
|
|
1220
|
+
// turn stops emitting tool events, so `diffContent` — the only other
|
|
1221
|
+
// place these are removed — never runs for the call that was in flight,
|
|
1222
|
+
// and its file contents would stay pinned for the rest of the session.
|
|
1223
|
+
// Cleared here rather than on `turn_end`, which fires before that turn's
|
|
1224
|
+
// tools execute and would discard snapshots still in use.
|
|
1225
|
+
diffSnapshots.clear();
|
|
1226
|
+
}
|
|
1227
|
+
return { stopReason: cancelled ? "cancelled" : stopReasonFor(truncation, hitMaxTurns) };
|
|
1228
|
+
}
|
|
1229
|
+
function handleCancel() {
|
|
1230
|
+
if (!running || !session)
|
|
1231
|
+
return;
|
|
1232
|
+
cancelled = true;
|
|
1233
|
+
abort.abort();
|
|
1234
|
+
// `AgentSession` keeps the construction signal for future turns. Re-arm it
|
|
1235
|
+
// immediately after aborting this turn, or every later prompt sees an
|
|
1236
|
+
// already-aborted signal and silently completes with no output.
|
|
1237
|
+
abort = new AbortController();
|
|
1238
|
+
session.setSignal(abort.signal);
|
|
1239
|
+
}
|
|
1240
|
+
async function dispatch(method, params) {
|
|
1241
|
+
switch (method) {
|
|
1242
|
+
case "initialize":
|
|
1243
|
+
return handleInitialize();
|
|
1244
|
+
case "session/new":
|
|
1245
|
+
return handleNewSession();
|
|
1246
|
+
case "session/prompt":
|
|
1247
|
+
return handlePrompt(params);
|
|
1248
|
+
case "session/list":
|
|
1249
|
+
return handleListSessions(params);
|
|
1250
|
+
case "session/load":
|
|
1251
|
+
return handleLoadSession(params);
|
|
1252
|
+
case "session/resume":
|
|
1253
|
+
return handleResumeSession(params);
|
|
1254
|
+
case "session/close":
|
|
1255
|
+
return handleCloseSession(params);
|
|
1256
|
+
case "session/delete":
|
|
1257
|
+
return handleDeleteSession(params);
|
|
1258
|
+
case "session/set_config_option":
|
|
1259
|
+
return handleSetConfigOption(params);
|
|
1260
|
+
case "session/set_mode":
|
|
1261
|
+
return handleSetMode(params);
|
|
1262
|
+
default:
|
|
1263
|
+
return undefined;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
// ── Read loop ────────────────────────────────────────────
|
|
1267
|
+
const rl = readline.createInterface({ input, terminal: false });
|
|
1268
|
+
/**
|
|
1269
|
+
* Requests still being served.
|
|
1270
|
+
*
|
|
1271
|
+
* Requests are dispatched WITHOUT blocking the read loop, because
|
|
1272
|
+
* `session/prompt` runs for as long as the agent does — awaiting it here
|
|
1273
|
+
* would mean `session/cancel` is not read until the turn it cancels has
|
|
1274
|
+
* already finished. That is a deadlock, not a slow path.
|
|
1275
|
+
*/
|
|
1276
|
+
const inFlight = new Set();
|
|
1277
|
+
function serve(id, method, params) {
|
|
1278
|
+
const task = (async () => {
|
|
1279
|
+
try {
|
|
1280
|
+
const result = await dispatch(method, params);
|
|
1281
|
+
if (result === undefined) {
|
|
1282
|
+
fail(id, RPC_METHOD_NOT_FOUND, `Unsupported method: ${method}`);
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
respond(id, result);
|
|
1286
|
+
}
|
|
1287
|
+
catch (err) {
|
|
1288
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1289
|
+
const code = err instanceof InvalidParams ? RPC_INVALID_PARAMS : RPC_INTERNAL_ERROR;
|
|
1290
|
+
fail(id, code, message);
|
|
1291
|
+
}
|
|
1292
|
+
})();
|
|
1293
|
+
inFlight.add(task);
|
|
1294
|
+
void task.finally(() => inFlight.delete(task));
|
|
1295
|
+
}
|
|
1296
|
+
try {
|
|
1297
|
+
for await (const line of rl) {
|
|
1298
|
+
if (!line.trim())
|
|
1299
|
+
continue;
|
|
1300
|
+
let frame;
|
|
1301
|
+
try {
|
|
1302
|
+
frame = JSON.parse(line);
|
|
1303
|
+
}
|
|
1304
|
+
catch {
|
|
1305
|
+
// No id to answer against, so this is the one case that uses a null id,
|
|
1306
|
+
// exactly as JSON-RPC 2.0 prescribes for unparseable input.
|
|
1307
|
+
write({
|
|
1308
|
+
jsonrpc: "2.0",
|
|
1309
|
+
id: null,
|
|
1310
|
+
error: { code: RPC_PARSE_ERROR, message: "Invalid JSON" },
|
|
1311
|
+
});
|
|
1312
|
+
continue;
|
|
1313
|
+
}
|
|
1314
|
+
const { id, method } = frame;
|
|
1315
|
+
if (typeof method !== "string") {
|
|
1316
|
+
if (id !== undefined)
|
|
1317
|
+
fail(id, RPC_INVALID_REQUEST, "Missing 'method'");
|
|
1318
|
+
continue;
|
|
1319
|
+
}
|
|
1320
|
+
// Notifications: no id, no response, ever — answering one is a protocol
|
|
1321
|
+
// violation that some clients treat as a fatal desync.
|
|
1322
|
+
if (id === undefined) {
|
|
1323
|
+
if (method === "session/cancel")
|
|
1324
|
+
handleCancel();
|
|
1325
|
+
continue;
|
|
1326
|
+
}
|
|
1327
|
+
serve(id, method, frame.params);
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
finally {
|
|
1331
|
+
rl.close();
|
|
1332
|
+
// The client is gone, so a turn still running has nowhere to report to.
|
|
1333
|
+
// Cancelling first is what stops the wait below from being unbounded.
|
|
1334
|
+
handleCancel();
|
|
1335
|
+
// A disconnect mid-turn must still not tear the session out from under the
|
|
1336
|
+
// run that is writing to it.
|
|
1337
|
+
await Promise.allSettled([...inFlight]);
|
|
1338
|
+
await disposeSession().catch(() => { });
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* CLI entry point: serve ACP on the real stdio, then exit.
|
|
1343
|
+
*
|
|
1344
|
+
* Split from {@link runAcpMode} so the protocol can be tested without the
|
|
1345
|
+
* process-level side effects (signal handlers, logger teardown, exit codes).
|
|
1346
|
+
*/
|
|
1347
|
+
export async function runAcpModeCli(options) {
|
|
1348
|
+
const onSigint = () => {
|
|
1349
|
+
// An ACP agent is driven entirely by its client; Ctrl-C is the user asking
|
|
1350
|
+
// the process to end, not the current turn to stop.
|
|
1351
|
+
process.exit(130);
|
|
1352
|
+
};
|
|
1353
|
+
process.on("SIGINT", onSigint);
|
|
1354
|
+
try {
|
|
1355
|
+
await runAcpMode(options);
|
|
1356
|
+
}
|
|
1357
|
+
catch (err) {
|
|
1358
|
+
process.stderr.write(`${formatUserError(err)}\n`);
|
|
1359
|
+
process.exitCode = 1;
|
|
1360
|
+
}
|
|
1361
|
+
finally {
|
|
1362
|
+
process.removeListener("SIGINT", onSigint);
|
|
1363
|
+
closeLogger();
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
//# sourceMappingURL=acp-mode.js.map
|