@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
@@ -0,0 +1,210 @@
1
+ /**
2
+ * The actions that create the dev plugin's objects: a plan on a repository and
3
+ * a task on a plan. Each runs the command's creation path, so an action and its
4
+ * command cannot drift.
5
+ */
6
+
7
+ import type {
8
+ ActionArgsSchema,
9
+ ActionTypeDefinition,
10
+ ObjectStore,
11
+ StoredObject,
12
+ } from "@operad-io/engine";
13
+ import { PLAN_CREATE_TASK_RANK } from "./actions.ts";
14
+ import { createPlan, createTask } from "./commands.ts";
15
+ import {
16
+ idOfKey,
17
+ DevError,
18
+ planData,
19
+ repositoryData,
20
+ taskData,
21
+ TASK_FINAL_STATES,
22
+ type RepositoryData,
23
+ } from "./model.ts";
24
+ import { flowNamesOf } from "./project-flows.ts";
25
+ import { readDevSettingsNow } from "./settings.ts";
26
+
27
+ /** Every flow of a repository, default first, with a fallback when it cannot be read. */
28
+ function flowChoices(repository: RepositoryData | undefined): readonly string[] {
29
+ if (repository === undefined) return ["default"];
30
+ try {
31
+ return flowNamesOf(repository.path, readDevSettingsNow(repository.path));
32
+ } catch {
33
+ return ["default"];
34
+ }
35
+ }
36
+
37
+ /** The stored repository, read synchronously so an action's schema can use it. */
38
+ function repositoryNow(store: ObjectStore, name: string): RepositoryData | undefined {
39
+ const found = store.get("repo", name);
40
+ if (found instanceof Promise || found === undefined) return undefined;
41
+ return repositoryData(found.data);
42
+ }
43
+
44
+ /** The tasks of a plan, read synchronously so an action's schema can list them. */
45
+ function tasksOfPlanNow(
46
+ store: ObjectStore,
47
+ repository: string,
48
+ plan: string,
49
+ ): readonly StoredObject[] {
50
+ const found: StoredObject[] = [];
51
+ let cursor: string | undefined;
52
+ for (;;) {
53
+ const page = store.list("task", cursor === undefined ? {} : { cursor });
54
+ if (page instanceof Promise) return found;
55
+ for (const object of page.objects) {
56
+ const task = taskData(object.data);
57
+ if (task.repository === repository && task.plan === plan) found.push(object);
58
+ }
59
+ if (page.next === undefined) return found;
60
+ cursor = page.next;
61
+ }
62
+ }
63
+
64
+ function planArgs(flows: readonly string[]): ActionArgsSchema {
65
+ const choices = flows.length === 0 ? ["default"] : flows;
66
+ return {
67
+ type: "object",
68
+ properties: {
69
+ title: {
70
+ type: "string",
71
+ description: "What the plan is called.",
72
+ },
73
+ slug: {
74
+ type: "string",
75
+ description:
76
+ "The last part of the plan id, 1-48 characters of a-z, 0-9 and -; taken from the title when left out.",
77
+ },
78
+ request: {
79
+ type: "string",
80
+ role: "note",
81
+ description: "The request the plan answers, shown in its Request section.",
82
+ },
83
+ flow: {
84
+ type: "string",
85
+ enum: [...choices],
86
+ default: choices[0],
87
+ description:
88
+ "The flow the plan's tasks start with; the repository's default when left out.",
89
+ },
90
+ },
91
+ required: ["title"],
92
+ additionalProperties: false,
93
+ };
94
+ }
95
+
96
+ function taskArgs(
97
+ flows: readonly string[],
98
+ after: readonly string[],
99
+ ): ActionArgsSchema {
100
+ const choices = flows.length === 0 ? ["default"] : flows;
101
+ return {
102
+ type: "object",
103
+ properties: {
104
+ title: {
105
+ type: "string",
106
+ description: "What the task is called.",
107
+ },
108
+ slug: {
109
+ type: "string",
110
+ description:
111
+ "The last part of the task id, 1-48 characters of a-z, 0-9 and -; taken from the title when left out.",
112
+ },
113
+ brief: {
114
+ type: "string",
115
+ role: "note",
116
+ description: "The brief, the instructions for the worker.",
117
+ },
118
+ flow: {
119
+ type: "string",
120
+ enum: [...choices],
121
+ default: choices[0],
122
+ description:
123
+ "The flow the task starts with; the plan's flow when left out.",
124
+ },
125
+ after: {
126
+ type: "array",
127
+ items: { type: "string", enum: [...after] },
128
+ description:
129
+ "The plan's tasks this task waits for; each must be merged before it starts.",
130
+ },
131
+ },
132
+ required: ["title"],
133
+ additionalProperties: false,
134
+ };
135
+ }
136
+
137
+ const planAction: ActionTypeDefinition = {
138
+ name: "plan",
139
+ on: "repo",
140
+ creates: "plan",
141
+ confirm: true,
142
+ args: planArgs([]),
143
+ argsFor: (object) => planArgs(flowChoices(repositoryData(object.data))),
144
+ when: (state) => repositoryData(state).removed !== true,
145
+ async run(ctx, args) {
146
+ const input = args as {
147
+ readonly title?: string;
148
+ readonly slug?: string;
149
+ readonly request?: string;
150
+ readonly flow?: string;
151
+ };
152
+ const plan = await createPlan(ctx.store, {
153
+ repository: repositoryData(ctx.object.data),
154
+ ...(input.slug === undefined ? {} : { slug: input.slug }),
155
+ title: input.title ?? "",
156
+ ...(input.request === undefined ? {} : { request: input.request }),
157
+ ...(input.flow === undefined ? {} : { flow: input.flow }),
158
+ });
159
+ return { text: idOfKey(plan.id), opens: `plan:${plan.id}` };
160
+ },
161
+ };
162
+
163
+ const taskAction: ActionTypeDefinition = {
164
+ name: "task",
165
+ on: "plan",
166
+ creates: "task",
167
+ rank: () => PLAN_CREATE_TASK_RANK,
168
+ args: taskArgs([], []),
169
+ argsFor: (object, env) => {
170
+ const plan = planData(object.data);
171
+ const id = idOfKey(object.id);
172
+ const repository = repositoryNow(env.store, plan.repository);
173
+ return taskArgs(
174
+ flowChoices(repository),
175
+ tasksOfPlanNow(env.store, plan.repository, id)
176
+ .filter(
177
+ (task) => !TASK_FINAL_STATES.includes(taskData(task.data).phase),
178
+ )
179
+ .map((task) => idOfKey(task.id)),
180
+ );
181
+ },
182
+ when: () => true,
183
+ async run(ctx, args) {
184
+ const input = args as {
185
+ readonly title?: string;
186
+ readonly slug?: string;
187
+ readonly brief?: string;
188
+ readonly flow?: string;
189
+ readonly after?: readonly string[];
190
+ };
191
+ const plan = planData(ctx.object.data);
192
+ const repository = await ctx.store.get("repo", plan.repository);
193
+ if (repository === undefined) {
194
+ throw new DevError("repo", `no repository "${plan.repository}"`);
195
+ }
196
+ const task = await createTask(ctx.store, {
197
+ repository: repositoryData(repository.data),
198
+ plan: idOfKey(ctx.object.id),
199
+ ...(input.slug === undefined ? {} : { slug: input.slug }),
200
+ title: input.title ?? "",
201
+ ...(input.brief === undefined ? {} : { brief: input.brief }),
202
+ ...(input.flow === undefined ? {} : { flow: input.flow }),
203
+ ...(input.after === undefined ? {} : { after: input.after }),
204
+ });
205
+ return { text: idOfKey(task.id), opens: `task:${task.id}` };
206
+ },
207
+ };
208
+
209
+ /** The actions that create a plan and a task. */
210
+ export const creationActions: readonly ActionTypeDefinition[] = [planAction, taskAction];
package/src/flaky.ts CHANGED
@@ -15,8 +15,8 @@ import { isAbsolute, join, relative } from "node:path";
15
15
  import type { ObjectStore, StoredObject } from "@operad-io/engine";
