@sema-agent/core 7.70.0 → 7.71.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/CHANGELOG.md +728 -0
- package/dist/agents/agent-transcript-tool.js +43 -19
- package/dist/agents/inherited-tool-pool.d.ts +5 -1
- package/dist/agents/inherited-tool-pool.js +6 -0
- package/dist/agents/retain-ledger.js +2 -0
- package/dist/agents/send-message-tool.d.ts +12 -1
- package/dist/agents/send-message-tool.js +47 -9
- package/dist/agents/subagent.js +31 -10
- package/dist/agents/tool-filter.js +1 -2
- package/dist/agents/verify.js +13 -2
- package/dist/agents/yield-adoption.js +11 -1
- package/dist/brain/claude-model-id.d.ts +11 -0
- package/dist/brain/claude-model-id.js +3 -1
- package/dist/config/catalog.js +10 -1
- package/dist/config/defaults.d.ts +3 -0
- package/dist/config/defaults.js +1 -0
- package/dist/core/allow-entry.js +1 -2
- package/dist/core/ask-origin.d.ts +55 -21
- package/dist/core/ask-origin.js +19 -11
- package/dist/core/ask-question.d.ts +4 -7
- package/dist/core/ask-question.js +2 -4
- package/dist/core/ask-unresolvable-notice.d.ts +17 -3
- package/dist/core/ask-unresolvable-notice.js +18 -4
- package/dist/core/attachment-source.d.ts +1 -1
- package/dist/core/attachment-source.js +2 -0
- package/dist/core/auto-compaction.d.ts +14 -4
- package/dist/core/auto-compaction.js +3 -2
- package/dist/core/auto-strip.js +2 -0
- package/dist/core/caller-text.d.ts +2 -33
- package/dist/core/caller-text.js +2 -23
- package/dist/core/caller-tool-name.js +1 -2
- package/dist/core/canonical-json.d.ts +9 -0
- package/dist/core/canonical-json.js +6 -0
- package/dist/core/checkpoint-features.d.ts +43 -80
- package/dist/core/checkpoint-features.js +10 -20
- package/dist/core/checkpoint-generation.d.ts +89 -19
- package/dist/core/checkpoint-generation.js +89 -14
- package/dist/core/checkpoint-queries.d.ts +95 -15
- package/dist/core/checkpoint-queries.js +108 -7
- package/dist/core/checkpoint-rekey.d.ts +2 -1
- package/dist/core/checkpoint-rekey.js +2 -2
- package/dist/core/checkpoint-requirements.d.ts +7 -6
- package/dist/core/checkpoint-requirements.js +2 -5
- package/dist/core/checkpoint-row-verdict.d.ts +3 -4
- package/dist/core/checkpoint-row-verdict.js +20 -41
- package/dist/core/checkpoint-store.d.ts +65 -41
- package/dist/core/checkpoint-store.js +28 -14
- package/dist/core/command-sandbox.d.ts +5 -3
- package/dist/core/command-sandbox.js +17 -9
- package/dist/core/config-refusal-codes.d.ts +1 -1
- package/dist/core/config-refusal-codes.js +1 -0
- package/dist/core/declaration-words.d.ts +2 -1
- package/dist/core/declaration-words.js +13 -2
- package/dist/core/effective-path-target.d.ts +23 -0
- package/dist/core/effective-path-target.js +15 -1
- package/dist/core/engine-attestation.d.ts +5 -1
- package/dist/core/engine-attestation.js +1 -0
- package/dist/core/engine-capabilities.d.ts +14 -9
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +62 -32
- package/dist/core/engine-version.js +1 -1
- package/dist/core/entries-not-applied.d.ts +1 -1
- package/dist/core/entries-not-applied.js +1 -0
- package/dist/core/file-history-store.d.ts +95 -11
- package/dist/core/file-history-store.js +117 -19
- package/dist/core/gate-fold.js +13 -7
- package/dist/core/gate-lanes.js +9 -9
- package/dist/core/governance-codes.d.ts +56 -7
- package/dist/core/governance-codes.js +105 -7
- package/dist/core/grant-holder.d.ts +53 -0
- package/dist/core/grant-holder.js +80 -0
- package/dist/core/hooks.d.ts +7 -3
- package/dist/core/hooks.js +2 -2
- package/dist/core/locked-config.d.ts +7 -1
- package/dist/core/locked-config.js +9 -2
- package/dist/core/mcp-call-meta.d.ts +52 -7
- package/dist/core/mcp-call-meta.js +21 -2
- package/dist/core/mcp-host-read.d.ts +1 -1
- package/dist/core/mcp-server-spec.d.ts +18 -0
- package/dist/core/mcp-server-spec.js +1 -0
- package/dist/core/mcp.js +2 -2
- package/dist/core/member-outcome.d.ts +22 -1
- package/dist/core/member-outcome.js +18 -6
- package/dist/core/memory-engine/delegation-settlement.js +5 -5
- package/dist/core/memory-engine/engine.js +19 -19
- package/dist/core/memory-engine/file-backend.d.ts +7 -2
- package/dist/core/memory-engine/file-backend.js +14 -12
- package/dist/core/memory-engine/frontmatter.js +1 -1
- package/dist/core/memory-engine/index.d.ts +1 -0
- package/dist/core/memory-engine/index.js +1 -0
- package/dist/core/memory-engine/layout.d.ts +34 -9
- package/dist/core/memory-engine/layout.js +36 -19
- package/dist/core/memory-engine/memory-deployment.js +8 -8
- package/dist/core/memory-engine/mount-failed-notice.d.ts +8 -5
- package/dist/core/memory-engine/mount-failed-notice.js +5 -2
- package/dist/core/mode-policy.d.ts +5 -0
- package/dist/core/mode-policy.js +6 -0
- package/dist/core/mods/host.d.ts +2 -1
- package/dist/core/mods/host.js +7 -6
- package/dist/core/mods/kernel/index.d.ts +1 -1
- package/dist/core/mods/kernel/index.js +1 -1
- package/dist/core/mods/kernel/registration.d.ts +5 -2
- package/dist/core/mods/kernel/registration.js +19 -3
- package/dist/core/mods/package.d.ts +12 -1
- package/dist/core/mods/package.js +36 -9
- package/dist/core/mods/stations.d.ts +7 -1
- package/dist/core/mods/stations.js +17 -3
- package/dist/core/mods/teammate-stations.d.ts +4 -1
- package/dist/core/mods/teammate-stations.js +1 -1
- package/dist/core/native-signal.d.ts +13 -0
- package/dist/core/native-signal.js +18 -0
- package/dist/core/park-resumability.d.ts +16 -14
- package/dist/core/park-resumability.js +9 -4
- package/dist/core/path-rule-binding.js +1 -1
- package/dist/core/permission-rule-model.d.ts +11 -5
- package/dist/core/permission-rule-model.js +5 -3
- package/dist/core/permission-rule-org.js +1 -1
- package/dist/core/permission-rule-provider.d.ts +5 -1
- package/dist/core/permission-rule-provider.js +6 -1
- package/dist/core/permission-rule-session.d.ts +35 -5
- package/dist/core/permission-rule-session.js +32 -1
- package/dist/core/permission-rule-store.d.ts +5 -1
- package/dist/core/permission-rule-store.js +28 -5
- package/dist/core/permission-rules.d.ts +2 -2
- package/dist/core/permission-rules.js +2 -3
- package/dist/core/principal-name.d.ts +12 -0
- package/dist/core/principal-name.js +6 -2
- package/dist/core/read-root-grant-screen.d.ts +7 -6
- package/dist/core/read-root-grant-screen.js +7 -8
- package/dist/core/remote-env.d.ts +42 -8
- package/dist/core/resume-config-judge.js +1 -1
- package/dist/core/resume-startup-cause.d.ts +19 -4
- package/dist/core/resume-startup-cause.js +25 -6
- package/dist/core/rewind-conversation.d.ts +4 -0
- package/dist/core/rewrite-rejudge.d.ts +9 -1
- package/dist/core/rewrite-rejudge.js +11 -1
- package/dist/core/rule-offer-read.js +3 -2
- package/dist/core/runner/assemble-result.d.ts +21 -11
- package/dist/core/runner/assemble-result.js +24 -4
- package/dist/core/runner/boundary-reminders.d.ts +104 -0
- package/dist/core/runner/boundary-reminders.js +108 -0
- package/dist/core/runner/branch-writeback.d.ts +21 -7
- package/dist/core/runner/branch-writeback.js +44 -6
- package/dist/core/runner/command-sandbox-frame.js +2 -1
- package/dist/core/runner/compact-session.js +11 -4
- package/dist/core/runner/constraint-layers.d.ts +24 -5
- package/dist/core/runner/constraint-layers.js +21 -2
- package/dist/core/runner/continuation-gate.js +3 -1
- package/dist/core/runner/contracts.d.ts +83 -13
- package/dist/core/runner/cross-boundary-lane.js +2 -1
- package/dist/core/runner/delegation-owner.d.ts +246 -45
- package/dist/core/runner/delegation-owner.js +237 -63
- package/dist/core/runner/expire-settle.d.ts +17 -0
- package/dist/core/runner/expire-settle.js +8 -2
- package/dist/core/runner/file-history-request.d.ts +4 -3
- package/dist/core/runner/file-history-request.js +4 -1
- package/dist/core/runner/file-history-restore.d.ts +11 -3
- package/dist/core/runner/file-history-restore.js +11 -3
- package/dist/core/runner/gate-exit.d.ts +22 -1
- package/dist/core/runner/gate-exit.js +12 -14
- package/dist/core/runner/nested-memory-content.js +1 -1
- package/dist/core/runner/nested-memory-lane.d.ts +10 -2
- package/dist/core/runner/nested-memory-lane.js +29 -8
- package/dist/core/runner/own-model-money-door.d.ts +13 -0
- package/dist/core/runner/own-model-money-door.js +17 -0
- package/dist/core/runner/park-commit.d.ts +4 -2
- package/dist/core/runner/park-commit.js +2 -1
- package/dist/core/runner/permission-rule-lanes.d.ts +4 -0
- package/dist/core/runner/permission-rule-lanes.js +7 -0
- package/dist/core/runner/person-path-rows.js +1 -1
- package/dist/core/runner/placement-fence.d.ts +8 -2
- package/dist/core/runner/placement-fence.js +8 -3
- package/dist/core/runner/policy-throw.d.ts +3 -2
- package/dist/core/runner/policy-throw.js +2 -2
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +23 -14
- package/dist/core/runner/prepare-acquire-reconcile.js +33 -15
- package/dist/core/runner/prepare-artifact.d.ts +14 -1
- package/dist/core/runner/prepare-artifact.js +7 -2
- package/dist/core/runner/prepare-ask-lane.d.ts +8 -0
- package/dist/core/runner/prepare-ask-lane.js +14 -5
- package/dist/core/runner/prepare-boundary-parks.js +5 -4
- package/dist/core/runner/prepare-config-doors.d.ts +9 -4
- package/dist/core/runner/prepare-config-doors.js +25 -8
- package/dist/core/runner/prepare-defer-classify.d.ts +8 -4
- package/dist/core/runner/prepare-defer-classify.js +6 -6
- package/dist/core/runner/prepare-execution-env.d.ts +4 -1
- package/dist/core/runner/prepare-execution-env.js +8 -3
- package/dist/core/runner/prepare-file-history.d.ts +26 -0
- package/dist/core/runner/prepare-file-history.js +15 -1
- package/dist/core/runner/prepare-inherited-gate.d.ts +8 -3
- package/dist/core/runner/prepare-inherited-gate.js +9 -2
- package/dist/core/runner/prepare-leg-adoption.d.ts +2 -2
- package/dist/core/runner/prepare-park-ask.js +8 -5
- package/dist/core/runner/prepare-policy-chain.d.ts +5 -0
- package/dist/core/runner/prepare-policy-chain.js +18 -7
- package/dist/core/runner/prepare-prompt-assembly.d.ts +3 -0
- package/dist/core/runner/prepare-prompt-assembly.js +4 -3
- package/dist/core/runner/prepare-suspend-saga.d.ts +4 -1
- package/dist/core/runner/prepare-suspend-saga.js +19 -5
- package/dist/core/runner/prepare-task.d.ts +2 -5
- package/dist/core/runner/prepare-task.js +71 -26
- package/dist/core/runner/prepare-turn-wiring.js +7 -5
- package/dist/core/runner/prepare-workspace-restore.js +59 -28
- package/dist/core/runner/read-root-grant.d.ts +1 -0
- package/dist/core/runner/read-root-grant.js +1 -2
- package/dist/core/runner/resume-admission.d.ts +3 -0
- package/dist/core/runner/resume-admission.js +6 -4
- package/dist/core/runner/resume-apply.js +7 -5
- package/dist/core/runner/resume-claim.d.ts +2 -2
- package/dist/core/runner/resume-claim.js +4 -4
- package/dist/core/runner/resume-policy-outcome.d.ts +1 -1
- package/dist/core/runner/resume-policy-outcome.js +6 -4
- package/dist/core/runner/resume-preflight.d.ts +3 -0
- package/dist/core/runner/resume-preflight.js +10 -3
- package/dist/core/runner/rewind-conversation.js +11 -4
- package/dist/core/runner/rewind-files.js +29 -14
- package/dist/core/runner/rewind-outcome.d.ts +27 -0
- package/dist/core/runner/rewind-outcome.js +14 -0
- package/dist/core/runner/run-attachment-seats.js +2 -1
- package/dist/core/runner/run-clock-and-content.js +2 -0
- package/dist/core/runner/run-identity-wiring.js +2 -0
- package/dist/core/runner/run-leg.js +11 -1
- package/dist/core/runner/run-notification-lane.d.ts +3 -0
- package/dist/core/runner/run-notification-lane.js +2 -2
- package/dist/core/runner/run-settle-and-teardown.d.ts +4 -2
- package/dist/core/runner/run-settle-and-teardown.js +52 -40
- package/dist/core/runner/run-stop-and-final-verify.d.ts +4 -0
- package/dist/core/runner/run-stop-and-final-verify.js +5 -4
- package/dist/core/runner/run-terminal-adoption.d.ts +1 -1
- package/dist/core/runner/run-terminal-adoption.js +3 -3
- package/dist/core/runner/run-turn-boundary.js +7 -0
- package/dist/core/runner/runtask.d.ts +7 -4
- package/dist/core/runner/runtask.js +18 -9
- package/dist/core/runner/session-call-grant-station.d.ts +64 -0
- package/dist/core/runner/session-call-grant-station.js +119 -0
- package/dist/core/runner/session-file-state-replay.js +2 -2
- package/dist/core/runner/session-prompt-seats.d.ts +95 -0
- package/dist/core/runner/session-prompt-seats.js +62 -0
- package/dist/core/runner/session-rule-policy.js +1 -1
- package/dist/core/runner/session-write-ledger.d.ts +8 -0
- package/dist/core/runner/session-write-ledger.js +16 -0
- package/dist/core/runner/side-call-account.js +5 -1
- package/dist/core/runner/stop-tail-notice.d.ts +7 -0
- package/dist/core/runner/stop-tail-notice.js +23 -8
- package/dist/core/runner/stream-reap.js +4 -2
- package/dist/core/runner/stream-settle-backstop.d.ts +1 -1
- package/dist/core/runner/stream-settle-backstop.js +17 -18
- package/dist/core/runner/terminal-account.js +17 -8
- package/dist/core/runner/terminal-projection.d.ts +3 -2
- package/dist/core/runner/terminal-projection.js +1 -1
- package/dist/core/runner/tool-turn-repair-seat.d.ts +2 -2
- package/dist/core/runner/tool-turn-repair-seat.js +12 -7
- package/dist/core/runner/turn-attachments.d.ts +22 -1
- package/dist/core/runner/turn-attachments.js +20 -3
- package/dist/core/runner-deps.d.ts +6 -2
- package/dist/core/secret-env.d.ts +26 -6
- package/dist/core/secret-env.js +6 -6
- package/dist/core/session-call-grant-screen.d.ts +58 -0
- package/dist/core/session-call-grant-screen.js +18 -0
- package/dist/core/session-call-grant.d.ts +93 -0
- package/dist/core/session-call-grant.js +524 -0
- package/dist/core/session-checkout.d.ts +3 -0
- package/dist/core/session-checkout.js +8 -3
- package/dist/core/session-policy-store.d.ts +14 -0
- package/dist/core/session-policy-store.js +16 -2
- package/dist/core/session-store.d.ts +18 -1
- package/dist/core/session-store.js +20 -4
- package/dist/core/session.d.ts +36 -4
- package/dist/core/shared-artifact-reads.d.ts +93 -0
- package/dist/core/shared-artifact-reads.js +94 -0
- package/dist/core/skill-grant.js +1 -1
- package/dist/core/skills-directory.d.ts +9 -45
- package/dist/core/skills-directory.js +9 -722
- package/dist/core/spend-account.js +3 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +22 -4
- package/dist/core/store-contracts/checkpoint-store-contract.js +363 -29
- package/dist/core/store-contracts/file-history-store-contract.d.ts +11 -3
- package/dist/core/store-contracts/file-history-store-contract.js +62 -2
- package/dist/core/store-contracts/grant-fixture.d.ts +52 -0
- package/dist/core/store-contracts/grant-fixture.js +84 -0
- package/dist/core/store-contracts/session-repo-contract.js +18 -0
- package/dist/core/store-contracts/session-store-contract.d.ts +15 -1
- package/dist/core/store-contracts/session-store-contract.js +211 -2
- package/dist/core/store-contracts/workflow-journal-store-contract.js +47 -8
- package/dist/core/suspend-lane-reasons.d.ts +13 -0
- package/dist/core/suspend-lane-reasons.js +5 -0
- package/dist/core/synthetic-read-verdict.d.ts +5 -3
- package/dist/core/synthetic-read-verdict.js +1 -1
- package/dist/core/task-limits.d.ts +15 -0
- package/dist/core/task-notification.d.ts +33 -7
- package/dist/core/task-notification.js +34 -9
- package/dist/core/task-registry-agent.d.ts +1 -1
- package/dist/core/task-registry-agent.js +18 -7
- package/dist/core/task-registry-shared.d.ts +29 -4
- package/dist/core/task-registry-shared.js +7 -0
- package/dist/core/task-registry.d.ts +21 -1
- package/dist/core/task-registry.js +36 -9
- package/dist/core/task-result.d.ts +55 -1
- package/dist/core/task-spec.d.ts +17 -3
- package/dist/core/terminal-cause.d.ts +68 -5
- package/dist/core/tool-catalog-entries.js +1 -1
- package/dist/core/tool-check-reading.js +2 -1
- package/dist/core/tool-errors.js +1 -0
- package/dist/core/tool-list-grammar.d.ts +0 -47
- package/dist/core/tool-list-grammar.js +1 -75
- package/dist/core/tool-model-gate.d.ts +7 -11
- package/dist/core/tool-model-gate.js +5 -8
- package/dist/core/tool-name-aliases.js +2 -3
- package/dist/core/tool-name-readings.d.ts +4 -0
- package/dist/core/tool-name-readings.js +1 -0
- package/dist/core/tool-policy.d.ts +46 -4
- package/dist/core/tool-policy.js +47 -18
- package/dist/core/tool-result-store.d.ts +0 -24
- package/dist/core/tool-result-store.js +1 -36
- package/dist/core/tool-spec.d.ts +8 -4
- package/dist/core/untrusted-egress.js +2 -2
- package/dist/core/untrusted-text.d.ts +8 -0
- package/dist/core/untrusted-text.js +14 -0
- package/dist/core/user-attachment.d.ts +16 -1
- package/dist/core/user-attachment.js +42 -18
- package/dist/core/wiring-manifest.d.ts +4 -9
- package/dist/core/wiring-manifest.js +1 -1
- package/dist/core/workflow-journal-store.d.ts +55 -8
- package/dist/core/workflow-journal-store.js +34 -10
- package/dist/core/workflow-run-store-contract.js +56 -1
- package/dist/core/workflow-run-store.d.ts +43 -19
- package/dist/core/workflow-run-store.js +17 -2
- package/dist/engine/execution-env/node-execution-env.d.ts +3 -0
- package/dist/engine/execution-env/node-execution-env.js +4 -0
- package/dist/engine/harness/agent-harness.d.ts +10 -5
- package/dist/engine/harness/agent-harness.js +12 -4
- package/dist/engine/harness/types.d.ts +18 -0
- package/dist/engine/llm/tool-turns.d.ts +1 -1
- package/dist/engine/llm/types.d.ts +5 -4
- package/dist/engine/session/memory-repo.d.ts +15 -3
- package/dist/engine/session/memory-repo.js +21 -3
- package/dist/engine/session/memory-storage.d.ts +5 -0
- package/dist/engine/session/memory-storage.js +8 -3
- package/dist/engine/session/repo-utils.d.ts +9 -0
- package/dist/engine/session/repo-utils.js +14 -0
- package/dist/engine/session/storage-base.d.ts +20 -7
- package/dist/engine/session/storage-base.js +13 -1
- package/dist/index.d.ts +37 -19
- package/dist/index.js +30 -15
- package/dist/internal/harness.d.ts +1 -1
- package/dist/internal/harness.js +1 -1
- package/dist/orchestration/run-workflow-tool.d.ts +13 -1
- package/dist/orchestration/run-workflow-tool.js +101 -32
- package/dist/orchestration/workflow-park-adoption.d.ts +309 -92
- package/dist/orchestration/workflow-park-adoption.js +588 -323
- package/dist/orchestration/workflow-tree-id.d.ts +66 -0
- package/dist/orchestration/workflow-tree-id.js +66 -0
- package/dist/orchestration/workflow-types.d.ts +90 -11
- package/dist/orchestration/workflow-types.js +10 -1
- package/dist/orchestration/workflow.d.ts +30 -4
- package/dist/orchestration/workflow.js +424 -114
- package/dist/prompt-assembly/catalog/constitution.js +5 -1
- package/dist/prompt-assembly/catalog/core-behavior.d.ts +3 -4
- package/dist/prompt-assembly/catalog/core-behavior.js +61 -22
- package/dist/prompt-assembly/catalog/environment.js +2 -2
- package/dist/prompt-assembly/catalog/events.d.ts +16 -0
- package/dist/prompt-assembly/catalog/events.js +2 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.js +72 -44
- package/dist/prompt-assembly/catalog/locales/zh-Hans/environment.js +2 -2
- package/dist/prompt-assembly/catalog/locales/zh-Hans/events.js +2 -0
- package/dist/prompt-assembly/catalog/schema.d.ts +5 -1
- package/dist/prompt-assembly/catalog/schema.js +2 -0
- package/dist/prompt-assembly/catalog/sections.js +3 -14
- package/dist/prompt-assembly/event-registry.js +2 -0
- package/dist/prompt-assembly/select.js +1 -0
- package/dist/prompt-assembly/tool-catalog.d.ts +10 -7
- package/dist/prompt-assembly/tool-catalog.js +21 -7
- package/dist/prompt-assembly/types.d.ts +3 -0
- package/dist/prompts/default.d.ts +4 -1
- package/dist/prompts/default.js +6 -0
- package/dist/stores/file/checkpoint-store.d.ts +11 -10
- package/dist/stores/file/checkpoint-store.js +36 -10
- package/dist/stores/file/file-history-store.d.ts +6 -0
- package/dist/stores/file/file-history-store.js +21 -4
- package/dist/stores/file/fs-atomic.d.ts +1 -1
- package/dist/stores/file/index.d.ts +14 -4
- package/dist/stores/file/index.js +21 -5
- package/dist/stores/file/process-anchor.d.ts +9 -1
- package/dist/stores/file/session-policy-store.js +2 -17
- package/dist/stores/file/session-store.d.ts +27 -0
- package/dist/stores/file/session-store.js +81 -9
- package/dist/stores/file/workflow-journal-store.d.ts +14 -4
- package/dist/stores/file/workflow-journal-store.js +32 -24
- package/dist/stores/file/workflow-run-store.d.ts +15 -4
- package/dist/stores/file/workflow-run-store.js +76 -0
- package/dist/tools/artifact/artifact-tool.d.ts +10 -3
- package/dist/tools/artifact/artifact-tool.js +16 -1
- package/dist/tools/fs/bash-program-position.d.ts +10 -4
- package/dist/tools/fs/bash-program-position.js +11 -8
- package/dist/tools/fs/bash-readonly-classifier.d.ts +3 -1
- package/dist/tools/fs/bash-readonly-classifier.js +9 -2
- package/dist/tools/fs/find-actions.d.ts +30 -16
- package/dist/tools/fs/find-actions.js +272 -19
- package/dist/tools/fs/fs-bash.js +8 -5
- package/dist/tools/fs/fs-shared.d.ts +0 -29
- package/dist/tools/fs/fs-shared.js +0 -5
- package/dist/tools/fs/fs-write.js +2 -1
- package/dist/tools/fs/read-deny.d.ts +6 -1
- package/dist/tools/fs/read-deny.js +6 -1
- package/dist/tools/fs/read-floor.d.ts +6 -0
- package/dist/tools/fs/read-floor.js +5 -1
- package/dist/tools/fs/removal-actions.d.ts +43 -0
- package/dist/tools/fs/removal-actions.js +25 -0
- package/dist/tools/fs/removal-targets.d.ts +2 -21
- package/dist/tools/fs/removal-targets.js +2 -3
- package/dist/tools/fs/safety.d.ts +37 -1
- package/dist/tools/fs/safety.js +52 -0
- package/dist/tools/fs/shell-climb.d.ts +46 -0
- package/dist/tools/fs/shell-climb.js +79 -0
- package/dist/tools/fs/shell-read-check.js +47 -19
- package/dist/tools/fs/shell-read-establish.js +36 -22
- package/dist/tools/fs/shell-read-judge.d.ts +10 -2
- package/dist/tools/fs/shell-read-judge.js +4 -4
- package/dist/tools/fs/shell-read-plan.d.ts +3 -0
- package/dist/tools/fs/shell-read-plan.js +1 -1
- package/dist/tools/fs/shell-read-workdir.js +3 -2
- package/dist/tools/fs/shell-read-write-targets.d.ts +4 -3
- package/dist/tools/fs/shell-read-write-targets.js +3 -0
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +169 -15
- package/wire-changes/core-stores-sql@7.71.0.json +40 -0
- package/wire-changes/core@7.71.0.json +5827 -0
- package/wire-changes/mods-kernel@7.71.0.json +52 -0
- package/wire-changes/primitives@7.71.0.json +473 -0
- package/wire-changes/wiki-gate@7.71.0.json +40 -0
- package/dist/core/frontmatter-fence.d.ts +0 -10
- package/dist/core/frontmatter-fence.js +0 -6
- package/dist/core/permission-rule-syntax.d.ts +0 -46
- package/dist/core/permission-rule-syntax.js +0 -52
|
@@ -3,8 +3,8 @@ import { types } from "node:util";
|
|
|
3
3
|
import { callerKey } from "../core/caller-text.js";
|
|
4
4
|
import { isPlainRecord, receive } from "../core/mods/kernel/receive.js";
|
|
5
5
|
import { assertNoRetiredKeys, RETIRED_TOOL_SPEC_KEYS } from "../core/retired-keys.js";
|
|
6
|
-
import { isPromptTraitName } from "./catalog/schema.js";
|
|
7
|
-
import { traitsHold } from "./select.js";
|
|
6
|
+
import { isPromptTraitName, TOOL_CARD_FACT_NAMES } from "./catalog/schema.js";
|
|
7
|
+
import { factsHold, traitsHold } from "./select.js";
|
|
8
8
|
import { projectToolSchema } from "../brain/tool-schema-projection.js";
|
|
9
9
|
export function contractOriginOf(contractId) {
|
|
10
10
|
return contractId.startsWith("core.") ? "core" : "caller";
|
|
@@ -78,8 +78,8 @@ function descriptionVariantsProblem(variants) {
|
|
|
78
78
|
return `${at} is not an object`;
|
|
79
79
|
const r = v;
|
|
80
80
|
for (const k of Object.keys(r))
|
|
81
|
-
if (k !== "id" && k !== "traits" && k !== "text")
|
|
82
|
-
return `${at} carries ${callerKey(k)} (id, traits, text only)`;
|
|
81
|
+
if (k !== "id" && k !== "traits" && k !== "facts" && k !== "text")
|
|
82
|
+
return `${at} carries ${callerKey(k)} (id, traits, facts, text only)`;
|
|
83
83
|
if (typeof r.id !== "string" || !VARIANT_ID.test(r.id))
|
|
84
84
|
return `${at}.id is not 1–64 characters of [A-Za-z0-9._-]`;
|
|
85
85
|
if (ids.has(r.id))
|
|
@@ -87,11 +87,25 @@ function descriptionVariantsProblem(variants) {
|
|
|
87
87
|
ids.add(r.id);
|
|
88
88
|
if (typeof r.text !== "string" || r.text.trim() === "")
|
|
89
89
|
return `${at}.text is not a non-blank string`;
|
|
90
|
+
if (r.facts !== undefined) {
|
|
91
|
+
const f = r.facts;
|
|
92
|
+
if (f === null || typeof f !== "object" || Array.isArray(f))
|
|
93
|
+
return `${at}.facts is not an object`;
|
|
94
|
+
const entries = Object.entries(f);
|
|
95
|
+
if (entries.length === 0)
|
|
96
|
+
return `${at}.facts is empty (use \`description\`)`;
|
|
97
|
+
for (const [k, want] of entries) {
|
|
98
|
+
if (!TOOL_CARD_FACT_NAMES.includes(k))
|
|
99
|
+
return `${at}.facts names ${callerKey(k)} (${TOOL_CARD_FACT_NAMES.join(", ")} only)`;
|
|
100
|
+
if (typeof want !== "boolean")
|
|
101
|
+
return `${at}.facts.${k} is not a boolean`;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
90
104
|
const t = r.traits;
|
|
91
105
|
if (t === null || typeof t !== "object" || Array.isArray(t))
|
|
92
106
|
return `${at}.traits is not an object`;
|
|
93
107
|
const lists = Object.entries(t);
|
|
94
|
-
if (lists.length === 0)
|
|
108
|
+
if (lists.length === 0 && r.facts === undefined)
|
|
95
109
|
return `${at}.traits is empty (use \`description\`)`;
|
|
96
110
|
for (const [k, list] of lists) {
|
|
97
111
|
if (k !== "allOf" && k !== "noneOf")
|
|
@@ -130,14 +144,14 @@ export function assertToolCardDeclarations(tools) {
|
|
|
130
144
|
throw descriptionVariantsRefusal(t["name"], problem);
|
|
131
145
|
});
|
|
132
146
|
}
|
|
133
|
-
export function mountDescriptionVariant(tool, traits) {
|
|
147
|
+
export function mountDescriptionVariant(tool, traits, facts) {
|
|
134
148
|
const variants = tool.descriptionVariants;
|
|
135
149
|
const problem = descriptionVariantsProblem(variants);
|
|
136
150
|
if (problem !== undefined)
|
|
137
151
|
throw descriptionVariantsRefusal(tool.name, problem);
|
|
138
152
|
const earlier = tool[CARD_VARIANT];
|
|
139
153
|
const unconditional = earlier?.unconditional ?? tool.description;
|
|
140
|
-
const chosen = tool.descriptionVariants?.find((v) => traitsHold(v.traits, traits));
|
|
154
|
+
const chosen = tool.descriptionVariants?.find((v) => traitsHold(v.traits, traits) && factsHold(v.facts, facts));
|
|
141
155
|
if (chosen === undefined && earlier === undefined)
|
|
142
156
|
return tool;
|
|
143
157
|
const face = { ...tool, description: chosen?.text ?? unconditional };
|
|
@@ -42,6 +42,9 @@ export interface PromptRuntimeFacts {
|
|
|
42
42
|
/** The `Skill` tool is on this leg's mounted roster (it mounts only with a non-empty skill set the valve leaves it for, so the
|
|
43
43
|
* skills listing is announced too): admits the skill-invocation sentence. OPTIONAL — absence reads as false. */
|
|
44
44
|
skillToolMounted?: boolean;
|
|
45
|
+
/** The session is a shell-first one (its tree's one judgment, `shellFirstSessionOf`): selects the shell-first Bash card.
|
|
46
|
+
* OPTIONAL — absence reads as false. */
|
|
47
|
+
shellFirstSession?: boolean;
|
|
45
48
|
/** What the tool valve left the model on this leg (`toolFaceClassOf`): the catalog reads it as `workToolsAbsent` /
|
|
46
49
|
* `actingToolsAbsent`. OPTIONAL — absence reads as `acting` (the text every leg with a tool to act through receives). */
|
|
47
50
|
toolFace?: import("../core/tool-face.js").ToolFaceClass;
|
|
@@ -46,7 +46,7 @@ export declare const MEMORY_SAFETY = "## Memory\nWhen you save a durable note to
|
|
|
46
46
|
export declare const MEMORY_HYGIENE = "What's worth saving \u2014 organize by topic, not by when it happened:\n- who the user is \u2014 role, expertise, durable preferences;\n- guidance the user gave on HOW to work \u2014 corrections and confirmed approaches, with the reason why;\n- ongoing goals or constraints that aren't derivable from the code or its history;\n- pointers to external resources (URLs, dashboards, tickets).\n\nHygiene:\n- Convert relative dates (\"yesterday\", \"last week\") to absolute dates, so the note stays interpretable later.\n- Before saving, check what memory already holds: update an existing note rather than writing a near-duplicate, and remove a note that turns out to be wrong.\n- Don't save what the code, its history, or this conversation already records (structure, past fixes, transient task state). If asked to remember something obvious, save what was non-obvious about it instead.";
|
|
47
47
|
/** The refuse-harmful-use security boundary (composed on every shape; safety text is never gated). */
|
|
48
48
|
export declare const CYBER_RISK: string;
|
|
49
|
-
/** The never-guess-URLs rule (composed on
|
|
49
|
+
/** The never-guess-URLs rule (composed on the full shape only, #4586). */
|
|
50
50
|
export declare const URL_SAFETY: string;
|
|
51
51
|
/** The tool-result retention reminder: old results can be cleared, summarized or budgeted away, so the model
|
|
52
52
|
* writes down what it needs. */
|
|
@@ -205,6 +205,9 @@ export declare function judgedUserTimeZone(clientContext: {
|
|
|
205
205
|
* catalog's canonical rendering); the facts fill its slots, sanitized here, and choose which branch message renders.
|
|
206
206
|
* Each fact is read once (a copy), so the value a line renders is the value its guard tested.
|
|
207
207
|
*/
|
|
208
|
+
/** #4913: a leg with nothing to act through (`actingToolsAbsent`) is told none of what a tool may reach — the scratchpad, the
|
|
209
|
+
* extra read and write roots (they list the scratchpad), the egress word. */
|
|
210
|
+
export declare function envFactsForFace(facts: EnvironmentFacts, actingToolsAbsent: boolean): EnvironmentFacts;
|
|
208
211
|
export declare function buildEnvironmentContext(given: EnvironmentFacts, text?: EngineText): string;
|
|
209
212
|
/**
|
|
210
213
|
* Optional preset role base for **software-engineering** roles (de-branded engineering disciplines). NOT the
|
package/dist/prompts/default.js
CHANGED
|
@@ -67,6 +67,12 @@ export function judgedUserTimeZone(clientContext) {
|
|
|
67
67
|
const tz = clientContext?.timeZone;
|
|
68
68
|
return tz !== undefined && isValidTimeZone(tz) ? tz : undefined;
|
|
69
69
|
}
|
|
70
|
+
export function envFactsForFace(facts, actingToolsAbsent) {
|
|
71
|
+
if (!actingToolsAbsent)
|
|
72
|
+
return facts;
|
|
73
|
+
const { scratchpadDir: _scratchpad, sandboxEgress: _egress, additionalDirectories: _roots, additionalReadDirectories: _readRoots, ...rest } = facts;
|
|
74
|
+
return rest;
|
|
75
|
+
}
|
|
70
76
|
export function buildEnvironmentContext(given, text = engineTextFor()) {
|
|
71
77
|
const { ...facts } = given;
|
|
72
78
|
const lines = [];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type RetentionDeclaration } from "../../core/retention.js";
|
|
2
2
|
import { type ExecutionOutcomeRecordWord } from "../../core/checkpoint-execution-record.js";
|
|
3
|
-
import { type HolderJudge } from "../../core/checkpoint-generation.js";
|
|
3
|
+
import { type HolderJudge, type StoreHolderFence } from "../../core/checkpoint-generation.js";
|
|
4
|
+
import type { CheckpointWriteOptions } from "../../core/checkpoint-store.js";
|
|
4
5
|
import { type Checkpoint, type PendingSteerEntry, type PendingSteerInput, type CheckpointFaultMode, type CheckpointStore, type CheckpointSummary, type CheckpointToken, type ReopenReason, type ResolveExpectation, type ResumeOutcome } from "../../core/checkpoint-store.js";
|
|
5
6
|
import type { GateOutcome } from "../../core/gate-outcome.js";
|
|
6
7
|
import { type CheckpointDeleteGuard, type CheckpointOverdueCursor, type CheckpointOverdueQuery, type CheckpointPage, type CheckpointRowRead, type CheckpointSessionCursor, type CheckpointSessionQuery } from "../../core/checkpoint-queries.js";
|
|
@@ -112,7 +113,9 @@ export interface FileCheckpointStoreOptions {
|
|
|
112
113
|
sessionHeadOf?: (sessionId: string) => Promise<{
|
|
113
114
|
readonly owner: string | null;
|
|
114
115
|
} | undefined>;
|
|
115
|
-
/** The
|
|
116
|
+
/** The deployment's grant judge ({@link HolderJudge}), asked on every write that carries a holder (`put`, `setPendingSteer`,
|
|
117
|
+
* `expire`, `resolve`); with it the store declares `fence = { holder: "writes" }`. It belongs to the directory's shared ledger: a
|
|
118
|
+
* second store over the same directory built with another judge (or with one beside none) is refused (`config.invalid_checkpoint_store`). */
|
|
116
119
|
holderIsCurrent?: HolderJudge;
|
|
117
120
|
/** The store's managed-retention declaration ({@link import("../../core/checkpoint-store.js").CheckpointStore.retention}), stated by
|
|
118
121
|
* the party that runs the sweep; default `"none"`, a third word refused (`config.retention_capability`). */
|
|
@@ -187,10 +190,8 @@ export declare class FileCheckpointStore implements CheckpointStore {
|
|
|
187
190
|
* same JSON reading as the ledger line); the declaration is what makes the loss visible to the mint BEFORE the
|
|
188
191
|
* row is filed. */
|
|
189
192
|
readonly fidelity: "json";
|
|
190
|
-
/**
|
|
191
|
-
readonly fence?:
|
|
192
|
-
readonly holder: true;
|
|
193
|
-
};
|
|
193
|
+
/** `{ holder: "writes" }`, declared exactly when the store was built with a `holderIsCurrent` judge. */
|
|
194
|
+
readonly fence?: StoreHolderFence;
|
|
194
195
|
private readonly holderIsCurrent;
|
|
195
196
|
private readonly fsyncEnabled;
|
|
196
197
|
private readonly compactEvery;
|
|
@@ -223,13 +224,13 @@ export declare class FileCheckpointStore implements CheckpointStore {
|
|
|
223
224
|
* the in-memory reference cannot do because it has no I/O here. Both halves are now in the base.
|
|
224
225
|
*/
|
|
225
226
|
private commit;
|
|
226
|
-
put(token: CheckpointToken, cp: Checkpoint): Promise<void>;
|
|
227
|
+
put(token: CheckpointToken, cp: Checkpoint, opts?: CheckpointWriteOptions): Promise<void>;
|
|
227
228
|
get(token: CheckpointToken): Promise<Checkpoint | null>;
|
|
228
|
-
resolve(token: CheckpointToken, scope: string, outcome: ResumeOutcome,
|
|
229
|
+
resolve(token: CheckpointToken, scope: string, outcome: ResumeOutcome, given?: ResolveExpectation): Promise<boolean>;
|
|
229
230
|
recordExecutionOutcome(token: CheckpointToken, scope: string, gate: GateOutcome): Promise<ExecutionOutcomeRecordWord>;
|
|
230
231
|
reopen(token: CheckpointToken, scope: string, reason: ReopenReason, expect?: Pick<ResolveExpectation, "rev">): Promise<boolean>;
|
|
231
|
-
setPendingSteer(token: CheckpointToken, scope: string, steer: PendingSteerInput): Promise<boolean>;
|
|
232
|
-
expire(token: CheckpointToken, scope: string): Promise<boolean>;
|
|
232
|
+
setPendingSteer(token: CheckpointToken, scope: string, steer: PendingSteerInput, opts?: CheckpointWriteOptions): Promise<boolean>;
|
|
233
|
+
expire(token: CheckpointToken, scope: string, opts?: CheckpointWriteOptions): Promise<boolean>;
|
|
233
234
|
reap(scope: string, cutoff: number): Promise<number>;
|
|
234
235
|
listByScope(scope: string): Promise<CheckpointSummary[]>;
|
|
235
236
|
listScopes(): Promise<string[]>;
|
|
@@ -4,9 +4,10 @@ import { memberPresent, optionKeys, receiveOptions } from "../../core/own-proper
|
|
|
4
4
|
import { LEDGER_COMPACT_EVERY_DEFAULTS, readLedgerTuning } from "./ledger-tuning.js";
|
|
5
5
|
import { readRetentionDeclaration } from "../../core/retention.js";
|
|
6
6
|
import { checkpointExecutionRecorded, executionRecordDisposition, ExecutionOutcomeConflictError, } from "../../core/checkpoint-execution-record.js";
|
|
7
|
-
import { checkpointHolderMatches, checkpointOccMatches, checkpointRevOf } from "../../core/checkpoint-generation.js";
|
|
7
|
+
import { checkpointHolderMatches, checkpointOccMatches, checkpointRevOf, holderJudgedCurrent, joinHolderJudge, readHolderJudge } from "../../core/checkpoint-generation.js";
|
|
8
|
+
import { holderSupersededError } from "../../core/grant-holder.js";
|
|
8
9
|
import { appendPendingSteer, CheckpointError, checkpointRowMatches, encodeAtFidelity, summarizeStoredCheckpoint, validatePendingSteer, winnerFromOutcome, } from "../../core/checkpoint-store.js";
|
|
9
|
-
import { CHECKPOINT_ROW_SHAPE, checkpointDeadlinePassed, deleteSessionRowsAtStart, ownerSessionRowsDelete, unreadableSessionRowsDelete, readCheckpointOverdueQuery, readCheckpointSessionQuery, selectOverduePage, selectSessionPage, } from "../../core/checkpoint-queries.js";
|
|
10
|
+
import { CHECKPOINT_ROW_SHAPE, checkpointDeadlinePassed, storedCheckpointRowRefusal, deleteSessionRowsAtStart, ownerSessionRowsDelete, unreadableSessionRowsDelete, readCheckpointOverdueQuery, readCheckpointSessionQuery, selectOverduePage, selectSessionPage, } from "../../core/checkpoint-queries.js";
|
|
10
11
|
import { oneStepRekeyAnswerOf, readIdentityRekeyInput } from "../../core/identity-rekey.js";
|
|
11
12
|
import { checkpointRekeySelects, rekeyCheckpointRow } from "../../core/checkpoint-rekey.js";
|
|
12
13
|
import { ledgerPathsOf, readLedgerSettled, SharedLedgerTable } from "./shared-ledger.js";
|
|
@@ -143,6 +144,7 @@ export async function rekeyCheckpointDirectory(root, input, onUnrekeyable) {
|
|
|
143
144
|
ledger.release();
|
|
144
145
|
}
|
|
145
146
|
}
|
|
147
|
+
const ledgerJudges = new WeakMap();
|
|
146
148
|
export class FileCheckpointStore {
|
|
147
149
|
durability = "durable";
|
|
148
150
|
retention;
|
|
@@ -165,14 +167,21 @@ export class FileCheckpointStore {
|
|
|
165
167
|
assertAdoptionBootGate(root, "FileCheckpointStore");
|
|
166
168
|
const tuning = readLedgerTuning(opts, "FileCheckpointStore", "FileCheckpointStore options");
|
|
167
169
|
this.fsyncEnabled = tuning.fsync;
|
|
168
|
-
this.holderIsCurrent = opts.holderIsCurrent;
|
|
169
|
-
if (
|
|
170
|
-
this.fence = Object.freeze({ holder:
|
|
170
|
+
this.holderIsCurrent = readHolderJudge("FileCheckpointStore.holderIsCurrent", opts.holderIsCurrent);
|
|
171
|
+
if (this.holderIsCurrent !== undefined)
|
|
172
|
+
this.fence = Object.freeze({ holder: "writes" });
|
|
171
173
|
this.compactEvery = tuning.compactEvery;
|
|
172
174
|
this.discloseCorrupt = guardCorruptSink(opts.onCorruptRead);
|
|
173
175
|
const paths = ledgerPathsOf(root, CHECKPOINT_LEDGER);
|
|
174
176
|
this.ledgerPath = paths.ledgerPath;
|
|
175
177
|
this.ledger = checkpointLedgers.acquire({ ...paths, ...(this.discloseCorrupt !== undefined ? { onCorruptRead: this.discloseCorrupt } : {}) });
|
|
178
|
+
try {
|
|
179
|
+
joinHolderJudge(ledgerJudges, this.ledger, this.holderIsCurrent, "checkpoint", `FileCheckpointStore(${paths.dir})`);
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
this.ledger.release();
|
|
183
|
+
throw err;
|
|
184
|
+
}
|
|
176
185
|
const headOf = opts.sessionHeadOf;
|
|
177
186
|
if (headOf !== undefined) {
|
|
178
187
|
const remove = (token, row) => this.withLock(token, () => {
|
|
@@ -196,8 +205,11 @@ export class FileCheckpointStore {
|
|
|
196
205
|
commit(ev, fsync) {
|
|
197
206
|
commitCheckpointEvent(this.ledger, ev, fsync, this.compactEvery);
|
|
198
207
|
}
|
|
199
|
-
async put(token, cp) {
|
|
208
|
+
async put(token, cp, opts) {
|
|
209
|
+
const holder = opts?.holder;
|
|
200
210
|
return this.withLock(token, () => {
|
|
211
|
+
if (!holderJudgedCurrent(holder, this.holderIsCurrent, "checkpoint"))
|
|
212
|
+
throw holderSupersededError("put");
|
|
201
213
|
if (this.cps.has(token)) {
|
|
202
214
|
throw new CheckpointError("checkpoint.already_exists", `checkpoint token already exists`);
|
|
203
215
|
}
|
|
@@ -206,11 +218,18 @@ export class FileCheckpointStore {
|
|
|
206
218
|
});
|
|
207
219
|
}
|
|
208
220
|
async get(token) {
|
|
221
|
+
if (!this.cps.has(token))
|
|
222
|
+
return null;
|
|
209
223
|
const cp = this.cps.get(token);
|
|
210
|
-
|
|
224
|
+
const refused = storedCheckpointRowRefusal(token, cp);
|
|
225
|
+
if (refused !== undefined)
|
|
226
|
+
throw refused;
|
|
227
|
+
return structuredClone(cp);
|
|
211
228
|
}
|
|
212
|
-
async resolve(token, scope, outcome,
|
|
229
|
+
async resolve(token, scope, outcome, given) {
|
|
230
|
+
const holder = given?.holder;
|
|
213
231
|
return this.withLock(token, () => {
|
|
232
|
+
const expect = given === undefined ? undefined : holder === undefined ? given : { rev: given.rev, holder };
|
|
214
233
|
if (this.fault === "resolve-before-commit") {
|
|
215
234
|
this.fault = null;
|
|
216
235
|
throw new Error("injected fault: resolve before commit");
|
|
@@ -258,9 +277,12 @@ export class FileCheckpointStore {
|
|
|
258
277
|
return true;
|
|
259
278
|
});
|
|
260
279
|
}
|
|
261
|
-
async setPendingSteer(token, scope, steer) {
|
|
280
|
+
async setPendingSteer(token, scope, steer, opts) {
|
|
262
281
|
const clean = validatePendingSteer(steer);
|
|
282
|
+
const holder = opts?.holder;
|
|
263
283
|
return this.withLock(token, () => {
|
|
284
|
+
if (!holderJudgedCurrent(holder, this.holderIsCurrent, "checkpoint"))
|
|
285
|
+
throw holderSupersededError("setPendingSteer");
|
|
264
286
|
const cp = this.cps.get(token);
|
|
265
287
|
if (!checkpointRowMatches(cp, scope, "pending")) {
|
|
266
288
|
return false;
|
|
@@ -273,12 +295,16 @@ export class FileCheckpointStore {
|
|
|
273
295
|
return true;
|
|
274
296
|
});
|
|
275
297
|
}
|
|
276
|
-
async expire(token, scope) {
|
|
298
|
+
async expire(token, scope, opts) {
|
|
299
|
+
const holder = opts?.holder;
|
|
277
300
|
return this.withLock(token, () => {
|
|
278
301
|
const cp = this.cps.get(token);
|
|
279
302
|
if (!checkpointRowMatches(cp, scope, "pending")) {
|
|
280
303
|
return false;
|
|
281
304
|
}
|
|
305
|
+
if (!holderJudgedCurrent(holder, this.holderIsCurrent, "checkpoint")) {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
282
308
|
this.commit({ t: "expire", token }, true);
|
|
283
309
|
return true;
|
|
284
310
|
});
|
|
@@ -86,6 +86,10 @@ export interface FileFileHistoryStoreOptions {
|
|
|
86
86
|
* would fill.
|
|
87
87
|
*/
|
|
88
88
|
retention?: FileHistoryRetentionPolicy;
|
|
89
|
+
/** The most bytes one stored copy of a file may hold — the in-memory store's option, read and judged by the same two functions
|
|
90
|
+
* (`readMaxBlobBytes`, `blobOverStoreLimit`): a copy over it is refused `too_large` at `trackEdit`, `snapshot`, `importHistory` and
|
|
91
|
+
* `blobExchange.put`, nothing of the call committed. Omitted ⇒ no bound. */
|
|
92
|
+
maxBlobBytes?: number;
|
|
89
93
|
}
|
|
90
94
|
export declare class FileFileHistoryStore implements FileHistoryStore {
|
|
91
95
|
private readonly base;
|
|
@@ -149,6 +153,8 @@ export declare class FileFileHistoryStore implements FileHistoryStore {
|
|
|
149
153
|
private readonly reapedCache;
|
|
150
154
|
/** Resolved boundary cap, or `null` for the explicit `"unbounded"` opt-out (host owns the GC). */
|
|
151
155
|
private readonly boundaryKeep;
|
|
156
|
+
/** {@link FileFileHistoryStoreOptions.maxBlobBytes}, as read at construction. */
|
|
157
|
+
private readonly maxBlobBytes;
|
|
152
158
|
/** Highest {@link BoundaryJson.committedAt} this instance has minted — see {@link nextCommittedAt}. */
|
|
153
159
|
private lastCommittedAt;
|
|
154
160
|
/** Scopes whose on-disk maximum has already been folded into {@link lastCommittedAt} — see there. */
|
|
@@ -5,14 +5,14 @@ import { join } from "node:path";
|
|
|
5
5
|
import { thrownText } from "../../core/thrown-value.js";
|
|
6
6
|
import { readUnreadableDeleteId } from "../../core/session.js";
|
|
7
7
|
import { readFileHistoryScope } from "../../engine/session/repo-utils.js";
|
|
8
|
-
import { applyFileRestoreViaEnv, boundaryPublishVerdict, worldStillMatchesMint, annulProofFailure, captureFileBackupViaEnv, modeProvenDifferent, placeProvenDifferent, blobPutRefusal, fileHistoryEntryFrozen, fileHistoryEntryTravels, fileHistoryParentIdentTravels, fileHistoryExportDigest, fileHistoryTargetOf, caughtFault, DAMAGED_RECORD, FILE_HISTORY_UNREFERENCED_BLOB_GRACE_MS, isBlobAddress, resolveTrackKey, resolveTrackedFile, trackKeyForAnnul, trackKeyForEdit, validateFileHistoryExport, } from "../../core/file-history-store.js";
|
|
8
|
+
import { applyFileRestoreViaEnv, boundaryPublishVerdict, worldStillMatchesMint, annulProofFailure, captureFileBackupViaEnv, modeProvenDifferent, placeProvenDifferent, blobPutRefusal, blobOverStoreLimit, overLimit, readMaxBlobBytes, fileHistoryEntryFrozen, fileHistoryEntryTravels, fileHistoryParentIdentTravels, fileHistoryExportDigest, fileHistoryTargetOf, caughtFault, DAMAGED_RECORD, FILE_HISTORY_UNREFERENCED_BLOB_GRACE_MS, isBlobAddress, resolveTrackKey, resolveTrackedFile, trackKeyForAnnul, trackKeyForEdit, validateFileHistoryExport, } from "../../core/file-history-store.js";
|
|
9
9
|
import { fileHistoryBoundariesToKeep, resolveFileHistoryRetention } from "../../core/file-history-retention.js";
|
|
10
10
|
import { atomicWriteFile, ensureDir, sanitizePathComponent, sanitizeScope, writeThenLink } from "./fs-atomic.js";
|
|
11
11
|
import { guardCorruptSink } from "./corrupt-read-sink.js";
|
|
12
12
|
import { isAbsoluteForFamily } from "../../tools/fs/safety.js";
|
|
13
13
|
import { assertAdoptionBootGate } from "./adoption/marker.js";
|
|
14
14
|
import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
|
|
15
|
-
const FILE_FILE_HISTORY_STORE_OPTION_KEYS = optionKeys()({ onCorruptRead: 0, retention: 0 });
|
|
15
|
+
const FILE_FILE_HISTORY_STORE_OPTION_KEYS = optionKeys()({ onCorruptRead: 0, retention: 0, maxBlobBytes: 0 });
|
|
16
16
|
function trackedDigest(rows) {
|
|
17
17
|
const canonical = [...rows]
|
|
18
18
|
.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0))
|
|
@@ -154,6 +154,7 @@ export class FileFileHistoryStore {
|
|
|
154
154
|
writers = new Map();
|
|
155
155
|
reapedCache = new Map();
|
|
156
156
|
boundaryKeep;
|
|
157
|
+
maxBlobBytes;
|
|
157
158
|
lastCommittedAt = 0;
|
|
158
159
|
seededScopes = new Set();
|
|
159
160
|
nextCommittedAt(scope) {
|
|
@@ -179,6 +180,7 @@ export class FileFileHistoryStore {
|
|
|
179
180
|
const opts = receiveOptions(options, "FileFileHistoryStore", FILE_FILE_HISTORY_STORE_OPTION_KEYS);
|
|
180
181
|
assertAdoptionBootGate(root, "FileFileHistoryStore");
|
|
181
182
|
this.boundaryKeep = resolveFileHistoryRetention("FileFileHistoryStore", opts?.retention);
|
|
183
|
+
this.maxBlobBytes = readMaxBlobBytes("FileFileHistoryStore", opts?.maxBlobBytes);
|
|
182
184
|
this.base = join(root, "file-history");
|
|
183
185
|
this.blobsDir = join(this.base, "blobs");
|
|
184
186
|
this.scopesDir = join(this.base, "scopes");
|
|
@@ -481,6 +483,9 @@ export class FileFileHistoryStore {
|
|
|
481
483
|
return { ok: true, minted: true };
|
|
482
484
|
}
|
|
483
485
|
if (cap.state === "file") {
|
|
486
|
+
const over = overLimit(blobOverStoreLimit(cap.bytes, this.maxBlobBytes, `the first-touch copy of ${absPath}`));
|
|
487
|
+
if (over !== undefined)
|
|
488
|
+
return over;
|
|
484
489
|
this.putBlob(cap.hash, cap.bytes);
|
|
485
490
|
tracked.set(key, { baseAvailable: true, mintId, keyKind: kind, keyFamily: family, versions: [{ version: 1, blobHash: cap.hash, backupTime: now, ...(cap.mode !== undefined ? { mode: cap.mode } : {}), ...(cap.parentIdent !== undefined ? { parentIdent: cap.parentIdent } : {}) }] });
|
|
486
491
|
this.writeTracked(scope, tracked);
|
|
@@ -686,6 +691,11 @@ export class FileFileHistoryStore {
|
|
|
686
691
|
staged.set(key, { kind: "unchanged", version: last.version });
|
|
687
692
|
continue;
|
|
688
693
|
}
|
|
694
|
+
const over = overLimit(blobOverStoreLimit(cap.bytes, this.maxBlobBytes, `the boundary's copy of ${resolved.abs}`));
|
|
695
|
+
if (over !== undefined) {
|
|
696
|
+
nestedSetAdd(this.spentAttempts, scope, entryId);
|
|
697
|
+
return over;
|
|
698
|
+
}
|
|
689
699
|
appendFileSync(journal, `${JSON.stringify({ blob: cap.hash })}\n`);
|
|
690
700
|
this.putBlob(cap.hash, cap.bytes);
|
|
691
701
|
staged.set(key, { kind: "changed", blobHash: cap.hash, ...(cap.mode !== undefined ? { mode: cap.mode } : {}), ...(cap.parentIdent !== undefined ? { parentIdent: cap.parentIdent } : {}) });
|
|
@@ -893,7 +903,7 @@ export class FileFileHistoryStore {
|
|
|
893
903
|
}
|
|
894
904
|
blobExchange = {
|
|
895
905
|
put: async (hash, bytes) => {
|
|
896
|
-
const refused = blobPutRefusal(hash, bytes);
|
|
906
|
+
const refused = blobPutRefusal(hash, bytes) ?? overLimit(blobOverStoreLimit(bytes, this.maxBlobBytes, `the blob put under ${hash}`));
|
|
897
907
|
if (refused !== undefined)
|
|
898
908
|
return refused;
|
|
899
909
|
try {
|
|
@@ -1433,8 +1443,12 @@ export class FileFileHistoryStore {
|
|
|
1433
1443
|
catch {
|
|
1434
1444
|
local = undefined;
|
|
1435
1445
|
}
|
|
1436
|
-
if (local !== undefined && createHash("sha256").update(local).digest("hex") === v.blobHash)
|
|
1446
|
+
if (local !== undefined && createHash("sha256").update(local).digest("hex") === v.blobHash) {
|
|
1447
|
+
const over = overLimit(blobOverStoreLimit(local, this.maxBlobBytes, `blob ${v.blobHash}`));
|
|
1448
|
+
if (over !== undefined)
|
|
1449
|
+
return over;
|
|
1437
1450
|
continue;
|
|
1451
|
+
}
|
|
1438
1452
|
this.disclose(this.blobPath(v.blobHash), "locally stored blob does not hash to its own name — the import re-fetched it from the source");
|
|
1439
1453
|
safeRm(this.blobPath(v.blobHash));
|
|
1440
1454
|
}
|
|
@@ -1450,6 +1464,9 @@ export class FileFileHistoryStore {
|
|
|
1450
1464
|
if (createHash("sha256").update(bytes).digest("hex") !== v.blobHash) {
|
|
1451
1465
|
return { ok: false, error: { code: "adopt_failed", message: `source blob ${v.blobHash} fails content-address integrity — refused, nothing published` } };
|
|
1452
1466
|
}
|
|
1467
|
+
const over = overLimit(blobOverStoreLimit(bytes, this.maxBlobBytes, `source blob ${v.blobHash}`));
|
|
1468
|
+
if (over !== undefined)
|
|
1469
|
+
return over;
|
|
1453
1470
|
this.putBlob(v.blobHash, bytes);
|
|
1454
1471
|
}
|
|
1455
1472
|
}
|
|
@@ -37,7 +37,7 @@ export declare function ensureDir(dir: string): void;
|
|
|
37
37
|
* 5. fsync the containing DIRECTORY (persists the rename itself).
|
|
38
38
|
* On any failure the temp is unlinked so a crashed write leaves no scratch behind.
|
|
39
39
|
*/
|
|
40
|
-
export declare function atomicWriteFile(tmpDir: string, target: string, bytes: string): void;
|
|
40
|
+
export declare function atomicWriteFile(tmpDir: string, target: string, bytes: string | Uint8Array): void;
|
|
41
41
|
/**
|
|
42
42
|
* Read a JSONL file and return every COMPLETE, parseable record — the universal torn-tail recovery (§2.2):
|
|
43
43
|
* - the last segment, when no `\n` ends it, is judged as every line is (`@contract store.read_back_shape_judged`):
|
|
@@ -15,6 +15,7 @@ import type { WorkflowJournalStore } from "../../core/workflow-journal-store.js"
|
|
|
15
15
|
import type { UsageWindowStore } from "../../core/usage-window-store.js";
|
|
16
16
|
import type { EngineStorageBackend } from "../../core/engine-storage-backend.js";
|
|
17
17
|
import { type RetentionDeclaration } from "../../core/retention.js";
|
|
18
|
+
import { type HolderJudge } from "../../core/checkpoint-generation.js";
|
|
18
19
|
export { FileCheckpointStore, CHECKPOINT_LEDGER_EVENT_KINDS, readCheckpointLedger, type CheckpointLedgerEventKind, type CheckpointLedgerReading, type FileCheckpointStoreOptions, type ReadCheckpointLedgerOptions, } from "./checkpoint-store.js";
|
|
19
20
|
export { FileSessionRepo, type FileSessionRepoOptions } from "./session-store.js";
|
|
20
21
|
export { FileToolResultStore } from "./tool-result-store.js";
|
|
@@ -70,10 +71,19 @@ export interface FileStorageBackendOptions {
|
|
|
70
71
|
/** `TtlSessionStore` idle-eviction policy. Default `"forget"` (§7 decision 5 — durable history is never
|
|
71
72
|
* deleted by an idle timer). */
|
|
72
73
|
evict?: EvictPolicy;
|
|
73
|
-
/** Checkpoint store tuning (fsync cadence for `put`/`setPendingSteer`, ledger compaction threshold
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
|
|
74
|
+
/** Checkpoint store tuning (fsync cadence for `put`/`setPendingSteer`, ledger compaction threshold). The corrupt-read sink, the
|
|
75
|
+
* session head read and the grant judge are the backend's own — the sink is {@link FileStorageBackendOptions.onCorruptRead} (one
|
|
76
|
+
* failure grammar, one sink), the head read is its session store's, and the judge is {@link FileStorageBackendOptions.holderIsCurrent}
|
|
77
|
+
* (one grant table, one judge) — so none is accepted here; a `holderIsCurrent` here is refused, naming where it moved. */
|
|
78
|
+
checkpoint?: Omit<FileCheckpointStoreOptions, "onCorruptRead" | "sessionHeadOf" | "retention" | "holderIsCurrent">;
|
|
79
|
+
/**
|
|
80
|
+
* The deployment's grant judge ({@link HolderJudge}) — ONE for the backend, handed to both stores that judge a holder: the session
|
|
81
|
+
* store's repo (every append and leaf move carrying one) and the checkpoint store (`put`, `setPendingSteer`, `expire`, `resolve`). With
|
|
82
|
+
* it both declare `fence = { holder: "writes" }`; without it neither does, and a run carrying a holder over this backend is refused at
|
|
83
|
+
* its store seats. A deployment has one grant table, so it has one judge; the same function object is what every other store it
|
|
84
|
+
* builds over this data root must be given too (a judge built later is wired through one trampoline function).
|
|
85
|
+
*/
|
|
86
|
+
holderIsCurrent?: HolderJudge;
|
|
77
87
|
/**
|
|
78
88
|
* The managed-retention declaration of this backend's three declaring stores — {@link FileStorageBackend.sessionStore},
|
|
79
89
|
* {@link FileStorageBackend.checkpointStore} and {@link FileStorageBackend.toolResultStore} — stated by the party that runs the sweep
|
|
@@ -20,6 +20,7 @@ import { describeRejectedValue } from "../../core/tool-search-setting.js";
|
|
|
20
20
|
import { deliverEngineNotice } from "../../core/engine-notice.js";
|
|
21
21
|
import { receiveFileHistoryRetention } from "../../core/file-history-retention.js";
|
|
22
22
|
import { readRetentionDeclaration } from "../../core/retention.js";
|
|
23
|
+
import { readHolderJudge } from "../../core/checkpoint-generation.js";
|
|
23
24
|
function nestedOptions(value, member, keys) {
|
|
24
25
|
return value === undefined ? undefined : receiveMembers(value, { subject: `FileStorageBackendOptions.${member}`, unit: "option", moment: "at new FileStorageBackend" }, keys);
|
|
25
26
|
}
|
|
@@ -43,7 +44,19 @@ export { processFingerprint, isProcessLive } from "./fs-atomic.js";
|
|
|
43
44
|
export { declareDataRoot } from "./data-root-declaration.js";
|
|
44
45
|
export { AdoptionError, assertAdoptionBootGate, readRootAdoptionFile, writeRootAdoptionFile, ROOT_ADOPTION_FILE, } from "./adoption/marker.js";
|
|
45
46
|
export { adoptLocalDataRoot, ackAdoptionConfig, witnessAdoptionConfig, listAdoptionQuarantine, readAdoptionStatus, } from "./adoption/adopt.js";
|
|
46
|
-
const FILE_STORAGE_BACKEND_OPTION_KEYS = optionKeys()({ root: 0, evict: 0, checkpoint: 0, retention: 0, fileHistory: 0, sessionPolicy: 0, onCorruptRead: 0, sessions: 0, admit: 0 });
|
|
47
|
+
const FILE_STORAGE_BACKEND_OPTION_KEYS = optionKeys()({ root: 0, evict: 0, checkpoint: 0, holderIsCurrent: 0, retention: 0, fileHistory: 0, sessionPolicy: 0, onCorruptRead: 0, sessions: 0, admit: 0 });
|
|
48
|
+
function refuseNestedHolderJudge(record) {
|
|
49
|
+
let nested;
|
|
50
|
+
try {
|
|
51
|
+
nested = record !== null && typeof record === "object" && Object.prototype.hasOwnProperty.call(record, "holderIsCurrent");
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (nested) {
|
|
57
|
+
throw receiptRefusal("FileStorageBackendOptions.checkpoint.holderIsCurrent is retired: the grant judge is the backend's one, handed to the session store and the checkpoint store alike — pass it as FileStorageBackendOptions.holderIsCurrent");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
47
60
|
function readAdmit(value) {
|
|
48
61
|
if (value === undefined || typeof value === "function")
|
|
49
62
|
return value;
|
|
@@ -64,9 +77,9 @@ function admitRoot(admit, root) {
|
|
|
64
77
|
`returning nothing and refuses by throwing, and this open is synchronous, so a returned value (a promise included) is not an admission`);
|
|
65
78
|
}
|
|
66
79
|
}
|
|
67
|
-
const NESTED_FILE_HISTORY_OPTION_KEYS = optionKeys()({ retention: 0 });
|
|
80
|
+
const NESTED_FILE_HISTORY_OPTION_KEYS = optionKeys()({ retention: 0, maxBlobBytes: 0 });
|
|
68
81
|
const NESTED_SESSION_POLICY_OPTION_KEYS = optionKeys()({ mountedToolNames: 0 });
|
|
69
|
-
const NESTED_CHECKPOINT_OPTION_KEYS = optionKeys()({ fsync: 0, compactEvery: 0
|
|
82
|
+
const NESTED_CHECKPOINT_OPTION_KEYS = optionKeys()({ fsync: 0, compactEvery: 0 });
|
|
70
83
|
export class FileStorageBackend {
|
|
71
84
|
root;
|
|
72
85
|
sessionStore;
|
|
@@ -89,6 +102,9 @@ export class FileStorageBackend {
|
|
|
89
102
|
constructor(options) {
|
|
90
103
|
const opts = receiveOptions(options, "FileStorageBackend", FILE_STORAGE_BACKEND_OPTION_KEYS);
|
|
91
104
|
const retention = readRetentionDeclaration("FileStorageBackendOptions.retention", opts.retention);
|
|
105
|
+
const holderIsCurrent = readHolderJudge("FileStorageBackendOptions.holderIsCurrent", opts.holderIsCurrent);
|
|
106
|
+
const judge = holderIsCurrent !== undefined ? { holderIsCurrent } : undefined;
|
|
107
|
+
refuseNestedHolderJudge(opts.checkpoint);
|
|
92
108
|
const checkpointRecord = nestedOptions(opts.checkpoint, "checkpoint", NESTED_CHECKPOINT_OPTION_KEYS);
|
|
93
109
|
const checkpointOptions = checkpointRecord === undefined ? undefined : { ...checkpointRecord, ...readLedgerTuning(checkpointRecord, "FileCheckpointStore", "FileStorageBackendOptions.checkpoint") };
|
|
94
110
|
const sessionPolicyRecord = nestedOptions(opts.sessionPolicy, "sessionPolicy", NESTED_SESSION_POLICY_OPTION_KEYS);
|
|
@@ -107,12 +123,12 @@ export class FileStorageBackend {
|
|
|
107
123
|
if (admit !== undefined)
|
|
108
124
|
admitRoot(admit, this.root);
|
|
109
125
|
const corruptRead = opts.onCorruptRead !== undefined ? { onCorruptRead: opts.onCorruptRead } : undefined;
|
|
110
|
-
const repo = new FileSessionRepo(this.root, corruptRead);
|
|
126
|
+
const repo = new FileSessionRepo(this.root, { ...corruptRead, ...judge });
|
|
111
127
|
this.fileSessions = repo;
|
|
112
128
|
this.ttl = new TtlSessionStore({ repo, evict: opts.evict ?? "forget", durability: "durable", placements: { subagent: { durability: "durable" } }, retention, ...(opts.sessions !== undefined ? { hooks: opts.sessions } : {}) });
|
|
113
129
|
this.sessionStore = this.ttl;
|
|
114
130
|
const sessionHeadOf = this.ttl.headOf;
|
|
115
|
-
this.fileCheckpoints = new FileCheckpointStore(this.root, { ...checkpointOptions, ...corruptRead, retention, ...(sessionHeadOf !== undefined ? { sessionHeadOf } : {}) });
|
|
131
|
+
this.fileCheckpoints = new FileCheckpointStore(this.root, { ...checkpointOptions, ...corruptRead, ...judge, retention, ...(sessionHeadOf !== undefined ? { sessionHeadOf } : {}) });
|
|
116
132
|
built.push(() => this.fileCheckpoints.close());
|
|
117
133
|
this.checkpointStore = this.fileCheckpoints;
|
|
118
134
|
this.toolResultStore = new FileToolResultStore(this.root, { ...corruptRead, retention });
|
|
@@ -18,7 +18,15 @@
|
|
|
18
18
|
* disk or in a user's macOS directory. The descriptor is a plain number held in this module's table — never a `FileHandle`,
|
|
19
19
|
* which one runtime closes when it is garbage-collected — and it is opened close-on-exec, so a child process never inherits it.
|
|
20
20
|
*/
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* The name of the directory, inside a lock's directory (`<lock dir>/.anchors`), that holds the anchors of the processes holding locks there
|
|
23
|
+
* (`p.<32 hex>`, and `t.<32 hex>` while one is being made). On Linux, for a store on a local disk, each entry is a NAMED PIPE (FIFO) that its holder keeps
|
|
24
|
+
* OPEN for as long as it holds a lock there — so a tool that reads a data root file by file (a backup, an archive, a diagnostic, a test fixture) must SKIP
|
|
25
|
+
* every directory of this name, by name, before it opens anything in it: while its holder lives the pipe opens (the holder keeps both ends) and a read of it blocks
|
|
26
|
+
* the calling thread, since nobody writes to it; one a killed holder left behind has no one holding it, and a read-only `open` of it blocks until a writer comes. A directory of this name is no data (it holds no row of any store), and nothing
|
|
27
|
+
* under it is worth copying: the next holder makes its own. On macOS and on a network disk the engine makes none, so a reader there cannot meet one.
|
|
28
|
+
* (Exported at the package root as `PROCESS_ANCHOR_DIR` — this very constant, which the engine's own readers and writers use.)
|
|
29
|
+
*/
|
|
22
30
|
export declare const ANCHOR_DIR = ".anchors";
|
|
23
31
|
/** What a lock record carries about its writer's anchor. `dev` / `ino` are decimal strings (an inode number can exceed 2^53). */
|
|
24
32
|
export interface AnchorRecord {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { readFileSync, readdirSync, unlinkSync } from "./descriptor-seat.js";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
import { judgeSessionRulesWrite, readMountedToolNames, readSessionRulesShape, SessionPolicyError, sessionRulesPrincipalOf, } from "../../core/session-policy-store.js";
|
|
4
|
+
import { conjoinSessionRuleRows, judgeSessionRulesWrite, readMountedToolNames, readSessionRulesShape, SessionPolicyError, sessionRulesPrincipalOf, } from "../../core/session-policy-store.js";
|
|
5
5
|
import { atomicWriteFile, ensureDir, sanitizeScope } from "./fs-atomic.js";
|
|
6
6
|
import { guardCorruptSink } from "./corrupt-read-sink.js";
|
|
7
7
|
import { assertAdoptionBootGate, readRootAdoptionFile } from "./adoption/marker.js";
|
|
@@ -367,7 +367,7 @@ export class FileSessionPolicyStore {
|
|
|
367
367
|
if (moved !== null && held === null)
|
|
368
368
|
row = { ...moved, rev: Math.max(moved.rev, (heldMark?.__hwm ?? 0) + 1), ...wearing(moved) };
|
|
369
369
|
if (held !== null) {
|
|
370
|
-
const both = moved === null ? held :
|
|
370
|
+
const both = moved === null ? held : conjoinSessionRuleRows(held, moved);
|
|
371
371
|
if (both === undefined) {
|
|
372
372
|
this.disclose({ sessionId, path: fromRow, reason: "a row an earlier release filed under the empty-string principal, in another rule grammar than the session-wide row" });
|
|
373
373
|
throw new SessionPolicyError("corrupt", `session rules for ${JSON.stringify(sessionId)}: an earlier release filed rules for this session under the principal "" (the empty string), which now reads as no principal, and the session-wide rules are written in another rule grammar, so the two cannot be held as one row without reading one row's entries differently — refusing rather than drop either. Repair it: delete the file the disclosure names and write its entries into the session's rules again without a principal. The file's location is reported to the store's corrupt-read disclosure (onCorruptRead), not in this message.`);
|
|
@@ -494,21 +494,6 @@ export class FileSessionPolicyStore {
|
|
|
494
494
|
return rekeySessionPolicyDirectory(this.dir, readPrincipalRekeyInput("SessionPolicyStore.rekeyPrincipal", input), this.anonymousAlias);
|
|
495
495
|
}
|
|
496
496
|
}
|
|
497
|
-
function conjoinBuckets(a, b) {
|
|
498
|
-
const both = (x, y) => (x === undefined ? y?.slice() : y === undefined ? x.slice() : x.filter((e) => y.includes(e)));
|
|
499
|
-
const either = (x, y) => (x === undefined && y === undefined ? undefined : [...new Set([...(x ?? []), ...(y ?? [])])]);
|
|
500
|
-
const out = { toolAllow: both(a.toolAllow, b.toolAllow), toolDeny: either(a.toolDeny, b.toolDeny), allowDirs: both(a.allowDirs, b.allowDirs) };
|
|
501
|
-
return Object.fromEntries(Object.entries(out).filter(([, v]) => v !== undefined));
|
|
502
|
-
}
|
|
503
|
-
function conjoinRows(a, b) {
|
|
504
|
-
const grammar = a.grammar ?? 0;
|
|
505
|
-
if ((b.grammar ?? 0) !== grammar || [a, b].some((r) => r.operatorRules !== undefined && r.operatorRules.grammar !== grammar))
|
|
506
|
-
return undefined;
|
|
507
|
-
const bucketsOf = (r) => ({ ...(r.toolAllow !== undefined ? { toolAllow: r.toolAllow } : {}), ...(r.toolDeny !== undefined ? { toolDeny: r.toolDeny } : {}), ...(r.allowDirs !== undefined ? { allowDirs: r.allowDirs } : {}) });
|
|
508
|
-
const lineOf = (r) => r.operatorRules ?? bucketsOf(r);
|
|
509
|
-
const part = a.operatorRules === undefined && b.operatorRules === undefined ? undefined : { ...conjoinBuckets(lineOf(a), lineOf(b)), grammar };
|
|
510
|
-
return { ...conjoinBuckets(a, b), ...(a.grammar !== undefined || b.grammar !== undefined ? { grammar } : {}), ...(part !== undefined ? { operatorRules: part } : {}) };
|
|
511
|
-
}
|
|
512
497
|
function sameRuleContent(a, b) {
|
|
513
498
|
const canonical = (r) => JSON.stringify({ toolAllow: r.toolAllow, toolDeny: r.toolDeny, allowDirs: r.allowDirs, grammar: r.grammar, operatorRules: r.operatorRules }, (_k, v) => v !== null && typeof v === "object" && !Array.isArray(v) ? Object.fromEntries(Object.entries(v).sort(([x], [y]) => (x < y ? -1 : x > y ? 1 : 0))) : v);
|
|
514
499
|
return canonical(a) === canonical(b);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Session, SessionCreateOptions, SessionForkOptions, SessionHead, SessionMetadata, SessionPlacementRecord, SessionRepo, SessionRepoRowCells, SessionRow, SessionRowExpectation, SessionRowRead, SessionTreeEntry } from "../../internal/harness.js";
|
|
2
2
|
import { type PlacedSessionRow } from "../../core/session.js";
|
|
3
3
|
import { type CorruptReadInfo } from "./corrupt-read-sink.js";
|
|
4
|
+
import { type HolderJudge, type StoreHolderFence } from "../../core/checkpoint-generation.js";
|
|
4
5
|
export interface FileSessionRepoOptions {
|
|
5
6
|
/**
|
|
6
7
|
* Disclosure sink for a durable read this repo treats as ABSENT (ruled 2026-08-03). Same name and
|
|
@@ -33,6 +34,14 @@ export interface FileSessionRepoOptions {
|
|
|
33
34
|
* and on its head read; `TtlSessionStore` refuses a repo of this mode.
|
|
34
35
|
*/
|
|
35
36
|
rowCells?: SessionRepoRowCells;
|
|
37
|
+
/**
|
|
38
|
+
* The deployment's grant judge ({@link HolderJudge}): every append and leaf move carrying a holder is judged by it first, in the
|
|
39
|
+
* write's own synchronous step; with it the repo declares `fence = { holder: "writes" }`. The judge belongs to the shared authority
|
|
40
|
+
* over a session file, not to this repo: a second repo over the same file built with another judge (or with one beside none) is
|
|
41
|
+
* refused when it joins (`config.invalid_session_store`), naming both — a deployment whose judge is built after its stores hands
|
|
42
|
+
* every store one trampoline function.
|
|
43
|
+
*/
|
|
44
|
+
holderIsCurrent?: HolderJudge;
|
|
36
45
|
}
|
|
37
46
|
export declare class FileSessionRepo implements SessionRepo {
|
|
38
47
|
private readonly dir;
|
|
@@ -46,6 +55,9 @@ export declare class FileSessionRepo implements SessionRepo {
|
|
|
46
55
|
private disposed;
|
|
47
56
|
/** {@link FileSessionRepoOptions.rowCells}, read once. */
|
|
48
57
|
readonly rowCells: SessionRepoRowCells;
|
|
58
|
+
/** `{ holder: "writes" }`, declared exactly when the repo was built with a `holderIsCurrent` judge. */
|
|
59
|
+
readonly fence?: StoreHolderFence;
|
|
60
|
+
private readonly holderIsCurrent;
|
|
49
61
|
/** `<root>/sessions`, absolute: the directory this repo writes its transcripts into ({@link SessionRepo.transcriptDirectory}). */
|
|
50
62
|
readonly transcriptDirectory: string;
|
|
51
63
|
constructor(root: string, options?: FileSessionRepoOptions);
|
|
@@ -120,6 +132,12 @@ export declare class FileSessionRepo implements SessionRepo {
|
|
|
120
132
|
/** For a removal or a stamp: `false` while this repo is not disposed; once it is, the row standing is refused and the answer for no
|
|
121
133
|
* row is `true` — the caller returns without touching the file system, so a row put there meanwhile is never removed or stamped. */
|
|
122
134
|
private disposedWithNoRow;
|
|
135
|
+
/**
|
|
136
|
+
* The judge belongs to the authority over a path ({@link joinHolderJudge}): a repo bringing another one is refused before it holds a
|
|
137
|
+
* share, before it evicts a live authority it reads as stale (a repo of another `rowCells` reads another occupant off the same file),
|
|
138
|
+
* and before it lays a row down or replaces one under the id — checked before anything is written.
|
|
139
|
+
*/
|
|
140
|
+
private assertJudgeJoins;
|
|
123
141
|
private storage;
|
|
124
142
|
/**
|
|
125
143
|
* RB-437 — release every shared authority this repo joined (LAST holder ⇒ evict + close the append fd).
|
|
@@ -194,4 +212,13 @@ export declare class FileSessionRepo implements SessionRepo {
|
|
|
194
212
|
preserveActorAssertions?: boolean;
|
|
195
213
|
expect?: SessionRowExpectation;
|
|
196
214
|
}): Promise<SessionHead>;
|
|
215
|
+
/**
|
|
216
|
+
* {@link SessionRepo.recordOwner}: inside the import's writer boundary — the row read whole, judged ({@link recordedOwnerCells}) and the
|
|
217
|
+
* file laid down again with only its header line changed (tmp→fsync→rename; the occupant, placement and lineage cells as they were, every
|
|
218
|
+
* byte after the header as the file held it), with no await between. A live authority that is a view of the row just read is not evicted: it binds a
|
|
219
|
+
* new append log to the replacing file (which repairs a torn tail, as every open of a log does) and answers the recorded owner ({@link FileSessionStorage.adoptRecordedRow}), so a session handed
|
|
220
|
+
* out before the write keeps writing to the row; one that is not a view of it is evicted as an import evicts it. A disposed repo
|
|
221
|
+
* changes no row.
|
|
222
|
+
*/
|
|
223
|
+
recordOwner(sessionId: string, owner: string, expect: SessionRowExpectation): Promise<SessionHead | undefined>;
|
|
197
224
|
}
|