@sema-agent/core 7.48.0 → 7.49.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 +457 -0
- package/README.md +2 -2
- package/dist/agents/cascade.d.ts +2 -5
- package/dist/agents/child-failure.d.ts +20 -0
- package/dist/agents/child-failure.js +28 -0
- package/dist/agents/cross-session-ref.d.ts +11 -3
- package/dist/agents/cross-session-ref.js +6 -0
- package/dist/agents/cumulative-stats.d.ts +12 -15
- package/dist/agents/cumulative-stats.js +1 -1
- package/dist/agents/extra-tool-names.js +1 -1
- package/dist/agents/inherited-tool-pool.d.ts +17 -13
- package/dist/agents/inherited-tool-pool.js +4 -3
- package/dist/agents/peer-session-drain.d.ts +3 -2
- package/dist/agents/peer-session-drain.js +5 -4
- package/dist/agents/send-message-tool.js +2 -9
- package/dist/agents/subagent.d.ts +10 -29
- package/dist/agents/subagent.js +65 -53
- package/dist/agents/suspend-guard.d.ts +1 -1
- package/dist/agents/tool-filter.d.ts +76 -65
- package/dist/agents/tool-filter.js +122 -92
- package/dist/agents/verify.d.ts +4 -7
- package/dist/agents/verify.js +6 -7
- package/dist/bench/metrics.d.ts +1 -2
- package/dist/brain/anthropic.js +133 -79
- package/dist/brain/errors.d.ts +53 -6
- package/dist/brain/errors.js +22 -2
- package/dist/brain/input-too-long.d.ts +40 -19
- package/dist/brain/input-too-long.js +3 -16
- package/dist/brain/open-responses.js +19 -10
- package/dist/brain/openai.js +123 -32
- package/dist/brain/provider-dialect.d.ts +214 -0
- package/dist/brain/provider-dialect.js +186 -0
- package/dist/brain/request-params.d.ts +27 -8
- package/dist/brain/request-params.js +7 -12
- package/dist/brain/request-route.d.ts +84 -0
- package/dist/brain/request-route.js +41 -0
- package/dist/brain/retry.d.ts +8 -0
- package/dist/brain/retry.js +10 -4
- package/dist/brain/route-adjudicator.d.ts +7 -0
- package/dist/brain/route-adjudicator.js +5 -1
- package/dist/brain/status-sink.d.ts +20 -0
- package/dist/brain/status-sink.js +11 -0
- package/dist/brain/stream-engine.d.ts +52 -1
- package/dist/brain/stream-engine.js +81 -24
- package/dist/brain/stream-shared.d.ts +57 -11
- package/dist/brain/stream-shared.js +28 -2
- package/dist/core/a2a.d.ts +1 -0
- package/dist/core/agent-config-dir.js +3 -2
- package/dist/core/allow-entry.d.ts +21 -12
- package/dist/core/allow-entry.js +38 -31
- package/dist/core/arg-summary.d.ts +21 -28
- package/dist/core/arg-summary.js +235 -88
- package/dist/core/ask-origin.d.ts +42 -24
- package/dist/core/ask-origin.js +18 -13
- package/dist/core/auto-mode-prompt-assets.d.ts +2 -2
- package/dist/core/auto-mode-prompt-assets.js +1 -1
- package/dist/core/auto-mode-prompt.d.ts +11 -1
- package/dist/core/auto-mode-prompt.js +13 -10
- package/dist/core/auto-mode-rebuild.d.ts +7 -0
- package/dist/core/auto-mode-rebuild.js +4 -1
- package/dist/core/canonical-json.d.ts +3 -0
- package/dist/core/canonical-json.js +2 -1
- package/dist/core/checkpoint-requirements.d.ts +892 -0
- package/dist/core/checkpoint-requirements.js +333 -0
- package/dist/core/checkpoint-store.d.ts +94 -65
- package/dist/core/checkpoint-store.js +14 -26
- package/dist/core/child-clamp-seats.d.ts +228 -69
- package/dist/core/child-clamp-seats.js +211 -17
- package/dist/core/classifier-unavailable-arm.d.ts +5 -1
- package/dist/core/classifier-unavailable-arm.js +3 -3
- package/dist/core/compliance.d.ts +3 -0
- package/dist/core/compliance.js +9 -4
- package/dist/core/credential-vocabulary.d.ts +140 -0
- package/dist/core/credential-vocabulary.js +131 -0
- package/dist/core/decision-receipt.js +1 -1
- package/dist/core/effective-path-target.d.ts +73 -16
- package/dist/core/effective-path-target.js +63 -33
- package/dist/core/engine-notice.d.ts +43 -11
- package/dist/core/file-history-store.js +2 -2
- package/dist/core/fs-write-gate-policy.d.ts +4 -0
- package/dist/core/fs-write-gate-policy.js +22 -5
- package/dist/core/gate-bounded-await.d.ts +28 -13
- package/dist/core/gate-bounded-await.js +41 -4
- package/dist/core/gate-fold.d.ts +1 -1
- package/dist/core/gate-fold.js +24 -25
- package/dist/core/gate-lanes.js +16 -15
- package/dist/core/gate-outcome.d.ts +20 -5
- package/dist/core/gate-outcome.js +5 -0
- package/dist/core/governance-codes.d.ts +11 -4
- package/dist/core/governance-codes.js +14 -3
- package/dist/core/hooks.d.ts +21 -0
- package/dist/core/locked-config.d.ts +8 -0
- package/dist/core/locked-config.js +14 -2
- package/dist/core/lsp.js +3 -5
- package/dist/core/mailbox-store.d.ts +3 -4
- package/dist/core/mcp-connection-pool.d.ts +75 -0
- package/dist/core/mcp-connection-pool.js +128 -0
- package/dist/core/mcp-failure.d.ts +2 -1
- package/dist/core/mcp-failure.js +13 -2
- package/dist/core/mcp.d.ts +4 -0
- package/dist/core/mcp.js +70 -43
- package/dist/core/memory-engine/content-origin.js +2 -14
- package/dist/core/memory-engine/engine.d.ts +32 -22
- package/dist/core/memory-engine/engine.js +103 -55
- package/dist/core/memory-engine/file-backend.d.ts +13 -30
- package/dist/core/memory-engine/file-backend.js +37 -252
- package/dist/core/memory-engine/index.d.ts +1 -1
- package/dist/core/memory-engine/index.js +1 -1
- package/dist/core/memory-engine/layout.d.ts +139 -9
- package/dist/core/memory-engine/layout.js +350 -7
- package/dist/core/memory-engine/scope-contract.d.ts +10 -0
- package/dist/core/memory-engine/scope-contract.js +8 -0
- package/dist/core/memory-engine/session-incarnation.d.ts +14 -4
- package/dist/core/memory-engine/session-incarnation.js +5 -2
- package/dist/core/memory-engine/types.d.ts +10 -1
- package/dist/core/memory.js +5 -17
- package/dist/core/model-seat.d.ts +4 -4
- package/dist/core/model-seat.js +1 -1
- package/dist/core/mounted-mcp.d.ts +57 -0
- package/dist/core/mounted-mcp.js +19 -0
- package/dist/core/namespaced-rule-name.d.ts +29 -0
- package/dist/core/namespaced-rule-name.js +52 -0
- package/dist/core/park-selfcheck.d.ts +1 -1
- package/dist/core/park-selfcheck.js +16 -6
- package/dist/core/path-guard-rows.d.ts +99 -0
- package/dist/core/path-guard-rows.js +45 -0
- package/dist/core/path-identity.d.ts +22 -16
- package/dist/core/path-identity.js +10 -10
- package/dist/core/path-rule-binding.d.ts +2 -1
- package/dist/core/path-rule-binding.js +3 -1
- package/dist/core/pause-registry.d.ts +16 -2
- package/dist/core/pause-registry.js +6 -0
- package/dist/core/permission-rule-consent.js +0 -7
- package/dist/core/permission-rule-model.d.ts +68 -24
- package/dist/core/permission-rule-model.js +105 -24
- package/dist/core/permission-rule-store.js +2 -2
- package/dist/core/permission-rules.d.ts +3 -30
- package/dist/core/permission-rules.js +4 -54
- package/dist/core/read-root-candidate.d.ts +1 -3
- package/dist/core/read-root-candidate.js +4 -15
- package/dist/core/real-approval.d.ts +4 -3
- package/dist/core/retired-keys.d.ts +13 -0
- package/dist/core/retired-keys.js +14 -0
- package/dist/core/roles.d.ts +2 -3
- package/dist/core/roles.js +15 -6
- package/dist/core/runner/assemble-result.d.ts +0 -7
- package/dist/core/runner/assemble-result.js +19 -31
- package/dist/core/runner/caller-roster.d.ts +78 -0
- package/dist/core/runner/caller-roster.js +219 -0
- package/dist/core/runner/checkpoint-scope.d.ts +16 -16
- package/dist/core/runner/checkpoint-scope.js +2 -2
- package/dist/core/runner/child-tree.js +2 -2
- package/dist/core/runner/contracts.d.ts +68 -35
- package/dist/core/runner/decide-continuation.d.ts +51 -3
- package/dist/core/runner/decide-continuation.js +76 -21
- package/dist/core/runner/denial-limit-arms.d.ts +17 -5
- package/dist/core/runner/denial-limit-arms.js +11 -9
- package/dist/core/runner/extra-body-dropped-seat.d.ts +8 -0
- package/dist/core/runner/extra-body-dropped-seat.js +22 -0
- package/dist/core/runner/finish-reason-seat.d.ts +9 -0
- package/dist/core/runner/finish-reason-seat.js +40 -0
- package/dist/core/runner/gate-exit.d.ts +44 -32
- package/dist/core/runner/gate-exit.js +112 -25
- package/dist/core/runner/inherited-ask-grants.js +6 -4
- package/dist/core/runner/mcp-redial.d.ts +3 -3
- package/dist/core/runner/mcp-redial.js +3 -4
- package/dist/core/runner/permission-rule-lanes.d.ts +1 -2
- package/dist/core/runner/permission-rule-lanes.js +5 -4
- package/dist/core/runner/prepare-artifact.d.ts +4 -0
- package/dist/core/runner/prepare-artifact.js +2 -1
- package/dist/core/runner/prepare-ask-lane.d.ts +2 -0
- package/dist/core/runner/prepare-ask-lane.js +12 -6
- package/dist/core/runner/prepare-boundary-parks.d.ts +5 -8
- package/dist/core/runner/prepare-boundary-parks.js +4 -7
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +11 -15
- package/dist/core/runner/prepare-caps-and-workflow.js +19 -27
- package/dist/core/runner/prepare-config-doors.d.ts +9 -9
- package/dist/core/runner/prepare-config-doors.js +10 -5
- package/dist/core/runner/prepare-defer-classify.d.ts +2 -2
- package/dist/core/runner/prepare-defer-classify.js +5 -3
- package/dist/core/runner/prepare-delegation-surface.d.ts +1 -1
- package/dist/core/runner/prepare-delegation-surface.js +3 -3
- package/dist/core/runner/prepare-gate-stations.d.ts +4 -4
- package/dist/core/runner/prepare-gate-stations.js +9 -7
- package/dist/core/runner/prepare-hands-readface.d.ts +7 -7
- package/dist/core/runner/prepare-hands-readface.js +7 -7
- package/dist/core/runner/prepare-inherited-gate.d.ts +7 -6
- package/dist/core/runner/prepare-inherited-gate.js +14 -15
- package/dist/core/runner/prepare-listings.d.ts +7 -24
- package/dist/core/runner/prepare-listings.js +4 -5
- package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -0
- package/dist/core/runner/prepare-memory-engine-session.js +4 -3
- package/dist/core/runner/prepare-memory.d.ts +6 -0
- package/dist/core/runner/prepare-memory.js +13 -13
- package/dist/core/runner/prepare-offload-wrappers.d.ts +5 -0
- package/dist/core/runner/prepare-offload-wrappers.js +3 -3
- package/dist/core/runner/prepare-park-ask.d.ts +7 -8
- package/dist/core/runner/prepare-park-ask.js +17 -10
- package/dist/core/runner/prepare-policy-chain.js +24 -44
- package/dist/core/runner/prepare-project-context.d.ts +1 -1
- package/dist/core/runner/prepare-project-context.js +3 -4
- package/dist/core/runner/prepare-protocol-tools.d.ts +9 -3
- package/dist/core/runner/prepare-protocol-tools.js +3 -4
- package/dist/core/runner/prepare-run-refs.d.ts +3 -0
- package/dist/core/runner/prepare-run-refs.js +2 -1
- package/dist/core/runner/prepare-safety-scan.d.ts +4 -8
- package/dist/core/runner/prepare-safety-scan.js +1 -2
- package/dist/core/runner/prepare-suspend-saga.d.ts +7 -1
- package/dist/core/runner/prepare-suspend-saga.js +28 -12
- package/dist/core/runner/prepare-task.d.ts +1 -1
- package/dist/core/runner/prepare-task.js +67 -56
- package/dist/core/runner/prepare-wiring-manifest.d.ts +11 -10
- package/dist/core/runner/prepare-wiring-manifest.js +5 -8
- package/dist/core/runner/resume-apply.js +7 -14
- package/dist/core/runner/resume-checkpoint-screen.js +11 -4
- package/dist/core/runner/resume-internals-and-config.js +2 -2
- package/dist/core/runner/resume-policy-outcome.js +5 -32
- package/dist/core/runner/resume-review-outcome.js +4 -1
- package/dist/core/runner/retired-runner-deps.d.ts +6 -0
- package/dist/core/runner/retired-runner-deps.js +10 -1
- package/dist/core/runner/run-brain-sinks.d.ts +4 -0
- package/dist/core/runner/run-brain-sinks.js +5 -2
- package/dist/core/runner/run-harness-handlers.js +29 -36
- package/dist/core/runner/run-leg.d.ts +0 -2
- package/dist/core/runner/run-leg.js +32 -33
- package/dist/core/runner/run-terminal-adoption.js +4 -3
- package/dist/core/runner/runtask.js +8 -8
- package/dist/core/runner/session-rule-policy.js +5 -5
- package/dist/core/runner/stream-settle-backstop.js +7 -4
- package/dist/core/runner/sub-agent-deny-lists.d.ts +51 -12
- package/dist/core/runner/sub-agent-deny-lists.js +111 -80
- package/dist/core/runner/terminal-account.d.ts +48 -0
- package/dist/core/runner/terminal-account.js +186 -0
- package/dist/core/runner/tool-end-body.d.ts +54 -17
- package/dist/core/runner/tool-end-body.js +27 -2
- package/dist/core/runner/tool-face-overlay.d.ts +3 -1
- package/dist/core/runner/tool-face-overlay.js +6 -4
- package/dist/core/runner/tool-occurrence.d.ts +106 -0
- package/dist/core/runner/tool-occurrence.js +123 -0
- package/dist/core/runner/tool-progress-lane.d.ts +16 -8
- package/dist/core/runner/tool-progress-lane.js +25 -34
- package/dist/core/runner/tool-turn-repair-seat.d.ts +28 -4
- package/dist/core/runner/tool-turn-repair-seat.js +36 -13
- package/dist/core/runner/turn-attachments.d.ts +1 -1
- package/dist/core/runner/write-protection-station.d.ts +21 -9
- package/dist/core/runner/write-protection-station.js +20 -17
- package/dist/core/runner-deps.d.ts +12 -22
- package/dist/core/secret-env.d.ts +16 -5
- package/dist/core/secret-env.js +23 -63
- package/dist/core/sensitive-path-policy.d.ts +19 -18
- package/dist/core/sensitive-path-policy.js +73 -49
- package/dist/core/session-reconcile.d.ts +3 -0
- package/dist/core/session-reconcile.js +5 -4
- package/dist/core/session-store.d.ts +5 -0
- package/dist/core/session-store.js +12 -0
- package/dist/core/session.d.ts +13 -0
- package/dist/core/shared-memory/normalize.d.ts +17 -4
- package/dist/core/shared-memory/normalize.js +7 -7
- package/dist/core/shell-lexer.js +5 -4
- package/dist/core/shell-wrapper-projection.js +1 -1
- package/dist/core/skill-grant.js +1 -1
- package/dist/core/store-contracts/checkpoint-store-contract.js +13 -0
- package/dist/core/store-contracts/mailbox-store-contract.d.ts +7 -14
- package/dist/core/store-contracts/session-store-incarnation-contract.d.ts +27 -0
- package/dist/core/store-contracts/session-store-incarnation-contract.js +92 -0
- package/dist/core/stub-env.d.ts +2 -0
- package/dist/core/stub-env.js +1 -0
- package/dist/core/synthetic-read-verdict.js +2 -2
- package/dist/core/task-event.d.ts +59 -5
- package/dist/core/task-result.d.ts +1 -1
- package/dist/core/task-spec.d.ts +42 -9
- package/dist/core/terminal-cause.d.ts +94 -11
- package/dist/core/tighten-task-spec.d.ts +5 -4
- package/dist/core/tighten-task-spec.js +20 -25
- package/dist/core/tool-catalog-entries.d.ts +5 -7
- package/dist/core/tool-catalog-entries.js +14 -15
- package/dist/core/tool-face.d.ts +47 -0
- package/dist/core/tool-face.js +5 -0
- package/dist/core/tool-model-gate.d.ts +5 -5
- package/dist/core/tool-name-aliases.d.ts +26 -2
- package/dist/core/tool-name-aliases.js +13 -0
- package/dist/core/tool-name-list.d.ts +30 -0
- package/dist/core/tool-name-list.js +55 -0
- package/dist/core/tool-name-readings.d.ts +1 -9
- package/dist/core/tool-name-readings.js +1 -3
- package/dist/core/tool-policy.d.ts +195 -85
- package/dist/core/tool-policy.js +165 -380
- package/dist/core/tool-registry.d.ts +44 -1
- package/dist/core/tool-registry.js +26 -0
- package/dist/core/tool-roster.d.ts +19 -1
- package/dist/core/tool-roster.js +21 -2
- package/dist/core/tool-spec-members.d.ts +45 -0
- package/dist/core/tool-spec-members.js +169 -0
- package/dist/core/tool-spec.d.ts +46 -8
- package/dist/core/tools.d.ts +6 -2
- package/dist/core/tools.js +8 -4
- package/dist/core/untrusted-egress.js +29 -26
- package/dist/core/untrusted-text.d.ts +13 -10
- package/dist/core/untrusted-text.js +6 -44
- package/dist/core/workflow-journal-store.d.ts +4 -1
- package/dist/core/write-protect.d.ts +65 -29
- package/dist/core/write-protect.js +235 -177
- package/dist/engine/compaction/compaction.d.ts +2 -2
- package/dist/engine/execution-env/node-execution-env.d.ts +5 -23
- package/dist/engine/execution-env/node-execution-env.js +16 -38
- package/dist/engine/execution-env/symlink-chain.d.ts +23 -0
- package/dist/engine/execution-env/symlink-chain.js +32 -0
- package/dist/engine/harness/types.d.ts +7 -0
- package/dist/engine/llm/tool-turns.d.ts +3 -0
- package/dist/engine/llm/tool-turns.js +1 -0
- package/dist/engine/llm/types.d.ts +59 -23
- package/dist/engine/loop/agent-loop.js +16 -2
- package/dist/engine/session/memory-repo.js +11 -3
- package/dist/engine/session/repo-utils.d.ts +8 -0
- package/dist/engine/session/repo-utils.js +13 -0
- package/dist/index.d.ts +20 -23
- package/dist/index.js +17 -20
- package/dist/internal/harness.d.ts +1 -1
- package/dist/internal/harness.js +1 -1
- package/dist/internal/llm.d.ts +2 -2
- package/dist/internal/llm.js +1 -1
- package/dist/orchestration/governance-baseline-validity.js +1 -1
- package/dist/orchestration/run-spec.js +3 -3
- package/dist/orchestration/run-workflow-tool.d.ts +16 -35
- package/dist/orchestration/run-workflow-tool.js +38 -78
- package/dist/orchestration/workflow-governance.d.ts +21 -25
- package/dist/orchestration/workflow-governance.js +38 -78
- package/dist/orchestration/workflow-primitives.d.ts +7 -22
- package/dist/orchestration/workflow-primitives.js +5 -12
- package/dist/orchestration/workflow-types.d.ts +1 -1
- package/dist/orchestration/workflow.d.ts +61 -11
- package/dist/orchestration/workflow.js +189 -117
- package/dist/scenarios/full-body.d.ts +1 -1
- package/dist/shell/lex.d.ts +0 -21
- package/dist/shell/lex.js +250 -68
- package/dist/shell/shell-words.d.ts +35 -0
- package/dist/shell/shell-words.js +65 -0
- package/dist/stores/file/checkpoint-store.d.ts +5 -5
- package/dist/stores/file/checkpoint-store.js +5 -2
- package/dist/stores/file/index.d.ts +0 -8
- package/dist/stores/file/index.js +0 -12
- package/dist/stores/file/session-store.d.ts +3 -0
- package/dist/stores/file/session-store.js +44 -19
- package/dist/tools/artifact/artifact-tool.js +2 -0
- package/dist/tools/fs/bash-program-position.d.ts +12 -4
- package/dist/tools/fs/bash-program-position.js +32 -9
- package/dist/tools/fs/bash-readonly-classifier.d.ts +1 -1
- package/dist/tools/fs/bash-readonly-classifier.js +8 -7
- package/dist/tools/fs/containment-face.d.ts +4 -0
- package/dist/tools/fs/containment-face.js +3 -0
- package/dist/tools/fs/fs-shared.d.ts +10 -0
- package/dist/tools/fs/fs-shared.js +18 -0
- package/dist/tools/fs/fs-write.js +4 -2
- package/dist/tools/fs/index.d.ts +1 -1
- package/dist/tools/fs/program-read-model.d.ts +46 -20
- package/dist/tools/fs/program-read-model.js +50 -20
- package/dist/tools/fs/program-read-model.rows.d.ts +0 -14
- package/dist/tools/fs/program-read-model.rows.js +16 -15
- package/dist/tools/fs/read-deny-home.d.ts +33 -47
- package/dist/tools/fs/read-deny-home.js +35 -49
- package/dist/tools/fs/read-deny.d.ts +23 -22
- package/dist/tools/fs/read-deny.js +114 -89
- package/dist/tools/fs/removal-targets.d.ts +56 -23
- package/dist/tools/fs/removal-targets.js +65 -87
- package/dist/tools/fs/safety.d.ts +29 -22
- package/dist/tools/fs/safety.js +17 -11
- package/dist/tools/fs/search.js +10 -8
- package/dist/tools/fs/shell-read-argv.js +1 -1
- package/dist/tools/fs/shell-read-bindings.d.ts +169 -37
- package/dist/tools/fs/shell-read-bindings.js +324 -86
- package/dist/tools/fs/shell-read-builtins.d.ts +35 -0
- package/dist/tools/fs/shell-read-builtins.js +43 -0
- package/dist/tools/fs/shell-read-check.d.ts +15 -1
- package/dist/tools/fs/shell-read-check.js +67 -43
- package/dist/tools/fs/shell-read-establish.js +6 -6
- package/dist/tools/fs/shell-read-functions.d.ts +22 -0
- package/dist/tools/fs/shell-read-functions.js +29 -0
- package/dist/tools/fs/shell-read-judge.d.ts +51 -18
- package/dist/tools/fs/shell-read-judge.js +40 -4
- package/dist/tools/fs/shell-read-plan.d.ts +12 -6
- package/dist/tools/fs/shell-read-plan.js +118 -113
- package/dist/tools/fs/shell-read-start.d.ts +29 -6
- package/dist/tools/fs/shell-read-start.js +16 -9
- package/dist/tools/fs/shell-read-word.js +4 -0
- package/dist/tools/fs/shell-read-workdir.d.ts +156 -0
- package/dist/tools/fs/shell-read-workdir.js +281 -0
- package/dist/tools/fs/shell-read-write-targets.d.ts +5 -2
- package/dist/tools/fs/shell-read-write-targets.js +14 -5
- package/dist/tools/fs/shell-reentry-text.d.ts +4 -6
- package/dist/tools/fs/shell-reentry-text.js +3 -11
- package/dist/tools/task-list.d.ts +1 -2
- package/dist/tools/web.js +1 -1
- package/package.json +4 -1
- package/test/export-surface.snapshot.json +107 -143
- package/wire-changes/core@7.49.0.json +4765 -0
- package/dist/agents/teacher.d.ts +0 -159
- package/dist/agents/teacher.js +0 -577
- package/dist/agents/team.d.ts +0 -226
- package/dist/agents/team.js +0 -257
- package/dist/core/strategy-store.d.ts +0 -238
- package/dist/core/strategy-store.js +0 -253
- package/dist/orchestration/builtin-workflows.d.ts +0 -133
- package/dist/orchestration/builtin-workflows.js +0 -159
- package/dist/scenarios/env.d.ts +0 -40
- package/dist/scenarios/env.js +0 -39
- package/dist/scenarios/scenario-registry.d.ts +0 -110
- package/dist/scenarios/scenario-registry.js +0 -140
- package/dist/scenarios/teacher-quickstart.d.ts +0 -40
- package/dist/scenarios/teacher-quickstart.js +0 -12
- package/dist/stores/cc/lockfile.d.ts +0 -10
- package/dist/stores/cc/lockfile.js +0 -98
- package/dist/stores/cc/mailbox-store.d.ts +0 -20
- package/dist/stores/cc/mailbox-store.js +0 -255
- package/dist/stores/cc/roster-adapter.d.ts +0 -12
- package/dist/stores/cc/roster-adapter.js +0 -117
- package/dist/stores/cc/sidecar-transcript.d.ts +0 -97
- package/dist/stores/cc/sidecar-transcript.js +0 -264
- package/dist/stores/cc/task-list-store.d.ts +0 -2
- package/dist/stores/cc/task-list-store.js +0 -125
- package/dist/stores/file/strategy-store.d.ts +0 -97
- package/dist/stores/file/strategy-store.js +0 -341
|
@@ -8,7 +8,7 @@ import { ambiguousOriginRepresentation, committedDistilledOf, committedOriginOf,
|
|
|
8
8
|
import { convertV1SidecarKeys } from "./delegation-settlement.js";
|
|
9
9
|
import { layerObservationLookup, observedDivergenceNotice } from "./layer-observations.js";
|
|
10
10
|
import { DEFAULT_MAX_ENTRY_DEPTH, MEMORY_INDEX_FILENAME, scanEntryFiles } from "./entry-scan.js";
|
|
11
|
-
import { ControlPlaneCorruptError, CURSORS_FILE, QUARANTINE_DIR, CHALLENGES_FILE, IMPORT_RECEIPTS_DIR, LINEAGE_FILE, SESSION_POLLUTION_DIR, appendChallengeEvents, atomicWriteFileSync, quarantineAndTombstone, captureAndClearLineageForEntries, adoptRootScopeLayout,
|
|
11
|
+
import { ControlPlaneCorruptError, CURSORS_FILE, QUARANTINE_DIR, CHALLENGES_FILE, IMPORT_RECEIPTS_DIR, LINEAGE_FILE, SESSION_POLLUTION_DIR, appendChallengeEvents, atomicWriteFileSync, quarantineAndTombstone, captureAndClearLineageForEntries, adoptRootScopeLayout, anchorStoreRoot, effectiveControlRootOf, ensureDirExists, LEDGER_FILE, enqueueMemoryAnnouncement, importLatchTxnId, importLineageCommitted, importSessionPollution, isContainedIn, permissionRemedyOf, withPermissionRemedy, lineageContributionsOfSession, listSessionPollution, readChallengeEvents, readLineageRecord, registerScope, registeredScopes, releaseImportLatch, layoutNeedsAdoption, scopeDirFor, scopeDirName, scopeRegistryShape, stageImportLatch, landsOutsideStore, storeActRefusal, storeRootMovedRefusal, writeAllSync, STORE_JOURNAL_FILE, STORE_TXN_LOCK_DIR, TXN_LOCK_STALE_MS, acquireStoreTxnLock, assertStoreTxnLockOwnership, tryStoreTxnLock, } from "./layout.js";
|
|
12
12
|
import { screenInboundEntries } from "./data-plane.js";
|
|
13
13
|
import { scanMemoryFileName, scanMemoryWrite } from "./scan.js";
|
|
14
14
|
import { thrownText } from "../thrown-value.js";
|
|
@@ -100,15 +100,10 @@ class AuditSnapshotContendedError extends Error {
|
|
|
100
100
|
}
|
|
101
101
|
class AuditObservationUnstableError extends Error {
|
|
102
102
|
}
|
|
103
|
-
const LEDGER_FILE = "revs.json";
|
|
104
103
|
const LEDGER_SCHEMA_VERSION = 2;
|
|
105
104
|
const LEDGER_V1_BACKUP_FILE = "revs.v1.json.bak";
|
|
106
105
|
const TRANSFERS_FILE = "transfers.jsonl";
|
|
107
106
|
const CHAIN_DEGRADED_FILE = "transfers.chain-degraded.json";
|
|
108
|
-
const JOURNAL_FILE = "journal.json";
|
|
109
|
-
const TXN_LOCK_STALE_MS = 30_000;
|
|
110
|
-
const TXN_LOCK_WAIT_MS = 15_000;
|
|
111
|
-
const TXN_LOCK_STEAL_GRACE_MS = 250;
|
|
112
107
|
const SHADOW_DIR = "shadow";
|
|
113
108
|
const STORE_IDENTITY_FILE = "store-identity.json";
|
|
114
109
|
function rowsRev(rows, id) {
|
|
@@ -522,7 +517,6 @@ function probeProjection(absPath, id) {
|
|
|
522
517
|
export class FileMemoryEngineBackend {
|
|
523
518
|
directoryRoot;
|
|
524
519
|
controlPlaneRoot;
|
|
525
|
-
physicalRoot;
|
|
526
520
|
now;
|
|
527
521
|
onIncident;
|
|
528
522
|
ledger;
|
|
@@ -542,11 +536,9 @@ export class FileMemoryEngineBackend {
|
|
|
542
536
|
this.now = opts.now ?? Date.now;
|
|
543
537
|
this.onIncident = opts.onIncident;
|
|
544
538
|
this.directoryRoot = dir;
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
this.controlPlaneRoot = opts.controlDir ?? deriveControlPlaneDir(resolveMemoryEngineRoot(), dir);
|
|
539
|
+
this.controlPlaneRoot = effectiveControlRootOf(dir, { controlDir: opts.controlDir, onIncident: opts.onIncident });
|
|
540
|
+
this.assertRootAnchored();
|
|
548
541
|
ensureDirExists(dir);
|
|
549
|
-
this.physicalRoot = landingPathOf(dir);
|
|
550
542
|
ensureDirExists(this.controlPlaneRoot);
|
|
551
543
|
this.recoverJournal({ unlocked: true });
|
|
552
544
|
try {
|
|
@@ -579,7 +571,7 @@ export class FileMemoryEngineBackend {
|
|
|
579
571
|
});
|
|
580
572
|
}
|
|
581
573
|
ensureLayout(ownerCandidate) {
|
|
582
|
-
this.
|
|
574
|
+
this.assertRootAnchored();
|
|
583
575
|
if (!layoutNeedsAdoption(this.directoryRoot, this.controlPlaneRoot))
|
|
584
576
|
return;
|
|
585
577
|
const lock = this.tryAcquireTxnLockSync();
|
|
@@ -594,7 +586,7 @@ export class FileMemoryEngineBackend {
|
|
|
594
586
|
}
|
|
595
587
|
}
|
|
596
588
|
async adoptRootScopeLayout(opts = {}) {
|
|
597
|
-
this.
|
|
589
|
+
this.assertRootAnchored();
|
|
598
590
|
if (!layoutNeedsAdoption(this.directoryRoot, this.controlPlaneRoot))
|
|
599
591
|
return;
|
|
600
592
|
const lock = await this.acquireTxnLock();
|
|
@@ -777,117 +769,7 @@ export class FileMemoryEngineBackend {
|
|
|
777
769
|
}
|
|
778
770
|
}
|
|
779
771
|
tryAcquireTxnLockSync() {
|
|
780
|
-
|
|
781
|
-
const ownerPath = join(lockDir, "owner");
|
|
782
|
-
const tryMkdir = () => {
|
|
783
|
-
try {
|
|
784
|
-
mkdirSync(this.controlPlaneRoot, { recursive: true });
|
|
785
|
-
}
|
|
786
|
-
catch (err) {
|
|
787
|
-
throw new ControlPlaneCorruptError(`memory control-plane root could not be created (${err.code ?? "io error"}) at ${this.controlPlaneRoot} — a lock-acquisition fault is not contention; deferring recovery/migration on it would be silent (fail-closed)`, { cause: err });
|
|
788
|
-
}
|
|
789
|
-
try {
|
|
790
|
-
mkdirSync(lockDir);
|
|
791
|
-
return true;
|
|
792
|
-
}
|
|
793
|
-
catch (err) {
|
|
794
|
-
if (err.code === "EEXIST")
|
|
795
|
-
return false;
|
|
796
|
-
throw new ControlPlaneCorruptError(`memory txn lock could not be created (${err.code ?? "io error"}) at ${lockDir} — a lock-acquisition fault is not contention; deferring recovery/migration on it would be silent (fail-closed)`, { cause: err });
|
|
797
|
-
}
|
|
798
|
-
};
|
|
799
|
-
let acquired = tryMkdir();
|
|
800
|
-
if (!acquired) {
|
|
801
|
-
let mtimeMs;
|
|
802
|
-
try {
|
|
803
|
-
mtimeMs = statSync(lockDir).mtimeMs;
|
|
804
|
-
}
|
|
805
|
-
catch (err) {
|
|
806
|
-
if (err.code !== "ENOENT") {
|
|
807
|
-
throw new ControlPlaneCorruptError(`memory txn lock state could not be probed (${err.code ?? "io error"}) at ${lockDir} — a probe failure is not contention (fail-closed)`, { cause: err });
|
|
808
|
-
}
|
|
809
|
-
let occupant;
|
|
810
|
-
try {
|
|
811
|
-
occupant = lstatSync(lockDir);
|
|
812
|
-
}
|
|
813
|
-
catch (lerr) {
|
|
814
|
-
if (lerr.code !== "ENOENT") {
|
|
815
|
-
throw new ControlPlaneCorruptError(`memory txn lock re-probe failed (${lerr.code ?? "io error"}) at ${lockDir} — a probe failure is not contention (fail-closed)`, { cause: lerr });
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
if (occupant !== undefined && !occupant.isDirectory()) {
|
|
819
|
-
throw new ControlPlaneCorruptError(`memory txn lock path is occupied by an invalid node (a dangling symlink?) at ${lockDir} — not contention and not a release race; remove the occupant (fail-closed)`, { cause: err });
|
|
820
|
-
}
|
|
821
|
-
mtimeMs = undefined;
|
|
822
|
-
}
|
|
823
|
-
if (mtimeMs !== undefined && this.now() - mtimeMs > TXN_LOCK_STALE_MS) {
|
|
824
|
-
let tokenPresent = false;
|
|
825
|
-
try {
|
|
826
|
-
statSync(ownerPath);
|
|
827
|
-
tokenPresent = true;
|
|
828
|
-
}
|
|
829
|
-
catch (err) {
|
|
830
|
-
if (err.code !== "ENOENT") {
|
|
831
|
-
throw new ControlPlaneCorruptError(`memory txn lock owner token could not be probed (${err.code ?? "io error"}) at ${ownerPath} — a probe failure is not a mid-acquisition (fail-closed)`, { cause: err });
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
if (tokenPresent) {
|
|
835
|
-
const tomb = join(this.controlPlaneRoot, `txn.lock.stale-${randomUUID()}`);
|
|
836
|
-
let stolen = false;
|
|
837
|
-
try {
|
|
838
|
-
renameSync(lockDir, tomb);
|
|
839
|
-
stolen = true;
|
|
840
|
-
}
|
|
841
|
-
catch (err) {
|
|
842
|
-
if (err.code !== "ENOENT") {
|
|
843
|
-
throw new ControlPlaneCorruptError(`memory txn lock stale-steal rename failed (${err.code ?? "io error"}) at ${lockDir} — a rename fault is not a lost race (fail-closed)`, { cause: err });
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
if (stolen) {
|
|
847
|
-
rmSync(tomb, { recursive: true, force: true });
|
|
848
|
-
acquired = tryMkdir();
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
if (!acquired)
|
|
853
|
-
return undefined;
|
|
854
|
-
}
|
|
855
|
-
const token = randomUUID();
|
|
856
|
-
try {
|
|
857
|
-
const fd = openSync(ownerPath, "w", 0o600);
|
|
858
|
-
try {
|
|
859
|
-
writeAllSync(fd, token);
|
|
860
|
-
fsyncSync(fd);
|
|
861
|
-
}
|
|
862
|
-
finally {
|
|
863
|
-
closeSync(fd);
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
catch (err) {
|
|
867
|
-
try {
|
|
868
|
-
rmSync(lockDir, { recursive: true, force: true });
|
|
869
|
-
}
|
|
870
|
-
catch {
|
|
871
|
-
}
|
|
872
|
-
throw new Error(`memory txn lock owner token could not be written at ${ownerPath}: ${thrownText(err)}`);
|
|
873
|
-
}
|
|
874
|
-
return {
|
|
875
|
-
token,
|
|
876
|
-
release: () => {
|
|
877
|
-
try {
|
|
878
|
-
if (readFileSync(ownerPath, "utf8") !== token)
|
|
879
|
-
return;
|
|
880
|
-
}
|
|
881
|
-
catch {
|
|
882
|
-
return;
|
|
883
|
-
}
|
|
884
|
-
try {
|
|
885
|
-
rmSync(lockDir, { recursive: true, force: true });
|
|
886
|
-
}
|
|
887
|
-
catch {
|
|
888
|
-
}
|
|
889
|
-
},
|
|
890
|
-
};
|
|
772
|
+
return tryStoreTxnLock(this.controlPlaneRoot, { now: this.now });
|
|
891
773
|
}
|
|
892
774
|
tryOpportunisticMigrate() {
|
|
893
775
|
const lock = this.tryAcquireTxnLockSync();
|
|
@@ -946,12 +828,12 @@ export class FileMemoryEngineBackend {
|
|
|
946
828
|
this.assertTxnLockOwnership(lockToken);
|
|
947
829
|
this.precheckTransfersAppendable();
|
|
948
830
|
const journal = { txn: `${Date.now()}-migrate`, ops: [], ledger2: ledgerEnvelope(next, this.envelopeExtras), transfers: events };
|
|
949
|
-
atomicWriteFileSync(join(this.controlPlaneRoot,
|
|
831
|
+
atomicWriteFileSync(join(this.controlPlaneRoot, STORE_JOURNAL_FILE), JSON.stringify(journal));
|
|
950
832
|
this.ledger = next;
|
|
951
833
|
this.persistedSchemaVersion = "v2";
|
|
952
834
|
this.saveLedger();
|
|
953
835
|
this.appendTransfers(events);
|
|
954
|
-
rmSync(join(this.controlPlaneRoot,
|
|
836
|
+
rmSync(join(this.controlPlaneRoot, STORE_JOURNAL_FILE), { force: true });
|
|
955
837
|
this.enqueueExternalItems([
|
|
956
838
|
fullMigration
|
|
957
839
|
? `memory ledger upgraded to v2 (${bound.length} row(s) bound, ${unbound.length} unbound${unbound.length > 0 ? `: ${unbound.slice(0, 8).join(", ")}${unbound.length > 8 ? ", …" : ""}` : ""})`
|
|
@@ -1027,7 +909,7 @@ export class FileMemoryEngineBackend {
|
|
|
1027
909
|
if (!isTail)
|
|
1028
910
|
throw new ControlPlaneCorruptError(`transfer evidence log line ${i + 1} is unparseable (not a torn tail — fail-closed): ${path}`);
|
|
1029
911
|
let journalHasPendingEvidence = false;
|
|
1030
|
-
const jraw = readControlFileOrAbsent(join(this.controlPlaneRoot,
|
|
912
|
+
const jraw = readControlFileOrAbsent(join(this.controlPlaneRoot, STORE_JOURNAL_FILE), "transaction journal");
|
|
1031
913
|
if (jraw !== undefined) {
|
|
1032
914
|
try {
|
|
1033
915
|
const jparsed = JSON.parse(jraw);
|
|
@@ -1215,7 +1097,7 @@ export class FileMemoryEngineBackend {
|
|
|
1215
1097
|
}
|
|
1216
1098
|
}
|
|
1217
1099
|
recoverJournal(fence) {
|
|
1218
|
-
this.
|
|
1100
|
+
this.assertRootAnchored();
|
|
1219
1101
|
if (fence.token === undefined) {
|
|
1220
1102
|
if (this.txnInFlight())
|
|
1221
1103
|
return;
|
|
@@ -1231,7 +1113,7 @@ export class FileMemoryEngineBackend {
|
|
|
1231
1113
|
return;
|
|
1232
1114
|
}
|
|
1233
1115
|
const fenceToken = fence.token;
|
|
1234
|
-
const jp = join(this.controlPlaneRoot,
|
|
1116
|
+
const jp = join(this.controlPlaneRoot, STORE_JOURNAL_FILE);
|
|
1235
1117
|
const raw = readControlFileOrAbsent(jp, "transaction journal");
|
|
1236
1118
|
if (raw !== undefined) {
|
|
1237
1119
|
const journal = parseJournal(raw, jp);
|
|
@@ -1465,21 +1347,23 @@ export class FileMemoryEngineBackend {
|
|
|
1465
1347
|
throw new ControlPlaneCorruptError(`txn lock state could not be probed (${code ?? "io error"}) at ${this.txnLockDir()} — a probe failure is not "no writer" (fail-closed)`);
|
|
1466
1348
|
}
|
|
1467
1349
|
}
|
|
1468
|
-
refuseEscapingTargets(ops, at) {
|
|
1350
|
+
refuseEscapingTargets(ops, at, anchoredRoot) {
|
|
1351
|
+
let root;
|
|
1469
1352
|
for (const op of ops) {
|
|
1470
1353
|
if (op.kind !== "write" && op.kind !== "delete")
|
|
1471
1354
|
continue;
|
|
1355
|
+
root ??= this.assertRootAnchored(anchoredRoot);
|
|
1472
1356
|
for (const path of op.staged === undefined ? [op.target] : [op.target, op.staged]) {
|
|
1473
|
-
if (landsOutsideStore(
|
|
1357
|
+
if (landsOutsideStore(root, path))
|
|
1474
1358
|
throw storeActRefusal(`${path === op.target ? "a" : "the staged file of a"} ${op.kind} at ${at}`, path);
|
|
1475
1359
|
}
|
|
1476
1360
|
}
|
|
1477
1361
|
}
|
|
1478
|
-
|
|
1479
|
-
const
|
|
1480
|
-
if (
|
|
1481
|
-
|
|
1482
|
-
|
|
1362
|
+
assertRootAnchored(expected) {
|
|
1363
|
+
const root = anchorStoreRoot(this.directoryRoot, this.controlPlaneRoot, { onIncident: this.onIncident, now: this.now });
|
|
1364
|
+
if (expected !== undefined && expected !== root)
|
|
1365
|
+
throw storeRootMovedRefusal(this.directoryRoot, { controlDir: this.controlPlaneRoot, recorded: root, now: expected });
|
|
1366
|
+
return root;
|
|
1483
1367
|
}
|
|
1484
1368
|
sweepStagedFiles() {
|
|
1485
1369
|
const walk = (d, depth) => {
|
|
@@ -1689,10 +1573,10 @@ export class FileMemoryEngineBackend {
|
|
|
1689
1573
|
ledger2: ledgerEnvelope(rows, this.envelopeExtras),
|
|
1690
1574
|
transfers: moveEvents,
|
|
1691
1575
|
};
|
|
1692
|
-
atomicWriteFileSync(join(this.controlPlaneRoot,
|
|
1576
|
+
atomicWriteFileSync(join(this.controlPlaneRoot, STORE_JOURNAL_FILE), JSON.stringify(journal));
|
|
1693
1577
|
this.saveLedger();
|
|
1694
1578
|
this.appendTransfers(moveEvents);
|
|
1695
|
-
rmSync(join(this.controlPlaneRoot,
|
|
1579
|
+
rmSync(join(this.controlPlaneRoot, STORE_JOURNAL_FILE), { force: true });
|
|
1696
1580
|
}
|
|
1697
1581
|
else {
|
|
1698
1582
|
this.saveLedger();
|
|
@@ -2226,10 +2110,10 @@ export class FileMemoryEngineBackend {
|
|
|
2226
2110
|
scored.sort((a, b) => band(a) - band(b) || a.score - b.score || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
2227
2111
|
return scored.slice(0, limit);
|
|
2228
2112
|
}
|
|
2229
|
-
async applyPatches(patches) {
|
|
2113
|
+
async applyPatches(patches, opts) {
|
|
2230
2114
|
const lock = await this.acquireTxnLock();
|
|
2231
2115
|
try {
|
|
2232
|
-
return await this.applyPatchesLocked(patches, lock.token);
|
|
2116
|
+
return await this.applyPatchesLocked(patches, lock.token, opts?.anchoredRoot);
|
|
2233
2117
|
}
|
|
2234
2118
|
catch (err) {
|
|
2235
2119
|
throw withPermissionRemedy(err, this.directoryRoot);
|
|
@@ -2239,117 +2123,18 @@ export class FileMemoryEngineBackend {
|
|
|
2239
2123
|
}
|
|
2240
2124
|
}
|
|
2241
2125
|
txnLockDir() {
|
|
2242
|
-
return join(this.controlPlaneRoot,
|
|
2243
|
-
}
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
const waitMs = timings.waitMs ?? TXN_LOCK_WAIT_MS;
|
|
2247
|
-
const stealGraceMs = timings.stealGraceMs ?? TXN_LOCK_STEAL_GRACE_MS;
|
|
2248
|
-
const lockDir = this.txnLockDir();
|
|
2249
|
-
const ownerPath = join(lockDir, "owner");
|
|
2250
|
-
mkdirSync(this.controlPlaneRoot, { recursive: true });
|
|
2251
|
-
const start = Date.now();
|
|
2252
|
-
let deadline = start + waitMs;
|
|
2253
|
-
for (;;) {
|
|
2254
|
-
let acquired = false;
|
|
2255
|
-
try {
|
|
2256
|
-
mkdirSync(lockDir);
|
|
2257
|
-
acquired = true;
|
|
2258
|
-
}
|
|
2259
|
-
catch (err) {
|
|
2260
|
-
if (err.code !== "EEXIST")
|
|
2261
|
-
throw err;
|
|
2262
|
-
}
|
|
2263
|
-
if (acquired) {
|
|
2264
|
-
const token = randomUUID();
|
|
2265
|
-
try {
|
|
2266
|
-
const fd = openSync(ownerPath, "w", 0o600);
|
|
2267
|
-
try {
|
|
2268
|
-
writeAllSync(fd, token);
|
|
2269
|
-
fsyncSync(fd);
|
|
2270
|
-
}
|
|
2271
|
-
finally {
|
|
2272
|
-
closeSync(fd);
|
|
2273
|
-
}
|
|
2274
|
-
}
|
|
2275
|
-
catch (err) {
|
|
2276
|
-
try {
|
|
2277
|
-
rmSync(lockDir, { recursive: true, force: true });
|
|
2278
|
-
}
|
|
2279
|
-
catch {
|
|
2280
|
-
}
|
|
2281
|
-
throw new Error(`memory txn lock owner token could not be written at ${ownerPath}: ${thrownText(err)}`);
|
|
2282
|
-
}
|
|
2283
|
-
return {
|
|
2284
|
-
token,
|
|
2285
|
-
release: () => {
|
|
2286
|
-
try {
|
|
2287
|
-
if (readFileSync(ownerPath, "utf8") !== token)
|
|
2288
|
-
return;
|
|
2289
|
-
}
|
|
2290
|
-
catch {
|
|
2291
|
-
return;
|
|
2292
|
-
}
|
|
2293
|
-
try {
|
|
2294
|
-
rmSync(lockDir, { recursive: true, force: true });
|
|
2295
|
-
}
|
|
2296
|
-
catch {
|
|
2297
|
-
}
|
|
2298
|
-
},
|
|
2299
|
-
};
|
|
2300
|
-
}
|
|
2301
|
-
let mtimeMs;
|
|
2302
|
-
try {
|
|
2303
|
-
mtimeMs = statSync(lockDir).mtimeMs;
|
|
2304
|
-
}
|
|
2305
|
-
catch {
|
|
2306
|
-
mtimeMs = undefined;
|
|
2307
|
-
}
|
|
2308
|
-
if (mtimeMs !== undefined) {
|
|
2309
|
-
const staleAt = mtimeMs + staleMs;
|
|
2310
|
-
deadline = Math.max(deadline, staleAt + stealGraceMs);
|
|
2311
|
-
if (Date.now() > staleAt) {
|
|
2312
|
-
let tokenPresent = false;
|
|
2313
|
-
try {
|
|
2314
|
-
statSync(ownerPath);
|
|
2315
|
-
tokenPresent = true;
|
|
2316
|
-
}
|
|
2317
|
-
catch {
|
|
2318
|
-
}
|
|
2319
|
-
if (tokenPresent) {
|
|
2320
|
-
const tomb = join(this.controlPlaneRoot, `txn.lock.stale-${randomUUID()}`);
|
|
2321
|
-
let stolen = false;
|
|
2322
|
-
try {
|
|
2323
|
-
renameSync(lockDir, tomb);
|
|
2324
|
-
stolen = true;
|
|
2325
|
-
}
|
|
2326
|
-
catch {
|
|
2327
|
-
}
|
|
2328
|
-
if (stolen)
|
|
2329
|
-
rmSync(tomb, { recursive: true, force: true });
|
|
2330
|
-
}
|
|
2331
|
-
}
|
|
2332
|
-
}
|
|
2333
|
-
if (Date.now() > deadline) {
|
|
2334
|
-
throw new Error(`memory txn lock timeout (${waitMs}ms, extended to the lock's stale line) at ${lockDir} — another writer is wedged?`);
|
|
2335
|
-
}
|
|
2336
|
-
await new Promise((r) => setTimeout(r, 20 + Math.floor(Math.random() * 40)));
|
|
2337
|
-
}
|
|
2126
|
+
return join(this.controlPlaneRoot, STORE_TXN_LOCK_DIR);
|
|
2127
|
+
}
|
|
2128
|
+
acquireTxnLock(timings = {}) {
|
|
2129
|
+
return acquireStoreTxnLock(this.controlPlaneRoot, { now: Date.now, timings });
|
|
2338
2130
|
}
|
|
2339
2131
|
assertTxnLockOwnership(token) {
|
|
2340
|
-
|
|
2341
|
-
try {
|
|
2342
|
-
held = readFileSync(join(this.txnLockDir(), "owner"), "utf8");
|
|
2343
|
-
}
|
|
2344
|
-
catch {
|
|
2345
|
-
held = undefined;
|
|
2346
|
-
}
|
|
2347
|
-
if (held !== token) {
|
|
2348
|
-
throw new ControlPlaneCorruptError("txn lock ownership lost before commit (holder stalled past the stale deadline and was stolen from?) — transaction aborted, nothing was committed", { facet: "lock-ownership" });
|
|
2349
|
-
}
|
|
2132
|
+
assertStoreTxnLockOwnership(this.controlPlaneRoot, token);
|
|
2350
2133
|
}
|
|
2351
|
-
async applyPatchesLocked(patches, lockToken) {
|
|
2134
|
+
async applyPatchesLocked(patches, lockToken, anchoredRoot) {
|
|
2352
2135
|
this.assertTxnLockOwnership(lockToken);
|
|
2136
|
+
if (anchoredRoot !== undefined)
|
|
2137
|
+
this.assertRootAnchored(anchoredRoot);
|
|
2353
2138
|
this.ledger = undefined;
|
|
2354
2139
|
this.recoverJournal({ token: lockToken });
|
|
2355
2140
|
this.adoptLayoutLocked(lockToken, patches.find((p) => p.op === "add" && p.entry !== undefined)?.entry?.scope);
|
|
@@ -2393,7 +2178,7 @@ export class FileMemoryEngineBackend {
|
|
|
2393
2178
|
const stagedFiles = [];
|
|
2394
2179
|
const refuseUnstaging = (batch, at) => {
|
|
2395
2180
|
try {
|
|
2396
|
-
this.refuseEscapingTargets(batch, at);
|
|
2181
|
+
this.refuseEscapingTargets(batch, at, anchoredRoot);
|
|
2397
2182
|
}
|
|
2398
2183
|
catch (err) {
|
|
2399
2184
|
for (const f of stagedFiles) {
|
|
@@ -2439,7 +2224,7 @@ export class FileMemoryEngineBackend {
|
|
|
2439
2224
|
this.precheckTransfersAppendable();
|
|
2440
2225
|
const journal = { txn, ops, ledger2: ledgerEnvelope(rows, this.envelopeExtras), ...(coherentTransfers.length > 0 ? { transfers: coherentTransfers } : {}) };
|
|
2441
2226
|
refuseUnstaging(ops, "applyPatches (commit point)");
|
|
2442
|
-
atomicWriteFileSync(join(this.controlPlaneRoot,
|
|
2227
|
+
atomicWriteFileSync(join(this.controlPlaneRoot, STORE_JOURNAL_FILE), JSON.stringify(journal));
|
|
2443
2228
|
for (const op of ops) {
|
|
2444
2229
|
this.refuseEscapingTargets([op], "applyPatches (after the commit point; the journal is kept)");
|
|
2445
2230
|
if (op.kind === "write" && op.staged) {
|
|
@@ -2462,7 +2247,7 @@ export class FileMemoryEngineBackend {
|
|
|
2462
2247
|
return report;
|
|
2463
2248
|
}
|
|
2464
2249
|
closeJournalIfOurs(txn) {
|
|
2465
|
-
const jp = join(this.controlPlaneRoot,
|
|
2250
|
+
const jp = join(this.controlPlaneRoot, STORE_JOURNAL_FILE);
|
|
2466
2251
|
let raw;
|
|
2467
2252
|
try {
|
|
2468
2253
|
raw = readFileSync(jp, "utf8");
|
|
@@ -2867,7 +2652,7 @@ export class FileMemoryEngineBackend {
|
|
|
2867
2652
|
this.precheckTransfersAppendable();
|
|
2868
2653
|
const journal = { txn, ops, ledger2: ledgerEnvelope(rows, this.envelopeExtras), transfers };
|
|
2869
2654
|
this.refuseEscapingTargets(ops, "eraseWithEvidence (commit point)");
|
|
2870
|
-
atomicWriteFileSync(join(this.controlPlaneRoot,
|
|
2655
|
+
atomicWriteFileSync(join(this.controlPlaneRoot, STORE_JOURNAL_FILE), JSON.stringify(journal));
|
|
2871
2656
|
for (const op of ops) {
|
|
2872
2657
|
this.refuseEscapingTargets([op], "eraseWithEvidence (after the commit point; the journal is kept)");
|
|
2873
2658
|
if (op.kind === "delete") {
|
|
@@ -2946,7 +2731,7 @@ export class FileMemoryEngineBackend {
|
|
|
2946
2731
|
static AUDIT_FENCE_ATTEMPTS = 6;
|
|
2947
2732
|
static AUDIT_FENCE_RETRY_MS = 25;
|
|
2948
2733
|
auditJournalPending() {
|
|
2949
|
-
return readControlFileOrAbsent(join(this.controlPlaneRoot,
|
|
2734
|
+
return readControlFileOrAbsent(join(this.controlPlaneRoot, STORE_JOURNAL_FILE), "transaction journal") !== undefined;
|
|
2950
2735
|
}
|
|
2951
2736
|
auditReadLedger() {
|
|
2952
2737
|
const path = join(this.controlPlaneRoot, LEDGER_FILE);
|
|
@@ -17,7 +17,7 @@ export type { OriginClearanceRow, OriginClearanceEvent, OriginClearanceShadow }
|
|
|
17
17
|
export { MEMORY_ORIGIN_CAUSES, writableRootOf } from "./types.js";
|
|
18
18
|
export type { MemoryBackend, MemoryEntry, MemoryEntryFrontmatter, MemoryEntryOrigin, MemoryOriginCause, MemoryScopeEnumeration, MemoryEntryDistilled, MemoryEntryDistilledInput, MemoryEntryHeader, ScoredMemoryEntry, NotePatch, PatchReport, MaterializedFile, MemorySessionHandle, HarvestReport, HarvestRejection, HarvestRejectionCode, MemoryAnnouncement, ScanFinding, } from "./types.js";
|
|
19
19
|
export { memoryBackendContract, assertMemoryBackendSearchEquivalence, type MemoryBackendContractHooks, } from "./memory-backend-contract.js";
|
|
20
|
-
export { SCOPE_SEGMENT_MAX_ENCODED, PROJECT_MARKER_PATH, encodeScopeSegment, decodeScopeSegment, parseScopeKey, formatUserScope, formatOrgScope, formatProjScope, formatUserProjScope, isPersonalScope, assertScopeContractPlacement, formatProjectMarker, parseProjectMarker, resolveProjectId, PROJECT_ID_REGEX, type ParsedScopeKey, } from "./scope-contract.js";
|
|
20
|
+
export { SCOPE_SEGMENT_MAX_ENCODED, PROJECT_MARKER_PATH, encodeScopeSegment, decodeScopeSegment, parseScopeKey, formatUserScope, formatOrgScope, formatProjScope, formatUserProjScope, isPersonalScope, isOrgScopeKey, assertScopeContractPlacement, formatProjectMarker, parseProjectMarker, resolveProjectId, PROJECT_ID_REGEX, type ParsedScopeKey, } from "./scope-contract.js";
|
|
21
21
|
export { migrateScope, type MigrateScopeReport } from "./migrate.js";
|
|
22
22
|
export { materializeEntriesToFiles, harvestFilesToPatches, projectionsToWriteBack, screenInboundEntries, REMOTE_HARVEST_PER_FILE_BYTES, REMOTE_MASS_DELETION_FUSE_RATIO, type RemoteMemoryFile, type RemoteMemoryBaseline, type RemoteMaterialization, type RemoteHarvestResult, type InboundEntryFinding, } from "./data-plane.js";
|
|
23
23
|
export { reconcileMemoryEntries, nextSyncBaseline, mergeRecallHits, type MemorySyncCursor, type MemorySyncConflict, type MemorySyncPlan, type RecallSource, } from "./sync.js";
|
|
@@ -15,7 +15,7 @@ export { DISTILLER_DEFAULT_MAX_INPUTS_PER_PRODUCT, LLM_DISTILLER_CONTRACT, LLM_D
|
|
|
15
15
|
export { CONSOLIDATION_DRIVER_PLANS_DIR, CONSOLIDATION_DRIVER_RUNS_FILE, archiveDistillerPlan, readConsolidationDriverRun, runMemoryConsolidationDriver, } from "./consolidation-driver.js";
|
|
16
16
|
export { MEMORY_ORIGIN_CAUSES, writableRootOf } from "./types.js";
|
|
17
17
|
export { memoryBackendContract, assertMemoryBackendSearchEquivalence, } from "./memory-backend-contract.js";
|
|
18
|
-
export { SCOPE_SEGMENT_MAX_ENCODED, PROJECT_MARKER_PATH, encodeScopeSegment, decodeScopeSegment, parseScopeKey, formatUserScope, formatOrgScope, formatProjScope, formatUserProjScope, isPersonalScope, assertScopeContractPlacement, formatProjectMarker, parseProjectMarker, resolveProjectId, PROJECT_ID_REGEX, } from "./scope-contract.js";
|
|
18
|
+
export { SCOPE_SEGMENT_MAX_ENCODED, PROJECT_MARKER_PATH, encodeScopeSegment, decodeScopeSegment, parseScopeKey, formatUserScope, formatOrgScope, formatProjScope, formatUserProjScope, isPersonalScope, isOrgScopeKey, assertScopeContractPlacement, formatProjectMarker, parseProjectMarker, resolveProjectId, PROJECT_ID_REGEX, } from "./scope-contract.js";
|
|
19
19
|
export { migrateScope } from "./migrate.js";
|
|
20
20
|
export { materializeEntriesToFiles, harvestFilesToPatches, projectionsToWriteBack, screenInboundEntries, REMOTE_HARVEST_PER_FILE_BYTES, REMOTE_MASS_DELETION_FUSE_RATIO, } from "./data-plane.js";
|
|
21
21
|
export { reconcileMemoryEntries, nextSyncBaseline, mergeRecallHits, } from "./sync.js";
|