@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
|
@@ -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");
|
|
@@ -9,7 +9,8 @@ export interface FileSessionRepoOptions {
|
|
|
9
9
|
*
|
|
10
10
|
* Fires for: an unreadable sessions DIRECTORY (the listing degrades to "no sessions"), a session log
|
|
11
11
|
* whose header could not be read during a listing (skipped from the result — a listing reads headers,
|
|
12
|
-
* it never replays a log
|
|
12
|
+
* it never replays a log; a PLACED row whose owner cell alone is unreadable is not skipped — the placed listing lists it — and is
|
|
13
|
+
* disclosed as that), and each corrupt interior JSONL record dropped on replay plus that replay's
|
|
13
14
|
* tally (turns missing from an otherwise healthy session).
|
|
14
15
|
*
|
|
15
16
|
* Never fires on plain ENOENT / `not_found` — that is honest absence, and the torn TAIL stays silent
|
|
@@ -41,7 +42,7 @@ export declare class FileSessionRepo implements SessionRepo {
|
|
|
41
42
|
* file whose first record is not a meta header → `corrupt_session`, even when every other record is intact
|
|
42
43
|
* (every write path here lays the header down first and the header alone carries `createdAt` / fork /
|
|
43
44
|
* placement / owner, so the file is not a session this store wrote, or its header line is damaged);
|
|
44
|
-
* otherwise the session, each skipped record disclosed.
|
|
45
|
+
* otherwise the session, each skipped record disclosed, and `loss` = what the replay dropped (absent = nothing).
|
|
45
46
|
*/
|
|
46
47
|
private read;
|
|
47
48
|
/**
|
|
@@ -51,6 +52,16 @@ export declare class FileSessionRepo implements SessionRepo {
|
|
|
51
52
|
* the row). `skipped` words the corrupt-header refusal's reading of the records around it, where the caller has one.
|
|
52
53
|
*/
|
|
53
54
|
private headerOf;
|
|
55
|
+
/** The header's cells but its owner — what a reader of the row's lane, lineage and occupant needs, each cell through its decoder. */
|
|
56
|
+
private cellsOf;
|
|
57
|
+
/**
|
|
58
|
+
* 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
|
|
59
|
+
* first record is anything else is no row this store wrote — `corrupt_session`, said once here for every reader of the row — and so is one
|
|
60
|
+
* whose placement cell is no placement tuple ({@link readPlacementCell}): the placement is the cell that says which lane the row lives
|
|
61
|
+
* in, so every reader of the row, of any other cell, goes through its judge. The other cells are each read by their own reader
|
|
62
|
+
* ({@link headerOf} for the whole header, `placementOf` for the placement tuple alone): a reader of one cell does not answer for the others.
|
|
63
|
+
*/
|
|
64
|
+
private metaLineOf;
|
|
54
65
|
/**
|
|
55
66
|
* 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
67
|
* occupant cells, and walking back from its end to the last entry record for the leaf. The three come from one inode — a file
|
|
@@ -70,12 +81,17 @@ export declare class FileSessionRepo implements SessionRepo {
|
|
|
70
81
|
/**
|
|
71
82
|
* The row's {@link SessionRow} — its header cells and the newest write it holds, the log's modification time (every write to a row
|
|
72
83
|
* is an append to its log; the placed listing's age reads the same time) — in one read of the header, never a replay of the log.
|
|
73
|
-
* `undefined` = no row; a row whose header cannot be read rejects (`corrupt_session`)
|
|
84
|
+
* `undefined` = no row; a row whose header cannot be read rejects (`corrupt_session`) — except a PLACED row whose only unreadable cell
|
|
85
|
+
* is the owner's, which is {@link OwnerlessPlacedRow}: a listing asks where a row lives and how old it is, not who owns it.
|
|
74
86
|
*/
|
|
75
87
|
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.
|
|
88
|
+
/** 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
|
|
89
|
+
* file replaced or removed while this reads is still the inode this descriptor opened); `undefined` = no file. A reader of one cell
|
|
90
|
+
* alone takes {@link atFirstRecord}, which this is built on. */
|
|
78
91
|
private atRow;
|
|
92
|
+
/** The descriptor under every by-id header read: the file's size and modification time and its first record, undecoded — the bytes
|
|
93
|
+
* each cell's reader decodes. One inode, bounded by the lines before the first record, never by the log; `undefined` = no file. */
|
|
94
|
+
private atFirstRecord;
|
|
79
95
|
private storage;
|
|
80
96
|
/**
|
|
81
97
|
* RB-437 — release every shared authority this repo joined (LAST holder ⇒ evict + close the append fd).
|
|
@@ -103,7 +119,8 @@ export declare class FileSessionRepo implements SessionRepo {
|
|
|
103
119
|
* browse face never throws — but "I could not read the directory" and "there are none" are different facts, and only the sink can
|
|
104
120
|
* tell them apart (ENOENT is honest absence: the constructor creates the directory, so it was removed underneath us). A session
|
|
105
121
|
* whose header cannot be read is skipped and disclosed — it exists and is missing from the listing — while a file that vanished
|
|
106
|
-
* between the directory read and its own is honest absence.
|
|
122
|
+
* between the directory read and its own is honest absence. A placed row whose owner alone is unreadable is neither skipped nor
|
|
123
|
+
* silent: it is kept (the placed listing lists it) and disclosed, once per listing, in the same sentence whichever listing reads it.
|
|
107
124
|
*/
|
|
108
125
|
private rows;
|
|
109
126
|
/**
|
|
@@ -119,7 +136,9 @@ export declare class FileSessionRepo implements SessionRepo {
|
|
|
119
136
|
scope?: string;
|
|
120
137
|
}): Promise<PlacedSessionRow[]>;
|
|
121
138
|
/** 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)
|
|
139
|
+
* placed real-deletion obligation holds after a restart), answered from the row's header record alone — never a replay of its log —
|
|
140
|
+
* 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
|
|
141
|
+
* refuse that row; this probe is not one of them). `undefined` = missing file OR unplaced; a log with no header record rejects. */
|
|
123
142
|
placementOf(sessionId: string): Promise<SessionPlacementRecord | undefined>;
|
|
124
143
|
delete(metadata: SessionMetadata, expect?: SessionRowExpectation): Promise<void>;
|
|
125
144
|
fork(sourceMetadata: SessionMetadata, options?: SessionForkOptions & SessionCreateOptions): Promise<Session>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { closeSync, existsSync, fstatSync, openSync, readdirSync, rmSync, utimesSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { BaseSessionStorage, StoredSession, SessionError, assertForkTarget, compareOccupants, forkRowCells, frozenRow, getEntriesToFork, importRowCells, incarnationCell, leafIdAfterEntry, ownerCell, readIncarnationCell, readOwnerCell, resolveLeafId, rowExpectationMissed, sessionLogMarkOf, sessionRowMatches, uuidv7, validateEntriesForImport, } from "../../internal/harness.js";
|
|
3
|
+
import { BaseSessionStorage, StoredSession, SessionError, assertForkTarget, compareOccupants, forkRowCells, frozenRow, getEntriesToFork, importRowCells, incarnationCell, leafIdAfterEntry, ownerCell, placementCellToWrite, readIncarnationCell, readOwnerCell, readPlacementCell, replayLossText, resolveLeafId, rowExpectationMissed, sessionLogMarkOf, sessionRowMatches, uuidv7, validateEntriesForImport, } from "../../internal/harness.js";
|
|
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 = {
|
|
@@ -38,8 +38,8 @@ class FileSessionStorage extends BaseSessionStorage {
|
|
|
38
38
|
canonicalPath;
|
|
39
39
|
holders = new Set();
|
|
40
40
|
occupant;
|
|
41
|
-
constructor(log, meta, entries, canonicalPath) {
|
|
42
|
-
super(meta, entries);
|
|
41
|
+
constructor(log, meta, entries, canonicalPath, replayLoss) {
|
|
42
|
+
super(meta, entries, undefined, replayLoss !== undefined ? { replayLoss } : undefined);
|
|
43
43
|
this.log = log;
|
|
44
44
|
this.canonicalPath = canonicalPath;
|
|
45
45
|
this.occupant = { incarnation: meta.incarnation };
|
|
@@ -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");
|
|
@@ -103,29 +104,38 @@ export class FileSessionRepo {
|
|
|
103
104
|
tally = info;
|
|
104
105
|
this.onCorruptRead?.({ ...info, sessionId: id });
|
|
105
106
|
}, SESSION_LINE_JUDGE);
|
|
106
|
-
const
|
|
107
|
+
const loss = tally !== undefined ? { dropped: tally.dropped, total: tally.total } : undefined;
|
|
108
|
+
const meta = this.headerOf(id, path, lines[0], () => ` (${replayLossText(loss ?? { dropped: 0, total: lines.length })})`);
|
|
107
109
|
const entries = [];
|
|
108
110
|
for (const line of lines)
|
|
109
111
|
if (line.kind === "entry")
|
|
110
112
|
entries.push(line.entry);
|
|
111
|
-
return { meta, entries };
|
|
113
|
+
return { meta, entries, ...(loss !== undefined ? { loss } : {}) };
|
|
112
114
|
}
|
|
113
115
|
headerOf(id, path, first, skipped = () => "") {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
+
const head = this.metaLineOf(id, first, skipped);
|
|
117
|
+
return { ...this.cellsOf(id, path, head), owner: readOwnerCell(head.owner, id) };
|
|
118
|
+
}
|
|
119
|
+
cellsOf(id, path, head) {
|
|
116
120
|
const said = (key) => (detail) => this.disclose(path, `session header ${key}: ${detail}`, id);
|
|
117
|
-
const incarnation = readIncarnationCell(
|
|
118
|
-
const forkedFromIncarnation = readIncarnationCell(
|
|
121
|
+
const incarnation = readIncarnationCell(head.incarnation, said("incarnation"));
|
|
122
|
+
const forkedFromIncarnation = readIncarnationCell(head.forkedFromIncarnation, said("forkedFromIncarnation"));
|
|
119
123
|
return {
|
|
120
124
|
id,
|
|
121
|
-
createdAt:
|
|
122
|
-
...(
|
|
123
|
-
...(
|
|
125
|
+
createdAt: head.createdAt,
|
|
126
|
+
...(head.forkedFrom !== undefined ? { forkedFrom: head.forkedFrom } : {}),
|
|
127
|
+
...(head.placement !== undefined ? { placement: head.placement } : {}),
|
|
124
128
|
...(incarnation !== undefined ? { incarnation } : {}),
|
|
125
129
|
...(forkedFromIncarnation !== undefined ? { forkedFromIncarnation } : {}),
|
|
126
|
-
owner: readOwnerCell(first.owner, id),
|
|
127
130
|
};
|
|
128
131
|
}
|
|
132
|
+
metaLineOf(id, first, skipped = () => "") {
|
|
133
|
+
if (first === undefined || first.kind !== "meta")
|
|
134
|
+
throw new SessionError("corrupt_session", `Session ${id} is unreadable: its log has no meta header${skipped()}`);
|
|
135
|
+
const { placement: raw, ...cells } = first;
|
|
136
|
+
const placement = readPlacementCell(raw, id);
|
|
137
|
+
return { ...cells, ...(placement !== undefined ? { placement } : {}) };
|
|
138
|
+
}
|
|
129
139
|
async headOf(sessionId) {
|
|
130
140
|
return this.headNow(sessionId);
|
|
131
141
|
}
|
|
@@ -152,13 +162,31 @@ export class FileSessionRepo {
|
|
|
152
162
|
return { metadata: meta, head: { owner: meta.owner ?? null, incarnation: meta.incarnation, leafId: resolveLeafId(entries) }, entries };
|
|
153
163
|
}
|
|
154
164
|
rowOf(sessionId) {
|
|
155
|
-
|
|
165
|
+
const path = this.pathFor(sessionId);
|
|
166
|
+
return this.atFirstRecord(sessionId, (_fd, _size, first, mtimeMs) => {
|
|
167
|
+
const head = this.metaLineOf(sessionId, first);
|
|
168
|
+
const cells = this.cellsOf(sessionId, path, head);
|
|
169
|
+
const lastActiveAt = Math.trunc(mtimeMs);
|
|
170
|
+
let owner;
|
|
171
|
+
try {
|
|
172
|
+
owner = readOwnerCell(head.owner, sessionId);
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
if (head.placement === undefined || !(err instanceof SessionError))
|
|
176
|
+
throw err;
|
|
177
|
+
return { id: sessionId, placement: head.placement, lastActiveAt, ownerFault: thrownText(err) };
|
|
178
|
+
}
|
|
179
|
+
return { ...cells, owner, lastActiveAt };
|
|
180
|
+
});
|
|
156
181
|
}
|
|
157
182
|
atRow(sessionId, read) {
|
|
158
183
|
const path = this.pathFor(sessionId);
|
|
184
|
+
return this.atFirstRecord(sessionId, (fd, size, first, mtimeMs) => read(fd, size, this.headerOf(sessionId, path, first), mtimeMs));
|
|
185
|
+
}
|
|
186
|
+
atFirstRecord(sessionId, read) {
|
|
159
187
|
let fd;
|
|
160
188
|
try {
|
|
161
|
-
fd = openSync(
|
|
189
|
+
fd = openSync(this.pathFor(sessionId), "r");
|
|
162
190
|
}
|
|
163
191
|
catch (err) {
|
|
164
192
|
if (err.code === "ENOENT")
|
|
@@ -167,13 +195,13 @@ export class FileSessionRepo {
|
|
|
167
195
|
}
|
|
168
196
|
try {
|
|
169
197
|
const { size, mtimeMs } = fstatSync(fd);
|
|
170
|
-
return read(fd, size,
|
|
198
|
+
return read(fd, size, firstJsonlRecord(fd, size, SESSION_LINE_JUDGE), mtimeMs);
|
|
171
199
|
}
|
|
172
200
|
finally {
|
|
173
201
|
closeSync(fd);
|
|
174
202
|
}
|
|
175
203
|
}
|
|
176
|
-
storage(meta, entries) {
|
|
204
|
+
storage(meta, entries, loss) {
|
|
177
205
|
const { id } = meta;
|
|
178
206
|
const canonical = canonicalStoreKey(this.pathFor(id));
|
|
179
207
|
const live = sharedSessionStorages.get(canonical)?.deref();
|
|
@@ -185,7 +213,7 @@ export class FileSessionRepo {
|
|
|
185
213
|
if (live !== undefined)
|
|
186
214
|
evictSharedSessionStorage(canonical);
|
|
187
215
|
const log = new AppendLog(this.pathFor(id));
|
|
188
|
-
const created = new FileSessionStorage(log, frozenRow({ ...meta, ...(meta.placement !== undefined ? { placement: { ...meta.placement } } : {}) }), entries, canonical);
|
|
216
|
+
const created = new FileSessionStorage(log, frozenRow({ ...meta, ...(meta.placement !== undefined ? { placement: { ...meta.placement } } : {}) }), entries, canonical, loss);
|
|
189
217
|
sharedSessionStorages.set(canonical, new WeakRef(created));
|
|
190
218
|
created.addHolder(this);
|
|
191
219
|
this.joined.set(canonical, new WeakRef(created));
|
|
@@ -210,7 +238,7 @@ export class FileSessionRepo {
|
|
|
210
238
|
const path = this.pathFor(id);
|
|
211
239
|
if (!existsSync(path)) {
|
|
212
240
|
const owner = ownerCell(options.owner);
|
|
213
|
-
const placement = options.placement
|
|
241
|
+
const placement = placementCellToWrite(options.placement, id, Date.now());
|
|
214
242
|
const meta = { id, createdAt, ...(placement !== undefined ? { placement } : {}), ...incarnationCell(undefined), ...owner };
|
|
215
243
|
try {
|
|
216
244
|
writeThenLink(path, `${JSON.stringify({ kind: "meta", ...meta })}\n`);
|
|
@@ -222,12 +250,12 @@ export class FileSessionRepo {
|
|
|
222
250
|
}
|
|
223
251
|
return new StoredSession(this.storage(meta, []));
|
|
224
252
|
}
|
|
225
|
-
const { meta, entries } = this.read(id);
|
|
226
|
-
return new StoredSession(this.storage({ ...meta, createdAt: meta.createdAt || createdAt }, entries));
|
|
253
|
+
const { meta, entries, loss } = this.read(id);
|
|
254
|
+
return new StoredSession(this.storage({ ...meta, createdAt: meta.createdAt || createdAt }, entries, loss));
|
|
227
255
|
}
|
|
228
256
|
async open(metadata) {
|
|
229
|
-
const { meta, entries } = this.read(metadata.id);
|
|
230
|
-
return new StoredSession(this.storage(meta, entries));
|
|
257
|
+
const { meta, entries, loss } = this.read(metadata.id);
|
|
258
|
+
return new StoredSession(this.storage(meta, entries, loss));
|
|
231
259
|
}
|
|
232
260
|
async touch(sessionId) {
|
|
233
261
|
const now = new Date();
|
|
@@ -269,8 +297,11 @@ export class FileSessionRepo {
|
|
|
269
297
|
this.disclose(this.pathFor(id), `session log unreadable (${thrownText(err)}) — skipped from ${listing}`, id);
|
|
270
298
|
continue;
|
|
271
299
|
}
|
|
272
|
-
if (row
|
|
273
|
-
|
|
300
|
+
if (row === undefined)
|
|
301
|
+
continue;
|
|
302
|
+
if ("ownerFault" in row)
|
|
303
|
+
this.disclose(this.pathFor(id), `session log is a placed row whose owner cell is unreadable (${row.ownerFault}) — the placed listing lists it, the host listing never does`, id);
|
|
304
|
+
out.push(row);
|
|
274
305
|
}
|
|
275
306
|
return out;
|
|
276
307
|
}
|
|
@@ -292,14 +323,7 @@ export class FileSessionRepo {
|
|
|
292
323
|
return out;
|
|
293
324
|
}
|
|
294
325
|
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
|
-
}
|
|
326
|
+
return this.atFirstRecord(sessionId, (_fd, _size, first) => this.metaLineOf(sessionId, first).placement);
|
|
303
327
|
}
|
|
304
328
|
async delete(metadata, expect) {
|
|
305
329
|
if (expect !== undefined && !sessionRowMatches(expect, this.headNow(metadata.id), () => sessionLogMarkOf(this.read(metadata.id).entries)))
|
|
@@ -105,6 +105,17 @@ export declare class FileToolResultStore implements ToolResultStore {
|
|
|
105
105
|
* even with a damaged owner record, so removing one on a guess would destroy another session's output.
|
|
106
106
|
*/
|
|
107
107
|
deleteBySession(sessionId: string): ToolResultDeletionReport;
|
|
108
|
+
/**
|
|
109
|
+
* Age out the entries stored more than `maxAgeMs` before `now` (interface: {@link ToolResultStore.reap}). An entry's
|
|
110
|
+
* age is its content file's modification time: the write-once publication sets it and nothing rewrites the file.
|
|
111
|
+
* Both namespaces are swept, and only names this store writes are judged. Removal is content then owner record, the order {@link deleteBySession} keeps; an owner
|
|
112
|
+
* record whose content is already gone — the leftover of an interrupted pass, or of a session sweep — is removed
|
|
113
|
+
* once it is past the cutoff too, and is not counted (it was not an entry). Synchronous: under the data root's single
|
|
114
|
+
* writer nothing interleaves with it.
|
|
115
|
+
*/
|
|
116
|
+
reap(now: number, opts?: {
|
|
117
|
+
maxAgeMs?: number;
|
|
118
|
+
}): number;
|
|
108
119
|
/**
|
|
109
120
|
* The entries `sessionId` owns, as ref + recorded owner (interface: {@link ToolResultStore.listBySession}). The selection is
|
|
110
121
|
* {@link deleteBySession}'s own: it walks the same two namespaces and matches on the SIDECAR's `sessionId`, never on a file name; a
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { readFileSync, readdirSync, unlinkSync } from "node:fs";
|
|
2
|
+
import { readFileSync, readdirSync, statSync, unlinkSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
+
import { ageCutoff } from "../../core/retention-policy.js";
|
|
4
5
|
import { assertSafeToolResultRef, assertToolResultProvenanceMatch, normalizeToolResultProvenance, ToolResultRefConflictError, } from "../../core/tool-result-store.js";
|
|
5
6
|
import { ensureDir, sanitizePathComponent, writeThenLink } from "./fs-atomic.js";
|
|
6
7
|
import { guardCorruptSink } from "./corrupt-read-sink.js";
|
|
7
8
|
import { assertAdoptionBootGate } from "./adoption/marker.js";
|
|
8
|
-
import { receiveOptions } from "../../core/own-property-receipt.js";
|
|
9
|
+
import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
|
|
10
|
+
const FILE_TOOL_RESULT_STORE_OPTION_KEYS = optionKeys()({ onCorruptRead: 0 });
|
|
9
11
|
export class FileToolResultStore {
|
|
10
12
|
dir;
|
|
11
13
|
discloseCorrupt;
|
|
12
14
|
constructor(root, options) {
|
|
13
|
-
const opts = receiveOptions(options, "FileToolResultStore");
|
|
15
|
+
const opts = receiveOptions(options, "FileToolResultStore", FILE_TOOL_RESULT_STORE_OPTION_KEYS);
|
|
14
16
|
assertAdoptionBootGate(root, "FileToolResultStore");
|
|
15
17
|
this.dir = join(root, "tool-results");
|
|
16
18
|
this.discloseCorrupt = guardCorruptSink(opts?.onCorruptRead);
|
|
@@ -181,6 +183,44 @@ export class FileToolResultStore {
|
|
|
181
183
|
}
|
|
182
184
|
return { deleted, unattributable };
|
|
183
185
|
}
|
|
186
|
+
reap(now, opts) {
|
|
187
|
+
const cutoff = ageCutoff("FileToolResultStore.reap", now, opts);
|
|
188
|
+
if (cutoff === undefined)
|
|
189
|
+
return 0;
|
|
190
|
+
let removed = 0;
|
|
191
|
+
for (const [dir, folded] of [[this.dir, false], [join(this.dir, FOLDED_SUBDIR), true]]) {
|
|
192
|
+
let names;
|
|
193
|
+
try {
|
|
194
|
+
names = readdirSync(dir);
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
if (err.code === "ENOENT")
|
|
198
|
+
continue;
|
|
199
|
+
throw err;
|
|
200
|
+
}
|
|
201
|
+
const listed = new Set(names);
|
|
202
|
+
for (const name of names) {
|
|
203
|
+
const content = name.endsWith(CONTENT_SUFFIX);
|
|
204
|
+
if (!content && !name.endsWith(OWNER_SUFFIX))
|
|
205
|
+
continue;
|
|
206
|
+
const stem = name.slice(0, -(content ? CONTENT_SUFFIX : OWNER_SUFFIX).length);
|
|
207
|
+
if (!isEncodedStem(stem, folded))
|
|
208
|
+
continue;
|
|
209
|
+
if (!content && listed.has(`${stem}${CONTENT_SUFFIX}`))
|
|
210
|
+
continue;
|
|
211
|
+
const path = join(dir, name);
|
|
212
|
+
const modified = modifiedAt(path);
|
|
213
|
+
if (modified === undefined || modified >= cutoff)
|
|
214
|
+
continue;
|
|
215
|
+
unlinkIfAbsentOk(path);
|
|
216
|
+
if (content) {
|
|
217
|
+
unlinkIfAbsentOk(join(dir, `${stem}${OWNER_SUFFIX}`));
|
|
218
|
+
removed++;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return removed;
|
|
223
|
+
}
|
|
184
224
|
listBySession(sessionId) {
|
|
185
225
|
const entries = [];
|
|
186
226
|
let unattributable = 0;
|
|
@@ -277,6 +317,16 @@ function readOwnerAt(path) {
|
|
|
277
317
|
const read = readOwnerFileAt(path);
|
|
278
318
|
return typeof read === "string" ? read : read.provenance;
|
|
279
319
|
}
|
|
320
|
+
function modifiedAt(path) {
|
|
321
|
+
try {
|
|
322
|
+
return statSync(path).mtimeMs;
|
|
323
|
+
}
|
|
324
|
+
catch (err) {
|
|
325
|
+
if (err.code === "ENOENT")
|
|
326
|
+
return undefined;
|
|
327
|
+
throw err;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
280
330
|
function unlinkIfAbsentOk(path) {
|
|
281
331
|
try {
|
|
282
332
|
unlinkSync(path);
|
|
@@ -295,6 +345,10 @@ function encodeRefFilename(ref) {
|
|
|
295
345
|
const base = ref.replace(/[^A-Za-z0-9_.-]/g, "-").slice(0, 64);
|
|
296
346
|
return { folded: true, stem: `${base || "ref"}-${createHash("sha256").update(Buffer.from(ref, "utf16le")).digest("hex")}` };
|
|
297
347
|
}
|
|
348
|
+
const FOLDED_STEM = /^[A-Za-z0-9_.-]{1,64}-[0-9a-f]{64}$/;
|
|
349
|
+
function isEncodedStem(stem, folded) {
|
|
350
|
+
return folded ? FOLDED_STEM.test(stem) : stem.length <= MAX_FILENAME_CHARS && NATIVE_FILENAME_CHARSET.test(stem);
|
|
351
|
+
}
|
|
298
352
|
function intOr(x, fallback) {
|
|
299
353
|
return Number.isFinite(x) ? Math.floor(x) : fallback;
|
|
300
354
|
}
|
|
@@ -3,13 +3,14 @@ import { join } from "node:path";
|
|
|
3
3
|
import { chargeUsageRecord, readUsageRecord, EMPTY_USAGE_WINDOW_RECORD, } from "../../core/usage-window-store.js";
|
|
4
4
|
import { atomicWriteFile, ensureDir, sanitizeScope } from "./fs-atomic.js";
|
|
5
5
|
import { assertAdoptionBootGate } from "./adoption/marker.js";
|
|
6
|
-
import { receiveOptions } from "../../core/own-property-receipt.js";
|
|
6
|
+
import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
|
|
7
7
|
import { guardCorruptSink } from "./corrupt-read-sink.js";
|
|
8
|
+
const FILE_USAGE_WINDOW_STORE_OPTION_KEYS = optionKeys()({ onCorruptRead: 0 });
|
|
8
9
|
export class FileUsageWindowStore {
|
|
9
10
|
dir;
|
|
10
11
|
onCorruptRead;
|
|
11
12
|
constructor(root, options) {
|
|
12
|
-
const opts = receiveOptions(options, "FileUsageWindowStore");
|
|
13
|
+
const opts = receiveOptions(options, "FileUsageWindowStore", FILE_USAGE_WINDOW_STORE_OPTION_KEYS);
|
|
13
14
|
assertAdoptionBootGate(root, "FileUsageWindowStore");
|
|
14
15
|
this.dir = join(root, "usage-windows");
|
|
15
16
|
ensureDir(this.dir);
|
|
@@ -126,8 +126,6 @@ export declare class FileWorkflowJournalStore implements WorkflowJournalStore {
|
|
|
126
126
|
/** RB-242 — release ONLY a claim this `newRunId` still holds. A claim that is already gone (TTL-reaped
|
|
127
127
|
* and possibly taken over) is a no-op: unlinking a successor's claim would re-open the very fork this prevents. */
|
|
128
128
|
releaseResumeClaim(input: ResumeClaimArgs): Promise<void>;
|
|
129
|
-
/** GC (service extra, mirrors the SQL twins): drop the run's ledger once the run is terminal + retained. */
|
|
130
|
-
deleteByRun(runId: string): Promise<number>;
|
|
131
129
|
/** Release ledger fds (graceful shutdown; parity with the other file stores' dispose).
|
|
132
130
|
* Refcounted: the fds are shared with any other instance on the same directory, so the LAST holder
|
|
133
131
|
* closes them. Idempotent — a second dispose() on the same instance must not decrement twice and pull
|
|
@@ -6,7 +6,7 @@ import { AppendLog, readJsonlRecords } from "./fs-atomic.js";
|
|
|
6
6
|
import { guardCorruptSink } from "./corrupt-read-sink.js";
|
|
7
7
|
import { canonicalStoreKey, sanitizePathComponent, writeThenLink } from "./fs-atomic.js";
|
|
8
8
|
import { assertAdoptionBootGate } from "./adoption/marker.js";
|
|
9
|
-
import { receiveOptions } from "../../core/own-property-receipt.js";
|
|
9
|
+
import { optionKeys, receiveOptions } from "../../core/own-property-receipt.js";
|
|
10
10
|
import { assertJournalEntryFits } from "../../core/workflow-journal-store.js";
|
|
11
11
|
export const RESUME_CLAIM_TTL_MS = 60 * 60 * 1000;
|
|
12
12
|
export const RESUME_CLAIM_RELEASE_GRACE_MS = 5_000;
|
|
@@ -18,6 +18,7 @@ function isJournalLine(r) {
|
|
|
18
18
|
const rec = r;
|
|
19
19
|
return typeof rec.scope === "string" && Number.isFinite(rec.ordinal);
|
|
20
20
|
}
|
|
21
|
+
const FILE_WORKFLOW_JOURNAL_STORE_OPTION_KEYS = optionKeys()({ onCorruptRead: 0 });
|
|
21
22
|
export class FileWorkflowJournalStore {
|
|
22
23
|
fsyncEnabled;
|
|
23
24
|
dir;
|
|
@@ -35,7 +36,7 @@ export class FileWorkflowJournalStore {
|
|
|
35
36
|
discloseCorrupt;
|
|
36
37
|
constructor(root, fsyncEnabled = true, options) {
|
|
37
38
|
this.fsyncEnabled = fsyncEnabled;
|
|
38
|
-
const opts = receiveOptions(options, "FileWorkflowJournalStore");
|
|
39
|
+
const opts = receiveOptions(options, "FileWorkflowJournalStore", FILE_WORKFLOW_JOURNAL_STORE_OPTION_KEYS);
|
|
39
40
|
this.discloseCorrupt = guardCorruptSink(opts?.onCorruptRead);
|
|
40
41
|
assertAdoptionBootGate(root, "FileWorkflowJournalStore");
|
|
41
42
|
this.dir = join(root, "workflow-journal");
|
|
@@ -259,22 +260,6 @@ export class FileWorkflowJournalStore {
|
|
|
259
260
|
return;
|
|
260
261
|
this.unlinkIfUnchanged(path, existing.raw);
|
|
261
262
|
}
|
|
262
|
-
async deleteByRun(runId) {
|
|
263
|
-
const log = this.logs.get(runId);
|
|
264
|
-
if (log !== undefined) {
|
|
265
|
-
try {
|
|
266
|
-
log.close();
|
|
267
|
-
}
|
|
268
|
-
catch { }
|
|
269
|
-
this.logs.delete(runId);
|
|
270
|
-
}
|
|
271
|
-
this.scopes.delete(runId);
|
|
272
|
-
const path = this.pathFor(runId);
|
|
273
|
-
if (!existsSync(path))
|
|
274
|
-
return 0;
|
|
275
|
-
unlinkSync(path);
|
|
276
|
-
return 1;
|
|
277
|
-
}
|
|
278
263
|
dispose() {
|
|
279
264
|
if (this.closed)
|
|
280
265
|
return;
|
|
@@ -17,7 +17,7 @@ export declare class FileWorkflowRunStore implements WorkflowRunStore {
|
|
|
17
17
|
/** RB-145: this instance's own close latch — the refcount belongs to the DIRECTORY, not to callers. */
|
|
18
18
|
private closed;
|
|
19
19
|
private get runs();
|
|
20
|
-
constructor(root: string,
|
|
20
|
+
constructor(root: string, options?: FileWorkflowRunStoreOptions);
|
|
21
21
|
/** Serialize an op behind any in-flight op on the same id (the in-process per-id async mutex). */
|
|
22
22
|
private withLock;
|
|
23
23
|
/** Commit one ledger event (append + fsync) THEN flip the in-memory map (crash-safe ordering), then
|