@bastani/atomic 0.9.85 → 0.9.86

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 (125) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +34 -0
  3. package/dist/builtin/intercom/README.md +10 -9
  4. package/dist/builtin/intercom/broker/away-asks.ts +272 -0
  5. package/dist/builtin/intercom/broker/broker.ts +171 -9
  6. package/dist/builtin/intercom/broker/client.ts +5 -3
  7. package/dist/builtin/intercom/broker/held-reply-targets.ts +5 -0
  8. package/dist/builtin/intercom/broker/multinode-router.ts +16 -7
  9. package/dist/builtin/intercom/broker/paths.ts +5 -0
  10. package/dist/builtin/intercom/broker/pending-question-index.ts +124 -0
  11. package/dist/builtin/intercom/broker/released-asker-replies.ts +39 -0
  12. package/dist/builtin/intercom/broker/send-handler.ts +44 -3
  13. package/dist/builtin/intercom/broker/terminal-questions.ts +2 -0
  14. package/dist/builtin/intercom/index.bundle.mjs +799 -177
  15. package/dist/builtin/intercom/package.json +1 -1
  16. package/dist/builtin/intercom/retry-policy.ts +1 -1
  17. package/dist/builtin/intercom/skills/intercom/SKILL.md +29 -35
  18. package/dist/builtin/intercom/types.ts +7 -2
  19. package/dist/builtin/mcp/package.json +1 -1
  20. package/dist/builtin/subagents/CHANGELOG.md +40 -0
  21. package/dist/builtin/subagents/package.json +1 -1
  22. package/dist/builtin/subagents/skills/subagent/SKILL.md +1 -1
  23. package/dist/builtin/subagents/src/extension/index.bundle.mjs +2765 -2719
  24. package/dist/builtin/web-access/package.json +1 -1
  25. package/dist/builtin/workflows/CHANGELOG.md +24 -0
  26. package/dist/builtin/workflows/package.json +1 -1
  27. package/dist/builtin/workflows/src/authoring.d.ts +1 -1
  28. package/dist/builtin/workflows/src/extension/index.bundle.mjs +371 -193
  29. package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +358 -181
  30. package/dist/builtin/workflows/src/index.js +356 -183
  31. package/dist/builtin/workflows/src/local-worker-entry.mjs +358 -181
  32. package/dist/builtin/workflows/src/shared/worktree-restore-outcome.d.ts +16 -0
  33. package/dist/builtin/workflows/src/workers/workspace-binding.d.ts +13 -2
  34. package/dist/core/agent-session-methods.d.ts +1 -0
  35. package/dist/core/agent-session-methods.d.ts.map +1 -1
  36. package/dist/core/agent-session-methods.js.map +1 -1
  37. package/dist/core/agent-session-prompt.d.ts.map +1 -1
  38. package/dist/core/agent-session-prompt.js +2 -35
  39. package/dist/core/agent-session-prompt.js.map +1 -1
  40. package/dist/core/agent-session-runtime.d.ts +3 -1
  41. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  42. package/dist/core/agent-session-runtime.js +12 -5
  43. package/dist/core/agent-session-runtime.js.map +1 -1
  44. package/dist/core/agent-session-state.d.ts.map +1 -1
  45. package/dist/core/agent-session-state.js +14 -1
  46. package/dist/core/agent-session-state.js.map +1 -1
  47. package/dist/core/agent-session.d.ts +2 -0
  48. package/dist/core/agent-session.d.ts.map +1 -1
  49. package/dist/core/agent-session.js +3 -1
  50. package/dist/core/agent-session.js.map +1 -1
  51. package/dist/core/resume/index.d.ts +1 -1
  52. package/dist/core/resume/index.d.ts.map +1 -1
  53. package/dist/core/resume/index.js +1 -1
  54. package/dist/core/resume/index.js.map +1 -1
  55. package/dist/core/resume/path-mapping.d.ts +10 -0
  56. package/dist/core/resume/path-mapping.d.ts.map +1 -1
  57. package/dist/core/resume/path-mapping.js +20 -0
  58. package/dist/core/resume/path-mapping.js.map +1 -1
  59. package/dist/core/resume/session-resume.d.ts +5 -0
  60. package/dist/core/resume/session-resume.d.ts.map +1 -1
  61. package/dist/core/resume/session-resume.js +24 -9
  62. package/dist/core/resume/session-resume.js.map +1 -1
  63. package/dist/core/session-worktree-snapshots.d.ts +5 -8
  64. package/dist/core/session-worktree-snapshots.d.ts.map +1 -1
  65. package/dist/core/session-worktree-snapshots.js +34 -99
  66. package/dist/core/session-worktree-snapshots.js.map +1 -1
  67. package/dist/core/skill-catalog.d.ts +11 -0
  68. package/dist/core/skill-catalog.d.ts.map +1 -1
  69. package/dist/core/skill-catalog.js +31 -0
  70. package/dist/core/skill-catalog.js.map +1 -1
  71. package/dist/core/tasks/agent-adapter.d.ts +2 -0
  72. package/dist/core/tasks/agent-adapter.d.ts.map +1 -1
  73. package/dist/core/tasks/agent-adapter.js +5 -1
  74. package/dist/core/tasks/agent-adapter.js.map +1 -1
  75. package/dist/core/tasks/supervisor.d.ts +17 -0
  76. package/dist/core/tasks/supervisor.d.ts.map +1 -1
  77. package/dist/core/tasks/supervisor.js +12 -6
  78. package/dist/core/tasks/supervisor.js.map +1 -1
  79. package/dist/core/tasks/task-view-source.d.ts +10 -0
  80. package/dist/core/tasks/task-view-source.d.ts.map +1 -1
  81. package/dist/core/tasks/task-view-source.js +24 -1
  82. package/dist/core/tasks/task-view-source.js.map +1 -1
  83. package/dist/core/worktree-snapshot/best-restore.d.ts +45 -0
  84. package/dist/core/worktree-snapshot/best-restore.d.ts.map +1 -0
  85. package/dist/core/worktree-snapshot/best-restore.js +92 -0
  86. package/dist/core/worktree-snapshot/best-restore.js.map +1 -0
  87. package/dist/core/worktree-snapshot/git.d.ts +2 -2
  88. package/dist/core/worktree-snapshot/git.d.ts.map +1 -1
  89. package/dist/core/worktree-snapshot/git.js +2 -5
  90. package/dist/core/worktree-snapshot/git.js.map +1 -1
  91. package/dist/core/worktree-snapshot/index.d.ts +1 -0
  92. package/dist/core/worktree-snapshot/index.d.ts.map +1 -1
  93. package/dist/core/worktree-snapshot/index.js +1 -0
  94. package/dist/core/worktree-snapshot/index.js.map +1 -1
  95. package/dist/core/worktree-snapshot/restore.d.ts.map +1 -1
  96. package/dist/core/worktree-snapshot/restore.js +18 -2
  97. package/dist/core/worktree-snapshot/restore.js.map +1 -1
  98. package/dist/index.d.ts +3 -2
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +1 -0
  101. package/dist/index.js.map +1 -1
  102. package/dist/modes/interactive/chat-autocomplete.d.ts +7 -0
  103. package/dist/modes/interactive/chat-autocomplete.d.ts.map +1 -0
  104. package/dist/modes/interactive/chat-autocomplete.js +85 -0
  105. package/dist/modes/interactive/chat-autocomplete.js.map +1 -0
  106. package/dist/modes/interactive/components/task-transcript-page.d.ts.map +1 -1
  107. package/dist/modes/interactive/components/task-transcript-page.js +8 -0
  108. package/dist/modes/interactive/components/task-transcript-page.js.map +1 -1
  109. package/dist/modes/interactive/interactive-autocomplete.js +3 -79
  110. package/dist/modes/interactive/interactive-autocomplete.js.map +1 -1
  111. package/dist/modes/interactive/skill-command-autocomplete.d.ts +6 -0
  112. package/dist/modes/interactive/skill-command-autocomplete.d.ts.map +1 -1
  113. package/dist/modes/interactive/skill-command-autocomplete.js +18 -2
  114. package/dist/modes/interactive/skill-command-autocomplete.js.map +1 -1
  115. package/docs/background-tasks.md +1 -1
  116. package/docs/intercom/operations.md +4 -4
  117. package/docs/intercom/reference.md +39 -8
  118. package/docs/intercom.md +26 -9
  119. package/docs/skills.md +3 -1
  120. package/docs/subagents.md +2 -0
  121. package/docs/workflows/api-reference.md +3 -3
  122. package/docs/workflows/operations.md +2 -2
  123. package/docs/worktree-snapshots.md +10 -4
  124. package/npm-shrinkwrap.json +32 -32
  125. package/package.json +3 -3
