@sema-agent/core 7.68.0 → 7.68.2
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 +55 -0
- package/dist/core/checkpoint-requirements.d.ts +20 -1
- package/dist/core/checkpoint-requirements.js +11 -5
- package/dist/core/engine-capabilities.d.ts +8 -1
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/file-history-store.d.ts +229 -44
- package/dist/core/file-history-store.js +288 -93
- package/dist/core/runner/contracts.d.ts +1 -1
- package/dist/core/runner/file-history-request.d.ts +10 -2
- package/dist/core/runner/file-history-request.js +17 -1
- package/dist/core/runner/file-history-restore.d.ts +11 -4
- package/dist/core/runner/file-history-restore.js +19 -5
- package/dist/core/runner/prepare-file-history.js +3 -3
- package/dist/core/runner/rewind-files.js +11 -8
- package/dist/core/store-contracts/file-history-store-contract.js +210 -13
- package/dist/core/task-spec-members.d.ts +2 -1
- package/dist/core/task-spec-members.js +1 -1
- package/dist/core/task-spec.d.ts +7 -0
- package/dist/core/tool-roster.d.ts +12 -0
- package/dist/core/tool-roster.js +12 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/stores/file/file-history-store.d.ts +5 -3
- package/dist/stores/file/file-history-store.js +42 -60
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +17 -1
- package/wire-changes/core-stores-sql@7.68.1.json +39 -0
- package/wire-changes/core-stores-sql@7.68.2.json +39 -0
- package/wire-changes/core@7.68.1.json +95 -0
- package/wire-changes/core@7.68.2.json +612 -0
- package/wire-changes/mods-kernel@7.68.1.json +39 -0
- package/wire-changes/mods-kernel@7.68.2.json +39 -0
- package/wire-changes/primitives@7.68.1.json +39 -0
- package/wire-changes/primitives@7.68.2.json +39 -0
- package/wire-changes/wiki-gate@7.68.1.json +39 -0
- package/wire-changes/wiki-gate@7.68.2.json +39 -0
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { ExecutionEnv } from "../../internal/harness.js";
|
|
10
10
|
import type { EngineNotice } from "../types.js";
|
|
11
|
-
import type { FileHistoryError, FileHistoryRestoreResult, FileHistoryStore, RewindFilesResult } from "../file-history-store.js";
|
|
11
|
+
import type { FileHistoryError, FileHistoryRestoreOptions, FileHistoryRestoreResult, FileHistoryStore, RewindFilesResult } from "../file-history-store.js";
|
|
12
12
|
import type { SessionReadFileStates } from "./session-read-file-states.js";
|
|
13
13
|
/** A restore outcome a seat may accept: the ledger, with `failed` (the operation could not run) already refused —
|
|
14
14
|
* the out-of-run rewind's answer carries exactly this. */
|
|
@@ -40,6 +40,11 @@ export declare function settleFileHistoryRestore(input: {
|
|
|
40
40
|
root: string;
|
|
41
41
|
signal: AbortSignal | undefined;
|
|
42
42
|
readStates: Pick<SessionReadFileStates, "noteRestored"> | undefined;
|
|
43
|
+
/** The rewind's restore options (`unplacedHistoryRecordedUnder`), handed to the store as they are. */
|
|
44
|
+
options: FileHistoryRestoreOptions | undefined;
|
|
45
|
+
/** Refuse before any file moves when the restore would refuse or fail one ({@link planFileHistoryRestore}) — a caller that does
|
|
46
|
+
* not accept a partial restore; a caller that reads the ledger itself leaves it off. */
|
|
47
|
+
wholeOrNothing: boolean;
|
|
43
48
|
}): Promise<AcceptedFileHistoryRestore>;
|
|
44
49
|
/**
|
|
45
50
|
* What `rewind.restore_failed` carries on its coded `detail` (the error's own member, which a failed task's
|
|
@@ -53,7 +58,7 @@ export type FileHistoryRestoreFailureDetail = Partial<Pick<FileHistoryError, "co
|
|
|
53
58
|
filesChangedCount: number;
|
|
54
59
|
refusedCount: number;
|
|
55
60
|
failedCount: number;
|
|
56
|
-
} & Pick<FileHistoryRestoreResult, "refused" | "failed">;
|
|
61
|
+
} & Pick<FileHistoryRestoreResult, "refused" | "failed" | "files">;
|
|
57
62
|
/**
|
|
58
63
|
* THE `rewind.restore_failed` error — the one mint for both ways a restore can fail a task: the store's operation-level
|
|
59
64
|
* failure ({@link settleFileHistoryRestore}) and the run seat's default refusal of a partial restore. The sentence is the
|
|
@@ -88,8 +93,10 @@ export declare function refuseTargetOutsideOwnLog(session: OwnLogReader, session
|
|
|
88
93
|
* crosses a session tree (`recordedRootOf`).
|
|
89
94
|
*/
|
|
90
95
|
export declare function refuseRestoreOnForkWithOwnTree(forkWithOwnTree: boolean, sessionId: string, target: string, ask: BoundaryAsk): void;
|
|
91
|
-
/** The per-file ledger as one sentence
|
|
92
|
-
|
|
96
|
+
/** The per-file ledger as one sentence: each count, with the files written or deleted named (by what was done to each, where
|
|
97
|
+
* the answer carries `files`), and each refused / failed path with its reason. A PLANNED ledger (nothing moved) says what the
|
|
98
|
+
* restore would have done instead ("would apply", "would write" / "would delete"). */
|
|
99
|
+
export declare function fileHistoryRestoreLedgerLine(r: FileHistoryRestoreResult, planned?: boolean): string;
|
|
93
100
|
/** A restore whose entry has no boundary on the session; a PREVIEW's form says "usable" — its probe
|
|
94
101
|
* (`canRestore`) cannot tell a boundary never made from one that is there and unreadable, a real restore can. */
|
|
95
102
|
export declare function noBoundaryRefusal(target: string, sessionId: string, preview?: boolean): Error & {
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { resolveTrackKey } from "../file-history-store.js";
|
|
2
|
+
import { planFileHistoryRestore, witnessEnvOf, withRewindFiles } from "../file-history-store.js";
|
|
2
3
|
import { isGovernanceRetryClass } from "../governance-codes.js";
|
|
3
4
|
export async function settleFileHistoryRestore(input) {
|
|
4
5
|
const { store, sessionId, scope, target, env, root } = input;
|
|
5
|
-
|
|
6
|
+
if (input.wholeOrNothing) {
|
|
7
|
+
const plan = await planFileHistoryRestore(store, { scope, entryId: target, env, root, ...(input.signal !== undefined ? { signal: input.signal } : {}), ...(input.options !== undefined ? { options: input.options } : {}) });
|
|
8
|
+
const planned = plan.restore;
|
|
9
|
+
if (planned.outcome === "failed" && planned.error?.code === "not_found")
|
|
10
|
+
throw noBoundaryFor(target, sessionId, input.before ? "before" : "restore");
|
|
11
|
+
if (planned.outcome !== "complete") {
|
|
12
|
+
throw restoreFailedError({ ...planned, filesChanged: [], identicalSkipped: [] }, `rewind-files: restore to entry "${target}" was refused before any file moved — the restore would ${planned.outcome === "failed" ? `fail (${planned.error?.code ?? "restore_failed"}: ${planned.error?.message ?? "unknown"})` : "be PARTIAL"}. Nothing was written or deleted; the plan: ${fileHistoryRestoreLedgerLine(planned, true)}${planned.outcome === "failed" ? "." : " (set acceptPartialRestore: true to restore the rest and disclose the ledger instead)."}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const witness = witnessEnvOf(env);
|
|
16
|
+
const restored = withRewindFiles(await store.restore(scope, target, witness.env, root, input.signal, input.options), witness.mutations, root);
|
|
6
17
|
input.readStates?.noteRestored(sessionId, restoredAbsPathsOf(restored, root));
|
|
7
18
|
if (restored.outcome !== "failed")
|
|
8
19
|
return restored;
|
|
@@ -17,8 +28,9 @@ export function restoreFailedError(restored, message) {
|
|
|
17
28
|
filesChangedCount: restored.filesChanged.length,
|
|
18
29
|
refusedCount: restored.refused.length,
|
|
19
30
|
failedCount: restored.failed.length,
|
|
20
|
-
refused: restored.refused.map((f) => ({ path: f.path, reason: f.reason, class: f.class })),
|
|
31
|
+
refused: restored.refused.map((f) => ({ path: f.path, reason: f.reason, class: f.class, ...(f.action !== undefined ? { action: f.action } : {}), ...(f.recordedUnder !== undefined ? { recordedUnder: f.recordedUnder } : {}) })),
|
|
21
32
|
failed: restored.failed.map((f) => ({ path: f.path, reason: f.reason })),
|
|
33
|
+
...(restored.files !== undefined ? { files: restored.files.map((f) => ({ ...f, ...(f.refused !== undefined ? { refused: { ...f.refused } } : {}), ...(f.failed !== undefined ? { failed: { ...f.failed } } : {}) })) } : {}),
|
|
22
34
|
};
|
|
23
35
|
const e = new Error(message);
|
|
24
36
|
e.code = "rewind.restore_failed";
|
|
@@ -36,8 +48,10 @@ export function refuseRestoreOnForkWithOwnTree(forkWithOwnTree, sessionId, targe
|
|
|
36
48
|
if (forkWithOwnTree)
|
|
37
49
|
throw noBoundaryFor(target, sessionId, ask);
|
|
38
50
|
}
|
|
39
|
-
export function fileHistoryRestoreLedgerLine(r) {
|
|
40
|
-
|
|
51
|
+
export function fileHistoryRestoreLedgerLine(r, planned = false) {
|
|
52
|
+
const done = planned ? { write: "would write", delete: "would delete" } : { write: "written", delete: "deleted" };
|
|
53
|
+
const moved = r.files?.filter((f) => f.refused === undefined).map((f) => `${f.action === "delete" ? done.delete : done.write} ${f.path}`) ?? r.filesChanged.map((k) => `${planned ? "would change" : "changed"} ${k}`);
|
|
54
|
+
return `${planned ? "would apply" : "applied"} ${r.filesChanged.length}, identical ${r.identicalSkipped.length}, refused ${r.refused.length}${r.refused.length > 0 ? ` (${r.refused.map((f) => `${f.path}: ${f.reason}`).join("; ")})` : ""}, failed ${r.failed.length}${r.failed.length > 0 ? ` (${r.failed.map((f) => `${f.path}: ${f.reason}`).join("; ")})` : ""}${moved.length > 0 ? `; ${moved.join("; ")}` : ""}`;
|
|
41
55
|
}
|
|
42
56
|
export function noBoundaryRefusal(target, sessionId, preview = false) {
|
|
43
57
|
const e = new Error(preview
|
|
@@ -64,7 +78,7 @@ function restoredAbsPathsOf(restored, root) {
|
|
|
64
78
|
return out;
|
|
65
79
|
}
|
|
66
80
|
function rewindRefusalTail() {
|
|
67
|
-
return `Boundaries are keyed by the entry of the person's input that opened a turn (an engine entry ahead of it, such as a task notification, has none) and exist only for turns that recorded history (a RunnerDeps.fileHistoryStore wired, capture on, and the run's file history not disabled); a fork holds its source's boundaries only when neither session works in a tree of its own (TaskSpec.workspace): a fork whose source has one, or whose source's checkout record cannot be read from its log,
|
|
81
|
+
return `Boundaries are keyed by the entry of the person's input that opened a turn (an engine entry ahead of it, such as a task notification, has none) and exist only for turns that recorded history (a RunnerDeps.fileHistoryStore wired, capture on, and the run's file history not disabled); a fork holds its source's boundaries only when neither session works in a tree of its own (TaskSpec.workspace): a fork whose source has one, or whose source's checkout record cannot be read from its log, is carried none of them by the engine — the file changes before the fork are not in its history unless a host carried them in (a deletion cascade, an import), and then each file recorded under another directory is refused where this session would write it (recorded_elsewhere) — and a fork that has a tree of its own records no file history and restores none in this version (its conversation is still branched by resumeAt); a file version is restored only under the directory it was recorded under, and an older version that records no directory only when the rewind names it (unplacedHistoryRecordedUnder); a boundary from the retired whole-tree snapshot era is not restorable by this seat, and reaped boundaries have none.`;
|
|
68
82
|
}
|
|
69
83
|
function beforeWithoutBoundaryRefusal(target, sessionId) {
|
|
70
84
|
const e = new Error(`rewind-files: entry "${target}" has no file-history boundary on session "${sessionId}" — a before-restore needs the target's own boundary and never crosses into an earlier turn, so the working tree was NOT rewound. ${rewindRefusalTail()}`);
|
|
@@ -69,7 +69,7 @@ export async function prepareFileHistory(input) {
|
|
|
69
69
|
throw own.refused ?? unaddressedRewindRefusal(sessionId, rewindTarget);
|
|
70
70
|
await refuseTargetOutsideOwnLog(session, sessionId, rewindTarget, rewindBefore ? "before" : "restore");
|
|
71
71
|
refuseRestoreOnForkWithOwnTree(forkWithOwnTree, sessionId, rewindTarget, rewindBefore ? "before" : "restore");
|
|
72
|
-
const restored = await settleFileHistoryRestore({ store: fileHistoryStore, sessionId, scope: own.scope, target: rewindTarget, before: rewindBefore, env: executionEnv, root: historyRoot, signal: restoreSignal, readStates: internals?.sessionReadStates });
|
|
72
|
+
const restored = await settleFileHistoryRestore({ store: fileHistoryStore, sessionId, scope: own.scope, target: rewindTarget, before: rewindBefore, env: executionEnv, root: historyRoot, signal: restoreSignal, readStates: internals?.sessionReadStates, options: request.restoreOptions, wholeOrNothing: spec.acceptPartialRestore !== true });
|
|
73
73
|
const ledgerLine = fileHistoryRestoreLedgerLine;
|
|
74
74
|
if (restored.outcome === "partial") {
|
|
75
75
|
if (spec.acceptPartialRestore === true) {
|
|
@@ -79,7 +79,7 @@ export async function prepareFileHistory(input) {
|
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
else {
|
|
82
|
-
throw restoreFailedError(restored, `rewind-files: restore to entry "${rewindTarget}" was PARTIAL — ledger: ${ledgerLine(restored)}. The task
|
|
82
|
+
throw restoreFailedError(restored, `rewind-files: restore to entry "${rewindTarget}" was PARTIAL after its plan passed — a write failed or the files changed between the plan and the restore, so the tree is now partly restored (the files written or deleted are named in the ledger): ${ledgerLine(restored)}. The task did not run on it (set acceptPartialRestore: true to run on a partly restored tree and disclose it instead); re-running the same restore converges (per-file idempotent).`);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -191,7 +191,7 @@ export async function adoptForkedFileHistory(store, lineage, sessionId, ownScope
|
|
|
191
191
|
if (own !== undefined && source !== undefined)
|
|
192
192
|
memo.settled.add(ownScope);
|
|
193
193
|
const apart = source === undefined ? "this session's copy of the source's log shows the source working in a tree of its own, or cannot vouch for where its history is keyed" : own === undefined ? "where this session's history is keyed cannot be read" : `the source's history is keyed against ${source} and this session's against ${own}`;
|
|
194
|
-
discloseOnce(new FileHistoryStoreError({ code: "adopt_failed" }, `file-history fork carry from session "${forkedFrom}" was not made — ${apart}: carried records
|
|
194
|
+
discloseOnce(new FileHistoryStoreError({ code: "adopt_failed" }, `file-history fork carry from session "${forkedFrom}" was not made — ${apart}: carried records would be joined on this session's root, where a version the source recorded under its own directory is refused (recorded elsewhere), so none is carried. Nothing was carried by this session; a rewind to a point before the fork is refused — as a point with no boundary on this session, or, where this session's history already holds the source's versions through another channel (a host's deletion cascade or import), file by file as recorded elsewhere, nothing written (the run itself proceeds)`));
|
|
195
195
|
return;
|
|
196
196
|
}
|
|
197
197
|
const shared = memo.inFlight.get(ownScope);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { planFileHistoryRestore } from "../file-history-store.js";
|
|
1
2
|
import { hasDestroy } from "../remote-env.js";
|
|
2
|
-
import { resolveDeploymentFileHistory, storeUnconfiguredRefusal } from "./file-history-request.js";
|
|
3
|
+
import { readRestoreOptions, resolveDeploymentFileHistory, storeUnconfiguredRefusal } from "./file-history-request.js";
|
|
3
4
|
import { prepareExecutionEnv } from "./prepare-execution-env.js";
|
|
4
5
|
import { noBoundaryRefusal, refuseRestoreOnForkWithOwnTree, refuseTargetOutsideOwnLog, settleFileHistoryRestore } from "./file-history-restore.js";
|
|
5
6
|
import { adoptForkedFileHistory, resolveFileHistoryCoordinates, unaddressedRewindRefusal } from "./prepare-file-history.js";
|
|
@@ -9,7 +10,7 @@ import { acquireExistingSession, claimIdleSession, readOccupantExpectation, read
|
|
|
9
10
|
import { settleTeardownLeg } from "./teardown-bounded.js";
|
|
10
11
|
import { forkHasOwnTree, recordedRootOf, sessionRootOf } from "../session-checkout.js";
|
|
11
12
|
import { canonicalOrSelf } from "./child-tree.js";
|
|
12
|
-
const REQUEST_KEYS = new Set(["sessionId", "to", "dryRun", "signal", "expect"]);
|
|
13
|
+
const REQUEST_KEYS = new Set(["sessionId", "to", "dryRun", "signal", "expect", "unplacedHistoryRecordedUnder"]);
|
|
13
14
|
export async function rewindSessionFiles(seats, request) {
|
|
14
15
|
const req = screenRewindFilesRequest(request);
|
|
15
16
|
const { deps } = seats;
|
|
@@ -71,19 +72,21 @@ async function rewindOnEnv(req, env, handsEnabled, baseRoot, ctx) {
|
|
|
71
72
|
if (req.dryRun) {
|
|
72
73
|
if (!(await ctx.store.canRestore(historyScope, req.to)))
|
|
73
74
|
throw noBoundaryRefusal(req.to, req.sessionId, true);
|
|
74
|
-
const
|
|
75
|
-
|
|
75
|
+
const plan = await planFileHistoryRestore(ctx.store, { scope: historyScope, entryId: req.to, env, root: historyRoot, ...(req.signal !== undefined ? { signal: req.signal } : {}), ...(req.restoreOptions !== undefined ? { options: req.restoreOptions } : {}) });
|
|
76
|
+
if (plan.restore.outcome === "failed" && plan.restore.error?.code === "not_found")
|
|
77
|
+
throw noBoundaryRefusal(req.to, req.sessionId, true);
|
|
78
|
+
return { dryRun: true, preview: plan.restore.outcome === "failed" && plan.restore.files.length === 0 ? null : plan.diffStats };
|
|
76
79
|
}
|
|
77
|
-
const restore = await settleFileHistoryRestore({ store: ctx.store, sessionId: req.sessionId, scope: historyScope, target: req.to, before: false, env, root: historyRoot, signal: req.signal, readStates: ctx.seats.readStates });
|
|
80
|
+
const restore = await settleFileHistoryRestore({ store: ctx.store, sessionId: req.sessionId, scope: historyScope, target: req.to, before: false, env, root: historyRoot, signal: req.signal, readStates: ctx.seats.readStates, options: req.restoreOptions, wholeOrNothing: false });
|
|
78
81
|
return { dryRun: false, restore };
|
|
79
82
|
}
|
|
80
83
|
function screenRewindFilesRequest(request) {
|
|
81
84
|
const bad = (what) => {
|
|
82
|
-
const e = new Error(`Runner.rewindFiles: ${what} — nothing was rewound. The request is { sessionId, to, dryRun?, signal?, expect? }.`);
|
|
85
|
+
const e = new Error(`Runner.rewindFiles: ${what} — nothing was rewound. The request is { sessionId, to, dryRun?, signal?, expect?, unplacedHistoryRecordedUnder? }.`);
|
|
83
86
|
e.code = "rewind.invalid_spec";
|
|
84
87
|
throw e;
|
|
85
88
|
};
|
|
86
|
-
const { sessionId, to, dryRun, signal, expect } = readPlainRequest(request, REQUEST_KEYS, bad);
|
|
89
|
+
const { sessionId, to, dryRun, signal, expect, unplacedHistoryRecordedUnder } = readPlainRequest(request, REQUEST_KEYS, bad);
|
|
87
90
|
if (typeof sessionId !== "string" || sessionId === "")
|
|
88
91
|
return bad(`sessionId must be a non-empty string, got ${shownValue(sessionId)}`);
|
|
89
92
|
if (typeof to !== "string" || to === "")
|
|
@@ -92,7 +95,7 @@ function screenRewindFilesRequest(request) {
|
|
|
92
95
|
return bad(`dryRun must be a boolean when given, got ${shownValue(dryRun)}`);
|
|
93
96
|
if (signal !== undefined && !(signal instanceof AbortSignal))
|
|
94
97
|
return bad(`signal must be an AbortSignal when given, got ${shownValue(signal)}`);
|
|
95
|
-
return { sessionId, to, dryRun: dryRun === true, signal, expect: readOccupantExpectation(expect, bad) };
|
|
98
|
+
return { sessionId, to, dryRun: dryRun === true, signal, expect: readOccupantExpectation(expect, bad), restoreOptions: readRestoreOptions(unplacedHistoryRecordedUnder, true, "Runner.rewindFiles") };
|
|
96
99
|
}
|
|
97
100
|
function sessionBusyRefusal(sessionId, target) {
|
|
98
101
|
const e = new Error(`Runner.rewindFiles: a task is running or queued on session "${sessionId}" in this Runner, or a write one of its tasks issued has not settled — rewinding its files to entry "${target}" now would move them under that work, so nothing was rewound; retry once it has ended and its writes have settled`);
|
|
@@ -3,7 +3,7 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
3
3
|
import { chmod, mkdtemp, mkdir, rm, stat, symlink, writeFile, readFile } from "node:fs/promises";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
5
|
import { join } from "node:path";
|
|
6
|
-
import { fileHistoryBlobExchangeOf } from "../file-history-store.js";
|
|
6
|
+
import { fileHistoryBlobExchangeOf, fileHistoryParentIdentTravels } from "../file-history-store.js";
|
|
7
7
|
import { isGovernanceRetryClass } from "../governance-codes.js";
|
|
8
8
|
import { physicalPathOfAsync } from "../physical-path.js";
|
|
9
9
|
import { NodeExecutionEnv } from "../../internal/harness.js";
|
|
@@ -45,6 +45,9 @@ function assertPermanenceWord(error, what) {
|
|
|
45
45
|
if (p !== undefined)
|
|
46
46
|
assert.ok(error !== undefined && NAMES_A_FAULT[error.code] === true, `${what}: ${error?.code} is not a fault and carries no permanence`);
|
|
47
47
|
}
|
|
48
|
+
async function existsAt(path) {
|
|
49
|
+
return stat(path).then(() => true, () => false);
|
|
50
|
+
}
|
|
48
51
|
async function withTree(fn) {
|
|
49
52
|
const dir = await physicalPathOfAsync(await mkdtemp(join(tmpdir(), "fh-kit-")));
|
|
50
53
|
try {
|
|
@@ -236,6 +239,41 @@ export async function fileHistoryStoreContract(make, runAssertion, onOptionalMem
|
|
|
236
239
|
assert.equal(await store.canRestore("fresh", "b"), true);
|
|
237
240
|
});
|
|
238
241
|
});
|
|
242
|
+
run("adoptScope carries only the entries that travel: after adoption the history holds no absolute-key entry, so a fork's rewind never writes the file its source edited outside its directory", async () => {
|
|
243
|
+
await withTree(async (dir, env) => {
|
|
244
|
+
await withTree(async (outside) => {
|
|
245
|
+
const probe = make();
|
|
246
|
+
await mkdir(join(outside, "w"), { recursive: true, mode: 0o700 });
|
|
247
|
+
await writeFile(join(dir, "w.txt"), "w-a");
|
|
248
|
+
await writeFile(join(outside, "w", "w.txt"), "w-b");
|
|
249
|
+
await probe.trackEdit("w", join(dir, "w.txt"), env, dir);
|
|
250
|
+
await probe.snapshot("w", "wb", env, dir);
|
|
251
|
+
const envW = new NodeExecutionEnv({ cwd: join(outside, "w") });
|
|
252
|
+
await probe.trackEdit("w", join(outside, "w", "w.txt"), envW, join(outside, "w"));
|
|
253
|
+
await writeFile(join(outside, "w", "w.txt"), "w-b-edited");
|
|
254
|
+
const minted = (await probe.restore("w", "wb", envW, join(outside, "w"))).filesChanged.includes(join(outside, "w", "w.txt"));
|
|
255
|
+
const store = make();
|
|
256
|
+
await writeFile(join(dir, "f.txt"), "f-0");
|
|
257
|
+
await writeFile(join(outside, "o.txt"), "o-0");
|
|
258
|
+
assert.deepEqual(await store.trackEdit("src", join(dir, "f.txt"), env, dir), { ok: true, minted: true });
|
|
259
|
+
assert.deepEqual(await store.trackEdit("src", join(outside, "o.txt"), env, dir), { ok: true, minted: true });
|
|
260
|
+
assert.deepEqual(await store.snapshot("src", "b1", env, dir), { ok: true });
|
|
261
|
+
await writeFile(join(dir, "f.txt"), "f-1");
|
|
262
|
+
await writeFile(join(outside, "o.txt"), "o-source-still-editing");
|
|
263
|
+
assert.deepEqual(await store.adoptScope("src", "fork"), { ok: true });
|
|
264
|
+
const r = await store.restore("fork", "b1", env, dir);
|
|
265
|
+
const combination = minted
|
|
266
|
+
? " — and this store mints a second file's absolute key: minting it while carrying every entry writes a fork's rewind into the file its source still edits; the two are followed together or not at all"
|
|
267
|
+
: "";
|
|
268
|
+
assert.equal(await readFile(join(outside, "o.txt"), "utf8"), "o-source-still-editing", `an absolute-key entry was carried into the fork and restored there${combination}: ${JSON.stringify(r)}`);
|
|
269
|
+
const named = [...r.filesChanged, ...r.identicalSkipped, ...r.refused.map((f) => f.path), ...r.failed.map((f) => f.path)];
|
|
270
|
+
assert.equal(named.includes(join(outside, "o.txt")), false, `the fork's history names no absolute-key entry${combination}: ${JSON.stringify(r)}`);
|
|
271
|
+
assert.equal(await readFile(join(dir, "f.txt"), "utf8"), "f-0", "the root-relative entry is carried and restores");
|
|
272
|
+
const own = await store.restore("src", "b1", env, dir);
|
|
273
|
+
assert.ok(own.filesChanged.includes(join(outside, "o.txt")), `the source's own absolute-key entry still restores: ${JSON.stringify(own)}`);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
});
|
|
239
277
|
run("deleteUnreadableSessionHistory (optional): every scope of the id — its bare id and each occupant's address — is erased, and no other id's (one it is a prefix of, one carrying `~` of its own); a repeat answers 0", async () => {
|
|
240
278
|
if (make().deleteUnreadableSessionHistory === undefined)
|
|
241
279
|
return;
|
|
@@ -427,7 +465,7 @@ export async function fileHistoryStoreContract(make, runAssertion, onOptionalMem
|
|
|
427
465
|
assert.equal(await readFile(join(dir, "f.txt"), "utf8"), "agent-edited");
|
|
428
466
|
});
|
|
429
467
|
});
|
|
430
|
-
run("track-key COORDINATE (A-082 idx5): an under-root capture
|
|
468
|
+
run("track-key COORDINATE (A-082 idx5): an under-root capture is keyed root-relative and an outside-root path verbatim-absolute; a restore handed another root writes neither root's under-root file (the version records the old directory) and restores the outside-root path in place", async () => {
|
|
431
469
|
await withTree(async (dirA, envA) => {
|
|
432
470
|
await withTree(async (dirB) => {
|
|
433
471
|
await withTree(async (outside, _envOut) => {
|
|
@@ -446,15 +484,16 @@ export async function fileHistoryStoreContract(make, runAssertion, onOptionalMem
|
|
|
446
484
|
await writeFile(join(dirB, "sub", "f.txt"), "EDITED");
|
|
447
485
|
const envB = new NodeExecutionEnv({ cwd: dirB });
|
|
448
486
|
const r = await store.restore("sc", "b1", envB, dirB);
|
|
449
|
-
assert.equal(r.outcome, "
|
|
450
|
-
assert.
|
|
451
|
-
assert.equal(await readFile(join(
|
|
487
|
+
assert.equal(r.outcome, "partial", `the under-root version is refused under another root, got ${JSON.stringify(r)}`);
|
|
488
|
+
assert.deepEqual(r.refused.map((f) => [f.path, f.class]), [["sub/f.txt", "recorded_elsewhere"]], "the under-root key is root-relative and its version records dirA");
|
|
489
|
+
assert.equal(await readFile(join(dirB, "sub", "f.txt"), "utf8"), "EDITED", "the CURRENT root's same-named file is not written");
|
|
490
|
+
assert.equal(await readFile(join(dirA, "sub", "f.txt"), "utf8"), "EDITED", "the OLD root is not written either (the key was rel, not absolute)");
|
|
452
491
|
assert.equal(await readFile(outsideFile, "utf8"), "P-outside-root", "an outside-root key is verbatim-absolute — it restores where it was captured, root move or not");
|
|
453
492
|
});
|
|
454
493
|
});
|
|
455
494
|
});
|
|
456
495
|
});
|
|
457
|
-
run("export/import round trip AFTER a reap: the complete retained state travels (v1 fallbacks,
|
|
496
|
+
run("export/import round trip AFTER a reap: the complete retained state travels (v1 fallbacks, key self-description; never a version's place) and the importing scope serves BOTH a boundary restore and the pristine fallback where the rewind names the directory they were recorded under", async () => {
|
|
458
497
|
await withTree(async (dir, env) => {
|
|
459
498
|
const src = make();
|
|
460
499
|
if (src.exportHistory === undefined || src.importHistory === undefined)
|
|
@@ -476,10 +515,13 @@ export async function fileHistoryStoreContract(make, runAssertion, onOptionalMem
|
|
|
476
515
|
assert.deepEqual(carried, { ok: true });
|
|
477
516
|
assert.equal(await dst.canRestore("carried", "b1"), true);
|
|
478
517
|
await writeFile(join(dir, "keep.txt"), "diverged");
|
|
479
|
-
const
|
|
518
|
+
const unnamed = await dst.restore("carried", "b1", env, dir);
|
|
519
|
+
assert.deepEqual(unnamed.refused.map((f) => [f.path, f.class]), [["keep.txt", "place_unrecorded"]], `an imported version records no place: ${JSON.stringify(unnamed)}`);
|
|
520
|
+
const named = { unplacedHistoryRecordedUnder: dir };
|
|
521
|
+
const r1 = await dst.restore("carried", "b1", env, dir, undefined, named);
|
|
480
522
|
assert.equal(r1.outcome, "complete", `imported boundary restore: ${JSON.stringify(r1)}`);
|
|
481
523
|
assert.equal(await readFile(join(dir, "keep.txt"), "utf8"), "turn-1");
|
|
482
|
-
const r0 = await dst.restore("carried", "b0", env, dir);
|
|
524
|
+
const r0 = await dst.restore("carried", "b0", env, dir, undefined, named);
|
|
483
525
|
assert.equal(r0.outcome, "complete");
|
|
484
526
|
assert.equal(await readFile(join(dir, "keep.txt"), "utf8"), "pristine", "the v1 fallback travelled: a boundary that predates the track still restores pristine");
|
|
485
527
|
});
|
|
@@ -603,6 +645,39 @@ export async function fileHistoryStoreContract(make, runAssertion, onOptionalMem
|
|
|
603
645
|
assert.equal(await readFile(outsideVictim, "utf8"), "not the agent's file", "the victim path was never in reach");
|
|
604
646
|
});
|
|
605
647
|
});
|
|
648
|
+
run("export carries only the entries that travel, and no version's place: an absolute-key entry is left out and counted (absoluteEntriesOmitted, never its path) and no version carries an absolute parentIdent, so the envelope passes the import door; an envelope carrying a place, or a malformed count, is refused at the door", async () => {
|
|
649
|
+
await withTree(async (dir, env) => {
|
|
650
|
+
await withTree(async (outside) => {
|
|
651
|
+
const src = make();
|
|
652
|
+
if (src.exportHistory === undefined || src.importHistory === undefined)
|
|
653
|
+
return;
|
|
654
|
+
const shed = contentShed();
|
|
655
|
+
await shed.write(join(dir, "f.txt"), "f-0");
|
|
656
|
+
await shed.write(join(outside, "o.txt"), "o-0");
|
|
657
|
+
assert.deepEqual(await src.trackEdit("sc", join(dir, "f.txt"), env, dir), { ok: true, minted: true });
|
|
658
|
+
assert.deepEqual(await src.trackEdit("sc", join(outside, "o.txt"), env, dir), { ok: true, minted: true });
|
|
659
|
+
assert.deepEqual(await src.snapshot("sc", "b1", env, dir), { ok: true });
|
|
660
|
+
const exported = await src.exportHistory("sc");
|
|
661
|
+
const envelope = exported.ok ? exported.history : null;
|
|
662
|
+
assert.ok(envelope !== null, JSON.stringify(exported));
|
|
663
|
+
assert.deepEqual(envelope.tracked.map((t) => [t.relOrAbsPath, t.keyKind]), [["f.txt", "root-relative"]], "only the root-relative entry travels");
|
|
664
|
+
assert.deepEqual(envelope.boundaries.map((b) => b.files.map((f) => f.relOrAbsPath)), [["f.txt"]], "and no boundary names the one left out");
|
|
665
|
+
assert.equal(envelope.absoluteEntriesOmitted, 1, "the one left out is counted");
|
|
666
|
+
assert.equal(JSON.stringify(envelope).includes(outside), false, "the left-out path does not travel");
|
|
667
|
+
const placed = envelope.tracked.flatMap((t) => t.versions.filter((v) => v.parentIdent !== undefined && !fileHistoryParentIdentTravels(v.parentIdent)).map((v) => `${t.relOrAbsPath}@v${v.version}`));
|
|
668
|
+
assert.deepEqual(placed, [], "no version's place travels (the importing door refuses an envelope that carries one)");
|
|
669
|
+
const dst = make();
|
|
670
|
+
assert.deepEqual(await dst.importHistory("carried", envelope, shed.fetch), { ok: true });
|
|
671
|
+
const withPlace = wireEnvelope({ ...envelope, tracked: envelope.tracked.map((t) => ({ ...t, versions: t.versions.map((v) => ({ ...v, parentIdent: dir })) })) });
|
|
672
|
+
const placeRefused = await make().importHistory("y", withPlace, shed.fetch);
|
|
673
|
+
assert.equal(placeRefused.ok ? "ok" : placeRefused.error.code, "unsupported_format", "an envelope carrying a version's place is refused at the door");
|
|
674
|
+
for (const bad of [-1, 1.5, "2", null]) {
|
|
675
|
+
const refused = await make().importHistory("x", wireEnvelope({ ...envelope, absoluteEntriesOmitted: bad }), shed.fetch);
|
|
676
|
+
assert.equal(refused.ok ? "ok" : refused.error.code, "unsupported_format", `absoluteEntriesOmitted ${JSON.stringify(bad)} is refused at the door`);
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
});
|
|
680
|
+
});
|
|
606
681
|
run("annulTrack refuses a mint ANOTHER lane is already relying on: two edits race one path, the first fails its write, and the second's baseline survives", async () => {
|
|
607
682
|
await withTree(async (dir, env) => {
|
|
608
683
|
const store = make();
|
|
@@ -727,7 +802,7 @@ export async function fileHistoryStoreContract(make, runAssertion, onOptionalMem
|
|
|
727
802
|
assert.equal(r.modeNotPreserved, 1, "…and the count says so — the honest-absence law, in the ledger");
|
|
728
803
|
});
|
|
729
804
|
});
|
|
730
|
-
run("restore preflight (§7 E5/E4, slice 3): an in-root ancestor swapped for a link OUT of the root is REFUSED per file, a
|
|
805
|
+
run("restore preflight (§7 E5/E4, slice 3): an in-root ancestor swapped for a link OUT of the root is REFUSED per file, a whole-root move is refused as recorded elsewhere (the version restores where it was recorded), and the rest of the set converges either way", async () => {
|
|
731
806
|
await withTree(async (dir, env) => {
|
|
732
807
|
const store = make();
|
|
733
808
|
const outside = await mkdtemp(join(tmpdir(), "fh-kit-outside-"));
|
|
@@ -759,13 +834,135 @@ export async function fileHistoryStoreContract(make, runAssertion, onOptionalMem
|
|
|
759
834
|
await writeFile(join(oldRoot, "d", "f.txt"), "pristine");
|
|
760
835
|
assert.deepEqual(await store.trackEdit("sc", join(oldRoot, "d", "f.txt"), env, oldRoot), { ok: true, minted: true });
|
|
761
836
|
assert.deepEqual(await store.snapshot("sc", "b1", env, oldRoot), { ok: true });
|
|
837
|
+
await writeFile(join(oldRoot, "d", "f.txt"), "old-root-edited");
|
|
762
838
|
await withTree(async (newRoot, newEnv) => {
|
|
763
839
|
await mkdir(join(newRoot, "d"), { recursive: true });
|
|
764
|
-
await writeFile(join(newRoot, "d", "f.txt"), "
|
|
840
|
+
await writeFile(join(newRoot, "d", "f.txt"), "new-root-own");
|
|
765
841
|
const r = await store.restore("sc", "b1", newEnv, newRoot);
|
|
766
|
-
assert.equal(r.outcome, "
|
|
767
|
-
assert.
|
|
842
|
+
assert.equal(r.outcome, "partial", `a version recorded under another directory is refused, never re-pointed: ${JSON.stringify(r)}`);
|
|
843
|
+
assert.deepEqual(r.refused.map((f) => [f.path, f.class]), [["d/f.txt", "recorded_elsewhere"]]);
|
|
844
|
+
const under = r.refused[0].recordedUnder;
|
|
845
|
+
assert.ok(under === undefined || under === join(oldRoot, "d"), `recordedUnder names the directory the version was recorded under: ${under}`);
|
|
846
|
+
assert.deepEqual(r.filesChanged, []);
|
|
847
|
+
assert.equal(await readFile(join(newRoot, "d", "f.txt"), "utf8"), "new-root-own", "the new root's file is not written");
|
|
848
|
+
assert.equal(await readFile(join(oldRoot, "d", "f.txt"), "utf8"), "old-root-edited", "nor the old root's");
|
|
849
|
+
const back = await store.restore("sc", "b1", env, oldRoot);
|
|
850
|
+
assert.equal(back.outcome, "complete", JSON.stringify(back));
|
|
851
|
+
assert.equal(await readFile(join(oldRoot, "d", "f.txt"), "utf8"), "pristine");
|
|
852
|
+
});
|
|
853
|
+
});
|
|
854
|
+
});
|
|
855
|
+
run("K1 one relative name, two files: a boundary taken under another root re-reads each tracked file where it was recorded, never the same-named file it was handed", async () => {
|
|
856
|
+
await withTree(async (r, env) => {
|
|
857
|
+
const store = make();
|
|
858
|
+
const x = join(r, "x");
|
|
859
|
+
await mkdir(join(r, "src"), { recursive: true, mode: 0o700 });
|
|
860
|
+
await mkdir(join(x, "src"), { recursive: true, mode: 0o700 });
|
|
861
|
+
await writeFile(join(r, "src", "i.ts"), "r-0");
|
|
862
|
+
await writeFile(join(x, "src", "i.ts"), "x-0");
|
|
863
|
+
assert.deepEqual(await store.trackEdit("sc", join(r, "src", "i.ts"), env, r), { ok: true, minted: true });
|
|
864
|
+
assert.deepEqual(await store.snapshot("sc", "b1", env, r), { ok: true });
|
|
865
|
+
await writeFile(join(r, "src", "i.ts"), "r-1");
|
|
866
|
+
const envX = new NodeExecutionEnv({ cwd: x });
|
|
867
|
+
assert.deepEqual(await store.snapshot("sc", "b2", envX, x), { ok: true });
|
|
868
|
+
await writeFile(join(x, "src", "i.ts"), "x-person");
|
|
869
|
+
const back = await store.restore("sc", "b2", envX, x);
|
|
870
|
+
assert.equal(await readFile(join(x, "src", "i.ts"), "utf8"), "x-person", `a file the history never touched is not written: ${JSON.stringify(back)}`);
|
|
871
|
+
assert.equal(await readFile(join(r, "src", "i.ts"), "utf8"), "r-1");
|
|
872
|
+
assert.deepEqual(back.filesChanged, []);
|
|
873
|
+
});
|
|
874
|
+
});
|
|
875
|
+
run("K2 a boundary reads no file through a link out of the root: an imported key that runs through one, and a tracked file swapped for one, are held, their outside bytes never read", async () => {
|
|
876
|
+
const reading = (env, seen) => new Proxy(env, {
|
|
877
|
+
get(target, prop, receiver) {
|
|
878
|
+
const value = Reflect.get(target, prop, receiver);
|
|
879
|
+
if (typeof value !== "function")
|
|
880
|
+
return value;
|
|
881
|
+
const fn = value;
|
|
882
|
+
return (...args) => {
|
|
883
|
+
if ((prop === "readBinaryFile" || prop === "readTextFile" || prop === "readTextLines" || prop === "openBound") && typeof args[0] === "string")
|
|
884
|
+
seen.push(args[0]);
|
|
885
|
+
return fn.apply(target, args);
|
|
886
|
+
};
|
|
887
|
+
},
|
|
888
|
+
});
|
|
889
|
+
await withTree(async (outside) => {
|
|
890
|
+
await writeFile(join(outside, "secret"), "OUTSIDE-SECRET");
|
|
891
|
+
await withTree(async (r, plain) => {
|
|
892
|
+
const store = make();
|
|
893
|
+
await symlink(outside, join(r, "link"));
|
|
894
|
+
await mkdir(join(r, "d"), { recursive: true, mode: 0o700 });
|
|
895
|
+
await writeFile(join(r, "d", "f.txt"), "mine");
|
|
896
|
+
assert.deepEqual(await store.trackEdit("sc", join(r, "d", "f.txt"), plain, r), { ok: true, minted: true });
|
|
897
|
+
assert.deepEqual(await store.snapshot("sc", "b1", plain, r), { ok: true });
|
|
898
|
+
await rm(join(r, "d", "f.txt"));
|
|
899
|
+
await symlink(join(outside, "secret"), join(r, "d", "f.txt"));
|
|
900
|
+
const seen = [];
|
|
901
|
+
const env = reading(plain, seen);
|
|
902
|
+
if (store.importHistory !== undefined) {
|
|
903
|
+
const linked = wireEnvelope({
|
|
904
|
+
formatVersion: "file-history/1",
|
|
905
|
+
tracked: [{ relOrAbsPath: "link/secret", keyKind: "root-relative", keyFamily: "posix", baseAvailable: true, versions: [{ version: 1, blobHash: null, backupTime: "t" }] }],
|
|
906
|
+
boundaries: [{ entryId: "i1", files: [{ relOrAbsPath: "link/secret", version: 1 }] }],
|
|
907
|
+
});
|
|
908
|
+
assert.deepEqual(await store.importHistory("imported", linked, async () => undefined), { ok: true });
|
|
909
|
+
assert.deepEqual(await store.snapshot("imported", "i2", env, r), { ok: true });
|
|
910
|
+
}
|
|
911
|
+
assert.deepEqual(await store.snapshot("sc", "b2", env, r), { ok: true });
|
|
912
|
+
const leaked = seen.filter((p) => p.startsWith(`${outside}/`) || p.startsWith(`${join(r, "link")}/`) || p === join(r, "d", "f.txt"));
|
|
913
|
+
assert.deepEqual(leaked, [], "no bytes read through a link out of the root");
|
|
914
|
+
});
|
|
915
|
+
});
|
|
916
|
+
});
|
|
917
|
+
run("W1 a second file whose root-relative name another directory's file already keys is tracked under its own absolute key, and a rewind restores it where it was recorded", async () => {
|
|
918
|
+
await withTree(async (a, envA) => {
|
|
919
|
+
await withTree(async (b, envB) => {
|
|
920
|
+
const store = make();
|
|
921
|
+
await writeFile(join(a, "f.txt"), "a-0");
|
|
922
|
+
await writeFile(join(b, "f.txt"), "b-0");
|
|
923
|
+
assert.deepEqual(await store.trackEdit("sc", join(a, "f.txt"), envA, a), { ok: true, minted: true });
|
|
924
|
+
assert.deepEqual(await store.snapshot("sc", "b1", envA, a), { ok: true });
|
|
925
|
+
await writeFile(join(a, "f.txt"), "a-1");
|
|
926
|
+
assert.deepEqual(await store.snapshot("sc", "b2", envB, b), { ok: true });
|
|
927
|
+
assert.deepEqual(await store.trackEdit("sc", join(b, "f.txt"), envB, b), { ok: true, minted: true }, "the second file is a first touch of its own");
|
|
928
|
+
assert.deepEqual(await store.trackEdit("sc", join(b, "g.txt"), envB, b), { ok: true, minted: true });
|
|
929
|
+
await writeFile(join(b, "f.txt"), "b-1");
|
|
930
|
+
await writeFile(join(b, "g.txt"), "b-g");
|
|
931
|
+
const r = await store.restore("sc", "b2", envB, b);
|
|
932
|
+
assert.equal(r.outcome, "complete", JSON.stringify(r));
|
|
933
|
+
assert.equal(await readFile(join(b, "f.txt"), "utf8"), "b-0", "B's own edit is restored at B");
|
|
934
|
+
assert.equal(await existsAt(join(b, "g.txt")), false, "B's created file is removed");
|
|
935
|
+
assert.equal(await readFile(join(a, "f.txt"), "utf8"), "a-1", "A's file is not written by a rewind of B's turn");
|
|
936
|
+
assert.ok(r.filesChanged.includes(join(b, "f.txt")) && r.filesChanged.includes("g.txt"), `the second file answers under its absolute key: ${JSON.stringify(r.filesChanged)}`);
|
|
937
|
+
});
|
|
938
|
+
});
|
|
939
|
+
});
|
|
940
|
+
run("a version that records no directory (an older engine's row) is refused place_unrecorded, unless the rewind names the directory such versions were recorded under — then the one place comparison judges it", async () => {
|
|
941
|
+
await withTree(async (dir, env) => {
|
|
942
|
+
const src = make();
|
|
943
|
+
if (src.exportHistory === undefined || src.importHistory === undefined)
|
|
944
|
+
return;
|
|
945
|
+
const shed = contentShed();
|
|
946
|
+
await shed.write(join(dir, "f.txt"), "pristine");
|
|
947
|
+
const pristine = createHash("sha256").update("pristine").digest("hex");
|
|
948
|
+
const unplaced = wireEnvelope({
|
|
949
|
+
formatVersion: "file-history/1",
|
|
950
|
+
tracked: [{ relOrAbsPath: "f.txt", keyKind: "root-relative", keyFamily: "posix", baseAvailable: true, versions: [{ version: 1, blobHash: pristine, parentIdent: ".", backupTime: new Date(0).toISOString() }] }],
|
|
951
|
+
boundaries: [{ entryId: "b1", files: [{ relOrAbsPath: "f.txt", version: 1 }] }],
|
|
952
|
+
});
|
|
953
|
+
assert.deepEqual(await src.importHistory("old", unplaced, shed.fetch), { ok: true });
|
|
954
|
+
await writeFile(join(dir, "f.txt"), "edited");
|
|
955
|
+
const refused = await src.restore("old", "b1", env, dir);
|
|
956
|
+
assert.deepEqual(refused.refused.map((f) => [f.path, f.class]), [["f.txt", "place_unrecorded"]], JSON.stringify(refused));
|
|
957
|
+
assert.equal(await readFile(join(dir, "f.txt"), "utf8"), "edited");
|
|
958
|
+
await withTree(async (elsewhere) => {
|
|
959
|
+
const named = await src.restore("old", "b1", env, dir, undefined, { unplacedHistoryRecordedUnder: elsewhere });
|
|
960
|
+
assert.deepEqual(named.refused.map((f) => [f.path, f.class]), [["f.txt", "recorded_elsewhere"]], `a named directory that is not this one is the same comparison: ${JSON.stringify(named)}`);
|
|
961
|
+
assert.equal(await readFile(join(dir, "f.txt"), "utf8"), "edited");
|
|
768
962
|
});
|
|
963
|
+
const here = await src.restore("old", "b1", env, dir, undefined, { unplacedHistoryRecordedUnder: dir });
|
|
964
|
+
assert.equal(here.outcome, "complete", JSON.stringify(here));
|
|
965
|
+
assert.equal(await readFile(join(dir, "f.txt"), "utf8"), "pristine");
|
|
769
966
|
});
|
|
770
967
|
});
|
|
771
968
|
run("restore preflight (kind arm, G11): a target replaced by a LEAF SYMLINK or a DIRECTORY is refused by name and the link's own target is untouched", async () => {
|
|
@@ -808,7 +1005,7 @@ export async function fileHistoryStoreContract(make, runAssertion, onOptionalMem
|
|
|
808
1005
|
assert.equal(await store.diffStats("sc", "no-such-boundary", env, dir), null);
|
|
809
1006
|
const quiet = await store.diffStats("sc", "b1", env, dir);
|
|
810
1007
|
assert.notEqual(quiet, null, "a boundary that exists must produce an answer, not an absence");
|
|
811
|
-
assert.deepEqual(quiet, { filesChanged: [], insertions: 0, deletions: 0 });
|
|
1008
|
+
assert.deepEqual({ filesChanged: quiet.filesChanged, insertions: quiet.insertions, deletions: quiet.deletions }, { filesChanged: [], insertions: 0, deletions: 0 });
|
|
812
1009
|
await writeFile(join(dir, "edited.txt"), "one\nTWO\nthree\nfour\n");
|
|
813
1010
|
const preview = await store.diffStats("sc", "b1", env, dir);
|
|
814
1011
|
assert.notEqual(preview, null);
|
|
@@ -68,6 +68,7 @@ declare const SPEC_MEMBER_TABLE: {
|
|
|
68
68
|
instructionFamily: 0;
|
|
69
69
|
restoreFiles: "session";
|
|
70
70
|
acceptPartialRestore: "session";
|
|
71
|
+
unplacedHistoryRecordedUnder: "session";
|
|
71
72
|
rewindFilesTo: "session";
|
|
72
73
|
tools: 0;
|
|
73
74
|
allowTools: 0;
|
|
@@ -142,7 +143,7 @@ declare const SPEC_MEMBER_TABLE: {
|
|
|
142
143
|
export declare const TASK_SPEC_MEMBERS: readonly string[];
|
|
143
144
|
/** The members the table marks as bound to the spec's session — a name here is a member that means something only beside
|
|
144
145
|
* `sessionId` (`requireExistingSession` without one is refused, `resumeAt` / `resumeAtMode` branch the session it names,
|
|
145
|
-
* `restoreFiles` needs the `resumeAt` it restores to, `rewindFilesTo` / `acceptPartialRestore` address its file-history boundaries). */
|
|
146
|
+
* `restoreFiles` needs the `resumeAt` it restores to, `rewindFilesTo` / `acceptPartialRestore` / `unplacedHistoryRecordedUnder` address its file-history boundaries). */
|
|
146
147
|
export type SessionBoundSpecMember = {
|
|
147
148
|
[K in keyof typeof SPEC_MEMBER_TABLE]: (typeof SPEC_MEMBER_TABLE)[K] extends typeof SESSION ? K : never;
|
|
148
149
|
}[keyof typeof SPEC_MEMBER_TABLE];
|
|
@@ -7,7 +7,7 @@ const SPEC_MEMBER_TABLE = {
|
|
|
7
7
|
images: 0, userAttachments: 0, sessionId: SESSION, projectId: 0, workspace: 0, requireExistingSession: SESSION, oneShot: 0, clientContext: 0, resumeAt: SESSION,
|
|
8
8
|
resumeAtMode: SESSION, model: 0, modelRole: 0, roles: 0, compactionModel: 0, advisorModel: 0, thinking: 0, systemPrompt: 0,
|
|
9
9
|
promptRole: 0, promptForm: 0, promptBinding: 0, promptLocale: 0, appendSystemPrompt: 0, outputStyle: 0, memory: 0, suggestNextPrompts: 0, fileHistory: 0,
|
|
10
|
-
projectMemory: 0, instructionFamily: 0, restoreFiles: SESSION, acceptPartialRestore: SESSION, rewindFilesTo: SESSION, tools: 0, allowTools: 0, excludeTools: 0, excludeAllTools: 0,
|
|
10
|
+
projectMemory: 0, instructionFamily: 0, restoreFiles: SESSION, acceptPartialRestore: SESSION, unplacedHistoryRecordedUnder: SESSION, rewindFilesTo: SESSION, tools: 0, allowTools: 0, excludeTools: 0, excludeAllTools: 0,
|
|
11
11
|
deferTools: 0, toolMaterializeStrategy: 0, alwaysLoadTools: 0, restoreGatedTools: 0, deferSelfResolve: 0, promptLean: 0, agents: 0, toolPolicy: 0,
|
|
12
12
|
basePolicyForResumeEdit: 0, onAsk: 0, onQuestion: 0, lspManager: 0, lspDiagnostics: 0, mods: 0, peerPresence: 0, durableApproval: 0,
|
|
13
13
|
resourceSuspend: 0, preemptSignal: 0, resilience: 0, finalVerification: 0, maxSuspends: 0, checkpointStore: 0, handsReadOnly: 0, memoryPersistenceCapable: 0,
|
package/dist/core/task-spec.d.ts
CHANGED
|
@@ -591,6 +591,13 @@ export interface TaskSpec {
|
|
|
591
591
|
* documented recovery either way: re-run the same restore — it is per-file idempotent and converges.
|
|
592
592
|
*/
|
|
593
593
|
acceptPartialRestore?: boolean;
|
|
594
|
+
/**
|
|
595
|
+
* The directory this session's OLDER file versions were recorded under (an engine before 7.68.2 recorded no place): without
|
|
596
|
+
* it they are refused `place_unrecorded`; with it they are judged as recorded there, by the one place comparison (another
|
|
597
|
+
* directory ⇒ `recorded_elsewhere`). An absolute path, in the run's environment; only on a run that restores files, else
|
|
598
|
+
* `rewind.invalid_spec`. A host states it when it knows where every earlier turn ran. `Runner.rewindFiles` takes it too.
|
|
599
|
+
*/
|
|
600
|
+
unplacedHistoryRecordedUnder?: string;
|
|
594
601
|
/**
|
|
595
602
|
* design/101 §E19 R8 + design/381 (CC Rewind `code`-only mode) — converge the tracked set (see
|
|
596
603
|
* {@link restoreFiles} for what that is and is not) to the history boundary of this prior entryId
|
|
@@ -523,6 +523,18 @@ export declare function mintCapabilityId(t: {
|
|
|
523
523
|
contractId: string;
|
|
524
524
|
remote?: string | undefined;
|
|
525
525
|
}): string;
|
|
526
|
+
/** Whether a mount of `source` names a peer (its `origin`): a protocol tool's server or agent, an external tool's. ONE reading — the
|
|
527
|
+
* mount's admission and {@link identityHoldsNoServerName} ask it. */
|
|
528
|
+
export declare function rosterSourceNamesPeer(source: RosterSource): boolean;
|
|
529
|
+
/**
|
|
530
|
+
* Whether a parked approval's tool identity, read off the row's own members, holds no name an MCP server lists a tool under: its
|
|
531
|
+
* `capabilityId` is the identity {@link mintCapabilityId} mints over the row's own `toolName` and `contractId` for a source that names
|
|
532
|
+
* no peer. Only the MCP listing hands a tool a server's name, and every MCP mount names its server as the peer, so such an identity has
|
|
533
|
+
* no `remote` member under any reading — the identity an engine that minted no server name wrote for the tool is the one this engine
|
|
534
|
+
* mints. A row of an MCP tool never answers yes, nor does one whose three members do not recompute (a member changed, a name other than
|
|
535
|
+
* the wire name the identity was minted over). A pure function of the record's own members; total over a record.
|
|
536
|
+
*/
|
|
537
|
+
export declare function identityHoldsNoServerName(pending: object): boolean;
|
|
526
538
|
export declare function rosterDigestOf(entries: readonly ToolRosterEntry[]): string;
|
|
527
539
|
/** The materialized schema's top-level properties, in declaration order. */
|
|
528
540
|
export declare function inputKeysOf(schema: TSchema | undefined): {
|
package/dist/core/tool-roster.js
CHANGED
|
@@ -227,6 +227,17 @@ export function toolDeclarationDigestOf(entry) {
|
|
|
227
227
|
export function mintCapabilityId(t) {
|
|
228
228
|
return sha16(canonicalJsonStringify({ source: t.source, peer: t.peer, name: t.name, contractId: t.contractId, ...(t.remote !== undefined ? { remote: t.remote } : {}) }));
|
|
229
229
|
}
|
|
230
|
+
export function rosterSourceNamesPeer(source) {
|
|
231
|
+
return source === "mcp" || source === "a2a" || source === "external";
|
|
232
|
+
}
|
|
233
|
+
export function identityHoldsNoServerName(pending) {
|
|
234
|
+
const name = Reflect.get(pending, "toolName");
|
|
235
|
+
const contractId = Reflect.get(pending, "contractId");
|
|
236
|
+
const id = Reflect.get(pending, "capabilityId");
|
|
237
|
+
if (typeof name !== "string" || typeof contractId !== "string" || typeof id !== "string")
|
|
238
|
+
return false;
|
|
239
|
+
return ROSTER_SOURCES.some((source) => !rosterSourceNamesPeer(source) && mintCapabilityId({ source, peer: null, name, contractId }) === id);
|
|
240
|
+
}
|
|
230
241
|
export function rosterDigestOf(entries) {
|
|
231
242
|
return sha16(canonicalJsonStringify(entries));
|
|
232
243
|
}
|
|
@@ -432,7 +443,7 @@ export class RosterBuilder {
|
|
|
432
443
|
this.#settleEffects(this.#mountOne(tool, meta, this.#engineLane));
|
|
433
444
|
}
|
|
434
445
|
#admit(tool, meta) {
|
|
435
|
-
if ((meta.source
|
|
446
|
+
if (rosterSourceNamesPeer(meta.source) !== (meta.origin !== undefined)) {
|
|
436
447
|
throw configError("config.tool_roster_origin", `tool ${JSON.stringify(tool.name)}: a ${meta.source} mount ${meta.origin === undefined ? "requires" : "must not carry"} an origin`);
|
|
437
448
|
}
|
|
438
449
|
if (!TOOL_MOUNT_TAGS.includes(meta.mountedBy))
|
package/dist/index.d.ts
CHANGED
|
@@ -178,6 +178,8 @@ export { COMPACTION_FAILURE_CAUSES } from "./core/auto-compaction.js";
|
|
|
178
178
|
export type { CompactionFailureCause } from "./core/auto-compaction.js";
|
|
179
179
|
export { trackKeyOf as fileHistoryTrackKeyOf, resolveTrackKey as fileHistoryResolveTrackKey } from "./core/file-history-store.js";
|
|
180
180
|
export { describeTrackKey as fileHistoryDescribeTrackKey, fileHistoryExportDigest, validateFileHistoryExport } from "./core/file-history-store.js";
|
|
181
|
+
export { resolveTrackedFile as fileHistoryResolveTrackedFile, placeProvenDifferent as fileHistoryPlaceProvenDifferent, trackKeyForEdit as fileHistoryTrackKeyForEdit, trackKeyForAnnul as fileHistoryTrackKeyForAnnul, fileHistoryEntryTravels, fileHistoryParentIdentTravels } from "./core/file-history-store.js";
|
|
182
|
+
export type { FileHistoryRewindFile, FileHistoryRestoreOptions } from "./core/file-history-store.js";
|
|
181
183
|
export { fileHistoryBlobExchangeOf } from "./core/file-history-store.js";
|
|
182
184
|
export type { FileHistoryBlobExchange } from "./core/file-history-store.js";
|
|
183
185
|
export type { FileHistoryStore, FileHistoryResult, FileHistoryTrackResult, FileHistoryError, FileHistoryKeyFamily, FileHistoryTrackKeyDescriptor, FileHistoryRestoreResult, FileHistoryDiffStats, FileHistoryExport, FileHistoryExportResult, FileBackupCapture, FileRestoreTarget, FileRestoreApplyOptions, FileRestoreApplyOutcome, FileHistoryTrackKeyResolution } from "./core/file-history-store.js";
|