@sideboard-ai/core 0.1.347 → 0.1.349

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 (41) hide show
  1. package/dist/agents/cursor-runner.js +3 -3
  2. package/dist/{agents-5MFGVK7C.js → agents-AZ2PV6XP.js} +7 -7
  3. package/dist/{agents-T4XBZZDA.js → agents-DMPBFF3F.js} +5 -5
  4. package/dist/{chunk-UGUWFONI.js → chunk-2E2HMJDU.js} +1 -1
  5. package/dist/{chunk-NTY5WGRD.js → chunk-3DBL2C45.js} +1 -1
  6. package/dist/{chunk-MOUAM6ZC.js → chunk-6RIPZ73M.js} +132 -2
  7. package/dist/{chunk-6TV6L2DD.js → chunk-CATTIFSP.js} +6 -5
  8. package/dist/{chunk-IJNTTVFH.js → chunk-IRFBD6GU.js} +247 -66
  9. package/dist/{chunk-ORO4ENZR.js → chunk-LESWJ7L4.js} +1 -0
  10. package/dist/{chunk-XNGW4OYD.js → chunk-MHSBF3SO.js} +6 -5
  11. package/dist/{chunk-ZJMYCDYQ.js → chunk-MVFFLU5V.js} +47 -9
  12. package/dist/{chunk-OPXEJJBM.js → chunk-PWOFUPYM.js} +1 -0
  13. package/dist/{chunk-27XWAI7S.js → chunk-Q4I6KDOL.js} +251 -70
  14. package/dist/{chunk-2HPVGTHF.js → chunk-QHXZKHUL.js} +1 -1
  15. package/dist/{chunk-GAGTEI6B.js → chunk-ROXM6QZV.js} +48 -10
  16. package/dist/{chunk-ATS7SYHG.js → chunk-RPHH4FNK.js} +132 -2
  17. package/dist/{chunk-Y6VQX2LY.js → chunk-WHMLMCPU.js} +11 -5
  18. package/dist/{chunk-BIM24I3O.js → chunk-WWBPK7GB.js} +1 -1
  19. package/dist/{chunk-5YCKATG6.js → chunk-YVN7L4KG.js} +1 -1
  20. package/dist/{chunk-Q4TZA4MN.js → chunk-ZXI5DR5S.js} +12 -6
  21. package/dist/{conductor-EMGMDNHL.js → conductor-65VPUPOW.js} +6 -6
  22. package/dist/{conductor-LYQKONSA.js → conductor-NHC6X74J.js} +5 -5
  23. package/dist/{coordinator-prompt-DLY3FS2L.js → coordinator-prompt-5GZWIVSY.js} +3 -3
  24. package/dist/{coordinator-prompt-WALVMGKI.js → coordinator-prompt-R2PURZL3.js} +3 -3
  25. package/dist/{global-workspace-UG2A3CEM.js → global-workspace-64KC7PST.js} +3 -3
  26. package/dist/{global-workspace-7OQ5O6JT.js → global-workspace-UEECLWSX.js} +3 -3
  27. package/dist/index.cjs +1321 -858
  28. package/dist/index.d.cts +31 -8
  29. package/dist/index.d.ts +31 -8
  30. package/dist/index.js +446 -365
  31. package/dist/mcp/run-stdio.cjs +1055 -594
  32. package/dist/mcp/run-stdio.js +296 -216
  33. package/dist/{orchestrator-AJZNVREM.js → orchestrator-I5G5A5BV.js} +7 -7
  34. package/dist/{orchestrator-BUEPWNCF.js → orchestrator-Y5PYSMR6.js} +9 -9
  35. package/dist/{thread-store-R3G5VBII.js → thread-store-HZ4U4OXB.js} +1 -1
  36. package/dist/{thread-store-MEUWZDVV.js → thread-store-QKNU5CHM.js} +1 -1
  37. package/dist/{workspaces-KWGTP7DI.js → workspaces-6TIM2TM2.js} +3 -3
  38. package/dist/{workspaces-35T6FW57.js → workspaces-I2EHNTFE.js} +3 -3
  39. package/dist/{worktree-ROJXGBWS.js → worktree-7JFYDNUX.js} +2 -2
  40. package/dist/{worktree-5P7SCST3.js → worktree-M2GJGK2P.js} +2 -2
  41. package/package.json +1 -1
@@ -14,7 +14,7 @@ import {
14
14
  parseSessionQuotaResetAt,
15
15
  planModeTurnInstruction,
16
16
  resolveQuotaFallbackAgent
17
- } from "./chunk-Y6VQX2LY.js";
17
+ } from "./chunk-WHMLMCPU.js";
18
18
  import {
19
19
  applyWorktreePkgCacheEnv,
20
20
  askBlockStillWaiting,
@@ -54,7 +54,7 @@ import {
54
54
  worktreeDevProcessKey,
55
55
  worktreeRunProcessKey,
56
56
  worktreeSetupProcessKey
57
- } from "./chunk-ZJMYCDYQ.js";
57
+ } from "./chunk-MVFFLU5V.js";
58
58
  import {
59
59
  applyAgentEvent,
60
60
  clipAgentEventForPaint,
@@ -81,7 +81,7 @@ import {
81
81
  summarizeTurnStderr,
82
82
  toolDescription,
83
83
  turnFailChatText
84
- } from "./chunk-ORO4ENZR.js";
84
+ } from "./chunk-LESWJ7L4.js";
85
85
  import {
86
86
  titleFromPrompt
87
87
  } from "./chunk-LX5R5JOR.js";
