@davidbyoung/software-factory 0.1.9 → 0.1.11

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 (67) hide show
  1. package/agents/factory-ticket-readiness.md +20 -15
  2. package/dist/board.d.mts +1 -1
  3. package/dist/board.mjs +4 -7
  4. package/dist/cli.mjs +23 -1
  5. package/dist/code-host/github.d.mts +1 -1
  6. package/dist/code-host/github.mjs +31 -2
  7. package/dist/code-host/types.d.mts +20 -1
  8. package/dist/code-host/types.mjs +8 -0
  9. package/dist/columns-suggest.d.mts +25 -5
  10. package/dist/columns-suggest.mjs +117 -21
  11. package/dist/commands.d.mts +8 -2
  12. package/dist/commands.mjs +92 -8
  13. package/dist/config.d.mts +19 -7
  14. package/dist/config.mjs +109 -30
  15. package/dist/doctor.mjs +1 -2
  16. package/dist/explain.mjs +7 -1
  17. package/dist/init.d.mts +19 -0
  18. package/dist/init.mjs +139 -23
  19. package/dist/lib/gh.d.mts +6 -0
  20. package/dist/lib/gh.mjs +11 -1
  21. package/dist/lib/listed.d.mts +3 -2
  22. package/dist/lib/listed.mjs +5 -4
  23. package/dist/lib/work-status.d.mts +5 -5
  24. package/dist/lib/work-status.mjs +7 -8
  25. package/dist/merge-policy.mjs +7 -3
  26. package/dist/poller.d.mts +1 -1
  27. package/dist/poller.mjs +9 -6
  28. package/dist/pr.d.mts +8 -6
  29. package/dist/pr.mjs +47 -22
  30. package/dist/review-verdict.d.mts +22 -4
  31. package/dist/review-verdict.mjs +55 -17
  32. package/dist/specs/index.d.mts +6 -0
  33. package/dist/specs/index.mjs +15 -0
  34. package/dist/specs/openspec.d.mts +2 -0
  35. package/dist/specs/openspec.mjs +78 -0
  36. package/dist/specs/types.d.mts +53 -0
  37. package/dist/specs/types.mjs +4 -0
  38. package/dist/ticket.d.mts +6 -1
  39. package/dist/ticket.mjs +62 -3
  40. package/dist/tickets/github-access.d.mts +5 -0
  41. package/dist/tickets/github-access.mjs +22 -0
  42. package/dist/tickets/github.mjs +2 -0
  43. package/dist/tickets/types.d.mts +4 -0
  44. package/dist/tool-names.d.mts +2 -0
  45. package/dist/tool-names.mjs +3 -0
  46. package/dist/tools.d.mts +2 -0
  47. package/dist/tools.mjs +3 -0
  48. package/docs/builds.md +30 -14
  49. package/docs/cli.md +48 -30
  50. package/docs/configuration.md +237 -73
  51. package/docs/developing.md +104 -59
  52. package/docs/existing-repo.md +51 -29
  53. package/docs/github/by-hand.md +13 -1
  54. package/docs/github/setup.md +26 -2
  55. package/docs/glossary.md +7 -6
  56. package/docs/limitations.md +8 -5
  57. package/docs/presets.md +15 -3
  58. package/docs/updating.md +147 -2
  59. package/docs/workflow.md +26 -9
  60. package/package.json +1 -1
  61. package/rules.md +36 -30
  62. package/settings.schema.json +14 -9
  63. package/skills/factory-address-review/SKILL.md +40 -39
  64. package/skills/factory-build/SKILL.md +77 -52
  65. package/skills/factory-deps/SKILL.md +6 -4
  66. package/skills/factory-refine/SKILL.md +30 -22
  67. package/skills/factory-resolve-conflicts/SKILL.md +8 -7
package/dist/init.mjs CHANGED
@@ -10,10 +10,10 @@ import { execFileSync, spawn, spawnSync } from "node:child_process";
10
10
  import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync, } from "node:fs";
11
11
  import { tmpdir } from "node:os";
12
12
  import { dirname, join } from "node:path";
13
- import { isMap, parseDocument } from "yaml";
13
+ import { isMap, parseDocument, Scalar } from "yaml";
14
14
  import { builtOf, secretSteps, TOOLS, } from "./tools.mjs";