16
16
  import { isRecord, messageOf, type SecretStore } from "@operad-io/engine";
17
17
  import type { MachineLoad } from "@operad-io/engine/platform";
18
- import type { CheckLoad } from "./notcode.ts";
19
- import { bareId, changeClock, isOpenTask, keyRepository, listAll, parseId, planData, planState, splitBrief, taskData, type PlanData, type RepositoryData } from "./model.ts";
18
+ import { underLoad, type CheckLoad, type CheckLoadReading } from "./check-load.ts";
19
+ import { idOfKey, changeClock, isOpenTask, keyRepository, listAll, parseId, planData, planState, splitBrief, taskData, type PlanData, type RepositoryData } from "./model.ts";
20
20
  import { anchoredPattern, shellQuote } from "./rerun.ts";
21
21
  import type { FailedRerun } from "./settings.ts";
22
22
  import { addConfirmedPlanLocked, addTaskLocked, withRepoLock } from "./service.ts";
@@ -70,7 +70,7 @@ export interface FlakyOccurrence {
70
70
  * recorded and never counts toward a task: a rerun on a busy machine says
71
71
  * little about the test.
72
72
  */
73
- readonly load?: MachineLoad | undefined;
73
+ readonly load?: CheckLoadReading | undefined;
74
74
  }
