toolroll 0.9.118 → 0.9.119

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 (63) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +14 -14
  3. package/dist/assignment.js +40 -29
  4. package/dist/browser/workspace.css +1 -1
  5. package/dist/browser/workspace.js +32 -31
  6. package/dist/builder.js +286 -236
  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/contracts/console-api.js +4 -1
  12. package/dist/contracts/engine-api.js +1 -0
  13. package/dist/contracts/release-check.js +7 -4
  14. package/dist/contracts/release-terms.js +11 -2
  15. package/dist/contracts/verification-receipt.js +1 -1
  16. package/dist/deploy-gate.js +7 -1
  17. package/dist/direct-chat.js +3 -3
  18. package/dist/easy-start.js +8 -6
  19. package/dist/engine-reads.js +72 -0
  20. package/dist/flexible-conversation-schema.js +24 -0
  21. package/dist/flexible-conversation.js +162 -0
  22. package/dist/flexible-custody.js +3 -0
  23. package/dist/flexible-import.js +51 -0
  24. package/dist/flexible-session.js +84 -11
  25. package/dist/install-mode.js +1 -1
  26. package/dist/local-landing.js +500 -0
  27. package/dist/local-owner.js +1 -0
  28. package/dist/operate.js +143 -22
  29. package/dist/passwordless.js +1 -1
  30. package/dist/project-delete.js +1 -0
  31. package/dist/rehearsal.js +27 -0
  32. package/dist/release-adapters.js +170 -2
  33. package/dist/release-approval.js +11 -8
  34. package/dist/release-card.js +7 -2
  35. package/dist/release-carry.js +1 -1
  36. package/dist/release-cli.js +115 -14
  37. package/dist/release-main-proof.js +49 -0
  38. package/dist/release-main.js +110 -0
  39. package/dist/release-recheck.js +10 -3
  40. package/dist/release.js +221 -33
  41. package/dist/reply-shape.js +6 -1
  42. package/dist/result-actions.js +7 -1
  43. package/dist/result-follow-ups.js +8 -4
  44. package/dist/serve.js +31 -14
  45. package/dist/server/direct-chat.js +88 -3
  46. package/dist/server/engine-api.js +43 -5
  47. package/dist/server/render-results.js +3 -1
  48. package/dist/server/render-tasks.js +10 -1
  49. package/dist/server/route-table.js +9 -0
  50. package/dist/server/settings.js +31 -7
  51. package/dist/server/task-views.js +15 -0
  52. package/dist/server/tasks.js +63 -3
  53. package/dist/settings-groups-ui.js +2 -2
  54. package/dist/store.js +29 -4
  55. package/dist/surface.js +9 -1
  56. package/dist/tui/darwin-arm64/toolroll-tui +0 -0
  57. package/dist/tui/darwin-x64/toolroll-tui +0 -0
  58. package/dist/tui/linux-arm64/toolroll-tui +0 -0
  59. package/dist/tui/linux-x64/toolroll-tui +0 -0
  60. package/dist/verification-evidence.js +17 -6
  61. package/dist/workspace-ui.js +1 -1
  62. package/package.json +2 -1
  63. package/scripts/release-proof.mjs +240 -0
@@ -1,3 +1,4 @@
1
+ import { mainJournalFile } from "./release-main.js";
1
2
  import { createHash } from "node:crypto";
2
3
  import { lstatSync, readdirSync, readFileSync, realpathSync } from "node:fs";
3
4
  import { join } from "node:path";
