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
refactor: extract board capacity adapters [B13,M1,H16]
Corey Olsonf0b0b21573fb
diff --git a/src/board.js b/src/board.jsindex 352c3b69..4191d048 100644--- a/src/board.js+++ b/src/board.js@@ -1,9 +1,4 @@-import { lineWipLimit } from './line-wip-limit.js';-import {- capacitySettings,- lineCapacitySnapshot,- lineCapacityProblem,-} from './line-capacity.js';+import * as capacity from './line-capacity-board.js';import {lineOrderEnabled,lineBuildOrder,@@ -1023,8 +1018,7 @@ export function claim(board, id, { agentId, lane, leaseMs, freeze, head = null,? new Refused('ITEM_HELD', `item #${id} is held by coordinator: ${held.item_hold_reason}; wait for the coordinator to lift it with pullboard hold ${id} --off`): null;},- lineCapacity: found => lineCapacityProblem(board, { renewal: isRenewal(found), oldestReview: pending =>- oldestCapacityReview(board, pending, { agentId, policy: reviewPolicy, familyPolicy }) }),+ lineCapacity: found => capacity.claimProblem(board, isRenewal(found), { agentId, policy: reviewPolicy, familyPolicy }, { reviewerChecks, reviewReleaseCooldown }),oneLiveClaim: (found) => {if (found.item_parent_id !== null || isRework(found)) return null;const other = board.db@@ -1268,26 +1262,8 @@ export { reviewQueueBreakdown } from './board-query.js';export { reviewQueue } from './board-query.js';/** Offer an eligible review at the queue ratio without claiming or reserving anything [Q1,V15]. */-export function reviewOffer(board, { agentId, lane, policy = 'any', familyPolicy = 'off', ratio = 3, runnable = false, routes = ROUTES }) {- const queue = reviewQueue(board);- const settings = capacitySettings(board);- const capacity = settings.reviewsFirst === true ? lineCapacitySnapshot(board) : null;- if (capacity) ratio = typeof settings.wipPerReviewer === 'number' ? settings.wipPerReviewer : 3;- if (capacity ? queue.pending <= lineWipLimit(ratio, capacity.activeReviewers) : queue.pending < ratio * Math.max(queue.reviewing, 1)) return null;- const { item } = nextFor(board, { agentId, lane, verify: true, policy, familyPolicy, runnable, routes });- return item ? { item, queue, ratio } : null;-}--/** Find the oldest eligible submission with exactly the reservation guards, including cooldown and ownership. */-function oldestCapacityReview(board, pending, who) {- try {- const checks = Object.values(reviewerChecks(board, who));- return pending.find(item => !reviewHolder(board, item) && !reviewReleaseCooldown(board, item.item_id, who.agentId)- && checks.every(check => !check(item))) ?? null;- } catch (error) {- if (error instanceof Refused) return null; // Eligibility failures are not a different claim refusal.- throw error;- }+export function reviewOffer(board, who) {+ return capacity.reviewOffer(board, who, nextFor);}/**diff --git a/src/line-capacity-board.js b/src/line-capacity-board.jsnew file mode 100644index 00000000..1cf9df96--- /dev/null+++ b/src/line-capacity-board.js@@ -0,0 +1,41 @@+/** Capacity adapters retain the board's canonical review eligibility checks [N2,B13,H16]. */+import { Refused } from './refused.js';+import { ROUTES } from './route-escalation.js';+import {+ reviewQueue,+ reviewHolder,+} from './board-query.js';+import {+ capacitySettings,+ lineCapacitySnapshot,+ lineCapacityProblem,+} from './line-capacity.js';+import { lineWipLimit } from './line-wip-limit.js';++/** Offer the existing eligible review with either the historical ratio or enabled total-cap threshold. */+export function reviewOffer(board, { agentId, lane, policy = 'any', familyPolicy = 'off', ratio = 3, runnable = false, routes = ROUTES }, nextFor) {+ const queue = reviewQueue(board);+ const settings = capacitySettings(board);+ const capacity = settings.reviewsFirst === true ? lineCapacitySnapshot(board) : null;+ if (capacity) ratio = typeof settings.wipPerReviewer === 'number' ? settings.wipPerReviewer : 3;+ if (capacity ? queue.pending <= lineWipLimit(ratio, capacity.activeReviewers) : queue.pending < ratio * Math.max(queue.reviewing, 1)) return null;+ const { item } = nextFor(board, { agentId, lane, verify: true, policy, familyPolicy, runnable, routes });+ return item ? { item, queue, ratio } : null;+}++/** Pass only the board's renewal fact and canonical eligibility callbacks into the capacity guard. */+export function claimProblem(board, renewal, who, checks) {+ return lineCapacityProblem(board, { renewal, oldestReview: pending => oldestCapacityReview(board, pending, who, checks) });+}++/** Find the oldest eligible submission with exactly the reservation guards, including cooldown and ownership. */+function oldestCapacityReview(board, pending, who, { reviewerChecks, reviewReleaseCooldown }) {+ try {+ const checks = Object.values(reviewerChecks(board, who));+ return pending.find(item => !reviewHolder(board, item) && !reviewReleaseCooldown(board, item.item_id, who.agentId)+ && checks.every(check => !check(item))) ?? null;+ } catch (error) {+ if (error instanceof Refused) return null; // Eligibility failures are not a different claim refusal.+ throw error;+ }+}diff --git a/test/machine.test.js b/test/machine.test.jsindex 6b3d4fff..795b7a9d 100644--- a/test/machine.test.js+++ b/test/machine.test.js@@ -108,7 +108,14 @@ const NON_MOVE_ENTRY_POINTS = [];/** Board functions handed a function to call, and the one the CLI and the runner hand them. */-const CALLBACKS = { 'board.js': { freeze: 'cli.js#freezer' } };+const CALLBACKS = {+ 'board.js': { freeze: 'cli.js#freezer' },+ 'line-capacity-board.js': {+ nextFor: 'board.js#nextFor',+ reviewerChecks: 'board.js#reviewerChecks',+ reviewReleaseCooldown: 'board.js#reviewReleaseCooldown',+ },+};/*** Calls whose refusals an entry point catches and reports as another: submit and verify read a@@ -118,7 +125,7 @@ const CALLBACKS = { 'board.js': { freeze: 'cli.js#freezer' } };*/const CAUGHT = {// Review eligibility returns Refused values as data, and this helper also catches thrown eligibility refusals.- 'board.js#oldestCapacityReview': ['board.js#reviewerChecks'],+ 'line-capacity-board.js#oldestCapacityReview': ['board.js#reviewerChecks'],'commands/submit.js#submitHere': ['native-flakes.js#observeFailure', 'cli.js#freezer', 'main-red.js#compareMainFailures', 'main-red.js#matchingReworks', 'doctrine-checks.js#checkRulesAt'],// observeNativeFailure catches its optional pair/recording errors; they cannot become lifecycle refusals.'commands/verify.js#verifyHere': ['cli.js#freezer', 'native-flakes.js#observeFailure'],