@operad-io/dev 0.1.0 → 0.2.0
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 +1 -1
- package/dev.schema.json +41 -28
- package/package.json +9 -6
- package/skills/setup/SKILL.md +57 -0
- package/src/access-grants.ts +59 -0
- package/src/actions.ts +78 -17
- package/src/announce.ts +128 -16
- package/src/chat.ts +512 -36
- package/src/check-host.ts +111 -0
- package/src/check-load.ts +67 -0
- package/src/check.ts +17 -12
- package/src/clock.ts +29 -0
- package/src/commands.ts +103 -34
- package/src/create-actions.ts +210 -0
- package/src/flaky.ts +45 -29
- package/src/flow-compiler.ts +155 -68
- package/src/followups.ts +20 -22
- package/src/gate.ts +192 -73
- package/src/git.ts +47 -0
- package/src/index.ts +46 -6
- package/src/integrate.ts +121 -43
- package/src/integration-queue.ts +176 -25
- package/src/lock.ts +101 -5
- package/src/mainclone.ts +44 -5
- package/src/model-error.ts +70 -0
- package/src/model.ts +50 -35
- package/src/notcode.ts +51 -15
- package/src/places.ts +2 -2
- package/src/prepare.ts +7 -2
- package/src/project-flows.ts +135 -4
- package/src/project-settings.ts +81 -0
- package/src/register-requests.ts +87 -0
- package/src/repository-key.ts +4 -0
- package/src/rerun.ts +23 -7
- package/src/retry.ts +2 -12
- package/src/rework.ts +8 -0
- package/src/schedule.ts +317 -86
- package/src/service.ts +177 -148
- package/src/settings.ts +305 -60
- package/src/standing.ts +23 -6
- package/src/step-edge.ts +22 -0
- package/src/steps.ts +469 -123
- package/src/throughput.ts +4 -21
- package/src/timeouts.ts +10 -2
- package/src/views.ts +147 -81
- package/src/waits.ts +59 -0
package/src/gate.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
writeFileSync,
|
|
19
19
|
} from "node:fs";
|
|
20
20
|
import { dirname, join, resolve } from "node:path";
|
|
21
|
+
import { checkEnvironment } from "./check-host.ts";
|
|
21
22
|
import { checkPlaces } from "./places.ts";
|
|
22
23
|
import { runPrepare, stepOptions } from "./prepare.ts";
|
|
23
24
|
import { runCheckCommands } from "./rerun.ts";
|
|
@@ -30,7 +31,7 @@ import {
|
|
|
30
31
|
strictestFixLevel,
|
|
31
32
|
type Grading,
|
|
32
33
|
} from "@operad-io/review-grading";
|
|
33
|
-
import { isRecord, messageOf, type PluginStepResult, type StepContext
|
|
34
|
+
import { isRecord, messageOf, type PluginStepResult, type StepContext } from "@operad-io/engine";
|
|
34
35
|
import { appendRework, DevError, type PendingReviewRun, type ReviewFinding, type ReviewNote, type ReviewNotes, type ReviewRecord, type ReviewResult, type ReviewRunRecord, type ReviewRunReason, type ReviewRunRole, type ReworkRecord, type TaskAttempt, type TaskData, type VerifyRecord, type VerifyResult } from "./model.ts";
|
|
35
36
|
import {
|
|
36
37
|
assertInsideRepository,
|
|
@@ -43,12 +44,14 @@ import {
|
|
|
43
44
|
} from "./settings.ts";
|
|
44
45
|
import { reviewWaitKind } from "./waits.ts";
|
|
45
46
|
import { appendChange } from "./model.ts";
|
|
47
|
+
import { reviewTestHooks } from "./clock.ts";
|
|
48
|
+
export { reviewTestHooks };
|
|
49
|
+
import { modelErrorIn, modelWaitsForPerson, type ModelErrorInfo } from "./model-error.ts";
|
|
50
|
+
import { commitOf, git } from "./git.ts";
|
|
46
51
|
import {
|
|
47
52
|
briefText,
|
|
48
53
|
cancelledStep,
|
|
49
54
|
claimAllows,
|
|
50
|
-
git,
|
|
51
|
-
headOf,
|
|
52
55
|
isRegistered,
|
|
53
56
|
saveTaskGuarded,
|
|
54
57
|
taskContext,
|
|
@@ -57,7 +60,6 @@ import {
|
|
|
57
60
|
} from "./steps.ts";
|
|
58
61
|
import {
|
|
59
62
|
addedLinesOf,
|
|
60
|
-
filePatches,
|
|
61
63
|
incrementOf,
|
|
62
64
|
type Increment,
|
|
63
65
|
fixedCount,
|
|
@@ -67,6 +69,7 @@ import {
|
|
|
67
69
|
reviewSettingsOf,
|
|
68
70
|
previousLine,
|
|
69
71
|
previousReview,
|
|
72
|
+
severityRank,
|
|
70
73
|
type LineMap,
|
|
71
74
|
type PreviousFinding,
|
|
72
75
|
type ReviewHistoryEntry,
|
|
@@ -96,20 +99,9 @@ export function branchHead(
|
|
|
96
99
|
workName: string,
|
|
97
100
|
): string | undefined {
|
|
98
101
|
const branch = workBranch(workName);
|
|
99
|
-
const local =
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
"--quiet",
|
|
103
|
-
`${branch}^{commit}`,
|
|
104
|
-
]);
|
|
105
|
-
if (local.ok && local.out.length > 0) return local.out;
|
|
106
|
-
const remote = git(repositoryPath, [
|
|
107
|
-
"rev-parse",
|
|
108
|
-
"--verify",
|
|
109
|
-
"--quiet",
|
|
110
|
-
`refs/remotes/${settings.remote}/${branch}^{commit}`,
|
|
111
|
-
]);
|
|
112
|
-
return remote.ok && remote.out.length > 0 ? remote.out : undefined;
|
|
102
|
+
const local = commitOf(repositoryPath, branch);
|
|
103
|
+
if (local !== undefined) return local;
|
|
104
|
+
return commitOf(repositoryPath, `refs/remotes/${settings.remote}/${branch}`);
|
|
113
105
|
}
|
|
114
106
|
|
|
115
107
|
/** The commit the task branched from: the merge base of main and the commit. */
|
|
@@ -310,6 +302,7 @@ export async function runVerify(
|
|
|
310
302
|
...(context.settings.gate.stallSecs === undefined
|
|
311
303
|
? {}
|
|
312
304
|
: { stallSecs: context.settings.gate.stallSecs }),
|
|
305
|
+
env: checkEnvironment(ctx.settings),
|
|
313
306
|
},
|
|
314
307
|
commands,
|
|
315
308
|
stepOptions(ctx, path),
|
|
@@ -320,6 +313,7 @@ export async function runVerify(
|
|
|
320
313
|
flakyLimit: context.settings.check.flakyLoadLimit,
|
|
321
314
|
signal: ctx.signal,
|
|
322
315
|
log: (text) => ctx.logger.write(text),
|
|
316
|
+
logPath: ctx.logger.path,
|
|
323
317
|
});
|
|
324
318
|
if (steady.cancelled === true) return cancelledStep();
|
|
325
319
|
const { checked } = steady;
|
|
@@ -433,6 +427,8 @@ interface FileDiff {
|
|
|
433
427
|
/** Why the file is left out of the prompt, or undefined when it is in it. */
|
|
434
428
|
readonly leftOut: string | undefined;
|
|
435
429
|
readonly binary: boolean;
|
|
430
|
+
/** True when the task deletes the whole file. */
|
|
431
|
+
readonly deleted: boolean;
|
|
436
432
|
}
|
|
437
433
|
|
|
438
434
|
interface Attributes {
|
|
@@ -608,6 +604,7 @@ function diffsOf(
|
|
|
608
604
|
bytes: Buffer.byteLength(patch, "utf8"),
|
|
609
605
|
leftOut: undefined,
|
|
610
606
|
binary,
|
|
607
|
+
deleted: change?.status === "deleted",
|
|
611
608
|
});
|
|
612
609
|
}
|
|
613
610
|
return files;
|
|
@@ -708,13 +705,6 @@ export function leftOutLine(file: FileDiff): string {
|
|
|
708
705
|
return `- ${file.path} (+${file.added}/-${file.removed}) — ${file.leftOut ?? "left out"}`;
|
|
709
706
|
}
|
|
710
707
|
|
|
711
|
-
function severityRank(severity: string): number {
|
|
712
|
-
if (severity === "critical") return 3;
|
|
713
|
-
if (severity === "major") return 2;
|
|
714
|
-
if (severity === "minor") return 1;
|
|
715
|
-
return 0;
|
|
716
|
-
}
|
|
717
|
-
|
|
718
708
|
function levelRank(level: FixLevel): number {
|
|
719
709
|
return severityRank(level);
|
|
720
710
|
}
|
|
@@ -723,6 +713,70 @@ function atOrAbove(severity: string, level: FixLevel): boolean {
|
|
|
723
713
|
return severityRank(severity) >= levelRank(level);
|
|
724
714
|
}
|
|
725
715
|
|
|
716
|
+
/** The line `dev/work` writes into the worker's answer for a main-checkout change. */
|
|
717
|
+
const MAIN_CHECKOUT_CHANGE = "changed the main checkout:";
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* The paths an attempt's work changed outside its worktree, read from the line
|
|
721
|
+
* the work step wrote into the worker's answer (T-0646).
|
|
722
|
+
*/
|
|
723
|
+
function mainCheckoutChanges(attempt: TaskAttempt): readonly string[] {
|
|
724
|
+
const message = attempt.finalMessage;
|
|
725
|
+
if (typeof message !== "string") return [];
|
|
726
|
+
const paths: string[] = [];
|
|
727
|
+
for (const line of message.split("\n")) {
|
|
728
|
+
const said = line.trim();
|
|
729
|
+
if (!said.startsWith(`${MAIN_CHECKOUT_CHANGE} `)) continue;
|
|
730
|
+
for (const path of said.slice(MAIN_CHECKOUT_CHANGE.length + 1).split(", ")) {
|
|
731
|
+
const named = path.trim();
|
|
732
|
+
if (named.length > 0 && !paths.includes(named)) paths.push(named);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
return paths;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* The major findings dev adds itself for an attempt whose work changed the main
|
|
740
|
+
* checkout: one per named file that no report already blocks on. They are
|
|
741
|
+
* added whatever the reviewer reported, so such an attempt carries the major
|
|
742
|
+
* finding without asking the reviewer for it; the work must make those changes
|
|
743
|
+
* in its own worktree instead.
|
|
744
|
+
*/
|
|
745
|
+
function mainCheckoutFindings(
|
|
746
|
+
paths: readonly string[],
|
|
747
|
+
reported: readonly ReviewFinding[],
|
|
748
|
+
): ReviewFinding[] {
|
|
749
|
+
const blocked = new Set(
|
|
750
|
+
reported
|
|
751
|
+
.filter(
|
|
752
|
+
(finding) =>
|
|
753
|
+
finding.preExisting !== true &&
|
|
754
|
+
finding.pre_existing !== true &&
|
|
755
|
+
atOrAbove(finding.severity, "major"),
|
|
756
|
+
)
|
|
757
|
+
.map((finding) => normalizePath(finding.file)),
|
|
758
|
+
);
|
|
759
|
+
return paths
|
|
760
|
+
.filter((path) => !blocked.has(normalizePath(path)))
|
|
761
|
+
.map((path) => ({
|
|
762
|
+
file: path,
|
|
763
|
+
line: 0,
|
|
764
|
+
severity: "major",
|
|
765
|
+
summary: "the work changed this file in the main checkout",
|
|
766
|
+
trigger: "the work must make this change in its own worktree instead",
|
|
767
|
+
}));
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
/** The counted findings of a failed review, as the task's history and brief show them. */
|
|
771
|
+
function describeFindings(findings: readonly ReviewFinding[]): string {
|
|
772
|
+
return findings
|
|
773
|
+
.map(
|
|
774
|
+
(finding) =>
|
|
775
|
+
`${finding.file}:${finding.line} ${finding.severity}: ${finding.summary}`,
|
|
776
|
+
)
|
|
777
|
+
.join("; ");
|
|
778
|
+
}
|
|
779
|
+
|
|
726
780
|
interface FindingShape {
|
|
727
781
|
readonly file: string;
|
|
728
782
|
readonly line: number;
|
|
@@ -885,12 +939,22 @@ function reviewPrompt(
|
|
|
885
939
|
prepare: readonly string[] = [],
|
|
886
940
|
rework?: ReworkPrompt,
|
|
887
941
|
checks: readonly string[] = [],
|
|
942
|
+
mainCheckout: readonly string[] = [],
|
|
888
943
|
): string {
|
|
889
944
|
const pieces: string[] = [
|
|
890
945
|
`Review the changes of task ${task.title}.`,
|
|
891
946
|
"## Brief",
|
|
892
947
|
briefText(task).trim(),
|
|
893
948
|
];
|
|
949
|
+
if (mainCheckout.length > 0) {
|
|
950
|
+
pieces.push(
|
|
951
|
+
"## The main checkout",
|
|
952
|
+
[
|
|
953
|
+
`The work of this attempt left this line in its answer: \`${MAIN_CHECKOUT_CHANGE} ${mainCheckout.join(", ")}\`. It means the work changed files outside its worktree, in the main checkout, and must make those changes in its own worktree instead.`,
|
|
954
|
+
"This is a major finding: report it as a major finding on each of those files.",
|
|
955
|
+
].join("\n"),
|
|
956
|
+
);
|
|
957
|
+
}
|
|
894
958
|
const graded = gradingLines(grading);
|
|
895
959
|
if (graded.length > 0) pieces.push("## Grading", graded.join("\n"));
|
|
896
960
|
if (rework !== undefined) {
|
|
@@ -924,6 +988,25 @@ function reviewPrompt(
|
|
|
924
988
|
prepared.included.map((file) => file.patch).join(""),
|
|
925
989
|
);
|
|
926
990
|
}
|
|
991
|
+
const deleted = prepared.files.filter((file) => file.deleted);
|
|
992
|
+
if (deleted.length > 0) {
|
|
993
|
+
if (rework === undefined) {
|
|
994
|
+
pieces.push(
|
|
995
|
+
"## Deleted files",
|
|
996
|
+
`A file this change deletes whole is listed by name with its line count, not by its removed lines. Read it from the base commit with \`git show ${base}:<path>\`.`,
|
|
997
|
+
);
|
|
998
|
+
} else {
|
|
999
|
+
// The increment holds hunks, and a whole deletion has none: list the
|
|
1000
|
+
// deleted files so a rework round still learns what went.
|
|
1001
|
+
pieces.push(
|
|
1002
|
+
"## Deleted files",
|
|
1003
|
+
[
|
|
1004
|
+
`These files are deleted whole. Each is listed by name with its line count, not by its removed lines; read one from the base commit with \`git show ${base}:<path>\`:`,
|
|
1005
|
+
...deleted.map((file) => `- ${file.path} (${file.removed} lines)`),
|
|
1006
|
+
].join("\n"),
|
|
1007
|
+
);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
927
1010
|
if (prepared.leftOut.length > 0) {
|
|
928
1011
|
pieces.push(
|
|
929
1012
|
"## Files left out of the diff",
|
|
@@ -977,6 +1060,8 @@ interface ReviewerCall {
|
|
|
977
1060
|
| "failed";
|
|
978
1061
|
readonly report?: Report | undefined;
|
|
979
1062
|
readonly message: string;
|
|
1063
|
+
/** What the model error said, when the run ended on one. */
|
|
1064
|
+
readonly modelError?: ModelErrorInfo | undefined;
|
|
980
1065
|
}
|
|
981
1066
|
|
|
982
1067
|
/** The largest review report the gate reads; anything bigger is not a report. */
|
|
@@ -1144,6 +1229,7 @@ function writeReviewOutcome(path: string, call: ReviewerCall): void {
|
|
|
1144
1229
|
outcome: call.outcome,
|
|
1145
1230
|
message: call.message,
|
|
1146
1231
|
...(call.report === undefined ? {} : { report: call.report }),
|
|
1232
|
+
...(call.modelError === undefined ? {} : { modelError: call.modelError }),
|
|
1147
1233
|
}),
|
|
1148
1234
|
);
|
|
1149
1235
|
} catch {
|
|
@@ -1180,8 +1266,13 @@ function readReviewOutcome(resultPath: string): ReviewerCall | undefined {
|
|
|
1180
1266
|
return undefined;
|
|
1181
1267
|
}
|
|
1182
1268
|
const message = typeof value.message === "string" ? value.message : "";
|
|
1269
|
+
const modelError = modelErrorIn(value);
|
|
1183
1270
|
if (outcome !== "report") {
|
|
1184
|
-
return {
|
|
1271
|
+
return {
|
|
1272
|
+
outcome: outcome as ReviewerCall["outcome"],
|
|
1273
|
+
message,
|
|
1274
|
+
...(modelError === undefined ? {} : { modelError }),
|
|
1275
|
+
};
|
|
1185
1276
|
}
|
|
1186
1277
|
const report = parseReport(JSON.stringify(value.report));
|
|
1187
1278
|
if (report === undefined) return undefined;
|
|
@@ -1447,7 +1538,12 @@ async function callReviewerOnce(
|
|
|
1447
1538
|
: `the reviewer ended "${outcome.result}"`;
|
|
1448
1539
|
const kind = failureOutcome(data, message);
|
|
1449
1540
|
if (kind === "timed_out" || kind === "unavailable") {
|
|
1450
|
-
|
|
1541
|
+
const modelError = modelErrorIn(data);
|
|
1542
|
+
return {
|
|
1543
|
+
outcome: kind,
|
|
1544
|
+
message,
|
|
1545
|
+
...(modelError === undefined ? {} : { modelError }),
|
|
1546
|
+
};
|
|
1451
1547
|
}
|
|
1452
1548
|
}
|
|
1453
1549
|
return { outcome: "no_report", message: lastMessageOf(outcome) };
|
|
@@ -1653,27 +1749,6 @@ function reviewMessage(
|
|
|
1653
1749
|
return parts.join("; ");
|
|
1654
1750
|
}
|
|
1655
1751
|
|
|
1656
|
-
/** Test-only hooks: a child process crashes at a named point in a review. */
|
|
1657
|
-
export const reviewTestHooks: {
|
|
1658
|
-
now?: (() => number) | undefined;
|
|
1659
|
-
/** Waits instead of the real timer, so a test can move the clock. */
|
|
1660
|
-
wait?:
|
|
1661
|
-
| ((ms: number, signal: AbortSignal | undefined) => Promise<boolean>)
|
|
1662
|
-
| undefined;
|
|
1663
|
-
beforeRun?:
|
|
1664
|
-
| ((run: { readonly role: ReviewRunRole; readonly reason: ReviewRunReason }) => void)
|
|
1665
|
-
| undefined;
|
|
1666
|
-
/** Runs after the reviewer answered and before its run is written. */
|
|
1667
|
-
afterCall?:
|
|
1668
|
-
| ((run: { readonly role: ReviewRunRole; readonly reason: ReviewRunReason }) => void)
|
|
1669
|
-
| undefined;
|
|
1670
|
-
afterRunSaved?: ((run: ReviewRunRecord) => void) | undefined;
|
|
1671
|
-
/** Runs after the reviewer wrote a valid report, before the store copy. */
|
|
1672
|
-
beforeCopy?: (() => void) | undefined;
|
|
1673
|
-
/** Runs while a workspace report is open, before the folders are checked again. */
|
|
1674
|
-
afterOpen?: (() => void) | undefined;
|
|
1675
|
-
} = {};
|
|
1676
|
-
|
|
1677
1752
|
/** The task's notes with this round's findings that did not fail it. */
|
|
1678
1753
|
function notesOf(
|
|
1679
1754
|
task: TaskData,
|
|
@@ -1840,6 +1915,9 @@ export async function runReview(
|
|
|
1840
1915
|
if (!claimAllows(ctx, context.task)) return cancelledStep();
|
|
1841
1916
|
const task = context.task;
|
|
1842
1917
|
const attempt = attemptOf(ctx, task);
|
|
1918
|
+
// The attempt being reviewed changed the main checkout: the work must make
|
|
1919
|
+
// those changes in its own worktree instead, and dev holds the review to it.
|
|
1920
|
+
const mainPaths = mainCheckoutChanges(attempt);
|
|
1843
1921
|
const reviews =
|
|
1844
1922
|
typeof attempt.reviews === "number" ? attempt.reviews : 0;
|
|
1845
1923
|
const round = reviews + 1;
|
|
@@ -2228,6 +2306,33 @@ export async function runReview(
|
|
|
2228
2306
|
// review to ask a model for. A change made only of left-out files still runs
|
|
2229
2307
|
// the reviewer: the list is what tells it those files exist.
|
|
2230
2308
|
if (prepared.files.length === 0) {
|
|
2309
|
+
// A main-checkout change fails even without a diff: no reviewer is asked,
|
|
2310
|
+
// and dev adds the major finding itself.
|
|
2311
|
+
const findings = mainCheckoutFindings(mainPaths, []);
|
|
2312
|
+
if (findings.length > 0) {
|
|
2313
|
+
const counted = findings.filter((finding) =>
|
|
2314
|
+
atOrAbove(finding.severity, context.settings.reviewer.fixLevel),
|
|
2315
|
+
).length;
|
|
2316
|
+
const message = describeFindings(findings);
|
|
2317
|
+
const record: ReviewRecord = {
|
|
2318
|
+
result: "findings",
|
|
2319
|
+
decision: "findings",
|
|
2320
|
+
run: ctx.runId,
|
|
2321
|
+
sha,
|
|
2322
|
+
round,
|
|
2323
|
+
runs: [],
|
|
2324
|
+
findings,
|
|
2325
|
+
verified: [],
|
|
2326
|
+
reason: "findings",
|
|
2327
|
+
message,
|
|
2328
|
+
};
|
|
2329
|
+
return finish(record, "fail", {
|
|
2330
|
+
reason: "findings",
|
|
2331
|
+
counted,
|
|
2332
|
+
message,
|
|
2333
|
+
leftOut: prepared.leftOut.map(leftOutLine),
|
|
2334
|
+
});
|
|
2335
|
+
}
|
|
2231
2336
|
const record: ReviewRecord = {
|
|
2232
2337
|
result: "passed",
|
|
2233
2338
|
decision: "passed",
|
|
@@ -2350,6 +2455,7 @@ export async function runReview(
|
|
|
2350
2455
|
context.settings.prepare,
|
|
2351
2456
|
reworkPrompt,
|
|
2352
2457
|
verifiedCommands(attempt.verify),
|
|
2458
|
+
mainPaths,
|
|
2353
2459
|
);
|
|
2354
2460
|
// A resumed call asks with the prompt it recorded, not one built again.
|
|
2355
2461
|
const recorded =
|
|
@@ -2489,6 +2595,7 @@ export async function runReview(
|
|
|
2489
2595
|
outcome: call.outcome,
|
|
2490
2596
|
run: ctx.runId,
|
|
2491
2597
|
...(call.message.length === 0 ? {} : { message: call.message }),
|
|
2598
|
+
...(call.modelError === undefined ? {} : { modelError: call.modelError }),
|
|
2492
2599
|
};
|
|
2493
2600
|
}
|
|
2494
2601
|
runs.push(runRecord);
|
|
@@ -2512,31 +2619,42 @@ export async function runReview(
|
|
|
2512
2619
|
if (!written) return cancelledStep();
|
|
2513
2620
|
reviewTestHooks.afterRunSaved?.(runRecord);
|
|
2514
2621
|
next = nextReviewAction(runs, settings.fallback);
|
|
2622
|
+
if (
|
|
2623
|
+
next === "wait-unavailable" &&
|
|
2624
|
+
runRecord.modelError !== undefined &&
|
|
2625
|
+
runRecord.modelError !== null &&
|
|
2626
|
+
modelWaitsForPerson(runRecord.modelError)
|
|
2627
|
+
) {
|
|
2628
|
+
// A usage limit, or a wait past half an hour, is not an outage dev can
|
|
2629
|
+
// wait out: the task goes to a person who can change the worker.
|
|
2630
|
+
next = "wait-exhausted";
|
|
2631
|
+
}
|
|
2515
2632
|
}
|
|
2516
2633
|
|
|
2517
2634
|
const last = runs[runs.length - 1];
|
|
2518
2635
|
if (next === "done" && last !== undefined) {
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
const
|
|
2522
|
-
const
|
|
2523
|
-
|
|
2636
|
+
// A reviewer that passed an attempt with a main-checkout change cannot let
|
|
2637
|
+
// it through: dev adds the major finding itself.
|
|
2638
|
+
const reported = last.findings ?? [];
|
|
2639
|
+
const findings = [
|
|
2640
|
+
...reported,
|
|
2641
|
+
...mainCheckoutFindings(mainPaths, reported),
|
|
2642
|
+
];
|
|
2524
2643
|
const countedFindings = findings.filter(
|
|
2525
2644
|
(finding) =>
|
|
2526
2645
|
finding.preExisting !== true &&
|
|
2527
2646
|
finding.pre_existing !== true &&
|
|
2528
2647
|
atOrAbove(finding.severity, settings.fixLevel),
|
|
2529
2648
|
);
|
|
2649
|
+
const counted = countedFindings.length;
|
|
2650
|
+
const decision = counted === 0 ? "passed" : "findings";
|
|
2651
|
+
const stepResult = decision === "passed" ? "pass" : "fail";
|
|
2652
|
+
const result: ReviewResult = decision;
|
|
2530
2653
|
const preExistingCount = findings.filter(
|
|
2531
2654
|
(finding) =>
|
|
2532
2655
|
finding.preExisting === true || finding.pre_existing === true,
|
|
2533
2656
|
).length;
|
|
2534
|
-
const findingsMessage = countedFindings
|
|
2535
|
-
.map(
|
|
2536
|
-
(finding) =>
|
|
2537
|
-
`${finding.file}:${finding.line} ${finding.severity}: ${finding.summary}`,
|
|
2538
|
-
)
|
|
2539
|
-
.join("; ");
|
|
2657
|
+
const findingsMessage = describeFindings(countedFindings);
|
|
2540
2658
|
const reworkLine =
|
|
2541
2659
|
rework === undefined
|
|
2542
2660
|
? ""
|
|
@@ -2594,7 +2712,14 @@ export async function runReview(
|
|
|
2594
2712
|
const why = exhausted
|
|
2595
2713
|
? "review did not finish (model unavailable)"
|
|
2596
2714
|
: "review did not finish (out of time)";
|
|
2597
|
-
const
|
|
2715
|
+
const reset =
|
|
2716
|
+
exhausted && last?.modelError?.retryAfterSecs !== undefined
|
|
2717
|
+
? `; the model can serve again at ${new Date(
|
|
2718
|
+
(last.modelError.reportedAt ?? clock()) +
|
|
2719
|
+
last.modelError.retryAfterSecs * 1000,
|
|
2720
|
+
).toISOString()}`
|
|
2721
|
+
: "";
|
|
2722
|
+
const message = [reviewMessage("passed", runs), why + reset]
|
|
2598
2723
|
.filter((piece) => piece.length > 0)
|
|
2599
2724
|
.join("; ");
|
|
2600
2725
|
const timedOut = !exhausted && last?.outcome === "timed_out";
|
|
@@ -2622,9 +2747,14 @@ export async function runReview(
|
|
|
2622
2747
|
const waits = runs.filter(
|
|
2623
2748
|
(run) => run.role === "primary" && run.outcome === "unavailable",
|
|
2624
2749
|
).length;
|
|
2750
|
+
const retryAfterSecs = last?.modelError?.retryAfterSecs;
|
|
2625
2751
|
const retryAt =
|
|
2626
|
-
(
|
|
2627
|
-
|
|
2752
|
+
(retryAfterSecs === undefined
|
|
2753
|
+
? clock()
|
|
2754
|
+
: last?.modelError?.reportedAt ?? clock()) +
|
|
2755
|
+
(retryAfterSecs === undefined
|
|
2756
|
+
? reviewWaitMs(settings.retrySecs, waits)
|
|
2757
|
+
: retryAfterSecs * 1000);
|
|
2628
2758
|
const message = reviewMessage("unavailable", runs, retryAt);
|
|
2629
2759
|
const record: ReviewRecord = {
|
|
2630
2760
|
result: "unavailable",
|
|
@@ -2937,14 +3067,3 @@ export async function runRework(
|
|
|
2937
3067
|
};
|
|
2938
3068
|
}
|
|
2939
3069
|
|
|
2940
|
-
/** The recorded verified commit of a task, for a caller that wants to look. */
|
|
2941
|
-
export function verifiedCommitOf(task: TaskData): string | undefined {
|
|
2942
|
-
const sha = task.attempt?.verified;
|
|
2943
|
-
return typeof sha === "string" && sha.length > 0 ? sha : undefined;
|
|
2944
|
-
}
|
|
2945
|
-
|
|
2946
|
-
/** The branch head a task's worktree is on, for tests and views. */
|
|
2947
|
-
export function taskHead(path: string): string | undefined {
|
|
2948
|
-
return headOf(path);
|
|
2949
|
-
}
|
|
2950
|
-
|
package/src/git.ts
CHANGED
|
@@ -136,3 +136,50 @@ export function git(
|
|
|
136
136
|
}
|
|
137
137
|
return result;
|
|
138
138
|
}
|
|
139
|
+
|
|
140
|
+
/** The commit `ref` names, or undefined when it does not name one. */
|
|
141
|
+
export function commitOf(cwd: string, ref: string): string | undefined {
|
|
142
|
+
return revisionOf(cwd, `${ref}^{commit}`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** The tree `ref` names, or undefined when it does not name one. */
|
|
146
|
+
export function treeOf(cwd: string, ref: string): string | undefined {
|
|
147
|
+
return revisionOf(cwd, `${ref}^{tree}`);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* What `git rev-parse --verify --quiet` prints for `ref`, or undefined when the
|
|
152
|
+
* ref does not name an object.
|
|
153
|
+
*/
|
|
154
|
+
export function revisionOf(cwd: string, ref: string): string | undefined {
|
|
155
|
+
const result = git(cwd, ["rev-parse", "--verify", "--quiet", ref]);
|
|
156
|
+
return result.ok && result.out.length > 0 ? result.out : undefined;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** The commit a work tree has checked out, or undefined when it has none. */
|
|
160
|
+
export function headOf(cwd: string): string | undefined {
|
|
161
|
+
const result = git(cwd, ["rev-parse", "HEAD"]);
|
|
162
|
+
return result.ok && result.out.length > 0 ? result.out : undefined;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** True when `ancestor` is reachable from `descendant`. */
|
|
166
|
+
export function isAncestor(
|
|
167
|
+
cwd: string,
|
|
168
|
+
ancestor: string,
|
|
169
|
+
descendant: string,
|
|
170
|
+
): boolean {
|
|
171
|
+
return git(cwd, ["merge-base", "--is-ancestor", ancestor, descendant]).ok;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** True when a local branch exists, or the branch on `remote` when one is named. */
|
|
175
|
+
export function branchExists(
|
|
176
|
+
cwd: string,
|
|
177
|
+
branch: string,
|
|
178
|
+
remote?: string,
|
|
179
|
+
): boolean {
|
|
180
|
+
const ref =
|
|
181
|
+
remote === undefined
|
|
182
|
+
? `refs/heads/${branch}`
|
|
183
|
+
: `refs/remotes/${remote}/${branch}`;
|
|
184
|
+
return git(cwd, ["show-ref", "--verify", "--quiet", ref]).ok;
|
|
185
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
/** The dev plugin: repositories, plans, tasks and their commands and views. */
|
|
2
2
|
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
3
4
|
import pkg from "../package.json" with { type: "json" };
|
|
4
5
|
import { definePlugin } from "@operad-io/engine";
|
|
6
|
+
import { WORKTREE_EVENT } from "@operad-io/chat";
|
|
5
7
|
import { PLAN_FILTERS, REPO_FILTERS, TASK_FILTERS } from "./model.ts";
|
|
6
8
|
import devFlow from "../flows/dev.flow.ts";
|
|
7
9
|
import chatWorktreeFlow from "../flows/chat-worktree.flow.ts";
|
|
8
10
|
import { actions } from "./actions.ts";
|
|
11
|
+
import { accessAction } from "./access-grants.ts";
|
|
9
12
|
import { runAnnounce } from "./announce.ts";
|
|
10
13
|
import { checkDev } from "./check.ts";
|
|
11
|
-
import { chatActions, runChatWorktree } from "./chat.ts";
|
|
14
|
+
import { chatActions, runChatSettings, runChatWorktree } from "./chat.ts";
|
|
12
15
|
import { commands } from "./commands.ts";
|
|
16
|
+
import { creationActions } from "./create-actions.ts";
|
|
13
17
|
import { runRework, runReview, runReviewDue, runVerify, runWorkDue } from "./gate.ts";
|
|
14
18
|
import { runRetry, runRetryDue } from "./retry.ts";
|
|
15
19
|
import { runCleanup, runIntegrate } from "./integrate.ts";
|
|
16
20
|
import { runScheduler, taskWaitAnsweredAutomatically } from "./schedule.ts";
|
|
17
21
|
import { devStanding } from "./standing.ts";
|
|
22
|
+
import { registerRequested } from "./register-requests.ts";
|
|
18
23
|
import { migrateLegacyRepositories, resolveDevKey } from "./service.ts";
|
|
19
24
|
import { runReverify, runWork, runWorktree } from "./steps.ts";
|
|
20
25
|
import { STEP_TIMEOUT_SECS } from "./timeouts.ts";
|
|
@@ -64,7 +69,7 @@ export function createDevPlugin() {
|
|
|
64
69
|
name: "work",
|
|
65
70
|
calls: ["pool/agent"],
|
|
66
71
|
timeoutSecs: STEP_TIMEOUT_SECS,
|
|
67
|
-
results: ["done", "nothing", "failed", "unavailable", "cancelled", "interrupted"],
|
|
72
|
+
results: ["done", "nothing", "failed", "unavailable", "cancelled", "interrupted", "waiting"],
|
|
68
73
|
run: runWork,
|
|
69
74
|
},
|
|
70
75
|
{
|
|
@@ -125,6 +130,7 @@ export function createDevPlugin() {
|
|
|
125
130
|
},
|
|
126
131
|
{
|
|
127
132
|
name: "integrate",
|
|
133
|
+
reachesOutside: true,
|
|
128
134
|
calls: ["shell/check", "shell/command"],
|
|
129
135
|
timeoutSecs: STEP_TIMEOUT_SECS,
|
|
130
136
|
results: ["merged", "conflict", "fail", "failed", "cancelled"],
|
|
@@ -138,9 +144,15 @@ export function createDevPlugin() {
|
|
|
138
144
|
},
|
|
139
145
|
{
|
|
140
146
|
name: "announce",
|
|
141
|
-
results: ["done", "interrupted", "cancelled"],
|
|
147
|
+
results: ["done", "waiting", "interrupted", "cancelled"],
|
|
142
148
|
run: runAnnounce,
|
|
143
149
|
},
|
|
150
|
+
{
|
|
151
|
+
// The skills and access of a repository chat, read at every reply.
|
|
152
|
+
name: "chat_settings",
|
|
153
|
+
results: ["done", "failed"],
|
|
154
|
+
run: runChatSettings,
|
|
155
|
+
},
|
|
144
156
|
{
|
|
145
157
|
// The worktree a chat asked for; git runs in the repository.
|
|
146
158
|
name: "chat_worktree",
|
|
@@ -153,12 +165,29 @@ export function createDevPlugin() {
|
|
|
153
165
|
properties: {
|
|
154
166
|
checks: {
|
|
155
167
|
type: "integer",
|
|
168
|
+
title: "Checks at once",
|
|
156
169
|
minimum: 1,
|
|
157
170
|
default: 2,
|
|
158
171
|
editable: true,
|
|
159
172
|
description:
|
|
160
173
|
"How many checks (a task's verify, and the checks before a merge) may run at the same time on this machine, across all repositories.",
|
|
161
174
|
},
|
|
175
|
+
testHost: {
|
|
176
|
+
type: "string",
|
|
177
|
+
title: "Test host",
|
|
178
|
+
minLength: 1,
|
|
179
|
+
editable: true,
|
|
180
|
+
description:
|
|
181
|
+
"The ssh destination, such as user@host, that gate, integration and rerun commands run on through remote-check.sh. Unset runs them here. An OPERAD_CHECK_HOST already in serve's own environment wins over this setting.",
|
|
182
|
+
},
|
|
183
|
+
testSlots: {
|
|
184
|
+
type: "integer",
|
|
185
|
+
title: "Test slots",
|
|
186
|
+
minimum: 1,
|
|
187
|
+
editable: true,
|
|
188
|
+
description:
|
|
189
|
+
"How many checks run at once on the test host. Unset lets remote-check.sh use its default of 1. An OPERAD_CHECK_SLOTS already in serve's own environment wins over this setting.",
|
|
190
|
+
},
|
|
162
191
|
},
|
|
163
192
|
additionalProperties: false,
|
|
164
193
|
},
|
|
@@ -177,15 +206,18 @@ export function createDevPlugin() {
|
|
|
177
206
|
// A chat of a repository asked for a worktree and a person said yes.
|
|
178
207
|
{
|
|
179
208
|
source: "operad",
|
|
180
|
-
type:
|
|
209
|
+
type: WORKTREE_EVENT,
|
|
181
210
|
start: { flow: "dev:chat-worktree" },
|
|
182
211
|
object: "$event.object",
|
|
183
212
|
mode: "auto",
|
|
184
213
|
},
|
|
185
214
|
],
|
|
186
|
-
actions: [...actions, ...chatActions],
|
|
215
|
+
actions: [...actions, accessAction, ...chatActions, ...creationActions],
|
|
187
216
|
commands,
|
|
188
|
-
onTick:
|
|
217
|
+
onTick: async (ctx) => {
|
|
218
|
+
await registerRequested(ctx);
|
|
219
|
+
await runScheduler(ctx);
|
|
220
|
+
},
|
|
189
221
|
standing: devStanding,
|
|
190
222
|
views: {
|
|
191
223
|
repo: repoViews,
|
|
@@ -199,16 +231,23 @@ export function createDevPlugin() {
|
|
|
199
231
|
check(ctx) {
|
|
200
232
|
return checkDev(ctx);
|
|
201
233
|
},
|
|
234
|
+
// Setup Dev (ADR 0030 D15): the guide a bot follows for what check reports missing.
|
|
235
|
+
guide: DEV_SETUP_GUIDE,
|
|
202
236
|
});
|
|
203
237
|
}
|
|
204
238
|
|
|
239
|
+
/** The `SKILL.md` Setup Dev gives a bot (ADR 0010 D7). */
|
|
240
|
+
export const DEV_SETUP_GUIDE = fileURLToPath(new URL("../skills/setup/SKILL.md", import.meta.url));
|
|
241
|
+
|
|
205
242
|
export default createDevPlugin();
|
|
206
243
|
|
|
207
244
|
export * from "./actions.ts";
|
|
208
245
|
export * from "./announce.ts";
|
|
209
246
|
export * from "./chat.ts";
|
|
210
247
|
export * from "./check.ts";
|
|
248
|
+
export * from "./check-host.ts";
|
|
211
249
|
export * from "./commands.ts";
|
|
250
|
+
export * from "./create-actions.ts";
|
|
212
251
|
export * from "./gate.ts";
|
|
213
252
|
export * from "./integrate.ts";
|
|
214
253
|
export * from "./model.ts";
|
|
@@ -216,6 +255,7 @@ export * from "./flow-compiler.ts";
|
|
|
216
255
|
export * from "./project-flows.ts";
|
|
217
256
|
export * from "./schedule.ts";
|
|
218
257
|
export * from "./service.ts";
|
|
258
|
+
export * from "./register-requests.ts";
|
|
219
259
|
export * from "./places.ts";
|
|
220
260
|
export * from "./project-settings.ts";
|
|
221
261
|
export * from "./retry.ts";
|