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(implies): read a phone's implies the way the CLI does [P6,B29]
Corey Olson93accab5d9b9
diff --git a/src/relay-requests.js b/src/relay-requests.jsindex 44d0c147..9041fad1 100644--- a/src/relay-requests.js+++ b/src/relay-requests.js@@ -3,6 +3,7 @@ import * as store from './board.js';import { createHash } from 'node:crypto';import { recordedRefusal } from './recorded-refusal.js';import { Refused } from './refused.js';+import { parseImplies } from './implies.js';import { validatePersonRequest } from './person-request.js';import { relayMoveActor } from './relay-sender.js';@@ -88,9 +89,10 @@ function fulfilsIntent(record, move) {&& (args.evidence === undefined ? value.evidence == null : value.evidence?.kind === args.evidence&& value.evidence.outcome === (args.outcome ?? '') && value.evidence.item === Number(args.item)&& /^[0-9a-f]{40,64}$/u.test(args.commit ?? '') && value.evidence.commit === args.commit);- // Every effect an answer can carry is bound to the request: no implied items or superseded answer the phone did not name.+ // Every effect an answer can carry is bound to the request, read as the CLI reads its flags: no implied+ // item or superseded answer the phone did not name, and none it named left out.if (intent.verb === 'answer') return value === intent.item && options?.asPerson === true && options.channel === 'view' && options.text === args.text- && JSON.stringify(options.implies ?? []) === JSON.stringify(args.implies ?? []) && (options.supersedes ?? null) === (args.supersedes ?? null);+ && JSON.stringify(options.implies ?? []) === JSON.stringify(requestedImplies(args.implies)) && (options.supersedes ?? null) === requestedAnswer(args.supersedes);if (intent.verb === 'hold') return value === args.lane && options?.asPerson === true && options.channel === 'view'&& (args.off || options.reason === (args.reason ?? ''));const rows = value?.decisions;@@ -102,6 +104,17 @@ function fulfilsIntent(record, move) {&& (args.text === undefined || row.text === args.text.trim()));}+/** The item ids a request's `implies` text names, parsed as `--implies` is, or null when it names none validly. */+function requestedImplies(text) {+ try { return parseImplies(text) ?? []; } catch { return null; } // an unreadable value matches no move+}++/** The answer id a request's `supersedes` text names, read as `--supersedes` is, or null for none. */+function requestedAnswer(text) {+ if (text === undefined || text === null) return null;+ return /^#?[1-9]\d*$/u.test(String(text).trim()) ? Number(String(text).trim().replace(/^#/u, '')) : NaN;+}+/** Keep receipt shouts fixed so a valid request cannot authorize unrelated person text or flags. */export function requestStageText(record, phase) {const text = phase === 'claim' ? 'Received a request from the paired view.'diff --git a/test/implies-phone.test.js b/test/implies-phone.test.jsindex f17098f7..b92dca84 100644--- a/test/implies-phone.test.js+++ b/test/implies-phone.test.js@@ -8,32 +8,24 @@ import { relayClientFixture } from './relay-client-fixture.js';import { preparePersonRequest } from '../src/person-request.js';import { decodeBoardKey, seal } from '../src/seal.js';import { ENGINE_VERSION } from '../src/machine.js';-const url = name => pathToFileURL(resolve(import.meta.dirname, '../src/' + name + '.js')).href;-for (const [label, extra, refusedCode] of [- ['the genuine text-only answer executes', '', null],- ['an added --implies is refused', ',implies:[TARGET]', 'PERSON_REQUEST_RECEIPT'],- ['an added --supersedes is refused', ',supersedes:999', 'PERSON_REQUEST_RECEIPT'],-]) test(`[P6,B26,B29] a phone answer authorizes only what the phone sent: ${label}`, async t => {- const box = await relayClientFixture(t);- await box.link();- const ask = await box.cli('shout', 'person', 'Which decision is approved?', '--decision');- assert.equal(ask.code, 0, JSON.stringify(ask.document));- assert.ok(Number.isSafeInteger(ask.document.id));- const target = box.before.tables.item[0].item_id;- const phone = await box.phoneSession();++const url = (name) => pathToFileURL(resolve(import.meta.dirname, '../src/' + name + '.js')).href;++/**+ * Post one genuine phone answer request through the real relay, claim it as this machine's executor,+ * then execute it with the given answer options. Returns the refusal code (or null), the result and+ * the answer each person-authored fact on the board cites. Pullboard's own executor may fulfil an+ * earlier genuine request later, so assertions count facts by the answer they cite.+ */+async function phoneAnswer(box, phone, { id, ask, args, options }) {const link = JSON.parse(readFileSync(box.linkFile, 'utf8'));- const id = 'phone-answer-' + label.split(' ')[1].replace(/[^a-z-]/gu, '');- const text = 'Only this answer text was approved on the phone';- const intent = preparePersonRequest({verb:'answer', item:ask.document.id, args:{text}}, id);- assert.equal(Object.hasOwn(intent.move.args, 'implies'), false);- assert.equal(Object.hasOwn(intent.move.args, 'supersedes'), false);+ const intent = preparePersonRequest({ verb: 'answer', item: ask, args }, id);const sealed = await seal(decodeBoardKey(readFileSync(box.keyFile, 'utf8').trim()), new TextEncoder().encode(JSON.stringify(intent)),- {boardId:link.board, kind:'request', sequence:link.sequence+1});- const posted = await fetch(box.origin+'/api/v1/boards/'+link.board+'/requests', {method:'POST',- headers:{authorization:'Bearer '+phone.token,'content-type':'application/json','x-pullboard-engine':String(ENGINE_VERSION)},- body:JSON.stringify({sequence:link.sequence+1,sealed:Buffer.from(sealed).toString('base64url')})});- assert.equal(posted.status,200);- assert.equal((await posted.json()).event.kind,'request');+ { boardId: link.board, kind: 'request', sequence: link.sequence + 1 });+ const posted = await fetch(box.origin + '/api/v1/boards/' + link.board + '/requests', { method: 'POST',+ headers: { authorization: 'Bearer ' + phone.token, 'content-type': 'application/json', 'x-pullboard-engine': String(ENGINE_VERSION) },+ body: JSON.stringify({ sequence: link.sequence + 1, sealed: Buffer.from(sealed).toString('base64url') }) });+ assert.equal(posted.status, 200, await posted.clone().text());const result = await box.script(`const {syncRelay,relayRequestDevice,relayOperation}=await import(${JSON.stringify(url('relay'))});const {personRequestRecords,requestIntentDigest,requestStageText}=await import(${JSON.stringify(url('relay-requests'))});@@ -50,18 +42,58 @@ for (const [label, extra, refusedCode] of [const lanes=laneNames(loadConfig(root));const tag={id:record.id,executor,digest:requestIntentDigest(record)};await relayOperation(root,'shout',[{from:'person',to:'coordinator',text:requestStageText(record,'claim'),lanes}],- {...io,personRequest:{...tag,phase:'claim'},personRequestMoveId:'phone-answer-claim'});+ {...io,personRequest:{...tag,phase:'claim'},personRequestMoveId:${JSON.stringify(id + '-claim')}});if(read().executor!==executor) throw new Error('actual executor claim missing');let refused=null,result=null;- try{result=await relayOperation(root,'answerDecision',[${ask.document.id},{agentId:'coordinator',asPerson:true,channel:'view',text:${JSON.stringify(text)},lanes${extra.replace('TARGET', String(target))}}],- {...io,personRequest:{...tag,phase:'execute'},personRequestMoveId:'phone-answer-execute'});}catch(error){refused=error.code;}+ try{result=await relayOperation(root,'answerDecision',[${ask},{agentId:'coordinator',asPerson:true,channel:'view',lanes,...${JSON.stringify(options)}}],+ {...io,personRequest:{...tag,phase:'execute'},personRequestMoveId:${JSON.stringify(id + '-execute')}});}catch(error){refused=error.code;}const b=store.openBoard(root+'/.git/pullboard/board.sqlite');let personFacts;- try{personFacts=b.db.prepare("SELECT event_detail FROM event WHERE event_kind='fact' AND event_by='person'").all();}finally{store.closeBoard(b);}- process.stdout.write(JSON.stringify({refused,result,personFactCount:personFacts.length}));+ try{personFacts=b.db.prepare("SELECT json_extract(event_detail,'$.decision.id') AS answer FROM event WHERE event_kind='fact' AND event_by='person'").all().map(row=>row.answer);}finally{store.closeBoard(b);}+ process.stdout.write(JSON.stringify({refused,result,personFacts}));`);- assert.equal(result.code,0, result.stderr);- assert.equal(result.document.refused, refusedCode, `${label}: ${JSON.stringify(result.document)}`);- if (refusedCode) assert.equal(result.document.personFactCount, 0, 'no person-authored implication the phone did not approve');- else assert.ok(result.document.result, 'the genuine phone answer is fulfilled');+ assert.equal(result.code, 0, result.stderr);+ return result.document;+}++/** A linked fixture board with a phone session and a person decision to answer. */+async function linkedBoard(t) {+ const box = await relayClientFixture(t);+ await box.link();+ const ask = async (text) => {+ const asked = await box.cli('shout', 'person', text, '--decision');+ assert.equal(asked.code, 0, JSON.stringify(asked.document));+ return asked.document.id;+ };+ return { box, ask, target: box.before.tables.item[0].item_id, phone: await box.phoneSession() };+}++const TEXT = 'The person approved this on the phone';++test('[P6,B26,B29] a phone answer executes with exactly the implied items it names', async (t) => {+ const { box, ask, target, phone } = await linkedBoard(t);+ const plain = await phoneAnswer(box, phone, { id: 'phone-plain', ask: await ask('Plain?'), args: { text: TEXT }, options: { text: TEXT } });+ assert.equal(plain.refused, null, `the genuine text-only answer executes: ${JSON.stringify(plain)}`);+ assert.deepEqual(plain.personFacts, [], 'a text-only answer implies nothing');+ const added = await phoneAnswer(box, phone, { id: 'phone-added', ask: await ask('Added?'), args: { text: TEXT }, options: { text: TEXT, implies: [target] } });+ assert.equal(added.refused, 'PERSON_REQUEST_RECEIPT', `an implied item the phone did not name is refused: ${JSON.stringify(added)}`);+ assert.deepEqual(added.personFacts, [], 'no person-authored fact the phone did not approve');+ const dropped = await phoneAnswer(box, phone, { id: 'phone-dropped', ask: await ask('Dropped?'), args: { text: TEXT, implies: String(target) }, options: { text: TEXT } });+ assert.equal(dropped.refused, 'PERSON_REQUEST_RECEIPT', `leaving out an item the phone named is refused: ${JSON.stringify(dropped)}`);+ assert.deepEqual(dropped.personFacts, [], 'a refused answer leaves no person fact');+ const named = await phoneAnswer(box, phone, { id: 'phone-named', ask: await ask('Named?'), args: { text: TEXT, implies: `#${target}` }, options: { text: TEXT, implies: [target] } });+ assert.equal(named.refused, null, `the item the phone named, written as the CLI takes it, executes: ${JSON.stringify(named)}`);+ assert.equal(named.personFacts.filter((answer) => answer === named.result).length, 1, `the phone-approved implication is one person fact citing its answer: ${JSON.stringify(named)}`);+});++test('[P6,B26,B31] a phone answer supersedes only the answer it names', async (t) => {+ const { box, ask, phone } = await linkedBoard(t);+ const first = await phoneAnswer(box, phone, { id: 'phone-first', ask: await ask('First?'), args: { text: TEXT }, options: { text: TEXT } });+ assert.equal(first.refused, null, JSON.stringify(first));+ const earlier = first.result;+ assert.ok(Number.isSafeInteger(earlier), `the first answer has an id: ${JSON.stringify(first)}`);+ const added = await phoneAnswer(box, phone, { id: 'phone-supersede-added', ask: await ask('Added?'), args: { text: TEXT }, options: { text: TEXT, supersedes: earlier } });+ assert.equal(added.refused, 'PERSON_REQUEST_RECEIPT', `a superseded answer the phone did not name is refused: ${JSON.stringify(added)}`);+ const named = await phoneAnswer(box, phone, { id: 'phone-supersede-named', ask: await ask('Named?'), args: { text: TEXT, supersedes: `#${earlier}` }, options: { text: TEXT, supersedes: earlier } });+ assert.equal(named.refused, null, `the answer the phone names as superseded executes: ${JSON.stringify(named)}`);});