@sema-agent/core 7.68.1 → 7.68.3
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 +49 -0
- package/dist/agents/repair-loop.js +1 -1
- package/dist/agents/verify.js +1 -1
- 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 +31 -18
- package/dist/core/task-spec-members.js +11 -8
- package/dist/core/task-spec.d.ts +7 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/orchestration/goal.js +3 -1
- 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.2.json +39 -0
- package/wire-changes/core-stores-sql@7.68.3.json +39 -0
- package/wire-changes/core@7.68.2.json +612 -0
- package/wire-changes/core@7.68.3.json +125 -0
- package/wire-changes/mods-kernel@7.68.2.json +39 -0
- package/wire-changes/mods-kernel@7.68.3.json +39 -0
- package/wire-changes/primitives@7.68.2.json +39 -0
- package/wire-changes/primitives@7.68.3.json +39 -0
- package/wire-changes/wiki-gate@7.68.2.json +39 -0
- package/wire-changes/wiki-gate@7.68.3.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);
|
|
@@ -20,17 +20,21 @@
|
|
|
20
20
|
* object): it compares objects, it does not take a value.
|
|
21
21
|
*/
|
|
22
22
|
import type { TaskSpec } from "./task-spec.js";
|
|
23
|
-
/** The
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
/** The two non-placeholder values of the member table's column — the member lives and dies with `sessionId`, so a run that is
|
|
24
|
+
* handed a new session of its own carries neither kind:
|
|
25
|
+
* - {@link SESSION}: the session's address and the run's demand on it (the session to continue, the requirement that it exists);
|
|
26
|
+
* - {@link ENTRY}: an operation a run performs on ENTERING that session — branch it at an entry, converge its files to a history
|
|
27
|
+
* boundary (and how), open on what is parked for it. The leg that enters performs it once; a later leg in the session an earlier
|
|
28
|
+
* leg of the same call entered carries none of them. */
|
|
26
29
|
declare const SESSION: "session";
|
|
30
|
+
declare const ENTRY: "entry";
|
|
27
31
|
/** Every {@link TaskSpec} member, by name — the type's own key set, fenced both ways (a member added to `TaskSpec` and not
|
|
28
32
|
* listed here, or a name here that `TaskSpec` does not declare, is a compile error). The value is a column: `0` for an
|
|
29
|
-
* ordinary member, {@link SESSION} for one that is bound to the spec's session. */
|
|
33
|
+
* ordinary member, {@link SESSION} or {@link ENTRY} for one that is bound to the spec's session. */
|
|
30
34
|
declare const SPEC_MEMBER_TABLE: {
|
|
31
35
|
taskId: 0;
|
|
32
36
|
objective: 0;
|
|
33
|
-
wake: "
|
|
37
|
+
wake: "entry";
|
|
34
38
|
principal: 0;
|
|
35
39
|
isolationScope: 0;
|
|
36
40
|
actor: 0;
|
|
@@ -46,8 +50,8 @@ declare const SPEC_MEMBER_TABLE: {
|
|
|
46
50
|
requireExistingSession: "session";
|
|
47
51
|
oneShot: 0;
|
|
48
52
|
clientContext: 0;
|
|
49
|
-
resumeAt: "
|
|
50
|
-
resumeAtMode: "
|
|
53
|
+
resumeAt: "entry";
|
|
54
|
+
resumeAtMode: "entry";
|
|
51
55
|
model: 0;
|
|
52
56
|
modelRole: 0;
|
|
53
57
|
roles: 0;
|
|
@@ -66,9 +70,10 @@ declare const SPEC_MEMBER_TABLE: {
|
|
|
66
70
|
fileHistory: 0;
|
|
67
71
|
projectMemory: 0;
|
|
68
72
|
instructionFamily: 0;
|
|
69
|
-
restoreFiles: "
|
|
70
|
-
acceptPartialRestore: "
|
|
71
|
-
|
|
73
|
+
restoreFiles: "entry";
|
|
74
|
+
acceptPartialRestore: "entry";
|
|
75
|
+
unplacedHistoryRecordedUnder: "entry";
|
|
76
|
+
rewindFilesTo: "entry";
|
|
72
77
|
tools: 0;
|
|
73
78
|
allowTools: 0;
|
|
74
79
|
excludeTools: 0;
|
|
@@ -140,14 +145,16 @@ declare const SPEC_MEMBER_TABLE: {
|
|
|
140
145
|
};
|
|
141
146
|
/** Every {@link TaskSpec} member, by name. */
|
|
142
147
|
export declare const TASK_SPEC_MEMBERS: readonly string[];
|
|
143
|
-
/** The members the table marks as bound to the spec's session — a name here is a member that means something only
|
|
144
|
-
* `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). */
|
|
148
|
+
/** The members the table marks as bound to the spec's session (either kind) — a name here is a member that means something only
|
|
149
|
+
* beside `sessionId` (`requireExistingSession` without one is refused, `resumeAt` / `resumeAtMode` branch the session it names,
|
|
150
|
+
* `restoreFiles` needs the `resumeAt` it restores to, `rewindFilesTo` / `acceptPartialRestore` / `unplacedHistoryRecordedUnder` address its file-history boundaries). */
|
|
146
151
|
export type SessionBoundSpecMember = {
|
|
147
|
-
[K in keyof typeof SPEC_MEMBER_TABLE]: (typeof SPEC_MEMBER_TABLE)[K] extends typeof SESSION ? K : never;
|
|
152
|
+
[K in keyof typeof SPEC_MEMBER_TABLE]: (typeof SPEC_MEMBER_TABLE)[K] extends typeof SESSION | typeof ENTRY ? K : never;
|
|
148
153
|
}[keyof typeof SPEC_MEMBER_TABLE];
|
|
149
154
|
/** The session-bound members, in table order. */
|
|
150
155
|
export declare const SESSION_BOUND_SPEC_MEMBERS: readonly SessionBoundSpecMember[];
|
|
156
|
+
/** The session-bound members of the {@link ENTRY} kind — the operations a run performs on entering its session — in table order. */
|
|
157
|
+
export declare const SESSION_ENTRY_SPEC_MEMBERS: readonly SessionBoundSpecMember[];
|
|
151
158
|
/**
|
|
152
159
|
* The spec for a run that gets a session of its own: the caller's spec without every session-bound member, by the table (never
|
|
153
160
|
* by a name written at the call site), so a member added to the column is dropped here too. A shallow copy — every other member
|
|
@@ -155,11 +162,17 @@ export declare const SESSION_BOUND_SPEC_MEMBERS: readonly SessionBoundSpecMember
|
|
|
155
162
|
*/
|
|
156
163
|
export declare function withoutSessionBinding(spec: TaskSpec): Omit<TaskSpec, SessionBoundSpecMember>;
|
|
157
164
|
/**
|
|
158
|
-
* The spec of a leg
|
|
159
|
-
*
|
|
160
|
-
*
|
|
165
|
+
* The spec of a leg a composition opens on an objective of its own, from the caller's spec. A leg opens on exactly one input (the
|
|
166
|
+
* door refuses `wake` beside an objective), and the objective is this one's.
|
|
167
|
+
* - Without `continues`: the leg that ENTERS the caller's session (a resumed repair loop's first attempt) — every member of the column
|
|
168
|
+
* stays but `wake`.
|
|
169
|
+
* - With `continues`: a LATER leg, in the session an earlier leg of the same call entered (a fix leg, a later repair attempt, a later
|
|
170
|
+
* goal iteration) — the leg runs in `continues`, and every {@link ENTRY} member is dropped, by the table: the earlier leg performed
|
|
171
|
+
* those on entering, and carried into a later leg each would be performed again (a rewind written back over the earlier legs' files,
|
|
172
|
+
* a branch that drops their turns). The {@link SESSION} members other than the address stay as the caller wrote them.
|
|
173
|
+
* A member added to the column is read here as its kind says. A shallow copy, as {@link withoutSessionBinding}.
|
|
161
174
|
*/
|
|
162
|
-
export declare function withOpeningObjective(spec: Omit<TaskSpec, "objective">, objective: string): TaskSpec;
|
|
175
|
+
export declare function withOpeningObjective(spec: Omit<TaskSpec, "objective">, objective: string, continues?: string): TaskSpec;
|
|
163
176
|
/** What one read of a caller's spec answered: the snapshot every reader reads, the caller's own object (for the roster's identity
|
|
164
177
|
* check only), and the refusal the read met (thrown at prepare's door), if any. */
|
|
165
178
|
export interface CallerSpecRead<S extends Partial<TaskSpec> = TaskSpec> {
|