toolroll 0.9.118 → 0.9.120

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.
Files changed (75) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +22 -22
  3. package/dist/assignment.js +43 -30
  4. package/dist/browser/workspace.css +1 -1
  5. package/dist/browser/workspace.js +32 -31
  6. package/dist/builder.js +288 -237
  7. package/dist/central-recovery-stage.js +3 -3
  8. package/dist/check-failure.js +2 -2
  9. package/dist/check-levels.js +3 -0
  10. package/dist/check-report.js +58 -7
  11. package/dist/cli-help.js +1 -0
  12. package/dist/codex-limits.js +40 -22
  13. package/dist/contracts/console-api.js +6 -1
  14. package/dist/contracts/engine-api.js +1 -0
  15. package/dist/contracts/release-check.js +7 -4
  16. package/dist/contracts/release-terms.js +11 -2
  17. package/dist/contracts/verification-receipt.js +1 -1
  18. package/dist/deploy-gate.js +7 -1
  19. package/dist/direct-chat.js +3 -3
  20. package/dist/easy-start.js +8 -6
  21. package/dist/engine-reads.js +74 -0
  22. package/dist/flexible-conversation-schema.js +24 -0
  23. package/dist/flexible-conversation.js +162 -0
  24. package/dist/flexible-custody.js +3 -0
  25. package/dist/flexible-import.js +89 -0
  26. package/dist/flexible-save.js +128 -0
  27. package/dist/flexible-session.js +93 -13
  28. package/dist/flexible-ship.js +3 -3
  29. package/dist/flexible-thread.js +2 -2
  30. package/dist/install-mode.js +1 -1
  31. package/dist/local-checks.js +32 -0
  32. package/dist/local-landing.js +758 -0
  33. package/dist/local-owner.js +3 -0
  34. package/dist/operate.js +165 -26
  35. package/dist/passwordless.js +1 -1
  36. package/dist/plan-limits-demand.js +48 -0
  37. package/dist/project-delete.js +1 -0
  38. package/dist/rehearsal.js +27 -0
  39. package/dist/release-adapters.js +170 -2
  40. package/dist/release-approval.js +11 -8
  41. package/dist/release-card.js +7 -2
  42. package/dist/release-carry.js +1 -1
  43. package/dist/release-cli.js +115 -14
  44. package/dist/release-main-proof.js +49 -0
  45. package/dist/release-main.js +110 -0
  46. package/dist/release-recheck.js +10 -3
  47. package/dist/release.js +221 -33
  48. package/dist/reply-shape.js +6 -1
  49. package/dist/result-actions.js +7 -1
  50. package/dist/result-follow-ups.js +30 -12
  51. package/dist/review-context.js +2 -1
  52. package/dist/serve.js +31 -14
  53. package/dist/server/direct-chat.js +109 -3
  54. package/dist/server/engine-api.js +65 -6
  55. package/dist/server/render-results.js +8 -4
  56. package/dist/server/render-tasks.js +10 -1
  57. package/dist/server/route-table.js +15 -1
  58. package/dist/server/send-back-build.js +4 -0
  59. package/dist/server/settings.js +33 -7
  60. package/dist/server/task-views.js +20 -0
  61. package/dist/server/tasks.js +108 -6
  62. package/dist/settings-groups-ui.js +3 -3
  63. package/dist/store.js +29 -4
  64. package/dist/subscription-usage.js +11 -5
  65. package/dist/surface.js +11 -2
  66. package/dist/task-base.js +23 -4
  67. package/dist/task-outcome-cli.js +10 -1
  68. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  69. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  70. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  71. package/dist/tui/linux-x64/toolroll-tui +0 -0
  72. package/dist/verification-evidence.js +20 -7
  73. package/dist/workspace-ui.js +1 -1
  74. package/package.json +2 -1
  75. package/scripts/release-proof.mjs +240 -0
package/dist/builder.js CHANGED
@@ -4,6 +4,7 @@ import { agentSaidTail } from "./agent-said.js";
4
4
  import { CHECK_ACCESS_DEFAULT, checkAccessHere, checkNetworkOf, localModeCap } from "./check-access.js";
5
5
  import { localModeOn } from "./local-owner.js";
6
6
  import { checkoutGit, refusal as gitRefusal } from "./teardown-git.js";
7
+ import { wholeChangeBaseOf } from "./task-base.js";
7
8
  import { isAcpProvider } from "./acp-agents.js";
8
9
  import { OBSERVATION_MAILBOX, observationBrief, parseObservationCases, collectObservations } from "./observations.js";
9
10
  import { checkCommandFor, effectiveCheckLevel, recordRunCheckLevel } from "./check-levels.js";
