@davidbyoung/software-factory 0.1.11 → 0.1.12

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 (56) hide show
  1. package/agents/factory-e2e-reviewer.md +1 -1
  2. package/agents/factory-test-reviewer.md +1 -1
  3. package/agents/factory-ui-reviewer.md +2 -2
  4. package/dist/board.d.mts +7 -7
  5. package/dist/board.mjs +50 -33
  6. package/dist/build.d.mts +4 -0
  7. package/dist/build.mjs +9 -4
  8. package/dist/cli.mjs +8 -1
  9. package/dist/code-host/github.mjs +9 -4
  10. package/dist/code-host/types.d.mts +4 -2
  11. package/dist/commands.d.mts +1 -1
  12. package/dist/commands.mjs +15 -6
  13. package/dist/lib/clock.d.mts +3 -1
  14. package/dist/lib/clock.mjs +12 -6
  15. package/dist/lib/pull-tickets.d.mts +15 -0
  16. package/dist/lib/pull-tickets.mjs +12 -0
  17. package/dist/lib/usage.d.mts +3 -1
  18. package/dist/lib/usage.mjs +4 -2
  19. package/dist/lib/work-status.d.mts +23 -19
  20. package/dist/lib/work-status.mjs +14 -27
  21. package/dist/poller.d.mts +3 -3
  22. package/dist/poller.mjs +18 -14
  23. package/dist/pr.d.mts +18 -0
  24. package/dist/pr.mjs +54 -7
  25. package/dist/review-tickets.d.mts +12 -0
  26. package/dist/review-tickets.mjs +59 -0
  27. package/dist/reviewers.d.mts +7 -4
  28. package/dist/reviewers.mjs +19 -12
  29. package/dist/runner/github-actions.mjs +6 -7
  30. package/dist/runner/types.d.mts +7 -6
  31. package/dist/status.d.mts +17 -7
  32. package/dist/status.mjs +35 -23
  33. package/dist/sync.d.mts +4 -0
  34. package/dist/sync.mjs +14 -1
  35. package/dist/ticket.d.mts +13 -7
  36. package/dist/ticket.mjs +94 -60
  37. package/dist/tickets/github.d.mts +10 -2
  38. package/dist/tickets/github.mjs +74 -20
  39. package/dist/tickets/index.d.mts +7 -1
  40. package/dist/tickets/index.mjs +15 -1
  41. package/dist/tickets/types.d.mts +59 -30
  42. package/dist/tickets/types.mjs +13 -3
  43. package/docs/cli.md +11 -7
  44. package/docs/configuration.md +1 -1
  45. package/docs/developing.md +16 -8
  46. package/docs/github/reference.md +1 -1
  47. package/docs/plugins.md +6 -6
  48. package/package.json +1 -1
  49. package/review.md +11 -11
  50. package/rules.md +18 -14
  51. package/skills/factory-address-review/SKILL.md +4 -3
  52. package/skills/factory-build/SKILL.md +25 -19
  53. package/skills/factory-refine/SKILL.md +1 -1
  54. package/skills/factory-resolve-conflicts/SKILL.md +4 -3
  55. package/workflows/factory-build.yml +6 -5
  56. package/workflows/factory-claude-review.yml +38 -1
@@ -97,6 +97,6 @@ A high or medium finding outside the change under review, such as an
97
97
  existing test that cannot fail, is also written as one follow-up line, in
98
98
  the format under "Follow-ups" in `.claude/factory/rules.md`, led by the test's file, so
99
99
  the author can append it as it stands to the follow-ups issue, rather than
100
- open an issue. Write `#N` for the build number; the author fills it in.
100
+ open an issue. Write `TICKET` for the ticket being built; the author fills it in.
101
101
 
102
102
  End with exactly one line: `Verdict: pass` when there is no high or medium finding, or `Verdict: fail, N findings to fix` with N the number of high and medium findings ("1 finding" when there is one). A low finding does not count. Nothing after that line.
@@ -86,6 +86,6 @@ A high or medium finding outside the change under review, such as an
86
86
  existing test that cannot fail, is also written as one follow-up line, in
87
87
  the format under "Follow-ups" in `.claude/factory/rules.md`, led by the test's file, so
88
88
  the author can append it as it stands to the follow-ups issue, rather than
89
- open an issue. Write `#N` for the build number; the author fills it in.
89
+ open an issue. Write `TICKET` for the ticket being built; the author fills it in.
90
90
 
91
91
  End with exactly one line: `Verdict: pass` when there is no high or medium finding, or `Verdict: fail, N findings to fix` with N the number of high and medium findings ("1 finding" when there is one). A low finding does not count. Nothing after that line.
@@ -152,8 +152,8 @@ A finding the builder will leave for the owner, because it needs a decision or
152
152
  is already on the default branch, is also written as one follow-up line, in
