toolroll 0.9.129 → 0.9.130
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 +24 -0
- package/dist/agent-fence.js +0 -2
- package/dist/agents-board.js +0 -3
- package/dist/assignment.js +4 -3
- package/dist/backup-ui.js +6 -3
- package/dist/bounded-spawn.js +0 -1
- package/dist/browser/manifest.json +57 -0
- package/dist/browser/terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js.br +0 -0
- package/dist/browser/terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js.gz +0 -0
- package/dist/browser/terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css.br +0 -0
- package/dist/browser/terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css.gz +0 -0
- package/dist/browser/{workspace.js → workspace.9bd1db81d3c897045a5d82d4804e374e41e78b1b2cfd05d37b982a4ea0d02626.js} +25 -25
- package/dist/browser/workspace.9bd1db81d3c897045a5d82d4804e374e41e78b1b2cfd05d37b982a4ea0d02626.js.br +0 -0
- package/dist/browser/workspace.9bd1db81d3c897045a5d82d4804e374e41e78b1b2cfd05d37b982a4ea0d02626.js.gz +0 -0
- package/dist/browser/{workspace.css → workspace.a0752f935cfeaf16758d1085fe8f3e1719a7cd525b91a9c9943c789d65879a54.css} +1 -1
- package/dist/browser/workspace.a0752f935cfeaf16758d1085fe8f3e1719a7cd525b91a9c9943c789d65879a54.css.br +0 -0
- package/dist/browser/workspace.a0752f935cfeaf16758d1085fe8f3e1719a7cd525b91a9c9943c789d65879a54.css.gz +0 -0
- package/dist/browser-shell.js +271 -25
- package/dist/canvas-freshness.js +122 -0
- package/dist/canvas-fs.js +273 -0
- package/dist/canvas-reads.js +747 -0
- package/dist/canvas-state-key.js +45 -0
- package/dist/canvas-state-worker.js +12 -0
- package/dist/central-recovery-stage.js +3 -3
- package/dist/chat-actions.js +26 -0
- package/dist/chat-channel.js +4 -3
- package/dist/chat-task-actions.js +1 -1
- package/dist/chat-warmth.js +0 -1
- package/dist/check-report.js +0 -6
- package/dist/commit-extract.js +79 -40
- package/dist/companion/access.js +1 -0
- package/dist/companion/actions.js +79 -16
- package/dist/companion/canvas.js +141 -0
- package/dist/companion/chat-origin.js +92 -0
- package/dist/companion/chat.js +571 -0
- package/dist/companion/daemon.js +46 -5
- package/dist/companion/finish.js +51 -0
- package/dist/companion/reads.js +5 -1
- package/dist/companion/schema.js +64 -0
- package/dist/companion/service.js +1 -0
- package/dist/companion/store.js +1 -0
- package/dist/companion/webauthn.js +11 -2
- package/dist/console-instance.js +0 -4
- package/dist/contracts/console-api.js +1 -1
- package/dist/converse.js +0 -1
- package/dist/coordinator.js +1 -1
- package/dist/desktop-config.js +156 -0
- package/dist/desktop-host.js +6 -152
- package/dist/desktop-update.js +1 -1
- package/dist/finished-task-sql.js +14 -0
- package/dist/flexible-answers.js +0 -1
- package/dist/github-read.js +41 -0
- package/dist/guides.js +4 -3
- package/dist/lead-doors.js +50 -3
- package/dist/lead-queue-runtime.js +11 -2
- package/dist/lead-queue.js +25 -0
- package/dist/live-backup-change.js +93 -0
- package/dist/live-backup.js +75 -31
- package/dist/live-bus.js +3 -2
- package/dist/live-records.js +0 -1
- package/dist/local-owner.js +0 -1
- package/dist/model-choices.js +0 -11
- package/dist/nightly-check.js +0 -3
- package/dist/nightly-github.js +1 -2
- package/dist/notification-retention.js +119 -0
- package/dist/observations.js +0 -1
- package/dist/operate.js +17 -4
- package/dist/pull-request-flow.js +56 -15
- package/dist/qr.js +0 -25
- package/dist/release-adapters.js +12 -42
- package/dist/release-auto.js +17 -13
- package/dist/release-card.js +0 -4
- package/dist/release-cli.js +37 -2
- package/dist/release.js +13 -2
- package/dist/restore-retirement.js +4 -1
- package/dist/result-review.js +0 -3
- package/dist/retention-ui.js +1 -1
- package/dist/retention.js +14 -21
- package/dist/review-context.js +0 -5
- package/dist/route-rules.js +1 -5
- package/dist/sandbox-runtime.js +0 -1
- package/dist/scope.js +1 -13
- package/dist/scout.js +0 -6
- package/dist/serve.js +31 -7
- package/dist/server/kit.js +1 -0
- package/dist/server/live.js +9 -2
- package/dist/server/pages.js +3 -2
- package/dist/server/phone-engine-api.js +22 -2
- package/dist/server/render-pages.js +1 -11
- package/dist/server/render-results.js +0 -1
- package/dist/server/render-tasks.js +0 -68
- package/dist/server/route-table.js +1 -1
- package/dist/server/settings-phone.js +32 -9
- package/dist/server/settings-scripts.js +1 -1
- package/dist/server/settings-section-table.js +0 -3
- package/dist/server/settings-sections.js +4 -2
- package/dist/server/settings.js +20 -5
- package/dist/server/terminals.js +2 -1
- package/dist/store.js +20 -5
- package/dist/structured-output.js +0 -1
- package/dist/style-asset.js +20 -7
- package/dist/tailnet.js +0 -3
- package/dist/task-control.js +5 -0
- package/dist/task-sizing.js +0 -1
- package/dist/toolroll-update-cli.js +19 -3
- package/dist/toolroll-update-ui.js +2 -2
- package/dist/toolroll-update.js +95 -15
- package/package.json +1 -1
- package/dist/companion/webauthn-test-support.js +0 -44
- package/dist/contracts/contract-test.js +0 -55
- package/dist/unfenced-test-support.js +0 -6
- /package/dist/browser/{terminal.js → terminal.2a682d0b91a35288271c73b7ee253e524cca0917d17fbaf6733e80b7a767a37c.js} +0 -0
- /package/dist/browser/{terminal.css → terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css} +0 -0
|
@@ -15,7 +15,8 @@ import { belongsToRelease } from "./release-authority.js";
|
|
|
15
15
|
import { autoReleaseSealed } from "./release-auto.js";
|
|
16
16
|
import { fullCheckGate, requestFollowUpChecks } from "./result-follow-ups.js";
|
|
17
17
|
import { checkPasskeyAction, consumePasskeyAction } from "./companion/passkey-gate.js";
|
|
18
|
-
import {
|
|
18
|
+
import { getPasskeyChallenge } from "./companion/store.js";
|
|
19
|
+
import { canonicalJson, passkeyProofDetail, publishDestinationForRun } from "./companion/webauthn.js";
|
|
19
20
|
export const MERGE_METHODS = ["squash", "merge", "rebase"];
|
|
20
21
|
export const MAX_CI_REVISIONS = 2;
|
|
21
22
|
export const MERGED_ACTION = "pull request merged";
|
|
@@ -155,6 +156,9 @@ export function completeAndOpenPullRequest(store, input, now) {
|
|
|
155
156
|
const run = store.getRun(input.runId);
|
|
156
157
|
if (receipt.head !== null && receipt.head !== run.headRevision)
|
|
157
158
|
return refuse("stale", "This result's commit changed. Open the current result first.");
|
|
159
|
+
if (input.destination !== undefined && canonicalJson(publishDestinationForRun(store, input.runId)) !== canonicalJson(input.destination)) {
|
|
160
|
+
return refuse("changed", "Where this pull request would open changed since you reviewed it. Nothing was published.");
|
|
161
|
+
}
|
|
158
162
|
const completed = checkAssignmentAsOperator(store, input.taskId, input.digest, input.who, now, input.root);
|
|
159
163
|
if (!completed.ok)
|
|
160
164
|
return refuse(completed.reason, completed.message);
|
|
@@ -344,6 +348,7 @@ function askPerson(store, publication, head, body, clock) {
|
|
|
344
348
|
});
|
|
345
349
|
}
|
|
346
350
|
export const MERGE_PROVED_ACTION = "merge proved";
|
|
351
|
+
export const MERGED_ELSEWHERE_ACTION = "merged elsewhere";
|
|
347
352
|
export async function mergeAsPerson(store, input) {
|
|
348
353
|
const run = store.getRun(input.runId);
|
|
349
354
|
const taskRef = run === null ? null : store.refById(run.taskRef);
|
|
@@ -356,27 +361,31 @@ export async function mergeAsPerson(store, input) {
|
|
|
356
361
|
return refuse("no-pr", "This result has no open pull request to merge.");
|
|
357
362
|
}
|
|
358
363
|
const method = grant?.mergeMethod ?? "squash";
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
};
|
|
368
|
-
const
|
|
369
|
-
if (!checked.ok)
|
|
370
|
-
return refuse("password", checked.message);
|
|
371
|
-
return mergePullRequest(store, {
|
|
364
|
+
const passkey = input.passkey;
|
|
365
|
+
const bindingOf = (base) => ({ verb: "ship", runId: input.runId, taskId: taskRef.externalId, prNumber: publication.prNumber,
|
|
366
|
+
headSha: publication.headSha, method, anyway: input.anyway === true, githubRepo: publication.githubRepo, base });
|
|
367
|
+
const row = getPasskeyChallenge(store.handle, passkey.challenge);
|
|
368
|
+
const bound = row === null ? null : JSON.parse(row.bindingJson).base;
|
|
369
|
+
const early = checkPasskeyAction(store, { accountName: input.name, repo, verb: "ship", expectedBinding: bindingOf(typeof bound === "string" ? bound : ""), proof: passkey, now: clock() });
|
|
370
|
+
if (!early.ok)
|
|
371
|
+
return refuse(early.code === "binding_mismatch" ? "changed" : "password", early.message);
|
|
372
|
+
const signed = { base: typeof bound === "string" ? bound : "", head: publication.headSha };
|
|
373
|
+
const merged = await mergePullRequest(store, {
|
|
372
374
|
runId: input.runId,
|
|
373
375
|
by: input.name,
|
|
374
376
|
...(input.anyway === true ? { anyway: true } : {}),
|
|
375
377
|
...(input.exec === undefined ? {} : { exec: input.exec }),
|
|
376
378
|
...(input.clock === undefined ? {} : { clock: input.clock }),
|
|
379
|
+
destination: seen => seen.base !== signed.base
|
|
380
|
+
? `It merged into ${seen.base ?? "another branch"}, not ${signed.base}: the pull request's base changed on GitHub.`
|
|
381
|
+
: seen.head !== signed.head ? `It merged at ${(seen.head ?? "another commit").slice(0, 7)}, not the approved ${signed.head.slice(0, 7)}.` : null,
|
|
377
382
|
beforeReserve: seen => {
|
|
378
383
|
if (seen.head !== publication.headSha)
|
|
379
384
|
return { ok: false, message: "The pull request head moved before merging." };
|
|
385
|
+
const expectedBinding = bindingOf(seen.base ?? "");
|
|
386
|
+
const checked = checkPasskeyAction(store, { accountName: input.name, repo, verb: "ship", expectedBinding, proof: passkey, now: clock() });
|
|
387
|
+
if (!checked.ok)
|
|
388
|
+
return { ok: false, message: checked.message, ...(checked.code === "binding_mismatch" ? { reason: "changed" } : {}) };
|
|
380
389
|
const now = clock();
|
|
381
390
|
const consumed = consumePasskeyAction(store, checked, { repo, now });
|
|
382
391
|
if (!consumed.ok)
|
|
@@ -404,6 +413,9 @@ export async function mergeAsPerson(store, input) {
|
|
|
404
413
|
return { ok: true };
|
|
405
414
|
},
|
|
406
415
|
});
|
|
416
|
+
if (!merged.ok && merged.reason === "elsewhere")
|
|
417
|
+
recordMergedElsewhere(store, { publication, taskId: taskRef.externalId, repo, by: input.name, words: merged.message }, clock());
|
|
418
|
+
return merged;
|
|
407
419
|
}
|
|
408
420
|
if (input.password === undefined || input.password === "")
|
|
409
421
|
return refuse("password", "Enter your password to merge.");
|
|
@@ -509,6 +521,7 @@ export async function mergePullRequest(store, input) {
|
|
|
509
521
|
const token = randomUUID();
|
|
510
522
|
let reserved;
|
|
511
523
|
let passkeyRefusedMsg = "Passkey verification failed.";
|
|
524
|
+
let passkeyRefusedReason = "password";
|
|
512
525
|
try {
|
|
513
526
|
reserved = store.transact(() => {
|
|
514
527
|
if (fullCheckGate(store, publication.run, clock()).state === "recovery-held")
|
|
@@ -530,6 +543,7 @@ export async function mergePullRequest(store, input) {
|
|
|
530
543
|
const check = input.beforeReserve({ base: before.base, url: before.url, head: before.head });
|
|
531
544
|
if (!check.ok) {
|
|
532
545
|
passkeyRefusedMsg = check.message;
|
|
546
|
+
passkeyRefusedReason = check.reason ?? "password";
|
|
533
547
|
return "passkey-refused";
|
|
534
548
|
}
|
|
535
549
|
}
|
|
@@ -543,7 +557,7 @@ export async function mergePullRequest(store, input) {
|
|
|
543
557
|
throw error;
|
|
544
558
|
}
|
|
545
559
|
if (reserved === "passkey-refused")
|
|
546
|
-
return refuse(
|
|
560
|
+
return refuse(passkeyRefusedReason, passkeyRefusedMsg);
|
|
547
561
|
if (reserved === "recovery-held")
|
|
548
562
|
return refuse("recovery-held", "Checks are on hold after recovery. Earlier execution is unverified.");
|
|
549
563
|
if (reserved === "halted")
|
|
@@ -580,11 +594,16 @@ export function pullRequestViewOf(store, runId) {
|
|
|
580
594
|
const follow = publication === null ? null : followOf(store, publication.id);
|
|
581
595
|
if (publication === null || follow === null)
|
|
582
596
|
return null;
|
|
597
|
+
const elsewhere = follow.mergeCommit !== null ? undefined
|
|
598
|
+
: store.handle.prepare("SELECT detail FROM action_ledger WHERE run_id = ? AND action = ? ORDER BY id DESC LIMIT 1").get(runId, MERGED_ELSEWHERE_ACTION);
|
|
583
599
|
const grant = store.publicationGrantFor(store.refById(publication.taskRef)?.repo ?? "");
|
|
584
600
|
const method = follow.mergeMethod ?? grant?.mergeMethod ?? "squash";
|
|
585
601
|
const gate = fullCheckGate(store, runId, new Date());
|
|
586
602
|
const fullCheck = gate.state === "clear" ? null : gate;
|
|
587
603
|
const base = { runId, prNumber: publication.prNumber, prUrl: publication.prUrl, mergeCommit: follow.mergeCommit || null, mergeMethod: method, canMerge: false, revisionTask: follow.revisionTask, fullCheck };
|
|
604
|
+
if (elsewhere !== undefined) {
|
|
605
|
+
return { ...base, state: "failed", label: "Merged into another branch", detail: `${String(elsewhere["detail"] ?? "It merged somewhere it wasn't approved for.")} Check it on GitHub.` };
|
|
606
|
+
}
|
|
588
607
|
const error = follow.mergeError === null ? "" : ` Last merge attempt: ${follow.mergeError}`;
|
|
589
608
|
if (follow.mergeCommit !== null) {
|
|
590
609
|
return { ...base, state: "merged", label: "Merged", detail: follow.mergedBy === null || follow.mergedBy === "GitHub" ? "Merged on GitHub." : `Merged by ${follow.mergedBy}${follow.mergeMethod === null ? "" : ` (${follow.mergeMethod})`}. Branch deleted.` };
|
|
@@ -627,3 +646,25 @@ export function newestPullRequestOf(store, versions) {
|
|
|
627
646
|
export const MERGE_NEEDS_PERSON = "Only a person can merge. Merge it on the task page or from your paired chat.";
|
|
628
647
|
class RecoveryHeldReservation extends Error {
|
|
629
648
|
}
|
|
649
|
+
export async function pullRequestOnGitHub(publication, exec = execRun) {
|
|
650
|
+
if (publication.prNumber === null)
|
|
651
|
+
return null;
|
|
652
|
+
const viewed = await exec("gh", ["pr", "view", String(publication.prNumber), "--repo", publication.githubRepo, "--json", "state,headRefOid,baseRefName,url"], { timeoutMs: EXEC_TIMEOUT_MS });
|
|
653
|
+
if (viewed.code !== 0)
|
|
654
|
+
return null;
|
|
655
|
+
try {
|
|
656
|
+
const payload = JSON.parse(viewed.stdout);
|
|
657
|
+
return { state: String(payload.state ?? "").toUpperCase(), head: typeof payload.headRefOid === "string" ? payload.headRefOid : null,
|
|
658
|
+
base: typeof payload.baseRefName === "string" ? payload.baseRefName : null, url: typeof payload.url === "string" ? payload.url : null };
|
|
659
|
+
}
|
|
660
|
+
catch {
|
|
661
|
+
return null;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
function recordMergedElsewhere(store, input, now) {
|
|
665
|
+
store.transact(() => {
|
|
666
|
+
updateFollow(store, input.publication.id, { merge_error: input.words.slice(0, 300) }, now);
|
|
667
|
+
store.recordAction({ at: now.toISOString(), actor: input.by, repo: input.repo, taskId: input.taskId, runId: input.publication.run, action: MERGED_ELSEWHERE_ACTION,
|
|
668
|
+
outcome: "needs-person", source: "work", detail: input.words });
|
|
669
|
+
});
|
|
670
|
+
}
|
package/dist/qr.js
CHANGED
|
@@ -61,31 +61,6 @@ export function encodeQr(data, ecc = "M") {
|
|
|
61
61
|
const modules = symbol.modules, size = symbol.size;
|
|
62
62
|
return { version, size, ecc: level, mask: bestMask, dark: (x, y) => x >= 0 && y >= 0 && x < size && y < size && modules[y][x] };
|
|
63
63
|
}
|
|
64
|
-
export function qrSvg(code, opts = {}) {
|
|
65
|
-
const border = 4, dim = code.size + border * 2;
|
|
66
|
-
let path = "";
|
|
67
|
-
for (let y = 0; y < code.size; y++)
|
|
68
|
-
for (let x = 0; x < code.size; x++) {
|
|
69
|
-
if (code.dark(x, y))
|
|
70
|
-
path += `M${x + border},${y + border}h1v1h-1z`;
|
|
71
|
-
}
|
|
72
|
-
const title = opts.title === undefined ? "" : `<title>${opts.title.replace(/[<>&"]/g, c => `&#${c.charCodeAt(0)};`)}</title>`;
|
|
73
|
-
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${dim} ${dim}" shape-rendering="crispEdges" role="img">${title}` +
|
|
74
|
-
`<rect width="100%" height="100%" fill="${opts.light ?? "#ffffff"}"/><path d="${path}" fill="${opts.dark ?? "#000000"}"/></svg>`;
|
|
75
|
-
}
|
|
76
|
-
export function qrText(code) {
|
|
77
|
-
const border = 2, lines = [];
|
|
78
|
-
const on = (x, y) => !code.dark(x, y);
|
|
79
|
-
for (let y = -border; y < code.size + border; y += 2) {
|
|
80
|
-
let line = "";
|
|
81
|
-
for (let x = -border; x < code.size + border; x++) {
|
|
82
|
-
const top = on(x, y), bottom = on(x, y + 1);
|
|
83
|
-
line += top && bottom ? "█" : top ? "▀" : bottom ? "▄" : " ";
|
|
84
|
-
}
|
|
85
|
-
lines.push(line);
|
|
86
|
-
}
|
|
87
|
-
return lines.join("\n");
|
|
88
|
-
}
|
|
89
64
|
function appendBits(out, value, length) {
|
|
90
65
|
for (let i = length - 1; i >= 0; i--)
|
|
91
66
|
out.push((value >>> i) & 1);
|
package/dist/release-adapters.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { existsSync, lstatSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync } from "node:fs";
|
|
4
4
|
import { homedir, tmpdir } from "node:os";
|
|
@@ -24,6 +24,7 @@ import { CHECK_REPORT_CAPTURE, readSealedJson } from "./check-report.js";
|
|
|
24
24
|
import { readCheckReport } from "./contracts/release-check.js";
|
|
25
25
|
import { macosCases, skipCoverage, skippedCases, uncoveredWords } from "./fenced-check-coverage.js";
|
|
26
26
|
import { runCheckStamp } from "./store.js";
|
|
27
|
+
import { runtimeVersionAt } from "./toolroll-update.js";
|
|
27
28
|
import { noteCiRunning, releaseCiHoldOf, releaseCiRunningOf } from "./release-ci-hold.js";
|
|
28
29
|
import { autoPublishHeld, holdAutoPublish, liftCiHold, authorizeAutoCheck, giveUpAutoApproval, noteAutoCheckFailed, noteAutoRelease, releaseAutoApproves, sealAutoGreen } from "./release-auto.js";
|
|
29
30
|
import { proveCarry } from "./release-carry.js";
|
|
@@ -37,19 +38,9 @@ export { failedBeforeTests } from "./github-jobs.js";
|
|
|
37
38
|
import { extractCommit } from "./commit-extract.js";
|
|
38
39
|
import { teardownGit, refusal as gitRefusal } from "./teardown-git.js";
|
|
39
40
|
import { RELEASE_REMOTE, releaseConfigProblem, releaseGitArgs, releaseGitEnv, releaseRemote, releaseTools } from "./release-git.js";
|
|
41
|
+
import { ciEnv, exec, githubReads } from "./github-read.js";
|
|
42
|
+
export { exec, githubReads } from "./github-read.js";
|
|
40
43
|
export { RELEASE_PATH, RELEASE_REMOTE, releaseConfigProblem, releaseGitArgs, releaseGitEnv, releaseRemote, releaseTools } from "./release-git.js";
|
|
41
|
-
export const exec = (command, args, options = {}) => new Promise(done => {
|
|
42
|
-
const child = execFile(command, [...args], { cwd: options.cwd, env: options.env ?? process.env, timeout: options.timeoutMs ?? 120_000, maxBuffer: 64 * 1024 * 1024, encoding: "utf8" }, (error, stdout, stderr) => {
|
|
43
|
-
const failure = error;
|
|
44
|
-
const code = failure === null ? 0 : failure.code === "ENOENT" ? 127 : failure.killed === true ? 124 : typeof failure.code === "number" ? failure.code : 1;
|
|
45
|
-
done({ code, stdout: String(stdout ?? ""), stderr: String(stderr ?? "") });
|
|
46
|
-
});
|
|
47
|
-
child.stdin?.on("error", () => { });
|
|
48
|
-
if (options.input !== undefined)
|
|
49
|
-
child.stdin?.end(options.input);
|
|
50
|
-
else
|
|
51
|
-
child.stdin?.end();
|
|
52
|
-
});
|
|
53
44
|
const ownCli = () => {
|
|
54
45
|
const bin = join(dirname(fileURLToPath(import.meta.url)), "bin.js");
|
|
55
46
|
return existsSync(bin) ? [process.execPath, bin] : ["toolroll"];
|
|
@@ -438,7 +429,11 @@ export function releaseAdapters(options) {
|
|
|
438
429
|
},
|
|
439
430
|
},
|
|
440
431
|
toolroll: {
|
|
441
|
-
async installed() {
|
|
432
|
+
async installed() {
|
|
433
|
+
const services = serviceRuntimes(), clis = cliRuntimes();
|
|
434
|
+
const versions = Object.fromEntries([...services, ...clis.flatMap(one => one.runtime === null ? [] : [one.runtime])].map(dist => [dist, runtimeVersionAt(dist)]));
|
|
435
|
+
return { services, clis, versions };
|
|
436
|
+
},
|
|
442
437
|
async runtimeCommit(runtime) {
|
|
443
438
|
try {
|
|
444
439
|
const candidate = object(JSON.parse(readFileSync(join(runtime, "..", "..", "..", "package.json"), "utf8")))["candidate"];
|
|
@@ -1056,10 +1051,6 @@ function autoReleaseAdapter(withStore, now, auto) {
|
|
|
1056
1051
|
async publishHeld(taskId) { return withStore(store => autoPublishHeld(store, taskId)); },
|
|
1057
1052
|
};
|
|
1058
1053
|
}
|
|
1059
|
-
function ciEnv() {
|
|
1060
|
-
const kept = Object.fromEntries(["HOME", "LANG", "LC_ALL", "TMPDIR", "USER", "LOGNAME", "GH_TOKEN", "GITHUB_TOKEN"].flatMap(name => process.env[name] === undefined ? [] : [[name, process.env[name]]]));
|
|
1061
|
-
return { ...kept, PATH: "/usr/bin:/bin", GH_HOST: "github.com", GH_PROMPT_DISABLED: "1", GH_NO_UPDATE_NOTIFIER: "1" };
|
|
1062
|
-
}
|
|
1063
1054
|
export async function readCheckRuns(run, gh, repo, sha, options = {}) {
|
|
1064
1055
|
if (options.tag !== undefined && !/^v\d+\.\d+\.\d+$/.test(options.tag))
|
|
1065
1056
|
throw new Error("not a release tag");
|
|
@@ -1070,14 +1061,15 @@ export async function readCheckRuns(run, gh, repo, sha, options = {}) {
|
|
|
1070
1061
|
const flows = await must(run(gh, ["api", "--hostname", "github.com", "--paginate", `repos/${repo}/actions/runs?head_sha=${sha}&per_page=100`,
|
|
1071
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");
|
|
1072
1063
|
const retargeted = new Map();
|
|
1064
|
+
const RETARGET_EVENTS = new Set(["base_ref_changed", "automatic_base_change_succeeded", "automatic_base_change_failed"]);
|
|
1073
1065
|
const everRetargeted = async (pr) => {
|
|
1074
1066
|
const known = retargeted.get(pr);
|
|
1075
1067
|
if (known !== undefined)
|
|
1076
1068
|
return known;
|
|
1077
1069
|
let changed = true;
|
|
1078
1070
|
try {
|
|
1079
|
-
const
|
|
1080
|
-
changed = events.code !== 0 || events.stdout.split("\n").some(line => line.trim()
|
|
1071
|
+
const reads = await Promise.all(["timeline", "events"].map(kind => run(gh, ["api", "--hostname", "github.com", "--paginate", `repos/${repo}/issues/${pr}/${kind}?per_page=100`, "--jq", ".[] | .event"], { cwd: "/", env: ciEnv() })));
|
|
1072
|
+
changed = reads.some(events => events.code !== 0 || events.stdout.split("\n").some(line => RETARGET_EVENTS.has(line.trim())));
|
|
1081
1073
|
}
|
|
1082
1074
|
catch {
|
|
1083
1075
|
changed = true;
|
|
@@ -1145,28 +1137,6 @@ export async function readJobBeforeTests(run, gh, repo, id) {
|
|
|
1145
1137
|
return failedBeforeTests({ id, status: String(job["status"]), conclusion: textOr(job["conclusion"]),
|
|
1146
1138
|
steps: steps.map(one => ({ number: Number(one["number"]), name: String(one["name"]), status: String(one["status"]), conclusion: textOr(one["conclusion"]) })) });
|
|
1147
1139
|
}
|
|
1148
|
-
export function githubReads(run, gh, options = {}) {
|
|
1149
|
-
return async (path, timeoutMs) => {
|
|
1150
|
-
if (!/^repos\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_./?&=%-]+$/.test(path) || timeoutMs <= 0)
|
|
1151
|
-
return { ok: false, why: "not a read this makes" };
|
|
1152
|
-
const exec = options.retry === true ? retryingExec(run, { say: () => { }, sleep, budgetMs: timeoutMs }) : run;
|
|
1153
|
-
let result;
|
|
1154
|
-
try {
|
|
1155
|
-
result = await exec(gh, ["api", "--hostname", "github.com", "--method", "GET", path], { cwd: "/", env: ciEnv(), timeoutMs });
|
|
1156
|
-
}
|
|
1157
|
-
catch (error) {
|
|
1158
|
-
return { ok: false, why: String(error?.message ?? error).slice(0, 200) };
|
|
1159
|
-
}
|
|
1160
|
-
if (result.code !== 0)
|
|
1161
|
-
return { ok: false, why: result.code === 124 ? "GitHub didn't answer in time" : result.code === 127 ? "gh isn't installed" : (result.stderr || result.stdout).trim().split("\n").slice(-1)[0].slice(0, 200) || `gh exited ${result.code}` };
|
|
1162
|
-
try {
|
|
1163
|
-
return { ok: true, body: JSON.parse(result.stdout) };
|
|
1164
|
-
}
|
|
1165
|
-
catch {
|
|
1166
|
-
return { ok: false, why: "GitHub's answer couldn't be read" };
|
|
1167
|
-
}
|
|
1168
|
-
};
|
|
1169
|
-
}
|
|
1170
1140
|
export const CHECK_SUITE_CEILING = 1000;
|
|
1171
1141
|
export async function readSuitesComplete(run, gh, repo, sha) {
|
|
1172
1142
|
if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repo) || !/^[0-9a-f]{40}$/.test(sha))
|
package/dist/release-auto.js
CHANGED
|
@@ -3,7 +3,7 @@ import { assignmentOf } from "./assignment.js";
|
|
|
3
3
|
import { fullCheckProblem, projectGitDir } from "./check-report.js";
|
|
4
4
|
import { sealedRun } from "./release-recheck.js";
|
|
5
5
|
import { runCheckLevel } from "./check-levels.js";
|
|
6
|
-
import { readVerifiedCommit,
|
|
6
|
+
import { readVerifiedCommit, verifiedView } from "./commit-extract.js";
|
|
7
7
|
import { EVAL_HOOK_FILES, evalHookProblem, LEARNING_HOOK_FILES, learningHookProblem, storeRewriteProblem } from "./eval-hooks.js";
|
|
8
8
|
import { isTestPath, mightName, testImportProblem, testInfrastructure } from "./test-infra.js";
|
|
9
9
|
import { chatControlHref } from "./chat-controls.js";
|
|
@@ -209,13 +209,13 @@ function withoutVersion(path, bytes) {
|
|
|
209
209
|
: value !== null && typeof value === "object" ? Object.fromEntries(Object.keys(value).sort().map(key => [key, canonical(value[key])])) : value;
|
|
210
210
|
return JSON.stringify(canonical(copy));
|
|
211
211
|
}
|
|
212
|
-
function infrastructureAt(
|
|
213
|
-
const entries =
|
|
212
|
+
function infrastructureAt(git, tree) {
|
|
213
|
+
const entries = git.treeEntries(tree);
|
|
214
214
|
if (!entries.ok)
|
|
215
215
|
return null;
|
|
216
216
|
const files = entries.value.filter(one => one.mode === "100644" || one.mode === "100755");
|
|
217
217
|
const paths = files.filter(one => (/\.(?:[cm]?[jt]sx?)$/.test(one.path) && !one.path.startsWith("node_modules/")) || one.path === "tsconfig.json" || one.path === "package.json").map(one => one.path);
|
|
218
|
-
const blobs =
|
|
218
|
+
const blobs = git.blobs(tree, paths);
|
|
219
219
|
if (!blobs.ok)
|
|
220
220
|
return null;
|
|
221
221
|
try {
|
|
@@ -231,34 +231,38 @@ function changeProblem(repo, base, candidate) {
|
|
|
231
231
|
return "the project's Git directory can't be read";
|
|
232
232
|
if (base === null || !/^[0-9a-f]{40}$/.test(base))
|
|
233
233
|
return "no base was recorded to compare with";
|
|
234
|
-
const
|
|
234
|
+
const view = verifiedView(gitDir);
|
|
235
|
+
if (!view.ok)
|
|
236
|
+
return "the candidate's commits can't be read";
|
|
237
|
+
const git = view.value;
|
|
238
|
+
const before = git.commit(base), after = git.commit(candidate);
|
|
235
239
|
if (!before.ok || !after.ok)
|
|
236
240
|
return "the candidate's commits can't be read";
|
|
237
|
-
const diff =
|
|
241
|
+
const diff = git.treeDiff(before.value.tree, after.value.tree);
|
|
238
242
|
if (!diff.ok)
|
|
239
243
|
return `the candidate's change can't be read: ${diff.message}`;
|
|
240
244
|
const scans = [];
|
|
241
245
|
for (const tree of [before.value.tree, after.value.tree]) {
|
|
242
|
-
const found = infrastructureAt(
|
|
246
|
+
const found = infrastructureAt(git, tree);
|
|
243
247
|
if (found === null)
|
|
244
248
|
return "the tests' imports can't be read";
|
|
245
249
|
scans.push(found);
|
|
246
250
|
}
|
|
247
251
|
const infra = new Set(scans.flatMap(one => [...one.infra]));
|
|
248
|
-
const blobAt = (tree) => { const blobs =
|
|
252
|
+
const blobAt = (tree) => { const blobs = git.blobs(tree, EVAL_HOOK_FILES); return (file) => blobs.ok ? blobs.value.get(file)?.bytes ?? null : null; };
|
|
249
253
|
const hooks = evalHookProblem(blobAt(after.value.tree), blobAt(before.value.tree));
|
|
250
254
|
if (hooks !== null)
|
|
251
255
|
return `${hooks}: a person decides`;
|
|
252
256
|
const changed = diff.value.filter(change => change.after !== null).map(change => change.path);
|
|
253
|
-
const changedAt = (tree) => { const blobs =
|
|
257
|
+
const changedAt = (tree) => { const blobs = git.blobs(tree, changed); return blobs.ok ? (file) => blobs.value.get(file)?.bytes ?? null : null; };
|
|
254
258
|
const rewrites = storeRewriteProblem(changed, changedAt(after.value.tree), changedAt(before.value.tree));
|
|
255
259
|
if (rewrites !== null)
|
|
256
260
|
return `${rewrites}: a person decides`;
|
|
257
|
-
const routingAt = (tree) => { const blobs =
|
|
261
|
+
const routingAt = (tree) => { const blobs = git.blobs(tree, ROUTING_HOOK_FILES); return (file) => blobs.ok ? blobs.value.get(file)?.bytes ?? null : null; };
|
|
258
262
|
const routing = routingHookProblem({ candidate: routingAt(after.value.tree), base: routingAt(before.value.tree) }, { paths: changed, candidate: changedAt(after.value.tree), base: changedAt(before.value.tree) });
|
|
259
263
|
if (routing !== null)
|
|
260
264
|
return `${routing}: a person decides`;
|
|
261
|
-
const learningAt = (tree) => { const blobs =
|
|
265
|
+
const learningAt = (tree) => { const blobs = git.blobs(tree, LEARNING_HOOK_FILES); return (file) => blobs.ok ? blobs.value.get(file)?.bytes ?? null : null; };
|
|
262
266
|
const learning = learningHookProblem({ candidate: learningAt(after.value.tree), base: learningAt(before.value.tree) }, { paths: changed, candidate: changedAt(after.value.tree), base: changedAt(before.value.tree) });
|
|
263
267
|
if (learning !== null)
|
|
264
268
|
return `${learning}: a person decides`;
|
|
@@ -271,7 +275,7 @@ function changeProblem(repo, base, candidate) {
|
|
|
271
275
|
if (change.before !== null && TEST_FILE.test(rulePath(change.path)))
|
|
272
276
|
return `${change.path} changes existing test code (new tests go in a new file; rewriting tests needs a person)`;
|
|
273
277
|
if (change.kind === "added" && isTestPath(rulePath(change.path))) {
|
|
274
|
-
const read =
|
|
278
|
+
const read = git.blobs(after.value.tree, [change.path]);
|
|
275
279
|
const bytes = read.ok ? read.value.get(change.path)?.bytes : undefined;
|
|
276
280
|
const why = bytes === undefined ? `${change.path}'s test code couldn't be read` : testImportProblem(change.path, bytes.toString("utf8"));
|
|
277
281
|
if (why !== null)
|
|
@@ -289,7 +293,7 @@ function changeProblem(repo, base, candidate) {
|
|
|
289
293
|
}
|
|
290
294
|
const normal = rulePath(change.path);
|
|
291
295
|
if (normal === "package.json" || normal === "package-lock.json") {
|
|
292
|
-
const read = (tree) => { const blobs =
|
|
296
|
+
const read = (tree) => { const blobs = git.blobs(tree, [change.path]); return blobs.ok ? withoutVersion(normal, blobs.value.get(change.path)?.bytes) : undefined; };
|
|
293
297
|
const was = read(before.value.tree), now = read(after.value.tree);
|
|
294
298
|
if (was === undefined || now === undefined || was !== now)
|
|
295
299
|
return `${change.path} changed beyond its version (dependencies or scripts need a person)`;
|
package/dist/release-card.js
CHANGED
|
@@ -197,10 +197,6 @@ export function readCommitsBetween(repo, from, to) {
|
|
|
197
197
|
}
|
|
198
198
|
return { ok: true, commits: range.value.map(one => ({ sha: one.id, subject: subjectText(one.message) })) };
|
|
199
199
|
}
|
|
200
|
-
export function commitsBetween(repo, from, to) {
|
|
201
|
-
const read = readCommitsBetween(repo, from, to);
|
|
202
|
-
return read.ok ? read.commits : null;
|
|
203
|
-
}
|
|
204
200
|
export const PULL_REQUEST_COMMITS_MAX = 250;
|
|
205
201
|
export const subjectText = (subject) => cleanTerminalLine(subject.split("\n")[0] ?? "").trim().slice(0, 200);
|
|
206
202
|
const ghRead = args => {
|
package/dist/release-cli.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
1
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
3
|
import { homedir } from "node:os";
|
|
3
4
|
import { dirname, join, resolve } from "node:path";
|
|
4
5
|
import { createRequire } from "node:module";
|
|
5
6
|
const sqlite = () => createRequire(import.meta.url)("node:sqlite");
|
|
6
7
|
import { checkedEnvelopeJson } from "./contracts/cli.js";
|
|
7
|
-
import { RELEASE_LIMITS, runRelease } from "./release.js";
|
|
8
|
+
import { RELEASE_LIMITS, RELEASE_STEPS, runRelease } from "./release.js";
|
|
8
9
|
import { exec, prepareRelease, processes, readMainVersion, recordedReleaseRepo, releaseAdapters, releaseTools } from "./release-adapters.js";
|
|
9
10
|
import { mainRunKey, releaseBranchFor } from "./release-main.js";
|
|
10
11
|
import { journals, releaseGate } from "./release-gate.js";
|
|
@@ -290,6 +291,7 @@ export async function runReleaseCommand(args, write, deps = {}) {
|
|
|
290
291
|
const taken = await takeReleaseRun(stateDir, lockKey, say, deps.runLock);
|
|
291
292
|
if (!taken.ok)
|
|
292
293
|
return refuse("running", `Another release of ${version ?? branch} is still running on ${taken.holder.host} (process ${taken.holder.pid}). Nothing was changed.`, 3);
|
|
294
|
+
let next = null;
|
|
293
295
|
try {
|
|
294
296
|
const world = deps.settle ?? (deps.adapters === undefined ? { rescue: installedRescueWorld(checkout), gate: installedGateWorld() } : null);
|
|
295
297
|
if (world !== null) {
|
|
@@ -299,11 +301,18 @@ export async function runReleaseCommand(args, write, deps = {}) {
|
|
|
299
301
|
}
|
|
300
302
|
const outcome = await runRelease({ branch: version === undefined ? branch : releaseBranchFor(version), checkout, stateDir, limits, fresh: bare.has("--new"), noCarry: bare.has("--no-carry"),
|
|
301
303
|
...(version === undefined ? {} : { version, full: bare.has("--full") }) }, adapters);
|
|
302
|
-
|
|
304
|
+
if (deps.adapters === undefined)
|
|
305
|
+
next = deployedBuildToContinue(outcome, deps.database ?? databasePath(process.env, homedir()));
|
|
306
|
+
if (next === null)
|
|
307
|
+
return report(outcome, write, json, lines);
|
|
303
308
|
}
|
|
304
309
|
finally {
|
|
305
310
|
taken.release();
|
|
306
311
|
}
|
|
312
|
+
const bin = next;
|
|
313
|
+
if (!json)
|
|
314
|
+
write(` This build (database schema ${SCHEMA_VERSION}) can't open the database the deploy upgraded; the deployed build goes on: ${bin}`);
|
|
315
|
+
return continueWith(bin, args.filter(arg => arg !== "--new"), deps.cwd ?? process.cwd());
|
|
307
316
|
}
|
|
308
317
|
function report(outcome, write, json, lines) {
|
|
309
318
|
const release = outcome.journal === null ? null : {
|
|
@@ -662,3 +671,29 @@ async function runPrepareCommand(version, flags, write, json, deps) {
|
|
|
662
671
|
return answer(false, { reason: "refused", message: `The release pull request for ${version} wasn't opened: ${made.why}.` }, `The release pull request for ${version} wasn't opened: ${made.why}.`, 1);
|
|
663
672
|
return answer(true, { version, pullRequest: made.pr, branch: made.branch, commit: made.commit }, `Opened pull request #${made.pr} (${made.branch}): the version and changelog for ${version}. Merge it like any pull request once its checks pass, then run \`toolroll release ${version}\`.`, 0);
|
|
664
673
|
}
|
|
674
|
+
export function deployedBuildToContinue(outcome, database) {
|
|
675
|
+
const runtime = outcome.journal?.deploy?.runtime;
|
|
676
|
+
if (outcome.ok || runtime === undefined || outcome.step === "preflight" || RELEASE_STEPS.indexOf(outcome.step) <= RELEASE_STEPS.indexOf("link"))
|
|
677
|
+
return null;
|
|
678
|
+
const bin = join(runtime, "bin.js");
|
|
679
|
+
if (!existsSync(bin) || !existsSync(database))
|
|
680
|
+
return null;
|
|
681
|
+
try {
|
|
682
|
+
const db = new (sqlite().DatabaseSync)(database, { readOnly: true });
|
|
683
|
+
try {
|
|
684
|
+
const rows = db.prepare("SELECT typeof(version) AS kind, version FROM schema_version").all();
|
|
685
|
+
return rows.length === 1 && rows[0].kind === "integer" && Math.abs(Number(rows[0].version)) > SCHEMA_VERSION ? bin : null;
|
|
686
|
+
}
|
|
687
|
+
finally {
|
|
688
|
+
db.close();
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
catch {
|
|
692
|
+
return null;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
const continueWith = (bin, args, cwd) => new Promise(done => {
|
|
696
|
+
const child = spawn(process.execPath, [bin, "release", ...args], { cwd, stdio: "inherit", env: process.env });
|
|
697
|
+
child.on("error", () => done(3));
|
|
698
|
+
child.on("exit", code => done(code ?? 3));
|
|
699
|
+
});
|
package/dist/release.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isNewer } from "./releases.js";
|
|
1
2
|
import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
2
3
|
import { randomUUID } from "node:crypto";
|
|
3
4
|
import { dirname, join } from "node:path";
|
|
@@ -1258,7 +1259,7 @@ async function begin(options, adapters, now) {
|
|
|
1258
1259
|
const installed = await adapters.toolroll.installed();
|
|
1259
1260
|
const runtimes = new Set([...installed.services, ...installed.clis.map(one => one.runtime ?? "(not linked)")]);
|
|
1260
1261
|
if (installed.services.length === 0 || runtimes.size !== 1) {
|
|
1261
|
-
throw new Stop("mixed-runtime",
|
|
1262
|
+
throw new Stop("mixed-runtime", mixedRuntimeWords(installed));
|
|
1262
1263
|
}
|
|
1263
1264
|
const github = await adapters.repo.github();
|
|
1264
1265
|
await adapters.repo.sync(branch);
|
|
@@ -1313,7 +1314,7 @@ async function beginMain(options, adapters, now) {
|
|
|
1313
1314
|
const installed = await adapters.toolroll.installed();
|
|
1314
1315
|
const runtimes = new Set([...installed.services, ...installed.clis.map(one => one.runtime ?? "(not linked)")]);
|
|
1315
1316
|
if (installed.services.length === 0 || runtimes.size !== 1) {
|
|
1316
|
-
throw new Stop("mixed-runtime",
|
|
1317
|
+
throw new Stop("mixed-runtime", mixedRuntimeWords(installed));
|
|
1317
1318
|
}
|
|
1318
1319
|
const github = await adapters.repo.github();
|
|
1319
1320
|
const nothing = "Nothing was checked, deployed, tagged or published";
|
|
@@ -1596,3 +1597,13 @@ export function workflowIs(path, file) {
|
|
|
1596
1597
|
}
|
|
1597
1598
|
const RELEASE_WORDS = new Set(["status", "nightly", "carry", "revoke", "ask-every-commit", "unsandboxed-carry", "auto-approve", "publish-ok", "approve"]);
|
|
1598
1599
|
export function releaseBranchArg(branch) { return RELEASE_WORDS.has(branch) ? `--branch ${branch}` : branch; }
|
|
1600
|
+
export function mixedRuntimeWords(installed) {
|
|
1601
|
+
const version = (dist) => dist === null ? null : installed.versions?.[dist] ?? null;
|
|
1602
|
+
const named = (label, dist) => `${label} ${dist ?? "not linked"}${version(dist) === null ? "" : ` (${version(dist)})`}`;
|
|
1603
|
+
const list = [...installed.services.map(one => named("service", one)), ...installed.clis.map(one => named(one.name, one.runtime))].join("; ");
|
|
1604
|
+
const service = installed.services.map(version).find(one => one !== null) ?? null;
|
|
1605
|
+
const cli = installed.clis.map(one => version(one.runtime)).find(one => one !== null) ?? null;
|
|
1606
|
+
const newer = service !== null && cli !== null && isNewer(cli, service) ? ` \`toolroll\` is ${cli}, newer than the ${service} your service runs.` : "";
|
|
1607
|
+
const fix = installed.services.length === 0 ? " Update them to one verified build first." : " Run `toolroll update --yes` to bring them to one verified build, then release again.";
|
|
1608
|
+
return `The console, worker and CLI names don't run one build (${list}).${newer}${fix}`;
|
|
1609
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
import { ChatCore } from "./chat-core.js";
|
|
3
3
|
import { retireCompanionOnRestore } from "./companion/store.js";
|
|
4
|
+
import { cancelPhoneWork, PHONE_RESTORED } from "./companion/chat-origin.js";
|
|
4
5
|
import { CHAT_PROVIDERS } from "./contracts/chat-tables.js";
|
|
5
6
|
import { revokeCoordinator } from "./coordinator.js";
|
|
6
7
|
import { autoPublishHeld, holdAutoPublish, PUBLISH_ALLOWED_ACTION, PUBLISH_HELD_ACTION } from "./release-auto.js";
|
|
@@ -108,6 +109,7 @@ export function retireRestoredAuthority(store, options) {
|
|
|
108
109
|
for (const table of CHAT_DECIDE_TABLES)
|
|
109
110
|
store.handle.prepare(`UPDATE ${table} SET consumed_at = ? WHERE consumed_at IS NULL`).run(stamp);
|
|
110
111
|
store.handle.prepare("UPDATE chat_note_draft SET state = 'discarded' WHERE state IN ('pending', 'armed')").run();
|
|
112
|
+
cancelPhoneWork(store, { all: true }, PHONE_RESTORED, now);
|
|
111
113
|
retireCompanionOnRestore(store.handle);
|
|
112
114
|
const afterIdentity = store.workspaceIdentity();
|
|
113
115
|
if (afterIdentity.id !== identity.id || afterIdentity.recoveryGeneration !== nextGeneration || excluded.has(afterIdentity.recoveryGeneration)) {
|
|
@@ -132,7 +134,8 @@ export function retireRestoredAuthority(store, options) {
|
|
|
132
134
|
|| count(store, "SELECT count(*) AS n FROM chat_binding WHERE revoked IS NULL") !== 0
|
|
133
135
|
|| count(store, "SELECT count(*) AS n FROM chat_room WHERE revoked IS NULL") !== 0
|
|
134
136
|
|| count(store, "SELECT count(*) AS n FROM chat_pair WHERE consumed IS NULL") !== 0
|
|
135
|
-
|| openChatActions(store) !== 0
|
|
137
|
+
|| openChatActions(store) !== 0
|
|
138
|
+
|| count(store, "SELECT count(*) AS n FROM lead_queue WHERE origin = 'phone' AND status IN ('queued', 'running')") !== 0) {
|
|
136
139
|
throw new Error("Restored credential retirement postcondition failed");
|
|
137
140
|
}
|
|
138
141
|
return {
|
package/dist/result-review.js
CHANGED
|
@@ -97,9 +97,6 @@ export function evidenceProblemDetailsOf(input) {
|
|
|
97
97
|
missing("The no-change conclusion has no handoff record.");
|
|
98
98
|
return problems;
|
|
99
99
|
}
|
|
100
|
-
export function evidenceProblemsOf(input) {
|
|
101
|
-
return evidenceProblemDetailsOf(input).map(one => one.words);
|
|
102
|
-
}
|
|
103
100
|
export function evidenceHealthOf(problems) {
|
|
104
101
|
const health = { damaged: 0, shortened: 0, missing: 0 };
|
|
105
102
|
for (const one of problems)
|
package/dist/retention-ui.js
CHANGED
|
@@ -7,7 +7,7 @@ export const RETENTION_CSS = "";
|
|
|
7
7
|
const listWords = (parts) => parts.length < 2 ? parts.join("") : `${parts.slice(0, -1).join(", ")} and ${parts.at(-1)}`;
|
|
8
8
|
function nextWords(view) {
|
|
9
9
|
if (RETENTION_KINDS.every(({ kind }) => view.periods[kind] === null))
|
|
10
|
-
return "
|
|
10
|
+
return "Only settled progress updates and undeliverable old delivery records go (after 30 days); everything else is kept forever.";
|
|
11
11
|
const due = view.next.filter(one => one.count > 0);
|
|
12
12
|
if (due.length === 0)
|
|
13
13
|
return "Nothing is old enough to remove yet.";
|
package/dist/retention.js
CHANGED
|
@@ -2,7 +2,8 @@ import { reclaimDatabase } from "./database-reclaim.js";
|
|
|
2
2
|
import { existsSync, lstatSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { RETENTION_NOTE } from "./evidence.js";
|
|
5
|
-
import {
|
|
5
|
+
import { finishedTask } from "./finished-task-sql.js";
|
|
6
|
+
import { lifecycleWords, NOTIFICATION_RETENTION_WORDS, sweepNotificationLifecycle, UNDER_LIFECYCLE_KEY } from "./notification-retention.js";
|
|
6
7
|
import { bytesWords, treeBytes } from "./storage.js";
|
|
7
8
|
import { RETENTION_DAYS, retentionDaysSchema, retentionKindSchema } from "./contracts/retention.js";
|
|
8
9
|
const KEPT_QUEUE_ROW = (message) => `lead_queue lq WHERE lq.message = ${message}
|
|
@@ -38,7 +39,7 @@ export const RETENTION_KINDS = [
|
|
|
38
39
|
{ kind: "evidence", label: "Run evidence and logs", detail: "Diffs, check logs, screenshots and reports saved for each run" },
|
|
39
40
|
{ kind: "checkouts", label: "Finished checkout records", detail: "Records of build checkouts that were let go and are no longer on disk" },
|
|
40
41
|
{ kind: "chat", label: "Chat messages", detail: "Messages in lead and team chats" },
|
|
41
|
-
{ kind: "notifications", label: "Notifications", detail:
|
|
42
|
+
{ kind: "notifications", label: "Notifications", detail: `Resolved notifications. ${NOTIFICATION_RETENTION_WORDS}` },
|
|
42
43
|
];
|
|
43
44
|
const LONG_CHOICES = [30, 90, 180, 365, 730, null];
|
|
44
45
|
export const PERIOD_CHOICES = {
|
|
@@ -82,19 +83,6 @@ export function periodLabel(kind, days, chosen) {
|
|
|
82
83
|
return `${label} (default)`;
|
|
83
84
|
return PERIOD_CHOICES[kind].includes(days) ? label : `${label} (custom)`;
|
|
84
85
|
}
|
|
85
|
-
function finishedTask(r) {
|
|
86
|
-
return `EXISTS (SELECT 1 FROM task t WHERE t.id = ${r}.external_id AND ${r}.backend = 'built-in' AND (t.state = 'cancelled' OR (t.state = 'done' AND EXISTS (
|
|
87
|
-
SELECT 1 FROM action_ledger a WHERE a.action = '${COMPLETION_ACTION}' AND (a.task_id = ${r}.external_id OR a.run_id IN (SELECT id FROM run WHERE task_ref = ${r}.id))))))
|
|
88
|
-
AND NOT EXISTS (SELECT 1 FROM hold h WHERE h.task_ref = ${r}.id)
|
|
89
|
-
AND NOT EXISTS (SELECT 1 FROM run live WHERE live.task_ref = ${r}.id AND live.finished_at IS NULL)
|
|
90
|
-
AND NOT EXISTS (SELECT 1 FROM task_scope s WHERE s.task_id = ${r}.external_id AND s.candidate IS NOT NULL)
|
|
91
|
-
AND NOT EXISTS (WITH RECURSIVE family(ext) AS (
|
|
92
|
-
SELECT rv.external_id FROM task_ref rv WHERE rv.revision_of = ${r}.external_id
|
|
93
|
-
UNION SELECT rv.external_id FROM task_ref rv JOIN family ON rv.revision_of = family.ext)
|
|
94
|
-
SELECT 1 FROM family JOIN task tv ON tv.id = family.ext
|
|
95
|
-
WHERE NOT (tv.state = 'cancelled' OR (tv.state = 'done' AND EXISTS (SELECT 1 FROM action_ledger a WHERE a.action = '${COMPLETION_ACTION}'
|
|
96
|
-
AND (a.task_id = family.ext OR a.run_id IN (SELECT run.id FROM run JOIN task_ref x ON x.id = run.task_ref WHERE x.external_id = family.ext))))))`;
|
|
97
|
-
}
|
|
98
86
|
function cutoff(now, days) {
|
|
99
87
|
return new Date(now.getTime() - days * DAY_MS).toISOString();
|
|
100
88
|
}
|
|
@@ -153,7 +141,7 @@ export function retentionPlan(store, evidenceRoot, now, periods = store.retentio
|
|
|
153
141
|
}
|
|
154
142
|
if (periods.notifications !== null) {
|
|
155
143
|
const rows = db.prepare(`SELECT n.id AS id, length(n.subject) + length(n.body) + 64 AS bytes FROM notification n
|
|
156
|
-
WHERE n.created_at < ? AND n.resolved_at IS NOT NULL
|
|
144
|
+
WHERE n.created_at < ? AND n.resolved_at IS NOT NULL AND NOT ${UNDER_LIFECYCLE_KEY("n")}
|
|
157
145
|
AND NOT EXISTS (SELECT 1 FROM notification_delivery d WHERE d.notification = n.id AND d.claim_owner IS NOT NULL AND d.claim_expires_at > ?)
|
|
158
146
|
AND NOT (n.resolved_at IS NULL AND n.task_ref IS NOT NULL AND NOT EXISTS (SELECT 1 FROM task_ref r WHERE r.id = n.task_ref AND ${finishedTask("r")}))
|
|
159
147
|
ORDER BY n.id LIMIT ?`).all(cutoff(now, periods.notifications), now.toISOString(), SWEEP_BATCH + 1);
|
|
@@ -176,8 +164,10 @@ function folderBytes(dir) {
|
|
|
176
164
|
export function sweepRetention(store, evidenceRoot, now, actor = "worker") {
|
|
177
165
|
const periods = store.retentionPeriods();
|
|
178
166
|
store.setServiceCursor(SWEEP_CURSOR, now.getTime(), now);
|
|
179
|
-
|
|
180
|
-
|
|
167
|
+
const lifecycle = sweepNotificationLifecycle(store, now);
|
|
168
|
+
const lifecycleDid = lifecycle.settled + lifecycle.pings + lifecycle.legacyCleared + lifecycle.deferred.families > 0;
|
|
169
|
+
if (!lifecycleDid && RETENTION_KINDS.every(({ kind }) => periods[kind] === null))
|
|
170
|
+
return { at: now.toISOString(), counts: [], freed: 0, ledgerId: null, lifecycle };
|
|
181
171
|
const plan = retentionPlan(store, evidenceRoot, now, periods);
|
|
182
172
|
const db = store.handle;
|
|
183
173
|
const done = { evidence: { count: 0, bytes: 0 }, checkouts: { count: 0, bytes: 0 }, chat: { count: 0, bytes: 0 }, notifications: { count: 0, bytes: 0 } };
|
|
@@ -262,10 +252,13 @@ export function sweepRetention(store, evidenceRoot, now, actor = "worker") {
|
|
|
262
252
|
}
|
|
263
253
|
});
|
|
264
254
|
const counts = plan.counts.map(one => ({ ...one, count: done[one.kind].count, bytes: done[one.kind].bytes }));
|
|
265
|
-
const freed = counts.reduce((sum, one) => sum + one.bytes, 0);
|
|
266
|
-
const
|
|
255
|
+
const freed = counts.reduce((sum, one) => sum + one.bytes, 0) + lifecycle.bytes;
|
|
256
|
+
const removed = freed > 0 || counts.some(one => one.count > 0) || lifecycle.pings + lifecycle.legacyCleared > 0;
|
|
257
|
+
const what = [counts.filter(one => one.count > 0).map(countWords).join(", "), lifecycleWords(lifecycle)].filter(Boolean).join("; ");
|
|
258
|
+
const detail = what === "" ? "nothing was due" : freed > 0 ? `${what}; about ${bytesWords(freed)} freed` : what;
|
|
259
|
+
const ledgerId = store.recordAction({ at: now.toISOString(), actor, repo: null, taskId: null, runId: null, action: "retention sweep", outcome: removed ? "removed" : lifecycle.settled > 0 ? "changed" : "nothing due", source: "policy", detail });
|
|
267
260
|
reclaimDatabase(store.handle, "retention");
|
|
268
|
-
return { at: now.toISOString(), counts, freed, ledgerId };
|
|
261
|
+
return { at: now.toISOString(), counts, freed, ledgerId, lifecycle };
|
|
269
262
|
}
|
|
270
263
|
export function retentionDue(store, now) {
|
|
271
264
|
return now.getTime() - store.serviceCursor(SWEEP_CURSOR) >= SWEEP_EVERY_MS;
|