@@ -16,14 +17,15 @@ import { CHECK_INVENTORY_CAPTURE, CHECK_REPORT_CAPTURE, CheckBaselineUnverifiabl
16
17
  import { CHECK_LOAD_CAPTURE, CheckLoadWatch } from "./check-load.js";
17
18
  import { NOTHING_STARTED_ACTION, retriedInside } from "./check-failure.js";
18
19
  import { planTargetedRecheck, settleCoverage } from "./release-recheck.js";
19
- import { effectiveCheckFacts } from "./verification-evidence.js";
20
+ import { coveragePasses, effectiveCheckFacts } from "./verification-evidence.js";
20
21
  import { learningContext } from "./project-learning.js";
21
22
  import { knowledgeContext } from "./project-knowledge.js";
22
23
  import { flowGoalCuts } from "./flow-engine.js";
23
24
  import { readCodingHandoff, verifyCodingHandoffBase } from "./coding-handoff.js";
24
25
  import { PREPARED_EVIDENCE_FILE, preparedEvidenceGit, preparedScreenshotMatches, readPreparedEvidence, writePreparedEvidence } from "./prepared-evidence.js";
25
- import { accessSync, constants as fsConstants, existsSync, realpathSync, statSync, unlinkSync, writeFileSync } from "node:fs";
26
- import { homedir } from "node:os";
26
+ import { accessSync, chmodSync, constants as fsConstants, existsSync, mkdtempSync, realpathSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
27
+ import { homedir, tmpdir } from "node:os";
28
+ import { purposeCheckMode } from "./contracts/release-terms.js";
27
29
  import { delimiter, isAbsolute, join, resolve } from "node:path";
28
30
  import { run, runClaudeStreamJsonl, runOwnerTag, streamsInput } from "./exec.js";
29
31
  import { stopRequestedFor, stopWords, underStopWatch } from "./task-control.js";
@@ -1291,7 +1293,7 @@ export async function settleProviderOutcome(captured, result) {
1291
1293
  .filter(line => line.trim() !== "" &&
1292
1294
  !line.trimEnd().endsWith(LEASE_MARKER) &&
1293
1295
  !(line.startsWith("?? ") && looksLikeProtocolFile(line.slice(3))));
1294
- const pinnedBase = store.firstBuilderBase(taskRef, branch) ?? baseRevision;
1296
+ const pinnedBase = wholeChangeBaseOf(store, taskRef, branch) ?? baseRevision;
1295
1297
  if (handoff.status === "no-change") {
1296
1298
  if (dirty.length > 0) {
1297
1299
  return {
@@ -1630,6 +1632,8 @@ async function settleProof(captured, statArtifactId, sealedHead) {
1630
1632
  const gateCommand = batched ? null : configured;
1631
1633
  let verifyCommand;
1632
1634
  let checkAttempt = null;
1635
+ let deployCopyDir = null;
1636
+ let deployCleanupProblem = null;
1633
1637
  let loadWatch = null;
1634
1638
  let releaseFacts = null;
1635
1639
  const verification = { last: null };
@@ -1680,186 +1684,92 @@ async function settleProof(captured, statArtifactId, sealedHead) {
1680
1684
  recordCheckNote("Verification did not start: this worker no longer owned the build.");
1681
1685
  }
1682
1686
  else {
1683
- const verifyRunner = request.verify ?? run;
1684
- const verifyShell = approvedCommandShell(configured.command);
1685
- let baselineUnverifiable = null;
1686
- if (repo !== null && chosenCheck?.level === "full" && (store.getScope(request.taskId)?.candidate ?? null) !== null) {
1687
- const access = checkLaunchOf(store, runId, captured.effective.profile).access;
1688
- const decision = planTargetedRecheck(store, root, { runId, taskId: request.taskId, repo, head: sealedHead, command: configured, access, now: now() });
1689
- const release = decision.authority !== null || releaseCheckScope(store.getScope(request.taskId));
1690
- loadWatch = new CheckLoadWatch(configured.timeoutMs, request.machine === undefined ? {} : { sample: request.machine });
1687
+ const removeDeployCopy = () => {
1688
+ if (deployCopyDir === null)
1689
+ return;
1690
+ const dir = deployCopyDir;
1691
+ deployCopyDir = null;
1691
1692
  try {
1692
- checkAttempt = prepareCheckAttempt(store, root, { runId, repo, head: sealedHead, command: configured, access, authority: decision.authority, limitMs: loadWatch?.limitMs,
1693
- ...(decision.mode === "targeted" ? { plan: decision.plan, snapshot: decision.snapshot } : {}), watch: decision.watch, release,
1694
- learn: learnRequestFor(store, repo, now(), runId).learn }, now());
1693
+ rmSync(dir, { recursive: true, force: true });
1695
1694
  }
1696
1695
  catch (error) {
1697
- if (!(error instanceof CheckBaselineUnverifiable))
1698
- throw error;
1699
- checkAttempt = null;
1700
- baselineUnverifiable = error.message;
1701
- recordCheckNote(error.message);
1702
- }
1703
- if (checkAttempt === null && loadWatch !== null) {
1704
- loadWatch.finish();
1705
- loadWatch = null;
1696
+ deployCleanupProblem = `its copy of this computer's database couldn't be deleted (${error instanceof Error ? error.message : String(error)})`;
1706
1697
  }
1707
- if (loadWatch !== null && loadWatch.limitMs !== configured.timeoutMs)
1708
- store.addRunNote(runId, "Toolroll", `The release check's time limit: ${loadWatch.why}.`, now());
1709
- if (checkAttempt !== null && decision.mode === "targeted")
1710
- store.addRunNote(runId, "Toolroll", `Re-running only what failed at run #${decision.plan.base}: ${decision.plan.units.length} unit files, ${decision.plan.groups.reduce((n, one) => n + one.groups.length, 0)} journey groups, ${decision.plan.versions.length} upgrade versions${decision.plan.parts.length > 0 ? `, and in full: ${decision.plan.parts.join(", ")}` : ""}.`, now());
1711
- }
1712
- else
1713
- checkAttempt = null;
1714
- const progressWrites = coalescedProgressWriter(snapshot => { store.saveCheckProgress(runId, snapshot, now()); });
1715
- const checkProgress = new CheckProgressTracker(snapshot => progressWrites.push(snapshot));
1716
- const runVerification = async (label, missing = null) => {
1717
- const streamed = { stdout: false, stderr: false };
1718
- if (missing === null)
1719
- checkConditions.last = captureCheckConditions({ repo, head: sealedHead, command: configured, access: checkLaunchOf(store, runId, captured.effective.profile).access, envNames: SETUP_ENV_ALLOWLIST });
1720
- const result = missing !== null
1721
- ? { code: 127, stdout: "", stderr: `Toolroll did not start the check: ${missing} wasn't found.`, timedOut: false, notFound: false }
1722
- : await underStopWatch(store, runId, () => {
1723
- loadWatch?.attemptStarted();
1724
- return runWithIsolatedDatabase(witnessedRunner(store, runId, now, commandRunner(store, runId, captured.effective.profile, verifyRunner)), verifyShell.file, verifyShell.args, {
1725
- cwd: worktree,
1726
- timeoutMs: loadWatch?.limitMs ?? configured.timeoutMs,
1727
- processGroup: true,
1728
- owner: runOwnerTag(store, runId),
1729
- beforeSpawn: () => !stopRequestedFor(store, runId, request.shouldStop),
1730
- onSpawn: pid => {
1731
- request.onProviderSpawn?.(pid);
1732
- if (stopRequestedFor(store, runId, request.shouldStop))
1733
- throw new Error("the attempt was stopped before spawn custody completed");
1734
- },
1735
- envAllowlist: SETUP_ENV_ALLOWLIST,
1736
- omitEnv: SETUP_ENV_DENYLIST,
1737
- ...(checkAttempt === null ? {} : { stdin: checkAttempt.stdin }),
1738
- onStdout: chunk => { streamed.stdout = true; checkProgress.feed(chunk, "stdout"); },
1739
- onStderr: chunk => { streamed.stderr = true; checkProgress.feed(chunk, "stderr"); },
1740
- }).finally(() => loadWatch?.attemptEnded());
1741
- });
1742
- if (missing !== null)
1743
- unstartedChecks.set(result, missing);
1744
- if (!streamed.stdout)
1745
- checkProgress.feed(result.stdout, "stdout");
1746
- if (!streamed.stderr)
1747
- checkProgress.feed(result.stderr, "stderr");
1748
- checkProgress.feed("\n", "stdout");
1749
- checkProgress.feed("\n", "stderr");
1750
- checkOutcomes.push(attemptOutcome(label, result));
1751
- noteCheckSuite(label, result);
1752
- checkLog.push(attemptLog(label, configured.command, result));
1753
- verification.last = result;
1754
- return result;
1698
+ if (deployCleanupProblem === null && existsSync(dir))
1699
+ deployCleanupProblem = `its copy of this computer's database is still at ${dir}`;
1700
+ if (deployCleanupProblem !== null)
1701
+ recordCheckNote(`The deploy check has no result: ${deployCleanupProblem}.`);
1755
1702
  };
1756
- const ownInstallIfChanged = async () => {
1757
- const depsRoot = sharedDepsRootOf(store);
1758
- if (depsRoot === null || repo === null)
1759
- return null;
1760
- const linked = linkedKey(worktree, depsRoot);
1761
- const live = linked === null ? null : store.liveWorktreeSetup(repo);
1762
- if (linked === null || live === null)
1763
- return null;
1764
- if (sharingFor({ repo, worktree, setup: live, root: depsRoot })?.key === linked && readyCopy(depsRoot, linked) !== null)
1765
- return null;
1766
- if (!store.proveRunnerCustodyForSpawn(runId, now()))
1767
- return "custody-lost";
1768
- detachShared(worktree, depsRoot);
1769
- const label = "Own install · approved project setup (package.json or lockfile changed)";
1770
- const setupShell = approvedCommandShell(live.command);
1771
- const installed = await underStopWatch(store, runId, () => runWithIsolatedDatabase(witnessedRunner(store, runId, now, commandRunner(store, runId, captured.effective.profile, request.setup ?? run)), setupShell.file, setupShell.args, {
1772
- cwd: worktree,
1773
- timeoutMs: live.timeoutMs,
1774
- processGroup: true,
1775
- owner: runOwnerTag(store, runId),
1776
- beforeSpawn: () => !stopRequestedFor(store, runId, request.shouldStop),
1777
- onSpawn: pid => {
1778
- request.onProviderSpawn?.(pid);
1779
- if (stopRequestedFor(store, runId, request.shouldStop))
1780
- throw new Error("the attempt was stopped before spawn custody completed");
1781
- },
1782
- envAllowlist: SETUP_ENV_ALLOWLIST,
1783
- omitEnv: SETUP_ENV_DENYLIST,
1784
- }));
1785
- checkOutcomes.push(attemptOutcome(label, installed));
1786
- noteCheckSuite(label, installed);
1787
- checkLog.push(attemptLog(label, live.command, installed));
1788
- if (installed.notFound || installed.timedOut || installed.code !== 0)
1789
- return "own-install-failed";
1790
- return await sealedTreeState(buildCheckoutGit(request.git ?? run, worktree)) === "clean" ? null : "setup-changed-files";
1791
- };
1792
- const ownInstall = baselineUnverifiable === null ? await ownInstallIfChanged() : null;
1793
- const missingProgram = configured.recoverySetupDigest === null ? null : approvedProgramMissing(configured.command, worktree, process.env["PATH"]);
1794
- const first = baselineUnverifiable === null && ownInstall === null ? await runVerification("Project check · attempt 1", missingProgram) : null;
1795
- if (first === null) {
1796
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: baselineUnverifiable !== null ? "baseline-unverifiable" : ownInstall ?? "own-install-failed" };
1797
- }
1798
- else if (first.notFound || first.timedOut) {
1799
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: first.timedOut ? "timed-out" : "spawn-failed" };
1800
- }
1801
- else if (first.stoppedByPlane === true) {
1802
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "stopped-by-toolroll" };
1803
- }
1804
- else if (!launchFailedBeforeCheck(first, checkAttempt?.nonce ?? null, missingProgram)) {
1805
- verifyCommand = { configured: true, ran: true, exitCode: first.code };
1806
- }
1807
- else {
1808
- const recoveryDigest = configured.recoverySetupDigest;
1809
- const liveRecoverySetup = () => {
1810
- if (repo === null || recoveryDigest === null)
1811
- return null;
1812
- const liveVerify = store.liveVerifyCommand(configured.repo);
1813
- const liveSetup = store.liveWorktreeSetup(repo);
1814
- return liveVerify !== null &&
1815
- liveVerify.digest === configured.digest &&
1816
- liveVerify.recoverySetupDigest === recoveryDigest &&
1817
- liveSetup !== null &&
1818
- liveSetup.digest === recoveryDigest
1819
- ? liveSetup
1820
- : null;
1821
- };
1822
- const setup = liveRecoverySetup();
1823
- if (recoveryDigest === null) {
1824
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "dependency-missing" };
1825
- }
1826
- else if (setup === null || setup.digest !== recoveryDigest) {
1827
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "setup-stale" };
1828
- }
1829
- else if (!store.proveRunnerCustodyForSpawn(runId, now())) {
1830
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "custody-lost" };
1703
+ try {
1704
+ const verifyRunner = request.verify ?? run;
1705
+ const verifyShell = approvedCommandShell(configured.command);
1706
+ let baselineUnverifiable = null;
1707
+ const deployCheck = repo !== null && chosenCheck?.level === "full" && purposeCheckMode(store.getScope(request.taskId)?.releaseCheck) === "deploy";
1708
+ if (deployCheck) {
1709
+ const access = checkLaunchOf(store, runId, captured.effective.profile).access;
1710
+ loadWatch = new CheckLoadWatch(configured.timeoutMs, request.machine === undefined ? {} : { sample: request.machine });
1711
+ try {
1712
+ const live = store.databaseFile();
1713
+ if (live === null)
1714
+ throw new Error("this plane's database has no file to copy");
1715
+ deployCopyDir = mkdtempSync(join(realpathSync(tmpdir()), "toolroll-deploy-check-"));
1716
+ chmodSync(deployCopyDir, 0o700);
1717
+ const copy = join(deployCopyDir, "orders.db");
1718
+ await (await import("./backup.js")).onlineCopy(live, copy);
1719
+ checkAttempt = prepareCheckAttempt(store, root, { runId, repo: repo, head: sealedHead, command: configured, access, authority: null, watch: [], release: true, limitMs: loadWatch.limitMs, deploy: { copy } }, now());
1720
+ if (checkAttempt === null)
1721
+ throw new Error("the release commit couldn't be read, so the deploy check couldn't be sealed");
1722
+ store.addRunNote(runId, "Toolroll", "The deploy check: build this commit, upgrade a copy of this computer's database with it and start it against that copy.", now());
1723
+ }
1724
+ catch (error) {
1725
+ checkAttempt = null;
1726
+ baselineUnverifiable = `The deploy check couldn't be prepared: ${error instanceof Error ? error.message : String(error)}.`;
1727
+ recordCheckNote(baselineUnverifiable);
1728
+ loadWatch.finish();
1729
+ loadWatch = null;
1730
+ }
1831
1731
  }
1832
- else {
1833
- const gitRunner = buildCheckoutGit(request.git ?? run, worktree);
1834
- const beforeSetup = await sealedTreeState(gitRunner);
1835
- if (beforeSetup === "head-moved") {
1836
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "checkout-moved" };
1837
- recordCheckNote("Automatic recovery stopped before setup because HEAD no longer matched the built commit.");
1732
+ else if (repo !== null && chosenCheck?.level === "full" && (store.getScope(request.taskId)?.candidate ?? null) !== null) {
1733
+ const access = checkLaunchOf(store, runId, captured.effective.profile).access;
1734
+ const decision = planTargetedRecheck(store, root, { runId, taskId: request.taskId, repo, head: sealedHead, command: configured, access, now: now() });
1735
+ const release = decision.authority !== null || releaseCheckScope(store.getScope(request.taskId));
1736
+ loadWatch = new CheckLoadWatch(configured.timeoutMs, request.machine === undefined ? {} : { sample: request.machine });
1737
+ try {
1738
+ checkAttempt = prepareCheckAttempt(store, root, { runId, repo, head: sealedHead, command: configured, access, authority: decision.authority, limitMs: loadWatch?.limitMs,
1739
+ ...(decision.mode === "targeted" ? { plan: decision.plan, snapshot: decision.snapshot } : {}), watch: decision.watch, release,
1740
+ learn: learnRequestFor(store, repo, now(), runId).learn }, now());
1838
1741
  }
1839
- else if (beforeSetup === "unavailable") {
1840
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "cleanliness-unavailable" };
1841
- recordCheckNote("Automatic recovery stopped before setup because checkout cleanliness could not be confirmed.");
1742
+ catch (error) {
1743
+ if (!(error instanceof CheckBaselineUnverifiable))
1744
+ throw error;
1745
+ checkAttempt = null;
1746
+ baselineUnverifiable = error.message;
1747
+ recordCheckNote(error.message);
1842
1748
  }
1843
- else if (beforeSetup === "changed") {
1844
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "tracked-files-changed" };
1845
- recordCheckNote("Automatic recovery stopped before setup because tracked files no longer matched the built commit.");
1749
+ if (checkAttempt === null && loadWatch !== null) {
1750
+ loadWatch.finish();
1751
+ loadWatch = null;
1846
1752
  }
1847
- else {
1848
- const liveBeforeSetup = liveRecoverySetup();
1849
- if (liveBeforeSetup === null) {
1850
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "setup-stale" };
1851
- recordCheckNote("Automatic recovery stopped before setup because its approval changed.");
1852
- }
1853
- else if (!store.proveRunnerCustodyForSpawn(runId, now())) {
1854
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "custody-lost" };
1855
- recordCheckNote("Automatic recovery stopped before setup: this worker no longer owned the build.");
1856
- }
1857
- else {
1858
- const setupRunner = request.setup ?? run;
1859
- const setupShell = approvedCommandShell(liveBeforeSetup.command);
1860
- const restored = await underStopWatch(store, runId, () => runWithIsolatedDatabase(witnessedRunner(store, runId, now, commandRunner(store, runId, captured.effective.profile, setupRunner)), setupShell.file, setupShell.args, {
1753
+ if (loadWatch !== null && loadWatch.limitMs !== configured.timeoutMs)
1754
+ store.addRunNote(runId, "Toolroll", `The release check's time limit: ${loadWatch.why}.`, now());
1755
+ if (checkAttempt !== null && decision.mode === "targeted")
1756
+ store.addRunNote(runId, "Toolroll", `Re-running only what failed at run #${decision.plan.base}: ${decision.plan.units.length} unit files, ${decision.plan.groups.reduce((n, one) => n + one.groups.length, 0)} journey groups, ${decision.plan.versions.length} upgrade versions${decision.plan.parts.length > 0 ? `, and in full: ${decision.plan.parts.join(", ")}` : ""}.`, now());
1757
+ }
1758
+ else
1759
+ checkAttempt = null;
1760
+ const progressWrites = coalescedProgressWriter(snapshot => { store.saveCheckProgress(runId, snapshot, now()); });
1761
+ const checkProgress = new CheckProgressTracker(snapshot => progressWrites.push(snapshot));
1762
+ const runVerification = async (label, missing = null) => {
1763
+ const streamed = { stdout: false, stderr: false };
1764
+ if (missing === null)
1765
+ checkConditions.last = captureCheckConditions({ repo, head: sealedHead, command: configured, access: checkLaunchOf(store, runId, captured.effective.profile).access, envNames: SETUP_ENV_ALLOWLIST });
1766
+ const result = missing !== null
1767
+ ? { code: 127, stdout: "", stderr: `Toolroll did not start the check: ${missing} wasn't found.`, timedOut: false, notFound: false }
1768
+ : await underStopWatch(store, runId, () => {
1769
+ loadWatch?.attemptStarted();
1770
+ return runWithIsolatedDatabase(witnessedRunner(store, runId, now, commandRunner(store, runId, captured.effective.profile, verifyRunner)), verifyShell.file, verifyShell.args, {
1861
1771
  cwd: worktree,
1862
- timeoutMs: liveBeforeSetup.timeoutMs,
1772
+ timeoutMs: loadWatch?.limitMs ?? configured.timeoutMs,
1863
1773
  processGroup: true,
1864
1774
  owner: runOwnerTag(store, runId),
1865
1775
  beforeSpawn: () => !stopRequestedFor(store, runId, request.shouldStop),
@@ -1870,86 +1780,227 @@ async function settleProof(captured, statArtifactId, sealedHead) {
1870
1780
  },
1871
1781
  envAllowlist: SETUP_ENV_ALLOWLIST,
1872
1782
  omitEnv: SETUP_ENV_DENYLIST,
1873
- }));
1874
- checkOutcomes.push(attemptOutcome("Automatic recovery · approved project setup", restored));
1875
- noteCheckSuite("Automatic recovery · approved project setup", restored);
1876
- checkLog.push(attemptLog("Automatic recovery · approved project setup", liveBeforeSetup.command, restored));
1877
- if (restored.notFound || restored.timedOut || restored.code !== 0) {
1878
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "setup-failed" };
1783
+ ...(checkAttempt === null ? {} : { stdin: checkAttempt.stdin }),
1784
+ onStdout: chunk => { streamed.stdout = true; checkProgress.feed(chunk, "stdout"); },
1785
+ onStderr: chunk => { streamed.stderr = true; checkProgress.feed(chunk, "stderr"); },
1786
+ }).finally(() => loadWatch?.attemptEnded());
1787
+ });
1788
+ if (missing !== null)
1789
+ unstartedChecks.set(result, missing);
1790
+ if (!streamed.stdout)
1791
+ checkProgress.feed(result.stdout, "stdout");
1792
+ if (!streamed.stderr)
1793
+ checkProgress.feed(result.stderr, "stderr");
1794
+ checkProgress.feed("\n", "stdout");
1795
+ checkProgress.feed("\n", "stderr");
1796
+ checkOutcomes.push(attemptOutcome(label, result));
1797
+ noteCheckSuite(label, result);
1798
+ checkLog.push(attemptLog(label, configured.command, result));
1799
+ verification.last = result;
1800
+ return result;
1801
+ };
1802
+ const ownInstallIfChanged = async () => {
1803
+ const depsRoot = sharedDepsRootOf(store);
1804
+ if (depsRoot === null || repo === null)
1805
+ return null;
1806
+ const linked = linkedKey(worktree, depsRoot);
1807
+ const live = linked === null ? null : store.liveWorktreeSetup(repo);
1808
+ if (linked === null || live === null)
1809
+ return null;
1810
+ if (sharingFor({ repo, worktree, setup: live, root: depsRoot })?.key === linked && readyCopy(depsRoot, linked) !== null)
1811
+ return null;
1812
+ if (!store.proveRunnerCustodyForSpawn(runId, now()))
1813
+ return "custody-lost";
1814
+ detachShared(worktree, depsRoot);
1815
+ const label = "Own install · approved project setup (package.json or lockfile changed)";
1816
+ const setupShell = approvedCommandShell(live.command);
1817
+ const installed = await underStopWatch(store, runId, () => runWithIsolatedDatabase(witnessedRunner(store, runId, now, commandRunner(store, runId, captured.effective.profile, request.setup ?? run)), setupShell.file, setupShell.args, {
1818
+ cwd: worktree,
1819
+ timeoutMs: live.timeoutMs,
1820
+ processGroup: true,
1821
+ owner: runOwnerTag(store, runId),
1822
+ beforeSpawn: () => !stopRequestedFor(store, runId, request.shouldStop),
1823
+ onSpawn: pid => {
1824
+ request.onProviderSpawn?.(pid);
1825
+ if (stopRequestedFor(store, runId, request.shouldStop))
1826
+ throw new Error("the attempt was stopped before spawn custody completed");
1827
+ },
1828
+ envAllowlist: SETUP_ENV_ALLOWLIST,
1829
+ omitEnv: SETUP_ENV_DENYLIST,
1830
+ }));
1831
+ checkOutcomes.push(attemptOutcome(label, installed));
1832
+ noteCheckSuite(label, installed);
1833
+ checkLog.push(attemptLog(label, live.command, installed));
1834
+ if (installed.notFound || installed.timedOut || installed.code !== 0)
1835
+ return "own-install-failed";
1836
+ return await sealedTreeState(buildCheckoutGit(request.git ?? run, worktree)) === "clean" ? null : "setup-changed-files";
1837
+ };
1838
+ const ownInstall = baselineUnverifiable === null ? await ownInstallIfChanged() : null;
1839
+ const missingProgram = configured.recoverySetupDigest === null ? null : approvedProgramMissing(configured.command, worktree, process.env["PATH"]);
1840
+ const first = baselineUnverifiable === null && ownInstall === null ? await runVerification("Project check · attempt 1", missingProgram) : null;
1841
+ if (first === null) {
1842
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: baselineUnverifiable !== null ? "baseline-unverifiable" : ownInstall ?? "own-install-failed" };
1843
+ }
1844
+ else if (first.notFound || first.timedOut) {
1845
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: first.timedOut ? "timed-out" : "spawn-failed" };
1846
+ }
1847
+ else if (first.stoppedByPlane === true) {
1848
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "stopped-by-toolroll" };
1849
+ }
1850
+ else if (!launchFailedBeforeCheck(first, checkAttempt?.nonce ?? null, missingProgram)) {
1851
+ verifyCommand = { configured: true, ran: true, exitCode: first.code };
1852
+ }
1853
+ else {
1854
+ const recoveryDigest = configured.recoverySetupDigest;
1855
+ const liveRecoverySetup = () => {
1856
+ if (repo === null || recoveryDigest === null)
1857
+ return null;
1858
+ const liveVerify = store.liveVerifyCommand(configured.repo);
1859
+ const liveSetup = store.liveWorktreeSetup(repo);
1860
+ return liveVerify !== null &&
1861
+ liveVerify.digest === configured.digest &&
1862
+ liveVerify.recoverySetupDigest === recoveryDigest &&
1863
+ liveSetup !== null &&
1864
+ liveSetup.digest === recoveryDigest
1865
+ ? liveSetup
1866
+ : null;
1867
+ };
1868
+ const setup = liveRecoverySetup();
1869
+ if (recoveryDigest === null) {
1870
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "dependency-missing" };
1871
+ }
1872
+ else if (setup === null || setup.digest !== recoveryDigest) {
1873
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "setup-stale" };
1874
+ }
1875
+ else if (!store.proveRunnerCustodyForSpawn(runId, now())) {
1876
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "custody-lost" };
1877
+ }
1878
+ else {
1879
+ const gitRunner = buildCheckoutGit(request.git ?? run, worktree);
1880
+ const beforeSetup = await sealedTreeState(gitRunner);
1881
+ if (beforeSetup === "head-moved") {
1882
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "checkout-moved" };
1883
+ recordCheckNote("Automatic recovery stopped before setup because HEAD no longer matched the built commit.");
1884
+ }
1885
+ else if (beforeSetup === "unavailable") {
1886
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "cleanliness-unavailable" };
1887
+ recordCheckNote("Automatic recovery stopped before setup because checkout cleanliness could not be confirmed.");
1888
+ }
1889
+ else if (beforeSetup === "changed") {
1890
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "tracked-files-changed" };
1891
+ recordCheckNote("Automatic recovery stopped before setup because tracked files no longer matched the built commit.");
1892
+ }
1893
+ else {
1894
+ const liveBeforeSetup = liveRecoverySetup();
1895
+ if (liveBeforeSetup === null) {
1896
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "setup-stale" };
1897
+ recordCheckNote("Automatic recovery stopped before setup because its approval changed.");
1898
+ }
1899
+ else if (!store.proveRunnerCustodyForSpawn(runId, now())) {
1900
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "custody-lost" };
1901
+ recordCheckNote("Automatic recovery stopped before setup: this worker no longer owned the build.");
1879
1902
  }
