@davidbyoung/software-factory 0.1.2 → 0.1.3

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 (83) hide show
  1. package/README.md +8 -9
  2. package/dist/agent/claude-code.d.mts +3 -0
  3. package/dist/agent/claude-code.mjs +89 -0
  4. package/dist/agent/index.d.mts +2 -0
  5. package/dist/agent/index.mjs +5 -0
  6. package/dist/board.mjs +1 -1
  7. package/dist/cli.mjs +17 -2
  8. package/dist/code-host/github-setup.d.mts +5 -0
  9. package/dist/code-host/github-setup.mjs +133 -0
  10. package/dist/code-host/github.mjs +4 -0
  11. package/dist/code-host/index.d.mts +1 -1
  12. package/dist/code-host/index.mjs +2 -1
  13. package/dist/code-host/types.d.mts +2 -0
  14. package/dist/config.d.mts +26 -7
  15. package/dist/config.mjs +79 -26
  16. package/dist/doctor.d.mts +6 -14
  17. package/dist/doctor.mjs +52 -64
  18. package/dist/explain.d.mts +2 -0
  19. package/dist/explain.mjs +127 -0
  20. package/dist/init.d.mts +8 -12
  21. package/dist/init.mjs +179 -131
  22. package/dist/lib/has-command.d.mts +5 -0
  23. package/dist/lib/has-command.mjs +8 -0
  24. package/dist/lib/listed.d.mts +2 -0
  25. package/dist/lib/listed.mjs +4 -0
  26. package/dist/lib/work-status.d.mts +12 -2
  27. package/dist/lib/work-status.mjs +14 -3
  28. package/dist/parts.d.mts +18 -15
  29. package/dist/parts.mjs +15 -43
  30. package/dist/poller.d.mts +20 -3
  31. package/dist/poller.mjs +62 -15
  32. package/dist/remove.d.mts +11 -0
  33. package/dist/remove.mjs +156 -0
  34. package/dist/runner/github-actions.d.mts +1 -1
  35. package/dist/runner/github-actions.mjs +12 -0
  36. package/dist/runner/index.d.mts +1 -1
  37. package/dist/runner/index.mjs +2 -1
  38. package/dist/runner/setup.d.mts +2 -0
  39. package/dist/runner/setup.mjs +22 -0
  40. package/dist/runner/types.d.mts +3 -0
  41. package/dist/runner/types.mjs +0 -2
  42. package/dist/setup.d.mts +98 -0
  43. package/dist/setup.mjs +3 -0
  44. package/dist/status.d.mts +4 -4
  45. package/dist/status.mjs +8 -7
  46. package/dist/sync.d.mts +18 -0
  47. package/dist/sync.mjs +137 -7
  48. package/dist/tickets/github-setup.d.mts +2 -0
  49. package/dist/tickets/github-setup.mjs +50 -0
  50. package/dist/tickets/github.mjs +0 -2
  51. package/dist/tickets/index.mjs +2 -1
  52. package/dist/tickets/transport.mjs +1 -3
  53. package/dist/tickets/types.mjs +0 -2
  54. package/dist/tool-names.d.mts +11 -0
  55. package/dist/tool-names.mjs +20 -0
  56. package/dist/tools.d.mts +56 -0
  57. package/dist/tools.mjs +76 -0
  58. package/docs/builds.md +103 -51
  59. package/docs/cli.md +42 -42
  60. package/docs/configuration.md +34 -32
  61. package/docs/design.md +1 -1
  62. package/docs/developing.md +143 -68
  63. package/docs/existing-repo.md +20 -9
  64. package/docs/github/by-hand.md +321 -0
  65. package/docs/github/reference.md +65 -61
  66. package/docs/github/setup.md +83 -267
  67. package/docs/glossary.md +5 -4
  68. package/docs/limitations.md +12 -10
  69. package/docs/plugins.md +9 -14
  70. package/docs/quick-start.md +62 -105
  71. package/docs/removing.md +36 -16
  72. package/docs/skills.md +47 -37
  73. package/docs/updating.md +2 -6
  74. package/docs/workflow.md +13 -12
  75. package/package.json +1 -1
  76. package/poller.Dockerfile +10 -18
  77. package/rules.md +14 -12
  78. package/settings.schema.json +24 -0
  79. package/skills/factory-build/SKILL.md +1 -1
  80. package/skills/factory-trace/SKILL.md +79 -0
  81. package/workflows/factory-build.yml +5 -4
  82. package/workflows/factory-deps-auto-merge.yml +3 -2
  83. package/workflows/factory-poller.yml +46 -0
