@davidbyoung/software-factory 0.1.8 → 0.1.9

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 (51) 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 +126 -38
  5. package/dist/cli.mjs +75 -9
  6. package/dist/code-host/github-setup.mjs +2 -2
  7. package/dist/columns-suggest.d.mts +0 -1
  8. package/dist/columns-suggest.mjs +2 -8
  9. package/dist/commands.d.mts +2 -0
  10. package/dist/commands.mjs +22 -11
  11. package/dist/config.d.mts +9 -0
  12. package/dist/config.mjs +57 -11
  13. package/dist/doctor.d.mts +6 -1
  14. package/dist/doctor.mjs +79 -18
  15. package/dist/explain.d.mts +5 -0
  16. package/dist/explain.mjs +29 -0
  17. package/dist/init.d.mts +2 -0
  18. package/dist/init.mjs +50 -9
  19. package/dist/lib/color.d.mts +11 -0
  20. package/dist/lib/color.mjs +15 -0
  21. package/dist/preset-commands.d.mts +2 -0
  22. package/dist/preset-commands.mjs +18 -12
  23. package/dist/preset.mjs +3 -2
  24. package/dist/setup.d.mts +3 -0
  25. package/dist/site.d.mts +3 -0
  26. package/dist/site.mjs +8 -1
  27. package/dist/status.d.mts +5 -2
  28. package/dist/status.mjs +13 -22
  29. package/dist/sync.d.mts +7 -1
  30. package/dist/sync.mjs +17 -5
  31. package/dist/ticket-fields.d.mts +84 -0
  32. package/dist/ticket-fields.mjs +374 -0
  33. package/dist/ticket.mjs +8 -7
  34. package/dist/tickets/github-setup.mjs +1 -1
  35. package/dist/tickets/github.mjs +69 -0
  36. package/dist/tickets/index.d.mts +8 -1
  37. package/dist/tickets/index.mjs +67 -7
  38. package/dist/tickets/types.d.mts +27 -1
  39. package/dist/tickets/types.mjs +4 -0
  40. package/dist/tools.d.mts +1 -1
  41. package/docs/cli.md +44 -10
  42. package/docs/configuration.md +78 -25
  43. package/docs/design.md +10 -0
  44. package/docs/developing.md +49 -18
  45. package/docs/existing-repo.md +137 -8
  46. package/docs/github/setup.md +5 -0
  47. package/docs/quick-start.md +3 -3
  48. package/docs/skills.md +3 -1
  49. package/docs/updating.md +3 -3
  50. package/package.json +4 -2
  51. package/settings.schema.json +68 -11
package/dist/config.mjs CHANGED
@@ -8,6 +8,7 @@
8
8
  // factory config check # prints nothing when sound
9
9
  //
10
10
  // A list prints one item per line. A failure names the key and exits 1.
11
+ import { colorOn, painter, plain } from "./lib/color.mjs";
11
12
  import { execFileSync } from "node:child_process";
12
13
  import { existsSync, readFileSync } from "node:fs";
13
14
  import { createRequire } from "node:module";
@@ -15,6 +16,7 @@ import { dirname, join } from "node:path";
15
16
  import { DEFAULT_CODE_HOST, unsupportedCodeHost } from "./code-host/index.mjs";
16
17
  import { matchesAny } from "./lib/glob.mjs";
17
18
  import { DEFAULT_RUNNER, unsupportedRunner } from "./runner/index.mjs";
19
+ import { FACTORY_FIELDS } from "./ticket-fields.mjs";
18
20
  import { BUILT, unsupported } from "./tool-names.mjs";
19
21
  import { DEFAULT_COLUMNS, STATE_KEYS, sameName, watchOf, } from "./lib/work-status.mjs";
