@sema-agent/core 7.60.0 → 7.61.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 +605 -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 +61 -10
- package/dist/agents/cascade.js +60 -20
- 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-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 +36 -7
- 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 +30 -40
- package/dist/agents/subagent.js +187 -196
- package/dist/agents/suspend-guard.d.ts +9 -0
- package/dist/agents/suspend-guard.js +4 -0
- package/dist/agents/verify.d.ts +41 -14
- package/dist/agents/verify.js +37 -27
- 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-requirements.d.ts +24 -3
- package/dist/core/checkpoint-requirements.js +9 -1
- package/dist/core/checkpoint-store.d.ts +78 -19
- package/dist/core/checkpoint-store.js +8 -4
- 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 +49 -18
- 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 +2 -1
- 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 +12 -4
- package/dist/core/governance-codes.js +16 -4
- package/dist/core/hooks.d.ts +12 -4
- package/dist/core/hooks.js +11 -4
- package/dist/core/host-floor.js +3 -5
- package/dist/core/image-admission.d.ts +48 -8
- 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 +2 -1
- 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 +220 -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.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/mode-policy.d.ts +8 -8
- package/dist/core/mode-policy.js +7 -5
- package/dist/core/mods/agent-stations.d.ts +39 -4
- package/dist/core/mods/agent-stations.js +59 -10
- package/dist/core/mods/dollar.d.ts +62 -0
- 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 +4 -1
- package/dist/core/mods/kernel/events.js +6 -6
- 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/session-append.d.ts +115 -0
- package/dist/core/mods/session-append.js +311 -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 +141 -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 +38 -16
- package/dist/core/mods/stations.js +25 -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 +61 -2
- package/dist/core/own-property-receipt.js +42 -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/remote-env.d.ts +74 -26
- package/dist/core/remote-env.js +20 -0
- 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 +14 -2
- 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 +98 -26
- 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/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/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 +5 -1
- package/dist/core/runner/permission-rule-lanes.js +28 -9
- package/dist/core/runner/person-path-rows.js +1 -1
- package/dist/core/runner/placement-fence.d.ts +26 -0
- package/dist/core/runner/placement-fence.js +38 -0
- 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 +2 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +1 -0
- package/dist/core/runner/prepare-config-doors.js +16 -17
- 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 +5 -5
- package/dist/core/runner/prepare-hands-readface.js +4 -4
- package/dist/core/runner/prepare-inherited-gate.d.ts +6 -0
- package/dist/core/runner/prepare-inherited-gate.js +3 -0
- 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 +56 -28
- 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 +5 -3
- package/dist/core/runner/resume-admission.js +17 -3
- package/dist/core/runner/resume-apply.js +3 -1
- 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.js +2 -1
- package/dist/core/runner/run-harness-handlers.js +2 -2
- 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 +40 -29
- 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 +9 -7
- 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 +27 -14
- package/dist/core/runner/runtask.d.ts +18 -3
- package/dist/core/runner/runtask.js +27 -11
- 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/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 +8 -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-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 +3 -2
- package/dist/core/runner/turn-attachments.js +1 -1
- 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 +24 -25
- package/dist/core/secret-env.d.ts +11 -11
- package/dist/core/secret-env.js +8 -9
- 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 +2 -0
- package/dist/core/session-store.js +5 -7
- package/dist/core/session.d.ts +2 -1
- 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 +2 -2
- package/dist/core/store-contracts/checkpoint-store-contract.js +15 -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/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 +17 -8
- package/dist/core/task-limits.d.ts +5 -0
- package/dist/core/task-notification.d.ts +89 -12
- package/dist/core/task-notification.js +87 -13
- package/dist/core/task-registry-agent.d.ts +5 -43
- package/dist/core/task-registry-agent.js +24 -51
- 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 +15 -112
- package/dist/core/task-registry-shared.js +3 -41
- package/dist/core/task-registry-workflow.js +4 -21
- package/dist/core/task-registry.d.ts +19 -60
- package/dist/core/task-registry.js +19 -106
- package/dist/core/task-result.d.ts +24 -7
- 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 +10 -10
- 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 +30 -0
- 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 +2 -3
- 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 +108 -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-spec.d.ts +19 -6
- package/dist/core/trace.d.ts +18 -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 +34 -9
- package/dist/engine/execution-env/node-execution-env.js +213 -21
- 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 +41 -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/fixtures/index.d.ts +7 -5
- package/dist/fixtures/index.js +5 -3
- package/dist/index.d.ts +21 -11
- package/dist/index.js +15 -7
- package/dist/internal/harness-types.d.ts +2 -0
- 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 +11 -17
- package/dist/orchestration/run-workflow-tool.js +19 -42
- package/dist/orchestration/workflow-governance.d.ts +1 -1
- package/dist/orchestration/workflow-types.d.ts +2 -2
- package/dist/orchestration/workflow.d.ts +4 -0
- package/dist/orchestration/workflow.js +8 -5
- package/dist/stores/file/background-agent-store.js +18 -15
- package/dist/stores/file/checkpoint-store.js +7 -4
- package/dist/stores/file/file-history-store.js +3 -2
- package/dist/stores/file/index.d.ts +5 -3
- package/dist/stores/file/index.js +23 -8
- 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 +16 -3
- package/dist/stores/file/session-store.js +21 -20
- 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/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/search.d.ts +3 -2
- package/dist/tools/fs/search.js +6 -6
- package/dist/tools/fs/shell-read-establish.js +3 -1
- 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/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 +92 -10
- package/wire-changes/core-stores-sql@7.61.0.json +480 -0
- package/wire-changes/core@7.61.0.json +4405 -0
- package/wire-changes/mods-kernel@7.61.0.json +65 -0
- package/wire-changes/primitives@7.61.0.json +30 -0
- package/dist/core/runner/image-removed-seat.d.ts +0 -12
- package/dist/core/runner/image-removed-seat.js +0 -19
|
@@ -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";
|
|
3
|
+
import { STORE_HOOK_KEYS, TtlSessionStore } from "../../core/session-store.js";
|
|
4
4
|
import { BootLock, createFileConsolidationLock, 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";
|
|
@@ -33,6 +36,10 @@ export { atomicWriteFile, writeThenLink, ensureDir, readJsonlRecords, AppendLog
|
|
|
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;
|
|
@@ -62,7 +69,15 @@ export class FileStorageBackend {
|
|
|
62
69
|
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
70
|
}
|
|
64
71
|
}
|
|
65
|
-
const opts = receiveOptions(options, "FileStorageBackend");
|
|
72
|
+
const opts = receiveOptions(options, "FileStorageBackend", FILE_STORAGE_BACKEND_OPTION_KEYS);
|
|
73
|
+
const checkpointRecord = nestedOptions(opts.checkpoint, "checkpoint", NESTED_CHECKPOINT_OPTION_KEYS);
|
|
74
|
+
const checkpointOptions = checkpointRecord === undefined ? undefined : { ...checkpointRecord, ...readLedgerTuning(checkpointRecord, "FileCheckpointStore", "FileStorageBackendOptions.checkpoint") };
|
|
75
|
+
const sessionPolicyRecord = nestedOptions(opts.sessionPolicy, "sessionPolicy", NESTED_SESSION_POLICY_OPTION_KEYS);
|
|
76
|
+
const sessionPolicyOptions = sessionPolicyRecord?.mountedToolNames === undefined ? sessionPolicyRecord : { ...sessionPolicyRecord, mountedToolNames: readMountedToolNames(sessionPolicyRecord.mountedToolNames) };
|
|
77
|
+
const fileHistoryRecord = nestedOptions(opts.fileHistory, "fileHistory", NESTED_FILE_HISTORY_OPTION_KEYS);
|
|
78
|
+
const fileHistoryOptions = fileHistoryRecord === undefined ? undefined : { ...fileHistoryRecord, retention: receiveFileHistoryRetention("FileStorageBackendOptions.fileHistory", fileHistoryRecord.retention) };
|
|
79
|
+
if (opts.sessions !== undefined)
|
|
80
|
+
refuseStrayMembers(opts.sessions, { subject: "FileStorageBackendOptions.sessions", unit: "hook", moment: "at new FileStorageBackend" }, STORE_HOOK_KEYS);
|
|
66
81
|
this.root = resolveDataRoot(opts.root);
|
|
67
82
|
assertAdoptionBootGate(this.root, "FileStorageBackend");
|
|
68
83
|
this.lock = new BootLock(join(this.root, "LOCK"));
|
|
@@ -75,14 +90,14 @@ export class FileStorageBackend {
|
|
|
75
90
|
this.ttl = new TtlSessionStore({ repo, evict: opts.evict ?? "forget", durability: "durable", placements: { subagent: { durability: "durable" } }, ...(opts.sessions !== undefined ? { hooks: opts.sessions } : {}) });
|
|
76
91
|
this.sessionStore = this.ttl;
|
|
77
92
|
const sessionHeadOf = this.ttl.headOf;
|
|
78
|
-
this.fileCheckpoints = new FileCheckpointStore(this.root, { ...
|
|
93
|
+
this.fileCheckpoints = new FileCheckpointStore(this.root, { ...checkpointOptions, ...corruptRead, ...(sessionHeadOf !== undefined ? { sessionHeadOf } : {}) });
|
|
79
94
|
built.push(() => this.fileCheckpoints.close());
|
|
80
95
|
this.checkpointStore = this.fileCheckpoints;
|
|
81
96
|
this.fileMemory = new FileMemoryStore(this.root, opts.embedder ? { embedder: opts.embedder } : {});
|
|
82
97
|
built.push(() => this.fileMemory.close());
|
|
83
98
|
this.memoryStore = guardedMemoryStore(this.fileMemory, opts.utilityGate);
|
|
84
99
|
this.toolResultStore = new FileToolResultStore(this.root, corruptRead);
|
|
85
|
-
this.sessionPolicyStore = new FileSessionPolicyStore(this.root, { ...
|
|
100
|
+
this.sessionPolicyStore = new FileSessionPolicyStore(this.root, { ...sessionPolicyOptions, ...corruptRead });
|
|
86
101
|
this.fileWorkflowJournal = new FileWorkflowJournalStore(this.root, true, corruptRead);
|
|
87
102
|
built.push(() => this.fileWorkflowJournal.dispose());
|
|
88
103
|
this.workflowJournalStore = this.fileWorkflowJournal;
|
|
@@ -94,7 +109,7 @@ export class FileStorageBackend {
|
|
|
94
109
|
built.push(() => this.fileMailbox.close());
|
|
95
110
|
this.mailboxStore = this.fileMailbox;
|
|
96
111
|
this.rosterStore = new FileRosterStore(join(this.root, "roster.json"), corruptRead ?? {});
|
|
97
|
-
this.fileHistoryStore = new FileFileHistoryStore(this.root, { ...
|
|
112
|
+
this.fileHistoryStore = new FileFileHistoryStore(this.root, { ...fileHistoryOptions, ...(corruptRead ?? {}) });
|
|
98
113
|
this.consolidationLock = createFileConsolidationLock(join(this.root, "consolidation-locks"));
|
|
99
114
|
}
|
|
100
115
|
catch (err) {
|
|
@@ -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);
|
|
@@ -6,40 +6,43 @@ import { principalNameOf } from "../../core/principal-name.js";
|
|
|
6
6
|
import { createPermissionRuleStoreProvider } from "../../core/permission-rule-provider.js";
|
|
7
7
|
import { syncPermissionRules } from "../../core/permission-rule-sync.js";
|
|
8
8
|
import { thrownText } from "../../core/thrown-value.js";
|
|
9
|
+
import { optionKeys, receiveMembers } from "../../core/own-property-receipt.js";
|
|
9
10
|
import { FileStoreLockError } from "./fs-atomic.js";
|
|
10
11
|
import { FileDurableRulePartitionProvider, LOCAL_OWNER_FILE, principalRuleFileName, readRuleAdoptionFile, writeRuleAdoptionFile, } from "./permission-rule-store.js";
|
|
12
|
+
const ADOPT_OPTION_KEYS = optionKeys()({ dir: 0, from: 0, toPrincipal: 0, transport: 0, now: 0, onError: 0 });
|
|
11
13
|
export async function adoptFilePermissionRuleStore(opts) {
|
|
12
|
-
|
|
14
|
+
const o = receiveMembers(opts, { subject: "adoptFilePermissionRuleStore options", unit: "option", moment: "at adoptFilePermissionRuleStore" }, ADOPT_OPTION_KEYS);
|
|
15
|
+
if (principalNameOf(o.toPrincipal) === undefined) {
|
|
13
16
|
throw new Error("adoptFilePermissionRuleStore requires the adopting principal, a principal name — adoption is the act of giving this bucket an identity");
|
|
14
17
|
}
|
|
15
|
-
const from = readRuleOwner(
|
|
18
|
+
const from = readRuleOwner(o.from);
|
|
16
19
|
if (from === undefined) {
|
|
17
20
|
throw new Error("adoptFilePermissionRuleStore requires a source owner — a principal owner whose principal is a principal name, or the local owner");
|
|
18
21
|
}
|
|
19
|
-
if (from.kind === "principal" && from.principal ===
|
|
20
|
-
throw new Error(`the bucket already belongs to "${
|
|
22
|
+
if (from.kind === "principal" && from.principal === o.toPrincipal) {
|
|
23
|
+
throw new Error(`the bucket already belongs to "${o.toPrincipal}" — there is nothing to adopt`);
|
|
21
24
|
}
|
|
22
|
-
const sourceFile = join(
|
|
23
|
-
const targetFile = join(
|
|
24
|
-
const existing = readRuleAdoptionFile(
|
|
25
|
+
const sourceFile = join(o.dir, from.kind === "local-owner" ? LOCAL_OWNER_FILE : principalRuleFileName(from.principal));
|
|
26
|
+
const targetFile = join(o.dir, principalRuleFileName(o.toPrincipal));
|
|
27
|
+
const existing = readRuleAdoptionFile(o.dir);
|
|
25
28
|
if (existing !== undefined) {
|
|
26
29
|
if ("adopted" in existing) {
|
|
27
|
-
if (existing.adopted.toPrincipal ===
|
|
30
|
+
if (existing.adopted.toPrincipal === o.toPrincipal && sameRuleOwner(existing.adopted.from, from))
|
|
28
31
|
return { status: "adopted" };
|
|
29
32
|
throw new Error(`this directory already carries a completed adoption (${ruleOwnerText(existing.adopted.from)} → "${existing.adopted.toPrincipal}") — a second adoption of the same directory is not a shape this helper supports`);
|
|
30
33
|
}
|
|
31
|
-
if (existing.marker.toPrincipal !==
|
|
34
|
+
if (existing.marker.toPrincipal !== o.toPrincipal || !sameRuleOwner(existing.marker.from, from)) {
|
|
32
35
|
throw new Error(`an adoption toward "${existing.marker.toPrincipal}" is already in flight in this directory — refusing to start a different one (resume the original, or repair the marker by hand)`);
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
else if (existsSync(targetFile)) {
|
|
36
|
-
throw new Error(`the target bucket for "${
|
|
39
|
+
throw new Error(`the target bucket for "${o.toPrincipal}" already exists — merging two existing buckets goes through an explicit sync join, not a rename`);
|
|
37
40
|
}
|
|
38
|
-
const provider = new FileDurableRulePartitionProvider(
|
|
41
|
+
const provider = new FileDurableRulePartitionProvider(o.dir, o.onError);
|
|
39
42
|
try {
|
|
40
43
|
let lockProbe;
|
|
41
44
|
try {
|
|
42
|
-
lockProbe = writerOf(provider.forPrincipal(
|
|
45
|
+
lockProbe = writerOf(provider.forPrincipal(o.toPrincipal));
|
|
43
46
|
}
|
|
44
47
|
catch (err) {
|
|
45
48
|
if (!(err instanceof FileStoreLockError))
|
|
@@ -50,7 +53,7 @@ export async function adoptFilePermissionRuleStore(opts) {
|
|
|
50
53
|
throw new Error("the target store refused a write face");
|
|
51
54
|
let phase = existing !== undefined && "marker" in existing ? existing.marker.phase : 2;
|
|
52
55
|
if (existing === undefined) {
|
|
53
|
-
writeRuleAdoptionFile(
|
|
56
|
+
writeRuleAdoptionFile(o.dir, marker(from, o.toPrincipal, 2));
|
|
54
57
|
phase = 2;
|
|
55
58
|
}
|
|
56
59
|
if (phase < 3) {
|
|
@@ -61,11 +64,11 @@ export async function adoptFilePermissionRuleStore(opts) {
|
|
|
61
64
|
}
|
|
62
65
|
if (sourcePresent)
|
|
63
66
|
renameSync(sourceFile, targetFile);
|
|
64
|
-
writeRuleAdoptionFile(
|
|
67
|
+
writeRuleAdoptionFile(o.dir, marker(from, o.toPrincipal, 3));
|
|
65
68
|
phase = 3;
|
|
66
69
|
}
|
|
67
70
|
if (phase < 4) {
|
|
68
|
-
writeRuleAdoptionFile(
|
|
71
|
+
writeRuleAdoptionFile(o.dir, marker(from, o.toPrincipal, 4));
|
|
69
72
|
phase = 4;
|
|
70
73
|
}
|
|
71
74
|
let syncResult;
|
|
@@ -73,9 +76,9 @@ export async function adoptFilePermissionRuleStore(opts) {
|
|
|
73
76
|
try {
|
|
74
77
|
syncResult = await syncPermissionRules({
|
|
75
78
|
provider: createPermissionRuleStoreProvider({ durable: provider }),
|
|
76
|
-
principal:
|
|
77
|
-
transport:
|
|
78
|
-
...(
|
|
79
|
+
principal: o.toPrincipal,
|
|
80
|
+
transport: o.transport,
|
|
81
|
+
...(o.now !== undefined ? { now: o.now } : {}),
|
|
79
82
|
});
|
|
80
83
|
}
|
|
81
84
|
catch (err) {
|
|
@@ -88,12 +91,12 @@ export async function adoptFilePermissionRuleStore(opts) {
|
|
|
88
91
|
error: `the first sync round did not land clean (${(syncResult.warnings ?? []).join("; ") || `${syncResult.dropped.length} drop(s)`}) — resume when the endpoint is healthy`,
|
|
89
92
|
};
|
|
90
93
|
}
|
|
91
|
-
writeRuleAdoptionFile(
|
|
94
|
+
writeRuleAdoptionFile(o.dir, marker(from, o.toPrincipal, 5));
|
|
92
95
|
phase = 5;
|
|
93
96
|
}
|
|
94
|
-
writeRuleAdoptionFile(
|
|
97
|
+
writeRuleAdoptionFile(o.dir, {
|
|
95
98
|
schemaVersion: 1,
|
|
96
|
-
adopted: { from, toPrincipal:
|
|
99
|
+
adopted: { from, toPrincipal: o.toPrincipal, atMs: (o.now ?? Date.now)() },
|
|
97
100
|
});
|
|
98
101
|
return { status: "adopted", ...(syncResult !== undefined ? { syncResult } : {}) };
|
|
99
102
|
}
|
|
@@ -11,6 +11,7 @@ import { SESSION_RULES_GRAMMAR, readRuleGrammarStamp } from "../../core/session-
|
|
|
11
11
|
import { canonicalize } from "../../core/canonical-json.js";
|
|
12
12
|
import { BootLock, FileStoreLockError } from "./fs-atomic.js";
|
|
13
13
|
import { assertAdoptionBootGate } from "./adoption/marker.js";
|
|
14
|
+
import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
|
|
14
15
|
import { thrownText } from "../../core/thrown-value.js";
|
|
15
16
|
function isRuleFile(v) {
|
|
16
17
|
const p = v;
|
|
@@ -402,6 +403,7 @@ class FileDurableRulePartition {
|
|
|
402
403
|
}),
|
|
403
404
|
};
|
|
404
405
|
}
|
|
406
|
+
const FILE_DURABLE_RULE_PARTITION_PROVIDER_OPTION_KEYS = optionKeys()({ dataRoot: 0, platform: 0 });
|
|
405
407
|
export class FileDurableRulePartitionProvider {
|
|
406
408
|
dir;
|
|
407
409
|
onError;
|
|
@@ -411,11 +413,12 @@ export class FileDurableRulePartitionProvider {
|
|
|
411
413
|
constructor(dir, onError, opts) {
|
|
412
414
|
this.dir = dir;
|
|
413
415
|
this.onError = onError;
|
|
414
|
-
|
|
415
|
-
|
|
416
|
+
const options = receiveOptions(opts, "FileDurableRulePartitionProvider", FILE_DURABLE_RULE_PARTITION_PROVIDER_OPTION_KEYS);
|
|
417
|
+
if (options.dataRoot !== undefined)
|
|
418
|
+
assertAdoptionBootGate(options.dataRoot, "FileDurableRulePartitionProvider");
|
|
416
419
|
let said = false;
|
|
417
420
|
this.vetting = {
|
|
418
|
-
platform:
|
|
421
|
+
platform: options.platform,
|
|
419
422
|
modeBitsUnjudged: (where) => {
|
|
420
423
|
if (said)
|
|
421
424
|
return;
|
|
@@ -4,7 +4,8 @@ import { judgeSessionRulesWrite, readMountedToolNames, readSessionRulesShape, Se
|
|
|
4
4
|
import { atomicWriteFile, ensureDir, sanitizeScope } from "./fs-atomic.js";
|
|
5
5
|
import { guardCorruptSink } from "./corrupt-read-sink.js";
|
|
6
6
|
import { assertAdoptionBootGate, readRootAdoptionFile } from "./adoption/marker.js";
|
|
7
|
-
import { receiveOptions } from "../../core/own-property-receipt.js";
|
|
7
|
+
import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
|
|
8
|
+
const FILE_SESSION_POLICY_STORE_OPTION_KEYS = optionKeys()({ mountedToolNames: 0, onCorruptRead: 0 });
|
|
8
9
|
export const SESSION_POLICY_MARK_SUFFIX = ".hwm.json";
|
|
9
10
|
const MARK_SUFFIX = SESSION_POLICY_MARK_SUFFIX;
|
|
10
11
|
export function readSessionPolicyMark(path) {
|
|
@@ -75,7 +76,7 @@ export class FileSessionPolicyStore {
|
|
|
75
76
|
mountedToolNames;
|
|
76
77
|
anonymousAlias;
|
|
77
78
|
constructor(root, options) {
|
|
78
|
-
const opts = receiveOptions(options, "FileSessionPolicyStore");
|
|
79
|
+
const opts = receiveOptions(options, "FileSessionPolicyStore", FILE_SESSION_POLICY_STORE_OPTION_KEYS);
|
|
79
80
|
assertAdoptionBootGate(root, "FileSessionPolicyStore");
|
|
80
81
|
this.mountedToolNames = readMountedToolNames(opts?.mountedToolNames);
|
|
81
82
|
this.dir = join(root, "session-policy");
|
|
@@ -51,6 +51,13 @@ export declare class FileSessionRepo implements SessionRepo {
|
|
|
51
51
|
* the row). `skipped` words the corrupt-header refusal's reading of the records around it, where the caller has one.
|
|
52
52
|
*/
|
|
53
53
|
private headerOf;
|
|
54
|
+
/**
|
|
55
|
+
* The row's header record, where the log has one: its FIRST record, which must be the meta header every write path lays down. A log whose
|
|
56
|
+
* first record is anything else is no row this store wrote — `corrupt_session`, said once here for every reader of the row. The cells
|
|
57
|
+
* inside it are each read by their own reader ({@link headerOf} for the whole header, `placementOf` for the placement tuple alone):
|
|
58
|
+
* a reader of one cell does not answer for the others.
|
|
59
|
+
*/
|
|
60
|
+
private metaLineOf;
|
|
54
61
|
/**
|
|
55
62
|
* The row's head in one read, without replaying the log: ONE descriptor on the session file, its first record for the owner and
|
|
56
63
|
* occupant cells, and walking back from its end to the last entry record for the leaf. The three come from one inode — a file
|
|
@@ -73,9 +80,13 @@ export declare class FileSessionRepo implements SessionRepo {
|
|
|
73
80
|
* `undefined` = no row; a row whose header cannot be read rejects (`corrupt_session`).
|
|
74
81
|
*/
|
|
75
82
|
private rowOf;
|
|
76
|
-
/** The one descriptor a by-id read of the row takes: its size and modification time and its header, from one inode (a
|
|
77
|
-
* or removed while this reads is still the inode this descriptor opened); `undefined` = no file.
|
|
83
|
+
/** The one descriptor a by-id read of the row takes: its size and modification time and its header decoded whole, from one inode (a
|
|
84
|
+
* file replaced or removed while this reads is still the inode this descriptor opened); `undefined` = no file. A reader of one cell
|
|
85
|
+
* alone takes {@link atFirstRecord}, which this is built on. */
|
|
78
86
|
private atRow;
|
|
87
|
+
/** The descriptor under every by-id header read: the file's size and modification time and its first record, undecoded — the bytes
|
|
88
|
+
* each cell's reader decodes. One inode, bounded by the lines before the first record, never by the log; `undefined` = no file. */
|
|
89
|
+
private atFirstRecord;
|
|
79
90
|
private storage;
|
|
80
91
|
/**
|
|
81
92
|
* RB-437 — release every shared authority this repo joined (LAST holder ⇒ evict + close the append fd).
|
|
@@ -119,7 +130,9 @@ export declare class FileSessionRepo implements SessionRepo {
|
|
|
119
130
|
scope?: string;
|
|
120
131
|
}): Promise<PlacedSessionRow[]>;
|
|
121
132
|
/** Cheap placement probe for one id (the TtlSessionStore's cold-cache release consults it so the
|
|
122
|
-
* placed real-deletion obligation holds after a restart)
|
|
133
|
+
* placed real-deletion obligation holds after a restart), answered from the row's header record alone — never a replay of its log —
|
|
134
|
+
* and from the placement cell alone: a row whose owner cell cannot be read still says whether it is placed (the readers of the owner
|
|
135
|
+
* refuse that row; this probe is not one of them). `undefined` = missing file OR unplaced; a log with no header record rejects. */
|
|
123
136
|
placementOf(sessionId: string): Promise<SessionPlacementRecord | undefined>;
|
|
124
137
|
delete(metadata: SessionMetadata, expect?: SessionRowExpectation): Promise<void>;
|
|
125
138
|
fork(sourceMetadata: SessionMetadata, options?: SessionForkOptions & SessionCreateOptions): Promise<Session>;
|
|
@@ -4,7 +4,7 @@ import { BaseSessionStorage, StoredSession, SessionError, assertForkTarget, comp
|
|
|
4
4
|
import { canonicalStoreKey, AppendLog, atomicWriteFile, ensureDir, firstJsonlRecord, lastJsonlRecord, readJsonlRecords, sanitizePathComponent, writeThenLink } from "./fs-atomic.js";
|
|
5
5
|
import { guardCorruptSink } from "./corrupt-read-sink.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
|
import { thrownText } from "../../core/thrown-value.js";
|
|
9
9
|
const SUFFIX = ".jsonl";
|
|
10
10
|
const SESSION_LINE_JUDGE = {
|
|
@@ -72,13 +72,14 @@ class FileSessionStorage extends BaseSessionStorage {
|
|
|
72
72
|
this.recordEntry(entry);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
+
const FILE_SESSION_REPO_OPTION_KEYS = optionKeys()({ onCorruptRead: 0 });
|
|
75
76
|
export class FileSessionRepo {
|
|
76
77
|
dir;
|
|
77
78
|
tmpDir;
|
|
78
79
|
onCorruptRead;
|
|
79
80
|
joined = new Map();
|
|
80
81
|
constructor(root, options) {
|
|
81
|
-
const opts = receiveOptions(options, "FileSessionRepo");
|
|
82
|
+
const opts = receiveOptions(options, "FileSessionRepo", FILE_SESSION_REPO_OPTION_KEYS);
|
|
82
83
|
assertAdoptionBootGate(root, "FileSessionRepo");
|
|
83
84
|
this.dir = join(root, "sessions");
|
|
84
85
|
this.tmpDir = join(root, "tmp");
|
|
@@ -111,21 +112,25 @@ export class FileSessionRepo {
|
|
|
111
112
|
return { meta, entries };
|
|
112
113
|
}
|
|
113
114
|
headerOf(id, path, first, skipped = () => "") {
|
|
114
|
-
|
|
115
|
-
throw new SessionError("corrupt_session", `Session ${id} is unreadable: its log has no meta header${skipped()}`);
|
|
115
|
+
const head = this.metaLineOf(id, first, skipped);
|
|
116
116
|
const said = (key) => (detail) => this.disclose(path, `session header ${key}: ${detail}`, id);
|
|
117
|
-
const incarnation = readIncarnationCell(
|
|
118
|
-
const forkedFromIncarnation = readIncarnationCell(
|
|
117
|
+
const incarnation = readIncarnationCell(head.incarnation, said("incarnation"));
|
|
118
|
+
const forkedFromIncarnation = readIncarnationCell(head.forkedFromIncarnation, said("forkedFromIncarnation"));
|
|
119
119
|
return {
|
|
120
120
|
id,
|
|
121
|
-
createdAt:
|
|
122
|
-
...(
|
|
123
|
-
...(
|
|
121
|
+
createdAt: head.createdAt,
|
|
122
|
+
...(head.forkedFrom !== undefined ? { forkedFrom: head.forkedFrom } : {}),
|
|
123
|
+
...(head.placement !== undefined ? { placement: head.placement } : {}),
|
|
124
124
|
...(incarnation !== undefined ? { incarnation } : {}),
|
|
125
125
|
...(forkedFromIncarnation !== undefined ? { forkedFromIncarnation } : {}),
|
|
126
|
-
owner: readOwnerCell(
|
|
126
|
+
owner: readOwnerCell(head.owner, id),
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
|
+
metaLineOf(id, first, skipped = () => "") {
|
|
130
|
+
if (first === undefined || first.kind !== "meta")
|
|
131
|
+
throw new SessionError("corrupt_session", `Session ${id} is unreadable: its log has no meta header${skipped()}`);
|
|
132
|
+
return first;
|
|
133
|
+
}
|
|
129
134
|
async headOf(sessionId) {
|
|
130
135
|
return this.headNow(sessionId);
|
|
131
136
|
}
|
|
@@ -156,9 +161,12 @@ export class FileSessionRepo {
|
|
|
156
161
|
}
|
|
157
162
|
atRow(sessionId, read) {
|
|
158
163
|
const path = this.pathFor(sessionId);
|
|
164
|
+
return this.atFirstRecord(sessionId, (fd, size, first, mtimeMs) => read(fd, size, this.headerOf(sessionId, path, first), mtimeMs));
|
|
165
|
+
}
|
|
166
|
+
atFirstRecord(sessionId, read) {
|
|
159
167
|
let fd;
|
|
160
168
|
try {
|
|
161
|
-
fd = openSync(
|
|
169
|
+
fd = openSync(this.pathFor(sessionId), "r");
|
|
162
170
|
}
|
|
163
171
|
catch (err) {
|
|
164
172
|
if (err.code === "ENOENT")
|
|
@@ -167,7 +175,7 @@ export class FileSessionRepo {
|
|
|
167
175
|
}
|
|
168
176
|
try {
|
|
169
177
|
const { size, mtimeMs } = fstatSync(fd);
|
|
170
|
-
return read(fd, size,
|
|
178
|
+
return read(fd, size, firstJsonlRecord(fd, size, SESSION_LINE_JUDGE), mtimeMs);
|
|
171
179
|
}
|
|
172
180
|
finally {
|
|
173
181
|
closeSync(fd);
|
|
@@ -292,14 +300,7 @@ export class FileSessionRepo {
|
|
|
292
300
|
return out;
|
|
293
301
|
}
|
|
294
302
|
async placementOf(sessionId) {
|
|
295
|
-
|
|
296
|
-
return this.read(sessionId).meta.placement;
|
|
297
|
-
}
|
|
298
|
-
catch (err) {
|
|
299
|
-
if (err instanceof SessionError && err.code === "not_found")
|
|
300
|
-
return undefined;
|
|
301
|
-
throw err;
|
|
302
|
-
}
|
|
303
|
+
return this.atFirstRecord(sessionId, (_fd, _size, first) => this.metaLineOf(sessionId, first).placement);
|
|
303
304
|
}
|
|
304
305
|
async delete(metadata, expect) {
|
|
305
306
|
if (expect !== undefined && !sessionRowMatches(expect, this.headNow(metadata.id), () => sessionLogMarkOf(this.read(metadata.id).entries)))
|