toolroll 0.9.127 → 0.9.129

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 (57) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +2 -1
  3. package/dist/accent-colors.js +3 -1
  4. package/dist/approval-authority.js +2 -1
  5. package/dist/assignment.js +55 -2
  6. package/dist/backup.js +6 -0
  7. package/dist/browser/terminal.css +1 -1
  8. package/dist/browser/workspace.css +2 -2
  9. package/dist/browser/workspace.js +9 -9
  10. package/dist/central-recovery-stage.js +3 -3
  11. package/dist/companion/access.js +161 -0
  12. package/dist/companion/actions.js +559 -0
  13. package/dist/companion/bonjour.js +45 -0
  14. package/dist/companion/daemon.js +1346 -0
  15. package/dist/companion/direct-server.js +177 -0
  16. package/dist/companion/framing.js +498 -0
  17. package/dist/companion/noise.js +461 -0
  18. package/dist/companion/passkey-gate.js +287 -0
  19. package/dist/companion/paths.js +90 -0
  20. package/dist/companion/reads.js +279 -0
  21. package/dist/companion/relay-auth.js +265 -0
  22. package/dist/companion/relay-server.js +870 -0
  23. package/dist/companion/schema.js +225 -0
  24. package/dist/companion/service.js +580 -0
  25. package/dist/companion/store.js +324 -0
  26. package/dist/companion/webauthn-test-support.js +44 -0
  27. package/dist/companion/webauthn.js +398 -0
  28. package/dist/contracts/console-api.js +18 -0
  29. package/dist/demo.js +1 -1
  30. package/dist/design/kit.css +36 -3
  31. package/dist/local-landing.js +47 -0
  32. package/dist/models-ui.js +5 -2
  33. package/dist/operate.js +19 -3
  34. package/dist/person-proof.js +5 -1
  35. package/dist/pull-request-flow.js +75 -2
  36. package/dist/qr.js +385 -0
  37. package/dist/release-adapters.js +2 -1
  38. package/dist/restore-retirement.js +2 -0
  39. package/dist/scope.js +67 -4
  40. package/dist/serve.js +31 -4
  41. package/dist/server/pages.js +9 -2
  42. package/dist/server/phone-engine-api.js +59 -0
  43. package/dist/server/route-table.js +11 -0
  44. package/dist/server/settings-phone.js +492 -0
  45. package/dist/server/settings-scripts.js +2 -0
  46. package/dist/server/settings-sections.js +6 -2
  47. package/dist/server/settings.js +8 -2
  48. package/dist/settings-groups-ui.js +2 -1
  49. package/dist/settings-proofs.js +6 -0
  50. package/dist/skills-ui.js +11 -6
  51. package/dist/spend-ui.js +3 -2
  52. package/dist/spend.js +8 -1
  53. package/dist/store.js +37 -4
  54. package/dist/tailnet.js +42 -0
  55. package/dist/toolroll-update.js +3 -1
  56. package/dist/youiyoux-intake.js +8 -0
  57. package/package.json +7 -2
