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.
Files changed (48) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/accent-colors.js +3 -1
  3. package/dist/approval-authority.js +2 -1
  4. package/dist/assignment.js +55 -2
  5. package/dist/backup.js +6 -0
  6. package/dist/browser/terminal.css +1 -1
  7. package/dist/browser/workspace.css +1 -1
  8. package/dist/central-recovery-stage.js +3 -3
  9. package/dist/companion/access.js +161 -0
  10. package/dist/companion/actions.js +559 -0
  11. package/dist/companion/bonjour.js +45 -0
  12. package/dist/companion/daemon.js +1346 -0
  13. package/dist/companion/direct-server.js +177 -0
  14. package/dist/companion/framing.js +498 -0
  15. package/dist/companion/noise.js +461 -0
  16. package/dist/companion/passkey-gate.js +287 -0
  17. package/dist/companion/paths.js +90 -0
  18. package/dist/companion/reads.js +279 -0
  19. package/dist/companion/relay-auth.js +265 -0
  20. package/dist/companion/relay-server.js +870 -0
  21. package/dist/companion/schema.js +225 -0
  22. package/dist/companion/service.js +580 -0
  23. package/dist/companion/store.js +324 -0
  24. package/dist/companion/webauthn-test-support.js +44 -0
  25. package/dist/companion/webauthn.js +398 -0
  26. package/dist/contracts/console-api.js +18 -0
  27. package/dist/design/kit.css +30 -0
  28. package/dist/local-landing.js +47 -0
  29. package/dist/person-proof.js +5 -1
  30. package/dist/pull-request-flow.js +75 -2
  31. package/dist/qr.js +385 -0
  32. package/dist/release-adapters.js +2 -1
  33. package/dist/restore-retirement.js +2 -0
  34. package/dist/scope.js +67 -4
  35. package/dist/serve.js +31 -4
  36. package/dist/server/pages.js +9 -2
  37. package/dist/server/phone-engine-api.js +59 -0
  38. package/dist/server/route-table.js +11 -0
  39. package/dist/server/settings-phone.js +492 -0
  40. package/dist/server/settings-scripts.js +2 -0
  41. package/dist/server/settings-sections.js +6 -2
  42. package/dist/settings-groups-ui.js +2 -1
  43. package/dist/settings-proofs.js +6 -0
  44. package/dist/store.js +37 -4
  45. package/dist/tailnet.js +42 -0
  46. package/dist/toolroll-update.js +3 -1
  47. package/dist/youiyoux-intake.js +8 -0
  48. package/package.json +7 -2
