Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

chore(core): merge phone recovery before compression [H5,H17]

Corey Olsonc275eac27160
diff --cc relay/browser-client.js
index 0376a85b,dbf85056..468d4758
--- a/relay/browser-client.js
+++ b/relay/browser-client.js
@@@ -1,4 -1,4 +1,4 @@@
- /** Device-only relay transport: cookie authorization, local keys and authenticated ciphertext [H5,H15]. */
-/** Device-only relay transport: cookie authorization, local keys and authenticated ciphertext [H5,H15,H16]. */
++/** Device-only relay transport: cookie authorization, local keys and authenticated ciphertext [H5,H15,H16,H17]. */
import { rememberDevicePairing, enrollPhone, deviceBoardKeys } from './browser-devices.js';
import { decodeBoardKey, encodeBoardKey, seal, unseal } from './seal.js';
import { preparePersonRequest, validatePersonRequest } from './person-request.js';
@@@ -41,23 -41,13 +41,30 @@@ function transportBytes(value)
return Uint8Array.from(binary, character => character.charCodeAt(0));
}
+/** Inflate a new gzip snapshot or preserve the legacy JSON plaintext format. */
+async function snapshotDocument(plain) {
+ if (plain[0] === 0x1f && plain[1] === 0x8b) {
+ if (typeof DecompressionStream !== 'function') throw new Error('This browser cannot read gzip snapshots. Upgrade the browser client.');
+ try {
+ const stream = new Blob([plain]).stream().pipeThrough(new DecompressionStream('gzip'));
+ return JSON.parse(await new Response(stream).text());
+ } catch { throw new Refused('SNAPSHOT_FORMAT', 'The sealed gzip snapshot is invalid. Refresh it from a linked machine.'); }
+ }
+ if (plain[0] !== 0x7b) {
+ const seen = [...plain.slice(0, 4)].map(value => value.toString(16).padStart(2, '0')).join('') || 'no bytes';
+ throw new Refused('SNAPSHOT_FORMAT', `The sealed snapshot starts with ${seen}; expected gzip magic 1f8b or legacy JSON starting with 7b.`);
+ }
+ try { return JSON.parse(new TextDecoder().decode(plain)); }
+ catch { throw new Refused('SNAPSHOT_FORMAT', 'The sealed legacy JSON snapshot is invalid. Refresh it from a linked machine.'); }
+}
+
+ /** Confirm session authorization before treating a board-local refusal as global access loss. */
+ async function checkAuthorization(path, status, onDenied) {
+ if (![401, 403].includes(status) || !onDenied) return;
+ if (['/api/v1/boards', '/api/v1/devices/session'].includes(new URL(path, location.origin).pathname)) onDenied();
+ else await documentAt('/api/v1/devices/session', onDenied);
+ }
+
/** Fetch only same-origin API documents, retaining stable refusal guidance and no provider details. */
async function documentAt(path, onDenied, options = {}) {
const headers = new Headers(options.headers ?? {});