153
153
  the format under "Follow-ups" in `.claude/factory/rules.md`, led by the page or
154
154
  file it is about, so the builder can append it to the follow-ups issue as it
155
- stands, rather than open an issue. Write `#N` for the build number; the builder
156
- fills it in.
155
+ stands, rather than open an issue. Write `TICKET` for the ticket being built; the
156
+ builder fills it in.
157
157
 
158
158
  End with exactly one line: `Verdict: pass` when there are no findings, or
159
159
  `Verdict: fail, N findings to fix` with N the number of findings ("1 finding"
package/dist/board.d.mts CHANGED
@@ -3,7 +3,7 @@ import { type Paint } from "./lib/color.mts";
3
3
  import { type Settings } from "./config.mts";
4
4
  import { type Columns, type Board, type BoardField, type Derived, type PullRequest, type RepoSnapshot } from "./lib/work-status.mts";
5
5
  import { type Runner } from "./runner/index.mts";
6
- import { type Ticket, type Tickets, type Write } from "./tickets/types.mts";
6
+ import { type Key, type Links, type Ticket, type Tickets, type Write } from "./tickets/types.mts";
7
7
  export type { Write };
8
8
  /** Which of the board's fields the sync writes, named as the settings name
9
9
  * them; null means never. */
@@ -65,7 +65,7 @@ export declare function boardRows(fields: BoardField[], cfg: BoardConfig, settin
65
65
  * field, under the setting each comes from. */
66
66
  export declare function boardReport(number: number, board: Board, cfg: BoardConfig, settings: Pick<Settings, "builds">, paint?: Paint): string[];
67
67
  export type Plan = {
68
- number: number;
68
+ key: Key;
69
69
  itemId: string | null;
70
70
  derived: Derived;
71
71
  /** The cost markers' sum as subscription dollars, or null when there are
@@ -80,9 +80,9 @@ export type Plan = {
80
80
  * A card's Session is an Actions run's page, which `runPage` gives for its
81
81
  * ID, and any other session as it is. */
82
82
  export declare function planSync(snapshot: RepoSnapshot, board: Board, runPage: (id: string) => string, cfg?: BoardConfig): Plan[];
83
- export declare function logLine(plan: Plan): string;
83
+ export declare function logLine(plan: Plan, ref: (key: Key) => string): string;
84
84
  export type Comment = {
85
- issue: number;
85
+ issue: Key;
86
86
  body: string;
87
87
  };
88
88
  type PullEvent = {
@@ -96,10 +96,10 @@ type PullEvent = {
96
96
  /** The comments a closed pull request calls for: one on each issue it
97
97
  * closes when it was not merged, and one on each open follow-ups issue it
98
98
  * built part of without closing. */
99
- export declare function closedPullComments(event: PullEvent, closes: number[], openFollowUps: number[], columns?: Columns): Comment[];
99
+ export declare function closedPullComments(event: PullEvent, links: Links, openFollowUps: Key[], columns: Columns, ref: (key: Key) => string): Comment[];
100
100
  /** The nightly run's clears: claims and starts over 24 hours old with no
101
101
  * pull request. */
102
- export declare function nightlyComments(snapshot: RepoSnapshot, now: Date, columns?: Columns): Comment[];
102
+ export declare function nightlyComments(snapshot: RepoSnapshot, now: Date, columns: Columns, ref: (key: Key) => string): Comment[];
103
103
  /** What collect saves for apply: the tickets and the pull requests. */
104
104
  export type Saved = {
105
105
  tickets: Ticket[];
@@ -113,7 +113,7 @@ export type PullSource = {
113
113
  costs: boolean;
114
114
  }): Promise<PullRequest[]>;
115
115
  linking(skip: number[]): Promise<PullRequest[]>;
116
- closes(pull: number): Promise<number[]>;
116
+ closes(pull: number): Promise<Key[]>;
117
117
  };
118
118
  export type Deps = {
119
119
  /** The ticket system and the pull requests for the repository and board
package/dist/board.mjs CHANGED
@@ -24,12 +24,13 @@ import { colorOn, painter, plain, } from "./lib/color.mjs";
24
24
  import { readFileSync, writeFileSync } from "node:fs";
25
25
  import { join } from "node:path";
26
26
  import { columnsOf, fieldNamesOf, loadSettings, } from "./config.mjs";
27
- import { DEFAULT_COLUMNS, STATE_KEYS, cardOf, columnFor, columnsFor, sameName, statusOfColumn, commentBody, derive, buildsPartOf, issueCost, toClear, toSnapshot, actionsRunLink, } from "./lib/work-status.mjs";
27
+ import { DEFAULT_COLUMNS, STATE_KEYS, cardOf, columnFor, columnsFor, sameName, statusOfColumn, commentBody, derive, issueCost, toClear, toSnapshot, actionsRunLink, } from "./lib/work-status.mjs";
28
28
  import { subscriptionDollars } from "./lib/pricing.mjs";
29
29
  import { openCodeHost } from "./code-host/index.mjs";
30
30
  import { openRunner } from "./runner/index.mjs";
31
31
  import { toBoard } from "./tickets/github.mjs";
32
- import { openTickets } from "./tickets/index.mjs";
32
+ import { openTickets, refOf } from "./tickets/index.mjs";
33
+ import { linkPulls, ownLinks, ticketsOf } from "./lib/pull-tickets.mjs";
33
34
  import { need, readAll, } from "./tickets/types.mjs";
34
35
  export const DEFAULT_FIELDS = {
35
36
  session: "Session",
@@ -260,14 +261,14 @@ export function planSync(snapshot, board, runPage, cfg = DEFAULT_BOARD) {
260
261
  const everyPull = [...snapshot.pulls, ...(snapshot.donePulls ?? [])];
261
262
  const fields = checkFields(board.fields, cfg);
262
263
  return snapshot.issues.map((issue) => {
263
- const derived = derive(issue, cardOf(board, issue.number, cfg.columns), snapshot.pulls, cfg.columns);
264
+ const derived = derive(issue, cardOf(board, issue.key, cfg.columns), snapshot.pulls, cfg.columns);
264
265
  const listPrice = issueCost(issue, everyPull);
265
266
  const cost = listPrice === null
266
267
  ? null
267
268
  : Math.round(subscriptionDollars(listPrice) * 100) / 100;
268
- const item = board.items.get(issue.number);
269
+ const item = board.items.get(issue.key);
269
270
  const base = {
270
- number: issue.number,
271
+ key: issue.key,
271
272
  itemId: item?.itemId ?? null,
272
273
  derived,
273
274
  cost,
@@ -306,27 +307,29 @@ export function planSync(snapshot, board, runPage, cfg = DEFAULT_BOARD) {
306
307
  return { ...base, writes };
307
308
  });
308
309
  }
309
- export function logLine(plan) {
310
+ export function logLine(plan, ref) {
310
311
  const d = plan.derived;
312
+ const name = ref(plan.key);
311
313
  if (plan.unmapped !== undefined)
312
- return `#${plan.number} card is in "${plan.unmapped}", which no state names (left alone)`;
314
+ return `${name} card is in "${plan.unmapped}", which no state names (left alone)`;
313
315
  const cost = plan.cost === null ? "(empty)" : plan.cost.toFixed(2);
314
316
  const values = `Status=${d.status}, Session=${d.session || "(empty)"}, Runs in=${d.runsIn || "(empty)"}, Cost=${cost}`;
315
317
  if (plan.writes.length === 0)
316
- return `#${plan.number} ${values} (unchanged)`;
318
+ return `${name} ${values} (unchanged)`;
317
319
  const added = plan.itemId ? "" : "added to the board; ";
318
- return `#${plan.number} ${values} (${added}set ${plan.writes.map((w) => w.field).join(", ")})`;
320
+ return `${name} ${values} (${added}set ${plan.writes.map((w) => w.field).join(", ")})`;
319
321
  }
320
322
  /** The comments a closed pull request calls for: one on each issue it
321
323
  * closes when it was not merged, and one on each open follow-ups issue it
322
324
  * built part of without closing. */
323
- export function closedPullComments(event, closes, openFollowUps, columns = DEFAULT_COLUMNS) {
325
+ export function closedPullComments(event, links, openFollowUps, columns, ref) {
324
326
  if (event.action !== "closed")
325
327
  return [];
326
328
  const pull = event.pull_request;
329
+ const { closes } = links;
327
330
  const closedKind = (issue) => ({
328
331
  kind: "pull-closed",
329
- issue,
332
+ issue: { key: issue, ref: ref(issue) },
330
333
  pull: pull.number,
331
334
  });
332
335
  const comments = [];
@@ -334,7 +337,7 @@ export function closedPullComments(event, closes, openFollowUps, columns = DEFAU
334
337
  for (const issue of closes)
335
338
  comments.push({ issue, body: commentBody(closedKind(issue), columns) });
336
339
  for (const followUps of openFollowUps) {
337
- if (closes.includes(followUps) || !buildsPartOf(pull.body ?? "", followUps))
340
+ if (closes.includes(followUps) || !links.partOf.includes(followUps))
338
341
  continue;
339
342
  comments.push({
340
343
  issue: followUps,
@@ -347,21 +350,18 @@ export function closedPullComments(event, closes, openFollowUps, columns = DEFAU
347
350
  }
348
351
  /** The nightly run's clears: claims and starts over 24 hours old with no
349
352
  * pull request. */
350
- export function nightlyComments(snapshot, now, columns = DEFAULT_COLUMNS) {
353
+ export function nightlyComments(snapshot, now, columns, ref) {
351
354
  return snapshot.issues.flatMap((issue) => {
352
355
  const clear = toClear(issue, snapshot.pulls, now);
353
356
  if (!clear)
354
357
  return [];
358
+ const named = { key: issue.key, ref: ref(issue.key) };
355
359
  return [
356
360
  {
357
- issue: issue.number,
361
+ issue: issue.key,
358
362
  body: commentBody(clear.kind === "claim"
359
- ? { kind: "cleared-claim", issue: issue.number, since: clear.since }
360
- : {
361
- kind: "cleared-start",
362
- issue: issue.number,
363
- since: clear.since,
364
- }, columns),
363
+ ? { kind: "cleared-claim", issue: named, since: clear.since }
364
+ : { kind: "cleared-start", issue: named, since: clear.since }, columns),
365
365
  },
366
366
  ];
367
367
  });
@@ -370,19 +370,24 @@ async function postAll(comments, d, dryRun) {
370
370
  for (const c of comments) {
371
371
  const first = c.body.split("\n")[0];
372
372
  if (dryRun) {
373
- d.out(`would comment on #${c.issue}: ${first}`);
373
+ d.out(`would comment on ${d.tickets.ref(c.issue)}: ${first}`);
374
374
  continue;
375
375
  }
376
376
  await d.tickets.comment(c.issue, c.body);
377
- d.out(`commented on #${c.issue}: ${first}`);
377
+ d.out(`commented on ${d.tickets.ref(c.issue)}: ${first}`);
378
378
  }
379
379
  }
380
380
  async function read(d) {
381
- const [tickets, pulls] = await Promise.all([
381
+ const [tickets, open] = await Promise.all([
382
382
  readAll(d.tickets),
383
383
  d.pulls.open({ costs: true }),
384
384
  ]);
385
- const donePulls = await d.pulls.linking(pulls.map((p) => p.number));
385
+ const pulls = linkPulls(open, d.tickets, d.own);
386
+ // Only the code host's own links say which closed pull requests built a
387
+ // ticket.
388
+ const donePulls = d.own
389
+ ? linkPulls(await d.pulls.linking(pulls.map((p) => p.number)), d.tickets, d.own)
390
+ : [];
386
391
  return { tickets, pulls, donePulls };
387
392
  }
388
393
  const snapshotOf = (saved, now) => toSnapshot(saved.tickets, saved.pulls, now, saved.donePulls);
@@ -394,8 +399,12 @@ async function collect(d, opts) {
394
399
  if (event.action === "closed") {
395
400
  const followUps = snapshot.issues
396
401
  .filter((i) => i.state === "open" && i.labels.includes("follow-up"))
397
- .map((i) => i.number);
398
- const comments = closedPullComments(event, await d.pulls.closes(event.pull_request.number), followUps, d.config.columns);
402
+ .map((i) => i.key);
403
+ const links = ticketsOf({
404
+ body: event.pull_request.body ?? "",
405
+ closes: d.own ? await d.pulls.closes(event.pull_request.number) : [],
406
+ }, d.tickets, d.own);
407
+ const comments = closedPullComments(event, links, followUps, d.config.columns, (k) => d.tickets.ref(k));
399
408
  await postAll(comments, d, opts.dryRun);
400
409
  if (comments.length && !opts.dryRun) {
401
410
  saved = await read(d);
@@ -404,7 +413,7 @@ async function collect(d, opts) {
404
413
  }
405
414
  }
406
415
  if (opts.nightly) {
407
- const comments = nightlyComments(snapshot, d.now(), d.config.columns);
416
+ const comments = nightlyComments(snapshot, d.now(), d.config.columns, (k) => d.tickets.ref(k));
408
417
  await postAll(comments, d, opts.dryRun);
409
418
  if (comments.length && !opts.dryRun)
410
419
  saved = await read(d);
@@ -422,10 +431,10 @@ async function apply(saved, board, d, write) {
422
431
  d.out(`${line.label} ${line.text}`);
423
432
  const plans = planSync(snapshotOf(saved, d.now()), board, d.runPage, d.config);
424
433
  for (const plan of plans) {
425
- d.out(logLine(plan));
434
+ d.out(logLine(plan, d.ref));
426
435
  if (!write || plan.writes.length === 0)
427
436
  continue;
428
- const itemId = plan.itemId ?? (await write.add(plan.number));
437
+ const itemId = plan.itemId ?? (await write.add(plan.key));
429
438
  await write.set(itemId, plan.writes);
430
439
  }
431
440
  }
@@ -455,6 +464,7 @@ export async function main(argv, deps) {
455
464
  const repository = deps.env.GITHUB_REPOSITORY || settings.repository;
456
465
  const runner = deps.runner(repository, settings.builds.runner);
457
466
  const runPage = (id) => runner.runPage(id);
467
+ const ref = refOf(settings.tickets.type);
458
468
  const fixture = option(argv, "--fixture");
459
469
  if (argv[0] !== "collect" &&
460
470
  argv[0] !== "apply" &&
@@ -464,12 +474,19 @@ export async function main(argv, deps) {
464
474
  if (fixture) {
465
475
  const saved = JSON.parse(deps.readFile(join(fixture, "repo.json")));
466
476
  const boardPages = JSON.parse(deps.readFile(join(fixture, "board.json")));
467
- await apply(saved, toBoard(boardPages, repository), { ...deps, repository, config, runPage }, null);
477
+ await apply(saved, toBoard(boardPages, repository), { ...deps, repository, config, runPage, ref }, null);
468
478
  return 0;
469
479
  }
470
480
  const board = argv[0] === "collect" ? null : await projectNumber(deps);
471
481
  const opened = await deps.open(settings, { repository, board });
472
- const d = { ...deps, config, repository, runPage, ...opened };
482
+ const d = {
483
+ ...deps,
484
+ config,
485
+ repository,
486
+ runPage,
487
+ ...opened,
488
+ own: ownLinks(settings),
489
+ };
473
490
  if (argv[0] === "collect") {
474
491
  const out = option(argv, "--out");
475
492
  if (!out)
@@ -500,11 +517,11 @@ export async function main(argv, deps) {
500
517
  throw new Error("apply needs --in FILE.");
501
518
  if (!d.env.GH_TOKEN)
502
519
  throw new Error("FACTORY_BOARD_TOKEN is not set.");
503
- await apply(JSON.parse(d.readFile(input)), await boardOps.read(), d, dryRun ? null : boardOps);
520
+ await apply(JSON.parse(d.readFile(input)), await boardOps.read(), { ...d, ref }, dryRun ? null : boardOps);
504
521
  return 0;
505
522
  }
506
523
  const saved = await collect(d, { nightly: false, dryRun: true });
507
- await apply(saved, await boardOps.read(), d, null);
524
+ await apply(saved, await boardOps.read(), { ...d, ref }, null);
508
525
  return 0;
509
526
  }
510
527
  catch (error) {
package/dist/build.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { type Settings } from "./config.mts";
2
2
  import { type CodeHost } from "./code-host/index.mts";
3
3
  import { type Runner } from "./runner/index.mts";
4
+ import type { Key } from "./tickets/types.mts";
4
5
  export type Deps = {
5
6
  settings: () => Promise<Settings>;
6
7
  env: Record<string, string | undefined>;
@@ -8,6 +9,9 @@ export type Deps = {
8
9
  codeHost: (repository: string, type: string) => CodeHost;
9
10
  /** The runner of that name. */
10
11
  runner: (repository: string, name: string) => Runner;
12
+ /** How the settings' ticket system reads a key and writes a ticket. */
13
+ keyOf: (type: string) => (typed: string) => Key;
14
+ refOf: (type: string) => (key: Key) => string;
11
15
  now: () => Date;
12
16
  sleep: (ms: number) => Promise<unknown>;
13
17
  out: (line: string) => void;
package/dist/build.mjs CHANGED
@@ -10,18 +10,21 @@ import { setTimeout as sleep } from "node:timers/promises";
10
10
  import { loadSettings, targetOf } from "./config.mjs";
11
11
  import { openCodeHost } from "./code-host/index.mjs";
12
12
  import { openRunner } from "./runner/index.mjs";
13
+ import { keyOf, refOf } from "./tickets/index.mjs";
13
14
  const USAGE = "Usage: factory build N";
14
15
  /** How long to look for the run, and how often. */
15
16
  const FIND_FOR_MS = 15_000;
16
17
  const EVERY_MS = 3_000;
17
18
  export async function main(argv, d) {
18
- const ticket = Number(argv[0]);
19
- if (argv.length !== 1 || !Number.isInteger(ticket) || ticket <= 0) {
19
+ if (argv.length !== 1 || !argv[0] || argv[0].startsWith("-")) {
20
20
  d.err(USAGE);
21
21
  return 2;
22
22
  }
23
23
  try {
24
24
  const settings = await d.settings();
25
+ const ticket = d.keyOf(settings.tickets.type)(argv[0]);
26
+ const ref = d.refOf(settings.tickets.type)(ticket);
27
+ const runName = `Build ${ref}`;
25
28
  const { repository } = targetOf(settings, d.env);
26
29
  const runner = d.runner(repository, settings.builds.runner);
27
30
  const branch = await d
@@ -31,12 +34,12 @@ export async function main(argv, d) {
31
34
  await runner.startBuild(ticket, branch);
32
35
  let link = null;
33
36
  for (;;) {
34
- link = await runner.findBuild(ticket, since);
37
+ link = await runner.findBuild(runName, since);
35
38
  if (link || d.now().getTime() - since >= FIND_FOR_MS)
36
39
  break;
37
40
  await d.sleep(EVERY_MS);
38
41
  }
39
- d.out(`Started a build of #${ticket} in GitHub Actions:`);
42
+ d.out(`Started a build of ${ref} in GitHub Actions:`);
40
43
  d.out(link ?? runner.buildsPage());
41
44
  return 0;
42
45
  }
@@ -52,6 +55,8 @@ export async function run(argv) {
52
55
  env: process.env,
53
56
  codeHost: (repository, type) => openCodeHost(repository, type),
54
57
  runner: (repository, name) => openRunner(repository, name),
58
+ keyOf,
59
+ refOf,
55
60
  now: () => new Date(),
56
61
  sleep,
57
62
  out: (line) => console.log(line),
package/dist/cli.mjs CHANGED
@@ -36,6 +36,7 @@ const PR_STEPS = [
36
36
  "resolve",
37
37
  "ready",
38
38
  "closes",
39
+ "cost",
39
40
  "for-branch",
40
41
  "comments",
41
42
  "comment",
@@ -64,7 +65,8 @@ const pr = (sub, args) => ({
64
65
  const TICKET_ARGS = {
65
66
  refined: "N [--check] [--before-file FILE]",
66
67
  stop: 'N "reason"',
67
- view: "N [--field title|state|labels|body] [--json]",
68
+ view: "N [--field title|state|labels|body|ref] [--json]",
69
+ link: "N [--part]",
68
70
  list: '[--label LABEL] [--title "TITLE"] [--json]',
69
71
  edit: "N --body-file FILE [--attach FILE]",
70
72
  comment: "N --body-file FILE [--attach FILE]",
@@ -272,6 +274,11 @@ export const COMMANDS = [
272
274
  args: "",
273
275
  run: async () => (await import("./review-tools.mjs")).run(),
274
276
  },
277
+ {
278
+ words: ["review", "tickets"],
279
+ args: "N",
280
+ run: async (argv) => (await import("./review-tickets.mjs")).run(argv),
281
+ },
275
282
  {
276
283
  words: ["reviewers", "start"],
277
284
  args: "",
@@ -139,7 +139,7 @@ fragment links on Issue {
139
139
  }
140
140
  }`;
141
141
  const toComments = (raw) => (raw?.nodes ?? []).map((c) => ({
142
- id: c.databaseId,
142
+ id: String(c.databaseId),
143
143
  createdAt: c.createdAt,
144
144
  body: c.body,
145
145
  author: c.author?.login ?? "ghost",
@@ -153,7 +153,8 @@ export function toPull(raw, repository) {
153
153
  author: raw.author?.login ?? "ghost",
154
154
  closes: raw.closingIssuesReferences.nodes
155
155
  .filter((ref) => ref.repository.nameWithOwner === repository)
156
- .map((ref) => ref.number),
156
+ .map((ref) => String(ref.number)),
157
+ partOf: [],
157
158
  openThreads: (raw.reviewThreads?.nodes ?? []).filter((t) => !t.isResolved)
158
159
  .length,
159
160
  checks: raw.commits?.nodes[0]?.commit.statusCheckRollup?.state ?? null,
@@ -184,7 +185,7 @@ const CLOSING_QUERY = `
184
185
  query ClosingIssues($owner: String!, $name: String!, $number: Int!) {
185
186
  repository(owner: $owner, name: $name) {
186
187
  pullRequest(number: $number) {
187
- closingIssuesReferences(first: 25) { nodes { number } }
188
+ closingIssuesReferences(first: 25) { nodes { number repository { nameWithOwner } } }
188
189
  }
189
190
  }
190
191
  }`;
@@ -346,7 +347,11 @@ export function githubCodeHost(o) {
346
347
  },
347
348
  async closes(n) {
348
349
  const result = await t.graphql(CLOSING_QUERY, { owner, name, number: n });
349
- return result.data.repository.pullRequest.closingIssuesReferences.nodes.map((x) => x.number);
350
+ return result.data.repository.pullRequest.closingIssuesReferences.nodes
351
+ .filter((x) => !x.repository ||
352
+ x.repository.nameWithOwner.toLowerCase() ===
353
+ o.repository.toLowerCase())
354
+ .map((x) => String(x.number));
350
355
  },
351
356
  async open(options = {}) {
352
357
  const page = await t.graphql(OPEN_PULLS_QUERY, {
@@ -1,4 +1,5 @@
1
1
  import type { PullRequest } from "../lib/work-status.mts";
2
+ import type { Key } from "../tickets/types.mts";
2
3
  /** One end of a pull request: the commit, its branch, and the repository
3
4
  * the branch is in, as owner/name. */
4
5
  export type PullEnd = {
@@ -171,8 +172,9 @@ export type CodeHost = {
171
172
  /** One line for each commit on the pull request the code host does not
172
173
  * show as signed: its short ID and the reason, such as `unsigned`. */
173
174
  unverifiedCommits(pull: number): Promise<string[]>;
174
- /** The tickets the pull request closes when it merges. */
175
- closes(pull: number): Promise<number[]>;
175
+ /** The tickets the pull request closes when it merges, by the code
176
+ * host's own links: only tickets the code host keeps itself. */
177
+ closes(pull: number): Promise<Key[]>;
176
178
  /** The open pull requests, as the views and the sync read them: with
177
179
  * their check state when `checks` is asked, and their comments, for the
178
180
  * cost markers, when `costs` is. */
@@ -13,7 +13,7 @@ export type Deps = {
13
13
  paint?: Paint;
14
14
  specTools: SpecTools;
15
15
  /** Ticket `id`'s labels; throws when it can't be read. */
16
- labels: (settings: Settings, id: number) => Promise<string[]>;
16
+ labels: (settings: Settings, id: string) => Promise<string[]>;
17
17
  };
18
18
  /** `argv` is the command's name, then its arguments. */
19
19
  export declare function main(argv: string[], d: Deps): Promise<number>;
package/dist/commands.mjs CHANGED
@@ -21,7 +21,8 @@ import { spawnSync } from "node:child_process";
21
21
  import { colorOn, painter, plain } from "./lib/color.mjs";
22
22
  import { defaultDeps, loadSettings, repoRoot, SETTINGS_FILE, SettingsError, } from "./config.mjs";
23
23
  import { specTools } from "./specs/index.mjs";
24
- import { openTickets } from "./tickets/index.mjs";
24
+ import { keyOf, openTickets } from "./tickets/index.mjs";
25
+ import { KeyError } from "./tickets/types.mjs";
25
26
  const USAGE = {
26
27
  gate: "Usage: factory gate",
27
28
  "test-one": "Usage: factory test-one FILE [NAME]",
@@ -63,9 +64,7 @@ export async function main(argv, d) {
63
64
  return usage();
64
65
  }
65
66
  else if (name === "specs-new" || name === "specs-finish") {
66
- // A ticket as the ticket system writes it: GitHub's, the only one
67
- // built, are whole numbers.
68
- if (args.length !== 1 || !/^[1-9]\d*$/.test(args[0]))
67
+ if (args.length !== 1 || args[0].startsWith("-"))
69
68
  return usage();
70
69
  }
71
70
  else if (name === "test-one") {
@@ -86,6 +85,16 @@ export async function main(argv, d) {
86
85
  d.err(e.message);
87
86
  return 1;
88
87
  }
88
+ if (name === "specs-new" || name === "specs-finish")
89
+ try {
90
+ keyOf(s.tickets.type)(args[0]);
91
+ }
92
+ catch (e) {
93
+ if (!(e instanceof KeyError))
94
+ throw e;
95
+ d.err(e.message);
96
+ return 1;
97
+ }
89
98
  const paint = d.paint ?? plain;
90
99
  /** The command's own closing line, after the output passed through. */
91
100
  const ended = (status, passed, failed) => {
@@ -169,7 +178,7 @@ export async function main(argv, d) {
169
178
  }
170
179
  let labels;
171
180
  try {
172
- labels = await d.labels(s, Number(id));
181
+ labels = await d.labels(s, id);
173
182
  }
174
183
  catch (e) {
175
184
  d.err(e instanceof Error ? e.message : String(e));
@@ -218,7 +227,7 @@ export async function run(argv) {
218
227
  repository: settings.repository,
219
228
  board: null,
220
229
  });
221
- return (await tickets.read(id)).labels;
230
+ return (await tickets.read(tickets.key(id))).labels;
222
231
  },
223
232
  });
224
233
  }
@@ -2,7 +2,7 @@
2
2
  * claimed or refined an issue: its spend is counted once, but its reviewer
3
3
  * runs belong to no issue. */
4
4
  export type Clock = {
5
- issue: number | null;
5
+ issue: string | null;
6
6
  start: string;
7
7
  };
8
8
  /** The repository's shared git directory, so a session that moves to
@@ -11,4 +11,6 @@ export declare function commonDir(): string;
11
11
  export declare const clockPath: (session: string) => string;
12
12
  /** The clock, or null when none was started or it cannot be read. */
13
13
  export declare function readClock(session: string): Clock | null;
14
+ /** A clock file's text as the clock, or null when it is not one. */
15
+ export declare function parseClock(text: string): Clock | null;
14
16
  export declare function writeClock(session: string, clock: Clock): void;
@@ -18,13 +18,19 @@ export const clockPath = (session) => join(commonDir(), `work-clock-${session}`)
18
18
  /** The clock, or null when none was started or it cannot be read. */
19
19
  export function readClock(session) {
20
20
  const path = clockPath(session);
21
- if (!existsSync(path))
22
- return null;
21
+ return existsSync(path) ? parseClock(readFileSync(path, "utf8")) : null;
22
+ }
23
+ /** A clock file's text as the clock, or null when it is not one. */
24
+ export function parseClock(text) {
23
25
  try {
24
- const clock = JSON.parse(readFileSync(path, "utf8"));
25
- return (clock.issue === null || Number.isInteger(clock.issue)) &&
26
- !Number.isNaN(Date.parse(clock.start))
27
- ? clock
26
+ const clock = JSON.parse(text);
27
+ if (Number.isNaN(Date.parse(clock.start)))
28
+ return null;
29
+ // A clock written before tickets had keys holds the issue's number.
30
+ if (typeof clock.issue === "number" && Number.isInteger(clock.issue))
31
+ return { issue: String(clock.issue), start: clock.start };
32
+ return clock.issue === null || typeof clock.issue === "string"
33
+ ? { issue: clock.issue, start: clock.start }
28
34
  : null;
29
35
  }
30
36
  catch {
@@ -0,0 +1,15 @@
1
+ import type { Settings } from "../config.mts";
2
+ import type { Links, Tickets } from "../tickets/types.mts";
3
+ import type { PullRequest } from "./work-status.mts";
4
+ /** Whether the code host keeps the tickets itself, so its own links, such
5
+ * as GitHub's closing references, say which tickets a pull request closes. */
6
+ export declare const ownLinks: (settings: Settings) => boolean;
7
+ /** The tickets a pull request closes and builds part of. `closes` is the
8
+ * code host's list as it read it. */
9
+ export declare function ticketsOf(pull: {
10
+ body: string;
11
+ closes: Links["closes"];
12
+ }, tickets: Pick<Tickets, "linksIn">, own: boolean): Links;
13
+ /** The pull requests with `closes` and `partOf` read as `ticketsOf` reads
14
+ * them. */
15
+ export declare const linkPulls: <P extends PullRequest>(pulls: P[], tickets: Pick<Tickets, "linksIn">, own: boolean) => P[];
@@ -0,0 +1,12 @@
1
+ /** Whether the code host keeps the tickets itself, so its own links, such
2
+ * as GitHub's closing references, say which tickets a pull request closes. */
3
+ export const ownLinks = (settings) => settings.tickets.type === "github" && settings.codeHost.type === "github";
4
+ /** The tickets a pull request closes and builds part of. `closes` is the
5
+ * code host's list as it read it. */
6
+ export function ticketsOf(pull, tickets, own) {
7
+ const links = tickets.linksIn(pull.body);
8
+ return { closes: own ? pull.closes : links.closes, partOf: links.partOf };
9
+ }
10
+ /** The pull requests with `closes` and `partOf` read as `ticketsOf` reads
11
+ * them. */
12
+ export const linkPulls = (pulls, tickets, own) => pulls.map((pull) => ({ ...pull, ...ticketsOf(pull, tickets, own) }));
@@ -24,7 +24,9 @@ export declare const dollars: (amount: number) => string;
24
24
  export declare const bothPrices: (listPrice: number) => string;
25
25
  /** The cost note's visible line and hidden marker, or the line that says
26
26
  * why the cost could not be measured. */
27
- export declare function costNote(measured: Measured, issue: number, session: string): string;
27
+ export declare function costNote(measured: Measured,
28
+ /** Where the note is posted, as written in prose, such as `#12`. */
29
+ on: string, session: string): string;
28
30
  /** Where Claude Code keeps its transcripts. */
29
31
  export declare function projectsDir(env: Record<string, string | undefined>): string;
30
32
  /** The session's own transcript and its subagents', or null when the
@@ -81,7 +81,9 @@ function unpricedClause(spend) {
81
81
  }
82
82
  /** The cost note's visible line and hidden marker, or the line that says
83
83
  * why the cost could not be measured. */
84
- export function costNote(measured, issue, session) {
84
+ export function costNote(measured,
85
+ /** Where the note is posted, as written in prose, such as `#12`. */
86
+ on, session) {
85
87
  const failed = (reason) => `This session's cost could not be measured: ${reason}.`;
86
88
  if (!measured.ok)
87
89
  return failed(measured.reason);
@@ -91,7 +93,7 @@ export function costNote(measured, issue, session) {
91
93
  ? "its transcript records no usage since its last note"
92
94
  : `no token in it is on a model with a list price${unpricedClause(spend).replace(/^, plus/, ":")}`);
93
95
  const amount = spend.dollars.toFixed(2);
94
- return `This session used ${bothPrices(spend.dollars)} on #${issue} since its last note${unpricedClause(spend)}.\n\n<!-- cost: ${amount} session=${session} -->`;
96
+ return `This session used ${bothPrices(spend.dollars)} on ${on} since its last note${unpricedClause(spend)}.\n\n<!-- cost: ${amount} session=${session} -->`;
95
97
  }
96
98
  /** Where Claude Code keeps its transcripts. */
97
99
  export function projectsDir(env) {