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(next): route a session across its lanes [N2,B13]
Corey Olson0cf8f8bd5312
diff --git a/src/agent-session.js b/src/agent-session.jsindex 3ef0e2bb..be9704bf 100644--- a/src/agent-session.js+++ b/src/agent-session.js@@ -1,7 +1,7 @@/** A checkout belongs to one local agent session; bindings never enter the shared board [B3,B7]. */import { createHash } from 'node:crypto';-import { existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';-import { join } from 'node:path';+import { existsSync, readdirSync, readFileSync, realpathSync, renameSync, writeFileSync } from 'node:fs';+import { dirname, join, resolve } from 'node:path';import { takeResource } from './resources.js';import { Refused } from './refused.js';@@ -55,3 +55,32 @@ export async function bindLocalSession(info, { agent, digest, takeover = false,}} finally { if (!retained) lease.release(); }}++/** Find this session's registered seats from local Git bindings, never from shared board credentials. */+export function localSessionSeats(info, { agents, digest }) {+ const directory = join(info.commonDir, 'worktrees');+ if (!existsSync(directory)) return [];+ const registered = new Map(agents.map((agent) => [agent.agent_id, agent]));+ const seats = [];+ for (const entry of readdirSync(directory, { withFileTypes: true })) {+ if (!entry.isDirectory()) continue;+ const gitDir = join(directory, entry.name);+ try {+ const binding = readBinding(join(gitDir, 'pullboard-checkout-session.json'), false);+ if (!binding || binding.digest !== digest) continue;+ const agent = registered.get(binding.agent);+ if (!agent || agent.agent_lane === 'coordinator') continue;+ const gitFile = readFileSync(join(gitDir, 'gitdir'), 'utf8').trim();+ const root = realpathSync(dirname(gitFile));+ if (root !== agent.agent_path) continue;+ const pointer = readFileSync(gitFile, 'utf8').trim();+ if (!pointer.startsWith('gitdir: ') || resolve(root, pointer.slice(8)) !== resolve(gitDir)) continue;+ seats.push(agent);+ } catch (error) {+ // Gone or damaged peers are not authority to borrow a checkout. The invoking seat was+ // already checked by bindCheckoutSession, so its own damaged binding still refuses.+ if (!['ENOENT', 'ENOTDIR'].includes(error.code) && !(error instanceof Refused)) throw error;+ }+ }+ return seats;+}diff --git a/src/board.js b/src/board.jsindex b471ca02..6907471b 100644--- a/src/board.js+++ b/src/board.js@@ -2136,6 +2136,16 @@ function milestonePriorities(board) {return (entry) => priorities.get(entry.item_id) ?? ordered.length;}+/** Make the shared build-queue comparator once: milestone, route, recent files, then oldest. */+export function buildOrder(board, { warm = [] } = {}) {+ const milestonePriority = milestonePriorities(board);+ const recent = new Set(warm);+ const shared = (entry) => itemFiles(entry).filter((path) => recent.has(path)).length;+ return (first, second) => milestonePriority(first) - milestonePriority(second)+ || ROUTES.indexOf(second.item_route) - ROUTES.indexOf(first.item_route)+ || shared(second) - shared(first) || first.item_id - second.item_id;+}+/*** The next item an agent can take (N2): for a builder, the oldest open item in its lane whose* dependencies are verified; for a verifier, the oldest submitted item it did not build. An agent@@ -2149,10 +2159,10 @@ function milestonePriorities(board) {* and `shared` names them (N20). A held lane offers nothing new (N22).** @param {any} board- * @param {{ agentId: string, lane: string, verify?: boolean, policy?: string, familyPolicy?: string, runnable?: boolean, routes?: string[], warm?: string[], priority?: number[] }} who+ * @param {{ agentId: string, lane: string, verify?: boolean, policy?: string, familyPolicy?: string, runnable?: boolean, routes?: string[], warm?: string[], priority?: number[], lanes?: string[] }} who* @returns {{ item: any | null, reasons: string[], shared?: string[] }}*/-export function nextFor(board, { agentId, lane, verify = false, policy = 'any', familyPolicy = 'off', runnable = false, routes = ROUTES, warm = [], priority = [] }) {+export function nextFor(board, { agentId, lane, verify = false, policy = 'any', familyPolicy = 'off', runnable = false, routes = ROUTES, warm = [], priority = [], lanes }) {const route = routeOf(board, agentId);const tier = (entry) => ROUTES.indexOf(entry.item_route);const allItems = listItems(board).reverse();@@ -2187,20 +2197,23 @@ export function nextFor(board, { agentId, lane, verify = false, policy = 'any',}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 reasons = allItems.filter((entry) => entry.item_status === 'open' && entry.item_lane === lane && entry.item_hold_reason)+ const selectedLanes = new Set(lanes ?? [lane]);+ const reasons = allItems.filter((entry) => entry.item_status === 'open' && selectedLanes.has(entry.item_lane) && entry.item_hold_reason).map((entry) => `#${entry.item_id} is held by coordinator: ${entry.item_hold_reason}`);const paused = laneHold(board, lane);- if (paused) return { item: null, reasons: [`${paused.hold_by} holds the ${lane} lane: ${paused.hold_reason}`, ...reasons] };- const milestonePriority = milestonePriorities(board);+ if (!lanes && paused) return { item: null, reasons: [`${paused.hold_by} holds the ${lane} lane: ${paused.hold_reason}`, ...reasons] };+ if (lanes) for (const name of selectedLanes) {+ const hold = laneHold(board, name);+ if (hold) { selectedLanes.delete(name); reasons.push(`${hold.hold_by} holds the ${name} lane: ${hold.hold_reason}`); }+ }+ const compare = buildOrder(board, { warm });const recent = new Set(warm);const mainRed = new Set(priority);- const laneItems = items.filter((entry) => entry.item_status === 'open' && entry.item_lane === lane);+ const laneItems = items.filter((entry) => entry.item_status === 'open' && selectedLanes.has(entry.item_lane));const mine = laneItems.filter((entry) => !itemHold(board, entry.item_id)).map((entry, order) => ({ entry, order, shared: itemFiles(entry).filter((path) => recent.has(path)) }))- .sort((first, second) => milestonePriority(first.entry) - milestonePriority(second.entry)- || tier(second.entry) - tier(first.entry)- || second.shared.length - first.shared.length || first.order - second.order);+ .sort((first, second) => compare(first.entry, second.entry));// Move only evidenced reworks ahead of their own tier; with no evidence, normal order is exact.for (const route of ROUTES) {const routeTier = ROUTES.indexOf(route);diff --git a/src/cli.js b/src/cli.jsindex 459f659d..d3b92192 100644--- a/src/cli.js+++ b/src/cli.js@@ -16,8 +16,8 @@ import { displayAgentName } from './agent-names.js';import { doctrineHistory, loadDoctrine } from './doctrine.js';import { agentDoctrine, proposeDoctrine, resumeDoctrineNotes, staleDoctrineRows } from './doctrine-rulings.js';import { checkRulesAt, doctrineReport, hasSubmitRules, holdDoctrine, ruleLine } from './doctrine-checks.js';-import { agentSessionDigest, requirePersonChannel } from './person.js';-import { bindLocalSession, localSessionMatches } from './agent-session.js';+import { AGENT_SESSION_IDS, agentSessionDigest, requirePersonChannel } from './person.js';+import { bindLocalSession, localSessionMatches, localSessionSeats } from './agent-session.js';import { decisionAnswer, decisionProjection, handAnsweredQuestions, pendingAnswers, planRowApply, prepareRowDecisions, restoreRowApply, writeRowApply } from './row-decisions.js';import { digestOf, gateReport, refuseSandboxBlocked, runGate, runProfiledShell, runSubmitGate, submitGateReport, timingDigest, withGateSlot } from './gate.js';import { checkNeedsBrowser, explicitCheckFiles } from './browser-admission.js';@@ -2647,6 +2647,34 @@ function primaryCheckoutRoot(info) {return found.length === 1 ? found[0] : null;}+/** A real runtime session may route across its own local seats; marker-only shells stay isolated. */+function nextSessionSeats(ctx, board) {+ if (ctx.info.isMain || ctx.io.personChannel === 'view' || ctx.io.personRequest+ || !AGENT_SESSION_IDS.some((name) => Boolean(process.env[name]))) return null;+ const digest = agentSessionDigest();+ return digest ? localSessionSeats(ctx.info, { agents: store.listAgents(board), digest }) : null;+}++/** Choose or open the matching lane seat, retaining ordinary checkout ownership and lane guards. */+async function nextSeatContext(ctx, board, me, item, seats) {+ const available = seats.filter((agent) => agent.agent_lane === item.item_lane+ && store.ROUTES.indexOf(agent.agent_route) >= store.ROUTES.indexOf(item.item_route));+ const held = item.item_status === 'claimed';+ let agent = held ? available.find((seat) => seat.agent_id === item.item_owner)+ : available.find((seat) => seat.agent_id === me.id) ?? available[0];+ let created = false;+ if (!agent) {+ let opened;+ await worktreeFor({ ...ctx.io, say: () => {}, result: (value) => { opened = value; } }, item.item_lane, me.route, me.family, me.model);+ agent = store.agentAt(board, opened.path);+ created = true;+ }+ const target = agent.agent_path === ctx.info.root ? ctx : context({ ...ctx.io, cwd: agent.agent_path });+ if (target.info.commonDir !== ctx.info.commonDir) throw new Refused('NOT_YOUR_CHECKOUT', 'the selected lane seat no longer belongs to this board; run pullboard next again');+ await bindLocalSession(target.info, { agent: agent.agent_id, digest: agentSessionDigest() });+ return { context: target, seat: { agent: agent.agent_id, lane: agent.agent_lane, path: target.info.root, created } };+}+/*** One loop of `next`: claim the next free item, or reserve the next review (V15). A claim that loses* a race to another agent is not an error; the caller looks again. A review is looked for and@@ -2668,8 +2696,16 @@ async function nextOnce(ctx, values) {return await ordered(ctx, board, 'reserveNextReview', [{ agentId: me.id, lane: me.lane, leaseMs: ctx.config.reviewLeaseMs, policy: ctx.config.verify.policy, familyPolicy: ctx.config.verify.family, runnable: values.runnable, routes: values.routes }]);}const warm = warmFiles(ctx, board, me);- const { item, reasons, shared } = store.nextFor(board, { agentId: me.id, lane: me.lane, runnable: values.runnable, routes: values.routes, warm,- priority: mainRedReworkItems(ctx.info.root, board) });+ const seats = nextSessionSeats(ctx, board);+ const owners = new Set(seats?.map((seat) => seat.agent_id));+ const heldItems = seats ? store.listItems(board).filter((item) => item.item_status === 'claimed'+ && item.item_parent_id === null && owners.has(item.item_owner)+ && store.ROUTES.indexOf(item.item_route) <= store.ROUTES.indexOf(me.route)) : [];+ const heldItem = heldItems.find((item) => item.item_owner === me.id) ?? heldItems[0];+ const { item, reasons, shared } = heldItem ? { item: heldItem, reasons: [], shared: [] }+ : store.nextFor(board, { agentId: me.id, lane: me.lane, runnable: values.runnable, routes: values.routes, warm,+ ...(seats ? { lanes: laneNames(ctx.config).filter((lane) => lane !== COORDINATOR) } : {}),+ priority: mainRedReworkItems(ctx.info.root, board) });const held = item?.item_status === 'claimed';const offer = held ? null : store.reviewOffer(board, { agentId: me.id, lane: me.lane, policy: ctx.config.verify.policy,familyPolicy: ctx.config.verify.family, ratio: ctx.config.verify.reviewRatio, runnable: values.runnable, routes: values.routes });@@ -2677,14 +2713,17 @@ async function nextOnce(ctx, values) {if (!item) return { reasons };const reviewSkipped = values.build && !held? { offeredItem: offer?.item.item_id ?? null, ratio: ctx.config.verify.reviewRatio, ...store.reviewQueue(board) } : null;+ const routed = seats ? await nextSeatContext(ctx, board, me, item, seats) : { context: ctx };+ const target = routed.context;+ const holder = whoAmI(target, board);try {- await claimOrdered(ctx, board, [item.item_id, { agentId: me.id, lane: me.lane, leaseMs: ctx.config.leaseMs, freeze: claimFreezer(ctx, board), head: headCommit(ctx.info.root), reviewSkipped }]);+ await claimOrdered(target, board, [item.item_id, { agentId: holder.id, lane: holder.lane, leaseMs: target.config.leaseMs, freeze: claimFreezer(target, board), head: headCommit(target.info.root), reviewSkipped }]);} catch (error) {- if (error instanceof MainSpecMerged) return { retry: true, specMerged: { item: item.item_id, rows: error.rows } };+ if (error instanceof MainSpecMerged) return { retry: true, ...routed, specMerged: { item: item.item_id, rows: error.rows } };if (error instanceof Refused && ['HELD', 'ITEM_HELD', 'BLOCKED', 'ONE_CLAIM'].includes(error.code)) return { retry: true };throw error;}- return { item: store.getItem(board, item.item_id), shared, held, reviewSkipped, reasons };+ return { item: store.getItem(board, item.item_id), shared, held, reviewSkipped, reasons, ...routed };});}@@ -2761,6 +2800,7 @@ async function nextHere(io, values) {const deadline = Date.now() + minutes * 60_000;for (;;) {const found = await nextOnce(ctx, values);+ if (found.context) ctx = found.context;if (found.specMerged) {io.say(`merged main before claiming #${found.specMerged.item}: added spec rows ${found.specMerged.rows.join(', ')}`);ctx = context(io);@@ -2770,7 +2810,7 @@ async function nextHere(io, values) {if (found.offer) { sayReviewOffer(ctx, found); return 0; }const item = found.item;const agents = withBoard(ctx, (board) => store.listAgents(board));- io.result?.({ item, review: Boolean(values.verify), held: Boolean(found.held), shared: found.shared ?? [], reasons: found.reasons ?? [] });+ io.result?.({ item, review: Boolean(values.verify), held: Boolean(found.held), shared: found.shared ?? [], reasons: found.reasons ?? [], ...(found.seat ? { seat: found.seat } : {}) });for (const reason of found.reasons ?? []) io.say(displayedWait(reason, agents, ctx.config));const here = cdTo(ctx.info.root);const as = ctx.info.isMain ? ' --as coordinator' : '';@@ -2783,6 +2823,7 @@ async function nextHere(io, values) {} else {if (found.reviewSkipped) io.say(`${reviewQueueLine(ctx, found.reviewSkipped)}; explicit build intent recorded with this claim`);io.say(`${found.held ? 'you hold' : 'claimed'} #${item.item_id}: ${item.item_title}`);+ if (found.seat) io.say(`${found.seat.created ? 'opened' : 'work in'} ${found.seat.agent}, ${found.seat.lane} lane: ${here}`);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)`);diff --git a/src/templates.js b/src/templates.jsindex 717bf7aa..d60dfcea 100644--- a/src/templates.js+++ b/src/templates.js@@ -121,7 +121,7 @@ It prints the folder to work in and what to run there first. Every join needs th**The loop.**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 9\` keeps looking for up to 9 minutes, which fits one tool call with a ten-minute timeout; run it again to keep waiting. 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. \`pullboard why <id>\` lists the decisions that changed it, newest first. When your own answer, verdict or fact changes other items, name them with \`--implies <ids>\` so each one carries it. A claim or submit refused as CRITERION_PROVES_NOTHING names a check that already passes on main, so it proves nothing: shout the coordinator for a check that fails before the work. Only the person accepts a check as it stands, with \`pullboard check accept <id>\` from the main checkout or the view.+2. \`pullboard next\` claims the next free item your session can take across the lanes, by release and queue rank. It names the lane worktree to use and opens one when your session has none there; begin subsequent commands in that folder. Each worktree still owns only its lane’s files. Joining associates the seat with the invoking agent session automatically; no person setup is needed. When everything is waiting on other work, \`pullboard next --wait 9\` keeps looking for up to 9 minutes, which fits one tool call with a ten-minute timeout; run it again to keep waiting. 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. \`pullboard why <id>\` lists the decisions that changed it, newest first. When your own answer, verdict or fact changes other items, name them with \`--implies <ids>\` so each one carries it. A claim or submit refused as CRITERION_PROVES_NOTHING names a check that already passes on main, so it proves nothing: shout the coordinator for a check that fails before the work. Only the person accepts a check as it stands, with \`pullboard check accept <id>\` from the main checkout or the view.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.5. A different agent verifies: \`pullboard next --verify\` names the next item to check. It checks out the submitted commit and runs \`pullboard verify <id> accept --note "how it proved it"\`, or \`pullboard verify <id> reject --reason TEST_FAILURE --note "what failed"\`.