ticket-runner 0.6.1 → 0.6.2

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.
package/src/templates.ts CHANGED
@@ -7,8 +7,9 @@ import { UNCHECKED_BOX } from "./acceptance-criteria.js";
7
7
  import type { GuardReason } from "./guards.js";
8
8
  import type { HostKind } from "./host.js";
9
9
  import type { FailurePoint } from "./lifecycle.js";
10
+ import { logTail } from "./log-tail.js";
10
11
  import type { NoteText, NotingStage, RoutedNote } from "./notes.js";
11
- import type { TicketOutcome } from "./orchestrator.js";
12
+ import type { ReleaseCause, TicketOutcome } from "./orchestrator.js";
12
13
  import type { IssueComment, SquashCommit } from "./ports/tracker.js";
13
14
  import type { KeptTranscripts } from "./ports/workspace.js";
14
15
  import type { RunStop } from "./run.js";
@@ -418,6 +419,61 @@ export function noteComment(subject: NoteSubject): string {
418
419
  return [NOTE_MARKER, noteProvenance(subject), "", paragraphs.join("\n\n"), ""].join("\n");
419
420
  }
420
421
 
422
+ /** A Check the Base branch fails, as the pipeline's own Note reports it. */
423
+ export interface FailingBaseNote {
424
+ /** The Ticket the failure released. */
425
+ origin: number;
426
+ /** Where the Ticket's branch failed: its Checks, or CI on its pull request. */
427
+ point: "checks" | "ci";
428
+ baseBranch: string;
429
+ /** The Ticket's branch, whose merge-base with the Base branch `commit` is. */
430
+ branch: string;
431
+ /** The merge-base, in full, so it can be checked out as it is. */
432
+ commit: string;
433
+ command: string;
434
+ output: string;
435
+ timedOut: boolean;
436
+ }
437
+
438
+ /** The pipeline's Note's summary, which is also the Run summary's `noted` row. */
439
+ export function failingBaseSummary(baseBranch: string, command: string): string {
440
+ return `The Base branch \`${baseBranch}\` fails \`${command}\`.`;
441
+ }
442
+
443
+ /**
444
+ * The one Note no Stage writes: a Ticket was released because the Base branch
445
+ * fails the Check its branch failed, so the defect is the Base branch's and a
446
+ * human has to mend it there.
447
+ *
448
+ * Signed and laid out as a Stage's Note is, so triage reads it the same way,
449
+ * with the provenance naming the pipeline rather than a Stage. The tail of the
450
+ * output is the one a CI log excerpt keeps, so long lines cannot push the Note
451
+ * past what GitHub takes in a comment. It is fenced with more backticks than
452
+ * any run of them inside it, so a fence the output prints cannot close it early.
453
+ */
454
+ export function failingBaseNote(note: FailingBaseNote): string {
455
+ const { baseBranch, branch, commit, command } = note;
456
+ const tail = logTail(note.output);
457
+ const where = `\`${command}\` ${note.timedOut ? "timed out" : "failed"} in a clean worktree at ${commit}, the merge-base of \`${branch}\` with \`${baseBranch}\`.`;
458
+ const fence = "`".repeat(Math.max(3, ...[...tail.matchAll(/`+/g)].map(([run]) => run.length + 1)));
459
+ const evidence =
460
+ tail === ""
461
+ ? `**Evidence**: ${where} It printed nothing.`
462
+ : `**Evidence**: ${where} The tail of its output:\n\n${fence}\n${escapeCheckboxes(tail)}\n${fence}`;
463
+ return [
464
+ NOTE_MARKER,
465
+ `From the pipeline, releasing #${note.origin} at ${note.point}`,
466
+ "",
467
+ [
468
+ `**${failingBaseSummary(baseBranch, command)}**`,
469
+ evidence,
470
+ `**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.`,
471
+ `**Next**: mend \`${command}\` on \`${baseBranch}\`. The next Run takes the released Tickets up again from their State files, rebased onto \`${baseBranch}\` before their Checks.`,
472
+ ].join("\n\n"),
473
+ "",
474
+ ].join("\n");
475
+ }
476
+
421
477
  /** Whether an issue's body says it is the standing Notes issue. */
422
478
  export function isNotesIssue(body: string): boolean {
423
479
  return carriesMarker(body, NOTES_ISSUE_MARKER);
@@ -440,7 +496,8 @@ export function notesIssue(): { title: string; body: string } {
440
496
  "**Notes from the pipeline.** Every finding a Stage could not post on a " +
441
497
  "Ticket arrives here as a comment: one that named no Ticket, one whose " +
442
498
  "Ticket would have buried it, and one whose Ticket refused the comment. " +
443
- "Each comment says which Ticket and Stage found it.",
499
+ "So does the pipeline's own Note about a Base branch that fails a Check. " +
500
+ "Each comment says which Ticket and Stage, or the pipeline, found it.",
444
501
  "",
445
502
  "Triage empties this issue by hand: promote what deserves a Ticket, record " +
446
503
  "the promotion in this body, and close the issue once the body accounts " +
@@ -467,13 +524,25 @@ export interface RunSummary {
467
524
  stop: RunStop;
468
525
  }
469
526
 
527
+ /**
528
+ * What a Release is put down to, in the words the Run summary and the log
529
+ * share: the subscription rate limit, a transient API failure, or a Base
530
+ * branch that fails the Check the Ticket's branch failed.
531
+ */
532
+ export const RELEASE_WORDS: Record<ReleaseCause, string> = {
533
+ "rate-limited": "rate limit",
534
+ "api-error": "API failure",
535
+ "failing-base": "failing Base branch",
536
+ };
537
+
470
538
  /** Every summary row is `<verb> #<n> <detail>`, so the numbers line up. */
471
539
  const VERB_WIDTH = 9;
472
540
 
473
541
  /**
474
542
  * What a Run prints when it ends. One line per Ticket, then why the Run
475
543
  * stopped — the Frontier is empty, everything left on it is blocked, the rate
476
- * limit released a Ticket and the Run went no further, or a human stopped it.
544
+ * limit, a transient API failure or a failing Base branch released a Ticket and
545
+ * the Run went no further, or a human stopped it.
477
546
  */
478
547
  export function runSummary({
479
548
  version,
@@ -507,7 +576,13 @@ export function runSummary({
507
576
  function lastLine(stop: RunStop): string {
508
577
  switch (stop.reason) {
509
578
  case "rate-limited":
510
- return "Rate limited.";
579
+ return stop.resetsAt === undefined
580
+ ? "Rate limited."
581
+ : `Rate limited · resets ${utcMinute(stop.resetsAt)}.`;
582
+ case "api-error":
583
+ return "API failure.";
584
+ case "failing-base":
585
+ return `Base branch \`${stop.baseBranch}\` fails \`${stop.command}\` at ${stop.commit.slice(0, 7)}.`;
511
586
  case "stopped":
512
587
  return `Stopped at ${clockTime(stop.at)} · ${holding(stop.busy)}.`;
513
588
  case "frontier":
@@ -523,6 +598,14 @@ function clockTime(at: string): string {
523
598
  return at.slice(11, 16);
524
599
  }
525
600
 
601
+ /**
602
+ * The date and minute a limit resets, in UTC like the Stop's clock time. The
603
+ * date is kept because a weekly limit can reset days after the Run stopped.
604
+ */
605
+ function utcMinute(at: string): string {
606
+ return `${at.slice(0, 10)} ${at.slice(11, 16)} UTC`;
607
+ }
608
+
526
609
  /** What the Lanes were holding when the Stop arrived, and what to call none. */
527
610
  function holding(busy: number[]): string {
528
611
  if (busy.length === 0) return "nothing to finish";
@@ -581,9 +664,13 @@ function ticketRow(outcome: TicketOutcome): string {
581
664
  `${outcome.title} · ${outcome.stage} · ${outcome.failure}`,
582
665
  );
583
666
  case "released":
584
- // Nothing for a human to do, so the row says only where the limit landed
585
- // and leaves the rest to the Run that resumes the Ticket.
586
- return row("released", outcome.ticket, `${outcome.title} · rate limit at ${outcome.stage}`);
667
+ // Nothing for a human to do, so the row says only what stopped the Stage
668
+ // and where, and leaves the rest to the Run that resumes the Ticket.
669
+ return row(
670
+ "released",
671
+ outcome.ticket,
672
+ `${outcome.title} · ${RELEASE_WORDS[outcome.cause]} at ${outcome.stage}`,
673
+ );
587
674
  case "skipped":
588
675
  // The reason is the guard's own word for it, which is also the marker on
589
676
  // the warning comment the human is being pointed at.
package/src/title.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * rewriting it.
11
11
  */
12
12
 
13
- import { NOTES_LIST_SCHEMA } from "./note-schema.js";
13
+ import { CODE_STAGE_NOTES_LIST_SCHEMA } from "./note-schema.js";
14
14
 
15
15
  /**
16
16
  * What a title is asked to be, in the words both the schema and the prompts of
@@ -41,7 +41,7 @@ export const CODE_STAGE_JSON_SCHEMA = {
41
41
  type: "string",
42
42
  description: `Write ${BRANCH_TITLE}: \`<type>(<scope>): <summary>\`, without the \`(#<n>)\`. It titles the pull request and the squash commit that lands.`,
43
43
  },
44
- notes: NOTES_LIST_SCHEMA,
44
+ notes: CODE_STAGE_NOTES_LIST_SCHEMA,
45
45
  },
46
46
  required: ["title", "notes"],
47
47
  additionalProperties: false,