@davidbyoung/software-factory 0.1.8 → 0.1.10

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 (69) hide show
  1. package/README.md +2 -0
  2. package/dist/agent/claude-code.mjs +15 -21
  3. package/dist/board.d.mts +20 -3
  4. package/dist/board.mjs +124 -38
  5. package/dist/cli.mjs +84 -9
  6. package/dist/code-host/github-setup.mjs +2 -2
  7. package/dist/code-host/github.d.mts +1 -1
  8. package/dist/code-host/github.mjs +29 -2
  9. package/dist/code-host/types.d.mts +16 -1
  10. package/dist/code-host/types.mjs +8 -0
  11. package/dist/columns-suggest.d.mts +25 -6
  12. package/dist/columns-suggest.mjs +119 -29
  13. package/dist/commands.d.mts +5 -2
  14. package/dist/commands.mjs +37 -12
  15. package/dist/config.d.mts +25 -3
  16. package/dist/config.mjs +159 -33
  17. package/dist/doctor.d.mts +6 -1
  18. package/dist/doctor.mjs +78 -18
  19. package/dist/explain.d.mts +5 -0
  20. package/dist/explain.mjs +36 -1
  21. package/dist/init.d.mts +10 -0
  22. package/dist/init.mjs +133 -31
  23. package/dist/lib/color.d.mts +11 -0
  24. package/dist/lib/color.mjs +15 -0
  25. package/dist/lib/gh.d.mts +6 -0
  26. package/dist/lib/gh.mjs +11 -1
  27. package/dist/lib/listed.d.mts +3 -2
  28. package/dist/lib/listed.mjs +5 -4
  29. package/dist/poller.d.mts +1 -1
  30. package/dist/poller.mjs +9 -6
  31. package/dist/pr.mjs +9 -1
  32. package/dist/preset-commands.d.mts +2 -0
  33. package/dist/preset-commands.mjs +18 -12
  34. package/dist/preset.mjs +3 -2
  35. package/dist/setup.d.mts +3 -0
  36. package/dist/site.d.mts +3 -0
  37. package/dist/site.mjs +8 -1
  38. package/dist/status.d.mts +5 -2
  39. package/dist/status.mjs +13 -22
  40. package/dist/sync.d.mts +7 -1
  41. package/dist/sync.mjs +17 -5
  42. package/dist/ticket-fields.d.mts +84 -0
  43. package/dist/ticket-fields.mjs +374 -0
  44. package/dist/ticket.d.mts +3 -0
  45. package/dist/ticket.mjs +35 -8
  46. package/dist/tickets/github-setup.mjs +1 -1
  47. package/dist/tickets/github.mjs +69 -0
  48. package/dist/tickets/index.d.mts +8 -1
  49. package/dist/tickets/index.mjs +67 -7
  50. package/dist/tickets/types.d.mts +27 -1
  51. package/dist/tickets/types.mjs +4 -0
  52. package/dist/tools.d.mts +1 -1
  53. package/docs/builds.md +26 -13
  54. package/docs/cli.md +73 -36
  55. package/docs/configuration.md +264 -59
  56. package/docs/design.md +10 -0
  57. package/docs/developing.md +49 -18
  58. package/docs/existing-repo.md +184 -34
  59. package/docs/github/by-hand.md +13 -1
  60. package/docs/github/setup.md +14 -2
  61. package/docs/presets.md +15 -3
  62. package/docs/quick-start.md +3 -3
  63. package/docs/skills.md +3 -1
  64. package/docs/updating.md +132 -5
  65. package/docs/workflow.md +1 -1
  66. package/package.json +4 -2
  67. package/settings.schema.json +82 -20
  68. package/skills/factory-build/SKILL.md +39 -7
  69. package/skills/factory-deps/SKILL.md +6 -4
