@sema-agent/core 7.59.0 → 7.60.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 +564 -0
- package/dist/agents/agent-definition.d.ts +7 -0
- package/dist/agents/agent-definition.js +12 -0
- package/dist/agents/agent-transcript-tool.d.ts +2 -1
- package/dist/agents/agent-transcript-tool.js +3 -1
- package/dist/agents/child-model-seat.js +6 -3
- package/dist/agents/cumulative-stats.js +0 -1
- package/dist/agents/inherited-tool-pool.d.ts +26 -1
- package/dist/agents/inherited-tool-pool.js +22 -0
- package/dist/agents/retain-ledger.d.ts +11 -1
- package/dist/agents/retain-ledger.js +13 -2
- package/dist/agents/roster-store.d.ts +1 -1
- package/dist/agents/roster-store.js +3 -1
- package/dist/agents/send-message-tool.d.ts +8 -19
- package/dist/agents/send-message-tool.js +11 -38
- package/dist/agents/subagent.d.ts +51 -17
- package/dist/agents/subagent.js +117 -78
- package/dist/agents/tool-filter.d.ts +1 -3
- package/dist/agents/tool-filter.js +4 -12
- package/dist/bench/metrics.d.ts +3 -5
- package/dist/bench/metrics.js +0 -1
- package/dist/brain/degrading.js +3 -1
- package/dist/brain/route-adjudicator.js +3 -1
- package/dist/brain/status-sink.d.ts +7 -1
- package/dist/brain/status-sink.js +6 -0
- package/dist/brain/timeout.d.ts +3 -1
- package/dist/brain/timeout.js +18 -5
- package/dist/core/a2a.d.ts +15 -5
- package/dist/core/a2a.js +34 -19
- package/dist/core/agent-definition.d.ts +20 -0
- package/dist/core/allow-entry.d.ts +2 -0
- package/dist/core/allow-entry.js +3 -1
- package/dist/core/artifact-host.d.ts +0 -2
- package/dist/core/artifact-host.js +0 -1
- package/dist/core/auto-mode-defaults.d.ts +8 -0
- package/dist/core/auto-mode-defaults.js +1 -0
- package/dist/core/auto-mode-rebuild.d.ts +2 -1
- package/dist/core/auto-mode.d.ts +39 -4
- package/dist/core/auto-mode.js +63 -12
- package/dist/core/background-agent-store.d.ts +10 -1
- package/dist/core/background-agent-store.js +3 -2
- package/dist/core/background-shell.d.ts +12 -1
- package/dist/core/background-shell.js +12 -0
- package/dist/core/checkpoint-store.d.ts +8 -13
- package/dist/core/checkpoint-store.js +4 -3
- package/dist/core/compliance.d.ts +1 -1
- package/dist/core/credential-echo.d.ts +52 -0
- package/dist/core/credential-echo.js +65 -0
- package/dist/core/credential-vocabulary.d.ts +13 -3
- package/dist/core/credential-vocabulary.js +12 -4
- package/dist/core/cross-boundary-taint.d.ts +4 -5
- package/dist/core/engine-notice.d.ts +58 -15
- package/dist/core/frame-settlement.d.ts +5 -0
- package/dist/core/frame-settlement.js +4 -0
- package/dist/core/gate-fold.js +7 -5
- package/dist/core/gate-lanes.js +39 -8
- package/dist/core/governance-codes.d.ts +9 -1
- package/dist/core/governance-codes.js +12 -0
- package/dist/core/hands-band-screen.js +0 -1
- package/dist/core/hands-band.d.ts +0 -3
- package/dist/core/hooks.d.ts +39 -56
- package/dist/core/hooks.js +123 -77
- package/dist/core/image-admission.d.ts +104 -51
- package/dist/core/image-admission.js +170 -46
- package/dist/core/image-downsample.d.ts +36 -69
- package/dist/core/image-downsample.js +111 -73
- package/dist/core/integer-option.d.ts +21 -0
- package/dist/core/integer-option.js +13 -0
- package/dist/core/locked-config.d.ts +54 -3
- package/dist/core/locked-config.js +81 -50
- package/dist/core/mcp-call-meta.d.ts +2 -2
- package/dist/core/mcp-call-meta.js +9 -10
- package/dist/core/mcp-failure.d.ts +9 -3
- package/dist/core/mcp-failure.js +10 -0
- package/dist/core/mcp-host-seat.d.ts +92 -0
- package/dist/core/mcp-host-seat.js +131 -0
- package/dist/core/mcp-probe.d.ts +7 -2
- package/dist/core/mcp-probe.js +7 -2
- package/dist/core/mcp-server-spec.d.ts +38 -9
- package/dist/core/mcp-server-spec.js +55 -21
- package/dist/core/mcp.d.ts +17 -6
- package/dist/core/mcp.js +67 -55
- package/dist/core/memory-admission.d.ts +23 -6
- package/dist/core/memory-admission.js +19 -9
- package/dist/core/memory-engine/content-origin.d.ts +13 -0
- package/dist/core/memory-engine/content-origin.js +21 -3
- package/dist/core/memory-engine/index.d.ts +2 -1
- package/dist/core/memory-engine/index.js +2 -1
- package/dist/core/memory-engine/scope-contract.d.ts +13 -3
- package/dist/core/memory-engine/scope-contract.js +2 -2
- package/dist/core/memory-engine/sync-client.d.ts +45 -11
- package/dist/core/memory-engine/sync-client.js +82 -11
- package/dist/core/memory-engine/sync-report.d.ts +103 -0
- package/dist/core/memory-engine/sync-report.js +119 -0
- package/dist/core/memory-engine/sync.d.ts +4 -2
- package/dist/core/mode-policy.d.ts +9 -1
- package/dist/core/mode-policy.js +11 -1
- package/dist/core/model-receipt.d.ts +39 -0
- package/dist/core/model-receipt.js +139 -0
- package/dist/core/mods/agent-stations.d.ts +65 -0
- package/dist/core/mods/agent-stations.js +105 -0
- package/dist/core/mods/kernel/dispatch.d.ts +5 -1
- package/dist/core/mods/kernel/dispatch.js +4 -4
- package/dist/core/mods/kernel/events.d.ts +10 -4
- package/dist/core/mods/kernel/events.js +10 -6
- package/dist/core/mods/kernel/receive.d.ts +5 -0
- package/dist/core/mods/kernel/receive.js +10 -0
- package/dist/core/mods/lifecycle-stations.d.ts +41 -0
- package/dist/core/mods/lifecycle-stations.js +35 -0
- package/dist/core/mods/stations.d.ts +51 -59
- package/dist/core/mods/stations.js +32 -42
- package/dist/core/mods/tool-call.d.ts +10 -4
- package/dist/core/mods/tool-call.js +28 -12
- package/dist/core/mounted-mcp.d.ts +5 -0
- package/dist/core/mounted-mcp.js +2 -2
- package/dist/core/namespaced-rule-name.d.ts +7 -1
- package/dist/core/namespaced-rule-name.js +13 -2
- package/dist/core/oracle-isolation.js +1 -1
- package/dist/core/own-property-receipt.d.ts +3 -0
- package/dist/core/own-property-receipt.js +3 -0
- package/dist/core/park-selfcheck.js +8 -8
- package/dist/core/peer-seat.d.ts +63 -8
- package/dist/core/peer-seat.js +179 -34
- package/dist/core/permission-rule-consent.d.ts +0 -21
- package/dist/core/permission-rule-consent.js +1 -2
- package/dist/core/permission-rule-model.d.ts +4 -2
- package/dist/core/permission-rule-model.js +7 -6
- package/dist/core/protocol-http-auth.d.ts +14 -2
- package/dist/core/protocol-http-auth.js +16 -7
- package/dist/core/read-face-seats.d.ts +7 -5
- package/dist/core/read-face-seats.js +4 -1
- package/dist/core/redaction-marks.d.ts +4 -3
- package/dist/core/redaction-marks.js +2 -2
- package/dist/core/remote-env.d.ts +146 -98
- package/dist/core/remote-env.js +113 -14
- package/dist/core/retention.js +37 -12
- package/dist/core/retired-keys.d.ts +6 -1
- package/dist/core/retired-keys.js +4 -1
- package/dist/core/rewrite-rejudge.d.ts +12 -5
- package/dist/core/rewrite-rejudge.js +9 -5
- package/dist/core/roles.d.ts +37 -3
- package/dist/core/roles.js +126 -78
- package/dist/core/rule-owner.d.ts +3 -0
- package/dist/core/runner/assemble-result.d.ts +0 -5
- package/dist/core/runner/assemble-result.js +0 -1
- package/dist/core/runner/call-hook-stations.d.ts +17 -10
- package/dist/core/runner/call-hook-stations.js +21 -10
- package/dist/core/runner/child-tree.d.ts +7 -8
- package/dist/core/runner/child-tree.js +6 -6
- package/dist/core/runner/classifier-ladder.d.ts +10 -2
- package/dist/core/runner/classifier-ladder.js +39 -8
- package/dist/core/runner/construction-doors.js +5 -0
- package/dist/core/runner/contracts.d.ts +62 -41
- package/dist/core/runner/cross-boundary-lane.d.ts +3 -5
- package/dist/core/runner/cross-boundary-lane.js +11 -2
- package/dist/core/runner/env-capability-census.d.ts +15 -20
- package/dist/core/runner/env-capability-census.js +25 -34
- package/dist/core/runner/file-history-request.d.ts +2 -2
- package/dist/core/runner/file-history-request.js +0 -8
- package/dist/core/runner/gate-exit.d.ts +75 -7
- package/dist/core/runner/gate-exit.js +20 -1
- package/dist/core/runner/git-status-frame.d.ts +5 -2
- package/dist/core/runner/git-status-frame.js +3 -4
- package/dist/core/runner/image.d.ts +7 -2
- package/dist/core/runner/image.js +14 -8
- package/dist/core/runner/inline-image.d.ts +10 -8
- package/dist/core/runner/inline-image.js +11 -9
- package/dist/core/runner/memory-consolidation-driver.js +4 -4
- package/dist/core/runner/permission-rule-lanes.js +1 -1
- package/dist/core/runner/prepare-boundary-parks.d.ts +2 -2
- package/dist/core/runner/prepare-boundary-parks.js +3 -3
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
- package/dist/core/runner/prepare-config-doors.d.ts +6 -1
- package/dist/core/runner/prepare-config-doors.js +14 -9
- package/dist/core/runner/prepare-delegation-surface.d.ts +5 -3
- package/dist/core/runner/prepare-delegation-surface.js +4 -4
- package/dist/core/runner/prepare-file-history.d.ts +10 -12
- package/dist/core/runner/prepare-file-history.js +3 -12
- package/dist/core/runner/prepare-gate-stations.d.ts +4 -3
- package/dist/core/runner/prepare-gate-stations.js +4 -3
- package/dist/core/runner/prepare-hands-readface.d.ts +3 -1
- package/dist/core/runner/prepare-hands-readface.js +15 -7
- package/dist/core/runner/prepare-inherited-gate.d.ts +5 -4
- package/dist/core/runner/prepare-inherited-gate.js +9 -5
- package/dist/core/runner/prepare-memory-engine-session.js +1 -1
- package/dist/core/runner/prepare-memory.d.ts +2 -2
- package/dist/core/runner/prepare-memory.js +2 -2
- package/dist/core/runner/prepare-park-ask.d.ts +3 -5
- package/dist/core/runner/prepare-park-ask.js +3 -8
- package/dist/core/runner/prepare-policy-chain.d.ts +5 -4
- package/dist/core/runner/prepare-policy-chain.js +120 -108
- package/dist/core/runner/prepare-project-context.js +8 -5
- package/dist/core/runner/prepare-prompt-inputs.d.ts +4 -1
- package/dist/core/runner/prepare-prompt-inputs.js +3 -2
- package/dist/core/runner/prepare-protocol-tools.d.ts +5 -3
- package/dist/core/runner/prepare-protocol-tools.js +9 -2
- package/dist/core/runner/prepare-suspend-saga.d.ts +0 -2
- package/dist/core/runner/prepare-suspend-saga.js +5 -7
- package/dist/core/runner/prepare-task.js +41 -27
- package/dist/core/runner/prepare-turn-wiring.d.ts +2 -0
- package/dist/core/runner/prepare-turn-wiring.js +7 -2
- package/dist/core/runner/prepare-wiring-manifest.d.ts +4 -3
- package/dist/core/runner/prepare-wiring-manifest.js +32 -18
- package/dist/core/runner/prepare-workspace-restore.js +3 -3
- package/dist/core/runner/resume-checkpoint-screen.js +4 -4
- package/dist/core/runner/retired-runner-deps.js +4 -1
- package/dist/core/runner/run-attachment-seats.js +3 -3
- package/dist/core/runner/run-brain-sinks.js +1 -0
- package/dist/core/runner/run-git-lane.d.ts +3 -1
- package/dist/core/runner/run-git-lane.js +1 -1
- package/dist/core/runner/run-harness-handlers.d.ts +3 -1
- package/dist/core/runner/run-harness-handlers.js +3 -1
- package/dist/core/runner/run-identity-wiring.js +1 -1
- package/dist/core/runner/run-leg.js +26 -28
- package/dist/core/runner/run-notification-lane.d.ts +3 -1
- package/dist/core/runner/run-notification-lane.js +16 -10
- package/dist/core/runner/run-settle-and-teardown.js +5 -1
- package/dist/core/runner/run-stop-and-final-verify.d.ts +4 -0
- package/dist/core/runner/run-stop-and-final-verify.js +12 -4
- package/dist/core/runner/run-turn-boundary.js +12 -7
- package/dist/core/runner/runtask.d.ts +7 -4
- package/dist/core/runner/runtask.js +19 -11
- package/dist/core/runner/skills-seat.js +2 -2
- package/dist/core/runner/sub-agent-deny-lists.js +10 -7
- package/dist/core/runner/synthetic-tools.js +2 -2
- package/dist/core/runner/tool-disclosure.js +0 -2
- package/dist/core/runner/tool-face-overlay.d.ts +1 -1
- package/dist/core/runner/tool-face-overlay.js +26 -19
- package/dist/core/runner/tool-result-media-seat.d.ts +9 -1
- package/dist/core/runner/tool-result-media-seat.js +17 -1
- package/dist/core/runner/turn-attachments.d.ts +3 -5
- package/dist/core/runner/turn-attachments.js +3 -16
- package/dist/core/runner-deps.d.ts +31 -18
- package/dist/core/secret-env.d.ts +3 -2
- package/dist/core/session-policy-store.d.ts +9 -2
- package/dist/core/session-policy-store.js +16 -1
- package/dist/core/session-store.d.ts +3 -2
- package/dist/core/session-store.js +50 -11
- package/dist/core/skill-grant.d.ts +9 -0
- package/dist/core/skill-grant.js +18 -0
- package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
- package/dist/core/store-contracts/tool-result-store-contract.js +37 -0
- package/dist/core/stub-env.d.ts +5 -5
- package/dist/core/stub-env.js +11 -1
- package/dist/core/swappable-deps.d.ts +17 -43
- package/dist/core/swappable-deps.js +15 -5
- package/dist/core/synthetic-read-verdict.d.ts +1 -1
- package/dist/core/task-event.d.ts +18 -2
- package/dist/core/task-notification.d.ts +88 -5
- package/dist/core/task-notification.js +130 -7
- package/dist/core/task-registry-agent.d.ts +18 -12
- package/dist/core/task-registry-agent.js +18 -6
- package/dist/core/task-registry-monitor.d.ts +7 -0
- package/dist/core/task-registry-monitor.js +28 -1
- package/dist/core/task-registry-shared.d.ts +38 -3
- package/dist/core/task-registry-shared.js +21 -7
- package/dist/core/task-registry-workflow.js +1 -1
- package/dist/core/task-registry.d.ts +50 -35
- package/dist/core/task-registry.js +64 -23
- package/dist/core/task-result.d.ts +3 -12
- package/dist/core/task-spec.d.ts +3 -6
- package/dist/core/task-stream.d.ts +1 -1
- package/dist/core/tool-catalog-entries.js +1 -1
- package/dist/core/tool-face-reader.d.ts +7 -6
- package/dist/core/tool-face-reader.js +4 -3
- package/dist/core/tool-name-aliases.d.ts +19 -0
- package/dist/core/tool-name-aliases.js +54 -2
- package/dist/core/tool-policy.d.ts +5 -4
- package/dist/core/tool-policy.js +1 -1
- package/dist/core/tool-registry.d.ts +5 -5
- package/dist/core/tool-registry.js +2 -2
- package/dist/core/tool-result-store.d.ts +88 -5
- package/dist/core/tool-result-store.js +51 -12
- package/dist/core/tool-spec.d.ts +20 -4
- package/dist/core/trace.d.ts +0 -1
- package/dist/core/types.d.ts +3 -3
- package/dist/core/types.js +1 -1
- package/dist/core/untrusted-text.js +1 -1
- package/dist/core/user-attachment.d.ts +10 -5
- package/dist/core/user-attachment.js +14 -6
- package/dist/engine/execution-env/node-execution-env.d.ts +7 -2
- package/dist/engine/execution-env/node-execution-env.js +12 -1
- package/dist/engine/harness/agent-harness.d.ts +1 -1
- package/dist/engine/harness/agent-harness.js +8 -4
- package/dist/engine/harness/types.d.ts +112 -29
- package/dist/engine/loop/agent-loop.d.ts +12 -12
- package/dist/engine/loop/agent-loop.js +153 -21
- package/dist/engine/loop/types.d.ts +9 -2
- package/dist/engine/lsp/node-lsp-manager.d.ts +3 -3
- package/dist/engine/lsp/node-lsp-manager.js +32 -13
- package/dist/index.d.ts +22 -14
- package/dist/index.js +15 -10
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/orchestration/run-workflow-tool.d.ts +9 -3
- package/dist/orchestration/run-workflow-tool.js +59 -29
- package/dist/orchestration/workflow-governance.d.ts +1 -1
- package/dist/orchestration/workflow-governance.js +2 -1
- package/dist/orchestration/workflow.d.ts +4 -0
- package/dist/orchestration/workflow.js +25 -4
- package/dist/prompts/default.d.ts +1 -10
- package/dist/prompts/default.js +0 -2
- package/dist/stores/file/background-agent-store.d.ts +1 -1
- package/dist/stores/file/background-agent-store.js +3 -1
- package/dist/stores/file/checkpoint-store.d.ts +127 -2
- package/dist/stores/file/checkpoint-store.js +19 -14
- package/dist/stores/file/file-history-store.d.ts +1 -1
- package/dist/stores/file/file-history-store.js +3 -1
- package/dist/stores/file/index.d.ts +4 -3
- package/dist/stores/file/index.js +17 -8
- package/dist/stores/file/mailbox-store.d.ts +1 -1
- package/dist/stores/file/mailbox-store.js +3 -1
- package/dist/stores/file/memory-store.d.ts +1 -1
- package/dist/stores/file/memory-store.js +3 -1
- package/dist/stores/file/session-policy-store.d.ts +1 -1
- package/dist/stores/file/session-policy-store.js +3 -1
- package/dist/stores/file/session-store.d.ts +1 -1
- package/dist/stores/file/session-store.js +3 -1
- package/dist/stores/file/shared-ledger.d.ts +26 -0
- package/dist/stores/file/shared-ledger.js +38 -9
- package/dist/stores/file/tool-result-store.d.ts +20 -2
- package/dist/stores/file/tool-result-store.js +74 -6
- package/dist/stores/file/usage-window-store.d.ts +1 -1
- package/dist/stores/file/usage-window-store.js +3 -1
- package/dist/stores/file/workflow-journal-store.d.ts +1 -11
- package/dist/stores/file/workflow-journal-store.js +3 -2
- package/dist/tools/fs/containment-face.d.ts +5 -0
- package/dist/tools/fs/encoding.d.ts +13 -4
- package/dist/tools/fs/encoding.js +17 -2
- package/dist/tools/fs/fs-bash-background-text.d.ts +7 -0
- package/dist/tools/fs/fs-bash-background-text.js +1 -0
- package/dist/tools/fs/fs-bash.d.ts +8 -4
- package/dist/tools/fs/fs-bash.js +26 -35
- package/dist/tools/fs/fs-pdf.d.ts +2 -2
- package/dist/tools/fs/fs-pdf.js +26 -21
- package/dist/tools/fs/fs-read.d.ts +5 -4
- package/dist/tools/fs/fs-read.js +35 -18
- package/dist/tools/fs/fs-search-tools.js +4 -1
- package/dist/tools/fs/fs-shared.d.ts +11 -13
- package/dist/tools/fs/fs-shared.js +11 -7
- package/dist/tools/fs/fs-write.js +5 -5
- package/dist/tools/fs/index.d.ts +14 -8
- package/dist/tools/fs/index.js +8 -4
- package/dist/tools/fs/read-floor.d.ts +44 -1
- package/dist/tools/fs/read-floor.js +35 -0
- package/dist/tools/fs/removal-targets.d.ts +9 -4
- package/dist/tools/fs/removal-targets.js +17 -9
- package/dist/tools/fs/search.d.ts +3 -3
- package/dist/tools/fs/search.js +4 -4
- package/dist/tools/monitor.d.ts +5 -4
- package/dist/tools/monitor.js +15 -8
- package/dist/tools/scheduler-tools.js +42 -4
- package/dist/tools/web.d.ts +0 -10
- package/dist/tools/web.js +1 -4
- package/package.json +4 -2
- package/test/export-surface.snapshot.json +75 -21
- package/wire-changes/core-stores-sql@7.60.0.json +30 -0
- package/wire-changes/core@7.60.0.json +3274 -0
- package/wire-changes/mods-kernel@7.60.0.json +62 -0
- package/wire-changes/primitives@7.60.0.json +30 -0
|
@@ -15,13 +15,14 @@ import type { SessionPolicyStore } from "../../core/session-policy-store.js";
|
|
|
15
15
|
import type { WorkflowJournalStore } from "../../core/workflow-journal-store.js";
|
|
16
16
|
import type { UsageWindowStore } from "../../core/usage-window-store.js";
|
|
17
17
|
import type { EngineStorageBackend } from "../../core/engine-storage-backend.js";
|
|
18
|
-
export { FileCheckpointStore, type FileCheckpointStoreOptions } from "./checkpoint-store.js";
|
|
18
|
+
export { FileCheckpointStore, CHECKPOINT_LEDGER_EVENT_KINDS, readCheckpointLedger, type CheckpointLedgerEventKind, type CheckpointLedgerReading, type FileCheckpointStoreOptions, type ReadCheckpointLedgerOptions, } from "./checkpoint-store.js";
|
|
19
19
|
export { FileMemoryStore } from "./memory-store.js";
|
|
20
20
|
export { FileSessionRepo, type FileSessionRepoOptions } from "./session-store.js";
|
|
21
21
|
export { FileToolResultStore } from "./tool-result-store.js";
|
|
22
22
|
export { FileSessionPolicyStore, type FileSessionPolicyStoreOptions, type SessionPolicyCorruptReadInfo } from "./session-policy-store.js";
|
|
23
23
|
export { FileFileHistoryStore, type FileFileHistoryStoreOptions } from "./file-history-store.js";
|
|
24
|
-
export { FileWorkflowJournalStore
|
|
24
|
+
export { FileWorkflowJournalStore } from "./workflow-journal-store.js";
|
|
25
|
+
export { MAX_JOURNAL_RESULT_BYTES, oversizeJournalResult } from "../../core/workflow-journal-store.js";
|
|
25
26
|
export { FileUsageWindowStore, type FileUsageWindowStoreOptions } from "./usage-window-store.js";
|
|
26
27
|
export { resolveDataRoot, sanitizeScope, sanitizePathComponent, createFileConsolidationLock } from "./fs-atomic.js";
|
|
27
28
|
export { FileStoreLockError, type FileStoreLockErrorCode } from "./fs-atomic.js";
|
|
@@ -184,7 +185,7 @@ export declare class FileStorageBackend implements EngineStorageBackend {
|
|
|
184
185
|
* descriptors) this backend joined; `TtlSessionStore.dispose()` only clears the sweep timer. */
|
|
185
186
|
private readonly fileSessions;
|
|
186
187
|
private readonly fileWorkflowJournal;
|
|
187
|
-
constructor(
|
|
188
|
+
constructor(options?: FileStorageBackendOptions);
|
|
188
189
|
/**
|
|
189
190
|
* The data-dir boot lock could not be handed back — a root that turned read-only under a running
|
|
190
191
|
* process, an unreadable lock file. Teardown here is best-effort by contract, but best-effort must not
|
|
@@ -14,13 +14,18 @@ import { FileBackgroundAgentStore } from "./background-agent-store.js";
|
|
|
14
14
|
import { FileMailboxStore } from "./mailbox-store.js";
|
|
15
15
|
import { FileRosterStore } from "../../agents/roster-store.js";
|
|
16
16
|
import { FileFileHistoryStore } from "./file-history-store.js";
|
|
17
|
-
|
|
17
|
+
import { receiveOptions, receiveOwnProperties, refuseProxy } from "../../core/own-property-receipt.js";
|
|
18
|
+
function nestedOptions(value, member) {
|
|
19
|
+
return value === undefined ? undefined : receiveOwnProperties(value, { subject: `FileStorageBackendOptions.${member}`, unit: "option", moment: "at new FileStorageBackend" });
|
|
20
|
+
}
|
|
21
|
+
export { FileCheckpointStore, CHECKPOINT_LEDGER_EVENT_KINDS, readCheckpointLedger, } from "./checkpoint-store.js";
|
|
18
22
|
export { FileMemoryStore } from "./memory-store.js";
|
|
19
23
|
export { FileSessionRepo } from "./session-store.js";
|
|
20
24
|
export { FileToolResultStore } from "./tool-result-store.js";
|
|
21
25
|
export { FileSessionPolicyStore } from "./session-policy-store.js";
|
|
22
26
|
export { FileFileHistoryStore } from "./file-history-store.js";
|
|
23
|
-
export { FileWorkflowJournalStore
|
|
27
|
+
export { FileWorkflowJournalStore } from "./workflow-journal-store.js";
|
|
28
|
+
export { MAX_JOURNAL_RESULT_BYTES, oversizeJournalResult } from "../../core/workflow-journal-store.js";
|
|
24
29
|
export { FileUsageWindowStore } from "./usage-window-store.js";
|
|
25
30
|
export { resolveDataRoot, sanitizeScope, sanitizePathComponent, createFileConsolidationLock } from "./fs-atomic.js";
|
|
26
31
|
export { FileStoreLockError } from "./fs-atomic.js";
|
|
@@ -50,10 +55,14 @@ export class FileStorageBackend {
|
|
|
50
55
|
ttl;
|
|
51
56
|
fileSessions;
|
|
52
57
|
fileWorkflowJournal;
|
|
53
|
-
constructor(
|
|
54
|
-
if ("
|
|
55
|
-
|
|
58
|
+
constructor(options) {
|
|
59
|
+
if (options !== undefined && options !== null && typeof options === "object") {
|
|
60
|
+
refuseProxy(options, { subject: "FileStorageBackend options", unit: "option", moment: "at new FileStorageBackend" });
|
|
61
|
+
if (Object.hasOwn(options, "retention")) {
|
|
62
|
+
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
|
+
}
|
|
56
64
|
}
|
|
65
|
+
const opts = receiveOptions(options, "FileStorageBackend");
|
|
57
66
|
this.root = resolveDataRoot(opts.root);
|
|
58
67
|
assertAdoptionBootGate(this.root, "FileStorageBackend");
|
|
59
68
|
this.lock = new BootLock(join(this.root, "LOCK"));
|
|
@@ -66,14 +75,14 @@ export class FileStorageBackend {
|
|
|
66
75
|
this.ttl = new TtlSessionStore({ repo, evict: opts.evict ?? "forget", durability: "durable", placements: { subagent: { durability: "durable" } }, ...(opts.sessions !== undefined ? { hooks: opts.sessions } : {}) });
|
|
67
76
|
this.sessionStore = this.ttl;
|
|
68
77
|
const sessionHeadOf = this.ttl.headOf;
|
|
69
|
-
this.fileCheckpoints = new FileCheckpointStore(this.root, { ...opts.checkpoint, ...corruptRead, ...(sessionHeadOf !== undefined ? { sessionHeadOf } : {}) });
|
|
78
|
+
this.fileCheckpoints = new FileCheckpointStore(this.root, { ...nestedOptions(opts.checkpoint, "checkpoint"), ...corruptRead, ...(sessionHeadOf !== undefined ? { sessionHeadOf } : {}) });
|
|
70
79
|
built.push(() => this.fileCheckpoints.close());
|
|
71
80
|
this.checkpointStore = this.fileCheckpoints;
|
|
72
81
|
this.fileMemory = new FileMemoryStore(this.root, opts.embedder ? { embedder: opts.embedder } : {});
|
|
73
82
|
built.push(() => this.fileMemory.close());
|
|
74
83
|
this.memoryStore = guardedMemoryStore(this.fileMemory, opts.utilityGate);
|
|
75
84
|
this.toolResultStore = new FileToolResultStore(this.root, corruptRead);
|
|
76
|
-
this.sessionPolicyStore = new FileSessionPolicyStore(this.root, { ...opts.sessionPolicy, ...corruptRead });
|
|
85
|
+
this.sessionPolicyStore = new FileSessionPolicyStore(this.root, { ...nestedOptions(opts.sessionPolicy, "sessionPolicy"), ...corruptRead });
|
|
77
86
|
this.fileWorkflowJournal = new FileWorkflowJournalStore(this.root, true, corruptRead);
|
|
78
87
|
built.push(() => this.fileWorkflowJournal.dispose());
|
|
79
88
|
this.workflowJournalStore = this.fileWorkflowJournal;
|
|
@@ -85,7 +94,7 @@ export class FileStorageBackend {
|
|
|
85
94
|
built.push(() => this.fileMailbox.close());
|
|
86
95
|
this.mailboxStore = this.fileMailbox;
|
|
87
96
|
this.rosterStore = new FileRosterStore(join(this.root, "roster.json"), corruptRead ?? {});
|
|
88
|
-
this.fileHistoryStore = new FileFileHistoryStore(this.root, { ...(opts.fileHistory
|
|
97
|
+
this.fileHistoryStore = new FileFileHistoryStore(this.root, { ...nestedOptions(opts.fileHistory, "fileHistory"), ...(corruptRead ?? {}) });
|
|
89
98
|
this.consolidationLock = createFileConsolidationLock(join(this.root, "consolidation-locks"));
|
|
90
99
|
}
|
|
91
100
|
catch (err) {
|
|
@@ -66,7 +66,7 @@ export declare class FileMailboxStore implements MailboxStore {
|
|
|
66
66
|
private readonly touched;
|
|
67
67
|
/** The swallow-guarded corrupt-read seat (undefined = the old silent tolerance). */
|
|
68
68
|
private readonly discloseCorrupt;
|
|
69
|
-
constructor(root: string,
|
|
69
|
+
constructor(root: string, options?: FileMailboxStoreOptions);
|
|
70
70
|
/**
|
|
71
71
|
* RB-67 (2026-07-25, red probe): the on-disk name is CASE-FOLDED, so the in-memory key and the physical
|
|
72
72
|
* file can never disagree. Before this, `AgentOne` and `agentone` produced two DIFFERENT shared-state
|
|
@@ -7,6 +7,7 @@ import { AppendLog, atomicWriteFile, canonicalStoreKey, ensureDir, readJsonlReco
|
|
|
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
11
|
function diskMarkOf(path) {
|
|
11
12
|
try {
|
|
12
13
|
const st = statSync(path);
|
|
@@ -332,7 +333,8 @@ export class FileMailboxStore {
|
|
|
332
333
|
lockWaitMs;
|
|
333
334
|
touched = new Map();
|
|
334
335
|
discloseCorrupt;
|
|
335
|
-
constructor(root,
|
|
336
|
+
constructor(root, options) {
|
|
337
|
+
const opts = receiveOptions(options, "FileMailboxStore");
|
|
336
338
|
assertAdoptionBootGate(root, "FileMailboxStore");
|
|
337
339
|
this.fsyncEnabled = opts.fsync !== false;
|
|
338
340
|
this.compactEvery = opts.compactEvery ?? 500;
|
|
@@ -24,7 +24,7 @@ export declare class FileMemoryStore implements MemoryStore {
|
|
|
24
24
|
/** Set by {@link close}: a background embed that resolves AFTER close must NOT writeSync to the (now closed)
|
|
25
25
|
* vlog fd — a stray write on a recycled fd could corrupt an unrelated file. */
|
|
26
26
|
private closed;
|
|
27
|
-
constructor(root: string,
|
|
27
|
+
constructor(root: string, options?: {
|
|
28
28
|
embedder?: Embedder;
|
|
29
29
|
embedTimeoutMs?: number;
|
|
30
30
|
});
|
|
@@ -4,6 +4,7 @@ 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
8
|
const MAX_OPEN_MEMORY_SCOPES = 64;
|
|
8
9
|
const sharedMemoryDirs = new Map();
|
|
9
10
|
export class FileMemoryStore {
|
|
@@ -17,7 +18,8 @@ export class FileMemoryStore {
|
|
|
17
18
|
sharedScopes;
|
|
18
19
|
scopeKey;
|
|
19
20
|
closed = false;
|
|
20
|
-
constructor(root,
|
|
21
|
+
constructor(root, options) {
|
|
22
|
+
const opts = receiveOptions(options, "FileMemoryStore");
|
|
21
23
|
assertAdoptionBootGate(root, "FileMemoryStore");
|
|
22
24
|
this.root = join(root, "memory");
|
|
23
25
|
this.scopeKey = canonicalStoreKey(this.root);
|
|
@@ -146,7 +146,7 @@ export declare class FileSessionPolicyStore implements SessionPolicyStore {
|
|
|
146
146
|
* identity, so on such a root the anonymous key IS the adopted principal — reads and writes
|
|
147
147
|
* alike (a window-era anonymous write must not mint a fresh orphan row). */
|
|
148
148
|
private readonly anonymousAlias;
|
|
149
|
-
constructor(root: string,
|
|
149
|
+
constructor(root: string, options?: FileSessionPolicyStoreOptions);
|
|
150
150
|
/** The one delivery point for {@link onCorruptRead}. */
|
|
151
151
|
private disclose;
|
|
152
152
|
/** The ONE refusal for a rules file that is PRESENT but cannot be served as rules — every damage grade lands
|
|
@@ -4,6 +4,7 @@ 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
8
|
export const SESSION_POLICY_MARK_SUFFIX = ".hwm.json";
|
|
8
9
|
const MARK_SUFFIX = SESSION_POLICY_MARK_SUFFIX;
|
|
9
10
|
export function readSessionPolicyMark(path) {
|
|
@@ -73,7 +74,8 @@ export class FileSessionPolicyStore {
|
|
|
73
74
|
onCorruptRead;
|
|
74
75
|
mountedToolNames;
|
|
75
76
|
anonymousAlias;
|
|
76
|
-
constructor(root,
|
|
77
|
+
constructor(root, options) {
|
|
78
|
+
const opts = receiveOptions(options, "FileSessionPolicyStore");
|
|
77
79
|
assertAdoptionBootGate(root, "FileSessionPolicyStore");
|
|
78
80
|
this.mountedToolNames = readMountedToolNames(opts?.mountedToolNames);
|
|
79
81
|
this.dir = join(root, "session-policy");
|
|
@@ -32,7 +32,7 @@ export declare class FileSessionRepo implements SessionRepo {
|
|
|
32
32
|
* `dispose()` walks it and releases each holder share; the weak value is what makes the identity
|
|
33
33
|
* check on the way out possible without pinning a storage the table itself only holds weakly. */
|
|
34
34
|
private readonly joined;
|
|
35
|
-
constructor(root: string,
|
|
35
|
+
constructor(root: string, options?: FileSessionRepoOptions);
|
|
36
36
|
/** The one delivery point for {@link FileSessionRepoOptions.onCorruptRead}'s whole-file level; `sessionId` when the file is one session's log. */
|
|
37
37
|
private disclose;
|
|
38
38
|
private pathFor;
|
|
@@ -4,6 +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
8
|
import { thrownText } from "../../core/thrown-value.js";
|
|
8
9
|
const SUFFIX = ".jsonl";
|
|
9
10
|
const SESSION_LINE_JUDGE = {
|
|
@@ -76,7 +77,8 @@ export class FileSessionRepo {
|
|
|
76
77
|
tmpDir;
|
|
77
78
|
onCorruptRead;
|
|
78
79
|
joined = new Map();
|
|
79
|
-
constructor(root,
|
|
80
|
+
constructor(root, options) {
|
|
81
|
+
const opts = receiveOptions(options, "FileSessionRepo");
|
|
80
82
|
assertAdoptionBootGate(root, "FileSessionRepo");
|
|
81
83
|
this.dir = join(root, "sessions");
|
|
82
84
|
this.tmpDir = join(root, "tmp");
|
|
@@ -92,6 +92,32 @@ export interface LedgerModel<Row, Ev> {
|
|
|
92
92
|
judgeRow(x: unknown): boolean;
|
|
93
93
|
judgeEvent(x: unknown): boolean;
|
|
94
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* The ONE fold of a snapshot+ledger pair into its rows: the snapshot (the compacted base) row by row, then the live ledger's events in
|
|
97
|
+
* order (last-writer-wins, `model.apply`). A READ — it takes no writer fence, opens no append handle and creates nothing (a missing file
|
|
98
|
+
* reads as empty), so it is what both the authority's own bootstrap ({@link LedgerCore.bootstrap}, which takes the fence first) and a
|
|
99
|
+
* reader that must not contend for the directory ({@link readLedgerSettled}) run: a reader never carries a second copy of the fold.
|
|
100
|
+
*/
|
|
101
|
+
export declare function replayLedger<Row, Ev>(paths: Pick<LedgerPaths, "snapshotPath" | "ledgerPath" | "onCorruptRead">, model: LedgerModel<Row, Ev>): {
|
|
102
|
+
rows: Map<string, Row>;
|
|
103
|
+
events: number;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* {@link replayLedger} for a reader that takes NO writer fence, beside a writer that may be compacting. The pair is read snapshot-first, and
|
|
107
|
+
* compaction rewrites the snapshot and THEN empties the ledger, so a read that saw the old snapshot and the emptied ledger would miss every
|
|
108
|
+
* row that lives only in the new snapshot — a clean-looking state that never existed. Such a read is recognisable by the snapshot having
|
|
109
|
+
* changed version by the time the ledger was read, and is discarded and redone, at most {@link SETTLED_READ_ATTEMPTS} times; a snapshot that
|
|
110
|
+
* will not hold still yields `settled: false` — no reading at all — never the last read. (A compaction that has replaced the snapshot but not
|
|
111
|
+
* yet the ledger is a state a crashed writer leaves too, and the authority's own bootstrap replays exactly that pair.) Appends move nothing
|
|
112
|
+
* here: a ledger read ends at a record boundary, so the events it holds are a prefix of the writer's.
|
|
113
|
+
*/
|
|
114
|
+
export declare function readLedgerSettled<Row, Ev>(paths: Pick<LedgerPaths, "snapshotPath" | "ledgerPath" | "onCorruptRead">, model: LedgerModel<Row, Ev>): {
|
|
115
|
+
settled: true;
|
|
116
|
+
rows: Map<string, Row>;
|
|
117
|
+
events: number;
|
|
118
|
+
} | {
|
|
119
|
+
settled: false;
|
|
120
|
+
};
|
|
95
121
|
/**
|
|
96
122
|
* One directory's authority: the replayed row map, the per-key async mutex, the append log and the
|
|
97
123
|
* event counter. Created and owned by {@link SharedLedgerTable}; every store instance over the
|
|
@@ -1,4 +1,38 @@
|
|
|
1
|
+
import { statSync } from "node:fs";
|
|
1
2
|
import { acquireStoreDirLock, AppendLog, atomicWriteFile, canonicalStoreKey, ensureDir, readJsonlRecords, } from "./fs-atomic.js";
|
|
3
|
+
export function replayLedger(paths, model) {
|
|
4
|
+
const rows = new Map();
|
|
5
|
+
const disclose = paths.onCorruptRead;
|
|
6
|
+
const judge = (accepts, what) => ({ accepts, what: `a ${what} carries none of this ${model.label}'s own members` });
|
|
7
|
+
for (const row of readJsonlRecords(paths.snapshotPath, disclose, judge(model.judgeRow, "snapshot row"))) {
|
|
8
|
+
rows.set(model.keyOf(row), row);
|
|
9
|
+
}
|
|
10
|
+
const events = readJsonlRecords(paths.ledgerPath, disclose, judge(model.judgeEvent, "ledger event"));
|
|
11
|
+
for (const ev of events)
|
|
12
|
+
model.apply(rows, ev);
|
|
13
|
+
return { rows, events: events.length };
|
|
14
|
+
}
|
|
15
|
+
function snapshotVersion(snapshotPath) {
|
|
16
|
+
try {
|
|
17
|
+
const st = statSync(snapshotPath, { bigint: true });
|
|
18
|
+
return `${st.dev}:${st.ino}:${st.size}:${st.mtimeNs}`;
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
if (e.code === "ENOENT")
|
|
22
|
+
return "absent";
|
|
23
|
+
throw e;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const SETTLED_READ_ATTEMPTS = 3;
|
|
27
|
+
export function readLedgerSettled(paths, model) {
|
|
28
|
+
for (let attempt = 0; attempt < SETTLED_READ_ATTEMPTS; attempt++) {
|
|
29
|
+
const before = snapshotVersion(paths.snapshotPath);
|
|
30
|
+
const read = replayLedger(paths, model);
|
|
31
|
+
if (snapshotVersion(paths.snapshotPath) === before)
|
|
32
|
+
return { settled: true, ...read };
|
|
33
|
+
}
|
|
34
|
+
return { settled: false };
|
|
35
|
+
}
|
|
2
36
|
export class LedgerCore {
|
|
3
37
|
key;
|
|
4
38
|
paths;
|
|
@@ -20,15 +54,10 @@ export class LedgerCore {
|
|
|
20
54
|
bootstrap() {
|
|
21
55
|
this.fence = acquireStoreDirLock(this.paths.dir, { label: this.model.label });
|
|
22
56
|
try {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
const events = readJsonlRecords(this.paths.ledgerPath, disclose, judge(this.model.judgeEvent, "ledger event"));
|
|
29
|
-
this.events = events.length;
|
|
30
|
-
for (const ev of events)
|
|
31
|
-
this.model.apply(this.rows, ev);
|
|
57
|
+
const replayed = replayLedger(this.paths, this.model);
|
|
58
|
+
for (const [key, row] of replayed.rows)
|
|
59
|
+
this.rows.set(key, row);
|
|
60
|
+
this.events = replayed.events;
|
|
32
61
|
this.handle = new AppendLog(this.paths.ledgerPath);
|
|
33
62
|
}
|
|
34
63
|
catch (e) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ToolResultDeletionReport, ToolResultProvenance, ToolResultSlice, ToolResultStore } from "../../core/tool-result-store.js";
|
|
1
|
+
import type { ToolResultDeletionReport, ToolResultProvenance, ToolResultSessionListing, ToolResultSlice, ToolResultStore } from "../../core/tool-result-store.js";
|
|
2
2
|
import { type CorruptReadInfo } from "./corrupt-read-sink.js";
|
|
3
3
|
/**
|
|
4
4
|
* design/80 §2.5 — file {@link ToolResultStore}: write-once-idempotent, ONE file per ref.
|
|
@@ -36,7 +36,7 @@ export interface FileToolResultStoreOptions {
|
|
|
36
36
|
export declare class FileToolResultStore implements ToolResultStore {
|
|
37
37
|
private readonly dir;
|
|
38
38
|
private readonly discloseCorrupt;
|
|
39
|
-
constructor(root: string,
|
|
39
|
+
constructor(root: string, options?: FileToolResultStoreOptions);
|
|
40
40
|
/** The one delivery point for {@link FileToolResultStoreOptions.onCorruptRead}. */
|
|
41
41
|
private disclose;
|
|
42
42
|
/** The directory a ref's files live in, and their shared stem. See {@link encodeRefFilename} for why
|
|
@@ -105,4 +105,22 @@ 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
|
+
* The entries `sessionId` owns, as ref + recorded owner (interface: {@link ToolResultStore.listBySession}). The selection is
|
|
110
|
+
* {@link deleteBySession}'s own: it walks the same two namespaces and matches on the SIDECAR's `sessionId`, never on a file name; a
|
|
111
|
+
* sidecar that cannot be read, and content with no sidecar, are counted `unattributable` and not listed.
|
|
112
|
+
*
|
|
113
|
+
* Naming the ref is this backend's one extra step, because a folded name is a digest of the ref and cannot be read back. An entry
|
|
114
|
+
* written by this engine carries its ref in its sidecar; an identity-named entry (a ref inside the filename charset) is its own stem.
|
|
115
|
+
* The ref a record states is believed only when its own encoding is the very file the record sits beside — a record that names a ref
|
|
116
|
+
* stored somewhere else is not this entry's. An entry owned by the session whose ref can be named by neither is counted
|
|
117
|
+
* `unaddressable` (a folded entry written before the sidecar carried it): it is still removed by a sweep, and is never listed under a
|
|
118
|
+
* guessed ref. An entry is what the sweep counts: an owner record whose content file is gone (the leftover of an interrupted sweep, which
|
|
119
|
+
* the next sweep finishes) is listed like the sweep counts it, and `get` answers `undefined` for it — the honest absence a reader of a
|
|
120
|
+
* listing already handles.
|
|
121
|
+
*/
|
|
122
|
+
listBySession(sessionId: string): ToolResultSessionListing;
|
|
123
|
+
/** The ref an entry stored at `dir`/`stem` is stored under, or `undefined` when none can be named: the ref its sidecar states when
|
|
124
|
+
* that ref's own location is this file, else — for an identity-named entry — the stem itself. */
|
|
125
|
+
private refOfEntry;
|
|
108
126
|
}
|
|
@@ -5,10 +5,12 @@ import { assertSafeToolResultRef, assertToolResultProvenanceMatch, normalizeTool
|
|
|
5
5
|
import { ensureDir, sanitizePathComponent, writeThenLink } from "./fs-atomic.js";
|
|
6
6
|
import { guardCorruptSink } from "./corrupt-read-sink.js";
|
|
7
7
|
import { assertAdoptionBootGate } from "./adoption/marker.js";
|
|
8
|
+
import { receiveOptions } from "../../core/own-property-receipt.js";
|
|
8
9
|
export class FileToolResultStore {
|
|
9
10
|
dir;
|
|
10
11
|
discloseCorrupt;
|
|
11
|
-
constructor(root,
|
|
12
|
+
constructor(root, options) {
|
|
13
|
+
const opts = receiveOptions(options, "FileToolResultStore");
|
|
12
14
|
assertAdoptionBootGate(root, "FileToolResultStore");
|
|
13
15
|
this.dir = join(root, "tool-results");
|
|
14
16
|
this.discloseCorrupt = guardCorruptSink(opts?.onCorruptRead);
|
|
@@ -98,7 +100,7 @@ export class FileToolResultStore {
|
|
|
98
100
|
}
|
|
99
101
|
writeOwnerFile(ref, provenance) {
|
|
100
102
|
try {
|
|
101
|
-
writeThenLink(this.ownerPathFor(ref), JSON.stringify(normalizeToolResultProvenance(provenance)));
|
|
103
|
+
writeThenLink(this.ownerPathFor(ref), JSON.stringify({ ...normalizeToolResultProvenance(provenance), ref }));
|
|
102
104
|
}
|
|
103
105
|
catch (err) {
|
|
104
106
|
if (err.code !== "EEXIST")
|
|
@@ -179,10 +181,71 @@ export class FileToolResultStore {
|
|
|
179
181
|
}
|
|
180
182
|
return { deleted, unattributable };
|
|
181
183
|
}
|
|
184
|
+
listBySession(sessionId) {
|
|
185
|
+
const entries = [];
|
|
186
|
+
let unattributable = 0;
|
|
187
|
+
let unaddressable = 0;
|
|
188
|
+
for (const dir of [this.dir, join(this.dir, FOLDED_SUBDIR)]) {
|
|
189
|
+
let names;
|
|
190
|
+
try {
|
|
191
|
+
names = readdirSync(dir);
|
|
192
|
+
}
|
|
193
|
+
catch (err) {
|
|
194
|
+
if (err.code === "ENOENT")
|
|
195
|
+
continue;
|
|
196
|
+
throw err;
|
|
197
|
+
}
|
|
198
|
+
const listed = new Set(names);
|
|
199
|
+
for (const name of names) {
|
|
200
|
+
if (!name.endsWith(OWNER_SUFFIX))
|
|
201
|
+
continue;
|
|
202
|
+
const owner = readOwnerFileAt(join(dir, name));
|
|
203
|
+
if (owner === "gone")
|
|
204
|
+
continue;
|
|
205
|
+
if (owner === "damaged") {
|
|
206
|
+
unattributable++;
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (owner.provenance.sessionId !== sessionId)
|
|
210
|
+
continue;
|
|
211
|
+
const stem = name.slice(0, -OWNER_SUFFIX.length);
|
|
212
|
+
const ref = this.refOfEntry(dir, stem, owner.ref);
|
|
213
|
+
if (ref === undefined)
|
|
214
|
+
unaddressable++;
|
|
215
|
+
else
|
|
216
|
+
entries.push({ ref, provenance: owner.provenance });
|
|
217
|
+
}
|
|
218
|
+
for (const name of names) {
|
|
219
|
+
if (!name.endsWith(CONTENT_SUFFIX))
|
|
220
|
+
continue;
|
|
221
|
+
if (listed.has(`${name.slice(0, -CONTENT_SUFFIX.length)}${OWNER_SUFFIX}`))
|
|
222
|
+
continue;
|
|
223
|
+
unattributable++;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return { entries, unattributable, unaddressable };
|
|
227
|
+
}
|
|
228
|
+
refOfEntry(dir, stem, stated) {
|
|
229
|
+
const lies = (ref) => {
|
|
230
|
+
try {
|
|
231
|
+
const at = this.locate(ref);
|
|
232
|
+
return at.dir === dir && at.stem === stem;
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
if (stated !== undefined)
|
|
239
|
+
return lies(stated) ? stated : undefined;
|
|
240
|
+
return dir === this.dir && lies(stem) ? stem : undefined;
|
|
241
|
+
}
|
|
182
242
|
}
|
|
183
243
|
const CONTENT_SUFFIX = ".txt";
|
|
184
244
|
const OWNER_SUFFIX = ".owner.json";
|
|
185
245
|
function parseOwnerRecord(raw) {
|
|
246
|
+
return parseOwnerFile(raw)?.provenance;
|
|
247
|
+
}
|
|
248
|
+
function parseOwnerFile(raw) {
|
|
186
249
|
const parsed = (() => {
|
|
187
250
|
try {
|
|
188
251
|
return JSON.parse(raw);
|
|
@@ -192,14 +255,15 @@ function parseOwnerRecord(raw) {
|
|
|
192
255
|
}
|
|
193
256
|
})();
|
|
194
257
|
if (typeof parsed === "object" && parsed !== null) {
|
|
195
|
-
const { sessionId, taskId } = parsed;
|
|
258
|
+
const { sessionId, taskId, ref } = parsed;
|
|
196
259
|
if (typeof sessionId === "string" && (taskId === undefined || typeof taskId === "string")) {
|
|
197
|
-
|
|
260
|
+
const provenance = taskId === undefined ? { sessionId } : { sessionId, taskId };
|
|
261
|
+
return typeof ref === "string" ? { provenance, ref } : { provenance };
|
|
198
262
|
}
|
|
199
263
|
}
|
|
200
264
|
return undefined;
|
|
201
265
|
}
|
|
202
|
-
function
|
|
266
|
+
function readOwnerFileAt(path) {
|
|
203
267
|
let raw;
|
|
204
268
|
try {
|
|
205
269
|
raw = readFileSync(path, "utf8");
|
|
@@ -207,7 +271,11 @@ function readOwnerAt(path) {
|
|
|
207
271
|
catch (err) {
|
|
208
272
|
return err.code === "ENOENT" ? "gone" : "damaged";
|
|
209
273
|
}
|
|
210
|
-
return
|
|
274
|
+
return parseOwnerFile(raw) ?? "damaged";
|
|
275
|
+
}
|
|
276
|
+
function readOwnerAt(path) {
|
|
277
|
+
const read = readOwnerFileAt(path);
|
|
278
|
+
return typeof read === "string" ? read : read.provenance;
|
|
211
279
|
}
|
|
212
280
|
function unlinkIfAbsentOk(path) {
|
|
213
281
|
try {
|
|
@@ -25,7 +25,7 @@ export interface FileUsageWindowStoreOptions {
|
|
|
25
25
|
export declare class FileUsageWindowStore implements UsageWindowStore {
|
|
26
26
|
private readonly dir;
|
|
27
27
|
private readonly onCorruptRead;
|
|
28
|
-
constructor(root: string,
|
|
28
|
+
constructor(root: string, options?: FileUsageWindowStoreOptions);
|
|
29
29
|
/** key → a safe, INJECTIVE filename (`sanitizeScope` appends the full sha256 of the raw key, so two
|
|
30
30
|
* distinct principals can never share a ledger file). */
|
|
31
31
|
private pathFor;
|
|
@@ -3,11 +3,13 @@ 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
7
|
import { guardCorruptSink } from "./corrupt-read-sink.js";
|
|
7
8
|
export class FileUsageWindowStore {
|
|
8
9
|
dir;
|
|
9
10
|
onCorruptRead;
|
|
10
|
-
constructor(root,
|
|
11
|
+
constructor(root, options) {
|
|
12
|
+
const opts = receiveOptions(options, "FileUsageWindowStore");
|
|
11
13
|
assertAdoptionBootGate(root, "FileUsageWindowStore");
|
|
12
14
|
this.dir = join(root, "usage-windows");
|
|
13
15
|
ensureDir(this.dir);
|
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
import { type WorkflowJournalEntry, type WorkflowJournalStore, type ResumeClaimArgs } from "../../core/workflow-journal-store.js";
|
|
2
2
|
import { type CorruptReadInfo } from "./corrupt-read-sink.js";
|
|
3
|
-
/**
|
|
4
|
-
* SVC-2 — the shared size bound for a journaled workflow-agent entry, so ALL backends answer an oversize
|
|
5
|
-
* TaskResult with the SAME refusal (no dialect divergence). Inlined from service's `workflow-journal-limits` on
|
|
6
|
-
* onboarding — the 5 MiB figure aligns with TiDB's ~6 MiB per-row txn-entry-size-limit (a row over it is
|
|
7
|
-
* REJECTED with "entry too large"). PostgreSQL TEXT has no such low limit, so without a shared bound the same
|
|
8
|
-
* large entry would journal on PG and fail on TiDB; the shared bound makes every backend refuse at the same
|
|
9
|
-
* byte and with the same code (`workflow.journal_oversize`) before the row reaches the medium. Measured in
|
|
10
|
-
* BYTES (UTF-8) — a multibyte result can be larger than its `.length` in chars.
|
|
11
|
-
*/
|
|
12
|
-
export { MAX_JOURNAL_RESULT_BYTES, oversizeJournalResult } from "../../core/workflow-journal-store.js";
|
|
13
3
|
/**
|
|
14
4
|
* RB-242 — how long a resume claim survives WITHOUT an engine release. This is the backstop for an engine that
|
|
15
5
|
* died holding one (crash / kill -9 / box reboot): it never reaches its `finally`, so nothing but expiry can
|
|
@@ -74,7 +64,7 @@ export declare class FileWorkflowJournalStore implements WorkflowJournalStore {
|
|
|
74
64
|
private get scopes();
|
|
75
65
|
/** The swallow-guarded corrupt-read seat (undefined = the old silent tolerance). */
|
|
76
66
|
private readonly discloseCorrupt;
|
|
77
|
-
constructor(root: string, fsyncEnabled?: boolean,
|
|
67
|
+
constructor(root: string, fsyncEnabled?: boolean, options?: FileWorkflowJournalStoreOptions);
|
|
78
68
|
private pathFor;
|
|
79
69
|
/** CC local form: the run's on-disk journal path for the notification diagnostics line.
|
|
80
70
|
* Traversal-shaped ids (LLM-controlled on some paths) degrade to undefined, never throw. */
|
|
@@ -6,8 +6,8 @@ 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
10
|
import { assertJournalEntryFits } from "../../core/workflow-journal-store.js";
|
|
10
|
-
export { MAX_JOURNAL_RESULT_BYTES, oversizeJournalResult } 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;
|
|
13
13
|
export const RESUME_CLAIM_SWEEP_INTERVAL_MS = 60_000;
|
|
@@ -33,8 +33,9 @@ export class FileWorkflowJournalStore {
|
|
|
33
33
|
return this.shared.scopes;
|
|
34
34
|
}
|
|
35
35
|
discloseCorrupt;
|
|
36
|
-
constructor(root, fsyncEnabled = true,
|
|
36
|
+
constructor(root, fsyncEnabled = true, options) {
|
|
37
37
|
this.fsyncEnabled = fsyncEnabled;
|
|
38
|
+
const opts = receiveOptions(options, "FileWorkflowJournalStore");
|
|
38
39
|
this.discloseCorrupt = guardCorruptSink(opts?.onCorruptRead);
|
|
39
40
|
assertAdoptionBootGate(root, "FileWorkflowJournalStore");
|
|
40
41
|
this.dir = join(root, "workflow-journal");
|
|
@@ -77,6 +77,11 @@ export interface ContainmentFaceInputs {
|
|
|
77
77
|
* reaches anyway" does not hold, so no implicit default may open it).
|
|
78
78
|
* 5. default: ROOTS — the engine never opens implicitly.
|
|
79
79
|
*
|
|
80
|
+
* A face is a DEPLOYMENT's trust statement, never an execution environment's capability: no declaration of the
|
|
81
|
+
* environment (a sandbox's `isolation` included) enters this order, so every lane's default is ROOTS, and a lane that is to
|
|
82
|
+
* read open says so at a seat allowed to open — the deployment seat in force for its run, or the task seat where no
|
|
83
|
+
* organization governance is declared; under governance only the deployment seat opens.
|
|
84
|
+
*
|
|
80
85
|
* @contract fs.containment_face.seat_independence — the two containment seats never read each other:
|
|
81
86
|
* each band passes its OWN resolved value into the shared containment step, a seat nobody declared
|
|
82
87
|
* resolves to "roots" on its own, and no gate other than that step is touched by either word. A
|
|
@@ -33,11 +33,20 @@ export interface DecodedTextFile {
|
|
|
33
33
|
* BACK across the entire file, so sampling a prefix is exactly the case where the cheap answer
|
|
34
34
|
* flips the remaining 99% of the lines. */
|
|
35
35
|
endings: DetectedLineEndings;
|
|
36
|
-
/**
|
|
37
|
-
*
|
|
38
|
-
|
|
39
|
-
malformed?: true;
|
|
36
|
+
/** The body cannot be written back byte for byte ({@link MalformedBody}). Flagged so the tool layer fails closed instead
|
|
37
|
+
* of "repairing" the file. */
|
|
38
|
+
malformed?: MalformedBody;
|
|
40
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Why a decoded body cannot be written back byte for byte — the one fact every write lane (Edit, Write onto an existing file,
|
|
42
|
+
* NotebookEdit) refuses on:
|
|
43
|
+
* - `truncated_utf16`: a utf16le body with an ODD byte count is truncated/corrupt — decoding drops the dangling byte and a
|
|
44
|
+
* write-back would destroy it permanently (Read refuses it too: the text itself is incomplete);
|
|
45
|
+
* - `not_utf8`: a body read as UTF-8 (with or without its BOM) that is not valid UTF-8 — an older encoding such as
|
|
46
|
+
* Windows-1252, Shift-JIS or GBK, or binary. Its undecodable bytes decode to U+FFFD, and writing the text back would
|
|
47
|
+
* replace every one of them with U+FFFD (Read shows the decoded text as it is).
|
|
48
|
+
*/
|
|
49
|
+
export type MalformedBody = "truncated_utf16" | "not_utf8";
|
|
41
50
|
/** BOM-only encoding detection (CC `detectEncodingForResolvedPath` parity — no content heuristics). */
|
|
42
51
|
export declare function detectFileEncoding(bytes: Uint8Array): DetectedFileEncoding;
|
|
43
52
|
/** Decode file bytes into the model-facing normalized form + the metadata needed to write back losslessly. */
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
const STRICT_UTF8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
2
|
+
function isValidUtf8(body) {
|
|
3
|
+
try {
|
|
4
|
+
STRICT_UTF8.decode(body);
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
1
11
|
export function detectFileEncoding(bytes) {
|
|
2
12
|
if (bytes.length >= 2 && bytes[0] === 0xff && bytes[1] === 0xfe)
|
|
3
13
|
return { encoding: "utf16le", hadBom: true };
|
|
@@ -23,8 +33,13 @@ export function decodeTextBytes(bytes) {
|
|
|
23
33
|
const body = encoding.hadBom ? bytes.subarray(encoding.encoding === "utf16le" ? 2 : 3) : bytes;
|
|
24
34
|
const raw = Buffer.from(body).toString(encoding.encoding);
|
|
25
35
|
const decoded = { text: raw.replaceAll("\r\n", "\n"), encoding, endings: detectLineEndings(raw) };
|
|
26
|
-
if (encoding.encoding === "utf16le"
|
|
27
|
-
|
|
36
|
+
if (encoding.encoding === "utf16le") {
|
|
37
|
+
if (body.length % 2 !== 0)
|
|
38
|
+
decoded.malformed = "truncated_utf16";
|
|
39
|
+
}
|
|
40
|
+
else if (raw.includes("�") && !isValidUtf8(body)) {
|
|
41
|
+
decoded.malformed = "not_utf8";
|
|
42
|
+
}
|
|
28
43
|
return decoded;
|
|
29
44
|
}
|
|
30
45
|
export function encodeTextForFile(text, encoding, endings) {
|
|
@@ -14,3 +14,10 @@
|
|
|
14
14
|
* (its own leg says so in a comment), so the sentence it gets must be the same string, not a second copy.
|
|
15
15
|
*/
|
|
16
16
|
export declare function backgroundLifetimeNote(retained: boolean, sessionScoped: boolean, envIsolatedOwned: boolean, face?: "receipt" | "description"): string;
|
|
17
|
+
/**
|
|
18
|
+
* The one sentence a background COMMAND's receipt carries in a one-shot submission (e.g. headless `-p`): the submission's
|
|
19
|
+
* ending waits for the completion of loop-type background tasks (agents, workflows) only — a command's lifetime is its
|
|
20
|
+
* process's, which may never end (a server, `tail -f`), so it is not waited for and its completion may never be heard.
|
|
21
|
+
* ONE construction point for both background legs (run_in_background and an adopted command).
|
|
22
|
+
*/
|
|
23
|
+
export declare const ONE_SHOT_BACKGROUND_COMMAND_NOTE = "This is a one-shot submission \u2014 the engine does not wait for background commands; run it in the foreground (with a timeout) if you need its output before the submission ends.";
|
|
@@ -20,3 +20,4 @@ export function backgroundLifetimeNote(retained, sessionScoped, envIsolatedOwned
|
|
|
20
20
|
return ` Background processes do NOT survive the session — they are reaped ${bgReapClause(sessionScoped, envIsolatedOwned)}. A deliverable that must stay alive afterwards (a server, a daemon) needs a self-detaching FOREGROUND start instead: run \`nohup cmd >log 2>&1 &\` as a normal foreground command (portable; setsid does not exist on macOS), or use a service manager${bgNohupCaveat(envIsolatedOwned)}.`;
|
|
21
21
|
return ` NOTE: background processes do NOT survive the session (reaped ${bgReapClause(sessionScoped, envIsolatedOwned)}). If this is a deliverable service that must stay alive afterwards, host it with a FOREGROUND command instead: \`nohup cmd >log 2>&1 &\` (self-detaching — survives the session)${bgNohupCaveat(envIsolatedOwned)}.`;
|
|
22
22
|
}
|
|
23
|
+
export const ONE_SHOT_BACKGROUND_COMMAND_NOTE = "This is a one-shot submission — the engine does not wait for background commands; run it in the foreground (with a timeout) if you need its output before the submission ends.";
|