ticket-runner 0.6.4 → 0.6.6

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 (50) hide show
  1. package/README.ko.md +5 -5
  2. package/README.md +4 -4
  3. package/docs/templates/operator-skill.md +81 -16
  4. package/package.json +1 -1
  5. package/src/acceptance-criteria.ts +99 -2
  6. package/src/adapters/claude-agent-runner.ts +5 -5
  7. package/src/adapters/exec.ts +32 -4
  8. package/src/adapters/gh-tracker.ts +276 -60
  9. package/src/adapters/git-workspace.ts +27 -10
  10. package/src/adapters/liveness.ts +77 -0
  11. package/src/adapters/process-tree.ts +4 -7
  12. package/src/adapters/version.ts +5 -5
  13. package/src/branch.ts +1 -1
  14. package/src/cli.ts +2 -2
  15. package/src/config.ts +22 -4
  16. package/src/conventions.ts +22 -19
  17. package/src/credential.ts +14 -13
  18. package/src/criteria.ts +102 -52
  19. package/src/failing-base.ts +7 -7
  20. package/src/failure-message.ts +72 -0
  21. package/src/guards.ts +21 -6
  22. package/src/handoff.ts +2 -2
  23. package/src/init.ts +8 -8
  24. package/src/landing.ts +1 -1
  25. package/src/lifecycle.ts +2 -2
  26. package/src/lock.ts +10 -2
  27. package/src/note-schema.ts +14 -11
  28. package/src/notes.ts +19 -7
  29. package/src/operator-skill.ts +2 -2
  30. package/src/orchestrator.ts +758 -275
  31. package/src/outside-fault.ts +103 -0
  32. package/src/ports/agent-runner.ts +1 -1
  33. package/src/ports/tracker.ts +29 -15
  34. package/src/ports/workspace.ts +52 -24
  35. package/src/progress.ts +42 -7
  36. package/src/prompts.ts +242 -34
  37. package/src/readiness.ts +11 -11
  38. package/src/remove.ts +7 -7
  39. package/src/resume.ts +28 -20
  40. package/src/run-log.ts +5 -5
  41. package/src/run.ts +55 -13
  42. package/src/staleness.ts +14 -14
  43. package/src/start.ts +29 -16
  44. package/src/stranded.ts +19 -19
  45. package/src/templates.ts +398 -149
  46. package/src/title.ts +106 -8
  47. package/src/transcript-home.ts +49 -0
  48. package/src/verdict.ts +132 -27
  49. package/src/version-number.ts +13 -13
  50. package/src/version-pr.ts +12 -12
package/src/templates.ts CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  emptyBilling,
13
13
  } from "./credential.js";
14
14
  import type { GuardReason } from "./guards.js";
15
- import type { HostKind } from "./host.js";
15
+ import { splitMessage } from "./failure-message.js";
16
16
  import type { FailurePoint } from "./lifecycle.js";
17
17
  import { logTail } from "./log-tail.js";
18
18
  import type { NoteText, NotingStage, RoutedNote } from "./notes.js";
@@ -20,7 +20,8 @@ import type { ReleaseCause, TicketOutcome } from "./orchestrator.js";
20
20
  import type { IssueComment, SquashCommit } from "./ports/tracker.js";
21
21
  import type { KeptTranscripts } from "./ports/workspace.js";
22
22
  import type { RunStop } from "./run.js";
23
- import { type Criterion, type Verdict, countStatuses } from "./verdict.js";
23
+ import type { BranchProse } from "./title.js";
24
+ import type { Verdict } from "./verdict.js";
24
25
 
25
26
  /** How the pipeline finds its own hand-off comment again. */
26
27
  export const HANDOFF_MARKER = "<!-- ticket-runner:handoff -->";
@@ -107,75 +108,65 @@ export function hasGuardWarning(comments: IssueComment[], reason: GuardReason):
107
108
  return findMarkedComment(comments, guardMarker(reason)) !== undefined;
108
109
  }
109
110
 
