@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
@@ -21,7 +21,7 @@ import {
21
21
  parseSessionQuotaResetAt,
22
22
  planModeTurnInstruction,
23
23
  resolveQuotaFallbackAgent
24
- } from "./chunk-Q4TZA4MN.js";
24
+ } from "./chunk-ZXI5DR5S.js";
25
25
  import {
26
26
  applyWorktreePkgCacheEnv,
27
27
  buildBrightsySessionSeed,
@@ -56,7 +56,7 @@ import {
56
56
  worktreeDevProcessKey,
57
57
  worktreeRunProcessKey,
58
58
  worktreeSetupProcessKey
59
- } from "./chunk-GAGTEI6B.js";
59
+ } from "./chunk-ROXM6QZV.js";
60
60
  import {
61
61
  applyAgentEvent,
62
62
  clipAgentEventForPaint,
@@ -71,7 +71,7 @@ import {
71
71
  partsToAssistantText,
72
72
  stripBrightsyNdjsonNoise,
73
73
  toolDescription
74
- } from "./chunk-BIM24I3O.js";
74
+ } from "./chunk-WWBPK7GB.js";
75
75
  import {
76
76
  titleFromPrompt
77
77
  } from "./chunk-7H655NEW.js";
@@ -101,7 +101,7 @@ import {
101
101
  stageAbsolutePathsAsAttachments,
102
102
  stageBuffersAsAttachments,
103
103
  syncWorkspacesFromThreads
104
- } from "./chunk-XNGW4OYD.js";
104
+ } from "./chunk-MHSBF3SO.js";
105
105
  import {
106
106
  addPrStackLayer,
107
107
  allocateTeamSlug,
@@ -154,12 +154,14 @@ import {
154
154
  resolveRepoRoot,
155
155
  switchWorktreeBranch,
156
156
  withRepoGitLock
157
- } from "./chunk-NTY5WGRD.js";
157
+ } from "./chunk-3DBL2C45.js";
158
158
  import {
159
159
  REVIEW_TAB_TITLE,
160
160
  agentNicknameFromWorktreePath,
161
161
  appendMessage,
162
+ ciChecksSettled,
162
163
  createEmptyThread,
164
+ decideFollowUps,
163
165
  deleteSchedule,
164
166
  deleteThreadRecord,
165
167
  findThreadByRef,
@@ -171,6 +173,8 @@ import {
171
173
  isWorktreeIdentityTitle,
172
174
  listSchedules,
173
175
  listThreads,
176
+ mergeFollowUpPoll,
177
+ normalizeChatFollowUps,
174
178
  normalizeWorkspaceTags,
175
179
  normalizeWorktreePath,
176
180
  readThread,
@@ -186,7 +190,7 @@ import {
186
190
  worktreeNameFromPath,
187
191
  worktreeSlugForTicket,
188
192
  writeThread
189
- } from "./chunk-ATS7SYHG.js";
193
+ } from "./chunk-RPHH4FNK.js";
190
194
  import {
191
195
  askBlockStillWaiting,
192
196
  extractPendingPlanQuestions,
@@ -204,7 +208,7 @@ import {
204
208
  import {
205
209
  applyAgentRunnerHeapEnv,
206
210
  packagedMcpDir
207
- } from "./chunk-UGUWFONI.js";
211
+ } from "./chunk-2E2HMJDU.js";
208
212
  import {
209
213
  fallbackTurnFailDetail,
210
214
  formatAgentErrorContinuePrompt,
@@ -219,7 +223,7 @@ import {
219
223
  shouldRetryFailedAgentTurn,
220
224
  summarizeTurnStderr,
221
225
  turnFailChatText
222
- } from "./chunk-OPXEJJBM.js";
226
+ } from "./chunk-PWOFUPYM.js";
223
227
  import {
224
228
  clearStaleIndexLocks,
225
229
  enrichPathWithNpmGlobalBin,
@@ -394,19 +398,19 @@ function traceTurn(phase, extra) {
394
398
  }
395
399
  }
396
400
  async function withTimeout(promise, ms, label) {
397
- let timer2;
401
+ let timer3;
398
402
  try {
399
403
  return await Promise.race([
400
404
  promise,
401
405
  new Promise((_, reject) => {
402
- timer2 = setTimeout(
406
+ timer3 = setTimeout(
403
407
  () => reject(new Error(`${label} timed out after ${ms}ms`)),
404
408
  ms
405
409
  );
406
410
  })
407
411
  ]);
408
412
  } finally {
409
- if (timer2) clearTimeout(timer2);
413
+ if (timer3) clearTimeout(timer3);
410
414
  }
411
415
  }
412
416
 
@@ -527,9 +531,9 @@ async function spawnAgentTurn(thread, input, onEvent) {
527
531
  `Cannot spawn ${thread.agent}: thread ${thread.id} has no worktreePath`
528
532
  );
529
533
  }
530
- const { isGlobalThread: isGlobalThread2 } = await import("./global-workspace-UG2A3CEM.js");
534
+ const { isGlobalThread: isGlobalThread2 } = await import("./global-workspace-64KC7PST.js");
531
535
  if (isGlobalThread2(thread)) {
532
- const { ensureGlobalCoordinatorCwd: ensureGlobalCoordinatorCwd2 } = await import("./coordinator-prompt-DLY3FS2L.js");
536
+ const { ensureGlobalCoordinatorCwd: ensureGlobalCoordinatorCwd2 } = await import("./coordinator-prompt-5GZWIVSY.js");
533
537
  ensureGlobalCoordinatorCwd2(
534
538
  isOrchestratorThread(thread) ? { orchestratorThreadId: thread.id } : void 0
535
539
  );
@@ -727,14 +731,97 @@ async function spawnAgentTurn(thread, input, onEvent) {
727
731
  }
728
732
  };
729
733
  signal("SIGTERM");
730
- const timer2 = setTimeout(() => signal("SIGKILL"), 5e3);
731
- timer2.unref?.();
732
- child.once("exit", () => clearTimeout(timer2));
734
+ const timer3 = setTimeout(() => signal("SIGKILL"), 5e3);
735
+ timer3.unref?.();
736
+ child.once("exit", () => clearTimeout(timer3));
733
737
  },
734
738
  done
735
739
  };
