@sema-agent/core 1.279.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +104 -0
- package/NOTICE.md +30 -0
- package/README.md +143 -0
- package/README.zh-CN.md +138 -0
- package/dist/agents/agent-definition.d.ts +3 -0
- package/dist/agents/agent-definition.d.ts.map +1 -0
- package/dist/agents/agent-definition.js +9 -0
- package/dist/agents/agent-definition.js.map +1 -0
- package/dist/agents/builtin-agents.d.ts +9 -0
- package/dist/agents/builtin-agents.d.ts.map +1 -0
- package/dist/agents/builtin-agents.js +114 -0
- package/dist/agents/builtin-agents.js.map +1 -0
- package/dist/agents/cascade.d.ts +44 -0
- package/dist/agents/cascade.d.ts.map +1 -0
- package/dist/agents/cascade.js +153 -0
- package/dist/agents/cascade.js.map +1 -0
- package/dist/agents/observer.d.ts +122 -0
- package/dist/agents/observer.d.ts.map +1 -0
- package/dist/agents/observer.js +365 -0
- package/dist/agents/observer.js.map +1 -0
- package/dist/agents/repair-loop.d.ts +49 -0
- package/dist/agents/repair-loop.d.ts.map +1 -0
- package/dist/agents/repair-loop.js +147 -0
- package/dist/agents/repair-loop.js.map +1 -0
- package/dist/agents/session-util.d.ts +3 -0
- package/dist/agents/session-util.d.ts.map +1 -0
- package/dist/agents/session-util.js +4 -0
- package/dist/agents/session-util.js.map +1 -0
- package/dist/agents/subagent-steps.d.ts +31 -0
- package/dist/agents/subagent-steps.d.ts.map +1 -0
- package/dist/agents/subagent-steps.js +167 -0
- package/dist/agents/subagent-steps.js.map +1 -0
- package/dist/agents/subagent.d.ts +152 -0
- package/dist/agents/subagent.d.ts.map +1 -0
- package/dist/agents/subagent.js +1698 -0
- package/dist/agents/subagent.js.map +1 -0
- package/dist/agents/suspend-guard.d.ts +6 -0
- package/dist/agents/suspend-guard.d.ts.map +1 -0
- package/dist/agents/suspend-guard.js +19 -0
- package/dist/agents/suspend-guard.js.map +1 -0
- package/dist/agents/teacher.d.ts +70 -0
- package/dist/agents/teacher.d.ts.map +1 -0
- package/dist/agents/teacher.js +462 -0
- package/dist/agents/teacher.js.map +1 -0
- package/dist/agents/team.d.ts +92 -0
- package/dist/agents/team.d.ts.map +1 -0
- package/dist/agents/team.js +231 -0
- package/dist/agents/team.js.map +1 -0
- package/dist/agents/tool-filter.d.ts +4 -0
- package/dist/agents/tool-filter.d.ts.map +1 -0
- package/dist/agents/tool-filter.js +18 -0
- package/dist/agents/tool-filter.js.map +1 -0
- package/dist/agents/verify.d.ts +46 -0
- package/dist/agents/verify.d.ts.map +1 -0
- package/dist/agents/verify.js +177 -0
- package/dist/agents/verify.js.map +1 -0
- package/dist/bench/metrics.d.ts +259 -0
- package/dist/bench/metrics.d.ts.map +1 -0
- package/dist/bench/metrics.js +439 -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 +373 -0
- package/dist/bin/sema-tb.js.map +1 -0
- package/dist/bin/tb-env.d.ts +2 -0
- package/dist/bin/tb-env.d.ts.map +1 -0
- package/dist/bin/tb-env.js +15 -0
- package/dist/bin/tb-env.js.map +1 -0
- package/dist/brain/anthropic.d.ts +16 -0
- package/dist/brain/anthropic.d.ts.map +1 -0
- package/dist/brain/anthropic.js +635 -0
- package/dist/brain/anthropic.js.map +1 -0
- package/dist/brain/circuit-breaker.d.ts +26 -0
- package/dist/brain/circuit-breaker.d.ts.map +1 -0
- package/dist/brain/circuit-breaker.js +118 -0
- package/dist/brain/circuit-breaker.js.map +1 -0
- package/dist/brain/degrading.d.ts +33 -0
- package/dist/brain/degrading.d.ts.map +1 -0
- package/dist/brain/degrading.js +175 -0
- package/dist/brain/degrading.js.map +1 -0
- package/dist/brain/errors.d.ts +14 -0
- package/dist/brain/errors.d.ts.map +1 -0
- package/dist/brain/errors.js +43 -0
- package/dist/brain/errors.js.map +1 -0
- package/dist/brain/failover.d.ts +3 -0
- package/dist/brain/failover.d.ts.map +1 -0
- package/dist/brain/failover.js +85 -0
- package/dist/brain/failover.js.map +1 -0
- package/dist/brain/model-presets.d.ts +5 -0
- package/dist/brain/model-presets.d.ts.map +1 -0
- package/dist/brain/model-presets.js +30 -0
- package/dist/brain/model-presets.js.map +1 -0
- package/dist/brain/openai.d.ts +13 -0
- package/dist/brain/openai.d.ts.map +1 -0
- package/dist/brain/openai.js +581 -0
- package/dist/brain/openai.js.map +1 -0
- package/dist/brain/reasoning.d.ts +33 -0
- package/dist/brain/reasoning.d.ts.map +1 -0
- package/dist/brain/reasoning.js +84 -0
- package/dist/brain/reasoning.js.map +1 -0
- package/dist/brain/repetition.d.ts +16 -0
- package/dist/brain/repetition.d.ts.map +1 -0
- package/dist/brain/repetition.js +96 -0
- package/dist/brain/repetition.js.map +1 -0
- package/dist/brain/request-params.d.ts +6 -0
- package/dist/brain/request-params.d.ts.map +1 -0
- package/dist/brain/request-params.js +44 -0
- package/dist/brain/request-params.js.map +1 -0
- package/dist/brain/retry.d.ts +3 -0
- package/dist/brain/retry.d.ts.map +1 -0
- package/dist/brain/retry.js +23 -0
- package/dist/brain/retry.js.map +1 -0
- package/dist/brain/routing.d.ts +7 -0
- package/dist/brain/routing.d.ts.map +1 -0
- package/dist/brain/routing.js +34 -0
- package/dist/brain/routing.js.map +1 -0
- package/dist/brain/status-sink.d.ts +27 -0
- package/dist/brain/status-sink.d.ts.map +1 -0
- package/dist/brain/status-sink.js +20 -0
- package/dist/brain/status-sink.js.map +1 -0
- package/dist/brain/stream-engine.d.ts +37 -0
- package/dist/brain/stream-engine.d.ts.map +1 -0
- package/dist/brain/stream-engine.js +295 -0
- package/dist/brain/stream-engine.js.map +1 -0
- package/dist/brain/timeout.d.ts +12 -0
- package/dist/brain/timeout.d.ts.map +1 -0
- package/dist/brain/timeout.js +34 -0
- package/dist/brain/timeout.js.map +1 -0
- package/dist/brain/tool-call-repair.d.ts +6 -0
- package/dist/brain/tool-call-repair.d.ts.map +1 -0
- package/dist/brain/tool-call-repair.js +58 -0
- package/dist/brain/tool-call-repair.js.map +1 -0
- package/dist/brain/walltime.d.ts +2 -0
- package/dist/brain/walltime.d.ts.map +1 -0
- package/dist/brain/walltime.js +2 -0
- package/dist/brain/walltime.js.map +1 -0
- package/dist/core/arg-summary.d.ts +3 -0
- package/dist/core/arg-summary.d.ts.map +1 -0
- package/dist/core/arg-summary.js +76 -0
- package/dist/core/arg-summary.js.map +1 -0
- package/dist/core/ask-question.d.ts +36 -0
- package/dist/core/ask-question.d.ts.map +1 -0
- package/dist/core/ask-question.js +171 -0
- package/dist/core/ask-question.js.map +1 -0
- package/dist/core/auto-compaction.d.ts +88 -0
- package/dist/core/auto-compaction.d.ts.map +1 -0
- package/dist/core/auto-compaction.js +253 -0
- package/dist/core/auto-compaction.js.map +1 -0
- package/dist/core/auto-mode-prompt-assets.d.ts +3 -0
- package/dist/core/auto-mode-prompt-assets.d.ts.map +1 -0
- package/dist/core/auto-mode-prompt-assets.js +3 -0
- package/dist/core/auto-mode-prompt-assets.js.map +1 -0
- package/dist/core/auto-mode-prompt.d.ts +22 -0
- package/dist/core/auto-mode-prompt.d.ts.map +1 -0
- package/dist/core/auto-mode-prompt.js +84 -0
- package/dist/core/auto-mode-prompt.js.map +1 -0
- package/dist/core/auto-mode.d.ts +35 -0
- package/dist/core/auto-mode.d.ts.map +1 -0
- package/dist/core/auto-mode.js +100 -0
- package/dist/core/auto-mode.js.map +1 -0
- package/dist/core/auto-promote.d.ts +26 -0
- package/dist/core/auto-promote.d.ts.map +1 -0
- package/dist/core/auto-promote.js +93 -0
- package/dist/core/auto-promote.js.map +1 -0
- package/dist/core/background-shell.d.ts +41 -0
- package/dist/core/background-shell.d.ts.map +1 -0
- package/dist/core/background-shell.js +21 -0
- package/dist/core/background-shell.js.map +1 -0
- package/dist/core/cache-break-detector.d.ts +29 -0
- package/dist/core/cache-break-detector.d.ts.map +1 -0
- package/dist/core/cache-break-detector.js +80 -0
- package/dist/core/cache-break-detector.js.map +1 -0
- package/dist/core/canonical-json.d.ts +3 -0
- package/dist/core/canonical-json.d.ts.map +1 -0
- package/dist/core/canonical-json.js +68 -0
- package/dist/core/canonical-json.js.map +1 -0
- package/dist/core/checkpoint-store.d.ts +257 -0
- package/dist/core/checkpoint-store.d.ts.map +1 -0
- package/dist/core/checkpoint-store.js +292 -0
- package/dist/core/checkpoint-store.js.map +1 -0
- package/dist/core/consolidate-scope.d.ts +19 -0
- package/dist/core/consolidate-scope.d.ts.map +1 -0
- package/dist/core/consolidate-scope.js +96 -0
- package/dist/core/consolidate-scope.js.map +1 -0
- package/dist/core/context-edit.d.ts +18 -0
- package/dist/core/context-edit.d.ts.map +1 -0
- package/dist/core/context-edit.js +98 -0
- package/dist/core/context-edit.js.map +1 -0
- package/dist/core/context-guard.d.ts +14 -0
- package/dist/core/context-guard.d.ts.map +1 -0
- package/dist/core/context-guard.js +110 -0
- package/dist/core/context-guard.js.map +1 -0
- package/dist/core/dynamic-recall.d.ts +33 -0
- package/dist/core/dynamic-recall.d.ts.map +1 -0
- package/dist/core/dynamic-recall.js +77 -0
- package/dist/core/dynamic-recall.js.map +1 -0
- package/dist/core/exec-gate.d.ts +30 -0
- package/dist/core/exec-gate.d.ts.map +1 -0
- package/dist/core/exec-gate.js +106 -0
- package/dist/core/exec-gate.js.map +1 -0
- package/dist/core/exec-output-tail.d.ts +15 -0
- package/dist/core/exec-output-tail.d.ts.map +1 -0
- package/dist/core/exec-output-tail.js +39 -0
- package/dist/core/exec-output-tail.js.map +1 -0
- package/dist/core/file-snapshot-store.d.ts +53 -0
- package/dist/core/file-snapshot-store.d.ts.map +1 -0
- package/dist/core/file-snapshot-store.js +244 -0
- package/dist/core/file-snapshot-store.js.map +1 -0
- package/dist/core/git-worktree-env.d.ts +16 -0
- package/dist/core/git-worktree-env.d.ts.map +1 -0
- package/dist/core/git-worktree-env.js +40 -0
- package/dist/core/git-worktree-env.js.map +1 -0
- package/dist/core/hooks.d.ts +128 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/hooks.js +184 -0
- package/dist/core/hooks.js.map +1 -0
- package/dist/core/lsp-diagnostics.d.ts +31 -0
- package/dist/core/lsp-diagnostics.d.ts.map +1 -0
- package/dist/core/lsp-diagnostics.js +79 -0
- package/dist/core/lsp-diagnostics.js.map +1 -0
- package/dist/core/lsp-protocol.d.ts +10 -0
- package/dist/core/lsp-protocol.d.ts.map +1 -0
- package/dist/core/lsp-protocol.js +136 -0
- package/dist/core/lsp-protocol.js.map +1 -0
- package/dist/core/lsp-session.d.ts +27 -0
- package/dist/core/lsp-session.d.ts.map +1 -0
- package/dist/core/lsp-session.js +134 -0
- package/dist/core/lsp-session.js.map +1 -0
- package/dist/core/lsp.d.ts +56 -0
- package/dist/core/lsp.d.ts.map +1 -0
- package/dist/core/lsp.js +130 -0
- package/dist/core/lsp.js.map +1 -0
- package/dist/core/mcp.d.ts +108 -0
- package/dist/core/mcp.d.ts.map +1 -0
- package/dist/core/mcp.js +692 -0
- package/dist/core/mcp.js.map +1 -0
- package/dist/core/media-byte-cap.d.ts +13 -0
- package/dist/core/media-byte-cap.d.ts.map +1 -0
- package/dist/core/media-byte-cap.js +51 -0
- package/dist/core/media-byte-cap.js.map +1 -0
- package/dist/core/memory-engine/data-plane.d.ts +60 -0
- package/dist/core/memory-engine/data-plane.d.ts.map +1 -0
- package/dist/core/memory-engine/data-plane.js +198 -0
- package/dist/core/memory-engine/data-plane.js.map +1 -0
- package/dist/core/memory-engine/dual-root.d.ts +16 -0
- package/dist/core/memory-engine/dual-root.d.ts.map +1 -0
- package/dist/core/memory-engine/dual-root.js +75 -0
- package/dist/core/memory-engine/dual-root.js.map +1 -0
- package/dist/core/memory-engine/engine.d.ts +67 -0
- package/dist/core/memory-engine/engine.d.ts.map +1 -0
- package/dist/core/memory-engine/engine.js +828 -0
- package/dist/core/memory-engine/engine.js.map +1 -0
- package/dist/core/memory-engine/file-backend.d.ts +55 -0
- package/dist/core/memory-engine/file-backend.d.ts.map +1 -0
- package/dist/core/memory-engine/file-backend.js +752 -0
- package/dist/core/memory-engine/file-backend.js.map +1 -0
- package/dist/core/memory-engine/frontmatter.d.ts +13 -0
- package/dist/core/memory-engine/frontmatter.d.ts.map +1 -0
- package/dist/core/memory-engine/frontmatter.js +119 -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 +12 -0
- package/dist/core/memory-engine/index.js.map +1 -0
- package/dist/core/memory-engine/layout.d.ts +44 -0
- package/dist/core/memory-engine/layout.d.ts.map +1 -0
- package/dist/core/memory-engine/layout.js +459 -0
- package/dist/core/memory-engine/layout.js.map +1 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts +10 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts.map +1 -0
- package/dist/core/memory-engine/memory-backend-contract.js +269 -0
- package/dist/core/memory-engine/memory-backend-contract.js.map +1 -0
- package/dist/core/memory-engine/migrate.d.ts +8 -0
- package/dist/core/memory-engine/migrate.d.ts.map +1 -0
- package/dist/core/memory-engine/migrate.js +23 -0
- package/dist/core/memory-engine/migrate.js.map +1 -0
- package/dist/core/memory-engine/scan.d.ts +8 -0
- package/dist/core/memory-engine/scan.d.ts.map +1 -0
- package/dist/core/memory-engine/scan.js +49 -0
- package/dist/core/memory-engine/scan.js.map +1 -0
- package/dist/core/memory-engine/scope-contract.d.ts +44 -0
- package/dist/core/memory-engine/scope-contract.d.ts.map +1 -0
- package/dist/core/memory-engine/scope-contract.js +205 -0
- package/dist/core/memory-engine/scope-contract.js.map +1 -0
- package/dist/core/memory-engine/sync-client.d.ts +57 -0
- package/dist/core/memory-engine/sync-client.d.ts.map +1 -0
- package/dist/core/memory-engine/sync-client.js +257 -0
- package/dist/core/memory-engine/sync-client.js.map +1 -0
- package/dist/core/memory-engine/sync.d.ts +37 -0
- package/dist/core/memory-engine/sync.d.ts.map +1 -0
- package/dist/core/memory-engine/sync.js +68 -0
- package/dist/core/memory-engine/sync.js.map +1 -0
- package/dist/core/memory-engine/types.d.ts +128 -0
- package/dist/core/memory-engine/types.d.ts.map +1 -0
- package/dist/core/memory-engine/types.js +2 -0
- package/dist/core/memory-engine/types.js.map +1 -0
- package/dist/core/memory-recall.d.ts +82 -0
- package/dist/core/memory-recall.d.ts.map +1 -0
- package/dist/core/memory-recall.js +352 -0
- package/dist/core/memory-recall.js.map +1 -0
- package/dist/core/memory-vector.d.ts +4 -0
- package/dist/core/memory-vector.d.ts.map +1 -0
- package/dist/core/memory-vector.js +31 -0
- package/dist/core/memory-vector.js.map +1 -0
- package/dist/core/memory.d.ts +112 -0
- package/dist/core/memory.d.ts.map +1 -0
- package/dist/core/memory.js +512 -0
- package/dist/core/memory.js.map +1 -0
- package/dist/core/message-utils.d.ts +4 -0
- package/dist/core/message-utils.d.ts.map +1 -0
- package/dist/core/message-utils.js +7 -0
- package/dist/core/message-utils.js.map +1 -0
- package/dist/core/oracle-isolation.d.ts +16 -0
- package/dist/core/oracle-isolation.d.ts.map +1 -0
- package/dist/core/oracle-isolation.js +50 -0
- package/dist/core/oracle-isolation.js.map +1 -0
- package/dist/core/permission-rules.d.ts +35 -0
- package/dist/core/permission-rules.d.ts.map +1 -0
- package/dist/core/permission-rules.js +270 -0
- package/dist/core/permission-rules.js.map +1 -0
- package/dist/core/present-plan-tool.d.ts +8 -0
- package/dist/core/present-plan-tool.d.ts.map +1 -0
- package/dist/core/present-plan-tool.js +82 -0
- package/dist/core/present-plan-tool.js.map +1 -0
- package/dist/core/pricing.d.ts +22 -0
- package/dist/core/pricing.d.ts.map +1 -0
- package/dist/core/pricing.js +23 -0
- package/dist/core/pricing.js.map +1 -0
- package/dist/core/property-harness.d.ts +40 -0
- package/dist/core/property-harness.d.ts.map +1 -0
- package/dist/core/property-harness.js +121 -0
- package/dist/core/property-harness.js.map +1 -0
- package/dist/core/push-queue.d.ts +9 -0
- package/dist/core/push-queue.d.ts.map +1 -0
- package/dist/core/push-queue.js +41 -0
- package/dist/core/push-queue.js.map +1 -0
- package/dist/core/remote-env.d.ts +105 -0
- package/dist/core/remote-env.d.ts.map +1 -0
- package/dist/core/remote-env.js +27 -0
- package/dist/core/remote-env.js.map +1 -0
- package/dist/core/roles.d.ts +35 -0
- package/dist/core/roles.d.ts.map +1 -0
- package/dist/core/roles.js +182 -0
- package/dist/core/roles.js.map +1 -0
- package/dist/core/runner/active-skill-scope.d.ts +26 -0
- package/dist/core/runner/active-skill-scope.d.ts.map +1 -0
- package/dist/core/runner/active-skill-scope.js +116 -0
- package/dist/core/runner/active-skill-scope.js.map +1 -0
- package/dist/core/runner/assemble-result.d.ts +89 -0
- package/dist/core/runner/assemble-result.d.ts.map +1 -0
- package/dist/core/runner/assemble-result.js +141 -0
- package/dist/core/runner/assemble-result.js.map +1 -0
- package/dist/core/runner/call-cap.d.ts +38 -0
- package/dist/core/runner/call-cap.d.ts.map +1 -0
- package/dist/core/runner/call-cap.js +76 -0
- package/dist/core/runner/call-cap.js.map +1 -0
- package/dist/core/runner/grounding-signal.d.ts +2 -0
- package/dist/core/runner/grounding-signal.d.ts.map +1 -0
- package/dist/core/runner/grounding-signal.js +32 -0
- package/dist/core/runner/grounding-signal.js.map +1 -0
- package/dist/core/runner/image.d.ts +6 -0
- package/dist/core/runner/image.d.ts.map +1 -0
- package/dist/core/runner/image.js +116 -0
- package/dist/core/runner/image.js.map +1 -0
- package/dist/core/runner/memory-consolidation.d.ts +52 -0
- package/dist/core/runner/memory-consolidation.d.ts.map +1 -0
- package/dist/core/runner/memory-consolidation.js +253 -0
- package/dist/core/runner/memory-consolidation.js.map +1 -0
- package/dist/core/runner/prepare-task.d.ts +219 -0
- package/dist/core/runner/prepare-task.d.ts.map +1 -0
- package/dist/core/runner/prepare-task.js +2087 -0
- package/dist/core/runner/prepare-task.js.map +1 -0
- package/dist/core/runner/prompt-suggestions.d.ts +26 -0
- package/dist/core/runner/prompt-suggestions.d.ts.map +1 -0
- package/dist/core/runner/prompt-suggestions.js +104 -0
- package/dist/core/runner/prompt-suggestions.js.map +1 -0
- package/dist/core/runner/runtask.d.ts +53 -0
- package/dist/core/runner/runtask.d.ts.map +1 -0
- package/dist/core/runner/runtask.js +2703 -0
- package/dist/core/runner/runtask.js.map +1 -0
- package/dist/core/runner/session-rule-policy.d.ts +11 -0
- package/dist/core/runner/session-rule-policy.d.ts.map +1 -0
- package/dist/core/runner/session-rule-policy.js +76 -0
- package/dist/core/runner/session-rule-policy.js.map +1 -0
- package/dist/core/runner/strict-output-schema.d.ts +21 -0
- package/dist/core/runner/strict-output-schema.d.ts.map +1 -0
- package/dist/core/runner/strict-output-schema.js +304 -0
- package/dist/core/runner/strict-output-schema.js.map +1 -0
- package/dist/core/runner/synthetic-tools.d.ts +30 -0
- package/dist/core/runner/synthetic-tools.d.ts.map +1 -0
- package/dist/core/runner/synthetic-tools.js +124 -0
- package/dist/core/runner/synthetic-tools.js.map +1 -0
- package/dist/core/runner/tool-disclosure.d.ts +46 -0
- package/dist/core/runner/tool-disclosure.d.ts.map +1 -0
- package/dist/core/runner/tool-disclosure.js +220 -0
- package/dist/core/runner/tool-disclosure.js.map +1 -0
- package/dist/core/runner/turn-attachments.d.ts +110 -0
- package/dist/core/runner/turn-attachments.d.ts.map +1 -0
- package/dist/core/runner/turn-attachments.js +334 -0
- package/dist/core/runner/turn-attachments.js.map +1 -0
- package/dist/core/runner/usage-accounting.d.ts +19 -0
- package/dist/core/runner/usage-accounting.d.ts.map +1 -0
- package/dist/core/runner/usage-accounting.js +30 -0
- package/dist/core/runner/usage-accounting.js.map +1 -0
- package/dist/core/runtime.d.ts +4 -0
- package/dist/core/runtime.d.ts.map +1 -0
- package/dist/core/runtime.js +12 -0
- package/dist/core/runtime.js.map +1 -0
- package/dist/core/safety-axis-vocab.d.ts +10 -0
- package/dist/core/safety-axis-vocab.d.ts.map +1 -0
- package/dist/core/safety-axis-vocab.js +12 -0
- package/dist/core/safety-axis-vocab.js.map +1 -0
- package/dist/core/safety-merge-corpus.d.ts +11 -0
- package/dist/core/safety-merge-corpus.d.ts.map +1 -0
- package/dist/core/safety-merge-corpus.js +195 -0
- package/dist/core/safety-merge-corpus.js.map +1 -0
- package/dist/core/scheduler.d.ts +55 -0
- package/dist/core/scheduler.d.ts.map +1 -0
- package/dist/core/scheduler.js +32 -0
- package/dist/core/scheduler.js.map +1 -0
- package/dist/core/secret-env.d.ts +3 -0
- package/dist/core/secret-env.d.ts.map +1 -0
- package/dist/core/secret-env.js +13 -0
- package/dist/core/secret-env.js.map +1 -0
- package/dist/core/select-model.d.ts +11 -0
- package/dist/core/select-model.d.ts.map +1 -0
- package/dist/core/select-model.js +44 -0
- package/dist/core/select-model.js.map +1 -0
- package/dist/core/sensitive-path-policy.d.ts +9 -0
- package/dist/core/sensitive-path-policy.d.ts.map +1 -0
- package/dist/core/sensitive-path-policy.js +61 -0
- package/dist/core/sensitive-path-policy.js.map +1 -0
- package/dist/core/session-policy-store.d.ts +38 -0
- package/dist/core/session-policy-store.d.ts.map +1 -0
- package/dist/core/session-policy-store.js +112 -0
- package/dist/core/session-policy-store.js.map +1 -0
- package/dist/core/session-reconcile.d.ts +15 -0
- package/dist/core/session-reconcile.d.ts.map +1 -0
- package/dist/core/session-reconcile.js +48 -0
- package/dist/core/session-reconcile.js.map +1 -0
- package/dist/core/session-store.d.ts +36 -0
- package/dist/core/session-store.d.ts.map +1 -0
- package/dist/core/session-store.js +192 -0
- package/dist/core/session-store.js.map +1 -0
- package/dist/core/session.d.ts +44 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/session.js +27 -0
- package/dist/core/session.js.map +1 -0
- package/dist/core/spec-contract.d.ts +58 -0
- package/dist/core/spec-contract.d.ts.map +1 -0
- package/dist/core/spec-contract.js +256 -0
- package/dist/core/spec-contract.js.map +1 -0
- package/dist/core/strategy-store.d.ts +25 -0
- package/dist/core/strategy-store.d.ts.map +1 -0
- package/dist/core/strategy-store.js +81 -0
- package/dist/core/strategy-store.js.map +1 -0
- package/dist/core/stub-env.d.ts +28 -0
- package/dist/core/stub-env.d.ts.map +1 -0
- package/dist/core/stub-env.js +61 -0
- package/dist/core/stub-env.js.map +1 -0
- package/dist/core/task-notification.d.ts +56 -0
- package/dist/core/task-notification.d.ts.map +1 -0
- package/dist/core/task-notification.js +200 -0
- package/dist/core/task-notification.js.map +1 -0
- package/dist/core/task-outcome.d.ts +27 -0
- package/dist/core/task-outcome.d.ts.map +1 -0
- package/dist/core/task-outcome.js +12 -0
- package/dist/core/task-outcome.js.map +1 -0
- package/dist/core/task-registry.d.ts +188 -0
- package/dist/core/task-registry.d.ts.map +1 -0
- package/dist/core/task-registry.js +1443 -0
- package/dist/core/task-registry.js.map +1 -0
- package/dist/core/tighten-task-spec.d.ts +6 -0
- package/dist/core/tighten-task-spec.d.ts.map +1 -0
- package/dist/core/tighten-task-spec.js +50 -0
- package/dist/core/tighten-task-spec.js.map +1 -0
- package/dist/core/tool-detach.d.ts +10 -0
- package/dist/core/tool-detach.d.ts.map +1 -0
- package/dist/core/tool-detach.js +41 -0
- package/dist/core/tool-detach.js.map +1 -0
- package/dist/core/tool-errors.d.ts +8 -0
- package/dist/core/tool-errors.d.ts.map +1 -0
- package/dist/core/tool-errors.js +132 -0
- package/dist/core/tool-errors.js.map +1 -0
- package/dist/core/tool-name-aliases.d.ts +3 -0
- package/dist/core/tool-name-aliases.d.ts.map +1 -0
- package/dist/core/tool-name-aliases.js +60 -0
- package/dist/core/tool-name-aliases.js.map +1 -0
- package/dist/core/tool-policy.d.ts +75 -0
- package/dist/core/tool-policy.d.ts.map +1 -0
- package/dist/core/tool-policy.js +363 -0
- package/dist/core/tool-policy.js.map +1 -0
- package/dist/core/tool-result-budget.d.ts +17 -0
- package/dist/core/tool-result-budget.d.ts.map +1 -0
- package/dist/core/tool-result-budget.js +103 -0
- package/dist/core/tool-result-budget.js.map +1 -0
- package/dist/core/tool-result-store.d.ts +55 -0
- package/dist/core/tool-result-store.d.ts.map +1 -0
- package/dist/core/tool-result-store.js +154 -0
- package/dist/core/tool-result-store.js.map +1 -0
- package/dist/core/tools.d.ts +6 -0
- package/dist/core/tools.d.ts.map +1 -0
- package/dist/core/tools.js +61 -0
- package/dist/core/tools.js.map +1 -0
- package/dist/core/trace.d.ts +208 -0
- package/dist/core/trace.d.ts.map +1 -0
- package/dist/core/trace.js +10 -0
- package/dist/core/trace.js.map +1 -0
- package/dist/core/types.d.ts +684 -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 +7 -0
- package/dist/core/untrusted-egress.d.ts.map +1 -0
- package/dist/core/untrusted-egress.js +23 -0
- package/dist/core/untrusted-egress.js.map +1 -0
- package/dist/core/untrusted-text.d.ts +5 -0
- package/dist/core/untrusted-text.d.ts.map +1 -0
- package/dist/core/untrusted-text.js +36 -0
- package/dist/core/untrusted-text.js.map +1 -0
- package/dist/core/warm-resume.d.ts +6 -0
- package/dist/core/warm-resume.d.ts.map +1 -0
- package/dist/core/warm-resume.js +11 -0
- package/dist/core/warm-resume.js.map +1 -0
- package/dist/core/with-retry.d.ts +19 -0
- package/dist/core/with-retry.d.ts.map +1 -0
- package/dist/core/with-retry.js +36 -0
- package/dist/core/with-retry.js.map +1 -0
- package/dist/core/workflow-journal-store.d.ts +16 -0
- package/dist/core/workflow-journal-store.d.ts.map +1 -0
- package/dist/core/workflow-journal-store.js +34 -0
- package/dist/core/workflow-journal-store.js.map +1 -0
- package/dist/core/workflow-run-store-contract.d.ts +6 -0
- package/dist/core/workflow-run-store-contract.d.ts.map +1 -0
- package/dist/core/workflow-run-store-contract.js +144 -0
- package/dist/core/workflow-run-store-contract.js.map +1 -0
- package/dist/core/workflow-run-store.d.ts +54 -0
- package/dist/core/workflow-run-store.d.ts.map +1 -0
- package/dist/core/workflow-run-store.js +86 -0
- package/dist/core/workflow-run-store.js.map +1 -0
- package/dist/engine/compaction/compaction.d.ts +63 -0
- package/dist/engine/compaction/compaction.d.ts.map +1 -0
- package/dist/engine/compaction/compaction.js +770 -0
- package/dist/engine/compaction/compaction.js.map +1 -0
- package/dist/engine/compaction/utils.d.ts +19 -0
- package/dist/engine/compaction/utils.d.ts.map +1 -0
- package/dist/engine/compaction/utils.js +167 -0
- package/dist/engine/compaction/utils.js.map +1 -0
- package/dist/engine/execution-env/kill-tree.d.ts +10 -0
- package/dist/engine/execution-env/kill-tree.d.ts.map +1 -0
- package/dist/engine/execution-env/kill-tree.js +143 -0
- package/dist/engine/execution-env/kill-tree.js.map +1 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +98 -0
- package/dist/engine/execution-env/node-execution-env.d.ts.map +1 -0
- package/dist/engine/execution-env/node-execution-env.js +945 -0
- package/dist/engine/execution-env/node-execution-env.js.map +1 -0
- package/dist/engine/harness/agent-harness.d.ts +112 -0
- package/dist/engine/harness/agent-harness.d.ts.map +1 -0
- package/dist/engine/harness/agent-harness.js +932 -0
- package/dist/engine/harness/agent-harness.js.map +1 -0
- package/dist/engine/harness/messages.d.ts +12 -0
- package/dist/engine/harness/messages.d.ts.map +1 -0
- package/dist/engine/harness/messages.js +102 -0
- package/dist/engine/harness/messages.js.map +1 -0
- package/dist/engine/harness/types.d.ts +484 -0
- package/dist/engine/harness/types.d.ts.map +1 -0
- package/dist/engine/harness/types.js +91 -0
- package/dist/engine/harness/types.js.map +1 -0
- package/dist/engine/llm/diagnostics.d.ts +19 -0
- package/dist/engine/llm/diagnostics.d.ts.map +1 -0
- package/dist/engine/llm/diagnostics.js +28 -0
- package/dist/engine/llm/diagnostics.js.map +1 -0
- package/dist/engine/llm/event-stream.d.ts +22 -0
- package/dist/engine/llm/event-stream.d.ts.map +1 -0
- package/dist/engine/llm/event-stream.js +91 -0
- package/dist/engine/llm/event-stream.js.map +1 -0
- package/dist/engine/llm/index.d.ts +5 -0
- package/dist/engine/llm/index.d.ts.map +1 -0
- package/dist/engine/llm/index.js +5 -0
- package/dist/engine/llm/index.js.map +1 -0
- package/dist/engine/llm/types.d.ts +359 -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 +5 -0
- package/dist/engine/llm/validation.d.ts.map +1 -0
- package/dist/engine/llm/validation.js +293 -0
- package/dist/engine/llm/validation.js.map +1 -0
- package/dist/engine/loop/agent-loop.d.ts +19 -0
- package/dist/engine/loop/agent-loop.d.ts.map +1 -0
- package/dist/engine/loop/agent-loop.js +1087 -0
- package/dist/engine/loop/agent-loop.js.map +1 -0
- package/dist/engine/loop/runtime-deps.d.ts +10 -0
- package/dist/engine/loop/runtime-deps.d.ts.map +1 -0
- package/dist/engine/loop/runtime-deps.js +19 -0
- package/dist/engine/loop/runtime-deps.js.map +1 -0
- package/dist/engine/loop/types.d.ts +209 -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 +3 -0
- package/dist/engine/lsp/frame-decoder.d.ts.map +1 -0
- package/dist/engine/lsp/frame-decoder.js +36 -0
- package/dist/engine/lsp/frame-decoder.js.map +1 -0
- package/dist/engine/lsp/node-lsp-manager.d.ts +49 -0
- package/dist/engine/lsp/node-lsp-manager.d.ts.map +1 -0
- package/dist/engine/lsp/node-lsp-manager.js +267 -0
- package/dist/engine/lsp/node-lsp-manager.js.map +1 -0
- package/dist/engine/lsp/stdio-lsp-transport.d.ts +32 -0
- package/dist/engine/lsp/stdio-lsp-transport.d.ts.map +1 -0
- package/dist/engine/lsp/stdio-lsp-transport.js +154 -0
- package/dist/engine/lsp/stdio-lsp-transport.js.map +1 -0
- package/dist/engine/session/import-validate.d.ts +13 -0
- package/dist/engine/session/import-validate.d.ts.map +1 -0
- package/dist/engine/session/import-validate.js +56 -0
- package/dist/engine/session/import-validate.js.map +1 -0
- package/dist/engine/session/memory-repo.d.ts +20 -0
- package/dist/engine/session/memory-repo.d.ts.map +1 -0
- package/dist/engine/session/memory-repo.js +54 -0
- package/dist/engine/session/memory-repo.js.map +1 -0
- package/dist/engine/session/memory-storage.d.ts +12 -0
- package/dist/engine/session/memory-storage.d.ts.map +1 -0
- package/dist/engine/session/memory-storage.js +16 -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 +27 -0
- package/dist/engine/session/session.d.ts.map +1 -0
- package/dist/engine/session/session.js +197 -0
- package/dist/engine/session/session.js.map +1 -0
- package/dist/engine/session/storage-base.d.ts +30 -0
- package/dist/engine/session/storage-base.d.ts.map +1 -0
- package/dist/engine/session/storage-base.js +138 -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 +156 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +141 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/harness.d.ts +19 -0
- package/dist/internal/harness.d.ts.map +1 -0
- package/dist/internal/harness.js +13 -0
- package/dist/internal/harness.js.map +1 -0
- package/dist/internal/llm.d.ts +3 -0
- package/dist/internal/llm.d.ts.map +1 -0
- package/dist/internal/llm.js +2 -0
- package/dist/internal/llm.js.map +1 -0
- package/dist/orchestration/builtin-workflows.d.ts +11 -0
- package/dist/orchestration/builtin-workflows.d.ts.map +1 -0
- package/dist/orchestration/builtin-workflows.js +134 -0
- package/dist/orchestration/builtin-workflows.js.map +1 -0
- package/dist/orchestration/dev-vm-script-runner.d.ts +5 -0
- package/dist/orchestration/dev-vm-script-runner.d.ts.map +1 -0
- package/dist/orchestration/dev-vm-script-runner.js +68 -0
- package/dist/orchestration/dev-vm-script-runner.js.map +1 -0
- package/dist/orchestration/goal.d.ts +40 -0
- package/dist/orchestration/goal.d.ts.map +1 -0
- package/dist/orchestration/goal.js +190 -0
- package/dist/orchestration/goal.js.map +1 -0
- package/dist/orchestration/run-spec.d.ts +21 -0
- package/dist/orchestration/run-spec.d.ts.map +1 -0
- package/dist/orchestration/run-spec.js +201 -0
- package/dist/orchestration/run-spec.js.map +1 -0
- package/dist/orchestration/run-workflow-tool.d.ts +80 -0
- package/dist/orchestration/run-workflow-tool.d.ts.map +1 -0
- package/dist/orchestration/run-workflow-tool.js +431 -0
- package/dist/orchestration/run-workflow-tool.js.map +1 -0
- package/dist/orchestration/workflow-governance.d.ts +30 -0
- package/dist/orchestration/workflow-governance.d.ts.map +1 -0
- package/dist/orchestration/workflow-governance.js +125 -0
- package/dist/orchestration/workflow-governance.js.map +1 -0
- package/dist/orchestration/workflow-meta.d.ts +13 -0
- package/dist/orchestration/workflow-meta.d.ts.map +1 -0
- package/dist/orchestration/workflow-meta.js +367 -0
- package/dist/orchestration/workflow-meta.js.map +1 -0
- package/dist/orchestration/workflow-observe.d.ts +18 -0
- package/dist/orchestration/workflow-observe.d.ts.map +1 -0
- package/dist/orchestration/workflow-observe.js +73 -0
- package/dist/orchestration/workflow-observe.js.map +1 -0
- package/dist/orchestration/workflow-primitives.d.ts +12 -0
- package/dist/orchestration/workflow-primitives.d.ts.map +1 -0
- package/dist/orchestration/workflow-primitives.js +56 -0
- package/dist/orchestration/workflow-primitives.js.map +1 -0
- package/dist/orchestration/workflow-sandbox-conformance.d.ts +5 -0
- package/dist/orchestration/workflow-sandbox-conformance.d.ts.map +1 -0
- package/dist/orchestration/workflow-sandbox-conformance.js +220 -0
- package/dist/orchestration/workflow-sandbox-conformance.js.map +1 -0
- package/dist/orchestration/workflow-script-runner.d.ts +39 -0
- package/dist/orchestration/workflow-script-runner.d.ts.map +1 -0
- package/dist/orchestration/workflow-script-runner.js +23 -0
- package/dist/orchestration/workflow-script-runner.js.map +1 -0
- package/dist/orchestration/workflow-script-store.d.ts +20 -0
- package/dist/orchestration/workflow-script-store.d.ts.map +1 -0
- package/dist/orchestration/workflow-script-store.js +73 -0
- package/dist/orchestration/workflow-script-store.js.map +1 -0
- package/dist/orchestration/workflow-size-guideline.d.ts +10 -0
- package/dist/orchestration/workflow-size-guideline.d.ts.map +1 -0
- package/dist/orchestration/workflow-size-guideline.js +38 -0
- package/dist/orchestration/workflow-size-guideline.js.map +1 -0
- package/dist/orchestration/workflow.d.ts +281 -0
- package/dist/orchestration/workflow.d.ts.map +1 -0
- package/dist/orchestration/workflow.js +1095 -0
- package/dist/orchestration/workflow.js.map +1 -0
- package/dist/prompts/default.d.ts +104 -0
- package/dist/prompts/default.d.ts.map +1 -0
- package/dist/prompts/default.js +397 -0
- package/dist/prompts/default.js.map +1 -0
- package/dist/prompts/supervisor.d.ts +5 -0
- package/dist/prompts/supervisor.d.ts.map +1 -0
- package/dist/prompts/supervisor.js +107 -0
- package/dist/prompts/supervisor.js.map +1 -0
- package/dist/scenarios/env.d.ts +13 -0
- package/dist/scenarios/env.d.ts.map +1 -0
- package/dist/scenarios/env.js +40 -0
- package/dist/scenarios/env.js.map +1 -0
- package/dist/scenarios/full-body.d.ts +13 -0
- package/dist/scenarios/full-body.d.ts.map +1 -0
- package/dist/scenarios/full-body.js +20 -0
- package/dist/scenarios/full-body.js.map +1 -0
- package/dist/scenarios/scenario-registry.d.ts +47 -0
- package/dist/scenarios/scenario-registry.d.ts.map +1 -0
- package/dist/scenarios/scenario-registry.js +139 -0
- package/dist/scenarios/scenario-registry.js.map +1 -0
- package/dist/scenarios/teacher-quickstart.d.ts +14 -0
- package/dist/scenarios/teacher-quickstart.d.ts.map +1 -0
- package/dist/scenarios/teacher-quickstart.js +13 -0
- package/dist/scenarios/teacher-quickstart.js.map +1 -0
- package/dist/server/http.d.ts +19 -0
- package/dist/server/http.d.ts.map +1 -0
- package/dist/server/http.js +115 -0
- package/dist/server/http.js.map +1 -0
- package/dist/stores/file/checkpoint-store.d.ts +40 -0
- package/dist/stores/file/checkpoint-store.d.ts.map +1 -0
- package/dist/stores/file/checkpoint-store.js +198 -0
- package/dist/stores/file/checkpoint-store.js.map +1 -0
- package/dist/stores/file/file-snapshot-store.d.ts +25 -0
- package/dist/stores/file/file-snapshot-store.d.ts.map +1 -0
- package/dist/stores/file/file-snapshot-store.js +313 -0
- package/dist/stores/file/file-snapshot-store.js.map +1 -0
- package/dist/stores/file/fs-atomic.d.ts +24 -0
- package/dist/stores/file/fs-atomic.d.ts.map +1 -0
- package/dist/stores/file/fs-atomic.js +276 -0
- package/dist/stores/file/fs-atomic.js.map +1 -0
- package/dist/stores/file/index.d.ts +45 -0
- package/dist/stores/file/index.d.ts.map +1 -0
- package/dist/stores/file/index.js +77 -0
- package/dist/stores/file/index.js.map +1 -0
- package/dist/stores/file/memory-store.d.ts +35 -0
- package/dist/stores/file/memory-store.d.ts.map +1 -0
- package/dist/stores/file/memory-store.js +300 -0
- package/dist/stores/file/memory-store.js.map +1 -0
- package/dist/stores/file/session-policy-store.d.ts +11 -0
- package/dist/stores/file/session-policy-store.d.ts.map +1 -0
- package/dist/stores/file/session-policy-store.js +96 -0
- package/dist/stores/file/session-policy-store.js.map +1 -0
- package/dist/stores/file/session-store.d.ts +24 -0
- package/dist/stores/file/session-store.d.ts.map +1 -0
- package/dist/stores/file/session-store.js +134 -0
- package/dist/stores/file/session-store.js.map +1 -0
- package/dist/stores/file/tool-result-store.d.ts +12 -0
- package/dist/stores/file/tool-result-store.d.ts.map +1 -0
- package/dist/stores/file/tool-result-store.js +44 -0
- package/dist/stores/file/tool-result-store.js.map +1 -0
- package/dist/stores/file/workflow-journal-store.d.ts +17 -0
- package/dist/stores/file/workflow-journal-store.d.ts.map +1 -0
- package/dist/stores/file/workflow-journal-store.js +104 -0
- package/dist/stores/file/workflow-journal-store.js.map +1 -0
- package/dist/stores/file/workflow-run-store.d.ts +41 -0
- package/dist/stores/file/workflow-run-store.d.ts.map +1 -0
- package/dist/stores/file/workflow-run-store.js +147 -0
- package/dist/stores/file/workflow-run-store.js.map +1 -0
- package/dist/stores/pg.d.ts +96 -0
- package/dist/stores/pg.d.ts.map +1 -0
- package/dist/stores/pg.js +451 -0
- package/dist/stores/pg.js.map +1 -0
- package/dist/tools/fs/encoding.d.ts +16 -0
- package/dist/tools/fs/encoding.d.ts.map +1 -0
- package/dist/tools/fs/encoding.js +44 -0
- package/dist/tools/fs/encoding.js.map +1 -0
- package/dist/tools/fs/gh-rate-limit.d.ts +3 -0
- package/dist/tools/fs/gh-rate-limit.d.ts.map +1 -0
- package/dist/tools/fs/gh-rate-limit.js +16 -0
- package/dist/tools/fs/gh-rate-limit.js.map +1 -0
- package/dist/tools/fs/index.d.ts +74 -0
- package/dist/tools/fs/index.d.ts.map +1 -0
- package/dist/tools/fs/index.js +1576 -0
- package/dist/tools/fs/index.js.map +1 -0
- package/dist/tools/fs/pdf.d.ts +47 -0
- package/dist/tools/fs/pdf.d.ts.map +1 -0
- package/dist/tools/fs/pdf.js +124 -0
- package/dist/tools/fs/pdf.js.map +1 -0
- package/dist/tools/fs/repo-map.d.ts +5 -0
- package/dist/tools/fs/repo-map.d.ts.map +1 -0
- package/dist/tools/fs/repo-map.js +209 -0
- package/dist/tools/fs/repo-map.js.map +1 -0
- package/dist/tools/fs/safety.d.ts +52 -0
- package/dist/tools/fs/safety.d.ts.map +1 -0
- package/dist/tools/fs/safety.js +314 -0
- package/dist/tools/fs/safety.js.map +1 -0
- package/dist/tools/fs/search.d.ts +57 -0
- package/dist/tools/fs/search.d.ts.map +1 -0
- package/dist/tools/fs/search.js +574 -0
- package/dist/tools/fs/search.js.map +1 -0
- package/dist/tools/gitea-issue.d.ts +14 -0
- package/dist/tools/gitea-issue.d.ts.map +1 -0
- package/dist/tools/gitea-issue.js +74 -0
- package/dist/tools/gitea-issue.js.map +1 -0
- package/dist/tools/monitor.d.ts +20 -0
- package/dist/tools/monitor.d.ts.map +1 -0
- package/dist/tools/monitor.js +90 -0
- package/dist/tools/monitor.js.map +1 -0
- package/dist/tools/scheduler-tools.d.ts +15 -0
- package/dist/tools/scheduler-tools.d.ts.map +1 -0
- package/dist/tools/scheduler-tools.js +338 -0
- package/dist/tools/scheduler-tools.js.map +1 -0
- package/dist/tools/sql-adapters.d.ts +14 -0
- package/dist/tools/sql-adapters.d.ts.map +1 -0
- package/dist/tools/sql-adapters.js +13 -0
- package/dist/tools/sql-adapters.js.map +1 -0
- package/dist/tools/sql.d.ts +11 -0
- package/dist/tools/sql.d.ts.map +1 -0
- package/dist/tools/sql.js +104 -0
- package/dist/tools/sql.js.map +1 -0
- package/dist/tools/task-list.d.ts +14 -0
- package/dist/tools/task-list.d.ts.map +1 -0
- package/dist/tools/task-list.js +318 -0
- package/dist/tools/task-list.js.map +1 -0
- package/dist/tools/todo.d.ts +3 -0
- package/dist/tools/todo.d.ts.map +1 -0
- package/dist/tools/todo.js +97 -0
- package/dist/tools/todo.js.map +1 -0
- package/dist/tools/web.d.ts +26 -0
- package/dist/tools/web.d.ts.map +1 -0
- package/dist/tools/web.js +498 -0
- package/dist/tools/web.js.map +1 -0
- package/dist/tools/worktree.d.ts +18 -0
- package/dist/tools/worktree.d.ts.map +1 -0
- package/dist/tools/worktree.js +288 -0
- package/dist/tools/worktree.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,752 @@
|
|
|
1
|
+
import { lstatSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync, openSync, writeSync, fsyncSync, closeSync } from "node:fs";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { basename, dirname, join, relative } from "node:path";
|
|
4
|
+
import { jaccardDistance, termSet } from "../memory-vector.js";
|
|
5
|
+
import { MAX_MEMORY_BYTES } from "../memory.js";
|
|
6
|
+
import { inlineUntrusted } from "../untrusted-text.js";
|
|
7
|
+
import { computeEntryRev, entryFromFile, isValidEntryId, parseEntryFile, serializeEntryFile } from "./frontmatter.js";
|
|
8
|
+
import { ControlPlaneCorruptError, CURSORS_FILE, atomicWriteFileSync, claimRootScope, deriveControlPlaneDir, ensureDirExists, enqueueMemoryAnnouncement, registerScope, registeredScopes, resolveMemoryEngineRoot, scopeDirName, } from "./layout.js";
|
|
9
|
+
import { scanMemoryFileName, scanMemoryWrite } from "./scan.js";
|
|
10
|
+
export const MEMORY_INDEX_FILENAME = "MEMORY.md";
|
|
11
|
+
export const DEFAULT_MAX_ENTRY_DEPTH = 3;
|
|
12
|
+
export function scanEntryFiles(dir, opts = {}) {
|
|
13
|
+
const maxDepth = opts.maxDepth ?? DEFAULT_MAX_ENTRY_DEPTH;
|
|
14
|
+
const out = [];
|
|
15
|
+
const walk = (d, depth) => {
|
|
16
|
+
let names;
|
|
17
|
+
try {
|
|
18
|
+
names = readdirSync(d);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
for (const name of names.sort()) {
|
|
24
|
+
if (name.startsWith(".") || name === MEMORY_INDEX_FILENAME) {
|
|
25
|
+
if (name.startsWith("."))
|
|
26
|
+
opts.onSkip?.(join(d, name), "dotfile");
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const p = join(d, name);
|
|
30
|
+
let st;
|
|
31
|
+
try {
|
|
32
|
+
st = lstatSync(p);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (st.isSymbolicLink()) {
|
|
38
|
+
opts.onSkip?.(p, "symlink");
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (st.isDirectory()) {
|
|
42
|
+
if (depth === 0 && opts.exclude?.has(name))
|
|
43
|
+
continue;
|
|
44
|
+
if (depth + 1 <= maxDepth)
|
|
45
|
+
walk(p, depth + 1);
|
|
46
|
+
else
|
|
47
|
+
opts.onSkip?.(p, "depth");
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (!st.isFile())
|
|
51
|
+
continue;
|
|
52
|
+
if (!name.endsWith(".md")) {
|
|
53
|
+
opts.onSkip?.(p, "nonmd");
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
out.push({ path: p, slug: relative(dir, p).replace(/\.md$/, "") });
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
walk(dir, 0);
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
const LEDGER_FILE = "revs.json";
|
|
63
|
+
const JOURNAL_FILE = "journal.json";
|
|
64
|
+
const TXN_LOCK_STALE_MS = 30_000;
|
|
65
|
+
const TXN_LOCK_WAIT_MS = 15_000;
|
|
66
|
+
const TXN_LOCK_STEAL_GRACE_MS = 250;
|
|
67
|
+
const SHADOW_DIR = "shadow";
|
|
68
|
+
const QUARANTINE_DIR = "quarantine";
|
|
69
|
+
export class FileMemoryEngineBackend {
|
|
70
|
+
directoryRoot;
|
|
71
|
+
controlPlaneRoot;
|
|
72
|
+
now;
|
|
73
|
+
ledger;
|
|
74
|
+
inboundFindings = [];
|
|
75
|
+
batchScan;
|
|
76
|
+
constructor(dir, opts = {}) {
|
|
77
|
+
this.now = opts.now ?? Date.now;
|
|
78
|
+
this.directoryRoot = dir;
|
|
79
|
+
this.controlPlaneRoot = opts.controlDir ?? deriveControlPlaneDir(resolveMemoryEngineRoot(), dir);
|
|
80
|
+
ensureDirExists(dir);
|
|
81
|
+
ensureDirExists(this.controlPlaneRoot);
|
|
82
|
+
this.recoverJournal();
|
|
83
|
+
}
|
|
84
|
+
checkControlPlane() {
|
|
85
|
+
this.recoverJournal();
|
|
86
|
+
this.ledger = undefined;
|
|
87
|
+
this.loadLedger();
|
|
88
|
+
registeredScopes(this.controlPlaneRoot);
|
|
89
|
+
}
|
|
90
|
+
drainInboundFindings() {
|
|
91
|
+
const out = this.inboundFindings;
|
|
92
|
+
this.inboundFindings = [];
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
readCommittedShadow(id) {
|
|
96
|
+
return readSafe(this.shadowPath(id));
|
|
97
|
+
}
|
|
98
|
+
shadowPath(id) {
|
|
99
|
+
return join(this.controlPlaneRoot, SHADOW_DIR, `${id}.md`);
|
|
100
|
+
}
|
|
101
|
+
quarantineFile(path, content) {
|
|
102
|
+
const dest = join(this.controlPlaneRoot, QUARANTINE_DIR, `${Date.now()}-${basename(path)}`);
|
|
103
|
+
let captured;
|
|
104
|
+
let detail;
|
|
105
|
+
try {
|
|
106
|
+
ensureDirExists(dirname(dest));
|
|
107
|
+
writeFileSync(dest, content, "utf8");
|
|
108
|
+
captured = dest;
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
detail = `quarantine copy failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
112
|
+
}
|
|
113
|
+
let removed = false;
|
|
114
|
+
try {
|
|
115
|
+
rmSync(path, { force: true });
|
|
116
|
+
removed = true;
|
|
117
|
+
}
|
|
118
|
+
catch (rmErr) {
|
|
119
|
+
try {
|
|
120
|
+
writeFileSync(path, "---\ndeleted: true\n---\n", "utf8");
|
|
121
|
+
removed = true;
|
|
122
|
+
detail = `${detail !== undefined ? `${detail}; ` : ""}delete failed (${rmErr instanceof Error ? rmErr.message : String(rmErr)}) — tombstoned in place`;
|
|
123
|
+
}
|
|
124
|
+
catch (clearErr) {
|
|
125
|
+
detail = `${detail !== undefined ? `${detail}; ` : ""}suspect file could not be deleted or cleared: ${clearErr instanceof Error ? clearErr.message : String(clearErr)}`;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return { ...(captured !== undefined ? { dest: captured } : {}), removed, ...(detail !== undefined ? { detail } : {}) };
|
|
129
|
+
}
|
|
130
|
+
loadLedger() {
|
|
131
|
+
if (this.ledger)
|
|
132
|
+
return this.ledger;
|
|
133
|
+
const path = join(this.controlPlaneRoot, LEDGER_FILE);
|
|
134
|
+
let raw;
|
|
135
|
+
try {
|
|
136
|
+
raw = readFileSync(path, "utf8");
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
raw = undefined;
|
|
140
|
+
}
|
|
141
|
+
if (raw === undefined) {
|
|
142
|
+
this.ledger = {};
|
|
143
|
+
return this.ledger;
|
|
144
|
+
}
|
|
145
|
+
let parsed;
|
|
146
|
+
try {
|
|
147
|
+
parsed = JSON.parse(raw);
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
throw new ControlPlaneCorruptError(`committed-rev ledger is unparseable: ${path}`);
|
|
151
|
+
}
|
|
152
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
153
|
+
throw new ControlPlaneCorruptError(`committed-rev ledger has the wrong shape: ${path}`);
|
|
154
|
+
}
|
|
155
|
+
for (const [k, v] of Object.entries(parsed)) {
|
|
156
|
+
if (typeof v !== "string")
|
|
157
|
+
throw new ControlPlaneCorruptError(`committed-rev ledger entry ${JSON.stringify(k)} is not a string: ${path}`);
|
|
158
|
+
}
|
|
159
|
+
this.ledger = parsed;
|
|
160
|
+
return this.ledger;
|
|
161
|
+
}
|
|
162
|
+
saveLedger() {
|
|
163
|
+
if (!this.ledger)
|
|
164
|
+
return;
|
|
165
|
+
atomicWriteFileSync(join(this.controlPlaneRoot, LEDGER_FILE), `${JSON.stringify(this.ledger, null, 2)}\n`);
|
|
166
|
+
}
|
|
167
|
+
recoverJournal() {
|
|
168
|
+
const jp = join(this.controlPlaneRoot, JOURNAL_FILE);
|
|
169
|
+
const raw = readSafe(jp);
|
|
170
|
+
if (raw !== undefined) {
|
|
171
|
+
let journal;
|
|
172
|
+
try {
|
|
173
|
+
const parsed = JSON.parse(raw);
|
|
174
|
+
if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.ops) || typeof parsed.ledger !== "object") {
|
|
175
|
+
throw new Error("wrong shape");
|
|
176
|
+
}
|
|
177
|
+
journal = parsed;
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
throw new ControlPlaneCorruptError(`transaction journal is unparseable: ${jp}`);
|
|
181
|
+
}
|
|
182
|
+
for (const op of journal.ops) {
|
|
183
|
+
try {
|
|
184
|
+
if (op.kind === "write" && op.content !== undefined) {
|
|
185
|
+
atomicWriteFileSync(op.target, op.content);
|
|
186
|
+
if (op.staged)
|
|
187
|
+
rmSync(op.staged, { force: true });
|
|
188
|
+
}
|
|
189
|
+
else if (op.kind === "delete") {
|
|
190
|
+
rmSync(op.target, { force: true });
|
|
191
|
+
}
|
|
192
|
+
else if (op.kind === "shadow-write" && op.content !== undefined) {
|
|
193
|
+
atomicWriteFileSync(this.shadowPath(op.target), op.content);
|
|
194
|
+
}
|
|
195
|
+
else if (op.kind === "shadow-delete") {
|
|
196
|
+
rmSync(this.shadowPath(op.target), { force: true });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
this.ledger = { ...journal.ledger };
|
|
203
|
+
this.saveLedger();
|
|
204
|
+
rmSync(jp, { force: true });
|
|
205
|
+
}
|
|
206
|
+
this.sweepStagedFiles();
|
|
207
|
+
}
|
|
208
|
+
sweepStagedFiles() {
|
|
209
|
+
const walk = (d, depth) => {
|
|
210
|
+
let names;
|
|
211
|
+
try {
|
|
212
|
+
names = readdirSync(d);
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
for (const name of names) {
|
|
218
|
+
const p = join(d, name);
|
|
219
|
+
if (name.startsWith(".stage-")) {
|
|
220
|
+
rmSync(p, { force: true });
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (depth < DEFAULT_MAX_ENTRY_DEPTH + 1) {
|
|
224
|
+
try {
|
|
225
|
+
if (lstatSync(p).isDirectory())
|
|
226
|
+
walk(p, depth + 1);
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
walk(this.directoryRoot, 0);
|
|
234
|
+
}
|
|
235
|
+
excludedSubdirNames(forScope) {
|
|
236
|
+
const reg = registeredScopes(this.controlPlaneRoot);
|
|
237
|
+
const names = new Set();
|
|
238
|
+
for (const [scope, dirName] of Object.entries(reg)) {
|
|
239
|
+
if (scope !== forScope && dirName !== "")
|
|
240
|
+
names.add(dirName);
|
|
241
|
+
}
|
|
242
|
+
return names;
|
|
243
|
+
}
|
|
244
|
+
scopeDir(scope) {
|
|
245
|
+
return registerScope(this.directoryRoot, this.controlPlaneRoot, scope);
|
|
246
|
+
}
|
|
247
|
+
inboundGate(relPath, text) {
|
|
248
|
+
const nameFinding = scanMemoryFileName(relPath);
|
|
249
|
+
if (nameFinding !== undefined)
|
|
250
|
+
return { path: relPath, code: "filename", reason: `inbound memory change blocked: ${nameFinding.reason} (quarantined)` };
|
|
251
|
+
const findings = scanMemoryWrite(text, { maxBytes: MAX_MEMORY_BYTES });
|
|
252
|
+
const first = findings[0];
|
|
253
|
+
if (first !== undefined) {
|
|
254
|
+
return { path: relPath, code: first.code, reason: `inbound memory change blocked: ${first.reason} (quarantined)` };
|
|
255
|
+
}
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
readScope(scope, sync = true) {
|
|
259
|
+
if (!sync && this.batchScan !== undefined) {
|
|
260
|
+
const memo = this.batchScan.get(scope);
|
|
261
|
+
if (memo !== undefined)
|
|
262
|
+
return memo;
|
|
263
|
+
}
|
|
264
|
+
const dir = this.scopeDir(scope);
|
|
265
|
+
const isRoot = dir === this.directoryRoot;
|
|
266
|
+
const files = scanEntryFiles(dir, { exclude: isRoot ? this.excludedSubdirNames(scope) : undefined });
|
|
267
|
+
const entries = [];
|
|
268
|
+
const ledger = sync ? this.loadLedger() : undefined;
|
|
269
|
+
let ledgerChanged = false;
|
|
270
|
+
const adoptedExternal = [];
|
|
271
|
+
for (const f of files) {
|
|
272
|
+
let text;
|
|
273
|
+
try {
|
|
274
|
+
text = readFileSync(f.path, "utf8");
|
|
275
|
+
}
|
|
276
|
+
catch {
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
const parsed = parseEntryFile(text);
|
|
280
|
+
if (parsed.id === undefined)
|
|
281
|
+
continue;
|
|
282
|
+
let entry = entryFromFile(text, parsed.id, f.slug, scope);
|
|
283
|
+
if (ledger) {
|
|
284
|
+
const committed = ledger[entry.id];
|
|
285
|
+
if (committed !== entry.rev) {
|
|
286
|
+
const finding = this.inboundGate(relative(this.directoryRoot, f.path), text);
|
|
287
|
+
if (finding) {
|
|
288
|
+
this.inboundFindings.push(finding);
|
|
289
|
+
const q = this.quarantineFile(f.path, text);
|
|
290
|
+
const shadowText = committed !== undefined ? this.readCommittedShadow(entry.id) : undefined;
|
|
291
|
+
let restoredShadow = false;
|
|
292
|
+
if (shadowText !== undefined) {
|
|
293
|
+
try {
|
|
294
|
+
atomicWriteFileSync(f.path, shadowText);
|
|
295
|
+
restoredShadow = true;
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
}
|
|
299
|
+
entry = entryFromFile(shadowText, entry.id, f.slug, scope);
|
|
300
|
+
}
|
|
301
|
+
if (q.detail !== undefined || (!q.removed && !restoredShadow)) {
|
|
302
|
+
const contained = q.removed || restoredShadow;
|
|
303
|
+
this.inboundFindings.push({
|
|
304
|
+
path: finding.path,
|
|
305
|
+
code: "quarantine_failed",
|
|
306
|
+
reason: `quarantine escalation: ${q.detail ?? "suspect copy not captured"}${contained ? "" : " — rejected content may still be on the model-visible plane"}`,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (shadowText === undefined) {
|
|
310
|
+
if (committed !== undefined) {
|
|
311
|
+
delete ledger[entry.id];
|
|
312
|
+
ledgerChanged = true;
|
|
313
|
+
}
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
if (committed !== undefined)
|
|
319
|
+
adoptedExternal.push(relative(this.directoryRoot, f.path));
|
|
320
|
+
ledger[entry.id] = entry.rev;
|
|
321
|
+
try {
|
|
322
|
+
atomicWriteFileSync(this.shadowPath(entry.id), text);
|
|
323
|
+
}
|
|
324
|
+
catch {
|
|
325
|
+
}
|
|
326
|
+
ledgerChanged = true;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
else if (this.readCommittedShadow(entry.id) === undefined) {
|
|
330
|
+
try {
|
|
331
|
+
atomicWriteFileSync(this.shadowPath(entry.id), text);
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
entries.push(entry);
|
|
338
|
+
}
|
|
339
|
+
if (ledgerChanged)
|
|
340
|
+
this.saveLedger();
|
|
341
|
+
if (adoptedExternal.length > 0) {
|
|
342
|
+
try {
|
|
343
|
+
enqueueMemoryAnnouncement(this.controlPlaneRoot, {
|
|
344
|
+
kind: "external",
|
|
345
|
+
at: this.now(),
|
|
346
|
+
items: adoptedExternal
|
|
347
|
+
.slice(0, 12)
|
|
348
|
+
.map((rel) => `out-of-session memory change adopted: ${JSON.stringify(inlineUntrusted(rel))} — re-read it before relying on prior knowledge of it`)
|
|
349
|
+
.concat(adoptedExternal.length > 12 ? [`…and ${adoptedExternal.length - 12} more adopted change(s)`] : []),
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
catch {
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
if (!sync && this.batchScan !== undefined)
|
|
356
|
+
this.batchScan.set(scope, entries);
|
|
357
|
+
return entries;
|
|
358
|
+
}
|
|
359
|
+
async listHeaders(scopes) {
|
|
360
|
+
const out = [];
|
|
361
|
+
for (const scope of scopes) {
|
|
362
|
+
const dir = this.scopeDir(scope);
|
|
363
|
+
for (const e of this.readScope(scope)) {
|
|
364
|
+
out.push(headerOf(e, join(dir, `${e.slug}.md`)));
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return out;
|
|
368
|
+
}
|
|
369
|
+
async getByIds(ids) {
|
|
370
|
+
const want = new Set(ids);
|
|
371
|
+
const out = [];
|
|
372
|
+
for (const scope of Object.keys(registeredScopes(this.controlPlaneRoot))) {
|
|
373
|
+
for (const e of this.readScope(scope)) {
|
|
374
|
+
if (want.has(e.id))
|
|
375
|
+
out.push(e);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return out;
|
|
379
|
+
}
|
|
380
|
+
async search(query, scopes, opts) {
|
|
381
|
+
const limit = opts?.limit ?? 20;
|
|
382
|
+
const q = termSet(query);
|
|
383
|
+
if (q.size === 0)
|
|
384
|
+
return [];
|
|
385
|
+
const scored = [];
|
|
386
|
+
for (const scope of scopes) {
|
|
387
|
+
const dir = this.scopeDir(scope);
|
|
388
|
+
for (const e of this.readScope(scope)) {
|
|
389
|
+
const haystack = `${e.frontmatter.name ?? e.slug} ${e.frontmatter.description ?? ""} ${e.body}`;
|
|
390
|
+
const d = jaccardDistance(q, haystack);
|
|
391
|
+
if (d === null)
|
|
392
|
+
continue;
|
|
393
|
+
scored.push({ ...headerOf(e, join(dir, `${e.slug}.md`)), score: d });
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
scored.sort((a, b) => a.score - b.score || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
397
|
+
return scored.slice(0, limit);
|
|
398
|
+
}
|
|
399
|
+
async applyPatches(patches) {
|
|
400
|
+
const lock = await this.acquireTxnLock();
|
|
401
|
+
try {
|
|
402
|
+
return await this.applyPatchesLocked(patches, lock.token);
|
|
403
|
+
}
|
|
404
|
+
finally {
|
|
405
|
+
lock.release();
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
txnLockDir() {
|
|
409
|
+
return join(this.controlPlaneRoot, "txn.lock");
|
|
410
|
+
}
|
|
411
|
+
async acquireTxnLock(timings = {}) {
|
|
412
|
+
const staleMs = timings.staleMs ?? TXN_LOCK_STALE_MS;
|
|
413
|
+
const waitMs = timings.waitMs ?? TXN_LOCK_WAIT_MS;
|
|
414
|
+
const stealGraceMs = timings.stealGraceMs ?? TXN_LOCK_STEAL_GRACE_MS;
|
|
415
|
+
const lockDir = this.txnLockDir();
|
|
416
|
+
const ownerPath = join(lockDir, "owner");
|
|
417
|
+
mkdirSync(this.controlPlaneRoot, { recursive: true });
|
|
418
|
+
const start = Date.now();
|
|
419
|
+
let deadline = start + waitMs;
|
|
420
|
+
for (;;) {
|
|
421
|
+
let acquired = false;
|
|
422
|
+
try {
|
|
423
|
+
mkdirSync(lockDir);
|
|
424
|
+
acquired = true;
|
|
425
|
+
}
|
|
426
|
+
catch (err) {
|
|
427
|
+
if (err.code !== "EEXIST")
|
|
428
|
+
throw err;
|
|
429
|
+
}
|
|
430
|
+
if (acquired) {
|
|
431
|
+
const token = randomUUID();
|
|
432
|
+
try {
|
|
433
|
+
const fd = openSync(ownerPath, "w", 0o600);
|
|
434
|
+
try {
|
|
435
|
+
writeSync(fd, token);
|
|
436
|
+
fsyncSync(fd);
|
|
437
|
+
}
|
|
438
|
+
finally {
|
|
439
|
+
closeSync(fd);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
catch (err) {
|
|
443
|
+
try {
|
|
444
|
+
rmSync(lockDir, { recursive: true, force: true });
|
|
445
|
+
}
|
|
446
|
+
catch {
|
|
447
|
+
}
|
|
448
|
+
throw new Error(`memory txn lock owner token could not be written at ${ownerPath}: ${err instanceof Error ? err.message : String(err)}`);
|
|
449
|
+
}
|
|
450
|
+
return {
|
|
451
|
+
token,
|
|
452
|
+
release: () => {
|
|
453
|
+
try {
|
|
454
|
+
if (readFileSync(ownerPath, "utf8") !== token)
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
catch {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
try {
|
|
461
|
+
rmSync(lockDir, { recursive: true, force: true });
|
|
462
|
+
}
|
|
463
|
+
catch {
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
let mtimeMs;
|
|
469
|
+
try {
|
|
470
|
+
mtimeMs = statSync(lockDir).mtimeMs;
|
|
471
|
+
}
|
|
472
|
+
catch {
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
const staleAt = mtimeMs + staleMs;
|
|
476
|
+
deadline = Math.max(deadline, staleAt + stealGraceMs);
|
|
477
|
+
if (Date.now() > staleAt) {
|
|
478
|
+
let tokenPresent = false;
|
|
479
|
+
try {
|
|
480
|
+
statSync(ownerPath);
|
|
481
|
+
tokenPresent = true;
|
|
482
|
+
}
|
|
483
|
+
catch {
|
|
484
|
+
}
|
|
485
|
+
if (tokenPresent) {
|
|
486
|
+
const tomb = join(this.controlPlaneRoot, `txn.lock.stale-${randomUUID()}`);
|
|
487
|
+
try {
|
|
488
|
+
renameSync(lockDir, tomb);
|
|
489
|
+
}
|
|
490
|
+
catch {
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
493
|
+
rmSync(tomb, { recursive: true, force: true });
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
if (Date.now() > deadline) {
|
|
498
|
+
throw new Error(`memory txn lock timeout (${waitMs}ms, extended to the lock's stale line) at ${lockDir} — another writer is wedged?`);
|
|
499
|
+
}
|
|
500
|
+
await new Promise((r) => setTimeout(r, 20 + Math.floor(Math.random() * 40)));
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
assertTxnLockOwnership(token) {
|
|
504
|
+
let held;
|
|
505
|
+
try {
|
|
506
|
+
held = readFileSync(join(this.txnLockDir(), "owner"), "utf8");
|
|
507
|
+
}
|
|
508
|
+
catch {
|
|
509
|
+
held = undefined;
|
|
510
|
+
}
|
|
511
|
+
if (held !== token) {
|
|
512
|
+
throw new ControlPlaneCorruptError("txn lock ownership lost before commit (holder stalled past the stale deadline and was stolen from?) — transaction aborted, nothing was committed");
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
async applyPatchesLocked(patches, lockToken) {
|
|
516
|
+
this.ledger = undefined;
|
|
517
|
+
this.recoverJournal();
|
|
518
|
+
const ledger = { ...this.loadLedger() };
|
|
519
|
+
const report = { applied: [], conflicts: [] };
|
|
520
|
+
const ops = [];
|
|
521
|
+
const plannedTargets = new Set();
|
|
522
|
+
const nonDeleteIds = new Set();
|
|
523
|
+
const plannedDeletes = new Set();
|
|
524
|
+
this.batchScan = new Map();
|
|
525
|
+
try {
|
|
526
|
+
for (const patch of patches) {
|
|
527
|
+
try {
|
|
528
|
+
if (patch.op !== "delete") {
|
|
529
|
+
if (patch.entry !== undefined && patch.entry.id !== patch.id) {
|
|
530
|
+
report.conflicts.push({ op: patch.op, id: patch.id, reason: `patch id ${JSON.stringify(patch.id)} != entry id ${JSON.stringify(patch.entry.id)} (malformed patch refused)` });
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
if (nonDeleteIds.has(patch.id)) {
|
|
534
|
+
report.conflicts.push({ op: patch.op, id: patch.id, reason: "duplicate id in batch: another add/update for this id is already planned (copied file keeping its frontmatter id?)" });
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
nonDeleteIds.add(patch.id);
|
|
538
|
+
}
|
|
539
|
+
this.planOne(patch, report, ops, ledger, plannedTargets, plannedDeletes);
|
|
540
|
+
}
|
|
541
|
+
catch (err) {
|
|
542
|
+
report.conflicts.push({ op: patch.op, id: patch.id, reason: `io error: ${err instanceof Error ? err.message : String(err)}` });
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
finally {
|
|
547
|
+
this.batchScan = undefined;
|
|
548
|
+
}
|
|
549
|
+
if (ops.length === 0) {
|
|
550
|
+
return report;
|
|
551
|
+
}
|
|
552
|
+
const txn = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
553
|
+
let n = 0;
|
|
554
|
+
for (const op of ops) {
|
|
555
|
+
if (op.kind !== "write" || op.content === undefined)
|
|
556
|
+
continue;
|
|
557
|
+
const staged = join(dirname(op.target), `.stage-${txn}-${n++}`);
|
|
558
|
+
mkdirSync(dirname(op.target), { recursive: true });
|
|
559
|
+
const fd = openSync(staged, "w", 0o600);
|
|
560
|
+
try {
|
|
561
|
+
writeSync(fd, op.content);
|
|
562
|
+
fsyncSync(fd);
|
|
563
|
+
}
|
|
564
|
+
finally {
|
|
565
|
+
closeSync(fd);
|
|
566
|
+
}
|
|
567
|
+
op.staged = staged;
|
|
568
|
+
}
|
|
569
|
+
this.assertTxnLockOwnership(lockToken);
|
|
570
|
+
const journal = { txn, ops, ledger };
|
|
571
|
+
atomicWriteFileSync(join(this.controlPlaneRoot, JOURNAL_FILE), JSON.stringify(journal));
|
|
572
|
+
for (const op of ops) {
|
|
573
|
+
if (op.kind === "write" && op.staged) {
|
|
574
|
+
renameSync(op.staged, op.target);
|
|
575
|
+
}
|
|
576
|
+
else if (op.kind === "delete") {
|
|
577
|
+
rmSync(op.target, { force: true });
|
|
578
|
+
}
|
|
579
|
+
else if (op.kind === "shadow-write" && op.content !== undefined) {
|
|
580
|
+
atomicWriteFileSync(this.shadowPath(op.target), op.content);
|
|
581
|
+
}
|
|
582
|
+
else if (op.kind === "shadow-delete") {
|
|
583
|
+
rmSync(this.shadowPath(op.target), { force: true });
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
this.ledger = ledger;
|
|
587
|
+
this.saveLedger();
|
|
588
|
+
rmSync(join(this.controlPlaneRoot, JOURNAL_FILE), { force: true });
|
|
589
|
+
return report;
|
|
590
|
+
}
|
|
591
|
+
planOne(patch, report, ops, ledger, plannedTargets, plannedDeletes) {
|
|
592
|
+
if (!isValidEntryId(patch.id)) {
|
|
593
|
+
report.conflicts.push({ op: patch.op, id: patch.id, reason: `invalid_id_shape (id ${JSON.stringify(patch.id)} fails the frontmatter id contract — the read side would drop it, leaving an applied-but-invisible entry)` });
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
if (patch.op === "add") {
|
|
597
|
+
const entry = patch.entry;
|
|
598
|
+
if (!entry) {
|
|
599
|
+
report.conflicts.push({ op: "add", id: patch.id, reason: "add patch without an entry" });
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
const locatedAnywhere = this.locateById(patch.id);
|
|
603
|
+
const existingAnywhere = locatedAnywhere !== undefined && plannedDeletes.has(patch.id) ? undefined : locatedAnywhere;
|
|
604
|
+
if (patch.guard === "absent") {
|
|
605
|
+
if (existingAnywhere) {
|
|
606
|
+
const currentRev = ledger[patch.id] ?? existingAnywhere.entry.rev;
|
|
607
|
+
if (currentRev !== computeEntryRev(entry)) {
|
|
608
|
+
report.conflicts.push({ op: "add", id: patch.id, reason: "add_guard_absent_conflict (id already exists at a different rev; add-if-absent refuses to overwrite)", currentRev });
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
if (existingAnywhere.entry.scope !== entry.scope || existingAnywhere.entry.slug !== entry.slug) {
|
|
612
|
+
report.conflicts.push({
|
|
613
|
+
op: "add",
|
|
614
|
+
id: patch.id,
|
|
615
|
+
reason: `add_guard_absent_conflict (id already exists at the same rev but a different projection ${JSON.stringify(`${existingAnywhere.entry.scope}/${existingAnywhere.entry.slug}`)}; add-if-absent refuses to duplicate)`,
|
|
616
|
+
currentRev,
|
|
617
|
+
});
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
if (existingAnywhere !== undefined && existingAnywhere.entry.scope !== entry.scope) {
|
|
623
|
+
report.conflicts.push({ op: "add", id: patch.id, reason: `id already exists in scope ${JSON.stringify(existingAnywhere.entry.scope)} (cross-scope add refused)` });
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
if (existingAnywhere !== undefined && existingAnywhere.entry.slug !== entry.slug) {
|
|
627
|
+
ops.push({ kind: "delete", target: existingAnywhere.path });
|
|
628
|
+
}
|
|
629
|
+
claimRootScope(this.controlPlaneRoot, entry.scope);
|
|
630
|
+
const dir = this.scopeDir(entry.scope);
|
|
631
|
+
let slug = entry.slug;
|
|
632
|
+
let target = join(dir, `${slug}.md`);
|
|
633
|
+
for (let n = 2;; n++) {
|
|
634
|
+
const existing = plannedTargets.has(target) ? "" : readSafe(target);
|
|
635
|
+
if (existing === undefined)
|
|
636
|
+
break;
|
|
637
|
+
if (existing !== "") {
|
|
638
|
+
const parsed = parseEntryFile(existing);
|
|
639
|
+
if (parsed.id === undefined || parsed.id === entry.id)
|
|
640
|
+
break;
|
|
641
|
+
}
|
|
642
|
+
slug = `${entry.slug}-${n}`;
|
|
643
|
+
target = join(dir, `${slug}.md`);
|
|
644
|
+
}
|
|
645
|
+
const content = serializeEntryFile(entry);
|
|
646
|
+
plannedTargets.add(target);
|
|
647
|
+
ops.push({ kind: "write", target, content });
|
|
648
|
+
ops.push({ kind: "shadow-write", target: entry.id, content });
|
|
649
|
+
ledger[entry.id] = computeEntryRev(entry);
|
|
650
|
+
report.applied.push({ op: "add", id: entry.id, slug });
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
const found = this.locateById(patch.id, patch.op === "update" ? patch.entry?.scope : undefined);
|
|
654
|
+
if (!found) {
|
|
655
|
+
report.conflicts.push({ op: patch.op, id: patch.id, reason: "unknown id (entry not found in backend)" });
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
const currentRev = ledger[patch.id] ?? found.entry.rev;
|
|
659
|
+
if (patch.baseRev !== undefined && patch.baseRev !== currentRev) {
|
|
660
|
+
report.conflicts.push({ op: patch.op, id: patch.id, reason: "rev mismatch (concurrent change)", baseRev: patch.baseRev, currentRev });
|
|
661
|
+
const shadowText = this.readCommittedShadow(patch.id);
|
|
662
|
+
if (shadowText !== undefined && shadowText !== serializeEntryFile(found.entry)) {
|
|
663
|
+
ops.push({ kind: "write", target: found.path, content: shadowText });
|
|
664
|
+
}
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
if (patch.op === "delete") {
|
|
668
|
+
ops.push({ kind: "delete", target: found.path });
|
|
669
|
+
ops.push({ kind: "shadow-delete", target: patch.id });
|
|
670
|
+
delete ledger[patch.id];
|
|
671
|
+
plannedDeletes.add(patch.id);
|
|
672
|
+
report.applied.push({ op: "delete", id: patch.id, slug: found.entry.slug });
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
const entry = patch.entry;
|
|
676
|
+
if (!entry) {
|
|
677
|
+
report.conflicts.push({ op: "update", id: patch.id, reason: "update patch without an entry" });
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
const dir = this.scopeDir(entry.scope);
|
|
681
|
+
const target = join(dir, `${entry.slug}.md`);
|
|
682
|
+
const content = serializeEntryFile(entry);
|
|
683
|
+
if (target !== found.path)
|
|
684
|
+
ops.push({ kind: "delete", target: found.path });
|
|
685
|
+
plannedTargets.add(target);
|
|
686
|
+
ops.push({ kind: "write", target, content });
|
|
687
|
+
ops.push({ kind: "shadow-write", target: entry.id, content });
|
|
688
|
+
ledger[entry.id] = computeEntryRev(entry);
|
|
689
|
+
report.applied.push({ op: "update", id: entry.id, slug: entry.slug });
|
|
690
|
+
}
|
|
691
|
+
locateById(id, preferScope) {
|
|
692
|
+
const scopes = Object.keys(registeredScopes(this.controlPlaneRoot));
|
|
693
|
+
const ordered = preferScope !== undefined ? [preferScope, ...scopes.filter((s) => s !== preferScope)] : scopes;
|
|
694
|
+
for (const scope of ordered) {
|
|
695
|
+
const dir = this.scopeDir(scope);
|
|
696
|
+
for (const e of this.readScope(scope, false)) {
|
|
697
|
+
if (e.id === id)
|
|
698
|
+
return { entry: e, path: join(dir, `${e.slug}.md`) };
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
return undefined;
|
|
702
|
+
}
|
|
703
|
+
async getConsolidationCursor(scope) {
|
|
704
|
+
const cursors = this.readCursors();
|
|
705
|
+
return cursors[scope];
|
|
706
|
+
}
|
|
707
|
+
async setConsolidationCursor(scope, cursor) {
|
|
708
|
+
const cursors = this.readCursors();
|
|
709
|
+
cursors[scope] = cursor;
|
|
710
|
+
atomicWriteFileSync(join(this.controlPlaneRoot, CURSORS_FILE), `${JSON.stringify(cursors, null, 2)}\n`);
|
|
711
|
+
}
|
|
712
|
+
readCursors() {
|
|
713
|
+
try {
|
|
714
|
+
const parsed = JSON.parse(readFileSync(join(this.controlPlaneRoot, CURSORS_FILE), "utf8"));
|
|
715
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
716
|
+
return Object.fromEntries(Object.entries(parsed).filter(([, v]) => typeof v === "string"));
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
catch {
|
|
720
|
+
}
|
|
721
|
+
return {};
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
function headerOf(e, path) {
|
|
725
|
+
let mtimeMs = 0;
|
|
726
|
+
try {
|
|
727
|
+
mtimeMs = statSync(path).mtimeMs;
|
|
728
|
+
}
|
|
729
|
+
catch {
|
|
730
|
+
}
|
|
731
|
+
return {
|
|
732
|
+
id: e.id,
|
|
733
|
+
slug: e.slug,
|
|
734
|
+
scope: e.scope,
|
|
735
|
+
...(e.frontmatter.name !== undefined ? { name: e.frontmatter.name } : {}),
|
|
736
|
+
...(e.frontmatter.description !== undefined ? { description: e.frontmatter.description } : {}),
|
|
737
|
+
...(e.frontmatter.type !== undefined ? { type: e.frontmatter.type } : {}),
|
|
738
|
+
mtimeMs,
|
|
739
|
+
rev: e.rev,
|
|
740
|
+
sizeBytes: Buffer.byteLength(serializeEntryFile(e), "utf8"),
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
function readSafe(path) {
|
|
744
|
+
try {
|
|
745
|
+
return readFileSync(path, "utf8");
|
|
746
|
+
}
|
|
747
|
+
catch {
|
|
748
|
+
return undefined;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
export { scopeDirName };
|
|
752
|
+
//# sourceMappingURL=file-backend.js.map
|