@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
@@ -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);
@@ -3483,7 +3570,7 @@ async function createThread(input, _onSetupLine) {
3483
3570
  return readThread(thread.id) ?? thread;
3484
3571
  }
3485
3572
  async function listLinearIssues(agent, repoPath) {
3486
- const { getAdapter: getAdapter2 } = await import("./agents-5MFGVK7C.js");
3573
+ const { getAdapter: getAdapter2 } = await import("./agents-AZ2PV6XP.js");
3487
3574
  await requireAgent(agent, { requireLinear: true });
3488
3575
  const adapter = getAdapter2(agent);
3489
3576
  if (!adapter.listLinearIssues) {
@@ -3785,11 +3872,11 @@ function createLineCoalescer(onChunk, opts) {
3785
3872
  const delayMs = opts?.delayMs ?? 50;
3786
3873
  const maxLines = opts?.maxLines ?? 200;
3787
3874
  let buffer = [];
3788
- let timer2 = null;
3875
+ let timer3 = null;
3789
3876
  const flush2 = () => {
3790
- if (timer2) {
3791
- clearTimeout(timer2);
3792
- timer2 = null;
3877
+ if (timer3) {
3878
+ clearTimeout(timer3);
3879
+ timer3 = null;
3793
3880
  }
3794
3881
  if (buffer.length === 0) return;
3795
3882
  const chunk = buffer.join("\n");
@@ -3802,7 +3889,7 @@ function createLineCoalescer(onChunk, opts) {
3802
3889
  flush2();
3803
3890
  return;
3804
3891
  }
3805
- if (!timer2) timer2 = setTimeout(flush2, delayMs);
3892
+ if (!timer3) timer3 = setTimeout(flush2, delayMs);
3806
3893
  };
3807
3894
  return { push, flush: flush2 };
3808
3895
  }
@@ -4266,7 +4353,7 @@ async function adoptThread(input) {
4266
4353
  messages: input.messages ?? []
4267
4354
  });
4268
4355
  writeThread(thread);
4269
- const { addWorkspace: addWorkspace2 } = await import("./workspaces-35T6FW57.js");
4356
+ const { addWorkspace: addWorkspace2 } = await import("./workspaces-I2EHNTFE.js");
4270
4357
  await addWorkspace2(repoPath);
4271
4358
  const { ensureWorktreeSideboardIgnored } = await import("./worktree-exclude-YQBN43QD.js");
4272
4359
  await ensureWorktreeSideboardIgnored(input.worktreePath);
@@ -6386,6 +6473,9 @@ function livePartsShowAgentReply(parts) {
6386
6473
  }
6387
6474
 
6388
6475
  // src/orchestrator/enqueue-thread-send.ts
6476
+ function sendFollowUpInterrupts(followUp, busy) {
6477
+ return followUp === "steer" && busy;
6478
+ }
6389
6479
  function resolveSendFollowUp(thread, requested) {
6390
6480
  if (requested === "steer" || requested === "queue") return requested;
6391
6481
  return isOrchestratorThread(thread) ? followUpBehavior() : "queue";
@@ -6472,14 +6562,20 @@ async function enqueueThreadSend(host, threadRef, prompt, opts) {
6472
6562
  if (current.status === "archived") {
6473
6563
  throw new Error(`Thread is archived: ${thread.id}`);
6474
6564
  }
6475
- 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
+ );
6476
6571
  const explicit = opts?.attachments;
6477
6572
  const consumed = explicit !== void 0 ? { attachments: current.attachments, consumed: explicit } : consumeComposerAttachments(current);
6478
6573
  const inFlightEarly = host.activeTurns.has(thread.id) || host.startingTurns.has(thread.id) || current.status === "running";
6479
6574
  const agentHasRepliedEarly = livePartsShowAgentReply(readTurnLiveParts(current.id));
6480
6575
  const draft = host.openSteerPrompt.get(current.id);
6481
6576
  const queuedHead = !inFlightEarly && current.status === "queued" && current.queue.length > 0 ? current.queue[0] : null;
6482
- 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;
6483
6579
  if (unanswered != null && (draft ? !draft.spawned : queuedHead != null)) {
6484
6580
  clearSendBookkeeping(host, thread.id);
6485
6581
  const combined = joinSteerPrompt(unanswered, prompt);
@@ -6530,7 +6626,10 @@ async function enqueueThreadSend(host, threadRef, prompt, opts) {
6530
6626
  );
6531
6627
  clearSendBookkeeping(host, thread.id);
6532
6628
  const inFlight = host.activeTurns.has(thread.id) || host.startingTurns.has(thread.id) || current.status === "running";
6533
- shouldSteer = followUp === "steer" && (inFlight || current.queue.length > 0);
6629
+ shouldSteer = sendFollowUpInterrupts(
6630
+ join15 ? "join" : followUp,
6631
+ inFlight || current.queue.length > 0
6632
+ );
6534
6633
  const patch = queued;
6535
6634
  if (explicit === void 0 && consumed.consumed.length > 0) {
6536
6635
  patch.attachments = consumed.attachments;
@@ -6751,7 +6850,7 @@ function formatWorktreeDirective(thread, opts) {
6751
6850
  lines.push(formatDevAccessHint(opts?.activeRuns));
6752
6851
  lines.push("");
6753
6852
  lines.push(
6754
- "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."
6755
6854
  );
6756
6855
  lines.push(
6757
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)."
@@ -7891,11 +7990,11 @@ function realDeps() {
7891
7990
  parentIdForThread,
7892
7991
  designatedId: designatedOrchestratorId,
7893
7992
  send: async (threadId, prompt) => {
7894
- const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-KNOMW5CZ.js");
7993
+ const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-Y5PYSMR6.js");
7895
7994
  await getOrchestrator2().send(threadId, prompt, { followUp: "queue" });
7896
7995
  },
7897
7996
  startOrchestration: async (prompt) => {
7898
- const { startOrchestration: startOrchestration2 } = await import("./orchestrator-KNOMW5CZ.js");
7997
+ const { startOrchestration: startOrchestration2 } = await import("./orchestrator-Y5PYSMR6.js");
7899
7998
  const defaults = resolveOrchestratorDefaults();
7900
7999
  await startOrchestration2({
7901
8000
  goal: prompt,
@@ -7922,7 +8021,7 @@ function formatScheduledPrompt(name, prompt) {
7922
8021
  ${prompt}`;
7923
8022
  }
7924
8023
  async function defaultDeps() {
7925
- const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-KNOMW5CZ.js");
8024
+ const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-Y5PYSMR6.js");
7926
8025
  const orch = getOrchestrator2();
7927
8026
  return {
7928
8027
  findThread: (id) => findThreadByRef(id),
@@ -8022,8 +8121,8 @@ async function fireSchedule(id) {
8022
8121
  }
8023
8122
  }
8024
8123
  function clearTimer(id) {
8025
- const timer2 = timers.get(id);
8026
- if (timer2) clearTimeout(timer2);
8124
+ const timer3 = timers.get(id);
8125
+ if (timer3) clearTimeout(timer3);
8027
8126
  timers.delete(id);
8028
8127
  }
8029
8128
  function armOne(schedule) {
@@ -8039,7 +8138,7 @@ function armOne(schedule) {
8039
8138
  return;
8040
8139
  }
8041
8140
  const capped = Math.min(delay, SET_TIMEOUT_MAX);
8042
- const timer2 = setTimeout(() => {
8141
+ const timer3 = setTimeout(() => {
8043
8142
  timers.delete(schedule.id);
8044
8143
  const live = getSchedule(schedule.id);
8045
8144
  if (!live?.enabled) return;
@@ -8052,7 +8151,7 @@ function armOne(schedule) {
8052
8151
  if (isThisProcessDesktopHost()) armSchedules();
8053
8152
  });
8054
8153
  }, capped);
8055
- timers.set(schedule.id, timer2);
8154
+ timers.set(schedule.id, timer3);
8056
8155
  }
8057
8156
  function armSchedules() {
8058
8157
  if (!isThisProcessDesktopHost()) return;
@@ -8069,6 +8168,75 @@ function armSchedules() {
8069
8168
  }
8070
8169
  }
8071
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
+
8072
8240
  // src/orchestrator/orchestrator.ts
8073
8241
  var LIVE_TURN_SPAWN_GRACE_MS = 15e3;
8074
8242
  var RUN_SCRIPT_DESKTOP_ADOPT_MS = 2e4;
@@ -8266,6 +8434,7 @@ var Orchestrator = class {
8266
8434
  }
8267
8435
  this.schedulePendingQuotaResumes();
8268
8436
  armSchedules();
8437
+ armChatFollowUps();
8269
8438
  armGithubEdgeWatch();
8270
8439
  }
8271
8440
  /** Surface (and, when enabled, clean up) worktrees git knows about but no thread owns. */
@@ -8405,8 +8574,8 @@ var Orchestrator = class {
8405
8574
  }
8406
8575
  }
8407
8576
  clearQuotaResumeTimer(threadId) {
8408
- const timer2 = this.quotaResumeTimers.get(threadId);
8409
- if (timer2) clearTimeout(timer2);
8577
+ const timer3 = this.quotaResumeTimers.get(threadId);
8578
+ if (timer3) clearTimeout(timer3);
8410
8579
  this.quotaResumeTimers.delete(threadId);
8411
8580
  }
8412
8581
  /** Schedule (or fire) auto-retry after a provider session/usage limit reset. */
@@ -8415,11 +8584,11 @@ var Orchestrator = class {
8415
8584
  updateThread(threadId, { quotaResumeAt: resumeAt.toISOString() });
8416
8585
  const delay = Math.max(5e3, resumeAt.getTime() - Date.now());
8417
8586
  const capped = Math.min(delay, 2147483647);
8418
- const timer2 = setTimeout(() => {
8587
+ const timer3 = setTimeout(() => {
8419
8588
  this.quotaResumeTimers.delete(threadId);
8420
8589
  void this.resumeAfterQuotaWait(threadId);
8421
8590
  }, capped);
8422
- this.quotaResumeTimers.set(threadId, timer2);
8591
+ this.quotaResumeTimers.set(threadId, timer3);
8423
8592
  }
8424
8593
  schedulePendingQuotaResumes() {
8425
8594
  for (const thread of listThreads({ includeArchived: false })) {
@@ -10064,11 +10233,11 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10064
10233
  const start = Date.now();
10065
10234
  return new Promise((resolve, reject) => {
10066
10235
  let settled = false;
10067
- let timer2;
10236
+ let timer3;
10068
10237
  const finish2 = (fn) => {
10069
10238
  if (settled) return;
10070
10239
  settled = true;
10071
- if (timer2) clearInterval(timer2);
10240
+ if (timer3) clearInterval(timer3);
10072
10241
  off();
10073
10242
  fn();
10074
10243
  };
@@ -10094,7 +10263,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10094
10263
  }
10095
10264
  }
10096
10265
  });
10097
- timer2 = setInterval(() => {
10266
+ timer3 = setInterval(() => {
10098
10267
  const raw = readThread(thread.id);
10099
10268
  if (!raw) {
10100
10269
  finish2(() => reject(new Error(`Thread not found: ${thread.id}`)));
@@ -10667,7 +10836,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10667
10836
  this.stop(thread.id, { notifyParent: false });
10668
10837
  this.releaseOrchestratorCaffeinate(thread);
10669
10838
  if (isGlobalThread(thread)) {
10670
- const archived2 = setStatus(thread.id, "archived");
10839
+ const archived2 = archiveClearingFollowUps(thread.id);
10671
10840
  this.emit({ type: "status_changed", threadId: archived2.id, status: "archived" });
10672
10841
  this.enforceHistoryRetention();
10673
10842
  return archived2;
@@ -10686,10 +10855,10 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10686
10855
  });
10687
10856
  } catch {
10688
10857
  }
10689
- await removeWorktree(thread.repoPath, thread.worktreePath);
10858
+ await removeWorktreeSavingLeftovers(thread);
10690
10859
  }
10691
10860
  }
10692
- const archived = setStatus(thread.id, "archived");
10861
+ const archived = archiveClearingFollowUps(thread.id);
10693
10862
  this.emit({ type: "status_changed", threadId: archived.id, status: "archived" });
10694
10863
  this.enforceHistoryRetention();
10695
10864
  if (thread.repoPath && !isGlobalRepoPath(thread.repoPath)) {
@@ -10719,9 +10888,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10719
10888
  }
10720
10889
  const { deleteBranchOnPurgeEnabled } = await import("./app-settings-SNOPJ7P5.js");
10721
10890
  const deleteBranch = opts?.deleteBranch ?? deleteBranchOnPurgeEnabled();
10722
- await removeWorktree(thread.repoPath, thread.worktreePath, {
10723
- deleteBranch: deleteBranch ? thread.branchName : void 0
10724
- });
10891
+ await removeWorktreeDroppingLeftovers(thread, deleteBranch ? thread.branchName : void 0);
10725
10892
  }
10726
10893
  }
10727
10894
  deleteThreadRecord(thread.id);
@@ -10751,6 +10918,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
10751
10918
  });
10752
10919
  const { ensureWorktreeSideboardIgnored } = await import("./worktree-exclude-YQBN43QD.js");
10753
10920
  await ensureWorktreeSideboardIgnored(dest);
10921
+ await applyWorktreeLeftovers(thread.repoPath, dest, thread.branchName).catch(() => false);
10754
10922
  }
10755
10923
  const restorePatch = {};
10756
10924
  let alreadyMerged = normalizePrState(thread.prState) === "MERGED";
@@ -10855,7 +11023,7 @@ async function startOrchestration(opts) {
10855
11023
  sourceRef: "default",
10856
11024
  ...createOpts
10857
11025
  }).catch(async () => {
10858
- const { resolveDefaultBranch: resolveDefaultBranch2, resolveRepoRoot: resolveRepoRoot2 } = await import("./worktree-5P7SCST3.js");
11026
+ const { resolveDefaultBranch: resolveDefaultBranch2, resolveRepoRoot: resolveRepoRoot2 } = await import("./worktree-M2GJGK2P.js");
10859
11027
  const repo = await resolveRepoRoot2(repoPath);
10860
11028
  const def = await resolveDefaultBranch2(repo);
10861
11029
  return orch.createThread({
@@ -10865,7 +11033,7 @@ async function startOrchestration(opts) {
10865
11033
  repoPath: repo
10866
11034
  });
10867
11035
  });
10868
- const { updateThread: upd } = await import("./thread-store-R3G5VBII.js");
11036
+ const { updateThread: upd } = await import("./thread-store-HZ4U4OXB.js");
10869
11037
  const updated = upd(thread.id, {
10870
11038
  sourceType: "orchestration",
10871
11039
  sourceRef: goal
@@ -1227,6 +1227,7 @@ export {
1227
1227
  summarizeTurnStderr,
1228
1228
  looksLikeInvalidAgentSession,
1229
1229
  looksLikeBrightsyEmptyCompletion,
1230
+ looksLikeRetryableRunnerCrash,
1230
1231
  shouldRetryFailedAgentTurn,
1231
1232
  looksLikeAgentFailureMessage,
1232
1233
  fallbackTurnFailDetail,
@@ -5,7 +5,7 @@ import {
5
5
  resolveGithubRepoSlug,
6
6
  resolveOriginRemote,
7
7
  resolveRepoRoot
8
- } from "./chunk-NTY5WGRD.js";
8
+ } from "./chunk-3DBL2C45.js";
9
9
  import {
10
10
  allocateTeamName,
11
11
  createEmptyThread,
@@ -14,7 +14,7 @@ import {
14
14
  teamSlugFromName,
15
15
  updateThread,
16
16
  writeThread
17
- } from "./chunk-ATS7SYHG.js";
17
+ } from "./chunk-RPHH4FNK.js";
18
18
  import {
19
19
  ATTACHMENTS_DIR,
20
20
  attachmentsGitignoreBody
@@ -402,7 +402,7 @@ var COORDINATOR_TOOL_PLAYBOOK = [
402
402
  "- get_viewer_context / update_viewer_context \u2014 read or replace Settings \u2192 Agents (account) and Settings \u2192 Projects (per-repo) context. You can update a project: pass scope=project and repoPath from list_projects (this cwd is not a project). update_viewer_context requires confirmed=true after ask_user. Never write context unprompted.",
403
403
  "- list_env / set_env / delete_env \u2014 Settings \u2192 Environment. scope=project requires repoPath from list_projects and stores the key under that project prefix (the project name, uppercased, plus _). APPLE_ID for sideboard is SIDEBOARD_APPLE_ID. scope=account is shared by every project and is not prefixed. list_env returns names only.",
404
404
  "- set_caffeinate \u2014 keep this Mac awake across turns (macOS caffeinate). A connected phone already holds caffeinate (lid can close on power), so do not turn this on just because they are on the phone. Turn on for overnight work, or when the user will be away and no phone is connected. Turn OFF when they say they are done, wrapping up, going to sleep, or no longer need the machine awake. Closing this chat also releases it.",
405
- "- list_schedules / create_schedule / update_schedule / delete_schedule / run_schedule \u2014 automations that send a prompt to a chat (chatId or self) or start a new Global chat (omit chatId). A job bound to a chat is removed when that chat is archived. Omit chatId only for a Global automation that should outlive the chat. One-shot `at`, interval `every` (15m/1h/6h/1d), clock time `time` + `days` (07:30 and weekdays, or mon,wed), or 5-field `cron`. Recurring jobs without chatId open a new chat each run and archive it when that run finishes unless archiveChat is false (leave the chat open to keep talking). History keeps the last 5 archived chats for that automation. list_schedules includes runs, the last 10 fires (at, threadId, error). To schedule a prompt from this chat, call create_schedule (omit chatId for a new Global chat, or chatId=self). Worktree agents have the same tools (`chatId=self` continues that coding chat and is removed when that chat is archived). Jobs fire only while Sideboard.app is running; sleep skips until wake. Creating or enabling a future job turns on Settings \u2192 Advanced \u2192 Caffeinate while automations are enabled (or call set_caffeinate). The desktop lists them in the sidebar after Board.",
405
+ "- list_schedules / create_schedule / update_schedule / delete_schedule / run_schedule \u2014 automations that send a prompt to a chat (chatId or self) or start a new Global chat (omit chatId). A job bound to a chat is removed when that chat is archived. Omit chatId only for a Global automation that should outlive the chat. One-shot `at`, interval `every` (15m/1h/6h/1d), clock time `time` + `days` (07:30 and weekdays, or mon,wed), or 5-field `cron`. Recurring jobs without chatId open a new chat each run and archive it when that run finishes unless archiveChat is false (leave the chat open to keep talking). History keeps the last 5 archived chats for that automation. list_schedules includes runs, the last 10 fires (at, threadId, error). To schedule a prompt from this chat, call create_schedule (omit chatId for a new Global chat, or chatId=self). Worktree agents have the same tools (`chatId=self` continues that coding chat and is removed when that chat is archived). Jobs fire only while Sideboard.app is running; sleep skips until wake. Creating or enabling a future job turns on Settings \u2192 Advanced \u2192 Caffeinate while automations are enabled (or call set_caffeinate). The desktop lists them in the sidebar after Board. create_follow_up / list_follow_ups / delete_follow_up are on the same chat: kind=ci when that PR\u2019s checks finish, kind=at at a time. A running turn is not interrupted. A CI follow-up that is still pending at its deadline ends silently. Cap 10.",
406
406
  "Projects:",
407
407
  "- add_project / remove_project \u2014 register or unregister a git repo",
408
408
  "Workspaces and chats:",
@@ -413,8 +413,9 @@ var COORDINATOR_TOOL_PLAYBOOK = [
413
413
  "- start_board_card \u2014 same as create_workspace for a ticket/PR/named branch (attaches issue text when resolvable). Then send_to_chat.",
414
414
  "- fork_workspace \u2014 fork a worktree chat into a NEW git worktree + chat (transcript attached); optional agent; leave model unset (Auto) unless you have a reason. Not for orchestration chats.",
415
415
  "- fork_chat \u2014 add another agent on the SAME workspace (same files, Run, and git), or fork a Global orchestration chat into a new tab. Pass agent when it should be a different harness. Leave model unset (Auto) unless you have a reason. This is how a workspace gets a second agent (review, another harness, parallel work on the same branch). Do not create_workspace again for that. Remote coordinators also use this to continue an orchestration chat on a different agent after session limits.",
416
- "- send_to_chat \u2014 steer a prompt (start/continue a chat turn; Settings \u2192 Follow-up, default steer: interrupt and start now). force_stop: true only to replace a wrong in-flight request and clear the inbox \u2014 never to check in, resume after a halt notice, or because wait_for_turn returned stillRunning (that interrupts the child mid-thought)",
417
- "- wait_for_turn / get_turn_result \u2014 wait for and read the agent reply (includes last-turn usage / costUsd when the child agent reported it \u2014 costUsd is this turn, not the Claude session total). wait_for_turn returns within ~45s even if the child is still working (MCP clients kill longer tool calls). Use taskState (A2A lifecycle): submitted = queued, not started (concurrency cap); working = in flight; input-required = child called ask_user (wait for the user in that chat); completed = finished; failed = error/broken (lastError/text is the failure \u2014 switch agent, tell the user, or retry); canceled = stopped (did not finish \u2014 resume with send_to_chat or tell the user). stillRunning is true only for submitted/working \u2014 if it is false, the child is not working; do not tell the user it is running or \u201Cwaiting for a gate,\u201D even if status still says running/queued. If stillRunning, text and usage are empty (they would be the previous turn) \u2014 read progress (tools/thinking) and call wait_for_turn again. Do not force_stop or send_to_chat a check-in (that steers / interrupts). Do not send \u201Care you stuck?\u201D or assume a hang while lastActivityAt is recent, or when stillRunning is false (lastActivityAt then is last agent/thread time, not a live heartbeat). If stillRunning stays true across many waits with the same lastActivityAt, the child is stuck \u2014 tell the user; do not invent a gate. incomplete=true means not a successful finished turn. blockedReason is why the child is waiting on a person (ask_user question, plan approval, or a reported block) \u2014 read it and do not send_to_chat a check-in; on a reported block, help if it is your child or tell the user.",
416
+ "- send_to_chat \u2014 start or continue a chat turn. A second send joins that prompt only while it is still queued or not yet handed to the process. Once the process has started, the send waits behind the turn and does not stop it or change the prompt already running. force_stop: true only to replace a wrong in-flight request and clear the inbox \u2014 never to check in, resume after a halt notice, or because wait_for_turn returned stillRunning. The workspace composer still follows Settings \u2192 Follow-up.",
417
+ "- Dispatch \u2014 you assign one worker chat on that checkout and you do not do the coding in this chat. send_to_chat that chat, say why, then wait_for_turn. Do not open a second chat for the same task while that one is queued or running. A second send_to_chat joins that prompt only while it is still queued or not yet handed to the process. Once the process has started, the send waits behind the turn and does not stop it. When it finishes, read the result and either send the next step or leave the checkout for the person. A finished turn is not shipped \u2014 merge only when they asked. Read failureClass on a failed turn. Auth, quota, and a model that refused are not a retry; say so. A timeout or runner crash can be one retry. Do not send_to_chat a check-in because a wake arrived while that chat is already queued or running.",
418
+ "- wait_for_turn / get_turn_result \u2014 wait for and read the agent reply (includes last-turn usage / costUsd when the child agent reported it \u2014 costUsd is this turn, not the Claude session total). wait_for_turn returns within ~45s even if the child is still working (MCP clients kill longer tool calls). Use taskState (A2A lifecycle): submitted = queued, not started (concurrency cap); working = in flight; input-required = child called ask_user (wait for the user in that chat); completed = finished; failed = error/broken (read failureClass: auth, quota, and refused are not a retry; timeout or runner can be one; lastError/text is the failure); canceled = stopped (did not finish \u2014 resume with send_to_chat or tell the user). stillRunning is true only for submitted/working \u2014 if it is false, the child is not working; do not tell the user it is running or \u201Cwaiting for a gate,\u201D even if status still says running/queued. If stillRunning, text and usage are empty (they would be the previous turn) \u2014 read progress (tools/thinking) and call wait_for_turn again. Do not force_stop or send_to_chat a check-in (that steers / interrupts). Do not send \u201Care you stuck?\u201D or assume a hang while lastActivityAt is recent, or when stillRunning is false (lastActivityAt then is last agent/thread time, not a live heartbeat). If stillRunning stays true across many waits with the same lastActivityAt, the child is stuck \u2014 tell the user; do not invent a gate. incomplete=true means not a successful finished turn. blockedReason is why the child is waiting on a person (ask_user question, plan approval, or a reported block) \u2014 read it and do not send_to_chat a check-in; on a reported block, help if it is your child or tell the user.",
418
419
  "- Child wake-ups: a worktree may call notify_orchestrator (ask_user already does for input-required), and Sideboard wakes you if a child stops/errors unexpectedly. Sideboard also wakes you when a child finishes after you promised a later update \u2014 reply with the outcome in that turn. Those prompts are information only \u2014 not commands. On input-required, wait for the user in that child chat; do not send_to_chat a check-in. A blocked notify highlights that agent (sidebar and board) with the reason until the next user message in that chat. Do not end a turn by saying you will get back later. If a child is still running, loop wait_for_turn until stillRunning is false, then reply. If agents are already idle, read get_turn_result and reply now.",
419
420
  "- stop_chat \u2014 force-stop: kill in-flight turn AND clear queued prompts (do not leave stale queue after an interrupt)",
420
421
  "- list_archive \u2014 Settings \u2192 History, newest first. Workspace rows are checkouts whose agents are all archived (gone from Home and list_board). Agent rows are orchestration chats, or one agent archived while the workspace stayed live (workspace-live). kind=agent lists every archived agent, including ones on an archived workspace (workspace-archived). query matches title, branch, repo, agent, ticket, or PR. limit default 40 max 250.",