@davidbyoung/software-factory 0.1.6 → 0.1.8

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 (50) hide show
  1. package/dist/agent/claude-code.d.mts +16 -0
  2. package/dist/agent/claude-code.mjs +75 -3
  3. package/dist/agent/index.d.mts +1 -1
  4. package/dist/agent/index.mjs +1 -1
  5. package/dist/agent/types.d.mts +24 -0
  6. package/dist/agent/types.mjs +3 -0
  7. package/dist/board.mjs +9 -11
  8. package/dist/code-host/github.mjs +4 -0
  9. package/dist/code-host/types.d.mts +2 -0
  10. package/dist/columns-suggest.d.mts +52 -0
  11. package/dist/columns-suggest.mjs +259 -0
  12. package/dist/config.d.mts +6 -1
  13. package/dist/config.mjs +45 -8
  14. package/dist/doctor.d.mts +3 -0
  15. package/dist/doctor.mjs +133 -5
  16. package/dist/explain.mjs +1 -1
  17. package/dist/init.mjs +155 -7
  18. package/dist/lib/work-status.d.mts +10 -7
  19. package/dist/lib/work-status.mjs +20 -19
  20. package/dist/npmrc.d.mts +29 -0
  21. package/dist/npmrc.mjs +98 -0
  22. package/dist/poller.mjs +2 -2
  23. package/dist/preset-commands.d.mts +0 -2
  24. package/dist/preset-commands.mjs +2 -12
  25. package/dist/preset.d.mts +4 -0
  26. package/dist/preset.mjs +10 -0
  27. package/dist/runner/github-actions.mjs +47 -10
  28. package/dist/runner/types.d.mts +13 -0
  29. package/dist/setup.d.mts +3 -1
  30. package/dist/status.mjs +1 -1
  31. package/dist/sync.d.mts +7 -0
  32. package/dist/sync.mjs +66 -2
  33. package/dist/ticket.mjs +1 -1
  34. package/dist/tickets/github.mjs +10 -2
  35. package/dist/tickets/types.d.mts +3 -0
  36. package/dist/tools.d.mts +4 -1
  37. package/dist/tools.mjs +9 -2
  38. package/docs/configuration.md +33 -5
  39. package/docs/design.md +15 -0
  40. package/docs/developing.md +15 -6
  41. package/docs/existing-repo.md +104 -31
  42. package/docs/github/by-hand.md +4 -0
  43. package/docs/github/reference.md +5 -0
  44. package/docs/github/setup.md +141 -8
  45. package/docs/limitations.md +0 -8
  46. package/docs/presets.md +5 -9
  47. package/docs/removing.md +2 -2
  48. package/package.json +1 -1
  49. package/settings.schema.json +45 -15
  50. package/skills/factory-deps/SKILL.md +4 -0
@@ -1,3 +1,19 @@
1
1
  import type { ToolSetup } from "../setup.mts";
2
+ import type { Agent } from "./types.mts";
2
3
  export declare const LABEL = "Claude Code";
3
4
  export declare const claudeCodeSetup: ToolSetup;
5
+ /** The part of a child process `answer` uses. */
6
+ export type Child = {
7
+ stdout: NodeJS.ReadableStream | null;
8
+ stderr: NodeJS.ReadableStream | null;
9
+ kill(): boolean;
10
+ on(event: "close", listener: (code: number | null) => void): unknown;
11
+ on(event: "error", listener: (e: Error) => void): unknown;
12
+ };
13
+ export type Spawn = (command: string, args: string[], options: {
14
+ cwd: string;
15
+ }) => Child;
16
+ /** Claude Code's answer to one question: `claude -p` with no tools, on its
17
+ * smallest model, run from an empty folder so no project's settings or
18
+ * hooks load. */
19
+ export declare function claudeCodeAgent(spawn: Spawn): Agent;
@@ -1,7 +1,8 @@
1
1
  // Claude Code as the factory's coding agent: the token it needs, the
2
- // configuration `factory sync` writes for it, and how `remove` takes that
3
- // configuration out.
4
- import { existsSync, readFileSync } from "node:fs";
2
+ // configuration `factory sync` writes for it, how `remove` takes that
3
+ // configuration out, and how it answers one question for `init`.
4
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
5
+ import { tmpdir } from "node:os";
5
6
  import { join } from "node:path";
6
7
  import { listed } from "../lib/listed.mjs";
