@sideboard-ai/core 0.1.348 → 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-WMD77UCY.js → chunk-IRFBD6GU.js} +223 -55
  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-OH3BAUMC.js → chunk-Q4I6KDOL.js} +227 -59
  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 +1298 -849
  28. package/dist/index.d.cts +30 -8
  29. package/dist/index.d.ts +30 -8
  30. package/dist/index.js +445 -365
  31. package/dist/mcp/run-stdio.cjs +1033 -585
  32. package/dist/mcp/run-stdio.js +296 -216
  33. package/dist/{orchestrator-4SXTORD2.js → orchestrator-I5G5A5BV.js} +7 -7
  34. package/dist/{orchestrator-KNOMW5CZ.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);
@@ -3473,11 +3560,11 @@ function createLineCoalescer(onChunk, opts) {
3473
3560
  const delayMs = opts?.delayMs ?? 50;
3474
3561
  const maxLines = opts?.maxLines ?? 200;
3475
3562
  let buffer = [];
3476
- let timer2 = null;
3563
+ let timer3 = null;
3477
3564
  const flush2 = () => {
3478
- if (timer2) {
3479
- clearTimeout(timer2);
3480
- timer2 = null;
3565
+ if (timer3) {
3566
+ clearTimeout(timer3);
3567
+ timer3 = null;
3481
3568
  }
3482
3569
  if (buffer.length === 0) return;
3483
3570
  const chunk = buffer.join("\n");
@@ -3490,7 +3577,7 @@ function createLineCoalescer(onChunk, opts) {
3490
3577
  flush2();
3491
3578
  return;
3492
3579
  }
3493
- if (!timer2) timer2 = setTimeout(flush2, delayMs);
3580
+ if (!timer3) timer3 = setTimeout(flush2, delayMs);
3494
3581
  };
3495
3582
  return { push, flush: flush2 };
3496
3583
  }
@@ -3951,7 +4038,7 @@ async function adoptThread(input) {
3951
4038
  messages: input.messages ?? []
3952
4039
  });
3953
4040
  writeThread(thread);
3954
- const { addWorkspace: addWorkspace2 } = await import("./workspaces-KWGTP7DI.js");
4041
+ const { addWorkspace: addWorkspace2 } = await import("./workspaces-6TIM2TM2.js");
3955
4042
  await addWorkspace2(repoPath);
3956
4043
  const { ensureWorktreeSideboardIgnored } = await import("./worktree-exclude-KMZQXZKP.js");
3957
4044
  await ensureWorktreeSideboardIgnored(input.worktreePath);
@@ -6058,6 +6145,9 @@ function livePartsShowAgentReply(parts) {
6058
6145
  }
6059
6146
 
6060
6147
  // src/orchestrator/enqueue-thread-send.ts
