@sema-agent/core 7.64.0 → 7.66.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 +571 -0
- package/dist/agents/delegation-registry-seat.d.ts +15 -0
- package/dist/agents/delegation-registry-seat.js +13 -0
- package/dist/agents/org-delivery-gate.d.ts +8 -1
- package/dist/agents/org-delivery-gate.js +9 -3
- package/dist/agents/peer-held-queue.js +1 -1
- package/dist/agents/peer-idle.js +1 -1
- package/dist/agents/peer-session-drain.d.ts +51 -12
- package/dist/agents/peer-session-drain.js +47 -34
- package/dist/agents/read-inbox-tool.d.ts +6 -2
- package/dist/agents/read-inbox-tool.js +18 -5
- package/dist/agents/subagent.d.ts +3 -1
- package/dist/agents/subagent.js +84 -77
- package/dist/brain/reasoning.d.ts +2 -0
- package/dist/brain/reasoning.js +1 -0
- package/dist/core/allow-entry.d.ts +9 -0
- package/dist/core/allow-entry.js +7 -1
- package/dist/core/ask-origin.d.ts +23 -3
- package/dist/core/ask-origin.js +11 -1
- package/dist/core/auto-promote.d.ts +3 -2
- package/dist/core/background-agent-store.d.ts +7 -0
- package/dist/core/checkpoint-store.d.ts +2 -3
- package/dist/core/context-settings.d.ts +1 -2
- package/dist/core/context-settings.js +1 -1
- package/dist/core/engine-attestation.d.ts +2 -2
- package/dist/core/engine-notice.d.ts +13 -1
- package/dist/core/engine-notice.js +3 -1
- package/dist/core/file-history-store.d.ts +2 -2
- package/dist/core/file-history-store.js +0 -4
- package/dist/core/gate-fold.js +3 -1
- package/dist/core/governance-codes.d.ts +6 -4
- package/dist/core/governance-codes.js +5 -3
- package/dist/core/human-input-projection.d.ts +9 -0
- package/dist/core/human-input-projection.js +13 -0
- package/dist/core/input-author.d.ts +66 -6
- package/dist/core/input-author.js +21 -3
- package/dist/core/leg-identity.d.ts +18 -2
- package/dist/core/leg-identity.js +5 -7
- package/dist/core/mailbox-store.d.ts +1 -1
- package/dist/core/memory-engine/consolidation.d.ts +30 -10
- package/dist/core/memory-engine/consolidation.js +41 -6
- package/dist/core/memory-engine/control-objects.d.ts +36 -3
- package/dist/core/memory-engine/control-objects.js +134 -12
- package/dist/core/memory-engine/control-plane-adoption.d.ts +13 -9
- package/dist/core/memory-engine/control-plane-adoption.js +58 -31
- package/dist/core/memory-engine/delegation-settlement.d.ts +75 -52
- package/dist/core/memory-engine/delegation-settlement.js +211 -228
- package/dist/core/memory-engine/dual-root.d.ts +3 -2
- package/dist/core/memory-engine/dual-root.js +5 -1
- package/dist/core/memory-engine/engine.d.ts +33 -16
- package/dist/core/memory-engine/engine.js +213 -177
- package/dist/core/memory-engine/file-backend.d.ts +21 -12
- package/dist/core/memory-engine/file-backend.js +58 -104
- package/dist/core/memory-engine/index.d.ts +2 -2
- package/dist/core/memory-engine/index.js +2 -2
- package/dist/core/memory-engine/layout.d.ts +184 -83
- package/dist/core/memory-engine/layout.js +267 -172
- package/dist/core/memory-engine/memory-age.d.ts +12 -0
- package/dist/core/memory-engine/memory-age.js +17 -0
- package/dist/core/memory-engine/memory-backend-contract.js +12 -11
- package/dist/core/memory-engine/memory-deployment.d.ts +4 -3
- package/dist/core/memory-engine/memory-deployment.js +6 -3
- package/dist/core/memory-engine/origin-clearance.d.ts +43 -15
- package/dist/core/memory-engine/origin-clearance.js +142 -58
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.js +7 -7
- package/dist/core/memory-engine/types.d.ts +16 -10
- package/dist/core/memory-vector.d.ts +6 -14
- package/dist/core/memory.d.ts +0 -462
- package/dist/core/memory.js +0 -333
- package/dist/core/model-receipt.d.ts +2 -1
- package/dist/core/model-receipt.js +5 -0
- package/dist/core/mods/dollar.d.ts +12 -0
- package/dist/core/mods/kernel/dispatch.d.ts +3 -1
- package/dist/core/mods/kernel/dispatch.js +5 -2
- package/dist/core/mods/kernel/events.d.ts +3 -1
- package/dist/core/mods/kernel/events.js +2 -2
- package/dist/core/mods/prompt-submit.d.ts +4 -0
- package/dist/core/mods/prompt-submit.js +24 -0
- package/dist/core/mods/stations.d.ts +23 -4
- package/dist/core/mods/stations.js +14 -7
- package/dist/core/permission-rule-consent.d.ts +49 -18
- package/dist/core/permission-rule-consent.js +59 -38
- package/dist/core/permission-rule-store.d.ts +24 -14
- package/dist/core/retention.d.ts +2 -7
- package/dist/core/retention.js +0 -1
- package/dist/core/retired-host-table-account.d.ts +19 -0
- package/dist/core/retired-host-table-account.js +28 -0
- package/dist/core/retired-tool-name-account.d.ts +60 -0
- package/dist/core/retired-tool-name-account.js +32 -0
- package/dist/core/roles.d.ts +3 -1
- package/dist/core/roles.js +5 -2
- package/dist/core/runner/classifier-ladder.d.ts +3 -1
- package/dist/core/runner/classifier-ladder.js +2 -2
- package/dist/core/runner/compact-session.js +2 -1
- package/dist/core/runner/contracts.d.ts +9 -9
- package/dist/core/runner/delegation-owner.d.ts +0 -8
- package/dist/core/runner/delegation-owner.js +1 -3
- package/dist/core/runner/gate-exit.js +9 -2
- package/dist/core/runner/memory-consolidation-driver.js +2 -2
- package/dist/core/runner/prepare-config-doors.js +1 -1
- package/dist/core/runner/prepare-delegation-surface.d.ts +1 -1
- package/dist/core/runner/prepare-delegation-surface.js +5 -3
- package/dist/core/runner/prepare-gate-stations.d.ts +8 -5
- package/dist/core/runner/prepare-gate-stations.js +13 -5
- package/dist/core/runner/prepare-inherited-gate.js +2 -0
- package/dist/core/runner/prepare-memory-engine-session.js +1 -1
- package/dist/core/runner/prepare-memory.js +35 -14
- package/dist/core/runner/prepare-policy-chain.js +12 -3
- package/dist/core/runner/prepare-project-context.js +2 -2
- package/dist/core/runner/prepare-task.d.ts +9 -1
- package/dist/core/runner/prepare-task.js +6 -5
- package/dist/core/runner/prepare-wiring-manifest.js +5 -4
- package/dist/core/runner/prompt-suggestions.js +1 -1
- package/dist/core/runner/run-identity-wiring.js +2 -2
- package/dist/core/runner/run-leg.js +3 -3
- package/dist/core/runner/run-notification-lane.d.ts +3 -0
- package/dist/core/runner/run-notification-lane.js +2 -2
- package/dist/core/runner/runtask.js +6 -3
- package/dist/core/runner/steer-admission.d.ts +11 -2
- package/dist/core/runner/stream-steer-verb.d.ts +5 -2
- package/dist/core/runner/stream-steer-verb.js +67 -14
- package/dist/core/runner/sub-agent-deny-lists.d.ts +8 -8
- package/dist/core/runner/sub-agent-deny-lists.js +22 -8
- package/dist/core/runner-deps.d.ts +4 -4
- package/dist/core/secret-env.d.ts +2 -2
- package/dist/core/secret-env.js +6 -20
- package/dist/core/session-store.d.ts +6 -6
- package/dist/core/session-store.js +3 -3
- package/dist/core/shell-run-candidates.js +3 -3
- package/dist/core/side-query.js +1 -1
- package/dist/core/skill-grant.d.ts +7 -0
- package/dist/core/skill-grant.js +14 -5
- package/dist/core/store-contracts/background-agent-store-contract.js +13 -0
- package/dist/core/task-event.d.ts +14 -0
- package/dist/core/task-notification.d.ts +35 -8
- package/dist/core/task-notification.js +31 -13
- package/dist/core/task-registry-agent.js +1 -0
- package/dist/core/task-registry-shared.d.ts +4 -0
- package/dist/core/tool-errors.d.ts +3 -3
- package/dist/core/tool-policy.js +2 -3
- package/dist/core/tool-spec.d.ts +20 -10
- package/dist/core/user-attachment.d.ts +5 -1
- package/dist/core/user-attachment.js +11 -5
- package/dist/core/write-protect.d.ts +16 -0
- package/dist/core/write-protect.js +10 -0
- package/dist/engine/harness/agent-harness.d.ts +19 -11
- package/dist/engine/harness/agent-harness.js +7 -4
- package/dist/engine/llm/types.d.ts +22 -10
- package/dist/engine/session/repo-utils.d.ts +14 -4
- package/dist/engine/session/repo-utils.js +5 -4
- package/dist/index.d.ts +10 -8
- package/dist/index.js +9 -7
- package/dist/prompts/default.d.ts +1 -2
- package/dist/scenarios/full-body.d.ts +1 -1
- package/dist/shell/lex.d.ts +50 -15
- package/dist/shell/lex.js +43 -9
- package/dist/stores/file/adoption/adopt.d.ts +1 -1
- package/dist/stores/file/index.d.ts +1 -15
- package/dist/stores/file/index.js +1 -15
- package/dist/stores/file/permission-rule-store.d.ts +12 -1
- package/dist/stores/file/permission-rule-store.js +31 -4
- package/dist/stores/file/session-store.js +1 -1
- package/dist/tools/fs/fs-bash.js +3 -3
- package/dist/tools/fs/removal-targets.d.ts +8 -2
- package/dist/tools/fs/removal-targets.js +31 -4
- package/dist/tools/fs/shell-read-argv.js +7 -1
- package/dist/tools/fs/shell-read-bindings.d.ts +21 -5
- package/dist/tools/fs/shell-read-bindings.js +130 -44
- package/dist/tools/fs/shell-read-plan.js +95 -29
- package/dist/tools/fs/shell-read-sourced.d.ts +25 -0
- package/dist/tools/fs/shell-read-sourced.js +119 -0
- package/dist/tools/fs/shell-read-word.d.ts +2 -2
- package/dist/tools/fs/shell-read-word.js +4 -5
- package/dist/tools/fs/shell-read-workdir.d.ts +19 -3
- package/dist/tools/fs/shell-read-workdir.js +60 -15
- package/dist/tools/fs/shell-reentry-text.d.ts +10 -2
- package/dist/tools/fs/shell-reentry-text.js +11 -4
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +21 -79
- package/wire-changes/core-stores-sql@7.65.0.json +30 -0
- package/wire-changes/core-stores-sql@7.66.0.json +30 -0
- package/wire-changes/core@7.65.0.json +1650 -0
- package/wire-changes/core@7.66.0.json +1218 -0
- package/wire-changes/mods-kernel@7.65.0.json +30 -0
- package/wire-changes/mods-kernel@7.66.0.json +65 -0
- package/wire-changes/primitives@7.65.0.json +337 -0
- package/wire-changes/primitives@7.66.0.json +30 -0
- package/dist/core/memory-recall.d.ts +0 -208
- package/dist/core/memory-recall.js +0 -136
- package/dist/stores/file/memory-store.d.ts +0 -124
- package/dist/stores/file/memory-store.js +0 -353
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const ONE_DAY_MS = 24 * 60 * 60 * 1_000;
|
|
2
|
+
const ONE_WEEK_MS = 7 * ONE_DAY_MS;
|
|
3
|
+
const ONE_MONTH_MS = 30.44 * ONE_DAY_MS;
|
|
4
|
+
export function formatMemoryAge(ageMs) {
|
|
5
|
+
if (ageMs < ONE_DAY_MS)
|
|
6
|
+
return "today";
|
|
7
|
+
if (ageMs < 2 * ONE_DAY_MS)
|
|
8
|
+
return "yesterday";
|
|
9
|
+
if (ageMs < ONE_WEEK_MS)
|
|
10
|
+
return `${Math.floor(ageMs / ONE_DAY_MS)} days ago`;
|
|
11
|
+
if (ageMs < ONE_MONTH_MS) {
|
|
12
|
+
const weeks = Math.floor(ageMs / ONE_WEEK_MS);
|
|
13
|
+
return `${weeks} ${weeks === 1 ? "week" : "weeks"} ago`;
|
|
14
|
+
}
|
|
15
|
+
const months = Math.floor(ageMs / ONE_MONTH_MS);
|
|
16
|
+
return `${months} ${months === 1 ? "month" : "months"} ago`;
|
|
17
|
+
}
|
|
@@ -805,7 +805,7 @@ export async function memoryBackendContract(hooks) {
|
|
|
805
805
|
await b.applyPatches([{ op: "add", id: e.id, entry: e }]);
|
|
806
806
|
const att = await erase.call(b, { requestId: "req-contract-1", select: { ids: [e.id, "id-ghost-8888"] } });
|
|
807
807
|
assert.strictEqual(att.v, 2, "the attestation rides the v:2 envelope");
|
|
808
|
-
for (const cls of ["projection", "shadow", "indexLine", "quarantineCopy", "planArchive", "planWorkbook", "evidenceBinding", "backendDerived"]) {
|
|
808
|
+
for (const cls of ["projection", "shadow", "indexLine", "quarantineCopy", "clearanceCustody", "planArchive", "planWorkbook", "evidenceBinding", "backendDerived"]) {
|
|
809
809
|
const answer = att.residuals.carriers[cls];
|
|
810
810
|
assert.ok(answer !== undefined && (answer.unverified === true || (typeof answer.removed === "number" && typeof answer.remaining === "number")), `carrier class ${cls} is answered (removed/remaining counts, or unverified)`);
|
|
811
811
|
}
|
|
@@ -1203,11 +1203,12 @@ export async function memoryGovernanceStoreContract(hooks) {
|
|
|
1203
1203
|
assert.strictEqual(await s.deleteObject(kind, "obj-1.json"), false, `${kind}: nothing to delete`);
|
|
1204
1204
|
}
|
|
1205
1205
|
});
|
|
1206
|
-
defer("an object is written once: a second put of the
|
|
1206
|
+
defer("an object is written once: a second put of the same bytes answers existed, a second put of other bytes is refused, and neither changes anything", async () => {
|
|
1207
1207
|
const s = await hooks.make();
|
|
1208
1208
|
for (const kind of MEMORY_CONTROL_OBJECT_KINDS) {
|
|
1209
1209
|
assert.strictEqual(await s.putObject(kind, "once.json", enc(`first ${kind}`), { scope: "s1" }), "created", `${kind}: the first put creates`);
|
|
1210
|
-
assert.strictEqual(await s.putObject(kind, "once.json", enc(`
|
|
1210
|
+
assert.strictEqual(await s.putObject(kind, "once.json", enc(`first ${kind}`)), "existed", `${kind}: the same bytes find it`);
|
|
1211
|
+
await rejectsCoded(s.putObject(kind, "once.json", enc(`second ${kind}`)), /ControlPlaneCorruptError|corrupt/i, `${kind}: other bytes over a standing name`);
|
|
1211
1212
|
assert.ok(same(await s.getObject(kind, "once.json"), enc(`first ${kind}`)), `${kind}: the first bytes stand`);
|
|
1212
1213
|
}
|
|
1213
1214
|
});
|
|
@@ -1259,7 +1260,7 @@ export async function memoryGovernanceStoreContract(hooks) {
|
|
|
1259
1260
|
const s = await hooks.make();
|
|
1260
1261
|
await rejectsCoded(s.putObject("ledger", "a.json", enc("x")), "memory.control_object_unknown", "an unknown kind");
|
|
1261
1262
|
await rejectsCoded(s.listObjects("__proto__"), "memory.control_object_unknown", "a prototype key as a kind");
|
|
1262
|
-
for (const name of ["", ".", "..", "a/b", "../x", "a\\b", "a\u0000b"]) {
|
|
1263
|
+
for (const name of ["", ".", "..", "a/b", "../x", "a\\b", "a\u0000b", "n".repeat(256), "中".repeat(86)]) {
|
|
1263
1264
|
await rejectsCoded(s.putObject("pollution", name, enc("x")), "memory.control_object_unknown", `put of the name ${JSON.stringify(name)}`);
|
|
1264
1265
|
await rejectsCoded(s.getObject("pollution", name), "memory.control_object_unknown", `get of the name ${JSON.stringify(name)}`);
|
|
1265
1266
|
}
|
|
@@ -1270,7 +1271,7 @@ export async function memoryGovernanceStoreContract(hooks) {
|
|
|
1270
1271
|
await s.putObject("pollution", "kept.json", enc("marker"));
|
|
1271
1272
|
await hooks.corrupt(s, { object: "pollution", name: "standing.json" });
|
|
1272
1273
|
await rejectsCoded(s.getObject("pollution", "standing.json"), /ControlPlaneCorruptError|corrupt/i, "an unreadable object");
|
|
1273
|
-
|
|
1274
|
+
await rejectsCoded(s.putObject("pollution", "standing.json", enc("over it")), /ControlPlaneCorruptError|corrupt/i, "an unreadable object still stands: a put neither overwrites it nor answers for bytes it could not compare");
|
|
1274
1275
|
await hooks.corrupt(s, { listing: "quarantine" });
|
|
1275
1276
|
await rejectsCoded(s.listObjects("quarantine"), /ControlPlaneCorruptError|corrupt/i, "an enumeration that fails");
|
|
1276
1277
|
});
|
|
@@ -1283,7 +1284,7 @@ export async function memoryGovernanceStoreContract(hooks) {
|
|
|
1283
1284
|
rmSync(replica, { recursive: true, force: true });
|
|
1284
1285
|
}
|
|
1285
1286
|
};
|
|
1286
|
-
defer("adoption: what the store lacks is written, what it holds the same converges, and the replica
|
|
1287
|
+
defer("adoption: what the store lacks is written, what it holds the same converges, and a pass that refused nothing removes the replica's copies beside a body-less receipt", async () => {
|
|
1287
1288
|
const s = await hooks.make();
|
|
1288
1289
|
await withReplica(async (replica, file) => {
|
|
1289
1290
|
await file.updateDoc("holds", judgeDoc, () => ({ next: { v: 1, owner: "replica", n: 1 }, result: undefined }));
|
|
@@ -1295,7 +1296,7 @@ export async function memoryGovernanceStoreContract(hooks) {
|
|
|
1295
1296
|
assert.deepStrictEqual(report.adopted.map((r) => `${r.record}:${r.outcome}`).sort(), ["doc:holds:written", "hold/cap.md:written", "pollution/s1.json:converged"]);
|
|
1296
1297
|
assert.deepStrictEqual(await s.readDoc("holds"), { v: 1, owner: "replica", n: 1 });
|
|
1297
1298
|
assert.ok(same(await s.getObject("hold", "cap.md"), enc("captured")));
|
|
1298
|
-
assert.deepStrictEqual(replicaControlPlaneStrays(replica), { docs: [
|
|
1299
|
+
assert.deepStrictEqual(replicaControlPlaneStrays(replica), { docs: [], objects: {} }, "the engine's readers read these records in the store: the replica's copies are removed (#3484)");
|
|
1299
1300
|
assert.deepStrictEqual(readControlPlaneAdoptionReceipt(replica).map((r) => r.record).sort(), ["doc:holds", "hold/cap.md", "pollution/s1.json"]);
|
|
1300
1301
|
});
|
|
1301
1302
|
});
|
|
@@ -1318,10 +1319,10 @@ export async function memoryGovernanceStoreContract(hooks) {
|
|
|
1318
1319
|
assert.deepStrictEqual(again.adopted.map((r) => `${r.record}:${r.outcome}`).sort(), ["doc:holds:written", "quarantine/q.md:written"]);
|
|
1319
1320
|
assert.deepStrictEqual(again.refused.map((r) => r.record), ["doc:lineage"]);
|
|
1320
1321
|
assert.deepStrictEqual(await s.readDoc("lineage"), { v: 1, owner: "carrier", n: 7 }, "no merge is invented");
|
|
1321
|
-
assert.deepStrictEqual(replicaControlPlaneStrays(replica), { docs: ["lineage", "holds"], objects: { quarantine: 1 } }, "
|
|
1322
|
+
assert.deepStrictEqual(replicaControlPlaneStrays(replica), { docs: ["lineage", "holds"], objects: { quarantine: 1 } }, "a pass with a refusal removes nothing from the replica");
|
|
1322
1323
|
});
|
|
1323
1324
|
});
|
|
1324
|
-
defer("adoption: a re-run converges — an interrupted handover converges, a
|
|
1325
|
+
defer("adoption: a re-run converges — an interrupted handover converges and empties the replica, and a re-run over the emptied replica hands over nothing and writes no second receipt row", async () => {
|
|
1325
1326
|
const s = await hooks.make();
|
|
1326
1327
|
await withReplica(async (replica, file) => {
|
|
1327
1328
|
await file.putObject("capture", "s2.json", enc("opted out"));
|
|
@@ -1330,9 +1331,9 @@ export async function memoryGovernanceStoreContract(hooks) {
|
|
|
1330
1331
|
const first = await adoptReplicaControlPlane(replica, s);
|
|
1331
1332
|
assert.deepStrictEqual(first.refused, []);
|
|
1332
1333
|
assert.deepStrictEqual(first.adopted.map((r) => `${r.record}:${r.outcome}`).sort(), ["capture/s2.json:converged", "doc:challenges:written"]);
|
|
1334
|
+
assert.deepStrictEqual(replicaControlPlaneStrays(replica), { docs: [], objects: {} }, "the finished handover leaves the replica empty");
|
|
1333
1335
|
const again = await adoptReplicaControlPlane(replica, s);
|
|
1334
|
-
assert.deepStrictEqual(again
|
|
1335
|
-
assert.deepStrictEqual(again.adopted.map((r) => `${r.record}:${r.outcome}`).sort(), ["capture/s2.json:converged", "doc:challenges:converged"], "a finished adoption converges again");
|
|
1336
|
+
assert.deepStrictEqual(again, { adopted: [], refused: [] }, "a finished adoption has nothing left to hand over");
|
|
1336
1337
|
assert.deepStrictEqual(readControlPlaneAdoptionReceipt(replica).map((r) => r.record).sort(), ["capture/s2.json", "doc:challenges"], "one receipt row per record");
|
|
1337
1338
|
assert.deepStrictEqual(await s.readDoc("challenges"), { v: 1, owner: "replica", n: 2 });
|
|
1338
1339
|
});
|
|
@@ -11,7 +11,7 @@ export interface MemoryDeploymentInput {
|
|
|
11
11
|
* there, and a backend without one keeps them in per-project control planes no deployment-wide reading can name —
|
|
12
12
|
* refused (`config.memory_scope_key`). This is the deployment's own question, not consolidation's
|
|
13
13
|
* (`memoryGovernanceDurability`). A backend that carries only `governance` stays refused here: its session accounts
|
|
14
|
-
* ride its store, its scope registry
|
|
14
|
+
* and capture records ride its store (#3484), its scope registry does not. */
|
|
15
15
|
backend: MemoryBackend;
|
|
16
16
|
/** The value given as `RunnerDeps.memoryEngineDir` — a required key, judged as `resolveMemoryScopeStore`
|
|
17
17
|
* judges it (`undefined` written out reads the Runner's same fallback). */
|
|
@@ -69,14 +69,15 @@ export interface MemoryDeployment {
|
|
|
69
69
|
* set exactly when its mount holds a record: a file under `<engine root>/personal/.engine` or
|
|
70
70
|
* `<engine root>/personal/memory` other than the named artifacts an open or a read leaves, matched at that place
|
|
71
71
|
* and by that name only (`*` = any rest of the name): control plane top level, files `root-anchor.json` ·
|
|
72
|
-
* `scopes.json` · `scopes.json.journal` · `.tmp-*`; control plane top level, directories as whole trees
|
|
72
|
+
* `scopes.json` · `scopes.json.journal` · `.tmp-*` · `.link-probe-*`; control plane top level, directories as whole trees
|
|
73
73
|
* `root-anchor.json.lock` · `scopes.json.lock` · `txn.lock` · `root-anchor.json.lock.stale-*` ·
|
|
74
74
|
* `scopes.json.lock.stale-*` · `txn.lock.stale-*`; memory directory top level, files `.casefold-probe-*`. A
|
|
75
75
|
* directory that cannot be read, for any reason but absence (a link that leads nowhere, at it or above it, is no
|
|
76
76
|
* absence), counts as holding one, and so does an anchor, a scope registry or a registry journal that stands there
|
|
77
77
|
* damaged (a link, no regular file, unreadable, not JSON or out of shape). Opening, reading and a refused request
|
|
78
78
|
* add no store, and every deployment object over one engine root answers the same. A store in the set that cannot be
|
|
79
|
-
* opened
|
|
79
|
+
* opened — the damaged anchor, scope registry or registry journal that put it there is one such cause: the census and the
|
|
80
|
+
* open read the same fault — is not a store of the list: the call throws `ControlPlaneCorruptError` (a bare system error is carried by one
|
|
80
81
|
* that names its errno, the original as its `cause`), and the session status answers that plane
|
|
81
82
|
* `optOutSource: "fault"`.
|
|
82
83
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { MemoryEngine } from "./engine.js";
|
|
3
3
|
import { derivePersonalControlDir, derivePersonalMemoryDir, directoryPinOf, judgeMemoryStoreSeat, memoryPlaneStore, memoryScopePlaneOf, mergeErasureAttestations, refuseMemoryStoreInput } from "./dual-root.js";
|
|
4
|
-
import { acquireStoreTxnLock, assertStoreTxnLockOwnership, ControlPlaneCorruptError, renewStoreTxnLock, resolveMemoryEngineRoot, storeHoldsRecord, TXN_LOCK_STALE_MS } from "./layout.js";
|
|
4
|
+
import { acquireStoreTxnLock, assertStoreTxnLockOwnership, ControlPlaneCorruptError, renewStoreTxnLock, resolveMemoryEngineRoot, storeHoldsRecord, storeOpenArtifactFault, TXN_LOCK_STALE_MS } from "./layout.js";
|
|
5
5
|
import { captureErasureInput, erasureRequestInvalid, erasureSelectHash } from "./file-backend.js";
|
|
6
6
|
import { canonicalExpectedScopes } from "./export-bundle.js";
|
|
7
7
|
import { thrownLabel, thrownText } from "../thrown-value.js";
|
|
@@ -62,9 +62,12 @@ export function createMemoryDeployment(input) {
|
|
|
62
62
|
const project = seatOf("project", backend);
|
|
63
63
|
let personal;
|
|
64
64
|
const personalStore = () => {
|
|
65
|
-
if (personal !== undefined)
|
|
66
|
-
return personal;
|
|
67
65
|
try {
|
|
66
|
+
const fault = storeOpenArtifactFault(derivePersonalMemoryDir(engineRoot), derivePersonalControlDir(engineRoot));
|
|
67
|
+
if (fault !== undefined)
|
|
68
|
+
throw fault;
|
|
69
|
+
if (personal !== undefined)
|
|
70
|
+
return personal;
|
|
68
71
|
personal = seatOf("personal", memoryPlaneStore("personal", backend, engineRoot, onIncident));
|
|
69
72
|
}
|
|
70
73
|
catch (err) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { MemoryEntryOrigin } from "./types.js";
|
|
2
|
-
|
|
1
|
+
import type { MemoryEntryOrigin, MemoryGovernanceDocs, MemoryGovernanceObjects } from "./types.js";
|
|
2
|
+
/** The part of a governance store the account is kept through: its document and its custody objects. */
|
|
3
|
+
export type OriginClearanceStore = MemoryGovernanceDocs & Pick<MemoryGovernanceObjects, "putObject" | "getObject" | "deleteObject">;
|
|
3
4
|
/** The custody object a clearance's cleared-entry text is kept as (kind `clearance-custody`): named by the row, so the
|
|
4
5
|
* row alone finds it again. */
|
|
5
6
|
export declare function clearanceCustodyName(clearanceId: string): string;
|
|
@@ -34,8 +35,13 @@ export interface OriginClearanceRow {
|
|
|
34
35
|
* the re-record batch leaves this as the only copy — the pending row is the loud recovery seat
|
|
35
36
|
* (a later clearEntryOrigin call for the same entry resumes from it). Kept as the row's custody
|
|
36
37
|
* object ({@link clearanceCustodyName}), never inside the account: the stored row carries the
|
|
37
|
-
* text's sha-256 (`custodyDigest`) and every read answers the text, checked against it.
|
|
38
|
+
* text's sha-256 (`custodyDigest`) and every read answers the text, checked against it. `""` on a row whose
|
|
39
|
+
* custody was erased with its entry (`custodyErased`). */
|
|
38
40
|
entryText: string;
|
|
41
|
+
/** Present (`true`) ⇔ an erasure of the entry erased this clearance's custody (#3463): the text is gone from the
|
|
42
|
+
* store, `entryText` answers `""`, and the row no longer resumes (`memory.origin_clear_unknown`). The row itself —
|
|
43
|
+
* who cleared, why, when, its events — stays. ADDITIVE: absent on every row whose custody stands. */
|
|
44
|
+
custodyErased?: true;
|
|
39
45
|
/** Set the moment THIS clearance's tombstone commits ({@link markOriginClearanceTombstoned}) —
|
|
40
46
|
* the resume arm's arbiter for an absent entry: with it, absence is the known crash window
|
|
41
47
|
* (tombstone landed, re-record owed — replay from custody); without it, the absence is an
|
|
@@ -73,18 +79,19 @@ export interface OriginClearanceShadow {
|
|
|
73
79
|
requestId: string;
|
|
74
80
|
settledAt: number;
|
|
75
81
|
}
|
|
76
|
-
/** Move every custody text the account still carries inline out into its custody object
|
|
77
|
-
* writes nothing when there is none. */
|
|
78
|
-
export declare function moveOriginClearanceCustodyOut(
|
|
79
|
-
/**
|
|
80
|
-
*
|
|
81
|
-
export declare function readOriginClearances(
|
|
82
|
+
/** Move every custody text the account still carries inline out into its custody object (each object before the
|
|
83
|
+
* update that drops its text); writes nothing when there is none. */
|
|
84
|
+
export declare function moveOriginClearanceCustodyOut(store: OriginClearanceStore): Promise<void>;
|
|
85
|
+
/** Strict read of the whole account (host audit face; corrupt = throw). Each row answers its custody text, wherever the
|
|
86
|
+
* account keeps it (`""` once an erasure took it, `custodyErased`). */
|
|
87
|
+
export declare function readOriginClearances(store: Pick<MemoryGovernanceDocs, "readDoc"> & Pick<MemoryGovernanceObjects, "getObject">): Promise<OriginClearanceRow[]>;
|
|
82
88
|
/**
|
|
83
89
|
* WRITE-AHEAD open: append the pending row (custody included) before any store mutation. Refuses a
|
|
84
90
|
* second OPEN while a pending row for the same entry stands — the pending row is a resume seat,
|
|
85
|
-
* not a queue (the caller resumes it instead).
|
|
91
|
+
* not a queue (the caller resumes it instead). The custody text lands as its object before the update
|
|
92
|
+
* that appends the row naming it; a refused open removes the object it wrote (no row names it).
|
|
86
93
|
*/
|
|
87
|
-
export declare function openOriginClearance(
|
|
94
|
+
export declare function openOriginClearance(store: OriginClearanceStore, row: Omit<OriginClearanceRow, "status" | "events" | "custodyErased">): Promise<void>;
|
|
88
95
|
/**
|
|
89
96
|
* Record that THIS clearance's tombstone leg committed (called between the delete's success and
|
|
90
97
|
* the re-record attempt). The record is what lets a later resume read an ABSENT entry as "the
|
|
@@ -93,10 +100,10 @@ export declare function openOriginClearance(controlDir: string, row: Omit<Origin
|
|
|
93
100
|
* the identical committed state). Idempotent (first write wins); non-pending rows are a no-op
|
|
94
101
|
* (a settled row's history never rewrites).
|
|
95
102
|
*/
|
|
96
|
-
export declare function markOriginClearanceTombstoned(
|
|
103
|
+
export declare function markOriginClearanceTombstoned(store: OriginClearanceStore, input: {
|
|
97
104
|
clearanceId: string;
|
|
98
105
|
now: () => number;
|
|
99
|
-
}): void
|
|
106
|
+
}): Promise<void>;
|
|
100
107
|
/**
|
|
101
108
|
* Terminal event append + status flip. Unknown clearanceId is a corrupt-caller refusal.
|
|
102
109
|
*
|
|
@@ -111,7 +118,7 @@ export declare function markOriginClearanceTombstoned(controlDir: string, input:
|
|
|
111
118
|
* bytes, so the row must stay resumable (a `failed` flip would strand them: the resume arm only
|
|
112
119
|
* completes pending rows).
|
|
113
120
|
*/
|
|
114
|
-
export declare function settleOriginClearance(
|
|
121
|
+
export declare function settleOriginClearance(store: OriginClearanceStore, input: {
|
|
115
122
|
clearanceId: string;
|
|
116
123
|
to: "done" | "failed";
|
|
117
124
|
requestId: string;
|
|
@@ -119,4 +126,25 @@ export declare function settleOriginClearance(controlDir: string, input: {
|
|
|
119
126
|
now: () => number;
|
|
120
127
|
detail?: string;
|
|
121
128
|
keepPending?: boolean;
|
|
122
|
-
}): void
|
|
129
|
+
}): Promise<void>;
|
|
130
|
+
/** Whether an erasure has taken this clearance's custody (a row that is not there reads as taken: nothing stands to
|
|
131
|
+
* resume from). The re-record legs ask it right before they add the entry back from the custody they read earlier. */
|
|
132
|
+
export declare function clearanceCustodyErased(store: Pick<MemoryGovernanceDocs, "readDoc">, clearanceId: string): Promise<boolean>;
|
|
133
|
+
/** What one erasure did to the clearances' custody (the attestation's `clearanceCustody` carrier class): `removed` — the
|
|
134
|
+
* custody texts of the erased entries this call took out of the store: each row this call marked (an inline text dropped
|
|
135
|
+
* from its row; a kept text whose object is gone after this call's delete — deleted by it, or already by an update of the
|
|
136
|
+
* account that read the mark first, {@link clearanceUpdate}), and each object a replay found still standing under a row
|
|
137
|
+
* marked before and deleted; `remaining` — the ones it could not delete. */
|
|
138
|
+
export interface ClearanceCustodyErasure {
|
|
139
|
+
removed: number;
|
|
140
|
+
remaining: number;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* #3463 — erase the custody of every clearance of an erased entry (`entryIds`). The rows go first: one update marks each
|
|
144
|
+
* of them `custodyErased` at `at` (`custodyErasedAt`; an inline text and the digest are dropped with it), so from then on no read answers the text
|
|
145
|
+
* and no resume acts on it; then each one's custody object is deleted. A row already marked is left as it is (a replay
|
|
146
|
+
* converges: its object is deleted again when one still stands, and a row is never rewritten twice). The row itself —
|
|
147
|
+
* who cleared, why, when, its events, its status — stays. A failed delete is counted in `remaining`, never swallowed; a
|
|
148
|
+
* document that cannot be read or updated throws (the lane that called decides what its attestation says about that).
|
|
149
|
+
*/
|
|
150
|
+
export declare function eraseOriginClearanceCustody(store: OriginClearanceStore, entryIds: ReadonlySet<string>, at: number): Promise<ClearanceCustodyErasure>;
|
|
@@ -1,56 +1,75 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { ControlPlaneCorruptError
|
|
3
|
-
import { getFileControlObject, putFileControlObject } from "./control-objects.js";
|
|
2
|
+
import { ControlPlaneCorruptError } from "./layout.js";
|
|
4
3
|
import { MEMORY_ORIGIN_CAUSES } from "./types.js";
|
|
5
|
-
const CLEARANCES = fileGovernanceDocOf("origin-clearances");
|
|
6
|
-
export const ORIGIN_CLEARANCES_FILE = CLEARANCES.file;
|
|
7
4
|
export function clearanceCustodyName(clearanceId) {
|
|
8
5
|
return `${clearanceId}.md`;
|
|
9
6
|
}
|
|
10
7
|
function sha256Hex(bytes) {
|
|
11
8
|
return createHash("sha256").update(bytes).digest("hex");
|
|
12
9
|
}
|
|
13
|
-
function
|
|
10
|
+
async function readClearanceRecord(store) {
|
|
11
|
+
return coerceClearances(await store.readDoc("origin-clearances"));
|
|
12
|
+
}
|
|
13
|
+
async function custodyTextOf(store, row) {
|
|
14
|
+
if (row.custodyErased === true)
|
|
15
|
+
return "";
|
|
14
16
|
if (row.entryText !== undefined)
|
|
15
17
|
return row.entryText;
|
|
16
18
|
const name = clearanceCustodyName(row.clearanceId);
|
|
17
|
-
const bytes =
|
|
19
|
+
const bytes = await store.getObject("clearance-custody", name);
|
|
18
20
|
if (bytes === undefined)
|
|
19
21
|
throw new ControlPlaneCorruptError(`memory origin-clearance ledger: clearance ${JSON.stringify(row.clearanceId)} names custody ${JSON.stringify(name)} that is not there (fail-closed)`);
|
|
20
22
|
if (sha256Hex(bytes) !== row.custodyDigest)
|
|
21
23
|
throw new ControlPlaneCorruptError(`memory origin-clearance ledger: clearance ${JSON.stringify(row.clearanceId)}'s custody does not match the digest its row records (fail-closed)`);
|
|
22
24
|
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
23
25
|
}
|
|
24
|
-
function keepCustody(
|
|
26
|
+
async function keepCustody(store, clearanceId, text) {
|
|
25
27
|
const bytes = new TextEncoder().encode(text);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
await store.putObject("clearance-custody", clearanceCustodyName(clearanceId), bytes);
|
|
29
|
+
return sha256Hex(bytes);
|
|
30
|
+
}
|
|
31
|
+
async function clearanceUpdate(store, fn) {
|
|
32
|
+
const kept = new Map();
|
|
33
|
+
let seen;
|
|
34
|
+
try {
|
|
35
|
+
for (const row of (await readClearanceRecord(store)).rows) {
|
|
36
|
+
if (row.entryText !== undefined)
|
|
37
|
+
kept.set(row.clearanceId, await keepCustody(store, row.clearanceId, row.entryText));
|
|
38
|
+
}
|
|
39
|
+
return await store.updateDoc("origin-clearances", coerceClearances, (rec) => {
|
|
40
|
+
seen = [...rec.rows];
|
|
41
|
+
let moved = false;
|
|
42
|
+
for (const row of rec.rows) {
|
|
43
|
+
if (row.entryText === undefined)
|
|
44
|
+
continue;
|
|
45
|
+
const digest = kept.get(row.clearanceId);
|
|
46
|
+
if (digest === undefined || digest !== sha256Hex(new TextEncoder().encode(row.entryText)))
|
|
47
|
+
continue;
|
|
48
|
+
const r = row;
|
|
49
|
+
delete r.entryText;
|
|
50
|
+
r.custodyDigest = digest;
|
|
51
|
+
moved = true;
|
|
52
|
+
}
|
|
53
|
+
const out = fn(rec);
|
|
54
|
+
return out.next === undefined && moved ? { next: rec, result: out.result } : out;
|
|
55
|
+
});
|
|
32
56
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
57
|
+
finally {
|
|
58
|
+
const rows = seen ?? (await readClearanceRecord(store).then((rec) => rec.rows, () => undefined));
|
|
59
|
+
const deleteFailures = [];
|
|
60
|
+
for (const row of rows ?? []) {
|
|
61
|
+
if (row.custodyErased !== true)
|
|
62
|
+
continue;
|
|
63
|
+
try {
|
|
64
|
+
await store.deleteObject("clearance-custody", clearanceCustodyName(row.clearanceId));
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
deleteFailures.push(err);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (deleteFailures.length > 0)
|
|
71
|
+
throw deleteFailures[0];
|
|
45
72
|
}
|
|
46
|
-
return moved;
|
|
47
|
-
}
|
|
48
|
-
function lockedClearanceUpdate(controlDir, fn) {
|
|
49
|
-
lockedStrictUpdate(controlDir, CLEARANCES.file, CLEARANCES.what, coerceClearances, (rec) => {
|
|
50
|
-
const moved = moveInlineCustody(controlDir, rec);
|
|
51
|
-
const out = fn(rec);
|
|
52
|
-
return out.next === undefined && moved ? { next: rec, result: out.result } : out;
|
|
53
|
-
});
|
|
54
73
|
}
|
|
55
74
|
function reqStr(v) {
|
|
56
75
|
return typeof v === "string" && v.length > 0;
|
|
@@ -75,8 +94,10 @@ function coerceClearances(raw) {
|
|
|
75
94
|
if (rec.version !== 1)
|
|
76
95
|
throw new ControlPlaneCorruptError(`memory origin-clearance ledger has an unrecognized version (${String(rec.version)}) — refusing (fail-closed)`);
|
|
77
96
|
for (const r of rec.rows) {
|
|
78
|
-
const
|
|
79
|
-
const
|
|
97
|
+
const notErased = r?.custodyErased === undefined && r?.custodyErasedAt === undefined;
|
|
98
|
+
const custodyInline = typeof r?.entryText === "string" && r.entryText.length > 0 && r.custodyDigest === undefined && notErased;
|
|
99
|
+
const custodyKept = r?.entryText === undefined && typeof r?.custodyDigest === "string" && /^[0-9a-f]{64}$/.test(r.custodyDigest) && notErased;
|
|
100
|
+
const custodyGone = r?.custodyErased === true && typeof r.custodyErasedAt === "number" && Number.isFinite(r.custodyErasedAt) && r.entryText === undefined && r.custodyDigest === undefined;
|
|
80
101
|
if (typeof r !== "object" ||
|
|
81
102
|
r === null ||
|
|
82
103
|
!reqStr(r.clearanceId) ||
|
|
@@ -88,7 +109,7 @@ function coerceClearances(raw) {
|
|
|
88
109
|
!reqStr(r.reason) ||
|
|
89
110
|
typeof r.at !== "number" ||
|
|
90
111
|
!Number.isFinite(r.at) ||
|
|
91
|
-
!(custodyInline || custodyKept) ||
|
|
112
|
+
!(custodyInline || custodyKept || custodyGone) ||
|
|
92
113
|
(r.tombstonedAt !== undefined && (typeof r.tombstonedAt !== "number" || !Number.isFinite(r.tombstonedAt))) ||
|
|
93
114
|
(r.status !== "pending" && r.status !== "done" && r.status !== "failed") ||
|
|
94
115
|
!Array.isArray(r.events)) {
|
|
@@ -103,29 +124,47 @@ function coerceClearances(raw) {
|
|
|
103
124
|
}
|
|
104
125
|
return rec;
|
|
105
126
|
}
|
|
106
|
-
export function moveOriginClearanceCustodyOut(
|
|
107
|
-
|
|
127
|
+
export async function moveOriginClearanceCustodyOut(store) {
|
|
128
|
+
await clearanceUpdate(store, () => ({ result: undefined }));
|
|
108
129
|
}
|
|
109
|
-
export function readOriginClearances(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
130
|
+
export async function readOriginClearances(store) {
|
|
131
|
+
const out = [];
|
|
132
|
+
for (const r of (await readClearanceRecord(store)).rows) {
|
|
133
|
+
const { custodyDigest: _digest, entryText: _inline, custodyErased: _erased, custodyErasedAt: _erasedAt, ...row } = r;
|
|
134
|
+
out.push({ ...row, entryText: await custodyTextOf(store, r), ...(r.custodyErased === true ? { custodyErased: true } : {}), events: [...r.events] });
|
|
135
|
+
}
|
|
136
|
+
return out;
|
|
114
137
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
e.code = "memory.origin_clear_pending";
|
|
120
|
-
throw e;
|
|
121
|
-
}
|
|
122
|
-
const { entryText, ...rest } = row;
|
|
123
|
-
rec.rows.push({ ...rest, custodyDigest: keepCustody(controlDir, row.clearanceId, entryText), status: "pending", events: [] });
|
|
124
|
-
return { next: rec, result: undefined };
|
|
125
|
-
});
|
|
138
|
+
function pendingClearanceRefusal(entryId) {
|
|
139
|
+
const e = new Error(`origin clearance for entry ${JSON.stringify(entryId)} is already pending — resume it (call clearEntryOrigin again) instead of opening a second row.`);
|
|
140
|
+
e.code = "memory.origin_clear_pending";
|
|
141
|
+
return e;
|
|
126
142
|
}
|
|
127
|
-
export function
|
|
128
|
-
|
|
143
|
+
export async function openOriginClearance(store, row) {
|
|
144
|
+
const pendingFor = (rec) => rec.rows.some((r) => r.entryId === row.entryId && r.status === "pending");
|
|
145
|
+
if (pendingFor(await readClearanceRecord(store)))
|
|
146
|
+
throw pendingClearanceRefusal(row.entryId);
|
|
147
|
+
const { entryText, ...rest } = row;
|
|
148
|
+
const custodyDigest = await keepCustody(store, row.clearanceId, entryText);
|
|
149
|
+
let refusedAsPending = false;
|
|
150
|
+
try {
|
|
151
|
+
await clearanceUpdate(store, (rec) => {
|
|
152
|
+
if (pendingFor(rec)) {
|
|
153
|
+
refusedAsPending = true;
|
|
154
|
+
throw pendingClearanceRefusal(row.entryId);
|
|
155
|
+
}
|
|
156
|
+
rec.rows.push({ ...rest, custodyDigest, status: "pending", events: [] });
|
|
157
|
+
return { next: rec, result: undefined };
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
if (refusedAsPending)
|
|
162
|
+
await Promise.resolve(store.deleteObject("clearance-custody", clearanceCustodyName(row.clearanceId))).catch(() => undefined);
|
|
163
|
+
throw err;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
export async function markOriginClearanceTombstoned(store, input) {
|
|
167
|
+
await clearanceUpdate(store, (rec) => {
|
|
129
168
|
const r = rec.rows.find((x) => x.clearanceId === input.clearanceId);
|
|
130
169
|
if (r === undefined || r.status !== "pending" || r.tombstonedAt !== undefined)
|
|
131
170
|
return { result: undefined };
|
|
@@ -133,8 +172,8 @@ export function markOriginClearanceTombstoned(controlDir, input) {
|
|
|
133
172
|
return { next: rec, result: undefined };
|
|
134
173
|
});
|
|
135
174
|
}
|
|
136
|
-
export function settleOriginClearance(
|
|
137
|
-
|
|
175
|
+
export async function settleOriginClearance(store, input) {
|
|
176
|
+
await clearanceUpdate(store, (rec) => {
|
|
138
177
|
const r = rec.rows.find((x) => x.clearanceId === input.clearanceId);
|
|
139
178
|
if (r === undefined) {
|
|
140
179
|
const e = new Error(`origin clearance ${JSON.stringify(input.clearanceId)} is unknown`);
|
|
@@ -151,3 +190,48 @@ export function settleOriginClearance(controlDir, input) {
|
|
|
151
190
|
return { next: rec, result: undefined };
|
|
152
191
|
});
|
|
153
192
|
}
|
|
193
|
+
export async function clearanceCustodyErased(store, clearanceId) {
|
|
194
|
+
const row = (await readClearanceRecord(store)).rows.find((r) => r.clearanceId === clearanceId);
|
|
195
|
+
return row === undefined || row.custodyErased === true;
|
|
196
|
+
}
|
|
197
|
+
export async function eraseOriginClearanceCustody(store, entryIds, at) {
|
|
198
|
+
if (entryIds.size === 0 || !(await readClearanceRecord(store)).rows.some((r) => entryIds.has(r.entryId)))
|
|
199
|
+
return { removed: 0, remaining: 0 };
|
|
200
|
+
const marked = await store.updateDoc("origin-clearances", coerceClearances, (rec) => {
|
|
201
|
+
const objects = [];
|
|
202
|
+
let inline = 0;
|
|
203
|
+
let changed = false;
|
|
204
|
+
for (const row of rec.rows) {
|
|
205
|
+
if (!entryIds.has(row.entryId))
|
|
206
|
+
continue;
|
|
207
|
+
if (row.custodyErased === true) {
|
|
208
|
+
objects.push({ clearanceId: row.clearanceId, take: "leftover" });
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (row.entryText !== undefined)
|
|
212
|
+
inline++;
|
|
213
|
+
objects.push({ clearanceId: row.clearanceId, take: row.entryText !== undefined ? "inline" : "kept" });
|
|
214
|
+
const r = row;
|
|
215
|
+
delete r.entryText;
|
|
216
|
+
delete r.custodyDigest;
|
|
217
|
+
r.custodyErased = true;
|
|
218
|
+
r.custodyErasedAt = at;
|
|
219
|
+
changed = true;
|
|
220
|
+
}
|
|
221
|
+
return changed ? { next: rec, result: { objects, inline } } : { result: { objects, inline } };
|
|
222
|
+
});
|
|
223
|
+
const out = { removed: marked.inline, remaining: 0 };
|
|
224
|
+
for (const { clearanceId, take } of marked.objects) {
|
|
225
|
+
try {
|
|
226
|
+
const deleted = await store.deleteObject("clearance-custody", clearanceCustodyName(clearanceId));
|
|
227
|
+
if (deleted !== true && deleted !== false)
|
|
228
|
+
out.remaining++;
|
|
229
|
+
else if (take === "kept" || (take === "leftover" && deleted === true))
|
|
230
|
+
out.removed++;
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
out.remaining++;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return out;
|
|
237
|
+
}
|
|
@@ -125,9 +125,9 @@ export interface MemoryEngineToolsOptions {
|
|
|
125
125
|
* Absent ⇒ no pollution face is wired (engine-direct hosts, tests): the empty-outcome wording is
|
|
126
126
|
* then exactly the clean-session wording — nothing is inferred from the seat's absence.
|
|
127
127
|
*/
|
|
128
|
-
sessionPollution?: () => {
|
|
128
|
+
sessionPollution?: () => Promise<{
|
|
129
129
|
reason: string;
|
|
130
|
-
} | undefined
|
|
130
|
+
} | undefined>;
|
|
131
131
|
/**
|
|
132
132
|
* design/336 §13-3 — the provenance mode the write engine runs under. Two consumers here:
|
|
133
133
|
* - the pollution sentence states what the mark actually DOES (under `"carry"` writes commit
|
|
@@ -2,7 +2,7 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { Type } from "typebox";
|
|
3
3
|
import { errorResult } from "../tools.js";
|
|
4
4
|
import { defuseFenceMarkers, delimitUntrusted, FENCED_LANE_ENVELOPE_TAGS, inlineUntrusted, sanitizeUntrustedText } from "../untrusted-text.js";
|
|
5
|
-
import { formatMemoryAge } from "
|
|
5
|
+
import { formatMemoryAge } from "./memory-age.js";
|
|
6
6
|
import { committedOriginOf } from "./frontmatter.js";
|
|
7
7
|
import { MEMORY_EXPOSURE_BANNER, MEMORY_EXPOSURE_HANDLE_TAG, MEMORY_PROVENANCE_INDEX_SENTENCE, MEMORY_PROVENANCE_SEARCH_SENTENCE, MEMORY_SEARCH_BAND_ORDER_HEADER } from "./provenance-wording.js";
|
|
8
8
|
import { deriveSupersededSet, memorySupersededNote, MEMORY_CHALLENGED_ENTRY_GUIDANCE, MEMORY_SEARCH_SUPERSEDED_TAG } from "./consolidation.js";
|
|
@@ -146,10 +146,10 @@ export function createMemoryEngineTools(opts) {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
const exposedEntry = (e) => committedOriginOf(e.frontmatter) !== undefined;
|
|
149
|
-
const pollutionSentence = () => {
|
|
149
|
+
const pollutionSentence = async () => {
|
|
150
150
|
let reason;
|
|
151
151
|
try {
|
|
152
|
-
reason = opts.sessionPollution?.()?.reason;
|
|
152
|
+
reason = (await opts.sessionPollution?.())?.reason;
|
|
153
153
|
}
|
|
154
154
|
catch {
|
|
155
155
|
return "";
|
|
@@ -161,13 +161,13 @@ export function createMemoryEngineTools(opts) {
|
|
|
161
161
|
}
|
|
162
162
|
return ` This session is marked polluted (${inlineUntrusted(reason, 200)}): the memory it writes is not admitted to the library at harvest, so writing this down now would not make it retrievable later either.`;
|
|
163
163
|
};
|
|
164
|
-
const noMatch = (query) => {
|
|
164
|
+
const noMatch = async (query) => {
|
|
165
165
|
const details = { outcome: "ok", hits: [] };
|
|
166
166
|
return {
|
|
167
167
|
content: `No memory entries matched ${JSON.stringify(inlineUntrusted(query, 120))}. Matching is lexical — other concrete ` +
|
|
168
168
|
`wordings may still hit, and ${MEMORY_INDEX_TOOL_NAME} lists every mounted entry when no wording works. ` +
|
|
169
169
|
`If the user expected you to know this, say that you checked memory and found nothing.` +
|
|
170
|
-
pollutionSentence(),
|
|
170
|
+
(await pollutionSentence()),
|
|
171
171
|
details,
|
|
172
172
|
};
|
|
173
173
|
};
|
|
@@ -448,7 +448,7 @@ export function createMemoryEngineTools(opts) {
|
|
|
448
448
|
`Only entries carrying a committed entry id are served here, and a memory file written into the memory root during ` +
|
|
449
449
|
`this session gets its id when the session-boundary harvest admits it — a file written in this session is not served here before then. ` +
|
|
450
450
|
`If the slug is misremembered: ${MEMORY_SEARCH_TOOL_NAME} matches keywords; ${MEMORY_INDEX_TOOL_NAME} lists exact slugs.` +
|
|
451
|
-
pollutionSentence(), "not_found", { slug: slug, ...(scope !== undefined ? { scope } : {}) });
|
|
451
|
+
(await pollutionSentence()), "not_found", { slug: slug, ...(scope !== undefined ? { scope } : {}) });
|
|
452
452
|
}
|
|
453
453
|
try {
|
|
454
454
|
const names = await shadowNamesAcross(await Promise.all(planes.map((plane) => plane.challengeExclusions?.())));
|
|
@@ -741,7 +741,7 @@ export function createMemoryEngineTools(opts) {
|
|
|
741
741
|
if (total === 0) {
|
|
742
742
|
const where = scope !== undefined ? ` in scope ${inlineUntrusted(scope, 80)}` : "";
|
|
743
743
|
const details = { outcome: "ok", entries: [], offset: 0, shown: 0, total: 0, ...(supersededHidden > 0 ? { supersededHidden } : {}), ...(shadowedHidden > 0 ? { shadowedHidden } : {}) };
|
|
744
|
-
return { content: `No ${supersededHidden > 0 || shadowedHidden > 0 ? "active " : ""}memory entries are mounted${where} in this session.${supersededNote}` + pollutionSentence(), details };
|
|
744
|
+
return { content: `No ${supersededHidden > 0 || shadowedHidden > 0 ? "active " : ""}memory entries are mounted${where} in this session.${supersededNote}` + (await pollutionSentence()), details };
|
|
745
745
|
}
|
|
746
746
|
if (offset >= total) {
|
|
747
747
|
return refusedIndex("offset_past_end", `offset ${offset} is past the end — the listing has ${total} row${total === 1 ? "" : "s"}.`);
|