@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.
- package/README.md +1 -1
- package/dev.schema.json +53 -31
- package/package.json +9 -6
- package/skills/git/SKILL.md +70 -0
- package/skills/setup/SKILL.md +74 -0
- package/src/access-grants.ts +59 -0
- package/src/actions.ts +81 -17
- package/src/announce.ts +134 -17
- package/src/chat.ts +586 -36
- package/src/check-host.ts +111 -0
- package/src/check-load.ts +67 -0
- package/src/check.ts +45 -22
- package/src/clock.ts +29 -0
- package/src/clone-chat.ts +32 -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 +156 -69
- package/src/followups.ts +20 -22
- package/src/gate.ts +254 -88
- package/src/git-state.ts +155 -0
- package/src/git.ts +92 -4
- package/src/index.ts +52 -6
- package/src/integrate.ts +162 -62
- package/src/integration-queue.ts +23 -10
- package/src/lock.ts +101 -5
- package/src/mainclone.ts +61 -5
- package/src/model-error.ts +70 -0
- package/src/model.ts +61 -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 +110 -3
- package/src/register-requests.ts +121 -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 +342 -93
- package/src/service.ts +241 -185
- package/src/settings.ts +409 -65
- package/src/setup-git.ts +366 -0
- package/src/standing.ts +23 -6
- package/src/step-edge.ts +22 -0
- package/src/steps.ts +945 -179
- package/src/throughput.ts +4 -21
- package/src/timeouts.ts +10 -2
- package/src/views.ts +325 -86
- package/src/waits.ts +59 -0
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 {
|
|
@@ -44,6 +44,23 @@ export interface MainCloneOutcome {
|
|
|
44
44
|
readonly prepared?: boolean | undefined;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Why a fast-forward refused. When untracked files are in the way, git lists
|
|
49
|
+
* them before "Aborting"; say which.
|
|
50
|
+
*/
|
|
51
|
+
function mergeReason(text: string): string {
|
|
52
|
+
const lines = text.split("\n");
|
|
53
|
+
const at = lines.findIndex((line) => line.includes("untracked working tree files would be overwritten"));
|
|
54
|
+
if (at >= 0) {
|
|
55
|
+
const files = lines
|
|
56
|
+
.slice(at + 1)
|
|
57
|
+
.filter((line) => line.startsWith("\t") || line.startsWith(" "))
|
|
58
|
+
.map((line) => line.trim());
|
|
59
|
+
if (files.length > 0) return `untracked files in the way: ${files.join(", ")}`;
|
|
60
|
+
}
|
|
61
|
+
return lastLine(text);
|
|
62
|
+
}
|
|
63
|
+
|
|
47
64
|
function lastLine(text: string): string {
|
|
48
65
|
const lines = text.split("\n").filter((line) => line.trim().length > 0);
|
|
49
66
|
return lines[lines.length - 1] ?? "";
|
|
@@ -87,6 +104,45 @@ export function mainCloneChange(outcome: MainCloneOutcome): string | undefined {
|
|
|
87
104
|
return outcome.note === undefined ? undefined : `main clone: ${outcome.note}`;
|
|
88
105
|
}
|
|
89
106
|
|
|
107
|
+
/**
|
|
108
|
+
* In branch mode the clone is on the task's branch when the merge lands. Put it
|
|
109
|
+
* back on the branch it started on so the fast-forward can follow. A clone the
|
|
110
|
+
* person moved, or left with uncommitted changes, stays as it is and the note
|
|
111
|
+
* says where it is.
|
|
112
|
+
*/
|
|
113
|
+
export function switchBackToStart(
|
|
114
|
+
repository: string,
|
|
115
|
+
start: string,
|
|
116
|
+
taskBranch: string,
|
|
117
|
+
): { readonly ok: true } | { readonly ok: false; readonly note: string } {
|
|
118
|
+
const current = git(repository, ["symbolic-ref", "--short", "-q", "HEAD"]);
|
|
119
|
+
if (current.ok && current.out === start) return { ok: true };
|
|
120
|
+
if (!current.ok || current.out !== taskBranch) {
|
|
121
|
+
return {
|
|
122
|
+
ok: false,
|
|
123
|
+
note: `the main clone is on ${current.ok ? `"${current.out}"` : "no branch"}, not on the task's branch "${taskBranch}" or "${start}"; it was left as it is`,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const status = git(repository, ["status", "--porcelain", "--untracked-files=normal"]);
|
|
127
|
+
if (!status.ok) {
|
|
128
|
+
return { ok: false, note: `cannot read its status: ${status.err}; the main clone stays on "${taskBranch}"` };
|
|
129
|
+
}
|
|
130
|
+
if (status.out.length > 0) {
|
|
131
|
+
return {
|
|
132
|
+
ok: false,
|
|
133
|
+
note: `uncommitted changes; the main clone stays on "${taskBranch}", not "${start}"`,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const moved = git(repository, ["switch", "-q", start]);
|
|
137
|
+
if (!moved.ok) {
|
|
138
|
+
return {
|
|
139
|
+
ok: false,
|
|
140
|
+
note: `cannot switch back to "${start}": ${lastLine(moved.err || moved.out) || "git switch failed"}; the main clone stays on "${taskBranch}"`,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return { ok: true };
|
|
144
|
+
}
|
|
145
|
+
|
|
90
146
|
/**
|
|
91
147
|
* Fast-forwards the main clone to `sha` when it is on `branch` and clean, then
|
|
92
148
|
* runs the prepare lines there when the clone moved. A marker left by an
|
|
@@ -108,14 +164,14 @@ export async function updateMainClone(
|
|
|
108
164
|
note: `the main clone is on ${current.ok ? `"${current.out}"` : "no branch"}, not "${branch}"`,
|
|
109
165
|
};
|
|
110
166
|
}
|
|
111
|
-
const status = git(repository, ["status", "--porcelain", "--untracked-files=
|
|
167
|
+
const status = git(repository, ["status", "--porcelain", "--untracked-files=no"]);
|
|
112
168
|
if (!status.ok) {
|
|
113
169
|
return { updated: false, note: `cannot read its status: ${status.err}` };
|
|
114
170
|
}
|
|
115
171
|
if (status.out.length > 0) {
|
|
116
172
|
return { updated: false, note: "uncommitted changes" };
|
|
117
173
|
}
|
|
118
|
-
const already =
|
|
174
|
+
const already = isAncestor(repository, sha, "HEAD");
|
|
119
175
|
if (already) {
|
|
120
176
|
if (marker?.due !== true) return { updated: true };
|
|
121
177
|
if (lines.length === 0) {
|
|
@@ -131,10 +187,10 @@ export async function updateMainClone(
|
|
|
131
187
|
}
|
|
132
188
|
const merge = git(repository, ["merge", "--ff-only", sha]);
|
|
133
189
|
if (!merge.ok) {
|
|
134
|
-
if (lines.length > 0 && marker !== undefined) await marker.save(
|
|
190
|
+
if (lines.length > 0 && marker !== undefined) await marker.save(marker.due);
|
|
135
191
|
return {
|
|
136
192
|
updated: false,
|
|
137
|
-
note: `cannot fast-forward: ${
|
|
193
|
+
note: `cannot fast-forward: ${mergeReason(merge.err || merge.out) || "git merge failed"}`,
|
|
138
194
|
};
|
|
139
195
|
}
|
|
140
196
|
return prepareAndClear(repository, lines, run, marker);
|
|
@@ -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;
|
|
@@ -281,6 +310,8 @@ export interface ReviewRecord {
|
|
|
281
310
|
readonly model?: string | null;
|
|
282
311
|
/** Which round (first or rework) ran and which block each setting came from. */
|
|
283
312
|
readonly reviewSettings?: ReviewSettingsUsed | null;
|
|
313
|
+
/** The fix level in force when the round ran. */
|
|
314
|
+
readonly fixLevel?: string | null;
|
|
284
315
|
/** When an unavailable round may run again, in epoch milliseconds. */
|
|
285
316
|
readonly retryAt?: number | null;
|
|
286
317
|
/** Every run of this round, in order. */
|
|
@@ -362,6 +393,12 @@ export type TaskAttempt = {
|
|
|
362
393
|
readonly worktree?: string | null;
|
|
363
394
|
readonly branch?: string | null;
|
|
364
395
|
readonly base?: string | null;
|
|
396
|
+
/**
|
|
397
|
+
* The text of `.operad/dev.json` as the attempt's first step read it (empty
|
|
398
|
+
* when the file did not exist). The attempt's steps use it and do not read
|
|
399
|
+
* the file again (ADR 0039 D6).
|
|
400
|
+
*/
|
|
401
|
+
readonly settingsText?: string;
|
|
365
402
|
readonly sessionId?: string | null;
|
|
366
403
|
/** The cost in dollars, when the harness reported one. */
|
|
367
404
|
readonly cost?: number | null;
|
|
@@ -380,6 +417,8 @@ export type TaskAttempt = {
|
|
|
380
417
|
readonly workerChanged?: string | null;
|
|
381
418
|
/** Whether the work step consumed this attempt; a later worktree visit is new work. */
|
|
382
419
|
readonly worked?: boolean;
|
|
420
|
+
/** Whether the work reported done; false when it failed, waited or never ran to its end. */
|
|
421
|
+
readonly workDone?: boolean;
|
|
383
422
|
/** The file the worker's own log was written to. */
|
|
384
423
|
readonly workLog?: string | null;
|
|
385
424
|
/** The worker's last message of this attempt's work, in full, as the harness reported it. */
|
|
@@ -413,6 +452,9 @@ export type TaskAttempt = {
|
|
|
413
452
|
readonly integrating?: string | null;
|
|
414
453
|
/** While the work step waits for its named worker: what it waits for and who holds it. */
|
|
415
454
|
readonly workerWait?: string | null;
|
|
455
|
+
/** While the work runs: the worker the pool placed and its harness step, for the log. */
|
|
456
|
+
readonly workerRunning?: string | null;
|
|
457
|
+
readonly workerUse?: string | null;
|
|
416
458
|
/** While a step waits for a check place: the place group, since when, and how many wait ahead. */
|
|
417
459
|
readonly placeWait?: { readonly key: string; readonly since: number; readonly ahead: number } | null;
|
|
418
460
|
/** While the integrate step waits for its turn: who is integrating. */
|
|
@@ -648,6 +690,17 @@ export function validateSlug(slug: unknown): string {
|
|
|
648
690
|
return slug;
|
|
649
691
|
}
|
|
650
692
|
|
|
693
|
+
/** The slug an action takes from a title when it is given none. */
|
|
694
|
+
export function slugFromTitle(title: unknown, fallback: string): string {
|
|
695
|
+
const text = typeof title === "string" ? title : "";
|
|
696
|
+
const words = text
|
|
697
|
+
.toLowerCase()
|
|
698
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
699
|
+
.replace(/^-+|-+$/g, "");
|
|
700
|
+
const slug = words.slice(0, 48).replace(/-+$/g, "");
|
|
701
|
+
return slug.length === 0 ? fallback : slug;
|
|
702
|
+
}
|
|
703
|
+
|
|
651
704
|
export function validateTitle(title: unknown): string {
|
|
652
705
|
if (typeof title !== "string" || title.trim().length === 0) {
|
|
653
706
|
throw new DevError("title", "must be a non-empty string");
|
|
@@ -707,7 +760,7 @@ function numberById(
|
|
|
707
760
|
let highest = 0;
|
|
708
761
|
for (const object of objects) {
|
|
709
762
|
// The store key carries the repository; the number lives in the bare id.
|
|
710
|
-
const parsed = parseId(
|
|
763
|
+
const parsed = parseId(idOfKey(object.id), kind);
|
|
711
764
|
if (parsed !== undefined && parsed.number > highest) {
|
|
712
765
|
highest = parsed.number;
|
|
713
766
|
}
|
|
@@ -725,7 +778,7 @@ export function storeKey(repository: string, id: string): string {
|
|
|
725
778
|
}
|
|
726
779
|
|
|
727
780
|
/** The id a person sees and types: the key without its repository prefix. */
|
|
728
|
-
export function
|
|
781
|
+
export function idOfKey(key: string): string {
|
|
729
782
|
const at = key.indexOf("/");
|
|
730
783
|
return at < 0 ? key : key.slice(at + 1);
|
|
731
784
|
}
|
|
@@ -741,7 +794,7 @@ export function dependencyKey(repository: string, entry: string): string {
|
|
|
741
794
|
|
|
742
795
|
/** How a dependency is named in a note: bare in its own repository. */
|
|
743
796
|
export function dependencyLabel(repository: string, key: string): string {
|
|
744
|
-
return keyRepository(key) === repository ?
|
|
797
|
+
return keyRepository(key) === repository ? idOfKey(key) : key;
|
|
745
798
|
}
|
|
746
799
|
|
|
747
800
|
/** The repository part of a store key. */
|
|
@@ -761,11 +814,7 @@ export async function nextId(
|
|
|
761
814
|
repository: string,
|
|
762
815
|
slug: string,
|
|
763
816
|
): Promise<string> {
|
|
764
|
-
const
|
|
765
|
-
const mine = all.filter(
|
|
766
|
-
(object) =>
|
|
767
|
-
isRecord(object.data) && object.data.repository === repository,
|
|
768
|
-
);
|
|
817
|
+
const mine = await listAll(store, type, { repository });
|
|
769
818
|
let number = numberById(mine, type) + 1;
|
|
770
819
|
for (;;) {
|
|
771
820
|
const id = formatId(type, number, slug);
|
|
@@ -1024,16 +1073,6 @@ export function briefBody(brief: string): string {
|
|
|
1024
1073
|
return splitBrief(brief).body;
|
|
1025
1074
|
}
|
|
1026
1075
|
|
|
1027
|
-
/** The Markdown of the rework sections, without the changes section. */
|
|
1028
|
-
export function reworkBody(brief: string): string {
|
|
1029
|
-
return splitBrief(brief).reworks;
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
/** The Markdown of the trailing changes section. */
|
|
1033
|
-
export function changesBody(brief: string): string {
|
|
1034
|
-
return splitBrief(brief).changes;
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
1076
|
/** Replaces the body and records the edit, unless the body did not change. */
|
|
1038
1077
|
export function editBrief(brief: string, body: string): string {
|
|
1039
1078
|
if (briefBody(brief) === body.replace(/\r\n/g, "\n").trimEnd()) return brief;
|
|
@@ -1139,23 +1178,10 @@ export function planNote(plan: PlanData): string {
|
|
|
1139
1178
|
return `${parts.join(" · ")} // ${plan.concurrency}`;
|
|
1140
1179
|
}
|
|
1141
1180
|
|
|
1142
|
-
export function planDataOf(data: Record<string, unknown>): PlanData {
|
|
1143
|
-
return planData(data);
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
|
-
export function taskDataOf(data: Record<string, unknown>): TaskData {
|
|
1147
|
-
return taskData(data);
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
1181
|
export function priorityIndex(priority: Priority): number {
|
|
1151
1182
|
return PRIORITIES.indexOf(priority);
|
|
1152
1183
|
}
|
|
1153
1184
|
|
|
1154
|
-
export function higherPriority(priority: Priority): Priority | undefined {
|
|
1155
|
-
const index = priorityIndex(priority);
|
|
1156
|
-
return index <= 0 ? undefined : PRIORITIES[index - 1];
|
|
1157
|
-
}
|
|
1158
|
-
|
|
1159
1185
|
/** A task is open until it merged or was cancelled. */
|
|
1160
1186
|
export function isOpenTask(task: TaskData): boolean {
|
|
1161
1187
|
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
|
};
|