@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,643 @@
|
|
|
1
|
+
// design/138 §2.7 (r2.1) — memory-directory layout: the memory dir root is PURE CONFIG (an in-repo
|
|
2
|
+
// git-tracked dir for a project scope, or the repo-keyed home mount below for user/personal scopes —
|
|
3
|
+
// the engine asserts NEITHER), plus the scope→dir mapping shared by the engine (projection) and the
|
|
4
|
+
// FileBackend (storage), so the two can never disagree about where an entry's file lives (the
|
|
5
|
+
// zero-copy invariant depends on this single source). TODO(S1b): per-scope PHYSICAL roots in one
|
|
6
|
+
// session (project in-repo + user out-of-repo simultaneously) — this module currently maps all of a
|
|
7
|
+
// session's scopes under ONE root.
|
|
8
|
+
//
|
|
9
|
+
// 双轨评审 B3 (架构): the ENGINE CONTROL PLANE. All engine metadata (the committed-rev ledger, the
|
|
10
|
+
// scope registry, consolidation cursors, the committed shadow, quarantine, the transaction journal)
|
|
11
|
+
// lives in a directory OUTSIDE the model-writable memory dir — under the memory-engine CONFIG ROOT
|
|
12
|
+
// (`<configRoot>/<key>/.engine/`), never inside the repo and never inside the memory dir, even when
|
|
13
|
+
// the memory dir itself is configured in-repo (§2.7). The model's file channel therefore can NEVER
|
|
14
|
+
// reach CAS/scope metadata; sidecar corruption is FAIL-CLOSED ({@link ControlPlaneCorruptError}) —
|
|
15
|
+
// harvest refuses and reports instead of degrading to an empty ledger / re-claimable root.
|
|
16
|
+
import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeSync } from "node:fs";
|
|
17
|
+
import { homedir } from "node:os";
|
|
18
|
+
import { createHash } from "node:crypto";
|
|
19
|
+
import { dirname, isAbsolute, join, resolve, sep } from "node:path";
|
|
20
|
+
/** The root-claim record: which scope's entries live DIRECTLY in the memory dir root (CC parity —
|
|
21
|
+
* `memory/MEMORY.md` + flat topic files). Claimed by the FIRST writeScope ever used for this repo's
|
|
22
|
+
* memory dir and durable thereafter; every other scope gets a `memory/<scope-label>/` subdir.
|
|
23
|
+
* B3: lives in the CONTROL PLANE (`scopes.json`), never in the model-writable memory dir. */
|
|
24
|
+
const SCOPES_FILE = "scopes.json";
|
|
25
|
+
/** Cursor sidecar for the design/84 Seam B pair on the FileBackend (`{ [scope]: cursor }`). B3: control plane. */
|
|
26
|
+
export const CURSORS_FILE = "cursors.json";
|
|
27
|
+
/** B3 fail-closed: a control-plane sidecar exists but cannot be trusted (unparseable / wrong shape).
|
|
28
|
+
* Read paths propagate it (materialize fails ⇒ the runner falls open to a memory-less session with
|
|
29
|
+
* onError); harvest converts it into a refused report (incident `sidecar_corrupt`). It is NEVER
|
|
30
|
+
* silently degraded to an empty ledger / unclaimed root — that would let a corrupted (or truncated)
|
|
31
|
+
* sidecar erase CAS baselines and re-open the root claim. */
|
|
32
|
+
export class ControlPlaneCorruptError extends Error {
|
|
33
|
+
constructor(message, opts) {
|
|
34
|
+
super(message, opts);
|
|
35
|
+
this.name = "ControlPlaneCorruptError";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* CC-style repo key: the absolute repo root path, every non-alphanumeric rune folded to `-` (the same
|
|
40
|
+
* slug family CC uses for its per-project dirs). Deterministic + filesystem-safe; collisions across
|
|
41
|
+
* repos require pathological sibling names and only merge their memory dirs (never corrupt them).
|
|
42
|
+
*/
|
|
43
|
+
export function deriveRepoKey(repoRoot) {
|
|
44
|
+
return resolve(repoRoot).normalize("NFC").replace(/[^A-Za-z0-9]/g, "-");
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* `<configRoot>/<repoKey>/memory` — the repo-level stable mount (§2.7: taskRoot 外, worktree-shared).
|
|
48
|
+
*
|
|
49
|
+
* Worktree note (验收 L5, documented behavior): the KEY must be the BASE repo root. The runner passes
|
|
50
|
+
* `deps.rootPath ?? taskRootPath` — when `rootPath` is configured, every derived worktree of that repo
|
|
51
|
+
* shares ONE memory dir (a worktree moves the task cwd, never the memory mount); when `rootPath` is
|
|
52
|
+
* NOT configured the taskRootPath fallback keys memory to the task's own checkout path, so an
|
|
53
|
+
* isolated-worktree task without `rootPath` gets a worktree-private memory dir. That fallback is the
|
|
54
|
+
* accepted degraded behavior (no silent cross-repo mixing; configure `rootPath` for worktree sharing).
|
|
55
|
+
*/
|
|
56
|
+
export function deriveRepoMemoryDir(configRoot, repoRoot) {
|
|
57
|
+
return join(configRoot, deriveRepoKey(repoRoot), "memory");
|
|
58
|
+
}
|
|
59
|
+
// ---------------------------------------------------------------------------------------------
|
|
60
|
+
// design/142 §1.5 — marker-first identity keying + the path→projectId hint cache
|
|
61
|
+
// ---------------------------------------------------------------------------------------------
|
|
62
|
+
/** design/142 §1.5 — the IDENTITY-keyed mount (v2 scope contract + a resolved project marker):
|
|
63
|
+
* `<configRoot>/proj-<projectId>/memory`. Unlike the path-derived {@link deriveRepoMemoryDir},
|
|
64
|
+
* this key survives rename/move/re-clone/container remounts — identity lives in the repo's marker,
|
|
65
|
+
* the mount stops referencing the path entirely. */
|
|
66
|
+
export function deriveProjectMemoryDir(configRoot, projectId) {
|
|
67
|
+
return join(configRoot, `proj-${projectId.toLowerCase()}`, "memory");
|
|
68
|
+
}
|
|
69
|
+
/** Control-plane sibling of {@link deriveProjectMemoryDir} (B3: always on the config-root side). */
|
|
70
|
+
export function deriveProjectControlDir(configRoot, projectId) {
|
|
71
|
+
return join(configRoot, `proj-${projectId.toLowerCase()}`, ".engine");
|
|
72
|
+
}
|
|
73
|
+
/** design/142 §1.5 — the path→projectId HINT CACHE (`<configRoot>/project-id-hints.json`). NOT an
|
|
74
|
+
* identity source (the marker is the single truth source); purely the recovery breadcrumb for a
|
|
75
|
+
* deleted/lost marker: materialize can tell "this path used to carry marker X" and prompt a
|
|
76
|
+
* restore instead of silently minting a fresh identity. Best-effort on both faces (a corrupt hint
|
|
77
|
+
* file degrades to "no hints", never blocks a session). */
|
|
78
|
+
export const PROJECT_ID_HINTS_FILE = "project-id-hints.json";
|
|
79
|
+
export function recordProjectIdHint(configRoot, repoRoot, projectId) {
|
|
80
|
+
try {
|
|
81
|
+
const path = join(configRoot, PROJECT_ID_HINTS_FILE);
|
|
82
|
+
let hints = {};
|
|
83
|
+
try {
|
|
84
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
85
|
+
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed))
|
|
86
|
+
hints = parsed;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
/* absent/corrupt ⇒ start fresh (hints are breadcrumbs, not a ledger) */
|
|
90
|
+
}
|
|
91
|
+
const key = resolve(repoRoot);
|
|
92
|
+
if (hints[key] === projectId.toLowerCase())
|
|
93
|
+
return;
|
|
94
|
+
hints[key] = projectId.toLowerCase();
|
|
95
|
+
mkdirSync(configRoot, { recursive: true });
|
|
96
|
+
atomicWriteFileSync(path, `${JSON.stringify(hints, null, 2)}\n`);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
/* best-effort */
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export function lookupProjectIdHint(configRoot, repoRoot) {
|
|
103
|
+
try {
|
|
104
|
+
const parsed = JSON.parse(readFileSync(join(configRoot, PROJECT_ID_HINTS_FILE), "utf8"));
|
|
105
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
|
|
106
|
+
return undefined;
|
|
107
|
+
const v = parsed[resolve(repoRoot)];
|
|
108
|
+
return typeof v === "string" ? v : undefined;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/** B3 — `<configRoot>/<key>/.engine`: the engine CONTROL PLANE for the memory dir/repo identified by
|
|
115
|
+
* `key` (a repo root for the standard flow, or the memory dir itself for a directory-pinned backend).
|
|
116
|
+
* Sibling of the derived `memory/` mount, ALWAYS on the config-root side — when the memory dir is
|
|
117
|
+
* configured in-repo, the control plane still lives here (model-invisible, not injected, not in-repo). */
|
|
118
|
+
export function deriveControlPlaneDir(configRoot, key) {
|
|
119
|
+
return join(configRoot, deriveRepoKey(key), ".engine");
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Resolve the memory-engine config root: explicit (`RunnerDeps.memoryEngineDir`) → `AGENT_DATA_DIR`
|
|
123
|
+
* env → `~/.ai-agent` (the same default family as the file stores' `resolveDataRoot`; re-stated here
|
|
124
|
+
* so core/memory-engine does not import from src/stores).
|
|
125
|
+
*/
|
|
126
|
+
export function resolveMemoryEngineRoot(explicit) {
|
|
127
|
+
const raw = explicit ?? process.env.AGENT_DATA_DIR ?? join(homedir(), ".ai-agent");
|
|
128
|
+
return isAbsolute(raw) ? raw : resolve(raw);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Filesystem-safe scope dir label. 评审 H5 (唯一映射): the cleaned slug alone is LOSSY
|
|
132
|
+
* (`org:7` and `org/7` both fold to `org-7` — two tenants, one directory = cross-scope bleed), so any
|
|
133
|
+
* scope whose cleaned form differs from the original gets a short content-hash suffix
|
|
134
|
+
* (`org-7-a1b2c3`), making the mapping injective for all practical inputs; an already-safe scope maps
|
|
135
|
+
* to itself (stable, human-readable). {@link registerScope} additionally FAIL-CLOSES on a registry
|
|
136
|
+
* collision (two distinct scopes → one dir name), so even a hash collision cannot silently merge scopes.
|
|
137
|
+
*/
|
|
138
|
+
export function scopeDirName(scope) {
|
|
139
|
+
if (/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(scope))
|
|
140
|
+
return scope;
|
|
141
|
+
const cleaned = scope.replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^[.-]+/, "") || "scope";
|
|
142
|
+
const hash = createHash("sha256").update(scope, "utf8").digest("hex").slice(0, 6);
|
|
143
|
+
return `${cleaned}-${hash}`;
|
|
144
|
+
}
|
|
145
|
+
function readScopesRecord(controlDir) {
|
|
146
|
+
const path = join(controlDir, SCOPES_FILE);
|
|
147
|
+
let raw;
|
|
148
|
+
try {
|
|
149
|
+
raw = readFileSync(path, "utf8");
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
if (err.code === "ENOENT")
|
|
153
|
+
return {}; // absent ⇒ genuinely unclaimed (first run)
|
|
154
|
+
// 对抗复审 L4: any OTHER read failure (EACCES/EIO/…) is NOT "unclaimed" — swallowing it would let
|
|
155
|
+
// the next locked update overwrite the registry with an empty table (a silent fail-open downgrade
|
|
156
|
+
// of a FAIL-CLOSED sidecar: CAS-load-bearing root claim + scope homes erased by a transient IO error).
|
|
157
|
+
throw new ControlPlaneCorruptError(`scope registry unreadable (${err.code ?? "io error"}): ${path}`, { cause: err });
|
|
158
|
+
}
|
|
159
|
+
let parsed;
|
|
160
|
+
try {
|
|
161
|
+
parsed = JSON.parse(raw);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
throw new ControlPlaneCorruptError(`scope registry is unparseable: ${path}`);
|
|
165
|
+
}
|
|
166
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
167
|
+
throw new ControlPlaneCorruptError(`scope registry has the wrong shape: ${path}`);
|
|
168
|
+
}
|
|
169
|
+
const rec = parsed;
|
|
170
|
+
if (rec.rootScope !== undefined && typeof rec.rootScope !== "string") {
|
|
171
|
+
throw new ControlPlaneCorruptError(`scope registry rootScope is not a string: ${path}`);
|
|
172
|
+
}
|
|
173
|
+
let scopes;
|
|
174
|
+
if (rec.scopes !== undefined) {
|
|
175
|
+
if (!rec.scopes || typeof rec.scopes !== "object" || Array.isArray(rec.scopes)) {
|
|
176
|
+
throw new ControlPlaneCorruptError(`scope registry scopes map has the wrong shape: ${path}`);
|
|
177
|
+
}
|
|
178
|
+
for (const [k, v] of Object.entries(rec.scopes)) {
|
|
179
|
+
if (typeof v !== "string")
|
|
180
|
+
throw new ControlPlaneCorruptError(`scope registry entry ${JSON.stringify(k)} is not a string: ${path}`);
|
|
181
|
+
}
|
|
182
|
+
scopes = rec.scopes;
|
|
183
|
+
}
|
|
184
|
+
return { rootScope: rec.rootScope, scopes };
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* 独立轨 F5 (design/142 S2b 连带) — scopes.json read-modify-write under the SAME sidecar lock family
|
|
188
|
+
* as announcements/scan-fuse. The dual-root personal mount is ONE physical tree shared by every
|
|
189
|
+
* concurrent session on the machine: an unlocked first-use root-claim race (two sessions both read
|
|
190
|
+
* "unclaimed", both write themselves as rootScope, last-writer-wins) mis-attributes root-dir entries
|
|
191
|
+
* across scopes. NOT lockedJournaledUpdate: scopes.json is FAIL-CLOSED on corruption (B3) — this
|
|
192
|
+
* variant reads via readScopesRecord (throws ControlPlaneCorruptError) instead of fail-open rebuild.
|
|
193
|
+
*/
|
|
194
|
+
function lockedScopesUpdate(controlDir, fn) {
|
|
195
|
+
ensureDirExists(controlDir);
|
|
196
|
+
const file = join(controlDir, SCOPES_FILE);
|
|
197
|
+
const journal = `${file}.journal`;
|
|
198
|
+
const lock = `${file}.lock`;
|
|
199
|
+
// 对抗复审 L4 (second half): scopes.json is FAIL-CLOSED — a wedged lock must throw, never proceed
|
|
200
|
+
// lock-less into a read-modify-write of the registry (the fail-open deadline steal is for the
|
|
201
|
+
// non-load-bearing sidecars only). The read path (readScopesRecord) throws on non-ENOENT IO errors
|
|
202
|
+
// for the same reason. Same lock primitive as the fail-open family, so it shares the single-winner
|
|
203
|
+
// tombstone steal + owner-token release guard (L1/L2 class fixes).
|
|
204
|
+
const token = acquireSidecarLock(lock, { onDeadline: "throw" });
|
|
205
|
+
try {
|
|
206
|
+
rollForwardSidecar(file, journal);
|
|
207
|
+
const rec = readScopesRecord(controlDir);
|
|
208
|
+
const { next, result } = fn(rec);
|
|
209
|
+
if (next !== undefined) {
|
|
210
|
+
const data = `${JSON.stringify(next, null, 2)}\n`;
|
|
211
|
+
// L2-analog 归属复验 at the commit point: a holder stalled past LOCK_STALE_MS and stolen from
|
|
212
|
+
// must not commit over the stealer's registry write (fail-closed, unlike the fail-open family).
|
|
213
|
+
assertSidecarLockOwnership(lock, token, "scope registry");
|
|
214
|
+
atomicWriteFileSync(journal, data); // commit point (crash after this rolls forward)
|
|
215
|
+
atomicWriteFileSync(file, data);
|
|
216
|
+
rmSync(journal, { force: true });
|
|
217
|
+
}
|
|
218
|
+
return result;
|
|
219
|
+
}
|
|
220
|
+
finally {
|
|
221
|
+
releaseSidecarLock(lock, token);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/** Which scope owns the memory dir ROOT (undefined = unclaimed). */
|
|
225
|
+
export function rootScopeOf(controlDir) {
|
|
226
|
+
return readScopesRecord(controlDir).rootScope;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Claim the memory dir root for `scope` iff unclaimed (idempotent, first-writer-wins, durable).
|
|
230
|
+
* Returns the (possibly pre-existing) root owner. Lock-serialized (独立轨 F5): two first-users of a
|
|
231
|
+
* shared mount race the claim under the sidecar lock — exactly one wins, the other SEES the winner.
|
|
232
|
+
*/
|
|
233
|
+
export function claimRootScope(controlDir, scope) {
|
|
234
|
+
return lockedScopesUpdate(controlDir, (rec) => {
|
|
235
|
+
if (rec.rootScope !== undefined)
|
|
236
|
+
return { result: rec.rootScope };
|
|
237
|
+
return { next: { rootScope: scope, scopes: { ...rec.scopes, [scope]: "" } }, result: scope };
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
/** Register `scope` in the durable registry (idempotent) and return its home dir under `memoryDir`.
|
|
241
|
+
* H5 fail-closed: a dir-name collision with a DIFFERENT registered scope throws — two scopes must
|
|
242
|
+
* never share one directory (silent cross-scope merge). Lock-serialized (独立轨 F5). */
|
|
243
|
+
export function registerScope(memoryDir, controlDir, scope) {
|
|
244
|
+
return lockedScopesUpdate(controlDir, (rec) => {
|
|
245
|
+
const dirName = rec.rootScope === scope ? "" : scopeDirName(scope);
|
|
246
|
+
for (const [other, otherDir] of Object.entries(rec.scopes ?? {})) {
|
|
247
|
+
if (other !== scope && otherDir !== "" && otherDir === dirName) {
|
|
248
|
+
throw new ControlPlaneCorruptError(`scope directory collision: ${JSON.stringify(scope)} and ${JSON.stringify(other)} both map to ${JSON.stringify(dirName)} — refusing (fail-closed)`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (rec.scopes?.[scope] === undefined) {
|
|
252
|
+
return { next: { ...rec, scopes: { ...rec.scopes, [scope]: dirName } }, result: dirName === "" ? memoryDir : join(memoryDir, dirName) };
|
|
253
|
+
}
|
|
254
|
+
if (rec.scopes[scope] !== dirName) {
|
|
255
|
+
// A registered scope's home NEVER moves (entries live there) — honor the registry, not the formula.
|
|
256
|
+
return { result: rec.scopes[scope] === "" ? memoryDir : join(memoryDir, rec.scopes[scope]) };
|
|
257
|
+
}
|
|
258
|
+
return { result: dirName === "" ? memoryDir : join(memoryDir, dirName) };
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
/** All registered scopes → home dir name (`""` = the root). */
|
|
262
|
+
export function registeredScopes(controlDir) {
|
|
263
|
+
return readScopesRecord(controlDir).scopes ?? {};
|
|
264
|
+
}
|
|
265
|
+
/** The stable home directory of `scope`'s entry files: the root when it owns the root, else the
|
|
266
|
+
* REGISTERED subdir (falls back to the {@link scopeDirName} formula for a never-registered scope). */
|
|
267
|
+
export function scopeDirFor(memoryDir, controlDir, scope) {
|
|
268
|
+
const rec = readScopesRecord(controlDir);
|
|
269
|
+
if (rec.rootScope === scope)
|
|
270
|
+
return memoryDir;
|
|
271
|
+
const registered = rec.scopes?.[scope];
|
|
272
|
+
if (registered !== undefined)
|
|
273
|
+
return registered === "" ? memoryDir : join(memoryDir, registered);
|
|
274
|
+
return join(memoryDir, scopeDirName(scope));
|
|
275
|
+
}
|
|
276
|
+
/** Canonicalize a path for containment checks (resolves symlinks on the EXISTING prefix). */
|
|
277
|
+
export function canonicalize(p) {
|
|
278
|
+
try {
|
|
279
|
+
return realpathSync(p);
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
// Non-existent leaf: canonicalize the nearest existing ancestor + re-append the remainder.
|
|
283
|
+
const parent = resolve(p, "..");
|
|
284
|
+
if (parent === p)
|
|
285
|
+
return p;
|
|
286
|
+
return join(canonicalize(parent), p.slice(parent.length + 1) || "");
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/** True iff `child` (canonicalized) is `root` or inside it. */
|
|
290
|
+
export function isContainedIn(root, child) {
|
|
291
|
+
const r = canonicalize(root);
|
|
292
|
+
const c = canonicalize(child);
|
|
293
|
+
// opus 1.258 review (LOW, platform sweep): `sep`, not a hardcoded '/', so win32 backslash paths
|
|
294
|
+
// neither fail-OPEN the write gate nor mass-reject harvest as outside_root.
|
|
295
|
+
return c === r || c.startsWith(`${r}${sep}`);
|
|
296
|
+
}
|
|
297
|
+
/** mkdir -p convenience used by the engine/backend (0o700 like the file stores). */
|
|
298
|
+
export function ensureDirExists(dir) {
|
|
299
|
+
if (!existsSync(dir))
|
|
300
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
301
|
+
}
|
|
302
|
+
// ============================================================================
|
|
303
|
+
// design/138 S2-B/S2-C — journaled control-plane state: the announcement queue
|
|
304
|
+
// (`announcements.json`) and the write-scan fuse (`scan-fuse.json`).
|
|
305
|
+
//
|
|
306
|
+
// O-F6/C-F5: a bare read-modify-write over atomicWriteFileSync only prevents TORN files — two
|
|
307
|
+
// concurrent writers (multi-worktree sessions sharing one repo-level control plane) would still
|
|
308
|
+
// overwrite each other's enqueue. These sidecars therefore go through `lockedJournaledUpdate`:
|
|
309
|
+
// lock (cross-process mkdir mutex, stale-stolen) → roll forward any interrupted journal →
|
|
310
|
+
// re-read → mutate → journal (atomic rename = commit point) → execute (atomic file write) →
|
|
311
|
+
// drop journal → unlock.
|
|
312
|
+
// This is the applyPatches stage→journal→execute discipline applied at sidecar scale, PLUS the
|
|
313
|
+
// mutual exclusion the announcement path needs because its writers (harvest tail / read-side sync /
|
|
314
|
+
// session-first drain) are not serialized by any CAS. Corrupt state stays FAIL-OPEN (discarded and
|
|
315
|
+
// rebuilt): announcements/fuse counts are never CAS-load-bearing (§9.1 — only cursors share this).
|
|
316
|
+
// ============================================================================
|
|
317
|
+
/** S2-B — the queued memory-change announcements (control plane; drained at session-first inject). */
|
|
318
|
+
export const ANNOUNCEMENTS_FILE = "announcements.json";
|
|
319
|
+
/** S2-B — bounded queue: overflow FOLDS (oldest dropped, counted) instead of growing unbounded. */
|
|
320
|
+
export const MEMORY_ANNOUNCEMENTS_MAX = 20;
|
|
321
|
+
/** S2-C — per-file write-rejection counts (the beforeWrite silent-reject fuse; O-F9/C-F7: scoped
|
|
322
|
+
* state in `.engine/`, so the count survives suspend/resume and backend re-construction). */
|
|
323
|
+
export const SCAN_FUSE_FILE = "scan-fuse.json";
|
|
324
|
+
/** Rejections at which the write-time feedback mutes (S2-C: 拒 ≥3 次熔断为静默拒). */
|
|
325
|
+
export const SCAN_FUSE_THRESHOLD = 3;
|
|
326
|
+
/** Synchronous sleep for the lock spin (Atomics.wait — no busy CPU loop, no async plumbing). */
|
|
327
|
+
function sleepSync(ms) {
|
|
328
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
329
|
+
}
|
|
330
|
+
const LOCK_STALE_MS = 1_500;
|
|
331
|
+
const LOCK_WAIT_CAP_MS = 3_000;
|
|
332
|
+
/** Cross-process mutex via mkdir (atomic on POSIX). A lock older than {@link LOCK_STALE_MS} is
|
|
333
|
+
* presumed crashed and stolen; after {@link LOCK_WAIT_CAP_MS} total we proceed anyway (fail-open —
|
|
334
|
+
* these sidecars are not CAS-load-bearing, and wedging a session start on a lock would be worse).
|
|
335
|
+
*
|
|
336
|
+
* opus 1.258 review (MED, steal TOCTOU): a bare rmSync+mkdir steal lets TWO stealers both win (B's
|
|
337
|
+
* force-rm deletes A's FRESH lock). The steal is made single-winner by an atomic `renameSync` of the
|
|
338
|
+
* stale lock dir to a unique tombstone first — rename is atomic, exactly one racer succeeds; the
|
|
339
|
+
* loser's rename throws ENOENT and it loops back to a normal mkdir wait. The deadline branch keeps
|
|
340
|
+
* the documented proceed-anyway semantics but steals through the same single-winner gate. */
|
|
341
|
+
function acquireSidecarLock(lockDir, opts = {}) {
|
|
342
|
+
const deadline = Date.now() + LOCK_WAIT_CAP_MS;
|
|
343
|
+
const stealOnce = () => {
|
|
344
|
+
// Single-winner steal: atomic rename to a unique tombstone; only one racer's rename succeeds.
|
|
345
|
+
const tomb = `${lockDir}.stale-${process.pid}-${Math.random().toString(36).slice(2, 8)}`;
|
|
346
|
+
try {
|
|
347
|
+
renameSync(lockDir, tomb);
|
|
348
|
+
}
|
|
349
|
+
catch {
|
|
350
|
+
return false; // another racer stole it (or the holder released) — go back to the mkdir wait
|
|
351
|
+
}
|
|
352
|
+
rmSync(tomb, { recursive: true, force: true });
|
|
353
|
+
return true;
|
|
354
|
+
};
|
|
355
|
+
for (;;) {
|
|
356
|
+
try {
|
|
357
|
+
mkdirSync(lockDir); // NOT recursive: recursive:true reports success on an EXISTING dir
|
|
358
|
+
// codex 1.258 review (MED, second half): OWNER TOKEN — a holder that stalls past LOCK_STALE_MS
|
|
359
|
+
// and gets stolen must not, on resume, delete the NEW holder's lock (its finally used to rm
|
|
360
|
+
// unconditionally). The token names this acquisition; release only removes the lock while the
|
|
361
|
+
// token is still ours.
|
|
362
|
+
const token = `${process.pid}-${Math.random().toString(36).slice(2, 10)}`;
|
|
363
|
+
try {
|
|
364
|
+
writeSync(openSync(join(lockDir, "owner"), "w"), token);
|
|
365
|
+
}
|
|
366
|
+
catch {
|
|
367
|
+
/* best-effort — a tokenless lock releases like the pre-token behavior */
|
|
368
|
+
}
|
|
369
|
+
return token;
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
try {
|
|
373
|
+
const age = Date.now() - statSync(lockDir).mtimeMs;
|
|
374
|
+
if (age > LOCK_STALE_MS) {
|
|
375
|
+
stealOnce(); // win or lose, loop back to mkdir — losers must NOT force-rm the winner's fresh lock
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
catch {
|
|
380
|
+
continue; // holder released between mkdir and stat — retry immediately
|
|
381
|
+
}
|
|
382
|
+
if (Date.now() > deadline) {
|
|
383
|
+
if (opts.onDeadline === "throw") {
|
|
384
|
+
// 对抗复审 L4: fail-closed callers (scopes.json) never proceed lock-less. No all-dead window
|
|
385
|
+
// here (L3 class): LOCK_STALE_MS < LOCK_WAIT_CAP_MS, so a crashed holder is always stolen
|
|
386
|
+
// BEFORE this deadline — reaching it means live contention wedged, which must surface.
|
|
387
|
+
throw new Error(`sidecar lock wait timed out (${LOCK_WAIT_CAP_MS}ms) at ${lockDir} — refusing to proceed without the lock (fail-closed sidecar)`);
|
|
388
|
+
}
|
|
389
|
+
stealOnce(); // documented fail-open: proceed anyway, but through the single-winner gate
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
sleepSync(5);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
/** Roll an interrupted sidecar journal forward (journal exists ⇒ its content IS the committed next
|
|
397
|
+
* state — adopt it). An unparseable journal is dropped (fail-open — see module note above). */
|
|
398
|
+
function rollForwardSidecar(file, journal) {
|
|
399
|
+
let raw;
|
|
400
|
+
try {
|
|
401
|
+
raw = readFileSync(journal, "utf8");
|
|
402
|
+
}
|
|
403
|
+
catch {
|
|
404
|
+
return; // no journal — nothing interrupted
|
|
405
|
+
}
|
|
406
|
+
try {
|
|
407
|
+
JSON.parse(raw); // adopt only a parseable journal
|
|
408
|
+
atomicWriteFileSync(file, raw);
|
|
409
|
+
}
|
|
410
|
+
catch {
|
|
411
|
+
/* fail-open: unknowable partial state for a non-load-bearing sidecar — discard */
|
|
412
|
+
}
|
|
413
|
+
rmSync(journal, { force: true });
|
|
414
|
+
}
|
|
415
|
+
/** The locked, journaled sidecar update (see module note). `mutate` receives the parsed current
|
|
416
|
+
* state (undefined when absent/corrupt — fail-open) and returns the next state, or undefined to
|
|
417
|
+
* skip the write entirely (read-only pass). */
|
|
418
|
+
function lockedJournaledUpdate(controlDir, fileName, mutate) {
|
|
419
|
+
ensureDirExists(controlDir);
|
|
420
|
+
const file = join(controlDir, fileName);
|
|
421
|
+
const journal = `${file}.journal`;
|
|
422
|
+
const lock = `${file}.lock`;
|
|
423
|
+
const token = acquireSidecarLock(lock);
|
|
424
|
+
try {
|
|
425
|
+
rollForwardSidecar(file, journal);
|
|
426
|
+
let current;
|
|
427
|
+
try {
|
|
428
|
+
current = JSON.parse(readFileSync(file, "utf8"));
|
|
429
|
+
}
|
|
430
|
+
catch {
|
|
431
|
+
current = undefined; // absent/corrupt ⇒ rebuild (fail-open)
|
|
432
|
+
}
|
|
433
|
+
const next = mutate(current);
|
|
434
|
+
if (next === undefined)
|
|
435
|
+
return;
|
|
436
|
+
const data = `${JSON.stringify(next, null, 2)}\n`;
|
|
437
|
+
atomicWriteFileSync(journal, data); // commit point (crash after this rolls forward)
|
|
438
|
+
atomicWriteFileSync(file, data);
|
|
439
|
+
rmSync(journal, { force: true });
|
|
440
|
+
}
|
|
441
|
+
finally {
|
|
442
|
+
releaseSidecarLock(lock, token);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
/** 对抗复审 L2-analog (fail-closed callers only): re-verify the owner token at the COMMIT POINT —
|
|
446
|
+
* a stolen-from holder aborts instead of writing over the stealer. Lenient on an absent/unreadable
|
|
447
|
+
* owner file (token writes are best-effort in this family — same leniency as release), strict on a
|
|
448
|
+
* FOREIGN token (that is a positive proof the lock is someone else's now). */
|
|
449
|
+
function assertSidecarLockOwnership(lockDir, token, what) {
|
|
450
|
+
let held;
|
|
451
|
+
try {
|
|
452
|
+
held = readFileSync(join(lockDir, "owner"), "utf8");
|
|
453
|
+
}
|
|
454
|
+
catch {
|
|
455
|
+
return; // pre-token degraded shape — cannot disprove ownership
|
|
456
|
+
}
|
|
457
|
+
if (held !== token) {
|
|
458
|
+
throw new ControlPlaneCorruptError(`${what}: sidecar lock ownership lost before commit (holder stalled past ${LOCK_STALE_MS}ms and was stolen from) — update aborted`);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
/** Release only while the owner token is still OURS (codex 1.258 MED second half): a holder that was
|
|
462
|
+
* stolen from (stall > LOCK_STALE_MS) finds a foreign/absent token and leaves the new holder's lock
|
|
463
|
+
* alone — its own write may have raced, but the sidecars are fail-open and the NEXT locked update
|
|
464
|
+
* self-heals; deleting the live lock would instead cascade a third writer in. */
|
|
465
|
+
function releaseSidecarLock(lockDir, token) {
|
|
466
|
+
try {
|
|
467
|
+
const held = readFileSync(join(lockDir, "owner"), "utf8");
|
|
468
|
+
if (held !== token)
|
|
469
|
+
return; // stolen while we stalled — the lock is someone else's now
|
|
470
|
+
}
|
|
471
|
+
catch {
|
|
472
|
+
/* owner file unreadable/absent: fall through and release (pre-token degraded shape) */
|
|
473
|
+
}
|
|
474
|
+
rmSync(lockDir, { recursive: true, force: true });
|
|
475
|
+
}
|
|
476
|
+
/** Read a sidecar with journal roll-forward SEMANTICS but no writes (safe without the lock: a
|
|
477
|
+
* journal present means that content is the committed next state). */
|
|
478
|
+
function readSidecarJson(controlDir, fileName) {
|
|
479
|
+
const file = join(controlDir, fileName);
|
|
480
|
+
for (const p of [`${file}.journal`, file]) {
|
|
481
|
+
try {
|
|
482
|
+
return JSON.parse(readFileSync(p, "utf8"));
|
|
483
|
+
}
|
|
484
|
+
catch {
|
|
485
|
+
/* try the next source */
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
return undefined;
|
|
489
|
+
}
|
|
490
|
+
/** Lenient shape recovery (fail-open): keep only well-formed entries, never throw. */
|
|
491
|
+
function coerceAnnouncements(raw) {
|
|
492
|
+
const rec = { folded: 0, queue: [] };
|
|
493
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
494
|
+
return rec;
|
|
495
|
+
const r = raw;
|
|
496
|
+
if (typeof r.folded === "number" && Number.isFinite(r.folded) && r.folded > 0)
|
|
497
|
+
rec.folded = Math.floor(r.folded);
|
|
498
|
+
if (Array.isArray(r.queue)) {
|
|
499
|
+
for (const e of r.queue) {
|
|
500
|
+
const a = e;
|
|
501
|
+
if (a &&
|
|
502
|
+
typeof a === "object" &&
|
|
503
|
+
(a.kind === "gate" || a.kind === "external") &&
|
|
504
|
+
typeof a.at === "number" &&
|
|
505
|
+
Array.isArray(a.items) &&
|
|
506
|
+
a.items.every((i) => typeof i === "string")) {
|
|
507
|
+
rec.queue.push({ kind: a.kind, at: a.at, ...(typeof a.sessionId === "string" ? { sessionId: a.sessionId } : {}), items: a.items });
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return rec;
|
|
512
|
+
}
|
|
513
|
+
/** S2-B — enqueue one announcement (journaled + locked; bounded with overflow folding). */
|
|
514
|
+
export function enqueueMemoryAnnouncement(controlDir, ann) {
|
|
515
|
+
if (ann.items.length === 0)
|
|
516
|
+
return;
|
|
517
|
+
lockedJournaledUpdate(controlDir, ANNOUNCEMENTS_FILE, (current) => {
|
|
518
|
+
const rec = coerceAnnouncements(current);
|
|
519
|
+
rec.queue.push(ann);
|
|
520
|
+
if (rec.queue.length > MEMORY_ANNOUNCEMENTS_MAX) {
|
|
521
|
+
rec.folded += rec.queue.length - MEMORY_ANNOUNCEMENTS_MAX;
|
|
522
|
+
rec.queue = rec.queue.slice(-MEMORY_ANNOUNCEMENTS_MAX);
|
|
523
|
+
}
|
|
524
|
+
return rec;
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
/** S2-B — drain the queue (session-first inject, 时机①). Returns what was queued and resets it. */
|
|
528
|
+
export function drainMemoryAnnouncements(controlDir) {
|
|
529
|
+
const file = join(controlDir, ANNOUNCEMENTS_FILE);
|
|
530
|
+
if (!existsSync(file) && !existsSync(`${file}.journal`))
|
|
531
|
+
return { folded: 0, queue: [] }; // fast path: nothing queued, no lock/write
|
|
532
|
+
let drained = { folded: 0, queue: [] };
|
|
533
|
+
lockedJournaledUpdate(controlDir, ANNOUNCEMENTS_FILE, (current) => {
|
|
534
|
+
drained = coerceAnnouncements(current);
|
|
535
|
+
if (drained.queue.length === 0 && drained.folded === 0)
|
|
536
|
+
return undefined; // nothing to reset
|
|
537
|
+
return { folded: 0, queue: [] };
|
|
538
|
+
});
|
|
539
|
+
return drained;
|
|
540
|
+
}
|
|
541
|
+
/** Test/observability peek (journal-aware, non-destructive). */
|
|
542
|
+
export function peekMemoryAnnouncements(controlDir) {
|
|
543
|
+
return coerceAnnouncements(readSidecarJson(controlDir, ANNOUNCEMENTS_FILE));
|
|
544
|
+
}
|
|
545
|
+
function coerceFuse(raw) {
|
|
546
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
547
|
+
return {};
|
|
548
|
+
const out = {};
|
|
549
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
550
|
+
if (typeof v === "number" && Number.isFinite(v) && v > 0)
|
|
551
|
+
out[k] = Math.floor(v);
|
|
552
|
+
}
|
|
553
|
+
return out;
|
|
554
|
+
}
|
|
555
|
+
/** S2-C — record one write-time scan rejection for `key` (canonical file path); returns the count
|
|
556
|
+
* BEFORE this bump (callers mute the feedback when it is already ≥ {@link SCAN_FUSE_THRESHOLD}). */
|
|
557
|
+
export function bumpScanFuse(controlDir, key) {
|
|
558
|
+
let prior = 0;
|
|
559
|
+
lockedJournaledUpdate(controlDir, SCAN_FUSE_FILE, (current) => {
|
|
560
|
+
const counts = coerceFuse(current);
|
|
561
|
+
prior = counts[key] ?? 0;
|
|
562
|
+
counts[key] = prior + 1;
|
|
563
|
+
return counts;
|
|
564
|
+
});
|
|
565
|
+
return prior;
|
|
566
|
+
}
|
|
567
|
+
/** S2-C — the current fuse count for `key` (0 = never rejected / cleared). */
|
|
568
|
+
/** F1 (REPORT-EXTENDED-2026-07-08) — the derived-index rev snapshot: target → entry rev AS OF the
|
|
569
|
+
* last rebuild. rebuildIndex keeps a model-worded index line only while the entry rev is unchanged;
|
|
570
|
+
* a rev change drops the stale wording (the injected index otherwise answers the OLD value for the
|
|
571
|
+
* next session). Control plane, best-effort, fail-open (absent/corrupt ⇒ {}). */
|
|
572
|
+
const INDEX_REVS_FILE = "index-revs.json";
|
|
573
|
+
export function readIndexRevs(controlDir) {
|
|
574
|
+
const parsed = readSidecarJson(controlDir, INDEX_REVS_FILE);
|
|
575
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
576
|
+
return {};
|
|
577
|
+
const out = {};
|
|
578
|
+
for (const [k, v] of Object.entries(parsed))
|
|
579
|
+
if (typeof v === "string")
|
|
580
|
+
out[k] = v;
|
|
581
|
+
return out;
|
|
582
|
+
}
|
|
583
|
+
export function writeIndexRevs(controlDir, revs) {
|
|
584
|
+
try {
|
|
585
|
+
ensureDirExists(controlDir);
|
|
586
|
+
atomicWriteFileSync(join(controlDir, INDEX_REVS_FILE), `${JSON.stringify(revs, null, 2)}\n`);
|
|
587
|
+
}
|
|
588
|
+
catch {
|
|
589
|
+
/* best-effort — a missed snapshot degrades to keep-model-wording-once, never breaks rebuild */
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
export function scanFuseCount(controlDir, key) {
|
|
593
|
+
return coerceFuse(readSidecarJson(controlDir, SCAN_FUSE_FILE))[key] ?? 0;
|
|
594
|
+
}
|
|
595
|
+
/** S2-C — clear the fuse for files harvest just ACCEPTED (a committed write resets the strike count). */
|
|
596
|
+
export function clearScanFuse(controlDir, keys) {
|
|
597
|
+
const wanted = [...keys];
|
|
598
|
+
if (wanted.length === 0)
|
|
599
|
+
return;
|
|
600
|
+
const file = join(controlDir, SCAN_FUSE_FILE);
|
|
601
|
+
if (!existsSync(file) && !existsSync(`${file}.journal`))
|
|
602
|
+
return;
|
|
603
|
+
lockedJournaledUpdate(controlDir, SCAN_FUSE_FILE, (current) => {
|
|
604
|
+
const counts = coerceFuse(current);
|
|
605
|
+
let changed = false;
|
|
606
|
+
for (const k of wanted) {
|
|
607
|
+
if (counts[k] !== undefined) {
|
|
608
|
+
delete counts[k];
|
|
609
|
+
changed = true;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
return changed ? counts : undefined;
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
/** B3/H4 — durable atomic write: tmp file in the SAME directory (rename atomicity needs one fs),
|
|
616
|
+
* fsync'd, then renamed over the target. Every control-plane sidecar write goes through this — a
|
|
617
|
+
* crash can leave the OLD content or the NEW content, never a torn file. Throws on failure
|
|
618
|
+
* (fail-closed: a sidecar that cannot be written must not be silently skipped). */
|
|
619
|
+
export function atomicWriteFileSync(path, data) {
|
|
620
|
+
ensureDirExists(dirname(path));
|
|
621
|
+
const tmp = join(dirname(path), `.tmp-${process.pid}-${Math.random().toString(36).slice(2, 10)}`);
|
|
622
|
+
const fd = openSync(tmp, "w", 0o600);
|
|
623
|
+
try {
|
|
624
|
+
writeSync(fd, data);
|
|
625
|
+
fsyncSync(fd);
|
|
626
|
+
}
|
|
627
|
+
finally {
|
|
628
|
+
closeSync(fd);
|
|
629
|
+
}
|
|
630
|
+
try {
|
|
631
|
+
renameSync(tmp, path);
|
|
632
|
+
}
|
|
633
|
+
catch (err) {
|
|
634
|
+
try {
|
|
635
|
+
unlinkSync(tmp);
|
|
636
|
+
}
|
|
637
|
+
catch {
|
|
638
|
+
/* best-effort tmp cleanup */
|
|
639
|
+
}
|
|
640
|
+
throw err;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
//# sourceMappingURL=layout.js.map
|