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
fix(view): keep project counts with their board [N26,A2]
Corey Olsonbe81a3a83f9f
diff --git a/src/cockpit.js b/src/cockpit.jsindex 6302591f..e589d13e 100644--- a/src/cockpit.js+++ b/src/cockpit.js@@ -91,6 +91,7 @@ export function cockpitPage(key = '', { snapshot = false, readOnly = false, requ<h2>No boards yet</h2><p>Run <code>pullboard init</code> in a git repo, or ask an agent to. Its board shows up here by itself.</p></section>+ <p class="empty" id="project-loading" role="status" hidden>Loading project…</p><section class="card-panel snapshot-controls" id="snapshot-controls" ${snapshot ? '' : 'hidden'} aria-label="Snapshot replay"><span>Read-only snapshot</span><button class="ghost" id="replay-play" type="button">Play from first event</button>@@ -449,7 +450,7 @@ const count = (n, one, many = one) => n + ' ' + (n === 1 ? one : many);// the decisions passed up to them, spec rows waiting for them, and held lanes, which only the main// checkout, the person's seat, can set. Work waiting for a verdict or sent back belongs to the agents,// and the line under the project says so without counting it.-const needCount = (x) => x.ok ? x.decisions + x.pending + x.drafts + x.holds : 0;+const needCount = (x) => x.ok && !x.loading ? x.decisions + x.pending + x.drafts + x.holds : 0;const doing = (x) => [x.decisions && count(x.decisions, 'decision', 'decisions'), x.pending && count(x.pending, 'question', 'questions'), x.drafts && count(x.drafts, 'draft row', 'draft rows'), x.holds && count(x.holds, 'lane held', 'lanes held'), x.sentBack && count(x.sentBack, 'sent back'), x.awaiting && count(x.awaiting, 'to verify'), x.building && count(x.building, 'building')].filter(Boolean).join(' · ') || (x.open ? count(x.open, 'item open', 'items open') : 'nothing open');/** The person's calls in one repo, as its Needs-you panel shows them, reused by a combined project view. */function projectNeeds(p) {@@ -928,18 +929,38 @@ function boardPath(root) {*/function lastRead(board, root) {const row = data?.projects.find((entry) => entry.root === board.root && entry.id === board.id && entry.ok);- if (!row) return null;+ if (!row || row.loading) return null;const state = data.root === board.root ? data.project : data.group?.repos.find((repo) => repo.root === board.root)?.board ?? null;if (!state && (board.root === root || root === 'group:' + board.project)) return null;return { row: { ...row, ...board, ok: true }, state };}+/** Group the listed repositories without waiting for their individual board states. */+function projectGroups(projects) {+ const grouped = new Map();+ for (const project of projects) {+ if (!project.project) continue;+ if (!grouped.has(project.project)) grouped.set(project.project, []);+ grouped.get(project.project).push(project);+ }+ // One repository shows once, without a heading that repeats its name.+ return [...grouped].filter(([, repos]) => repos.length > 1).map(([name, repos]) => ({ name, key: 'group:' + name, repos }));+}+/*** Compose the multi-repo page from the public board list and each board's public state. A catch-up names the boards* whose events arrived in fresh and reads only those; every other board keeps what the page last drew (#545).*/async function boardState(root, mark, fresh = null) {const listed = await api('/api/v1/boards');+ if (!data) {+ // Names are already known: a slow board must not leave the project picker blank.+ const projects = listed.boards.map((board) => ({ ...board, ok: true, loading: true }));+ projects.push(...(listed.warnings || []).map((warning) => ({ ...warning, ok: false, error: warning.error.error.message })));+ data = { root: null, project: null, group: null, projects, groups: projectGroups(projects) };+ renderSide();+ $('project-loading').hidden = projects.length === 0;+ }const states = new Map();const cursor = mark !== null && mark !== undefined && /^\\d+$/.test(String(mark)) && Number.isSafeInteger(Number(mark)) ? Number(mark) : null;const projects = await Promise.all(listed.boards.map(async (board) => {@@ -958,15 +979,7 @@ async function boardState(root, mark, fresh = null) {}}));projects.push(...(listed.warnings || []).map((warning) => ({ ...warning, ok: false, error: warning.error.error.message })));- const grouped = new Map();- for (const project of projects) {- if (!project.project) continue;- if (!grouped.has(project.project)) grouped.set(project.project, []);- grouped.get(project.project).push(project);- }- // A project groups repos only when two or more share its name. One repo alone, as every board the relay- // lists is, shows as itself: a heading above the same board would only say it twice.- const groups = [...grouped].filter(([, repos]) => repos.length > 1).map(([name, repos]) => ({ name, key: 'group:' + name, repos }));+ const groups = projectGroups(projects);const group = groups.find((entry) => entry.key === root);return {projects, groups, project: states.get(root) || null,@@ -1399,7 +1412,7 @@ function renderSide() {if (!x.ok) return '<p class="repo-error" role="status"><b>' + esc(x.name) + ':</b> ' + esc(x.error) + '</p>';const on = x.root === view.root;const parts = doing(x).split(' · '), asks = [x.decisions, x.pending, x.drafts, x.holds].filter(Boolean).length;- const line = (asks ? '<span class="asks">' + esc(parts.slice(0, asks).join(' · ')) + '</span>' + (parts.length > asks ? ' · ' : '') : '') + esc(parts.slice(asks).join(' · '));+ const line = x.loading ? 'Loading…' : (asks ? '<span class="asks">' + esc(parts.slice(0, asks).join(' · ')) + '</span>' + (parts.length > asks ? ' · ' : '') : '') + esc(parts.slice(asks).join(' · '));return '<button class="proj repo' + (on ? ' on' : '') + '"' + (on ? ' aria-current="true"' : '') + ' data-root="' + esc(x.root) + '" title="' + esc(x.root) + '" type="button"><span class="pname">' + esc(x.name) + '</span><small>' + line + '</small></button>';};const groupedRoots = new Set(data.groups.flatMap((group) => group.repos.map((repo) => repo.root)));@@ -1413,7 +1426,8 @@ function renderSide() {$('proj-list').innerHTML = grouped || loose ? grouped + loose : '<div class="empty">None yet.</div>';const p = data.project;const selectedGroup = data.groups.find((group) => group.key === view.root);- $('proj-name').textContent = selectedGroup?.name || (p ? (data.projects.find((x) => x.root === view.root) || { name: p.root.split('/').pop() }).name : 'No project');+ const selectedRepo = data.projects.find((x) => x.root === view.root);+ $('proj-name').textContent = selectedGroup?.name || selectedRepo?.name || (p ? p.root.split('/').pop() : 'No project');// The browser tab says it too, for when the view sits behind other tabs.const needs = data.projects.reduce((n, x) => n + needCount(x), 0);document.title = p || selectedGroup ? (needs ? '(' + needs + ') ' : '') + $('proj-name').textContent + ' · Pullboard' : 'Pullboard';@@ -1771,6 +1785,15 @@ function render() {const p = data.project;const group = data.group;renderSide();+ $('project-loading').hidden = data.root === view.root;+ if (data.root !== view.root) {+ // Keep the cached picker available, but never label the last board's counts as the new one.+ document.querySelectorAll('[data-pane]').forEach((pane) => { pane.hidden = true; });+ for (const id of ['products', 'group-view', 'proof-stats', 'upgrade-note', 'person-requests', 'credentials', 'find-results']) $(id).hidden = true;+ $('status-board').innerHTML = '';+ $('live').textContent = 'Loading project…';+ return;+ }$('proof-stats').hidden = true;$('proof-stats').innerHTML = '';if (view.answering && view.answering.root !== view.root) answer(null);@@ -2828,7 +2851,7 @@ function switchTo(root, target = null, record = true) {fold(false);// The board that arrives is drawn even if it matches the last one seen, so the pick is made from it.seen = '';- if (data) renderSide();+ if (data) render();document.body.classList.add('switching');refresh().catch(() => { $('live').textContent = 'offline: is pullboard view still running?'; }).finally(() => {if (generation === switchGeneration) document.body.classList.remove('switching');diff --git a/test/cockpit/layout.test.js b/test/cockpit/layout.test.jsindex 2348179e..080884f6 100644--- a/test/cockpit/layout.test.js+++ b/test/cockpit/layout.test.js@@ -522,7 +522,8 @@ test('the project corner and the theme read the same everywhere [N26]', { timeouconst middle = (b) => b.top + b.height / 2;try {chrome = await openSnapshotChrome(executable, view.link.href, profile);- await chrome.waitFor("typeof data === 'object' && data?.projects?.length === 2 && !!document.querySelector('#proj-list .proj.repo')");+ // Project names can arrive before their states; measure the corner only after the board is drawn.+ await chrome.waitFor("data?.projects?.length === 2 && data.root === view.root && !document.body.classList.contains('loading') && document.querySelector('header.top').getBoundingClientRect().width > 0 && !!document.querySelector('#proj-list .proj.repo')");for (const scheme of ['light', 'dark']) {for (const width of [1280, 375]) {await chrome.send('Emulation.setDeviceMetricsOverride', { width, height: 900, deviceScaleFactor: 1, mobile: false });diff --git a/test/cockpit/projects.test.js b/test/cockpit/projects.test.jsindex c2fbc8b7..1f4aa14c 100644--- a/test/cockpit/projects.test.js+++ b/test/cockpit/projects.test.js@@ -10,6 +10,89 @@ import { test } from 'node:test';import { tapTarget, SPEC, machine, project, build, sendBack, fetchLive, startView, styleOf, element, openPage, projectRows, productEntries, accept, boardId, boardOf, chromeExecutable, openSnapshotChrome, closeSnapshotChrome } from './fixture.js';+test('a project switch never shows the old project\'s numbers [N26,A2]', { timeout: 120_000 }, async (t) => {+ const executable = chromeExecutable();+ if (!executable) return t.skip('Install Chrome or set PULLBOARD_CHROME for project switch checks.');+ const box = machine();+ const alpha = project(box, 'alpha');+ const beta = project(box, 'beta');+ box.run(alpha.repo, 'add', 'web', 'Alpha-only first item', '--specs', 'G1', '--criterion', 'shown');+ box.run(alpha.repo, 'add', 'web', 'Alpha-only second item', '--specs', 'G2', '--criterion', 'shown');+ box.run(beta.repo, 'add', 'web', 'Beta-only item', '--specs', 'G1', '--criterion', 'shown');+ let view, profile, chrome;+ /** Read only the rendered project names and visible board content, including the status counts. */+ const read = async () => JSON.parse(await chrome.stable(`JSON.stringify({+ names: [...document.querySelectorAll('#proj-list .pname')].map((node) => node.textContent),+ lines: [...document.querySelectorAll('#proj-list .repo small')].map((node) => node.textContent),+ name: document.querySelector('#proj-name').textContent,+ main: document.querySelector('main').innerText,+ products: document.querySelector('#products').hidden ? '' : document.querySelector('#products').innerText,+ status: document.querySelector('#status-board').innerText,+ })`));+ try {+ view = await startView(box);+ profile = mkdtempSync(join(tmpdir(), 'pullboard-project-switch-chrome-'));+ const betaId = await boardId(view, beta.repo);+ chrome = await openSnapshotChrome(executable, 'about:blank', profile);+ // Hold requests before real HTTP, without replacing any SQLite state or API reply.+ await chrome.send('Page.addScriptToEvaluateOnNewDocument', { source: `(() => {+ const nativeFetch = window.fetch.bind(window);+ const gate = window.__projectStateGate = { all: true, board: null, blocked: [] };+ gate.release = () => { gate.all = false; gate.board = null; gate.blocked.splice(0).forEach((entry) => entry.resolve()); };+ window.fetch = async (input, init) => {+ const path = new URL(typeof input === 'string' ? input : input.url, location.href).pathname;+ if (/^\\/api\\/v1\\/boards\\/[^/]+\\/state$/.test(path) && (gate.all || path === '/api/v1/boards/' + gate.board + '/state')) {+ await new Promise((resolve) => gate.blocked.push({ path, resolve }));+ }+ return nativeFetch(input, init);+ };+ })()` });+ await chrome.send('Page.navigate', { url: view.link.href });+ await chrome.waitFor('window.__projectStateGate?.blocked.length >= 2');+ const listed = await read();+ assert.deepEqual(listed.names, ['alpha', 'beta'], 'the known project names draw before any delayed board state arrives');+ assert.deepEqual(listed.lines, ['Loading…', 'Loading…'], 'unknown counts say loading rather than inventing zeros');+ await chrome.stable('window.__projectStateGate.release()');+ await chrome.waitFor(`data?.root === ${JSON.stringify(alpha.repo)} && !document.body.classList.contains('loading')`);+ const before = await read();+ assert.match(before.main, /Alpha-only/);+ assert.match(before.status, /^2\s+items\b/u);+ assert.deepEqual(before.lines, ['2 items open', '1 item open']);++ await chrome.stable(`window.__projectStateGate.board = ${JSON.stringify(betaId)}`);+ if (await chrome.stable("getComputedStyle(document.querySelector('#side .side-body')).display === 'none'")) {+ await chrome.click("document.querySelector('#proj-switch')");+ }+ await chrome.click(`document.querySelector('#proj-list [data-root="${beta.repo}"]')`);+ await chrome.waitFor('window.__projectStateGate.blocked.length > 0');+ const pending = await read();+ assert.deepEqual(pending.names, ['alpha', 'beta'], 'the cached project list stays available during the switch');+ assert.equal(pending.name, 'beta', 'the selected project is named immediately');+ assert.match(pending.main, /Loading project…/, 'the target board has an explicit loading state');+ assert.doesNotMatch(pending.main, /Alpha-only/, 'the old board is hidden beneath the new project name');+ assert.equal(pending.status, '', 'the old item and agent counts are absent until the target state arrives');+ assert.equal(pending.products, '', 'the old project progress is absent too');+ assert.deepEqual(pending.lines, before.lines, 'cached sidebar summaries retain their own project identities');+ await chrome.stable('window.__projectStateGate.release()');+ await chrome.waitFor(`data?.root === ${JSON.stringify(beta.repo)} && !document.body.classList.contains('switching')`);+ const after = await read();+ assert.match(after.main, /Beta-only item/);+ assert.doesNotMatch(after.main, /Alpha-only|Loading project…/);+ assert.match(after.status, /^1\s+items\b/u);+ assert.deepEqual(chrome.exceptions, [], 'the delayed switch raises no uncaught exception');+ } finally {+ try {+ if (chrome) {+ await chrome.stable('window.__projectStateGate?.release()').catch(() => {});+ await closeSnapshotChrome(chrome);+ }+ } finally {+ try { if (profile) rmSync(profile, { recursive: true, force: true }); }+ finally { if (view) await view.stop(); }+ }+ }+});+test('the sidebar lists every project and what needs the person [N26]', async () => {const box = machine();const alpha = project(box, 'alpha');