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
feat(machine): help and docs/lifecycle.md are generated [M1,P4]
Corey Olson34d85c2fd9f0
diff --git a/docs/lifecycle.md b/docs/lifecycle.mdnew file mode 100644index 00000000..fc90b8fe--- /dev/null+++ b/docs/lifecycle.md@@ -0,0 +1,102 @@+# The item lifecycle++Generated from src/machine.js by `pullboard lifecycle`. Do not edit it by hand: change the declaration, then run `pullboard lifecycle > docs/lifecycle.md`.++An item starts open. Its final states, verified and withdrawn, cannot be left, and every way into them passes the same exit guards, whatever command gets there. The board file itself refuses any move not declared here.++```mermaid+stateDiagram-v2+ [*] --> open+ open --> claimed: claim+ claimed --> claimed: claim+ claimed --> open: release+ claimed --> open: lapse (clock)+ claimed --> submitted: submit+ submitted --> verified: accept+ submitted --> open: reject+ open --> open: escalate+ claimed --> open: escalate+ open --> open: refreeze+ claimed --> open: refreeze+ submitted --> open: refreeze+ open --> withdrawn: withdraw+ claimed --> withdrawn: withdraw+ submitted --> withdrawn: withdraw+ verified --> [*]+ withdrawn --> [*]+```++## States++| State | Means | Fields it needs |+| --- | --- | --- |+| open | waiting for a builder; claimable once what it waits on is verified | none |+| claimed | an agent holds it under a lease, its criterion frozen | item_owner, item_lease_until, item_frozen_digest |+| submitted | built and gated green at a pinned commit, waiting for another agent | item_built_by, item_commit, item_frozen_digest |+| verified (final) | another agent accepted it at the submitted commit | item_verified_by, item_commit |+| withdrawn (final) | nobody should build it; the reason stays on it | item_withdrawn_reason |++## Moves++Each move checks its guards in this order and refuses with the first one that does not hold.++| Move | From | To | Who | Guards, in order |+| --- | --- | --- | --- | --- |+| claim | open, claimed | claimed | agent, coordinator | joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_CLAIMABLE), inLane (WRONG_LANE), routeAllows (ROUTE), dependenciesVerified (BLOCKED), notHeldByAnother (HELD), laneOpen (LANE_HELD), oneLiveClaim (ONE_CLAIM), rowsInForce (UNKNOWN_SPEC) |+| release | claimed | open | agent, coordinator | joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_YOURS), isHolder (NOT_YOURS) |+| lapse | claimed | open | clock, when its lease runs out | none |+| submit | claimed | submitted | agent, coordinator | joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_YOURS), isHolder (NOT_YOURS), criterionUnchanged (CRITERIA_CHANGED), treeClean (DIRTY), nothingUntracked (UNTRACKED), hasCommit (NO_COMMIT), gateConfigured (NO_GATE), gateGreen (GATE_RED), childrenDone (CHILDREN_OPEN), headIsNew (HEAD_NOT_NEW) |+| accept | submitted | verified | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_SUBMITTED), atSubmittedCommit (NOT_AT_COMMIT), notBuilder (SELF_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), criterionUnchanged (CRITERIA_CHANGED), reasonIsMet (BAD_REASON), proofNoted (PROOF_REQUIRED) |+| reject | submitted | open | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_SUBMITTED), atSubmittedCommit (NOT_AT_COMMIT), notBuilder (SELF_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), criterionUnchanged (CRITERIA_CHANGED), reasonCoded (BAD_REASON), noteGiven (NOTE_REQUIRED) |+| escalate | open, claimed | open | agent, coordinator | joined (NOT_JOINED), noteGiven (NOTE_REQUIRED), itemExists (NO_ITEM), holderOrCoordinator (NOT_YOURS), inState (CLOSED) |+| refreeze | open, claimed, submitted | open | coordinator | joined (NOT_JOINED), coordinatorOnly (COORDINATOR_ONLY), itemExists (NO_ITEM), inState (CLOSED), rowsInForce (UNKNOWN_SPEC) |+| withdraw | open, claimed, submitted | withdrawn | coordinator | joined (NOT_JOINED), coordinatorOnly (COORDINATOR_ONLY), noteGiven (NOTE_REQUIRED), itemExists (NO_ITEM), inState (CLOSED) |++## Exit guards++| Final state | Every move into it passes |+| --- | --- |+| verified | atSubmittedCommit, notBuilder, criterionUnchanged, proofNoted |+| withdrawn | coordinatorOnly, noteGiven |++## Refusals++| Code | Raised when this does not hold | Next step |+| --- | --- | --- |+| NOT_CLAIMABLE | claim: the item is in open, claimed | pullboard show <id> |+| NOT_YOURS | release: the item is in claimed | pullboard show <id> |+| NOT_YOURS | submit: the item is in claimed | pullboard show <id> |+| NOT_SUBMITTED | accept: the item is in submitted | pullboard show <id> |+| NOT_SUBMITTED | reject: the item is in submitted | pullboard show <id> |+| CLOSED | escalate: the item is in open, claimed | pullboard show <id> |+| CLOSED | refreeze: the item is in open, claimed, submitted | pullboard show <id> |+| CLOSED | withdraw: the item is in open, claimed, submitted | pullboard show <id> |+| NOT_JOINED | the caller is the main checkout, or a worktree that joined a lane | pullboard join <lane> (see: pullboard lanes) |+| NO_ITEM | the item exists | pullboard list --all |+| COORDINATOR_ONLY | the caller is the coordinator | run it from the main checkout |+| MAIN_IS_COORDINATOR | in the main checkout, the caller says it is the coordinator | verify from your own worktree; the coordinator adds --as coordinator |+| NOT_YOURS | the caller holds the item, or is the coordinator | shout its holder, or the coordinator |+| NOT_YOURS | the caller holds the claim | pullboard claim <id> |+| WRONG_LANE | the item is in the caller's lane; the main checkout builds coordinator-lane items only | cd <the lane's worktree> && pullboard claim <id> |+| ROUTE | the caller's route covers the item's: light, then mid, then strong | pullboard next, which offers only items your route covers |+| BLOCKED | every item it waits on is verified | claim another item, or shout the lane it waits on |+| HELD | no other agent holds it under a live lease | pullboard next |+| LANE_HELD | nobody holds its lane | pullboard next --wait 9 (minutes) |+| ONE_CLAIM | the caller holds no other live top-level claim, reworks of its own rejected items aside | submit or release the other item first; child items are free |+| UNKNOWN_SPEC | every row the item cites exists and is in force | fix the spec, or the coordinator withdraws the item |+| CRITERIA_CHANGED | the criterion and the rows it cites read as they did at claim | the coordinator runs pullboard refreeze <id> |+| DIRTY | the worktree has no uncommitted changes | commit your changes, then submit |+| UNTRACKED | the worktree has no untracked files | commit or ignore them, then submit |+| NO_COMMIT | there is a commit to submit | commit your work, then submit |+| NO_GATE | the repo names a gate command | set "gate" in pullboard.json, e.g. "npm test" |+| GATE_RED | the gate is green at HEAD | fix what the digest names, commit, submit again |+| CHILDREN_OPEN | every child item is verified or withdrawn | finish the child items, or the coordinator withdraws them |+| HEAD_NOT_NEW | a verifier has not already rejected this commit | commit the rework, then submit |+| NOT_AT_COMMIT | the caller's checkout contains the submitted commit | git switch --detach <commit> |+| SELF_VERIFY | the caller did not build it | another agent verifies it: pullboard next --verify |+| COORDINATOR_VERIFIES | the repo's verify policy lets the caller verify this lane's work | the coordinator verifies it |+| BAD_REASON | an accept gives CRITERION_MET as its reason | a failed criterion is a reject: pullboard verify <id> reject --reason CODE |+| PROOF_REQUIRED | an accept notes how it was proved | --note "what you broke or which edge you tried, and what happened" |+| BAD_REASON | a reject names one of the reject reasons | --reason TEST_FAILURE, BEHAVIOR_MISMATCH, INSUFFICIENT_EVIDENCE, STALE_HEAD or OTHER |+| NOTE_REQUIRED | the move carries a note: what failed, what was tried, or why | --note "..." or --note-file <file> |+| BAD_DECISION | a verdict is accept or reject | pullboard verify <id> accept, or reject --reason CODE --note "..." |diff --git a/src/cli.js b/src/cli.jsindex ef531621..820091d6 100644--- a/src/cli.js+++ b/src/cli.js@@ -20,6 +20,7 @@ import {prePushProblems,} from './hooks.js';import { initRepo } from './init.js';+import { lifecycleHelp, lifecycleMarkdown } from './machine.js';import { productLine, productProblems, productSummaries } from './products.js';import { isLane, laneNames, laneOf, outOfLane } from './lanes.js';import { Refused } from './refused.js';@@ -115,6 +116,8 @@ Gate and hookspullboard gate run the configured gatepullboard hook pre-commit|commit-msg|pre-push git runs these+${lifecycleHelp()}+Reject reasons: TEST_FAILURE, BEHAVIOR_MISMATCH, INSUFFICIENT_EVIDENCE, STALE_HEAD, OTHER.--json prints list, show and status as JSON.`;@@ -1275,6 +1278,10 @@ export async function main(argv, streams) {const args = { first, second, rest, values };try {if (command === 'tour') return tour(io);+ if (command === 'lifecycle') {+ io.say(lifecycleMarkdown().trimEnd());+ return 0;+ }if (command === 'view') return await viewHere(io, values);if (command === 'spec') return specCommand(io, args);if (command === 'prompt') {diff --git a/src/machine.js b/src/machine.jsindex 69e50a72..0228ad72 100644--- a/src/machine.js+++ b/src/machine.js@@ -437,3 +437,97 @@ export function storeTriggers(machine = MACHINE) {}return triggers;}++/**+ * A guard as the lifecycle page shows it: its id, with the code it raises, or the move's own code+ * for the state check.+ *+ * @param {Machine} machine+ * @param {Move} move+ * @param {string} id+ * @returns {string}+ */+function guardLabel(machine, move, id) {+ const code = id === IN_STATE ? move.refuse : machine.guards.find((guard) => guard.id === id)?.refuse;+ return code ? `${id} (${code})` : id;+}++/**+ * The lifecycle as a markdown page: a Mermaid state diagram, every move with its guards in the+ * order they are checked (exit guards included), each final state's exit guards, and every refusal+ * with the rule behind it and the next step (M1, P4). docs/lifecycle.md is this page, written by+ * `pullboard lifecycle`, and a test fails when the two differ, so the page cannot drift from the code.+ *+ * @param {Machine} [machine]+ * @returns {string}+ */+export function lifecycleMarkdown(machine = MACHINE) {+ const cell = (text) => String(text).replaceAll('|', '\\|');+ const finals = machine.states.filter((state) => state.final);+ const edges = machine.moves.flatMap((move) => move.from.map((from) => ` ${from} --> ${move.to}: ${move.verb}${move.by.includes('clock') ? ' (clock)' : ''}`));+ const moves = machine.moves.map((move) => {+ const who = move.when ? `${move.by.join(', ')}, when ${move.when}` : move.by.join(', ');+ const guards = effectiveGuards(move, machine).map((id) => guardLabel(machine, move, id)).join(', ') || 'none';+ return `| ${move.verb} | ${move.from.join(', ')} | ${move.to} | ${cell(who)} | ${cell(guards)} |`;+ });+ const wrongState = machine.moves.filter((move) => move.refuse).map((move) => `| ${move.refuse} | ${move.verb}: the item is in ${move.from.join(', ')} | pullboard show <id> |`);+ const refusals = machine.guards.filter((guard) => guard.id !== IN_STATE).map((guard) => `| ${guard.refuse} | ${cell(guard.rule)} | ${cell(guard.next)} |`);+ const unknown = `| ${machine.unknownMove.refuse} | ${cell(machine.unknownMove.rule)} | ${cell(machine.unknownMove.next)} |`;+ return [+ '# The item lifecycle',+ '',+ 'Generated from src/machine.js by `pullboard lifecycle`. Do not edit it by hand: change the declaration, then run `pullboard lifecycle > docs/lifecycle.md`.',+ '',+ `An item starts ${machine.initial}. Its final states, ${finals.map((state) => state.id).join(' and ')}, cannot be left, and every way into them passes the same exit guards, whatever command gets there. The board file itself refuses any move not declared here.`,+ '',+ '```mermaid',+ 'stateDiagram-v2',+ ` [*] --> ${machine.initial}`,+ ...[...new Set(edges)],+ ...finals.map((state) => ` ${state.id} --> [*]`),+ '```',+ '',+ '## States',+ '',+ '| State | Means | Fields it needs |',+ '| --- | --- | --- |',+ ...machine.states.map((state) => `| ${state.id}${state.final ? ' (final)' : ''} | ${cell(state.means)} | ${state.requires.join(', ') || 'none'} |`),+ '',+ '## Moves',+ '',+ 'Each move checks its guards in this order and refuses with the first one that does not hold.',+ '',+ '| Move | From | To | Who | Guards, in order |',+ '| --- | --- | --- | --- | --- |',+ ...moves,+ '',+ '## Exit guards',+ '',+ '| Final state | Every move into it passes |',+ '| --- | --- |',+ ...finals.map((state) => `| ${state.id} | ${(machine.exitGuards[state.id] ?? []).join(', ')} |`),+ '',+ '## Refusals',+ '',+ '| Code | Raised when this does not hold | Next step |',+ '| --- | --- | --- |',+ ...[...new Set([...wrongState, ...refusals, unknown])],+ '',+ ].join('\n');+}++/**+ * The help screen's lifecycle section: who may make which moves, read from the declaration.+ *+ * @param {Machine} [machine]+ * @returns {string}+ */+export function lifecycleHelp(machine = MACHINE) {+ const lines = machine.roles.map((role) => {+ const moves = machine.moves.filter((move) => move.by.includes(role));+ const when = moves.filter((move) => move.when).map((move) => `${move.verb} (when ${move.when})`);+ const plain = moves.filter((move) => !move.when).map((move) => move.verb);+ return ` ${role.padEnd(13)} ${[...plain, ...when].join(', ')}`;+ });+ return ['Lifecycle, read from src/machine.js', ' pullboard lifecycle the states, moves, guards and refusals as a markdown page, with a diagram', ...lines].join('\n');+}diff --git a/test/machine.test.js b/test/machine.test.jsindex c9da762a..c1745a97 100644--- a/test/machine.test.js+++ b/test/machine.test.js@@ -9,7 +9,9 @@ import { join } from 'node:path';import { DatabaseSync } from 'node:sqlite';import { test } from 'node:test';import * as store from '../src/board.js';-import { BLANKS, IN_STATE, MACHINE, effectiveGuards, machineProblems, storeTriggers } from '../src/machine.js';+import { HELP } from '../src/cli.js';+import { BLANKS, IN_STATE, MACHINE, effectiveGuards, lifecycleHelp, lifecycleMarkdown, machineProblems, storeTriggers } from '../src/machine.js';+import { spawnSync } from 'node:child_process';/*** Refusals that are not about an item's lifecycle, so no move declares them: how a command was@@ -692,3 +694,46 @@ test("a blank field in the board file is exactly what JavaScript's trim removesfor (let code = 0; code <= 0xffff; code += 1) if (String.fromCharCode(code).trim() === '') trimmed.push(code);assert.deepEqual(BLANKS, trimmed);});++const BIN = join(import.meta.dirname, '..', 'bin', 'pullboard.js');++test('docs/lifecycle.md is the page the declaration generates, so a stale copy fails [M1, P4]', () => {+ const page = lifecycleMarkdown();+ const committed = readFileSync(new URL('../docs/lifecycle.md', import.meta.url), 'utf8');+ assert.equal(committed, page, 'docs/lifecycle.md is stale; regenerate it: node bin/pullboard.js lifecycle > docs/lifecycle.md');+ assert.match(page, /```mermaid\nstateDiagram-v2\n {2}\[\*\] --> open\n/);+ for (const state of MACHINE.states) assert.match(page, new RegExp(`^\\| ${state.id}( \\(final\\))? \\|`, 'm'), `${state.id} has a row`);+ for (const move of MACHINE.moves) {+ assert.match(page, new RegExp(`^\\| ${move.verb} \\| ${move.from.join(', ')} \\| ${move.to} \\|`, 'm'), `${move.verb} has a row`);+ for (const from of move.from) assert.ok(page.includes(` ${from} --> ${move.to}: ${move.verb}`), `the diagram draws ${move.verb} from ${from}`);+ for (const id of effectiveGuards(move)) assert.ok(page.includes(id), `${move.verb}'s guard ${id} is listed`);+ }+ for (const [state, guards] of Object.entries(MACHINE.exitGuards)) assert.ok(page.includes(`| ${state} | ${guards.join(', ')} |`), `${state}'s exit guards are listed`);+ const codes = new Set([...MACHINE.guards.map((guard) => guard.refuse), ...MACHINE.moves.map((move) => move.refuse), MACHINE.unknownMove.refuse].filter(Boolean));+ for (const code of codes) assert.match(page, new RegExp(`^\\| ${code} \\|`, 'm'), `${code} is in the refusal table`);+});++test('the page and the help follow the declaration: a new move appears in both [M1, P4]', () => {+ const machine = copy();+ machine.moves.push({ verb: 'shelve', from: ['open'], to: 'withdrawn', by: ['coordinator'], refuse: 'CLOSED', guards: ['joined', 'coordinatorOnly', 'noteGiven', 'itemExists', IN_STATE], sets: ['item_withdrawn_reason'] });+ assert.ok(!lifecycleMarkdown().includes('shelve'));+ assert.ok(lifecycleMarkdown(machine).includes(' open --> withdrawn: shelve'));+ assert.match(lifecycleMarkdown(machine), /^\| shelve \| open \| withdrawn \| coordinator \|/m);+ assert.match(lifecycleHelp(machine), /^ {2}coordinator +.*\bshelve\b/m);+ assert.doesNotMatch(lifecycleHelp(machine), /^ {2}agent +.*\bshelve\b/m);+});++test('pullboard help lists each role\'s moves from the declaration, and pullboard lifecycle prints the page [M1, P4]', () => {+ const help = spawnSync(process.execPath, [BIN, 'help'], { encoding: 'utf8' });+ assert.equal(help.status, 0, help.stderr);+ for (const role of MACHINE.roles) {+ const line = help.stdout.split('\n').find((text) => text.startsWith(` ${role} `));+ assert.ok(line, `help has a line for ${role}`);+ const listed = line.slice(role.length + 2).split(',').map((part) => part.trim().split(' ')[0]).filter(Boolean);+ assert.deepEqual(listed.sort(), MACHINE.moves.filter((move) => move.by.includes(role)).map((move) => move.verb).sort(), `${role}'s moves`);+ }+ assert.ok(HELP.includes(lifecycleHelp()), 'the help screen carries the generated section, not a typed copy');+ const printed = spawnSync(process.execPath, [BIN, 'lifecycle'], { encoding: 'utf8' });+ assert.equal(printed.status, 0, printed.stderr);+ assert.equal(printed.stdout, lifecycleMarkdown());+});