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(cli): resume, file affinity and lane holds [N19,N20,N21,N22,I6]
Corey Olson068c858cd0ed
diff --git a/SPEC.md b/SPEC.mdindex 9adbdb5d..f4365c7a 100644--- a/SPEC.md+++ b/SPEC.md@@ -73,6 +73,7 @@ Statuses: approved = decided · draft = proposed · pending = open question · f- I3 [approved, must] Init writes the standard PRACTICE.md and the role guides as Claude Code skills. | gate: test/e2e.test.js- I4 [approved, must] `pullboard worktree <lane>` makes a joined worktree and says what to run next. | gate: test/e2e.test.js- I5 [approved, must] Every command pullboard suggests to an agent starts with cd to its worktree. | gate: test/e2e.test.js | serves: I4+- I6 [draft, must] Init adds a Claude Code SessionStart hook that runs `pullboard resume`, keeping every other setting. | gate: test/e2e.test.js | serves: N19## N · Next commands- N1 [draft, must] `pullboard decide`: the person's queue of everything waiting on them.@@ -93,6 +94,10 @@ Statuses: approved = decided · draft = proposed · pending = open question · f- N16 [approved, must] The runner takes a command per tier and merges an item's verified dependencies before building it. | gate: test/e2e.test.js | serves: N14- N17 [approved, must] Sweep runs each item's check once before filing; a check that passes on a flagged file is refused. | gate: test/e2e.test.js | serves: N15- N18 [retired] Model ladders and routing by history left the core for a separate project; the core keeps tiers and escalation.+- N19 [draft, must] `pullboard resume` prints one short card: the claim, the branch against main, what came back, unread shouts, the next step. | gate: test/e2e.test.js+- N20 [draft, must] Within a tier, `next` takes the item sharing most files with the agent's recent work, and names them. | gate: test/board.test.js, test/e2e.test.js | serves: N2+- N21 [draft, must] Submit records the files an item changed; show and the run pack name verified items that share them. | gate: test/board.test.js, test/e2e.test.js+- N22 [draft, must] `pullboard hold <lane>` pauses a lane: nothing new is claimed there, and next says who held it and why. | gate: test/board.test.js, test/e2e.test.js## H · Hosted- H1 [pending, aim] `pullboard sync` mirrors the local board to pullboard.dev for teams across machines.diff --git a/src/board.js b/src/board.jsindex 81bc5a55..4ba5afb1 100644--- a/src/board.js+++ b/src/board.js@@ -109,6 +109,12 @@ const SCHEMA = `item_id INTEGER,event_detail TEXT NOT NULL DEFAULT '{}');+ CREATE TABLE IF NOT EXISTS hold (+ hold_lane TEXT PRIMARY KEY,+ hold_reason TEXT NOT NULL,+ hold_by TEXT NOT NULL,+ hold_at TEXT NOT NULL+ );`;/**@@ -144,6 +150,8 @@ function migrate(db) {['item', 'item_route', "TEXT NOT NULL DEFAULT 'strong'"],['item', 'item_check', "TEXT NOT NULL DEFAULT ''"],['agent', 'agent_route', "TEXT NOT NULL DEFAULT 'strong'"],+ ['item', 'item_claim_head', 'TEXT'],+ ['item', 'item_files', "TEXT NOT NULL DEFAULT ''"],];for (const [table, column, type] of added) {const columns = db.prepare(`PRAGMA table_info(${table})`).all().map((entry) => entry.name);@@ -524,14 +532,15 @@ export function recordAttempt(board, id, { agentId, n, seconds, result }) {* sub-agents share a lane. A lapsed claim can be taken. Every item is built in its own lane, the* coordinator's included, so no agent can build another lane's work from the main checkout. The* first claim freezes the criterion: `freeze` returns the text and digest the verdict will later be- * held to.+ * held to. A fresh claim also records `head`, the commit the work starts from, so submit can name+ * the files the item changed (N21). A held lane takes no new claims (N22); renewals go on.** @param {any} board* @param {number} id- * @param {{ agentId: string, lane: string, leaseMs: number, freeze: (item: any) => { text: string, digest: string } }} who+ * @param {{ agentId: string, lane: string, leaseMs: number, freeze: (item: any) => { text: string, digest: string }, head?: string | null }} who* @returns {{ leaseUntil: string, digest: string, renewed: boolean }}*/-export function claim(board, id, { agentId, lane, leaseMs, freeze }) {+export function claim(board, id, { agentId, lane, leaseMs, freeze, head = null }) {return atomic(board, () => {const item = itemById(board, id);if (['submitted', 'verified', 'withdrawn'].includes(item.item_status)) {@@ -562,6 +571,10 @@ export function claim(board, id, { agentId, lane, leaseMs, freeze }) {if (isHeld(board, item) && !isMine) {throw new Refused('HELD', `item #${id} is held by ${item.item_owner} until ${item.item_lease_until}`);}+ const paused = laneHold(board, item.item_lane);+ if (paused && !(isMine && isHeld(board, item))) {+ throw new Refused('LANE_HELD', `${paused.hold_by} holds the ${item.item_lane} lane: ${paused.hold_reason}. Wait for it: pullboard next --wait 30`);+ }if (item.item_parent_id === null) {const other = board.db.prepare(@@ -584,13 +597,14 @@ export function claim(board, id, { agentId, lane, leaseMs, freeze }) {Object.assign(fields, { item_frozen: frozen.text, item_frozen_digest: frozen.digest });}const leaseUntil = new Date(board.clock.now().getTime() + leaseMs).toISOString();+ const renewed = isMine && isHeld(board, item);+ if (!renewed && head) fields.item_claim_head = head;setItem(board, id, {...fields,item_status: 'claimed',item_owner: agentId,item_lease_until: leaseUntil,});- const renewed = isMine && isHeld(board, item);logEvent(board, agentId, renewed ? 'renew' : 'claim', id, { leaseUntil, digest });return { leaseUntil, digest, renewed };});@@ -623,9 +637,10 @@ export function release(board, id, agentId) {** @param {any} board* @param {number} id- * @param {{ agentId: string, commit: string, tree: string }} at+ * @param {{ agentId: string, commit: string, tree: string, files?: string[] }} at - `files`: what the+ * item's own commits changed since its claim; a rework adds to what the first attempt changed.*/-export function submit(board, id, { agentId, commit, tree }) {+export function submit(board, id, { agentId, commit, tree, files = [] }) {atomic(board, () => {const item = itemById(board, id);if (item.item_status !== 'claimed' || item.item_owner !== agentId) {@@ -649,6 +664,7 @@ export function submit(board, id, { agentId, commit, tree }) {item_commit: commit,item_tree: tree,item_lease_until: null,+ item_files: [...new Set([...(item.item_files ?? '').split('\n').filter(Boolean), ...files])].join('\n'),});logEvent(board, agentId, 'submit', id, { commit, tree });});@@ -957,13 +973,15 @@ export function events(board, { itemId } = {}) {* is waiting on.** With `runnable`, only items that carry a check command, which an unattended runner needs; with- * `routes`, only items on those routes, the ones a runner has an agent command for.+ * `routes`, only items on those routes, the ones a runner has an agent command for. With `warm`, the+ * files the agent worked in lately, an item that shares more of them comes first within its tier,+ * and `shared` names them (N20). A held lane offers nothing new (N22).** @param {any} board- * @param {{ agentId: string, lane: string, verify?: boolean, runnable?: boolean, routes?: string[] }} who- * @returns {{ item: any | null, reasons: string[] }}+ * @param {{ agentId: string, lane: string, verify?: boolean, runnable?: boolean, routes?: string[], warm?: string[] }} who+ * @returns {{ item: any | null, reasons: string[], shared?: string[] }}*/-export function nextFor(board, { agentId, lane, verify = false, runnable = false, routes = ROUTES }) {+export function nextFor(board, { agentId, lane, verify = false, runnable = false, routes = ROUTES, warm = [] }) {const route = routeOf(board, agentId);const tier = (entry) => ROUTES.indexOf(entry.item_route);const items = listItems(board)@@ -978,13 +996,19 @@ export function nextFor(board, { agentId, lane, verify = false, runnable = false}const held = items.find((entry) => entry.item_status === 'claimed' && entry.item_owner === agentId && entry.item_parent_id === null);if (held) return { item: held, reasons: [] };- const mine = items.filter((entry) => entry.item_status === 'open' && entry.item_lane === lane);+ const paused = laneHold(board, lane);+ if (paused) return { item: null, reasons: [`${paused.hold_by} holds the ${lane} lane: ${paused.hold_reason}`] };+ const recent = new Set(warm);+ const mine = items+ .filter((entry) => entry.item_status === 'open' && entry.item_lane === lane)+ .map((entry, order) => ({ entry, order, shared: itemFiles(entry).filter((path) => recent.has(path)) }))+ .sort((first, second) => tier(second.entry) - tier(first.entry) || second.shared.length - first.shared.length || first.order - second.order);const reasons = [];- for (const entry of mine) {+ for (const { entry, shared } of mine) {const waiting = (entry.item_after ? entry.item_after.split(',').map(Number) : []).map((id) => current(board, itemById(board, id))).filter((before) => before.item_status !== 'verified');- if (!waiting.length) return { item: entry, reasons: [] };+ if (!waiting.length) return { item: entry, reasons: [], shared };reasons.push(`#${entry.item_id} waits on ${waiting.map(waitingOn).join(', ')}`);}if (!mine.length) reasons.push(idleReason(items, lane, routed));@@ -1020,6 +1044,116 @@ function idleReason(items, lane, routed) {return `${reason}; ${awaiting.join(', ')} still await${awaiting.length === 1 ? 's' : ''} a verdict, and a rejected item comes back to this lane. A lane is done when its items are verified`;}+/**+ * The files an item touches, as far as the board knows: the files its submission changed, else the+ * files its brief names.+ *+ * @param {any} item+ * @returns {string[]}+ */+export function itemFiles(item) {+ const changed = (item.item_files ?? '').split('\n').filter(Boolean);+ return [...new Set([...changed, ...briefFiles(item.item_brief ?? '')])];+}++/**+ * Finished items that touched the same files as this one, most shared first (N21). A builder+ * starting cold reads how its neighbours were done instead of rediscovering it. File overlap, not+ * word similarity: in one real build, an item shared a source file with one of the three before it+ * in its lane 56% of the time.+ *+ * @param {any} board+ * @param {any} item+ * @param {number} [limit]+ * @returns {{ item: any, shared: string[] }[]}+ */+export function relatedItems(board, item, limit = 3) {+ const mine = new Set(itemFiles(item));+ if (!mine.size) return [];+ return listItems(board, { all: true })+ .filter((other) => other.item_id !== item.item_id && other.item_status === 'verified')+ .map((other) => ({ item: other, shared: itemFiles(other).filter((path) => mine.has(path)) }))+ .filter((entry) => entry.shared.length)+ .sort((first, second) => second.shared.length - first.shared.length || second.item.item_id - first.item.item_id)+ .slice(0, limit);+}++/**+ * Hold a lane (N22): `next` there claims nothing and names the reason, so a pause lives on the board+ * and not in a message. Work already claimed goes on. Only the coordinator holds and releases.+ *+ * @param {any} board+ * @param {string} lane+ * @param {{ agentId: string, reason: string }} hold+ */+export function holdLane(board, lane, { agentId, reason }) {+ coordinatorOnly(agentId, 'holds a lane');+ if (!String(reason ?? '').trim()) throw new Refused('USAGE', `a hold needs a reason: pullboard hold ${lane} --reason "why"`);+ atomic(board, () => {+ board.db+ .prepare(+ `INSERT INTO hold (hold_lane, hold_reason, hold_by, hold_at) VALUES (?, ?, ?, ?)+ ON CONFLICT (hold_lane) DO UPDATE SET hold_reason = excluded.hold_reason, hold_by = excluded.hold_by, hold_at = excluded.hold_at`,+ )+ .run(lane, reason.trim(), agentId, now(board));+ logEvent(board, agentId, 'hold', null, { lane, reason: reason.trim() });+ });+}++/**+ * Release a held lane.+ *+ * @param {any} board+ * @param {string} lane+ * @param {{ agentId: string }} who+ */+export function releaseLane(board, lane, { agentId }) {+ coordinatorOnly(agentId, 'releases a lane');+ atomic(board, () => {+ const { changes } = board.db.prepare('DELETE FROM hold WHERE hold_lane = ?').run(lane);+ if (!changes) throw new Refused('NOT_HELD', `the ${lane} lane is not held`);+ logEvent(board, agentId, 'unhold', null, { lane });+ });+}++/**+ * The hold on a lane, or null.+ *+ * @param {any} board+ * @param {string} lane+ * @returns {any | null}+ */+export function laneHold(board, lane) {+ return board.db.prepare('SELECT * FROM hold WHERE hold_lane = ?').get(lane) ?? null;+}++/**+ * Every held lane.+ *+ * @param {any} board+ * @returns {any[]}+ */+export function laneHolds(board) {+ return board.db.prepare('SELECT * FROM hold ORDER BY hold_lane').all();+}++/**+ * The newest unread shouts, without marking them read: `resume` shows them, `inbox` reads them.+ *+ * @param {any} board+ * @param {string} agentId+ * @param {number} [limit]+ * @returns {any[]}+ */+export function peekShouts(board, agentId, limit = 2) {+ const agent = board.db.prepare('SELECT * FROM agent WHERE agent_id = ?').get(agentId);+ if (!agent) return [];+ return board.db+ .prepare(`SELECT * ${UNREAD_SQL} ORDER BY shout_id DESC LIMIT ?`)+ .all(agent.agent_last_shout_id, agentId, agent.agent_lane, agentId, limit)+ .reverse();+}+/*** Counts for the status line and the ledger's summary: items by status, verdicts by decision.*diff --git a/src/cli.js b/src/cli.jsindex fbc27039..1e93382e 100644--- a/src/cli.js+++ b/src/cli.js@@ -52,6 +52,8 @@ Set uppullboard join <lane> [--route light] register the worktree you are in as an agent in a lane--route light: a lighter model that takes only items routed lightpullboard whoami | lanes | status who you are, the lanes, the board at a glance+ pullboard resume where you are: your claim, branch, uncommitted work, what came back,+ unread shouts, what to do next; run it to start any sessionpullboard hooks reinstall the git hooks (e.g. after a fresh clone)Work@@ -85,6 +87,8 @@ Coordinatorpullboard merged <id> <commit> record where verified work landedpullboard withdraw <id> <reason> drop an item nobody should buildpullboard refreeze <id> re-freeze a criterion after its spec rows changed+ pullboard hold <lane> --reason "..." pause a lane: next there claims nothing and names the reason+ pullboard hold <lane> --off release itReceiptspullboard ledger markdown: what was built, by whom, verified by whom@@ -110,6 +114,7 @@ const OPTIONS = {specs: { type: 'string' },parent: { type: 'string' },reason: { type: 'string' },+ off: { type: 'boolean' },note: { type: 'string' },by: { type: 'string' },out: { type: 'string' },@@ -311,6 +316,151 @@ function itemLine(item) {return `#${item.item_id} ${item.item_status}${holder}${verifier}${rejected} ${item.item_lane} ${item.item_title}${specs}${parent}${after}${light}`;}+/**+ * The files an agent has been working in (N20): what its latest three items touched, and what is+ * uncommitted in its worktree now.+ *+ * @param {any} ctx+ * @param {any} board+ * @param {{ id: string }} me+ * @returns {string[]}+ */+function warmFiles(ctx, board, me) {+ const recent = store+ .listItems(board, { all: true })+ .filter((item) => item.item_built_by === me.id)+ .sort((first, second) => second.item_updated_at.localeCompare(first.item_updated_at))+ .slice(0, 3)+ .flatMap((item) => store.itemFiles(item));+ return [...new Set([...recent, ...dirtyFiles(ctx.info.root)])];+}++/**+ * The paths with uncommitted changes in a worktree, untracked files included.+ *+ * @param {string} root+ * @returns {string[]}+ */+function dirtyFiles(root) {+ return tryGit(root, ['status', '--porcelain', '--untracked-files=all']).stdout.split('\n').filter(Boolean).map((line) => line.slice(3));+}++/**+ * The files an item's own commits changed since its claim (N21). First parents only, so main merged+ * into a lane branch is not counted as the item's work.+ *+ * @param {string} root+ * @param {string | null} from+ * @param {string} to+ * @returns {string[]}+ */+function filesSince(root, from, to) {+ if (!from) return [];+ const result = tryGit(root, ['log', '--first-parent', '--no-merges', '--format=', '--name-only', `${from}..${to}`]);+ return result.status === 0 ? [...new Set(result.stdout.split('\n').filter(Boolean))].sort() : [];+}++/**+ * How long ago an ISO time was, or how long until it, in the board's clock: 45m, 3h, 2d.+ *+ * @param {any} ctx+ * @param {string} iso+ * @returns {string}+ */+function span(ctx, iso) {+ const minutes = Math.round(Math.abs(ctx.clock.now().getTime() - Date.parse(iso)) / 60_000);+ if (minutes < 60) return `${minutes}m`;+ if (minutes < 48 * 60) return `${Math.round(minutes / 60)}h`;+ return `${Math.round(minutes / 1440)}d`;+}++/**+ * A shout's text cut to one short line.+ *+ * @param {string} text+ * @returns {string}+ */+const firstLine = (text) => {+ const line = String(text).split('\n')[0];+ return line.length > 100 ? `${line.slice(0, 99)}…` : line;+};++/**+ * `pullboard resume` (N19): one short card that puts an agent back to work after a fresh start,+ * a restart or a compaction, from the board rather than from a summary.+ *+ * @param {any} io+ * @returns {number}+ */+function resumeHere(io) {+ const ctx = context(io);+ const { root, isMain } = ctx.info;+ const card = withBoard(ctx, (board) => {+ const me = whoAmI(ctx, board);+ const all = store.listItems(board, { all: true });+ return {+ me,+ holding: all.filter((item) => item.item_status === 'claimed' && item.item_owner === me.id),+ sentBack: all+ .filter((item) => item.item_status === 'open' && item.item_verdict === 'REJECT' && item.item_built_by === me.id)+ .map((item) => ({ item, verdict: store.verdictsFor(board, item.item_id).at(-1) })),+ awaiting: all.filter((item) => item.item_status === 'submitted' && item.item_built_by === me.id),+ toVerify: all.filter((item) => item.item_status === 'submitted' && item.item_built_by !== me.id),+ toMerge: all.filter((item) => item.item_status === 'verified' && !item.item_merged_commit),+ open: all.filter((item) => item.item_status === 'open'),+ hold: store.laneHold(board, me.lane),+ holds: store.laneHolds(board),+ unread: store.unreadCount(board, me.id),+ newest: store.peekShouts(board, me.id, 1),+ };+ });+ const { me } = card;+ const say = (line) => io.say(line);+ const plural = (n, word) => `${n} ${word}${n === 1 ? '' : 's'}`;+ say(`resume: ${me.id}, ${me.lane} lane${isMain ? ', the main checkout' : ''}, at ${root}`);+ const dirty = dirtyFiles(root).length;+ if (!isMain) {+ const branch = tryGit(root, ['rev-parse', '--abbrev-ref', 'HEAD']).stdout || 'HEAD';+ // Against the main checkout's branch, not its HEAD, which is detached while the coordinator verifies.+ const mainRef = /^branch (.+)$/m.exec(tryGit(root, ['worktree', 'list', '--porcelain']).stdout.split('\n\n')[0])?.[1];+ const [behind = 0, ahead = 0] = mainRef ? tryGit(root, ['rev-list', '--left-right', '--count', `${mainRef}...HEAD`]).stdout.split(/\s+/).map(Number) : [];+ const against = mainRef ? `${ahead} ahead of main, ${behind} behind${behind ? ' (merge main before you submit)' : ''}` : 'main is detached for a verification, so ahead and behind are unknown';+ say(`branch ${branch}: ${against}${dirty ? `; ${plural(dirty, 'file')} uncommitted` : ''}`);+ } else if (dirty) {+ say(`${plural(dirty, 'file')} uncommitted in the main checkout`);+ }+ for (const item of card.holding) {+ say(`holding #${item.item_id} ${item.item_title}, lease ${span(ctx, item.item_lease_until)} left${item.item_check ? `; check: ${item.item_check}` : ''}`);+ const files = briefFiles(item.item_brief);+ if (files.length) say(` files: ${files.join(', ')}`);+ }+ for (const { item, verdict } of card.sentBack) {+ say(`sent back: #${item.item_id} ${verdict ? `${verdict.verdict_reason} by ${verdict.verdict_by}: ${firstLine(verdict.verdict_note)}` : 'rejected'}`);+ }+ if (card.awaiting.length) say(`awaiting a verdict: ${card.awaiting.map((item) => `#${item.item_id} (${span(ctx, item.item_updated_at)})`).join(', ')}`);+ if (isMain) {+ if (card.toVerify.length) say(`to verify: ${card.toVerify.map((item) => `#${item.item_id} ${item.item_lane} (${span(ctx, item.item_updated_at)})`).join(', ')}`);+ if (card.toMerge.length) say(`verified, not merged: ${card.toMerge.map((item) => `#${item.item_id} at ${item.item_commit.slice(0, 12)}`).join(', ')}; pullboard merged <id> <commit> records each`);+ for (const hold of card.holds) say(`held: the ${hold.hold_lane} lane, ${hold.hold_reason}`);+ const byLane = Object.entries(Map.groupBy(card.open, (item) => item.item_lane)).map(([lane, items]) => `${lane} ${items.length}`);+ say(`open: ${card.open.length}${byLane.length ? ` (${byLane.join(', ')})` : ''}`);+ } else if (card.hold) {+ say(`the ${me.lane} lane is held by ${card.hold.hold_by}: ${card.hold.hold_reason}`);+ }+ if (card.unread) say(`${plural(card.unread, 'unread shout')}; newest from ${card.newest[0].shout_from}: ${firstLine(card.newest[0].shout_text)} (pullboard inbox reads them)`);+ const mineOpen = card.open.filter((item) => item.item_lane === me.lane).length;+ let next;+ if (card.holding.length) next = `build #${card.holding[0].item_id}, commit, then pullboard submit ${card.holding[0].item_id}`;+ else if (card.sentBack.length) next = `pullboard claim ${card.sentBack[0].item.item_id}, fix what the verifier found, and submit again`;+ else if (isMain) next = card.toVerify.length ? 'pullboard next --verify --as coordinator' : 'curate the queue: pullboard add, edit, hold';+ else if (card.hold) next = 'wait for the hold to lift: pullboard next --wait 30';+ else if (mineOpen) next = `pullboard next (${mineOpen} open in your lane)`;+ else if (card.awaiting.length) next = 'pullboard next --wait 30; a rejected item comes back to your lane';+ else next = 'nothing open in your lane; pullboard next --verify names work you can check';+ say(`next: ${next}`);+ return 0;+}+/*** The commands that set a repo or a worktree up.*@@ -393,6 +543,7 @@ function worktreeFor(io, lane, route) {*/function readCommands(io, { first, values }) {return {+ resume: () => resumeHere(io),whoami: () => {const ctx = context(io);const me = withBoard(ctx, (board) => whoAmI(ctx, board));@@ -422,10 +573,11 @@ function readCommands(io, { first, values }) {show: () => {const ctx = context(io);const id = idArg(first);- const { item, verdicts, moves } = withBoard(ctx, (board) => ({+ const { item, verdicts, moves, related } = withBoard(ctx, (board) => ({item: store.getItem(board, id),verdicts: store.verdictsFor(board, id),moves: store.events(board, { itemId: id }).filter((event) => ['attempt', 'escalate'].includes(event.event_kind)),+ related: store.relatedItems(board, store.getItem(board, id)),}));if (values.json) {io.say(JSON.stringify({ ...item, verdicts }, null, 2));@@ -435,6 +587,9 @@ function readCommands(io, { first, values }) {if (item.item_criterion) io.say(`criterion: ${item.item_criterion}`);if (item.item_check) io.say(`check: ${item.item_check}`);sayBrief(io, item.item_brief);+ for (const { item: other, shared } of related) {+ io.say(`related: #${other.item_id} ${other.item_title}: ${shared.slice(0, 4).join(', ')}${shared.length > 4 ? ', ...' : ''} (git log -p -1 ${other.item_commit.slice(0, 12)} -- ${shared[0]})`);+ }const attempts = moves.filter((event) => event.event_kind === 'attempt').map((event) => JSON.parse(event.event_detail).result);if (attempts.length) io.say(`unattended attempts: ${attempts.join(', ')}`);for (const event of moves.filter((entry) => entry.event_kind === 'escalate')) {@@ -514,13 +669,13 @@ function readCommands(io, { first, values }) {*/function submitHere(ctx, id) {const { root } = ctx.info;- const me = withBoard(ctx, (board) => {+ const { me, claimHead } = withBoard(ctx, (board) => {const who = whoAmI(ctx, board);const item = store.getItem(board, id);if (item.item_status !== 'claimed' || item.item_owner !== who.id) {throw new Refused('NOT_YOURS', `item #${id} is not claimed by you; claim it first`);}- return who;+ return { me: who, claimHead: item.item_claim_head };});if (!isClean(root)) throw new Refused('DIRTY', 'commit your changes first; the gate must check what you submit');const stray = untracked(root);@@ -529,7 +684,7 @@ function submitHere(ctx, id) {if (!commit) throw new Refused('NO_COMMIT', 'nothing committed yet');const gate = runGate(root, ctx.config);if (!gate.isGreen) throw new Refused('GATE_RED', `the gate is red at ${commit.slice(0, 12)}; fix it, commit, submit again`);- withBoard(ctx, (board) => store.submit(board, id, { agentId: me.id, commit, tree: headTree(root) ?? '' }));+ withBoard(ctx, (board) => store.submit(board, id, { agentId: me.id, commit, tree: headTree(root) ?? '', files: filesSince(root, claimHead, commit) }));const pin = `refs/pullboard/items/${id}/${commit.slice(0, 12)}`;git(root, ['update-ref', pin, commit]);ctx.io.say(`submitted #${id} at ${commit.slice(0, 12)}; gate green${gate.isCached ? ' (this tree already passed)' : ''}`);@@ -595,17 +750,18 @@ function nextOnce(ctx, values) {return withBoard(ctx, (board) => {if (values.verify) checkMainVerifier(ctx, board, values);const me = whoAmI(ctx, board);- const { item, reasons } = store.nextFor(board, { agentId: me.id, lane: me.lane, verify: values.verify, runnable: values.runnable, routes: values.routes });+ const warm = values.verify ? [] : warmFiles(ctx, board, me);+ const { item, reasons, shared } = store.nextFor(board, { agentId: me.id, lane: me.lane, verify: values.verify, runnable: values.runnable, routes: values.routes, warm });if (!item) return { reasons };if (values.verify) return { item };if (item.item_status === 'claimed') return { item, held: true };try {- store.claim(board, item.item_id, { agentId: me.id, lane: me.lane, leaseMs: ctx.config.leaseMs, freeze: freezer(ctx) });+ store.claim(board, item.item_id, { agentId: me.id, lane: me.lane, leaseMs: ctx.config.leaseMs, freeze: freezer(ctx), head: headCommit(ctx.info.root) });} catch (error) {if (error instanceof Refused && ['HELD', 'BLOCKED', 'ONE_CLAIM'].includes(error.code)) return { retry: true };throw error;}- return { item: store.getItem(board, item.item_id) };+ return { item: store.getItem(board, item.item_id), shared };});}@@ -636,6 +792,7 @@ async function nextHere(io, values) {io.say(`then: ${here} pullboard verify ${item.item_id} accept${as} --note "how you proved it", or reject${as} --reason CODE --note "what failed"`);} else {io.say(`${found.held ? 'you hold' : 'claimed'} #${item.item_id}: ${item.item_title}`);+ if (found.shared?.length) io.say(`it touches ${found.shared.length === 1 ? 'a file' : `${found.shared.length} files`} you worked in recently: ${found.shared.slice(0, 4).join(', ')}`);if (item.item_criterion) io.say(`criterion: ${item.item_criterion}`);if (item.item_check) io.say(`check: ${item.item_check} (run it before you submit)`);for (const row of item.item_frozen ? JSON.parse(item.item_frozen).rows : []) io.say(` ${row.id}: ${row.text}`);@@ -773,10 +930,21 @@ function workCommands(io, args) {sweep: () => act((ctx, board, me) => sweepHere(ctx, board, me, values)),next: () => nextHere(io, values),claim: () => act((ctx, board, me) => {- const result = store.claim(board, idArg(first), { agentId: me.id, lane: me.lane, leaseMs: ctx.config.leaseMs, freeze: freezer(ctx) });+ const result = store.claim(board, idArg(first), { agentId: me.id, lane: me.lane, leaseMs: ctx.config.leaseMs, freeze: freezer(ctx), head: headCommit(ctx.info.root) });io.say(`${result.renewed ? 'renewed' : 'claimed'} #${first} until ${result.leaseUntil}; criterion frozen as ${result.digest.slice(0, 12)}`);return 0;}),+ hold: () => act((ctx, board, me) => {+ if (!first || !isLane(ctx.config, first)) throw new Refused('NO_LANE', `no lane "${first ?? ''}"; see: pullboard lanes`);+ if (values.off) {+ store.releaseLane(board, first, { agentId: me.id });+ io.say(`released the ${first} lane`);+ } else {+ store.holdLane(board, first, { agentId: me.id, reason: values.reason ?? '' });+ io.say(`holding the ${first} lane: ${values.reason}. Release it with: pullboard hold ${first} --off`);+ }+ return 0;+ }),release: () => act((ctx, board, me) => {store.release(board, idArg(first), me.id);io.say(`released #${first}`);diff --git a/src/init.js b/src/init.jsindex 7e4b6227..61845b21 100644--- a/src/init.js+++ b/src/init.js@@ -4,7 +4,7 @@* the main checkout as the coordinator. It runs again safely and never overwrites a file it did not* write.*/-import { appendFileSync, existsSync, readFileSync, writeFileSync } from 'node:fs';+import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';import { basename, join } from 'node:path';import { CONFIG_FILE, COORDINATOR } from './config.js';import { installHooks } from './hooks.js';@@ -106,6 +106,42 @@ function writeAgentDocs(root) {return notes;}+/**+ * The session hook's command: pullboard from the repo's own install when there is one, else from the+ * PATH, and silence when neither is there, so a session never fails to start over it.+ */+export const RESUME_HOOK =+ '[ -x node_modules/.bin/pullboard ] && exec node_modules/.bin/pullboard resume; command -v pullboard >/dev/null && exec pullboard resume; true';++/**+ * Have Claude Code run `pullboard resume` whenever a session starts, resumes or is compacted (I6), so+ * an agent picks its work up from the board rather than from a summary of it. The hook is merged+ * into .claude/settings.json; every other setting stays as it was.+ *+ * @param {string} root+ * @returns {string} What happened.+ */+function writeSessionHook(root) {+ const file = join(root, '.claude', 'settings.json');+ let settings = {};+ if (existsSync(file)) {+ try {+ settings = JSON.parse(readFileSync(file, 'utf8'));+ } catch {+ settings = null;+ }+ if (!settings || typeof settings !== 'object' || Array.isArray(settings)) {+ return 'kept .claude/settings.json, which is not a JSON object; add a SessionStart hook that runs pullboard resume';+ }+ }+ const starts = settings.hooks?.SessionStart ?? [];+ if (JSON.stringify(starts).includes('pullboard resume')) return 'kept the Claude Code session hook';+ settings.hooks = { ...settings.hooks, SessionStart: [...starts, { hooks: [{ type: 'command', command: RESUME_HOOK, timeout: 30 }] }] };+ mkdirSync(join(root, '.claude'), { recursive: true });+ writeFileSync(file, `${JSON.stringify(settings, null, 2)}\n`);+ return 'added a Claude Code session hook: pullboard resume at every start and compaction';+}+/*** Set the repo up. Must run in the main checkout, which becomes the coordinator.*@@ -125,6 +161,7 @@ export function initRepo({ info, openBoardHere, register, closeBoard }) {...writeAgentDocs(root),...installHooks(root),...installSkills(root),+ writeSessionHook(root),];const board = openBoardHere();try {diff --git a/src/run.js b/src/run.jsindex 5ca30b99..af612a30 100644--- a/src/run.js+++ b/src/run.js@@ -129,7 +129,7 @@ function restore(root, start, paths) {* @param {{ attempt: number, attempts: number, digest: string, earlier?: string[] }} state* @returns {string}*/-export function packText(root, item, { attempt, attempts, digest, earlier = [] }) {+export function packText(root, item, { attempt, attempts, digest, earlier = [], related = [] }) {const rows = item.item_frozen ? JSON.parse(item.item_frozen).rows : [];const files = briefFiles(item.item_brief);let budget = PACK_FILE_CHARS;@@ -165,6 +165,9 @@ export function packText(root, item, { attempt, attempts, digest, earlier = [] }...(digest? ['', '## Your previous attempt', 'It left the files as they are below. Continue from them. It failed with:', '```', digest, '```', 'Fix exactly that.']: []),+ ...(related.length+ ? ['', '## Finished items that touched the same files', ...related.map(({ item: other, shared }) => `- #${other.item_id} ${other.item_title}: ${shared.join(', ')}`), 'Follow the patterns they set where your change is similar.']+ : []),...(contents.length ? ['', '## The files, as they are now', ...contents] : []),'',].join('\n');@@ -278,12 +281,13 @@ async function tryItem(ctx, item, { command, attempts, minutes, deps, me, start,let digest = '';let seconds = 0;for (let attempt = 1; attempt <= attempts; attempt += 1) {- const fresh = deps.withBoard(ctx, (board) => {+ const { fresh, related } = deps.withBoard(ctx, (board) => {store.claim(board, id, { agentId: me.id, lane: me.lane, leaseMs: ctx.config.leaseMs, freeze: deps.freezer(ctx) });- return store.getItem(board, id);+ const claimed = store.getItem(board, id);+ return { fresh: claimed, related: store.relatedItems(board, claimed) };});const pack = join(packs, `${id}-${tag}-${attempt}.md`);- writeFileSync(pack, packText(root, fresh, { attempt, attempts, digest, earlier }));+ writeFileSync(pack, packText(root, fresh, { attempt, attempts, digest, earlier, related }));ctx.io.say(`#${id} attempt ${attempt}/${attempts}: running the ${item.item_route} agent`);const env = { ...process.env, PULLBOARD_PACK: pack, PULLBOARD_CHECK: item.item_check, PULLBOARD_ITEM: String(id), PULLBOARD_ATTEMPT: String(attempt), PULLBOARD_TIER: item.item_route };const built = await runCommand(command, { cwd: root, env, timeoutMs: minutes * 60_000, log: join(packs, `${id}-${tag}-${attempt}.log`) });diff --git a/src/templates.js b/src/templates.jsindex 649ddf8e..f9b29784 100644--- a/src/templates.js+++ b/src/templates.js@@ -127,7 +127,7 @@ This repo runs on pullboard: a work board, lanes and a spec that live in git. NoIt prints the folder to work in and what to run there first. A smaller model joins with \`--route light\` or \`--route mid\` and takes items at its tier and below. Work only in that folder. Your shell may start every command in the main checkout, where pullboard takes you for the coordinator, so begin each command with \`cd <your worktree> &&\`. Verifiers take the \`review\` lane, which owns no folders. Keep your worktree and branch until your items are merged.**The loop.**-1. \`pullboard inbox\`.+1. \`pullboard resume\` at the start of every session and after your context is compacted: your claim, what came back, unread shouts and the next step. Then \`pullboard inbox\`.2. \`pullboard next\` claims the next item in your lane that is free to start. When everything is waiting on other work, \`pullboard next --wait 30\` keeps looking for up to 30 minutes. A claim is a 2-hour lease; claim again to renew. The criterion freezes now: \`pullboard show <id>\` is the bar your work is judged against, and its brief says how to start.3. Build inside your lane's folders (\`pullboard lanes\`). Pre-commit refuses anything else; shout the owner instead.4. Commit, then \`pullboard submit <id>\`. It needs a clean tree and the gate green at HEAD.diff --git a/test/board.test.js b/test/board.test.jsindex 1a72c61d..724afcfe 100644--- a/test/board.test.js+++ b/test/board.test.js@@ -219,14 +219,16 @@ test('a board made by an older version is migrated on open', () => {try {const file = join(dir, 'board.sqlite');const old = store.openBoard(file, clock);- for (const column of ['item_after', 'item_brief', 'item_route', 'item_check']) old.db.exec(`ALTER TABLE item DROP COLUMN ${column}`);+ for (const column of ['item_after', 'item_brief', 'item_route', 'item_check', 'item_claim_head', 'item_files']) old.db.exec(`ALTER TABLE item DROP COLUMN ${column}`);old.db.exec('ALTER TABLE agent DROP COLUMN agent_route');+ old.db.exec('DROP TABLE hold');store.closeBoard(old);const reopened = store.openBoard(file, clock);const columns = (table) => reopened.db.prepare(`PRAGMA table_info(${table})`).all().map((column) => column.name);- const [items, agents] = [columns('item'), columns('agent')];+ const [items, agents, holds] = [columns('item'), columns('agent'), columns('hold')];store.closeBoard(reopened);- for (const column of ['item_after', 'item_brief', 'item_route', 'item_check']) assert.ok(items.includes(column), column);+ for (const column of ['item_after', 'item_brief', 'item_route', 'item_check', 'item_claim_head', 'item_files']) assert.ok(items.includes(column), column);+ assert.ok(holds.includes('hold_reason'));assert.ok(agents.includes('agent_route'));} finally {rmSync(dir, { recursive: true, force: true });@@ -339,3 +341,78 @@ test('escalate frees an item one tier up, with what was tried attached [B15]', (const moves = store.events(board, { itemId: id }).map((event) => event.event_kind).filter((kind) => ['attempt', 'escalate'].includes(kind));assert.deepEqual(moves, ['attempt', 'escalate', 'escalate', 'escalate']);});++test('a fresh claim records where the work started; submit records what it changed, reworks included [N21]', () => {+ const id = store.addItem(board, { by: 'coordinator', lane: 'web', title: 'Page' });+ const claimAt = (head) => store.claim(board, id, { agentId: 'web-1', lane: 'web', leaseMs: 2 * HOUR, freeze, head });+ claimAt(SHA_A);+ claimAt(SHA_B);+ assert.equal(store.getItem(board, id).item_claim_head, SHA_A, 'a renewal keeps the first head');+ store.submit(board, id, { agentId: 'web-1', commit: SHA_B, tree: 't', files: ['web/page.js', 'web/page.test.js'] });+ verdict(id, { agentId: 'web-2', decision: 'REJECT', reason: 'TEST_FAILURE', note: 'an empty page throws' });+ claimAt(SHA_B);+ assert.equal(store.getItem(board, id).item_claim_head, SHA_B, 'the rework starts from the rejected head');+ store.submit(board, id, { agentId: 'web-1', commit: 'c'.repeat(40), tree: 't2', files: ['web/page.js', 'web/empty.js'] });+ assert.deepEqual(store.itemFiles(store.getItem(board, id)), ['web/page.js', 'web/page.test.js', 'web/empty.js']);+});++test('related items: verified work that touched the same files, the most shared first [N21]', () => {+ const build = (title, files) => {+ const id = store.addItem(board, { by: 'coordinator', lane: 'web', title });+ claimAs(id, 'web-1', 'web');+ store.submit(board, id, { agentId: 'web-1', commit: SHA_A, tree: 't', files });+ return id;+ };+ const header = build('Header', ['web/layout.js', 'web/header.js']);+ const footer = build('Footer', ['web/layout.js']);+ const api = build('Route', ['api/route.js']);+ build('Pending', ['web/layout.js', 'web/header.js']);+ for (const [id, title] of [[header, 'Header'], [footer, 'Footer'], [api, 'Route']]) verdict(id, { agentId: 'web-2', decision: 'ACCEPT', digest: `digest:${title}` });+ const nav = store.addItem(board, { by: 'coordinator', lane: 'web', title: 'Nav', brief: 'Files: web/header.js, web/layout.js' });+ assert.deepEqual(+ store.relatedItems(board, store.getItem(board, nav)).map(({ item, shared }) => [item.item_id, shared]),+ [[header, ['web/layout.js', 'web/header.js']], [footer, ['web/layout.js']]],+ );+ const loose = store.addItem(board, { by: 'coordinator', lane: 'web', title: 'Copy' });+ assert.deepEqual(store.relatedItems(board, store.getItem(board, loose)), []);+});++test('within a tier, next takes the item nearest your recent work and names the shared files [N20]', () => {+ const footer = store.addItem(board, { by: 'coordinator', lane: 'web', title: 'Footer', brief: 'Files: web/footer.js' });+ const nav = store.addItem(board, { by: 'coordinator', lane: 'web', title: 'Nav', brief: 'Files: web/header.js, web/nav.js' });+ assert.equal(store.nextFor(board, { agentId: 'web-1', lane: 'web' }).item.item_id, footer, 'with nothing warm, the oldest');+ const warm = store.nextFor(board, { agentId: 'web-1', lane: 'web', warm: ['web/header.js', 'web/layout.js'] });+ assert.equal(warm.item.item_id, nav);+ assert.deepEqual(warm.shared, ['web/header.js']);+ const mid = routed('Rename', 'mid', { brief: BRIEF.replace('web/a.js', 'web/header.js') });+ const midAgent = store.register(board, { lane: 'web', path: '/repo-web-3', route: 'mid' });+ assert.equal(store.nextFor(board, { agentId: 'web-1', lane: 'web', warm: ['web/header.js'] }).item.item_id, nav, 'a strong agent takes strong work first');+ assert.equal(store.nextFor(board, { agentId: midAgent, lane: 'web', warm: ['web/footer.js'] }).item.item_id, mid, 'a mid agent never gets strong work');+});++test('a held lane takes no new claims and says who held it and why; claimed work goes on [N22]', () => {+ const page = store.addItem(board, { by: 'coordinator', lane: 'web', title: 'Page' });+ const nav = store.addItem(board, { by: 'coordinator', lane: 'web', title: 'Nav' });+ claimAs(page, 'web-1', 'web');+ assert.throws(() => store.holdLane(board, 'web', { agentId: 'web-1', reason: 'mine' }), /COORDINATOR_ONLY/);+ assert.throws(() => store.holdLane(board, 'web', { agentId: 'coordinator', reason: ' ' }), /USAGE/);+ store.holdLane(board, 'web', { agentId: 'coordinator', reason: 'the spec rows are changing' });+ assert.deepEqual(store.nextFor(board, { agentId: 'web-2', lane: 'web' }), { item: null, reasons: ['coordinator holds the web lane: the spec rows are changing'] });+ assert.throws(() => claimAs(nav, 'web-2', 'web'), /LANE_HELD.*the spec rows are changing/);+ assert.equal(store.nextFor(board, { agentId: 'web-1', lane: 'web' }).item.item_id, page, 'claimed work goes on');+ assert.equal(claimAs(page, 'web-1', 'web').renewed, true);+ assert.equal(store.nextFor(board, { agentId: 'api-1', lane: 'api' }).reasons[0], 'no open items in the api lane');+ store.releaseLane(board, 'web', { agentId: 'coordinator' });+ assert.equal(store.nextFor(board, { agentId: 'web-2', lane: 'web' }).item.item_id, nav);+ assert.throws(() => store.releaseLane(board, 'web', { agentId: 'coordinator' }), /NOT_HELD/);+ assert.deepEqual(store.events(board).map((event) => event.event_kind).filter((kind) => kind.endsWith('hold')), ['hold', 'unhold']);+});++test('peeking shows the newest unread shouts and leaves them unread [N19]', () => {+ const lanes = ['coordinator', 'web', 'api'];+ for (const text of ['one', 'two', 'three']) store.shout(board, { from: 'coordinator', to: 'web-1', text, lanes });+ assert.deepEqual(store.peekShouts(board, 'web-1').map((shout) => shout.shout_text), ['two', 'three']);+ assert.equal(store.unreadCount(board, 'web-1'), 3);+ store.inbox(board, 'web-1');+ assert.deepEqual(store.peekShouts(board, 'web-1'), []);+});diff --git a/test/e2e.test.js b/test/e2e.test.jsindex c8979f3a..360d0078 100644--- a/test/e2e.test.js+++ b/test/e2e.test.js@@ -516,3 +516,98 @@ test('pre-commit runs the fixers on fully staged files and restages them; partlyassert.match(failed.stderr, /fixer "false" failed \(1\); staged nothing from it/);assert.equal(committedText('docs/e.js'), 'const e = 1; \n');});++test('resume puts an agent back to work from the board: its claim, its branch, what came back, the next step [N19]', () => {+ const box = project();+ box.run(box.repo, 'add', 'web', 'Page', '--specs', 'G1', '--brief', 'Files: web/page.html');+ const fresh = box.run(box.web, 'resume');+ assert.equal(fresh.code, 0, fresh.err);+ assert.match(fresh.out, /^resume: web-1, web lane, at /);+ assert.match(fresh.out, /branch web\/one: 0 ahead of main, 0 behind/);+ assert.match(fresh.out, /next: pullboard next \(1 open in your lane\)/);+ box.run(box.web, 'next');+ mkdirSync(join(box.web, 'web'));+ writeFileSync(join(box.web, 'web', 'page.html'), '<h1>Hi</h1>');+ box.run(box.repo, 'shout', 'web-1', 'the heading text is in G1');+ const building = box.run(box.web, 'resume').out;+ assert.match(building, /1 file uncommitted/);+ assert.match(building, /holding #1 Page, lease \d+[mh] left/);+ assert.match(building, /files: web\/page\.html/);+ assert.match(building, /1 unread shout; newest from coordinator: the heading text is in G1/);+ assert.match(building, /next: build #1, commit, then pullboard submit 1/);+ box.git(box.web, 'add', '-A');+ box.git(box.web, 'commit', '-q', '-m', 'feat(web): page [G1]');+ assert.equal(box.run(box.web, 'submit', '1').code, 0);+ const coordinator = box.run(box.repo, 'resume').out;+ assert.match(coordinator, /^resume: coordinator, coordinator lane, the main checkout/);+ assert.match(coordinator, /to verify: #1 web \(\d+[mhd]\)/);+ assert.match(coordinator, /next: pullboard next --verify --as coordinator/);+ box.git(box.repo, 'switch', '-q', '--detach', 'web/one');+ box.run(box.repo, 'verify', '1', 'reject', '--reason', 'TEST_FAILURE', '--note', 'no test proves the heading\nthe rest is fine', '--as', 'coordinator');+ const back = box.run(box.web, 'resume').out;+ assert.match(back, /branch web\/one: main is detached for a verification/);+ box.git(box.repo, 'switch', '-q', 'main');+ assert.match(box.run(box.web, 'resume').out, /branch web\/one: 1 ahead of main, 0 behind/);+ assert.match(back, /sent back: #1 TEST_FAILURE by coordinator: no test proves the heading$/m);+ assert.match(back, /next: pullboard claim 1, fix what the verifier found, and submit again/);+});++test('next takes work near your recent files; submit records them; show names related verified work [N20, N21]', () => {+ const box = project();+ box.run(box.repo, 'add', 'web', 'Footer', '--specs', 'G1', '--brief', 'Files: web/footer.html');+ box.run(box.repo, 'add', 'web', 'Header', '--specs', 'G1', '--brief', 'Files: web/header.html');+ mkdirSync(join(box.web, 'web'));+ writeFileSync(join(box.web, 'web', 'header.html'), '<header>');+ const next = box.run(box.web, 'next');+ assert.match(next.out, /claimed #2: Header/);+ assert.match(next.out, /it touches a file you worked in recently: web\/header\.html/);+ box.git(box.web, 'add', '-A');+ box.git(box.web, 'commit', '-q', '-m', 'feat(web): header [G1]');+ commitFile(box, box.web, 'web/nav.html', '<nav>', 'feat(web): nav in the header [G1]');+ box.git(box.repo, 'commit', '-q', '--allow-empty', '-m', 'chore: main moves on');+ box.git(box.web, 'merge', '-q', '--no-edit', 'main');+ assert.equal(box.run(box.web, 'submit', '2').code, 0);+ assert.equal(JSON.parse(box.run(box.web, 'show', '2', '--json').out).item_files, 'web/header.html\nweb/nav.html', 'only the item\'s own commits, not the merge');+ box.git(box.repo, 'switch', '-q', '--detach', 'web/one');+ box.run(box.repo, 'verify', '2', 'accept', '--note', 'emptied the header; the page lost it', '--as', 'coordinator');+ box.git(box.repo, 'switch', '-q', 'main');+ box.run(box.repo, 'add', 'web', 'Menu', '--specs', 'G1', '--brief', 'Files: web/nav.html, web/menu.html');+ assert.match(box.run(box.repo, 'show', '3').out, /related: #2 Header: web\/nav\.html \(git log -p -1 [0-9a-f]{12} -- web\/nav\.html\)/);+});++test('hold pauses a lane: next names who held it and why; --off lets it go [N22]', () => {+ const box = project();+ box.run(box.repo, 'add', 'web', 'Page', '--specs', 'G1');+ assert.match(box.run(box.web, 'hold', 'web', '--reason', 'mine').err, /COORDINATOR_ONLY/);+ assert.match(box.run(box.repo, 'hold', 'nowhere', '--reason', 'x').err, /NO_LANE/);+ assert.match(box.run(box.repo, 'hold', 'web', '--reason', 'G1 is being rewritten').out, /holding the web lane: G1 is being rewritten/);+ const held = box.run(box.web, 'next');+ assert.equal(held.code, 1);+ assert.match(held.err, /coordinator holds the web lane: G1 is being rewritten/);+ assert.match(box.run(box.web, 'claim', '1').err, /LANE_HELD/);+ assert.match(box.run(box.web, 'resume').out, /the web lane is held by coordinator: G1 is being rewritten/);+ assert.match(box.run(box.repo, 'hold', 'web', '--off').out, /released the web lane/);+ assert.match(box.run(box.web, 'next').out, /claimed #1: Page/);+});++test('init adds a Claude Code session hook that runs resume, and keeps every other setting [I6]', () => {+ const box = sandbox();+ const repo = join(box.dir, 'repo');+ mkdirSync(join(repo, '.claude'), { recursive: true });+ box.git(repo, 'init', '-q', '-b', 'main');+ const mine = { permissions: { allow: ['Bash(npm test)'] }, hooks: { Stop: [{ hooks: [{ type: 'command', command: 'echo done' }] }] } };+ writeFileSync(join(repo, '.claude', 'settings.json'), JSON.stringify(mine));+ assert.match(box.run(repo, 'init').out, /added a Claude Code session hook/);+ assert.match(box.run(repo, 'init').out, /kept the Claude Code session hook/);+ const settings = JSON.parse(readFileSync(join(repo, '.claude', 'settings.json'), 'utf8'));+ assert.deepEqual(settings.permissions, mine.permissions);+ assert.deepEqual(settings.hooks.Stop, mine.hooks.Stop);+ assert.equal(settings.hooks.SessionStart.length, 1);+ const { command } = settings.hooks.SessionStart[0].hooks[0];+ const card = spawnSync('sh', ['-c', command], { cwd: repo, env: box.env, encoding: 'utf8' });+ assert.equal(card.status, 0, card.stderr);+ assert.match(card.stdout, /^resume: coordinator/);+ const bare = spawnSync('sh', ['-c', command], { cwd: repo, env: { ...box.env, PATH: '/usr/bin:/bin' }, encoding: 'utf8' });+ assert.equal(bare.status, 0, 'without pullboard installed, the session still starts');+ assert.equal(bare.stdout, '');+});