@sema-agent/core 7.55.0 → 7.57.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 +1054 -0
- package/LICENSE +1 -1
- package/dist/agents/cascade.js +1 -1
- package/dist/agents/cc-peer-directory.js +1 -0
- package/dist/agents/child-model-seat.d.ts +0 -11
- package/dist/agents/child-model-seat.js +0 -3
- package/dist/agents/list-agents-tool.d.ts +3 -1
- package/dist/agents/list-agents-tool.js +7 -7
- package/dist/agents/org-delivery-gate.js +3 -4
- package/dist/agents/peer-directory.d.ts +22 -4
- package/dist/agents/peer-directory.js +24 -2
- package/dist/agents/peer-held-queue.d.ts +69 -49
- package/dist/agents/peer-held-queue.js +255 -106
- package/dist/agents/peer-session-drain.js +65 -45
- package/dist/agents/repair-loop.js +2 -2
- package/dist/agents/send-message-tool.js +7 -6
- package/dist/agents/subagent.d.ts +6 -4
- package/dist/agents/subagent.js +72 -68
- package/dist/agents/tool-filter.d.ts +7 -5
- package/dist/agents/tool-filter.js +12 -9
- package/dist/agents/verify.d.ts +3 -2
- package/dist/agents/verify.js +3 -3
- package/dist/brain/anthropic.js +45 -80
- package/dist/brain/media-degrade.d.ts +18 -7
- package/dist/brain/media-degrade.js +13 -2
- package/dist/brain/model-capability.d.ts +37 -0
- package/dist/brain/model-capability.js +34 -0
- package/dist/brain/model-presets.d.ts +2 -8
- package/dist/brain/model-presets.js +1 -6
- package/dist/brain/open-responses.js +23 -34
- package/dist/brain/openai.js +25 -96
- package/dist/brain/provider-dialect.d.ts +3 -2
- package/dist/brain/provider-dialect.js +2 -2
- package/dist/brain/reasoning-request.d.ts +96 -0
- package/dist/brain/reasoning-request.js +174 -0
- package/dist/brain/reasoning.d.ts +11 -11
- package/dist/brain/reasoning.js +4 -3
- package/dist/brain/request-params.d.ts +13 -4
- package/dist/brain/request-params.js +21 -5
- package/dist/brain/status-sink.d.ts +20 -0
- package/dist/brain/status-sink.js +7 -0
- package/dist/brain/stream-engine.d.ts +9 -0
- package/dist/brain/stream-engine.js +24 -10
- package/dist/brain/stream-shared.d.ts +5 -4
- package/dist/brain/stream-shared.js +4 -4
- package/dist/core/a2a.d.ts +2 -1
- package/dist/core/a2a.js +19 -13
- package/dist/core/agent-definition.d.ts +10 -0
- package/dist/core/allow-entry.d.ts +23 -23
- package/dist/core/allow-entry.js +42 -46
- package/dist/core/allow-rule-shadow.d.ts +3 -3
- package/dist/core/approval-object.d.ts +21 -5
- package/dist/core/approval-object.js +44 -17
- package/dist/core/ask-origin.d.ts +66 -20
- package/dist/core/ask-origin.js +63 -23
- package/dist/core/ask-question.d.ts +51 -8
- package/dist/core/ask-question.js +3 -4
- package/dist/core/ask-unresolvable-notice.d.ts +8 -3
- package/dist/core/ask-unresolvable-notice.js +16 -2
- package/dist/core/auto-compaction.d.ts +71 -6
- package/dist/core/auto-compaction.js +42 -26
- package/dist/core/background-agent-store.d.ts +6 -2
- package/dist/core/background-agent-store.js +1 -1
- package/dist/core/checkpoint-generation.d.ts +53 -0
- package/dist/core/checkpoint-generation.js +35 -0
- package/dist/core/checkpoint-queries.d.ts +180 -0
- package/dist/core/checkpoint-queries.js +272 -0
- package/dist/core/checkpoint-requirements.d.ts +19 -1
- package/dist/core/checkpoint-requirements.js +6 -0
- package/dist/core/checkpoint-store.d.ts +105 -53
- package/dist/core/checkpoint-store.js +43 -20
- package/dist/core/cross-boundary-taint.d.ts +6 -5
- package/dist/core/cross-boundary-taint.js +5 -5
- package/dist/core/decision-receipt.d.ts +37 -3
- package/dist/core/decision-receipt.js +17 -17
- package/dist/core/delegation-not-started.d.ts +6 -0
- package/dist/core/delegation-not-started.js +17 -0
- package/dist/core/engine-attestation.d.ts +93 -0
- package/dist/core/engine-attestation.js +70 -0
- package/dist/core/engine-capabilities.d.ts +4 -1
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +32 -12
- package/dist/core/engine-notice.js +6 -0
- package/dist/core/file-history-store.d.ts +104 -22
- package/dist/core/file-history-store.js +37 -19
- package/dist/core/gate-fold.d.ts +1 -1
- package/dist/core/gate-fold.js +22 -10
- package/dist/core/gate-lanes.js +73 -65
- package/dist/core/gate-outcome.d.ts +26 -5
- package/dist/core/gate-outcome.js +26 -0
- package/dist/core/governance-codes.d.ts +5 -1
- package/dist/core/governance-codes.js +6 -0
- package/dist/core/hooks.d.ts +19 -18
- package/dist/core/hooks.js +3 -1
- package/dist/core/host-floor.d.ts +128 -0
- package/dist/core/host-floor.js +206 -0
- package/dist/core/host-target.d.ts +38 -3
- package/dist/core/host-target.js +38 -5
- package/dist/core/mailbox-store.d.ts +62 -1
- package/dist/core/mailbox-store.js +59 -0
- package/dist/core/mcp-name-judge.d.ts +46 -0
- package/dist/core/mcp-name-judge.js +61 -0
- package/dist/core/mcp-probe.d.ts +1 -1
- package/dist/core/mcp-probe.js +2 -5
- package/dist/core/mcp.d.ts +5 -1
- package/dist/core/mcp.js +70 -64
- package/dist/core/memory-engine/consolidation-driver.js +4 -3
- package/dist/core/memory-engine/delegation-settlement.js +15 -24
- package/dist/core/memory-engine/distiller.js +26 -17
- package/dist/core/memory-engine/engine.js +4 -4
- package/dist/core/memory-engine/layout.d.ts +60 -8
- package/dist/core/memory-engine/layout.js +70 -8
- package/dist/core/model-seat.d.ts +10 -3
- package/dist/core/mods/classic-events.d.ts +67 -0
- package/dist/core/mods/classic-events.js +1 -0
- package/dist/core/mods/dollar.d.ts +13 -0
- package/dist/core/mods/extension-call.d.ts +31 -0
- package/dist/core/mods/extension-call.js +43 -0
- package/dist/core/mods/kernel/dispatch.d.ts +20 -3
- package/dist/core/mods/kernel/dispatch.js +140 -69
- package/dist/core/mods/kernel/events.d.ts +47 -11
- package/dist/core/mods/kernel/events.js +66 -42
- package/dist/core/mods/kernel/index.d.ts +4 -4
- package/dist/core/mods/kernel/index.js +2 -2
- package/dist/core/mods/kernel/receive.d.ts +39 -5
- package/dist/core/mods/kernel/receive.js +290 -17
- package/dist/core/mods/kernel/registration.d.ts +33 -2
- package/dist/core/mods/kernel/registration.js +6 -7
- package/dist/core/mods/kernel/site-rules.d.ts +44 -16
- package/dist/core/mods/kernel/site-rules.js +24 -42
- package/dist/core/mods/spec-seats.d.ts +69 -0
- package/dist/core/mods/spec-seats.js +114 -0
- package/dist/core/mods/stations.d.ts +28 -8
- package/dist/core/mods/stations.js +29 -13
- package/dist/core/mods/tool-call.d.ts +79 -0
- package/dist/core/mods/tool-call.js +152 -0
- package/dist/core/namespaced-rule-name.d.ts +32 -38
- package/dist/core/namespaced-rule-name.js +29 -36
- package/dist/core/parent-spec-seat.d.ts +6 -1
- package/dist/core/parent-spec-seat.js +2 -0
- package/dist/core/park-selfcheck.js +3 -0
- package/dist/core/permission-rule-consent.d.ts +24 -3
- package/dist/core/permission-rule-consent.js +136 -41
- package/dist/core/permission-rule-model.d.ts +57 -5
- package/dist/core/permission-rule-model.js +90 -31
- package/dist/core/permission-rule-org.d.ts +6 -2
- package/dist/core/permission-rule-org.js +8 -4
- package/dist/core/permission-rule-provider.d.ts +5 -2
- package/dist/core/permission-rule-provider.js +41 -11
- package/dist/core/permission-rule-store.d.ts +3 -2
- package/dist/core/permission-rule-store.js +11 -2
- package/dist/core/permission-rule-sync.js +3 -2
- package/dist/core/permission-rule-syntax.d.ts +5 -4
- package/dist/core/permission-rule-syntax.js +2 -2
- package/dist/core/permission-rules.d.ts +4 -4
- package/dist/core/permission-rules.js +11 -20
- package/dist/core/persisted-rule-arms.d.ts +2 -2
- package/dist/core/persisted-rule-arms.js +10 -12
- package/dist/core/principal-name.d.ts +20 -0
- package/dist/core/principal-name.js +22 -0
- package/dist/core/prompt-section-seat.js +4 -6
- package/dist/core/protocol-http-auth.d.ts +40 -5
- package/dist/core/protocol-http-auth.js +168 -4
- package/dist/core/protocol-naming.d.ts +20 -0
- package/dist/core/protocol-naming.js +20 -3
- package/dist/core/read-only-shell.d.ts +20 -5
- package/dist/core/read-only-shell.js +29 -14
- package/dist/core/remote-env.d.ts +37 -1
- package/dist/core/remote-env.js +11 -0
- package/dist/core/resume-startup-cause.d.ts +24 -2
- package/dist/core/resume-startup-cause.js +20 -1
- package/dist/core/retired-keys.d.ts +16 -0
- package/dist/core/retired-keys.js +16 -4
- package/dist/core/rewrite-rejudge.d.ts +60 -0
- package/dist/core/rewrite-rejudge.js +36 -0
- package/dist/core/roles.d.ts +28 -1
- package/dist/core/roles.js +81 -26
- package/dist/core/rule-lane-reads.d.ts +20 -15
- package/dist/core/rule-lane-reads.js +45 -17
- package/dist/core/rule-owner.d.ts +3 -3
- package/dist/core/rule-owner.js +3 -2
- package/dist/core/runner/announce-once-ledger.d.ts +14 -0
- package/dist/core/runner/announce-once-ledger.js +5 -0
- package/dist/core/runner/assemble-result.d.ts +1 -0
- package/dist/core/runner/assemble-result.js +1 -1
- package/dist/core/runner/call-hook-stations.d.ts +3 -2
- package/dist/core/runner/caller-roster.d.ts +16 -4
- package/dist/core/runner/caller-roster.js +33 -6
- package/dist/core/runner/capability-withheld-seat.d.ts +5 -0
- package/dist/core/runner/capability-withheld-seat.js +24 -0
- package/dist/core/runner/classifier-ladder.d.ts +7 -9
- package/dist/core/runner/classifier-ladder.js +3 -3
- package/dist/core/runner/compact-session.d.ts +10 -0
- package/dist/core/runner/compact-session.js +202 -0
- package/dist/core/runner/compaction-call-options.d.ts +2 -2
- package/dist/core/runner/compaction-seams.d.ts +21 -1
- package/dist/core/runner/compaction-seams.js +11 -8
- package/dist/core/runner/construction-doors.js +3 -0
- package/dist/core/runner/contracts.d.ts +50 -40
- package/dist/core/runner/cross-boundary-lane.d.ts +17 -13
- package/dist/core/runner/cross-boundary-lane.js +40 -27
- package/dist/core/runner/denial-limit-arms.d.ts +2 -2
- package/dist/core/runner/denial-limit-arms.js +1 -1
- package/dist/core/runner/derived-route-fallback.d.ts +13 -0
- package/dist/core/runner/derived-route-fallback.js +6 -0
- package/dist/core/runner/env-capability-census.d.ts +3 -2
- package/dist/core/runner/env-capability-census.js +9 -3
- package/dist/core/runner/file-history-request.d.ts +18 -0
- package/dist/core/runner/file-history-request.js +21 -13
- package/dist/core/runner/file-history-restore.d.ts +45 -0
- package/dist/core/runner/file-history-restore.js +46 -0
- package/dist/core/runner/gate-exit.d.ts +3 -3
- package/dist/core/runner/gate-exit.js +4 -3
- package/dist/core/runner/image.d.ts +7 -17
- package/dist/core/runner/image.js +9 -60
- package/dist/core/runner/permission-rule-lanes.d.ts +11 -11
- package/dist/core/runner/permission-rule-lanes.js +39 -17
- package/dist/core/runner/person-path-rows.d.ts +12 -9
- package/dist/core/runner/person-path-rows.js +18 -7
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +3 -0
- package/dist/core/runner/prepare-acquire-reconcile.js +2 -1
- package/dist/core/runner/prepare-ask-lane.d.ts +2 -2
- package/dist/core/runner/prepare-ask-lane.js +5 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -6
- package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
- package/dist/core/runner/prepare-config-doors.d.ts +35 -38
- package/dist/core/runner/prepare-config-doors.js +46 -28
- package/dist/core/runner/prepare-defer-classify.d.ts +4 -3
- package/dist/core/runner/prepare-defer-classify.js +7 -8
- package/dist/core/runner/prepare-file-history.d.ts +48 -8
- package/dist/core/runner/prepare-file-history.js +7 -39
- package/dist/core/runner/prepare-gate-stations.d.ts +1 -1
- package/dist/core/runner/prepare-gate-stations.js +10 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +5 -9
- package/dist/core/runner/prepare-hands-readface.js +17 -14
- package/dist/core/runner/prepare-inherited-gate.d.ts +6 -3
- package/dist/core/runner/prepare-inherited-gate.js +5 -3
- package/dist/core/runner/prepare-memory-engine-session.js +1 -1
- package/dist/core/runner/prepare-park-ask.d.ts +2 -0
- package/dist/core/runner/prepare-park-ask.js +7 -7
- package/dist/core/runner/prepare-policy-chain.d.ts +6 -3
- package/dist/core/runner/prepare-policy-chain.js +67 -76
- package/dist/core/runner/prepare-prompt-assembly.d.ts +5 -7
- package/dist/core/runner/prepare-prompt-assembly.js +10 -8
- package/dist/core/runner/prepare-prompt-inputs.d.ts +11 -9
- package/dist/core/runner/prepare-prompt-inputs.js +3 -5
- package/dist/core/runner/prepare-protocol-tools.d.ts +2 -0
- package/dist/core/runner/prepare-protocol-tools.js +3 -3
- package/dist/core/runner/prepare-safety-scan.d.ts +1 -1
- package/dist/core/runner/prepare-safety-scan.js +0 -17
- package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
- package/dist/core/runner/prepare-suspend-saga.js +5 -6
- package/dist/core/runner/prepare-task.d.ts +5 -2
- package/dist/core/runner/prepare-task.js +48 -43
- package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +20 -4
- package/dist/core/runner/prepare-tool-disclosure-mount.js +33 -23
- package/dist/core/runner/prepare-turn-wiring.d.ts +0 -4
- package/dist/core/runner/prepare-turn-wiring.js +2 -7
- package/dist/core/runner/prepare-wiring-manifest.d.ts +6 -2
- package/dist/core/runner/prepare-wiring-manifest.js +3 -3
- package/dist/core/runner/resume-admission.js +1 -1
- package/dist/core/runner/resume-apply.js +11 -12
- package/dist/core/runner/resume-checkpoint-screen.js +3 -0
- package/dist/core/runner/resume-claim.d.ts +4 -2
- package/dist/core/runner/resume-claim.js +15 -8
- package/dist/core/runner/retired-runner-deps.js +1 -0
- package/dist/core/runner/rewind-files.d.ts +12 -0
- package/dist/core/runner/rewind-files.js +90 -0
- package/dist/core/runner/run-attachment-seats.js +2 -1
- package/dist/core/runner/run-brain-sinks.d.ts +4 -1
- package/dist/core/runner/run-brain-sinks.js +4 -2
- package/dist/core/runner/run-harness-handlers.js +12 -4
- package/dist/core/runner/run-leg.d.ts +1 -1
- package/dist/core/runner/run-leg.js +40 -39
- package/dist/core/runner/run-notification-lane.d.ts +2 -0
- package/dist/core/runner/run-notification-lane.js +2 -2
- package/dist/core/runner/run-recovery-lanes.js +3 -4
- package/dist/core/runner/run-settle-and-teardown.js +7 -12
- package/dist/core/runner/run-terminal-adoption.js +3 -4
- package/dist/core/runner/run-turn-boundary.js +4 -15
- package/dist/core/runner/runtask.d.ts +10 -0
- package/dist/core/runner/runtask.js +35 -42
- package/dist/core/runner/send-message-continuation.js +1 -1
- package/dist/core/runner/session-read-file-states.d.ts +15 -0
- package/dist/core/runner/session-read-file-states.js +28 -0
- package/dist/core/runner/session-rule-policy.js +4 -3
- package/dist/core/runner/session-verb-doors.d.ts +28 -0
- package/dist/core/runner/session-verb-doors.js +48 -0
- package/dist/core/runner/session-write-ledger.d.ts +30 -0
- package/dist/core/runner/session-write-ledger.js +101 -0
- package/dist/core/runner/shell-env-withheld.d.ts +33 -0
- package/dist/core/runner/shell-env-withheld.js +51 -0
- package/dist/core/runner/skills-seat.js +6 -2
- package/dist/core/runner/stream-settle-backstop.js +12 -15
- package/dist/core/runner/sub-agent-deny-lists.d.ts +25 -3
- package/dist/core/runner/sub-agent-deny-lists.js +25 -17
- package/dist/core/runner/synthetic-tools.d.ts +6 -0
- package/dist/core/runner/synthetic-tools.js +4 -1
- package/dist/core/runner/teardown-bounded.d.ts +1 -0
- package/dist/core/runner/teardown-bounded.js +1 -0
- package/dist/core/runner/tool-disclosure.d.ts +10 -12
- package/dist/core/runner/tool-disclosure.js +1 -3
- package/dist/core/runner/tool-end-body.d.ts +1 -1
- package/dist/core/runner/tool-end-body.js +10 -9
- package/dist/core/runner/tool-not-executed.d.ts +5 -0
- package/dist/core/runner/tool-not-executed.js +11 -0
- package/dist/core/runner/tool-occurrence.d.ts +8 -0
- package/dist/core/runner/tool-occurrence.js +7 -0
- package/dist/core/runner/turn-attachments.d.ts +33 -15
- package/dist/core/runner/turn-attachments.js +62 -37
- package/dist/core/runner-deps.d.ts +7 -7
- package/dist/core/safety-axis-vocab.d.ts +6 -4
- package/dist/core/safety-axis-vocab.js +6 -5
- package/dist/core/safety-merge-corpus.js +11 -3
- package/dist/core/secret-env.d.ts +30 -3
- package/dist/core/secret-env.js +47 -8
- package/dist/core/select-model.js +3 -3
- package/dist/core/session-policy-store.d.ts +32 -15
- package/dist/core/session-policy-store.js +156 -36
- package/dist/core/session-store.d.ts +29 -10
- package/dist/core/session-store.js +51 -19
- package/dist/core/session.d.ts +82 -16
- package/dist/core/session.js +53 -0
- package/dist/core/shell-read-silence.d.ts +11 -12
- package/dist/core/shell-read-silence.js +9 -5
- package/dist/core/shell-run-candidates.js +3 -1
- package/dist/core/shell-wrapper-projection.d.ts +1 -1
- package/dist/core/shell-wrapper-projection.js +1 -1
- package/dist/core/shell-wrapper-table.d.ts +14 -7
- package/dist/core/shell-wrapper-table.js +5 -4
- package/dist/core/side-query.js +10 -1
- package/dist/core/skill-grant.d.ts +7 -2
- package/dist/core/skill-grant.js +5 -0
- package/dist/core/skills-directory.js +6 -2
- package/dist/core/store-contracts/background-agent-store-contract.js +1 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +11 -1
- package/dist/core/store-contracts/checkpoint-store-contract.js +141 -2
- package/dist/core/store-contracts/file-history-store-contract.js +40 -1
- package/dist/core/store-contracts/mailbox-store-contract.js +49 -1
- package/dist/core/store-contracts/peer-directory-contract.d.ts +7 -2
- package/dist/core/store-contracts/peer-directory-contract.js +14 -2
- package/dist/core/store-contracts/session-repo-contract.js +51 -0
- package/dist/core/store-contracts/session-store-contract.d.ts +2 -1
- package/dist/core/store-contracts/session-store-contract.js +150 -14
- package/dist/core/stub-env.d.ts +2 -0
- package/dist/core/stub-env.js +1 -0
- package/dist/core/synthetic-read-verdict.js +3 -3
- package/dist/core/task-event.d.ts +32 -4
- package/dist/core/task-notification.d.ts +16 -12
- package/dist/core/task-registry-agent.d.ts +8 -4
- package/dist/core/task-registry-agent.js +14 -8
- package/dist/core/task-registry-shared.d.ts +35 -6
- package/dist/core/task-registry-shared.js +11 -0
- package/dist/core/task-registry.d.ts +10 -1
- package/dist/core/task-registry.js +12 -2
- package/dist/core/task-result.d.ts +18 -0
- package/dist/core/task-spec.d.ts +18 -13
- package/dist/core/tighten-task-spec.js +2 -1
- package/dist/core/tool-catalog-entries.d.ts +23 -0
- package/dist/core/tool-catalog-entries.js +14 -2
- package/dist/core/tool-check-reading.d.ts +11 -0
- package/dist/core/tool-check-reading.js +11 -6
- package/dist/core/tool-model-gate.d.ts +2 -2
- package/dist/core/tool-name-aliases.d.ts +48 -18
- package/dist/core/tool-name-aliases.js +36 -19
- package/dist/core/tool-name-readings.d.ts +6 -32
- package/dist/core/tool-name-readings.js +2 -9
- package/dist/core/tool-policy.d.ts +78 -204
- package/dist/core/tool-policy.js +152 -204
- package/dist/core/tool-result-store.js +3 -0
- package/dist/core/tool-roster.d.ts +14 -19
- package/dist/core/tool-roster.js +11 -44
- package/dist/core/tool-spec-members.js +7 -2
- package/dist/core/tool-spec.d.ts +19 -11
- package/dist/core/tools.js +49 -9
- package/dist/core/trace.d.ts +6 -3
- package/dist/core/trace.js +2 -1
- package/dist/core/types.d.ts +1 -1
- package/dist/core/untrusted-egress.d.ts +20 -0
- package/dist/core/untrusted-egress.js +77 -3
- package/dist/core/user-attachment.d.ts +8 -1
- package/dist/core/user-attachment.js +64 -4
- package/dist/core/wiring-manifest.d.ts +9 -0
- package/dist/core/wiring-manifest.js +1 -0
- package/dist/core/workflow-journal-store.js +1 -1
- package/dist/engine/compaction/compaction.js +3 -2
- package/dist/engine/execution-env/node-execution-env.d.ts +7 -3
- package/dist/engine/execution-env/node-execution-env.js +11 -2
- package/dist/engine/harness/agent-harness.d.ts +32 -6
- package/dist/engine/harness/agent-harness.js +65 -9
- package/dist/engine/harness/types.d.ts +29 -2
- package/dist/engine/llm/types.d.ts +28 -11
- package/dist/engine/loop/agent-loop.d.ts +23 -4
- package/dist/engine/loop/agent-loop.js +42 -30
- package/dist/engine/loop/types.d.ts +16 -6
- package/dist/engine/session/memory-repo.d.ts +9 -2
- package/dist/engine/session/memory-repo.js +11 -1
- package/dist/engine/session/repo-utils.d.ts +6 -5
- package/dist/engine/session/repo-utils.js +14 -6
- package/dist/index.d.ts +34 -17
- package/dist/index.js +22 -11
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +2 -1
- package/dist/internal/harness.js +1 -0
- package/dist/internal/llm.d.ts +1 -1
- package/dist/orchestration/run-workflow-tool.d.ts +6 -4
- package/dist/orchestration/run-workflow-tool.js +5 -3
- package/dist/orchestration/workflow.d.ts +3 -0
- package/dist/orchestration/workflow.js +36 -18
- package/dist/primitives/credential-ref.d.ts +89 -0
- package/dist/primitives/credential-ref.js +125 -0
- package/dist/primitives/index.d.ts +2 -0
- package/dist/primitives/index.js +1 -0
- package/dist/prompt-assembly/artifact.d.ts +2 -2
- package/dist/prompt-assembly/artifact.js +5 -3
- package/dist/prompt-assembly/assemble.d.ts +3 -2
- package/dist/prompt-assembly/assemble.js +1 -1
- package/dist/prompt-assembly/catalog/schema.d.ts +43 -12
- package/dist/prompt-assembly/catalog/schema.js +34 -2
- package/dist/prompt-assembly/catalog/sections.js +0 -1
- package/dist/prompt-assembly/composer.d.ts +3 -1
- package/dist/prompt-assembly/composer.js +1 -1
- package/dist/prompt-assembly/event-registry.js +1 -0
- package/dist/prompt-assembly/overlay.js +3 -3
- package/dist/prompt-assembly/renderers.d.ts +1 -1
- package/dist/prompt-assembly/renderers.js +0 -3
- package/dist/prompt-assembly/role-base.d.ts +15 -0
- package/dist/prompt-assembly/role-base.js +9 -0
- package/dist/prompt-assembly/select.d.ts +39 -14
- package/dist/prompt-assembly/select.js +47 -16
- package/dist/prompt-assembly/sugar.d.ts +17 -11
- package/dist/prompt-assembly/sugar.js +8 -3
- package/dist/prompt-assembly/tool-catalog.d.ts +37 -3
- package/dist/prompt-assembly/tool-catalog.js +114 -4
- package/dist/prompt-assembly/turn-snapshot.d.ts +4 -10
- package/dist/prompt-assembly/turn-snapshot.js +0 -3
- package/dist/prompt-assembly/types.d.ts +0 -7
- package/dist/scenarios/full-body.d.ts +11 -11
- package/dist/scenarios/full-body.js +4 -3
- package/dist/shell/lex.js +10 -1
- package/dist/stores/file/adoption/adopt.js +4 -3
- package/dist/stores/file/adoption/marker.js +3 -2
- package/dist/stores/file/checkpoint-store.d.ts +21 -4
- package/dist/stores/file/checkpoint-store.js +38 -7
- package/dist/stores/file/file-history-store.js +18 -11
- package/dist/stores/file/index.js +2 -1
- package/dist/stores/file/mailbox-store.d.ts +2 -1
- package/dist/stores/file/mailbox-store.js +26 -1
- package/dist/stores/file/permission-rule-adopt.js +4 -3
- package/dist/stores/file/permission-rule-store.js +11 -5
- package/dist/stores/file/session-store.d.ts +29 -6
- package/dist/stores/file/session-store.js +42 -50
- package/dist/tools/artifact/artifact-tool.js +3 -2
- package/dist/tools/fs/bash-program-position.d.ts +19 -2
- package/dist/tools/fs/bash-program-position.js +56 -9
- package/dist/tools/fs/bash-readonly-classifier.d.ts +15 -19
- package/dist/tools/fs/bash-readonly-classifier.js +5 -10
- package/dist/tools/fs/fs-bash.js +15 -8
- package/dist/tools/fs/fs-glob.d.ts +86 -0
- package/dist/tools/fs/fs-glob.js +226 -0
- package/dist/tools/fs/fs-read.js +14 -14
- package/dist/tools/fs/fs-search-tools.js +7 -7
- package/dist/tools/fs/pattern-kill-guard.d.ts +23 -0
- package/dist/tools/fs/pattern-kill-guard.js +429 -0
- package/dist/tools/fs/pdf.d.ts +9 -6
- package/dist/tools/fs/pdf.js +3 -3
- package/dist/tools/fs/program-read-model.d.ts +57 -7
- package/dist/tools/fs/program-read-model.js +11 -1
- package/dist/tools/fs/program-read-model.rows.js +78 -21
- package/dist/tools/fs/read-deny-home.js +3 -2
- package/dist/tools/fs/removal-targets.d.ts +17 -7
- package/dist/tools/fs/removal-targets.js +47 -20
- package/dist/tools/fs/search.d.ts +10 -0
- package/dist/tools/fs/search.js +20 -26
- package/dist/tools/fs/shell-read-argv.js +89 -12
- package/dist/tools/fs/shell-read-bindings.d.ts +31 -0
- package/dist/tools/fs/shell-read-bindings.js +41 -0
- package/dist/tools/fs/shell-read-check.d.ts +10 -0
- package/dist/tools/fs/shell-read-check.js +13 -20
- package/dist/tools/fs/shell-read-environment.d.ts +5 -1
- package/dist/tools/fs/shell-read-environment.js +3 -2
- package/dist/tools/fs/shell-read-establish.d.ts +15 -0
- package/dist/tools/fs/shell-read-establish.js +19 -20
- package/dist/tools/fs/shell-read-identity.d.ts +12 -9
- package/dist/tools/fs/shell-read-identity.js +9 -4
- package/dist/tools/fs/shell-read-plan.js +24 -16
- package/dist/tools/fs/shell-read-start.d.ts +6 -1
- package/dist/tools/fs/shell-read-write-targets.d.ts +5 -1
- package/dist/tools/fs/shell-read-write-targets.js +2 -3
- package/dist/tools/fs/shell-reentry-text.d.ts +9 -0
- package/dist/tools/fs/shell-reentry-text.js +40 -2
- package/dist/tools/todo.js +63 -63
- package/dist/tools/web.d.ts +19 -14
- package/dist/tools/web.js +46 -61
- package/package.json +1 -1
- package/test/export-surface.snapshot.json +221 -7
- package/wire-changes/core-stores-sql@7.57.0.json +29 -0
- package/wire-changes/core@7.56.0.json +3891 -0
- package/wire-changes/core@7.57.0.json +1487 -0
- package/wire-changes/mods-kernel@7.56.0.json +303 -0
- package/wire-changes/mods-kernel@7.57.0.json +29 -0
- package/wire-changes/primitives@7.57.0.json +245 -0
|
@@ -6,12 +6,9 @@ export interface RawPrefixInputs {
|
|
|
6
6
|
provider: string;
|
|
7
7
|
/** Model id (a switch is a new cache namespace). */
|
|
8
8
|
modelId: string;
|
|
9
|
-
/** The run's prompt identity (`promptIdentityOf`: catalog, renderers, overlay layers, binding
|
|
10
|
-
* `identity.artifact`. */
|
|
9
|
+
/** The run's prompt identity (`promptIdentityOf`: catalog, renderers, overlay layers, binding — the binding element
|
|
10
|
+
* digests the selector values, the prompt traits among them) — the manifest's `identity.artifact`. */
|
|
11
11
|
artifactDigest: string;
|
|
12
|
-
/** Presentation/policy axis: promptProfile + fable mitigations (prose forks on these). */
|
|
13
|
-
promptProfile: string;
|
|
14
|
-
fableMitigations: boolean;
|
|
15
12
|
/** Physical block layout as SERVED (derived from the composed system blocks; single-block default). */
|
|
16
13
|
layoutGroups: ReadonlyArray<{
|
|
17
14
|
groupId: string;
|
|
@@ -47,8 +44,6 @@ export declare const PREFIX_INPUT_CLASSIFICATION: {
|
|
|
47
44
|
readonly provider: "cache-identity";
|
|
48
45
|
readonly modelId: "cache-identity";
|
|
49
46
|
readonly artifactDigest: "cache-identity";
|
|
50
|
-
readonly promptProfile: "cache-identity";
|
|
51
|
-
readonly fableMitigations: "cache-identity";
|
|
52
47
|
readonly layoutGroups: "cache-identity";
|
|
53
48
|
readonly stableSystemText: "cache-identity";
|
|
54
49
|
readonly toolWire: "cache-identity";
|
|
@@ -68,12 +63,11 @@ export interface LoweringRecord {
|
|
|
68
63
|
}
|
|
69
64
|
export declare const LOWERING_VERSION = "sema-lowering@1";
|
|
70
65
|
export declare function loweringRecordFor(api: string): LoweringRecord;
|
|
71
|
-
/** The
|
|
66
|
+
/** The eight identity elements, individually digested (observable without shipping prompt text). */
|
|
72
67
|
export interface CacheIdentityElements {
|
|
73
68
|
provider: string;
|
|
74
69
|
modelId: string;
|
|
75
70
|
artifactDigest: string;
|
|
76
|
-
policyDigest: string;
|
|
77
71
|
layoutDigest: string;
|
|
78
72
|
stableSystemDigest: string;
|
|
79
73
|
toolWireDigest: string;
|
|
@@ -82,7 +76,7 @@ export interface CacheIdentityElements {
|
|
|
82
76
|
}
|
|
83
77
|
export interface TurnPromptSnapshot {
|
|
84
78
|
elements: CacheIdentityElements;
|
|
85
|
-
/** sha256(canonical(elements)) — the ONE
|
|
79
|
+
/** sha256(canonical(elements)) — the ONE eight-element identity value. */
|
|
86
80
|
cacheIdentity: string;
|
|
87
81
|
lowering: LoweringRecord;
|
|
88
82
|
/** invoked after EVERY refresh so the run loop can emit the changed identity
|
|
@@ -4,8 +4,6 @@ export const PREFIX_INPUT_CLASSIFICATION = {
|
|
|
4
4
|
provider: "cache-identity",
|
|
5
5
|
modelId: "cache-identity",
|
|
6
6
|
artifactDigest: "cache-identity",
|
|
7
|
-
promptProfile: "cache-identity",
|
|
8
|
-
fableMitigations: "cache-identity",
|
|
9
7
|
layoutGroups: "cache-identity",
|
|
10
8
|
stableSystemText: "cache-identity",
|
|
11
9
|
toolWire: "cache-identity",
|
|
@@ -53,7 +51,6 @@ export function buildTurnPromptSnapshot(raw, api, promptHasher) {
|
|
|
53
51
|
provider: raw.provider,
|
|
54
52
|
modelId: raw.modelId,
|
|
55
53
|
artifactDigest: raw.artifactDigest,
|
|
56
|
-
policyDigest: sha(canonical({ promptProfile: raw.promptProfile, fableMitigations: raw.fableMitigations })),
|
|
57
54
|
layoutDigest: sha(canonical(raw.layoutGroups)),
|
|
58
55
|
stableSystemDigest: promptSha(raw.stableSystemText),
|
|
59
56
|
toolWireDigest: sha(canonical(raw.toolWire.map((t) => ({ name: t.name, description: t.description, parameters: t.parameters })))),
|
|
@@ -32,11 +32,6 @@ export interface PromptRuntimeFacts {
|
|
|
32
32
|
/** Orchestration is active but the Workflow tool is DEFERRED — the mode section serves the short pointer.
|
|
33
33
|
* Only meaningful when orchestrationEnabled. OPTIONAL — absence reads as false. */
|
|
34
34
|
orchestrationDeferred?: boolean;
|
|
35
|
-
/** The run's resolved prompt profile ("simple" default). It becomes the `lean_prompt` trait; catalog
|
|
36
|
-
* data reads the trait. OPTIONAL — absence reads as "simple". */
|
|
37
|
-
promptProfile?: "simple" | "classic";
|
|
38
|
-
/** The run's model is fable-family. It becomes the `fable_5_mitigations` trait. OPTIONAL — absence = false. */
|
|
39
|
-
fableMitigations?: boolean;
|
|
40
35
|
awarenessEnabled: boolean;
|
|
41
36
|
goalEnabled: boolean;
|
|
42
37
|
worktreeIsolated: boolean;
|
|
@@ -59,8 +54,6 @@ export interface SectionRenderInputs {
|
|
|
59
54
|
environmentBlock?: string;
|
|
60
55
|
/** Pre-rendered volatile memory tail (engine injection + fenced project layer). */
|
|
61
56
|
memoryBlock?: string;
|
|
62
|
-
/** model.promptGuidance joined text, if the model declares any. */
|
|
63
|
-
modelGuidance?: string;
|
|
64
57
|
}
|
|
65
58
|
/** One rendered (admitted, non-empty) section of a composition — the compiled IR unit. */
|
|
66
59
|
export interface CompiledSection {
|
|
@@ -10,9 +10,9 @@ import type { ToolSpec, RoleSpec } from "../core/types.js";
|
|
|
10
10
|
* `prepareTask` when the trusted assembler wires those deps/flags. This bundle is only the caller-composed factories.
|
|
11
11
|
*/
|
|
12
12
|
export interface CodeToolsConfig {
|
|
13
|
-
/** web_fetch
|
|
14
|
-
* `
|
|
15
|
-
*
|
|
13
|
+
/** web_fetch's factory options (fetch seam, byte / time caps, summarizer). Which hosts it may reach is NOT one of them: that is the
|
|
14
|
+
* deployment's host floor (`RunnerDeps.hostFloor`, every structured egress, read from the run on every hop) — a MULTI-TENANT
|
|
15
|
+
* deployment declares one there; the private-network floor applies regardless. */
|
|
16
16
|
webFetch?: WebFetchConfig;
|
|
17
17
|
/** WebSearch backend (BRAIN/model-service leg). Absent ⇒ WebSearch is not assembled (core ships no backend). */
|
|
18
18
|
webSearch?: WebSearchConfig;
|
|
@@ -20,11 +20,11 @@ export interface CodeToolsConfig {
|
|
|
20
20
|
* surface as the leader's own instances (one `TaskListStore`), bounded by what the spawning run mounts and trimmed
|
|
21
21
|
* by the spawn tier (`SubagentToolOptions.inheritedTools`). Tools composed BESIDE the bundle are not inherited: a
|
|
22
22
|
* host hands those per spawn through `subagent.extraTools`, behind its own gates.
|
|
23
|
-
* 合车复审修③: when this
|
|
24
|
-
* `
|
|
23
|
+
* 合车复审修③: when this names NO role base (neither `promptRole` nor `systemPrompt`), the assembler defaults it
|
|
24
|
+
* to `promptRole: "code"` — a code-scenario child holds Bash/Write side-effect tools, so it keeps the code
|
|
25
25
|
* constitution (snapshot-before-mutate / destructive-op care / git discipline) instead of falling to the
|
|
26
26
|
* lean SUBAGENT_PROMPT (the G1 default, which is the right upstream-anchor shape only for bare
|
|
27
|
-
* general-purpose delegation). Pass an explicit `systemPrompt` here to override. */
|
|
27
|
+
* general-purpose delegation). Pass an explicit `promptRole` / `systemPrompt` here to override. */
|
|
28
28
|
subagent?: SubagentToolOptions;
|
|
29
29
|
/**
|
|
30
30
|
* TodoWrite (CONTEXT leg). Default true, BUT mutually exclusive with the task-list family (
|
|
@@ -58,15 +58,15 @@ export interface CodeToolsConfig {
|
|
|
58
58
|
* Single-source bundle of the `code` scenario's `spec.tools`-class tools, so each deployment doesn't re-wire it
|
|
59
59
|
* (the single-source discipline: a scenario is data — a named bundle).
|
|
60
60
|
* Profile-as-data — the engine iterates `spec.tools` branch-free; nothing keys off the scenario name. A trusted
|
|
61
|
-
* assembler (service) calls this, sets `
|
|
61
|
+
* assembler (service) calls this, sets `promptRole = "code"` (or `roles.default = CODE_ROLE`) +
|
|
62
62
|
* `enablePlanMode:true`, and wires the deps seams (executionEnv/onQuestion/lspManager/skillSpecs/memoryStore/
|
|
63
63
|
* selfOrchestration) — that is what makes a run the `code` scenario. Returns ONLY the caller-composed tools.
|
|
64
64
|
*/
|
|
65
65
|
export declare function assembleCodeTools(cfg?: CodeToolsConfig): ToolSpec[];
|
|
66
66
|
/**
|
|
67
|
-
* RoleSpec preset for the `code` scenario's coding role
|
|
68
|
-
* `
|
|
69
|
-
* sensible floor; the assembler/SDK can raise it (effort→thinking) per request. The global
|
|
70
|
-
* stays neutral.
|
|
67
|
+
* RoleSpec preset for the `code` scenario's coding role: the catalog's coding role base by word (`promptRole:
|
|
68
|
+
* "code"`), the role-base decision's second source — it applies when the task names no role base of its own.
|
|
69
|
+
* `thinking:"high"` is a sensible floor; the assembler/SDK can raise it (effort→thinking) per request. The global
|
|
70
|
+
* DEFAULT_SYSTEM_PROMPT stays neutral.
|
|
71
71
|
*/
|
|
72
72
|
export declare const CODE_ROLE: RoleSpec;
|
|
@@ -2,7 +2,7 @@ import { webFetchToolSpec, createWebSearchTool } from "../tools/web.js";
|
|
|
2
2
|
import { createTodoWriteTool } from "../tools/todo.js";
|
|
3
3
|
import { createTaskListTools } from "../tools/task-list.js";
|
|
4
4
|
import { createSubagentTool } from "../agents/subagent.js";
|
|
5
|
-
import {
|
|
5
|
+
import { namesRoleBase } from "../prompt-assembly/role-base.js";
|
|
6
6
|
export function assembleCodeTools(cfg = {}) {
|
|
7
7
|
const web = [webFetchToolSpec(cfg.webFetch ?? {})];
|
|
8
8
|
if (cfg.webSearch)
|
|
@@ -19,13 +19,14 @@ export function assembleCodeTools(cfg = {}) {
|
|
|
19
19
|
}
|
|
20
20
|
const tools = [...web];
|
|
21
21
|
if (cfg.subagent) {
|
|
22
|
+
const roleBase = namesRoleBase(cfg.subagent) ? {} : { promptRole: "code" };
|
|
22
23
|
tools.push(createSubagentTool({
|
|
23
24
|
...cfg.subagent,
|
|
24
|
-
|
|
25
|
+
...roleBase,
|
|
25
26
|
inheritedTools: cfg.subagent.inheritedTools ?? [...web, ...scaffolds],
|
|
26
27
|
}));
|
|
27
28
|
}
|
|
28
29
|
tools.push(...scaffolds);
|
|
29
30
|
return tools;
|
|
30
31
|
}
|
|
31
|
-
export const CODE_ROLE = {
|
|
32
|
+
export const CODE_ROLE = { promptRole: "code", thinking: "high" };
|
package/dist/shell/lex.js
CHANGED
|
@@ -1169,6 +1169,7 @@ function scan(source, connectorsAreText, segments, level, list) {
|
|
|
1169
1169
|
let assignmentSeen = false;
|
|
1170
1170
|
let subscriptsClosed = false;
|
|
1171
1171
|
let commandWord;
|
|
1172
|
+
let arithParens = 0;
|
|
1172
1173
|
let w = new WordBuilder();
|
|
1173
1174
|
const next = (j) => past(source, j + 1);
|
|
1174
1175
|
const quotedBy = () => (inSingle || inDouble ? regionBy : undefined);
|
|
@@ -1503,7 +1504,7 @@ function scan(source, connectorsAreText, segments, level, list) {
|
|
|
1503
1504
|
take(ch, i);
|
|
1504
1505
|
continue;
|
|
1505
1506
|
}
|
|
1506
|
-
if (ch === "#" && !w.started) {
|
|
1507
|
+
if (ch === "#" && !w.started && arithParens === 0) {
|
|
1507
1508
|
const nl = source.indexOf("\n", i);
|
|
1508
1509
|
i = nl < 0 ? source.length : nl - 1;
|
|
1509
1510
|
continue;
|
|
@@ -1531,6 +1532,14 @@ function scan(source, connectorsAreText, segments, level, list) {
|
|
|
1531
1532
|
const r = endWord() ?? operandOwed(i);
|
|
1532
1533
|
if (r !== undefined)
|
|
1533
1534
|
return r;
|
|
1535
|
+
if (ch === "(") {
|
|
1536
|
+
if (arithParens > 0)
|
|
1537
|
+
arithParens++;
|
|
1538
|
+
else if (split && source[next(i)] === "(")
|
|
1539
|
+
arithParens = 1;
|
|
1540
|
+
}
|
|
1541
|
+
else if (arithParens > 0)
|
|
1542
|
+
arithParens--;
|
|
1534
1543
|
current().tokens.push({ kind: "group", op: ch });
|
|
1535
1544
|
resetPosition();
|
|
1536
1545
|
continue;
|
|
@@ -8,6 +8,7 @@ import { SessionPolicyError } from "../../../core/session-policy-store.js";
|
|
|
8
8
|
import { thrownText } from "../../../core/thrown-value.js";
|
|
9
9
|
import { AdoptionError, NOT_MIGRATED_BY_DESIGN, readRootAdoptionFile, writeRootAdoptionFile, } from "./marker.js";
|
|
10
10
|
import { readRuleOwner, ruleOwnerText, sameRuleOwner } from "../../../core/rule-owner.js";
|
|
11
|
+
import { principalNameOf } from "../../../core/principal-name.js";
|
|
11
12
|
const CONFIG_ACCOUNT_FILE = "adoption-configs.json";
|
|
12
13
|
function baselineConfigs(toPrincipal) {
|
|
13
14
|
return [
|
|
@@ -333,12 +334,12 @@ function answerFromExisting(root, existing, from, toPrincipal) {
|
|
|
333
334
|
return undefined;
|
|
334
335
|
}
|
|
335
336
|
export async function adoptLocalDataRoot(opts) {
|
|
336
|
-
if (
|
|
337
|
-
throw new AdoptionError("adoption_bad_request", "adoptLocalDataRoot requires the adopting principal — adoption is the act of giving this data root an identity");
|
|
337
|
+
if (principalNameOf(opts.toPrincipal) === undefined) {
|
|
338
|
+
throw new AdoptionError("adoption_bad_request", "adoptLocalDataRoot requires the adopting principal, a principal name — adoption is the act of giving this data root an identity");
|
|
338
339
|
}
|
|
339
340
|
const from = readRuleOwner(opts.from);
|
|
340
341
|
if (from === undefined) {
|
|
341
|
-
throw new AdoptionError("adoption_bad_request", "the adoption source must be the local-owner kind or a principal
|
|
342
|
+
throw new AdoptionError("adoption_bad_request", "the adoption source must be the local-owner kind or a principal owner whose principal is a principal name — local-single-user identity is the local-owner kind, never a blank string");
|
|
342
343
|
}
|
|
343
344
|
if (from.kind === "principal" && from.principal === opts.toPrincipal) {
|
|
344
345
|
throw new AdoptionError("adoption_bad_request", `the data root already belongs to "${opts.toPrincipal}" — there is nothing to adopt`);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { readRuleOwner, sameRuleOwner } from "../../../core/rule-owner.js";
|
|
4
|
+
import { principalNameOf } from "../../../core/principal-name.js";
|
|
4
5
|
import { atomicWriteFile, ensureDir } from "../fs-atomic.js";
|
|
5
6
|
export class AdoptionError extends Error {
|
|
6
7
|
code;
|
|
@@ -39,7 +40,7 @@ function isRootAdoptionFileShape(v) {
|
|
|
39
40
|
typeof m !== "object" ||
|
|
40
41
|
typeof m.adoptionId !== "string" ||
|
|
41
42
|
readRuleOwner(m.from) === undefined ||
|
|
42
|
-
|
|
43
|
+
principalNameOf(m.toPrincipal) === undefined ||
|
|
43
44
|
typeof m.phase !== "number" ||
|
|
44
45
|
![2, 3, 4, 5].includes(m.phase)) {
|
|
45
46
|
return false;
|
|
@@ -88,7 +89,7 @@ function isRootAdoptionFileShape(v) {
|
|
|
88
89
|
if (a === null ||
|
|
89
90
|
typeof a !== "object" ||
|
|
90
91
|
from === undefined ||
|
|
91
|
-
|
|
92
|
+
principalNameOf(a.toPrincipal) === undefined ||
|
|
92
93
|
typeof a.atMs !== "number" ||
|
|
93
94
|
a.immutableReport === null ||
|
|
94
95
|
typeof a.immutableReport !== "object") {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type ExecutionOutcomeRecordWord } from "../../core/checkpoint-execution-record.js";
|
|
2
|
+
import { type HolderJudge } from "../../core/checkpoint-generation.js";
|
|
2
3
|
import { type Checkpoint, type PendingSteerInput, type CheckpointFaultMode, type CheckpointStore, type CheckpointSummary, type CheckpointToken, type ReopenReason, type ResolveExpectation, type ResumeOutcome } from "../../core/checkpoint-store.js";
|
|
3
4
|
import type { GateOutcome } from "../../core/gate-outcome.js";
|
|
5
|
+
import { type CheckpointDeleteGuard, type CheckpointOverdueCursor, type CheckpointOverdueQuery, type CheckpointPage, type CheckpointRowRead, type CheckpointSessionCursor, type CheckpointSessionQuery } from "../../core/checkpoint-queries.js";
|
|
4
6
|
import { type CorruptReadInfo } from "./corrupt-read-sink.js";
|
|
5
7
|
export interface FileCheckpointStoreOptions {
|
|
6
8
|
/** This store's half of {@link import("./shared-ledger.js").LedgerPaths.onCorruptRead}. */
|
|
@@ -11,6 +13,13 @@ export interface FileCheckpointStoreOptions {
|
|
|
11
13
|
fsync?: boolean;
|
|
12
14
|
/** Compact the ledger into a snapshot once it exceeds this many events (then truncate). Default 1000. */
|
|
13
15
|
compactEvery?: number;
|
|
16
|
+
/** The session head read (a session store's `headOf`) {@link FileCheckpointStore.deleteSessionCheckpoints} judges its guard by;
|
|
17
|
+
* without it the store has no `deleteSessionCheckpoints` member. */
|
|
18
|
+
sessionHeadOf?: (sessionId: string) => Promise<{
|
|
19
|
+
readonly owner: string | null;
|
|
20
|
+
} | undefined>;
|
|
21
|
+
/** The judge of a resolve's claim holder ({@link HolderJudge}); with it the store declares `fence = { holder: true }`. */
|
|
22
|
+
holderIsCurrent?: HolderJudge;
|
|
14
23
|
}
|
|
15
24
|
export declare class FileCheckpointStore implements CheckpointStore {
|
|
16
25
|
/** design/173 §2.3 — honest declaration on the restart-survival axis the vocabulary claims: rows
|
|
@@ -26,14 +35,15 @@ export declare class FileCheckpointStore implements CheckpointStore {
|
|
|
26
35
|
* same JSON reading as the ledger line); the declaration is what makes the loss visible to the mint BEFORE the
|
|
27
36
|
* row is filed. */
|
|
28
37
|
readonly fidelity: "json";
|
|
29
|
-
/** F-012 L2: `reopen` here is a real resolved→pending CAS journaled to the ledger — declared, not sniffed. */
|
|
30
|
-
readonly redecision: {
|
|
31
|
-
readonly reopen: true;
|
|
32
|
-
};
|
|
33
38
|
/** The execution-outcome record verb below is the contract's CAS (journaled), and `reopen` honours the record. */
|
|
34
39
|
readonly execution: {
|
|
35
40
|
readonly outcome: true;
|
|
36
41
|
};
|
|
42
|
+
/** Declared exactly when the store was built with a `holderIsCurrent` judge. */
|
|
43
|
+
readonly fence?: {
|
|
44
|
+
readonly holder: true;
|
|
45
|
+
};
|
|
46
|
+
private readonly holderIsCurrent;
|
|
37
47
|
private readonly fsyncEnabled;
|
|
38
48
|
private readonly compactEvery;
|
|
39
49
|
/** RB-134: the directory's ONE authority (map + token mutex + append log), joined not rebuilt. */
|
|
@@ -45,6 +55,8 @@ export declare class FileCheckpointStore implements CheckpointStore {
|
|
|
45
55
|
/** The guarded {@link FileCheckpointStoreOptions.onCorruptRead} seat (the ledger's replay and this store's projection share it). */
|
|
46
56
|
private readonly discloseCorrupt;
|
|
47
57
|
private readonly ledgerPath;
|
|
58
|
+
/** Present exactly when the store was built with a session head read (`FileCheckpointStoreOptions.sessionHeadOf`). */
|
|
59
|
+
readonly deleteSessionCheckpoints?: (sessionId: string, guard: CheckpointDeleteGuard) => Promise<number>;
|
|
48
60
|
constructor(root: string, opts?: FileCheckpointStoreOptions);
|
|
49
61
|
/** Serialize an op behind any in-flight op on the same token (the in-process per-token async mutex). */
|
|
50
62
|
private withLock;
|
|
@@ -69,6 +81,11 @@ export declare class FileCheckpointStore implements CheckpointStore {
|
|
|
69
81
|
reap(scope: string, cutoff: number): Promise<number>;
|
|
70
82
|
listByScope(scope: string): Promise<CheckpointSummary[]>;
|
|
71
83
|
listScopes(): Promise<string[]>;
|
|
84
|
+
/** The listing faces' disclosure: a row read past a damage is reported through the corrupt-read seat, named by its non-secret
|
|
85
|
+
* identity (never its token). */
|
|
86
|
+
private listingDisclose;
|
|
87
|
+
listOverdue(query: CheckpointOverdueQuery): Promise<CheckpointPage<CheckpointSummary, CheckpointOverdueCursor>>;
|
|
88
|
+
listBySession(query: CheckpointSessionQuery): Promise<CheckpointPage<CheckpointRowRead, CheckpointSessionCursor>>;
|
|
72
89
|
/** Force a compaction now (test/inspection). The snapshot rewrite + RB-167 closeForSwap swap that
|
|
73
90
|
* makes `replay` read the full state from the snapshot alone is the base's {@link LedgerCore.compact}. */
|
|
74
91
|
compactNow(): void;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { assertAdoptionBootGate } from "./adoption/marker.js";
|
|
3
3
|
import { checkpointExecutionRecorded, executionRecordDisposition, ExecutionOutcomeConflictError, } from "../../core/checkpoint-execution-record.js";
|
|
4
|
-
import {
|
|
4
|
+
import { checkpointHolderMatches, checkpointOccMatches, checkpointRevOf } from "../../core/checkpoint-generation.js";
|
|
5
|
+
import { appendPendingSteer, CheckpointError, checkpointRowMatches, encodeAtFidelity, summarizeCheckpoint, validatePendingSteer, winnerFromOutcome, } from "../../core/checkpoint-store.js";
|
|
6
|
+
import { checkpointDeadlinePassed, deleteSessionRowsAtStart, readCheckpointOverdueQuery, readCheckpointSessionQuery, selectOverduePage, selectSessionPage, } from "../../core/checkpoint-queries.js";
|
|
5
7
|
import { SharedLedgerTable } from "./shared-ledger.js";
|
|
6
8
|
import { guardCorruptSink } from "./corrupt-read-sink.js";
|
|
7
9
|
const CHECKPOINT_LEDGER_EVENT_REGISTRY = {
|
|
@@ -10,6 +12,7 @@ const CHECKPOINT_LEDGER_EVENT_REGISTRY = {
|
|
|
10
12
|
reopen: true,
|
|
11
13
|
execution: true,
|
|
12
14
|
expire: true,
|
|
15
|
+
delete: true,
|
|
13
16
|
steer_append: true,
|
|
14
17
|
};
|
|
15
18
|
const KNOWN_CHECKPOINT_LEDGER_EVENTS = new Set(Object.keys(CHECKPOINT_LEDGER_EVENT_REGISTRY));
|
|
@@ -45,6 +48,9 @@ function applyCheckpointEvent(cps, ev) {
|
|
|
45
48
|
case "expire":
|
|
46
49
|
cp.status = "expired";
|
|
47
50
|
break;
|
|
51
|
+
case "delete":
|
|
52
|
+
cps.delete(ev.token);
|
|
53
|
+
break;
|
|
48
54
|
case "steer_append": {
|
|
49
55
|
const queue = cp.state.pendingSteerQueue ?? [];
|
|
50
56
|
if (!queue.some((e) => e.inputId === ev.entry.inputId))
|
|
@@ -82,8 +88,8 @@ const checkpointLedgers = new SharedLedgerTable({
|
|
|
82
88
|
export class FileCheckpointStore {
|
|
83
89
|
durability = "durable";
|
|
84
90
|
fidelity = "json";
|
|
85
|
-
redecision = { reopen: true };
|
|
86
91
|
execution = { outcome: true };
|
|
92
|
+
holderIsCurrent;
|
|
87
93
|
fsyncEnabled;
|
|
88
94
|
compactEvery;
|
|
89
95
|
ledger;
|
|
@@ -97,6 +103,9 @@ export class FileCheckpointStore {
|
|
|
97
103
|
constructor(root, opts = {}) {
|
|
98
104
|
assertAdoptionBootGate(root, "FileCheckpointStore");
|
|
99
105
|
this.fsyncEnabled = opts.fsync !== false;
|
|
106
|
+
this.holderIsCurrent = opts.holderIsCurrent;
|
|
107
|
+
if (opts.holderIsCurrent !== undefined)
|
|
108
|
+
this.fence = Object.freeze({ holder: true });
|
|
100
109
|
this.compactEvery = opts.compactEvery ?? 1000;
|
|
101
110
|
this.discloseCorrupt = guardCorruptSink(opts.onCorruptRead);
|
|
102
111
|
const dir = join(root, "checkpoints");
|
|
@@ -108,6 +117,15 @@ export class FileCheckpointStore {
|
|
|
108
117
|
ledgerPath: this.ledgerPath,
|
|
109
118
|
snapshotPath: join(dir, "checkpoints.snapshot.jsonl"),
|
|
110
119
|
});
|
|
120
|
+
const headOf = opts.sessionHeadOf;
|
|
121
|
+
if (headOf !== undefined) {
|
|
122
|
+
this.deleteSessionCheckpoints = (sessionId, guard) => deleteSessionRowsAtStart(this.cps, sessionId, guard, headOf, (token, row) => this.withLock(token, () => {
|
|
123
|
+
if (this.cps.get(token) !== row)
|
|
124
|
+
return false;
|
|
125
|
+
this.commit({ t: "delete", token }, true);
|
|
126
|
+
return true;
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
111
129
|
}
|
|
112
130
|
withLock(token, fn) {
|
|
113
131
|
return this.ledger.withLock(token, fn);
|
|
@@ -144,8 +162,11 @@ export class FileCheckpointStore {
|
|
|
144
162
|
if (!checkpointOccMatches(cp, expect)) {
|
|
145
163
|
return false;
|
|
146
164
|
}
|
|
165
|
+
if (!checkpointHolderMatches(expect, this.holderIsCurrent)) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
147
168
|
const winner = winnerFromOutcome(outcome);
|
|
148
|
-
const rev = (cp
|
|
169
|
+
const rev = checkpointRevOf(cp) + 1;
|
|
149
170
|
this.commit({ t: "resolve", token, rev, resolvedOutcome: winner }, true);
|
|
150
171
|
if (this.fault === "resolve-after-commit") {
|
|
151
172
|
this.fault = null;
|
|
@@ -172,7 +193,7 @@ export class FileCheckpointStore {
|
|
|
172
193
|
if (!checkpointRowMatches(cp, scope, "resolved") || checkpointExecutionRecorded(cp)) {
|
|
173
194
|
return false;
|
|
174
195
|
}
|
|
175
|
-
const rev = (cp
|
|
196
|
+
const rev = checkpointRevOf(cp) + 1;
|
|
176
197
|
this.commit({ t: "reopen", token, rev, reason }, true);
|
|
177
198
|
return true;
|
|
178
199
|
});
|
|
@@ -204,7 +225,7 @@ export class FileCheckpointStore {
|
|
|
204
225
|
}
|
|
205
226
|
async reap(scope, cutoff) {
|
|
206
227
|
let n = 0;
|
|
207
|
-
const deadlinePassed = (deadline) =>
|
|
228
|
+
const deadlinePassed = (deadline) => checkpointDeadlinePassed(deadline, cutoff);
|
|
208
229
|
const candidates = [...this.cps.values()].filter((cp) => cp.scope === scope && cp.status === "pending" && deadlinePassed(cp.deadline));
|
|
209
230
|
for (const cp of candidates) {
|
|
210
231
|
const won = await this.withLock(cp.token, () => {
|
|
@@ -222,8 +243,7 @@ export class FileCheckpointStore {
|
|
|
222
243
|
return n;
|
|
223
244
|
}
|
|
224
245
|
async listByScope(scope) {
|
|
225
|
-
const
|
|
226
|
-
const disclose = sink === undefined ? undefined : (sentence) => sink({ kind: "file", path: this.ledgerPath, reason: sentence });
|
|
246
|
+
const disclose = this.listingDisclose();
|
|
227
247
|
const out = [];
|
|
228
248
|
for (const cp of this.cps.values()) {
|
|
229
249
|
if (cp.scope === scope && cp.status === "pending")
|
|
@@ -238,6 +258,17 @@ export class FileCheckpointStore {
|
|
|
238
258
|
out.add(cp.scope);
|
|
239
259
|
return [...out];
|
|
240
260
|
}
|
|
261
|
+
listingDisclose() {
|
|
262
|
+
const sink = this.discloseCorrupt;
|
|
263
|
+
return sink === undefined ? undefined : (sentence) => sink({ kind: "file", path: this.ledgerPath, reason: sentence });
|
|
264
|
+
}
|
|
265
|
+
async listOverdue(query) {
|
|
266
|
+
const disclose = this.listingDisclose();
|
|
267
|
+
return selectOverduePage(this.cps.entries(), readCheckpointOverdueQuery(query), (cp) => summarizeCheckpoint(cp, disclose), disclose);
|
|
268
|
+
}
|
|
269
|
+
async listBySession(query) {
|
|
270
|
+
return selectSessionPage(this.cps.entries(), readCheckpointSessionQuery(query), (cp) => structuredClone(cp), this.listingDisclose());
|
|
271
|
+
}
|
|
241
272
|
compactNow() {
|
|
242
273
|
this.ledger.compact();
|
|
243
274
|
}
|
|
@@ -2,7 +2,7 @@ import { createHash, randomBytes } from "node:crypto";
|
|
|
2
2
|
import { appendFileSync, closeSync, existsSync, fsyncSync, openSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { thrownText } from "../../core/thrown-value.js";
|
|
5
|
-
import { applyFileRestoreViaEnv, boundaryPublishVerdict, worldStillMatchesMint, captureFileBackupViaEnv, modeProvenDifferent, previewFileDelta, describeTrackKey, fileHistoryExportDigest, caughtFault, DAMAGED_RECORD, resolveTrackKey, trackKeyOf, validateFileHistoryExport, } from "../../core/file-history-store.js";
|
|
5
|
+
import { applyFileRestoreViaEnv, boundaryPublishVerdict, worldStillMatchesMint, annulProofFailure, captureFileBackupViaEnv, modeProvenDifferent, previewFileDelta, describeTrackKey, fileHistoryExportDigest, caughtFault, DAMAGED_RECORD, resolveTrackKey, trackKeyOf, validateFileHistoryExport, } from "../../core/file-history-store.js";
|
|
6
6
|
import { fileHistoryBoundariesToKeep, resolveFileHistoryRetention } from "../../core/file-history-retention.js";
|
|
7
7
|
import { atomicWriteFile, ensureDir, sanitizePathComponent, sanitizeScope, writeThenLink } from "./fs-atomic.js";
|
|
8
8
|
import { guardCorruptSink } from "./corrupt-read-sink.js";
|
|
@@ -481,9 +481,8 @@ export class FileFileHistoryStore {
|
|
|
481
481
|
return { ok: false, error: { code: "conflict", message: `first-touch record for ${absPath} has since been served to another edit of the same path — it is that edit's baseline now, not a retractable mint` } };
|
|
482
482
|
}
|
|
483
483
|
const proof = verify === undefined ? undefined : await worldStillMatchesMint(verify.env, absPath, root, rec.baseAvailable, rec.versions[0]?.blobHash ?? null, verify.signal);
|
|
484
|
-
if (proof !== undefined &&
|
|
485
|
-
return
|
|
486
|
-
}
|
|
484
|
+
if (proof !== undefined && proof.verdict !== "unchanged")
|
|
485
|
+
return annulProofFailure(proof, absPath);
|
|
487
486
|
const fresh = this.readTrackedState(scope);
|
|
488
487
|
if (fresh.corrupt)
|
|
489
488
|
return { ok: false, error: { code: "track_failed", message: `file history for scope "${scope}" became unreadable — the record was left in place`, ...fresh.fault } };
|
|
@@ -723,7 +722,7 @@ export class FileFileHistoryStore {
|
|
|
723
722
|
let targetVersion = boundary.get(key);
|
|
724
723
|
if (targetVersion === undefined) {
|
|
725
724
|
if (!rec.baseAvailable) {
|
|
726
|
-
ledger.refused.push({ path: key, reason: "base_unavailable" });
|
|
725
|
+
ledger.refused.push({ path: key, reason: "base_unavailable", class: "base_unavailable" });
|
|
727
726
|
continue;
|
|
728
727
|
}
|
|
729
728
|
targetVersion = 1;
|
|
@@ -735,7 +734,7 @@ export class FileFileHistoryStore {
|
|
|
735
734
|
}
|
|
736
735
|
const resolved = resolveTrackKey(root, key, descriptorOf(rec));
|
|
737
736
|
if (!resolved.ok) {
|
|
738
|
-
ledger.refused.push({ path: key, reason: resolved.reason });
|
|
737
|
+
ledger.refused.push({ path: key, reason: resolved.reason, class: resolved.class });
|
|
739
738
|
continue;
|
|
740
739
|
}
|
|
741
740
|
let target;
|
|
@@ -777,7 +776,7 @@ export class FileFileHistoryStore {
|
|
|
777
776
|
else if (applied.outcome === "identical")
|
|
778
777
|
ledger.identicalSkipped.push(key);
|
|
779
778
|
else if (applied.outcome === "refused")
|
|
780
|
-
ledger.refused.push({ path: key, reason: applied.reason });
|
|
779
|
+
ledger.refused.push({ path: key, reason: applied.reason, class: applied.class });
|
|
781
780
|
else
|
|
782
781
|
ledger.failed.push({ path: key, reason: applied.reason });
|
|
783
782
|
if ((applied.outcome === "applied" || applied.outcome === "identical") && applied.modeNotPreserved === true)
|
|
@@ -1148,6 +1147,14 @@ export class FileFileHistoryStore {
|
|
|
1148
1147
|
const shaped = validateFileHistoryExport(data);
|
|
1149
1148
|
if (!shaped.ok)
|
|
1150
1149
|
return shaped;
|
|
1150
|
+
for (const b of data.boundaries) {
|
|
1151
|
+
try {
|
|
1152
|
+
historyPathComponent(b.entryId);
|
|
1153
|
+
}
|
|
1154
|
+
catch (err) {
|
|
1155
|
+
return { ok: false, error: { code: "unsupported_format", message: `importHistory refused a boundary entry id this backend cannot hold as a record name: ${thrownText(err)} — nothing was fetched or published` } };
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1151
1158
|
const target = await this.importTargetOf(scope, data, "before");
|
|
1152
1159
|
if (typeof target === "object")
|
|
1153
1160
|
return target;
|
|
@@ -1165,7 +1172,7 @@ export class FileFileHistoryStore {
|
|
|
1165
1172
|
return await this.runImport(scope, data, srcGetBlob, importJournal, identicalRepublish);
|
|
1166
1173
|
}
|
|
1167
1174
|
catch (err) {
|
|
1168
|
-
return { ok: false, error: { code: "
|
|
1175
|
+
return { ok: false, error: { code: "adopt_failed", message: `importHistory failed: ${thrownText(err)}`, ...caughtFault(err) } };
|
|
1169
1176
|
}
|
|
1170
1177
|
}
|
|
1171
1178
|
async runImport(scope, data, srcGetBlob, importJournal, identicalRepublish) {
|
|
@@ -1192,12 +1199,12 @@ export class FileFileHistoryStore {
|
|
|
1192
1199
|
bytes = await srcGetBlob(v.blobHash);
|
|
1193
1200
|
}
|
|
1194
1201
|
catch (err) {
|
|
1195
|
-
return { ok: false, error: { code: "
|
|
1202
|
+
return { ok: false, error: { code: "adopt_failed", message: `source blob ${v.blobHash} fetch failed: ${thrownText(err)}`, ...caughtFault(err) } };
|
|
1196
1203
|
}
|
|
1197
1204
|
if (bytes === undefined)
|
|
1198
1205
|
return { ok: false, error: { code: "adopt_failed", message: `source blob ${v.blobHash} is missing — the envelope's graph cannot be completed, so nothing is published` } };
|
|
1199
1206
|
if (createHash("sha256").update(bytes).digest("hex") !== v.blobHash) {
|
|
1200
|
-
return { ok: false, error: { code: "
|
|
1207
|
+
return { ok: false, error: { code: "adopt_failed", message: `source blob ${v.blobHash} fails content-address integrity — refused, nothing published` } };
|
|
1201
1208
|
}
|
|
1202
1209
|
this.putBlob(v.blobHash, bytes);
|
|
1203
1210
|
}
|
|
@@ -1251,7 +1258,7 @@ export class FileFileHistoryStore {
|
|
|
1251
1258
|
return { ok: true };
|
|
1252
1259
|
}
|
|
1253
1260
|
catch (err) {
|
|
1254
|
-
return { ok: false, error: { code: "
|
|
1261
|
+
return { ok: false, error: { code: "adopt_failed", message: `importHistory failed: ${thrownText(err)}`, ...caughtFault(err) } };
|
|
1255
1262
|
}
|
|
1256
1263
|
finally {
|
|
1257
1264
|
safeRm(importJournal);
|
|
@@ -62,7 +62,8 @@ export class FileStorageBackend {
|
|
|
62
62
|
this.fileSessions = repo;
|
|
63
63
|
this.ttl = new TtlSessionStore({ repo, evict: opts.evict ?? "forget", durability: "durable", placements: { subagent: { durability: "durable" } } });
|
|
64
64
|
this.sessionStore = this.ttl;
|
|
65
|
-
|
|
65
|
+
const sessionHeadOf = this.ttl.headOf;
|
|
66
|
+
this.fileCheckpoints = new FileCheckpointStore(this.root, { ...opts.checkpoint, ...corruptRead, ...(sessionHeadOf !== undefined ? { sessionHeadOf } : {}) });
|
|
66
67
|
built.push(() => this.fileCheckpoints.close());
|
|
67
68
|
this.checkpointStore = this.fileCheckpoints;
|
|
68
69
|
this.fileMemory = new FileMemoryStore(this.root, opts.embedder ? { embedder: opts.embedder } : {});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type MailboxAckResult, type MailboxAppendMessage, type MailboxLease, type MailboxStore } from "../../core/mailbox-store.js";
|
|
1
|
+
import { type MailboxAckResult, type MailboxAppendMessage, type MailboxLease, type MailboxDecisionOutcome, type MailboxDecision, type MailboxStore } from "../../core/mailbox-store.js";
|
|
2
2
|
import { type CorruptReadInfo } from "./corrupt-read-sink.js";
|
|
3
3
|
/** The waiter's refusal when a box lock stays held by a LIVE process past `lockWaitMs`. Carried as
|
|
4
4
|
* `.code` on a plain Error (consumers branch on the string); the message names the lock and the holder. */
|
|
@@ -113,6 +113,7 @@ export declare class FileMailboxStore implements MailboxStore {
|
|
|
113
113
|
append(scope: string, handle: string, msg: MailboxAppendMessage): Promise<number>;
|
|
114
114
|
claimLease(scope: string, handle: string, owner: string, ttlMs: number, now?: number): Promise<MailboxLease | null>;
|
|
115
115
|
ack(scope: string, handle: string, owner: string, upToSeq: number): Promise<MailboxAckResult>;
|
|
116
|
+
moveDecision(scope: string, handle: string, seq: number, expect: MailboxDecision | undefined, next: MailboxDecision): Promise<MailboxDecisionOutcome>;
|
|
116
117
|
releaseLease(scope: string, handle: string, owner: string): Promise<void>;
|
|
117
118
|
peekCount(scope: string, handle: string): Promise<number>;
|
|
118
119
|
drop(scope: string, handle: string): Promise<void>;
|
|
@@ -2,7 +2,7 @@ import { join, resolve, sep } from "node:path";
|
|
|
2
2
|
import { createHash, randomBytes } from "node:crypto";
|
|
3
3
|
import { assertRetentionPolicy } from "../../core/retention-policy.js";
|
|
4
4
|
import { existsSync, linkSync, readdirSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { detachMailboxMessage, newestSentAt, readMailboxPeerMeta, } from "../../core/mailbox-store.js";
|
|
5
|
+
import { assertMailboxDecisionMove, detachMailboxMessage, newestSentAt, readStoredMailboxDecision, readMailboxPeerMeta, } from "../../core/mailbox-store.js";
|
|
6
6
|
import { AppendLog, atomicWriteFile, canonicalStoreKey, ensureDir, readJsonlRecords, sanitizeScope, sanitizePathComponent } from "./fs-atomic.js";
|
|
7
7
|
import { guardCorruptSink } from "./corrupt-read-sink.js";
|
|
8
8
|
import { physicalPathOf } from "../../core/physical-path.js";
|
|
@@ -478,6 +478,19 @@ export class FileMailboxStore {
|
|
|
478
478
|
return { acked: true };
|
|
479
479
|
});
|
|
480
480
|
}
|
|
481
|
+
async moveDecision(scope, handle, seq, expect, next) {
|
|
482
|
+
assertMailboxDecisionMove(seq, expect, next);
|
|
483
|
+
return this.withBox(this.lockKey(scope, handle), this.boxPath(scope, handle), () => {
|
|
484
|
+
const b = this.load(scope, handle);
|
|
485
|
+
const m = b.messages.find((x) => x.seq === seq);
|
|
486
|
+
if (m === undefined)
|
|
487
|
+
return { ok: false, current: "gone" };
|
|
488
|
+
if (m.decision !== expect)
|
|
489
|
+
return { ok: false, current: m.decision ?? "unset" };
|
|
490
|
+
this.commit(b, this.boxPath(scope, handle), { t: "decision", seq, state: next });
|
|
491
|
+
return { ok: true };
|
|
492
|
+
});
|
|
493
|
+
}
|
|
481
494
|
async releaseLease(scope, handle, owner) {
|
|
482
495
|
return this.withBox(this.lockKey(scope, handle), this.boxPath(scope, handle), () => {
|
|
483
496
|
const b = this.load(scope, handle);
|
|
@@ -592,12 +605,19 @@ const MAILBOX_EVENT_JUDGE = {
|
|
|
592
605
|
return typeof ev.owner === "string" && num(ev.maxSeq) && num(ev.expiresAt);
|
|
593
606
|
if (ev.t === "ack")
|
|
594
607
|
return num(ev.upToSeq);
|
|
608
|
+
if (ev.t === "decision")
|
|
609
|
+
return num(r.seq) && typeof r.state === "string";
|
|
595
610
|
return ev.t === "release" && typeof ev.owner === "string";
|
|
596
611
|
},
|
|
597
612
|
what: "a mailbox record is not one of this box's events — an unknown tag, or a known tag whose payload is missing",
|
|
598
613
|
};
|
|
599
614
|
function applyEvent(b, ev) {
|
|
600
615
|
if (ev.t === "append") {
|
|
616
|
+
const decision = readStoredMailboxDecision(ev.m.decision);
|
|
617
|
+
if (decision === undefined)
|
|
618
|
+
delete ev.m.decision;
|
|
619
|
+
else
|
|
620
|
+
ev.m.decision = decision;
|
|
601
621
|
b.messages.push(ev.m);
|
|
602
622
|
if (ev.m.seq >= b.nextSeq)
|
|
603
623
|
b.nextSeq = ev.m.seq + 1;
|
|
@@ -613,6 +633,11 @@ function applyEvent(b, ev) {
|
|
|
613
633
|
if (b.lease !== undefined && b.lease.maxSeq <= ev.upToSeq)
|
|
614
634
|
b.lease = undefined;
|
|
615
635
|
}
|
|
636
|
+
else if (ev.t === "decision") {
|
|
637
|
+
const m = b.messages.find((x) => x.seq === ev.seq);
|
|
638
|
+
if (m !== undefined)
|
|
639
|
+
m.decision = readStoredMailboxDecision(ev.state) ?? "held";
|
|
640
|
+
}
|
|
616
641
|
else if (b.lease?.owner === ev.owner) {
|
|
617
642
|
b.lease = undefined;
|
|
618
643
|
}
|