@@ -2,16 +2,18 @@ import { existsSync } from "node:fs";
2
2
  import { stat } from "node:fs/promises";
3
3
  import { isAbsolute, relative, resolve, sep } from "node:path";
4
4
  import { getBranchPath, getSessionLeafId } from "./session-manager-history.js";
5
+ import { restoreBestWorktree, unrestoredRecord } from "./worktree-snapshot/best-restore.js";
5
6
  import { snapshotBlobHashes } from "./worktree-snapshot/blob-store.js";
6
7
  import { captureWorktreeSnapshot, locateCheckout, withScratchDirectory, writeWorkingTree, } from "./worktree-snapshot/capture.js";
7
8
  import { sha256Hex } from "./worktree-snapshot/env-hash.js";
8
- import { findWorkspaceError, isGitUnavailableError, isWorkspaceDriftError, isWorkspaceError, isWorkspaceRestoreError, isWorkspaceSnapshotError, unreadablePathError, WorkspaceDriftError, WorkspaceRestoreError, WorkspaceSnapshotError, } from "./worktree-snapshot/errors.js";
9
+ import { findWorkspaceError, isGitUnavailableError, isWorkspaceDriftError, isWorkspaceSnapshotError, unreadablePathError, WorkspaceDriftError, WorkspaceRestoreError, WorkspaceSnapshotError, } from "./worktree-snapshot/errors.js";
9
10
  import { scheduleSnapshotCollection } from "./worktree-snapshot/garbage.js";