736
740
  }
737
741
 
742
+ // src/git/worktree-leftovers.ts
743
+ var LEFTOVER_REF_PREFIX = "refs/sideboard/leftovers/";
744
+ function leftoverRefName(branch) {
745
+ const safe = branch.trim().replace(/[^A-Za-z0-9._/-]+/g, "-") || "branch";
746
+ return `${LEFTOVER_REF_PREFIX}${safe}`;
747
+ }
748
+ function gitFailure(result, fallback) {
749
+ const text3 = (result.stderr || result.stdout).trim();
750
+ return text3 || fallback;
751
+ }
752
+ async function restoreIndex(worktreePath, treeSha) {
753
+ await git(["read-tree", "--reset", treeSha], worktreePath, { reject: false });
754
+ }
755
+ async function saveWorktreeLeftovers(repoPath, worktreePath, branch) {
756
+ const status = await git(["status", "--porcelain"], worktreePath, { reject: false });
757
+ if (status.exitCode !== 0) {
758
+ return { ok: false, error: gitFailure(status, "git status failed") };
759
+ }
760
+ if (!status.stdout.trim()) return { ok: true, ref: null };
761
+ const indexBefore = await git(["write-tree"], worktreePath, { reject: false });
762
+ const indexSha = indexBefore.stdout.trim();
763
+ if (indexBefore.exitCode !== 0 || !/^[0-9a-f]{7,64}$/i.test(indexSha)) {
764
+ return { ok: false, error: gitFailure(indexBefore, "git write-tree failed") };
765
+ }
766
+ const fail = async (result, fallback) => {
767
+ await restoreIndex(worktreePath, indexSha);
768
+ return { ok: false, error: gitFailure(result, fallback) };
769
+ };
770
+ const added = await git(["add", "-A"], worktreePath, { reject: false });
771
+ if (added.exitCode !== 0) return fail(added, "git add failed");
772
+ const tree = await git(["write-tree"], worktreePath, { reject: false });
773
+ const treeSha = tree.stdout.trim();
774
+ if (tree.exitCode !== 0 || !/^[0-9a-f]{7,64}$/i.test(treeSha)) {
775
+ return fail(tree, "git write-tree failed");
776
+ }
777
+ const head = await git(["rev-parse", "HEAD"], worktreePath, { reject: false });
778
+ const parent = head.stdout.trim();
779
+ if (head.exitCode !== 0 || !parent) return fail(head, "git rev-parse HEAD failed");
780
+ const commit = await git(
781
+ ["commit-tree", treeSha, "-p", parent, "-m", "sideboard leftover"],
782
+ worktreePath,
783
+ { reject: false }
784
+ );
785
+ const sha = commit.stdout.trim();
786
+ if (commit.exitCode !== 0 || !/^[0-9a-f]{7,64}$/i.test(sha)) {
787
+ return fail(commit, "git commit-tree failed");
788
+ }
789
+ const ref = leftoverRefName(branch);
790
+ const updated = await git(["update-ref", ref, sha], repoPath, { reject: false });
791
+ if (updated.exitCode !== 0) return fail(updated, "git update-ref failed");
792
+ await git(["reset"], worktreePath, { reject: false });
793
+ return { ok: true, ref };
794
+ }
795
+ async function applyWorktreeLeftovers(repoPath, worktreePath, branch) {
796
+ const ref = leftoverRefName(branch);
797
+ const shown = await git(["rev-parse", "--verify", "--quiet", ref], repoPath, { reject: false });
798
+ const sha = shown.stdout.trim();
799
+ if (shown.exitCode !== 0 || !sha) return false;
800
+ const restored = await git(["restore", "--source", sha, "--worktree", "--", "."], worktreePath, {
801
+ reject: false
802
+ });
803
+ if (restored.exitCode !== 0) return false;
804
+ await git(["update-ref", "-d", ref], repoPath, { reject: false });
805
+ return true;
806
+ }
807
+ async function deleteWorktreeLeftovers(repoPath, branch) {
808
+ await git(["update-ref", "-d", leftoverRefName(branch)], repoPath, { reject: false });
809
+ }
810
+ function archiveClearingFollowUps(id) {
811
+ const archived = setStatus(id, "archived");
812
+ if ((archived.followUps?.length ?? 0) === 0) return archived;
813
+ return updateThread(archived.id, { followUps: [] });
814
+ }
815
+ async function removeWorktreeSavingLeftovers(thread) {
816
+ const saved = await saveWorktreeLeftovers(thread.repoPath, thread.worktreePath, thread.branchName);
817
+ if (!saved.ok) throw new Error(`Could not save uncommitted files: ${saved.error}`);
818
+ await removeWorktree(thread.repoPath, thread.worktreePath);
819
+ }
820
+ async function removeWorktreeDroppingLeftovers(thread, deleteBranch) {
821
+ await removeWorktree(thread.repoPath, thread.worktreePath, { deleteBranch });
822
+ await deleteWorktreeLeftovers(thread.repoPath, thread.branchName).catch(() => void 0);
823
+ }
824
+
738
825
  // src/git/agent-git-actions.ts
