toolroll 0.9.129 → 0.9.131

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/agent-fence.js +0 -2
  3. package/dist/agent-state.js +1 -1
  4. package/dist/agents-board.js +0 -3
  5. package/dist/assignment.js +4 -3
  6. package/dist/backup-ui.js +6 -3
  7. package/dist/bounded-spawn.js +0 -1
  8. package/dist/browser/manifest.json +57 -0
  9. package/dist/browser/terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css.br +0 -0
  10. package/dist/browser/terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css.gz +0 -0
  11. package/dist/browser/{terminal.js → terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js} +1 -1
  12. package/dist/browser/terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js.br +0 -0
  13. package/dist/browser/terminal.8978c8cbb268e1006f4b0be371c2401b58078e6d9f1380f4a5c2a12da843909f.js.gz +0 -0
  14. package/dist/browser/{workspace.js → workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js} +25 -25
  15. package/dist/browser/workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js.br +0 -0
  16. package/dist/browser/workspace.4f5935dc80574baadf1adafd39a08c567fb1fac1323052ca355546622f9b06d2.js.gz +0 -0
  17. package/dist/browser/{workspace.css → workspace.a0752f935cfeaf16758d1085fe8f3e1719a7cd525b91a9c9943c789d65879a54.css} +1 -1
  18. package/dist/browser/workspace.a0752f935cfeaf16758d1085fe8f3e1719a7cd525b91a9c9943c789d65879a54.css.br +0 -0
  19. package/dist/browser/workspace.a0752f935cfeaf16758d1085fe8f3e1719a7cd525b91a9c9943c789d65879a54.css.gz +0 -0
  20. package/dist/browser-shell.js +271 -25
  21. package/dist/builder-restart.js +13 -4
  22. package/dist/builder.js +4 -1
  23. package/dist/canvas-freshness.js +122 -0
  24. package/dist/canvas-fs.js +273 -0
  25. package/dist/canvas-reads.js +747 -0
  26. package/dist/canvas-state-key.js +45 -0
  27. package/dist/canvas-state-worker.js +12 -0
  28. package/dist/central-recovery-stage.js +3 -3
  29. package/dist/chat-actions.js +26 -0
  30. package/dist/chat-channel.js +4 -3
  31. package/dist/chat-follow.js +4 -0
  32. package/dist/chat-task-actions.js +1 -1
  33. package/dist/chat-warmth.js +0 -1
  34. package/dist/check-report.js +0 -6
  35. package/dist/commit-extract.js +79 -40
  36. package/dist/companion/access.js +1 -0
  37. package/dist/companion/actions.js +79 -16
  38. package/dist/companion/canvas.js +141 -0
  39. package/dist/companion/chat-origin.js +92 -0
  40. package/dist/companion/chat.js +571 -0
  41. package/dist/companion/daemon.js +46 -5
  42. package/dist/companion/finish.js +51 -0
  43. package/dist/companion/reads.js +5 -1
  44. package/dist/companion/schema.js +64 -0
  45. package/dist/companion/service.js +1 -0
  46. package/dist/companion/store.js +1 -0
  47. package/dist/companion/webauthn.js +11 -2
  48. package/dist/console-instance.js +0 -4
  49. package/dist/contracts/console-api.js +1 -1
  50. package/dist/converse.js +0 -1
  51. package/dist/coordinator.js +1 -1
  52. package/dist/db-tuning.js +16 -0
  53. package/dist/desktop-config.js +156 -0
  54. package/dist/desktop-host.js +6 -152
  55. package/dist/desktop-update.js +1 -1
  56. package/dist/discord.js +9 -3
  57. package/dist/dispatch.js +32 -4
  58. package/dist/doctor.js +30 -0
  59. package/dist/evidence.js +49 -3
  60. package/dist/exec.js +3 -0
  61. package/dist/finished-task-sql.js +14 -0
  62. package/dist/flexible-answers.js +0 -1
  63. package/dist/git-views.js +7 -1
  64. package/dist/github-read.js +41 -0
  65. package/dist/guides.js +4 -3
  66. package/dist/invoke.js +12 -2
  67. package/dist/lead-doors.js +50 -3
  68. package/dist/lead-queue-runtime.js +18 -6
  69. package/dist/lead-queue.js +25 -0
  70. package/dist/lead-status.js +3 -3
  71. package/dist/live-backup-change.js +93 -0
  72. package/dist/live-backup.js +75 -31
  73. package/dist/live-bus.js +3 -2
  74. package/dist/live-records.js +0 -1
  75. package/dist/local-owner.js +0 -1
  76. package/dist/loop-recovery.js +40 -0
  77. package/dist/maintenance.js +29 -1
  78. package/dist/model-choices.js +0 -11
  79. package/dist/needs-you.js +2 -0
  80. package/dist/nightly-check.js +0 -3
  81. package/dist/nightly-github.js +1 -2
  82. package/dist/notification-retention.js +119 -0
  83. package/dist/observations.js +0 -1
  84. package/dist/operate.js +393 -56
  85. package/dist/planner.js +4 -1
  86. package/dist/pull-request-flow.js +56 -15
  87. package/dist/qr.js +0 -25
  88. package/dist/query-index-schema.js +10 -0
  89. package/dist/read-executor-worker.js +9 -7
  90. package/dist/read-executor.js +18 -1
  91. package/dist/read-worker-connection.js +7 -0
  92. package/dist/release-adapters.js +63 -48
  93. package/dist/release-auto.js +17 -13
  94. package/dist/release-card.js +0 -4
  95. package/dist/release-cli.js +58 -10
  96. package/dist/release-next.js +1 -1
  97. package/dist/release-stops.js +71 -0
  98. package/dist/release-supersede.js +125 -0
  99. package/dist/release-supervise.js +90 -0
  100. package/dist/release.js +265 -42
  101. package/dist/restore-retirement.js +4 -1
  102. package/dist/result-review.js +0 -3
  103. package/dist/retention-ui.js +1 -1
  104. package/dist/retention.js +14 -21
  105. package/dist/review-context.js +0 -5
  106. package/dist/route-rules.js +1 -5
  107. package/dist/runner.js +36 -1
  108. package/dist/sandbox-runtime.js +0 -1
  109. package/dist/scope.js +1 -13
  110. package/dist/scout.js +4 -7
  111. package/dist/serve.js +122 -12
  112. package/dist/server/kit.js +1 -0
  113. package/dist/server/live.js +9 -2
  114. package/dist/server/pages.js +3 -2
  115. package/dist/server/phone-engine-api.js +22 -2
  116. package/dist/server/render-pages.js +1 -11
  117. package/dist/server/render-results.js +0 -1
  118. package/dist/server/render-tasks.js +0 -68
  119. package/dist/server/route-table.js +1 -1
  120. package/dist/server/settings-phone.js +32 -9
  121. package/dist/server/settings-scripts.js +1 -1
  122. package/dist/server/settings-section-table.js +0 -3
  123. package/dist/server/settings-sections.js +4 -2
  124. package/dist/server/settings.js +20 -5
  125. package/dist/server/terminals.js +2 -1
  126. package/dist/shutdown-proof.js +29 -0
  127. package/dist/slack.js +9 -3
  128. package/dist/sqlite-telemetry.js +26 -14
  129. package/dist/statement-cache.js +137 -0
  130. package/dist/store.js +86 -14
  131. package/dist/structured-output.js +0 -1
  132. package/dist/style-asset.js +20 -7
  133. package/dist/tailnet.js +0 -3
  134. package/dist/task-control.js +5 -0
  135. package/dist/task-sizing.js +0 -1
  136. package/dist/task-status.js +1 -1
  137. package/dist/teams.js +9 -3
  138. package/dist/teardown-git.js +10 -1
  139. package/dist/telegram.js +4 -1
  140. package/dist/toolroll-update-cli.js +19 -3
  141. package/dist/toolroll-update-ui.js +2 -2
  142. package/dist/toolroll-update.js +95 -15
  143. package/dist/up-processes.js +16 -1
  144. package/dist/up-role-child.js +2 -0
  145. package/dist/wake-hub.js +15 -6
  146. package/dist/work-index.js +101 -44
  147. package/dist/work-reads.js +53 -9
  148. package/dist/work-snapshots.js +185 -0
  149. package/dist/worker-statement-cache.js +83 -0
  150. package/dist/workspace-revision.js +145 -21
  151. package/package.json +1 -1
  152. package/dist/companion/webauthn-test-support.js +0 -44
  153. package/dist/contracts/contract-test.js +0 -55
  154. package/dist/unfenced-test-support.js +0 -6
  155. /package/dist/browser/{terminal.css → terminal.4d1cf20c32ad7c2099df657358d540d5fd92bb55195a88121e74b28467238b42.css} +0 -0
