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
@@ -0,0 +1,398 @@
1
+ import { createHash, createPublicKey, randomBytes, timingSafeEqual, verify as cryptoVerify } from "node:crypto";
2
+ export const PASSKEY_RP_ID = "toolroll.dev";
3
+ export const PASSKEY_RP_NAME = "Toolroll";
4
+ export const PASSKEY_ORIGIN = "https://toolroll.dev";
5
+ export const PASSKEY_CHALLENGE_TTL_MS = 120_000;
6
+ const P256_SPKI_PREFIX = Buffer.from("3059301306072a8648ce3d020106082a8648ce3d030107034200", "hex");
7
+ const P256_P = BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff");
8
+ const P256_B = BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b");
9
+ export function sha256(data) {
10
+ return createHash("sha256").update(data).digest();
11
+ }
12
+ export function randomChallenge32() {
13
+ return randomBytes(32).toString("base64url");
14
+ }
15
+ export function canonicalJson(value) {
16
+ if (value === null || typeof value !== "object")
17
+ return JSON.stringify(value);
18
+ if (Array.isArray(value))
19
+ return `[${value.map(canonicalJson).join(",")}]`;
20
+ const obj = value;
21
+ const keys = Object.keys(obj).filter(k => obj[k] !== undefined).sort();
22
+ return `{${keys.map(k => `${JSON.stringify(k)}:${canonicalJson(obj[k])}`).join(",")}}`;
23
+ }
24
+ export function derivePasskeyUserHandle(workspaceId, accountName) {
25
+ return sha256(Buffer.concat([
26
+ Buffer.from("toolroll-passkey-user-v1\0", "utf8"),
27
+ Buffer.from(workspaceId, "utf8"),
28
+ Buffer.from("\0", "utf8"),
29
+ Buffer.from(accountName, "utf8"),
30
+ ]));
31
+ }
32
+ export function normalizeAcceptNote(note) {
33
+ return typeof note === "string" && note.trim().length > 0 ? note.trim() : null;
34
+ }
35
+ export function acceptBindingOf(input, receiptRunId) {
36
+ return {
37
+ verb: "accept",
38
+ taskId: input.taskId,
39
+ runId: input.runId ?? receiptRunId,
40
+ receiptDigest: input.receiptDigest,
41
+ noteHash: sha256(normalizeAcceptNote(input.note) ?? "").toString("hex"),
42
+ publish: input.publish,
43
+ };
44
+ }
45
+ export function buildActionChallenge(input) {
46
+ const nonce = input.nonce ?? randomChallenge32();
47
+ const payload = {
48
+ v: 1,
49
+ verb: input.binding.verb,
50
+ workspaceId: input.workspaceId,
51
+ recoveryGeneration: input.recoveryGeneration,
52
+ accountName: input.accountName,
53
+ deviceId: input.deviceId,
54
+ binding: input.binding,
55
+ nonce,
56
+ };
57
+ const canonicalPayload = canonicalJson(payload);
58
+ const challenge = sha256(canonicalPayload).toString("base64url");
59
+ const bindingJson = canonicalJson(input.binding);
60
+ const wording = wordingForBinding(input.binding);
61
+ return { challenge, canonicalPayload, bindingJson, wording };
62
+ }
63
+ function wordingForBinding(binding) {
64
+ switch (binding.verb) {
65
+ case "approve":
66
+ return `Approve task ${binding.taskId} plan (${binding.sawDigest.slice(0, 12)})`;
67
+ case "accept":
68
+ return `Accept task ${binding.taskId} result (${binding.receiptDigest.slice(0, 12)})${binding.publish ? " and open pull request" : ""}`;
69
+ case "land":
70
+ return `${binding.undo ? "Undo landing" : "Land"} task ${binding.taskId} (${binding.planKey})`;
71
+ case "ship":
72
+ return `Merge PR #${binding.prNumber} for task ${binding.taskId} at ${binding.headSha.slice(0, 10)} (${binding.method})`;
73
+ case "unlock":
74
+ return `Unlock approvals for ${minutesWords(binding.minutes)}`;
75
+ }
76
+ }
77
+ export function minutesWords(minutes) {
78
+ return minutes === 60 ? "1 hour" : minutes === 1 ? "1 minute" : `${minutes} minutes`;
79
+ }
80
+ export function passkeyProofDetail(input) {
81
+ return JSON.stringify({
82
+ v: 1,
83
+ at: input.at.toISOString(),
84
+ ...(input.provedAtMs === undefined ? {} : { provedAt: new Date(input.provedAtMs).toISOString() }),
85
+ generation: input.generation,
86
+ digest: input.digest,
87
+ verb: input.verb,
88
+ cred: sha256(input.credentialId).toString("hex").slice(0, 16),
89
+ dev: input.pairedDeviceId.slice(0, 40),
90
+ be: input.be,
91
+ bs: input.bs,
92
+ });
93
+ }
94
+ function constantTimeStringEqual(a, b) {
95
+ const ba = Buffer.from(a, "utf8");
96
+ const bb = Buffer.from(b, "utf8");
97
+ if (ba.length !== bb.length)
98
+ return false;
99
+ return timingSafeEqual(ba, bb);
100
+ }
101
+ function decodeBase64UrlStrict(raw) {
102
+ if (typeof raw !== "string" || raw.length === 0 || !/^[A-Za-z0-9_-]+$/.test(raw))
103
+ return null;
104
+ return Buffer.from(raw, "base64url");
105
+ }
106
+ function bytesToBigInt(buf) {
107
+ let out = 0n;
108
+ for (const byte of buf)
109
+ out = (out << 8n) | BigInt(byte);
110
+ return out;
111
+ }
112
+ function isOnP256Curve(xBuf, yBuf) {
113
+ if (xBuf.length !== 32 || yBuf.length !== 32)
114
+ return false;
115
+ const x = bytesToBigInt(xBuf);
116
+ const y = bytesToBigInt(yBuf);
117
+ if (x <= 0n || x >= P256_P || y <= 0n || y >= P256_P)
118
+ return false;
119
+ const lhs = (y * y) % P256_P;
120
+ const rhs = (((x * x) % P256_P) * x - 3n * x + P256_B) % P256_P;
121
+ const normalizedRhs = rhs < 0n ? rhs + P256_P : rhs;
122
+ return lhs === normalizedRhs;
123
+ }
124
+ export function p256CoordsToSpkiDer(x, y) {
125
+ if (!isOnP256Curve(x, y))
126
+ return null;
127
+ const spki = Buffer.concat([P256_SPKI_PREFIX, Buffer.from([0x04]), x, y]);
128
+ try {
129
+ const key = createPublicKey({ key: spki, format: "der", type: "spki" });
130
+ if (key.asymmetricKeyType !== "ec")
131
+ return null;
132
+ return spki;
133
+ }
134
+ catch {
135
+ return null;
136
+ }
137
+ }
138
+ function decodeCborItem(buf, offset, depth) {
139
+ if (depth > 8 || offset >= buf.length)
140
+ throw new Error("cbor_bounds");
141
+ const initial = buf[offset++];
142
+ const major = initial >> 5;
143
+ const ai = initial & 0x1f;
144
+ let arg = 0;
145
+ if (ai < 24) {
146
+ arg = ai;
147
+ }
148
+ else if (ai === 24) {
149
+ if (offset + 1 > buf.length)
150
+ throw new Error("cbor_eof");
151
+ arg = buf[offset++];
152
+ }
153
+ else if (ai === 25) {
154
+ if (offset + 2 > buf.length)
155
+ throw new Error("cbor_eof");
156
+ arg = buf.readUInt16BE(offset);
157
+ offset += 2;
158
+ }
159
+ else if (ai === 26) {
160
+ if (offset + 4 > buf.length)
161
+ throw new Error("cbor_eof");
162
+ arg = buf.readUInt32BE(offset);
163
+ offset += 4;
164
+ }
165
+ else {
166
+ throw new Error("cbor_unsupported");
167
+ }
168
+ switch (major) {
169
+ case 0:
170
+ return { value: arg, next: offset };
171
+ case 1:
172
+ return { value: -1 - arg, next: offset };
173
+ case 2: {
174
+ if (offset + arg > buf.length)
175
+ throw new Error("cbor_eof");
176
+ return { value: Buffer.from(buf.subarray(offset, offset + arg)), next: offset + arg };
177
+ }
178
+ case 3: {
179
+ if (offset + arg > buf.length)
180
+ throw new Error("cbor_eof");
181
+ return { value: buf.subarray(offset, offset + arg).toString("utf8"), next: offset + arg };
182
+ }
183
+ case 4: {
184
+ if (arg > 256)
185
+ throw new Error("cbor_limit");
186
+ const arr = [];
187
+ for (let i = 0; i < arg; i++) {
188
+ const item = decodeCborItem(buf, offset, depth + 1);
189
+ arr.push(item.value);
190
+ offset = item.next;
191
+ }
192
+ return { value: arr, next: offset };
193
+ }
194
+ case 5: {
195
+ if (arg > 256)
196
+ throw new Error("cbor_limit");
197
+ const map = new Map();
198
+ for (let i = 0; i < arg; i++) {
199
+ const k = decodeCborItem(buf, offset, depth + 1);
200
+ if (typeof k.value !== "number" && typeof k.value !== "string")
201
+ throw new Error("cbor_key_type");
202
+ const v = decodeCborItem(buf, k.next, depth + 1);
203
+ map.set(k.value, v.value);
204
+ offset = v.next;
205
+ }
206
+ return { value: map, next: offset };
207
+ }
208
+ case 7:
209
+ if (ai === 20)
210
+ return { value: false, next: offset };
211
+ if (ai === 21)
212
+ return { value: true, next: offset };
213
+ if (ai === 22)
214
+ return { value: null, next: offset };
215
+ throw new Error("cbor_simple");
216
+ default:
217
+ throw new Error("cbor_major");
218
+ }
219
+ }
220
+ function parseClientData(rawB64) {
221
+ const raw = decodeBase64UrlStrict(rawB64);
222
+ if (raw === null || raw.length > 8_192)
223
+ return { ok: false, code: "invalid_client_data", message: "Invalid WebAuthn clientDataJSON." };
224
+ let parsed;
225
+ try {
226
+ parsed = JSON.parse(raw.toString("utf8"));
227
+ }
228
+ catch {
229
+ return { ok: false, code: "invalid_client_data", message: "WebAuthn clientDataJSON is not valid JSON." };
230
+ }
231
+ if (parsed === null || typeof parsed !== "object" || typeof parsed["type"] !== "string" || typeof parsed["challenge"] !== "string" || typeof parsed["origin"] !== "string") {
232
+ return { ok: false, code: "invalid_client_data", message: "WebAuthn clientDataJSON is missing required fields." };
233
+ }
234
+ return { ok: true, raw, type: parsed["type"], challenge: parsed["challenge"], origin: parsed["origin"] };
235
+ }
236
+ export function verifyRegistrationResponse(input) {
237
+ const rpId = input.rpId ?? PASSKEY_RP_ID;
238
+ const expectedOrigin = input.expectedOrigin ?? PASSKEY_ORIGIN;
239
+ const client = parseClientData(input.payload.clientDataJSON);
240
+ if (!client.ok)
241
+ return client;
242
+ if (client.type !== "webauthn.create") {
243
+ return { ok: false, code: "invalid_type", message: "Expected webauthn.create clientData type." };
244
+ }
245
+ if (!constantTimeStringEqual(client.challenge, input.expectedChallenge)) {
246
+ return { ok: false, code: "challenge_mismatch", message: "Registration challenge does not match." };
247
+ }
248
+ if (client.origin !== expectedOrigin) {
249
+ return { ok: false, code: "origin_mismatch", message: `Passkey origin must be ${expectedOrigin}.` };
250
+ }
251
+ const attRaw = decodeBase64UrlStrict(input.payload.attestationObject);
252
+ if (attRaw === null || attRaw.length > 16_384) {
253
+ return { ok: false, code: "invalid_attestation", message: "Invalid WebAuthn attestationObject." };
254
+ }
255
+ let attObj;
256
+ try {
257
+ const decoded = decodeCborItem(attRaw, 0, 0);
258
+ if (decoded.next !== attRaw.length)
259
+ return { ok: false, code: "invalid_attestation", message: "Trailing bytes in attestationObject." };
260
+ attObj = decoded.value;
261
+ }
262
+ catch {
263
+ return { ok: false, code: "invalid_attestation", message: "Could not decode WebAuthn attestationObject CBOR." };
264
+ }
265
+ if (!(attObj instanceof Map))
266
+ return { ok: false, code: "invalid_attestation", message: "attestationObject must be a CBOR map." };
267
+ const authData = attObj.get("authData");
268
+ if (!Buffer.isBuffer(authData) || authData.length < 55) {
269
+ return { ok: false, code: "invalid_auth_data", message: "Authenticator data is missing or truncated." };
270
+ }
271
+ const expectedRpHash = sha256(rpId);
272
+ if (!timingSafeEqual(authData.subarray(0, 32), expectedRpHash)) {
273
+ return { ok: false, code: "rp_id_mismatch", message: "Passkey rpIdHash does not match toolroll.dev." };
274
+ }
275
+ const flags = authData[32];
276
+ const up = (flags & 0x01) !== 0;
277
+ const uv = (flags & 0x04) !== 0;
278
+ const be = (flags & 0x08) !== 0;
279
+ const bs = (flags & 0x10) !== 0;
280
+ const at = (flags & 0x40) !== 0;
281
+ const ed = (flags & 0x80) !== 0;
282
+ if (!up)
283
+ return { ok: false, code: "user_presence_required", message: "Passkey registration requires user presence (UP=1)." };
284
+ if (!uv)
285
+ return { ok: false, code: "user_verification_required", message: "Passkey registration requires user verification (UV=1)." };
286
+ if (!at)
287
+ return { ok: false, code: "attested_credential_missing", message: "Passkey registration requires attested credential data (AT=1)." };
288
+ const signCount = authData.readUInt32BE(33);
289
+ const credIdLen = authData.readUInt16BE(53);
290
+ if (credIdLen === 0 || credIdLen > 1023 || 55 + credIdLen >= authData.length) {
291
+ return { ok: false, code: "invalid_credential_id", message: "Invalid passkey credentialId length." };
292
+ }
293
+ const credentialIdBuf = authData.subarray(55, 55 + credIdLen);
294
+ const credentialId = credentialIdBuf.toString("base64url");
295
+ if (input.payload.credentialId !== undefined && !constantTimeStringEqual(input.payload.credentialId, credentialId)) {
296
+ return { ok: false, code: "credential_id_mismatch", message: "Credential ID does not match attested authData." };
297
+ }
298
+ let coseKey;
299
+ let coseEnd;
300
+ try {
301
+ const decoded = decodeCborItem(authData, 55 + credIdLen, 0);
302
+ coseKey = decoded.value;
303
+ coseEnd = decoded.next;
304
+ }
305
+ catch {
306
+ return { ok: false, code: "invalid_cose_key", message: "Could not decode COSE public key." };
307
+ }
308
+ if (!ed && coseEnd !== authData.length) {
309
+ return { ok: false, code: "invalid_auth_data", message: "Unexpected trailing bytes in authData." };
310
+ }
311
+ if (!(coseKey instanceof Map)) {
312
+ return { ok: false, code: "invalid_cose_key", message: "COSE public key must be a CBOR map." };
313
+ }
314
+ const kty = coseKey.get(1);
315
+ const alg = coseKey.get(3);
316
+ const crv = coseKey.get(-1);
317
+ const x = coseKey.get(-2);
318
+ const y = coseKey.get(-3);
319
+ if (kty !== 2 || alg !== -7 || crv !== 1 || !Buffer.isBuffer(x) || !Buffer.isBuffer(y)) {
320
+ return { ok: false, code: "unsupported_algorithm", message: "Only ES256 (P-256) passkeys are supported." };
321
+ }
322
+ const spki = p256CoordsToSpkiDer(x, y);
323
+ if (spki === null) {
324
+ return { ok: false, code: "invalid_public_key", message: "Passkey public key is not a valid point on P-256." };
325
+ }
326
+ return {
327
+ ok: true,
328
+ credentialId,
329
+ publicKeySpki: spki.toString("base64url"),
330
+ signCount,
331
+ be,
332
+ bs,
333
+ };
334
+ }
335
+ export function verifyAssertionResponse(input) {
336
+ const rpId = input.rpId ?? PASSKEY_RP_ID;
337
+ const expectedOrigin = input.expectedOrigin ?? PASSKEY_ORIGIN;
338
+ const client = parseClientData(input.payload.clientDataJSON);
339
+ if (!client.ok)
340
+ return client;
341
+ if (client.type !== "webauthn.get") {
342
+ return { ok: false, code: "invalid_type", message: "Expected webauthn.get clientData type." };
343
+ }
344
+ if (!constantTimeStringEqual(client.challenge, input.expectedChallenge)) {
345
+ return { ok: false, code: "challenge_mismatch", message: "Assertion challenge does not match." };
346
+ }
347
+ if (client.origin !== expectedOrigin) {
348
+ return { ok: false, code: "origin_mismatch", message: `Passkey origin must be ${expectedOrigin}.` };
349
+ }
350
+ const authData = decodeBase64UrlStrict(input.payload.authenticatorData);
351
+ const signature = decodeBase64UrlStrict(input.payload.signature);
352
+ const userHandle = decodeBase64UrlStrict(input.payload.userHandle);
353
+ if (authData === null || authData.length < 37 || authData.length > 8_192) {
354
+ return { ok: false, code: "invalid_auth_data", message: "Invalid authenticatorData." };
355
+ }
356
+ if (signature === null || signature.length === 0 || signature.length > 256) {
357
+ return { ok: false, code: "invalid_signature", message: "Invalid WebAuthn signature." };
358
+ }
359
+ if (userHandle === null || userHandle.length !== input.expectedUserHandle.length || !timingSafeEqual(userHandle, input.expectedUserHandle)) {
360
+ return { ok: false, code: "user_handle_mismatch", message: "Passkey userHandle does not match this Workspace account." };
361
+ }
362
+ const expectedRpHash = sha256(rpId);
363
+ if (!timingSafeEqual(authData.subarray(0, 32), expectedRpHash)) {
364
+ return { ok: false, code: "rp_id_mismatch", message: "Passkey rpIdHash does not match toolroll.dev." };
365
+ }
366
+ const flags = authData[32];
367
+ const up = (flags & 0x01) !== 0;
368
+ const uv = (flags & 0x04) !== 0;
369
+ const be = (flags & 0x08) !== 0;
370
+ const bs = (flags & 0x10) !== 0;
371
+ if (!up)
372
+ return { ok: false, code: "user_presence_required", message: "Passkey approval requires user presence (UP=1)." };
373
+ if (!uv)
374
+ return { ok: false, code: "user_verification_required", message: "Passkey approval requires user verification (UV=1)." };
375
+ const newSignCount = authData.readUInt32BE(33);
376
+ if (!(input.storedSignCount === 0 && newSignCount === 0) && newSignCount <= input.storedSignCount) {
377
+ return { ok: false, code: "sign_count_regression", message: "Passkey signCount did not advance." };
378
+ }
379
+ let publicKey;
380
+ try {
381
+ publicKey = createPublicKey({ key: Buffer.from(input.storedPublicKeySpki, "base64url"), format: "der", type: "spki" });
382
+ }
383
+ catch {
384
+ return { ok: false, code: "invalid_public_key", message: "Stored passkey public key is unreadable." };
385
+ }
386
+ const signedData = Buffer.concat([authData, sha256(client.raw)]);
387
+ const validSig = cryptoVerify("sha256", signedData, publicKey, signature);
388
+ if (!validSig) {
389
+ return { ok: false, code: "signature_invalid", message: "Passkey signature verification failed." };
390
+ }
391
+ return {
392
+ ok: true,
393
+ credentialId: input.payload.credentialId,
394
+ newSignCount,
395
+ be,
396
+ bs,
397
+ };
398
+ }
@@ -117,6 +117,14 @@ export const CONSOLE_FORMS = {
117
117
  slack: formContract("POST /settings/slack/connect|pair|unpair|disconnect|alerts", ["password", "app-token", "bot-token"]),
118
118
  chatApproval: formContract("POST /settings/chat-approval/confirm, /settings/chat-approval/save, /settings/chat-approval/off", ["scope", "full-access", "cap-usd", "nonce", "digest", "token"]),
119
119
  telegramPair: formContract("POST /settings/telegram/pair, /settings/telegram/unpair", ["password"]),
120
+ phoneAccess: formContract("POST /settings/phone/access", ["password", "act", "hosted"]),
121
+ phonePair: formContract("POST /settings/phone/pair", ["password"]),
122
+ phonePairing: formContract("POST /settings/phone/confirm, /settings/phone/cancel", ["pairing"]),
123
+ phoneRemove: formContract("POST /settings/phone/remove", ["password", "device"]),
124
+ phonePasskeyEnable: formContract("POST /settings/phone/passkey/enable", ["password"]),
125
+ phonePasskeyRevoke: formContract("POST /settings/phone/passkey/revoke", ["password", "credential"]),
126
+ phonePasskeyWindow: formContract("POST /settings/phone/passkey/window", ["password", "window"]),
127
+ phoneRename: formContract("POST /settings/phone/rename", ["device", "name"]),
120
128
  teams: formContract("POST /settings/teams/connect|pair|unpair|disconnect|alerts", ["password", "app-id", "tenant", "secret"]),
121
129
  discord: formContract("POST /settings/discord/connect|pair|unpair|disconnect|alerts", ["password", "bot-token"]),
122
130
  messaging: formContract("POST /settings/messaging", ["primary"]),
@@ -293,10 +301,20 @@ export const flowViewSchema = z.looseObject({
293
301
  kinds: z.array(z.looseObject({ kind: z.string(), label: z.string() })),
294
302
  colors: z.array(z.string()),
295
303
  });
304
+ export const phonePairingViewSchema = z.looseObject({
305
+ pairSessionId: z.string(),
306
+ status: z.enum(["awaiting_scan", "awaiting_ready", "awaiting_confirm", "confirming", "finishing", "paired", "cancelled", "expired", "contested", "failed"]),
307
+ expiresAtMs: z.number(),
308
+ confirmCode: z.string().nullable(),
309
+ deviceName: z.string().nullable(),
310
+ deviceId: z.string().nullable(),
311
+ error: z.string().nullable(),
312
+ });
296
313
  export const CONSOLE_RESPONSES = {
297
314
  ledgerPage: { route: "GET /ledger?format=json", schema: ledgerPageSchema },
298
315
  evidencePack: { route: "GET /t/<task>/evidence?format=json", schema: evidencePackSchema },
299
316
  flowView: { route: "GET /flows/<id>?format=json", schema: flowViewSchema },
317
+ phonePairingView: { route: "GET /settings/phone/pairings/<id>", schema: phonePairingViewSchema },
300
318
  };
301
319
  export function checkResponse(name, payload, report = toStderr) {
302
320
  const { route, schema } = CONSOLE_RESPONSES[name];
package/dist/demo.js CHANGED
@@ -921,7 +921,7 @@ export function createDemoSandbox(now) {
921
921
  { window: "seven_day", usedPercent: 83, windowMinutes: 10_080, resetsAt: later(62), reached: false },
922
922
  ] }, now);
