@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/lock.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/** The repository lock: one dev writer per repository, safe across processes. */
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { existsSync, readFileSync, realpathSync, statSync, unlinkSync } from "node:fs";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
import { defaultOperadHome } from "@operad-io/engine";
|
|
4
6
|
import {
|
|
5
7
|
LOCK_TIMEOUT_MS,
|
|
6
8
|
LockTimeoutError,
|
|
@@ -9,8 +11,100 @@ import {
|
|
|
9
11
|
} from "@operad-io/engine/platform";
|
|
10
12
|
import { DevError } from "./model.ts";
|
|
11
13
|
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
+
/**
|
|
15
|
+
* What a waiter may inject: the clock, how it waits, where a log goes, and the
|
|
16
|
+
* operad home that holds the lock file.
|
|
17
|
+
*/
|
|
18
|
+
export type RepositoryLockOptions = Omit<LockFileOptions, "label"> & {
|
|
19
|
+
/** The home whose `dev/repository-locks` holds the file; defaults to `$OPERAD_HOME`. */
|
|
20
|
+
readonly home?: string | undefined;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** Where an older dev kept its lock, inside the working tree. */
|
|
24
|
+
const LEGACY_LOCK_FILE = join(".operad", "dev.lock");
|
|
25
|
+
|
|
26
|
+
function realpathOr(path: string): string {
|
|
27
|
+
try {
|
|
28
|
+
return realpathSync.native(path);
|
|
29
|
+
} catch {
|
|
30
|
+
return path;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The git directory a repository shares with its worktrees. A normal checkout
|
|
36
|
+
* has `.git` as a directory; a linked worktree has a `.git` file naming its git
|
|
37
|
+
* directory, whose `commondir` file names the shared one. Reading both keeps
|
|
38
|
+
* the lock path off a git process and off the working tree.
|
|
39
|
+
*/
|
|
40
|
+
function commonGitDirectory(repositoryPath: string): string {
|
|
41
|
+
const dotGit = join(repositoryPath, ".git");
|
|
42
|
+
try {
|
|
43
|
+
if (statSync(dotGit).isDirectory()) return realpathOr(dotGit);
|
|
44
|
+
const line = /^gitdir:\s*(.+?)\s*$/m.exec(readFileSync(dotGit, "utf8"));
|
|
45
|
+
const named = line?.[1];
|
|
46
|
+
if (named !== undefined) {
|
|
47
|
+
const gitDirectory = resolve(repositoryPath, named);
|
|
48
|
+
const commonFile = join(gitDirectory, "commondir");
|
|
49
|
+
if (existsSync(commonFile)) {
|
|
50
|
+
const common = readFileSync(commonFile, "utf8").trim();
|
|
51
|
+
if (common.length > 0) return realpathOr(resolve(gitDirectory, common));
|
|
52
|
+
}
|
|
53
|
+
return realpathOr(gitDirectory);
|
|
54
|
+
}
|
|
55
|
+
} catch {
|
|
56
|
+
// Not a readable git checkout; its own path is the best identity left.
|
|
57
|
+
}
|
|
58
|
+
return realpathOr(resolve(repositoryPath));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The identity of a repository, shared by every worktree, so a lock taken
|
|
63
|
+
* through one holds through all.
|
|
64
|
+
*/
|
|
65
|
+
function repositoryKey(repositoryPath: string): string {
|
|
66
|
+
return new Bun.CryptoHasher("sha1")
|
|
67
|
+
.update(commonGitDirectory(repositoryPath))
|
|
68
|
+
.digest("hex");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The lock file of one repository. It lives in the operad home, never in the
|
|
73
|
+
* working tree: a held lock must not make the main clone look dirty to a merge.
|
|
74
|
+
*/
|
|
75
|
+
export function repositoryLockPath(
|
|
76
|
+
repositoryPath: string,
|
|
77
|
+
home: string = defaultOperadHome(),
|
|
78
|
+
): string {
|
|
79
|
+
return join(home, "dev", "repository-locks", `${repositoryKey(repositoryPath)}.lock`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Removes the lock older versions left in the working tree, but only when
|
|
84
|
+
* nobody holds it. An old holder keeps it until it ends; that lock is not ours
|
|
85
|
+
* and its process still relies on it.
|
|
86
|
+
*/
|
|
87
|
+
async function removeLegacyLock(repositoryPath: string): Promise<void> {
|
|
88
|
+
const legacy = join(repositoryPath, LEGACY_LOCK_FILE);
|
|
89
|
+
if (!existsSync(legacy)) return;
|
|
90
|
+
const held = new Error("the legacy dev lock is held");
|
|
91
|
+
try {
|
|
92
|
+
await withLockFile(
|
|
93
|
+
legacy,
|
|
94
|
+
() => {
|
|
95
|
+
unlinkSync(legacy);
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
label: "dev lock",
|
|
99
|
+
onLog: () => {},
|
|
100
|
+
timeoutMs: 0,
|
|
101
|
+
wait: () => Promise.reject(held),
|
|
102
|
+
},
|
|
103
|
+
);
|
|
104
|
+
} catch {
|
|
105
|
+
// A held or unreadable old lock is left as it is; the new lock is elsewhere.
|
|
106
|
+
}
|
|
107
|
+
}
|
|
14
108
|
|
|
15
109
|
/**
|
|
16
110
|
* Holds one repository's lock while ids and counts change. The lock file makes
|
|
@@ -21,9 +115,11 @@ export async function withRepositoryLock<T>(
|
|
|
21
115
|
work: () => Promise<T> | T,
|
|
22
116
|
options: RepositoryLockOptions = {},
|
|
23
117
|
): Promise<T> {
|
|
24
|
-
|
|
118
|
+
await removeLegacyLock(repositoryPath);
|
|
119
|
+
const { home, ...lockOptions } = options;
|
|
120
|
+
const lockPath = repositoryLockPath(repositoryPath, home);
|
|
25
121
|
try {
|
|
26
|
-
return await withLockFile(lockPath, work, { ...
|
|
122
|
+
return await withLockFile(lockPath, work, { ...lockOptions, label: "dev lock" });
|
|
27
123
|
} catch (error) {
|
|
28
124
|
if (error instanceof LockTimeoutError) {
|
|
29
125
|
throw new DevError(
|
package/src/mainclone.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* through git is ever used: no reset, rebase or stash.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { git } from "./
|
|
8
|
+
import { git, isAncestor } from "./git.ts";
|
|
9
9
|
|
|
10
10
|
/** What a command runner reports. */
|
|
11
11
|
export interface CommandResult {
|
|
@@ -23,6 +23,18 @@ export type CommandRunner = (
|
|
|
23
23
|
line: string,
|
|
24
24
|
) => Promise<CommandResult>;
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* The task's durable record of whether this merge's prepare still has to run.
|
|
28
|
+
* It is saved before the fast-forward, so a restart after the clone moved runs
|
|
29
|
+
* the lines even when the clone already holds the commit.
|
|
30
|
+
*/
|
|
31
|
+
export interface PrepareMarker {
|
|
32
|
+
/** True when the record says this merge moved the clone and prepare is not done. */
|
|
33
|
+
readonly due: boolean;
|
|
34
|
+
/** Saves whether prepare is due; false when the record could not be written. */
|
|
35
|
+
readonly save: (due: boolean) => Promise<boolean>;
|
|
36
|
+
}
|
|
37
|
+
|
|
26
38
|
/** What happened to the main clone. */
|
|
27
39
|
export interface MainCloneOutcome {
|
|
28
40
|
readonly updated: boolean;
|
|
@@ -57,6 +69,18 @@ async function prepare(
|
|
|
57
69
|
return { updated: true, prepared: true, note: "prepare done" };
|
|
58
70
|
}
|
|
59
71
|
|
|
72
|
+
/** Runs prepare and records that it is no longer due, even when a line failed. */
|
|
73
|
+
async function prepareAndClear(
|
|
74
|
+
repository: string,
|
|
75
|
+
lines: readonly string[],
|
|
76
|
+
run: CommandRunner,
|
|
77
|
+
marker: PrepareMarker | undefined,
|
|
78
|
+
): Promise<MainCloneOutcome> {
|
|
79
|
+
const outcome = await prepare(repository, lines, run);
|
|
80
|
+
await marker?.save(false);
|
|
81
|
+
return outcome;
|
|
82
|
+
}
|
|
83
|
+
|
|
60
84
|
/** The text a task's Changes shows, or undefined when there is nothing to say. */
|
|
61
85
|
export function mainCloneChange(outcome: MainCloneOutcome): string | undefined {
|
|
62
86
|
if (!outcome.updated) return `main clone not updated: ${outcome.note ?? "unknown"}`;
|
|
@@ -65,7 +89,9 @@ export function mainCloneChange(outcome: MainCloneOutcome): string | undefined {
|
|
|
65
89
|
|
|
66
90
|
/**
|
|
67
91
|
* Fast-forwards the main clone to `sha` when it is on `branch` and clean, then
|
|
68
|
-
* runs the prepare lines there when the clone moved.
|
|
92
|
+
* runs the prepare lines there when the clone moved. A marker left by an
|
|
93
|
+
* interrupted merge makes a replay run prepare even when the clone already
|
|
94
|
+
* holds the commit.
|
|
69
95
|
*/
|
|
70
96
|
export async function updateMainClone(
|
|
71
97
|
repository: string,
|
|
@@ -73,6 +99,7 @@ export async function updateMainClone(
|
|
|
73
99
|
sha: string,
|
|
74
100
|
lines: readonly string[],
|
|
75
101
|
run: CommandRunner,
|
|
102
|
+
marker?: PrepareMarker | undefined,
|
|
76
103
|
): Promise<MainCloneOutcome> {
|
|
77
104
|
const current = git(repository, ["symbolic-ref", "--short", "-q", "HEAD"]);
|
|
78
105
|
if (!current.ok || current.out !== branch) {
|
|
@@ -88,15 +115,27 @@ export async function updateMainClone(
|
|
|
88
115
|
if (status.out.length > 0) {
|
|
89
116
|
return { updated: false, note: "uncommitted changes" };
|
|
90
117
|
}
|
|
91
|
-
|
|
92
|
-
|
|
118
|
+
const already = isAncestor(repository, sha, "HEAD");
|
|
119
|
+
if (already) {
|
|
120
|
+
if (marker?.due !== true) return { updated: true };
|
|
121
|
+
if (lines.length === 0) {
|
|
122
|
+
await marker.save(false);
|
|
123
|
+
return { updated: true };
|
|
124
|
+
}
|
|
125
|
+
return prepareAndClear(repository, lines, run, marker);
|
|
126
|
+
}
|
|
127
|
+
if (lines.length > 0 && marker !== undefined) {
|
|
128
|
+
if (!(await marker.save(true))) {
|
|
129
|
+
return { updated: false, note: "cannot record that prepare is due" };
|
|
130
|
+
}
|
|
93
131
|
}
|
|
94
132
|
const merge = git(repository, ["merge", "--ff-only", sha]);
|
|
95
133
|
if (!merge.ok) {
|
|
134
|
+
if (lines.length > 0 && marker !== undefined) await marker.save(marker.due);
|
|
96
135
|
return {
|
|
97
136
|
updated: false,
|
|
98
137
|
note: `cannot fast-forward: ${lastLine(merge.err || merge.out) || "git merge failed"}`,
|
|
99
138
|
};
|
|
100
139
|
}
|
|
101
|
-
return
|
|
140
|
+
return prepareAndClear(repository, lines, run, marker);
|
|
102
141
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a harness's `modelError` says, as dev reads it. A harness reports the
|
|
3
|
+
* kind, the model's own message and, when it knows it, how long to wait.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { isRecord } from "@operad-io/engine";
|
|
7
|
+
import { MAX_MODEL_RETRY_SECS } from "./timeouts.ts";
|
|
8
|
+
|
|
9
|
+
export interface ModelErrorInfo {
|
|
10
|
+
/** `unavailable` or `usage_limit`; another kind is not a model outage. */
|
|
11
|
+
readonly kind: string;
|
|
12
|
+
/** The model's own message, when it gave one. */
|
|
13
|
+
readonly message?: string;
|
|
14
|
+
/** How long the model said to wait, in seconds; absent when it did not say. */
|
|
15
|
+
readonly retryAfterSecs?: number;
|
|
16
|
+
/** When the model reported the wait, in epoch milliseconds; absent when unknown. */
|
|
17
|
+
readonly reportedAt?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A positive epoch time, or undefined when the value is not one. */
|
|
21
|
+
function positiveTime(value: unknown): number | undefined {
|
|
22
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0
|
|
23
|
+
? value
|
|
24
|
+
: undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function retryAfterSecs(value: unknown): number | undefined {
|
|
28
|
+
return positiveTime(value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A normalized model error, or undefined when the value is not one. */
|
|
32
|
+
export function readModelError(value: unknown): ModelErrorInfo | undefined {
|
|
33
|
+
if (!isRecord(value) || typeof value.kind !== "string") return undefined;
|
|
34
|
+
if (value.kind !== "unavailable" && value.kind !== "usage_limit") {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
const message =
|
|
38
|
+
typeof value.message === "string" && value.message.length > 0
|
|
39
|
+
? value.message
|
|
40
|
+
: undefined;
|
|
41
|
+
const retry = retryAfterSecs(value.retry_after_secs);
|
|
42
|
+
const reported = positiveTime(value.reported_at);
|
|
43
|
+
return {
|
|
44
|
+
kind: value.kind,
|
|
45
|
+
...(message === undefined ? {} : { message }),
|
|
46
|
+
...(retry === undefined ? {} : { retryAfterSecs: retry }),
|
|
47
|
+
...(reported === undefined ? {} : { reportedAt: reported }),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The model error a harness step put in its result data, when it put one. */
|
|
52
|
+
export function modelErrorIn(
|
|
53
|
+
data: Readonly<Record<string, unknown>> | undefined,
|
|
54
|
+
): ModelErrorInfo | undefined {
|
|
55
|
+
return readModelError(data?.modelError);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* True when dev must not retry the run on its own. A usage limit is not an
|
|
60
|
+
* outage to wait out: the account cannot serve until its period ends. A
|
|
61
|
+
* retry-after longer than half an hour is the same kind of wait, and a person
|
|
62
|
+
* decides whether to switch the worker or wait for the model.
|
|
63
|
+
*/
|
|
64
|
+
export function modelWaitsForPerson(error: ModelErrorInfo): boolean {
|
|
65
|
+
return (
|
|
66
|
+
error.kind === "usage_limit" ||
|
|
67
|
+
(error.retryAfterSecs !== undefined &&
|
|
68
|
+
error.retryAfterSecs > MAX_MODEL_RETRY_SECS)
|
|
69
|
+
);
|
|
70
|
+
}
|
package/src/model.ts
CHANGED
|
@@ -1,28 +1,55 @@
|
|
|
1
1
|
/** The objects the dev plugin owns, and the pure rules that change them. */
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
FlowDefinition,
|
|
5
|
+
ObjectStore,
|
|
6
|
+
PluginFact,
|
|
7
|
+
StoredObject,
|
|
8
|
+
} from "@operad-io/engine";
|
|
4
9
|
import type { ReviewHistoryEntry, ReviewSettingsUsed } from "./rework.ts";
|
|
10
|
+
import type { ModelErrorInfo } from "./model-error.ts";
|
|
5
11
|
import type { WaitKind } from "./waits.ts";
|
|
6
12
|
import { isRecord, oneLine } from "@operad-io/engine";
|
|
7
13
|
|
|
8
|
-
/**
|
|
9
|
-
* Every object of a type, following the store's pages. The store returns one
|
|
14
|
+
/** Every object of a type, following the store's pages. The store returns one
|
|
10
15
|
* page at a time; an id scan must not stop at its default limit.
|
|
11
16
|
*/
|
|
12
17
|
export async function listAll(
|
|
13
18
|
store: ObjectStore,
|
|
14
19
|
type: string,
|
|
20
|
+
where?: Readonly<Record<string, unknown>> | undefined,
|
|
15
21
|
): Promise<StoredObject[]> {
|
|
16
22
|
const objects: StoredObject[] = [];
|
|
17
23
|
let cursor: string | undefined;
|
|
18
24
|
for (;;) {
|
|
19
|
-
const page = await store.list(type,
|
|
25
|
+
const page = await store.list(type, {
|
|
26
|
+
...(where === undefined ? {} : { where }),
|
|
27
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
28
|
+
});
|
|
20
29
|
objects.push(...page.objects);
|
|
21
30
|
if (page.next === undefined) return objects;
|
|
22
31
|
cursor = page.next;
|
|
23
32
|
}
|
|
24
33
|
}
|
|
25
34
|
|
|
35
|
+
/** Every fact of one object, following the store's pages. */
|
|
36
|
+
export async function allFactsOf(
|
|
37
|
+
store: ObjectStore,
|
|
38
|
+
object: Pick<StoredObject, "type" | "id">,
|
|
39
|
+
): Promise<PluginFact[]> {
|
|
40
|
+
const facts: PluginFact[] = [];
|
|
41
|
+
let cursor: string | undefined;
|
|
42
|
+
for (;;) {
|
|
43
|
+
const page = await store.facts(
|
|
44
|
+
{ type: object.type, id: object.id },
|
|
45
|
+
cursor === undefined ? {} : { cursor },
|
|
46
|
+
);
|
|
47
|
+
facts.push(...page.facts);
|
|
48
|
+
if (page.next === undefined) return facts;
|
|
49
|
+
cursor = page.next;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
26
53
|
/** A plan is a request the owner confirmed into work. */
|
|
27
54
|
export type PlanStatus = "draft" | "confirmed" | "paused" | "cancelled";
|
|
28
55
|
|
|
@@ -238,6 +265,8 @@ export interface ReviewRunRecord {
|
|
|
238
265
|
readonly outcome: ReviewRunOutcome;
|
|
239
266
|
readonly run?: string | null;
|
|
240
267
|
readonly message?: string | null;
|
|
268
|
+
/** What the model error said, when this run ended on one. */
|
|
269
|
+
readonly modelError?: ModelErrorInfo | null;
|
|
241
270
|
/** The findings a report run returned, with pre-existing marks. */
|
|
242
271
|
readonly findings?: readonly ReviewFinding[] | null;
|
|
243
272
|
readonly verified?: readonly string[] | null;
|
|
@@ -317,6 +346,8 @@ export interface IntegrationRecord {
|
|
|
317
346
|
/** True when the branch head was no longer the verified commit. */
|
|
318
347
|
readonly headMoved?: boolean | null;
|
|
319
348
|
readonly pushed?: boolean | null;
|
|
349
|
+
/** True when this merge moved the clone and its prepare lines have not finished. */
|
|
350
|
+
readonly prepareDue?: boolean | null;
|
|
320
351
|
readonly message?: string | null;
|
|
321
352
|
readonly command?: string | null;
|
|
322
353
|
readonly log?: string | null;
|
|
@@ -646,6 +677,17 @@ export function validateSlug(slug: unknown): string {
|
|
|
646
677
|
return slug;
|
|
647
678
|
}
|
|
648
679
|
|
|
680
|
+
/** The slug an action takes from a title when it is given none. */
|
|
681
|
+
export function slugFromTitle(title: unknown, fallback: string): string {
|
|
682
|
+
const text = typeof title === "string" ? title : "";
|
|
683
|
+
const words = text
|
|
684
|
+
.toLowerCase()
|
|
685
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
686
|
+
.replace(/^-+|-+$/g, "");
|
|
687
|
+
const slug = words.slice(0, 48).replace(/-+$/g, "");
|
|
688
|
+
return slug.length === 0 ? fallback : slug;
|
|
689
|
+
}
|
|
690
|
+
|
|
649
691
|
export function validateTitle(title: unknown): string {
|
|
650
692
|
if (typeof title !== "string" || title.trim().length === 0) {
|
|
651
693
|
throw new DevError("title", "must be a non-empty string");
|
|
@@ -705,7 +747,7 @@ function numberById(
|
|
|
705
747
|
let highest = 0;
|
|
706
748
|
for (const object of objects) {
|
|
707
749
|
// The store key carries the repository; the number lives in the bare id.
|
|
708
|
-
const parsed = parseId(
|
|
750
|
+
const parsed = parseId(idOfKey(object.id), kind);
|
|
709
751
|
if (parsed !== undefined && parsed.number > highest) {
|
|
710
752
|
highest = parsed.number;
|
|
711
753
|
}
|
|
@@ -723,7 +765,7 @@ export function storeKey(repository: string, id: string): string {
|
|
|
723
765
|
}
|
|
724
766
|
|
|
725
767
|
/** The id a person sees and types: the key without its repository prefix. */
|
|
726
|
-
export function
|
|
768
|
+
export function idOfKey(key: string): string {
|
|
727
769
|
const at = key.indexOf("/");
|
|
728
770
|
return at < 0 ? key : key.slice(at + 1);
|
|
729
771
|
}
|
|
@@ -739,7 +781,7 @@ export function dependencyKey(repository: string, entry: string): string {
|
|
|
739
781
|
|
|
740
782
|
/** How a dependency is named in a note: bare in its own repository. */
|
|
741
783
|
export function dependencyLabel(repository: string, key: string): string {
|
|
742
|
-
return keyRepository(key) === repository ?
|
|
784
|
+
return keyRepository(key) === repository ? idOfKey(key) : key;
|
|
743
785
|
}
|
|
744
786
|
|
|
745
787
|
/** The repository part of a store key. */
|
|
@@ -759,11 +801,7 @@ export async function nextId(
|
|
|
759
801
|
repository: string,
|
|
760
802
|
slug: string,
|
|
761
803
|
): Promise<string> {
|
|
762
|
-
const
|
|
763
|
-
const mine = all.filter(
|
|
764
|
-
(object) =>
|
|
765
|
-
isRecord(object.data) && object.data.repository === repository,
|
|
766
|
-
);
|
|
804
|
+
const mine = await listAll(store, type, { repository });
|
|
767
805
|
let number = numberById(mine, type) + 1;
|
|
768
806
|
for (;;) {
|
|
769
807
|
const id = formatId(type, number, slug);
|
|
@@ -1022,16 +1060,6 @@ export function briefBody(brief: string): string {
|
|
|
1022
1060
|
return splitBrief(brief).body;
|
|
1023
1061
|
}
|
|
1024
1062
|
|
|
1025
|
-
/** The Markdown of the rework sections, without the changes section. */
|
|
1026
|
-
export function reworkBody(brief: string): string {
|
|
1027
|
-
return splitBrief(brief).reworks;
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
/** The Markdown of the trailing changes section. */
|
|
1031
|
-
export function changesBody(brief: string): string {
|
|
1032
|
-
return splitBrief(brief).changes;
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
1063
|
/** Replaces the body and records the edit, unless the body did not change. */
|
|
1036
1064
|
export function editBrief(brief: string, body: string): string {
|
|
1037
1065
|
if (briefBody(brief) === body.replace(/\r\n/g, "\n").trimEnd()) return brief;
|
|
@@ -1137,23 +1165,10 @@ export function planNote(plan: PlanData): string {
|
|
|
1137
1165
|
return `${parts.join(" · ")} // ${plan.concurrency}`;
|
|
1138
1166
|
}
|
|
1139
1167
|
|
|
1140
|
-
export function planDataOf(data: Record<string, unknown>): PlanData {
|
|
1141
|
-
return planData(data);
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
export function taskDataOf(data: Record<string, unknown>): TaskData {
|
|
1145
|
-
return taskData(data);
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
1168
|
export function priorityIndex(priority: Priority): number {
|
|
1149
1169
|
return PRIORITIES.indexOf(priority);
|
|
1150
1170
|
}
|
|
1151
1171
|
|
|
1152
|
-
export function higherPriority(priority: Priority): Priority | undefined {
|
|
1153
|
-
const index = priorityIndex(priority);
|
|
1154
|
-
return index <= 0 ? undefined : PRIORITIES[index - 1];
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
1172
|
/** A task is open until it merged or was cancelled. */
|
|
1158
1173
|
export function isOpenTask(task: TaskData): boolean {
|
|
1159
1174
|
return task.phase !== "merged" && task.phase !== "cancelled";
|
package/src/notcode.ts
CHANGED
|
@@ -37,6 +37,7 @@ import { waitFor } from "./gate.ts";
|
|
|
37
37
|
import { flakyLoadLimitOf } from "./flaky.ts";
|
|
38
38
|
import { readSince, type CheckRun } from "./rerun.ts";
|
|
39
39
|
import { isRecord } from "@operad-io/engine";
|
|
40
|
+
import { loadsFromLog, underLoad, type CheckLoad, type CheckLoadReading } from "./check-load.ts";
|
|
40
41
|
|
|
41
42
|
/** The kind of a "not the code" result. */
|
|
42
43
|
export type NotCodeKind = "limit" | "signal" | "test-timeout" | "rerun-passed";
|
|
@@ -177,14 +178,35 @@ function worthAnotherRun(found: NotCode | undefined): found is NotCode {
|
|
|
177
178
|
}
|
|
178
179
|
|
|
179
180
|
/** The waiting line for a check that came out the same way twice. */
|
|
180
|
-
export function notCodeCause(found: NotCode, load:
|
|
181
|
-
|
|
181
|
+
export function notCodeCause(found: NotCode, load: CheckLoadReading): string {
|
|
182
|
+
const shown = load.unknown === true ? undefined : String(Math.round(load.load1));
|
|
183
|
+
return `${found.what} twice ${underLoad(load, shown)}`;
|
|
182
184
|
}
|
|
183
185
|
|
|
184
|
-
/** The
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
/** The busiest of a run's two readings, keeping an unknown reading as it is. */
|
|
187
|
+
function peakOf(load: CheckLoad): CheckLoadReading {
|
|
188
|
+
if (load.start.unknown === true) return load.start;
|
|
189
|
+
if (load.end.unknown === true) return load.end;
|
|
190
|
+
return load.end.load1 >= load.start.load1 ? load.end : load.start;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* A run's load: what remote-check.sh wrote into its part of the log, else the
|
|
195
|
+
* local readings around it. A remote line that says unknown is not replaced.
|
|
196
|
+
* The part starts where the run's first command said its output began, not at
|
|
197
|
+
* a file size read before the run, which a buffered logger can leave stale.
|
|
198
|
+
*/
|
|
199
|
+
function loadOfRun(
|
|
200
|
+
path: string | undefined,
|
|
201
|
+
checked: CheckRun,
|
|
202
|
+
start: MachineLoad,
|
|
203
|
+
end: MachineLoad,
|
|
204
|
+
): CheckLoad {
|
|
205
|
+
if (path !== undefined && checked.logStart !== undefined) {
|
|
206
|
+
const remote = loadsFromLog(readSince(path, checked.logStart));
|
|
207
|
+
if (remote !== undefined) return remote;
|
|
208
|
+
}
|
|
209
|
+
return { start, end };
|
|
188
210
|
}
|
|
189
211
|
|
|
190
212
|
/**
|
|
@@ -202,15 +224,19 @@ function timeoutAlone(
|
|
|
202
224
|
const limit = flakyLoadLimitOf(flakyLimit, load.end);
|
|
203
225
|
// Busy means above the limit, as `flaky.ts` reads it. The reading spans the whole
|
|
204
226
|
// check run (full suite and alone rerun), so a quiet reading is a strict test.
|
|
205
|
-
|
|
227
|
+
// An unknown reading is judged as quiet, never against the local load.
|
|
228
|
+
const busy = (reading: CheckLoadReading): boolean =>
|
|
229
|
+
reading.unknown !== true && reading.load1 > limit;
|
|
230
|
+
if (busy(load.start) || busy(load.end)) return undefined;
|
|
206
231
|
const outcome = checked.outcome;
|
|
207
232
|
if (outcome === undefined) return undefined;
|
|
208
233
|
const data = isRecord(outcome.data) ? outcome.data : {};
|
|
209
234
|
const names = failedTests(facts.log).map((test) => test.name).join("; ");
|
|
210
235
|
const seconds = testTimeoutOf(facts.line) / 1000;
|
|
211
|
-
const peak =
|
|
236
|
+
const peak = peakOf(load);
|
|
237
|
+
const shown = peak.unknown === true ? undefined : String(Number(peak.load1.toFixed(1)));
|
|
212
238
|
const log = typeof data.log === "string" ? `; log: ${data.log}` : "";
|
|
213
|
-
const message = `the failed test "${names}" timed out at ${seconds} s when run alone
|
|
239
|
+
const message = `the failed test "${names}" timed out at ${seconds} s when run alone ${underLoad(peak, shown)}${log}`;
|
|
214
240
|
return { ...checked, outcome: { ...outcome, data: { ...data, message } } };
|
|
215
241
|
}
|
|
216
242
|
|
|
@@ -266,6 +292,8 @@ export async function runCheckSteadily(input: {
|
|
|
266
292
|
readonly flakyLimit?: number | undefined;
|
|
267
293
|
readonly signal?: AbortSignal | undefined;
|
|
268
294
|
readonly log?: ((text: string) => Promise<unknown> | unknown) | undefined;
|
|
295
|
+
/** The step's log; the remote load lines are read from each run's part of it. */
|
|
296
|
+
readonly logPath?: string | undefined;
|
|
269
297
|
}): Promise<SteadyCheck> {
|
|
270
298
|
const firstStart = currentLoad();
|
|
271
299
|
let peak = firstStart;
|
|
@@ -276,20 +304,28 @@ export async function runCheckSteadily(input: {
|
|
|
276
304
|
};
|
|
277
305
|
const first = await input.run();
|
|
278
306
|
const firstEnd = sample();
|
|
279
|
-
const
|
|
280
|
-
const
|
|
307
|
+
const firstLoad = loadOfRun(input.logPath, first, firstStart, firstEnd);
|
|
308
|
+
const loads: CheckLoad[] = [firstLoad];
|
|
309
|
+
const firstCode = timeoutAlone(first, firstLoad, input.flakyLimit);
|
|
281
310
|
if (firstCode !== undefined) return { checked: firstCode, runs: 1, load: peak, loads };
|
|
282
311
|
if (!worthAnotherRun(classifyRun(first))) {
|
|
283
312
|
return { checked: first, runs: 1, load: peak, loads };
|
|
284
313
|
}
|
|
285
|
-
|
|
314
|
+
// A remote check read its own host's load; there is no local reading to wait
|
|
315
|
+
// on, and an unknown one must not fall back to this machine either.
|
|
316
|
+
const quiet =
|
|
317
|
+
firstLoad.start.host !== undefined || firstLoad.start.unknown === true
|
|
318
|
+
? true
|
|
319
|
+
: await waitForQuiet(input.limit, input.signal, input.log ?? (() => {}));
|
|
320
|
+
if (!quiet) {
|
|
286
321
|
return { checked: first, runs: 1, load: peak, loads, cancelled: true };
|
|
287
322
|
}
|
|
288
323
|
const secondStart = sample();
|
|
289
324
|
const second = await input.run();
|
|
290
325
|
const after = sample();
|
|
291
|
-
|
|
292
|
-
|
|
326
|
+
const secondLoad = loadOfRun(input.logPath, second, secondStart, after);
|
|
327
|
+
loads.push(secondLoad);
|
|
328
|
+
const secondCode = timeoutAlone(second, secondLoad, input.flakyLimit);
|
|
293
329
|
if (secondCode !== undefined) return { checked: secondCode, runs: 2, load: peak, loads };
|
|
294
330
|
const found = classifyRun(second);
|
|
295
331
|
if (!worthAnotherRun(found)) {
|
|
@@ -300,6 +336,6 @@ export async function runCheckSteadily(input: {
|
|
|
300
336
|
runs: 2,
|
|
301
337
|
load: peak,
|
|
302
338
|
loads,
|
|
303
|
-
notCode: { cause: notCodeCause(found,
|
|
339
|
+
notCode: { cause: notCodeCause(found, secondLoad.end), kind: found.kind },
|
|
304
340
|
};
|
|
305
341
|
}
|
package/src/places.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type { StepContext } from "@operad-io/engine";
|
|
|
13
13
|
import { taskPlaceWait } from "./place-wait.ts";
|
|
14
14
|
import { withLockFile, waitForChange } from "@operad-io/engine/platform";
|
|
15
15
|
import { WaitEntry, type CheckKind } from "./place-order.ts";
|
|
16
|
+
import { repositoryPathKey } from "./repository-key.ts";
|
|
16
17
|
|
|
17
18
|
export { VERIFY_STARVATION_MS, type CheckKind } from "./place-order.ts";
|
|
18
19
|
|
|
@@ -105,9 +106,8 @@ class PlaceBusy extends Error {
|
|
|
105
106
|
|
|
106
107
|
/** The lock files of the repository's places, next to the home's. */
|
|
107
108
|
function repositoryKey(repository: RepositoryPlaces): string {
|
|
108
|
-
const hash = new Bun.CryptoHasher("sha1").update(repository.path).digest("hex");
|
|
109
109
|
const name = repository.name.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
110
|
-
return `repo-${name}-${
|
|
110
|
+
return `repo-${name}-${repositoryPathKey(repository.path).slice(0, 8)}`;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/**
|
package/src/prepare.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* plain checkout: dev installs and links nothing itself.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { isRecord, messageOf, type StepContext, type StepRunOptions } from "@operad-io/engine";
|
|
7
|
+
import { isRecord, messageOf, type JsonValue, type StepContext, type StepRunOptions } from "@operad-io/engine";
|
|
8
8
|
|
|
9
9
|
import type { CommandRunner } from "./mainclone.ts";
|
|
10
10
|
import type { DevSettings } from "./settings.ts";
|
|
@@ -12,13 +12,18 @@ import type { DevSettings } from "./settings.ts";
|
|
|
12
12
|
/** The reason a step reports when a prepare command failed. */
|
|
13
13
|
export const PREPARE_FAILED = "prepare failed";
|
|
14
14
|
|
|
15
|
+
/** The profile every step of a dev task uses: the default's denies, not its asks (ADR 0025 D9). */
|
|
16
|
+
export function taskStepAccess(access: JsonValue): JsonValue {
|
|
17
|
+
return { ...(isRecord(access) ? access : {}), defaultAsks: false };
|
|
18
|
+
}
|
|
19
|
+
|
|
15
20
|
export function stepOptions(ctx: StepContext, cwd: string): StepRunOptions {
|
|
16
21
|
return {
|
|
17
22
|
runId: ctx.runId,
|
|
18
23
|
cwd,
|
|
19
24
|
...(ctx.object === undefined ? {} : { object: ctx.object }),
|
|
20
25
|
params: ctx.params,
|
|
21
|
-
access: ctx.access,
|
|
26
|
+
access: taskStepAccess(ctx.access),
|
|
22
27
|
...(ctx.trigger === undefined ? {} : { trigger: ctx.trigger }),
|
|
23
28
|
signal: ctx.signal,
|
|
24
29
|
};
|