@gajae-code/coding-agent 0.11.1 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/dist/types/cli/config-cli.d.ts +11 -1
- 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 +56 -1
- 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 +3 -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/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 +27 -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/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 +3 -0
- package/dist/types/tools/search-tool-bm25.d.ts +3 -4
- package/dist/types/utils/event-bus.d.ts +1 -1
- 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/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 +159 -2
- 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 +320 -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 +28 -8
- 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/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 +778 -93
- 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 +31 -1
- 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 +458 -479
- 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 +13 -5
- package/src/tools/read.ts +37 -1
- package/src/tools/resource-gc.ts +2 -2
- package/src/tools/search-tool-bm25.ts +11 -74
- package/src/utils/event-bus.ts +9 -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,474 @@
|
|
|
1
|
+
import { consumePendingGoalModeRequest } from "../../gjc-runtime/goal-mode-request";
|
|
2
|
+
import {
|
|
3
|
+
canonicalArgsKey,
|
|
4
|
+
classifyToolOutcome,
|
|
5
|
+
decideTimeoutHold,
|
|
6
|
+
type TimeoutToolOutcome,
|
|
7
|
+
toResultText,
|
|
8
|
+
turnTimeoutFingerprint,
|
|
9
|
+
} from "../../goals/continuation-timeout-guard";
|
|
10
|
+
import { type Goal, type GoalModeState, normalizeGoal } from "../../goals/state";
|
|
11
|
+
import type { AgentSession, AgentSessionEvent } from "../../session/agent-session";
|
|
12
|
+
import type { SessionContext, SessionManager } from "../../session/session-manager";
|
|
13
|
+
import { formatDuration } from "../../slash-commands/helpers/format";
|
|
14
|
+
import type { SubmittedUserInput } from "../types";
|
|
15
|
+
import type { ModeGate } from "./mode-gate";
|
|
16
|
+
|
|
17
|
+
type GoalSubcommand = "set" | "show" | "pause" | "resume" | "drop";
|
|
18
|
+
|
|
19
|
+
const GOAL_SUBCOMMANDS = new Set<GoalSubcommand>(["set", "show", "pause", "resume", "drop"]);
|
|
20
|
+
|
|
21
|
+
interface GoalModeControllerContext {
|
|
22
|
+
readonly session: AgentSession;
|
|
23
|
+
readonly sessionManager: SessionManager;
|
|
24
|
+
readonly modeGate: ModeGate;
|
|
25
|
+
get planModeActive(): boolean;
|
|
26
|
+
get inputCallback(): ((input: SubmittedUserInput) => void) | undefined;
|
|
27
|
+
get hasPendingSubmission(): boolean;
|
|
28
|
+
get hasPendingImages(): boolean;
|
|
29
|
+
get editorText(): string;
|
|
30
|
+
startPendingSubmission(input: { text: string; customType?: string; display?: boolean }): SubmittedUserInput;
|
|
31
|
+
showStatus(message: string): void;
|
|
32
|
+
showWarning(message: string): void;
|
|
33
|
+
showError(message: string): void;
|
|
34
|
+
showHookConfirm(title: string, message: string): Promise<boolean>;
|
|
35
|
+
showHookSelector(title: string, options: string[]): Promise<string | undefined>;
|
|
36
|
+
showHookEditor(title: string, options?: { promptStyle?: boolean }): Promise<string | undefined>;
|
|
37
|
+
updateGoalModeStatus(status: { enabled: boolean; paused: boolean } | undefined): void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function parseGoalSubcommand(args: string): { sub: GoalSubcommand | undefined; rest: string } {
|
|
41
|
+
const trimmed = args.trim();
|
|
42
|
+
if (!trimmed) return { sub: undefined, rest: "" };
|
|
43
|
+
const match = /^(\S+)(?:\s+([\s\S]*))?$/.exec(trimmed);
|
|
44
|
+
if (!match) return { sub: undefined, rest: trimmed };
|
|
45
|
+
const first = match[1].toLowerCase();
|
|
46
|
+
if (GOAL_SUBCOMMANDS.has(first as GoalSubcommand)) {
|
|
47
|
+
return { sub: first as GoalSubcommand, rest: match[2]?.trim() ?? "" };
|
|
48
|
+
}
|
|
49
|
+
return { sub: undefined, rest: trimmed };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Owns goal-mode state, continuation scheduling, commands, and session restoration. */
|
|
53
|
+
export class GoalModeController {
|
|
54
|
+
#enabled = false;
|
|
55
|
+
#paused = false;
|
|
56
|
+
#previousTools: string[] | undefined;
|
|
57
|
+
#continuationTimer: NodeJS.Timeout | undefined;
|
|
58
|
+
#turnHadToolCalls = false;
|
|
59
|
+
#continuationTurnInFlight = false;
|
|
60
|
+
#suppressNextContinuation = false;
|
|
61
|
+
#goalTurnToolStarts = new Map<string, { toolName: string; argsKey: string }>();
|
|
62
|
+
#goalTurnOutcomes: TimeoutToolOutcome[] = [];
|
|
63
|
+
#goalTurnUnpaired = false;
|
|
64
|
+
#goalTurnSnapshotKey: string | undefined;
|
|
65
|
+
#goalHeldSnapshotKey: string | undefined;
|
|
66
|
+
#goalTimeoutFingerprint: string | undefined;
|
|
67
|
+
#goalIdenticalTimeoutStreak = 0;
|
|
68
|
+
|
|
69
|
+
constructor(private readonly ctx: GoalModeControllerContext) {}
|
|
70
|
+
|
|
71
|
+
get enabled(): boolean {
|
|
72
|
+
return this.#enabled;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get paused(): boolean {
|
|
76
|
+
return this.#paused;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
setEnabledForCompatibility(enabled: boolean): void {
|
|
80
|
+
this.#enabled = enabled;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
setPausedForCompatibility(paused: boolean): void {
|
|
84
|
+
this.#paused = paused;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async beforeGetUserInput(): Promise<void> {
|
|
88
|
+
if (this.ctx.session.getGoalModeState()?.mode === "exiting") {
|
|
89
|
+
await this.exit({ reason: "completed", silent: true });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
scheduleContinuation(): void {
|
|
94
|
+
this.cancelContinuation();
|
|
95
|
+
if (!this.ctx.inputCallback) return;
|
|
96
|
+
if (!this.ctx.session.settings.get("goal.continuationModes").includes("interactive")) return;
|
|
97
|
+
if (this.ctx.planModeActive || !this.#enabled || this.#paused || this.#suppressNextContinuation) return;
|
|
98
|
+
if (this.ctx.hasPendingSubmission || this.ctx.editorText.trim() || this.ctx.hasPendingImages) return;
|
|
99
|
+
const state = this.ctx.session.getGoalModeState();
|
|
100
|
+
if (!state?.enabled || state.goal.status !== "active") return;
|
|
101
|
+
const prompt = this.ctx.session.goalRuntime.buildContinuationPrompt();
|
|
102
|
+
if (!prompt) return;
|
|
103
|
+
this.#continuationTimer = setTimeout(() => {
|
|
104
|
+
this.#continuationTimer = undefined;
|
|
105
|
+
if (!this.ctx.inputCallback || !this.#enabled || this.#paused) return;
|
|
106
|
+
if (this.ctx.hasPendingSubmission || this.ctx.editorText.trim() || this.ctx.hasPendingImages) return;
|
|
107
|
+
if (this.ctx.session.isStreaming || this.ctx.session.isCompacting) {
|
|
108
|
+
this.scheduleContinuation();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const latestState = this.ctx.session.getGoalModeState();
|
|
112
|
+
if (!latestState?.enabled || latestState.goal.status !== "active") return;
|
|
113
|
+
this.#continuationTurnInFlight = true;
|
|
114
|
+
this.ctx.inputCallback(
|
|
115
|
+
this.ctx.startPendingSubmission({ text: prompt, customType: "goal-continuation", display: false }),
|
|
116
|
+
);
|
|
117
|
+
}, 800);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
cancelContinuation(): void {
|
|
121
|
+
if (this.#continuationTimer) clearTimeout(this.#continuationTimer);
|
|
122
|
+
this.#continuationTimer = undefined;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
onPendingSubmissionFinished(customType?: string): void {
|
|
126
|
+
if (customType === "goal-continuation") this.#continuationTurnInFlight = false;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
onUserSubmission(): void {
|
|
130
|
+
this.#resetContinuationSuppression();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async handleSessionEvent(event: AgentSessionEvent): Promise<void> {
|
|
134
|
+
if (event.type === "agent_start") {
|
|
135
|
+
this.#turnHadToolCalls = false;
|
|
136
|
+
this.#goalTurnToolStarts.clear();
|
|
137
|
+
this.#goalTurnOutcomes = [];
|
|
138
|
+
this.#goalTurnUnpaired = false;
|
|
139
|
+
const goal = this.ctx.session.getGoalModeState()?.goal;
|
|
140
|
+
this.#goalTurnSnapshotKey = goal ? `${goal.id}\u0000${goal.objective}` : undefined;
|
|
141
|
+
this.cancelContinuation();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (event.type === "tool_execution_start") {
|
|
145
|
+
this.#turnHadToolCalls = true;
|
|
146
|
+
this.#goalTurnToolStarts.set(event.toolCallId, {
|
|
147
|
+
toolName: event.toolName,
|
|
148
|
+
argsKey: canonicalArgsKey(event.args),
|
|
149
|
+
});
|
|
150
|
+
if (!this.#continuationTurnInFlight) this.#resetContinuationSuppression();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (event.type === "tool_execution_end") {
|
|
154
|
+
const start = this.#goalTurnToolStarts.get(event.toolCallId);
|
|
155
|
+
if (!start) {
|
|
156
|
+
this.#turnHadToolCalls = true;
|
|
157
|
+
this.#goalTurnUnpaired = true;
|
|
158
|
+
} else {
|
|
159
|
+
this.#goalTurnOutcomes.push({
|
|
160
|
+
...start,
|
|
161
|
+
kind: classifyToolOutcome(event.isError, toResultText(event.result)),
|
|
162
|
+
});
|
|
163
|
+
this.#goalTurnToolStarts.delete(event.toolCallId);
|
|
164
|
+
}
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (event.type === "message_start" && event.message.role === "user" && !event.message.synthetic) {
|
|
168
|
+
this.#resetContinuationSuppression();
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (event.type === "goal_updated") {
|
|
172
|
+
if (event.state?.goal?.status === "dropped") {
|
|
173
|
+
await this.exit({ reason: "dropped", silent: true });
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const goal = event.state?.goal;
|
|
177
|
+
const snapshotKey = goal ? `${goal.id}\u0000${goal.objective}` : undefined;
|
|
178
|
+
if (this.#goalHeldSnapshotKey !== undefined && this.#goalHeldSnapshotKey !== snapshotKey)
|
|
179
|
+
this.#resetContinuationSuppression();
|
|
180
|
+
if (event.state?.enabled && !this.#previousTools) this.#previousTools = this.ctx.session.getActiveToolNames();
|
|
181
|
+
this.#enabled = event.state?.enabled === true;
|
|
182
|
+
this.#paused = event.state?.enabled !== true && event.state?.goal?.status === "paused";
|
|
183
|
+
if (this.#enabled || this.#paused) this.ctx.modeGate.enter("goal");
|
|
184
|
+
else this.ctx.modeGate.exit("goal");
|
|
185
|
+
if (!event.state?.enabled) {
|
|
186
|
+
this.#resetContinuationSuppression();
|
|
187
|
+
this.cancelContinuation();
|
|
188
|
+
}
|
|
189
|
+
this.#updateStatus();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (event.type !== "agent_end") return;
|
|
193
|
+
if (this.#continuationTurnInFlight) {
|
|
194
|
+
this.#suppressNextContinuation = !this.#turnHadToolCalls;
|
|
195
|
+
const fingerprint =
|
|
196
|
+
this.#goalTurnToolStarts.size > 0 || this.#goalTurnUnpaired
|
|
197
|
+
? null
|
|
198
|
+
: turnTimeoutFingerprint(this.#goalTurnOutcomes);
|
|
199
|
+
const decision = decideTimeoutHold(
|
|
200
|
+
{
|
|
201
|
+
heldSnapshotKey: this.#goalHeldSnapshotKey,
|
|
202
|
+
fingerprint: this.#goalTimeoutFingerprint,
|
|
203
|
+
streak: this.#goalIdenticalTimeoutStreak,
|
|
204
|
+
},
|
|
205
|
+
{ snapshotKey: this.#goalTurnSnapshotKey ?? "", fingerprint },
|
|
206
|
+
);
|
|
207
|
+
if (fingerprint === null) this.#resetTimeoutHold();
|
|
208
|
+
else {
|
|
209
|
+
this.#goalHeldSnapshotKey = decision.next.heldSnapshotKey;
|
|
210
|
+
this.#goalTimeoutFingerprint = decision.next.fingerprint;
|
|
211
|
+
this.#goalIdenticalTimeoutStreak = decision.next.streak;
|
|
212
|
+
}
|
|
213
|
+
if (decision.hold) {
|
|
214
|
+
this.#suppressNextContinuation = true;
|
|
215
|
+
this.ctx.showStatus(
|
|
216
|
+
`Goal paused for attention: repeated identical timeout from ${this.#goalTurnOutcomes[0]?.toolName ?? "tool"}. Send a message to continue.`,
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
this.#continuationTurnInFlight = false;
|
|
220
|
+
} else {
|
|
221
|
+
this.#resetTimeoutHold();
|
|
222
|
+
}
|
|
223
|
+
if (this.ctx.session.getGoalModeState()?.mode === "exiting") {
|
|
224
|
+
await this.exit({ reason: "completed", silent: true });
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
this.scheduleContinuation();
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async restoreFromSession(sessionContext: SessionContext): Promise<boolean> {
|
|
231
|
+
const goalEnabled = this.ctx.session.settings.get("goal.enabled");
|
|
232
|
+
if (!goalEnabled && (sessionContext.mode === "goal" || sessionContext.mode === "goal_paused")) {
|
|
233
|
+
this.ctx.sessionManager.appendModeChange("none");
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
if (sessionContext.mode === "goal" || sessionContext.mode === "goal_paused") {
|
|
237
|
+
const goal = normalizeGoal(sessionContext.modeData?.goal) ?? undefined;
|
|
238
|
+
if (!goal) {
|
|
239
|
+
this.ctx.sessionManager.appendModeChange("none");
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
this.ctx.session.setGoalModeState({ enabled: sessionContext.mode === "goal", mode: "active", goal });
|
|
243
|
+
const restored = await this.ctx.session.goalRuntime.onThreadResumed();
|
|
244
|
+
this.#enabled = restored?.enabled === true;
|
|
245
|
+
this.#paused = restored?.enabled !== true && restored?.goal.status === "paused";
|
|
246
|
+
if (this.#enabled || this.#paused) this.ctx.modeGate.enter("goal");
|
|
247
|
+
if (restored?.goal) {
|
|
248
|
+
this.#previousTools = this.ctx.session.getActiveToolNames();
|
|
249
|
+
await this.ctx.session.setActiveToolsByName([...new Set([...this.#previousTools, "goal"])]);
|
|
250
|
+
}
|
|
251
|
+
this.#updateStatus();
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
const pendingGoal = goalEnabled
|
|
255
|
+
? await consumePendingGoalModeRequest(this.ctx.sessionManager.getCwd(), this.ctx.sessionManager.getSessionId())
|
|
256
|
+
: null;
|
|
257
|
+
if (!pendingGoal) return false;
|
|
258
|
+
await this.enter({ objective: pendingGoal.objective, provenance: pendingGoal.provenance, silent: true });
|
|
259
|
+
this.scheduleContinuation();
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async handleCommand(rest?: string): Promise<void> {
|
|
264
|
+
try {
|
|
265
|
+
if (this.ctx.planModeActive) return this.ctx.showWarning("Exit plan mode first.");
|
|
266
|
+
if (!this.ctx.session.settings.get("goal.enabled"))
|
|
267
|
+
return this.ctx.showWarning("Goal mode is disabled. Enable it in settings (goal.enabled).");
|
|
268
|
+
const { sub, rest: subRest } = parseGoalSubcommand(rest ?? "");
|
|
269
|
+
if (sub) return await this.#dispatchSubcommand(sub, subRest);
|
|
270
|
+
if (this.#enabled) {
|
|
271
|
+
if (subRest)
|
|
272
|
+
return this.ctx.showStatus(
|
|
273
|
+
"Goal mode is already active. Use /goal to manage it, or /goal drop to start over.",
|
|
274
|
+
);
|
|
275
|
+
return await this.#openMenu("active");
|
|
276
|
+
}
|
|
277
|
+
if (this.#getPausedState()) {
|
|
278
|
+
if (subRest)
|
|
279
|
+
return this.ctx.showWarning("Resume the current goal first, or drop it before setting a new objective.");
|
|
280
|
+
return await this.#openMenu("paused");
|
|
281
|
+
}
|
|
282
|
+
const objective = subRest || (await this.ctx.showHookEditor("Goal objective", { promptStyle: true }))?.trim();
|
|
283
|
+
if (objective) await this.#startFromObjective(objective);
|
|
284
|
+
} catch (error) {
|
|
285
|
+
this.ctx.showError(error instanceof Error ? error.message : String(error));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async enter(options: {
|
|
290
|
+
objective?: string;
|
|
291
|
+
provenance?: Goal["provenance"];
|
|
292
|
+
resume?: boolean;
|
|
293
|
+
silent?: boolean;
|
|
294
|
+
}): Promise<void> {
|
|
295
|
+
if (this.#enabled) return;
|
|
296
|
+
if (!this.ctx.modeGate.enter("goal")) return this.ctx.showWarning("Exit plan mode first.");
|
|
297
|
+
this.#previousTools = this.ctx.session.getActiveToolNames();
|
|
298
|
+
this.#paused = false;
|
|
299
|
+
const state = options.resume
|
|
300
|
+
? await this.ctx.session.goalRuntime.resumeGoal()
|
|
301
|
+
: await this.ctx.session.goalRuntime.createGoal({
|
|
302
|
+
objective: options.objective ?? "",
|
|
303
|
+
provenance: options.provenance,
|
|
304
|
+
});
|
|
305
|
+
await this.ctx.session.setActiveToolsByName([...new Set([...this.#previousTools, "goal"])]);
|
|
306
|
+
this.ctx.session.setGoalModeState(state);
|
|
307
|
+
this.#enabled = true;
|
|
308
|
+
this.#resetContinuationSuppression();
|
|
309
|
+
this.#updateStatus();
|
|
310
|
+
if (this.ctx.session.isStreaming) await this.ctx.session.sendGoalModeContext({ deliverAs: "steer" });
|
|
311
|
+
if (!options.silent) this.ctx.showStatus(options.resume ? "Goal mode resumed." : "Goal mode enabled.");
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async exit(options?: {
|
|
315
|
+
silent?: boolean;
|
|
316
|
+
paused?: boolean;
|
|
317
|
+
reason?: "completed" | "paused" | "dropped";
|
|
318
|
+
}): Promise<void> {
|
|
319
|
+
const shouldRestoreTools =
|
|
320
|
+
this.#previousTools &&
|
|
321
|
+
options?.reason !== "dropped" &&
|
|
322
|
+
(this.#enabled || options?.reason === "completed" || options?.paused);
|
|
323
|
+
if (shouldRestoreTools && this.#previousTools) await this.ctx.session.setActiveToolsByName(this.#previousTools);
|
|
324
|
+
const currentState = this.ctx.session.getGoalModeState();
|
|
325
|
+
if (options?.reason === "completed") {
|
|
326
|
+
this.ctx.session.setGoalModeState(undefined);
|
|
327
|
+
this.ctx.sessionManager.appendModeChange("none");
|
|
328
|
+
this.ctx.sessionManager.appendCustomEntry("goal-completed", {
|
|
329
|
+
objective: currentState?.goal?.objective,
|
|
330
|
+
tokensUsed: currentState?.goal?.tokensUsed,
|
|
331
|
+
timeUsedSeconds: currentState?.goal?.timeUsedSeconds,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
this.#enabled = false;
|
|
335
|
+
this.#paused = options?.paused ?? false;
|
|
336
|
+
this.#previousTools = undefined;
|
|
337
|
+
this.#continuationTurnInFlight = false;
|
|
338
|
+
this.#resetContinuationSuppression();
|
|
339
|
+
this.cancelContinuation();
|
|
340
|
+
if (!this.#paused) this.ctx.modeGate.exit("goal");
|
|
341
|
+
this.#updateStatus();
|
|
342
|
+
if (!options?.silent)
|
|
343
|
+
this.ctx.showStatus(
|
|
344
|
+
options?.reason === "completed"
|
|
345
|
+
? "Goal mode completed."
|
|
346
|
+
: options?.reason === "dropped"
|
|
347
|
+
? "Goal dropped."
|
|
348
|
+
: options?.paused
|
|
349
|
+
? "Goal mode paused."
|
|
350
|
+
: "Goal mode disabled.",
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
#getPausedState(): GoalModeState | undefined {
|
|
355
|
+
const state = this.ctx.session.getGoalModeState();
|
|
356
|
+
return state?.goal && !state.enabled && state.goal.status === "paused" ? state : undefined;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
#updateStatus(): void {
|
|
360
|
+
this.ctx.updateGoalModeStatus(
|
|
361
|
+
this.#enabled || this.#paused ? { enabled: this.#enabled, paused: this.#paused } : undefined,
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
#resetTimeoutHold(): void {
|
|
366
|
+
this.#goalTurnToolStarts.clear();
|
|
367
|
+
this.#goalTurnOutcomes = [];
|
|
368
|
+
this.#goalTurnUnpaired = false;
|
|
369
|
+
this.#goalTurnSnapshotKey = undefined;
|
|
370
|
+
this.#goalHeldSnapshotKey = undefined;
|
|
371
|
+
this.#goalTimeoutFingerprint = undefined;
|
|
372
|
+
this.#goalIdenticalTimeoutStreak = 0;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
#resetContinuationSuppression(): void {
|
|
376
|
+
this.#suppressNextContinuation = false;
|
|
377
|
+
this.#resetTimeoutHold();
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
async #dispatchSubcommand(sub: GoalSubcommand, rest: string): Promise<void> {
|
|
381
|
+
switch (sub) {
|
|
382
|
+
case "set":
|
|
383
|
+
return await this.#set(rest);
|
|
384
|
+
case "show":
|
|
385
|
+
return this.#showDetails();
|
|
386
|
+
case "pause":
|
|
387
|
+
return await this.#pause();
|
|
388
|
+
case "resume":
|
|
389
|
+
return await this.#resume();
|
|
390
|
+
case "drop":
|
|
391
|
+
return await this.#drop();
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
async #openMenu(state: "active" | "paused"): Promise<void> {
|
|
396
|
+
const goal = this.ctx.session.getGoalModeState()?.goal;
|
|
397
|
+
if (!goal) return;
|
|
398
|
+
const summary = goal.objective.length > 48 ? `${goal.objective.slice(0, 47)}…` : goal.objective;
|
|
399
|
+
const choice = await this.ctx.showHookSelector(
|
|
400
|
+
state === "active" ? `Goal: ${summary} (${goal.status})` : `Goal paused: ${summary}`,
|
|
401
|
+
state === "active" ? ["Show details", "Pause", "Drop"] : ["Resume", "Show details", "Drop"],
|
|
402
|
+
);
|
|
403
|
+
if (choice === "Show details") this.#showDetails();
|
|
404
|
+
else if (choice === "Pause") await this.#pause();
|
|
405
|
+
else if (choice === "Resume") await this.#resume();
|
|
406
|
+
else if (choice === "Drop") await this.#drop();
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
#showDetails(): void {
|
|
410
|
+
const state = this.ctx.session.getGoalModeState();
|
|
411
|
+
const goal = state?.goal;
|
|
412
|
+
if (!goal) return this.ctx.showStatus("No goal set.");
|
|
413
|
+
this.ctx.showStatus(
|
|
414
|
+
[
|
|
415
|
+
`Objective: ${goal.objective}`,
|
|
416
|
+
`Status: ${goal.status}${state?.enabled ? "" : " (paused)"}`,
|
|
417
|
+
`Tokens used: ${goal.tokensUsed.toLocaleString()}`,
|
|
418
|
+
`Time spent: ${formatDuration(goal.timeUsedSeconds * 1000)}`,
|
|
419
|
+
].join("\n"),
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
async #pause(): Promise<void> {
|
|
424
|
+
if (!this.#enabled) return this.ctx.showWarning("No active goal to pause.");
|
|
425
|
+
await this.ctx.session.goalRuntime.pauseGoal();
|
|
426
|
+
await this.exit({ paused: true, reason: "paused" });
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
async #resume(): Promise<void> {
|
|
430
|
+
if (!this.#getPausedState()) return this.ctx.showWarning("No paused goal to resume.");
|
|
431
|
+
await this.enter({ resume: true, silent: true });
|
|
432
|
+
this.ctx.showStatus("Goal mode resumed.");
|
|
433
|
+
this.scheduleContinuation();
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
async #drop(): Promise<void> {
|
|
437
|
+
if (!this.#enabled && !this.#getPausedState()) return this.ctx.showWarning("No goal to drop.");
|
|
438
|
+
if (
|
|
439
|
+
!(await this.ctx.showHookConfirm(
|
|
440
|
+
"Drop goal?",
|
|
441
|
+
"This removes the goal record. Accumulated usage stays in the session log.",
|
|
442
|
+
))
|
|
443
|
+
)
|
|
444
|
+
return;
|
|
445
|
+
await this.ctx.session.goalRuntime.dropGoal();
|
|
446
|
+
await this.exit({ reason: "dropped" });
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
async #startFromObjective(objective: string): Promise<void> {
|
|
450
|
+
await this.enter({ objective, silent: true });
|
|
451
|
+
this.#resetContinuationSuppression();
|
|
452
|
+
this.ctx.inputCallback?.(this.ctx.startPendingSubmission({ text: objective }));
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
async #replaceFromObjective(objective: string): Promise<void> {
|
|
456
|
+
const state = await this.ctx.session.goalRuntime.replaceGoal({ objective });
|
|
457
|
+
this.ctx.session.setGoalModeState(state);
|
|
458
|
+
this.#enabled = true;
|
|
459
|
+
this.#paused = false;
|
|
460
|
+
this.#resetContinuationSuppression();
|
|
461
|
+
this.#updateStatus();
|
|
462
|
+
if (this.ctx.session.isStreaming) await this.ctx.session.sendGoalModeContext({ deliverAs: "steer" });
|
|
463
|
+
this.ctx.inputCallback?.(this.ctx.startPendingSubmission({ text: objective }));
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
async #set(rest: string): Promise<void> {
|
|
467
|
+
if (!this.#enabled && this.#getPausedState())
|
|
468
|
+
return this.ctx.showWarning("Resume the current goal first, or drop it before setting a new objective.");
|
|
469
|
+
const objective = rest.trim() || (await this.ctx.showHookEditor("Goal objective", { promptStyle: true }))?.trim();
|
|
470
|
+
if (!objective) return;
|
|
471
|
+
if (this.#enabled) await this.#replaceFromObjective(objective);
|
|
472
|
+
else await this.#startFromObjective(objective);
|
|
473
|
+
}
|
|
474
|
+
}
|