package/dist/config.mjs CHANGED
@@ -15,17 +15,26 @@ import { dirname, join } from "node:path";
15
15
  import { DEFAULT_CODE_HOST, unsupportedCodeHost } from "./code-host/index.mjs";
16
16
  import { matchesAny } from "./lib/glob.mjs";
17
17
  import { DEFAULT_RUNNER, unsupportedRunner } from "./runner/index.mjs";
18
- import { DEFAULT_COLUMNS, STATE_KEYS, sameName, } from "./lib/work-status.mjs";
18
+ import { BUILT, unsupported } from "./tool-names.mjs";
19
+ import { DEFAULT_COLUMNS, STATE_KEYS, sameName, watchOf, } from "./lib/work-status.mjs";
19
20
  export class SettingsError extends Error {
20
21
  }
21
22
  export const ROLES = ["mockups", "builder", "reviewer"];
22
23
  export const TRIGGERS = ["own-server", "github-action", "manual"];
24
+ /** How often the scheduled poller may check the board, in minutes: each
25
+ * divides an hour, so a schedule every N minutes keeps an even beat. */
26
+ export const POLL_MINUTES = [5, 10, 15, 30, 60];
23
27
  export const SPECS = ["none", "openspec"];
24
28
  const FIELD_DEFAULTS = {
25
29
  session: "Session",
26
30
  "runs-in": "Runs in",
27
31
  cost: "Cost",
28
32
  };
33
+ /** Each number the rules use, with its default. */
34
+ export const RULE_NUMBERS = {
35
+ "small-change-lines": 30,
36
+ "review-rounds": 2,
37
+ };
29
38
  /** Each kind of unattended session, with how long it may run by default. */
30
39
  export const SESSION_MINUTES = {
31
40
  build: 230,
@@ -61,12 +70,13 @@ export const SETTINGS_KEYS = {
61
70
  "ci-review",
62
71
  "site",
63
72
  "session-minutes",
73
+ "rules",
64
74
  ],
65
75
  tickets: ["type", "board", "columns", "fields"],
66
76
  "tickets.columns": Object.keys(STATE_KEYS),
67
77
  "tickets.fields": Object.keys(FIELD_DEFAULTS),
68
78
  "code-host": ["type"],
69
- builds: ["trigger", "runner"],
79
+ builds: ["trigger", "runner", "poll-minutes"],
70
80
  specs: ["type"],
71
81
  "auto-merge": ["allow", "deny", "commands"],
72
82
  "ci-review": ["commands"],
@@ -85,6 +95,7 @@ export const SETTINGS_KEYS = {
85
95
  ],
86
96
  "plugins[]": ["skill", "agent", "role", "files", "labels"],
87
97
  "session-minutes": Object.keys(SESSION_MINUTES),
98
+ rules: Object.keys(RULE_NUMBERS),
88
99
  };