15
15
  import { NeedsScopeError } from "./code-host/types.mjs";
16
- import { columnsOf, fieldNamesOf, filesDeps, parseSettings, resolveFiles, POLL_MINUTES, repoRoot, SETTINGS_FILE, SettingsError, } from "./config.mjs";
16
+ import { branchPatternFault, columnsOf, fieldNamesOf, filesDeps, parseSettings, resolveFiles, POLL_MINUTES, repoRoot, SETTINGS_FILE, SettingsError, } from "./config.mjs";
17
17
  import { colorOn, painter } from "./lib/color.mjs";
18
18
  import { checks as doctorChecks, doctorDeps, printChecks } from "./doctor.mjs";
19
19
  import { branchDeps, needDefaultBranch, NoDefaultBranch, } from "./lib/default-branch.mjs";
@@ -25,8 +25,8 @@ import { neededSecrets, PART_TEXT, PARTS, partsOn, resolveParts, SIGNING_KEY, }
25
25
  import { CONTEXT as REVIEW_VERDICT } from "./review-verdict.mjs";
26
26
  import { RULE } from "./setup.mjs";
27
27
  import { differences, PACKAGE, plan as syncPlan } from "./sync.mjs";
28
- import { DEFAULT_COLUMNS, STATE_KEYS, sameName } from "./lib/work-status.mjs";
29
- import { askReady, suggestColumns } from "./columns-suggest.mjs";
28
+ import { DEFAULT_COLUMNS, STATE_KEYS, sameName, } from "./lib/work-status.mjs";
29
+ import { askReady, everyColumn, FACTORY_LINES, fillColumns, suggestColumns, } from "./columns-suggest.mjs";
30
30
  import { FACTORY_FIELDS, suggestFields } from "./ticket-fields.mjs";
31
31
  const SIGNING_TITLE = "software factory builds";
32
32
  /** Where each release's poller image is published. */
@@ -34,6 +34,57 @@ const POLLER_IMAGE = "ghcr.io/davidbyoung/software-factory-poller";
34
34
  /** A month of runs at each interval the scheduled poller allows. */
35
35
  const RUNS_A_MONTH = (minutes) => (30 * 24 * 60) / minutes;
36
36
  const AGAIN = "Run factory init again to add it.";
37
+ /** Each state `tickets.columns` writes, as its columns or null for none,
38
+ * from the settings as parsed YAML. */
39
+ function writtenColumnsOf(raw) {
40
+ const tickets = raw?.tickets;
41
+ const columns = tickets?.columns;
42
+ if (typeof columns !== "object" || columns === null)
43
+ return {};
44
+ return Object.fromEntries(Object.entries(columns)
45
+ .filter(([k]) => k in STATE_KEYS)
46
+ .map(([k, v]) => [
47
+ k,
48
+ v === "none" ? null : Array.isArray(v) ? v.map(String) : [String(v)],
49
+ ]));
50
+ }
51
+ /** The branch name a preset in effect supplies to the settings `text`
52
+ * of the repository at `root`, or null for none. Settings whose presets
53
+ * can't be read get the question: the check that follows says what is
54
+ * wrong with them. */
55
+ export const presetBranchNameAt = (root) => async (text) => {
56
+ try {
57
+ const r = await resolveFiles({ ...filesDeps(root), readFile: () => text }, { partial: true });
58
+ return r.settings.codeHost.branchName;
59
+ }
60
+ catch {
61
+ return null;
62
+ }
63
+ };
64
+ /** The spec tool a preset in effect names, as `presetBranchNameAt` finds
65
+ * a branch name. */
66
+ export const presetSpecsAt = (root) => async (text) => {
67
+ try {
68
+ const r = await resolveFiles({ ...filesDeps(root), readFile: () => text }, { partial: true });
69
+ return "specs" in r.resolution.raw ? r.settings.specs : null;
70
+ }
71
+ catch {
72
+ return null;
73
+ }
74
+ };
75
+ const NO_SPEC_TOOL = "None: each ticket holds its own spec";
76
+ const BRANCH_QUESTION = "How should a build name its branch? Use {ticket}, and {user} for the GitHub account:";
77
+ /** The pattern a build names its branch by, asked until the answer is one
78
+ * the settings check takes. */
79
+ async function askBranchName(d) {
80
+ for (;;) {
81
+ const answer = (await d.ask.input(BRANCH_QUESTION, "{ticket}")).trim();
82
+ const fault = branchPatternFault(answer);
83
+ if (!fault)
84
+ return answer;
85
+ d.out(fault);
86
+ }
87
+ }
37
88
  /** The columns and fields the board sync uses: the settings' names where
38
89
  * they rename one, and none for one they set to none. */