package/dist/init.mjs CHANGED
@@ -10,11 +10,12 @@ 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";
17
- import { checks as doctorChecks, doctorDeps, line } from "./doctor.mjs";
16
+ import { branchPatternFault, columnsOf, fieldNamesOf, filesDeps, parseSettings, resolveFiles, POLL_MINUTES, repoRoot, SETTINGS_FILE, SettingsError, } from "./config.mjs";
17
+ import { colorOn, painter } from "./lib/color.mjs";
18
+ import { checks as doctorChecks, doctorDeps, printChecks } from "./doctor.mjs";
18
19
  import { branchDeps, needDefaultBranch, NoDefaultBranch, } from "./lib/default-branch.mjs";
19
20
  import { hasCommand, noTerminal } from "./lib/has-command.mjs";
20
21
  import { DEFAULT_RUNNER } from "./runner/index.mjs";
@@ -24,14 +25,54 @@ import { neededSecrets, PART_TEXT, PARTS, partsOn, resolveParts, SIGNING_KEY, }
24
25
  import { CONTEXT as REVIEW_VERDICT } from "./review-verdict.mjs";
25
26
  import { RULE } from "./setup.mjs";
26
27
  import { differences, PACKAGE, plan as syncPlan } from "./sync.mjs";
27
- import { DEFAULT_COLUMNS, STATE_KEYS, sameName } from "./lib/work-status.mjs";
28
- 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
+ import { FACTORY_FIELDS, suggestFields } from "./ticket-fields.mjs";
29
31
  const SIGNING_TITLE = "software factory builds";
30
32
  /** Where each release's poller image is published. */
31
33
  const POLLER_IMAGE = "ghcr.io/davidbyoung/software-factory-poller";
32
34
  /** A month of runs at each interval the scheduled poller allows. */
33
35
  const RUNS_A_MONTH = (minutes) => (30 * 24 * 60) / minutes;
34
- const AGAIN = "Run npx --no-install factory init again to add it.";
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
+ const BRANCH_QUESTION = "How should a build name its branch? Use {ticket}, and {user} for the GitHub account:";
65
+ /** The pattern a build names its branch by, asked until the answer is one
66
+ * the settings check takes. */
67
+ async function askBranchName(d) {
68
+ for (;;) {
69
+ const answer = (await d.ask.input(BRANCH_QUESTION, "{ticket}")).trim();
70
+ const fault = branchPatternFault(answer);
71
+ if (!fault)
72
+ return answer;
73
+ d.out(fault);
74
+ }
75
+ }
35
76
  /** The columns and fields the board sync uses: the settings' names where
36
77
  * they rename one, and none for one they set to none. */
