@nathanstephenson/flow 0.1.10-beta.3 → 0.1.10-beta.5

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 (109) hide show
  1. package/README.md +11 -3
  2. package/build/backend-worker-chunks/{chunk-LO7O6NAM.mjs → chunk-JOI2POLP.mjs} +1 -1
  3. package/build/backend-worker-chunks/{chunk-UQDH2COY.mjs → chunk-K774KOGL.mjs} +2 -7
  4. package/build/backend-worker-chunks/chunk-LAEUXDNH.mjs +130 -0
  5. package/build/backend-worker-chunks/{chunk-MLOUI3ZM.mjs → chunk-NZZME2I3.mjs} +6 -1
  6. package/build/backend-worker-chunks/claude-GY27HBAY.mjs +35739 -0
  7. package/build/backend-worker-chunks/{pi-QNU2YE4G.mjs → pi-JV6MWPW7.mjs} +1891 -35
  8. package/build/backend-worker.mjs +25 -126
  9. package/build/workflow-runtime.cjs +12 -12
  10. package/dist/backend/claude/index.js +69 -11
  11. package/dist/backend/claude/subagents.js +11 -0
  12. package/dist/backend/claude/workflow-parent.js +1 -1
  13. package/dist/backend/fake/index.js +8 -2
  14. package/dist/backend/pi/cache-warming.js +8 -0
  15. package/dist/backend/pi/canonical-json.js +120 -0
  16. package/dist/backend/pi/compaction-model.js +3 -2
  17. package/dist/backend/pi/host-auth.js +258 -0
  18. package/dist/backend/pi/index.js +37 -12
  19. package/dist/backend/pi/model-auth.js +159 -0
  20. package/dist/backend/pi/model-catalog.js +120 -0
  21. package/dist/backend/pi/model-config.js +5 -0
  22. package/dist/backend/pi/model-selection.js +32 -0
  23. package/dist/backend/pi/work.js +9 -1
  24. package/dist/backend/pi/workflow-parent.js +1 -1
  25. package/dist/backend/pi/workflow-subagent.js +4 -3
  26. package/dist/backend/worker/entry.js +13 -1
  27. package/dist/backend/worker/index.js +69 -7
  28. package/dist/backend/worker/launcher.js +11 -4
  29. package/dist/build-id +1 -1
  30. package/dist/cli/application.js +5 -5
  31. package/dist/cli/bootstrap.js +1 -1
  32. package/dist/cli/host-control.js +1 -1
  33. package/dist/cli/install-guard.js +1 -1
  34. package/dist/cli/main.js +4 -4
  35. package/dist/cli/systemd-update.js +3 -3
  36. package/dist/cli/update.js +6 -6
  37. package/dist/cli/web-update.js +6 -6
  38. package/dist/client/reduce.js +2 -0
  39. package/dist/client/tool-summary.js +26 -15
  40. package/dist/daemon/changes.js +116 -0
  41. package/dist/daemon/commit.js +84 -0
  42. package/dist/daemon/config-store.js +3 -3
  43. package/dist/daemon/git-state.js +197 -0
  44. package/dist/daemon/github.js +54 -0
  45. package/dist/daemon/host-control-routes.js +1 -1
  46. package/dist/daemon/host.js +147 -78
  47. package/dist/daemon/log.js +3 -0
  48. package/dist/daemon/mcp-auth.js +1 -1
  49. package/dist/daemon/models.js +2 -2
  50. package/dist/daemon/pi-model-cache.js +44 -0
  51. package/dist/daemon/pull-request.js +156 -129
  52. package/dist/daemon/push.js +43 -0
  53. package/dist/daemon/repository.js +106 -0
  54. package/dist/daemon/runtime.js +27 -20
  55. package/dist/daemon/secret-store.js +1 -1
  56. package/dist/daemon/server.js +11 -10
  57. package/dist/daemon/stack-metadata.js +12 -5
  58. package/dist/daemon/stack.js +127 -656
  59. package/dist/daemon/summariser.js +19 -8
  60. package/dist/daemon/workflow-authoring-scope-checks.js +1 -1
  61. package/dist/daemon/workflow-authoring-scope.js +1 -1
  62. package/dist/daemon/workflow-builder-files.js +2 -2
  63. package/dist/daemon/workflow-builder-routes.js +2 -2
  64. package/dist/daemon/workflow-builder.js +5 -5
  65. package/dist/daemon/workflow-environment.js +5 -5
  66. package/dist/daemon/workflow-execution-launch.js +5 -5
  67. package/dist/daemon/workflow-execution-resources.js +3 -3
  68. package/dist/daemon/workflow-execution-routes.js +3 -3
  69. package/dist/daemon/workflow-execution-values.js +5 -5
  70. package/dist/daemon/workflow-executions.js +19 -19
  71. package/dist/daemon/workflow-mcp-authoring-routes.js +2 -2
  72. package/dist/daemon/workflow-mcp-authoring.js +4 -4
  73. package/dist/daemon/workflow-mcp.js +1 -1
  74. package/dist/daemon/workflow-routes.js +3 -3
  75. package/dist/daemon/workflow-schedule-driver.js +8 -8
  76. package/dist/daemon/workflow-schedule-routes.js +5 -5
  77. package/dist/daemon/workflow-schedules.js +3 -3
  78. package/dist/isolation/filesystem.js +5 -1
  79. package/dist/isolation/sandbox.js +31 -4
  80. package/dist/isolation/toolchain-assets.js +1 -1
  81. package/dist/protocol/stack.js +1 -41
  82. package/dist/workflows/calls.js +2 -2
  83. package/dist/workflows/executors.js +3 -3
  84. package/dist/workflows/graph.js +6 -6
  85. package/dist/workflows/invocations.js +1 -1
  86. package/dist/workflows/mcp.js +1 -1
  87. package/dist/workflows/records.js +6 -6
  88. package/dist/workflows/recovery.js +2 -2
  89. package/dist/workflows/runtime-settings.js +1 -1
  90. package/dist/workflows/runtime.js +2 -2
  91. package/dist/workflows/schedule-store.js +2 -2
  92. package/dist/workflows/scheduler.js +9 -9
  93. package/dist/workflows/schema.js +1 -1
  94. package/dist/workflows/store.js +3 -3
  95. package/package.json +9 -6
  96. package/web/dist/assets/index-BqZ_iUmY.css +2 -0
  97. package/web/dist/assets/index-CxdSb7k0.js +51 -0
  98. package/web/dist/assets/{settings-mcp-Vf_fCXyE.js → settings-mcp-BwOPXAfH.js} +1 -1
  99. package/web/dist/assets/settings-workflows-DocTa31_.js +23 -0
  100. package/web/dist/assets/{switch-DIogWclb.js → switch-B00FEUA7.js} +1 -1
  101. package/web/dist/assets/{workflows-Dobqzjg-.js → workflows-DJqUuGyg.js} +41 -41
  102. package/web/dist/assets/{workflows-pane-KB-Q76KZ.js → workflows-pane-oM1fO_BC.js} +1 -1
  103. package/web/dist/index.html +4 -4
  104. package/build/backend-worker-chunks/claude-6L5KCQWJ.mjs +0 -30894
  105. package/dist/daemon/publish.js +0 -289
  106. package/dist/protocol/publish.js +0 -1
  107. package/web/dist/assets/index-BGu3YSP7.css +0 -2
  108. package/web/dist/assets/index-Miy2nveb.js +0 -40
  109. package/web/dist/assets/settings-workflows-DVKxJWQm.js +0 -23
