@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/init.mjs
CHANGED
|
@@ -11,34 +11,23 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync
|
|
|
11
11
|
import { tmpdir } from "node:os";
|
|
12
12
|
import { dirname, join } from "node:path";
|
|
13
13
|
import { isMap, parseDocument } from "yaml";
|
|
14
|
-
import {
|
|
14
|
+
import { builtOf, secretSteps, TOOLS, } from "./tools.mjs";
|
|
15
15
|
import { NeedsScopeError } from "./code-host/types.mjs";
|
|
16
|
-
import { columnsOf, fieldNamesOf, parseSettings, repoRoot, SETTINGS_FILE, SettingsError, } from "./config.mjs";
|
|
17
|
-
import { checks as doctorChecks, doctorDeps, line
|
|
18
|
-
import {
|
|
16
|
+
import { columnsOf, fieldNamesOf, parseSettings, POLL_MINUTES, repoRoot, SETTINGS_FILE, SettingsError, } from "./config.mjs";
|
|
17
|
+
import { checks as doctorChecks, doctorDeps, line } from "./doctor.mjs";
|
|
18
|
+
import { hasCommand, noTerminal } from "./lib/has-command.mjs";
|
|
19
|
+
import { DEFAULT_RUNNER } from "./runner/index.mjs";
|
|
20
|
+
import { listed } from "./lib/listed.mjs";
|
|
21
|
+
import { neededSecrets, PART_TEXT, PARTS, partsOn, resolveParts, SIGNING_KEY, } from "./parts.mjs";
|
|
19
22
|
import { CONTEXT as REVIEW_VERDICT } from "./review-verdict.mjs";
|
|
20
|
-
import {
|
|
23
|
+
import { RULE } from "./setup.mjs";
|
|
21
24
|
import { differences, PACKAGE, plan as syncPlan } from "./sync.mjs";
|
|
22
|
-
import { githubTickets } from "./tickets/github.mjs";
|
|
23
|
-
import { ghTransport } from "./tickets/transport.mjs";
|
|
24
|
-
import { gh } from "./lib/gh.mjs";
|
|
25
25
|
import { DEFAULT_COLUMNS } from "./lib/work-status.mjs";
|
|
26
|
-
/** Today's one choice of each tool, by the name a setting gives it. */
|
|
27
|
-
const TOOLS = {
|
|
28
|
-
codeHost: { github: "GitHub" },
|
|
29
|
-
tickets: { github: "GitHub Issues" },
|
|
30
|
-
runner: { "github-actions": "GitHub Actions" },
|
|
31
|
-
agent: "Claude Code",
|
|
32
|
-
};
|
|
33
|
-
/** The coding agent's command, and the one that makes its token. */
|
|
34
|
-
const AGENT = {
|
|
35
|
-
command: "claude",
|
|
36
|
-
token: ["claude", "setup-token"],
|
|
37
|
-
};
|
|
38
|
-
/** The rule that requires the review's verdict, by name, so removing it is
|
|
39
|
-
* deleting that one rule. */
|
|
40
|
-
const RULE = "Software factory";
|
|
41
26
|
const SIGNING_TITLE = "software factory builds";
|
|
27
|
+
/** Where each release's poller image is published. */
|
|
28
|
+
const POLLER_IMAGE = "ghcr.io/davidbyoung/software-factory-poller";
|
|
29
|
+
/** A month of runs at each interval the scheduled poller allows. */
|
|
30
|
+
const RUNS_A_MONTH = (minutes) => (30 * 24 * 60) / minutes;
|
|
42
31
|
const AGAIN = "Run npx --no-install factory init again to add it.";
|
|
43
32
|
/** The columns and fields the board sync uses: the settings' names where
|
|
44
33
|
* they rename one, and none for one they set to none. */
|
|
@@ -62,23 +51,15 @@ function boardShape(s) {
|
|
|
62
51
|
}
|
|
63
52
|
/** The repository and code host a remote's address names, or null for one
|
|
64
53
|
* on a code host the factory does not support. */
|
|
65
|
-
export function parseRemote(url) {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
54
|
+
export function parseRemote(url, tools = TOOLS) {
|
|
55
|
+
for (const [name, host] of Object.entries(tools.codeHost)) {
|
|
56
|
+
const repository = host.repositoryOf(url);
|
|
57
|
+
if (repository)
|
|
58
|
+
return { codeHost: name, repository };
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
70
61
|
}
|
|
71
62
|
const message = (e) => (e instanceof Error ? e.message : String(e));
|
|
72
|
-
/** Items as a sentence lists them: "a", "a and b", "a, b, and c". */
|
|
73
|
-
const listed = (items) => items.length < 3
|
|
74
|
-
? items.join(" and ")
|
|
75
|
-
: `${items.slice(0, -1).join(", ")}, and ${items.at(-1)}`;
|
|
76
|
-
/** What a token must be able to do, in words. */
|
|
77
|
-
const NEED_TEXT = {
|
|
78
|
-
push: "push a branch",
|
|
79
|
-
workflows: "change a workflow's file",
|
|
80
|
-
board: "write the board",
|
|
81
|
-
};
|
|
82
63
|
/** Deletes a key, then any map the deletion left empty above it. */
|
|
83
64
|
function remove(doc, path) {
|
|
84
65
|
if (!doc.hasIn(path))
|
|
@@ -98,10 +79,10 @@ export async function main(_argv, d) {
|
|
|
98
79
|
writeFileSync(at(path), text);
|
|
99
80
|
};
|
|
100
81
|
const remote = d.remote();
|
|
101
|
-
const found = remote ? parseRemote(remote) : null;
|
|
82
|
+
const found = remote ? parseRemote(remote, d.tools) : null;
|
|
102
83
|
if (!found) {
|
|
103
84
|
d.out(remote
|
|
104
|
-
? `The origin remote, ${remote}, is not on a code host the factory supports: ${Object.values(
|
|
85
|
+
? `The origin remote, ${remote}, is not on a code host the factory supports: ${listed(Object.values(d.tools.codeHost).map((t) => t.label))}.`
|
|
105
86
|
: "This is not a git repository with an origin remote. Run it in your repository's checkout.");
|
|
106
87
|
return 1;
|
|
107
88
|
}
|
|
@@ -112,7 +93,7 @@ export async function main(_argv, d) {
|
|
|
112
93
|
let settings = null;
|
|
113
94
|
if (settingsText !== null) {
|
|
114
95
|
try {
|
|
115
|
-
settings = parseSettings(doc.toJS(), (p) => existsSync(at(p)));
|
|
96
|
+
settings = parseSettings(doc.toJS(), (p) => existsSync(at(p)), builtOf(d.tools));
|
|
116
97
|
}
|
|
117
98
|
catch (e) {
|
|
118
99
|
d.out(`${SETTINGS_FILE}: ${message(e)}`);
|
|
@@ -121,24 +102,70 @@ export async function main(_argv, d) {
|
|
|
121
102
|
}
|
|
122
103
|
}
|
|
123
104
|
const hasPackage = existsSync(at("package.json"));
|
|
124
|
-
|
|
105
|
+
// A kind with one tool is that tool; with several, the settings' choice,
|
|
106
|
+
// or one asked for below.
|
|
107
|
+
const only = (r) => {
|
|
108
|
+
const names = Object.keys(r);
|
|
109
|
+
return names.length === 1 ? names[0] : null;
|
|
110
|
+
};
|
|
111
|
+
const named = {
|
|
112
|
+
tickets: settings?.tickets.type ?? null,
|
|
113
|
+
runner: settings?.builds.runner ?? null,
|
|
114
|
+
};
|
|
115
|
+
const choice = {
|
|
116
|
+
tickets: only(d.tools.tickets) ?? named.tickets,
|
|
117
|
+
runner: only(d.tools.runner) ?? named.runner,
|
|
118
|
+
};
|
|
119
|
+
const agentName = Object.keys(d.tools.agent)[0];
|
|
120
|
+
const agent = d.tools.agent[agentName];
|
|
121
|
+
const shown = (kind) => {
|
|
122
|
+
const tools = d.tools[kind];
|
|
123
|
+
if (only(tools))
|
|
124
|
+
return tools[only(tools)].label;
|
|
125
|
+
return choice[kind]
|
|
126
|
+
? `${tools[choice[kind]].label}, from your settings`
|
|
127
|
+
: "chosen below";
|
|
128
|
+
};
|
|
125
129
|
d.out(`Setting up the software factory for ${repository}`);
|
|
126
130
|
d.out("");
|
|
127
131
|
d.out("Found");
|
|
128
132
|
const row = (label, text) => d.out(` ${label.padEnd(14)} ${text}`);
|
|
129
|
-
row("Code host", `${
|
|
130
|
-
row("Tickets",
|
|
131
|
-
row("Coding agent",
|
|
132
|
-
|
|
133
|
-
: `${TOOLS.agent}, which is not installed: sessions and its token need it`);
|
|
134
|
-
row("Cloud builds", TOOLS.runner["github-actions"]);
|
|
133
|
+
row("Code host", `${d.tools.codeHost[found.codeHost].label} (from your git remote)`);
|
|
134
|
+
row("Tickets", shown("tickets"));
|
|
135
|
+
row("Coding agent", agent.setup.found?.({ hasCommand: d.hasCommand }) ?? agent.label);
|
|
136
|
+
row("Cloud builds", shown("runner"));
|
|
135
137
|
row("package.json", hasPackage ? "yes" : "none, so a private one will be created");
|
|
136
138
|
row("Settings", settingsText === null ? "none yet" : SETTINGS_FILE);
|
|
137
139
|
row("Board", settings?.tickets.board != null
|
|
138
140
|
? `${settings.tickets.board}, from your settings`
|
|
139
141
|
: "none yet");
|
|
140
142
|
d.out("");
|
|
141
|
-
const
|
|
143
|
+
const pick = async (kind, question) => {
|
|
144
|
+
const tools = d.tools[kind];
|
|
145
|
+
if (only(tools))
|
|
146
|
+
return only(tools);
|
|
147
|
+
const first = named[kind];
|
|
148
|
+
const names = Object.keys(tools).sort((a, b) => a === first ? -1 : b === first ? 1 : 0);
|
|
149
|
+
return d.ask.select(question, names.map((n) => ({ name: tools[n].label, value: n })));
|
|
150
|
+
};
|
|
151
|
+
const chosen = {
|
|
152
|
+
codeHost: found.codeHost,
|
|
153
|
+
tickets: await pick("tickets", "Which ticket system?"),
|
|
154
|
+
runner: await pick("runner", "Where do cloud builds run?"),
|
|
155
|
+
agent: agentName,
|
|
156
|
+
};
|
|
157
|
+
const codeHost = d.tools.codeHost[chosen.codeHost].open(repository);
|
|
158
|
+
const runner = d.tools.runner[chosen.runner].open(repository);
|
|
159
|
+
const tickets = await d.tools.tickets[chosen.tickets].open({ repository, board: null }, settings);
|
|
160
|
+
const context = (parts) => ({
|
|
161
|
+
repository,
|
|
162
|
+
root: d.root,
|
|
163
|
+
parts: new Set(parts),
|
|
164
|
+
chosen,
|
|
165
|
+
settings,
|
|
166
|
+
hasCommand: d.hasCommand,
|
|
167
|
+
opened: { codeHost, runner, tickets },
|
|
168
|
+
});
|
|
142
169
|
let secrets;
|
|
143
170
|
try {
|
|
144
171
|
secrets = await runner.secretNames();
|
|
@@ -147,9 +174,11 @@ export async function main(_argv, d) {
|
|
|
147
174
|
d.out(`Could not reach the code host: ${message(e)}`);
|
|
148
175
|
return 1;
|
|
149
176
|
}
|
|
150
|
-
const
|
|
177
|
+
const isSet = (n) => secrets.includes(n);
|
|
178
|
+
const cloudNeeds = secretSteps(d.tools, context(["cloud"])).flatMap((s) => s.step.needs.filter((n) => n.part === "cloud"));
|
|
179
|
+
const before = partsOn(settings, secrets, cloudNeeds);
|
|
151
180
|
const first = settingsText === null;
|
|
152
|
-
const
|
|
181
|
+
const chosenParts = await d.ask.checkbox("Which parts do you want?", PARTS.map((part) => ({
|
|
153
182
|
name: PART_TEXT[part].name,
|
|
154
183
|
description: PART_TEXT[part].gives,
|
|
155
184
|
value: part,
|
|
@@ -157,10 +186,11 @@ export async function main(_argv, d) {
|
|
|
157
186
|
? part === "review" || part === "board" || part === "cloud"
|
|
158
187
|
: before.has(part),
|
|
159
188
|
})));
|
|
160
|
-
const resolved = resolveParts(before, new Set(
|
|
189
|
+
const resolved = resolveParts(before, new Set(chosenParts));
|
|
161
190
|
const parts = resolved.parts;
|
|
162
191
|
for (const note of resolved.notes)
|
|
163
192
|
d.out(note);
|
|
193
|
+
const removed = PARTS.filter((p) => before.has(p) && !parts.has(p));
|
|
164
194
|
// The board: the one in the settings, or one chosen now.
|
|
165
195
|
const boardOps = tickets.board;
|
|
166
196
|
let board = parts.has("board")
|
|
@@ -196,20 +226,50 @@ export async function main(_argv, d) {
|
|
|
196
226
|
.split(",")
|
|
197
227
|
.map((x) => x.trim())
|
|
198
228
|
.filter(Boolean);
|
|
229
|
+
// Where the poller runs, asked only when the part is new: a re-run keeps
|
|
230
|
+
// what the settings say, as it does every value already set.
|
|
231
|
+
let trigger = settings?.builds.trigger ?? "manual";
|
|
232
|
+
let pollMinutes = null;
|
|
233
|
+
if (parts.has("from-board") && !before.has("from-board")) {
|
|
234
|
+
trigger = (await d.ask.select("Where does the poller run?", [
|
|
235
|
+
{
|
|
236
|
+
name: "A schedule on GitHub Actions, every 5 minutes, nothing to host",
|
|
237
|
+
value: "github-action",
|
|
238
|
+
},
|
|
239
|
+
{ name: "A server you host, within a minute", value: "own-server" },
|
|
240
|
+
]));
|
|
241
|
+
if (trigger === "github-action" &&
|
|
242
|
+
(await codeHost.isPrivate().catch(() => true))) {
|
|
243
|
+
d.out("Each run bills at least one Actions minute on a private repository.");
|
|
244
|
+
pollMinutes = Number(await d.ask.select("How often?", POLL_MINUTES.map((m) => ({
|
|
245
|
+
name: `Every ${m} minutes, ${RUNS_A_MONTH(m).toLocaleString("en-US")} runs a month`,
|
|
246
|
+
value: String(m),
|
|
247
|
+
})), "30"));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
199
250
|
// The settings as they will stand, keeping every other key and comment.
|
|
200
251
|
if (!doc.has("version"))
|
|
201
252
|
doc.set("version", 1);
|
|
202
253
|
if (!doc.has("repository"))
|
|
203
254
|
doc.set("repository", repository);
|
|
255
|
+
// A tool other than the one a setting defaults to is written down.
|
|
256
|
+
if ((doc.getIn(["tickets", "type"]) ?? "github") !== chosen.tickets)
|
|
257
|
+
doc.setIn(["tickets", "type"], chosen.tickets);
|
|
258
|
+
if ((doc.getIn(["builds", "runner"]) ?? DEFAULT_RUNNER) !== chosen.runner)
|
|
259
|
+
doc.setIn(["builds", "runner"], chosen.runner);
|
|
204
260
|
if (parts.has("board") && typeof board === "number")
|
|
205
261
|
doc.setIn(["tickets", "board"], board);
|
|
206
262
|
if (!parts.has("board"))
|
|
207
263
|
for (const key of ["board", "columns", "fields"])
|
|
208
264
|
remove(doc, ["tickets", key]);
|
|
209
265
|
if (parts.has("from-board"))
|
|
210
|
-
doc.setIn(["builds", "trigger"],
|
|
266
|
+
doc.setIn(["builds", "trigger"], trigger);
|
|
211
267
|
else if (before.has("from-board"))
|
|
212
268
|
remove(doc, ["builds", "trigger"]);
|
|
269
|
+
if (pollMinutes !== null && pollMinutes !== 5)
|
|
270
|
+
doc.setIn(["builds", "poll-minutes"], pollMinutes);
|
|
271
|
+
if (!parts.has("from-board") || trigger !== "github-action")
|
|
272
|
+
remove(doc, ["builds", "poll-minutes"]);
|
|
213
273
|
if (parts.has("auto-merge"))
|
|
214
274
|
doc.setIn(["auto-merge", "allow"], allow);
|
|
215
275
|
else
|
|
@@ -220,28 +280,43 @@ export async function main(_argv, d) {
|
|
|
220
280
|
doc.setIn(["ci-review", "commands"], []);
|
|
221
281
|
if (!parts.has("review"))
|
|
222
282
|
doc.delete("ci-review");
|
|
283
|
+
// The ticket system's own values: asked for once, and taken out with
|
|
284
|
+
// the part that needed them.
|
|
285
|
+
const values = (ps) => (d.tools.tickets[chosen.tickets].setup.steps?.(context(ps)) ?? []).filter((s) => s.kind === "value");
|
|
286
|
+
for (const step of values(parts)) {
|
|
287
|
+
if (step.part !== null && !parts.has(step.part))
|
|
288
|
+
continue;
|
|
289
|
+
if (doc.hasIn(["tickets", step.key]))
|
|
290
|
+
continue;
|
|
291
|
+
doc.setIn(["tickets", step.key], await d.ask.input(step.ask, step.fallback ?? ""));
|
|
292
|
+
}
|
|
293
|
+
for (const step of values(removed))
|
|
294
|
+
if (step.part !== null && removed.includes(step.part))
|
|
295
|
+
remove(doc, ["tickets", step.key]);
|
|
223
296
|
// The secrets: those the parts read that are not set, or all of them when
|
|
224
297
|
// you choose to replace them.
|
|
225
|
-
const
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
];
|
|
298
|
+
const steps = secretSteps(d.tools, context(parts));
|
|
299
|
+
const needed = neededSecrets(parts, steps);
|
|
300
|
+
const alreadySet = [...new Set(needed.flatMap((n) => n.anyOf.filter(isSet)))];
|
|
229
301
|
let replace = false;
|
|
230
302
|
if (alreadySet.length)
|
|
231
303
|
replace = await d.ask.confirm(alreadySet.length === 1
|
|
232
304
|
? "1 secret these parts read is already set. Replace it?"
|
|
233
305
|
: `${alreadySet.length} secrets these parts read are already set. Replace them?`, false);
|
|
234
|
-
const
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
306
|
+
const unmet = (step) => step.needs.some((n) => (n.part === null || parts.has(n.part)) && !n.anyOf.some(isSet));
|
|
307
|
+
const asked = steps
|
|
308
|
+
.filter(({ step }) => replace || unmet(step))
|
|
309
|
+
.map(({ step }) => ({
|
|
310
|
+
step,
|
|
311
|
+
names: step.storeAs.filter((n) => replace || !isSet(n)),
|
|
312
|
+
}))
|
|
313
|
+
.filter((a) => a.names.length > 0);
|
|
314
|
+
const wantsKey = parts.has("signing") && (replace || !isSet(SIGNING_KEY));
|
|
315
|
+
const stillRead = new Set(needed.flatMap((n) => n.anyOf));
|
|
241
316
|
const deletable = [
|
|
242
|
-
...new Set(neededSecrets(new Set(removed))
|
|
317
|
+
...new Set(neededSecrets(new Set(removed), secretSteps(d.tools, context(removed)))
|
|
243
318
|
.flatMap((n) => n.anyOf)
|
|
244
|
-
.filter((n) =>
|
|
319
|
+
.filter((n) => isSet(n) && !stillRead.has(n))),
|
|
245
320
|
];
|
|
246
321
|
// The plan.
|
|
247
322
|
const newText = String(doc);
|
|
@@ -261,8 +336,7 @@ export async function main(_argv, d) {
|
|
|
261
336
|
return 1;
|
|
262
337
|
}
|
|
263
338
|
const toStore = [
|
|
264
|
-
...(
|
|
265
|
-
...tokenTo,
|
|
339
|
+
...asked.flatMap((a) => a.names),
|
|
266
340
|
...(wantsKey ? [SIGNING_KEY] : []),
|
|
267
341
|
];
|
|
268
342
|
d.out("");
|
|
@@ -326,62 +400,37 @@ export async function main(_argv, d) {
|
|
|
326
400
|
const synced = await d.sync();
|
|
327
401
|
if (synced !== 0)
|
|
328
402
|
d.out("The sync failed, as above.");
|
|
329
|
-
//
|
|
330
|
-
if (wantsAgent) {
|
|
331
|
-
let value = "";
|
|
332
|
-
if (agentInstalled) {
|
|
333
|
-
d.out("");
|
|
334
|
-
d.out(`The coding agent's token: running ${AGENT.token.join(" ")}...`);
|
|
335
|
-
await d.interactive(AGENT.token);
|
|
336
|
-
value = await d.ask.secret("Paste the token it printed (leave empty to do this later):");
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
value = await d.ask.secret("Paste an API key from the Claude Console (leave empty to do this later):");
|
|
340
|
-
}
|
|
341
|
-
const secret = agentInstalled ? AGENT_TOKEN : AGENT_KEY;
|
|
342
|
-
if (value) {
|
|
343
|
-
await runner.setSecret(secret, value);
|
|
344
|
-
d.out(`Stored as ${secret}.`);
|
|
345
|
-
}
|
|
346
|
-
else
|
|
347
|
-
d.out(`No ${secret} stored. ${AGAIN}`);
|
|
348
|
-
}
|
|
349
|
-
// The one access token.
|
|
403
|
+
// Each tool's secrets, in the tools' order.
|
|
350
404
|
let tokenAccount = null;
|
|
351
|
-
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
405
|
+
for (const { step, names } of asked) {
|
|
406
|
+
for (const l of step.intro)
|
|
407
|
+
d.out(l);
|
|
408
|
+
if (step.get && "page" in step.get)
|
|
409
|
+
d.openPage(step.get.page);
|
|
410
|
+
if (step.get && "command" in step.get)
|
|
411
|
+
await d.interactive(step.get.command);
|
|
358
412
|
for (;;) {
|
|
359
|
-
const value = await d.ask.secret(
|
|
413
|
+
const value = await d.ask.secret(step.prompt);
|
|
360
414
|
if (!value) {
|
|
361
|
-
d.out(
|
|
415
|
+
d.out(`${step.skipped} ${AGAIN}`);
|
|
362
416
|
break;
|
|
363
417
|
}
|
|
364
|
-
let
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
d.out(`That token lacks ${listed(lacking)}. Make one with every scope checked, and paste it.`);
|
|
377
|
-
continue;
|
|
378
|
-
}
|
|
379
|
-
if (owned.scopes === null)
|
|
380
|
-
d.out(`The code host does not say what this token may do: make sure it can ${listed(tokenNeeds(parts).map((n) => NEED_TEXT[n]))}.`);
|
|
381
|
-
for (const n of tokenTo)
|
|
418
|
+
let checked = { lines: [] };
|
|
419
|
+
if (step.verify)
|
|
420
|
+
try {
|
|
421
|
+
checked = await step.verify(value);
|
|
422
|
+
}
|
|
423
|
+
catch (e) {
|
|
424
|
+
d.out(message(e));
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
for (const l of checked.lines)
|
|
428
|
+
d.out(l);
|
|
429
|
+
for (const n of names)
|
|
382
430
|
await runner.setSecret(n, value);
|
|
383
|
-
|
|
384
|
-
|
|
431
|
+
if (checked.account !== undefined)
|
|
432
|
+
tokenAccount = checked.account;
|
|
433
|
+
d.out(step.stored(names, checked.account));
|
|
385
434
|
break;
|
|
386
435
|
}
|
|
387
436
|
}
|
|
@@ -434,9 +483,11 @@ export async function main(_argv, d) {
|
|
|
434
483
|
const app = codeHost.reviewAppPage();
|
|
435
484
|
if (parts.has("review") && app)
|
|
436
485
|
left.push(`Install the app the review posts through: ${app}`);
|
|
437
|
-
if (parts.has("from-board") &&
|
|
486
|
+
if (parts.has("from-board") &&
|
|
487
|
+
trigger === "own-server" &&
|
|
488
|
+
typeof board === "number")
|
|
438
489
|
left.push([
|
|
439
|
-
|
|
490
|
+
`Run the poller's image, ${POLLER_IMAGE}:${d.packageVersion}, where you host it, with:`,
|
|
440
491
|
` FACTORY_REPOSITORY=${repository}`,
|
|
441
492
|
` FACTORY_BOARD_OWNER=${owner}`,
|
|
442
493
|
` FACTORY_BOARD_NUMBER=${board}`,
|
|
@@ -457,13 +508,18 @@ async function terminalAsk() {
|
|
|
457
508
|
const p = await import("@inquirer/prompts");
|
|
458
509
|
return {
|
|
459
510
|
checkbox: (message, choices) => p.checkbox({ message, choices }),
|
|
460
|
-
select: (message, choices) => p.select({ message, choices }),
|
|
511
|
+
select: (message, choices, fallback) => p.select({ message, choices, default: fallback }),
|
|
461
512
|
confirm: (message, fallback) => p.confirm({ message, default: fallback }),
|
|
462
513
|
secret: (message) => p.password({ message, mask: "•" }),
|
|
463
514
|
input: (message, fallback) => p.input({ message, default: fallback }),
|
|
464
515
|
};
|
|
465
516
|
}
|
|
466
517
|
export async function run(argv) {
|
|
518
|
+
const terminal = noTerminal("init");
|
|
519
|
+
if (terminal) {
|
|
520
|
+
console.log(terminal);
|
|
521
|
+
return 1;
|
|
522
|
+
}
|
|
467
523
|
let root;
|
|
468
524
|
try {
|
|
469
525
|
root = repoRoot();
|
|
@@ -489,15 +545,7 @@ export async function run(argv) {
|
|
|
489
545
|
return null;
|
|
490
546
|
}
|
|
491
547
|
},
|
|
492
|
-
|
|
493
|
-
codeHost: openCodeHost(repository),
|
|
494
|
-
runner: openRunner(repository),
|
|
495
|
-
tickets: githubTickets({
|
|
496
|
-
transport: ghTransport(gh),
|
|
497
|
-
repository,
|
|
498
|
-
board: null,
|
|
499
|
-
}),
|
|
500
|
-
}),
|
|
548
|
+
tools: TOOLS,
|
|
501
549
|
sync: async () => (await import("./sync.mjs")).run([]),
|
|
502
550
|
syncChanges: (text) => {
|
|
503
551
|
const raw = parseDocument(text).toJS();
|
|
@@ -505,7 +553,7 @@ export async function run(argv) {
|
|
|
505
553
|
return differences(root, syncPlan(PACKAGE, root, s));
|
|
506
554
|
},
|
|
507
555
|
interactive: async (argv2) => spawnSync(argv2[0], argv2.slice(1), { stdio: "inherit" }).status ?? 1,
|
|
508
|
-
hasCommand
|
|
556
|
+
hasCommand,
|
|
509
557
|
openPage: (url) => {
|
|
510
558
|
const opener = process.platform === "darwin"
|
|
511
559
|
? "open"
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** The line a command that asks questions prints with no terminal to ask
|
|
2
|
+
* in, or null when there is one. */
|
|
3
|
+
export declare const noTerminal: (command: string) => string | null;
|
|
4
|
+
/** Whether a command is installed, by running it with `--version`. */
|
|
5
|
+
export declare const hasCommand: (name: string) => boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
/** The line a command that asks questions prints with no terminal to ask
|
|
3
|
+
* in, or null when there is one. */
|
|
4
|
+
export const noTerminal = (command) => process.stdin.isTTY
|
|
5
|
+
? null
|
|
6
|
+
: `factory ${command} asks its questions in a terminal: run it in one.`;
|
|
7
|
+
/** Whether a command is installed, by running it with `--version`. */
|
|
8
|
+
export const hasCommand = (name) => !spawnSync(name, ["--version"], { stdio: "ignore" }).error;
|
|
@@ -163,8 +163,18 @@ export declare function actionsRunLink(derived: Pick<Derived, "session" | "runsI
|
|
|
163
163
|
export declare function derive(issue: Issue, card: BoardCard | null, pulls: PullRequest[], columns?: Columns): Derived;
|
|
164
164
|
/** Over 24 hours In progress or In refinement with a session. */
|
|
165
165
|
export declare function isStale(derived: Derived, now: Date): boolean;
|
|
166
|
-
/**
|
|
167
|
-
|
|
166
|
+
/** How long a card may sit in Ready before the poller should have started
|
|
167
|
+
* it, and what the flag asks then; null when nothing starts builds from
|
|
168
|
+
* the board. A schedule runs every few minutes and often late, so it gets
|
|
169
|
+
* its interval and 15 minutes more. */
|
|
170
|
+
export type Watch = {
|
|
171
|
+
minutes: number;
|
|
172
|
+
flag: string;
|
|
173
|
+
};
|
|
174
|
+
export declare function watchOf(trigger: "own-server" | "github-action" | "manual", pollMinutes: number): Watch | null;
|
|
175
|
+
/** Ready for longer than the poller takes, with no start: it should have
|
|
176
|
+
* fired. */
|
|
177
|
+
export declare function isNotStarted(derived: Derived, openBlockers: number[], now: Date, minutes?: number): boolean;
|
|
168
178
|
/** A claim or start over 24 hours old with no pull request, which the
|
|
169
179
|
* nightly sync clears. Null when there is nothing to clear. */
|
|
170
180
|
export declare function toClear(issue: Issue, pulls: PullRequest[], now: Date): {
|
package/dist/lib/work-status.mjs
CHANGED
|
@@ -389,12 +389,23 @@ export function isStale(derived, now) {
|
|
|
389
389
|
return (derived.since !== null &&
|
|
390
390
|
now.getTime() - Date.parse(derived.since) > 24 * HOUR);
|
|
391
391
|
}
|
|
392
|
-
|
|
393
|
-
|
|
392
|
+
export function watchOf(trigger, pollMinutes) {
|
|
393
|
+
if (trigger === "manual")
|
|
394
|
+
return null;
|
|
395
|
+
if (trigger === "github-action")
|
|
396
|
+
return {
|
|
397
|
+
minutes: pollMinutes + 15,
|
|
398
|
+
flag: "not started, is the factory-poller workflow running?",
|
|
399
|
+
};
|
|
400
|
+
return { minutes: 5, flag: "not started, is the poller running?" };
|
|
401
|
+
}
|
|
402
|
+
/** Ready for longer than the poller takes, with no start: it should have
|
|
403
|
+
* fired. */
|
|
404
|
+
export function isNotStarted(derived, openBlockers, now, minutes = 5) {
|
|
394
405
|
return (derived.status === "Ready" &&
|
|
395
406
|
openBlockers.length === 0 &&
|
|
396
407
|
derived.since !== null &&
|
|
397
|
-
now.getTime() - Date.parse(derived.since) >
|
|
408
|
+
now.getTime() - Date.parse(derived.since) > minutes * 60 * 1000);
|
|
398
409
|
}
|
|
399
410
|
/** A claim or start over 24 hours old with no pull request, which the
|
|
400
411
|
* nightly sync clears. Null when there is nothing to clear. */
|
package/dist/parts.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Settings } from "./config.mts";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Need } from "./setup.mts";
|
|
3
3
|
export declare const PARTS: readonly ["review", "board", "cloud", "from-board", "auto-merge", "signing"];
|
|
4
4
|
export type Part = (typeof PARTS)[number];
|
|
5
5
|
/** Each part's name, and what it gives you, in plain words. */
|
|
@@ -16,9 +16,10 @@ export declare const BOARD_TOKEN = "FACTORY_BOARD_TOKEN";
|
|
|
16
16
|
export declare const BUILD_TOKEN = "FACTORY_BUILD_TOKEN";
|
|
17
17
|
export declare const AUTOMERGE_TOKEN = "FACTORY_AUTOMERGE_TOKEN";
|
|
18
18
|
export declare const SIGNING_KEY = "FACTORY_SIGNING_KEY";
|
|
19
|
-
/** The parts on: those with a setting, from the settings;
|
|
20
|
-
*
|
|
21
|
-
|
|
19
|
+
/** The parts on: those with a setting, from the settings; cloud builds,
|
|
20
|
+
* when every secret the tools read for them is set; and signing, from its
|
|
21
|
+
* key. */
|
|
22
|
+
export declare function partsOn(s: Settings | null, secrets: string[], cloudNeeds: Need[]): Set<Part>;
|
|
22
23
|
/** The parts chosen, with what one needs turned on alongside it, and a part
|
|
23
24
|
* turned off when one it needs was just turned off. `before` is what was on,
|
|
24
25
|
* so turning a needed part off wins over keeping the part that needs it. */
|
|
@@ -26,14 +27,16 @@ export declare function resolveParts(before: Set<Part>, chosen: Set<Part>): {
|
|
|
26
27
|
parts: Set<Part>;
|
|
27
28
|
notes: string[];
|
|
28
29
|
};
|
|
29
|
-
/**
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
/** A secret read, by the tool whose step reads it, or the factory's own. */
|
|
31
|
+
export type Needed = Need & {
|
|
32
|
+
tool: string;
|
|
33
|
+
};
|
|
34
|
+
/** The secrets read for the parts on, from the tools' secret steps, with
|
|
35
|
+
* the signing key, which is the factory's own. Each is met by any one of
|
|
36
|
+
* its names. */
|
|
37
|
+
export declare function neededSecrets(parts: ReadonlySet<Part>, steps: {
|
|
38
|
+
tool: string;
|
|
39
|
+
step: {
|
|
40
|
+
needs: Need[];
|
|
41
|
+
};
|
|
42
|
+
}[]): Needed[];
|