923
923
  store.recordProviderLimits({ provider: "codex", plan: "pro", windows: [{ window: "seven_day", usedPercent: 12, windowMinutes: 10_080, resetsAt: later(130), reached: false }] }, now);
924
- store.setBudget({ scope: "project", key: repos.web, limitMicrousd: 25_000_000, hardStop: true }, seed.login.name, now);
924
+ store.setBudget({ scope: "project", key: realpathSync(repos.web), limitMicrousd: 25_000_000, hardStop: true }, seed.login.name, now);
925
925
  const passwordFile = join(sandbox, "demo-login.txt");
926
926
  writeFileSync(passwordFile, `name: ${seed.login.name}\npassword: ${seed.login.password}\n`, { mode: 0o600 });
927
927
  const lead = createDemoLead({ store, repos, evidenceRoot, approver: seed.login.name, token: seed.login.password });
@@ -109,8 +109,9 @@
109
109
  /* A native select in the same family, with the chevron: 36px (sm 28px in a toolbar). */
110
110
  .k-selw { position: relative; display: inline-block; min-width: 0; max-width: 100%; }
111
111
  .k-selw::after { content: ""; position: absolute; right: 13px; top: 50%; margin-top: -5px; width: 6px; height: 6px; border: solid var(--so-muted); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); pointer-events: none; }
