@sema-agent/core 7.61.0 → 7.63.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 +840 -0
- package/dist/agents/cascade.d.ts +11 -3
- package/dist/agents/cascade.js +1 -1
- package/dist/agents/peer-held-queue.d.ts +27 -4
- package/dist/agents/peer-held-queue.js +81 -36
- package/dist/agents/peer-session-drain.js +13 -3
- package/dist/agents/subagent-transcript-placement.d.ts +23 -0
- package/dist/agents/subagent-transcript-placement.js +14 -0
- package/dist/agents/subagent.d.ts +6 -1
- package/dist/agents/subagent.js +143 -58
- package/dist/agents/suspend-guard.d.ts +38 -16
- package/dist/agents/suspend-guard.js +9 -4
- package/dist/agents/verify.js +4 -3
- package/dist/brain/route-adjudicator.js +9 -4
- package/dist/core/approval-object.js +1 -1
- package/dist/core/arg-summary.js +1 -1
- package/dist/core/ask-question.d.ts +2 -2
- package/dist/core/canonical-json.d.ts +23 -13
- package/dist/core/canonical-json.js +4 -4
- package/dist/core/checkpoint-features.d.ts +722 -0
- package/dist/core/checkpoint-features.js +98 -0
- package/dist/core/checkpoint-queries.d.ts +47 -4
- package/dist/core/checkpoint-queries.js +36 -16
- package/dist/core/checkpoint-requirements.d.ts +12 -5
- package/dist/core/checkpoint-requirements.js +11 -5
- package/dist/core/checkpoint-row-verdict.d.ts +110 -0
- package/dist/core/checkpoint-row-verdict.js +245 -0
- package/dist/core/checkpoint-store.d.ts +76 -753
- package/dist/core/checkpoint-store.js +83 -144
- package/dist/core/compliance.d.ts +6 -2
- package/dist/core/compliance.js +3 -3
- package/dist/core/engine-attestation.d.ts +1 -1
- package/dist/core/engine-notice.d.ts +38 -7
- package/dist/core/engine-notice.js +9 -2
- package/dist/core/gate-fold.js +2 -2
- package/dist/core/git-worktree-env.d.ts +62 -3
- package/dist/core/git-worktree-env.js +91 -30
- package/dist/core/governance-codes.d.ts +9 -3
- package/dist/core/governance-codes.js +16 -3
- package/dist/core/hooks.d.ts +13 -0
- 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 +1 -1
- package/dist/core/locked-config.d.ts +2 -2
- package/dist/core/mcp-host-seat.js +6 -1
- package/dist/core/memory-engine/consolidation-driver.d.ts +33 -18
- package/dist/core/memory-engine/consolidation-driver.js +99 -98
- package/dist/core/memory-engine/consolidation.d.ts +73 -10
- package/dist/core/memory-engine/consolidation.js +167 -11
- package/dist/core/memory-engine/data-plane.d.ts +8 -4
- package/dist/core/memory-engine/data-plane.js +11 -6
- package/dist/core/memory-engine/delegation-settlement.d.ts +37 -35
- package/dist/core/memory-engine/delegation-settlement.js +53 -59
- package/dist/core/memory-engine/dual-root.d.ts +12 -6
- package/dist/core/memory-engine/dual-root.js +9 -5
- package/dist/core/memory-engine/engine.d.ts +98 -35
- package/dist/core/memory-engine/engine.js +477 -380
- package/dist/core/memory-engine/entry-scan.d.ts +8 -0
- package/dist/core/memory-engine/entry-scan.js +3 -0
- package/dist/core/memory-engine/file-backend.d.ts +29 -3
- package/dist/core/memory-engine/file-backend.js +66 -35
- package/dist/core/memory-engine/index.d.ts +7 -7
- package/dist/core/memory-engine/index.js +6 -6
- package/dist/core/memory-engine/landing-admission.d.ts +5 -3
- package/dist/core/memory-engine/landing-admission.js +3 -3
- package/dist/core/memory-engine/layout.d.ts +121 -45
- package/dist/core/memory-engine/layout.js +252 -102
- package/dist/core/memory-engine/memory-backend-contract.d.ts +19 -1
- package/dist/core/memory-engine/memory-backend-contract.js +320 -0
- package/dist/core/memory-engine/memory-deployment.d.ts +31 -8
- package/dist/core/memory-engine/memory-deployment.js +26 -12
- package/dist/core/memory-engine/scope-contract.d.ts +52 -11
- package/dist/core/memory-engine/scope-contract.js +68 -19
- package/dist/core/memory-engine/session-write-home.d.ts +3 -1
- package/dist/core/memory-engine/session-write-home.js +1 -1
- package/dist/core/memory-engine/sync-client.d.ts +3 -1
- package/dist/core/memory-engine/sync-client.js +7 -0
- package/dist/core/memory-engine/sync-report.d.ts +3 -2
- package/dist/core/memory-engine/sync-report.js +6 -2
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.js +10 -10
- package/dist/core/memory-engine/types.d.ts +118 -19
- package/dist/core/memory-engine/types.js +1 -0
- package/dist/core/memory-vector.d.ts +1 -1
- package/dist/core/memory.d.ts +10 -10
- package/dist/core/memory.js +15 -6
- package/dist/core/mode-policy.js +1 -1
- package/dist/core/mods/classic-events.d.ts +9 -1
- package/dist/core/mods/dollar.d.ts +32 -1
- package/dist/core/mods/dollar.js +13 -1
- package/dist/core/mods/kernel/events.d.ts +11 -3
- package/dist/core/mods/kernel/events.js +13 -10
- package/dist/core/mods/lifecycle-stations.d.ts +36 -4
- package/dist/core/mods/lifecycle-stations.js +44 -9
- package/dist/core/mods/session-append.d.ts +4 -1
- package/dist/core/mods/session-append.js +7 -0
- package/dist/core/mods/session-receive.js +12 -15
- package/dist/core/mods/stations.d.ts +70 -6
- package/dist/core/mods/stations.js +144 -1
- package/dist/core/own-property-receipt.d.ts +7 -0
- package/dist/core/own-property-receipt.js +3 -0
- package/dist/core/park-selfcheck.js +2 -2
- package/dist/core/pause-registry.d.ts +2 -0
- package/dist/core/pause-registry.js +3 -0
- package/dist/core/permission-rule-consent.d.ts +10 -3
- package/dist/core/permission-rule-consent.js +37 -24
- package/dist/core/permission-rule-store.d.ts +35 -1
- package/dist/core/permission-rule-store.js +27 -8
- package/dist/core/read-only-shell.js +3 -2
- package/dist/core/read-root-candidate.js +1 -1
- package/dist/core/redaction-marks.d.ts +8 -0
- package/dist/core/redaction-marks.js +6 -0
- package/dist/core/remote-env.d.ts +12 -1
- package/dist/core/remote-env.js +3 -0
- package/dist/core/resume-startup-cause.d.ts +5 -4
- package/dist/core/runner/child-tree.d.ts +29 -3
- package/dist/core/runner/child-tree.js +39 -16
- package/dist/core/runner/compact-session.js +5 -2
- package/dist/core/runner/contracts.d.ts +36 -17
- package/dist/core/runner/delegation-owner.d.ts +43 -0
- package/dist/core/runner/delegation-owner.js +59 -0
- package/dist/core/runner/gate-exit.js +2 -2
- package/dist/core/runner/inherited-ask-grants.js +1 -1
- package/dist/core/runner/lineage-reroot-view.d.ts +56 -0
- package/dist/core/runner/lineage-reroot-view.js +108 -0
- package/dist/core/runner/memory-consolidation-driver.d.ts +6 -3
- package/dist/core/runner/memory-consolidation-driver.js +4 -4
- package/dist/core/runner/memory-consolidation-write-judge.d.ts +2 -1
- package/dist/core/runner/memory-consolidation-write-judge.js +3 -2
- package/dist/core/runner/permission-rule-lanes.d.ts +2 -1
- package/dist/core/runner/permission-rule-lanes.js +2 -2
- package/dist/core/runner/person-path-rows.d.ts +23 -3
- package/dist/core/runner/person-path-rows.js +31 -4
- package/dist/core/runner/placement-fence.d.ts +12 -0
- package/dist/core/runner/placement-fence.js +20 -6
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +4 -1
- package/dist/core/runner/prepare-acquire-reconcile.js +7 -2
- package/dist/core/runner/prepare-ask-lane.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -1
- package/dist/core/runner/prepare-caps-and-workflow.js +6 -3
- package/dist/core/runner/prepare-config-doors.d.ts +6 -6
- package/dist/core/runner/prepare-config-doors.js +3 -4
- package/dist/core/runner/prepare-execution-env.js +17 -6
- package/dist/core/runner/prepare-hands-readface.d.ts +3 -2
- package/dist/core/runner/prepare-hands-readface.js +32 -10
- package/dist/core/runner/prepare-inherited-gate.d.ts +12 -8
- package/dist/core/runner/prepare-inherited-gate.js +14 -6
- package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -4
- package/dist/core/runner/prepare-memory-engine-session.js +4 -4
- package/dist/core/runner/prepare-memory.d.ts +3 -2
- package/dist/core/runner/prepare-memory.js +28 -20
- package/dist/core/runner/prepare-park-ask.js +4 -3
- package/dist/core/runner/prepare-task.js +22 -16
- package/dist/core/runner/prepare-workspace-restore.js +3 -6
- package/dist/core/runner/resume-admission.d.ts +3 -3
- package/dist/core/runner/resume-admission.js +6 -3
- package/dist/core/runner/resume-apply.d.ts +4 -0
- package/dist/core/runner/resume-apply.js +11 -4
- package/dist/core/runner/resume-checkpoint-screen.d.ts +9 -0
- package/dist/core/runner/resume-checkpoint-screen.js +4 -84
- package/dist/core/runner/run-git-lane.d.ts +2 -0
- package/dist/core/runner/run-git-lane.js +4 -1
- package/dist/core/runner/run-harness-handlers.d.ts +2 -0
- package/dist/core/runner/run-harness-handlers.js +3 -2
- package/dist/core/runner/run-leg.js +25 -8
- package/dist/core/runner/run-settle-and-teardown.js +6 -4
- package/dist/core/runner/run-stop-and-final-verify.js +2 -1
- package/dist/core/runner/run-turn-boundary.js +7 -4
- package/dist/core/runner/runtask.js +6 -6
- package/dist/core/runner/steering-preview.d.ts +9 -0
- package/dist/core/runner/steering-preview.js +5 -0
- package/dist/core/runner/stream-steer-verb.js +8 -0
- package/dist/core/runner/terminal-account.js +1 -1
- package/dist/core/runner/tool-face-overlay.js +2 -0
- package/dist/core/runner/turn-attachments.d.ts +5 -0
- package/dist/core/runner/turn-attachments.js +1 -1
- package/dist/core/runner-deps.d.ts +8 -4
- package/dist/core/secret-env.d.ts +9 -6
- package/dist/core/secret-env.js +41 -22
- package/dist/core/session-checkout.d.ts +108 -0
- package/dist/core/session-checkout.js +485 -0
- package/dist/core/session-store.d.ts +13 -5
- package/dist/core/session-store.js +28 -4
- package/dist/core/session.d.ts +29 -5
- package/dist/core/session.js +3 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +6 -12
- package/dist/core/store-contracts/checkpoint-store-contract.js +73 -6
- package/dist/core/store-contracts/session-store-contract.js +61 -8
- package/dist/core/task-event.d.ts +28 -1
- package/dist/core/task-notification.d.ts +9 -1
- package/dist/core/task-notification.js +8 -1
- package/dist/core/task-registry-agent.d.ts +40 -8
- package/dist/core/task-registry-agent.js +57 -24
- package/dist/core/task-registry-shared.d.ts +33 -11
- package/dist/core/task-registry-workflow.js +4 -3
- package/dist/core/task-registry.d.ts +27 -10
- package/dist/core/task-registry.js +19 -13
- package/dist/core/task-result.d.ts +5 -5
- package/dist/core/task-spec-members.js +1 -1
- package/dist/core/task-spec.d.ts +21 -1
- package/dist/core/terminal-cause.d.ts +6 -6
- package/dist/core/tool-face.d.ts +6 -2
- package/dist/core/tool-face.js +1 -1
- package/dist/core/tool-policy.d.ts +16 -13
- package/dist/core/tool-policy.js +11 -10
- package/dist/core/tool-roster.d.ts +4 -4
- package/dist/core/tool-spec.d.ts +42 -19
- package/dist/core/types.d.ts +2 -2
- package/dist/core/types.js +1 -1
- package/dist/core/untrusted-egress.d.ts +15 -4
- package/dist/core/untrusted-egress.js +23 -22
- package/dist/core/workspace-snapshot.d.ts +3 -1
- package/dist/core/workspace-snapshot.js +1 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +3 -0
- package/dist/engine/execution-env/node-execution-env.js +12 -5
- package/dist/engine/harness/types.d.ts +77 -1
- package/dist/engine/harness/types.js +108 -0
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/parent-chain-guard.d.ts +3 -3
- package/dist/engine/session/parent-chain-guard.js +1 -1
- package/dist/engine/session/path-to-root.d.ts +18 -3
- package/dist/engine/session/path-to-root.js +15 -1
- package/dist/engine/session/repo-utils.d.ts +12 -1
- package/dist/engine/session/repo-utils.js +41 -0
- package/dist/engine/session/session.d.ts +24 -1
- package/dist/engine/session/session.js +46 -2
- package/dist/engine/session/storage-base.d.ts +20 -0
- package/dist/engine/session/storage-base.js +28 -9
- package/dist/index.d.ts +16 -12
- package/dist/index.js +11 -8
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +4 -3
- package/dist/internal/harness.js +3 -2
- package/dist/orchestration/run-workflow-tool.d.ts +7 -1
- package/dist/orchestration/run-workflow-tool.js +28 -11
- package/dist/orchestration/workflow-governance.d.ts +1 -1
- package/dist/orchestration/workflow.d.ts +6 -0
- package/dist/orchestration/workflow.js +5 -8
- package/dist/stores/file/checkpoint-store.d.ts +2 -0
- package/dist/stores/file/checkpoint-store.js +7 -6
- package/dist/stores/file/fs-atomic.d.ts +0 -22
- package/dist/stores/file/fs-atomic.js +0 -17
- package/dist/stores/file/index.d.ts +2 -9
- package/dist/stores/file/index.js +2 -4
- package/dist/stores/file/session-store.d.ts +13 -7
- package/dist/stores/file/session-store.js +42 -18
- package/dist/tools/fs/bash-program-position.d.ts +3 -2
- package/dist/tools/fs/bash-program-position.js +10 -10
- package/dist/tools/fs/program-read-model.d.ts +34 -10
- package/dist/tools/fs/program-read-model.js +37 -7
- package/dist/tools/fs/program-read-model.rows.js +13 -2
- package/dist/tools/fs/read-deny.d.ts +13 -1
- package/dist/tools/fs/read-deny.js +10 -2
- package/dist/tools/fs/removal-targets.js +5 -5
- package/dist/tools/fs/safety.d.ts +2 -0
- package/dist/tools/fs/safety.js +1 -1
- package/dist/tools/fs/shell-read-argv.d.ts +11 -2
- package/dist/tools/fs/shell-read-argv.js +45 -29
- package/dist/tools/fs/shell-read-bindings.d.ts +20 -2
- package/dist/tools/fs/shell-read-bindings.js +153 -69
- package/dist/tools/fs/shell-read-brace.d.ts +18 -0
- package/dist/tools/fs/shell-read-brace.js +79 -0
- package/dist/tools/fs/shell-read-check.js +29 -11
- package/dist/tools/fs/shell-read-establish.js +43 -22
- package/dist/tools/fs/shell-read-functions.js +2 -2
- package/dist/tools/fs/shell-read-judge.d.ts +11 -0
- package/dist/tools/fs/shell-read-judge.js +3 -3
- package/dist/tools/fs/shell-read-object-path.d.ts +59 -0
- package/dist/tools/fs/shell-read-object-path.js +119 -0
- package/dist/tools/fs/shell-read-plan.d.ts +18 -0
- package/dist/tools/fs/shell-read-plan.js +217 -104
- package/dist/tools/fs/shell-read-start.d.ts +76 -13
- package/dist/tools/fs/shell-read-start.js +97 -17
- package/dist/tools/fs/shell-read-word.d.ts +10 -0
- package/dist/tools/fs/shell-read-word.js +9 -5
- package/dist/tools/fs/shell-read-workdir.d.ts +54 -14
- package/dist/tools/fs/shell-read-workdir.js +103 -19
- package/dist/tools/fs/shell-read-write-targets.js +13 -8
- package/dist/tools/worktree.d.ts +3 -2
- package/dist/tools/worktree.js +7 -35
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +93 -43
- package/wire-changes/core-stores-sql@7.62.0.json +30 -0
- package/wire-changes/core-stores-sql@7.63.0.json +30 -0
- package/wire-changes/core@7.62.0.json +2181 -0
- package/wire-changes/core@7.63.0.json +3523 -0
- package/wire-changes/mods-kernel@7.62.0.json +42 -0
- package/wire-changes/mods-kernel@7.63.0.json +30 -0
- package/wire-changes/primitives@7.62.0.json +30 -0
- package/wire-changes/primitives@7.63.0.json +445 -0
- package/dist/core/consolidate-scope.d.ts +0 -93
- package/dist/core/consolidate-scope.js +0 -98
- package/dist/core/credential-vocabulary.d.ts +0 -176
- package/dist/core/credential-vocabulary.js +0 -190
- package/dist/core/redaction-passes.d.ts +0 -82
- package/dist/core/redaction-passes.js +0 -377
- package/dist/core/runner/memory-consolidation.d.ts +0 -109
- package/dist/core/runner/memory-consolidation.js +0 -251
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* they land) — a second implementation would be a drift seam, exactly the class the challenge
|
|
9
9
|
* exclusion view closed.
|
|
10
10
|
*/
|
|
11
|
-
import type { MemoryEntry, MemoryEntryHeader, MemoryEntryOrigin, NotePatch } from "./types.js";
|
|
11
|
+
import type { MemoryBackend, MemoryEntry, MemoryEntryHeader, MemoryEntryOrigin, MemoryGovernanceStore, NotePatch } from "./types.js";
|
|
12
|
+
import type { ConsolidationDriverRunRow } from "./consolidation-driver.js";
|
|
12
13
|
/**
|
|
13
14
|
* Derive the SUPERSEDED set from a committed header listing: superseded entry id → the standing
|
|
14
15
|
* carrier (product) id whose edge suppresses it. `active(x) ⇔ !returned.has(x.id)` over non-
|
|
@@ -110,9 +111,13 @@ export interface MemoryConsolidationOptions {
|
|
|
110
111
|
* CLEAN-set arm only — a marked visible set refuses instruction forms under the laundering
|
|
111
112
|
* hard gate no matter what (privilege and hard gate enter and exit through one door). */
|
|
112
113
|
allowInstructionProducts?: true;
|
|
113
|
-
/** D-13a — the multi-node POSTURE declaration: present ⇒ `lease` must be injected
|
|
114
|
-
*
|
|
115
|
-
* undetectable — the declaration turns a silent omission into an
|
|
114
|
+
/** D-13a — the multi-node POSTURE declaration: present ⇒ `lease` must be injected and the backend's consolidation
|
|
115
|
+
* state must ride it (`memoryGovernanceDurability(backend) === "backend"`) — constructor refusal otherwise. Multi-node
|
|
116
|
+
* without declaring is OUT OF CONTRACT (structurally undetectable — the declaration turns a silent omission into an
|
|
117
|
+
* explicit choice). What the engine cannot judge stays the host's word under this posture, as the lease's globality
|
|
118
|
+
* is: a `MemoryEngineOptions.captureRecordStore` the host injects is one every replica reads (that seat's own
|
|
119
|
+
* contract — a supplied carrier is the deployment's durable store); the default carrier lives in the engine's
|
|
120
|
+
* control plane, which on a `"backend"` answer is the store's own. */
|
|
116
121
|
multiNode?: true;
|
|
117
122
|
/** The global lease (§1.7). Absent ⇒ the single-machine plan-seat CAS is the only mutex. */
|
|
118
123
|
lease?: ConsolidationLeaseSeat;
|
|
@@ -178,11 +183,29 @@ export interface ScreenedConsolidationOptions {
|
|
|
178
183
|
* consolidation.
|
|
179
184
|
* - D-13a: `multiNode: true` without an injected lease refuses — the declaration exists exactly
|
|
180
185
|
* to make that omission explicit.
|
|
186
|
+
* - `multiNode: true` over a backend whose consolidation state is replica-local
|
|
187
|
+
* ({@link memoryGovernanceDurability}, the engine's backend's answer handed in as `durability`)
|
|
188
|
+
* refuses — a second replica would read none of the challenges, settlements, lineage and capture
|
|
189
|
+
* opt-outs this one recorded, and consolidate what they exclude. Every consolidation verb reads the screened
|
|
190
|
+
* options, so this closes all of them, not just the driver.
|
|
181
191
|
*/
|
|
182
|
-
export declare function screenConsolidationOptions(given: MemoryConsolidationOptions, provenance: "off" | "carry"): ScreenedConsolidationOptions;
|
|
183
|
-
/**
|
|
192
|
+
export declare function screenConsolidationOptions(given: MemoryConsolidationOptions, provenance: "off" | "carry", durability: MemoryGovernanceDurability): ScreenedConsolidationOptions;
|
|
193
|
+
/** What the model is told to do about a challenged entry it still needs — one sentence for both faces
|
|
194
|
+
* that say it (the challenge announcement, the `memory_get` withheld answer). "Delete" is the act the
|
|
195
|
+
* harvest reads: removing the entry's file deletes it. */
|
|
196
|
+
export declare const MEMORY_CHALLENGED_ENTRY_GUIDANCE = "If the fact is still needed, verify it with the user, record a fresh entry from their current statement, and delete the old entry.";
|
|
197
|
+
/** §1.2-2 — the supersession fuse ceiling: min(N-1, {@link fuseAllowance}); N ≤ 1 ⇒ 0 (one plan
|
|
184
198
|
* may NEVER empty the active set — the N-1 ceiling is unconditional, G21). */
|
|
185
199
|
export declare function supersessionFuseCeiling(activeSetSize: number, opts: Pick<ScreenedConsolidationOptions, "supersedeRatioCap" | "supersedeAbsoluteFloor">): number;
|
|
200
|
+
/** The harvest deletion fuse's absolute floor: a session may remove up to this many of its write
|
|
201
|
+
* scope's materialized files in one harvest whatever the scope's size (the ratio governs above it). */
|
|
202
|
+
export declare const DELETION_FUSE_FLOOR = 3;
|
|
203
|
+
/** The harvest deletion fuse ceiling over `materialized` writable files: {@link fuseAllowance} with
|
|
204
|
+
* {@link DELETION_FUSE_FLOOR}. More removals than this in one harvest is judged an accident and the
|
|
205
|
+
* whole harvest is refused. Unlike the supersession ceiling there is no N-1 cap: removing the only
|
|
206
|
+
* entry of a scope is the ordinary "forget it" case. Read by the host engine's harvest and the remote
|
|
207
|
+
* data plane alike (one fuse, two harvest lanes). */
|
|
208
|
+
export declare function deletionFuseCeiling(materialized: number, ratio: number): number;
|
|
186
209
|
/**
|
|
187
210
|
* design/376 C-2② — the scan-refusal fuse ceiling: how many scan-refused products ONE plan may
|
|
188
211
|
* carry before the whole plan refuses instead of committing around them.
|
|
@@ -317,22 +340,22 @@ export declare function sessionsSinceExcludingCurrent(row: Pick<ConsolidationGat
|
|
|
317
340
|
*
|
|
318
341
|
* The ring records the calling session (dedup), so `count` INCLUDES the caller; the gate here and the number beside it are {@link sessionsSinceExcludingCurrent}, which takes it back out.
|
|
319
342
|
*/
|
|
320
|
-
export declare function recordConsolidationSession(
|
|
343
|
+
export declare function recordConsolidationSession(store: MemoryGovernanceStore, scope: string, sessionId: string, opts: ScreenedConsolidationOptions, now: () => number): Promise<{
|
|
321
344
|
recommended: boolean;
|
|
322
345
|
sessionsSince: number;
|
|
323
|
-
}
|
|
346
|
+
}>;
|
|
324
347
|
/**
|
|
325
348
|
* §1.4.5 — the active-set COLLAPSE fuse: record the freshly derived active-set size against the
|
|
326
349
|
* stored baseline; a single-window shrink beyond the ratio cap answers the collapse fact (the
|
|
327
350
|
* caller discloses via incident + announcement — the read face NEVER refuses service over it).
|
|
328
351
|
* Baseline loss ⇒ re-baseline silently (conservative: one extra disclosure at worst next window).
|
|
329
352
|
*/
|
|
330
|
-
export declare function recordActiveSetBaseline(
|
|
353
|
+
export declare function recordActiveSetBaseline(store: MemoryGovernanceStore, scope: string, size: number, ratioCap: number): Promise<{
|
|
331
354
|
collapsed?: {
|
|
332
355
|
from: number;
|
|
333
356
|
to: number;
|
|
334
357
|
};
|
|
335
|
-
}
|
|
358
|
+
}>;
|
|
336
359
|
/** §1.5 — a directed-change intent (TERMINAL-STATE form: the intent names the target end state,
|
|
337
360
|
* never an increment — the precondition for replay/re-judgment converging at any interleaving). */
|
|
338
361
|
export type ConsolidationIntent = {
|
|
@@ -501,6 +524,46 @@ export interface ConsolidationIntentCredentialRow {
|
|
|
501
524
|
*/
|
|
502
525
|
export declare function recordIntentCredentials(controlDir: string, rows: readonly ConsolidationIntentCredentialRow[]): string[];
|
|
503
526
|
export declare function readIntentCredentials(controlDir: string): Record<string, ConsolidationIntentCredentialRow>;
|
|
527
|
+
/** The run account's file and the mint archive's directory under a control plane — File-store internals. */
|
|
528
|
+
export declare const CONSOLIDATION_DRIVER_RUNS_FILE = "distiller-runs.json";
|
|
529
|
+
/** The archive name carries the CLAIM (`attempt`): two invocations that raced onto one run each archive under their
|
|
530
|
+
* own name, so a superseded worker never overwrites the winning transcript. */
|
|
531
|
+
export declare function distillerPlanArchiveName(runId: string, attempt: number): string;
|
|
532
|
+
/** The superseded-writer refusal of {@link MemoryGovernanceStore.writeRun} (code `memory.consolidation_driver_superseded`). */
|
|
533
|
+
export declare function consolidationRunSuperseded(scope: string, cur: Pick<ConsolidationDriverRunRow, "runId" | "attempt"> | undefined): Error & {
|
|
534
|
+
code: string;
|
|
535
|
+
};
|
|
536
|
+
/** {@link memoryGovernanceDurability}'s answer. */
|
|
537
|
+
export type MemoryGovernanceDurability = "backend" | "replica-local";
|
|
538
|
+
/**
|
|
539
|
+
* Whether the state a consolidation reads and writes rides `backend` — kept with its entries, the same for every replica
|
|
540
|
+
* that opens it (`"backend"`) — or lives in the control plane of the replica the engine runs on (`"replica-local"`): a
|
|
541
|
+
* second replica, or the same one after its disk is replaced, sees none of it. It answers one question: may
|
|
542
|
+
* consolidation be armed across replicas. The engine's construction asks it for `consolidation.multiNode` (a
|
|
543
|
+
* `"replica-local"` answer refuses `config.memory_consolidation_replica_local`); a host that arms or reports
|
|
544
|
+
* consolidation asks here, never of a backend member it probes itself. A deployment-wide memory face asks a different
|
|
545
|
+
* fact — whether the backend publishes a control plane — and does not ask here.
|
|
546
|
+
*
|
|
547
|
+
* `"backend"` ⇔ the backend publishes its own control plane (`controlPlaneRoot`, a non-empty string — the File backend:
|
|
548
|
+
* every control-plane record, the consolidation store and the governance ledgers alike, sits in its directory). A
|
|
549
|
+
* backend that carries `MemoryBackend.governance` but no control plane still answers `"replica-local"`: the
|
|
550
|
+
* consolidation state and the governance documents (lineage, challenges, settlements, session accounts and the
|
|
551
|
+
* announcement queue a consolidation writes) ride its store, but the instruction holds (each beside its captured bytes)
|
|
552
|
+
* are still kept in the replica's control plane, and the answer changes only when they ride the store too. Eligibility also reads the capture opt-out records
|
|
553
|
+
* (`MemoryEngineOptions.captureRecordStore`: a carrier the host injects is its declaration of a store every replica
|
|
554
|
+
* reads; the default is a file in the engine's control plane — the store's own directory on the File backend): an
|
|
555
|
+
* answer that turns `"backend"` for a backend without a control plane must hold for the default carrier as well.
|
|
556
|
+
*/
|
|
557
|
+
export declare function memoryGovernanceDurability(backend: MemoryBackend): MemoryGovernanceDurability;
|
|
558
|
+
/** The control plane a File governance store keeps its documents in; `undefined` for any other store. */
|
|
559
|
+
export declare function fileGovernanceStoreDir(store: MemoryGovernanceStore): string | undefined;
|
|
560
|
+
/**
|
|
561
|
+
* The consolidation state's File store over one control plane — the gate file, the plan workbook, the intent
|
|
562
|
+
* credentials, the run account and the mint archive exactly as they have always been laid out (same names, same
|
|
563
|
+
* bytes, same locks). The File backend carries it over its own control plane; an engine whose backend carries no
|
|
564
|
+
* store keeps its state with this over the replica's control plane.
|
|
565
|
+
*/
|
|
566
|
+
export declare function fileGovernanceStore(controlDir: string): MemoryGovernanceStore;
|
|
504
567
|
/** Derive a product's slug from its proposed name (memory filename charset; collisions are the
|
|
505
568
|
* backend's deterministic -n suffix). */
|
|
506
569
|
export declare function deriveProductSlug(name: string | undefined, fallback: string): string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { existsSync, readdirSync, renameSync } from "node:fs";
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, renameSync, rmSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { uuidv7 } from "../../engine/session/uuid.js";
|
|
4
|
-
import { atomicWriteFileSync, lockedStrictUpdate, readStrictSidecar, ControlPlaneCorruptError, ensureDirExists } from "./layout.js";
|
|
4
|
+
import { atomicWriteFileSync, fileGovernanceDocOf, lockedStrictUpdate, readStrictSidecar, ControlPlaneCorruptError, ensureDirExists } from "./layout.js";
|
|
5
5
|
import { thrownText } from "../thrown-value.js";
|
|
6
6
|
import { optionKeys, receiveMembers } from "../own-property-receipt.js";
|
|
7
7
|
export function deriveSupersededSet(headers, opts = {}) {
|
|
@@ -58,7 +58,7 @@ function coded(message, code) {
|
|
|
58
58
|
e.code = code;
|
|
59
59
|
return e;
|
|
60
60
|
}
|
|
61
|
-
export function screenConsolidationOptions(given, provenance) {
|
|
61
|
+
export function screenConsolidationOptions(given, provenance, durability) {
|
|
62
62
|
if (provenance === "off") {
|
|
63
63
|
throw coded(`MemoryEngineOptions.consolidation cannot be enabled under provenance: "off" — the consolidation fold law must be able to mint origin markers (a marked input's product would otherwise commit unmarked). Enable provenance "carry" or remove the consolidation options.`, "config.memory_consolidation_provenance_off");
|
|
64
64
|
}
|
|
@@ -98,12 +98,23 @@ export function screenConsolidationOptions(given, provenance) {
|
|
|
98
98
|
if (raw.lease !== undefined && typeof raw.lease.acquire !== "function") {
|
|
99
99
|
throw coded(`MemoryEngineOptions.consolidation.lease.acquire must be a function.`, "config.memory_consolidation");
|
|
100
100
|
}
|
|
101
|
+
if (screened.multiNode && durability === "replica-local") {
|
|
102
|
+
throw coded(`MemoryEngineOptions.consolidation.multiNode declared over a backend whose consolidation state is replica-local (memoryGovernanceDurability) — the challenge, settlement and lineage ledgers and the capture opt-out records a consolidation's eligibility reads stay in this replica's control plane, so another replica would consolidate entries this one excludes. Run consolidation on one node (remove the multiNode declaration) or use a backend whose state rides it.`, "config.memory_consolidation_replica_local");
|
|
103
|
+
}
|
|
101
104
|
return screened;
|
|
102
105
|
}
|
|
106
|
+
export const MEMORY_CHALLENGED_ENTRY_GUIDANCE = "If the fact is still needed, verify it with the user, record a fresh entry from their current statement, and delete the old entry.";
|
|
107
|
+
function fuseAllowance(n, ratio, floor) {
|
|
108
|
+
return Math.max(floor, Math.floor(ratio * n));
|
|
109
|
+
}
|
|
103
110
|
export function supersessionFuseCeiling(activeSetSize, opts) {
|
|
104
111
|
if (activeSetSize <= 1)
|
|
105
112
|
return 0;
|
|
106
|
-
return Math.min(activeSetSize - 1,
|
|
113
|
+
return Math.min(activeSetSize - 1, fuseAllowance(activeSetSize, opts.supersedeRatioCap, opts.supersedeAbsoluteFloor));
|
|
114
|
+
}
|
|
115
|
+
export const DELETION_FUSE_FLOOR = 3;
|
|
116
|
+
export function deletionFuseCeiling(materialized, ratio) {
|
|
117
|
+
return fuseAllowance(materialized, ratio, DELETION_FUSE_FLOOR);
|
|
107
118
|
}
|
|
108
119
|
export function scanRefusalCeiling(submittedProducts, opts) {
|
|
109
120
|
if (submittedProducts <= 0)
|
|
@@ -161,11 +172,11 @@ export function recommendationUnconsumed(row) {
|
|
|
161
172
|
export function sessionsSinceExcludingCurrent(row) {
|
|
162
173
|
return Math.max(0, (row?.sessions.count ?? 0) - 1);
|
|
163
174
|
}
|
|
164
|
-
export function recordConsolidationSession(
|
|
165
|
-
return
|
|
175
|
+
export function recordConsolidationSession(store, scope, sessionId, opts, now) {
|
|
176
|
+
return store.transact([], (file) => {
|
|
166
177
|
const row = file.scopes[scope] ?? freshRow();
|
|
167
178
|
if (row.sessions.ring.includes(sessionId)) {
|
|
168
|
-
return { result: { recommended: false, sessionsSince: sessionsSinceExcludingCurrent(row) } };
|
|
179
|
+
return { writeGate: false, result: { recommended: false, sessionsSince: sessionsSinceExcludingCurrent(row) } };
|
|
169
180
|
}
|
|
170
181
|
row.sessions.count += 1;
|
|
171
182
|
row.sessions.ring.push(sessionId);
|
|
@@ -182,17 +193,17 @@ export function recordConsolidationSession(controlDir, scope, sessionId, opts, n
|
|
|
182
193
|
row.lastRecommendedAt = at;
|
|
183
194
|
}
|
|
184
195
|
file.scopes[scope] = row;
|
|
185
|
-
return {
|
|
196
|
+
return { writeGate: true, result: { recommended, sessionsSince: banked } };
|
|
186
197
|
});
|
|
187
198
|
}
|
|
188
|
-
export function recordActiveSetBaseline(
|
|
189
|
-
return
|
|
199
|
+
export function recordActiveSetBaseline(store, scope, size, ratioCap) {
|
|
200
|
+
return store.transact([], (file) => {
|
|
190
201
|
const row = file.scopes[scope] ?? freshRow();
|
|
191
202
|
const prev = row.activeSetBaseline;
|
|
192
203
|
row.activeSetBaseline = size;
|
|
193
204
|
file.scopes[scope] = row;
|
|
194
205
|
const collapsed = prev !== undefined && prev > 0 && size < prev && (prev - size) / prev > ratioCap ? { from: prev, to: size } : undefined;
|
|
195
|
-
return {
|
|
206
|
+
return { writeGate: true, result: collapsed !== undefined ? { collapsed } : {} };
|
|
196
207
|
});
|
|
197
208
|
}
|
|
198
209
|
export function isValidConsolidationPlanId(value) {
|
|
@@ -362,6 +373,151 @@ export function readIntentCredentials(controlDir) {
|
|
|
362
373
|
const raw = readStrictSidecar(controlDir, CONSOLIDATION_INTENTS_FILE, "memory consolidation intent-credential account");
|
|
363
374
|
return coerceIntentFile(raw).rows;
|
|
364
375
|
}
|
|
376
|
+
export const CONSOLIDATION_DRIVER_RUNS_FILE = "distiller-runs.json";
|
|
377
|
+
function coerceRunsFile(raw) {
|
|
378
|
+
if (raw === undefined)
|
|
379
|
+
return { v: 1, scopes: {} };
|
|
380
|
+
if (typeof raw !== "object" || raw === null || raw.v !== 1 || typeof raw.scopes !== "object" || raw.scopes === null) {
|
|
381
|
+
throw new ControlPlaneCorruptError("memory consolidation driver run account has an unrecognized shape (fail-closed sidecar)");
|
|
382
|
+
}
|
|
383
|
+
for (const [scope, rowRaw] of Object.entries(raw.scopes)) {
|
|
384
|
+
const r = rowRaw;
|
|
385
|
+
if (typeof r !== "object" || r === null || typeof r["runId"] !== "string" || (r["state"] !== "pending" && r["state"] !== "settled") || typeof r["cyclesDone"] !== "number") {
|
|
386
|
+
throw new ControlPlaneCorruptError(`memory consolidation driver run row for scope ${JSON.stringify(scope)} is malformed (fail-closed sidecar)`);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return raw;
|
|
390
|
+
}
|
|
391
|
+
export function distillerPlanArchiveName(runId, attempt) {
|
|
392
|
+
return `${runId}-a${attempt}.json`;
|
|
393
|
+
}
|
|
394
|
+
function mintPath(controlDir, name) {
|
|
395
|
+
return /^[A-Za-z0-9][A-Za-z0-9_-]{7,63}-a[0-9]{1,9}\.json$/.test(name) ? join(controlDir, CONSOLIDATION_DRIVER_PLANS_DIR, name) : undefined;
|
|
396
|
+
}
|
|
397
|
+
export function consolidationRunSuperseded(scope, cur) {
|
|
398
|
+
const e = new Error(`memory consolidation driver run seat for scope ${JSON.stringify(scope)} was taken over by a newer invocation${cur !== undefined ? ` (run ${cur.runId} attempt ${cur.attempt ?? 0})` : ""} — this worker stops without settling; the newer claim owns the account.`);
|
|
399
|
+
e.code = "memory.consolidation_driver_superseded";
|
|
400
|
+
return e;
|
|
401
|
+
}
|
|
402
|
+
export function memoryGovernanceDurability(backend) {
|
|
403
|
+
const root = Reflect.get(backend, "controlPlaneRoot");
|
|
404
|
+
return typeof root === "string" && root !== "" ? "backend" : "replica-local";
|
|
405
|
+
}
|
|
406
|
+
const FILE_GOVERNANCE_DIRS = new WeakMap();
|
|
407
|
+
export function fileGovernanceStoreDir(store) {
|
|
408
|
+
return FILE_GOVERNANCE_DIRS.get(store);
|
|
409
|
+
}
|
|
410
|
+
function isMintArchive(value) {
|
|
411
|
+
return typeof value === "object" && value !== null && Reflect.get(value, "kind") === "llm-consolidation-plan";
|
|
412
|
+
}
|
|
413
|
+
export function fileGovernanceStore(controlDir) {
|
|
414
|
+
const runsWhat = "memory consolidation driver run account";
|
|
415
|
+
const store = Object.freeze({
|
|
416
|
+
async readDoc(name) {
|
|
417
|
+
const doc = fileGovernanceDocOf(name);
|
|
418
|
+
return readStrictSidecar(controlDir, doc.file, doc.what);
|
|
419
|
+
},
|
|
420
|
+
async updateDoc(name, coerce, fn) {
|
|
421
|
+
const doc = fileGovernanceDocOf(name);
|
|
422
|
+
return lockedStrictUpdate(controlDir, doc.file, doc.what, coerce, fn);
|
|
423
|
+
},
|
|
424
|
+
async transact(planIds, fn) {
|
|
425
|
+
return updateConsolidationGate(controlDir, (file) => {
|
|
426
|
+
const reads = new Map(planIds.map((id) => [id, readConsolidationPlan(controlDir, id)]));
|
|
427
|
+
const staged = new Map();
|
|
428
|
+
const tx = {
|
|
429
|
+
scopes: file.scopes,
|
|
430
|
+
plan(planId) {
|
|
431
|
+
const read = reads.get(planId);
|
|
432
|
+
if (read === undefined)
|
|
433
|
+
throw new Error(`consolidation transaction: plan ${JSON.stringify(planId)} was not named when the transaction began, so it was not read under it`);
|
|
434
|
+
return read;
|
|
435
|
+
},
|
|
436
|
+
writePlan(plan) {
|
|
437
|
+
staged.set(plan.planId, plan);
|
|
438
|
+
},
|
|
439
|
+
};
|
|
440
|
+
const { writeGate, result } = fn(tx);
|
|
441
|
+
for (const plan of staged.values())
|
|
442
|
+
writeConsolidationPlan(controlDir, plan);
|
|
443
|
+
return writeGate ? { next: file, result } : { result };
|
|
444
|
+
});
|
|
445
|
+
},
|
|
446
|
+
async readGate() {
|
|
447
|
+
return readConsolidationGateFile(controlDir).scopes;
|
|
448
|
+
},
|
|
449
|
+
readPlan(planId) {
|
|
450
|
+
return readConsolidationPlan(controlDir, planId);
|
|
451
|
+
},
|
|
452
|
+
async listPlanIds() {
|
|
453
|
+
return listConsolidationPlanIds(controlDir);
|
|
454
|
+
},
|
|
455
|
+
async quarantinePlan(planId) {
|
|
456
|
+
return quarantineCorruptPlan(controlDir, planId);
|
|
457
|
+
},
|
|
458
|
+
async recordIntents(rows) {
|
|
459
|
+
return recordIntentCredentials(controlDir, rows);
|
|
460
|
+
},
|
|
461
|
+
async readIntents() {
|
|
462
|
+
return readIntentCredentials(controlDir);
|
|
463
|
+
},
|
|
464
|
+
async claimRun(scope, fresh) {
|
|
465
|
+
return lockedStrictUpdate(controlDir, CONSOLIDATION_DRIVER_RUNS_FILE, runsWhat, coerceRunsFile, (file) => {
|
|
466
|
+
const cur = file.scopes[scope];
|
|
467
|
+
if (cur !== undefined && cur.state === "pending") {
|
|
468
|
+
cur.attempt = (cur.attempt ?? 0) + 1;
|
|
469
|
+
file.scopes[scope] = cur;
|
|
470
|
+
return { next: file, result: { row: structuredClone(cur), resumed: true } };
|
|
471
|
+
}
|
|
472
|
+
const row = fresh();
|
|
473
|
+
file.scopes[scope] = row;
|
|
474
|
+
return { next: file, result: { row: structuredClone(row), resumed: false } };
|
|
475
|
+
});
|
|
476
|
+
},
|
|
477
|
+
async readRun(scope) {
|
|
478
|
+
return coerceRunsFile(readStrictSidecar(controlDir, CONSOLIDATION_DRIVER_RUNS_FILE, runsWhat)).scopes[scope];
|
|
479
|
+
},
|
|
480
|
+
async writeRun(row) {
|
|
481
|
+
lockedStrictUpdate(controlDir, CONSOLIDATION_DRIVER_RUNS_FILE, runsWhat, coerceRunsFile, (file) => {
|
|
482
|
+
const cur = file.scopes[row.scope];
|
|
483
|
+
if (cur === undefined || cur.runId !== row.runId || (cur.attempt ?? 0) !== row.attempt)
|
|
484
|
+
throw consolidationRunSuperseded(row.scope, cur);
|
|
485
|
+
file.scopes[row.scope] = row;
|
|
486
|
+
return { next: file, result: undefined };
|
|
487
|
+
});
|
|
488
|
+
},
|
|
489
|
+
async archiveMint(runId, attempt, plan) {
|
|
490
|
+
ensureDirExists(join(controlDir, CONSOLIDATION_DRIVER_PLANS_DIR));
|
|
491
|
+
const name = distillerPlanArchiveName(runId, attempt);
|
|
492
|
+
atomicWriteFileSync(join(controlDir, CONSOLIDATION_DRIVER_PLANS_DIR, name), `${JSON.stringify(plan, null, 2)}\n`);
|
|
493
|
+
return name;
|
|
494
|
+
},
|
|
495
|
+
async readMint(name) {
|
|
496
|
+
const path = mintPath(controlDir, name);
|
|
497
|
+
if (path === undefined || !existsSync(path))
|
|
498
|
+
return undefined;
|
|
499
|
+
let parsed;
|
|
500
|
+
try {
|
|
501
|
+
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
502
|
+
}
|
|
503
|
+
catch (err) {
|
|
504
|
+
throw new ControlPlaneCorruptError(`memory consolidation mint archive ${JSON.stringify(name)} is unreadable or unparseable: ${thrownText(err)}`, { cause: err });
|
|
505
|
+
}
|
|
506
|
+
if (!isMintArchive(parsed))
|
|
507
|
+
throw new ControlPlaneCorruptError(`memory consolidation mint archive ${JSON.stringify(name)} does not carry the mint's kind (fail-closed)`);
|
|
508
|
+
return parsed;
|
|
509
|
+
},
|
|
510
|
+
async eraseMint(name) {
|
|
511
|
+
const path = mintPath(controlDir, name);
|
|
512
|
+
if (path === undefined || !existsSync(path))
|
|
513
|
+
return false;
|
|
514
|
+
rmSync(path, { force: true });
|
|
515
|
+
return true;
|
|
516
|
+
},
|
|
517
|
+
});
|
|
518
|
+
FILE_GOVERNANCE_DIRS.set(store, controlDir);
|
|
519
|
+
return store;
|
|
520
|
+
}
|
|
365
521
|
export function deriveProductSlug(name, fallback) {
|
|
366
522
|
const base = (name ?? "").toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[-.]+|[-.]+$/g, "");
|
|
367
523
|
return base.length > 0 ? base : fallback;
|
|
@@ -2,7 +2,8 @@ import type { HarvestRejection, MemoryBackend, MemoryEntry, NotePatch, PatchRepo
|
|
|
2
2
|
/** Default per-file byte cap — SAME value as the host engine's MAX_MEMORY_BYTES (独立轨 F3: a 60KB
|
|
3
3
|
* entry legal on the host must not be re-rejected every remote round; one cap, one truth). */
|
|
4
4
|
export declare const REMOTE_HARVEST_PER_FILE_BYTES: number;
|
|
5
|
-
/**
|
|
5
|
+
/** The deletion fuse's ratio leg on the remote lane (engine MASS_DELETION_FUSE_RATIO): with the shared
|
|
6
|
+
* floor, more removals than max(floor, ⌊ratio × N⌋) refuses the harvest wholesale. */
|
|
6
7
|
export declare const REMOTE_MASS_DELETION_FUSE_RATIO = 0.5;
|
|
7
8
|
/** File-count cap per harvest (host DEFAULT_MAX_MEMORY_FILES parity). */
|
|
8
9
|
export declare const REMOTE_HARVEST_MAX_FILES = 500;
|
|
@@ -52,7 +53,9 @@ export interface RemoteHarvestResult {
|
|
|
52
53
|
/** Feed to `backend.applyPatches` (the deployment owns the call + the resulting PatchReport). */
|
|
53
54
|
patches: NotePatch[];
|
|
54
55
|
rejections: HarvestRejection[];
|
|
55
|
-
/** Baseline files
|
|
56
|
+
/** Baseline files gone from the read-back set (absent, or blank). A writable one is the session's
|
|
57
|
+
* removal and rides `patches` as a delete (unless the fuse trips); a read-only one is only listed
|
|
58
|
+
* (no delete; any restore is the deployment's sandbox I/O). */
|
|
56
59
|
missing: string[];
|
|
57
60
|
/** Set instead of patches when the mass-deletion fuse trips (deployment surfaces it, human call). */
|
|
58
61
|
incident?: {
|
|
@@ -71,8 +74,9 @@ export interface RemoteHarvestResult {
|
|
|
71
74
|
/**
|
|
72
75
|
* The pure gate+diff core over files read back from a remote sandbox. Same judgment order as the
|
|
73
76
|
* host engine's harvest: readonly-layer tamper → rejection (restore is the deployment's I/O);
|
|
74
|
-
*
|
|
75
|
-
* id-immutability (baseline id wins) → tombstone
|
|
77
|
+
* removals + fuse (a removed writable file = a CAS'd delete); per-file size cap → scan rule set
|
|
78
|
+
* (secret/injection/filename) → parse → id-immutability (baseline id wins) → tombstone delete → CAS
|
|
79
|
+
* update / rename / add.
|
|
76
80
|
*/
|
|
77
81
|
export declare function harvestFilesToPatches(baseline: RemoteMemoryBaseline, files: readonly RemoteMemoryFile[], opts?: {
|
|
78
82
|
perFileBytes?: number;
|
|
@@ -2,7 +2,8 @@ import { uuidv7 } from "../../internal/harness.js";
|
|
|
2
2
|
import { firstSentence } from "../memory.js";
|
|
3
3
|
import { computeEntryRev, parseEntryFile, serializeEntryFile, UNCLOSED_MEMORY_FILE_REASON } from "./frontmatter.js";
|
|
4
4
|
import { scanMemoryFileName, scanMemoryWrite } from "./scan.js";
|
|
5
|
-
import { MEMORY_INDEX_FILENAME } from "./entry-scan.js";
|
|
5
|
+
import { MEMORY_INDEX_FILENAME, carriesEntry } from "./entry-scan.js";
|
|
6
|
+
import { deletionFuseCeiling } from "./consolidation.js";
|
|
6
7
|
import { scopeDirName } from "./layout.js";
|
|
7
8
|
export const REMOTE_HARVEST_PER_FILE_BYTES = 100 * 1024;
|
|
8
9
|
export const REMOTE_MASS_DELETION_FUSE_RATIO = 0.5;
|
|
@@ -33,7 +34,8 @@ export function harvestFilesToPatches(baseline, files, opts = {}) {
|
|
|
33
34
|
const writeScope = baseline.writeScope;
|
|
34
35
|
if (writeScope === null)
|
|
35
36
|
return out;
|
|
36
|
-
const
|
|
37
|
+
const carried = files.filter((f) => carriesEntry(f.content));
|
|
38
|
+
const byRel = new Map(carried.map((f) => [f.relPath, f]));
|
|
37
39
|
const baseByRel = new Map(baseline.files.map((b) => [b.relPath, b]));
|
|
38
40
|
const basePathById = new Map(baseline.files.filter((b) => !b.readonly).map((b) => [b.id, b.relPath]));
|
|
39
41
|
const readonlyPrefixes = new Set();
|
|
@@ -70,7 +72,7 @@ export function harvestFilesToPatches(baseline, files, opts = {}) {
|
|
|
70
72
|
}
|
|
71
73
|
const presentIds = new Set();
|
|
72
74
|
const parsedByRel = new Map();
|
|
73
|
-
for (const f of
|
|
75
|
+
for (const f of carried) {
|
|
74
76
|
if (baseByRel.get(f.relPath)?.readonly)
|
|
75
77
|
continue;
|
|
76
78
|
const p = parseEntryFile(f.content);
|
|
@@ -81,16 +83,19 @@ export function harvestFilesToPatches(baseline, files, opts = {}) {
|
|
|
81
83
|
const writable = baseline.files.filter((b) => !b.readonly);
|
|
82
84
|
const missingWritable = writable.filter((b) => !byRel.has(b.relPath) && !presentIds.has(b.id));
|
|
83
85
|
out.missing.push(...missingWritable.map((b) => b.relPath));
|
|
84
|
-
|
|
86
|
+
const ceiling = deletionFuseCeiling(writable.length, fuseRatio);
|
|
87
|
+
if (missingWritable.length > ceiling) {
|
|
85
88
|
out.incident = {
|
|
86
89
|
kind: "mass_deletion",
|
|
87
|
-
detail: `${missingWritable.length}/${writable.length} materialized memory files are missing from the read-back set —
|
|
90
|
+
detail: `${missingWritable.length}/${writable.length} materialized memory files are missing from the read-back set — more than one harvest may remove (${ceiling}), judged an accident: harvest refused, no patches`,
|
|
88
91
|
};
|
|
89
92
|
out.patches = [];
|
|
90
93
|
return out;
|
|
91
94
|
}
|
|
95
|
+
for (const b of missingWritable)
|
|
96
|
+
out.patches.push({ op: "delete", id: b.id, baseRev: b.rev });
|
|
92
97
|
let kept = 0;
|
|
93
|
-
for (const f of
|
|
98
|
+
for (const f of carried) {
|
|
94
99
|
const base = baseByRel.get(f.relPath);
|
|
95
100
|
if (base?.readonly)
|
|
96
101
|
continue;
|