37
78
  function boardShape(s) {
@@ -96,7 +137,8 @@ export async function main(_argv, d) {
96
137
  let settings = null;
97
138
  if (settingsText !== null) {
98
139
  try {
99
- settings = parseSettings(doc.toJS(), (p) => existsSync(at(p)), builtOf(d.tools));
140
+ // A block that leaves states out is what the column step fills in.
141
+ settings = parseSettings(doc.toJS(), (p) => existsSync(at(p)), builtOf(d.tools), { partial: true });
100
142
  }
101
143
  catch (e) {
102
144
  d.out(`${SETTINGS_FILE}: ${message(e)}`);
@@ -142,6 +184,12 @@ export async function main(_argv, d) {
142
184
  const npmrc = npmrcAt(d.root);
143
185
  d.out(`Setting up the software factory for ${repository}`);
144
186
  d.out("");
187
+ if (!agent.agent.installed(d.hasCommand)) {
188
+ d.out(`The factory runs in a coding agent, and ${agent.label} is not installed.`);
189
+ d.out("Install it and run factory init again.");
190
+ d.out("Nothing changed.");
191
+ return 1;
192
+ }
145
193
  d.out("Found");
146
194
  const row = (label, text) => d.out(` ${label.padEnd(14)} ${text}`);
147
195
  row("Code host", `${d.tools.codeHost[found.codeHost].label} (from your git remote)`);
@@ -175,6 +223,10 @@ export async function main(_argv, d) {
175
223
  runner: await pick("runner", "Where do cloud builds run?"),
176
224
  agent: agentName,
177
225
  };
226
+ const branchName = doc.hasIn(["code-host", "branch-name"]) ||
227
+ (await d.presetBranchName(String(doc))) !== null
228
+ ? null
229
+ : await askBranchName(d);
178
230
  const codeHost = d.tools.codeHost[chosen.codeHost].open(repository);
179
231
  const runner = d.tools.runner[chosen.runner].open(repository);
180
232
  const tickets = await d.tools.tickets[chosen.tickets].open({ repository, board: null }, settings);
@@ -228,7 +280,7 @@ export async function main(_argv, d) {
228
280
  const chooseBoard = async (offerNew) => {
229
281
  const existing = boardOps ? await boardOps.list() : [];
230
282
  if (!offerNew && existing.length === 0) {
231
- d.out("No board to use instead: create one on the code host, then run npx --no-install factory init again.");
283
+ d.out("No board to use instead: create one on the code host, then run factory init again.");
232
284
  return null;
233
285
  }
234
286
  const choice = await d.ask.select("Which board?", [
@@ -276,19 +328,21 @@ export async function main(_argv, d) {
276
328
  })), "30"));
277
329
  }
278
330
  }
279
- // The board's columns: the coding agent suggests them when an existing
280
- // board lacks one of the factory's and the settings name none, and a
281
- // ready column is asked for when builds from the board turn on without
282
- // one.
331
+ // The board's columns, all six written: the coding agent suggests them
332
+ // when an existing board lacks one of the factory's and the settings
333
+ // name none, a block that leaves states out is filled in, and a ready
334
+ // column is asked for when builds from the board turn on without one.
283
335
  let columnLines = [];
284
336
  let readyColumn;
337
+ const writtenColumns = writtenColumnsOf(doc.toJS());
338
+ const missing = Object.keys(STATE_KEYS).filter((k) => !(k in writtenColumns));
285
339
  if (parts.has("board") && typeof board === "number" && boardOps) {
286
340
  const asksReady = parts.has("from-board") &&
287
341
  !before.has("from-board") &&
288
342
  settings?.tickets.columns.ready === null;
289
- const suggests = !doc.hasIn(["tickets", "columns"]);
343
+ const suggests = missing.length === Object.keys(STATE_KEYS).length;
290
344
  let names = [];
291
- if (suggests || asksReady)
345
+ if (missing.length || asksReady)
292
346
  try {
293
347
  names = await boardOps.columns(board);
294
348
  }
@@ -298,26 +352,55 @@ export async function main(_argv, d) {
298
352
  return 1;
299
353
  }
300
354
  const lacks = Object.values(STATE_KEYS).some((f) => !names.some((n) => sameName(n, f)));
355
+ const fromBoard = parts.has("from-board") && trigger !== "manual";
301
356
  if (suggests && names.length && lacks) {
302
357
  const got = await suggestColumns({
303
358
  ask: d.ask,
304
359
  out: d.out,
305
360
  agent: agent.agent,
306
361
  label: agent.label,
307
- hasCommand: d.hasCommand,
308
- }, {
309
- board,
310
- columns: names,
311
- fromBoard: parts.has("from-board") && trigger !== "manual",
312
- });
362
+ }, { board, columns: names, fromBoard });
313
363
  if (got === 1)
314
364
  return 1;
315
- if (got !== "default")
316
- columnLines = got;
365
+ columnLines = got;
317
366
  }
367
+ else if (suggests && names.length)
368
+ columnLines = everyColumn(d, { board, columns: names });
369
+ else if (suggests)
370
+ columnLines = FACTORY_LINES;
371
+ else if (missing.length)
372
+ columnLines = await fillColumns({ ask: d.ask, out: d.out }, { board, columns: names, written: writtenColumns, fromBoard });
318
373
  else if (asksReady && settings)
319
374
  readyColumn = await askReady({ ask: d.ask, out: d.out }, { columns: names, current: columnsOf(settings) });
320
375
  }
376
+ // The factory fields a refined ticket has: the coding agent suggests
377
+ // which of the tickets' text fields holds each, when the settings name
378
+ // none of the four.
379
+ let fieldLines = [];
380
+ if (tickets.fields &&
381
+ !FACTORY_FIELDS.some((f) => doc.hasIn(["tickets", "fields", f.key]))) {
382
+ let text;
383
+ try {
384
+ text = (await tickets.fields.list()).filter((f) => f.text);
385
+ }
386
+ catch (e) {
387
+ d.out(`Could not read ${repository}'s ticket fields: ${message(e)}`);
388
+ d.out("Nothing changed.");
389
+ return 1;
390
+ }
391
+ if (text.length) {
392
+ const got = await suggestFields({ ask: d.ask, out: d.out, agent: agent.agent, label: agent.label }, {
393
+ repository,
394
+ fields: text,
395
+ plainText: tickets.fields.plainText
396
+ ? d.tools.tickets[chosen.tickets].label
397
+ : null,
398
+ });
399
+ if (got === 1)
400
+ return 1;
401
+ fieldLines = got;
402
+ }
403
+ }
321
404
  // The settings as they will stand, keeping every other key and comment.
322
405
  if (!doc.has("version"))
323
406
  doc.set("version", 2);
@@ -332,13 +415,24 @@ export async function main(_argv, d) {
332
415
  doc.setIn(["tickets", "board"], board);
333
416
  for (const [key, name] of columnLines)
334
417
  doc.setIn(["tickets", "columns", key], name);
335
- if (readyColumn === null)
336
- remove(doc, ["tickets", "columns", "ready"]);
337
- else if (readyColumn !== undefined)
338
- doc.setIn(["tickets", "columns", "ready"], readyColumn);
339
- if (!parts.has("board"))
340
- for (const key of ["board", "columns", "fields"])
418
+ for (const [key, name] of fieldLines)
419
+ doc.setIn(["tickets", "fields", key], name);
420
+ if (readyColumn !== undefined)
421
+ doc.setIn(["tickets", "columns", "ready"], readyColumn ?? "Ready");
422
+ if (!parts.has("board")) {
423
+ for (const key of ["board", "columns"])
341
424
  remove(doc, ["tickets", key]);
425
+ for (const key of ["session", "runs-in", "cost"])
426
+ remove(doc, ["tickets", "fields", key]);
427
+ }
428
+ if (branchName !== null) {
429
+ if (!isMap(doc.get("code-host")))
430
+ doc.set("code-host", doc.createNode({ type: chosen.codeHost }));
431
+ // Quoted: YAML reads a pattern that starts with `{` as a map.
432
+ const quoted = new Scalar(branchName);
433
+ quoted.type = Scalar.QUOTE_DOUBLE;
434
+ doc.setIn(["code-host", "branch-name"], quoted);
435
+ }
342
436
  if (parts.has("from-board"))
343
437
  doc.setIn(["builds", "trigger"], trigger);
344
438
  else if (before.has("from-board"))
@@ -460,6 +554,7 @@ export async function main(_argv, d) {
460
554
  }
461
555
  // The board first, since the settings name its number.
462
556
  if (parts.has("board") && boardOps) {
557
+ const creating = board === "new";
463
558
  while (board === "new") {
464
559
  try {
465
560
  board = await boardOps.create(name);
@@ -472,6 +567,10 @@ export async function main(_argv, d) {
472
567
  }
473
568
  if (typeof board === "number") {
474
569
  doc.setIn(["tickets", "board"], board);
570
+ // A block needs a board, so one init creates has none written yet.
571
+ if (creating)
572
+ for (const [key, name] of FACTORY_LINES)
573
+ doc.setIn(["tickets", "columns", key], name);
475
574
  try {
476
575
  const shape = boardShape(standing());
477
576
  const columns = await boardOps.addColumns(board, shape.columns);
@@ -616,6 +715,7 @@ export async function main(_argv, d) {
616
715
  ` FACTORY_BOARD_OWNER=${owner}`,
617
716
  ` FACTORY_BOARD_NUMBER=${board}`,
618
717
  " FACTORY_BOARD_TOKEN=the access token you just made",
718
+ ` FACTORY_READY_COLUMN=${columnsOf(standing()).Ready?.[0]}`,
619
719
  ].join("\n"));
620
720
  // Init asks for no command, so a gate is the owner's to add: without one
621
721
  // `factory gate` fails, and a build cannot finish.
@@ -627,8 +727,8 @@ export async function main(_argv, d) {
627
727
  d.out("");
628
728
  d.out("Checks");
629
729
  const found2 = await d.checks();
630
- for (const c of found2)
631
- d.out(` ${line(c)}`);
730
+ for (const l of printChecks(found2, d.paint, 2))
731
+ d.out(l);
632
732
  return found2.some((c) => c.state === "fail") ? 1 : 0;
633
733
  }
634
734
  /** The questions, asked at the terminal. */
@@ -674,7 +774,7 @@ export async function run(argv) {
674
774
  }
675
775
  },
676
776
  tools: TOOLS,
677
- sync: async () => (await import("./sync.mjs")).run([]),
777
+ sync: async () => (await import("./sync.mjs")).run([], false),
678
778
  // The settings are not written yet, so the code host asked is the one
679
779
  // setup has just opened, not the one a settings file names.
680
780
  syncChanges: async (text, host) => {
@@ -685,6 +785,7 @@ export async function run(argv) {
685
785
  const branch = await needDefaultBranch({ ...branchDeps(root), host });
686
786
  return differences(root, await syncPlan(PACKAGE, root, r, branch));
687
787
  },
788
+ presetBranchName: presetBranchNameAt(root),
688
789
  interactive: async (argv2) => spawnSync(argv2[0], argv2.slice(1), { stdio: "inherit" }).status ?? 1,
689
790
  hasCommand,
690
791
  openPage: (url) => {
@@ -717,6 +818,7 @@ export async function run(argv) {
717
818
  }
718
819
  },
719
820
  checks: () => doctorChecks(doctorDeps(root)),
821
+ paint: painter(colorOn()),
720
822
  packageName: manifest.name,
721
823
  packageVersion: manifest.version,
722
824
  };
@@ -0,0 +1,11 @@
1
+ import { styleText } from "node:util";
2
+ export type StyleFormat = Parameters<typeof styleText>[0];
3
+ export type Paint = (format: StyleFormat, text: string) => string;
4
+ export declare const plain: Paint;
5
+ /** Whether output to `stream` is colored, by Node's own rule: a terminal
6
+ * unless NO_COLOR, NODE_DISABLE_COLORS, or TERM=dumb, or wherever
7
+ * FORCE_COLOR says. */
8
+ export declare function colorOn(stream?: NodeJS.WritableStream): boolean;
9
+ /** Paints when `on`. The decision is made once, by `colorOn`, so painting
10
+ * skips Node's stream check: with it, a test's piped output stays plain. */
11
+ export declare function painter(on: boolean): Paint;
@@ -0,0 +1,15 @@
1
+ import { styleText } from "node:util";
2
+ export const plain = (_format, text) => text;
3
+ /** Whether output to `stream` is colored, by Node's own rule: a terminal
4
+ * unless NO_COLOR, NODE_DISABLE_COLORS, or TERM=dumb, or wherever
5
+ * FORCE_COLOR says. */
6
+ export function colorOn(stream = process.stdout) {
7
+ return styleText("red", "x", { stream }) !== "x";
8
+ }
9
+ /** Paints when `on`. The decision is made once, by `colorOn`, so painting
10
+ * skips Node's stream check: with it, a test's piped output stays plain. */
11
+ export function painter(on) {
12
+ return on
13
+ ? (format, text) => styleText(format, text, { validateStream: false })
14
+ : plain;
15
+ }
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)}`;
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.mjs CHANGED
@@ -210,7 +210,7 @@ const FIELDS = {
210
210
  };
211
211
  /** How many lines of a failed job's log `failed` prints, from its end. */
212
212
  const LOG_TAIL = 200;
213
- const USAGE = `Usage: npx --no-install factory pr state [N] [--wait] | threads N [--all] | reply N COMMENT_ID --body-file FILE | resolve N COMMENT_ID | ready N | closes N | wait-checks N | comments N [--author LOGIN] [--contains TEXT] [--json] | comment N --body-file FILE | comment-view ID | label N --add LABEL | --remove LABEL | review-pending N REVIEW | conflicts | open --title TITLE --body-file FILE [--base BRANCH] [--ready] | view N --field ${Object.keys(FIELDS).join("|")} | review N REVIEW | unverified N | uncovered [BASE] [LCOV] | failed N | review-again N`;
213
+ const USAGE = `Usage: npx --no-install factory pr state [N] [--wait] | threads N [--all] | reply N COMMENT_ID --body-file FILE | resolve N COMMENT_ID | ready N | closes N | for-branch BRANCH | wait-checks N | comments N [--author LOGIN] [--contains TEXT] [--json] | comment N --body-file FILE | comment-view ID | label N --add LABEL | --remove LABEL | review-pending N REVIEW | conflicts | open --title TITLE --body-file FILE [--base BRANCH] [--ready] | view N --field ${Object.keys(FIELDS).join("|")} | review N REVIEW | unverified N | uncovered [BASE] [LCOV] | failed N | review-again N`;
214
214
  function option(args, name) {
215
215
  const at = args.indexOf(name);
216
216
  if (at === -1)
@@ -367,6 +367,14 @@ export async function main(argv, d) {
367
367
  d.out("ready");
368
368
  return 0;
369
369
  }
370
+ case "for-branch": {
371
+ const [branch] = rest;
372
+ if (!branch || rest.length > 1)
373
+ throw new Error(USAGE);
374
+ const last = await p.lastForBranch(branch);
375
+ d.out(last ? `#${last.number} ${last.state}` : "none");
376
+ return 0;
377
+ }
370
378
  case "closes": {
371
379
  const [pr] = numbers;
372
380
  if (!pr)
@@ -1,3 +1,4 @@
1
+ import { type Paint } from "./lib/color.mts";
1
2
  import { type Resolved } from "./config.mts";
2
3
  import type { Check } from "./setup.mts";
3
4
  export type PresetDeps = {
@@ -25,6 +26,7 @@ export type PresetDeps = {
25
26
  resolve: (own: string, choices: string | null) => Promise<Resolved>;
26
27
  write: (path: string, text: string | null) => void;
27
28
  read: (path: string) => string | null;
29
+ paint?: Paint;
28
30
  };
29
31
  /** A value as the summaries show it: a list's items joined, a plugin by its
30
32
  * name. */
@@ -8,6 +8,7 @@
8
8
  // factory preset choose KEY PRESET
9
9
  // factory preset check
10
10
  // factory preset changes REF
11
+ import { colorOn, painter, plain } from "./lib/color.mjs";
11
12
  import { execFileSync, spawnSync } from "node:child_process";
12
13
  import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync, } from "node:fs";
13
14
  import { STATUS_CODES } from "node:http";
@@ -82,19 +83,21 @@ function valueInEffect(r, key) {
82
83
  return r.resolution.files.get(key)?.source;
83
84
  return getPath(r.resolution.raw, key.split("."));
84
85
  }
85
- function summary(head, groups, files) {
86
+ function summary(head, groups, files, paint) {
86
87
  const shown = groups.filter((g) => g.rows.length);
87
88
  const width = Math.max(0, ...shown.flatMap((g) => g.rows.map((r) => r.key.length))) + 3;
88
89
  return [
89
90
  head,
90
91
  "",
91
92
  ...shown.flatMap((g) => [
92
- ` ${g.title}`,
93
+ ` ${paint("bold", g.title)}`,
93
94
  ...g.rows.map((r) => ` ${r.key.padEnd(width)}${r.text}`),
94
95
  ]),
95
96
  ...(files.length ? ["", ...files.map((f) => ` ${f}`)] : []),
96
97
  ];
97
98
  }
99
+ /** An `OLD → NEW` row: the old value dim, the new one bold. */
100
+ const change = (paint, was, now) => `${paint("dim", was)} → ${paint("bold", now)}`;
98
101
  /** A question asked until the answer is one of `options`. */
99
102
  async function choose(d, question, options) {
100
103
  for (;;) {
@@ -282,6 +285,7 @@ async function syncing(d, wroteChoices) {
282
285
  // ---------------------------------------------------------------- add
283
286
  const PAREN = "this preset";
284
287
  export async function add(argv, d) {
288
+ const paint = d.paint ?? plain;
285
289
  const name = argv.find((a) => !a.startsWith("--"));
286
290
  const yes = argv.includes("--yes");
287
291
  const dry = argv.includes("--dry-run");
@@ -291,7 +295,7 @@ export async function add(argv, d) {
291
295
  }
292
296
  const ownText = d.read(SETTINGS_FILE);
293
297
  if (ownText === null) {
294
- d.err(`${SETTINGS_FILE} is missing. Run: npx --no-install factory init`);
298
+ d.err(`${SETTINGS_FILE} is missing. Run: factory init`);
295
299
  return 1;
296
300
  }
297
301
  const own = (await loadYaml(ownText));
@@ -380,13 +384,13 @@ export async function add(argv, d) {
380
384
  continue;
381
385
  }
382
386
  if (list) {
383
- added.push({ key: list, text: `+ ${show(mine)}` });
387
+ added.push({ key: list, text: paint("green", `+ ${show(mine)}`) });
384
388
  continue;
385
389
  }
386
390
  const was = getPath(effNow, key.split("."));
387
391
  if (stable(was) === stable(mine))
388
392
  continue;
389
- replacesDefault.push({ key, text: `${show(was)} → ${show(mine)}` });
393
+ replacesDefault.push({ key, text: change(paint, show(was), show(mine)) });
390
394
  }
391
395
  for (const path of VALUE_LISTS) {
392
396
  const was = getPath(effNow, path.split("."));
@@ -397,7 +401,7 @@ export async function add(argv, d) {
397
401
  for (const item of is)
398
402
  if (!had.has(stable(item)) &&
399
403
  after.resolution.sources.get(`${path}[${stable(item)}]`)?.from === name)
400
- added.push({ key: path, text: `+ ${show(item)}` });
404
+ added.push({ key: path, text: paint("green", `+ ${show(item)}`) });
401
405
  }
402
406
  const locked = await lockFiles(d);
403
407
  const writes = [...after.resolution.files]
@@ -412,7 +416,7 @@ export async function add(argv, d) {
412
416
  rows,
413
417
  })),
414
418
  { title: `replaced by your ${SETTINGS_FILE}`, rows: yours },
415
- ], writes))
419
+ ], writes, paint))
416
420
  d.out(line);
