@sideboard-ai/core 0.1.51 → 0.1.52

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 (37) hide show
  1. package/dist/{agents-HIEJL3UV.js → agents-ON6RKKND.js} +1 -1
  2. package/dist/{agents-5ROTZNCX.js → agents-YKSS6VBO.js} +1 -1
  3. package/dist/{chunk-7EUWSBWR.js → chunk-6QTZVJ7A.js} +5 -3
  4. package/dist/chunk-B3SJXYIJ.js +24 -0
  5. package/dist/{chunk-5ZPSH7VI.js → chunk-D3METLRW.js} +5 -3
  6. package/dist/{chunk-ZH5QZ4CR.js → chunk-DZFH2KLT.js} +280 -7
  7. package/dist/chunk-FKOIHGKV.js +21 -0
  8. package/dist/{chunk-E4VVEKAM.js → chunk-GNML24AW.js} +2 -2
  9. package/dist/{chunk-EOYDCKQC.js → chunk-HLEX5AQ6.js} +4 -0
  10. package/dist/{chunk-K3WMKGFY.js → chunk-LRLKJM3O.js} +2 -1
  11. package/dist/chunk-N5PM7HGQ.js +103 -0
  12. package/dist/chunk-QTUESPAW.js +101 -0
  13. package/dist/{chunk-O6W3P7V3.js → chunk-TSRXOSVD.js} +4 -0
  14. package/dist/{chunk-F4Q3IM6V.js → chunk-UEAHMGHW.js} +2 -1
  15. package/dist/{chunk-XRSAGVRW.js → chunk-XOU6HNQJ.js} +245 -7
  16. package/dist/{chunk-O5DOO7DP.js → chunk-XX5BB7NV.js} +3 -3
  17. package/dist/{chunk-QN7XNQAT.js → chunk-YDXQ72MD.js} +2 -2
  18. package/dist/{chunk-YFJ4FG2P.js → chunk-YOWIYAVA.js} +3 -3
  19. package/dist/{coordinator-prompt-7HHJRO7B.js → coordinator-prompt-6FXVTSFN.js} +4 -3
  20. package/dist/{coordinator-prompt-WD7FAMA2.js → coordinator-prompt-S6JZD5EF.js} +4 -3
  21. package/dist/{global-workspace-OJEPGDXA.js → global-workspace-EV4G2WMQ.js} +5 -4
  22. package/dist/{global-workspace-ECYN2MKL.js → global-workspace-MSX2K27Y.js} +5 -4
  23. package/dist/index.cjs +1288 -140
  24. package/dist/index.d.cts +388 -15
  25. package/dist/index.d.ts +388 -15
  26. package/dist/index.js +801 -84
  27. package/dist/mcp/run-stdio.cjs +1059 -132
  28. package/dist/mcp/run-stdio.js +628 -73
  29. package/dist/plan-file-6O7G4VPQ.js +23 -0
  30. package/dist/plan-file-PHVKUAEE.js +25 -0
  31. package/dist/{thread-store-XICUWFNM.js → thread-store-GHOADGL2.js} +1 -1
  32. package/dist/{thread-store-OV2X6PYO.js → thread-store-UJIGMI5J.js} +1 -1
  33. package/dist/{workspaces-MUU7RGVV.js → workspaces-3RQQZQRO.js} +6 -5
  34. package/dist/{workspaces-ZWOOFZUV.js → workspaces-AYTBR6KQ.js} +6 -5
  35. package/dist/{worktree-DVNDMWZ7.js → worktree-5KEQWSAF.js} +5 -2
  36. package/dist/{worktree-GDV56MX4.js → worktree-RWGL7FUV.js} +5 -2
  37. package/package.json +1 -1
@@ -15,14 +15,19 @@ import {
15
15
  pushTurnStderr,
16
16
  resolveQuotaFallbackAgent,
17
17
  summarizeTurnStderr
18
- } from "../chunk-7EUWSBWR.js";
18
+ } from "../chunk-6QTZVJ7A.js";
19
19
  import "../chunk-H6GGDLYS.js";
20
20
  import {
21
21
  addWorkspace,
22
22
  ensureWorkspace,
23
23
  removeWorkspace,
24
24
  syncWorkspacesFromThreads
25
- } from "../chunk-QN7XNQAT.js";
25
+ } from "../chunk-YDXQ72MD.js";
26
+ import {
27
+ extractPresentedPlan,
28
+ readPlanFile,
29
+ writePlanFile
30
+ } from "../chunk-N5PM7HGQ.js";
26
31
  import {
27
32
  childEnvWithAppSettings,
28
33
  getLinearApiKey,
@@ -41,7 +46,7 @@ import {
41
46
  isGlobalThread,
42
47
  isOrchestratorThread,
43
48
  orchestratorSessionPoisonedByBuiltins
44
- } from "../chunk-YFJ4FG2P.js";
49
+ } from "../chunk-YOWIYAVA.js";
45
50
  import {
46
51
  assertOrchestratorCapableAgent
47
52
  } from "../chunk-S2LL5HA4.js";
