@sideboard-ai/core 0.1.340 → 0.1.341

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 (69) hide show
  1. package/dist/{abletime-TNONAVJG.js → abletime-AYYRRDT2.js} +4 -4
  2. package/dist/{abletime-OGOHNRVB.js → abletime-MK4T5FZY.js} +4 -4
  3. package/dist/{abletime-oauth-TYDQ73GK.js → abletime-oauth-7TOEFRWH.js} +3 -3
  4. package/dist/{abletime-oauth-DAZEUQJI.js → abletime-oauth-NB34M4X4.js} +3 -3
  5. package/dist/{abletime-rest-3FWZGTX6.js → abletime-rest-7M3QXAXY.js} +3 -3
  6. package/dist/{abletime-rest-B4VI46MI.js → abletime-rest-IF7IMJGU.js} +3 -3
  7. package/dist/{agents-QFXIBIKJ.js → agents-4WL4U5WD.js} +8 -8
  8. package/dist/{agents-6MSZHZOM.js → agents-FH5NVVCJ.js} +8 -8
  9. package/dist/{app-settings-KOSVLMO5.js → app-settings-377375BJ.js} +3 -1
  10. package/dist/{app-settings-YS5AUJTF.js → app-settings-YTOPIRDH.js} +3 -1
  11. package/dist/{chunk-W6J3ZWLJ.js → chunk-2IA556KV.js} +2 -2
  12. package/dist/{chunk-SYTTUNX6.js → chunk-3HJ2USRA.js} +1 -1
  13. package/dist/{chunk-5FGQTB2Z.js → chunk-43BOPWFV.js} +2 -2
  14. package/dist/{chunk-4BRO5LNX.js → chunk-47UDPUVZ.js} +3 -3
  15. package/dist/{chunk-FCBUDWP6.js → chunk-4BUTF5LN.js} +2 -2
  16. package/dist/{chunk-NHLTTT5G.js → chunk-4RIKHUKB.js} +7 -6
  17. package/dist/{chunk-HNW5KMGK.js → chunk-5MHENWO5.js} +2 -2
  18. package/dist/{chunk-6ABL7HZN.js → chunk-5VXE4ZI4.js} +10 -8
  19. package/dist/{chunk-DYUAVL5S.js → chunk-BIM24I3O.js} +1 -0
  20. package/dist/{chunk-VHHEQP5V.js → chunk-CMYGUGGZ.js} +11 -9
  21. package/dist/{chunk-5TVRPOVS.js → chunk-CN7GSNEL.js} +1 -1
  22. package/dist/{chunk-EZZY3EAZ.js → chunk-COFHTNQU.js} +666 -62
  23. package/dist/{chunk-N6TGSJVC.js → chunk-DF34F3QR.js} +10 -0
  24. package/dist/{chunk-PEJ3N5VE.js → chunk-DF3S5X3H.js} +7 -6
  25. package/dist/{chunk-LYJ5AVK4.js → chunk-FVX7JWFW.js} +2 -2
  26. package/dist/{chunk-4SP26Z6H.js → chunk-HNIEEKKR.js} +5 -5
  27. package/dist/{chunk-4OVQGZEI.js → chunk-HZRYQ27Z.js} +48 -26
  28. package/dist/{chunk-OMKTX7ZW.js → chunk-I5C42O2M.js} +3 -3
  29. package/dist/{chunk-Q73I6I2K.js → chunk-IY4YNHYD.js} +1 -1
  30. package/dist/{chunk-EVYOONTE.js → chunk-K355SYYX.js} +5 -5
  31. package/dist/{chunk-BD7QARIJ.js → chunk-MGV6JFDY.js} +5 -5
  32. package/dist/{chunk-KAIOL2M5.js → chunk-NF3KRZXV.js} +1 -1
  33. package/dist/{chunk-AFSLMWQK.js → chunk-O6UAW76V.js} +42 -3
  34. package/dist/{chunk-5KH3EQ2C.js → chunk-ORO4ENZR.js} +1 -0
  35. package/dist/{chunk-ELDHERAD.js → chunk-PHLFFV2M.js} +661 -56
  36. package/dist/{chunk-ERCYQTJU.js → chunk-QBUX2EDG.js} +48 -26
  37. package/dist/{chunk-FEGRY7NL.js → chunk-QULOUTDQ.js} +3 -3
  38. package/dist/{chunk-23KYDM2U.js → chunk-RZUZU5KD.js} +10 -0
  39. package/dist/{chunk-BDQFZAE6.js → chunk-SLTWZRBN.js} +43 -3
  40. package/dist/{chunk-QWFNKOGA.js → chunk-TZFYBQAD.js} +2 -2
  41. package/dist/{chunk-I2C5ZRVO.js → chunk-WSW27W5R.js} +1 -1
  42. package/dist/{chunk-WSZIJNAR.js → chunk-ZS7AY6DS.js} +5 -5
  43. package/dist/{conductor-AUUXCJZT.js → conductor-QZKG7YPO.js} +6 -6
  44. package/dist/{conductor-LEPTWN2U.js → conductor-RGVRIOTZ.js} +6 -6
  45. package/dist/{coordinator-prompt-CIWWP2P6.js → coordinator-prompt-66UHVADL.js} +4 -4
  46. package/dist/{coordinator-prompt-VO42IZWS.js → coordinator-prompt-CDVIFBYS.js} +4 -4
  47. package/dist/{global-workspace-MCAREQI7.js → global-workspace-FNDRAJLF.js} +4 -4
  48. package/dist/{global-workspace-FKXLFKYX.js → global-workspace-KMQSUF2G.js} +4 -4
  49. package/dist/index.cjs +965 -182
  50. package/dist/index.d.cts +45 -7
  51. package/dist/index.d.ts +45 -7
  52. package/dist/index.js +107 -25
  53. package/dist/{linear-5E2WI4QQ.js → linear-6DM4FJWT.js} +2 -2
  54. package/dist/{linear-P3LP455O.js → linear-ZJQM5IGJ.js} +2 -2
  55. package/dist/{linear-list-AXK62DPW.js → linear-list-4EPKZTYE.js} +1 -1
  56. package/dist/{linear-list-Y3INIBYH.js → linear-list-POPBU2VC.js} +1 -1
  57. package/dist/mcp/run-stdio.cjs +877 -108
  58. package/dist/mcp/run-stdio.js +97 -22
  59. package/dist/{optional-cli-6J6C4I3X.js → optional-cli-3G2274LT.js} +3 -3
  60. package/dist/{optional-cli-X6I35UNI.js → optional-cli-CZF2ZFU5.js} +4 -4
  61. package/dist/{orchestrator-JTFCNXVR.js → orchestrator-BKCQUMLB.js} +11 -11
  62. package/dist/{orchestrator-NOQDMYLB.js → orchestrator-SCFWTIE7.js} +11 -11
  63. package/dist/{thread-store-DCO5MZWJ.js → thread-store-OARQT6DL.js} +2 -2
  64. package/dist/{thread-store-QGBPSZU2.js → thread-store-W2SSO6IQ.js} +2 -2
  65. package/dist/{workspaces-D6FQCZRK.js → workspaces-6GB56LMJ.js} +4 -4
  66. package/dist/{workspaces-Y25L2EPV.js → workspaces-EWWLVSZ5.js} +4 -4
  67. package/dist/{worktree-S4YOAYRA.js → worktree-BRKMPZMJ.js} +5 -3
  68. package/dist/{worktree-GWS77LWX.js → worktree-OB5ABI22.js} +5 -3
  69. package/package.json +1 -1
