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
test(person): exercise native apply approval provenance [E22,H16]
Corey Olsonf16613f54215
diff --git a/src/commands/spec.js b/src/commands/spec.jsindex eef92c77..9ab83526 100644--- a/src/commands/spec.js+++ b/src/commands/spec.js@@ -390,6 +390,7 @@ export async function specCommand(io, { first, second, rest, values }) {return errors ? 1 : 0;}if (first === 'signers' && second === 'add') {+ if (signsPersonMoves(ctx.info.root)) throw new Refused('PERSON_SIGNER_REQUIRED', `SSH signer ${values.by ?? defaultPrincipal(ctx.info.root)} cannot be enrolled by a passkey identity`, 'keep signing on and use passkey row approvals; named SSH signer changes wait until signing is off');requirePersonChannel(io.personChannel);const signer = addSigner(ctx.info.root, { by: values.by, key: values.key });io.result?.(signer);diff --git a/src/person-presence.js b/src/person-presence.jsindex 7118863a..83b9bea4 100644--- a/src/person-presence.js+++ b/src/person-presence.js@@ -23,3 +23,14 @@ export function presenceSigned(stamp, publicKey) {return key.asymmetricKeyType === 'ed25519' && verify(null, presenceAttestation(stamp), key, Buffer.from(stamp.signature, 'base64url'));} catch { return false; } // An unreadable key or signature verifies nothing; the caller fails closed.}++/**+ * The relay's passkey stamp on a person request: the board, the request id and intent digest it was granted for,+ * the passkey, when, and the relay's signature over them [E22].+ */+export function validPresence(value) {+ return Boolean(value && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).sort().join() === 'at,board,credential,digest,request,signature' &&+ typeof value.request === 'string' && /^[A-Za-z0-9_-]{1,80}$/u.test(value.request) && typeof value.credential === 'string' &&+ /^[A-Za-z0-9_-]{1,1400}$/u.test(value.credential) && Number.isSafeInteger(value.at) && value.at > 0 &&+ /^[0-9a-f]{32}$/u.test(value.board ?? '') && /^[0-9a-f]{64}$/u.test(value.digest ?? '') && /^[A-Za-z0-9_-]{86}$/u.test(value.signature ?? ''));+}diff --git a/src/person-row-proof.js b/src/person-row-proof.jsnew file mode 100644index 00000000..52457d37--- /dev/null+++ b/src/person-row-proof.js@@ -0,0 +1,56 @@+/** Read-only validation of optional row approvals, without importing the mutable board or CLI graph [E22,H16]. */+import { createHash } from 'node:crypto';+import { isDeepStrictEqual } from 'node:util';+import { parseSpec } from './spec.js';+import { answerQuestion } from './blueprints.js';+import {+ presenceSigned,+ validPresence,+} from './person-presence.js';+import { rowDecisionReplacement } from './row-decision-text.js';++/** Keep the original signed request's complete row effect, including source fields and optional signer boundaries. */+export function signedRowDecisionsMatch(request, rows) {+ try {+ const document = JSON.parse(request.encoded);+ const { verb, args } = document.move;+ if (!['spec-approve', 'spec-decline', 'spec-answer'].includes(verb) || args.by !== undefined && args.by !== 'person') return false;+ const ids = verb === 'spec-answer' ? [args.row] : args.ids.split(/[\s,]+/u).filter(Boolean);+ if (!Array.isArray(rows) || rows.length !== ids.length || !Array.isArray(document.rows) || document.rows.length !== ids.length) return false;+ return rows.every((row, index) => {+ const id = ids[index];+ const shown = document.rows.find(entry => entry.id === id);+ const original = parseSpec(`## Decision\n${row.source}\n`).rows[0];+ const kindId = row.kind === 'doctrine' ? `doctrine:${row.id}` : row.id;+ const decision = verb === 'spec-decline' ? 'decline' : 'approve';+ const text = verb === 'spec-answer' ? answerQuestion(shown.text, args.answer, args.row).text+ : args.text === undefined ? shown.text : args.text.trim();+ return shown && original && kindId === id && original.id === row.id && original.text === shown.text && !original.signers?.length+ && row.decision === decision && row.text === text && row.by === 'person' && row.signature === undefined+ && row.reason === (decision === 'decline' ? args.reason.trim() : '') && row.passkeyRequest === request.id+ && row.replacement === rowDecisionReplacement(row.source, decision, text);+ });+ } catch { return false; }+}++/** Ignore mutable local projection fields while keeping all original decision fields exact. */+function decisionBody({ event, at, applied, appliedAt, ...value }) { return value; }++/** Verify a decision from its immutable signed intent and exact committed result; a local marker alone grants nothing. */+export function verifiedPasskeyRowDecision(board, decision) {+ try {+ if (typeof decision.passkeyRequest !== 'string' || decision.by !== 'person' || decision.signature !== undefined) return false;+ const read = key => board.db.prepare('SELECT meta_value FROM board_meta WHERE meta_key=?').get(key)?.meta_value;+ const request = JSON.parse(read('relay_person_requests') ?? '[]').find(record => record.id === decision.passkeyRequest && !record.duplicateOf);+ if (!request || !Number.isSafeInteger(request.resultSequence) || request.resultSequence < 1) return false;+ const source = JSON.parse(request.received);+ const stamp = source.sender?.presence;+ const pin = JSON.parse(read('person_authority_local') ?? 'null');+ if (source.sender?.kind !== 'person' || typeof source.sender.userId !== 'string' || !source.sender.userId+ || JSON.stringify(source.document) !== request.encoded || JSON.stringify(source.document.move) !== JSON.stringify(request.move)+ || stamp?.board !== read('board_id') || stamp?.request !== request.id+ || stamp?.digest !== createHash('sha256').update(request.encoded).digest('hex')+ || !validPresence(stamp) || !pin || !presenceSigned(stamp, pin.publicKey) || !signedRowDecisionsMatch(request, request.result)) return false;+ return request.result.some(record => record.event === decision.event && isDeepStrictEqual(decisionBody(record), decisionBody(decision)));+ } catch { return false; }+}diff --git a/src/person-signing.js b/src/person-signing.jsindex 5ccaf3f8..2d7d99f2 100644--- a/src/person-signing.js+++ b/src/person-signing.js@@ -14,13 +14,11 @@ import {SIGNED_EVENT_LOG_VERSION,} from './board.js';import { createHash } from 'node:crypto';-import { isDeepStrictEqual } from 'node:util';import { Refused } from './refused.js';import { validatePersonRequest } from './person-request.js';import {personRequestRecords,requestIntentDigest,- requestRowDecisionsMatch,} from './relay-requests.js';import { validPresence } from './relay-sender.js';import { presenceSigned } from './person-presence.js';@@ -209,15 +207,7 @@ export function requestPresence(board, id, { strict = true } = {}) {&& stampHolds(board, presence, strict) ? presence : null;}-/** Verify an optional row's exact committed result against the original relay-attested passkey intent. */-export function verifiedPasskeyRowDecision(board, decision) {- if (typeof decision.passkeyRequest !== 'string' || decision.by !== 'person' || decision.signature !== undefined) return false;- const request = personRequestRecords(board).find(record => record.id === decision.passkeyRequest && !record.duplicateOf);- if (!request || !Number.isSafeInteger(request.resultSequence) || !requestPresence(board, request.id)- || !requestRowDecisionsMatch(board, request, request.result)) return false;- const strip = ({ event, at, applied, appliedAt, ...value }) => value;- return request.result.some(record => record.event === decision.event && isDeepStrictEqual(strip(record), strip(decision)));-}+export { verifiedPasskeyRowDecision } from './person-row-proof.js';/** Whether this command or move carries out a person request a passkey confirmed. */export function passkeyConfirmed(board, personRequest, { strict = true } = {}) {diff --git a/src/relay-requests.js b/src/relay-requests.jsindex 96a4c673..014b3bb0 100644--- a/src/relay-requests.js+++ b/src/relay-requests.js@@ -5,8 +5,7 @@ import { recordedRefusal } from './recorded-refusal.js';import { Refused } from './refused.js';import { answerQuestion } from './blueprints.js';import { personSigning } from './person-signing.js';-import { parseSpec } from './spec.js';-import { rowDecisionReplacement } from './row-decision-text.js';+import { signedRowDecisionsMatch } from './person-row-proof.js';import { parseImplies } from './implies.js';import { validatePersonRequest } from './person-request.js';import { relayMoveActor } from './relay-sender.js';@@ -143,7 +142,7 @@ function fulfilsIntent(record, move, board) {return value?.agentId === 'person' && value.channel === 'view' && value.decisions?.length === 1&& value.decisions[0].id === args.row && value.decisions[0].kind === 'spec'&& value.decisions[0].decision === 'approve' && value.decisions[0].text === text && value.decisions[0].by === 'person'- && value.decisions[0].signature === undefined && boundSignedRow(record, value.decisions[0], args.row, text);+ && value.decisions[0].signature === undefined && signedRowDecisionsMatch(record, value.decisions);}if (intent.verb === 'hold') return value === args.lane && options?.asPerson === true && options.channel === 'view'&& (args.off || options.reason === (args.reason ?? ''));@@ -171,24 +170,8 @@ function fulfilsIntent(record, move, board) {&& row.decision === (intent.verb === 'spec-approve' ? 'approve' : 'decline')&& (intent.verb !== 'spec-decline' || row.reason === args.reason.trim())&& (args.text === undefined ? !requiresShown || row.text === shown.find(entry => entry.id === ids[index])?.text : row.text === args.text.trim())- && (!requiresShown || row.by === 'person' && row.signature === undefined && boundSignedRow(record, row, ids[index], row.text)));-}--/** A signed decision cannot substitute the source text, named SSH identity or unrelated row fields. */-function boundSignedRow(request, row, id, text) {- let shown;- let original;- try {- shown = JSON.parse(request.encoded).rows?.find(entry => entry.id === id);- original = parseSpec(`## Decision\n${row.source}\n`).rows[0];- } catch { return false; }- return Boolean(shown && original && original.id === row.id && original.text === shown.text && !original.signers?.length- && row.passkeyRequest === request.id && row.replacement === rowDecisionReplacement(row.source, row.decision, text));-}--/** Recheck the entire committed row-result effect against its original signed request, independently of mutable flags. */-export function requestRowDecisionsMatch(board, request, rows) {- return Array.isArray(rows) && fulfilsIntent(request, { operation: 'recordRowDecisions', args: [{ agentId: 'person', channel: 'view', decisions: rows }] }, board);+ && (!requiresShown || row.by === 'person' && row.signature === undefined))+ && (!requiresShown || signedRowDecisionsMatch(record, rows));}/** The item ids a request's `implies` text names, parsed as `--implies` is, or null when it names none validly. */diff --git a/src/relay-sender.js b/src/relay-sender.jsindex 0e628764..7a502e1a 100644--- a/src/relay-sender.js+++ b/src/relay-sender.js@@ -33,16 +33,8 @@ export function validRelaySender(sender) {(sender.presence === undefined || sender.kind === 'person' && validPresence(sender.presence)));}-/**- * The relay's passkey stamp on a person request: the board, the request id and intent digest it was granted for,- * the passkey, when, and the relay's signature over them [E22].- */-export function validPresence(value) {- return Boolean(value && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).sort().join() === 'at,board,credential,digest,request,signature' &&- typeof value.request === 'string' && /^[A-Za-z0-9_-]{1,80}$/u.test(value.request) && typeof value.credential === 'string' &&- /^[A-Za-z0-9_-]{1,1400}$/u.test(value.credential) && Number.isSafeInteger(value.at) && value.at > 0 &&- /^[0-9a-f]{32}$/u.test(value.board ?? '') && /^[0-9a-f]{64}$/u.test(value.digest ?? '') && /^[A-Za-z0-9_-]{86}$/u.test(value.signature ?? ''));-}+export { validPresence } from './person-presence.js';+import { validPresence } from './person-presence.js';/*** True for a move only the person may make: a row decision, a sentinel decision, an answer or hold as the person, adiff --git a/test/person-optional-apply-fixture.js b/test/person-optional-apply-fixture.jsindex aa1913d3..a2060847 100644--- a/test/person-optional-apply-fixture.js+++ b/test/person-optional-apply-fixture.js@@ -43,7 +43,7 @@ function sshPublicLine(publicKey) {}/** Exercise actual engine receipt validation and native apply on an owned project, with a separately pinned fixture relay key. */-export async function optionalPasskeyApply(t) {+export async function optionalPasskeyApply(t, { throughCli = false } = {}) {const box = await relayClientFixture(t);const specFile = join(box.root, 'SPEC.md');const text = 'An optional SSH row approved by its exact passkey request.';@@ -86,6 +86,19 @@ export async function optionalPasskeyApply(t) {decisions.forEach(record => { record.passkeyRequest = document.id; });assert.equal(decisions[0].signature, undefined, 'optional passkey approval does not invoke SSH signing');execute('recordRowDecisions', [{ agentId: 'person', channel: 'view', decisions }], 'execute');+ if (throughCli) {+ const applied = await box.cli('spec', 'apply');+ assert.equal(applied.code, 0, JSON.stringify(applied.document));+ assert.match(readFileSync(specFile, 'utf8'), /- G21 \[approved, must\] An optional SSH row approved by its exact passkey request\./u);+ const status = await box.cli('status');+ assert.equal(status.code, 0, JSON.stringify(status.document));+ assert.equal(status.document.specApprovalBaseline?.pending, false, 'the approval projection must not skip behind an uncaptured baseline');+ assert.equal(status.document.needs.some(need => need.kind === 'agent-approved' && need.id === 'G21'), false,+ 'the actual status projection recognizes the applied passkey approval');+ assert.equal((status.document.specApprovalEvidenceErrors ?? []).some(error => error.id === 'G21'), false,+ 'the optional SSH approval carries valid provenance through the real CLI');+ return;+ }const plan = planRowApply(box.root, loadConfig(box.root), store.rowDecisions(board), {passkeyDecision: record => signing.verifiedPasskeyRowDecision(board, record),});@@ -93,3 +106,6 @@ export async function optionalPasskeyApply(t) {assert.match(plan.files[0].after, /- G21 \[approved, must\] An optional SSH row approved by its exact passkey request\./u);assert.equal(readFileSync(specFile, 'utf8').includes('G21 [draft'), true, 'planning does not write before the caller commits its ordered apply');}++/** Reuse real engine intake and exercise the ordinary native command and approval projection. */+export function optionalPasskeyApplyThroughCli(t) { return optionalPasskeyApply(t, { throughCli: true }); }diff --git a/test/team.test.js b/test/team.test.jsindex 449d2462..66122656 100644--- a/test/team.test.js+++ b/test/team.test.js@@ -54,7 +54,10 @@ import {grantChallenge,softwarePasskey,} from './person-passkey-fixture.js';-import { optionalPasskeyApply } from './person-optional-apply-fixture.js';+import {+ optionalPasskeyApply,+ optionalPasskeyApplyThroughCli,+} from './person-optional-apply-fixture.js';import { firstUnpairedAuthorityInsertion } from './person-first-pin-fixture.js';import { refuseNamedSigners } from '../src/person-signing-cli.js';import { createE2eHelpers } from './e2e-helpers.js';@@ -135,7 +138,10 @@ async function holdForReviewQueue(box) {const source = `import {setTimeout as pause} from 'node:timers/promises';import {writeFileSync} from 'node:fs';-import {takeResource,listResources} from ${JSON.stringify(new URL('../src/resources.js', import.meta.url).href)};+import {+ takeResource,+ listResources,+} from ${JSON.stringify(new URL('../src/resources.js', import.meta.url).href)};import {loadMachineSettings} from ${JSON.stringify(new URL('../src/settings.js', import.meta.url).href)};const [root,ready,observed]=process.argv.slice(1);const capacity=loadMachineSettings().gateSlots;@@ -1190,6 +1196,9 @@ test('person-only moves are signed [E22,B26,H16]', { timeout: relayWorkBudgetMs(const namedSignoff = await cli(cleared, 'spec', 'signoff', 'G6');assert.equal(namedSignoff.document.error?.code, 'PERSON_SIGNER_REQUIRED');assert.match(namedSignoff.document.error.message, /G6 names its SSH signers alice@example\.com/u);+ const signerChange = await cli(cleared, 'spec', 'signers', 'add', '--by', '[email protected]', '--key', 'unread-key');+ assert.equal(signerChange.document.error?.code, 'PERSON_SIGNER_REQUIRED');+ assert.match(signerChange.document.error.message, /alice@example\.com/u);const waiver = await confirmTerminal(['land', '--waive', 'gate:lint', '--until', '2099-01-01', '--reason', 'An explicit bounded fixture exception'], 'land-waive');assert.equal(waiver.waiver.test, 'gate:lint');@@ -1210,3 +1219,6 @@ test('person-only moves are signed before the first authority pin [E22,B26,H16]'/** Optional SSH policy must accept a genuinely bound passkey row decision without using an SSH key. */test('person-only moves are signed through optional SSH apply [E22,H16]', optionalPasskeyApply);++/** The actual CLI applies and projects the recorded passkey approval even with optional SSH enabled. */+test('person-only moves are signed through native CLI apply [E22,H16]', optionalPasskeyApplyThroughCli);