@davidbyoung/software-factory 0.1.11 → 0.1.13
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/agents/factory-e2e-reviewer.md +1 -1
- package/agents/factory-test-reviewer.md +1 -1
- package/agents/factory-ui-reviewer.md +2 -2
- package/dist/board.d.mts +9 -7
- package/dist/board.mjs +59 -36
- package/dist/build.d.mts +4 -0
- package/dist/build.mjs +9 -4
- package/dist/cli.mjs +8 -1
- package/dist/code-host/github.mjs +9 -4
- package/dist/code-host/types.d.mts +4 -2
- package/dist/commands.d.mts +1 -1
- package/dist/commands.mjs +16 -7
- package/dist/config.d.mts +7 -0
- package/dist/config.mjs +68 -5
- package/dist/explain.mjs +6 -0
- package/dist/guard-commit.d.mts +3 -3
- package/dist/guard-commit.mjs +31 -6
- package/dist/guard-ticket-text.d.mts +3 -2
- package/dist/guard-ticket-text.mjs +7 -4
- package/dist/labels.d.mts +28 -0
- package/dist/labels.mjs +36 -0
- package/dist/lib/clock.d.mts +3 -1
- package/dist/lib/clock.mjs +12 -6
- package/dist/lib/pull-tickets.d.mts +15 -0
- package/dist/lib/pull-tickets.mjs +12 -0
- package/dist/lib/refined-check.d.mts +1 -1
- package/dist/lib/refined-check.mjs +3 -5
- package/dist/lib/usage.d.mts +3 -1
- package/dist/lib/usage.mjs +4 -2
- package/dist/lib/work-status.d.mts +29 -23
- package/dist/lib/work-status.mjs +30 -33
- package/dist/merge-policy.d.mts +9 -7
- package/dist/merge-policy.mjs +13 -11
- package/dist/poller.d.mts +5 -3
- package/dist/poller.mjs +27 -17
- package/dist/pr.d.mts +22 -0
- package/dist/pr.mjs +60 -10
- package/dist/remove.mjs +16 -9
- package/dist/review-tickets.d.mts +12 -0
- package/dist/review-tickets.mjs +59 -0
- package/dist/review-verdict.d.mts +6 -1
- package/dist/review-verdict.mjs +15 -9
- package/dist/reviewers.d.mts +7 -4
- package/dist/reviewers.mjs +19 -12
- package/dist/runner/github-actions.mjs +6 -7
- package/dist/runner/types.d.mts +7 -6
- package/dist/status.d.mts +19 -7
- package/dist/status.mjs +38 -23
- package/dist/sync.d.mts +8 -0
- package/dist/sync.mjs +30 -1
- package/dist/ticket-fields.d.mts +4 -2
- package/dist/ticket-fields.mjs +10 -3
- package/dist/ticket.d.mts +14 -7
- package/dist/ticket.mjs +121 -72
- package/dist/tickets/github.d.mts +10 -2
- package/dist/tickets/github.mjs +74 -20
- package/dist/tickets/index.d.mts +9 -2
- package/dist/tickets/index.mjs +20 -5
- package/dist/tickets/types.d.mts +59 -30
- package/dist/tickets/types.mjs +13 -3
- package/dist/tool-names.d.mts +7 -0
- package/dist/tool-names.mjs +1 -0
- package/dist/tools.d.mts +4 -1
- package/dist/tools.mjs +5 -0
- package/docs/cli.md +12 -8
- package/docs/configuration.md +179 -9
- package/docs/developing.md +17 -9
- package/docs/github/by-hand.md +2 -2
- package/docs/github/reference.md +22 -22
- package/docs/plugins.md +6 -6
- package/docs/workflow.md +8 -6
- package/package.json +1 -1
- package/review.md +11 -11
- package/rules.md +25 -16
- package/settings.schema.json +45 -0
- package/skills/factory-address-review/SKILL.md +7 -6
- package/skills/factory-build/SKILL.md +28 -22
- package/skills/factory-refine/SKILL.md +1 -1
- package/skills/factory-resolve-conflicts/SKILL.md +5 -4
- package/workflows/factory-build.yml +6 -5
- package/workflows/factory-claude-review.yml +38 -1
- package/workflows/factory-conflicts.yml +1 -1
- package/workflows/factory-merge-policy.yml +8 -7
- package/workflows/factory-review-verdict.yml +1 -1
- package/workflows/factory-review.yml +1 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Prints the tickets a pull request builds, for its review: each one it
|
|
2
|
+
// closes, then each it builds part of, as a `## ` heading with the ticket's
|
|
3
|
+
// written form and title, then its body.
|
|
4
|
+
//
|
|
5
|
+
// npx --no-install factory review tickets N
|
|
6
|
+
//
|
|
7
|
+
// The review workflow runs it from the base commit's install and hands the
|
|
8
|
+
// reviewer its output, so a pull request cannot change what its own review
|
|
9
|
+
// is told the tickets say.
|
|
10
|
+
import { reachOf } from "./config.mjs";
|
|
11
|
+
import { prDeps, pullTickets } from "./pr.mjs";
|
|
12
|
+
import { NotFoundError, } from "./tickets/types.mjs";
|
|
13
|
+
const USAGE = "Usage: factory review tickets N";
|
|
14
|
+
export async function main(argv, d) {
|
|
15
|
+
const pr = Number(argv[0]);
|
|
16
|
+
if (argv.length !== 1 || !Number.isInteger(pr) || pr <= 0) {
|
|
17
|
+
console.error(USAGE);
|
|
18
|
+
return 2;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const { tickets, links } = await d.pull(pr);
|
|
22
|
+
const keys = [
|
|
23
|
+
...links.closes,
|
|
24
|
+
...links.partOf.filter((k) => !links.closes.includes(k)),
|
|
25
|
+
];
|
|
26
|
+
for (const [i, key] of keys.entries()) {
|
|
27
|
+
if (i > 0)
|
|
28
|
+
d.out("");
|
|
29
|
+
const ref = tickets.ref(key);
|
|
30
|
+
try {
|
|
31
|
+
const ticket = await tickets.read(key);
|
|
32
|
+
d.out(`## ${ref} ${ticket.title}`);
|
|
33
|
+
d.out("");
|
|
34
|
+
d.out(ticket.body.trimEnd());
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
if (!(error instanceof NotFoundError))
|
|
38
|
+
throw error;
|
|
39
|
+
d.out(`## ${ref}`);
|
|
40
|
+
d.out("");
|
|
41
|
+
d.out("Not found.");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
48
|
+
return 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** `factory review tickets N`. */
|
|
52
|
+
export async function run(argv) {
|
|
53
|
+
const { repository, codeHost, runner } = await reachOf(process.env);
|
|
54
|
+
const deps = prDeps(repository, codeHost, runner);
|
|
55
|
+
return main(argv, {
|
|
56
|
+
pull: (n) => pullTickets(deps, n),
|
|
57
|
+
out: (line) => console.log(line),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import type { CodeHost } from "./code-host/types.mts";
|
|
3
3
|
export declare const CONTEXT = "Review verdict";
|
|
4
|
-
|
|
4
|
+
/** The override's name when the settings give it no other. */
|
|
5
|
+
export declare const OVERRIDE: "verdict-override";
|
|
5
6
|
export type Verdict = "ready" | "changes" | null;
|
|
6
7
|
export type Input = {
|
|
7
8
|
event: "workflow_run" | "pull_request_target";
|
|
@@ -9,6 +10,8 @@ export type Input = {
|
|
|
9
10
|
action?: string;
|
|
10
11
|
/** The label added or removed, on a labeled or unlabeled action. */
|
|
11
12
|
label?: string;
|
|
13
|
+
/** The override's name, as `code-host.labels` gives it. */
|
|
14
|
+
override?: string;
|
|
12
15
|
isDependabot: boolean;
|
|
13
16
|
isDraft: boolean;
|
|
14
17
|
/** The override label is on the pull request. A push removes it, so it
|
|
@@ -63,6 +66,8 @@ export declare function apply(o: {
|
|
|
63
66
|
/** The page of the run posting the status. */
|
|
64
67
|
link?: string;
|
|
65
68
|
log: (line: string) => void;
|
|
69
|
+
/** The override's name, as `code-host.labels` gives it. */
|
|
70
|
+
override?: string;
|
|
66
71
|
}): Promise<void>;
|
|
67
72
|
/** `factory review verdict`. */
|
|
68
73
|
export declare function run(): Promise<number>;
|
package/dist/review-verdict.mjs
CHANGED
|
@@ -5,14 +5,17 @@
|
|
|
5
5
|
//
|
|
6
6
|
// Runs from main's copy, on two events: the Claude review finishing
|
|
7
7
|
// (workflow_run), and the pull request itself (pull_request_target: opened,
|
|
8
|
-
// pushed to, marked ready, or labeled
|
|
8
|
+
// pushed to, marked ready, or labeled with the override). The verdict is posted
|
|
9
9
|
// on one commit, so a new push always starts without one.
|
|
10
|
+
import { loadSettings } from "./config.mjs";
|
|
11
|
+
import { PR_LABELS } from "./labels.mjs";
|
|
10
12
|
import { readFileSync } from "node:fs";
|
|
11
13
|
import { openCodeHost } from "./code-host/index.mjs";
|
|
12
14
|
import { openRunner } from "./runner/index.mjs";
|
|
13
15
|
// The status's name, which the main ruleset requires by exactly this text.
|
|
14
16
|
export const CONTEXT = "Review verdict";
|
|
15
|
-
|
|
17
|
+
/** The override's name when the settings give it no other. */
|
|
18
|
+
export const OVERRIDE = PR_LABELS["verdict-override"];
|
|
16
19
|
const WAITING = {
|
|
17
20
|
state: "pending",
|
|
18
21
|
description: "Waiting for the review of this commit",
|
|
@@ -62,7 +65,7 @@ export function decide(input) {
|
|
|
62
65
|
}
|
|
63
66
|
switch (input.action) {
|
|
64
67
|
case "labeled":
|
|
65
|
-
if (input.label !== OVERRIDE)
|
|
68
|
+
if (input.label !== (input.override ?? OVERRIDE))
|
|
66
69
|
return null;
|
|
67
70
|
if (!input.senderIsApprover) {
|
|
68
71
|
return {
|
|
@@ -75,7 +78,7 @@ export function decide(input) {
|
|
|
75
78
|
}
|
|
76
79
|
return { ...OVERRIDDEN, announceOverride: true };
|
|
77
80
|
case "unlabeled":
|
|
78
|
-
return input.label === OVERRIDE
|
|
81
|
+
return input.label === (input.override ?? OVERRIDE)
|
|
79
82
|
? fromVerdict(input.verdict, WAITING)
|
|
80
83
|
: null;
|
|
81
84
|
case "synchronize":
|
|
@@ -120,6 +123,7 @@ export function verdictIn(comments, sha) {
|
|
|
120
123
|
* rejects with the reason. */
|
|
121
124
|
export async function apply(o) {
|
|
122
125
|
const { eventName, event, pulls, log } = o;
|
|
126
|
+
const override = o.override ?? OVERRIDE;
|
|
123
127
|
// Read the pull request as it is now. The event's copy can be stale: a
|
|
124
128
|
// "marked ready" event sent just after a push carries the previous commit.
|
|
125
129
|
let number;
|
|
@@ -143,7 +147,7 @@ export async function apply(o) {
|
|
|
143
147
|
}
|
|
144
148
|
let senderIsApprover;
|
|
145
149
|
let lookupFailure;
|
|
146
|
-
if (event.action === "labeled" && event.label?.name ===
|
|
150
|
+
if (event.action === "labeled" && event.label?.name === override)
|
|
147
151
|
try {
|
|
148
152
|
senderIsApprover = await pulls.canWrite(event.sender.login);
|
|
149
153
|
}
|
|
@@ -155,9 +159,10 @@ export async function apply(o) {
|
|
|
155
159
|
event: eventName,
|
|
156
160
|
action: event.action,
|
|
157
161
|
label: event.label?.name,
|
|
162
|
+
override,
|
|
158
163
|
isDependabot: pr.author === "dependabot[bot]",
|
|
159
164
|
isDraft: pr.isDraft,
|
|
160
|
-
hasOverride: labels.includes(
|
|
165
|
+
hasOverride: labels.includes(override),
|
|
161
166
|
senderIsApprover,
|
|
162
167
|
senderUnchecked: lookupFailure !== undefined,
|
|
163
168
|
runConclusion: event.workflow_run?.conclusion,
|
|
@@ -173,12 +178,12 @@ export async function apply(o) {
|
|
|
173
178
|
});
|
|
174
179
|
log(`${CONTEXT} on ${sha}: ${decision.state}, ${decision.description}`);
|
|
175
180
|
if (decision.removeOverride)
|
|
176
|
-
await pulls.removeLabel(pr.number,
|
|
181
|
+
await pulls.removeLabel(pr.number, override);
|
|
177
182
|
const who = event.sender?.login;
|
|
178
183
|
if (decision.explainRemoval === "not an approver")
|
|
179
|
-
await pulls.comment(pr.number, `Removed \`${
|
|
184
|
+
await pulls.comment(pr.number, `Removed \`${override}\`: @${who} cannot write to this repository, and only an account that can may pass the verdict.`);
|
|
180
185
|
if (decision.explainRemoval === "could not check") {
|
|
181
|
-
await pulls.comment(pr.number, `Removed \`${
|
|
186
|
+
await pulls.comment(pr.number, `Removed \`${override}\`: could not check whether @${who} can write to this repository. Add the label again to retry.`);
|
|
182
187
|
throw lookupFailure;
|
|
183
188
|
}
|
|
184
189
|
if (decision.announceOverride) {
|
|
@@ -199,6 +204,7 @@ export async function run() {
|
|
|
199
204
|
pulls: openCodeHost(repo),
|
|
200
205
|
link: openRunner(repo).thisRun(process.env)?.page,
|
|
201
206
|
log: (line) => console.log(line),
|
|
207
|
+
override: (await loadSettings()).codeHost.labels["verdict-override"],
|
|
202
208
|
});
|
|
203
209
|
return 0;
|
|
204
210
|
}
|
package/dist/reviewers.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { type Tickets } from "./tickets/types.mts";
|
|
2
|
+
import { type Key, type Tickets } from "./tickets/types.mts";
|
|
3
3
|
import { type Clock } from "./lib/clock.mts";
|
|
4
4
|
import { type ReviewerRun } from "./lib/work-status.mts";
|
|
5
5
|
export type HookInput = {
|
|
@@ -12,7 +12,7 @@ export type HookInput = {
|
|
|
12
12
|
/** What the hook remembers between its runs: the comment it posted, and the
|
|
13
13
|
* rows it shows. */
|
|
14
14
|
export type State = {
|
|
15
|
-
commentId:
|
|
15
|
+
commentId: string | null;
|
|
16
16
|
runs: ReviewerRun[];
|
|
17
17
|
};
|
|
18
18
|
export type Deps = {
|
|
@@ -24,8 +24,8 @@ export type Deps = {
|
|
|
24
24
|
/** The text of a file, or null when it cannot be read. */
|
|
25
25
|
readFile: (path: string) => string | null;
|
|
26
26
|
state: {
|
|
27
|
-
read: (session: string, issue:
|
|
28
|
-
write: (session: string, issue:
|
|
27
|
+
read: (session: string, issue: Key) => State;
|
|
28
|
+
write: (session: string, issue: Key, state: State) => void;
|
|
29
29
|
};
|
|
30
30
|
/** Runs `work` while no other hook of this session edits the comment. */
|
|
31
31
|
locked: <T>(session: string, work: () => Promise<T>) => Promise<T>;
|
|
@@ -50,5 +50,8 @@ export declare function resultText(run: ReviewerRun, now: Date): string;
|
|
|
50
50
|
* note already includes what the reviewers spent. */
|
|
51
51
|
export declare function commentFor(session: string, runs: ReviewerRun[], now: Date): string;
|
|
52
52
|
export declare function main(event: string, input: HookInput, agentsDir: string, d: Deps): Promise<number>;
|
|
53
|
+
/** A state file's text as the state; none when there is no file or it
|
|
54
|
+
* cannot be read. */
|
|
55
|
+
export declare function parseState(text: string | null): State;
|
|
53
56
|
/** `factory reviewers start|stop`, with the hook's input on stdin. */
|
|
54
57
|
export declare function run(argv: string[]): Promise<number>;
|
package/dist/reviewers.mjs
CHANGED
|
@@ -234,11 +234,28 @@ export async function main(event, input, agentsDir, d) {
|
|
|
234
234
|
catch (error) {
|
|
235
235
|
const why = error instanceof Error ? error.message : String(error);
|
|
236
236
|
d.out(JSON.stringify({
|
|
237
|
-
systemMessage: `The ${reviewer} run was not recorded${issue === null ? "" : ` on
|
|
237
|
+
systemMessage: `The ${reviewer} run was not recorded${issue === null ? "" : ` on ticket ${issue}`}: ${why.split("\n")[0].slice(0, 200)}`,
|
|
238
238
|
}));
|
|
239
239
|
}
|
|
240
240
|
return 0;
|
|
241
241
|
}
|
|
242
|
+
/** A state file's text as the state; none when there is no file or it
|
|
243
|
+
* cannot be read. */
|
|
244
|
+
export function parseState(text) {
|
|
245
|
+
try {
|
|
246
|
+
if (!text)
|
|
247
|
+
return { commentId: null, runs: [] };
|
|
248
|
+
const state = JSON.parse(text);
|
|
249
|
+
// State written before comment IDs were text holds a number.
|
|
250
|
+
return {
|
|
251
|
+
...state,
|
|
252
|
+
commentId: state.commentId === null ? null : String(state.commentId),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
return { commentId: null, runs: [] };
|
|
257
|
+
}
|
|
258
|
+
}
|
|
242
259
|
const statePath = (session, issue) => join(commonDir(), `reviewer-runs-${session}-${issue}.json`);
|
|
243
260
|
/** A lock directory beside the state, since reviewers run in parallel. One
|
|
244
261
|
* older than a minute was left by a hook that died, and is taken over. */
|
|
@@ -293,17 +310,7 @@ export async function run(argv) {
|
|
|
293
310
|
clock: readClock,
|
|
294
311
|
readFile: read,
|
|
295
312
|
state: {
|
|
296
|
-
read: (session, issue) =>
|
|
297
|
-
const text = read(statePath(session, issue));
|
|
298
|
-
try {
|
|
299
|
-
return text
|
|
300
|
-
? JSON.parse(text)
|
|
301
|
-
: { commentId: null, runs: [] };
|
|
302
|
-
}
|
|
303
|
-
catch {
|
|
304
|
-
return { commentId: null, runs: [] };
|
|
305
|
-
}
|
|
306
|
-
},
|
|
313
|
+
read: (session, issue) => parseState(read(statePath(session, issue))),
|
|
307
314
|
write: (session, issue, state) => writeFileSync(statePath(session, issue), JSON.stringify(state)),
|
|
308
315
|
},
|
|
309
316
|
locked,
|
|
@@ -25,16 +25,15 @@ export function githubActionsRunner(o) {
|
|
|
25
25
|
const reviewsOf = async (sha) => (await t.rest("GET", `${API}/actions/workflows/${REVIEW_WORKFLOW}/runs?head_sha=${sha}&per_page=5`)).workflow_runs;
|
|
26
26
|
return {
|
|
27
27
|
async startBuild(ticket, branch) {
|
|
28
|
-
await t.rest("POST", `${API}/actions/workflows/${BUILD_WORKFLOW}/dispatches`, { fields: { ref: branch, inputs: { ticket
|
|
28
|
+
await t.rest("POST", `${API}/actions/workflows/${BUILD_WORKFLOW}/dispatches`, { fields: { ref: branch, inputs: { ticket } } });
|
|
29
29
|
},
|
|
30
|
-
// GitHub answers a dispatch with no run
|
|
31
|
-
//
|
|
32
|
-
// rounded down to one.
|
|
33
|
-
async findBuild(
|
|
30
|
+
// GitHub answers a dispatch with no run, so the run is found by the
|
|
31
|
+
// name the build workflow gives it. GitHub's times are whole seconds, so
|
|
32
|
+
// `since` is rounded down to one.
|
|
33
|
+
async findBuild(runName, since) {
|
|
34
34
|
const from = Math.floor(since / 1000) * 1000;
|
|
35
35
|
const answer = await t.rest("GET", `${API}/actions/workflows/${BUILD_WORKFLOW}/runs?event=workflow_dispatch&per_page=30`);
|
|
36
|
-
const found = answer.workflow_runs.find((r) => r.display_title ===
|
|
37
|
-
Date.parse(r.created_at) >= from);
|
|
36
|
+
const found = answer.workflow_runs.find((r) => r.display_title === runName && Date.parse(r.created_at) >= from);
|
|
38
37
|
return found?.html_url ?? null;
|
|
39
38
|
},
|
|
40
39
|
buildsPage: () => `${SITE}/${o.repository}/actions/workflows/${BUILD_WORKFLOW}`,
|
package/dist/runner/types.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Key } from "../tickets/types.mts";
|
|
1
2
|
/** One run of the repository's jobs for a commit. `status` is `completed`
|
|
2
3
|
* once it has ended, and `conclusion` says how. */
|
|
3
4
|
export type Run = {
|
|
@@ -26,12 +27,12 @@ export type FailedJob = {
|
|
|
26
27
|
log: string;
|
|
27
28
|
};
|
|
28
29
|
export type Runner = {
|
|
29
|
-
/** Starts a build of the ticket on the branch. The runner
|
|
30
|
-
* before the run exists, so `findBuild` finds it. */
|
|
31
|
-
startBuild(ticket:
|
|
32
|
-
/** The page of the
|
|
33
|
-
* milliseconds, or null when none shows yet. */
|
|
34
|
-
findBuild(
|
|
30
|
+
/** Starts a build of the ticket, by its key, on the branch. The runner
|
|
31
|
+
* may answer before the run exists, so `findBuild` finds it. */
|
|
32
|
+
startBuild(ticket: Key, branch: string): Promise<void>;
|
|
33
|
+
/** The page of the build named `runName`, such as `Build #12`, started at
|
|
34
|
+
* or after `since`, in milliseconds, or null when none shows yet. */
|
|
35
|
+
findBuild(runName: string, since: number): Promise<string | null>;
|
|
35
36
|
/** The page that lists builds. */
|
|
36
37
|
buildsPage(): string;
|
|
37
38
|
/** The page of a run, from its ID. */
|
package/dist/status.d.mts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { type Settings, type Target } from "./config.mts";
|
|
3
3
|
import { type Columns, type Watch, type Board, type Derived, type PullRequest, type Issue, type RepoSnapshot, type ReviewerRun } from "./lib/work-status.mts";
|
|
4
|
-
import { type Tickets } from "./tickets/types.mts";
|
|
4
|
+
import { type Key, type Tickets } from "./tickets/types.mts";
|
|
5
5
|
import { type CodeHost } from "./code-host/index.mts";
|
|
6
6
|
import { type Runner } from "./runner/index.mts";
|
|
7
7
|
export type Row = {
|
|
8
|
-
number
|
|
8
|
+
/** A ticket's key, or a pull request's number. */
|
|
9
|
+
key: string;
|
|
10
|
+
/** How it is written: the ticket system's form, or `#N` for a pull
|
|
11
|
+
* request. */
|
|
12
|
+
name: string;
|
|
9
13
|
kind: "issue" | "pull";
|
|
10
14
|
title: string;
|
|
11
15
|
derived: Derived | null;
|
|
@@ -26,17 +30,23 @@ export declare function age(since: string | null, now: Date): string;
|
|
|
26
30
|
export declare function isWatching(body: string, now: Date): boolean;
|
|
27
31
|
/** One row per open issue, and one per open pull request that closes no
|
|
28
32
|
* issue and builds no part of the follow-ups, such as Dependabot's. */
|
|
29
|
-
export declare function toRows(snapshot: RepoSnapshot, board: Board, blockers: Map<
|
|
30
|
-
/** What starts builds from the board, so that a card left in Ready is
|
|
31
|
-
|
|
32
|
-
watch?: Watch | null
|
|
33
|
+
export declare function toRows(snapshot: RepoSnapshot, board: Board, blockers: Map<Key, Key[]>, now: Date, options: {
|
|
34
|
+
/** What starts builds from the board, so that a card left in Ready is
|
|
35
|
+
* worth flagging; null when builds.trigger is manual. */
|
|
36
|
+
watch?: Watch | null;
|
|
37
|
+
columns?: Columns;
|
|
38
|
+
/** The name of the follow-ups ticket's label. */
|
|
39
|
+
followUp?: string;
|
|
40
|
+
/** How the ticket system writes a ticket. */
|
|
41
|
+
ref: (key: Key) => string;
|
|
42
|
+
}): {
|
|
33
43
|
rows: Row[];
|
|
34
44
|
closed: Row[];
|
|
35
45
|
};
|
|
36
46
|
/** Where a ticket's number, a pull request's number, and an Actions run's
|
|
37
47
|
* ID each lead. */
|
|
38
48
|
export type Links = {
|
|
39
|
-
ticket: (
|
|
49
|
+
ticket: (key: Key) => string;
|
|
40
50
|
pull: (n: number) => string;
|
|
41
51
|
run: (id: string) => string;
|
|
42
52
|
};
|
|
@@ -75,6 +85,8 @@ export type Source = {
|
|
|
75
85
|
tickets: Tickets;
|
|
76
86
|
pulls: Pick<CodeHost, "open" | "address">;
|
|
77
87
|
runner: Pick<Runner, "runPage">;
|
|
88
|
+
/** Whether the code host's own links count (`lib/pull-tickets.mts`). */
|
|
89
|
+
own: boolean;
|
|
78
90
|
};
|
|
79
91
|
export type Deps = {
|
|
80
92
|
/** The ticket system and pull requests for the target. */
|
package/dist/status.mjs
CHANGED
|
@@ -11,12 +11,14 @@
|
|
|
11
11
|
// The repository and the board come from the factory's settings, whose
|
|
12
12
|
// loader needs dependencies installed; before npm ci the hook prints
|
|
13
13
|
// nothing.
|
|
14
|
+
import { TICKET_LABELS } from "./labels.mjs";
|
|
14
15
|
import { colorOn, painter } from "./lib/color.mjs";
|
|
15
16
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
16
17
|
import { NO_DEPENDENCIES, SettingsError, loadSettings, targetOf, } from "./config.mjs";
|
|
17
18
|
import { appSessionLink } from "./lib/gh.mjs";
|
|
18
|
-
import { DEFAULT_COLUMNS, cardOf, derive, isNotStarted, watchOf, isStale, isStuck, actionsRunLink,
|
|
19
|
+
import { DEFAULT_COLUMNS, cardOf, derive, isNotStarted, watchOf, isStale, isStuck, actionsRunLink, markedComments, parseRuns, toSnapshot, } from "./lib/work-status.mjs";
|
|
19
20
|
import { boardOf, readAll } from "./tickets/types.mjs";
|
|
21
|
+
import { linkPulls, ownLinks } from "./lib/pull-tickets.mjs";
|
|
20
22
|
import { openTickets } from "./tickets/index.mjs";
|
|
21
23
|
import { openCodeHost } from "./code-host/index.mjs";
|
|
22
24
|
import { openRunner } from "./runner/index.mjs";
|
|
@@ -66,50 +68,52 @@ export function isWatching(body, now) {
|
|
|
66
68
|
}
|
|
67
69
|
/** One row per open issue, and one per open pull request that closes no
|
|
68
70
|
* issue and builds no part of the follow-ups, such as Dependabot's. */
|
|
69
|
-
export function toRows(snapshot, board, blockers, now,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
export function toRows(snapshot, board, blockers, now, options) {
|
|
72
|
+
const watch = options.watch === undefined ? watchOf("own-server", 5) : options.watch;
|
|
73
|
+
const columns = options.columns ?? DEFAULT_COLUMNS;
|
|
74
|
+
const followUp = options.followUp ?? TICKET_LABELS["follow-up"];
|
|
73
75
|
const rows = [];
|
|
74
76
|
const closed = [];
|
|
75
77
|
const claimed = new Set();
|
|
76
78
|
for (const issue of snapshot.issues) {
|
|
77
|
-
const derived = derive(issue, cardOf(board, issue.
|
|
79
|
+
const derived = derive(issue, cardOf(board, issue.key, columns), snapshot.pulls, columns, followUp);
|
|
78
80
|
const pulls = snapshot.pulls.filter((p) => derived.pulls.includes(p.number));
|
|
79
81
|
pulls.forEach((p) => claimed.add(p.number));
|
|
80
82
|
const flags = [];
|
|
81
83
|
if (isStale(derived, now))
|
|
82
84
|
flags.push("stale");
|
|
83
85
|
if (watch &&
|
|
84
|
-
isNotStarted(derived, blockers.get(issue.
|
|
86
|
+
isNotStarted(derived, blockers.get(issue.key) ?? [], now, watch.minutes))
|
|
85
87
|
flags.push(watch.flag);
|
|
86
88
|
const row = {
|
|
87
|
-
|
|
89
|
+
key: issue.key,
|
|
90
|
+
name: options.ref(issue.key),
|
|
88
91
|
kind: "issue",
|
|
89
92
|
title: issue.title,
|
|
90
93
|
derived,
|
|
91
94
|
pulls,
|
|
92
95
|
runs: cardRuns(issue, derived),
|
|
93
96
|
flags,
|
|
94
|
-
cost: board.items.get(issue.
|
|
97
|
+
cost: board.items.get(issue.key)?.cost ?? null,
|
|
95
98
|
};
|
|
96
99
|
(derived.status === "Done" ? closed : rows).push(row);
|
|
97
100
|
}
|
|
98
101
|
for (const pull of snapshot.pulls) {
|
|
99
102
|
if (claimed.has(pull.number))
|
|
100
103
|
continue;
|
|
101
|
-
const followUps = snapshot.issues.filter((i) => i.labels.includes(
|
|
104
|
+
const followUps = snapshot.issues.filter((i) => i.labels.includes(followUp) && pull.partOf.includes(i.key));
|
|
102
105
|
if (pull.closes.length > 0 || followUps.length > 0)
|
|
103
106
|
continue;
|
|
104
107
|
rows.push({
|
|
105
|
-
|
|
108
|
+
key: String(pull.number),
|
|
109
|
+
name: `#${pull.number}`,
|
|
106
110
|
kind: "pull",
|
|
107
111
|
title: `pull request by ${pull.author}`,
|
|
108
112
|
derived: null,
|
|
109
113
|
pulls: [pull],
|
|
110
114
|
runs: [],
|
|
111
115
|
flags: [],
|
|
112
|
-
cost:
|
|
116
|
+
cost: null,
|
|
113
117
|
});
|
|
114
118
|
}
|
|
115
119
|
return { rows, closed };
|
|
@@ -133,7 +137,9 @@ const INDENT = " ";
|
|
|
133
137
|
const GAP = " ";
|
|
134
138
|
const MIN_TITLE = 20;
|
|
135
139
|
const HEADER = ["#", "Title", "Time in status", "Cost", "Session"];
|
|
136
|
-
const linkTo = (
|
|
140
|
+
const linkTo = (row, style) => row.kind === "issue"
|
|
141
|
+
? style.links?.ticket(row.key)
|
|
142
|
+
: style.links?.pull(Number(row.key));
|
|
137
143
|
const width = (segs) => segs.reduce((n, s) => n + [...s.text].length, 0);
|
|
138
144
|
function paint(text, style, ...codes) {
|
|
139
145
|
if (!style.color || codes.length === 0)
|
|
@@ -189,7 +195,10 @@ function pullLine(pull, now, named, style) {
|
|
|
189
195
|
return named
|
|
190
196
|
? [
|
|
191
197
|
{ text: "↳ Pull request " },
|
|
192
|
-
{
|
|
198
|
+
{
|
|
199
|
+
text: `#${pull.number}`,
|
|
200
|
+
url: linkTo({ kind: "pull", key: String(pull.number) }, style),
|
|
201
|
+
},
|
|
193
202
|
{ text: ` · ${rest}` },
|
|
194
203
|
]
|
|
195
204
|
: [{ text: `↳ ${rest}` }];
|
|
@@ -259,10 +268,10 @@ export function formatRows({ rows, closed }, now, withClosed = true, style = PLA
|
|
|
259
268
|
lines.push("Nothing open.");
|
|
260
269
|
else {
|
|
261
270
|
const cells = rows.map((row) => {
|
|
262
|
-
const url = linkTo(row
|
|
271
|
+
const url = linkTo(row, style);
|
|
263
272
|
return {
|
|
264
273
|
row,
|
|
265
|
-
number:
|
|
274
|
+
number: row.name,
|
|
266
275
|
url,
|
|
267
276
|
time: age(row.derived?.since ?? null, now),
|
|
268
277
|
// Read from the board, never summed here, so it matches the card.
|
|
@@ -359,8 +368,8 @@ export function formatRows({ rows, closed }, now, withClosed = true, style = PLA
|
|
|
359
368
|
lines.push("", `${paint("Closed in the last 24 hours:", style, "dim")} ${closed
|
|
360
369
|
.map((r) => paint(render([
|
|
361
370
|
{
|
|
362
|
-
text:
|
|
363
|
-
url: linkTo(
|
|
371
|
+
text: r.name,
|
|
372
|
+
url: linkTo(r, style),
|
|
364
373
|
},
|
|
365
374
|
], style), style, "blueBright"))
|
|
366
375
|
.join(", ")}`);
|
|
@@ -384,17 +393,22 @@ async function snapshotLines(source, target, now, hook, style = PLAIN) {
|
|
|
384
393
|
readAll(source.tickets, { board: target.board !== null }),
|
|
385
394
|
source.pulls.open({ checks: true }),
|
|
386
395
|
]);
|
|
387
|
-
const snapshot = toSnapshot(tickets, pulls, now);
|
|
396
|
+
const snapshot = toSnapshot(tickets, linkPulls(pulls, source.tickets, source.own), now);
|
|
388
397
|
const board = boardOf(tickets);
|
|
389
398
|
const blockers = new Map();
|
|
390
399
|
for (const issue of snapshot.issues) {
|
|
391
400
|
if (!source.tickets.blockers ||
|
|
392
|
-
derive(issue, cardOf(board, issue.
|
|
401
|
+
derive(issue, cardOf(board, issue.key, target.columns), snapshot.pulls, target.columns, target.followUp).status !== "Ready")
|
|
393
402
|
continue;
|
|
394
|
-
const list = await source.tickets.blockers.list(issue.
|
|
395
|
-
blockers.set(issue.
|
|
403
|
+
const list = await source.tickets.blockers.list(issue.key);
|
|
404
|
+
blockers.set(issue.key, list.filter((b) => b.state === "open").map((b) => b.key));
|
|
396
405
|
}
|
|
397
|
-
return formatRows(toRows(snapshot, board, blockers, now,
|
|
406
|
+
return formatRows(toRows(snapshot, board, blockers, now, {
|
|
407
|
+
watch: target.watch,
|
|
408
|
+
columns: target.columns,
|
|
409
|
+
followUp: target.followUp,
|
|
410
|
+
ref: (k) => source.tickets.ref(k),
|
|
411
|
+
}), now, !hook, { ...style, links, columns: target.columns });
|
|
398
412
|
}
|
|
399
413
|
const WATCH_MS = 15_000;
|
|
400
414
|
// The alternate screen with the cursor hidden, and back.
|
|
@@ -484,6 +498,7 @@ export async function run(argv) {
|
|
|
484
498
|
tickets,
|
|
485
499
|
pulls: openCodeHost(target.repository, settings.codeHost.type),
|
|
486
500
|
runner: openRunner(target.repository, settings.builds.runner),
|
|
501
|
+
own: ownLinks(settings),
|
|
487
502
|
};
|
|
488
503
|
},
|
|
489
504
|
now: () => new Date(),
|
package/dist/sync.d.mts
CHANGED
|
@@ -16,6 +16,14 @@ export declare function withSchedule(text: string, minutes: number, file: string
|
|
|
16
16
|
/** A workflow with the one `branches:` line of its push trigger naming the
|
|
17
17
|
* default branch and nothing else. */
|
|
18
18
|
export declare function withDefaultBranch(text: string, name: string, file: string): string;
|
|
19
|
+
/** The verdict workflow starting on the override by the name the settings
|
|
20
|
+
* give it, written only when it is not the default, in single quotes as
|
|
21
|
+
* GitHub's expressions take text. */
|
|
22
|
+
export declare function withOverride(text: string, name: string, file: string): string;
|
|
23
|
+
/** The build workflow with its run named as the ticket system writes the
|
|
24
|
+
* ticket, such as `Build #12` on GitHub, which `factory build` finds the
|
|
25
|
+
* run by. */
|
|
26
|
+
export declare function withRunName(text: string, ref: (key: string) => string, file: string): string;
|
|
19
27
|
/** A session workflow with the minutes its session may run, and its job 10
|
|
20
28
|
* more, so the steps after the session still run before the job is
|
|
21
29
|
* stopped. */
|
package/dist/sync.mjs
CHANGED
|
@@ -14,11 +14,13 @@
|
|
|
14
14
|
// the rules' numbers, and the default branch's name in the push triggers.
|
|
15
15
|
// Edit the source in the package, never the copy. A file the lock lists that the package no longer has is
|
|
16
16
|
// deleted. Nothing else is.
|
|
17
|
+
import { PR_LABELS } from "./labels.mjs";
|
|
17
18
|
import { colorOn, painter, plain } from "./lib/color.mjs";
|
|
18
19
|
import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync, } from "node:fs";
|
|
19
20
|
import { dirname, join, relative, sep } from "node:path";
|
|
20
21
|
import { fileURLToPath } from "node:url";
|
|
21
22
|
import { firstRefusal, npmrcAt } from "./npmrc.mjs";
|
|
23
|
+
import { refOf } from "./tickets/index.mjs";
|
|
22
24
|
import { filesDeps, repoRoot, resolveFiles, RULE_NUMBERS, staleOf, defaultDeps, } from "./config.mjs";
|
|
23
25
|
import { CHOICES_FILE, choicesText, settingsHash, staleChoices, } from "./preset.mjs";
|
|
24
26
|
import { branchDeps, CANNOT_TELL, defaultBranch, } from "./lib/default-branch.mjs";
|
|
@@ -75,6 +77,29 @@ export function withDefaultBranch(text, name, file) {
|
|
|
75
77
|
: JSON.stringify(name);
|
|
76
78
|
return text.replace(pattern, (_, lead) => `${lead}[${written}]`);
|
|
77
79
|
}
|
|
80
|
+
const BUILD_WORKFLOW = "workflows/factory-build.yml";
|
|
81
|
+
const VERDICT_WORKFLOW = "workflows/factory-review-verdict.yml";
|
|
82
|
+
/** The verdict workflow starting on the override by the name the settings
|
|
83
|
+
* give it, written only when it is not the default, in single quotes as
|
|
84
|
+
* GitHub's expressions take text. */
|
|
85
|
+
export function withOverride(text, name, file) {
|
|
86
|
+
const fallback = PR_LABELS["verdict-override"];
|
|
87
|
+
if (name === fallback)
|
|
88
|
+
return text;
|
|
89
|
+
const line = `github.event.label.name == '${fallback}'`;
|
|
90
|
+
if (text.split(line).length !== 2)
|
|
91
|
+
throw new Error(`${file}: expected one match for ${line}, to set the override's name`);
|
|
92
|
+
return text.replace(line, () => `github.event.label.name == '${name.replace(/'/g, "''")}'`);
|
|
93
|
+
}
|
|
94
|
+
/** The build workflow with its run named as the ticket system writes the
|
|
95
|
+
* ticket, such as `Build #12` on GitHub, which `factory build` finds the
|
|
96
|
+
* run by. */
|
|
97
|
+
export function withRunName(text, ref, file) {
|
|
98
|
+
const pattern = /^run-name: .*$/gm;
|
|
99
|
+
if ((text.match(pattern) ?? []).length !== 1)
|
|
100
|
+
throw new Error(`${file}: expected one run-name line, to name the build`);
|
|
101
|
+
return text.replace(pattern, () => `run-name: ${JSON.stringify(`Build ${ref("${{ inputs.ticket }}")}`)}`);
|
|
102
|
+
}
|
|
78
103
|
/** The workflows that run a Claude session, by the kind of session each
|
|
79
104
|
* runs. */
|
|
80
105
|
const SESSION_WORKFLOWS = {
|
|
@@ -511,7 +536,11 @@ export async function plan(pkg, root, r, branch) {
|
|
|
511
536
|
const source = readFileSync(join(pkg, from), "utf8");
|
|
512
537
|
const text = PUSH_WORKFLOWS.includes(from)
|
|
513
538
|
? withDefaultBranch(source, branch, from)
|
|
514
|
-
:
|
|
539
|
+
: from === BUILD_WORKFLOW
|
|
540
|
+
? withRunName(source, refOf(s.tickets.type), from)
|
|
541
|
+
: from === VERDICT_WORKFLOW
|
|
542
|
+
? withOverride(source, s.codeHost.labels["verdict-override"], from)
|
|
543
|
+
: source;
|
|
515
544
|
const kind = SESSION_WORKFLOWS[from.replace(/^workflows\//, "")];
|
|
516
545
|
const written = kind && from.startsWith("workflows/")
|
|
517
546
|
? withMinutes(text, s.sessionMinutes[kind], from)
|
package/dist/ticket-fields.d.mts
CHANGED
|
@@ -38,8 +38,10 @@ export declare function split(body: string, mapping: FieldMapping): {
|
|
|
38
38
|
error: string;
|
|
39
39
|
};
|
|
40
40
|
/** A ticket's document: its description with each ticket field's text under
|
|
41
|
-
* its key's heading, before the first later heading the description has.
|
|
42
|
-
|
|
41
|
+
* its key's heading, before the first later heading the description has.
|
|
42
|
+
* `specLabel` is the name of the label that puts a ticket on the spec
|
|
43
|
+
* track. */
|
|
44
|
+
export declare function join(description: string, values: Record<string, string>, mapping: FieldMapping, labels: readonly string[], specLabel?: string): string;
|
|
43
45
|
/** The agent's answer for a factory field no ticket field fits. A token,
|
|
44
46
|
* so a ticket field called "Description" stays usable. */
|
|
45
47
|
export declare const DESCRIPTION = "__description__";
|
package/dist/ticket-fields.mjs
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// Refinement's factory fields in a ticket's own fields: which heading each
|
|
2
|
+
// key names, and how a ticket's document is split into its description and
|
|
3
|
+
// its ticket fields and joined back, and `init`'s field step, which asks the
|
|
4
|
+
// coding agent where each goes. It names no agent and no ticket system.
|
|
5
|
+
import { TICKET_LABELS } from "./labels.mjs";
|
|
1
6
|
import { listed } from "./lib/listed.mjs";
|
|
2
7
|
/** The factory fields a refined ticket has, in the order its body has them. */
|
|
3
8
|
export const FACTORY_FIELDS = [
|
|
@@ -131,8 +136,10 @@ const ORDER = [
|
|
|
131
136
|
"for-the-builder",
|
|
132
137
|
];
|
|
133
138
|
/** A ticket's document: its description with each ticket field's text under
|
|
134
|
-
* its key's heading, before the first later heading the description has.
|
|
135
|
-
|
|
139
|
+
* its key's heading, before the first later heading the description has.
|
|
140
|
+
* `specLabel` is the name of the label that puts a ticket on the spec
|
|
141
|
+
* track. */
|
|
142
|
+
export function join(description, values, mapping, labels, specLabel = TICKET_LABELS.spec) {
|
|
136
143
|
const order = [
|
|
137
144
|
...Object.keys(mapping).filter((k) => !ORDER.includes(k)),
|
|
138
145
|
...ORDER,
|
|
@@ -141,7 +148,7 @@ export function join(description, values, mapping, labels) {
|
|
|
141
148
|
const shared = pairs.filter(([k]) => SHARED.includes(k)).length === 2 &&
|
|
142
149
|
mapping.spec === mapping["acceptance-criteria"];
|
|
143
150
|
const reads = shared
|
|
144
|
-
? labels.includes(
|
|
151
|
+
? labels.includes(specLabel)
|
|
145
152
|
? "spec"
|
|
146
153
|
: "acceptance-criteria"
|
|
147
154
|
: null;
|