20
22
  export class SettingsError extends Error {
@@ -144,7 +146,10 @@ export const SETTINGS_KEYS = {
144
146
  ],
145
147
  tickets: ["type", "board", "columns", "fields"],
146
148
  "tickets.columns": Object.keys(STATE_KEYS),
147
- "tickets.fields": Object.keys(FIELD_DEFAULTS),
149
+ "tickets.fields": [
150
+ ...Object.keys(FIELD_DEFAULTS),
151
+ ...FACTORY_FIELDS.map((f) => f.key),
152
+ ],
148
153
  "code-host": ["type"],
149
154
  builds: ["trigger", "runner", "poll-minutes"],
150
155
  specs: ["type", "check"],
@@ -312,6 +317,36 @@ function names(v, key, defaults) {
312
317
  return [k, value.trim()];
313
318
  }));
314
319
  }
320
+ /** A key under `tickets.fields` naming a heading of the repository's own. */
321
+ export const OWN_HEADING = /^[a-z0-9]+(-[a-z0-9]+)*$/;
322
+ /** The ticket-side keys under `tickets.fields`: the four factory fields,
323
+ * each a ticket field's name or none, and any other key a heading of the
324
+ * repository's own. Spec and Acceptance criteria may share a field. */
325
+ function ticketFieldsOf(o) {
326
+ const out = Object.fromEntries(FACTORY_FIELDS.map((f) => [f.key, null]));
327
+ const seen = [];
328
+ for (const [k, value] of Object.entries(o)) {
329
+ if (k in FIELD_DEFAULTS)
330
+ continue;
331
+ const key = `tickets.fields.${k}`;
332
+ if (!FACTORY_FIELDS.some((f) => f.key === k) && !OWN_HEADING.test(k))
333
+ fail(key, "must be a heading in lowercase, with hyphens for spaces");
334
+ if (value === "none") {
335
+ out[k] = null;
336
+ continue;
337
+ }
338
+ if (typeof value !== "string" || !value.trim())
339
+ fail(key, "must be a name, or none");
340
+ const name = value.trim();
341
+ const other = seen.find(([o, n]) => sameName(n, name) &&
342
+ !([o, k].includes("spec") && [o, k].includes("acceptance-criteria")));
343
+ if (other)
344
+ fail(key, `names the same field as ${other[0]}`);
345
+ seen.push([k, name]);
346
+ out[k] = name;
347
+ }
348
+ return out;
349
+ }
315
350
  /** Each state's columns: a name, a list of names, or none, each left out
316
351
  * keeping the factory's own name. Only an approved ticket goes to ready,
317
352
  * so it takes one name. */