417
421
  if (dry) {
418
422
  undo();
@@ -471,6 +475,7 @@ async function lockFiles(d) {
471
475
  }
472
476
  // ---------------------------------------------------------------- remove
473
477
  export async function remove(argv, d) {
478
+ const paint = d.paint ?? plain;
474
479
  const name = argv.find((a) => !a.startsWith("--"));
475
480
  const yes = argv.includes("--yes");
476
481
  const dry = argv.includes("--dry-run");
@@ -521,17 +526,17 @@ export async function remove(argv, d) {
521
526
  if (!after.resolution.sources.has(key))
522
527
  removed.push({
523
528
  key: path,
524
- text: `− ${show(JSON.parse(key.slice(path.length + 1, -1)))}`,
529
+ text: paint("red", `− ${show(JSON.parse(key.slice(path.length + 1, -1)))}`),
525
530
  });
526
531
  continue;
527
532
  }
528
533
  if (!nextSrc) {
529
534
  if (list)
530
- removed.push({ key: list, text: `− ${show(old)}` });
535
+ removed.push({ key: list, text: paint("red", `− ${show(old)}`) });
531
536
  else
532
537
  toDefault.push({
533
538
  key,
534
- text: `${show(old)} → ${show(getPath(effAfter, key.split(".")))}`,
539
+ text: change(paint, show(old), show(getPath(effAfter, key.split(".")))),
535
540
  });
536
541
  continue;
537
542
  }
@@ -540,7 +545,7 @@ export async function remove(argv, d) {
540
545
  continue;
541
546
  const row = {
542
547
  key: list ?? key,
543
- text: `${show(old)} → ${show(next)}, from ${nextSrc.from}`,
548
+ text: `${change(paint, show(old), show(next))}, from ${nextSrc.from}`,
544
549
  };
545
550
  if (src.state === "chosen") {
546
551
  chosenAgainst.push(row);
@@ -559,7 +564,7 @@ export async function remove(argv, d) {
559
564
  { title: "back to the default", rows: toDefault },
560
565
  { title: "back to another preset's value", rows: toOther },
561
566
  { title: "back to a value you chose against", rows: chosenAgainst },
562
- ], deletes))
567
+ ], deletes, paint))
563
568
  d.out(line);