@@ -179,7 +180,7 @@ export function releaseCardLines(card) {
179
180
  const BRANCH = /^[A-Za-z0-9._/-]{1,255}$/;
180
181
  const TASK_ID = /^[A-Za-z0-9._-]{1,200}$/;
181
182
  const VERSION = /^\d+\.\d+\.\d+$/;
182
- export function readWaitingJournal(file, raw, expectedFile) {
183
+ export function readWaitingJournal(file, raw, expectedFile, expectedMainFile) {
183
184
  if (raw === null || typeof raw !== "object" || Array.isArray(raw))
184
185
  return null;
185
186
  const j = raw;
@@ -197,7 +198,7 @@ export function readWaitingJournal(file, raw, expectedFile) {
197
198
  return null;
198
199
  if (candidate === null || typeof candidate !== "object" || typeof candidate["sha"] !== "string" || !SHA.test(candidate["sha"]))
199
200
  return null;
200
- if (expectedFile(j["branch"]) !== file)
201
+ if (j["mode"] === "main" ? expectedMainFile === undefined || expectedMainFile(j["packageVersion"]) !== file : expectedFile(j["branch"]) !== file)
201
202
  return null;
202
203
  return { file, branch: j["branch"], checkout: j["checkout"], taskId: task["id"], scopeDigest: task["scopeDigest"], candidate: candidate["sha"], version: j["packageVersion"], pr: j["pr"] };
203
204
  }
@@ -226,15 +227,17 @@ export function journalMatchesPlane(store, journal, repo) {
226
227
  }
227
228
  export function waitingJournals(stateDir, expectedFile) {
228
229
  const folder = join(stateDir, "releases");
229
- let names = [];
230
- try {
231
- names = readdirSync(folder).filter(name => name.endsWith(".json"));
230
+ const list = (dir, prefix) => { try {
231
+ return readdirSync(dir).filter(name => name.endsWith(".json")).sort().map(name => `${prefix}${name}`);
232
232
  }
233
233
  catch {
234
+ return [];
235
+ } };
236
+ const names = [...list(folder, ""), ...list(join(folder, "from-main"), "from-main/")];
237
+ if (names.length === 0)
234
238
  return { journals: [], unreadable: [] };
235
- }
236
239
  const journals = [], unreadable = [];
237
- for (const name of names.sort()) {
240
+ for (const name of names) {
238
241
  const file = join(folder, name);
239
242
  let raw;
240
243
  try {
@@ -251,7 +254,7 @@ export function waitingJournals(stateDir, expectedFile) {
251
254
  const step = raw?.step;
252
255
  if (step !== "approval" && step !== "gate")
253
256
  continue;
254
- const read = readWaitingJournal(file, raw, expectedFile);
257
+ const read = readWaitingJournal(file, raw, expectedFile, version => mainJournalFile(stateDir, version));
255
258
  if (read === null)
256
259
  unreadable.push(name);
257
260
  else
@@ -65,7 +65,7 @@ export const RELEASE_TERM_LABELS = {
65
65
  export const RELEASE_CHECK_LABELS = {
66
66
  version: "Release check version", purpose: "Approved as", repo: "Repository", packageVersion: "Package version", branch: "Branch", pr: "Pull request",
67
67
  base: "Base", approvedSha: "Approved commit", approvedTree: "Approved tree", "grant.id": "Release check grant", "grant.digest": "Release check grant digest",
68
- access: "Release check access",
68
+ access: "Release check access", check: "Check on this Mac",
69
69
  };
70
70
  export function releaseSealOf(scope) {
71
71
  if (scope === null)
@@ -134,7 +134,12 @@ export function approvalTermsOf(store, scope, words) {
134
134
  if (terms === null && scope.releaseCheck != null) {
135
135
  const purpose = scope.releaseCheck;
136
136
  for (const path of schemaLeaves(releaseCheckPurposeSchema)) {
137
- const value = path === "pr" ? `#${purpose.pr}` : path === "purpose" ? "a release check: every later commit asks again" : path === "repo" ? where(purpose.repo) : said(valueAt(purpose, path));
137
+ if (path === "check" && purpose.check === undefined)
138
+ continue;
139
+ const value = path === "pr" ? `#${purpose.pr}`
140
+ : path === "purpose" ? purpose.purpose === "main-release" ? "a release from main: this commit, proven again before the deploy and the tag" : "a release check: every later commit asks again"
141
+ : path === "check" ? purpose.check === "deploy" ? "the deploy check: build, upgrade a copy of your database, start against it (about 4 minutes)" : "the full release check (about 40 minutes)"
142
+ : path === "repo" ? where(purpose.repo) : said(valueAt(purpose, path));
138
143
  lines.push({ key: `releaseCheck.${path}`, label: RELEASE_CHECK_LABELS[path] ?? path, value });
139
144
  }
140
145
  return lines;
@@ -129,7 +129,7 @@ export function releaseCheckPurposeFor(store, input) {
129
129
  if (grant === null)
130
130
  return { ok: false, why: "the project has no approved release check" };
131
131
  return { ok: true, purpose: {
132
- version: 1, purpose: "release-check", repo: input.repo, packageVersion: input.version, branch: input.branch, pr: input.pr, base: "main",
132
+ version: 1, ...(input.main === undefined ? { purpose: "release-check" } : { purpose: "main-release", check: input.main.check }), repo: input.repo, packageVersion: input.version, branch: input.branch, pr: input.pr, base: "main",
133
133
  approvedSha: input.candidate, approvedTree: commit.value.tree, grant: { id: grant.id, digest: grant.digest }, access: store.projectCheckAccess(input.repo),
134
134
  } };
135
135
  }
@@ -5,11 +5,12 @@ import { createRequire } from "node:module";
5
5
  const sqlite = () => createRequire(import.meta.url)("node:sqlite");
6
6
  import { checkedEnvelopeJson } from "./contracts/cli.js";
7
7
  import { RELEASE_LIMITS, runRelease } from "./release.js";
8
- import { processes, releaseAdapters } from "./release-adapters.js";
8
+ import { exec, prepareRelease, processes, readMainVersion, recordedReleaseRepo, releaseAdapters, releaseTools } from "./release-adapters.js";
9
+ import { mainRunKey, releaseBranchFor } from "./release-main.js";
9
10
  import { journals, releaseGate } from "./release-gate.js";
10
11
  import { rescueDeployment } from "./deploy-rescue.js";
11
12
  import { settleDeployment, takeReleaseRun } from "./release-next.js";
12
- import { databasePath, elapsedSeconds, latestReleaseStepTask, openStore, releaseProgressFor, revokeRelease } from "./store.js";
13
+ import { databasePath, elapsedSeconds, latestReleaseStepTask, openStore, readSchemaVersion, releaseProgressFor, revokeRelease, SCHEMA_VERSION } from "./store.js";
13
14
  import { dur, plural } from "./design/kit.js";
14
15
  import { carryRefusalWords, proveCarry, setAskEveryReleaseCommit, setUnsandboxedCarry } from "./release-carry.js";
15
16
  import { authenticateApprover, machineActing, personProof, proveCredential } from "./scope.js";
@@ -17,7 +18,25 @@ import { allowAutoPublish, setReleaseApproval } from "./release-auto.js";
17
18
  import { createNightlyCheckFlow } from "./nightly-check.js";
18
19
  import { aliasNightlyLane, optInGithubNightly, retireNightlyLane } from "./nightly-github.js";
19
20
  import { parseSchedule } from "./flow-schedule.js";
20
- export const RELEASE_HELP = `toolroll release <branch> — release Toolroll itself, from a pushed branch with an open pull request
21
+ export const RELEASE_HELP = `toolroll release [<version>] — release Toolroll from main: proves the version's release commit passed every
22
+ required check on its pull request, asks you, runs the deploy check on this Mac, deploys here, tags, publishes.
23
+
24
+ The release commit is main's squash merge of the release pull request from release-<version> (\`toolroll release
25
+ prepare\`). It is proven with publication's own proof before anything is filed, again right before the deploy and
26
+ again right before the tag; commits that land on main after it go in the next release. The deploy check builds it,
27
+ upgrades a copy of your database and starts it against that copy (about 4 minutes), after your approval: it runs
28
+ this commit's code with full access to this computer. With no version, main's own. Run the same command to go on
29
+ after any stop.
30
+
31
+ --full run the full release check on this Mac (about 40 minutes) instead of the deploy check
32
+
33
+ toolroll release prepare <version> [--notes <file>] — open the version pull request: a release-<version> branch from
34
+ main with only the version changed in package.json and package-lock.json, and the CHANGELOG entry (--notes, unless
35
+ CHANGELOG.md already has one). Merge it like any pull request once its checks pass, then run \`toolroll release
36
+ <version>\`.
37
+
38
+ toolroll release <branch> — the earlier way: release from a pushed branch with an open pull request (kept until the
39
+ releases it began are finished)
21
40
 
22
41
  First looks at the pull request's checks: a required check that failed stops before anything is filed or sent for
23
42
  approval, and checks not started or still running are named and waited for (stopping if they don't finish within
@@ -88,8 +107,9 @@ Options
88
107
  A runner's lease is returned with \`toolroll worker release <lease>\`.`;
89
108
  export const LEASE_SHAPED = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
90
109
  export const LEASE_DEPRECATION = "`toolroll release <lease>` is now `toolroll worker release <lease>`; the old form goes in the next minor version.";
91
- const VALUE_FLAGS = new Set(["--repo", "--limit", "--tap", "--release-gate", "--to", "--request", "--as", "--token", "--schedule", "--stage", "--lane-retire", "--branch"]);
92
- const BARE_FLAGS = new Set(["--new", "--json", "--help", "--yes", "--no-carry", "--start", "--recover-deploy", "--github"]);
110
+ const VALUE_FLAGS = new Set(["--repo", "--limit", "--tap", "--release-gate", "--to", "--request", "--as", "--token", "--schedule", "--stage", "--lane-retire", "--branch", "--notes"]);
111
+ const BARE_FLAGS = new Set(["--new", "--json", "--help", "--yes", "--no-carry", "--start", "--recover-deploy", "--github", "--full"]);
112
+ const VERSION_ARG = /^\d+\.\d+\.\d+$/;
93
113
  export async function runReleaseCommand(args, write, deps = {}) {
94
114
  const bare = new Set(args.filter(one => BARE_FLAGS.has(one)));
95
115
  const json = bare.has("--json");
@@ -102,7 +122,7 @@ export async function runReleaseCommand(args, write, deps = {}) {
102
122
  let stage, laneRetire, laneAlias;
103
123
  let branchFlag, literal = false, branchFlags = 0;
104
124
  const literalArgs = [];
105
- let repo, tap, gate, to, request, as, token, scheduleFlag;
125
+ let repo, tap, gate, to, request, as, token, scheduleFlag, notes;
106
126
  for (let i = 0; i < args.length; i += 1) {
107
127
  const raw = args[i];
108
128
  if (raw === "--" && !literal) {
@@ -156,6 +176,8 @@ export async function runReleaseCommand(args, write, deps = {}) {
156
176
  branchFlag = value;
157
177
  branchFlags += 1;
158
178
  }
179
+ else if (arg === "--notes")
180
+ notes = value;
159
181
  else {
160
182
  const match = /^([a-z]+)=([0-9]+)$/.exec(value);
161
183
  if (match === null || !(match[1] in RELEASE_LIMITS) || Number(match[2]) < 1)
@@ -211,10 +233,23 @@ export async function runReleaseCommand(args, write, deps = {}) {
211
233
  if (!named && ["carry", "revoke", "ask-every-commit", "unsandboxed-carry", "auto-approve", "publish-ok"].includes(positional[0] ?? "") && positional.length === 2) {
212
234
  return runAuthorityCommand(positional[0], positional[1], { to, request, as, token, repo: repo === undefined ? undefined : resolve(deps.cwd ?? process.cwd(), repo) }, write, json, deps);
213
235
  }
214
- if (!named && positional.length !== 1)
215
- return refuse("usage", `Which branch? \`toolroll release <branch>\`.\n${RELEASE_HELP}`, 2);
216
- const branch = branchFlag ?? literalArgs[0] ?? positional[0];
217
- if (!named && LEASE_SHAPED.test(branch)) {
236
+ if (!named && positional[0] === "prepare") {
237
+ if (positional.length !== 2 || !VERSION_ARG.test(positional[1]))
238
+ return refuse("usage", "`toolroll release prepare <version>` takes one version (0.9.119, say).", 2);
239
+ return runPrepareCommand(positional[1], { repo: resolve(deps.cwd ?? process.cwd(), repo ?? "."), notes: notes === undefined ? undefined : resolve(deps.cwd ?? process.cwd(), notes) }, write, json, deps);
240
+ }
241
+ if (notes !== undefined)
242
+ return refuse("usage", "--notes goes with `toolroll release prepare <version>`.", 2);
243
+ const fromMain = !named && (positional.length === 0 || (positional.length === 1 && VERSION_ARG.test(positional[0])));
244
+ if (fromMain && bare.has("--no-carry"))
245
+ return refuse("usage", "--no-carry doesn't apply to releases from main: nothing carries, the release commit never moves.", 2);
246
+ if (!fromMain && bare.has("--full"))
247
+ return refuse("usage", "--full goes with `toolroll release <version>`.", 2);
248
+ if (!fromMain && !named && positional.length !== 1)
249
+ return refuse("usage", `Which version? \`toolroll release <version>\`.\n${RELEASE_HELP}`, 2);
250
+ let version = fromMain ? positional[0] : undefined;
251
+ const branch = fromMain ? "" : branchFlag ?? literalArgs[0] ?? positional[0];
252
+ if (!fromMain && !named && LEASE_SHAPED.test(branch)) {
218
253
  const releaseOptions = args.filter(arg => VALUE_FLAGS.has(arg) || arg === "--new");
219
254
  if (releaseOptions.length > 0)
220
255
  return refuse("ambiguous", `${branch} looks like a lease id, but ${releaseOptions[0]} is a release option. Return a lease with \`toolroll worker release <lease>\`; a branch shaped like a lease id can't be released.`, 2);
@@ -223,10 +258,15 @@ export async function runReleaseCommand(args, write, deps = {}) {
223
258
  return refuse("usage", "This build can't return leases from here: use `toolroll worker release <lease>`.", 2);
224
259
  return deps.releaseLease(args);
225
260
  }
226
- if (!/^[A-Za-z0-9._/-]+$/.test(branch) || branch.startsWith("-") || branch.includes(".."))
261
+ if (!fromMain && (!/^[A-Za-z0-9._/-]+$/.test(branch) || branch.startsWith("-") || branch.includes("..")))
227
262
  return refuse("usage", `${branch} is not a branch name this command takes.`, 2);
228
263
  const checkout = resolve(deps.cwd ?? process.cwd(), repo ?? ".");
229
264
  const stateDir = deps.stateDir ?? dirname(databasePath(process.env, homedir()));
265
+ if (fromMain && deps.adapters === undefined) {
266
+ const problem = liveSchemaProblem(deps.database ?? databasePath(process.env, homedir()));
267
+ if (problem !== null)
268
+ return refuse("mixed-runtime", problem, 3);
269
+ }
230
270
  const lines = [];
231
271
  const say = (line) => { if (json)
232
272
  lines.push(line);
@@ -235,9 +275,21 @@ export async function runReleaseCommand(args, write, deps = {}) {
235
275
  const adapters = deps.adapters === undefined
236
276
  ? releaseAdapters({ checkout, say, ...(tap === undefined ? {} : { tap }), ...(limits["deploy"] === undefined ? {} : { deployMinutes: limits["deploy"] }) })
237
277
  : { ...deps.adapters, say };
238
- const taken = await takeReleaseRun(stateDir, branch, say, deps.runLock);
278
+ if (fromMain && version === undefined) {
279
+ const read = deps.mainVersion ?? (async () => readMainVersion(exec, releaseTools("").gh, await adapters.repo.github()));
280
+ try {
281
+ version = await read() ?? undefined;
282
+ }
283
+ catch (error) {
284
+ return refuse("github", `Couldn't read main's version from GitHub: ${error.message}. Name it: \`toolroll release <version>\`.`, 3);
285
+ }
286
+ if (version === undefined)
287
+ return refuse("usage", "Main's package.json names no version. Name it: `toolroll release <version>`.", 2);
288
+ }
289
+ const lockKey = version === undefined ? branch : mainRunKey(version);
290
+ const taken = await takeReleaseRun(stateDir, lockKey, say, deps.runLock);
239
291
  if (!taken.ok)
240
- return refuse("running", `Another release of ${branch} is still running on ${taken.holder.host} (process ${taken.holder.pid}). Nothing was changed.`, 3);
292
+ return refuse("running", `Another release of ${version ?? branch} is still running on ${taken.holder.host} (process ${taken.holder.pid}). Nothing was changed.`, 3);
241
293
  try {
242
294
  const world = deps.settle ?? (deps.adapters === undefined ? { rescue: installedRescueWorld(checkout), gate: installedGateWorld() } : null);
243
295
  if (world !== null) {
@@ -245,7 +297,8 @@ export async function runReleaseCommand(args, write, deps = {}) {
245
297
  if (!settled.ok)
246
298
  return refuse("deployment", settled.message, 3);
247
299
  }
248
- const outcome = await runRelease({ branch, checkout, stateDir, limits, fresh: bare.has("--new"), noCarry: bare.has("--no-carry") }, adapters);
300
+ const outcome = await runRelease({ branch: version === undefined ? branch : releaseBranchFor(version), checkout, stateDir, limits, fresh: bare.has("--new"), noCarry: bare.has("--no-carry"),
301
+ ...(version === undefined ? {} : { version, full: bare.has("--full") }) }, adapters);
249
302
  return report(outcome, write, json, lines);
250
303
  }
251
304
  finally {
@@ -561,3 +614,51 @@ async function runStatusCommand(task, write, json, deps) {
561
614
  store.close();
562
615
  }
563
616
  }
617
+ export function liveSchemaProblem(database) {
618
+ if (!existsSync(database))
619
+ return null;
620
+ let version = null;
621
+ try {
622
+ const db = new (sqlite().DatabaseSync)(database, { readOnly: true });
623
+ try {
624
+ const read = readSchemaVersion(db);
625
+ version = read.ok ? read.version : null;
626
+ }
627
+ finally {
628
+ db.close();
629
+ }
630
+ }
631
+ catch {
632
+ return "This computer's Toolroll database can't be read, so no release starts. Check it, then run the installed `toolroll release` again.";
633
+ }
634
+ if (version === null || version === SCHEMA_VERSION)
635
+ return null;
636
+ return `This Toolroll build (database schema ${SCHEMA_VERSION}) isn't the one this computer's database belongs to (schema ${version}): coordinating a release with it would ${version < SCHEMA_VERSION ? "upgrade the live database under the running services" : "use a database written by a newer build"}. Nothing was changed. Run \`toolroll release\` with the build this database belongs to${version < SCHEMA_VERSION ? " (the installed one)" : " (the one a deploy already put in place)"}.`;
637
+ }
638
+ async function runPrepareCommand(version, flags, write, json, deps) {
639
+ const command = "release prepare";
640
+ const answer = (ok, fields, words, code) => { write(json ? checkedEnvelopeJson({ ok, command, ...fields }) : words); return code; };
641
+ let notes = null;
642
+ if (flags.notes !== undefined) {
643
+ try {
644
+ notes = readFileSync(flags.notes, "utf8");
645
+ }
646
+ catch {
647
+ return answer(false, { reason: "usage", message: `${flags.notes} can't be read.` }, `${flags.notes} can't be read.`, 2);
648
+ }
649
+ }
650
+ const prepare = deps.prepare ?? (async (input) => {
651
+ const slug = recordedReleaseRepo(databasePath(process.env, homedir()), flags.repo).slug;
652
+ return { ...(await prepareRelease(exec, releaseTools("").gh, { repo: slug, version: input.version, notes: input.notes, date: new Date().toISOString().slice(0, 10) })), repo: slug };
653
+ });
654
+ let made;
655
+ try {
656
+ made = await prepare({ version, notes });
657
+ }
658
+ catch (error) {
659
+ return answer(false, { reason: "refused", message: error.message }, error.message, 1);
660
+ }
661
+ if (!made.ok)
662
+ return answer(false, { reason: "refused", message: `The release pull request for ${version} wasn't opened: ${made.why}.` }, `The release pull request for ${version} wasn't opened: ${made.why}.`, 1);
663
+ return answer(true, { version, pullRequest: made.pr, branch: made.branch, commit: made.commit }, `Opened pull request #${made.pr} (${made.branch}): the version and changelog for ${version}. Merge it like any pull request once its checks pass, then run \`toolroll release ${version}\`.`, 0);
664
+ }
@@ -0,0 +1,49 @@
1
+ export const MAIN_PROOF_ACTION = "main release proved";
2
+ export const MAIN_PROOF_FAILED_ACTION = "main release proof failed";
3
+ export const MAIN_PROOF_VALID_MS = 30 * 60_000;
4
+ const SHA = /^[0-9a-f]{40}$/;
5
+ export function recordMainReleaseProof(store, input) {
6
+ const { proof } = input;
7
+ if (![proof.sha, proof.tree, proof.head].every(one => SHA.test(one)) || !Number.isSafeInteger(proof.pr) || proof.pr < 1 || !/^[A-Za-z0-9._/-]{1,100}$/.test(proof.branch))
8
+ throw new Error("not a release proof this plane keeps");
9
+ const ref = store.lookupRef(input.taskId);
10
+ if (ref === null)
11
+ throw new Error(`no task ${input.taskId}`);
12
+ store.recordAction({ at: input.now.toISOString(), actor: "toolroll release", repo: ref.repo, taskId: input.taskId, runId: null, action: MAIN_PROOF_ACTION, outcome: input.version,
13
+ source: "work", detail: JSON.stringify({ sha: proof.sha, tree: proof.tree, pr: proof.pr, head: proof.head, branch: proof.branch }) });
14
+ }
15
+ export function recordMainReleaseProofFailure(store, input) {
16
+ const ref = store.lookupRef(input.taskId);
17
+ if (ref === null)
18
+ throw new Error(`no task ${input.taskId}`);
19
+ store.recordAction({ at: input.now.toISOString(), actor: "toolroll release", repo: ref.repo, taskId: input.taskId, runId: null, action: MAIN_PROOF_FAILED_ACTION, outcome: input.version,
20
+ source: "work", detail: input.why });
21
+ }
22
+ export function mainReleaseProofProblem(store, taskId, scope, now) {
23
+ const purpose = scope?.releaseCheck ?? null;
24
+ if (scope === null || purpose === null || purpose.purpose !== "main-release")
25
+ return "only a release from main deploys on the deploy check";
26
+ if (scope.approvedAt === null)
27
+ return "the release isn't approved";
28
+ const row = store.handle.prepare("SELECT at, action, detail FROM action_ledger WHERE task_id = ? AND action IN (?, ?) ORDER BY id DESC LIMIT 1").get(taskId, MAIN_PROOF_ACTION, MAIN_PROOF_FAILED_ACTION);
29
+ if (row === undefined)
30
+ return "the release commit's proof isn't recorded: run `toolroll release` to prove it";
31
+ if (row["action"] === MAIN_PROOF_FAILED_ACTION)
32
+ return `the release commit's last proof failed (${String(row["detail"] ?? "no reason kept")})`;
33
+ const age = now.getTime() - Date.parse(String(row["at"]));
34
+ if (!(age >= 0 && age < MAIN_PROOF_VALID_MS))
35
+ return "the release commit's proof is older than 30 minutes: run `toolroll release` to prove it again";
36
+ let facts;
37
+ try {
38
+ facts = JSON.parse(String(row["detail"]));
39
+ }
40
+ catch {
41
+ return "the release commit's proof can't be read";
42
+ }
43
+ if (Date.parse(String(row["at"])) < Date.parse(scope.approvedAt))
44
+ return "the release commit wasn't proven since it was approved: run `toolroll release` to prove it";
45
+ if (facts["sha"] !== purpose.approvedSha || facts["sha"] !== scope.candidate || facts["tree"] !== purpose.approvedTree || facts["pr"] !== purpose.pr || facts["branch"] !== purpose.branch) {
46
+ return "the recorded proof names another release commit than the one approved";
47
+ }
48
+ return null;
49
+ }
@@ -0,0 +1,110 @@
1
+ import { join } from "node:path";
2
+ export const VERSION_PATTERN = /^\d+\.\d+\.\d+$/;
3
+ export const releaseBranchFor = (version) => `release-${version}`;
4
+ export const mainJournalFile = (stateDir, version) => join(stateDir, "releases", "from-main", `${version}.json`);
5
+ export const mainRunKey = (version) => `from-main:${version}`;
6
+ export const mainResumeCommand = (version, checkout) => `toolroll release ${version} --repo ${checkout}`;
7
+ export function sameRelease(held, read) {
8
+ if (read.sha !== held.sha)
9
+ return `the release commit is now ${read.sha.slice(0, 7)}, not ${held.sha.slice(0, 7)}`;
10
+ if (read.tree !== held.tree)
11
+ return `${held.sha.slice(0, 7)}'s tree is now ${read.tree.slice(0, 12)}, not ${held.tree.slice(0, 12)}`;
12
+ if (read.pr !== held.pr)
13
+ return `${held.sha.slice(0, 7)} is now pull request #${read.pr}'s merge, not #${held.pr}'s`;
14
+ if (read.head !== held.head || read.branch !== held.branch)
15
+ return `pull request #${held.pr}'s tested head is now ${read.branch} at ${read.head.slice(0, 7)}, not ${held.branch} at ${held.head.slice(0, 7)}`;
16
+ return null;
17
+ }
18
+ export function firstParentAfter(head, sha, parents) {
19
+ const after = [];
20
+ const seen = new Set();
21
+ for (let at = head; at !== undefined; at = parents.get(at)?.[0]) {
22
+ if (at === sha)
23
+ return after;
24
+ if (seen.has(at) || !parents.has(at))
25
+ return null;
26
+ seen.add(at);
27
+ after.push(at);
28
+ }
29
+ return null;
30
+ }
31
+ function versionSpan(text, from, value) {
32
+ const pattern = /"version"\s*:\s*"/g;
33
+ pattern.lastIndex = from;
34
+ const found = pattern.exec(text);
35
+ if (found === null)
36
+ return null;
37
+ const start = found.index + found[0].length;
38
+ if (text.slice(start, start + value.length + 1) !== `${value}"`)
39
+ return null;
40
+ return { start, end: start + value.length };
41
+ }
42
+ function strictJson(text) {
43
+ let value;
44
+ try {
45
+ value = JSON.parse(text);
46
+ }
47
+ catch {
48
+ return null;
49
+ }
50
+ if (value === null || typeof value !== "object" || Array.isArray(value))
51
+ return null;
52
+ const tokens = (source) => JSON.stringify(source.match(/"(?:\\.|[^"\\])*"|[^\s"{}[\]:,]+|[{}[\]:,]/g));
53
+ return tokens(text) === tokens(JSON.stringify(value)) ? value : null;
54
+ }
55
+ export function bumpVersion(file, text, from, to) {
56
+ if (!VERSION_PATTERN.test(to) || !VERSION_PATTERN.test(from))
57
+ return null;
58
+ const before = strictJson(text);
59
+ if (before === null || before["version"] !== from)
60
+ return null;
61
+ const spans = [];
62
+ const first = versionSpan(text, 0, from);
63
+ if (first === null)
64
+ return null;
65
+ spans.push(first);
66
+ if (file === "package-lock.json") {
67
+ const packages = before["packages"];
68
+ if (packages?.[""]?.["version"] !== from)
69
+ return null;
70
+ const second = versionSpan(text, first.end, from);
71
+ if (second === null)
72
+ return null;
73
+ spans.push(second);
74
+ }
75
+ let out = text;
76
+ for (const span of [...spans].reverse())
77
+ out = `${out.slice(0, span.start)}${to}${out.slice(span.end)}`;
78
+ const after = strictJson(out);
79
+ if (after === null || after["version"] !== to)
80
+ return null;
81
+ const strip = (value) => {
82
+ const copy = structuredClone(value);
83
+ delete copy["version"];
84
+ const root = copy["packages"]?.[""];
85
+ if (file === "package-lock.json" && root !== undefined)
86
+ delete root["version"];
87
+ return JSON.stringify(copy);
88
+ };
89
+ if (strip(before) !== strip(after))
90
+ return null;
91
+ if (file === "package-lock.json" && after["packages"][""]?.["version"] !== to)
92
+ return null;
93
+ return out;
94
+ }
95
+ export function changelogWith(text, version, notes, date) {
96
+ const heading = `## ${version} — ${date}`;
97
+ const entry = `${heading}\n\n${notes.trim()}\n\n`;
98
+ const at = text.search(/^## /m);
99
+ return at === -1 ? `${text.replace(/\s*$/, "\n\n")}${entry}` : `${text.slice(0, at)}${entry}${text.slice(at)}`;
100
+ }
101
+ export function changelogHas(text, version) {
102
+ return new RegExp(`^## ${version.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}( |$)`, "m").test(text);
103
+ }
104
+ export const HARNESS_PATTERNS = [
105
+ /^\.github\/workflows\//, /^scripts\/(?:ci-|release-proof|release-check|gate-|guard-|browser-build|suite-lifecycle|upgrade-rule)/, /^vitest\.config\.ts$/,
106
+ /^test\/(?:setup|setup-state|ensure-build)\b/, /^package(?:-lock)?\.json$/, /^tsconfig[^/]*\.json$/, /^scripts\/gate-files\.json$/,
107
+ ];
108
+ export function harnessChanges(changed) {
109
+ return changed.filter(path => HARNESS_PATTERNS.some(pattern => pattern.test(path)));
110
+ }
@@ -1,6 +1,7 @@
1
- import { CHECK_CONTEXT_CAPTURE, CHECK_INVENTORY_CAPTURE, CHECK_REPORT_CAPTURE, OBLIGATION_SNAPSHOT_CAPTURE, TARGETED_PLAN_CAPTURE, checkContextOf, fullCheckProblem, isUnitFile, payloadDigest, projectGitDir, readSealedJson, treeFactsOf } from "./check-report.js";
1
+ import { purposeCheckMode } from "./contracts/release-terms.js";
2
+ import { CHECK_CONTEXT_CAPTURE, CHECK_INVENTORY_CAPTURE, CHECK_REPORT_CAPTURE, OBLIGATION_SNAPSHOT_CAPTURE, TARGETED_PLAN_CAPTURE, checkContextOf, deployCheckProblem, fullCheckProblem, isUnitFile, payloadDigest, projectGitDir, readSealedJson, treeFactsOf } from "./check-report.js";
2
3
  import { readVerifiedCommit, verifiedTreeDiff } from "./commit-extract.js";
3
- import { checkContextSchema, fileIdentity, groupIdentity, journeyIdentity, obligationSnapshotSchema, readCheckReport, sealedInventorySchema, targetedPlanSchema, unitIdentity, versionIdentity, } from "./contracts/release-check.js";
4
+ import { checkContextSchema, fileIdentity, groupIdentity, journeyIdentity, obligationSnapshotSchema, readCheckReport, sealedInventorySchema, targetedPlanSchema, unitIdentity, versionIdentity, CHECK_PARTS, } from "./contracts/release-check.js";
4
5
  import { parseContract } from "./contracts/contract.js";
5
6
  import { releaseAuthority, releaseAuthorityOfTask, releaseCarries } from "./release-authority.js";
6
7
  import { liveReleaseOf, releaseCheckScope } from "./scope.js";
@@ -244,7 +245,7 @@ export function planTargetedRecheck(store, root, input) {
244
245
  return full("the check runs somewhere other than the last full check did", watch);
245
246
  if (base.inventory.sealed.units.some(file => !facts.facts.units.includes(file)))
246
247
  return full("a unit file the last full check had is gone", watch);
247
- const journeysRan = base.report.parts.filter(one => one.ran).map(one => one.part);
248
+ const journeysRan = base.report.parts.filter(one => one.ran).map(one => one.part).filter((part) => CHECK_PARTS.includes(part));
248
249
  const plan = planFrom(base.run, { ...obligations, required: [...new Set([...obligations.required, ...owed])].sort(),
249
250
  units: [...new Set([...obligations.units, ...owed.flatMap(id => /^unit:(.+?)::/.exec(id)?.[1] ?? /^file:(.+)$/.exec(id)?.[1] ?? [])])].sort() }, snapshot, changed, facts.facts.units, journeysRan);
250
251
  return { mode: "targeted", authority: a.id, plan, snapshot, watch: plan.required };
@@ -414,6 +415,12 @@ export function settleCoverage(store, root, input, gateOf) {
414
415
  }
415
416
  return { coverage: "identity-removed", composed: null };
416
417
  };
418
+ if (b.attempt.mode === "full" && b.inventory?.sealed.deploy === true) {
419
+ const purpose = store.getScope(input.taskId)?.releaseCheck ?? null;
420
+ if (purposeCheckMode(purpose) !== "deploy" || deployCheckProblem({ report: b.report, inventory: b.inventory, exitCode: input.exitCode }) !== null)
421
+ return { coverage: "no-result", composed: null };
422
+ return { coverage: "deploy", composed: null };
423
+ }
417
424
  if (b.attempt.mode === "full") {
418
425
  if (b.attempt.authority !== null) {
419
426
  const watch = owedIdentities(store, root, b.attempt.authority, input.runId);