110
- /** The one warning a skipped candidate gets. Two sentences: the reason, the fix. */
111
- export function guardComment(reason: GuardReason): string {
112
- return [
113
- guardMarker(reason),
114
- `**Skipped by ticket-runner.** ${GUARD_SENTENCES[reason]}`,
115
- "",
116
- ].join("\n");
111
+ /**
112
+ * What the `no-criteria` guard says of a Ticket whose checkboxes are all
113
+ * ticked. Told only that it has no criteria, a human looking at a list of them
114
+ * reads the comment as wrong.
115
+ */
116
+ function allTickedSentences(ticked: number): string {
117
+ const boxes = ticked === 1 ? "its one checkbox is" : `all ${ticked} of its checkboxes are`;
118
+ return (
119
+ `No \`- [ ]\` acceptance criteria found: ${boxes} already ticked. ` +
120
+ "Untick each criterion not yet done, then re-run."
121
+ );
117
122
  }
118
123
 
119
- /** The Verdict summary both the pull request body and the squash commit carry. */
120
- function verdictCounts(verdict: Verdict): string {
121
- const counts = countStatuses(verdict);
122
- return `${counts.met} met · ${counts.unmet} unmet · ${counts.unverifiable} unverifiable`;
124
+ /**
125
+ * The one warning a skipped candidate gets. Two sentences: the reason, the fix.
126
+ *
127
+ * `ticked` is how many ticked checkboxes the Ticket carries, which only the
128
+ * `no-criteria` warning reads.
129
+ */
130
+ export function guardComment(reason: GuardReason, ticked = 0): string {
131
+ const sentences =
132
+ reason === "no-criteria" && ticked > 0 ? allTickedSentences(ticked) : GUARD_SENTENCES[reason];
133
+ return [guardMarker(reason), `**Skipped by ticket-runner.** ${sentences}`, ""].join("\n");
123
134
  }
124
135
 
125
- const STATUS_ICON: Record<Criterion["status"], string> = {
126
- met: "✅",
127
- unmet: "❌",
128
- unverifiable: "❓",
129
- };
130
-
131
136
  export interface PullRequestBody {
132
137
  ticket: number;
133
- verdict: Verdict;
134
- runId: string;
135
- /** The Host the Run is on, which decides whether its run directory is worth naming. */
136
- host: HostKind;
138
+ /** The latest body a Stage answered for the branch, when one has. */
139
+ body?: string;
137
140
  }
138
141
 
139
- export function pullRequestBody({ ticket, verdict, runId, host }: PullRequestBody): string {
140
- const criteria = verdict.criteria.map((criterion) => {
141
- const line = `- ${STATUS_ICON[criterion.status]} ${criterion.text}`;
142
- return criterion.status === "met" ? line : `${line} — ${criterion.evidence}`;
143
- });
144
-
145
- // A merged Ticket keeps no transcripts on the remote, so the run directory is
146
- // the only place they are, and a cloud Host's goes with its session.
147
- const where =
148
- host === "workstation" ? `\`.ticket-runner/runs/${runId}/${ticket}/\`` : undefined;
149
-
150
- return [
151
- `Closes #${ticket}`,
152
- "",
153
- `**Verdict:** ${verdictCounts(verdict)}`,
154
- "",
155
- "<details><summary>Criteria</summary>",
156
- "",
157
- ...criteria,
158
- "",
159
- "</details>",
160
- "",
161
- runLine(runId, where),
162
- "",
163
- ].join("\n");
142
+ /**
143
+ * The body of a pipeline pull request: the one `Closes` the pipeline writes,
144
+ * and below it the body a Stage answered in the Target's shape or the `pr`
145
+ * skill's. The pipeline adds nothing of its own: the verify Stage's progress
146
+ * row carries the verdict, and the merge ticks the met criteria on the Ticket.
147
+ */
148
+ export function pullRequestBody({ ticket, body }: PullRequestBody): string {
149
+ const closes = `Closes #${ticket}`;
150
+ return body === undefined ? `${closes}\n` : `${closes}\n\n${body}\n`;
164
151
  }
165
152
 
166
153
  export interface DraftPullRequestBody {
167
154
  ticket: number;
168
155
  stage: FailurePoint;
156
+ /**
157
+ * As the hand-off comment's: one line, or an unexpected error's whole
158
+ * message, whose output the body shows as evidence the way the comment does.
159
+ */
169
160
  failure: string;
170
161
  runId: string;
171
- /** Where the hand-off kept the Stages' transcripts on the remote, when it kept any. */
172
- transcripts?: KeptTranscripts;
162
+ /** Where the hand-off kept the Stages' transcripts, when there are any. */
163
+ transcripts?: TranscriptsPlace;
173
164
  }
174
165
 
175
166
  /**
176
- * The body of the draft PR a hand-off leaves behind, whether it opened the PR
177
- * or made an open one a draft: what a human needs from it is the hand-off, not
178
- * a Verdict.
167
+ * The body of the draft pull request a hand-off leaves behind, whether it
168
+ * opened the pull request or made an open one a draft: what a human needs from
169
+ * it is the hand-off, not a verdict.
179
170
  */
180
171
  export function draftPullRequestBody({
181
172
  ticket,
@@ -184,40 +175,89 @@ export function draftPullRequestBody({
184
175
  runId,
185
176
  transcripts,
186
177
  }: DraftPullRequestBody): string {
178
+ const shown = failureShown(failure, "");
187
179
  return [
188
180
  `Closes #${ticket}`,
189
181
  "",
190
- `**Handed off at ${stage}.** ${failure}`,
182
+ `**Handed off at ${stage}.** ${shown.line}`,
191
183
  "",
184
+ ...evidenceBlock(shown.evidence),
192
185
  `See the hand-off comment on #${ticket} for the branch, worktree and evidence.`,
193
186
  "",
194
- runLine(runId, transcripts === undefined ? undefined : keptPlace(transcripts)),
187
+ runLine(runId, transcripts),
195
188
  "",
196
189
  ].join("\n");
197
190
  }
198
191
 
199
192
  /**
200
- * The line both pull request bodies end with: the Run, and where its
201
- * transcripts are when there is somewhere that outlives the Host to point at.
193
+ * A hand-off's failure as one line, and the evidence that goes with it.
194
+ *
195
+ * The failures the pipeline expects already come as one line and their output
196
+ * as evidence. An unexpected error comes as its message whole — the command,
197
+ * how it exited, and everything it printed — so its first line is the failure
198
+ * and the rest is evidence, ahead of any the hand-off carried already.
202
199
  */
203
- function runLine(runId: string, where: string | undefined): string {
204
- const run = `Run \`${runId}\``;
205
- return where === undefined ? run : `${run} · transcripts in ${where}`;
200
+ function failureShown(failure: string, evidence: string): { line: string; evidence: string } {
201
+ const { line, output } = splitMessage(failure);
202
+ return {
203
+ line,
204
+ evidence: [output, evidence.trim()].filter((part) => part !== "").join("\n\n"),
205
+ };
206
+ }
207
+
208
+ /**
209
+ * Evidence folded away and fenced, because it is raw output that would
210
+ * otherwise be read as Markdown; nothing at all when there is none.
211
+ */
212
+ function evidenceBlock(evidence: string): string[] {
213
+ if (evidence === "") return [];
214
+ return ["<details><summary>Evidence</summary>", "", "```", evidence, "```", "", "</details>", ""];
206
215
  }
207
216
 
208
- /** Where a hand-off kept the transcripts, as every shape that names it spells it. */
209
- function keptPlace(transcripts: KeptTranscripts): string {
210
- return `\`${transcripts.path}\` on the \`${transcripts.branch}\` branch`;
217
+ /**
218
+ * Where a hand-off says the Stages' transcripts are: on the remote beside the
219
+ * Ticket's state, or kept off it on the Host, which a workstation outlives and
220
+ * a cloud Host's VM does not. A workstation's directory is named relative to
221
+ * the checkout, so a public comment does not publish the Host's home path.
222
+ */
223
+ export type TranscriptsPlace =
224
+ | ({ on: "remote" } & KeptTranscripts)
225
+ | { on: "workstation"; path: string }
226
+ | { on: "cloud" };
227
+
228
+ /**
229
+ * The line a draft pull request's body ends with: the Run, and where its
230
+ * transcripts are when there are any.
231
+ */
232
+ function runLine(runId: string, transcripts: TranscriptsPlace | undefined): string {
233
+ const run = `Run \`${runId}\``;
234
+ if (transcripts === undefined) return run;
235
+ // A directory is led into with `in`; the cloud Host's phrase names none.
236
+ const lead = transcripts.on === "cloud" ? "transcripts" : "transcripts in";
237
+ return `${run} · ${lead} ${placeOf(transcripts)}`;
238
+ }
239
+
240
+ /** Where the transcripts are, as every shape that names it spells it. */
241
+ function placeOf(transcripts: TranscriptsPlace): string {
242
+ switch (transcripts.on) {
243
+ case "remote":
244
+ return `\`${transcripts.path}\` on the \`${transcripts.branch}\` branch`;
245
+ case "workstation":
246
+ return `\`${transcripts.path}\` on the Host, kept off the remote`;
247
+ case "cloud":
248
+ return "kept off the remote, on the cloud Host, so they go with its VM";
249
+ }
211
250
  }
212
251
 
213
- export interface SquashCommitMessage {
252
+ export interface SquashCommitMessage extends Pick<BranchProse, "problem" | "solution"> {
214
253
  ticket: number;
215
254
  /** The pull request number, appended to the subject as GitHub would. */
216
255
  pullRequest: number;
217
256
  /** The pull request title, which is the subject that lands on the base branch. */
218
257
  title: string;
258
+ /** The verdict the merge is made on, whose unverifiable criteria the body names. */
219
259
  verdict: Verdict;
220
- /** The branch's commit subjects, oldest first. */
260
+ /** The branch's commit subjects, oldest first, which stand in for a solution no Stage answered. */
221
261
  commits: string[];
222
262
  /** Unique `Co-authored-by` values from the branch, carried as trailers. */
223
263
  coAuthors: string[];
@@ -226,37 +266,130 @@ export interface SquashCommitMessage {
226
266
  /**
227
267
  * The commit a merged Ticket leaves on the base branch.
228
268
  *
229
- * `git log` renders no HTML, so this is the one template with nothing folded
230
- * away: the Verdict is counts only, and the per-criterion evidence stays in the
231
- * pull request body where a browser can collapse it.
269
+ * It opens with the problem and the solution a Stage answered, so `git log`
270
+ * says why without the Ticket. Where no Stage answered a solution, the
271
+ * branch's commit subjects say what changed in its place; nothing is made up
272
+ * for either.
273
+ *
274
+ * An unverifiable criterion's reason is kept nowhere on the Ticket, so it is
275
+ * carried here, one line per criterion. `git log` renders no HTML, so nothing
276
+ * is folded away.
232
277
  */
233
278
  export function squashCommit({
234
279
  ticket,
235
280
  pullRequest,
236
281
  title,
282
+ problem,
283
+ solution,
237
284
  verdict,
238
285
  commits,
239
286
  coAuthors,
240
287
  }: SquashCommitMessage): SquashCommit {
241
- // What GitHub's default message would have carried, now carried by hand.
242
- const trailers = coAuthors.map((author) => `Co-authored-by: ${author}`);
288
+ const paragraphs = [
289
+ [`Closes #${ticket}`],
290
+ ...(problem === undefined ? [] : [wrapLines(problem)]),
291
+ solution === undefined ? commits.map((subject) => `- ${subject}`) : wrapLines(solution),
292
+ unverifiedLines(verdict),
293
+ // What GitHub's default message would have carried, now carried by hand.
294
+ coAuthors.map((author) => `Co-authored-by: ${author}`),
295
+ ].filter((lines) => lines.length > 0);
243
296
  return {
244
297
  subject: `${title} (#${pullRequest})`,
245
- body: [
246
- `Closes #${ticket}`,
247
- "",
248
- `Verdict: ${verdictCounts(verdict)}`,
249
- "",
250
- ...commits.map((subject) => `- ${subject}`),
251
- "",
252
- ...(trailers.length === 0 ? [] : [...trailers, ""]),
253
- ].join("\n"),
298
+ body: `${paragraphs.map((lines) => lines.join("\n")).join("\n\n")}\n`,
254
299
  };
255
300
  }
256
301
 
302
+ /** The unverifiable criteria with their evidence on one line each, under a heading; nothing when there are none. */
303
+ function unverifiedLines(verdict: Verdict): string[] {
304
+ const unverifiable = unverifiableLines(verdict);
305
+ return unverifiable.length === 0 ? [] : ["Unverified:", ...unverifiable];
306
+ }
307
+
308
+ /**
309
+ * One `- <criterion> — <evidence>` line per unverifiable criterion, each joined
310
+ * into one line: what the squash commit carries, and what a hand-off on a
311
+ * Target that merges by hand says in its place.
312
+ */
313
+ function unverifiableLines(verdict: Verdict): string[] {
314
+ return verdict.criteria
315
+ .filter((criterion) => criterion.status === "unverifiable")
316
+ .map((criterion) => `- ${oneLine(criterion.text)} — ${oneLine(criterion.evidence)}`);
317
+ }
318
+
319
+ /** Text with its line breaks, and the space around them, joined into single spaces. */
320
+ function oneLine(text: string): string {
321
+ return text.trim().replace(/\s*\n\s*/g, " ");
322
+ }
323
+
324
+ /** How wide a commit body's line may run, as git's own convention has it. */
325
+ const COMMIT_BODY_COLUMNS = 72;
326
+
327
+ /**
328
+ * Prose for a commit body, each line wider than {@link COMMIT_BODY_COLUMNS}
329
+ * broken at its spaces. The lines the Stage wrote stay as they are, so a list
330
+ * stays a list, and a word wider than the limit is left whole.
331
+ */
332
+ export function wrapLines(text: string): string[] {
333
+ return text.split("\n").flatMap((line) => wrapLine(line.trimEnd()));
334
+ }
335
+
336
+ function wrapLine(line: string): string[] {
337
+ if (columns(line) <= COMMIT_BODY_COLUMNS) return [line];
338
+ // A line's indent belongs to its first word, so the break never lands in it.
339
+ const indent = /^\s*/.exec(line)?.[0] ?? "";
340
+ const words = line.slice(indent.length).split(/ +/);
341
+ const lines: string[] = [];
342
+ let current = indent + (words.shift() ?? "");
343
+ for (const word of words) {
344
+ const joined = `${current} ${word}`;
345
+ if (columns(joined) <= COMMIT_BODY_COLUMNS) {
346
+ current = joined;
347
+ } else {
348
+ lines.push(current);
349
+ current = word;
350
+ }
351
+ }
352
+ lines.push(current);
353
+ return lines;
354
+ }
355
+
356
+ /** How many columns a terminal gives `text`: two for a wide character such as Hangul, one for any other. */
357
+ export function columns(text: string): number {
358
+ let width = 0;
359
+ for (const character of text) width += isWide(character.codePointAt(0) ?? 0) ? 2 : 1;
360
+ return width;
361
+ }
362
+
363
+ /** East Asian Wide and Fullwidth code points, the ones a terminal draws two columns wide. */
364
+ const WIDE_RANGES: readonly (readonly [number, number])[] = [
365
+ [0x1100, 0x115f], // Hangul Jamo initial consonants
366
+ [0x2e80, 0x303e], // CJK radicals, Kangxi, CJK symbols and punctuation
367
+ [0x3041, 0x33ff], // Hiragana, Katakana, Bopomofo, Hangul compatibility Jamo, CJK compatibility
368
+ [0x3400, 0x4dbf], // CJK unified ideographs extension A
369
+ [0x4e00, 0x9fff], // CJK unified ideographs
370
+ [0xa000, 0xa4cf], // Yi
371
+ [0xa960, 0xa97f], // Hangul Jamo extended A
372
+ [0xac00, 0xd7a3], // Hangul syllables
373
+ [0xf900, 0xfaff], // CJK compatibility ideographs
374
+ [0xfe30, 0xfe4f], // CJK compatibility forms
375
+ [0xff00, 0xff60], // Fullwidth forms
376
+ [0xffe0, 0xffe6], // Fullwidth signs
377
+ [0x1f300, 0x1f64f], // Pictographs and emoticons
378
+ [0x1f680, 0x1f6ff], // Transport and map symbols
379
+ [0x1f900, 0x1f9ff], // Supplemental pictographs
380
+ [0x20000, 0x3fffd], // CJK unified ideographs extensions B onwards
381
+ ];
382
+
383
+ function isWide(codePoint: number): boolean {
384
+ return WIDE_RANGES.some(([low, high]) => codePoint >= low && codePoint <= high);
385
+ }
386
+
257
387
  export interface HandoffComment {
258
388
  stage: FailurePoint;
259
- /** One line a human can read in a notification. */
389
+ /**
390
+ * One line a human can read in a notification, or an unexpected error's
391
+ * whole message, whose first line is shown here and the rest as evidence.
392
+ */
260
393
  failure: string;
261
394
  branch: string;
262
395
  /**
@@ -275,48 +408,104 @@ export interface HandoffComment {
275
408
  evidence: string;
276
409
  /** Whether the Ticket's fix budget had already been spent when this failure came. */
277
410
  fixUsed?: boolean;
278
- /** Where the Stages' transcripts were kept on the remote, when any were. */
279
- transcripts?: KeptTranscripts;
411
+ /** Where the Stages' transcripts are, when there are any. */
412
+ transcripts?: TranscriptsPlace;
413
+ /**
414
+ * Why the Stage this hand-off is for committed nothing, as it answered it in
415
+ * `noCommitReason`. Set only for an implement or fix Stage that finished and
416
+ * left no new commit, which is the one hand-off the reason explains.
417
+ */
418
+ reason?: string;
280
419
  }
281
420
 
282
421
  export function handoffComment(handoff: HandoffComment): string {
283
- const location = [
284
- `Branch \`${handoff.branch}\`${handoff.onRemote === true ? " on the remote" : ""}`,
285
- ...(handoff.worktree === undefined ? [] : [`worktree \`${handoff.worktree}\``]),
286
- ...(handoff.pullRequest === undefined ? [] : [`PR #${handoff.pullRequest} (draft)`]),
287
- ].join(" · ");
422
+ const location = whereTheWorkIs(
423
+ handoff,
424
+ handoff.pullRequest === undefined ? undefined : `PR #${handoff.pullRequest} (draft)`,
425
+ );
288
426
 
289
427
  // The budget clause is the difference between one bad Stage and a Ticket the
290
428
  // pipeline already had a second go at, which is what a human needs to know.
291
429
  const budget = handoff.fixUsed ? ", after the fix budget was used" : "";
292
430
 
293
- const lines = [
431
+ const shown = failureShown(handoff.failure, handoff.evidence);
432
+ return [
294
433
  HANDOFF_MARKER,
295
434
  `**Handed off.** Failed at **${handoff.stage}**${budget}.`,
296
435
  "",
297
- `- Failure: ${handoff.failure}`,
436
+ `- Failure: ${shown.line}`,
298
437
  `- ${location}`,
299
438
  ...(handoff.transcripts === undefined
300
439
  ? []
301
- : [`- Transcripts: ${keptPlace(handoff.transcripts)}`]),
440
+ : [`- Transcripts: ${placeOf(handoff.transcripts)}`]),
302
441
  "",
303
- ];
442
+ ...stageSaid(handoff.stage, handoff.reason),
443
+ ...evidenceBlock(shown.evidence),
444
+ ].join("\n");
445
+ }
304
446
 
305
- const evidence = handoff.evidence.trim();
306
- if (evidence !== "") {
307
- lines.push(
308
- "<details><summary>Evidence</summary>",
309
- "",
310
- "```",
311
- evidence,
312
- "```",
313
- "",
314
- "</details>",
315
- "",
316
- );
317
- }
447
+ /** The branch, the worktree and the pull request, as one line of a hand-off comment says them. */
448
+ function whereTheWorkIs(
449
+ { branch, onRemote, worktree }: Pick<HandoffComment, "branch" | "onRemote" | "worktree">,
450
+ pullRequest: string | undefined,
451
+ ): string {
452
+ return [
453
+ `Branch \`${branch}\`${onRemote === true ? " on the remote" : ""}`,
454
+ ...(worktree === undefined ? [] : [`worktree \`${worktree}\``]),
455
+ ...(pullRequest === undefined ? [] : [pullRequest]),
456
+ ].join(" · ");
457
+ }
458
+
459
+ /** Why a Ticket handed off on a Target that merges by hand was handed off, in the words its row and log line give. */
460
+ export const LEFT_TO_HUMAN = "left to a human, as this Target merges by hand";
461
+
462
+ export interface MergeByHandComment extends Pick<HandoffComment, "branch" | "onRemote" | "worktree"> {
463
+ /** The pull request a human is to merge, published ready for review. */
464
+ pullRequest: number;
465
+ /** The verdict the Ticket passed on, whose unverifiable criteria the comment lists. */
466
+ verdict: Verdict;
467
+ }
468
+
469
+ /**
470
+ * The hand-off of a Ticket that passed every gate on a Target that merges by
471
+ * hand: nothing failed, so there is no failure line and no evidence block, and
472
+ * the pull request is no draft.
473
+ *
474
+ * The unverifiable criteria and their evidence are what the squash commit
475
+ * would have carried, had the pipeline merged. A human merging by hand gets
476
+ * GitHub's own message instead, so they are said here, where that human reads
477
+ * them. They are posted on the Ticket, whose comments are read for Acceptance
478
+ * Criteria, so a line that could read as a checkbox is defused.
479
+ */
480
+ export function mergeByHandComment(handoff: MergeByHandComment): string {
481
+ const unverifiable = unverifiableLines(handoff.verdict);
482
+ return [
483
+ HANDOFF_MARKER,
484
+ `**Handed off.** PR #${handoff.pullRequest} passed every gate and waits for a human to merge it: this Target merges by hand.`,
485
+ "",
486
+ `- ${whereTheWorkIs(handoff, `PR #${handoff.pullRequest}`)}`,
487
+ ...(unverifiable.length === 0
488
+ ? []
489
+ : [
490
+ "",
491
+ "**Unverifiable criteria:**",
492
+ "",
493
+ ...unverifiable.map(escapeCheckboxes),
494
+ ]),
495
+ ].join("\n");
496
+ }
318
497
 
319
- return lines.join("\n");
498
+ /**
499
+ * The reason a Stage gave for committing nothing, as a paragraph of its own
500
+ * between the hand-off's lines and its folded evidence, so a human reads it
501
+ * without unfolding anything; nothing when it gave none.
502
+ *
503
+ * The Stage's prose is posted on the Ticket, whose comments are read for
504
+ * Acceptance Criteria, so its checkboxes are defused as a Note's are.
505
+ */
506
+ function stageSaid(stage: FailurePoint, reason: string | undefined): string[] {
507
+ if (reason === undefined || reason.trim() === "") return [];
508
+ return [`**The ${stage} Stage said:** ${escapeCheckboxes(reason.trim())}`, ""];
320
509
  }
321
510
 
322
511
  /**
@@ -368,21 +557,22 @@ export interface NoteSubject {
368
557
  because?: string;
369
558
  }
370
559
 
371
- /** {@link UNCHECKED_BOX}, over every line of a Note rather than the first. */
372
- const NOTE_CHECKBOX = new RegExp(UNCHECKED_BOX, "gm");
560
+ /** {@link UNCHECKED_BOX}, over every line of a Stage's prose rather than the first. */
561
+ const PROSE_CHECKBOX = new RegExp(UNCHECKED_BOX, "gm");
373
562
 
374
563
  /**
375
- * One part of a Note's prose, with every checkbox defused.
564
+ * A Stage's prose — one part of a Note, or the reason it gave for committing
565
+ * nothing — with every checkbox defused.
376
566
  *
377
567
  * `- [ ]` is Acceptance Criteria to everything that reads a Ticket: the
378
568
  * `no-criteria` guard counts one as a usable Ticket, verify grades it, and the
379
- * merge ticks it. A Note is prose a human should read, not work anyone
569
+ * merge ticks it. A Stage's prose is for a human to read, not work anyone
380
570
  * promised, so its boxes are escaped into the text they were meant to be.
381
571
  * Brackets anywhere but at the head of a list item are left alone, because that
382
572
  * is the only shape those readers recognise.
383
573
  */
384
- function escapeCheckboxes(note: string): string {
385
- return note.replaceAll(NOTE_CHECKBOX, (_, bullet: string) => `${bullet}\\[ \\]`);
574
+ function escapeCheckboxes(prose: string): string {
575
+ return prose.replaceAll(PROSE_CHECKBOX, (_, bullet: string) => `${bullet}\\[ \\]`);
386
576
  }
387
577
 
388
578
  /**
@@ -426,14 +616,28 @@ export function noteComment(subject: NoteSubject): string {
426
616
  return [NOTE_MARKER, noteProvenance(subject), "", paragraphs.join("\n\n"), ""].join("\n");
427
617
  }
428
618
 
429
- /** A Check the Base branch fails, as the pipeline's own Note reports it. */
619
+ /**
620
+ * How the Ticket's own branch failed, before the merge-base was graded: a Check
621
+ * in its worktree, or CI on its pull request.
622
+ */
623
+ export type BranchFailure =
624
+ | { point: "checks"; command: string; output: string; timedOut: boolean }
625
+ | {
626
+ point: "ci";
627
+ /** Which checks went red, as CI reported them. */
628
+ summary: string;
629
+ /** The tail of the failing jobs' logs, which a fix Stage would be handed; empty when none had one. */
630
+ excerpt: string;
631
+ };
632
+
633
+ /** A Check the base branch fails, as the pipeline's own Note reports it. */
430
634
  export interface FailingBaseNote {
431
635
  /** The Ticket the failure released. */
432
636
  origin: number;
433
- /** Where the Ticket's branch failed: its Checks, or CI on its pull request. */
434
- point: "checks" | "ci";
637
+ /** How the Ticket's branch failed, which the Note quotes beside the merge-base's output. */
638
+ onBranch: BranchFailure;
435
639
  baseBranch: string;
436
- /** The Ticket's branch, whose merge-base with the Base branch `commit` is. */
640
+ /** The Ticket's branch, whose merge-base with the base branch `commit` is. */
437
641
  branch: string;
438
642
  /** The merge-base, in full, so it can be checked out as it is. */
439
643
  commit: string;
@@ -444,43 +648,72 @@ export interface FailingBaseNote {
444
648
 
445
649
  /** The pipeline's Note's summary, which is also the Run summary's `noted` row. */
446
650
  export function failingBaseSummary(baseBranch: string, command: string): string {
447
- return `The Base branch \`${baseBranch}\` fails \`${command}\`.`;
651
+ return `The base branch \`${baseBranch}\` fails \`${command}\`.`;
448
652
  }
449
653
 
450
654
  /**
451
- * The one Note no Stage writes: a Ticket was released because the Base branch
452
- * fails the Check its branch failed, so the defect is the Base branch's and a
655
+ * The one Note no Stage writes: a Ticket was released because the base branch
656
+ * fails the Check its branch failed, so the defect is the base branch's and a
453
657
  * human has to mend it there.
454
658
  *
455
659
  * Signed and laid out as a Stage's Note is, so triage reads it the same way,
456
660
  * with the provenance naming the pipeline rather than a Stage. The tail of the
457
661
  * output is the one a CI log excerpt keeps, so long lines cannot push the Note
458
- * past what GitHub takes in a comment. It is fenced with more backticks than
459
- * any run of them inside it, so a fence the output prints cannot close it early.
662
+ * past what GitHub takes in a comment.
663
+ *
664
+ * The branch's own failure is quoted beside it, because only the command is
665
+ * compared: a branch that fails the command differently is released all the
666
+ * same, and its failure would otherwise be nowhere a human can read it. For CI
667
+ * that is the failing jobs' logs as a fix Stage would be handed them, which are
668
+ * tails already.
460
669
  */
461
670
  export function failingBaseNote(note: FailingBaseNote): string {
462
- const { baseBranch, branch, commit, command } = note;
463
- const tail = logTail(note.output);
671
+ const { baseBranch, branch, commit, command, onBranch } = note;
464
672
  const where = `\`${command}\` ${note.timedOut ? "timed out" : "failed"} in a clean worktree at ${commit}, the merge-base of \`${branch}\` with \`${baseBranch}\`.`;
465
- const fence = "`".repeat(Math.max(3, ...[...tail.matchAll(/`+/g)].map(([run]) => run.length + 1)));
466
- const evidence =
467
- tail === ""
468
- ? `**Evidence**: ${where} It printed nothing.`
469
- : `**Evidence**: ${where} The tail of its output:\n\n${fence}\n${escapeCheckboxes(tail)}\n${fence}`;
673
+ const opening = "The branch's own failure, which need not be the same:";
674
+ const branchPart =
675
+ onBranch.point === "checks"
676
+ ? quoted(
677
+ `${opening} \`${onBranch.command}\` ${onBranch.timedOut ? "timed out" : "failed"} on \`${branch}\`.`,
678
+ "The tail of the branch's output:",
679
+ logTail(onBranch.output),
680
+ "It printed nothing.",
681
+ )
682
+ : quoted(
683
+ `${opening} CI on the pull request from \`${branch}\` reported ${onBranch.summary}.`,
684
+ "The tail of the failing jobs' logs:",
685
+ onBranch.excerpt.trim(),
686
+ "No failing job had a log to quote.",
687
+ );
470
688
  return [
471
689
  NOTE_MARKER,
472
- `From the pipeline, releasing #${note.origin} at ${note.point}`,
690
+ `From the pipeline, releasing #${note.origin} at ${onBranch.point}`,
473
691
  "",
474
692
  [
475
693
  `**${failingBaseSummary(baseBranch, command)}**`,
476
- evidence,
477
- `**Impact**: every Ticket whose branch inherits ${commit} fails the same Check. #${note.origin} was released with its Fix budget as it was, and the Run claimed no more Tickets.`,
478
- `**Next**: mend \`${command}\` on \`${baseBranch}\`. The next Run takes the released Tickets up again from their State files, rebased onto \`${baseBranch}\` before their Checks.`,
694
+ `**Evidence**: ${quoted(where, "The tail of its output:", logTail(note.output), "It printed nothing.")}`,
695
+ branchPart,
696
+ `**Impact**: every Ticket whose branch inherits ${commit} fails the same Check. #${note.origin} was released with its fix budget as it was, and the Run claimed no more Tickets.`,
697
+ `**Next**: mend \`${command}\` on \`${baseBranch}\`. The next Run takes the released Tickets up again from their state files, rebased onto \`${baseBranch}\` before their Checks.`,
479
698
  ].join("\n\n"),
480
699
  "",
481
700
  ].join("\n");
482
701
  }
483
702
 
703
+ /**
704
+ * A sentence of the pipeline's own and the output it introduces, or `ifEmpty`
705
+ * in place of the introduction when there was no output.
706
+ *
707
+ * The output is fenced with more backticks than any run of them inside it, so a
708
+ * fence the output prints cannot close it early, and only the output has its
709
+ * checkboxes escaped, since the words around it are the pipeline's.
710
+ */
711
+ function quoted(sentence: string, introduction: string, output: string, ifEmpty: string): string {
712
+ if (output === "") return `${sentence} ${ifEmpty}`;
713
+ const fence = "`".repeat(Math.max(3, ...[...output.matchAll(/`+/g)].map(([run]) => run.length + 1)));
714
+ return `${sentence} ${introduction}\n\n${fence}\n${escapeCheckboxes(output)}\n${fence}`;
715
+ }
716
+
484
717
  /** Whether an issue's body says it is the standing Notes issue. */
485
718
  export function isNotesIssue(body: string): boolean {
486
719
  return carriesMarker(body, NOTES_ISSUE_MARKER);
@@ -503,7 +736,7 @@ export function notesIssue(): { title: string; body: string } {
503
736
  "**Notes from the pipeline.** Every finding a Stage could not post on a " +
504
737
  "Ticket arrives here as a comment: one that named no Ticket, one whose " +
505
738
  "Ticket would have buried it, and one whose Ticket refused the comment. " +
506
- "So does the pipeline's own Note about a Base branch that fails a Check. " +
739
+ "So does the pipeline's own Note about a base branch that fails a Check. " +
507
740
  "Each comment says which Ticket and Stage, or the pipeline, found it.",
508
741
  "",
509
742
  "Triage empties this issue by hand: promote what deserves a Ticket, record " +
@@ -516,7 +749,7 @@ export function notesIssue(): { title: string; body: string } {
516
749
  }
517
750
 
518
751
  export interface RunSummary {
519
- /** The Version the Run ran, which is what its transcripts are stamped with. */
752
+ /** The version the Run ran, which is what its transcripts are stamped with. */
520
753
  version: string;
521
754
  runId: string;
522
755
  durationMs: number;
@@ -524,13 +757,13 @@ export interface RunSummary {
524
757
  credential: Credential;
525
758
  outcomes: TicketOutcome[];
526
759
  /**
527
- * What the Run's Stages said they were billed: the Spend or extra usage its
760
+ * What the Run's Stages said they were billed: the spend or extra usage its
528
761
  * header gives, and every Stage that said it ran on something else, each
529
762
  * named in a row after its own Ticket's.
530
763
  */
531
764
  billing?: Billing;
532
765
  /**
533
- * The line saying a newer Version is out, where one is. Above the header
766
+ * The line saying a newer version is out, where one is. Above the header
534
767
  * rather than below it: the Run already said this hours ago, at the top of a
535
768
  * log this summary is the bottom of (ADR-0007).
536
769
  */
@@ -540,16 +773,19 @@ export interface RunSummary {
540
773
  }
541
774
 
542
775
  /**
543
- * What a Release is put down to, in the words the Run summary and the log
544
- * share: the rate limit, a transient API failure, an API key out of credit or
545
- * past its spend limit, or a Base branch that fails the Check the Ticket's
546
- * branch failed.
776
+ * What a Release is put down to, in the words the Run summary, the log and
777
+ * the progress comment share: the rate limit, a transient API failure, an API
778
+ * key out of credit or past its spend limit, a base branch that fails the
779
+ * Check the Ticket's branch failed, or GitHub or the git remote failing on its
780
+ * own side.
547
781
  */
548
782
  export const RELEASE_WORDS: Record<ReleaseCause, string> = {
549
783
  "rate-limited": "rate limit",
550
784
  "api-error": "API failure",
551
785
  "out-of-budget": "out of API budget",
552
- "failing-base": "failing Base branch",
786
+ "failing-base": "failing base branch",
787
+ github: "GitHub failure",
788
+ remote: "remote unreachable",
553
789
  };
554
790
 
555
791
  /**
@@ -569,7 +805,7 @@ const VERB_WIDTH = 9;
569
805
  /**
570
806
  * What a Run prints when it ends. One line per Ticket, then why the Run
571
807
  * stopped — the Frontier is empty, everything left on it is blocked, the rate
572
- * limit, a transient API failure, the API key's budget or a failing Base branch
808
+ * limit, a transient API failure, the API key's budget or a failing base branch
573
809
  * released a Ticket and the Run went no further, or a human stopped it.
574
810
  */
575
811
  export function runSummary({
@@ -607,7 +843,7 @@ export function runSummary({
607
843
 
608
844
  /**
609
845
  * What the header says the Run's Stages were billed to. An `--api-key` Run
610
- * adds its Spend, ending `+` where a Stage on the key reported no figure, so it
846
+ * adds its spend, ending `+` where a Stage on the key reported no figure, so it
611
847
  * is at least that much. A subscription Run adds no amount, since its figure
612
848
  * is an estimate at API prices and not money spent, only whether a Stage ran
613
849
  * on the plan's extra usage.
@@ -652,6 +888,11 @@ function lastLine(stop: RunStop, credential: Credential): string {
652
888
  return "Out of API budget.";
653
889
  case "failing-base":
654
890
  return `Base branch \`${stop.baseBranch}\` fails \`${stop.command}\` at ${stop.commit.slice(0, 7)}.`;
891
+ // What failed and what it said, because the human may have to act: an
892
+ // authentication failure mends only with a key or a login.
893
+ case "github":
894
+ case "remote":
895
+ return `${capitalised(RELEASE_WORDS[stop.reason])} · \`${stop.command}\` · ${stop.line}`;
655
896
  case "stopped":
656
897
  return `Stopped at ${clockTime(stop.at)} · ${holding(stop.busy)}.`;
657
898
  case "frontier":
@@ -659,6 +900,11 @@ function lastLine(stop: RunStop, credential: Credential): string {
659
900
  }
660
901
  }
661
902
 
903
+ /** `words` opening a line. */
904
+ function capitalised(words: string): string {
905
+ return `${words.charAt(0).toUpperCase()}${words.slice(1)}`;
906
+ }
907
+
662
908
  /**
663
909
  * The minute a Stop arrived, in UTC — the clock the run id on the first line of
664
910
  * the summary is already written in, so the two can be read against each other.
@@ -694,11 +940,6 @@ function ticketRows(outcome: TicketOutcome, credential: Credential): string[] {
694
940
  ];
695
941
  }
696
942
 
697
- /** A Note summary's opening line, which is as much of it as a Run summary has room for. */
698
- function firstLine(text: string): string {
699
- return (text.split("\n").find((line) => line.trim() !== "") ?? "").trim();
700
- }
701
-
702
943
  /** `text`, or as much of it as fits with an ellipsis standing in for the rest. */
703
944
  function truncate(text: string, limit: number): string {
704
945
  return text.length <= limit ? text : `${text.slice(0, limit - 1).trimEnd()}\u2026`;
@@ -717,10 +958,13 @@ function noteRow({ origin, stage, issue, opened, summary }: RoutedNote): string
717
958
  return row(
718
959
  "noted",
719
960
  issue,
720
- `${destination} · from #${origin} ${stage} · ${truncate(firstLine(summary), NOTE_WIDTH)}`,
961
+ `${destination} · from #${origin} ${stage} · ${truncate(splitMessage(summary).line, NOTE_WIDTH)}`,
721
962
  );
722
963
  }
723
964
 
965
+ /** What a `handed` row says of a hand-off a fault outside the Ticket cut short. */
966
+ const CUT_SHORT = "hand-off cut short";
967
+
724
968
  /** One Ticket's line in a summary: what happened to it, and where to look. */
725
969
  function ticketRow(outcome: TicketOutcome, credential: Credential): string {
726
970
  switch (outcome.outcome) {
@@ -730,7 +974,12 @@ function ticketRow(outcome: TicketOutcome, credential: Credential): string {
730
974
  return row(
731
975
  "handed",
732
976
  outcome.ticket,
733
- `${outcome.title} · ${outcome.stage} · ${outcome.failure}`,
977
+ // The one line of an unexpected error; its output is the hand-off's.
978
+ `${outcome.title} · ${outcome.stage} · ${splitMessage(outcome.failure).line}` +
979
+ // A hand-off the fault cut short says so, since a human finishes it.
980
+ (outcome.fault === undefined
981
+ ? ""
982
+ : ` · ${CUT_SHORT} · ${releaseWords(outcome.fault.side, credential)}`),
734
983
  );
735
984
  case "released":
736
985
  // Nothing for a human to do, so the row says only what stopped the Stage