6148
+ function sendFollowUpInterrupts(followUp, busy) {
6149
+ return followUp === "steer" && busy;
6150
+ }
6061
6151
  function resolveSendFollowUp(thread, requested) {
6062
6152
  if (requested === "steer" || requested === "queue") return requested;
6063
6153
  return isOrchestratorThread(thread) ? followUpBehavior() : "queue";
@@ -6144,14 +6234,20 @@ async function enqueueThreadSend(host, threadRef, prompt, opts) {
6144
6234
  if (current.status === "archived") {
6145
6235
  throw new Error(`Thread is archived: ${thread.id}`);
6146
6236
  }
6147
- 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
+ );
6148
6243
  const explicit = opts?.attachments;
6149
6244
  const consumed = explicit !== void 0 ? { attachments: current.attachments, consumed: explicit } : consumeComposerAttachments(current);
6150
6245
  const inFlightEarly = host.activeTurns.has(thread.id) || host.startingTurns.has(thread.id) || current.status === "running";
6151
6246
  const agentHasRepliedEarly = livePartsShowAgentReply(readTurnLiveParts(current.id));
6152
6247
  const draft = host.openSteerPrompt.get(current.id);
6153
6248
  const queuedHead = !inFlightEarly && current.status === "queued" && current.queue.length > 0 ? current.queue[0] : null;
6154
- 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;
6155
6251
  if (unanswered != null && (draft ? !draft.spawned : queuedHead != null)) {
6156
6252
  clearSendBookkeeping(host, thread.id);
6157
6253
  const combined = joinSteerPrompt(unanswered, prompt);
@@ -6202,7 +6298,10 @@ async function enqueueThreadSend(host, threadRef, prompt, opts) {
6202
6298
  );
6203
6299
  clearSendBookkeeping(host, thread.id);
6204
6300
  const inFlight = host.activeTurns.has(thread.id) || host.startingTurns.has(thread.id) || current.status === "running";
6205
- shouldSteer = followUp === "steer" && (inFlight || current.queue.length > 0);
6301
+ shouldSteer = sendFollowUpInterrupts(
6302
+ join15 ? "join" : followUp,
6303
+ inFlight || current.queue.length > 0
6304
+ );
6206
6305
  const patch = queued;
6207
6306
  if (explicit === void 0 && consumed.consumed.length > 0) {
6208
6307
  patch.attachments = consumed.attachments;
@@ -6423,7 +6522,7 @@ function formatWorktreeDirective(thread, opts) {
6423
6522
  lines.push(formatDevAccessHint(opts?.activeRuns));
6424
6523
  lines.push("");
6425
6524
  lines.push(
6426
- "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."
6427
6526
  );
6428
6527
  lines.push(
6429
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)."
@@ -7541,11 +7640,11 @@ function realDeps() {
7541
7640
  parentIdForThread,
7542
7641
  designatedId: designatedOrchestratorId,
7543
7642
  send: async (threadId, prompt) => {
7544
- const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-4SXTORD2.js");
7643
+ const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-I5G5A5BV.js");
7545
7644
  await getOrchestrator2().send(threadId, prompt, { followUp: "queue" });
7546
7645
  },
7547
7646
  startOrchestration: async (prompt) => {
7548
- const { startOrchestration: startOrchestration2 } = await import("./orchestrator-4SXTORD2.js");
7647
+ const { startOrchestration: startOrchestration2 } = await import("./orchestrator-I5G5A5BV.js");
7549
7648
  const defaults = resolveOrchestratorDefaults();
7550
7649
  await startOrchestration2({
7551
7650
  goal: prompt,
@@ -7572,7 +7671,7 @@ function formatScheduledPrompt(name, prompt) {
7572
7671
  ${prompt}`;
7573
7672
  }
7574
7673
  async function defaultDeps() {
7575
- const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-4SXTORD2.js");
7674
+ const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-I5G5A5BV.js");
7576
7675
  const orch = getOrchestrator2();
7577
7676
  return {
7578
7677
  findThread: (id) => findThreadByRef(id),
@@ -7672,8 +7771,8 @@ async function fireSchedule(id) {
7672
7771
  }
7673
7772
  }
7674
7773
  function clearTimer(id) {
7675
- const timer2 = timers.get(id);
7676
- if (timer2) clearTimeout(timer2);
7774
+ const timer3 = timers.get(id);
7775
+ if (timer3) clearTimeout(timer3);
7677
7776
  timers.delete(id);
7678
7777
  }
7679
7778
  function armOne(schedule) {
@@ -7689,7 +7788,7 @@ function armOne(schedule) {
7689
7788
  return;
7690
7789
  }
7691
7790
  const capped = Math.min(delay, SET_TIMEOUT_MAX);
7692
- const timer2 = setTimeout(() => {
7791
+ const timer3 = setTimeout(() => {
7693
7792
  timers.delete(schedule.id);
7694
7793
  const live = getSchedule(schedule.id);
7695
7794
  if (!live?.enabled) return;
@@ -7702,7 +7801,7 @@ function armOne(schedule) {
7702
7801
  if (isThisProcessDesktopHost()) armSchedules();
7703
7802
  });
7704
7803
  }, capped);
7705
- timers.set(schedule.id, timer2);
7804
+ timers.set(schedule.id, timer3);
7706
7805
  }
7707
7806
  function armSchedules() {
7708
7807
  if (!isThisProcessDesktopHost()) return;
@@ -7719,6 +7818,75 @@ function armSchedules() {
7719
7818
  }
7720
7819
  }
7721
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
+
7722
7890
  // src/orchestrator/orchestrator.ts
7723
7891
  var LIVE_TURN_SPAWN_GRACE_MS = 15e3;
7724
7892
  var RUN_SCRIPT_DESKTOP_ADOPT_MS = 2e4;
@@ -7916,6 +8084,7 @@ var Orchestrator = class {
7916
8084
  }
7917
8085
  this.schedulePendingQuotaResumes();
7918
8086
  armSchedules();
8087
+ armChatFollowUps();
7919
8088
  armGithubEdgeWatch();
7920
8089
  }
7921
8090
  /** Surface (and, when enabled, clean up) worktrees git knows about but no thread owns. */
@@ -8055,8 +8224,8 @@ var Orchestrator = class {
8055
8224
  }
8056
8225
  }
8057
8226
  clearQuotaResumeTimer(threadId) {
8058
- const timer2 = this.quotaResumeTimers.get(threadId);
8059
- if (timer2) clearTimeout(timer2);
8227
+ const timer3 = this.quotaResumeTimers.get(threadId);
8228
+ if (timer3) clearTimeout(timer3);
8060
8229
  this.quotaResumeTimers.delete(threadId);
8061
8230
  }
8062
8231
  /** Schedule (or fire) auto-retry after a provider session/usage limit reset. */
@@ -8065,11 +8234,11 @@ var Orchestrator = class {
8065
8234
  updateThread(threadId, { quotaResumeAt: resumeAt.toISOString() });
8066
8235
  const delay = Math.max(5e3, resumeAt.getTime() - Date.now());
8067
8236
  const capped = Math.min(delay, 2147483647);
8068
- const timer2 = setTimeout(() => {
8237
+ const timer3 = setTimeout(() => {
8069
8238
  this.quotaResumeTimers.delete(threadId);
8070
8239
  void this.resumeAfterQuotaWait(threadId);
8071
8240
  }, capped);
8072
- this.quotaResumeTimers.set(threadId, timer2);
8241
+ this.quotaResumeTimers.set(threadId, timer3);
8073
8242
  }
8074
8243
  schedulePendingQuotaResumes() {
8075
8244
  for (const thread of listThreads({ includeArchived: false })) {
@@ -9714,11 +9883,11 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9714
9883
  const start = Date.now();
9715
9884
  return new Promise((resolve, reject) => {
9716
9885
  let settled = false;
9717
- let timer2;
9886
+ let timer3;
9718
9887
  const finish = (fn) => {
9719
9888
  if (settled) return;
9720
9889
  settled = true;
9721
- if (timer2) clearInterval(timer2);
9890
+ if (timer3) clearInterval(timer3);
9722
9891
  off();
9723
9892
  fn();
9724
9893
  };
@@ -9744,7 +9913,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9744
9913
  }
9745
9914
  }
9746
9915
  });
9747
- timer2 = setInterval(() => {
9916
+ timer3 = setInterval(() => {
9748
9917
  const raw = readThread(thread.id);
9749
9918
  if (!raw) {
9750
9919
  finish(() => reject(new Error(`Thread not found: ${thread.id}`)));
@@ -10317,7 +10486,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10317
10486
  this.stop(thread.id, { notifyParent: false });
10318
10487
  this.releaseOrchestratorCaffeinate(thread);
10319
10488
  if (isGlobalThread(thread)) {
10320
- const archived2 = setStatus(thread.id, "archived");
10489
+ const archived2 = archiveClearingFollowUps(thread.id);
10321
10490
  this.emit({ type: "status_changed", threadId: archived2.id, status: "archived" });
10322
10491
  this.enforceHistoryRetention();
10323
10492
  return archived2;
@@ -10336,10 +10505,10 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10336
10505
  });
10337
10506
  } catch {
10338
10507
  }
10339
- await removeWorktree(thread.repoPath, thread.worktreePath);
10508
+ await removeWorktreeSavingLeftovers(thread);
10340
10509
  }
10341
10510
  }
10342
- const archived = setStatus(thread.id, "archived");
10511
+ const archived = archiveClearingFollowUps(thread.id);
10343
10512
  this.emit({ type: "status_changed", threadId: archived.id, status: "archived" });
10344
10513
  this.enforceHistoryRetention();
10345
10514
  if (thread.repoPath && !isGlobalRepoPath(thread.repoPath)) {
@@ -10369,9 +10538,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10369
10538
  }
10370
10539
  const { deleteBranchOnPurgeEnabled } = await import("./app-settings-PPIMYJKS.js");
10371
10540
  const deleteBranch = opts?.deleteBranch ?? deleteBranchOnPurgeEnabled();
10372
- await removeWorktree(thread.repoPath, thread.worktreePath, {
10373
- deleteBranch: deleteBranch ? thread.branchName : void 0
10374
- });
10541
+ await removeWorktreeDroppingLeftovers(thread, deleteBranch ? thread.branchName : void 0);
10375
10542
  }
10376
10543
  }
10377
10544
  deleteThreadRecord(thread.id);
@@ -10401,6 +10568,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10401
10568
  });
10402
10569
  const { ensureWorktreeSideboardIgnored } = await import("./worktree-exclude-KMZQXZKP.js");
10403
10570
  await ensureWorktreeSideboardIgnored(dest);
10571
+ await applyWorktreeLeftovers(thread.repoPath, dest, thread.branchName).catch(() => false);
10404
10572
  }
10405
10573
  const restorePatch = {};
10406
10574
  let alreadyMerged = normalizePrState(thread.prState) === "MERGED";
@@ -10505,7 +10673,7 @@ async function startOrchestration(opts) {
10505
10673
  sourceRef: "default",
10506
10674
  ...createOpts
10507
10675
  }).catch(async () => {
10508
- const { resolveDefaultBranch: resolveDefaultBranch2, resolveRepoRoot: resolveRepoRoot2 } = await import("./worktree-ROJXGBWS.js");
10676
+ const { resolveDefaultBranch: resolveDefaultBranch2, resolveRepoRoot: resolveRepoRoot2 } = await import("./worktree-7JFYDNUX.js");
10509
10677
  const repo = await resolveRepoRoot2(repoPath);
10510
10678
  const def = await resolveDefaultBranch2(repo);
10511
10679
  return orch.createThread({
@@ -10515,7 +10683,7 @@ async function startOrchestration(opts) {
10515
10683
  repoPath: repo
10516
10684
  });
10517
10685
  });
10518
- const { updateThread: upd } = await import("./thread-store-MEUWZDVV.js");
10686
+ const { updateThread: upd } = await import("./thread-store-QKNU5CHM.js");
10519
10687
  const updated = upd(thread.id, {
10520
10688
  sourceType: "orchestration",
10521
10689
  sourceRef: goal
@@ -23,7 +23,7 @@ import {
23
23
  normalizeTakenSlug,
24
24
  normalizeWorktreePath,
25
25
  takenSlugsFromThread
26
- } from "./chunk-MOUAM6ZC.js";
26
+ } from "./chunk-6RIPZ73M.js";
27
27
  import {
28
28
  getGithubGitAuthMode,
29
29
  getGithubPat