@@ -506,7 +541,9 @@ export function parseSettings(raw, exists, built = BUILT) {
506
541
  const hasBoard = typeof board === "number";
507
542
  if (tickets.columns !== undefined && !hasBoard)
508
543
  fail("tickets.columns", "needs tickets.board");
509
- if (tickets.fields !== undefined && !hasBoard)
544
+ const rawFields = isObj(tickets.fields) ? tickets.fields : {};
545
+ const boardFields = Object.fromEntries(Object.entries(rawFields).filter(([k]) => k in FIELD_DEFAULTS));
546
+ if (Object.keys(boardFields).length && !hasBoard)
510
547
  fail("tickets.fields", "needs tickets.board");
511
548
  const columns = columnNames(tickets.columns);
512
549
  if (columns.backlog === null)
@@ -525,7 +562,10 @@ export function parseSettings(raw, exists, built = BUILT) {
525
562
  }
526
563
  if (columns.ready === null && trigger !== "manual")
527
564
  fail("tickets.columns.ready", "no column shows ready, so nothing would start a build: name one, or set builds.trigger to manual");
528
- const fieldNames = names(tickets.fields, "tickets.fields", FIELD_DEFAULTS);
565
+ if (tickets.fields !== undefined && !isObj(tickets.fields))
566
+ fail("tickets.fields", "must be a block of settings");
567
+ const fieldNames = names(boardFields, "tickets.fields", FIELD_DEFAULTS);
568
+ const ticketFields = ticketFieldsOf(rawFields);
529
569
  const specsBlock = typed(top.specs ?? "none", "specs");
530
570
  const specs = oneOf(specsBlock.type, "specs", SPECS, "none");
531
571
  if (specsBlock.check !== undefined && specs !== "openspec")
@@ -564,6 +604,7 @@ export function parseSettings(raw, exists, built = BUILT) {
564
604
  board: typeof board === "number" ? board : null,
565
605
  columns,
566
606
  fields: fieldNames,
607
+ ticketFields,
567
608
  },
568
609
  codeHost: { type: codeHost },
569
610
  builds: { trigger, runner, pollMinutes },
@@ -875,6 +916,7 @@ export const defaultDeps = (root = repoRoot(), env = process.env) => ({
875
916
  loadYaml: async () => (await import("js-yaml")).load,
876
917
  out: (line) => console.log(line),
877
918
  err: (line) => console.error(line),
919
+ paint: painter(colorOn()),
878
920
  });
879
921
  /** The column each state shows in on the board, null for none. */
880
922
  export function columnsOf(s) {
@@ -1005,17 +1047,21 @@ export async function main(argv, d) {
1005
1047
  d.err(`warning: ${w}`);
1006
1048
  if (s.site && !s.plugins.some((p) => p.role === "mockups"))
1007
1049
  if (!d.exists(DESIGN_SKILL))
1008
- d.err(`warning: ${DESIGN_SKILL} is missing: run \`npx --no-install factory sync\` to give the site its design skill`);
1050
+ d.err(`warning: ${DESIGN_SKILL} is missing: run \`factory sync\` to give the site its design skill`);
1051
+ d.out(`${(d.paint ?? plain)("green", "✓")} The settings are valid.`);
1009
1052
  return 0;
1010
1053
  }
1011
1054
  if (command === "explain") {
1012
- if (lockText !== null) {
1013
- for (const line of lockSettingsLines(lockText))
1014
- d.out(line);
1015
- return 0;
1016
- }
1017
- const { explainLines, markerOf } = await import("./explain.mjs");
1018
- for (const line of await explainLines(s, markerOf(resolved.resolution), resolved.exists))
1055
+ const { explainLines, markerOf, paintExplainLines } = await import("./explain.mjs");
1056
+ const lines = lockText !== null
1057
+ ? lockSettingsLines(lockText)
1058
+ : await explainLines(s, markerOf(resolved.resolution), resolved.exists);
1059
+ // Printed only: the lock holds the settings, not how to read them.
1060
+ const header = [
1061
+ '# The settings in effect. "# default" marks the factory\'s own value,',
1062
+ "# a preset's name marks that preset's, and an unmarked line is yours.",
1063
+ ];
1064
+ for (const line of paintExplainLines([...header, ...lines], d.paint ?? plain))
1019
1065
  d.out(line);
1020
1066
  return 0;
1021
1067
  }
package/dist/doctor.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type Settings } from "./config.mts";
2
+ import { type Paint } from "./lib/color.mts";
2
3
  import type { Check } from "./setup.mts";
3
4
  import { type Registry } from "./tools.mts";
4
5
  export type { Check } from "./setup.mts";
@@ -19,6 +20,7 @@ export type DoctorDeps = {
19
20
  hasCommand: (name: string) => boolean;
20
21
  tools: Registry;
21
22
  out: (line: string) => void;
23
+ paint?: Paint;
22
24
  };
23
25
  export declare function checks(d: DoctorDeps): Promise<Check[]>;
24
26
  /** Whether Dependabot's settings name the registry at `url` under their
@@ -26,7 +28,10 @@ export declare function checks(d: DoctorDeps): Promise<Check[]>;
26
28
  export declare function usesRegistry(settings: string, url: string): boolean;
27
29
  /** One check as a line: a tick, a cross with what to do, or a dash for a
28
30
  * part that is off. */
29
- export declare function line(c: Check): string;
31
+ export declare function line(c: Check, paint?: Paint): string;
32
+ /** The checks under their headings, each group apart from the next, the
33
+ * whole indented by `indent` spaces. */
34
+ export declare function printChecks(found: Check[], paint?: Paint, indent?: number): string[];
30
35
  export declare function main(_argv: string[], d: DoctorDeps): Promise<number>;
31
36
  /** The checks, run in the repository this command runs in. */
32
37
  export declare function doctorDeps(root?: string): DoctorDeps;
package/dist/doctor.mjs CHANGED
@@ -4,6 +4,7 @@
4
4
  //
5
5
  // A stored secret cannot be read back, so a secret is checked only for
6
6
  // being set.
7
+ import { listed } from "./lib/listed.mjs";
7
8
  import { existsSync, readFileSync } from "node:fs";
8
9
  import { load } from "js-yaml";
9
10
  import { bareRegistry, npmrcAt, privateRegistries } from "./npmrc.mjs";
@@ -11,12 +12,16 @@ import { join } from "node:path";
11
12
  import { defaultDeps, filesDeps, repoRoot, resolveFiles, staleOf, } from "./config.mjs";
12
13
  import { presetChecks } from "./preset-commands.mjs";
13
14
  import { hasCommand } from "./lib/has-command.mjs";
15
+ import { colorOn, painter, plain } from "./lib/color.mjs";
14
16
  import { neededSecrets, PART_TEXT, PARTS, partsOn, } from "./parts.mjs";
15
17
  import { branchDeps, CANNOT_TELL, needDefaultBranch, NoDefaultBranch, } from "./lib/default-branch.mjs";
16
18
  import { differences, LOCK, PACKAGE, plan } from "./sync.mjs";
17
19
  import { inUse, secretSteps, TOOLS } from "./tools.mjs";
18
- const SYNC = "Run npx --no-install factory sync";
19
- const INIT = "Run npx --no-install factory init";
20
+ import { fieldChecks } from "./ticket-fields.mjs";
21
+ const SYNC = "Run factory sync";
22
+ const INIT = "Run factory init";
23
+ const SETTINGS = "Settings and files";
24
+ const OFF = "Parts that are off";
20
25
  const message = (e) => (e instanceof Error ? e.message : String(e));
21
26
  /** -1, 0, or 1 as version `a` is older than, the same as, or newer than `b`. */
22
27
  function compareVersions(a, b) {
@@ -39,7 +44,14 @@ export async function checks(d) {
39
44
  s = await d.settings();
40
45
  }
41
46
  catch (e) {
42
- return [{ state: "fail", text: "The settings are valid", fix: message(e) }];
47
+ return [
48
+ {
49
+ state: "fail",
50
+ text: "The settings are valid",
51
+ fix: message(e),
52
+ group: SETTINGS,
53
+ },
54
+ ];
43
55
  }
44
56
  out.push({ state: "pass", text: "The settings are valid" });
45
57
  let differ = null;
@@ -76,6 +88,9 @@ export async function checks(d) {
76
88
  fix: compareVersions(installed, locked) < 0 ? "Run npm ci" : SYNC,
77
89
  });
78
90
  out.push(...((await d.lockChecks?.()) ?? []));
91
+ for (const c of out)
92
+ c.group = SETTINGS;
93
+ const under = (group, found) => found.map((c) => ({ ...c, group }));
79
94
  const chosen = {
80
95
  codeHost: s.codeHost.type,
81
96
  tickets: s.tickets.type,
@@ -97,8 +112,7 @@ export async function checks(d) {
97
112
  opened,
98
113
  });
99
114
  const [agent, codeHost, tickets, runner] = inUse(d.tools, chosen);
100
- out.push(...((await codeHost.setup.checks?.({ ...context([]), secrets: null })) ??
101
- []));
115
+ out.push(...under(codeHost.label, (await codeHost.setup.checks?.({ ...context([]), secrets: null })) ?? []));
102
116
  // A secret the organization shares with the repository counts as set.
103
117
  const isOrganization = await opened.codeHost
104
118
  .ownerIsOrganization()
@@ -116,6 +130,7 @@ export async function checks(d) {
116
130
  state: "fail",
117
131
  text: "The secrets can be listed",
118
132
  fix: message(e),
133
+ group: runner.label,
119
134
  });