@@ -0,0 +1,225 @@
1
+ export const COMPANION_RETIRED_REASONS = ["removed", "password_changed", "access_changed", "restored", "migration", "contested", "pairing_failed"];
2
+ export const V187_SCHEMA = `
3
+ CREATE TABLE IF NOT EXISTS companion_access (
4
+ singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
5
+ enabled INTEGER NOT NULL CHECK (enabled IN (0, 1)),
6
+ changed_by TEXT NOT NULL,
7
+ changed_at TEXT NOT NULL,
8
+ hosted_relay TEXT,
9
+ direct_port INTEGER
10
+ );
11
+ CREATE TABLE IF NOT EXISTS companion_host_keys (
12
+ singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
13
+ noise_static_priv TEXT NOT NULL,
14
+ noise_static_pub TEXT NOT NULL,
15
+ relay_priv TEXT NOT NULL,
16
+ relay_pub TEXT NOT NULL,
17
+ machine_id TEXT NOT NULL,
18
+ created_at TEXT NOT NULL
19
+ );
20
+ CREATE TABLE IF NOT EXISTS companion_paired_device (
21
+ device_id TEXT PRIMARY KEY,
22
+ account_name TEXT NOT NULL,
23
+ device_name TEXT NOT NULL,
24
+ phone_static_pub TEXT NOT NULL,
25
+ device_relay_pub TEXT NOT NULL,
26
+ device_psk TEXT NOT NULL,
27
+ recovery_generation TEXT NOT NULL,
28
+ account_generation INTEGER NOT NULL,
29
+ created_at TEXT NOT NULL,
30
+ activated_at TEXT,
31
+ last_seen_at TEXT,
32
+ revoked_at TEXT,
33
+ revoked_reason TEXT CHECK (revoked_reason IS NULL OR revoked_reason IN ('removed', 'password_changed', 'access_changed', 'restored', 'migration', 'contested', 'pairing_failed')),
34
+ CHECK ((revoked_at IS NULL) = (revoked_reason IS NULL))
35
+ );
36
+ `;
37
+ export const V187_STEPS = Object.freeze(["companion"]);
38
+ export const V187_TABLES = Object.freeze(["companion_access", "companion_host_keys", "companion_paired_device"]);
39
+ export const V187_DROPPED_TABLES = Object.freeze(["companion_push_token", "companion_idempotency"]);
40
+ const shapeOf = (columns) => JSON.stringify(columns);
41
+ function columnsOf(db, table) {
42
+ return db.prepare(`PRAGMA table_info(${table})`).all()
43
+ .map(row => [String(row["name"]), String(row["type"]).toUpperCase(), Number(row["notnull"]) === 1 ? 1 : 0, Number(row["pk"])]);
44
+ }
45
+ const tableExists = (db, table) => db.prepare("SELECT 1 AS hit FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) !== undefined;
46
+ const ACCESS_BASE = [["singleton", "INTEGER", 0, 1], ["enabled", "INTEGER", 1, 0], ["changed_by", "TEXT", 1, 0], ["changed_at", "TEXT", 1, 0]];
47
+ const ACCESS_V187 = [...ACCESS_BASE, ["hosted_relay", "TEXT", 0, 0], ["direct_port", "INTEGER", 0, 0]];
48
+ const ACCESS_LEGACY = [shapeOf(ACCESS_BASE), shapeOf([...ACCESS_BASE, ["hosted_relay", "TEXT", 0, 0]])];
49
+ const HOST_KEYS_V187 = [["singleton", "INTEGER", 0, 1], ["noise_static_priv", "TEXT", 1, 0], ["noise_static_pub", "TEXT", 1, 0],
50
+ ["relay_priv", "TEXT", 1, 0], ["relay_pub", "TEXT", 1, 0], ["machine_id", "TEXT", 1, 0], ["created_at", "TEXT", 1, 0]];
51
+ const HOST_KEYS_LEGACY = shapeOf([...HOST_KEYS_V187.slice(0, 6), ["relay_url", "TEXT", 1, 0], ["created_at", "TEXT", 1, 0]]);
52
+ const DEVICE_V187 = [["device_id", "TEXT", 0, 1], ["account_name", "TEXT", 1, 0], ["device_name", "TEXT", 1, 0], ["phone_static_pub", "TEXT", 1, 0],
53
+ ["device_relay_pub", "TEXT", 1, 0], ["device_psk", "TEXT", 1, 0], ["recovery_generation", "TEXT", 1, 0], ["account_generation", "INTEGER", 1, 0],
54
+ ["created_at", "TEXT", 1, 0], ["activated_at", "TEXT", 0, 0], ["last_seen_at", "TEXT", 0, 0], ["revoked_at", "TEXT", 0, 0], ["revoked_reason", "TEXT", 0, 0]];
55
+ const DEVICE_LEGACY_BASE = [["device_id", "TEXT", 0, 1], ["account_name", "TEXT", 1, 0], ["device_name", "TEXT", 1, 0], ["phone_static_pub", "TEXT", 1, 0],
56
+ ["device_relay_pub", "TEXT", 1, 0], ["device_psk", "TEXT", 1, 0], ["next_device_psk", "TEXT", 0, 0], ["psk_version", "INTEGER", 1, 0],
57
+ ["recovery_generation", "TEXT", 1, 0], ["created_at", "TEXT", 1, 0], ["last_seen_at", "TEXT", 0, 0], ["revoked_at", "TEXT", 0, 0]];
58
+ const DEVICE_LEGACY = { base: shapeOf(DEVICE_LEGACY_BASE), generation: shapeOf([...DEVICE_LEGACY_BASE, ["account_generation", "INTEGER", 0, 0]]) };
59
+ const DROPPED_SHAPES = {
60
+ companion_push_token: shapeOf([["device_id", "TEXT", 0, 1], ["apns_token", "TEXT", 1, 0], ["p256dh", "TEXT", 1, 0], ["auth_secret", "TEXT", 1, 0],
61
+ ["include_titles", "INTEGER", 1, 0], ["updated_at", "TEXT", 1, 0]]),
62
+ companion_idempotency: shapeOf([["device_id", "TEXT", 1, 1], ["idempotency_key", "TEXT", 1, 2], ["method", "TEXT", 1, 0], ["request_hash", "TEXT", 1, 0],
63
+ ["state", "TEXT", 1, 0], ["outcome_json", "TEXT", 0, 0], ["updated_at", "TEXT", 1, 0]]),
64
+ };
65
+ const TARGET = {
66
+ companion_access: shapeOf(ACCESS_V187),
67
+ companion_host_keys: shapeOf(HOST_KEYS_V187),
68
+ companion_paired_device: shapeOf(DEVICE_V187),
69
+ };
70
+ export function companionShapeProblem(db) {
71
+ for (const table of V187_TABLES) {
72
+ if (!tableExists(db, table))
73
+ return `the phone access table ${table} is missing`;
74
+ if (shapeOf(columnsOf(db, table)) !== TARGET[table])
75
+ return `the phone access table ${table} has an unknown shape`;
76
+ }
77
+ for (const table of V187_DROPPED_TABLES)
78
+ if (tableExists(db, table))
79
+ return `the retired phone access table ${table} is still here`;
80
+ return null;
81
+ }
82
+ function rebuild(db, table, ddl, columns, select) {
83
+ const next = `${table}_v187`;
84
+ db.exec(`DROP TABLE IF EXISTS ${next}`);
85
+ db.exec(ddl.replace(`CREATE TABLE IF NOT EXISTS ${table} (`, `CREATE TABLE ${next} (`));
86
+ db.exec(`INSERT INTO ${next} (rowid, ${columns.join(", ")}) SELECT rowid, ${select.join(", ")} FROM ${table}`);
87
+ db.exec(`DROP TABLE ${table}`);
88
+ db.exec(`ALTER TABLE ${next} RENAME TO ${table}`);
89
+ }
90
+ const ddlOf = (table) => {
91
+ const statement = V187_SCHEMA.split(/;\s*\n/).map(one => one.trim()).find(one => one.startsWith(`CREATE TABLE IF NOT EXISTS ${table} (`));
92
+ if (statement === undefined)
93
+ throw new Error(`no v187 DDL for ${table}`);
94
+ return statement;
95
+ };
96
+ export function adoptLegacyCompanion(db, now) {
97
+ if (tableExists(db, "companion_access")) {
98
+ const shape = shapeOf(columnsOf(db, "companion_access"));
99
+ if (shape !== TARGET.companion_access) {
100
+ if (!ACCESS_LEGACY.includes(shape))
101
+ throw new Error("the phone access table companion_access has an unknown shape; refusing to adopt it");
102
+ if (!columnsOf(db, "companion_access").some(([name]) => name === "hosted_relay"))
103
+ db.exec("ALTER TABLE companion_access ADD COLUMN hosted_relay TEXT");
104
+ db.exec("ALTER TABLE companion_access ADD COLUMN direct_port INTEGER");
105
+ }
106
+ }
107
+ if (tableExists(db, "companion_host_keys")) {
108
+ const shape = shapeOf(columnsOf(db, "companion_host_keys"));
109
+ if (shape !== TARGET.companion_host_keys) {
110
+ if (shape !== HOST_KEYS_LEGACY)
111
+ throw new Error("the phone access table companion_host_keys has an unknown shape; refusing to adopt it");
112
+ const columns = HOST_KEYS_V187.map(([name]) => name);
113
+ rebuild(db, "companion_host_keys", ddlOf("companion_host_keys"), columns, columns);
114
+ }
115
+ }
116
+ if (tableExists(db, "companion_paired_device")) {
117
+ const shape = shapeOf(columnsOf(db, "companion_paired_device"));
118
+ if (shape !== TARGET.companion_paired_device) {
119
+ if (shape !== DEVICE_LEGACY.base && shape !== DEVICE_LEGACY.generation) {
120
+ throw new Error("the phone access table companion_paired_device has an unknown shape; refusing to adopt it");
121
+ }
122
+ const generation = shape === DEVICE_LEGACY.generation ? "account_generation" : "NULL";
123
+ const stamp = `'${now.toISOString()}'`;
124
+ const columns = DEVICE_V187.map(([name]) => name);
125
+ const select = columns.map(name => {
126
+ switch (name) {
127
+ case "account_generation": return `COALESCE(${generation}, -1)`;
128
+ case "activated_at": return "created_at";
129
+ case "revoked_at": return `CASE WHEN revoked_at IS NOT NULL THEN revoked_at WHEN ${generation} IS NULL THEN ${stamp} ELSE NULL END`;
130
+ case "revoked_reason": return `CASE WHEN revoked_at IS NOT NULL THEN 'removed' WHEN ${generation} IS NULL THEN 'migration' ELSE NULL END`;
131
+ default: return name;
132
+ }
133
+ });
134
+ rebuild(db, "companion_paired_device", ddlOf("companion_paired_device"), columns, select);
135
+ }
136
+ }
137
+ for (const table of V187_DROPPED_TABLES) {
138
+ if (!tableExists(db, table))
139
+ continue;
140
+ if (shapeOf(columnsOf(db, table)) !== DROPPED_SHAPES[table])
141
+ throw new Error(`the retired phone access table ${table} has an unknown shape; refusing to drop it`);
142
+ db.exec(`DROP TABLE ${table}`);
143
+ }
144
+ db.exec(V187_SCHEMA);
145
+ }
146
+ export const V188_SCHEMA = `
147
+ CREATE TABLE IF NOT EXISTS account_passkeys (
148
+ credential_id TEXT PRIMARY KEY,
149
+ workspace_id TEXT NOT NULL,
150
+ account_name TEXT NOT NULL,
151
+ user_handle TEXT NOT NULL,
152
+ public_key_spki TEXT NOT NULL,
153
+ sign_count INTEGER NOT NULL CHECK (sign_count >= 0),
154
+ label TEXT NOT NULL,
155
+ created_at TEXT NOT NULL,
156
+ last_used_at TEXT,
157
+ recovery_generation TEXT NOT NULL,
158
+ revoked_at TEXT
159
+ );
160
+ CREATE INDEX IF NOT EXISTS idx_account_passkeys_owner ON account_passkeys (workspace_id, account_name, recovery_generation);
161
+ CREATE TABLE IF NOT EXISTS passkey_challenges (
162
+ challenge TEXT PRIMARY KEY,
163
+ kind TEXT NOT NULL CHECK (kind IN ('register', 'approve', 'accept', 'land', 'ship', 'unlock')),
164
+ workspace_id TEXT NOT NULL,
165
+ account_name TEXT NOT NULL,
166
+ device_id TEXT NOT NULL,
167
+ recovery_generation TEXT NOT NULL,
168
+ binding_json TEXT NOT NULL,
169
+ expires_at TEXT NOT NULL,
170
+ consumed_at TEXT
171
+ );
172
+ CREATE INDEX IF NOT EXISTS idx_passkey_challenges_expires ON passkey_challenges (expires_at);
173
+ CREATE TABLE IF NOT EXISTS device_idempotency (
174
+ device_id TEXT NOT NULL,
175
+ idempotency_key TEXT NOT NULL,
176
+ method TEXT NOT NULL,
177
+ request_hash TEXT NOT NULL,
178
+ state TEXT NOT NULL CHECK (state IN ('in_flight', 'completed', 'unknown')),
179
+ outcome_json TEXT,
180
+ updated_at TEXT NOT NULL,
181
+ PRIMARY KEY (device_id, idempotency_key)
182
+ );
183
+ CREATE INDEX IF NOT EXISTS idx_device_idempotency_updated ON device_idempotency (device_id, state, updated_at);
184
+ CREATE TABLE IF NOT EXISTS passkey_approval_policy (
185
+ scope TEXT PRIMARY KEY,
186
+ required INTEGER NOT NULL CHECK (required IN (0, 1)),
187
+ window_minutes INTEGER NOT NULL DEFAULT 15 CHECK (window_minutes IN (0, 15, 60))
188
+ );
189
+ `;
190
+ export const V188_STEPS = Object.freeze(["companion-passkey"]);
191
+ export const V188_TABLES = Object.freeze(["account_passkeys", "passkey_challenges", "device_idempotency", "passkey_approval_policy"]);
192
+ const PASSKEYS_V188 = [
193
+ ["credential_id", "TEXT", 0, 1], ["workspace_id", "TEXT", 1, 0], ["account_name", "TEXT", 1, 0],
194
+ ["user_handle", "TEXT", 1, 0], ["public_key_spki", "TEXT", 1, 0], ["sign_count", "INTEGER", 1, 0],
195
+ ["label", "TEXT", 1, 0], ["created_at", "TEXT", 1, 0], ["last_used_at", "TEXT", 0, 0],
196
+ ["recovery_generation", "TEXT", 1, 0], ["revoked_at", "TEXT", 0, 0],
197
+ ];
198
+ const CHALLENGES_V188 = [
199
+ ["challenge", "TEXT", 0, 1], ["kind", "TEXT", 1, 0], ["workspace_id", "TEXT", 1, 0],
200
+ ["account_name", "TEXT", 1, 0], ["device_id", "TEXT", 1, 0], ["recovery_generation", "TEXT", 1, 0],
201
+ ["binding_json", "TEXT", 1, 0], ["expires_at", "TEXT", 1, 0], ["consumed_at", "TEXT", 0, 0],
202
+ ];
203
+ const IDEMPOTENCY_V188 = [
204
+ ["device_id", "TEXT", 1, 1], ["idempotency_key", "TEXT", 1, 2], ["method", "TEXT", 1, 0],
205
+ ["request_hash", "TEXT", 1, 0], ["state", "TEXT", 1, 0], ["outcome_json", "TEXT", 0, 0],
206
+ ["updated_at", "TEXT", 1, 0],
207
+ ];
208
+ const POLICY_V188 = [
209
+ ["scope", "TEXT", 0, 1], ["required", "INTEGER", 1, 0], ["window_minutes", "INTEGER", 1, 0],
210
+ ];
211
+ const TARGET_V188 = {
212
+ account_passkeys: shapeOf(PASSKEYS_V188),
213
+ passkey_challenges: shapeOf(CHALLENGES_V188),
214
+ device_idempotency: shapeOf(IDEMPOTENCY_V188),
215
+ passkey_approval_policy: shapeOf(POLICY_V188),
216
+ };
217
+ export function companionPasskeyShapeProblem(db) {
218
+ for (const table of V188_TABLES) {
219
+ if (!tableExists(db, table))
220
+ return `the passkey approval table ${table} is missing`;
221
+ if (shapeOf(columnsOf(db, table)) !== TARGET_V188[table])
222
+ return `the passkey approval table ${table} has an unknown shape`;
223
+ }
224
+ return null;
225
+ }