@sema-agent/core 7.62.0 → 7.64.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 +936 -0
- package/dist/agents/cc-peer-directory.js +1 -0
- package/dist/agents/cc-peer-wire.d.ts +4 -0
- package/dist/agents/cc-peer-wire.js +1 -0
- package/dist/agents/cc-uds-peer-channel.js +5 -0
- package/dist/agents/cross-session-judge.d.ts +3 -1
- package/dist/agents/cross-session-judge.js +4 -1
- package/dist/agents/peer-directory.d.ts +8 -0
- package/dist/agents/peer-directory.js +4 -0
- package/dist/agents/peer-held-queue.d.ts +9 -3
- package/dist/agents/peer-held-queue.js +12 -9
- package/dist/agents/peer-idle.d.ts +20 -1
- package/dist/agents/peer-idle.js +23 -12
- package/dist/agents/peer-notice-route.d.ts +16 -5
- package/dist/agents/peer-notice-route.js +11 -9
- package/dist/agents/peer-notices.d.ts +25 -8
- package/dist/agents/peer-notices.js +6 -1
- package/dist/agents/peer-session-drain.d.ts +32 -6
- package/dist/agents/peer-session-drain.js +100 -26
- package/dist/agents/send-message-tool.d.ts +7 -0
- package/dist/agents/send-message-tool.js +18 -6
- package/dist/agents/subagent-transcript-placement.d.ts +23 -0
- package/dist/agents/subagent-transcript-placement.js +14 -0
- package/dist/agents/subagent.js +102 -54
- package/dist/brain/route-adjudicator.js +9 -4
- package/dist/core/allow-entry.d.ts +4 -0
- package/dist/core/approval-object.js +1 -1
- package/dist/core/arg-summary.js +1 -1
- package/dist/core/ask-origin.d.ts +1 -1
- package/dist/core/ask-origin.js +2 -2
- package/dist/core/ask-question.d.ts +2 -2
- package/dist/core/ask-unresolvable-notice.d.ts +13 -4
- package/dist/core/ask-unresolvable-notice.js +10 -3
- package/dist/core/auto-compaction.d.ts +7 -5
- package/dist/core/background-agent-store.d.ts +7 -0
- package/dist/core/background-agent-store.js +3 -0
- package/dist/core/canonical-json.d.ts +23 -13
- package/dist/core/canonical-json.js +4 -4
- package/dist/core/checkpoint-queries.d.ts +50 -4
- package/dist/core/checkpoint-queries.js +42 -17
- package/dist/core/checkpoint-requirements.d.ts +3 -3
- package/dist/core/checkpoint-requirements.js +2 -1
- package/dist/core/checkpoint-row-verdict.d.ts +15 -4
- package/dist/core/checkpoint-row-verdict.js +22 -2
- package/dist/core/checkpoint-store.d.ts +28 -11
- package/dist/core/checkpoint-store.js +45 -4
- package/dist/core/compliance.d.ts +6 -2
- package/dist/core/compliance.js +3 -3
- package/dist/core/context-settings.d.ts +40 -9
- package/dist/core/context-settings.js +32 -10
- package/dist/core/engine-attestation.d.ts +27 -7
- package/dist/core/engine-attestation.js +5 -1
- package/dist/core/engine-notice.d.ts +43 -5
- package/dist/core/extension-requester.d.ts +9 -0
- package/dist/core/extension-requester.js +7 -0
- package/dist/core/file-history-store.d.ts +28 -0
- package/dist/core/file-history-store.js +48 -5
- package/dist/core/fs-write-gate-policy.js +1 -1
- package/dist/core/gate-fold.js +2 -0
- package/dist/core/gate-lanes.js +2 -0
- package/dist/core/gate-outcome.d.ts +39 -2
- package/dist/core/gate-outcome.js +20 -1
- 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 +17 -3
- package/dist/core/leg-identity.d.ts +19 -1
- package/dist/core/leg-identity.js +12 -0
- package/dist/core/mailbox-store.d.ts +39 -4
- package/dist/core/mailbox-store.js +14 -2
- package/dist/core/memory-engine/consolidation-driver.d.ts +32 -17
- package/dist/core/memory-engine/consolidation-driver.js +99 -98
- package/dist/core/memory-engine/consolidation.d.ts +74 -10
- package/dist/core/memory-engine/consolidation.js +183 -11
- package/dist/core/memory-engine/control-objects.d.ts +25 -0
- package/dist/core/memory-engine/control-objects.js +151 -0
- package/dist/core/memory-engine/control-plane-adoption.d.ts +48 -0
- package/dist/core/memory-engine/control-plane-adoption.js +159 -0
- 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 +58 -40
- package/dist/core/memory-engine/delegation-settlement.js +270 -85
- package/dist/core/memory-engine/dual-root.d.ts +12 -6
- package/dist/core/memory-engine/dual-root.js +11 -7
- package/dist/core/memory-engine/engine.d.ts +136 -58
- package/dist/core/memory-engine/engine.js +491 -394
- 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 +62 -60
- package/dist/core/memory-engine/file-backend.js +122 -198
- package/dist/core/memory-engine/index.d.ts +8 -7
- package/dist/core/memory-engine/index.js +7 -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 +127 -46
- package/dist/core/memory-engine/layout.js +264 -109
- package/dist/core/memory-engine/memory-backend-contract.d.ts +26 -1
- package/dist/core/memory-engine/memory-backend-contract.js +476 -0
- package/dist/core/memory-engine/memory-deployment.d.ts +42 -11
- package/dist/core/memory-engine/memory-deployment.js +54 -15
- package/dist/core/memory-engine/origin-clearance.d.ts +12 -3
- package/dist/core/memory-engine/origin-clearance.js +68 -9
- 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 +37 -2
- package/dist/core/memory-engine/session-write-home.js +38 -11
- 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 +155 -19
- package/dist/core/memory-engine/types.js +2 -0
- package/dist/core/memory.js +15 -6
- package/dist/core/mode-policy.js +3 -3
- package/dist/core/mods/agent-stations.d.ts +18 -0
- package/dist/core/mods/agent-stations.js +8 -6
- package/dist/core/mods/extension-call.d.ts +4 -0
- package/dist/core/mods/extension-call.js +8 -0
- package/dist/core/mods/stations.d.ts +20 -1
- package/dist/core/mods/stations.js +21 -2
- package/dist/core/mods/tool-call.js +3 -4
- package/dist/core/parent-spec-seat.d.ts +2 -2
- 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/peer-channel.d.ts +5 -0
- package/dist/core/permission-rule-consent.d.ts +26 -8
- package/dist/core/permission-rule-consent.js +76 -36
- package/dist/core/permission-rule-store.d.ts +72 -13
- package/dist/core/permission-rule-store.js +29 -8
- package/dist/core/read-only-shell.js +3 -2
- package/dist/core/redaction-marks.d.ts +8 -0
- package/dist/core/redaction-marks.js +6 -0
- package/dist/core/refusal-echo.d.ts +20 -0
- package/dist/core/refusal-echo.js +33 -0
- package/dist/core/remote-env.d.ts +12 -1
- package/dist/core/remote-env.js +3 -0
- package/dist/core/retention.d.ts +180 -10
- package/dist/core/retention.js +45 -0
- package/dist/core/retired-keys.d.ts +5 -0
- package/dist/core/retired-keys.js +3 -0
- package/dist/core/rule-offer-read.d.ts +0 -4
- package/dist/core/rule-offer-read.js +2 -18
- package/dist/core/runner/child-tree.d.ts +29 -3
- package/dist/core/runner/child-tree.js +39 -16
- package/dist/core/runner/classifier-ladder.d.ts +7 -1
- package/dist/core/runner/classifier-ladder.js +4 -2
- package/dist/core/runner/compact-session.js +10 -7
- package/dist/core/runner/compaction-call-options.d.ts +7 -7
- package/dist/core/runner/compaction-call-options.js +3 -2
- package/dist/core/runner/contracts.d.ts +39 -11
- package/dist/core/runner/delegation-owner.d.ts +10 -3
- package/dist/core/runner/delegation-owner.js +4 -1
- package/dist/core/runner/gate-exit.d.ts +6 -0
- package/dist/core/runner/gate-exit.js +13 -4
- package/dist/core/runner/inherited-ask-grants.js +1 -1
- package/dist/core/runner/memory-consolidation-driver.d.ts +10 -5
- package/dist/core/runner/memory-consolidation-driver.js +12 -9
- 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/person-path-rows.d.ts +8 -3
- package/dist/core/runner/person-path-rows.js +5 -1
- package/dist/core/runner/placement-fence.d.ts +12 -0
- package/dist/core/runner/placement-fence.js +20 -6
- package/dist/core/runner/prepare-ask-lane.js +5 -5
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +7 -2
- package/dist/core/runner/prepare-caps-and-workflow.js +7 -4
- package/dist/core/runner/prepare-config-doors.js +4 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
- package/dist/core/runner/prepare-delegation-surface.js +2 -2
- package/dist/core/runner/prepare-execution-env.js +17 -6
- package/dist/core/runner/prepare-gate-stations.d.ts +5 -0
- package/dist/core/runner/prepare-gate-stations.js +5 -5
- package/dist/core/runner/prepare-hands-readface.d.ts +2 -1
- package/dist/core/runner/prepare-hands-readface.js +5 -4
- package/dist/core/runner/prepare-inherited-gate.d.ts +13 -9
- package/dist/core/runner/prepare-inherited-gate.js +12 -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 +7 -2
- package/dist/core/runner/prepare-memory.js +41 -39
- package/dist/core/runner/prepare-park-ask.js +4 -3
- package/dist/core/runner/prepare-policy-chain.js +7 -7
- package/dist/core/runner/prepare-prompt-inputs.js +1 -1
- package/dist/core/runner/prepare-task.js +26 -18
- package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
- package/dist/core/runner/prepare-wiring-manifest.js +3 -2
- package/dist/core/runner/prepare-workspace-restore.js +3 -6
- package/dist/core/runner/resume-admission.d.ts +2 -2
- package/dist/core/runner/resume-admission.js +2 -23
- package/dist/core/runner/role-resolution-table.d.ts +98 -0
- package/dist/core/runner/role-resolution-table.js +62 -0
- package/dist/core/runner/run-compaction-machinery.js +2 -2
- package/dist/core/runner/run-identity-wiring.js +12 -9
- package/dist/core/runner/run-leg.js +9 -5
- package/dist/core/runner/run-notification-lane.js +22 -22
- package/dist/core/runner/run-recovery-lanes.js +3 -3
- package/dist/core/runner/run-settle-and-teardown.js +3 -2
- package/dist/core/runner/run-terminal-adoption.js +1 -1
- package/dist/core/runner/run-turn-boundary.js +14 -15
- package/dist/core/runner/runtask.js +1 -1
- package/dist/core/runner/terminal-account.js +1 -1
- package/dist/core/runner/tool-occurrence.d.ts +4 -2
- package/dist/core/runner/tool-occurrence.js +2 -2
- package/dist/core/runner-deps.d.ts +7 -3
- package/dist/core/secret-env.d.ts +1 -1
- package/dist/core/secret-env.js +4 -4
- package/dist/core/session-checkout.d.ts +168 -0
- package/dist/core/session-checkout.js +579 -0
- package/dist/core/session-store.d.ts +12 -4
- package/dist/core/session-store.js +23 -3
- package/dist/core/session.d.ts +16 -2
- package/dist/core/session.js +3 -0
- package/dist/core/shell-read-silence.js +8 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +0 -12
- package/dist/core/store-contracts/checkpoint-store-contract.js +6 -7
- package/dist/core/store-contracts/peer-directory-contract.js +8 -1
- package/dist/core/store-contracts/session-store-contract.js +39 -0
- package/dist/core/task-event.d.ts +30 -5
- package/dist/core/task-notification.d.ts +119 -32
- package/dist/core/task-notification.js +186 -100
- package/dist/core/task-registry-agent.d.ts +25 -2
- package/dist/core/task-registry-agent.js +56 -22
- package/dist/core/task-registry-shared.d.ts +33 -11
- package/dist/core/task-registry.d.ts +33 -9
- package/dist/core/task-registry.js +36 -18
- package/dist/core/task-spec-members.js +1 -1
- package/dist/core/task-spec.d.ts +27 -2
- package/dist/core/tool-errors.d.ts +14 -6
- package/dist/core/tool-errors.js +1 -1
- package/dist/core/tool-policy.d.ts +32 -13
- package/dist/core/tool-policy.js +27 -17
- package/dist/core/tool-result-store.d.ts +20 -0
- package/dist/core/tool-spec.d.ts +42 -19
- package/dist/core/trace.d.ts +3 -2
- package/dist/core/types.d.ts +1 -1
- package/dist/core/untrusted-egress.d.ts +15 -4
- package/dist/core/untrusted-egress.js +23 -22
- package/dist/core/workflow-journal-store.d.ts +11 -0
- package/dist/core/workflow-journal-store.js +7 -0
- package/dist/core/workflow-run-store.d.ts +9 -0
- package/dist/core/workflow-run-store.js +6 -0
- package/dist/core/workspace-snapshot.d.ts +3 -1
- package/dist/core/workspace-snapshot.js +1 -0
- package/dist/engine/compaction/compaction.d.ts +2 -1
- package/dist/engine/harness/types.d.ts +67 -1
- package/dist/engine/harness/types.js +108 -0
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/session.d.ts +30 -1
- package/dist/engine/session/session.js +48 -1
- package/dist/index.d.ts +12 -7
- package/dist/index.js +12 -7
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/orchestration/run-workflow-tool.d.ts +8 -1
- package/dist/orchestration/run-workflow-tool.js +8 -0
- package/dist/orchestration/workflow-types.d.ts +2 -1
- package/dist/orchestration/workflow.d.ts +6 -0
- package/dist/orchestration/workflow.js +5 -2
- package/dist/stores/file/checkpoint-store.d.ts +6 -0
- package/dist/stores/file/checkpoint-store.js +4 -1
- package/dist/stores/file/file-history-store.d.ts +13 -0
- package/dist/stores/file/file-history-store.js +75 -13
- package/dist/stores/file/index.d.ts +11 -1
- package/dist/stores/file/index.js +7 -11
- package/dist/stores/file/permission-rule-store.d.ts +23 -0
- package/dist/stores/file/permission-rule-store.js +75 -7
- package/dist/stores/file/session-store.js +2 -1
- package/dist/stores/file/tool-result-store.d.ts +14 -0
- package/dist/stores/file/tool-result-store.js +39 -2
- package/dist/stores/file/workflow-journal-store.d.ts +4 -0
- package/dist/stores/file/workflow-journal-store.js +17 -0
- package/dist/stores/file/workflow-run-store.d.ts +3 -0
- package/dist/stores/file/workflow-run-store.js +15 -0
- package/dist/tools/fs/bash-program-position.js +3 -3
- 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 +28 -3
- package/dist/tools/fs/read-deny.js +18 -2
- package/dist/tools/fs/removal-targets.js +3 -3
- 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 +8 -1
- package/dist/tools/fs/shell-read-argv.js +34 -29
- package/dist/tools/fs/shell-read-bindings.d.ts +2 -0
- package/dist/tools/fs/shell-read-bindings.js +5 -1
- 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.d.ts +8 -2
- package/dist/tools/fs/shell-read-check.js +16 -14
- package/dist/tools/fs/shell-read-establish.js +23 -16
- 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-plan.d.ts +10 -0
- package/dist/tools/fs/shell-read-plan.js +189 -93
- package/dist/tools/fs/shell-read-start.d.ts +19 -9
- package/dist/tools/fs/shell-read-start.js +20 -12
- 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 +26 -7
- package/dist/tools/fs/shell-read-workdir.js +73 -12
- 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 +135 -11
- package/wire-changes/core-stores-sql@7.63.0.json +30 -0
- package/wire-changes/core-stores-sql@7.64.0.json +30 -0
- package/wire-changes/core@7.63.0.json +3523 -0
- package/wire-changes/core@7.64.0.json +2653 -0
- package/wire-changes/mods-kernel@7.63.0.json +30 -0
- package/wire-changes/mods-kernel@7.64.0.json +30 -0
- package/wire-changes/primitives@7.63.0.json +445 -0
- package/wire-changes/primitives@7.64.0.json +30 -0
- 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
|
@@ -1,66 +1,23 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
1
|
import { uuidv7 } from "../../internal/harness.js";
|
|
3
|
-
import {
|
|
2
|
+
import { enqueueMemoryAnnouncement } from "./layout.js";
|
|
4
3
|
import { inlineUntrusted } from "../untrusted-text.js";
|
|
5
4
|
import { extensionWords } from "../untrusted-egress.js";
|
|
6
5
|
import { deliverEngineNotice } from "../engine-notice.js";
|
|
7
|
-
import {
|
|
6
|
+
import { CONSOLIDATION_FORCE_THROTTLE_FLOOR_MS, distillerPlanArchiveName, screenConsolidationOptions, supersessionFuseCeiling, recommendationUnconsumed, CONSOLIDATION_WRITE_REFUSED_CODE, ConsolidationRefusedError, } from "./consolidation.js";
|
|
8
7
|
import { memoryConsolidationIncompleteNotice, memoryConsolidationWithheldNotice } from "./engine.js";
|
|
9
8
|
import { asThrownError, thrownText } from "../thrown-value.js";
|
|
9
|
+
import { complianceCapabilityProblem, resolveComplianceDenies } from "../compliance.js";
|
|
10
|
+
import { memoryScopeOwnerOf } from "./scope-contract.js";
|
|
10
11
|
import { CONSOLIDATION_DRIVE_ABORT, CONSOLIDATION_SNAPSHOT_PARKED, MEMORY_DISTILLER_CONTRACT_V1, detectCleanArmVerbatimLeak, driveConsolidationToFixpoint, isAliasModelId, llmPlanDistiller, mintExposurePartitionedPlan, mintLlmConsolidationPlan, normalizedCandidateRev, } from "./distiller.js";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (raw === undefined)
|
|
15
|
-
return { v: 1, scopes: {} };
|
|
16
|
-
if (typeof raw !== "object" || raw === null || raw.v !== 1 || typeof raw.scopes !== "object" || raw.scopes === null) {
|
|
17
|
-
throw new ControlPlaneCorruptError("memory consolidation driver run account has an unrecognized shape (fail-closed sidecar)");
|
|
12
|
+
async function writeDriverRun(store, row) {
|
|
13
|
+
try {
|
|
14
|
+
await store.writeRun(row);
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
if (typeof err === "object" && err !== null && Reflect.get(err, "code") === "memory.consolidation_driver_superseded")
|
|
18
|
+
Reflect.set(err, CONSOLIDATION_DRIVE_ABORT, true);
|
|
19
|
+
throw err;
|
|
24
20
|
}
|
|
25
|
-
return raw;
|
|
26
|
-
}
|
|
27
|
-
export function readConsolidationDriverRun(controlDir, scope) {
|
|
28
|
-
return coerceRunsFile(readStrictSidecar(controlDir, CONSOLIDATION_DRIVER_RUNS_FILE, "memory consolidation driver run account")).scopes[scope];
|
|
29
|
-
}
|
|
30
|
-
function writeDriverRun(controlDir, row) {
|
|
31
|
-
lockedStrictUpdate(controlDir, CONSOLIDATION_DRIVER_RUNS_FILE, "memory consolidation driver run account", coerceRunsFile, (file) => {
|
|
32
|
-
const cur = file.scopes[row.scope];
|
|
33
|
-
if (cur === undefined || cur.runId !== row.runId || (cur.attempt ?? 0) !== row.attempt) {
|
|
34
|
-
const e = new Error(`memory consolidation driver run seat for scope ${JSON.stringify(row.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.`);
|
|
35
|
-
e.code = "memory.consolidation_driver_superseded";
|
|
36
|
-
e[CONSOLIDATION_DRIVE_ABORT] = true;
|
|
37
|
-
throw e;
|
|
38
|
-
}
|
|
39
|
-
file.scopes[row.scope] = row;
|
|
40
|
-
return { next: file, result: undefined };
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
function claimDriverRun(controlDir, scope, fresh) {
|
|
44
|
-
return lockedStrictUpdate(controlDir, CONSOLIDATION_DRIVER_RUNS_FILE, "memory consolidation driver run account", coerceRunsFile, (file) => {
|
|
45
|
-
const cur = file.scopes[scope];
|
|
46
|
-
if (cur !== undefined && cur.state === "pending") {
|
|
47
|
-
cur.attempt = (cur.attempt ?? 0) + 1;
|
|
48
|
-
file.scopes[scope] = cur;
|
|
49
|
-
return { next: file, result: { row: structuredClone(cur), resumed: true } };
|
|
50
|
-
}
|
|
51
|
-
const row = fresh();
|
|
52
|
-
file.scopes[scope] = row;
|
|
53
|
-
return { next: file, result: { row: structuredClone(row), resumed: false } };
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
export function distillerPlanArchiveName(runId, attempt) {
|
|
57
|
-
return `${runId}-a${attempt}.json`;
|
|
58
|
-
}
|
|
59
|
-
export function archiveDistillerPlan(controlDir, runId, plan, attempt = 1) {
|
|
60
|
-
ensureDirExists(join(controlDir, CONSOLIDATION_DRIVER_PLANS_DIR));
|
|
61
|
-
const name = distillerPlanArchiveName(runId, attempt);
|
|
62
|
-
atomicWriteFileSync(join(controlDir, CONSOLIDATION_DRIVER_PLANS_DIR, name), `${JSON.stringify(plan, null, 2)}\n`);
|
|
63
|
-
return name;
|
|
64
21
|
}
|
|
65
22
|
export { CONSOLIDATION_WRITE_REFUSED_CODE };
|
|
66
23
|
function driverConfigRefusal(message) {
|
|
@@ -68,6 +25,49 @@ function driverConfigRefusal(message) {
|
|
|
68
25
|
e.code = "config.memory_consolidation_driver";
|
|
69
26
|
return e;
|
|
70
27
|
}
|
|
28
|
+
async function refuseUnlessCompliancePermits(compliance, scope) {
|
|
29
|
+
if (compliance === undefined)
|
|
30
|
+
return;
|
|
31
|
+
if (typeof compliance !== "object" || compliance === null || !Object.hasOwn(compliance, "scopeContract") || (compliance.scopeContract !== undefined && compliance.scopeContract !== "v2")) {
|
|
32
|
+
throw driverConfigRefusal(`runMemoryConsolidationDriver: opts.compliance must be an object whose scopeContract key is present and "v2" or undefined — the owner of the scope is read under it, and a guessed contract reads another owner.`);
|
|
33
|
+
}
|
|
34
|
+
const { postureOf, scopeContract, denies = [] } = compliance;
|
|
35
|
+
if (postureOf !== undefined && typeof postureOf !== "function")
|
|
36
|
+
throw driverConfigRefusal(`runMemoryConsolidationDriver: opts.compliance.postureOf must be a function when present (got ${typeof postureOf}).`);
|
|
37
|
+
if (!Array.isArray(denies))
|
|
38
|
+
throw driverConfigRefusal(`runMemoryConsolidationDriver: opts.compliance.denies must be an array when present.`);
|
|
39
|
+
for (const cap of denies) {
|
|
40
|
+
const problem = complianceCapabilityProblem(cap, "opts.compliance.denies");
|
|
41
|
+
if (problem !== undefined)
|
|
42
|
+
throw driverConfigRefusal(`runMemoryConsolidationDriver: ${problem}`);
|
|
43
|
+
}
|
|
44
|
+
const owners = [memoryScopeOwnerOf(scope, scopeContract)];
|
|
45
|
+
if (scopeContract !== "v2") {
|
|
46
|
+
try {
|
|
47
|
+
owners.push(memoryScopeOwnerOf(scope, "v2"));
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const subjects = [...new Set(owners.map((o) => (o.kind === "principal" ? o.principal : undefined)))];
|
|
53
|
+
for (const subject of subjects) {
|
|
54
|
+
const ownerText = subject !== undefined ? `principal ${inlineUntrusted(subject, 80)}` : "the deployment";
|
|
55
|
+
let ownerDenies;
|
|
56
|
+
try {
|
|
57
|
+
const posture = postureOf === undefined ? undefined : ((await postureOf(subject)) ?? undefined);
|
|
58
|
+
ownerDenies = posture === undefined ? new Set() : resolveComplianceDenies(posture);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
throw new ConsolidationRefusedError("config.compliance_required", `memory consolidation refused for scope ${inlineUntrusted(scope, 80)}: the compliance posture of its owner (${ownerText}) could not be read (${inlineUntrusted(thrownText(err), 200)}), so every managed capability is denied fail-closed — no run was started and nothing was written.`);
|
|
62
|
+
}
|
|
63
|
+
if (ownerDenies.has("memory_consolidation")) {
|
|
64
|
+
throw new ConsolidationRefusedError("config.compliance_denied", `memory consolidation refused for scope ${inlineUntrusted(scope, 80)}: the capability "memory_consolidation" is denied by the compliance posture of its owner (${ownerText}) — no run was started and nothing was written.`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (denies.includes("memory_consolidation")) {
|
|
68
|
+
throw new ConsolidationRefusedError("config.compliance_denied", `memory consolidation refused for scope ${inlineUntrusted(scope, 80)}: the capability "memory_consolidation" is denied by the caller's own denies — no run was started and nothing was written.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
71
|
class DriverMintFailure extends Error {
|
|
72
72
|
detail;
|
|
73
73
|
constructor(detail) {
|
|
@@ -140,7 +140,7 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
140
140
|
if (typeof contract?.version !== "string" || contract.version === "" || typeof contract?.grouping?.instructions !== "string" || typeof contract?.writing?.instructions !== "string") {
|
|
141
141
|
throw driverConfigRefusal("runMemoryConsolidationDriver: opts.contract does not carry the contract shape (version + grouping/writing instructions).");
|
|
142
142
|
}
|
|
143
|
-
const screened = screenConsolidationOptions(opts.consolidation ?? {}, "carry");
|
|
143
|
+
const screened = screenConsolidationOptions(opts.consolidation ?? {}, "carry", "backend");
|
|
144
144
|
const mintRepairBudget = opts.mintRepairBudget ?? 0.1;
|
|
145
145
|
const now = opts.now ?? Date.now;
|
|
146
146
|
const rawSleep = opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
@@ -155,7 +155,8 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
155
155
|
}
|
|
156
156
|
};
|
|
157
157
|
const throttleWindowMs = Math.min(screened.minRunIntervalMs, CONSOLIDATION_FORCE_THROTTLE_FLOOR_MS);
|
|
158
|
-
const
|
|
158
|
+
const store = engine.governance;
|
|
159
|
+
await refuseUnlessCompliancePermits(opts.compliance, scope);
|
|
159
160
|
if (typeof opts.writeJudge !== "function")
|
|
160
161
|
throw driverConfigRefusal(`runMemoryConsolidationDriver needs an explicit write judge (opts.writeJudge), got ${typeof opts.writeJudge} — a run writes the library with nobody watching, so it asks the judgment a foreground write meets before it starts; an absent seat is refused, never read as "no rules apply" (a host that holds no rules passes a judge that answers no_objection).`);
|
|
161
162
|
let libraryHome;
|
|
@@ -175,7 +176,7 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
175
176
|
return undefined;
|
|
176
177
|
});
|
|
177
178
|
const openFold = await engine.readConsolidationFoldState(scope);
|
|
178
|
-
const { row: run, resumed } =
|
|
179
|
+
const { row: run, resumed } = await store.claimRun(scope, () => ({
|
|
179
180
|
runId: uuidv7(),
|
|
180
181
|
scope,
|
|
181
182
|
attempt: 1,
|
|
@@ -197,9 +198,9 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
197
198
|
run.contractVersion = contract.version;
|
|
198
199
|
}
|
|
199
200
|
const announceFailures = [];
|
|
200
|
-
const announce = (items) => {
|
|
201
|
+
const announce = async (items) => {
|
|
201
202
|
try {
|
|
202
|
-
enqueueMemoryAnnouncement(
|
|
203
|
+
await enqueueMemoryAnnouncement(store, { kind: "gate", scope, at: now(), items });
|
|
203
204
|
}
|
|
204
205
|
catch (err) {
|
|
205
206
|
announceFailures.push(thrownText(err));
|
|
@@ -217,44 +218,44 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
217
218
|
}
|
|
218
219
|
})(opts.baseUrl);
|
|
219
220
|
const egressSeat = `${inlineUntrusted(opts.model, 80)}${egressEndpoint}`;
|
|
220
|
-
const announceMintEgress = (calls, offered, plan) => {
|
|
221
|
+
const announceMintEgress = async (calls, offered, plan) => {
|
|
221
222
|
if (calls === 0) {
|
|
222
|
-
announce([
|
|
223
|
+
await announce([
|
|
223
224
|
`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} made NO model call: all ${offered} offered candidate(s) were withheld from every arm, so no memory content left this process.`,
|
|
224
225
|
]);
|
|
225
226
|
return;
|
|
226
227
|
}
|
|
227
228
|
const armLine = (plan?.minting.arms ?? []).map((a) => `${a.arm} arm ${a.candidateCount} candidate(s) in ${a.calls} call(s)`).join(", ");
|
|
228
|
-
announce([
|
|
229
|
+
await announce([
|
|
229
230
|
`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} SENT memory content to the configured consolidation model: ${egressSeat} — ${armLine || `up to ${offered} candidate(s) over ${calls} call(s) (the mint failed before its per-arm split was recorded; an arm that never ran sent nothing)`}. Each candidate was rendered as its name, description and body.`,
|
|
230
231
|
]);
|
|
231
232
|
const withheld = run.withheldFromCleanArm ?? 0;
|
|
232
233
|
if (withheld > 0) {
|
|
233
234
|
const neverSent = run.withheldNeverSent ?? 0;
|
|
234
235
|
const sent = Math.max(0, withheld - neverSent);
|
|
235
|
-
announce([
|
|
236
|
+
await announce([
|
|
236
237
|
` ${withheld} externally-marked entr${withheld === 1 ? "y was" : "ies were"} withheld from the clean products' prompts.` +
|
|
237
238
|
(sent > 0 ? ` ${sent} of those ${sent === 1 ? "was" : "were"} sent to the model in a separate marked-only call.` : "") +
|
|
238
239
|
(neverSent > 0 ? ` ${neverSent} ${neverSent === 1 ? "was" : "were"} not sent to the model at all.` : ""),
|
|
239
240
|
]);
|
|
240
241
|
}
|
|
241
242
|
};
|
|
242
|
-
const settle = (outcome, drive, stopDetail) => {
|
|
243
|
+
const settle = async (outcome, drive, stopDetail) => {
|
|
243
244
|
run.state = "settled";
|
|
244
245
|
run.outcome = outcome;
|
|
245
246
|
run.settledAt = now();
|
|
246
247
|
if (stopDetail !== undefined)
|
|
247
248
|
run.stopDetail = stopDetail;
|
|
248
249
|
run.residue = run.residue ?? drive?.stop?.fuseBlocked;
|
|
249
|
-
writeDriverRun(
|
|
250
|
+
await writeDriverRun(store, run);
|
|
250
251
|
if (outcome === "converged") {
|
|
251
252
|
try {
|
|
252
|
-
|
|
253
|
-
const row =
|
|
253
|
+
await store.transact([], (tx) => {
|
|
254
|
+
const row = tx.scopes[scope];
|
|
254
255
|
if (row === undefined || !recommendationUnconsumed(row))
|
|
255
|
-
return { result: undefined };
|
|
256
|
+
return { writeGate: false, result: undefined };
|
|
256
257
|
row.lastRunAt = now();
|
|
257
|
-
return {
|
|
258
|
+
return { writeGate: true, result: undefined };
|
|
258
259
|
});
|
|
259
260
|
}
|
|
260
261
|
catch (err) {
|
|
@@ -267,14 +268,14 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
267
268
|
notices.push(notice);
|
|
268
269
|
if (opts.onNotice !== undefined)
|
|
269
270
|
deliverEngineNotice(opts.onNotice, notice);
|
|
270
|
-
announce([notice.message]);
|
|
271
|
+
await announce([notice.message]);
|
|
271
272
|
}
|
|
272
273
|
if ((run.withheldFromCleanArm ?? 0) > 0) {
|
|
273
274
|
const withheldNotice = memoryConsolidationWithheldNotice({ scope, runId: run.runId, withheld: run.withheldFromCleanArm, neverSent: run.withheldNeverSent ?? 0 });
|
|
274
275
|
notices.push(withheldNotice);
|
|
275
276
|
if (opts.onNotice !== undefined)
|
|
276
277
|
deliverEngineNotice(opts.onNotice, withheldNotice);
|
|
277
|
-
announce([withheldNotice.message]);
|
|
278
|
+
await announce([withheldNotice.message]);
|
|
278
279
|
}
|
|
279
280
|
return {
|
|
280
281
|
runId: run.runId,
|
|
@@ -325,7 +326,7 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
325
326
|
catch (err) {
|
|
326
327
|
if (codeOf(err) === "config.memory_consolidation_driver")
|
|
327
328
|
throw err;
|
|
328
|
-
announce([
|
|
329
|
+
await announce([
|
|
329
330
|
`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} ATTEMPTED to send memory content to the configured consolidation model: ${egressSeat} — the seat threw before any answer was recorded, so whether any content reached the provider is NOT observable from here; up to ${candidates.length} candidate(s) were in flight, each rendered as its name, description and body. Treat this as a possible transmission.`,
|
|
330
331
|
]);
|
|
331
332
|
throw new DriverMintFailure(`the model seat failed during the mint: ${thrownText(err)}`);
|
|
@@ -337,7 +338,7 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
337
338
|
run.usage.completionTokens += c.usage?.completionTokens ?? 0;
|
|
338
339
|
}
|
|
339
340
|
if (!minted.ok) {
|
|
340
|
-
announceMintEgress(transcript.length, candidates.length);
|
|
341
|
+
await announceMintEgress(transcript.length, candidates.length);
|
|
341
342
|
throw new DriverMintFailure(minted.reason);
|
|
342
343
|
}
|
|
343
344
|
const plan = minted.plan;
|
|
@@ -346,7 +347,7 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
346
347
|
const markedServed = (plan.servedCandidates ?? []).filter((r) => r.marked).length;
|
|
347
348
|
run.withheldNeverSent = Math.max(0, plan.withheldFromCleanArm - markedServed);
|
|
348
349
|
}
|
|
349
|
-
announceMintEgress(transcript.length, candidates.length, plan);
|
|
350
|
+
await announceMintEgress(transcript.length, candidates.length, plan);
|
|
350
351
|
run.usage.retries += plan.minting.parseRepairs.retries;
|
|
351
352
|
run.usage.truncations += plan.minting.parseRepairs.lengthCapped.length;
|
|
352
353
|
run.repairs = {
|
|
@@ -367,8 +368,8 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
367
368
|
const purity = detectCleanArmVerbatimLeak(plan);
|
|
368
369
|
if (purity.findings.length > 0) {
|
|
369
370
|
run.planArchive = distillerPlanArchiveName(run.runId, run.attempt);
|
|
370
|
-
writeDriverRun(
|
|
371
|
-
|
|
371
|
+
await writeDriverRun(store, run);
|
|
372
|
+
await store.archiveMint(run.runId, run.attempt, plan);
|
|
372
373
|
const where = [...new Set(purity.findings.map((f) => `#${f.productIndex}.${f.field}`))].sort();
|
|
373
374
|
throw new DriverPurityViolation(`the exposure partition's clean arm is not clean: ${purity.findings.length} verbatim marked-side byte sequence(s) surfaced in ${new Set(purity.findings.map((f) => f.productIndex)).size} product(s) that would commit UNMARKED, across ${purity.scannedProducts} scanned product(s) against ${purity.markedUniqueShingles} marked-unique shingle(s). Locations (product index into the archived plan . field): ${where.slice(0, 8).join(", ")}${where.length > 8 ? ", …" : ""}. The whole mint is discarded with zero writes; NO model-authored bytes (neither the offending text nor the product keys) are reproduced here — re-run detectCleanArmVerbatimLeak over the archived plan ${run.planArchive} for the byte-level witness.`);
|
|
374
375
|
}
|
|
@@ -379,8 +380,8 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
379
380
|
...(plan.mintExposure !== undefined ? { mintExposure: plan.mintExposure } : {}),
|
|
380
381
|
...(plan.servedCandidates !== undefined ? { servedCandidates: plan.servedCandidates } : {}),
|
|
381
382
|
};
|
|
382
|
-
writeDriverRun(
|
|
383
|
-
|
|
383
|
+
await writeDriverRun(store, run);
|
|
384
|
+
await store.archiveMint(run.runId, run.attempt, plan);
|
|
384
385
|
}
|
|
385
386
|
const roster = run.planCache?.servedCandidates;
|
|
386
387
|
if (roster !== undefined && roster.length > 0) {
|
|
@@ -400,7 +401,7 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
400
401
|
violations.push(`${rowR.id}: marked flag flipped since the mint (${String(rowR.marked)} -> ${String(off.marked)})`);
|
|
401
402
|
continue;
|
|
402
403
|
}
|
|
403
|
-
ownFold ??= collectRunFoldEvidence(engine, scope, run.requestId);
|
|
404
|
+
ownFold ??= await collectRunFoldEvidence(engine, scope, run.requestId);
|
|
404
405
|
if (ownFold.unreadable !== undefined)
|
|
405
406
|
continue;
|
|
406
407
|
if (!ownFold.targets.has(rowR.id))
|
|
@@ -441,7 +442,7 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
441
442
|
};
|
|
442
443
|
let firstSnapshotOfNewRun = !resumed;
|
|
443
444
|
const takeSnapshot = async (_cycle) => {
|
|
444
|
-
writeDriverRun(
|
|
445
|
+
await writeDriverRun(store, run);
|
|
445
446
|
let force = !firstSnapshotOfNewRun;
|
|
446
447
|
let throttleWaits = 0;
|
|
447
448
|
let busyWaits = 0;
|
|
@@ -461,10 +462,10 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
461
462
|
if (throttleWaits >= MAX_THROTTLE_WAITS_PER_SNAPSHOT)
|
|
462
463
|
throw err;
|
|
463
464
|
throttleWaits += 1;
|
|
464
|
-
const lastRunAt = engine.readConsolidationGate(scope)?.lastRunAt;
|
|
465
|
+
const lastRunAt = (await engine.readConsolidationGate(scope))?.lastRunAt;
|
|
465
466
|
const until = (lastRunAt ?? now()) + throttleWindowMs;
|
|
466
467
|
run.nextEligibleAt = until;
|
|
467
|
-
writeDriverRun(
|
|
468
|
+
await writeDriverRun(store, run);
|
|
468
469
|
const waitMs = Math.max(1, until - now());
|
|
469
470
|
await sleep(waitMs);
|
|
470
471
|
continue;
|
|
@@ -497,7 +498,7 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
497
498
|
maxCycles: opts.maxCycles ?? 64,
|
|
498
499
|
takeSnapshot,
|
|
499
500
|
writeGate,
|
|
500
|
-
onCycle: (row) => {
|
|
501
|
+
onCycle: async (row) => {
|
|
501
502
|
cyclesSeen.push(row);
|
|
502
503
|
if (row.committed.products > 0 || row.committed.superseded > 0)
|
|
503
504
|
run.cyclesDone += 1;
|
|
@@ -505,21 +506,21 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
505
506
|
if (row.planId !== undefined)
|
|
506
507
|
run.planIds.push(row.planId);
|
|
507
508
|
run.nextEligibleAt = now() + throttleWindowMs;
|
|
508
|
-
writeDriverRun(
|
|
509
|
+
await writeDriverRun(store, run);
|
|
509
510
|
},
|
|
510
511
|
});
|
|
511
512
|
}
|
|
512
513
|
catch (err) {
|
|
513
514
|
if (err instanceof DriverMintFailure) {
|
|
514
|
-
announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} FAILED before any write: ${extensionWords(err.detail, 300)}`]);
|
|
515
|
+
await announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} FAILED before any write: ${extensionWords(err.detail, 300)}`]);
|
|
515
516
|
return settle("driver_failed", undefined, err.detail);
|
|
516
517
|
}
|
|
517
518
|
if (err instanceof DriverPurityViolation) {
|
|
518
|
-
announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} REFUSED on the clean-arm purity gate (no writes): ${extensionWords(err.detail, 300)}`]);
|
|
519
|
+
await announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} REFUSED on the clean-arm purity gate (no writes): ${extensionWords(err.detail, 300)}`]);
|
|
519
520
|
return settle("purity_violation", undefined, err.detail);
|
|
520
521
|
}
|
|
521
522
|
if (err instanceof MintInvalidated) {
|
|
522
|
-
announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} MINT INVALIDATED: ${extensionWords(err.detail, 300)}`]);
|
|
523
|
+
await announce([`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)} MINT INVALIDATED: ${extensionWords(err.detail, 300)}`]);
|
|
523
524
|
if (run.residue === undefined && err.residue.length > 0)
|
|
524
525
|
run.residue = err.residue;
|
|
525
526
|
const partial = {
|
|
@@ -546,10 +547,10 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
546
547
|
return settle("driver_failed", drive, `the drive reached a fixpoint but the account does not balance: ${plannedMembers} planned member(s), ${supersededAttested} superseded attested for this run (row account ${rowAccount}, store delta ${run.foldBaseline !== undefined ? storeAccount : "unavailable — the row predates the store anchor"}), ${residueTargets} in named residue — ${plannedMembers - accounted} member(s) left the candidate set without a fold the store attests (deleted or excluded mid-run${run.foldBaseline !== undefined ? "" : ", or folded in a window whose account write did not survive"}); their entries stand (or revive with their exclusion), and a fresh run re-mints over the current library`);
|
|
547
548
|
}
|
|
548
549
|
if (plannedIds.length > 0) {
|
|
549
|
-
const evidence = collectRunFoldEvidence(engine, scope, run.requestId);
|
|
550
|
+
const evidence = await collectRunFoldEvidence(engine, scope, run.requestId);
|
|
550
551
|
if (evidence.skipped.length > 0) {
|
|
551
552
|
const named = evidence.skipped.slice(0, 5).map((s) => `${s.planId} (${s.state})`).join(", ");
|
|
552
|
-
announce([
|
|
553
|
+
await announce([
|
|
553
554
|
`memory consolidation conservation wall for scope ${inlineUntrusted(scope, 80)}: ${evidence.skipped.length} same-scope plan file(s) answered unreadable and were SKIPPED as foreign to run ${run.runId} — they attest nothing for this run and need out-of-band repair: ${named}${evidence.skipped.length > 5 ? ", …" : ""}`,
|
|
554
555
|
]);
|
|
555
556
|
}
|
|
@@ -573,9 +574,9 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
573
574
|
run.residue = [...(drive.stop?.fuseBlocked ?? []), ...driverResidue];
|
|
574
575
|
const plannedAtStop = (run.planCache?.products ?? []).some((p) => (p.inputIds?.length ?? 0) > 0);
|
|
575
576
|
if (plannedAtStop) {
|
|
576
|
-
const evidence = collectRunFoldEvidence(engine, scope, run.requestId);
|
|
577
|
+
const evidence = await collectRunFoldEvidence(engine, scope, run.requestId);
|
|
577
578
|
if (evidence.unreadable !== undefined) {
|
|
578
|
-
announce([
|
|
579
|
+
await announce([
|
|
579
580
|
`memory consolidation driver run ${run.runId} for scope ${inlineUntrusted(scope, 80)}: plan ${evidence.unreadable} — one of THIS run's own cycles — answered ${evidence.unreadableState} (control-plane damage on run-owned evidence, not a transient race); the run stops non-converged with the damage disclosed, and a fresh run re-mints over the current bytes`,
|
|
580
581
|
]);
|
|
581
582
|
}
|
|
@@ -589,16 +590,16 @@ export async function runMemoryConsolidationDriver(engine, scope, opts) {
|
|
|
589
590
|
return settle("parked", drive, stop.reason);
|
|
590
591
|
return settle("refused", drive, stop?.reason ?? "the drive stopped without a stated reason");
|
|
591
592
|
}
|
|
592
|
-
function collectRunFoldEvidence(engine, scope, requestId) {
|
|
593
|
+
async function collectRunFoldEvidence(engine, scope, requestId) {
|
|
593
594
|
const cycleId = new RegExp(`^${requestId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}-c\\d+$`);
|
|
594
595
|
const targets = new Set();
|
|
595
596
|
const skipped = [];
|
|
596
|
-
for (const summary of engine.listConsolidationPlans()) {
|
|
597
|
+
for (const summary of await engine.listConsolidationPlans()) {
|
|
597
598
|
if (summary.corrupt === true)
|
|
598
599
|
continue;
|
|
599
600
|
if (summary.scope !== scope)
|
|
600
601
|
continue;
|
|
601
|
-
const ev = engine.readConsolidationPlanFoldEvidence(summary.planId);
|
|
602
|
+
const ev = await engine.readConsolidationPlanFoldEvidence(summary.planId);
|
|
602
603
|
if (ev.state !== "ok") {
|
|
603
604
|
if (ev.state === "corrupt" && ev.requestId !== undefined && cycleId.test(ev.requestId)) {
|
|
604
605
|
return { targets, unreadable: summary.planId, unreadableState: ev.state, skipped };
|
|
@@ -615,19 +616,19 @@ function collectRunFoldEvidence(engine, scope, requestId) {
|
|
|
615
616
|
}
|
|
616
617
|
async function recoverSeat(engine, scope, { sleep, windowMs, writeGate }) {
|
|
617
618
|
await engine.reconcileConsolidation(scope, { writeGate });
|
|
618
|
-
let seat = engine.readConsolidationGate(scope)?.openPlanId;
|
|
619
|
+
let seat = (await engine.readConsolidationGate(scope))?.openPlanId;
|
|
619
620
|
if (seat === undefined)
|
|
620
621
|
return undefined;
|
|
621
|
-
const summary = engine.listConsolidationPlans().find((p) => p.planId === seat);
|
|
622
|
+
const summary = (await engine.listConsolidationPlans()).find((p) => p.planId === seat);
|
|
622
623
|
if (summary?.corrupt === true || summary?.state === "conflict") {
|
|
623
624
|
return `plan ${seat} holds the ${JSON.stringify(scope)} seat in a ${summary.corrupt === true ? "corrupt" : "conflict"} state — resolveConsolidationPlan(planId, "retry" | "discard") is the host valve; the run parks rather than stacking a second plan on the seat`;
|
|
624
625
|
}
|
|
625
626
|
await sleep(windowMs);
|
|
626
627
|
await engine.reconcileConsolidation(scope, { writeGate });
|
|
627
|
-
seat = engine.readConsolidationGate(scope)?.openPlanId;
|
|
628
|
+
seat = (await engine.readConsolidationGate(scope))?.openPlanId;
|
|
628
629
|
if (seat === undefined)
|
|
629
630
|
return undefined;
|
|
630
|
-
const again = engine.listConsolidationPlans().find((p) => p.planId === seat);
|
|
631
|
+
const again = (await engine.listConsolidationPlans()).find((p) => p.planId === seat);
|
|
631
632
|
if (again?.corrupt === true || again?.state === "conflict") {
|
|
632
633
|
return `plan ${seat} holds the ${JSON.stringify(scope)} seat in a ${again.corrupt === true ? "corrupt" : "conflict"} state — resolveConsolidationPlan(planId, "retry" | "discard") is the host valve; the run parks rather than stacking a second plan on the seat`;
|
|
633
634
|
}
|
|
@@ -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,47 @@ 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), each governance document in its own file ({@link fileGovernanceDocOf}) and each control object
|
|
564
|
+
* in its kind's directory (`control-objects.ts`). The File backend carries it over its own control plane; an engine
|
|
565
|
+
* whose backend carries no store keeps its state with this over the replica's control plane.
|
|
566
|
+
*/
|
|
567
|
+
export declare function fileGovernanceStore(controlDir: string): MemoryGovernanceStore;
|
|
504
568
|
/** Derive a product's slug from its proposed name (memory filename charset; collisions are the
|
|
505
569
|
* backend's deterministic -n suffix). */
|
|
506
570
|
export declare function deriveProductSlug(name: string | undefined, fallback: string): string;
|