120
135
  }
121
136
  const secrets = own === null ? null : [...own, ...shared];
@@ -133,16 +148,27 @@ export async function checks(d) {
133
148
  fix: INIT,
134
149
  };
135
150
  };
151
+ // One line per secret, naming every part that reads it.
152
+ const reads = new Map();
153
+ const reading = (anyOf, forWhat) => {
154
+ // Parts can accept different names for one secret: the one set is the
155
+ // line, or the names asked for when none is.
156
+ const key = anyOf.find((n) => secrets.includes(n)) ?? anyOf.join(" or ");
157
+ const entry = reads.get(key) ?? { anyOf, fors: [] };
158
+ if (!entry.fors.includes(forWhat))
159
+ entry.fors.push(forWhat);
160
+ reads.set(key, entry);
161
+ };
136
162
  for (const part of PARTS) {
137
163
  if (!on.has(part)) {
138
- out.push({ state: "off", text: `${PART_TEXT[part].name}: off` });
164
+ out.push({ state: "off", text: PART_TEXT[part].name, group: OFF });
139
165
  continue;
140
166
  }
141
167
  if (secrets === null)
142
168
  continue;
143
169
  const forPart = PART_TEXT[part].name.replace(/^./, (c) => c.toLowerCase());
144
170
  for (const need of needed.filter((n) => n.part === part))
145
- out.push(secretLine(need.anyOf, forPart));
171
+ reading(need.anyOf, forPart);
146
172
  }
