@bastani/atomic 0.9.84-alpha.1 → 0.9.85-alpha.1

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.
Files changed (183) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +6 -0
  3. package/dist/builtin/intercom/broker/broker.ts +25 -7
  4. package/dist/builtin/intercom/broker/spawn.ts +83 -17
  5. package/dist/builtin/intercom/index.bundle.mjs +89 -26
  6. package/dist/builtin/intercom/package.json +1 -1
  7. package/dist/builtin/mcp/package.json +1 -1
  8. package/dist/builtin/subagents/package.json +1 -1
  9. package/dist/builtin/web-access/package.json +1 -1
  10. package/dist/builtin/workflows/CHANGELOG.md +6 -0
  11. package/dist/builtin/workflows/package.json +1 -1
  12. package/dist/builtin/workflows/src/authoring.d.ts +1 -1
  13. package/dist/builtin/workflows/src/extension/index.bundle.mjs +48 -9
  14. package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +48 -9
  15. package/dist/builtin/workflows/src/index.js +48 -9
  16. package/dist/builtin/workflows/src/local-worker-entry.mjs +48 -9
  17. package/dist/config.d.ts +3 -2
  18. package/dist/config.d.ts.map +1 -1
  19. package/dist/config.js +4 -3
  20. package/dist/config.js.map +1 -1
  21. package/dist/core/agent-session-export.d.ts +2 -2
  22. package/dist/core/agent-session-export.d.ts.map +1 -1
  23. package/dist/core/agent-session-export.js +4 -5
  24. package/dist/core/agent-session-export.js.map +1 -1
  25. package/dist/core/agent-session-services.js +1 -1
  26. package/dist/core/agent-session-services.js.map +1 -1
  27. package/dist/core/agent-session-summary.d.ts.map +1 -1
  28. package/dist/core/agent-session-summary.js +8 -1
  29. package/dist/core/agent-session-summary.js.map +1 -1
  30. package/dist/core/agent-session-tree.d.ts.map +1 -1
  31. package/dist/core/agent-session-tree.js +3 -6
  32. package/dist/core/agent-session-tree.js.map +1 -1
  33. package/dist/core/builtin-resource-loader.d.ts.map +1 -1
  34. package/dist/core/builtin-resource-loader.js +1 -1
  35. package/dist/core/builtin-resource-loader.js.map +1 -1
  36. package/dist/core/extensions/loader-core.d.ts +6 -2
  37. package/dist/core/extensions/loader-core.d.ts.map +1 -1
  38. package/dist/core/extensions/loader-core.js +13 -9
  39. package/dist/core/extensions/loader-core.js.map +1 -1
  40. package/dist/core/extensions/loader-discovery.js +1 -1
  41. package/dist/core/extensions/loader-discovery.js.map +1 -1
  42. package/dist/core/extensions/loader-virtual-modules.d.ts +20 -14
  43. package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
  44. package/dist/core/extensions/loader-virtual-modules.js +133 -78
  45. package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
  46. package/dist/core/extensions/ts-source-specifiers.d.ts +1 -0
  47. package/dist/core/extensions/ts-source-specifiers.d.ts.map +1 -1
  48. package/dist/core/extensions/ts-source-specifiers.js +18 -2
  49. package/dist/core/extensions/ts-source-specifiers.js.map +1 -1
  50. package/dist/core/mandatory-resource-loader.d.ts +5 -2
  51. package/dist/core/mandatory-resource-loader.d.ts.map +1 -1
  52. package/dist/core/mandatory-resource-loader.js +17 -12
  53. package/dist/core/mandatory-resource-loader.js.map +1 -1
  54. package/dist/core/model-fallback-failures.d.ts.map +1 -1
  55. package/dist/core/model-fallback-failures.js +10 -3
  56. package/dist/core/model-fallback-failures.js.map +1 -1
  57. package/dist/core/resource-loader-extensions.d.ts.map +1 -1
  58. package/dist/core/resource-loader-extensions.js +1 -1
  59. package/dist/core/resource-loader-extensions.js.map +1 -1
  60. package/dist/core/resource-loader-reload.js +1 -1
  61. package/dist/core/resource-loader-reload.js.map +1 -1
  62. package/dist/core/resume/blueprint/resume.d.ts +4 -4
  63. package/dist/core/resume/blueprint/resume.js +4 -4
  64. package/dist/core/resume/blueprint/resume.js.map +1 -1
  65. package/dist/core/resume/session-resume.d.ts +6 -3
  66. package/dist/core/resume/session-resume.d.ts.map +1 -1
  67. package/dist/core/resume/session-resume.js +159 -37
  68. package/dist/core/resume/session-resume.js.map +1 -1
  69. package/dist/core/sdk.js +1 -1
  70. package/dist/core/sdk.js.map +1 -1
  71. package/dist/core/session-manager-core.d.ts +10 -4
  72. package/dist/core/session-manager-core.d.ts.map +1 -1
  73. package/dist/core/session-manager-core.js +23 -6
  74. package/dist/core/session-manager-core.js.map +1 -1
  75. package/dist/core/session-manager-entries.d.ts +2 -2
  76. package/dist/core/session-manager-entries.d.ts.map +1 -1
  77. package/dist/core/session-manager-entries.js +2 -1
  78. package/dist/core/session-manager-entries.js.map +1 -1
  79. package/dist/core/session-manager-history.d.ts +13 -1
  80. package/dist/core/session-manager-history.d.ts.map +1 -1
  81. package/dist/core/session-manager-history.js +21 -1
  82. package/dist/core/session-manager-history.js.map +1 -1
  83. package/dist/core/session-manager-types.d.ts +3 -1
  84. package/dist/core/session-manager-types.d.ts.map +1 -1
  85. package/dist/core/session-manager-types.js.map +1 -1
  86. package/dist/core/session-manager.d.ts +1 -1
  87. package/dist/core/session-manager.d.ts.map +1 -1
  88. package/dist/core/session-manager.js +1 -1
  89. package/dist/core/session-manager.js.map +1 -1
  90. package/dist/core/session-worktree-snapshots.d.ts +61 -4
  91. package/dist/core/session-worktree-snapshots.d.ts.map +1 -1
  92. package/dist/core/session-worktree-snapshots.js +261 -28
  93. package/dist/core/session-worktree-snapshots.js.map +1 -1
  94. package/dist/core/storage/session/entry-structure.js +31 -1
  95. package/dist/core/storage/session/entry-structure.js.map +1 -1
  96. package/dist/core/tools/ask-user-question/state/build-questionnaire.d.ts.map +1 -1
  97. package/dist/core/tools/ask-user-question/state/build-questionnaire.js +2 -1
  98. package/dist/core/tools/ask-user-question/state/build-questionnaire.js.map +1 -1
  99. package/dist/core/tools/ask-user-question/state/questionnaire-session.d.ts.map +1 -1
  100. package/dist/core/tools/ask-user-question/state/questionnaire-session.js +2 -0
  101. package/dist/core/tools/ask-user-question/state/questionnaire-session.js.map +1 -1
  102. package/dist/core/tools/ask-user-question/state/selectors/field-tone.d.ts +26 -0
  103. package/dist/core/tools/ask-user-question/state/selectors/field-tone.d.ts.map +1 -0
  104. package/dist/core/tools/ask-user-question/state/selectors/field-tone.js +27 -0
  105. package/dist/core/tools/ask-user-question/state/selectors/field-tone.js.map +1 -0
  106. package/dist/core/tools/ask-user-question/state/selectors/projections.d.ts.map +1 -1
  107. package/dist/core/tools/ask-user-question/state/selectors/projections.js +1 -0
  108. package/dist/core/tools/ask-user-question/state/selectors/projections.js.map +1 -1
  109. package/dist/core/tools/ask-user-question/state/state-reducer.js +1 -1
  110. package/dist/core/tools/ask-user-question/state/state-reducer.js.map +1 -1
  111. package/dist/core/tools/ask-user-question/view/components/multi-select-view.d.ts.map +1 -1
  112. package/dist/core/tools/ask-user-question/view/components/multi-select-view.js +6 -6
  113. package/dist/core/tools/ask-user-question/view/components/multi-select-view.js.map +1 -1
  114. package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts +5 -3
  115. package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts.map +1 -1
  116. package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.js +14 -4
  117. package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.js.map +1 -1
  118. package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.d.ts +2 -0
  119. package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.d.ts.map +1 -1
  120. package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.js +3 -3
  121. package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.js.map +1 -1
  122. package/dist/core/tools/ask-user-question/view/components/wrapping-select.d.ts +16 -6
  123. package/dist/core/tools/ask-user-question/view/components/wrapping-select.d.ts.map +1 -1
  124. package/dist/core/tools/ask-user-question/view/components/wrapping-select.js +42 -24
  125. package/dist/core/tools/ask-user-question/view/components/wrapping-select.js.map +1 -1
  126. package/dist/core/tools/ask-user-question/view/tab-content-strategy.d.ts.map +1 -1
  127. package/dist/core/tools/ask-user-question/view/tab-content-strategy.js +12 -3
  128. package/dist/core/tools/ask-user-question/view/tab-content-strategy.js.map +1 -1
  129. package/dist/core/tools/read.d.ts +1 -0
  130. package/dist/core/tools/read.d.ts.map +1 -1
  131. package/dist/core/tools/read.js +13 -14
  132. package/dist/core/tools/read.js.map +1 -1
  133. package/dist/core/worktree-snapshot/index.d.ts +2 -2
  134. package/dist/core/worktree-snapshot/index.d.ts.map +1 -1
  135. package/dist/core/worktree-snapshot/index.js +1 -1
  136. package/dist/core/worktree-snapshot/index.js.map +1 -1
  137. package/dist/core/worktree-snapshot/records.d.ts +6 -0
  138. package/dist/core/worktree-snapshot/records.d.ts.map +1 -1
  139. package/dist/core/worktree-snapshot/records.js +18 -4
  140. package/dist/core/worktree-snapshot/records.js.map +1 -1
  141. package/dist/core/worktree-snapshot/restore.d.ts +24 -1
  142. package/dist/core/worktree-snapshot/restore.d.ts.map +1 -1
  143. package/dist/core/worktree-snapshot/restore.js +443 -72
  144. package/dist/core/worktree-snapshot/restore.js.map +1 -1
  145. package/dist/core/worktree-snapshot/types.d.ts +44 -0
  146. package/dist/core/worktree-snapshot/types.d.ts.map +1 -1
  147. package/dist/core/worktree-snapshot/types.js.map +1 -1
  148. package/dist/index.d.ts +2 -2
  149. package/dist/index.d.ts.map +1 -1
  150. package/dist/index.js +2 -2
  151. package/dist/index.js.map +1 -1
  152. package/dist/modes/interactive/components/tool-execution.js +2 -1
  153. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  154. package/dist/modes/interactive/interactive-slash-commands.js +4 -1
  155. package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
  156. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  157. package/dist/modes/interactive-engine/isolated-runtime.js +8 -0
  158. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  159. package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
  160. package/dist/modes/rpc/rpc-command-handler.js +11 -2
  161. package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
  162. package/dist/modes/rpc/rpc-command-timeouts.d.ts.map +1 -1
  163. package/dist/modes/rpc/rpc-command-timeouts.js +1 -0
  164. package/dist/modes/rpc/rpc-command-timeouts.js.map +1 -1
  165. package/dist/modes/rpc/rpc-input-scheduler.d.ts.map +1 -1
  166. package/dist/modes/rpc/rpc-input-scheduler.js +1 -0
  167. package/dist/modes/rpc/rpc-input-scheduler.js.map +1 -1
  168. package/dist/modes/rpc/rpc-types.d.ts +11 -1
  169. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  170. package/dist/modes/rpc/rpc-types.js.map +1 -1
  171. package/docs/environment-variables.md +1 -1
  172. package/docs/guides/resume-on-any-machine.md +6 -4
  173. package/docs/intercom/operations.md +4 -0
  174. package/docs/rpc/protocol.md +2 -2
  175. package/docs/sdk/reference.md +3 -0
  176. package/docs/sdk.md +2 -2
  177. package/docs/session-format.md +11 -2
  178. package/docs/sessions.md +4 -2
  179. package/docs/settings.md +1 -1
  180. package/docs/workflows/api-reference.md +2 -2
  181. package/docs/worktree-snapshots.md +13 -5
  182. package/npm-shrinkwrap.json +32 -32
  183. package/package.json +3 -3