89
100
  function wholeNumber(v, key, fallback) {
90
101
  if (v === undefined)
@@ -162,14 +173,14 @@ const fail = (key, message) => {
162
173
  throw new SettingsError(`${SETTINGS_FILE}: ${key}: ${message}`);
163
174
  };
164
175
  const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
165
- /** A block of settings. Its keys are `SETTINGS_KEYS[path]`, and `path` is
166
- * the block's `key` unless a list's item names it otherwise. */
167
- function object(v, key, path = key) {
176
+ /** A block of settings. Its keys are `SETTINGS_KEYS[path]` and `extra`,
177
+ * and `path` is the block's `key` unless a list's item names it otherwise. */
178
+ function object(v, key, path = key, extra = []) {
168
179
  if (v === undefined)
169
180
  return {};
170
181
  if (!isObj(v))
171
182
  return fail(key, "must be a block of settings");
172
- const allowed = SETTINGS_KEYS[path];
183
+ const allowed = [...SETTINGS_KEYS[path], ...extra];
173
184
  for (const k of Object.keys(v)) {
174
185
  if (!allowed.includes(k))
175
186
  fail(key ? `${key}.${k}` : k, "unknown key");
@@ -217,10 +228,10 @@ function names(v, key, defaults) {
217
228
  }));
218
229
  }
219
230
  /** A part you can swap, written as a block with a `type` or as one word. */
220
- function typed(v, key) {
231
+ function typed(v, key, extra) {
221
232
  if (typeof v === "string")
222
233
  return { type: v };
223
- return object(v, key);
234
+ return object(v, key, key, extra);
224
235
  }
225
236
  function plugin(v, i, exists) {
226
237
  const key = `plugins[${i}]`;
@@ -251,29 +262,51 @@ function plugin(v, i, exists) {
251
262
  /** The settings with every default filled in. Throws a SettingsError naming
252
263
  * the key on anything unsound. `exists` says whether a path from the root
253
264
  * exists, for the plug-ins' files. */
254
- export function parseSettings(raw, exists) {
265
+ export function parseSettings(raw, exists, built = BUILT) {
255
266
  const top = object(raw ?? {}, "");
256
267
  if (top.version !== 1)
257
268
  fail("version", "must be 1");
258
269
  if (typeof top.repository !== "string" ||
259
270
  !/^[\w.-]+\/[\w.-]+$/.test(top.repository))
260
271
  fail("repository", "must be owner/name");
261
- const tickets = typed(top.tickets, "tickets");
262
- if (tickets.type !== undefined && tickets.type !== "github")
272
+ const declared = (v) => {
273
+ const type = isObj(v) ? v.type : v;
274
+ return typeof type === "string" ? (built.tickets[type] ?? []) : [];
275
+ };
276
+ const ticketType = (isObj(top.tickets) ? top.tickets.type : top.tickets) ?? "github";
277
+ if (typeof ticketType !== "string" || !(ticketType in built.tickets))
263
278
  // The same words every ticket command fails with (`tickets/index.mts`).
264
- throw new SettingsError(`${SETTINGS_FILE}: tickets.type "${String(tickets.type)}" is not supported. "github" is the only ticket system built.`);
279
+ throw new SettingsError(`${SETTINGS_FILE}: ${unsupported("tickets.type", String(ticketType), "ticket system", Object.keys(built.tickets))}`);
280
+ const tickets = typed(top.tickets, "tickets", declared(top.tickets));
281
+ const options = Object.fromEntries(declared(top.tickets)
282
+ .filter((k) => tickets[k] !== undefined)
283
+ .map((k) => [
284
+ k,
285
+ typeof tickets[k] === "string" && tickets[k]
286
+ ? tickets[k]
287
+ : fail(`tickets.${k}`, "must be text"),
288
+ ]));
265
289
  const board = tickets.board;
266
290
  if (board !== undefined &&
267
291
  board !== "none" &&
268
292
  !(Number.isInteger(board) && board > 0))
269
293
  fail("tickets.board", "must be a whole number above zero, or none");
270
- const codeHost = typed(top["code-host"], "code-host").type;
271
- if (codeHost !== undefined && codeHost !== DEFAULT_CODE_HOST)
272
- throw new SettingsError(`${SETTINGS_FILE}: ${unsupportedCodeHost(String(codeHost))}`);
294
+ const codeHost = typed(top["code-host"], "code-host").type ?? DEFAULT_CODE_HOST;
295
+ if (typeof codeHost !== "string" || !built.codeHost.includes(codeHost))
296
+ throw new SettingsError(`${SETTINGS_FILE}: ${unsupportedCodeHost(String(codeHost), built.codeHost)}`);
273
297
  const builds = object(top.builds, "builds");
274
298
  const trigger = oneOf(builds.trigger, "builds.trigger", TRIGGERS, "manual");
275
- if (builds.runner !== undefined && builds.runner !== DEFAULT_RUNNER)
276
- throw new SettingsError(`${SETTINGS_FILE}: ${unsupportedRunner(String(builds.runner))}`);
299
+ const minutes = builds["poll-minutes"];
300
+ if (minutes !== undefined && trigger !== "github-action")
301
+ throw new SettingsError(`${SETTINGS_FILE}: builds.poll-minutes needs builds.trigger: github-action`);
302
+ const pollMinutes = minutes === undefined
303
+ ? 5
304
+ : POLL_MINUTES.includes(minutes)
305
+ ? minutes
306
+ : fail("builds.poll-minutes", `must be one of ${POLL_MINUTES.join(", ")}`);
307
+ const runner = builds.runner ?? DEFAULT_RUNNER;
308
+ if (typeof runner !== "string" || !built.runner.includes(runner))
309
+ throw new SettingsError(`${SETTINGS_FILE}: ${unsupportedRunner(String(runner), built.runner)}`);
277
310
  const hasBoard = typeof board === "number";
278
311
  if (tickets.columns !== undefined && !hasBoard)
279
312
  fail("tickets.columns", "needs tickets.board");
@@ -309,13 +342,14 @@ export function parseSettings(raw, exists) {
309
342
  version: 1,
310
343
  repository: top.repository,
311
344
  tickets: {
312
- type: "github",
345
+ type: ticketType,
346
+ options,
313
347
  board: typeof board === "number" ? board : null,
314
348
  columns,
315
349
  fields: fieldNames,
316
350
  },
317
- codeHost: { type: DEFAULT_CODE_HOST },
318
- builds: { trigger, runner: DEFAULT_RUNNER },
351
+ codeHost: { type: codeHost },
352
+ builds: { trigger, runner, pollMinutes },
319
353
  specs: oneOf(specs.type, "specs", SPECS, "none"),
320
354
  beforeCommit: strings(top["before-commit"], "before-commit"),
321
355
  buildSetup: strings(top["build-setup"], "build-setup"),
@@ -328,6 +362,7 @@ export function parseSettings(raw, exists) {
328
362
  ciReview: ciReview && { commands: reviewCommands(ciReview.commands) },
329
363
  site,
330
364
  sessionMinutes: sessionMinutesOf(top["session-minutes"]),
365
+ rules: rulesOf(top.rules),
331
366
  };
332
367
  }
333
368
  function sessionMinutesOf(v) {
@@ -337,6 +372,14 @@ function sessionMinutesOf(v) {
337
372
  wholeNumber(o[kind], `session-minutes.${kind}`, fallback),
338
373
  ]));
339
374
  }
375
+ function rulesOf(v) {
376
+ const o = object(v ?? {}, "rules");
377
+ const n = (k) => wholeNumber(o[k], `rules.${k}`, RULE_NUMBERS[k]);
378
+ return {
379
+ smallChangeLines: n("small-change-lines"),
380
+ reviewRounds: n("review-rounds"),
381
+ };
382
+ }
340
383
  /** One line for each pattern that matches none of `files`: a stale pattern
341
384
  * is how a policy rots. */
342
385
  export function patternWarnings(s, files) {
@@ -356,6 +399,10 @@ export const NO_DEPENDENCIES = "The factory's settings cannot be read until depe
356
399
  /** js-yaml is loaded when needed, so a checkout without dependencies gets
357
400
  * one line saying what to do rather than a stack trace. */
358
401
  async function read(d) {
402
+ return parseSettings(await readRaw(d), d.exists);
403
+ }
404
+ /** The file as it is written, before any default is filled in. */
405
+ async function readRaw(d) {
359
406
  let load;
360
407
  try {
361
408
  load = await d.loadYaml();
@@ -363,14 +410,12 @@ async function read(d) {
363
410
  catch {
364
411
  throw new SettingsError(NO_DEPENDENCIES);
365
412
  }
366
- let raw;
367
413
  try {
368
- raw = load(d.readFile());
414
+ return load(d.readFile());
369
415
  }
370
416
  catch (e) {
371
417
  throw new SettingsError(`${SETTINGS_FILE}: ${e.message}`);
372
418
  }
373
- return parseSettings(raw, d.exists);
374
419
  }
375
420
  /** The settings file: FACTORY_SETTINGS where it is set, for trying settings
376
421
  * against a board without changing the repository's, and otherwise the
@@ -456,12 +501,14 @@ export function pluginsOf(s, exists) {
456
501
  export async function main(argv, d) {
457
502
  const [command, arg] = argv;
458
503
  if (!command) {
459
- d.err("Usage: factory config get KEY | config check | plugins [ROLE]");
504
+ d.err("Usage: factory config get KEY | config check | config explain | plugins [ROLE]");
460
505
  return 2;
461
506
  }
462
507
  let s;
508
+ let raw;
463
509
  try {
464
- s = await read(d);
510
+ raw = await readRaw(d);
511
+ s = parseSettings(raw, d.exists);
465
512
  }
466
513
  catch (e) {
467
514
  if (!(e instanceof SettingsError))
@@ -481,6 +528,12 @@ export async function main(argv, d) {
481
528
  d.err(`warning: ${DESIGN_SKILL} is missing: run \`npx --no-install factory sync\` to give the site its design skill`);
482
529
  return 0;
483
530
  }
531
+ if (command === "explain") {
532
+ const { explainLines } = await import("./explain.mjs");
533
+ for (const line of await explainLines(s, raw))
534
+ d.out(line);
535
+ return 0;
536
+ }
484
537
  if (command === "plugins") {
485
538
  for (const p of pluginsOf(s, d.exists)) {
486
539
  if (arg && p.role !== arg)
@@ -524,7 +577,7 @@ export function targetOf(s, env) {
524
577
  board: env.FACTORY_BOARD_NUMBER
525
578
  ? Number(env.FACTORY_BOARD_NUMBER)
526
579
  : s.tickets.board,
527
- watched: s.builds.trigger !== "manual",
580
+ watch: watchOf(s.builds.trigger, s.builds.pollMinutes),
528
581
  columns: columnsOf(s),
529
582
  };
530
583
  }
package/dist/doctor.d.mts CHANGED
@@ -1,13 +1,7 @@
1
- import { type CodeHost } from "./code-host/index.mts";
2
1
  import { type Settings } from "./config.mts";
3
- import { type Runner } from "./runner/index.mts";
4
- import { type Tickets } from "./tickets/index.mts";
5
- export type Check = {
6
- state: "pass" | "fail" | "off";
7
- text: string;
8
- /** What to do about a failure. */
9
- fix?: string;
10
- };
2
+ import type { Check } from "./setup.mts";
3
+ import { type Registry } from "./tools.mts";
4
+ export type { Check } from "./setup.mts";
11
5
  export type DoctorDeps = {
12
6
  settings: () => Promise<Settings>;
13
7
  /** The paths a sync would change. */
@@ -17,11 +11,9 @@ export type DoctorDeps = {
17
11
  installed: string;
18
12
  locked: string | null;
19
13
  };
20
- open: (s: Settings) => {
21
- codeHost: CodeHost;
22
- runner: Runner;
23
- tickets: Tickets | Promise<Tickets>;
24
- };
14
+ root: string;
15
+ hasCommand: (name: string) => boolean;
16
+ tools: Registry;
25
17
  out: (line: string) => void;
26
18
  };
27
19
  export declare function checks(d: DoctorDeps): Promise<Check[]>;
package/dist/doctor.mjs CHANGED
@@ -6,18 +6,18 @@
6
6
  // being set.
7
7
  import { readFileSync } from "node:fs";
8
8
  import { join } from "node:path";
9
- import { boardConfigOf, inspectBoard } from "./board.mjs";
10
- import { openCodeHost } from "./code-host/index.mjs";
11
9
  import { defaultDeps, loadSettings, repoRoot, } from "./config.mjs";
12
- import { neededSecrets, PART_TEXT, PARTS, partsOn } from "./parts.mjs";
13
- import { openRunner } from "./runner/index.mjs";
10
+ import { hasCommand } from "./lib/has-command.mjs";
11
+ import { neededSecrets, PART_TEXT, PARTS, partsOn, } from "./parts.mjs";
14
12
  import { differences, LOCK, PACKAGE, plan } from "./sync.mjs";
15
- import { openTickets } from "./tickets/index.mjs";
13
+ import { inUse, secretSteps, TOOLS } from "./tools.mjs";
16
14
  const SYNC = "Run npx --no-install factory sync";
17
15
  const INIT = "Run npx --no-install factory init";
18
16
  const message = (e) => (e instanceof Error ? e.message : String(e));
19
17
  /** -1, 0, or 1 as version `a` is older than, the same as, or newer than `b`. */
20
18
  function compareVersions(a, b) {
19
+ if (a === b)
20
+ return 0;
21
21
  const pa = a.split(/[.-]/).map(Number);
22
22
  const pb = b.split(/[.-]/).map(Number);
23
23
  for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
@@ -64,23 +64,32 @@ export async function checks(d) {
64
64
  text: `Version ${installed} is installed, but the repository records ${locked}`,
65
65
  fix: compareVersions(installed, locked) < 0 ? "Run npm ci" : SYNC,
66
66
  });
67
- const { codeHost, runner, tickets } = d.open(s);
68
- try {
69
- out.push({
70
- state: "pass",
71
- text: `Signed in to the code host as ${await codeHost.signedInAs()}`,
72
- });
73
- }
74
- catch (e) {
75
- out.push({
76
- state: "fail",
77
- text: "Signed in to the code host",
78
- fix: message(e),
79
- });
80
- }
67
+ const chosen = {
68
+ codeHost: s.codeHost.type,
69
+ tickets: s.tickets.type,
70
+ runner: s.builds.runner,
71
+ agent: Object.keys(d.tools.agent)[0],
72
+ };
73
+ const opened = {
74
+ codeHost: d.tools.codeHost[chosen.codeHost].open(s.repository),
75
+ runner: d.tools.runner[chosen.runner].open(s.repository),
76
+ tickets: await d.tools.tickets[chosen.tickets].open({ repository: s.repository, board: s.tickets.board }, s),
77
+ };
78
+ const context = (parts) => ({
79
+ repository: s.repository,
80
+ root: d.root,
81
+ parts: new Set(parts),
82
+ chosen,
83
+ settings: s,
84
+ hasCommand: d.hasCommand,
85
+ opened,
86
+ });
87
+ const [agent, codeHost, tickets, runner] = inUse(d.tools, chosen);
88
+ out.push(...((await codeHost.setup.checks?.({ ...context([]), secrets: null })) ??
89
+ []));
81
90
  let secrets;
82
91
  try {
83
- secrets = await runner.secretNames();
92
+ secrets = await opened.runner.secretNames();
84
93
  }
85
94
  catch (e) {
86
95
  secrets = null;
@@ -90,8 +99,19 @@ export async function checks(d) {
90
99
  fix: message(e),
91
100
  });
92
101
  }
93
- const on = partsOn(s, secrets ?? []);
94
- const needed = neededSecrets(on);
102
+ const cloudNeeds = secretSteps(d.tools, context(["cloud"])).flatMap((x) => x.step.needs.filter((n) => n.part === "cloud"));
103
+ const on = partsOn(s, secrets ?? [], cloudNeeds);
104
+ const needed = neededSecrets(on, secretSteps(d.tools, context(on)));
105
+ const secretLine = (anyOf, forWhat) => {
106
+ const found = anyOf.find((n) => secrets.includes(n));
107
+ return found
108
+ ? { state: "pass", text: `${found} is set, for ${forWhat}` }
109
+ : {
110
+ state: "fail",
111
+ text: `${anyOf.join(" or ")} is not set, for ${forWhat}`,
112
+ fix: INIT,
113
+ };
114
+ };
95
115
  for (const part of PARTS) {
96
116
  if (!on.has(part)) {
97
117
  out.push({ state: "off", text: `${PART_TEXT[part].name}: off` });
@@ -100,41 +120,14 @@ export async function checks(d) {
100
120
  if (secrets === null)
101
121
  continue;
102
122
  const forPart = PART_TEXT[part].name.replace(/^./, (c) => c.toLowerCase());
103
- for (const need of needed.filter((n) => n.part === part)) {
104
- const found = need.anyOf.find((n) => secrets.includes(n));
105
- out.push(found
106
- ? { state: "pass", text: `${found} is set, for ${forPart}` }
107
- : {
108
- state: "fail",
109
- text: `${need.anyOf.join(" or ")} is not set, for ${forPart}`,
110
- fix: INIT,
111
- });
112
- }
113
- }
114
- if (s.tickets.board !== null) {
115
- const number = s.tickets.board;
116
- try {
117
- const board = await (await tickets).board.read();
118
- const { problems } = inspectBoard(board.fields, boardConfigOf(s));
119
- out.push(problems.length === 0
120
- ? {
121
- state: "pass",
122
- text: `Board ${number} has every column the settings name`,
123
- }
124
- : {
125
- state: "fail",
126
- text: `Board ${number}: ${problems.join("; ")}`,
127
- fix: INIT,
128
- });
129
- }
130
- catch (e) {
131
- out.push({
132
- state: "fail",
133
- text: `Board ${number} can be read`,
134
- fix: message(e),
135
- });
136
- }
123
+ for (const need of needed.filter((n) => n.part === part))
124
+ out.push(secretLine(need.anyOf, forPart));
137
125
  }
126
+ if (secrets !== null)
127
+ for (const need of needed.filter((n) => n.part === null))
128
+ out.push(secretLine(need.anyOf, need.tool));
129
+ for (const tool of [tickets, runner, agent])
130
+ out.push(...((await tool.setup.checks?.({ ...context(on), secrets })) ?? []));
138
131
  return out;
139
132
  }
140
133
  /** One check as a line: a tick, a cross with what to do, or a dash for a
@@ -172,14 +165,9 @@ export function doctorDeps(root = repoRoot()) {
172
165
  }
173
166
  return { installed, locked };
174
167
  },
175
- open: (s) => ({
176
- codeHost: openCodeHost(s.repository, s.codeHost.type),
177
- runner: openRunner(s.repository, s.builds.runner),
178
- tickets: openTickets(s, {
179
- repository: s.repository,
180
- board: s.tickets.board,
181
- }).then((o) => o.tickets),
182
- }),
168
+ root,
169
+ hasCommand,
170
+ tools: TOOLS,
183
171
  out: (l) => console.log(l),
184
172
  };
185
173
  }
@@ -0,0 +1,2 @@
1
+ import type { Settings } from "./config.mts";
2
+ export declare function explainLines(s: Settings, raw: unknown): Promise<string[]>;
@@ -0,0 +1,127 @@
1
+ const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
2
+ /** Whether the file sets `path`, each step a key into the raw file. A
3
+ * block written as one word, such as `code-host: github`, sets its `type`. */
4
+ function sets(raw, path) {
5
+ let at = raw;
6
+ for (const key of path) {
7
+ if (typeof at === "string" && key === "type")
8
+ return true;
9
+ if (!isObj(at) || !(key in at))
10
+ return false;
11
+ at = at[key];
12
+ }
13
+ return true;
14
+ }
15
+ export async function explainLines(s, raw) {
16
+ const { stringify } = await import("yaml");
17
+ const value = (v) => stringify(v, { lineWidth: 0 }).trim();
18
+ const lines = [];
19
+ const pad = (depth) => " ".repeat(depth);
20
+ /** One key, its value printed under it when it is a list or a block. */
21
+ const put = (path, v, depth = path.length - 1) => {
22
+ const key = path.at(-1);
23
+ const byDefault = !sets(raw, path);
24
+ if (Array.isArray(v) && v.length && typeof v[0] !== "object") {
25
+ lines.push({ text: `${pad(depth)}${key}:`, byDefault });
26
+ for (const item of v)
27
+ lines.push({ text: `${pad(depth + 1)}- ${value(item)}`, byDefault });
28
+ return;
29
+ }
30
+ lines.push({ text: `${pad(depth)}${key}: ${value(v)}`, byDefault });
31
+ };
32
+ const block = (path) => lines.push({
33
+ text: `${pad(path.length - 1)}${path.at(-1)}:`,
34
+ byDefault: false,
35
+ });
36
+ const comment = (depth, text) => lines.push({ text: `${pad(depth)}# ${text}`, byDefault: false });
37
+ put(["version"], s.version);
38
+ put(["repository"], s.repository);
39
+ block(["tickets"]);
40
+ put(["tickets", "type"], s.tickets.type);
41
+ for (const [k, v] of Object.entries(s.tickets.options))
42
+ put(["tickets", k], v);
43
+ if (s.tickets.board === null)
44
+ comment(1, "board: none (default)");
45
+ else {
46
+ put(["tickets", "board"], s.tickets.board);
47
+ block(["tickets", "columns"]);
48
+ for (const [k, v] of Object.entries(s.tickets.columns))
49
+ put(["tickets", "columns", k], v ?? "none");
50
+ block(["tickets", "fields"]);
51
+ for (const [k, v] of Object.entries(s.tickets.fields))
52
+ put(["tickets", "fields", k], v ?? "none");
53
+ }
54
+ put(["code-host"], s.codeHost.type);
55
+ block(["builds"]);
56
+ put(["builds", "trigger"], s.builds.trigger);
57
+ put(["builds", "runner"], s.builds.runner);
58
+ if (s.builds.trigger === "github-action")
59
+ put(["builds", "poll-minutes"], s.builds.pollMinutes);
60
+ else
61
+ comment(1, "poll-minutes: only with trigger github-action");
62
+ put(["specs"], s.specs);
63
+ put(["before-commit"], s.beforeCommit);
64
+ put(["build-setup"], s.buildSetup);
65
+ if (!s.plugins.length)
66
+ put(["plugins"], []);
67
+ else {
68
+ block(["plugins"]);
69
+ for (const p of s.plugins) {
70
+ lines.push({ text: ` - ${p.kind}: ${value(p.name)}`, byDefault: false });
71
+ lines.push({ text: ` role: ${p.role}`, byDefault: false });
72
+ for (const [k, list] of [
73
+ ["files", p.files],
74
+ ["labels", p.labels],
75
+ ])
76
+ if (list.length) {
77
+ lines.push({ text: ` ${k}:`, byDefault: false });
78
+ for (const item of list)
79
+ lines.push({ text: ` - ${value(item)}`, byDefault: false });
80
+ }
81
+ }
82
+ }
83
+ block(["auto-merge"]);
84
+ put(["auto-merge", "allow"], s.autoMerge.allow);
85
+ put(["auto-merge", "deny"], s.autoMerge.deny);
86
+ put(["auto-merge", "commands"], s.autoMerge.commands);
87
+ if (s.ciReview === null)
88
+ comment(0, "ci-review: off");
89
+ else {
90
+ block(["ci-review"]);
91
+ put(["ci-review", "commands"], s.ciReview.commands);
92
+ }
93
+ if (s.site === null)
94
+ comment(0, "site: off");
95
+ else {
96
+ const site = s.site;
97
+ block(["site"]);
98
+ put(["site", "start"], site.start);
99
+ put(["site", "url"], site.url);
100
+ if (site.designGuide === null)
101
+ comment(1, "design-guide: none (default)");
102
+ else
103
+ put(["site", "design-guide"], site.designGuide);
104
+ if (site.pages === null)
105
+ comment(1, "pages: found by the factory (default)");
106
+ else
107
+ put(["site", "pages"], site.pages);
108
+ put(["site", "widths"], site.widths);
109
+ put(["site", "hide"], site.hide);
110
+ put(["site", "checks"], site.checks);
111
+ put(["site", "max-pages"], site.maxPages);
112
+ put(["site", "start-minutes"], site.startMinutes);
113
+ put(["site", "accessibility"], site.accessibility);
114
+ put(["site", "new-values"], site.newValues);
115
+ }
116
+ block(["session-minutes"]);
117
+ for (const [k, v] of Object.entries(s.sessionMinutes))
118
+ put(["session-minutes", k], v);
119
+ block(["rules"]);
120
+ put(["rules", "small-change-lines"], s.rules.smallChangeLines);
121
+ put(["rules", "review-rounds"], s.rules.reviewRounds);
122
+ // Each default's mark lines up with the others, two spaces past the
123
+ // longest line that carries one.
124
+ const marked = lines.filter((l) => l.byDefault);
125
+ const at = Math.max(0, ...marked.map((l) => l.text.length)) + 2;
126
+ return lines.map((l) => l.byDefault ? `${l.text.padEnd(at)}# default` : l.text);
127
+ }
package/dist/init.d.mts CHANGED
@@ -1,7 +1,5 @@
1
- import { type CodeHost } from "./code-host/index.mts";
2
- import { type Check } from "./doctor.mts";
3
- import { type Runner } from "./runner/index.mts";
4
- import type { Tickets } from "./tickets/types.mts";
1
+ import { type Registry } from "./tools.mts";
2
+ import { type Check } from "./setup.mts";
5
3
  /** The questions init asks. Each is answered at the terminal, and in tests
6
4
  * from a script. */
7
5
  export type Ask = {
@@ -15,7 +13,9 @@ export type Ask = {
15
13
  select(message: string, choices: {
16
14
  name: string;
17
15
  value: string;
18
- }[]): Promise<string>;
16
+ }[],
17
+ /** The value chosen when the person picks nothing else. */
18
+ fallback?: string): Promise<string>;
19
19
  confirm(message: string, fallback: boolean): Promise<boolean>;
20
20
  /** Read without echoing what is typed. */
21
21
  secret(message: string): Promise<string>;
@@ -27,11 +27,7 @@ export type InitDeps = {
27
27
  out: (line: string) => void;
28
28
  /** The `origin` remote's address, or null without one. */
29
29
  remote: () => string | null;
30
- open: (repository: string) => {
31
- codeHost: CodeHost;
32
- runner: Runner;
33
- tickets: Tickets;
34
- };
30
+ tools: Registry;
35
31
  sync: () => Promise<number>;
36
32
  /** The files a sync with these settings would write or delete. */
37
33
  syncChanges: (settingsText: string) => string[];
@@ -50,8 +46,8 @@ export type InitDeps = {
50
46
  };
51
47
  /** The repository and code host a remote's address names, or null for one
52
48
  * on a code host the factory does not support. */
53
- export declare function parseRemote(url: string): {
54
- codeHost: "github";
49
+ export declare function parseRemote(url: string, tools?: Registry): {
50
+ codeHost: string;
55
51
  repository: string;
56
52
  } | null;
57
53
  export declare function main(_argv: string[], d: InitDeps): Promise<number>;