@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/settings.ts
CHANGED
|
@@ -4,14 +4,12 @@
|
|
|
4
4
|
* read, and this module applies the same rules when a step loads the file.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { messageOf } from "@operad-io/engine";
|
|
8
8
|
import {
|
|
9
9
|
existsSync,
|
|
10
|
-
mkdirSync,
|
|
11
10
|
readFileSync,
|
|
12
11
|
realpathSync,
|
|
13
|
-
|
|
14
|
-
writeFileSync,
|
|
12
|
+
statSync,
|
|
15
13
|
} from "node:fs";
|
|
16
14
|
import {
|
|
17
15
|
basename,
|
|
@@ -31,11 +29,14 @@ import {
|
|
|
31
29
|
type WorkerDefinition,
|
|
32
30
|
} from "@operad-io/pool";
|
|
33
31
|
import { defaultOperadHome, isRecord } from "@operad-io/engine";
|
|
32
|
+
import { writeJsonAtomicSync } from "@operad-io/engine/platform";
|
|
34
33
|
import { DevError, type AutoMode } from "./model.ts";
|
|
34
|
+
import { repositoryPathKey } from "./repository-key.ts";
|
|
35
35
|
import {
|
|
36
36
|
type DevFlowSpec,
|
|
37
37
|
type DevFlows,
|
|
38
38
|
type DevStage,
|
|
39
|
+
type StageKind,
|
|
39
40
|
} from "./flow-compiler.ts";
|
|
40
41
|
|
|
41
42
|
/** Where a repository keeps its dev settings. */
|
|
@@ -47,9 +48,72 @@ export const DEV_SETTINGS_SCHEMA = "https://operad.io/schemas/dev.schema.json";
|
|
|
47
48
|
/** The default location of a repository's worker brief. */
|
|
48
49
|
export const WORKER_BRIEF_FILE = ".operad/worker-brief.md";
|
|
49
50
|
|
|
50
|
-
/** The
|
|
51
|
+
/** The skill directories a repository gives its chats when it writes none. */
|
|
52
|
+
export const DEFAULT_SKILLS: readonly string[] = [".agents/skills"];
|
|
53
|
+
|
|
54
|
+
/** The harness step a repository uses when it names none and the home enables none. */
|
|
51
55
|
export const DEFAULT_WORKER_USE = "radian/agent";
|
|
52
56
|
|
|
57
|
+
/** The harness order a repository with no worker settings chooses from. */
|
|
58
|
+
export const DEFAULT_HARNESS_ORDER: readonly string[] = ["radian", "claude", "pi", "codex"];
|
|
59
|
+
|
|
60
|
+
/** The harness a plugin entry names, whether by its key or by its package. */
|
|
61
|
+
function harnessPlugin(name: string | undefined, module: unknown): string | undefined {
|
|
62
|
+
for (const harness of DEFAULT_HARNESS_ORDER) {
|
|
63
|
+
if (name === harness) return harness;
|
|
64
|
+
if (typeof module !== "string") continue;
|
|
65
|
+
if (
|
|
66
|
+
module === `@operad-io/harness-${harness}` ||
|
|
67
|
+
module.endsWith(`/harness-${harness}`) ||
|
|
68
|
+
module.endsWith(`/harness/${harness}/src/index.ts`)
|
|
69
|
+
) {
|
|
70
|
+
return harness;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The first enabled harness in the home's `config.json`, in `DEFAULT_HARNESS_ORDER`.
|
|
78
|
+
* A missing or unreadable file keeps the old radian default.
|
|
79
|
+
*/
|
|
80
|
+
export function defaultAgentUse(home: string = defaultOperadHome()): string {
|
|
81
|
+
let raw: unknown;
|
|
82
|
+
try {
|
|
83
|
+
raw = JSON.parse(readFileSync(join(home, "config.json"), "utf8"));
|
|
84
|
+
} catch {
|
|
85
|
+
return DEFAULT_WORKER_USE;
|
|
86
|
+
}
|
|
87
|
+
if (!isRecord(raw)) return DEFAULT_WORKER_USE;
|
|
88
|
+
const plugins = raw.plugins;
|
|
89
|
+
const enabled = new Set<string>();
|
|
90
|
+
if (Array.isArray(plugins)) {
|
|
91
|
+
for (const entry of plugins) {
|
|
92
|
+
if (typeof entry === "string") {
|
|
93
|
+
const found = harnessPlugin(undefined, entry);
|
|
94
|
+
if (found !== undefined) enabled.add(found);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const record = isRecord(entry) ? entry : undefined;
|
|
98
|
+
if (record?.enabled === false) continue;
|
|
99
|
+
const name = typeof record?.name === "string" ? record.name : undefined;
|
|
100
|
+
const module = record?.module;
|
|
101
|
+
const found = harnessPlugin(name, module) ?? harnessPlugin(undefined, module);
|
|
102
|
+
if (found !== undefined) enabled.add(found);
|
|
103
|
+
}
|
|
104
|
+
} else if (isRecord(plugins)) {
|
|
105
|
+
for (const [name, entry] of Object.entries(plugins)) {
|
|
106
|
+
const record = isRecord(entry) ? entry : undefined;
|
|
107
|
+
if (record?.enabled === false) continue;
|
|
108
|
+
const module = typeof entry === "string" ? entry : record?.module;
|
|
109
|
+
const found = harnessPlugin(name, module) ?? harnessPlugin(undefined, module);
|
|
110
|
+
if (found !== undefined) enabled.add(found);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const first = DEFAULT_HARNESS_ORDER.find((name) => enabled.has(name));
|
|
114
|
+
return first === undefined ? DEFAULT_WORKER_USE : `${first}/agent`;
|
|
115
|
+
}
|
|
116
|
+
|
|
53
117
|
/** How long a review waits before it runs again after a model was unavailable. */
|
|
54
118
|
export const DEFAULT_REVIEWER_RETRY_SECS = 120;
|
|
55
119
|
|
|
@@ -249,6 +313,12 @@ export interface DevSettings {
|
|
|
249
313
|
*/
|
|
250
314
|
readonly workers: ParsedWorkers;
|
|
251
315
|
readonly workerBrief: string;
|
|
316
|
+
/**
|
|
317
|
+
* The skill directories this repository's chats read, relative to the
|
|
318
|
+
* repository. A `.agents` directory is read through its `skills` directory.
|
|
319
|
+
* Empty gives the chats no skills.
|
|
320
|
+
*/
|
|
321
|
+
readonly skills: readonly string[];
|
|
252
322
|
/**
|
|
253
323
|
* Commands run in every checkout dev makes (the worker's worktree, the gate
|
|
254
324
|
* checkout, the integration checkout) after it is created or moved to a new
|
|
@@ -307,6 +377,7 @@ export const DEFAULT_DEV_SETTINGS: DevSettings = {
|
|
|
307
377
|
},
|
|
308
378
|
workers: legacyWorkers({ use: DEFAULT_WORKER_USE, args: [] }, 1),
|
|
309
379
|
workerBrief: WORKER_BRIEF_FILE,
|
|
380
|
+
skills: DEFAULT_SKILLS,
|
|
310
381
|
prepare: [],
|
|
311
382
|
gate: {
|
|
312
383
|
commands: [],
|
|
@@ -338,6 +409,17 @@ export const DEFAULT_DEV_SETTINGS: DevSettings = {
|
|
|
338
409
|
flows: {},
|
|
339
410
|
};
|
|
340
411
|
|
|
412
|
+
/** The defaults when the home enables `agentUse` instead of radian. */
|
|
413
|
+
export function defaultDevSettings(agentUse: string = defaultAgentUse()): DevSettings {
|
|
414
|
+
if (agentUse === DEFAULT_WORKER_USE) return DEFAULT_DEV_SETTINGS;
|
|
415
|
+
return {
|
|
416
|
+
...DEFAULT_DEV_SETTINGS,
|
|
417
|
+
worker: { use: agentUse, args: [] },
|
|
418
|
+
workers: legacyWorkers({ use: agentUse, args: [] }, DEFAULT_DEV_SETTINGS.concurrency),
|
|
419
|
+
reviewer: { ...DEFAULT_DEV_SETTINGS.reviewer, use: agentUse },
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
|
|
341
423
|
const KNOWN_FIELDS = new Set([
|
|
342
424
|
"$schema",
|
|
343
425
|
"name",
|
|
@@ -353,6 +435,7 @@ const KNOWN_FIELDS = new Set([
|
|
|
353
435
|
"workers",
|
|
354
436
|
"pools",
|
|
355
437
|
"workerBrief",
|
|
438
|
+
"skills",
|
|
356
439
|
"prepare",
|
|
357
440
|
"gate",
|
|
358
441
|
"check",
|
|
@@ -389,6 +472,16 @@ function repositoryRelativePath(value: unknown, field: string): string {
|
|
|
389
472
|
return path;
|
|
390
473
|
}
|
|
391
474
|
|
|
475
|
+
/** A list of skill directories, each relative to the repository. */
|
|
476
|
+
function repositorySkillList(value: unknown, field: string): readonly string[] {
|
|
477
|
+
if (!Array.isArray(value)) {
|
|
478
|
+
throw new DevError(field, "must be an array of strings");
|
|
479
|
+
}
|
|
480
|
+
return value.map((item, index) =>
|
|
481
|
+
repositoryRelativePath(item, `${field}[${index}]`),
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
|
|
392
485
|
/**
|
|
393
486
|
* The real path of `path`, resolving the symlinks of every part that exists.
|
|
394
487
|
* A tail that does not exist yet is appended unchanged, so the answer is where
|
|
@@ -460,7 +553,7 @@ function settingsStringList(value: unknown, field: string): readonly string[] {
|
|
|
460
553
|
});
|
|
461
554
|
}
|
|
462
555
|
|
|
463
|
-
function workerSettings(value: unknown, field: string): WorkerSettings {
|
|
556
|
+
function workerSettings(value: unknown, field: string, defaultUse: string): WorkerSettings {
|
|
464
557
|
if (!isRecord(value)) {
|
|
465
558
|
throw new DevError(field, "must be an object");
|
|
466
559
|
}
|
|
@@ -471,7 +564,7 @@ function workerSettings(value: unknown, field: string): WorkerSettings {
|
|
|
471
564
|
}
|
|
472
565
|
const use =
|
|
473
566
|
value.use === undefined
|
|
474
|
-
?
|
|
567
|
+
? defaultUse
|
|
475
568
|
: nonEmptyString(value.use, `${field}.use`);
|
|
476
569
|
const args =
|
|
477
570
|
value.args === undefined
|
|
@@ -799,7 +892,7 @@ function reviewerFirst(value: unknown, field: string): ReviewerFirst {
|
|
|
799
892
|
};
|
|
800
893
|
}
|
|
801
894
|
|
|
802
|
-
function reviewerSettings(value: unknown, field: string): ReviewerSettings {
|
|
895
|
+
function reviewerSettings(value: unknown, field: string, defaultUse: string): ReviewerSettings {
|
|
803
896
|
if (!isRecord(value)) {
|
|
804
897
|
throw new DevError(field, "must be an object");
|
|
805
898
|
}
|
|
@@ -836,7 +929,7 @@ function reviewerSettings(value: unknown, field: string): ReviewerSettings {
|
|
|
836
929
|
return {
|
|
837
930
|
use:
|
|
838
931
|
value.use === undefined
|
|
839
|
-
?
|
|
932
|
+
? defaultUse
|
|
840
933
|
: nonEmptyString(value.use, `${field}.use`),
|
|
841
934
|
args:
|
|
842
935
|
value.args === undefined
|
|
@@ -961,6 +1054,7 @@ function firstWorker(workers: ParsedWorkers): WorkerSettings {
|
|
|
961
1054
|
function workerSettingsOf(
|
|
962
1055
|
value: Readonly<Record<string, unknown>>,
|
|
963
1056
|
concurrency: number,
|
|
1057
|
+
defaults: DevSettings,
|
|
964
1058
|
): { readonly worker: WorkerSettings; readonly workers: ParsedWorkers } {
|
|
965
1059
|
if (value.workers === undefined) {
|
|
966
1060
|
if (value.pools !== undefined) {
|
|
@@ -968,8 +1062,8 @@ function workerSettingsOf(
|
|
|
968
1062
|
}
|
|
969
1063
|
const worker =
|
|
970
1064
|
value.worker === undefined
|
|
971
|
-
?
|
|
972
|
-
: workerSettings(value.worker, "worker");
|
|
1065
|
+
? defaults.worker
|
|
1066
|
+
: workerSettings(value.worker, "worker", defaults.worker.use);
|
|
973
1067
|
return { worker, workers: legacyWorkers(worker, concurrency) };
|
|
974
1068
|
}
|
|
975
1069
|
if (value.worker !== undefined) {
|
|
@@ -1035,19 +1129,19 @@ export function repositoryTaskCap(settings: DevSettings): number {
|
|
|
1035
1129
|
return settings.concurrencySet ? Math.min(total, settings.concurrency) : total;
|
|
1036
1130
|
}
|
|
1037
1131
|
|
|
1038
|
-
/** The pool a flow's tasks count against: its first
|
|
1132
|
+
/** The pool a flow's tasks count against: its first code stage's pool, or `default`. */
|
|
1039
1133
|
export function flowPool(settings: DevSettings, flowName: string | undefined): string {
|
|
1040
1134
|
const spec = settings.flows[flowName ?? "default"];
|
|
1041
1135
|
for (const stage of spec?.stages ?? []) {
|
|
1042
|
-
if (stage.stage === "work") return stage.pool ?? DEFAULT_POOL;
|
|
1136
|
+
if (stage.stage === "code" || stage.stage === "work") return stage.pool ?? DEFAULT_POOL;
|
|
1043
1137
|
}
|
|
1044
1138
|
return DEFAULT_POOL;
|
|
1045
1139
|
}
|
|
1046
1140
|
|
|
1047
1141
|
/** The fields a stage of each kind may name. */
|
|
1048
|
-
const STAGE_FIELDS: Readonly<Record<
|
|
1049
|
-
|
|
1050
|
-
|
|
1142
|
+
const STAGE_FIELDS: Readonly<Record<StageKind, readonly string[]>> = {
|
|
1143
|
+
code: ["stage", "use", "args", "pool", "workerBrief", "commit", "brief", "beforeAttempt"],
|
|
1144
|
+
test: ["stage", "commands", "rerun"],
|
|
1051
1145
|
review: ["stage", "use", "args", "later", "grading"],
|
|
1052
1146
|
human: ["stage"],
|
|
1053
1147
|
};
|
|
@@ -1056,18 +1150,23 @@ function stageOf(value: unknown, field: string): DevStage {
|
|
|
1056
1150
|
if (!isRecord(value)) {
|
|
1057
1151
|
throw new DevError(field, "must be a JSON object");
|
|
1058
1152
|
}
|
|
1059
|
-
const
|
|
1153
|
+
const written = value.stage;
|
|
1060
1154
|
if (
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1155
|
+
written !== "code" &&
|
|
1156
|
+
written !== "test" &&
|
|
1157
|
+
written !== "review" &&
|
|
1158
|
+
written !== "human" &&
|
|
1159
|
+
written !== "work" &&
|
|
1160
|
+
written !== "check"
|
|
1065
1161
|
) {
|
|
1066
1162
|
throw new DevError(
|
|
1067
1163
|
`${field}.stage`,
|
|
1068
|
-
'must be "
|
|
1164
|
+
'must be "code", "test", "review" or "human"',
|
|
1069
1165
|
);
|
|
1070
1166
|
}
|
|
1167
|
+
// The older names load as the same stages; everything written back uses the new names.
|
|
1168
|
+
const kind: StageKind =
|
|
1169
|
+
written === "work" ? "code" : written === "check" ? "test" : written;
|
|
1071
1170
|
for (const key of Object.keys(value)) {
|
|
1072
1171
|
if (!STAGE_FIELDS[kind].includes(key)) {
|
|
1073
1172
|
throw new DevError(`${field}.${key}`, "is not a stage setting");
|
|
@@ -1078,7 +1177,7 @@ function stageOf(value: unknown, field: string): DevStage {
|
|
|
1078
1177
|
const optionalList = (key: string): readonly string[] | undefined =>
|
|
1079
1178
|
value[key] === undefined ? undefined : settingsStringList(value[key], `${field}.${key}`);
|
|
1080
1179
|
switch (kind) {
|
|
1081
|
-
case "
|
|
1180
|
+
case "code": {
|
|
1082
1181
|
const use = optionalString("use");
|
|
1083
1182
|
const args = optionalList("args");
|
|
1084
1183
|
const pool = optionalString("pool");
|
|
@@ -1100,7 +1199,7 @@ function stageOf(value: unknown, field: string): DevStage {
|
|
|
1100
1199
|
);
|
|
1101
1200
|
}
|
|
1102
1201
|
return {
|
|
1103
|
-
stage: "
|
|
1202
|
+
stage: "code",
|
|
1104
1203
|
...(use === undefined ? {} : { use }),
|
|
1105
1204
|
...(args === undefined ? {} : { args }),
|
|
1106
1205
|
...(pool === undefined ? {} : { pool }),
|
|
@@ -1110,7 +1209,7 @@ function stageOf(value: unknown, field: string): DevStage {
|
|
|
1110
1209
|
...(beforeAttempt === undefined ? {} : { beforeAttempt }),
|
|
1111
1210
|
};
|
|
1112
1211
|
}
|
|
1113
|
-
case "
|
|
1212
|
+
case "test": {
|
|
1114
1213
|
const commands =
|
|
1115
1214
|
value.commands === undefined
|
|
1116
1215
|
? undefined
|
|
@@ -1120,7 +1219,7 @@ function stageOf(value: unknown, field: string): DevStage {
|
|
|
1120
1219
|
? undefined
|
|
1121
1220
|
: nonNegativeInteger(value.rerun, `${field}.rerun`);
|
|
1122
1221
|
return {
|
|
1123
|
-
stage: "
|
|
1222
|
+
stage: "test",
|
|
1124
1223
|
...(commands === undefined ? {} : { commands }),
|
|
1125
1224
|
...(rerun === undefined ? {} : { rerun }),
|
|
1126
1225
|
};
|
|
@@ -1162,7 +1261,7 @@ function flowSpecOf(value: unknown, field: string): DevFlowSpec {
|
|
|
1162
1261
|
}
|
|
1163
1262
|
|
|
1164
1263
|
/**
|
|
1165
|
-
* The repository's flows, and the two hard rules: a flow needs a
|
|
1264
|
+
* The repository's flows, and the two hard rules: a flow needs a test, review
|
|
1166
1265
|
* or human stage, and its last stage is human because integrate is the step
|
|
1167
1266
|
* that puts a change on main.
|
|
1168
1267
|
*/
|
|
@@ -1181,14 +1280,14 @@ function flowsOf(
|
|
|
1181
1280
|
}
|
|
1182
1281
|
const field = `flows.${name}`;
|
|
1183
1282
|
const flow = flowSpecOf(raw, field);
|
|
1184
|
-
if (!flow.stages.some((stage) => stage.stage !== "
|
|
1283
|
+
if (!flow.stages.some((stage) => stage.stage !== "code")) {
|
|
1185
1284
|
throw new DevError(
|
|
1186
1285
|
`${field}.stages`,
|
|
1187
|
-
"needs at least one
|
|
1286
|
+
"needs at least one test, review or human stage",
|
|
1188
1287
|
);
|
|
1189
1288
|
}
|
|
1190
1289
|
flow.stages.forEach((stage, index) => {
|
|
1191
|
-
if (stage.stage === "
|
|
1290
|
+
if (stage.stage === "code" && stage.pool !== undefined && pools[stage.pool] === undefined) {
|
|
1192
1291
|
throw new DevError(
|
|
1193
1292
|
`${field}.stages[${index}].pool`,
|
|
1194
1293
|
`no pool named "${stage.pool}" in pools`,
|
|
@@ -1200,10 +1299,29 @@ function flowsOf(
|
|
|
1200
1299
|
return flows;
|
|
1201
1300
|
}
|
|
1202
1301
|
|
|
1302
|
+
/**
|
|
1303
|
+
* Rewrites the older stage names in a dev.json value that has already passed
|
|
1304
|
+
* validation, so a settings write stores the new names.
|
|
1305
|
+
*/
|
|
1306
|
+
export function useNewStageNames(value: unknown): void {
|
|
1307
|
+
if (!isRecord(value) || !isRecord(value.flows)) return;
|
|
1308
|
+
for (const flow of Object.values(value.flows)) {
|
|
1309
|
+
if (!isRecord(flow) || !Array.isArray(flow.stages)) continue;
|
|
1310
|
+
for (const stage of flow.stages) {
|
|
1311
|
+
if (!isRecord(stage)) continue;
|
|
1312
|
+
if (stage.stage === "work") stage.stage = "code";
|
|
1313
|
+
else if (stage.stage === "check") stage.stage = "test";
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1203
1318
|
/**
|
|
1204
1319
|
* Validates one parsed dev.json value and fills the defaults.
|
|
1205
1320
|
*/
|
|
1206
|
-
export function validateDevSettings(
|
|
1321
|
+
export function validateDevSettings(
|
|
1322
|
+
value: unknown,
|
|
1323
|
+
defaults: DevSettings = defaultDevSettings(),
|
|
1324
|
+
): DevSettings {
|
|
1207
1325
|
if (!isRecord(value)) {
|
|
1208
1326
|
throw new DevError("dev.json", "must be a JSON object");
|
|
1209
1327
|
}
|
|
@@ -1215,9 +1333,9 @@ export function validateDevSettings(value: unknown): DevSettings {
|
|
|
1215
1333
|
const worktreeRoot = worktreeRootOf(value);
|
|
1216
1334
|
const concurrency =
|
|
1217
1335
|
value.concurrency === undefined
|
|
1218
|
-
?
|
|
1336
|
+
? defaults.concurrency
|
|
1219
1337
|
: positiveInteger(value.concurrency, "concurrency");
|
|
1220
|
-
const { worker, workers } = workerSettingsOf(value, concurrency);
|
|
1338
|
+
const { worker, workers } = workerSettingsOf(value, concurrency, defaults);
|
|
1221
1339
|
return {
|
|
1222
1340
|
...(value.name === undefined
|
|
1223
1341
|
? {}
|
|
@@ -1239,6 +1357,10 @@ export function validateDevSettings(value: unknown): DevSettings {
|
|
|
1239
1357
|
value.workerBrief === undefined
|
|
1240
1358
|
? DEFAULT_DEV_SETTINGS.workerBrief
|
|
1241
1359
|
: nonEmptyString(value.workerBrief, "workerBrief"),
|
|
1360
|
+
skills:
|
|
1361
|
+
value.skills === undefined
|
|
1362
|
+
? DEFAULT_DEV_SETTINGS.skills
|
|
1363
|
+
: repositorySkillList(value.skills, "skills"),
|
|
1242
1364
|
prepare:
|
|
1243
1365
|
value.prepare === undefined
|
|
1244
1366
|
? DEFAULT_DEV_SETTINGS.prepare
|
|
@@ -1257,8 +1379,8 @@ export function validateDevSettings(value: unknown): DevSettings {
|
|
|
1257
1379
|
: workSettings(value.work, "work"),
|
|
1258
1380
|
reviewer:
|
|
1259
1381
|
value.reviewer === undefined
|
|
1260
|
-
?
|
|
1261
|
-
: reviewerSettings(value.reviewer, "reviewer"),
|
|
1382
|
+
? defaults.reviewer
|
|
1383
|
+
: reviewerSettings(value.reviewer, "reviewer", defaults.reviewer.use),
|
|
1262
1384
|
integration:
|
|
1263
1385
|
value.integration === undefined
|
|
1264
1386
|
? DEFAULT_DEV_SETTINGS.integration
|
|
@@ -1289,12 +1411,34 @@ interface ReadSettings {
|
|
|
1289
1411
|
readonly text: string;
|
|
1290
1412
|
}
|
|
1291
1413
|
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1414
|
+
interface ParsedSettings {
|
|
1415
|
+
readonly settings: DevSettings;
|
|
1416
|
+
/** The name of the worktree-root field the file wrote. */
|
|
1417
|
+
readonly worktreeField: string;
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
/** How many parsed settings texts and last-read files are kept. */
|
|
1421
|
+
const SETTINGS_CACHE_MAX = 64;
|
|
1422
|
+
|
|
1423
|
+
/** The last parsed value of each settings text, bounded like the file cache. */
|
|
1424
|
+
const parsedSettings = new Map<string, ParsedSettings>();
|
|
1425
|
+
|
|
1426
|
+
/** A copy of a parsed value, so one caller cannot change what another reads. */
|
|
1427
|
+
function copyParsed(value: ParsedSettings): ParsedSettings {
|
|
1428
|
+
return {
|
|
1429
|
+
settings: structuredClone(value.settings),
|
|
1430
|
+
worktreeField: value.worktreeField,
|
|
1431
|
+
};
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
/** Parses and validates a settings text, reusing the last result for that text. */
|
|
1435
|
+
function parseSettingsText(path: string, text: string): ParsedSettings {
|
|
1436
|
+
const kept = parsedSettings.get(text);
|
|
1437
|
+
if (kept !== undefined) {
|
|
1438
|
+
parsedSettings.delete(text);
|
|
1439
|
+
parsedSettings.set(text, kept);
|
|
1440
|
+
return copyParsed(kept);
|
|
1441
|
+
}
|
|
1298
1442
|
let parsed: unknown;
|
|
1299
1443
|
try {
|
|
1300
1444
|
parsed = JSON.parse(text);
|
|
@@ -1302,20 +1446,87 @@ function settingsFromText(
|
|
|
1302
1446
|
throw new DevError("dev.json", `invalid JSON in ${path}: ${String(error)}`);
|
|
1303
1447
|
}
|
|
1304
1448
|
const settings = validateDevSettings(parsed);
|
|
1305
|
-
const
|
|
1449
|
+
const worktreeField =
|
|
1306
1450
|
isRecord(parsed) &&
|
|
1307
1451
|
parsed.worktreeRoot === undefined &&
|
|
1308
1452
|
parsed.worktrees !== undefined
|
|
1309
1453
|
? "worktrees"
|
|
1310
1454
|
: "worktreeRoot";
|
|
1455
|
+
const value = { settings, worktreeField };
|
|
1456
|
+
parsedSettings.set(text, value);
|
|
1457
|
+
if (parsedSettings.size > SETTINGS_CACHE_MAX) {
|
|
1458
|
+
const oldest = parsedSettings.keys().next().value;
|
|
1459
|
+
if (oldest !== undefined) parsedSettings.delete(oldest);
|
|
1460
|
+
}
|
|
1461
|
+
return copyParsed(value);
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
interface CachedSettingsText {
|
|
1465
|
+
readonly mtimeNs: bigint;
|
|
1466
|
+
readonly ctimeNs: bigint;
|
|
1467
|
+
readonly size: bigint;
|
|
1468
|
+
readonly ino: bigint;
|
|
1469
|
+
readonly text: string;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
/** The last text read from each settings file, with the stat that matched it. */
|
|
1473
|
+
const settingsTexts = new Map<string, CachedSettingsText>();
|
|
1474
|
+
|
|
1475
|
+
/** Reads a settings file, unless its stat says it is the file already read. */
|
|
1476
|
+
function readSettingsText(path: string): string {
|
|
1477
|
+
const stat = statSync(path, { bigint: true });
|
|
1478
|
+
const kept = settingsTexts.get(path);
|
|
1479
|
+
if (
|
|
1480
|
+
kept !== undefined &&
|
|
1481
|
+
kept.mtimeNs === stat.mtimeNs &&
|
|
1482
|
+
kept.ctimeNs === stat.ctimeNs &&
|
|
1483
|
+
kept.size === stat.size &&
|
|
1484
|
+
kept.ino === stat.ino
|
|
1485
|
+
) {
|
|
1486
|
+
settingsTexts.delete(path);
|
|
1487
|
+
settingsTexts.set(path, kept);
|
|
1488
|
+
return kept.text;
|
|
1489
|
+
}
|
|
1490
|
+
const text = readFileSync(path, "utf8");
|
|
1491
|
+
settingsTexts.set(path, {
|
|
1492
|
+
mtimeNs: stat.mtimeNs,
|
|
1493
|
+
ctimeNs: stat.ctimeNs,
|
|
1494
|
+
size: stat.size,
|
|
1495
|
+
ino: stat.ino,
|
|
1496
|
+
text,
|
|
1497
|
+
});
|
|
1498
|
+
if (settingsTexts.size > SETTINGS_CACHE_MAX) {
|
|
1499
|
+
const oldest = settingsTexts.keys().next().value;
|
|
1500
|
+
if (oldest !== undefined) settingsTexts.delete(oldest);
|
|
1501
|
+
}
|
|
1502
|
+
return text;
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
/**
|
|
1506
|
+
* Checks the paths a settings value references. These run on every read, even
|
|
1507
|
+
* when the parsed value came from the cache: a skill or a stage's workerBrief
|
|
1508
|
+
* can move or disappear while dev.json stays the same.
|
|
1509
|
+
*/
|
|
1510
|
+
function checkSettingsPaths(
|
|
1511
|
+
repositoryPath: string,
|
|
1512
|
+
parsed: ParsedSettings,
|
|
1513
|
+
): void {
|
|
1514
|
+
const { settings, worktreeField } = parsed;
|
|
1311
1515
|
assertInsideRepository(
|
|
1312
1516
|
repositoryPath,
|
|
1313
1517
|
resolve(repositoryPath, settings.worktreeRoot),
|
|
1314
|
-
|
|
1518
|
+
worktreeField,
|
|
1315
1519
|
);
|
|
1520
|
+
settings.skills.forEach((skill, index) => {
|
|
1521
|
+
assertInsideRepository(
|
|
1522
|
+
repositoryPath,
|
|
1523
|
+
resolve(repositoryPath, skill),
|
|
1524
|
+
`skills[${index}]`,
|
|
1525
|
+
);
|
|
1526
|
+
});
|
|
1316
1527
|
for (const [name, flow] of Object.entries(settings.flows ?? {})) {
|
|
1317
1528
|
flow.stages.forEach((stage, index) => {
|
|
1318
|
-
if (stage.stage !== "
|
|
1529
|
+
if (stage.stage !== "code" || stage.workerBrief === undefined) return;
|
|
1319
1530
|
const field = `flows.${name}.stages[${index}].workerBrief`;
|
|
1320
1531
|
if (isAbsolute(stage.workerBrief)) {
|
|
1321
1532
|
throw new DevError(field, "must be a path relative to the repository");
|
|
@@ -1327,7 +1538,17 @@ function settingsFromText(
|
|
|
1327
1538
|
assertInsideRepository(repositoryPath, file, field);
|
|
1328
1539
|
});
|
|
1329
1540
|
}
|
|
1330
|
-
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
/** Parses and checks the text of a settings file for the repository at `repositoryPath`. */
|
|
1544
|
+
function settingsFromText(
|
|
1545
|
+
repositoryPath: string,
|
|
1546
|
+
path: string,
|
|
1547
|
+
text: string,
|
|
1548
|
+
): ReadSettings {
|
|
1549
|
+
const parsed = parseSettingsText(path, text);
|
|
1550
|
+
checkSettingsPaths(repositoryPath, parsed);
|
|
1551
|
+
return { settings: parsed.settings, text };
|
|
1331
1552
|
}
|
|
1332
1553
|
|
|
1333
1554
|
/** Reads the file as it is now; any problem with it is thrown. */
|
|
@@ -1339,11 +1560,11 @@ function readSettingsNow(repositoryPath: string): ReadSettings {
|
|
|
1339
1560
|
resolve(repositoryPath, DEFAULT_DEV_SETTINGS.worktreeRoot),
|
|
1340
1561
|
"worktreeRoot",
|
|
1341
1562
|
);
|
|
1342
|
-
return { settings:
|
|
1563
|
+
return { settings: defaultDevSettings(), text: "" };
|
|
1343
1564
|
}
|
|
1344
1565
|
let text: string;
|
|
1345
1566
|
try {
|
|
1346
|
-
text =
|
|
1567
|
+
text = readSettingsText(path);
|
|
1347
1568
|
} catch (error) {
|
|
1348
1569
|
throw new DevError("dev.json", `cannot read ${path}: ${String(error)}`);
|
|
1349
1570
|
}
|
|
@@ -1358,7 +1579,7 @@ function readSettingsNow(repositoryPath: string): ReadSettings {
|
|
|
1358
1579
|
const lastValid = new Map<string, ReadSettings>();
|
|
1359
1580
|
|
|
1360
1581
|
function keptFile(home: string, repositoryPath: string): string {
|
|
1361
|
-
const key =
|
|
1582
|
+
const key = repositoryPathKey(repositoryPath);
|
|
1362
1583
|
return join(home, "dev", "settings", `${key}.json`);
|
|
1363
1584
|
}
|
|
1364
1585
|
|
|
@@ -1375,10 +1596,11 @@ function keep(repositoryPath: string, read: ReadSettings): void {
|
|
|
1375
1596
|
if (home === undefined) return;
|
|
1376
1597
|
try {
|
|
1377
1598
|
const file = keptFile(home, repositoryPath);
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1599
|
+
writeJsonAtomicSync(
|
|
1600
|
+
file,
|
|
1601
|
+
{ path: repositoryPath, text: read.text },
|
|
1602
|
+
{ newline: false },
|
|
1603
|
+
);
|
|
1382
1604
|
} catch {
|
|
1383
1605
|
// The copy is a convenience for the next process; the memory copy stays.
|
|
1384
1606
|
}
|
|
@@ -1415,7 +1637,7 @@ function readDefaults(repositoryPath: string): ReadSettings {
|
|
|
1415
1637
|
resolve(repositoryPath, DEFAULT_DEV_SETTINGS.worktreeRoot),
|
|
1416
1638
|
"worktreeRoot",
|
|
1417
1639
|
);
|
|
1418
|
-
return { settings:
|
|
1640
|
+
return { settings: defaultDevSettings(), text: "" };
|
|
1419
1641
|
}
|
|
1420
1642
|
|
|
1421
1643
|
/**
|
|
@@ -1424,9 +1646,7 @@ function readDefaults(repositoryPath: string): ReadSettings {
|
|
|
1424
1646
|
* not valid never stops work: the last valid settings stay in force. Only a
|
|
1425
1647
|
* repository that never had valid settings gets the error.
|
|
1426
1648
|
*/
|
|
1427
|
-
export
|
|
1428
|
-
repositoryPath: string,
|
|
1429
|
-
): Promise<DevSettings> {
|
|
1649
|
+
export function readDevSettingsNow(repositoryPath: string): DevSettings {
|
|
1430
1650
|
try {
|
|
1431
1651
|
const read = readSettingsNow(repositoryPath);
|
|
1432
1652
|
keep(repositoryPath, read);
|
|
@@ -1438,13 +1658,41 @@ export async function readDevSettings(
|
|
|
1438
1658
|
}
|
|
1439
1659
|
}
|
|
1440
1660
|
|
|
1661
|
+
/** Reads a repository's settings; an action's schema uses the synchronous form. */
|
|
1662
|
+
export async function readDevSettings(
|
|
1663
|
+
repositoryPath: string,
|
|
1664
|
+
): Promise<DevSettings> {
|
|
1665
|
+
return readDevSettingsNow(repositoryPath);
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
/**
|
|
1669
|
+
* What is wrong with a dev.json value that is about to be written, or
|
|
1670
|
+
* undefined when dev would accept it. The reason is dev's own, as it reads it
|
|
1671
|
+
* when it loads the file.
|
|
1672
|
+
*/
|
|
1673
|
+
export function settingsValueProblem(
|
|
1674
|
+
repositoryPath: string,
|
|
1675
|
+
value: unknown,
|
|
1676
|
+
): string | undefined {
|
|
1677
|
+
try {
|
|
1678
|
+
settingsFromText(
|
|
1679
|
+
repositoryPath,
|
|
1680
|
+
join(repositoryPath, DEV_SETTINGS_FILE),
|
|
1681
|
+
JSON.stringify(value),
|
|
1682
|
+
);
|
|
1683
|
+
return undefined;
|
|
1684
|
+
} catch (error) {
|
|
1685
|
+
return messageOf(error);
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1441
1689
|
/** What is wrong with the repository's settings file now, or undefined when it is valid. */
|
|
1442
1690
|
export function settingsProblem(repositoryPath: string): string | undefined {
|
|
1443
1691
|
try {
|
|
1444
1692
|
keep(repositoryPath, readSettingsNow(repositoryPath));
|
|
1445
1693
|
return undefined;
|
|
1446
1694
|
} catch (error) {
|
|
1447
|
-
return
|
|
1695
|
+
return messageOf(error);
|
|
1448
1696
|
}
|
|
1449
1697
|
}
|
|
1450
1698
|
|
|
@@ -1453,9 +1701,6 @@ export function hasValidSettings(repositoryPath: string): boolean {
|
|
|
1453
1701
|
return recall(repositoryPath) !== undefined;
|
|
1454
1702
|
}
|
|
1455
1703
|
|
|
1456
|
-
/** An alias for callers that name the file rather than the plugin. */
|
|
1457
|
-
export const readRepositorySettings = readDevSettings;
|
|
1458
|
-
|
|
1459
1704
|
/** The absolute path of the brief a worker reads, whether it exists or not. */
|
|
1460
1705
|
export function workerBriefPath(
|
|
1461
1706
|
repositoryPath: string,
|