7
8
  import { AGENT_KEY, AGENT_TOKEN } from "../parts.mjs";
@@ -87,3 +88,74 @@ export const claudeCodeSetup = {
87
88
  return out;
88
89
  },
89
90
  };
91
+ const firstLine = (text) => text
92
+ .split("\n")
93
+ .map((l) => l.trim())
94
+ .find(Boolean) ?? null;
95
+ /** Claude Code's answer to one question: `claude -p` with no tools, on its
96
+ * smallest model, run from an empty folder so no project's settings or
97
+ * hooks load. */
98
+ export function claudeCodeAgent(spawn) {
99
+ return {
100
+ installed: (hasCommand) => hasCommand(COMMAND),
101
+ answer: (q) => new Promise((resolve) => {
102
+ const cwd = mkdtempSync(join(tmpdir(), "factory-ask-"));
103
+ const child = spawn(COMMAND, [
104
+ "-p",
105
+ q.prompt,
106
+ "--output-format",
107
+ "json",
108
+ "--json-schema",
109
+ JSON.stringify(q.schema),
110
+ "--tools",
111
+ "",
112
+ "--model",
113
+ "haiku",
114
+ "--setting-sources",
115
+ "",
116
+ ], { cwd });
117
+ let stdout = "";
118
+ let stderr = "";
119
+ child.stdout?.on("data", (b) => (stdout += String(b)));
120
+ child.stderr?.on("data", (b) => (stderr += String(b)));
121
+ let timedOut = false;
122
+ const timer = setTimeout(() => {
123
+ timedOut = true;
124
+ child.kill();
125
+ }, q.timeoutMs);
126
+ const done = (answer) => {
127
+ clearTimeout(timer);
128
+ rmSync(cwd, { recursive: true, force: true });
129
+ resolve(answer);
130
+ };
131
+ child.on("error", (e) => done({ failed: { code: 1, error: firstLine(e.message) } }));
132
+ child.on("close", (code) => {
133
+ if (timedOut)
134
+ return done({ timedOut: true });
135
+ let json = {};
136
+ try {
137
+ json = JSON.parse(stdout) ?? {};
138
+ }
139
+ catch {
140
+ // Not JSON: no answer, and no result line to fall back to.
141
+ }
142
+ const result = typeof json.result === "string" ? json.result : "";
143
+ if (code !== 0)
144
+ return done({
145
+ failed: {
146
+ code: code ?? 1,
147
+ error: firstLine(stderr) ?? firstLine(result),
148
+ },
149
+ });
150
+ if (json.structured_output !== undefined)
151
+ return done({ answer: json.structured_output });
152
+ try {
153
+ return done({ answer: JSON.parse(result) });
154
+ }
155
+ catch {
156
+ return done({ answer: undefined });
157
+ }
158
+ });
159
+ }),
160
+ };
161
+ }
@@ -1,2 +1,2 @@
1
- export { claudeCodeSetup } from "./claude-code.mts";
1
+ export { claudeCodeAgent, claudeCodeSetup } from "./claude-code.mts";
2
2
  export declare const DEFAULT_AGENT: "claude-code";
@@ -1,5 +1,5 @@
1
1
  // The coding agent the factory's sessions run in. Claude Code is the only
2
2
  // one, so the settings name none: the agent that adds a second adds the
3
3
  // setting.
4
- export { claudeCodeSetup } from "./claude-code.mjs";
4
+ export { claudeCodeAgent, claudeCodeSetup } from "./claude-code.mjs";
5
5
  export const DEFAULT_AGENT = "claude-code";
@@ -0,0 +1,24 @@
1
+ export type Question = {
2
+ prompt: string;
3
+ /** The JSON schema the answer follows. */
4
+ schema: object;
5
+ timeoutMs: number;
6
+ };
7
+ export type Answer = {
8
+ answer: unknown;
9
+ }
10
+ /** The command exited non-zero: the first line of its error output, or
11
+ * null when it printed none. */
12
+ | {
13
+ failed: {
14
+ code: number;
15
+ error: string | null;
16
+ };
17
+ } | {
18
+ timedOut: true;
19
+ };
20
+ export type Agent = {
21
+ /** Whether its command is on this machine. */
22
+ installed(hasCommand: (name: string) => boolean): boolean;
23
+ answer(q: Question): Promise<Answer>;
24
+ };
@@ -0,0 +1,3 @@
1
+ // What a coding agent does for `init` beyond the sessions it runs: answer
2
+ // one question, with no tools, in the shape a JSON schema gives.
3
+ export {};
package/dist/board.mjs CHANGED
@@ -23,7 +23,7 @@
23
23
  import { readFileSync, writeFileSync } from "node:fs";