1880
1903
  else {
1881
- const afterSetup = await sealedTreeState(gitRunner);
1882
- if (afterSetup === "head-moved") {
1883
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "checkout-moved" };
1884
- recordCheckNote("Automatic recovery stopped: setup moved HEAD away from the built commit.");
1885
- }
1886
- else if (afterSetup === "unavailable") {
1887
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "cleanliness-unavailable" };
1888
- recordCheckNote("Automatic recovery stopped after setup because checkout cleanliness could not be confirmed.");
1889
- }
1890
- else if (afterSetup === "changed") {
1891
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "setup-changed-files" };
1892
- recordCheckNote("Automatic recovery stopped: setup changed tracked files after the build.");
1893
- }
1894
- else if (!store.proveRunnerCustodyForSpawn(runId, now())) {
1895
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "custody-lost" };
1896
- recordCheckNote("Automatic recovery stopped before retry: this worker no longer owned the build.");
1897
- }
1898
- else if (liveRecoverySetup() === null) {
1899
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "setup-stale" };
1900
- recordCheckNote("Automatic recovery stopped before retry because its approval changed.");
1904
+ const setupRunner = request.setup ?? run;
1905
+ const setupShell = approvedCommandShell(liveBeforeSetup.command);
1906
+ const restored = await underStopWatch(store, runId, () => runWithIsolatedDatabase(witnessedRunner(store, runId, now, commandRunner(store, runId, captured.effective.profile, setupRunner)), setupShell.file, setupShell.args, {
1907
+ cwd: worktree,
1908
+ timeoutMs: liveBeforeSetup.timeoutMs,
1909
+ processGroup: true,
1910
+ owner: runOwnerTag(store, runId),
1911
+ beforeSpawn: () => !stopRequestedFor(store, runId, request.shouldStop),
1912
+ onSpawn: pid => {
1913
+ request.onProviderSpawn?.(pid);
1914
+ if (stopRequestedFor(store, runId, request.shouldStop))
1915
+ throw new Error("the attempt was stopped before spawn custody completed");
1916
+ },
1917
+ envAllowlist: SETUP_ENV_ALLOWLIST,
1918
+ omitEnv: SETUP_ENV_DENYLIST,
1919
+ }));
1920
+ checkOutcomes.push(attemptOutcome("Automatic recovery · approved project setup", restored));
1921
+ noteCheckSuite("Automatic recovery · approved project setup", restored);
1922
+ checkLog.push(attemptLog("Automatic recovery · approved project setup", liveBeforeSetup.command, restored));
1923
+ if (restored.notFound || restored.timedOut || restored.code !== 0) {
1924
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "setup-failed" };
1901
1925
  }