10
11
  import { gitText, runGit } from "./worktree-snapshot/git.js";
11
12
  import { isHeadOnlyAdvance } from "./worktree-snapshot/head-advance.js";
12
13
  import { canonicalizeWorktreePath } from "./worktree-snapshot/paths.js";
13
14
  import { loadSnapshotPathPolicy } from "./worktree-snapshot/policy.js";
14
- import { isDegradableRestoreFailure, removeRestoredWorktree, restoreDegradedWorktree, restoreWorktree, snapshotRestoreWarnings, verifyWorktree, } from "./worktree-snapshot/restore.js";
15
+ import { removeRestoredWorktree, snapshotRestoreWarnings, verifyWorktree } from "./worktree-snapshot/restore.js";
16
+ export { isRecoverableRestoreFailure } from "./worktree-snapshot/best-restore.js";
15
17
  /** Built-in tools that can change files: a turn that called one records a snapshot. */
16
18
  export const FILE_WRITING_TOOLS = new Set(["bash", "edit", "write", "powershell"]);
17
19
  const PATH_TOOLS = new Set(["edit", "write"]);
@@ -209,17 +211,9 @@ export function currentWorktreeSnapshots(sessionManager) {
209
211
  return current;
210
212
  }
211
213
  /**
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.
214
+ * The commits of every earlier snapshot of the checkout on the branch, newest first and each once, to restore when its
215
+ * own is out of reach (#4744). The restore stops at the first it holds or fetches, so a nearer one costs no more.
215
216
  */
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
217
  function earlierSnapshotHeads(sessionManager, original, mappings, snapshot) {
224
218
  const records = sessionManager.getWorktreeSnapshotRecords();
225
219
  const heads = [];
@@ -227,46 +221,10 @@ function earlierSnapshotHeads(sessionManager, original, mappings, snapshot) {
227
221
  if (entry.type !== "worktree_snapshot" || originalRoot(entry.root, mappings) !== original)
228
222
  continue;
229
223
  const head = records.get(entry.snapshotId)?.head;
230
- if (head !== undefined && head !== snapshot.head && !heads.includes(head))
224
+ if (head !== undefined && head !== snapshot.head)
231
225
  heads.push(head);
232
- if (heads.length === 3)
233
- break;
234
226
  }
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
- };
227
+ return [...new Set(heads)];
270
228
  }