package/dist/operate.js CHANGED
@@ -289,6 +289,21 @@ import { loginFileOf, migrateLegacyLogin, removeStaleSavedLogin, savedLoginFile,
289
289
  import { runWords } from "./needs-you.js";
290
290
  export const EXIT = { ok: 0, failed: 1, usage: 2, refused: 3 };
291
291
  const STATES = ["queued", "running", "done", "failed", "cancelled"];
292
+ export const TASK_HELP = `toolroll task — create, inspect, and ship tasks
293
+
294
+ toolroll task add "<change>" --repo . queue a task (--plan to review plan first; --checks quick|full|off)
295
+ toolroll task list [--view <v>] list tasks (needs-you, ready, running, queued, completed, archived)
296
+ toolroll task show <id> current state, diff summary, checks, and next action
297
+ toolroll task wait <id> [--timeout <s>] wait until this attempt finishes or needs you
298
+ toolroll task accept <id> accept a Ready result
299
+ toolroll task revise <id> --note "<text>" send a result back with feedback (catches up with main automatically)
300
+ toolroll task land <id> fast-forward or merge an accepted result onto your local branch
301
+ toolroll task stop <id> stop a running build
302
+ toolroll task retry <id> retry a failed or stopped task
303
+ toolroll task archive <id...> put tasks away (history kept; restore with \`task restore\`)
304
+ toolroll task evidence <id> [--html] export a task's evidence pack
305
+
306
+ Every command supports --json. Everything else: \`toolroll internals\`.`;
292
307
  export const OPERATE_HELP = `toolroll — operating the queue
293
308
 
294
309
  toolroll status running, queued, ready results, release check and plan windows
@@ -855,11 +870,12 @@ async function runOperateLocal(command, argv, write, options = {}) {
855
870
  const { positional, flags } = parsed;
856
871
  const json = flags.has("json");
857
872
  if (flags.has("help")) {
873
+ const helpText = command === "task" && positional.length === 0 ? TASK_HELP : OPERATE_HELP;
858
874
  if (json) {
859
- write(envelopeJson({ ok: true, command: "help", help: OPERATE_HELP }));
875
+ write(envelopeJson({ ok: true, command: "help", help: helpText }));
860
876
  }
861
877
  else {
862
- write(OPERATE_HELP);
878
+ write(helpText);
863
879
  }
864
880
  return EXIT.ok;
865
881
  }
@@ -7638,7 +7654,7 @@ async function waitTask(positional, flags, context) {
7638
7654
  function taskCommand(positional, flags, context) {
7639
7655
  const [action, ...rest] = positional;
7640
7656
  if (action === undefined) {
7641
- context.write(OPERATE_HELP);
7657
+ context.write(TASK_HELP);
7642
7658
  return EXIT.ok;
7643
7659
  }
7644
7660
  const actor = currentActor();
@@ -3,7 +3,11 @@ const METHOD_IS_PERSON = {
3
3
  "remote-token": false, "lead-token": false,
4
4
  "local-owner": true,
5
5
  };
6
- const OTHER_PERSON_PROOFS = new Set(["chat", "passkey"]);
6
+ const OTHER_PERSON_PROOFS = new Set(["chat", "passkey", "passkey-fresh"]);
7
+ export const PERSON_PROOFS = Object.freeze([
8
+ ...Object.entries(METHOD_IS_PERSON).filter(([, person]) => person).map(([method]) => method),
9
+ ...OTHER_PERSON_PROOFS,
10
+ ]);
7
11
  export function personProof(proof) {
8
12
  if (typeof proof !== "string")
9
13
  return false;
@@ -14,6 +14,8 @@ import { NIGHTLY_CHECK_ONLY, RELEASE_MERGES_ONLY, nightlyTaskRef, refArchived, r
14
14
  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
+ import { checkPasskeyAction, consumePasskeyAction } from "./companion/passkey-gate.js";
18
+ import { passkeyProofDetail } from "./companion/webauthn.js";
17
19
  export const MERGE_METHODS = ["squash", "merge", "rebase"];
18
20
  export const MAX_CI_REVISIONS = 2;
19
21
  export const MERGED_ACTION = "pull request merged";
@@ -341,10 +343,69 @@ function askPerson(store, publication, head, body, clock) {
341
343
  }, clock());
342
344
  });
343
345
  }
346
+ export const MERGE_PROVED_ACTION = "merge proved";
344
347
  export async function mergeAsPerson(store, input) {
345
348
  const run = store.getRun(input.runId);
346
- const repo = run === null ? null : store.refById(run.taskRef)?.repo ?? null;
347
- if (input.password === "")
349
+ const taskRef = run === null ? null : store.refById(run.taskRef);
350
+ const repo = taskRef?.repo ?? null;
351
+ const clock = input.clock ?? (() => new Date());
352
+ if (input.passkey !== undefined) {
353
+ const publication = store.publicationForRun(input.runId);
354
+ const grant = repo === null ? null : store.publicationGrantFor(repo);
355
+ if (publication === null || publication.prNumber === null || taskRef === null) {
356
+ return refuse("no-pr", "This result has no open pull request to merge.");
357
+ }
358
+ 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, {
372
+ runId: input.runId,
373
+ by: input.name,
374
+ ...(input.anyway === true ? { anyway: true } : {}),
375
+ ...(input.exec === undefined ? {} : { exec: input.exec }),
376
+ ...(input.clock === undefined ? {} : { clock: input.clock }),
377
+ beforeReserve: seen => {
378
+ if (seen.head !== publication.headSha)
379
+ return { ok: false, message: "The pull request head moved before merging." };
380
+ const now = clock();
381
+ const consumed = consumePasskeyAction(store, checked, { repo, now });
382
+ if (!consumed.ok)
383
+ return { ok: false, message: consumed.message };
384
+ store.recordAction({
385
+ at: now.toISOString(),
386
+ actor: input.name,
387
+ repo,
388
+ taskId: taskRef.externalId,
389
+ runId: input.runId,
390
+ action: MERGE_PROVED_ACTION,
391
+ outcome: "passkey",
392
+ source: "request",
393
+ detail: passkeyProofDetail({
394
+ at: now,
395
+ generation: consumed.accountGeneration,
396
+ digest: publication.headSha,
397
+ verb: "ship",
398
+ credentialId: consumed.credentialId,
399
+ pairedDeviceId: consumed.deviceId,
400
+ be: consumed.be,
401
+ bs: consumed.bs,
402
+ }),
403
+ });
404
+ return { ok: true };
405
+ },
406
+ });
407
+ }
408
+ if (input.password === undefined || input.password === "")
348
409
  return refuse("password", "Enter your password to merge.");
349
410
  const proved = authenticateApprover(store, input.name, input.password, repo);
350
411
  if (!proved.ok)
@@ -447,6 +508,7 @@ export async function mergePullRequest(store, input) {
447
508
  return fail("checks", before.checks === "failing" ? "Checks are failing, so it can't merge." : before.checks === "running" ? "Checks are still running. Merge once they pass." : "No checks have reported yet. Merge once they pass.");
448
509
  const token = randomUUID();
449
510
  let reserved;
511
+ let passkeyRefusedMsg = "Passkey verification failed.";
450
512
  try {
451
513
  reserved = store.transact(() => {
452
514
  if (fullCheckGate(store, publication.run, clock()).state === "recovery-held")
@@ -464,6 +526,13 @@ export async function mergePullRequest(store, input) {
464
526
  const reservedAt = clock();
465
527
  if (fullCheckGate(store, publication.run, reservedAt).state === "recovery-held")
466
528
  throw new RecoveryHeldReservation();
529
+ if (input.beforeReserve !== undefined) {
530
+ const check = input.beforeReserve({ base: before.base, url: before.url, head: before.head });
531
+ if (!check.ok) {
532
+ passkeyRefusedMsg = check.message;
533
+ return "passkey-refused";
534
+ }
535
+ }
467
536
  store.handle.prepare("INSERT OR REPLACE INTO merge_in_flight (publication, task_ref, token, by, at) VALUES (?, ?, ?, ?, ?)").run(publication.id, publication.taskRef, token, input.by, reservedAt.toISOString());
468
537
  return "ok";
469
538
  });
@@ -473,6 +542,8 @@ export async function mergePullRequest(store, input) {
473
542
  return refuse("recovery-held", "Checks are on hold after recovery. Earlier execution is unverified.");
474
543
  throw error;
475
544
  }
545
+ if (reserved === "passkey-refused")
546
+ return refuse("password", passkeyRefusedMsg);
476
547
  if (reserved === "recovery-held")
477
548
  return refuse("recovery-held", "Checks are on hold after recovery. Earlier execution is unverified.");
478
549
  if (reserved === "halted")
@@ -500,6 +571,8 @@ export async function mergePullRequest(store, input) {
500
571
  }
501
572
  if (merged.code === 4)
502
573
  return fail("gh-signed-out", "The GitHub CLI isn't signed in on this computer. Run gh auth login, then merge again.");
574
+ if (after === null)
575
+ return fail("unconfirmed", "GitHub couldn't be read after the merge ran, so whether it merged isn't known yet. Refresh before trying again.");
503
576
  return fail("refused", `GitHub didn't merge it: ${plain(firstLine(merged.stderr) || "no reason given", 200)}`);
504
577
  }