1902
1926
  else {
1903
- const retried = await runVerification("Project check · retry after setup");
1904
- if (retried.timedOut) {
1905
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "retry-timed-out" };
1927
+ const afterSetup = await sealedTreeState(gitRunner);
1928
+ if (afterSetup === "head-moved") {
1929
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "checkout-moved" };
1930
+ recordCheckNote("Automatic recovery stopped: setup moved HEAD away from the built commit.");
1931
+ }
1932
+ else if (afterSetup === "unavailable") {
1933
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "cleanliness-unavailable" };
1934
+ recordCheckNote("Automatic recovery stopped after setup because checkout cleanliness could not be confirmed.");
1906
1935
  }
1907
- else if (retried.notFound) {
1908
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "retry-spawn-failed" };
1936
+ else if (afterSetup === "changed") {
1937
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "setup-changed-files" };
1938
+ recordCheckNote("Automatic recovery stopped: setup changed tracked files after the build.");
1909
1939
  }
1910
- else if (verificationExecutableMissing(retried)) {
1911
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "dependency-still-missing" };
1940
+ else if (!store.proveRunnerCustodyForSpawn(runId, now())) {
1941
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "custody-lost" };
1942
+ recordCheckNote("Automatic recovery stopped before retry: this worker no longer owned the build.");
1943
+ }
1944
+ else if (liveRecoverySetup() === null) {
1945
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "setup-stale" };
1946
+ recordCheckNote("Automatic recovery stopped before retry because its approval changed.");
1912
1947
  }
