@davidbyoung/software-factory 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -9
- 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 +17 -2
- 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/config.d.mts +26 -7
- package/dist/config.mjs +79 -26
- package/dist/doctor.d.mts +6 -14
- package/dist/doctor.mjs +52 -64
- package/dist/explain.d.mts +2 -0
- package/dist/explain.mjs +127 -0
- package/dist/init.d.mts +8 -12
- package/dist/init.mjs +179 -131
- 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/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/poller.d.mts +20 -3
- package/dist/poller.mjs +62 -15
- 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/setup.d.mts +98 -0
- package/dist/setup.mjs +3 -0
- package/dist/status.d.mts +4 -4
- package/dist/status.mjs +8 -7
- package/dist/sync.d.mts +22 -3
- package/dist/sync.mjs +144 -11
- 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 +103 -51
- package/docs/cli.md +42 -42
- package/docs/configuration.md +38 -32
- package/docs/design.md +1 -1
- package/docs/developing.md +156 -67
- package/docs/existing-repo.md +20 -9
- package/docs/github/by-hand.md +321 -0
- package/docs/github/reference.md +65 -61
- package/docs/github/setup.md +83 -267
- package/docs/glossary.md +5 -4
- package/docs/limitations.md +12 -10
- package/docs/plugins.md +12 -17
- package/docs/quick-start.md +62 -105
- package/docs/removing.md +36 -16
- package/docs/skills.md +47 -37
- package/docs/updating.md +2 -6
- package/docs/workflow.md +13 -12
- package/package.json +5 -3
- package/poller.Dockerfile +10 -18
- package/rules.md +14 -12
- package/settings.schema.json +24 -0
- package/skills/factory-build/SKILL.md +1 -1
- package/skills/factory-trace/SKILL.md +79 -0
- package/workflows/factory-build.yml +5 -4
- package/workflows/factory-deps-auto-merge.yml +3 -2
- package/workflows/factory-poller.yml +46 -0
package/dist/status.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { type Settings, type Target } from "./config.mts";
|
|
3
|
-
import { type Columns, type Board, type Derived, type PullRequest, type Issue, type RepoSnapshot, type ReviewerRun } from "./lib/work-status.mts";
|
|
3
|
+
import { type Columns, type Watch, type Board, type Derived, type PullRequest, type Issue, type RepoSnapshot, type ReviewerRun } from "./lib/work-status.mts";
|
|
4
4
|
import { type Tickets } from "./tickets/types.mts";
|
|
5
5
|
import { type CodeHost } from "./code-host/index.mts";
|
|
6
6
|
import { type Runner } from "./runner/index.mts";
|
|
@@ -27,9 +27,9 @@ export declare function isWatching(body: string, now: Date): boolean;
|
|
|
27
27
|
/** One row per open issue, and one per open pull request that closes no
|
|
28
28
|
* issue and builds no part of the follow-ups, such as Dependabot's. */
|
|
29
29
|
export declare function toRows(snapshot: RepoSnapshot, board: Board, blockers: Map<number, number[]>, now: Date,
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
32
|
-
|
|
30
|
+
/** What starts builds from the board, so that a card left in Ready is
|
|
31
|
+
* worth flagging; null when builds.trigger is manual. */
|
|
32
|
+
watch?: Watch | null, columns?: Columns): {
|
|
33
33
|
rows: Row[];
|
|
34
34
|
closed: Row[];
|
|
35
35
|
};
|
package/dist/status.mjs
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
15
15
|
import { NO_DEPENDENCIES, SettingsError, loadSettings, targetOf, } from "./config.mjs";
|
|
16
16
|
import { appSessionLink } from "./lib/gh.mjs";
|
|
17
|
-
import { DEFAULT_COLUMNS, cardOf, derive, isNotStarted, isStale, isStuck, actionsRunLink, buildsPartOf, markedComments, parseRuns, toSnapshot, } from "./lib/work-status.mjs";
|
|
17
|
+
import { DEFAULT_COLUMNS, cardOf, derive, isNotStarted, watchOf, isStale, isStuck, actionsRunLink, buildsPartOf, markedComments, parseRuns, toSnapshot, } from "./lib/work-status.mjs";
|
|
18
18
|
import { boardOf, readAll } from "./tickets/types.mjs";
|
|
19
19
|
import { openTickets } from "./tickets/index.mjs";
|
|
20
20
|
import { openCodeHost } from "./code-host/index.mjs";
|
|
@@ -66,9 +66,9 @@ export function isWatching(body, now) {
|
|
|
66
66
|
/** One row per open issue, and one per open pull request that closes no
|
|
67
67
|
* issue and builds no part of the follow-ups, such as Dependabot's. */
|
|
68
68
|
export function toRows(snapshot, board, blockers, now,
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
71
|
-
|
|
69
|
+
/** What starts builds from the board, so that a card left in Ready is
|
|
70
|
+
* worth flagging; null when builds.trigger is manual. */
|
|
71
|
+
watch = watchOf("own-server", 5), columns = DEFAULT_COLUMNS) {
|
|
72
72
|
const rows = [];
|
|
73
73
|
const closed = [];
|
|
74
74
|
const claimed = new Set();
|
|
@@ -79,8 +79,9 @@ watched = true, columns = DEFAULT_COLUMNS) {
|
|
|
79
79
|
const flags = [];
|
|
80
80
|
if (isStale(derived, now))
|
|
81
81
|
flags.push("stale");
|
|
82
|
-
if (
|
|
83
|
-
|
|
82
|
+
if (watch &&
|
|
83
|
+
isNotStarted(derived, blockers.get(issue.number) ?? [], now, watch.minutes))
|
|
84
|
+
flags.push(watch.flag);
|
|
84
85
|
const row = {
|
|
85
86
|
number: issue.number,
|
|
86
87
|
kind: "issue",
|
|
@@ -404,7 +405,7 @@ async function snapshotLines(source, target, now, hook, style = PLAIN) {
|
|
|
404
405
|
const list = await source.tickets.blockers.list(issue.number);
|
|
405
406
|
blockers.set(issue.number, list.filter((b) => b.state === "open").map((b) => b.number));
|
|
406
407
|
}
|
|
407
|
-
return formatRows(toRows(snapshot, board, blockers, now, target.
|
|
408
|
+
return formatRows(toRows(snapshot, board, blockers, now, target.watch, target.columns), now, !hook, { ...style, links, columns: target.columns });
|
|
408
409
|
}
|
|
409
410
|
const WATCH_MS = 15_000;
|
|
410
411
|
// The alternate screen with the cursor hidden, and back.
|
package/dist/sync.d.mts
CHANGED
|
@@ -8,15 +8,23 @@ export declare const CLAUDE_MD = "CLAUDE.md";
|
|
|
8
8
|
export declare const IMPORT_LINE = "@.claude/factory/rules.md";
|
|
9
9
|
/** Whether the repository has a file, by its path from the root. */
|
|
10
10
|
type Has = (path: string) => boolean;
|
|
11
|
+
/** The scheduled poller's workflow, its one `cron` line set to run every
|
|
12
|
+
* `minutes`: on the hour for 60, every N minutes past it otherwise. */
|
|
13
|
+
export declare function withSchedule(text: string, minutes: number, file: string): string;
|
|
11
14
|
/** A session workflow with the minutes its session may run, and its job 10
|
|
12
15
|
* more, so the steps after the session still run before the job is
|
|
13
16
|
* stopped. */
|
|
14
17
|
export declare function withMinutes(text: string, minutes: number, file: string): string;
|
|
18
|
+
/** A copy with the rules' numbers the settings give in place of the
|
|
19
|
+
* defaults. A phrase is replaced only when its number is not the default,
|
|
20
|
+
* and must then match exactly once. */
|
|
21
|
+
export declare function withRules(text: string, r: Settings["rules"], file: string): string;
|
|
15
22
|
/** Each copy, as [path in the package, path in the repository]. */
|
|
16
23
|
export declare function copies(pkg: string, s: Settings, has: Has): [string, string][];
|
|
17
|
-
/** The launcher's path from the repository's root: the
|
|
18
|
-
*
|
|
19
|
-
*
|
|
24
|
+
/** The launcher's path from the repository's root: the root's own, where
|
|
25
|
+
* the repository is the package itself; the package's own folder where it
|
|
26
|
+
* is inside the repository, as a workspace or installed; and where it would
|
|
27
|
+
* be installed otherwise. */
|
|
20
28
|
export declare function launcherPath(pkg: string, root: string, name: string): string;
|
|
21
29
|
type HookEntry = {
|
|
22
30
|
type: "command";
|
|
@@ -34,8 +42,19 @@ export declare function factoryHooks(launcher: string): [string, HookGroup][];
|
|
|
34
42
|
* replaced by the five above, and attribution turned off unless the file
|
|
35
43
|
* sets its own. Every other entry stays, in its order. */
|
|
36
44
|
export declare function withHooks(text: string | null, launcher: string): string;
|
|
45
|
+
/** Whether every event of the five has the factory's entry. */
|
|
46
|
+
export declare function hasFactoryHooks(text: string | null): boolean;
|
|
47
|
+
/** Whether any hook entry is the factory's. */
|
|
48
|
+
export declare function hasAnyFactoryHook(text: string | null): boolean;
|
|
49
|
+
/** `.claude/settings.json` with the factory's entries taken out and an
|
|
50
|
+
* emptied `hooks` dropped, or null when nothing is left. */
|
|
51
|
+
export declare function withoutHooks(text: string): string | null;
|
|
52
|
+
export declare const hasImport: (text: string | null) => boolean;
|
|
37
53
|
/** `CLAUDE.md` with the rules' import added when no line is that import. */
|
|
38
54
|
export declare function withImport(text: string | null): string;
|
|
55
|
+
/** `CLAUDE.md` without the rules' import, nor the blank line `withImport`
|
|
56
|
+
* put before it, or null when nothing else is left. */
|
|
57
|
+
export declare function withoutImport(text: string): string | null;
|
|
39
58
|
export declare function lockText(version: string, files: string[]): string;
|
|
40
59
|
export declare function lockedFiles(text: string | null): string[];
|
|
41
60
|
export type Plan = {
|
package/dist/sync.mjs
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync, } from "node:fs";
|
|
14
14
|
import { dirname, join, relative, sep } from "node:path";
|
|
15
15
|
import { fileURLToPath } from "node:url";
|
|
16
|
-
import { defaultDeps, loadSettings, repoRoot, } from "./config.mjs";
|
|
16
|
+
import { defaultDeps, loadSettings, repoRoot, RULE_NUMBERS, } from "./config.mjs";
|
|
17
17
|
/** The package's own folder: the parent of `src/`, or of `dist/` once
|
|
18
18
|
* compiled. */
|
|
19
19
|
export const PACKAGE = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
@@ -36,7 +36,18 @@ const NEEDS = {
|
|
|
36
36
|
"workflows/factory-board-sync.yml": (s) => s.tickets.board !== null,
|
|
37
37
|
"workflows/factory-merge-policy.yml": (s) => s.autoMerge.allow.length > 0,
|
|
38
38
|
"workflows/factory-claude-review.yml": (s) => s.ciReview !== null,
|
|
39
|
+
"workflows/factory-poller.yml": (s) => s.builds.trigger === "github-action",
|
|
39
40
|
};
|
|
41
|
+
const POLLER_WORKFLOW = "workflows/factory-poller.yml";
|
|
42
|
+
/** The scheduled poller's workflow, its one `cron` line set to run every
|
|
43
|
+
* `minutes`: on the hour for 60, every N minutes past it otherwise. */
|
|
44
|
+
export function withSchedule(text, minutes, file) {
|
|
45
|
+
const pattern = /^(\s+- cron: )"[^"]*"$/gm;
|
|
46
|
+
if ((text.match(pattern) ?? []).length !== 1)
|
|
47
|
+
throw new Error(`${file}: expected one cron line, to set the poller's schedule`);
|
|
48
|
+
const cron = minutes === 60 ? "0 * * * *" : `*/${minutes} * * * *`;
|
|
49
|
+
return text.replace(pattern, (_, lead) => `${lead}"${cron}"`);
|
|
50
|
+
}
|
|
40
51
|
/** The workflows that run a Claude session, by the kind of session each
|
|
41
52
|
* runs. */
|
|
42
53
|
const SESSION_WORKFLOWS = {
|
|
@@ -57,6 +68,81 @@ export function withMinutes(text, minutes, file) {
|
|
|
57
68
|
const session = one(/^(\s+minutes: )\d+$/gm, minutes, text);
|
|
58
69
|
return one(/^(\s+timeout-minutes: )\d+$/gm, minutes + 10, session);
|
|
59
70
|
}
|
|
71
|
+
const WORDS = [
|
|
72
|
+
"zero",
|
|
73
|
+
"one",
|
|
74
|
+
"two",
|
|
75
|
+
"three",
|
|
76
|
+
"four",
|
|
77
|
+
"five",
|
|
78
|
+
"six",
|
|
79
|
+
"seven",
|
|
80
|
+
"eight",
|
|
81
|
+
"nine",
|
|
82
|
+
"ten",
|
|
83
|
+
];
|
|
84
|
+
const ORDINALS = [
|
|
85
|
+
"zeroth",
|
|
86
|
+
"first",
|
|
87
|
+
"second",
|
|
88
|
+
"third",
|
|
89
|
+
"fourth",
|
|
90
|
+
"fifth",
|
|
91
|
+
"sixth",
|
|
92
|
+
"seventh",
|
|
93
|
+
"eighth",
|
|
94
|
+
"ninth",
|
|
95
|
+
"tenth",
|
|
96
|
+
"eleventh",
|
|
97
|
+
];
|
|
98
|
+
const count = (n) => WORDS[n] ?? String(n);
|
|
99
|
+
const ordinal = (n) => ORDINALS[n] ??
|
|
100
|
+
`${n}${n % 100 >= 11 && n % 100 <= 13 ? "th" : (["th", "st", "nd", "rd"][n % 10] ?? "th")}`;
|
|
101
|
+
const capital = (s) => s[0].toUpperCase() + s.slice(1);
|
|
102
|
+
const rounds = (n) => `${count(n)} round${n === 1 ? "" : "s"}`;
|
|
103
|
+
/** The phrases in a copied file that state one of the rules' numbers, by
|
|
104
|
+
* the file's path in the package: each the default's words, the setting's
|
|
105
|
+
* words, and whether the setting differs from its default. */
|
|
106
|
+
const RULE_PHRASES = {
|
|
107
|
+
"rules.md": (r) => [
|
|
108
|
+
[
|
|
109
|
+
/under about 30 lines/g,
|
|
110
|
+
`under about ${r.smallChangeLines} lines`,
|
|
111
|
+
r.smallChangeLines !== RULE_NUMBERS["small-change-lines"],
|
|
112
|
+
],
|
|
113
|
+
[
|
|
114
|
+
/After two rounds,/g,
|
|
115
|
+
`After ${rounds(r.reviewRounds)},`,
|
|
116
|
+
r.reviewRounds !== RULE_NUMBERS["review-rounds"],
|
|
117
|
+
],
|
|
118
|
+
],
|
|
119
|
+
"skills/factory-address-review/SKILL.md": (r) => [
|
|
120
|
+
[
|
|
121
|
+
/^## 6\. Two rounds, then escalate$/gm,
|
|
122
|
+
`## 6. ${capital(rounds(r.reviewRounds))}, then escalate`,
|
|
123
|
+
r.reviewRounds !== RULE_NUMBERS["review-rounds"],
|
|
124
|
+
],
|
|
125
|
+
[
|
|
126
|
+
/at most two(\s+)rounds\*\*\. When the third review arrives/g,
|
|
127
|
+
`at most ${count(r.reviewRounds)}$1round${r.reviewRounds === 1 ? "" : "s"}**. When the ${ordinal(r.reviewRounds + 1)} review arrives`,
|
|
128
|
+
r.reviewRounds !== RULE_NUMBERS["review-rounds"],
|
|
129
|
+
],
|
|
130
|
+
],
|
|
131
|
+
};
|
|
132
|
+
/** A copy with the rules' numbers the settings give in place of the
|
|
133
|
+
* defaults. A phrase is replaced only when its number is not the default,
|
|
134
|
+
* and must then match exactly once. */
|
|
135
|
+
export function withRules(text, r, file) {
|
|
136
|
+
let out = text;
|
|
137
|
+
for (const [pattern, words, set] of RULE_PHRASES[file]?.(r) ?? []) {
|
|
138
|
+
if (!set)
|
|
139
|
+
continue;
|
|
140
|
+
if ((out.match(pattern) ?? []).length !== 1)
|
|
141
|
+
throw new Error(`${file}: expected one match for ${pattern.source}, to set a number from rules`);
|
|
142
|
+
out = out.replace(pattern, words);
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
60
146
|
function walk(dir, base = dir) {
|
|
61
147
|
if (!existsSync(dir))
|
|
62
148
|
return [];
|
|
@@ -90,14 +176,17 @@ export function copies(pkg, s, has) {
|
|
|
90
176
|
add("actions", ".github/actions");
|
|
91
177
|
return out;
|
|
92
178
|
}
|
|
93
|
-
/** The launcher's path from the repository's root: the
|
|
94
|
-
*
|
|
95
|
-
*
|
|
179
|
+
/** The launcher's path from the repository's root: the root's own, where
|
|
180
|
+
* the repository is the package itself; the package's own folder where it
|
|
181
|
+
* is inside the repository, as a workspace or installed; and where it would
|
|
182
|
+
* be installed otherwise. */
|
|
96
183
|
export function launcherPath(pkg, root, name) {
|
|
97
184
|
const rel = relative(realpathSync(root), realpathSync(pkg))
|
|
98
185
|
.split(sep)
|
|
99
186
|
.join("/");
|
|
100
|
-
|
|
187
|
+
if (rel === "")
|
|
188
|
+
return LAUNCHER;
|
|
189
|
+
const base = !rel.startsWith("..") && !rel.startsWith("/")
|
|
101
190
|
? rel
|
|
102
191
|
: `node_modules/${name}`;
|
|
103
192
|
return `${base}/${LAUNCHER}`;
|
|
@@ -174,6 +263,14 @@ const isFactory = (h) => typeof h.command === "string" && h.command.includes(`/$
|
|
|
174
263
|
* sets its own. Every other entry stays, in its order. */
|
|
175
264
|
export function withHooks(text, launcher) {
|
|
176
265
|
const settings = text ? JSON.parse(text) : {};
|
|
266
|
+
const hooks = othersHooks(settings);
|
|
267
|
+
for (const [event, group] of factoryHooks(launcher))
|
|
268
|
+
(hooks[event] ??= []).push(group);
|
|
269
|
+
const attribution = settings.attribution ?? NO_ATTRIBUTION;
|
|
270
|
+
return `${JSON.stringify({ ...settings, attribution, hooks }, null, 2)}\n`;
|
|
271
|
+
}
|
|
272
|
+
/** Every hook entry that is not the factory's, by event. */
|
|
273
|
+
function othersHooks(settings) {
|
|
177
274
|
const hooks = {};
|
|
178
275
|
for (const [event, groups] of Object.entries(settings.hooks ?? {})) {
|
|
179
276
|
const kept = groups
|
|
@@ -182,19 +279,53 @@ export function withHooks(text, launcher) {
|
|
|
182
279
|
if (kept.length)
|
|
183
280
|
hooks[event] = kept;
|
|
184
281
|
}
|
|
185
|
-
|
|
186
|
-
(hooks[event] ??= []).push(group);
|
|
187
|
-
const attribution = settings.attribution ?? NO_ATTRIBUTION;
|
|
188
|
-
return `${JSON.stringify({ ...settings, attribution, hooks }, null, 2)}\n`;
|
|
282
|
+
return hooks;
|
|
189
283
|
}
|
|
284
|
+
/** Whether every event of the five has the factory's entry. */
|
|
285
|
+
export function hasFactoryHooks(text) {
|
|
286
|
+
if (!text)
|
|
287
|
+
return false;
|
|
288
|
+
const hooks = JSON.parse(text).hooks ?? {};
|
|
289
|
+
return factoryHooks(LAUNCHER).every(([event]) => (hooks[event] ?? []).some((g) => g.hooks.some(isFactory)));
|
|
290
|
+
}
|
|
291
|
+
/** Whether any hook entry is the factory's. */
|
|
292
|
+
export function hasAnyFactoryHook(text) {
|
|
293
|
+
if (!text)
|
|
294
|
+
return false;
|
|
295
|
+
const hooks = JSON.parse(text).hooks ?? {};
|
|
296
|
+
return Object.values(hooks).some((groups) => groups.some((g) => g.hooks.some(isFactory)));
|
|
297
|
+
}
|
|
298
|
+
/** `.claude/settings.json` with the factory's entries taken out and an
|
|
299
|
+
* emptied `hooks` dropped, or null when nothing is left. */
|
|
300
|
+
export function withoutHooks(text) {
|
|
301
|
+
const { hooks: _, ...rest } = JSON.parse(text);
|
|
302
|
+
const hooks = othersHooks(JSON.parse(text));
|
|
303
|
+
const after = Object.keys(hooks).length ? { ...rest, hooks } : rest;
|
|
304
|
+
return Object.keys(after).length
|
|
305
|
+
? `${JSON.stringify(after, null, 2)}\n`
|
|
306
|
+
: null;
|
|
307
|
+
}
|
|
308
|
+
export const hasImport = (text) => text !== null && text.split("\n").some((line) => line.trim() === IMPORT_LINE);
|
|
190
309
|
/** `CLAUDE.md` with the rules' import added when no line is that import. */
|
|
191
310
|
export function withImport(text) {
|
|
192
311
|
if (text === null)
|
|
193
312
|
return `${IMPORT_LINE}\n`;
|
|
194
|
-
if (text
|
|
313
|
+
if (hasImport(text))
|
|
195
314
|
return text;
|
|
196
315
|
return `${text}${text.endsWith("\n") || !text ? "" : "\n"}\n${IMPORT_LINE}\n`;
|
|
197
316
|
}
|
|
317
|
+
/** `CLAUDE.md` without the rules' import, nor the blank line `withImport`
|
|
318
|
+
* put before it, or null when nothing else is left. */
|
|
319
|
+
export function withoutImport(text) {
|
|
320
|
+
const lines = text.split("\n");
|
|
321
|
+
const at = lines.findIndex((line) => line.trim() === IMPORT_LINE);
|
|
322
|
+
if (at < 0)
|
|
323
|
+
return text;
|
|
324
|
+
const from = at > 0 && lines[at - 1] === "" ? at - 1 : at;
|
|
325
|
+
lines.splice(from, at - from + 1);
|
|
326
|
+
const after = lines.join("\n");
|
|
327
|
+
return after.trim() ? after : null;
|
|
328
|
+
}
|
|
198
329
|
export function lockText(version, files) {
|
|
199
330
|
return [
|
|
200
331
|
"# Written by `factory sync`: the factory's version and the files it",
|
|
@@ -224,7 +355,9 @@ export function plan(pkg, root, s) {
|
|
|
224
355
|
const kind = SESSION_WORKFLOWS[from.replace(/^workflows\//, "")];
|
|
225
356
|
write.set(to, kind && from.startsWith("workflows/")
|
|
226
357
|
? withMinutes(text, s.sessionMinutes[kind], from)
|
|
227
|
-
:
|
|
358
|
+
: from === POLLER_WORKFLOW
|
|
359
|
+
? withSchedule(text, s.builds.pollMinutes, from)
|
|
360
|
+
: withRules(text, s.rules, from));
|
|
228
361
|
}
|
|
229
362
|
const launcher = launcherPath(pkg, root, manifest.name);
|
|
230
363
|
write.set(SETTINGS_JSON, withHooks(read(SETTINGS_JSON), launcher));
|
|
@@ -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
|
+
});
|