@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/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] &&
|
package/dist/pr-watch.d.mts
CHANGED
|
@@ -30,8 +30,9 @@ export type WatchEvent = {
|
|
|
30
30
|
};
|
|
31
31
|
export declare function toChecks(runs: CheckRun[], statuses: CommitStatus[]): Check[];
|
|
32
32
|
/** What needs the session now and has not been reported. A closed pull
|
|
33
|
-
* request ends the watch, so nothing else about it is news.
|
|
34
|
-
|
|
33
|
+
* request ends the watch, so nothing else about it is news. `branch` is the
|
|
34
|
+
* default branch, which a conflict's line names. */
|
|
35
|
+
export declare function newEvents(snapshot: Snapshot, seen: Set<string>, branch: string): WatchEvent[];
|
|
35
36
|
export declare function withWatchMark(body: string, now: Date): string;
|
|
36
37
|
export declare function withoutWatchMark(body: string): string;
|
|
37
38
|
/** A mark goes stale after an hour, so a session that has gone stops holding
|
package/dist/pr-watch.mjs
CHANGED
|
@@ -13,7 +13,8 @@ import { execFileSync } from "node:child_process";
|
|
|
13
13
|
import { createHash } from "node:crypto";
|
|
14
14
|
import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
15
15
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
16
|
-
import { reachOf } from "./config.mjs";
|
|
16
|
+
import { reachOf, repoRoot } from "./config.mjs";
|
|
17
|
+
import { branchDeps, needDefaultBranch, NoDefaultBranch, } from "./lib/default-branch.mjs";
|
|
17
18
|
import { openCodeHost, } from "./code-host/index.mjs";
|
|
18
19
|
const FAILED_CONCLUSIONS = new Set([
|
|
19
20
|
"failure",
|
|
@@ -63,8 +64,9 @@ function reviewIsOver(snapshot) {
|
|
|
63
64
|
return run?.state === "failed";
|
|
64
65
|
}
|
|
65
66
|
/** What needs the session now and has not been reported. A closed pull
|
|
66
|
-
* request ends the watch, so nothing else about it is news.
|
|
67
|
-
|
|
67
|
+
* request ends the watch, so nothing else about it is news. `branch` is the
|
|
68
|
+
* default branch, which a conflict's line names. */
|
|
69
|
+
export function newEvents(snapshot, seen, branch) {
|
|
68
70
|
if (snapshot.merged)
|
|
69
71
|
return [{ key: "merged", line: "merged" }];
|
|
70
72
|
if (snapshot.state !== "open")
|
|
@@ -74,7 +76,7 @@ export function newEvents(snapshot, seen) {
|
|
|
74
76
|
if (snapshot.mergeableState === "dirty") {
|
|
75
77
|
found.push({
|
|
76
78
|
key: `conflict:${sha}`,
|
|
77
|
-
line: `conflict with
|
|
79
|
+
line: `conflict with ${branch} at ${sha}`,
|
|
78
80
|
});
|
|
79
81
|
}
|
|
80
82
|
for (const check of snapshot.checks) {
|
|
@@ -198,13 +200,28 @@ async function main(argv) {
|
|
|
198
200
|
await p.setBody(n, withoutWatchMark(body));
|
|
199
201
|
return;
|
|
200
202
|
}
|
|
203
|
+
// The code host is already open, so it is the one asked where the
|
|
204
|
+
// checkout does not say.
|
|
205
|
+
let branch;
|
|
206
|
+
try {
|
|
207
|
+
branch = await needDefaultBranch({
|
|
208
|
+
...branchDeps(repoRoot()),
|
|
209
|
+
host: () => p.defaultBranch(),
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
if (!(error instanceof NoDefaultBranch))
|
|
214
|
+
throw error;
|
|
215
|
+
console.error(error.message);
|
|
216
|
+
process.exit(1);
|
|
217
|
+
}
|
|
201
218
|
const seenFile = execFileSync("git", ["rev-parse", "--git-path", `watch-pr-${pr}.json`], { encoding: "utf8" }).trim();
|
|
202
219
|
const seen = new Set(existsSync(seenFile) ? JSON.parse(readFileSync(seenFile, "utf8")) : []);
|
|
203
220
|
let failures = 0;
|
|
204
221
|
for (;;) {
|
|
205
222
|
try {
|
|
206
223
|
const { snapshot, body } = await readSnapshot(p, n);
|
|
207
|
-
const events = newEvents(snapshot, seen);
|
|
224
|
+
const events = newEvents(snapshot, seen, branch);
|
|
208
225
|
if (snapshot.state !== "open") {
|
|
209
226
|
rmSync(seenFile, { force: true });
|
|
210
227
|
console.log(events.map((event) => event.line).join("\n"));
|
package/dist/pr.mjs
CHANGED
|
@@ -25,6 +25,7 @@ import { readFileSync } from "node:fs";
|
|
|
25
25
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
26
26
|
import { reachOf } from "./config.mjs";
|
|
27
27
|
import { AGENT_MARK } from "./lib/work-status.mjs";
|
|
28
|
+
import { changedLines, parseLcov, uncovered } from "./patch-coverage.mjs";
|
|
28
29
|
import { toChecks } from "./pr-watch.mjs";
|
|
29
30
|
import { openCodeHost, } from "./code-host/index.mjs";
|
|
30
31
|
import { openRunner } from "./runner/index.mjs";
|
|
@@ -209,7 +210,7 @@ const FIELDS = {
|
|
|
209
210
|
};
|
|
210
211
|
/** How many lines of a failed job's log `failed` prints, from its end. */
|
|
211
212
|
const LOG_TAIL = 200;
|
|
212
|
-
const USAGE = `Usage: npx --no-install factory pr state [N] [--wait] | threads N [--all] | reply N COMMENT_ID --body-file FILE | resolve N COMMENT_ID | ready N | closes N | wait-checks N | comments N [--author LOGIN] [--contains TEXT] [--json] | comment N --body-file FILE | comment-view ID | label N --add LABEL | --remove LABEL | review-pending N REVIEW | conflicts | open --title TITLE --body-file FILE [--base BRANCH] [--ready] | view N --field ${Object.keys(FIELDS).join("|")} | review N REVIEW | unverified N | failed N | review-again N`;
|
|
213
|
+
const USAGE = `Usage: npx --no-install factory pr state [N] [--wait] | threads N [--all] | reply N COMMENT_ID --body-file FILE | resolve N COMMENT_ID | ready N | closes N | wait-checks N | comments N [--author LOGIN] [--contains TEXT] [--json] | comment N --body-file FILE | comment-view ID | label N --add LABEL | --remove LABEL | review-pending N REVIEW | conflicts | open --title TITLE --body-file FILE [--base BRANCH] [--ready] | view N --field ${Object.keys(FIELDS).join("|")} | review N REVIEW | unverified N | uncovered [BASE] [LCOV] | failed N | review-again N`;
|
|
213
214
|
function option(args, name) {
|
|
214
215
|
const at = args.indexOf(name);
|
|
215
216
|
if (at === -1)
|
|
@@ -504,6 +505,31 @@ export async function main(argv, d) {
|
|
|
504
505
|
}, null, 2));
|
|
505
506
|
return 0;
|
|
506
507
|
}
|
|
508
|
+
case "uncovered": {
|
|
509
|
+
if (rest.length > 2)
|
|
510
|
+
throw new Error(USAGE);
|
|
511
|
+
const [base, lcov = "coverage/lcov.info"] = rest;
|
|
512
|
+
let report;
|
|
513
|
+
try {
|
|
514
|
+
report = d.readFile(lcov);
|
|
515
|
+
}
|
|
516
|
+
catch {
|
|
517
|
+
d.out(`No coverage report at ${lcov}. Run the project's coverage command first.`);
|
|
518
|
+
return 1;
|
|
519
|
+
}
|
|
520
|
+
const from = base ?? `origin/${await p.defaultBranch()}`;
|
|
521
|
+
const diff = d.git(["diff", "-U0", `${from}...HEAD`]);
|
|
522
|
+
const source = (path) => {
|
|
523
|
+
try {
|
|
524
|
+
return d.readFile(path);
|
|
525
|
+
}
|
|
526
|
+
catch {
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
uncovered(parseLcov(report, process.cwd()), changedLines(diff), source).forEach((line) => d.out(line));
|
|
531
|
+
return 0;
|
|
532
|
+
}
|
|
507
533
|
case "unverified": {
|
|
508
534
|
const [pr] = numbers;
|
|
509
535
|
if (!pr)
|
|
@@ -565,7 +591,13 @@ export async function run(argv) {
|
|
|
565
591
|
sleep,
|
|
566
592
|
out: (line) => console.log(line),
|
|
567
593
|
readFile: (path) => readFileSync(path, "utf8"),
|
|
568
|
-
|
|
594
|
+
// A branch's whole diff, which `uncovered` reads, can pass Node's 1 MB.
|
|
595
|
+
// Git's own error is in the thrown message, so it is not printed twice.
|
|
596
|
+
git: (args) => execFileSync("git", args, {
|
|
597
|
+
encoding: "utf8",
|
|
598
|
+
maxBuffer: 256 << 20,
|
|
599
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
600
|
+
}),
|
|
569
601
|
env: process.env,
|
|
570
602
|
});
|
|
571
603
|
}
|
|
@@ -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/session-start.d.mts
CHANGED
|
@@ -1,20 +1,30 @@
|
|
|
1
|
-
type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export declare function repositoryState(git: Git): string[];
|
|
1
|
+
import { gitIn, type Deps as BranchDeps, type Git } from "./lib/default-branch.mts";
|
|
2
|
+
export { gitIn };
|
|
3
|
+
/** Each local branch but the default one, `branch`, with work
|
|
4
|
+
* origin/BRANCH lacks, as "NAME (N commits not on origin/BRANCH)". Pull
|
|
5
|
+
* requests are squash-merged, so a merged branch still has commits the
|
|
6
|
+
* default branch lacks: it counts as merged when merging it into the
|
|
7
|
+
* default branch would change nothing. */
|
|
8
|
+
export declare function unmergedBranches(git: Git, branch: string): string[];
|
|
9
|
+
/** What the hook prints before the tickets' state. `branch` is the default
|
|
10
|
+
* branch, or null when it could not be told: then no branch is compared
|
|
11
|
+
* with anything, and the line that names the fix stands in for the list. */
|
|
12
|
+
export declare function repositoryState(git: Git, branch: string | null): string[];
|
|
13
13
|
/** A line telling the person to run `npm ci` when `node_modules` is older
|
|
14
14
|
* than `package-lock.json`, or null when it is current or there is no
|
|
15
15
|
* lockfile. Without it, a command installed since the lockfile last changed,
|
|
16
16
|
* such as `factory` once it became a workspace package, is missing and the
|
|
17
17
|
* shell's "Permission denied" says nothing of why. */
|
|
18
18
|
export declare function installBehind(dir: string): string | null;
|
|
19
|
+
export type Deps = {
|
|
20
|
+
/** The checkout the session starts in. */
|
|
21
|
+
dir: string;
|
|
22
|
+
/** The sources of the default branch's name. */
|
|
23
|
+
branch: BranchDeps;
|
|
24
|
+
out: (text: string) => void;
|
|
25
|
+
/** Prints each ticket's state, and gives the hook's exit. */
|
|
26
|
+
tickets: () => Promise<number>;
|
|
27
|
+
};
|
|
28
|
+
export declare function main(d: Deps): Promise<number>;
|
|
29
|
+
/** `factory session-start`. */
|
|
19
30
|
export declare function run(): Promise<number>;
|
|
20
|
-
export {};
|