@bastani/atomic 0.9.84 → 0.9.85
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 +64 -0
- package/dist/builtin/intercom/CHANGELOG.md +16 -0
- package/dist/builtin/intercom/broker/broker.ts +25 -7
- package/dist/builtin/intercom/broker/spawn.ts +83 -17
- package/dist/builtin/intercom/index.bundle.mjs +89 -26
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +16 -0
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/authoring.d.ts +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +48 -9
- package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +48 -9
- package/dist/builtin/workflows/src/index.js +48 -9
- package/dist/builtin/workflows/src/local-worker-entry.mjs +48 -9
- package/dist/config.d.ts +3 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -3
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-export.d.ts +2 -2
- package/dist/core/agent-session-export.d.ts.map +1 -1
- package/dist/core/agent-session-export.js +4 -5
- package/dist/core/agent-session-export.js.map +1 -1
- package/dist/core/agent-session-services.js +1 -1
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session-summary.d.ts.map +1 -1
- package/dist/core/agent-session-summary.js +8 -1
- package/dist/core/agent-session-summary.js.map +1 -1
- package/dist/core/agent-session-tree.d.ts.map +1 -1
- package/dist/core/agent-session-tree.js +3 -6
- package/dist/core/agent-session-tree.js.map +1 -1
- package/dist/core/builtin-resource-loader.d.ts.map +1 -1
- package/dist/core/builtin-resource-loader.js +1 -1
- package/dist/core/builtin-resource-loader.js.map +1 -1
- package/dist/core/extensions/loader-core.d.ts +6 -2
- package/dist/core/extensions/loader-core.d.ts.map +1 -1
- package/dist/core/extensions/loader-core.js +13 -9
- package/dist/core/extensions/loader-core.js.map +1 -1
- package/dist/core/extensions/loader-discovery.js +1 -1
- package/dist/core/extensions/loader-discovery.js.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.d.ts +20 -14
- package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.js +133 -78
- package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
- package/dist/core/extensions/ts-source-specifiers.d.ts +1 -0
- package/dist/core/extensions/ts-source-specifiers.d.ts.map +1 -1
- package/dist/core/extensions/ts-source-specifiers.js +18 -2
- package/dist/core/extensions/ts-source-specifiers.js.map +1 -1
- package/dist/core/mandatory-resource-loader.d.ts +5 -2
- package/dist/core/mandatory-resource-loader.d.ts.map +1 -1
- package/dist/core/mandatory-resource-loader.js +17 -12
- package/dist/core/mandatory-resource-loader.js.map +1 -1
- package/dist/core/model-fallback-failures.d.ts.map +1 -1
- package/dist/core/model-fallback-failures.js +10 -3
- package/dist/core/model-fallback-failures.js.map +1 -1
- package/dist/core/resource-loader-extensions.d.ts.map +1 -1
- package/dist/core/resource-loader-extensions.js +1 -1
- package/dist/core/resource-loader-extensions.js.map +1 -1
- package/dist/core/resource-loader-reload.js +1 -1
- package/dist/core/resource-loader-reload.js.map +1 -1
- package/dist/core/resume/blueprint/resume.d.ts +4 -4
- package/dist/core/resume/blueprint/resume.js +4 -4
- package/dist/core/resume/blueprint/resume.js.map +1 -1
- package/dist/core/resume/session-resume.d.ts +6 -3
- package/dist/core/resume/session-resume.d.ts.map +1 -1
- package/dist/core/resume/session-resume.js +159 -37
- package/dist/core/resume/session-resume.js.map +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager-core.d.ts +10 -4
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +23 -6
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-entries.d.ts +2 -2
- package/dist/core/session-manager-entries.d.ts.map +1 -1
- package/dist/core/session-manager-entries.js +2 -1
- package/dist/core/session-manager-entries.js.map +1 -1
- package/dist/core/session-manager-history.d.ts +13 -1
- package/dist/core/session-manager-history.d.ts.map +1 -1
- package/dist/core/session-manager-history.js +21 -1
- package/dist/core/session-manager-history.js.map +1 -1
- package/dist/core/session-manager-types.d.ts +3 -1
- package/dist/core/session-manager-types.d.ts.map +1 -1
- package/dist/core/session-manager-types.js.map +1 -1
- package/dist/core/session-manager.d.ts +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +1 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/session-worktree-snapshots.d.ts +61 -4
- package/dist/core/session-worktree-snapshots.d.ts.map +1 -1
- package/dist/core/session-worktree-snapshots.js +261 -28
- package/dist/core/session-worktree-snapshots.js.map +1 -1
- package/dist/core/storage/session/entry-structure.js +31 -1
- package/dist/core/storage/session/entry-structure.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/build-questionnaire.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/build-questionnaire.js +2 -1
- package/dist/core/tools/ask-user-question/state/build-questionnaire.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/questionnaire-session.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/questionnaire-session.js +2 -0
- package/dist/core/tools/ask-user-question/state/questionnaire-session.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/field-tone.d.ts +26 -0
- package/dist/core/tools/ask-user-question/state/selectors/field-tone.d.ts.map +1 -0
- package/dist/core/tools/ask-user-question/state/selectors/field-tone.js +27 -0
- package/dist/core/tools/ask-user-question/state/selectors/field-tone.js.map +1 -0
- package/dist/core/tools/ask-user-question/state/selectors/projections.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/projections.js +1 -0
- package/dist/core/tools/ask-user-question/state/selectors/projections.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/state-reducer.js +1 -1
- package/dist/core/tools/ask-user-question/state/state-reducer.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.js +6 -6
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts +5 -3
- package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.js +14 -4
- package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.d.ts +2 -0
- package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.js +3 -3
- package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.d.ts +16 -6
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.js +42 -24
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/tab-content-strategy.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/view/tab-content-strategy.js +12 -3
- package/dist/core/tools/ask-user-question/view/tab-content-strategy.js.map +1 -1
- package/dist/core/tools/read.d.ts +1 -0
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +13 -14
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/worktree-snapshot/index.d.ts +2 -2
- package/dist/core/worktree-snapshot/index.d.ts.map +1 -1
- package/dist/core/worktree-snapshot/index.js +1 -1
- package/dist/core/worktree-snapshot/index.js.map +1 -1
- package/dist/core/worktree-snapshot/records.d.ts +6 -0
- package/dist/core/worktree-snapshot/records.d.ts.map +1 -1
- package/dist/core/worktree-snapshot/records.js +18 -4
- package/dist/core/worktree-snapshot/records.js.map +1 -1
- package/dist/core/worktree-snapshot/restore.d.ts +24 -1
- package/dist/core/worktree-snapshot/restore.d.ts.map +1 -1
- package/dist/core/worktree-snapshot/restore.js +443 -72
- package/dist/core/worktree-snapshot/restore.js.map +1 -1
- package/dist/core/worktree-snapshot/types.d.ts +44 -0
- package/dist/core/worktree-snapshot/types.d.ts.map +1 -1
- package/dist/core/worktree-snapshot/types.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +2 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.js +4 -1
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +8 -0
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-handler.js +11 -2
- package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
- package/dist/modes/rpc/rpc-command-timeouts.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-command-timeouts.js +1 -0
- package/dist/modes/rpc/rpc-command-timeouts.js.map +1 -1
- package/dist/modes/rpc/rpc-input-scheduler.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-input-scheduler.js +1 -0
- package/dist/modes/rpc/rpc-input-scheduler.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +11 -1
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/docs/environment-variables.md +1 -1
- package/docs/guides/resume-on-any-machine.md +6 -4
- package/docs/intercom/operations.md +4 -0
- package/docs/rpc/protocol.md +2 -2
- package/docs/sdk/reference.md +3 -0
- package/docs/sdk.md +2 -2
- package/docs/session-format.md +11 -2
- package/docs/sessions.md +4 -2
- package/docs/settings.md +1 -1
- package/docs/workflows/api-reference.md +2 -2
- package/docs/worktree-snapshots.md +13 -5
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
1
2
|
import { stat } from "node:fs/promises";
|
|
2
3
|
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
3
|
-
import { getBranchPath } from "./session-manager-history.js";
|
|
4
|
+
import { getBranchPath, getSessionLeafId } from "./session-manager-history.js";
|
|
4
5
|
import { snapshotBlobHashes } from "./worktree-snapshot/blob-store.js";
|
|
5
6
|
import { captureWorktreeSnapshot, locateCheckout, withScratchDirectory, writeWorkingTree, } from "./worktree-snapshot/capture.js";
|
|
6
7
|
import { sha256Hex } from "./worktree-snapshot/env-hash.js";
|
|
7
|
-
import { findWorkspaceError, isGitUnavailableError, isWorkspaceDriftError, isWorkspaceSnapshotError, unreadablePathError, WorkspaceDriftError, WorkspaceRestoreError, WorkspaceSnapshotError, } from "./worktree-snapshot/errors.js";
|
|
8
|
+
import { findWorkspaceError, isGitUnavailableError, isWorkspaceDriftError, isWorkspaceError, isWorkspaceRestoreError, isWorkspaceSnapshotError, unreadablePathError, WorkspaceDriftError, WorkspaceRestoreError, WorkspaceSnapshotError, } from "./worktree-snapshot/errors.js";
|
|
8
9
|
import { scheduleSnapshotCollection } from "./worktree-snapshot/garbage.js";
|
|
9
10
|
import { gitText, runGit } from "./worktree-snapshot/git.js";
|
|
10
11
|
import { isHeadOnlyAdvance } from "./worktree-snapshot/head-advance.js";
|
|
11
12
|
import { canonicalizeWorktreePath } from "./worktree-snapshot/paths.js";
|
|
12
13
|
import { loadSnapshotPathPolicy } from "./worktree-snapshot/policy.js";
|
|
13
|
-
import { removeRestoredWorktree, restoreWorktree, snapshotRestoreWarnings, verifyWorktree, } from "./worktree-snapshot/restore.js";
|
|
14
|
+
import { isDegradableRestoreFailure, removeRestoredWorktree, restoreDegradedWorktree, restoreWorktree, snapshotRestoreWarnings, verifyWorktree, } from "./worktree-snapshot/restore.js";
|
|
14
15
|
/** Built-in tools that can change files: a turn that called one records a snapshot. */
|
|
15
16
|
export const FILE_WRITING_TOOLS = new Set(["bash", "edit", "write", "powershell"]);
|
|
16
17
|
const PATH_TOOLS = new Set(["edit", "write"]);
|
|
@@ -181,6 +182,17 @@ function latestSnapshotIdsByCheckout(sessionManager, mappings) {
|
|
|
181
182
|
}
|
|
182
183
|
return latestIds;
|
|
183
184
|
}
|
|
185
|
+
/** The checkouts on the active branch whose latest snapshot the session holds no record of, where they are now (#4733). */
|
|
186
|
+
export function missingSnapshotRecords(sessionManager) {
|
|
187
|
+
const mappings = sessionManager.getWorktreeRootMappings();
|
|
188
|
+
const records = sessionManager.getWorktreeSnapshotRecords();
|
|
189
|
+
const missing = [];
|
|
190
|
+
for (const [original, snapshotId] of latestSnapshotIdsByCheckout(sessionManager, mappings)) {
|
|
191
|
+
if (!records.has(snapshotId))
|
|
192
|
+
missing.push({ root: mapRestoredPath(original, mappings), snapshotId });
|
|
193
|
+
}
|
|
194
|
+
return missing;
|
|
195
|
+
}
|
|
184
196
|
/**
|
|
185
197
|
* The latest snapshot of each checkout on the active branch, keyed by where that checkout is now: a checkout restored
|
|
186
198
|
* elsewhere appears once, under its newest location. A snapshot whose record is missing is left out.
|
|
@@ -196,6 +208,66 @@ export function currentWorktreeSnapshots(sessionManager) {
|
|
|
196
208
|
}
|
|
197
209
|
return current;
|
|
198
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Whether a failed restore of one checkout leaves the resume able to continue without the exact state (#4733): any
|
|
213
|
+
* typed workspace or Git failure, except a snapshot record that fails the security checks (`invalid-snapshot`) and a
|
|
214
|
+
* target that holds other files (`unsafe-target`), which refuse the resume.
|
|
215
|
+
*/
|
|
216
|
+
export function isRecoverableRestoreFailure(error) {
|
|
217
|
+
if (isWorkspaceRestoreError(error) && (error.code === "invalid-snapshot" || error.code === "unsafe-target")) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
return (isWorkspaceError(error) && error.code !== "invalid-setting") || isGitUnavailableError(error);
|
|
221
|
+
}
|
|
222
|
+
/** The commits of the checkout's earlier snapshots on the branch, newest first, to restore when its own is out of reach. */
|
|
223
|
+
function earlierSnapshotHeads(sessionManager, original, mappings, snapshot) {
|
|
224
|
+
const records = sessionManager.getWorktreeSnapshotRecords();
|
|
225
|
+
const heads = [];
|
|
226
|
+
for (const entry of [...sessionManager.getBranch()].reverse()) {
|
|
227
|
+
if (entry.type !== "worktree_snapshot" || originalRoot(entry.root, mappings) !== original)
|
|
228
|
+
continue;
|
|
229
|
+
const head = records.get(entry.snapshotId)?.head;
|
|
230
|
+
if (head !== undefined && head !== snapshot.head && !heads.includes(head))
|
|
231
|
+
heads.push(head);
|
|
232
|
+
if (heads.length === 3)
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
return heads;
|
|
236
|
+
}
|
|
237
|
+
/** What a resume tells about a checkout it continued without: why, as a clause, and what to do. */
|
|
238
|
+
function unrestoredReason(snapshot, reason) {
|
|
239
|
+
const head = snapshot.head.slice(0, 12);
|
|
240
|
+
if (isGitUnavailableError(reason)) {
|
|
241
|
+
return {
|
|
242
|
+
detail: `Git is unavailable here (${reason.code}), which checking and restoring it need`,
|
|
243
|
+
hint: reason.hint ?? "",
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
if (isWorkspaceRestoreError(reason)) {
|
|
247
|
+
switch (reason.code) {
|
|
248
|
+
case "commits-unavailable":
|
|
249
|
+
return {
|
|
250
|
+
detail: reason.reason === "denied-history"
|
|
251
|
+
? `its commit ${head} is not on its recorded remotes, and its unpushed commits touch files snapshots never copy`
|
|
252
|
+
: reason.reason === "bundle-over-cap"
|
|
253
|
+
? `its commit ${head} is not on its recorded remotes, and its unpushed commits were too large to record`
|
|
254
|
+
: `its commit ${head} and the commits around it are not on its recorded remotes`,
|
|
255
|
+
hint: reason.hint,
|
|
256
|
+
};
|
|
257
|
+
case "snapshot-not-found":
|
|
258
|
+
return { detail: "the session holds no record of its snapshot", hint: reason.hint };
|
|
259
|
+
case "blob-missing":
|
|
260
|
+
case "blob-corrupt":
|
|
261
|
+
return { detail: "part of its recorded content is not in this storage", hint: reason.hint };
|
|
262
|
+
default:
|
|
263
|
+
return { detail: reason.summary, hint: reason.hint };
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
detail: isWorkspaceError(reason) ? reason.summary : reason.message,
|
|
268
|
+
hint: isWorkspaceError(reason) ? reason.hint : "",
|
|
269
|
+
};
|
|
270
|
+
}
|
|
199
271
|
/**
|
|
200
272
|
* Checks the latest recorded snapshot of each checkout on the active session branch. Drifted or missing checkouts are
|
|
201
273
|
* restored into fresh worktrees, and each old→new mapping is recorded only after all checkouts have been restored.
|
|
@@ -209,19 +281,27 @@ export async function resumeSessionWorktree(sessionManager, options) {
|
|
|
209
281
|
const records = sessionManager.getWorktreeSnapshotRecords();
|
|
210
282
|
const latestIds = latestSnapshotIdsByCheckout(sessionManager, existing);
|
|
211
283
|
const latest = new Map();
|
|
284
|
+
const missingRecords = [];
|
|
212
285
|
for (const [root, snapshotId] of latestIds) {
|
|
213
286
|
const snapshot = records.get(snapshotId);
|
|
287
|
+
if (!snapshot && options.skipMissingRecords) {
|
|
288
|
+
missingRecords.push({ root: mapRestoredPath(root, existing), snapshotId });
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
214
291
|
if (!snapshot)
|
|
215
292
|
throw new WorkspaceRestoreError("snapshot-not-found", { snapshotId, target: root });
|
|
216
293
|
latest.set(root, snapshot);
|
|
217
294
|
}
|
|
218
295
|
if (latest.size === 0)
|
|
219
|
-
return { status: "none" };
|
|
296
|
+
return missingRecords.length === 0 ? { status: "none" } : { status: "none", missingRecords };
|
|
220
297
|
const cwd = mapRestoredPath(sessionManager.getCwd(), existing);
|
|
221
298
|
const mappings = [];
|
|
222
299
|
const warnings = [];
|
|
223
300
|
const hostWarnings = new Map();
|
|
224
301
|
const reportedLeftovers = new Set();
|
|
302
|
+
const left = [];
|
|
303
|
+
const unrestored = [];
|
|
304
|
+
let continuedIn;
|
|
225
305
|
let selected;
|
|
226
306
|
try {
|
|
227
307
|
for (const [original, snapshot] of latest) {
|
|
@@ -231,6 +311,11 @@ export async function resumeSessionWorktree(sessionManager, options) {
|
|
|
231
311
|
selected = { root, snapshot };
|
|
232
312
|
if (options.keepInPlace?.has(root))
|
|
233
313
|
continue;
|
|
314
|
+
const cannot = options.cannotRestore?.get(root);
|
|
315
|
+
if (cannot !== undefined) {
|
|
316
|
+
left.push({ root, snapshot, reason: cannot });
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
234
319
|
let drift;
|
|
235
320
|
try {
|
|
236
321
|
await verifyWorktree(snapshot, root, { settings: options.settings, signal: options.signal });
|
|
@@ -256,27 +341,50 @@ export async function resumeSessionWorktree(sessionManager, options) {
|
|
|
256
341
|
else
|
|
257
342
|
throw error;
|
|
258
343
|
}
|
|
344
|
+
const refused = (error) => new WorkspaceDriftError({
|
|
345
|
+
root: drift.root,
|
|
346
|
+
expectedHead: drift.expectedHead,
|
|
347
|
+
actualHead: drift.actualHead,
|
|
348
|
+
expectedTree: drift.expectedTree,
|
|
349
|
+
actualTree: drift.actualTree,
|
|
350
|
+
snapshotId: drift.snapshotId,
|
|
351
|
+
reason: "restore-failed",
|
|
352
|
+
}, error);
|
|
353
|
+
const blobs = sessionSnapshotBlobs(sessionManager.getSessionStore().snapshotBlobs, sessionManager.getEntries());
|
|
259
354
|
let restored;
|
|
260
355
|
try {
|
|
261
|
-
restored = await restoreWorktree(snapshot, {
|
|
262
|
-
blobs: sessionSnapshotBlobs(sessionManager.getSessionStore().snapshotBlobs, sessionManager.getEntries()),
|
|
263
|
-
storeDir: options.storeDir,
|
|
264
|
-
signal: options.signal,
|
|
265
|
-
});
|
|
356
|
+
restored = await restoreWorktree(snapshot, { blobs, storeDir: options.storeDir, signal: options.signal });
|
|
266
357
|
}
|
|
267
358
|
catch (error) {
|
|
268
359
|
options.signal?.throwIfAborted();
|
|
269
360
|
if (!(error instanceof Error))
|
|
270
361
|
throw error;
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
362
|
+
if (!isRecoverableRestoreFailure(error))
|
|
363
|
+
throw refused(error);
|
|
364
|
+
// The exact state is out of reach: restore the best this host can, else continue without the checkout.
|
|
365
|
+
let degraded;
|
|
366
|
+
if (isDegradableRestoreFailure(error)) {
|
|
367
|
+
try {
|
|
368
|
+
degraded = await restoreDegradedWorktree(snapshot, error, {
|
|
369
|
+
blobs,
|
|
370
|
+
storeDir: options.storeDir,
|
|
371
|
+
signal: options.signal,
|
|
372
|
+
candidates: earlierSnapshotHeads(sessionManager, original, existing, snapshot),
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
catch (degradedError) {
|
|
376
|
+
options.signal?.throwIfAborted();
|
|
377
|
+
if (!(degradedError instanceof Error))
|
|
378
|
+
throw degradedError;
|
|
379
|
+
if (!isRecoverableRestoreFailure(degradedError))
|
|
380
|
+
throw refused(degradedError);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (degraded === undefined) {
|
|
384
|
+
left.push({ root, snapshot, reason: error });
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
restored = degraded;
|
|
280
388
|
}
|
|
281
389
|
const mapping = {
|
|
282
390
|
from: root,
|
|
@@ -284,6 +392,7 @@ export async function resumeSessionWorktree(sessionManager, options) {
|
|
|
284
392
|
snapshotId: snapshot.id,
|
|
285
393
|
tree: snapshot.tree,
|
|
286
394
|
restoredAt: new Date().toISOString(),
|
|
395
|
+
...(restored.degraded === undefined ? {} : { degraded: restored.degraded }),
|
|
287
396
|
};
|
|
288
397
|
mappings.push(mapping);
|
|
289
398
|
warnings.push(...restored.warnings);
|
|
@@ -301,6 +410,28 @@ export async function resumeSessionWorktree(sessionManager, options) {
|
|
|
301
410
|
options.signal?.throwIfAborted();
|
|
302
411
|
await sessionManager.appendWorktreeSnapshot(mapping.to, mapping.snapshotId, undefined, mapping, hostWarnings.get(mapping));
|
|
303
412
|
}
|
|
413
|
+
const continuing = mapRestoredPath(cwd, mappings);
|
|
414
|
+
const recordedHere = selected !== undefined && left.some((checkout) => checkout.root === selected.root);
|
|
415
|
+
const launch = recordedHere && !existsSync(continuing) && options.fallbackCwd !== undefined;
|
|
416
|
+
continuedIn = launch ? resolve(options.fallbackCwd) : continuing;
|
|
417
|
+
for (const checkout of left) {
|
|
418
|
+
const at = new Date().toISOString();
|
|
419
|
+
const record = {
|
|
420
|
+
snapshotId: checkout.snapshot.id,
|
|
421
|
+
continuedIn,
|
|
422
|
+
place: launch ? "launch" : "recorded",
|
|
423
|
+
cause: isWorkspaceError(checkout.reason) || isGitUnavailableError(checkout.reason)
|
|
424
|
+
? checkout.reason.code
|
|
425
|
+
: "error",
|
|
426
|
+
...(isWorkspaceRestoreError(checkout.reason) && checkout.reason.reason !== undefined
|
|
427
|
+
? { causeReason: String(checkout.reason.reason) }
|
|
428
|
+
: {}),
|
|
429
|
+
...unrestoredReason(checkout.snapshot, checkout.reason),
|
|
430
|
+
at,
|
|
431
|
+
};
|
|
432
|
+
await sessionManager.appendWorktreeSnapshot(checkout.root, checkout.snapshot.id, undefined, undefined, [], record);
|
|
433
|
+
unrestored.push({ ...checkout, record });
|
|
434
|
+
}
|
|
304
435
|
}
|
|
305
436
|
catch (error) {
|
|
306
437
|
const cleanupFailures = [];
|
|
@@ -321,10 +452,10 @@ export async function resumeSessionWorktree(sessionManager, options) {
|
|
|
321
452
|
throw error;
|
|
322
453
|
}
|
|
323
454
|
const snapshot = selected?.snapshot ?? [...latest.values()].at(-1);
|
|
324
|
-
const
|
|
455
|
+
const missing = missingRecords.length === 0 ? {} : { missingRecords };
|
|
325
456
|
return mappings.length === 0
|
|
326
|
-
? { status: "verified", snapshot, cwd:
|
|
327
|
-
: { status: "restored", snapshot, mappings, cwd:
|
|
457
|
+
? { status: "verified", snapshot, cwd: continuedIn, unrestored, ...missing }
|
|
458
|
+
: { status: "restored", snapshot, mappings, cwd: continuedIn, warnings, unrestored, ...missing };
|
|
328
459
|
}
|
|
329
460
|
/** The one-line notice shown when a session or run continues in a restored worktree. */
|
|
330
461
|
export function formatWorktreeRestoreNotice(mapping) {
|
|
@@ -358,19 +489,87 @@ export function formatWorktreeRestoreWarning(warning) {
|
|
|
358
489
|
}
|
|
359
490
|
}
|
|
360
491
|
}
|
|
492
|
+
/** The first 12 characters of a commit or snapshot id, as notices show them. */
|
|
493
|
+
function short(id) {
|
|
494
|
+
return id.slice(0, 12);
|
|
495
|
+
}
|
|
496
|
+
/** What a degraded restore checked out, for its notice. */
|
|
497
|
+
function degradedBasis(degraded, snapshot) {
|
|
498
|
+
switch (degraded.basis) {
|
|
499
|
+
case "pushed-base":
|
|
500
|
+
return `the last pushed commit before it, ${short(degraded.head)}`;
|
|
501
|
+
case "earlier-snapshot":
|
|
502
|
+
return `${short(degraded.head)}, the commit of an earlier snapshot of this session`;
|
|
503
|
+
default:
|
|
504
|
+
return `${short(degraded.head)}, the tip of ${snapshot?.branch ? `branch ${snapshot.branch}` : "the default branch"} on its remote`;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
function listed(items, limit = 5) {
|
|
508
|
+
return items.length <= limit
|
|
509
|
+
? items.join(", ")
|
|
510
|
+
: `${items.slice(0, limit).join(", ")} and ${items.length - limit} more`;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* The one notice for a worktree restored with less than its snapshot (#4733): what it holds, what is missing and what
|
|
514
|
+
* to do to get the rest.
|
|
515
|
+
*/
|
|
516
|
+
export function formatDegradedRestoreNotice(mapping, snapshot, warnings = []) {
|
|
517
|
+
const lfs = warnings
|
|
518
|
+
.filter((warning) => warning.code === "lfs-objects-unavailable")
|
|
519
|
+
.map((warning) => ` ${formatWorktreeRestoreWarning(warning)}.`)
|
|
520
|
+
.join("");
|
|
521
|
+
return `${degradedRestoreSummary(mapping, snapshot)}${lfs}`;
|
|
522
|
+
}
|
|
523
|
+
function degradedRestoreSummary(mapping, snapshot) {
|
|
524
|
+
const degraded = mapping.degraded;
|
|
525
|
+
const links = snapshot?.chain.length ?? 0;
|
|
526
|
+
const restored = `Restored ${mapping.from} into ${mapping.to}`;
|
|
527
|
+
const missingPaths = degraded.missingPaths.length > 0 ? `: ${listed(degraded.missingPaths)}` : "";
|
|
528
|
+
if (degraded.stage === "partial-changes") {
|
|
529
|
+
const missing = degraded.missingLinks.length > 0
|
|
530
|
+
? `change set${degraded.missingLinks.length === 1 ? "" : "s"} ${degraded.missingLinks.join(", ")}${missingPaths}`
|
|
531
|
+
: `the recorded content of ${listed(degraded.missingPaths)}, which differs on this machine`;
|
|
532
|
+
return `${restored} at its recorded commit ${short(degraded.head)} with ${links - degraded.missingLinks.length} of the ${links} change sets of snapshot ${short(mapping.snapshotId)}. Not restored: ${missing}. ${degraded.hint}`;
|
|
533
|
+
}
|
|
534
|
+
const commits = degraded.missingCommits.length;
|
|
535
|
+
const recorded = snapshot === undefined ? "" : ` instead of the recorded commit ${short(snapshot.head)}`;
|
|
536
|
+
const changes = degraded.missingLinks.length > 0 ? " and the snapshot's uncommitted changes" : "";
|
|
537
|
+
return `${restored} at ${degradedBasis(degraded, snapshot)}${recorded}, the closest commit available here. Not restored: ${commits} commit${commits === 1 ? "" : "s"} (${listed(degraded.missingCommits.map(short), 3)})${changes} of snapshot ${short(mapping.snapshotId)}. ${degraded.hint}`;
|
|
538
|
+
}
|
|
539
|
+
/** The notice for a checkout whose snapshot the session holds no record of, which a resume continued without. */
|
|
540
|
+
export function formatMissingRecordNotice(missing) {
|
|
541
|
+
return `Continuing without restoring ${missing.root}: the session holds no record of its snapshot ${short(missing.snapshotId)}. Resume on the machine that recorded it, or import (\`atomic --import <file>\`) a session saved there with \`/export <file>.jsonl\`, which carries its snapshots.`;
|
|
542
|
+
}
|
|
543
|
+
/** The one notice for a checkout a resume continued without (#4733). */
|
|
544
|
+
export function formatUnrestoredNotice(root, unrestored) {
|
|
545
|
+
const place = unrestored.place === "launch" ? "the directory the resume started from" : "the session's own directory";
|
|
546
|
+
return `Continuing in ${unrestored.continuedIn} (${place}) without restoring ${root} from snapshot ${short(unrestored.snapshotId)}: ${unrestored.detail}. ${unrestored.hint}`.trimEnd();
|
|
547
|
+
}
|
|
361
548
|
/**
|
|
362
549
|
* One informational line per worktree restored since `since`, each followed by its snapshot's warnings and what the
|
|
363
|
-
* restore itself reported
|
|
550
|
+
* restore itself reported; one notice per worktree restored with less than its snapshot, and per checkout a resume
|
|
551
|
+
* continued without, since `since` (#4733).
|
|
364
552
|
*/
|
|
365
553
|
export function worktreeRestoreNotices(sessionManager, since) {
|
|
366
|
-
return restoreNotices(sessionManager, (
|
|
554
|
+
return restoreNotices(sessionManager, (entry) => entry.restore
|
|
555
|
+
? entry.restore.restoredAt >= since
|
|
556
|
+
: entry.unrestored !== undefined && entry.unrestored.at >= since);
|
|
367
557
|
}
|
|
368
558
|
function restoreNotices(sessionManager, include) {
|
|
369
559
|
const records = sessionManager.getWorktreeSnapshotRecords();
|
|
370
560
|
return sessionManager.getBranch().flatMap((entry) => {
|
|
371
|
-
if (entry.type !== "worktree_snapshot" || !
|
|
561
|
+
if (entry.type !== "worktree_snapshot" || !include(entry))
|
|
562
|
+
return [];
|
|
563
|
+
if (entry.unrestored) {
|
|
564
|
+
return [{ type: "warning", message: formatUnrestoredNotice(entry.root, entry.unrestored) }];
|
|
565
|
+
}
|
|
566
|
+
if (!entry.restore)
|
|
372
567
|
return [];
|
|
373
568
|
const snapshot = records.get(entry.snapshotId);
|
|
569
|
+
if (entry.restore.degraded) {
|
|
570
|
+
const message = formatDegradedRestoreNotice(entry.restore, snapshot, entry.restoreWarnings);
|
|
571
|
+
return [{ type: "warning", message }];
|
|
572
|
+
}
|
|
374
573
|
return [
|
|
375
574
|
{ type: "info", message: formatWorktreeRestoreNotice(entry.restore) },
|
|
376
575
|
...[...(snapshot ? snapshotRestoreWarnings(snapshot) : []), ...(entry.restoreWarnings ?? [])].map((warning) => ({ type: "warning", message: formatWorktreeRestoreWarning(warning) })),
|
|
@@ -539,6 +738,34 @@ export async function compareWorktreeSnapshot(snapshot, dir, settings) {
|
|
|
539
738
|
: undefined;
|
|
540
739
|
return { status: "differs", head: checkout.head, tree: state.tree, stat };
|
|
541
740
|
}
|
|
741
|
+
/**
|
|
742
|
+
* What the last resume did about the checkout now at `root`, for `/session snapshot`, when it restored less than the
|
|
743
|
+
* snapshot or nothing of it (#4733): the notice that resume showed. Undefined after a complete restore, or none.
|
|
744
|
+
*/
|
|
745
|
+
export function describeWorktreeRestoreStatus(sessionManager, root) {
|
|
746
|
+
const records = sessionManager.getWorktreeSnapshotRecords();
|
|
747
|
+
let status;
|
|
748
|
+
for (const entry of sessionManager.getBranch()) {
|
|
749
|
+
if (entry.type !== "worktree_snapshot")
|
|
750
|
+
continue;
|
|
751
|
+
if (entry.restore && resolve(entry.restore.to) === resolve(root)) {
|
|
752
|
+
status = entry.restore.degraded
|
|
753
|
+
? {
|
|
754
|
+
snapshotId: entry.snapshotId,
|
|
755
|
+
message: formatDegradedRestoreNotice(entry.restore, records.get(entry.snapshotId), entry.restoreWarnings),
|
|
756
|
+
}
|
|
757
|
+
: undefined;
|
|
758
|
+
}
|
|
759
|
+
else if (entry.unrestored && resolve(entry.root) === resolve(root)) {
|
|
760
|
+
status = { snapshotId: entry.snapshotId, message: formatUnrestoredNotice(entry.root, entry.unrestored) };
|
|
761
|
+
}
|
|
762
|
+
else if (status && resolve(entry.root) === resolve(root) && entry.snapshotId !== status.snapshotId) {
|
|
763
|
+
// A later snapshot of the checkout records what it holds now, which replaces what the resume left out.
|
|
764
|
+
status = undefined;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
return status?.message;
|
|
768
|
+
}
|
|
542
769
|
/** Lines describing `snapshot` for `/session snapshot`. */
|
|
543
770
|
export function describeWorktreeSnapshot(root, snapshot) {
|
|
544
771
|
const omitted = snapshot.omitted.map((omission) => "path" in omission
|
|
@@ -563,18 +790,24 @@ export function describeWorktreeSnapshot(root, snapshot) {
|
|
|
563
790
|
*/
|
|
564
791
|
export async function openSessionInWorktree(sessionManager, options) {
|
|
565
792
|
const resume = await resumeSessionWorktree(sessionManager, options);
|
|
566
|
-
return openResumedSession(sessionManager, resume.status === "none" ? sessionManager.getCwd() : resume.cwd, resume.status === "restored" ? resume.mappings : [], options.sessionDirectory);
|
|
793
|
+
return openResumedSession(sessionManager, resume.status === "none" ? sessionManager.getCwd() : resume.cwd, resume.status === "restored" ? resume.mappings : [], options.sessionDirectory, resume.status === "none" ? [] : resume.unrestored.map((checkout) => checkout.record));
|
|
567
794
|
}
|
|
568
795
|
/**
|
|
569
796
|
* Opens `sessionManager`'s session in `cwd`, where resuming it left its working directory, and returns the notices to
|
|
570
797
|
* show for the worktrees that resuming `restored` it into.
|
|
571
798
|
*/
|
|
572
|
-
export async function openResumedSession(sessionManager, cwd, restored, sessionDirectory) {
|
|
799
|
+
export async function openResumedSession(sessionManager, cwd, restored, sessionDirectory, unrestored = []) {
|
|
573
800
|
const opened = cwd !== sessionManager.getCwd()
|
|
574
801
|
? await sessionManager.openSessionById(sessionManager.getSessionId(), cwd, sessionDirectory)
|
|
575
802
|
: sessionManager;
|
|
576
803
|
const restoredHere = new Set(restored.map((mapping) => mapping.to));
|
|
577
|
-
|
|
804
|
+
const leftHere = new Set(unrestored.map((record) => `${record.snapshotId}\0${record.at}`));
|
|
805
|
+
return {
|
|
806
|
+
sessionManager: opened,
|
|
807
|
+
notices: restoreNotices(opened, (entry) => entry.restore
|
|
808
|
+
? restoredHere.has(entry.restore.to)
|
|
809
|
+
: entry.unrestored !== undefined && leftHere.has(`${entry.unrestored.snapshotId}\0${entry.unrestored.at}`)),
|
|
810
|
+
};
|
|
578
811
|
}
|
|
579
812
|
/**
|
|
580
813
|
* Whether a session recorded elsewhere continues in `cwd` because a restore moved its checkout there, so opening it
|
|
@@ -616,7 +849,7 @@ function storedBranchSnapshots(entries, leafId) {
|
|
|
616
849
|
*/
|
|
617
850
|
export async function sessionRunsInRecordedCheckout(store, sessionId) {
|
|
618
851
|
const { header, entries } = await store.load(sessionId);
|
|
619
|
-
const { mappings, current } = storedBranchSnapshots(entries, entries
|
|
852
|
+
const { mappings, current } = storedBranchSnapshots(entries, getSessionLeafId(entries));
|
|
620
853
|
const cwd = mapRestoredPath(header.cwd, mappings);
|
|
621
854
|
return [...current.keys()].some((root) => isInside(root, cwd));
|
|
622
855
|
}
|