739
826
  var AGENT_GIT_ACTIONS = [
740
827
  "commit-push",
@@ -1079,9 +1166,9 @@ function mergeSetupOutput(prev, incoming) {
1079
1166
  }
1080
1167
  var PERSIST_DEBOUNCE_MS = 500;
1081
1168
  function persistNow(threadId) {
1082
- const timer2 = persistTimers.get(threadId);
1083
- if (timer2) {
1084
- clearTimeout(timer2);
1169
+ const timer3 = persistTimers.get(threadId);
1170
+ if (timer3) {
1171
+ clearTimeout(timer3);
1085
1172
  persistTimers.delete(threadId);
1086
1173
  }
1087
1174
  const mem = memory.get(threadId);
@@ -1230,9 +1317,9 @@ function sliceRunLogOutput(output, tailChars = DEFAULT_RUN_LOG_TAIL_CHARS) {
1230
1317
  }
1231
1318
  var PERSIST_DEBOUNCE_MS2 = 500;
1232
1319
  function persistNow2(key) {
1233
- const timer2 = persistTimers2.get(key);
1234
- if (timer2) {
1235
- clearTimeout(timer2);
1320
+ const timer3 = persistTimers2.get(key);
1321
+ if (timer3) {
1322
+ clearTimeout(timer3);
1236
1323
  persistTimers2.delete(key);
1237
1324
  }
1238
1325
  const mem = memory2.get(key);
@@ -2339,6 +2426,10 @@ function resolveStopReason(opts) {
2339
2426
  if (opts?.clearQueue === false) return "Stopped by the user";
2340
2427
  return "Stopped (queue cleared)";
2341
2428
  }
2429
+ function isRoutineStopNote(err) {
2430
+ const text3 = err?.trim() ?? "";
2431
+ return text3 === "Stopped" || text3 === "Stopped by the user" || text3 === "Stopped (queue cleared)" || text3 === "Stopped to send the next prompt";
2432
+ }
2342
2433
  function reasonToKeepOnStop(existing, incoming) {
2343
2434
  const next = incoming?.trim();
2344
2435
  if (next) return next.slice(0, STOP_REASON_MAX);
@@ -2346,6 +2437,16 @@ function reasonToKeepOnStop(existing, incoming) {
2346
2437
  if (prior) return prior.slice(0, STOP_REASON_MAX);
2347
2438
  return "Stopped";
2348
2439
  }
2440
+ function turnFinishedEvent(threadId, exitCode, userStopped, lastError) {
2441
+ const note = lastError?.trim() ?? "";
2442
+ const routineStop = userStopped && (note.length === 0 || isRoutineStopNote(note));
2443
+ return {
2444
+ type: "turn_finished",
2445
+ threadId,
2446
+ exitCode,
2447
+ ...routineStop ? { routineStop: true } : {}
2448
+ };
2449
+ }
2349
2450
  function writeStoppedStatus(threadId, reason) {
2350
2451
  const latest = readThread(threadId);
2351
2452
  if (!latest || latest.status === "archived") return latest;
@@ -3469,7 +3570,7 @@ async function createThread(input, _onSetupLine) {
3469
3570
  return readThread(thread.id) ?? thread;
3470
3571
  }
3471
3572
  async function listLinearIssues(agent, repoPath) {
3472
- const { getAdapter: getAdapter2 } = await import("./agents-5MFGVK7C.js");
3573
+ const { getAdapter: getAdapter2 } = await import("./agents-AZ2PV6XP.js");
3473
3574
  await requireAgent(agent, { requireLinear: true });
3474
3575
  const adapter = getAdapter2(agent);
3475
3576
  if (!adapter.listLinearIssues) {
@@ -3771,11 +3872,11 @@ function createLineCoalescer(onChunk, opts) {
3771
3872
  const delayMs = opts?.delayMs ?? 50;
3772
3873
  const maxLines = opts?.maxLines ?? 200;
3773
3874
  let buffer = [];
3774
- let timer2 = null;
3875
+ let timer3 = null;
3775
3876
  const flush2 = () => {
3776
- if (timer2) {
3777
- clearTimeout(timer2);
3778
- timer2 = null;
3877
+ if (timer3) {
3878
+ clearTimeout(timer3);
3879
+ timer3 = null;
3779
3880
  }
3780
3881
  if (buffer.length === 0) return;
3781
3882
  const chunk = buffer.join("\n");
@@ -3788,7 +3889,7 @@ function createLineCoalescer(onChunk, opts) {
3788
3889
  flush2();
3789
3890
  return;
3790
3891
  }
3791
- if (!timer2) timer2 = setTimeout(flush2, delayMs);
3892
+ if (!timer3) timer3 = setTimeout(flush2, delayMs);
3792
3893
  };
3793
3894
  return { push, flush: flush2 };
3794
3895
  }
@@ -4252,7 +4353,7 @@ async function adoptThread(input) {
4252
4353
  messages: input.messages ?? []
4253
4354
  });
4254
4355
  writeThread(thread);
4255
- const { addWorkspace: addWorkspace2 } = await import("./workspaces-35T6FW57.js");
4356
+ const { addWorkspace: addWorkspace2 } = await import("./workspaces-I2EHNTFE.js");
4256
4357
  await addWorkspace2(repoPath);
4257
4358
  const { ensureWorktreeSideboardIgnored } = await import("./worktree-exclude-YQBN43QD.js");
4258
4359
  await ensureWorktreeSideboardIgnored(input.worktreePath);
@@ -6372,6 +6473,9 @@ function livePartsShowAgentReply(parts) {
6372
6473
  }
6373
6474
 
6374
6475
  // src/orchestrator/enqueue-thread-send.ts
6476
+ function sendFollowUpInterrupts(followUp, busy) {
6477
+ return followUp === "steer" && busy;
6478
+ }
6375
6479
  function resolveSendFollowUp(thread, requested) {
6376
6480
  if (requested === "steer" || requested === "queue") return requested;
6377
6481
  return isOrchestratorThread(thread) ? followUpBehavior() : "queue";
@@ -6458,14 +6562,20 @@ async function enqueueThreadSend(host, threadRef, prompt, opts) {
6458
6562
  if (current.status === "archived") {
6459
6563
  throw new Error(`Thread is archived: ${thread.id}`);
6460
6564
  }
6461
- const followUp = resolveSendFollowUp(current, opts?.followUp);
6565
+ const requested = opts?.followUp;
6566
+ const join15 = requested === "join";
6567
+ const followUp = resolveSendFollowUp(
6568
+ current,
6569
+ join15 ? "steer" : requested
6570
+ );
6462
6571
  const explicit = opts?.attachments;
6463
6572
  const consumed = explicit !== void 0 ? { attachments: current.attachments, consumed: explicit } : consumeComposerAttachments(current);
6464
6573
  const inFlightEarly = host.activeTurns.has(thread.id) || host.startingTurns.has(thread.id) || current.status === "running";
6465
6574
  const agentHasRepliedEarly = livePartsShowAgentReply(readTurnLiveParts(current.id));
6466
6575
  const draft = host.openSteerPrompt.get(current.id);
6467
6576
  const queuedHead = !inFlightEarly && current.status === "queued" && current.queue.length > 0 ? current.queue[0] : null;
6468
- const unanswered = followUp === "steer" && !agentHasRepliedEarly ? draft?.text ?? (inFlightEarly ? trailingUnansweredUserText(current.messages) : queuedHead) : null;
6577
+ const joinCanMerge = draft != null && !draft.spawned || !inFlightEarly && queuedHead != null;
6578
+ const unanswered = followUp === "steer" && !agentHasRepliedEarly && (!join15 || joinCanMerge) ? draft?.text ?? (inFlightEarly ? trailingUnansweredUserText(current.messages) : queuedHead) : null;
6469
6579
  if (unanswered != null && (draft ? !draft.spawned : queuedHead != null)) {
6470
6580
  clearSendBookkeeping(host, thread.id);
6471
6581
  const combined = joinSteerPrompt(unanswered, prompt);
@@ -6516,7 +6626,10 @@ async function enqueueThreadSend(host, threadRef, prompt, opts) {
6516
6626
  );
6517
6627
  clearSendBookkeeping(host, thread.id);
6518
6628
  const inFlight = host.activeTurns.has(thread.id) || host.startingTurns.has(thread.id) || current.status === "running";
6519
- shouldSteer = followUp === "steer" && (inFlight || current.queue.length > 0);
6629
+ shouldSteer = sendFollowUpInterrupts(
6630
+ join15 ? "join" : followUp,
6631
+ inFlight || current.queue.length > 0
6632
+ );
6520
6633
  const patch = queued;
6521
6634
  if (explicit === void 0 && consumed.consumed.length > 0) {
6522
6635
  patch.attachments = consumed.attachments;
@@ -6737,7 +6850,7 @@ function formatWorktreeDirective(thread, opts) {
6737
6850
  lines.push(formatDevAccessHint(opts?.activeRuns));
6738
6851
  lines.push("");
6739
6852
  lines.push(
6740
- "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."
6853
+ "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."
6741
6854
  );
6742
6855
  lines.push(
6743
6856
  "`set_workspace_tags` labels this checkout (omit ref). `set_wake_on_github_edges` opts this checkout in when Advanced is already on (omit ref)."
@@ -7877,11 +7990,11 @@ function realDeps() {
7877
7990
  parentIdForThread,
7878
7991
  designatedId: designatedOrchestratorId,
7879
7992
  send: async (threadId, prompt) => {
7880
- const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-BUEPWNCF.js");
7993
+ const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-Y5PYSMR6.js");
7881
7994
  await getOrchestrator2().send(threadId, prompt, { followUp: "queue" });
7882
7995
  },
7883
7996
  startOrchestration: async (prompt) => {
7884
- const { startOrchestration: startOrchestration2 } = await import("./orchestrator-BUEPWNCF.js");
7997
+ const { startOrchestration: startOrchestration2 } = await import("./orchestrator-Y5PYSMR6.js");
7885
7998
  const defaults = resolveOrchestratorDefaults();
7886
7999
  await startOrchestration2({
7887
8000
  goal: prompt,
@@ -7908,7 +8021,7 @@ function formatScheduledPrompt(name, prompt) {
7908
8021
  ${prompt}`;
7909
8022
  }
7910
8023
  async function defaultDeps() {
7911
- const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-BUEPWNCF.js");
8024
+ const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-Y5PYSMR6.js");
7912
8025
  const orch = getOrchestrator2();
7913
8026
  return {
7914
8027
  findThread: (id) => findThreadByRef(id),
@@ -8008,8 +8121,8 @@ async function fireSchedule(id) {
8008
8121
  }
8009
8122
  }
8010
8123
  function clearTimer(id) {
8011
- const timer2 = timers.get(id);
8012
- if (timer2) clearTimeout(timer2);
8124
+ const timer3 = timers.get(id);
8125
+ if (timer3) clearTimeout(timer3);
8013
8126
  timers.delete(id);
8014
8127
  }
8015
8128
  function armOne(schedule) {
@@ -8025,7 +8138,7 @@ function armOne(schedule) {
8025
8138
  return;
8026
8139
  }
8027
8140
  const capped = Math.min(delay, SET_TIMEOUT_MAX);
8028
- const timer2 = setTimeout(() => {
8141
+ const timer3 = setTimeout(() => {
8029
8142
  timers.delete(schedule.id);
8030
8143
  const live = getSchedule(schedule.id);
8031
8144
  if (!live?.enabled) return;
@@ -8038,7 +8151,7 @@ function armOne(schedule) {
8038
8151
  if (isThisProcessDesktopHost()) armSchedules();
8039
8152
  });
8040
8153
  }, capped);
8041
- timers.set(schedule.id, timer2);
8154
+ timers.set(schedule.id, timer3);
8042
8155
  }
8043
8156
  function armSchedules() {
8044
8157
  if (!isThisProcessDesktopHost()) return;
@@ -8055,6 +8168,75 @@ function armSchedules() {
8055
8168
  }
8056
8169
  }
8057
8170
 
8171
+ // src/orchestrator/chat-follow-up-runner.ts
8172
+ var POLL_MS = 6e4;
8173
+ var timer2 = null;
8174
+ var polling2 = false;
8175
+ async function ciPhase(thread) {
8176
+ const selector = resolvePrSelector(thread);
8177
+ if (!selector || !thread.worktreePath?.trim()) return "none";
8178
+ try {
8179
+ const checks = await getPrCiChecks(thread.worktreePath, selector);
8180
+ return ciChecksSettled(checks);
8181
+ } catch {
8182
+ return "unknown";
8183
+ }
8184
+ }
8185
+ async function pollChatFollowUps(send = defaultSend) {
8186
+ if (polling2) return;
8187
+ polling2 = true;
8188
+ try {
8189
+ const threads = listThreads().filter(
8190
+ (thread) => thread.status !== "archived" && (thread.followUps?.length ?? 0) > 0
8191
+ );
8192
+ for (const thread of threads) {
8193
+ const followUps = thread.followUps ?? [];
8194
+ const ci = followUps.some((item) => item.kind === "ci") ? await ciPhase(thread) : "none";
8195
+ const decision = decideFollowUps({ followUps, now: /* @__PURE__ */ new Date(), ci });
8196
+ const kept = [...decision.keep];
8197
+ const firedIds = [];
8198
+ for (const item of decision.fire) {
8199
+ try {
8200
+ await send(thread.id, `[Follow-up]
8201
+ ${item.prompt}`);
8202
+ firedIds.push(item.id);
8203
+ } catch {
8204
+ kept.push(item);
8205
+ }
8206
+ }
8207
+ const fresh = readThread(thread.id);
8208
+ if (!fresh || fresh.status === "archived") continue;
8209
+ const after = normalizeChatFollowUps(fresh.followUps);
8210
+ const next = mergeFollowUpPoll({
8211
+ before: followUps,
8212
+ after,
8213
+ firedIds,
8214
+ keep: kept
8215
+ });
8216
+ if (JSON.stringify(next) !== JSON.stringify(after)) {
8217
+ updateThread(thread.id, { followUps: next });
8218
+ }
8219
+ }
8220
+ } finally {
8221
+ polling2 = false;
8222
+ }
8223
+ }
8224
+ async function defaultSend(id, prompt) {
8225
+ const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-Y5PYSMR6.js");
8226
+ await getOrchestrator2().send(id, prompt, { followUp: "join" });
8227
+ }
8228
+ function armChatFollowUps() {
8229
+ if (!isThisProcessDesktopHost()) return;
8230
+ if (timer2) return;
8231
+ const tick = () => {
8232
+ timer2 = setTimeout(() => {
8233
+ void pollChatFollowUps().finally(tick);
8234
+ }, POLL_MS);
8235
+ };
8236
+ void pollChatFollowUps();
8237
+ tick();
8238
+ }
8239
+
8058
8240
  // src/orchestrator/orchestrator.ts
8059
8241
  var LIVE_TURN_SPAWN_GRACE_MS = 15e3;
8060
8242
  var RUN_SCRIPT_DESKTOP_ADOPT_MS = 2e4;
@@ -8252,6 +8434,7 @@ var Orchestrator = class {
8252
8434
  }
8253
8435
  this.schedulePendingQuotaResumes();
8254
8436
  armSchedules();
8437
+ armChatFollowUps();
8255
8438
  armGithubEdgeWatch();
8256
8439
  }
8257
8440
  /** Surface (and, when enabled, clean up) worktrees git knows about but no thread owns. */
@@ -8383,7 +8566,7 @@ var Orchestrator = class {
8383
8566
  if (!this.shouldReclaimRunningThread(thread)) continue;
8384
8567
  setStatus(thread.id, "stopped", "Process died (agent exited)");
8385
8568
  this.emit({ type: "status_changed", threadId: thread.id, status: "stopped" });
8386
- this.emit({ type: "turn_finished", threadId: thread.id, exitCode: 1 });
8569
+ this.emit(turnFinishedEvent(thread.id, 1, this.stoppedTurns.has(thread.id), readThread(thread.id)?.lastError));
8387
8570
  const latest = readThread(thread.id);
8388
8571
  if (latest) {
8389
8572
  notifyParentOfChildHalt(latest, "stopped", (id, prompt) => this.send(id, prompt));
@@ -8391,8 +8574,8 @@ var Orchestrator = class {
8391
8574
  }
8392
8575
  }
8393
8576
  clearQuotaResumeTimer(threadId) {
8394
- const timer2 = this.quotaResumeTimers.get(threadId);
8395
- if (timer2) clearTimeout(timer2);
8577
+ const timer3 = this.quotaResumeTimers.get(threadId);
8578
+ if (timer3) clearTimeout(timer3);
8396
8579
  this.quotaResumeTimers.delete(threadId);
8397
8580
  }
8398
8581
  /** Schedule (or fire) auto-retry after a provider session/usage limit reset. */
@@ -8401,11 +8584,11 @@ var Orchestrator = class {
8401
8584
  updateThread(threadId, { quotaResumeAt: resumeAt.toISOString() });
8402
8585
  const delay = Math.max(5e3, resumeAt.getTime() - Date.now());
8403
8586
  const capped = Math.min(delay, 2147483647);
8404
- const timer2 = setTimeout(() => {
8587
+ const timer3 = setTimeout(() => {
8405
8588
  this.quotaResumeTimers.delete(threadId);
8406
8589
  void this.resumeAfterQuotaWait(threadId);
8407
8590
  }, capped);
8408
- this.quotaResumeTimers.set(threadId, timer2);
8591
+ this.quotaResumeTimers.set(threadId, timer3);
8409
8592
  }
8410
8593
  schedulePendingQuotaResumes() {
8411
8594
  for (const thread of listThreads({ includeArchived: false })) {
@@ -8948,7 +9131,7 @@ var Orchestrator = class {
8948
9131
  if (stopped?.status === "stopped") {
8949
9132
  this.emit({ type: "status_changed", threadId, status: "stopped" });
8950
9133
  }
8951
- this.emit({ type: "turn_finished", threadId, exitCode: 1 });
9134
+ this.emit(turnFinishedEvent(threadId, 1, this.stoppedTurns.has(threadId), readThread(threadId)?.lastError));
8952
9135
  return;
8953
9136
  }
8954
9137
  thread = this.requireThread(threadId);
@@ -9356,7 +9539,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9356
9539
  if (stopped?.status === "stopped") {
9357
9540
  this.emit({ type: "status_changed", threadId, status: "stopped" });
9358
9541
  }
9359
- this.emit({ type: "turn_finished", threadId, exitCode });
9542
+ this.emit(turnFinishedEvent(threadId, exitCode, this.stoppedTurns.has(threadId), readThread(threadId)?.lastError));
9360
9543
  } else {
9361
9544
  const failDetail = formatTurnExitError(exitCode, detail);
9362
9545
  const explainedInChat = exitCode !== 0 && Boolean(chatText) && (looksLikeAgentFailureMessage(chatText) || failDetail && chatText.includes(failDetail.replace(/^exit\s*\d+:\s*/i, "").trim()));
@@ -9373,7 +9556,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9373
9556
  status: written.status
9374
9557
  });
9375
9558
  }
9376
- this.emit({ type: "turn_finished", threadId, exitCode });
9559
+ this.emit(turnFinishedEvent(threadId, exitCode, this.stoppedTurns.has(threadId), readThread(threadId)?.lastError));
9377
9560
  if (exitCode === 0) {
9378
9561
  this.crashContinued.delete(threadId);
9379
9562
  this.maybeEnqueueJobContinue(threadId, chatText, parts);
@@ -9408,14 +9591,14 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9408
9591
  if (stopped?.status === "stopped") {
9409
9592
  this.emit({ type: "status_changed", threadId, status: "stopped" });
9410
9593
  }
9411
- this.emit({ type: "turn_finished", threadId, exitCode: 1 });
9594
+ this.emit(turnFinishedEvent(threadId, 1, this.stoppedTurns.has(threadId), readThread(threadId)?.lastError));
9412
9595
  } else {
9413
9596
  const written = writeLiveStatus(threadId, "error", message);
9414
9597
  if (written?.status === "error") {
9415
9598
  this.emit({ type: "error", threadId, message });
9416
9599
  this.emit({ type: "status_changed", threadId, status: "error" });
9417
9600
  }
9418
- this.emit({ type: "turn_finished", threadId, exitCode: 1 });
9601
+ this.emit(turnFinishedEvent(threadId, 1, this.stoppedTurns.has(threadId), readThread(threadId)?.lastError));
9419
9602
  const failedOver = await isolateQuotaFailover(
9420
9603
  () => this.maybeHandleOrchestrationQuotaFailover(threadId, message)
9421
9604
  );
@@ -9463,9 +9646,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9463
9646
  const continueQueue = opts?.continueQueue === true;
9464
9647
  const thread = this.requireThread(threadRef);
9465
9648
  const inFlight = this.activeTurns.has(thread.id) || this.startingTurns.has(thread.id);
9466
- if (inFlight) {
9467
- this.stoppedTurns.add(thread.id);
9468
- }
9649
+ if (inFlight) this.stoppedTurns.add(thread.id);
9469
9650
  if (clearQueue && thread.queue.length > 0) {
9470
9651
  this.haltDrain.delete(thread.id);
9471
9652
  updateThread(thread.id, { queue: [], queueAttachments: [] });
@@ -9475,6 +9656,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9475
9656
  } else if (continueQueue) {
9476
9657
  this.haltDrain.delete(thread.id);
9477
9658
  }
9659
+ let stopped = writeStoppedStatus(thread.id, resolveStopReason(opts)) ?? readThread(thread.id) ?? thread;
9478
9660
  const handle = this.activeTurns.get(thread.id);
9479
9661
  if (handle) handle.kill();
9480
9662
  const proc = this.processes.get(`${thread.id}:agent`);
@@ -9493,10 +9675,10 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9493
9675
  }
9494
9676
  }
9495
9677
  }
9496
- const stopped = writeStoppedStatus(thread.id, resolveStopReason(opts)) ?? readThread(thread.id) ?? thread;
9678
+ stopped = readThread(thread.id) ?? stopped;
9497
9679
  if (stopped.status === "stopped") {
9498
9680
  this.emit({ type: "status_changed", threadId: thread.id, status: "stopped" });
9499
- if (inFlight && opts?.notifyParent !== false) {
9681
+ if (inFlight && opts?.notifyParent !== false && !continueQueue) {
9500
9682
  notifyParentOfChildHalt(stopped, "stopped", (id, prompt) => this.send(id, prompt));
9501
9683
  }
9502
9684
  }
@@ -10051,11 +10233,11 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10051
10233
  const start = Date.now();
10052
10234
  return new Promise((resolve, reject) => {
10053
10235
  let settled = false;
10054
- let timer2;
10236
+ let timer3;
10055
10237
  const finish2 = (fn) => {
10056
10238
  if (settled) return;
10057
10239
  settled = true;
10058
- if (timer2) clearInterval(timer2);
10240
+ if (timer3) clearInterval(timer3);
10059
10241
  off();
10060
10242
  fn();
10061
10243
  };
@@ -10081,7 +10263,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10081
10263
  }
10082
10264
  }
10083
10265
  });
10084
- timer2 = setInterval(() => {
10266
+ timer3 = setInterval(() => {
10085
10267
  const raw = readThread(thread.id);
10086
10268
  if (!raw) {
10087
10269
  finish2(() => reject(new Error(`Thread not found: ${thread.id}`)));
@@ -10654,7 +10836,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10654
10836
  this.stop(thread.id, { notifyParent: false });
10655
10837
  this.releaseOrchestratorCaffeinate(thread);
10656
10838
  if (isGlobalThread(thread)) {
10657
- const archived2 = setStatus(thread.id, "archived");
10839
+ const archived2 = archiveClearingFollowUps(thread.id);
10658
10840
  this.emit({ type: "status_changed", threadId: archived2.id, status: "archived" });
10659
10841
  this.enforceHistoryRetention();
10660
10842
  return archived2;
@@ -10673,10 +10855,10 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10673
10855
  });
10674
10856
  } catch {
10675
10857
  }
10676
- await removeWorktree(thread.repoPath, thread.worktreePath);
10858
+ await removeWorktreeSavingLeftovers(thread);
10677
10859
  }
10678
10860
  }
10679
- const archived = setStatus(thread.id, "archived");
10861
+ const archived = archiveClearingFollowUps(thread.id);
10680
10862
  this.emit({ type: "status_changed", threadId: archived.id, status: "archived" });
10681
10863
  this.enforceHistoryRetention();
10682
10864
  if (thread.repoPath && !isGlobalRepoPath(thread.repoPath)) {
@@ -10706,9 +10888,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10706
10888
  }
10707
10889
  const { deleteBranchOnPurgeEnabled } = await import("./app-settings-SNOPJ7P5.js");
10708
10890
  const deleteBranch = opts?.deleteBranch ?? deleteBranchOnPurgeEnabled();
10709
- await removeWorktree(thread.repoPath, thread.worktreePath, {
10710
- deleteBranch: deleteBranch ? thread.branchName : void 0
10711
- });
10891
+ await removeWorktreeDroppingLeftovers(thread, deleteBranch ? thread.branchName : void 0);
10712
10892
  }
10713
10893
  }
10714
10894
  deleteThreadRecord(thread.id);
@@ -10738,6 +10918,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10738
10918
  });
10739
10919
  const { ensureWorktreeSideboardIgnored } = await import("./worktree-exclude-YQBN43QD.js");
10740
10920
  await ensureWorktreeSideboardIgnored(dest);
10921
+ await applyWorktreeLeftovers(thread.repoPath, dest, thread.branchName).catch(() => false);
10741
10922
  }
10742
10923
  const restorePatch = {};
10743
10924
  let alreadyMerged = normalizePrState(thread.prState) === "MERGED";
@@ -10842,7 +11023,7 @@ async function startOrchestration(opts) {
10842
11023
  sourceRef: "default",
10843
11024
  ...createOpts
10844
11025
  }).catch(async () => {
10845
- const { resolveDefaultBranch: resolveDefaultBranch2, resolveRepoRoot: resolveRepoRoot2 } = await import("./worktree-5P7SCST3.js");
11026
+ const { resolveDefaultBranch: resolveDefaultBranch2, resolveRepoRoot: resolveRepoRoot2 } = await import("./worktree-M2GJGK2P.js");
10846
11027
  const repo = await resolveRepoRoot2(repoPath);
10847
11028
  const def = await resolveDefaultBranch2(repo);
10848
11029
  return orch.createThread({
@@ -10852,7 +11033,7 @@ async function startOrchestration(opts) {
10852
11033
  repoPath: repo
10853
11034
  });
10854
11035
  });
10855
- const { updateThread: upd } = await import("./thread-store-R3G5VBII.js");
11036
+ const { updateThread: upd } = await import("./thread-store-HZ4U4OXB.js");
10856
11037
  const updated = upd(thread.id, {
10857
11038
  sourceType: "orchestration",
10858
11039
  sourceRef: goal