@operad-io/dev 0.0.0-stage → 0.0.1
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/LICENSE +21 -0
- package/README.md +795 -2
- package/dev.schema.json +602 -0
- package/flows/chat-worktree.flow.ts +18 -0
- package/flows/dev.flow.ts +7 -0
- package/package.json +29 -4
- package/src/actions.ts +591 -0
- package/src/announce.ts +225 -0
- package/src/chat.ts +234 -0
- package/src/check.ts +80 -0
- package/src/commands.ts +417 -0
- package/src/editor.ts +55 -0
- package/src/flaky.ts +716 -0
- package/src/flow-compiler.ts +858 -0
- package/src/followups.ts +223 -0
- package/src/gate.ts +2897 -0
- package/src/git.ts +138 -0
- package/src/index.ts +226 -0
- package/src/integrate.ts +1201 -0
- package/src/integration-queue.ts +393 -0
- package/src/lock.ts +36 -0
- package/src/mainclone.ts +102 -0
- package/src/marks.ts +126 -0
- package/src/model.ts +1165 -0
- package/src/notcode.ts +266 -0
- package/src/place-order.ts +161 -0
- package/src/place-wait.ts +64 -0
- package/src/places.ts +368 -0
- package/src/prepare.ts +106 -0
- package/src/progress.ts +115 -0
- package/src/project-flows.ts +160 -0
- package/src/project-settings.ts +185 -0
- package/src/refusals.ts +336 -0
- package/src/rerun.ts +378 -0
- package/src/reruns.ts +62 -0
- package/src/retry.ts +212 -0
- package/src/rework.ts +366 -0
- package/src/schedule.ts +1052 -0
- package/src/service.ts +2160 -0
- package/src/settings.ts +1463 -0
- package/src/standing.ts +87 -0
- package/src/stdin.ts +105 -0
- package/src/steps.ts +1775 -0
- package/src/stops.ts +103 -0
- package/src/throughput.ts +347 -0
- package/src/timeouts.ts +60 -0
- package/src/views.ts +1167 -0
- package/src/waits.ts +105 -0
package/src/actions.ts
ADDED
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
/** The actions the owner runs on a plan or a task. */
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
ActionEnv,
|
|
5
|
+
ActionTypeDefinition,
|
|
6
|
+
ObjectStore,
|
|
7
|
+
StoredObject,
|
|
8
|
+
} from "@operad-io/engine";
|
|
9
|
+
import {
|
|
10
|
+
appendChange,
|
|
11
|
+
appendRework,
|
|
12
|
+
bareId,
|
|
13
|
+
DevError,
|
|
14
|
+
DevRefusal,
|
|
15
|
+
isIntegrating,
|
|
16
|
+
planData,
|
|
17
|
+
planState,
|
|
18
|
+
PRIORITIES,
|
|
19
|
+
storeKey,
|
|
20
|
+
taskData,
|
|
21
|
+
type PlanData,
|
|
22
|
+
type TaskData,
|
|
23
|
+
} from "./model.ts";
|
|
24
|
+
import {
|
|
25
|
+
planLine,
|
|
26
|
+
taskLine,
|
|
27
|
+
type Facts,
|
|
28
|
+
type PlanActionName,
|
|
29
|
+
type TaskActionName,
|
|
30
|
+
} from "./refusals.ts";
|
|
31
|
+
import { waitAccepts, type WaitAction } from "./waits.ts";
|
|
32
|
+
import {
|
|
33
|
+
cancelPlan,
|
|
34
|
+
cancelTask,
|
|
35
|
+
pauseTask,
|
|
36
|
+
resumeTask,
|
|
37
|
+
claimWaitingTask,
|
|
38
|
+
confirmPlan,
|
|
39
|
+
confirmTask,
|
|
40
|
+
getPlan,
|
|
41
|
+
getTask,
|
|
42
|
+
releaseWaitingClaim,
|
|
43
|
+
setAuto,
|
|
44
|
+
setConcurrency,
|
|
45
|
+
validatePlanConcurrency,
|
|
46
|
+
setPriority,
|
|
47
|
+
MAX_PLAN_CONCURRENCY,
|
|
48
|
+
MIN_PLAN_CONCURRENCY,
|
|
49
|
+
} from "./service.ts";
|
|
50
|
+
|
|
51
|
+
const AUTO_LEVELS = ["off", "run", "merge"] as const;
|
|
52
|
+
|
|
53
|
+
/** The plan of a task, as the lines name it; undefined when it is gone. */
|
|
54
|
+
async function planOfTask(
|
|
55
|
+
store: ObjectStore,
|
|
56
|
+
task: TaskData,
|
|
57
|
+
): Promise<Facts["plan"]> {
|
|
58
|
+
const object = await store.get("plan", storeKey(task.repository, task.plan));
|
|
59
|
+
if (object === undefined) return undefined;
|
|
60
|
+
return { id: task.plan, state: planState(planData(object.data)) };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** What a task action's line needs to know about the task. */
|
|
64
|
+
async function taskFacts(store: ObjectStore, object: StoredObject): Promise<Facts> {
|
|
65
|
+
const task = taskData(object.data);
|
|
66
|
+
const id = bareId(object.id);
|
|
67
|
+
return task.phase === "proposed"
|
|
68
|
+
? { id, plan: await planOfTask(store, task) }
|
|
69
|
+
: { id };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The line a task action refuses with now, or undefined when it can run. A
|
|
74
|
+
* proposed task is confirmed only inside a confirmed plan.
|
|
75
|
+
*/
|
|
76
|
+
export async function taskRefusal(
|
|
77
|
+
action: TaskActionName,
|
|
78
|
+
store: ObjectStore,
|
|
79
|
+
object: StoredObject,
|
|
80
|
+
): Promise<string | undefined> {
|
|
81
|
+
const task = taskData(object.data);
|
|
82
|
+
const facts = await taskFacts(store, object);
|
|
83
|
+
if (action === "confirm" && task.phase === "proposed" && facts.plan?.state === "confirmed") {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
const said = taskLine(action, task, facts);
|
|
87
|
+
return said?.kind === "refuse" ? said.text : undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The line a plan action refuses with now, or undefined when it can run. */
|
|
91
|
+
export function planRefusal(
|
|
92
|
+
action: PlanActionName,
|
|
93
|
+
object: StoredObject,
|
|
94
|
+
): string | undefined {
|
|
95
|
+
const said = planLine(action, planData(object.data), { id: bareId(object.id) });
|
|
96
|
+
return said?.kind === "refuse" ? said.text : undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Whether a set-a-value action gets the value the plan already has. */
|
|
100
|
+
function sameValue(action: PlanActionName, plan: PlanData, args: unknown): string | number | undefined {
|
|
101
|
+
const given =
|
|
102
|
+
typeof args === "object" && args !== null ? (args as Record<string, unknown>) : {};
|
|
103
|
+
if (action === "auto" && given.level === plan.auto) return plan.auto;
|
|
104
|
+
if (action === "priority" && given.level === plan.priority) return plan.priority;
|
|
105
|
+
if (action === "concurrency" && given.count === plan.concurrency) return plan.concurrency;
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const taskWhy = (action: TaskActionName) =>
|
|
110
|
+
(object: StoredObject, env: ActionEnv) => taskRefusal(action, env.store, object);
|
|
111
|
+
|
|
112
|
+
const planWhy = (action: PlanActionName) =>
|
|
113
|
+
(object: StoredObject): string | undefined => planRefusal(action, object);
|
|
114
|
+
|
|
115
|
+
/** The line for a task action whose result is already true. */
|
|
116
|
+
const taskSettled = (action: TaskActionName) =>
|
|
117
|
+
(object: StoredObject): string | undefined => {
|
|
118
|
+
const said = taskLine(action, taskData(object.data), { id: bareId(object.id) });
|
|
119
|
+
return said?.kind === "done" ? said.text : undefined;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/** The line for a plan action whose result is already true or already set. */
|
|
123
|
+
const planSettled = (action: PlanActionName) =>
|
|
124
|
+
(object: StoredObject, args: unknown): string | undefined => {
|
|
125
|
+
const plan = planData(object.data);
|
|
126
|
+
const value = sameValue(action, plan, args);
|
|
127
|
+
const said = planLine(action, plan, { id: bareId(object.id), value }, value !== undefined);
|
|
128
|
+
return said?.kind === "done" ? said.text : undefined;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/** A task that waits for a person, as opposed to for a review model. */
|
|
132
|
+
function offeredWhileWaiting(action: WaitAction) {
|
|
133
|
+
return (state: Parameters<typeof taskData>[0]): boolean =>
|
|
134
|
+
waitAccepts(taskData(state), action);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* True when a person can merge the task as it stands: its head is verified and
|
|
139
|
+
* the wait is not the question of a rework that the automatic limit ended in.
|
|
140
|
+
*/
|
|
141
|
+
function readyToMerge(state: Parameters<typeof taskData>[0]): boolean {
|
|
142
|
+
const task = taskData(state);
|
|
143
|
+
const verified = task.attempt?.verified;
|
|
144
|
+
return (
|
|
145
|
+
typeof verified === "string" &&
|
|
146
|
+
verified.length > 0 &&
|
|
147
|
+
task.attempt?.rework?.result !== "ask"
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* The order of a task's actions: what a person most likely wants next first,
|
|
153
|
+
* what ends the task last. Lower comes first; `merge` and `rework` swap places
|
|
154
|
+
* by what the wait asks.
|
|
155
|
+
*/
|
|
156
|
+
export const TASK_RANKS: Record<TaskActionName, (state: Parameters<typeof taskData>[0]) => number> = {
|
|
157
|
+
confirm: () => 0,
|
|
158
|
+
resume: () => 1,
|
|
159
|
+
merge: (state) => (readyToMerge(state) ? 1 : 4),
|
|
160
|
+
rework: (state) => (readyToMerge(state) ? 4 : 1),
|
|
161
|
+
reverify: () => 5,
|
|
162
|
+
reject: () => 6,
|
|
163
|
+
pause: () => 7,
|
|
164
|
+
cancel: () => 9,
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The order of a plan's actions. With auto off the next step is to turn it on;
|
|
169
|
+
* with auto on it is the priority, since the level is already chosen.
|
|
170
|
+
*/
|
|
171
|
+
export const PLAN_RANKS: Record<PlanActionName, (state: Parameters<typeof planData>[0]) => number> = {
|
|
172
|
+
confirm: () => 0,
|
|
173
|
+
auto: (state) => (planData(state).auto === "off" ? 1 : 2),
|
|
174
|
+
priority: (state) => (planData(state).auto === "off" ? 2 : 1),
|
|
175
|
+
concurrency: () => 3,
|
|
176
|
+
cancel: () => 9,
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/** Reads a required enum argument; the kernel checks it first, this is for types. */
|
|
180
|
+
function enumArgument<T extends string>(
|
|
181
|
+
args: unknown,
|
|
182
|
+
field: string,
|
|
183
|
+
allowed: readonly T[],
|
|
184
|
+
): T {
|
|
185
|
+
if (typeof args !== "object" || args === null) {
|
|
186
|
+
throw new DevError(field, `must be one of ${allowed.join(", ")}`);
|
|
187
|
+
}
|
|
188
|
+
const raw = (args as Record<string, unknown>)[field];
|
|
189
|
+
if (typeof raw !== "string" || !(allowed as readonly string[]).includes(raw)) {
|
|
190
|
+
throw new DevError(field, `must be one of ${allowed.join(", ")}`);
|
|
191
|
+
}
|
|
192
|
+
return raw as T;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The merge, reject, rework and reverify actions answer the task's wait, so they
|
|
197
|
+
* refuse unless the task waits for a person; the line is the table's.
|
|
198
|
+
*/
|
|
199
|
+
async function waitingTask(
|
|
200
|
+
store: Parameters<typeof getTask>[0],
|
|
201
|
+
id: string,
|
|
202
|
+
action: TaskActionName,
|
|
203
|
+
) {
|
|
204
|
+
const object = await getTask(store, id);
|
|
205
|
+
const line = await taskRefusal(action, store, object);
|
|
206
|
+
if (line !== undefined) throw new DevRefusal(line);
|
|
207
|
+
return object;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function noteArgument(args: unknown): string {
|
|
211
|
+
if (
|
|
212
|
+
typeof args !== "object" ||
|
|
213
|
+
args === null ||
|
|
214
|
+
typeof (args as { note?: unknown }).note !== "string"
|
|
215
|
+
) {
|
|
216
|
+
throw new DevError("note", "needs a note");
|
|
217
|
+
}
|
|
218
|
+
const note = (args as { note: string }).note.trim();
|
|
219
|
+
if (note.length === 0) {
|
|
220
|
+
throw new DevError("note", "must be a non-empty string");
|
|
221
|
+
}
|
|
222
|
+
return note;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
type Answer = NonNullable<Parameters<ActionTypeDefinition["run"]>[0]["answer"]>;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Answers the task's wait after claiming the task's next transition at the
|
|
229
|
+
* version the action saw. The claim goes first so that a concurrent action on
|
|
230
|
+
* the same version loses before it records anything; an answer that then fails
|
|
231
|
+
* gives the claim back.
|
|
232
|
+
*/
|
|
233
|
+
async function claimAndAnswer(
|
|
234
|
+
ctx: {
|
|
235
|
+
readonly store: Parameters<typeof getTask>[0];
|
|
236
|
+
readonly object: { readonly id: string; readonly version?: number | undefined };
|
|
237
|
+
readonly answer?: Answer | undefined;
|
|
238
|
+
},
|
|
239
|
+
action: TaskActionName,
|
|
240
|
+
choice: string,
|
|
241
|
+
change: (latest: TaskData) => TaskData,
|
|
242
|
+
note?: string,
|
|
243
|
+
): Promise<string | undefined> {
|
|
244
|
+
const object = await waitingTask(ctx.store, ctx.object.id, action);
|
|
245
|
+
// Claim at the version the action was offered on, not one read here: an
|
|
246
|
+
// action that starts after a competing one wrote must still lose.
|
|
247
|
+
const seen = ctx.object.version ?? object.version;
|
|
248
|
+
if (ctx.answer === undefined) {
|
|
249
|
+
throw new DevRefusal(`${bareId(ctx.object.id)} is not waiting for an answer now`);
|
|
250
|
+
}
|
|
251
|
+
const claim = await claimWaitingTask(
|
|
252
|
+
ctx.store,
|
|
253
|
+
ctx.object.id,
|
|
254
|
+
seen,
|
|
255
|
+
action,
|
|
256
|
+
change,
|
|
257
|
+
);
|
|
258
|
+
// Another action already made the result true: succeed with its line.
|
|
259
|
+
if (claim.settled !== undefined) return claim.settled;
|
|
260
|
+
const { claimed, before } = claim;
|
|
261
|
+
try {
|
|
262
|
+
await ctx.answer(choice, note);
|
|
263
|
+
} catch (error) {
|
|
264
|
+
await releaseWaitingClaim(ctx.store, ctx.object.id, claimed, before);
|
|
265
|
+
throw error;
|
|
266
|
+
}
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const mergeTask: ActionTypeDefinition = {
|
|
271
|
+
name: "merge",
|
|
272
|
+
on: "task",
|
|
273
|
+
rank: TASK_RANKS.merge,
|
|
274
|
+
confirm: true,
|
|
275
|
+
when(state) {
|
|
276
|
+
return offeredWhileWaiting("merge")(state);
|
|
277
|
+
},
|
|
278
|
+
why: taskWhy("merge"),
|
|
279
|
+
settled: taskSettled("merge"),
|
|
280
|
+
async run(ctx) {
|
|
281
|
+
return claimAndAnswer(ctx, "merge", "merge", (latest) => {
|
|
282
|
+
const verified = latest.attempt?.verified;
|
|
283
|
+
if (typeof verified !== "string" || verified.length === 0) {
|
|
284
|
+
// The merge step would refuse later, in the background; say so now.
|
|
285
|
+
throw new DevError(
|
|
286
|
+
"merge",
|
|
287
|
+
`${bareId(ctx.object.id)} has no verified commit; run operad dev:reverify ${bareId(ctx.object.id)} first`,
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
return { ...latest, brief: appendChange(latest.brief, "merge requested") };
|
|
291
|
+
});
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const NOTE_ARGS = (description: string) =>
|
|
296
|
+
({
|
|
297
|
+
type: "object",
|
|
298
|
+
properties: { note: { type: "string", role: "note", description } },
|
|
299
|
+
required: ["note"],
|
|
300
|
+
additionalProperties: false,
|
|
301
|
+
}) as const;
|
|
302
|
+
|
|
303
|
+
const rejectTaskAction: ActionTypeDefinition = {
|
|
304
|
+
name: "reject",
|
|
305
|
+
on: "task",
|
|
306
|
+
rank: TASK_RANKS.reject,
|
|
307
|
+
args: NOTE_ARGS("What the worker should change before the next review."),
|
|
308
|
+
when(state) {
|
|
309
|
+
return offeredWhileWaiting("reject")(state);
|
|
310
|
+
},
|
|
311
|
+
why: taskWhy("reject"),
|
|
312
|
+
settled: taskSettled("reject"),
|
|
313
|
+
async run(ctx, args) {
|
|
314
|
+
const note = noteArgument(args);
|
|
315
|
+
return claimAndAnswer(
|
|
316
|
+
ctx,
|
|
317
|
+
"reject",
|
|
318
|
+
"reject",
|
|
319
|
+
(latest) => ({
|
|
320
|
+
...latest,
|
|
321
|
+
brief: appendRework(latest.brief, "owner", note),
|
|
322
|
+
reviewFailed: undefined,
|
|
323
|
+
}),
|
|
324
|
+
note,
|
|
325
|
+
);
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* The lead's own rework: it goes into the brief as `## Rework <n> (lead)`, the
|
|
331
|
+
* worker runs again, and the count of automatic reworks in a row starts over.
|
|
332
|
+
*/
|
|
333
|
+
const reworkTaskAction: ActionTypeDefinition = {
|
|
334
|
+
name: "rework",
|
|
335
|
+
on: "task",
|
|
336
|
+
rank: TASK_RANKS.rework,
|
|
337
|
+
args: NOTE_ARGS("What the worker should do in this rework."),
|
|
338
|
+
when(state) {
|
|
339
|
+
return offeredWhileWaiting("rework")(state);
|
|
340
|
+
},
|
|
341
|
+
why: taskWhy("rework"),
|
|
342
|
+
settled: taskSettled("rework"),
|
|
343
|
+
async run(ctx, args) {
|
|
344
|
+
const note = noteArgument(args);
|
|
345
|
+
return claimAndAnswer(
|
|
346
|
+
ctx,
|
|
347
|
+
"rework",
|
|
348
|
+
"rework",
|
|
349
|
+
(latest) => ({
|
|
350
|
+
...appendRework(latest, "lead", note),
|
|
351
|
+
phase: "running",
|
|
352
|
+
reworkStreak: 0,
|
|
353
|
+
reviewFailed: undefined,
|
|
354
|
+
}),
|
|
355
|
+
note,
|
|
356
|
+
);
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
/** Runs verify and review again on the task's current head, with no worker. */
|
|
361
|
+
const reverifyTaskAction: ActionTypeDefinition = {
|
|
362
|
+
name: "reverify",
|
|
363
|
+
on: "task",
|
|
364
|
+
rank: TASK_RANKS.reverify,
|
|
365
|
+
when(state) {
|
|
366
|
+
return offeredWhileWaiting("reverify")(state);
|
|
367
|
+
},
|
|
368
|
+
why: taskWhy("reverify"),
|
|
369
|
+
settled: taskSettled("reverify"),
|
|
370
|
+
async run(ctx) {
|
|
371
|
+
return claimAndAnswer(ctx, "reverify", "reverify", (latest) => {
|
|
372
|
+
if (latest.attempt === undefined) {
|
|
373
|
+
throw new DevError(
|
|
374
|
+
"reverify",
|
|
375
|
+
"the task has no work to verify yet; rework it instead",
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
return {
|
|
379
|
+
...latest,
|
|
380
|
+
phase: "running",
|
|
381
|
+
brief: appendChange(latest.brief, "reverify"),
|
|
382
|
+
// A fresh gate result: the verify step replays a result its own run
|
|
383
|
+
// recorded, so the old ones must go before the step enters again.
|
|
384
|
+
attempt: {
|
|
385
|
+
...latest.attempt,
|
|
386
|
+
verified: null,
|
|
387
|
+
verify: null,
|
|
388
|
+
review: null,
|
|
389
|
+
reviews: 0,
|
|
390
|
+
// Round 1 starts again: the old round's runs and pending run must
|
|
391
|
+
// not be read back as this round's.
|
|
392
|
+
reviewRuns: [],
|
|
393
|
+
reviewPending: null,
|
|
394
|
+
rework: null,
|
|
395
|
+
integration: null,
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
});
|
|
399
|
+
},
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
export const actions: readonly ActionTypeDefinition[] = [
|
|
403
|
+
{
|
|
404
|
+
name: "confirm",
|
|
405
|
+
on: "plan",
|
|
406
|
+
rank: PLAN_RANKS.confirm,
|
|
407
|
+
when(state) {
|
|
408
|
+
const plan = planData(state);
|
|
409
|
+
return plan.status === "draft" && plan.taskCount > 0;
|
|
410
|
+
},
|
|
411
|
+
why: planWhy("confirm"),
|
|
412
|
+
settled: planSettled("confirm"),
|
|
413
|
+
async run(ctx) {
|
|
414
|
+
await confirmPlan(ctx.store, ctx.object.id);
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
name: "confirm",
|
|
419
|
+
on: "task",
|
|
420
|
+
rank: TASK_RANKS.confirm,
|
|
421
|
+
async when(state, env) {
|
|
422
|
+
const task = taskData(state);
|
|
423
|
+
if (task.phase !== "proposed") return false;
|
|
424
|
+
// Only a confirmed plan takes a proposed task into work; a draft plan is
|
|
425
|
+
// confirmed as a whole.
|
|
426
|
+
return (await planOfTask(env.store, task))?.state === "confirmed";
|
|
427
|
+
},
|
|
428
|
+
why: taskWhy("confirm"),
|
|
429
|
+
settled: taskSettled("confirm"),
|
|
430
|
+
async run(ctx) {
|
|
431
|
+
await confirmTask(ctx.store, ctx.object.id);
|
|
432
|
+
},
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
name: "cancel",
|
|
436
|
+
on: "plan",
|
|
437
|
+
ends: true,
|
|
438
|
+
rank: PLAN_RANKS.cancel,
|
|
439
|
+
confirm: true,
|
|
440
|
+
when(state) {
|
|
441
|
+
return planData(state).status !== "cancelled";
|
|
442
|
+
},
|
|
443
|
+
why: planWhy("cancel"),
|
|
444
|
+
settled: planSettled("cancel"),
|
|
445
|
+
async run(ctx) {
|
|
446
|
+
await cancelPlan(ctx.store, ctx.object.id, { runs: ctx.runs });
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
name: "cancel",
|
|
451
|
+
on: "task",
|
|
452
|
+
ends: true,
|
|
453
|
+
rank: TASK_RANKS.cancel,
|
|
454
|
+
confirm: true,
|
|
455
|
+
when(state) {
|
|
456
|
+
const phase = taskData(state).phase;
|
|
457
|
+
return phase !== "merged" && phase !== "cancelled";
|
|
458
|
+
},
|
|
459
|
+
why: taskWhy("cancel"),
|
|
460
|
+
settled: taskSettled("cancel"),
|
|
461
|
+
async run(ctx) {
|
|
462
|
+
await cancelTask(ctx.store, ctx.object.id, { runs: ctx.runs });
|
|
463
|
+
},
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
name: "pause",
|
|
467
|
+
on: "task",
|
|
468
|
+
rank: TASK_RANKS.pause,
|
|
469
|
+
confirm: true,
|
|
470
|
+
when(state) {
|
|
471
|
+
const task = taskData(state);
|
|
472
|
+
const phase = task.phase;
|
|
473
|
+
return (
|
|
474
|
+
!isIntegrating(task) &&
|
|
475
|
+
(phase === "ready" || phase === "running" || phase === "review")
|
|
476
|
+
);
|
|
477
|
+
},
|
|
478
|
+
why: taskWhy("pause"),
|
|
479
|
+
settled: taskSettled("pause"),
|
|
480
|
+
async run(ctx) {
|
|
481
|
+
await pauseTask(ctx.store, ctx.object.id, { runs: ctx.runs });
|
|
482
|
+
},
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
name: "resume",
|
|
486
|
+
on: "task",
|
|
487
|
+
rank: TASK_RANKS.resume,
|
|
488
|
+
confirm: true,
|
|
489
|
+
when(state) {
|
|
490
|
+
return taskData(state).phase === "paused";
|
|
491
|
+
},
|
|
492
|
+
why: taskWhy("resume"),
|
|
493
|
+
settled: taskSettled("resume"),
|
|
494
|
+
async run(ctx) {
|
|
495
|
+
await resumeTask(ctx.store, ctx.object.id);
|
|
496
|
+
},
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
name: "auto",
|
|
500
|
+
on: "plan",
|
|
501
|
+
rank: PLAN_RANKS.auto,
|
|
502
|
+
args: {
|
|
503
|
+
type: "object",
|
|
504
|
+
properties: {
|
|
505
|
+
level: {
|
|
506
|
+
type: "string",
|
|
507
|
+
enum: [...AUTO_LEVELS],
|
|
508
|
+
description: "How far the plan may run without a person.",
|
|
509
|
+
},
|
|
510
|
+
},
|
|
511
|
+
required: ["level"],
|
|
512
|
+
additionalProperties: false,
|
|
513
|
+
},
|
|
514
|
+
when(state) {
|
|
515
|
+
return planData(state).status !== "cancelled";
|
|
516
|
+
},
|
|
517
|
+
why: planWhy("auto"),
|
|
518
|
+
settled: planSettled("auto"),
|
|
519
|
+
async run(ctx, args) {
|
|
520
|
+
const level = enumArgument(args, "level", AUTO_LEVELS);
|
|
521
|
+
await setAuto(ctx.store, ctx.object.id, level);
|
|
522
|
+
},
|
|
523
|
+
},
|
|
524
|
+
mergeTask,
|
|
525
|
+
rejectTaskAction,
|
|
526
|
+
reworkTaskAction,
|
|
527
|
+
reverifyTaskAction,
|
|
528
|
+
{
|
|
529
|
+
name: "priority",
|
|
530
|
+
on: "plan",
|
|
531
|
+
rank: PLAN_RANKS.priority,
|
|
532
|
+
args: {
|
|
533
|
+
type: "object",
|
|
534
|
+
properties: {
|
|
535
|
+
level: {
|
|
536
|
+
type: "string",
|
|
537
|
+
enum: [...PRIORITIES],
|
|
538
|
+
description: "The plan's priority, P0 (most urgent) to P5.",
|
|
539
|
+
},
|
|
540
|
+
},
|
|
541
|
+
required: ["level"],
|
|
542
|
+
additionalProperties: false,
|
|
543
|
+
},
|
|
544
|
+
when(state) {
|
|
545
|
+
return planData(state).status !== "cancelled";
|
|
546
|
+
},
|
|
547
|
+
why: planWhy("priority"),
|
|
548
|
+
settled: planSettled("priority"),
|
|
549
|
+
async run(ctx, args) {
|
|
550
|
+
const level = enumArgument(args, "level", PRIORITIES);
|
|
551
|
+
await setPriority(ctx.store, ctx.object.id, level);
|
|
552
|
+
const id = bareId(ctx.object.id);
|
|
553
|
+
if (planData((await getPlan(ctx.store, ctx.object.id)).data).auto === "off") {
|
|
554
|
+
return `${id} has auto off: the scheduler does not start its tasks; run operad dev:auto ${id} --level merge`;
|
|
555
|
+
}
|
|
556
|
+
return undefined;
|
|
557
|
+
},
|
|
558
|
+
},
|
|
559
|
+
{
|
|
560
|
+
name: "concurrency",
|
|
561
|
+
on: "plan",
|
|
562
|
+
rank: PLAN_RANKS.concurrency,
|
|
563
|
+
args: {
|
|
564
|
+
type: "object",
|
|
565
|
+
properties: {
|
|
566
|
+
count: {
|
|
567
|
+
type: "integer",
|
|
568
|
+
minimum: MIN_PLAN_CONCURRENCY,
|
|
569
|
+
maximum: MAX_PLAN_CONCURRENCY,
|
|
570
|
+
description: `How many of the plan's tasks may run at once, from ${MIN_PLAN_CONCURRENCY} to ${MAX_PLAN_CONCURRENCY} (a fixed upper bound). Takes effect at the next scheduler tick; running tasks are not stopped.`,
|
|
571
|
+
},
|
|
572
|
+
},
|
|
573
|
+
required: ["count"],
|
|
574
|
+
additionalProperties: false,
|
|
575
|
+
},
|
|
576
|
+
when(state) {
|
|
577
|
+
const plan = planData(state);
|
|
578
|
+
return plan.status !== "cancelled" && planState(plan) !== "finished";
|
|
579
|
+
},
|
|
580
|
+
why: planWhy("concurrency"),
|
|
581
|
+
settled: planSettled("concurrency"),
|
|
582
|
+
async run(ctx, args) {
|
|
583
|
+
const count =
|
|
584
|
+
typeof args === "object" && args !== null
|
|
585
|
+
? (args as Record<string, unknown>).count
|
|
586
|
+
: undefined;
|
|
587
|
+
await setConcurrency(ctx.store, ctx.object.id, validatePlanConcurrency(count));
|
|
588
|
+
},
|
|
589
|
+
},
|
|
590
|
+
];
|
|
591
|
+
|