@operad-io/dev 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +12 -2
- package/dev.schema.json +631 -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 +2950 -0
- package/src/git.ts +138 -0
- package/src/index.ts +227 -0
- package/src/integrate.ts +1213 -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 +1171 -0
- package/src/notcode.ts +305 -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 +192 -0
- package/src/refusals.ts +336 -0
- package/src/rerun.ts +390 -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 +1495 -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/standing.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `dev` asks a person to know about without a run waiting: a repository
|
|
3
|
+
* whose settings are not valid, a plugin dev needs that the home does not
|
|
4
|
+
* load, and proposed tasks.
|
|
5
|
+
* The pending view builds these each time, so each disappears when it is fixed.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { StandingContext, StandingItem } from "@operad-io/engine";
|
|
9
|
+
import { bareId, listAll, planData, storeKey, taskData } from "./model.ts";
|
|
10
|
+
import { listRepositories } from "./service.ts";
|
|
11
|
+
import { hasValidSettings, settingsProblem } from "./settings.ts";
|
|
12
|
+
|
|
13
|
+
/** A plugin dev starts steps of, so it cannot start work without it. */
|
|
14
|
+
export interface RequiredPlugin {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly why: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The plugins dev's steps run through. */
|
|
20
|
+
export const REQUIRED_PLUGINS: readonly RequiredPlugin[] = [
|
|
21
|
+
{ name: "pool", why: "runs its workers" },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
/** The required plugins that `loaded` does not contain. */
|
|
25
|
+
export function missingPlugins(loaded: readonly string[]): readonly RequiredPlugin[] {
|
|
26
|
+
return REQUIRED_PLUGINS.filter((plugin) => !loaded.includes(plugin.name));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function pluginItem(plugin: RequiredPlugin): StandingItem {
|
|
30
|
+
return {
|
|
31
|
+
id: `plugin:${plugin.name}`,
|
|
32
|
+
prompt: `plugin ${plugin.name} is not loaded and dev ${plugin.why} through it: run \`operad plugin enable ${plugin.name}\` and restart serve; until then no new work starts`,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The `standing` hook of the dev plugin. */
|
|
37
|
+
export async function devStanding(ctx: StandingContext): Promise<readonly StandingItem[]> {
|
|
38
|
+
const items: StandingItem[] = [];
|
|
39
|
+
for (const repository of await listRepositories(ctx.store)) {
|
|
40
|
+
const problem = settingsProblem(repository.path);
|
|
41
|
+
if (problem === undefined) continue;
|
|
42
|
+
items.push({
|
|
43
|
+
id: `settings:${repository.name}`,
|
|
44
|
+
prompt: hasValidSettings(repository.path)
|
|
45
|
+
? `the repository settings are not valid: ${problem}; the last valid settings are in use (repository ${repository.name})`
|
|
46
|
+
: `the repository settings are not valid: ${problem}; no valid settings were read before, so nothing starts in it until the file is fixed (repository ${repository.name})`,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
// A proposed task has no run, so it is pending here: whoever opened it, the
|
|
50
|
+
// owner confirms or cancels it. It leaves when it is confirmed or cancelled.
|
|
51
|
+
// A task of a draft plan is confirmed with its plan, so the plan carries one
|
|
52
|
+
// item for all of its proposed tasks.
|
|
53
|
+
const drafts = new Map<string, { titles: string[]; tasks: { type: string; id: string }[]; byDev: boolean }>();
|
|
54
|
+
for (const object of await listAll(ctx.store, "task")) {
|
|
55
|
+
const task = taskData(object.data);
|
|
56
|
+
if (task.phase !== "proposed") continue;
|
|
57
|
+
const planKey = storeKey(task.repository, task.plan);
|
|
58
|
+
const plan = await ctx.store.get("plan", planKey);
|
|
59
|
+
if (plan !== undefined && planData(plan.data).status === "draft") {
|
|
60
|
+
const draft = drafts.get(planKey) ?? { titles: [], tasks: [], byDev: false };
|
|
61
|
+
draft.titles.push(`${bareId(object.id)}`);
|
|
62
|
+
draft.tasks.push({ type: "task", id: object.id });
|
|
63
|
+
draft.byDev = draft.byDev || task.openedBy === "dev";
|
|
64
|
+
drafts.set(planKey, draft);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const by = task.openedBy === "dev" ? "dev" : "a person";
|
|
68
|
+
items.push({
|
|
69
|
+
id: `task:${object.id}`,
|
|
70
|
+
prompt: `task ${bareId(object.id)} is proposed by ${by} and waits for you: ${task.title}`,
|
|
71
|
+
object: { type: "task", id: object.id },
|
|
72
|
+
// A person who added the task knows of it; the lead is told of dev's own.
|
|
73
|
+
announce: task.openedBy === "dev",
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
for (const [planKey, draft] of drafts) {
|
|
77
|
+
items.push({
|
|
78
|
+
id: `plan:${planKey}`,
|
|
79
|
+
prompt: `plan ${bareId(planKey)} is a draft whose tasks wait for you: ${draft.titles.join(", ")}; confirm the plan to start them`,
|
|
80
|
+
object: { type: "plan", id: planKey },
|
|
81
|
+
covers: draft.tasks,
|
|
82
|
+
announce: draft.byDev,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
for (const plugin of missingPlugins(ctx.loaded)) items.push(pluginItem(plugin));
|
|
86
|
+
return items;
|
|
87
|
+
}
|
package/src/stdin.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/** Reads the text a command takes on standard input. */
|
|
2
|
+
|
|
3
|
+
/** The stream a command reads: stdin, or a test's stand-in. */
|
|
4
|
+
export type StdinStream = AsyncIterable<Uint8Array | string> & {
|
|
5
|
+
readonly destroy?: (() => void) | undefined;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/** What a bounded read may inject: its deadline, clock, wait and stream. */
|
|
9
|
+
export interface StdinReadOptions {
|
|
10
|
+
/** How long to wait before giving up; unset waits for the end of input. */
|
|
11
|
+
readonly timeoutMs?: number | undefined;
|
|
12
|
+
readonly clock?: (() => number) | undefined;
|
|
13
|
+
/** Waits `ms` unless `signal` aborts first; the default clears its timer on abort. */
|
|
14
|
+
readonly wait?: ((ms: number, signal: AbortSignal) => Promise<void>) | undefined;
|
|
15
|
+
/** The stream to read; defaults to the process's standard input. */
|
|
16
|
+
readonly stream?: StdinStream | undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** What a bounded read found: the text, and whether its deadline passed first. */
|
|
20
|
+
export interface StdinRead {
|
|
21
|
+
readonly text: string;
|
|
22
|
+
readonly timedOut: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function collect(stream: StdinStream): Promise<string> {
|
|
26
|
+
const chunks: Uint8Array[] = [];
|
|
27
|
+
for await (const chunk of stream) {
|
|
28
|
+
chunks.push(
|
|
29
|
+
typeof chunk === "string" ? Buffer.from(chunk, "utf8") : chunk,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Waits `ms`, or until `signal` aborts; either way the timer is gone. */
|
|
36
|
+
function timerWait(ms: number, signal: AbortSignal): Promise<void> {
|
|
37
|
+
return new Promise<void>((resolve) => {
|
|
38
|
+
const timer = setTimeout(resolve, ms);
|
|
39
|
+
signal.addEventListener(
|
|
40
|
+
"abort",
|
|
41
|
+
() => {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
resolve();
|
|
44
|
+
},
|
|
45
|
+
{ once: true },
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Reads standard input with a deadline. A stream that never ends is stopped
|
|
52
|
+
* when the deadline passes, so the caller gets an answer instead of waiting
|
|
53
|
+
* forever. A read that finishes first stops the deadline's wait as well. The
|
|
54
|
+
* clock and wait are injectable; production uses real time.
|
|
55
|
+
*/
|
|
56
|
+
export async function readStdinWithin(
|
|
57
|
+
input: string | undefined,
|
|
58
|
+
options: StdinReadOptions = {},
|
|
59
|
+
): Promise<StdinRead> {
|
|
60
|
+
if (input !== undefined) return { text: input, timedOut: false };
|
|
61
|
+
const stream = options.stream ?? process.stdin;
|
|
62
|
+
// A terminal has no piped request: an empty text is the only safe answer.
|
|
63
|
+
if (options.stream === undefined && process.stdin.isTTY === true) {
|
|
64
|
+
return { text: "", timedOut: false };
|
|
65
|
+
}
|
|
66
|
+
const reading = collect(stream);
|
|
67
|
+
if (options.timeoutMs === undefined) {
|
|
68
|
+
return { text: await reading, timedOut: false };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const clock = options.clock ?? (() => Date.now());
|
|
72
|
+
const wait = options.wait ?? timerWait;
|
|
73
|
+
const deadline = clock() + options.timeoutMs;
|
|
74
|
+
const stop = new AbortController();
|
|
75
|
+
const timeout = (async (): Promise<"timedOut"> => {
|
|
76
|
+
while (!stop.signal.aborted && clock() < deadline) {
|
|
77
|
+
await wait(Math.max(1, deadline - clock()), stop.signal);
|
|
78
|
+
}
|
|
79
|
+
return "timedOut";
|
|
80
|
+
})();
|
|
81
|
+
const outcome = await Promise.race([
|
|
82
|
+
reading.then((text) => ({ text, timedOut: false as const })),
|
|
83
|
+
timeout.then(() => ({ text: "", timedOut: true as const })),
|
|
84
|
+
]);
|
|
85
|
+
if (outcome.timedOut) {
|
|
86
|
+
// The read is no longer wanted. Destroying the stream releases its handle;
|
|
87
|
+
// its eventual result is ignored.
|
|
88
|
+
try {
|
|
89
|
+
stream.destroy?.();
|
|
90
|
+
} catch {
|
|
91
|
+
// The stream already ended.
|
|
92
|
+
}
|
|
93
|
+
void reading.catch(() => undefined);
|
|
94
|
+
} else {
|
|
95
|
+
// Nothing is waiting for the deadline any more, so drop its timer.
|
|
96
|
+
stop.abort();
|
|
97
|
+
}
|
|
98
|
+
return outcome;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Reads the text a command takes on standard input. */
|
|
102
|
+
export async function readStdinText(input?: string): Promise<string> {
|
|
103
|
+
const read = await readStdinWithin(input);
|
|
104
|
+
return read.text;
|
|
105
|
+
}
|