@sema-agent/core 7.60.0 → 7.62.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 +917 -0
- package/README.md +2 -2
- package/dist/agents/agent-transcript-tool.d.ts +2 -2
- package/dist/agents/agent-transcript-tool.js +1 -1
- package/dist/agents/cascade.d.ts +71 -12
- package/dist/agents/cascade.js +61 -21
- package/dist/agents/composition-allowance.d.ts +53 -0
- package/dist/agents/composition-allowance.js +49 -0
- package/dist/agents/composition-placement.d.ts +29 -0
- package/dist/agents/composition-placement.js +24 -0
- package/dist/agents/cumulative-stats.d.ts +4 -0
- package/dist/agents/cumulative-stats.js +3 -0
- package/dist/agents/inherited-tool-pool.d.ts +5 -3
- package/dist/agents/inherited-tool-pool.js +2 -2
- package/dist/agents/list-agents-tool.d.ts +1 -1
- package/dist/agents/peer-held-queue.d.ts +27 -4
- package/dist/agents/peer-held-queue.js +81 -36
- package/dist/agents/peer-notice-route.d.ts +1 -1
- package/dist/agents/peer-notice-route.js +4 -3
- package/dist/agents/peer-notices.d.ts +4 -4
- package/dist/agents/peer-notices.js +8 -4
- package/dist/agents/peer-session-drain.d.ts +8 -1
- package/dist/agents/peer-session-drain.js +49 -10
- package/dist/agents/repair-loop.js +16 -6
- package/dist/agents/retain-ledger.js +3 -1
- package/dist/agents/roster-store.d.ts +1 -1
- package/dist/agents/roster-store.js +7 -4
- package/dist/agents/send-message-tool.d.ts +8 -10
- package/dist/agents/send-message-tool.js +43 -23
- package/dist/agents/subagent-completion-gate.d.ts +35 -0
- package/dist/agents/subagent-completion-gate.js +62 -0
- package/dist/agents/subagent-steps.d.ts +7 -6
- package/dist/agents/subagent.d.ts +36 -41
- package/dist/agents/subagent.js +245 -200
- package/dist/agents/suspend-guard.d.ts +47 -16
- package/dist/agents/suspend-guard.js +13 -4
- package/dist/agents/verify.d.ts +41 -14
- package/dist/agents/verify.js +41 -30
- package/dist/brain/anthropic.js +1 -0
- package/dist/brain/errors.d.ts +7 -1
- package/dist/brain/errors.js +6 -0
- package/dist/brain/failover.js +2 -1
- package/dist/brain/open-responses.js +1 -0
- package/dist/brain/openai.js +1 -0
- package/dist/brain/provider-dialect.d.ts +10 -0
- package/dist/brain/provider-dialect.js +13 -2
- package/dist/brain/stream-engine.d.ts +3 -0
- package/dist/brain/stream-engine.js +4 -0
- package/dist/core/agent-state.d.ts +1 -1
- package/dist/core/allow-entry.d.ts +59 -23
- package/dist/core/allow-entry.js +131 -38
- package/dist/core/ask-origin.d.ts +79 -0
- package/dist/core/ask-origin.js +76 -0
- package/dist/core/ask-question.d.ts +19 -13
- package/dist/core/ask-question.js +8 -2
- package/dist/core/auto-compaction.d.ts +2 -0
- package/dist/core/auto-compaction.js +2 -1
- package/dist/core/auto-mode.js +3 -5
- package/dist/core/background-agent-store.d.ts +7 -5
- package/dist/core/background-agent-store.js +12 -11
- package/dist/core/checkpoint-features.d.ts +722 -0
- package/dist/core/checkpoint-features.js +98 -0
- package/dist/core/checkpoint-requirements.d.ts +33 -5
- package/dist/core/checkpoint-requirements.js +18 -5
- package/dist/core/checkpoint-row-verdict.d.ts +99 -0
- package/dist/core/checkpoint-row-verdict.js +225 -0
- package/dist/core/checkpoint-store.d.ts +107 -738
- package/dist/core/checkpoint-store.js +45 -143
- package/dist/core/child-clamp-seats.d.ts +3 -2
- package/dist/core/child-clamp-seats.js +4 -3
- package/dist/core/closest-name.d.ts +13 -0
- package/dist/core/closest-name.js +35 -0
- package/dist/core/context-settings.js +3 -5
- package/dist/core/cross-boundary-taint.d.ts +1 -1
- package/dist/core/decision-receipt.d.ts +14 -1
- package/dist/core/decision-receipt.js +6 -3
- package/dist/core/delegation-frames.d.ts +13 -9
- package/dist/core/effective-path-target.js +2 -3
- package/dist/core/engine-attestation.d.ts +11 -1
- package/dist/core/engine-attestation.js +2 -0
- package/dist/core/engine-notice.d.ts +68 -21
- package/dist/core/engine-notice.js +9 -2
- package/dist/core/file-history-retention.d.ts +8 -0
- package/dist/core/file-history-retention.js +14 -11
- package/dist/core/file-history-store.d.ts +31 -1
- package/dist/core/file-history-store.js +31 -2
- package/dist/core/frame-settlement.d.ts +10 -0
- package/dist/core/frame-settlement.js +6 -1
- package/dist/core/fs-write-gate-policy.d.ts +3 -3
- package/dist/core/fs-write-gate-policy.js +8 -7
- package/dist/core/gate-fold.js +4 -3
- package/dist/core/gate-lanes.js +7 -4
- package/dist/core/gate-outcome.d.ts +40 -1
- package/dist/core/gate-outcome.js +10 -0
- package/dist/core/git-worktree-env.d.ts +7 -3
- package/dist/core/git-worktree-env.js +16 -13
- package/dist/core/governance-codes.d.ts +14 -4
- package/dist/core/governance-codes.js +19 -4
- package/dist/core/hooks.d.ts +25 -4
- package/dist/core/hooks.js +11 -4
- package/dist/core/host-floor.js +3 -5
- package/dist/core/human-input-projection.d.ts +1 -0
- package/dist/core/human-input-projection.js +3 -0
- package/dist/core/image-admission.d.ts +47 -7
- package/dist/core/image-admission.js +35 -4
- package/dist/core/input-author.d.ts +36 -0
- package/dist/core/input-author.js +39 -0
- package/dist/core/leg-identity.d.ts +62 -0
- package/dist/core/leg-identity.js +18 -0
- package/dist/core/locked-config.d.ts +4 -3
- package/dist/core/locked-config.js +5 -3
- package/dist/core/lsp.d.ts +5 -3
- package/dist/core/lsp.js +3 -2
- package/dist/core/mailbox-store.d.ts +85 -10
- package/dist/core/mailbox-store.js +31 -10
- package/dist/core/mcp-connection-pool.d.ts +6 -20
- package/dist/core/mcp-connection-pool.js +10 -28
- package/dist/core/mcp-failure.d.ts +76 -15
- package/dist/core/mcp-failure.js +60 -33
- package/dist/core/mcp-host-seat.d.ts +92 -53
- package/dist/core/mcp-host-seat.js +225 -46
- package/dist/core/mcp-probe.js +2 -2
- package/dist/core/mcp-server-link.d.ts +18 -6
- package/dist/core/mcp-server-link.js +19 -4
- package/dist/core/mcp-server-spec.d.ts +2 -1
- package/dist/core/mcp-session-end.d.ts +1 -2
- package/dist/core/mcp-session-end.js +1 -1
- package/dist/core/mcp.d.ts +6 -49
- package/dist/core/mcp.js +115 -111
- package/dist/core/media-byte-cap.d.ts +21 -46
- package/dist/core/media-byte-cap.js +55 -55
- package/dist/core/member-group.d.ts +7 -0
- package/dist/core/member-group.js +35 -0
- package/dist/core/memory-engine/consolidation-driver.d.ts +1 -1
- package/dist/core/memory-engine/consolidation.d.ts +1 -1
- package/dist/core/memory-engine/consolidation.js +7 -1
- package/dist/core/memory-engine/dual-root.d.ts +31 -0
- package/dist/core/memory-engine/dual-root.js +59 -11
- package/dist/core/memory-engine/engine.js +27 -24
- package/dist/core/memory-engine/file-backend.d.ts +13 -0
- package/dist/core/memory-engine/file-backend.js +35 -15
- package/dist/core/memory-engine/layout.d.ts +3 -0
- package/dist/core/memory-engine/layout.js +13 -3
- package/dist/core/memory-engine/memory-deployment.d.ts +110 -0
- package/dist/core/memory-engine/memory-deployment.js +182 -0
- package/dist/core/memory-engine/sync-client.d.ts +39 -18
- package/dist/core/memory-engine/sync-client.js +72 -14
- package/dist/core/memory-engine/sync-report.d.ts +7 -4
- package/dist/core/memory-engine/sync.d.ts +9 -1
- package/dist/core/memory-vector.d.ts +1 -1
- package/dist/core/memory.d.ts +10 -10
- package/dist/core/mode-policy.d.ts +8 -8
- package/dist/core/mode-policy.js +8 -6
- package/dist/core/mods/agent-stations.d.ts +39 -4
- package/dist/core/mods/agent-stations.js +59 -10
- package/dist/core/mods/classic-events.d.ts +9 -1
- package/dist/core/mods/dollar.d.ts +94 -1
- package/dist/core/mods/dollar.js +13 -1
- package/dist/core/mods/extension-call.d.ts +15 -1
- package/dist/core/mods/extension-call.js +7 -2
- package/dist/core/mods/kernel/dispatch.d.ts +4 -3
- package/dist/core/mods/kernel/dispatch.js +4 -4
- package/dist/core/mods/kernel/events.d.ts +14 -3
- package/dist/core/mods/kernel/events.js +18 -15
- package/dist/core/mods/kernel/registration.d.ts +3 -0
- package/dist/core/mods/kernel/registration.js +5 -0
- package/dist/core/mods/kernel/site-rules.d.ts +6 -3
- package/dist/core/mods/kernel/site-rules.js +10 -2
- package/dist/core/mods/lifecycle-stations.d.ts +36 -4
- package/dist/core/mods/lifecycle-stations.js +44 -9
- package/dist/core/mods/session-append.d.ts +118 -0
- package/dist/core/mods/session-append.js +318 -0
- package/dist/core/mods/session-compact.d.ts +48 -0
- package/dist/core/mods/session-compact.js +194 -0
- package/dist/core/mods/session-receive.d.ts +93 -0
- package/dist/core/mods/session-receive.js +138 -0
- package/dist/core/mods/session-send.d.ts +72 -0
- package/dist/core/mods/session-send.js +88 -0
- package/dist/core/mods/stations.d.ts +88 -21
- package/dist/core/mods/stations.js +149 -11
- package/dist/core/mods/tool-call.d.ts +2 -0
- package/dist/core/mods/tool-call.js +4 -4
- package/dist/core/output-style.js +3 -4
- package/dist/core/own-property-receipt.d.ts +68 -2
- package/dist/core/own-property-receipt.js +45 -2
- package/dist/core/park-selfcheck.js +4 -2
- package/dist/core/path-identity.d.ts +11 -0
- package/dist/core/path-identity.js +4 -0
- package/dist/core/path-rule-binding.d.ts +3 -1
- package/dist/core/path-rule-binding.js +3 -1
- package/dist/core/peer-seat.d.ts +3 -3
- package/dist/core/peer-seat.js +20 -8
- package/dist/core/permission-rule-consent.d.ts +21 -5
- package/dist/core/permission-rule-consent.js +21 -1
- package/dist/core/permission-rule-model.d.ts +34 -11
- package/dist/core/permission-rule-model.js +47 -10
- package/dist/core/permission-rule-org.d.ts +1 -1
- package/dist/core/permission-rule-provider.js +4 -1
- package/dist/core/permission-rules.d.ts +4 -0
- package/dist/core/permission-rules.js +11 -16
- package/dist/core/read-root-candidate.js +1 -1
- package/dist/core/remote-env.d.ts +74 -26
- package/dist/core/remote-env.js +20 -0
- package/dist/core/resume-startup-cause.d.ts +5 -4
- package/dist/core/retention-policy.d.ts +24 -23
- package/dist/core/retention-policy.js +36 -2
- package/dist/core/retention.d.ts +4 -1
- package/dist/core/retired-keys.d.ts +4 -4
- package/dist/core/row-admission.d.ts +10 -0
- package/dist/core/row-admission.js +5 -0
- package/dist/core/runner/advisor-instructions.d.ts +2 -1
- package/dist/core/runner/advisor-instructions.js +2 -1
- package/dist/core/runner/announce-once-ledger.d.ts +4 -4
- package/dist/core/runner/assemble-result.d.ts +13 -3
- package/dist/core/runner/assemble-result.js +12 -7
- package/dist/core/runner/caller-roster.d.ts +12 -9
- package/dist/core/runner/caller-roster.js +5 -2
- package/dist/core/runner/checkpoint-scope.d.ts +16 -1
- package/dist/core/runner/checkpoint-scope.js +21 -0
- package/dist/core/runner/compact-session.js +18 -3
- package/dist/core/runner/compaction-call-options.d.ts +1 -1
- package/dist/core/runner/compaction-restate.d.ts +2 -2
- package/dist/core/runner/compaction-restate.js +4 -3
- package/dist/core/runner/construction-doors.d.ts +2 -2
- package/dist/core/runner/construction-doors.js +2 -2
- package/dist/core/runner/contracts.d.ts +116 -34
- package/dist/core/runner/cross-boundary-lane.d.ts +1 -1
- package/dist/core/runner/decide-continuation.d.ts +4 -2
- package/dist/core/runner/decide-continuation.js +7 -4
- package/dist/core/runner/delegation-owner.d.ts +43 -0
- package/dist/core/runner/delegation-owner.js +59 -0
- package/dist/core/runner/denial-limit-arms.d.ts +15 -21
- package/dist/core/runner/denial-limit-arms.js +17 -10
- package/dist/core/runner/expire-settle.d.ts +44 -0
- package/dist/core/runner/expire-settle.js +55 -0
- package/dist/core/runner/git-status-frame.d.ts +3 -3
- package/dist/core/runner/git-status-frame.js +2 -1
- package/dist/core/runner/halt-attribution.d.ts +2 -1
- package/dist/core/runner/halt-attribution.js +2 -1
- package/dist/core/runner/lineage-reroot-view.d.ts +56 -0
- package/dist/core/runner/lineage-reroot-view.js +108 -0
- package/dist/core/runner/local-claims.d.ts +17 -0
- package/dist/core/runner/local-claims.js +18 -0
- package/dist/core/runner/media-removed-seat.d.ts +46 -0
- package/dist/core/runner/media-removed-seat.js +88 -0
- package/dist/core/runner/park-commit.d.ts +2 -2
- package/dist/core/runner/permission-rule-lanes.d.ts +7 -2
- package/dist/core/runner/permission-rule-lanes.js +28 -9
- package/dist/core/runner/person-path-rows.d.ts +15 -0
- package/dist/core/runner/person-path-rows.js +27 -4
- package/dist/core/runner/placement-fence.d.ts +26 -0
- package/dist/core/runner/placement-fence.js +38 -0
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +4 -1
- package/dist/core/runner/prepare-acquire-reconcile.js +7 -2
- package/dist/core/runner/prepare-ask-lane.d.ts +6 -12
- package/dist/core/runner/prepare-ask-lane.js +4 -4
- package/dist/core/runner/prepare-boundary-parks.d.ts +4 -1
- package/dist/core/runner/prepare-boundary-parks.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +3 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +2 -1
- package/dist/core/runner/prepare-config-doors.d.ts +6 -6
- package/dist/core/runner/prepare-config-doors.js +19 -21
- package/dist/core/runner/prepare-context-lane.d.ts +6 -2
- package/dist/core/runner/prepare-context-lane.js +13 -13
- package/dist/core/runner/prepare-delegation-surface.d.ts +9 -9
- package/dist/core/runner/prepare-delegation-surface.js +4 -5
- package/dist/core/runner/prepare-execution-env.d.ts +5 -2
- package/dist/core/runner/prepare-execution-env.js +7 -4
- package/dist/core/runner/prepare-gate-stations.d.ts +19 -14
- package/dist/core/runner/prepare-gate-stations.js +6 -4
- package/dist/core/runner/prepare-hands-readface.d.ts +6 -6
- package/dist/core/runner/prepare-hands-readface.js +32 -11
- package/dist/core/runner/prepare-inherited-gate.d.ts +8 -0
- package/dist/core/runner/prepare-inherited-gate.js +10 -3
- package/dist/core/runner/prepare-lsp.d.ts +3 -0
- package/dist/core/runner/prepare-lsp.js +2 -2
- package/dist/core/runner/prepare-park-ask.d.ts +5 -2
- package/dist/core/runner/prepare-park-ask.js +4 -5
- package/dist/core/runner/prepare-policy-chain.d.ts +10 -21
- package/dist/core/runner/prepare-policy-chain.js +16 -25
- package/dist/core/runner/prepare-project-context.d.ts +2 -2
- package/dist/core/runner/prepare-prompt-inputs.d.ts +5 -4
- package/dist/core/runner/prepare-prompt-inputs.js +3 -2
- package/dist/core/runner/prepare-question-face.d.ts +6 -4
- package/dist/core/runner/prepare-question-face.js +2 -2
- package/dist/core/runner/prepare-run-refs.d.ts +3 -0
- package/dist/core/runner/prepare-run-refs.js +2 -2
- package/dist/core/runner/prepare-suspend-saga.d.ts +11 -7
- package/dist/core/runner/prepare-suspend-saga.js +17 -7
- package/dist/core/runner/prepare-task.d.ts +1 -1
- package/dist/core/runner/prepare-task.js +61 -30
- package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +6 -0
- package/dist/core/runner/prepare-tool-disclosure-mount.js +3 -1
- package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -0
- package/dist/core/runner/prepare-wiring-manifest.js +2 -1
- package/dist/core/runner/prepare-workspace-restore.d.ts +5 -0
- package/dist/core/runner/prepare-workspace-restore.js +10 -6
- package/dist/core/runner/read-root-grant.d.ts +1 -1
- package/dist/core/runner/read-root-grant.js +2 -1
- package/dist/core/runner/resume-admission.d.ts +8 -6
- package/dist/core/runner/resume-admission.js +23 -6
- package/dist/core/runner/resume-apply.d.ts +4 -0
- package/dist/core/runner/resume-apply.js +14 -5
- package/dist/core/runner/resume-checkpoint-screen.d.ts +9 -0
- package/dist/core/runner/resume-checkpoint-screen.js +4 -84
- package/dist/core/runner/resume-claim.d.ts +8 -3
- package/dist/core/runner/resume-claim.js +28 -12
- package/dist/core/runner/resume-internals-and-config.d.ts +2 -2
- package/dist/core/runner/resume-internals-and-config.js +10 -1
- package/dist/core/runner/resume-preflight.d.ts +3 -2
- package/dist/core/runner/resume-preflight.js +13 -26
- package/dist/core/runner/retired-runner-deps.js +2 -0
- package/dist/core/runner/run-git-lane.d.ts +2 -0
- package/dist/core/runner/run-git-lane.js +6 -2
- package/dist/core/runner/run-harness-handlers.d.ts +2 -0
- package/dist/core/runner/run-harness-handlers.js +5 -4
- package/dist/core/runner/run-identity-wiring.d.ts +2 -2
- package/dist/core/runner/run-identity-wiring.js +14 -5
- package/dist/core/runner/run-leg.d.ts +3 -3
- package/dist/core/runner/run-leg.js +64 -36
- package/dist/core/runner/run-notification-lane.js +20 -2
- package/dist/core/runner/run-recovery-lanes.js +3 -2
- package/dist/core/runner/run-settle-and-teardown.js +12 -9
- package/dist/core/runner/run-stop-and-final-verify.js +2 -1
- package/dist/core/runner/run-telemetry-and-budget-seats.d.ts +1 -1
- package/dist/core/runner/run-terminal-adoption.d.ts +1 -1
- package/dist/core/runner/run-terminal-adoption.js +26 -17
- package/dist/core/runner/run-turn-boundary.js +34 -18
- package/dist/core/runner/runtask.d.ts +18 -3
- package/dist/core/runner/runtask.js +33 -17
- package/dist/core/runner/session-rule-policy.d.ts +1 -1
- package/dist/core/runner/session-rule-policy.js +6 -1
- package/dist/core/runner/shell-env-withheld.d.ts +1 -1
- package/dist/core/runner/steering-preview.d.ts +9 -0
- package/dist/core/runner/steering-preview.js +5 -0
- package/dist/core/runner/stream-halt-verbs.d.ts +1 -14
- package/dist/core/runner/stream-halt-verbs.js +4 -3
- package/dist/core/runner/stream-reap.d.ts +7 -6
- package/dist/core/runner/stream-reap.js +13 -16
- package/dist/core/runner/stream-settle-backstop.d.ts +3 -2
- package/dist/core/runner/stream-settle-backstop.js +5 -3
- package/dist/core/runner/stream-steer-verb.d.ts +5 -2
- package/dist/core/runner/stream-steer-verb.js +16 -7
- package/dist/core/runner/terminal-account.d.ts +11 -1
- package/dist/core/runner/terminal-account.js +20 -0
- package/dist/core/runner/terminal-projection.d.ts +8 -2
- package/dist/core/runner/terminal-projection.js +2 -2
- package/dist/core/runner/tool-disclosure.d.ts +3 -0
- package/dist/core/runner/tool-disclosure.js +5 -2
- package/dist/core/runner/tool-end-body.d.ts +3 -3
- package/dist/core/runner/tool-end-body.js +1 -1
- package/dist/core/runner/tool-face-overlay.js +2 -0
- package/dist/core/runner/tool-output-projection.d.ts +3 -3
- package/dist/core/runner/tool-output-projection.js +7 -6
- package/dist/core/runner/tool-table-view.d.ts +56 -0
- package/dist/core/runner/tool-table-view.js +51 -0
- package/dist/core/runner/turn-attachments.d.ts +8 -2
- package/dist/core/runner/turn-attachments.js +2 -2
- package/dist/core/runner/void-verifier-pause.d.ts +33 -0
- package/dist/core/runner/void-verifier-pause.js +41 -0
- package/dist/core/runner-deps.d.ts +26 -27
- package/dist/core/secret-env.d.ts +19 -16
- package/dist/core/secret-env.js +45 -27
- package/dist/core/session-log-transfer.js +9 -10
- package/dist/core/session-policy-store.d.ts +1 -1
- package/dist/core/session-policy-store.js +5 -2
- package/dist/core/session-reconcile.d.ts +3 -2
- package/dist/core/session-reconcile.js +7 -4
- package/dist/core/session-store.d.ts +3 -1
- package/dist/core/session-store.js +10 -8
- package/dist/core/session.d.ts +16 -5
- package/dist/core/shell-confinement.d.ts +37 -0
- package/dist/core/shell-confinement.js +56 -0
- package/dist/core/skill-grant.js +1 -1
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +8 -2
- package/dist/core/store-contracts/checkpoint-store-contract.js +83 -2
- package/dist/core/store-contracts/file-history-store-contract.d.ts +5 -2
- package/dist/core/store-contracts/file-history-store-contract.js +25 -1
- package/dist/core/store-contracts/mailbox-store-contract.d.ts +12 -5
- package/dist/core/store-contracts/mailbox-store-contract.js +156 -9
- package/dist/core/store-contracts/session-store-contract.js +22 -8
- package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
- package/dist/core/store-contracts/tool-result-store-contract.js +30 -0
- package/dist/core/task-event.d.ts +24 -9
- package/dist/core/task-limits.d.ts +5 -0
- package/dist/core/task-notification.d.ts +89 -12
- package/dist/core/task-notification.js +89 -14
- package/dist/core/task-registry-agent.d.ts +32 -50
- package/dist/core/task-registry-agent.js +36 -56
- package/dist/core/task-registry-monitor.d.ts +1 -1
- package/dist/core/task-registry-monitor.js +15 -60
- package/dist/core/task-registry-shared.d.ts +22 -112
- package/dist/core/task-registry-shared.js +3 -41
- package/dist/core/task-registry-workflow.js +5 -21
- package/dist/core/task-registry.d.ts +32 -62
- package/dist/core/task-registry.js +30 -110
- package/dist/core/task-result.d.ts +29 -12
- package/dist/core/task-spec-members.d.ts +39 -0
- package/dist/core/task-spec-members.js +92 -0
- package/dist/core/task-spec.d.ts +11 -11
- package/dist/core/task-tool-shape.d.ts +7 -57
- package/dist/core/task-tool-shape.js +7 -66
- package/dist/core/terminal-cause.d.ts +36 -6
- package/dist/core/terminal-cause.js +1 -0
- package/dist/core/tool-catalog-entries.js +2 -5
- package/dist/core/tool-check-reading.js +16 -10
- package/dist/core/tool-conformance.js +1 -2
- package/dist/core/tool-errors.d.ts +6 -3
- package/dist/core/tool-errors.js +2 -0
- package/dist/core/tool-face-reader.js +3 -2
- package/dist/core/tool-face.d.ts +8 -5
- package/dist/core/tool-face.js +1 -1
- package/dist/core/tool-name-aliases.d.ts +5 -29
- package/dist/core/tool-name-aliases.js +9 -5
- package/dist/core/tool-name-readings.d.ts +14 -3
- package/dist/core/tool-name-readings.js +2 -0
- package/dist/core/tool-policy.d.ts +109 -18
- package/dist/core/tool-policy.js +84 -14
- package/dist/core/tool-result-store.d.ts +23 -0
- package/dist/core/tool-result-store.js +3 -2
- package/dist/core/tool-roster.d.ts +4 -4
- package/dist/core/tool-spec.d.ts +23 -6
- package/dist/core/trace.d.ts +18 -1
- package/dist/core/types.d.ts +1 -1
- package/dist/core/types.js +1 -1
- package/dist/core/user-attachment.js +26 -21
- package/dist/core/workflow-journal-store.d.ts +1 -1
- package/dist/core/workflow-run-store.d.ts +2 -0
- package/dist/core/workflow-run-store.js +6 -5
- package/dist/core/workflow-settled-run.d.ts +5 -0
- package/dist/core/workflow-settled-run.js +7 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +37 -9
- package/dist/engine/execution-env/node-execution-env.js +221 -22
- package/dist/engine/harness/agent-harness.d.ts +65 -18
- package/dist/engine/harness/agent-harness.js +90 -23
- package/dist/engine/harness/messages.d.ts +4 -3
- package/dist/engine/harness/messages.js +2 -2
- package/dist/engine/harness/types.d.ts +52 -7
- package/dist/engine/llm/media-removed.d.ts +14 -0
- package/dist/engine/llm/media-removed.js +9 -0
- package/dist/engine/llm/rejected-images.d.ts +35 -25
- package/dist/engine/llm/rejected-images.js +59 -10
- package/dist/engine/llm/types.d.ts +24 -3
- package/dist/engine/llm/types.js +7 -3
- package/dist/engine/loop/agent-loop.d.ts +6 -1
- package/dist/engine/loop/agent-loop.js +20 -11
- package/dist/engine/loop/types.d.ts +12 -3
- package/dist/engine/session/import-validate.js +7 -0
- package/dist/engine/session/parent-chain-guard.d.ts +3 -3
- package/dist/engine/session/parent-chain-guard.js +1 -1
- package/dist/engine/session/path-to-root.d.ts +18 -3
- package/dist/engine/session/path-to-root.js +15 -1
- package/dist/engine/session/repo-utils.d.ts +12 -1
- package/dist/engine/session/repo-utils.js +41 -0
- package/dist/engine/session/session.js +1 -1
- package/dist/engine/session/storage-base.d.ts +20 -0
- package/dist/engine/session/storage-base.js +28 -9
- package/dist/fixtures/index.d.ts +7 -5
- package/dist/fixtures/index.js +5 -3
- package/dist/index.d.ts +29 -18
- package/dist/index.js +19 -11
- package/dist/internal/harness-types.d.ts +2 -0
- package/dist/internal/harness.d.ts +4 -3
- package/dist/internal/harness.js +3 -2
- package/dist/internal/llm.d.ts +2 -1
- package/dist/internal/llm.js +1 -0
- package/dist/orchestration/goal.d.ts +6 -2
- package/dist/orchestration/goal.js +6 -3
- package/dist/orchestration/run-workflow-tool.d.ts +14 -17
- package/dist/orchestration/run-workflow-tool.js +43 -50
- package/dist/orchestration/workflow-types.d.ts +2 -2
- package/dist/orchestration/workflow.d.ts +7 -0
- package/dist/orchestration/workflow.js +10 -12
- package/dist/stores/file/background-agent-store.js +18 -15
- package/dist/stores/file/checkpoint-store.d.ts +2 -0
- package/dist/stores/file/checkpoint-store.js +13 -9
- package/dist/stores/file/file-history-store.js +3 -2
- package/dist/stores/file/fs-atomic.d.ts +0 -22
- package/dist/stores/file/fs-atomic.js +0 -17
- package/dist/stores/file/index.d.ts +7 -12
- package/dist/stores/file/index.js +25 -12
- package/dist/stores/file/ledger-tuning.d.ts +23 -0
- package/dist/stores/file/ledger-tuning.js +21 -0
- package/dist/stores/file/mailbox-store.js +42 -22
- package/dist/stores/file/memory-store.js +3 -2
- package/dist/stores/file/permission-rule-adopt.js +24 -21
- package/dist/stores/file/permission-rule-store.js +6 -3
- package/dist/stores/file/session-policy-store.js +3 -2
- package/dist/stores/file/session-store.d.ts +26 -7
- package/dist/stores/file/session-store.js +59 -35
- package/dist/stores/file/tool-result-store.d.ts +11 -0
- package/dist/stores/file/tool-result-store.js +57 -3
- package/dist/stores/file/usage-window-store.js +3 -2
- package/dist/stores/file/workflow-journal-store.d.ts +0 -2
- package/dist/stores/file/workflow-journal-store.js +3 -18
- package/dist/stores/file/workflow-run-store.d.ts +1 -1
- package/dist/stores/file/workflow-run-store.js +15 -10
- package/dist/tools/fs/bash-program-position.d.ts +3 -2
- package/dist/tools/fs/bash-program-position.js +7 -7
- package/dist/tools/fs/dead-cwd.d.ts +5 -5
- package/dist/tools/fs/dead-cwd.js +4 -11
- package/dist/tools/fs/fs-bash-background-text.d.ts +6 -0
- package/dist/tools/fs/fs-bash-background-text.js +6 -0
- package/dist/tools/fs/fs-bash.d.ts +3 -18
- package/dist/tools/fs/fs-bash.js +37 -124
- package/dist/tools/fs/fs-pdf.js +8 -6
- package/dist/tools/fs/fs-read.js +2 -2
- package/dist/tools/fs/fs-shared.d.ts +28 -3
- package/dist/tools/fs/fs-shared.js +15 -0
- package/dist/tools/fs/index.d.ts +1 -1
- package/dist/tools/fs/index.js +4 -14
- package/dist/tools/fs/pdf.d.ts +4 -4
- package/dist/tools/fs/pdf.js +6 -6
- package/dist/tools/fs/read-deny-home.js +8 -1
- package/dist/tools/fs/read-deny.d.ts +26 -2
- package/dist/tools/fs/read-deny.js +9 -2
- package/dist/tools/fs/read-floor.d.ts +13 -5
- package/dist/tools/fs/read-floor.js +206 -2
- package/dist/tools/fs/removal-targets.js +2 -2
- package/dist/tools/fs/search.d.ts +3 -2
- package/dist/tools/fs/search.js +6 -6
- package/dist/tools/fs/shell-read-argv.d.ts +4 -2
- package/dist/tools/fs/shell-read-argv.js +14 -3
- package/dist/tools/fs/shell-read-bindings.d.ts +18 -2
- package/dist/tools/fs/shell-read-bindings.js +148 -68
- package/dist/tools/fs/shell-read-check.js +20 -4
- package/dist/tools/fs/shell-read-establish.js +25 -9
- package/dist/tools/fs/shell-read-functions.js +2 -2
- package/dist/tools/fs/shell-read-identity.d.ts +3 -1
- package/dist/tools/fs/shell-read-identity.js +4 -2
- package/dist/tools/fs/shell-read-judge.d.ts +7 -1
- package/dist/tools/fs/shell-read-judge.js +1 -1
- package/dist/tools/fs/shell-read-object-path.d.ts +59 -0
- package/dist/tools/fs/shell-read-object-path.js +119 -0
- package/dist/tools/fs/shell-read-plan.d.ts +8 -0
- package/dist/tools/fs/shell-read-plan.js +47 -30
- package/dist/tools/fs/shell-read-start.d.ts +66 -13
- package/dist/tools/fs/shell-read-start.js +89 -17
- package/dist/tools/fs/shell-read-workdir.d.ts +29 -8
- package/dist/tools/fs/shell-read-workdir.js +31 -8
- package/dist/tools/monitor.d.ts +8 -7
- package/dist/tools/monitor.js +12 -10
- package/dist/tools/worktree.d.ts +5 -1
- package/dist/tools/worktree.js +20 -17
- package/package.json +6 -3
- package/test/export-surface.snapshot.json +112 -42
- package/wire-changes/core-stores-sql@7.61.0.json +480 -0
- package/wire-changes/core-stores-sql@7.62.0.json +30 -0
- package/wire-changes/core@7.61.0.json +4405 -0
- package/wire-changes/core@7.62.0.json +2181 -0
- package/wire-changes/mods-kernel@7.61.0.json +65 -0
- package/wire-changes/mods-kernel@7.62.0.json +42 -0
- package/wire-changes/primitives@7.61.0.json +30 -0
- package/wire-changes/primitives@7.62.0.json +30 -0
- package/dist/core/consolidate-scope.d.ts +0 -93
- package/dist/core/consolidate-scope.js +0 -98
- package/dist/core/runner/image-removed-seat.d.ts +0 -12
- package/dist/core/runner/image-removed-seat.js +0 -19
- package/dist/core/runner/memory-consolidation.d.ts +0 -109
- package/dist/core/runner/memory-consolidation.js +0 -251
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { assertAdoptionBootGate } from "./adoption/marker.js";
|
|
3
|
-
import { receiveOptions } from "../../core/own-property-receipt.js";
|
|
3
|
+
import { memberPresent, optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
|
|
4
|
+
import { readLedgerTuning } from "./ledger-tuning.js";
|
|
4
5
|
import { checkpointExecutionRecorded, executionRecordDisposition, ExecutionOutcomeConflictError, } from "../../core/checkpoint-execution-record.js";
|
|
5
6
|
import { checkpointHolderMatches, checkpointOccMatches, checkpointRevOf } from "../../core/checkpoint-generation.js";
|
|
6
|
-
import { appendPendingSteer, CheckpointError, checkpointRowMatches, encodeAtFidelity,
|
|
7
|
+
import { appendPendingSteer, CheckpointError, checkpointRowMatches, encodeAtFidelity, summarizeStoredCheckpoint, validatePendingSteer, winnerFromOutcome, } from "../../core/checkpoint-store.js";
|
|
7
8
|
import { checkpointDeadlinePassed, deleteSessionRowsAtStart, readCheckpointOverdueQuery, readCheckpointSessionQuery, selectOverduePage, selectSessionPage, } from "../../core/checkpoint-queries.js";
|
|
8
9
|
import { readLedgerSettled, SharedLedgerTable } from "./shared-ledger.js";
|
|
9
10
|
import { guardCorruptSink } from "./corrupt-read-sink.js";
|
|
11
|
+
const FILE_CHECKPOINT_STORE_OPTION_KEYS = optionKeys()({ onCorruptRead: 0, fsync: 0, compactEvery: 0, sessionHeadOf: 0, holderIsCurrent: 0 });
|
|
10
12
|
export const CHECKPOINT_LEDGER_EVENT_KINDS = Object.freeze(["put", "resolve", "reopen", "execution", "expire", "delete", "steer_append"]);
|
|
11
13
|
const KNOWN_CHECKPOINT_LEDGER_EVENTS = new Set(CHECKPOINT_LEDGER_EVENT_KINDS);
|
|
12
14
|
function applyCheckpointEvent(cps, ev) {
|
|
@@ -25,9 +27,9 @@ function applyCheckpointEvent(cps, ev) {
|
|
|
25
27
|
case "resolve":
|
|
26
28
|
cp.status = "resolved";
|
|
27
29
|
cp.rev = ev.rev;
|
|
28
|
-
if (ev
|
|
30
|
+
if (memberPresent(ev, "resolvedOutcome"))
|
|
29
31
|
cp.resolvedOutcome = ev.resolvedOutcome;
|
|
30
|
-
cp.reopenReason
|
|
32
|
+
delete cp.reopenReason;
|
|
31
33
|
break;
|
|
32
34
|
case "reopen":
|
|
33
35
|
cp.status = "pending";
|
|
@@ -101,17 +103,19 @@ export class FileCheckpointStore {
|
|
|
101
103
|
get cps() {
|
|
102
104
|
return this.ledger.rows;
|
|
103
105
|
}
|
|
106
|
+
rowVerdicts = new WeakMap();
|
|
104
107
|
fault = null;
|
|
105
108
|
discloseCorrupt;
|
|
106
109
|
ledgerPath;
|
|
107
110
|
constructor(root, options) {
|
|
108
|
-
const opts = receiveOptions(options, "FileCheckpointStore");
|
|
111
|
+
const opts = receiveOptions(options, "FileCheckpointStore", FILE_CHECKPOINT_STORE_OPTION_KEYS);
|
|
109
112
|
assertAdoptionBootGate(root, "FileCheckpointStore");
|
|
110
|
-
|
|
113
|
+
const tuning = readLedgerTuning(opts, "FileCheckpointStore", "FileCheckpointStore options");
|
|
114
|
+
this.fsyncEnabled = tuning.fsync;
|
|
111
115
|
this.holderIsCurrent = opts.holderIsCurrent;
|
|
112
116
|
if (opts.holderIsCurrent !== undefined)
|
|
113
117
|
this.fence = Object.freeze({ holder: true });
|
|
114
|
-
this.compactEvery =
|
|
118
|
+
this.compactEvery = tuning.compactEvery;
|
|
115
119
|
this.discloseCorrupt = guardCorruptSink(opts.onCorruptRead);
|
|
116
120
|
const dir = join(root, "checkpoints");
|
|
117
121
|
this.ledgerPath = join(dir, "checkpoints.jsonl");
|
|
@@ -252,7 +256,7 @@ export class FileCheckpointStore {
|
|
|
252
256
|
const out = [];
|
|
253
257
|
for (const cp of this.cps.values()) {
|
|
254
258
|
if (cp.scope === scope && cp.status === "pending")
|
|
255
|
-
out.push(
|
|
259
|
+
out.push(summarizeStoredCheckpoint(cp, this.rowVerdicts, disclose));
|
|
256
260
|
}
|
|
257
261
|
return out;
|
|
258
262
|
}
|
|
@@ -269,7 +273,7 @@ export class FileCheckpointStore {
|
|
|
269
273
|
}
|
|
270
274
|
async listOverdue(query) {
|
|
271
275
|
const disclose = this.listingDisclose();
|
|
272
|
-
return selectOverduePage(this.cps.entries(), readCheckpointOverdueQuery(query), (cp) =>
|
|
276
|
+
return selectOverduePage(this.cps.entries(), readCheckpointOverdueQuery(query), (cp) => summarizeStoredCheckpoint(cp, this.rowVerdicts, disclose), disclose);
|
|
273
277
|
}
|
|
274
278
|
async listBySession(query) {
|
|
275
279
|
return selectSessionPage(this.cps.entries(), readCheckpointSessionQuery(query), (cp) => structuredClone(cp), this.listingDisclose());
|
|
@@ -8,7 +8,8 @@ import { atomicWriteFile, ensureDir, sanitizePathComponent, sanitizeScope, write
|
|
|
8
8
|
import { guardCorruptSink } from "./corrupt-read-sink.js";
|
|
9
9
|
import { isAbsoluteForFamily } from "../../tools/fs/safety.js";
|
|
10
10
|
import { assertAdoptionBootGate } from "./adoption/marker.js";
|
|
11
|
-
import { receiveOptions } from "../../core/own-property-receipt.js";
|
|
11
|
+
import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
|
|
12
|
+
const FILE_FILE_HISTORY_STORE_OPTION_KEYS = optionKeys()({ onCorruptRead: 0, retention: 0 });
|
|
12
13
|
function trackedDigest(rows) {
|
|
13
14
|
const canonical = [...rows]
|
|
14
15
|
.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0))
|
|
@@ -157,7 +158,7 @@ export class FileFileHistoryStore {
|
|
|
157
158
|
return this.lastCommittedAt;
|
|
158
159
|
}
|
|
159
160
|
constructor(root, options) {
|
|
160
|
-
const opts = receiveOptions(options, "FileFileHistoryStore");
|
|
161
|
+
const opts = receiveOptions(options, "FileFileHistoryStore", FILE_FILE_HISTORY_STORE_OPTION_KEYS);
|
|
161
162
|
assertAdoptionBootGate(root, "FileFileHistoryStore");
|
|
162
163
|
this.boundaryKeep = resolveFileHistoryRetention("FileFileHistoryStore", opts?.retention);
|
|
163
164
|
this.base = join(root, "file-history");
|
|
@@ -374,28 +374,6 @@ export declare function acquireStoreDirLock(dir: string, opts: {
|
|
|
374
374
|
label: string;
|
|
375
375
|
fileName?: string;
|
|
376
376
|
}): StoreDirLockLease;
|
|
377
|
-
/**
|
|
378
|
-
* design/84 Seam B (TOC profile) — a per-scope CONSOLIDATION lock factory for the file backend's
|
|
379
|
-
* {@link import("../../core/consolidate-scope.js").ConsolidateScopeDeps.acquire} injection point. A single
|
|
380
|
-
* machine may run a periodic-consolidation timer AND a task-end inline pass concurrently; this advisory lock
|
|
381
|
-
* stops two processes consolidating the SAME scope at once (the in-process model the file backend assumes —
|
|
382
|
-
* see {@link BootLock} — does not cover a second OS process with its own timer).
|
|
383
|
-
*
|
|
384
|
-
* `acquire(scope)` takes a {@link BootLock} over `lockDir/<sanitizedScope>.consolidate.lock`. It returns a
|
|
385
|
-
* `release` callback on success, or `undefined` for EVERY refusal that lock knows how to make — a live
|
|
386
|
-
* owner (including this process: a second pass here is still a conflict), a takeover in flight, an
|
|
387
|
-
* unreadable file — because the caller's whole vocabulary is "busy → skip this pass", a no-op that costs
|
|
388
|
-
* one deferred consolidation. A stale lock is reclaimed by the same protocol as any other, which is the
|
|
389
|
-
* point of not hand-rolling one: this factory used to prune with a bare `unlink` and re-publish, and two
|
|
390
|
-
* passes that had both read the same dead owner would then both prune and both publish — one deleting the
|
|
391
|
-
* other's fresh lock, leaving two processes consolidating the SAME scope, which is exactly what the lock
|
|
392
|
-
* exists to prevent. The reclaim gate serialises that, the depth cap bounds it, and the identity re-read
|
|
393
|
-
* makes sure a reclaim prunes the owner it came for. One lock MECHANISM in this family, not two.
|
|
394
|
-
*
|
|
395
|
-
* The implementation lives HERE (the deployment shell's persist/exec axis), NOT core — core only DEFINES
|
|
396
|
-
* the injection point (the constitutional split: gate-presence in core, mechanism in the profile).
|
|
397
|
-
*/
|
|
398
|
-
export declare function createFileConsolidationLock(lockDir: string): (scope: string) => (() => void) | undefined;
|
|
399
377
|
/**
|
|
400
378
|
* A process identity that survives PID REUSE: a pid, WHEN that pid's process started, and the host the
|
|
401
379
|
* observation was made on.
|
|
@@ -717,23 +717,6 @@ export function acquireStoreDirLock(dir, opts) {
|
|
|
717
717
|
heldStoreDirLocks.set(key, entry);
|
|
718
718
|
return lease(entry);
|
|
719
719
|
}
|
|
720
|
-
export function createFileConsolidationLock(lockDir) {
|
|
721
|
-
return (scope) => {
|
|
722
|
-
ensureDir(lockDir);
|
|
723
|
-
const lock = new BootLock(join(lockDir, `${sanitizeScope(scope)}.consolidate.lock`));
|
|
724
|
-
try {
|
|
725
|
-
lock.acquire();
|
|
726
|
-
}
|
|
727
|
-
catch (err) {
|
|
728
|
-
if (err instanceof FileStoreLockError)
|
|
729
|
-
return undefined;
|
|
730
|
-
throw err;
|
|
731
|
-
}
|
|
732
|
-
return () => {
|
|
733
|
-
lock.release();
|
|
734
|
-
};
|
|
735
|
-
};
|
|
736
|
-
}
|
|
737
720
|
function isProcessRunning(pid) {
|
|
738
721
|
try {
|
|
739
722
|
process.kill(pid, 0);
|
|
@@ -11,7 +11,7 @@ import type { FileHistoryStore } from "../../core/file-history-store.js";
|
|
|
11
11
|
import type { BackgroundAgentStore } from "../../core/background-agent-store.js";
|
|
12
12
|
import type { MailboxStore } from "../../core/mailbox-store.js";
|
|
13
13
|
import type { RosterStore } from "../../agents/roster-store.js";
|
|
14
|
-
import type
|
|
14
|
+
import { type SessionPolicyStore } from "../../core/session-policy-store.js";
|
|
15
15
|
import type { WorkflowJournalStore } from "../../core/workflow-journal-store.js";
|
|
16
16
|
import type { UsageWindowStore } from "../../core/usage-window-store.js";
|
|
17
17
|
import type { EngineStorageBackend } from "../../core/engine-storage-backend.js";
|
|
@@ -24,7 +24,7 @@ export { FileFileHistoryStore, type FileFileHistoryStoreOptions } from "./file-h
|
|
|
24
24
|
export { FileWorkflowJournalStore } from "./workflow-journal-store.js";
|
|
25
25
|
export { MAX_JOURNAL_RESULT_BYTES, oversizeJournalResult } from "../../core/workflow-journal-store.js";
|
|
26
26
|
export { FileUsageWindowStore, type FileUsageWindowStoreOptions } from "./usage-window-store.js";
|
|
27
|
-
export { resolveDataRoot, sanitizeScope, sanitizePathComponent
|
|
27
|
+
export { resolveDataRoot, sanitizeScope, sanitizePathComponent } from "./fs-atomic.js";
|
|
28
28
|
export { FileStoreLockError, type FileStoreLockErrorCode } from "./fs-atomic.js";
|
|
29
29
|
export { atomicWriteFile, writeThenLink, ensureDir, readJsonlRecords, AppendLog } from "./fs-atomic.js";
|
|
30
30
|
export { processFingerprint, isProcessLive, type ProcessFingerprint } from "./fs-atomic.js";
|
|
@@ -34,7 +34,7 @@ export { adoptLocalDataRoot, ackAdoptionConfig, witnessAdoptionConfig, listAdopt
|
|
|
34
34
|
* design/80 — the file-backed {@link EngineStorageBackend} for the local (TOC) single-user binary, selected
|
|
35
35
|
* purely by what the embedder injects into `RunnerDeps` (no engine change). Construct one over a single data
|
|
36
36
|
* root and pass its members into the `RunnerDeps` seats of the same names (every member of the contract is
|
|
37
|
-
* one; the class's extra members — `root`, `memoryStore
|
|
37
|
+
* one; the class's extra members — `root`, `memoryStore` — are not seats):
|
|
38
38
|
*
|
|
39
39
|
* ```ts
|
|
40
40
|
* const backend = new FileStorageBackend(); // ~/.ai-agent (or $AGENT_DATA_DIR)
|
|
@@ -67,8 +67,10 @@ export interface FileStorageBackendOptions {
|
|
|
67
67
|
/** `TtlSessionStore` idle-eviction policy. Default `"forget"` (§7 decision 5 — durable history is never
|
|
68
68
|
* deleted by an idle timer). */
|
|
69
69
|
evict?: EvictPolicy;
|
|
70
|
-
/** Checkpoint store tuning (fsync cadence for `put`/`setPendingSteer`, ledger compaction threshold).
|
|
71
|
-
|
|
70
|
+
/** Checkpoint store tuning (fsync cadence for `put`/`setPendingSteer`, ledger compaction threshold, the holder judge). The
|
|
71
|
+
* corrupt-read sink and the session head read are the backend's own — the sink is {@link FileStorageBackendOptions.onCorruptRead}
|
|
72
|
+
* (one failure grammar, one sink) and the head read is its session store's — so neither is accepted here. */
|
|
73
|
+
checkpoint?: Omit<FileCheckpointStoreOptions, "onCorruptRead" | "sessionHeadOf">;
|
|
72
74
|
/**
|
|
73
75
|
* design/381 §片2 — file-history tuning, today just the boundary RETENTION bound (omitted ⇒ the
|
|
74
76
|
* engine default; `{ retention: { keep: "unbounded" } }` hands the GC schedule to the deployment).
|
|
@@ -168,13 +170,6 @@ export declare class FileStorageBackend implements EngineStorageBackend {
|
|
|
168
170
|
* never edited are structurally out of reach of a restore.
|
|
169
171
|
*/
|
|
170
172
|
readonly fileHistoryStore: FileHistoryStore;
|
|
171
|
-
/**
|
|
172
|
-
* design/84 Seam B (TOC) — the per-scope consolidation lock for `consolidateScope`'s `acquire` injection
|
|
173
|
-
* point: `consolidateScope(scope, { store: backend.memoryStore, llm, acquire: backend.consolidationLock })`.
|
|
174
|
-
* Stops two OS processes sharing this data dir from consolidating the SAME scope at once (a busy scope ⇒
|
|
175
|
-
* `undefined` ⇒ the pass is a no-op). The locks live under `root/consolidation-locks/`.
|
|
176
|
-
*/
|
|
177
|
-
readonly consolidationLock: (scope: string) => (() => void) | undefined;
|
|
178
173
|
private readonly lock;
|
|
179
174
|
private readonly fileAgentRows;
|
|
180
175
|
private readonly fileMailbox;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { guardedMemoryStore } from "../../core/memory.js";
|
|
3
|
-
import { TtlSessionStore } from "../../core/session-store.js";
|
|
4
|
-
import { BootLock,
|
|
3
|
+
import { STORE_HOOK_KEYS, TtlSessionStore } from "../../core/session-store.js";
|
|
4
|
+
import { BootLock, resolveDataRoot } from "./fs-atomic.js";
|
|
5
5
|
import { assertAdoptionBootGate } from "./adoption/marker.js";
|
|
6
6
|
import { FileCheckpointStore } from "./checkpoint-store.js";
|
|
7
|
+
import { readLedgerTuning } from "./ledger-tuning.js";
|
|
7
8
|
import { FileMemoryStore } from "./memory-store.js";
|
|
8
9
|
import { FileSessionRepo } from "./session-store.js";
|
|
9
10
|
import { FileToolResultStore } from "./tool-result-store.js";
|
|
@@ -14,9 +15,11 @@ import { FileBackgroundAgentStore } from "./background-agent-store.js";
|
|
|
14
15
|
import { FileMailboxStore } from "./mailbox-store.js";
|
|
15
16
|
import { FileRosterStore } from "../../agents/roster-store.js";
|
|
16
17
|
import { FileFileHistoryStore } from "./file-history-store.js";
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
import { readMountedToolNames } from "../../core/session-policy-store.js";
|
|
19
|
+
import { optionKeys, receiveMembers, receiveOptions, refuseProxy, refuseStrayMembers } from "../../core/own-property-receipt.js";
|
|
20
|
+
import { receiveFileHistoryRetention } from "../../core/file-history-retention.js";
|
|
21
|
+
function nestedOptions(value, member, keys) {
|
|
22
|
+
return value === undefined ? undefined : receiveMembers(value, { subject: `FileStorageBackendOptions.${member}`, unit: "option", moment: "at new FileStorageBackend" }, keys);
|
|
20
23
|
}
|
|
21
24
|
export { FileCheckpointStore, CHECKPOINT_LEDGER_EVENT_KINDS, readCheckpointLedger, } from "./checkpoint-store.js";
|
|
22
25
|
export { FileMemoryStore } from "./memory-store.js";
|
|
@@ -27,12 +30,16 @@ export { FileFileHistoryStore } from "./file-history-store.js";
|
|
|
27
30
|
export { FileWorkflowJournalStore } from "./workflow-journal-store.js";
|
|
28
31
|
export { MAX_JOURNAL_RESULT_BYTES, oversizeJournalResult } from "../../core/workflow-journal-store.js";
|
|
29
32
|
export { FileUsageWindowStore } from "./usage-window-store.js";
|
|
30
|
-
export { resolveDataRoot, sanitizeScope, sanitizePathComponent
|
|
33
|
+
export { resolveDataRoot, sanitizeScope, sanitizePathComponent } from "./fs-atomic.js";
|
|
31
34
|
export { FileStoreLockError } from "./fs-atomic.js";
|
|
32
35
|
export { atomicWriteFile, writeThenLink, ensureDir, readJsonlRecords, AppendLog } from "./fs-atomic.js";
|
|
33
36
|
export { processFingerprint, isProcessLive } from "./fs-atomic.js";
|
|
34
37
|
export { AdoptionError, assertAdoptionBootGate, readRootAdoptionFile, writeRootAdoptionFile, ROOT_ADOPTION_FILE, } from "./adoption/marker.js";
|
|
35
38
|
export { adoptLocalDataRoot, ackAdoptionConfig, witnessAdoptionConfig, listAdoptionQuarantine, readAdoptionStatus, } from "./adoption/adopt.js";
|
|
39
|
+
const FILE_STORAGE_BACKEND_OPTION_KEYS = optionKeys()({ root: 0, utilityGate: 0, evict: 0, checkpoint: 0, fileHistory: 0, sessionPolicy: 0, embedder: 0, onCorruptRead: 0, sessions: 0 });
|
|
40
|
+
const NESTED_FILE_HISTORY_OPTION_KEYS = optionKeys()({ retention: 0 });
|
|
41
|
+
const NESTED_SESSION_POLICY_OPTION_KEYS = optionKeys()({ mountedToolNames: 0 });
|
|
42
|
+
const NESTED_CHECKPOINT_OPTION_KEYS = optionKeys()({ fsync: 0, compactEvery: 0, holderIsCurrent: 0 });
|
|
36
43
|
export class FileStorageBackend {
|
|
37
44
|
root;
|
|
38
45
|
sessionStore;
|
|
@@ -46,7 +53,6 @@ export class FileStorageBackend {
|
|
|
46
53
|
mailboxStore;
|
|
47
54
|
rosterStore;
|
|
48
55
|
fileHistoryStore;
|
|
49
|
-
consolidationLock;
|
|
50
56
|
lock;
|
|
51
57
|
fileAgentRows;
|
|
52
58
|
fileMailbox;
|
|
@@ -62,7 +68,15 @@ export class FileStorageBackend {
|
|
|
62
68
|
throw Object.assign(new Error(`FileStorageBackend runs no retention executor, so its options take no \`retention\` word: its stores declare "none".`), { code: "config.retention_capability" });
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
|
-
const opts = receiveOptions(options, "FileStorageBackend");
|
|
71
|
+
const opts = receiveOptions(options, "FileStorageBackend", FILE_STORAGE_BACKEND_OPTION_KEYS);
|
|
72
|
+
const checkpointRecord = nestedOptions(opts.checkpoint, "checkpoint", NESTED_CHECKPOINT_OPTION_KEYS);
|
|
73
|
+
const checkpointOptions = checkpointRecord === undefined ? undefined : { ...checkpointRecord, ...readLedgerTuning(checkpointRecord, "FileCheckpointStore", "FileStorageBackendOptions.checkpoint") };
|
|
74
|
+
const sessionPolicyRecord = nestedOptions(opts.sessionPolicy, "sessionPolicy", NESTED_SESSION_POLICY_OPTION_KEYS);
|
|
75
|
+
const sessionPolicyOptions = sessionPolicyRecord?.mountedToolNames === undefined ? sessionPolicyRecord : { ...sessionPolicyRecord, mountedToolNames: readMountedToolNames(sessionPolicyRecord.mountedToolNames) };
|
|
76
|
+
const fileHistoryRecord = nestedOptions(opts.fileHistory, "fileHistory", NESTED_FILE_HISTORY_OPTION_KEYS);
|
|
77
|
+
const fileHistoryOptions = fileHistoryRecord === undefined ? undefined : { ...fileHistoryRecord, retention: receiveFileHistoryRetention("FileStorageBackendOptions.fileHistory", fileHistoryRecord.retention) };
|
|
78
|
+
if (opts.sessions !== undefined)
|
|
79
|
+
refuseStrayMembers(opts.sessions, { subject: "FileStorageBackendOptions.sessions", unit: "hook", moment: "at new FileStorageBackend" }, STORE_HOOK_KEYS);
|
|
66
80
|
this.root = resolveDataRoot(opts.root);
|
|
67
81
|
assertAdoptionBootGate(this.root, "FileStorageBackend");
|
|
68
82
|
this.lock = new BootLock(join(this.root, "LOCK"));
|
|
@@ -75,14 +89,14 @@ export class FileStorageBackend {
|
|
|
75
89
|
this.ttl = new TtlSessionStore({ repo, evict: opts.evict ?? "forget", durability: "durable", placements: { subagent: { durability: "durable" } }, ...(opts.sessions !== undefined ? { hooks: opts.sessions } : {}) });
|
|
76
90
|
this.sessionStore = this.ttl;
|
|
77
91
|
const sessionHeadOf = this.ttl.headOf;
|
|
78
|
-
this.fileCheckpoints = new FileCheckpointStore(this.root, { ...
|
|
92
|
+
this.fileCheckpoints = new FileCheckpointStore(this.root, { ...checkpointOptions, ...corruptRead, ...(sessionHeadOf !== undefined ? { sessionHeadOf } : {}) });
|
|
79
93
|
built.push(() => this.fileCheckpoints.close());
|
|
80
94
|
this.checkpointStore = this.fileCheckpoints;
|
|
81
95
|
this.fileMemory = new FileMemoryStore(this.root, opts.embedder ? { embedder: opts.embedder } : {});
|
|
82
96
|
built.push(() => this.fileMemory.close());
|
|
83
97
|
this.memoryStore = guardedMemoryStore(this.fileMemory, opts.utilityGate);
|
|
84
98
|
this.toolResultStore = new FileToolResultStore(this.root, corruptRead);
|
|
85
|
-
this.sessionPolicyStore = new FileSessionPolicyStore(this.root, { ...
|
|
99
|
+
this.sessionPolicyStore = new FileSessionPolicyStore(this.root, { ...sessionPolicyOptions, ...corruptRead });
|
|
86
100
|
this.fileWorkflowJournal = new FileWorkflowJournalStore(this.root, true, corruptRead);
|
|
87
101
|
built.push(() => this.fileWorkflowJournal.dispose());
|
|
88
102
|
this.workflowJournalStore = this.fileWorkflowJournal;
|
|
@@ -94,8 +108,7 @@ export class FileStorageBackend {
|
|
|
94
108
|
built.push(() => this.fileMailbox.close());
|
|
95
109
|
this.mailboxStore = this.fileMailbox;
|
|
96
110
|
this.rosterStore = new FileRosterStore(join(this.root, "roster.json"), corruptRead ?? {});
|
|
97
|
-
this.fileHistoryStore = new FileFileHistoryStore(this.root, { ...
|
|
98
|
-
this.consolidationLock = createFileConsolidationLock(join(this.root, "consolidation-locks"));
|
|
111
|
+
this.fileHistoryStore = new FileFileHistoryStore(this.root, { ...fileHistoryOptions, ...(corruptRead ?? {}) });
|
|
99
112
|
}
|
|
100
113
|
catch (err) {
|
|
101
114
|
for (const undo of built.reverse()) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Each store's compaction threshold when none is given. */
|
|
2
|
+
export declare const LEDGER_COMPACT_EVERY_DEFAULTS: Readonly<{
|
|
3
|
+
FileCheckpointStore: 1000;
|
|
4
|
+
FileMailboxStore: 500;
|
|
5
|
+
FileBackgroundAgentStore: 1000;
|
|
6
|
+
FileWorkflowRunStore: 1000;
|
|
7
|
+
}>;
|
|
8
|
+
/** A store that takes ledger tuning. */
|
|
9
|
+
export type LedgerTunedStore = keyof typeof LEDGER_COMPACT_EVERY_DEFAULTS;
|
|
10
|
+
/** A store's ledger tuning, read: every member present. */
|
|
11
|
+
export interface LedgerTuning {
|
|
12
|
+
readonly fsync: boolean;
|
|
13
|
+
readonly compactEvery: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Read a store's ledger tuning off an options record already received (the store door's copy, or a backend's nested record's):
|
|
17
|
+
* the values judged, the absent ones the store's defaults. `subject` names the record in a refusal (`FileMailboxStore options`,
|
|
18
|
+
* `FileStorageBackendOptions.checkpoint`).
|
|
19
|
+
*/
|
|
20
|
+
export declare function readLedgerTuning(given: {
|
|
21
|
+
readonly fsync?: unknown;
|
|
22
|
+
readonly compactEvery?: unknown;
|
|
23
|
+
}, store: LedgerTunedStore, subject: string): LedgerTuning;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { receiptRefusal } from "../../core/own-property-receipt.js";
|
|
2
|
+
export const LEDGER_COMPACT_EVERY_DEFAULTS = Object.freeze({
|
|
3
|
+
FileCheckpointStore: 1000,
|
|
4
|
+
FileMailboxStore: 500,
|
|
5
|
+
FileBackgroundAgentStore: 1000,
|
|
6
|
+
FileWorkflowRunStore: 1000,
|
|
7
|
+
});
|
|
8
|
+
function shown(value) {
|
|
9
|
+
return typeof value === "number" ? String(value) : value === null ? "null" : Array.isArray(value) ? "an array" : typeof value;
|
|
10
|
+
}
|
|
11
|
+
export function readLedgerTuning(given, store, subject) {
|
|
12
|
+
const fsync = given.fsync;
|
|
13
|
+
if (fsync !== undefined && typeof fsync !== "boolean") {
|
|
14
|
+
throw receiptRefusal(`${subject}.fsync must be a boolean when given (got ${shown(fsync)}) — refused rather than read as on`);
|
|
15
|
+
}
|
|
16
|
+
const compactEvery = given.compactEvery;
|
|
17
|
+
if (compactEvery !== undefined && !(typeof compactEvery === "number" && Number.isSafeInteger(compactEvery) && compactEvery >= 1)) {
|
|
18
|
+
throw receiptRefusal(`${subject}.compactEvery must be a whole number of events of at least 1 when given (got ${shown(compactEvery)}) — refused rather than kept: such a threshold is never reached (the ledger grows without compacting) or reached at every event (a rewrite per write)`);
|
|
19
|
+
}
|
|
20
|
+
return Object.freeze({ fsync: fsync !== false, compactEvery: compactEvery ?? LEDGER_COMPACT_EVERY_DEFAULTS[store] });
|
|
21
|
+
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { join, resolve, sep } from "node:path";
|
|
2
2
|
import { createHash, randomBytes } from "node:crypto";
|
|
3
|
-
import {
|
|
3
|
+
import { receiveRetentionPolicy } from "../../core/retention-policy.js";
|
|
4
4
|
import { existsSync, linkSync, readdirSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { assertMailboxDecisionMove, detachMailboxMessage, newestSentAt, readStoredMailboxDecision, readMailboxAppend, judgeMailboxAppendById, } from "../../core/mailbox-store.js";
|
|
5
|
+
import { assertMailboxDecisionMove, detachMailboxMessage, foldMailboxConsumed, MAILBOX_REAP_KNOBS, MAILBOX_REPLAY_FACETS, newestSentAt, readStoredMailboxDecision, readMailboxAppend, judgeMailboxAppendById, } 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";
|
|
9
9
|
import { assertAdoptionBootGate } from "./adoption/marker.js";
|
|
10
|
-
import { receiveOptions } from "../../core/own-property-receipt.js";
|
|
10
|
+
import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
|
|
11
|
+
import { readLedgerTuning } from "./ledger-tuning.js";
|
|
11
12
|
function diskMarkOf(path) {
|
|
12
13
|
try {
|
|
13
14
|
const st = statSync(path);
|
|
@@ -323,6 +324,7 @@ function sweepLockResidue(dir, lockName) {
|
|
|
323
324
|
}
|
|
324
325
|
}
|
|
325
326
|
}
|
|
327
|
+
const FILE_MAILBOX_STORE_OPTION_KEYS = optionKeys()({ fsync: 0, lockWaitMs: 0, compactEvery: 0, onCorruptRead: 0 });
|
|
326
328
|
export class FileMailboxStore {
|
|
327
329
|
crossProcessSafe = true;
|
|
328
330
|
identity;
|
|
@@ -334,10 +336,11 @@ export class FileMailboxStore {
|
|
|
334
336
|
touched = new Map();
|
|
335
337
|
discloseCorrupt;
|
|
336
338
|
constructor(root, options) {
|
|
337
|
-
const opts = receiveOptions(options, "FileMailboxStore");
|
|
339
|
+
const opts = receiveOptions(options, "FileMailboxStore", FILE_MAILBOX_STORE_OPTION_KEYS);
|
|
338
340
|
assertAdoptionBootGate(root, "FileMailboxStore");
|
|
339
|
-
|
|
340
|
-
this.
|
|
341
|
+
const tuning = readLedgerTuning(opts, "FileMailboxStore", "FileMailboxStore options");
|
|
342
|
+
this.fsyncEnabled = tuning.fsync;
|
|
343
|
+
this.compactEvery = tuning.compactEvery;
|
|
341
344
|
const lockWaitMs = opts.lockWaitMs ?? 10_000;
|
|
342
345
|
if (typeof lockWaitMs !== "number" || !Number.isFinite(lockWaitMs) || lockWaitMs <= 0) {
|
|
343
346
|
throw new Error(`FileMailboxStore: lockWaitMs must be a finite number > 0, got ${JSON.stringify(opts.lockWaitMs)}`);
|
|
@@ -386,10 +389,11 @@ export class FileMailboxStore {
|
|
|
386
389
|
const events = readJsonlRecords(b.path, this.discloseCorrupt, MAILBOX_EVENT_JUDGE);
|
|
387
390
|
b.messages = [];
|
|
388
391
|
b.nextSeq = 1;
|
|
392
|
+
b.consumed = [];
|
|
389
393
|
delete b.lease;
|
|
390
394
|
for (const ev of events)
|
|
391
395
|
applyEvent(b, ev);
|
|
392
|
-
b.events = Math.max(0, events.length - (b.messages.length + 1 + (b.lease !== undefined ? 1 : 0)));
|
|
396
|
+
b.events = Math.max(0, events.length - (b.messages.length + 1 + (b.consumed.length > 0 ? 1 : 0) + (b.lease !== undefined ? 1 : 0)));
|
|
393
397
|
b.mark = now;
|
|
394
398
|
}
|
|
395
399
|
load(scope, handle) {
|
|
@@ -406,7 +410,7 @@ export class FileMailboxStore {
|
|
|
406
410
|
}
|
|
407
411
|
ensureDir(join(this.dir, sanitizeScope(scope)));
|
|
408
412
|
const events = readJsonlRecords(path, this.discloseCorrupt, MAILBOX_EVENT_JUDGE);
|
|
409
|
-
const state = { messages: [], nextSeq: 1, log: new AppendLog(path), events: events.length, refs: 1, path, mark: undefined };
|
|
413
|
+
const state = { messages: [], nextSeq: 1, consumed: [], log: new AppendLog(path), events: events.length, refs: 1, path, mark: undefined };
|
|
410
414
|
for (const ev of events)
|
|
411
415
|
applyEvent(state, ev);
|
|
412
416
|
state.mark = diskMarkOf(path);
|
|
@@ -429,14 +433,8 @@ export class FileMailboxStore {
|
|
|
429
433
|
b.mark = markAfterWrite(path);
|
|
430
434
|
}
|
|
431
435
|
compact(b, path) {
|
|
432
|
-
const lines = [];
|
|
433
|
-
lines.push(JSON.stringify({ t: "lease", owner: "", expiresAt: 0, maxSeq: b.nextSeq - 1 }));
|
|
434
|
-
for (const m of b.messages)
|
|
435
|
-
lines.push(JSON.stringify({ t: "append", m }));
|
|
436
|
-
if (b.lease !== undefined)
|
|
437
|
-
lines.push(JSON.stringify({ t: "lease", ...b.lease }));
|
|
438
436
|
b.log.closeForSwap();
|
|
439
|
-
atomicWriteFile(this.tmpDir, path,
|
|
437
|
+
atomicWriteFile(this.tmpDir, path, snapshotOf(b));
|
|
440
438
|
b.events = 0;
|
|
441
439
|
b.mark = markAfterWrite(path);
|
|
442
440
|
}
|
|
@@ -446,7 +444,7 @@ export class FileMailboxStore {
|
|
|
446
444
|
const record = readMailboxAppend(msg);
|
|
447
445
|
return this.withBox(this.lockKey(scope, handle), this.boxPath(scope, handle), () => {
|
|
448
446
|
const b = this.load(scope, handle);
|
|
449
|
-
const held = judgeMailboxAppendById(b.messages, record);
|
|
447
|
+
const held = judgeMailboxAppendById({ held: b.messages, consumed: b.consumed }, record);
|
|
450
448
|
if (held !== undefined)
|
|
451
449
|
return held;
|
|
452
450
|
const seq = b.nextSeq;
|
|
@@ -505,7 +503,7 @@ export class FileMailboxStore {
|
|
|
505
503
|
if (!existsSync(path))
|
|
506
504
|
return 0;
|
|
507
505
|
return withPathLock(this.lockKey(scope, handle), () => {
|
|
508
|
-
const b = { messages: [], nextSeq: 1 };
|
|
506
|
+
const b = { messages: [], nextSeq: 1, consumed: [] };
|
|
509
507
|
for (const ev of readJsonlRecords(path, this.discloseCorrupt, MAILBOX_EVENT_JUDGE))
|
|
510
508
|
applyEvent(b, ev);
|
|
511
509
|
return b.messages.length;
|
|
@@ -525,14 +523,14 @@ export class FileMailboxStore {
|
|
|
525
523
|
});
|
|
526
524
|
}
|
|
527
525
|
async reap(scope, now, opts) {
|
|
528
|
-
|
|
526
|
+
const policy = receiveRetentionPolicy("MailboxStore.reap", opts, MAILBOX_REAP_KNOBS);
|
|
529
527
|
sweepLockResidue(join(this.dir, sanitizeScope(scope)));
|
|
530
|
-
if (
|
|
528
|
+
if (policy.maxAgeMs === undefined)
|
|
531
529
|
return 0;
|
|
532
530
|
let dropped = 0;
|
|
533
531
|
const scopeDir = join(this.dir, sanitizeScope(scope));
|
|
534
532
|
const prefix = scopeDir + sep;
|
|
535
|
-
const maxAgeMs =
|
|
533
|
+
const maxAgeMs = policy.maxAgeMs;
|
|
536
534
|
for (const [key, b] of [...sharedBoxes]) {
|
|
537
535
|
if (!b.path.startsWith(prefix))
|
|
538
536
|
continue;
|
|
@@ -565,13 +563,13 @@ export class FileMailboxStore {
|
|
|
565
563
|
const swept = await this.withBox(key, path, () => {
|
|
566
564
|
if (sharedBoxes.has(key))
|
|
567
565
|
return false;
|
|
568
|
-
const b = { messages: [], nextSeq: 1 };
|
|
566
|
+
const b = { messages: [], nextSeq: 1, consumed: [] };
|
|
569
567
|
for (const ev of readJsonlRecords(path, this.discloseCorrupt, MAILBOX_EVENT_JUDGE))
|
|
570
568
|
applyEvent(b, ev);
|
|
571
569
|
const newest = newestSentAt(b.messages);
|
|
572
570
|
if (newest === undefined || newest >= now - maxAgeMs)
|
|
573
571
|
return false;
|
|
574
|
-
atomicWriteFile(this.tmpDir, path,
|
|
572
|
+
atomicWriteFile(this.tmpDir, path, snapshotOf({ messages: [], nextSeq: b.nextSeq, consumed: b.consumed }));
|
|
575
573
|
return true;
|
|
576
574
|
});
|
|
577
575
|
if (swept)
|
|
@@ -594,6 +592,22 @@ export class FileMailboxStore {
|
|
|
594
592
|
}
|
|
595
593
|
}
|
|
596
594
|
const num = (v) => typeof v === "number" && Number.isFinite(v);
|
|
595
|
+
function isConsumedRecord(v) {
|
|
596
|
+
if (v === null || typeof v !== "object")
|
|
597
|
+
return false;
|
|
598
|
+
const { id, seq, digests } = v;
|
|
599
|
+
return typeof id === "string" && id !== "" && num(seq) && digests !== null && typeof digests === "object" && MAILBOX_REPLAY_FACETS.every((f) => typeof digests[f] === "string");
|
|
600
|
+
}
|
|
601
|
+
function snapshotOf(b) {
|
|
602
|
+
const lines = [JSON.stringify({ t: "lease", owner: "", expiresAt: 0, maxSeq: b.nextSeq - 1 })];
|
|
603
|
+
if (b.consumed.length > 0)
|
|
604
|
+
lines.push(JSON.stringify({ t: "consumed", records: b.consumed }));
|
|
605
|
+
for (const m of b.messages)
|
|
606
|
+
lines.push(JSON.stringify({ t: "append", m }));
|
|
607
|
+
if (b.lease !== undefined)
|
|
608
|
+
lines.push(JSON.stringify({ t: "lease", ...b.lease }));
|
|
609
|
+
return `${lines.join("\n")}\n`;
|
|
610
|
+
}
|
|
597
611
|
const MAILBOX_EVENT_JUDGE = {
|
|
598
612
|
accepts: (r) => {
|
|
599
613
|
const ev = r;
|
|
@@ -605,6 +619,8 @@ const MAILBOX_EVENT_JUDGE = {
|
|
|
605
619
|
return num(ev.upToSeq);
|
|
606
620
|
if (ev.t === "decision")
|
|
607
621
|
return num(r.seq) && typeof r.state === "string";
|
|
622
|
+
if (ev.t === "consumed")
|
|
623
|
+
return Array.isArray(r.records) && r.records.every(isConsumedRecord);
|
|
608
624
|
return ev.t === "release" && typeof ev.owner === "string";
|
|
609
625
|
},
|
|
610
626
|
what: "a mailbox record is not one of this box's events — an unknown tag, or a known tag whose payload is missing",
|
|
@@ -627,10 +643,14 @@ function applyEvent(b, ev) {
|
|
|
627
643
|
b.lease = { owner: ev.owner, expiresAt: ev.expiresAt, maxSeq: ev.maxSeq };
|
|
628
644
|
}
|
|
629
645
|
else if (ev.t === "ack") {
|
|
646
|
+
b.consumed = foldMailboxConsumed(b.consumed, b.messages.filter((m) => m.seq <= ev.upToSeq));
|
|
630
647
|
b.messages = b.messages.filter((m) => m.seq > ev.upToSeq);
|
|
631
648
|
if (b.lease !== undefined && b.lease.maxSeq <= ev.upToSeq)
|
|
632
649
|
b.lease = undefined;
|
|
633
650
|
}
|
|
651
|
+
else if (ev.t === "consumed") {
|
|
652
|
+
b.consumed = foldMailboxConsumed(ev.records, []);
|
|
653
|
+
}
|
|
634
654
|
else if (ev.t === "decision") {
|
|
635
655
|
const m = b.messages.find((x) => x.seq === ev.seq);
|
|
636
656
|
if (m !== undefined)
|
|
@@ -4,9 +4,10 @@ import { firstSentence, lexicalSearchMatch, parseNoteTimestamp, MemoryProjection
|
|
|
4
4
|
import { cosineDistance, jaccardDistance, termSet } from "../../core/memory-vector.js";
|
|
5
5
|
import { canonicalStoreKey, AppendLog, atomicWriteFile, ensureDir, readJsonlRecords, sanitizeScope, } from "./fs-atomic.js";
|
|
6
6
|
import { assertAdoptionBootGate } from "./adoption/marker.js";
|
|
7
|
-
import { receiveOptions } from "../../core/own-property-receipt.js";
|
|
7
|
+
import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
|
|
8
8
|
const MAX_OPEN_MEMORY_SCOPES = 64;
|
|
9
9
|
const sharedMemoryDirs = new Map();
|
|
10
|
+
const FILE_MEMORY_STORE_OPTION_KEYS = optionKeys()({ embedder: 0, embedTimeoutMs: 0 });
|
|
10
11
|
export class FileMemoryStore {
|
|
11
12
|
root;
|
|
12
13
|
embedder;
|
|
@@ -19,7 +20,7 @@ export class FileMemoryStore {
|
|
|
19
20
|
scopeKey;
|
|
20
21
|
closed = false;
|
|
21
22
|
constructor(root, options) {
|
|
22
|
-
const opts = receiveOptions(options, "FileMemoryStore");
|
|
23
|
+
const opts = receiveOptions(options, "FileMemoryStore", FILE_MEMORY_STORE_OPTION_KEYS);
|
|
23
24
|
assertAdoptionBootGate(root, "FileMemoryStore");
|
|
24
25
|
this.root = join(root, "memory");
|
|
25
26
|
this.scopeKey = canonicalStoreKey(this.root);
|