112
- .k-sel.k-sel { appearance: none; -webkit-appearance: none; height: 36px; min-height: 0; padding: 0 32px 0 12px; line-height: 1; text-overflow: ellipsis; cursor: pointer; }
113
- .k-selw.sm .k-sel { height: 28px; border-radius: 999px; font: 500 12.5px/1 var(--so-font-sans); padding: 0 26px 0 11px; }
112
+ .k-sel.k-sel { appearance: none; -webkit-appearance: none; -moz-appearance: none; background-image: none; height: 36px; min-height: 0; padding: 0 32px 0 12px; line-height: 34px; text-overflow: ellipsis; cursor: pointer; }
113
+ .k-sel.k-sel::picker-icon { display: none; }
114
+ .k-selw.sm .k-sel { height: 28px; border-radius: 999px; font: 500 12.5px/26px var(--so-font-sans); padding: 0 26px 0 11px; }
114
115
  .k-selw.sm::after { right: 11px; }
115
116
  .k-selw.wide { display: block; width: 100%; }
116
117
  /* A select drawn as a pill chip (a composer's project): filled, no box, works without script. */
@@ -226,8 +227,9 @@
226
227
  .k-tb-ctx > .k-seg + .k-seg { margin-left: 8px; }
227
228
  /* Phone header: menu or back · title · one trailing action. Hidden at a desk. */