564
569
  if (dry)
565
570
  return 0;
@@ -1075,6 +1080,7 @@ export function presetDeps(root = repoRoot()) {
1075
1080
  out: (l) => console.log(l),
1076
1081
  err: (l) => console.error(l),
1077
1082
  terminal: Boolean(process.stdin.isTTY && process.stdout.isTTY),
1083
+ paint: painter(colorOn()),
1078
1084
  ask: async (question) => {
1079
1085
  const { createInterface } = await import("node:readline/promises");
1080
1086
  const rl = createInterface({
package/dist/preset.mjs CHANGED
@@ -7,7 +7,7 @@ import { createHash } from "node:crypto";
7
7
  import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
8
8
  import { dirname, join, relative, sep } from "node:path";
9
9
  import { DEFAULT_CODE_HOST } from "./code-host/index.mjs";
10
- import { ROLE_SHAPE, ROLES, SETTINGS_FILE, SETTINGS_KEYS } from "./config.mjs";
10
+ import { OWN_HEADING, ROLE_SHAPE, ROLES, SETTINGS_FILE, SETTINGS_KEYS, } from "./config.mjs";
11
11
  import { BUILT } from "./tool-names.mjs";
12
12
  import { NPMRC, refusal } from "./npmrc.mjs";
13
13
  export const PRESET_FILE = "factory-preset.yaml";
@@ -131,7 +131,8 @@ export function unknownKey(raw) {
131
131
  for (const [k, value] of Object.entries(v)) {
132
132
  const at = path ? `${path}.${k}` : k;
133
133
  const show = shown ? `${shown}.${k}` : k;
134
- if (!allowed.includes(k) && !extra.includes(k))
134
+ const own = path === "tickets.fields" && OWN_HEADING.test(k);
135
+ if (!allowed.includes(k) && !extra.includes(k) && !own)
135
136
  return `${show}: unknown key`;
136
137
  const inner = SETTINGS_KEYS[`${at}[]`] && Array.isArray(value)
137
138
  ? value
package/dist/setup.d.mts CHANGED
@@ -13,6 +13,9 @@ export type Check = {
13
13
  text: string;
14
14
  /** What to do about a failure. */
15
15
  fix?: string;
16
+ /** The heading `doctor` prints it under: a tool's name, or one of its
17
+ * own. */
18
+ group?: string;
16
19
  };
17
20
  /** A secret is needed for a part that is on, or always when `part` is
18
21
  * null, and any one of `anyOf` being set meets it. */
package/dist/site.d.mts CHANGED
@@ -57,4 +57,7 @@ export declare function givenUrls(argv: string[]): {
57
57
  before: string;
58
58
  after: string;
59
59
  } | null;
60
+ /** What `factory site stop` says: a kept comparison is always two sites,
61
+ * this branch's and the base's. */
62
+ export declare function stopMessage(stopped: boolean): string;
60
63
  export declare function run(argv: string[]): Promise<number>;