@@ -121,7 +121,7 @@ import {
121
121
  stageAbsolutePathsAsAttachments,
122
122
  stageBuffersAsAttachments,
123
123
  syncWorkspacesFromThreads
124
- } from "./chunk-6TV6L2DD.js";
124
+ } from "./chunk-CATTIFSP.js";
125
125
  import {
126
126
  addPrStackLayer,
127
127
  allocateTeamSlug,
@@ -172,7 +172,7 @@ import {
172
172
  resolveRepoRoot,
173
173
  switchWorktreeBranch,
174
174
  withRepoGitLock
175
- } from "./chunk-2HPVGTHF.js";
175
+ } from "./chunk-QHXZKHUL.js";
176
176
  import {
177
177
  issueActivityKind
178
178
  } from "./chunk-OYRN356W.js";
@@ -188,7 +188,9 @@ import {
188
188
  REVIEW_TAB_TITLE,
189
189
  agentNicknameFromWorktreePath,
190
190
  appendMessage,
191
+ ciChecksSettled,
191
192
  createEmptyThread,
193
+ decideFollowUps,
192
194
  deleteSchedule,
193
195
  deleteThreadRecord,
194
196
  findThreadByRef,
@@ -200,6 +202,8 @@ import {
200
202
  isWorktreeIdentityTitle,
201
203
  listSchedules,
202
204
  listThreads,
205
+ mergeFollowUpPoll,
206
+ normalizeChatFollowUps,
203
207
  normalizeWorkspaceTags,
204
208
  normalizeWorktreePath,
205
209
  readThread,
@@ -215,7 +219,7 @@ import {
215
219
  worktreeNameFromPath,
216
220
  worktreeSlugForTicket,
217
221
  writeThread
218
- } from "./chunk-MOUAM6ZC.js";
222
+ } from "./chunk-6RIPZ73M.js";
219
223
  import {
220
224
  HISTORY_CLEANUP_INTERVAL_HOURS_DEFAULT,
221
225
  applyTurnUsage,
@@ -379,19 +383,19 @@ function traceTurn(phase, extra) {
379
383
  }
380
384
  }
381
385
  async function withTimeout(promise, ms, label) {
382
- let timer2;
386
+ let timer3;
383
387
  try {
384
388
  return await Promise.race([
385
389
  promise,
386
390
  new Promise((_, reject) => {
387
- timer2 = setTimeout(
391
+ timer3 = setTimeout(
388
392
  () => reject(new Error(`${label} timed out after ${ms}ms`)),
389
393
  ms
390
394
  );
391
395
  })
392
396
  ]);
393
397
  } finally {
394
- if (timer2) clearTimeout(timer2);
398
+ if (timer3) clearTimeout(timer3);
395
399
  }
396
400
  }
397
401
 
@@ -504,11 +508,11 @@ function parentKey(event) {
504
508
  function createAgentStreamCoalescer(emit, opts) {
505
509
  const intervalMs = opts?.intervalMs ?? 32;
506
510
  let pending = null;
507
- let timer2 = null;
511
+ let timer3 = null;
508
512
  const flush2 = () => {
509
- if (timer2) {
510
- clearTimeout(timer2);
511
- timer2 = null;
513
+ if (timer3) {
514
+ clearTimeout(timer3);
515
+ timer3 = null;
512
516
  }
513
517
  if (!pending) return;
514
518
  const event = pending;
@@ -520,9 +524,9 @@ function createAgentStreamCoalescer(emit, opts) {
520
524
  });
521
525
  };
522
526
  const schedule = () => {
523
- if (timer2) return;
524
- timer2 = setTimeout(flush2, intervalMs);
525
- timer2.unref?.();
527
+ if (timer3) return;
528
+ timer3 = setTimeout(flush2, intervalMs);
529
+ timer3.unref?.();
526
530
  };
527
531
  return {
528
532
  push(event) {
@@ -571,9 +575,9 @@ async function spawnAgentTurn(thread, input, onEvent) {
571
575
  `Cannot spawn ${thread.agent}: thread ${thread.id} has no worktreePath`
572
576
  );
573
577
  }
574
- const { isGlobalThread: isGlobalThread2 } = await import("./global-workspace-7OQ5O6JT.js");
578
+ const { isGlobalThread: isGlobalThread2 } = await import("./global-workspace-UEECLWSX.js");
575
579
  if (isGlobalThread2(thread)) {
576
- const { ensureGlobalCoordinatorCwd: ensureGlobalCoordinatorCwd2 } = await import("./coordinator-prompt-WALVMGKI.js");
580
+ const { ensureGlobalCoordinatorCwd: ensureGlobalCoordinatorCwd2 } = await import("./coordinator-prompt-R2PURZL3.js");
577
581
  ensureGlobalCoordinatorCwd2(
578
582
  isOrchestratorThread(thread) ? { orchestratorThreadId: thread.id } : void 0
579
583
  );
@@ -771,14 +775,97 @@ async function spawnAgentTurn(thread, input, onEvent) {
771
775
  }
772
776
  };
773
777
  signal("SIGTERM");
774
- const timer2 = setTimeout(() => signal("SIGKILL"), 5e3);
775
- timer2.unref?.();
776
- child.once("exit", () => clearTimeout(timer2));
778
+ const timer3 = setTimeout(() => signal("SIGKILL"), 5e3);
779
+ timer3.unref?.();
780
+ child.once("exit", () => clearTimeout(timer3));
777
781
  },
778
782
  done
779
783
  };
780
784
  }
781
785
 
786
+ // src/git/worktree-leftovers.ts
787
+ var LEFTOVER_REF_PREFIX = "refs/sideboard/leftovers/";
788
+ function leftoverRefName(branch) {
789
+ const safe = branch.trim().replace(/[^A-Za-z0-9._/-]+/g, "-") || "branch";
790
+ return `${LEFTOVER_REF_PREFIX}${safe}`;
791
+ }
792
+ function gitFailure(result, fallback) {
793
+ const text3 = (result.stderr || result.stdout).trim();
794
+ return text3 || fallback;
795
+ }
796
+ async function restoreIndex(worktreePath, treeSha) {
797
+ await git(["read-tree", "--reset", treeSha], worktreePath, { reject: false });
798
+ }
799
+ async function saveWorktreeLeftovers(repoPath, worktreePath, branch) {
800
+ const status = await git(["status", "--porcelain"], worktreePath, { reject: false });
801
+ if (status.exitCode !== 0) {
802
+ return { ok: false, error: gitFailure(status, "git status failed") };
803
+ }
804
+ if (!status.stdout.trim()) return { ok: true, ref: null };
805
+ const indexBefore = await git(["write-tree"], worktreePath, { reject: false });
806
+ const indexSha = indexBefore.stdout.trim();
807
+ if (indexBefore.exitCode !== 0 || !/^[0-9a-f]{7,64}$/i.test(indexSha)) {
808
+ return { ok: false, error: gitFailure(indexBefore, "git write-tree failed") };
809
+ }
810
+ const fail = async (result, fallback) => {
811
+ await restoreIndex(worktreePath, indexSha);
812
+ return { ok: false, error: gitFailure(result, fallback) };
813
+ };
814
+ const added = await git(["add", "-A"], worktreePath, { reject: false });
815
+ if (added.exitCode !== 0) return fail(added, "git add failed");
816
+ const tree = await git(["write-tree"], worktreePath, { reject: false });
817
+ const treeSha = tree.stdout.trim();
818
+ if (tree.exitCode !== 0 || !/^[0-9a-f]{7,64}$/i.test(treeSha)) {
819
+ return fail(tree, "git write-tree failed");
820
+ }
821
+ const head = await git(["rev-parse", "HEAD"], worktreePath, { reject: false });
822
+ const parent = head.stdout.trim();
823
+ if (head.exitCode !== 0 || !parent) return fail(head, "git rev-parse HEAD failed");
824
+ const commit = await git(
825
+ ["commit-tree", treeSha, "-p", parent, "-m", "sideboard leftover"],
826
+ worktreePath,
827
+ { reject: false }
828
+ );
829
+ const sha = commit.stdout.trim();
830
+ if (commit.exitCode !== 0 || !/^[0-9a-f]{7,64}$/i.test(sha)) {
831
+ return fail(commit, "git commit-tree failed");
832
+ }
833
+ const ref = leftoverRefName(branch);
834
+ const updated = await git(["update-ref", ref, sha], repoPath, { reject: false });
835
+ if (updated.exitCode !== 0) return fail(updated, "git update-ref failed");
836
+ await git(["reset"], worktreePath, { reject: false });
837
+ return { ok: true, ref };
838
+ }
839
+ async function applyWorktreeLeftovers(repoPath, worktreePath, branch) {
840
+ const ref = leftoverRefName(branch);
841
+ const shown = await git(["rev-parse", "--verify", "--quiet", ref], repoPath, { reject: false });
842
+ const sha = shown.stdout.trim();
843
+ if (shown.exitCode !== 0 || !sha) return false;
844
+ const restored = await git(["restore", "--source", sha, "--worktree", "--", "."], worktreePath, {
845
+ reject: false
846
+ });
847
+ if (restored.exitCode !== 0) return false;
848
+ await git(["update-ref", "-d", ref], repoPath, { reject: false });
849
+ return true;
850
+ }
851
+ async function deleteWorktreeLeftovers(repoPath, branch) {
852
+ await git(["update-ref", "-d", leftoverRefName(branch)], repoPath, { reject: false });
853
+ }
854
+ function archiveClearingFollowUps(id) {
855
+ const archived = setStatus(id, "archived");
856
+ if ((archived.followUps?.length ?? 0) === 0) return archived;
857
+ return updateThread(archived.id, { followUps: [] });
858
+ }
859
+ async function removeWorktreeSavingLeftovers(thread) {
860
+ const saved = await saveWorktreeLeftovers(thread.repoPath, thread.worktreePath, thread.branchName);
861
+ if (!saved.ok) throw new Error(`Could not save uncommitted files: ${saved.error}`);
862
+ await removeWorktree(thread.repoPath, thread.worktreePath);
863
+ }
864
+ async function removeWorktreeDroppingLeftovers(thread, deleteBranch) {
865
+ await removeWorktree(thread.repoPath, thread.worktreePath, { deleteBranch });
866
+ await deleteWorktreeLeftovers(thread.repoPath, thread.branchName).catch(() => void 0);
867
+ }
868
+
782
869
  // src/git/agent-git-actions.ts
783
870
  var AGENT_GIT_ACTIONS = [
784
871
  "commit-push",
@@ -1115,9 +1202,9 @@ function emptySetupLog() {
1115
1202
  }
1116
1203
  var PERSIST_DEBOUNCE_MS = 500;
1117
1204
  function persistNow(threadId) {
1118
- const timer2 = persistTimers.get(threadId);
1119
- if (timer2) {
1120
- clearTimeout(timer2);
1205
+ const timer3 = persistTimers.get(threadId);
1206
+ if (timer3) {
1207
+ clearTimeout(timer3);
1121
1208
  persistTimers.delete(threadId);
1122
1209
  }
1123
1210
  const mem = memory.get(threadId);
@@ -1266,9 +1353,9 @@ function sliceRunLogOutput(output, tailChars = DEFAULT_RUN_LOG_TAIL_CHARS) {
1266
1353
  }
1267
1354
  var PERSIST_DEBOUNCE_MS2 = 500;
1268
1355
  function persistNow2(key) {
1269
- const timer2 = persistTimers2.get(key);
1270
- if (timer2) {
1271
- clearTimeout(timer2);
1356
+ const timer3 = persistTimers2.get(key);
1357
+ if (timer3) {
1358
+ clearTimeout(timer3);
1272
1359
  persistTimers2.delete(key);
1273
1360
  }
1274
1361
  const mem = memory2.get(key);
@@ -2215,6 +2302,10 @@ function resolveStopReason(opts) {
2215
2302
  if (opts?.clearQueue === false) return "Stopped by the user";
2216
2303
  return "Stopped (queue cleared)";
2217
2304
  }
2305
+ function isRoutineStopNote(err) {
2306
+ const text3 = err?.trim() ?? "";
2307
+ return text3 === "Stopped" || text3 === "Stopped by the user" || text3 === "Stopped (queue cleared)" || text3 === "Stopped to send the next prompt";
2308
+ }
2218
2309
  function reasonToKeepOnStop(existing, incoming) {
2219
2310
  const next = incoming?.trim();
2220
2311
  if (next) return next.slice(0, STOP_REASON_MAX);
@@ -2222,6 +2313,16 @@ function reasonToKeepOnStop(existing, incoming) {
2222
2313
  if (prior) return prior.slice(0, STOP_REASON_MAX);
2223
2314
  return "Stopped";
2224
2315
  }
2316
+ function turnFinishedEvent(threadId, exitCode, userStopped, lastError) {
2317
+ const note = lastError?.trim() ?? "";
2318
+ const routineStop = userStopped && (note.length === 0 || isRoutineStopNote(note));
2319
+ return {
2320
+ type: "turn_finished",
2321
+ threadId,
2322
+ exitCode,
2323
+ ...routineStop ? { routineStop: true } : {}
2324
+ };
2325
+ }
2225
2326
  function writeStoppedStatus(threadId, reason) {
2226
2327
  const latest = readThread(threadId);
2227
2328
  if (!latest || latest.status === "archived") return latest;
@@ -3459,11 +3560,11 @@ function createLineCoalescer(onChunk, opts) {
3459
3560
  const delayMs = opts?.delayMs ?? 50;
3460
3561
  const maxLines = opts?.maxLines ?? 200;
3461
3562
  let buffer = [];
3462
- let timer2 = null;
3563
+ let timer3 = null;
3463
3564
  const flush2 = () => {
3464
- if (timer2) {
3465
- clearTimeout(timer2);
3466
- timer2 = null;
3565
+ if (timer3) {
3566
+ clearTimeout(timer3);
3567
+ timer3 = null;
3467
3568
  }
3468
3569
  if (buffer.length === 0) return;
3469
3570
  const chunk = buffer.join("\n");
@@ -3476,7 +3577,7 @@ function createLineCoalescer(onChunk, opts) {
3476
3577
  flush2();
3477
3578
  return;
3478
3579
  }
3479
- if (!timer2) timer2 = setTimeout(flush2, delayMs);
3580
+ if (!timer3) timer3 = setTimeout(flush2, delayMs);
3480
3581
  };
3481
3582
  return { push, flush: flush2 };
3482
3583
  }
@@ -3937,7 +4038,7 @@ async function adoptThread(input) {
3937
4038
  messages: input.messages ?? []
3938
4039
  });
3939
4040
  writeThread(thread);
3940
- const { addWorkspace: addWorkspace2 } = await import("./workspaces-KWGTP7DI.js");
4041
+ const { addWorkspace: addWorkspace2 } = await import("./workspaces-6TIM2TM2.js");
3941
4042
  await addWorkspace2(repoPath);
3942
4043
  const { ensureWorktreeSideboardIgnored } = await import("./worktree-exclude-KMZQXZKP.js");
3943
4044
  await ensureWorktreeSideboardIgnored(input.worktreePath);
@@ -6044,6 +6145,9 @@ function livePartsShowAgentReply(parts) {
6044
6145
  }
6045
6146
 
6046
6147
  // src/orchestrator/enqueue-thread-send.ts
6148
+ function sendFollowUpInterrupts(followUp, busy) {
6149
+ return followUp === "steer" && busy;
6150
+ }
6047
6151
  function resolveSendFollowUp(thread, requested) {
6048
6152
  if (requested === "steer" || requested === "queue") return requested;
6049
6153
  return isOrchestratorThread(thread) ? followUpBehavior() : "queue";
@@ -6130,14 +6234,20 @@ async function enqueueThreadSend(host, threadRef, prompt, opts) {
6130
6234
  if (current.status === "archived") {
6131
6235
  throw new Error(`Thread is archived: ${thread.id}`);
6132
6236
  }
6133
- const followUp = resolveSendFollowUp(current, opts?.followUp);
6237
+ const requested = opts?.followUp;
6238
+ const join15 = requested === "join";
6239
+ const followUp = resolveSendFollowUp(
6240
+ current,
6241
+ join15 ? "steer" : requested
6242
+ );
6134
6243
  const explicit = opts?.attachments;
6135
6244
  const consumed = explicit !== void 0 ? { attachments: current.attachments, consumed: explicit } : consumeComposerAttachments(current);
6136
6245
  const inFlightEarly = host.activeTurns.has(thread.id) || host.startingTurns.has(thread.id) || current.status === "running";
6137
6246
  const agentHasRepliedEarly = livePartsShowAgentReply(readTurnLiveParts(current.id));
6138
6247
  const draft = host.openSteerPrompt.get(current.id);
6139
6248
  const queuedHead = !inFlightEarly && current.status === "queued" && current.queue.length > 0 ? current.queue[0] : null;
6140
- const unanswered = followUp === "steer" && !agentHasRepliedEarly ? draft?.text ?? (inFlightEarly ? trailingUnansweredUserText(current.messages) : queuedHead) : null;
6249
+ const joinCanMerge = draft != null && !draft.spawned || !inFlightEarly && queuedHead != null;
6250
+ const unanswered = followUp === "steer" && !agentHasRepliedEarly && (!join15 || joinCanMerge) ? draft?.text ?? (inFlightEarly ? trailingUnansweredUserText(current.messages) : queuedHead) : null;
6141
6251
  if (unanswered != null && (draft ? !draft.spawned : queuedHead != null)) {
6142
6252
  clearSendBookkeeping(host, thread.id);
6143
6253
  const combined = joinSteerPrompt(unanswered, prompt);
@@ -6188,7 +6298,10 @@ async function enqueueThreadSend(host, threadRef, prompt, opts) {
6188
6298
  );
6189
6299
  clearSendBookkeeping(host, thread.id);
6190
6300
  const inFlight = host.activeTurns.has(thread.id) || host.startingTurns.has(thread.id) || current.status === "running";
6191
- shouldSteer = followUp === "steer" && (inFlight || current.queue.length > 0);
6301
+ shouldSteer = sendFollowUpInterrupts(
6302
+ join15 ? "join" : followUp,
6303
+ inFlight || current.queue.length > 0
6304
+ );
6192
6305
  const patch = queued;
6193
6306
  if (explicit === void 0 && consumed.consumed.length > 0) {
6194
6307
  patch.attachments = consumed.attachments;
@@ -6409,7 +6522,7 @@ function formatWorktreeDirective(thread, opts) {
6409
6522
  lines.push(formatDevAccessHint(opts?.activeRuns));
6410
6523
  lines.push("");
6411
6524
  lines.push(
6412
- "Automations (sidebar, after Board): `create_schedule` / `list_schedules` (`at` / `every` / `cron` / `time`+`days`). `archiveChat=false` keeps the new chat. `chatId=self` is removed when this chat is archived. Fires only while Sideboard.app is running. Future jobs turn on Caffeinate."
6525
+ "Automations (sidebar, after Board): `create_schedule` / `list_schedules` (`at` / `every` / `cron` / `time`+`days`). `archiveChat=false` keeps the new chat. `chatId=self` is removed when this chat is archived. Fires only while Sideboard.app is running. Future jobs turn on Caffeinate. `create_follow_up` (ci|at) waits behind this turn."
6413
6526
  );
6414
6527
  lines.push(
6415
6528
  "`set_workspace_tags` labels this checkout (omit ref). `set_wake_on_github_edges` opts this checkout in when Advanced is already on (omit ref)."
@@ -7527,11 +7640,11 @@ function realDeps() {
7527
7640
  parentIdForThread,
7528
7641
  designatedId: designatedOrchestratorId,
7529
7642
  send: async (threadId, prompt) => {
7530
- const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-AJZNVREM.js");
7643
+ const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-I5G5A5BV.js");
7531
7644
  await getOrchestrator2().send(threadId, prompt, { followUp: "queue" });
7532
7645
  },
7533
7646
  startOrchestration: async (prompt) => {
7534
- const { startOrchestration: startOrchestration2 } = await import("./orchestrator-AJZNVREM.js");
7647
+ const { startOrchestration: startOrchestration2 } = await import("./orchestrator-I5G5A5BV.js");
7535
7648
  const defaults = resolveOrchestratorDefaults();
7536
7649
  await startOrchestration2({
7537
7650
  goal: prompt,
@@ -7558,7 +7671,7 @@ function formatScheduledPrompt(name, prompt) {
7558
7671
  ${prompt}`;
7559
7672
  }
7560
7673
  async function defaultDeps() {
7561
- const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-AJZNVREM.js");
7674
+ const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-I5G5A5BV.js");
7562
7675
  const orch = getOrchestrator2();
7563
7676
  return {
7564
7677
  findThread: (id) => findThreadByRef(id),
@@ -7658,8 +7771,8 @@ async function fireSchedule(id) {
7658
7771
  }
7659
7772
  }
7660
7773
  function clearTimer(id) {
7661
- const timer2 = timers.get(id);
7662
- if (timer2) clearTimeout(timer2);
7774
+ const timer3 = timers.get(id);
7775
+ if (timer3) clearTimeout(timer3);
7663
7776
  timers.delete(id);
7664
7777
  }
7665
7778
  function armOne(schedule) {
@@ -7675,7 +7788,7 @@ function armOne(schedule) {
7675
7788
  return;
7676
7789
  }
7677
7790
  const capped = Math.min(delay, SET_TIMEOUT_MAX);
7678
- const timer2 = setTimeout(() => {
7791
+ const timer3 = setTimeout(() => {
7679
7792
  timers.delete(schedule.id);
7680
7793
  const live = getSchedule(schedule.id);
7681
7794
  if (!live?.enabled) return;
@@ -7688,7 +7801,7 @@ function armOne(schedule) {
7688
7801
  if (isThisProcessDesktopHost()) armSchedules();
7689
7802
  });
7690
7803
  }, capped);
7691
- timers.set(schedule.id, timer2);
7804
+ timers.set(schedule.id, timer3);
7692
7805
  }
7693
7806
  function armSchedules() {
7694
7807
  if (!isThisProcessDesktopHost()) return;
@@ -7705,6 +7818,75 @@ function armSchedules() {
7705
7818
  }
7706
7819
  }
7707
7820
 
7821
+ // src/orchestrator/chat-follow-up-runner.ts
7822
+ var POLL_MS = 6e4;
7823
+ var timer2 = null;
7824
+ var polling2 = false;
7825
+ async function ciPhase(thread) {
7826
+ const selector = resolvePrSelector(thread);
7827
+ if (!selector || !thread.worktreePath?.trim()) return "none";
7828
+ try {
7829
+ const checks = await getPrCiChecks(thread.worktreePath, selector);
7830
+ return ciChecksSettled(checks);
7831
+ } catch {
7832
+ return "unknown";
7833
+ }
7834
+ }
7835
+ async function pollChatFollowUps(send = defaultSend) {
7836
+ if (polling2) return;
7837
+ polling2 = true;
7838
+ try {
7839
+ const threads = listThreads().filter(
7840
+ (thread) => thread.status !== "archived" && (thread.followUps?.length ?? 0) > 0
7841
+ );
7842
+ for (const thread of threads) {
7843
+ const followUps = thread.followUps ?? [];
7844
+ const ci = followUps.some((item) => item.kind === "ci") ? await ciPhase(thread) : "none";
7845
+ const decision = decideFollowUps({ followUps, now: /* @__PURE__ */ new Date(), ci });
7846
+ const kept = [...decision.keep];
7847
+ const firedIds = [];
7848
+ for (const item of decision.fire) {
7849
+ try {
7850
+ await send(thread.id, `[Follow-up]
7851
+ ${item.prompt}`);
7852
+ firedIds.push(item.id);
7853
+ } catch {
7854
+ kept.push(item);
7855
+ }
7856
+ }
7857
+ const fresh = readThread(thread.id);
7858
+ if (!fresh || fresh.status === "archived") continue;
7859
+ const after = normalizeChatFollowUps(fresh.followUps);
7860
+ const next = mergeFollowUpPoll({
7861
+ before: followUps,
7862
+ after,
7863
+ firedIds,
7864
+ keep: kept
7865
+ });
7866
+ if (JSON.stringify(next) !== JSON.stringify(after)) {
7867
+ updateThread(thread.id, { followUps: next });
7868
+ }
7869
+ }
7870
+ } finally {
7871
+ polling2 = false;
7872
+ }
7873
+ }
7874
+ async function defaultSend(id, prompt) {
7875
+ const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-I5G5A5BV.js");
7876
+ await getOrchestrator2().send(id, prompt, { followUp: "join" });
7877
+ }
7878
+ function armChatFollowUps() {
7879
+ if (!isThisProcessDesktopHost()) return;
7880
+ if (timer2) return;
7881
+ const tick = () => {
7882
+ timer2 = setTimeout(() => {
7883
+ void pollChatFollowUps().finally(tick);
7884
+ }, POLL_MS);
7885
+ };
7886
+ void pollChatFollowUps();
7887
+ tick();
7888
+ }
7889
+
7708
7890
  // src/orchestrator/orchestrator.ts
7709
7891
  var LIVE_TURN_SPAWN_GRACE_MS = 15e3;
7710
7892
  var RUN_SCRIPT_DESKTOP_ADOPT_MS = 2e4;
@@ -7902,6 +8084,7 @@ var Orchestrator = class {
7902
8084
  }
7903
8085
  this.schedulePendingQuotaResumes();
7904
8086
  armSchedules();
8087
+ armChatFollowUps();
7905
8088
  armGithubEdgeWatch();
7906
8089
  }
7907
8090
  /** Surface (and, when enabled, clean up) worktrees git knows about but no thread owns. */
@@ -8033,7 +8216,7 @@ var Orchestrator = class {
8033
8216
  if (!this.shouldReclaimRunningThread(thread)) continue;
8034
8217
  setStatus(thread.id, "stopped", "Process died (agent exited)");
8035
8218
  this.emit({ type: "status_changed", threadId: thread.id, status: "stopped" });
8036
- this.emit({ type: "turn_finished", threadId: thread.id, exitCode: 1 });
8219
+ this.emit(turnFinishedEvent(thread.id, 1, this.stoppedTurns.has(thread.id), readThread(thread.id)?.lastError));
8037
8220
  const latest = readThread(thread.id);
8038
8221
  if (latest) {
8039
8222
  notifyParentOfChildHalt(latest, "stopped", (id, prompt) => this.send(id, prompt));
@@ -8041,8 +8224,8 @@ var Orchestrator = class {
8041
8224
  }
8042
8225
  }
8043
8226
  clearQuotaResumeTimer(threadId) {
8044
- const timer2 = this.quotaResumeTimers.get(threadId);
8045
- if (timer2) clearTimeout(timer2);
8227
+ const timer3 = this.quotaResumeTimers.get(threadId);
8228
+ if (timer3) clearTimeout(timer3);
8046
8229
  this.quotaResumeTimers.delete(threadId);
8047
8230
  }
8048
8231
  /** Schedule (or fire) auto-retry after a provider session/usage limit reset. */
@@ -8051,11 +8234,11 @@ var Orchestrator = class {
8051
8234
  updateThread(threadId, { quotaResumeAt: resumeAt.toISOString() });
8052
8235
  const delay = Math.max(5e3, resumeAt.getTime() - Date.now());
8053
8236
  const capped = Math.min(delay, 2147483647);
8054
- const timer2 = setTimeout(() => {
8237
+ const timer3 = setTimeout(() => {
8055
8238
  this.quotaResumeTimers.delete(threadId);
8056
8239
  void this.resumeAfterQuotaWait(threadId);
8057
8240
  }, capped);
8058
- this.quotaResumeTimers.set(threadId, timer2);
8241
+ this.quotaResumeTimers.set(threadId, timer3);
8059
8242
  }
8060
8243
  schedulePendingQuotaResumes() {
8061
8244
  for (const thread of listThreads({ includeArchived: false })) {
@@ -8598,7 +8781,7 @@ var Orchestrator = class {
8598
8781
  if (stopped?.status === "stopped") {
8599
8782
  this.emit({ type: "status_changed", threadId, status: "stopped" });
8600
8783
  }
8601
- this.emit({ type: "turn_finished", threadId, exitCode: 1 });
8784
+ this.emit(turnFinishedEvent(threadId, 1, this.stoppedTurns.has(threadId), readThread(threadId)?.lastError));
8602
8785
  return;
8603
8786
  }
8604
8787
  thread = this.requireThread(threadId);
@@ -9006,7 +9189,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9006
9189
  if (stopped?.status === "stopped") {
9007
9190
  this.emit({ type: "status_changed", threadId, status: "stopped" });
9008
9191
  }
9009
- this.emit({ type: "turn_finished", threadId, exitCode });
9192
+ this.emit(turnFinishedEvent(threadId, exitCode, this.stoppedTurns.has(threadId), readThread(threadId)?.lastError));
9010
9193
  } else {
9011
9194
  const failDetail = formatTurnExitError(exitCode, detail);
9012
9195
  const explainedInChat = exitCode !== 0 && Boolean(chatText) && (looksLikeAgentFailureMessage(chatText) || failDetail && chatText.includes(failDetail.replace(/^exit\s*\d+:\s*/i, "").trim()));
@@ -9023,7 +9206,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9023
9206
  status: written.status
9024
9207
  });
9025
9208
  }
9026
- this.emit({ type: "turn_finished", threadId, exitCode });
9209
+ this.emit(turnFinishedEvent(threadId, exitCode, this.stoppedTurns.has(threadId), readThread(threadId)?.lastError));
9027
9210
  if (exitCode === 0) {
9028
9211
  this.crashContinued.delete(threadId);
9029
9212
  this.maybeEnqueueJobContinue(threadId, chatText, parts);
@@ -9058,14 +9241,14 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9058
9241
  if (stopped?.status === "stopped") {
9059
9242
  this.emit({ type: "status_changed", threadId, status: "stopped" });
9060
9243
  }
9061
- this.emit({ type: "turn_finished", threadId, exitCode: 1 });
9244
+ this.emit(turnFinishedEvent(threadId, 1, this.stoppedTurns.has(threadId), readThread(threadId)?.lastError));
9062
9245
  } else {
9063
9246
  const written = writeLiveStatus(threadId, "error", message);
9064
9247
  if (written?.status === "error") {
9065
9248
  this.emit({ type: "error", threadId, message });
9066
9249
  this.emit({ type: "status_changed", threadId, status: "error" });
9067
9250
  }
9068
- this.emit({ type: "turn_finished", threadId, exitCode: 1 });
9251
+ this.emit(turnFinishedEvent(threadId, 1, this.stoppedTurns.has(threadId), readThread(threadId)?.lastError));
9069
9252
  const failedOver = await isolateQuotaFailover(
9070
9253
  () => this.maybeHandleOrchestrationQuotaFailover(threadId, message)
9071
9254
  );
@@ -9113,9 +9296,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9113
9296
  const continueQueue = opts?.continueQueue === true;
9114
9297
  const thread = this.requireThread(threadRef);
9115
9298
  const inFlight = this.activeTurns.has(thread.id) || this.startingTurns.has(thread.id);
9116
- if (inFlight) {
9117
- this.stoppedTurns.add(thread.id);
9118
- }
9299
+ if (inFlight) this.stoppedTurns.add(thread.id);
9119
9300
  if (clearQueue && thread.queue.length > 0) {
9120
9301
  this.haltDrain.delete(thread.id);
9121
9302
  updateThread(thread.id, { queue: [], queueAttachments: [] });
@@ -9125,6 +9306,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9125
9306
  } else if (continueQueue) {
9126
9307
  this.haltDrain.delete(thread.id);
9127
9308
  }
9309
+ let stopped = writeStoppedStatus(thread.id, resolveStopReason(opts)) ?? readThread(thread.id) ?? thread;
9128
9310
  const handle = this.activeTurns.get(thread.id);
9129
9311
  if (handle) handle.kill();
9130
9312
  const proc = this.processes.get(`${thread.id}:agent`);
@@ -9143,10 +9325,10 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9143
9325
  }
9144
9326
  }
9145
9327
  }
9146
- const stopped = writeStoppedStatus(thread.id, resolveStopReason(opts)) ?? readThread(thread.id) ?? thread;
9328
+ stopped = readThread(thread.id) ?? stopped;
9147
9329
  if (stopped.status === "stopped") {
9148
9330
  this.emit({ type: "status_changed", threadId: thread.id, status: "stopped" });
9149
- if (inFlight && opts?.notifyParent !== false) {
9331
+ if (inFlight && opts?.notifyParent !== false && !continueQueue) {
9150
9332
  notifyParentOfChildHalt(stopped, "stopped", (id, prompt) => this.send(id, prompt));
9151
9333
  }
9152
9334
  }
@@ -9701,11 +9883,11 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9701
9883
  const start = Date.now();
9702
9884
  return new Promise((resolve, reject) => {
9703
9885
  let settled = false;
9704
- let timer2;
9886
+ let timer3;
9705
9887
  const finish = (fn) => {
9706
9888
  if (settled) return;
9707
9889
  settled = true;
9708
- if (timer2) clearInterval(timer2);
9890
+ if (timer3) clearInterval(timer3);
9709
9891
  off();
9710
9892
  fn();
9711
9893
  };
@@ -9731,7 +9913,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9731
9913
  }
9732
9914
  }
9733
9915
  });
9734
- timer2 = setInterval(() => {
9916
+ timer3 = setInterval(() => {
9735
9917
  const raw = readThread(thread.id);
9736
9918
  if (!raw) {
9737
9919
  finish(() => reject(new Error(`Thread not found: ${thread.id}`)));
@@ -10304,7 +10486,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10304
10486
  this.stop(thread.id, { notifyParent: false });
10305
10487
  this.releaseOrchestratorCaffeinate(thread);
10306
10488
  if (isGlobalThread(thread)) {
10307
- const archived2 = setStatus(thread.id, "archived");
10489
+ const archived2 = archiveClearingFollowUps(thread.id);
10308
10490
  this.emit({ type: "status_changed", threadId: archived2.id, status: "archived" });
10309
10491
  this.enforceHistoryRetention();
10310
10492
  return archived2;
@@ -10323,10 +10505,10 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10323
10505
  });
10324
10506
  } catch {
10325
10507
  }
10326
- await removeWorktree(thread.repoPath, thread.worktreePath);
10508
+ await removeWorktreeSavingLeftovers(thread);
10327
10509
  }
10328
10510
  }
10329
- const archived = setStatus(thread.id, "archived");
10511
+ const archived = archiveClearingFollowUps(thread.id);
10330
10512
  this.emit({ type: "status_changed", threadId: archived.id, status: "archived" });
10331
10513
  this.enforceHistoryRetention();
10332
10514
  if (thread.repoPath && !isGlobalRepoPath(thread.repoPath)) {
@@ -10356,9 +10538,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10356
10538
  }
10357
10539
  const { deleteBranchOnPurgeEnabled } = await import("./app-settings-PPIMYJKS.js");
10358
10540
  const deleteBranch = opts?.deleteBranch ?? deleteBranchOnPurgeEnabled();
10359
- await removeWorktree(thread.repoPath, thread.worktreePath, {
10360
- deleteBranch: deleteBranch ? thread.branchName : void 0
10361
- });
10541
+ await removeWorktreeDroppingLeftovers(thread, deleteBranch ? thread.branchName : void 0);
10362
10542
  }
10363
10543
  }
10364
10544
  deleteThreadRecord(thread.id);
@@ -10388,6 +10568,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10388
10568
  });
10389
10569
  const { ensureWorktreeSideboardIgnored } = await import("./worktree-exclude-KMZQXZKP.js");
10390
10570
  await ensureWorktreeSideboardIgnored(dest);
10571
+ await applyWorktreeLeftovers(thread.repoPath, dest, thread.branchName).catch(() => false);
10391
10572
  }
10392
10573
  const restorePatch = {};
10393
10574
  let alreadyMerged = normalizePrState(thread.prState) === "MERGED";
@@ -10492,7 +10673,7 @@ async function startOrchestration(opts) {
10492
10673
  sourceRef: "default",
10493
10674
  ...createOpts
10494
10675
  }).catch(async () => {
10495
- const { resolveDefaultBranch: resolveDefaultBranch2, resolveRepoRoot: resolveRepoRoot2 } = await import("./worktree-ROJXGBWS.js");
10676
+ const { resolveDefaultBranch: resolveDefaultBranch2, resolveRepoRoot: resolveRepoRoot2 } = await import("./worktree-7JFYDNUX.js");
10496
10677
  const repo = await resolveRepoRoot2(repoPath);
10497
10678
  const def = await resolveDefaultBranch2(repo);
10498
10679
  return orch.createThread({
@@ -10502,7 +10683,7 @@ async function startOrchestration(opts) {
10502
10683
  repoPath: repo
10503
10684
  });
10504
10685
  });
10505
- const { updateThread: upd } = await import("./thread-store-MEUWZDVV.js");
10686
+ const { updateThread: upd } = await import("./thread-store-QKNU5CHM.js");
10506
10687
  const updated = upd(thread.id, {
10507
10688
  sourceType: "orchestration",
10508
10689
  sourceRef: goal