75
75
 
76
76
  /** The passes that count toward a task: the ones seen on an idle machine. */
@@ -83,23 +83,23 @@ export function flakyLoadLimitOf(configured: number | undefined, load: MachineLo
83
83
  return configured ?? load.cores * 2;
84
84
  }
85
85
 
86
- /** True when a reading is above the limit. */
87
- function overLimit(load: MachineLoad, configured: number | undefined): boolean {
88
- return load.load1 > flakyLoadLimitOf(configured, load);
86
+ /** True when a reading is above the limit. An unknown reading is not busy. */
87
+ function overLimit(load: CheckLoadReading, configured: number | undefined): boolean {
88
+ return load.unknown !== true && load.load1 > flakyLoadLimitOf(configured, load);
89
89
  }
90
90
 
91
91
  /** The load readings a check handed over: the start and the end of each run. */
92
92
  interface LoadInput {
93
- readonly load?: MachineLoad | undefined;
94
- readonly startLoad?: MachineLoad | undefined;
95
- readonly endLoad?: MachineLoad | undefined;
93
+ readonly load?: CheckLoadReading | undefined;
94
+ readonly startLoad?: CheckLoadReading | undefined;
95
+ readonly endLoad?: CheckLoadReading | undefined;
96
96
  readonly loads?: readonly CheckLoad[] | undefined;
97
97
  readonly loadLimit?: number | undefined;
98
98
  }
99
99
 
100
100
  /** The first reading above the limit, or undefined when the check ran idle. */
101
- function busyLoad(input: LoadInput): MachineLoad | undefined {
102
- const readings: MachineLoad[] = [];
101
+ function busyLoad(input: LoadInput): CheckLoadReading | undefined {
102
+ const readings: CheckLoadReading[] = [];
103
103
  for (const run of input.loads ?? []) readings.push(run.start, run.end);
104
104
  if (input.startLoad !== undefined) readings.push(input.startLoad);
105
105
  if (input.endLoad !== undefined) readings.push(input.endLoad);
@@ -108,8 +108,8 @@ function busyLoad(input: LoadInput): MachineLoad | undefined {
108
108
  }
109
109
 
110
110
  /** The history and check-log line for a failure skipped as seen under load. */
111
- function skippedNotice(name: string, load: MachineLoad): string {
112
- return `flaky test "${name}" skipped: seen under load ${load.load1} on ${load.cores} cores`;
111
+ function skippedNotice(name: string, load: CheckLoadReading): string {
112
+ return `flaky test "${name}" skipped: seen ${underLoad(load)}`;
113
113
  }
114
114
 
115
115
  /** Adds the skip line to the check's own log; a log that cannot be written stays as it is. */
@@ -143,7 +143,14 @@ function occurrenceOf(value: unknown): FlakyOccurrence | undefined {
143
143
  if (typeof task !== "string" || typeof at !== "number") return undefined;
144
144
  return {
145
145
  ...(isRecord(load) && typeof load.load1 === "number" && typeof load.cores === "number"
146
- ? { load: { load1: load.load1, cores: load.cores } }
146
+ ? {
147
+ load: {
148
+ load1: load.load1,
149
+ cores: load.cores,
150
+ ...(typeof load.host === "string" ? { host: load.host } : {}),
151
+ ...(load.unknown === true ? { unknown: true } : {}),
152
+ },
153
+ }
147
154
  : {}),
148
155
  task,
149
156
  at,
@@ -178,7 +185,16 @@ function writableOf(record: FlakyRecord): Record<string, unknown> {
178
185
  task: entry.task,
179
186
  at: entry.at,
180
187
  excerpt: entry.excerpt,
181
- ...(entry.load === undefined ? {} : { load: { load1: entry.load.load1, cores: entry.load.cores } }),
188
+ ...(entry.load === undefined
189
+ ? {}
190
+ : {
191
+ load: {
192
+ load1: entry.load.load1,
193
+ cores: entry.load.cores,
194
+ ...(entry.load.host === undefined ? {} : { host: entry.load.host }),
195
+ ...(entry.load.unknown === true ? { unknown: true } : {}),
196
+ },
197
+ }),
182
198
  ...(entry.file === undefined ? {} : { file: entry.file }),
183
199
  ...(entry.stress === undefined ? {} : { stress: entry.stress }),
184
200
  ...(entry.rule === undefined ? {} : { rule: entry.rule }),
@@ -353,7 +369,7 @@ async function newestConfirmedPlan(
353
369
  for (const object of await listAll(store, "plan")) {
354
370
  const plan = planData(object.data);
355
371
  if (plan.repository !== repository || plan.status !== "confirmed") continue;
356
- const number = parseId(bareId(object.id), "plan")?.number ?? -1;
372
+ const number = parseId(idOfKey(object.id), "plan")?.number ?? -1;
357
373
  if (best === undefined || number > best.number) best = { object, number };
358
374
  }
359
375
  return best?.object;
@@ -380,7 +396,7 @@ async function flakyPlanFor(
380
396
  ): Promise<{ readonly plan: StoredObject; readonly missing: string | undefined }> {
381
397
  let missing: string | undefined;
382
398
  if (configured !== undefined) {
383
- const named = await store.get("plan", `${repository.name}/${bareId(configured)}`);
399
+ const named = await store.get("plan", `${repository.name}/${idOfKey(configured)}`);
384
400
  if (named !== undefined) {
385
401
  const data = planData(named.data);
386
402
  if (data.repository === repository.name && !isEnded(data)) {
@@ -394,13 +410,13 @@ async function flakyPlanFor(
394
410
  const data = planData(object.data);
395
411
  return (
396
412
  data.repository === repository.name &&
397
- parseId(bareId(object.id), "plan")?.slug === FLAKY_PLAN_SLUG &&
413
+ parseId(idOfKey(object.id), "plan")?.slug === FLAKY_PLAN_SLUG &&
398
414
  !isEnded(data)
399
415
  );
400
416
  })
401
417
  .sort(
402
418
  (x, y) =>
403
- (parseId(bareId(y.id), "plan")?.number ?? -1) - (parseId(bareId(x.id), "plan")?.number ?? -1),
419
+ (parseId(idOfKey(y.id), "plan")?.number ?? -1) - (parseId(idOfKey(x.id), "plan")?.number ?? -1),
404
420
  )[0];
405
421
  if (own !== undefined) return { plan: own, missing };
406
422
  const model = await newestConfirmedPlan(store, repository.name);
@@ -469,10 +485,10 @@ export interface FlakyInput {
469
485
  /** The check log, which still holds the first run's output. */
470
486
  readonly log: string | undefined;
471
487
  /** One load reading for the check, when the caller has only that. */
472
- readonly load?: MachineLoad | undefined;
488
+ readonly load?: CheckLoadReading | undefined;
473
489
  /** The load at the start and the end of the check, when it is one run. */
474
- readonly startLoad?: MachineLoad | undefined;
475
- readonly endLoad?: MachineLoad | undefined;
490
+ readonly startLoad?: CheckLoadReading | undefined;
491
+ readonly endLoad?: CheckLoadReading | undefined;
476
492
  /** The load at the start and the end of each run of the check. */
477
493
  readonly loads?: readonly CheckLoad[] | undefined;
478
494
  /** `check.flakyLoadLimit`: the load above which a failure is not a flaky test. */
@@ -528,7 +544,7 @@ export async function trackFlakyTests(input: FlakyInput): Promise<string | undef
528
544
  // the count restarts when that task ends, however few passes came before.
529
545
  const existing = await namingTask(store, fresh.name, name);
530
546
  if (existing !== undefined) {
531
- record = { ...record, task: bareId(existing.id) };
547
+ record = { ...record, task: idOfKey(existing.id) };
532
548
  await store.put(FLAKY_TYPE, key, writableOf(record), "dev:flaky-task");
533
549
  }
534
550
  }
@@ -579,7 +595,7 @@ async function propose(
579
595
  await store.put(
580
596
  FLAKY_TYPE,
581
597
  key,
582
- writableOf({ ...record, task: bareId(existing.id) }),
598
+ writableOf({ ...record, task: idOfKey(existing.id) }),
583
599
  "dev:flaky-task",
584
600
  );
585
601
  return undefined;
@@ -589,7 +605,7 @@ async function propose(
589
605
  const fallback =
590
606
  missing === undefined
591
607
  ? undefined
592
- : `check.flakyPlan "${missing}" does not name an open plan of this repository; the task went into "${bareId(plan.id)}"`;
608
+ : `check.flakyPlan "${missing}" does not name an open plan of this repository; the task went into "${idOfKey(plan.id)}"`;
593
609
  try {
594
610
  const task = await addTaskLocked(
595
611
  store,
@@ -605,7 +621,7 @@ async function propose(
605
621
  await store.put(
606
622
  FLAKY_TYPE,
607
623
  key,
608
- writableOf({ ...record, task: bareId(task.id) }),
624
+ writableOf({ ...record, task: idOfKey(task.id) }),
609
625
  "dev:flaky-task",
610
626
  );
611
627
  return fallback;
@@ -652,9 +668,9 @@ export interface FlakyReport {
652
668
  readonly taskId: string;
653
669
  readonly threshold: number;
654
670
  readonly flakyPlan?: string | undefined;
655
- readonly load?: MachineLoad | undefined;
656
- readonly startLoad?: MachineLoad | undefined;
657
- readonly endLoad?: MachineLoad | undefined;
671
+ readonly load?: CheckLoadReading | undefined;
672
+ readonly startLoad?: CheckLoadReading | undefined;
673
+ readonly endLoad?: CheckLoadReading | undefined;
658
674
  readonly loads?: readonly CheckLoad[] | undefined;
659
675
  readonly loadLimit?: number | undefined;
660
676
  readonly check: {