@@ -1,10 +1,10 @@
1
- import { localStack, localStacks } from "./stack-metadata.js";
1
+ import { commonGitPath, localStack, localStacks } from "./stack-metadata.js";
2
2
  import { access } from "node:fs/promises";
3
3
  import { resolve } from "node:path";
4
4
  import { createHash } from "node:crypto";
5
- import { gh, repositoryTarget } from "./publish.js";
6
- import { head, run, GIT_READ_TIMEOUT_MS, GIT_WRITE_TIMEOUT_MS } from "./git.js";
7
- import { stackDisplayGraph } from "../protocol/stack.js";
5
+ import { localRepository, resolveRepository } from "./repository.js";
6
+ import { api, gh } from "./github.js";
7
+ import { head, localBranches, run, GIT_READ_TIMEOUT_MS, GIT_WRITE_TIMEOUT_MS } from "./git.js";
8
8
  async function git(scope, args, write = false) {
9
9
  const result = await run(scope, args, write ? GIT_WRITE_TIMEOUT_MS : GIT_READ_TIMEOUT_MS);
10
10
  if (!result.ok)
@@ -18,664 +18,113 @@ export function parseStack(raw) {
18
18
  throw new Error("Invalid gh stack view JSON.");
19
19
  return value;
20
20
  }
21
- // Project each API page to one compact JSON line. gh forbids combining --slurp and
22
- // --jq, while --paginate applies the jq expression separately to every page.
23
- const pullProjection = "map({number,title,html_url,state,merged_at,head:{ref:.head.ref,repo:(.head.repo|if . then {node_id,id} else null end)},base:{ref:.base.ref,repo:(.base.repo|if . then {node_id,id} else null end)}}) | @json";
24
- const nativeProjection = "map({id,base:{ref:.base.ref},pull_requests:(.pull_requests|map({number,state,merged_at,head:{ref:.head.ref}}))}) | @json";
25
- function message(error) {
26
- return error instanceof Error ? error.message : String(error);
27
- }
28
- function pages(raw, label) {
29
- try {
30
- const parsed = raw.trim().split("\n").filter(Boolean).map(line => JSON.parse(line));
31
- if (parsed.some(page => !Array.isArray(page) || page.some(Array.isArray)))
32
- throw new Error();
33
- return parsed.flat();
34
- }
35
- catch {
36
- throw new Error(`GitHub returned invalid ${label} data.`);
37
- }
38
- }
39
- function pullRequest(pr) {
40
- return {
41
- number: pr.number,
42
- state: pr.merged_at ? "MERGED" : pr.state.toUpperCase(),
43
- ...(pr.title && pr.html_url ? { title: pr.title, url: pr.html_url } : {}),
44
- };
45
- }
46
- function validPull(pr) {
47
- return Number.isInteger(pr?.number) && typeof pr?.head?.ref === "string" && typeof pr?.base?.ref === "string" &&
48
- ["open", "closed"].includes(pr.state) && (pr.merged_at === null || typeof pr.merged_at === "string");
49
- }
50
- function sameRepository(pr, id) {
51
- const identity = (repo) => repo?.node_id ?? (repo?.id === undefined ? undefined : String(repo.id));
52
- return identity(pr.head.repo) === id && identity(pr.base.repo) === id;
53
- }
54
- async function loadPullRequests(scope, github, destination, current, localEdges = new Map(), explicitEdges = new Map(), blocked = new Set(), trunk = destination.defaultBranch) {
55
- const warnings = [];
56
- const load = async (query) => {
57
- const loaded = pages(await github(scope, ["api", "--paginate", "--jq", pullProjection, `repos/${destination.repo}/pulls?${query}&per_page=100`]), "pull request");
58
- if (loaded.some(pr => !validPull(pr)))
59
- addWarning(warnings, "Some invalid pull request relationships were ignored.");
60
- return loaded.filter(pr => validPull(pr) && sameRepository(pr, String(destination.id)));
61
- };
62
- const prs = await load("state=open");
63
- const component = new Set([current]);
64
- const queried = new Set();
65
- for (;;) {
66
- let changed = false;
67
- for (const pr of prs) {
68
- if (pr.head.ref === trunk || explicitEdges.has(pr.head.ref) || blocked.has(pr.head.ref))
69
- continue;
70
- if (component.has(pr.head.ref) || (pr.base.ref !== trunk && component.has(pr.base.ref))) {
71
- for (const branch of [pr.head.ref, pr.base.ref])
72
- if (branch !== trunk && !component.has(branch)) {
73
- component.add(branch);
74
- changed = true;
75
- }
76
- }
77
- }
78
- for (const [child, edge] of new Map([...localEdges, ...explicitEdges])) {
79
- if (blocked.has(child) || (!explicitEdges.has(child) && prs.some(pr => pr.head.ref === child)) || edge.parent === trunk)
80
- continue;
81
- if (component.has(child) || component.has(edge.parent)) {
82
- for (const name of [child, edge.parent])
83
- if (!component.has(name)) {
84
- component.add(name);
85
- changed = true;
86
- }
87
- }
88
- }
89
- if (changed)
90
- continue;
91
- const branch = [...component].find(name => name !== trunk && !queried.has(name) && !prs.some(pr => pr.head.ref === name && pr.state === "open"));
92
- if (!branch)
93
- break;
94
- queried.add(branch);
95
- try {
96
- const history = await load(`state=closed&head=${encodeURIComponent(`${destination.repo.split("/")[0]}:${branch}`)}`);
97
- prs.push(...history.filter(pr => pr.head.ref === branch && Boolean(pr.merged_at)));
98
- }
99
- catch (error) {
100
- addWarning(warnings, `Pull request ancestors for ${branch} could not be read: ${message(error)}`);
101
- }
102
- }
103
- return { prs, warnings };
104
- }
105
- async function refs(scope) {
106
- const result = { local: new Map(), remote: new Map() };
107
- const raw = await git(scope, ["for-each-ref", "--format=%(refname) %(objectname)", "refs/heads", "refs/remotes"]);
108
- for (const line of raw.trim().split("\n").filter(Boolean)) {
109
- const space = line.lastIndexOf(" ");
110
- if (space < 0)
111
- continue;
112
- const ref = line.slice(0, space);
113
- const oid = line.slice(space + 1);
114
- if (ref.startsWith("refs/heads/"))
115
- result.local.set(ref.slice("refs/heads/".length), { oid });
116
- else if (ref.startsWith("refs/remotes/") && !ref.endsWith("/HEAD")) {
117
- const short = ref.slice("refs/remotes/".length);
118
- const slash = short.indexOf("/");
119
- if (slash >= 0 && !result.remote.has(short.slice(slash + 1)))
120
- result.remote.set(short.slice(slash + 1), { oid });
121
- }
122
- }
123
- const remotes = (await git(scope, ["remote"])).trim().split("\n").filter(Boolean);
124
- if (remotes.length === 1) {
125
- result.remoteName = remotes[0];
126
- try {
127
- const target = (await git(scope, ["symbolic-ref", "--quiet", `refs/remotes/${remotes[0]}/HEAD`])).trim();
128
- const prefix = `refs/remotes/${remotes[0]}/`;
129
- if (target.startsWith(prefix))
130
- result.remoteHead = target.slice(prefix.length);
131
- }
132
- catch { /* A remote without an existing HEAD is not an error. */ }
133
- }
134
- return result;
135
- }
136
- function expectedNativeUnavailable(error) {
137
- return /(?:HTTP 404|not found|stacked pull requests (?:are )?not (?:enabled|available))/i.test(message(error));
138
- }
139
- function addWarning(warnings, value) {
140
- if (value && !warnings.includes(value))
141
- warnings.push(value);
142
- }
143
- async function ancestry(scope, tips) {
144
- const unique = [...new Set(tips)];
145
- const merged = new Map();
146
- // Ask Git to walk each tip, but emit only matching refs. Unlike rev-list this keeps output
147
- // bounded by the number of refs rather than by repository history.
148
- const next = unique.values();
149
- const worker = async () => {
150
- for (let item = next.next(); !item.done; item = next.next()) {
151
- const descendant = item.value;
152
- const raw = await git(scope, ["for-each-ref", `--merged=${descendant}`, "--format=%(objectname)", "refs/heads", "refs/remotes"]);
153
- merged.set(descendant, new Set(raw.trim().split("\n").filter(Boolean)));
154
- }
155
- };
156
- await Promise.all(Array.from({ length: Math.min(4, unique.length) }, worker));
157
- return (ancestor, descendant) => ancestor === descendant || Boolean(merged.get(descendant)?.has(ancestor));
158
- }
159
- /**
160
- * Read-only discovery for the current branch. It deliberately uses only inspection commands:
161
- * no fetch, import, registration, checkout, rebase, or push is performed here.
162
- */
163
- export async function discoverStackGraph(scope, github = gh) {
164
- const warnings = [];
165
- const branchWarnings = [];
166
- const warnBranch = (branch, text) => branchWarnings.push({ branches: [branch], text });
167
- const scopedWarnings = (component) => [...warnings, ...branchWarnings.filter(warning => warning.branches.some(branch => component.has(branch))).map(warning => warning.text)];
168
- const currentResult = await head(scope);
169
- if (!currentResult.ok)
170
- return { warnings: [currentResult.failure.message] };
171
- if (currentResult.value.detached)
172
- return { warnings };
173
- const current = currentResult.value.name;
174
- let reference;
21
+ const install = "Install gh-stack on the Session Host: gh extension install github/gh-stack. Run gh auth login if needed.";
22
+ const notInStack = /is not part of a stack/i;
23
+ export const otherWorktreeRebase = "A stack rebase is in progress in another worktree.";
24
+ const queues = new Map();
25
+ async function runStack(scope, args, github) {
26
+ const key = await commonGitPath(scope, ".");
27
+ const run = (queues.get(key) ?? Promise.resolve()).catch(() => undefined).then(() => github(scope, ["stack", ...args]));
28
+ queues.set(key, run);
175
29
  try {
176
- reference = await refs(scope);
177
- }
178
- catch (error) {
179
- return { warnings: [message(error)] };
180
- }
181
- let stacks = [];
182
- try {
183
- stacks = await localStacks(scope);
184
- }
185
- catch (error) {
186
- addWarning(warnings, `Local stack metadata could not be read: ${message(error)}`);
187
- }
188
- const localMatches = stacks.filter(stack => stack.branches.some(branch => branch.branch === current));
189
- let destination;
190
- let prs = [];
191
- let pullsComplete = false;
192
- let nativeStacks = [];
193
- if (reference.remoteName) {
194
- try {
195
- destination = await repositoryTarget(scope, github);
196
- }
197
- catch (error) {
198
- addWarning(warnings, `GitHub stack discovery failed: ${message(error)}`);
199
- }
200
- if (destination) {
201
- const [nativeResult] = await Promise.allSettled([
202
- github(scope, ["api", "--paginate", "--jq", nativeProjection, `repos/${destination.repo}/stacks?per_page=100`]),
203
- ]);
204
- if (nativeResult.status === "fulfilled") {
205
- try {
206
- const loaded = pages(nativeResult.value, "native stack");
207
- nativeStacks = loaded.filter(stack => Number.isInteger(stack?.id) && typeof stack?.base?.ref === "string" && Array.isArray(stack.pull_requests) && stack.pull_requests.every(pr => Number.isInteger(pr?.number) && typeof pr?.head?.ref === "string" && ["open", "closed"].includes(pr.state) && (pr.merged_at === null || typeof pr.merged_at === "string")));
208
- if (nativeStacks.length !== loaded.length)
209
- addWarning(warnings, "Some invalid native stack data was ignored.");
210
- }
211
- catch (error) {
212
- addWarning(warnings, `Native GitHub stack data could not be parsed: ${message(error)}`);
213
- }
214
- }
215
- else if (!expectedNativeUnavailable(nativeResult.reason))
216
- addWarning(warnings, `Native GitHub stacks could not be read: ${message(nativeResult.reason)}`);
217
- }
218
- }
219
- const nodes = new Set();
220
- const prsByBranch = new Map();
221
- const edges = new Map();
222
- const claimed = new Set();
223
- const explicitMembers = new Set();
224
- const blocked = new Set();
225
- const explicitEdges = new Map();
226
- const explicitTrunks = new Set();
227
- const offerExplicit = (child, parent, relation) => {
228
- nodes.add(child);
229
- explicitMembers.add(child);
230
- const choices = explicitEdges.get(child) ?? [];
231
- choices.push({ parent, relation });
232
- explicitEdges.set(child, choices);
233
- };
234
- for (const stack of localMatches) {
235
- explicitTrunks.add(stack.trunk.branch);
236
- let parent = stack.trunk.branch;
237
- for (const branch of stack.branches) {
238
- offerExplicit(branch.branch, parent, "local");
239
- if (branch.pullRequest)
240
- prsByBranch.set(branch.branch, { number: branch.pullRequest.number, state: branch.pullRequest.merged ? "MERGED" : "OPEN" });
241
- parent = branch.branch;
242
- }
243
- }
244
- for (const stack of nativeStacks.filter(stack => stack.pull_requests.some(pr => pr.head.ref === current))) {
245
- const topOpen = stack.pull_requests.reduce((last, pr, index) => pr.state === "open" ? index : last, -1);
246
- if (topOpen < 0)
247
- continue;
248
- explicitTrunks.add(stack.base.ref);
249
- let parent = stack.base.ref;
250
- for (let index = 0; index <= topOpen; index++) {
251
- const pr = stack.pull_requests[index];
252
- if (pr.state === "closed" && !pr.merged_at) {
253
- // Do not let a closed-unmerged member connect the members around it.
254
- parent = undefined;
255
- continue;
256
- }
257
- if (parent)
258
- offerExplicit(pr.head.ref, parent, "native");
259
- else {
260
- nodes.add(pr.head.ref);
261
- explicitMembers.add(pr.head.ref);
262
- claimed.add(pr.head.ref);
263
- blocked.add(pr.head.ref);
264
- addWarning(warnings, `A closed-unmerged native stack member precedes ${pr.head.ref}; its parent was omitted.`);
265
- }
266
- prsByBranch.set(pr.head.ref, pullRequest(pr));
267
- parent = pr.head.ref;
268
- }
269
- }
270
- for (const [child, choices] of explicitEdges) {
271
- const parents = [...new Set(choices.map(choice => choice.parent))];
272
- claimed.add(child);
273
- if (parents.length !== 1) {
274
- blocked.add(child);
275
- addWarning(warnings, `Conflicting explicit stack parents for ${child}; its parent was omitted.`);
276
- continue;
277
- }
278
- edges.set(child, { parent: parents[0], relation: choices.some(choice => choice.relation === "native") ? "native" : "local" });
279
- }
280
- let trunk;
281
- if (explicitTrunks.size === 1)
282
- trunk = [...explicitTrunks][0];
283
- else if (explicitTrunks.size > 1)
284
- addWarning(warnings, "Conflicting explicit stack trunks were found; the trunk was left unknown.");
285
- else
286
- trunk = destination?.defaultBranch ?? reference.remoteHead;
287
- const localParents = new Map();
288
- const ambiguousParents = new Set();
289
- const trunkValues = trunk ? [reference.local.get(trunk), reference.remote.get(trunk)].filter((value) => Boolean(value)) : [];
290
- const trunkValue = trunkValues[0];
291
- if (trunk && trunkValue) {
292
- try {
293
- const isAncestor = await ancestry(scope, [...reference.local.values(), ...trunkValues].map(value => value.oid));
294
- const usable = [...reference.local].filter(([branch, value]) => branch !== trunk &&
295
- !trunkValues.some(tip => isAncestor(value.oid, tip.oid)) && trunkValues.some(tip => isAncestor(tip.oid, value.oid)));
296
- for (const [child, childRef] of usable) {
297
- const ancestors = usable.filter(([parent, parentRef]) => parent !== child && parentRef.oid !== childRef.oid && isAncestor(parentRef.oid, childRef.oid));
298
- const nearest = ancestors.filter(([, candidate]) => !ancestors.some(([, other]) => candidate.oid !== other.oid && isAncestor(candidate.oid, other.oid)));
299
- if (nearest.length > 1)
300
- ambiguousParents.add(child);
301
- else
302
- localParents.set(child, { parent: nearest[0]?.[0] ?? trunk, relation: "ancestry" });
303
- }
304
- }
305
- catch (error) {
306
- addWarning(warnings, `Local ancestry could not be read: ${message(error)}`);
307
- }
308
- }
309
- if (destination) {
310
- try {
311
- const loaded = await loadPullRequests(scope, github, destination, current, localParents, edges, blocked, trunk);
312
- prs = loaded.prs;
313
- pullsComplete = !loaded.warnings.length;
314
- for (const warning of loaded.warnings)
315
- addWarning(warnings, warning);
316
- }
317
- catch (error) {
318
- addWarning(warnings, `Pull request relationships could not be read: ${message(error)}`);
319
- }
30
+ return await run;
320
31
  }
321
- const snapshot = { current, reference, stacks, ...(destination ? { destination } : {}), prs, pullsComplete };
322
- const byHead = new Map();
323
- for (const pr of prs) {
324
- const list = byHead.get(pr.head.ref) ?? [];
325
- list.push(pr);
326
- byHead.set(pr.head.ref, list);
32
+ finally {
33
+ if (queues.get(key) === run)
34
+ queues.delete(key);
327
35
  }
328
- const selected = new Map();
329
- for (const [branch, branchPRs] of byHead) {
330
- const open = branchPRs.filter(pr => pr.state === "open");
331
- if (open.length === 1)
332
- selected.set(branch, open[0]);
333
- else if (open.length > 1) {
334
- claimed.add(branch);
335
- blocked.add(branch);
336
- warnBranch(branch, `Multiple open pull requests describe ${branch}; its parent was omitted.`);
337
- }
338
- }
339
- // A merged PR only participates when it is needed to connect an active descendant.
340
- const queue = [...selected.values()].map(pr => pr.base.ref);
341
- const visitedBases = new Set();
342
- while (queue.length) {
343
- const branch = queue.shift();
344
- if (branch === trunk || visitedBases.has(branch) || selected.has(branch))
345
- continue;
346
- visitedBases.add(branch);
347
- const merged = (byHead.get(branch) ?? []).filter(pr => Boolean(pr.merged_at));
348
- if (!merged.length)
349
- continue;
350
- const parents = [...new Set(merged.map(pr => pr.base.ref))];
351
- if (parents.length !== 1) {
352
- claimed.add(branch);
353
- blocked.add(branch);
354
- warnBranch(branch, `Historical pull requests disagree about the parent of ${branch}; its parent was omitted.`);
355
- continue;
356
- }
357
- // GitHub lists newest PRs first. Equivalent historical relationships do not compete.
358
- selected.set(branch, merged[0]);
359
- queue.push(merged[0].base.ref);
360
- }
361
- for (const [child, pr] of selected) {
362
- nodes.add(child);
363
- if (pr.base.ref !== trunk)
364
- nodes.add(pr.base.ref);
365
- prsByBranch.set(child, pullRequest(pr));
366
- claimed.add(child);
367
- if (!edges.has(child) && !blocked.has(child))
368
- edges.set(child, { parent: pr.base.ref, relation: "pull-request" });
369
- }
370
- for (const [child, edge] of localParents) {
371
- if (claimed.has(child) || blocked.has(child) || edges.has(child))
372
- continue;
373
- nodes.add(child);
374
- if (edge.parent !== trunk)
375
- nodes.add(edge.parent);
376
- edges.set(child, edge);
377
- }
378
- for (const child of ambiguousParents) {
379
- if (claimed.has(child) || blocked.has(child) || edges.has(child))
380
- continue;
381
- blocked.add(child);
382
- warnBranch(child, `Local history has multiple equally near parents for ${child}; its parent was omitted.`);
383
- }
384
- if (!trunk && new Set([...reference.local.values()].map(value => value.oid)).size >= 2 && !explicitMembers.size && !selected.size) {
385
- addWarning(warnings, "The trunk branch is unknown, so local branch relationships could not be inferred.");
386
- }
387
- else if (trunk && !trunkValue && new Set([...reference.local.values()].map(value => value.oid)).size >= 2 && !explicitMembers.size && !selected.size) {
388
- addWarning(warnings, `The trunk ${trunk} is not available in local refs, so local branch relationships could not be inferred.`);
389
- }
390
- // A parent map cannot safely contain a cycle. Remove every edge in each cycle rather than
391
- // selecting an arbitrary edge to break it.
392
- const checked = new Set();
393
- for (const start of edges.keys()) {
394
- if (checked.has(start))
395
- continue;
396
- const path = [];
397
- const position = new Map();
398
- let branch = start;
399
- while (branch && edges.has(branch) && !checked.has(branch)) {
400
- const seen = position.get(branch);
401
- if (seen !== undefined) {
402
- const cycle = path.slice(seen);
403
- for (const member of cycle) {
404
- edges.delete(member);
405
- blocked.add(member);
406
- }
407
- branchWarnings.push({ branches: cycle, text: `A stack relationship cycle involving ${[...cycle].sort().join(", ")} was omitted.` });
408
- break;
409
- }
410
- position.set(branch, path.length);
411
- path.push(branch);
412
- branch = edges.get(branch)?.parent;
413
- }
414
- for (const member of path)
415
- checked.add(member);
416
- }
417
- if (current === trunk || !nodes.has(current))
418
- return { warnings: scopedWarnings(new Set([current])), snapshot };
419
- // Scope through non-trunk edges only. Trunk is a boundary, not a hub joining unrelated stacks.
420
- const adjacent = new Map();
421
- const join = (a, b) => {
422
- const aSet = adjacent.get(a) ?? new Set();
423
- aSet.add(b);
424
- adjacent.set(a, aSet);
425
- const bSet = adjacent.get(b) ?? new Set();
426
- bSet.add(a);
427
- adjacent.set(b, bSet);
428
- };
429
- for (const [child, edge] of edges)
430
- if (edge.parent !== trunk && nodes.has(edge.parent))
431
- join(child, edge.parent);
432
- const component = new Set([current]);
433
- const pending = [current];
434
- while (pending.length)
435
- for (const next of adjacent.get(pending.shift()) ?? [])
436
- if (!component.has(next)) {
437
- component.add(next);
438
- pending.push(next);
439
- }
440
- const explicit = [...component].some(branch => explicitMembers.has(branch));
441
- const related = [...component].some(branch => {
442
- const parent = edges.get(branch)?.parent;
443
- return parent !== undefined && parent !== trunk && component.has(parent);
444
- });
445
- if (!explicit && (component.size < 2 || !related))
446
- return { warnings: scopedWarnings(component), snapshot };
447
- const children = new Map();
448
- for (const branch of component) {
449
- const parent = edges.get(branch)?.parent;
450
- if (!parent || !component.has(parent))
451
- continue;
452
- const list = children.get(parent) ?? [];
453
- list.push(branch);
454
- children.set(parent, list);
455
- }
456
- for (const list of children.values())
457
- list.sort((a, b) => a.localeCompare(b));
458
- const roots = [...component].filter(branch => !component.has(edges.get(branch)?.parent ?? "")).sort((a, b) => a.localeCompare(b));
459
- const order = [];
460
- const append = (branch) => { order.push(branch); for (const child of children.get(branch) ?? [])
461
- append(child); };
462
- for (const root of roots)
463
- append(root);
464
- const branches = order.map(name => {
465
- const edge = edges.get(name);
466
- return {
467
- name,
468
- ...(edge ? { parent: edge.parent, relation: edge.relation } : {}),
469
- isCurrent: name === current,
470
- availability: reference.local.has(name) ? "local" : "remote",
471
- ...(prsByBranch.has(name) ? { pr: prsByBranch.get(name) } : {}),
472
- };
473
- });
474
- return { graph: { ...(trunk ? { trunk } : {}), currentBranch: current, branches, explicit }, warnings: scopedWarnings(component), snapshot };
475
36
  }
476
- function indexPullRequests(pullRequests) {
477
- const byHead = new Map();
478
- const openByBase = new Map();
479
- for (const pr of pullRequests) {
480
- const heads = byHead.get(pr.head.ref) ?? [];
481
- heads.push(pr);
482
- byHead.set(pr.head.ref, heads);
483
- if (pr.state === "open") {
484
- const children = openByBase.get(pr.base.ref) ?? [];
485
- children.push(pr);
486
- openByBase.set(pr.base.ref, children);
487
- }
488
- }
489
- return { byHead, openByBase };
490
- }
491
- function candidateFromSnapshot(snapshot) {
492
- const { current, reference, stacks, destination } = snapshot;
493
- const { byHead, openByBase } = indexPullRequests(snapshot.prs);
494
- if (!destination?.id || current === destination.defaultBranch)
495
- return;
496
- const tracked = new Set(stacks.flatMap(stack => [stack.trunk.branch, ...stack.branches.map(branch => branch.branch)]));
497
- if (stacks.some(stack => stack.branches.some(branch => branch.branch === current)))
498
- return;
499
- const localRefs = [...reference.local].map(([name, value]) => [name, value.oid]);
500
- const trunk = destination.defaultBranch;
501
- const base = localRefs.find(([name]) => name === trunk);
502
- if (!base)
503
- return;
504
- const choose = (branch, merged) => {
505
- const matching = byHead.get(branch) ?? [];
506
- const open = matching.filter(pr => pr.state === "open");
507
- if (open.length === 1)
508
- return open[0];
509
- if (open.length > 1 || !merged)
510
- return;
511
- const history = matching.filter(pr => Boolean(pr.merged_at));
512
- return new Set(history.map(pr => pr.base.ref)).size === 1 ? history[0] : undefined;
513
- };
514
- const chain = [];
515
- const seen = new Set();
516
- let branch = current;
517
- while (branch !== trunk) {
518
- if (seen.has(branch))
519
- return;
520
- seen.add(branch);
521
- const parent = choose(branch, true);
522
- if (!parent)
523
- return;
524
- chain.unshift(parent);
525
- branch = parent.base.ref;
526
- }
527
- branch = current;
528
- while (true) {
529
- const children = openByBase.get(branch) ?? [];
530
- if (!children.length)
531
- break;
532
- if (children.length !== 1 || seen.has(children[0].head.ref))
533
- return;
534
- chain.push(children[0]);
535
- branch = children[0].head.ref;
536
- seen.add(branch);
537
- }
538
- if (chain.length < 2 || !chain.some(pr => pr.state === "open"))
539
- return;
540
- for (const pr of chain)
541
- if (pr.head.ref === trunk || tracked.has(pr.head.ref) || !reference.local.has(pr.head.ref))
542
- return;
543
- for (const pr of chain)
544
- if ((openByBase.get(pr.head.ref)?.length ?? 0) > (pr === chain.at(-1) ? 0 : 1))
545
- return;
546
- return {
547
- trunk,
548
- branches: chain.map(pr => pr.head.ref),
549
- pullRequests: chain.map(pr => ({ branch: pr.head.ref, ...pullRequest(pr) })),
550
- fingerprint: createHash("sha256").update(JSON.stringify({ destination, base, chain, localRefs, current })).digest("hex"),
551
- };
552
- }
553
- export async function discoverStack(scope, github = gh) {
554
- try {
555
- const current = await head(scope);
556
- if (!current.ok || current.value.detached)
557
- return;
558
- const [reference, stacks, destination] = await Promise.all([refs(scope), localStacks(scope), repositoryTarget(scope, github)]);
559
- const { prs, warnings } = await loadPullRequests(scope, github, destination, current.value.name);
560
- if (warnings.length || !destination.id)
561
- return;
562
- return candidateFromSnapshot({ current: current.value.name, reference, stacks, destination, prs });
563
- }
564
- catch {
565
- return;
566
- }
37
+ async function gitPathExists(scope, name) {
38
+ return access(resolve(scope, (await git(scope, ["rev-parse", "--git-path", name])).trim())).then(() => true, () => false);
567
39
  }
568
- export async function actionStackStatus(scope, github = gh) {
569
- const status = { available: false, conflicts: [], rebasing: false };
40
+ export async function stackStatus(scope, github = gh) {
570
41
  try {
571
- await github(scope, ["stack", "--help"]);
572
- status.available = true;
42
+ await runStack(scope, ["--help"], github);
573
43
  }
574
44
  catch {
575
- status.problem = "Install GitHub CLI, then run gh extension install github/gh-stack on the Session Host to manage this stack. Viewing does not require the extension. Run gh auth login if needed.";
576
- status.problemKind = "action";
577
- }
45
+ return { available: false, conflicts: [], rebasing: false };
46
+ }
47
+ const conflicts = (await git(scope, ["diff", "--name-only", "--diff-filter=U", "-z"])).split("\0").filter(Boolean);
48
+ const stackRebase = await access(await commonGitPath(scope, "gh-stack-rebase-state")).then(() => true, () => false);
49
+ const rebasing = stackRebase && (await gitPathExists(scope, "rebase-merge") || await gitPathExists(scope, "rebase-apply"));
50
+ const status = { available: true, conflicts, rebasing };
51
+ if (rebasing)
52
+ return status;
53
+ if (stackRebase)
54
+ return { ...status, notice: otherWorktreeRebase };
55
+ const current = await head(scope);
56
+ if (!current.ok)
57
+ throw new Error(current.failure.message);
58
+ if (current.value.detached)
59
+ return { ...status, notice: "HEAD is detached. Switch to a branch to see its stack." };
60
+ const branch = current.value.name;
61
+ const [listed, stacks] = await Promise.all([localBranches(scope), localStacks(scope)]);
62
+ if (!listed.ok)
63
+ throw new Error(listed.failure.message);
64
+ if (!listed.value.includes(branch))
65
+ return { ...status, notice: "This branch has no commits yet. Commit first to create a stack." };
66
+ const trunkNotice = `${branch} is a trunk. Switch to another branch to create a stack.`;
67
+ if (stacks.some(stack => stack.trunk.branch === branch))
68
+ return { ...status, notice: trunkNotice };
578
69
  try {
579
- status.conflicts = (await git(scope, ["diff", "--name-only", "--diff-filter=U", "-z"])).split("\0").filter(Boolean);
580
- const path = (await git(scope, ["rev-parse", "--git-path", "gh-stack-rebase-state"])).trim();
581
- status.rebasing = await access(resolve(scope, path)).then(() => true, () => false);
70
+ return { ...status, view: parseStack(await runStack(scope, ["view", "--json"], github)) };
582
71
  }
583
72
  catch (error) {
584
- status.problem = message(error);
585
- status.problemKind = "discovery";
586
- }
587
- if (status.available) {
588
- try {
589
- status.view = parseStack(await github(scope, ["stack", "view", "--json"]));
590
- }
591
- catch (error) {
592
- if (/current branch .+ (?:is not|not) (?:a )?part of (?:a |any )?stack/i.test(message(error))) {
593
- status.warnings = ["gh-stack reports that the current branch is not part of a managed stack."];
594
- }
595
- else
596
- status.warnings = [`Managed stack details could not be read: ${message(error)}`];
597
- }
598
- }
599
- return status;
600
- }
601
- export async function stackStatus(scope, github = gh) {
602
- const status = await actionStackStatus(scope, github);
603
- const actionProblem = status.problemKind === "action" ? status.problem : undefined;
604
- if (actionProblem) {
605
- delete status.problem;
606
- delete status.problemKind;
607
- }
608
- const notManagedWarning = "gh-stack reports that the current branch is not part of a managed stack.";
609
- const warnings = [...(status.warnings ?? [])];
610
- delete status.warnings;
611
- let discovery;
73
+ if (!notInStack.test(String(error)))
74
+ throw error;
75
+ }
76
+ const trunk = (await localRepository(scope, branch))?.defaultBranches.find(name => listed.value.includes(name));
77
+ if (branch === trunk)
78
+ return { ...status, notice: trunkNotice };
79
+ const stacked = new Set(stacks.flatMap(stack => stack.branches.map(member => member.branch)));
80
+ return { ...status, create: { current: branch, ...(trunk ? { trunk } : {}), branches: listed.value, unstacked: listed.value.filter(name => !stacked.has(name)) } };
81
+ }
82
+ const titles = new Map();
83
+ async function readTitles(scope, branch, numbers, github) {
84
+ const [owner, name] = (await resolveRepository(scope, branch, github)).base.repo.split("/");
85
+ const query = (list) => api(scope, github, `query($owner:String!,$name:String!){repository(owner:$owner,name:$name){${list.map(number => `pr${number}:pullRequest(number:${number}){title isDraft}`).join(" ")}}}`, { owner: owner, name: name });
86
+ let wanted = numbers;
87
+ let data;
612
88
  try {
613
- discovery = await discoverStackGraph(scope, github);
614
- if (discovery.graph)
615
- status.graph = discovery.graph;
616
- if (status.view && discovery.snapshot) {
617
- const details = new Map(discovery.snapshot.prs.map(pr => [pr.number, pr]));
618
- for (const branch of status.view.branches) {
619
- if (!branch.pr)
620
- continue;
621
- const found = details.get(branch.pr.number);
622
- if (found?.title && found.html_url)
623
- Object.assign(branch.pr, { title: found.title, url: found.html_url });
624
- }
625
- }
626
- for (const warning of discovery.warnings)
627
- addWarning(warnings, warning);
628
- if (!discovery.snapshot?.stacks.some(stack => stack.branches.some(branch => branch.branch === discovery.snapshot.current))) {
629
- const index = warnings.indexOf(notManagedWarning);
630
- if (index >= 0)
631
- warnings.splice(index, 1);
632
- }
89
+ data = await query(wanted);
633
90
  }
634
91
  catch (error) {
635
- addWarning(warnings, `Stack discovery failed: ${message(error)}`);
636
- }
637
- if (!status.view && !status.rebasing) {
638
- try {
639
- const candidate = discovery?.snapshot?.pullsComplete ? candidateFromSnapshot(discovery.snapshot) : undefined;
640
- if (candidate)
641
- status.candidate = candidate;
642
- }
643
- catch (error) {
644
- // Broad discovery may still have produced a useful graph. Candidate failure only removes Init.
645
- if (status.graph)
646
- addWarning(warnings, `This graph is read-only because registration eligibility could not be verified: ${message(error)}`);
647
- }
648
- }
649
- const displayGraph = stackDisplayGraph(status);
650
- if (displayGraph)
651
- status.graph = displayGraph;
652
- else
653
- delete status.graph;
654
- if (warnings.length)
655
- status.warnings = warnings;
656
- const hasDisplay = Boolean(status.graph || status.rebasing);
657
- if (!status.problem && warnings.length && !hasDisplay) {
658
- status.problem = warnings.shift();
659
- status.problemKind = "discovery";
660
- if (warnings.length)
661
- status.warnings = warnings;
662
- else
663
- delete status.warnings;
664
- }
665
- else if (!status.problem && actionProblem) {
666
- status.problem = actionProblem;
667
- status.problemKind = "action";
668
- }
669
- return status;
92
+ const missing = [...String(error).matchAll(/number of (\d+)/g)].map(match => Number(match[1]));
93
+ wanted = numbers.filter(number => !missing.includes(number));
94
+ if (!missing.length || !wanted.length)
95
+ throw error;
96
+ data = await query(wanted);
97
+ }
98
+ return new Map(wanted.flatMap(number => data.repository[`pr${number}`] ? [[number, data.repository[`pr${number}`]]] : []));
99
+ }
100
+ export async function stackTitles(scope, view, github = gh) {
101
+ for (const [cachedScope, entry] of titles)
102
+ if (entry.expires <= Date.now())
103
+ titles.delete(cachedScope);
104
+ const numbers = view.branches.flatMap(branch => branch.pr ? [branch.pr.number] : []);
105
+ if (!numbers.length)
106
+ return true;
107
+ const key = JSON.stringify(view.branches.map(branch => branch.pr && [branch.pr.number, branch.pr.state]));
108
+ const cached = titles.get(scope);
109
+ let found = cached?.key === key ? cached.found : undefined;
110
+ if (!found) {
111
+ found = await readTitles(scope, view.currentBranch, numbers, github).catch(() => new Map());
112
+ titles.set(scope, { key, expires: Date.now() + 5 * 60_000, found });
113
+ }
114
+ for (const branch of view.branches)
115
+ if (branch.pr && found.has(branch.pr.number))
116
+ Object.assign(branch.pr, found.get(branch.pr.number));
117
+ return numbers.every(number => found.has(number));
670
118
  }
671
119
  export async function cleanStack(scope) {
672
120
  if ((await git(scope, ["status", "--porcelain=v1", "-z", "--untracked-files=all"])).length)
673
- throw new Error("This Scope has uncommitted changes. Use Publish or commit them first. Stack operations never stash changes.");
674
- for (const operation of ["rebase-merge", "rebase-apply", "sequencer", "MERGE_HEAD", "CHERRY_PICK_HEAD", "REVERT_HEAD", "gh-stack-rebase-state"]) {
675
- const path = (await git(scope, ["rev-parse", "--git-path", operation])).trim();
676
- if (await access(resolve(scope, path)).then(() => true, () => false))
121
+ throw new Error("This Scope has uncommitted changes. Commit them first. Stack operations never stash changes.");
122
+ for (const operation of ["rebase-merge", "rebase-apply", "sequencer", "MERGE_HEAD", "CHERRY_PICK_HEAD", "REVERT_HEAD"]) {
123
+ if (await gitPathExists(scope, operation))
677
124
  throw new Error("Finish or abort the current Git operation first.");
678
125
  }
126
+ if (await access(await commonGitPath(scope, "gh-stack-rebase-state")).then(() => true, () => false))
127
+ throw new Error("A stack rebase is in progress in this or another worktree. Finish or abort it first.");
679
128
  }
680
129
  export async function stackFingerprint(scope, view, sync = false, github = gh) {
681
130
  let membership;
@@ -696,26 +145,44 @@ export async function stackFingerprint(scope, view, sync = false, github = gh) {
696
145
  const config = await git(scope, ["config", "--local", "--list"]);
697
146
  return createHash("sha256").update(JSON.stringify({ view, refs, config, membership })).digest("hex");
698
147
  }
148
+ async function validateInit(scope, trunk, branches, github) {
149
+ try {
150
+ await runStack(scope, ["--help"], github);
151
+ }
152
+ catch {
153
+ throw new Error(install);
154
+ }
155
+ const listed = await localBranches(scope);
156
+ if (!listed.ok)
157
+ throw new Error(listed.failure.message);
158
+ if (typeof trunk !== "string" || !listed.value.includes(trunk))
159
+ throw new Error(`${String(trunk)} is not a local branch.`);
160
+ const stacked = new Set((await localStacks(scope)).flatMap(stack => stack.branches.map(member => member.branch)));
161
+ for (const [index, branch] of branches.entries()) {
162
+ if (!listed.value.includes(branch))
163
+ throw new Error(`${branch} is not a local branch.`);
164
+ if (branch === trunk)
165
+ throw new Error(`${branch} is the trunk. Choose it only as the trunk.`);
166
+ if (branches.indexOf(branch) !== index)
167
+ throw new Error(`${branch} is listed twice.`);
168
+ if (stacked.has(branch))
169
+ throw new Error(`${branch} is already in a stack.`);
170
+ }
171
+ }
699
172
  export async function changeStack(scope, input, github = gh) {
700
173
  const { action } = input;
701
174
  if (!["init", "add", "checkout", "rebase", "continue", "abort", "submit", "sync"].includes(action))
702
175
  throw new Error("Unknown Stack action.");
703
176
  if (action === "continue" || action === "abort") {
704
- const state = await actionStackStatus(scope, github);
177
+ const state = await stackStatus(scope, github);
705
178
  if (!state.rebasing)
706
- throw new Error("No Stack rebase is in progress.");
179
+ throw new Error(state.notice === otherWorktreeRebase ? otherWorktreeRebase : "No Stack rebase is in progress.");
707
180
  if (action === "continue" && state.conflicts.length)
708
181
  throw new Error("Resolve and stage all conflict files before continuing.");
709
182
  }
710
183
  else
711
184
  await cleanStack(scope);
712
- const args = ["stack", action];
713
- if (action === "init") {
714
- const candidate = await discoverStack(scope, github);
715
- if (!candidate || input.fingerprint !== candidate.fingerprint || JSON.stringify(input.branches) !== JSON.stringify(candidate.branches))
716
- throw new Error("The existing branch chain changed or is not eligible. Refresh Stack and review it again.");
717
- args.push("--base", candidate.trunk);
718
- }
185
+ const args = [action];
719
186
  if (action === "init" || action === "add" || action === "checkout") {
720
187
  if (!Array.isArray(input.branches) || !input.branches.length || (action !== "init" && input.branches.length !== 1))
721
188
  throw new Error("Enter a branch name.");
@@ -724,8 +191,12 @@ export async function changeStack(scope, input, github = gh) {
724
191
  throw new Error("Invalid branch name.");
725
192
  await git(scope, ["check-ref-format", "--branch", branch]);
726
193
  }
194
+ if (action === "init") {
195
+ await validateInit(scope, input.trunk, input.branches, github);
196
+ args.push("--base", input.trunk);
197
+ }
727
198
  if (action === "checkout") {
728
- const state = await actionStackStatus(scope, github);
199
+ const state = await stackStatus(scope, github);
729
200
  const branch = input.branches[0];
730
201
  if (!state.view?.branches.some(b => b.name === branch))
731
202
  throw new Error("Choose a branch in the current local stack.");
@@ -735,9 +206,9 @@ export async function changeStack(scope, input, github = gh) {
735
206
  args.push(...input.branches);
736
207
  }
737
208
  if (action === "continue" || action === "abort")
738
- args.splice(1, 1, "rebase", `--${action}`);
209
+ args.splice(0, 1, "rebase", `--${action}`);
739
210
  if (action === "submit")
740
211
  args.push("--auto");
741
- return github(scope, args);
212
+ return runStack(scope, args, github);
742
213
  }
743
- export const stackConflictMessage = "Resolve the current gh stack rebase conflicts in this Scope. Inspect the Stack rebase state and conflict files first. Preserve the intended changes and stage only resolved files. Run gh stack rebase --continue only after git diff --name-only --diff-filter=U is empty and all conflicts are resolved. Repeat for further conflicts; stop and report if the intended resolution is unclear. This request permits local conflict repair and Stack rebase continuation only. Do not push, publish, submit, sync, merge, or restructure the stack. Report the result so I can review it before any separate Sync confirmation.";
214
+ export const stackConflictMessage = "Resolve the current gh stack rebase conflicts in this Scope. Inspect the Stack rebase state and conflict files first. Preserve the intended changes and stage only resolved files. Run gh stack rebase --continue only after git diff --name-only --diff-filter=U is empty and all conflicts are resolved. Repeat for further conflicts; stop and report if the intended resolution is unclear. This request permits local conflict repair and Stack rebase continuation only. Do not push, submit, sync, merge, or restructure the stack. Report the result so I can review it before any separate Sync confirmation.";