147
173
  // A gate is no part and fails no check: it is shown as off, since a
148
174
  // build cannot finish without one.
@@ -150,14 +176,30 @@ export async function checks(d) {
150
176
  out.push({
151
177
  state: "off",
152
178
  text: "commands.gate is not set: a build cannot finish until it is",
179
+ group: SETTINGS,
153
180
  });
154
181
  if (secrets !== null)
155
182
  for (const need of needed.filter((n) => n.part === null))
156
- out.push(secretLine(need.anyOf, need.tool));
157
- out.push(...(await npmChecks(d.root, opened, isOrganization, own, shared)));
183
+ reading(need.anyOf, need.tool);
184
+ for (const { anyOf, fors } of reads.values())
185
+ out.push({ ...secretLine(anyOf, listed(fors)), group: runner.label });
186
+ out.push(...under(runner.label, await npmChecks(d.root, opened, isOrganization, own, shared)));
158
187
  for (const tool of [tickets, runner, agent])
159
- out.push(...((await tool.setup.checks?.({ ...context(on), secrets })) ?? []));
160
- return out;
188
+ out.push(...under(tool.label, (await tool.setup.checks?.({ ...context(on), secrets })) ?? []));
189
+ out.push(...under(tickets.label, await fieldChecks(opened.tickets, s.tickets.ticketFields, s.repository, tickets.label)));
190
+ const order = [
191
+ SETTINGS,
192
+ codeHost.label,
193
+ runner.label,
194
+ tickets.label,
195
+ agent.label,
196
+ OFF,
197
+ ];
198
+ const rank = (c) => order.indexOf(c.group ?? SETTINGS);
199
+ return out
200
+ .map((c, i) => [c, i])
201
+ .sort(([a, i], [b, j]) => rank(a) - rank(b) || i - j)
202
+ .map(([c]) => c);
161
203
  }
162
204
  const DEPENDABOT = ".github/dependabot.yml";
163
205
  const FOR_NPM = "for installing what .npmrc names";
@@ -275,21 +317,39 @@ export function usesRegistry(settings, url) {
275
317
  }
276
318
  /** One check as a line: a tick, a cross with what to do, or a dash for a
277
319
  * part that is off. */
