@sema-agent/core 7.57.0 → 7.59.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 +1161 -0
- package/README.md +6 -4
- package/dist/agents/cc-peer-directory.js +8 -8
- package/dist/agents/child-model-seat.d.ts +4 -2
- package/dist/agents/child-model-seat.js +5 -3
- package/dist/agents/peer-directory.d.ts +9 -0
- package/dist/agents/peer-directory.js +6 -2
- package/dist/agents/send-message-tool.js +21 -12
- package/dist/agents/subagent-steps.js +2 -4
- package/dist/agents/subagent.js +33 -34
- package/dist/brain/anthropic.js +161 -45
- package/dist/brain/errors.d.ts +9 -3
- package/dist/brain/errors.js +7 -1
- package/dist/brain/failover.js +2 -1
- package/dist/brain/open-responses.js +3 -3
- package/dist/brain/openai.js +103 -53
- package/dist/brain/provider-dialect.d.ts +11 -0
- package/dist/brain/provider-dialect.js +5 -2
- package/dist/brain/reasoning-request.js +5 -4
- package/dist/brain/reasoning.d.ts +19 -0
- package/dist/brain/reasoning.js +17 -2
- package/dist/brain/request-route.d.ts +4 -1
- package/dist/brain/request-route.js +4 -1
- package/dist/brain/route-adjudicator.d.ts +84 -18
- package/dist/brain/route-adjudicator.js +89 -22
- package/dist/brain/route-conformance.js +1 -1
- package/dist/brain/stream-engine.js +84 -49
- package/dist/brain/stream-shared.d.ts +30 -0
- package/dist/brain/stream-shared.js +34 -1
- package/dist/brain/timeout.d.ts +62 -5
- package/dist/brain/timeout.js +93 -6
- package/dist/core/a2a.d.ts +2 -1
- package/dist/core/a2a.js +23 -10
- package/dist/core/account-row.d.ts +61 -0
- package/dist/core/account-row.js +51 -0
- package/dist/core/advisor-verdict.d.ts +2 -1
- package/dist/core/advisor-verdict.js +1 -1
- package/dist/core/allow-entry.d.ts +20 -7
- package/dist/core/allow-entry.js +18 -9
- package/dist/core/approval-object.d.ts +29 -15
- package/dist/core/approval-object.js +47 -19
- package/dist/core/ask-origin.d.ts +21 -2
- package/dist/core/ask-origin.js +5 -1
- package/dist/core/auto-compaction.d.ts +4 -0
- package/dist/core/auto-compaction.js +2 -2
- package/dist/core/auto-mode-directive.d.ts +29 -5
- package/dist/core/auto-mode-directive.js +38 -8
- package/dist/core/background-agent-store.d.ts +16 -3
- package/dist/core/checkpoint-requirements.d.ts +19 -1
- package/dist/core/checkpoint-requirements.js +5 -1
- package/dist/core/checkpoint-store.d.ts +85 -23
- package/dist/core/checkpoint-store.js +31 -9
- package/dist/core/child-clamp-seats.d.ts +29 -0
- package/dist/core/child-clamp-seats.js +56 -1
- package/dist/core/compliance.d.ts +2 -2
- package/dist/core/compliance.js +1 -1
- package/dist/core/effective-path-target.d.ts +8 -2
- package/dist/core/effective-path-target.js +8 -3
- package/dist/core/engine-notice.d.ts +99 -9
- package/dist/core/engine-notice.js +19 -5
- package/dist/core/fs-write-gate-policy.d.ts +4 -2
- package/dist/core/fs-write-gate-policy.js +7 -3
- package/dist/core/gate-fold.js +7 -4
- package/dist/core/gate-lanes.js +19 -6
- package/dist/core/gate-outcome.d.ts +32 -3
- package/dist/core/gate-outcome.js +19 -1
- package/dist/core/git-worktree-env.d.ts +53 -11
- package/dist/core/git-worktree-env.js +96 -12
- package/dist/core/governance-codes.d.ts +9 -1
- package/dist/core/governance-codes.js +13 -0
- package/dist/core/hooks.d.ts +35 -4
- package/dist/core/hooks.js +17 -11
- package/dist/core/human-input-projection.d.ts +1 -0
- package/dist/core/human-input-projection.js +3 -0
- package/dist/core/image-admission.d.ts +6 -5
- package/dist/core/image-admission.js +18 -14
- package/dist/core/locked-config.d.ts +20 -3
- package/dist/core/locked-config.js +40 -3
- package/dist/core/mailbox-store.d.ts +45 -1
- package/dist/core/mailbox-store.js +53 -9
- package/dist/core/mcp-call-meta.d.ts +66 -0
- package/dist/core/mcp-call-meta.js +103 -0
- package/dist/core/mcp-connection-pool.d.ts +3 -1
- package/dist/core/mcp-connection-pool.js +3 -1
- package/dist/core/mcp-failure.d.ts +117 -15
- package/dist/core/mcp-failure.js +71 -3
- package/dist/core/mcp-probe.d.ts +4 -0
- package/dist/core/mcp-probe.js +1 -1
- package/dist/core/mcp-server-link.d.ts +27 -3
- package/dist/core/mcp-server-link.js +25 -1
- package/dist/core/mcp-server-spec.d.ts +46 -18
- package/dist/core/mcp-server-spec.js +1 -18
- package/dist/core/mcp.d.ts +16 -20
- package/dist/core/mcp.js +112 -55
- package/dist/core/memory-engine/consolidation-driver.d.ts +2 -4
- package/dist/core/memory-engine/consolidation-driver.js +3 -3
- package/dist/core/memory-engine/consolidation.d.ts +4 -0
- package/dist/core/memory-engine/consolidation.js +1 -0
- package/dist/core/memory-engine/delegation-settlement.js +5 -12
- package/dist/core/memory-engine/distiller.js +2 -2
- package/dist/core/memory-engine/dual-root.d.ts +50 -1
- package/dist/core/memory-engine/dual-root.js +44 -1
- package/dist/core/memory-engine/engine.d.ts +67 -14
- package/dist/core/memory-engine/engine.js +384 -212
- package/dist/core/memory-engine/export-bundle.d.ts +23 -0
- package/dist/core/memory-engine/export-bundle.js +23 -4
- package/dist/core/memory-engine/file-backend.d.ts +128 -55
- package/dist/core/memory-engine/file-backend.js +290 -117
- package/dist/core/memory-engine/index.d.ts +1 -1
- package/dist/core/memory-engine/layout.d.ts +59 -11
- package/dist/core/memory-engine/layout.js +190 -40
- package/dist/core/memory-engine/memory-backend-contract.d.ts +1 -1
- package/dist/core/memory-engine/memory-backend-contract.js +39 -2
- package/dist/core/memory-engine/scope-contract.d.ts +45 -4
- package/dist/core/memory-engine/scope-contract.js +80 -11
- package/dist/core/memory-engine/sync-client.d.ts +9 -1
- package/dist/core/memory-engine/sync-client.js +31 -8
- package/dist/core/memory-engine/sync.d.ts +5 -0
- package/dist/core/memory-engine/types.d.ts +6 -0
- package/dist/core/mode-policy.d.ts +8 -5
- package/dist/core/mode-policy.js +5 -4
- package/dist/core/mods/classic-events.d.ts +5 -1
- package/dist/core/mods/host.js +1 -1
- package/dist/core/mods/kernel/dispatch.d.ts +3 -0
- package/dist/core/mods/kernel/dispatch.js +12 -9
- package/dist/core/mods/kernel/events.d.ts +6 -1
- package/dist/core/mods/kernel/events.js +2 -2
- package/dist/core/mods/kernel/registration.d.ts +9 -1
- package/dist/core/mods/kernel/registration.js +3 -0
- package/dist/core/mods/kernel/site-rules.d.ts +3 -0
- package/dist/core/mods/kernel/site-rules.js +10 -0
- package/dist/core/mods/package.d.ts +23 -0
- package/dist/core/mods/package.js +118 -0
- package/dist/core/mods/stations.d.ts +33 -12
- package/dist/core/mods/stations.js +45 -11
- package/dist/core/mods/tool-call.d.ts +5 -1
- package/dist/core/mods/tool-call.js +13 -4
- package/dist/core/parent-spec-seat.d.ts +8 -3
- package/dist/core/parent-spec-seat.js +2 -0
- package/dist/core/park-selfcheck.js +6 -0
- package/dist/core/path-guard-rows.d.ts +20 -0
- package/dist/core/path-guard-rows.js +11 -0
- package/dist/core/peer-seat.d.ts +248 -0
- package/dist/core/peer-seat.js +439 -0
- package/dist/core/permission-rule-consent.js +10 -4
- package/dist/core/permission-rule-model.d.ts +16 -0
- package/dist/core/permission-rule-model.js +1 -1
- package/dist/core/present-plan-tool.d.ts +20 -3
- package/dist/core/present-plan-tool.js +48 -4
- package/dist/core/protocol-http-auth.d.ts +40 -29
- package/dist/core/protocol-http-auth.js +30 -32
- package/dist/core/redaction-marks.d.ts +16 -0
- package/dist/core/redaction-marks.js +16 -0
- package/dist/core/redaction-passes.js +8 -9
- package/dist/core/resume-startup-cause.js +1 -0
- package/dist/core/retention.d.ts +41 -15
- package/dist/core/retention.js +59 -12
- package/dist/core/rewrite-rejudge.d.ts +38 -0
- package/dist/core/rewrite-rejudge.js +42 -2
- package/dist/core/roles.d.ts +34 -2
- package/dist/core/roles.js +43 -4
- package/dist/core/run-origin.d.ts +40 -0
- package/dist/core/run-origin.js +37 -0
- package/dist/core/runner/advertised-writable-dirs.d.ts +57 -38
- package/dist/core/runner/advertised-writable-dirs.js +126 -0
- package/dist/core/runner/announce-once-ledger.d.ts +5 -4
- package/dist/core/runner/announce-once-ledger.js +4 -2
- package/dist/core/runner/call-hook-stations.js +2 -2
- package/dist/core/runner/compaction-restate.d.ts +15 -6
- package/dist/core/runner/compaction-restate.js +28 -2
- package/dist/core/runner/contracts.d.ts +33 -21
- package/dist/core/runner/credential-origin-seat.js +4 -3
- package/dist/core/runner/cwd-alignment-probe.d.ts +20 -0
- package/dist/core/runner/cwd-alignment-probe.js +21 -0
- package/dist/core/runner/decide-continuation.d.ts +2 -2
- package/dist/core/runner/gate-exit.d.ts +30 -8
- package/dist/core/runner/gate-exit.js +15 -8
- package/dist/core/runner/image-removed-seat.d.ts +12 -0
- package/dist/core/runner/image-removed-seat.js +19 -0
- package/dist/core/runner/inline-image.js +1 -1
- package/dist/core/runner/memory-consolidation-driver.js +3 -3
- package/dist/core/runner/park-commit.d.ts +1 -1
- package/dist/core/runner/park-commit.js +3 -0
- package/dist/core/runner/prepare-ask-lane.d.ts +1 -1
- package/dist/core/runner/prepare-ask-lane.js +2 -1
- package/dist/core/runner/prepare-boundary-parks.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -5
- package/dist/core/runner/prepare-caps-and-workflow.js +3 -1
- package/dist/core/runner/prepare-config-doors.d.ts +8 -5
- package/dist/core/runner/prepare-config-doors.js +14 -10
- package/dist/core/runner/prepare-context-lane.js +2 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +8 -0
- package/dist/core/runner/prepare-delegation-surface.js +16 -18
- package/dist/core/runner/prepare-gate-stations.js +1 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +11 -3
- package/dist/core/runner/prepare-hands-readface.js +9 -1
- package/dist/core/runner/prepare-inherited-gate.d.ts +1 -3
- package/dist/core/runner/prepare-inherited-gate.js +14 -27
- package/dist/core/runner/prepare-memory.d.ts +3 -0
- package/dist/core/runner/prepare-memory.js +26 -37
- package/dist/core/runner/prepare-park-ask.d.ts +1 -1
- package/dist/core/runner/prepare-park-ask.js +2 -1
- package/dist/core/runner/prepare-policy-chain.d.ts +7 -7
- package/dist/core/runner/prepare-policy-chain.js +18 -15
- package/dist/core/runner/prepare-project-context.d.ts +2 -2
- package/dist/core/runner/prepare-project-context.js +2 -2
- package/dist/core/runner/prepare-prompt-inputs.d.ts +1 -1
- package/dist/core/runner/prepare-prompt-inputs.js +8 -19
- package/dist/core/runner/prepare-protocol-tools.d.ts +4 -2
- package/dist/core/runner/prepare-protocol-tools.js +11 -3
- package/dist/core/runner/prepare-run-refs.d.ts +2 -3
- package/dist/core/runner/prepare-run-refs.js +4 -1
- package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
- package/dist/core/runner/prepare-suspend-saga.js +2 -1
- package/dist/core/runner/prepare-task.js +28 -13
- package/dist/core/runner/prepare-wiring-manifest.d.ts +2 -1
- package/dist/core/runner/prepare-wiring-manifest.js +4 -3
- package/dist/core/runner/prepare-workspace-restore.d.ts +3 -0
- package/dist/core/runner/prepare-workspace-restore.js +4 -4
- package/dist/core/runner/reply-pricing.d.ts +30 -0
- package/dist/core/runner/reply-pricing.js +19 -0
- package/dist/core/runner/resume-admission.js +5 -3
- package/dist/core/runner/resume-apply.js +6 -1
- package/dist/core/runner/resume-checkpoint-screen.js +2 -0
- package/dist/core/runner/resume-policy-outcome.js +5 -5
- package/dist/core/runner/role-seat-defaulted.d.ts +44 -0
- package/dist/core/runner/role-seat-defaulted.js +40 -0
- package/dist/core/runner/run-brain-sinks.js +2 -0
- package/dist/core/runner/run-harness-handlers.d.ts +3 -4
- package/dist/core/runner/run-harness-handlers.js +1 -8
- package/dist/core/runner/run-identity-wiring.d.ts +2 -5
- package/dist/core/runner/run-identity-wiring.js +6 -4
- package/dist/core/runner/run-leg.d.ts +2 -0
- package/dist/core/runner/run-leg.js +42 -29
- package/dist/core/runner/run-notification-lane.js +3 -0
- package/dist/core/runner/run-stop-and-final-verify.js +2 -2
- package/dist/core/runner/run-terminal-adoption.d.ts +2 -5
- package/dist/core/runner/run-terminal-adoption.js +9 -3
- package/dist/core/runner/run-turn-boundary.js +77 -70
- package/dist/core/runner/runtask.d.ts +1 -1
- package/dist/core/runner/runtask.js +2 -2
- package/dist/core/runner/side-call-account.d.ts +1 -1
- package/dist/core/runner/side-call-account.js +3 -18
- package/dist/core/runner/sub-agent-deny-lists.d.ts +24 -0
- package/dist/core/runner/sub-agent-deny-lists.js +10 -0
- package/dist/core/runner/terminal-account.js +3 -3
- package/dist/core/runner/tool-end-body.js +2 -1
- package/dist/core/runner/tool-occurrence.d.ts +5 -2
- package/dist/core/runner/tool-occurrence.js +4 -3
- package/dist/core/runner/turn-attachments.d.ts +26 -22
- package/dist/core/runner/turn-attachments.js +24 -26
- package/dist/core/runner/write-protection-station.d.ts +8 -2
- package/dist/core/runner/write-protection-station.js +2 -0
- package/dist/core/runner-deps.d.ts +3 -3
- package/dist/core/secret-env.d.ts +32 -2
- package/dist/core/secret-env.js +65 -3
- package/dist/core/sensitive-path-policy.js +9 -10
- package/dist/core/session-log-transfer.d.ts +24 -0
- package/dist/core/session-log-transfer.js +166 -0
- package/dist/core/session-policy-store.d.ts +3 -1
- package/dist/core/session-policy-store.js +13 -9
- package/dist/core/session-store.d.ts +86 -24
- package/dist/core/session-store.js +162 -24
- package/dist/core/session.d.ts +92 -1
- package/dist/core/shell-read-silence.js +1 -0
- package/dist/core/side-query.d.ts +11 -1
- package/dist/core/side-query.js +9 -0
- package/dist/core/skill-grant-binding.d.ts +31 -2
- package/dist/core/skill-grant-binding.js +31 -1
- package/dist/core/skill-grant.d.ts +8 -5
- package/dist/core/skill-grant.js +6 -6
- package/dist/core/steer-replay.d.ts +4 -2
- package/dist/core/steer-replay.js +2 -1
- package/dist/core/store-contracts/background-agent-store-contract.js +27 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +20 -2
- package/dist/core/store-contracts/mailbox-store-contract.js +31 -1
- package/dist/core/store-contracts/session-repo-contract.js +112 -5
- package/dist/core/store-contracts/session-store-contract.d.ts +4 -1
- package/dist/core/store-contracts/session-store-contract.js +236 -2
- package/dist/core/synthetic-read-verdict.js +2 -1
- package/dist/core/task-event.d.ts +92 -8
- package/dist/core/task-notification.js +16 -10
- package/dist/core/task-registry-agent.js +1 -0
- package/dist/core/task-registry-shared.d.ts +7 -1
- package/dist/core/task-spec.d.ts +49 -1
- package/dist/core/task-stream.d.ts +2 -1
- package/dist/core/terminal-cause.d.ts +11 -1
- package/dist/core/tool-catalog-entries.js +1 -0
- package/dist/core/tool-check-reading.d.ts +1 -0
- package/dist/core/tool-check-reading.js +3 -3
- package/dist/core/tool-policy.d.ts +16 -0
- package/dist/core/tool-result-store.d.ts +17 -10
- package/dist/core/tool-result-store.js +3 -1
- package/dist/core/tool-roster.d.ts +112 -5
- package/dist/core/tool-roster.js +42 -1
- package/dist/core/tool-spec.d.ts +3 -1
- package/dist/core/types.d.ts +3 -3
- package/dist/core/types.js +1 -1
- package/dist/core/untrusted-egress.d.ts +0 -2
- package/dist/core/untrusted-egress.js +10 -14
- package/dist/core/user-attachment.js +1 -1
- package/dist/core/wiring-manifest.d.ts +18 -6
- package/dist/core/wiring-manifest.js +4 -3
- package/dist/core/workspace-snapshot.d.ts +44 -0
- package/dist/core/workspace-snapshot.js +34 -0
- package/dist/core/write-protect.d.ts +43 -3
- package/dist/core/write-protect.js +43 -16
- package/dist/engine/compaction/compaction.js +29 -3
- package/dist/engine/execution-env/node-execution-env.d.ts +4 -3
- package/dist/engine/execution-env/node-execution-env.js +24 -23
- package/dist/engine/execution-env/symlink-chain.d.ts +7 -5
- package/dist/engine/harness/agent-harness.d.ts +30 -2
- package/dist/engine/harness/agent-harness.js +43 -12
- package/dist/engine/harness/messages.d.ts +3 -1
- package/dist/engine/harness/messages.js +3 -2
- package/dist/engine/harness/types.d.ts +56 -7
- package/dist/engine/harness/types.js +5 -1
- package/dist/engine/llm/rejected-images.d.ts +46 -0
- package/dist/engine/llm/rejected-images.js +54 -0
- package/dist/engine/llm/tool-turns.d.ts +2 -1
- package/dist/engine/llm/types.d.ts +30 -10
- package/dist/engine/llm/types.js +1 -1
- package/dist/engine/loop/agent-loop.d.ts +8 -0
- package/dist/engine/loop/agent-loop.js +52 -15
- package/dist/engine/loop/types.d.ts +3 -1
- package/dist/engine/session/import-validate.js +3 -0
- package/dist/engine/session/memory-repo.d.ts +17 -9
- package/dist/engine/session/memory-repo.js +44 -34
- package/dist/engine/session/path-to-root.d.ts +38 -0
- package/dist/engine/session/path-to-root.js +39 -0
- package/dist/engine/session/repo-utils.d.ts +22 -4
- package/dist/engine/session/repo-utils.js +49 -1
- package/dist/engine/session/storage-base.d.ts +10 -1
- package/dist/engine/session/storage-base.js +11 -22
- package/dist/index.d.ts +29 -16
- package/dist/index.js +21 -11
- package/dist/internal/harness-types.d.ts +2 -2
- package/dist/internal/harness.d.ts +3 -2
- package/dist/internal/harness.js +2 -2
- package/dist/internal/llm.d.ts +1 -0
- package/dist/orchestration/workflow-observe.d.ts +17 -1
- package/dist/orchestration/workflow-observe.js +20 -0
- package/dist/orchestration/workflow-types.d.ts +32 -7
- package/dist/orchestration/workflow.js +739 -489
- package/dist/shell/counting-pass.d.ts +50 -0
- package/dist/shell/counting-pass.js +502 -0
- package/dist/shell/lex.d.ts +4 -2
- package/dist/shell/lex.js +93 -34
- package/dist/shell/shell-words.d.ts +1 -1
- package/dist/shell/shell-words.js +7 -6
- package/dist/stores/file/index.d.ts +4 -1
- package/dist/stores/file/index.js +4 -1
- package/dist/stores/file/mailbox-store.js +6 -10
- package/dist/stores/file/session-store.d.ts +15 -8
- package/dist/stores/file/session-store.js +28 -13
- package/dist/tools/fs/fs-bash.d.ts +6 -0
- package/dist/tools/fs/fs-bash.js +6 -3
- package/dist/tools/fs/fs-write.d.ts +6 -3
- package/dist/tools/fs/fs-write.js +8 -7
- package/dist/tools/fs/index.d.ts +3 -0
- package/dist/tools/fs/index.js +7 -3
- package/dist/tools/fs/program-read-model.d.ts +13 -0
- package/dist/tools/fs/program-read-model.js +15 -0
- package/dist/tools/fs/program-read-model.rows.js +1 -1
- package/dist/tools/fs/read-deny.d.ts +13 -10
- package/dist/tools/fs/read-deny.js +25 -5
- package/dist/tools/fs/read-floor.d.ts +19 -0
- package/dist/tools/fs/read-floor.js +23 -0
- package/dist/tools/fs/safety.js +40 -8
- package/dist/tools/fs/search.js +6 -24
- package/dist/tools/fs/shell-read-check.d.ts +9 -2
- package/dist/tools/fs/shell-read-check.js +61 -16
- package/dist/tools/fs/shell-read-establish.js +2 -1
- package/dist/tools/fs/shell-read-identity.js +1 -1
- package/dist/tools/fs/shell-read-judge.d.ts +26 -9
- package/dist/tools/fs/shell-read-judge.js +10 -6
- package/dist/tools/fs/shell-read-plan.d.ts +6 -1
- package/dist/tools/fs/shell-read-plan.js +22 -15
- package/dist/tools/fs/shell-read-start.js +1 -0
- package/dist/tools/fs/shell-reentry-text.d.ts +15 -1
- package/dist/tools/fs/shell-reentry-text.js +25 -3
- package/dist/tools/monitor.d.ts +4 -0
- package/dist/tools/monitor.js +2 -0
- package/dist/tools/worktree.d.ts +42 -15
- package/dist/tools/worktree.js +60 -32
- package/package.json +5 -2
- package/test/export-surface.snapshot.json +149 -1
- package/wire-changes/core-stores-sql@7.58.0.json +29 -0
- package/wire-changes/core-stores-sql@7.59.0.json +29 -0
- package/wire-changes/core@7.58.0.json +2188 -0
- package/wire-changes/core@7.59.0.json +2459 -0
- package/wire-changes/mods-kernel@7.58.0.json +81 -0
- package/wire-changes/mods-kernel@7.59.0.json +29 -0
- package/wire-changes/primitives@7.58.0.json +29 -0
- package/wire-changes/primitives@7.59.0.json +29 -0
- package/dist/primitives/credential-ref.d.ts +0 -89
- package/dist/primitives/credential-ref.js +0 -125
- package/dist/primitives/index.d.ts +0 -2
- package/dist/primitives/index.js +0 -1
|
@@ -2,7 +2,7 @@ export { MemoryEngine, buildMemoryInstruction, truncateIndex, MEMORY_INSTRUCTION
|
|
|
2
2
|
export { MEMORY_SEARCH_TOOL_NAME, MEMORY_GET_TOOL_NAME, MEMORY_INDEX_TOOL_NAME, MEMORY_ENGINE_TOOL_NAMES, type MemorySearchDetails, type MemorySearchHit, type CleanMemorySearchHit, type ExposedMemorySearchHit, type MemoryGetDetails, type MemoryIndexDetails, type MemoryIndexRow, type CleanMemoryIndexRow, type ExposedMemoryIndexRow, } from "./tools.js";
|
|
3
3
|
export { MEMORY_EXPOSURE_BANNER, MEMORY_EXPOSURE_HANDLE_TAG, MEMORY_PROVENANCE_RECALL_SENTENCE, MEMORY_PROVENANCE_SEARCH_SENTENCE, memoryExposureIndexRow, parseMemoryExposureIndexRow, } from "./provenance-wording.js";
|
|
4
4
|
export { scanMemoryWrite, scanMemoryFileName, scanRemediation, MEMORY_FILENAME_SEGMENT_RE } from "./scan.js";
|
|
5
|
-
export { FileMemoryEngineBackend, scanEntryFiles, MEMORY_INDEX_FILENAME, DEFAULT_MAX_ENTRY_DEPTH, type ScannedEntryFile, type TransferEvidence, type CommittedBinding, type CommittedEntrySnapshot, type CommittedScopeSnapshots, type EntryCustodyReport, erasureSelectHash, type EraseMemoryEntriesInput, type ErasureSelect, type ErasedBinding, type MemoryErasureAttestation, type MemoryExportSnapshot, } from "./file-backend.js";
|
|
5
|
+
export { FileMemoryEngineBackend, scanEntryFiles, MEMORY_INDEX_FILENAME, DEFAULT_MAX_ENTRY_DEPTH, type ScannedEntryFile, type TransferEvidence, type CommittedBinding, type CommittedEntrySnapshot, type CommittedScopeSnapshots, type EntryCustodyReport, erasureSelectHash, type EraseMemoryEntriesInput, type ErasureCarrierAnswer, type ErasureCarrierClass, type ErasureCountAnswer, type ErasureSelect, type ErasedBinding, type MemoryErasureAttestation, type MemoryExportSnapshot, } from "./file-backend.js";
|
|
6
6
|
export { computeBundleSectionHashes, computeMemoryBundleHash, memoryBundleInvalid, type MemoryExportBundle, type MemoryImportReport, type MemoryBundleImportPlan, type BundleChallengeRow, type BundleLineageRow, type BundlePollutedSession, } from "./export-bundle.js";
|
|
7
7
|
export { ControlPlaneCorruptError, deriveControlPlaneDir, deriveRepoControlPlaneDir, deriveRepoKey, deriveRepoMemoryDir, deriveProjectMemoryDir, deriveProjectControlDir, recordProjectIdHint, lookupProjectIdHint, PROJECT_ID_HINTS_FILE, resolveMemoryEngineRoot, scopeDirFor, scopeDirName, scopeRegistryShape, layoutNeedsAdoption, adoptRootScopeLayout, v1MemoryPathKeyResolver, unresolvedProjectionDebts, scanFuseKey, type AdoptRootScopeLayoutOptions, type ScopeRegistryShape, enqueueMemoryAnnouncement, drainMemoryAnnouncements, peekMemoryAnnouncements, bumpScanFuse, scanFuseCount, clearScanFuse, ANNOUNCEMENTS_FILE, MEMORY_ANNOUNCEMENTS_MAX, SCAN_FUSE_FILE, SCAN_FUSE_THRESHOLD, LINEAGE_FILE, CHALLENGES_FILE, CHALLENGED_HISTORY_FILE, CHALLENGE_LEDGER_MAX_EVENTS, rebuildStrictControlPlaneLedger, type ControlPlaneRebuildReceipt, type StrictControlPlaneLedger, type ChallengeAppendResult, type ChallengeAssignment, type ChallengeEvent, type ChallengedHistoryRow, type LineagePendingTxn, type LineagePromotion, SESSION_CAPTURE_OPTOUT_DIR, markSessionCaptureOptOut, readSessionCaptureOptOut, listSessionCaptureOptOut, fileSessionCaptureRecordStore, type SessionCaptureOptOutRecord, type SessionCaptureOptOutMarkOutcome, type SessionCaptureRecordStore, } from "./layout.js";
|
|
8
8
|
export { readV2HeaderHints, isInstructionEntry, type V2HeaderHints } from "./header-hints.js";
|
|
@@ -433,6 +433,32 @@ export interface StoreRootReanchor {
|
|
|
433
433
|
/** The control plane the anchor lives in. */
|
|
434
434
|
readonly controlDir: string;
|
|
435
435
|
}
|
|
436
|
+
/**
|
|
437
|
+
* The TRANSIENT sweep record: per erasure requestId, the projection paths it deleted, kept in the
|
|
438
|
+
* control plane only until the derived-index sweep has cleared every MEMORY.md line naming them (the
|
|
439
|
+
* paths spell slugs, so the durable chain and the attestation never hold them). Written from the
|
|
440
|
+
* request's journal right after its commit point, and by recovery from a journal it rolls forward;
|
|
441
|
+
* swept and settled by `MemoryEngine.eraseMemoryEntries` under this file's lock. A request with a
|
|
442
|
+
* record is `partial` on `indexLine`. A row's paths are relative to the store root
|
|
443
|
+
* ({@link erasureSweepRecordPathOf}) and are read at the root the store is opened at now
|
|
444
|
+
* ({@link erasureSweepOwedAt}), so a row binds no root and follows a re-anchor. A record that cannot
|
|
445
|
+
* be read or written, or a row path that is absolute or leaves the root, refuses like every strict
|
|
446
|
+
* control-plane file (fail-closed).
|
|
447
|
+
*/
|
|
448
|
+
export declare const ERASURE_SWEEP_RECORD_FILE = "erasure-sweeps.json";
|
|
449
|
+
export declare const ERASURE_SWEEP_RECORD_WHAT = "memory erasure sweep record";
|
|
450
|
+
export interface ErasureSweepRecordFile {
|
|
451
|
+
v: 1;
|
|
452
|
+
requests: Record<string, string[]>;
|
|
453
|
+
}
|
|
454
|
+
export declare function coerceErasureSweepRecord(raw: unknown): ErasureSweepRecordFile;
|
|
455
|
+
/** The row path of `target`, a projection `requestId` deleted under `storeRoot`: relative to the root's
|
|
456
|
+
* physical form, the target placed as the act gate places a delete ({@link landsOutsideStore}: its directory
|
|
457
|
+
* where it lands, the final component as spelled) — so every spelling of one root records one row. A target
|
|
458
|
+
* that does not land under the root is refused (fail-closed; the text names no path — paths spell slugs). */
|
|
459
|
+
export declare function erasureSweepRecordPathOf(storeRoot: string, requestId: string, target: string): string;
|
|
460
|
+
/** The paths `requestId`'s row owes, at the root the store is opened at now (`[]` without a row). */
|
|
461
|
+
export declare function erasureSweepOwedAt(file: ErasureSweepRecordFile, storeRoot: string, requestId: string): string[];
|
|
436
462
|
/**
|
|
437
463
|
* The ONE way a recorded root anchor changes: point it at where `dir` resolves now — a store moved on
|
|
438
464
|
* purpose, or an anchor that is damaged. `opts.controlDir` names the store's control plane exactly as its
|
|
@@ -442,9 +468,10 @@ export interface StoreRootReanchor {
|
|
|
442
468
|
* mistaken `controlDir` would otherwise record an anchor no opener reads. Moves nothing and says nothing
|
|
443
469
|
* about whether the directory holds the same store. A re-anchor is a transaction of the store: it holds the
|
|
444
470
|
* store's transaction lock ({@link acquireStoreTxnLock}; a commit in progress is waited for, never crossed) and
|
|
445
|
-
* is refused while
|
|
446
|
-
*
|
|
447
|
-
*
|
|
471
|
+
* is refused while the control plane owes anything at the recorded root ({@link rootBoundObligationOf}: a
|
|
472
|
+
* committed transaction pending recovery — its journal names paths under the recorded root and is replayed
|
|
473
|
+
* there first, never carried over). Every live holder judges against the new anchor at its next face.
|
|
474
|
+
* Discloses `memory.root_reanchored` on `opts.onIncident`.
|
|
448
475
|
*/
|
|
449
476
|
export declare function reanchorMemoryStoreRoot(dir: string, opts?: {
|
|
450
477
|
controlDir?: string;
|
|
@@ -598,9 +625,12 @@ export declare function dropStagingSecondNames(seat: string, opened: {
|
|
|
598
625
|
*/
|
|
599
626
|
export declare function restoreContainedBaseline(path: string, committed: string, leftOnPlane: string | undefined): "written" | "kept" | "failed";
|
|
600
627
|
export declare function quarantineAndTombstone(path: string, content: string, quarantineDir: string, now: () => number): QuarantineOutcome;
|
|
601
|
-
/** S2-B — the queued memory-change announcements (control plane; drained at session-first inject).
|
|
628
|
+
/** S2-B — the queued memory-change announcements (control plane; drained at session-first inject).
|
|
629
|
+
* One file, one bounded queue PER SCOPE inside it (see {@link enqueueMemoryAnnouncement}). */
|
|
602
630
|
export declare const ANNOUNCEMENTS_FILE = "announcements.json";
|
|
603
|
-
/** S2-B — bounded queue: overflow FOLDS (oldest dropped, counted) instead of growing
|
|
631
|
+
/** S2-B — bounded queue, per scope: overflow FOLDS (oldest dropped, counted) instead of growing
|
|
632
|
+
* unbounded. The bound, the fold count and the standing-condition sweep are all one scope's —
|
|
633
|
+
* a scope that floods its own queue never pushes another scope's notices out. */
|
|
604
634
|
export declare const MEMORY_ANNOUNCEMENTS_MAX = 20;
|
|
605
635
|
/** S2-C — per-file write-rejection counts (the beforeWrite silent-reject fuse; O-F9/C-F7: scoped
|
|
606
636
|
* state in `.engine/`, so the count survives suspend/resume and backend re-construction). */
|
|
@@ -640,10 +670,17 @@ export declare function acquireSidecarLock(lockDir: string, opts?: SidecarLockOp
|
|
|
640
670
|
* locked update) keeps the leniency, because its token writes are best-effort and an absent owner
|
|
641
671
|
* file there is the documented pre-token degraded shape, not evidence of a steal. */
|
|
642
672
|
export declare function assertSidecarLockOwnership(lockDir: string, token: string, what: string, mode?: "strict" | "lenient"): void;
|
|
643
|
-
|
|
644
|
-
|
|
673
|
+
/** What a drain or a peek answers for the scopes it was asked about. */
|
|
674
|
+
export interface DrainedMemoryAnnouncements {
|
|
675
|
+
/** The asked scopes' fold counts, summed. */
|
|
645
676
|
folded: number;
|
|
677
|
+
/** The asked scopes' announcements, in enqueue-time order. */
|
|
646
678
|
queue: MemoryAnnouncement[];
|
|
679
|
+
/** Notices found in the queue file WITHOUT a scope (the pre-per-scope file form, or a hand-written
|
|
680
|
+
* line): they belong to no queue, so no session ever reads them — they are discarded on the first
|
|
681
|
+
* locked rewrite and only their number is kept, for the operator face. A drain hands the number
|
|
682
|
+
* over once and resets it; a peek reports it without resetting. */
|
|
683
|
+
unscopedDiscarded: number;
|
|
647
684
|
}
|
|
648
685
|
/**
|
|
649
686
|
* S2-B — enqueue one announcement (journaled + locked; bounded with overflow folding).
|
|
@@ -670,10 +707,21 @@ interface AnnouncementsRecord {
|
|
|
670
707
|
export declare function enqueueMemoryAnnouncement(controlDir: string, ann: MemoryAnnouncement, opts?: {
|
|
671
708
|
supersedesPrefix?: string;
|
|
672
709
|
}): void;
|
|
673
|
-
/**
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
710
|
+
/**
|
|
711
|
+
* S2-B — drain the queues of `scopes` (session-first inject, 时机①): returns what those scopes had
|
|
712
|
+
* queued and resets exactly them. Every other scope's queue is left as it was, for the session that
|
|
713
|
+
* mounts it — the drain that empties a queue is a reader of that queue, never a bystander.
|
|
714
|
+
*/
|
|
715
|
+
export declare function drainMemoryAnnouncements(controlDir: string, scopes: readonly string[]): DrainedMemoryAnnouncements;
|
|
716
|
+
/** Test/observability peek of `scopes` (journal-aware, non-destructive). */
|
|
717
|
+
export declare function peekMemoryAnnouncements(controlDir: string, scopes: readonly string[]): DrainedMemoryAnnouncements;
|
|
718
|
+
/**
|
|
719
|
+
* Move every scope's queue from one control plane to another (a mount-key switch re-homes the control
|
|
720
|
+
* plane, and the notices queued under the old key must not be orphaned). Each line keeps its scope; the
|
|
721
|
+
* destination's per-scope bounds apply as each line lands. The only whole-file read there is: it hands
|
|
722
|
+
* lines to the same scopes' queues elsewhere, never to a reader.
|
|
723
|
+
*/
|
|
724
|
+
export declare function transferMemoryAnnouncements(fromControlDir: string, toControlDir: string): void;
|
|
677
725
|
/** The fuse key for a memory file: the ledger form `(scope, rel)` (`rel` relative to the scope's
|
|
678
726
|
* home, `/`-separated) — location-free, so a home move never re-keys a count. */
|
|
679
727
|
export declare function scanFuseKey(scope: string, rel: string): string;
|
|
@@ -2,7 +2,7 @@ import { closeSync, constants as fsConstants, copyFileSync, existsSync, fstatSyn
|
|
|
2
2
|
const { O_WRONLY, O_RDONLY, O_CREAT, O_NOFOLLOW, O_NONBLOCK, O_EXCL } = fsConstants;
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
|
-
import { basename, dirname, isAbsolute, join, resolve, sep } from "node:path";
|
|
5
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
6
6
|
import { MEMORY_ORIGIN_CAUSES } from "./types.js";
|
|
7
7
|
import { physicalPathOf, physicalPathOfExisting, priorCallerCasedPathOf } from "../physical-path.js";
|
|
8
8
|
import { thrownLabel, thrownText } from "../thrown-value.js";
|
|
@@ -1063,6 +1063,40 @@ function reanchorDestination(dir) {
|
|
|
1063
1063
|
throw reanchorRefusal(`the store root ${JSON.stringify(dir)} resolves to ${to}, which is not a directory`);
|
|
1064
1064
|
return to;
|
|
1065
1065
|
}
|
|
1066
|
+
export const ERASURE_SWEEP_RECORD_FILE = "erasure-sweeps.json";
|
|
1067
|
+
export const ERASURE_SWEEP_RECORD_WHAT = "memory erasure sweep record";
|
|
1068
|
+
function isStoreRelativePath(p) {
|
|
1069
|
+
return p.length > 0 && !isAbsolute(p) && !p.split(sep === "/" ? "/" : /[\\/]/).includes("..");
|
|
1070
|
+
}
|
|
1071
|
+
export function coerceErasureSweepRecord(raw) {
|
|
1072
|
+
if (raw === undefined)
|
|
1073
|
+
return { v: 1, requests: Object.create(null) };
|
|
1074
|
+
const requests = raw?.requests;
|
|
1075
|
+
if (typeof raw !== "object" || raw === null || raw.v !== 1 || typeof requests !== "object" || requests === null || Array.isArray(requests)) {
|
|
1076
|
+
throw new ControlPlaneCorruptError(`${ERASURE_SWEEP_RECORD_WHAT} has an unrecognized shape (fail-closed sidecar)`);
|
|
1077
|
+
}
|
|
1078
|
+
const out = Object.create(null);
|
|
1079
|
+
for (const [req, paths] of Object.entries(requests)) {
|
|
1080
|
+
if (!Array.isArray(paths) || paths.some((p) => typeof p !== "string" || !isStoreRelativePath(p)))
|
|
1081
|
+
throw new ControlPlaneCorruptError(`${ERASURE_SWEEP_RECORD_WHAT} row for request ${JSON.stringify(req.slice(0, 80))} is malformed — a row names paths relative to the store root (fail-closed sidecar)`);
|
|
1082
|
+
out[req] = paths;
|
|
1083
|
+
}
|
|
1084
|
+
return { v: 1, requests: out };
|
|
1085
|
+
}
|
|
1086
|
+
export function erasureSweepRecordPathOf(storeRoot, requestId, target) {
|
|
1087
|
+
const rel = join(relative(landingPathOf(storeRoot), landingPathOf(dirname(target))), basename(target));
|
|
1088
|
+
if (!isStoreRelativePath(rel))
|
|
1089
|
+
throw new ControlPlaneCorruptError(`${ERASURE_SWEEP_RECORD_WHAT}: a path request ${JSON.stringify(requestId.slice(0, 80))} deleted is not under the store root ${storeRoot} — a row names paths relative to the root (fail-closed sidecar)`);
|
|
1090
|
+
return rel;
|
|
1091
|
+
}
|
|
1092
|
+
export function erasureSweepOwedAt(file, storeRoot, requestId) {
|
|
1093
|
+
return (file.requests[requestId] ?? []).map((rel) => join(storeRoot, rel));
|
|
1094
|
+
}
|
|
1095
|
+
function rootBoundObligationOf(controlDir) {
|
|
1096
|
+
if (lstatOrAbsent(join(controlDir, STORE_JOURNAL_FILE)) === undefined)
|
|
1097
|
+
return undefined;
|
|
1098
|
+
return { owed: "a committed transaction is still pending recovery", remedy: "open it once so the journal replays" };
|
|
1099
|
+
}
|
|
1066
1100
|
function reanchorRefusal(sentence) {
|
|
1067
1101
|
const e = new Error(`reanchorMemoryStoreRoot: ${sentence}`);
|
|
1068
1102
|
e.code = "config.memory_reanchor";
|
|
@@ -1092,8 +1126,9 @@ export async function reanchorMemoryStoreRoot(dir, opts = {}) {
|
|
|
1092
1126
|
catch {
|
|
1093
1127
|
throw reanchorRefusal(`the store's transaction lock was lost while re-anchoring (held past its stale line and taken by another writer) — nothing changed; retry (control plane ${controlDir})`);
|
|
1094
1128
|
}
|
|
1095
|
-
|
|
1096
|
-
|
|
1129
|
+
const obligation = rootBoundObligationOf(controlDir);
|
|
1130
|
+
if (obligation !== undefined) {
|
|
1131
|
+
throw reanchorRefusal(`${obligation.owed} at the recorded root — put the store back at ${from ?? "the root it was last opened at"}, ${obligation.remedy}, then re-anchor (control plane ${controlDir})`);
|
|
1097
1132
|
}
|
|
1098
1133
|
let still;
|
|
1099
1134
|
try {
|
|
@@ -1468,75 +1503,190 @@ function readSidecarJson(controlDir, fileName) {
|
|
|
1468
1503
|
}
|
|
1469
1504
|
return undefined;
|
|
1470
1505
|
}
|
|
1506
|
+
const ANNOUNCEMENTS_FORM = 2;
|
|
1507
|
+
function emptyAnnouncements() {
|
|
1508
|
+
return { scopes: Object.create(null), unscopedDiscarded: 0 };
|
|
1509
|
+
}
|
|
1510
|
+
function wholeCount(v) {
|
|
1511
|
+
return typeof v === "number" && Number.isFinite(v) && v > 0 ? Math.floor(v) : 0;
|
|
1512
|
+
}
|
|
1513
|
+
function coerceAnnouncement(e, scope) {
|
|
1514
|
+
const a = e;
|
|
1515
|
+
if (!a ||
|
|
1516
|
+
typeof a !== "object" ||
|
|
1517
|
+
(a.kind !== "gate" && a.kind !== "external") ||
|
|
1518
|
+
typeof a.at !== "number" ||
|
|
1519
|
+
!Array.isArray(a.items) ||
|
|
1520
|
+
!a.items.every((i) => typeof i === "string") ||
|
|
1521
|
+
a.scope !== scope) {
|
|
1522
|
+
return undefined;
|
|
1523
|
+
}
|
|
1524
|
+
return {
|
|
1525
|
+
kind: a.kind,
|
|
1526
|
+
scope,
|
|
1527
|
+
at: a.at,
|
|
1528
|
+
...(typeof a.sessionId === "string" ? { sessionId: a.sessionId } : {}),
|
|
1529
|
+
...(typeof a.reportId === "string" ? { reportId: a.reportId } : {}),
|
|
1530
|
+
items: mintedItems(a.items),
|
|
1531
|
+
};
|
|
1532
|
+
}
|
|
1471
1533
|
const mintedItems = (items) => items.map((item) => egressText("same-principal", item));
|
|
1472
1534
|
function coerceAnnouncements(raw) {
|
|
1473
|
-
const rec =
|
|
1535
|
+
const rec = emptyAnnouncements();
|
|
1474
1536
|
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
1475
1537
|
return rec;
|
|
1476
1538
|
const r = raw;
|
|
1477
|
-
if (
|
|
1478
|
-
rec.
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1539
|
+
if (r.v !== ANNOUNCEMENTS_FORM) {
|
|
1540
|
+
rec.unscopedDiscarded = (Array.isArray(r.queue) ? r.queue.length : 0) + wholeCount(r.folded);
|
|
1541
|
+
return rec;
|
|
1542
|
+
}
|
|
1543
|
+
rec.unscopedDiscarded = wholeCount(r.unscopedDiscarded);
|
|
1544
|
+
if (!r.scopes || typeof r.scopes !== "object" || Array.isArray(r.scopes))
|
|
1545
|
+
return rec;
|
|
1546
|
+
for (const scope of Object.keys(r.scopes)) {
|
|
1547
|
+
const q = r.scopes[scope];
|
|
1548
|
+
if (scope === "" || !q || typeof q !== "object")
|
|
1549
|
+
continue;
|
|
1550
|
+
const queue = [];
|
|
1551
|
+
if (Array.isArray(q.queue)) {
|
|
1552
|
+
for (const e of q.queue) {
|
|
1553
|
+
const a = coerceAnnouncement(e, scope);
|
|
1554
|
+
if (a !== undefined)
|
|
1555
|
+
queue.push(a);
|
|
1556
|
+
else
|
|
1557
|
+
rec.unscopedDiscarded += 1;
|
|
1495
1558
|
}
|
|
1496
1559
|
}
|
|
1560
|
+
const folded = wholeCount(q.folded);
|
|
1561
|
+
if (queue.length > 0 || folded > 0)
|
|
1562
|
+
rec.scopes[scope] = { folded, queue };
|
|
1497
1563
|
}
|
|
1498
1564
|
return rec;
|
|
1499
1565
|
}
|
|
1566
|
+
function persistedAnnouncements(rec) {
|
|
1567
|
+
return { v: ANNOUNCEMENTS_FORM, scopes: rec.scopes, ...(rec.unscopedDiscarded > 0 ? { unscopedDiscarded: rec.unscopedDiscarded } : {}) };
|
|
1568
|
+
}
|
|
1569
|
+
function askedScopes(scopes, verb) {
|
|
1570
|
+
if (!Array.isArray(scopes) || !scopes.every((s) => typeof s === "string" && s !== "")) {
|
|
1571
|
+
throw new TypeError(`${verb}: scopes must be an array of non-empty scope keys — the queue is read per scope`);
|
|
1572
|
+
}
|
|
1573
|
+
return [...new Set(scopes)];
|
|
1574
|
+
}
|
|
1575
|
+
function mergeScopeQueues(rec, scopes) {
|
|
1576
|
+
let folded = 0;
|
|
1577
|
+
const lines = [];
|
|
1578
|
+
scopes.forEach((scope, s) => {
|
|
1579
|
+
const q = Object.prototype.hasOwnProperty.call(rec.scopes, scope) ? rec.scopes[scope] : undefined;
|
|
1580
|
+
if (q === undefined)
|
|
1581
|
+
return;
|
|
1582
|
+
folded += q.folded;
|
|
1583
|
+
q.queue.forEach((a, i) => lines.push({ a, s, i }));
|
|
1584
|
+
});
|
|
1585
|
+
lines.sort((x, y) => x.a.at - y.a.at || x.s - y.s || x.i - y.i);
|
|
1586
|
+
return { folded, queue: lines.map((l) => l.a) };
|
|
1587
|
+
}
|
|
1500
1588
|
export function enqueueMemoryAnnouncement(controlDir, ann, opts) {
|
|
1589
|
+
if (typeof ann.scope !== "string" || ann.scope === "") {
|
|
1590
|
+
throw new TypeError("enqueueMemoryAnnouncement: announcement.scope is required — each notice is filed under the one scope it reports on");
|
|
1591
|
+
}
|
|
1592
|
+
const scope = ann.scope;
|
|
1501
1593
|
ann = { ...ann, items: mintedItems(ann.items) };
|
|
1502
1594
|
const family = opts?.supersedesPrefix === undefined ? undefined : egressText("same-principal", opts.supersedesPrefix);
|
|
1503
1595
|
if (ann.items.length === 0 && family === undefined)
|
|
1504
1596
|
return;
|
|
1505
1597
|
lockedJournaledUpdate(controlDir, ANNOUNCEMENTS_FILE, (current) => {
|
|
1506
1598
|
const rec = coerceAnnouncements(current);
|
|
1599
|
+
const own = Object.prototype.hasOwnProperty.call(rec.scopes, scope) ? rec.scopes[scope] : { folded: 0, queue: [] };
|
|
1507
1600
|
if (family !== undefined) {
|
|
1508
|
-
const queued =
|
|
1601
|
+
const queued = own.queue.flatMap((a) => a.items.filter((i) => i.startsWith(family)));
|
|
1509
1602
|
if (queued.length === ann.items.length && ann.items.every((i) => queued.includes(i)))
|
|
1510
1603
|
return undefined;
|
|
1511
|
-
for (const a of
|
|
1604
|
+
for (const a of own.queue)
|
|
1512
1605
|
a.items = a.items.filter((i) => !i.startsWith(family));
|
|
1513
|
-
|
|
1514
|
-
if (ann.items.length === 0)
|
|
1515
|
-
return rec;
|
|
1606
|
+
own.queue = own.queue.filter((a) => a.items.length > 0);
|
|
1516
1607
|
}
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1608
|
+
if (ann.items.length > 0)
|
|
1609
|
+
own.queue.push({ ...ann, scope });
|
|
1610
|
+
if (own.queue.length > MEMORY_ANNOUNCEMENTS_MAX) {
|
|
1611
|
+
own.folded += own.queue.length - MEMORY_ANNOUNCEMENTS_MAX;
|
|
1612
|
+
own.queue = own.queue.slice(-MEMORY_ANNOUNCEMENTS_MAX);
|
|
1521
1613
|
}
|
|
1522
|
-
|
|
1614
|
+
if (own.queue.length > 0 || own.folded > 0)
|
|
1615
|
+
rec.scopes[scope] = own;
|
|
1616
|
+
else
|
|
1617
|
+
delete rec.scopes[scope];
|
|
1618
|
+
return persistedAnnouncements(rec);
|
|
1523
1619
|
});
|
|
1524
1620
|
}
|
|
1525
|
-
export function drainMemoryAnnouncements(controlDir) {
|
|
1621
|
+
export function drainMemoryAnnouncements(controlDir, scopes) {
|
|
1622
|
+
const asked = askedScopes(scopes, "drainMemoryAnnouncements");
|
|
1526
1623
|
const file = join(controlDir, ANNOUNCEMENTS_FILE);
|
|
1527
1624
|
if (!existsSync(file) && !existsSync(`${file}.journal`))
|
|
1528
|
-
return { folded: 0, queue: [] };
|
|
1529
|
-
let drained = { folded: 0, queue: [] };
|
|
1625
|
+
return { folded: 0, queue: [], unscopedDiscarded: 0 };
|
|
1626
|
+
let drained = { folded: 0, queue: [], unscopedDiscarded: 0 };
|
|
1530
1627
|
lockedJournaledUpdate(controlDir, ANNOUNCEMENTS_FILE, (current) => {
|
|
1531
|
-
|
|
1532
|
-
|
|
1628
|
+
const rec = coerceAnnouncements(current);
|
|
1629
|
+
const mine = mergeScopeQueues(rec, asked);
|
|
1630
|
+
drained = { ...mine, unscopedDiscarded: rec.unscopedDiscarded };
|
|
1631
|
+
const otherForm = !current || typeof current !== "object" || current.v !== ANNOUNCEMENTS_FORM;
|
|
1632
|
+
if (mine.queue.length === 0 && mine.folded === 0 && rec.unscopedDiscarded === 0 && !otherForm)
|
|
1533
1633
|
return undefined;
|
|
1534
|
-
|
|
1634
|
+
for (const scope of asked)
|
|
1635
|
+
delete rec.scopes[scope];
|
|
1636
|
+
rec.unscopedDiscarded = 0;
|
|
1637
|
+
return persistedAnnouncements(rec);
|
|
1535
1638
|
});
|
|
1536
1639
|
return drained;
|
|
1537
1640
|
}
|
|
1538
|
-
export function peekMemoryAnnouncements(controlDir) {
|
|
1539
|
-
|
|
1641
|
+
export function peekMemoryAnnouncements(controlDir, scopes) {
|
|
1642
|
+
const asked = askedScopes(scopes, "peekMemoryAnnouncements");
|
|
1643
|
+
const rec = coerceAnnouncements(readSidecarJson(controlDir, ANNOUNCEMENTS_FILE));
|
|
1644
|
+
return { ...mergeScopeQueues(rec, asked), unscopedDiscarded: rec.unscopedDiscarded };
|
|
1645
|
+
}
|
|
1646
|
+
export function transferMemoryAnnouncements(fromControlDir, toControlDir) {
|
|
1647
|
+
const file = join(fromControlDir, ANNOUNCEMENTS_FILE);
|
|
1648
|
+
if (!existsSync(file) && !existsSync(`${file}.journal`))
|
|
1649
|
+
return;
|
|
1650
|
+
const taken = coerceAnnouncements(readSidecarJson(fromControlDir, ANNOUNCEMENTS_FILE));
|
|
1651
|
+
const carried = Object.keys(taken.scopes).flatMap((scope) => taken.scopes[scope].queue);
|
|
1652
|
+
carried.sort((x, y) => x.at - y.at);
|
|
1653
|
+
for (const ann of carried)
|
|
1654
|
+
enqueueMemoryAnnouncement(toControlDir, ann);
|
|
1655
|
+
const extraFolded = Object.keys(taken.scopes).map((scope) => ({ scope, folded: taken.scopes[scope].folded })).filter((x) => x.folded > 0);
|
|
1656
|
+
if (extraFolded.length > 0 || taken.unscopedDiscarded > 0) {
|
|
1657
|
+
lockedJournaledUpdate(toControlDir, ANNOUNCEMENTS_FILE, (current) => {
|
|
1658
|
+
const rec = coerceAnnouncements(current);
|
|
1659
|
+
for (const { scope, folded } of extraFolded) {
|
|
1660
|
+
const own = Object.prototype.hasOwnProperty.call(rec.scopes, scope) ? rec.scopes[scope] : { folded: 0, queue: [] };
|
|
1661
|
+
own.folded += folded;
|
|
1662
|
+
rec.scopes[scope] = own;
|
|
1663
|
+
}
|
|
1664
|
+
rec.unscopedDiscarded += taken.unscopedDiscarded;
|
|
1665
|
+
return persistedAnnouncements(rec);
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
const moved = new Map();
|
|
1669
|
+
for (const ann of carried)
|
|
1670
|
+
moved.set(JSON.stringify(ann), (moved.get(JSON.stringify(ann)) ?? 0) + 1);
|
|
1671
|
+
lockedJournaledUpdate(fromControlDir, ANNOUNCEMENTS_FILE, (current) => {
|
|
1672
|
+
const rec = coerceAnnouncements(current);
|
|
1673
|
+
for (const scope of Object.keys(rec.scopes)) {
|
|
1674
|
+
const own = rec.scopes[scope];
|
|
1675
|
+
own.queue = own.queue.filter((a) => {
|
|
1676
|
+
const key = JSON.stringify(a);
|
|
1677
|
+
const n = moved.get(key) ?? 0;
|
|
1678
|
+
if (n === 0)
|
|
1679
|
+
return true;
|
|
1680
|
+
moved.set(key, n - 1);
|
|
1681
|
+
return false;
|
|
1682
|
+
});
|
|
1683
|
+
own.folded = Math.max(0, own.folded - (taken.scopes[scope]?.folded ?? 0));
|
|
1684
|
+
if (own.queue.length === 0 && own.folded === 0)
|
|
1685
|
+
delete rec.scopes[scope];
|
|
1686
|
+
}
|
|
1687
|
+
rec.unscopedDiscarded = Math.max(0, rec.unscopedDiscarded - taken.unscopedDiscarded);
|
|
1688
|
+
return persistedAnnouncements(rec);
|
|
1689
|
+
});
|
|
1540
1690
|
}
|
|
1541
1691
|
export function scanFuseKey(scope, rel) {
|
|
1542
1692
|
return JSON.stringify([scope, rel.split(sep).join("/")]);
|
|
@@ -22,7 +22,7 @@ export interface MemoryBackendContractHooks {
|
|
|
22
22
|
* assembly answers it as capability-absent.
|
|
23
23
|
*/
|
|
24
24
|
onOptionalMember?: (report: {
|
|
25
|
-
member: "committedSnapshotOf" | "committedSnapshotsOfScopes" | "custodyOf" | "eraseWithEvidence" | "exportSnapshotOf" | "governanceExport" | "custodyImport" | "importBundleCommit";
|
|
25
|
+
member: "committedSnapshotOf" | "committedSnapshotsOfScopes" | "custodyOf" | "eraseWithEvidence" | "judgesErasureScopes" | "exportSnapshotOf" | "governanceExport" | "custodyImport" | "importBundleCommit";
|
|
26
26
|
status: "verified" | "absent";
|
|
27
27
|
}) => void;
|
|
28
28
|
}
|
|
@@ -728,10 +728,16 @@ export async function memoryBackendContract(hooks) {
|
|
|
728
728
|
return;
|
|
729
729
|
}
|
|
730
730
|
const erase = seat;
|
|
731
|
-
const e = entry("id-erase-0001", "s1", "erasable", "erasable body", { name: "Erasable" });
|
|
731
|
+
const e = entry("id-erase-0001", "s1", "erasable-slugword", "erasable body", { name: "Erasable" });
|
|
732
732
|
await b.applyPatches([{ op: "add", id: e.id, entry: e }]);
|
|
733
733
|
const att = await erase.call(b, { requestId: "req-contract-1", select: { ids: [e.id, "id-ghost-8888"] } });
|
|
734
|
-
assert.strictEqual(att.v,
|
|
734
|
+
assert.strictEqual(att.v, 2, "the attestation rides the v:2 envelope");
|
|
735
|
+
for (const cls of ["projection", "shadow", "indexLine", "quarantineCopy", "planArchive", "planWorkbook", "evidenceBinding", "backendDerived"]) {
|
|
736
|
+
const answer = att.residuals.carriers[cls];
|
|
737
|
+
assert.ok(answer !== undefined && (answer.unverified === true || (typeof answer.removed === "number" && typeof answer.remaining === "number")), `carrier class ${cls} is answered (removed/remaining counts, or unverified)`);
|
|
738
|
+
}
|
|
739
|
+
assert.strictEqual(att.residuals.replay, "converges", "an evidence face's replay converges (no time limit)");
|
|
740
|
+
assert.ok(!JSON.stringify(att).includes("slugword") && !JSON.stringify(att).includes("erasable body"), "the attestation names no slug and no entry text");
|
|
735
741
|
assert.strictEqual(att.evidenceCapability, "journal", "a face-claiming backend answers the evidenced capability");
|
|
736
742
|
assert.deepStrictEqual(att.erased.map((r) => r.id), [e.id], "the existing id is erased");
|
|
737
743
|
assert.ok(typeof att.erased[0]?.evidenceEv === "string" && att.erased[0].evidenceEv.length > 0, "an evidenced erase names its evidence row");
|
|
@@ -743,6 +749,37 @@ export async function memoryBackendContract(hooks) {
|
|
|
743
749
|
await assert.rejects(async () => erase.call(b, { requestId: "req-contract-1", select: { ids: ["id-other-7777"] } }), (err) => err.code === "memory.erasure_selector_mismatch", "a reused requestId with a different selector refuses loudly");
|
|
744
750
|
hooks.onOptionalMember?.({ member: "eraseWithEvidence", status: "verified" });
|
|
745
751
|
});
|
|
752
|
+
defer("design/1068 S1a optional erasure authorization seat: post-resolution judgment, whole-request refusal, replay bound to its set (undeclared ⇒ reported)", async () => {
|
|
753
|
+
const b = await hooks.make();
|
|
754
|
+
const seat = b.eraseWithEvidence;
|
|
755
|
+
const declared = b.judgesErasureScopes;
|
|
756
|
+
assert.ok(declared === undefined || declared === true, "judgesErasureScopes must be absent or the literal true — any other occupant is a defect, not absence");
|
|
757
|
+
assert.ok(declared !== true || typeof seat === "function", "a backend declaring judgesErasureScopes must offer eraseWithEvidence");
|
|
758
|
+
if (declared !== true) {
|
|
759
|
+
hooks.onOptionalMember?.({ member: "judgesErasureScopes", status: "absent" });
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
const erase = seat;
|
|
763
|
+
const mine = entry("id-grant-mine-0001", "tenant-mine", "mine", "mine body", { name: "Mine" });
|
|
764
|
+
const theirs = entry("id-grant-theirs-0001", "tenant-theirs", "theirs", "theirs body", { name: "Theirs" });
|
|
765
|
+
await b.applyPatches([
|
|
766
|
+
{ op: "add", id: mine.id, entry: mine },
|
|
767
|
+
{ op: "add", id: theirs.id, entry: theirs },
|
|
768
|
+
]);
|
|
769
|
+
const refusedBySeat = (err) => err.code === "config.memory_erasure_scope";
|
|
770
|
+
await assert.rejects(async () => erase.call(b, { requestId: "req-grant-1", select: { ids: [mine.id, theirs.id] }, expectedScopes: ["tenant-mine"] }), refusedBySeat, "an id resolving outside the set refuses the WHOLE request");
|
|
771
|
+
await assert.rejects(async () => erase.call(b, { requestId: "req-grant-2", select: { ids: [mine.id, "id-grant-ghost-0001"] }, expectedScopes: ["tenant-mine"] }), refusedBySeat, "an id the store cannot attribute to a scope is not a member — refused the same way");
|
|
772
|
+
await assert.rejects(async () => erase.call(b, { requestId: "req-grant-3", select: { scope: "tenant-empty" }, expectedScopes: ["tenant-mine"] }), refusedBySeat, "a place selector naming a scope outside the set refuses — even when that scope resolves to nothing");
|
|
773
|
+
assert.deepStrictEqual((await b.getByIds([mine.id, theirs.id])).map((e) => e.id).sort(), [mine.id, theirs.id].sort(), "refused requests erase nothing");
|
|
774
|
+
const att = await erase.call(b, { requestId: "req-grant-4", select: { ids: [mine.id] }, expectedScopes: ["tenant-mine", "tenant-mine"] });
|
|
775
|
+
assert.deepStrictEqual(att.erased.map((r) => r.id), [mine.id], "inside the set the request erases");
|
|
776
|
+
const replay = await erase.call(b, { requestId: "req-grant-4", select: { ids: [mine.id] }, expectedScopes: ["tenant-mine"] });
|
|
777
|
+
assert.deepStrictEqual((replay.erasedPreviously ?? []).map((r) => r.id), [mine.id], "a replay under the same set (another spelling) converges — judged against the first resolution, not the live account");
|
|
778
|
+
await assert.rejects(async () => erase.call(b, { requestId: "req-grant-4", select: { ids: [mine.id] }, expectedScopes: ["tenant-mine", "tenant-theirs"] }), (err) => err.code === "config.memory_erasure_scope", "a replay under another set refuses");
|
|
779
|
+
await assert.rejects(async () => erase.call(b, { requestId: "req-grant-4", select: { ids: [mine.id] } }), (err) => err.code === "config.memory_erasure_scope", "a replay with no set refuses (absent and present are different authorizations)");
|
|
780
|
+
assert.deepStrictEqual((await b.getByIds([theirs.id])).map((e) => e.id), [theirs.id], "the other scope's entry survives every call");
|
|
781
|
+
hooks.onOptionalMember?.({ member: "judgesErasureScopes", status: "verified" });
|
|
782
|
+
});
|
|
746
783
|
defer("design/178 v2-c optional export/import faces: export composite / governance slice / custody carriage (absent ⇒ reported)", async () => {
|
|
747
784
|
const b = await hooks.make();
|
|
748
785
|
const seats = [
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ExecutionEnv } from "../../internal/harness-types.js";
|
|
1
2
|
/** Per-segment cap, measured AFTER encoding. A conservative portability policy adopted as contract
|
|
2
3
|
* (research (d) recommendation — NOT a verified third-party hard limit; uuidv7 = 36 chars fits). */
|
|
3
4
|
export declare const SCOPE_SEGMENT_MAX_ENCODED = 64;
|
|
@@ -96,6 +97,17 @@ export declare function formatProjectMarker(projectId: string): string;
|
|
|
96
97
|
export declare function parseProjectMarker(body: string): {
|
|
97
98
|
projectId: string;
|
|
98
99
|
} | null;
|
|
100
|
+
/** What the marker walk reads through: the filesystem the task root names — the leg's execution env (any `ExecutionEnv`
|
|
101
|
+
* satisfies it), or the host's ({@link hostProjectMarkerFs}) for a leg that has none. */
|
|
102
|
+
export type ProjectMarkerFs = Pick<ExecutionEnv, "exists" | "readTextFile">;
|
|
103
|
+
/** The host filesystem as a {@link ProjectMarkerFs} — what a leg whose env does no I/O reads its task root through (its
|
|
104
|
+
* root is a host path: the deployment's `rootPath`). `exists` answers `false` only for a path that is not there; any
|
|
105
|
+
* other failure is an error, never an absence. Read synchronously, as the memory phase always read the marker: a leg
|
|
106
|
+
* with no I/O of its own gains no event-loop turn from its project read (its scheduling against sibling legs stays). */
|
|
107
|
+
export declare const hostProjectMarkerFs: ProjectMarkerFs;
|
|
108
|
+
/** The filesystem a leg's task root names: its execution env, or the host's when the env is the no-I/O placeholder (a leg
|
|
109
|
+
* with no env, or one handed none — the hands band's own "is there a filesystem" reading). */
|
|
110
|
+
export declare function projectMarkerFsOf(env: ExecutionEnv): ProjectMarkerFs;
|
|
99
111
|
/**
|
|
100
112
|
* design/142 §1.1 — resolve a project's identity. READS ONLY THE MARKER (复审 F2: never derives an
|
|
101
113
|
* identity from a git remote; remote-URL normalization is a scaffold-side minting heuristic, not an
|
|
@@ -104,10 +116,39 @@ export declare function parseProjectMarker(body: string): {
|
|
|
104
116
|
* repo root is fail-loud (`config.memory_project_marker_nested`) — monorepo sub-project identity
|
|
105
117
|
* is a future need-signal, not a silent second identity;
|
|
106
118
|
* - outside git, the given rootDir IS the project root (path-form local projects).
|
|
107
|
-
*
|
|
108
|
-
*
|
|
119
|
+
* Read through `fs` — the filesystem `rootDir` names (a remote env's marker lives in that env). A lookup
|
|
120
|
+
* the filesystem could not answer, or a marker it could not read, is `config.memory_project_marker` (never "no marker").
|
|
121
|
+
* Returns null when no marker exists. The leg's verdict over this read is {@link resolveSessionProject}.
|
|
109
122
|
*/
|
|
110
|
-
export declare function resolveProjectId(rootDir: string): {
|
|
123
|
+
export declare function resolveProjectId(fs: ProjectMarkerFs, rootDir: string): Promise<{
|
|
111
124
|
projectId: string;
|
|
112
125
|
markerDir: string;
|
|
113
|
-
} | null
|
|
126
|
+
} | null>;
|
|
127
|
+
/** A leg's project identity. `marker` = the checkout's `.sema/project` (a declaration, when present,
|
|
128
|
+
* equals it); `declared` = `TaskSpec.projectId` in a checkout that carries no marker. */
|
|
129
|
+
export interface SessionProject {
|
|
130
|
+
readonly id: string;
|
|
131
|
+
readonly source: "marker" | "declared";
|
|
132
|
+
}
|
|
133
|
+
/** The ONE verdict every reader of a leg's project identity reads (the `workspace_changed` frame, memory v2). */
|
|
134
|
+
export interface SessionProjectVerdict {
|
|
135
|
+
/** The root the verdict was decided on (the leg's task root): a reader keeping facts about ANOTHER root (memory's
|
|
136
|
+
* per-partition marker hint) reads the verdict as a fact about this root only. */
|
|
137
|
+
readonly root: string;
|
|
138
|
+
/** ABSENT = no marker and no declaration, or the marker could not be read ({@link markerFault} says why). */
|
|
139
|
+
readonly project?: SessionProject;
|
|
140
|
+
/** Why the marker could not be read (nested / corrupt / unreadable), on a leg that declared no project — reported by
|
|
141
|
+
* the caller, NOT thrown here: only a reader that consumes project identity refuses with it (memory v2 `proj:` /
|
|
142
|
+
* `userproj:` keys). A leg that DECLARED a project consumes it, so there the fault is thrown. */
|
|
143
|
+
readonly markerFault?: Error & {
|
|
144
|
+
code: string;
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The leg's ONE project-identity judge, called once per leg on the task root. The marker decides when the
|
|
149
|
+
* checkout carries one; `declared` (`TaskSpec.projectId`) is the identity only where it does not. Refuses the leg when
|
|
150
|
+
* `declared` is not a UUID (`config.project_id_invalid`), when it names a different project than the marker
|
|
151
|
+
* (`config.project_identity_mismatch` — never file the session under the wrong project), and when the marker cannot be
|
|
152
|
+
* read while a declaration needs checking against it (the marker's own code).
|
|
153
|
+
*/
|
|
154
|
+
export declare function resolveSessionProject(fs: ProjectMarkerFs, taskRoot: string, declared: string | undefined): Promise<SessionProjectVerdict>;
|