@gajae-code/coding-agent 0.11.1 → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -0
- package/dist/types/cli/config-cli.d.ts +11 -1
- package/dist/types/cli/launch-disposition.d.ts +23 -0
- package/dist/types/cli/notify-cli.d.ts +1 -0
- package/dist/types/cli/session-picker.d.ts +2 -1
- package/dist/types/cli/setup-cli.d.ts +1 -1
- package/dist/types/commands/mcp-serve.d.ts +33 -0
- package/dist/types/commands/mcp.d.ts +1 -1
- package/dist/types/commands/notify.d.ts +0 -2
- package/dist/types/commands/sdk.d.ts +1 -1
- package/dist/types/config/atomic-yaml-patch.d.ts +18 -0
- package/dist/types/config/file-lock.d.ts +14 -4
- package/dist/types/config/keybindings.d.ts +42 -1
- package/dist/types/config/model-auth.d.ts +3 -0
- package/dist/types/config/model-bindings-applier.d.ts +13 -0
- package/dist/types/config/model-discovery-manager.d.ts +49 -0
- package/dist/types/config/model-equivalence.d.ts +20 -0
- package/dist/types/config/model-registry.d.ts +16 -15
- package/dist/types/config/model-resolver.d.ts +28 -18
- package/dist/types/config/models-config-schema.d.ts +11 -0
- package/dist/types/config/settings-schema.d.ts +141 -11
- package/dist/types/config/settings.d.ts +14 -11
- package/dist/types/coordinator-mcp/policy.d.ts +5 -0
- package/dist/types/coordinator-mcp/question-gate-codec.d.ts +129 -0
- package/dist/types/coordinator-mcp/question-state.d.ts +356 -0
- package/dist/types/coordinator-mcp/server.d.ts +4 -0
- package/dist/types/discovery/helpers.d.ts +0 -6
- package/dist/types/edit/index.d.ts +3 -0
- package/dist/types/eval/py/env.d.ts +9 -0
- package/dist/types/extensibility/extensions/loader.d.ts +2 -1
- package/dist/types/extensibility/extensions/runner.d.ts +2 -2
- package/dist/types/extensibility/extensions/types.d.ts +34 -3
- package/dist/types/extensibility/hooks/runner.d.ts +1 -1
- package/dist/types/extensibility/shared-events.d.ts +2 -0
- package/dist/types/gjc-runtime/deep-interview-recorder.d.ts +10 -1
- package/dist/types/gjc-runtime/deep-interview-state.d.ts +44 -0
- package/dist/types/gjc-runtime/goal-mode-request.d.ts +11 -1
- package/dist/types/gjc-runtime/launch-worktree.d.ts +4 -2
- package/dist/types/gjc-runtime/linux-proc.d.ts +29 -0
- package/dist/types/gjc-runtime/session-resolution.d.ts +2 -2
- package/dist/types/gjc-runtime/state-migrations.d.ts +1 -1
- package/dist/types/gjc-runtime/state-writer.d.ts +2 -1
- package/dist/types/gjc-runtime/team-launch.d.ts +59 -0
- package/dist/types/gjc-runtime/team-notify.d.ts +45 -0
- package/dist/types/gjc-runtime/team-runtime.d.ts +29 -121
- package/dist/types/gjc-runtime/team-store.d.ts +160 -0
- package/dist/types/gjc-runtime/team-workers.d.ts +78 -0
- package/dist/types/gjc-runtime/tmux-owner-isolation.d.ts +8 -0
- package/dist/types/gjc-runtime/ultragoal-change-set.d.ts +13 -0
- package/dist/types/gjc-runtime/ultragoal-evidence.d.ts +38 -0
- package/dist/types/gjc-runtime/ultragoal-guard.d.ts +7 -0
- package/dist/types/gjc-runtime/ultragoal-pipeline.d.ts +23 -0
- package/dist/types/gjc-runtime/ultragoal-runtime.d.ts +55 -33
- package/dist/types/gjc-runtime/workflow-cli-common.d.ts +8 -0
- package/dist/types/gjc-runtime/workflow-manifest.d.ts +3 -0
- package/dist/types/goals/continuation-timeout-guard.d.ts +22 -0
- package/dist/types/goals/runtime.d.ts +1 -0
- package/dist/types/goals/state.d.ts +8 -0
- package/dist/types/harness-control-plane/lifecycle-reconciliation.d.ts +17 -0
- package/dist/types/harness-control-plane/phase-rollup.d.ts +4 -7
- package/dist/types/harness-control-plane/receipt-ingest.d.ts +5 -0
- package/dist/types/harness-control-plane/receipt-spool.d.ts +4 -0
- package/dist/types/hindsight/state.d.ts +11 -4
- package/dist/types/lsp/lspmux.d.ts +5 -3
- package/dist/types/lsp/path-trust.d.ts +1 -0
- package/dist/types/main.d.ts +4 -2
- package/dist/types/memories/storage.d.ts +1 -0
- package/dist/types/modes/action-registry.d.ts +29 -0
- package/dist/types/modes/components/chrome.d.ts +14 -0
- package/dist/types/modes/components/command-palette.d.ts +27 -0
- package/dist/types/modes/components/custom-provider-wizard.d.ts +1 -0
- package/dist/types/modes/components/index.d.ts +2 -1
- package/dist/types/modes/components/pet-selector.d.ts +1 -1
- package/dist/types/modes/components/plan-preview-overlay.d.ts +43 -0
- package/dist/types/modes/components/queue-mode-selector.d.ts +1 -1
- package/dist/types/modes/components/queue-pane.d.ts +12 -0
- package/dist/types/modes/components/read-tool-group.d.ts +6 -0
- package/dist/types/modes/components/session-observer-overlay.d.ts +3 -4
- package/dist/types/modes/components/sessions-dashboard.d.ts +32 -0
- package/dist/types/modes/components/settings-selector.d.ts +1 -1
- package/dist/types/modes/components/show-images-selector.d.ts +1 -1
- package/dist/types/modes/components/status-line/types.d.ts +1 -1
- package/dist/types/modes/components/status-line.d.ts +1 -94
- package/dist/types/modes/components/tasks-pane.d.ts +15 -0
- package/dist/types/modes/components/theme-selector.d.ts +1 -1
- package/dist/types/modes/components/tool-execution.d.ts +15 -0
- package/dist/types/modes/components/tool-status-header.d.ts +111 -0
- package/dist/types/modes/components/transcript-viewer-overlay.d.ts +42 -0
- package/dist/types/modes/controllers/goal-mode-controller.d.ts +62 -0
- package/dist/types/modes/controllers/input-controller.d.ts +8 -1
- package/dist/types/modes/controllers/mode-gate.d.ts +8 -0
- package/dist/types/modes/controllers/plan-mode-controller.d.ts +65 -0
- package/dist/types/modes/controllers/selector-controller.d.ts +15 -3
- package/dist/types/modes/controllers/stt-controller.d.ts +26 -0
- package/dist/types/modes/interactive-mode.d.ts +19 -17
- package/dist/types/modes/jobs-observer.d.ts +2 -0
- package/dist/types/modes/prompt-action-autocomplete.d.ts +4 -0
- package/dist/types/modes/shared/agent-wire/deep-interview-gate.d.ts +4 -11
- package/dist/types/modes/shared/agent-wire/workflow-gate-broker.d.ts +20 -2
- package/dist/types/modes/shared/agent-wire/workflow-gate-types.d.ts +31 -0
- package/dist/types/modes/tasks-aggregator.d.ts +39 -0
- package/dist/types/modes/transcript-item-registry.d.ts +60 -0
- package/dist/types/modes/types.d.ts +20 -13
- package/dist/types/modes/utils/ui-helpers.d.ts +2 -2
- package/dist/types/runtime-mcp/manager.d.ts +1 -1
- package/dist/types/sdk/broker/broker.d.ts +78 -12
- package/dist/types/sdk/broker/lifecycle-codec.d.ts +4 -0
- package/dist/types/sdk/broker/lifecycle-ledger.d.ts +15 -1
- package/dist/types/sdk/broker/lifecycle.d.ts +6 -2
- package/dist/types/sdk/broker/process-incarnation.d.ts +2 -0
- package/dist/types/sdk/broker/session-index.d.ts +0 -1
- package/dist/types/sdk/broker/state-version.d.ts +2 -0
- package/dist/types/sdk/bus/chat-effect-journal.d.ts +1 -0
- package/dist/types/sdk/bus/config-commands.d.ts +1 -1
- package/dist/types/sdk/bus/config.d.ts +11 -0
- package/dist/types/sdk/bus/daemon-paths.d.ts +1 -0
- package/dist/types/sdk/bus/html-format.d.ts +3 -2
- package/dist/types/sdk/bus/index.d.ts +29 -0
- package/dist/types/sdk/bus/lifecycle-control-runtime.d.ts +4 -0
- package/dist/types/sdk/bus/notification-service.d.ts +20 -0
- package/dist/types/sdk/bus/rate-limit-pool.d.ts +13 -2
- package/dist/types/sdk/bus/recent-activity.d.ts +21 -12
- package/dist/types/sdk/bus/rich-document.d.ts +7 -0
- package/dist/types/sdk/bus/rich-render.d.ts +18 -41
- package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +9 -4
- package/dist/types/sdk/bus/telegram-daemon.d.ts +46 -3
- package/dist/types/sdk/bus/threaded-inbound.d.ts +1 -1
- package/dist/types/sdk/bus/threaded-render.d.ts +13 -0
- package/dist/types/sdk/bus/topic-registry.d.ts +24 -2
- package/dist/types/sdk/host/control/operations.d.ts +1 -1
- package/dist/types/sdk/host/host.d.ts +2 -0
- package/dist/types/sdk/index.d.ts +1 -0
- package/dist/types/sdk/session-directory.d.ts +56 -0
- package/dist/types/sdk/session.d.ts +2 -0
- package/dist/types/session/agent-session.d.ts +82 -47
- package/dist/types/session/agent-storage.d.ts +7 -0
- package/dist/types/session/fallback-chain-controller.d.ts +10 -2
- package/dist/types/session/internal/managed-session-scope.d.ts +102 -0
- package/dist/types/session/internal/managed-session-storage.d.ts +38 -0
- package/dist/types/session/messages.d.ts +16 -0
- package/dist/types/session/session-manager-internal.d.ts +14 -0
- package/dist/types/session/session-manager.d.ts +82 -12
- package/dist/types/session/session-storage.d.ts +43 -3
- package/dist/types/session/volatile-context-pruning.d.ts +15 -0
- package/dist/types/skill-state/{deep-interview-mutation-guard.d.ts → workflow-mutation-guard.d.ts} +24 -8
- package/dist/types/skill-state/workflow-state-contract.d.ts +1 -3
- package/dist/types/slash-commands/builtin-registry.d.ts +4 -1
- package/dist/types/system-prompt.d.ts +2 -11
- package/dist/types/task/executor.d.ts +3 -1
- package/dist/types/thinking.d.ts +7 -0
- package/dist/types/tool-discovery/tool-index.d.ts +1 -50
- package/dist/types/tools/ask.d.ts +64 -2
- package/dist/types/tools/bash.d.ts +3 -0
- package/dist/types/tools/browser/dead-tab-recovery.d.ts +24 -0
- package/dist/types/tools/browser/tab-supervisor.d.ts +21 -0
- package/dist/types/tools/cron.d.ts +2 -0
- package/dist/types/tools/fetch.d.ts +1 -0
- package/dist/types/tools/index.d.ts +30 -15
- package/dist/types/tools/output-meta.d.ts +1 -0
- package/dist/types/tools/read.d.ts +5 -0
- package/dist/types/tools/search-tool-bm25.d.ts +3 -4
- package/dist/types/tools/subagent.d.ts +1 -0
- package/dist/types/utils/event-bus.d.ts +1 -1
- package/dist/types/utils/file-mentions.d.ts +3 -3
- package/dist/types/web/search/index.d.ts +3 -1
- package/package.json +21 -9
- package/scripts/build-sdk-package-smoke.ts +34 -1
- package/scripts/generate-hotkeys-docs.ts +74 -0
- package/scripts/generate-sdk-operation-inventory.ts +64 -20
- package/scripts/verify-gjc-sdk-canonicalization.ts +182 -2
- package/src/async/job-manager.ts +49 -6
- package/src/cli/config-cli.ts +75 -2
- package/src/cli/launch-disposition.ts +42 -0
- package/src/cli/notify-cli.ts +92 -26
- package/src/cli/session-picker.ts +20 -3
- package/src/cli/setup-cli.ts +1 -1
- package/src/cli.ts +1 -1
- package/src/commands/config.ts +1 -1
- package/src/commands/harness.ts +34 -106
- package/src/commands/launch.ts +6 -4
- package/src/commands/mcp-serve.ts +85 -8
- package/src/commands/mcp.ts +2 -2
- package/src/commands/notify.ts +8 -4
- package/src/commands/sdk.ts +61 -40
- package/src/commands/ultragoal.ts +4 -1
- package/src/config/atomic-yaml-patch.ts +80 -13
- package/src/config/file-lock.ts +105 -43
- package/src/config/keybindings.ts +64 -20
- package/src/config/model-auth.ts +9 -0
- package/src/config/model-bindings-applier.ts +139 -0
- package/src/config/model-discovery-manager.ts +224 -0
- package/src/config/model-equivalence.ts +66 -0
- package/src/config/model-registry.ts +169 -302
- package/src/config/model-resolver.ts +361 -369
- package/src/config/models-config-schema.ts +5 -4
- package/src/config/settings-schema.ts +214 -12
- package/src/config/settings.ts +458 -482
- package/src/coordinator-mcp/policy.ts +76 -11
- package/src/coordinator-mcp/question-gate-codec.ts +274 -0
- package/src/coordinator-mcp/question-state.ts +778 -0
- package/src/coordinator-mcp/server.ts +1702 -238
- package/src/debug/index.ts +1 -1
- package/src/defaults/gjc/skills/deep-interview/SKILL.md +13 -1
- package/src/defaults/gjc/skills/team/SKILL.md +16 -0
- package/src/discovery/helpers.ts +1 -50
- package/src/edit/index.ts +64 -0
- package/src/eval/py/env.ts +26 -0
- package/src/eval/py/kernel.ts +5 -3
- package/src/extensibility/extensions/loader.ts +9 -1
- package/src/extensibility/extensions/runner.ts +12 -3
- package/src/extensibility/extensions/types.ts +39 -1
- package/src/extensibility/gjc-plugins/installer.ts +16 -16
- package/src/extensibility/hooks/runner.ts +2 -2
- package/src/extensibility/runtime-skill-discovery.ts +33 -13
- package/src/extensibility/shared-events.ts +2 -0
- package/src/gjc-runtime/deep-interview-recorder.ts +63 -3
- package/src/gjc-runtime/deep-interview-runtime.ts +76 -27
- package/src/gjc-runtime/deep-interview-state.ts +317 -5
- package/src/gjc-runtime/goal-mode-request.ts +55 -8
- package/src/gjc-runtime/launch-tmux.ts +2 -5
- package/src/gjc-runtime/launch-worktree.ts +5 -5
- package/src/gjc-runtime/linux-proc.ts +71 -0
- package/src/gjc-runtime/ralplan-runtime.ts +74 -90
- package/src/gjc-runtime/session-resolution.ts +18 -3
- package/src/gjc-runtime/session-state-sidecar.ts +6 -107
- package/src/gjc-runtime/state-migrations.ts +1 -1
- package/src/gjc-runtime/state-runtime.ts +327 -249
- package/src/gjc-runtime/state-writer.ts +36 -40
- package/src/gjc-runtime/team-launch.ts +319 -0
- package/src/gjc-runtime/team-notify.ts +326 -0
- package/src/gjc-runtime/team-runtime.ts +1099 -1482
- package/src/gjc-runtime/team-store.ts +828 -0
- package/src/gjc-runtime/team-workers.ts +962 -0
- package/src/gjc-runtime/tmux-owner-isolation-cli.ts +2 -11
- package/src/gjc-runtime/tmux-owner-isolation.ts +14 -9
- package/src/gjc-runtime/tmux-sessions.ts +4 -21
- package/src/gjc-runtime/ultragoal-change-set.ts +172 -0
- package/src/gjc-runtime/ultragoal-evidence.ts +874 -0
- package/src/gjc-runtime/ultragoal-guard.ts +29 -5
- package/src/gjc-runtime/ultragoal-pipeline.ts +306 -0
- package/src/gjc-runtime/ultragoal-runtime.ts +84 -1311
- package/src/gjc-runtime/workflow-cli-common.ts +30 -0
- package/src/gjc-runtime/workflow-manifest.generated.json +58 -0
- package/src/gjc-runtime/workflow-manifest.ts +18 -0
- package/src/goals/continuation-timeout-guard.ts +79 -0
- package/src/goals/runtime.ts +7 -5
- package/src/goals/state.ts +18 -0
- package/src/harness-control-plane/lifecycle-reconciliation.ts +64 -0
- package/src/harness-control-plane/phase-rollup.ts +4 -7
- package/src/harness-control-plane/receipt-ingest.ts +5 -0
- package/src/harness-control-plane/receipt-spool.ts +51 -7
- package/src/harness-control-plane/session-lease.ts +12 -130
- package/src/hindsight/backend.ts +26 -27
- package/src/hindsight/state.ts +101 -32
- package/src/hooks/skill-state.ts +17 -11
- package/src/internal-urls/docs-index.generated.ts +21 -18
- package/src/lsp/client.ts +1 -1
- package/src/lsp/config.ts +145 -26
- package/src/lsp/index.ts +1 -1
- package/src/lsp/lspmux.ts +39 -10
- package/src/lsp/path-trust.ts +81 -0
- package/src/main.ts +127 -30
- package/src/memories/index.ts +1 -0
- package/src/memories/storage.ts +6 -2
- package/src/modes/action-registry.ts +165 -0
- package/src/modes/components/chrome.ts +40 -0
- package/src/modes/components/command-palette.ts +168 -0
- package/src/modes/components/custom-editor.ts +1 -1
- package/src/modes/components/custom-provider-wizard.ts +51 -14
- package/src/modes/components/index.ts +2 -1
- package/src/modes/components/pet-selector.ts +11 -17
- package/src/modes/components/plan-preview-overlay.ts +295 -0
- package/src/modes/components/queue-mode-selector.ts +10 -27
- package/src/modes/components/queue-pane.ts +79 -0
- package/src/modes/components/read-tool-group.ts +13 -0
- package/src/modes/components/session-observer-overlay.ts +207 -772
- package/src/modes/components/sessions-dashboard.ts +181 -0
- package/src/modes/components/settings-selector.ts +1 -1
- package/src/modes/components/show-images-selector.ts +10 -24
- package/src/modes/components/status-line/types.ts +1 -1
- package/src/modes/components/status-line.ts +1 -969
- package/src/modes/components/tasks-pane.ts +73 -0
- package/src/modes/components/theme-selector.ts +11 -31
- package/src/modes/components/tool-execution.ts +22 -0
- package/src/modes/components/tool-status-header.ts +1056 -0
- package/src/modes/components/transcript-viewer-overlay.ts +384 -0
- package/src/modes/controllers/btw-controller.ts +1 -0
- package/src/modes/controllers/event-controller.ts +3 -2
- package/src/modes/controllers/extension-ui-controller.ts +24 -1
- package/src/modes/controllers/goal-mode-controller.ts +474 -0
- package/src/modes/controllers/input-controller.ts +764 -229
- package/src/modes/controllers/mode-gate.ts +24 -0
- package/src/modes/controllers/plan-mode-controller.ts +517 -0
- package/src/modes/controllers/selector-controller.ts +225 -10
- package/src/modes/controllers/stt-controller.ts +125 -0
- package/src/modes/interactive-mode.ts +289 -1150
- package/src/modes/jobs-observer.ts +3 -0
- package/src/modes/prompt-action-autocomplete.ts +7 -0
- package/src/modes/runtime-init.ts +8 -0
- package/src/modes/shared/agent-wire/deep-interview-gate.ts +31 -106
- package/src/modes/shared/agent-wire/workflow-gate-broker.ts +71 -16
- package/src/modes/shared/agent-wire/workflow-gate-types.ts +177 -0
- package/src/modes/tasks-aggregator.ts +199 -0
- package/src/modes/transcript-item-registry.ts +229 -0
- package/src/modes/types.ts +45 -18
- package/src/modes/utils/ui-helpers.ts +17 -9
- package/src/prompts/agent-fragments/ralplan-persistence.md +6 -0
- package/src/prompts/agent-fragments/restricted-bash.md +1 -0
- package/src/prompts/agents/architect.md +2 -8
- package/src/prompts/agents/critic.md +2 -8
- package/src/prompts/agents/executor.md +3 -0
- package/src/prompts/agents/planner.md +4 -12
- package/src/prompts/system/custom-system-prompt.md +1 -23
- package/src/prompts/system/plan-mode-approved.md +8 -0
- package/src/prompts/system/system-prompt.md +17 -96
- package/src/prompts/tools/bash.md +4 -4
- package/src/prompts/tools/browser.md +15 -52
- package/src/prompts/tools/find.md +2 -2
- package/src/prompts/tools/hashline.md +13 -55
- package/src/prompts/tools/read.md +3 -6
- package/src/prompts/tools/search-tool-bm25.md +0 -2
- package/src/prompts/tools/search.md +2 -4
- package/src/prompts/tools/skill-discovery.md +1 -2
- package/src/prompts/tools/task.md +1 -1
- package/src/runtime-mcp/manager.ts +1 -1
- package/src/sdk/broker/broker.ts +206 -78
- package/src/sdk/broker/discovery.ts +1 -1
- package/src/sdk/broker/ensure.ts +3 -1
- package/src/sdk/broker/lifecycle-codec.ts +11 -0
- package/src/sdk/broker/lifecycle-ledger.ts +371 -74
- package/src/sdk/broker/lifecycle.ts +1399 -142
- package/src/sdk/broker/process-incarnation.ts +5 -13
- package/src/sdk/broker/session-index.ts +145 -56
- package/src/sdk/broker/state-version.ts +21 -0
- package/src/sdk/broker/transport.ts +1 -1
- package/src/sdk/bus/chat-daemon-cli.ts +2 -0
- package/src/sdk/bus/chat-daemon-control.ts +8 -28
- package/src/sdk/bus/chat-effect-journal.ts +10 -2
- package/src/sdk/bus/config-commands.ts +5 -4
- package/src/sdk/bus/config.ts +98 -0
- package/src/sdk/bus/conversation-store.ts +5 -29
- package/src/sdk/bus/daemon-paths.ts +2 -0
- package/src/sdk/bus/html-format.ts +20 -3
- package/src/sdk/bus/index.ts +782 -94
- package/src/sdk/bus/lifecycle-control-runtime.ts +91 -33
- package/src/sdk/bus/natives-augment.d.ts +26 -1
- package/src/sdk/bus/notification-service.ts +168 -20
- package/src/sdk/bus/rate-limit-pool.ts +58 -14
- package/src/sdk/bus/recent-activity.ts +188 -74
- package/src/sdk/bus/rich-document.ts +258 -0
- package/src/sdk/bus/rich-render.ts +62 -70
- package/src/sdk/bus/telegram-daemon-cli.ts +15 -59
- package/src/sdk/bus/telegram-daemon-contract.ts +9 -4
- package/src/sdk/bus/telegram-daemon.ts +1389 -237
- package/src/sdk/bus/threaded-inbound.ts +8 -3
- package/src/sdk/bus/threaded-render.ts +57 -1
- package/src/sdk/bus/topic-registry.ts +120 -13
- package/src/sdk/host/control/dispatch.ts +14 -2
- package/src/sdk/host/control/operations.ts +6 -1
- package/src/sdk/host/host.ts +44 -2
- package/src/sdk/host/query/handlers.ts +20 -22
- package/src/sdk/host/query/revision-store.ts +80 -57
- package/src/sdk/index.ts +1 -0
- package/src/sdk/protocol/operation-inventory.generated.json +943 -1907
- package/src/sdk/session-directory.ts +141 -0
- package/src/sdk/session.ts +462 -480
- package/src/session/agent-session.ts +1700 -583
- package/src/session/agent-storage.ts +18 -0
- package/src/session/cache-economics.ts +25 -8
- package/src/session/fallback-chain-controller.ts +53 -3
- package/src/session/internal/managed-session-scope.ts +2226 -0
- package/src/session/internal/managed-session-storage.ts +453 -0
- package/src/session/messages.ts +91 -2
- package/src/session/session-manager-internal.ts +33 -0
- package/src/session/session-manager.ts +1112 -333
- package/src/session/session-storage.ts +444 -39
- package/src/session/volatile-context-pruning.ts +78 -0
- package/src/setup/credential-auto-import.ts +2 -1
- package/src/setup/hermes/templates/operator-instructions.v1.md +1 -1
- package/src/setup/provider-onboarding.ts +36 -61
- package/src/setup/provider-presets.json +5 -0
- package/src/skill-state/active-state.ts +3 -13
- package/src/skill-state/{deep-interview-mutation-guard.ts → workflow-mutation-guard.ts} +47 -29
- package/src/skill-state/workflow-state-contract.ts +6 -41
- package/src/slash-commands/builtin-registry.ts +46 -11
- package/src/system-prompt.ts +37 -44
- package/src/task/agents.ts +19 -1
- package/src/task/executor.ts +90 -6
- package/src/task/index.ts +36 -21
- package/src/thinking.ts +21 -6
- package/src/tool-discovery/tool-index.ts +2 -134
- package/src/tools/ask.ts +157 -21
- package/src/tools/ast-edit.ts +1 -1
- package/src/tools/bash.ts +38 -0
- package/src/tools/browser/dead-tab-recovery.ts +78 -0
- package/src/tools/browser/tab-supervisor.ts +282 -36
- package/src/tools/computer.ts +10 -3
- package/src/tools/cron.ts +30 -16
- package/src/tools/eval.ts +1 -2
- package/src/tools/fetch.ts +11 -4
- package/src/tools/index.ts +76 -24
- package/src/tools/output-meta.ts +19 -7
- package/src/tools/read.ts +219 -64
- package/src/tools/resource-gc.ts +2 -2
- package/src/tools/search-tool-bm25.ts +11 -74
- package/src/tools/subagent.ts +43 -2
- package/src/utils/event-bus.ts +9 -4
- package/src/utils/file-mentions.ts +4 -4
- package/src/web/search/index.ts +3 -3
- package/dist/types/discovery/plugin-dir-roots.d.ts +0 -15
- package/dist/types/runtime-mcp/discoverable-tool-metadata.d.ts +0 -7
- package/src/discovery/plugin-dir-roots.ts +0 -28
- package/src/runtime-mcp/discoverable-tool-metadata.ts +0 -25
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type ExclusiveMode = "goal" | "plan";
|
|
2
|
+
|
|
3
|
+
/** Owns the mutual-exclusion state for interactive goal and plan modes. */
|
|
4
|
+
export class ModeGate {
|
|
5
|
+
#activeMode: ExclusiveMode | undefined;
|
|
6
|
+
|
|
7
|
+
get activeMode(): ExclusiveMode | undefined {
|
|
8
|
+
return this.#activeMode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
enter(mode: ExclusiveMode): boolean {
|
|
12
|
+
if (this.#activeMode && this.#activeMode !== mode) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
this.#activeMode = mode;
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exit(mode: ExclusiveMode): void {
|
|
20
|
+
if (this.#activeMode === mode) {
|
|
21
|
+
this.#activeMode = undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import type { AgentToolResult, ThinkingLevel } from "@gajae-code/agent-core";
|
|
4
|
+
import type { CompactionOutcome } from "@gajae-code/agent-core/compaction";
|
|
5
|
+
import { type Model, modelsAreEqual } from "@gajae-code/ai";
|
|
6
|
+
import { Container, type KeyId, Markdown, Spacer, Text } from "@gajae-code/tui";
|
|
7
|
+
import { isEnoent, prompt } from "@gajae-code/utils";
|
|
8
|
+
import { resolveLocalUrlToPath } from "../../internal-urls";
|
|
9
|
+
import { humanizePlanTitle, type PlanApprovalDetails, resolvePlanTitle } from "../../plan-mode/approved-plan";
|
|
10
|
+
import planModeApprovedPrompt from "../../prompts/system/plan-mode-approved.md" with { type: "text" };
|
|
11
|
+
import planModeCompactInstructionsPrompt from "../../prompts/system/plan-mode-compact-instructions.md" with {
|
|
12
|
+
type: "text",
|
|
13
|
+
};
|
|
14
|
+
import type { AgentSession, TemporaryProviderSessionScope } from "../../session/agent-session";
|
|
15
|
+
import type { SessionContext, SessionManager } from "../../session/session-manager";
|
|
16
|
+
import { normalizeLocalScheme } from "../../tools/path-utils";
|
|
17
|
+
import { type ResolveToolDetails, runResolveInvocation } from "../../tools/resolve";
|
|
18
|
+
import { ToolError } from "../../tools/tool-errors";
|
|
19
|
+
import { getEditorCommand, openInEditor } from "../../utils/external-editor";
|
|
20
|
+
import { setSessionTerminalTitle } from "../../utils/title-generator";
|
|
21
|
+
import { DynamicBorder } from "../components/dynamic-border";
|
|
22
|
+
import {
|
|
23
|
+
type PlanPreviewOptions,
|
|
24
|
+
type PlanPreviewResult,
|
|
25
|
+
planSnapshotHash,
|
|
26
|
+
serializePlanReviewComments,
|
|
27
|
+
} from "../components/plan-preview-overlay";
|
|
28
|
+
import { getMarkdownTheme, theme } from "../theme/theme";
|
|
29
|
+
import type { SubmittedUserInput } from "../types";
|
|
30
|
+
import { INTERACTIVE_ABORT_CLEANUP_TIMEOUT_MS } from "./input-controller";
|
|
31
|
+
import type { ModeGate } from "./mode-gate";
|
|
32
|
+
|
|
33
|
+
const ABORT_TIMEOUT_MS = INTERACTIVE_ABORT_CLEANUP_TIMEOUT_MS;
|
|
34
|
+
|
|
35
|
+
type PlanModeControllerContext = {
|
|
36
|
+
readonly session: AgentSession;
|
|
37
|
+
readonly sessionManager: SessionManager;
|
|
38
|
+
readonly modeGate: ModeGate;
|
|
39
|
+
readonly chatContainer: Container;
|
|
40
|
+
readonly inputCallback: ((input: SubmittedUserInput) => void) | undefined;
|
|
41
|
+
readonly externalEditorKey: string | undefined;
|
|
42
|
+
readonly externalEditorKeys: readonly KeyId[];
|
|
43
|
+
startPendingSubmission(input: { text: string }): SubmittedUserInput;
|
|
44
|
+
addChatChild(child: Container): void;
|
|
45
|
+
requestRender(full?: boolean): void;
|
|
46
|
+
stopUi(): void;
|
|
47
|
+
startUi(): void;
|
|
48
|
+
showStatus(message: string): void;
|
|
49
|
+
showWarning(message: string): void;
|
|
50
|
+
showError(message: string): void;
|
|
51
|
+
showHookConfirm(title: string, message: string): Promise<boolean>;
|
|
52
|
+
showPlanPreview(content: string | null, options?: PlanPreviewOptions): Promise<PlanPreviewResult>;
|
|
53
|
+
flushCompactionQueue(options?: { willRetry?: boolean }): Promise<void>;
|
|
54
|
+
updatePlanModeStatus(status: { enabled: boolean; paused: boolean } | undefined): void;
|
|
55
|
+
handleClearCommand(): Promise<boolean>;
|
|
56
|
+
handleCompactCommand(instructions?: string): Promise<CompactionOutcome>;
|
|
57
|
+
updateEditorChrome(): void;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** Owns plan-mode state, model scope, plan review, approval, and restoration. */
|
|
61
|
+
export class PlanModeController {
|
|
62
|
+
#enabled = false;
|
|
63
|
+
#paused = false;
|
|
64
|
+
#planFilePath: string | undefined;
|
|
65
|
+
#previousTools: string[] | undefined;
|
|
66
|
+
#previousModelState: { model: Model; thinkingLevel?: ThinkingLevel } | undefined;
|
|
67
|
+
#pendingModelSwitch: { model: Model; thinkingLevel?: ThinkingLevel } | undefined;
|
|
68
|
+
#providerSessionScope: TemporaryProviderSessionScope | undefined;
|
|
69
|
+
#hasEntered = false;
|
|
70
|
+
#reviewContainer: Container | undefined;
|
|
71
|
+
#planApprovalDispatchPending = false;
|
|
72
|
+
|
|
73
|
+
constructor(private readonly ctx: PlanModeControllerContext) {}
|
|
74
|
+
get enabled(): boolean {
|
|
75
|
+
return this.#enabled;
|
|
76
|
+
}
|
|
77
|
+
get paused(): boolean {
|
|
78
|
+
return this.#paused;
|
|
79
|
+
}
|
|
80
|
+
get planFilePath(): string | undefined {
|
|
81
|
+
return this.#planFilePath;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
setEnabledForCompatibility(enabled: boolean): void {
|
|
85
|
+
this.#enabled = enabled;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
setPausedForCompatibility(paused: boolean): void {
|
|
89
|
+
this.#paused = paused;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
setPlanFilePathForCompatibility(planFilePath: string | undefined): void {
|
|
93
|
+
this.#planFilePath = planFilePath;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
clearReview(): void {
|
|
97
|
+
this.#reviewContainer = undefined;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async restoreFromSession(sessionContext: SessionContext): Promise<void> {
|
|
101
|
+
if (!this.ctx.session.settings.get("plan.enabled")) {
|
|
102
|
+
if (sessionContext.mode === "plan" || sessionContext.mode === "plan_paused")
|
|
103
|
+
this.ctx.sessionManager.appendModeChange("none");
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (sessionContext.mode === "plan") {
|
|
107
|
+
await this.enter({ planFilePath: sessionContext.modeData?.planFilePath as string | undefined });
|
|
108
|
+
} else if (sessionContext.mode === "plan_paused") {
|
|
109
|
+
this.#paused = true;
|
|
110
|
+
this.#hasEntered = true;
|
|
111
|
+
this.ctx.modeGate.enter("plan");
|
|
112
|
+
this.#updateStatus();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async enter(options?: { planFilePath?: string; workflow?: "parallel" | "iterative" }): Promise<void> {
|
|
117
|
+
if (this.#enabled) return;
|
|
118
|
+
if (!this.ctx.modeGate.enter("plan")) return this.ctx.showWarning("Exit goal mode first.");
|
|
119
|
+
this.#paused = false;
|
|
120
|
+
const planFilePath = options?.planFilePath ?? "local://PLAN.md";
|
|
121
|
+
const previousTools = this.ctx.session.getActiveToolNames();
|
|
122
|
+
this.#previousTools = previousTools;
|
|
123
|
+
this.#planFilePath = planFilePath;
|
|
124
|
+
this.#enabled = true;
|
|
125
|
+
await this.ctx.session.setActiveToolsByName(
|
|
126
|
+
this.ctx.session.getToolByName("resolve") ? [...new Set([...previousTools, "resolve"])] : previousTools,
|
|
127
|
+
);
|
|
128
|
+
this.ctx.session.setPlanModeState({
|
|
129
|
+
enabled: true,
|
|
130
|
+
planFilePath,
|
|
131
|
+
workflow: options?.workflow ?? "parallel",
|
|
132
|
+
reentry: this.#hasEntered,
|
|
133
|
+
});
|
|
134
|
+
this.ctx.session.setStandingResolveHandler?.(input => this.#runApprovalResolve(input));
|
|
135
|
+
if (this.ctx.session.isStreaming) await this.ctx.session.sendPlanModeContext({ deliverAs: "steer" });
|
|
136
|
+
this.#hasEntered = true;
|
|
137
|
+
await this.#applyModel();
|
|
138
|
+
this.#updateStatus();
|
|
139
|
+
this.ctx.sessionManager.appendModeChange("plan", { planFilePath });
|
|
140
|
+
this.ctx.showStatus(`Plan mode enabled. Plan file: ${planFilePath}`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async exit(options?: { silent?: boolean; paused?: boolean }): Promise<void> {
|
|
144
|
+
if (!this.#enabled) return;
|
|
145
|
+
await this.ctx.session.abort({ timeoutMs: ABORT_TIMEOUT_MS });
|
|
146
|
+
if (this.#previousTools?.length) await this.ctx.session.setActiveToolsByName(this.#previousTools);
|
|
147
|
+
if (this.#providerSessionScope && !this.ctx.session.isStreaming) {
|
|
148
|
+
if (this.ctx.session.restoreTemporaryProviderSessionScope(this.#providerSessionScope))
|
|
149
|
+
this.#providerSessionScope = undefined;
|
|
150
|
+
} else if (this.#previousModelState) {
|
|
151
|
+
const previous = this.#previousModelState;
|
|
152
|
+
if (modelsAreEqual(this.ctx.session.model, previous.model))
|
|
153
|
+
this.ctx.session.setThinkingLevel(previous.thinkingLevel);
|
|
154
|
+
else if (this.ctx.session.isStreaming) this.#pendingModelSwitch = previous;
|
|
155
|
+
else
|
|
156
|
+
await this.ctx.session.setModelTemporary(previous.model, previous.thinkingLevel, {
|
|
157
|
+
cause: "restore",
|
|
158
|
+
reason: "plan-mode",
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
const pending = this.#pendingModelSwitch;
|
|
162
|
+
const planModel = this.ctx.session.resolveRoleModelWithThinking("plan").model;
|
|
163
|
+
if (pending && planModel && modelsAreEqual(pending.model, planModel)) this.#pendingModelSwitch = undefined;
|
|
164
|
+
this.ctx.session.setStandingResolveHandler?.(null);
|
|
165
|
+
this.ctx.session.setPlanModeState(undefined);
|
|
166
|
+
this.#enabled = false;
|
|
167
|
+
this.#paused = options?.paused ?? false;
|
|
168
|
+
this.#planFilePath = undefined;
|
|
169
|
+
this.#previousTools = undefined;
|
|
170
|
+
this.#previousModelState = undefined;
|
|
171
|
+
if (!this.#paused) this.ctx.modeGate.exit("plan");
|
|
172
|
+
this.#updateStatus();
|
|
173
|
+
this.ctx.sessionManager.appendModeChange(this.#paused ? "plan_paused" : "none");
|
|
174
|
+
if (!options?.silent) this.ctx.showStatus(this.#paused ? "Plan mode paused." : "Plan mode disabled.");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async flushPendingModelSwitch(): Promise<void> {
|
|
178
|
+
const pending = this.#pendingModelSwitch;
|
|
179
|
+
if (!pending) return;
|
|
180
|
+
this.#pendingModelSwitch = undefined;
|
|
181
|
+
try {
|
|
182
|
+
this.#providerSessionScope ??= this.ctx.session.beginTemporaryProviderSessionScope("plan-mode");
|
|
183
|
+
await this.ctx.session.setModelTemporary(pending.model, pending.thinkingLevel, {
|
|
184
|
+
cause: "temporary-operation",
|
|
185
|
+
reason: "plan-mode",
|
|
186
|
+
providerSessionScope: this.#providerSessionScope,
|
|
187
|
+
});
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (this.#providerSessionScope)
|
|
190
|
+
this.ctx.session.restoreTemporaryProviderSessionScope(this.#providerSessionScope);
|
|
191
|
+
this.#providerSessionScope = undefined;
|
|
192
|
+
this.ctx.showWarning(
|
|
193
|
+
`Failed to switch model after streaming: ${error instanceof Error ? error.message : String(error)}`,
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async handleCommand(initialPrompt?: string): Promise<void> {
|
|
199
|
+
if (this.#enabled) {
|
|
200
|
+
if (await this.ctx.showHookConfirm("Exit plan mode?", "This exits plan mode without approving a plan."))
|
|
201
|
+
await this.exit({ paused: true });
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (!this.ctx.session.settings.get("plan.enabled"))
|
|
205
|
+
return this.ctx.showWarning("Plan mode is disabled. Enable it in settings (plan.enabled).");
|
|
206
|
+
await this.enter();
|
|
207
|
+
if (initialPrompt && this.ctx.inputCallback)
|
|
208
|
+
this.ctx.inputCallback(this.ctx.startPendingSubmission({ text: initialPrompt }));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async handleApproval(details: PlanApprovalDetails): Promise<void> {
|
|
212
|
+
if (!this.#enabled) return this.ctx.showWarning("Plan mode is not active.");
|
|
213
|
+
await this.ctx.session.abort({ timeoutMs: ABORT_TIMEOUT_MS });
|
|
214
|
+
const planFilePath = details.planFilePath || this.#planFilePath || "local://PLAN.md";
|
|
215
|
+
this.#planFilePath = planFilePath;
|
|
216
|
+
const review = await this.ctx.showPlanPreview(await this.#readFile(planFilePath), {
|
|
217
|
+
externalEditorKey: this.ctx.externalEditorKey,
|
|
218
|
+
externalEditorKeys: this.ctx.externalEditorKeys,
|
|
219
|
+
onExternalEditor: () => this.#openEditor(planFilePath),
|
|
220
|
+
});
|
|
221
|
+
if (!review.action) return;
|
|
222
|
+
|
|
223
|
+
const latestPlanContent = await this.#readFile(planFilePath);
|
|
224
|
+
if (review.snapshotHash !== planSnapshotHash(latestPlanContent ?? "")) {
|
|
225
|
+
this.ctx.showWarning(
|
|
226
|
+
"Plan changed while reviewing; comments and notes were discarded. Confirm the decision again.",
|
|
227
|
+
);
|
|
228
|
+
return this.handleApproval(details);
|
|
229
|
+
}
|
|
230
|
+
const commentBlock = serializePlanReviewComments(
|
|
231
|
+
latestPlanContent ?? "",
|
|
232
|
+
review.snapshotHash,
|
|
233
|
+
review.comments,
|
|
234
|
+
review.notes,
|
|
235
|
+
);
|
|
236
|
+
this.#renderPreview(
|
|
237
|
+
`## Plan approval audit\n\nDecision: ${review.action}\n\nPath: \`${planFilePath}\`\n\nSnapshot SHA-256: \`${review.snapshotHash}\`\n\n${latestPlanContent ?? "*(missing plan.md)*"}${commentBlock ? `\n\n${commentBlock}` : ""}`,
|
|
238
|
+
true,
|
|
239
|
+
);
|
|
240
|
+
if (review.action === "Refine plan") {
|
|
241
|
+
if (commentBlock)
|
|
242
|
+
await this.ctx.session.prompt(`${commentBlock}\n\nPlease refine the plan using these review comments.`);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (!latestPlanContent) return this.ctx.showError(`Plan file not found at ${planFilePath}`);
|
|
246
|
+
try {
|
|
247
|
+
await this.#approve(latestPlanContent, {
|
|
248
|
+
planFilePath,
|
|
249
|
+
finalPlanFilePath: details.finalPlanFilePath || planFilePath,
|
|
250
|
+
title: details.title,
|
|
251
|
+
preserveContext: review.action !== "Approve and execute",
|
|
252
|
+
compactBeforeExecute: review.action === "Approve and compact context",
|
|
253
|
+
reviewerComments: commentBlock,
|
|
254
|
+
});
|
|
255
|
+
} catch (error) {
|
|
256
|
+
this.ctx.showError(
|
|
257
|
+
`Failed to finalize approved plan: ${error instanceof Error ? error.message : String(error)}`,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async #applyModel(): Promise<void> {
|
|
263
|
+
const resolved = this.ctx.session.resolveRoleModelWithThinking("plan");
|
|
264
|
+
if (!resolved.model) return;
|
|
265
|
+
const current = this.ctx.session.model;
|
|
266
|
+
const thinkingLevel = resolved.explicitThinkingLevel ? resolved.thinkingLevel : undefined;
|
|
267
|
+
this.#previousModelState = current
|
|
268
|
+
? { model: current, thinkingLevel: this.ctx.session.thinkingLevel }
|
|
269
|
+
: undefined;
|
|
270
|
+
if (modelsAreEqual(current, resolved.model)) {
|
|
271
|
+
if (thinkingLevel) this.ctx.session.setThinkingLevel(thinkingLevel);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (this.ctx.session.isStreaming) {
|
|
275
|
+
this.#pendingModelSwitch = { model: resolved.model, thinkingLevel };
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
try {
|
|
279
|
+
this.#providerSessionScope = this.ctx.session.beginTemporaryProviderSessionScope("plan-mode");
|
|
280
|
+
await this.ctx.session.setModelTemporary(resolved.model, thinkingLevel, {
|
|
281
|
+
cause: "temporary-operation",
|
|
282
|
+
reason: "plan-mode",
|
|
283
|
+
providerSessionScope: this.#providerSessionScope,
|
|
284
|
+
});
|
|
285
|
+
} catch (error) {
|
|
286
|
+
if (this.#providerSessionScope)
|
|
287
|
+
this.ctx.session.restoreTemporaryProviderSessionScope(this.#providerSessionScope);
|
|
288
|
+
this.#providerSessionScope = undefined;
|
|
289
|
+
this.ctx.showWarning(
|
|
290
|
+
`Failed to switch to plan model for plan mode: ${error instanceof Error ? error.message : String(error)}`,
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
#runApprovalResolve(input: unknown): Promise<AgentToolResult<ResolveToolDetails>> {
|
|
296
|
+
return runResolveInvocation(input as Parameters<typeof runResolveInvocation>[0], {
|
|
297
|
+
sourceToolName: "plan_approval",
|
|
298
|
+
label: "Plan ready for approval",
|
|
299
|
+
apply: async (_reason, extra) => {
|
|
300
|
+
const state = this.ctx.session.getPlanModeState?.();
|
|
301
|
+
if (!state?.enabled) throw new ToolError("Plan mode is not active.");
|
|
302
|
+
const planContent = await this.#readFile(state.planFilePath);
|
|
303
|
+
if (planContent === null)
|
|
304
|
+
throw new ToolError(
|
|
305
|
+
`Plan file not found at ${state.planFilePath}. Write the finalized plan to ${state.planFilePath} before requesting approval.`,
|
|
306
|
+
);
|
|
307
|
+
const normalized = resolvePlanTitle({
|
|
308
|
+
suppliedTitle: extra?.title,
|
|
309
|
+
planContent,
|
|
310
|
+
planFilePath: state.planFilePath,
|
|
311
|
+
});
|
|
312
|
+
return {
|
|
313
|
+
content: [{ type: "text", text: "Plan ready for approval." }],
|
|
314
|
+
details: {
|
|
315
|
+
planFilePath: state.planFilePath,
|
|
316
|
+
finalPlanFilePath: `local://${normalized.fileName}`,
|
|
317
|
+
title: normalized.title,
|
|
318
|
+
planExists: true,
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
async #readFile(planFilePath: string): Promise<string | null> {
|
|
326
|
+
try {
|
|
327
|
+
return await Bun.file(this.#resolvePath(planFilePath)).text();
|
|
328
|
+
} catch (error) {
|
|
329
|
+
if (isEnoent(error)) return null;
|
|
330
|
+
throw error;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
#resolvePath(planFilePath: string): string {
|
|
334
|
+
return planFilePath.startsWith("local:")
|
|
335
|
+
? resolveLocalUrlToPath(normalizeLocalScheme(planFilePath), {
|
|
336
|
+
getArtifactsDir: () => this.ctx.sessionManager.getArtifactsDir(),
|
|
337
|
+
getSessionId: () => this.ctx.sessionManager.getSessionId(),
|
|
338
|
+
})
|
|
339
|
+
: path.resolve(this.ctx.sessionManager.getCwd(), planFilePath);
|
|
340
|
+
}
|
|
341
|
+
async #finalizeApprovedPlan(planContent: string, planFilePath: string, finalPlanFilePath: string): Promise<void> {
|
|
342
|
+
if (!planFilePath.startsWith("local:") || !finalPlanFilePath.startsWith("local:"))
|
|
343
|
+
throw new Error("Approved plan source and destination paths must use the local: scheme.");
|
|
344
|
+
const sourcePath = this.#resolvePath(planFilePath);
|
|
345
|
+
const destinationPath = this.#resolvePath(finalPlanFilePath);
|
|
346
|
+
const temporaryPath = `${destinationPath}.approval-${crypto.randomUUID()}`;
|
|
347
|
+
try {
|
|
348
|
+
await fs.writeFile(temporaryPath, planContent, { encoding: "utf8", flag: "wx" });
|
|
349
|
+
if (sourcePath === destinationPath) await fs.rename(temporaryPath, destinationPath);
|
|
350
|
+
else {
|
|
351
|
+
try {
|
|
352
|
+
await fs.link(temporaryPath, destinationPath);
|
|
353
|
+
} catch (error) {
|
|
354
|
+
if ((error as NodeJS.ErrnoException).code === "EEXIST")
|
|
355
|
+
throw new Error(
|
|
356
|
+
`Plan destination already exists at ${finalPlanFilePath}. Choose a different title and submit the plan for approval again.`,
|
|
357
|
+
);
|
|
358
|
+
throw error;
|
|
359
|
+
}
|
|
360
|
+
await fs.unlink(temporaryPath);
|
|
361
|
+
await fs.unlink(sourcePath);
|
|
362
|
+
}
|
|
363
|
+
if (planSnapshotHash(await Bun.file(destinationPath).text()) !== planSnapshotHash(planContent))
|
|
364
|
+
throw new Error(
|
|
365
|
+
`Approved plan destination hash did not match the reviewed snapshot at ${finalPlanFilePath}.`,
|
|
366
|
+
);
|
|
367
|
+
} finally {
|
|
368
|
+
await fs.unlink(temporaryPath).catch(() => {});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
#renderPreview(content: string, append = false): void {
|
|
372
|
+
const attached = this.#reviewContainer && this.ctx.chatContainer.children.includes(this.#reviewContainer);
|
|
373
|
+
const container = !append && attached ? this.#reviewContainer! : new Container();
|
|
374
|
+
container.clear();
|
|
375
|
+
container.addChild(new Spacer(1));
|
|
376
|
+
container.addChild(new DynamicBorder());
|
|
377
|
+
container.addChild(new Text(theme.bold(theme.fg("accent", "Plan Review")), 1, 1));
|
|
378
|
+
container.addChild(new Spacer(1));
|
|
379
|
+
container.addChild(new Markdown(content, 1, 1, getMarkdownTheme()));
|
|
380
|
+
container.addChild(new DynamicBorder());
|
|
381
|
+
if (container !== this.#reviewContainer || !attached) this.ctx.addChatChild(container);
|
|
382
|
+
this.#reviewContainer = container;
|
|
383
|
+
this.ctx.requestRender();
|
|
384
|
+
}
|
|
385
|
+
async #openEditor(planFilePath: string): Promise<string | null> {
|
|
386
|
+
const command = getEditorCommand();
|
|
387
|
+
if (!command) {
|
|
388
|
+
this.ctx.showWarning("No editor configured. Set $VISUAL or $EDITOR environment variable.");
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
const resolved = this.#resolvePath(planFilePath);
|
|
392
|
+
let text: string;
|
|
393
|
+
try {
|
|
394
|
+
text = await Bun.file(resolved).text();
|
|
395
|
+
} catch (error) {
|
|
396
|
+
if (isEnoent(error)) this.ctx.showError(`Plan file not found at ${planFilePath}`);
|
|
397
|
+
else this.ctx.showWarning(`Failed to open external editor: ${String(error)}`);
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
let tty: fs.FileHandle | null = null;
|
|
401
|
+
try {
|
|
402
|
+
if (process.platform !== "win32") {
|
|
403
|
+
try {
|
|
404
|
+
tty = await fs.open("/dev/tty", "r+");
|
|
405
|
+
} catch {}
|
|
406
|
+
}
|
|
407
|
+
this.ctx.stopUi();
|
|
408
|
+
const result = await openInEditor(command, text, {
|
|
409
|
+
extension: path.extname(resolved) || ".md",
|
|
410
|
+
stdio: tty ? [tty.fd, tty.fd, tty.fd] : ["inherit", "inherit", "inherit"],
|
|
411
|
+
trimTrailingNewline: false,
|
|
412
|
+
});
|
|
413
|
+
if (result !== null) {
|
|
414
|
+
await Bun.write(resolved, result);
|
|
415
|
+
this.ctx.showStatus("Plan updated in external editor.");
|
|
416
|
+
}
|
|
417
|
+
return result;
|
|
418
|
+
} catch (error) {
|
|
419
|
+
this.ctx.showWarning(`Failed to open external editor: ${String(error)}`);
|
|
420
|
+
return null;
|
|
421
|
+
} finally {
|
|
422
|
+
await tty?.close();
|
|
423
|
+
this.ctx.startUi();
|
|
424
|
+
this.ctx.requestRender(true);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
async #approve(
|
|
428
|
+
planContent: string,
|
|
429
|
+
options: {
|
|
430
|
+
planFilePath: string;
|
|
431
|
+
finalPlanFilePath: string;
|
|
432
|
+
title: string;
|
|
433
|
+
preserveContext: boolean;
|
|
434
|
+
compactBeforeExecute: boolean;
|
|
435
|
+
reviewerComments?: string;
|
|
436
|
+
},
|
|
437
|
+
): Promise<void> {
|
|
438
|
+
await this.#finalizeApprovedPlan(planContent, options.planFilePath, options.finalPlanFilePath);
|
|
439
|
+
const previousTools = this.#previousTools ?? this.ctx.session.getActiveToolNames();
|
|
440
|
+
if (options.compactBeforeExecute) this.ctx.session.markPlanCompactAbortPending();
|
|
441
|
+
let sessionSwitchCompleted = true;
|
|
442
|
+
let compactOutcome: CompactionOutcome | undefined;
|
|
443
|
+
try {
|
|
444
|
+
await this.exit({ silent: true });
|
|
445
|
+
if (!options.preserveContext) {
|
|
446
|
+
sessionSwitchCompleted = await this.ctx.handleClearCommand();
|
|
447
|
+
if (sessionSwitchCompleted)
|
|
448
|
+
await Bun.write(
|
|
449
|
+
resolveLocalUrlToPath(options.finalPlanFilePath, {
|
|
450
|
+
getArtifactsDir: () => this.ctx.sessionManager.getArtifactsDir(),
|
|
451
|
+
getSessionId: () => this.ctx.sessionManager.getSessionId(),
|
|
452
|
+
}),
|
|
453
|
+
planContent,
|
|
454
|
+
);
|
|
455
|
+
} else if (options.compactBeforeExecute) {
|
|
456
|
+
this.ctx.session.setPlanReferencePath(options.finalPlanFilePath);
|
|
457
|
+
this.#planApprovalDispatchPending = true;
|
|
458
|
+
try {
|
|
459
|
+
compactOutcome = await this.ctx.handleCompactCommand(
|
|
460
|
+
prompt.render(planModeCompactInstructionsPrompt, { planFilePath: options.finalPlanFilePath }),
|
|
461
|
+
);
|
|
462
|
+
} catch (error) {
|
|
463
|
+
this.#planApprovalDispatchPending = false;
|
|
464
|
+
await this.ctx.flushCompactionQueue({ willRetry: false });
|
|
465
|
+
throw error;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
} finally {
|
|
469
|
+
this.ctx.session.clearPlanCompactAbortPending();
|
|
470
|
+
}
|
|
471
|
+
if (previousTools.length) await this.ctx.session.setActiveToolsByName(previousTools);
|
|
472
|
+
if (!sessionSwitchCompleted)
|
|
473
|
+
return this.ctx.showWarning(
|
|
474
|
+
"Plan approved, but the new session could not be created — execution was not dispatched.",
|
|
475
|
+
);
|
|
476
|
+
this.ctx.session.setPlanReferencePath(options.finalPlanFilePath);
|
|
477
|
+
if (compactOutcome === "cancelled") {
|
|
478
|
+
this.#planApprovalDispatchPending = false;
|
|
479
|
+
await this.ctx.flushCompactionQueue({ willRetry: false });
|
|
480
|
+
return this.ctx.showWarning(
|
|
481
|
+
"Plan approved, but compaction was cancelled — execution not dispatched. Submit a turn to continue.",
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
const name = humanizePlanTitle(options.title);
|
|
485
|
+
if (
|
|
486
|
+
name &&
|
|
487
|
+
!this.ctx.sessionManager.getSessionName() &&
|
|
488
|
+
(await this.ctx.sessionManager.setSessionName(name, "auto"))
|
|
489
|
+
) {
|
|
490
|
+
setSessionTerminalTitle(this.ctx.sessionManager.getSessionName(), this.ctx.sessionManager.getCwd());
|
|
491
|
+
this.ctx.updateEditorChrome();
|
|
492
|
+
}
|
|
493
|
+
try {
|
|
494
|
+
await this.ctx.session.prompt(
|
|
495
|
+
prompt.render(planModeApprovedPrompt, {
|
|
496
|
+
planContent,
|
|
497
|
+
finalPlanFilePath: options.finalPlanFilePath,
|
|
498
|
+
contextPreserved: options.preserveContext,
|
|
499
|
+
tools: this.ctx.session.getActiveToolNames(),
|
|
500
|
+
reviewerComments: options.reviewerComments,
|
|
501
|
+
}),
|
|
502
|
+
{ synthetic: true },
|
|
503
|
+
);
|
|
504
|
+
this.ctx.session.markPlanReferenceSent();
|
|
505
|
+
} finally {
|
|
506
|
+
if (this.#planApprovalDispatchPending) {
|
|
507
|
+
this.#planApprovalDispatchPending = false;
|
|
508
|
+
await this.ctx.flushCompactionQueue({ willRetry: false });
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
#updateStatus(): void {
|
|
513
|
+
this.ctx.updatePlanModeStatus(
|
|
514
|
+
this.#enabled || this.#paused ? { enabled: this.#enabled, paused: this.#paused } : undefined,
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
}
|