toolroll 0.9.130 → 0.9.131
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/CHANGELOG.md +20 -0
- package/dist/agent-state.js +1 -1
- package/dist/browser/manifest.json +14 -14
- package/dist/browser/{terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js → terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js} +1 -1
- package/dist/browser/terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js.br +0 -0
- package/dist/browser/{terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js.gz → terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js.gz} +0 -0
- package/dist/browser/{workspace.9bd1db81d3c897045a5d82d4804e374e41e78b1b2cfd05d37b982a4ea0d02626.js → workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js} +1 -1
- package/dist/browser/workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js.br +0 -0
- package/dist/browser/workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js.gz +0 -0
- package/dist/builder-restart.js +13 -4
- package/dist/builder.js +4 -1
- package/dist/central-recovery-stage.js +2 -2
- package/dist/chat-follow.js +4 -0
- package/dist/db-tuning.js +16 -0
- package/dist/discord.js +9 -3
- package/dist/dispatch.js +32 -4
- package/dist/doctor.js +30 -0
- package/dist/evidence.js +49 -3
- package/dist/exec.js +3 -0
- package/dist/git-views.js +7 -1
- package/dist/invoke.js +12 -2
- package/dist/lead-queue-runtime.js +8 -5
- package/dist/lead-status.js +3 -3
- package/dist/loop-recovery.js +40 -0
- package/dist/maintenance.js +29 -1
- package/dist/needs-you.js +2 -0
- package/dist/operate.js +376 -52
- package/dist/planner.js +4 -1
- package/dist/query-index-schema.js +10 -0
- package/dist/read-executor-worker.js +9 -7
- package/dist/read-executor.js +18 -1
- package/dist/read-worker-connection.js +7 -0
- package/dist/release-adapters.js +51 -6
- package/dist/release-cli.js +24 -11
- package/dist/release-next.js +1 -1
- package/dist/release-stops.js +71 -0
- package/dist/release-supersede.js +125 -0
- package/dist/release-supervise.js +90 -0
- package/dist/release.js +252 -40
- package/dist/runner.js +36 -1
- package/dist/scout.js +4 -1
- package/dist/serve.js +92 -6
- package/dist/shutdown-proof.js +29 -0
- package/dist/slack.js +9 -3
- package/dist/sqlite-telemetry.js +26 -14
- package/dist/statement-cache.js +137 -0
- package/dist/store.js +70 -13
- package/dist/task-status.js +1 -1
- package/dist/teams.js +9 -3
- package/dist/teardown-git.js +10 -1
- package/dist/telegram.js +4 -1
- package/dist/up-processes.js +16 -1
- package/dist/up-role-child.js +2 -0
- package/dist/wake-hub.js +15 -6
- package/dist/work-index.js +101 -44
- package/dist/work-reads.js +53 -9
- package/dist/work-snapshots.js +185 -0
- package/dist/worker-statement-cache.js +83 -0
- package/dist/workspace-revision.js +145 -21
- package/package.json +1 -1
- package/dist/browser/terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js.br +0 -0
- package/dist/browser/workspace.9bd1db81d3c897045a5d82d4804e374e41e78b1b2cfd05d37b982a4ea0d02626.js.br +0 -0
- package/dist/browser/workspace.9bd1db81d3c897045a5d82d4804e374e41e78b1b2cfd05d37b982a4ea0d02626.js.gz +0 -0
package/dist/planner.js
CHANGED
|
@@ -10,6 +10,7 @@ import { join } from "node:path";
|
|
|
10
10
|
import { run } from "./exec.js";
|
|
11
11
|
import { checkoutGit } from "./teardown-git.js";
|
|
12
12
|
import { auditOf, isProviderId } from "./provider.js";
|
|
13
|
+
import { isDatabaseBusy } from "./store.js";
|
|
13
14
|
import { currentClaim, heartbeat } from "./claim.js";
|
|
14
15
|
import { heartbeat as runnerHeartbeat, RUNNER_HEARTBEAT_MS } from "./runner.js";
|
|
15
16
|
import { parseDecision } from "./decision.js";
|
|
@@ -499,7 +500,9 @@ export async function plan(store, request) {
|
|
|
499
500
|
if (!answer.ok)
|
|
500
501
|
fencedMidPlan = true;
|
|
501
502
|
}
|
|
502
|
-
catch {
|
|
503
|
+
catch (error) {
|
|
504
|
+
if (isDatabaseBusy(error))
|
|
505
|
+
return;
|
|
503
506
|
fencedMidPlan = true;
|
|
504
507
|
}
|
|
505
508
|
if (fencedMidPlan && pulseTimer !== undefined)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const V190_STEPS = Object.freeze(["query-indexes"]);
|
|
2
|
+
export const V190_INDEXES = Object.freeze([
|
|
3
|
+
["flow_trigger_event_task", "flow_trigger_event", "CREATE INDEX IF NOT EXISTS flow_trigger_event_task ON flow_trigger_event (task) WHERE task IS NOT NULL"],
|
|
4
|
+
["notification_delivery_unsettled", "notification_delivery", "CREATE INDEX IF NOT EXISTS notification_delivery_unsettled ON notification_delivery (destination, notification) WHERE delivered_at IS NULL"],
|
|
5
|
+
]);
|
|
6
|
+
export const V190_DROPPED_INDEXES = Object.freeze(["claim_by_task", "idx_direct_chat_ship_thread"]);
|
|
7
|
+
export const V190_SCHEMA = [
|
|
8
|
+
...V190_INDEXES.map(([, , ddl]) => `${ddl};`),
|
|
9
|
+
...V190_DROPPED_INDEXES.map(name => `DROP INDEX IF EXISTS ${name};`),
|
|
10
|
+
].join("\n");
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { parentPort, workerData } from 'node:worker_threads';
|
|
2
|
-
import {
|
|
2
|
+
import { openReadWorkerStore } from './read-worker-connection.js';
|
|
3
3
|
import { workCountsByProject, workIndexPage } from './work-index.js';
|
|
4
4
|
import { projectSummaryOf } from './console-chrome.js';
|
|
5
|
+
import { readSnapshot } from './work-snapshots.js';
|
|
6
|
+
import { proveReadOnly } from './read-executor.js';
|
|
7
|
+
import { cacheStatements } from './worker-statement-cache.js';
|
|
5
8
|
let store = null;
|
|
6
9
|
function connection() {
|
|
7
10
|
if (store !== null)
|
|
8
11
|
return store;
|
|
9
|
-
const opened =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
opened.handle.exec('PRAGMA query_only=1; PRAGMA temp_store=MEMORY; PRAGMA cache_size=-16000;');
|
|
13
|
-
return store = opened;
|
|
12
|
+
const opened = openReadWorkerStore(String(workerData.file));
|
|
13
|
+
proveReadOnly(opened.handle);
|
|
14
|
+
return store = Object.create(opened, { db: { value: cacheStatements(opened.handle) } });
|
|
14
15
|
}
|
|
15
16
|
parentPort.on('message', ({ id, job }) => {
|
|
16
17
|
let reply;
|
|
@@ -19,7 +20,8 @@ parentPort.on('message', ({ id, job }) => {
|
|
|
19
20
|
const value = job.kind === 'work-index-page' ? workIndexPage(connection(), now, job.access, job.options)
|
|
20
21
|
: job.kind === 'work-counts' ? workCountsByProject(connection(), now, job.access)
|
|
21
22
|
: job.kind === 'project-summary' ? projectSummaryOf(connection(), now, job.access, job.actor, job.projects, job.evidenceRoot ?? undefined)
|
|
22
|
-
:
|
|
23
|
+
: job.kind === 'snapshot' ? readSnapshot(connection(), job.job)
|
|
24
|
+
: (() => { throw new Error('Unknown read.'); })();
|
|
23
25
|
reply = { id, ok: true, value };
|
|
24
26
|
}
|
|
25
27
|
catch (error) {
|
package/dist/read-executor.js
CHANGED
|
@@ -27,6 +27,8 @@ function readCacheKey(job) {
|
|
|
27
27
|
if (job.kind === 'work-counts') {
|
|
28
28
|
return JSON.stringify(['wc', secondBucket, canonicalAccess(job.access)]);
|
|
29
29
|
}
|
|
30
|
+
if (job.kind === 'snapshot')
|
|
31
|
+
throw new Error('Snapshots are never cached by data version.');
|
|
30
32
|
return JSON.stringify(['ps', secondBucket, canonicalAccess(job.access), job.actor, job.projects, job.evidenceRoot]);
|
|
31
33
|
}
|
|
32
34
|
export class ReadExecutorError extends Error {
|
|
@@ -83,10 +85,13 @@ export class ReadExecutor {
|
|
|
83
85
|
async projectSummary(now, access, actor, projects, evidenceRoot) {
|
|
84
86
|
return await this.#run({ kind: 'project-summary', now: now.toISOString(), access, actor, projects: projects.map(one => ({ path: one.path, name: one.name })), evidenceRoot: evidenceRoot ?? null });
|
|
85
87
|
}
|
|
88
|
+
async snapshot(job) {
|
|
89
|
+
return await this.#run({ kind: 'snapshot', now: job.now, job });
|
|
90
|
+
}
|
|
86
91
|
#run(job) {
|
|
87
92
|
if (this.#closed)
|
|
88
93
|
return Promise.reject(new ReadExecutorError('The server is closing.'));
|
|
89
|
-
const version = this.#dataVersion();
|
|
94
|
+
const version = job.kind === 'snapshot' ? null : this.#dataVersion();
|
|
90
95
|
const key = version === null ? null : readCacheKey(job);
|
|
91
96
|
const nowMs = Date.now();
|
|
92
97
|
if (key !== null && version !== null) {
|
|
@@ -200,6 +205,18 @@ export class ReadExecutor {
|
|
|
200
205
|
export function defaultReadWorkers() {
|
|
201
206
|
return Math.max(1, Math.min(8, Math.floor(availableParallelism() / 2)));
|
|
202
207
|
}
|
|
208
|
+
export function proveReadOnly(db) {
|
|
209
|
+
try {
|
|
210
|
+
db.exec('UPDATE main.service_cursor SET key = key WHERE 0');
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
const code = error.errcode;
|
|
214
|
+
if (typeof code === 'number' && (code & 0xff) === SQLITE_READONLY)
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
throw new ReadExecutorError('The read worker\'s connection is not proved read-only; it must be.');
|
|
218
|
+
}
|
|
219
|
+
const SQLITE_READONLY = 8;
|
|
203
220
|
const attached = new WeakMap();
|
|
204
221
|
export function attachReadExecutor(store, executor) {
|
|
205
222
|
attached.set(store, executor);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { openStoreReadOnly } from './store.js';
|
|
2
|
+
export function openReadWorkerStore(file) {
|
|
3
|
+
const opened = openStoreReadOnly(file);
|
|
4
|
+
if (opened === null)
|
|
5
|
+
throw new Error('The read worker could not open the database read-only at the current schema.');
|
|
6
|
+
return opened;
|
|
7
|
+
}
|
package/dist/release-adapters.js
CHANGED
|
@@ -36,7 +36,10 @@ import { noteReleaseReady, noteReleaseStopped, recordReleaseCi } from "./release
|
|
|
36
36
|
import { recordVerifiedRelease } from "./release-card.js";
|
|
37
37
|
export { failedBeforeTests } from "./github-jobs.js";
|
|
38
38
|
import { extractCommit } from "./commit-extract.js";
|
|
39
|
-
import { teardownGit, refusal as gitRefusal } from "./teardown-git.js";
|
|
39
|
+
import { checkoutBusy, teardownGit, refusal as gitRefusal } from "./teardown-git.js";
|
|
40
|
+
import { CheckoutBusy } from "./git-views.js";
|
|
41
|
+
import { NotYetPublished } from "./release-stops.js";
|
|
42
|
+
import { supersedeReleaseTask } from "./release-supersede.js";
|
|
40
43
|
import { RELEASE_REMOTE, releaseConfigProblem, releaseGitArgs, releaseGitEnv, releaseRemote, releaseTools } from "./release-git.js";
|
|
41
44
|
import { ciEnv, exec, githubReads } from "./github-read.js";
|
|
42
45
|
export { exec, githubReads } from "./github-read.js";
|
|
@@ -270,6 +273,8 @@ export function releaseAdapters(options) {
|
|
|
270
273
|
return { ...result, timedOut: result.code === 124, notFound: result.code === 127 };
|
|
271
274
|
}, { repo: repo.checkout }, Math.max(0, left()), tools.git);
|
|
272
275
|
const result = await viewed(repo.checkout, full.slice(2));
|
|
276
|
+
if (checkoutBusy(result))
|
|
277
|
+
throw new CheckoutBusy();
|
|
273
278
|
const why = gitRefusal(result);
|
|
274
279
|
if (why !== null)
|
|
275
280
|
throw stop(why);
|
|
@@ -592,6 +597,7 @@ export function releaseAdapters(options) {
|
|
|
592
597
|
async mainHead(repo) { return readMainHead(reads, ciGh, repo); },
|
|
593
598
|
async contains(repo, sha, ancestor) { return readContains(reads, ciGh, repo, sha, ancestor); },
|
|
594
599
|
async updateBranch(repo, pr, expectedHead) { return updatePullRequestBranch(reads, ciGh, repo, pr, expectedHead); },
|
|
600
|
+
async rerun(repo, id) { return rerunWorkflowRun(run, ciGh, repo, id); },
|
|
595
601
|
async upToDateRequired(repo) { return readMainProtection(reads, ciGh, repo); },
|
|
596
602
|
async merge(repo, pr, head, message) {
|
|
597
603
|
return writeWithRecheck(`merging #${pr}`, { ...net, maxAttempts: 1 }, {
|
|
@@ -608,7 +614,7 @@ export function releaseAdapters(options) {
|
|
|
608
614
|
},
|
|
609
615
|
async tag(repo, tag) { return readTag(repo, tag); },
|
|
610
616
|
async createTag(repo, tag, sha) {
|
|
611
|
-
await writeWithRecheck(`creating ${tag}`, net, {
|
|
617
|
+
await writeWithRecheck(`creating ${tag}`, { ...net, maxAttempts: 1 }, {
|
|
612
618
|
write: remaining => ghWrite(remaining, "api", "-X", "POST", `repos/${repo}/git/refs`, "-f", `ref=refs/tags/${tag}`, "-f", `sha=${sha}`),
|
|
613
619
|
accept: () => undefined,
|
|
614
620
|
refuse: result => { throw failed(result, `creating ${tag}`); },
|
|
@@ -678,6 +684,8 @@ export function releaseAdapters(options) {
|
|
|
678
684
|
async propose(version) {
|
|
679
685
|
const tarball = `https://registry.npmjs.org/toolroll/-/toolroll-${version}.tgz`;
|
|
680
686
|
const response = await get(tarball, { signal: AbortSignal.timeout(60_000) });
|
|
687
|
+
if (response.status === 404)
|
|
688
|
+
throw new NotYetPublished(`npm doesn't serve ${tarball} yet`);
|
|
681
689
|
if (!response.ok)
|
|
682
690
|
throw new Error(`downloading ${tarball} answered ${response.status}`);
|
|
683
691
|
const sha256 = createHash("sha256").update(Buffer.from(await response.arrayBuffer())).digest("hex");
|
|
@@ -955,9 +963,10 @@ export function storeReleaseAdapter(open, done, now, runner, auto, nightlyReads)
|
|
|
955
963
|
async start(operation, epoch) { return withStore(store => runReleaseOperation(store, operation, epoch, now())); },
|
|
956
964
|
async finish(operation, outcome, facts, epoch) { return withStore(store => finishReleaseOperation(store, operation, outcome, facts, now(), epoch)); },
|
|
957
965
|
async needsApproval(authority, reason, epoch) { return withStore(store => requireFreshReleaseApproval(store, authority, reason, epoch, now())); },
|
|
966
|
+
async supersede(input) { return withStore(store => supersedeReleaseTask(store, input, now())); },
|
|
958
967
|
async operations(authority) {
|
|
959
968
|
return withStore(store => releaseOperations(store, authority).map(op => ({ id: op.id, kind: op.kind, state: op.state, candidate: op.candidate, externalRef: op.externalRef, reservedAt: op.reservedAt,
|
|
960
|
-
direct: op.direct, issuerGone: releaseIssuerGone(op), stage: op.stage })));
|
|
969
|
+
direct: op.direct, issuerGone: releaseIssuerGone(op), issuedHere: op.issuer !== null && op.issuer.pid === process.pid && !releaseIssuerGone(op), stage: op.stage })));
|
|
961
970
|
},
|
|
962
971
|
};
|
|
963
972
|
}
|
|
@@ -1059,7 +1068,7 @@ export async function readCheckRuns(run, gh, repo, sha, options = {}) {
|
|
|
1059
1068
|
const out = await must(run(gh, ["api", "--hostname", "github.com", "--paginate", `repos/${repo}/commits/${sha}/check-runs?filter=all&per_page=100`,
|
|
1060
1069
|
"--jq", ".check_runs[] | {id, name, status, conclusion, app: .app.slug, suite: .check_suite.id, head: .head_sha}"], { cwd: "/", env: ciEnv() }), "gh api check-runs");
|
|
1061
1070
|
const flows = await must(run(gh, ["api", "--hostname", "github.com", "--paginate", `repos/${repo}/actions/runs?head_sha=${sha}&per_page=100`,
|
|
1062
|
-
"--jq", ".workflow_runs[] | {suite: .check_suite_id, workflow: .workflow_id, path: .path, head: .head_sha, event: .event, branch: .head_branch, bases: [(.pull_requests // [])[] | .base.ref], prs: [(.pull_requests // [])[] | {number, repo: .base.repo.url}]}"], { cwd: "/", env: ciEnv() }), "gh api actions/runs");
|
|
1071
|
+
"--jq", ".workflow_runs[] | {run: .id, suite: .check_suite_id, workflow: .workflow_id, path: .path, head: .head_sha, event: .event, branch: .head_branch, repo: .repository.full_name, headRepo: .head_repository.full_name, bases: [(.pull_requests // [])[] | .base.ref], prs: [(.pull_requests // [])[] | {number, repo: .base.repo.url}]}"], { cwd: "/", env: ciEnv() }), "gh api actions/runs");
|
|
1063
1072
|
const retargeted = new Map();
|
|
1064
1073
|
const RETARGET_EVENTS = new Set(["base_ref_changed", "automatic_base_change_succeeded", "automatic_base_change_failed"]);
|
|
1065
1074
|
const everRetargeted = async (pr) => {
|
|
@@ -1077,7 +1086,32 @@ export async function readCheckRuns(run, gh, repo, sha, options = {}) {
|
|
|
1077
1086
|
retargeted.set(pr, changed);
|
|
1078
1087
|
return changed;
|
|
1079
1088
|
};
|
|
1089
|
+
const onlyPull = new Map();
|
|
1090
|
+
const onlyPullFrom = async (branch) => {
|
|
1091
|
+
const known = onlyPull.get(branch);
|
|
1092
|
+
if (known !== undefined)
|
|
1093
|
+
return known;
|
|
1094
|
+
let bound = false;
|
|
1095
|
+
try {
|
|
1096
|
+
if (/^[A-Za-z0-9._/-]+$/.test(branch) && !branch.includes("..")) {
|
|
1097
|
+
const owner = repo.split("/")[0];
|
|
1098
|
+
const listed = await run(gh, ["api", "--hostname", "github.com", "--paginate", `repos/${repo}/pulls?state=all&head=${encodeURIComponent(`${owner}:${branch}`)}&per_page=100`,
|
|
1099
|
+
"--jq", ".[] | {number, state, merged: (.merged_at != null), base: .base.ref, baseRepo: .base.repo.full_name, head: .head.ref, headRepo: .head.repo.full_name, headSha: .head.sha}"], { cwd: "/", env: ciEnv() });
|
|
1100
|
+
const pulls = listed.code !== 0 ? null : listed.stdout.split("\n").filter(Boolean).map(line => object(JSON.parse(line)));
|
|
1101
|
+
const only = pulls !== null && pulls.length === 1 ? pulls[0] : null;
|
|
1102
|
+
bound = only !== null && Number.isSafeInteger(only["number"]) && only["state"] === "closed" && only["merged"] === true
|
|
1103
|
+
&& only["base"] === "main" && only["baseRepo"] === repo && only["head"] === branch && only["headRepo"] === repo && only["headSha"] === sha
|
|
1104
|
+
&& !await everRetargeted(Number(only["number"]));
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
catch {
|
|
1108
|
+
bound = false;
|
|
1109
|
+
}
|
|
1110
|
+
onlyPull.set(branch, bound);
|
|
1111
|
+
return bound;
|
|
1112
|
+
};
|
|
1080
1113
|
const workflowOf = new Map();
|
|
1114
|
+
const runOf = new Map();
|
|
1081
1115
|
const pathOf = new Map();
|
|
1082
1116
|
for (const line of flows.split("\n").filter(Boolean)) {
|
|
1083
1117
|
const one = object(JSON.parse(line));
|
|
@@ -1087,10 +1121,14 @@ export async function readCheckRuns(run, gh, repo, sha, options = {}) {
|
|
|
1087
1121
|
if (known !== undefined && (known !== Number(one["workflow"]) || pathOf.get(Number(one["suite"])) !== one["path"]))
|
|
1088
1122
|
throw new Error("GitHub named two workflows for one check suite");
|
|
1089
1123
|
workflowOf.set(Number(one["suite"]), Number(one["workflow"]));
|
|
1124
|
+
if (Number.isSafeInteger(one["run"]) && Number(one["run"]) > 0)
|
|
1125
|
+
runOf.set(Number(one["suite"]), Number(one["run"]));
|
|
1090
1126
|
const prs = (Array.isArray(one["prs"]) ? one["prs"] : []).map(pr => (pr !== null && typeof pr === "object" ? pr : {}));
|
|
1091
1127
|
const ours = prs.length > 0 && prs.every(pr => Number.isSafeInteger(pr["number"]) && pr["repo"] === `https://api.github.com/repos/${repo}`);
|
|
1092
1128
|
const untouched = one["event"] !== "pull_request" || (ours && !(await Promise.all(prs.map(pr => everRetargeted(Number(pr["number"]))))).some(Boolean));
|
|
1093
|
-
|
|
1129
|
+
const emptied = options.tag === undefined && one["event"] === "pull_request" && prs.length === 0 && one["repo"] === repo && one["headRepo"] === repo
|
|
1130
|
+
&& typeof one["branch"] === "string" && await onlyPullFrom(one["branch"]);
|
|
1131
|
+
if (((options.tag === undefined ? mainTriggered(one) : tagTriggered(one, options.tag)) && untouched) || emptied)
|
|
1094
1132
|
pathOf.set(Number(one["suite"]), String(one["path"]));
|
|
1095
1133
|
}
|
|
1096
1134
|
const runs = out.split("\n").filter(Boolean).map(line => {
|
|
@@ -1099,7 +1137,8 @@ export async function readCheckRuns(run, gh, repo, sha, options = {}) {
|
|
|
1099
1137
|
throw new Error("GitHub answered a check run this can't read");
|
|
1100
1138
|
const suite = Number.isSafeInteger(one["suite"]) ? Number(one["suite"]) : null;
|
|
1101
1139
|
return { id: Number(one["id"]), name: one["name"], status: one["status"], conclusion: textOr(one["conclusion"]), app: textOr(one["app"]),
|
|
1102
|
-
suite, head: textOr(one["head"]), workflow: suite === null ? null : workflowOf.get(suite) ?? null, workflowPath: suite === null ? null : pathOf.get(suite) ?? null
|
|
1140
|
+
suite, head: textOr(one["head"]), workflow: suite === null ? null : workflowOf.get(suite) ?? null, workflowPath: suite === null ? null : pathOf.get(suite) ?? null,
|
|
1141
|
+
...(suite !== null && runOf.has(suite) ? { workflowRun: runOf.get(suite) } : {}) };
|
|
1103
1142
|
});
|
|
1104
1143
|
if (new Set(runs.map(one => one.id)).size !== runs.length)
|
|
1105
1144
|
throw new Error("GitHub answered the same check run twice");
|
|
@@ -1553,3 +1592,9 @@ export async function readMainVersion(run, gh, repo) {
|
|
|
1553
1592
|
return null;
|
|
1554
1593
|
}
|
|
1555
1594
|
}
|
|
1595
|
+
export async function rerunWorkflowRun(run, gh, repo, id) {
|
|
1596
|
+
if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repo) || !Number.isSafeInteger(id) || id < 1)
|
|
1597
|
+
return { ok: false, why: "not a workflow run GitHub can be asked to run again" };
|
|
1598
|
+
const ran = await run(gh, ["api", "--hostname", "github.com", "--method", "POST", `repos/${repo}/actions/runs/${id}/rerun`], { cwd: "/", env: ciEnv() });
|
|
1599
|
+
return ran.code === 0 ? { ok: true } : { ok: false, why: (ran.stderr.trim().split("\n")[0] ?? "").slice(0, 200) || `gh exited ${ran.code}` };
|
|
1600
|
+
}
|
package/dist/release-cli.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
4
|
import { homedir } from "node:os";
|
|
4
5
|
import { dirname, join, resolve } from "node:path";
|
|
5
6
|
import { createRequire } from "node:module";
|
|
6
7
|
const sqlite = () => createRequire(import.meta.url)("node:sqlite");
|
|
7
8
|
import { checkedEnvelopeJson } from "./contracts/cli.js";
|
|
8
|
-
import { RELEASE_LIMITS, RELEASE_STEPS, runRelease } from "./release.js";
|
|
9
|
+
import { readJournal, RELEASE_LIMITS, RELEASE_STEPS, runRelease, writeJournal } from "./release.js";
|
|
10
|
+
import { superviseRelease } from "./release-supervise.js";
|
|
9
11
|
import { exec, prepareRelease, processes, readMainVersion, recordedReleaseRepo, releaseAdapters, releaseTools } from "./release-adapters.js";
|
|
10
12
|
import { mainRunKey, releaseBranchFor } from "./release-main.js";
|
|
11
13
|
import { journals, releaseGate } from "./release-gate.js";
|
|
12
14
|
import { rescueDeployment } from "./deploy-rescue.js";
|
|
13
|
-
import { settleDeployment, takeReleaseRun } from "./release-next.js";
|
|
15
|
+
import { RELEASE_WAIT_MS, settleDeployment, takeReleaseRun } from "./release-next.js";
|
|
14
16
|
import { databasePath, elapsedSeconds, latestReleaseStepTask, openStore, readSchemaVersion, releaseProgressFor, revokeRelease, SCHEMA_VERSION } from "./store.js";
|
|
15
17
|
import { dur, plural } from "./design/kit.js";
|
|
16
18
|
import { carryRefusalWords, proveCarry, setAskEveryReleaseCommit, setUnsandboxedCarry } from "./release-carry.js";
|
|
@@ -47,10 +49,15 @@ toolroll release <branch> — the earlier way: release from a pushed branch with
|
|
|
47
49
|
squash-merges, deletes the matching remote branch, verifies the merged tree and tags. Both macOS legs gate npm
|
|
48
50
|
publication; Homebrew waits for its checks to register and all pass before merging.
|
|
49
51
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
to
|
|
52
|
+
A stop that clears on its own (GitHub not answering, Toolroll's own git busy on the checkout, CI, npm or Homebrew
|
|
53
|
+
catching up, an earlier operation's process ending) doesn't end the release: it goes on by itself from its journal,
|
|
54
|
+
within a budget the journal keeps. A failed CI job whose runner failed before the tests is run again once; any other red check waits for
|
|
55
|
+
you to rerun it or push a fix. Run the same command to go on after any other stop. It reads where the release got to
|
|
56
|
+
and does the one thing that's next: finishes a deployment forward, puts one back, lifts a pause left before a swap,
|
|
57
|
+
follows another run of the release (naming its computer and process), or waits for your approval. It says what it
|
|
58
|
+
did. A branch behind main is brought up to date for you; that new commit needs its own approval, CI and check.
|
|
59
|
+
--new starts over for a new commit and sets the earlier release's task aside (stopped, put away, its approval
|
|
60
|
+
withdrawn), refused once it began merging.
|
|
54
61
|
|
|
55
62
|
A branch whose name is one of this command's own words (approve, status, nightly, carry…) is named with --branch <name>
|
|
56
63
|
or after --: \`toolroll release --branch status\`.
|
|
@@ -290,7 +297,7 @@ export async function runReleaseCommand(args, write, deps = {}) {
|
|
|
290
297
|
const lockKey = version === undefined ? branch : mainRunKey(version);
|
|
291
298
|
const taken = await takeReleaseRun(stateDir, lockKey, say, deps.runLock);
|
|
292
299
|
if (!taken.ok)
|
|
293
|
-
return refuse("running", `
|
|
300
|
+
return refuse("running", `The release of ${version ?? branch} is being run by ${taken.holder.host} (process ${taken.holder.pid}), which goes on by itself; this command followed it for ${Math.max(1, Math.round((deps.runLock?.waitMs ?? RELEASE_WAIT_MS) / 60_000))} min and changed nothing. \`toolroll release status\` shows where it is.`, 3);
|
|
294
301
|
let next = null;
|
|
295
302
|
try {
|
|
296
303
|
const world = deps.settle ?? (deps.adapters === undefined ? { rescue: installedRescueWorld(checkout), gate: installedGateWorld() } : null);
|
|
@@ -299,10 +306,16 @@ export async function runReleaseCommand(args, write, deps = {}) {
|
|
|
299
306
|
if (!settled.ok)
|
|
300
307
|
return refuse("deployment", settled.message, 3);
|
|
301
308
|
}
|
|
302
|
-
const
|
|
303
|
-
...(version === undefined ? {} : { version, full: bare.has("--full") }) }
|
|
304
|
-
|
|
305
|
-
|
|
309
|
+
const base = { branch: version === undefined ? branch : releaseBranchFor(version), checkout, stateDir, limits, noCarry: bare.has("--no-carry"), leaseOwner: randomUUID(),
|
|
310
|
+
...(version === undefined ? {} : { version, full: bare.has("--full") }) };
|
|
311
|
+
const outcome = await superviseRelease(await runRelease({ ...base, fresh: bare.has("--new") }, adapters), {
|
|
312
|
+
again: () => runRelease(base, adapters), now: () => adapters.now(), sleep: ms => adapters.sleep(ms), say, read: readJournal, write: writeJournal,
|
|
313
|
+
handOver: done => {
|
|
314
|
+
if (deps.adapters === undefined)
|
|
315
|
+
next = deployedBuildToContinue(done, deps.database ?? databasePath(process.env, homedir()));
|
|
316
|
+
return next !== null;
|
|
317
|
+
},
|
|
318
|
+
});
|
|
306
319
|
if (next === null)
|
|
307
320
|
return report(outcome, write, json, lines);
|
|
308
321
|
}
|
package/dist/release-next.js
CHANGED
|
@@ -57,7 +57,7 @@ export async function takeReleaseRun(stateDir, branch, say, seams = {}) {
|
|
|
57
57
|
continue;
|
|
58
58
|
}
|
|
59
59
|
if (!said) {
|
|
60
|
-
say(`
|
|
60
|
+
say(`Following: the release of ${branch} is already being run by ${holder.host} (process ${holder.pid}), which goes on by itself; this command waits for it to finish (up to ${Math.max(1, Math.round((seams.waitMs ?? RELEASE_WAIT_MS) / 60_000))} min).`);
|
|
61
61
|
said = true;
|
|
62
62
|
}
|
|
63
63
|
if (now() >= deadline)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export const TIMEOUT_POLICY = {
|
|
2
|
+
gate: "auto-wait",
|
|
3
|
+
approval: "person",
|
|
4
|
+
check: "person",
|
|
5
|
+
quiet: "auto-wait",
|
|
6
|
+
deploy: "person",
|
|
7
|
+
ci: "auto-wait",
|
|
8
|
+
publish: "auto-wait",
|
|
9
|
+
homebrew: "auto-wait",
|
|
10
|
+
};
|
|
11
|
+
export const STOP_POLICY = {
|
|
12
|
+
"network": "auto-resume",
|
|
13
|
+
"checkout-busy": "auto-resume",
|
|
14
|
+
"github-unreadable": "auto-resume",
|
|
15
|
+
"operation-in-flight": "auto-wait",
|
|
16
|
+
"ci-missing": "auto-wait",
|
|
17
|
+
"deploy-busy": "auto-wait",
|
|
18
|
+
"superseding": "auto-wait",
|
|
19
|
+
"timeout": "by-limit",
|
|
20
|
+
"approval": "person",
|
|
21
|
+
"base": "person",
|
|
22
|
+
"base-moved": "person",
|
|
23
|
+
"base-unprotected": "person",
|
|
24
|
+
"changelog": "person",
|
|
25
|
+
"check-failed": "person",
|
|
26
|
+
"check-level": "person",
|
|
27
|
+
"checkout": "person",
|
|
28
|
+
"ci-failed": "person",
|
|
29
|
+
"complete": "person",
|
|
30
|
+
"conflict": "person",
|
|
31
|
+
"deploy": "person",
|
|
32
|
+
"deploy-recovery": "person",
|
|
33
|
+
"drift": "person",
|
|
34
|
+
"error": "person",
|
|
35
|
+
"gate-held": "person",
|
|
36
|
+
"github-auth": "person",
|
|
37
|
+
"lease": "person",
|
|
38
|
+
"link": "person",
|
|
39
|
+
"merge-unknown": "person",
|
|
40
|
+
"merging": "person",
|
|
41
|
+
"mixed-runtime": "person",
|
|
42
|
+
"nightly-debt": "person",
|
|
43
|
+
"no-branch": "person",
|
|
44
|
+
"no-pull-request": "person",
|
|
45
|
+
"no-release-commit": "person",
|
|
46
|
+
"not-merged": "person",
|
|
47
|
+
"proof": "person",
|
|
48
|
+
"publish-failed": "person",
|
|
49
|
+
"release": "person",
|
|
50
|
+
"scope-changed": "person",
|
|
51
|
+
"tagging": "person",
|
|
52
|
+
"tree-mismatch": "person",
|
|
53
|
+
"usage": "person",
|
|
54
|
+
"version": "person",
|
|
55
|
+
"worktree": "person",
|
|
56
|
+
"write-unknown": "person",
|
|
57
|
+
};
|
|
58
|
+
export function stopPolicy(reason, waited = null) {
|
|
59
|
+
if (!Object.hasOwn(STOP_POLICY, reason))
|
|
60
|
+
return "person";
|
|
61
|
+
const policy = STOP_POLICY[reason];
|
|
62
|
+
if (policy !== "by-limit")
|
|
63
|
+
return policy;
|
|
64
|
+
return waited === null ? "person" : TIMEOUT_POLICY[waited];
|
|
65
|
+
}
|
|
66
|
+
export class NotYetPublished extends Error {
|
|
67
|
+
constructor(message) {
|
|
68
|
+
super(message);
|
|
69
|
+
this.name = "NotYetPublished";
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { requestTaskStop, taskControlOf } from "./task-control.js";
|
|
2
|
+
import { archiveTaskFamily, LIVE_RELEASE_STATES, outstandingReleaseOperations, releaseAuthority, releaseAuthorityOfTask, revokeRelease, withdrawApproval } from "./store.js";
|
|
3
|
+
const SUPERSEDED = "superseded by a newer release (toolroll release --new)";
|
|
4
|
+
class Refusal extends Error {
|
|
5
|
+
answer;
|
|
6
|
+
constructor(answer) {
|
|
7
|
+
super(answer.why);
|
|
8
|
+
this.answer = answer;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function supersedeReleaseTask(store, input, now) {
|
|
12
|
+
const ref = store.lookupRef(input.taskId);
|
|
13
|
+
if (ref === null || store.getTask(input.taskId) === null)
|
|
14
|
+
return { state: "done", steps: [] };
|
|
15
|
+
const unbound = () => {
|
|
16
|
+
const now = store.lookupRef(input.taskId);
|
|
17
|
+
if (now === null || now.id !== ref.id)
|
|
18
|
+
return { state: "refused", why: `task ${input.taskId} is no longer the one this release recorded`, merging: false };
|
|
19
|
+
const current = releaseAuthorityOfTask(store, input.taskId)?.authority ?? null;
|
|
20
|
+
const recorded = input.authority === null ? null : releaseAuthority(store, input.authority.id);
|
|
21
|
+
for (const one of [current, recorded]) {
|
|
22
|
+
if (one !== null && (one.state === "merge-reserved" || one.state === "merged"))
|
|
23
|
+
return { state: "refused", why: `release ${one.id} already began merging`, merging: true };
|
|
24
|
+
}
|
|
25
|
+
if ((store.getScope(input.taskId)?.digest ?? null) !== input.scopeDigest)
|
|
26
|
+
return { state: "refused", why: `task ${input.taskId}'s scope changed since this release recorded it`, merging: false };
|
|
27
|
+
if ((current?.id ?? null) !== (input.authority?.id ?? null) || (current !== null && current.generation !== input.authority.generation)) {
|
|
28
|
+
return { state: "refused", why: `task ${input.taskId}'s release is no longer the one this release recorded`, merging: false };
|
|
29
|
+
}
|
|
30
|
+
const open = current === null ? [] : outstandingReleaseOperations(store, current.id);
|
|
31
|
+
if (open.length > 0)
|
|
32
|
+
return { state: "refused", why: `release ${current.id} still has a ${open[0].kind} in flight (operation ${open[0].id})`, merging: open.some(one => one.kind === "merge") };
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
const guarded = (write) => {
|
|
36
|
+
try {
|
|
37
|
+
return store.transact(() => {
|
|
38
|
+
const refused = unbound();
|
|
39
|
+
if (refused !== null)
|
|
40
|
+
throw new Refusal(refused);
|
|
41
|
+
return write();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error instanceof Refusal)
|
|
46
|
+
return error.answer;
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const refusedNow = (value) => typeof value === "object" && value !== null && value.state === "refused";
|
|
51
|
+
const steps = [];
|
|
52
|
+
const held = guarded(() => {
|
|
53
|
+
if (store.handle.prepare("SELECT 1 FROM hold WHERE owner_kind = 'operator' AND owner_id = ?").get(String(ref.id)) !== undefined)
|
|
54
|
+
return false;
|
|
55
|
+
store.hold(ref.id, SUPERSEDED, null, now);
|
|
56
|
+
return true;
|
|
57
|
+
});
|
|
58
|
+
if (refusedNow(held))
|
|
59
|
+
return held;
|
|
60
|
+
if (held)
|
|
61
|
+
steps.push("held");
|
|
62
|
+
const control = taskControlOf(store, ref.id, now);
|
|
63
|
+
if (control.kind === "stop") {
|
|
64
|
+
let signal = null;
|
|
65
|
+
const asked = guarded(() => requestTaskStop(store, { taskId: input.taskId, runId: control.run, by: input.by, via: "cli", deferSignal: run => { signal = run; } }, now));
|
|
66
|
+
if (refusedNow(asked))
|
|
67
|
+
return asked;
|
|
68
|
+
signal?.();
|
|
69
|
+
if (!asked.ok && asked.reason !== "finished")
|
|
70
|
+
return asked.reason === "publication" ? { state: "refused", why: asked.detail, merging: false } : { state: "stopping", steps, why: asked.detail };
|
|
71
|
+
if (asked.ok && !asked.repeated)
|
|
72
|
+
steps.push("stop-requested");
|
|
73
|
+
return { state: "stopping", steps, why: `build #${control.run} of ${input.taskId} is stopping` };
|
|
74
|
+
}
|
|
75
|
+
if (control.kind === "stopping")
|
|
76
|
+
return { state: "stopping", steps, why: control.detail ?? `build #${control.run} of ${input.taskId} is still stopping` };
|
|
77
|
+
if (store.hasLiveClaim(ref.id, now))
|
|
78
|
+
return { state: "stopping", steps, why: `${input.taskId} still holds a claim` };
|
|
79
|
+
class Again extends Error {
|
|
80
|
+
why;
|
|
81
|
+
constructor(why) {
|
|
82
|
+
super(why);
|
|
83
|
+
this.why = why;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const done = guarded(() => {
|
|
88
|
+
const made = [];
|
|
89
|
+
const cancelled = store.cancelTask(input.taskId, now, SUPERSEDED);
|
|
90
|
+
if (!cancelled.ok && cancelled.reason === "claimed")
|
|
91
|
+
throw new Again(`${input.taskId} was claimed again`);
|
|
92
|
+
if (cancelled.ok)
|
|
93
|
+
made.push("cancelled");
|
|
94
|
+
else if (cancelled.reason !== "already-terminal")
|
|
95
|
+
throw new Refusal({ state: "refused", why: `${input.taskId} couldn't be cancelled (${cancelled.reason})`, merging: false });
|
|
96
|
+
if (withdrawApproval(store, { where: "WHERE task_id = ? AND approved_at IS NOT NULL", args: [input.taskId] }, { basisAfter: null, clearRoute: false, clearModeDigest: false }) > 0)
|
|
97
|
+
made.push("approval-withdrawn");
|
|
98
|
+
const authority = input.authority === null ? null : releaseAuthority(store, input.authority.id);
|
|
99
|
+
if (authority !== null && LIVE_RELEASE_STATES.includes(authority.state)) {
|
|
100
|
+
const revoked = revokeRelease(store, authority.id, input.by, now);
|
|
101
|
+
if (!revoked.ok)
|
|
102
|
+
throw new Refusal({ state: "refused", why: revoked.why, merging: false });
|
|
103
|
+
made.push("authority-revoked");
|
|
104
|
+
}
|
|
105
|
+
const put = archiveTaskFamily(store, input.taskId, { by: input.by, byKind: "person", rule: null, reason: SUPERSEDED }, now);
|
|
106
|
+
if (put.ok)
|
|
107
|
+
made.push("archived");
|
|
108
|
+
else if (put.reason === "live")
|
|
109
|
+
throw new Again(put.message);
|
|
110
|
+
else if (put.reason !== "archived")
|
|
111
|
+
throw new Refusal({ state: "refused", why: put.message, merging: false });
|
|
112
|
+
if (made.length > 0)
|
|
113
|
+
store.recordAction({ at: now.toISOString(), actor: input.by, repo: ref.repo, taskId: input.taskId, runId: null, action: "release superseded", outcome: "done", source: "work", detail: [...steps, ...made].join(", ") });
|
|
114
|
+
return made;
|
|
115
|
+
});
|
|
116
|
+
if (refusedNow(done))
|
|
117
|
+
return done;
|
|
118
|
+
return { state: "done", steps: [...steps, ...done] };
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
if (error instanceof Again)
|
|
122
|
+
return { state: "stopping", steps, why: error.why };
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { stopPolicy } from "./release-stops.js";
|
|
2
|
+
export const HEAL_DEADLINE_MS = 6 * 60 * 60_000;
|
|
3
|
+
export const HEAL_MAX_TOTAL = 30;
|
|
4
|
+
export const HEAL_MAX = {
|
|
5
|
+
"network": 10, "checkout-busy": 12, "github-unreadable": 5,
|
|
6
|
+
"operation-in-flight": 6, "ci-missing": 4, "deploy-busy": 8, "superseding": 6, "timeout": 4,
|
|
7
|
+
"homebrew-pending": 6,
|
|
8
|
+
};
|
|
9
|
+
export const HEAL_PREFLIGHT_MAX = 5;
|
|
10
|
+
const PAUSE_MS = {
|
|
11
|
+
"auto-resume": [30_000, 60_000, 120_000, 300_000],
|
|
12
|
+
"auto-wait": [120_000, 300_000],
|
|
13
|
+
};
|
|
14
|
+
export function nextRun(outcome) {
|
|
15
|
+
if (outcome.ok) {
|
|
16
|
+
const j = outcome.journal;
|
|
17
|
+
return j.step === "homebrew" && j.published !== null && j.homebrew?.state === "pending" ? { key: "homebrew-pending", policy: "auto-wait" } : null;
|
|
18
|
+
}
|
|
19
|
+
const policy = stopPolicy(outcome.reason, outcome.waited ?? null);
|
|
20
|
+
return policy === "person" ? null : { key: outcome.reason, policy };
|
|
21
|
+
}
|
|
22
|
+
export function budgetFor(journal, now) {
|
|
23
|
+
const kept = journal.heal;
|
|
24
|
+
if (kept != null && kept.journal === journal.id && kept.candidate === journal.candidate.sha)
|
|
25
|
+
return kept;
|
|
26
|
+
return { journal: journal.id, candidate: journal.candidate.sha, since: now.toISOString(), deadline: new Date(now.getTime() + HEAL_DEADLINE_MS).toISOString(), counts: {}, total: 0, last: null };
|
|
27
|
+
}
|
|
28
|
+
export function exhausted(budget, key, now) {
|
|
29
|
+
if (now.getTime() >= Date.parse(budget.deadline))
|
|
30
|
+
return `it has been running itself again since ${budget.since}, up to its ${Math.round(HEAL_DEADLINE_MS / 3_600_000)}-hour limit`;
|
|
31
|
+
if (budget.total >= HEAL_MAX_TOTAL)
|
|
32
|
+
return `it already ran itself again ${budget.total} times`;
|
|
33
|
+
const max = HEAL_MAX[key] ?? 0;
|
|
34
|
+
if ((budget.counts[key] ?? 0) >= max)
|
|
35
|
+
return max === 0 ? "this stop is never run again by itself" : `it already ran itself again ${max} times for this`;
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
export async function superviseRelease(first, deps) {
|
|
39
|
+
let outcome = first;
|
|
40
|
+
let preflight = 0;
|
|
41
|
+
for (;;) {
|
|
42
|
+
if (deps.handOver?.(outcome) === true)
|
|
43
|
+
return outcome;
|
|
44
|
+
const next = nextRun(outcome);
|
|
45
|
+
if (next === null)
|
|
46
|
+
return outcome;
|
|
47
|
+
const now = deps.now();
|
|
48
|
+
let tries, deadline = null;
|
|
49
|
+
if (outcome.journal === null) {
|
|
50
|
+
if (preflight >= HEAL_PREFLIGHT_MAX) {
|
|
51
|
+
deps.say(` Toolroll stopped running it again by itself: it already tried ${preflight} times before anything began.`);
|
|
52
|
+
return outcome;
|
|
53
|
+
}
|
|
54
|
+
tries = ++preflight;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const journal = deps.read(outcome.file);
|
|
58
|
+
if (journal === null || journal.id !== outcome.journal.id)
|
|
59
|
+
return outcome;
|
|
60
|
+
const budget = budgetFor(journal, now);
|
|
61
|
+
const why = exhausted(budget, next.key, now);
|
|
62
|
+
if (why !== null) {
|
|
63
|
+
deps.say(` Toolroll stopped running it again by itself: ${why}.`);
|
|
64
|
+
return outcome;
|
|
65
|
+
}
|
|
66
|
+
budget.counts = { ...budget.counts, [next.key]: (budget.counts[next.key] ?? 0) + 1 };
|
|
67
|
+
budget.total += 1;
|
|
68
|
+
budget.last = { reason: next.key, step: journal.step, at: now.toISOString() };
|
|
69
|
+
journal.heal = budget;
|
|
70
|
+
deps.write(outcome.file, journal);
|
|
71
|
+
tries = budget.counts[next.key];
|
|
72
|
+
deadline = Date.parse(budget.deadline);
|
|
73
|
+
}
|
|
74
|
+
const pauses = PAUSE_MS[next.policy];
|
|
75
|
+
const pause = Math.max(0, Math.min(pauses[Math.min(tries - 1, pauses.length - 1)], deadline === null ? Infinity : deadline - now.getTime()));
|
|
76
|
+
deps.say(outcome.ok
|
|
77
|
+
? ` Homebrew is still pending; Toolroll finishes it by itself in ${Math.round(pause / 60_000)} min.`
|
|
78
|
+
: ` ${outcome.message.split("\n")[0]} Toolroll goes on by itself from ${outcome.step} in ${pause >= 60_000 ? `${Math.round(pause / 60_000)} min` : `${Math.round(pause / 1000)} s`}.`);
|
|
79
|
+
await deps.sleep(pause);
|
|
80
|
+
if (outcome.journal !== null) {
|
|
81
|
+
const kept = deps.read(outcome.file)?.heal;
|
|
82
|
+
const until = kept != null && kept.journal === outcome.journal.id ? Date.parse(kept.deadline) : deadline;
|
|
83
|
+
if (until !== null && !(deps.now().getTime() < until)) {
|
|
84
|
+
deps.say(` Toolroll stopped running it again by itself: its ${Math.round(HEAL_DEADLINE_MS / 3_600_000)}-hour limit passed.`);
|
|
85
|
+
return outcome;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
outcome = await deps.again();
|
|
89
|
+
}
|
|
90
|
+
}
|