228
229
  .k-ph { display: none; }
229
- /* Reading pages: one 760px column, a back link and the doc header. */
230
+ /* Reading pages: one 760px column, expanding to 960px on wide desks when reviewing code diffs. */
230
231
  .k-doc { box-sizing: border-box; width: 100%; max-width: 760px; margin: 0 auto; padding: 22px 28px 120px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; align-content: start; }
232
+ @media (min-width: 1100px) { .k-doc:has(.diff-review) { max-width: 960px; } }
231
233
  .k-backlink { display: inline-flex; align-items: center; gap: 6px; color: var(--so-muted); font: var(--so-typography-label); justify-self: start; min-height: 24px; text-decoration: none; }
232
234
  .k-dh { display: flex; align-items: flex-start; gap: 6px; }
233
235
  .k-dh > div { flex: 1; display: grid; gap: 6px; min-width: 0; }
@@ -564,6 +566,7 @@ html:not(.k-js) .k-composer:focus-within, html.k-kbd .k-composer:focus-within {
564
566
  .k-btn-icon, .k-btn-sm.k-btn-icon { width: 44px; padding: 0; }
565
567
  .k-input.k-input, .k-textarea.k-textarea, .k-sel.k-sel { font-size: 16px; }
566
568
  .k-input.k-input, .k-pop .k-input.k-input, .k-sel.k-sel, .k-selw.sm .k-sel { height: 44px; }
569
+ .k-sel.k-sel, .k-selw.sm .k-sel { line-height: 42px; }
567
570
  .k-selw::after { right: 13px; }
568
571
  .k-seg > a, .k-seg > button { height: 44px; font-size: 13.5px; }
569
572
  .k-seg.k-seg-icons > a, .k-seg.k-seg-icons > button { min-width: 44px; justify-content: center; }
@@ -818,3 +821,33 @@ html.k-js .k-sform[data-k-gate]:not([data-dirty]) .k-ssave:has(.k-ssave-said:emp
818
821
  .k-srec-a .k-ssave { min-height: 0; padding: 0; background: none; }
819
822
  .k-srec-a .k-ssave-said:empty { display: none; }
820
823
  pre.k-scode { white-space: pre-wrap; }
824
+ /* Settings → Phone (settings-phone.ts): addresses, the pairing panel, the code to compare, phones. */
825
+ .k-phone-addrs { display: grid; gap: 4px; margin: 8px 0 4px; padding: 0; list-style: none; }
826
+ .k-phone-addrs li { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
827
+ .k-phone-addr-k { min-width: 120px; font-size: 12.5px; color: var(--so-muted); }
828
+ .k-phone-addrs .k-mono { font-size: 12.5px; color: var(--so-ink); }
829
+ .k-phone-line { display: block; margin-top: 6px; }
830
+ .k-phone-hosted { display: flex; gap: 8px; align-items: flex-start; margin: 0 0 12px; font-size: 12.5px; line-height: 1.45; color: var(--so-muted); }
831
+ .k-phone-hosted input { margin-top: 2px; flex: none; }
832
+ .k-phone-pairing { display: grid; gap: 0; }
833
+ .k-phone-pairing [hidden] { display: none !important; }
834
+ .k-phone-steps { margin: 0 0 12px; padding-left: 1.2em; font-size: 12.5px; line-height: 1.55; color: var(--so-muted); }
835
+ .k-phone-steps strong { color: var(--so-ink); font-weight: 600; }
836
+ .k-phone-qr { margin: 0 0 12px; max-width: 280px; }
837
+ .k-phone-qr svg { display: block; width: 100%; height: auto; background: #fff; border-radius: 8px; }
838
+ .k-phone-paste { margin: 0 0 8px; }
839
+ .k-phone-paste summary { cursor: pointer; }
840
+ .k-phone-paste textarea { box-sizing: border-box; width: 100%; margin-top: 8px; padding: 8px 10px; border: 1px solid var(--so-field-line); border-radius: 7px; background: var(--so-raised); color: var(--so-ink); font: 12px/1.45 var(--so-font-mono); resize: vertical; }
841
+ .k-phone-code { margin: 8px 0 12px; font: 600 32px/1.2 var(--so-font-mono); letter-spacing: .08em; color: var(--so-ink); font-variant-numeric: tabular-nums; }
842
+ .k-phone-wait { margin: 0 0 6px; font-size: 13.5px; color: var(--so-ink); }
843
+ .k-phone-pairing .k-acts { margin-top: 12px; }
844
+ .k-phone-pairing .k-acts form { display: inline; }
845
+ .k-phone-sub { margin: 18px 0 0; font-size: 12px; font-weight: 500; color: var(--so-muted); }
846
+ details.k-phone-rename { margin: 2px 0 6px; padding: 0; border: 0; border-radius: 0; background: none; }
847
+ details.k-phone-rename > summary { display: inline-block; min-height: 0; padding: 2px 0; font-size: 12.5px; font-weight: 400; cursor: pointer; }
848
+ .k-phone-rename form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
849
+ .k-phone-rename-f { flex: 1 1 200px; max-width: 320px; }
850
+ @media (max-width: 760px) {
851
+ .k-phone-code { font-size: 28px; }
852
+ .k-phone-rename .k-input { height: 44px; font-size: 16px; }
853
+ }
@@ -12,8 +12,12 @@ import { localActNow, LOCAL_OWNER_LAPSED } from "./local-owner.js";
12
12
  import { publishingOf } from "./pull-request-flow.js";
13
13
  import { readGit, wholeChangeBaseOf } from "./task-base.js";
14
14
  import { catchUpConflictOf } from "./revision-catch-up.js";
15
+ import { checkPasskeyAction, consumePasskeyAction } from "./companion/passkey-gate.js";
16
+ import { passkeyProofDetail } from "./companion/webauthn.js";
17
+ import { deviceAccountStands, getPairedDevice } from "./companion/store.js";
15
18
  export const LAND_DESTINATION = "land destination";
16
19
  export const LAND_INTENT = "land intent";
20
+ export const LAND_PROVED_ACTION = "land proved";
17
21
  export const LAND_SETTLED = "land settled";
18
22
  export const LAND_HANDOFF = "land handoff";
19
23
  export const LAND_HANDOFF_SETTLED = "land handoff settled";
@@ -444,6 +448,14 @@ function standing(store, authority, repo) {
444
448
  const proved = reproveApprover(store, authority.who);
445
449
  if (!proved.ok || !authority.who.repos.includes(repo) || !store.accountCanAccess(authority.who.name, repo))
446
450
  return refuse("authority", "Your access changed. Sign in again.");
451
+ if (authority.kind === "passkey") {
452
+ const dev = getPairedDevice(store.handle, authority.proof.deviceId);
453
+ const identity = store.workspaceIdentity();
454
+ if (dev === null || dev.revokedAt !== null || dev.activatedAt === null || dev.accountName !== authority.who.name
455
+ || dev.recoveryGeneration !== identity.recoveryGeneration || !deviceAccountStands(dev, store.accountOf(authority.who.name))) {
456
+ return refuse("authority", "This iPhone is no longer paired or your account changed.");
457
+ }
458
+ }
447
459
  return { ok: true, actor: `operator:${authority.who.name}` };
448
460
  }
449
461
  const projectLocks = new Map();
@@ -548,6 +560,39 @@ export async function land(store, taskId, input, authority, access, now, options
548
560
  const pre = standing(store, authority, plan.repo);
549
561
  if (!pre.ok)
550
562
  return pre;
563
+ const landBinding = { verb: "land", taskId, planKey: plan.key, into: input.into ?? null, undo: input.undo === true };
564
+ const passkeyChecked = authority.kind !== "passkey" ? null
565
+ : checkPasskeyAction(store, { accountName: authority.who.name, repo: plan.repo, verb: "land", expectedBinding: landBinding, proof: authority.proof, now });
566
+ if (passkeyChecked !== null && !passkeyChecked.ok)
567
+ return refuse("authority", passkeyChecked.message);
568
+ const consumeLandPasskey = () => {
569
+ if (authority.kind !== "passkey" || passkeyChecked === null || !passkeyChecked.ok)
570
+ return;
571
+ const at = authority.clock();
572
+ const consumed = consumePasskeyAction(store, passkeyChecked, { repo: plan.repo, now: at });
573
+ if (!consumed.ok)
574
+ throw new Refused(refuse("authority", consumed.message));
575
+ store.recordAction({
576
+ at: at.toISOString(),
577
+ actor: authority.who.name,
578
+ repo: plan.repo,
579
+ taskId: plan.rootId,
580
+ runId: plan.runId,
581
+ action: LAND_PROVED_ACTION,
582
+ outcome: "passkey",
583
+ source: "request",
584
+ detail: passkeyProofDetail({
585
+ at,
586
+ generation: consumed.accountGeneration,
587
+ digest: plan.key,
588
+ verb: "land",
589
+ credentialId: consumed.credentialId,
590
+ pairedDeviceId: consumed.deviceId,
591
+ be: consumed.be,
592
+ bs: consumed.bs,
593
+ }),
594
+ });
595
+ };
551
596
  const made = plan.kind === "undo" ? await revertCommit(git, plan, options.scratch) : await squashCommit(git, plan, options.scratch);
552
597
  if (!made.ok)
553
598
  return made;
@@ -573,6 +618,7 @@ export async function land(store, taskId, input, authority, access, now, options
573
618
  replayed = earlier.settled;
574
619
  return earlier.id;
575
620
  }
621
+ consumeLandPasskey();
576
622
  if (!plan.recorded)
577
623
  recordActionWhole(store.handle, { at: now.toISOString(), actor: who.actor, repo: plan.repo, taskId: null, runId: null, action: LAND_DESTINATION, outcome: plan.ref, source: "request" }, { v: 1, ref: plan.ref, common: project.common });
578
624
  return recordActionWhole(store.handle, { at: now.toISOString(), actor: who.actor, repo: plan.repo, taskId: plan.rootId, runId: plan.runId, action: LAND_HANDOFF, outcome: "pending", source: "request" }, { v: 1, key: plan.key, ref: plan.ref, old: plan.old, commit, keep, folder: project.repo, policy: "squash", candidate: plan.candidate, base: plan.squash.base, tree: plan.squash.tree,
@@ -601,6 +647,7 @@ export async function land(store, taskId, input, authority, access, now, options
601
647
  throw new Refused(who);
602
648
  if (intents(store, "repo = ?", [plan.repo]).some(one => settledOf(store, one.id) === null))
603
649
  throw new Refused(refuse("busy", "Another landing in this project hasn't finished. Try again in a moment."));
650
+ consumeLandPasskey();
604
651
  if (!plan.recorded)
605
652
  recordActionWhole(store.handle, { at: now.toISOString(), actor: who.actor, repo: plan.repo, taskId: null, runId: null, action: LAND_DESTINATION, outcome: plan.ref, source: "request" }, { v: 1, ref: plan.ref, common: project.common });
606
653
  return recordActionWhole(store.handle, { at: now.toISOString(), actor: who.actor, repo: plan.repo, taskId: plan.rootId, runId: plan.runId, action: LAND_INTENT, outcome: "pending", source: "request" }, { v: 1, kind: plan.kind, key: plan.key, ref: plan.ref, old: plan.old, commit, mode: "ref", ...(plan.reverts === undefined ? {} : { reverts: plan.reverts.source }),
package/dist/models-ui.js CHANGED
@@ -75,7 +75,7 @@ function choiceSection(view, manage, previewing) {
75
75
  const presetItems = view.presets.map(one => ({ value: one.name, label: one.label, text: `${one.words}${one.recommended ? " Recommended." : ""}${one.inUse ? " In use." : ""}` }));
76
76
  const presets = manage
77
77
  ? html `<form method="get" action="/settings/models" class="models-presets" id="models-preset">${view.scope.value === "installation" ? "" : html `<input type="hidden" name="scope" value="${view.scope.value}">`}\
78
- ${radios({ name: "preset", legend: "Preset", current, items: presetItems })}${acts(btn("Review changes", { variant: previewing ? "outline" : "primary", type: "submit", docked: !previewing }))}</form>`
78
+ ${radios({ name: "preset", legend: "Preset", current, items: presetItems })}${acts(btn("Review changes", { variant: previewing || current === "" ? "outline" : "primary", type: "submit", docked: !previewing && current !== "" }))}</form>`
79
79
  : factList(view.presets.map(one => [one.label, `${one.words}${one.inUse ? " In use." : ""}`]));
80
80
  const newer = view.newer.length === 0 ? "" : html `${group("Newer models")}${view.newer.map(one => formRow(one.name, `Newer than ${one.from}, used by ${one.roles}.`, manage ? btn("Switch to it", { sm: true, href: `/settings/models?switch=${encodeURIComponent(one.from)}&to=${encodeURIComponent(one.to)}${scopeQuery(view)}` }) : html ``, "inline"))}`;
81
81
  const main = view.roles.filter(role => !role.tier), tiers = view.roles.filter(role => role.tier);
@@ -109,7 +109,10 @@ function sizingSection(view) {
109
109
  function recentSection(view) {
110
110
  if (view.recent.length === 0)
111
111
  return "";
112
- return sec("recent", "Recent work", "", view.recent.map(one => formRow(one.role, `Chosen ${one.chosen} → ran on ${one.ranOn}`, html `<a class="k-link k-mono" href="/t/${encodeURIComponent(one.taskId)}">${one.taskId}</a>`, "inline")));
112
+ return sec("recent", "Recent work", "", view.recent.map(one => {
113
+ const detail = one.ranOn === "not reported" ? `Set to ${one.chosen} · actual model not reported` : `Set to ${one.chosen} → ran on ${one.ranOn}`;
114
+ return formRow(one.role, detail, html `<a class="k-link k-mono" href="/t/${encodeURIComponent(one.taskId)}">${one.taskId}</a>`, "inline");
115
+ }));
113
116
  }
114
117
  function suggestedSection(view) {
115
118
  const s = view.suggested;