1913
1948
  else {
1914
- verifyCommand = { configured: true, ran: true, exitCode: retried.code, setupReplayed: true, firstAttempt: { class: "launch", program: missingProgram, exitCode: first.code } };
1949
+ const retried = await runVerification("Project check · retry after setup");
1950
+ if (retried.timedOut) {
1951
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "retry-timed-out" };
1952
+ }
1953
+ else if (retried.notFound) {
1954
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "retry-spawn-failed" };
1955
+ }
1956
+ else if (verificationExecutableMissing(retried)) {
1957
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "dependency-still-missing" };
1958
+ }
1959
+ else {
1960
+ verifyCommand = { configured: true, ran: true, exitCode: retried.code, setupReplayed: true, firstAttempt: { class: "launch", program: missingProgram, exitCode: first.code } };
1961
+ }
1915
1962
  }
1916
1963
  }
1917
1964
  }
1918
1965
  }
1919
1966
  }
1920
1967
  }
1921
- }
1922
- try {
1923
- checkProgress.finish();
1924
- }
1925
- catch { }
1926
- if (loadWatch !== null) {
1927
- const record = loadWatch.finish();
1968
+ removeDeployCopy();
1928
1969
  try {
1929
- sealJson(store, root, runId, "check-load.json", record, CHECK_LOAD_CAPTURE, now());
1970
+ checkProgress.finish();
1930
1971
  }
1931
- catch (error) {
1932
- store.addRunNote(runId, "Toolroll", `This check's load record wasn't kept (${redactSecretText(error instanceof Error ? error.message : String(error))}), so a timeout in it can't be called the machine's own.`, now());
1972
+ catch { }
1973
+ if (loadWatch !== null) {
1974
+ const record = loadWatch.finish();
1975
+ try {
1976
+ sealJson(store, root, runId, "check-load.json", record, CHECK_LOAD_CAPTURE, now());
1977
+ }
1978
+ catch (error) {
1979
+ store.addRunNote(runId, "Toolroll", `This check's load record wasn't kept (${redactSecretText(error instanceof Error ? error.message : String(error))}), so a timeout in it can't be called the machine's own.`, now());
1980
+ }
1981
+ }
1982
+ if (!progressWrites.flush())
1983
+ progressWrites.flush();
1984
+ const last = verification.last;
1985
+ let sealedReport = null;
1986
+ if (checkAttempt !== null && last !== null && !last.notFound) {
1987
+ sealedReport = settledReport = sealCheckOutcome(store, root, checkAttempt, { stdout: last.stdout, exitCode: last.timedOut ? null : last.code }, now());
1988
+ keepCheckTimeline(store, { runId, taskId: request.taskId, report: sealedReport, stdout: last.stdout, now: now() });
1989
+ }
1990
+ if (checkAttempt !== null) {
1991
+ const settled = settleCoverage(store, root, { runId, taskId: request.taskId, exitCode: last === null || last.notFound || last.timedOut ? null : last.code, now: now() }, run => { const gate = verificationEvidence(store, root, run); return gate.ok ? gate.digest : null; });
1992
+ const sha = (capture) => { const found = store.artifactsFor(runId).filter(a => a.kind === "structured-output" && a.capture === capture); return found.length === 1 ? found[0].sha256 : null; };
1993
+ const effective = effectiveCheckFacts(verifyCommand, { coverage: deployCleanupProblem !== null ? "no-result" : settled.coverage, check: { attempt: checkAttempt.mode === "deploy" ? "full" : checkAttempt.mode, report: sha(CHECK_REPORT_CAPTURE), inventory: sha(CHECK_INVENTORY_CAPTURE), retried: retriedInside(sealedReport) }, composed: settled.composed });
1994
+ verifyCommand = effective.result;
1995
+ releaseFacts = effective.facts;
1996
+ }
1997
+ else if (verifyCommand.configured && verifyCommand.ran && chosenCheck?.level === "full" && releaseCheckScope(store.getScope(request.taskId))) {
1998
+ verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "no-result" };
1999
+ recordCheckNote("The release check ran without a sealed attempt (its commit couldn't be read before it ran), so it has no result that can count.");
1933
2000
  }
1934
2001
  }