24
24
  import { join } from "node:path";
25
25
  import { columnsOf, fieldNamesOf, loadSettings, } from "./config.mjs";
26
- import { DEFAULT_COLUMNS, STATE_KEYS, cardOf, columnFor, sameName, statusOfColumn, commentBody, derive, buildsPartOf, issueCost, toClear, toSnapshot, actionsRunLink, } from "./lib/work-status.mjs";
26
+ import { DEFAULT_COLUMNS, STATE_KEYS, cardOf, columnFor, columnsFor, sameName, statusOfColumn, commentBody, derive, buildsPartOf, issueCost, toClear, toSnapshot, actionsRunLink, } from "./lib/work-status.mjs";
27
27
  import { subscriptionDollars } from "./lib/pricing.mjs";
28
28
  import { openCodeHost } from "./code-host/index.mjs";
29
29
  import { openRunner } from "./runner/index.mjs";
@@ -82,12 +82,9 @@ export function inspectBoard(fields, cfg = DEFAULT_BOARD) {
82
82
  }
83
83
  else {
84
84
  const names = (status.options ?? []).map((o) => o.name);
85
- const missing = Object.keys(STATE_KEYS).flatMap((key) => {
86
- const column = cfg.columns[STATE_KEYS[key]];
87
- return column !== null && !names.some((n) => sameName(n, column))
88
- ? [`${column} (tickets.columns.${key})`]
89
- : [];
90
- });
85
+ const missing = Object.keys(STATE_KEYS).flatMap((key) => (cfg.columns[STATE_KEYS[key]] ?? [])
86
+ .filter((column) => !names.some((n) => sameName(n, column)))
87
+ .map((column) => `${column} (tickets.columns.${key})`));
91
88
  if (missing.length)
92
89
  problems.push(`the Status field lacks ${missing.join(", ")}`);
93
90
  for (const name of names)
@@ -156,7 +153,7 @@ export function boardReport(number, board, cfg, settings) {
156
153
  const column = cfg.columns[status];
157
154
  out.push(pad(key) +
158
155
  (column !== null
159
- ? column
156
+ ? column.join(", ")
160
157
  : key === "ready"
161
158
  ? "no column: builds start only when you ask"
162
159
  : `no column, shows in ${columnFor(status, cfg.columns)}`));
@@ -164,11 +161,11 @@ export function boardReport(number, board, cfg, settings) {
164
161
  out.push("");
165
162
  for (const line of found.lines)
166
163
  out.push(pad(line.label) + line.text);
167
- const ready = cfg.columns.Ready;
164
+ const ready = cfg.columns.Ready?.[0] ?? null;
168
165
  const extra = [
169
166
  ...found.notes.map((n) => `Note: ${n}`),
170
167
  ...(ready !== null &&
171
- ready !== DEFAULT_COLUMNS.Ready &&
168
+ ready !== DEFAULT_COLUMNS.Ready[0] &&
172
169
  settings.builds.trigger === "own-server"
173
170
  ? [`Note: The poller needs FACTORY_READY_COLUMN set to "${ready}".`]
174
171
  : []),
@@ -206,7 +203,8 @@ export function planSync(snapshot, board, repository, runPage, cfg = DEFAULT_BOA
206
203
  const column = columnFor(derived.status, cfg.columns);
207
204
  const option = fields.status.options?.find((o) => sameName(o.name, column));
208
205
  const writes = [];
209
- if (item?.status == null || !sameName(item.status, column))
206
+ if (item?.status == null ||
207
+ !columnsFor(derived.status, cfg.columns).some((c) => sameName(item.status, c)))
210
208
  writes.push({
211
209
  field: fields.status.name,
212
210
  optionName: option?.name ?? column,
@@ -234,6 +234,10 @@ export function githubCodeHost(o) {
234
234
  const repo = await t.rest("GET", API);
235
235
  return repo.private;
236
236
  },
237
+ async ownerIsOrganization() {
238
+ const repo = await t.rest("GET", API);
239
+ return repo.owner.type === "Organization";
240
+ },
237
241
  async checkRuns(sha) {
238
242
  const answer = await t.rest("GET", `${API}/commits/${sha}/check-runs?per_page=100`);
239
243
  return answer.check_runs.map((c) => ({
@@ -123,6 +123,8 @@ export type CodeHost = {
123
123
  defaultBranch(): Promise<string>;
124
124
  /** Whether only people given access can see the repository. */
125
125
  isPrivate(): Promise<boolean>;
126
+ /** Whether an organization owns the repository, rather than a person. */
127
+ ownerIsOrganization(): Promise<boolean>;
126
128
  /** The check runs on a commit, without its statuses. */
127
129
  checkRuns(sha: string): Promise<CheckRun[]>;
128
130
  /** The statuses on a commit, without its check runs. */
@@ -0,0 +1,52 @@
1
+ import type { Agent } from "./agent/types.mts";
2
+ import type { Ask } from "./init.mts";
3
+ import { type Columns, type StateKey } from "./lib/work-status.mts";
4
+ /** A state's column: one of the board's, by the board's spelling; the
5
+ * factory's own name, which init adds; or none. */
6
+ export type Choice = {
7
+ column: string;
8
+ } | "add" | "none";
9
+ export type Mapping = Record<StateKey, Choice>;
10
+ export declare const NONE = "__none__";
11
+ export declare const ADD = "__add__";
12
+ export declare const TIMEOUT_MS = 60000;
13
+ export declare function prompt(columns: readonly string[], fromBoard: boolean): string;
14
+ export declare function schema(columns: readonly string[]): object;
15
+ /** The mapping the agent's answer gives, or the reason it can't be used,
16
+ * the first that applies in the order the issue lists them. */
17
+ export declare function check(answer: unknown, columns: readonly string[], fromBoard: boolean, board: number): {
18
+ mapping: Mapping;
19
+ } | {
20
+ reason: string;
21
+ };
22
+ /** The columns a mapping gives each state, a column init adds by its
23
+ * factory name. */
24
+ export declare function toColumns(mapping: Mapping): Columns;
25
+ /** The table of each state's column, as `factory board check` words it. */
26
+ export declare function table(mapping: Mapping): string[];
27
+ /** What `Yes` writes under `tickets.columns`: each state whose column is
28
+ * not the factory's own name. */
29
+ export declare function written(mapping: Mapping): [StateKey, string][];
30
+ export type SuggestDeps = {
31
+ ask: Ask;
32
+ out: (line: string) => void;
33
+ agent: Agent;
34
+ /** The agent's registered label, which every line names it by. */
35
+ label: string;
36
+ hasCommand: (name: string) => boolean;
37
+ };
38
+ /** The board's columns, as init's first line about them says. */
39
+ export declare const boardLine: (board: number, columns: readonly string[]) => string;
40
+ /** The column step: the mapping's `tickets.columns` lines to write, none
41
+ * for the factory's own columns, or 1 when init stops. */
42
+ export declare function suggestColumns(d: SuggestDeps, o: {
43
+ board: number;
44
+ columns: readonly string[];
45
+ fromBoard: boolean;
46
+ }): Promise<[StateKey, string][] | "default" | 1>;
47
+ /** A ready column, asked for when builds from the board turn on and the
48
+ * settings give ready none: one of the board's, or null to add Ready. */
49
+ export declare function askReady(d: Pick<SuggestDeps, "ask" | "out">, o: {
50
+ columns: readonly string[];
51
+ current: Columns;
52
+ }): Promise<string | null>;
@@ -0,0 +1,259 @@
1
+ import { listed } from "./lib/listed.mjs";
2
+ import { STATE_KEYS, columnFor, sameName, } from "./lib/work-status.mjs";
3
+ export const NONE = "__none__";
4
+ export const ADD = "__add__";
5
+ export const TIMEOUT_MS = 60_000;
6
+ const KEYS = Object.keys(STATE_KEYS);
7
+ /** What each state means, as `docs/workflow.md` "The six states" says. */
8
+ const MEANING = {
9
+ backlog: "nothing is happening",
10
+ refining: "a session is turning it into a spec, or the spec is written and waits for you",
11
+ ready: "you approved it for a build from the board",
12
+ building: "a session has claimed it, or a build ended without a pull request merging",
13
+ review: "a pull request that closes it is open",
14
+ done: "the ticket is closed",
15
+ };
16
+ /** Where a ticket goes with no column, after "No column: ". */
17
+ const NO_COLUMN = {
18
+ backlog: null,
19
+ refining: (c) => `a ticket being refined shows in ${c}`,
20
+ ready: () => "builds start only when you ask",
21
+ building: (c) => `a ticket being built shows in ${c}`,
22
+ review: (c) => `a ticket in review shows in ${c}`,
23
+ done: (c) => `a ticket that is done shows in ${c}`,
24
+ };
25
+ export function prompt(columns, fromBoard) {
26
+ return [
27
+ "A software factory moves each ticket through six states, in this order:",
28
+ ...KEYS.map((k) => `- ${k}: ${MEANING[k]}`),
29
+ "",
30
+ "A kanban board has these columns, in this order:",
31
+ ...columns.map((c) => `- ${c}`),
32
+ "",
33
+ "For each state, say which one of the board's columns shows it. Give each column to at most one state.",
34
+ `Answer ${NONE} for a state no column shows: its tickets then stay in the column of the nearest earlier state. backlog always needs a column.`,
35
+ fromBoard
36
+ ? "ready needs a column, since builds start when a ticket moves there."
37
+ : `ready may be ${NONE}: builds then start only when someone asks.`,
38
+ `Answer ${ADD} for a state that should get a new column of its own.`,
39
+ "Answer with a JSON object with each of the six states as a key.",
40
+ ].join("\n");
41
+ }
42
+ export function schema(columns) {
43
+ const one = { type: "string", enum: [...columns, NONE, ADD] };
44
+ return {
45
+ type: "object",
46
+ properties: Object.fromEntries(KEYS.map((k) => [k, one])),
47
+ required: KEYS,
48
+ };
49
+ }
50
+ /** The board's spelling of `name`, or null when it has no such column. */
51
+ const onBoard = (name, columns) => columns.find((c) => sameName(c, name)) ?? null;
52
+ /** The column a choice puts on the board, or null for none. */
53
+ const nameOf = (key, c) => c === "none" ? null : c === "add" ? STATE_KEYS[key] : c.column;
54
+ /** The mapping the agent's answer gives, or the reason it can't be used,
55
+ * the first that applies in the order the issue lists them. */
56
+ export function check(answer, columns, fromBoard, board) {
57
+ const form = { reason: "it did not answer in the form asked for" };
58
+ if (typeof answer !== "object" || answer === null || Array.isArray(answer))
59
+ return form;
60
+ const raw = answer;
61
+ const given = KEYS.filter((k) => typeof raw[k] === "string");
62
+ for (const k of given) {
63
+ const v = raw[k];
64
+ if (v !== NONE && v !== ADD && !onBoard(v, columns))
65
+ return { reason: `it named ${v}, which board ${board} doesn't have` };
66
+ }
67
+ const mapping = {};
68
+ for (const k of given) {
69
+ const v = raw[k];
70
+ const existing = v === ADD ? onBoard(STATE_KEYS[k], columns) : onBoard(v, columns);
71
+ mapping[k] = v === NONE ? "none" : existing ? { column: existing } : "add";
72
+ }
73
+ for (const [i, a] of given.entries())
74
+ for (const b of given.slice(i + 1)) {
75
+ const x = nameOf(a, mapping[a]);
76
+ const y = nameOf(b, mapping[b]);
77
+ if (x !== null && y !== null && sameName(x, y))
78
+ return { reason: `it put ${x} in both ${a} and ${b}` };
79
+ }
80
+ const missing = KEYS.find((k) => raw[k] === undefined);
81
+ if (missing)
82
+ return { reason: `it left out ${missing}` };
83
+ if (given.length < KEYS.length)
84
+ return form;
85
+ if (mapping.backlog === "none")
86
+ return {
87
+ reason: "it gave backlog no column, and every ticket starts there",
88
+ };
89
+ if (mapping.ready === "none" && fromBoard)
90
+ return {
91
+ reason: "it gave ready no column, and builds start from the board",
92
+ };
93
+ return { mapping };
94
+ }
95
+ /** The columns a mapping gives each state, a column init adds by its
96
+ * factory name. */
97
+ export function toColumns(mapping) {
98
+ return Object.fromEntries(KEYS.map((k) => {
99
+ const name = nameOf(k, mapping[k]);
100
+ return [STATE_KEYS[k], name === null ? null : [name]];
101
+ }));
102
+ }
103
+ /** A state's column as the table shows it. */
104
+ function shown(key, mapping) {
105
+ const c = mapping[key];
106
+ if (c === "add")
107
+ return `${STATE_KEYS[key]}, which init adds`;
108
+ if (c !== "none")
109
+ return c.column;
110
+ if (key === "ready")
111
+ return "no column: builds start only when you ask";
112
+ return `no column, shows in ${columnFor(STATE_KEYS[key], toColumns(mapping))}`;
113
+ }
114
+ /** The table of each state's column, as `factory board check` words it. */
115
+ export function table(mapping) {
116
+ const pad = (label) => ` ${label.padEnd(10)} `;
117
+ return [
118
+ `${pad("State")}Column`,
119
+ ...KEYS.map((k) => pad(k) + shown(k, mapping)),
120
+ ];
121
+ }
122
+ /** What `Yes` writes under `tickets.columns`: each state whose column is
123
+ * not the factory's own name. */
124
+ export function written(mapping) {
125
+ return KEYS.flatMap((k) => {
126
+ const c = mapping[k];
127
+ if (c === "add")
128
+ return [];
129
+ if (c === "none")
130
+ return [[k, "none"]];
131
+ return sameName(c.column, STATE_KEYS[k]) ? [] : [[k, c.column]];
132
+ });
133
+ }
134
+ const AGAIN_OR_WRITE = "write tickets.columns in .claude/factory.yaml yourself.";
135
+ /** The board's columns, as init's first line about them says. */
136
+ export const boardLine = (board, columns) => `Board ${board} has the columns ${listed(columns)}.`;
137
+ /** The other state a column already shows, or null. */
138
+ function showing(name, key, current) {
139
+ return (KEYS.find((k) => k !== key &&
140
+ (current[STATE_KEYS[k]] ?? []).some((c) => sameName(c, name))) ?? null);
141
+ }
142
+ /** Asks which column shows `key`, with `current` selected. */
143
+ async function pickColumn(d, key, columns, current, noColumn) {
144
+ const factory = STATE_KEYS[key];
145
+ return d.ask.select(`Which column shows ${key}?`, [
146
+ ...columns.map((c) => ({ name: c, value: `column:${c}` })),
147
+ ...(noColumn === null
148
+ ? []
149
+ : [{ name: `No column: ${noColumn}`, value: NONE }]),
150
+ ...(onBoard(factory, columns)
151
+ ? []
152
+ : [{ name: `Add a column called "${factory}"`, value: ADD }]),
153
+ ], current);
154
+ }
155
+ const valueOf = (c) => c === "none" ? NONE : c === "add" ? ADD : `column:${c.column}`;
156
+ const choiceOf = (v) => v === NONE ? "none" : v === ADD ? "add" : { column: v.slice(7) };
157
+ /** "Change some": the states you pick, then a column for each, until no
158
+ * two states share one. */
159
+ async function changeSome(d, mapping, columns, fromBoard) {
160
+ const m = { ...mapping };
161
+ let picked = [];
162
+ for (;;) {
163
+ picked = await d.ask.checkbox("Which states do you want to change?", KEYS.map((k) => ({
164
+ name: `${k}: ${shown(k, m)}`,
165
+ value: k,
166
+ checked: picked.includes(k),
167
+ })));
168
+ let clash = false;
169
+ for (const key of KEYS.filter((k) => picked.includes(k))) {
170
+ const others = { ...m, [key]: "none" };
171
+ const noColumn = key === "backlog" || (key === "ready" && fromBoard)
172
+ ? null
173
+ : NO_COLUMN[key](columnFor(STATE_KEYS[key], toColumns(others)));
174
+ const choice = choiceOf(await pickColumn(d, key, columns, valueOf(m[key]), noColumn));
175
+ const name = nameOf(key, choice);
176
+ const other = name === null ? null : showing(name, key, toColumns(m));
177
+ if (other) {
178
+ d.out(`${name} already shows ${other}. Pick another column for ${key}.`);
179
+ clash = true;
180
+ break;
181
+ }
182
+ m[key] = choice;
183
+ }
184
+ if (!clash)
185
+ return m;
186
+ }
187
+ }
188
+ /** The column step: the mapping's `tickets.columns` lines to write, none
189
+ * for the factory's own columns, or 1 when init stops. */
190
+ export async function suggestColumns(d, o) {
191
+ d.out("");
192
+ d.out(boardLine(o.board, o.columns));
193
+ if (!d.agent.installed(d.hasCommand)) {
194
+ d.out(`Matching them to the factory's six states needs ${d.label}, which is not installed.`);
195
+ d.out(`Install it and run factory init again, or ${AGAIN_OR_WRITE}`);
196
+ d.out("Nothing changed.");
197
+ return 1;
198
+ }
199
+ d.out(`Asking ${d.label} which of them shows each of the factory's six states...`);
200
+ const got = await d.agent.answer({
201
+ prompt: prompt(o.columns, o.fromBoard),
202
+ schema: schema(o.columns),
203
+ timeoutMs: TIMEOUT_MS,
204
+ });
205
+ const checked = "timedOut" in got
206
+ ? { reason: `it took longer than ${TIMEOUT_MS / 1000} seconds` }
207
+ : "failed" in got
208
+ ? {
209
+ reason: got.failed.error === null
210
+ ? `it failed with exit code ${got.failed.code}`
211
+ : `it failed: ${got.failed.error}`,
212
+ }
213
+ : check(got.answer, o.columns, o.fromBoard, o.board);
214
+ if ("reason" in checked) {
215
+ d.out(`${d.label}'s answer could not be used: ${checked.reason}.`);
216
+ d.out(`Run factory init again, or ${AGAIN_OR_WRITE}`);
217
+ d.out("Nothing changed.");
218
+ return 1;
219
+ }
220
+ let mapping = checked.mapping;
221
+ for (;;) {
222
+ d.out("");
223
+ for (const line of table(mapping))
224
+ d.out(line);
225
+ d.out("");
226
+ const use = await d.ask.select("Use these columns?", [
227
+ { name: "Yes", value: "yes" },
228
+ { name: "Change some", value: "change" },
229
+ { name: "No: add the factory's columns instead", value: "no" },
230
+ ], "yes");
231
+ if (use === "yes")
232
+ return written(mapping);
233
+ if (use === "no")
234
+ return "default";
235
+ mapping = await changeSome(d, mapping, o.columns, o.fromBoard);
236
+ }
237
+ }
238
+ /** A ready column, asked for when builds from the board turn on and the
239
+ * settings give ready none: one of the board's, or null to add Ready. */
240
+ export async function askReady(d, o) {
241
+ d.out("");
242
+ d.out("Builds from the board start when a ticket moves to the ready column,");
243
+ d.out("and your settings give ready no column.");
244
+ for (;;) {
245
+ const v = await d.ask.select("Which column shows ready?", [
246
+ ...o.columns.map((c) => ({ name: c, value: `column:${c}` })),
247
+ ...(onBoard("Ready", o.columns)
248
+ ? []
249
+ : [{ name: 'Add a column called "Ready"', value: ADD }]),
250
+ ]);
251
+ if (v === ADD)
252
+ return null;
253
+ const name = v.slice(7);
254
+ const other = showing(name, "ready", o.current);
255
+ if (!other)
256
+ return name;
257
+ d.out(`${name} already shows ${other}. Pick another column for ready.`);
258
+ }
259
+ }
package/dist/config.d.mts CHANGED
@@ -47,7 +47,9 @@ export type Settings = {
47
47
  options: Record<string, string>;
48
48
  board: number | null;
49
49
  /** The board's column for each state, null for none. */
50
- columns: Record<StateKey, string | null>;
50
+ /** Each state's columns, the first the one a ticket moves to, or
51
+ * null for none. */
52
+ columns: Record<StateKey, readonly string[] | null>;
51
53
  /** The board's field for each of three the sync writes, null for none. */
52
54
  fields: Record<FieldKey, string | null>;
53
55
  };
@@ -192,6 +194,9 @@ export type Deps = {
192
194
  };
193
195
  /** `.claude/factory.choices.yaml`, null when there is none. */
194
196
  readChoices?: () => string | null;
197
+ /** The text of `.npmrc` at the root, or null. Read from disk unless
198
+ * given. */
199
+ readNpmrc?: () => string | null;
195
200
  /** Where presets are installed from. */
196
201
  root?: string;
197
202
  /** Which of the settings files differ from the last commit. */
package/dist/config.mjs CHANGED
@@ -312,6 +312,35 @@ function names(v, key, defaults) {
312
312
  return [k, value.trim()];
313
313
  }));
314
314
  }
315
+ /** Each state's columns: a name, a list of names, or none, each left out
316
+ * keeping the factory's own name. Only an approved ticket goes to ready,
317
+ * so it takes one name. */
318
+ function columnNames(v) {
319
+ const o = object(v, "tickets.columns");
320
+ const out = {};
321
+ for (const [k, status] of Object.entries(STATE_KEYS)) {
322
+ const key = `tickets.columns.${k}`;
323
+ const value = o[k];
324
+ if (Array.isArray(value)) {
325
+ if (k === "ready")
326
+ fail(key, "must be one column, or none: only a ticket you approved goes there");
327
+ if (value.length === 0)
328
+ fail(key, "must name at least one column");
329
+ out[k] = value.map((n, i) => typeof n === "string" && n.trim()
330
+ ? n.trim()
331
+ : fail(`${key}[${i}]`, "must be a name"));
332
+ }
333
+ else if (value === undefined)
334
+ out[k] = DEFAULT_COLUMNS[status];
335
+ else if (value === "none")
336
+ out[k] = null;
337
+ else if (typeof value === "string" && value.trim())
338
+ out[k] = [value.trim()];
339
+ else
340
+ fail(key, "must be a name, a list of names, or none");
341
+ }
342
+ return out;
343
+ }
315
344
  /** A part you can swap, written as a block with a `type` or as one word. */
316
345
  function typed(v, key, extra) {
317
346
  if (typeof v === "string")
@@ -479,17 +508,20 @@ export function parseSettings(raw, exists, built = BUILT) {
479
508
  fail("tickets.columns", "needs tickets.board");
480
509
  if (tickets.fields !== undefined && !hasBoard)
481
510
  fail("tickets.fields", "needs tickets.board");
482
- const columns = names(tickets.columns, "tickets.columns", Object.fromEntries(Object.entries(STATE_KEYS).map(([k, s]) => [k, DEFAULT_COLUMNS[s]])));
511
+ const columns = columnNames(tickets.columns);
483
512
  if (columns.backlog === null)
484
513
  fail("tickets.columns.backlog", "cannot be none: every ticket starts there");
485
514
  const seen = new Map();
486
- for (const [key, name] of Object.entries(columns)) {
487
- if (name === null)
488
- continue;
489
- const other = [...seen].find(([n]) => sameName(n, name));
490
- if (other)
491
- fail(`tickets.columns.${key}`, `names the same column as ${other[1]}`);
492
- seen.set(name, key);
515
+ for (const [key, list] of Object.entries(columns)) {
516
+ for (const [i, name] of (list ?? []).entries()) {
517
+ if (list.slice(0, i).some((n) => sameName(n, name)))
518
+ fail(`tickets.columns.${key}`, `names ${name} twice`);
519
+ const other = [...seen].find(([n]) => sameName(n, name));
520
+ if (other)
521
+ fail(`tickets.columns.${key}`, `names the same column as ${other[1]}`);
522
+ }
523
+ for (const name of list ?? [])
524
+ seen.set(name, key);
493
525
  }
494
526
  if (columns.ready === null && trigger !== "manual")
495
527
  fail("tickets.columns.ready", "no column shows ready, so nothing would start a build: name one, or set builds.trigger to manual");
@@ -743,6 +775,11 @@ export async function staleOf(d) {
743
775
  ? (P.findPackage(root, pkg)?.version ?? null)
744
776
  : undefined),
745
777
  load,
778
+ npmrcNames: (await import("./npmrc.mjs")).readNpmrc(d.readNpmrc
779
+ ? d.readNpmrc()
780
+ : existsSync(join(root, ".npmrc"))
781
+ ? readFileSync(join(root, ".npmrc"), "utf8")
782
+ : null).names,
746
783
  });
747
784
  }
748
785
  /** The settings in the lock, after checking it is current where `check`
package/dist/doctor.d.mts CHANGED
@@ -21,6 +21,9 @@ export type DoctorDeps = {
21
21
  out: (line: string) => void;
22
22
  };
23
23
  export declare function checks(d: DoctorDeps): Promise<Check[]>;
24
+ /** Whether Dependabot's settings name the registry at `url` under their
25
+ * `registries`, and every npm update lists it, or all of them. */
26
+ export declare function usesRegistry(settings: string, url: string): boolean;
24
27
  /** One check as a line: a tick, a cross with what to do, or a dash for a
25
28
  * part that is off. */
26
29
  export declare function line(c: Check): string;