@orion-agents/orion-code 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +495 -0
- package/README.md +142 -314
- package/README.zh-CN.md +117 -559
- package/dist/cli.js +71 -90
- package/dist/cli.js.map +1 -1
- package/dist/commands/context-commands.d.ts.map +1 -1
- package/dist/commands/context-commands.js +14 -7
- package/dist/commands/context-commands.js.map +1 -1
- package/dist/commands/context-tool-command-handlers.d.ts +4 -5
- package/dist/commands/context-tool-command-handlers.d.ts.map +1 -1
- package/dist/commands/context-tool-command-handlers.js +174 -208
- package/dist/commands/context-tool-command-handlers.js.map +1 -1
- package/dist/commands/core-command-handlers.d.ts +3 -6
- package/dist/commands/core-command-handlers.d.ts.map +1 -1
- package/dist/commands/core-command-handlers.js +66 -664
- package/dist/commands/core-command-handlers.js.map +1 -1
- package/dist/commands/diagnostic-command-handlers.d.ts +1 -2
- package/dist/commands/diagnostic-command-handlers.d.ts.map +1 -1
- package/dist/commands/diagnostic-command-handlers.js +3 -17
- package/dist/commands/diagnostic-command-handlers.js.map +1 -1
- package/dist/commands/diagnostic-commands.d.ts.map +1 -1
- package/dist/commands/diagnostic-commands.js +0 -45
- package/dist/commands/diagnostic-commands.js.map +1 -1
- package/dist/commands/index.d.ts +1 -1
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +2 -7
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/model-command-handlers.d.ts +2 -2
- package/dist/commands/model-command-handlers.d.ts.map +1 -1
- package/dist/commands/model-command-handlers.js +168 -3
- package/dist/commands/model-command-handlers.js.map +1 -1
- package/dist/commands/model-commands.d.ts.map +1 -1
- package/dist/commands/model-commands.js +0 -11
- package/dist/commands/model-commands.js.map +1 -1
- package/dist/commands/registry.d.ts.map +1 -1
- package/dist/commands/registry.js +1 -139
- package/dist/commands/registry.js.map +1 -1
- package/dist/commands/session-command-handlers.d.ts.map +1 -1
- package/dist/commands/session-command-handlers.js +35 -119
- package/dist/commands/session-command-handlers.js.map +1 -1
- package/dist/commands/session-commands.d.ts.map +1 -1
- package/dist/commands/session-commands.js +2 -50
- package/dist/commands/session-commands.js.map +1 -1
- package/dist/commands/target-command.d.ts +9 -15
- package/dist/commands/target-command.d.ts.map +1 -1
- package/dist/commands/target-command.js +16 -130
- package/dist/commands/target-command.js.map +1 -1
- package/dist/commands/tool-commands.d.ts.map +1 -1
- package/dist/commands/tool-commands.js +0 -10
- package/dist/commands/tool-commands.js.map +1 -1
- package/dist/commands/types.d.ts +14 -14
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/types.js +1 -1
- package/dist/commands/types.js.map +1 -1
- package/dist/commands/workflow-command-handlers.d.ts.map +1 -1
- package/dist/commands/workflow-command-handlers.js +1 -3
- package/dist/commands/workflow-command-handlers.js.map +1 -1
- package/dist/commands/workflow-commands.d.ts.map +1 -1
- package/dist/commands/workflow-commands.js +2 -24
- package/dist/commands/workflow-commands.js.map +1 -1
- package/dist/framework/agent-mode.d.ts +2 -3
- package/dist/framework/agent-mode.d.ts.map +1 -1
- package/dist/framework/agent-mode.js +8 -31
- package/dist/framework/agent-mode.js.map +1 -1
- package/dist/framework/index.d.ts +8 -6
- package/dist/framework/index.d.ts.map +1 -1
- package/dist/framework/index.js +14 -9
- package/dist/framework/index.js.map +1 -1
- package/dist/framework/loop-budget-contract.d.ts +20 -0
- package/dist/framework/loop-budget-contract.d.ts.map +1 -0
- package/dist/framework/loop-budget-contract.js +13 -0
- package/dist/framework/loop-budget-contract.js.map +1 -0
- package/dist/framework/prompt.d.ts.map +1 -1
- package/dist/framework/prompt.js +5 -4
- package/dist/framework/prompt.js.map +1 -1
- package/dist/framework/query.d.ts +71 -26
- package/dist/framework/query.d.ts.map +1 -1
- package/dist/framework/query.js +371 -102
- package/dist/framework/query.js.map +1 -1
- package/dist/framework/stop-decision.d.ts +56 -0
- package/dist/framework/stop-decision.d.ts.map +1 -0
- package/dist/framework/stop-decision.js +36 -0
- package/dist/framework/stop-decision.js.map +1 -0
- package/dist/framework/store.d.ts +4 -2
- package/dist/framework/store.d.ts.map +1 -1
- package/dist/framework/store.js +1 -0
- package/dist/framework/store.js.map +1 -1
- package/dist/framework/tool-call-orchestrator.d.ts +80 -0
- package/dist/framework/tool-call-orchestrator.d.ts.map +1 -0
- package/dist/framework/tool-call-orchestrator.js +192 -0
- package/dist/framework/tool-call-orchestrator.js.map +1 -0
- package/dist/framework/tool-state.d.ts +12 -11
- package/dist/framework/tool-state.d.ts.map +1 -1
- package/dist/framework/tool-state.js +36 -28
- package/dist/framework/tool-state.js.map +1 -1
- package/dist/framework/tool.d.ts +0 -9
- package/dist/framework/tool.d.ts.map +1 -1
- package/dist/framework/tool.js.map +1 -1
- package/dist/harness/assembler.d.ts.map +1 -1
- package/dist/harness/assembler.js +77 -19
- package/dist/harness/assembler.js.map +1 -1
- package/dist/harness/capability-profile.d.ts +3 -0
- package/dist/harness/capability-profile.d.ts.map +1 -0
- package/dist/harness/capability-profile.js +44 -0
- package/dist/harness/capability-profile.js.map +1 -0
- package/dist/harness/capsule.d.ts.map +1 -1
- package/dist/harness/capsule.js +22 -3
- package/dist/harness/capsule.js.map +1 -1
- package/dist/harness/compact-benchmark-corpus.d.ts +10 -0
- package/dist/harness/compact-benchmark-corpus.d.ts.map +1 -0
- package/dist/harness/compact-benchmark-corpus.js +56 -0
- package/dist/harness/compact-benchmark-corpus.js.map +1 -0
- package/dist/harness/context-harness.d.ts +23 -3
- package/dist/harness/context-harness.d.ts.map +1 -1
- package/dist/harness/context-harness.js +183 -11
- package/dist/harness/context-harness.js.map +1 -1
- package/dist/harness/contract.d.ts.map +1 -1
- package/dist/harness/contract.js +106 -11
- package/dist/harness/contract.js.map +1 -1
- package/dist/harness/drift-guard.d.ts +2 -1
- package/dist/harness/drift-guard.d.ts.map +1 -1
- package/dist/harness/drift-guard.js +315 -20
- package/dist/harness/drift-guard.js.map +1 -1
- package/dist/harness/evidence.d.ts.map +1 -1
- package/dist/harness/evidence.js +25 -12
- package/dist/harness/evidence.js.map +1 -1
- package/dist/harness/index.d.ts +7 -2
- package/dist/harness/index.d.ts.map +1 -1
- package/dist/harness/index.js +19 -1
- package/dist/harness/index.js.map +1 -1
- package/dist/harness/ledger.d.ts.map +1 -1
- package/dist/harness/ledger.js +44 -14
- package/dist/harness/ledger.js.map +1 -1
- package/dist/harness/progress-controller.d.ts +14 -0
- package/dist/harness/progress-controller.d.ts.map +1 -0
- package/dist/harness/progress-controller.js +110 -0
- package/dist/harness/progress-controller.js.map +1 -0
- package/dist/harness/state.d.ts.map +1 -1
- package/dist/harness/state.js +5 -2
- package/dist/harness/state.js.map +1 -1
- package/dist/harness/stop-controller.d.ts +15 -0
- package/dist/harness/stop-controller.d.ts.map +1 -0
- package/dist/harness/stop-controller.js +87 -0
- package/dist/harness/stop-controller.js.map +1 -0
- package/dist/harness/types.d.ts +137 -0
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/verification.d.ts +7 -0
- package/dist/harness/verification.d.ts.map +1 -0
- package/dist/harness/verification.js +122 -0
- package/dist/harness/verification.js.map +1 -0
- package/dist/index.d.ts +70 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +64 -59
- package/dist/index.js.map +1 -1
- package/dist/memory/index.d.ts +1 -0
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +1 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/prompt-context.d.ts +42 -0
- package/dist/memory/prompt-context.d.ts.map +1 -0
- package/dist/memory/prompt-context.js +129 -0
- package/dist/memory/prompt-context.js.map +1 -0
- package/dist/print-ui/launch.d.ts.map +1 -1
- package/dist/print-ui/launch.js +9 -2
- package/dist/print-ui/launch.js.map +1 -1
- package/dist/product/paths.d.ts +7 -0
- package/dist/product/paths.d.ts.map +1 -1
- package/dist/product/paths.js +19 -0
- package/dist/product/paths.js.map +1 -1
- package/dist/runtime/agent-loop.d.ts +78 -0
- package/dist/runtime/agent-loop.d.ts.map +1 -0
- package/dist/runtime/agent-loop.js +418 -0
- package/dist/runtime/agent-loop.js.map +1 -0
- package/dist/runtime/agent-runtime-controller.d.ts +10 -57
- package/dist/runtime/agent-runtime-controller.d.ts.map +1 -1
- package/dist/runtime/agent-runtime-controller.js +265 -1215
- package/dist/runtime/agent-runtime-controller.js.map +1 -1
- package/dist/runtime/agent-runtime-protocol.d.ts +4 -5
- package/dist/runtime/agent-runtime-protocol.d.ts.map +1 -1
- package/dist/runtime/agent-runtime-protocol.js.map +1 -1
- package/dist/runtime/agent-runtime-runner.d.ts +34 -0
- package/dist/runtime/agent-runtime-runner.d.ts.map +1 -0
- package/dist/runtime/agent-runtime-runner.js +3 -0
- package/dist/runtime/agent-runtime-runner.js.map +1 -0
- package/dist/runtime/batch-read-service.d.ts +29 -0
- package/dist/runtime/batch-read-service.d.ts.map +1 -0
- package/dist/runtime/batch-read-service.js +212 -0
- package/dist/runtime/batch-read-service.js.map +1 -0
- package/dist/runtime/builtin-tool-provider.d.ts +30 -0
- package/dist/runtime/builtin-tool-provider.d.ts.map +1 -0
- package/dist/runtime/builtin-tool-provider.js +233 -0
- package/dist/runtime/builtin-tool-provider.js.map +1 -0
- package/dist/runtime/capabilities/compiler.d.ts +11 -0
- package/dist/runtime/capabilities/compiler.d.ts.map +1 -0
- package/dist/runtime/capabilities/compiler.js +719 -0
- package/dist/runtime/capabilities/compiler.js.map +1 -0
- package/dist/runtime/capabilities/index.d.ts +3 -0
- package/dist/runtime/capabilities/index.d.ts.map +1 -0
- package/dist/runtime/capabilities/index.js +9 -0
- package/dist/runtime/capabilities/index.js.map +1 -0
- package/dist/runtime/capabilities/types.d.ts +175 -0
- package/dist/runtime/capabilities/types.d.ts.map +1 -0
- package/dist/runtime/capabilities/types.js +3 -0
- package/dist/runtime/capabilities/types.js.map +1 -0
- package/dist/runtime/capability-receipt-journal.d.ts +29 -0
- package/dist/runtime/capability-receipt-journal.d.ts.map +1 -0
- package/dist/runtime/capability-receipt-journal.js +264 -0
- package/dist/runtime/capability-receipt-journal.js.map +1 -0
- package/dist/runtime/capability-step-factory.d.ts +73 -0
- package/dist/runtime/capability-step-factory.d.ts.map +1 -0
- package/dist/runtime/capability-step-factory.js +302 -0
- package/dist/runtime/capability-step-factory.js.map +1 -0
- package/dist/runtime/compact-transaction.d.ts +225 -0
- package/dist/runtime/compact-transaction.d.ts.map +1 -0
- package/dist/runtime/compact-transaction.js +622 -0
- package/dist/runtime/compact-transaction.js.map +1 -0
- package/dist/runtime/composer/buffer.d.ts +3 -4
- package/dist/runtime/composer/buffer.d.ts.map +1 -1
- package/dist/runtime/composer/buffer.js +3 -4
- package/dist/runtime/composer/buffer.js.map +1 -1
- package/dist/runtime/composer/grapheme.d.ts +2 -4
- package/dist/runtime/composer/grapheme.d.ts.map +1 -1
- package/dist/runtime/composer/grapheme.js +2 -4
- package/dist/runtime/composer/grapheme.js.map +1 -1
- package/dist/runtime/composer/layout.d.ts +1 -3
- package/dist/runtime/composer/layout.d.ts.map +1 -1
- package/dist/runtime/composer/layout.js +1 -3
- package/dist/runtime/composer/layout.js.map +1 -1
- package/dist/runtime/core-tools/descriptors.d.ts +17 -0
- package/dist/runtime/core-tools/descriptors.d.ts.map +1 -0
- package/dist/runtime/core-tools/descriptors.js +185 -0
- package/dist/runtime/core-tools/descriptors.js.map +1 -0
- package/dist/runtime/first-party-core-provider.d.ts +55 -0
- package/dist/runtime/first-party-core-provider.d.ts.map +1 -0
- package/dist/runtime/first-party-core-provider.js +197 -0
- package/dist/runtime/first-party-core-provider.js.map +1 -0
- package/dist/runtime/first-party-long-tail-provider.d.ts +57 -0
- package/dist/runtime/first-party-long-tail-provider.d.ts.map +1 -0
- package/dist/runtime/first-party-long-tail-provider.js +238 -0
- package/dist/runtime/first-party-long-tail-provider.js.map +1 -0
- package/dist/runtime/first-party-tool-services.d.ts +43 -0
- package/dist/runtime/first-party-tool-services.d.ts.map +1 -0
- package/dist/runtime/first-party-tool-services.js +200 -0
- package/dist/runtime/first-party-tool-services.js.map +1 -0
- package/dist/runtime/first-party-tool-universe.d.ts +14 -0
- package/dist/runtime/first-party-tool-universe.d.ts.map +1 -0
- package/dist/runtime/first-party-tool-universe.js +20 -0
- package/dist/runtime/first-party-tool-universe.js.map +1 -0
- package/dist/runtime/goal-lifecycle-v2.d.ts +63 -0
- package/dist/runtime/goal-lifecycle-v2.d.ts.map +1 -0
- package/dist/runtime/goal-lifecycle-v2.js +253 -0
- package/dist/runtime/goal-lifecycle-v2.js.map +1 -0
- package/dist/runtime/goal-runtime-coordinator.d.ts +105 -0
- package/dist/runtime/goal-runtime-coordinator.d.ts.map +1 -0
- package/dist/runtime/goal-runtime-coordinator.js +506 -0
- package/dist/runtime/goal-runtime-coordinator.js.map +1 -0
- package/dist/runtime/goals/types.d.ts +0 -1
- package/dist/runtime/goals/types.d.ts.map +1 -1
- package/dist/runtime/goals/types.js +0 -1
- package/dist/runtime/goals/types.js.map +1 -1
- package/dist/runtime/harness-confluence.d.ts +165 -0
- package/dist/runtime/harness-confluence.d.ts.map +1 -0
- package/dist/runtime/harness-confluence.js +807 -0
- package/dist/runtime/harness-confluence.js.map +1 -0
- package/dist/runtime/harness-eval.d.ts +96 -0
- package/dist/runtime/harness-eval.d.ts.map +1 -0
- package/dist/runtime/harness-eval.js +181 -0
- package/dist/runtime/harness-eval.js.map +1 -0
- package/dist/runtime/harness-metrics.d.ts +202 -0
- package/dist/runtime/harness-metrics.d.ts.map +1 -0
- package/dist/runtime/harness-metrics.js +415 -0
- package/dist/runtime/harness-metrics.js.map +1 -0
- package/dist/runtime/legacy-session-importer.d.ts +99 -0
- package/dist/runtime/legacy-session-importer.d.ts.map +1 -0
- package/dist/runtime/legacy-session-importer.js +455 -0
- package/dist/runtime/legacy-session-importer.js.map +1 -0
- package/dist/runtime/legacy-thread-materializer.d.ts +72 -0
- package/dist/runtime/legacy-thread-materializer.d.ts.map +1 -0
- package/dist/runtime/legacy-thread-materializer.js +553 -0
- package/dist/runtime/legacy-thread-materializer.js.map +1 -0
- package/dist/runtime/long-tail-tools/descriptors.d.ts +23 -0
- package/dist/runtime/long-tail-tools/descriptors.d.ts.map +1 -0
- package/dist/runtime/long-tail-tools/descriptors.js +423 -0
- package/dist/runtime/long-tail-tools/descriptors.js.map +1 -0
- package/dist/runtime/loop-budget.d.ts +1 -1
- package/dist/runtime/loop-budget.d.ts.map +1 -1
- package/dist/runtime/loop-budget.js +2 -2
- package/dist/runtime/loop-budget.js.map +1 -1
- package/dist/runtime/mcp/first-party-mcp-adapter.d.ts +75 -0
- package/dist/runtime/mcp/first-party-mcp-adapter.d.ts.map +1 -0
- package/dist/runtime/mcp/first-party-mcp-adapter.js +484 -0
- package/dist/runtime/mcp/first-party-mcp-adapter.js.map +1 -0
- package/dist/runtime/mcp/first-party-mcp-config.d.ts +13 -0
- package/dist/runtime/mcp/first-party-mcp-config.d.ts.map +1 -0
- package/dist/runtime/mcp/first-party-mcp-config.js +139 -0
- package/dist/runtime/mcp/first-party-mcp-config.js.map +1 -0
- package/dist/runtime/mcp/index.d.ts +5 -0
- package/dist/runtime/mcp/index.d.ts.map +1 -0
- package/dist/{skills → runtime/mcp}/index.js +3 -9
- package/dist/runtime/mcp/index.js.map +1 -0
- package/dist/runtime/mcp/lazy-mcp-runtime.d.ts +95 -0
- package/dist/runtime/mcp/lazy-mcp-runtime.d.ts.map +1 -0
- package/dist/runtime/mcp/lazy-mcp-runtime.js +854 -0
- package/dist/runtime/mcp/lazy-mcp-runtime.js.map +1 -0
- package/dist/runtime/mcp/types.d.ts +128 -0
- package/dist/runtime/mcp/types.d.ts.map +1 -0
- package/dist/runtime/mcp/types.js +5 -0
- package/dist/runtime/mcp/types.js.map +1 -0
- package/dist/runtime/model-coordinator.d.ts +44 -1
- package/dist/runtime/model-coordinator.d.ts.map +1 -1
- package/dist/runtime/model-coordinator.js +161 -19
- package/dist/runtime/model-coordinator.js.map +1 -1
- package/dist/runtime/orion-runtime-v1.d.ts +321 -0
- package/dist/runtime/orion-runtime-v1.d.ts.map +1 -0
- package/dist/runtime/orion-runtime-v1.js +958 -0
- package/dist/runtime/orion-runtime-v1.js.map +1 -0
- package/dist/runtime/orion-session-runner.d.ts +37 -0
- package/dist/runtime/orion-session-runner.d.ts.map +1 -0
- package/dist/runtime/orion-session-runner.js +146 -0
- package/dist/runtime/orion-session-runner.js.map +1 -0
- package/dist/runtime/product-orion-runtime.d.ts +35 -0
- package/dist/runtime/product-orion-runtime.d.ts.map +1 -0
- package/dist/runtime/product-orion-runtime.js +1019 -0
- package/dist/runtime/product-orion-runtime.js.map +1 -0
- package/dist/runtime/prompts/index.d.ts +3 -0
- package/dist/runtime/prompts/index.d.ts.map +1 -0
- package/dist/{ink-ui/types.js → runtime/prompts/index.js} +3 -2
- package/dist/runtime/prompts/index.js.map +1 -0
- package/dist/runtime/prompts/prompt-registry.d.ts +22 -0
- package/dist/runtime/prompts/prompt-registry.d.ts.map +1 -0
- package/dist/runtime/prompts/prompt-registry.js +356 -0
- package/dist/runtime/prompts/prompt-registry.js.map +1 -0
- package/dist/runtime/prompts/types.d.ts +111 -0
- package/dist/runtime/prompts/types.d.ts.map +1 -0
- package/dist/runtime/prompts/types.js +5 -0
- package/dist/runtime/prompts/types.js.map +1 -0
- package/dist/runtime/protocol/canonical.d.ts +3 -0
- package/dist/runtime/protocol/canonical.d.ts.map +1 -0
- package/dist/runtime/protocol/canonical.js +21 -0
- package/dist/runtime/protocol/canonical.js.map +1 -0
- package/dist/runtime/protocol/index.d.ts +4 -0
- package/dist/runtime/protocol/index.d.ts.map +1 -0
- package/dist/runtime/protocol/index.js +16 -0
- package/dist/runtime/protocol/index.js.map +1 -0
- package/dist/runtime/protocol/runtime-protocol-v1.d.ts +671 -0
- package/dist/runtime/protocol/runtime-protocol-v1.d.ts.map +1 -0
- package/dist/runtime/protocol/runtime-protocol-v1.js +557 -0
- package/dist/runtime/protocol/runtime-protocol-v1.js.map +1 -0
- package/dist/runtime/release-receipts.d.ts +109 -0
- package/dist/runtime/release-receipts.d.ts.map +1 -0
- package/dist/runtime/release-receipts.js +304 -0
- package/dist/runtime/release-receipts.js.map +1 -0
- package/dist/runtime/resource-scope.d.ts +123 -0
- package/dist/runtime/resource-scope.d.ts.map +1 -0
- package/dist/runtime/resource-scope.js +363 -0
- package/dist/runtime/resource-scope.js.map +1 -0
- package/dist/runtime/runtime-event-buffer.d.ts +78 -0
- package/dist/runtime/runtime-event-buffer.d.ts.map +1 -0
- package/dist/runtime/runtime-event-buffer.js +237 -0
- package/dist/runtime/runtime-event-buffer.js.map +1 -0
- package/dist/runtime/runtime-services.d.ts +87 -0
- package/dist/runtime/runtime-services.d.ts.map +1 -0
- package/dist/runtime/runtime-services.js +180 -0
- package/dist/runtime/runtime-services.js.map +1 -0
- package/dist/runtime/skills/bounded-lru-cache.d.ts +34 -0
- package/dist/runtime/skills/bounded-lru-cache.d.ts.map +1 -0
- package/dist/runtime/skills/bounded-lru-cache.js +100 -0
- package/dist/runtime/skills/bounded-lru-cache.js.map +1 -0
- package/dist/runtime/skills/filesystem-skill-provider.d.ts +96 -0
- package/dist/runtime/skills/filesystem-skill-provider.d.ts.map +1 -0
- package/dist/runtime/skills/filesystem-skill-provider.js +829 -0
- package/dist/runtime/skills/filesystem-skill-provider.js.map +1 -0
- package/dist/runtime/skills/index.d.ts +5 -0
- package/dist/runtime/skills/index.d.ts.map +1 -0
- package/dist/{ink-ui/controllers/chat-controller.js → runtime/skills/index.js} +5 -2
- package/dist/runtime/skills/index.js.map +1 -0
- package/dist/runtime/skills/lazy-skill-runtime.d.ts +77 -0
- package/dist/runtime/skills/lazy-skill-runtime.d.ts.map +1 -0
- package/dist/runtime/skills/lazy-skill-runtime.js +673 -0
- package/dist/runtime/skills/lazy-skill-runtime.js.map +1 -0
- package/dist/runtime/skills/types.d.ts +137 -0
- package/dist/runtime/skills/types.d.ts.map +1 -0
- package/dist/runtime/skills/types.js +13 -0
- package/dist/runtime/skills/types.js.map +1 -0
- package/dist/runtime/step-snapshot.d.ts +183 -0
- package/dist/runtime/step-snapshot.d.ts.map +1 -0
- package/dist/runtime/step-snapshot.js +286 -0
- package/dist/runtime/step-snapshot.js.map +1 -0
- package/dist/runtime/subagent-thread-runtime.d.ts +239 -0
- package/dist/runtime/subagent-thread-runtime.d.ts.map +1 -0
- package/dist/runtime/subagent-thread-runtime.js +876 -0
- package/dist/runtime/subagent-thread-runtime.js.map +1 -0
- package/dist/runtime/subagents/index.d.ts +5 -2
- package/dist/runtime/subagents/index.d.ts.map +1 -1
- package/dist/runtime/subagents/index.js +10 -2
- package/dist/runtime/subagents/index.js.map +1 -1
- package/dist/runtime/subagents/parent-step-fork.d.ts +36 -0
- package/dist/runtime/subagents/parent-step-fork.d.ts.map +1 -0
- package/dist/runtime/subagents/parent-step-fork.js +83 -0
- package/dist/runtime/subagents/parent-step-fork.js.map +1 -0
- package/dist/runtime/subagents/production.d.ts +65 -42
- package/dist/runtime/subagents/production.d.ts.map +1 -1
- package/dist/runtime/subagents/production.js +494 -151
- package/dist/runtime/subagents/production.js.map +1 -1
- package/dist/runtime/subagents/receipt-journal.d.ts +20 -0
- package/dist/runtime/subagents/receipt-journal.d.ts.map +1 -0
- package/dist/runtime/subagents/receipt-journal.js +74 -0
- package/dist/runtime/subagents/receipt-journal.js.map +1 -0
- package/dist/runtime/subagents/runner.d.ts +12 -1
- package/dist/runtime/subagents/runner.d.ts.map +1 -1
- package/dist/runtime/subagents/runner.js +62 -1
- package/dist/runtime/subagents/runner.js.map +1 -1
- package/dist/runtime/subagents/runtime-contract.d.ts +29 -0
- package/dist/runtime/subagents/runtime-contract.d.ts.map +1 -0
- package/dist/runtime/subagents/runtime-contract.js +3 -0
- package/dist/runtime/subagents/runtime-contract.js.map +1 -0
- package/dist/runtime/subagents/runtime-integration.d.ts +41 -56
- package/dist/runtime/subagents/runtime-integration.d.ts.map +1 -1
- package/dist/runtime/subagents/runtime-integration.js +34 -197
- package/dist/runtime/subagents/runtime-integration.js.map +1 -1
- package/dist/runtime/subagents/supervisor.d.ts +19 -7
- package/dist/runtime/subagents/supervisor.d.ts.map +1 -1
- package/dist/runtime/subagents/supervisor.js +88 -39
- package/dist/runtime/subagents/supervisor.js.map +1 -1
- package/dist/runtime/subagents/types.d.ts +5 -2
- package/dist/runtime/subagents/types.d.ts.map +1 -1
- package/dist/runtime/subagents/types.js +1 -1
- package/dist/runtime/subagents/types.js.map +1 -1
- package/dist/runtime/task-context-service.d.ts +91 -0
- package/dist/runtime/task-context-service.d.ts.map +1 -0
- package/dist/runtime/task-context-service.js +122 -0
- package/dist/runtime/task-context-service.js.map +1 -0
- package/dist/runtime/thread-admission.d.ts +130 -0
- package/dist/runtime/thread-admission.d.ts.map +1 -0
- package/dist/runtime/thread-admission.js +276 -0
- package/dist/runtime/thread-admission.js.map +1 -0
- package/dist/runtime/thread-compact-persistence.d.ts +50 -0
- package/dist/runtime/thread-compact-persistence.d.ts.map +1 -0
- package/dist/runtime/thread-compact-persistence.js +176 -0
- package/dist/runtime/thread-compact-persistence.js.map +1 -0
- package/dist/runtime/thread-event-store.d.ts +98 -0
- package/dist/runtime/thread-event-store.d.ts.map +1 -0
- package/dist/runtime/thread-event-store.js +737 -0
- package/dist/runtime/thread-event-store.js.map +1 -0
- package/dist/runtime/thread-projection.d.ts +91 -0
- package/dist/runtime/thread-projection.d.ts.map +1 -0
- package/dist/runtime/thread-projection.js +407 -0
- package/dist/runtime/thread-projection.js.map +1 -0
- package/dist/runtime/thread-runtime.d.ts +165 -0
- package/dist/runtime/thread-runtime.d.ts.map +1 -0
- package/dist/runtime/thread-runtime.js +704 -0
- package/dist/runtime/thread-runtime.js.map +1 -0
- package/dist/runtime/thread-tool-journal.d.ts +11 -0
- package/dist/runtime/thread-tool-journal.d.ts.map +1 -0
- package/dist/runtime/thread-tool-journal.js +131 -0
- package/dist/runtime/thread-tool-journal.js.map +1 -0
- package/dist/runtime/thread-ui-adapter.d.ts +85 -0
- package/dist/runtime/thread-ui-adapter.d.ts.map +1 -0
- package/dist/runtime/thread-ui-adapter.js +514 -0
- package/dist/runtime/thread-ui-adapter.js.map +1 -0
- package/dist/runtime/tool-gateway.d.ts +159 -0
- package/dist/runtime/tool-gateway.d.ts.map +1 -0
- package/dist/runtime/tool-gateway.js +311 -0
- package/dist/runtime/tool-gateway.js.map +1 -0
- package/dist/runtime/turn-commit.d.ts +103 -0
- package/dist/runtime/turn-commit.d.ts.map +1 -0
- package/dist/runtime/turn-commit.js +321 -0
- package/dist/runtime/turn-commit.js.map +1 -0
- package/dist/runtime/ui-events.d.ts +15 -5
- package/dist/runtime/ui-events.d.ts.map +1 -1
- package/dist/runtime/ui-events.js +0 -1
- package/dist/runtime/ui-events.js.map +1 -1
- package/dist/runtime/ui-view-model.d.ts +1 -1
- package/dist/runtime/ui-view-model.d.ts.map +1 -1
- package/dist/runtime/ui-view-model.js +3 -5
- package/dist/runtime/ui-view-model.js.map +1 -1
- package/dist/services/compact/auto-compact.d.ts +82 -2
- package/dist/services/compact/auto-compact.d.ts.map +1 -1
- package/dist/services/compact/auto-compact.js +226 -44
- package/dist/services/compact/auto-compact.js.map +1 -1
- package/dist/services/compact/compact.d.ts +54 -37
- package/dist/services/compact/compact.d.ts.map +1 -1
- package/dist/services/compact/compact.js +512 -127
- package/dist/services/compact/compact.js.map +1 -1
- package/dist/services/compact/coordinator.d.ts +5 -1
- package/dist/services/compact/coordinator.d.ts.map +1 -1
- package/dist/services/compact/coordinator.js +10 -1
- package/dist/services/compact/coordinator.js.map +1 -1
- package/dist/services/compact/fingerprint.d.ts +27 -0
- package/dist/services/compact/fingerprint.d.ts.map +1 -0
- package/dist/services/compact/fingerprint.js +69 -0
- package/dist/services/compact/fingerprint.js.map +1 -0
- package/dist/services/compact/index.d.ts +7 -5
- package/dist/services/compact/index.d.ts.map +1 -1
- package/dist/services/compact/index.js +19 -6
- package/dist/services/compact/index.js.map +1 -1
- package/dist/services/compact/planner.d.ts +41 -0
- package/dist/services/compact/planner.d.ts.map +1 -0
- package/dist/services/compact/planner.js +102 -0
- package/dist/services/compact/planner.js.map +1 -0
- package/dist/services/compact/semantic-summary.d.ts +93 -0
- package/dist/services/compact/semantic-summary.d.ts.map +1 -0
- package/dist/services/compact/semantic-summary.js +158 -0
- package/dist/services/compact/semantic-summary.js.map +1 -0
- package/dist/services/compact/summary-generator.d.ts +23 -0
- package/dist/services/compact/summary-generator.d.ts.map +1 -1
- package/dist/services/compact/summary-generator.js +173 -39
- package/dist/services/compact/summary-generator.js.map +1 -1
- package/dist/services/config-dir.d.ts +1 -1
- package/dist/services/config-dir.d.ts.map +1 -1
- package/dist/services/config-dir.js +2 -1
- package/dist/services/config-dir.js.map +1 -1
- package/dist/services/config.d.ts +2 -16
- package/dist/services/config.d.ts.map +1 -1
- package/dist/services/config.js +2 -29
- package/dist/services/config.js.map +1 -1
- package/dist/services/doctor.d.ts +0 -2
- package/dist/services/doctor.d.ts.map +1 -1
- package/dist/services/doctor.js +39 -64
- package/dist/services/doctor.js.map +1 -1
- package/dist/services/file-context.d.ts.map +1 -1
- package/dist/services/file-context.js +29 -33
- package/dist/services/file-context.js.map +1 -1
- package/dist/services/global-config.d.ts +8 -2
- package/dist/services/global-config.d.ts.map +1 -1
- package/dist/services/global-config.js +8 -0
- package/dist/services/global-config.js.map +1 -1
- package/dist/services/llm.d.ts +3 -0
- package/dist/services/llm.d.ts.map +1 -1
- package/dist/services/llm.js +7 -0
- package/dist/services/llm.js.map +1 -1
- package/dist/services/project-instructions.d.ts.map +1 -1
- package/dist/services/project-instructions.js +10 -17
- package/dist/services/project-instructions.js.map +1 -1
- package/dist/services/safe-project-reader.d.ts +30 -0
- package/dist/services/safe-project-reader.d.ts.map +1 -0
- package/dist/services/safe-project-reader.js +141 -0
- package/dist/services/safe-project-reader.js.map +1 -0
- package/dist/services/session-storage.d.ts +134 -5
- package/dist/services/session-storage.d.ts.map +1 -1
- package/dist/services/session-storage.js +727 -57
- package/dist/services/session-storage.js.map +1 -1
- package/dist/services/usage-state.d.ts +7 -0
- package/dist/services/usage-state.d.ts.map +1 -1
- package/dist/services/usage-state.js +117 -16
- package/dist/services/usage-state.js.map +1 -1
- package/dist/skills/builtin/code-review/SKILL.md +51 -0
- package/dist/skills/builtin/security-check/SKILL.md +54 -0
- package/dist/skills/builtin/test-gen/SKILL.md +49 -0
- package/dist/terminal-ui/launch.d.ts +3 -1
- package/dist/terminal-ui/launch.d.ts.map +1 -1
- package/dist/terminal-ui/launch.js +19 -3
- package/dist/terminal-ui/launch.js.map +1 -1
- package/dist/tools/core/common.d.ts +34 -0
- package/dist/tools/core/common.d.ts.map +1 -0
- package/dist/tools/core/common.js +164 -0
- package/dist/tools/core/common.js.map +1 -0
- package/dist/tools/core/edit-file.d.ts +10 -0
- package/dist/tools/core/edit-file.d.ts.map +1 -0
- package/dist/tools/core/edit-file.js +301 -0
- package/dist/tools/core/edit-file.js.map +1 -0
- package/dist/tools/core/exec-command.d.ts +2 -0
- package/dist/tools/core/exec-command.d.ts.map +1 -0
- package/dist/tools/core/exec-command.js +347 -0
- package/dist/tools/core/exec-command.js.map +1 -0
- package/dist/tools/core/glob.d.ts +2 -0
- package/dist/tools/core/glob.d.ts.map +1 -0
- package/dist/tools/core/glob.js +133 -0
- package/dist/tools/core/glob.js.map +1 -0
- package/dist/tools/core/grep.d.ts +12 -0
- package/dist/tools/core/grep.d.ts.map +1 -0
- package/dist/tools/core/grep.js +223 -0
- package/dist/tools/core/grep.js.map +1 -0
- package/dist/tools/core/index.d.ts +15 -0
- package/dist/tools/core/index.d.ts.map +1 -0
- package/dist/tools/core/index.js +31 -0
- package/dist/tools/core/index.js.map +1 -0
- package/dist/tools/core/list-files.d.ts +2 -0
- package/dist/tools/core/list-files.d.ts.map +1 -0
- package/dist/tools/core/list-files.js +87 -0
- package/dist/tools/core/list-files.js.map +1 -0
- package/dist/tools/core/read-file.d.ts +2 -0
- package/dist/tools/core/read-file.d.ts.map +1 -0
- package/dist/tools/core/read-file.js +129 -0
- package/dist/tools/core/read-file.js.map +1 -0
- package/dist/tools/core/write-file.d.ts +2 -0
- package/dist/tools/core/write-file.d.ts.map +1 -0
- package/dist/tools/core/write-file.js +65 -0
- package/dist/tools/core/write-file.js.map +1 -0
- package/dist/tools/todo.d.ts +3 -4
- package/dist/tools/todo.d.ts.map +1 -1
- package/dist/tools/todo.js +80 -79
- package/dist/tools/todo.js.map +1 -1
- package/dist/tui-ui/chrome-view-model.js +1 -1
- package/dist/tui-ui/chrome-view-model.js.map +1 -1
- package/dist/tui-ui/layout.js +1 -1
- package/dist/tui-ui/layout.js.map +1 -1
- package/docs/migration/v0.1.9-to-v0.2.0.md +98 -0
- package/docs/orion.example.json +79 -0
- package/docs/plan/v0.2.0-dsh-harness-redesign-plan.md +1234 -0
- package/docs/plan/v0.2.0-release-checklist.md +91 -0
- package/docs/readme.md +27 -0
- package/npm-shrinkwrap.json +9 -438
- package/package.json +19 -11
- package/dist/agents/coder.d.ts +0 -12
- package/dist/agents/coder.d.ts.map +0 -1
- package/dist/agents/coder.js +0 -48
- package/dist/agents/coder.js.map +0 -1
- package/dist/agents/coordinator.d.ts +0 -86
- package/dist/agents/coordinator.d.ts.map +0 -1
- package/dist/agents/coordinator.js +0 -251
- package/dist/agents/coordinator.js.map +0 -1
- package/dist/agents/fork.d.ts +0 -69
- package/dist/agents/fork.d.ts.map +0 -1
- package/dist/agents/fork.js +0 -164
- package/dist/agents/fork.js.map +0 -1
- package/dist/agents/leader.d.ts +0 -12
- package/dist/agents/leader.d.ts.map +0 -1
- package/dist/agents/leader.js +0 -49
- package/dist/agents/leader.js.map +0 -1
- package/dist/agents/router.d.ts +0 -59
- package/dist/agents/router.d.ts.map +0 -1
- package/dist/agents/router.js +0 -193
- package/dist/agents/router.js.map +0 -1
- package/dist/agents/worker-pool.d.ts +0 -72
- package/dist/agents/worker-pool.d.ts.map +0 -1
- package/dist/agents/worker-pool.js +0 -224
- package/dist/agents/worker-pool.js.map +0 -1
- package/dist/commands/legacy-commands.d.ts +0 -4
- package/dist/commands/legacy-commands.d.ts.map +0 -1
- package/dist/commands/legacy-commands.js +0 -44
- package/dist/commands/legacy-commands.js.map +0 -1
- package/dist/core/agent.d.ts +0 -84
- package/dist/core/agent.d.ts.map +0 -1
- package/dist/core/agent.js +0 -58
- package/dist/core/agent.js.map +0 -1
- package/dist/core/brain.d.ts +0 -50
- package/dist/core/brain.d.ts.map +0 -1
- package/dist/core/brain.js +0 -95
- package/dist/core/brain.js.map +0 -1
- package/dist/framework/tool-scheduler.d.ts +0 -186
- package/dist/framework/tool-scheduler.d.ts.map +0 -1
- package/dist/framework/tool-scheduler.js +0 -558
- package/dist/framework/tool-scheduler.js.map +0 -1
- package/dist/harness/harness.d.ts +0 -58
- package/dist/harness/harness.d.ts.map +0 -1
- package/dist/harness/harness.js +0 -195
- package/dist/harness/harness.js.map +0 -1
- package/dist/harness/safety.d.ts +0 -101
- package/dist/harness/safety.d.ts.map +0 -1
- package/dist/harness/safety.js +0 -322
- package/dist/harness/safety.js.map +0 -1
- package/dist/init.d.ts +0 -108
- package/dist/init.d.ts.map +0 -1
- package/dist/init.js +0 -393
- package/dist/init.js.map +0 -1
- package/dist/ink-ui/App.d.ts +0 -9
- package/dist/ink-ui/App.d.ts.map +0 -1
- package/dist/ink-ui/App.js +0 -12
- package/dist/ink-ui/App.js.map +0 -1
- package/dist/ink-ui/components/Markdown.d.ts +0 -10
- package/dist/ink-ui/components/Markdown.d.ts.map +0 -1
- package/dist/ink-ui/components/Markdown.js +0 -210
- package/dist/ink-ui/components/Markdown.js.map +0 -1
- package/dist/ink-ui/components/NativeCursor.d.ts +0 -12
- package/dist/ink-ui/components/NativeCursor.d.ts.map +0 -1
- package/dist/ink-ui/components/NativeCursor.js +0 -35
- package/dist/ink-ui/components/NativeCursor.js.map +0 -1
- package/dist/ink-ui/components/PixelHorseBanner.d.ts +0 -8
- package/dist/ink-ui/components/PixelHorseBanner.d.ts.map +0 -1
- package/dist/ink-ui/components/PixelHorseBanner.js +0 -97
- package/dist/ink-ui/components/PixelHorseBanner.js.map +0 -1
- package/dist/ink-ui/components/PromptInput.d.ts +0 -13
- package/dist/ink-ui/components/PromptInput.d.ts.map +0 -1
- package/dist/ink-ui/components/PromptInput.js +0 -30
- package/dist/ink-ui/components/PromptInput.js.map +0 -1
- package/dist/ink-ui/components/RunningHorseIndicator.d.ts +0 -13
- package/dist/ink-ui/components/RunningHorseIndicator.d.ts.map +0 -1
- package/dist/ink-ui/components/RunningHorseIndicator.js +0 -53
- package/dist/ink-ui/components/RunningHorseIndicator.js.map +0 -1
- package/dist/ink-ui/components/SelectList.d.ts +0 -16
- package/dist/ink-ui/components/SelectList.d.ts.map +0 -1
- package/dist/ink-ui/components/SelectList.js +0 -60
- package/dist/ink-ui/components/SelectList.js.map +0 -1
- package/dist/ink-ui/components/StatusLine.d.ts +0 -11
- package/dist/ink-ui/components/StatusLine.d.ts.map +0 -1
- package/dist/ink-ui/components/StatusLine.js +0 -70
- package/dist/ink-ui/components/StatusLine.js.map +0 -1
- package/dist/ink-ui/components/ToolActivity.d.ts +0 -19
- package/dist/ink-ui/components/ToolActivity.d.ts.map +0 -1
- package/dist/ink-ui/components/ToolActivity.js +0 -134
- package/dist/ink-ui/components/ToolActivity.js.map +0 -1
- package/dist/ink-ui/components/Transcript.d.ts +0 -14
- package/dist/ink-ui/components/Transcript.d.ts.map +0 -1
- package/dist/ink-ui/components/Transcript.js +0 -66
- package/dist/ink-ui/components/Transcript.js.map +0 -1
- package/dist/ink-ui/controllers/chat-controller.d.ts +0 -2
- package/dist/ink-ui/controllers/chat-controller.d.ts.map +0 -1
- package/dist/ink-ui/controllers/chat-controller.js.map +0 -1
- package/dist/ink-ui/hooks/use-raw-input-bridge.d.ts +0 -6
- package/dist/ink-ui/hooks/use-raw-input-bridge.d.ts.map +0 -1
- package/dist/ink-ui/hooks/use-raw-input-bridge.js +0 -27
- package/dist/ink-ui/hooks/use-raw-input-bridge.js.map +0 -1
- package/dist/ink-ui/hooks/use-terminal-size.d.ts +0 -7
- package/dist/ink-ui/hooks/use-terminal-size.d.ts.map +0 -1
- package/dist/ink-ui/hooks/use-terminal-size.js +0 -34
- package/dist/ink-ui/hooks/use-terminal-size.js.map +0 -1
- package/dist/ink-ui/launch.d.ts +0 -9
- package/dist/ink-ui/launch.d.ts.map +0 -1
- package/dist/ink-ui/launch.js +0 -101
- package/dist/ink-ui/launch.js.map +0 -1
- package/dist/ink-ui/runtime/grapheme.d.ts +0 -10
- package/dist/ink-ui/runtime/grapheme.d.ts.map +0 -1
- package/dist/ink-ui/runtime/grapheme.js +0 -17
- package/dist/ink-ui/runtime/grapheme.js.map +0 -1
- package/dist/ink-ui/runtime/input-buffer.d.ts +0 -10
- package/dist/ink-ui/runtime/input-buffer.d.ts.map +0 -1
- package/dist/ink-ui/runtime/input-buffer.js +0 -18
- package/dist/ink-ui/runtime/input-buffer.js.map +0 -1
- package/dist/ink-ui/runtime/layout-budget.d.ts +0 -13
- package/dist/ink-ui/runtime/layout-budget.d.ts.map +0 -1
- package/dist/ink-ui/runtime/layout-budget.js +0 -25
- package/dist/ink-ui/runtime/layout-budget.js.map +0 -1
- package/dist/ink-ui/runtime/native-cursor.d.ts +0 -62
- package/dist/ink-ui/runtime/native-cursor.d.ts.map +0 -1
- package/dist/ink-ui/runtime/native-cursor.js +0 -398
- package/dist/ink-ui/runtime/native-cursor.js.map +0 -1
- package/dist/ink-ui/runtime/prompt-layout.d.ts +0 -10
- package/dist/ink-ui/runtime/prompt-layout.d.ts.map +0 -1
- package/dist/ink-ui/runtime/prompt-layout.js +0 -21
- package/dist/ink-ui/runtime/prompt-layout.js.map +0 -1
- package/dist/ink-ui/runtime/raw-input.d.ts +0 -4
- package/dist/ink-ui/runtime/raw-input.d.ts.map +0 -1
- package/dist/ink-ui/runtime/raw-input.js +0 -15
- package/dist/ink-ui/runtime/raw-input.js.map +0 -1
- package/dist/ink-ui/runtime/transcript-state.d.ts +0 -37
- package/dist/ink-ui/runtime/transcript-state.d.ts.map +0 -1
- package/dist/ink-ui/runtime/transcript-state.js +0 -91
- package/dist/ink-ui/runtime/transcript-state.js.map +0 -1
- package/dist/ink-ui/screens/ReplScreen.d.ts +0 -24
- package/dist/ink-ui/screens/ReplScreen.d.ts.map +0 -1
- package/dist/ink-ui/screens/ReplScreen.js +0 -756
- package/dist/ink-ui/screens/ReplScreen.js.map +0 -1
- package/dist/ink-ui/types.d.ts +0 -2
- package/dist/ink-ui/types.d.ts.map +0 -1
- package/dist/ink-ui/types.js.map +0 -1
- package/dist/runtime/chat-checkpoint.d.ts +0 -17
- package/dist/runtime/chat-checkpoint.d.ts.map +0 -1
- package/dist/runtime/chat-checkpoint.js +0 -105
- package/dist/runtime/chat-checkpoint.js.map +0 -1
- package/dist/runtime/chat-command-scope.d.ts +0 -5
- package/dist/runtime/chat-command-scope.d.ts.map +0 -1
- package/dist/runtime/chat-command-scope.js +0 -22
- package/dist/runtime/chat-command-scope.js.map +0 -1
- package/dist/runtime/chat-controller.d.ts +0 -62
- package/dist/runtime/chat-controller.d.ts.map +0 -1
- package/dist/runtime/chat-controller.js +0 -1630
- package/dist/runtime/chat-controller.js.map +0 -1
- package/dist/runtime/chat-effort.d.ts +0 -5
- package/dist/runtime/chat-effort.d.ts.map +0 -1
- package/dist/runtime/chat-effort.js +0 -47
- package/dist/runtime/chat-effort.js.map +0 -1
- package/dist/runtime/chat-presentation.d.ts +0 -63
- package/dist/runtime/chat-presentation.d.ts.map +0 -1
- package/dist/runtime/chat-presentation.js +0 -561
- package/dist/runtime/chat-presentation.js.map +0 -1
- package/dist/runtime/chat-trace.d.ts +0 -52
- package/dist/runtime/chat-trace.d.ts.map +0 -1
- package/dist/runtime/chat-trace.js +0 -234
- package/dist/runtime/chat-trace.js.map +0 -1
- package/dist/runtime/chat-workspace.d.ts +0 -22
- package/dist/runtime/chat-workspace.d.ts.map +0 -1
- package/dist/runtime/chat-workspace.js +0 -154
- package/dist/runtime/chat-workspace.js.map +0 -1
- package/dist/runtime/goals/accounting.d.ts +0 -45
- package/dist/runtime/goals/accounting.d.ts.map +0 -1
- package/dist/runtime/goals/accounting.js +0 -114
- package/dist/runtime/goals/accounting.js.map +0 -1
- package/dist/runtime/goals/coordinator.d.ts +0 -89
- package/dist/runtime/goals/coordinator.d.ts.map +0 -1
- package/dist/runtime/goals/coordinator.js +0 -1481
- package/dist/runtime/goals/coordinator.js.map +0 -1
- package/dist/runtime/goals/lifecycle.d.ts +0 -13
- package/dist/runtime/goals/lifecycle.d.ts.map +0 -1
- package/dist/runtime/goals/lifecycle.js +0 -46
- package/dist/runtime/goals/lifecycle.js.map +0 -1
- package/dist/runtime/goals/prompt.d.ts +0 -16
- package/dist/runtime/goals/prompt.d.ts.map +0 -1
- package/dist/runtime/goals/prompt.js +0 -88
- package/dist/runtime/goals/prompt.js.map +0 -1
- package/dist/runtime/goals/tools.d.ts +0 -61
- package/dist/runtime/goals/tools.d.ts.map +0 -1
- package/dist/runtime/goals/tools.js +0 -568
- package/dist/runtime/goals/tools.js.map +0 -1
- package/dist/sdk/index.d.ts +0 -10
- package/dist/sdk/index.d.ts.map +0 -1
- package/dist/sdk/index.js +0 -23
- package/dist/sdk/index.js.map +0 -1
- package/dist/sdk/init.d.ts +0 -24
- package/dist/sdk/init.d.ts.map +0 -1
- package/dist/sdk/init.js +0 -48
- package/dist/sdk/init.js.map +0 -1
- package/dist/sdk/query.d.ts +0 -19
- package/dist/sdk/query.d.ts.map +0 -1
- package/dist/sdk/query.js +0 -42
- package/dist/sdk/query.js.map +0 -1
- package/dist/sdk/sessions.d.ts +0 -19
- package/dist/sdk/sessions.d.ts.map +0 -1
- package/dist/sdk/sessions.js +0 -57
- package/dist/sdk/sessions.js.map +0 -1
- package/dist/sdk/types.d.ts +0 -47
- package/dist/sdk/types.d.ts.map +0 -1
- package/dist/sdk/types.js +0 -8
- package/dist/sdk/types.js.map +0 -1
- package/dist/services/agent-runner.d.ts +0 -71
- package/dist/services/agent-runner.d.ts.map +0 -1
- package/dist/services/agent-runner.js +0 -185
- package/dist/services/agent-runner.js.map +0 -1
- package/dist/services/compact/micro-compact.d.ts +0 -21
- package/dist/services/compact/micro-compact.d.ts.map +0 -1
- package/dist/services/compact/micro-compact.js +0 -99
- package/dist/services/compact/micro-compact.js.map +0 -1
- package/dist/services/task-manager.d.ts +0 -161
- package/dist/services/task-manager.d.ts.map +0 -1
- package/dist/services/task-manager.js +0 -315
- package/dist/services/task-manager.js.map +0 -1
- package/dist/skills/discovery.d.ts +0 -22
- package/dist/skills/discovery.d.ts.map +0 -1
- package/dist/skills/discovery.js +0 -75
- package/dist/skills/discovery.js.map +0 -1
- package/dist/skills/index.d.ts +0 -11
- package/dist/skills/index.d.ts.map +0 -1
- package/dist/skills/index.js.map +0 -1
- package/dist/skills/loader.d.ts +0 -53
- package/dist/skills/loader.d.ts.map +0 -1
- package/dist/skills/loader.js +0 -421
- package/dist/skills/loader.js.map +0 -1
- package/dist/skills/registry.d.ts +0 -41
- package/dist/skills/registry.d.ts.map +0 -1
- package/dist/skills/registry.js +0 -157
- package/dist/skills/registry.js.map +0 -1
- package/dist/skills/runtime.d.ts +0 -46
- package/dist/skills/runtime.d.ts.map +0 -1
- package/dist/skills/runtime.js +0 -364
- package/dist/skills/runtime.js.map +0 -1
- package/dist/skills/types.d.ts +0 -112
- package/dist/skills/types.d.ts.map +0 -1
- package/dist/skills/types.js +0 -24
- package/dist/skills/types.js.map +0 -1
- package/dist/tools/index.d.ts +0 -52
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js +0 -2268
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/mcp.d.ts +0 -99
- package/dist/tools/mcp.d.ts.map +0 -1
- package/dist/tools/mcp.js +0 -695
- package/dist/tools/mcp.js.map +0 -1
- package/dist/tools/plan.d.ts +0 -17
- package/dist/tools/plan.d.ts.map +0 -1
- package/dist/tools/plan.js +0 -84
- package/dist/tools/plan.js.map +0 -1
|
@@ -1,1481 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* v0.2.24 — Goal Coordinator.
|
|
4
|
-
*
|
|
5
|
-
* Single-flight state machine that manages goal lifecycle: creation,
|
|
6
|
-
* pause/resume, auto-continuation, completion/blocked audit, and
|
|
7
|
-
* persistence. Owned by AgentRuntimeController — NOT a global singleton.
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.GoalCoordinator = void 0;
|
|
11
|
-
exports.goalRequiresBoundaryConfirmation = goalRequiresBoundaryConfirmation;
|
|
12
|
-
const crypto_1 = require("crypto");
|
|
13
|
-
const fs_1 = require("fs");
|
|
14
|
-
const path_1 = require("path");
|
|
15
|
-
const types_1 = require("./types");
|
|
16
|
-
const goal_storage_1 = require("../../services/goal-storage");
|
|
17
|
-
const accounting_1 = require("./accounting");
|
|
18
|
-
const completion_audit_1 = require("./completion-audit");
|
|
19
|
-
const redaction_1 = require("../../services/redaction");
|
|
20
|
-
const config_dir_1 = require("../../services/config-dir");
|
|
21
|
-
const objective_1 = require("./objective");
|
|
22
|
-
const MAX_EVIDENCE_LEDGER_RECORDS = 500;
|
|
23
|
-
const MAX_EVIDENCE_TRUNCATION_COUNT = 1000000000;
|
|
24
|
-
function addSafeInteger(value, increment, field) {
|
|
25
|
-
if (!Number.isSafeInteger(value) ||
|
|
26
|
-
value < 0 ||
|
|
27
|
-
!Number.isSafeInteger(increment) ||
|
|
28
|
-
increment < 0 ||
|
|
29
|
-
value > Number.MAX_SAFE_INTEGER - increment) {
|
|
30
|
-
throw new RangeError(`${field} would exceed the non-negative safe integer range`);
|
|
31
|
-
}
|
|
32
|
-
return value + increment;
|
|
33
|
-
}
|
|
34
|
-
function boundedTruncationCount(current, increment) {
|
|
35
|
-
return Math.min(MAX_EVIDENCE_TRUNCATION_COUNT, current + increment);
|
|
36
|
-
}
|
|
37
|
-
function appendBoundedEvidence(existing, incoming, objectiveRevision, previousTruncation) {
|
|
38
|
-
const all = [...existing, ...incoming];
|
|
39
|
-
const carried = previousTruncation?.objectiveRevision === objectiveRevision ? previousTruncation : undefined;
|
|
40
|
-
if (all.length <= MAX_EVIDENCE_LEDGER_RECORDS) {
|
|
41
|
-
return { ledger: all, truncation: carried };
|
|
42
|
-
}
|
|
43
|
-
const retained = new Set();
|
|
44
|
-
const retainNewest = (records) => {
|
|
45
|
-
for (let index = records.length - 1; index >= 0; index -= 1) {
|
|
46
|
-
if (retained.size >= MAX_EVIDENCE_LEDGER_RECORDS)
|
|
47
|
-
return;
|
|
48
|
-
retained.add(records[index]);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
// Negative evidence for the current objective epoch is safety-critical. Keep
|
|
52
|
-
// it ahead of passing and old-epoch records; if more than the entire bounded
|
|
53
|
-
// ledger is negative, the truncation summary below makes completion fail
|
|
54
|
-
// closed even after later passing evidence arrives.
|
|
55
|
-
retainNewest(all.filter(record => record.objectiveRevision === objectiveRevision && record.result !== 'passed'));
|
|
56
|
-
retainNewest(all.filter(record => record.objectiveRevision === objectiveRevision));
|
|
57
|
-
retainNewest(all);
|
|
58
|
-
const ledger = all.filter(record => retained.has(record));
|
|
59
|
-
const dropped = all.filter(record => record.objectiveRevision === objectiveRevision && !retained.has(record));
|
|
60
|
-
if (dropped.length === 0)
|
|
61
|
-
return { ledger, truncation: carried };
|
|
62
|
-
const increment = (result) => dropped.filter(record => record.result === result).length;
|
|
63
|
-
return {
|
|
64
|
-
ledger,
|
|
65
|
-
truncation: {
|
|
66
|
-
objectiveRevision,
|
|
67
|
-
droppedPassed: boundedTruncationCount(carried?.droppedPassed ?? 0, increment('passed')),
|
|
68
|
-
droppedFailed: boundedTruncationCount(carried?.droppedFailed ?? 0, increment('failed')),
|
|
69
|
-
droppedInconclusive: boundedTruncationCount(carried?.droppedInconclusive ?? 0, increment('inconclusive')),
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
function finalEvidenceReceipt(record) {
|
|
74
|
-
return {
|
|
75
|
-
evidenceId: record.id,
|
|
76
|
-
kind: record.kind,
|
|
77
|
-
provenance: record.kind === 'user'
|
|
78
|
-
? 'user_acceptance'
|
|
79
|
-
: record.kind === 'external'
|
|
80
|
-
? 'external'
|
|
81
|
-
: 'runtime_automatic',
|
|
82
|
-
result: record.result,
|
|
83
|
-
subject: record.subject,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
function noProgressTurnSummary(outcome) {
|
|
87
|
-
const evidence = outcome.evidenceRecords ?? [];
|
|
88
|
-
return {
|
|
89
|
-
turnId: (0, redaction_1.redactTraceText)(String(outcome.turnId)).slice(0, 80),
|
|
90
|
-
endedAt: outcome.endedAt,
|
|
91
|
-
finishReason: (0, redaction_1.redactTraceText)(outcome.finishReason).slice(0, 80),
|
|
92
|
-
passedEvidence: evidence.filter(record => record.result === 'passed').length,
|
|
93
|
-
failedEvidence: evidence.filter(record => record.result === 'failed').length,
|
|
94
|
-
inconclusiveEvidence: evidence.filter(record => record.result === 'inconclusive').length,
|
|
95
|
-
planUpdateProposed: Boolean(outcome.pendingPlanUpdate),
|
|
96
|
-
blockerCategory: outcome.blocker?.category,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
function formatNoProgressTurns(turns) {
|
|
100
|
-
return turns
|
|
101
|
-
.map(turn => `${turn.turnId} finish=${turn.finishReason} evidence=${turn.passedEvidence}p/${turn.failedEvidence}f/${turn.inconclusiveEvidence}i plan=${turn.planUpdateProposed ? 'no-change' : 'none'}${turn.blockerCategory ? ` blocker=${turn.blockerCategory}` : ''}`)
|
|
102
|
-
.join('; ');
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Build a minimal pending contract from an objective string. Used at creation
|
|
106
|
-
* and at load time to normalize v0.1.1 sidecars (which have no contract).
|
|
107
|
-
*
|
|
108
|
-
* The primary criterion is `source=user` because it is the user's verbatim
|
|
109
|
-
* objective, with a stable id so repeated
|
|
110
|
-
* normalizations of the same goal produce the same id (no churn on reload).
|
|
111
|
-
* User-supplied criteria (`source=user`) are added via a separate path.
|
|
112
|
-
*/
|
|
113
|
-
function minimalContract(objective, now, originalObjective = objective, completionAction) {
|
|
114
|
-
return {
|
|
115
|
-
originalObjective,
|
|
116
|
-
objectiveRevision: 0,
|
|
117
|
-
...(completionAction ? { completionAction } : {}),
|
|
118
|
-
constraints: [],
|
|
119
|
-
successCriteria: [
|
|
120
|
-
{
|
|
121
|
-
id: 'criterion:primary',
|
|
122
|
-
statement: objective,
|
|
123
|
-
source: 'user',
|
|
124
|
-
status: 'pending',
|
|
125
|
-
// External completion actions cannot be proven by local process output.
|
|
126
|
-
// Other primary criteria accept local runtime evidence; model natural
|
|
127
|
-
// language is never an accepted kind.
|
|
128
|
-
requiredEvidenceKinds: (0, completion_audit_1.criterionRequiresExternalCompletionEvidence)(objective)
|
|
129
|
-
? ['external', 'user']
|
|
130
|
-
: ['test', 'build', 'file', 'runtime'],
|
|
131
|
-
evidenceRefs: [],
|
|
132
|
-
},
|
|
133
|
-
],
|
|
134
|
-
planSnapshot: {
|
|
135
|
-
revision: 0,
|
|
136
|
-
phase: 'initial',
|
|
137
|
-
steps: [],
|
|
138
|
-
updatedAt: now,
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
const CONTRACT_EVIDENCE_KINDS = new Set([
|
|
143
|
-
'test',
|
|
144
|
-
'build',
|
|
145
|
-
'lint',
|
|
146
|
-
'file',
|
|
147
|
-
'runtime',
|
|
148
|
-
'external',
|
|
149
|
-
'user',
|
|
150
|
-
]);
|
|
151
|
-
const BOUNDARY_CONFIRMATION_PATTERN = /\b(publish|deploy|delete|erase|remove|drop|migrate|send|email|message|post|pay|purchase|merge|push|tag|overwrite|destroy|revoke|transfer|upload)\b|发布|部署|删除|清空|迁移|发送|付款|购买|合并|推送|打标签|覆盖|销毁|撤销|转账|上传/i;
|
|
152
|
-
/** High-impact external or destructive goals must not auto-start from model-created text. */
|
|
153
|
-
function goalRequiresBoundaryConfirmation(objective, input = {}) {
|
|
154
|
-
return [
|
|
155
|
-
objective,
|
|
156
|
-
...(input.constraints ?? []),
|
|
157
|
-
...(input.successCriteria ?? []).map(criterion => criterion.statement),
|
|
158
|
-
].some(statement => (0, completion_audit_1.hasUnnegatedActionMatch)(statement, BOUNDARY_CONFIRMATION_PATTERN));
|
|
159
|
-
}
|
|
160
|
-
function boundaryConfirmationState(objectiveRevision, now) {
|
|
161
|
-
return {
|
|
162
|
-
status: 'paused',
|
|
163
|
-
stopReason: {
|
|
164
|
-
kind: 'user',
|
|
165
|
-
message: 'Boundary confirmation required for an external, destructive, or high-impact Goal. Review the objective and constraints, then use /target resume to confirm.',
|
|
166
|
-
at: now,
|
|
167
|
-
},
|
|
168
|
-
boundaryConfirmation: {
|
|
169
|
-
requiredAt: now,
|
|
170
|
-
reason: 'external_destructive_or_high_impact',
|
|
171
|
-
objectiveRevision,
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function pauseForBoundaryConfirmation(goal, now) {
|
|
176
|
-
return {
|
|
177
|
-
...goal,
|
|
178
|
-
...boundaryConfirmationState(goal.contract?.objectiveRevision ?? 0, now),
|
|
179
|
-
updatedAt: now,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
function creationContract(objective, now, input, originalObjective = objective, completionAction) {
|
|
183
|
-
const constraints = input.constraints ?? [];
|
|
184
|
-
const successCriteria = input.successCriteria ?? [];
|
|
185
|
-
if (constraints.length > 50 || successCriteria.length > 50)
|
|
186
|
-
return null;
|
|
187
|
-
if (constraints.some(statement => !statement.trim()) ||
|
|
188
|
-
successCriteria.some(criterion => !criterion.statement.trim() ||
|
|
189
|
-
criterion.requiredEvidenceKinds.length === 0 ||
|
|
190
|
-
criterion.requiredEvidenceKinds.some(kind => !CONTRACT_EVIDENCE_KINDS.has(kind)))) {
|
|
191
|
-
return null;
|
|
192
|
-
}
|
|
193
|
-
const contract = minimalContract(objective, now, originalObjective, completionAction);
|
|
194
|
-
contract.constraints = constraints.map((statement, index) => ({
|
|
195
|
-
id: `constraint:user:${index + 1}`,
|
|
196
|
-
statement: statement.trim(),
|
|
197
|
-
source: 'user',
|
|
198
|
-
}));
|
|
199
|
-
contract.successCriteria.push(...successCriteria.map((criterion, index) => ({
|
|
200
|
-
id: `criterion:user:${index + 1}`,
|
|
201
|
-
statement: criterion.statement.trim(),
|
|
202
|
-
source: 'user',
|
|
203
|
-
status: 'pending',
|
|
204
|
-
requiredEvidenceKinds: [...new Set(criterion.requiredEvidenceKinds)],
|
|
205
|
-
evidenceRefs: [],
|
|
206
|
-
})));
|
|
207
|
-
return contract;
|
|
208
|
-
}
|
|
209
|
-
function compactPlanValue(value) {
|
|
210
|
-
const compact = value?.replace(/\s+/gu, ' ').trim();
|
|
211
|
-
return compact || undefined;
|
|
212
|
-
}
|
|
213
|
-
function stablePlanStepKey(value) {
|
|
214
|
-
return value
|
|
215
|
-
.normalize('NFKC')
|
|
216
|
-
.toLowerCase()
|
|
217
|
-
.replace(/[^\p{L}\p{N}]+/gu, ' ')
|
|
218
|
-
.trim()
|
|
219
|
-
.replace(/\s+/gu, ' ');
|
|
220
|
-
}
|
|
221
|
-
const OBJECTIVE_TRACE_STOP_WORDS = new Set([
|
|
222
|
-
'add',
|
|
223
|
-
'build',
|
|
224
|
-
'check',
|
|
225
|
-
'code',
|
|
226
|
-
'complete',
|
|
227
|
-
'create',
|
|
228
|
-
'goal',
|
|
229
|
-
'implement',
|
|
230
|
-
'pass',
|
|
231
|
-
'run',
|
|
232
|
-
'test',
|
|
233
|
-
'update',
|
|
234
|
-
'verify',
|
|
235
|
-
]);
|
|
236
|
-
function objectiveTraceTokens(value) {
|
|
237
|
-
const tokens = new Set();
|
|
238
|
-
for (const raw of value
|
|
239
|
-
.normalize('NFKC')
|
|
240
|
-
.toLowerCase()
|
|
241
|
-
.match(/[\p{L}\p{N}_-]+/gu) ?? []) {
|
|
242
|
-
if (raw.length >= 3 && !OBJECTIVE_TRACE_STOP_WORDS.has(raw))
|
|
243
|
-
tokens.add(raw);
|
|
244
|
-
if (/\p{Script=Han}/u.test(raw)) {
|
|
245
|
-
const characters = Array.from(raw);
|
|
246
|
-
for (let index = 0; index < characters.length - 1; index += 1) {
|
|
247
|
-
tokens.add(`${characters[index]}${characters[index + 1]}`);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return tokens;
|
|
252
|
-
}
|
|
253
|
-
function criterionTracesToObjective(statement, contract) {
|
|
254
|
-
const objectiveTokens = objectiveTraceTokens(contract.originalObjective);
|
|
255
|
-
if (objectiveTokens.size === 0)
|
|
256
|
-
return false;
|
|
257
|
-
const criterionTokens = objectiveTraceTokens(statement);
|
|
258
|
-
return [...criterionTokens].some(token => objectiveTokens.has(token));
|
|
259
|
-
}
|
|
260
|
-
function substantivePlanProgress(contract, update, derivedCriteria) {
|
|
261
|
-
const current = contract.planSnapshot;
|
|
262
|
-
const completedStableStep = Boolean(current?.steps.some(step => {
|
|
263
|
-
if (step.done)
|
|
264
|
-
return false;
|
|
265
|
-
const key = stablePlanStepKey(step.description);
|
|
266
|
-
return Boolean(key && update.steps.some(next => next.done && stablePlanStepKey(next.description) === key));
|
|
267
|
-
}));
|
|
268
|
-
const traceableCriterionAdded = derivedCriteria.some(criterion => criterionTracesToObjective(criterion.statement, contract));
|
|
269
|
-
return completedStableStep || traceableCriterionAdded;
|
|
270
|
-
}
|
|
271
|
-
function stableEvidenceSource(sourceRef) {
|
|
272
|
-
const tool = /^tool:[^:]+:(.+)$/iu.exec(sourceRef.trim());
|
|
273
|
-
return compactPlanValue(tool ? `tool:${tool[1]}` : sourceRef)?.toLowerCase() ?? 'unknown';
|
|
274
|
-
}
|
|
275
|
-
function normalizedEvidenceSubject(subject) {
|
|
276
|
-
return (0, redaction_1.redactTraceText)(subject)
|
|
277
|
-
.normalize('NFKC')
|
|
278
|
-
.toLowerCase()
|
|
279
|
-
.replace(/[^\p{L}\p{N}_-]+/gu, ' ')
|
|
280
|
-
.trim()
|
|
281
|
-
.replace(/\s+/gu, ' ');
|
|
282
|
-
}
|
|
283
|
-
function evidenceProgressKeys(incoming, contract) {
|
|
284
|
-
const keys = new Set();
|
|
285
|
-
for (const record of incoming) {
|
|
286
|
-
if (record.result !== 'passed')
|
|
287
|
-
continue;
|
|
288
|
-
const stableSource = stableEvidenceSource(record.sourceRef);
|
|
289
|
-
const normalizedSubject = normalizedEvidenceSubject(record.subject);
|
|
290
|
-
const evidenceTokens = objectiveTraceTokens(`${normalizedSubject} ${stableSource}`);
|
|
291
|
-
for (const criterion of contract.successCriteria) {
|
|
292
|
-
if (!criterion.requiredEvidenceKinds.includes(record.kind))
|
|
293
|
-
continue;
|
|
294
|
-
const directCriterionReference = normalizedSubject.includes(criterion.id.toLowerCase()) ||
|
|
295
|
-
stableSource.includes(criterion.id.toLowerCase());
|
|
296
|
-
const criterionTokens = objectiveTraceTokens(criterion.statement);
|
|
297
|
-
const semanticallyRelated = [...criterionTokens].some(token => evidenceTokens.has(token));
|
|
298
|
-
if (!directCriterionReference && !semanticallyRelated)
|
|
299
|
-
continue;
|
|
300
|
-
const materialIdentity = [
|
|
301
|
-
record.objectiveRevision,
|
|
302
|
-
criterion.id,
|
|
303
|
-
record.kind,
|
|
304
|
-
stableSource,
|
|
305
|
-
normalizedSubject,
|
|
306
|
-
record.workspaceFingerprint ?? 'workspace:none',
|
|
307
|
-
].join('\u0000');
|
|
308
|
-
keys.add((0, crypto_1.createHash)('sha256').update(materialIdentity).digest('hex'));
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return [...keys];
|
|
312
|
-
}
|
|
313
|
-
function criterionStateAdvanced(before, after, evidenceLedger) {
|
|
314
|
-
if (!after)
|
|
315
|
-
return false;
|
|
316
|
-
const passedEvidence = new Set(evidenceLedger.filter(record => record.result === 'passed').map(record => record.id));
|
|
317
|
-
const priorById = new Map(before.successCriteria.map(criterion => [criterion.id, criterion]));
|
|
318
|
-
return after.successCriteria.some(criterion => {
|
|
319
|
-
const prior = priorById.get(criterion.id);
|
|
320
|
-
if (!prior)
|
|
321
|
-
return false;
|
|
322
|
-
if (prior.status !== 'passed' && criterion.status === 'passed')
|
|
323
|
-
return true;
|
|
324
|
-
const priorRefs = new Set(prior.evidenceRefs);
|
|
325
|
-
return criterion.evidenceRefs.some(ref => !priorRefs.has(ref) && passedEvidence.has(ref));
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
function planContentChanged(contract, update) {
|
|
329
|
-
const current = contract.planSnapshot;
|
|
330
|
-
if (!current)
|
|
331
|
-
return true;
|
|
332
|
-
if (compactPlanValue(current.phase) !== compactPlanValue(update.phase))
|
|
333
|
-
return true;
|
|
334
|
-
if (compactPlanValue(current.nextAction) !== compactPlanValue(update.nextAction))
|
|
335
|
-
return true;
|
|
336
|
-
if (current.steps.length !== update.steps.length)
|
|
337
|
-
return true;
|
|
338
|
-
return current.steps.some((step, index) => {
|
|
339
|
-
const next = update.steps[index];
|
|
340
|
-
return (compactPlanValue(step.description) !== compactPlanValue(next.description) ||
|
|
341
|
-
step.done !== next.done);
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
function newDerivedCriteria(contract, update, planRevision) {
|
|
345
|
-
const existingStatements = new Set(contract.successCriteria.map(criterion => criterion.statement.trim().toLowerCase()));
|
|
346
|
-
return update.derivedCriteria
|
|
347
|
-
.filter(item => !existingStatements.has(item.statement.trim().toLowerCase()))
|
|
348
|
-
.map((item, index) => ({
|
|
349
|
-
id: `criterion:derived:${planRevision}:${index + 1}`,
|
|
350
|
-
statement: item.statement,
|
|
351
|
-
source: 'derived',
|
|
352
|
-
status: 'pending',
|
|
353
|
-
requiredEvidenceKinds: item.requiredEvidenceKinds,
|
|
354
|
-
evidenceRefs: [],
|
|
355
|
-
}));
|
|
356
|
-
}
|
|
357
|
-
/** Ensure a loaded goal carries a contract; normalize v0.1.1 sidecars. */
|
|
358
|
-
function ensureContract(goal) {
|
|
359
|
-
const normalized = (0, objective_1.normalizeGoalObjective)(goal.objective);
|
|
360
|
-
const shouldMigrateExitAction = normalized.completionAction === 'exit_goal' &&
|
|
361
|
-
Boolean(normalized.objective) &&
|
|
362
|
-
goal.status !== 'complete';
|
|
363
|
-
if (goal.contract && shouldMigrateExitAction) {
|
|
364
|
-
const failedAudit = goal.completionAudit?.passed === false;
|
|
365
|
-
const normalizedContract = {
|
|
366
|
-
...goal.contract,
|
|
367
|
-
completionAction: 'exit_goal',
|
|
368
|
-
successCriteria: goal.contract.successCriteria.map(criterion => criterion.id === 'criterion:primary'
|
|
369
|
-
? {
|
|
370
|
-
...criterion,
|
|
371
|
-
statement: normalized.objective,
|
|
372
|
-
...(failedAudit ? { status: 'pending' } : {}),
|
|
373
|
-
}
|
|
374
|
-
: criterion),
|
|
375
|
-
...(failedAudit && goal.contract.planSnapshot
|
|
376
|
-
? {
|
|
377
|
-
planSnapshot: {
|
|
378
|
-
...goal.contract.planSnapshot,
|
|
379
|
-
phase: 'execution',
|
|
380
|
-
nextAction: `Verify and complete: ${normalized.objective}`,
|
|
381
|
-
},
|
|
382
|
-
}
|
|
383
|
-
: {}),
|
|
384
|
-
};
|
|
385
|
-
return {
|
|
386
|
-
...goal,
|
|
387
|
-
objective: normalized.objective,
|
|
388
|
-
contract: normalizedContract,
|
|
389
|
-
completionAudit: failedAudit ? undefined : goal.completionAudit,
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
if (goal.contract)
|
|
393
|
-
return goal;
|
|
394
|
-
const objective = shouldMigrateExitAction ? normalized.objective : goal.objective;
|
|
395
|
-
const contract = minimalContract(objective, goal.updatedAt || goal.createdAt, shouldMigrateExitAction ? normalized.originalObjective : objective, shouldMigrateExitAction ? normalized.completionAction : undefined);
|
|
396
|
-
const normalizedLegacy = {
|
|
397
|
-
...goal,
|
|
398
|
-
objective,
|
|
399
|
-
contract,
|
|
400
|
-
completedAt: undefined,
|
|
401
|
-
completionAudit: undefined,
|
|
402
|
-
};
|
|
403
|
-
if (goal.status === 'active') {
|
|
404
|
-
return {
|
|
405
|
-
...normalizedLegacy,
|
|
406
|
-
blocker: undefined,
|
|
407
|
-
stopReason: undefined,
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
if (goal.status === 'blocked' && (!goal.blocker || goal.stopReason?.kind !== 'blocked')) {
|
|
411
|
-
return {
|
|
412
|
-
...normalizedLegacy,
|
|
413
|
-
status: 'paused',
|
|
414
|
-
blocker: undefined,
|
|
415
|
-
stopReason: {
|
|
416
|
-
kind: 'user',
|
|
417
|
-
message: 'Legacy blocked state requires v0.1.2 blocker re-verification.',
|
|
418
|
-
at: Date.now(),
|
|
419
|
-
},
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
if (goal.status !== 'complete')
|
|
423
|
-
return normalizedLegacy;
|
|
424
|
-
const now = Date.now();
|
|
425
|
-
return {
|
|
426
|
-
...normalizedLegacy,
|
|
427
|
-
status: 'paused',
|
|
428
|
-
stopReason: {
|
|
429
|
-
kind: 'user',
|
|
430
|
-
message: 'Legacy completion requires v0.1.2 evidence re-verification.',
|
|
431
|
-
at: now,
|
|
432
|
-
},
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
|
-
class GoalCoordinator {
|
|
436
|
-
constructor(projectPath, sessionId) {
|
|
437
|
-
this.projectPath = projectPath;
|
|
438
|
-
this.sessionId = sessionId;
|
|
439
|
-
this.state = { goal: null, generation: 0, continuationDeferred: false };
|
|
440
|
-
this.loadIssue = null;
|
|
441
|
-
/** A failed reload requires storage recovery before a fresh Goal may be written. */
|
|
442
|
-
this.loadRecoveryRequired = false;
|
|
443
|
-
/** Runtime-only dedupe for interrupted stale turns; in-flight turns do not survive restart. */
|
|
444
|
-
this.accountedStaleTurnKeys = new Set();
|
|
445
|
-
/** Last disk-authoritative state, used when both a write and recovery read fail. */
|
|
446
|
-
this.persistedGoalSnapshot = null;
|
|
447
|
-
}
|
|
448
|
-
// ==========================================================================
|
|
449
|
-
// Queries
|
|
450
|
-
// ==========================================================================
|
|
451
|
-
get goal() {
|
|
452
|
-
return this.state.goal;
|
|
453
|
-
}
|
|
454
|
-
get generation() {
|
|
455
|
-
return this.state.generation;
|
|
456
|
-
}
|
|
457
|
-
get boundSessionId() {
|
|
458
|
-
return this.sessionId;
|
|
459
|
-
}
|
|
460
|
-
get isActive() {
|
|
461
|
-
return this.state.goal?.status === 'active';
|
|
462
|
-
}
|
|
463
|
-
get canContinue() {
|
|
464
|
-
return (this.isActive &&
|
|
465
|
-
!this.state.continuationDeferred &&
|
|
466
|
-
(this.state.goal.automaticContinuationStreak ?? 0) <
|
|
467
|
-
types_1.GOAL_INVARIANTS.maxAutomaticContinuationTurns &&
|
|
468
|
-
!(0, accounting_1.isBudgetExceeded)(this.state.goal.tokensUsed, this.state.goal.tokenBudget));
|
|
469
|
-
}
|
|
470
|
-
get lastLoadIssue() {
|
|
471
|
-
return this.loadIssue;
|
|
472
|
-
}
|
|
473
|
-
addGoalInteger(value, increment, field) {
|
|
474
|
-
try {
|
|
475
|
-
return addSafeInteger(value, increment, field);
|
|
476
|
-
}
|
|
477
|
-
catch (error) {
|
|
478
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
479
|
-
this.failClosedAfterPersistenceError(message);
|
|
480
|
-
throw error;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
loadRecoveryMessage() {
|
|
484
|
-
const detail = this.loadIssue?.message ?? 'Goal storage state is not readable.';
|
|
485
|
-
return `Goal storage recovery is required before creating or replacing a Goal. ${detail}`;
|
|
486
|
-
}
|
|
487
|
-
snapshot() {
|
|
488
|
-
const g = this.state.goal;
|
|
489
|
-
if (!g)
|
|
490
|
-
return null;
|
|
491
|
-
const criteria = g.contract?.successCriteria ?? [];
|
|
492
|
-
return {
|
|
493
|
-
goalId: g.goalId,
|
|
494
|
-
revision: g.revision,
|
|
495
|
-
objective: g.objective,
|
|
496
|
-
status: g.status,
|
|
497
|
-
tokenBudget: g.tokenBudget,
|
|
498
|
-
tokensUsed: g.tokensUsed,
|
|
499
|
-
timeUsedMs: g.timeUsedMs,
|
|
500
|
-
continuationCount: g.continuationCount,
|
|
501
|
-
automaticContinuationStreak: g.automaticContinuationStreak ?? 0,
|
|
502
|
-
updatedAt: g.updatedAt,
|
|
503
|
-
stopReason: g.stopReason?.message,
|
|
504
|
-
criteria: {
|
|
505
|
-
passed: criteria.filter(criterion => criterion.status === 'passed').length,
|
|
506
|
-
failed: criteria.filter(criterion => criterion.status === 'failed').length,
|
|
507
|
-
stale: criteria.filter(criterion => criterion.status === 'stale').length,
|
|
508
|
-
total: criteria.length,
|
|
509
|
-
},
|
|
510
|
-
planRevision: g.contract?.planSnapshot?.revision,
|
|
511
|
-
planPhase: g.contract?.planSnapshot?.phase,
|
|
512
|
-
nextAction: g.contract?.planSnapshot?.nextAction,
|
|
513
|
-
auditRemaining: g.completionAudit?.remainingRequirements,
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
// ==========================================================================
|
|
517
|
-
// Lifecycle
|
|
518
|
-
// ==========================================================================
|
|
519
|
-
load(recoverActive = false) {
|
|
520
|
-
const result = (0, goal_storage_1.loadGoal)(this.projectPath, this.sessionId);
|
|
521
|
-
if (result.ok) {
|
|
522
|
-
this.loadIssue = null;
|
|
523
|
-
this.loadRecoveryRequired = false;
|
|
524
|
-
// v0.1.2: normalize v0.1.1 sidecars (no contract) into a minimal pending
|
|
525
|
-
// contract. This is in-memory only; it does not rewrite the sidecar
|
|
526
|
-
// until the next real state update.
|
|
527
|
-
this.state.goal = ensureContract(result.value);
|
|
528
|
-
this.persistedGoalSnapshot = structuredClone(this.state.goal);
|
|
529
|
-
// Every reload replaces the in-memory authority, even if the disk bytes
|
|
530
|
-
// are unchanged. Advance the runtime epoch so pre-reload outcomes cannot
|
|
531
|
-
// finalize or account against the newly loaded state.
|
|
532
|
-
this.state.generation += 1;
|
|
533
|
-
this.state.continuationDeferred = false;
|
|
534
|
-
if (recoverActive && this.state.goal.status === 'active') {
|
|
535
|
-
const loadedGoal = this.state.goal;
|
|
536
|
-
const lockPath = (0, path_1.join)((0, config_dir_1.getProjectSessionsDir)(this.projectPath), `${this.sessionId}.goal.json.lock`);
|
|
537
|
-
if ((0, fs_1.existsSync)(lockPath)) {
|
|
538
|
-
const message = `Restart recovery could not persist a paused Goal because storage is temporarily locked at ${lockPath}. No continuation was started; resolve the lock, then use /target resume.`;
|
|
539
|
-
this.loadIssue = { code: 'io_error', message };
|
|
540
|
-
this.loadRecoveryRequired = true;
|
|
541
|
-
this.failClosedAfterPersistenceError(message);
|
|
542
|
-
return true;
|
|
543
|
-
}
|
|
544
|
-
try {
|
|
545
|
-
this.state.goal = {
|
|
546
|
-
...loadedGoal,
|
|
547
|
-
status: 'paused',
|
|
548
|
-
revision: addSafeInteger(loadedGoal.revision, 1, 'revision'),
|
|
549
|
-
updatedAt: Date.now(),
|
|
550
|
-
stopReason: {
|
|
551
|
-
kind: 'user',
|
|
552
|
-
message: 'Recovered after restart. Use /target resume to continue.',
|
|
553
|
-
at: Date.now(),
|
|
554
|
-
},
|
|
555
|
-
};
|
|
556
|
-
this.state.continuationDeferred = true;
|
|
557
|
-
this.persist();
|
|
558
|
-
}
|
|
559
|
-
catch (error) {
|
|
560
|
-
const detail = (0, redaction_1.redactTraceText)(error instanceof Error ? error.message : String(error));
|
|
561
|
-
const message = `Restart recovery could not persist a paused Goal. No continuation was started; resolve the storage error, then use /target resume. ${detail}`;
|
|
562
|
-
this.loadIssue = { code: 'io_error', message };
|
|
563
|
-
this.loadRecoveryRequired = true;
|
|
564
|
-
this.failClosedAfterPersistenceError(message);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
return true;
|
|
568
|
-
}
|
|
569
|
-
this.loadIssue = ['corrupt', 'metadata_mismatch', 'incompatible_schema', 'io_error'].includes(result.error)
|
|
570
|
-
? {
|
|
571
|
-
code: result.error,
|
|
572
|
-
message: result.message,
|
|
573
|
-
}
|
|
574
|
-
: null;
|
|
575
|
-
// A missing sidecar is an authoritative empty state and permits a fresh
|
|
576
|
-
// create. Every other load failure leaves the write path recovery-gated;
|
|
577
|
-
// otherwise create/replace could hide the unreadable sidecar.
|
|
578
|
-
this.loadRecoveryRequired = result.error !== 'not_found';
|
|
579
|
-
// A failed repeat load makes the disk state authoritative and the previous
|
|
580
|
-
// in-memory Goal unsafe to continue. Invalidate in-flight work and discard
|
|
581
|
-
// both cached copies without attempting to write the stale Goal back.
|
|
582
|
-
this.state.generation += 1;
|
|
583
|
-
this.state.continuationDeferred = true;
|
|
584
|
-
this.state.goal = null;
|
|
585
|
-
this.persistedGoalSnapshot = null;
|
|
586
|
-
return false;
|
|
587
|
-
}
|
|
588
|
-
create(objective, contractInput = {}) {
|
|
589
|
-
if (this.loadRecoveryRequired) {
|
|
590
|
-
return { ok: false, error: this.loadRecoveryMessage() };
|
|
591
|
-
}
|
|
592
|
-
if (this.state.goal && !types_1.GOAL_TERMINAL_STATES.has(this.state.goal.status)) {
|
|
593
|
-
return {
|
|
594
|
-
ok: false,
|
|
595
|
-
error: 'An active goal already exists. Use /target replace to change it.',
|
|
596
|
-
};
|
|
597
|
-
}
|
|
598
|
-
const normalized = (0, objective_1.normalizeGoalObjective)(objective);
|
|
599
|
-
if (!normalized.originalObjective) {
|
|
600
|
-
return { ok: false, error: 'Objective cannot be empty.' };
|
|
601
|
-
}
|
|
602
|
-
if (!normalized.objective && normalized.completionAction === 'exit_goal') {
|
|
603
|
-
return {
|
|
604
|
-
ok: false,
|
|
605
|
-
error: 'Goal exit is a lifecycle command, not an objective. Use /goal exit.',
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
if (normalized.originalObjective.length > types_1.GOAL_INVARIANTS.maxObjectiveChars) {
|
|
609
|
-
return {
|
|
610
|
-
ok: false,
|
|
611
|
-
error: `Objective too long (max ${types_1.GOAL_INVARIANTS.maxObjectiveChars} chars).`,
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
const now = Date.now();
|
|
615
|
-
const contract = creationContract(normalized.objective, now, contractInput, normalized.originalObjective, normalized.completionAction);
|
|
616
|
-
if (!contract) {
|
|
617
|
-
return { ok: false, error: 'Goal constraints or success criteria are invalid.' };
|
|
618
|
-
}
|
|
619
|
-
const requiresBoundaryConfirmation = goalRequiresBoundaryConfirmation(normalized.objective, contractInput);
|
|
620
|
-
const result = (0, goal_storage_1.createGoal)(this.projectPath, this.sessionId, normalized.objective, contract, this.state.goal?.revision, requiresBoundaryConfirmation
|
|
621
|
-
? boundaryConfirmationState(contract.objectiveRevision, now)
|
|
622
|
-
: undefined);
|
|
623
|
-
if (!result.ok)
|
|
624
|
-
return { ok: false, error: result.message };
|
|
625
|
-
const created = result.value;
|
|
626
|
-
this.state.goal = created;
|
|
627
|
-
this.persistedGoalSnapshot = structuredClone(created);
|
|
628
|
-
this.state.generation += 1;
|
|
629
|
-
this.state.continuationDeferred = created.status !== 'active';
|
|
630
|
-
return { ok: true };
|
|
631
|
-
}
|
|
632
|
-
pause() {
|
|
633
|
-
if (!this.state.goal || this.state.goal.status !== 'active')
|
|
634
|
-
return false;
|
|
635
|
-
this.state.goal = {
|
|
636
|
-
...this.state.goal,
|
|
637
|
-
status: 'paused',
|
|
638
|
-
revision: this.addGoalInteger(this.state.goal.revision, 1, 'revision'),
|
|
639
|
-
updatedAt: Date.now(),
|
|
640
|
-
stopReason: { kind: 'user', message: 'Paused by user.', at: Date.now() },
|
|
641
|
-
};
|
|
642
|
-
this.persist();
|
|
643
|
-
this.state.continuationDeferred = true;
|
|
644
|
-
return true;
|
|
645
|
-
}
|
|
646
|
-
resume(options = {}) {
|
|
647
|
-
if (!this.state.goal || !types_1.GOAL_USER_RECOVERABLE_STATES.has(this.state.goal.status))
|
|
648
|
-
return false;
|
|
649
|
-
const pendingBoundary = this.state.goal.boundaryConfirmation &&
|
|
650
|
-
this.state.goal.boundaryConfirmation.confirmedAt === undefined;
|
|
651
|
-
if (pendingBoundary &&
|
|
652
|
-
(!options.confirmBoundary ||
|
|
653
|
-
options.expectedGoalId !== this.state.goal.goalId ||
|
|
654
|
-
options.expectedRevision !== this.state.goal.revision)) {
|
|
655
|
-
return false;
|
|
656
|
-
}
|
|
657
|
-
const resumedAt = Date.now();
|
|
658
|
-
this.state.goal = {
|
|
659
|
-
...this.state.goal,
|
|
660
|
-
status: 'active',
|
|
661
|
-
revision: this.addGoalInteger(this.state.goal.revision, 1, 'revision'),
|
|
662
|
-
updatedAt: resumedAt,
|
|
663
|
-
activeSince: resumedAt,
|
|
664
|
-
stopReason: undefined,
|
|
665
|
-
blocker: undefined,
|
|
666
|
-
noProgressCount: 0,
|
|
667
|
-
automaticContinuationStreak: 0,
|
|
668
|
-
recentNoProgressTurns: [],
|
|
669
|
-
boundaryConfirmation: pendingBoundary
|
|
670
|
-
? {
|
|
671
|
-
...this.state.goal.boundaryConfirmation,
|
|
672
|
-
confirmedAt: resumedAt,
|
|
673
|
-
confirmedRevision: this.state.goal.revision,
|
|
674
|
-
}
|
|
675
|
-
: this.state.goal.boundaryConfirmation,
|
|
676
|
-
};
|
|
677
|
-
this.persist();
|
|
678
|
-
this.state.continuationDeferred = false;
|
|
679
|
-
return true;
|
|
680
|
-
}
|
|
681
|
-
edit(objective, reason = 'User invoked /target edit.') {
|
|
682
|
-
if (!this.state.goal || types_1.GOAL_TERMINAL_STATES.has(this.state.goal.status))
|
|
683
|
-
return false;
|
|
684
|
-
const normalized = (0, objective_1.normalizeGoalObjective)(objective);
|
|
685
|
-
if (!normalized.objective)
|
|
686
|
-
return false;
|
|
687
|
-
const g = this.state.goal;
|
|
688
|
-
const nextObjective = normalized.objective;
|
|
689
|
-
const currentContract = g.contract ?? minimalContract(g.objective, g.updatedAt);
|
|
690
|
-
if (nextObjective === g.objective &&
|
|
691
|
-
normalized.completionAction === currentContract.completionAction) {
|
|
692
|
-
return true;
|
|
693
|
-
}
|
|
694
|
-
const changedAt = Date.now();
|
|
695
|
-
// v0.1.2: preserve originalObjective; record an objective revision on the
|
|
696
|
-
// contract so steering can never silently rewrite the root goal. The
|
|
697
|
-
// top-level `objective` reflects the current wording.
|
|
698
|
-
const objectiveRevision = this.addGoalInteger(currentContract.objectiveRevision, 1, 'contract.objectiveRevision');
|
|
699
|
-
const contract = {
|
|
700
|
-
...currentContract,
|
|
701
|
-
originalObjective: currentContract.originalObjective,
|
|
702
|
-
objectiveRevision,
|
|
703
|
-
completionAction: normalized.completionAction,
|
|
704
|
-
objectiveHistory: [
|
|
705
|
-
...(currentContract.objectiveHistory ?? []),
|
|
706
|
-
{
|
|
707
|
-
revision: objectiveRevision,
|
|
708
|
-
previousObjective: g.objective,
|
|
709
|
-
objective: nextObjective,
|
|
710
|
-
reason: reason.trim() || 'User invoked /target edit.',
|
|
711
|
-
changedAt,
|
|
712
|
-
source: 'user',
|
|
713
|
-
},
|
|
714
|
-
].slice(-50),
|
|
715
|
-
successCriteria: currentContract.successCriteria.map(criterion => criterion.id === 'criterion:primary'
|
|
716
|
-
? {
|
|
717
|
-
...criterion,
|
|
718
|
-
statement: nextObjective,
|
|
719
|
-
source: 'user',
|
|
720
|
-
status: 'pending',
|
|
721
|
-
evidenceRefs: [],
|
|
722
|
-
}
|
|
723
|
-
: criterion),
|
|
724
|
-
};
|
|
725
|
-
const edited = {
|
|
726
|
-
...g,
|
|
727
|
-
objective: nextObjective,
|
|
728
|
-
contract,
|
|
729
|
-
revision: this.addGoalInteger(g.revision, 1, 'revision'),
|
|
730
|
-
updatedAt: changedAt,
|
|
731
|
-
completionAudit: undefined,
|
|
732
|
-
// Truncation is scoped to an objective epoch. A user edit intentionally
|
|
733
|
-
// starts a fresh verification epoch; old evidence remains provenance but
|
|
734
|
-
// cannot permanently block the edited objective.
|
|
735
|
-
evidenceLedgerTruncation: undefined,
|
|
736
|
-
};
|
|
737
|
-
const preservedContractInput = {
|
|
738
|
-
constraints: contract.constraints.map(constraint => constraint.statement),
|
|
739
|
-
successCriteria: contract.successCriteria.map(criterion => ({
|
|
740
|
-
statement: criterion.statement,
|
|
741
|
-
requiredEvidenceKinds: criterion.requiredEvidenceKinds,
|
|
742
|
-
})),
|
|
743
|
-
};
|
|
744
|
-
this.state.goal = goalRequiresBoundaryConfirmation(nextObjective, preservedContractInput)
|
|
745
|
-
? { ...pauseForBoundaryConfirmation(edited, changedAt), revision: edited.revision }
|
|
746
|
-
: { ...edited, boundaryConfirmation: undefined };
|
|
747
|
-
this.persist();
|
|
748
|
-
this.state.continuationDeferred = this.state.goal.status !== 'active';
|
|
749
|
-
return true;
|
|
750
|
-
}
|
|
751
|
-
/** Record trusted human acceptance for a criterion that requires user evidence. */
|
|
752
|
-
confirmCriterion(criterionId) {
|
|
753
|
-
const goal = this.state.goal;
|
|
754
|
-
const contract = goal?.contract;
|
|
755
|
-
if (!goal || !contract || types_1.GOAL_TERMINAL_STATES.has(goal.status))
|
|
756
|
-
return false;
|
|
757
|
-
const criterion = contract.successCriteria.find(item => item.id === criterionId.trim());
|
|
758
|
-
if (!criterion || !criterion.requiredEvidenceKinds.includes('user'))
|
|
759
|
-
return false;
|
|
760
|
-
const now = Date.now();
|
|
761
|
-
const revision = this.addGoalInteger(goal.revision, 1, 'revision');
|
|
762
|
-
const evidenceId = `evidence:user:${(0, crypto_1.randomUUID)()}`;
|
|
763
|
-
const record = {
|
|
764
|
-
id: evidenceId,
|
|
765
|
-
goalId: goal.goalId,
|
|
766
|
-
goalRevision: revision,
|
|
767
|
-
objectiveRevision: contract.objectiveRevision,
|
|
768
|
-
turnId: `user-confirmation:${revision}`,
|
|
769
|
-
kind: 'user',
|
|
770
|
-
subject: `User confirmed ${criterion.id}: ${criterion.statement}`.slice(0, 240),
|
|
771
|
-
result: 'passed',
|
|
772
|
-
sourceRef: 'user:/target-confirm',
|
|
773
|
-
capturedAt: now,
|
|
774
|
-
redacted: true,
|
|
775
|
-
};
|
|
776
|
-
const boundedEvidence = appendBoundedEvidence(goal.evidenceLedger ?? [], [record], contract.objectiveRevision, goal.evidenceLedgerTruncation);
|
|
777
|
-
this.state.goal = {
|
|
778
|
-
...goal,
|
|
779
|
-
revision,
|
|
780
|
-
updatedAt: now,
|
|
781
|
-
evidenceLedger: boundedEvidence.ledger,
|
|
782
|
-
evidenceLedgerTruncation: boundedEvidence.truncation,
|
|
783
|
-
contract: {
|
|
784
|
-
...contract,
|
|
785
|
-
successCriteria: contract.successCriteria.map(item => item.id === criterion.id
|
|
786
|
-
? {
|
|
787
|
-
...item,
|
|
788
|
-
status: 'passed',
|
|
789
|
-
evidenceRefs: [...new Set([...item.evidenceRefs, evidenceId])],
|
|
790
|
-
}
|
|
791
|
-
: item),
|
|
792
|
-
},
|
|
793
|
-
completionAudit: undefined,
|
|
794
|
-
};
|
|
795
|
-
this.persist();
|
|
796
|
-
return true;
|
|
797
|
-
}
|
|
798
|
-
addConstraint(statement) {
|
|
799
|
-
const goal = this.state.goal;
|
|
800
|
-
const trimmed = statement.trim();
|
|
801
|
-
if (!goal || goal.status === 'complete' || !trimmed)
|
|
802
|
-
return false;
|
|
803
|
-
const contract = goal.contract ?? minimalContract(goal.objective, goal.updatedAt);
|
|
804
|
-
if (contract.constraints.some(constraint => constraint.statement === trimmed))
|
|
805
|
-
return true;
|
|
806
|
-
const revision = this.addGoalInteger(goal.revision, 1, 'revision');
|
|
807
|
-
this.state.goal = {
|
|
808
|
-
...goal,
|
|
809
|
-
contract: {
|
|
810
|
-
...contract,
|
|
811
|
-
constraints: [
|
|
812
|
-
...contract.constraints,
|
|
813
|
-
{
|
|
814
|
-
id: `constraint:user:${revision}`,
|
|
815
|
-
statement: trimmed,
|
|
816
|
-
source: 'user',
|
|
817
|
-
},
|
|
818
|
-
],
|
|
819
|
-
},
|
|
820
|
-
revision,
|
|
821
|
-
updatedAt: Date.now(),
|
|
822
|
-
};
|
|
823
|
-
this.persist();
|
|
824
|
-
return true;
|
|
825
|
-
}
|
|
826
|
-
replace(objective) {
|
|
827
|
-
if (this.loadRecoveryRequired)
|
|
828
|
-
return false;
|
|
829
|
-
const normalized = (0, objective_1.normalizeGoalObjective)(objective);
|
|
830
|
-
if (!normalized.objective)
|
|
831
|
-
return false;
|
|
832
|
-
// Create new goal with fresh goalId and fresh contract; old generation
|
|
833
|
-
// invalidated. Does not reuse the old goal's completion state.
|
|
834
|
-
const now = Date.now();
|
|
835
|
-
const contract = minimalContract(normalized.objective, now, normalized.originalObjective, normalized.completionAction);
|
|
836
|
-
const requiresBoundaryConfirmation = goalRequiresBoundaryConfirmation(normalized.objective);
|
|
837
|
-
const result = (0, goal_storage_1.createGoal)(this.projectPath, this.sessionId, normalized.objective, contract, this.state.goal?.revision, requiresBoundaryConfirmation
|
|
838
|
-
? boundaryConfirmationState(contract.objectiveRevision, now)
|
|
839
|
-
: undefined);
|
|
840
|
-
if (!result.ok) {
|
|
841
|
-
this.restoreDiskAuthorityAfterMutationFailure();
|
|
842
|
-
return false;
|
|
843
|
-
}
|
|
844
|
-
const replacement = result.value;
|
|
845
|
-
this.state.goal = replacement;
|
|
846
|
-
this.persistedGoalSnapshot = structuredClone(replacement);
|
|
847
|
-
this.state.generation += 1;
|
|
848
|
-
this.state.continuationDeferred = replacement.status !== 'active';
|
|
849
|
-
return true;
|
|
850
|
-
}
|
|
851
|
-
setBudget(tokenBudget) {
|
|
852
|
-
if (!this.state.goal || this.state.goal.status === 'complete')
|
|
853
|
-
return false;
|
|
854
|
-
this.state.goal = {
|
|
855
|
-
...this.state.goal,
|
|
856
|
-
tokenBudget: tokenBudget ?? undefined,
|
|
857
|
-
revision: this.addGoalInteger(this.state.goal.revision, 1, 'revision'),
|
|
858
|
-
updatedAt: Date.now(),
|
|
859
|
-
};
|
|
860
|
-
this.persist();
|
|
861
|
-
return true;
|
|
862
|
-
}
|
|
863
|
-
clear() {
|
|
864
|
-
if (!this.state.goal)
|
|
865
|
-
return false;
|
|
866
|
-
const result = (0, goal_storage_1.deleteGoal)(this.projectPath, this.sessionId, this.state.goal.revision, this.state.goal.goalId);
|
|
867
|
-
if (!result.ok) {
|
|
868
|
-
this.restoreDiskAuthorityAfterMutationFailure();
|
|
869
|
-
throw new Error(`${result.error}: ${result.message}`);
|
|
870
|
-
}
|
|
871
|
-
this.state.goal = null;
|
|
872
|
-
this.persistedGoalSnapshot = null;
|
|
873
|
-
this.state.generation += 1;
|
|
874
|
-
this.state.continuationDeferred = false;
|
|
875
|
-
return true;
|
|
876
|
-
}
|
|
877
|
-
/**
|
|
878
|
-
* Detach a completed Goal from the live runtime after its session binding is
|
|
879
|
-
* cleared. The persisted sidecar remains the immutable completion receipt.
|
|
880
|
-
*/
|
|
881
|
-
detachCompletedReceipt(expectedGoalId) {
|
|
882
|
-
const goal = this.state.goal;
|
|
883
|
-
if (!goal ||
|
|
884
|
-
goal.goalId !== expectedGoalId ||
|
|
885
|
-
goal.status !== 'complete' ||
|
|
886
|
-
goal.completionAudit?.passed !== true) {
|
|
887
|
-
return false;
|
|
888
|
-
}
|
|
889
|
-
this.state.goal = null;
|
|
890
|
-
this.persistedGoalSnapshot = null;
|
|
891
|
-
this.state.generation += 1;
|
|
892
|
-
this.state.continuationDeferred = false;
|
|
893
|
-
return true;
|
|
894
|
-
}
|
|
895
|
-
// ==========================================================================
|
|
896
|
-
// Turn integration
|
|
897
|
-
// ==========================================================================
|
|
898
|
-
buildContinuationRequest() {
|
|
899
|
-
if (!this.canContinue)
|
|
900
|
-
return null;
|
|
901
|
-
const g = this.state.goal;
|
|
902
|
-
let continuationIndex;
|
|
903
|
-
try {
|
|
904
|
-
continuationIndex = this.addGoalInteger(g.continuationCount, 1, 'continuationCount');
|
|
905
|
-
}
|
|
906
|
-
catch {
|
|
907
|
-
return null;
|
|
908
|
-
}
|
|
909
|
-
return {
|
|
910
|
-
inputKind: 'goal_continuation',
|
|
911
|
-
sessionId: this.sessionId,
|
|
912
|
-
persistAsUserMessage: false,
|
|
913
|
-
echoToTranscript: false,
|
|
914
|
-
generation: this.state.generation,
|
|
915
|
-
goal: {
|
|
916
|
-
goalId: g.goalId,
|
|
917
|
-
revision: g.revision,
|
|
918
|
-
continuationIndex,
|
|
919
|
-
},
|
|
920
|
-
};
|
|
921
|
-
}
|
|
922
|
-
finalizeTurn(outcome) {
|
|
923
|
-
const g = this.state.goal;
|
|
924
|
-
if (!g)
|
|
925
|
-
return;
|
|
926
|
-
if (outcome.sessionId !== this.sessionId ||
|
|
927
|
-
outcome.goalId !== g.goalId ||
|
|
928
|
-
outcome.goalRevision !== g.revision ||
|
|
929
|
-
(outcome.goalGeneration !== undefined && outcome.goalGeneration !== this.state.generation))
|
|
930
|
-
return;
|
|
931
|
-
if (outcome.usageComplete === false) {
|
|
932
|
-
const accounting = (0, accounting_1.accumulateTurn)({
|
|
933
|
-
tokensUsed: g.tokensUsed,
|
|
934
|
-
timeUsedMs: g.timeUsedMs,
|
|
935
|
-
continuationCount: g.continuationCount,
|
|
936
|
-
noProgressCount: g.noProgressCount,
|
|
937
|
-
}, outcome);
|
|
938
|
-
const pausedAt = Date.now();
|
|
939
|
-
const tokensUsed = this.addGoalInteger(accounting.tokensUsed, 0, 'tokensUsed');
|
|
940
|
-
const timeUsedMs = this.addGoalInteger(accounting.timeUsedMs, 0, 'timeUsedMs');
|
|
941
|
-
const continuationCount = this.addGoalInteger(accounting.continuationCount, 0, 'continuationCount');
|
|
942
|
-
const noProgressCount = this.addGoalInteger(accounting.noProgressCount, 0, 'noProgressCount');
|
|
943
|
-
const automaticContinuationStreak = outcome.inputKind === 'goal_continuation'
|
|
944
|
-
? this.addGoalInteger(g.automaticContinuationStreak ?? 0, 1, 'automaticContinuationStreak')
|
|
945
|
-
: 0;
|
|
946
|
-
this.state.goal = {
|
|
947
|
-
...g,
|
|
948
|
-
tokensUsed,
|
|
949
|
-
timeUsedMs,
|
|
950
|
-
continuationCount,
|
|
951
|
-
automaticContinuationStreak,
|
|
952
|
-
noProgressCount,
|
|
953
|
-
status: 'paused',
|
|
954
|
-
revision: this.addGoalInteger(g.revision, 1, 'revision'),
|
|
955
|
-
updatedAt: pausedAt,
|
|
956
|
-
lastTurn: {
|
|
957
|
-
turnId: outcome.turnId,
|
|
958
|
-
finishReason: outcome.finishReason,
|
|
959
|
-
endedAt: outcome.endedAt,
|
|
960
|
-
promptTokens: outcome.usage.promptTokens,
|
|
961
|
-
completionTokens: outcome.usage.completionTokens,
|
|
962
|
-
subagentTokens: outcome.usage.subagentTokens,
|
|
963
|
-
totalTokens: outcome.usage.totalTokens,
|
|
964
|
-
madeProgress: outcome.madeProgress,
|
|
965
|
-
},
|
|
966
|
-
stopReason: {
|
|
967
|
-
kind: 'runtime_error',
|
|
968
|
-
message: 'Paused because provider usage was missing or incomplete across retry/fallback attempts; known usage was recorded, and budget accounting is incomplete.',
|
|
969
|
-
at: pausedAt,
|
|
970
|
-
},
|
|
971
|
-
};
|
|
972
|
-
this.state.continuationDeferred = true;
|
|
973
|
-
this.persist();
|
|
974
|
-
return;
|
|
975
|
-
}
|
|
976
|
-
const currentContract = g.contract ?? minimalContract(g.objective, g.updatedAt);
|
|
977
|
-
const pendingPlanRevision = outcome.pendingPlanUpdate
|
|
978
|
-
? this.addGoalInteger(currentContract.planSnapshot?.revision ?? 0, 1, 'contract.planSnapshot.revision')
|
|
979
|
-
: 0;
|
|
980
|
-
const pendingDerivedCriteria = outcome.pendingPlanUpdate
|
|
981
|
-
? newDerivedCriteria(currentContract, outcome.pendingPlanUpdate, pendingPlanRevision)
|
|
982
|
-
: [];
|
|
983
|
-
const pendingPlanChangesContent = outcome.pendingPlanUpdate
|
|
984
|
-
? planContentChanged(currentContract, outcome.pendingPlanUpdate)
|
|
985
|
-
: false;
|
|
986
|
-
const pendingPlanMutatesContract = Boolean(outcome.pendingPlanUpdate && (pendingPlanChangesContent || pendingDerivedCriteria.length > 0));
|
|
987
|
-
const newEvidence = (outcome.evidenceRecords ?? []).filter(record => record.goalId === g.goalId &&
|
|
988
|
-
record.goalRevision === g.revision &&
|
|
989
|
-
record.objectiveRevision === (g.contract?.objectiveRevision ?? 0) &&
|
|
990
|
-
record.turnId === outcome.turnId);
|
|
991
|
-
const planAdvanced = Boolean(outcome.pendingPlanUpdate &&
|
|
992
|
-
substantivePlanProgress(currentContract, outcome.pendingPlanUpdate, pendingDerivedCriteria));
|
|
993
|
-
const evidenceContract = pendingDerivedCriteria.length
|
|
994
|
-
? {
|
|
995
|
-
...currentContract,
|
|
996
|
-
successCriteria: [...currentContract.successCriteria, ...pendingDerivedCriteria],
|
|
997
|
-
}
|
|
998
|
-
: currentContract;
|
|
999
|
-
const incomingEvidenceKeys = evidenceProgressKeys(newEvidence, evidenceContract);
|
|
1000
|
-
const recordedEvidenceKeys = new Set(g.progressEvidenceKeys ?? []);
|
|
1001
|
-
const evidenceAdvanced = incomingEvidenceKeys.some(key => !recordedEvidenceKeys.has(key));
|
|
1002
|
-
const hasAuditableProgressInputs = outcome.workspaceChanged !== undefined ||
|
|
1003
|
-
outcome.evidenceRecords !== undefined ||
|
|
1004
|
-
outcome.pendingPlanUpdate !== undefined;
|
|
1005
|
-
// Text-only plan churn is still persisted as a snapshot for observability,
|
|
1006
|
-
// but phase/next-action/description rewrites are not Goal progress. Runtime
|
|
1007
|
-
// turns must present an auditable signal; legacy direct callers without the
|
|
1008
|
-
// new metadata retain their explicit madeProgress value for compatibility.
|
|
1009
|
-
const madeAuditableProgress = Boolean(outcome.workspaceChanged) || evidenceAdvanced || planAdvanced;
|
|
1010
|
-
const accountingOutcome = {
|
|
1011
|
-
...outcome,
|
|
1012
|
-
madeProgress: hasAuditableProgressInputs ? madeAuditableProgress : outcome.madeProgress,
|
|
1013
|
-
};
|
|
1014
|
-
// Accumulate per-turn usage.
|
|
1015
|
-
const acc = (0, accounting_1.accumulateTurn)({
|
|
1016
|
-
tokensUsed: g.tokensUsed,
|
|
1017
|
-
timeUsedMs: g.timeUsedMs,
|
|
1018
|
-
continuationCount: g.continuationCount,
|
|
1019
|
-
noProgressCount: g.noProgressCount,
|
|
1020
|
-
}, accountingOutcome);
|
|
1021
|
-
const tokensUsed = this.addGoalInteger(acc.tokensUsed, 0, 'tokensUsed');
|
|
1022
|
-
const timeUsedMs = this.addGoalInteger(acc.timeUsedMs, 0, 'timeUsedMs');
|
|
1023
|
-
const continuationCount = this.addGoalInteger(acc.continuationCount, 0, 'continuationCount');
|
|
1024
|
-
const noProgressCount = this.addGoalInteger(acc.noProgressCount, 0, 'noProgressCount');
|
|
1025
|
-
const automaticContinuationStreak = outcome.inputKind === 'goal_continuation'
|
|
1026
|
-
? this.addGoalInteger(g.automaticContinuationStreak ?? 0, 1, 'automaticContinuationStreak')
|
|
1027
|
-
: 0;
|
|
1028
|
-
const updated = {
|
|
1029
|
-
...g,
|
|
1030
|
-
tokensUsed,
|
|
1031
|
-
timeUsedMs,
|
|
1032
|
-
continuationCount,
|
|
1033
|
-
automaticContinuationStreak,
|
|
1034
|
-
noProgressCount,
|
|
1035
|
-
recentNoProgressTurns: accountingOutcome.madeProgress
|
|
1036
|
-
? []
|
|
1037
|
-
: [...(g.recentNoProgressTurns ?? []), noProgressTurnSummary(accountingOutcome)].slice(-3),
|
|
1038
|
-
progressEvidenceKeys: [
|
|
1039
|
-
...(g.progressEvidenceKeys ?? []),
|
|
1040
|
-
...incomingEvidenceKeys.filter(key => !recordedEvidenceKeys.has(key)),
|
|
1041
|
-
].slice(-1000),
|
|
1042
|
-
revision: this.addGoalInteger(g.revision, 1, 'revision'),
|
|
1043
|
-
updatedAt: Date.now(),
|
|
1044
|
-
lastTurn: {
|
|
1045
|
-
turnId: outcome.turnId,
|
|
1046
|
-
finishReason: outcome.finishReason,
|
|
1047
|
-
endedAt: outcome.endedAt,
|
|
1048
|
-
promptTokens: outcome.usage.promptTokens,
|
|
1049
|
-
completionTokens: outcome.usage.completionTokens,
|
|
1050
|
-
subagentTokens: outcome.usage.subagentTokens,
|
|
1051
|
-
totalTokens: outcome.usage.totalTokens,
|
|
1052
|
-
madeProgress: accountingOutcome.madeProgress,
|
|
1053
|
-
},
|
|
1054
|
-
};
|
|
1055
|
-
if (outcome.pendingPlanUpdate && pendingPlanMutatesContract) {
|
|
1056
|
-
const contract = updated.contract ?? minimalContract(updated.objective, updated.updatedAt);
|
|
1057
|
-
updated.contract = {
|
|
1058
|
-
...contract,
|
|
1059
|
-
successCriteria: [...contract.successCriteria, ...pendingDerivedCriteria],
|
|
1060
|
-
planSnapshot: {
|
|
1061
|
-
revision: pendingPlanRevision,
|
|
1062
|
-
phase: outcome.pendingPlanUpdate.phase,
|
|
1063
|
-
steps: outcome.pendingPlanUpdate.steps.map((step, index) => ({
|
|
1064
|
-
id: `plan:${pendingPlanRevision}:${index + 1}`,
|
|
1065
|
-
description: step.description,
|
|
1066
|
-
done: step.done,
|
|
1067
|
-
})),
|
|
1068
|
-
nextAction: outcome.pendingPlanUpdate.nextAction,
|
|
1069
|
-
updatedAt: Date.now(),
|
|
1070
|
-
},
|
|
1071
|
-
};
|
|
1072
|
-
}
|
|
1073
|
-
const boundedEvidence = appendBoundedEvidence(g.evidenceLedger ?? [], newEvidence, currentContract.objectiveRevision, g.evidenceLedgerTruncation);
|
|
1074
|
-
const evidenceLedger = boundedEvidence.ledger;
|
|
1075
|
-
updated.evidenceLedger = evidenceLedger;
|
|
1076
|
-
updated.evidenceLedgerTruncation = boundedEvidence.truncation;
|
|
1077
|
-
// Process a terminal request only when it belongs to this exact turn and
|
|
1078
|
-
// goal revision. A stale tool call can never close a newer goal.
|
|
1079
|
-
const terminalRequest = outcome.pendingTerminalRequest;
|
|
1080
|
-
const currentBlockedSignal = Boolean(terminalRequest?.requestedStatus === 'blocked' &&
|
|
1081
|
-
terminalRequest.goalId === g.goalId &&
|
|
1082
|
-
terminalRequest.goalRevision === g.revision &&
|
|
1083
|
-
terminalRequest.turnId === outcome.turnId &&
|
|
1084
|
-
outcome.blocker &&
|
|
1085
|
-
updated.blocker?.fingerprint === outcome.blocker.fingerprint);
|
|
1086
|
-
// Consecutive means every Goal turn. Any intervening turn without the same
|
|
1087
|
-
// current-turn blocker breaks the streak instead of leaving an old counter
|
|
1088
|
-
// available for a later terminal request.
|
|
1089
|
-
if (updated.blocker && !currentBlockedSignal)
|
|
1090
|
-
updated.blocker = undefined;
|
|
1091
|
-
if (terminalRequest &&
|
|
1092
|
-
terminalRequest.goalId === g.goalId &&
|
|
1093
|
-
terminalRequest.goalRevision === g.revision &&
|
|
1094
|
-
terminalRequest.turnId === outcome.turnId) {
|
|
1095
|
-
if (terminalRequest.requestedStatus === 'complete') {
|
|
1096
|
-
if (updated.contract && terminalRequest.criterionEvidence) {
|
|
1097
|
-
const ledgerById = new Map(evidenceLedger.map(record => [record.id, record]));
|
|
1098
|
-
const criterionCounts = new Map();
|
|
1099
|
-
const evidenceCounts = new Map();
|
|
1100
|
-
for (const mapping of terminalRequest.criterionEvidence) {
|
|
1101
|
-
criterionCounts.set(mapping.criterionId, (criterionCounts.get(mapping.criterionId) ?? 0) + 1);
|
|
1102
|
-
for (const id of mapping.evidenceIds) {
|
|
1103
|
-
evidenceCounts.set(id, (evidenceCounts.get(id) ?? 0) + 1);
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
const mappings = new Map(terminalRequest.criterionEvidence.map(mapping => [
|
|
1107
|
-
mapping.criterionId,
|
|
1108
|
-
mapping.evidenceIds,
|
|
1109
|
-
]));
|
|
1110
|
-
updated.contract = {
|
|
1111
|
-
...updated.contract,
|
|
1112
|
-
successCriteria: updated.contract.successCriteria.map(criterion => {
|
|
1113
|
-
if (criterionCounts.get(criterion.id) !== 1)
|
|
1114
|
-
return criterion;
|
|
1115
|
-
const refs = (mappings.get(criterion.id) ?? []).filter(id => {
|
|
1116
|
-
const record = ledgerById.get(id);
|
|
1117
|
-
return Boolean(record &&
|
|
1118
|
-
evidenceCounts.get(id) === 1 &&
|
|
1119
|
-
record.goalId === g.goalId &&
|
|
1120
|
-
record.goalRevision <= g.revision &&
|
|
1121
|
-
record.objectiveRevision === (updated.contract?.objectiveRevision ?? 0) &&
|
|
1122
|
-
criterion.requiredEvidenceKinds.includes(record.kind));
|
|
1123
|
-
});
|
|
1124
|
-
return {
|
|
1125
|
-
...criterion,
|
|
1126
|
-
evidenceRefs: [...new Set([...criterion.evidenceRefs, ...refs])],
|
|
1127
|
-
};
|
|
1128
|
-
}),
|
|
1129
|
-
};
|
|
1130
|
-
}
|
|
1131
|
-
const audit = (0, completion_audit_1.auditCompletion)({
|
|
1132
|
-
objective: updated.objective,
|
|
1133
|
-
contract: updated.contract ?? minimalContract(updated.objective, updated.updatedAt),
|
|
1134
|
-
evidenceLedger,
|
|
1135
|
-
evidenceLedgerTruncation: updated.evidenceLedgerTruncation,
|
|
1136
|
-
goalId: g.goalId,
|
|
1137
|
-
goalRevision: g.revision,
|
|
1138
|
-
requestedAt: terminalRequest.requestedAt,
|
|
1139
|
-
verificationSummary: outcome.verificationSummary ?? outcome.finishReason,
|
|
1140
|
-
workspaceFingerprint: outcome.workspaceFingerprint,
|
|
1141
|
-
});
|
|
1142
|
-
updated.completionAudit = audit;
|
|
1143
|
-
if (updated.contract) {
|
|
1144
|
-
const statusById = new Map(audit.criterionResults?.map(result => [result.criterionId, result.status]) ?? []);
|
|
1145
|
-
updated.contract = {
|
|
1146
|
-
...updated.contract,
|
|
1147
|
-
successCriteria: updated.contract.successCriteria.map(criterion => ({
|
|
1148
|
-
...criterion,
|
|
1149
|
-
status: statusById.get(criterion.id) ?? 'pending',
|
|
1150
|
-
})),
|
|
1151
|
-
};
|
|
1152
|
-
}
|
|
1153
|
-
if (audit.passed) {
|
|
1154
|
-
const completedAt = Date.now();
|
|
1155
|
-
const criterionResults = audit.criterionResults ?? [];
|
|
1156
|
-
const finalLedgerById = new Map(evidenceLedger.map(record => [record.id, record]));
|
|
1157
|
-
updated.completionAudit = {
|
|
1158
|
-
...audit,
|
|
1159
|
-
finalSummary: {
|
|
1160
|
-
originalObjective: updated.contract?.originalObjective ?? updated.objective,
|
|
1161
|
-
currentObjective: updated.objective,
|
|
1162
|
-
objectiveRevision: updated.contract?.objectiveRevision ?? 0,
|
|
1163
|
-
completedAt,
|
|
1164
|
-
verificationSummary: audit.verificationSummary,
|
|
1165
|
-
criterionResults: criterionResults.map(result => ({
|
|
1166
|
-
criterionId: result.criterionId,
|
|
1167
|
-
status: result.status,
|
|
1168
|
-
evidenceRefs: result.evidenceRefs,
|
|
1169
|
-
evidence: result.evidenceRefs.flatMap(id => {
|
|
1170
|
-
const record = finalLedgerById.get(id);
|
|
1171
|
-
return record ? [finalEvidenceReceipt(record)] : [];
|
|
1172
|
-
}),
|
|
1173
|
-
})),
|
|
1174
|
-
evidenceRefs: audit.evidenceRefs,
|
|
1175
|
-
accounting: {
|
|
1176
|
-
tokensUsed: updated.tokensUsed,
|
|
1177
|
-
timeUsedMs: updated.timeUsedMs,
|
|
1178
|
-
continuationCount: updated.continuationCount,
|
|
1179
|
-
usageComplete: true,
|
|
1180
|
-
},
|
|
1181
|
-
remainingRequirements: [],
|
|
1182
|
-
stopReason: 'completed',
|
|
1183
|
-
},
|
|
1184
|
-
};
|
|
1185
|
-
updated.status = 'complete';
|
|
1186
|
-
updated.completedAt = completedAt;
|
|
1187
|
-
delete updated.activeSince;
|
|
1188
|
-
delete updated.blocker;
|
|
1189
|
-
delete updated.stopReason;
|
|
1190
|
-
if (updated.contract) {
|
|
1191
|
-
const currentPlan = updated.contract.planSnapshot;
|
|
1192
|
-
updated.contract = {
|
|
1193
|
-
...updated.contract,
|
|
1194
|
-
planSnapshot: {
|
|
1195
|
-
revision: this.addGoalInteger(currentPlan?.revision ?? 0, 1, 'contract.planSnapshot.revision'),
|
|
1196
|
-
phase: 'complete',
|
|
1197
|
-
steps: currentPlan?.steps ?? [],
|
|
1198
|
-
nextAction: undefined,
|
|
1199
|
-
updatedAt: completedAt,
|
|
1200
|
-
},
|
|
1201
|
-
};
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
else if (updated.contract) {
|
|
1205
|
-
const currentPlan = updated.contract.planSnapshot;
|
|
1206
|
-
updated.contract = {
|
|
1207
|
-
...updated.contract,
|
|
1208
|
-
planSnapshot: {
|
|
1209
|
-
revision: this.addGoalInteger(currentPlan?.revision ?? 0, 1, 'contract.planSnapshot.revision'),
|
|
1210
|
-
phase: 'verification',
|
|
1211
|
-
steps: currentPlan?.steps ?? [],
|
|
1212
|
-
nextAction: audit.remainingRequirements[0],
|
|
1213
|
-
updatedAt: Date.now(),
|
|
1214
|
-
},
|
|
1215
|
-
};
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
else if (terminalRequest.requestedStatus === 'blocked') {
|
|
1219
|
-
const blocker = outcome.blocker;
|
|
1220
|
-
if (blocker) {
|
|
1221
|
-
const fingerprint = blocker.fingerprint;
|
|
1222
|
-
const same = (0, completion_audit_1.blockersMatch)(updated.blocker, fingerprint);
|
|
1223
|
-
const newBlocker = {
|
|
1224
|
-
category: blocker.category,
|
|
1225
|
-
fingerprint,
|
|
1226
|
-
firstSeenAt: same && updated.blocker ? updated.blocker.firstSeenAt : Date.now(),
|
|
1227
|
-
lastSeenAt: Date.now(),
|
|
1228
|
-
consecutiveTurns: same
|
|
1229
|
-
? this.addGoalInteger(updated.blocker?.consecutiveTurns ?? 0, 1, 'blocker.consecutiveTurns')
|
|
1230
|
-
: 1,
|
|
1231
|
-
summary: blocker.summary,
|
|
1232
|
-
retryable: false,
|
|
1233
|
-
};
|
|
1234
|
-
updated.blocker = newBlocker;
|
|
1235
|
-
const blockAudit = (0, completion_audit_1.auditBlocked)({
|
|
1236
|
-
blocker: newBlocker,
|
|
1237
|
-
noProgressCount: updated.noProgressCount,
|
|
1238
|
-
});
|
|
1239
|
-
if (blockAudit.allowed) {
|
|
1240
|
-
updated.status = 'blocked';
|
|
1241
|
-
updated.stopReason = { kind: 'blocked', message: blockAudit.reason, at: Date.now() };
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
if (updated.lastTurn &&
|
|
1247
|
-
!updated.lastTurn.madeProgress &&
|
|
1248
|
-
criterionStateAdvanced(currentContract, updated.contract, evidenceLedger)) {
|
|
1249
|
-
updated.noProgressCount = 0;
|
|
1250
|
-
updated.recentNoProgressTurns = [];
|
|
1251
|
-
updated.lastTurn = { ...updated.lastTurn, madeProgress: true };
|
|
1252
|
-
}
|
|
1253
|
-
const providerStop = (0, accounting_1.classifyStopReason)(outcome.providerError);
|
|
1254
|
-
if (providerStop && updated.status === 'active') {
|
|
1255
|
-
updated.status = providerStop.kind === 'usage_limit' ? 'usage_limited' : 'paused';
|
|
1256
|
-
updated.stopReason = {
|
|
1257
|
-
kind: providerStop.kind,
|
|
1258
|
-
message: providerStop.message,
|
|
1259
|
-
at: Date.now(),
|
|
1260
|
-
};
|
|
1261
|
-
this.state.continuationDeferred = true;
|
|
1262
|
-
}
|
|
1263
|
-
const recentBlockedContinuations = (updated.recentNoProgressTurns ?? []).slice(-types_1.GOAL_INVARIANTS.maxConsecutiveBlockedContinuationTurns);
|
|
1264
|
-
if (outcome.inputKind === 'goal_continuation' &&
|
|
1265
|
-
(updated.automaticContinuationStreak ?? 0) >=
|
|
1266
|
-
types_1.GOAL_INVARIANTS.maxConsecutiveBlockedContinuationTurns &&
|
|
1267
|
-
recentBlockedContinuations.length ===
|
|
1268
|
-
types_1.GOAL_INVARIANTS.maxConsecutiveBlockedContinuationTurns &&
|
|
1269
|
-
recentBlockedContinuations.every(turn => turn.finishReason === 'blocked') &&
|
|
1270
|
-
updated.status === 'active') {
|
|
1271
|
-
updated.status = 'paused';
|
|
1272
|
-
updated.stopReason = {
|
|
1273
|
-
kind: 'user',
|
|
1274
|
-
message: `Auto-paused after ${types_1.GOAL_INVARIANTS.maxConsecutiveBlockedContinuationTurns} blocked autonomous continuations. Inspect the unmet completion gate or external blocker, then use /goal resume to continue or /goal exit to abandon.`,
|
|
1275
|
-
at: Date.now(),
|
|
1276
|
-
};
|
|
1277
|
-
this.state.continuationDeferred = true;
|
|
1278
|
-
}
|
|
1279
|
-
// Auto-pause on no-progress threshold.
|
|
1280
|
-
if (updated.noProgressCount >= types_1.GOAL_INVARIANTS.maxConsecutiveNoProgressTurns &&
|
|
1281
|
-
updated.status === 'active') {
|
|
1282
|
-
updated.status = 'paused';
|
|
1283
|
-
const recent = updated.recentNoProgressTurns ?? [];
|
|
1284
|
-
updated.stopReason = {
|
|
1285
|
-
kind: 'user',
|
|
1286
|
-
message: `Auto-paused: no progress for ${types_1.GOAL_INVARIANTS.maxConsecutiveNoProgressTurns} consecutive turns. Recent turns: ${formatNoProgressTurns(recent)}.`,
|
|
1287
|
-
at: Date.now(),
|
|
1288
|
-
};
|
|
1289
|
-
this.state.continuationDeferred = true;
|
|
1290
|
-
}
|
|
1291
|
-
// A Goal may make genuine progress indefinitely, but it must not run
|
|
1292
|
-
// indefinitely without another human decision point. Pause instead of
|
|
1293
|
-
// deleting state so the user can inspect, resume, or explicitly abandon it.
|
|
1294
|
-
if ((updated.automaticContinuationStreak ?? 0) >= types_1.GOAL_INVARIANTS.maxAutomaticContinuationTurns &&
|
|
1295
|
-
updated.status === 'active') {
|
|
1296
|
-
updated.status = 'paused';
|
|
1297
|
-
updated.stopReason = {
|
|
1298
|
-
kind: 'user',
|
|
1299
|
-
message: `Auto-paused after ${types_1.GOAL_INVARIANTS.maxAutomaticContinuationTurns} consecutive autonomous continuations. Review progress, then use /goal resume to continue or /goal exit to abandon.`,
|
|
1300
|
-
at: Date.now(),
|
|
1301
|
-
};
|
|
1302
|
-
this.state.continuationDeferred = true;
|
|
1303
|
-
}
|
|
1304
|
-
// Budget limit.
|
|
1305
|
-
if ((0, accounting_1.isBudgetExceeded)(updated.tokensUsed, updated.tokenBudget) && updated.status === 'active') {
|
|
1306
|
-
updated.status = 'budget_limited';
|
|
1307
|
-
updated.stopReason = {
|
|
1308
|
-
kind: 'budget_limit',
|
|
1309
|
-
message: `Token budget reached: ${updated.tokensUsed}/${updated.tokenBudget}`,
|
|
1310
|
-
at: Date.now(),
|
|
1311
|
-
};
|
|
1312
|
-
}
|
|
1313
|
-
this.state.goal = updated;
|
|
1314
|
-
this.persist();
|
|
1315
|
-
}
|
|
1316
|
-
/**
|
|
1317
|
-
* Account an interrupted turn whose request revision was superseded by live steering.
|
|
1318
|
-
*
|
|
1319
|
-
* This deliberately ignores every semantic payload on the stale outcome: evidence,
|
|
1320
|
-
* plan updates, blockers, and terminal requests belong to the old contract revision.
|
|
1321
|
-
* Only already-incurred token/time/turn accounting is retained, without changing the
|
|
1322
|
-
* revised Goal's no-progress streak.
|
|
1323
|
-
*/
|
|
1324
|
-
accountStaleTurn(outcome) {
|
|
1325
|
-
const g = this.state.goal;
|
|
1326
|
-
if (!g ||
|
|
1327
|
-
outcome.sessionId !== this.sessionId ||
|
|
1328
|
-
outcome.goalId !== g.goalId ||
|
|
1329
|
-
outcome.goalRevision === undefined ||
|
|
1330
|
-
outcome.goalRevision >= g.revision ||
|
|
1331
|
-
(outcome.goalGeneration !== undefined && outcome.goalGeneration !== this.state.generation)) {
|
|
1332
|
-
return false;
|
|
1333
|
-
}
|
|
1334
|
-
const key = `${outcome.goalId}:${outcome.goalGeneration ?? this.state.generation}:${outcome.turnId}`;
|
|
1335
|
-
if (this.accountedStaleTurnKeys.has(key))
|
|
1336
|
-
return false;
|
|
1337
|
-
const endedAt = Math.max(outcome.startedAt, outcome.endedAt);
|
|
1338
|
-
const elapsedMs = endedAt - outcome.startedAt;
|
|
1339
|
-
const tokensUsed = this.addGoalInteger(g.tokensUsed, Math.max(0, outcome.usage.totalTokens), 'tokensUsed');
|
|
1340
|
-
const timeUsedMs = this.addGoalInteger(g.timeUsedMs, elapsedMs, 'timeUsedMs');
|
|
1341
|
-
const continuationCount = this.addGoalInteger(g.continuationCount, 1, 'continuationCount');
|
|
1342
|
-
const revision = this.addGoalInteger(g.revision, 1, 'revision');
|
|
1343
|
-
this.accountedStaleTurnKeys.add(key);
|
|
1344
|
-
const updated = {
|
|
1345
|
-
...g,
|
|
1346
|
-
tokensUsed,
|
|
1347
|
-
timeUsedMs,
|
|
1348
|
-
continuationCount,
|
|
1349
|
-
automaticContinuationStreak: 0,
|
|
1350
|
-
revision,
|
|
1351
|
-
updatedAt: Date.now(),
|
|
1352
|
-
lastTurn: {
|
|
1353
|
-
turnId: outcome.turnId,
|
|
1354
|
-
finishReason: outcome.finishReason,
|
|
1355
|
-
endedAt,
|
|
1356
|
-
promptTokens: Math.max(0, outcome.usage.promptTokens),
|
|
1357
|
-
completionTokens: Math.max(0, outcome.usage.completionTokens),
|
|
1358
|
-
subagentTokens: Math.max(0, outcome.usage.subagentTokens),
|
|
1359
|
-
totalTokens: Math.max(0, outcome.usage.totalTokens),
|
|
1360
|
-
madeProgress: false,
|
|
1361
|
-
},
|
|
1362
|
-
};
|
|
1363
|
-
if ((0, accounting_1.isBudgetExceeded)(updated.tokensUsed, updated.tokenBudget) && updated.status === 'active') {
|
|
1364
|
-
updated.status = 'budget_limited';
|
|
1365
|
-
updated.stopReason = {
|
|
1366
|
-
kind: 'budget_limit',
|
|
1367
|
-
message: `Token budget reached: ${updated.tokensUsed}/${updated.tokenBudget}`,
|
|
1368
|
-
at: Date.now(),
|
|
1369
|
-
};
|
|
1370
|
-
this.state.continuationDeferred = true;
|
|
1371
|
-
}
|
|
1372
|
-
this.state.goal = updated;
|
|
1373
|
-
try {
|
|
1374
|
-
this.persist();
|
|
1375
|
-
}
|
|
1376
|
-
catch (error) {
|
|
1377
|
-
// The key protects an in-flight attempt, but a failed pre-commit save did
|
|
1378
|
-
// not durably account the turn. Release it only after persist() restores
|
|
1379
|
-
// disk authority so the same outcome can be retried exactly once.
|
|
1380
|
-
this.accountedStaleTurnKeys.delete(key);
|
|
1381
|
-
throw error;
|
|
1382
|
-
}
|
|
1383
|
-
return true;
|
|
1384
|
-
}
|
|
1385
|
-
deferContinuation() {
|
|
1386
|
-
if (!this.state.goal || this.state.goal.status !== 'active')
|
|
1387
|
-
return;
|
|
1388
|
-
this.state.continuationDeferred = true;
|
|
1389
|
-
const g = this.state.goal;
|
|
1390
|
-
this.state.goal = {
|
|
1391
|
-
...g,
|
|
1392
|
-
status: 'paused',
|
|
1393
|
-
revision: this.addGoalInteger(g.revision, 1, 'revision'),
|
|
1394
|
-
updatedAt: Date.now(),
|
|
1395
|
-
stopReason: { kind: 'user', message: 'Paused by interrupt.', at: Date.now() },
|
|
1396
|
-
};
|
|
1397
|
-
this.persist();
|
|
1398
|
-
}
|
|
1399
|
-
limitBudget(reason) {
|
|
1400
|
-
const goal = this.state.goal;
|
|
1401
|
-
if (!goal || goal.status !== 'active')
|
|
1402
|
-
return;
|
|
1403
|
-
this.state.goal = {
|
|
1404
|
-
...goal,
|
|
1405
|
-
status: 'budget_limited',
|
|
1406
|
-
revision: this.addGoalInteger(goal.revision, 1, 'revision'),
|
|
1407
|
-
updatedAt: Date.now(),
|
|
1408
|
-
stopReason: { kind: 'budget_limit', message: reason, at: Date.now() },
|
|
1409
|
-
};
|
|
1410
|
-
this.state.continuationDeferred = true;
|
|
1411
|
-
this.persist();
|
|
1412
|
-
}
|
|
1413
|
-
/**
|
|
1414
|
-
* Apply a runtime-only safety overlay after a mutation failed to persist.
|
|
1415
|
-
* `persist()` has already restored the disk-authoritative Goal. Keep its
|
|
1416
|
-
* revision intact so `/target resume` can save normally once storage recovers,
|
|
1417
|
-
* while invalidating every in-flight request and queued continuation now.
|
|
1418
|
-
*/
|
|
1419
|
-
failClosedAfterPersistenceError(reason) {
|
|
1420
|
-
const goal = this.state.goal;
|
|
1421
|
-
this.state.generation += 1;
|
|
1422
|
-
this.state.continuationDeferred = true;
|
|
1423
|
-
if (!goal || goal.status === 'complete')
|
|
1424
|
-
return;
|
|
1425
|
-
this.state.goal = {
|
|
1426
|
-
...goal,
|
|
1427
|
-
status: 'paused',
|
|
1428
|
-
updatedAt: Date.now(),
|
|
1429
|
-
stopReason: {
|
|
1430
|
-
kind: 'runtime_error',
|
|
1431
|
-
message: (0, redaction_1.redactTraceText)(reason).slice(0, 600),
|
|
1432
|
-
at: Date.now(),
|
|
1433
|
-
},
|
|
1434
|
-
};
|
|
1435
|
-
}
|
|
1436
|
-
// ==========================================================================
|
|
1437
|
-
// Persistence
|
|
1438
|
-
// ==========================================================================
|
|
1439
|
-
/** Restore disk authority without reviving a deletion-fenced Goal. */
|
|
1440
|
-
restoreDiskAuthorityAfterMutationFailure() {
|
|
1441
|
-
const persisted = (0, goal_storage_1.loadGoal)(this.projectPath, this.sessionId);
|
|
1442
|
-
if (persisted.ok) {
|
|
1443
|
-
this.loadRecoveryRequired = false;
|
|
1444
|
-
this.state.goal = ensureContract(persisted.value);
|
|
1445
|
-
this.persistedGoalSnapshot = structuredClone(this.state.goal);
|
|
1446
|
-
this.state.continuationDeferred = true;
|
|
1447
|
-
return;
|
|
1448
|
-
}
|
|
1449
|
-
if (persisted.error === 'not_found') {
|
|
1450
|
-
this.loadRecoveryRequired = false;
|
|
1451
|
-
this.state.goal = null;
|
|
1452
|
-
this.persistedGoalSnapshot = null;
|
|
1453
|
-
this.state.generation += 1;
|
|
1454
|
-
this.state.continuationDeferred = false;
|
|
1455
|
-
return;
|
|
1456
|
-
}
|
|
1457
|
-
if (this.persistedGoalSnapshot) {
|
|
1458
|
-
this.state.goal = structuredClone(this.persistedGoalSnapshot);
|
|
1459
|
-
}
|
|
1460
|
-
else {
|
|
1461
|
-
this.state.goal = null;
|
|
1462
|
-
}
|
|
1463
|
-
this.loadRecoveryRequired = true;
|
|
1464
|
-
this.state.continuationDeferred = true;
|
|
1465
|
-
}
|
|
1466
|
-
persist() {
|
|
1467
|
-
if (!this.state.goal)
|
|
1468
|
-
return;
|
|
1469
|
-
const result = (0, goal_storage_1.saveGoal)(this.projectPath, this.sessionId, this.state.goal, Math.max(0, this.state.goal.revision - 1));
|
|
1470
|
-
if (result.ok) {
|
|
1471
|
-
this.persistedGoalSnapshot = structuredClone(this.state.goal);
|
|
1472
|
-
return;
|
|
1473
|
-
}
|
|
1474
|
-
if (!result.ok) {
|
|
1475
|
-
this.restoreDiskAuthorityAfterMutationFailure();
|
|
1476
|
-
throw new Error(`Goal persistence failed (${result.error}): ${result.message}`);
|
|
1477
|
-
}
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
exports.GoalCoordinator = GoalCoordinator;
|
|
1481
|
-
//# sourceMappingURL=coordinator.js.map
|