1935
- if (!progressWrites.flush())
1936
- progressWrites.flush();
1937
- const last = verification.last;
1938
- let sealedReport = null;
1939
- if (checkAttempt !== null && last !== null && !last.notFound) {
1940
- sealedReport = settledReport = sealCheckOutcome(store, root, checkAttempt, { stdout: last.stdout, exitCode: last.timedOut ? null : last.code }, now());
1941
- keepCheckTimeline(store, { runId, taskId: request.taskId, report: sealedReport, stdout: last.stdout, now: now() });
1942
- }
1943
- if (checkAttempt !== null) {
1944
- const settled = settleCoverage(store, root, { runId, taskId: request.taskId, exitCode: last === null || last.notFound || last.timedOut ? null : last.code, now: now() }, run => { const gate = verificationEvidence(store, root, run); return gate.ok ? gate.digest : null; });
1945
- const sha = (capture) => { const found = store.artifactsFor(runId).filter(a => a.kind === "structured-output" && a.capture === capture); return found.length === 1 ? found[0].sha256 : null; };
1946
- const effective = effectiveCheckFacts(verifyCommand, { coverage: settled.coverage, check: { attempt: checkAttempt.mode, report: sha(CHECK_REPORT_CAPTURE), inventory: sha(CHECK_INVENTORY_CAPTURE), retried: retriedInside(sealedReport) }, composed: settled.composed });
1947
- verifyCommand = effective.result;
1948
- releaseFacts = effective.facts;
1949
- }
1950
- else if (verifyCommand.configured && verifyCommand.ran && chosenCheck?.level === "full" && releaseCheckScope(store.getScope(request.taskId))) {
1951
- verifyCommand = { configured: true, ran: false, attemptFailed: true, failure: "no-result" };
1952
- recordCheckNote("The release check ran without a sealed attempt (its commit couldn't be read before it ran), so it has no result that can count.");
2002
+ finally {
2003
+ removeDeployCopy();
1953
2004
  }
1954
2005
  }
1955
2006
  if (configured !== null && checkLog.length > 0) {
@@ -1968,7 +2019,7 @@ async function settleProof(captured, statArtifactId, sealedHead) {
1968
2019
  }
1969
2020
  if (configured !== null && checkLog.length > 0)
1970
2021
  sealVerificationReceipt(store, root, runId, sealedHead, configured, verifyCommand, now(), undefined, releaseFacts ?? undefined);
1971
- const uncovered = releaseFacts !== null && releaseFacts.coverage !== "full" && releaseFacts.coverage !== "composed";
2022
+ const uncovered = releaseFacts !== null && !coveragePasses(releaseFacts.coverage);
1972
2023
  const checkStatus = verifyCommand.configured === false ? "not-run"
1973
2024
  : uncovered ? "failed"
1974
2025
  : verifyCommand.ran ? verifyCommand.exitCode === 0 ? "passed" : "failed"