@operad-io/dev 0.1.1 → 0.3.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.
Files changed (50) hide show
  1. package/README.md +1 -1
  2. package/dev.schema.json +53 -31
  3. package/package.json +9 -6
  4. package/skills/git/SKILL.md +70 -0
  5. package/skills/setup/SKILL.md +74 -0
  6. package/src/access-grants.ts +59 -0
  7. package/src/actions.ts +81 -17
  8. package/src/announce.ts +134 -17
  9. package/src/chat.ts +586 -36
  10. package/src/check-host.ts +111 -0
  11. package/src/check-load.ts +67 -0
  12. package/src/check.ts +45 -22
  13. package/src/clock.ts +29 -0
  14. package/src/clone-chat.ts +32 -0
  15. package/src/commands.ts +103 -34
  16. package/src/create-actions.ts +210 -0
  17. package/src/flaky.ts +45 -29
  18. package/src/flow-compiler.ts +156 -69
  19. package/src/followups.ts +20 -22
  20. package/src/gate.ts +254 -88
  21. package/src/git-state.ts +155 -0
  22. package/src/git.ts +92 -4
  23. package/src/index.ts +52 -6
  24. package/src/integrate.ts +162 -62
  25. package/src/integration-queue.ts +23 -10
  26. package/src/lock.ts +101 -5
  27. package/src/mainclone.ts +61 -5
  28. package/src/model-error.ts +70 -0
  29. package/src/model.ts +61 -35
  30. package/src/notcode.ts +51 -15
  31. package/src/places.ts +2 -2
  32. package/src/prepare.ts +7 -2
  33. package/src/project-flows.ts +135 -4
  34. package/src/project-settings.ts +110 -3
  35. package/src/register-requests.ts +121 -0
  36. package/src/repository-key.ts +4 -0
  37. package/src/rerun.ts +23 -7
  38. package/src/retry.ts +2 -12
  39. package/src/rework.ts +8 -0
  40. package/src/schedule.ts +342 -93
  41. package/src/service.ts +241 -185
  42. package/src/settings.ts +409 -65
  43. package/src/setup-git.ts +366 -0
  44. package/src/standing.ts +23 -6
  45. package/src/step-edge.ts +22 -0
  46. package/src/steps.ts +945 -179
  47. package/src/throughput.ts +4 -21
  48. package/src/timeouts.ts +10 -2
  49. package/src/views.ts +325 -86
  50. package/src/waits.ts +59 -0
@@ -5,12 +5,15 @@
5
5
  * one, or whose name dev.json also defines.
6
6
  */
7
7
 
8
+ import { messageOf } from "@operad-io/engine";
8
9
  import { createHash } from "node:crypto";
9
10
  import { existsSync, readdirSync, statSync } from "node:fs";
10
11
  import { join } from "node:path";
11
12
  import { pathToFileURL } from "node:url";
12
13
  import type { FlowDefinition, StepShape } from "@operad-io/engine";
13
14
  import type { DevSettings } from "./settings.ts";
15
+ import type { DevStage } from "./flow-compiler.ts";
16
+ import { isWorkQuestionWait } from "./waits.ts";
14
17
  import { isRecord } from "@operad-io/engine";
15
18
 
16
19
  const FLOW_SUFFIX = ".flow.ts";
