@davidbyoung/software-factory 0.1.2 → 0.1.4
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.
- package/README.md +20 -20
- package/actions/factory-agent/action.yml +1 -1
- package/agents/factory-e2e-reviewer.md +102 -0
- package/agents/factory-test-reviewer.md +26 -64
- package/agents/factory-ticket-readiness.md +14 -6
- package/dist/agent/claude-code.d.mts +3 -0
- package/dist/agent/claude-code.mjs +89 -0
- package/dist/agent/index.d.mts +2 -0
- package/dist/agent/index.mjs +5 -0
- package/dist/board.mjs +1 -1
- package/dist/cli.mjs +46 -4
- package/dist/code-host/github-setup.d.mts +5 -0
- package/dist/code-host/github-setup.mjs +133 -0
- package/dist/code-host/github.mjs +4 -0
- package/dist/code-host/index.d.mts +1 -1
- package/dist/code-host/index.mjs +2 -1
- package/dist/code-host/types.d.mts +2 -0
- package/dist/commands.d.mts +16 -0
- package/dist/commands.mjs +129 -0
- package/dist/config.d.mts +87 -20
- package/dist/config.mjs +344 -89
- package/dist/deps.d.mts +7 -4
- package/dist/deps.mjs +20 -9
- package/dist/doctor.d.mts +9 -16
- package/dist/doctor.mjs +71 -68
- package/dist/explain.d.mts +4 -0
- package/dist/explain.mjs +174 -0
- package/dist/guard-commit.d.mts +7 -2
- package/dist/guard-commit.mjs +58 -21
- package/dist/init.d.mts +12 -14
- package/dist/init.mjs +194 -136
- package/dist/lib/default-branch.d.mts +35 -0
- package/dist/lib/default-branch.mjs +117 -0
- package/dist/lib/has-command.d.mts +5 -0
- package/dist/lib/has-command.mjs +8 -0
- package/dist/lib/listed.d.mts +2 -0
- package/dist/lib/listed.mjs +4 -0
- package/dist/lib/refined-check.d.mts +7 -0
- package/dist/lib/refined-check.mjs +76 -0
- package/dist/lib/work-status.d.mts +12 -2
- package/dist/lib/work-status.mjs +14 -3
- package/dist/parts.d.mts +18 -15
- package/dist/parts.mjs +15 -43
- package/dist/patch-coverage.d.mts +13 -0
- package/dist/patch-coverage.mjs +73 -0
- package/dist/poller.d.mts +20 -3
- package/dist/poller.mjs +62 -15
- package/dist/pr-watch.d.mts +3 -2
- package/dist/pr-watch.mjs +22 -5
- package/dist/pr.mjs +34 -2
- package/dist/remove.d.mts +11 -0
- package/dist/remove.mjs +156 -0
- package/dist/runner/github-actions.d.mts +1 -1
- package/dist/runner/github-actions.mjs +12 -0
- package/dist/runner/index.d.mts +1 -1
- package/dist/runner/index.mjs +2 -1
- package/dist/runner/setup.d.mts +2 -0
- package/dist/runner/setup.mjs +22 -0
- package/dist/runner/types.d.mts +3 -0
- package/dist/runner/types.mjs +0 -2
- package/dist/session-start.d.mts +23 -13
- package/dist/session-start.mjs +56 -44
- package/dist/setup.d.mts +98 -0
- package/dist/setup.mjs +3 -0
- package/dist/site/servers.d.mts +6 -2
- package/dist/site/servers.mjs +14 -9
- package/dist/site.mjs +2 -2
- package/dist/status.d.mts +4 -4
- package/dist/status.mjs +8 -7
- package/dist/sync.d.mts +26 -2
- package/dist/sync.mjs +177 -13
- package/dist/ticket.mjs +19 -1
- package/dist/tickets/github-setup.d.mts +2 -0
- package/dist/tickets/github-setup.mjs +50 -0
- package/dist/tickets/github.mjs +0 -2
- package/dist/tickets/index.mjs +2 -1
- package/dist/tickets/transport.mjs +1 -3
- package/dist/tickets/types.mjs +0 -2
- package/dist/tool-names.d.mts +11 -0
- package/dist/tool-names.mjs +20 -0
- package/dist/tools.d.mts +56 -0
- package/dist/tools.mjs +76 -0
- package/docs/builds.md +111 -59
- package/docs/cli.md +106 -69
- package/docs/configuration.md +489 -171
- package/docs/design.md +18 -5
- package/docs/developing.md +179 -73
- package/docs/existing-repo.md +25 -12
- package/docs/github/by-hand.md +334 -0
- package/docs/github/reference.md +76 -67
- package/docs/github/setup.md +105 -286
- package/docs/glossary.md +18 -7
- package/docs/limitations.md +39 -12
- package/docs/plugins.md +305 -56
- package/docs/quick-start.md +85 -100
- package/docs/removing.md +37 -17
- package/docs/skills.md +121 -62
- package/docs/updating.md +150 -9
- package/docs/workflow.md +23 -19
- package/package.json +1 -1
- package/poller.Dockerfile +10 -18
- package/review.md +20 -11
- package/rules.md +36 -30
- package/settings.schema.json +313 -69
- package/skills/factory-address-review/SKILL.md +50 -30
- package/skills/factory-build/SKILL.md +76 -23
- package/skills/factory-deps/SKILL.md +46 -21
- package/skills/factory-design/SKILL.md +17 -8
- package/skills/factory-diagnose/SKILL.md +22 -20
- package/skills/factory-mutate/SKILL.md +38 -24
- package/skills/factory-refine/SKILL.md +55 -31
- package/skills/factory-resolve-conflicts/SKILL.md +76 -34
- package/skills/factory-trace/SKILL.md +80 -0
- package/workflows/factory-build.yml +6 -5
- package/workflows/factory-conflicts.yml +8 -8
- package/workflows/factory-deps-auto-merge.yml +3 -2
- package/workflows/factory-deps.yml +1 -1
- package/workflows/factory-poller.yml +46 -0
- package/workflows/factory-review.yml +1 -1
- package/skills/factory-address-review/patch-coverage.py +0 -68
package/dist/sync.mjs
CHANGED
|
@@ -7,13 +7,16 @@
|
|
|
7
7
|
// factory sync # write what differs
|
|
8
8
|
// factory sync --check # write nothing; exit 1 naming what differs
|
|
9
9
|
//
|
|
10
|
-
// A copy is the source, byte for byte
|
|
11
|
-
//
|
|
10
|
+
// A copy is the source, byte for byte but for what the settings and the
|
|
11
|
+
// repository decide: the minutes a session may run, the poller's schedule,
|
|
12
|
+
// the rules' numbers, and the default branch's name in the push triggers.
|
|
13
|
+
// Edit the source in the package, never the copy. A file the lock lists that the package no longer has is
|
|
12
14
|
// deleted. Nothing else is.
|
|
13
15
|
import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync, } from "node:fs";
|
|
14
16
|
import { dirname, join, relative, sep } from "node:path";
|
|
15
17
|
import { fileURLToPath } from "node:url";
|
|
16
|
-
import { defaultDeps, loadSettings, repoRoot, } from "./config.mjs";
|
|
18
|
+
import { defaultDeps, loadSettings, repoRoot, RULE_NUMBERS, } from "./config.mjs";
|
|
19
|
+
import { branchDeps, CANNOT_TELL, defaultBranch, } from "./lib/default-branch.mjs";
|
|
17
20
|
/** The package's own folder: the parent of `src/`, or of `dist/` once
|
|
18
21
|
* compiled. */
|
|
19
22
|
export const PACKAGE = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
@@ -30,13 +33,43 @@ const DEPENDABOT = ".github/dependabot.yml";
|
|
|
30
33
|
const NEEDS = {
|
|
31
34
|
"skills/factory-design": (s) => s.site !== null,
|
|
32
35
|
"agents/factory-ui-reviewer.md": (s) => s.site !== null,
|
|
36
|
+
"agents/factory-e2e-reviewer.md": (s) => s.commands.endToEnd !== null,
|
|
33
37
|
"skills/factory-deps": (_, has) => has(DEPENDABOT),
|
|
34
38
|
"workflows/factory-deps.yml": (_, has) => has(DEPENDABOT),
|
|
35
39
|
"workflows/factory-deps-auto-merge.yml": (_, has) => has(DEPENDABOT),
|
|
36
40
|
"workflows/factory-board-sync.yml": (s) => s.tickets.board !== null,
|
|
37
41
|
"workflows/factory-merge-policy.yml": (s) => s.autoMerge.allow.length > 0,
|
|
38
42
|
"workflows/factory-claude-review.yml": (s) => s.ciReview !== null,
|
|
43
|
+
"workflows/factory-poller.yml": (s) => s.builds.trigger === "github-action",
|
|
39
44
|
};
|
|
45
|
+
const POLLER_WORKFLOW = "workflows/factory-poller.yml";
|
|
46
|
+
/** The scheduled poller's workflow, its one `cron` line set to run every
|
|
47
|
+
* `minutes`: on the hour for 60, every N minutes past it otherwise. */
|
|
48
|
+
export function withSchedule(text, minutes, file) {
|
|
49
|
+
const pattern = /^(\s+- cron: )"[^"]*"$/gm;
|
|
50
|
+
if ((text.match(pattern) ?? []).length !== 1)
|
|
51
|
+
throw new Error(`${file}: expected one cron line, to set the poller's schedule`);
|
|
52
|
+
const cron = minutes === 60 ? "0 * * * *" : `*/${minutes} * * * *`;
|
|
53
|
+
return text.replace(pattern, (_, lead) => `${lead}"${cron}"`);
|
|
54
|
+
}
|
|
55
|
+
/** The workflows whose push trigger names the default branch. A workflow
|
|
56
|
+
* cannot ask for it in a trigger, so the sync writes it there. */
|
|
57
|
+
const PUSH_WORKFLOWS = [
|
|
58
|
+
"workflows/factory-check.yml",
|
|
59
|
+
"workflows/factory-conflicts.yml",
|
|
60
|
+
];
|
|
61
|
+
/** A workflow with the one `branches:` line of its push trigger naming the
|
|
62
|
+
* default branch and nothing else. */
|
|
63
|
+
export function withDefaultBranch(text, name, file) {
|
|
64
|
+
const pattern = /^(\s+branches: )\[[^\]\n]*\]$/gm;
|
|
65
|
+
if ((text.match(pattern) ?? []).length !== 1)
|
|
66
|
+
throw new Error(`${file}: expected one branches line, to set the push trigger's branch`);
|
|
67
|
+
// Plain where YAML reads the name as text, quoted otherwise.
|
|
68
|
+
const written = /^[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(name)
|
|
69
|
+
? name
|
|
70
|
+
: JSON.stringify(name);
|
|
71
|
+
return text.replace(pattern, (_, lead) => `${lead}[${written}]`);
|
|
72
|
+
}
|
|
40
73
|
/** The workflows that run a Claude session, by the kind of session each
|
|
41
74
|
* runs. */
|
|
42
75
|
const SESSION_WORKFLOWS = {
|
|
@@ -57,6 +90,81 @@ export function withMinutes(text, minutes, file) {
|
|
|
57
90
|
const session = one(/^(\s+minutes: )\d+$/gm, minutes, text);
|
|
58
91
|
return one(/^(\s+timeout-minutes: )\d+$/gm, minutes + 10, session);
|
|
59
92
|
}
|
|
93
|
+
const WORDS = [
|
|
94
|
+
"zero",
|
|
95
|
+
"one",
|
|
96
|
+
"two",
|
|
97
|
+
"three",
|
|
98
|
+
"four",
|
|
99
|
+
"five",
|
|
100
|
+
"six",
|
|
101
|
+
"seven",
|
|
102
|
+
"eight",
|
|
103
|
+
"nine",
|
|
104
|
+
"ten",
|
|
105
|
+
];
|
|
106
|
+
const ORDINALS = [
|
|
107
|
+
"zeroth",
|
|
108
|
+
"first",
|
|
109
|
+
"second",
|
|
110
|
+
"third",
|
|
111
|
+
"fourth",
|
|
112
|
+
"fifth",
|
|
113
|
+
"sixth",
|
|
114
|
+
"seventh",
|
|
115
|
+
"eighth",
|
|
116
|
+
"ninth",
|
|
117
|
+
"tenth",
|
|
118
|
+
"eleventh",
|
|
119
|
+
];
|
|
120
|
+
const count = (n) => WORDS[n] ?? String(n);
|
|
121
|
+
const ordinal = (n) => ORDINALS[n] ??
|
|
122
|
+
`${n}${n % 100 >= 11 && n % 100 <= 13 ? "th" : (["th", "st", "nd", "rd"][n % 10] ?? "th")}`;
|
|
123
|
+
const capital = (s) => s[0].toUpperCase() + s.slice(1);
|
|
124
|
+
const rounds = (n) => `${count(n)} round${n === 1 ? "" : "s"}`;
|
|
125
|
+
/** The phrases in a copied file that state one of the rules' numbers, by
|
|
126
|
+
* the file's path in the package: each the default's words, the setting's
|
|
127
|
+
* words, and whether the setting differs from its default. */
|
|
128
|
+
const RULE_PHRASES = {
|
|
129
|
+
"rules.md": (r) => [
|
|
130
|
+
[
|
|
131
|
+
/under about 30 lines/g,
|
|
132
|
+
`under about ${r.smallChangeLines} lines`,
|
|
133
|
+
r.smallChangeLines !== RULE_NUMBERS["small-change-lines"],
|
|
134
|
+
],
|
|
135
|
+
[
|
|
136
|
+
/After two rounds,/g,
|
|
137
|
+
`After ${rounds(r.reviewRounds)},`,
|
|
138
|
+
r.reviewRounds !== RULE_NUMBERS["review-rounds"],
|
|
139
|
+
],
|
|
140
|
+
],
|
|
141
|
+
"skills/factory-address-review/SKILL.md": (r) => [
|
|
142
|
+
[
|
|
143
|
+
/^## 6\. Two rounds, then escalate$/gm,
|
|
144
|
+
`## 6. ${capital(rounds(r.reviewRounds))}, then escalate`,
|
|
145
|
+
r.reviewRounds !== RULE_NUMBERS["review-rounds"],
|
|
146
|
+
],
|
|
147
|
+
[
|
|
148
|
+
/at most two(\s+)rounds\*\*\. When the third review arrives/g,
|
|
149
|
+
`at most ${count(r.reviewRounds)}$1round${r.reviewRounds === 1 ? "" : "s"}**. When the ${ordinal(r.reviewRounds + 1)} review arrives`,
|
|
150
|
+
r.reviewRounds !== RULE_NUMBERS["review-rounds"],
|
|
151
|
+
],
|
|
152
|
+
],
|
|
153
|
+
};
|
|
154
|
+
/** A copy with the rules' numbers the settings give in place of the
|
|
155
|
+
* defaults. A phrase is replaced only when its number is not the default,
|
|
156
|
+
* and must then match exactly once. */
|
|
157
|
+
export function withRules(text, r, file) {
|
|
158
|
+
let out = text;
|
|
159
|
+
for (const [pattern, words, set] of RULE_PHRASES[file]?.(r) ?? []) {
|
|
160
|
+
if (!set)
|
|
161
|
+
continue;
|
|
162
|
+
if ((out.match(pattern) ?? []).length !== 1)
|
|
163
|
+
throw new Error(`${file}: expected one match for ${pattern.source}, to set a number from rules`);
|
|
164
|
+
out = out.replace(pattern, words);
|
|
165
|
+
}
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
60
168
|
function walk(dir, base = dir) {
|
|
61
169
|
if (!existsSync(dir))
|
|
62
170
|
return [];
|
|
@@ -177,6 +285,14 @@ const isFactory = (h) => typeof h.command === "string" && h.command.includes(`/$
|
|
|
177
285
|
* sets its own. Every other entry stays, in its order. */
|
|
178
286
|
export function withHooks(text, launcher) {
|
|
179
287
|
const settings = text ? JSON.parse(text) : {};
|
|
288
|
+
const hooks = othersHooks(settings);
|
|
289
|
+
for (const [event, group] of factoryHooks(launcher))
|
|
290
|
+
(hooks[event] ??= []).push(group);
|
|
291
|
+
const attribution = settings.attribution ?? NO_ATTRIBUTION;
|
|
292
|
+
return `${JSON.stringify({ ...settings, attribution, hooks }, null, 2)}\n`;
|
|
293
|
+
}
|
|
294
|
+
/** Every hook entry that is not the factory's, by event. */
|
|
295
|
+
function othersHooks(settings) {
|
|
180
296
|
const hooks = {};
|
|
181
297
|
for (const [event, groups] of Object.entries(settings.hooks ?? {})) {
|
|
182
298
|
const kept = groups
|
|
@@ -185,19 +301,53 @@ export function withHooks(text, launcher) {
|
|
|
185
301
|
if (kept.length)
|
|
186
302
|
hooks[event] = kept;
|
|
187
303
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
304
|
+
return hooks;
|
|
305
|
+
}
|
|
306
|
+
/** Whether every event of the five has the factory's entry. */
|
|
307
|
+
export function hasFactoryHooks(text) {
|
|
308
|
+
if (!text)
|
|
309
|
+
return false;
|
|
310
|
+
const hooks = JSON.parse(text).hooks ?? {};
|
|
311
|
+
return factoryHooks(LAUNCHER).every(([event]) => (hooks[event] ?? []).some((g) => g.hooks.some(isFactory)));
|
|
312
|
+
}
|
|
313
|
+
/** Whether any hook entry is the factory's. */
|
|
314
|
+
export function hasAnyFactoryHook(text) {
|
|
315
|
+
if (!text)
|
|
316
|
+
return false;
|
|
317
|
+
const hooks = JSON.parse(text).hooks ?? {};
|
|
318
|
+
return Object.values(hooks).some((groups) => groups.some((g) => g.hooks.some(isFactory)));
|
|
319
|
+
}
|
|
320
|
+
/** `.claude/settings.json` with the factory's entries taken out and an
|
|
321
|
+
* emptied `hooks` dropped, or null when nothing is left. */
|
|
322
|
+
export function withoutHooks(text) {
|
|
323
|
+
const { hooks: _, ...rest } = JSON.parse(text);
|
|
324
|
+
const hooks = othersHooks(JSON.parse(text));
|
|
325
|
+
const after = Object.keys(hooks).length ? { ...rest, hooks } : rest;
|
|
326
|
+
return Object.keys(after).length
|
|
327
|
+
? `${JSON.stringify(after, null, 2)}\n`
|
|
328
|
+
: null;
|
|
192
329
|
}
|
|
330
|
+
export const hasImport = (text) => text !== null && text.split("\n").some((line) => line.trim() === IMPORT_LINE);
|
|
193
331
|
/** `CLAUDE.md` with the rules' import added when no line is that import. */
|
|
194
332
|
export function withImport(text) {
|
|
195
333
|
if (text === null)
|
|
196
334
|
return `${IMPORT_LINE}\n`;
|
|
197
|
-
if (text
|
|
335
|
+
if (hasImport(text))
|
|
198
336
|
return text;
|
|
199
337
|
return `${text}${text.endsWith("\n") || !text ? "" : "\n"}\n${IMPORT_LINE}\n`;
|
|
200
338
|
}
|
|
339
|
+
/** `CLAUDE.md` without the rules' import, nor the blank line `withImport`
|
|
340
|
+
* put before it, or null when nothing else is left. */
|
|
341
|
+
export function withoutImport(text) {
|
|
342
|
+
const lines = text.split("\n");
|
|
343
|
+
const at = lines.findIndex((line) => line.trim() === IMPORT_LINE);
|
|
344
|
+
if (at < 0)
|
|
345
|
+
return text;
|
|
346
|
+
const from = at > 0 && lines[at - 1] === "" ? at - 1 : at;
|
|
347
|
+
lines.splice(from, at - from + 1);
|
|
348
|
+
const after = lines.join("\n");
|
|
349
|
+
return after.trim() ? after : null;
|
|
350
|
+
}
|
|
201
351
|
export function lockText(version, files) {
|
|
202
352
|
return [
|
|
203
353
|
"# Written by `factory sync`: the factory's version and the files it",
|
|
@@ -216,18 +366,24 @@ export function lockedFiles(text) {
|
|
|
216
366
|
.map((l) => /^ {2}- (.+)$/.exec(l)?.[1])
|
|
217
367
|
.filter((f) => Boolean(f));
|
|
218
368
|
}
|
|
219
|
-
/** What a sync of `root` from `pkg` writes and deletes
|
|
220
|
-
|
|
369
|
+
/** What a sync of `root` from `pkg` writes and deletes, in a repository
|
|
370
|
+
* whose default branch is `branch`. */
|
|
371
|
+
export function plan(pkg, root, s, branch) {
|
|
221
372
|
const manifest = JSON.parse(readFileSync(join(pkg, "package.json"), "utf8"));
|
|
222
373
|
const read = (p) => existsSync(join(root, p)) ? readFileSync(join(root, p), "utf8") : null;
|
|
223
374
|
const write = new Map();
|
|
224
375
|
const has = (p) => existsSync(join(root, p));
|
|
225
376
|
for (const [from, to] of copies(pkg, s, has)) {
|
|
226
|
-
const
|
|
377
|
+
const source = readFileSync(join(pkg, from), "utf8");
|
|
378
|
+
const text = PUSH_WORKFLOWS.includes(from)
|
|
379
|
+
? withDefaultBranch(source, branch, from)
|
|
380
|
+
: source;
|
|
227
381
|
const kind = SESSION_WORKFLOWS[from.replace(/^workflows\//, "")];
|
|
228
382
|
write.set(to, kind && from.startsWith("workflows/")
|
|
229
383
|
? withMinutes(text, s.sessionMinutes[kind], from)
|
|
230
|
-
:
|
|
384
|
+
: from === POLLER_WORKFLOW
|
|
385
|
+
? withSchedule(text, s.builds.pollMinutes, from)
|
|
386
|
+
: withRules(text, s.rules, from));
|
|
231
387
|
}
|
|
232
388
|
const launcher = launcherPath(pkg, root, manifest.name);
|
|
233
389
|
write.set(SETTINGS_JSON, withHooks(read(SETTINGS_JSON), launcher));
|
|
@@ -257,7 +413,14 @@ export async function main(argv, d) {
|
|
|
257
413
|
d.err(e instanceof Error ? e.message : String(e));
|
|
258
414
|
return 1;
|
|
259
415
|
}
|
|
260
|
-
|
|
416
|
+
// Nothing is written with a guessed name: a push trigger that names the
|
|
417
|
+
// wrong branch never runs.
|
|
418
|
+
const branch = await d.defaultBranch();
|
|
419
|
+
if (branch === null) {
|
|
420
|
+
d.err(CANNOT_TELL);
|
|
421
|
+
return 1;
|
|
422
|
+
}
|
|
423
|
+
const p = plan(d.pkg, d.root, s, branch);
|
|
261
424
|
const differ = differences(d.root, p);
|
|
262
425
|
if (check) {
|
|
263
426
|
if (differ.length === 0)
|
|
@@ -289,6 +452,7 @@ export async function run(argv) {
|
|
|
289
452
|
root,
|
|
290
453
|
pkg: PACKAGE,
|
|
291
454
|
settings: () => loadSettings(defaultDeps(root)),
|
|
455
|
+
defaultBranch: () => defaultBranch(branchDeps(root)),
|
|
292
456
|
out: (line) => console.log(line),
|
|
293
457
|
err: (line) => console.error(line),
|
|
294
458
|
});
|
package/dist/ticket.mjs
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// npx --no-install factory ticket stop N "one-line reason"
|
|
9
9
|
// npx --no-install factory ticket end N
|
|
10
10
|
// npx --no-install factory ticket refining|waiting N
|
|
11
|
-
// npx --no-install factory ticket refined N [--before-file FILE]
|
|
11
|
+
// npx --no-install factory ticket refined N [--check] [--before-file FILE]
|
|
12
12
|
// npx --no-install factory follow-up FILE "what is wrong"
|
|
13
13
|
// npx --no-install factory ticket ready N
|
|
14
14
|
// npx --no-install factory ticket cost N
|
|
@@ -36,6 +36,11 @@
|
|
|
36
36
|
// or pull request N. The clock is keyed by CLAUDE_CODE_SESSION_ID, the ID the
|
|
37
37
|
// hooks receive and the transcript's file name.
|
|
38
38
|
//
|
|
39
|
+
// `refined` posts its marker only on a ticket whose body a build can read
|
|
40
|
+
// (`lib/refined-check.mts`): otherwise it prints one line for each part that
|
|
41
|
+
// is missing and exits 1. With `--check` it posts nothing, and prints
|
|
42
|
+
// `sound` when nothing is missing.
|
|
43
|
+
//
|
|
39
44
|
// `ready` moves issue N's card to Ready when the owner asks a session to, so
|
|
40
45
|
// the sync and the poller treat it as the owner's own move. It is the one
|
|
41
46
|
// write to Status outside the sync, and needs the project scope:
|
|
@@ -55,6 +60,7 @@ import { openCodeHost } from "./code-host/index.mjs";
|
|
|
55
60
|
import { openRunner } from "./runner/index.mjs";
|
|
56
61
|
import { loadSettings, targetOf } from "./config.mjs";
|
|
57
62
|
import { commentBody, sameName, reviewingPulls, workState, } from "./lib/work-status.mjs";
|
|
63
|
+
import { missingParts } from "./lib/refined-check.mjs";
|
|
58
64
|
import { commonDir, readClock, writeClock } from "./lib/clock.mjs";
|
|
59
65
|
import { costNote, measureSession, projectsDir } from "./lib/usage.mjs";
|
|
60
66
|
import { boardConfigOf, checkFields } from "./board.mjs";
|
|
@@ -509,6 +515,18 @@ export async function main(argv, deps) {
|
|
|
509
515
|
await post(d, issue, { kind: "cost", cost: takeCost(issue, d) });
|
|
510
516
|
break;
|
|
511
517
|
case "refined": {
|
|
518
|
+
// A body the build could not read gets no marker, whoever wrote it.
|
|
519
|
+
const ticket = await d.tickets.read(issue);
|
|
520
|
+
const missing = missingParts(ticket.body, ticket.labels);
|
|
521
|
+
if (missing.length > 0) {
|
|
522
|
+
for (const line of missing)
|
|
523
|
+
console.error(line);
|
|
524
|
+
return 1;
|
|
525
|
+
}
|
|
526
|
+
if (rest.includes("--check")) {
|
|
527
|
+
d.out("sound");
|
|
528
|
+
return 0;
|
|
529
|
+
}
|
|
512
530
|
const at = rest.indexOf("--before-file");
|
|
513
531
|
const before = at === -1 ? undefined : d.readFile(rest[at + 1]);
|
|
514
532
|
await post(d, issue, {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// GitHub Issues as the ticket system: the board check, and the fields
|
|
2
|
+
// removing the factory leaves on the board. Its token is the code host's.
|
|
3
|
+
import { boardConfigOf, inspectBoard } from "../board.mjs";
|
|
4
|
+
import { fieldNamesOf } from "../config.mjs";
|
|
5
|
+
import { listed } from "../lib/listed.mjs";
|
|
6
|
+
const INIT = "Run npx --no-install factory init";
|
|
7
|
+
export const githubTicketsSetup = {
|
|
8
|
+
checks: async (c) => {
|
|
9
|
+
const s = c.settings;
|
|
10
|
+
if (s === null || s.tickets.board === null)
|
|
11
|
+
return [];
|
|
12
|
+
const number = s.tickets.board;
|
|
13
|
+
try {
|
|
14
|
+
const board = await c.opened.tickets.board.read();
|
|
15
|
+
const { problems } = inspectBoard(board.fields, boardConfigOf(s));
|
|
16
|
+
return [
|
|
17
|
+
problems.length === 0
|
|
18
|
+
? {
|
|
19
|
+
state: "pass",
|
|
20
|
+
text: `Board ${number} has every column the settings name`,
|
|
21
|
+
}
|
|
22
|
+
: {
|
|
23
|
+
state: "fail",
|
|
24
|
+
text: `Board ${number}: ${problems.join("; ")}`,
|
|
25
|
+
fix: INIT,
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
return [
|
|
31
|
+
{
|
|
32
|
+
state: "fail",
|
|
33
|
+
text: `Board ${number} can be read`,
|
|
34
|
+
fix: e instanceof Error ? e.message : String(e),
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
leftovers: (c) => {
|
|
40
|
+
const s = c.settings;
|
|
41
|
+
if (s === null || s.tickets.board === null)
|
|
42
|
+
return [];
|
|
43
|
+
const fields = Object.values(fieldNamesOf(s)).filter((f) => f !== null);
|
|
44
|
+
return fields.length
|
|
45
|
+
? [
|
|
46
|
+
`Delete the ${listed(fields)} field${fields.length === 1 ? "" : "s"} from board ${s.tickets.board}, if you do not want them`,
|
|
47
|
+
]
|
|
48
|
+
: [];
|
|
49
|
+
},
|
|
50
|
+
};
|
package/dist/tickets/github.mjs
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
// organization. It reaches GitHub through
|
|
4
4
|
// the transport it is given (`transport.mts`), and picks REST or GraphQL per
|
|
5
5
|
// call.
|
|
6
|
-
//
|
|
7
|
-
// Node built-ins only: the poller's image copies this file.
|
|
8
6
|
import { rmSync, writeFileSync } from "node:fs";
|
|
9
7
|
import { tmpdir } from "node:os";
|
|
10
8
|
import { dirname, join } from "node:path";
|
package/dist/tickets/index.mjs
CHANGED
|
@@ -5,9 +5,10 @@ import { gh } from "../lib/gh.mjs";
|
|
|
5
5
|
import { fieldNamesOf } from "../config.mjs";
|
|
6
6
|
import { githubTickets } from "./github.mjs";
|
|
7
7
|
import { ghTransport } from "./transport.mjs";
|
|
8
|
+
import { BUILT, unsupported } from "../tool-names.mjs";
|
|
8
9
|
export * from "./types.mjs";
|
|
9
10
|
/** The ticket system's message for a type that is not built. */
|
|
10
|
-
export const unsupportedType = (type) =>
|
|
11
|
+
export const unsupportedType = (type) => unsupported("tickets.type", type, "ticket system", Object.keys(BUILT.tickets));
|
|
11
12
|
/** The settings' adapter, reaching its system through the GitHub CLI. The
|
|
12
13
|
* repository and board are the caller's, since a workflow can name its own. */
|
|
13
14
|
export async function openTickets(settings, target, run = gh) {
|
|
@@ -3,14 +3,12 @@
|
|
|
3
3
|
// the GitHub CLI, for sessions and CI. `fetchTransport` calls the API with a
|
|
4
4
|
// token, for the poller, which runs with no `gh` and no install. A failed
|
|
5
5
|
// call rejects, so a failed read is never mistaken for an empty answer.
|
|
6
|
-
//
|
|
7
|
-
// Node built-ins only: the poller's image copies this file.
|
|
8
6
|
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
9
7
|
import { tmpdir } from "node:os";
|
|
10
8
|
import { join } from "node:path";
|
|
11
9
|
/** A call GitHub answered with an HTTP error. */
|
|
12
10
|
export class HttpError extends Error {
|
|
13
|
-
// A plain field, not a parameter property: the
|
|
11
|
+
// A plain field, not a parameter property: the factory runs its source
|
|
14
12
|
// unbuilt, and Node's type stripping refuses parameter properties.
|
|
15
13
|
status;
|
|
16
14
|
/** What GitHub said was wrong: the `message` in its answer, or the status
|
package/dist/tickets/types.mjs
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
// adapter added beside `github.mts`, not a rewrite of the commands. What a
|
|
4
4
|
// ticket's state means (the marker comments, costs, and the views) stays
|
|
5
5
|
// above it, in `lib/work-status.mts` and the commands.
|
|
6
|
-
//
|
|
7
|
-
// Node built-ins only: the poller's image copies this file.
|
|
8
6
|
export const GROUPS = [
|
|
9
7
|
"board",
|
|
10
8
|
"blockers",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Built = {
|
|
2
|
+
codeHost: readonly string[];
|
|
3
|
+
/** Each ticket system, with the keys it adds under `tickets`. */
|
|
4
|
+
tickets: Readonly<Record<string, readonly string[]>>;
|
|
5
|
+
runner: readonly string[];
|
|
6
|
+
};
|
|
7
|
+
export declare const BUILT: Built;
|
|
8
|
+
/** The words every command fails with for a name that is not built, such
|
|
9
|
+
* as `tickets.type "jira" is not supported. "github" is the only ticket
|
|
10
|
+
* system built.` */
|
|
11
|
+
export declare function unsupported(key: string, name: string, noun: string, built: readonly string[]): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// The tools the factory has built, by the name a setting gives each, and the
|
|
2
|
+
// keys a ticket system adds under `tickets`. `config.mts` checks the
|
|
3
|
+
// settings against these, and `tools.mts` registers what each name runs; a
|
|
4
|
+
// test fails when the two differ. It imports nothing that imports the
|
|
5
|
+
// settings, so both can read it.
|
|
6
|
+
import { listed } from "./lib/listed.mjs";
|
|
7
|
+
export const BUILT = {
|
|
8
|
+
codeHost: ["github"],
|
|
9
|
+
tickets: { github: [] },
|
|
10
|
+
runner: ["github-actions"],
|
|
11
|
+
};
|
|
12
|
+
/** The words every command fails with for a name that is not built, such
|
|
13
|
+
* as `tickets.type "jira" is not supported. "github" is the only ticket
|
|
14
|
+
* system built.` */
|
|
15
|
+
export function unsupported(key, name, noun, built) {
|
|
16
|
+
const names = built.map((n) => `"${n}"`);
|
|
17
|
+
return names.length === 1
|
|
18
|
+
? `${key} "${name}" is not supported. ${names[0]} is the only ${noun} built.`
|
|
19
|
+
: `${key} "${name}" is not supported. The ${noun}s built are ${listed(names)}.`;
|
|
20
|
+
}
|
package/dist/tools.d.mts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type CodeHost } from "./code-host/index.mts";
|
|
2
|
+
import type { Settings } from "./config.mts";
|
|
3
|
+
import type { Part } from "./parts.mts";
|
|
4
|
+
import { type Runner } from "./runner/index.mts";
|
|
5
|
+
import type { Chosen, SecretStep, SetupContext, SetupStep, ToolSetup } from "./setup.mts";
|
|
6
|
+
import { type Tickets } from "./tickets/index.mts";
|
|
7
|
+
import { type Built } from "./tool-names.mts";
|
|
8
|
+
export type Tool = {
|
|
9
|
+
label: string;
|
|
10
|
+
setup: ToolSetup;
|
|
11
|
+
};
|
|
12
|
+
export type Registry = {
|
|
13
|
+
codeHost: Record<string, Tool & {
|
|
14
|
+
/** The repository a remote's address names, or null for one on
|
|
15
|
+
* another code host. */
|
|
16
|
+
repositoryOf(remote: string): string | null;
|
|
17
|
+
open(repository: string): CodeHost;
|
|
18
|
+
}>;
|
|
19
|
+
tickets: Record<string, Tool & {
|
|
20
|
+
/** The keys it adds under `tickets`. */
|
|
21
|
+
keys: readonly string[];
|
|
22
|
+
open(target: {
|
|
23
|
+
repository: string;
|
|
24
|
+
board: number | null;
|
|
25
|
+
}, settings: Settings | null): Tickets | Promise<Tickets>;
|
|
26
|
+
}>;
|
|
27
|
+
runner: Record<string, Tool & {
|
|
28
|
+
open(repository: string): Runner;
|
|
29
|
+
}>;
|
|
30
|
+
agent: Record<string, Tool>;
|
|
31
|
+
};
|
|
32
|
+
export declare const TOOLS: Registry;
|
|
33
|
+
/** The names and keys the settings accept, as `config.mts` checks them. */
|
|
34
|
+
export declare function builtOf(r: Registry): Built;
|
|
35
|
+
/** The tools in use, in the order setup asks for them. */
|
|
36
|
+
export declare function inUse(r: Registry, chosen: Chosen): Tool[];
|
|
37
|
+
/** Each tool's steps for the context, with the tool's label. */
|
|
38
|
+
export declare function stepsOf(r: Registry, c: SetupContext): {
|
|
39
|
+
tool: string;
|
|
40
|
+
step: SetupStep;
|
|
41
|
+
}[];
|
|
42
|
+
/** The secret steps among them. */
|
|
43
|
+
export declare function secretSteps(r: Registry, c: SetupContext): {
|
|
44
|
+
tool: string;
|
|
45
|
+
step: SecretStep;
|
|
46
|
+
}[];
|
|
47
|
+
/** The same context for other parts. */
|
|
48
|
+
export declare const withParts: (c: SetupContext, parts: Iterable<Part>) => {
|
|
49
|
+
parts: Set<"board" | "review" | "cloud" | "auto-merge" | "from-board" | "signing">;
|
|
50
|
+
repository: string;
|
|
51
|
+
root: string;
|
|
52
|
+
chosen: Chosen;
|
|
53
|
+
settings: Settings | null;
|
|
54
|
+
hasCommand: (name: string) => boolean;
|
|
55
|
+
opened: import("./setup.mts").Opened;
|
|
56
|
+
};
|
package/dist/tools.mjs
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Every tool the factory has built, by kind and by the name a setting gives
|
|
2
|
+
// it: how to open it, and its setup (`setup.mts`). `init`, `doctor`, and
|
|
3
|
+
// `remove` take this as a parameter, so a test adds a tool of its own.
|
|
4
|
+
import { claudeCodeSetup, DEFAULT_AGENT } from "./agent/index.mjs";
|
|
5
|
+
import { githubRepository, githubCodeHostSetup, } from "./code-host/github-setup.mjs";
|
|
6
|
+
import { openCodeHost } from "./code-host/index.mjs";
|
|
7
|
+
import { gh } from "./lib/gh.mjs";
|
|
8
|
+
import { openRunner } from "./runner/index.mjs";
|
|
9
|
+
import { githubTickets } from "./tickets/github.mjs";
|
|
10
|
+
import { githubTicketsSetup } from "./tickets/github-setup.mjs";
|
|
11
|
+
import { openTickets } from "./tickets/index.mjs";
|
|
12
|
+
import { ghTransport } from "./tickets/transport.mjs";
|
|
13
|
+
import { githubActionsSetup } from "./runner/setup.mjs";
|
|
14
|
+
import { BUILT } from "./tool-names.mjs";
|
|
15
|
+
export const TOOLS = {
|
|
16
|
+
codeHost: {
|
|
17
|
+
github: {
|
|
18
|
+
label: "GitHub",
|
|
19
|
+
setup: githubCodeHostSetup,
|
|
20
|
+
repositoryOf: githubRepository,
|
|
21
|
+
open: (repository) => openCodeHost(repository),
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
tickets: {
|
|
25
|
+
github: {
|
|
26
|
+
label: "GitHub Issues",
|
|
27
|
+
keys: BUILT.tickets.github,
|
|
28
|
+
setup: githubTicketsSetup,
|
|
29
|
+
open: (target, settings) => settings
|
|
30
|
+
? openTickets(settings, target).then((o) => o.tickets)
|
|
31
|
+
: githubTickets({
|
|
32
|
+
transport: ghTransport(gh),
|
|
33
|
+
repository: target.repository,
|
|
34
|
+
board: target.board,
|
|
35
|
+
}),
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
runner: {
|
|
39
|
+
"github-actions": {
|
|
40
|
+
label: "GitHub Actions",
|
|
41
|
+
setup: githubActionsSetup,
|
|
42
|
+
open: (repository) => openRunner(repository),
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
agent: { [DEFAULT_AGENT]: { label: "Claude Code", setup: claudeCodeSetup } },
|
|
46
|
+
};
|
|
47
|
+
/** The names and keys the settings accept, as `config.mts` checks them. */
|
|
48
|
+
export function builtOf(r) {
|
|
49
|
+
return {
|
|
50
|
+
codeHost: Object.keys(r.codeHost),
|
|
51
|
+
tickets: Object.fromEntries(Object.entries(r.tickets).map(([name, t]) => [name, t.keys])),
|
|
52
|
+
runner: Object.keys(r.runner),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** The tools in use, in the order setup asks for them. */
|
|
56
|
+
export function inUse(r, chosen) {
|
|
57
|
+
return [
|
|
58
|
+
r.agent[chosen.agent],
|
|
59
|
+
r.codeHost[chosen.codeHost],
|
|
60
|
+
r.tickets[chosen.tickets],
|
|
61
|
+
r.runner[chosen.runner],
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
/** Each tool's steps for the context, with the tool's label. */
|
|
65
|
+
export function stepsOf(r, c) {
|
|
66
|
+
return inUse(r, c.chosen).flatMap((t) => (t.setup.steps?.(c) ?? []).map((step) => ({ tool: t.label, step })));
|
|
67
|
+
}
|
|
68
|
+
/** The secret steps among them. */
|
|
69
|
+
export function secretSteps(r, c) {
|
|
70
|
+
return stepsOf(r, c).filter((s) => s.step.kind === "secret");
|
|
71
|
+
}
|
|
72
|
+
/** The same context for other parts. */
|
|
73
|
+
export const withParts = (c, parts) => ({
|
|
74
|
+
...c,
|
|
75
|
+
parts: new Set(parts),
|
|
76
|
+
});
|