@@ -3,7 +3,7 @@ import { stat } from "node:fs/promises";
3
3
  import { join, relative, resolve } from "node:path";
4
4
  import { isGitUnavailableError } from "../../utils/git-errors.js";
5
5
  import { failureDebugFields, reportDebug } from "../debug.js";
6
- import { currentWorktreeSnapshots, mapRestoredPath, openResumedSession, resumeSessionWorktree, } from "../session-worktree-snapshots.js";
6
+ import { currentWorktreeSnapshots, formatMissingRecordNotice, mapRestoredPath, missingSnapshotRecords, openResumedSession, resumeSessionWorktree, } from "../session-worktree-snapshots.js";
7
7
  import { ProjectTrustStore } from "../trust-manager.js";
8
8
  import { locateCheckout, readRepositoryConfig } from "../worktree-snapshot/capture.js";
9
9
  import { isWorkspaceConfigError, isWorkspaceDriftError, isWorkspaceSnapshotError, } from "../worktree-snapshot/errors.js";
@@ -11,10 +11,10 @@ import { gitText, runGit } from "../worktree-snapshot/git.js";
11
11
  import { isHeadOnlyAdvance } from "../worktree-snapshot/head-advance.js";
12
12
  import { defaultWorktreeSnapshotStoreDir, verifyWorktree, } from "../worktree-snapshot/restore.js";