39
90
  function boardShape(s) {
@@ -98,7 +149,8 @@ export async function main(_argv, d) {
98
149
  let settings = null;
99
150
  if (settingsText !== null) {
100
151
  try {
101
- settings = parseSettings(doc.toJS(), (p) => existsSync(at(p)), builtOf(d.tools));
152
+ // A block that leaves states out is what the column step fills in.
153
+ settings = parseSettings(doc.toJS(), (p) => existsSync(at(p)), builtOf(d.tools), { partial: true });
102
154
  }
103
155
  catch (e) {
104
156
  d.out(`${SETTINGS_FILE}: ${message(e)}`);
@@ -183,6 +235,27 @@ export async function main(_argv, d) {
183
235
  runner: await pick("runner", "Where do cloud builds run?"),
184
236
  agent: agentName,
185
237
  };
238
+ const branchName = doc.hasIn(["code-host", "branch-name"]) ||
239
+ (await d.presetBranchName(String(doc))) !== null
240
+ ? null
241
+ : await askBranchName(d);
242
+ const ownSpecs = doc.get("specs");
243
+ const writtenSpecs = isMap(ownSpecs)
244
+ ? String(ownSpecs.get("type") ?? "none")
245
+ : ownSpecs === undefined
246
+ ? await d.presetSpecs(String(doc))
247
+ : String(ownSpecs);
248
+ const specsAnswer = writtenSpecs === null
249
+ ? await d.ask.select("Which spec tool do you use?", [
250
+ { name: NO_SPEC_TOOL, value: "none" },
251
+ ...Object.entries(d.tools.specs).map(([value, t]) => ({
252
+ name: t.label,
253
+ value,
254
+ })),
255
+ ], "none")
256
+ : null;
257
+ const specTool = d.tools.specs[specsAnswer ?? writtenSpecs ?? "none"];
258
+ const installing = specTool && !specTool.install.installed(d.root) ? specTool : null;
186
259
  const codeHost = d.tools.codeHost[chosen.codeHost].open(repository);
187
260
  const runner = d.tools.runner[chosen.runner].open(repository);
188
261
  const tickets = await d.tools.tickets[chosen.tickets].open({ repository, board: null }, settings);
@@ -284,19 +357,21 @@ export async function main(_argv, d) {
284
357
  })), "30"));
285
358
  }
286
359
  }
287
- // The board's columns: the coding agent suggests them when an existing
288
- // board lacks one of the factory's and the settings name none, and a
289
- // ready column is asked for when builds from the board turn on without
290
- // one.
360
+ // The board's columns, all six written: the coding agent suggests them
361
+ // when an existing board lacks one of the factory's and the settings
362
+ // name none, a block that leaves states out is filled in, and a ready
363
+ // column is asked for when builds from the board turn on without one.
291
364
  let columnLines = [];
292
365
  let readyColumn;
366
+ const writtenColumns = writtenColumnsOf(doc.toJS());
367
+ const missing = Object.keys(STATE_KEYS).filter((k) => !(k in writtenColumns));
293
368
  if (parts.has("board") && typeof board === "number" && boardOps) {
294
369
  const asksReady = parts.has("from-board") &&
295
370
  !before.has("from-board") &&
296
371
  settings?.tickets.columns.ready === null;
297
- const suggests = !doc.hasIn(["tickets", "columns"]);
372
+ const suggests = missing.length === Object.keys(STATE_KEYS).length;
298
373
  let names = [];
299
- if (suggests || asksReady)
374
+ if (missing.length || asksReady)
300
375
  try {
301
376
  names = await boardOps.columns(board);
302
377
  }
@@ -306,22 +381,24 @@ export async function main(_argv, d) {
306
381
  return 1;
307
382
  }
308
383
  const lacks = Object.values(STATE_KEYS).some((f) => !names.some((n) => sameName(n, f)));
384
+ const fromBoard = parts.has("from-board") && trigger !== "manual";
309
385
  if (suggests && names.length && lacks) {
310
386
  const got = await suggestColumns({
311
387
  ask: d.ask,
312
388
  out: d.out,
313
389
  agent: agent.agent,
314
390
  label: agent.label,
315
- }, {
316
- board,
317
- columns: names,
318
- fromBoard: parts.has("from-board") && trigger !== "manual",
319
- });
391
+ }, { board, columns: names, fromBoard });
320
392
  if (got === 1)
