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.

fix(relay): reconcile unreadable keys with file storage [H10,H17]

Corey Olsonb7a05745c741
diff --cc src/relay-key.js
index 6d6101a1,4cb2cda0..3789a0b1
--- a/src/relay-key.js
+++ b/src/relay-key.js
@@@ -70,12 -68,12 +68,17 @@@ export function readBoardKey(boardId)
if (existsSync(file)) {
const stat = lstatSync(file);
if (!stat.isFile() || stat.isSymbolicLink() || (stat.mode & 0o077)) throw new Refused('RELAY_KEY_STORAGE', 'restore the board key as an owner-only regular file with mode 600');
- try {
- return decodeBoardKey(readFileSync(file, 'utf8').trim());
- } catch (error) {
- const encoded = readFileSync(file, 'utf8').trim();
++ let encoded;
++ try { encoded = readFileSync(file, 'utf8').trim(); }
++ catch (error) {
+ if (!['EACCES', 'EPERM'].includes(error.code)) throw error;
+ throw new Refused('RELAY_KEY_MISSING', 'the board key is unreadable in this shell (' + error.code + '); run this command where the key is available, or pair this device');
+ }
+ const key = decodeBoardKey(encoded);
+ if (process.env.PULLBOARD_RELAY_KEY !== undefined && process.env.PULLBOARD_RELAY_KEY !== encoded) {
+ throw new Refused('RELAY_KEY_FILE_ENV_MISMATCH', 'PULLBOARD_RELAY_KEY differs from this board key file; unset PULLBOARD_RELAY_KEY or set it to the key from this device file');
+ }
+ return key;
}
const service = keychain();
if (service) {
@@@ -83,9 -81,18 +86,18 @@@
? ['find-generic-password', '-a', id, '-s', 'pullboard.board-key', '-w']
: ['lookup', 'application', 'pullboard', 'board', id];
const found = spawnSync(service, args, { encoding: 'utf8', timeout: 10000 });
- if (found.status === 0) return decodeBoardKey(found.stdout.trim());
+ if (found.status === 0) {
+ const encoded = found.stdout.trim();
+ const key = decodeBoardKey(encoded);
+ // Keep the legacy value until a verified private file exists; roll back if deletion fails.
+ const migrated = writeKeyFile(id, encoded);
+ try { removeKeychainValue(service, id); }
+ catch (error) { rmSync(migrated, { force: true }); throw error; }
+ return key;
+ }
}
- throw new Refused('RELAY_KEY_MISSING', 'the board key is missing on this device; run this command where the key is available, or pair this device');
+ if (process.env.PULLBOARD_RELAY_KEY !== undefined) return decodeBoardKey(process.env.PULLBOARD_RELAY_KEY);
- throw new Refused('RELAY_KEY_MISSING', 'the board key is missing on this device; set PULLBOARD_RELAY_KEY from your local secret store, pair this device again, or run pullboard relay off then relay on to upload a new sealed snapshot');
++ throw new Refused('RELAY_KEY_MISSING', 'the board key is missing on this device; set PULLBOARD_RELAY_KEY from your local secret store, pair this device again, or run pullboard relay off then relay on to upload a new sealed snapshot; run this command where the key is available, or pair this device');
}
/** Remove the device key after a successful unlink, leaving all local board records untouched. */