package/dist/planner.js CHANGED
@@ -10,6 +10,7 @@ import { join } from "node:path";
10
10
  import { run } from "./exec.js";
11
11
  import { checkoutGit } from "./teardown-git.js";
12
12
  import { auditOf, isProviderId } from "./provider.js";
13
+ import { isDatabaseBusy } from "./store.js";
13
14
  import { currentClaim, heartbeat } from "./claim.js";
14
15
  import { heartbeat as runnerHeartbeat, RUNNER_HEARTBEAT_MS } from "./runner.js";
15
16
  import { parseDecision } from "./decision.js";
@@ -499,7 +500,9 @@ export async function plan(store, request) {
499
500
  if (!answer.ok)
500
501
  fencedMidPlan = true;
501
502
  }
502
- catch {
503
+ catch (error) {
504
+ if (isDatabaseBusy(error))
505
+ return;
503
506
  fencedMidPlan = true;
504
507
  }
505
508
  if (fencedMidPlan && pulseTimer !== undefined)
@@ -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 { passkeyProofDetail } from "./companion/webauthn.js";
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 expectedBinding = {
360
- verb: "ship",
361
- runId: input.runId,
362
- taskId: taskRef.externalId,
363
- prNumber: publication.prNumber,
364
- headSha: publication.headSha,
365
- method,
366
- anyway: input.anyway === true,
367
- };
368
- const checked = checkPasskeyAction(store, { accountName: input.name, repo, verb: "ship", expectedBinding, proof: input.passkey, now: clock() });
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("password", passkeyRefusedMsg);
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);
@@ -0,0 +1,10 @@
1
+ export const V190_STEPS = Object.freeze(["query-indexes"]);
2
+ export const V190_INDEXES = Object.freeze([
3
+ ["flow_trigger_event_task", "flow_trigger_event", "CREATE INDEX IF NOT EXISTS flow_trigger_event_task ON flow_trigger_event (task) WHERE task IS NOT NULL"],
4
+ ["notification_delivery_unsettled", "notification_delivery", "CREATE INDEX IF NOT EXISTS notification_delivery_unsettled ON notification_delivery (destination, notification) WHERE delivered_at IS NULL"],
5
+ ]);
6
+ export const V190_DROPPED_INDEXES = Object.freeze(["claim_by_task", "idx_direct_chat_ship_thread"]);
7
+ export const V190_SCHEMA = [
8
+ ...V190_INDEXES.map(([, , ddl]) => `${ddl};`),
9
+ ...V190_DROPPED_INDEXES.map(name => `DROP INDEX IF EXISTS ${name};`),
10
+ ].join("\n");
@@ -1,16 +1,17 @@
1
1
  import { parentPort, workerData } from 'node:worker_threads';