321
393
  return 1;
322
- if (got !== "default")
323
- columnLines = got;
394
+ columnLines = got;
324
395
  }
396
+ else if (suggests && names.length)
397
+ columnLines = everyColumn(d, { board, columns: names });
398
+ else if (suggests)
399
+ columnLines = FACTORY_LINES;
400
+ else if (missing.length)
401
+ columnLines = await fillColumns({ ask: d.ask, out: d.out }, { board, columns: names, written: writtenColumns, fromBoard });
325
402
  else if (asksReady && settings)
326
403
  readyColumn = await askReady({ ask: d.ask, out: d.out }, { columns: names, current: columnsOf(settings) });
327
404
  }
@@ -369,16 +446,24 @@ export async function main(_argv, d) {
369
446
  doc.setIn(["tickets", "columns", key], name);
370
447
  for (const [key, name] of fieldLines)
371
448
  doc.setIn(["tickets", "fields", key], name);
372
- if (readyColumn === null)
373
- remove(doc, ["tickets", "columns", "ready"]);
374
- else if (readyColumn !== undefined)
375
- doc.setIn(["tickets", "columns", "ready"], readyColumn);
449
+ if (readyColumn !== undefined)
450
+ doc.setIn(["tickets", "columns", "ready"], readyColumn ?? "Ready");
376
451
  if (!parts.has("board")) {
377
452
  for (const key of ["board", "columns"])
378
453
  remove(doc, ["tickets", key]);
379
454
  for (const key of ["session", "runs-in", "cost"])
380
455
  remove(doc, ["tickets", "fields", key]);
381
456
  }
457
+ if (branchName !== null) {
458
+ if (!isMap(doc.get("code-host")))
459
+ doc.set("code-host", doc.createNode({ type: chosen.codeHost }));
460
+ // Quoted: YAML reads a pattern that starts with `{` as a map.
461
+ const quoted = new Scalar(branchName);
462
+ quoted.type = Scalar.QUOTE_DOUBLE;
463
+ doc.setIn(["code-host", "branch-name"], quoted);
464
+ }
465
+ if (specsAnswer !== null)
466
+ doc.set("specs", specsAnswer);
382
467
  if (parts.has("from-board"))
383
468
  doc.setIn(["builds", "trigger"], trigger);
384
469
  else if (before.has("from-board"))
@@ -492,6 +577,8 @@ export async function main(_argv, d) {
492
577
  planRow("Settings", "allow auto-merge on the repository");
493
578
  if (parts.has("review"))
494
579
  planRow("Rules", `Require "${REVIEW_VERDICT}" before a merge to the default branch, as the rule "${RULE}"`);
580
+ if (installing)
581
+ planRow("Install", `${installing.install.package}, with ${installing.install.via}`);
495
582
  for (const part of removed)
496
583
  planRow("Turn off", PART_TEXT[part].name);
497
584
  if (!(await d.ask.confirm("Go ahead?", true))) {
@@ -500,6 +587,7 @@ export async function main(_argv, d) {
500
587
  }
501
588
  // The board first, since the settings name its number.
502
589
  if (parts.has("board") && boardOps) {
590
+ const creating = board === "new";
503
591
  while (board === "new") {
504
592
  try {
505
593
  board = await boardOps.create(name);
@@ -512,6 +600,10 @@ export async function main(_argv, d) {
512
600
  }
513
601
  if (typeof board === "number") {
514
602
  doc.setIn(["tickets", "board"], board);
603
+ // A block needs a board, so one init creates has none written yet.
604
+ if (creating)
605
+ for (const [key, name] of FACTORY_LINES)
606
+ doc.setIn(["tickets", "columns", key], name);
515
607
  try {
516
608
  const shape = boardShape(standing());
517
609
  const columns = await boardOps.addColumns(board, shape.columns);
@@ -535,6 +627,19 @@ export async function main(_argv, d) {
535
627
  if (!/^\/?node_modules\/?$/m.test(ignore ?? ""))
536
628
  write(".gitignore", `${ignore ?? ""}${ignore && !ignore.endsWith("\n") ? "\n" : ""}node_modules/\n`);
537
629
  write(SETTINGS_FILE, String(doc));
630
+ let installFailed = null;
631
+ if (installing) {
632
+ const { package: pkg, via } = installing.install;
633
+ const r = await d.install([...via.split(" "), pkg]);
634
+ if (r.status === 0)
635
+ d.out(`Installed ${pkg}.`);
636
+ else {
637
+ d.out(`Could not install ${pkg}:`);
638
+ for (const l of r.stderr.trimEnd().split("\n").slice(-5))
639
+ d.out(` ${l}`);
640
+ installFailed = `Install ${installing.name}, which a build writes specs with: ${via} ${pkg}`;
641
+ }
642
+ }
538
643
  const synced = await d.sync();
539
644
  if (synced !== 0)
540
645
  d.out("The sync failed, as above.");
@@ -643,7 +748,7 @@ export async function main(_argv, d) {
643
748
  d.out("");
644
749
  if (deletable.length)
645
750
  d.out(`You can now delete these secrets: ${deletable.join(", ")}`);
646
- const left = [];
751
+ const left = installFailed ? [installFailed] : [];
647
752
  const app = codeHost.reviewAppPage();
648
753
  if (parts.has("review") && app)
649
754
  left.push(`Install the app the review posts through: ${app}`);
@@ -656,6 +761,7 @@ export async function main(_argv, d) {
656
761
  ` FACTORY_BOARD_OWNER=${owner}`,
657
762
  ` FACTORY_BOARD_NUMBER=${board}`,
658
763
  " FACTORY_BOARD_TOKEN=the access token you just made",
764
+ ` FACTORY_READY_COLUMN=${columnsOf(standing()).Ready?.[0]}`,
659
765
  ].join("\n"));
660
766
  // Init asks for no command, so a gate is the owner's to add: without one
661
767
  // `factory gate` fails, and a build cannot finish.
@@ -725,6 +831,16 @@ export async function run(argv) {
725
831
  const branch = await needDefaultBranch({ ...branchDeps(root), host });
726
832
  return differences(root, await syncPlan(PACKAGE, root, r, branch));
727
833
  },
834
+ presetBranchName: presetBranchNameAt(root),
835
+ presetSpecs: presetSpecsAt(root),
836
+ install: async (argv2) => {
837
+ const r = spawnSync(argv2[0], argv2.slice(1), {
838
+ cwd: root,
839
+ encoding: "utf8",
840
+ stdio: ["ignore", "ignore", "pipe"],
841
+ });
842
+ return { status: r.status ?? 1, stderr: r.stderr ?? "" };
843
+ },
728
844
  interactive: async (argv2) => spawnSync(argv2[0], argv2.slice(1), { stdio: "inherit" }).status ?? 1,
729
845
  hasCommand,
730
846
  openPage: (url) => {
package/dist/lib/gh.d.mts CHANGED
@@ -11,6 +11,12 @@ export declare function refusalsIn(stdout: string): string;
11
11
  /** A failed call's error: the call, the CLI's own message, and the reasons
12
12
  * in the answer it printed. */
13
13
  export declare function failureOf(args: string[], detail: string, stdout: string): string;
14
+ /** A call the GitHub CLI failed, with the status it exited with: 4 when
15
+ * it is signed in as nobody. */
16
+ export declare class GhError extends Error {
17
+ readonly exitCode: number | null;
18
+ constructor(message: string, exitCode: number | null);
19
+ }
14
20
  export declare const gh: Gh;
15
21
  export declare const ghIn: GhIn;
16
22
  export declare function ghJson<T>(run: Gh, args: string[]): Promise<T>;
package/dist/lib/gh.mjs CHANGED
@@ -25,10 +25,20 @@ export function failureOf(args, detail, stdout) {
25
25
  const said = refusalsIn(stdout);
26
26
  return `gh ${args.slice(0, 4).join(" ")}: ${detail.trim()}${said ? `: ${said}` : ""}`;
27
27
  }
28
+ /** A call the GitHub CLI failed, with the status it exited with: 4 when
29
+ * it is signed in as nobody. */
30
+ export class GhError extends Error {
31
+ exitCode;
32
+ constructor(message, exitCode) {
33
+ super(message);
34
+ this.name = "GhError";
35
+ this.exitCode = exitCode;
36
+ }
37
+ }
28
38
  export const gh = (args) => new Promise((resolve, reject) => {
29
39
  execFile("gh", args, { maxBuffer: 64 * 1024 * 1024 }, (error, stdout, stderr) => {
30
40
  if (error)
31
- reject(new Error(failureOf(args, stderr || error.message, stdout)));
41
+ reject(new GhError(failureOf(args, stderr || error.message, stdout), typeof error.code === "number" ? error.code : null));
32
42
  else
33
43
  resolve(stdout);
34
44
  });
@@ -1,2 +1,3 @@
1
- /** Items as a sentence lists them: "a", "a and b", "a, b, and c". */
2
- export declare const listed: (items: readonly string[]) => string;
1
+ /** Items as a sentence lists them: "a", "a and b", "a, b, and c", or
2
+ * with "or" in place of "and". */
3
+ export declare const listed: (items: readonly string[], conjunction?: "and" | "or") => string;
@@ -1,4 +1,5 @@
1
- /** Items as a sentence lists them: "a", "a and b", "a, b, and c". */
2
- export const listed = (items) => items.length < 3
3
- ? items.join(" and ")
4
- : `${items.slice(0, -1).join(", ")}, and ${items.at(-1)}`;
1
+ /** Items as a sentence lists them: "a", "a and b", "a, b, and c", or
2
+ * with "or" in place of "and". */
3
+ export const listed = (items, conjunction = "and") => items.length < 3
4
+ ? items.join(` ${conjunction} `)
5
+ : `${items.slice(0, -1).join(", ")}, ${conjunction} ${items.at(-1)}`;
@@ -75,16 +75,16 @@ export declare const CI_BOT = "github-actions[bot]";
75
75
  * prose does not count. */
76
76
  export declare function hasCostMarker(body: string): boolean;
77
77
  /** The cost markers in one comment, read as markers are: each on a line of
78
- * its own, outside a fenced code block. Only the owner's account, which the
79
- * agents post as, and the pull request review's bot count; the owner's comments count
80
- * only with the agent mark. */
81
- export declare function parseCosts(comment: IssueComment, owner: string): number[];
78
+ * its own, outside a fenced code block. A comment counts when it carries the
79
+ * agent mark, whoever posted it, as a claim or a release does, or when the
80
+ * pull request review's bot posted it. */
81
+ export declare function parseCosts(comment: IssueComment): number[];
82
82
  /** Whether a pull request's body says it builds this issue, as "Closes #N"
83
83
  * or "Part of #N". */
84
84
  export declare function buildsIssue(body: string, number: number): boolean;
85
85
  /** The issue's Cost: every cost marker on it and on each pull request, open,
86
86
  * merged, or closed, that builds it, to the cent. Null when there are none. */
87
- export declare function issueCost(issue: Issue, pulls: PullRequest[], owner: string): number | null;
87
+ export declare function issueCost(issue: Issue, pulls: PullRequest[]): number | null;
88
88
  export declare const REVIEWER_RUNS_MARK = "<!-- reviewer-runs session=";
89
89
  export type RunResult = "running" | "passed" | "failed" | "no verdict";
90
90
  export type ReviewerRun = {
@@ -115,12 +115,11 @@ export function hasCostMarker(body) {
115
115
  return linesOutsideFences(body).some((line) => COST_LINE.test(line));
116
116
  }
117
117
  /** The cost markers in one comment, read as markers are: each on a line of
118
- * its own, outside a fenced code block. Only the owner's account, which the
119
- * agents post as, and the pull request review's bot count; the owner's comments count
120
- * only with the agent mark. */
121
- export function parseCosts(comment, owner) {
122
- const fromAgent = comment.author === owner && comment.body.includes(AGENT_MARK);
123
- if (!fromAgent && comment.author !== CI_BOT)
118
+ * its own, outside a fenced code block. A comment counts when it carries the
119
+ * agent mark, whoever posted it, as a claim or a release does, or when the
120
+ * pull request review's bot posted it. */
121
+ export function parseCosts(comment) {
122
+ if (!comment.body.includes(AGENT_MARK) && comment.author !== CI_BOT)
124
123
  return [];
125
124
  return linesOutsideFences(comment.body).flatMap((line) => {
126
125
  const match = COST_LINE.exec(line);
@@ -134,7 +133,7 @@ export function buildsIssue(body, number) {
134
133
  }
135
134
  /** The issue's Cost: every cost marker on it and on each pull request, open,
136
135
  * merged, or closed, that builds it, to the cent. Null when there are none. */
137
- export function issueCost(issue, pulls, owner) {
136
+ export function issueCost(issue, pulls) {
138
137
  const comments = [
139
138
  ...issue.comments,
140
139
  ...pulls
@@ -142,7 +141,7 @@ export function issueCost(issue, pulls, owner) {
142
141
  buildsIssue(pull.body, issue.number))
143
142
  .flatMap((pull) => pull.comments ?? []),
144
143
  ];
145
- const costs = comments.flatMap((c) => parseCosts(c, owner));
144
+ const costs = comments.flatMap((c) => parseCosts(c));
146
145
  if (costs.length === 0)
147
146
  return null;
148
147
  return Math.round(costs.reduce((a, b) => a + b, 0) * 100) / 100;
@@ -12,6 +12,7 @@ import { spawnSync } from "node:child_process";
12
12
  import { loadSettings } from "./config.mjs";
13
13
  import { openCodeHost } from "./code-host/index.mjs";
14
14
  import { matchesAny } from "./lib/glob.mjs";
15
+ import { processFiles } from "./specs/index.mjs";
15
16
  /** The code host's changed files under those names. */
16
17
  export const inGithubNames = (files) => files.map(({ path, previousPath, status }) => ({
17
18
  filename: path,
@@ -23,10 +24,13 @@ export const inGithubNames = (files) => files.map(({ path, previousPath, status
23
24
  export const AUTOMATIC = "merge: automatic";
24
25
  export const MANUAL = "merge: manual";
25
26
  /** The factory's own files, held whatever the settings allow: a pull request
26
- * must not be able to change how pull requests are judged. */
27
- const FACTORY_FILES = /^(\.github|\.claude)\/|(^|\/)(CLAUDE|AGENTS)\.md$|^openspec\/config\.yaml$/;
27
+ * must not be able to change how pull requests are judged. Every spec tool's
28
+ * process files are among them, whichever the settings name, since a pull
29
+ * request could change that setting too. */
30
+ const FACTORY_FILES = /^(\.github|\.claude)\/|(^|\/)(CLAUDE|AGENTS)\.md$/;
31
+ const SPEC_TOOL_FILES = new Set(processFiles());
28
32
  function classifyPath(path, policy) {
29
- if (FACTORY_FILES.test(path))
33
+ if (FACTORY_FILES.test(path) || SPEC_TOOL_FILES.has(path))
30
34
  return "the factory's own files";
31
35
  if (matchesAny(path, policy.deny))
32
36
  return "held by auto-merge.deny";
package/dist/poller.d.mts CHANGED
@@ -10,7 +10,7 @@ export declare function selectToStart(snapshot: RepoSnapshot, board: Board, colu
10
10
  export declare function startMarker(): string;
11
11
  /** The columns the poller reads a board by. It runs with no settings file,
12
12
  * so it is told the one name it needs, the column that approves a build:
13
- * FACTORY_READY_COLUMN, which defaults to Ready. */
13
+ * FACTORY_READY_COLUMN, which `readConfig` requires. */
14
14
  export declare function columnsFrom(env: Record<string, string | undefined>): Columns;
15
15
  /** What a refused dispatch's comment says GitHub answered: the status, and
16
16
  * the answer's message or else the status text. */
package/dist/poller.mjs CHANGED
@@ -6,10 +6,12 @@
6
6
  // column from the settings in its checkout and needs only the token.
7
7
  //
8
8
  // Hosted, its environment: FACTORY_REPOSITORY (owner/name), FACTORY_BOARD_OWNER,
9
- // FACTORY_BOARD_NUMBER, and FACTORY_BOARD_TOKEN (a classic token with the
9
+ // FACTORY_BOARD_NUMBER, FACTORY_BOARD_TOKEN (a classic token with the
10
10
  // repo and project scopes, or a fine-grained one that can also write
11
- // Actions: it starts the workflow). It has no checkout, so it reads
12
- // the repository from its environment rather than the factory's settings.
11
+ // Actions: it starts the workflow), and FACTORY_READY_COLUMN (the column
12
+ // tickets.columns.ready names). It has no checkout, so it reads the
13
+ // repository and the column from its environment rather than the
14
+ // factory's settings.
13
15
  //
14
16
  // Once started it never exits on its own: a host that deploys every
15
17
  // component together can fail the whole deploy when a worker exits during
@@ -45,11 +47,11 @@ export function startMarker() {
45
47
  }
46
48
  /** The columns the poller reads a board by. It runs with no settings file,
47
49
  * so it is told the one name it needs, the column that approves a build:
48
- * FACTORY_READY_COLUMN, which defaults to Ready. */
50
+ * FACTORY_READY_COLUMN, which `readConfig` requires. */
49
51
  export function columnsFrom(env) {
50
52
  return {
51
53
  ...DEFAULT_COLUMNS,
52
- Ready: [env.FACTORY_READY_COLUMN?.trim() || "Ready"],
54
+ Ready: [env.FACTORY_READY_COLUMN.trim()],
53
55
  };
54
56
  }
55
57
  /** What a refused dispatch's comment says GitHub answered: the status, and
@@ -90,8 +92,9 @@ export function readConfig(env) {
90
92
  "FACTORY_BOARD_OWNER",
91
93
  "FACTORY_BOARD_NUMBER",
92
94
  "FACTORY_BOARD_TOKEN",
95
+ "FACTORY_READY_COLUMN",
93
96
  ];
94
- const missing = names.filter((name) => !env[name]);
97
+ const missing = names.filter((name) => !env[name]?.trim());
95
98
  if (missing.length)
96
99
  return { missing };
97
100
  return {
package/dist/pr.d.mts CHANGED
@@ -19,7 +19,9 @@ export type Deps = {
19
19
  export declare function withAgentMark(body: string): string;
20
20
  export type Report = {
21
21
  pull: Pull;
22
- ownerLogin: string;
22
+ /** The authors among the reviews and the threads' last comments who can
23
+ * write to the repository. */
24
+ approvers: string[];
23
25
  reviewRun: {
24
26
  status: string;
25
27
  conclusion: string | null;
@@ -30,10 +32,10 @@ export type Report = {
30
32
  threads: Thread[];
31
33
  checks: Check[];
32
34
  };
33
- /** The owner's review bodies still to answer: submitted after the last
35
+ /** An approver's review bodies still to answer: submitted after the last
34
36
  * conversation comment carrying the agent mark, a sweep's own comments
35
37
  * aside. */
36
- export declare function ownerReviewsToWork(r: Report): Review[];
38
+ export declare function approverReviewsToWork(r: Report): Review[];
37
39
  /** A review is coming for this head only on a pull request the Claude review
38
40
  * workflow runs on. */
39
41
  export declare function reviewExpected(pull: Pull): boolean;
@@ -44,11 +46,11 @@ export declare function newestRuns(runs: Run[]): Run[];
44
46
  /** A conversation comment as `pr comments` lists it: ID, author, time, and
45
47
  * its first line. */
46
48
  export declare function commentLine(c: PullComment): string;
47
- /** Whether the owner's review has something in it to work, and if not,
48
- * why: "closed", "someone else's review", or "the factory's own reply". An
49
+ /** Whether an approver's review has something in it to work, and if not,
50
+ * why: "closed", "not an approver's", or "the factory's own reply". An
49
51
  * empty body counts for nothing, since the factory's reply is a review with
50
52
  * an empty body and one comment carrying the marker. */
51
- export declare function reviewPending(p: CodeHost, pr: number, reviewId: number, owner: string): Promise<{
53
+ export declare function reviewPending(p: CodeHost, pr: number, reviewId: number): Promise<{
52
54
  pending: true;
53
55
  } | {
54
56
  pending: false;