278
- export function line(c) {
320
+ export function line(c, paint = plain) {
279
321
  if (c.state === "off")
280
- return `- ${c.text}`;
322
+ return `${paint("dim", "-")} ${c.text}`;
281
323
  if (c.state === "unknown")
282
- return `? ${c.text}`;
324
+ return `${paint("yellow", "?")} ${c.text}`;
283
325
  if (c.state === "pass")
284
- return `✓ ${c.text}`;
326
+ return `${paint("green", "✓")} ${c.text}`;
285
327
  const fix = c.fix ?? "";
286
328
  // An instruction follows as its own sentence; a reason, after a colon.
287
- return `✗ ${c.text}${!fix ? "" : /^Run /.test(fix) ? `. ${fix}` : `: ${fix}`}`;
329
+ return `${paint("red", "✗")} ${c.text}${!fix ? "" : /^Run /.test(fix) ? `. ${fix}` : `: ${fix}`}`;
330
+ }
331
+ /** The checks under their headings, each group apart from the next, the
332
+ * whole indented by `indent` spaces. */
333
+ export function printChecks(found, paint = plain, indent = 0) {
334
+ const at = " ".repeat(indent);
335
+ const out = [];
336
+ let heading;
337
+ for (const c of found) {
338
+ if (c.group !== heading || out.length === 0) {
339
+ if (out.length)
340
+ out.push("");
341
+ heading = c.group;
342
+ if (heading)
343
+ out.push(`${at}${heading}`);
344
+ }
345
+ out.push(`${at}${heading ? " " : ""}${line(c, paint)}`);
346
+ }
347
+ return out;
288
348
  }
289
349
  export async function main(_argv, d) {
290
350
  const found = await checks(d);
291
- for (const c of found)
292
- d.out(line(c));
351
+ for (const l of printChecks(found, d.paint))
352
+ d.out(l);
293
353
  return found.some((c) => c.state === "fail") ? 1 : 0;
294
354
  }
295
355
  /** The checks, run in the repository this command runs in. */
@@ -315,6 +375,7 @@ export function doctorDeps(root = repoRoot()) {
315
375
  hasCommand,
316
376
  tools: TOOLS,
317
377
  out: (l) => console.log(l),
378
+ paint: painter(colorOn()),
318
379
  };
319
380
  }
