@sema-agent/core 7.66.0 → 7.67.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 +3498 -0
- package/LICENSE +2 -1
- package/dist/agents/agent-definition.js +2 -1
- package/dist/agents/agent-transcript-tool.d.ts +1 -1
- package/dist/agents/agent-transcript-tool.js +4 -3
- package/dist/agents/builtin-agents.d.ts +10 -7
- package/dist/agents/builtin-agents.js +1 -0
- package/dist/agents/cascade.d.ts +24 -11
- package/dist/agents/cascade.js +21 -9
- package/dist/agents/child-failure.d.ts +30 -0
- package/dist/agents/child-failure.js +25 -1
- package/dist/agents/composition-placement.d.ts +6 -2
- package/dist/agents/composition-placement.js +7 -3
- package/dist/agents/cross-session-envelope.d.ts +10 -1
- package/dist/agents/cross-session-envelope.js +6 -2
- package/dist/agents/cross-session-judge.d.ts +7 -1
- package/dist/agents/cross-session-judge.js +1 -0
- package/dist/agents/cumulative-stats.d.ts +36 -2
- package/dist/agents/cumulative-stats.js +44 -9
- package/dist/agents/delegation-registry-seat.js +2 -3
- package/dist/agents/inherited-tool-pool.d.ts +9 -4
- package/dist/agents/inherited-tool-pool.js +7 -1
- package/dist/agents/leg-label.d.ts +28 -0
- package/dist/agents/leg-label.js +9 -0
- package/dist/agents/list-agents-tool.d.ts +1 -1
- package/dist/agents/list-agents-tool.js +4 -4
- package/dist/agents/org-delivery-gate.d.ts +129 -23
- package/dist/agents/org-delivery-gate.js +41 -20
- package/dist/agents/peer-held-queue.d.ts +15 -10
- package/dist/agents/peer-held-queue.js +47 -19
- package/dist/agents/peer-notice-route.js +2 -2
- package/dist/agents/peer-notices.d.ts +13 -2
- package/dist/agents/peer-notices.js +12 -2
- package/dist/agents/peer-session-drain.d.ts +65 -15
- package/dist/agents/peer-session-drain.js +198 -41
- package/dist/agents/read-inbox-tool.d.ts +3 -2
- package/dist/agents/read-inbox-tool.js +7 -5
- package/dist/agents/repair-loop.js +20 -16
- package/dist/agents/retain-ledger.d.ts +1 -1
- package/dist/agents/retain-ledger.js +2 -4
- package/dist/agents/root-session-lane.d.ts +27 -0
- package/dist/agents/root-session-lane.js +57 -0
- package/dist/agents/roster-store.js +1 -2
- package/dist/agents/send-message-tool.js +6 -4
- package/dist/agents/subagent.d.ts +20 -4
- package/dist/agents/subagent.js +218 -183
- package/dist/agents/tool-filter.d.ts +3 -10
- package/dist/agents/tool-filter.js +0 -13
- package/dist/agents/verifier-independence.d.ts +31 -0
- package/dist/agents/verifier-independence.js +23 -0
- package/dist/agents/verify.d.ts +23 -11
- package/dist/agents/verify.js +28 -12
- package/dist/agents/yield-adoption.d.ts +24 -0
- package/dist/agents/yield-adoption.js +84 -0
- package/dist/bench/metrics.d.ts +2 -2
- package/dist/brain/anthropic.d.ts +4 -2
- package/dist/brain/anthropic.js +49 -35
- package/dist/brain/brain-faces.d.ts +11 -0
- package/dist/brain/brain-faces.js +6 -0
- package/dist/brain/cache-retention.d.ts +2 -0
- package/dist/brain/cache-retention.js +9 -0
- package/dist/brain/circuit-breaker.js +51 -26
- package/dist/brain/errors.d.ts +15 -1
- package/dist/brain/errors.js +8 -0
- package/dist/brain/failover.d.ts +6 -0
- package/dist/brain/failover.js +52 -37
- package/dist/brain/media-degrade.d.ts +5 -0
- package/dist/brain/media-degrade.js +4 -0
- package/dist/brain/model-capability.d.ts +2 -1
- package/dist/brain/model-lane.d.ts +145 -0
- package/dist/brain/model-lane.js +444 -0
- package/dist/brain/open-responses.js +19 -22
- package/dist/brain/openai.js +23 -22
- package/dist/brain/provider-message.d.ts +9 -0
- package/dist/brain/provider-message.js +18 -0
- package/dist/brain/reasoning-request.d.ts +9 -7
- package/dist/brain/reasoning-request.js +9 -10
- package/dist/brain/reasoning.d.ts +47 -13
- package/dist/brain/reasoning.js +20 -10
- package/dist/brain/route-adjudicator.d.ts +8 -2
- package/dist/brain/route-adjudicator.js +35 -1
- package/dist/brain/route-conformance.js +17 -0
- package/dist/brain/routing.d.ts +2 -0
- package/dist/brain/routing.js +19 -8
- package/dist/brain/status-sink.d.ts +5 -4
- package/dist/brain/status-sink.js +2 -2
- package/dist/brain/stream-engine.js +8 -2
- package/dist/brain/stream-shared.d.ts +12 -0
- package/dist/brain/stream-shared.js +18 -0
- package/dist/brain/timeout.d.ts +28 -0
- package/dist/brain/timeout.js +13 -4
- package/dist/brain/tool-schema-projection.d.ts +2 -0
- package/dist/brain/tool-schema-projection.js +108 -0
- package/dist/brain/usage-reading.d.ts +49 -0
- package/dist/brain/usage-reading.js +44 -0
- package/dist/brain/usage-reasoning.d.ts +38 -0
- package/dist/brain/usage-reasoning.js +9 -0
- package/dist/config/catalog.d.ts +3 -0
- package/dist/config/catalog.js +18 -9
- package/dist/core/a2a.d.ts +22 -4
- package/dist/core/a2a.js +191 -50
- package/dist/core/agent-definition.d.ts +3 -1
- package/dist/core/agent-state.d.ts +29 -16
- package/dist/core/agent-state.js +36 -9
- package/dist/core/allow-entry.d.ts +12 -3
- package/dist/core/allow-entry.js +10 -3
- package/dist/core/approval-display.d.ts +18 -0
- package/dist/core/approval-display.js +26 -0
- package/dist/core/approval-object.js +2 -2
- package/dist/core/approval-route.d.ts +16 -0
- package/dist/core/approval-route.js +5 -0
- package/dist/core/approval-words.d.ts +43 -0
- package/dist/core/approval-words.js +37 -0
- package/dist/core/ask-origin.d.ts +37 -10
- package/dist/core/ask-origin.js +19 -7
- package/dist/core/ask-question.d.ts +36 -8
- package/dist/core/ask-question.js +24 -9
- package/dist/core/ask-unresolvable-notice.d.ts +3 -2
- package/dist/core/ask-unresolvable-notice.js +3 -2
- package/dist/core/attachment-source.d.ts +50 -0
- package/dist/core/attachment-source.js +46 -0
- package/dist/core/auto-compaction.d.ts +151 -40
- package/dist/core/auto-compaction.js +115 -50
- package/dist/core/auto-mode.d.ts +5 -0
- package/dist/core/auto-mode.js +11 -4
- package/dist/core/background-agent-store.d.ts +151 -23
- package/dist/core/background-agent-store.js +201 -61
- package/dist/core/background-shell.d.ts +4 -1
- package/dist/core/background-shell.js +1 -0
- package/dist/core/cache-break-detector.d.ts +49 -25
- package/dist/core/cache-break-detector.js +99 -44
- package/dist/core/caller-text.d.ts +28 -0
- package/dist/core/caller-text.js +12 -0
- package/dist/core/canonical-json.d.ts +5 -0
- package/dist/core/canonical-json.js +7 -0
- package/dist/core/checkpoint-features.d.ts +80 -9
- package/dist/core/checkpoint-features.js +1 -1
- package/dist/core/checkpoint-generation.d.ts +8 -1
- package/dist/core/checkpoint-generation.js +3 -0
- package/dist/core/checkpoint-queries.d.ts +47 -14
- package/dist/core/checkpoint-queries.js +63 -30
- package/dist/core/checkpoint-requirements.d.ts +36 -3
- package/dist/core/checkpoint-requirements.js +11 -1
- package/dist/core/checkpoint-row-verdict.d.ts +0 -2
- package/dist/core/checkpoint-row-verdict.js +5 -8
- package/dist/core/checkpoint-store.d.ts +166 -41
- package/dist/core/checkpoint-store.js +96 -15
- package/dist/core/child-clamp-seats.d.ts +10 -2
- package/dist/core/child-clamp-seats.js +2 -2
- package/dist/core/classifier-unavailable-arm.d.ts +11 -9
- package/dist/core/classifier-unavailable-arm.js +4 -2
- package/dist/core/command-sandbox-dispatch.d.ts +13 -0
- package/dist/core/command-sandbox-dispatch.js +8 -0
- package/dist/core/command-sandbox.d.ts +231 -0
- package/dist/core/command-sandbox.js +344 -0
- package/dist/core/completion-id.d.ts +21 -0
- package/dist/core/completion-id.js +14 -0
- package/dist/core/config-refusal-codes.d.ts +22 -0
- package/dist/core/config-refusal-codes.js +196 -0
- package/dist/core/context-edit.d.ts +26 -0
- package/dist/core/context-edit.js +4 -2
- package/dist/core/context-guard.d.ts +80 -7
- package/dist/core/context-guard.js +126 -25
- package/dist/core/context-settings.d.ts +32 -0
- package/dist/core/context-settings.js +41 -3
- package/dist/core/contract-faces.d.ts +22 -0
- package/dist/core/contract-faces.js +1 -0
- package/dist/core/credential-echo.d.ts +2 -2
- package/dist/core/credential-echo.js +2 -2
- package/dist/core/cross-boundary-taint.d.ts +10 -8
- package/dist/core/decision-receipt.d.ts +3 -2
- package/dist/core/decision-receipt.js +1 -1
- package/dist/core/definition-entry-grammar.d.ts +42 -0
- package/dist/core/definition-entry-grammar.js +15 -0
- package/dist/core/engine-attestation.d.ts +19 -4
- package/dist/core/engine-attestation.js +4 -0
- package/dist/core/engine-capabilities.d.ts +8 -1
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-contracts/open-face-contract.d.ts +39 -0
- package/dist/core/engine-contracts/open-face-contract.js +57 -0
- package/dist/core/engine-notice.d.ts +161 -33
- package/dist/core/exclusive-temp.d.ts +25 -0
- package/dist/core/exclusive-temp.js +19 -0
- package/dist/core/existing-target.d.ts +112 -0
- package/dist/core/existing-target.js +88 -0
- package/dist/core/file-history-store.d.ts +14 -6
- package/dist/core/gate-lanes.js +8 -3
- package/dist/core/gate-outcome.d.ts +2 -1
- package/dist/core/git-worktree-env.d.ts +92 -1
- package/dist/core/git-worktree-env.js +87 -6
- package/dist/core/governance-codes.d.ts +49 -8
- package/dist/core/governance-codes.js +59 -8
- package/dist/core/hands-band.d.ts +10 -6
- package/dist/core/hooks.d.ts +60 -6
- package/dist/core/hooks.js +10 -2
- package/dist/core/host-floor.d.ts +24 -8
- package/dist/core/host-floor.js +45 -16
- package/dist/core/human-input-projection.d.ts +7 -0
- package/dist/core/human-input-projection.js +11 -3
- package/dist/core/image-admission.d.ts +16 -4
- package/dist/core/image-admission.js +29 -17
- package/dist/core/input-author.d.ts +43 -1
- package/dist/core/input-author.js +19 -0
- package/dist/core/isolation-scope.d.ts +41 -0
- package/dist/core/isolation-scope.js +10 -0
- package/dist/core/json-schema-seats.d.ts +11 -0
- package/dist/core/json-schema-seats.js +5 -0
- package/dist/core/leg-identity.d.ts +53 -5
- package/dist/core/leg-identity.js +32 -1
- package/dist/core/locked-config.d.ts +33 -38
- package/dist/core/locked-config.js +21 -3
- package/dist/core/lsp.js +2 -1
- package/dist/core/mailbox-store.d.ts +111 -18
- package/dist/core/mailbox-store.js +101 -13
- package/dist/core/mcp-call-meta.js +1 -1
- package/dist/core/mcp-connection-pool.d.ts +8 -2
- package/dist/core/mcp-connection-pool.js +3 -1
- package/dist/core/mcp-failure.d.ts +6 -1
- package/dist/core/mcp-failure.js +10 -0
- package/dist/core/mcp-host-read.d.ts +293 -0
- package/dist/core/mcp-host-read.js +428 -0
- package/dist/core/mcp-server-link.d.ts +28 -6
- package/dist/core/mcp-server-link.js +35 -7
- package/dist/core/mcp-server-spec.d.ts +22 -29
- package/dist/core/mcp-server-spec.js +7 -14
- package/dist/core/mcp-server-unavailable-notice.d.ts +32 -0
- package/dist/core/mcp-server-unavailable-notice.js +15 -0
- package/dist/core/mcp-session-end.d.ts +5 -2
- package/dist/core/mcp-session-end.js +7 -2
- package/dist/core/mcp-tool-meta.d.ts +6 -0
- package/dist/core/mcp-tool-meta.js +1 -0
- package/dist/core/mcp.d.ts +54 -19
- package/dist/core/mcp.js +194 -241
- package/dist/core/memory-engine/committed-shadow-read.d.ts +16 -0
- package/dist/core/memory-engine/committed-shadow-read.js +21 -0
- package/dist/core/memory-engine/consolidation-driver.js +2 -1
- package/dist/core/memory-engine/consolidation.d.ts +3 -3
- package/dist/core/memory-engine/control-objects.d.ts +4 -3
- package/dist/core/memory-engine/control-objects.js +6 -4
- package/dist/core/memory-engine/delegation-settlement.d.ts +127 -25
- package/dist/core/memory-engine/delegation-settlement.js +145 -18
- package/dist/core/memory-engine/distiller.d.ts +2 -1
- package/dist/core/memory-engine/distiller.js +10 -5
- package/dist/core/memory-engine/dual-root.js +2 -2
- package/dist/core/memory-engine/engine.d.ts +127 -33
- package/dist/core/memory-engine/engine.js +774 -323
- package/dist/core/memory-engine/entry-scan.d.ts +3 -0
- package/dist/core/memory-engine/entry-scan.js +8 -0
- package/dist/core/memory-engine/export-bundle.d.ts +4 -0
- package/dist/core/memory-engine/export-bundle.js +2 -0
- package/dist/core/memory-engine/file-backend.d.ts +62 -17
- package/dist/core/memory-engine/file-backend.js +155 -99
- package/dist/core/memory-engine/index.d.ts +1 -1
- package/dist/core/memory-engine/index.js +1 -1
- package/dist/core/memory-engine/layer-observations.d.ts +7 -1
- package/dist/core/memory-engine/layer-observations.js +6 -0
- package/dist/core/memory-engine/layout.d.ts +88 -26
- package/dist/core/memory-engine/layout.js +105 -29
- package/dist/core/memory-engine/memory-deployment.js +4 -4
- package/dist/core/memory-engine/mount-failed-notice.d.ts +24 -0
- package/dist/core/memory-engine/mount-failed-notice.js +22 -0
- package/dist/core/memory-engine/origin-clearance.d.ts +15 -1
- package/dist/core/memory-engine/origin-clearance.js +30 -10
- package/dist/core/memory-engine/scan.js +1 -1
- package/dist/core/memory-engine/scope-contract.js +4 -3
- package/dist/core/memory-engine/session-write-home.js +13 -1
- package/dist/core/memory-engine/sync-client.d.ts +1 -1
- package/dist/core/memory-engine/sync-client.js +3 -1
- package/dist/core/memory-engine/tools.d.ts +5 -4
- package/dist/core/memory-engine/tools.js +1 -1
- package/dist/core/memory-engine/types.d.ts +18 -1
- package/dist/core/memory-engine/types.js +1 -0
- package/dist/core/memory.d.ts +1 -1
- package/dist/core/memory.js +2 -6
- package/dist/core/mode-policy.d.ts +8 -1
- package/dist/core/mode-policy.js +6 -2
- package/dist/core/model-fallbacks.d.ts +103 -0
- package/dist/core/model-fallbacks.js +79 -0
- package/dist/core/model-receipt.d.ts +15 -3
- package/dist/core/model-receipt.js +22 -1
- package/dist/core/model-seat.d.ts +1 -1
- package/dist/core/mods/classic-events.d.ts +5 -1
- package/dist/core/mods/dollar.d.ts +47 -2
- package/dist/core/mods/dollar.js +28 -5
- package/dist/core/mods/kernel/budget.d.ts +6 -0
- package/dist/core/mods/kernel/budget.js +6 -0
- package/dist/core/mods/kernel/dispatch.d.ts +23 -2
- package/dist/core/mods/kernel/dispatch.js +104 -15
- package/dist/core/mods/kernel/events.d.ts +18 -1
- package/dist/core/mods/kernel/events.js +7 -6
- package/dist/core/mods/kernel/index.d.ts +2 -2
- package/dist/core/mods/kernel/index.js +1 -1
- package/dist/core/mods/kernel/receive.d.ts +2 -1
- package/dist/core/mods/lifecycle-stations.d.ts +13 -4
- package/dist/core/mods/lifecycle-stations.js +8 -3
- package/dist/core/mods/message-display.d.ts +81 -0
- package/dist/core/mods/message-display.js +369 -0
- package/dist/core/mods/prompt-submit.d.ts +1 -1
- package/dist/core/mods/prompt-submit.js +5 -2
- package/dist/core/mods/session-append.d.ts +2 -2
- package/dist/core/mods/session-append.js +2 -1
- package/dist/core/mods/session-compact.js +2 -2
- package/dist/core/mods/stations.d.ts +48 -18
- package/dist/core/mods/stations.js +100 -19
- package/dist/core/mods/stop-answers.d.ts +23 -0
- package/dist/core/mods/stop-answers.js +20 -0
- package/dist/core/mounted-mcp.d.ts +48 -8
- package/dist/core/mounted-mcp.js +82 -16
- package/dist/core/namespaced-rule-name.js +2 -1
- package/dist/core/own-property-receipt.js +3 -5
- package/dist/core/parent-spec-seat.d.ts +20 -1
- package/dist/core/parent-spec-seat.js +13 -3
- package/dist/core/park-selfcheck.js +1 -0
- package/dist/core/path-identity.js +2 -1
- package/dist/core/peer-seat.d.ts +21 -7
- package/dist/core/peer-seat.js +25 -16
- package/dist/core/permission-rule-consent.js +15 -5
- package/dist/core/permission-rule-model.d.ts +4 -2
- package/dist/core/permission-rule-model.js +43 -23
- package/dist/core/permission-rule-store.d.ts +31 -16
- package/dist/core/permission-rule-store.js +27 -18
- package/dist/core/present-plan-tool.d.ts +6 -1
- package/dist/core/present-plan-tool.js +11 -3
- package/dist/core/pricing.d.ts +8 -6
- package/dist/core/pricing.js +1 -1
- package/dist/core/principal-name.d.ts +13 -0
- package/dist/core/principal-name.js +9 -2
- package/dist/core/process-identity.d.ts +140 -0
- package/dist/core/process-identity.js +215 -0
- package/dist/core/protocol-http-auth.d.ts +28 -6
- package/dist/core/protocol-http-auth.js +22 -5
- package/dist/core/protocol-naming.d.ts +7 -0
- package/dist/core/protocol-naming.js +12 -2
- package/dist/core/protocol-revocation.d.ts +72 -0
- package/dist/core/protocol-revocation.js +98 -0
- package/dist/core/protocol-table.d.ts +4 -4
- package/dist/core/protocol-table.js +3 -2
- package/dist/core/push-queue.d.ts +35 -2
- package/dist/core/push-queue.js +60 -4
- package/dist/core/read-only-shell.d.ts +19 -0
- package/dist/core/read-only-shell.js +38 -11
- package/dist/core/real-approval.d.ts +26 -0
- package/dist/core/real-approval.js +15 -0
- package/dist/core/redaction-marks.d.ts +6 -2
- package/dist/core/redaction-marks.js +3 -0
- package/dist/core/reminder-mint.d.ts +6 -0
- package/dist/core/reminder-mint.js +9 -8
- package/dist/core/remote-env.d.ts +31 -15
- package/dist/core/remote-env.js +29 -0
- package/dist/core/request-copy-projection.d.ts +51 -0
- package/dist/core/request-copy-projection.js +410 -0
- package/dist/core/resume-config-judge.d.ts +69 -0
- package/dist/core/resume-config-judge.js +78 -0
- package/dist/core/resume-startup-cause.d.ts +14 -4
- package/dist/core/resume-startup-cause.js +12 -2
- package/dist/core/retention-policy.js +2 -1
- package/dist/core/retention.d.ts +119 -24
- package/dist/core/retention.js +60 -16
- package/dist/core/retired-keys.d.ts +0 -10
- package/dist/core/retired-keys.js +2 -3
- package/dist/core/roles.d.ts +6 -0
- package/dist/core/roles.js +65 -4
- package/dist/core/row-shape.d.ts +149 -0
- package/dist/core/row-shape.js +184 -0
- package/dist/core/runner/advertised-writable-dirs.js +10 -9
- package/dist/core/runner/advisor-instructions.d.ts +11 -27
- package/dist/core/runner/advisor-instructions.js +18 -20
- package/dist/core/runner/advisor-tool.js +1 -0
- package/dist/core/runner/announce-once-ledger.js +4 -1
- package/dist/core/runner/approval-feedback.d.ts +17 -8
- package/dist/core/runner/approval-feedback.js +18 -13
- package/dist/core/runner/approver-defect-announcer.d.ts +17 -0
- package/dist/core/runner/approver-defect-announcer.js +22 -0
- package/dist/core/runner/assemble-result.d.ts +29 -14
- package/dist/core/runner/assemble-result.js +16 -25
- package/dist/core/runner/cache-hit-account.d.ts +77 -0
- package/dist/core/runner/cache-hit-account.js +46 -0
- package/dist/core/runner/call-hook-stations.d.ts +3 -2
- package/dist/core/runner/call-hook-stations.js +5 -4
- package/dist/core/runner/changed-files-scan.d.ts +43 -0
- package/dist/core/runner/changed-files-scan.js +34 -0
- package/dist/core/runner/checkpoint-scope.d.ts +33 -9
- package/dist/core/runner/checkpoint-scope.js +27 -1
- package/dist/core/runner/classifier-ladder.d.ts +2 -2
- package/dist/core/runner/classifier-ladder.js +18 -9
- package/dist/core/runner/clock-and-limits.d.ts +15 -4
- package/dist/core/runner/clock-and-limits.js +19 -1
- package/dist/core/runner/compact-session.js +84 -14
- package/dist/core/runner/compaction-call-options.d.ts +2 -29
- package/dist/core/runner/compaction-call-options.js +2 -9
- package/dist/core/runner/compaction-restate.d.ts +18 -2
- package/dist/core/runner/compaction-restate.js +36 -2
- package/dist/core/runner/construction-doors.js +8 -0
- package/dist/core/runner/context-room.d.ts +55 -0
- package/dist/core/runner/context-room.js +71 -0
- package/dist/core/runner/contracts.d.ts +313 -205
- package/dist/core/runner/conversation-segment.d.ts +49 -14
- package/dist/core/runner/conversation-segment.js +92 -19
- package/dist/core/runner/cross-boundary-lane.d.ts +4 -0
- package/dist/core/runner/cross-boundary-lane.js +9 -6
- package/dist/core/runner/decide-continuation.js +1 -1
- package/dist/core/runner/deferred-ask.d.ts +62 -0
- package/dist/core/runner/deferred-ask.js +44 -0
- package/dist/core/runner/delegation-owner.d.ts +19 -0
- package/dist/core/runner/delegation-owner.js +27 -1
- package/dist/core/runner/denial-limit-arms.d.ts +10 -6
- package/dist/core/runner/denial-limit-arms.js +13 -7
- package/dist/core/runner/env-capability-census.d.ts +1 -1
- package/dist/core/runner/file-history-request.js +2 -1
- package/dist/core/runner/file-history-restore.d.ts +16 -2
- package/dist/core/runner/file-history-restore.js +9 -1
- package/dist/core/runner/gate-exit.d.ts +18 -5
- package/dist/core/runner/gate-exit.js +26 -15
- package/dist/core/runner/git-status-frame.d.ts +26 -8
- package/dist/core/runner/git-status-frame.js +14 -9
- package/dist/core/runner/halt-attribution.d.ts +29 -12
- package/dist/core/runner/halt-attribution.js +38 -11
- package/dist/core/runner/image.js +3 -2
- package/dist/core/runner/initial-run-state.d.ts +1 -1
- package/dist/core/runner/initial-run-state.js +4 -4
- package/dist/core/runner/language-frame.d.ts +66 -0
- package/dist/core/runner/language-frame.js +76 -0
- package/dist/core/runner/leg-frame.d.ts +81 -0
- package/dist/core/runner/leg-frame.js +68 -0
- package/dist/core/runner/main-call-account.d.ts +34 -0
- package/dist/core/runner/main-call-account.js +50 -0
- package/dist/core/runner/mcp-redial.d.ts +9 -7
- package/dist/core/runner/mcp-redial.js +20 -21
- package/dist/core/runner/memory-consolidation-driver.d.ts +2 -0
- package/dist/core/runner/memory-consolidation-driver.js +5 -3
- package/dist/core/runner/messages-omitted-seat.d.ts +2 -0
- package/dist/core/runner/messages-omitted-seat.js +21 -0
- package/dist/core/runner/model-fallback-seat.d.ts +20 -0
- package/dist/core/runner/model-fallback-seat.js +43 -0
- package/dist/core/runner/model-lane-seat.d.ts +12 -0
- package/dist/core/runner/model-lane-seat.js +35 -0
- package/dist/core/runner/nested-memory-content.d.ts +33 -0
- package/dist/core/runner/nested-memory-content.js +171 -0
- package/dist/core/runner/nested-memory-lane.d.ts +181 -0
- package/dist/core/runner/nested-memory-lane.js +673 -0
- package/dist/core/runner/park-commit.d.ts +7 -0
- package/dist/core/runner/park-commit.js +3 -0
- package/dist/core/runner/prepare-advisor.d.ts +7 -9
- package/dist/core/runner/prepare-advisor.js +11 -5
- package/dist/core/runner/prepare-artifact.d.ts +1 -1
- package/dist/core/runner/prepare-artifact.js +8 -3
- package/dist/core/runner/prepare-ask-lane.d.ts +21 -3
- package/dist/core/runner/prepare-ask-lane.js +32 -28
- package/dist/core/runner/prepare-boundary-parks.d.ts +2 -2
- package/dist/core/runner/prepare-boundary-parks.js +21 -17
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +10 -2
- package/dist/core/runner/prepare-caps-and-workflow.js +24 -18
- package/dist/core/runner/prepare-config-doors.d.ts +51 -5
- package/dist/core/runner/prepare-config-doors.js +73 -73
- package/dist/core/runner/prepare-context-lane.d.ts +68 -3
- package/dist/core/runner/prepare-context-lane.js +137 -27
- package/dist/core/runner/prepare-defer-classify.d.ts +0 -4
- package/dist/core/runner/prepare-defer-classify.js +9 -13
- package/dist/core/runner/prepare-delegation-surface.d.ts +8 -8
- package/dist/core/runner/prepare-delegation-surface.js +72 -64
- package/dist/core/runner/prepare-execution-env.js +1 -9
- package/dist/core/runner/prepare-file-history.d.ts +3 -2
- package/dist/core/runner/prepare-file-history.js +11 -4
- package/dist/core/runner/prepare-gate-stations.d.ts +21 -11
- package/dist/core/runner/prepare-gate-stations.js +13 -13
- package/dist/core/runner/prepare-hands-readface.d.ts +23 -6
- package/dist/core/runner/prepare-hands-readface.js +18 -12
- package/dist/core/runner/prepare-inherited-gate.d.ts +12 -5
- package/dist/core/runner/prepare-inherited-gate.js +14 -10
- package/dist/core/runner/prepare-lsp.js +2 -1
- package/dist/core/runner/prepare-memory-engine-session.js +30 -10
- package/dist/core/runner/prepare-memory.d.ts +4 -0
- package/dist/core/runner/prepare-memory.js +38 -16
- package/dist/core/runner/prepare-offload-wrappers.d.ts +3 -16
- package/dist/core/runner/prepare-offload-wrappers.js +6 -5
- package/dist/core/runner/prepare-park-ask.d.ts +13 -3
- package/dist/core/runner/prepare-park-ask.js +25 -19
- package/dist/core/runner/prepare-policy-chain.d.ts +17 -3
- package/dist/core/runner/prepare-policy-chain.js +144 -120
- package/dist/core/runner/prepare-project-context.d.ts +15 -53
- package/dist/core/runner/prepare-project-context.js +20 -83
- package/dist/core/runner/prepare-prompt-assembly.d.ts +7 -1
- package/dist/core/runner/prepare-prompt-assembly.js +9 -7
- package/dist/core/runner/prepare-prompt-inputs.d.ts +9 -3
- package/dist/core/runner/prepare-prompt-inputs.js +5 -3
- package/dist/core/runner/prepare-protocol-tools.d.ts +9 -4
- package/dist/core/runner/prepare-protocol-tools.js +46 -27
- package/dist/core/runner/prepare-question-face.d.ts +7 -6
- package/dist/core/runner/prepare-question-face.js +7 -6
- package/dist/core/runner/prepare-suspend-saga.d.ts +3 -0
- package/dist/core/runner/prepare-suspend-saga.js +1 -1
- package/dist/core/runner/prepare-task.d.ts +3 -3
- package/dist/core/runner/prepare-task.js +113 -61
- package/dist/core/runner/prepare-tool-disclosure-mount.js +6 -5
- package/dist/core/runner/prepare-turn-wiring.d.ts +33 -7
- package/dist/core/runner/prepare-turn-wiring.js +53 -17
- package/dist/core/runner/prepare-wiring-manifest.d.ts +42 -5
- package/dist/core/runner/prepare-wiring-manifest.js +81 -42
- package/dist/core/runner/prepare-workspace-restore.js +3 -2
- package/dist/core/runner/read-root-grant.js +2 -1
- package/dist/core/runner/reply-pricing.d.ts +31 -18
- package/dist/core/runner/reply-pricing.js +10 -15
- package/dist/core/runner/resume-admission.js +10 -15
- package/dist/core/runner/resume-apply.js +20 -9
- package/dist/core/runner/resume-checkpoint-screen.js +2 -4
- package/dist/core/runner/resume-internals-and-config.d.ts +12 -9
- package/dist/core/runner/resume-internals-and-config.js +37 -9
- package/dist/core/runner/resume-preflight.js +3 -3
- package/dist/core/runner/retired-runner-deps.js +3 -0
- package/dist/core/runner/rewind-files.js +6 -6
- package/dist/core/runner/run-attachment-seats.d.ts +1 -3
- package/dist/core/runner/run-attachment-seats.js +1 -6
- package/dist/core/runner/run-brain-sinks.d.ts +4 -7
- package/dist/core/runner/run-brain-sinks.js +7 -10
- package/dist/core/runner/run-clock-and-content.d.ts +8 -5
- package/dist/core/runner/run-clock-and-content.js +18 -3
- package/dist/core/runner/run-compaction-machinery.d.ts +8 -4
- package/dist/core/runner/run-compaction-machinery.js +4 -19
- package/dist/core/runner/run-git-lane.d.ts +8 -3
- package/dist/core/runner/run-git-lane.js +5 -3
- package/dist/core/runner/run-harness-handlers.d.ts +4 -1
- package/dist/core/runner/run-harness-handlers.js +70 -45
- package/dist/core/runner/run-identity-wiring.d.ts +6 -0
- package/dist/core/runner/run-identity-wiring.js +17 -8
- package/dist/core/runner/run-leg.d.ts +5 -2
- package/dist/core/runner/run-leg.js +156 -71
- package/dist/core/runner/run-notification-lane.d.ts +1 -1
- package/dist/core/runner/run-notification-lane.js +22 -10
- package/dist/core/runner/run-recovery-lanes.js +8 -6
- package/dist/core/runner/run-settle-and-teardown.d.ts +4 -0
- package/dist/core/runner/run-settle-and-teardown.js +77 -26
- package/dist/core/runner/run-stop-and-final-verify.js +46 -12
- package/dist/core/runner/run-telemetry-and-budget-seats.js +13 -28
- package/dist/core/runner/run-terminal-adoption.d.ts +2 -2
- package/dist/core/runner/run-terminal-adoption.js +14 -9
- package/dist/core/runner/run-tool-mount-facts.js +5 -9
- package/dist/core/runner/run-turn-boundary.d.ts +3 -2
- package/dist/core/runner/run-turn-boundary.js +112 -106
- package/dist/core/runner/runtask.d.ts +28 -8
- package/dist/core/runner/runtask.js +132 -41
- package/dist/core/runner/session-file-state-replay.d.ts +5 -3
- package/dist/core/runner/session-file-state-replay.js +10 -3
- package/dist/core/runner/session-rule-policy.d.ts +3 -3
- package/dist/core/runner/session-verb-doors.d.ts +18 -3
- package/dist/core/runner/session-verb-doors.js +38 -6
- package/dist/core/runner/shell-env-withheld.d.ts +8 -5
- package/dist/core/runner/shell-env-withheld.js +4 -4
- package/dist/core/runner/side-call-account.d.ts +12 -8
- package/dist/core/runner/side-call-account.js +24 -15
- package/dist/core/runner/stream-halt-verbs.js +1 -0
- package/dist/core/runner/stream-mode-verb.js +2 -1
- package/dist/core/runner/stream-settle-backstop.js +4 -1
- package/dist/core/runner/stream-steer-verb.js +35 -19
- package/dist/core/runner/sub-agent-deny-lists.d.ts +47 -11
- package/dist/core/runner/sub-agent-deny-lists.js +140 -39
- package/dist/core/runner/teardown-bounded.d.ts +6 -0
- package/dist/core/runner/teardown-bounded.js +12 -7
- package/dist/core/runner/terminal-account.d.ts +2 -0
- package/dist/core/runner/terminal-account.js +6 -1
- package/dist/core/runner/tool-disclosure.js +2 -1
- package/dist/core/runner/tool-end-body.js +3 -1
- package/dist/core/runner/tool-face-overlay.d.ts +1 -1
- package/dist/core/runner/tool-face-overlay.js +1 -1
- package/dist/core/runner/tool-occurrence.d.ts +34 -9
- package/dist/core/runner/tool-occurrence.js +32 -21
- package/dist/core/runner/tool-progress-lane.d.ts +20 -5
- package/dist/core/runner/tool-progress-lane.js +27 -5
- package/dist/core/runner/tool-result-media-seat.d.ts +15 -4
- package/dist/core/runner/tool-result-media-seat.js +17 -1
- package/dist/core/runner/tool-table-view.js +1 -1
- package/dist/core/runner/turn-attachments.d.ts +44 -71
- package/dist/core/runner/turn-attachments.js +52 -104
- package/dist/core/runner/usage-accounting.d.ts +3 -2
- package/dist/core/runner/usage-accounting.js +3 -2
- package/dist/core/runner/void-verifier-pause.js +1 -1
- package/dist/core/runner-deps.d.ts +42 -158
- package/dist/core/runtime-caps.d.ts +16 -4
- package/dist/core/secret-env.d.ts +20 -3
- package/dist/core/secret-env.js +46 -23
- package/dist/core/sensitive-path-policy.d.ts +8 -0
- package/dist/core/sensitive-path-policy.js +10 -2
- package/dist/core/session-checkout.d.ts +32 -27
- package/dist/core/session-checkout.js +109 -61
- package/dist/core/session-log-transfer.js +2 -1
- package/dist/core/session-policy-store.d.ts +24 -11
- package/dist/core/session-policy-store.js +11 -2
- package/dist/core/session-store.d.ts +16 -2
- package/dist/core/session-store.js +43 -17
- package/dist/core/session.d.ts +31 -3
- package/dist/core/session.js +33 -2
- package/dist/core/shell-run-candidates.d.ts +20 -8
- package/dist/core/shell-run-candidates.js +44 -21
- package/dist/core/side-query.d.ts +17 -5
- package/dist/core/side-query.js +17 -14
- package/dist/core/skill-grant.js +2 -3
- package/dist/core/skills-directory.js +3 -66
- package/dist/core/snapshot-frame-seat.d.ts +8 -0
- package/dist/core/snapshot-frame-seat.js +24 -0
- package/dist/core/steer-replay.d.ts +19 -3
- package/dist/core/steer-replay.js +8 -1
- package/dist/core/store-contracts/background-agent-store-contract.d.ts +17 -2
- package/dist/core/store-contracts/background-agent-store-contract.js +131 -2
- package/dist/core/store-contracts/checkpoint-store-contract.js +63 -1
- package/dist/core/store-contracts/mailbox-store-contract.d.ts +15 -2
- package/dist/core/store-contracts/mailbox-store-contract.js +213 -3
- package/dist/core/store-contracts/permission-rule-write-contract.js +24 -0
- package/dist/core/store-contracts/session-deletion-cascade-contract.d.ts +15 -0
- package/dist/core/store-contracts/session-deletion-cascade-contract.js +288 -0
- package/dist/core/store-contracts/session-policy-store-contract.js +57 -36
- package/dist/core/store-contracts/session-repo-contract.js +130 -5
- package/dist/core/store-contracts/session-store-contract.d.ts +1 -1
- package/dist/core/store-contracts/session-store-contract.js +17 -0
- package/dist/core/store-contracts/task-list-store-contract.d.ts +32 -0
- package/dist/core/store-contracts/task-list-store-contract.js +240 -0
- package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
- package/dist/core/store-contracts/tool-result-store-contract.js +41 -0
- package/dist/core/stub-env.d.ts +2 -2
- package/dist/core/stub-env.js +1 -0
- package/dist/core/synthetic-read-verdict.d.ts +38 -28
- package/dist/core/synthetic-read-verdict.js +19 -28
- package/dist/core/task-event.d.ts +171 -19
- package/dist/core/task-intake.d.ts +26 -0
- package/dist/core/task-intake.js +31 -0
- package/dist/core/task-limits.d.ts +8 -6
- package/dist/core/task-notification.d.ts +88 -8
- package/dist/core/task-notification.js +45 -5
- package/dist/core/task-registry-agent.d.ts +24 -7
- package/dist/core/task-registry-agent.js +51 -28
- package/dist/core/task-registry-monitor.js +16 -14
- package/dist/core/task-registry-shared.d.ts +177 -35
- package/dist/core/task-registry-shared.js +44 -17
- package/dist/core/task-registry-workflow.js +8 -5
- package/dist/core/task-registry-yield.d.ts +32 -0
- package/dist/core/task-registry-yield.js +85 -0
- package/dist/core/task-registry.d.ts +88 -10
- package/dist/core/task-registry.js +124 -33
- package/dist/core/task-result.d.ts +115 -31
- package/dist/core/task-spec-members.d.ts +140 -1
- package/dist/core/task-spec-members.js +23 -8
- package/dist/core/task-spec.d.ts +181 -51
- package/dist/core/task-spec.js +1 -1
- package/dist/core/task-stream.d.ts +12 -2
- package/dist/core/terminal-cause.d.ts +12 -4
- package/dist/core/thrown-value.d.ts +49 -7
- package/dist/core/thrown-value.js +38 -2
- package/dist/core/tool-catalog-entries.js +13 -3
- package/dist/core/tool-data-door.d.ts +7 -0
- package/dist/core/tool-data-door.js +13 -0
- package/dist/core/tool-face-lists.d.ts +25 -0
- package/dist/core/tool-face-lists.js +38 -0
- package/dist/core/tool-face-reader.d.ts +0 -10
- package/dist/core/tool-face-reader.js +5 -3
- package/dist/core/tool-list-grammar.d.ts +103 -0
- package/dist/core/tool-list-grammar.js +130 -0
- package/dist/core/tool-mount-facts.d.ts +47 -0
- package/dist/core/tool-mount-facts.js +50 -0
- package/dist/core/tool-mount-plan.d.ts +196 -0
- package/dist/core/tool-mount-plan.js +404 -0
- package/dist/core/tool-mount-static.d.ts +12 -0
- package/dist/core/tool-mount-static.js +174 -0
- package/dist/core/tool-name-aliases.d.ts +60 -2
- package/dist/core/tool-name-aliases.js +22 -2
- package/dist/core/tool-name-list.d.ts +3 -0
- package/dist/core/tool-name-readings.d.ts +4 -0
- package/dist/core/tool-name-readings.js +1 -0
- package/dist/core/tool-policy.d.ts +246 -51
- package/dist/core/tool-policy.js +165 -71
- package/dist/core/tool-registry.d.ts +4 -11
- package/dist/core/tool-registry.js +0 -3
- package/dist/core/tool-result-bytes.d.ts +94 -0
- package/dist/core/tool-result-bytes.js +34 -0
- package/dist/core/tool-result-store.d.ts +97 -13
- package/dist/core/tool-result-store.js +52 -4
- package/dist/core/tool-roster.d.ts +71 -10
- package/dist/core/tool-roster.js +71 -21
- package/dist/core/tool-search-setting.d.ts +7 -9
- package/dist/core/tool-search-setting.js +23 -7
- package/dist/core/tool-spec.d.ts +32 -2
- package/dist/core/tools.js +6 -20
- package/dist/core/trace.d.ts +63 -11
- package/dist/core/trace.js +19 -0
- package/dist/core/types.d.ts +8 -6
- package/dist/core/types.js +3 -1
- package/dist/core/unmatched-tool-names.d.ts +37 -0
- package/dist/core/unmatched-tool-names.js +18 -0
- package/dist/core/untrusted-egress.d.ts +16 -5
- package/dist/core/untrusted-egress.js +202 -32
- package/dist/core/untrusted-text.d.ts +29 -8
- package/dist/core/untrusted-text.js +6 -3
- package/dist/core/user-attachment.d.ts +129 -35
- package/dist/core/user-attachment.js +124 -57
- package/dist/core/user-row-origin.d.ts +63 -0
- package/dist/core/user-row-origin.js +61 -0
- package/dist/core/wiring-manifest.d.ts +161 -39
- package/dist/core/wiring-manifest.js +42 -6
- package/dist/core/workflow-run-store-contract.d.ts +11 -1
- package/dist/core/workflow-run-store-contract.js +60 -7
- package/dist/core/workflow-run-store.d.ts +61 -12
- package/dist/core/workflow-run-store.js +100 -15
- package/dist/core/workspace-snapshot.d.ts +10 -14
- package/dist/core/workspace-snapshot.js +3 -22
- package/dist/core/write-protect.d.ts +3 -5
- package/dist/core/write-protect.js +2 -4
- package/dist/engine/compaction/compaction.d.ts +3 -0
- package/dist/engine/compaction/compaction.js +4 -3
- package/dist/engine/execution-env/node-execution-env.d.ts +15 -4
- package/dist/engine/execution-env/node-execution-env.js +80 -27
- package/dist/engine/harness/agent-harness.d.ts +143 -27
- package/dist/engine/harness/agent-harness.js +162 -74
- package/dist/engine/harness/types.d.ts +84 -13
- package/dist/engine/harness/types.js +21 -1
- package/dist/engine/llm/tool-turns.d.ts +4 -0
- package/dist/engine/llm/tool-turns.js +7 -2
- package/dist/engine/llm/types.d.ts +111 -24
- package/dist/engine/llm/types.js +69 -5
- package/dist/engine/llm/validation.js +2 -1
- package/dist/engine/loop/agent-loop.d.ts +39 -6
- package/dist/engine/loop/agent-loop.js +172 -82
- package/dist/engine/loop/types.d.ts +43 -4
- package/dist/engine/lsp/node-lsp-manager.d.ts +5 -3
- package/dist/engine/lsp/node-lsp-manager.js +14 -10
- package/dist/engine/session/import-validate.js +9 -0
- package/dist/engine/session/memory-repo.d.ts +8 -1
- package/dist/engine/session/memory-repo.js +20 -12
- package/dist/engine/session/repo-utils.d.ts +10 -0
- package/dist/engine/session/repo-utils.js +11 -5
- package/dist/engine/session/row-cells.d.ts +32 -0
- package/dist/engine/session/row-cells.js +25 -0
- package/dist/index.d.ts +63 -34
- package/dist/index.js +44 -21
- package/dist/internal/harness.d.ts +8 -6
- package/dist/internal/harness.js +6 -4
- package/dist/internal/llm.d.ts +2 -2
- package/dist/internal/llm.js +1 -1
- package/dist/orchestration/governance-baseline-validity.d.ts +7 -0
- package/dist/orchestration/governance-baseline-validity.js +33 -9
- package/dist/orchestration/run-workflow-tool.d.ts +2 -0
- package/dist/orchestration/run-workflow-tool.js +25 -12
- package/dist/orchestration/workflow-governance.d.ts +19 -4
- package/dist/orchestration/workflow-governance.js +30 -9
- package/dist/orchestration/workflow-primitives.d.ts +4 -1
- package/dist/orchestration/workflow-primitives.js +2 -2
- package/dist/orchestration/workflow-script-runner.d.ts +1 -1
- package/dist/orchestration/workflow-size-guideline.d.ts +1 -1
- package/dist/orchestration/workflow-types.d.ts +21 -12
- package/dist/orchestration/workflow-types.js +15 -4
- package/dist/orchestration/workflow.d.ts +37 -7
- package/dist/orchestration/workflow.js +81 -35
- package/dist/prompt-assembly/artifact-store.js +6 -9
- package/dist/prompt-assembly/assemble.d.ts +4 -10
- package/dist/prompt-assembly/assemble.js +1 -3
- package/dist/prompt-assembly/catalog/constitution.d.ts +0 -20
- package/dist/prompt-assembly/catalog/constitution.js +2 -0
- package/dist/prompt-assembly/catalog/core-behavior.js +5 -3
- package/dist/prompt-assembly/catalog/engine.d.ts +108 -0
- package/dist/prompt-assembly/catalog/engine.js +19 -0
- package/dist/prompt-assembly/catalog/environment.d.ts +276 -0
- package/dist/prompt-assembly/catalog/environment.js +61 -0
- package/dist/prompt-assembly/catalog/index.d.ts +9 -2
- package/dist/prompt-assembly/catalog/index.js +73 -2
- package/dist/prompt-assembly/catalog/locales/index.d.ts +16 -0
- package/dist/prompt-assembly/catalog/locales/index.js +22 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/constitution.d.ts +7 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/constitution.js +124 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.d.ts +6 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/core-behavior.js +120 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/cowork.d.ts +8 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/cowork.js +442 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.d.ts +7 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/engine.js +15 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/environment.d.ts +7 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/environment.js +50 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/modes.d.ts +7 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/modes.js +163 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/role.d.ts +7 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/role.js +148 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/team.d.ts +6 -0
- package/dist/prompt-assembly/catalog/locales/zh-Hans/team.js +246 -0
- package/dist/prompt-assembly/catalog/role.js +3 -6
- package/dist/prompt-assembly/catalog/schema.d.ts +23 -1
- package/dist/prompt-assembly/catalog/schema.js +2 -0
- package/dist/prompt-assembly/composer.d.ts +6 -11
- package/dist/prompt-assembly/composer.js +7 -7
- package/dist/prompt-assembly/engine-text.d.ts +9 -0
- package/dist/prompt-assembly/engine-text.js +33 -0
- package/dist/prompt-assembly/event-registry.js +3 -3
- package/dist/prompt-assembly/explain.d.ts +1 -0
- package/dist/prompt-assembly/explain.js +1 -1
- package/dist/prompt-assembly/locale-review.d.ts +13 -0
- package/dist/prompt-assembly/locale-review.js +19 -0
- package/dist/prompt-assembly/overlay.d.ts +7 -3
- package/dist/prompt-assembly/overlay.js +27 -5
- package/dist/prompt-assembly/renderers.d.ts +4 -4
- package/dist/prompt-assembly/renderers.js +26 -17
- package/dist/prompt-assembly/role-base.d.ts +1 -1
- package/dist/prompt-assembly/select.d.ts +26 -5
- package/dist/prompt-assembly/select.js +25 -2
- package/dist/prompt-assembly/slots.d.ts +19 -0
- package/dist/prompt-assembly/slots.js +16 -0
- package/dist/prompt-assembly/sugar.d.ts +4 -7
- package/dist/prompt-assembly/sugar.js +1 -2
- package/dist/prompt-assembly/tool-catalog.d.ts +5 -1
- package/dist/prompt-assembly/tool-catalog.js +5 -1
- package/dist/prompt-assembly/turn-snapshot.d.ts +38 -10
- package/dist/prompt-assembly/turn-snapshot.js +43 -13
- package/dist/prompt-assembly/types.d.ts +3 -0
- package/dist/prompts/cowork.d.ts +6 -25
- package/dist/prompts/cowork.js +10 -12
- package/dist/prompts/default.d.ts +10 -32
- package/dist/prompts/default.js +37 -63
- package/dist/shell/lex.d.ts +39 -13
- package/dist/shell/lex.js +70 -30
- package/dist/stores/file/background-agent-store.d.ts +5 -0
- package/dist/stores/file/background-agent-store.js +35 -61
- package/dist/stores/file/checkpoint-store.d.ts +5 -3
- package/dist/stores/file/checkpoint-store.js +8 -10
- package/dist/stores/file/fs-atomic.d.ts +27 -70
- package/dist/stores/file/fs-atomic.js +52 -148
- package/dist/stores/file/index.d.ts +12 -0
- package/dist/stores/file/index.js +27 -2
- package/dist/stores/file/mailbox-store.d.ts +10 -1
- package/dist/stores/file/mailbox-store.js +40 -12
- package/dist/stores/file/permission-rule-adopt.js +5 -2
- package/dist/stores/file/permission-rule-store.d.ts +81 -20
- package/dist/stores/file/permission-rule-store.js +126 -33
- package/dist/stores/file/session-policy-store.d.ts +2 -2
- package/dist/stores/file/session-store.d.ts +21 -2
- package/dist/stores/file/session-store.js +27 -14
- package/dist/stores/file/task-list-store.js +23 -25
- package/dist/stores/file/tool-result-store.d.ts +45 -7
- package/dist/stores/file/tool-result-store.js +99 -36
- package/dist/stores/file/workflow-run-store.d.ts +1 -0
- package/dist/stores/file/workflow-run-store.js +14 -11
- package/dist/tools/artifact/artifact-tool.js +2 -0
- package/dist/tools/artifact/local-stub.js +6 -6
- package/dist/tools/fs/bash-program-position.d.ts +1 -2
- package/dist/tools/fs/bash-readonly-classifier.d.ts +35 -0
- package/dist/tools/fs/bash-readonly-classifier.js +50 -12
- package/dist/tools/fs/env-error-detail.d.ts +1 -0
- package/dist/tools/fs/env-error-detail.js +7 -0
- package/dist/tools/fs/fs-bash.d.ts +24 -6
- package/dist/tools/fs/fs-bash.js +73 -25
- package/dist/tools/fs/fs-pdf.js +6 -4
- package/dist/tools/fs/fs-read.d.ts +76 -31
- package/dist/tools/fs/fs-read.js +159 -79
- package/dist/tools/fs/fs-search-tools.d.ts +1 -1
- package/dist/tools/fs/fs-search-tools.js +3 -1
- package/dist/tools/fs/fs-shared.d.ts +59 -63
- package/dist/tools/fs/fs-shared.js +31 -18
- package/dist/tools/fs/fs-write.d.ts +13 -0
- package/dist/tools/fs/fs-write.js +69 -13
- package/dist/tools/fs/index.d.ts +19 -1
- package/dist/tools/fs/index.js +10 -2
- package/dist/tools/fs/pdf.js +10 -9
- package/dist/tools/fs/read-deny.js +4 -10
- package/dist/tools/fs/read-floor.d.ts +5 -4
- package/dist/tools/fs/removal-targets.d.ts +11 -5
- package/dist/tools/fs/removal-targets.js +62 -32
- package/dist/tools/fs/safety.d.ts +26 -19
- package/dist/tools/fs/safety.js +13 -8
- package/dist/tools/fs/search.d.ts +1 -1
- package/dist/tools/fs/shell-read-argv.js +1 -0
- package/dist/tools/fs/shell-read-bindings.d.ts +128 -26
- package/dist/tools/fs/shell-read-bindings.js +667 -139
- package/dist/tools/fs/shell-read-check.js +1 -1
- package/dist/tools/fs/shell-read-judge.d.ts +4 -1
- package/dist/tools/fs/shell-read-judge.js +5 -1
- package/dist/tools/fs/shell-read-plan.d.ts +4 -0
- package/dist/tools/fs/shell-read-plan.js +21 -19
- package/dist/tools/fs/shell-read-sourced.d.ts +4 -3
- package/dist/tools/fs/shell-read-sourced.js +18 -1
- package/dist/tools/fs/shell-read-start.d.ts +6 -6
- package/dist/tools/fs/shell-read-start.js +1 -6
- package/dist/tools/fs/shell-read-word.d.ts +4 -2
- package/dist/tools/fs/shell-read-word.js +7 -6
- package/dist/tools/fs/shell-read-workdir.d.ts +1 -1
- package/dist/tools/fs/shell-reentry-text.d.ts +24 -9
- package/dist/tools/fs/shell-reentry-text.js +50 -20
- package/dist/tools/monitor.d.ts +4 -0
- package/dist/tools/monitor.js +14 -4
- package/dist/tools/scheduler-tools.d.ts +5 -2
- package/dist/tools/scheduler-tools.js +8 -6
- package/dist/tools/task-list.d.ts +49 -20
- package/dist/tools/task-list.js +115 -35
- package/dist/tools/web.d.ts +13 -3
- package/dist/tools/web.js +17 -6
- package/dist/tools/worktree.d.ts +3 -2
- package/dist/tools/worktree.js +24 -25
- package/package.json +10 -3
- package/test/export-surface.snapshot.json +330 -32
- package/wire-changes/core-stores-sql@7.66.1.json +30 -0
- package/wire-changes/core-stores-sql@7.67.0.json +39 -0
- package/wire-changes/core@7.66.1.json +46 -0
- package/wire-changes/core@7.67.0.json +12578 -0
- package/wire-changes/mods-kernel@7.66.1.json +30 -0
- package/wire-changes/mods-kernel@7.67.0.json +167 -0
- package/wire-changes/primitives@7.66.1.json +30 -0
- package/wire-changes/primitives@7.67.0.json +325 -0
- package/wire-changes/wiki-gate@7.67.0.json +1636 -0
- package/dist/brain/degrading.d.ts +0 -93
- package/dist/brain/degrading.js +0 -189
- package/dist/core/tool-conformance.d.ts +0 -20
- package/dist/core/tool-conformance.js +0 -37
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { accessSync, closeSync, constants as fsConstants, existsSync, fsyncSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync,
|
|
2
|
+
import { accessSync, closeSync, constants as fsConstants, existsSync, fsyncSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmSync, unlinkSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, join, relative, sep } from "node:path";
|
|
4
4
|
import { uuidv7 } from "../../internal/harness.js";
|
|
5
5
|
import { MAX_MEMORY_BYTES, composeMemoryBlock, firstSentence } from "../memory.js";
|
|
6
6
|
import { inlineUntrusted } from "../untrusted-text.js";
|
|
7
|
+
import { describeRejectedValue } from "../tool-search-setting.js";
|
|
7
8
|
import { canonicalJsonStringify } from "../canonical-json.js";
|
|
8
9
|
import { mintSystemReminder } from "../reminder-mint.js";
|
|
9
10
|
import { formatMemoryAge } from "./memory-age.js";
|
|
11
|
+
import { committedShadowFrontmatter, committedShadowOrFault, committedShadowTextOrAbsent } from "./committed-shadow-read.js";
|
|
10
12
|
import { committedDistilledOf, committedOriginOf, computeEntryRev, consolidationExposedFrontmatter, distilledEquals, hasDistilledFormExtra, hasOriginFormExtra, isValidEntryId, originEquals, parseEntryFile, serializeEntryFile, stripModelWrittenDistilled, stripModelWrittenOrigin, UNCLOSED_MEMORY_FILE_REASON } from "./frontmatter.js";
|
|
11
13
|
import { MEMORY_PROVENANCE_RECALL_SENTENCE, memoryExposureIndexRow, parseMemoryExposureIndexRow } from "./provenance-wording.js";
|
|
12
14
|
import { isInstructionEntry } from "./header-hints.js";
|
|
13
15
|
import { ConsolidationRefusedError, CONSOLIDATION_WRITE_REFUSED_CODE, CONSOLIDATION_FORCE_THROTTLE_FLOOR_MS, CONSOLIDATION_SEAT_FREEZE_GRACE_MS, consolidationTypeEligible, deriveProductSlug, deriveSupersededSet, fileGovernanceStore, governanceCaptureRecordStore, fileGovernanceStoreDir, governanceStoreIsFileOver, standingControlObjectsOf, isValidConsolidationPlanId, productAddPatch, recordActiveSetBaseline, recordConsolidationSession, sessionsSinceExcludingCurrent, scanRefusalCeiling, screenConsolidationOptions, memoryGovernanceDurability, supersessionFuseCeiling, deletionFuseCeiling, MEMORY_CHALLENGED_ENTRY_GUIDANCE, } from "./consolidation.js";
|
|
14
16
|
import { deriveShadowedSet } from "./shadowing.js";
|
|
15
|
-
import { classifySessionSettlements, clearHoldResolution, closeSessionAccount, disposeHold, effectiveSettlements, expireOverdueSettlements,
|
|
16
|
-
import { noReplaceRestore,
|
|
17
|
+
import { classifySessionSettlements, clearHoldResolution, closeSessionAccount, disposeHold, effectiveSettlements, expireOverdueSettlements, foreignWriterCandidates, legUnprovableText, terminateSessionAccount, sessionAccountLeg, markHoldReleased, openInstructionHold, openSessionAccount, readHoldCustody, readHolds, reconcileHolds, replayExternalSettlementEffects, resolveHoldRecord, resolveSessionAccountRecord, resolveSettlementRecord, sessionSettlements, sessionUnattributedSet, emptyUnattributedSet, convertV1SidecarKeys, } from "./delegation-settlement.js";
|
|
18
|
+
import { noReplaceRestore, stagingPathBeside } from "./delegation-settlement.js";
|
|
17
19
|
import { probeControlPlaneLinks } from "./control-objects.js";
|
|
18
20
|
import { replicaControlPlaneStrays } from "./control-plane-adoption.js";
|
|
19
21
|
import { sessionWriteHomeOf } from "./session-write-home.js";
|
|
20
|
-
import { landedUndecided, layerDigest, layerObservationLookup, readOnlyLayerCandidates, readOnlyLayerCensus, recordLayerObservations, settleUndecidedLayerObservations, observationBacked, sameObservation, undecidedLayerObservations } from "./layer-observations.js";
|
|
21
|
-
import { clearanceCustodyErased, eraseOriginClearanceCustody, markOriginClearanceTombstoned, openOriginClearance, readOriginClearances, settleOriginClearance } from "./origin-clearance.js";
|
|
22
|
-
import { carriesEntry } from "./entry-scan.js";
|
|
22
|
+
import { landedUndecided, layerDigest, layerObservationLookup, readOnlyLayerCandidates, readOnlyLayerCensus, recordLayerObservations, retireLayerObservations, settleUndecidedLayerObservations, observationBacked, sameObservation, undecidedLayerObservations } from "./layer-observations.js";
|
|
23
|
+
import { clearanceCustodyErased, eraseOriginClearanceCustody, markOriginClearanceTombstoned, openOriginClearance, readClearanceErasureCount, readOriginClearances, settleOriginClearance } from "./origin-clearance.js";
|
|
24
|
+
import { carriesEntry, standsAsLink } from "./entry-scan.js";
|
|
23
25
|
import { DEFAULT_MAX_ENTRY_DEPTH, MEMORY_INDEX_FILENAME, captureErasureInput, erasureRequestInvalid, erasureScopeRefusal, erasureSelectHash, erasureStatusOf, sweepUnderErasureRecord, scanEntryFiles, } from "./file-backend.js";
|
|
24
26
|
import { assembleMemoryExportBundle, canonicalExpectedScopes, computeMemoryBundleHash, expectedScopesInvalid, firstOutsideExpectedScopes, memoryBundleInvalid, } from "./export-bundle.js";
|
|
25
|
-
import { SCAN_FUSE_THRESHOLD, captureIntoQuarantine, clearContainedPath, eraseQuarantineCopies, keepCopiesBeforeOverwrite,
|
|
27
|
+
import { SCAN_FUSE_THRESHOLD, captureIntoQuarantine, clearContainedPath, eraseQuarantineCopies, keepCopiesBeforeOverwrite, quarantineObjectNameOf, restoreContainedBaseline, mintStagingName, indexLineIsStale, readIndexRevs, writeIndexRevs, bumpScanFuse, scanFuseKey, canonicalize, anchorStoreRoot, landingPathOf, landsOutsideStore, storeActRefusal, storeRootMovedRefusal, adoptRootScopeLayout, clearScanFuse, effectiveControlRootOf, sayAnnounceFailure, drainMemoryAnnouncements, enqueueMemoryAnnouncement, ensureDirExists, markSessionPolluted, readSessionPollution, recordRetrievedAccount, writeFileNoFollow, writeFileNoReplace, withPermissionRemedy, permissionRemedyOf, readRetrievedAccount, registerScope, registeredScopes, scopeDirFor, appendChallengeEvents, appendLineageAudit, rebuildStrictControlPlaneLedger, isStrictControlPlaneLedgerCorrupt, ControlPlaneCorruptError, CHALLENGE_LEDGER_MAX_EVENTS, adjudicateLineagePending, challengedEntryIds, clearLineageForEntries, discardLineagePending, lineageAccountOfEntry, lineageContributionsOfSession, lineageLatchedIds, promoteLineagePending, readChallengeEvents, readChallengedHistory, readLineageRecord, recordChallengedHistory, recordLineageCredential, reconcileLineage, readProjectionDebts, resolveChallengeEvent, settleProjectionDebts, stageLineagePending, stageProjectionDebts, controlPlaneStraysRefusal, } from "./layout.js";
|
|
26
28
|
import { createSessionIncarnationSeat, recalledForAnyIdentity, recalledForIdentity, rememberForIdentity } from "./session-incarnation.js";
|
|
27
29
|
import { scanMemoryFileName, scanMemoryWrite, scanRemediation } from "./scan.js";
|
|
28
30
|
import { writableRootOf } from "./types.js";
|
|
@@ -69,22 +71,6 @@ export function memoryRecallDisciplineSegment(provenance, opts) {
|
|
|
69
71
|
const teachMarkedForm = provenance === "carry" && opts?.markedEntriesServed !== false;
|
|
70
72
|
return teachMarkedForm ? `${MEMORY_RECALL_DISCIPLINE} ${MEMORY_PROVENANCE_RECALL_SENTENCE}` : MEMORY_RECALL_DISCIPLINE;
|
|
71
73
|
}
|
|
72
|
-
export function entryFileHeadCarriesOrigin(absPath, maxBytes = 64 * 1024) {
|
|
73
|
-
try {
|
|
74
|
-
const fd = openSync(absPath, "r");
|
|
75
|
-
try {
|
|
76
|
-
const buf = Buffer.alloc(maxBytes);
|
|
77
|
-
const n = readSync(fd, buf, 0, maxBytes, 0);
|
|
78
|
-
return committedOriginOf(parseEntryFile(buf.subarray(0, n).toString("utf8")).frontmatter) !== undefined;
|
|
79
|
-
}
|
|
80
|
-
finally {
|
|
81
|
-
closeSync(fd);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
74
|
export const MEMORY_PREFERENCE_DISCIPLINE = "When the user confirms a stored preference or fact still holds, refresh that entry's `last-confirmed: <YYYY-MM-DD>` frontmatter line (add it when absent). When you save a preference, add an `applies-when: <context>` frontmatter line naming when it applies. Both are plain frontmatter lines — write them yourself; nothing fills them in for you.";
|
|
89
75
|
export const MEMORY_ANNOUNCEMENT_READONLY_PLANE_CODA = "The notices immediately above concern a READ-ONLY memory store: any guidance in them to record, update, or tombstone an entry cannot be applied to that store this session — surface it to the user instead of claiming it done.";
|
|
90
76
|
export const MEMORY_ANNOUNCEMENT_READONLY_CODA = "The memory store itself is not writable this session, so any guidance above to record, update, or tombstone a memory entry cannot be applied here — surface it to the user instead of claiming it done.";
|
|
@@ -369,6 +355,18 @@ function noticeScopesOf(handle) {
|
|
|
369
355
|
}
|
|
370
356
|
const ANNOUNCEMENT_ATTRIBUTION_WAIT_MS = 5_000;
|
|
371
357
|
const STALE_LEG_NOTE = "memory session account: this harvest belongs to an earlier leg of the session (a later leg re-opened the account while it ran) — its account close and leg end were not written over the later leg";
|
|
358
|
+
function withoutIdLine(text) {
|
|
359
|
+
if (!text.startsWith("---"))
|
|
360
|
+
return text;
|
|
361
|
+
const close = text.indexOf("\n---", 3);
|
|
362
|
+
if (close < 0)
|
|
363
|
+
return text;
|
|
364
|
+
return text.slice(0, close).replace(/\nid:[^\n]*(?=\n|$)/, "") + text.slice(close);
|
|
365
|
+
}
|
|
366
|
+
function foreignWriterReason(x) {
|
|
367
|
+
const shown = x.dirty.slice(0, 3).map((d) => `${JSON.stringify(d.sessionId)} (${d.state})`).join(", ") + (x.dirty.length > 3 ? ", …" : "");
|
|
368
|
+
return `another session writing this memory layer in the same window is ${x.state === "exposed" ? "externally exposed" : "of unknown exposure (a pending delegation outcome, or an unreadable state)"} — ${shown} — so this harvest's writes cannot be attributed to a clean writer`;
|
|
369
|
+
}
|
|
372
370
|
export class MemoryEngine {
|
|
373
371
|
backend;
|
|
374
372
|
memoryDir;
|
|
@@ -390,8 +388,7 @@ export class MemoryEngine {
|
|
|
390
388
|
constructor(opts) {
|
|
391
389
|
const o = receiveOptions(opts, "MemoryEngine", MEMORY_ENGINE_OPTION_KEYS);
|
|
392
390
|
if (o.provenance !== undefined && o.provenance !== "off" && o.provenance !== "carry") {
|
|
393
|
-
const
|
|
394
|
-
const e = new Error(`MemoryEngineOptions.provenance must be "off" or "carry" when present (got ${got}) — an unevaluable provenance mode is refused loudly, never folded to either mode.`);
|
|
391
|
+
const e = new Error(`MemoryEngineOptions.provenance must be "off" or "carry" when present (got ${describeRejectedValue(o.provenance)}) — an unevaluable provenance mode is refused loudly, never folded to either mode.`);
|
|
395
392
|
e.code = "config.memory_provenance";
|
|
396
393
|
throw e;
|
|
397
394
|
}
|
|
@@ -467,15 +464,14 @@ export class MemoryEngine {
|
|
|
467
464
|
const candidates = [];
|
|
468
465
|
for (const m of handle.materialized.filter((x) => x.readonly)) {
|
|
469
466
|
const text = readSafe(m.path);
|
|
470
|
-
|
|
467
|
+
const linked = text === undefined && standsAsLink(m.path);
|
|
468
|
+
if (text === undefined && !linked) {
|
|
471
469
|
report.missing.push(m.relPath);
|
|
472
470
|
continue;
|
|
473
471
|
}
|
|
474
|
-
if (revOfText(text, m.id) === m.rev)
|
|
475
|
-
continue;
|
|
476
|
-
if ((await this.committedContentUnadopted(m.id)) === text)
|
|
472
|
+
if (text !== undefined && (revOfText(text, m.id) === m.rev || (await this.committedContentUnadopted(m.id)) === text))
|
|
477
473
|
continue;
|
|
478
|
-
const stood = handle.layerBaseline?.get(m.path) === layerDigest(text);
|
|
474
|
+
const stood = text !== undefined && handle.layerBaseline?.get(m.path) === layerDigest(text);
|
|
479
475
|
const rejection = admitsNothing
|
|
480
476
|
? { path: m.relPath, code: "readonly_layer", reason: `a read-only inherited memory layer's file ${stood ? "differed from its committed content when this session started (not this session's write)" : "differs from what this session was served"}; this session admits nothing, so it was not restored — the bytes stay on disk for a session that may write to adjudicate` }
|
|
481
477
|
: { path: m.relPath, code: "readonly_layer", reason: stood ? "a read-only inherited memory layer's file differed from its committed content when this session started (not this session's write)" : "a read-only inherited memory layer was modified; changes to inherited layers are not writable from this session" };
|
|
@@ -485,6 +481,9 @@ export class MemoryEngine {
|
|
|
485
481
|
}
|
|
486
482
|
return candidates;
|
|
487
483
|
}
|
|
484
|
+
layerCommittedView(scope) {
|
|
485
|
+
return this.backend.restrictedAdoptionView?.call(this.backend, { audit: false, scopes: [scope] }) ?? this.backend;
|
|
486
|
+
}
|
|
488
487
|
async committedContentUnadopted(id) {
|
|
489
488
|
const view = this.zeroCopy ? undefined : this.backend.restrictedAdoptionView?.({ audit: false });
|
|
490
489
|
if (view === undefined)
|
|
@@ -496,10 +495,9 @@ export class MemoryEngine {
|
|
|
496
495
|
}
|
|
497
496
|
catch {
|
|
498
497
|
}
|
|
499
|
-
return this.backend
|
|
498
|
+
return committedShadowTextOrAbsent(this.backend, id);
|
|
500
499
|
}
|
|
501
500
|
async restoreReadOnlyLayers(candidates, report, selfLeg, handle) {
|
|
502
|
-
let writers;
|
|
503
501
|
for (const c of candidates) {
|
|
504
502
|
const text = readSafe(c.path);
|
|
505
503
|
const committed = await this.committedContentUnadopted(c.id);
|
|
@@ -509,25 +507,199 @@ export class MemoryEngine {
|
|
|
509
507
|
}
|
|
510
508
|
if (committed === undefined)
|
|
511
509
|
continue;
|
|
512
|
-
|
|
513
|
-
|
|
510
|
+
const { disposition, ended } = await this.disposeDivergentSeat({ path: c.path, scope: c.scope, entryId: c.id, found: readNoFollowSafe(c.path), committed, act: "restoring the read-only layer file" }, { ...(selfLeg !== undefined ? { leg: selfLeg } : {}) }, handle);
|
|
511
|
+
await this.sayProvenEnded(ended, report);
|
|
512
|
+
const file = `read-only layer file ${quoteId(c.relPath)}`;
|
|
513
|
+
switch (disposition.kind) {
|
|
514
|
+
case "held":
|
|
515
|
+
c.rejection.reason = `a read-only inherited memory layer's file ${c.stood ? "differed from its committed content when this session started (not this session's write)" : "differs from what this session was served"}; ${disposition.why.join("; ")}; so it was not restored`;
|
|
516
|
+
this.warnScoped(report, c.scope, `${file} was not restored: ${disposition.why.join("; ")}`);
|
|
517
|
+
break;
|
|
518
|
+
case "restored":
|
|
519
|
+
case "vacated":
|
|
520
|
+
report.restored.push(c.relPath);
|
|
521
|
+
if (disposition.custody !== undefined)
|
|
522
|
+
this.warnScoped(report, c.scope, `${file} was restored to its committed content — the modified bytes are kept as quarantine object ${disposition.custody} in the memory control plane`);
|
|
523
|
+
break;
|
|
524
|
+
case "writer_kept":
|
|
525
|
+
this.warnScoped(report, c.scope, `${file} was not restored: a writer created the file again after its modified bytes were moved aside, and its bytes are kept${disposition.custody !== undefined ? ` (the modified bytes are quarantine object ${disposition.custody})` : ""}`);
|
|
526
|
+
break;
|
|
527
|
+
case "moved_under":
|
|
528
|
+
this.warnScoped(report, c.scope, `${file} was not restored: it changed while it was being restored — the newer bytes ${disposition.at === undefined ? "are back on the file" : `are preserved at ${disposition.at}`} (the earlier bytes are quarantine object ${disposition.custody})`);
|
|
529
|
+
break;
|
|
530
|
+
case "unkept":
|
|
531
|
+
this.warnScoped(report, c.scope, `${file} could NOT be restored to its committed content — the modified bytes could not be kept in the memory control plane first, so they are still on disk: ${disposition.detail}`);
|
|
532
|
+
break;
|
|
533
|
+
case "failed":
|
|
534
|
+
this.warnScoped(report, c.scope, `${file} could NOT be restored to its committed content — the modified bytes are still on disk: ${this.writeFailureText(disposition.cause)}`);
|
|
535
|
+
break;
|
|
514
536
|
}
|
|
515
|
-
|
|
516
|
-
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
async layerHolders(scope, self) {
|
|
540
|
+
const ended = [];
|
|
541
|
+
let writers;
|
|
542
|
+
try {
|
|
543
|
+
writers = (await foreignWriterCandidates(this.governanceStore, { since: this.now(), self: { ...(self.leg !== undefined ? { leg: self.leg } : {}) }, now: this.now, onEnded: (e) => ended.push(e) })).filter((w) => w.standing.state !== "ended");
|
|
544
|
+
}
|
|
545
|
+
catch {
|
|
546
|
+
return { held: { why: [LEDGER_UNREADABLE_CLAUSE], unreadable: true }, ended };
|
|
547
|
+
}
|
|
548
|
+
const blocking = writers.filter((w) => (w.writeScope === undefined || w.writeScope === scope) && (self.leg !== undefined || w.sessionId !== self.sessionId));
|
|
549
|
+
return {
|
|
550
|
+
...(blocking.length > 0 ? { held: { why: this.writerRefusals(blocking) } } : {}),
|
|
551
|
+
ended,
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
async disposeDivergentSeat(seat, self, handle) {
|
|
555
|
+
const holders = await this.layerHolders(seat.scope, self);
|
|
556
|
+
const done = (disposition) => ({ disposition, ended: holders.ended });
|
|
557
|
+
if (holders.held !== undefined)
|
|
558
|
+
return done({ kind: "held", ...holders.held });
|
|
559
|
+
let notAFile;
|
|
560
|
+
let seatMode;
|
|
561
|
+
try {
|
|
562
|
+
const standing = lstatSync(seat.path, { throwIfNoEntry: false });
|
|
563
|
+
if (standing !== undefined && !standing.isFile())
|
|
564
|
+
notAFile = standing.isSymbolicLink() ? "a link" : "something other than a file";
|
|
565
|
+
else if (standing !== undefined)
|
|
566
|
+
seatMode = standing.mode & 0o777;
|
|
567
|
+
}
|
|
568
|
+
catch (cause) {
|
|
569
|
+
return done({ kind: "failed", cause });
|
|
570
|
+
}
|
|
571
|
+
if (notAFile !== undefined)
|
|
572
|
+
return done({ kind: "failed", cause: new Error(`${notAFile} stands at this path — it was left as found, nothing read through it or written over it`) });
|
|
573
|
+
if (seat.found === undefined) {
|
|
574
|
+
if (seat.committed === undefined)
|
|
575
|
+
return done({ kind: "restored" });
|
|
576
|
+
try {
|
|
577
|
+
this.refuseOutsideStore(seat.path, seat.act, handle);
|
|
578
|
+
return done(writeFileNoReplace(seat.path, seat.committed) === "written" ? { kind: "restored" } : { kind: "writer_kept" });
|
|
517
579
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
this.warnScoped(report, c.scope, `read-only layer file ${quoteId(c.relPath)} was not restored: a session that writes this layer is open, and the bytes may be its uncommitted edit`);
|
|
521
|
-
continue;
|
|
580
|
+
catch (cause) {
|
|
581
|
+
return done({ kind: "failed", cause });
|
|
522
582
|
}
|
|
583
|
+
}
|
|
584
|
+
const label = `residue-${seat.entryId}.md`;
|
|
585
|
+
const kept = await this.keepInCustody(label, seat.found);
|
|
586
|
+
if (!("name" in kept))
|
|
587
|
+
return done({ kind: "unkept", detail: kept.failed });
|
|
588
|
+
const custody = kept.name;
|
|
589
|
+
const residueName = quarantineObjectNameOf(new TextEncoder().encode(seat.found), label);
|
|
590
|
+
const staging = stagingPathBeside(seat.path, mintStagingName(residueName, this.now));
|
|
591
|
+
try {
|
|
592
|
+
this.refuseOutsideStore(seat.path, seat.act, handle);
|
|
593
|
+
renameSync(seat.path, staging);
|
|
594
|
+
}
|
|
595
|
+
catch (cause) {
|
|
596
|
+
return done({ kind: "failed", custody, cause });
|
|
597
|
+
}
|
|
598
|
+
if (readNoFollowSafe(staging) !== seat.found) {
|
|
599
|
+
const back = noReplaceRestore(staging, seat.path);
|
|
600
|
+
if (back === "restored")
|
|
601
|
+
return done({ kind: "moved_under", custody });
|
|
602
|
+
return done({ kind: "moved_under", custody, at: await this.keepStagedInCustody(staging, label, seat.path, back === "stranded", handle) });
|
|
603
|
+
}
|
|
604
|
+
if (seat.committed !== undefined) {
|
|
605
|
+
let published;
|
|
523
606
|
try {
|
|
524
|
-
this.refuseOutsideStore(
|
|
525
|
-
|
|
526
|
-
report.restored.push(c.relPath);
|
|
607
|
+
this.refuseOutsideStore(seat.path, seat.act, handle);
|
|
608
|
+
published = writeFileNoReplace(seat.path, seat.committed, seatMode);
|
|
527
609
|
}
|
|
528
|
-
catch (
|
|
529
|
-
|
|
610
|
+
catch (cause) {
|
|
611
|
+
if (noReplaceRestore(staging, seat.path) === "kept")
|
|
612
|
+
this.dropStagedCopy(staging, handle);
|
|
613
|
+
return done({ kind: "failed", custody, cause });
|
|
530
614
|
}
|
|
615
|
+
this.dropStagedCopy(staging, handle);
|
|
616
|
+
return done(published === "written" ? { kind: "restored", custody } : { kind: "writer_kept", custody });
|
|
617
|
+
}
|
|
618
|
+
this.dropStagedCopy(staging, handle);
|
|
619
|
+
return done({ kind: "vacated", custody });
|
|
620
|
+
}
|
|
621
|
+
dropStagedCopy(staging, handle) {
|
|
622
|
+
if (this.storeActRefusedText(staging, "removing a staged copy custody holds", handle) !== undefined)
|
|
623
|
+
return;
|
|
624
|
+
try {
|
|
625
|
+
unlinkSync(staging);
|
|
626
|
+
}
|
|
627
|
+
catch {
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
async keepInCustody(label, content) {
|
|
631
|
+
const capture = await captureIntoQuarantine(this.governanceStore, label, content);
|
|
632
|
+
if (!("name" in capture))
|
|
633
|
+
return capture;
|
|
634
|
+
const bytes = typeof content === "string" ? Buffer.from(content, "utf8") : Buffer.from(content);
|
|
635
|
+
try {
|
|
636
|
+
const back = await this.governanceStore.getObject("quarantine", capture.name);
|
|
637
|
+
return back !== undefined && Buffer.from(back).equals(bytes) ? capture : { failed: "the control-plane custody copy could not be read back" };
|
|
638
|
+
}
|
|
639
|
+
catch {
|
|
640
|
+
return { failed: "the control-plane custody copy could not be read back" };
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
async keepStagedInCustody(staging, label, seatPath, stranded, handle) {
|
|
644
|
+
let staged;
|
|
645
|
+
try {
|
|
646
|
+
staged = readFileSync(staging);
|
|
647
|
+
}
|
|
648
|
+
catch {
|
|
649
|
+
staged = undefined;
|
|
650
|
+
}
|
|
651
|
+
let at = `${staging} (the staged bytes could not be read into the control plane)`;
|
|
652
|
+
let settled = false;
|
|
653
|
+
if (staged !== undefined) {
|
|
654
|
+
const kept = await this.keepInCustody(label, staged);
|
|
655
|
+
if (!("name" in kept))
|
|
656
|
+
at = `${staging} (${kept.failed})`;
|
|
657
|
+
else {
|
|
658
|
+
const refused = this.storeActRefusedText(staging, "removing a contained staging copy", handle);
|
|
659
|
+
if (refused !== undefined)
|
|
660
|
+
at = `${staging} (a copy is quarantine object ${kept.name}; this one was not removed: ${refused})`;
|
|
661
|
+
else {
|
|
662
|
+
try {
|
|
663
|
+
unlinkSync(staging);
|
|
664
|
+
settled = true;
|
|
665
|
+
at = `quarantine object ${kept.name} in the memory control plane`;
|
|
666
|
+
}
|
|
667
|
+
catch {
|
|
668
|
+
at = `${staging} (a copy is quarantine object ${kept.name}; this one could not be removed)`;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
if (stranded || !settled)
|
|
674
|
+
this.discloseSessionAccountIncident(`a concurrent write to ${seatPath} landed while the file was being moved aside and could not be put back — its bytes are preserved at ${at}`, undefined);
|
|
675
|
+
return at;
|
|
676
|
+
}
|
|
677
|
+
writerRefusals(blocking) {
|
|
678
|
+
const clauses = [];
|
|
679
|
+
if (blocking.some((w) => w.standing.state === "running"))
|
|
680
|
+
clauses.push("a session that writes this layer is still running (the bytes may be its uncommitted edit)");
|
|
681
|
+
for (const w of blocking) {
|
|
682
|
+
if (w.standing.state !== "unprovable")
|
|
683
|
+
continue;
|
|
684
|
+
const sid = JSON.stringify(w.sessionId);
|
|
685
|
+
const leg = JSON.stringify(w.leg ?? null);
|
|
686
|
+
clauses.push(`the session ${sid} (leg ${leg}) that writes ${w.writeScope === undefined ? "every layer" : "this layer"} cannot be checked from here — ` +
|
|
687
|
+
`${legUnprovableText(w.standing.why)} — so it may still be running (the bytes may be its uncommitted edit); ` +
|
|
688
|
+
`if it is over, close it with resolveSessionAccount(${sid}, <requestId>, ${leg})`);
|
|
689
|
+
}
|
|
690
|
+
return clauses;
|
|
691
|
+
}
|
|
692
|
+
async sayProvenEnded(ended, to) {
|
|
693
|
+
if (Array.isArray(to)) {
|
|
694
|
+
to.push(...ended);
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
for (const e of ended) {
|
|
698
|
+
const text = `the session ${JSON.stringify(e.sessionId)} that wrote this layer ended without finishing — its process is gone, so its leg was recorded as over (leg ${JSON.stringify(e.leg)})`;
|
|
699
|
+
if (to !== undefined)
|
|
700
|
+
this.warnScoped(to, e.writeScope, text);
|
|
701
|
+
else
|
|
702
|
+
await this.announce(e.writeScope, { kind: "gate", at: this.now(), items: [`index note: ${inlineUntrusted(text, 200)}`] }, "writer-account census enqueue");
|
|
531
703
|
}
|
|
532
704
|
}
|
|
533
705
|
async observeReadOnlyLayers(handle, report, sessionId) {
|
|
@@ -744,6 +916,7 @@ export class MemoryEngine {
|
|
|
744
916
|
}
|
|
745
917
|
announcementWork = Promise.resolve();
|
|
746
918
|
layerWarningScopes = new WeakMap();
|
|
919
|
+
mountEndedLegs = new WeakMap();
|
|
747
920
|
warnScoped(report, scope, text) {
|
|
748
921
|
report.warnings.push(text);
|
|
749
922
|
const own = this.layerWarningScopes.get(report) ?? new Map();
|
|
@@ -840,6 +1013,36 @@ export class MemoryEngine {
|
|
|
840
1013
|
return inProcess;
|
|
841
1014
|
return readSessionPollution(this.governanceStore, sessionId, identity);
|
|
842
1015
|
}
|
|
1016
|
+
async foreignWriterExposure(input) {
|
|
1017
|
+
const { report, ...ask } = input;
|
|
1018
|
+
const ended = [];
|
|
1019
|
+
let rows;
|
|
1020
|
+
try {
|
|
1021
|
+
rows = await foreignWriterCandidates(this.governanceStore, { ...ask, now: this.now, onEnded: (e) => ended.push(e) });
|
|
1022
|
+
}
|
|
1023
|
+
finally {
|
|
1024
|
+
await this.sayProvenEnded(ended, report);
|
|
1025
|
+
}
|
|
1026
|
+
const candidates = [...new Set(rows.map((r) => r.sessionId))];
|
|
1027
|
+
const dirty = [];
|
|
1028
|
+
for (const sessionId of candidates) {
|
|
1029
|
+
try {
|
|
1030
|
+
const rec = recalledForAnyIdentity(this.pollutedSessions, sessionId) ?? (await readSessionPollution(this.governanceStore, sessionId));
|
|
1031
|
+
if (rec !== undefined) {
|
|
1032
|
+
dirty.push({ sessionId, state: "exposed" });
|
|
1033
|
+
continue;
|
|
1034
|
+
}
|
|
1035
|
+
const cls = classifySessionSettlements(await sessionSettlements(this.governanceStore, sessionId));
|
|
1036
|
+
if (cls.state !== "clean")
|
|
1037
|
+
dirty.push({ sessionId, state: cls.state === "exposed" ? "exposed" : "unknown" });
|
|
1038
|
+
}
|
|
1039
|
+
catch {
|
|
1040
|
+
dirty.push({ sessionId, state: "unknown" });
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
const state = dirty.some((d) => d.state === "exposed") ? "exposed" : dirty.length > 0 ? "unknown" : "clean";
|
|
1044
|
+
return { candidates, state, dirty };
|
|
1045
|
+
}
|
|
843
1046
|
captureRecords;
|
|
844
1047
|
captureOptOutSessions = new Map();
|
|
845
1048
|
markSessionCaptureOptOut(sessionId, reason) {
|
|
@@ -1204,6 +1407,7 @@ export class MemoryEngine {
|
|
|
1204
1407
|
}
|
|
1205
1408
|
else {
|
|
1206
1409
|
resolvedIds = (await lineageContributionsOfSession(this.governanceStore, select.sessionId))
|
|
1410
|
+
.filter((c) => c.attribution === undefined)
|
|
1207
1411
|
.map((c) => c.entryId)
|
|
1208
1412
|
.sort();
|
|
1209
1413
|
}
|
|
@@ -1266,19 +1470,29 @@ export class MemoryEngine {
|
|
|
1266
1470
|
}
|
|
1267
1471
|
async answerClearanceCustody(att) {
|
|
1268
1472
|
let resolved;
|
|
1473
|
+
let faced;
|
|
1269
1474
|
try {
|
|
1270
1475
|
const counted = att.residuals.carriers.clearanceCustody;
|
|
1271
|
-
|
|
1272
|
-
|
|
1476
|
+
const removed = typeof counted === "object" && counted !== null ? counted.removed : undefined;
|
|
1477
|
+
const remaining = typeof counted === "object" && counted !== null ? counted.remaining : undefined;
|
|
1478
|
+
if (typeof removed === "number" && Number.isSafeInteger(removed) && removed >= 0 && typeof remaining === "number" && Number.isSafeInteger(remaining) && remaining >= 0)
|
|
1479
|
+
faced = { removed, remaining };
|
|
1273
1480
|
const conflicted = new Set(att.conflicts.map((c) => String(c.id)));
|
|
1274
1481
|
resolved = att.resolvedIds.map(String).filter((id) => !conflicted.has(id));
|
|
1275
1482
|
}
|
|
1276
1483
|
catch {
|
|
1277
1484
|
return att;
|
|
1278
1485
|
}
|
|
1279
|
-
|
|
1486
|
+
let corrupt = false;
|
|
1487
|
+
const custody = await eraseOriginClearanceCustody(this.governanceStore, new Set(resolved), this.now()).catch((err) => {
|
|
1488
|
+
corrupt = err instanceof ControlPlaneCorruptError;
|
|
1489
|
+
return undefined;
|
|
1490
|
+
});
|
|
1491
|
+
if (custody === undefined && faced !== undefined && !corrupt)
|
|
1492
|
+
return att;
|
|
1280
1493
|
try {
|
|
1281
|
-
const
|
|
1494
|
+
const answer = custody !== undefined ? { removed: (faced?.removed ?? 0) + custody.removed, remaining: custody.remaining } : { unverified: true };
|
|
1495
|
+
const out = { ...att, residuals: { ...att.residuals, carriers: { ...att.residuals.carriers, clearanceCustody: answer } } };
|
|
1282
1496
|
out.status = erasureStatusOf(out);
|
|
1283
1497
|
return out;
|
|
1284
1498
|
}
|
|
@@ -1433,6 +1647,7 @@ export class MemoryEngine {
|
|
|
1433
1647
|
lastRev: c.lastRev,
|
|
1434
1648
|
lastAt: c.lastAt,
|
|
1435
1649
|
...(polluted !== undefined ? { polluted: { at: polluted.at, reason: polluted.reason } } : {}),
|
|
1650
|
+
...(c.attribution !== undefined ? { attribution: c.attribution } : {}),
|
|
1436
1651
|
});
|
|
1437
1652
|
}
|
|
1438
1653
|
return {
|
|
@@ -1697,6 +1912,7 @@ export class MemoryEngine {
|
|
|
1697
1912
|
}
|
|
1698
1913
|
}
|
|
1699
1914
|
async materializeCore(scopes, writeScope, opts, legSeat) {
|
|
1915
|
+
const mountedAt = this.now();
|
|
1700
1916
|
this.assertRootAnchored();
|
|
1701
1917
|
ensureDirExists(this.memoryDir);
|
|
1702
1918
|
ensureDirExists(this.controlDir);
|
|
@@ -1707,9 +1923,6 @@ export class MemoryEngine {
|
|
|
1707
1923
|
const restricted = opts?.adoptionRestricted === true;
|
|
1708
1924
|
let sessionAccountFailed = false;
|
|
1709
1925
|
let accountLeg;
|
|
1710
|
-
const readBackend = restricted
|
|
1711
|
-
? (this.backend.restrictedAdoptionView?.({ audit: true, writeScope }) ?? this.backend)
|
|
1712
|
-
: this.backend;
|
|
1713
1926
|
const scopeDirs = new Map();
|
|
1714
1927
|
for (const scope of scopes)
|
|
1715
1928
|
scopeDirs.set(scope, registerScope(this.memoryDir, this.controlDir, scope));
|
|
@@ -1722,12 +1935,21 @@ export class MemoryEngine {
|
|
|
1722
1935
|
: undefined;
|
|
1723
1936
|
if (layerBaseline !== undefined)
|
|
1724
1937
|
this.discloseUnsettleableObservations();
|
|
1938
|
+
let liveLayer = false;
|
|
1939
|
+
const mountEnded = [];
|
|
1725
1940
|
if (this.provenance === "carry" && opts?.sessionId !== undefined && writeScope !== null && !restricted) {
|
|
1726
1941
|
let accountFailed = false;
|
|
1727
1942
|
try {
|
|
1728
|
-
const foreign = await
|
|
1943
|
+
const foreign = await this.foreignWriterExposure({ layer: writeScope, since: this.now(), self: { sessionId: opts.sessionId }, report: mountEnded });
|
|
1944
|
+
const holders = foreign.candidates.length > 0 ? await this.layerHolders(writeScope, { sessionId: opts.sessionId }) : undefined;
|
|
1945
|
+
if (holders !== undefined)
|
|
1946
|
+
mountEnded.push(...holders.ended);
|
|
1947
|
+
if (holders?.held !== undefined)
|
|
1948
|
+
liveLayer = true;
|
|
1729
1949
|
const unattributed = [];
|
|
1730
|
-
|
|
1950
|
+
const recordedOnly = foreign.state === "clean" && foreign.candidates.length > 0 && holders?.held === undefined;
|
|
1951
|
+
let observedAtMount;
|
|
1952
|
+
if (foreign.state !== "clean" || recordedOnly) {
|
|
1731
1953
|
const wroot = canonicalize(scopeDirFor(this.memoryDir, this.controlDir, writeScope));
|
|
1732
1954
|
let committedRevs;
|
|
1733
1955
|
const snapFace = this.backend.committedSnapshotsOfScopes;
|
|
@@ -1768,64 +1990,38 @@ export class MemoryEngine {
|
|
|
1768
1990
|
}
|
|
1769
1991
|
const uncommitted = (parsed.id === undefined && !debtAttributed) || (parsed.id !== undefined && committedRevs !== undefined && !committedRevs.has(parsed.id));
|
|
1770
1992
|
if (uncommitted) {
|
|
1771
|
-
|
|
1993
|
+
if (!recordedOnly)
|
|
1994
|
+
unattributed.push({ scope: writeScope, rel: relHome });
|
|
1772
1995
|
continue;
|
|
1773
1996
|
}
|
|
1774
1997
|
if (parsed.id !== undefined && committedRevs !== undefined) {
|
|
1775
1998
|
const committedRev = committedRevs.get(parsed.id);
|
|
1776
1999
|
const diskRev = computeEntryRev({ id: parsed.id, frontmatter: parsed.frontmatter, body: parsed.body });
|
|
1777
|
-
|
|
2000
|
+
const entryId = parsed.id;
|
|
2001
|
+
const recorded = () => (observedAtMount ??= layerObservationLookup(this.controlDir)).find(entryId, committedRev, revOfText(text, entryId)) !== undefined;
|
|
2002
|
+
if (committedRev !== undefined && diskRev !== committedRev && (!recordedOnly || recorded())) {
|
|
1778
2003
|
const committed = await this.committedContentFor(parsed.id);
|
|
1779
2004
|
if (committed !== undefined && committed !== text) {
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
}
|
|
1788
|
-
catch {
|
|
1789
|
-
captured = false;
|
|
1790
|
-
}
|
|
1791
|
-
let restoredCommitted = false;
|
|
1792
|
-
if (captured) {
|
|
1793
|
-
const stagingName = mintStagingName(captureName, this.now);
|
|
1794
|
-
const stagingPath = stagingPathBeside(canonical, stagingName);
|
|
1795
|
-
try {
|
|
1796
|
-
this.refuseOutsideStore(canonical, "containing session residue");
|
|
1797
|
-
renameSync(canonical, stagingPath);
|
|
1798
|
-
if (readFileSync(stagingPath, "utf8") === text) {
|
|
1799
|
-
writeFileNoFollow(canonical, committed);
|
|
1800
|
-
restoredCommitted = true;
|
|
1801
|
-
try {
|
|
1802
|
-
unlinkSync(stagingPath);
|
|
1803
|
-
}
|
|
1804
|
-
catch {
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
else {
|
|
1808
|
-
const restore = noReplaceRestore(stagingPath, canonical);
|
|
1809
|
-
if (restore !== "restored") {
|
|
1810
|
-
const retired = await retireStagingToObject(this.governanceStore, stagingPath, "quarantine", stagingName, () => this.storeActRefusedText(stagingPath, "removing a contained staging copy"));
|
|
1811
|
-
if (restore === "stranded" || !retired.settled)
|
|
1812
|
-
this.discloseSessionAccountIncident(`a concurrent write to ${rel} landed during residue containment and could not be restored — its bytes are preserved at ${retired.at}`, undefined);
|
|
1813
|
-
}
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
catch {
|
|
1817
|
-
}
|
|
2005
|
+
const { disposition, ended } = await this.disposeDivergentSeat({ path: canonical, scope: writeScope, entryId: parsed.id, found: text, committed, act: "containing session residue" }, { sessionId: opts.sessionId });
|
|
2006
|
+
mountEnded.push(...ended);
|
|
2007
|
+
if (disposition.kind === "held") {
|
|
2008
|
+
liveLayer = true;
|
|
2009
|
+
if (disposition.unreadable === true)
|
|
2010
|
+
this.discloseSessionAccountIncident(`the crash-residue edit of ${rel} was left in place: ${disposition.why.join("; ")}`, undefined);
|
|
2011
|
+
continue;
|
|
1818
2012
|
}
|
|
1819
|
-
|
|
2013
|
+
if (disposition.kind === "unkept")
|
|
1820
2014
|
this.discloseSessionAccountIncident(`the crash-residue edit of ${rel} could not be captured to quarantine — the divergent bytes were left in place (the inbound gate adjudicates them)`, undefined);
|
|
1821
|
-
}
|
|
2015
|
+
const kept = "custody" in disposition && disposition.custody !== undefined ? ` (${disposition.custody})` : "";
|
|
1822
2016
|
await this.announce(writeScope, {
|
|
1823
2017
|
kind: "external",
|
|
1824
2018
|
at: this.now(),
|
|
1825
2019
|
items: [
|
|
1826
|
-
|
|
1827
|
-
? `crash residue: an edit of committed memory entry ${quoteId(rel)} pre-existed this session under an unresolved foreign session account — its writer cannot be attributed, so the edit bytes were captured to control-plane quarantine
|
|
1828
|
-
:
|
|
2020
|
+
disposition.kind === "restored"
|
|
2021
|
+
? `crash residue: an edit of committed memory entry ${quoteId(rel)} pre-existed this session under an unresolved foreign session account — its writer cannot be attributed, so the edit bytes were captured to control-plane quarantine${kept} and the committed content restored (host review adjudicates the edit)`
|
|
2022
|
+
: disposition.kind === "writer_kept"
|
|
2023
|
+
? `crash residue: an edit of committed memory entry ${quoteId(rel)} pre-existed this session under an unresolved foreign session account — the edit bytes were captured to control-plane quarantine${kept}; a writer created the file again after the edit was moved aside, and its bytes are kept (host review adjudicates the edit)`
|
|
2024
|
+
: `crash residue: an edit of committed memory entry ${quoteId(rel)} pre-existed this session under an unresolved foreign session account and could NOT be fully contained — the divergent/newer bytes were left in place (or preserved beside the capture) for the ordinary inbound gate`,
|
|
1829
2025
|
],
|
|
1830
2026
|
}, "session-account residue");
|
|
1831
2027
|
}
|
|
@@ -1851,6 +2047,11 @@ export class MemoryEngine {
|
|
|
1851
2047
|
if (accountFailed)
|
|
1852
2048
|
sessionAccountFailed = true;
|
|
1853
2049
|
}
|
|
2050
|
+
const readBackend = restricted
|
|
2051
|
+
? (this.backend.restrictedAdoptionView?.call(this.backend, { audit: true, writeScope }) ?? this.backend)
|
|
2052
|
+
: liveLayer && writeScope !== null
|
|
2053
|
+
? this.layerCommittedView(writeScope)
|
|
2054
|
+
: this.backend;
|
|
1854
2055
|
const allScopes = [...scopeDirs.keys()];
|
|
1855
2056
|
const headers = await readBackend.listHeaders(allScopes);
|
|
1856
2057
|
const entries = await readBackend.getByIds(headers.map((h) => h.id));
|
|
@@ -1878,6 +2079,8 @@ export class MemoryEngine {
|
|
|
1878
2079
|
...(layerBaseline !== undefined ? { layerBaseline } : {}),
|
|
1879
2080
|
...(accountLeg !== undefined ? { accountLeg } : {}),
|
|
1880
2081
|
};
|
|
2082
|
+
if (mountEnded.length > 0)
|
|
2083
|
+
this.mountEndedLegs.set(handle, mountEnded);
|
|
1881
2084
|
if (handle.writableRoot !== null) {
|
|
1882
2085
|
this.refuseOutsideStore(join(handle.writableRoot, MEMORY_INDEX_FILENAME), "creating the write home", handle);
|
|
1883
2086
|
ensureDirExists(handle.writableRoot);
|
|
@@ -2021,7 +2224,7 @@ export class MemoryEngine {
|
|
|
2021
2224
|
await this.announce(handle.writeScope, { kind: "gate", at: this.now(), items: [inlineUntrusted(`this session's memory write home cannot be written at ${refused.size} path(s) (${path}${refused.size > 1 ? ", …" : ""}): ${remedy ?? thrownText(err)}`, 700)] }, "write-home permission enqueue");
|
|
2022
2225
|
}
|
|
2023
2226
|
const indexOnDisk = readSafe(join(writableRoot, MEMORY_INDEX_FILENAME));
|
|
2024
|
-
handle.planeBaseline = { files, ...(indexOnDisk !== undefined ? { index: indexOnDisk } : {}) };
|
|
2227
|
+
handle.planeBaseline = { files, ...(indexOnDisk !== undefined ? { index: indexOnDisk } : {}), at: mountedAt };
|
|
2025
2228
|
}
|
|
2026
2229
|
return handle;
|
|
2027
2230
|
}
|
|
@@ -2092,7 +2295,7 @@ export class MemoryEngine {
|
|
|
2092
2295
|
const nameFinding = scanMemoryFileName(relative(root, canonicalPath));
|
|
2093
2296
|
if (nameFinding !== undefined)
|
|
2094
2297
|
findings.push(nameFinding);
|
|
2095
|
-
findings.push(...scanMemoryWrite(content, { maxBytes: this.perFileBytes }));
|
|
2298
|
+
findings.push(...scanMemoryWrite(typeof content === "string" ? content : new TextDecoder().decode(content), { maxBytes: this.perFileBytes }));
|
|
2096
2299
|
if (findings.length === 0)
|
|
2097
2300
|
return { ok: true };
|
|
2098
2301
|
const f = findings[0];
|
|
@@ -2152,13 +2355,16 @@ export class MemoryEngine {
|
|
|
2152
2355
|
const lineageSessionId = opts?.sessionId;
|
|
2153
2356
|
const startedAt = this.now();
|
|
2154
2357
|
let sessionPending = false;
|
|
2155
|
-
let
|
|
2358
|
+
let foreignWriters;
|
|
2359
|
+
let exposureFrom = "self";
|
|
2156
2360
|
let unattributedSet = emptyUnattributedSet();
|
|
2157
2361
|
const containment = { indexRolledBack: false, quarantinedInstruction: [], heldInstruction: [], releasedHolds: [], disposedHolds: [] };
|
|
2158
2362
|
const signalContainment = (fill) => {
|
|
2159
2363
|
fill(containment);
|
|
2160
2364
|
report.containment = containment;
|
|
2161
2365
|
};
|
|
2366
|
+
const containedObjects = [];
|
|
2367
|
+
const heldThisHarvest = [];
|
|
2162
2368
|
const pushDistinct = (arr, rel) => {
|
|
2163
2369
|
if (!arr.includes(rel))
|
|
2164
2370
|
arr.push(rel);
|
|
@@ -2288,10 +2494,17 @@ export class MemoryEngine {
|
|
|
2288
2494
|
}
|
|
2289
2495
|
else if (cls.state === "pending") {
|
|
2290
2496
|
sessionPending = true;
|
|
2291
|
-
pendingSettleIds = rows.filter((r) => r.effective === "pending").map((r) => r.row.settleId);
|
|
2292
2497
|
}
|
|
2293
2498
|
unattributedSet = await sessionUnattributedSet(this.governanceStore, lineageSessionId);
|
|
2294
2499
|
}
|
|
2500
|
+
if (writeScope !== null) {
|
|
2501
|
+
foreignWriters = await this.foreignWriterExposure({ layer: writeScope, since: handle.planeBaseline?.at ?? 0, self: { ...(lineageSessionId !== undefined ? { sessionId: lineageSessionId } : {}), ...(handle.accountLeg !== undefined ? { leg: handle.accountLeg } : {}) }, report });
|
|
2502
|
+
if (foreignWriters.state !== "clean" && pollutedReason === undefined) {
|
|
2503
|
+
pollutedReason = foreignWriterReason(foreignWriters);
|
|
2504
|
+
pollutionCause = "unattributed";
|
|
2505
|
+
exposureFrom = "foreign";
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2295
2508
|
}
|
|
2296
2509
|
const rec = await reconcileLineage(this.governanceStore);
|
|
2297
2510
|
await this.settlePromotions(rec.promoted);
|
|
@@ -2364,11 +2577,13 @@ export class MemoryEngine {
|
|
|
2364
2577
|
presentIds.add(r.parsed.id);
|
|
2365
2578
|
const recordByPath = new Map(records.map((r) => [r.canonical, r]));
|
|
2366
2579
|
const pollutedStubs = new Map(handle.materialized.filter((m) => !m.readonly && m.stub).map((m) => [m.path, m]));
|
|
2367
|
-
const withheldWhy = carry
|
|
2368
|
-
? "this session
|
|
2369
|
-
:
|
|
2580
|
+
const withheldWhy = () => !carry
|
|
2581
|
+
? "this session invoked a tool classified as an external content source, so its memory changes were not committed"
|
|
2582
|
+
: exposureFrom === "foreign"
|
|
2583
|
+
? "another session writing this memory layer in the same window is externally exposed or of unknown state and this file is instruction-form (type: feedback, or pinned/triggers/applies-when header lines) — an instruction-form write that cannot be attributed to a clean writer is withheld for host review"
|
|
2584
|
+
: "this session is marked externally exposed and this file is instruction-form (type: feedback, or pinned/triggers/applies-when header lines) — instruction-form entries from exposed sessions are withheld for host review";
|
|
2370
2585
|
const containPollutedRecord = async (f, whyOverride) => {
|
|
2371
|
-
const why = whyOverride ?? withheldWhy;
|
|
2586
|
+
const why = whyOverride ?? withheldWhy();
|
|
2372
2587
|
const rel = f.rel;
|
|
2373
2588
|
if (!insideWriteRoot(f.canonical)) {
|
|
2374
2589
|
report.rejections.push({ path: rel, code: "outside_root", reason: "file resolves outside the writable memory root (containment gate, fail-closed)" });
|
|
@@ -2386,6 +2601,8 @@ export class MemoryEngine {
|
|
|
2386
2601
|
if (pollutedStub) {
|
|
2387
2602
|
if (revOfText(f.text, pollutedStub.id) !== pollutedStub.rev) {
|
|
2388
2603
|
const sq = await this.containSuspect(f.canonical, f.text, "containing a withheld file", handle);
|
|
2604
|
+
if (sq.dest !== undefined)
|
|
2605
|
+
containedObjects.push({ name: sq.dest, record: f });
|
|
2389
2606
|
const stubCaptured = sq.dest !== undefined;
|
|
2390
2607
|
if (stubCaptured && sq.removed)
|
|
2391
2608
|
report.movedToQuarantine.push(rel);
|
|
@@ -2403,6 +2620,8 @@ export class MemoryEngine {
|
|
|
2403
2620
|
return;
|
|
2404
2621
|
}
|
|
2405
2622
|
const q = await this.containSuspect(f.canonical, f.text, "containing a withheld file", handle);
|
|
2623
|
+
if (q.dest !== undefined)
|
|
2624
|
+
containedObjects.push({ name: q.dest, record: f });
|
|
2406
2625
|
let contained = q.removed;
|
|
2407
2626
|
const priorId = handle.baseIds.get(f.canonical);
|
|
2408
2627
|
if (priorId !== undefined) {
|
|
@@ -2447,12 +2666,8 @@ export class MemoryEngine {
|
|
|
2447
2666
|
if (indexNow === undefined || indexNow === handle.indexText)
|
|
2448
2667
|
return false;
|
|
2449
2668
|
const kept = await keepCopiesBeforeOverwrite(indexNow, async (bytes) => {
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
}
|
|
2453
|
-
catch (err) {
|
|
2454
|
-
return thrownText(err);
|
|
2455
|
-
}
|
|
2669
|
+
const capture = await captureIntoQuarantine(this.governanceStore, `polluted-${MEMORY_INDEX_FILENAME}`, bytes);
|
|
2670
|
+
return "name" in capture ? true : capture.failed;
|
|
2456
2671
|
}, () => {
|
|
2457
2672
|
this.refuseOutsideStore(pollutedIndexPath, "reading the index again after its copy", handle);
|
|
2458
2673
|
return readNoFollowSafe(pollutedIndexPath);
|
|
@@ -2493,7 +2708,7 @@ export class MemoryEngine {
|
|
|
2493
2708
|
}
|
|
2494
2709
|
if (await restorePollutedIndex())
|
|
2495
2710
|
signalContainment((c) => (c.indexRolledBack = true));
|
|
2496
|
-
report.warnings.push(`memory harvest refused by an incident while this session is marked externally exposed — no entries were committed; instruction-form files were withheld and the derived index rolled back: ${inlineUntrusted(pollutedReason, 200)}`);
|
|
2711
|
+
report.warnings.push(`memory harvest refused by an incident while ${exposureFrom === "foreign" ? "another writer of this layer is externally exposed or of unknown state" : "this session is marked externally exposed"} — no entries were committed; instruction-form files were withheld and the derived index rolled back: ${inlineUntrusted(pollutedReason, 200)}`);
|
|
2497
2712
|
};
|
|
2498
2713
|
await this.restoreReadOnlyLayers(readOnlyRestorable, report, handle.accountLeg, handle);
|
|
2499
2714
|
const removedOnPlane = (p) => {
|
|
@@ -2574,7 +2789,17 @@ export class MemoryEngine {
|
|
|
2574
2789
|
const idsAddedThisHarvest = new Set();
|
|
2575
2790
|
const modelIdAdds = new Set();
|
|
2576
2791
|
const stoodAsFound = new Set();
|
|
2792
|
+
await this.sayProvenEnded(this.mountEndedLegs.get(handle) ?? [], report);
|
|
2793
|
+
this.mountEndedLegs.delete(handle);
|
|
2794
|
+
const layerHolding = carry && lineageSessionId !== undefined && handle.adoptionRestricted !== true
|
|
2795
|
+
? await this.layerHolders(writeScope, { ...(handle.accountLeg !== undefined ? { leg: handle.accountLeg } : {}), sessionId: lineageSessionId })
|
|
2796
|
+
: undefined;
|
|
2797
|
+
await this.sayProvenEnded(layerHolding?.ended ?? [], report);
|
|
2798
|
+
const layerHeld = layerHolding?.held;
|
|
2799
|
+
const leftForWriter = [];
|
|
2577
2800
|
let observedTable;
|
|
2801
|
+
const recordedResidue = new Set();
|
|
2802
|
+
const recordedDisposals = [];
|
|
2578
2803
|
const removalDeletes = new Map();
|
|
2579
2804
|
for (const m of missingWritable) {
|
|
2580
2805
|
const placement = await this.committedPlacementOf(m.id);
|
|
@@ -2602,7 +2827,7 @@ export class MemoryEngine {
|
|
|
2602
2827
|
const back = await restoreRemoved(m);
|
|
2603
2828
|
const unread = committedFm === undefined ? " (its committed form could not be read, so it is withheld as one)" : "";
|
|
2604
2829
|
if (pollutedReason !== undefined) {
|
|
2605
|
-
report.rejections.push({ path: m.relPath, code: "polluted", reason: `memory deletion withheld${unread}: ${withheldWhy} — ${back}` });
|
|
2830
|
+
report.rejections.push({ path: m.relPath, code: "polluted", reason: `memory deletion withheld${unread}: ${withheldWhy()} — ${back}` });
|
|
2606
2831
|
}
|
|
2607
2832
|
else {
|
|
2608
2833
|
report.warnings.push(`${m.relPath}: instruction-form entry NOT deleted${unread} — this session's delegation outcome is still pending (attested-only evidence standard); ${back}, and the entry can be removed again once the session settles clean`);
|
|
@@ -2716,10 +2941,57 @@ export class MemoryEngine {
|
|
|
2716
2941
|
continue;
|
|
2717
2942
|
}
|
|
2718
2943
|
const recorded = parsed.id === undefined
|
|
2719
|
-
? observed.findNote(writeScope, homeRel(writableRoot, f.canonical), planeDigest(f.text))
|
|
2720
|
-
: observed.covers(parsed.id)
|
|
2721
|
-
|
|
2722
|
-
|
|
2944
|
+
? observed.findNote(writeScope, homeRel(writableRoot, f.canonical), planeDigest(f.text))
|
|
2945
|
+
: observed.covers(parsed.id)
|
|
2946
|
+
? observed.find(parsed.id, committedRow?.rev, revOfText(f.text, parsed.id))
|
|
2947
|
+
: undefined;
|
|
2948
|
+
if (recorded !== undefined) {
|
|
2949
|
+
const refuse = () => {
|
|
2950
|
+
report.rejections.push({ path: rel, code: "readonly_layer", reason: "this file appeared while a session held this memory layer read-only (recorded as an unexpected write) — it is not committed as this session's; remove it, or edit it to commit this session's own version" });
|
|
2951
|
+
};
|
|
2952
|
+
if (!carry) {
|
|
2953
|
+
refuse();
|
|
2954
|
+
continue;
|
|
2955
|
+
}
|
|
2956
|
+
const self = { ...(handle.accountLeg !== undefined ? { leg: handle.accountLeg } : {}), ...(lineageSessionId !== undefined ? { sessionId: lineageSessionId } : {}) };
|
|
2957
|
+
if (parsed.id === undefined || committedRow === undefined) {
|
|
2958
|
+
const holders = await this.layerHolders(writeScope, self);
|
|
2959
|
+
await this.sayProvenEnded(holders.ended, report);
|
|
2960
|
+
if (holders.held !== undefined) {
|
|
2961
|
+
refuse();
|
|
2962
|
+
continue;
|
|
2963
|
+
}
|
|
2964
|
+
recordedResidue.add(f.canonical);
|
|
2965
|
+
recordedDisposals.push({ row: recorded, path: f.canonical });
|
|
2966
|
+
}
|
|
2967
|
+
else {
|
|
2968
|
+
const committed = committedRow.scope === writeScope && committedRow.slug === f.slug ? await this.committedContentFor(parsed.id) : undefined;
|
|
2969
|
+
const { disposition, ended } = await this.disposeDivergentSeat({ path: f.canonical, scope: writeScope, entryId: parsed.id, found: f.text, committed, act: "disposing of a recorded unexpected write" }, self, handle);
|
|
2970
|
+
await this.sayProvenEnded(ended, report);
|
|
2971
|
+
switch (disposition.kind) {
|
|
2972
|
+
case "held":
|
|
2973
|
+
case "unkept":
|
|
2974
|
+
case "failed":
|
|
2975
|
+
if (disposition.kind !== "held")
|
|
2976
|
+
report.warnings.push(`${rel}: a recorded unexpected write could not be taken into custody — it stays on the plane, refused: ${disposition.kind === "unkept" ? disposition.detail : this.writeFailureText(disposition.cause)}`);
|
|
2977
|
+
refuse();
|
|
2978
|
+
break;
|
|
2979
|
+
default: {
|
|
2980
|
+
recordedDisposals.push({ row: recorded, path: f.canonical });
|
|
2981
|
+
const kept = disposition.custody !== undefined ? ` as quarantine object ${disposition.custody}` : "";
|
|
2982
|
+
if (disposition.kind === "restored" || disposition.kind === "vacated")
|
|
2983
|
+
report.movedToQuarantine.push(rel);
|
|
2984
|
+
if (disposition.kind === "restored")
|
|
2985
|
+
report.restored.push(rel);
|
|
2986
|
+
report.warnings.push(`${rel}: a recorded unexpected write (an edit of committed entry ${quoteId(parsed.id)} that appeared while a session held this layer read-only, with no writer of this layer running) was taken into custody${kept}${disposition.kind === "writer_kept" ? " — a writer created the file again after it was moved aside, and its bytes are kept" : disposition.kind === "moved_under" ? ` — it changed while it was being moved aside; the newer bytes ${disposition.at === undefined ? "are back on the file" : `are preserved at ${disposition.at}`}` : committed !== undefined ? " and the committed content put back" : " and the file removed (the entry's committed copy stands at its own seat)"}`);
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
continue;
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
else if (layerHeld !== undefined) {
|
|
2993
|
+
stoodAsFound.add(rel);
|
|
2994
|
+
leftForWriter.push(rel);
|
|
2723
2995
|
continue;
|
|
2724
2996
|
}
|
|
2725
2997
|
}
|
|
@@ -2771,8 +3043,13 @@ export class MemoryEngine {
|
|
|
2771
3043
|
}
|
|
2772
3044
|
}
|
|
2773
3045
|
const instructionForm = carry && (isInstructionEntry(fm) || (committedFmHere !== undefined && isInstructionEntry(committedFmHere)));
|
|
2774
|
-
|
|
2775
|
-
|
|
3046
|
+
const unattributedWhy = unattributedSet.has(writeScope, homeRel(writableRoot, f.canonical))
|
|
3047
|
+
? "pre-existed the session under an unresolved foreign session account (crash residue)"
|
|
3048
|
+
: recordedResidue.has(f.canonical)
|
|
3049
|
+
? "appeared while a session held this layer read-only (recorded as an unexpected write) and no writer of this layer is running"
|
|
3050
|
+
: undefined;
|
|
3051
|
+
if (instructionForm && unattributedWhy !== undefined) {
|
|
3052
|
+
await containPollutedRecord(f, `this file ${unattributedWhy} and is instruction-form — its writer cannot be attributed, so it is withheld for host review`);
|
|
2776
3053
|
signalContainment((c) => pushDistinct(c.quarantinedInstruction, rel));
|
|
2777
3054
|
continue;
|
|
2778
3055
|
}
|
|
@@ -2793,11 +3070,11 @@ export class MemoryEngine {
|
|
|
2793
3070
|
...(baseId !== undefined && revByBasePath.get(f.canonical) !== undefined ? { baseRev: revByBasePath.get(f.canonical) } : {}),
|
|
2794
3071
|
slug: f.slug,
|
|
2795
3072
|
scope: writeScope,
|
|
2796
|
-
settleIds: pendingSettleIds,
|
|
2797
3073
|
now: this.now,
|
|
2798
3074
|
actRefused: (path, act) => this.storeActRefusedText(path, act, handle),
|
|
2799
3075
|
});
|
|
2800
3076
|
if (held.ok) {
|
|
3077
|
+
heldThisHarvest.push({ holdId: held.holdId, rel });
|
|
2801
3078
|
report.warnings.push(`${rel}: instruction-form entry HELD — this session's delegation outcome is still pending (attested-only evidence standard); the file was captured off the model-visible plane and commits automatically when every delegation settles clean, disposes to quarantine on a dirty or expired settlement (resolveHold is the host valve)`);
|
|
2802
3079
|
if (held.thirdWriterStrandedAt !== undefined) {
|
|
2803
3080
|
report.warnings.push(`${rel}: a concurrent writer's bytes could not be restored onto the plane while the hold was captured — they are preserved at ${held.thirdWriterStrandedAt} for host recovery`);
|
|
@@ -2831,9 +3108,9 @@ export class MemoryEngine {
|
|
|
2831
3108
|
report.warnings.push(`${rel}: the entry's committed external-origin marker was carried in a legacy byte form — normalized into the typed origin field (the marker follows the content)`);
|
|
2832
3109
|
}
|
|
2833
3110
|
}
|
|
2834
|
-
else if (carry &&
|
|
3111
|
+
else if (carry && unattributedWhy !== undefined) {
|
|
2835
3112
|
fm.origin = { taint: "external", cause: "unattributed", at: this.now() };
|
|
2836
|
-
report.warnings.push(`${rel}: this file
|
|
3113
|
+
report.warnings.push(`${rel}: this file ${unattributedWhy} — committed with an external-origin marker (cause "unattributed"), not under this session's name`);
|
|
2837
3114
|
}
|
|
2838
3115
|
else if (carry && pollutedReason !== undefined) {
|
|
2839
3116
|
fm.origin = mintOrigin();
|
|
@@ -2926,8 +3203,24 @@ export class MemoryEngine {
|
|
|
2926
3203
|
}
|
|
2927
3204
|
else {
|
|
2928
3205
|
const txnId = uuidv7();
|
|
2929
|
-
const
|
|
3206
|
+
const stagedRows = () => {
|
|
3207
|
+
const own = patches.filter((p) => p.op !== "delete" && p.entry !== undefined).map((p) => ({ entryId: p.id, rev: p.entry.rev, ...(p.entry.frontmatter.origin !== undefined ? { marked: true } : {}) }));
|
|
3208
|
+
const others = foreignWriters?.candidates ?? [];
|
|
3209
|
+
return [...own, ...others.flatMap((sessionId) => own.map((r) => ({ ...r, sessionId, attribution: "overlap" })))];
|
|
3210
|
+
};
|
|
3211
|
+
const pendingRows = stagedRows();
|
|
2930
3212
|
let lineageArmed = lineageSessionId !== undefined && pendingRows.length > 0;
|
|
3213
|
+
const dropStaging = async (loud) => {
|
|
3214
|
+
if (!lineageArmed)
|
|
3215
|
+
return;
|
|
3216
|
+
lineageArmed = false;
|
|
3217
|
+
try {
|
|
3218
|
+
await discardLineagePending(this.governanceStore, txnId);
|
|
3219
|
+
}
|
|
3220
|
+
catch (err) {
|
|
3221
|
+
loud?.(err);
|
|
3222
|
+
}
|
|
3223
|
+
};
|
|
2931
3224
|
if (lineageArmed) {
|
|
2932
3225
|
try {
|
|
2933
3226
|
await stageLineagePending(this.governanceStore, txnId, lineageSessionId, pendingRows, this.now, this.incarnation.incarnationOf(lineageSessionId));
|
|
@@ -2938,223 +3231,242 @@ export class MemoryEngine {
|
|
|
2938
3231
|
return report;
|
|
2939
3232
|
}
|
|
2940
3233
|
}
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
3234
|
+
let commitReached = false;
|
|
3235
|
+
try {
|
|
3236
|
+
const preCommitRead = lineageSessionId !== undefined ? await this.sessionCaptureOptOutOrFault(lineageSessionId) : { fault: false, record: undefined };
|
|
3237
|
+
if (preCommitRead.record !== undefined || preCommitRead.fault) {
|
|
3238
|
+
report.warnings.push(preCommitRead.record !== undefined
|
|
3239
|
+
? `harvest admitted nothing: a memory capture opt-out record landed for this session while the harvest was collecting — the assembled batch was discarded before commit`
|
|
3240
|
+
: `harvest admitted nothing: the capture opt-out record store became unreadable while the harvest was collecting — the assembled batch was discarded fail-closed (an indeterminate opt-out state must not commit)`);
|
|
3241
|
+
const preFindings = this.backend.drainInboundFindings?.();
|
|
3242
|
+
if (preFindings !== undefined && preFindings.length > 0)
|
|
3243
|
+
report.inboundFindings = preFindings;
|
|
3244
|
+
return report;
|
|
3245
|
+
}
|
|
3246
|
+
let preCommit = lineageSessionId !== undefined ? await this.sessionPollution(lineageSessionId) : undefined;
|
|
3247
|
+
if (carry && preCommit === undefined && pollutedReason === undefined && writeScope !== null) {
|
|
3248
|
+
let late;
|
|
2944
3249
|
try {
|
|
2945
|
-
await
|
|
3250
|
+
late = await this.foreignWriterExposure({ layer: writeScope, since: handle.planeBaseline?.at ?? 0, self: { ...(lineageSessionId !== undefined ? { sessionId: lineageSessionId } : {}), ...(handle.accountLeg !== undefined ? { leg: handle.accountLeg } : {}) }, report });
|
|
2946
3251
|
}
|
|
2947
3252
|
catch {
|
|
3253
|
+
late = { candidates: foreignWriters?.candidates ?? [], state: "unknown", dirty: [{ sessionId: "(session account unreadable)", state: "unknown" }] };
|
|
2948
3254
|
}
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
if (preFindings !== undefined && preFindings.length > 0)
|
|
2955
|
-
report.inboundFindings = preFindings;
|
|
2956
|
-
return report;
|
|
2957
|
-
}
|
|
2958
|
-
const preCommit = lineageSessionId !== undefined ? await this.sessionPollution(lineageSessionId) : undefined;
|
|
2959
|
-
if (preCommit !== undefined && !carry) {
|
|
2960
|
-
if (lineageArmed) {
|
|
2961
|
-
try {
|
|
2962
|
-
await discardLineagePending(this.governanceStore, txnId);
|
|
3255
|
+
const priorCandidates = foreignWriters?.candidates ?? [];
|
|
3256
|
+
foreignWriters = { ...late, candidates: [...new Set([...priorCandidates, ...late.candidates])] };
|
|
3257
|
+
if (late.state !== "clean") {
|
|
3258
|
+
preCommit = { at: this.now(), reason: foreignWriterReason(late), cause: "unattributed" };
|
|
3259
|
+
exposureFrom = "foreign";
|
|
2963
3260
|
}
|
|
2964
|
-
|
|
3261
|
+
else if (lineageArmed && late.candidates.some((c) => !priorCandidates.includes(c))) {
|
|
3262
|
+
try {
|
|
3263
|
+
await stageLineagePending(this.governanceStore, txnId, lineageSessionId, stagedRows(), this.now, this.incarnation.incarnationOf(lineageSessionId));
|
|
3264
|
+
}
|
|
3265
|
+
catch (err) {
|
|
3266
|
+
report.ok = false;
|
|
3267
|
+
report.incident = { kind: "sidecar_corrupt", detail: `memory lineage restage refused: ${thrownText(err)}` };
|
|
3268
|
+
return report;
|
|
3269
|
+
}
|
|
2965
3270
|
}
|
|
2966
3271
|
}
|
|
2967
|
-
|
|
2968
|
-
for (const f of records)
|
|
2969
|
-
await containPollutedRecord(f);
|
|
2970
|
-
for (const r of removalDeletes.values())
|
|
2971
|
-
await restoreRemoved(r.file);
|
|
2972
|
-
patchReport = { applied: [], conflicts: [] };
|
|
2973
|
-
}
|
|
2974
|
-
else {
|
|
2975
|
-
if (carry && preCommit !== undefined && pollutedReason === undefined) {
|
|
3272
|
+
if (preCommit !== undefined && !carry) {
|
|
2976
3273
|
pollutedReason = preCommit.reason;
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
const
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
}
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
3274
|
+
for (const f of records)
|
|
3275
|
+
await containPollutedRecord(f);
|
|
3276
|
+
for (const r of removalDeletes.values())
|
|
3277
|
+
await restoreRemoved(r.file);
|
|
3278
|
+
patchReport = { applied: [], conflicts: [] };
|
|
3279
|
+
}
|
|
3280
|
+
else {
|
|
3281
|
+
if (carry && preCommit !== undefined && pollutedReason === undefined) {
|
|
3282
|
+
pollutedReason = preCommit.reason;
|
|
3283
|
+
pollutionCause = preCommit.cause;
|
|
3284
|
+
try {
|
|
3285
|
+
for (const fresh of heldThisHarvest.splice(0)) {
|
|
3286
|
+
const d = await disposeHold(this.governanceStore, { holdId: fresh.holdId, terminal: "dirty" });
|
|
3287
|
+
if (!d.ok)
|
|
3288
|
+
continue;
|
|
3289
|
+
signalContainment((c) => {
|
|
3290
|
+
c.heldInstruction = c.heldInstruction.filter((p) => p !== fresh.rel);
|
|
3291
|
+
c.disposedHolds.push({ relPath: fresh.rel, terminal: "dirty" });
|
|
3292
|
+
});
|
|
3293
|
+
report.warnings.push(`${fresh.rel}: held instruction entry DISPOSED (dirty): ${withheldWhy()}${d.quarantineName !== undefined ? ` — captured bytes moved to control-plane quarantine (${d.quarantineName})` : ""}`);
|
|
2996
3294
|
}
|
|
2997
|
-
keptPatches.push(p);
|
|
2998
|
-
continue;
|
|
2999
3295
|
}
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3296
|
+
catch (err) {
|
|
3297
|
+
report.ok = false;
|
|
3298
|
+
report.incident = { kind: "sidecar_corrupt", detail: `memory instruction hold disposal refused before the commit: ${thrownText(err)}` };
|
|
3299
|
+
return report;
|
|
3003
3300
|
}
|
|
3004
|
-
const
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
await
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
if (p.op === "add" && modelIdAdds.has(p.id)) {
|
|
3022
|
-
const projection = pendingProjections.find((pp) => pp.entry.id === p.id);
|
|
3023
|
-
const flipRec = projection !== undefined ? records.find((r) => r.canonical === projection.path) : undefined;
|
|
3024
|
-
if (flipRec === undefined) {
|
|
3025
|
-
droppedIds.add(p.id);
|
|
3026
|
-
report.warnings.push(`entry ${p.id} was withdrawn from this commit: its projection record could not be located for the marked-commit id re-mint — the file stays on disk and the next harvest re-judges it`);
|
|
3027
|
-
continue;
|
|
3028
|
-
}
|
|
3029
|
-
const idless = serializeEntryFile({ id: "", frontmatter: p.entry.frontmatter, body: p.entry.body }).replace(/^id:[ \t]*$\r?\n/m, "");
|
|
3030
|
-
try {
|
|
3031
|
-
this.refuseOutsideStore(flipRec.canonical, "re-minting a marked commit's id", handle);
|
|
3032
|
-
writeFileNoFollow(flipRec.canonical, idless);
|
|
3033
|
-
}
|
|
3034
|
-
catch (err) {
|
|
3035
|
-
report.rejections.push({
|
|
3036
|
-
path: flipRec.rel,
|
|
3037
|
-
code: "filename",
|
|
3038
|
-
reason: `memory write blocked: an external-origin commit does not adopt the file's model-written entry id and its frontmatter could not be rewritten (${this.writeFailureText(err)}) — remove the "id:" line so it can be committed under an engine-minted id`,
|
|
3039
|
-
});
|
|
3040
|
-
droppedIds.add(p.id);
|
|
3301
|
+
const keptPatches = [];
|
|
3302
|
+
const droppedIds = new Set();
|
|
3303
|
+
for (const p of patches) {
|
|
3304
|
+
if (p.op === "delete") {
|
|
3305
|
+
const removed = removalDeletes.get(p.id);
|
|
3306
|
+
const committedFm = removed?.form ?? (await this.committedFrontmatterFor(p.id));
|
|
3307
|
+
if (committedFm !== undefined ? isInstructionEntry(committedFm) : removed !== undefined) {
|
|
3308
|
+
const rec = records.find((r) => (handle.baseIds.get(r.canonical) ?? r.parsed.id) === p.id && r.parsed.frontmatter.deleted === true);
|
|
3309
|
+
if (rec !== undefined) {
|
|
3310
|
+
await containPollutedRecord(rec);
|
|
3311
|
+
signalContainment((c) => pushDistinct(c.quarantinedInstruction, rec.rel));
|
|
3312
|
+
}
|
|
3313
|
+
else if (removed !== undefined) {
|
|
3314
|
+
const back = await restoreRemoved(removed.file);
|
|
3315
|
+
const unread = committedFm === undefined ? " (its committed form could not be read, so it is withheld as one)" : "";
|
|
3316
|
+
report.rejections.push({ path: removed.file.relPath, code: "polluted", reason: `memory deletion withheld${unread}: ${withheldWhy()} — ${back}` });
|
|
3317
|
+
}
|
|
3041
3318
|
continue;
|
|
3042
3319
|
}
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
p.id = p.entry.id;
|
|
3046
|
-
projection.idCompletion = true;
|
|
3047
|
-
report.warnings.push(`${flipRec.rel}: the file's model-written id was not adopted for this external-origin commit — committed under an engine-minted id (a marked entry's index/search handles carry no model-authored bytes)`);
|
|
3048
|
-
}
|
|
3049
|
-
}
|
|
3050
|
-
keptPatches.push(p);
|
|
3051
|
-
}
|
|
3052
|
-
patches.length = 0;
|
|
3053
|
-
patches.push(...keptPatches);
|
|
3054
|
-
for (let pi = pendingProjections.length - 1; pi >= 0; pi--) {
|
|
3055
|
-
if (droppedIds.has(pendingProjections[pi].entry.id))
|
|
3056
|
-
pendingProjections.splice(pi, 1);
|
|
3057
|
-
}
|
|
3058
|
-
const restagedRows = patches.filter((p) => p.op !== "delete" && p.entry !== undefined).map((p) => ({ entryId: p.id, rev: p.entry.rev, ...(p.entry.frontmatter.origin !== undefined ? { marked: true } : {}) }));
|
|
3059
|
-
if (lineageArmed) {
|
|
3060
|
-
if (restagedRows.length > 0) {
|
|
3061
|
-
try {
|
|
3062
|
-
await stageLineagePending(this.governanceStore, txnId, lineageSessionId, restagedRows, this.now, this.incarnation.incarnationOf(lineageSessionId));
|
|
3063
|
-
}
|
|
3064
|
-
catch (err) {
|
|
3065
|
-
report.ok = false;
|
|
3066
|
-
report.incident = { kind: "sidecar_corrupt", detail: `memory lineage restage refused: ${thrownText(err)}` };
|
|
3067
|
-
return report;
|
|
3320
|
+
keptPatches.push(p);
|
|
3321
|
+
continue;
|
|
3068
3322
|
}
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
await discardLineagePending(this.governanceStore, txnId);
|
|
3323
|
+
if (p.entry === undefined) {
|
|
3324
|
+
keptPatches.push(p);
|
|
3325
|
+
continue;
|
|
3073
3326
|
}
|
|
3074
|
-
|
|
3075
|
-
|
|
3327
|
+
const committedFm = await this.committedFrontmatterFor(p.id);
|
|
3328
|
+
if (isInstructionEntry(p.entry.frontmatter) || (committedFm !== undefined && isInstructionEntry(committedFm))) {
|
|
3329
|
+
const projection = pendingProjections.find((pp) => pp.entry.id === p.id);
|
|
3330
|
+
const rec = projection !== undefined ? records.find((r) => r.canonical === projection.path) : undefined;
|
|
3331
|
+
if (rec !== undefined) {
|
|
3332
|
+
await containPollutedRecord(rec);
|
|
3333
|
+
signalContainment((c) => pushDistinct(c.quarantinedInstruction, rec.rel));
|
|
3334
|
+
}
|
|
3335
|
+
droppedIds.add(p.id);
|
|
3336
|
+
continue;
|
|
3076
3337
|
}
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3338
|
+
if (p.entry.frontmatter.origin === undefined) {
|
|
3339
|
+
p.entry.frontmatter.origin = mintOrigin();
|
|
3340
|
+
p.entry.rev = computeEntryRev(p.entry);
|
|
3341
|
+
for (const pp of pendingProjections)
|
|
3342
|
+
if (pp.entry.id === p.id)
|
|
3343
|
+
pp.needed = true;
|
|
3344
|
+
if (p.op === "add" && modelIdAdds.has(p.id)) {
|
|
3345
|
+
const projection = pendingProjections.find((pp) => pp.entry.id === p.id);
|
|
3346
|
+
const flipRec = projection !== undefined ? records.find((r) => r.canonical === projection.path) : undefined;
|
|
3347
|
+
if (flipRec === undefined) {
|
|
3348
|
+
droppedIds.add(p.id);
|
|
3349
|
+
report.warnings.push(`entry ${p.id} was withdrawn from this commit: its projection record could not be located for the marked-commit id re-mint — the file stays on disk and the next harvest re-judges it`);
|
|
3350
|
+
continue;
|
|
3351
|
+
}
|
|
3352
|
+
const idless = serializeEntryFile({ id: "", frontmatter: p.entry.frontmatter, body: p.entry.body }).replace(/^id:[ \t]*$\r?\n/m, "");
|
|
3353
|
+
try {
|
|
3354
|
+
this.refuseOutsideStore(flipRec.canonical, "re-minting a marked commit's id", handle);
|
|
3355
|
+
writeFileNoFollow(flipRec.canonical, idless);
|
|
3356
|
+
}
|
|
3357
|
+
catch (err) {
|
|
3358
|
+
report.rejections.push({
|
|
3359
|
+
path: flipRec.rel,
|
|
3360
|
+
code: "filename",
|
|
3361
|
+
reason: `memory write blocked: an external-origin commit does not adopt the file's model-written entry id and its frontmatter could not be rewritten (${this.writeFailureText(err)}) — remove the "id:" line so it can be committed under an engine-minted id`,
|
|
3362
|
+
});
|
|
3363
|
+
droppedIds.add(p.id);
|
|
3364
|
+
continue;
|
|
3365
|
+
}
|
|
3366
|
+
p.entry.id = uuidv7();
|
|
3367
|
+
p.entry.rev = computeEntryRev(p.entry);
|
|
3368
|
+
p.id = p.entry.id;
|
|
3369
|
+
projection.idCompletion = true;
|
|
3370
|
+
report.warnings.push(`${flipRec.rel}: the file's model-written id was not adopted for this external-origin commit — committed under an engine-minted id (a marked entry's index/search handles carry no model-authored bytes)`);
|
|
3371
|
+
}
|
|
3109
3372
|
}
|
|
3373
|
+
keptPatches.push(p);
|
|
3110
3374
|
}
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
});
|
|
3117
|
-
report.warnings.push(`${relative(handle.memoryDir, join(writableRoot, r.rel))}: earlier notes about this file committing under a fresh id are superseded — its commit was WITHDRAWN this harvest (deferred to the next)`);
|
|
3375
|
+
patches.length = 0;
|
|
3376
|
+
patches.push(...keptPatches);
|
|
3377
|
+
for (let pi = pendingProjections.length - 1; pi >= 0; pi--) {
|
|
3378
|
+
if (droppedIds.has(pendingProjections[pi].entry.id))
|
|
3379
|
+
pendingProjections.splice(pi, 1);
|
|
3118
3380
|
}
|
|
3381
|
+
const restagedRows = stagedRows();
|
|
3119
3382
|
if (lineageArmed) {
|
|
3120
|
-
|
|
3121
|
-
if (remaining.length > 0) {
|
|
3383
|
+
if (restagedRows.length > 0) {
|
|
3122
3384
|
try {
|
|
3123
|
-
await stageLineagePending(this.governanceStore, txnId, lineageSessionId,
|
|
3385
|
+
await stageLineagePending(this.governanceStore, txnId, lineageSessionId, restagedRows, this.now, this.incarnation.incarnationOf(lineageSessionId));
|
|
3124
3386
|
}
|
|
3125
3387
|
catch (err) {
|
|
3126
3388
|
report.ok = false;
|
|
3127
|
-
report.incident = { kind: "sidecar_corrupt", detail: `memory lineage restage refused
|
|
3389
|
+
report.incident = { kind: "sidecar_corrupt", detail: `memory lineage restage refused: ${thrownText(err)}` };
|
|
3128
3390
|
return report;
|
|
3129
3391
|
}
|
|
3130
3392
|
}
|
|
3131
3393
|
else {
|
|
3132
|
-
|
|
3133
|
-
await discardLineagePending(this.governanceStore, txnId);
|
|
3134
|
-
}
|
|
3135
|
-
catch (err) {
|
|
3136
|
-
report.warnings.push(`memory lineage stage for withheld entries could not be discarded — their ids stay latched until the host adjudicates pending transaction ${txnId}: ${thrownText(err)}`);
|
|
3137
|
-
}
|
|
3138
|
-
lineageArmed = false;
|
|
3394
|
+
await dropStaging((err) => report.warnings.push(`memory lineage stage for withdrawn instruction entries could not be discarded — their ids stay latched (memory reads refuse them) until the host adjudicates pending transaction ${txnId}: ${thrownText(err)}`));
|
|
3139
3395
|
}
|
|
3140
3396
|
}
|
|
3141
3397
|
}
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3398
|
+
const debtStage = pendingProjections
|
|
3399
|
+
.filter((p) => p.idCompletion === true)
|
|
3400
|
+
.map((p) => {
|
|
3401
|
+
const seat = seatOf(p.path);
|
|
3402
|
+
const replaces = staleReplacedDebts.get(debtSeat(seat.scope, seat.rel));
|
|
3403
|
+
return { ...seat, entryId: p.entry.id, rev: p.entry.rev, ...(replaces !== undefined ? { replaces } : {}) };
|
|
3404
|
+
});
|
|
3405
|
+
if (debtStage.length > 0) {
|
|
3406
|
+
let refusedStage = [];
|
|
3148
3407
|
try {
|
|
3149
|
-
|
|
3408
|
+
refusedStage = stageProjectionDebts(this.controlDir, debtStage, this.now).refused;
|
|
3150
3409
|
}
|
|
3151
|
-
catch {
|
|
3410
|
+
catch (err) {
|
|
3411
|
+
report.warnings.push(`memory projection-debt staging failed — duplicate-admission protection for this harvest's id write-backs is degraded (a failed write-back could re-admit its file as a duplicate until the next materialize repairs the plane): ${thrownText(err)}`);
|
|
3412
|
+
}
|
|
3413
|
+
if (refusedStage.length > 0) {
|
|
3414
|
+
const refusedIds = new Set(refusedStage.map((r) => r.entryId));
|
|
3415
|
+
for (let i = patches.length - 1; i >= 0; i--) {
|
|
3416
|
+
const p = patches[i];
|
|
3417
|
+
if (p.op !== "delete" && refusedIds.has(p.id))
|
|
3418
|
+
patches.splice(i, 1);
|
|
3419
|
+
}
|
|
3420
|
+
for (let i = pendingProjections.length - 1; i >= 0; i--) {
|
|
3421
|
+
const proj = pendingProjections[i];
|
|
3422
|
+
if (refusedIds.has(proj.entry.id)) {
|
|
3423
|
+
idByBasePath.delete(proj.path);
|
|
3424
|
+
revByBasePath.delete(proj.path);
|
|
3425
|
+
pendingProjections.splice(i, 1);
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
for (const r of refusedStage) {
|
|
3429
|
+
report.rejections.push({
|
|
3430
|
+
path: relative(handle.memoryDir, join(writableRoot, r.rel)),
|
|
3431
|
+
code: "deferred",
|
|
3432
|
+
reason: "memory write deferred: a concurrent writer's projection-debt claim stands at this seat — retried next harvest (committing without a protected id write-back could duplicate the concurrent entry)",
|
|
3433
|
+
});
|
|
3434
|
+
report.warnings.push(`${relative(handle.memoryDir, join(writableRoot, r.rel))}: earlier notes about this file committing under a fresh id are superseded — its commit was WITHDRAWN this harvest (deferred to the next)`);
|
|
3435
|
+
}
|
|
3436
|
+
if (lineageArmed) {
|
|
3437
|
+
const remaining = stagedRows();
|
|
3438
|
+
if (remaining.length > 0) {
|
|
3439
|
+
try {
|
|
3440
|
+
await stageLineagePending(this.governanceStore, txnId, lineageSessionId, remaining, this.now, this.incarnation.incarnationOf(lineageSessionId));
|
|
3441
|
+
}
|
|
3442
|
+
catch (err) {
|
|
3443
|
+
report.ok = false;
|
|
3444
|
+
report.incident = { kind: "sidecar_corrupt", detail: `memory lineage restage refused after a withheld projection-debt seat: ${thrownText(err)}` };
|
|
3445
|
+
return report;
|
|
3446
|
+
}
|
|
3447
|
+
}
|
|
3448
|
+
else {
|
|
3449
|
+
await dropStaging((err) => report.warnings.push(`memory lineage stage for withheld entries could not be discarded — their ids stay latched until the host adjudicates pending transaction ${txnId}: ${thrownText(err)}`));
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
3152
3452
|
}
|
|
3153
3453
|
}
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3454
|
+
try {
|
|
3455
|
+
patchReport = await this.backend.applyPatches(patches, { anchoredRoot: handle.memoryDir });
|
|
3456
|
+
}
|
|
3457
|
+
catch (err) {
|
|
3458
|
+
report.ok = false;
|
|
3459
|
+
report.incident = { kind: "sidecar_corrupt", detail: `memory commit refused: ${this.writeFailureText(err)}` };
|
|
3460
|
+
return report;
|
|
3461
|
+
}
|
|
3462
|
+
commitReached = true;
|
|
3157
3463
|
}
|
|
3464
|
+
}
|
|
3465
|
+
finally {
|
|
3466
|
+
if (!commitReached)
|
|
3467
|
+
await dropStaging();
|
|
3468
|
+
}
|
|
3469
|
+
if (commitReached) {
|
|
3158
3470
|
if (lineageArmed) {
|
|
3159
3471
|
try {
|
|
3160
3472
|
await recordLineageCredential(this.governanceStore, txnId, patchReport.applied.filter((a) => a.op !== "delete").map((a) => a.id), this.now);
|
|
@@ -3205,8 +3517,62 @@ export class MemoryEngine {
|
|
|
3205
3517
|
report.warnings.push(`memory challenge of this harvest's commits failed (session polluted post-commit): ${thrownText(err)}`);
|
|
3206
3518
|
}
|
|
3207
3519
|
}
|
|
3520
|
+
if (carry && pollutedReason === undefined && foreignWriters !== undefined && foreignWriters.candidates.length > 0) {
|
|
3521
|
+
const appliedNonDelete = patchReport.applied.filter((a) => a.op !== "delete").map((a) => a.id);
|
|
3522
|
+
try {
|
|
3523
|
+
for (const other of foreignWriters.candidates) {
|
|
3524
|
+
const rec = recalledForAnyIdentity(this.pollutedSessions, other) ?? (await readSessionPollution(this.governanceStore, other));
|
|
3525
|
+
if (rec === undefined)
|
|
3526
|
+
continue;
|
|
3527
|
+
await this.challengeAndAnnounce(appliedNonDelete.map((id) => ({ eventId: `pollution:${other}:${rec.at}:${id}`, entryId: id, reason: `challenged: the contributing session was marked polluted` })));
|
|
3528
|
+
}
|
|
3529
|
+
}
|
|
3530
|
+
catch (err) {
|
|
3531
|
+
report.warnings.push(`memory challenge of this harvest's commits failed (another writer of the layer marked post-commit): ${thrownText(err)}`);
|
|
3532
|
+
}
|
|
3533
|
+
}
|
|
3208
3534
|
}
|
|
3209
3535
|
}
|
|
3536
|
+
try {
|
|
3537
|
+
const standingCopies = await this.governanceStore.listObjects("quarantine");
|
|
3538
|
+
const committedNow = standingCopies.length === 0 ? [] : patches.filter((p) => p.op !== "delete" && p.entry !== undefined && patchReport.applied.some((a) => a.id === p.id && a.op !== "delete")).map((p) => p.entry);
|
|
3539
|
+
const unreadCopies = new Map();
|
|
3540
|
+
const readCopies = async (names) => {
|
|
3541
|
+
const index = await this.quarantineCopyIndex(names);
|
|
3542
|
+
for (const [name, fault] of index.unread)
|
|
3543
|
+
unreadCopies.set(name, fault);
|
|
3544
|
+
return index;
|
|
3545
|
+
};
|
|
3546
|
+
let standingIndex;
|
|
3547
|
+
const standingCopyIndex = async () => (standingIndex ??= await readCopies(standingCopies));
|
|
3548
|
+
if (committedNow.length > 0)
|
|
3549
|
+
await this.challengeQuarantineMatches(committedNow, await standingCopyIndex());
|
|
3550
|
+
const baselineIds = new Set(handle.baseIds.values());
|
|
3551
|
+
for (const o of containedObjects) {
|
|
3552
|
+
const kept = o.record.parsed.id;
|
|
3553
|
+
const keptRow = kept !== undefined && !baselineIds.has(kept) ? await this.committedRowOf(kept) : undefined;
|
|
3554
|
+
if (kept !== undefined && typeof keptRow === "object" && keptRow.scope === writeScope && keptRow.slug === o.record.slug) {
|
|
3555
|
+
await this.challengeAndAnnounce([{ eventId: `quarantine-match:${o.name}:${kept}`, entryId: kept, reason: "challenged: a quarantined copy holds this entry's committed content", challengedRev: keptRow.rev }]);
|
|
3556
|
+
continue;
|
|
3557
|
+
}
|
|
3558
|
+
const atSeat = (await this.listCommittedHeaders([writeScope])).find((h) => h.slug === o.record.slug);
|
|
3559
|
+
if (atSeat !== undefined)
|
|
3560
|
+
await this.challengeQuarantineMatches(await this.committedAuditFace().getByIds([atSeat.id]), await readCopies([o.name]));
|
|
3561
|
+
}
|
|
3562
|
+
if (!this.quarantineStockMatched.has(writeScope) && standingCopies.length > 0) {
|
|
3563
|
+
const headers = await this.listCommittedHeaders([writeScope]);
|
|
3564
|
+
await this.challengeQuarantineMatches(await this.committedAuditFace().getByIds(headers.map((h) => h.id)), await standingCopyIndex());
|
|
3565
|
+
if (unreadCopies.size === 0)
|
|
3566
|
+
this.quarantineStockMatched.add(writeScope);
|
|
3567
|
+
}
|
|
3568
|
+
if (unreadCopies.size > 0) {
|
|
3569
|
+
const [first, fault] = [...unreadCopies][0];
|
|
3570
|
+
report.warnings.push(`memory quarantine-match check could not read ${unreadCopies.size} standing quarantine cop${unreadCopies.size === 1 ? "y" : "ies"} (${inlineUntrusted(first, 80)}: ${inlineUntrusted(fault, 160)}) — the others were compared; committed entries an unread copy holds may stay unchallenged until a later harvest`);
|
|
3571
|
+
}
|
|
3572
|
+
}
|
|
3573
|
+
catch (err) {
|
|
3574
|
+
report.warnings.push(`memory quarantine-match check could not complete (committed entries a quarantined copy holds may stay unchallenged until a later harvest): ${thrownText(err)}`);
|
|
3575
|
+
}
|
|
3210
3576
|
const appliedIds = new Set(patchReport.applied.filter((a) => a.op !== "delete").map((a) => a.id));
|
|
3211
3577
|
const planeAfterFailedWriteBack = this.zeroCopy
|
|
3212
3578
|
? "this plane is the store itself: the next read adopts them as an out-of-session edit unless the committed copy is put back first"
|
|
@@ -3250,6 +3616,25 @@ export class MemoryEngine {
|
|
|
3250
3616
|
if (p.idCompletion === true && ((committed === undefined && !committedRead.fault) || planeHoldsCommitted))
|
|
3251
3617
|
debtClears.push({ ...pSeat, entryId: p.entry.id });
|
|
3252
3618
|
}
|
|
3619
|
+
if (layerHeld !== undefined && leftForWriter.length > 0) {
|
|
3620
|
+
report.warnings.push(`${leftForWriter.length} file(s) that stood on this memory layer when this session started, and that it was never given, were left in place for the layer's running writer to commit (${layerHeld.why.join("; ")}): ${leftForWriter.slice(0, 8).join(", ")}${leftForWriter.length > 8 ? ", …" : ""}`);
|
|
3621
|
+
}
|
|
3622
|
+
const settledRecords = recordedDisposals
|
|
3623
|
+
.filter((d) => {
|
|
3624
|
+
if (d.row.scope !== writeScope || d.row.rel !== homeRel(writableRoot, d.path))
|
|
3625
|
+
return false;
|
|
3626
|
+
const standing = readNoFollowSafe(d.path);
|
|
3627
|
+
return standing === undefined || (d.row.entryId === undefined ? planeDigest(standing) : revOfText(standing, d.row.entryId)) !== d.row.observedRev;
|
|
3628
|
+
})
|
|
3629
|
+
.map((d) => d.row);
|
|
3630
|
+
if (settledRecords.length > 0) {
|
|
3631
|
+
try {
|
|
3632
|
+
retireLayerObservations(this.controlDir, settledRecords);
|
|
3633
|
+
}
|
|
3634
|
+
catch (err) {
|
|
3635
|
+
report.warnings.push(`memory layer-observation retirement failed — the disposed of records stay (the next harvest finds their bytes gone or disposes of them again): ${thrownText(err)}`);
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3253
3638
|
if (debtClears.length > 0) {
|
|
3254
3639
|
try {
|
|
3255
3640
|
settleProjectionDebts(this.controlDir, debtClears);
|
|
@@ -3273,7 +3658,9 @@ export class MemoryEngine {
|
|
|
3273
3658
|
if (await restorePollutedIndex())
|
|
3274
3659
|
signalContainment((c) => (c.indexRolledBack = true));
|
|
3275
3660
|
report.warnings.push(carry
|
|
3276
|
-
?
|
|
3661
|
+
? exposureFrom === "foreign"
|
|
3662
|
+
? `memory entries this session wrote while another writer of the layer was externally exposed or of unknown state were committed with an external-origin marker (cause "unattributed"); its index prose additions were not retained: ${inlineUntrusted(pollutedReason, 200)}`
|
|
3663
|
+
: `memory entries from this externally exposed session were committed with an external-origin marker; its index prose additions were not retained: ${inlineUntrusted(pollutedReason, 200)}`
|
|
3277
3664
|
: `memory harvest committed nothing this session: ${inlineUntrusted(pollutedReason, 200)}`);
|
|
3278
3665
|
}
|
|
3279
3666
|
else if (carry && sessionPending) {
|
|
@@ -3288,9 +3675,10 @@ export class MemoryEngine {
|
|
|
3288
3675
|
if (!indexGate.contained)
|
|
3289
3676
|
handle.indexOnDiskUntrusted = true;
|
|
3290
3677
|
}
|
|
3291
|
-
const
|
|
3678
|
+
const headerSource = layerHeld !== undefined ? this.layerCommittedView(writeScope) : this.backend;
|
|
3679
|
+
const headers = await headerSource.listHeaders([...new Set([...handle.scopes, writeScope])]);
|
|
3292
3680
|
handle.indexText = await this.rebuildIndex(handle, headers, { write: true, ignoreOnDisk: indexGate !== undefined }, report.warnings);
|
|
3293
|
-
await this.rebaseline(handle, new Set([...(report.degraded?.pending ?? []), ...stoodAsFound, ...records.filter((r) => r.parsed.unclosed === true).map((r) => r.rel)]), new Set(report.rejections.map((r) => r.path)));
|
|
3681
|
+
await this.rebaseline(handle, new Set([...(report.degraded?.pending ?? []), ...stoodAsFound, ...records.filter((r) => r.parsed.unclosed === true).map((r) => r.rel)]), new Set(report.rejections.map((r) => r.path)), report.degraded === undefined ? startedAt : (handle.planeBaseline?.at ?? startedAt));
|
|
3294
3682
|
if (carry && lineageSessionId !== undefined && report.degraded === undefined) {
|
|
3295
3683
|
const deferredSeats = [...new Set(report.rejections.filter((r) => r.code === "deferred").map((r) => r.path))];
|
|
3296
3684
|
const shown = deferredSeats.slice(0, MAX_DISCLOSED_DEFERRED_SEATS);
|
|
@@ -3512,8 +3900,8 @@ export class MemoryEngine {
|
|
|
3512
3900
|
async resolveHold(holdId, action, requestId) {
|
|
3513
3901
|
await resolveHoldRecord(this.governanceStore, { holdId, action, requestId, now: this.now });
|
|
3514
3902
|
}
|
|
3515
|
-
async resolveSessionAccount(sessionId, requestId) {
|
|
3516
|
-
await resolveSessionAccountRecord(this.governanceStore, { sessionId, requestId, now: this.now });
|
|
3903
|
+
async resolveSessionAccount(sessionId, requestId, leg) {
|
|
3904
|
+
await resolveSessionAccountRecord(this.governanceStore, { sessionId, requestId, leg, now: this.now });
|
|
3517
3905
|
}
|
|
3518
3906
|
async readDelegationSettlements() {
|
|
3519
3907
|
return await effectiveSettlements(this.governanceStore);
|
|
@@ -3522,7 +3910,16 @@ export class MemoryEngine {
|
|
|
3522
3910
|
return await readHolds(this.governanceStore);
|
|
3523
3911
|
}
|
|
3524
3912
|
async readDanglingSessionAccounts(selfSessionId) {
|
|
3525
|
-
|
|
3913
|
+
const ended = [];
|
|
3914
|
+
try {
|
|
3915
|
+
return (await foreignWriterCandidates(this.governanceStore, { since: this.now(), self: { sessionId: selfSessionId }, now: this.now, onEnded: (e) => ended.push(e) })).map((w) => {
|
|
3916
|
+
const { standing: _standing, ...row } = w;
|
|
3917
|
+
return row;
|
|
3918
|
+
});
|
|
3919
|
+
}
|
|
3920
|
+
finally {
|
|
3921
|
+
await this.sayProvenEnded(ended, undefined);
|
|
3922
|
+
}
|
|
3526
3923
|
}
|
|
3527
3924
|
requireConsolidation() {
|
|
3528
3925
|
if (this.consolidation === undefined) {
|
|
@@ -4824,6 +5221,59 @@ export class MemoryEngine {
|
|
|
4824
5221
|
return [];
|
|
4825
5222
|
return this.committedAuditFace().listHeaders(scopes);
|
|
4826
5223
|
}
|
|
5224
|
+
async quarantineCopyIndex(names) {
|
|
5225
|
+
const byContent = new Map();
|
|
5226
|
+
const unread = new Map();
|
|
5227
|
+
for (const n of names) {
|
|
5228
|
+
let bytes;
|
|
5229
|
+
try {
|
|
5230
|
+
bytes = await this.governanceStore.getObject("quarantine", n);
|
|
5231
|
+
}
|
|
5232
|
+
catch (err) {
|
|
5233
|
+
unread.set(n, thrownText(err));
|
|
5234
|
+
continue;
|
|
5235
|
+
}
|
|
5236
|
+
if (bytes === undefined)
|
|
5237
|
+
continue;
|
|
5238
|
+
const key = planeDigest(withoutIdLine(new TextDecoder().decode(bytes)));
|
|
5239
|
+
const bucket = byContent.get(key);
|
|
5240
|
+
if (bucket === undefined)
|
|
5241
|
+
byContent.set(key, [n]);
|
|
5242
|
+
else
|
|
5243
|
+
bucket.push(n);
|
|
5244
|
+
}
|
|
5245
|
+
return { byContent, unread };
|
|
5246
|
+
}
|
|
5247
|
+
async challengeQuarantineMatches(entries, copies) {
|
|
5248
|
+
if (entries.length === 0 || copies.byContent.size === 0)
|
|
5249
|
+
return;
|
|
5250
|
+
const events = [];
|
|
5251
|
+
for (const e of entries) {
|
|
5252
|
+
for (const n of copies.byContent.get(planeDigest(withoutIdLine(serializeEntryFile(e)))) ?? [])
|
|
5253
|
+
events.push({ eventId: `quarantine-match:${n}:${e.id}`, entryId: e.id, reason: "challenged: a quarantined copy holds this entry's committed content", challengedRev: e.rev });
|
|
5254
|
+
}
|
|
5255
|
+
await this.challengeAndAnnounce(events);
|
|
5256
|
+
}
|
|
5257
|
+
quarantineStockMatched = new Set();
|
|
5258
|
+
async entryExposureVerdict(id) {
|
|
5259
|
+
if ((await challengedEntryIds(this.governanceStore)).has(id))
|
|
5260
|
+
return "challenged";
|
|
5261
|
+
const fm = await this.committedFrontmatterFor(id);
|
|
5262
|
+
return fm !== undefined && committedOriginOf(fm) !== undefined ? "marked" : "clean";
|
|
5263
|
+
}
|
|
5264
|
+
async entryIdAtPlanePath(handle, absPath) {
|
|
5265
|
+
const target = canonicalize(absPath);
|
|
5266
|
+
if (!target.endsWith(".md"))
|
|
5267
|
+
return undefined;
|
|
5268
|
+
for (const scope of new Set([...handle.scopes, ...(handle.writeScope !== null ? [handle.writeScope] : [])])) {
|
|
5269
|
+
const home = canonicalize(scopeDirFor(this.memoryDir, this.controlDir, scope));
|
|
5270
|
+
if (!target.startsWith(`${home}${sep}`))
|
|
5271
|
+
continue;
|
|
5272
|
+
const slug = target.slice(home.length + 1, -".md".length).split(sep).join("/");
|
|
5273
|
+
return (await this.listCommittedHeaders([scope])).find((h) => h.slug === slug)?.id;
|
|
5274
|
+
}
|
|
5275
|
+
return undefined;
|
|
5276
|
+
}
|
|
4827
5277
|
static originClearRefusal(code, message, detail) {
|
|
4828
5278
|
const e = new Error(message);
|
|
4829
5279
|
e.code = code;
|
|
@@ -4882,6 +5332,7 @@ export class MemoryEngine {
|
|
|
4882
5332
|
const pending = clearances.find((r) => r.entryId === entryId && r.status === "pending");
|
|
4883
5333
|
if (pending !== undefined)
|
|
4884
5334
|
return await this.completeOriginClearance(pending, input.requestId);
|
|
5335
|
+
const judgedUnder = await readClearanceErasureCount(this.governanceStore);
|
|
4885
5336
|
const face = this.committedAuditFace();
|
|
4886
5337
|
const [committed] = await face.getByIds([entryId]);
|
|
4887
5338
|
if (committed === undefined || committed.frontmatter.deleted === true) {
|
|
@@ -4912,7 +5363,7 @@ export class MemoryEngine {
|
|
|
4912
5363
|
at: this.now(),
|
|
4913
5364
|
entryText: serializeEntryFile(cleared),
|
|
4914
5365
|
};
|
|
4915
|
-
await openOriginClearance(this.governanceStore, row);
|
|
5366
|
+
await openOriginClearance(this.governanceStore, row, judgedUnder);
|
|
4916
5367
|
return await this.completeOriginClearance({ ...row, status: "pending", events: [] }, input.requestId);
|
|
4917
5368
|
}
|
|
4918
5369
|
async completeOriginClearance(row, requestId) {
|
|
@@ -5026,7 +5477,7 @@ export class MemoryEngine {
|
|
|
5026
5477
|
await this.announce(row.scope, { kind: "gate", at: this.now(), items: [`memory entry ${inlineUntrusted(row.entryId, 80)} external-origin marker CLEARED by host request ${JSON.stringify(inlineUntrusted(requestId, 80))} — re-recorded unmarked (${inlineUntrusted(detail, 160)})`] }, "origin-clearance enqueue");
|
|
5027
5478
|
return { entryId: row.entryId, clearanceId: row.clearanceId, origin: row.origin, landedSlug };
|
|
5028
5479
|
}
|
|
5029
|
-
async rebaseline(handle, keepBaseline = new Set(), uncommittedPaths = new Set()) {
|
|
5480
|
+
async rebaseline(handle, keepBaseline = new Set(), uncommittedPaths = new Set(), windowFrom = this.now()) {
|
|
5030
5481
|
const writeScope = handle.writeScope;
|
|
5031
5482
|
if (writeScope === null)
|
|
5032
5483
|
return;
|
|
@@ -5088,7 +5539,7 @@ export class MemoryEngine {
|
|
|
5088
5539
|
handle.baseRevs = baseRevs;
|
|
5089
5540
|
handle.baseIds = baseIds;
|
|
5090
5541
|
const indexOnDisk = readSafe(join(writableRoot, MEMORY_INDEX_FILENAME));
|
|
5091
|
-
handle.planeBaseline = { files: planeFiles, ...(indexOnDisk !== undefined ? { index: indexOnDisk } : {}) };
|
|
5542
|
+
handle.planeBaseline = { files: planeFiles, ...(indexOnDisk !== undefined ? { index: indexOnDisk } : {}), at: windowFrom };
|
|
5092
5543
|
}
|
|
5093
5544
|
async rebuildIndex(handle, headers, opts, warnings) {
|
|
5094
5545
|
const indexBase = handle.writableRoot ?? handle.memoryDir;
|
|
@@ -5309,10 +5760,10 @@ export class MemoryEngine {
|
|
|
5309
5760
|
fault = true;
|
|
5310
5761
|
}
|
|
5311
5762
|
}
|
|
5312
|
-
const viaShadow = this.backend
|
|
5313
|
-
if (viaShadow !== undefined)
|
|
5314
|
-
return { content: viaShadow, fault: false };
|
|
5315
|
-
return { fault };
|
|
5763
|
+
const viaShadow = committedShadowOrFault(this.backend, id);
|
|
5764
|
+
if (!viaShadow.fault && viaShadow.content !== undefined)
|
|
5765
|
+
return { content: viaShadow.content, fault: false };
|
|
5766
|
+
return { fault: fault || viaShadow.fault };
|
|
5316
5767
|
}
|
|
5317
5768
|
async committedFrontmatterFor(id) {
|
|
5318
5769
|
if (!this.zeroCopy) {
|
|
@@ -5325,8 +5776,7 @@ export class MemoryEngine {
|
|
|
5325
5776
|
catch {
|
|
5326
5777
|
}
|
|
5327
5778
|
}
|
|
5328
|
-
|
|
5329
|
-
return text !== undefined ? parseEntryFile(text).frontmatter : undefined;
|
|
5779
|
+
return committedShadowFrontmatter(this.backend, id);
|
|
5330
5780
|
}
|
|
5331
5781
|
async gateDerivedIndex(handle) {
|
|
5332
5782
|
if (handle.writableRoot === null)
|
|
@@ -5339,7 +5789,7 @@ export class MemoryEngine {
|
|
|
5339
5789
|
if (finding === undefined)
|
|
5340
5790
|
return undefined;
|
|
5341
5791
|
const kept = await keepCopiesBeforeOverwrite(text, async (bytes) => {
|
|
5342
|
-
const capture = await captureIntoQuarantine(this.governanceStore, indexPath, bytes
|
|
5792
|
+
const capture = await captureIntoQuarantine(this.governanceStore, indexPath, bytes);
|
|
5343
5793
|
return "name" in capture ? true : capture.failed;
|
|
5344
5794
|
}, () => {
|
|
5345
5795
|
this.refuseOutsideStore(indexPath, "reading the index again after its copy", handle);
|
|
@@ -5383,7 +5833,7 @@ export class MemoryEngine {
|
|
|
5383
5833
|
}
|
|
5384
5834
|
}
|
|
5385
5835
|
async containSuspect(path, content, act, handle) {
|
|
5386
|
-
const capture = await captureIntoQuarantine(this.governanceStore, path, content
|
|
5836
|
+
const capture = await captureIntoQuarantine(this.governanceStore, path, content);
|
|
5387
5837
|
const refused = this.storeActRefusedText(path, act, handle);
|
|
5388
5838
|
if (refused !== undefined)
|
|
5389
5839
|
return { ...("name" in capture ? { dest: capture.name } : {}), removed: false, leftOnPlane: content, detail: "failed" in capture ? `${capture.failed}; ${refused}` : refused };
|
|
@@ -5586,6 +6036,7 @@ function readSafe(path) {
|
|
|
5586
6036
|
return undefined;
|
|
5587
6037
|
}
|
|
5588
6038
|
}
|
|
6039
|
+
const LEDGER_UNREADABLE_CLAUSE = "the session-account ledger could not be read, so a session that writes this layer may be open (the bytes may be its uncommitted edit)";
|
|
5589
6040
|
function readNoFollowSafe(path) {
|
|
5590
6041
|
let fd;
|
|
5591
6042
|
try {
|