13
13
  import { checkoutsNeedingRebuild, enclosingRepositoryRoot, inheritedRemotes, recordBlueprintContext, setUpResumedBlueprints, } from "./blueprint/resume.js";
14
- import { isResumePreconditionError, ResumePreconditionError } from "./errors.js";
14
+ import { isResumePreconditionError } from "./errors.js";
15
15
  import { isResumeFailure } from "./failure.js";
16
16
  import { isInside } from "./path-mapping.js";
17
- import { defaultResumePreflightIo, gitUnavailableProblem } from "./preflight.js";
17
+ import { defaultResumePreflightIo } from "./preflight.js";
18
18
  async function isDirectory(path) {
19
19
  try {
20
20
  return (await stat(path)).isDirectory();
@@ -174,9 +174,12 @@ async function hasLocalChanges(root, signal) {
174
174
  * the checkout it was restored from when that checkout is here. When the checkout the session works in is missing or
175
175
  * belongs to another clone here, a checkout of the same
176
176
  * repository the resume started in is used as-is if it matches (and, if it differs, only when the user chooses it).
177
- * The checkout the session works in is the only one the resume cannot go without: when it must be restored, the
178
- * precondition of restoring the recorded checkouts, that Git can run, is checked first, and an unmet one refuses the
179
- * resume before anything is written. Every other checkout the session recorded that is gone or changed here, except
177
+ * Resume always opens the session (#4733): a checkout whose snapshot cannot be restored exactly gets the best state
178
+ * this node can reach, its recorded commit with the change sets that apply or the closest commit it can fetch, and one
179
+ * notice saying what is missing; when nothing of it can be restored, Git being unavailable included, the session
180
+ * continues in its recorded directory, or the directory the resume started from when that is not here, with the same
181
+ * kind of notice. Only a snapshot record that fails the security checks, or a restore target that holds other files,
182
+ * refuses the resume. Every other checkout the session recorded that is gone or changed here, except
180
183
  * those in `keepInPlace`, never blocks the resume: one the session worked in on this node, changed since, continues as
181
184
  * it is; the rest are restored into fresh worktrees one by one by #4245's {@link resumeSessionWorktree}, and one that
182
185
  * cannot be (Git is unavailable, or its restore fails) is left out with a warning that names its path and why. Each
@@ -188,6 +191,9 @@ export async function prepareSessionResume(sessionManager, options) {
188
191
  const io = options.io ?? defaultResumePreflightIo;
189
192
  const storeDir = resolve(options.storeDir ?? defaultWorktreeSnapshotStoreDir());
190
193
  if (!options.settings.enabled || sessionManager.getLatestWorktreeSnapshots().size === 0) {
194
+ const missing = options.settings.enabled ? missingSnapshotRecords(sessionManager) : [];
195
+ if (missing.length > 0)
196
+ return continueWithoutRecords(sessionManager, missing, storeDir, options);
191
197
  const unchanged = await describeBlueprintsInPlace(sessionManager, storeDir, options);
192
198
  return { status: "ready", sessionManager, notices: [], blueprintNotices: [], blueprintContext: unchanged };
193
199
  }
@@ -204,10 +210,25 @@ export async function prepareSessionResume(sessionManager, options) {
204
210
  }
205
211
  return verification;
206
212
  };
213
+ // Which partly restored worktrees are still as the restore left them, compared once per resume.
214
+ let partialOnce;
215
+ const partial = () => {
216
+ partialOnce ??= partialRestores(sessionManager, options);
217
+ return partialOnce;
218
+ };
207
219
  const match = latestSessionSnapshot(sessionManager);
208
220
  let git;
209
221
  let reused;
210
- const needsRestore = match !== undefined && !options.keepInPlace?.has(match.root) && (await verifyOnce(match.snapshot, match.root));
222
+ let needsRestore;
223
+ try {
224
+ needsRestore =
225
+ match !== undefined && !options.keepInPlace?.has(match.root) && (await verifyOnce(match.snapshot, match.root));
226
+ }
227
+ catch (error) {
228
+ if (!isGitUnavailableError(error))
229
+ throw error;
230
+ return continueWithoutGit(sessionManager, error, storeDir, options);
231
+ }
211
232
  const project = match !== undefined && !needsRestore && !options.keepInPlace?.has(match.root)
212
233
  ? await orFallBack(options, "return-to-checkout", undefined, () => returnToStartingCheckout(sessionManager, match, storeDir, options))
213
234
  : undefined;
@@ -219,7 +240,7 @@ export async function prepareSessionResume(sessionManager, options) {
219
240
  project === undefined &&
220
241
  needsRestore &&
221
242
  (await isDirectory(match.root)) &&
222
- (await orFallBack(options, "own-checkout", new Set([match.root]), () => checkoutsWorkedHere(new Map([[match.root, match.snapshot]]), match.cwd, options)).then((worked) => worked.has(match.root)));
243
+ (await orFallBack(options, "own-checkout", new Set([match.root]), async () => checkoutsWorkedHere(new Map([[match.root, match.snapshot]]), match.cwd, options, await partial())).then((worked) => worked.has(match.root)));
223
244
  // The checkout the session returned to stays as it is, whatever it changed since: only the others are restored.
224
245
  const kept = [...(keepsOwnCheckout && match !== undefined ? [match.root] : [])];
225
246
  if (project !== undefined && match !== undefined)
@@ -240,15 +261,15 @@ export async function prepareSessionResume(sessionManager, options) {
240
261
  }
241
262
  }
242
263
  const checkouts = withMapping(sessionManager, reused);
243
- const candidates = await restoreCandidates(checkouts, mapRestoredPath(sessionManager.getCwd(), checkouts.getWorktreeRootMappings()), resume, verifyOnce);
264
+ const candidates = await restoreCandidates(checkouts, mapRestoredPath(sessionManager.getCwd(), checkouts.getWorktreeRootMappings()), resume, verifyOnce, partial);
244
265
  if (candidates.targets.length > 0)
245
266
  git ??= { unavailable: await io.probeGit(options.signal) };
246
- const plan = planRestores(sessionManager, candidates, resume, git?.unavailable);
267
+ const plan = planRestores(candidates, git?.unavailable);
247
268
  notices.push(...plan.left.values());
248
269
  const recordedBefore = sessionManager.getWorktreeRootMappings().length;
249
270
  const resumed = await restorePlanned(sessionManager, plan, reused, storeDir, resume);
250
- const cwd = mapRestoredPath(sessionManager.getCwd(), sessionManager.getWorktreeRootMappings());
251
- const opened = await openResumedSession(sessionManager, cwd, resumed.restored, options.sessionDirectory);
271
+ const cwd = resumed.cwd ?? mapRestoredPath(sessionManager.getCwd(), sessionManager.getWorktreeRootMappings());
272
+ const opened = await openResumedSession(sessionManager, cwd, resumed.restored, options.sessionDirectory, resumed.unrestored);
252
273
  notices.push(...opened.notices, ...resumed.failed);
253
274
  const restoredNow = new Set(opened.sessionManager
254
275
  .getWorktreeRootMappings()
@@ -269,6 +290,58 @@ export async function prepareSessionResume(sessionManager, options) {
269
290
  blueprintContext: blueprints.context,
270
291
  };
271
292
  }
293
+ /**
294
+ * Opens a session whose checkouts cannot even be compared with their snapshots, because Git cannot run here (#4733):
295
+ * it continues in its recorded directory as it is, or in the directory the resume started from when that is not
296
+ * here, without restoring any checkout, and each is recorded as left out with a notice. Nothing is written to any
297
+ * checkout.
298
+ */
299
+ async function continueWithoutGit(sessionManager, git, storeDir, options) {
300
+ const roots = [...currentWorktreeSnapshots(sessionManager).keys()].filter((root) => !options.keepInPlace?.has(root));
301
+ const resumed = await resumeSessionWorktree(sessionManager, {
302
+ settings: options.settings,
303
+ storeDir,
304
+ signal: options.signal,
305
+ keepInPlace: options.keepInPlace,
306
+ cannotRestore: new Map(roots.map((root) => [root, git])),
307
+ fallbackCwd: options.launchCwd,
308
+ skipMissingRecords: true,
309
+ });
310
+ const cwd = resumed.status === "none" ? sessionManager.getCwd() : resumed.cwd;
311
+ const opened = await openResumedSession(sessionManager, cwd, [], options.sessionDirectory, resumed.status === "none" ? [] : resumed.unrestored.map((checkout) => checkout.record));
312
+ const context = await describeBlueprintsInPlace(opened.sessionManager, storeDir, options);
313
+ return {
314
+ status: "ready",
315
+ sessionManager: opened.sessionManager,
316
+ notices: [
317
+ ...opened.notices,
318
+ ...(resumed.missingRecords ?? []).map((missing) => ({
319
+ type: "warning",
320
+ message: formatMissingRecordNotice(missing),
321
+ })),
322
+ ],
323
+ blueprintNotices: [],
324
+ blueprintContext: context,
325
+ };
326
+ }
327
+ /**
328
+ * Opens a session whose every recorded checkout refers to a snapshot the session holds no record of (#4733): nothing
329
+ * can be restored, so it continues in its recorded directory, or the directory the resume started from when that is
330
+ * not here, with one notice per checkout.
331
+ */
332
+ async function continueWithoutRecords(sessionManager, missing, storeDir, options) {
333
+ const recorded = mapRestoredPath(sessionManager.getCwd(), sessionManager.getWorktreeRootMappings());
334
+ const cwd = existsSync(recorded) ? recorded : resolve(options.launchCwd);
335
+ const opened = await openResumedSession(sessionManager, cwd, [], options.sessionDirectory);
336
+ const context = await describeBlueprintsInPlace(opened.sessionManager, storeDir, options);
337
+ return {
338
+ status: "ready",
339
+ sessionManager: opened.sessionManager,
340
+ notices: missing.map((record) => ({ type: "warning", message: formatMissingRecordNotice(record) })),
341
+ blueprintNotices: [],
342
+ blueprintContext: context,
343
+ };
344
+ }
272
345
  const SKIPPED_BLUEPRINTS = { outcome: undefined, notices: [], layers: [], context: undefined };
273
346
  /**
274
347
  * The blueprint context of a session that has no worktree snapshots to restore: what its working directory's
@@ -377,7 +450,7 @@ function describeFailure(error) {
377
450
  * with a warning, when it cannot be compared with its snapshot, or when it is here and the session worked in it on this
378
451
  * node, so it continues as it is.
379
452
  */
380
- async function restoreCandidates(sessionManager, cwd, options, needsRestore) {
453
+ async function restoreCandidates(sessionManager, cwd, options, needsRestore, partial) {
381
454
  const targets = [];
382
455
  const left = new Map();
383
456
  const checkouts = [...currentWorktreeSnapshots(sessionManager)].filter(([root]) => !options.keepInPlace?.has(root));
@@ -395,7 +468,9 @@ async function restoreCandidates(sessionManager, cwd, options, needsRestore) {
395
468
  if (!comparison.value)
396
469
  continue;
397
470
  const absent = !(await isDirectory(root));
398
- if (!runsHere && !absent && (await checkoutsWorkedHere(new Map([[root, snapshot]]), cwd, options)).has(root)) {
471
+ if (!runsHere &&
472
+ !absent &&
473
+ (await checkoutsWorkedHere(new Map([[root, snapshot]]), cwd, options, await partial())).has(root)) {
399
474
  left.set(root, notRestored(root, snapshot, "it changed since the snapshot, and the session worked in it on this node, so it stays as it is"));
400
475
  continue;
401
476
  }
@@ -426,14 +501,25 @@ async function settleBounded(items, limit, map) {
426
501
  /**
427
502
  * Restores what `plan` says into fresh worktrees with #4245's {@link resumeSessionWorktree}, recording each restore on
428
503
  * `sessionManager`, and returns the mappings it recorded. The checkouts the session works in are restored together,
429
- * with the mapping to the launch checkout `reused`, and any failure refuses the resume. Every other checkout is
430
- * restored on its own, and one whose restore fails is reported in `failed` and left out.
504
+ * with the mapping to the launch checkout `reused`; one that cannot be restored exactly is restored as far as it can be,
505
+ * or recorded as left out, in `unrestored` (#4733), and only a failure that is not about a checkout refuses the resume.
506
+ * Every other checkout is restored on its own the same way, and one whose restore is refused is reported in `failed`
507
+ * and left out. `cwd` is where the session continues after the restore of the checkouts it works in.
431
508
  */
432
509
  async function restorePlanned(sessionManager, plan, reused, storeDir, options) {
433
- const outcome = { restored: [], failed: [] };
510
+ const outcome = {
511
+ restored: [],
512
+ failed: [],
513
+ unrestored: [],
514
+ cwd: undefined,
515
+ missing: new Set(),
516
+ };
434
517
  const restore = async (targets, pending) => {
518
+ const git = plan.git;
435
519
  for (const target of targets) {
436
- options.onProgress?.(`Restoring ${target.root} from snapshot ${target.snapshot.id.slice(0, 12)}`);
520
+ if (git === undefined) {
521
+ options.onProgress?.(`Restoring ${target.root} from snapshot ${target.snapshot.id.slice(0, 12)}`);
522
+ }
437
523
  }
438
524
  const restoring = new Set(targets.map((target) => target.root));
439
525
  const resumed = await resumeSessionWorktree(sessionManager, {
@@ -442,11 +528,25 @@ async function restorePlanned(sessionManager, plan, reused, storeDir, options) {
442
528
  signal: options.signal,
443
529
  pendingMappings: pending === undefined ? [] : [pending],
444
530
  keepInPlace: new Set([...currentWorktreeSnapshots(withMapping(sessionManager, pending)).keys()].filter((root) => !restoring.has(root))),
531
+ ...(git === undefined ? {} : { cannotRestore: new Map(targets.map((target) => [target.root, git])) }),
532
+ fallbackCwd: options.launchCwd,
533
+ skipMissingRecords: true,
445
534
  });
535
+ for (const missing of resumed.missingRecords ?? []) {
536
+ if (outcome.missing.has(missing.root))
537
+ continue;
538
+ outcome.missing.add(missing.root);
539
+ outcome.failed.push({ type: "warning", message: formatMissingRecordNotice(missing) });
540
+ }
541
+ if (resumed.status === "none")
542
+ return undefined;
446
543
  if (resumed.status === "restored")
447
544
  outcome.restored.push(...resumed.mappings);
545
+ outcome.unrestored.push(...resumed.unrestored.map((checkout) => checkout.record));
546
+ return resumed.cwd;
448
547
  };
449
- await restore(plan.required, reused);
548
+ if (plan.required.length > 0 || reused !== undefined)
549
+ outcome.cwd = await restore(plan.required, reused);
450
550
  for (const target of plan.optional) {
451
551
  try {
452
552
  await restore([target], undefined);
@@ -521,7 +621,7 @@ export async function holdsSnapshotCommit(snapshot, root, signal) {
521
621
  export async function continueSessionWhereItWorked(opened, options, reopen = (cwd) => opened.openSessionById(opened.getSessionId(), cwd)) {
522
622
  const cwd = mapRestoredPath(opened.getCwd(), opened.getWorktreeRootMappings());
523
623
  const checkouts = currentWorktreeSnapshots(opened);
524
- const own = await checkoutsWorkedHere(checkouts, cwd, options);
624
+ const own = await checkoutsWorkedHere(checkouts, cwd, options, await partialRestores(opened, options));
525
625
  if (own.size < checkouts.size) {
526
626
  const prepared = await prepareSessionResume(opened, { ...options, keepInPlace: own });
527
627
  if (prepared.status !== "ready")
@@ -547,17 +647,49 @@ export async function continueSessionWhereItWorked(opened, options, reopen = (cw
547
647
  * or changed since: a worktree this node restored for it, or a checkout whose repository holds the commit of its latest
548
648
  * snapshot. The checkout the session works in counts only while its working directory `cwd` is here too.
549
649
  */
550
- async function checkoutsWorkedHere(checkouts, cwd, options) {
650
+ async function checkoutsWorkedHere(checkouts, cwd, options, partial = new Set()) {
551
651
  const storeDir = resolve(options.storeDir ?? defaultWorktreeSnapshotStoreDir());
552
652
  const own = new Set();
553
653
  for (const [root, snapshot] of checkouts) {
554
654
  if (!existsSync(isInside(root, cwd) ? cwd : root))
555
655
  continue;
556
- if (isInside(storeDir, root) || (await holdsSnapshotCommit(snapshot, root, options.signal)))
656
+ const restoredHere = isInside(storeDir, root) && !partial.has(resolve(root));
657
+ if (restoredHere || (await holdsSnapshotCommit(snapshot, root, options.signal)))
557
658
  own.add(root);
558
659
  }
559
660
  return own;
560
661
  }
662
+ /**
663
+ * The worktrees a resume restored with less than their snapshot (#4733) that are still exactly as it left them: the
664
+ * session recorded no snapshot there since, and their HEAD and files are what the restore put there. The next resume
665
+ * tries the snapshot again instead of keeping them. A worktree changed since, even by hand, is the session's work and
666
+ * stays; one that cannot be compared stays too.
667
+ */
668
+ async function partialRestores(sessionManager, options) {
669
+ const current = currentWorktreeSnapshots(sessionManager);
670
+ const partial = new Set();
671
+ for (const mapping of sessionManager.getWorktreeRootMappings()) {
672
+ const degraded = mapping.degraded;
673
+ const snapshot = current.get(mapping.to);
674
+ if (degraded === undefined || snapshot?.id !== mapping.snapshotId || !existsSync(mapping.to))
675
+ continue;
676
+ const restored = {
677
+ remotes: [...snapshot.remotes],
678
+ head: degraded.head,
679
+ tree: degraded.tree,
680
+ envHash: snapshot.envHash,
681
+ };
682
+ try {
683
+ await verifyWorktree(restored, mapping.to, { settings: options.settings, signal: options.signal });
684
+ partial.add(resolve(mapping.to));
685
+ }
686
+ catch (error) {
687
+ if (options.signal?.aborted)
688
+ throw error;
689
+ }
690
+ }
691
+ return partial;
692
+ }
561
693
  /**
562
694
  * Whether resuming in `root` restores `snapshot` into a fresh worktree: the checkout is gone, is not a repository of
563
695
  * the recorded tree, or no longer matches it. A path that cannot be read fails with its typed `unreadable-path` error
@@ -580,15 +712,13 @@ export async function worktreeNeedsRestore(snapshot, root, options) {
580
712
  /**
581
713
  * Decides what the resume does about the `candidates` that are gone or changed here, before anything is written. The
582
714
  * precondition of restoring them on this node is that Git can be started or provisioned (`git`, the probe's typed
583
- * failure). When it is unmet and the session works in a checkout that must be restored, the resume is refused; for any
584
- * other checkout it leaves that checkout out, with a warning. A blueprint is never a precondition.
715
+ * failure). When it is unmet, the checkouts the session works in are not restored and the session continues without
716
+ * them, with a notice and a record in the session (#4733); any other checkout is left out with a warning. A blueprint
717
+ * is never a precondition.
585
718
  */
586
- function planRestores(sessionManager, candidates, options, git) {
719
+ function planRestores(candidates, git) {
587
720
  const required = candidates.targets.filter((target) => target.runsHere);
588
721
  const others = candidates.targets.filter((target) => !target.runsHere);
589
- if (required.length > 0 && git !== undefined) {
590
- throw preconditionFailure(sessionManager, [...required, ...others], options, git);
591
- }
592
722
  const left = new Map(candidates.left);
593
723
  const optional = [];
594
724
  for (const target of others) {
@@ -599,15 +729,7 @@ function planRestores(sessionManager, candidates, options, git) {
599
729
  optional.push(target);
600
730
  }
601
731
  }
602
- return { required, optional, left };
603
- }
604
- /** The refusal to resume because `targets` cannot be restored here: Git cannot be started or provisioned. */
605
- function preconditionFailure(sessionManager, targets, options, git) {
606
- const reasons = targets.map((target) => `snapshot ${target.snapshot.id.slice(0, 12)} because ${target.root} ${target.absent ? "does not exist on this node" : "no longer matches it"}`);
607
- const problems = [
608
- gitUnavailableProblem(git, `session ${sessionManager.getSessionId()} must be restored from ${reasons.join(", and from ")}`),
609
- ];
610
- return new ResumePreconditionError({ entryPoint: options.entryPoint, problems }, git);
732
+ return { required, optional, left, git };
611
733
  }
612
734
  /**
613
735
  * Whether a restored worktree is trusted to run its blueprints outside the CLI: the decision saved in `agentDir` for