toolroll 0.9.128 → 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.
- package/CHANGELOG.md +17 -0
- package/dist/accent-colors.js +3 -1
- package/dist/approval-authority.js +2 -1
- package/dist/assignment.js +55 -2
- package/dist/backup.js +6 -0
- package/dist/browser/terminal.css +1 -1
- package/dist/browser/workspace.css +1 -1
- package/dist/central-recovery-stage.js +3 -3
- package/dist/companion/access.js +161 -0
- package/dist/companion/actions.js +559 -0
- package/dist/companion/bonjour.js +45 -0
- package/dist/companion/daemon.js +1346 -0
- package/dist/companion/direct-server.js +177 -0
- package/dist/companion/framing.js +498 -0
- package/dist/companion/noise.js +461 -0
- package/dist/companion/passkey-gate.js +287 -0
- package/dist/companion/paths.js +90 -0
- package/dist/companion/reads.js +279 -0
- package/dist/companion/relay-auth.js +265 -0
- package/dist/companion/relay-server.js +870 -0
- package/dist/companion/schema.js +225 -0
- package/dist/companion/service.js +580 -0
- package/dist/companion/store.js +324 -0
- package/dist/companion/webauthn-test-support.js +44 -0
- package/dist/companion/webauthn.js +398 -0
- package/dist/contracts/console-api.js +18 -0
- package/dist/design/kit.css +30 -0
- package/dist/local-landing.js +47 -0
- package/dist/person-proof.js +5 -1
- package/dist/pull-request-flow.js +75 -2
- package/dist/qr.js +385 -0
- package/dist/release-adapters.js +2 -1
- package/dist/restore-retirement.js +2 -0
- package/dist/scope.js +67 -4
- package/dist/serve.js +31 -4
- package/dist/server/pages.js +9 -2
- package/dist/server/phone-engine-api.js +59 -0
- package/dist/server/route-table.js +11 -0
- package/dist/server/settings-phone.js +492 -0
- package/dist/server/settings-scripts.js +2 -0
- package/dist/server/settings-sections.js +6 -2
- package/dist/settings-groups-ui.js +2 -1
- package/dist/settings-proofs.js +6 -0
- package/dist/store.js +37 -4
- package/dist/tailnet.js +42 -0
- package/dist/toolroll-update.js +3 -1
- package/dist/youiyoux-intake.js +8 -0
- package/package.json +7 -2
|
@@ -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
|
|
347
|
-
|
|
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
|
+
}
|
package/dist/release-adapters.js
CHANGED
|
@@ -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
|
-
|
|
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");
|
package/dist/scope.js
CHANGED
|
@@ -21,6 +21,8 @@ import { parseLeadToken } from "./api-tokens.js";
|
|
|
21
21
|
import { isAcpProfile, isAcpProvider } from "./acp-agents.js";
|
|
22
22
|
import { levelOfProfile } from "./policy.js";
|
|
23
23
|
import { canonicalJson } from "./canonical-json.js";
|
|
24
|
+
import { checkPasskeyAction, consumePasskeyAction, passkeyApprovalWindowMinutes, passkeyRequiredForApprovals, usesPasskeyLease, verifyPasskeyLease } from "./companion/passkey-gate.js";
|
|
25
|
+
import { passkeyProofDetail } from "./companion/webauthn.js";
|
|
24
26
|
export { isAcpProfile };
|
|
25
27
|
import { createHash, randomBytes, scryptSync, timingSafeEqual } from "node:crypto";
|
|
26
28
|
import { networkFromValue } from "./egress.js";
|
|
@@ -749,15 +751,44 @@ export function fileAndSealUnderMode(store, input) {
|
|
|
749
751
|
return { ok: true, scope: store.getScope(input.taskId), basis: "mode" };
|
|
750
752
|
});
|
|
751
753
|
}
|
|
752
|
-
export function approve(store, taskId, by, now, sawDigest, token, mutation = {}, fastStart, chat) {
|
|
754
|
+
export function approve(store, taskId, by, now, sawDigest, token, mutation = {}, fastStart, chat, passkey) {
|
|
753
755
|
return store.transact(() => {
|
|
754
756
|
const repoNow = store.lookupRef(taskId)?.repo ?? null;
|
|
757
|
+
if (chat !== undefined && passkey !== undefined)
|
|
758
|
+
return { ok: false, reason: "policy", message: "Approval cannot combine chat and passkey proofs." };
|
|
759
|
+
if (chat !== undefined && passkeyRequiredForApprovals(store, repoNow)) {
|
|
760
|
+
return { ok: false, reason: "policy", message: "Passkey required for approvals on this project; chat approvals are disabled." };
|
|
761
|
+
}
|
|
755
762
|
const account = chat === undefined ? null : store.accountOf(by);
|
|
756
|
-
if (chat !== undefined && machineActing())
|
|
763
|
+
if ((chat !== undefined || passkey !== undefined) && machineActing())
|
|
757
764
|
return { ok: false, reason: "machine-proof" };
|
|
758
765
|
if (chat !== undefined && (account === null || account.revokedAt !== null || account.role !== "approver" || repoNow === null || !store.accountCanAccess(by, repoNow)))
|
|
759
766
|
return { ok: false, reason: "not-an-approver" };
|
|
760
|
-
|
|
767
|
+
let passkeyVerified = null;
|
|
768
|
+
let passkeyChecked = null;
|
|
769
|
+
let authenticated;
|
|
770
|
+
if (passkey !== undefined) {
|
|
771
|
+
const checked = usesPasskeyLease(passkey)
|
|
772
|
+
? verifyPasskeyLease(store, { accountName: by, repo: repoNow, proof: passkey, now })
|
|
773
|
+
: checkPasskeyAction(store, { accountName: by, repo: repoNow, verb: "approve", expectedBinding: { verb: "approve", taskId, sawDigest }, proof: passkey, now });
|
|
774
|
+
if (!checked.ok) {
|
|
775
|
+
if (checked.code === "step_up_required")
|
|
776
|
+
return { ok: false, reason: "password-now" };
|
|
777
|
+
return checked.code === "not_an_approver"
|
|
778
|
+
? { ok: false, reason: "not-an-approver" }
|
|
779
|
+
: { ok: false, reason: "policy", message: checked.message };
|
|
780
|
+
}
|
|
781
|
+
passkeyVerified = checked;
|
|
782
|
+
if (!usesPasskeyLease(passkey))
|
|
783
|
+
passkeyChecked = checked;
|
|
784
|
+
authenticated = { ok: true, method: usesPasskeyLease(passkey) ? "passkey-fresh" : "passkey", at: checked.provedAtMs };
|
|
785
|
+
}
|
|
786
|
+
else if (chat !== undefined) {
|
|
787
|
+
authenticated = { ok: true, method: "chat", at: now.getTime() };
|
|
788
|
+
}
|
|
789
|
+
else {
|
|
790
|
+
authenticated = authenticateApprover(store, by, token, repoNow);
|
|
791
|
+
}
|
|
761
792
|
if (!authenticated.ok)
|
|
762
793
|
return authenticated;
|
|
763
794
|
if (!personProof(authenticated.method))
|
|
@@ -816,11 +847,29 @@ export function approve(store, taskId, by, now, sawDigest, token, mutation = {},
|
|
|
816
847
|
if ((authenticated.method === "fresh-password" || authenticated.method === "fresh-sso") && !freshlyApprovable(store, taskId, scope, gate.verdict === "seal" && !gate.protectedWork)) {
|
|
817
848
|
return { ok: false, reason: "password-now" };
|
|
818
849
|
}
|
|
850
|
+
const routine = approvalWindowCovers(store, taskId, by);
|
|
851
|
+
if (authenticated.method === "passkey-fresh" && !routine)
|
|
852
|
+
return { ok: false, reason: "password-now" };
|
|
819
853
|
const proved = () => store.recordAction({ at: now.toISOString(), actor: by, repo: store.lookupRef(taskId)?.repo ?? null, taskId, runId: null, action: APPROVAL_PROOF,
|
|
820
|
-
outcome: authenticated.method, source: "work", detail:
|
|
854
|
+
outcome: authenticated.method, source: "work", detail: passkeyVerified !== null
|
|
855
|
+
? passkeyProofDetail({ at: now, ...(authenticated.method === "passkey-fresh" ? { provedAtMs: passkeyVerified.provedAtMs } : {}), generation: passkeyVerified.accountGeneration, digest: scope.digest, verb: "approve",
|
|
856
|
+
credentialId: passkeyVerified.credentialId, pairedDeviceId: passkeyVerified.deviceId, be: passkeyVerified.be, bs: passkeyVerified.bs })
|
|
857
|
+
: (fastStart === undefined ? approvalProofDetail : fastProofDetail(fastStart))(authenticated.at, store.accountOf(by)?.generation ?? 0, scope.digest, local === null ? undefined : { generation: local.localGeneration, transport: local.transport }) });
|
|
858
|
+
const consumePasskeyOrFail = (opensWindow) => {
|
|
859
|
+
if (passkeyChecked === null)
|
|
860
|
+
return null;
|
|
861
|
+
const consumed = consumePasskeyAction(store, passkeyChecked, { repo: repoNow, now, ...(opensWindow ? { startsLease: { minutes: passkeyApprovalWindowMinutes(store) } } : {}) });
|
|
862
|
+
if (!consumed.ok)
|
|
863
|
+
return { ok: false, reason: "policy", message: consumed.message };
|
|
864
|
+
passkeyVerified = consumed;
|
|
865
|
+
return null;
|
|
866
|
+
};
|
|
821
867
|
if (gate.verdict === "vote") {
|
|
822
868
|
if (gate.already)
|
|
823
869
|
return { ok: false, reason: "second-approver", have: gate.have, need: gate.need, already: true };
|
|
870
|
+
const passkeyErr = consumePasskeyOrFail(false);
|
|
871
|
+
if (passkeyErr !== null)
|
|
872
|
+
return passkeyErr;
|
|
824
873
|
store.recordApprovalVote(taskId, scope.digest, by, now, authenticated.method);
|
|
825
874
|
proved();
|
|
826
875
|
return { ok: false, reason: "second-approver", have: gate.have, need: gate.need, already: gate.already };
|
|
@@ -828,6 +877,11 @@ export function approve(store, taskId, by, now, sawDigest, token, mutation = {},
|
|
|
828
877
|
const refused = {};
|
|
829
878
|
try {
|
|
830
879
|
return store.savepoint(() => {
|
|
880
|
+
const passkeyErr = consumePasskeyOrFail(routine);
|
|
881
|
+
if (passkeyErr !== null) {
|
|
882
|
+
refused.result = passkeyErr;
|
|
883
|
+
throw refused;
|
|
884
|
+
}
|
|
831
885
|
if (gate.protectedWork)
|
|
832
886
|
store.recordApprovalVote(taskId, scope.digest, by, now, authenticated.method);
|
|
833
887
|
const sealed = chat === undefined ? store.sealScopeApproval(taskId, by, now, mutation)
|
|
@@ -861,6 +915,15 @@ export function approvalProofOf(store, taskId, by, digest) {
|
|
|
861
915
|
}
|
|
862
916
|
return null;
|
|
863
917
|
}
|
|
918
|
+
export function approvalWindowCovers(store, taskId, by) {
|
|
919
|
+
const scope = store.getScope(taskId);
|
|
920
|
+
const repo = store.lookupRef(taskId)?.repo ?? null;
|
|
921
|
+
if (scope === null || repo === null || scope.releaseTerms != null)
|
|
922
|
+
return false;
|
|
923
|
+
if (isProtectedWork(store.approvalRules(repo), [...scope.touches]))
|
|
924
|
+
return false;
|
|
925
|
+
return store.approvalGate(taskId, by, "person").verdict === "seal" && freshlyApprovable(store, taskId, scope, true);
|
|
926
|
+
}
|
|
864
927
|
export function freshlyApprovable(store, taskId, scope, singleApprover) {
|
|
865
928
|
if (!singleApprover)
|
|
866
929
|
return false;
|