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
perf(view): bound project state event reads [C7]
Corey Olsonb53c82dcf4c5
diff --git a/src/serve.js b/src/serve.jsindex bd98257c..93e0ae63 100644--- a/src/serve.js+++ b/src/serve.js@@ -338,9 +338,8 @@ export function projectState(root, { seen = null, board: providedBoard = null, i// A decline's text is its reason. Keep the inherited rule available so the page strikes the// rule itself, while showing the repo's reason beside it.const inherited = new Map(standardDoctrine().rows.map((row) => [row.id, row.text]));- const log = store.events(board);- // When each agent last moved on the board: the log is in order, so the last write wins.- const lastMove = new Map(log.map((event) => [event.event_by, event.event_at]));+ const log = store.recentEvents(board, 80);+ const lastMove = store.lastMoves(board);const state = projectRowDecisions(store.rowDecisions(board), {root: info.root,releaseNotes: viewReleaseNotes(),@@ -357,7 +356,7 @@ export function projectState(root, { seen = null, board: providedBoard = null, i// person's to answer here, and the rest with who holds them (B26).decisions: store.openDecisions(board, store.PERSON),asked: store.openDecisions(board).filter((ask) => ask.shout_to !== store.PERSON),- events: log.slice(-80).reverse(),+ events: log,agents: store.listAgents(board).map((agent) => ({ ...agent, model: agent.agent_model ?? 'unknown', displayName: displayAgentName(agent, config.agents.names), lastMoveAt: lastMove.get(agent.agent_id) ?? null })),holds: store.laneHolds(board),spec: rows(config.spec),diff --git a/test/cockpit/state-plan.test.js b/test/cockpit/state-plan.test.jsnew file mode 100644index 00000000..40be3601--- /dev/null+++ b/test/cockpit/state-plan.test.js@@ -0,0 +1,71 @@+/** @pullboard-test-input source-tree */+/** The view state gets recent events and last moves through indexed queries [C7]. */+import assert from 'node:assert/strict';+import { join } from 'node:path';+import { after, test } from 'node:test';+import * as store from '../../src/board.js';+import { projectState } from '../../src/serve.js';+import { createE2eHelpers } from '../e2e-helpers.js';++const e2e = createE2eHelpers();+const EVENTS = 45_000;+after(e2e.cleanup);++test('the view state reads recent events by index [C7]', () => {+ const box = e2e.project();+ const board = store.openBoard(join(box.repo, '.git', 'pullboard', 'board.sqlite'));+ try {+ const insert = board.db.prepare('INSERT INTO event (event_at, event_by, event_kind, item_id, event_detail) VALUES (?, ?, ?, NULL, ?)');+ const base = Math.max(...store.events(board).map((event) => Date.parse(event.event_at))) + 1000;+ board.db.exec('BEGIN');+ try {+ for (let n = 0; n < EVENTS; n += 1) {+ insert.run(new Date(base + n * 1000).toISOString(), n % 2 ? 'web-1' : 'coordinator', 'shout', '{}');+ }+ board.db.exec('COMMIT');+ } catch (error) {+ board.db.exec('ROLLBACK');+ throw error;+ }++ const originalLog = store.events(board);+ const expectedMoves = new Map(originalLog.map((event) => [event.event_by, event.event_at]));+ const expectedAgents = store.listAgents(board).map((agent) => [agent.agent_id, expectedMoves.get(agent.agent_id) ?? null]);+ const statements = [];+ const db = new Proxy(board.db, {+ get(target, key) {+ if (key === 'prepare') return (sql, ...params) => {+ if (/\b(?:FROM|JOIN)\s+event\b/iu.test(sql)) statements.push(sql);+ return target.prepare(sql, ...params);+ };+ const value = Reflect.get(target, key, target);+ return typeof value === 'function' ? value.bind(target) : value;+ },+ });+ const observedBoard = new Proxy(board, {+ get(target, key) {+ if (key === 'db') return db;+ const value = Reflect.get(target, key, target);+ return typeof value === 'function' ? value.bind(target) : value;+ },+ });++ const state = projectState(box.repo, { board: observedBoard });+ assert.deepEqual(state.events, originalLog.slice(-80).reverse(), 'the view keeps the same newest-first activity');+ assert.deepEqual(state.agents.map((agent) => [agent.agent_id, agent.lastMoveAt]), expectedAgents,+ 'the view keeps each agent’s most recent event time');+ assert.ok(statements.some((sql) => /SELECT\s+agent_id,\s*\(SELECT\s+MAX\(event_at\)/iu.test(sql)),+ 'the state asks the indexed per-agent last-move query');+ assert.ok(statements.some((sql) => /ORDER BY event_id DESC LIMIT \?/iu.test(sql)),+ 'the state asks for only the bounded newest event range');++ for (const sql of statements) {+ const parameters = (sql.match(/\?/gu) ?? []).map(() => 80);+ const plan = board.db.prepare(`EXPLAIN QUERY PLAN ${sql}`).all(...parameters).map((row) => row.detail);+ assert.doesNotMatch(plan.join('\n'), /^(?:SCAN event\b|SEARCH event USING AUTOMATIC)/mu,+ `the view state must not scan the event table for: ${sql}`);+ }+ } finally {+ store.closeBoard(board);+ }+});