271
229
  /**
272
230
  * Checks the latest recorded snapshot of each checkout on the active session branch. Drifted or missing checkouts are
@@ -353,38 +311,24 @@ export async function resumeSessionWorktree(sessionManager, options) {
353
311
  const blobs = sessionSnapshotBlobs(sessionManager.getSessionStore().snapshotBlobs, sessionManager.getEntries());
354
312
  let restored;
355
313
  try {
356
- restored = await restoreWorktree(snapshot, { blobs, storeDir: options.storeDir, signal: options.signal });
314
+ // The exact state, else the best this host can restore, else continue without the checkout.
315
+ const best = await restoreBestWorktree(snapshot, {
316
+ blobs,
317
+ storeDir: options.storeDir,
318
+ signal: options.signal,
319
+ candidates: earlierSnapshotHeads(sessionManager, original, existing, snapshot),
320
+ });
321
+ if (best.status === "unrestored") {
322
+ left.push({ root, snapshot, reason: best.reason });
323
+ continue;
324
+ }
325
+ restored = best;
357
326
  }
358
327
  catch (error) {
359
328
  options.signal?.throwIfAborted();
360
329
  if (!(error instanceof Error))
361
330
  throw error;
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;
331
+ throw refused(error);
388
332
  }
389
333
  const mapping = {
390
334
  from: root,
@@ -415,20 +359,7 @@ export async function resumeSessionWorktree(sessionManager, options) {
415
359
  const launch = recordedHere && !existsSync(continuing) && options.fallbackCwd !== undefined;
416
360
  continuedIn = launch ? resolve(options.fallbackCwd) : continuing;
417
361
  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
- };
362
+ const record = unrestoredRecord(checkout.snapshot, checkout.reason, continuedIn, launch ? "launch" : "recorded");
432
363
  await sessionManager.appendWorktreeSnapshot(checkout.root, checkout.snapshot.id, undefined, undefined, [], record);
433
364
  unrestored.push({ ...checkout, record });
434
365
  }
@@ -494,12 +425,12 @@ function short(id) {
494
425
  return id.slice(0, 12);
495
426
  }
496
427
  /** What a degraded restore checked out, for its notice. */
497
- function degradedBasis(degraded, snapshot) {
428
+ function degradedBasis(degraded, snapshot, owner) {
498
429
  switch (degraded.basis) {
499
430
  case "pushed-base":
500
431
  return `the last pushed commit before it, ${short(degraded.head)}`;
501
432
  case "earlier-snapshot":
502
- return `${short(degraded.head)}, the commit of an earlier snapshot of this session`;
433
+ return `${short(degraded.head)}, the commit of an earlier snapshot of this ${owner}`;
503
434
  default:
504
435
  return `${short(degraded.head)}, the tip of ${snapshot?.branch ? `branch ${snapshot.branch}` : "the default branch"} on its remote`;
505
436
  }
@@ -513,14 +444,14 @@ function listed(items, limit = 5) {
513
444
  * The one notice for a worktree restored with less than its snapshot (#4733): what it holds, what is missing and what
514
445
  * to do to get the rest.
515
446
  */
516
- export function formatDegradedRestoreNotice(mapping, snapshot, warnings = []) {
447
+ export function formatDegradedRestoreNotice(mapping, snapshot, warnings = [], owner = "session") {
517
448
  const lfs = warnings
518
449
  .filter((warning) => warning.code === "lfs-objects-unavailable")
519
450
  .map((warning) => ` ${formatWorktreeRestoreWarning(warning)}.`)
520
451
  .join("");
521
- return `${degradedRestoreSummary(mapping, snapshot)}${lfs}`;
452
+ return `${degradedRestoreSummary(mapping, snapshot, owner)}${lfs}`;
522
453
  }
523
- function degradedRestoreSummary(mapping, snapshot) {
454
+ function degradedRestoreSummary(mapping, snapshot, owner) {
524
455
  const degraded = mapping.degraded;
525
456
  const links = snapshot?.chain.length ?? 0;
526
457
  const restored = `Restored ${mapping.from} into ${mapping.to}`;
@@ -534,15 +465,19 @@ function degradedRestoreSummary(mapping, snapshot) {
534
465
  const commits = degraded.missingCommits.length;
535
466
  const recorded = snapshot === undefined ? "" : ` instead of the recorded commit ${short(snapshot.head)}`;
536
467
  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}`;
468
+ return `${restored} at ${degradedBasis(degraded, snapshot, owner)}${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
469
  }
539
470
  /** The notice for a checkout whose snapshot the session holds no record of, which a resume continued without. */
540
471
  export function formatMissingRecordNotice(missing) {
541
472
  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
473
  }
543
474
  /** 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";
475
+ export function formatUnrestoredNotice(root, unrestored, owner = "session") {
476
+ const place = unrestored.place === "launch"
477
+ ? "the directory the resume started from"
478
+ : owner === "session"
479
+ ? "the session's own directory"
480
+ : "the run's own directory";
546
481
  return `Continuing in ${unrestored.continuedIn} (${place}) without restoring ${root} from snapshot ${short(unrestored.snapshotId)}: ${unrestored.detail}. ${unrestored.hint}`.trimEnd();
547
482
  }
548
483
  /**