@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
package/dist/lib/work-status.mjs
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
// Who is working on what, read from the marker comments sessions post on a
|
|
2
|
+
// ticket and from the board's Status. The terminal view
|
|
3
|
+
// (`factory status`), the board sync (`factory board`), and the
|
|
4
|
+
// poller (`factory poller`) all decide from this one module, so they
|
|
5
|
+
// cannot disagree. It reads tickets as the ticket interface returns them
|
|
6
|
+
// (`tickets/types.mts`) and never calls a ticket system itself.
|
|
7
|
+
import { TICKET_LABELS } from "../labels.mjs";
|
|
1
8
|
export const AGENT_MARK = "<!-- agent -->";
|
|
2
9
|
export const STATUSES = [
|
|
3
10
|
"Backlog",
|
|
@@ -126,19 +133,13 @@ export function parseCosts(comment) {
|
|
|
126
133
|
return match ? [Number(match[1])] : [];
|
|
127
134
|
});
|
|
128
135
|
}
|
|
129
|
-
/** Whether a pull request's body says it builds this issue, as "Closes #N"
|
|
130
|
-
* or "Part of #N". */
|
|
131
|
-
export function buildsIssue(body, number) {
|
|
132
|
-
return new RegExp(`\\b(?:closes|part of) #${number}(?!\\d)`, "i").test(body);
|
|
133
|
-
}
|
|
134
136
|
/** The issue's Cost: every cost marker on it and on each pull request, open,
|
|
135
137
|
* merged, or closed, that builds it, to the cent. Null when there are none. */
|
|
136
138
|
export function issueCost(issue, pulls) {
|
|
137
139
|
const comments = [
|
|
138
140
|
...issue.comments,
|
|
139
141
|
...pulls
|
|
140
|
-
.filter((pull) => pull.closes.includes(issue.
|
|
141
|
-
buildsIssue(pull.body, issue.number))
|
|
142
|
+
.filter((pull) => pull.closes.includes(issue.key) || pull.partOf.includes(issue.key))
|
|
142
143
|
.flatMap((pull) => pull.comments ?? []),
|
|
143
144
|
];
|
|
144
145
|
const costs = comments.flatMap((c) => parseCosts(c));
|
|
@@ -181,10 +182,10 @@ export function parseRuns(comment) {
|
|
|
181
182
|
export const STUCK_AFTER_MS = 2 * 60 * 60 * 1000;
|
|
182
183
|
export const isStuck = (run, now) => run.result === "running" &&
|
|
183
184
|
now.getTime() - Date.parse(run.start) > STUCK_AFTER_MS;
|
|
185
|
+
// Comments with the same time keep the order the ticket system returned
|
|
186
|
+
// them in: the sort is stable, and their IDs are opaque.
|
|
184
187
|
function byTime(a, b) {
|
|
185
|
-
|
|
186
|
-
const bt = Date.parse(b.createdAt);
|
|
187
|
-
return at !== bt ? at - bt : a.id - b.id;
|
|
188
|
+
return Date.parse(a.createdAt) - Date.parse(b.createdAt);
|
|
188
189
|
}
|
|
189
190
|
export function markedComments(comments) {
|
|
190
191
|
return [...comments]
|
|
@@ -221,17 +222,12 @@ export function workState(comments) {
|
|
|
221
222
|
}
|
|
222
223
|
return { live, lastLive, start };
|
|
223
224
|
}
|
|
224
|
-
/**
|
|
225
|
-
*
|
|
226
|
-
* it
|
|
227
|
-
export function
|
|
228
|
-
return
|
|
229
|
-
|
|
230
|
-
/** The pull requests that put this issue In review. */
|
|
231
|
-
export function reviewingPulls(issue, pulls) {
|
|
232
|
-
return pulls.filter((pull) => pull.closes.includes(issue.number) ||
|
|
233
|
-
(issue.labels.includes("follow-up") &&
|
|
234
|
-
buildsPartOf(pull.body, issue.number)));
|
|
225
|
+
/** The pull requests that put this issue In review: those that close it,
|
|
226
|
+
* and on the follow-ups ticket, labeled `followUp`, those that build part
|
|
227
|
+
* of it. */
|
|
228
|
+
export function reviewingPulls(issue, pulls, followUp = TICKET_LABELS["follow-up"]) {
|
|
229
|
+
return pulls.filter((pull) => pull.closes.includes(issue.key) ||
|
|
230
|
+
(issue.labels.includes(followUp) && pull.partOf.includes(issue.key)));
|
|
235
231
|
}
|
|
236
232
|
const READY_RESETS = new Set([
|
|
237
233
|
"released",
|
|
@@ -269,7 +265,7 @@ function claimSession(claim) {
|
|
|
269
265
|
}
|
|
270
266
|
/** An issue's Status is the first rule that applies: Done, In review,
|
|
271
267
|
* In progress, Ready, In refinement, Backlog. */
|
|
272
|
-
export function derive(issue, card, pulls, columns = DEFAULT_COLUMNS) {
|
|
268
|
+
export function derive(issue, card, pulls, columns = DEFAULT_COLUMNS, followUp = TICKET_LABELS["follow-up"]) {
|
|
273
269
|
const work = workState(issue.comments);
|
|
274
270
|
const marked = markedComments(issue.comments);
|
|
275
271
|
if (issue.state === "closed") {
|
|
@@ -280,7 +276,7 @@ export function derive(issue, card, pulls, columns = DEFAULT_COLUMNS) {
|
|
|
280
276
|
pulls: [],
|
|
281
277
|
};
|
|
282
278
|
}
|
|
283
|
-
const reviewing = reviewingPulls(issue, pulls);
|
|
279
|
+
const reviewing = reviewingPulls(issue, pulls, followUp);
|
|
284
280
|
if (reviewing.length > 0) {
|
|
285
281
|
const first = [...reviewing].sort((a, b) => a.createdAt.localeCompare(b.createdAt))[0];
|
|
286
282
|
return {
|
|
@@ -409,8 +405,9 @@ export function isNotStarted(derived, openBlockers, now, minutes = 5) {
|
|
|
409
405
|
}
|
|
410
406
|
/** A claim or start over 24 hours old with no pull request, which the
|
|
411
407
|
* nightly sync clears. Null when there is nothing to clear. */
|
|
412
|
-
export function toClear(issue, pulls, now) {
|
|
413
|
-
if (issue.state !== "open" ||
|
|
408
|
+
export function toClear(issue, pulls, now, followUp = TICKET_LABELS["follow-up"]) {
|
|
409
|
+
if (issue.state !== "open" ||
|
|
410
|
+
reviewingPulls(issue, pulls, followUp).length > 0)
|
|
414
411
|
return null;
|
|
415
412
|
const work = workState(issue.comments);
|
|
416
413
|
const old = (m) => m !== null && now.getTime() - Date.parse(m.createdAt) > 24 * HOUR;
|
|
@@ -443,7 +440,7 @@ const waiting = (columns) => `The card stays ${cardAt("In progress", columns)},
|
|
|
443
440
|
const again = (issue, columns) => {
|
|
444
441
|
const ready = columns.Ready?.[0] ?? null;
|
|
445
442
|
if (ready === null)
|
|
446
|
-
return `To try again, tell a session to build
|
|
443
|
+
return `To try again, tell a session to build ${issue.ref}, or run \`factory build ${issue.key}\`.`;
|
|
447
444
|
return `Move it to ${ready} to try again.`;
|
|
448
445
|
};
|
|
449
446
|
export function commentBody(c, columns = DEFAULT_COLUMNS) {
|
|
@@ -461,8 +458,8 @@ export function commentBody(c, columns = DEFAULT_COLUMNS) {
|
|
|
461
458
|
return mark("waiting", withCost("Refinement is waiting on you: the questions are in the comment above.", c.cost));
|
|
462
459
|
case "refined": {
|
|
463
460
|
const sentence = ready === null
|
|
464
|
-
? `Refinement is done. This board has no column for approving a build: tell a session to build
|
|
465
|
-
: `Refinement is done. The card stays ${cardAt("In refinement", columns)} until it moves to ${ready}, which starts a build in GitHub Actions: move it there, or ask this session to. To build it on your machine instead, tell a local session to work
|
|
461
|
+
? `Refinement is done. This board has no column for approving a build: tell a session to build ${c.issue.ref}, or run \`factory build ${c.issue.key}\`.`
|
|
462
|
+
: `Refinement is done. The card stays ${cardAt("In refinement", columns)} until it moves to ${ready}, which starts a build in GitHub Actions: move it there, or ask this session to. To build it on your machine instead, tell a local session to work ${c.issue.ref}.`;
|
|
466
463
|
const before = c.before?.trimEnd();
|
|
467
464
|
const lead = [before, c.cost].filter(Boolean).join("\n\n");
|
|
468
465
|
return mark("refined", lead ? `${lead}\n\n${sentence}` : sentence);
|
|
@@ -476,8 +473,8 @@ export function commentBody(c, columns = DEFAULT_COLUMNS) {
|
|
|
476
473
|
case "stopped": {
|
|
477
474
|
const head = `Stopped without a pull request: ${c.reason}. ${WAITING}`;
|
|
478
475
|
const tail = c.where === "actions"
|
|
479
|
-
? `Run \`factory build ${c.issue}\` to try again${ready === null ? "." : `, or move it to ${ready}.`}`
|
|
480
|
-
: `Tell a session to work
|
|
476
|
+
? `Run \`factory build ${c.issue.key}\` to try again${ready === null ? "." : `, or move it to ${ready}.`}`
|
|
477
|
+
: `Tell a session to work ${c.issue.ref} again${ready === null ? "." : `, or move it to ${ready} to build it in GitHub Actions.`}`;
|
|
481
478
|
return mark("released", withCost(`${head} ${tail}`, c.cost));
|
|
482
479
|
}
|
|
483
480
|
case "ended":
|
|
@@ -490,7 +487,7 @@ export function commentBody(c, columns = DEFAULT_COLUMNS) {
|
|
|
490
487
|
return mark("partial", `Pull request #${c.pull} merged part of these follow-ups. The unchecked lines wait for the next build; the card is back in ${columnFor("Backlog", columns)}.`);
|
|
491
488
|
case "pull-closed":
|
|
492
489
|
return mark("released", ready === null
|
|
493
|
-
? `Pull request #${c.pull} was closed without merging. ${WAITING} Tell a session to build
|
|
490
|
+
? `Pull request #${c.pull} was closed without merging. ${WAITING} Tell a session to build ${c.issue.ref}, or run \`factory build ${c.issue.key}\`, to rebuild it, or ask a session to refine it first.`
|
|
494
491
|
: `Pull request #${c.pull} was closed without merging. ${WAITING} Move it to ${ready} to rebuild it, or ask a session to refine it first.`);
|
|
495
492
|
}
|
|
496
493
|
}
|
|
@@ -510,8 +507,8 @@ export function toSnapshot(tickets, pulls, now, donePulls = []) {
|
|
|
510
507
|
/** A ticket's card, its column read as the state that column shows. A
|
|
511
508
|
* card with no Status has none; one in a column no state names is
|
|
512
509
|
* "Unmapped". */
|
|
513
|
-
export const cardOf = (board,
|
|
514
|
-
const item = board.items.get(
|
|
510
|
+
export const cardOf = (board, key, columns = DEFAULT_COLUMNS) => {
|
|
511
|
+
const item = board.items.get(key);
|
|
515
512
|
if (!item)
|
|
516
513
|
return null;
|
|
517
514
|
const status = item.status === null
|
package/dist/merge-policy.d.mts
CHANGED
|
@@ -12,10 +12,10 @@ export declare const inGithubNames: (files: {
|
|
|
12
12
|
previousPath?: string;
|
|
13
13
|
status: string;
|
|
14
14
|
}[]) => ChangedFile[];
|
|
15
|
-
/** The two merge labels. The merge-policy workflow applies one
|
|
16
|
-
* other; only
|
|
17
|
-
export declare const AUTOMATIC = "merge
|
|
18
|
-
export declare const MANUAL = "merge
|
|
15
|
+
/** The keys of the two merge labels. The merge-policy workflow applies one
|
|
16
|
+
* and removes the other; only the automatic one turns auto-merge on. */
|
|
17
|
+
export declare const AUTOMATIC = "merge-automatic";
|
|
18
|
+
export declare const MANUAL = "merge-manual";
|
|
19
19
|
export type Risk = {
|
|
20
20
|
risk: typeof AUTOMATIC | typeof MANUAL;
|
|
21
21
|
reasons: string[];
|
|
@@ -53,9 +53,11 @@ export declare function decide(paths: Risk, commandHolds: string[]): Risk;
|
|
|
53
53
|
/** The description of the "Who merges" commit status: what happens, and why,
|
|
54
54
|
* on one line. GitHub cuts a status description at 140 characters. */
|
|
55
55
|
export declare function statusLine({ risk, reasons }: Risk): string;
|
|
56
|
-
/** What the merge-policy workflow needs: the label to set
|
|
57
|
-
* whether auto-merge goes on,
|
|
58
|
-
|
|
56
|
+
/** What the merge-policy workflow needs: the label to set and the one to
|
|
57
|
+
* remove, each by the name `names` gives it, whether auto-merge goes on,
|
|
58
|
+
* and the status line. */
|
|
59
|
+
export declare function workflowOutput(result: Risk, names: Readonly<Record<typeof AUTOMATIC | typeof MANUAL, string>>): {
|
|
60
|
+
label: string;
|
|
59
61
|
other: string;
|
|
60
62
|
automatic: boolean;
|
|
61
63
|
status: string;
|
package/dist/merge-policy.mjs
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
//
|
|
4
4
|
// npx --no-install factory merge-policy PR_NUMBER # prints the labels to set
|
|
5
5
|
//
|
|
6
|
-
// "merge
|
|
6
|
+
// "merge-automatic" only when no changed file is one of the factory's own,
|
|
7
7
|
// none matches auto-merge.deny in .claude/factory.yaml, every one matches
|
|
8
8
|
// auto-merge.allow, and every command under auto-merge.commands exits 0;
|
|
9
|
-
// "merge
|
|
9
|
+
// "merge-manual" otherwise. The merge-policy workflow runs this from main's copy,
|
|
10
10
|
// with main's settings, so a pull request cannot change how it is judged.
|
|
11
11
|
import { spawnSync } from "node:child_process";
|
|
12
12
|
import { loadSettings } from "./config.mjs";
|
|
@@ -19,10 +19,10 @@ export const inGithubNames = (files) => files.map(({ path, previousPath, status
|
|
|
19
19
|
previous_filename: previousPath,
|
|
20
20
|
status,
|
|
21
21
|
}));
|
|
22
|
-
/** The two merge labels. The merge-policy workflow applies one
|
|
23
|
-
* other; only
|
|
24
|
-
export const AUTOMATIC = "merge
|
|
25
|
-
export const MANUAL = "merge
|
|
22
|
+
/** The keys of the two merge labels. The merge-policy workflow applies one
|
|
23
|
+
* and removes the other; only the automatic one turns auto-merge on. */
|
|
24
|
+
export const AUTOMATIC = "merge-automatic";
|
|
25
|
+
export const MANUAL = "merge-manual";
|
|
26
26
|
/** The factory's own files, held whatever the settings allow: a pull request
|
|
27
27
|
* must not be able to change how pull requests are judged. Every spec tool's
|
|
28
28
|
* process files are among them, whichever the settings name, since a pull
|
|
@@ -99,13 +99,15 @@ export function statusLine({ risk, reasons }) {
|
|
|
99
99
|
const line = `Waits for the owner: ${first}${more}`;
|
|
100
100
|
return line.length > 140 ? `${line.slice(0, 139)}…` : line;
|
|
101
101
|
}
|
|
102
|
-
/** What the merge-policy workflow needs: the label to set
|
|
103
|
-
* whether auto-merge goes on,
|
|
104
|
-
|
|
102
|
+
/** What the merge-policy workflow needs: the label to set and the one to
|
|
103
|
+
* remove, each by the name `names` gives it, whether auto-merge goes on,
|
|
104
|
+
* and the status line. */
|
|
105
|
+
export function workflowOutput(result, names) {
|
|
105
106
|
const automatic = result.risk === AUTOMATIC;
|
|
106
107
|
return {
|
|
107
108
|
...result,
|
|
108
|
-
|
|
109
|
+
label: names[result.risk],
|
|
110
|
+
other: names[automatic ? MANUAL : AUTOMATIC],
|
|
109
111
|
automatic,
|
|
110
112
|
status: statusLine(result),
|
|
111
113
|
};
|
|
@@ -137,7 +139,7 @@ async function main(argv) {
|
|
|
137
139
|
// The pull request as it is now, not as the event described it: an event
|
|
138
140
|
// sent just after a push can carry the previous commit and draft state.
|
|
139
141
|
console.log(JSON.stringify({
|
|
140
|
-
...workflowOutput(decide(paths, holds)),
|
|
142
|
+
...workflowOutput(decide(paths, holds), settings.codeHost.labels),
|
|
141
143
|
sha: pull.head.sha,
|
|
142
144
|
draft: pull.isDraft,
|
|
143
145
|
}));
|
package/dist/poller.d.mts
CHANGED
|
@@ -3,10 +3,10 @@ import { type Settings } from "./config.mts";
|
|
|
3
3
|
import { type Columns, type Board, type RepoSnapshot } from "./lib/work-status.mts";
|
|
4
4
|
import type { CodeHost } from "./code-host/types.mts";
|
|
5
5
|
import type { Runner } from "./runner/types.mts";
|
|
6
|
-
import { type Tickets } from "./tickets/types.mts";
|
|
6
|
+
import { type Key, type Tickets } from "./tickets/types.mts";
|
|
7
7
|
export declare const FIRE_LIMIT = 20;
|
|
8
|
-
/** The open issues the shared derivation puts in Ready,
|
|
9
|
-
export declare function selectToStart(snapshot: RepoSnapshot, board: Board, columns?: Columns):
|
|
8
|
+
/** The open issues the shared derivation puts in Ready, in key order. */
|
|
9
|
+
export declare function selectToStart(snapshot: RepoSnapshot, board: Board, columns?: Columns, followUp?: string): Key[];
|
|
10
10
|
export declare function startMarker(): string;
|
|
11
11
|
/** The columns the poller reads a board by. It runs with no settings file,
|
|
12
12
|
* so it is told the one name it needs, the column that approves a build:
|
|
@@ -67,6 +67,8 @@ export declare function tick(d: Deps, state: State): Promise<void>;
|
|
|
67
67
|
export type OnceSettings = {
|
|
68
68
|
board: number | null;
|
|
69
69
|
ready: string | null;
|
|
70
|
+
/** The name of the follow-ups ticket's label. */
|
|
71
|
+
followUp: string;
|
|
70
72
|
};
|
|
71
73
|
export declare function onceSettings(s: Settings): OnceSettings;
|
|
72
74
|
/** One pass, for a scheduled run: the board and the Ready column come from
|
package/dist/poller.mjs
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
// It names its implementations itself, having no settings to name them:
|
|
21
21
|
// the GitHub ticket adapter, GitHub as the code host, and GitHub Actions as
|
|
22
22
|
// the runner, each over the `fetch` transport, since it runs with no `gh`.
|
|
23
|
+
import { TICKET_LABELS } from "./labels.mjs";
|
|
23
24
|
import { randomBytes } from "node:crypto";
|
|
24
25
|
import { columnsOf, loadSettings } from "./config.mjs";
|
|
25
26
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
@@ -29,18 +30,19 @@ import { githubCodeHost } from "./code-host/github.mjs";
|
|
|
29
30
|
import { BUILD_WORKFLOW, githubActionsRunner, } from "./runner/github-actions.mjs";
|
|
30
31
|
import { githubTickets } from "./tickets/github.mjs";
|
|
31
32
|
import { HttpError, fetchTransport, statusOf } from "./tickets/transport.mjs";
|
|
32
|
-
import { boardOf } from "./tickets/types.mjs";
|
|
33
|
+
import { boardOf, compareKeys, } from "./tickets/types.mjs";
|
|
34
|
+
import { linkPulls } from "./lib/pull-tickets.mjs";
|
|
33
35
|
const MINUTE = 60_000;
|
|
34
36
|
const HOUR = 60 * MINUTE;
|
|
35
37
|
export const FIRE_LIMIT = 20;
|
|
36
38
|
const FIRE_TIMEOUT_MS = 30_000;
|
|
37
|
-
/** The open issues the shared derivation puts in Ready,
|
|
38
|
-
export function selectToStart(snapshot, board, columns = DEFAULT_COLUMNS) {
|
|
39
|
+
/** The open issues the shared derivation puts in Ready, in key order. */
|
|
40
|
+
export function selectToStart(snapshot, board, columns = DEFAULT_COLUMNS, followUp = TICKET_LABELS["follow-up"]) {
|
|
39
41
|
return snapshot.issues
|
|
40
42
|
.filter((issue) => issue.state === "open" &&
|
|
41
|
-
derive(issue, cardOf(board, issue.
|
|
42
|
-
.map((issue) => issue.
|
|
43
|
-
.sort(
|
|
43
|
+
derive(issue, cardOf(board, issue.key, columns), snapshot.pulls, columns, followUp).status === "Ready")
|
|
44
|
+
.map((issue) => issue.key)
|
|
45
|
+
.sort(compareKeys);
|
|
44
46
|
}
|
|
45
47
|
export function startMarker() {
|
|
46
48
|
return `st_${randomBytes(6).toString("hex")}`;
|
|
@@ -128,8 +130,10 @@ async function readAll(tickets, codeHost, d) {
|
|
|
128
130
|
tickets.readAll({ board: true }),
|
|
129
131
|
codeHost.open(),
|
|
130
132
|
]);
|
|
133
|
+
// The poller reaches GitHub alone, so the code host's links are the
|
|
134
|
+
// tickets' own.
|
|
131
135
|
return {
|
|
132
|
-
snapshot: toSnapshot(read, open, new Date(d.now())),
|
|
136
|
+
snapshot: toSnapshot(read, linkPulls(open, tickets, true), new Date(d.now())),
|
|
133
137
|
board: boardOf(read),
|
|
134
138
|
};
|
|
135
139
|
}
|
|
@@ -174,7 +178,7 @@ export async function tick(d, state) {
|
|
|
174
178
|
}
|
|
175
179
|
}
|
|
176
180
|
const columns = columnsFrom(d.env);
|
|
177
|
-
const ready = selectToStart(read.snapshot, read.board, columns);
|
|
181
|
+
const ready = selectToStart(read.snapshot, read.board, columns, d.env.FACTORY_FOLLOW_UP_LABEL?.trim() || TICKET_LABELS["follow-up"]);
|
|
178
182
|
// This pass's own start comments are not in what it read, so it adds them.
|
|
179
183
|
const fired = recentStarts(read.snapshot.issues, d.now());
|
|
180
184
|
if (d.now() - state.lastHeartbeat >= HOUR) {
|
|
@@ -182,20 +186,21 @@ export async function tick(d, state) {
|
|
|
182
186
|
state.lastHeartbeat = d.now();
|
|
183
187
|
}
|
|
184
188
|
for (const issue of ready) {
|
|
189
|
+
const ref = tickets.ref(issue);
|
|
185
190
|
try {
|
|
186
191
|
const blockers = await tickets.blockers.list(issue);
|
|
187
192
|
const open = blockers.filter((b) => b.state === "open");
|
|
188
193
|
if (open.length) {
|
|
189
|
-
d.log(
|
|
194
|
+
d.log(`${ref} waits on ${open.map((b) => tickets.ref(b.key)).join(", ")}`);
|
|
190
195
|
continue;
|
|
191
196
|
}
|
|
192
197
|
}
|
|
193
198
|
catch (error) {
|
|
194
|
-
d.log(
|
|
199
|
+
d.log(`${ref} skipped: its blockers could not be read (${String(error)})`);
|
|
195
200
|
continue;
|
|
196
201
|
}
|
|
197
202
|
if (!capAllows(fired, d.now())) {
|
|
198
|
-
d.log(
|
|
203
|
+
d.log(`${ref} waits: ${FIRE_LIMIT} builds started in the last hour`);
|
|
199
204
|
continue;
|
|
200
205
|
}
|
|
201
206
|
const marker = d.marker();
|
|
@@ -203,31 +208,35 @@ export async function tick(d, state) {
|
|
|
203
208
|
await tickets.comment(issue, commentBody({ kind: "started", marker }, columns));
|
|
204
209
|
}
|
|
205
210
|
catch (error) {
|
|
206
|
-
d.log(
|
|
211
|
+
d.log(`${ref} not started: the start comment failed (${String(error)})`);
|
|
207
212
|
continue;
|
|
208
213
|
}
|
|
209
214
|
fired.push(d.now());
|
|
210
215
|
const outcome = await dispatch(runner, d.defaultBranch, issue);
|
|
211
216
|
if (outcome.ok) {
|
|
212
|
-
d.log(
|
|
217
|
+
d.log(`${ref} started ${marker}: dispatched ${BUILD_WORKFLOW}`);
|
|
213
218
|
continue;
|
|
214
219
|
}
|
|
215
|
-
d.log(
|
|
220
|
+
d.log(`${ref} dispatch failed: ${outcome.status} (${outcome.reason})`);
|
|
216
221
|
try {
|
|
217
222
|
await tickets.comment(issue, commentBody({
|
|
218
223
|
kind: "dispatch-failed",
|
|
219
|
-
issue,
|
|
224
|
+
issue: { key: issue, ref },
|
|
220
225
|
status: outcome.status,
|
|
221
226
|
reason: outcome.reason,
|
|
222
227
|
}, columns));
|
|
223
228
|
}
|
|
224
229
|
catch (error) {
|
|
225
|
-
d.log(
|
|
230
|
+
d.log(`${ref} dispatch-failure comment failed (${String(error)})`);
|
|
226
231
|
}
|
|
227
232
|
}
|
|
228
233
|
}
|
|
229
234
|
export function onceSettings(s) {
|
|
230
|
-
return {
|
|
235
|
+
return {
|
|
236
|
+
board: s.tickets.board,
|
|
237
|
+
ready: columnsOf(s).Ready?.[0] ?? null,
|
|
238
|
+
followUp: s.tickets.labels["follow-up"],
|
|
239
|
+
};
|
|
231
240
|
}
|
|
232
241
|
/** One pass, for a scheduled run: the board and the Ready column come from
|
|
233
242
|
* the settings, the board's owner is the repository's, and only the token
|
|
@@ -246,6 +255,7 @@ export async function once(s, d) {
|
|
|
246
255
|
FACTORY_BOARD_OWNER: d.repository.split("/")[0],
|
|
247
256
|
FACTORY_BOARD_NUMBER: String(s.board),
|
|
248
257
|
FACTORY_READY_COLUMN: s.ready,
|
|
258
|
+
FACTORY_FOLLOW_UP_LABEL: s.followUp,
|
|
249
259
|
};
|
|
250
260
|
const state = { failuresInARow: 0, lastHeartbeat: d.now() };
|
|
251
261
|
await tick({ ...d, env }, state);
|
package/dist/pr.d.mts
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import { type Check } from "./pr-watch.mts";
|
|
3
3
|
import { type CodeHost, type Pull, type PullComment, type Review, type Thread } from "./code-host/index.mts";
|
|
4
4
|
import { type Run, type Runner } from "./runner/index.mts";
|
|
5
|
+
import { type Labels } from "./labels.mts";
|
|
6
|
+
import type { Tickets } from "./tickets/types.mts";
|
|
7
|
+
import { type CostDeps } from "./ticket.mts";
|
|
5
8
|
export type Deps = {
|
|
6
9
|
/** The repository, as owner/name, from the factory's settings. */
|
|
7
10
|
repository: string;
|
|
@@ -15,7 +18,23 @@ export type Deps = {
|
|
|
15
18
|
now?: () => number;
|
|
16
19
|
/** For GITHUB_ACTIONS, which says GraphQL is open without asking. */
|
|
17
20
|
env?: Record<string, string | undefined>;
|
|
21
|
+
/** The settings' ticket system, and whether the code host's own links
|
|
22
|
+
* count (`lib/pull-tickets.mts`), for `closes`. */
|
|
23
|
+
tickets?: () => Promise<{
|
|
24
|
+
tickets: Tickets;
|
|
25
|
+
own: boolean;
|
|
26
|
+
}>;
|
|
27
|
+
/** The session's cost clock, for `cost`. */
|
|
28
|
+
cost?: CostDeps;
|
|
29
|
+
/** The name of each label the factory puts on pull requests, for
|
|
30
|
+
* `label`; the defaults without it. */
|
|
31
|
+
labels?: () => Promise<Labels["codeHost"]>;
|
|
18
32
|
};
|
|
33
|
+
/** The tickets a pull request builds, as the factory counts them. */
|
|
34
|
+
export declare function pullTickets(d: Deps, pr: number): Promise<{
|
|
35
|
+
tickets: Tickets;
|
|
36
|
+
links: import("./tickets/types.mts").Links;
|
|
37
|
+
}>;
|
|
19
38
|
export declare function withAgentMark(body: string): string;
|
|
20
39
|
export type Report = {
|
|
21
40
|
pull: Pull;
|
|
@@ -65,3 +84,6 @@ export declare function conflicting(p: CodeHost, sleepFor: (ms: number) => Promi
|
|
|
65
84
|
export declare function main(argv: string[], d: Deps): Promise<number>;
|
|
66
85
|
/** `factory pr ...`. */
|
|
67
86
|
export declare function run(argv: string[]): Promise<number>;
|
|
87
|
+
/** What `run` gives `main`, for the repository and the code host and
|
|
88
|
+
* runner named. */
|
|
89
|
+
export declare function prDeps(repository: string, codeHost: string, runner: string): Deps;
|
package/dist/pr.mjs
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
// npx --no-install factory pr reply N COMMENT_ID --body-file FILE
|
|
7
7
|
// npx --no-install factory pr resolve N COMMENT_ID
|
|
8
8
|
// npx --no-install factory pr ready N # refuses an unverified commit when git signs
|
|
9
|
-
// npx --no-install factory pr closes N #
|
|
9
|
+
// npx --no-install factory pr closes N # the tickets the pull request closes, by key
|
|
10
|
+
// npx --no-install factory pr cost N # notes this session's cost on the pull request
|
|
10
11
|
// npx --no-install factory pr wait-checks N # every check on HEAD
|
|
11
12
|
// npx --no-install factory pr review-pending N REVIEW # exits 0 when an approver's review needs an answer
|
|
12
13
|
// npx --no-install factory pr conflicts # the pull requests the conflict sweep takes
|
|
@@ -24,13 +25,30 @@
|
|
|
24
25
|
import { execFileSync } from "node:child_process";
|
|
25
26
|
import { readFileSync } from "node:fs";
|
|
26
27
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
27
|
-
import { reachOf } from "./config.mjs";
|
|
28
|
-
import {
|
|
28
|
+
import { loadSettings, reachOf } from "./config.mjs";
|
|
29
|
+
import { openTickets } from "./tickets/index.mjs";
|
|
30
|
+
import { ownLinks, ticketsOf } from "./lib/pull-tickets.mjs";
|
|
31
|
+
import { readClock, writeClock } from "./lib/clock.mjs";
|
|
32
|
+
import { measureSession, projectsDir } from "./lib/usage.mjs";
|
|
33
|
+
import { AGENT_MARK, commentBody } from "./lib/work-status.mjs";
|
|
29
34
|
import { changedLines, parseLcov, uncovered } from "./patch-coverage.mjs";
|
|
30
35
|
import { toChecks } from "./pr-watch.mjs";
|
|
31
36
|
import { openCodeHost, } from "./code-host/index.mjs";
|
|
32
37
|
import { openRunner } from "./runner/index.mjs";
|
|
33
38
|
import { refuseBareTags, refuseOverride } from "./guard-ticket-text.mjs";
|
|
39
|
+
import { labelOf, PR_LABELS } from "./labels.mjs";
|
|
40
|
+
import { takeCost } from "./ticket.mjs";
|
|
41
|
+
/** The tickets a pull request builds, as the factory counts them. */
|
|
42
|
+
export async function pullTickets(d, pr) {
|
|
43
|
+
if (!d.tickets)
|
|
44
|
+
throw new Error("No ticket system to read links with.");
|
|
45
|
+
const { tickets, own } = await d.tickets();
|
|
46
|
+
const pull = await d.codeHost.get(pr);
|
|
47
|
+
return {
|
|
48
|
+
tickets,
|
|
49
|
+
links: ticketsOf({ body: pull.body, closes: own ? await d.codeHost.closes(pr) : [] }, tickets, own),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
34
52
|
export function withAgentMark(body) {
|
|
35
53
|
return body.includes(AGENT_MARK)
|
|
36
54
|
? body
|
|
@@ -225,7 +243,7 @@ const FIELDS = {
|
|
|
225
243
|
};
|
|
226
244
|
/** How many lines of a failed job's log `failed` prints, from its end. */
|
|
227
245
|
const LOG_TAIL = 200;
|
|
228
|
-
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 | for-branch BRANCH | wait-checks N | comments N [--author LOGIN] [--contains TEXT] [--from-approvers] [--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`;
|
|
246
|
+
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 | cost N | for-branch BRANCH | wait-checks N | comments N [--author LOGIN] [--contains TEXT] [--from-approvers] [--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`;
|
|
229
247
|
function option(args, name) {
|
|
230
248
|
const at = args.indexOf(name);
|
|
231
249
|
if (at === -1)
|
|
@@ -394,7 +412,18 @@ export async function main(argv, d) {
|
|
|
394
412
|
const [pr] = numbers;
|
|
395
413
|
if (!pr)
|
|
396
414
|
throw new Error(USAGE);
|
|
397
|
-
d.out((await
|
|
415
|
+
d.out((await pullTickets(d, pr)).links.closes.join(" "));
|
|
416
|
+
return 0;
|
|
417
|
+
}
|
|
418
|
+
case "cost": {
|
|
419
|
+
const [pr] = numbers;
|
|
420
|
+
if (!pr || !d.cost)
|
|
421
|
+
throw new Error(USAGE);
|
|
422
|
+
// Read first: a number that is no pull request leaves the clock.
|
|
423
|
+
await p.get(pr);
|
|
424
|
+
const note = takeCost(`#${pr}`, d.cost);
|
|
425
|
+
await p.comment(pr, commentBody({ kind: "cost", cost: note }));
|
|
426
|
+
d.out("posted");
|
|
398
427
|
return 0;
|
|
399
428
|
}
|
|
400
429
|
case "wait-checks": {
|
|
@@ -471,12 +500,13 @@ export async function main(argv, d) {
|
|
|
471
500
|
pr <= 0 ||
|
|
472
501
|
(add === undefined) === (remove === undefined))
|
|
473
502
|
throw new Error(USAGE);
|
|
503
|
+
const names = d.labels ? await d.labels() : PR_LABELS;
|
|
474
504
|
if (add !== undefined) {
|
|
475
|
-
refuseOverride(add);
|
|
476
|
-
await p.addLabel(pr, add);
|
|
505
|
+
refuseOverride(add, names["verdict-override"]);
|
|
506
|
+
await p.addLabel(pr, labelOf(names, add));
|
|
477
507
|
}
|
|
478
508
|
else
|
|
479
|
-
await p.removeLabel(pr, remove);
|
|
509
|
+
await p.removeLabel(pr, labelOf(names, remove));
|
|
480
510
|
d.out(add !== undefined ? "added" : "removed");
|
|
481
511
|
return 0;
|
|
482
512
|
}
|
|
@@ -609,7 +639,12 @@ export async function main(argv, d) {
|
|
|
609
639
|
/** `factory pr ...`. */
|
|
610
640
|
export async function run(argv) {
|
|
611
641
|
const { repository, codeHost, runner } = await reachOf(process.env);
|
|
612
|
-
return main(argv,
|
|
642
|
+
return main(argv, prDeps(repository, codeHost, runner));
|
|
643
|
+
}
|
|
644
|
+
/** What `run` gives `main`, for the repository and the code host and
|
|
645
|
+
* runner named. */
|
|
646
|
+
export function prDeps(repository, codeHost, runner) {
|
|
647
|
+
return {
|
|
613
648
|
repository,
|
|
614
649
|
codeHost: openCodeHost(repository, codeHost),
|
|
615
650
|
runner: openRunner(repository, runner),
|
|
@@ -624,5 +659,20 @@ export async function run(argv) {
|
|
|
624
659
|
stdio: ["ignore", "pipe", "pipe"],
|
|
625
660
|
}),
|
|
626
661
|
env: process.env,
|
|
627
|
-
|
|
662
|
+
tickets: async () => {
|
|
663
|
+
const settings = await loadSettings();
|
|
664
|
+
const { tickets } = await openTickets(settings, {
|
|
665
|
+
repository,
|
|
666
|
+
board: null,
|
|
667
|
+
});
|
|
668
|
+
return { tickets, own: ownLinks(settings) };
|
|
669
|
+
},
|
|
670
|
+
labels: async () => (await loadSettings()).codeHost.labels,
|
|
671
|
+
cost: {
|
|
672
|
+
env: process.env,
|
|
673
|
+
now: () => new Date(),
|
|
674
|
+
clock: { read: readClock, write: writeClock },
|
|
675
|
+
measure: (session, since) => measureSession(projectsDir(process.env), session, since),
|
|
676
|
+
},
|
|
677
|
+
};
|
|
628
678
|
}
|
package/dist/remove.mjs
CHANGED
|
@@ -9,17 +9,10 @@ import { parseSettings, repoRoot, SETTINGS_FILE, } from "./config.mjs";
|
|
|
9
9
|
import { hasCommand, noTerminal } from "./lib/has-command.mjs";
|
|
10
10
|
import { listed } from "./lib/listed.mjs";
|
|
11
11
|
import { SIGNING_KEY } from "./parts.mjs";
|
|
12
|
-
import {
|
|
12
|
+
import { DEFAULT_LABELS } from "./labels.mjs";
|
|
13
13
|
import { LOCK, PACKAGE } from "./sync.mjs";
|
|
14
14
|
import { CHOICES_FILE } from "./preset.mjs";
|
|
15
15
|
import { builtOf, inUse, TOOLS } from "./tools.mjs";
|
|
16
|
-
const LABELS = [
|
|
17
|
-
"merge: automatic",
|
|
18
|
-
"merge: manual",
|
|
19
|
-
OVERRIDE,
|
|
20
|
-
"follow-up",
|
|
21
|
-
"spec",
|
|
22
|
-
];
|
|
23
16
|
/** The agents and skills the lock lists that presets shipped, a skill as
|
|
24
17
|
* its folder, and the packages of the presets it records. */
|
|
25
18
|
async function presetParts(root) {
|
|
@@ -49,6 +42,20 @@ async function presetParts(root) {
|
|
|
49
42
|
packages: [...new Set(lock.presets.map((p) => splitName(p.name).pkg))],
|
|
50
43
|
};
|
|
51
44
|
}
|
|
45
|
+
/** The labels the factory adds, by the names the settings give them: the
|
|
46
|
+
* pull request labels, then the ticket labels. */
|
|
47
|
+
function labelsOf(settings) {
|
|
48
|
+
const { codeHost, tickets } = settings
|
|
49
|
+
? { codeHost: settings.codeHost.labels, tickets: settings.tickets.labels }
|
|
50
|
+
: DEFAULT_LABELS;
|
|
51
|
+
return [
|
|
52
|
+
codeHost["merge-automatic"],
|
|
53
|
+
codeHost["merge-manual"],
|
|
54
|
+
codeHost["verdict-override"],
|
|
55
|
+
tickets["follow-up"],
|
|
56
|
+
tickets.spec,
|
|
57
|
+
];
|
|
58
|
+
}
|
|
52
59
|
/** The factory's own files and folders, each a path from the root. */
|
|
53
60
|
function factoryFiles(root) {
|
|
54
61
|
const named = (dir, match) => existsSync(join(root, dir))
|
|
@@ -151,7 +158,7 @@ export async function main(_argv, d) {
|
|
|
151
158
|
...(secrets === null || secrets.includes(SIGNING_KEY)
|
|
152
159
|
? [`Delete the secret ${SIGNING_KEY}${secrets === null ? " if set" : ""}`]
|
|
153
160
|
: []),
|
|
154
|
-
`Delete whichever of the labels ${listed(
|
|
161
|
+
`Delete whichever of the labels ${listed(labelsOf(settings))} exist, if you do not want their history: deleting one takes it off every ticket`,
|
|
155
162
|
`Run npm uninstall ${d.packageName}`,
|
|
156
163
|
...shipped.packages.map((p) => `Run npm uninstall ${p}`),
|
|
157
164
|
"Commit this on a branch, open a pull request, and merge it",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Links, type Tickets } from "./tickets/types.mts";
|
|
2
|
+
export type Deps = {
|
|
3
|
+
/** The tickets pull request N builds, as `factory pr closes` reads them. */
|
|
4
|
+
pull: (pr: number) => Promise<{
|
|
5
|
+
tickets: Tickets;
|
|
6
|
+
links: Links;
|
|
7
|
+
}>;
|
|
8
|
+
out: (line: string) => void;
|
|
9
|
+
};
|
|
10
|
+
export declare function main(argv: string[], d: Deps): Promise<number>;
|
|
11
|
+
/** `factory review tickets N`. */
|
|
12
|
+
export declare function run(argv: string[]): Promise<number>;
|