@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/parts.mjs
CHANGED
|
@@ -22,7 +22,7 @@ export const PART_TEXT = {
|
|
|
22
22
|
},
|
|
23
23
|
"from-board": {
|
|
24
24
|
name: "Builds that start when you move a card to Ready",
|
|
25
|
-
gives: "
|
|
25
|
+
gives: "a schedule on GitHub Actions, or a small server you host",
|
|
26
26
|
},
|
|
27
27
|
"auto-merge": {
|
|
28
28
|
name: "Pull requests that merge themselves",
|
|
@@ -42,18 +42,17 @@ export const BOARD_TOKEN = "FACTORY_BOARD_TOKEN";
|
|
|
42
42
|
export const BUILD_TOKEN = "FACTORY_BUILD_TOKEN";
|
|
43
43
|
export const AUTOMERGE_TOKEN = "FACTORY_AUTOMERGE_TOKEN";
|
|
44
44
|
export const SIGNING_KEY = "FACTORY_SIGNING_KEY";
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
export function partsOn(s, secrets) {
|
|
45
|
+
/** The parts on: those with a setting, from the settings; cloud builds,
|
|
46
|
+
* when every secret the tools read for them is set; and signing, from its
|
|
47
|
+
* key. */
|
|
48
|
+
export function partsOn(s, secrets, cloudNeeds) {
|
|
50
49
|
const has = (names) => names.some((n) => secrets.includes(n));
|
|
51
50
|
const on = new Set();
|
|
52
51
|
if (s?.ciReview)
|
|
53
52
|
on.add("review");
|
|
54
53
|
if (s?.tickets.board != null)
|
|
55
54
|
on.add("board");
|
|
56
|
-
if (
|
|
55
|
+
if (cloudNeeds.length && cloudNeeds.every((n) => has(n.anyOf)))
|
|
57
56
|
on.add("cloud");
|
|
58
57
|
if (s && s.builds.trigger !== "manual")
|
|
59
58
|
on.add("from-board");
|
|
@@ -98,41 +97,14 @@ export function resolveParts(before, chosen) {
|
|
|
98
97
|
}
|
|
99
98
|
return { parts, notes };
|
|
100
99
|
}
|
|
101
|
-
/** The secrets
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
out.push({ part, anyOf: AGENT }, { part, anyOf: ACCESS });
|
|
111
|
-
if (part === "board" || part === "from-board")
|
|
112
|
-
out.push({ part, anyOf: [BOARD_TOKEN] });
|
|
113
|
-
if (part === "auto-merge")
|
|
114
|
-
out.push({ part, anyOf: [AUTOMERGE_TOKEN] });
|
|
115
|
-
if (part === "signing")
|
|
116
|
-
out.push({ part, anyOf: [SIGNING_KEY] });
|
|
117
|
-
}
|
|
100
|
+
/** The secrets read for the parts on, from the tools' secret steps, with
|
|
101
|
+
* the signing key, which is the factory's own. Each is met by any one of
|
|
102
|
+
* its names. */
|
|
103
|
+
export function neededSecrets(parts, steps) {
|
|
104
|
+
const out = steps.flatMap(({ tool, step }) => step.needs
|
|
105
|
+
.filter((n) => n.part === null || parts.has(n.part))
|
|
106
|
+
.map((n) => ({ ...n, tool })));
|
|
107
|
+
if (parts.has("signing"))
|
|
108
|
+
out.push({ part: "signing", anyOf: [SIGNING_KEY], tool: "factory" });
|
|
118
109
|
return out;
|
|
119
110
|
}
|
|
120
|
-
/** The names the one access token is stored under: the board's with a
|
|
121
|
-
* board, which builds also read, the build token's without one, and the
|
|
122
|
-
* auto-merge token's. */
|
|
123
|
-
export function tokenNames(parts) {
|
|
124
|
-
const names = [];
|
|
125
|
-
if (parts.has("board"))
|
|
126
|
-
names.push(BOARD_TOKEN);
|
|
127
|
-
else if (parts.has("cloud"))
|
|
128
|
-
names.push(BUILD_TOKEN);
|
|
129
|
-
if (parts.has("auto-merge"))
|
|
130
|
-
names.push(AUTOMERGE_TOKEN);
|
|
131
|
-
return names;
|
|
132
|
-
}
|
|
133
|
-
/** What the access token must be able to do for the parts. */
|
|
134
|
-
export function tokenNeeds(parts) {
|
|
135
|
-
return parts.has("board")
|
|
136
|
-
? ["push", "workflows", "board"]
|
|
137
|
-
: ["push", "workflows"];
|
|
138
|
-
}
|
package/dist/poller.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { type Settings } from "./config.mts";
|
|
2
3
|
import { type Columns, type Board, type RepoSnapshot } from "./lib/work-status.mts";
|
|
3
4
|
import type { CodeHost } from "./code-host/types.mts";
|
|
4
5
|
import type { Runner } from "./runner/types.mts";
|
|
@@ -17,6 +18,10 @@ export declare function dispatchFailure(error: unknown): {
|
|
|
17
18
|
status: string;
|
|
18
19
|
reason: string;
|
|
19
20
|
};
|
|
21
|
+
/** When each build started in the past hour went out, read from the start
|
|
22
|
+
* comments on the tickets, so the count holds across a scheduled run and a
|
|
23
|
+
* restart, neither of which keeps it in memory. */
|
|
24
|
+
export declare function recentStarts(issues: RepoSnapshot["issues"], now: number): number[];
|
|
20
25
|
/** Whether another fire fits in the rolling hour, given when the recent ones
|
|
21
26
|
* went out. */
|
|
22
27
|
export declare function capAllows(fired: number[], now: number): boolean;
|
|
@@ -31,7 +36,6 @@ export declare function readConfig(env: Record<string, string | undefined>): Con
|
|
|
31
36
|
missing: string[];
|
|
32
37
|
};
|
|
33
38
|
export type State = {
|
|
34
|
-
fired: number[];
|
|
35
39
|
failuresInARow: number;
|
|
36
40
|
lastHeartbeat: number;
|
|
37
41
|
};
|
|
@@ -57,5 +61,18 @@ export declare function sources(d: Deps, c: Config): {
|
|
|
57
61
|
/** One minute's work. It never throws: every failure is logged, and a failed
|
|
58
62
|
* read counts toward the slower retry. */
|
|
59
63
|
export declare function tick(d: Deps, state: State): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
|
|
64
|
+
/** What one scheduled pass reads from the settings: the board's number,
|
|
65
|
+
* and the column that approves a build, each null when the settings have
|
|
66
|
+
* none. */
|
|
67
|
+
export type OnceSettings = {
|
|
68
|
+
board: number | null;
|
|
69
|
+
ready: string | null;
|
|
70
|
+
};
|
|
71
|
+
export declare function onceSettings(s: Settings): OnceSettings;
|
|
72
|
+
/** One pass, for a scheduled run: the board and the Ready column come from
|
|
73
|
+
* the settings, the board's owner is the repository's, and only the token
|
|
74
|
+
* comes from the environment. 1 when it read nothing or could not read. */
|
|
75
|
+
export declare function once(s: OnceSettings, d: Deps): Promise<number>;
|
|
76
|
+
/** `factory poller`, and `factory poller --once`. The settings are loaded
|
|
77
|
+
* only for `--once`, since the hosted poller has no checkout. */
|
|
78
|
+
export declare function run(argv?: string[]): Promise<number>;
|
package/dist/poller.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Start a build in GitHub Actions for each card the owner moves to Ready. A board owned
|
|
3
3
|
// by a user account sends no event, so this reads it once a minute. It runs
|
|
4
|
-
// as a worker on a server the repository's owner hosts
|
|
4
|
+
// as a worker on a server the repository's owner hosts, or, with `--once`,
|
|
5
|
+
// as one pass of a scheduled workflow, which reads the board and the Ready
|
|
6
|
+
// column from the settings in its checkout and needs only the token.
|
|
5
7
|
//
|
|
6
|
-
//
|
|
8
|
+
// Hosted, its environment: FACTORY_REPOSITORY (owner/name), FACTORY_BOARD_OWNER,
|
|
7
9
|
// FACTORY_BOARD_NUMBER, and FACTORY_BOARD_TOKEN (a classic token with the
|
|
8
10
|
// repo and project scopes, or a fine-grained one that can also write
|
|
9
11
|
// Actions: it starts the workflow). It has no checkout, so it reads
|
|
@@ -16,11 +18,11 @@
|
|
|
16
18
|
// It names its implementations itself, having no settings to name them:
|
|
17
19
|
// the GitHub ticket adapter, GitHub as the code host, and GitHub Actions as
|
|
18
20
|
// the runner, each over the `fetch` transport, since it runs with no `gh`.
|
|
19
|
-
// Node built-ins and the modules below only; its image copies nothing else.
|
|
20
21
|
import { randomBytes } from "node:crypto";
|
|
22
|
+
import { columnsOf, loadSettings } from "./config.mjs";
|
|
21
23
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
22
24
|
import { pathToFileURL } from "node:url";
|
|
23
|
-
import { DEFAULT_COLUMNS, cardOf, commentBody, derive, toSnapshot, } from "./lib/work-status.mjs";
|
|
25
|
+
import { DEFAULT_COLUMNS, cardOf, commentBody, derive, markedComments, toSnapshot, } from "./lib/work-status.mjs";
|
|
24
26
|
import { githubCodeHost } from "./code-host/github.mjs";
|
|
25
27
|
import { BUILD_WORKFLOW, githubActionsRunner, } from "./runner/github-actions.mjs";
|
|
26
28
|
import { githubTickets } from "./tickets/github.mjs";
|
|
@@ -64,6 +66,16 @@ export function dispatchFailure(error) {
|
|
|
64
66
|
reason: error instanceof Error ? error.message : String(error),
|
|
65
67
|
};
|
|
66
68
|
}
|
|
69
|
+
/** When each build started in the past hour went out, read from the start
|
|
70
|
+
* comments on the tickets, so the count holds across a scheduled run and a
|
|
71
|
+
* restart, neither of which keeps it in memory. */
|
|
72
|
+
export function recentStarts(issues, now) {
|
|
73
|
+
return issues
|
|
74
|
+
.flatMap((issue) => markedComments(issue.comments))
|
|
75
|
+
.filter((m) => m.marker.kind === "started")
|
|
76
|
+
.map((m) => Date.parse(m.createdAt))
|
|
77
|
+
.filter((at) => now - at < HOUR);
|
|
78
|
+
}
|
|
67
79
|
/** Whether another fire fits in the rolling hour, given when the recent ones
|
|
68
80
|
* went out. */
|
|
69
81
|
export function capAllows(fired, now) {
|
|
@@ -160,6 +172,8 @@ export async function tick(d, state) {
|
|
|
160
172
|
}
|
|
161
173
|
const columns = columnsFrom(d.env);
|
|
162
174
|
const ready = selectToStart(read.snapshot, read.board, columns);
|
|
175
|
+
// This pass's own start comments are not in what it read, so it adds them.
|
|
176
|
+
const fired = recentStarts(read.snapshot.issues, d.now());
|
|
163
177
|
if (d.now() - state.lastHeartbeat >= HOUR) {
|
|
164
178
|
d.log(`heartbeat: ${ready.length} Ready card${ready.length === 1 ? "" : "s"}`);
|
|
165
179
|
state.lastHeartbeat = d.now();
|
|
@@ -177,7 +191,7 @@ export async function tick(d, state) {
|
|
|
177
191
|
d.log(`#${issue} skipped: its blockers could not be read (${String(error)})`);
|
|
178
192
|
continue;
|
|
179
193
|
}
|
|
180
|
-
if (!capAllows(
|
|
194
|
+
if (!capAllows(fired, d.now())) {
|
|
181
195
|
d.log(`#${issue} waits: ${FIRE_LIMIT} builds started in the last hour`);
|
|
182
196
|
continue;
|
|
183
197
|
}
|
|
@@ -189,8 +203,7 @@ export async function tick(d, state) {
|
|
|
189
203
|
d.log(`#${issue} not started: the start comment failed (${String(error)})`);
|
|
190
204
|
continue;
|
|
191
205
|
}
|
|
192
|
-
|
|
193
|
-
state.fired = state.fired.filter((at) => d.now() - at < HOUR);
|
|
206
|
+
fired.push(d.now());
|
|
194
207
|
const outcome = await dispatch(runner, d.defaultBranch, issue);
|
|
195
208
|
if (outcome.ok) {
|
|
196
209
|
d.log(`#${issue} started ${marker}: dispatched ${BUILD_WORKFLOW}`);
|
|
@@ -210,14 +223,34 @@ export async function tick(d, state) {
|
|
|
210
223
|
}
|
|
211
224
|
}
|
|
212
225
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
226
|
+
export function onceSettings(s) {
|
|
227
|
+
return { board: s.tickets.board, ready: columnsOf(s).Ready };
|
|
228
|
+
}
|
|
229
|
+
/** One pass, for a scheduled run: the board and the Ready column come from
|
|
230
|
+
* the settings, the board's owner is the repository's, and only the token
|
|
231
|
+
* comes from the environment. 1 when it read nothing or could not read. */
|
|
232
|
+
export async function once(s, d) {
|
|
233
|
+
if (s.board === null) {
|
|
234
|
+
d.log("No board to read: tickets.board is not set in .claude/factory.yaml.");
|
|
235
|
+
return 1;
|
|
236
|
+
}
|
|
237
|
+
if (s.ready === null) {
|
|
238
|
+
d.log("No card can start a build: the Ready column is none in .claude/factory.yaml.");
|
|
217
239
|
return 1;
|
|
218
240
|
}
|
|
219
|
-
const
|
|
220
|
-
|
|
241
|
+
const env = {
|
|
242
|
+
...d.env,
|
|
243
|
+
FACTORY_BOARD_OWNER: d.repository.split("/")[0],
|
|
244
|
+
FACTORY_BOARD_NUMBER: String(s.board),
|
|
245
|
+
FACTORY_READY_COLUMN: s.ready,
|
|
246
|
+
};
|
|
247
|
+
const state = { failuresInARow: 0, lastHeartbeat: d.now() };
|
|
248
|
+
await tick({ ...d, env }, state);
|
|
249
|
+
return state.failuresInARow > 0 ? 1 : 0;
|
|
250
|
+
}
|
|
251
|
+
/** The parts of the dependencies that are the same however it runs. */
|
|
252
|
+
function liveDeps(repository) {
|
|
253
|
+
return {
|
|
221
254
|
repository,
|
|
222
255
|
fetch,
|
|
223
256
|
env: process.env,
|
|
@@ -225,6 +258,15 @@ async function main() {
|
|
|
225
258
|
log: (line) => console.log(`${new Date().toISOString()} ${line}`),
|
|
226
259
|
marker: startMarker,
|
|
227
260
|
};
|
|
261
|
+
}
|
|
262
|
+
async function main() {
|
|
263
|
+
const repository = process.env.FACTORY_REPOSITORY;
|
|
264
|
+
if (!repository) {
|
|
265
|
+
console.error("ready-poller not started: FACTORY_REPOSITORY is not set. Set it to the repository, as owner/name.");
|
|
266
|
+
return 1;
|
|
267
|
+
}
|
|
268
|
+
const state = { failuresInARow: 0, lastHeartbeat: 0 };
|
|
269
|
+
const d = liveDeps(repository);
|
|
228
270
|
process.on("unhandledRejection", (error) => d.log(`unhandled: ${String(error)}`));
|
|
229
271
|
d.log("ready-poller started");
|
|
230
272
|
for (;;) {
|
|
@@ -237,8 +279,13 @@ async function main() {
|
|
|
237
279
|
await sleep(nextDelay(state.failuresInARow));
|
|
238
280
|
}
|
|
239
281
|
}
|
|
240
|
-
/** `factory poller`.
|
|
241
|
-
|
|
282
|
+
/** `factory poller`, and `factory poller --once`. The settings are loaded
|
|
283
|
+
* only for `--once`, since the hosted poller has no checkout. */
|
|
284
|
+
export async function run(argv = []) {
|
|
285
|
+
if (argv.includes("--once")) {
|
|
286
|
+
const s = await loadSettings();
|
|
287
|
+
process.exit(await once(onceSettings(s), liveDeps(s.repository)));
|
|
288
|
+
}
|
|
242
289
|
process.exit(await main());
|
|
243
290
|
}
|
|
244
291
|
if (process.argv[1] &&
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Registry } from "./tools.mts";
|
|
2
|
+
export type RemoveDeps = {
|
|
3
|
+
root: string;
|
|
4
|
+
confirm: (message: string, fallback: boolean) => Promise<boolean>;
|
|
5
|
+
out: (line: string) => void;
|
|
6
|
+
tools: Registry;
|
|
7
|
+
hasCommand: (name: string) => boolean;
|
|
8
|
+
packageName: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function main(_argv: string[], d: RemoveDeps): Promise<number>;
|
|
11
|
+
export declare function run(argv: string[]): Promise<number>;
|
package/dist/remove.mjs
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// `factory remove`: takes the factory out of a repository. It shows every
|
|
2
|
+
// file it will delete or change, and once told to go ahead deletes the
|
|
3
|
+
// factory's files, takes its part out of the files it shares with the
|
|
4
|
+
// coding agent, and prints what is left outside the repository for you to
|
|
5
|
+
// remove by hand. It commits nothing.
|
|
6
|
+
import { existsSync, readdirSync, readFileSync, rmdirSync, rmSync, writeFileSync, } from "node:fs";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { parseSettings, repoRoot, SETTINGS_FILE, } from "./config.mjs";
|
|
9
|
+
import { hasCommand, noTerminal } from "./lib/has-command.mjs";
|
|
10
|
+
import { listed } from "./lib/listed.mjs";
|
|
11
|
+
import { SIGNING_KEY } from "./parts.mjs";
|
|
12
|
+
import { OVERRIDE } from "./review-verdict.mjs";
|
|
13
|
+
import { LOCK, PACKAGE } from "./sync.mjs";
|
|
14
|
+
import { builtOf, inUse, TOOLS } from "./tools.mjs";
|
|
15
|
+
const LABELS = [
|
|
16
|
+
"merge: automatic",
|
|
17
|
+
"merge: manual",
|
|
18
|
+
OVERRIDE,
|
|
19
|
+
"follow-up",
|
|
20
|
+
"spec",
|
|
21
|
+
];
|
|
22
|
+
/** The factory's own files and folders, each a path from the root. */
|
|
23
|
+
function factoryFiles(root) {
|
|
24
|
+
const named = (dir, match) => existsSync(join(root, dir))
|
|
25
|
+
? readdirSync(join(root, dir))
|
|
26
|
+
.filter((f) => match.test(f))
|
|
27
|
+
.sort()
|
|
28
|
+
.map((f) => `${dir}/${f}`)
|
|
29
|
+
: [];
|
|
30
|
+
return [
|
|
31
|
+
SETTINGS_FILE,
|
|
32
|
+
LOCK,
|
|
33
|
+
".claude/factory",
|
|
34
|
+
...named(".claude/skills", /^factory-/),
|
|
35
|
+
...named(".claude/agents", /^factory-.*\.md$/),
|
|
36
|
+
...named(".github/workflows", /^factory-.*\.yml$/),
|
|
37
|
+
".github/factory-review.md",
|
|
38
|
+
...named(".github/actions", /^factory-/),
|
|
39
|
+
].filter((p) => existsSync(join(root, p)));
|
|
40
|
+
}
|
|
41
|
+
const message = (e) => (e instanceof Error ? e.message : String(e));
|
|
42
|
+
export async function main(_argv, d) {
|
|
43
|
+
const first = (r) => Object.keys(r)[0];
|
|
44
|
+
let settings = null;
|
|
45
|
+
let unread = null;
|
|
46
|
+
const path = join(d.root, SETTINGS_FILE);
|
|
47
|
+
if (!existsSync(path))
|
|
48
|
+
unread = "there is none";
|
|
49
|
+
else
|
|
50
|
+
try {
|
|
51
|
+
const { parse } = await import("yaml");
|
|
52
|
+
settings = parseSettings(parse(readFileSync(path, "utf8")), (p) => existsSync(join(d.root, p)), builtOf(d.tools));
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
unread = message(e);
|
|
56
|
+
}
|
|
57
|
+
const chosen = {
|
|
58
|
+
codeHost: settings?.codeHost.type ?? first(d.tools.codeHost),
|
|
59
|
+
tickets: settings?.tickets.type ?? first(d.tools.tickets),
|
|
60
|
+
runner: settings?.builds.runner ?? first(d.tools.runner),
|
|
61
|
+
agent: first(d.tools.agent),
|
|
62
|
+
};
|
|
63
|
+
const repository = settings?.repository ?? "";
|
|
64
|
+
const context = {
|
|
65
|
+
repository,
|
|
66
|
+
root: d.root,
|
|
67
|
+
parts: new Set(),
|
|
68
|
+
chosen,
|
|
69
|
+
settings,
|
|
70
|
+
hasCommand: d.hasCommand,
|
|
71
|
+
opened: {
|
|
72
|
+
codeHost: d.tools.codeHost[chosen.codeHost].open(repository),
|
|
73
|
+
runner: d.tools.runner[chosen.runner].open(repository),
|
|
74
|
+
tickets: await d.tools.tickets[chosen.tickets].open({ repository, board: settings?.tickets.board ?? null }, settings),
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
const tools = inUse(d.tools, chosen);
|
|
78
|
+
const deletes = factoryFiles(d.root);
|
|
79
|
+
const changes = tools.flatMap((t) => t.setup.unconfigure?.(context) ?? []);
|
|
80
|
+
if (deletes.length === 0 && changes.length === 0) {
|
|
81
|
+
d.out("Nothing of the factory's is here.");
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
if (unread !== null)
|
|
85
|
+
d.out(`Could not read ${SETTINGS_FILE}: ${unread}. Naming what ${listed(tools.map((t) => t.label))} leave behind.`);
|
|
86
|
+
d.out("This is everything remove will do:");
|
|
87
|
+
for (const p of deletes)
|
|
88
|
+
d.out(` Delete ${p}`);
|
|
89
|
+
for (const c of changes)
|
|
90
|
+
d.out(` ${c.text === null ? "Delete " : "Change "} ${c.path}`);
|
|
91
|
+
if (!(await d.confirm("Go ahead?", true))) {
|
|
92
|
+
d.out("Nothing changed.");
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
for (const p of deletes)
|
|
96
|
+
rmSync(join(d.root, p), { recursive: true, force: true });
|
|
97
|
+
for (const c of changes)
|
|
98
|
+
if (c.text === null)
|
|
99
|
+
rmSync(join(d.root, c.path), { force: true });
|
|
100
|
+
else
|
|
101
|
+
writeFileSync(join(d.root, c.path), c.text);
|
|
102
|
+
// A folder the deletions emptied goes too, up to the root.
|
|
103
|
+
for (const p of [
|
|
104
|
+
...deletes,
|
|
105
|
+
...changes.filter((c) => c.text === null).map((c) => c.path),
|
|
106
|
+
])
|
|
107
|
+
for (let dir = dirname(p); dir !== "."; dir = dirname(dir)) {
|
|
108
|
+
const at = join(d.root, dir);
|
|
109
|
+
if (!existsSync(at) || readdirSync(at).length)
|
|
110
|
+
break;
|
|
111
|
+
rmdirSync(at);
|
|
112
|
+
}
|
|
113
|
+
let secrets = null;
|
|
114
|
+
if (settings)
|
|
115
|
+
secrets = await context.opened.runner.secretNames().catch(() => null);
|
|
116
|
+
const withSecrets = { ...context, secrets };
|
|
117
|
+
const byHand = [
|
|
118
|
+
...[tools[1], tools[2], tools[3], tools[0]].flatMap((t) => t.setup.leftovers?.(withSecrets) ?? []),
|
|
119
|
+
...(secrets === null || secrets.includes(SIGNING_KEY)
|
|
120
|
+
? [`Delete the secret ${SIGNING_KEY}${secrets === null ? " if set" : ""}`]
|
|
121
|
+
: []),
|
|
122
|
+
`Delete whichever of the labels ${listed(LABELS)} exist, if you do not want their history: deleting one takes it off every ticket`,
|
|
123
|
+
`Run npm uninstall ${d.packageName}`,
|
|
124
|
+
"Commit this on a branch, open a pull request, and merge it",
|
|
125
|
+
];
|
|
126
|
+
d.out("");
|
|
127
|
+
d.out("Nothing is committed. Left for you to do by hand:");
|
|
128
|
+
byHand.forEach((step, i) => d.out(` ${i + 1}. ${step}.`));
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
export async function run(argv) {
|
|
132
|
+
const terminal = noTerminal("remove");
|
|
133
|
+
if (terminal) {
|
|
134
|
+
console.log(terminal);
|
|
135
|
+
return 1;
|
|
136
|
+
}
|
|
137
|
+
const manifest = JSON.parse(readFileSync(join(PACKAGE, "package.json"), "utf8"));
|
|
138
|
+
const { confirm } = await import("@inquirer/prompts");
|
|
139
|
+
try {
|
|
140
|
+
return await main(argv, {
|
|
141
|
+
root: repoRoot(),
|
|
142
|
+
confirm: (message, fallback) => confirm({ message, default: fallback }),
|
|
143
|
+
out: (l) => console.log(l),
|
|
144
|
+
tools: TOOLS,
|
|
145
|
+
hasCommand,
|
|
146
|
+
packageName: manifest.name,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
if (e instanceof Error && e.name === "ExitPromptError") {
|
|
151
|
+
console.log("Stopped. Nothing changed.");
|
|
152
|
+
return 130;
|
|
153
|
+
}
|
|
154
|
+
throw e;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GhIn } from "../lib/gh.mts";
|
|
2
|
-
import type
|
|
2
|
+
import { type Transport } from "../tickets/transport.mts";
|
|
3
3
|
import type { Runner } from "./types.mts";
|
|
4
4
|
/** The workflow a build is a run of. */
|
|
5
5
|
export declare const BUILD_WORKFLOW = "factory-build.yml";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { statusOf } from "../tickets/transport.mjs";
|
|
1
2
|
/** The workflow a build is a run of. */
|
|
2
3
|
export const BUILD_WORKFLOW = "factory-build.yml";
|
|
3
4
|
const REVIEW_WORKFLOW = "factory-claude-review.yml";
|
|
@@ -78,6 +79,17 @@ export function githubActionsRunner(o) {
|
|
|
78
79
|
}
|
|
79
80
|
return failed;
|
|
80
81
|
},
|
|
82
|
+
async workflowState(file) {
|
|
83
|
+
try {
|
|
84
|
+
const workflow = await t.rest("GET", `${API}/actions/workflows/${file}`);
|
|
85
|
+
return workflow.state === "active" ? "active" : "disabled";
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (statusOf(error) === 404)
|
|
89
|
+
return "missing";
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
},
|
|
81
93
|
async secretNames() {
|
|
82
94
|
// The list is an object, not an array, so it is paged by hand.
|
|
83
95
|
const names = [];
|
package/dist/runner/index.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Runner } from "./types.mts";
|
|
|
3
3
|
export * from "./types.mts";
|
|
4
4
|
export declare const DEFAULT_RUNNER: "github-actions";
|
|
5
5
|
/** The message for a runner that is not built. */
|
|
6
|
-
export declare const unsupportedRunner: (name: string) => string;
|
|
6
|
+
export declare const unsupportedRunner: (name: string, built?: readonly string[]) => string;
|
|
7
7
|
/** The runner of that name for the repository, reached through the GitHub
|
|
8
8
|
* CLI. */
|
|
9
9
|
export declare function openRunner(repository: string, name?: string, run?: Gh, runIn?: GhIn): Runner;
|
package/dist/runner/index.mjs
CHANGED
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
import { gh, ghIn } from "../lib/gh.mjs";
|
|
6
6
|
import { ghTransport } from "../tickets/transport.mjs";
|
|
7
7
|
import { githubActionsRunner } from "./github-actions.mjs";
|
|
8
|
+
import { BUILT, unsupported } from "../tool-names.mjs";
|
|
8
9
|
export * from "./types.mjs";
|
|
9
10
|
export const DEFAULT_RUNNER = "github-actions";
|
|
10
11
|
/** The message for a runner that is not built. */
|
|
11
|
-
export const unsupportedRunner = (name) =>
|
|
12
|
+
export const unsupportedRunner = (name, built = BUILT.runner) => unsupported("builds.runner", name, "runner", built);
|
|
12
13
|
/** The runner of that name for the repository, reached through the GitHub
|
|
13
14
|
* CLI. */
|
|
14
15
|
export function openRunner(repository, name = DEFAULT_RUNNER, run = gh, runIn = ghIn) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const POLLER = "factory-poller.yml";
|
|
2
|
+
export const githubActionsSetup = {
|
|
3
|
+
checks: async (c) => {
|
|
4
|
+
if (c.settings?.builds.trigger !== "github-action")
|
|
5
|
+
return [];
|
|
6
|
+
const state = await c.opened.runner.workflowState(POLLER);
|
|
7
|
+
if (state === "active")
|
|
8
|
+
return [{ state: "pass", text: `${POLLER} is enabled` }];
|
|
9
|
+
if (state === "missing")
|
|
10
|
+
return [
|
|
11
|
+
{ state: "off", text: `${POLLER} is not on the default branch yet` },
|
|
12
|
+
];
|
|
13
|
+
return [
|
|
14
|
+
{
|
|
15
|
+
state: "fail",
|
|
16
|
+
text: `${POLLER} is disabled`,
|
|
17
|
+
fix: `Enable it on the Actions tab, or run: gh workflow enable ${POLLER}`,
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
},
|
|
21
|
+
leftovers: (c) => c.settings?.builds.trigger === "own-server" ? ["The poller you host"] : [],
|
|
22
|
+
};
|
package/dist/runner/types.d.mts
CHANGED
|
@@ -52,6 +52,9 @@ export type Runner = {
|
|
|
52
52
|
/** The jobs that failed in one run, each with its log. Which runs count
|
|
53
53
|
* is the caller's: `factory pr failed` takes those `wait-checks` waits on. */
|
|
54
54
|
failedJobs(run: number): Promise<FailedJob[]>;
|
|
55
|
+
/** Whether a workflow of the factory's, by its file name, runs: missing
|
|
56
|
+
* when the default branch does not have it. */
|
|
57
|
+
workflowState(file: string): Promise<"active" | "disabled" | "missing">;
|
|
55
58
|
/** The names of the secrets the runner's jobs can read. */
|
|
56
59
|
secretNames(): Promise<string[]>;
|
|
57
60
|
/** Stores a secret the runner's jobs can read. The value never appears
|
package/dist/runner/types.mjs
CHANGED
|
@@ -2,6 +2,4 @@
|
|
|
2
2
|
// unattended build runs. The factory's commands start a build and read its
|
|
3
3
|
// runs only through it. The job files a runner needs, such as GitHub
|
|
4
4
|
// Actions' workflows, are its own and no part of this.
|
|
5
|
-
//
|
|
6
|
-
// Node built-ins only: the poller's image copies this file.
|
|
7
5
|
export {};
|
package/dist/setup.d.mts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { CodeHost } from "./code-host/types.mts";
|
|
2
|
+
import type { Settings } from "./config.mts";
|
|
3
|
+
import type { Part } from "./parts.mts";
|
|
4
|
+
import type { Runner } from "./runner/types.mts";
|
|
5
|
+
import type { Tickets } from "./tickets/types.mts";
|
|
6
|
+
/** The repository rule that requires the review's verdict, by name, so
|
|
7
|
+
* removing it is deleting that one rule. */
|
|
8
|
+
export declare const RULE = "Software factory";
|
|
9
|
+
export type Check = {
|
|
10
|
+
state: "pass" | "fail" | "off";
|
|
11
|
+
text: string;
|
|
12
|
+
/** What to do about a failure. */
|
|
13
|
+
fix?: string;
|
|
14
|
+
};
|
|
15
|
+
/** A secret is needed for a part that is on, or always when `part` is
|
|
16
|
+
* null, and any one of `anyOf` being set meets it. */
|
|
17
|
+
export type Need = {
|
|
18
|
+
part: Part | null;
|
|
19
|
+
anyOf: string[];
|
|
20
|
+
};
|
|
21
|
+
/** A value written under the tool's kind's block of the settings. */
|
|
22
|
+
export type ValueStep = {
|
|
23
|
+
kind: "value";
|
|
24
|
+
/** Its key, such as `site` under `tickets`. */
|
|
25
|
+
key: string;
|
|
26
|
+
part: Part | null;
|
|
27
|
+
ask: string;
|
|
28
|
+
fallback?: string;
|
|
29
|
+
};
|
|
30
|
+
export type SecretStep = {
|
|
31
|
+
kind: "secret";
|
|
32
|
+
needs: Need[];
|
|
33
|
+
/** The names a pasted value is stored under. */
|
|
34
|
+
storeAs: string[];
|
|
35
|
+
/** Printed before the value is read. */
|
|
36
|
+
intro: string[];
|
|
37
|
+
get?: {
|
|
38
|
+
page: string;
|
|
39
|
+
} | {
|
|
40
|
+
command: string[];
|
|
41
|
+
};
|
|
42
|
+
/** The masked prompt. */
|
|
43
|
+
prompt: string;
|
|
44
|
+
/** Printed when nothing is pasted, before "Run ... init again". */
|
|
45
|
+
skipped: string;
|
|
46
|
+
/** Resolves to lines to print, and the account the value belongs to
|
|
47
|
+
* when the tool knows it; rejects with the line to print before asking
|
|
48
|
+
* again. */
|
|
49
|
+
verify?: (value: string) => Promise<{
|
|
50
|
+
lines: string[];
|
|
51
|
+
account?: string;
|
|
52
|
+
}>;
|
|
53
|
+
/** Printed once it is stored. */
|
|
54
|
+
stored: (names: string[], account?: string) => string;
|
|
55
|
+
};
|
|
56
|
+
export type SetupStep = ValueStep | SecretStep;
|
|
57
|
+
/** The name of each kind's tool in use. */
|
|
58
|
+
export type Chosen = {
|
|
59
|
+
codeHost: string;
|
|
60
|
+
tickets: string;
|
|
61
|
+
runner: string;
|
|
62
|
+
agent: string;
|
|
63
|
+
};
|
|
64
|
+
export type Opened = {
|
|
65
|
+
codeHost: CodeHost;
|
|
66
|
+
runner: Runner;
|
|
67
|
+
tickets: Tickets;
|
|
68
|
+
};
|
|
69
|
+
export type SetupContext = {
|
|
70
|
+
repository: string;
|
|
71
|
+
root: string;
|
|
72
|
+
parts: ReadonlySet<Part>;
|
|
73
|
+
chosen: Chosen;
|
|
74
|
+
settings: Settings | null;
|
|
75
|
+
hasCommand: (name: string) => boolean;
|
|
76
|
+
opened: Opened;
|
|
77
|
+
};
|
|
78
|
+
/** The secrets set, or null when the runner could not list them. */
|
|
79
|
+
export type WithSecrets = SetupContext & {
|
|
80
|
+
secrets: string[] | null;
|
|
81
|
+
};
|
|
82
|
+
/** A file of the tool's own, as it reads with the factory's part taken
|
|
83
|
+
* out: null to delete it. */
|
|
84
|
+
export type Unconfigured = {
|
|
85
|
+
path: string;
|
|
86
|
+
text: string | null;
|
|
87
|
+
};
|
|
88
|
+
export type ToolSetup = {
|
|
89
|
+
/** Its row under Found, when it says more than its label. */
|
|
90
|
+
found?(c: Pick<SetupContext, "hasCommand">): string;
|
|
91
|
+
steps?(c: SetupContext): SetupStep[];
|
|
92
|
+
checks?(c: WithSecrets): Promise<Check[]>;
|
|
93
|
+
/** What `remove` prints as left to remove by hand. */
|
|
94
|
+
leftovers?(c: WithSecrets): string[];
|
|
95
|
+
/** Its own files with the factory's part taken out, for `remove`: only
|
|
96
|
+
* those the factory's part is in. */
|
|
97
|
+
unconfigure?(c: SetupContext): Unconfigured[];
|
|
98
|
+
};
|
package/dist/setup.mjs
ADDED