@@ -50,19 +55,24 @@ import {
50
55
  coordinatorTurnReminder,
51
56
  enrichWorkspacesWithGithub,
52
57
  ensureGlobalCoordinatorCwd
53
- } from "../chunk-F4Q3IM6V.js";
58
+ } from "../chunk-UEAHMGHW.js";
54
59
  import {
60
+ addPrStackLayer,
55
61
  allocateTeamName,
56
62
  allocateTeamSlug,
57
63
  commitAll,
64
+ createExistingBranchWorktree,
58
65
  createOrUpdatePr,
59
66
  createThreadWorktree,
67
+ detectGhStack,
60
68
  fetchPrHead,
61
69
  formatGhLandError,
62
70
  getPr,
63
71
  getPrChecks,
64
72
  getPrDetails,
65
73
  getPrMeta,
74
+ getPrStack,
75
+ initPrStack,
66
76
  isDirty,
67
77
  isPlaceholderBranch,
68
78
  isSideboardScratchPath,
@@ -82,7 +92,12 @@ import {
82
92
  takenSlugsFromThread,
83
93
  threadDisplayLabel,
84
94
  worktreeNameFromPath
85
- } from "../chunk-XRSAGVRW.js";
95
+ } from "../chunk-XOU6HNQJ.js";
96
+ import {
97
+ ATTACHMENTS_DIR,
98
+ LEGACY_ATTACHMENTS_DIR,
99
+ attachmentsGitignoreBody
100
+ } from "../chunk-B3SJXYIJ.js";
86
101
  import {
87
102
  appendMessage,
88
103
  createEmptyThread,
@@ -94,7 +109,7 @@ import {
94
109
  updateThread,
95
110
  withThreadLock,
96
111
  writeThread
97
- } from "../chunk-EOYDCKQC.js";
112
+ } from "../chunk-HLEX5AQ6.js";
98
113
  import {
99
114
  ensureAgentPath,
100
115
  gh,
@@ -119,7 +134,7 @@ import { basename as basename4 } from "path";
119
134
 
120
135
  // src/orchestrator/orchestrator.ts
121
136
  import { EventEmitter } from "events";
122
- import { existsSync as existsSync12 } from "fs";
137
+ import { existsSync as existsSync13 } from "fs";
123
138
 
124
139
  // src/agents/spawn.ts
125
140
  import { createInterface } from "readline";
@@ -161,6 +176,9 @@ function toolDescription(name, input) {
161
176
  if (/present_artifact$/i.test(name)) {
162
177
  return str(input?.title) ? `Present ${str(input?.title)}` : "Present artifact";
163
178
  }
179
+ if (/present_plan$/i.test(name)) {
180
+ return str(input?.title) ? `Plan ${str(input?.title)}` : "Present plan";
181
+ }
164
182
  if (/present_schema$/i.test(name)) {
165
183
  return str(input?.title) ? `Schema ${str(input?.title)}` : "Present schema";
166
184
  }
@@ -357,9 +375,9 @@ async function spawnAgentTurn(thread, input, onEvent) {
357
375
  `Cannot spawn ${thread.agent}: thread ${thread.id} has no worktreePath`
358
376
  );
359
377
  }
360
- const { isGlobalThread: isGlobalThread2 } = await import("../global-workspace-OJEPGDXA.js");
378
+ const { isGlobalThread: isGlobalThread2 } = await import("../global-workspace-EV4G2WMQ.js");
361
379
  if (isGlobalThread2(thread)) {
362
- const { ensureGlobalCoordinatorCwd: ensureGlobalCoordinatorCwd2 } = await import("../coordinator-prompt-7HHJRO7B.js");
380
+ const { ensureGlobalCoordinatorCwd: ensureGlobalCoordinatorCwd2 } = await import("../coordinator-prompt-6FXVTSFN.js");
363
381
  ensureGlobalCoordinatorCwd2();
364
382
  }
365
383
  if (isOrchestratorThread(thread)) {
@@ -1083,7 +1101,7 @@ async function requireAgent(agent, opts) {
1083
1101
  }
1084
1102
 
1085
1103
  // src/threads/create.ts
1086
- async function createThread(input, onSetupLine) {
1104
+ async function createThread(input, _onSetupLine) {
1087
1105
  await requireAgent(input.agent);
1088
1106
  const repoPath = await resolveRepoRoot(input.repoPath);
1089
1107
  if (!existsSync5(repoPath)) {
@@ -1141,26 +1159,10 @@ async function createThread(input, onSetupLine) {
1141
1159
  });
1142
1160
  writeThread(thread);
1143
1161
  await ensureWorkspace(repoPath);
1144
- try {
1145
- let setup = await runSetupScript(repoPath, worktreePath, onSetupLine);
1146
- if (!setup.ran) {
1147
- setup = await runCursorWorktreeSetup(repoPath, worktreePath, onSetupLine);
1148
- }
1149
- if (setup.ran && setup.exitCode !== 0 && setup.exitCode !== null) {
1150
- updateThread(thread.id, {
1151
- lastError: `Setup exited ${setup.exitCode} (thread is still usable)`
1152
- });
1153
- }
1154
- } catch (err) {
1155
- const message = err instanceof Error ? err.message : String(err);
1156
- updateThread(thread.id, {
1157
- lastError: `Setup failed: ${message}`
1158
- });
1159
- }
1160
1162
  return readThread(thread.id) ?? thread;
1161
1163
  }
1162
1164
  async function listLinearIssues(agent, repoPath) {
1163
- const { getAdapter: getAdapter2 } = await import("../agents-HIEJL3UV.js");
1165
+ const { getAdapter: getAdapter2 } = await import("../agents-ON6RKKND.js");
1164
1166
  await requireAgent(agent, { requireLinear: true });
1165
1167
  const adapter = getAdapter2(agent);
1166
1168
  if (!adapter.listLinearIssues) {
@@ -1477,7 +1479,9 @@ function worktreeBindingFrom(from) {
1477
1479
  sourceIsFork: from.sourceIsFork,
1478
1480
  parentThreadId: from.parentThreadId,
1479
1481
  prUrl: from.prUrl,
1480
- prTitle: from.prTitle
1482
+ prTitle: from.prTitle,
1483
+ stackId: from.stackId,
1484
+ stackLayer: from.stackLayer
1481
1485
  };
1482
1486
  }
1483
1487
  function threadsSharingWorktree(worktreePath) {
@@ -1675,13 +1679,10 @@ File: src/client/frontends/desktop/core/UserData.ts
1675
1679
  // src/review/request-review.ts
1676
1680
  var REPO_REVIEW_PATH = ".sideboard/review.md";
1677
1681
  var REPO_REVIEW_NAME = "review.md";
1678
- var REVIEW_REQUEST_PATH = ".sideboard/attachments/Review request.md";
1682
+ var REVIEW_REQUEST_PATH = `${ATTACHMENTS_DIR}/Review request.md`;
1683
+ var LEGACY_REVIEW_REQUEST_PATH = `${LEGACY_ATTACHMENTS_DIR}/Review request.md`;
1679
1684
  var REVIEW_REQUEST_NAME = "Review request.md";
1680
1685
  var REVIEW_REQUEST_PREFILL = "Review.";
1681
- var ATTACHMENTS_GITIGNORE = `# Sideboard review / composer attachments (local only)
1682
- *
1683
- !.gitignore
1684
- `;
1685
1686
  var LEGACY_REVIEW_TEMPLATE_MARKERS = [
1686
1687
  "You are acting as a reviewer for a proposed code change made by another engineer.",
1687
1688
  "HOW MANY FINDINGS TO RETURN:"
@@ -1704,10 +1705,10 @@ function readTextIfPresent(abs) {
1704
1705
  }
1705
1706
  }
1706
1707
  function ensureAttachmentsGitignore(worktreePath) {
1707
- const gitignoreAbs = join5(worktreePath, ".sideboard", "attachments", ".gitignore");
1708
+ const gitignoreAbs = join5(worktreePath, ATTACHMENTS_DIR, ".gitignore");
1708
1709
  if (existsSync6(gitignoreAbs)) return;
1709
1710
  mkdirSync2(dirname2(gitignoreAbs), { recursive: true });
1710
- writeFileSync(gitignoreAbs, ATTACHMENTS_GITIGNORE, "utf8");
1711
+ writeFileSync(gitignoreAbs, attachmentsGitignoreBody(), "utf8");
1711
1712
  }
1712
1713
  function resolveReviewGuidelines(worktreePath) {
1713
1714
  const repoAbs = join5(worktreePath, REPO_REVIEW_PATH);
@@ -1730,6 +1731,16 @@ function resolveReviewGuidelines(worktreePath) {
1730
1731
  source: "local"
1731
1732
  };
1732
1733
  }
1734
+ const legacyAbs = join5(worktreePath, LEGACY_REVIEW_REQUEST_PATH);
1735
+ const legacyContent = readTextIfPresent(legacyAbs);
1736
+ if (legacyContent && !shouldRefreshReviewRequestTemplate(legacyContent)) {
1737
+ return {
1738
+ path: LEGACY_REVIEW_REQUEST_PATH,
1739
+ name: REVIEW_REQUEST_NAME,
1740
+ content: legacyContent,
1741
+ source: "local"
1742
+ };
1743
+ }
1733
1744
  ensureAttachmentsGitignore(worktreePath);
1734
1745
  mkdirSync2(dirname2(localAbs), { recursive: true });
1735
1746
  writeFileSync(localAbs, REVIEW_REQUEST_TEMPLATE, "utf8");
@@ -2013,7 +2024,7 @@ async function adoptThread(input) {
2013
2024
  messages: input.messages ?? []
2014
2025
  });
2015
2026
  writeThread(thread);
2016
- const { ensureWorkspace: ensureWorkspace2 } = await import("../workspaces-MUU7RGVV.js");
2027
+ const { ensureWorkspace: ensureWorkspace2 } = await import("../workspaces-3RQQZQRO.js");
2017
2028
  await ensureWorkspace2(repoPath);
2018
2029
  return thread;
2019
2030
  }
@@ -2208,11 +2219,295 @@ async function importConductorWorkspaceAsync(workspaceId) {
2208
2219
  return importConductorWorkspace(workspaceId);
2209
2220
  }
2210
2221
 
2222
+ // src/threads/stack-layers.ts
2223
+ import { existsSync as existsSync8 } from "fs";
2224
+ function stackIdFrom(stack) {
2225
+ if (stack.stackNumber != null) return `gh-stack-${stack.stackNumber}`;
2226
+ const key = stack.layers.map((l) => l.branchName).join("|");
2227
+ if (!key) return null;
2228
+ return `gh-stack-local-${hashShort(key)}`;
2229
+ }
2230
+ function hashShort(s) {
2231
+ let h = 0;
2232
+ for (let i = 0; i < s.length; i++) h = h * 31 + s.charCodeAt(i) | 0;
2233
+ return Math.abs(h).toString(36);
2234
+ }
2235
+ function requireThread3(idOrRef) {
2236
+ const thread = findThreadByRef(idOrRef) ?? readThread(idOrRef);
2237
+ if (!thread) throw new Error(`Thread not found: ${idOrRef}`);
2238
+ return thread;
2239
+ }
2240
+ function sanitizeSlugPart(name) {
2241
+ return name.trim().replace(/^refs\/heads\//, "").replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 48) || "layer";
2242
+ }
2243
+ function layerSlug(stackId, layer) {
2244
+ const stackPart = stackId.replace(/^gh-stack-/, "s");
2245
+ return sanitizeSlugPart(`${stackPart}-L${layer.position}-${layer.branchName}`);
2246
+ }
2247
+ function findThreadForStackLayer(repoPath, stackId, layer) {
2248
+ const threads = listThreads({ includeArchived: false }).filter(
2249
+ (t) => t.repoPath === repoPath && t.stackId === stackId
2250
+ );
2251
+ const byLayer = threads.find((t) => t.stackLayer === layer.position);
2252
+ if (byLayer) return byLayer;
2253
+ return threads.find((t) => t.branchName === layer.branchName) ?? listThreads({ includeArchived: false }).find(
2254
+ (t) => t.repoPath === repoPath && t.branchName === layer.branchName
2255
+ ) ?? null;
2256
+ }
2257
+ async function openStackLayer(input, _onSetupLine) {
2258
+ await requireAgent(input.agent);
2259
+ const repoPath = await resolveRepoRoot(input.repoPath);
2260
+ const stackId = stackIdFrom(input.stack);
2261
+ if (!stackId) throw new Error("Cannot open stack layer without a stack id");
2262
+ const existing = findThreadForStackLayer(repoPath, stackId, input.layer);
2263
+ if (existing) {
2264
+ const patch = {};
2265
+ if (existing.stackId !== stackId) patch.stackId = stackId;
2266
+ if (existing.stackLayer !== input.layer.position) {
2267
+ patch.stackLayer = input.layer.position;
2268
+ }
2269
+ if (input.layer.prUrl && existing.prUrl !== input.layer.prUrl) {
2270
+ patch.prUrl = input.layer.prUrl;
2271
+ }
2272
+ if (input.layer.title && existing.prTitle !== input.layer.title) {
2273
+ patch.prTitle = input.layer.title;
2274
+ }
2275
+ if (Object.keys(patch).length > 0) updateThread(existing.id, patch);
2276
+ return {
2277
+ thread: readThread(existing.id) ?? existing,
2278
+ createdWorktree: false
2279
+ };
2280
+ }
2281
+ let worktreePath = null;
2282
+ let branchName = input.layer.branchName;
2283
+ let createdWorktree = false;
2284
+ const trees = await listWorktrees(repoPath);
2285
+ const checkedOut = trees.find((w) => w.branch === branchName);
2286
+ if (checkedOut?.path && existsSync8(checkedOut.path)) {
2287
+ if (input.reuseExistingWorktree !== false) {
2288
+ worktreePath = checkedOut.path;
2289
+ } else {
2290
+ throw new Error(
2291
+ `Branch ${branchName} is already checked out at ${checkedOut.path}`
2292
+ );
2293
+ }
2294
+ }
2295
+ if (!worktreePath) {
2296
+ const slug = layerSlug(stackId, input.layer);
2297
+ const created = await createExistingBranchWorktree({
2298
+ repoPath,
2299
+ branchName,
2300
+ slug
2301
+ });
2302
+ worktreePath = created.worktreePath;
2303
+ branchName = created.branchName;
2304
+ copyConfiguredFiles(repoPath, worktreePath);
2305
+ createdWorktree = true;
2306
+ }
2307
+ const title = input.layer.title?.trim() || (input.layer.prNumber != null ? `PR #${input.layer.prNumber}` : input.layer.branchName);
2308
+ const thread = createEmptyThread({
2309
+ title,
2310
+ userSetTitle: Boolean(input.layer.title?.trim()),
2311
+ sourceType: input.layer.prNumber != null ? "pr" : "branch",
2312
+ sourceRef: input.layer.prNumber != null ? String(input.layer.prNumber) : input.layer.branchName,
2313
+ branchName,
2314
+ worktreePath,
2315
+ repoPath,
2316
+ agent: input.agent,
2317
+ autonomy: input.autonomy ?? "default",
2318
+ model: input.model ?? null,
2319
+ effort: input.effort ?? "high",
2320
+ fast: Boolean(input.fast),
2321
+ planMode: Boolean(input.planMode),
2322
+ parentThreadId: input.parentThreadId ?? null,
2323
+ status: "idle",
2324
+ prUrl: input.layer.prUrl,
2325
+ prTitle: input.layer.title ?? null,
2326
+ stackId,
2327
+ stackLayer: input.layer.position
2328
+ });
2329
+ writeThread(thread);
2330
+ await ensureWorkspace(repoPath);
2331
+ return { thread: readThread(thread.id) ?? thread, createdWorktree };
2332
+ }
2333
+ async function openPrStackLayers(input, onSetupLine) {
2334
+ const from = requireThread3(input.threadRef);
2335
+ if (!from.worktreePath?.trim() || !from.repoPath?.trim()) {
2336
+ throw new Error("Thread has no worktree");
2337
+ }
2338
+ const stack = await getPrStack(from.worktreePath);
2339
+ if (!stack) throw new Error("Current branch is not part of a GitHub PR stack");
2340
+ const layers = input.layer != null ? stack.layers.filter((l) => l.position === input.layer) : stack.layers;
2341
+ if (!layers.length) {
2342
+ throw new Error(
2343
+ input.layer != null ? `No stack layer at position ${input.layer}` : "Stack has no layers"
2344
+ );
2345
+ }
2346
+ const threads = [];
2347
+ const createdThreadIds = [];
2348
+ for (const layer of layers) {
2349
+ const { thread, createdWorktree } = await openStackLayer(
2350
+ {
2351
+ repoPath: from.repoPath,
2352
+ stack,
2353
+ layer,
2354
+ agent: from.agent,
2355
+ autonomy: from.autonomy,
2356
+ model: from.model,
2357
+ effort: from.effort,
2358
+ fast: from.fast,
2359
+ planMode: from.planMode,
2360
+ parentThreadId: from.id
2361
+ },
2362
+ onSetupLine
2363
+ );
2364
+ threads.push(thread);
2365
+ if (createdWorktree) createdThreadIds.push(thread.id);
2366
+ }
2367
+ const stackId = stackIdFrom(stack);
2368
+ const current = stack.layers[stack.currentIndex];
2369
+ if (stackId) {
2370
+ updateThread(from.id, {
2371
+ stackId,
2372
+ stackLayer: current?.position ?? from.stackLayer
2373
+ });
2374
+ }
2375
+ return { stack, threads, createdThreadIds };
2376
+ }
2377
+ async function addStackLayerFromThread(input, onSetupLine) {
2378
+ const from = requireThread3(input.threadRef);
2379
+ if (!from.worktreePath?.trim() || !from.repoPath?.trim()) {
2380
+ throw new Error("Thread has no worktree");
2381
+ }
2382
+ const status = await detectGhStack(from.worktreePath);
2383
+ if (!status.available) throw new Error(status.reason);
2384
+ await addPrStackLayer(from.worktreePath, input.branchName);
2385
+ const stack = await getPrStack(from.worktreePath);
2386
+ if (!stack) throw new Error("Stack not found after adding layer");
2387
+ const layer = stack.layers.find((l) => l.branchName === input.branchName.trim()) ?? stack.layers[stack.layers.length - 1];
2388
+ if (!layer) throw new Error("New stack layer not found");
2389
+ if (input.title?.trim()) {
2390
+ layer.title = input.title.trim();
2391
+ }
2392
+ const thread = await openStackLayer(
2393
+ {
2394
+ repoPath: from.repoPath,
2395
+ stack,
2396
+ layer,
2397
+ agent: from.agent,
2398
+ autonomy: from.autonomy,
2399
+ model: from.model,
2400
+ effort: from.effort,
2401
+ fast: from.fast,
2402
+ planMode: from.planMode,
2403
+ parentThreadId: from.id
2404
+ },
2405
+ onSetupLine
2406
+ );
2407
+ return { stack, thread: thread.thread, createdWorktree: thread.createdWorktree };
2408
+ }
2409
+ async function initStackFromThread(input, onSetupLine) {
2410
+ const from = requireThread3(input.threadRef);
2411
+ if (!from.worktreePath?.trim() || !from.branchName?.trim() || !from.repoPath?.trim()) {
2412
+ throw new Error("Thread has no worktree/branch");
2413
+ }
2414
+ const status = await detectGhStack(from.worktreePath);
2415
+ if (!status.available) throw new Error(status.reason);
2416
+ const branches = [
2417
+ from.branchName,
2418
+ ...(input.additionalBranches ?? []).map((b) => b.trim()).filter(Boolean)
2419
+ ];
2420
+ await initPrStack(from.worktreePath, branches, {
2421
+ base: input.base ?? await resolveDefaultBranch(from.repoPath)
2422
+ });
2423
+ return openPrStackLayers({ threadRef: from.id }, onSetupLine);
2424
+ }
2425
+ async function createPrStack(input, onSetupLine) {
2426
+ await requireAgent(input.agent);
2427
+ const repoPath = await resolveRepoRoot(input.repoPath);
2428
+ if (!existsSync8(repoPath)) throw new Error(`Repo not found: ${repoPath}`);
2429
+ if (!input.branches.length) throw new Error("At least one branch name required");
2430
+ const status = await detectGhStack(repoPath);
2431
+ if (!status.available) throw new Error(status.reason);
2432
+ const team = allocateTeamSlug(repoPath);
2433
+ const base = input.base ?? await resolveDefaultBranch(repoPath);
2434
+ const bootstrap = await createThreadWorktree({
2435
+ repoPath,
2436
+ sourceRef: base,
2437
+ slug: `${team.slug}-stack-init`
2438
+ });
2439
+ copyConfiguredFiles(repoPath, bootstrap.worktreePath);
2440
+ try {
2441
+ await initPrStack(bootstrap.worktreePath, input.branches, { base });
2442
+ const bottom = input.branches[0];
2443
+ const co = await git(["checkout", bottom], bootstrap.worktreePath, {
2444
+ reject: false
2445
+ });
2446
+ if (co.exitCode !== 0) {
2447
+ throw new Error(
2448
+ co.stderr.trim() || co.stdout.trim() || `Could not check out ${bottom} after stack init`
2449
+ );
2450
+ }
2451
+ } catch (err) {
2452
+ try {
2453
+ await removeWorktree(repoPath, bootstrap.worktreePath, {
2454
+ deleteBranch: bootstrap.branchName
2455
+ });
2456
+ } catch {
2457
+ }
2458
+ throw err;
2459
+ }
2460
+ const stack = await getPrStack(bootstrap.worktreePath);
2461
+ if (!stack) {
2462
+ try {
2463
+ await removeWorktree(repoPath, bootstrap.worktreePath, {
2464
+ deleteBranch: bootstrap.branchName
2465
+ });
2466
+ } catch {
2467
+ }
2468
+ throw new Error("Stack init succeeded but gh stack view returned no stack");
2469
+ }
2470
+ const threads = [];
2471
+ const createdThreadIds = [];
2472
+ for (const layer of stack.layers) {
2473
+ const title = layer.position === 1 && input.title?.trim() ? input.title.trim() : layer.title;
2474
+ const opened = await openStackLayer(
2475
+ {
2476
+ repoPath,
2477
+ stack,
2478
+ layer: title ? { ...layer, title } : layer,
2479
+ agent: input.agent,
2480
+ autonomy: input.autonomy,
2481
+ model: input.model,
2482
+ effort: input.effort,
2483
+ fast: input.fast,
2484
+ planMode: input.planMode,
2485
+ reuseExistingWorktree: true
2486
+ },
2487
+ onSetupLine
2488
+ );
2489
+ threads.push(opened.thread);
2490
+ if (opened.createdWorktree || opened.thread.worktreePath === bootstrap.worktreePath) {
2491
+ createdThreadIds.push(opened.thread.id);
2492
+ }
2493
+ }
2494
+ const claimed = new Set(threads.map((t) => t.worktreePath));
2495
+ if (!claimed.has(bootstrap.worktreePath) && existsSync8(bootstrap.worktreePath)) {
2496
+ try {
2497
+ await removeWorktree(repoPath, bootstrap.worktreePath, {
2498
+ deleteBranch: bootstrap.branchName
2499
+ });
2500
+ } catch {
2501
+ }
2502
+ }
2503
+ return { stack, threads, createdThreadIds };
2504
+ }
2505
+
2211
2506
  // src/diff/diff.ts
2212
- import { existsSync as existsSync8, mkdirSync as mkdirSync3, readFileSync as readFileSync5, statSync as statSync2, writeFileSync as writeFileSync2 } from "fs";
2507
+ import { existsSync as existsSync9, mkdirSync as mkdirSync3, readFileSync as readFileSync5, statSync as statSync2, writeFileSync as writeFileSync2 } from "fs";
2213
2508
  import { dirname as dirname3, join as join7 } from "path";
2214
2509
  async function inspectGitWorktree(worktreePath) {
2215
- if (!worktreePath || !existsSync8(worktreePath)) return "missing_worktree";
2510
+ if (!worktreePath || !existsSync9(worktreePath)) return "missing_worktree";
2216
2511
  const check = await git(["rev-parse", "--is-inside-work-tree"], worktreePath, {
2217
2512
  reject: false
2218
2513
  });
@@ -2220,7 +2515,7 @@ async function inspectGitWorktree(worktreePath) {
2220
2515
  return "ok";
2221
2516
  }
2222
2517
  async function initializeGitRepository(worktreePath) {
2223
- if (!worktreePath || !existsSync8(worktreePath)) {
2518
+ if (!worktreePath || !existsSync9(worktreePath)) {
2224
2519
  throw new Error("Worktree not found");
2225
2520
  }
2226
2521
  const status = await inspectGitWorktree(worktreePath);
@@ -2904,7 +3199,7 @@ async function confirmLand(thread, opts) {
2904
3199
  }
2905
3200
 
2906
3201
  // src/skills/discover.ts
2907
- import { existsSync as existsSync9, readdirSync as readdirSync4, readFileSync as readFileSync6, statSync as statSync3 } from "fs";
3202
+ import { existsSync as existsSync10, readdirSync as readdirSync4, readFileSync as readFileSync6, statSync as statSync3 } from "fs";
2908
3203
  import { homedir } from "os";
2909
3204
  import { join as join8 } from "path";
2910
3205
  function toCommand(name) {
@@ -2957,7 +3252,7 @@ function readSkill(skillMd, source) {
2957
3252
  }
2958
3253
  }
2959
3254
  function scanSkillsDir(dir, source, out) {
2960
- if (!existsSync9(dir)) return;
3255
+ if (!existsSync10(dir)) return;
2961
3256
  let entries;
2962
3257
  try {
2963
3258
  entries = readdirSync4(dir);
@@ -2967,7 +3262,7 @@ function scanSkillsDir(dir, source, out) {
2967
3262
  for (const entry of entries) {
2968
3263
  if (entry.startsWith(".")) continue;
2969
3264
  const skillMd = join8(dir, entry, "SKILL.md");
2970
- if (!existsSync9(skillMd)) continue;
3265
+ if (!existsSync10(skillMd)) continue;
2971
3266
  try {
2972
3267
  if (!statSync3(skillMd).isFile()) continue;
2973
3268
  } catch {
@@ -2978,7 +3273,7 @@ function scanSkillsDir(dir, source, out) {
2978
3273
  }
2979
3274
  }
2980
3275
  function scanClaudePluginSkills(pluginsRoot, out) {
2981
- if (!existsSync9(pluginsRoot)) return;
3276
+ if (!existsSync10(pluginsRoot)) return;
2982
3277
  const walk = (dir, depth, lookingForSkillsDir) => {
2983
3278
  if (depth > 7) return;
2984
3279
  let entries;
@@ -3128,7 +3423,7 @@ function expandComposerPrompt(worktreePath, prompt, opts) {
3128
3423
  }
3129
3424
 
3130
3425
  // src/composer/stage-files.ts
3131
- import { copyFileSync as copyFileSync3, existsSync as existsSync10, mkdirSync as mkdirSync4, readFileSync as readFileSync7, statSync as statSync4, writeFileSync as writeFileSync3 } from "fs";
3426
+ import { copyFileSync as copyFileSync3, existsSync as existsSync11, mkdirSync as mkdirSync4, readFileSync as readFileSync7, statSync as statSync4, writeFileSync as writeFileSync3 } from "fs";
3132
3427
  import { basename as basename3, extname, join as join9 } from "path";
3133
3428
  import { randomUUID as randomUUID4 } from "crypto";
3134
3429
  var IMAGE_EXTENSIONS2 = /* @__PURE__ */ new Set([
@@ -3151,11 +3446,6 @@ var IMAGE_MIME_BY_EXT = {
3151
3446
  bmp: "image/bmp",
3152
3447
  ico: "image/x-icon"
3153
3448
  };
3154
- var ATTACHMENTS_DIR = ".sideboard/attachments";
3155
- var ATTACHMENTS_GITIGNORE2 = `# Sideboard review / composer attachments (local only)
3156
- *
3157
- !.gitignore
3158
- `;
3159
3449
  var MAX_INLINE_BYTES = 4e5;
3160
3450
  var MAX_PREVIEW_BYTES = 5e6;
3161
3451
  function fileExtension(filePath) {
@@ -3172,19 +3462,19 @@ function ensureAttachmentsDir(worktreePath) {
3172
3462
  const dir = join9(worktreePath, ATTACHMENTS_DIR);
3173
3463
  mkdirSync4(dir, { recursive: true });
3174
3464
  const gi = join9(dir, ".gitignore");
3175
- if (!existsSync10(gi)) {
3176
- writeFileSync3(gi, ATTACHMENTS_GITIGNORE2, "utf8");
3465
+ if (!existsSync11(gi)) {
3466
+ writeFileSync3(gi, attachmentsGitignoreBody(), "utf8");
3177
3467
  }
3178
3468
  return dir;
3179
3469
  }
3180
3470
  function uniqueAttachmentName(dir, originalName) {
3181
3471
  const safe = originalName.replace(/[/\\]/g, "_") || "file";
3182
- if (!existsSync10(join9(dir, safe))) return safe;
3472
+ if (!existsSync11(join9(dir, safe))) return safe;
3183
3473
  const ext = extname(safe);
3184
3474
  const stem = ext ? safe.slice(0, -ext.length) : safe;
3185
3475
  for (let i = 1; i < 1e4; i++) {
3186
3476
  const candidate = `${stem}-${i}${ext}`;
3187
- if (!existsSync10(join9(dir, candidate))) return candidate;
3477
+ if (!existsSync11(join9(dir, candidate))) return candidate;
3188
3478
  }
3189
3479
  return `${stem}-${randomUUID4()}${ext}`;
3190
3480
  }
@@ -3317,7 +3607,7 @@ function attachmentsFromWorktreePaths(worktreePath, relativePaths) {
3317
3607
  }
3318
3608
 
3319
3609
  // src/agents/instructions.ts
3320
- import { existsSync as existsSync11, readFileSync as readFileSync8, statSync as statSync5 } from "fs";
3610
+ import { existsSync as existsSync12, readFileSync as readFileSync8, statSync as statSync5 } from "fs";
3321
3611
  import { join as join10 } from "path";
3322
3612
  function normPath(p) {
3323
3613
  return p.replace(/\/+$/, "");
@@ -3457,7 +3747,7 @@ function loadAgentInstructions(worktreePath, agent) {
3457
3747
  for (const rel of candidates) {
3458
3748
  if (seen.has(rel)) continue;
3459
3749
  const abs = join10(worktreePath, rel);
3460
- if (!existsSync11(abs)) continue;
3750
+ if (!existsSync12(abs)) continue;
3461
3751
  try {
3462
3752
  if (!statSync5(abs).isFile()) continue;
3463
3753
  let content = readFileSync8(abs, "utf8");
@@ -3602,7 +3892,7 @@ var Orchestrator = class {
3602
3892
  }
3603
3893
  continue;
3604
3894
  }
3605
- if (!existsSync12(thread.worktreePath)) {
3895
+ if (!existsSync13(thread.worktreePath)) {
3606
3896
  setStatus(thread.id, "broken", "Worktree missing on disk");
3607
3897
  this.emit({ type: "status_changed", threadId: thread.id, status: "broken" });
3608
3898
  continue;
@@ -3747,14 +4037,9 @@ var Orchestrator = class {
3747
4037
  return findThreadByRef(idOrRef) ?? readThread(idOrRef);
3748
4038
  }
3749
4039
  async createThread(input) {
3750
- let thread = await createThread(input, (line) => {
3751
- this.emit({
3752
- type: "turn_output",
3753
- threadId: "pending",
3754
- event: { type: "stdout", data: line }
3755
- });
3756
- });
4040
+ let thread = await createThread(input);
3757
4041
  this.emit({ type: "status_changed", threadId: thread.id, status: thread.status });
4042
+ await this.runSetupAfterCreate(thread.id);
3758
4043
  const { autoRunAfterSetupEnabled } = await import("../app-settings-7XVDQJ7F.js");
3759
4044
  if (autoRunAfterSetupEnabled()) {
3760
4045
  try {
@@ -3768,6 +4053,19 @@ var Orchestrator = class {
3768
4053
  }
3769
4054
  return thread;
3770
4055
  }
4056
+ /** Run workspace setup after a new worktree is created (no-op if none configured). */
4057
+ async runSetupAfterCreate(threadId) {
4058
+ try {
4059
+ await this.runSetup(threadId);
4060
+ } catch (err) {
4061
+ const message = err instanceof Error ? err.message : String(err);
4062
+ if (/no setup script/i.test(message)) return;
4063
+ if (/already running/i.test(message)) return;
4064
+ updateThread(threadId, {
4065
+ lastError: `Setup failed: ${message}`
4066
+ });
4067
+ }
4068
+ }
3771
4069
  listWorkspaces() {
3772
4070
  const fromThreads = listThreads({ includeArchived: false }).map((t) => t.repoPath);
3773
4071
  return syncWorkspacesFromThreads(fromThreads);
@@ -4116,6 +4414,19 @@ var Orchestrator = class {
4116
4414
  });
4117
4415
  }
4118
4416
  const afterTurn = this.requireThread(threadId);
4417
+ if (afterTurn.planMode && afterTurn.worktreePath?.trim()) {
4418
+ const presented = extractPresentedPlan(parts);
4419
+ const exited = parts.some(
4420
+ (p) => p.type === "tool" && /exitplanmode/i.test(p.name)
4421
+ );
4422
+ if (presented?.content) {
4423
+ writePlanFile(afterTurn.worktreePath, presented.content);
4424
+ } else if (exited || chatText && chatText.trim().length >= 400) {
4425
+ if (!readPlanFile(afterTurn.worktreePath) && chatText?.trim()) {
4426
+ writePlanFile(afterTurn.worktreePath, chatText.trim());
4427
+ }
4428
+ }
4429
+ }
4119
4430
  if (afterTurn.planMode && afterTurn.agent === "claude" && parts.some(
4120
4431
  (p) => p.type === "tool" && /exitplanmode/i.test(p.name)
4121
4432
  )) {
@@ -4597,6 +4908,82 @@ var Orchestrator = class {
4597
4908
  }
4598
4909
  return meta;
4599
4910
  }
4911
+ async getPrStack(threadRef) {
4912
+ const thread = this.requireThread(threadRef);
4913
+ if (!thread.worktreePath?.trim()) return null;
4914
+ const stack = await getPrStack(thread.worktreePath);
4915
+ if (!stack) return null;
4916
+ const current = stack.currentIndex >= 0 ? stack.layers[stack.currentIndex] : null;
4917
+ const patch = {};
4918
+ if (stack.stackNumber != null) {
4919
+ const id = `gh-stack-${stack.stackNumber}`;
4920
+ if (thread.stackId !== id) patch.stackId = id;
4921
+ }
4922
+ if (current?.position != null && thread.stackLayer !== current.position) {
4923
+ patch.stackLayer = current.position;
4924
+ }
4925
+ if (current?.prUrl && current.prUrl !== thread.prUrl) patch.prUrl = current.prUrl;
4926
+ if (current?.title && current.title !== thread.prTitle) patch.prTitle = current.title;
4927
+ if (current?.branchName && current.branchName !== thread.branchName) {
4928
+ patch.branchName = current.branchName;
4929
+ }
4930
+ if (Object.keys(patch).length > 0) updateThread(thread.id, patch);
4931
+ return stack;
4932
+ }
4933
+ /** Open worktrees for all (or one) stack layers discovered from a thread. */
4934
+ async openPrStackLayers(threadRef, opts) {
4935
+ const result = await openPrStackLayers({ threadRef, layer: opts?.layer });
4936
+ for (const t of result.threads) {
4937
+ this.emit({ type: "status_changed", threadId: t.id, status: t.status });
4938
+ }
4939
+ for (const id of result.createdThreadIds) {
4940
+ await this.runSetupAfterCreate(id);
4941
+ }
4942
+ return { stack: result.stack, threads: result.threads };
4943
+ }
4944
+ /** Add a branch on top of the thread's stack and open its worktree. */
4945
+ async addStackLayer(threadRef, branchName, opts) {
4946
+ const result = await addStackLayerFromThread({
4947
+ threadRef,
4948
+ branchName,
4949
+ title: opts?.title
4950
+ });
4951
+ this.emit({
4952
+ type: "status_changed",
4953
+ threadId: result.thread.id,
4954
+ status: result.thread.status
4955
+ });
4956
+ if (result.createdWorktree) {
4957
+ await this.runSetupAfterCreate(result.thread.id);
4958
+ }
4959
+ return { stack: result.stack, thread: result.thread };
4960
+ }
4961
+ /** Initialize a stack from the current thread branch (optional extra layers). */
4962
+ async initStackFromThread(threadRef, opts) {
4963
+ const result = await initStackFromThread({
4964
+ threadRef,
4965
+ additionalBranches: opts?.additionalBranches,
4966
+ base: opts?.base
4967
+ });
4968
+ for (const t of result.threads) {
4969
+ this.emit({ type: "status_changed", threadId: t.id, status: t.status });
4970
+ }
4971
+ for (const id of result.createdThreadIds) {
4972
+ await this.runSetupAfterCreate(id);
4973
+ }
4974
+ return { stack: result.stack, threads: result.threads };
4975
+ }
4976
+ /** Create a new multi-layer stack with one worktree per layer. */
4977
+ async createPrStack(input) {
4978
+ const result = await createPrStack(input);
4979
+ for (const t of result.threads) {
4980
+ this.emit({ type: "status_changed", threadId: t.id, status: t.status });
4981
+ }
4982
+ for (const id of result.createdThreadIds) {
4983
+ await this.runSetupAfterCreate(id);
4984
+ }
4985
+ return { stack: result.stack, threads: result.threads };
4986
+ }
4600
4987
  async getPrDetails(threadRef) {
4601
4988
  const { thread, selector, cwd } = await this.withPrSelector(threadRef);
4602
4989
  if (!selector) return null;
@@ -4659,14 +5046,9 @@ var Orchestrator = class {
4659
5046
  return forkChatTab(input);
4660
5047
  }
4661
5048
  async forkThreadWorktree(input) {
4662
- const thread = await forkThreadWorktree(input, (line) => {
4663
- this.emit({
4664
- type: "turn_output",
4665
- threadId: "pending",
4666
- event: { type: "stdout", data: line }
4667
- });
4668
- });
5049
+ const thread = await forkThreadWorktree(input);
4669
5050
  this.emit({ type: "status_changed", threadId: thread.id, status: thread.status });
5051
+ await this.runSetupAfterCreate(thread.id);
4670
5052
  return thread;
4671
5053
  }
4672
5054
  renameThread(threadRef, title) {
@@ -4680,7 +5062,7 @@ var Orchestrator = class {
4680
5062
  }
4681
5063
  /**
4682
5064
  * Stage OS / worktree files into composer attachments (copies external files
4683
- * into `.sideboard/attachments/` so agents can Read images and binaries).
5065
+ * into `.context/attachments/` so agents can Read images and binaries).
4684
5066
  */
4685
5067
  attachComposerFiles(threadRef, opts) {
4686
5068
  const thread = this.requireThread(threadRef);
@@ -4754,8 +5136,8 @@ var Orchestrator = class {
4754
5136
  updateThread(thread.id, { worktreePath: globalAgentCwd() });
4755
5137
  return setStatus(thread.id, "idle");
4756
5138
  }
4757
- if (!existsSync12(thread.worktreePath)) {
4758
- const { createThreadWorktree: createThreadWorktree2 } = await import("../worktree-DVNDMWZ7.js");
5139
+ if (!existsSync13(thread.worktreePath)) {
5140
+ const { createThreadWorktree: createThreadWorktree2 } = await import("../worktree-5KEQWSAF.js");
4759
5141
  const { execa: execa6 } = await import("execa");
4760
5142
  const slug = thread.worktreePath.split("/").pop();
4761
5143
  const dest = thread.worktreePath;
@@ -5021,6 +5403,59 @@ async function startMcpServer() {
5021
5403
  return { content: [{ type: "text", text: JSON.stringify(payload) }] };
5022
5404
  }
5023
5405
  );
5406
+ server.tool(
5407
+ "ask_user",
5408
+ "Ask the user clarifying multiple-choice questions in Sideboard\u2019s composer (plan mode). Before calling, write a short chat message explaining the decision and what each option means. Include a description on every option. Use for approach forks and requirements \u2014 not for \u201Cis the plan ready?\u201D. After calling, stop and wait for their next message with answers.",
5409
+ {
5410
+ questions: z.array(
5411
+ z.object({
5412
+ question: z.string().describe("Full question text ending with ?"),
5413
+ header: z.string().max(24).optional().describe("Short label shown above the question"),
5414
+ multiSelect: z.boolean().optional().describe("Allow selecting multiple options"),
5415
+ options: z.array(
5416
+ z.object({
5417
+ label: z.string(),
5418
+ description: z.string().optional().describe("What this option means / when to choose it (strongly preferred)")
5419
+ })
5420
+ ).min(2).max(6).describe("2\u20136 choices (Sideboard also offers Other)")
5421
+ })
5422
+ ).min(1).max(4).describe("1\u20134 questions")
5423
+ },
5424
+ async ({ questions }) => {
5425
+ const payload = {
5426
+ ok: true,
5427
+ questions,
5428
+ message: "Questions shown in Sideboard\u2019s composer. Wait for the user\u2019s next message with their answers before continuing."
5429
+ };
5430
+ return { content: [{ type: "text", text: JSON.stringify(payload) }] };
5431
+ }
5432
+ );
5433
+ server.tool(
5434
+ "present_plan",
5435
+ "Save the implementation plan as markdown to .context/attachments/plan.md and show it in Sideboard chat for user approval (Copy / Hand off / Approve). Call this when the plan is ready \u2014 required in plan mode. Pass the full plan body in content. Then Claude should call ExitPlanMode.",
5436
+ {
5437
+ title: z.string().optional().describe("Short plan title (defaults to Plan)"),
5438
+ content: z.string().min(1).describe("Full plan markdown (headings, steps, risks, open questions)"),
5439
+ thread_id: z.string().optional().describe("Sideboard thread id when cwd is not the worktree")
5440
+ },
5441
+ async ({ title, content, thread_id }) => {
5442
+ const { writePlanFile: writePlanFile2 } = await import("../plan-file-PHVKUAEE.js");
5443
+ let root = process.cwd();
5444
+ if (thread_id?.trim()) {
5445
+ const t = orch.getThread(thread_id.trim());
5446
+ if (t?.worktreePath?.trim()) root = t.worktreePath;
5447
+ }
5448
+ const path = writePlanFile2(root, content);
5449
+ const payload = {
5450
+ ok: true,
5451
+ path,
5452
+ title: title?.trim() || "Plan",
5453
+ content,
5454
+ message: "Plan saved to .context/attachments/plan.md and shown in Sideboard chat for approval."
5455
+ };
5456
+ return { content: [{ type: "text", text: JSON.stringify(payload) }] };
5457
+ }
5458
+ );
5024
5459
  server.tool(
5025
5460
  "present_schema",
5026
5461
  "Open Sideboard\u2019s schema-driven CMS side column (filterable table and/or form). Pass JSON Schema + schemaUi (Brightsy extensions supported). Use datasource=brightsy with resource_id (record type UUID) when logged into Brightsy; use datasource=inline with embedded resource/records for any other source.",
@@ -5599,6 +6034,126 @@ async function startMcpServer() {
5599
6034
  };
5600
6035
  }
5601
6036
  );
6037
+ server.tool(
6038
+ "get_pr_stack",
6039
+ "Load the GitHub PR stack for a thread worktree (`gh stack view --json`). Returns null JSON when the branch is not stacked. Prefer this before mergePr on stacked PRs.",
6040
+ { ref: z.string() },
6041
+ async ({ ref }) => {
6042
+ const stack = await orch.getPrStack(ref);
6043
+ return {
6044
+ content: [{ type: "text", text: JSON.stringify(stack, null, 2) }]
6045
+ };
6046
+ }
6047
+ );
6048
+ server.tool(
6049
+ "open_pr_stack_layers",
6050
+ "Materialize one worktree+thread per stack layer (or a single 1-based layer). Pass a thread ref already on the stack.",
6051
+ {
6052
+ ref: z.string(),
6053
+ layer: z.number().int().positive().optional()
6054
+ },
6055
+ async ({ ref, layer }) => {
6056
+ const result = await orch.openPrStackLayers(ref, { layer });
6057
+ return {
6058
+ content: [
6059
+ {
6060
+ type: "text",
6061
+ text: JSON.stringify(
6062
+ {
6063
+ stackNumber: result.stack.stackNumber,
6064
+ trunk: result.stack.trunk,
6065
+ threads: result.threads.map((t) => ({
6066
+ id: t.id,
6067
+ title: t.title,
6068
+ branchName: t.branchName,
6069
+ stackLayer: t.stackLayer,
6070
+ worktreePath: t.worktreePath,
6071
+ prUrl: t.prUrl,
6072
+ link: `sideboard://thread/${t.id}`
6073
+ }))
6074
+ },
6075
+ null,
6076
+ 2
6077
+ )
6078
+ }
6079
+ ]
6080
+ };
6081
+ }
6082
+ );
6083
+ server.tool(
6084
+ "add_stack_layer",
6085
+ "Add a branch on top of the current stack (`gh stack add`) and open a worktree+thread for it.",
6086
+ {
6087
+ ref: z.string(),
6088
+ branchName: z.string(),
6089
+ title: z.string().optional()
6090
+ },
6091
+ async ({ ref, branchName, title }) => {
6092
+ const result = await orch.addStackLayer(ref, branchName, { title });
6093
+ return {
6094
+ content: [
6095
+ {
6096
+ type: "text",
6097
+ text: JSON.stringify(
6098
+ {
6099
+ id: result.thread.id,
6100
+ title: result.thread.title,
6101
+ branchName: result.thread.branchName,
6102
+ stackLayer: result.thread.stackLayer,
6103
+ worktreePath: result.thread.worktreePath,
6104
+ link: `sideboard://thread/${result.thread.id}`
6105
+ },
6106
+ null,
6107
+ 2
6108
+ )
6109
+ }
6110
+ ]
6111
+ };
6112
+ }
6113
+ );
6114
+ server.tool(
6115
+ "create_pr_stack",
6116
+ "Create a new GitHub PR stack with one Sideboard worktree per layer (bottom\u2192top branch names). Requires `gh extension install github/gh-stack`.",
6117
+ {
6118
+ repoPath: z.string(),
6119
+ branches: z.array(z.string()).min(1),
6120
+ agent: z.enum(["claude", "codex", "opencode", "brightsy", "cursor"]),
6121
+ base: z.string().optional(),
6122
+ title: z.string().optional()
6123
+ },
6124
+ async (args) => {
6125
+ const result = await orch.createPrStack({
6126
+ repoPath: args.repoPath,
6127
+ branches: args.branches,
6128
+ agent: args.agent,
6129
+ base: args.base,
6130
+ title: args.title
6131
+ });
6132
+ return {
6133
+ content: [
6134
+ {
6135
+ type: "text",
6136
+ text: JSON.stringify(
6137
+ {
6138
+ stackNumber: result.stack.stackNumber,
6139
+ trunk: result.stack.trunk,
6140
+ threads: result.threads.map((t) => ({
6141
+ id: t.id,
6142
+ title: t.title,
6143
+ branchName: t.branchName,
6144
+ stackLayer: t.stackLayer,
6145
+ worktreePath: t.worktreePath,
6146
+ link: `sideboard://thread/${t.id}`
6147
+ }))
6148
+ },
6149
+ null,
6150
+ 2
6151
+ )
6152
+ }
6153
+ ]
6154
+ };
6155
+ }
6156
+ );
5602
6157
  server.tool(
5603
6158
  "list_issues",
5604
6159
  "List issues from Sideboard Account connections (Linear API or GitHub Issues; Linear\u2192GitHub fallback when Linear is not connected). Pass repoPath from list_workspaces \u2014 GitHub Issues are scoped to that repo. Then create_thread with sourceType=ticket.",