320
381
  export async function run(argv) {
@@ -1,5 +1,6 @@
1
1
  import { type Settings } from "./config.mts";
2
2
  import { type Resolution } from "./preset.mts";
3
+ import type { Paint } from "./lib/color.mts";
3
4
  /** The mark of the value at `path`, or of one item of the list there:
4
5
  * `item` is the item for a list of values and the plugin's name for a
5
6
  * list of plugins. */
@@ -13,3 +14,7 @@ export declare function markerOf(r: Resolution): Marker;
13
14
  /** `exists` says whether a path from the root exists, for the plugins the
14
15
  * factory uses where the settings name none. */
15
16
  export declare function explainLines(s: Settings, marks: Marker, exists: (path: string) => boolean): Promise<string[]>;
17
+ /** The lines as `config explain` prints them to a terminal: a default's
18
+ * whole line dim, a comment line dim, and any other mark alone dim. It
19
+ * works on the text alone, since the lock keeps only that. */
20
+ export declare function paintExplainLines(lines: string[], paint: Paint): string[];
package/dist/explain.mjs CHANGED
@@ -71,6 +71,10 @@ export async function explainLines(s, marks, exists) {
71
71
  for (const [k, v] of Object.entries(s.tickets.fields))
72
72
  put(["tickets", "fields", k], v ?? "none");
73
73
  }
74
+ if (s.tickets.board === null)
75
+ block(["tickets", "fields"]);
76
+ for (const [k, v] of Object.entries(s.tickets.ticketFields))
77
+ put(["tickets", "fields", k], v ?? "none");
74
78
  put(["code-host"], s.codeHost.type);
75
79
  block(["builds"]);
76
80
  put(["builds", "trigger"], s.builds.trigger);
@@ -187,3 +191,28 @@ export async function explainLines(s, marks, exists) {
187
191
  const at = Math.max(0, ...marked.map((l) => l.text.length)) + 2;
188
192
  return lines.map((l) => l.mark !== null ? `${l.text.padEnd(at)}# ${l.mark}` : l.text);
189
193
  }
194
+ /** The lines as `config explain` prints them to a terminal: a default's
195
+ * whole line dim, a comment line dim, and any other mark alone dim. It
196
+ * works on the text alone, since the lock keeps only that. */
197
+ export function paintExplainLines(lines, paint) {
198
+ const comment = (l) => l.trimStart().startsWith("#");
199
+ // Every mark starts at one column, two spaces past the longest marked
200
+ // line. A quoted value can hold " # " too, but rarely at that column.
201
+ const counts = new Map();
202
+ for (const l of lines.filter((l) => !comment(l)))
203
+ for (const m of l.matchAll(/ {2}# /g)) {
204
+ const at = m.index + 2;
205
+ counts.set(at, (counts.get(at) ?? 0) + 1);
206
+ }
207
+ const most = Math.max(0, ...counts.values());
208
+ const at = Math.max(-1, ...[...counts].filter(([, n]) => n === most).map(([c]) => c));
209
+ return lines.map((l) => {
210
+ if (comment(l))
211
+ return paint("dim", l);
212
+ if (at < 0 || !l.startsWith(" # ", at - 2))
213
+ return l;
214
+ return l.slice(at) === "# default"
215
+ ? paint("dim", l)
216
+ : l.slice(0, at) + paint("dim", l.slice(at));
217
+ });
218
+ }
package/dist/init.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type Registry } from "./tools.mts";
2
+ import { type Paint } from "./lib/color.mts";
2
3
  import { type Check } from "./setup.mts";
3
4
  /** The questions init asks. Each is answered at the terminal, and in tests
4
5
  * from a script. */
@@ -28,6 +29,7 @@ export type InitDeps = {
28
29
  /** The `origin` remote's address, or null without one. */
29
30
  remote: () => string | null;
30
31
  tools: Registry;
32
+ paint?: Paint;
31
33
  sync: () => Promise<number>;
32
34
  /** The files a sync with these settings would write or delete. `host`
33
35
  * asks the code host for the default branch, where the checkout does not
package/dist/init.mjs CHANGED
@@ -14,7 +14,8 @@ import { isMap, parseDocument } from "yaml";
14
14
  import { builtOf, secretSteps, TOOLS, } from "./tools.mjs";
15
15
  import { NeedsScopeError } from "./code-host/types.mjs";
16
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";
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";
@@ -26,12 +27,13 @@ import { RULE } from "./setup.mjs";
26
27
  import { differences, PACKAGE, plan as syncPlan } from "./sync.mjs";
27
28
  import { DEFAULT_COLUMNS, STATE_KEYS, sameName } from "./lib/work-status.mjs";
28
29
  import { askReady, 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.";
35
37
  /** The columns and fields the board sync uses: the settings' names where
36
38
  * they rename one, and none for one they set to none. */
37
39
  function boardShape(s) {
@@ -142,6 +144,12 @@ export async function main(_argv, d) {
142
144
  const npmrc = npmrcAt(d.root);
143
145
  d.out(`Setting up the software factory for ${repository}`);
144
146
  d.out("");
147
+ if (!agent.agent.installed(d.hasCommand)) {
148
+ d.out(`The factory runs in a coding agent, and ${agent.label} is not installed.`);
149
+ d.out("Install it and run factory init again.");
150
+ d.out("Nothing changed.");
151
+ return 1;
152
+ }
145
153
  d.out("Found");
146
154
  const row = (label, text) => d.out(` ${label.padEnd(14)} ${text}`);
147
155
  row("Code host", `${d.tools.codeHost[found.codeHost].label} (from your git remote)`);
@@ -228,7 +236,7 @@ export async function main(_argv, d) {
228
236
  const chooseBoard = async (offerNew) => {
229
237
  const existing = boardOps ? await boardOps.list() : [];
230
238
  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.");
239
+ d.out("No board to use instead: create one on the code host, then run factory init again.");
232
240
  return null;
233
241
  }
234
242
  const choice = await d.ask.select("Which board?", [
@@ -304,7 +312,6 @@ export async function main(_argv, d) {
304
312
  out: d.out,
305
313
  agent: agent.agent,
306
314
  label: agent.label,
307
- hasCommand: d.hasCommand,
308
315
  }, {
309
316
  board,
310
317
  columns: names,
@@ -318,6 +325,34 @@ export async function main(_argv, d) {
318
325
  else if (asksReady && settings)
319
326
  readyColumn = await askReady({ ask: d.ask, out: d.out }, { columns: names, current: columnsOf(settings) });
320
327
  }
328
+ // The factory fields a refined ticket has: the coding agent suggests
329
+ // which of the tickets' text fields holds each, when the settings name
330
+ // none of the four.
331
+ let fieldLines = [];
332
+ if (tickets.fields &&
333
+ !FACTORY_FIELDS.some((f) => doc.hasIn(["tickets", "fields", f.key]))) {
334
+ let text;
335
+ try {
336
+ text = (await tickets.fields.list()).filter((f) => f.text);
337
+ }
338
+ catch (e) {
339
+ d.out(`Could not read ${repository}'s ticket fields: ${message(e)}`);
340
+ d.out("Nothing changed.");
341
+ return 1;
342
+ }
343
+ if (text.length) {
344
+ const got = await suggestFields({ ask: d.ask, out: d.out, agent: agent.agent, label: agent.label }, {
345
+ repository,
346
+ fields: text,
347
+ plainText: tickets.fields.plainText
348
+ ? d.tools.tickets[chosen.tickets].label
349
+ : null,
350
+ });
351
+ if (got === 1)
352
+ return 1;
353
+ fieldLines = got;
354
+ }
355
+ }
321
356
  // The settings as they will stand, keeping every other key and comment.
322
357
  if (!doc.has("version"))
323
358
  doc.set("version", 2);
@@ -332,13 +367,18 @@ export async function main(_argv, d) {
332
367
  doc.setIn(["tickets", "board"], board);
333
368
  for (const [key, name] of columnLines)
334
369
  doc.setIn(["tickets", "columns", key], name);
370
+ for (const [key, name] of fieldLines)
371
+ doc.setIn(["tickets", "fields", key], name);
335
372
  if (readyColumn === null)
336
373
  remove(doc, ["tickets", "columns", "ready"]);
337
374
  else if (readyColumn !== undefined)
338
375
  doc.setIn(["tickets", "columns", "ready"], readyColumn);
339
- if (!parts.has("board"))
340
- for (const key of ["board", "columns", "fields"])
376
+ if (!parts.has("board")) {
377
+ for (const key of ["board", "columns"])
341
378
  remove(doc, ["tickets", key]);
379
+ for (const key of ["session", "runs-in", "cost"])
380
+ remove(doc, ["tickets", "fields", key]);
381
+ }
342
382
  if (parts.has("from-board"))
343
383
  doc.setIn(["builds", "trigger"], trigger);
344
384
  else if (before.has("from-board"))
@@ -627,8 +667,8 @@ export async function main(_argv, d) {
627
667
  d.out("");
628
668
  d.out("Checks");
629
669
  const found2 = await d.checks();
630
- for (const c of found2)
631
- d.out(` ${line(c)}`);
670
+ for (const l of printChecks(found2, d.paint, 2))
671
+ d.out(l);
632
672
  return found2.some((c) => c.state === "fail") ? 1 : 0;
633
673
  }
634
674
  /** The questions, asked at the terminal. */
@@ -674,7 +714,7 @@ export async function run(argv) {
674
714
  }
675
715
  },
676
716
  tools: TOOLS,
677
- sync: async () => (await import("./sync.mjs")).run([]),
717
+ sync: async () => (await import("./sync.mjs")).run([], false),
678
718
  // The settings are not written yet, so the code host asked is the one
679
719
  // setup has just opened, not the one a settings file names.
680
720
  syncChanges: async (text, host) => {
@@ -717,6 +757,7 @@ export async function run(argv) {
717
757
  }
718
758
  },
719
759
  checks: () => doctorChecks(doctorDeps(root)),
760
+ paint: painter(colorOn()),
720
761
  packageName: manifest.name,
721
762
  packageVersion: manifest.version,
722
763
  };
@@ -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
+ }
@@ -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. */