@sema-ai/core 1.275.1
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 +5433 -0
- package/LICENSE +27 -0
- package/NOTICE.md +30 -0
- package/README.md +1040 -0
- package/dist/agents/agent-definition.d.ts +10 -0
- package/dist/agents/agent-definition.d.ts.map +1 -0
- package/dist/agents/agent-definition.js +18 -0
- package/dist/agents/agent-definition.js.map +1 -0
- package/dist/agents/builtin-agents.d.ts +69 -0
- package/dist/agents/builtin-agents.d.ts.map +1 -0
- package/dist/agents/builtin-agents.js +177 -0
- package/dist/agents/builtin-agents.js.map +1 -0
- package/dist/agents/cascade.d.ts +101 -0
- package/dist/agents/cascade.d.ts.map +1 -0
- package/dist/agents/cascade.js +189 -0
- package/dist/agents/cascade.js.map +1 -0
- package/dist/agents/observer.d.ts +209 -0
- package/dist/agents/observer.d.ts.map +1 -0
- package/dist/agents/observer.js +495 -0
- package/dist/agents/observer.js.map +1 -0
- package/dist/agents/repair-loop.d.ts +236 -0
- package/dist/agents/repair-loop.d.ts.map +1 -0
- package/dist/agents/repair-loop.js +293 -0
- package/dist/agents/repair-loop.js.map +1 -0
- package/dist/agents/session-util.d.ts +8 -0
- package/dist/agents/session-util.d.ts.map +1 -0
- package/dist/agents/session-util.js +9 -0
- package/dist/agents/session-util.js.map +1 -0
- package/dist/agents/subagent-steps.d.ts +93 -0
- package/dist/agents/subagent-steps.d.ts.map +1 -0
- package/dist/agents/subagent-steps.js +206 -0
- package/dist/agents/subagent-steps.js.map +1 -0
- package/dist/agents/subagent.d.ts +441 -0
- package/dist/agents/subagent.d.ts.map +1 -0
- package/dist/agents/subagent.js +2492 -0
- package/dist/agents/subagent.js.map +1 -0
- package/dist/agents/suspend-guard.d.ts +35 -0
- package/dist/agents/suspend-guard.d.ts.map +1 -0
- package/dist/agents/suspend-guard.js +48 -0
- package/dist/agents/suspend-guard.js.map +1 -0
- package/dist/agents/teacher.d.ts +137 -0
- package/dist/agents/teacher.d.ts.map +1 -0
- package/dist/agents/teacher.js +575 -0
- package/dist/agents/teacher.js.map +1 -0
- package/dist/agents/team.d.ts +211 -0
- package/dist/agents/team.d.ts.map +1 -0
- package/dist/agents/team.js +293 -0
- package/dist/agents/team.js.map +1 -0
- package/dist/agents/tool-filter.d.ts +29 -0
- package/dist/agents/tool-filter.d.ts.map +1 -0
- package/dist/agents/tool-filter.js +50 -0
- package/dist/agents/tool-filter.js.map +1 -0
- package/dist/agents/verify.d.ts +177 -0
- package/dist/agents/verify.d.ts.map +1 -0
- package/dist/agents/verify.js +305 -0
- package/dist/agents/verify.js.map +1 -0
- package/dist/bench/metrics.d.ts +714 -0
- package/dist/bench/metrics.d.ts.map +1 -0
- package/dist/bench/metrics.js +618 -0
- package/dist/bench/metrics.js.map +1 -0
- package/dist/bin/sema-tb.d.ts +3 -0
- package/dist/bin/sema-tb.d.ts.map +1 -0
- package/dist/bin/sema-tb.js +516 -0
- package/dist/bin/sema-tb.js.map +1 -0
- package/dist/bin/tb-env.d.ts +13 -0
- package/dist/bin/tb-env.d.ts.map +1 -0
- package/dist/bin/tb-env.js +26 -0
- package/dist/bin/tb-env.js.map +1 -0
- package/dist/brain/anthropic.d.ts +46 -0
- package/dist/brain/anthropic.d.ts.map +1 -0
- package/dist/brain/anthropic.js +830 -0
- package/dist/brain/anthropic.js.map +1 -0
- package/dist/brain/circuit-breaker.d.ts +46 -0
- package/dist/brain/circuit-breaker.d.ts.map +1 -0
- package/dist/brain/circuit-breaker.js +173 -0
- package/dist/brain/circuit-breaker.js.map +1 -0
- package/dist/brain/degrading.d.ts +98 -0
- package/dist/brain/degrading.d.ts.map +1 -0
- package/dist/brain/degrading.js +249 -0
- package/dist/brain/degrading.js.map +1 -0
- package/dist/brain/errors.d.ts +31 -0
- package/dist/brain/errors.d.ts.map +1 -0
- package/dist/brain/errors.js +58 -0
- package/dist/brain/errors.js.map +1 -0
- package/dist/brain/failover.d.ts +18 -0
- package/dist/brain/failover.d.ts.map +1 -0
- package/dist/brain/failover.js +118 -0
- package/dist/brain/failover.js.map +1 -0
- package/dist/brain/model-presets.d.ts +36 -0
- package/dist/brain/model-presets.d.ts.map +1 -0
- package/dist/brain/model-presets.js +54 -0
- package/dist/brain/model-presets.js.map +1 -0
- package/dist/brain/openai.d.ts +43 -0
- package/dist/brain/openai.d.ts.map +1 -0
- package/dist/brain/openai.js +784 -0
- package/dist/brain/openai.js.map +1 -0
- package/dist/brain/reasoning.d.ts +138 -0
- package/dist/brain/reasoning.d.ts.map +1 -0
- package/dist/brain/reasoning.js +146 -0
- package/dist/brain/reasoning.js.map +1 -0
- package/dist/brain/repetition.d.ts +60 -0
- package/dist/brain/repetition.d.ts.map +1 -0
- package/dist/brain/repetition.js +121 -0
- package/dist/brain/repetition.js.map +1 -0
- package/dist/brain/request-params.d.ts +29 -0
- package/dist/brain/request-params.d.ts.map +1 -0
- package/dist/brain/request-params.js +78 -0
- package/dist/brain/request-params.js.map +1 -0
- package/dist/brain/retry.d.ts +18 -0
- package/dist/brain/retry.d.ts.map +1 -0
- package/dist/brain/retry.js +42 -0
- package/dist/brain/retry.js.map +1 -0
- package/dist/brain/routing.d.ts +19 -0
- package/dist/brain/routing.d.ts.map +1 -0
- package/dist/brain/routing.js +44 -0
- package/dist/brain/routing.js.map +1 -0
- package/dist/brain/status-sink.d.ts +46 -0
- package/dist/brain/status-sink.d.ts.map +1 -0
- package/dist/brain/status-sink.js +36 -0
- package/dist/brain/status-sink.js.map +1 -0
- package/dist/brain/stream-engine.d.ts +85 -0
- package/dist/brain/stream-engine.d.ts.map +1 -0
- package/dist/brain/stream-engine.js +391 -0
- package/dist/brain/stream-engine.js.map +1 -0
- package/dist/brain/timeout.d.ts +44 -0
- package/dist/brain/timeout.d.ts.map +1 -0
- package/dist/brain/timeout.js +41 -0
- package/dist/brain/timeout.js.map +1 -0
- package/dist/brain/tool-call-repair.d.ts +15 -0
- package/dist/brain/tool-call-repair.d.ts.map +1 -0
- package/dist/brain/tool-call-repair.js +67 -0
- package/dist/brain/tool-call-repair.js.map +1 -0
- package/dist/brain/walltime.d.ts +14 -0
- package/dist/brain/walltime.d.ts.map +1 -0
- package/dist/brain/walltime.js +14 -0
- package/dist/brain/walltime.js.map +1 -0
- package/dist/core/arg-summary.d.ts +19 -0
- package/dist/core/arg-summary.d.ts.map +1 -0
- package/dist/core/arg-summary.js +96 -0
- package/dist/core/arg-summary.js.map +1 -0
- package/dist/core/ask-question.d.ts +113 -0
- package/dist/core/ask-question.d.ts.map +1 -0
- package/dist/core/ask-question.js +246 -0
- package/dist/core/ask-question.js.map +1 -0
- package/dist/core/auto-compaction.d.ts +341 -0
- package/dist/core/auto-compaction.d.ts.map +1 -0
- package/dist/core/auto-compaction.js +495 -0
- package/dist/core/auto-compaction.js.map +1 -0
- package/dist/core/auto-promote.d.ts +126 -0
- package/dist/core/auto-promote.d.ts.map +1 -0
- package/dist/core/auto-promote.js +171 -0
- package/dist/core/auto-promote.js.map +1 -0
- package/dist/core/background-shell.d.ts +128 -0
- package/dist/core/background-shell.d.ts.map +1 -0
- package/dist/core/background-shell.js +42 -0
- package/dist/core/background-shell.js.map +1 -0
- package/dist/core/cache-break-detector.d.ts +63 -0
- package/dist/core/cache-break-detector.d.ts.map +1 -0
- package/dist/core/cache-break-detector.js +0 -0
- package/dist/core/cache-break-detector.js.map +1 -0
- package/dist/core/canonical-json.d.ts +45 -0
- package/dist/core/canonical-json.d.ts.map +1 -0
- package/dist/core/canonical-json.js +132 -0
- package/dist/core/canonical-json.js.map +1 -0
- package/dist/core/checkpoint-store.d.ts +1101 -0
- package/dist/core/checkpoint-store.d.ts.map +1 -0
- package/dist/core/checkpoint-store.js +514 -0
- package/dist/core/checkpoint-store.js.map +1 -0
- package/dist/core/consolidate-scope.d.ts +94 -0
- package/dist/core/consolidate-scope.d.ts.map +1 -0
- package/dist/core/consolidate-scope.js +158 -0
- package/dist/core/consolidate-scope.js.map +1 -0
- package/dist/core/context-edit.d.ts +82 -0
- package/dist/core/context-edit.d.ts.map +1 -0
- package/dist/core/context-edit.js +149 -0
- package/dist/core/context-edit.js.map +1 -0
- package/dist/core/context-guard.d.ts +43 -0
- package/dist/core/context-guard.d.ts.map +1 -0
- package/dist/core/context-guard.js +171 -0
- package/dist/core/context-guard.js.map +1 -0
- package/dist/core/dynamic-recall.d.ts +100 -0
- package/dist/core/dynamic-recall.d.ts.map +1 -0
- package/dist/core/dynamic-recall.js +108 -0
- package/dist/core/dynamic-recall.js.map +1 -0
- package/dist/core/exec-gate.d.ts +74 -0
- package/dist/core/exec-gate.d.ts.map +1 -0
- package/dist/core/exec-gate.js +143 -0
- package/dist/core/exec-gate.js.map +1 -0
- package/dist/core/exec-output-tail.d.ts +37 -0
- package/dist/core/exec-output-tail.d.ts.map +1 -0
- package/dist/core/exec-output-tail.js +63 -0
- package/dist/core/exec-output-tail.js.map +1 -0
- package/dist/core/file-snapshot-store.d.ts +137 -0
- package/dist/core/file-snapshot-store.d.ts.map +1 -0
- package/dist/core/file-snapshot-store.js +319 -0
- package/dist/core/file-snapshot-store.js.map +1 -0
- package/dist/core/git-worktree-env.d.ts +41 -0
- package/dist/core/git-worktree-env.d.ts.map +1 -0
- package/dist/core/git-worktree-env.js +64 -0
- package/dist/core/git-worktree-env.js.map +1 -0
- package/dist/core/hooks.d.ts +372 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/hooks.js +269 -0
- package/dist/core/hooks.js.map +1 -0
- package/dist/core/lsp-diagnostics.d.ts +74 -0
- package/dist/core/lsp-diagnostics.d.ts.map +1 -0
- package/dist/core/lsp-diagnostics.js +125 -0
- package/dist/core/lsp-diagnostics.js.map +1 -0
- package/dist/core/lsp-protocol.d.ts +28 -0
- package/dist/core/lsp-protocol.d.ts.map +1 -0
- package/dist/core/lsp-protocol.js +179 -0
- package/dist/core/lsp-protocol.js.map +1 -0
- package/dist/core/lsp-session.d.ts +56 -0
- package/dist/core/lsp-session.d.ts.map +1 -0
- package/dist/core/lsp-session.js +185 -0
- package/dist/core/lsp-session.js.map +1 -0
- package/dist/core/lsp.d.ts +132 -0
- package/dist/core/lsp.d.ts.map +1 -0
- package/dist/core/lsp.js +147 -0
- package/dist/core/lsp.js.map +1 -0
- package/dist/core/mcp.d.ts +294 -0
- package/dist/core/mcp.d.ts.map +1 -0
- package/dist/core/mcp.js +992 -0
- package/dist/core/mcp.js.map +1 -0
- package/dist/core/media-byte-cap.d.ts +34 -0
- package/dist/core/media-byte-cap.d.ts.map +1 -0
- package/dist/core/media-byte-cap.js +76 -0
- package/dist/core/media-byte-cap.js.map +1 -0
- package/dist/core/memory-engine/data-plane.d.ts +103 -0
- package/dist/core/memory-engine/data-plane.d.ts.map +1 -0
- package/dist/core/memory-engine/data-plane.js +272 -0
- package/dist/core/memory-engine/data-plane.js.map +1 -0
- package/dist/core/memory-engine/dual-root.d.ts +40 -0
- package/dist/core/memory-engine/dual-root.d.ts.map +1 -0
- package/dist/core/memory-engine/dual-root.js +95 -0
- package/dist/core/memory-engine/dual-root.js.map +1 -0
- package/dist/core/memory-engine/engine.d.ts +161 -0
- package/dist/core/memory-engine/engine.d.ts.map +1 -0
- package/dist/core/memory-engine/engine.js +1110 -0
- package/dist/core/memory-engine/engine.js.map +1 -0
- package/dist/core/memory-engine/file-backend.d.ts +162 -0
- package/dist/core/memory-engine/file-backend.d.ts.map +1 -0
- package/dist/core/memory-engine/file-backend.js +948 -0
- package/dist/core/memory-engine/file-backend.js.map +1 -0
- package/dist/core/memory-engine/frontmatter.d.ts +24 -0
- package/dist/core/memory-engine/frontmatter.d.ts.map +1 -0
- package/dist/core/memory-engine/frontmatter.js +135 -0
- package/dist/core/memory-engine/frontmatter.js.map +1 -0
- package/dist/core/memory-engine/index.d.ts +13 -0
- package/dist/core/memory-engine/index.d.ts.map +1 -0
- package/dist/core/memory-engine/index.js +28 -0
- package/dist/core/memory-engine/index.js.map +1 -0
- package/dist/core/memory-engine/layout.d.ts +123 -0
- package/dist/core/memory-engine/layout.d.ts.map +1 -0
- package/dist/core/memory-engine/layout.js +643 -0
- package/dist/core/memory-engine/layout.js.map +1 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts +22 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts.map +1 -0
- package/dist/core/memory-engine/memory-backend-contract.js +271 -0
- package/dist/core/memory-engine/memory-backend-contract.js.map +1 -0
- package/dist/core/memory-engine/migrate.d.ts +17 -0
- package/dist/core/memory-engine/migrate.d.ts.map +1 -0
- package/dist/core/memory-engine/migrate.js +35 -0
- package/dist/core/memory-engine/migrate.js.map +1 -0
- package/dist/core/memory-engine/scan.d.ts +20 -0
- package/dist/core/memory-engine/scan.d.ts.map +1 -0
- package/dist/core/memory-engine/scan.js +84 -0
- package/dist/core/memory-engine/scan.js.map +1 -0
- package/dist/core/memory-engine/scope-contract.d.ts +104 -0
- package/dist/core/memory-engine/scope-contract.d.ts.map +1 -0
- package/dist/core/memory-engine/scope-contract.js +288 -0
- package/dist/core/memory-engine/scope-contract.js.map +1 -0
- package/dist/core/memory-engine/sync-client.d.ts +100 -0
- package/dist/core/memory-engine/sync-client.d.ts.map +1 -0
- package/dist/core/memory-engine/sync-client.js +328 -0
- package/dist/core/memory-engine/sync-client.js.map +1 -0
- package/dist/core/memory-engine/sync.d.ts +97 -0
- package/dist/core/memory-engine/sync.d.ts.map +1 -0
- package/dist/core/memory-engine/sync.js +91 -0
- package/dist/core/memory-engine/sync.js.map +1 -0
- package/dist/core/memory-engine/types.d.ts +279 -0
- package/dist/core/memory-engine/types.d.ts.map +1 -0
- package/dist/core/memory-engine/types.js +9 -0
- package/dist/core/memory-engine/types.js.map +1 -0
- package/dist/core/memory-recall.d.ts +261 -0
- package/dist/core/memory-recall.d.ts.map +1 -0
- package/dist/core/memory-recall.js +600 -0
- package/dist/core/memory-recall.js.map +1 -0
- package/dist/core/memory-vector.d.ts +24 -0
- package/dist/core/memory-vector.d.ts.map +1 -0
- package/dist/core/memory-vector.js +51 -0
- package/dist/core/memory-vector.js.map +1 -0
- package/dist/core/memory.d.ts +502 -0
- package/dist/core/memory.d.ts.map +1 -0
- package/dist/core/memory.js +881 -0
- package/dist/core/memory.js.map +1 -0
- package/dist/core/message-utils.d.ts +7 -0
- package/dist/core/message-utils.d.ts.map +1 -0
- package/dist/core/message-utils.js +10 -0
- package/dist/core/message-utils.js.map +1 -0
- package/dist/core/oracle-isolation.d.ts +85 -0
- package/dist/core/oracle-isolation.d.ts.map +1 -0
- package/dist/core/oracle-isolation.js +121 -0
- package/dist/core/oracle-isolation.js.map +1 -0
- package/dist/core/permission-rules.d.ts +102 -0
- package/dist/core/permission-rules.d.ts.map +1 -0
- package/dist/core/permission-rules.js +357 -0
- package/dist/core/permission-rules.js.map +1 -0
- package/dist/core/present-plan-tool.d.ts +28 -0
- package/dist/core/present-plan-tool.d.ts.map +1 -0
- package/dist/core/present-plan-tool.js +119 -0
- package/dist/core/present-plan-tool.js.map +1 -0
- package/dist/core/pricing.d.ts +48 -0
- package/dist/core/pricing.d.ts.map +1 -0
- package/dist/core/pricing.js +46 -0
- package/dist/core/pricing.js.map +1 -0
- package/dist/core/property-harness.d.ts +126 -0
- package/dist/core/property-harness.d.ts.map +1 -0
- package/dist/core/property-harness.js +192 -0
- package/dist/core/property-harness.js.map +1 -0
- package/dist/core/push-queue.d.ts +10 -0
- package/dist/core/push-queue.d.ts.map +1 -0
- package/dist/core/push-queue.js +42 -0
- package/dist/core/push-queue.js.map +1 -0
- package/dist/core/remote-env.d.ts +432 -0
- package/dist/core/remote-env.d.ts.map +1 -0
- package/dist/core/remote-env.js +77 -0
- package/dist/core/remote-env.js.map +1 -0
- package/dist/core/roles.d.ts +74 -0
- package/dist/core/roles.d.ts.map +1 -0
- package/dist/core/roles.js +272 -0
- package/dist/core/roles.js.map +1 -0
- package/dist/core/runner/active-skill-scope.d.ts +64 -0
- package/dist/core/runner/active-skill-scope.d.ts.map +1 -0
- package/dist/core/runner/active-skill-scope.js +197 -0
- package/dist/core/runner/active-skill-scope.js.map +1 -0
- package/dist/core/runner/assemble-result.d.ts +191 -0
- package/dist/core/runner/assemble-result.d.ts.map +1 -0
- package/dist/core/runner/assemble-result.js +250 -0
- package/dist/core/runner/assemble-result.js.map +1 -0
- package/dist/core/runner/call-cap.d.ts +130 -0
- package/dist/core/runner/call-cap.d.ts.map +1 -0
- package/dist/core/runner/call-cap.js +151 -0
- package/dist/core/runner/call-cap.js.map +1 -0
- package/dist/core/runner/grounding-signal.d.ts +12 -0
- package/dist/core/runner/grounding-signal.d.ts.map +1 -0
- package/dist/core/runner/grounding-signal.js +94 -0
- package/dist/core/runner/grounding-signal.js.map +1 -0
- package/dist/core/runner/image.d.ts +23 -0
- package/dist/core/runner/image.d.ts.map +1 -0
- package/dist/core/runner/image.js +151 -0
- package/dist/core/runner/image.js.map +1 -0
- package/dist/core/runner/memory-consolidation.d.ts +112 -0
- package/dist/core/runner/memory-consolidation.d.ts.map +1 -0
- package/dist/core/runner/memory-consolidation.js +372 -0
- package/dist/core/runner/memory-consolidation.js.map +1 -0
- package/dist/core/runner/prepare-task.d.ts +583 -0
- package/dist/core/runner/prepare-task.d.ts.map +1 -0
- package/dist/core/runner/prepare-task.js +3612 -0
- package/dist/core/runner/prepare-task.js.map +1 -0
- package/dist/core/runner/prompt-suggestions.d.ts +33 -0
- package/dist/core/runner/prompt-suggestions.d.ts.map +1 -0
- package/dist/core/runner/prompt-suggestions.js +116 -0
- package/dist/core/runner/prompt-suggestions.js.map +1 -0
- package/dist/core/runner/runtask.d.ts +274 -0
- package/dist/core/runner/runtask.d.ts.map +1 -0
- package/dist/core/runner/runtask.js +4606 -0
- package/dist/core/runner/runtask.js.map +1 -0
- package/dist/core/runner/session-rule-policy.d.ts +28 -0
- package/dist/core/runner/session-rule-policy.d.ts.map +1 -0
- package/dist/core/runner/session-rule-policy.js +110 -0
- package/dist/core/runner/session-rule-policy.js.map +1 -0
- package/dist/core/runner/strict-output-schema.d.ts +36 -0
- package/dist/core/runner/strict-output-schema.d.ts.map +1 -0
- package/dist/core/runner/strict-output-schema.js +365 -0
- package/dist/core/runner/strict-output-schema.js.map +1 -0
- package/dist/core/runner/synthetic-tools.d.ts +72 -0
- package/dist/core/runner/synthetic-tools.d.ts.map +1 -0
- package/dist/core/runner/synthetic-tools.js +203 -0
- package/dist/core/runner/synthetic-tools.js.map +1 -0
- package/dist/core/runner/tool-disclosure.d.ts +117 -0
- package/dist/core/runner/tool-disclosure.d.ts.map +1 -0
- package/dist/core/runner/tool-disclosure.js +0 -0
- package/dist/core/runner/tool-disclosure.js.map +1 -0
- package/dist/core/runner/turn-attachments.d.ts +381 -0
- package/dist/core/runner/turn-attachments.d.ts.map +1 -0
- package/dist/core/runner/turn-attachments.js +596 -0
- package/dist/core/runner/turn-attachments.js.map +1 -0
- package/dist/core/runner/usage-accounting.d.ts +35 -0
- package/dist/core/runner/usage-accounting.d.ts.map +1 -0
- package/dist/core/runner/usage-accounting.js +45 -0
- package/dist/core/runner/usage-accounting.js.map +1 -0
- package/dist/core/runtime.d.ts +9 -0
- package/dist/core/runtime.d.ts.map +1 -0
- package/dist/core/runtime.js +17 -0
- package/dist/core/runtime.js.map +1 -0
- package/dist/core/safety-axis-vocab.d.ts +33 -0
- package/dist/core/safety-axis-vocab.d.ts.map +1 -0
- package/dist/core/safety-axis-vocab.js +35 -0
- package/dist/core/safety-axis-vocab.js.map +1 -0
- package/dist/core/safety-merge-corpus.d.ts +48 -0
- package/dist/core/safety-merge-corpus.d.ts.map +1 -0
- package/dist/core/safety-merge-corpus.js +203 -0
- package/dist/core/safety-merge-corpus.js.map +1 -0
- package/dist/core/scheduler.d.ts +126 -0
- package/dist/core/scheduler.d.ts.map +1 -0
- package/dist/core/scheduler.js +54 -0
- package/dist/core/scheduler.js.map +1 -0
- package/dist/core/secret-env.d.ts +23 -0
- package/dist/core/secret-env.d.ts.map +1 -0
- package/dist/core/secret-env.js +35 -0
- package/dist/core/secret-env.js.map +1 -0
- package/dist/core/select-model.d.ts +26 -0
- package/dist/core/select-model.d.ts.map +1 -0
- package/dist/core/select-model.js +58 -0
- package/dist/core/select-model.js.map +1 -0
- package/dist/core/sensitive-path-policy.d.ts +24 -0
- package/dist/core/sensitive-path-policy.d.ts.map +1 -0
- package/dist/core/sensitive-path-policy.js +96 -0
- package/dist/core/sensitive-path-policy.js.map +1 -0
- package/dist/core/session-policy-store.d.ts +102 -0
- package/dist/core/session-policy-store.d.ts.map +1 -0
- package/dist/core/session-policy-store.js +177 -0
- package/dist/core/session-policy-store.js.map +1 -0
- package/dist/core/session-reconcile.d.ts +63 -0
- package/dist/core/session-reconcile.d.ts.map +1 -0
- package/dist/core/session-reconcile.js +71 -0
- package/dist/core/session-reconcile.js.map +1 -0
- package/dist/core/session-store.d.ts +99 -0
- package/dist/core/session-store.d.ts.map +1 -0
- package/dist/core/session-store.js +298 -0
- package/dist/core/session-store.js.map +1 -0
- package/dist/core/session.d.ts +144 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/session.js +56 -0
- package/dist/core/session.js.map +1 -0
- package/dist/core/spec-contract.d.ts +147 -0
- package/dist/core/spec-contract.d.ts.map +1 -0
- package/dist/core/spec-contract.js +340 -0
- package/dist/core/spec-contract.js.map +1 -0
- package/dist/core/strategy-store.d.ts +50 -0
- package/dist/core/strategy-store.d.ts.map +1 -0
- package/dist/core/strategy-store.js +100 -0
- package/dist/core/strategy-store.js.map +1 -0
- package/dist/core/stub-env.d.ts +35 -0
- package/dist/core/stub-env.d.ts.map +1 -0
- package/dist/core/stub-env.js +69 -0
- package/dist/core/stub-env.js.map +1 -0
- package/dist/core/task-notification.d.ts +115 -0
- package/dist/core/task-notification.d.ts.map +1 -0
- package/dist/core/task-notification.js +247 -0
- package/dist/core/task-notification.js.map +1 -0
- package/dist/core/task-outcome.d.ts +80 -0
- package/dist/core/task-outcome.d.ts.map +1 -0
- package/dist/core/task-outcome.js +40 -0
- package/dist/core/task-outcome.js.map +1 -0
- package/dist/core/task-registry.d.ts +349 -0
- package/dist/core/task-registry.d.ts.map +1 -0
- package/dist/core/task-registry.js +1751 -0
- package/dist/core/task-registry.js.map +1 -0
- package/dist/core/tighten-task-spec.d.ts +27 -0
- package/dist/core/tighten-task-spec.d.ts.map +1 -0
- package/dist/core/tighten-task-spec.js +95 -0
- package/dist/core/tighten-task-spec.js.map +1 -0
- package/dist/core/tool-detach.d.ts +31 -0
- package/dist/core/tool-detach.d.ts.map +1 -0
- package/dist/core/tool-detach.js +62 -0
- package/dist/core/tool-detach.js.map +1 -0
- package/dist/core/tool-errors.d.ts +72 -0
- package/dist/core/tool-errors.d.ts.map +1 -0
- package/dist/core/tool-errors.js +194 -0
- package/dist/core/tool-errors.js.map +1 -0
- package/dist/core/tool-name-aliases.d.ts +5 -0
- package/dist/core/tool-name-aliases.d.ts.map +1 -0
- package/dist/core/tool-name-aliases.js +130 -0
- package/dist/core/tool-name-aliases.js.map +1 -0
- package/dist/core/tool-policy.d.ts +295 -0
- package/dist/core/tool-policy.d.ts.map +1 -0
- package/dist/core/tool-policy.js +567 -0
- package/dist/core/tool-policy.js.map +1 -0
- package/dist/core/tool-result-budget.d.ts +44 -0
- package/dist/core/tool-result-budget.d.ts.map +1 -0
- package/dist/core/tool-result-budget.js +140 -0
- package/dist/core/tool-result-budget.js.map +1 -0
- package/dist/core/tool-result-store.d.ts +136 -0
- package/dist/core/tool-result-store.d.ts.map +1 -0
- package/dist/core/tool-result-store.js +219 -0
- package/dist/core/tool-result-store.js.map +1 -0
- package/dist/core/tools.d.ts +14 -0
- package/dist/core/tools.d.ts.map +1 -0
- package/dist/core/tools.js +98 -0
- package/dist/core/tools.js.map +1 -0
- package/dist/core/trace.d.ts +340 -0
- package/dist/core/trace.d.ts.map +1 -0
- package/dist/core/trace.js +12 -0
- package/dist/core/trace.js.map +1 -0
- package/dist/core/types.d.ts +2828 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/untrusted-egress.d.ts +32 -0
- package/dist/core/untrusted-egress.d.ts.map +1 -0
- package/dist/core/untrusted-egress.js +49 -0
- package/dist/core/untrusted-egress.js.map +1 -0
- package/dist/core/untrusted-text.d.ts +64 -0
- package/dist/core/untrusted-text.d.ts.map +1 -0
- package/dist/core/untrusted-text.js +119 -0
- package/dist/core/untrusted-text.js.map +1 -0
- package/dist/core/warm-resume.d.ts +23 -0
- package/dist/core/warm-resume.d.ts.map +1 -0
- package/dist/core/warm-resume.js +28 -0
- package/dist/core/warm-resume.js.map +1 -0
- package/dist/core/with-retry.d.ts +43 -0
- package/dist/core/with-retry.d.ts.map +1 -0
- package/dist/core/with-retry.js +59 -0
- package/dist/core/with-retry.js.map +1 -0
- package/dist/core/workflow-journal-store.d.ts +44 -0
- package/dist/core/workflow-journal-store.d.ts.map +1 -0
- package/dist/core/workflow-journal-store.js +47 -0
- package/dist/core/workflow-journal-store.js.map +1 -0
- package/dist/core/workflow-run-store-contract.d.ts +31 -0
- package/dist/core/workflow-run-store-contract.d.ts.map +1 -0
- package/dist/core/workflow-run-store-contract.js +191 -0
- package/dist/core/workflow-run-store-contract.js.map +1 -0
- package/dist/core/workflow-run-store.d.ts +149 -0
- package/dist/core/workflow-run-store.d.ts.map +1 -0
- package/dist/core/workflow-run-store.js +110 -0
- package/dist/core/workflow-run-store.js.map +1 -0
- package/dist/engine/compaction/compaction.d.ts +139 -0
- package/dist/engine/compaction/compaction.d.ts.map +1 -0
- package/dist/engine/compaction/compaction.js +1030 -0
- package/dist/engine/compaction/compaction.js.map +1 -0
- package/dist/engine/compaction/utils.d.ts +45 -0
- package/dist/engine/compaction/utils.d.ts.map +1 -0
- package/dist/engine/compaction/utils.js +203 -0
- package/dist/engine/compaction/utils.js.map +1 -0
- package/dist/engine/execution-env/kill-tree.d.ts +20 -0
- package/dist/engine/execution-env/kill-tree.d.ts.map +1 -0
- package/dist/engine/execution-env/kill-tree.js +183 -0
- package/dist/engine/execution-env/kill-tree.js.map +1 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +133 -0
- package/dist/engine/execution-env/node-execution-env.d.ts.map +1 -0
- package/dist/engine/execution-env/node-execution-env.js +1031 -0
- package/dist/engine/execution-env/node-execution-env.js.map +1 -0
- package/dist/engine/harness/agent-harness.d.ts +174 -0
- package/dist/engine/harness/agent-harness.d.ts.map +1 -0
- package/dist/engine/harness/agent-harness.js +1053 -0
- package/dist/engine/harness/agent-harness.js.map +1 -0
- package/dist/engine/harness/messages.d.ts +17 -0
- package/dist/engine/harness/messages.d.ts.map +1 -0
- package/dist/engine/harness/messages.js +122 -0
- package/dist/engine/harness/messages.js.map +1 -0
- package/dist/engine/harness/types.d.ts +713 -0
- package/dist/engine/harness/types.d.ts.map +1 -0
- package/dist/engine/harness/types.js +100 -0
- package/dist/engine/harness/types.js.map +1 -0
- package/dist/engine/llm/diagnostics.d.ts +23 -0
- package/dist/engine/llm/diagnostics.d.ts.map +1 -0
- package/dist/engine/llm/diagnostics.js +32 -0
- package/dist/engine/llm/diagnostics.js.map +1 -0
- package/dist/engine/llm/event-stream.d.ts +25 -0
- package/dist/engine/llm/event-stream.d.ts.map +1 -0
- package/dist/engine/llm/event-stream.js +103 -0
- package/dist/engine/llm/event-stream.js.map +1 -0
- package/dist/engine/llm/index.d.ts +12 -0
- package/dist/engine/llm/index.d.ts.map +1 -0
- package/dist/engine/llm/index.js +12 -0
- package/dist/engine/llm/index.js.map +1 -0
- package/dist/engine/llm/types.d.ts +753 -0
- package/dist/engine/llm/types.d.ts.map +1 -0
- package/dist/engine/llm/types.js +2 -0
- package/dist/engine/llm/types.js.map +1 -0
- package/dist/engine/llm/validation.d.ts +8 -0
- package/dist/engine/llm/validation.d.ts.map +1 -0
- package/dist/engine/llm/validation.js +318 -0
- package/dist/engine/llm/validation.js.map +1 -0
- package/dist/engine/loop/agent-loop.d.ts +74 -0
- package/dist/engine/loop/agent-loop.d.ts.map +1 -0
- package/dist/engine/loop/agent-loop.js +1490 -0
- package/dist/engine/loop/agent-loop.js.map +1 -0
- package/dist/engine/loop/runtime-deps.d.ts +17 -0
- package/dist/engine/loop/runtime-deps.d.ts.map +1 -0
- package/dist/engine/loop/runtime-deps.js +21 -0
- package/dist/engine/loop/runtime-deps.js.map +1 -0
- package/dist/engine/loop/types.d.ts +609 -0
- package/dist/engine/loop/types.d.ts.map +1 -0
- package/dist/engine/loop/types.js +2 -0
- package/dist/engine/loop/types.js.map +1 -0
- package/dist/engine/lsp/frame-decoder.d.ts +16 -0
- package/dist/engine/lsp/frame-decoder.d.ts.map +1 -0
- package/dist/engine/lsp/frame-decoder.js +53 -0
- package/dist/engine/lsp/frame-decoder.js.map +1 -0
- package/dist/engine/lsp/node-lsp-manager.d.ts +105 -0
- package/dist/engine/lsp/node-lsp-manager.d.ts.map +1 -0
- package/dist/engine/lsp/node-lsp-manager.js +343 -0
- package/dist/engine/lsp/node-lsp-manager.js.map +1 -0
- package/dist/engine/lsp/stdio-lsp-transport.d.ts +37 -0
- package/dist/engine/lsp/stdio-lsp-transport.d.ts.map +1 -0
- package/dist/engine/lsp/stdio-lsp-transport.js +185 -0
- package/dist/engine/lsp/stdio-lsp-transport.js.map +1 -0
- package/dist/engine/session/import-validate.d.ts +44 -0
- package/dist/engine/session/import-validate.d.ts.map +1 -0
- package/dist/engine/session/import-validate.js +92 -0
- package/dist/engine/session/import-validate.js.map +1 -0
- package/dist/engine/session/memory-repo.d.ts +25 -0
- package/dist/engine/session/memory-repo.d.ts.map +1 -0
- package/dist/engine/session/memory-repo.js +59 -0
- package/dist/engine/session/memory-repo.js.map +1 -0
- package/dist/engine/session/memory-storage.d.ts +14 -0
- package/dist/engine/session/memory-storage.d.ts.map +1 -0
- package/dist/engine/session/memory-storage.js +17 -0
- package/dist/engine/session/memory-storage.js.map +1 -0
- package/dist/engine/session/repo-utils.d.ts +11 -0
- package/dist/engine/session/repo-utils.d.ts.map +1 -0
- package/dist/engine/session/repo-utils.js +40 -0
- package/dist/engine/session/repo-utils.js.map +1 -0
- package/dist/engine/session/session.d.ts +34 -0
- package/dist/engine/session/session.d.ts.map +1 -0
- package/dist/engine/session/session.js +227 -0
- package/dist/engine/session/session.js.map +1 -0
- package/dist/engine/session/storage-base.d.ts +38 -0
- package/dist/engine/session/storage-base.d.ts.map +1 -0
- package/dist/engine/session/storage-base.js +157 -0
- package/dist/engine/session/storage-base.js.map +1 -0
- package/dist/engine/session/timestamps.d.ts +3 -0
- package/dist/engine/session/timestamps.d.ts.map +1 -0
- package/dist/engine/session/timestamps.js +15 -0
- package/dist/engine/session/timestamps.js.map +1 -0
- package/dist/engine/session/uuid.d.ts +2 -0
- package/dist/engine/session/uuid.d.ts.map +1 -0
- package/dist/engine/session/uuid.js +50 -0
- package/dist/engine/session/uuid.js.map +1 -0
- package/dist/index.d.ts +160 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +374 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/harness.d.ts +26 -0
- package/dist/internal/harness.d.ts.map +1 -0
- package/dist/internal/harness.js +24 -0
- package/dist/internal/harness.js.map +1 -0
- package/dist/internal/llm.d.ts +9 -0
- package/dist/internal/llm.d.ts.map +1 -0
- package/dist/internal/llm.js +8 -0
- package/dist/internal/llm.js.map +1 -0
- package/dist/orchestration/builtin-workflows.d.ts +44 -0
- package/dist/orchestration/builtin-workflows.d.ts.map +1 -0
- package/dist/orchestration/builtin-workflows.js +165 -0
- package/dist/orchestration/builtin-workflows.js.map +1 -0
- package/dist/orchestration/dev-vm-script-runner.d.ts +24 -0
- package/dist/orchestration/dev-vm-script-runner.d.ts.map +1 -0
- package/dist/orchestration/dev-vm-script-runner.js +106 -0
- package/dist/orchestration/dev-vm-script-runner.js.map +1 -0
- package/dist/orchestration/goal.d.ts +97 -0
- package/dist/orchestration/goal.d.ts.map +1 -0
- package/dist/orchestration/goal.js +248 -0
- package/dist/orchestration/goal.js.map +1 -0
- package/dist/orchestration/run-spec.d.ts +63 -0
- package/dist/orchestration/run-spec.d.ts.map +1 -0
- package/dist/orchestration/run-spec.js +274 -0
- package/dist/orchestration/run-spec.js.map +1 -0
- package/dist/orchestration/run-workflow-tool.d.ts +187 -0
- package/dist/orchestration/run-workflow-tool.d.ts.map +1 -0
- package/dist/orchestration/run-workflow-tool.js +612 -0
- package/dist/orchestration/run-workflow-tool.js.map +1 -0
- package/dist/orchestration/workflow-governance.d.ts +70 -0
- package/dist/orchestration/workflow-governance.d.ts.map +1 -0
- package/dist/orchestration/workflow-governance.js +176 -0
- package/dist/orchestration/workflow-governance.js.map +1 -0
- package/dist/orchestration/workflow-meta.d.ts +41 -0
- package/dist/orchestration/workflow-meta.d.ts.map +1 -0
- package/dist/orchestration/workflow-meta.js +426 -0
- package/dist/orchestration/workflow-meta.js.map +1 -0
- package/dist/orchestration/workflow-observe.d.ts +77 -0
- package/dist/orchestration/workflow-observe.d.ts.map +1 -0
- package/dist/orchestration/workflow-observe.js +177 -0
- package/dist/orchestration/workflow-observe.js.map +1 -0
- package/dist/orchestration/workflow-primitives.d.ts +31 -0
- package/dist/orchestration/workflow-primitives.d.ts.map +1 -0
- package/dist/orchestration/workflow-primitives.js +104 -0
- package/dist/orchestration/workflow-primitives.js.map +1 -0
- package/dist/orchestration/workflow-sandbox-conformance.d.ts +34 -0
- package/dist/orchestration/workflow-sandbox-conformance.d.ts.map +1 -0
- package/dist/orchestration/workflow-sandbox-conformance.js +301 -0
- package/dist/orchestration/workflow-sandbox-conformance.js.map +1 -0
- package/dist/orchestration/workflow-script-runner.d.ts +127 -0
- package/dist/orchestration/workflow-script-runner.d.ts.map +1 -0
- package/dist/orchestration/workflow-script-runner.js +48 -0
- package/dist/orchestration/workflow-script-runner.js.map +1 -0
- package/dist/orchestration/workflow-script-store.d.ts +99 -0
- package/dist/orchestration/workflow-script-store.d.ts.map +1 -0
- package/dist/orchestration/workflow-script-store.js +133 -0
- package/dist/orchestration/workflow-script-store.js.map +1 -0
- package/dist/orchestration/workflow-size-guideline.d.ts +50 -0
- package/dist/orchestration/workflow-size-guideline.d.ts.map +1 -0
- package/dist/orchestration/workflow-size-guideline.js +78 -0
- package/dist/orchestration/workflow-size-guideline.js.map +1 -0
- package/dist/orchestration/workflow.d.ts +624 -0
- package/dist/orchestration/workflow.d.ts.map +1 -0
- package/dist/orchestration/workflow.js +1596 -0
- package/dist/orchestration/workflow.js.map +1 -0
- package/dist/prompts/default.d.ts +474 -0
- package/dist/prompts/default.d.ts.map +1 -0
- package/dist/prompts/default.js +676 -0
- package/dist/prompts/default.js.map +1 -0
- package/dist/prompts/supervisor.d.ts +60 -0
- package/dist/prompts/supervisor.d.ts.map +1 -0
- package/dist/prompts/supervisor.js +162 -0
- package/dist/prompts/supervisor.js.map +1 -0
- package/dist/scenarios/env.d.ts +41 -0
- package/dist/scenarios/env.d.ts.map +1 -0
- package/dist/scenarios/env.js +65 -0
- package/dist/scenarios/env.js.map +1 -0
- package/dist/scenarios/full-body.d.ts +47 -0
- package/dist/scenarios/full-body.d.ts.map +1 -0
- package/dist/scenarios/full-body.js +36 -0
- package/dist/scenarios/full-body.js.map +1 -0
- package/dist/scenarios/scenario-registry.d.ts +107 -0
- package/dist/scenarios/scenario-registry.d.ts.map +1 -0
- package/dist/scenarios/scenario-registry.js +192 -0
- package/dist/scenarios/scenario-registry.js.map +1 -0
- package/dist/scenarios/teacher-quickstart.d.ts +41 -0
- package/dist/scenarios/teacher-quickstart.d.ts.map +1 -0
- package/dist/scenarios/teacher-quickstart.js +32 -0
- package/dist/scenarios/teacher-quickstart.js.map +1 -0
- package/dist/server/http.d.ts +36 -0
- package/dist/server/http.d.ts.map +1 -0
- package/dist/server/http.js +144 -0
- package/dist/server/http.js.map +1 -0
- package/dist/stores/file/checkpoint-store.d.ts +62 -0
- package/dist/stores/file/checkpoint-store.d.ts.map +1 -0
- package/dist/stores/file/checkpoint-store.js +250 -0
- package/dist/stores/file/checkpoint-store.js.map +1 -0
- package/dist/stores/file/file-snapshot-store.d.ts +43 -0
- package/dist/stores/file/file-snapshot-store.d.ts.map +1 -0
- package/dist/stores/file/file-snapshot-store.js +374 -0
- package/dist/stores/file/file-snapshot-store.js.map +1 -0
- package/dist/stores/file/fs-atomic.d.ts +95 -0
- package/dist/stores/file/fs-atomic.d.ts.map +1 -0
- package/dist/stores/file/fs-atomic.js +415 -0
- package/dist/stores/file/fs-atomic.js.map +1 -0
- package/dist/stores/file/index.d.ts +98 -0
- package/dist/stores/file/index.d.ts.map +1 -0
- package/dist/stores/file/index.js +109 -0
- package/dist/stores/file/index.js.map +1 -0
- package/dist/stores/file/memory-store.d.ts +95 -0
- package/dist/stores/file/memory-store.d.ts.map +1 -0
- package/dist/stores/file/memory-store.js +393 -0
- package/dist/stores/file/memory-store.js.map +1 -0
- package/dist/stores/file/session-policy-store.d.ts +24 -0
- package/dist/stores/file/session-policy-store.d.ts.map +1 -0
- package/dist/stores/file/session-policy-store.js +123 -0
- package/dist/stores/file/session-policy-store.js.map +1 -0
- package/dist/stores/file/session-store.d.ts +34 -0
- package/dist/stores/file/session-store.d.ts.map +1 -0
- package/dist/stores/file/session-store.js +175 -0
- package/dist/stores/file/session-store.js.map +1 -0
- package/dist/stores/file/tool-result-store.d.ts +23 -0
- package/dist/stores/file/tool-result-store.d.ts.map +1 -0
- package/dist/stores/file/tool-result-store.js +61 -0
- package/dist/stores/file/tool-result-store.js.map +1 -0
- package/dist/stores/file/workflow-journal-store.d.ts +36 -0
- package/dist/stores/file/workflow-journal-store.d.ts.map +1 -0
- package/dist/stores/file/workflow-journal-store.js +157 -0
- package/dist/stores/file/workflow-journal-store.js.map +1 -0
- package/dist/stores/file/workflow-run-store.d.ts +58 -0
- package/dist/stores/file/workflow-run-store.d.ts.map +1 -0
- package/dist/stores/file/workflow-run-store.js +178 -0
- package/dist/stores/file/workflow-run-store.js.map +1 -0
- package/dist/stores/pg.d.ts +210 -0
- package/dist/stores/pg.d.ts.map +1 -0
- package/dist/stores/pg.js +652 -0
- package/dist/stores/pg.js.map +1 -0
- package/dist/tools/fs/encoding.d.ts +51 -0
- package/dist/tools/fs/encoding.d.ts.map +1 -0
- package/dist/tools/fs/encoding.js +74 -0
- package/dist/tools/fs/encoding.js.map +1 -0
- package/dist/tools/fs/gh-rate-limit.d.ts +19 -0
- package/dist/tools/fs/gh-rate-limit.d.ts.map +1 -0
- package/dist/tools/fs/gh-rate-limit.js +35 -0
- package/dist/tools/fs/gh-rate-limit.js.map +1 -0
- package/dist/tools/fs/index.d.ts +246 -0
- package/dist/tools/fs/index.d.ts.map +1 -0
- package/dist/tools/fs/index.js +2130 -0
- package/dist/tools/fs/index.js.map +1 -0
- package/dist/tools/fs/pdf.d.ts +106 -0
- package/dist/tools/fs/pdf.d.ts.map +1 -0
- package/dist/tools/fs/pdf.js +178 -0
- package/dist/tools/fs/pdf.js.map +1 -0
- package/dist/tools/fs/repo-map.d.ts +15 -0
- package/dist/tools/fs/repo-map.d.ts.map +1 -0
- package/dist/tools/fs/repo-map.js +251 -0
- package/dist/tools/fs/repo-map.js.map +1 -0
- package/dist/tools/fs/safety.d.ts +168 -0
- package/dist/tools/fs/safety.d.ts.map +1 -0
- package/dist/tools/fs/safety.js +479 -0
- package/dist/tools/fs/safety.js.map +1 -0
- package/dist/tools/fs/search.d.ts +118 -0
- package/dist/tools/fs/search.d.ts.map +1 -0
- package/dist/tools/fs/search.js +650 -0
- package/dist/tools/fs/search.js.map +1 -0
- package/dist/tools/gitea-issue.d.ts +39 -0
- package/dist/tools/gitea-issue.d.ts.map +1 -0
- package/dist/tools/gitea-issue.js +91 -0
- package/dist/tools/gitea-issue.js.map +1 -0
- package/dist/tools/monitor.d.ts +64 -0
- package/dist/tools/monitor.d.ts.map +1 -0
- package/dist/tools/monitor.js +135 -0
- package/dist/tools/monitor.js.map +1 -0
- package/dist/tools/scheduler-tools.d.ts +48 -0
- package/dist/tools/scheduler-tools.d.ts.map +1 -0
- package/dist/tools/scheduler-tools.js +449 -0
- package/dist/tools/scheduler-tools.js.map +1 -0
- package/dist/tools/sql-adapters.d.ts +32 -0
- package/dist/tools/sql-adapters.d.ts.map +1 -0
- package/dist/tools/sql-adapters.js +31 -0
- package/dist/tools/sql-adapters.js.map +1 -0
- package/dist/tools/sql.d.ts +36 -0
- package/dist/tools/sql.d.ts.map +1 -0
- package/dist/tools/sql.js +131 -0
- package/dist/tools/sql.js.map +1 -0
- package/dist/tools/task-list.d.ts +26 -0
- package/dist/tools/task-list.d.ts.map +1 -0
- package/dist/tools/task-list.js +352 -0
- package/dist/tools/task-list.js.map +1 -0
- package/dist/tools/todo.d.ts +11 -0
- package/dist/tools/todo.d.ts.map +1 -0
- package/dist/tools/todo.js +126 -0
- package/dist/tools/todo.js.map +1 -0
- package/dist/tools/web.d.ts +59 -0
- package/dist/tools/web.d.ts.map +1 -0
- package/dist/tools/web.js +607 -0
- package/dist/tools/web.js.map +1 -0
- package/dist/tools/worktree.d.ts +88 -0
- package/dist/tools/worktree.d.ts.map +1 -0
- package/dist/tools/worktree.js +434 -0
- package/dist/tools/worktree.js.map +1 -0
- package/docs/A1-ATTRIBUTION-ROUND1-2026-07-09.md +181 -0
- package/docs/AB-ORACLE-GATE-VERDICT-2026-07-10.md +100 -0
- package/docs/ANCHOR-GAP-INVENTORY-2026-07-09.md +143 -0
- package/docs/ARCHITECTURE.md +125 -0
- package/docs/BUGHUNT-2026-07-05-NIGHT.md +98 -0
- package/docs/BUILD.md +63 -0
- package/docs/CANCEL-ASYNC-ATTRIBUTION-2026-07-09.md +98 -0
- package/docs/CC-198-VS-201-DRIFT-2026-07-09.md +70 -0
- package/docs/CC-BASELINE-FAKE-ZERO-AUDIT-2026-07-09.md +51 -0
- package/docs/CC-DRIFT-198-206-AGENT-TYPES-2026-07-10.md +82 -0
- package/docs/CC-DRIFT-198-206-CHANGELOG-2026-07-10.md +82 -0
- package/docs/CC-DRIFT-198-206-REMINDERS-2026-07-10.md +96 -0
- package/docs/CC-DRIFT-198-206-ROADMAP-2026-07-10.md +110 -0
- package/docs/CC-DRIFT-198-206-TOOL-INVENTORY-2026-07-10.md +53 -0
- package/docs/CC-DRIFT-198-206-USAGE-CONSTANTS-2026-07-10.md +64 -0
- package/docs/CC-DRIFT-198-206-WORKFLOW-2026-07-10.md +83 -0
- package/docs/CC-PARITY-CHECKLIST.md +220 -0
- package/docs/CC-PARITY-DEEP-SWEEP-2026-07-07.md +149 -0
- package/docs/CC-SUBAGENT-PROMPT-STUDY-2026-07-09.md +219 -0
- package/docs/CC-TASK-REMINDER-CADENCE-STUDY-2026-07-09.md +396 -0
- package/docs/CC-TOOL-PARITY-SWEEP-2026-07.md +56 -0
- package/docs/CC-TOOL-PROMPT-DEEP-DIFF-2026-07-08.md +274 -0
- package/docs/CC-TOOLSURFACE-DEEP-DIVE-2026-07-07.md +197 -0
- package/docs/CC206-OBSERVER-ANCHORS-2026-07-11.md +463 -0
- package/docs/CC207-CORE-SWEEP-BACKLOG-2026-07-12.md +155 -0
- package/docs/CENTER-CONTROL-PLANE-SEAM.md +86 -0
- package/docs/CLEANUP-CONTRACT-ANCHOR-2026-07-09.md +83 -0
- package/docs/COLD-START-RSI-2026-07-09.md +72 -0
- package/docs/COMPACTION-LIVE-AUDIT-2026-07-09.md +114 -0
- package/docs/CONTEXT-lifecycle-extension-points-and-stop-attribution.md +71 -0
- package/docs/COREWARS-POLYGLOT-TRIAGE-2026-07-09.md +85 -0
- package/docs/DEADTARGET-OVERFULL-HBOX-2026-07-10.md +92 -0
- package/docs/DEADTARGET-PATH-TRACING-REVERSE-2026-07-10.md +87 -0
- package/docs/DEADTARGET-WINNING-AVG-COREWARS-2026-07-10.md +96 -0
- package/docs/DEEPSEEK-API-LIMITS-PROBE-2026-07-09.md +118 -0
- package/docs/DESIGN-140-MOCK-VERIFY-2026-07-11.md +79 -0
- package/docs/DESIGN-140-VERIFICATION-2026-07-11.md +43 -0
- package/docs/DESIGN-DRAFT-workflow-collab-2026-07-11.md +56 -0
- package/docs/DESIGN-ORACLE-GROUNDING-GATE-2026-07-10.md +167 -0
- package/docs/DESIGN-TFRAG-RECONCILE-SCAFFOLD-2026-07-09.md +102 -0
- package/docs/EXP-PA2-PE-DESIGN-2026-07-11.md +220 -0
- package/docs/EXT-DOGFOOD-2026-07-12.md +50 -0
- package/docs/FINAL-VERIFY-SURFACE-AUDIT-2026-07-09.md +44 -0
- package/docs/FRAG-RECON-INVESTIGATION-2026-07-09.md +183 -0
- package/docs/HANDOFF.md +121 -0
- package/docs/KNOWN-ISSUES.md +96 -0
- package/docs/LEGW-WINDOW-TAX-2026-07-10.md +82 -0
- package/docs/LIVE-PROBE-BATCH-2026-07-11.md +207 -0
- package/docs/M2-CERT-ATTRIBUTION-2026-07-10.md +61 -0
- package/docs/M25-LEG-VARIANCE-ATTRIBUTION-2026-07-10.md +81 -0
- package/docs/MAILMAN-TIMEOUT-ATTRIBUTION-2026-07-10.md +88 -0
- package/docs/MEMORY-BACKEND-DIALECT-NOTES.md +69 -0
- package/docs/MTEB-ESCAPE-HATCH-ATTRIBUTION-2026-07-09.md +57 -0
- package/docs/MTEB-LEADERBOARD-ATTRIBUTION-2026-07-10.md +134 -0
- package/docs/ORACLE-GATE-NEGATIVE-SAMPLE-2026-07-11.md +28 -0
- package/docs/PARITY-CONTEXT-TRANSACTIONS-2026-07-10.md +67 -0
- package/docs/PARITY-PROGRESS-MATRIX-2026-07-10.md +37 -0
- package/docs/PARITY-SPOT-AGENT-TYPES-2026-07-10.md +70 -0
- package/docs/PARITY-SPOT-REMINDERS-2026-07-10.md +144 -0
- package/docs/PARITY-SPOT-TOOL-INVENTORY-2026-07-10.md +61 -0
- package/docs/PARITY-SPOT-USAGE-CONSTANTS-2026-07-10.md +95 -0
- package/docs/PARITY-SPOT-WORKFLOW-2026-07-10.md +93 -0
- package/docs/PASSWORD-RECOVERY-PANEL-VERDICT-2026-07-10.md +62 -0
- package/docs/R8-R9-FINALIZE-COORDINATION-2026-07-09.md +124 -0
- package/docs/REPL-CODE-MODE-EVALUATION-2026-07-10.md +187 -0
- package/docs/REPORT-1249-TARGETED.md +48 -0
- package/docs/RESEARCH-3P-MEMORY-SWAP-2026-07-12.md +273 -0
- package/docs/ROADMAP.md +111 -0
- package/docs/RSI-CLOUD-DEPLOY-2026-07-06.md +289 -0
- package/docs/RSI-PROCESS-AI-COLDSTART-2026-07-11.md +68 -0
- package/docs/S18-THOROUGHNESS-AUDIT-2026-07-09.md +113 -0
- package/docs/SERVICE-INTEGRATION-GUIDE.md +298 -0
- package/docs/SUBAGENT-STREAM-RESILIENCE-PARITY-2026-07-10.md +118 -0
- package/docs/SWEBENCH-PRO-RECON-2026-07-11.md +31 -0
- package/docs/TB-EFFICIENCY-TELEMETRY-2026-07-08.md +114 -0
- package/docs/TB-FAILURE-AUTOPSY-2026-07-05-RERUN.md +67 -0
- package/docs/TB-FAIRNESS-AUDIT-2026-07-08.md +141 -0
- package/docs/TB-FULL-1257-2026-07-08.md +77 -0
- package/docs/TB-LEG-GAP-ATTRIBUTION-1261-1263-2026-07-11.md +154 -0
- package/docs/TB-REGRESSION-DAEMON-KILL-2026-07-08.md +58 -0
- package/docs/TB-RSI-CROSSCHECK-2026-07-06.md +68 -0
- package/docs/TB-RSI-LEDGER.md +30 -0
- package/docs/TB-STABLE-SET-2026-07-08.md +127 -0
- package/docs/TB21-RECON-2026-07-11.md +28 -0
- package/docs/TEST-DESIGN-BATCH-1-2-3.md +97 -0
- package/docs/THIRD-PARTY-INTEGRATION.md +45 -0
- package/docs/TOKEN-ESTIMATE-CALIBRATION-LIVE-2026-07-09.md +102 -0
- package/docs/audit-2026-06-10-/347/254/254/344/272/214/350/275/256-/347/251/272/347/231/275/345/214/272/344/270/216/345/277/230/346/216/245/347/272/277.md +147 -0
- package/docs/audit-2026-06-10-/350/256/241/347/256/227bug/346/211/253/346/217/217.md +163 -0
- package/docs/audit-2026-06-11-/344/277/256/345/244/215/345/244/215/345/256/241/344/270/216/345/233/236/345/275/222/344/270/223/346/211/253.md +95 -0
- package/docs/audit-2026-06-12-design71-P1/346/275/234/344/274/217/351/235/242/350/243/201/345/206/263/344/270/216/345/220/236/351/224/231/345/256/241/350/256/241.md +45 -0
- package/docs/audit-2026-06-12-/345/205/254/345/274/200/346/227/213/351/222/256/346/264/273/346/200/247/344/270/216vendored/346/255/273/350/267/257.md +63 -0
- package/docs/audit-2026-06-15/ADDENDUM-second-pass.md +88 -0
- package/docs/audit-2026-06-15/ARCHITECTURE-AND-ROADMAP.md +187 -0
- package/docs/audit-2026-06-15/DOC-CORRECTIONS.md +105 -0
- package/docs/audit-2026-06-15/INDEX.md +49 -0
- package/docs/audit-2026-06-15/ORCHESTRATION-STATUS.md +98 -0
- package/docs/audit-2026-06-15/PRODUCTION-ISSUES.md +189 -0
- package/docs/audit-2026-06-15/REFERENCES-literature.md +139 -0
- package/docs/audit-2026-06-15/VENDOR-REFACTOR-PLAN.md +96 -0
- package/docs/cc-probe-198/README.md +72 -0
- package/docs/cc-probe-198/STABILITY-AUDIT.md +118 -0
- package/docs/cc-probe-198/live-schema-monitor-worktree-2026-07-09.json +56 -0
- package/docs/cc-probe-198/mount-variants.json +536 -0
- package/docs/cc-probe-198/plan-mode-run.json +1 -0
- package/docs/cc-probe-198/probe-bash-bg.json +224 -0
- package/docs/cc-probe-198/probe-edit-mismatch.json +120 -0
- package/docs/cc-probe-198/probe-read-missing.json +62 -0
- package/docs/cc-probe-198/probe-search-empty.json +127 -0
- package/docs/cc-probe-198/probe-task-family.json +227 -0
- package/docs/cc-probe-198/probes.status +6 -0
- package/docs/cc-probe-198/raw-capture-interactive.json +948 -0
- package/docs/cc-probe-198/raw-capture-print.json +787 -0
- package/docs/cc-probe-198/raw-capture2-interactive.json +948 -0
- package/docs/cc-probe-198/raw-capture2-print.json +787 -0
- package/docs/cc-probe-198/system-prompt.txt +135 -0
- package/docs/cc-probe-198/tools-array.json +962 -0
- package/docs/durability-boundary.md +63 -0
- package/docs/fix-2026-06-10-/350/256/241/347/256/227bug/344/277/256/345/244/215-search/346/211/271.md +75 -0
- package/docs/fix-2026-06-11-/347/254/254/344/272/214/350/275/256-/344/277/256/345/244/215-search/346/211/271.md +62 -0
- package/docs/parity-sweep/REPORT-DYNAMIC.md +97 -0
- package/docs/parity-sweep/REPORT-STATIC-GGB.md +127 -0
- package/docs/parity-sweep/REPORT-STATIC-RWE.md +133 -0
- package/docs/vendor-history.md +385 -0
- package/docs/vendored-upstream-diff-2026-07.md +83 -0
- package/package.json +70 -0
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostgreSQL **reference adapters** for the two durable seams a deployment must supply to make a
|
|
3
|
+
* stateless runner durable (the "session center" + design/45 durable-checkpoint):
|
|
4
|
+
*
|
|
5
|
+
* - {@link PgSessionRepo} — a durable `SessionRepo` (append-only event log). Hand it to the built-in
|
|
6
|
+
* `TtlSessionStore` (`new TtlSessionStore({ repo })`) and you get the full session center: wake on
|
|
7
|
+
* `acquire`, idle-cache, cross-instance optimistic lock. This is the README §11 recipe, on Postgres.
|
|
8
|
+
* - {@link PgCheckpointStore} — a durable `CheckpointStore` (design/45 F4/1C): atomic CAS `resolve`,
|
|
9
|
+
* `expire` fence, deadline `reap`.
|
|
10
|
+
*
|
|
11
|
+
* **Driver-neutral**: this module depends on no Postgres client. Pass any `(text, params) => {rows}`
|
|
12
|
+
* function ({@link PgQueryFn}) — `node-postgres` (`(t, p) => pool.query(t, p)`), `pg-mem` in tests, or
|
|
13
|
+
* a thin wrapper over postgres.js. The SQL sticks to portable basics (text/bigint/jsonb columns,
|
|
14
|
+
* `ON CONFLICT`, conditional `UPDATE … RETURNING`).
|
|
15
|
+
*
|
|
16
|
+
* **Concurrency contract** (mirrors the TiDB backend, README §11 / design/10):
|
|
17
|
+
* - Session appends are serialized by the `(session_id, seq)` primary key: two replicas that woke the
|
|
18
|
+
* same session race their next `INSERT`; the loser hits a unique violation and gets
|
|
19
|
+
* `SessionError("conflict")` (catch with `isSessionConflict`) — never a silent fork.
|
|
20
|
+
* - `resolve`/`expire` are single-row conditional UPDATEs over the same `pending` row, so the DB
|
|
21
|
+
* serializes them: exactly one wins (the once-only foundation, design/45 §2.1).
|
|
22
|
+
*
|
|
23
|
+
* Reference-grade scope (open-source profile): full-tree wake (no F3 bounded-tail query), no
|
|
24
|
+
* connection management (the caller owns the pool), no retention/GC worker (run `reap` + your own
|
|
25
|
+
* retention policy on a schedule).
|
|
26
|
+
*/
|
|
27
|
+
import { BaseSessionStorage, Session, SessionError, getEntriesToFork, uuidv7, } from "../internal/harness.js";
|
|
28
|
+
import { CheckpointError, summarizeCheckpoint, validatePendingSteer, winnerFromOutcome, } from "../core/checkpoint-store.js";
|
|
29
|
+
import { firstSentence, lexicalSearchMatch, } from "../core/memory.js";
|
|
30
|
+
import { cosineDistance, jaccardDistance, termSet } from "../core/memory-vector.js";
|
|
31
|
+
/** Table names used by {@link ensurePgAgentSchema} and the adapters (single source of truth). */
|
|
32
|
+
export const PG_AGENT_TABLES = {
|
|
33
|
+
sessions: "agent_sessions",
|
|
34
|
+
sessionEntries: "agent_session_entries",
|
|
35
|
+
checkpoints: "agent_checkpoints",
|
|
36
|
+
memory: "agent_memory",
|
|
37
|
+
/** design/84 Seam B: per-scope periodic-consolidation cursor (one row per writeScope). */
|
|
38
|
+
memoryCursor: "agent_memory_cursor",
|
|
39
|
+
toolResults: "agent_tool_results",
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Create the three tables (idempotent, `IF NOT EXISTS`). Call once at startup, or run the same DDL
|
|
43
|
+
* through your own migration tool. JSON payloads are `jsonb`; values are always **passed as JSON
|
|
44
|
+
* strings** (every driver can bind a string; Postgres casts it into the column type).
|
|
45
|
+
*/
|
|
46
|
+
export async function ensurePgAgentSchema(query, opts = {}) {
|
|
47
|
+
await query(`CREATE TABLE IF NOT EXISTS ${PG_AGENT_TABLES.sessions} (
|
|
48
|
+
session_id text PRIMARY KEY,
|
|
49
|
+
created_at text NOT NULL,
|
|
50
|
+
forked_from text
|
|
51
|
+
)`);
|
|
52
|
+
// F7 fork-GC seam migration: an EXISTING sessions table (created before forked_from) is untouched by
|
|
53
|
+
// CREATE TABLE IF NOT EXISTS — add the column idempotently (same posture as the checkpoints/memory
|
|
54
|
+
// migrations above: NOT swallowed, a real ALTER failure must surface at startup).
|
|
55
|
+
await query(`ALTER TABLE ${PG_AGENT_TABLES.sessions} ADD COLUMN IF NOT EXISTS forked_from text`);
|
|
56
|
+
await query(`CREATE TABLE IF NOT EXISTS ${PG_AGENT_TABLES.sessionEntries} (
|
|
57
|
+
session_id text NOT NULL,
|
|
58
|
+
seq bigint NOT NULL,
|
|
59
|
+
entry jsonb NOT NULL,
|
|
60
|
+
PRIMARY KEY (session_id, seq)
|
|
61
|
+
)`);
|
|
62
|
+
await query(`CREATE TABLE IF NOT EXISTS ${PG_AGENT_TABLES.checkpoints} (
|
|
63
|
+
token text PRIMARY KEY,
|
|
64
|
+
scope text NOT NULL,
|
|
65
|
+
status text NOT NULL,
|
|
66
|
+
deadline bigint,
|
|
67
|
+
checkpoint jsonb NOT NULL,
|
|
68
|
+
outcome jsonb,
|
|
69
|
+
-- design/80 D-1 (persist-winner + reopen-by-reason): the won binding + the last reopen reason, recorded
|
|
70
|
+
-- atomically with the status CAS so a reopen → re-resume can be validated against the approved decision.
|
|
71
|
+
resolved_outcome jsonb,
|
|
72
|
+
reopen_reason text,
|
|
73
|
+
-- design/80 D-1 (atomicity OCC): a monotonic revision bumped by every resolve/reopen — the once-only CAS's
|
|
74
|
+
-- optimistic-concurrency key (ABA-proof; the resume snapshots it and resolve requires it unchanged).
|
|
75
|
+
rev bigint,
|
|
76
|
+
created_at bigint NOT NULL
|
|
77
|
+
)`);
|
|
78
|
+
// design/80 D-1 migration: an EXISTING checkpoints table (created before these columns) is untouched by
|
|
79
|
+
// CREATE TABLE IF NOT EXISTS, so add the columns idempotently. `ADD COLUMN IF NOT EXISTS` is a clean no-op on
|
|
80
|
+
// a fresh table (all columns already present) and a real add on a legacy one — on both real Postgres and
|
|
81
|
+
// pg-mem. It is deliberately NOT swallowed: these columns are load-bearing (resolve/reopen reference them), so
|
|
82
|
+
// a genuine ALTER failure (insufficient privilege / lock timeout) must surface LOUDLY at startup rather than
|
|
83
|
+
// leave a half-migrated table that silently breaks durable resume at the first approval (round-3 MAJOR).
|
|
84
|
+
for (const col of ["resolved_outcome jsonb", "reopen_reason text", "rev bigint"]) {
|
|
85
|
+
await query(`ALTER TABLE ${PG_AGENT_TABLES.checkpoints} ADD COLUMN IF NOT EXISTS ${col}`);
|
|
86
|
+
}
|
|
87
|
+
const mv = opts.memoryVector;
|
|
88
|
+
if (mv?.pgvector) {
|
|
89
|
+
await query(`CREATE EXTENSION IF NOT EXISTS vector`);
|
|
90
|
+
}
|
|
91
|
+
const embeddingType = mv?.pgvector ? `vector(${Math.floor(mv.dimensions)})` : "jsonb";
|
|
92
|
+
await query(`CREATE TABLE IF NOT EXISTS ${PG_AGENT_TABLES.memory} (
|
|
93
|
+
scope text NOT NULL,
|
|
94
|
+
id text NOT NULL,
|
|
95
|
+
body text NOT NULL,
|
|
96
|
+
mtime_ms bigint NOT NULL,
|
|
97
|
+
name text,
|
|
98
|
+
type text,
|
|
99
|
+
description text,
|
|
100
|
+
links jsonb,
|
|
101
|
+
embedding ${embeddingType},
|
|
102
|
+
consolidation_generated boolean,
|
|
103
|
+
PRIMARY KEY (scope, id)
|
|
104
|
+
)`);
|
|
105
|
+
// design/84 Seam B: idempotent add for an EXISTING memory table (created before the marker column). A
|
|
106
|
+
// clean no-op on a fresh table (column already present), a real add on a legacy one; both real Postgres
|
|
107
|
+
// and pg-mem. Not swallowed: periodic consolidation reads it (excluding self-generated notes).
|
|
108
|
+
await query(`ALTER TABLE ${PG_AGENT_TABLES.memory} ADD COLUMN IF NOT EXISTS consolidation_generated boolean`);
|
|
109
|
+
// design/84 Seam B: per-scope periodic-consolidation cursor (idempotent; small key/value table mirroring
|
|
110
|
+
// the `consolidation_generated` migration pattern — one row per writeScope, last-writer-wins on update).
|
|
111
|
+
await query(`CREATE TABLE IF NOT EXISTS ${PG_AGENT_TABLES.memoryCursor} (
|
|
112
|
+
scope text PRIMARY KEY,
|
|
113
|
+
cursor text NOT NULL
|
|
114
|
+
)`);
|
|
115
|
+
await query(`CREATE TABLE IF NOT EXISTS ${PG_AGENT_TABLES.toolResults} (
|
|
116
|
+
ref text PRIMARY KEY,
|
|
117
|
+
content text NOT NULL
|
|
118
|
+
)`);
|
|
119
|
+
// Serves `reap` (scope + pending + deadline range). Optional but cheap; ignore "exists" races.
|
|
120
|
+
try {
|
|
121
|
+
await query(`CREATE INDEX IF NOT EXISTS ${PG_AGENT_TABLES.checkpoints}_reap_idx
|
|
122
|
+
ON ${PG_AGENT_TABLES.checkpoints} (scope, status, deadline)`);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
// A driver/emulator without `CREATE INDEX IF NOT EXISTS` only loses the index, not correctness.
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** Postgres SQLSTATE 23505; fall back to message sniffing for emulators that don't set `code`.
|
|
129
|
+
* Exported for `MemoryBackend` dialect implementations (the Pg reference implementation moved to
|
|
130
|
+
* @sema-ai/server — see docs/MEMORY-BACKEND-DIALECT-NOTES.md); one sniffing rule, every consumer. */
|
|
131
|
+
export function isUniqueViolation(err) {
|
|
132
|
+
if (typeof err !== "object" || err === null)
|
|
133
|
+
return false;
|
|
134
|
+
if (err.code === "23505")
|
|
135
|
+
return true;
|
|
136
|
+
return /duplicate key|unique constraint|already exists/i.test(String(err.message ?? ""));
|
|
137
|
+
}
|
|
138
|
+
/** jsonb round-trip: drivers return parsed objects for jsonb, emulators/text columns may return strings.
|
|
139
|
+
* UNCHECKED cast (council DESIGN-7): the value is trusted because this module wrote it — these tables
|
|
140
|
+
* are not a hostile input surface. A deployment sharing the tables with other writers owns validation. */
|
|
141
|
+
function fromJsonColumn(v) {
|
|
142
|
+
return (typeof v === "string" ? JSON.parse(v) : v);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Durable session storage over the `agent_session_entries` event log. Write-through: every entry is
|
|
146
|
+
* INSERTed first, then mirrored into the in-memory indexes (`BaseSessionStorage`) the harness reads.
|
|
147
|
+
*
|
|
148
|
+
* The cross-instance optimistic lock is the `(session_id, seq)` primary key: this instance's `seq`
|
|
149
|
+
* counter mirrors exactly the entries it has seen, so a stale replica's next append collides and is
|
|
150
|
+
* rejected as `SessionError("conflict")` — the conditional-write recipe from README §11 (1.3.0).
|
|
151
|
+
* `assertExpectedLeaf` still runs first for the cheap in-process check.
|
|
152
|
+
*/
|
|
153
|
+
class PgSessionStorage extends BaseSessionStorage {
|
|
154
|
+
query;
|
|
155
|
+
nextSeq;
|
|
156
|
+
constructor(query, meta, entries, nextSeq) {
|
|
157
|
+
super(meta, entries);
|
|
158
|
+
this.query = query;
|
|
159
|
+
this.nextSeq = nextSeq;
|
|
160
|
+
}
|
|
161
|
+
async persist(entry) {
|
|
162
|
+
const meta = await this.getMetadata();
|
|
163
|
+
try {
|
|
164
|
+
await this.query(`INSERT INTO ${PG_AGENT_TABLES.sessionEntries} (session_id, seq, entry) VALUES ($1, $2, $3)`, [meta.id, this.nextSeq, JSON.stringify(entry)]);
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
if (isUniqueViolation(err)) {
|
|
168
|
+
// Another instance appended this seq first — surface the standard optimistic-lock error so
|
|
169
|
+
// the Runner's conflict handling (re-acquire + retry) applies unchanged.
|
|
170
|
+
throw new SessionError("conflict", `Stale write: seq ${this.nextSeq} of session ${meta.id} was appended by another instance`);
|
|
171
|
+
}
|
|
172
|
+
throw err;
|
|
173
|
+
}
|
|
174
|
+
this.nextSeq++;
|
|
175
|
+
}
|
|
176
|
+
async appendEntry(entry, opts) {
|
|
177
|
+
this.assertExpectedLeaf(opts);
|
|
178
|
+
await this.persist(entry);
|
|
179
|
+
this.recordEntry(entry);
|
|
180
|
+
}
|
|
181
|
+
async setLeafId(leafId, opts) {
|
|
182
|
+
this.assertExpectedLeaf(opts);
|
|
183
|
+
const entry = this.createLeafEntry(leafId);
|
|
184
|
+
await this.persist(entry);
|
|
185
|
+
this.recordEntry(entry);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Durable `SessionRepo` on Postgres. Plug into the built-in cache:
|
|
190
|
+
* ```ts
|
|
191
|
+
* const repo = new PgSessionRepo((t, p) => pool.query(t, p));
|
|
192
|
+
* const runner = new Runner({ brain, sessionStore: new TtlSessionStore({ repo }) });
|
|
193
|
+
* ```
|
|
194
|
+
* `TtlSessionStore` defaults to `evict: "forget"` for a custom repo, so idle eviction never deletes
|
|
195
|
+
* durable history; `open` of an unknown id throws `not_found` and the store falls back to `create`.
|
|
196
|
+
*/
|
|
197
|
+
export class PgSessionRepo {
|
|
198
|
+
query;
|
|
199
|
+
constructor(query) {
|
|
200
|
+
this.query = query;
|
|
201
|
+
}
|
|
202
|
+
async load(id, createdAt, forkedFrom) {
|
|
203
|
+
// Full-tree wake (reference-grade trade-off, see the module header): no F3 bounded-tail query.
|
|
204
|
+
// A deployment with multi-day sessions should load only `[last compaction's firstKeptEntryId ..
|
|
205
|
+
// leaf]` and pass `floorEntryId` (see `boundedTail` / design F3) — left out here to keep the
|
|
206
|
+
// reference adapter auditable.
|
|
207
|
+
const res = await this.query(`SELECT seq, entry FROM ${PG_AGENT_TABLES.sessionEntries} WHERE session_id = $1 ORDER BY seq`, [id]);
|
|
208
|
+
const entries = res.rows.map((r) => fromJsonColumn(r.entry));
|
|
209
|
+
// seq is dense (each append takes current count), but derive from the last row to be safe.
|
|
210
|
+
const last = res.rows.at(-1);
|
|
211
|
+
const nextSeq = last ? Number(last.seq) + 1 : 0;
|
|
212
|
+
// bigint guard (council BUG-3): past Number.MAX_SAFE_INTEGER the (session_id, seq) lock would
|
|
213
|
+
// silently corrupt (precision-folded seq → spurious conflicts or gaps). Unreachable in practice;
|
|
214
|
+
// fail loud instead of corrupting if it ever isn't.
|
|
215
|
+
if (!Number.isSafeInteger(nextSeq)) {
|
|
216
|
+
throw new SessionError("storage", `session ${id} seq ${String(last?.seq)} exceeds safe integer range`);
|
|
217
|
+
}
|
|
218
|
+
return new PgSessionStorage(this.query, { id, createdAt, ...(forkedFrom !== undefined ? { forkedFrom } : {}) }, entries, nextSeq);
|
|
219
|
+
}
|
|
220
|
+
async create(options = {}) {
|
|
221
|
+
const id = options.id ?? uuidv7();
|
|
222
|
+
const createdAt = new Date().toISOString();
|
|
223
|
+
// A FRESH create purges any leftover orphan entries first (a `fork` that failed before its
|
|
224
|
+
// session-row commit point — council BUG-1's failure residue must not be silently adopted as
|
|
225
|
+
// history by an unrelated create with the same explicit id). No session row ⇒ entries under this
|
|
226
|
+
// id are orphans by definition. Then race-safe with a concurrent creator: first INSERT wins, the
|
|
227
|
+
// loser opens the same session. (Existence-check + purge rather than `RETURNING`-based detection:
|
|
228
|
+
// identical on real PG, and robust to emulators that return rows from a conflicted DO NOTHING.)
|
|
229
|
+
const existing = await this.query(`SELECT 1 FROM ${PG_AGENT_TABLES.sessions} WHERE session_id = $1`, [id]);
|
|
230
|
+
if (existing.rows.length === 0) {
|
|
231
|
+
await this.query(`DELETE FROM ${PG_AGENT_TABLES.sessionEntries} WHERE session_id = $1`, [id]);
|
|
232
|
+
}
|
|
233
|
+
await this.query(`INSERT INTO ${PG_AGENT_TABLES.sessions} (session_id, created_at) VALUES ($1, $2)
|
|
234
|
+
ON CONFLICT (session_id) DO NOTHING`, [id, createdAt]);
|
|
235
|
+
return new Session(await this.load(id, createdAt));
|
|
236
|
+
}
|
|
237
|
+
async open(metadata) {
|
|
238
|
+
const res = await this.query(`SELECT created_at, forked_from FROM ${PG_AGENT_TABLES.sessions} WHERE session_id = $1`, [metadata.id]);
|
|
239
|
+
const row = res.rows[0];
|
|
240
|
+
if (!row) {
|
|
241
|
+
throw new SessionError("not_found", `Session not found: ${metadata.id}`);
|
|
242
|
+
}
|
|
243
|
+
return new Session(await this.load(metadata.id, String(row.created_at), row.forked_from != null ? String(row.forked_from) : undefined));
|
|
244
|
+
}
|
|
245
|
+
async list() {
|
|
246
|
+
const res = await this.query(`SELECT session_id, created_at, forked_from FROM ${PG_AGENT_TABLES.sessions} ORDER BY created_at`);
|
|
247
|
+
return res.rows.map((r) => ({
|
|
248
|
+
id: String(r.session_id),
|
|
249
|
+
createdAt: String(r.created_at),
|
|
250
|
+
...(r.forked_from != null ? { forkedFrom: String(r.forked_from) } : {}),
|
|
251
|
+
}));
|
|
252
|
+
}
|
|
253
|
+
async delete(metadata) {
|
|
254
|
+
// Session row FIRST (council BUG-2): the row is the liveness marker — once it's gone, `open` is
|
|
255
|
+
// `not_found` regardless of leftover entries. The reverse order could fail half-way into a session
|
|
256
|
+
// row with NO entries, which `open` would happily serve as silently-emptied history.
|
|
257
|
+
await this.query(`DELETE FROM ${PG_AGENT_TABLES.sessions} WHERE session_id = $1`, [metadata.id]);
|
|
258
|
+
await this.query(`DELETE FROM ${PG_AGENT_TABLES.sessionEntries} WHERE session_id = $1`, [metadata.id]);
|
|
259
|
+
}
|
|
260
|
+
/** Fork caveats (1.94.0 review obs#1/#2): an EXPLICIT `options.id` must not be shared with a
|
|
261
|
+
* concurrent `create` of the same id (create's orphan purge can race the in-flight entry batches —
|
|
262
|
+
* unreachable under default uuidv7 ids; explicit-id reuse is a caller contract); and forking onto an
|
|
263
|
+
* id holding orphan residue from a previously failed fork fails LOUD with a unique violation
|
|
264
|
+
* (`create` purges such residue, `fork` deliberately does not — loud beats silently adopting). */
|
|
265
|
+
async fork(sourceMetadata, options = {}) {
|
|
266
|
+
const source = await this.open(sourceMetadata);
|
|
267
|
+
const forked = await getEntriesToFork(source.getStorage(), options);
|
|
268
|
+
const id = options.id ?? uuidv7();
|
|
269
|
+
const createdAt = new Date().toISOString();
|
|
270
|
+
// Entries land BEFORE the session row (council BUG-1): the row is the commit point. Each batch is
|
|
271
|
+
// one multi-row INSERT, so a mid-fork failure leaves either nothing visible or orphan entries with
|
|
272
|
+
// NO session row — invisible to `open` (not_found) and purged by a later `create` with the same id;
|
|
273
|
+
// it can never surface as a partially-populated session. Re-seq from 0 in the new session; entry
|
|
274
|
+
// ids/parent links are per-session and copy verbatim.
|
|
275
|
+
const BATCH = 200;
|
|
276
|
+
for (let start = 0; start < forked.length; start += BATCH) {
|
|
277
|
+
const batch = forked.slice(start, start + BATCH);
|
|
278
|
+
const values = batch.map((_, i) => `($1, ${start + i}, $${i + 2})`).join(", ");
|
|
279
|
+
await this.query(`INSERT INTO ${PG_AGENT_TABLES.sessionEntries} (session_id, seq, entry) VALUES ${values}`, [id, ...batch.map((e) => JSON.stringify(e))]);
|
|
280
|
+
}
|
|
281
|
+
await this.query(`INSERT INTO ${PG_AGENT_TABLES.sessions} (session_id, created_at, forked_from) VALUES ($1, $2, $3)`, [id, createdAt, sourceMetadata.id]);
|
|
282
|
+
return new Session(new PgSessionStorage(this.query, { id, createdAt, forkedFrom: sourceMetadata.id }, [...forked], forked.length));
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Durable `CheckpointStore` on Postgres (design/45 §2.1). The `status` **column** is authoritative
|
|
287
|
+
* (the CAS target); the `checkpoint` jsonb is the full payload, whose embedded `status` is overwritten
|
|
288
|
+
* from the column on `get`. `resolve` persists the outcome atomically with the status flip (the v2
|
|
289
|
+
* resumable-resume hook the interface reserves).
|
|
290
|
+
*/
|
|
291
|
+
export class PgCheckpointStore {
|
|
292
|
+
query;
|
|
293
|
+
constructor(query) {
|
|
294
|
+
this.query = query;
|
|
295
|
+
}
|
|
296
|
+
async put(token, cp) {
|
|
297
|
+
try {
|
|
298
|
+
await this.query(`INSERT INTO ${PG_AGENT_TABLES.checkpoints} (token, scope, status, deadline, checkpoint, created_at)
|
|
299
|
+
VALUES ($1, $2, $3, $4, $5, $6)`, [token, cp.scope, cp.status, cp.deadline ?? null, JSON.stringify(cp), cp.createdAt]);
|
|
300
|
+
}
|
|
301
|
+
catch (err) {
|
|
302
|
+
if (isUniqueViolation(err)) {
|
|
303
|
+
// Create-once: a reused token must never clobber a live suspension (design/45 §2.1).
|
|
304
|
+
throw new CheckpointError("checkpoint.already_exists", "checkpoint token already exists");
|
|
305
|
+
}
|
|
306
|
+
throw err;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
async get(token) {
|
|
310
|
+
const res = await this.query(`SELECT status, checkpoint, resolved_outcome, reopen_reason, rev FROM ${PG_AGENT_TABLES.checkpoints} WHERE token = $1`, [token]);
|
|
311
|
+
const row = res.rows[0];
|
|
312
|
+
if (!row)
|
|
313
|
+
return null;
|
|
314
|
+
const cp = fromJsonColumn(row.checkpoint);
|
|
315
|
+
// design/80 D-1: surface the persisted winner + last reopen reason + monotonic rev from their dedicated
|
|
316
|
+
// columns (written atomically with the status CAS by `resolve`/`reopen`) so a reopen → re-resume can
|
|
317
|
+
// validate per reason and the OCC `rev` is authoritative (the `checkpoint` jsonb copy is stale after a CAS).
|
|
318
|
+
const resolvedOutcome = row.resolved_outcome != null ? fromJsonColumn(row.resolved_outcome) : undefined;
|
|
319
|
+
return {
|
|
320
|
+
...cp,
|
|
321
|
+
status: row.status,
|
|
322
|
+
...(row.rev != null ? { rev: Number(row.rev) } : {}),
|
|
323
|
+
...(resolvedOutcome !== undefined ? { resolvedOutcome } : {}),
|
|
324
|
+
...(row.reopen_reason != null ? { reopenReason: row.reopen_reason } : {}),
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
async resolve(token, scope, outcome, expect) {
|
|
328
|
+
// The once-only CAS: exactly one caller flips pending → resolved; everyone else sees 0 rows.
|
|
329
|
+
// design/80 D-1 (persist-winner): when the won outcome binds to an action (`policy_ask`), also record
|
|
330
|
+
// the winner in the dedicated `resolved_outcome` column — ONE atomic CAS (status flip + winner together)
|
|
331
|
+
// so a later reopen → re-resume can validate against the approved decision (`get` reads it back). A
|
|
332
|
+
// non-`policy_ask` outcome binds to no action → winnerFromOutcome is undefined → the column is left null.
|
|
333
|
+
const winner = winnerFromOutcome(outcome);
|
|
334
|
+
const params = [token, scope, JSON.stringify(outcome), winner ? JSON.stringify(winner) : null];
|
|
335
|
+
// design/80 D-1 (atomicity fix): fold the caller's optimistic-concurrency precondition INTO the CAS — when
|
|
336
|
+
// `expect` is supplied ($5), additionally require the live monotonic `rev` to still equal what the resume
|
|
337
|
+
// validated against (`COALESCE(rev,0) = $5`, legacy NULL = 0). A resolve/reopen cycle that landed in the
|
|
338
|
+
// get→resolve window bumped `rev` → 0 rows → the stale-snapshot resume loses (fail-closed). The won CAS
|
|
339
|
+
// bumps `rev` and clears `reopen_reason` (MINOR-12), atomic with the status flip.
|
|
340
|
+
let occ = "";
|
|
341
|
+
if (expect !== undefined) {
|
|
342
|
+
params.push(expect.rev);
|
|
343
|
+
occ = " AND COALESCE(rev, 0) = $5";
|
|
344
|
+
}
|
|
345
|
+
const res = await this.query(`UPDATE ${PG_AGENT_TABLES.checkpoints}
|
|
346
|
+
SET status = 'resolved', outcome = $3, resolved_outcome = $4, reopen_reason = NULL, rev = COALESCE(rev, 0) + 1
|
|
347
|
+
WHERE token = $1 AND scope = $2 AND status = 'pending'${occ} RETURNING token`, params);
|
|
348
|
+
return res.rows.length === 1;
|
|
349
|
+
}
|
|
350
|
+
async reopen(token, scope, reason) {
|
|
351
|
+
// Inverse of `resolve`: CAS resolved → pending. Compensation for a post-CAS env-restore failure
|
|
352
|
+
// (design/45/49) — only the run that consumed the checkpoint (and then failed to restore) can
|
|
353
|
+
// reopen it, and only while it is still `resolved` (the `status='resolved'` guard). Returns the CAS
|
|
354
|
+
// winner so a durable resume can re-resume the SAME suspended work instead of losing it.
|
|
355
|
+
// design/80 D-1 (reopen-by-reason): record WHY into the dedicated `reopen_reason` column (so `get`
|
|
356
|
+
// surfaces `cp.reopenReason` → re-resume validates per reason); the `resolved_outcome` winner column is
|
|
357
|
+
// left UNTOUCHED (PRESERVED — an env_failed re-resume must replay it). One atomic CAS, status + reason.
|
|
358
|
+
// Bump the monotonic `rev` (atomicity OCC key) so any resume that snapshotted the pre-reopen row loses its
|
|
359
|
+
// resolve CAS (ABA-proof — round-2 BLOCKER fix).
|
|
360
|
+
const res = await this.query(`UPDATE ${PG_AGENT_TABLES.checkpoints} SET status = 'pending', reopen_reason = $3, rev = COALESCE(rev, 0) + 1
|
|
361
|
+
WHERE token = $1 AND scope = $2 AND status = 'resolved' RETURNING token`, [token, scope, reason]);
|
|
362
|
+
return res.rows.length === 1;
|
|
363
|
+
}
|
|
364
|
+
async setPendingSteer(token, scope, steer) {
|
|
365
|
+
// design/80 D-A: validate FIRST (typed `steering.invalid_content` on a `</system-reminder>`-bearing text)
|
|
366
|
+
// so a dirty steer never touches the row, even on a missing/resolved checkpoint (§3 inv #2). Trust is frozen
|
|
367
|
+
// verbatim (§3 inv #1).
|
|
368
|
+
const clean = validatePendingSteer(steer);
|
|
369
|
+
// Park the steer INSIDE the `checkpoint` jsonb at `state.pendingSteer` (where `get` reads it back), guarded
|
|
370
|
+
// by `status='pending'` (scope in the WHERE for isolation, like `resolve`/`expire`). Only a still-pending
|
|
371
|
+
// checkpoint can be steered (§3 inv #6); a resolved/expired one matches 0 rows → `false`, a no-op. This is
|
|
372
|
+
// GUIDANCE ONLY — it never flips `status` or touches the resolve/outcome columns (§3 inv #4). The 3-arg
|
|
373
|
+
// `jsonb_set` defaults `create_missing=true` (standard Postgres), so it CREATES the `pendingSteer` key (and
|
|
374
|
+
// overwrites a prior one — last-writer-wins, idempotent-safe). One atomic UPDATE, no read-modify-write race.
|
|
375
|
+
const res = await this.query(`UPDATE ${PG_AGENT_TABLES.checkpoints}
|
|
376
|
+
SET checkpoint = jsonb_set(checkpoint, '{state,pendingSteer}', $3::jsonb)
|
|
377
|
+
WHERE token = $1 AND scope = $2 AND status = 'pending' RETURNING token`, [token, scope, JSON.stringify(clean)]);
|
|
378
|
+
return res.rows.length === 1;
|
|
379
|
+
}
|
|
380
|
+
async expire(token, scope) {
|
|
381
|
+
// Races `resolve` over the same pending row; the DB serializes — a checkpoint is never both
|
|
382
|
+
// resumed and reaped (the fence-then-reap contract, design/51 §2/§4).
|
|
383
|
+
const res = await this.query(`UPDATE ${PG_AGENT_TABLES.checkpoints} SET status = 'expired'
|
|
384
|
+
WHERE token = $1 AND scope = $2 AND status = 'pending' RETURNING token`, [token, scope]);
|
|
385
|
+
return res.rows.length === 1;
|
|
386
|
+
}
|
|
387
|
+
async reap(scope, cutoff) {
|
|
388
|
+
const res = await this.query(`UPDATE ${PG_AGENT_TABLES.checkpoints} SET status = 'expired'
|
|
389
|
+
WHERE scope = $1 AND status = 'pending' AND deadline IS NOT NULL AND deadline <= $2
|
|
390
|
+
RETURNING token`, [scope, cutoff]);
|
|
391
|
+
return res.rows.length;
|
|
392
|
+
}
|
|
393
|
+
async listByScope(scope) {
|
|
394
|
+
// design/80 assistant-scheduler seam #1: a single READ-ONLY query for every PENDING checkpoint in the scope
|
|
395
|
+
// (no N+1 `get`s). The WHERE predicate mirrors the resolve CAS's (`scope = $1 AND status = 'pending'`), so
|
|
396
|
+
// the result is exactly the still-resumable rows. The `status` COLUMN is authoritative (as in `get`); the
|
|
397
|
+
// `checkpoint` jsonb carries scope/sessionId/gate/resourceLedger/deadline + the design S1d source-tag fields
|
|
398
|
+
// (sourceTaskId/principal/pendingAction) — all of which `summarizeCheckpoint` reads (no new column needed: the
|
|
399
|
+
// optional fields ride the full-cp jsonb that `put` already stringifies) — so hydrate row→Checkpoint with the
|
|
400
|
+
// authoritative status, then project via the shared helper
|
|
401
|
+
// (anti-drift with the in-memory/file backends). resolved_outcome/reopen_reason/rev are irrelevant to the
|
|
402
|
+
// summary, so they are not selected here.
|
|
403
|
+
const res = await this.query(`SELECT status, checkpoint FROM ${PG_AGENT_TABLES.checkpoints} WHERE scope = $1 AND status = 'pending'`, [scope]);
|
|
404
|
+
return res.rows.map((row) => {
|
|
405
|
+
const cp = fromJsonColumn(row.checkpoint);
|
|
406
|
+
return summarizeCheckpoint({ ...cp, status: row.status });
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Durable `ToolResultStore` on Postgres. Required for durable suspend (design/45): the runner refuses
|
|
412
|
+
* to suspend over the default `InMemoryToolResultStore` (its offload refs die with the process and a
|
|
413
|
+
* cross-replica resume could never read them back). Write-once per ref (`ON CONFLICT DO NOTHING`, the
|
|
414
|
+
* interface contract); slicing matches the in-memory store exactly (JS `slice` semantics).
|
|
415
|
+
*/
|
|
416
|
+
export class PgToolResultStore {
|
|
417
|
+
query;
|
|
418
|
+
constructor(query) {
|
|
419
|
+
this.query = query;
|
|
420
|
+
}
|
|
421
|
+
async put(ref, content) {
|
|
422
|
+
await this.query(`INSERT INTO ${PG_AGENT_TABLES.toolResults} (ref, content) VALUES ($1, $2)
|
|
423
|
+
ON CONFLICT (ref) DO NOTHING`, [ref, content]);
|
|
424
|
+
}
|
|
425
|
+
async get(ref, opts) {
|
|
426
|
+
const res = await this.query(`SELECT content FROM ${PG_AGENT_TABLES.toolResults} WHERE ref = $1`, [ref]);
|
|
427
|
+
const row = res.rows[0];
|
|
428
|
+
if (!row)
|
|
429
|
+
return undefined;
|
|
430
|
+
const full = String(row.content);
|
|
431
|
+
const offset = Math.min(full.length, Math.max(0, Math.floor(Number(opts?.offset ?? 0)) || 0));
|
|
432
|
+
const limit = opts?.limit != null ? Math.max(0, Math.floor(Number(opts.limit)) || 0) : undefined;
|
|
433
|
+
const content = limit != null ? full.slice(offset, offset + limit) : full.slice(offset);
|
|
434
|
+
return { content, offset, totalChars: full.length };
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
/** "YYYY-MM-DD HH:MM" (UTC) — the bullet-timestamp format shared with the in-memory store. */
|
|
438
|
+
function tsOf(mtimeMs) {
|
|
439
|
+
return new Date(mtimeMs).toISOString().replace("T", " ").slice(0, 16);
|
|
440
|
+
}
|
|
441
|
+
// termSet / jaccardDistance / cosineDistance moved to core/memory-vector.ts (single source, File + Pg share them).
|
|
442
|
+
/** pgvector input literal: `[0.1,0.2,…]`. */
|
|
443
|
+
function vectorLiteral(v) {
|
|
444
|
+
return `[${v.join(",")}]`;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Durable `MemoryStore` on Postgres — the full surface (L2 read/append, L3 `search`, consolidation
|
|
448
|
+
* trio `searchScored`/`update`/`delete`, design/65 structured notes + manifest), with **switchable
|
|
449
|
+
* recall** (see {@link PgMemoryStoreOptions}): lexical → in-process cosine over `jsonb` embeddings →
|
|
450
|
+
* native pgvector `<=>`. All three return the same cosine-distance scale, so upgrading recall is a
|
|
451
|
+
* config change, not a recalibration.
|
|
452
|
+
*
|
|
453
|
+
* Insertion order is the uuidv7 id order (time-sortable), matching the in-memory store's append order
|
|
454
|
+
* for `read`/`search` output. Concurrency: same-scope writes from different sessions follow the
|
|
455
|
+
* MemoryStore contract's eventual-consistency allowance (at worst a near-duplicate survives one extra
|
|
456
|
+
* consolidation pass); `update` is a single-row UPDATE, never a read-modify-write of the whole scope.
|
|
457
|
+
*/
|
|
458
|
+
export class PgMemoryStore {
|
|
459
|
+
query;
|
|
460
|
+
embedder;
|
|
461
|
+
pgvectorSql;
|
|
462
|
+
/** design/81 Slice 5 rung: native when the pgvector `<=>` SQL path is on, portable when an embedder ranks
|
|
463
|
+
* in-process over the jsonb column, lexical when no embedder. */
|
|
464
|
+
get vectorMode() {
|
|
465
|
+
return this.pgvectorSql ? "native" : this.embedder ? "portable" : "lexical";
|
|
466
|
+
}
|
|
467
|
+
constructor(query, opts = {}) {
|
|
468
|
+
this.query = query;
|
|
469
|
+
this.embedder = opts.embedder;
|
|
470
|
+
this.pgvectorSql = opts.pgvectorSql === true;
|
|
471
|
+
if (this.pgvectorSql && !this.embedder) {
|
|
472
|
+
throw new Error("PgMemoryStore: pgvectorSql requires an embedder");
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
async embeddingParam(text) {
|
|
476
|
+
if (!this.embedder)
|
|
477
|
+
return null;
|
|
478
|
+
const v = await this.embedder.embed(text);
|
|
479
|
+
// Dimension guard (mirrors the File backend's write path, memory-store.ts): store ONLY a vector of the
|
|
480
|
+
// embedder's declared dimension. A wrong-length vector (a buggy/transient embedder) would otherwise poison
|
|
481
|
+
// the row — silently truncating cosineDistance on read (jsonb), or erroring the insert (pgvector's fixed-dim
|
|
482
|
+
// column). Storing no vector instead lets that row fall open to the lexical stand-in.
|
|
483
|
+
if (!Array.isArray(v) || v.length !== this.embedder.dimensions)
|
|
484
|
+
return null;
|
|
485
|
+
// pgvector parses the same `[…]` literal that JSON.parse reads back from jsonb — one format serves
|
|
486
|
+
// both column types, which is what makes the mode a schema choice instead of a data migration.
|
|
487
|
+
return this.pgvectorSql ? vectorLiteral(v) : JSON.stringify(v);
|
|
488
|
+
}
|
|
489
|
+
async read(scope) {
|
|
490
|
+
const res = await this.query(`SELECT body, mtime_ms FROM ${PG_AGENT_TABLES.memory} WHERE scope = $1 ORDER BY id`, [scope]);
|
|
491
|
+
if (res.rows.length === 0)
|
|
492
|
+
return null;
|
|
493
|
+
return res.rows.map((r) => `- (${tsOf(Number(r.mtime_ms))} UTC) ${String(r.body)}`).join("\n");
|
|
494
|
+
}
|
|
495
|
+
async append(scope, note) {
|
|
496
|
+
const text = note.trim().replace(/^#+\s*/, "");
|
|
497
|
+
if (!text)
|
|
498
|
+
return;
|
|
499
|
+
return this.insert(scope, { body: text });
|
|
500
|
+
}
|
|
501
|
+
async appendStructured(scope, note) {
|
|
502
|
+
const body = note.body.trim().replace(/^#+\s*/, "");
|
|
503
|
+
if (!body)
|
|
504
|
+
return "";
|
|
505
|
+
return this.insert(scope, {
|
|
506
|
+
body,
|
|
507
|
+
name: note.name,
|
|
508
|
+
type: note.type ?? "project",
|
|
509
|
+
description: note.description?.trim() || firstSentence(body),
|
|
510
|
+
links: note.links,
|
|
511
|
+
consolidationGenerated: note.consolidationGenerated, // design/84 Seam B marker
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
async insert(scope, note) {
|
|
515
|
+
const id = uuidv7();
|
|
516
|
+
await this.query(`INSERT INTO ${PG_AGENT_TABLES.memory} (scope, id, body, mtime_ms, name, type, description, links, embedding, consolidation_generated)
|
|
517
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`, [
|
|
518
|
+
scope,
|
|
519
|
+
id,
|
|
520
|
+
note.body,
|
|
521
|
+
Date.now(),
|
|
522
|
+
note.name ?? null,
|
|
523
|
+
note.type ?? null,
|
|
524
|
+
note.description ?? null,
|
|
525
|
+
note.links ? JSON.stringify(note.links) : null,
|
|
526
|
+
await this.embeddingParam(note.body),
|
|
527
|
+
note.consolidationGenerated ? true : null,
|
|
528
|
+
]);
|
|
529
|
+
return id;
|
|
530
|
+
}
|
|
531
|
+
async clear(scope) {
|
|
532
|
+
await this.query(`DELETE FROM ${PG_AGENT_TABLES.memory} WHERE scope = $1`, [scope]);
|
|
533
|
+
// design/84 Seam B: a cleared scope is logically fresh — drop its consolidation cursor too.
|
|
534
|
+
await this.query(`DELETE FROM ${PG_AGENT_TABLES.memoryCursor} WHERE scope = $1`, [scope]);
|
|
535
|
+
}
|
|
536
|
+
/** design/84 Seam B: read the per-scope periodic-consolidation cursor (the opaque note-id high-water mark). */
|
|
537
|
+
async getConsolidationCursor(scope) {
|
|
538
|
+
const res = await this.query(`SELECT cursor FROM ${PG_AGENT_TABLES.memoryCursor} WHERE scope = $1`, [scope]);
|
|
539
|
+
const row = res.rows[0];
|
|
540
|
+
return row && row.cursor != null ? String(row.cursor) : undefined;
|
|
541
|
+
}
|
|
542
|
+
/** design/84 Seam B: upsert the per-scope periodic-consolidation cursor (last-writer-wins). */
|
|
543
|
+
async setConsolidationCursor(scope, cursor) {
|
|
544
|
+
await this.query(`INSERT INTO ${PG_AGENT_TABLES.memoryCursor} (scope, cursor) VALUES ($1, $2)
|
|
545
|
+
ON CONFLICT (scope) DO UPDATE SET cursor = EXCLUDED.cursor`, [scope, cursor]);
|
|
546
|
+
}
|
|
547
|
+
async search(scope, query, limit = 10) {
|
|
548
|
+
if (query.trim().length === 0)
|
|
549
|
+
return [];
|
|
550
|
+
const res = await this.query(`SELECT body, mtime_ms FROM ${PG_AGENT_TABLES.memory} WHERE scope = $1 ORDER BY id`, [scope]);
|
|
551
|
+
// Whole-scope fetch + bullet-format BEFORE filtering (terms match the timestamp too) is exact
|
|
552
|
+
// behavioral parity with `InMemoryMemoryStore.search` — the reference semantics, not an accident
|
|
553
|
+
// (council DESIGN-2/-6). Memory scopes are note-sized and consolidation-bounded; a deployment with
|
|
554
|
+
// huge scopes should push matching into SQL at the cost of diverging from the in-memory reference.
|
|
555
|
+
//
|
|
556
|
+
// design/81 Slice 2b — the matcher MUST be the SHARED synonym/stem-aware `lexicalSearchMatch` (the
|
|
557
|
+
// SAME one InMemory/File use), or the `recall` tool returns DIFFERENT hits on Postgres (a synonym
|
|
558
|
+
// query like "auth token" would miss a "bearer credentials" note). This is the cross-backend
|
|
559
|
+
// equivalence invariant `test/cross-backend-shared.ts` enforces.
|
|
560
|
+
return res.rows
|
|
561
|
+
.map((r) => `- (${tsOf(Number(r.mtime_ms))} UTC) ${String(r.body)}`)
|
|
562
|
+
.filter((b) => lexicalSearchMatch(query, b))
|
|
563
|
+
.slice(-limit);
|
|
564
|
+
}
|
|
565
|
+
async searchScored(scope, query, limit = 20) {
|
|
566
|
+
if (this.embedder && this.pgvectorSql) {
|
|
567
|
+
const qv = vectorLiteral(await this.embedder.embed(query));
|
|
568
|
+
// Explicit `::vector` casts (council QUESTION-1): don't rely on an implicit text→vector cast
|
|
569
|
+
// existing on every pgvector build. Cosine-distance operator `<=>` returns exactly the [0,2]
|
|
570
|
+
// ScoredMemory contract.
|
|
571
|
+
const res = await this.query(`SELECT id, body, consolidation_generated, embedding <=> $2::vector AS score FROM ${PG_AGENT_TABLES.memory}
|
|
572
|
+
WHERE scope = $1 AND embedding IS NOT NULL
|
|
573
|
+
ORDER BY embedding <=> $2::vector LIMIT $3`, [scope, qv, limit]);
|
|
574
|
+
return res.rows.map((r) => ({ id: String(r.id), text: String(r.body), score: Number(r.score), ...(r.consolidation_generated ? { consolidationGenerated: true } : {}) }));
|
|
575
|
+
}
|
|
576
|
+
const res = await this.query(`SELECT id, body, embedding, consolidation_generated FROM ${PG_AGENT_TABLES.memory} WHERE scope = $1`, [scope]);
|
|
577
|
+
if (res.rows.length === 0)
|
|
578
|
+
return [];
|
|
579
|
+
const qv = this.embedder ? await this.embedder.embed(query) : null;
|
|
580
|
+
const qTerms = termSet(query); // always available for the per-row lexical fallback (+ the no-embedder path)
|
|
581
|
+
if (!qv && qTerms.size === 0)
|
|
582
|
+
return []; // no-embedder lexical path with no terms → no candidates (File parity)
|
|
583
|
+
const scored = [];
|
|
584
|
+
for (const r of res.rows) {
|
|
585
|
+
const text = String(r.body);
|
|
586
|
+
let score;
|
|
587
|
+
if (qv) {
|
|
588
|
+
const ev = r.embedding == null ? null : fromJsonColumn(r.embedding);
|
|
589
|
+
// Use the stored vector ONLY when it is dim-matched to the query vector. A pre-embedder legacy row (no
|
|
590
|
+
// vector) OR a mismatched-dim row (embedder model swapped without a re-embed) falls open to the lexical
|
|
591
|
+
// stand-in for that row — else cosineDistance's Math.min would silently TRUNCATE the longer vector and
|
|
592
|
+
// return a wrong distance. Mirrors the File backend's vectorScored guard (memory-store.ts) + the
|
|
593
|
+
// cosineDistance contract (memory-vector.ts): callers must only score dimension-matched vectors.
|
|
594
|
+
score = ev && ev.length === qv.length ? cosineDistance(qv, ev) : jaccardDistance(qTerms, text);
|
|
595
|
+
}
|
|
596
|
+
else {
|
|
597
|
+
score = jaccardDistance(qTerms, text);
|
|
598
|
+
}
|
|
599
|
+
if (score === null)
|
|
600
|
+
continue;
|
|
601
|
+
scored.push({ id: String(r.id), text, score, ...(r.consolidation_generated ? { consolidationGenerated: true } : {}) });
|
|
602
|
+
}
|
|
603
|
+
scored.sort((a, b) => a.score - b.score);
|
|
604
|
+
return scored.slice(0, limit);
|
|
605
|
+
}
|
|
606
|
+
async update(scope, id, text) {
|
|
607
|
+
const clean = text.trim();
|
|
608
|
+
if (!clean)
|
|
609
|
+
return;
|
|
610
|
+
const res = await this.query(`SELECT body, description FROM ${PG_AGENT_TABLES.memory} WHERE scope = $1 AND id = $2`, [scope, id]);
|
|
611
|
+
const row = res.rows[0];
|
|
612
|
+
if (!row)
|
|
613
|
+
return; // unknown id → no-op (defensive, mirrors the in-memory store)
|
|
614
|
+
const newBody = clean.replace(/^#+\s*/, "");
|
|
615
|
+
const oldBody = String(row.body);
|
|
616
|
+
const oldDesc = row.description == null ? undefined : String(row.description);
|
|
617
|
+
// design/65 [79]: re-derive an AUTO-DERIVED description; preserve an explicit one.
|
|
618
|
+
const newDesc = oldDesc !== undefined && oldDesc === firstSentence(oldBody) ? firstSentence(newBody) : oldDesc;
|
|
619
|
+
await this.query(`UPDATE ${PG_AGENT_TABLES.memory}
|
|
620
|
+
SET body = $3, description = $4, mtime_ms = $5, embedding = $6
|
|
621
|
+
WHERE scope = $1 AND id = $2`, [scope, id, newBody, newDesc ?? null, Date.now(), await this.embeddingParam(newBody)]);
|
|
622
|
+
}
|
|
623
|
+
async delete(scope, id) {
|
|
624
|
+
await this.query(`DELETE FROM ${PG_AGENT_TABLES.memory} WHERE scope = $1 AND id = $2`, [scope, id]);
|
|
625
|
+
}
|
|
626
|
+
async listStructuredNotes(scope) {
|
|
627
|
+
const res = await this.query(`SELECT id, body, mtime_ms, name, type, description, consolidation_generated FROM ${PG_AGENT_TABLES.memory}
|
|
628
|
+
WHERE scope = $1 ORDER BY id`, [scope]);
|
|
629
|
+
return res.rows.map((r) => this.toHeader(r));
|
|
630
|
+
}
|
|
631
|
+
async getByIds(scope, ids) {
|
|
632
|
+
if (ids.length === 0)
|
|
633
|
+
return [];
|
|
634
|
+
const res = await this.query(`SELECT id, body, mtime_ms, name, type, description, consolidation_generated FROM ${PG_AGENT_TABLES.memory}
|
|
635
|
+
WHERE scope = $1 AND id = ANY($2) ORDER BY id`, [scope, ids]);
|
|
636
|
+
return res.rows.map((r) => {
|
|
637
|
+
const row = r;
|
|
638
|
+
return { ...this.toHeader(row), text: row.body };
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
toHeader(row) {
|
|
642
|
+
return {
|
|
643
|
+
id: row.id,
|
|
644
|
+
description: row.description ?? firstSentence(row.body),
|
|
645
|
+
mtimeMs: Number(row.mtime_ms),
|
|
646
|
+
...(row.name ? { name: row.name } : {}),
|
|
647
|
+
...(row.type ? { type: row.type } : {}),
|
|
648
|
+
...(row.consolidation_generated ? { consolidationGenerated: true } : {}),
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
//# sourceMappingURL=pg.js.map
|