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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(relay): publish exclusions during off [H5,H17]
Corey Olson9116e2f033ae
diff --git a/relay/device-http.js b/relay/device-http.jsindex a1d9dceb..6139336e 100644--- a/relay/device-http.js+++ b/relay/device-http.js@@ -24,6 +24,12 @@ export function createDeviceHandler({ authenticate, authorizeBoard, boardsFor, dconst who = await authenticate(req, !['GET', 'HEAD'].includes(req.method));const account = who.user.id;if (url.pathname === '/api/v1/devices/exclusions') {+ if (who.kind === 'machine' && req.method === 'POST') {+ await authorizeBoard(req, who.board);+ const body = await readApiBody(req, { maxBytes: 800000 });+ if (body?.machine !== who.machine) throw new Refused('EXCLUDED_INVENTORY', 'Publish only this authenticated machine’s sealed exclusion list.');+ apiJson(res, 200, devices.exclusions.publish(account, body)); return true;+ }if (who.kind !== 'session') throw new Refused('HUMAN_REQUIRED', 'Sign in as the person to publish or read excluded-board metadata.');if (req.method === 'GET') { apiJson(res, 200, { exclusions: devices.exclusions.metadata(account) }); return true; }if (req.method === 'POST') { apiJson(res, 200, devices.exclusions.publish(account, await readApiBody(req, { maxBytes: 800000 }))); return true; }diff --git a/src/relay-excluded.js b/src/relay-excluded.jsindex 562eb25c..1267e6b4 100644--- a/src/relay-excluded.js+++ b/src/relay-excluded.js@@ -19,7 +19,9 @@ import { Refused } from './refused.js';export async function publishExcludedBoards(session, io, request) {const machine = readRelayMachine();if (machine.owner?.account !== session.account || machine.owner?.url !== session.url) return;- if (!/^ps_[A-Za-z0-9_-]{43}$/u.test(session.token ?? '')) return;+ const person = /^ps_[A-Za-z0-9_-]{43}$/u.test(session.token ?? '');+ const publisher = /^pm_[A-Za-z0-9_-]{43}$/u.test(session.token ?? '') && session.machine === machine.machine;+ if (!person && !publisher) return;const names = listApiProjects().filter(project => machine.excluded.includes(project.root)).map(project => {const repository = originRepository(project.root, { optional: true });if (!repository) throw new Refused('EXCLUDED_REPOSITORY', 'Restore a GitHub origin for each excluded project, then run pullboard relay on --all.');diff --git a/src/relay.js b/src/relay.jsindex 0be93290..fb4fd708 100644--- a/src/relay.js+++ b/src/relay.js@@ -1644,13 +1644,29 @@ export async function relayOn(root, address, io, { session, credential, quiet =});}+/** Publish this machine's changed exclusions without retaining a person session or blocking local opt-out. */+async function publishOffExclusions(state, io) {+ const machine = readRelayMachine();+ const candidates = state ? [state] : [];+ for (const project of listApiProjects()) {+ try { const linked = loadLink(linkFile(project.root)); if (linked) candidates.push(linked); }+ catch { /* An unrelated broken link cannot prevent local exclusion. */ }+ }+ const publisher = candidates.find(value => value.machine === machine.machine+ && value.account === machine.owner?.account && value.url === machine.owner?.url+ && /^pm_[A-Za-z0-9_-]{43}$/u.test(value.token ?? ''));+ if (!publisher) return;+ try { await publishExcludedBoards(publisher, io, relayDeviceRequest); }+ catch { io.err('Excluded locally; the relay exclusion notice could not be updated. Run pullboard relay on --all when the relay is reachable.'); }+}+/** Unlink locally without approval, then request a separate phone-approved remote deletion if possible. */export async function relayOff(root, io) {updateRelayMachine(machine => { const project = repoInfo(root).root; if (!machine.excluded.includes(project)) machine.excluded.push(project); });const file = linkFile(root);return locked(file, async () => {const state = loadLink(file);- if (!state) return summary(root, null);+ if (!state) { await publishOffExclusions(null, io); return summary(root, null); }let joined = [];try {const roster = await request(state, '/auth/machines?board=' + state.board, {}, io);@@ -1666,6 +1682,7 @@ export async function relayOff(root, io) {rmSync(file, { force: true });try { forgetBoardKey(state.board, state.keyStorage); }catch { /* The local opt-out is complete even when secure key storage is temporarily locked. */ }+ await publishOffExclusions(state, io);let requested = false;let remote;try {diff --git a/test/relay-device-http.test.js b/test/relay-device-http.test.jsindex 6406faf5..9603cf31 100644--- a/test/relay-device-http.test.js+++ b/test/relay-device-http.test.js@@ -55,6 +55,20 @@ test('excluded inventories keep names sealed, isolate accounts and refuse revokeconst extra = await deviceRequest(box, path, { method: 'POST', cookie: owner, origin: box.origin, body: { ...body, names: ['forbidden'] } });assert.equal(extra.document.error?.code, 'EXCLUDED_INVENTORY', 'plaintext name fields are refused');assert.equal((await deviceRequest(box, path, { method: 'POST', cookie: owner, origin: box.origin, body })).response.status, 200);+ const board = 'b'.repeat(32);+ assert.equal((await deviceRequest(box, '/auth/boards/link', { method: 'POST', cookie: owner,+ origin: box.origin, body: { board, repository: 'fixture/repository' } })).response.status, 200);+ const issued = await deviceRequest(box, '/auth/machines', { method: 'POST', cookie: owner,+ origin: box.origin, body: { board, machine } });+ assert.equal(issued.response.status, 200);+ const token = issued.document.token;+ assert.equal((await deviceRequest(box, path, { method: 'POST', token, engine: ENGINE_VERSION, body })).response.status, 200,+ 'the enrolled machine can publish immediately without a retained person session');+ assert.equal((await deviceRequest(box, path, { token, engine: ENGINE_VERSION })).document.error?.code, 'HUMAN_REQUIRED',+ 'a machine credential cannot read the account inventory');+ assert.equal((await deviceRequest(box, path, { method: 'POST', token, engine: ENGINE_VERSION,+ body: { ...body, machine: 'another-machine' } })).document.error?.code, 'EXCLUDED_INVENTORY',+ 'a machine credential cannot replace another machine’s list');box.restart();const metadata = await deviceRequest(box, path, { cookie: owner });assert.deepEqual(metadata.document.exclusions, [{ machine, label, count: 1 }], 'durable public metadata has no name, key or wrap');