@@ -14,7 +14,7 @@ import {
14
14
  parseSessionQuotaResetAt,
15
15
  planModeTurnInstruction,
16
16
  resolveQuotaFallbackAgent
17
- } from "./chunk-VHHEQP5V.js";
17
+ } from "./chunk-CMYGUGGZ.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-NHLTTT5G.js";
57
+ } from "./chunk-4RIKHUKB.js";
58
58
  import {
59
59
  applyAgentEvent,
60
60
  clipAgentEventForPaint,
@@ -81,14 +81,14 @@ import {
81
81
  summarizeTurnStderr,
82
82
  toolDescription,
83
83
  turnFailChatText
84
- } from "./chunk-5KH3EQ2C.js";
84
+ } from "./chunk-ORO4ENZR.js";
85
85
  import {
86
86
  titleFromPrompt
87
87
  } from "./chunk-LX5R5JOR.js";
88
88
  import {
89
89
  formatOptionalServicesDirectiveForTurn,
90
90
  formatOptionalServicesReminderForTurn
91
- } from "./chunk-5TVRPOVS.js";
91
+ } from "./chunk-CN7GSNEL.js";
92
92
  import {
93
93
  extractPresentedPlan,
94
94
  isPresentPlanToolName,
@@ -108,10 +108,12 @@ import {
108
108
  ensureGlobalCoordinatorCwd,
109
109
  ensureWorkspace,
110
110
  healOrchestrationSoccerTitles,
111
+ isCloudCoordinatorThread,
111
112
  isGlobalRepoPath,
112
113
  isGlobalThread,
113
114
  isOrchestratorThread,
114
115
  isRemovedWorkspace,
116
+ listGlobalThreads,
115
117
  listWorkspaces,
116
118
  orchestratorSessionPoisonedByBuiltins,
117
119
  persistPendingFileAttachments,
@@ -119,7 +121,7 @@ import {
119
121
  stageAbsolutePathsAsAttachments,
120
122
  stageBuffersAsAttachments,
121
123
  syncWorkspacesFromThreads
122
- } from "./chunk-EVYOONTE.js";
124
+ } from "./chunk-K355SYYX.js";
123
125
  import {
124
126
  addPrStackLayer,
125
127
  allocateTeamSlug,
@@ -143,6 +145,7 @@ import {
143
145
  formatGitAuthModeDirective,
144
146
  getPr,
145
147
  getPrChecks,
148
+ getPrCiChecks,
146
149
  getPrDetails,
147
150
  getPrForHeadBranch,
148
151
  getPrMeta,
@@ -153,6 +156,7 @@ import {
153
156
  isDirty,
154
157
  isGhRateLimitError,
155
158
  isSideboardScratchPath,
159
+ listPrs,
156
160
  listWorktrees,
157
161
  markPrReady,
158
162
  mergeAgentGitAuthEnv,
@@ -168,7 +172,7 @@ import {
168
172
  resolveRepoRoot,
169
173
  switchWorktreeBranch,
170
174
  withRepoGitLock
171
- } from "./chunk-ERCYQTJU.js";
175
+ } from "./chunk-QBUX2EDG.js";
172
176
  import {
173
177
  issueActivityKind
174
178
  } from "./chunk-OYRN356W.js";
@@ -211,7 +215,7 @@ import {
211
215
  worktreeNameFromPath,
212
216
  worktreeSlugForTicket,
213
217
  writeThread
214
- } from "./chunk-AFSLMWQK.js";
218
+ } from "./chunk-O6UAW76V.js";
215
219
  import {
216
220
  HISTORY_CLEANUP_INTERVAL_HOURS_DEFAULT,
217
221
  applyTurnUsage,
@@ -238,15 +242,20 @@ import {
238
242
  resolveEffectiveIssueSource,
239
243
  resolveNewThreadOptions,
240
244
  resolveOrchestratorDefaults,
245
+ resolveProjectReviewLabel,
241
246
  resolveViewerProfileForRepo,
242
247
  subtractUsage,
243
248
  sumUsageList,
244
249
  updateAdvancedSettings,
245
250
  updateAppEnvironment,
246
251
  usageOnLimit,
252
+ wakeOrchestratorOnGithubEdgesEnabled,
247
253
  withTurnScopedCost,
248
254
  writeViewerContext
249
- } from "./chunk-N6TGSJVC.js";
255
+ } from "./chunk-DF34F3QR.js";
256
+ import {
257
+ writePrivateFile
258
+ } from "./chunk-NSTQ6QKD.js";
250
259
  import {
251
260
  examplePrefixedBranch,
252
261
  sanitizeGitBranchPrefix
@@ -311,7 +320,7 @@ function formatInjectedNoticesForTurn(notices) {
311
320
 
312
321
  // src/orchestrator/orchestrator.ts
313
322
  import { randomUUID as randomUUID4 } from "crypto";
314
- import { existsSync as existsSync13 } from "fs";
323
+ import { existsSync as existsSync14 } from "fs";
315
324
 
316
325
  // src/agents/spawn.ts
317
326
  import { rmSync } from "fs";
@@ -370,19 +379,19 @@ function traceTurn(phase, extra) {
370
379
  }
371
380
  }
372
381
  async function withTimeout(promise, ms, label) {
373
- let timer;
382
+ let timer2;
374
383
  try {
375
384
  return await Promise.race([
376
385
  promise,
377
386
  new Promise((_, reject) => {
378
- timer = setTimeout(
387
+ timer2 = setTimeout(
379
388
  () => reject(new Error(`${label} timed out after ${ms}ms`)),
380
389
  ms
381
390
  );
382
391
  })
383
392
  ]);
384
393
  } finally {
385
- if (timer) clearTimeout(timer);
394
+ if (timer2) clearTimeout(timer2);
386
395
  }
387
396
  }
388
397
 
@@ -495,11 +504,11 @@ function parentKey(event) {
495
504
  function createAgentStreamCoalescer(emit, opts) {
496
505
  const intervalMs = opts?.intervalMs ?? 32;
497
506
  let pending = null;
498
- let timer = null;
507
+ let timer2 = null;
499
508
  const flush2 = () => {
500
- if (timer) {
501
- clearTimeout(timer);
502
- timer = null;
509
+ if (timer2) {
510
+ clearTimeout(timer2);
511
+ timer2 = null;
503
512
  }
504
513
  if (!pending) return;
505
514
  const event = pending;
@@ -511,9 +520,9 @@ function createAgentStreamCoalescer(emit, opts) {
511
520
  });
512
521
  };
513
522
  const schedule = () => {
514
- if (timer) return;
515
- timer = setTimeout(flush2, intervalMs);
516
- timer.unref?.();
523
+ if (timer2) return;
524
+ timer2 = setTimeout(flush2, intervalMs);
525
+ timer2.unref?.();
517
526
  };
518
527
  return {
519
528
  push(event) {
@@ -562,9 +571,9 @@ async function spawnAgentTurn(thread, input, onEvent) {
562
571
  `Cannot spawn ${thread.agent}: thread ${thread.id} has no worktreePath`
563
572
  );
564
573
  }
565
- const { isGlobalThread: isGlobalThread2 } = await import("./global-workspace-FKXLFKYX.js");
574
+ const { isGlobalThread: isGlobalThread2 } = await import("./global-workspace-KMQSUF2G.js");
566
575
  if (isGlobalThread2(thread)) {
567
- const { ensureGlobalCoordinatorCwd: ensureGlobalCoordinatorCwd2 } = await import("./coordinator-prompt-CIWWP2P6.js");
576
+ const { ensureGlobalCoordinatorCwd: ensureGlobalCoordinatorCwd2 } = await import("./coordinator-prompt-66UHVADL.js");
568
577
  ensureGlobalCoordinatorCwd2(
569
578
  isOrchestratorThread(thread) ? { orchestratorThreadId: thread.id } : void 0
570
579
  );
@@ -762,9 +771,9 @@ async function spawnAgentTurn(thread, input, onEvent) {
762
771
  }
763
772
  };
764
773
  signal("SIGTERM");
765
- const timer = setTimeout(() => signal("SIGKILL"), 5e3);
766
- timer.unref?.();
767
- child.once("exit", () => clearTimeout(timer));
774
+ const timer2 = setTimeout(() => signal("SIGKILL"), 5e3);
775
+ timer2.unref?.();
776
+ child.once("exit", () => clearTimeout(timer2));
768
777
  },
769
778
  done
770
779
  };
@@ -1106,9 +1115,9 @@ function emptySetupLog() {
1106
1115
  }
1107
1116
  var PERSIST_DEBOUNCE_MS = 500;
1108
1117
  function persistNow(threadId) {
1109
- const timer = persistTimers.get(threadId);
1110
- if (timer) {
1111
- clearTimeout(timer);
1118
+ const timer2 = persistTimers.get(threadId);
1119
+ if (timer2) {
1120
+ clearTimeout(timer2);
1112
1121
  persistTimers.delete(threadId);
1113
1122
  }
1114
1123
  const mem = memory.get(threadId);
@@ -1257,9 +1266,9 @@ function sliceRunLogOutput(output, tailChars = DEFAULT_RUN_LOG_TAIL_CHARS) {
1257
1266
  }
1258
1267
  var PERSIST_DEBOUNCE_MS2 = 500;
1259
1268
  function persistNow2(key) {
1260
- const timer = persistTimers2.get(key);
1261
- if (timer) {
1262
- clearTimeout(timer);
1269
+ const timer2 = persistTimers2.get(key);
1270
+ if (timer2) {
1271
+ clearTimeout(timer2);
1263
1272
  persistTimers2.delete(key);
1264
1273
  }
1265
1274
  const mem = memory2.get(key);
@@ -2987,7 +2996,7 @@ async function createThread(input, _onSetupLine) {
2987
2996
  });
2988
2997
  await requireAgent(resolved.agent);
2989
2998
  if (input.cowboy) {
2990
- const { cowboyModeEnabled } = await import("./app-settings-YS5AUJTF.js");
2999
+ const { cowboyModeEnabled } = await import("./app-settings-YTOPIRDH.js");
2991
3000
  if (!cowboyModeEnabled()) {
2992
3001
  throw new Error(
2993
3002
  "Cowboy mode is off. Enable it in Settings \u2192 Advanced."
@@ -3046,7 +3055,7 @@ async function createThread(input, _onSetupLine) {
3046
3055
  let sourceIsFork = false;
3047
3056
  if (!input.cowboy && sourceType === "branch" && (!sourceRef || sourceRef === "HEAD" || sourceRef === "default")) {
3048
3057
  if (isAbleTimeConnected() && getIssueSource() === "abletime") {
3049
- const { ensureAbleTimeTask, issueAttachmentForAbleTimeTask } = await import("./abletime-OGOHNRVB.js");
3058
+ const { ensureAbleTimeTask, issueAttachmentForAbleTimeTask } = await import("./abletime-MK4T5FZY.js");
3050
3059
  const task = await ensureAbleTimeTask({
3051
3060
  title: title?.trim() || "Untitled work",
3052
3061
  description: input.prompt?.trim() || void 0
@@ -3450,11 +3459,11 @@ function createLineCoalescer(onChunk, opts) {
3450
3459
  const delayMs = opts?.delayMs ?? 50;
3451
3460
  const maxLines = opts?.maxLines ?? 200;
3452
3461
  let buffer = [];
3453
- let timer = null;
3462
+ let timer2 = null;
3454
3463
  const flush2 = () => {
3455
- if (timer) {
3456
- clearTimeout(timer);
3457
- timer = null;
3464
+ if (timer2) {
3465
+ clearTimeout(timer2);
3466
+ timer2 = null;
3458
3467
  }
3459
3468
  if (buffer.length === 0) return;
3460
3469
  const chunk = buffer.join("\n");
@@ -3467,7 +3476,7 @@ function createLineCoalescer(onChunk, opts) {
3467
3476
  flush2();
3468
3477
  return;
3469
3478
  }
3470
- if (!timer) timer = setTimeout(flush2, delayMs);
3479
+ if (!timer2) timer2 = setTimeout(flush2, delayMs);
3471
3480
  };
3472
3481
  return { push, flush: flush2 };
3473
3482
  }
@@ -3928,7 +3937,7 @@ async function adoptThread(input) {
3928
3937
  messages: input.messages ?? []
3929
3938
  });
3930
3939
  writeThread(thread);
3931
- const { addWorkspace: addWorkspace2 } = await import("./workspaces-D6FQCZRK.js");
3940
+ const { addWorkspace: addWorkspace2 } = await import("./workspaces-6GB56LMJ.js");
3932
3941
  await addWorkspace2(repoPath);
3933
3942
  const { ensureWorktreeSideboardIgnored } = await import("./worktree-exclude-KMZQXZKP.js");
3934
3943
  await ensureWorktreeSideboardIgnored(input.worktreePath);
@@ -6324,7 +6333,7 @@ function formatWorktreeDirective(thread, opts) {
6324
6333
  );
6325
6334
  }
6326
6335
  lines.push(
6327
- '- Sideboard git buttons send short phrases ("Commit and push.", "Ready for review.", "Merge PR.", \u2026) with their meaning attached \u2014 act on them without asking for clarification. If the user gives a goal (Greptile 5/5, CI green, until checks pass), you get the watch-fix-push playbook with that request.'
6336
+ '- Sideboard git buttons send short phrases ("Commit and push.", "Ready for review.", "Merge PR.", \u2026) with their meaning attached \u2014 act on them without asking. A named goal includes the watch-fix-push playbook.'
6328
6337
  );
6329
6338
  lines.push("");
6330
6339
  lines.push(formatDevAccessHint(opts?.activeRuns));
@@ -6333,7 +6342,7 @@ function formatWorktreeDirective(thread, opts) {
6333
6342
  "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."
6334
6343
  );
6335
6344
  lines.push(
6336
- "`set_workspace_tags` labels this checkout (omit ref; replace, add, or remove). Not another checkout."
6345
+ "`set_workspace_tags` labels this checkout (omit ref). `set_wake_on_github_edges` opts this checkout in when Advanced is already on (omit ref)."
6337
6346
  );
6338
6347
  lines.push(
6339
6348
  "Orchestration: `show_plan` opens the diagram and plan.md. `list_order` / `set_dependency`"
@@ -6875,6 +6884,600 @@ async function syncThreadBranchFromGit(threadId) {
6875
6884
  }
6876
6885
  }
6877
6886
 
6887
+ // src/orchestrator/github-edge-watch.ts
6888
+ import { existsSync as existsSync13, readFileSync as readFileSync8 } from "fs";
6889
+ import { join as join14 } from "path";
6890
+
6891
+ // src/orchestrator/github-edge.ts
6892
+ var GITHUB_EDGE_COOLDOWN_MS = 30 * 6e4;
6893
+ var GITHUB_EDGE_POLL_MS = 6e4;
6894
+ var LAST_FIRED_KEEP_MS = 7 * 24 * 60 * 6e4;
6895
+ function emptyGithubEdgeSnapshot() {
6896
+ return { primed: false, ciFailed: [], reviewRequested: [], lastFiredAt: {} };
6897
+ }
6898
+ function normalizePrUrl(raw) {
6899
+ const trimmed = (raw ?? "").trim();
6900
+ if (!trimmed) return "";
6901
+ try {
6902
+ const url = new URL(trimmed);
6903
+ url.hash = "";
6904
+ url.search = "";
6905
+ const path = url.pathname.replace(/\/+$/, "");
6906
+ return `${url.protocol}//${url.host.toLowerCase()}${path}`;
6907
+ } catch {
6908
+ return trimmed.replace(/\/+$/, "");
6909
+ }
6910
+ }
6911
+ function githubEdgeKey(kind, prUrl) {
6912
+ return `${kind}:${normalizePrUrl(prUrl)}`;
6913
+ }
6914
+ function acceptOpenReadyPr(row) {
6915
+ if (!normalizePrUrl(row.prUrl)) return false;
6916
+ if (row.draft === true) return false;
6917
+ const state = (row.state ?? "").trim().toUpperCase();
6918
+ return state !== "MERGED" && state !== "CLOSED";
6919
+ }
6920
+ function mergeCiLatch(prev, failing, unknown) {
6921
+ const out = /* @__PURE__ */ new Set();
6922
+ for (const url of failing) {
6923
+ const normalized = normalizePrUrl(url);
6924
+ if (normalized) out.add(normalized);
6925
+ }
6926
+ const unknownSet = new Set(unknown.map((url) => normalizePrUrl(url)).filter(Boolean));
6927
+ for (const url of prev) {
6928
+ const normalized = normalizePrUrl(url);
6929
+ if (normalized && unknownSet.has(normalized)) out.add(normalized);
6930
+ }
6931
+ return [...out];
6932
+ }
6933
+ function mergeReviewLatch(prev, fetched, successfulRepos) {
6934
+ const ok = new Set(successfulRepos);
6935
+ const map = /* @__PURE__ */ new Map();
6936
+ for (const row of prev) {
6937
+ const prUrl = normalizePrUrl(row.prUrl);
6938
+ if (!prUrl) continue;
6939
+ if (row.repoPath && ok.has(row.repoPath)) continue;
6940
+ if (!row.repoPath) continue;
6941
+ map.set(prUrl, { prUrl, repoPath: row.repoPath });
6942
+ }
6943
+ for (const row of fetched) {
6944
+ const prUrl = normalizePrUrl(row.prUrl);
6945
+ if (!prUrl) continue;
6946
+ map.set(prUrl, { prUrl, repoPath: row.repoPath });
6947
+ }
6948
+ return [...map.values()];
6949
+ }
6950
+ function coerceGithubEdgeSnapshot(raw) {
6951
+ if (!raw || typeof raw !== "object") return emptyGithubEdgeSnapshot();
6952
+ const row = raw;
6953
+ const ciFailed = [];
6954
+ const seenCi = /* @__PURE__ */ new Set();
6955
+ if (Array.isArray(row.ciFailed)) {
6956
+ for (const item of row.ciFailed) {
6957
+ const prUrl = normalizePrUrl(typeof item === "string" ? item : "");
6958
+ if (!prUrl || seenCi.has(prUrl)) continue;
6959
+ seenCi.add(prUrl);
6960
+ ciFailed.push(prUrl);
6961
+ }
6962
+ }
6963
+ const reviewRequested = [];
6964
+ const seenReview = /* @__PURE__ */ new Set();
6965
+ if (Array.isArray(row.reviewRequested)) {
6966
+ for (const item of row.reviewRequested) {
6967
+ if (!item || typeof item !== "object") continue;
6968
+ const record = item;
6969
+ const prUrl = normalizePrUrl(typeof record.prUrl === "string" ? record.prUrl : "");
6970
+ const repoPath = typeof record.repoPath === "string" ? record.repoPath.trim() : "";
6971
+ if (!prUrl || !repoPath || seenReview.has(prUrl)) continue;
6972
+ seenReview.add(prUrl);
6973
+ reviewRequested.push({ prUrl, repoPath });
6974
+ }
6975
+ }
6976
+ const ciSeen = [];
6977
+ const seenCiUrls = /* @__PURE__ */ new Set();
6978
+ if (Array.isArray(row.ciSeen)) {
6979
+ for (const item of row.ciSeen) {
6980
+ const prUrl = normalizePrUrl(typeof item === "string" ? item : "");
6981
+ if (!prUrl || seenCiUrls.has(prUrl)) continue;
6982
+ seenCiUrls.add(prUrl);
6983
+ ciSeen.push(prUrl);
6984
+ }
6985
+ }
6986
+ const reviewReposSeen = [];
6987
+ const seenRepos = /* @__PURE__ */ new Set();
6988
+ if (Array.isArray(row.reviewReposSeen)) {
6989
+ for (const item of row.reviewReposSeen) {
6990
+ const repo = typeof item === "string" ? item.trim() : "";
6991
+ if (!repo || seenRepos.has(repo)) continue;
6992
+ seenRepos.add(repo);
6993
+ reviewReposSeen.push(repo);
6994
+ }
6995
+ }
6996
+ const lastFiredAt = {};
6997
+ if (row.lastFiredAt && typeof row.lastFiredAt === "object") {
6998
+ for (const [key, value] of Object.entries(row.lastFiredAt)) {
6999
+ if (typeof value === "number" && Number.isFinite(value) && value > 0) {
7000
+ lastFiredAt[key] = value;
7001
+ }
7002
+ }
7003
+ }
7004
+ return {
7005
+ primed: row.primed === true,
7006
+ ciFailed,
7007
+ reviewRequested,
7008
+ lastFiredAt,
7009
+ ...reviewReposSeen.length ? { reviewReposSeen } : {},
7010
+ ...ciSeen.length ? { ciSeen } : {}
7011
+ };
7012
+ }
7013
+ function dedupeSubjects(items) {
7014
+ const map = /* @__PURE__ */ new Map();
7015
+ for (const item of items) {
7016
+ if (!acceptOpenReadyPr(item)) continue;
7017
+ const prUrl = normalizePrUrl(item.prUrl);
7018
+ if (!prUrl) continue;
7019
+ const next = { ...item, prUrl };
7020
+ const prev = map.get(prUrl);
7021
+ if (!prev) {
7022
+ map.set(prUrl, next);
7023
+ continue;
7024
+ }
7025
+ if (!prev.threadId && next.threadId) {
7026
+ map.set(prUrl, {
7027
+ ...prev,
7028
+ ...next,
7029
+ prUrl,
7030
+ title: next.title.trim() || prev.title
7031
+ });
7032
+ }
7033
+ }
7034
+ return [...map.values()];
7035
+ }
7036
+ function diffGithubEdges(input) {
7037
+ if (!input.prev.primed) return [];
7038
+ const cooldown = input.cooldownMs ?? GITHUB_EDGE_COOLDOWN_MS;
7039
+ const edges = [];
7040
+ const consider = (kind, items, latched) => {
7041
+ for (const item of dedupeSubjects(items)) {
7042
+ if (latched.has(item.prUrl)) continue;
7043
+ const firedAt = input.prev.lastFiredAt[githubEdgeKey(kind, item.prUrl)] ?? 0;
7044
+ if (firedAt && input.now - firedAt < cooldown) continue;
7045
+ edges.push({ ...item, kind });
7046
+ }
7047
+ };
7048
+ consider("ci-failed", input.ciFailed, new Set(input.prev.ciFailed.map((url) => normalizePrUrl(url))));
7049
+ consider(
7050
+ "review-requested",
7051
+ input.reviewRequested,
7052
+ new Set(input.prev.reviewRequested.map((row) => normalizePrUrl(row.prUrl)))
7053
+ );
7054
+ return edges;
7055
+ }
7056
+ function commitGithubEdgeSnapshot(input) {
7057
+ const deliveredCi = new Set(
7058
+ input.delivered.filter((edge) => edge.kind === "ci-failed").map((edge) => normalizePrUrl(edge.prUrl)).filter(Boolean)
7059
+ );
7060
+ const deliveredReview = new Set(
7061
+ input.delivered.filter((edge) => edge.kind === "review-requested").map((edge) => normalizePrUrl(edge.prUrl)).filter(Boolean)
7062
+ );
7063
+ const ciObserved = dedupeSubjects(input.ciFailed).map((item) => item.prUrl);
7064
+ const ciFailed = nextUrls(input.prev.primed, input.prev.ciFailed, ciObserved, deliveredCi);
7065
+ const reviewRequested = nextReviewLatch(
7066
+ input.prev.primed,
7067
+ input.reviewRequested,
7068
+ input.prev.reviewRequested,
7069
+ deliveredReview
7070
+ );
7071
+ const lastFiredAt = {};
7072
+ for (const [key, at] of Object.entries(input.prev.lastFiredAt)) {
7073
+ if (input.now - at <= LAST_FIRED_KEEP_MS) lastFiredAt[key] = at;
7074
+ }
7075
+ for (const edge of input.delivered) {
7076
+ const prUrl = normalizePrUrl(edge.prUrl);
7077
+ if (!prUrl) continue;
7078
+ lastFiredAt[githubEdgeKey(edge.kind, prUrl)] = input.now;
7079
+ }
7080
+ return { primed: true, ciFailed, reviewRequested, lastFiredAt };
7081
+ }
7082
+ function nextUrls(primed, prev, observed, delivered) {
7083
+ const prevSet = new Set(prev.map((url) => normalizePrUrl(url)).filter(Boolean));
7084
+ const out = [];
7085
+ const seen = /* @__PURE__ */ new Set();
7086
+ for (const url of observed) {
7087
+ if (!url || seen.has(url)) continue;
7088
+ seen.add(url);
7089
+ if (!primed || prevSet.has(url) || delivered.has(url)) out.push(url);
7090
+ }
7091
+ return out;
7092
+ }
7093
+ function nextReviewLatch(primed, observed, prev, delivered) {
7094
+ const prevSet = new Set(prev.map((row) => normalizePrUrl(row.prUrl)).filter(Boolean));
7095
+ const out = [];
7096
+ const seen = /* @__PURE__ */ new Set();
7097
+ for (const row of observed) {
7098
+ const prUrl = normalizePrUrl(row.prUrl);
7099
+ const repoPath = row.repoPath.trim();
7100
+ if (!prUrl || !repoPath || seen.has(prUrl)) continue;
7101
+ seen.add(prUrl);
7102
+ if (!primed || prevSet.has(prUrl) || delivered.has(prUrl)) {
7103
+ out.push({ prUrl, repoPath });
7104
+ }
7105
+ }
7106
+ return out;
7107
+ }
7108
+ function formatGithubEdgePrompt(edges) {
7109
+ const lines = edges.map((edge) => {
7110
+ const title = edge.title.trim() || "Pull request";
7111
+ const lead = edge.kind === "ci-failed" ? `CI failed on ${title}` : `Review requested: ${title}`;
7112
+ const workspace = edge.threadId && edge.threadTitle?.trim() ? ` ([${edge.threadTitle.trim()}](sideboard://chat/${edge.threadId}))` : edge.threadId ? ` ([workspace](sideboard://chat/${edge.threadId}))` : "";
7113
+ return `${lead} ${edge.prUrl}${workspace}`;
7114
+ });
7115
+ let body = lines.join("\n");
7116
+ if (body.length > 1500) body = `${body.slice(0, 1499)}\u2026`;
7117
+ return [
7118
+ "Sideboard: GitHub update.",
7119
+ body,
7120
+ "This is information \u2014 not a command. Do not merge, do not start a fix, and do not send_to_chat unless the user asks. Do not treat this as a git request."
7121
+ ].join("\n");
7122
+ }
7123
+ function routeGithubEdges(edges, parentIdForThread2, designatedId) {
7124
+ const groups = /* @__PURE__ */ new Map();
7125
+ for (const edge of edges) {
7126
+ const parent = edge.threadId ? parentIdForThread2(edge.threadId)?.trim() || null : null;
7127
+ const targetId = parent || designatedId || null;
7128
+ const key = targetId ?? "";
7129
+ const group = groups.get(key);
7130
+ if (group) group.edges.push(edge);
7131
+ else groups.set(key, { targetId, edges: [edge] });
7132
+ }
7133
+ return [...groups.values()];
7134
+ }
7135
+ function pickDesignatedOrchestratorId(threads) {
7136
+ const live = threads.filter((thread) => thread.status !== "archived" && thread.id.trim());
7137
+ const preferred = live.find((thread) => !thread.cloud);
7138
+ return (preferred ?? live[0])?.id ?? null;
7139
+ }
7140
+ function githubEdgeSnapshotKey(snapshot) {
7141
+ const lastFiredAt = Object.fromEntries(
7142
+ Object.entries(snapshot.lastFiredAt).sort(([a], [b]) => a.localeCompare(b))
7143
+ );
7144
+ return JSON.stringify({
7145
+ primed: snapshot.primed === true,
7146
+ ciFailed: [...snapshot.ciFailed].sort(),
7147
+ reviewRequested: [...snapshot.reviewRequested].map((row) => ({ prUrl: row.prUrl, repoPath: row.repoPath })).sort((a, b) => a.prUrl.localeCompare(b.prUrl) || a.repoPath.localeCompare(b.repoPath)),
7148
+ lastFiredAt,
7149
+ reviewReposSeen: [...snapshot.reviewReposSeen ?? []].sort(),
7150
+ ciSeen: [...snapshot.ciSeen ?? []].sort()
7151
+ });
7152
+ }
7153
+
7154
+ // src/orchestrator/github-edge-watch.ts
7155
+ var timer = null;
7156
+ var polling = false;
7157
+ var needsBaseline = true;
7158
+ function githubEdgeSnapshotPath() {
7159
+ return join14(appDataDir(), "github-edge-watch.json");
7160
+ }
7161
+ function loadGithubEdgeSnapshot() {
7162
+ try {
7163
+ const path = githubEdgeSnapshotPath();
7164
+ if (!existsSync13(path)) return emptyGithubEdgeSnapshot();
7165
+ return coerceGithubEdgeSnapshot(JSON.parse(readFileSync8(path, "utf8")));
7166
+ } catch {
7167
+ return emptyGithubEdgeSnapshot();
7168
+ }
7169
+ }
7170
+ function saveGithubEdgeSnapshot(snapshot) {
7171
+ writePrivateFile(githubEdgeSnapshotPath(), `${JSON.stringify(snapshot, null, 2)}
7172
+ `);
7173
+ }
7174
+ function stopGithubEdgeWatch() {
7175
+ if (timer) clearInterval(timer);
7176
+ timer = null;
7177
+ }
7178
+ function armGithubEdgeWatch() {
7179
+ if (!isThisProcessDesktopHost()) return;
7180
+ if (!wakeOrchestratorOnGithubEdgesEnabled()) {
7181
+ stopGithubEdgeWatch();
7182
+ needsBaseline = true;
7183
+ return;
7184
+ }
7185
+ if (timer) return;
7186
+ const tick = () => {
7187
+ if (polling) return;
7188
+ polling = true;
7189
+ const baseline = needsBaseline;
7190
+ needsBaseline = false;
7191
+ void pollGithubEdges(realDeps(), { baseline }).catch(() => {
7192
+ if (baseline) needsBaseline = true;
7193
+ }).finally(() => {
7194
+ polling = false;
7195
+ });
7196
+ };
7197
+ timer = setInterval(tick, GITHUB_EDGE_POLL_MS);
7198
+ timer.unref?.();
7199
+ tick();
7200
+ }
7201
+ async function pollGithubEdges(deps = realDeps(), opts) {
7202
+ if (!deps.enabled()) return { fired: 0, primed: false, skipped: "disabled" };
7203
+ const loaded = deps.load();
7204
+ const prev = opts?.baseline ? { ...loaded, primed: false } : loaded;
7205
+ const now = deps.now();
7206
+ const cards = indexCiCards(deps.listCiCards(), (threadId) => deps.parentIdForThread(threadId));
7207
+ const failing = [];
7208
+ const unknown = [];
7209
+ const observed = [];
7210
+ const failingSubjects = /* @__PURE__ */ new Map();
7211
+ for (const card of cards.values()) {
7212
+ const prUrl = normalizePrUrl(card.prUrl);
7213
+ let failed;
7214
+ try {
7215
+ failed = await deps.fetchCiFailed(card);
7216
+ } catch {
7217
+ failed = null;
7218
+ }
7219
+ if (failed == null) {
7220
+ unknown.push(prUrl);
7221
+ continue;
7222
+ }
7223
+ observed.push(prUrl);
7224
+ if (!failed) continue;
7225
+ failing.push(prUrl);
7226
+ failingSubjects.set(prUrl, subjectFromCard(card, prUrl));
7227
+ }
7228
+ const ciUrls = mergeCiLatch(
7229
+ prev.ciFailed,
7230
+ prev.primed ? failing : [...failing, ...unknown],
7231
+ unknown
7232
+ );
7233
+ const ciFailed = ciUrls.map(
7234
+ (prUrl) => failingSubjects.get(prUrl) ?? { prUrl, title: prUrl }
7235
+ );
7236
+ const repos = [...new Set(deps.listRepoPaths().map((path) => path.trim()).filter(Boolean))].sort();
7237
+ const fetchedReviews = [];
7238
+ const reviewSubjects = /* @__PURE__ */ new Map();
7239
+ const successfulRepos = [];
7240
+ for (const repoPath of repos) {
7241
+ let rows;
7242
+ try {
7243
+ rows = await deps.listReviewRequested(repoPath);
7244
+ } catch {
7245
+ rows = null;
7246
+ }
7247
+ if (!rows) continue;
7248
+ successfulRepos.push(repoPath);
7249
+ for (const row of rows) {
7250
+ if (!acceptOpenReadyPr(row)) continue;
7251
+ const prUrl = normalizePrUrl(row.prUrl);
7252
+ if (!prUrl) continue;
7253
+ const card = cards.get(prUrl);
7254
+ fetchedReviews.push({ prUrl, repoPath });
7255
+ reviewSubjects.set(prUrl, {
7256
+ prUrl,
7257
+ title: row.title.trim() || card?.prTitle || prUrl,
7258
+ threadId: card?.threadId,
7259
+ threadTitle: card?.threadTitle,
7260
+ repoPath
7261
+ });
7262
+ }
7263
+ }
7264
+ const seenRepos = new Set(prev.reviewReposSeen ?? []);
7265
+ const freshRepos = new Set(
7266
+ prev.primed ? successfulRepos.filter((repo) => !seenRepos.has(repo)) : []
7267
+ );
7268
+ const reviewLatch = repos.length ? mergeReviewLatch(prev.reviewRequested, fetchedReviews, successfulRepos) : prev.reviewRequested;
7269
+ const reviewRequested = reviewLatch.filter((row) => !freshRepos.has(row.repoPath)).map(
7270
+ (row) => reviewSubjects.get(row.prUrl) ?? {
7271
+ prUrl: row.prUrl,
7272
+ title: row.prUrl,
7273
+ repoPath: row.repoPath
7274
+ }
7275
+ );
7276
+ const baseline = reviewLatch.filter((row) => freshRepos.has(row.repoPath));
7277
+ const seenCi = new Set((prev.ciSeen ?? []).map((url) => normalizePrUrl(url)).filter(Boolean));
7278
+ const freshCi = new Set(prev.primed ? observed.filter((url) => !seenCi.has(url)) : []);
7279
+ const ciForDiff = ciFailed.filter((subject) => !freshCi.has(subject.prUrl));
7280
+ const edges = diffGithubEdges({ prev, ciFailed: ciForDiff, reviewRequested, now });
7281
+ const delivered = prev.primed && edges.length ? await deliverGithubEdges(edges, deps) : [];
7282
+ const freshFailing = [...freshCi].filter((url) => failing.includes(url));
7283
+ const prevForCommit = freshFailing.length || baseline.length ? {
7284
+ ...prev,
7285
+ ...freshFailing.length ? {
7286
+ ciFailed: [
7287
+ .../* @__PURE__ */ new Set([
7288
+ ...prev.ciFailed.map((url) => normalizePrUrl(url)).filter(Boolean),
7289
+ ...freshFailing
7290
+ ])
7291
+ ]
7292
+ } : {},
7293
+ ...baseline.length ? { reviewRequested: mergeReviewLatch(prev.reviewRequested, baseline, [...freshRepos]) } : {}
7294
+ } : prev;
7295
+ const committed = commitGithubEdgeSnapshot({
7296
+ prev: prevForCommit,
7297
+ ciFailed,
7298
+ reviewRequested: reviewLatch,
7299
+ delivered,
7300
+ now
7301
+ });
7302
+ const watched = new Set(repos);
7303
+ const reviewReposSeen = [
7304
+ .../* @__PURE__ */ new Set([
7305
+ ...(prev.reviewReposSeen ?? []).filter((repo) => watched.has(repo)),
7306
+ ...successfulRepos
7307
+ ])
7308
+ ].sort();
7309
+ const cardUrls = new Set(cards.keys());
7310
+ const ciSeen = [
7311
+ .../* @__PURE__ */ new Set([
7312
+ ...(prev.ciSeen ?? []).map((url) => normalizePrUrl(url)).filter((url) => url && cardUrls.has(url)),
7313
+ ...observed
7314
+ ])
7315
+ ].sort();
7316
+ const next = {
7317
+ ...committed,
7318
+ ...reviewReposSeen.length ? { reviewReposSeen } : {},
7319
+ ...ciSeen.length ? { ciSeen } : {}
7320
+ };
7321
+ if (githubEdgeSnapshotKey(prev) !== githubEdgeSnapshotKey(next)) deps.save(next);
7322
+ return { fired: delivered.length, primed: next.primed };
7323
+ }
7324
+ async function deliverGithubEdges(edges, deps) {
7325
+ const delivered = [];
7326
+ for (const group of routeGithubEdges(edges, (threadId) => deps.parentIdForThread(threadId), deps.designatedId())) {
7327
+ const prompt = formatGithubEdgePrompt(group.edges);
7328
+ try {
7329
+ if (group.targetId) await deps.send(group.targetId, prompt);
7330
+ else await deps.startOrchestration(prompt);
7331
+ delivered.push(...group.edges);
7332
+ } catch {
7333
+ }
7334
+ }
7335
+ return delivered;
7336
+ }
7337
+ function indexCiCards(cards, parentIdForThread2) {
7338
+ const byUrl = /* @__PURE__ */ new Map();
7339
+ for (const card of cards) {
7340
+ if (!acceptOpenReadyPr(card)) continue;
7341
+ const prUrl = normalizePrUrl(card.prUrl);
7342
+ if (!prUrl) continue;
7343
+ const existing = byUrl.get(prUrl);
7344
+ if (!existing) {
7345
+ byUrl.set(prUrl, card);
7346
+ continue;
7347
+ }
7348
+ const existingParent = parentIdForThread2(existing.threadId);
7349
+ const nextParent = parentIdForThread2(card.threadId);
7350
+ if (!existingParent && nextParent) byUrl.set(prUrl, card);
7351
+ }
7352
+ return byUrl;
7353
+ }
7354
+ function subjectFromCard(card, prUrl) {
7355
+ return {
7356
+ prUrl,
7357
+ title: card.prTitle.trim() || card.threadTitle.trim() || prUrl,
7358
+ threadId: card.threadId,
7359
+ threadTitle: card.threadTitle,
7360
+ repoPath: card.repoPath,
7361
+ draft: card.draft,
7362
+ state: card.state
7363
+ };
7364
+ }
7365
+ function liveWorktreeThreads() {
7366
+ return listThreads().filter(
7367
+ (thread) => !isGlobalThread(thread) && !isOrchestratorThread(thread) && thread.wakeOnGithubEdges === true && Boolean(thread.worktreePath?.trim()) && Boolean(thread.repoPath?.trim())
7368
+ );
7369
+ }
7370
+ function listCiCardsFromStore() {
7371
+ const cards = [];
7372
+ for (const thread of liveWorktreeThreads()) {
7373
+ const prUrl = thread.prUrl?.trim() ?? "";
7374
+ if (!prUrl) continue;
7375
+ cards.push({
7376
+ threadId: thread.id,
7377
+ threadTitle: thread.title?.trim() || "Workspace",
7378
+ worktreePath: thread.worktreePath,
7379
+ repoPath: thread.repoPath,
7380
+ prUrl,
7381
+ prTitle: thread.prTitle?.trim() || thread.title?.trim() || prUrl,
7382
+ draft: thread.prIsDraft,
7383
+ state: thread.prState
7384
+ });
7385
+ }
7386
+ return cards;
7387
+ }
7388
+ function listLiveRepoPaths() {
7389
+ return [...new Set(liveWorktreeThreads().map((thread) => thread.repoPath.trim()).filter(Boolean))];
7390
+ }
7391
+ async function fetchCiFailedFromGh(card) {
7392
+ try {
7393
+ const checks = await getPrCiChecks(card.worktreePath, card.prUrl);
7394
+ if (!checks) return null;
7395
+ const failed = ciChecksFailed(checks);
7396
+ persistChecksFailed(card, failed);
7397
+ return failed;
7398
+ } catch {
7399
+ return null;
7400
+ }
7401
+ }
7402
+ function persistChecksFailed(card, failed) {
7403
+ const siblings = threadsSharingWorktree(card.worktreePath);
7404
+ const self = readThread(card.threadId);
7405
+ const targets = siblings.length > 0 ? siblings : self ? [self] : [];
7406
+ for (const thread of targets) {
7407
+ const patch = threadPrChecksFailedPatch(thread, failed);
7408
+ if (Object.keys(patch).length === 0) continue;
7409
+ try {
7410
+ updateThread(thread.id, patch);
7411
+ } catch {
7412
+ }
7413
+ }
7414
+ }
7415
+ async function listMineFromGh(repoPath) {
7416
+ try {
7417
+ const reviewLabel = resolveProjectReviewLabel(loadAppSettings(), repoPath);
7418
+ const rows = await listPrs(repoPath, {
7419
+ queue: "mine",
7420
+ limit: 30,
7421
+ strict: true,
7422
+ ...reviewLabel ? { reviewLabel } : {}
7423
+ });
7424
+ return rows.map((row) => ({
7425
+ prUrl: row.url,
7426
+ title: row.title,
7427
+ draft: row.isDraft,
7428
+ state: row.state
7429
+ }));
7430
+ } catch {
7431
+ return null;
7432
+ }
7433
+ }
7434
+ function parentIdForThread(threadId) {
7435
+ const thread = readThread(threadId);
7436
+ if (!thread || thread.status === "archived") return null;
7437
+ const parent = connectedOrchestrator(thread, (id) => readThread(id));
7438
+ if (!parent || parent.status === "archived") return null;
7439
+ return parent.id;
7440
+ }
7441
+ function designatedOrchestratorId() {
7442
+ return pickDesignatedOrchestratorId(
7443
+ listGlobalThreads().map((thread) => ({
7444
+ id: thread.id,
7445
+ status: thread.status,
7446
+ cloud: isCloudCoordinatorThread(thread)
7447
+ }))
7448
+ );
7449
+ }
7450
+ function realDeps() {
7451
+ return {
7452
+ enabled: () => wakeOrchestratorOnGithubEdgesEnabled(),
7453
+ listCiCards: listCiCardsFromStore,
7454
+ fetchCiFailed: fetchCiFailedFromGh,
7455
+ listRepoPaths: listLiveRepoPaths,
7456
+ listReviewRequested: listMineFromGh,
7457
+ parentIdForThread,
7458
+ designatedId: designatedOrchestratorId,
7459
+ send: async (threadId, prompt) => {
7460
+ const { getOrchestrator: getOrchestrator2 } = await import("./orchestrator-BKCQUMLB.js");
7461
+ await getOrchestrator2().send(threadId, prompt, { followUp: "queue" });
7462
+ },
7463
+ startOrchestration: async (prompt) => {
7464
+ const { startOrchestration: startOrchestration2 } = await import("./orchestrator-BKCQUMLB.js");
7465
+ const defaults = resolveOrchestratorDefaults();
7466
+ await startOrchestration2({
7467
+ goal: prompt,
7468
+ agent: defaults.agent,
7469
+ model: defaults.model,
7470
+ effort: defaults.effort,
7471
+ fast: defaults.fast,
7472
+ autonomy: defaults.autonomy
7473
+ });
7474
+ },
7475
+ load: loadGithubEdgeSnapshot,
7476
+ save: saveGithubEdgeSnapshot,
7477
+ now: () => Date.now()
7478
+ };
7479
+ }
7480
+
6878
7481
  // src/orchestrator/schedule-runner.ts
6879
7482
  var SET_TIMEOUT_MAX = 2147483647;
6880
7483
  var fireHooks = null;
@@ -6885,7 +7488,7 @@ function formatScheduledPrompt(name, prompt) {
6885
7488
  ${prompt}`;
6886
7489
  }
6887
7490
  async function defaultDeps() {
6888
- const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-JTFCNXVR.js");
7491
+ const { getOrchestrator: getOrchestrator2, startOrchestration: startOrchestration2 } = await import("./orchestrator-BKCQUMLB.js");
6889
7492
  const orch = getOrchestrator2();
6890
7493
  return {
6891
7494
  findThread: (id) => findThreadByRef(id),
@@ -6985,8 +7588,8 @@ async function fireSchedule(id) {
6985
7588
  }
6986
7589
  }
6987
7590
  function clearTimer(id) {
6988
- const timer = timers.get(id);
6989
- if (timer) clearTimeout(timer);
7591
+ const timer2 = timers.get(id);
7592
+ if (timer2) clearTimeout(timer2);
6990
7593
  timers.delete(id);
6991
7594
  }
6992
7595
  function armOne(schedule) {
@@ -7002,7 +7605,7 @@ function armOne(schedule) {
7002
7605
  return;
7003
7606
  }
7004
7607
  const capped = Math.min(delay, SET_TIMEOUT_MAX);
7005
- const timer = setTimeout(() => {
7608
+ const timer2 = setTimeout(() => {
7006
7609
  timers.delete(schedule.id);
7007
7610
  const live = getSchedule(schedule.id);
7008
7611
  if (!live?.enabled) return;
@@ -7015,7 +7618,7 @@ function armOne(schedule) {
7015
7618
  if (isThisProcessDesktopHost()) armSchedules();
7016
7619
  });
7017
7620
  }, capped);
7018
- timers.set(schedule.id, timer);
7621
+ timers.set(schedule.id, timer2);
7019
7622
  }
7020
7623
  function armSchedules() {
7021
7624
  if (!isThisProcessDesktopHost()) return;
@@ -7174,7 +7777,7 @@ var Orchestrator = class {
7174
7777
  this.lightReconcileAt.set(repoPath, Date.now());
7175
7778
  for (const thread of listThreads()) {
7176
7779
  if (isGlobalThread(thread) || thread.repoPath !== repoPath) continue;
7177
- if (!existsSync13(thread.worktreePath)) {
7780
+ if (!existsSync14(thread.worktreePath)) {
7178
7781
  setStatus(thread.id, "broken", "Worktree missing on disk");
7179
7782
  this.emit({ type: "status_changed", threadId: thread.id, status: "broken" });
7180
7783
  }
@@ -7203,7 +7806,7 @@ var Orchestrator = class {
7203
7806
  }
7204
7807
  continue;
7205
7808
  }
7206
- if (!existsSync13(thread.worktreePath)) {
7809
+ if (!existsSync14(thread.worktreePath)) {
7207
7810
  setStatus(thread.id, "broken", "Worktree missing on disk");
7208
7811
  this.emit({ type: "status_changed", threadId: thread.id, status: "broken" });
7209
7812
  continue;
@@ -7229,6 +7832,7 @@ var Orchestrator = class {
7229
7832
  }
7230
7833
  this.schedulePendingQuotaResumes();
7231
7834
  armSchedules();
7835
+ armGithubEdgeWatch();
7232
7836
  }
7233
7837
  /** Surface (and, when enabled, clean up) worktrees git knows about but no thread owns. */
7234
7838
  async reconcileOrphans(repoPaths) {
@@ -7240,7 +7844,7 @@ var Orchestrator = class {
7240
7844
  orphans: orphans.map((o) => ({ path: o.path, repoPath: o.repoPath }))
7241
7845
  });
7242
7846
  }
7243
- const { autoCleanupOrphansEnabled } = await import("./app-settings-YS5AUJTF.js");
7847
+ const { autoCleanupOrphansEnabled } = await import("./app-settings-YTOPIRDH.js");
7244
7848
  if (autoCleanupOrphansEnabled() && shouldRunWorktreeCleanup() && orphans.length > 0) {
7245
7849
  await cleanupOrphanWorktrees({ repoPaths });
7246
7850
  }
@@ -7367,8 +7971,8 @@ var Orchestrator = class {
7367
7971
  }
7368
7972
  }
7369
7973
  clearQuotaResumeTimer(threadId) {
7370
- const timer = this.quotaResumeTimers.get(threadId);
7371
- if (timer) clearTimeout(timer);
7974
+ const timer2 = this.quotaResumeTimers.get(threadId);
7975
+ if (timer2) clearTimeout(timer2);
7372
7976
  this.quotaResumeTimers.delete(threadId);
7373
7977
  }
7374
7978
  /** Schedule (or fire) auto-retry after a provider session/usage limit reset. */
@@ -7377,11 +7981,11 @@ var Orchestrator = class {
7377
7981
  updateThread(threadId, { quotaResumeAt: resumeAt.toISOString() });
7378
7982
  const delay = Math.max(5e3, resumeAt.getTime() - Date.now());
7379
7983
  const capped = Math.min(delay, 2147483647);
7380
- const timer = setTimeout(() => {
7984
+ const timer2 = setTimeout(() => {
7381
7985
  this.quotaResumeTimers.delete(threadId);
7382
7986
  void this.resumeAfterQuotaWait(threadId);
7383
7987
  }, capped);
7384
- this.quotaResumeTimers.set(threadId, timer);
7988
+ this.quotaResumeTimers.set(threadId, timer2);
7385
7989
  }
7386
7990
  schedulePendingQuotaResumes() {
7387
7991
  for (const thread of listThreads({ includeArchived: false })) {
@@ -7630,7 +8234,7 @@ var Orchestrator = class {
7630
8234
  }
7631
8235
  await setup;
7632
8236
  if (skipSetup) return;
7633
- const { autoRunAfterSetupEnabled } = await import("./app-settings-YS5AUJTF.js");
8237
+ const { autoRunAfterSetupEnabled } = await import("./app-settings-YTOPIRDH.js");
7634
8238
  if (autoRunAfterSetupEnabled()) {
7635
8239
  try {
7636
8240
  await this.startDev(threadId);
@@ -8015,7 +8619,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
8015
8619
  }
8016
8620
  const isBrightsy = fresh.agent === "brightsy";
8017
8621
  const isOrchestration = isOrchestratorThread(fresh);
8018
- const { autoRenameBranchEnabled, getGithubGitAuthMode, gitBranchPrefixSetting } = await import("./app-settings-YS5AUJTF.js");
8622
+ const { autoRenameBranchEnabled, getGithubGitAuthMode, gitBranchPrefixSetting } = await import("./app-settings-YTOPIRDH.js");
8019
8623
  const gitAuthMode = getGithubGitAuthMode();
8020
8624
  const worktreeDirective = isBrightsy || isOrchestration ? null : formatWorktreeDirective(fresh, {
8021
8625
  githubSlug: turnOrigin?.forge === "github" ? turnOrigin.slug : await withTimeout(resolveGithubRepoSlug(fresh.worktreePath), 8e3, "resolveGithubRepoSlug").catch(() => null),
@@ -9029,11 +9633,11 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9029
9633
  const start = Date.now();
9030
9634
  return new Promise((resolve, reject) => {
9031
9635
  let settled = false;
9032
- let timer;
9636
+ let timer2;
9033
9637
  const finish = (fn) => {
9034
9638
  if (settled) return;
9035
9639
  settled = true;
9036
- if (timer) clearInterval(timer);
9640
+ if (timer2) clearInterval(timer2);
9037
9641
  off();
9038
9642
  fn();
9039
9643
  };
@@ -9059,7 +9663,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9059
9663
  }
9060
9664
  }
9061
9665
  });
9062
- timer = setInterval(() => {
9666
+ timer2 = setInterval(() => {
9063
9667
  const raw = readThread(thread.id);
9064
9668
  if (!raw) {
9065
9669
  finish(() => reject(new Error(`Thread not found: ${thread.id}`)));
@@ -9358,7 +9962,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9358
9962
  if (Object.keys(patch).length === 0) continue;
9359
9963
  updateThread(t.id, patch);
9360
9964
  }
9361
- const { autoArchiveOnMergeEnabled } = await import("./app-settings-YS5AUJTF.js");
9965
+ const { autoArchiveOnMergeEnabled } = await import("./app-settings-YTOPIRDH.js");
9362
9966
  const latest = this.requireThread(thread.id);
9363
9967
  if (!shouldAutoArchiveOnPrMerge({
9364
9968
  previousPrState: prevState || null,
@@ -9682,7 +10286,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9682
10286
  await runArchiveScript(thread.repoPath, thread.worktreePath);
9683
10287
  } catch {
9684
10288
  }
9685
- const { deleteBranchOnPurgeEnabled } = await import("./app-settings-YS5AUJTF.js");
10289
+ const { deleteBranchOnPurgeEnabled } = await import("./app-settings-YTOPIRDH.js");
9686
10290
  const deleteBranch = opts?.deleteBranch ?? deleteBranchOnPurgeEnabled();
9687
10291
  await removeWorktree(thread.repoPath, thread.worktreePath, {
9688
10292
  deleteBranch: deleteBranch ? thread.branchName : void 0
@@ -9704,7 +10308,7 @@ ${formatEnvReminder(projectNameForRepoPath(thread.repoPath || thread.worktreePat
9704
10308
  this.emit({ type: "status_changed", threadId: restored2.id, status: restored2.status });
9705
10309
  return restored2;
9706
10310
  }
9707
- if (!existsSync13(thread.worktreePath)) {
10311
+ if (!existsSync14(thread.worktreePath)) {
9708
10312
  if (isCowboyThread(thread) || isPrimaryCheckoutThread(thread)) {
9709
10313
  throw new Error(
9710
10314
  `Cowboy checkout missing: ${thread.worktreePath}. Re-add the project folder, then restore.`
@@ -9820,7 +10424,7 @@ async function startOrchestration(opts) {
9820
10424
  sourceRef: "default",
9821
10425
  ...createOpts
9822
10426
  }).catch(async () => {
9823
- const { resolveDefaultBranch: resolveDefaultBranch2, resolveRepoRoot: resolveRepoRoot2 } = await import("./worktree-S4YOAYRA.js");
10427
+ const { resolveDefaultBranch: resolveDefaultBranch2, resolveRepoRoot: resolveRepoRoot2 } = await import("./worktree-BRKMPZMJ.js");
9824
10428
  const repo = await resolveRepoRoot2(repoPath);
9825
10429
  const def = await resolveDefaultBranch2(repo);
9826
10430
  return orch.createThread({
@@ -9830,7 +10434,7 @@ async function startOrchestration(opts) {
9830
10434
  repoPath: repo
9831
10435
  });
9832
10436
  });
9833
- const { updateThread: upd } = await import("./thread-store-DCO5MZWJ.js");
10437
+ const { updateThread: upd } = await import("./thread-store-OARQT6DL.js");
9834
10438
  const updated = upd(thread.id, {
9835
10439
  sourceType: "orchestration",
9836
10440
  sourceRef: goal