2
- import { openStoreReadOnly } from './store.js';
2
+ import { openReadWorkerStore } from './read-worker-connection.js';
3
3
  import { workCountsByProject, workIndexPage } from './work-index.js';
4
4
  import { projectSummaryOf } from './console-chrome.js';
5
+ import { readSnapshot } from './work-snapshots.js';
6
+ import { proveReadOnly } from './read-executor.js';
7
+ import { cacheStatements } from './worker-statement-cache.js';
5
8
  let store = null;
6
9
  function connection() {
7
10
  if (store !== null)
8
11
  return store;
9
- const opened = openStoreReadOnly(String(workerData.file));
10
- if (opened === null)
11
- throw new Error('The read worker could not open the database read-only at the current schema.');
12
- opened.handle.exec('PRAGMA query_only=1; PRAGMA temp_store=MEMORY; PRAGMA cache_size=-16000;');
13
- return store = opened;
12
+ const opened = openReadWorkerStore(String(workerData.file));
13
+ proveReadOnly(opened.handle);
14
+ return store = Object.create(opened, { db: { value: cacheStatements(opened.handle) } });
14
15
  }
15
16
  parentPort.on('message', ({ id, job }) => {
16
17
  let reply;
@@ -19,7 +20,8 @@ parentPort.on('message', ({ id, job }) => {
19
20
  const value = job.kind === 'work-index-page' ? workIndexPage(connection(), now, job.access, job.options)
20
21
  : job.kind === 'work-counts' ? workCountsByProject(connection(), now, job.access)
21
22
  : job.kind === 'project-summary' ? projectSummaryOf(connection(), now, job.access, job.actor, job.projects, job.evidenceRoot ?? undefined)
22
- : (() => { throw new Error('Unknown read.'); })();
23
+ : job.kind === 'snapshot' ? readSnapshot(connection(), job.job)
24
+ : (() => { throw new Error('Unknown read.'); })();
23
25
  reply = { id, ok: true, value };
24
26
  }
25
27
  catch (error) {
@@ -27,6 +27,8 @@ function readCacheKey(job) {
27
27
  if (job.kind === 'work-counts') {
28
28
  return JSON.stringify(['wc', secondBucket, canonicalAccess(job.access)]);
29
29
  }
30
+ if (job.kind === 'snapshot')
31
+ throw new Error('Snapshots are never cached by data version.');
30
32
  return JSON.stringify(['ps', secondBucket, canonicalAccess(job.access), job.actor, job.projects, job.evidenceRoot]);
31
33
  }
32
34
  export class ReadExecutorError extends Error {
@@ -83,10 +85,13 @@ export class ReadExecutor {
83
85
  async projectSummary(now, access, actor, projects, evidenceRoot) {
84
86
  return await this.#run({ kind: 'project-summary', now: now.toISOString(), access, actor, projects: projects.map(one => ({ path: one.path, name: one.name })), evidenceRoot: evidenceRoot ?? null });
85
87
  }
88
+ async snapshot(job) {
89
+ return await this.#run({ kind: 'snapshot', now: job.now, job });
90
+ }
86
91
  #run(job) {
87
92
  if (this.#closed)
88
93
  return Promise.reject(new ReadExecutorError('The server is closing.'));
89
- const version = this.#dataVersion();
94
+ const version = job.kind === 'snapshot' ? null : this.#dataVersion();
90
95
  const key = version === null ? null : readCacheKey(job);
91
96
  const nowMs = Date.now();
92
97
  if (key !== null && version !== null) {
@@ -200,6 +205,18 @@ export class ReadExecutor {
200
205
  export function defaultReadWorkers() {
201
206
  return Math.max(1, Math.min(8, Math.floor(availableParallelism() / 2)));
202
207
  }
208
+ export function proveReadOnly(db) {
209
+ try {
210
+ db.exec('UPDATE main.service_cursor SET key = key WHERE 0');
211
+ }
212
+ catch (error) {
213
+ const code = error.errcode;
214
+ if (typeof code === 'number' && (code & 0xff) === SQLITE_READONLY)
215
+ return;
216
+ }
217
+ throw new ReadExecutorError('The read worker\'s connection is not proved read-only; it must be.');
218
+ }
219
+ const SQLITE_READONLY = 8;
203
220
  const attached = new WeakMap();
204
221
  export function attachReadExecutor(store, executor) {
205
222
  attached.set(store, executor);
@@ -0,0 +1,7 @@
1
+ import { openStoreReadOnly } from './store.js';
2
+ export function openReadWorkerStore(file) {
3
+ const opened = openStoreReadOnly(file);
4
+ if (opened === null)
5
+ throw new Error('The read worker could not open the database read-only at the current schema.');
6
+ return opened;
7
+ }
@@ -1,4 +1,4 @@
1
- import { execFile, spawnSync } from "node:child_process";
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";
@@ -35,21 +36,14 @@ import { noteReleaseReady, noteReleaseStopped, recordReleaseCi } from "./release
35
36
  import { recordVerifiedRelease } from "./release-card.js";
36
37
  export { failedBeforeTests } from "./github-jobs.js";
37
38
  import { extractCommit } from "./commit-extract.js";
38
- import { teardownGit, refusal as gitRefusal } from "./teardown-git.js";
39
+ import { checkoutBusy, teardownGit, refusal as gitRefusal } from "./teardown-git.js";
40
+ import { CheckoutBusy } from "./git-views.js";
41
+ import { NotYetPublished } from "./release-stops.js";
42
+ import { supersedeReleaseTask } from "./release-supersede.js";
39
43
  import { RELEASE_REMOTE, releaseConfigProblem, releaseGitArgs, releaseGitEnv, releaseRemote, releaseTools } from "./release-git.js";
44
+ import { ciEnv, exec, githubReads } from "./github-read.js";
45
+ export { exec, githubReads } from "./github-read.js";
40
46
  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
47
  const ownCli = () => {
54
48
  const bin = join(dirname(fileURLToPath(import.meta.url)), "bin.js");
55
49
  return existsSync(bin) ? [process.execPath, bin] : ["toolroll"];
@@ -279,6 +273,8 @@ export function releaseAdapters(options) {
279
273
  return { ...result, timedOut: result.code === 124, notFound: result.code === 127 };
280
274
  }, { repo: repo.checkout }, Math.max(0, left()), tools.git);
281
275
  const result = await viewed(repo.checkout, full.slice(2));
276
+ if (checkoutBusy(result))
277
+ throw new CheckoutBusy();
282
278
  const why = gitRefusal(result);
283
279
  if (why !== null)
284
280
  throw stop(why);
@@ -438,7 +434,11 @@ export function releaseAdapters(options) {
438
434
  },
439
435
  },
440
436
  toolroll: {
441
- async installed() { return { services: serviceRuntimes(), clis: cliRuntimes() }; },
437
+ async installed() {
438
+ const services = serviceRuntimes(), clis = cliRuntimes();
439
+ const versions = Object.fromEntries([...services, ...clis.flatMap(one => one.runtime === null ? [] : [one.runtime])].map(dist => [dist, runtimeVersionAt(dist)]));
440
+ return { services, clis, versions };
441
+ },
442
442
  async runtimeCommit(runtime) {
443
443
  try {
444
444
  const candidate = object(JSON.parse(readFileSync(join(runtime, "..", "..", "..", "package.json"), "utf8")))["candidate"];
@@ -597,6 +597,7 @@ export function releaseAdapters(options) {
597
597
  async mainHead(repo) { return readMainHead(reads, ciGh, repo); },
598
598
  async contains(repo, sha, ancestor) { return readContains(reads, ciGh, repo, sha, ancestor); },
599
599
  async updateBranch(repo, pr, expectedHead) { return updatePullRequestBranch(reads, ciGh, repo, pr, expectedHead); },
600
+ async rerun(repo, id) { return rerunWorkflowRun(run, ciGh, repo, id); },
600
601
  async upToDateRequired(repo) { return readMainProtection(reads, ciGh, repo); },
601
602
  async merge(repo, pr, head, message) {
602
603
  return writeWithRecheck(`merging #${pr}`, { ...net, maxAttempts: 1 }, {
@@ -613,7 +614,7 @@ export function releaseAdapters(options) {
613
614
  },
614
615
  async tag(repo, tag) { return readTag(repo, tag); },
615
616
  async createTag(repo, tag, sha) {
616
- await writeWithRecheck(`creating ${tag}`, net, {
617
+ await writeWithRecheck(`creating ${tag}`, { ...net, maxAttempts: 1 }, {
617
618
  write: remaining => ghWrite(remaining, "api", "-X", "POST", `repos/${repo}/git/refs`, "-f", `ref=refs/tags/${tag}`, "-f", `sha=${sha}`),
618
619
  accept: () => undefined,
619
620
  refuse: result => { throw failed(result, `creating ${tag}`); },
@@ -683,6 +684,8 @@ export function releaseAdapters(options) {
683
684
  async propose(version) {
684
685
  const tarball = `https://registry.npmjs.org/toolroll/-/toolroll-${version}.tgz`;
685
686
  const response = await get(tarball, { signal: AbortSignal.timeout(60_000) });
687
+ if (response.status === 404)
688
+ throw new NotYetPublished(`npm doesn't serve ${tarball} yet`);
686
689
  if (!response.ok)
687
690
  throw new Error(`downloading ${tarball} answered ${response.status}`);
688
691
  const sha256 = createHash("sha256").update(Buffer.from(await response.arrayBuffer())).digest("hex");
@@ -960,9 +963,10 @@ export function storeReleaseAdapter(open, done, now, runner, auto, nightlyReads)
960
963
  async start(operation, epoch) { return withStore(store => runReleaseOperation(store, operation, epoch, now())); },
961
964
  async finish(operation, outcome, facts, epoch) { return withStore(store => finishReleaseOperation(store, operation, outcome, facts, now(), epoch)); },
962
965
  async needsApproval(authority, reason, epoch) { return withStore(store => requireFreshReleaseApproval(store, authority, reason, epoch, now())); },
966
+ async supersede(input) { return withStore(store => supersedeReleaseTask(store, input, now())); },
963
967
  async operations(authority) {
964
968
  return withStore(store => releaseOperations(store, authority).map(op => ({ id: op.id, kind: op.kind, state: op.state, candidate: op.candidate, externalRef: op.externalRef, reservedAt: op.reservedAt,
965
- direct: op.direct, issuerGone: releaseIssuerGone(op), stage: op.stage })));
969
+ direct: op.direct, issuerGone: releaseIssuerGone(op), issuedHere: op.issuer !== null && op.issuer.pid === process.pid && !releaseIssuerGone(op), stage: op.stage })));
966
970
  },
967
971
  };
968
972
  }
@@ -1056,10 +1060,6 @@ function autoReleaseAdapter(withStore, now, auto) {
1056
1060
  async publishHeld(taskId) { return withStore(store => autoPublishHeld(store, taskId)); },
1057
1061
  };
1058
1062
  }
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
1063
  export async function readCheckRuns(run, gh, repo, sha, options = {}) {
1064
1064
  if (options.tag !== undefined && !/^v\d+\.\d+\.\d+$/.test(options.tag))
1065
1065
  throw new Error("not a release tag");
@@ -1068,16 +1068,17 @@ export async function readCheckRuns(run, gh, repo, sha, options = {}) {
1068
1068
  const out = await must(run(gh, ["api", "--hostname", "github.com", "--paginate", `repos/${repo}/commits/${sha}/check-runs?filter=all&per_page=100`,
1069
1069
  "--jq", ".check_runs[] | {id, name, status, conclusion, app: .app.slug, suite: .check_suite.id, head: .head_sha}"], { cwd: "/", env: ciEnv() }), "gh api check-runs");
1070
1070
  const flows = await must(run(gh, ["api", "--hostname", "github.com", "--paginate", `repos/${repo}/actions/runs?head_sha=${sha}&per_page=100`,
1071
- "--jq", ".workflow_runs[] | {suite: .check_suite_id, workflow: .workflow_id, path: .path, head: .head_sha, event: .event, branch: .head_branch, bases: [(.pull_requests // [])[] | .base.ref], prs: [(.pull_requests // [])[] | {number, repo: .base.repo.url}]}"], { cwd: "/", env: ciEnv() }), "gh api actions/runs");
1071
+ "--jq", ".workflow_runs[] | {run: .id, suite: .check_suite_id, workflow: .workflow_id, path: .path, head: .head_sha, event: .event, branch: .head_branch, repo: .repository.full_name, headRepo: .head_repository.full_name, bases: [(.pull_requests // [])[] | .base.ref], prs: [(.pull_requests // [])[] | {number, repo: .base.repo.url}]}"], { cwd: "/", env: ciEnv() }), "gh api actions/runs");
1072
1072
  const retargeted = new Map();
1073
+ const RETARGET_EVENTS = new Set(["base_ref_changed", "automatic_base_change_succeeded", "automatic_base_change_failed"]);
1073
1074
  const everRetargeted = async (pr) => {
1074
1075
  const known = retargeted.get(pr);
1075
1076
  if (known !== undefined)
1076
1077
  return known;
1077
1078
  let changed = true;
1078
1079
  try {
1079
- const events = await run(gh, ["api", "--hostname", "github.com", "--paginate", `repos/${repo}/issues/${pr}/timeline?per_page=100`, "--jq", ".[] | .event"], { cwd: "/", env: ciEnv() });
1080
- changed = events.code !== 0 || events.stdout.split("\n").some(line => line.trim() === "base_ref_changed");
1080
+ 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() })));
1081
+ changed = reads.some(events => events.code !== 0 || events.stdout.split("\n").some(line => RETARGET_EVENTS.has(line.trim())));
1081
1082
  }
1082
1083
  catch {
1083
1084
  changed = true;
@@ -1085,7 +1086,32 @@ export async function readCheckRuns(run, gh, repo, sha, options = {}) {
1085
1086
  retargeted.set(pr, changed);
1086
1087
  return changed;
1087
1088
  };
1089
+ const onlyPull = new Map();
1090
+ const onlyPullFrom = async (branch) => {
1091
+ const known = onlyPull.get(branch);
1092
+ if (known !== undefined)
1093
+ return known;
1094
+ let bound = false;
1095
+ try {
1096
+ if (/^[A-Za-z0-9._/-]+$/.test(branch) && !branch.includes("..")) {
1097
+ const owner = repo.split("/")[0];
1098
+ const listed = await run(gh, ["api", "--hostname", "github.com", "--paginate", `repos/${repo}/pulls?state=all&head=${encodeURIComponent(`${owner}:${branch}`)}&per_page=100`,
1099
+ "--jq", ".[] | {number, state, merged: (.merged_at != null), base: .base.ref, baseRepo: .base.repo.full_name, head: .head.ref, headRepo: .head.repo.full_name, headSha: .head.sha}"], { cwd: "/", env: ciEnv() });
1100
+ const pulls = listed.code !== 0 ? null : listed.stdout.split("\n").filter(Boolean).map(line => object(JSON.parse(line)));
1101
+ const only = pulls !== null && pulls.length === 1 ? pulls[0] : null;
1102
+ bound = only !== null && Number.isSafeInteger(only["number"]) && only["state"] === "closed" && only["merged"] === true
1103
+ && only["base"] === "main" && only["baseRepo"] === repo && only["head"] === branch && only["headRepo"] === repo && only["headSha"] === sha
1104
+ && !await everRetargeted(Number(only["number"]));
1105
+ }
1106
+ }
1107
+ catch {
1108
+ bound = false;
1109
+ }
1110
+ onlyPull.set(branch, bound);
1111
+ return bound;
1112
+ };
1088
1113
  const workflowOf = new Map();
1114
+ const runOf = new Map();
1089
1115
  const pathOf = new Map();
1090
1116
  for (const line of flows.split("\n").filter(Boolean)) {
1091
1117
  const one = object(JSON.parse(line));
@@ -1095,10 +1121,14 @@ export async function readCheckRuns(run, gh, repo, sha, options = {}) {
1095
1121
  if (known !== undefined && (known !== Number(one["workflow"]) || pathOf.get(Number(one["suite"])) !== one["path"]))
1096
1122
  throw new Error("GitHub named two workflows for one check suite");
1097
1123
  workflowOf.set(Number(one["suite"]), Number(one["workflow"]));
1124
+ if (Number.isSafeInteger(one["run"]) && Number(one["run"]) > 0)
1125
+ runOf.set(Number(one["suite"]), Number(one["run"]));
1098
1126
  const prs = (Array.isArray(one["prs"]) ? one["prs"] : []).map(pr => (pr !== null && typeof pr === "object" ? pr : {}));
1099
1127
  const ours = prs.length > 0 && prs.every(pr => Number.isSafeInteger(pr["number"]) && pr["repo"] === `https://api.github.com/repos/${repo}`);
1100
1128
  const untouched = one["event"] !== "pull_request" || (ours && !(await Promise.all(prs.map(pr => everRetargeted(Number(pr["number"]))))).some(Boolean));
1101
- if ((options.tag === undefined ? mainTriggered(one) : tagTriggered(one, options.tag)) && untouched)
1129
+ const emptied = options.tag === undefined && one["event"] === "pull_request" && prs.length === 0 && one["repo"] === repo && one["headRepo"] === repo
1130
+ && typeof one["branch"] === "string" && await onlyPullFrom(one["branch"]);
1131
+ if (((options.tag === undefined ? mainTriggered(one) : tagTriggered(one, options.tag)) && untouched) || emptied)
1102
1132
  pathOf.set(Number(one["suite"]), String(one["path"]));
1103
1133
  }
1104
1134
  const runs = out.split("\n").filter(Boolean).map(line => {
@@ -1107,7 +1137,8 @@ export async function readCheckRuns(run, gh, repo, sha, options = {}) {
1107
1137
  throw new Error("GitHub answered a check run this can't read");
1108
1138
  const suite = Number.isSafeInteger(one["suite"]) ? Number(one["suite"]) : null;
1109
1139
  return { id: Number(one["id"]), name: one["name"], status: one["status"], conclusion: textOr(one["conclusion"]), app: textOr(one["app"]),
1110
- suite, head: textOr(one["head"]), workflow: suite === null ? null : workflowOf.get(suite) ?? null, workflowPath: suite === null ? null : pathOf.get(suite) ?? null };
1140
+ suite, head: textOr(one["head"]), workflow: suite === null ? null : workflowOf.get(suite) ?? null, workflowPath: suite === null ? null : pathOf.get(suite) ?? null,
1141
+ ...(suite !== null && runOf.has(suite) ? { workflowRun: runOf.get(suite) } : {}) };
1111
1142
  });
1112
1143
  if (new Set(runs.map(one => one.id)).size !== runs.length)
1113
1144
  throw new Error("GitHub answered the same check run twice");
@@ -1145,28 +1176,6 @@ export async function readJobBeforeTests(run, gh, repo, id) {
1145
1176
  return failedBeforeTests({ id, status: String(job["status"]), conclusion: textOr(job["conclusion"]),
1146
1177
  steps: steps.map(one => ({ number: Number(one["number"]), name: String(one["name"]), status: String(one["status"]), conclusion: textOr(one["conclusion"]) })) });
1147
1178
  }
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
1179
  export const CHECK_SUITE_CEILING = 1000;
1171
1180
  export async function readSuitesComplete(run, gh, repo, sha) {
1172
1181
  if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repo) || !/^[0-9a-f]{40}$/.test(sha))
@@ -1583,3 +1592,9 @@ export async function readMainVersion(run, gh, repo) {
1583
1592
  return null;
1584
1593
  }
1585
1594
  }
1595
+ export async function rerunWorkflowRun(run, gh, repo, id) {
1596
+ if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repo) || !Number.isSafeInteger(id) || id < 1)
1597
+ return { ok: false, why: "not a workflow run GitHub can be asked to run again" };
1598
+ const ran = await run(gh, ["api", "--hostname", "github.com", "--method", "POST", `repos/${repo}/actions/runs/${id}/rerun`], { cwd: "/", env: ciEnv() });
1599
+ return ran.code === 0 ? { ok: true } : { ok: false, why: (ran.stderr.trim().split("\n")[0] ?? "").slice(0, 200) || `gh exited ${ran.code}` };
1600
+ }
@@ -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, verifiedBlobs, verifiedTreeDiff, verifiedTreeEntries } from "./commit-extract.js";
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(gitDir, tree) {
213
- const entries = verifiedTreeEntries(gitDir, tree);
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 = verifiedBlobs(gitDir, tree, paths);
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 before = readVerifiedCommit(gitDir, base), after = readVerifiedCommit(gitDir, candidate);
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 = verifiedTreeDiff(gitDir, before.value.tree, after.value.tree);
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(gitDir, tree);
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 = verifiedBlobs(gitDir, tree, EVAL_HOOK_FILES); return (file) => blobs.ok ? blobs.value.get(file)?.bytes ?? null : null; };
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 = verifiedBlobs(gitDir, tree, changed); return blobs.ok ? (file) => blobs.value.get(file)?.bytes ?? null : null; };
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 = verifiedBlobs(gitDir, tree, ROUTING_HOOK_FILES); return (file) => blobs.ok ? blobs.value.get(file)?.bytes ?? null : null; };
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 = verifiedBlobs(gitDir, tree, LEARNING_HOOK_FILES); return (file) => blobs.ok ? blobs.value.get(file)?.bytes ?? null : null; };
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 = verifiedBlobs(gitDir, after.value.tree, [change.path]);
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 = verifiedBlobs(gitDir, tree, [change.path]); return blobs.ok ? withoutVersion(normal, blobs.value.get(change.path)?.bytes) : undefined; };
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)`;
@@ -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 => {