@@ -40,7 +43,7 @@ function targetsOf(step: Record<string, unknown>): string[] {
40
43
  /**
41
44
  * The reason a flow breaks a hard rule, or undefined when it keeps both: the
42
45
  * step before a finished end is integrate (or the cleanup that follows it), and
43
- * there is at least one check, review or human step.
46
+ * there is at least one test, review or human step.
44
47
  */
45
48
  export function flowProblem(flow: unknown): string | undefined {
46
49
  if (!isRecord(flow) || !Array.isArray(flow.steps) || typeof flow.entry !== "string") {
@@ -49,9 +52,14 @@ export function flowProblem(flow: unknown): string | undefined {
49
52
  const steps = flow.steps.filter(isRecord);
50
53
  const decides = steps.some((step) => {
51
54
  const use = useOf(step);
52
- return step.kind === "wait_person" || use === "dev/verify" || use === "dev/review";
55
+ // A worker's own question keeps the worker going; it is not a step that
56
+ // asks a person what the task should do.
57
+ const asked = step.kind === "wait_person" && !(
58
+ typeof step.id === "string" && isWorkQuestionWait(step.id)
59
+ );
60
+ return asked || use === "dev/verify" || use === "dev/review";
53
61
  });
54
- if (!decides) return "needs at least one check, review or human step";
62
+ if (!decides) return "needs at least one test, review or human step";
55
63
  if (!steps.some((step) => useOf(step) === "dev/integrate")) {
56
64
  return "has no integrate step: a change reaches main only through integrate";
57
65
  }
@@ -136,7 +144,7 @@ export async function loadProjectFlows(
136
144
  } catch (error) {
137
145
  refused.set(
138
146
  name,
139
- `${where}: could not be loaded: ${error instanceof Error ? error.message : String(error)}`,
147
+ `${where}: could not be loaded: ${messageOf(error)}`,
140
148
  );
141
149
  continue;
142
150
  }
@@ -158,3 +166,126 @@ export async function loadProjectFlows(
158
166
  }
159
167
  return { flows, refused };
160
168
  }
169
+
170
+ /**
171
+ * The names `dev.flowList` shows for a repository, with `default` first. It
172
+ * names a TypeScript file without loading it, so an action's schema can list
173
+ * the choices synchronously.
174
+ */
175
+ export function flowNamesOf(
176
+ repositoryPath: string,
177
+ settings: DevSettings,
178
+ ): readonly string[] {
179
+ const names = Object.keys(settings.flows);
180
+ const directory = join(repositoryPath, PROJECT_FLOWS_DIR);
181
+ if (existsSync(directory)) {
182
+ const files = readdirSync(directory)
183
+ .filter((item) => item.endsWith(FLOW_SUFFIX))
184
+ .sort();
185
+ for (const file of files) names.push(file.slice(0, -FLOW_SUFFIX.length));
186
+ }
187
+ const unique = [...new Set(names)];
188
+ const at = unique.indexOf("default");
189
+ if (at < 0) {
190
+ unique.unshift("default");
191
+ } else if (at > 0) {
192
+ unique.splice(at, 1);
193
+ unique.unshift("default");
194
+ }
195
+ return unique;
196
+ }
197
+
198
+ /** One flow of a repository, as a client lists it. */
199
+ export interface FlowInfo {
200
+ readonly name: string;
201
+ /** Where the flow comes from. */
202
+ readonly source: "dev.json" | "typescript" | "built-in";
203
+ /** A dev.json flow or the built-in default: its stages. */
204
+ readonly stages?: readonly unknown[];
205
+ /** A TypeScript flow: the steps dev reads when it loads the file. */
206
+ readonly steps?: readonly { readonly id: string; readonly kind: string; readonly use?: string }[];
207
+ /** Why dev refuses the flow; the flow starts no task. */
208
+ readonly refused?: string;
209
+ }
210
+
211
+ /**
212
+ * The stages of the built-in default flow, with the parameters this
213
+ * repository's `worker`, `reviewer` and `gate` settings give them (ADR 0020
214
+ * D7), so a client can show them and start an edited copy from them. These
215
+ * three settings carry no secrets.
216
+ */
217
+ export function defaultFlowStages(settings: DevSettings): DevStage[] {
218
+ return [
219
+ { stage: "code", use: settings.worker.use, args: [...settings.worker.args] },
220
+ { stage: "test", commands: [...settings.gate.commands] },
221
+ { stage: "review", use: settings.reviewer.use, args: [...settings.reviewer.args] },
222
+ { stage: "human" },
223
+ ];
224
+ }
225
+
226
+ /**
227
+ * Every flow a repository has: those of dev.json, the TypeScript files in
228
+ * `.operad/flows`, and the built-in default when nothing names `default`. A
229
+ * TypeScript file dev refuses is listed with dev's reason.
230
+ */
231
+ export async function listRepositoryFlows(
232
+ repositoryPath: string,
233
+ repository: string,
234
+ settings: DevSettings,
235
+ ): Promise<FlowInfo[]> {
236
+ const infos: FlowInfo[] = Object.entries(settings.flows).map(([name, flow]) => ({
237
+ name,
238
+ source: "dev.json",
239
+ stages: flow.stages as readonly unknown[],
240
+ }));
241
+ const loaded = await loadProjectFlows(repositoryPath, repository, settings);
242
+ const directory = join(repositoryPath, PROJECT_FLOWS_DIR);
243
+ const files = existsSync(directory)
244
+ ? readdirSync(directory).filter((file) => file.endsWith(FLOW_SUFFIX)).sort()
245
+ : [];
246
+ for (const file of files) {
247
+ const name = file.slice(0, -FLOW_SUFFIX.length);
248
+ const reason = loaded.refused.get(name);
249
+ const flow = loaded.flows.get(name);
250
+ infos.push({
251
+ name,
252
+ source: "typescript",
253
+ ...(flow === undefined
254
+ ? {}
255
+ : {
256
+ steps: flow.steps.map((step) => {
257
+ const use = useOf(step as unknown as Record<string, unknown>);
258
+ return {
259
+ id: step.id,
260
+ kind: step.kind,
261
+ ...(use === undefined ? {} : { use }),
262
+ };
263
+ }),
264
+ }),
265
+ ...(reason === undefined ? {} : { refused: reason }),
266
+ });
267
+ }
268
+ if (!infos.some((info) => info.name === "default")) {
269
+ infos.unshift({
270
+ name: "default",
271
+ source: "built-in",
272
+ stages: defaultFlowStages(settings),
273
+ });
274
+ }
275
+ return infos;
276
+ }
277
+
278
+ /**
279
+ * The reason a dev.json value cannot be written because of a TypeScript flow:
280
+ * a flow of the same name is in `.operad/flows`.
281
+ */
282
+ export function flowClash(repositoryPath: string, flows: unknown): string | undefined {
283
+ if (!isRecord(flows)) return undefined;
284
+ for (const name of Object.keys(flows)) {
285
+ const where = `${PROJECT_FLOWS_DIR}/${name}${FLOW_SUFFIX}`;
286
+ if (existsSync(join(repositoryPath, where))) {
287
+ return `flow "${name}" is defined in dev.json and in ${where}; keep one`;
288
+ }
289
+ }
290
+ return undefined;
291
+ }
@@ -7,16 +7,78 @@
7
7
  * merges.
8
8
  */
9
9
 
10
- import type { ProjectSettingsDeclaration } from "@operad-io/engine";
11
- import { listRepositories } from "./service.ts";
10
+ import { messageOf } from "@operad-io/engine";
11
+ import type { ObjectStore, ProjectSettingsDeclaration, SettingsRepository } from "@operad-io/engine";
12
+ import { flowClash, listRepositoryFlows } from "./project-flows.ts";
13
+ import { defaultDevSettings, readDevSettings, settingsProblem, settingsValueProblem, useNewStageNames } from "./settings.ts";
14
+ import { cloneHolder, listRepositories } from "./service.ts";
15
+ import type { JsonValue } from "@operad-io/engine";
16
+
17
+ /** The store each listed repository came from: a settings save looks for the task holding its clone there. */
18
+ const storeOf = new WeakMap<SettingsRepository, ObjectStore>();
12
19
 
13
20
  export const DEV_PROJECT_SETTINGS: ProjectSettingsDeclaration = {
14
21
  repositories: async ({ store }) =>
15
- (await listRepositories(store)).map(({ name, path }) => ({ name, path })),
22
+ (await listRepositories(store)).map(({ name, path }) => {
23
+ const repository = { name, path };
24
+ storeOf.set(repository, store);
25
+ return repository;
26
+ }),
16
27
  files: [
17
28
  {
18
29
  name: "dev",
19
30
  path: "dev.json",
31
+ // dev's own check of the file as it would be written: its schema and rules
32
+ // (ADR 0020 D4), then the name clash with a TypeScript flow (D6). It runs
33
+ // for a flow change only, so an invalid flow already in the file does not
34
+ // block an unrelated setting.
35
+ check: async ({ repository, value, name }) => {
36
+ // dev reads dev.json once when an attempt starts (ADR 0039 D6): a save
37
+ // while a branch-mode task holds the clone would change what the next
38
+ // attempt reads from the branch it started on, so none is made.
39
+ const store = storeOf.get(repository);
40
+ const holder = store === undefined ? undefined : await cloneHolder(store, repository.name);
41
+ if (holder !== undefined) {
42
+ return `dev.json cannot be saved while ${holder} holds the main clone on its own branch: merge or cancel ${holder} first`;
43
+ }
44
+ if (name !== "dev.flows" && !name.startsWith("dev.flows.")) return undefined;
45
+ const problem =
46
+ settingsValueProblem(repository.path, value) ??
47
+ flowClash(repository.path, value.flows);
48
+ if (problem === undefined) useNewStageNames(value);
49
+ return problem;
50
+ },
51
+ derived: async ({ repository }) => {
52
+ const problem = settingsProblem(repository.path);
53
+ let settings;
54
+ try {
55
+ settings = await readDevSettings(repository.path);
56
+ } catch (error) {
57
+ // The file was never valid, so there are no dev.json flows to list;
58
+ // the read-only list stays and says why, beside the TypeScript flows.
59
+ const reason =
60
+ problem ?? (messageOf(error));
61
+ const list = await listRepositoryFlows(
62
+ repository.path,
63
+ repository.name,
64
+ defaultDevSettings(),
65
+ );
66
+ return {
67
+ flowList: [
68
+ { name: "dev.json", source: "dev.json", refused: reason },
69
+ ...list,
70
+ ] as unknown as JsonValue,
71
+ };
72
+ }
73
+ const list = await listRepositoryFlows(repository.path, repository.name, settings);
74
+ return {
75
+ flowList: (
76
+ problem === undefined
77
+ ? list
78
+ : [{ name: "dev.json", source: "dev.json", refused: problem }, ...list]
79
+ ) as unknown as JsonValue,
80
+ };
81
+ },
20
82
  schema: {
21
83
  type: "object",
22
84
  $defs: {
@@ -49,13 +111,26 @@ export const DEV_PROJECT_SETTINGS: ProjectSettingsDeclaration = {
49
111
  properties: {
50
112
  concurrency: {
51
113
  type: "integer",
114
+ title: "Tasks at once",
52
115
  minimum: 1,
53
116
  editable: true,
54
117
  description:
55
118
  "The most of this repository's tasks that run at the same time, on top of the worker counts. Unset means the workers' own counts decide.",
56
119
  },
120
+ workIn: {
121
+ title: "Work in",
122
+ oneOf: [
123
+ { const: "branch", title: "A branch in this folder" },
124
+ { const: "worktree", title: "A separate worktree" },
125
+ ],
126
+ default: "worktree",
127
+ editable: true,
128
+ description:
129
+ "Where a task's changes are made. branch (A branch in this folder): dev makes the task's branch in the main clone and the task works there, one task at a time; it cannot be combined with a concurrency above 1 or workers that add up to more than 1. worktree (A separate worktree): each task has its own worktree.",
130
+ },
57
131
  autoDefault: {
58
132
  type: "string",
133
+ title: "Auto for new plans",
59
134
  enum: ["off", "run", "merge"],
60
135
  default: "off",
61
136
  editable: true,
@@ -63,11 +138,32 @@ export const DEV_PROJECT_SETTINGS: ProjectSettingsDeclaration = {
63
138
  description:
64
139
  "The auto level a new plan starts at: off waits for you to start tasks, run starts them by itself, merge also merges a task whose review passed. Plans already made keep their level.",
65
140
  },
141
+ flows: {
142
+ type: "object",
143
+ title: "Custom flows",
144
+ editable: true,
145
+ description:
146
+ "The repository's own flows, by name. A flow is { \"stages\": [...] }, each stage one of code, test, review or human (the older names work and check still load); dev checks the flow when it is saved and refuses one that breaks its rules. A name may also be changed on its own (dev.flows.<name>); null removes it.",
147
+ additionalProperties: {
148
+ type: "object",
149
+ properties: {
150
+ stages: { type: "array", items: { type: "object" } },
151
+ },
152
+ },
153
+ },
154
+ flowList: {
155
+ type: "array",
156
+ title: "Flows",
157
+ items: { type: "object" },
158
+ description:
159
+ "Every flow of the repository, read only: its name, where it comes from (dev.json, typescript or built-in), its stages for a dev.json flow or the built-in default, the steps dev reads for a TypeScript flow, or why dev refuses the file.",
160
+ },
66
161
  gate: {
67
162
  type: "object",
68
163
  properties: {
69
164
  commands: {
70
165
  type: "array",
166
+ title: "Check commands",
71
167
  items: { $ref: "#/$defs/checkCommand" },
72
168
  default: [],
73
169
  editable: true,
@@ -76,6 +172,7 @@ export const DEV_PROJECT_SETTINGS: ProjectSettingsDeclaration = {
76
172
  },
77
173
  commandTimeoutSecs: {
78
174
  type: "number",
175
+ title: "Check timeout",
79
176
  minimum: 1,
80
177
  default: 1800,
81
178
  editable: true,
@@ -84,6 +181,7 @@ export const DEV_PROJECT_SETTINGS: ProjectSettingsDeclaration = {
84
181
  },
85
182
  stallSecs: {
86
183
  type: "number",
184
+ title: "Check stall limit",
87
185
  minimum: 1,
88
186
  editable: true,
89
187
  description:
@@ -96,6 +194,7 @@ export const DEV_PROJECT_SETTINGS: ProjectSettingsDeclaration = {
96
194
  properties: {
97
195
  use: {
98
196
  type: "string",
197
+ title: "Reviewer",
99
198
  minLength: 1,
100
199
  default: "radian/agent",
101
200
  editable: true,
@@ -104,6 +203,7 @@ export const DEV_PROJECT_SETTINGS: ProjectSettingsDeclaration = {
104
203
  },
105
204
  args: {
106
205
  type: "array",
206
+ title: "Reviewer arguments",
107
207
  items: { type: "string" },
108
208
  default: [],
109
209
  editable: true,
@@ -112,6 +212,7 @@ export const DEV_PROJECT_SETTINGS: ProjectSettingsDeclaration = {
112
212
  },
113
213
  timeoutSecs: {
114
214
  type: "number",
215
+ title: "Review timeout",
115
216
  minimum: 1,
116
217
  default: 600,
117
218
  editable: true,
@@ -120,6 +221,7 @@ export const DEV_PROJECT_SETTINGS: ProjectSettingsDeclaration = {
120
221
  },
121
222
  fixLevel: {
122
223
  type: "string",
224
+ title: "Reviewer rework threshold",
123
225
  enum: ["critical", "major", "minor"],
124
226
  default: "major",
125
227
  editable: true,
@@ -146,6 +248,7 @@ export const DEV_PROJECT_SETTINGS: ProjectSettingsDeclaration = {
146
248
  properties: {
147
249
  critical: {
148
250
  type: "string",
251
+ title: "Critical level",
149
252
  editable: true,
150
253
  confirm: true,
151
254
  description:
@@ -153,6 +256,7 @@ export const DEV_PROJECT_SETTINGS: ProjectSettingsDeclaration = {
153
256
  },
154
257
  major: {
155
258
  type: "string",
259
+ title: "Major level",
156
260
  editable: true,
157
261
  confirm: true,
158
262
  description:
@@ -160,6 +264,7 @@ export const DEV_PROJECT_SETTINGS: ProjectSettingsDeclaration = {
160
264
  },
161
265
  minor: {
162
266
  type: "string",
267
+ title: "Minor level",
163
268
  editable: true,
164
269
  confirm: true,
165
270
  description:
@@ -169,6 +274,7 @@ export const DEV_PROJECT_SETTINGS: ProjectSettingsDeclaration = {
169
274
  },
170
275
  rules: {
171
276
  type: "array",
277
+ title: "Review rules",
172
278
  items: { type: "string" },
173
279
  editable: true,
174
280
  confirm: true,
@@ -177,6 +283,7 @@ export const DEV_PROJECT_SETTINGS: ProjectSettingsDeclaration = {
177
283
  },
178
284
  fixLevel: {
179
285
  type: "string",
286
+ title: "Rework threshold",
180
287
  enum: ["critical", "major", "minor"],
181
288
  editable: true,
182
289
  confirm: true,
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Repositories that an approved Setup Dev asks `dev` to register (ADR 0030
3
+ * D15). The `bot` plugin leaves one file per request in `<home>/dev-register/`
4
+ * because `dev` may not be loaded when the proposal is approved; `dev` reads
5
+ * the directory on every tick, registers each repository as `operad dev repo
6
+ * add` does and removes the file. A request that cannot be registered stays,
7
+ * with the reason written into it, and is shown as a pending item until it is
8
+ * fixed or removed.
9
+ *
10
+ * A request with `"kind": "setup-git"` (ADR 0039 D8) asks for git to be set up in
11
+ * a folder instead: it carries the `.gitignore` text, the approved paths and,
12
+ * when git has none, the name and email (see `setup-git.ts`). It is run the
13
+ * same way and a failure stays in the file the same way.
14
+ */
15
+
16
+ import { existsSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
17
+ import { join } from "node:path";
18
+ import { isRecord, messageOf, type ObjectStore, type StandingItem } from "@operad-io/engine";
19
+ import { addRepository } from "./service.ts";
20
+ import { applySetupGit, type SetupGitRequest } from "./setup-git.ts";
21
+
22
+ /** The directory under the home that holds the requests. */
23
+ export function registerRequestsDirectory(home: string): string {
24
+ return join(home, "dev-register");
25
+ }
26
+
27
+ interface Request {
28
+ readonly file: string;
29
+ readonly path: string;
30
+ readonly error: string | undefined;
31
+ /** The whole file, kept when a failure is written back. */
32
+ readonly body: Record<string, unknown>;
33
+ /** Set for a request to set up git. */
34
+ readonly setupGit: SetupGitRequest | undefined;
35
+ }
36
+
37
+ function setupGitOf(body: Record<string, unknown>, path: string): SetupGitRequest | undefined {
38
+ if (body.kind !== "setup-git") return undefined;
39
+ const paths = Array.isArray(body.paths) ? body.paths.filter((p): p is string => typeof p === "string") : [];
40
+ const identity = isRecord(body.identity) ? body.identity : undefined;
41
+ return {
42
+ path,
43
+ gitignore: typeof body.gitignore === "string" ? body.gitignore : "",
44
+ paths,
45
+ ...(identity !== undefined && typeof identity.name === "string" && typeof identity.email === "string"
46
+ ? { identity: { name: identity.name, email: identity.email } }
47
+ : {}),
48
+ };
49
+ }
50
+
51
+ function readRequests(home: string): Request[] {
52
+ const directory = registerRequestsDirectory(home);
53
+ if (!existsSync(directory)) return [];
54
+ const found: Request[] = [];
55
+ let names: string[];
56
+ try {
57
+ names = readdirSync(directory).sort();
58
+ } catch {
59
+ // An unreadable directory holds no requests; it must not stop the tick.
60
+ return found;
61
+ }
62
+ for (const name of names) {
63
+ if (!name.endsWith(".json")) continue;
64
+ const file = join(directory, name);
65
+ try {
66
+ const parsed: unknown = JSON.parse(readFileSync(file, "utf8"));
67
+ if (!isRecord(parsed) || typeof parsed.path !== "string") continue;
68
+ found.push({
69
+ file,
70
+ path: parsed.path,
71
+ error: typeof parsed.error === "string" ? parsed.error : undefined,
72
+ body: parsed,
73
+ setupGit: setupGitOf(parsed, parsed.path),
74
+ });
75
+ } catch {
76
+ // A file that is not written yet or is not a request is left alone.
77
+ }
78
+ }
79
+ return found;
80
+ }
81
+
82
+ /** Registers every requested repository; a failure stays in its file. */
83
+ export async function registerRequested(ctx: {
84
+ readonly home: string;
85
+ readonly cwd: string;
86
+ readonly store: ObjectStore;
87
+ }): Promise<void> {
88
+ for (const request of readRequests(ctx.home)) {
89
+ try {
90
+ if (request.setupGit !== undefined) {
91
+ await applySetupGit(request.setupGit, { lock: { home: ctx.home } });
92
+ } else {
93
+ await addRepository(ctx.store, { path: request.path, cwd: ctx.cwd });
94
+ }
95
+ rmSync(request.file, { force: true });
96
+ } catch (error) {
97
+ const message = messageOf(error);
98
+ if (message.includes("is already registered")) {
99
+ rmSync(request.file, { force: true });
100
+ continue;
101
+ }
102
+ if (message !== request.error) {
103
+ const body = request.setupGit === undefined ? { path: request.path } : request.body;
104
+ writeFileSync(request.file, `${JSON.stringify({ ...body, error: message })}\n`);
105
+ }
106
+ }
107
+ }
108
+ }
109
+
110
+ /** The pending items of requests that could not be registered. */
111
+ export function registerStanding(home: string): readonly StandingItem[] {
112
+ return readRequests(home)
113
+ .filter((request) => request.error !== undefined)
114
+ .map((request) => ({
115
+ id: `${request.setupGit === undefined ? "register" : "setup-git"}:${request.path}`,
116
+ prompt:
117
+ request.setupGit === undefined
118
+ ? `the repository ${request.path} could not be registered: ${request.error ?? ""}; fix it and it is registered on its own, or remove ${request.file}`
119
+ : `git could not be set up in ${request.path}: ${request.error ?? ""}; fix it and it is tried again on its own, or remove ${request.file}`,
120
+ }));
121
+ }
@@ -0,0 +1,4 @@
1
+ /** A stable key for a repository path, for files kept under the operad home. */
2
+ export function repositoryPathKey(repositoryPath: string): string {
3
+ return new Bun.CryptoHasher("sha1").update(repositoryPath).digest("hex");
4
+ }
package/src/rerun.ts CHANGED
@@ -36,6 +36,8 @@ export interface CheckRun {
36
36
  readonly failedBy?: ReadonlyMap<string, FailedRerun> | undefined;
37
37
  /** Set when the result is the failed test's own rerun, run alone, failing again. */
38
38
  readonly aloneRerun?: boolean | undefined;
39
+ /** Where the run's first command began writing in the log, when the step said. */
40
+ readonly logStart?: number | undefined;
39
41
  }
40
42
 
41
43
  /** The line drawn between the two runs in the check log. */
@@ -75,10 +77,10 @@ function logOf(outcome: PluginStepResult | undefined): string | undefined {
75
77
  return typeof log === "string" ? log : undefined;
76
78
  }
77
79
 
78
- /** Where the step's own output began in the shared log; 0 when it does not say. */
79
- function logStartOf(outcome: PluginStepResult | undefined): number {
80
+ /** Where the step's own output began in the shared log; undefined when it does not say. */
81
+ function logStartOf(outcome: PluginStepResult | undefined): number | undefined {
80
82
  const start = dataOf(outcome).logStart;
81
- return typeof start === "number" ? start : 0;
83
+ return typeof start === "number" ? start : undefined;
82
84
  }
83
85
 
84
86
  /** How many bytes the log holds now; a log that cannot be read holds none. */
@@ -119,6 +121,8 @@ export async function runCheckWithRerun(
119
121
  ): Promise<CheckRun> {
120
122
  const first = await once(runStep, params, options, places);
121
123
  const firstData = dataOf(first.outcome);
124
+ const firstStart = logStartOf(first.outcome);
125
+ const started = firstStart === undefined ? {} : { logStart: firstStart };
122
126
  const failed = first.hostError !== undefined || first.outcome?.result === "fail";
123
127
  // Only a plain failure is rerun: not a cancel, not a hang.
124
128
  if (
@@ -128,7 +132,7 @@ export async function runCheckWithRerun(
128
132
  firstData.reason === "stall" ||
129
133
  first.hostError !== undefined
130
134
  ) {
131
- return { ...first, rerun: false, note: undefined, passedOnRerun: [] };
135
+ return { ...first, ...started, rerun: false, note: undefined, passedOnRerun: [] };
132
136
  }
133
137
  const label =
134
138
  typeof firstData.lineNumber === "number"
@@ -147,6 +151,7 @@ export async function runCheckWithRerun(
147
151
  ) {
148
152
  return {
149
153
  ...last,
154
+ ...started,
150
155
  rerun: true,
151
156
  passedOnRerun: [],
152
157
  note: `${label} failed, passed on rerun${attempts > 1 ? ` ${attempts}` : ""}`,
@@ -162,7 +167,7 @@ export async function runCheckWithRerun(
162
167
  break;
163
168
  }
164
169
  }
165
- return { ...last, rerun: true, note: undefined, passedOnRerun: [] };
170
+ return { ...last, ...started, rerun: true, note: undefined, passedOnRerun: [] };
166
171
  }
167
172
 
168
173
  /* ---------------------------------------------------------------------------
@@ -248,6 +253,13 @@ function describePass(names: readonly string[]): string | undefined {
248
253
  : `passed on rerun: ${names.join("; ")}`;
249
254
  }
250
255
 
256
+ export interface RunCheckBase {
257
+ readonly cwd: string;
258
+ readonly timeoutSecs?: number | undefined;
259
+ /** The environment added to the check line; the shell inherits the rest. */
260
+ readonly env?: Readonly<Record<string, string>> | undefined;
261
+ }
262
+
251
263
  /**
252
264
  * Runs a list of check commands. A list of plain strings is one `shell/check`
253
265
  * with the whole-list rerun. A command with `failed` runs alone; when it exits
@@ -255,7 +267,7 @@ function describePass(names: readonly string[]): string | undefined {
255
267
  */
256
268
  export async function runCheckCommands(
257
269
  runStep: NonNullable<StepContext["runStep"]>,
258
- base: { readonly cwd: string; readonly timeoutSecs?: number },
270
+ base: RunCheckBase,
259
271
  commands: readonly CheckCommand[],
260
272
  options: StepRunOptions,
261
273
  rerun: number,
@@ -281,6 +293,7 @@ export async function runCheckCommands(
281
293
  const passed: string[] = [];
282
294
  const failedBy = new Map<string, FailedRerun>();
283
295
  let reran = false;
296
+ let firstStart: number | undefined;
284
297
  let last: Pick<CheckRun, "outcome" | "hostError"> = {
285
298
  outcome: { result: "pass", data: { lines: 0, tail: [] } },
286
299
  hostError: undefined,
@@ -290,6 +303,7 @@ export async function runCheckCommands(
290
303
  aloneRerun = false,
291
304
  ): CheckRun => ({
292
305
  ...result,
306
+ ...(firstStart === undefined ? {} : { logStart: firstStart }),
293
307
  ...(aloneRerun ? { aloneRerun: true } : {}),
294
308
  rerun: reran,
295
309
  passedOnRerun: passed,
@@ -319,6 +333,7 @@ export async function runCheckCommands(
319
333
  index,
320
334
  );
321
335
  reran = reran || group.rerun;
336
+ firstStart ??= group.logStart;
322
337
  if (group.note !== undefined) notes.push(group.note);
323
338
  const lineNumber = dataOf(group.outcome).lineNumber;
324
339
  const outcome =
@@ -335,6 +350,7 @@ export async function runCheckCommands(
335
350
 
336
351
  const lineNumber = index + 1;
337
352
  const first = await once(runStep, paramsFor([runOf(command)]), options, places);
353
+ firstStart ??= logStartOf(first.outcome);
338
354
  const firstData = dataOf(first.outcome);
339
355
  const numbered = {
340
356
  outcome: withLineNumber(first.outcome, lineNumber),
@@ -353,7 +369,7 @@ export async function runCheckCommands(
353
369
  return finish(numbered);
354
370
  }
355
371
  const log = logOf(first.outcome);
356
- const names = failedNames(failed, readSince(log, logStartOf(first.outcome)));
372
+ const names = failedNames(failed, readSince(log, logStartOf(first.outcome) ?? 0));
357
373
  if (names.length === 0 || names.length > failed.max) return finish(numbered);
358
374
 
359
375
  reran = true;
package/src/retry.ts CHANGED
@@ -10,6 +10,7 @@ import type { PluginStepResult, StepContext } from "@operad-io/engine";
10
10
  import { reviewTestHooks, waitFor } from "./gate.ts";
11
11
  import type { RetryRecord, TaskData } from "./model.ts";
12
12
  import { DEFAULT_DEV_SETTINGS, readDevSettings } from "./settings.ts";
13
+ import { edgeParamsOf } from "./step-edge.ts";
13
14
  import { classifyStop } from "./stops.ts";
14
15
  import {
15
16
  cancelledStep,
@@ -28,17 +29,6 @@ export interface RetryParams {
28
29
  readonly result: string;
29
30
  }
30
31
 
31
- function paramsOf(params: unknown): RetryParams {
32
- const record =
33
- typeof params === "object" && params !== null && !Array.isArray(params)
34
- ? (params as Record<string, unknown>)
35
- : {};
36
- return {
37
- from: typeof record.from === "string" ? record.from : "",
38
- result: typeof record.result === "string" ? record.result : "",
39
- };
40
- }
41
-
42
32
  function attemptNumber(task: TaskData): number {
43
33
  return task.attempt?.number ?? task.attempts;
44
34
  }
@@ -63,7 +53,7 @@ export async function runRetry(
63
53
  const context = await looseTaskContext(ctx);
64
54
  const task = context.task;
65
55
  if (!claimAllows(ctx, task)) return cancelledStep();
66
- const edge = paramsOf(stepParams);
56
+ const edge = edgeParamsOf(stepParams);
67
57
  const used = usedRetry(task);
68
58
 
69
59
  const write = async (