@orion-agents/orion-code 0.1.9 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +85 -0
- package/README.md +142 -323
- package/README.zh-CN.md +118 -578
- package/dist/cli.js +65 -84
- 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 +132 -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 +1 -1
- package/dist/commands/model-command-handlers.js +2 -2
- 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 +1 -1
- package/dist/commands/session-command-handlers.d.ts.map +1 -1
- package/dist/commands/session-command-handlers.js +52 -214
- 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 +0 -48
- 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 +10 -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 +3 -3
- package/dist/framework/index.d.ts.map +1 -1
- package/dist/framework/index.js +6 -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 +45 -22
- package/dist/framework/query.d.ts.map +1 -1
- package/dist/framework/query.js +64 -52
- package/dist/framework/query.js.map +1 -1
- 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/index.d.ts +70 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +64 -65
- package/dist/index.js.map +1 -1
- 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 +80 -0
- package/dist/runtime/agent-loop.d.ts.map +1 -0
- package/dist/runtime/agent-loop.js +419 -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 +270 -1216
- 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 +36 -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 +111 -0
- package/dist/runtime/goal-runtime-coordinator.d.ts.map +1 -0
- package/dist/runtime/goal-runtime-coordinator.js +511 -0
- package/dist/runtime/goal-runtime-coordinator.js.map +1 -0
- 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/orion-runtime-v1.d.ts +322 -0
- package/dist/runtime/orion-runtime-v1.d.ts.map +1 -0
- package/dist/runtime/orion-runtime-v1.js +959 -0
- package/dist/runtime/orion-runtime-v1.js.map +1 -0
- package/dist/runtime/orion-session-runner.d.ts +38 -0
- package/dist/runtime/orion-session-runner.d.ts.map +1 -0
- package/dist/runtime/orion-session-runner.js +168 -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 +1047 -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 +110 -0
- package/dist/runtime/release-receipts.d.ts.map +1 -0
- package/dist/runtime/release-receipts.js +305 -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/session-history-recovery.d.ts +19 -0
- package/dist/runtime/session-history-recovery.d.ts.map +1 -0
- package/dist/runtime/session-history-recovery.js +45 -0
- package/dist/runtime/session-history-recovery.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 +4 -1
- 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 -46
- package/dist/runtime/subagents/production.d.ts.map +1 -1
- package/dist/runtime/subagents/production.js +494 -170
- 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/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 -198
- 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 +83 -40
- package/dist/runtime/subagents/supervisor.js.map +1 -1
- package/dist/runtime/subagents/types.d.ts +1 -1
- package/dist/runtime/subagents/types.js +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-session-view.d.ts +45 -0
- package/dist/runtime/thread-session-view.d.ts.map +1 -0
- package/dist/runtime/thread-session-view.js +264 -0
- package/dist/runtime/thread-session-view.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 +87 -0
- package/dist/runtime/thread-ui-adapter.d.ts.map +1 -0
- package/dist/runtime/thread-ui-adapter.js +580 -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 +2 -1
- package/dist/runtime/ui-view-model.d.ts.map +1 -1
- package/dist/runtime/ui-view-model.js +6 -5
- package/dist/runtime/ui-view-model.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-lock.d.ts.map +1 -1
- package/dist/services/file-lock.js +42 -17
- package/dist/services/file-lock.js.map +1 -1
- package/dist/services/global-config.d.ts +2 -2
- package/dist/services/global-config.d.ts.map +1 -1
- package/dist/services/session-storage.d.ts +8 -0
- package/dist/services/session-storage.d.ts.map +1 -1
- package/dist/services/session-storage.js +76 -12
- package/dist/services/session-storage.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 +21 -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/tools/web.js +1 -1
- package/dist/tools/web.js.map +1 -1
- package/dist/tui-ui/chrome-view-model.d.ts.map +1 -1
- package/dist/tui-ui/chrome-view-model.js +22 -8
- package/dist/tui-ui/chrome-view-model.js.map +1 -1
- package/dist/tui-ui/launch.d.ts.map +1 -1
- package/dist/tui-ui/launch.js +13 -0
- package/dist/tui-ui/launch.js.map +1 -1
- package/dist/tui-ui/layout.js +1 -1
- package/dist/tui-ui/layout.js.map +1 -1
- package/dist/tui-ui/state.d.ts.map +1 -1
- package/dist/tui-ui/state.js +2 -0
- package/dist/tui-ui/state.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 +8 -8
- package/npm-shrinkwrap.json +45 -450
- package/package.json +17 -13
- 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 -291
- package/dist/agents/coordinator.js.map +0 -1
- package/dist/agents/fork.d.ts +0 -73
- package/dist/agents/fork.d.ts.map +0 -1
- package/dist/agents/fork.js +0 -163
- 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 -229
- 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 -191
- package/dist/framework/tool-scheduler.d.ts.map +0 -1
- package/dist/framework/tool-scheduler.js +0 -573
- 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 -27
- package/dist/ink-ui/screens/ReplScreen.d.ts.map +0 -1
- package/dist/ink-ui/screens/ReplScreen.js +0 -781
- 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-compact.d.ts +0 -26
- package/dist/runtime/chat-compact.d.ts.map +0 -1
- package/dist/runtime/chat-compact.js +0 -132
- package/dist/runtime/chat-compact.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 -1620
- 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 -92
- package/dist/runtime/goals/coordinator.d.ts.map +0 -1
- package/dist/runtime/goals/coordinator.js +0 -1471
- 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/stop-policy.d.ts +0 -9
- package/dist/runtime/goals/stop-policy.d.ts.map +0 -1
- package/dist/runtime/goals/stop-policy.js +0 -83
- package/dist/runtime/goals/stop-policy.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/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 -363
- 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
- package/docs/migration/v0.1.8-to-v0.1.9.md +0 -60
- package/docs/plan/v0.1.9-release-checklist.md +0 -64
|
@@ -0,0 +1,737 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ThreadEventStore = exports.ThreadEventStoreError = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const atomic_write_1 = require("../services/atomic-write");
|
|
7
|
+
const file_lock_1 = require("../services/file-lock");
|
|
8
|
+
const canonical_1 = require("./protocol/canonical");
|
|
9
|
+
const runtime_protocol_v1_1 = require("./protocol/runtime-protocol-v1");
|
|
10
|
+
const thread_projection_1 = require("./thread-projection");
|
|
11
|
+
class ThreadEventStoreError extends Error {
|
|
12
|
+
constructor(code, message, offset) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.offset = offset;
|
|
16
|
+
this.name = 'ThreadEventStoreError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.ThreadEventStoreError = ThreadEventStoreError;
|
|
20
|
+
const DEFAULT_MAX_LOG_BYTES = 128 * 1024 * 1024;
|
|
21
|
+
const DEFAULT_MAX_REPLAY_EVENTS = 10000;
|
|
22
|
+
const DEFAULT_LOCK_WAIT_MS = 10000;
|
|
23
|
+
/**
|
|
24
|
+
* Append-only durable fact store for a single Thread.
|
|
25
|
+
*
|
|
26
|
+
* The log is authoritative. Its projection is an atomic, rebuildable cache and
|
|
27
|
+
* is never returned when it is ahead of or divergent from the durable cursor.
|
|
28
|
+
*/
|
|
29
|
+
class ThreadEventStore {
|
|
30
|
+
constructor(rootDir, threadId, options = {}) {
|
|
31
|
+
this.rootDir = rootDir;
|
|
32
|
+
this.threadId = threadId;
|
|
33
|
+
this.commitListeners = new Set();
|
|
34
|
+
if (!(0, runtime_protocol_v1_1.isRuntimeId)(threadId)) {
|
|
35
|
+
throw new ThreadEventStoreError('ORION_THREAD_EVENT_IDENTITY', `ThreadEventStore threadId must be a UUID: ${threadId}`);
|
|
36
|
+
}
|
|
37
|
+
this.logPath = (0, path_1.join)(rootDir, `${threadId}.events.v1.jsonl`);
|
|
38
|
+
this.projectionPath = (0, path_1.join)(rootDir, `${threadId}.projection.v1.json`);
|
|
39
|
+
this.compactStatePath = (0, path_1.join)(rootDir, `${threadId}.compact-state.v1.json`);
|
|
40
|
+
this.compactCheckpointsDir = (0, path_1.join)(rootDir, `${threadId}.compact-checkpoints.v1`);
|
|
41
|
+
this.maxLogBytes = positiveInteger(options.maxLogBytes ?? DEFAULT_MAX_LOG_BYTES, 'maxLogBytes');
|
|
42
|
+
this.maxReplayEvents = positiveInteger(options.maxReplayEvents ?? DEFAULT_MAX_REPLAY_EVENTS, 'maxReplayEvents');
|
|
43
|
+
this.lockWaitMs = positiveInteger(options.lockWaitMs ?? DEFAULT_LOCK_WAIT_MS, 'lockWaitMs');
|
|
44
|
+
this.clock = options.clock ?? Date.now;
|
|
45
|
+
this.idFactory = options.idFactory ?? runtime_protocol_v1_1.createRuntimeId;
|
|
46
|
+
this.onBoundary = options.onBoundary;
|
|
47
|
+
}
|
|
48
|
+
appendDurable(input) {
|
|
49
|
+
return this.appendDurableBatch([input]).events[0];
|
|
50
|
+
}
|
|
51
|
+
appendDurableBatch(inputs) {
|
|
52
|
+
if (inputs.length === 0) {
|
|
53
|
+
return { events: [], projection: this.loadProjection() };
|
|
54
|
+
}
|
|
55
|
+
const commit = this.withLogLock(() => {
|
|
56
|
+
ensurePrivateDirectory(this.rootDir);
|
|
57
|
+
const scan = scanThreadEventLog(this.logPath, this.threadId, this.maxLogBytes);
|
|
58
|
+
if (scan.discardedTailBytes > 0)
|
|
59
|
+
(0, fs_1.truncateSync)(this.logPath, scan.safeByteLength);
|
|
60
|
+
let seq = scan.events.length;
|
|
61
|
+
let previousHash = scan.records.at(-1)?.hash ?? null;
|
|
62
|
+
const records = [];
|
|
63
|
+
const eventIds = new Set(scan.events.map(event => event.eventId));
|
|
64
|
+
for (const input of inputs) {
|
|
65
|
+
seq += 1;
|
|
66
|
+
const eventId = this.idFactory();
|
|
67
|
+
if (!(0, runtime_protocol_v1_1.isRuntimeId)(eventId) || eventIds.has(eventId)) {
|
|
68
|
+
throw new ThreadEventStoreError('ORION_THREAD_EVENT_IDENTITY', `Event ID factory returned an invalid or duplicate UUID: ${eventId}`);
|
|
69
|
+
}
|
|
70
|
+
eventIds.add(eventId);
|
|
71
|
+
const event = {
|
|
72
|
+
protocolVersion: 1,
|
|
73
|
+
eventId,
|
|
74
|
+
seq,
|
|
75
|
+
threadId: this.threadId,
|
|
76
|
+
turnId: input.turnId,
|
|
77
|
+
stepId: input.stepId,
|
|
78
|
+
itemId: input.itemId,
|
|
79
|
+
durability: 'durable',
|
|
80
|
+
timestamp: input.timestamp ?? this.clock(),
|
|
81
|
+
payload: input.payload,
|
|
82
|
+
};
|
|
83
|
+
(0, runtime_protocol_v1_1.assertRuntimeEventEnvelopeV1)(event);
|
|
84
|
+
const hash = (0, canonical_1.digestRuntimeValue)({ version: 1, previousHash, event });
|
|
85
|
+
records.push({ version: 1, previousHash, hash, event });
|
|
86
|
+
previousHash = hash;
|
|
87
|
+
}
|
|
88
|
+
// Validate the complete lifecycle before a byte becomes durable. A bad
|
|
89
|
+
// duplicate terminal event must never poison the append-only fact log.
|
|
90
|
+
const allEvents = [...scan.events, ...records.map(record => record.event)];
|
|
91
|
+
const projection = (0, thread_projection_1.projectThreadEvents)(this.threadId, allEvents);
|
|
92
|
+
this.boundary('before_log_write', seq);
|
|
93
|
+
appendRecordsAndFlush(this.logPath, records, () => this.boundary('after_log_write', seq));
|
|
94
|
+
// appendRecordsAndFlush fsyncs before returning; this boundary is the
|
|
95
|
+
// point after which consumers may safely publish success notifications.
|
|
96
|
+
this.boundary('after_log_flush', seq);
|
|
97
|
+
fsyncDirectory(this.rootDir);
|
|
98
|
+
this.boundary('before_projection_write', seq);
|
|
99
|
+
writeProjection(this.projectionPath, projection);
|
|
100
|
+
fsyncDirectory(this.rootDir);
|
|
101
|
+
this.boundary('after_projection_write', seq);
|
|
102
|
+
return deepFreeze({ events: records.map(record => record.event), projection });
|
|
103
|
+
});
|
|
104
|
+
this.notifyCommitted(commit.events);
|
|
105
|
+
return commit;
|
|
106
|
+
}
|
|
107
|
+
/** Observe locally committed durable facts after log and projection fsync. */
|
|
108
|
+
subscribeCommitted(listener) {
|
|
109
|
+
this.commitListeners.add(listener);
|
|
110
|
+
return () => this.commitListeners.delete(listener);
|
|
111
|
+
}
|
|
112
|
+
createEphemeral(input) {
|
|
113
|
+
const cursor = this.getCursor();
|
|
114
|
+
const event = {
|
|
115
|
+
protocolVersion: 1,
|
|
116
|
+
eventId: this.idFactory(),
|
|
117
|
+
seq: cursor,
|
|
118
|
+
threadId: this.threadId,
|
|
119
|
+
turnId: input.turnId,
|
|
120
|
+
stepId: input.stepId,
|
|
121
|
+
itemId: input.itemId,
|
|
122
|
+
durability: 'ephemeral',
|
|
123
|
+
timestamp: input.timestamp ?? this.clock(),
|
|
124
|
+
payload: input.payload,
|
|
125
|
+
};
|
|
126
|
+
(0, runtime_protocol_v1_1.assertRuntimeEventEnvelopeV1)(event);
|
|
127
|
+
return deepFreeze(event);
|
|
128
|
+
}
|
|
129
|
+
replay(cursor = 0, limit = this.maxReplayEvents) {
|
|
130
|
+
if (!Number.isSafeInteger(cursor) || cursor < 0) {
|
|
131
|
+
throw new ThreadEventStoreError('ORION_THREAD_EVENT_CURSOR', 'Replay cursor must be a non-negative safe integer');
|
|
132
|
+
}
|
|
133
|
+
const safeLimit = positiveInteger(limit, 'replay limit');
|
|
134
|
+
if (safeLimit > this.maxReplayEvents) {
|
|
135
|
+
throw new ThreadEventStoreError('ORION_THREAD_EVENT_LIMIT', `Replay limit ${safeLimit} exceeds ${this.maxReplayEvents}`);
|
|
136
|
+
}
|
|
137
|
+
return this.withLogLock(() => {
|
|
138
|
+
const scan = scanThreadEventLog(this.logPath, this.threadId, this.maxLogBytes);
|
|
139
|
+
const lastSeq = scan.events.length;
|
|
140
|
+
if (cursor > lastSeq) {
|
|
141
|
+
throw new ThreadEventStoreError('ORION_THREAD_EVENT_CURSOR', `Replay cursor ${cursor} is ahead of durable cursor ${lastSeq}`);
|
|
142
|
+
}
|
|
143
|
+
const events = scan.events.slice(cursor, cursor + safeLimit);
|
|
144
|
+
const nextCursor = events.at(-1)?.seq ?? cursor;
|
|
145
|
+
return deepFreeze({
|
|
146
|
+
events,
|
|
147
|
+
fromCursor: cursor,
|
|
148
|
+
nextCursor,
|
|
149
|
+
hasMore: nextCursor < lastSeq,
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
getCursor() {
|
|
154
|
+
return this.withLogLock(() => scanThreadEventLog(this.logPath, this.threadId, this.maxLogBytes).events.length);
|
|
155
|
+
}
|
|
156
|
+
loadProjection() {
|
|
157
|
+
return this.withLogLock(() => {
|
|
158
|
+
ensurePrivateDirectory(this.rootDir);
|
|
159
|
+
const scan = scanThreadEventLog(this.logPath, this.threadId, this.maxLogBytes);
|
|
160
|
+
const replayed = (0, thread_projection_1.projectThreadEvents)(this.threadId, scan.events);
|
|
161
|
+
const cached = readProjection(this.projectionPath);
|
|
162
|
+
if (cached &&
|
|
163
|
+
cached.threadId === this.threadId &&
|
|
164
|
+
cached.cursor === replayed.cursor &&
|
|
165
|
+
cached.digest === replayed.digest &&
|
|
166
|
+
(0, thread_projection_1.verifyThreadProjectionDigest)(cached)) {
|
|
167
|
+
return deepFreeze(cached);
|
|
168
|
+
}
|
|
169
|
+
writeProjection(this.projectionPath, replayed);
|
|
170
|
+
fsyncDirectory(this.rootDir);
|
|
171
|
+
return replayed;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Load exactly the history selected by the latest committed TurnCommit or,
|
|
176
|
+
* when newer, the atomically-installed Compact checkpoint pointer.
|
|
177
|
+
*/
|
|
178
|
+
loadAuthoritativeModelHistory() {
|
|
179
|
+
return this.withLogLock(() => {
|
|
180
|
+
const scan = scanThreadEventLog(this.logPath, this.threadId, this.maxLogBytes);
|
|
181
|
+
const state = readCompactState(this.compactStatePath, this.threadId);
|
|
182
|
+
if (state)
|
|
183
|
+
this.assertCompactCheckpoint(state);
|
|
184
|
+
const turnState = readLatestDurableTurnState(scan.events, this.threadId);
|
|
185
|
+
if (!state && !turnState)
|
|
186
|
+
return undefined;
|
|
187
|
+
return resolveCompactAuthority(scan.events, state, this.threadId).history;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Capture the history and TaskContext that a maintenance compact is allowed
|
|
192
|
+
* to replace. The event log and compact pointer are read under the same lock.
|
|
193
|
+
*/
|
|
194
|
+
captureCompactSource(turnId) {
|
|
195
|
+
return this.withLogLock(() => {
|
|
196
|
+
ensurePrivateDirectory(this.rootDir);
|
|
197
|
+
const scan = scanThreadEventLog(this.logPath, this.threadId, this.maxLogBytes);
|
|
198
|
+
const projection = (0, thread_projection_1.projectThreadEvents)(this.threadId, scan.events);
|
|
199
|
+
assertActiveMaintenanceTurn(projection, turnId);
|
|
200
|
+
const state = readCompactState(this.compactStatePath, this.threadId);
|
|
201
|
+
if (state)
|
|
202
|
+
this.assertCompactCheckpoint(state);
|
|
203
|
+
const authoritative = resolveCompactAuthority(scan.events, state, this.threadId);
|
|
204
|
+
return deepFreeze({
|
|
205
|
+
threadId: this.threadId,
|
|
206
|
+
maintenanceTurn: {
|
|
207
|
+
turnId,
|
|
208
|
+
mode: 'maintenance',
|
|
209
|
+
active: true,
|
|
210
|
+
steerable: false,
|
|
211
|
+
},
|
|
212
|
+
cursor: projection.cursor,
|
|
213
|
+
projectionDigest: projection.digest,
|
|
214
|
+
history: authoritative.history,
|
|
215
|
+
taskContext: authoritative.taskContext,
|
|
216
|
+
taskContextRevision: authoritative.taskContextRevision,
|
|
217
|
+
activeCheckpointId: state?.pointer.checkpointId ?? null,
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* The only compact pointer commit boundary. Cursor/projection, history,
|
|
223
|
+
* TaskContext and the previous pointer are rechecked while the log lock is
|
|
224
|
+
* held; the checkpoint is durable before one atomic state-file rename makes
|
|
225
|
+
* the new pointer and model-visible history authoritative together.
|
|
226
|
+
*/
|
|
227
|
+
appendCompactCheckpointCas(input) {
|
|
228
|
+
return this.withLogLock(() => {
|
|
229
|
+
ensurePrivateDirectory(this.rootDir);
|
|
230
|
+
ensurePrivateDirectory(this.compactCheckpointsDir);
|
|
231
|
+
validateCompactCommitInput(input, this.threadId);
|
|
232
|
+
input.onBoundary('before_cas_recheck');
|
|
233
|
+
const scan = scanThreadEventLog(this.logPath, this.threadId, this.maxLogBytes);
|
|
234
|
+
const projection = (0, thread_projection_1.projectThreadEvents)(this.threadId, scan.events);
|
|
235
|
+
const eventsAfterAnchor = scan.events.slice(input.expectedEventAnchor.cursor);
|
|
236
|
+
const onlyQueuedFollowUps = eventsAfterAnchor.length > 0 &&
|
|
237
|
+
eventsAfterAnchor.every(event => event.payload.type === 'turn.queued');
|
|
238
|
+
if (projection.cursor !== input.expectedEventAnchor.cursor && !onlyQueuedFollowUps) {
|
|
239
|
+
return { status: 'conflict', reason: 'cursor_changed' };
|
|
240
|
+
}
|
|
241
|
+
if (projection.digest !== input.expectedEventAnchor.projectionDigest &&
|
|
242
|
+
!onlyQueuedFollowUps) {
|
|
243
|
+
return { status: 'conflict', reason: 'projection_changed' };
|
|
244
|
+
}
|
|
245
|
+
assertActiveMaintenanceTurn(projection, input.source.turnId);
|
|
246
|
+
const previousState = readCompactState(this.compactStatePath, this.threadId);
|
|
247
|
+
if (previousState)
|
|
248
|
+
this.assertCompactCheckpoint(previousState);
|
|
249
|
+
const authoritative = resolveCompactAuthority(scan.events, previousState, this.threadId);
|
|
250
|
+
if (authoritative.historyDigest !== input.source.historyDigest) {
|
|
251
|
+
return { status: 'conflict', reason: 'history_changed' };
|
|
252
|
+
}
|
|
253
|
+
if (authoritative.taskContextDigest !== input.source.taskContextDigest) {
|
|
254
|
+
return { status: 'conflict', reason: 'task_context_changed' };
|
|
255
|
+
}
|
|
256
|
+
if (authoritative.taskContextRevision !== input.source.taskContextRevision) {
|
|
257
|
+
return { status: 'conflict', reason: 'task_context_revision_changed' };
|
|
258
|
+
}
|
|
259
|
+
if ((previousState?.pointer.checkpointId ?? null) !== input.source.activeCheckpointId) {
|
|
260
|
+
return { status: 'conflict', reason: 'checkpoint_pointer_changed' };
|
|
261
|
+
}
|
|
262
|
+
input.onBoundary('after_cas_recheck');
|
|
263
|
+
const checkpoint = createStoredCompactCheckpoint(this.threadId, input);
|
|
264
|
+
const checkpointPath = (0, path_1.join)(this.compactCheckpointsDir, `${input.candidate.checkpointId}.json`);
|
|
265
|
+
const existingCheckpoint = readStoredCompactCheckpoint(checkpointPath, this.threadId);
|
|
266
|
+
if (existingCheckpoint && existingCheckpoint.digest !== checkpoint.digest) {
|
|
267
|
+
throw new ThreadEventStoreError('ORION_THREAD_COMPACT_CONFLICT', `Compact checkpoint ${input.candidate.checkpointId} already contains different data`);
|
|
268
|
+
}
|
|
269
|
+
if (!existingCheckpoint) {
|
|
270
|
+
(0, atomic_write_1.atomicWriteFileSync)(checkpointPath, `${(0, canonical_1.canonicalRuntimeJson)(checkpoint)}\n`, {
|
|
271
|
+
mode: 0o600,
|
|
272
|
+
fsync: true,
|
|
273
|
+
});
|
|
274
|
+
fsyncDirectory(this.compactCheckpointsDir);
|
|
275
|
+
}
|
|
276
|
+
input.onBoundary('after_checkpoint_write');
|
|
277
|
+
const state = createStoredCompactState(this.threadId, input, authoritative.taskContext, authoritative.taskContextRevision);
|
|
278
|
+
(0, atomic_write_1.atomicWriteFileSync)(this.compactStatePath, `${(0, canonical_1.canonicalRuntimeJson)(state)}\n`, {
|
|
279
|
+
mode: 0o600,
|
|
280
|
+
fsync: true,
|
|
281
|
+
});
|
|
282
|
+
fsyncDirectory(this.rootDir);
|
|
283
|
+
input.onBoundary('after_pointer_commit');
|
|
284
|
+
return deepFreeze({ status: 'committed', pointer: input.commit.pointer });
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
findCompactCheckpointCommit(turnId, sourceSeq) {
|
|
288
|
+
return this.withLogLock(() => {
|
|
289
|
+
const state = readCompactState(this.compactStatePath, this.threadId);
|
|
290
|
+
if (!state)
|
|
291
|
+
return undefined;
|
|
292
|
+
return state.commit.turnId === turnId && state.commit.source.cursor === sourceSeq
|
|
293
|
+
? state.commit
|
|
294
|
+
: undefined;
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
listCompactEvents() {
|
|
298
|
+
return this.withLogLock(() => {
|
|
299
|
+
const scan = scanThreadEventLog(this.logPath, this.threadId, this.maxLogBytes);
|
|
300
|
+
return deepFreeze(scan.events.filter((event) => event.payload.type === 'compact.started' ||
|
|
301
|
+
event.payload.type === 'compact.completed' ||
|
|
302
|
+
event.payload.type === 'compact.failed'));
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Converts orphaned started items to an explicit indeterminate terminal
|
|
307
|
+
* state, then interrupts their active turn. This never guesses success.
|
|
308
|
+
*/
|
|
309
|
+
recoverIncomplete(reason = 'runtime_restarted_before_terminal_commit') {
|
|
310
|
+
const projection = this.loadProjection();
|
|
311
|
+
const openItems = Object.values(projection.items).filter(item => item.status === 'started');
|
|
312
|
+
const inputs = openItems.map(item => ({
|
|
313
|
+
turnId: item.turnId,
|
|
314
|
+
stepId: item.stepId,
|
|
315
|
+
itemId: item.itemId,
|
|
316
|
+
payload: { type: 'item.indeterminate', data: { reason } },
|
|
317
|
+
}));
|
|
318
|
+
if (projection.activeTurnId) {
|
|
319
|
+
const commit = projection.turns[projection.activeTurnId]?.commit;
|
|
320
|
+
if (commit?.terminal === 'completed') {
|
|
321
|
+
inputs.push({
|
|
322
|
+
turnId: projection.activeTurnId,
|
|
323
|
+
payload: {
|
|
324
|
+
type: 'turn.completed',
|
|
325
|
+
data: commit.outcome === undefined ? {} : { outcome: commit.outcome },
|
|
326
|
+
},
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
else if (commit?.terminal === 'failed') {
|
|
330
|
+
inputs.push({
|
|
331
|
+
turnId: projection.activeTurnId,
|
|
332
|
+
payload: {
|
|
333
|
+
type: 'turn.failed',
|
|
334
|
+
data: { error: commit.error || 'Turn failed before terminal publication' },
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
inputs.push({
|
|
340
|
+
turnId: projection.activeTurnId,
|
|
341
|
+
payload: {
|
|
342
|
+
type: 'turn.interrupted',
|
|
343
|
+
data: { reason: commit?.reason ?? reason },
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return inputs.length > 0 ? this.appendDurableBatch(inputs).projection : projection;
|
|
349
|
+
}
|
|
350
|
+
withLogLock(operation) {
|
|
351
|
+
ensurePrivateDirectory((0, path_1.dirname)(this.logPath));
|
|
352
|
+
return (0, file_lock_1.withFileLockSync)(this.logPath, operation, { waitMs: this.lockWaitMs });
|
|
353
|
+
}
|
|
354
|
+
assertCompactCheckpoint(state) {
|
|
355
|
+
const checkpointPath = (0, path_1.join)(this.compactCheckpointsDir, `${state.pointer.checkpointId}.json`);
|
|
356
|
+
const checkpoint = readStoredCompactCheckpoint(checkpointPath, this.threadId);
|
|
357
|
+
if (!checkpoint ||
|
|
358
|
+
checkpoint.checkpointId !== state.pointer.checkpointId ||
|
|
359
|
+
checkpoint.commit.digest !== state.commit.digest ||
|
|
360
|
+
checkpoint.nextModelVisibleHistoryDigest !== state.historyDigest ||
|
|
361
|
+
checkpoint.nextModelVisibleHistoryDigest !== state.pointer.nextModelVisibleHistoryDigest) {
|
|
362
|
+
throw compactCorrupt('Compact pointer does not resolve to its committed checkpoint');
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
boundary(boundary, lastSeq) {
|
|
366
|
+
this.onBoundary?.(boundary, { threadId: this.threadId, lastSeq });
|
|
367
|
+
}
|
|
368
|
+
notifyCommitted(events) {
|
|
369
|
+
for (const listener of this.commitListeners) {
|
|
370
|
+
try {
|
|
371
|
+
listener(events);
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
// Durable commit observers are projections only and cannot veto facts.
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
exports.ThreadEventStore = ThreadEventStore;
|
|
380
|
+
function scanThreadEventLog(path, threadId, maxLogBytes) {
|
|
381
|
+
if (!(0, fs_1.existsSync)(path)) {
|
|
382
|
+
return { records: [], events: [], safeByteLength: 0, discardedTailBytes: 0 };
|
|
383
|
+
}
|
|
384
|
+
const content = (0, fs_1.readFileSync)(path);
|
|
385
|
+
if (content.byteLength > maxLogBytes) {
|
|
386
|
+
throw new ThreadEventStoreError('ORION_THREAD_EVENT_LIMIT', `Thread event log exceeds ${maxLogBytes} bytes`);
|
|
387
|
+
}
|
|
388
|
+
const endsWithNewline = content.byteLength === 0 || content[content.byteLength - 1] === 0x0a;
|
|
389
|
+
const text = content.toString('utf8');
|
|
390
|
+
const allLines = text.split('\n');
|
|
391
|
+
const tail = endsWithNewline ? '' : (allLines.pop() ?? '');
|
|
392
|
+
if (endsWithNewline)
|
|
393
|
+
allLines.pop();
|
|
394
|
+
const records = [];
|
|
395
|
+
const events = [];
|
|
396
|
+
const eventIds = new Set();
|
|
397
|
+
let expectedPreviousHash = null;
|
|
398
|
+
let safeByteLength = 0;
|
|
399
|
+
for (const line of allLines) {
|
|
400
|
+
const lineBytes = Buffer.byteLength(line, 'utf8') + 1;
|
|
401
|
+
if (line.length === 0) {
|
|
402
|
+
throw corrupt('Empty record inside the durable event log', safeByteLength);
|
|
403
|
+
}
|
|
404
|
+
let value;
|
|
405
|
+
try {
|
|
406
|
+
value = JSON.parse(line);
|
|
407
|
+
}
|
|
408
|
+
catch {
|
|
409
|
+
throw corrupt('Malformed JSON record inside the durable event log', safeByteLength);
|
|
410
|
+
}
|
|
411
|
+
const record = validateStoredRecord(value, threadId, records.length + 1, expectedPreviousHash, safeByteLength);
|
|
412
|
+
if (eventIds.has(record.event.eventId)) {
|
|
413
|
+
throw corrupt(`Duplicate eventId ${record.event.eventId}`, safeByteLength);
|
|
414
|
+
}
|
|
415
|
+
eventIds.add(record.event.eventId);
|
|
416
|
+
records.push(record);
|
|
417
|
+
events.push(record.event);
|
|
418
|
+
expectedPreviousHash = record.hash;
|
|
419
|
+
safeByteLength += lineBytes;
|
|
420
|
+
}
|
|
421
|
+
return {
|
|
422
|
+
records,
|
|
423
|
+
events,
|
|
424
|
+
safeByteLength,
|
|
425
|
+
discardedTailBytes: Buffer.byteLength(tail, 'utf8'),
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function validateStoredRecord(value, threadId, expectedSeq, expectedPreviousHash, offset) {
|
|
429
|
+
if (!isRecord(value) || value.version !== 1 || !isRecord(value.event)) {
|
|
430
|
+
throw corrupt('Invalid durable record envelope', offset);
|
|
431
|
+
}
|
|
432
|
+
try {
|
|
433
|
+
(0, runtime_protocol_v1_1.assertRuntimeEventEnvelopeV1)(value.event);
|
|
434
|
+
}
|
|
435
|
+
catch (error) {
|
|
436
|
+
throw corrupt(error instanceof Error ? error.message : 'Invalid runtime event', offset);
|
|
437
|
+
}
|
|
438
|
+
const event = value.event;
|
|
439
|
+
if (event.durability !== 'durable')
|
|
440
|
+
throw corrupt('Ephemeral event found in durable log', offset);
|
|
441
|
+
if (event.threadId !== threadId)
|
|
442
|
+
throw corrupt('Thread identity changed inside event log', offset);
|
|
443
|
+
if (event.seq !== expectedSeq) {
|
|
444
|
+
throw corrupt(`Expected durable seq ${expectedSeq}, found ${event.seq}`, offset);
|
|
445
|
+
}
|
|
446
|
+
if (value.previousHash !== expectedPreviousHash) {
|
|
447
|
+
throw corrupt('Event hash chain predecessor mismatch', offset);
|
|
448
|
+
}
|
|
449
|
+
if (typeof value.hash !== 'string')
|
|
450
|
+
throw corrupt('Event record hash is missing', offset);
|
|
451
|
+
const expectedHash = (0, canonical_1.digestRuntimeValue)({
|
|
452
|
+
version: 1,
|
|
453
|
+
previousHash: expectedPreviousHash,
|
|
454
|
+
event,
|
|
455
|
+
});
|
|
456
|
+
if (value.hash !== expectedHash)
|
|
457
|
+
throw corrupt('Event record hash mismatch', offset);
|
|
458
|
+
return {
|
|
459
|
+
version: 1,
|
|
460
|
+
previousHash: expectedPreviousHash,
|
|
461
|
+
hash: value.hash,
|
|
462
|
+
event,
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
function appendRecordsAndFlush(path, records, afterWrite) {
|
|
466
|
+
const fd = (0, fs_1.openSync)(path, 'a', 0o600);
|
|
467
|
+
try {
|
|
468
|
+
for (const record of records)
|
|
469
|
+
writeAll(fd, Buffer.from(`${(0, canonical_1.canonicalRuntimeJson)(record)}\n`));
|
|
470
|
+
afterWrite();
|
|
471
|
+
(0, fs_1.fsyncSync)(fd);
|
|
472
|
+
}
|
|
473
|
+
finally {
|
|
474
|
+
(0, fs_1.closeSync)(fd);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
function writeAll(fd, content) {
|
|
478
|
+
let offset = 0;
|
|
479
|
+
while (offset < content.byteLength) {
|
|
480
|
+
const written = (0, fs_1.writeSync)(fd, content, offset, content.byteLength - offset);
|
|
481
|
+
if (written <= 0)
|
|
482
|
+
throw new Error('Unable to append durable event record');
|
|
483
|
+
offset += written;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
function writeProjection(path, projection) {
|
|
487
|
+
(0, atomic_write_1.atomicWriteFileSync)(path, `${(0, canonical_1.canonicalRuntimeJson)(projection)}\n`, { mode: 0o600, fsync: true });
|
|
488
|
+
}
|
|
489
|
+
function readProjection(path) {
|
|
490
|
+
if (!(0, fs_1.existsSync)(path))
|
|
491
|
+
return null;
|
|
492
|
+
try {
|
|
493
|
+
const value = JSON.parse((0, fs_1.readFileSync)(path, 'utf8'));
|
|
494
|
+
return value?.version === 1 && typeof value.digest === 'string' ? value : null;
|
|
495
|
+
}
|
|
496
|
+
catch {
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
function ensurePrivateDirectory(path) {
|
|
501
|
+
(0, fs_1.mkdirSync)(path, { recursive: true, mode: 0o700 });
|
|
502
|
+
}
|
|
503
|
+
function fsyncDirectory(path) {
|
|
504
|
+
let fd;
|
|
505
|
+
try {
|
|
506
|
+
fd = (0, fs_1.openSync)(path, 'r');
|
|
507
|
+
(0, fs_1.fsyncSync)(fd);
|
|
508
|
+
}
|
|
509
|
+
catch {
|
|
510
|
+
// Some filesystems do not support directory fsync. File fsync and atomic
|
|
511
|
+
// rename still preserve the fail-closed ordering used by the store.
|
|
512
|
+
}
|
|
513
|
+
finally {
|
|
514
|
+
if (fd !== undefined)
|
|
515
|
+
(0, fs_1.closeSync)(fd);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
function assertActiveMaintenanceTurn(projection, turnId) {
|
|
519
|
+
const turn = projection.turns[turnId];
|
|
520
|
+
if (!(0, runtime_protocol_v1_1.isRuntimeId)(turnId) ||
|
|
521
|
+
projection.activeTurnId !== turnId ||
|
|
522
|
+
!turn ||
|
|
523
|
+
turn.status !== 'active' ||
|
|
524
|
+
turn.mode !== 'maintenance') {
|
|
525
|
+
throw new ThreadEventStoreError('ORION_THREAD_COMPACT_INVALID', `Compact requires ${turnId} to be the active maintenance turn`);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function resolveCompactAuthority(events, compactState, threadId) {
|
|
529
|
+
const turnState = readLatestDurableTurnState(events, threadId);
|
|
530
|
+
if (!turnState && !compactState) {
|
|
531
|
+
throw new ThreadEventStoreError('ORION_THREAD_COMPACT_INVALID', 'Compact requires a durable TurnCommitV1 source');
|
|
532
|
+
}
|
|
533
|
+
const historyOwner = compactState && (!turnState || compactState.installedAtCursor > turnState.eventSeq)
|
|
534
|
+
? compactState
|
|
535
|
+
: turnState;
|
|
536
|
+
const taskContextOwner = turnState && (!compactState || turnState.eventSeq > compactState.installedAtCursor)
|
|
537
|
+
? turnState
|
|
538
|
+
: compactState;
|
|
539
|
+
if (!historyOwner || !taskContextOwner) {
|
|
540
|
+
throw new ThreadEventStoreError('ORION_THREAD_COMPACT_INVALID', 'Compact authoritative state could not be resolved');
|
|
541
|
+
}
|
|
542
|
+
return deepFreeze({
|
|
543
|
+
history: structuredClone(historyOwner.history),
|
|
544
|
+
historyDigest: historyOwner.historyDigest,
|
|
545
|
+
taskContext: structuredClone(taskContextOwner.taskContext),
|
|
546
|
+
taskContextDigest: taskContextOwner.taskContextDigest,
|
|
547
|
+
taskContextRevision: taskContextOwner.taskContextRevision,
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
function readLatestDurableTurnState(events, threadId) {
|
|
551
|
+
const event = [...events]
|
|
552
|
+
.reverse()
|
|
553
|
+
.find(candidate => candidate.payload.type === 'turn.committed');
|
|
554
|
+
if (!event || event.payload.type !== 'turn.committed')
|
|
555
|
+
return null;
|
|
556
|
+
let receipt;
|
|
557
|
+
try {
|
|
558
|
+
receipt = JSON.parse(event.payload.data.receipt);
|
|
559
|
+
}
|
|
560
|
+
catch {
|
|
561
|
+
throw compactCorrupt('TurnCommitV1 receipt is not valid JSON');
|
|
562
|
+
}
|
|
563
|
+
const { digest, ...content } = receipt;
|
|
564
|
+
if (receipt.version !== 1 ||
|
|
565
|
+
receipt.threadId !== threadId ||
|
|
566
|
+
typeof digest !== 'string' ||
|
|
567
|
+
(0, canonical_1.digestRuntimeValue)(content) !== digest ||
|
|
568
|
+
typeof receipt.history !== 'string' ||
|
|
569
|
+
typeof receipt.historyDigest !== 'string' ||
|
|
570
|
+
typeof receipt.taskContext !== 'string' ||
|
|
571
|
+
typeof receipt.taskContextDigest !== 'string' ||
|
|
572
|
+
!Number.isSafeInteger(receipt.taskContextRevision) ||
|
|
573
|
+
receipt.taskContextRevision < 0) {
|
|
574
|
+
throw compactCorrupt('TurnCommitV1 receipt failed compact source validation');
|
|
575
|
+
}
|
|
576
|
+
let history;
|
|
577
|
+
let taskContext;
|
|
578
|
+
try {
|
|
579
|
+
history = JSON.parse(receipt.history);
|
|
580
|
+
taskContext = JSON.parse(receipt.taskContext);
|
|
581
|
+
}
|
|
582
|
+
catch {
|
|
583
|
+
throw compactCorrupt('TurnCommitV1 history or TaskContext is not valid JSON');
|
|
584
|
+
}
|
|
585
|
+
if (!Array.isArray(history) ||
|
|
586
|
+
(0, canonical_1.digestRuntimeValue)(history) !== receipt.historyDigest ||
|
|
587
|
+
(0, canonical_1.digestRuntimeValue)(taskContext) !== receipt.taskContextDigest) {
|
|
588
|
+
throw compactCorrupt('TurnCommitV1 history or TaskContext digest changed');
|
|
589
|
+
}
|
|
590
|
+
return deepFreeze({
|
|
591
|
+
eventSeq: event.seq,
|
|
592
|
+
history: structuredClone(history),
|
|
593
|
+
historyDigest: receipt.historyDigest,
|
|
594
|
+
taskContext: structuredClone(taskContext),
|
|
595
|
+
taskContextDigest: receipt.taskContextDigest,
|
|
596
|
+
taskContextRevision: receipt.taskContextRevision,
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
function validateCompactCommitInput(input, threadId) {
|
|
600
|
+
const commit = input.commit;
|
|
601
|
+
const { digest, ...content } = commit;
|
|
602
|
+
if (commit.version !== 1 ||
|
|
603
|
+
commit.threadId !== threadId ||
|
|
604
|
+
commit.threadId !== input.source.threadId ||
|
|
605
|
+
commit.turnId !== input.source.turnId ||
|
|
606
|
+
commit.source.digest !== input.source.digest ||
|
|
607
|
+
commit.startedEvent.cursor !== input.expectedEventAnchor.cursor ||
|
|
608
|
+
commit.startedEvent.projectionDigest !== input.expectedEventAnchor.projectionDigest ||
|
|
609
|
+
commit.checkpointId !== input.candidate.checkpointId ||
|
|
610
|
+
commit.checkpointDigest !== (0, canonical_1.digestRuntimeValue)(input.candidate.checkpoint) ||
|
|
611
|
+
commit.pointer.nextModelVisibleHistoryDigest !==
|
|
612
|
+
(0, canonical_1.digestRuntimeValue)(input.candidate.modelVisibleHistory) ||
|
|
613
|
+
(0, canonical_1.digestRuntimeValue)(content) !== digest ||
|
|
614
|
+
!(0, runtime_protocol_v1_1.isRuntimeId)(commit.transactionId) ||
|
|
615
|
+
!(0, runtime_protocol_v1_1.isRuntimeId)(commit.checkpointId)) {
|
|
616
|
+
throw compactCorrupt('Compact CAS input failed receipt validation');
|
|
617
|
+
}
|
|
618
|
+
const { digest: pointerDigest, ...pointerContent } = commit.pointer;
|
|
619
|
+
if (commit.pointer.version !== 1 ||
|
|
620
|
+
commit.pointer.checkpointId !== commit.checkpointId ||
|
|
621
|
+
commit.pointer.transactionId !== commit.transactionId ||
|
|
622
|
+
commit.pointer.sourceReceiptDigest !== commit.source.digest ||
|
|
623
|
+
(0, canonical_1.digestRuntimeValue)(pointerContent) !== pointerDigest) {
|
|
624
|
+
throw compactCorrupt('Compact pointer failed receipt validation');
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
function createStoredCompactCheckpoint(threadId, input) {
|
|
628
|
+
const content = {
|
|
629
|
+
version: 1,
|
|
630
|
+
threadId,
|
|
631
|
+
checkpointId: input.candidate.checkpointId,
|
|
632
|
+
checkpoint: structuredClone(input.candidate.checkpoint),
|
|
633
|
+
checkpointDigest: input.commit.checkpointDigest,
|
|
634
|
+
modelVisibleHistory: structuredClone(input.candidate.modelVisibleHistory),
|
|
635
|
+
nextModelVisibleHistoryDigest: input.commit.pointer.nextModelVisibleHistoryDigest,
|
|
636
|
+
commit: structuredClone(input.commit),
|
|
637
|
+
};
|
|
638
|
+
return deepFreeze({ ...content, digest: (0, canonical_1.digestRuntimeValue)(content) });
|
|
639
|
+
}
|
|
640
|
+
function createStoredCompactState(threadId, input, taskContext, taskContextRevision) {
|
|
641
|
+
const history = structuredClone(input.candidate.modelVisibleHistory);
|
|
642
|
+
const task = structuredClone(taskContext);
|
|
643
|
+
const content = {
|
|
644
|
+
version: 1,
|
|
645
|
+
threadId,
|
|
646
|
+
installedAtCursor: input.expectedEventAnchor.cursor,
|
|
647
|
+
pointer: structuredClone(input.commit.pointer),
|
|
648
|
+
history,
|
|
649
|
+
historyDigest: (0, canonical_1.digestRuntimeValue)(history),
|
|
650
|
+
taskContext: task,
|
|
651
|
+
taskContextDigest: (0, canonical_1.digestRuntimeValue)(task),
|
|
652
|
+
taskContextRevision,
|
|
653
|
+
commit: structuredClone(input.commit),
|
|
654
|
+
};
|
|
655
|
+
return deepFreeze({ ...content, digest: (0, canonical_1.digestRuntimeValue)(content) });
|
|
656
|
+
}
|
|
657
|
+
function readCompactState(path, threadId) {
|
|
658
|
+
if (!(0, fs_1.existsSync)(path))
|
|
659
|
+
return null;
|
|
660
|
+
let value;
|
|
661
|
+
try {
|
|
662
|
+
value = JSON.parse((0, fs_1.readFileSync)(path, 'utf8'));
|
|
663
|
+
}
|
|
664
|
+
catch {
|
|
665
|
+
throw compactCorrupt('Compact state is not valid JSON');
|
|
666
|
+
}
|
|
667
|
+
const { digest, ...content } = value;
|
|
668
|
+
if (value.version !== 1 ||
|
|
669
|
+
value.threadId !== threadId ||
|
|
670
|
+
!Number.isSafeInteger(value.installedAtCursor) ||
|
|
671
|
+
value.installedAtCursor < 0 ||
|
|
672
|
+
!Array.isArray(value.history) ||
|
|
673
|
+
(0, canonical_1.digestRuntimeValue)(value.history) !== value.historyDigest ||
|
|
674
|
+
(0, canonical_1.digestRuntimeValue)(value.taskContext) !== value.taskContextDigest ||
|
|
675
|
+
!Number.isSafeInteger(value.taskContextRevision) ||
|
|
676
|
+
value.taskContextRevision < 0 ||
|
|
677
|
+
(0, canonical_1.digestRuntimeValue)(content) !== digest ||
|
|
678
|
+
value.commit?.digest === undefined ||
|
|
679
|
+
value.pointer?.digest === undefined ||
|
|
680
|
+
value.commit.digest !== (0, canonical_1.digestRuntimeValue)(stripDigest(value.commit)) ||
|
|
681
|
+
value.pointer.digest !== (0, canonical_1.digestRuntimeValue)(stripDigest(value.pointer)) ||
|
|
682
|
+
value.commit.pointer.digest !== value.pointer.digest) {
|
|
683
|
+
throw compactCorrupt('Compact state failed integrity validation');
|
|
684
|
+
}
|
|
685
|
+
return deepFreeze(value);
|
|
686
|
+
}
|
|
687
|
+
function readStoredCompactCheckpoint(path, threadId) {
|
|
688
|
+
if (!(0, fs_1.existsSync)(path))
|
|
689
|
+
return null;
|
|
690
|
+
let value;
|
|
691
|
+
try {
|
|
692
|
+
value = JSON.parse((0, fs_1.readFileSync)(path, 'utf8'));
|
|
693
|
+
}
|
|
694
|
+
catch {
|
|
695
|
+
throw compactCorrupt('Compact checkpoint is not valid JSON');
|
|
696
|
+
}
|
|
697
|
+
const { digest, ...content } = value;
|
|
698
|
+
if (value.version !== 1 ||
|
|
699
|
+
value.threadId !== threadId ||
|
|
700
|
+
!(0, runtime_protocol_v1_1.isRuntimeId)(value.checkpointId) ||
|
|
701
|
+
(0, canonical_1.digestRuntimeValue)(value.checkpoint) !== value.checkpointDigest ||
|
|
702
|
+
!Array.isArray(value.modelVisibleHistory) ||
|
|
703
|
+
(0, canonical_1.digestRuntimeValue)(value.modelVisibleHistory) !== value.nextModelVisibleHistoryDigest ||
|
|
704
|
+
(0, canonical_1.digestRuntimeValue)(content) !== digest) {
|
|
705
|
+
throw compactCorrupt('Compact checkpoint failed integrity validation');
|
|
706
|
+
}
|
|
707
|
+
return deepFreeze(value);
|
|
708
|
+
}
|
|
709
|
+
function stripDigest(value) {
|
|
710
|
+
const { digest: _digest, ...content } = value;
|
|
711
|
+
void _digest;
|
|
712
|
+
return content;
|
|
713
|
+
}
|
|
714
|
+
function compactCorrupt(message) {
|
|
715
|
+
return new ThreadEventStoreError('ORION_THREAD_COMPACT_INVALID', message);
|
|
716
|
+
}
|
|
717
|
+
function positiveInteger(value, name) {
|
|
718
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
719
|
+
throw new ThreadEventStoreError('ORION_THREAD_EVENT_LIMIT', `${name} must be a positive safe integer`);
|
|
720
|
+
}
|
|
721
|
+
return value;
|
|
722
|
+
}
|
|
723
|
+
function corrupt(message, offset) {
|
|
724
|
+
return new ThreadEventStoreError('ORION_THREAD_EVENT_CORRUPT', message, offset);
|
|
725
|
+
}
|
|
726
|
+
function isRecord(value) {
|
|
727
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
728
|
+
}
|
|
729
|
+
function deepFreeze(value) {
|
|
730
|
+
if (typeof value !== 'object' || value === null || Object.isFrozen(value))
|
|
731
|
+
return value;
|
|
732
|
+
Object.freeze(value);
|
|
733
|
+
for (const entry of Object.values(value))
|
|
734
|
+
deepFreeze(entry);
|
|
735
|
+
return value;
|
|
736
|
+
}
|
|
737
|
+
//# sourceMappingURL=thread-event-store.js.map
|