505
578
  export function pullRequestViewOf(store, runId) {
package/dist/qr.js ADDED
@@ -0,0 +1,385 @@
1
+ const ECC_ORDINAL = { L: 0, M: 1, Q: 2, H: 3 };
2
+ const ECC_FORMAT_BITS = { L: 1, M: 0, Q: 3, H: 2 };
3
+ const ECC_CODEWORDS_PER_BLOCK = [
4
+ [-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
5
+ [-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28],
6
+ [-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
7
+ [-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
8
+ ];
9
+ const NUM_ERROR_CORRECTION_BLOCKS = [
10
+ [-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25],
11
+ [-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49],
12
+ [-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68],
13
+ [-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81],
14
+ ];
15
+ const PENALTY_N1 = 3, PENALTY_N2 = 3, PENALTY_N3 = 40, PENALTY_N4 = 10;
16
+ export function encodeQr(data, ecc = "M") {
17
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
18
+ let version = 1;
19
+ let dataUsedBits = 0;
20
+ for (;; version++) {
21
+ const capacityBits = numDataCodewords(version, ecc) * 8;
22
+ dataUsedBits = 4 + (version <= 9 ? 8 : 16) + bytes.length * 8;
23
+ if (dataUsedBits <= capacityBits)
24
+ break;
25
+ if (version >= 40)
26
+ throw new RangeError("Data too long for a QR code");
27
+ }
28
+ let level = ecc;
29
+ for (const better of ["M", "Q", "H"]) {
30
+ if (ECC_ORDINAL[better] > ECC_ORDINAL[level] && dataUsedBits <= numDataCodewords(version, better) * 8)
31
+ level = better;
32
+ }
33
+ const bits = [];
34
+ appendBits(bits, 0x4, 4);
35
+ appendBits(bits, bytes.length, version <= 9 ? 8 : 16);
36
+ for (const b of bytes)
37
+ appendBits(bits, b, 8);
38
+ const capacityBits = numDataCodewords(version, level) * 8;
39
+ appendBits(bits, 0, Math.min(4, capacityBits - bits.length));
40
+ appendBits(bits, 0, (8 - (bits.length % 8)) % 8);
41
+ for (let pad = 0xec; bits.length < capacityBits; pad ^= 0xec ^ 0x11)
42
+ appendBits(bits, pad, 8);
43
+ const dataCodewords = new Array(bits.length / 8).fill(0);
44
+ bits.forEach((bit, i) => { dataCodewords[i >>> 3] = (dataCodewords[i >>> 3] ?? 0) | (bit << (7 - (i & 7))); });
45
+ const symbol = new QrSymbol(version, level);
46
+ symbol.drawFunctionPatterns();
47
+ symbol.drawCodewords(symbol.addEccAndInterleave(dataCodewords));
48
+ let bestMask = 0, minPenalty = Infinity;
49
+ for (let mask = 0; mask < 8; mask++) {
50
+ symbol.applyMask(mask);
51
+ symbol.drawFormatBits(mask);
52
+ const penalty = symbol.penaltyScore();
53
+ if (penalty < minPenalty) {
54
+ bestMask = mask;
55
+ minPenalty = penalty;
56
+ }
57
+ symbol.applyMask(mask);
58
+ }
59
+ symbol.applyMask(bestMask);
60
+ symbol.drawFormatBits(bestMask);
61
+ const modules = symbol.modules, size = symbol.size;
62
+ return { version, size, ecc: level, mask: bestMask, dark: (x, y) => x >= 0 && y >= 0 && x < size && y < size && modules[y][x] };
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
+ function appendBits(out, value, length) {
90
+ for (let i = length - 1; i >= 0; i--)
91
+ out.push((value >>> i) & 1);
92
+ }
93
+ function numRawDataModules(version) {
94
+ let result = (16 * version + 128) * version + 64;
95
+ if (version >= 2) {
96
+ const numAlign = Math.floor(version / 7) + 2;
97
+ result -= (25 * numAlign - 10) * numAlign - 55;
98
+ if (version >= 7)
99
+ result -= 36;
100
+ }
101
+ return result;
102
+ }
103
+ function numDataCodewords(version, ecc) {
104
+ const o = ECC_ORDINAL[ecc];
105
+ return Math.floor(numRawDataModules(version) / 8) - ECC_CODEWORDS_PER_BLOCK[o][version] * NUM_ERROR_CORRECTION_BLOCKS[o][version];
106
+ }
107
+ function rsMultiply(x, y) {
108
+ let z = 0;
109
+ for (let i = 7; i >= 0; i--) {
110
+ z = (z << 1) ^ ((z >>> 7) * 0x11d);
111
+ z ^= ((y >>> i) & 1) * x;
112
+ }
113
+ return z & 0xff;
114
+ }
115
+ function rsDivisor(degree) {
116
+ const result = new Array(degree).fill(0);
117
+ result[degree - 1] = 1;
118
+ let root = 1;
119
+ for (let i = 0; i < degree; i++) {
120
+ for (let j = 0; j < result.length; j++) {
121
+ result[j] = rsMultiply(result[j], root);
122
+ if (j + 1 < result.length)
123
+ result[j] = result[j] ^ result[j + 1];
124
+ }
125
+ root = rsMultiply(root, 0x02);
126
+ }
127
+ return result;
128
+ }
129
+ function rsRemainder(data, divisor) {
130
+ const result = divisor.map(() => 0);
131
+ for (const b of data) {
132
+ const factor = b ^ result.shift();
133
+ result.push(0);
134
+ divisor.forEach((coef, i) => { result[i] = result[i] ^ rsMultiply(coef, factor); });
135
+ }
136
+ return result;
137
+ }
138
+ class QrSymbol {
139
+ version;
140
+ ecc;
141
+ size;
142
+ modules;
143
+ isFunction;
144
+ constructor(version, ecc) {
145
+ this.version = version;
146
+ this.ecc = ecc;
147
+ this.size = version * 4 + 17;
148
+ this.modules = Array.from({ length: this.size }, () => new Array(this.size).fill(false));
149
+ this.isFunction = Array.from({ length: this.size }, () => new Array(this.size).fill(false));
150
+ }
151
+ set(x, y, dark) {
152
+ this.modules[y][x] = dark;
153
+ this.isFunction[y][x] = true;
154
+ }
155
+ drawFunctionPatterns() {
156
+ for (let i = 0; i < this.size; i++) {
157
+ this.set(6, i, i % 2 === 0);
158
+ this.set(i, 6, i % 2 === 0);
159
+ }
160
+ this.drawFinder(3, 3);
161
+ this.drawFinder(this.size - 4, 3);
162
+ this.drawFinder(3, this.size - 4);
163
+ const align = this.alignmentPositions(), n = align.length;
164
+ for (let i = 0; i < n; i++)
165
+ for (let j = 0; j < n; j++) {
166
+ if (!((i === 0 && j === 0) || (i === 0 && j === n - 1) || (i === n - 1 && j === 0)))
167
+ this.drawAlignment(align[i], align[j]);
168
+ }
169
+ this.drawFormatBits(0);
170
+ this.drawVersion();
171
+ }
172
+ drawFormatBits(mask) {
173
+ const data = (ECC_FORMAT_BITS[this.ecc] << 3) | mask;
174
+ let rem = data;
175
+ for (let i = 0; i < 10; i++)
176
+ rem = (rem << 1) ^ ((rem >>> 9) * 0x537);
177
+ const bits = ((data << 10) | rem) ^ 0x5412;
178
+ const bit = (i) => ((bits >>> i) & 1) !== 0;
179
+ for (let i = 0; i <= 5; i++)
180
+ this.set(8, i, bit(i));
181
+ this.set(8, 7, bit(6));
182
+ this.set(8, 8, bit(7));
183
+ this.set(7, 8, bit(8));
184
+ for (let i = 9; i < 15; i++)
185
+ this.set(14 - i, 8, bit(i));
186
+ for (let i = 0; i < 8; i++)
187
+ this.set(this.size - 1 - i, 8, bit(i));
188
+ for (let i = 8; i < 15; i++)
189
+ this.set(8, this.size - 15 + i, bit(i));
190
+ this.set(8, this.size - 8, true);
191
+ }
192
+ drawVersion() {
193
+ if (this.version < 7)
194
+ return;
195
+ let rem = this.version;
196
+ for (let i = 0; i < 12; i++)
197
+ rem = (rem << 1) ^ ((rem >>> 11) * 0x1f25);
198
+ const bits = (this.version << 12) | rem;
199
+ for (let i = 0; i < 18; i++) {
200
+ const dark = ((bits >>> i) & 1) !== 0, a = this.size - 11 + (i % 3), b = Math.floor(i / 3);
201
+ this.set(a, b, dark);
202
+ this.set(b, a, dark);
203
+ }
204
+ }
205
+ drawFinder(x, y) {
206
+ for (let dy = -4; dy <= 4; dy++)
207
+ for (let dx = -4; dx <= 4; dx++) {
208
+ const dist = Math.max(Math.abs(dx), Math.abs(dy)), xx = x + dx, yy = y + dy;
209
+ if (xx >= 0 && xx < this.size && yy >= 0 && yy < this.size)
210
+ this.set(xx, yy, dist !== 2 && dist !== 4);
211
+ }
212
+ }
213
+ drawAlignment(x, y) {
214
+ for (let dy = -2; dy <= 2; dy++)
215
+ for (let dx = -2; dx <= 2; dx++)
216
+ this.set(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1);
217
+ }
218
+ alignmentPositions() {
219
+ if (this.version === 1)
220
+ return [];
221
+ const numAlign = Math.floor(this.version / 7) + 2;
222
+ const step = this.version === 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
223
+ const result = [6];
224
+ for (let pos = this.size - 7; result.length < numAlign; pos -= step)
225
+ result.splice(1, 0, pos);
226
+ return result;
227
+ }
228
+ addEccAndInterleave(data) {
229
+ const o = ECC_ORDINAL[this.ecc];
230
+ const numBlocks = NUM_ERROR_CORRECTION_BLOCKS[o][this.version];
231
+ const blockEccLen = ECC_CODEWORDS_PER_BLOCK[o][this.version];
232
+ const rawCodewords = Math.floor(numRawDataModules(this.version) / 8);
233
+ const numShortBlocks = numBlocks - (rawCodewords % numBlocks);
234
+ const shortBlockLen = Math.floor(rawCodewords / numBlocks);
235
+ const blocks = [];
236
+ const divisor = rsDivisor(blockEccLen);
237
+ for (let i = 0, k = 0; i < numBlocks; i++) {
238
+ const dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
239
+ k += dat.length;
240
+ const ecc = rsRemainder(dat, divisor);
241
+ if (i < numShortBlocks)
242
+ dat.push(0);
243
+ blocks.push(dat.concat(ecc));
244
+ }
245
+ const result = [];
246
+ for (let i = 0; i < blocks[0].length; i++) {
247
+ blocks.forEach((block, j) => {
248
+ if (i !== shortBlockLen - blockEccLen || j >= numShortBlocks)
249
+ result.push(block[i]);
250
+ });
251
+ }
252
+ return result;
253
+ }
254
+ drawCodewords(data) {
255
+ let i = 0;
256
+ for (let right = this.size - 1; right >= 1; right -= 2) {
257
+ if (right === 6)
258
+ right = 5;
259
+ for (let vert = 0; vert < this.size; vert++) {
260
+ for (let j = 0; j < 2; j++) {
261
+ const x = right - j, upward = ((right + 1) & 2) === 0, y = upward ? this.size - 1 - vert : vert;
262
+ if (!this.isFunction[y][x] && i < data.length * 8) {
263
+ this.modules[y][x] = ((data[i >>> 3] >>> (7 - (i & 7))) & 1) !== 0;
264
+ i++;
265
+ }
266
+ }
267
+ }
268
+ }
269
+ }
270
+ applyMask(mask) {
271
+ for (let y = 0; y < this.size; y++)
272
+ for (let x = 0; x < this.size; x++) {
273
+ let invert;
274
+ switch (mask) {
275
+ case 0:
276
+ invert = (x + y) % 2 === 0;
277
+ break;
278
+ case 1:
279
+ invert = y % 2 === 0;
280
+ break;
281
+ case 2:
282
+ invert = x % 3 === 0;
283
+ break;
284
+ case 3:
285
+ invert = (x + y) % 3 === 0;
286
+ break;
287
+ case 4:
288
+ invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;
289
+ break;
290
+ case 5:
291
+ invert = ((x * y) % 2) + ((x * y) % 3) === 0;
292
+ break;
293
+ case 6:
294
+ invert = (((x * y) % 2) + ((x * y) % 3)) % 2 === 0;
295
+ break;
296
+ default:
297
+ invert = (((x + y) % 2) + ((x * y) % 3)) % 2 === 0;
298
+ break;
299
+ }
300
+ if (!this.isFunction[y][x] && invert)
301
+ this.modules[y][x] = !this.modules[y][x];
302
+ }
303
+ }
304
+ penaltyScore() {
305
+ let result = 0;
306
+ const size = this.size, m = this.modules;
307
+ for (let y = 0; y < size; y++) {
308
+ let runColor = false, runX = 0;
309
+ const history = [0, 0, 0, 0, 0, 0, 0];
310
+ for (let x = 0; x < size; x++) {
311
+ if (m[y][x] === runColor) {
312
+ runX++;
313
+ if (runX === 5)
314
+ result += PENALTY_N1;
315
+ else if (runX > 5)
316
+ result++;
317
+ }
318
+ else {
319
+ this.finderHistoryAdd(runX, history);
320
+ if (!runColor)
321
+ result += this.finderPenaltyCount(history) * PENALTY_N3;
322
+ runColor = m[y][x];
323
+ runX = 1;
324
+ }
325
+ }
326
+ result += this.finderTerminate(runColor, runX, history) * PENALTY_N3;
327
+ }
328
+ for (let x = 0; x < size; x++) {
329
+ let runColor = false, runY = 0;
330
+ const history = [0, 0, 0, 0, 0, 0, 0];
331
+ for (let y = 0; y < size; y++) {
332
+ if (m[y][x] === runColor) {
333
+ runY++;
334
+ if (runY === 5)
335
+ result += PENALTY_N1;
336
+ else if (runY > 5)
337
+ result++;
338
+ }
339
+ else {
340
+ this.finderHistoryAdd(runY, history);
341
+ if (!runColor)
342
+ result += this.finderPenaltyCount(history) * PENALTY_N3;
343
+ runColor = m[y][x];
344
+ runY = 1;
345
+ }
346
+ }
347
+ result += this.finderTerminate(runColor, runY, history) * PENALTY_N3;
348
+ }
349
+ for (let y = 0; y < size - 1; y++)
350
+ for (let x = 0; x < size - 1; x++) {
351
+ const c = m[y][x];
352
+ if (c === m[y][x + 1] && c === m[y + 1][x] && c === m[y + 1][x + 1])
353
+ result += PENALTY_N2;
354
+ }
355
+ let dark = 0;
356
+ for (const row of m)
357
+ for (const v of row)
358
+ if (v)
359
+ dark++;
360
+ const total = size * size;
361
+ const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
362
+ result += k * PENALTY_N4;
363
+ return result;
364
+ }
365
+ finderPenaltyCount(h) {
366
+ const n = h[1];
367
+ const core = n > 0 && h[2] === n && h[3] === n * 3 && h[4] === n && h[5] === n;
368
+ return (core && h[0] >= n * 4 && h[6] >= n ? 1 : 0) + (core && h[6] >= n * 4 && h[0] >= n ? 1 : 0);
369
+ }
370
+ finderTerminate(runColor, run, history) {
371
+ if (runColor) {
372
+ this.finderHistoryAdd(run, history);
373
+ run = 0;
374
+ }
375
+ run += this.size;
376
+ this.finderHistoryAdd(run, history);
377
+ return this.finderPenaltyCount(history);
378
+ }
379
+ finderHistoryAdd(run, history) {
380
+ if (history[0] === 0)
381
+ run += this.size;
382
+ history.pop();
383
+ history.unshift(run);
384
+ }
385
+ }
@@ -1423,7 +1423,8 @@ async function macosCasesOf(run, gh, slug, sha) {
1423
1423
  }
1424
1424
  export function githubJson(run, gh) {
1425
1425
  return async (path) => {
1426
- if (!/^repos\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_./?&=%:+-]+$/.test(path) || path.includes(".."))
1426
+ const compare = /^repos\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/compare\/(?:[0-9a-f]{40}|v\d+\.\d+\.\d+)\.\.\.[0-9a-f]{40}(?:\?per_page=\d+)?$/.test(path);
1427
+ if (!/^repos\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_./?&=%:+-]+$/.test(path) || (path.includes("..") && !compare))
1427
1428
  throw new Error(`not a GitHub read this makes: ${path.slice(0, 120)}`);
1428
1429
  const out = await run(gh, ["api", "--hostname", "github.com", "--method", "GET", path], { cwd: "/", env: ciEnv() });
1429
1430
  if (out.code !== 0)
@@ -1,5 +1,6 @@
1
1
  import { randomBytes } from "node:crypto";
2
2
  import { ChatCore } from "./chat-core.js";
3
+ import { retireCompanionOnRestore } from "./companion/store.js";
3
4
  import { CHAT_PROVIDERS } from "./contracts/chat-tables.js";
4
5
  import { revokeCoordinator } from "./coordinator.js";
5
6
  import { autoPublishHeld, holdAutoPublish, PUBLISH_ALLOWED_ACTION, PUBLISH_HELD_ACTION } from "./release-auto.js";
@@ -107,6 +108,7 @@ export function retireRestoredAuthority(store, options) {
107
108
  for (const table of CHAT_DECIDE_TABLES)
108
109
  store.handle.prepare(`UPDATE ${table} SET consumed_at = ? WHERE consumed_at IS NULL`).run(stamp);
109
110
  store.handle.prepare("UPDATE chat_note_draft SET state = 'discarded' WHERE state IN ('pending', 'armed')").run();
111
+ retireCompanionOnRestore(store.handle);
110
112
  const afterIdentity = store.workspaceIdentity();
111
113
  if (afterIdentity.id !== identity.id || afterIdentity.recoveryGeneration !== nextGeneration || excluded.has(afterIdentity.recoveryGeneration)) {
112
114
  throw new Error("Restored workspace identity postcondition failed");