Skip to content

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.

feat(view): group repos by project [N33,N34,N36]

Corey Olson6a84ea910bda
diff --git a/src/cockpit.js b/src/cockpit.js
index f7fa9990..ccddb4f8 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -71,6 +71,10 @@ export function cockpitPage(key = '') {
<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>
+ <section id="group-view" class="group-view" hidden>
+ <section class="card-panel group-panel"><h2>Needs you</h2><div id="group-needs"></div></section>
+ <section class="card-panel group-panel"><h2>Activity</h2><div class="feed" id="group-activity"></div></section>
+ </section>
<section data-pane="items" class="two">
<div class="primary">
<div class="card-panel toolbar"><div class="seg" id="state-chips" role="group" aria-label="Show"></div><input id="q" type="search" placeholder="Search" aria-label="Search titles, lanes or ids"><button class="go" id="new-item" type="button">New item</button></div>
@@ -175,6 +179,19 @@ const count = (n, one, many = one) => n + ' ' + (n === 1 ? one : many);
// verdict, open questions, held lanes.
const needCount = (x) => x.ok ? x.decisions + x.sentBack + x.awaiting + x.pending + x.holds : 0;
const doing = (x) => [x.decisions && count(x.decisions, 'decision', 'decisions'), x.sentBack && count(x.sentBack, 'sent back'), x.awaiting && count(x.awaiting, 'to verify'), x.pending && count(x.pending, 'question', 'questions'), x.holds && count(x.holds, 'lane held', 'lanes held'), x.building && count(x.building, 'building')].filter(Boolean).join(' · ') || (x.open ? count(x.open, 'item open', 'items open') : 'nothing open');
+/** The actionable rows shown in one repo's Needs-you panel, reused by a combined project view. */
+function projectNeeds(p) {
+ const items = p.items.filter((item) => item.status !== 'withdrawn');
+ const by = (state) => items.filter((item) => stateOf(item) === state);
+ return [
+ ...p.decisions.map((d) => ({ ref: d.shout_from, text: d.shout_text, what: 'decision', at: d.shout_at })),
+ ...p.spec.filter((row) => row.status === 'pending').map((row) => ({ ref: row.id, text: row.text, what: 'answer in SPEC.md' })),
+ ...by('back').map((item) => ({ ref: '#' + item.id, text: item.title, what: 'sent back: ' + item.verdict.reason, target: 'item:' + item.id, at: item.updatedAt })),
+ ...by('verify').map((item) => ({ ref: '#' + item.id, text: item.title, what: item.reviewer ? 'being reviewed by ' + item.reviewer : rejected(item) ? 'resubmitted after ' + item.verdict.reason : 'to verify', target: 'item:' + item.id, at: item.updatedAt })),
+ ...p.holds.map((hold) => ({ ref: hold.hold_lane, text: hold.hold_reason, what: 'lane held' })),
+ ...(p.spec.some((row) => row.status === 'draft') ? [{ ref: String(p.spec.filter((row) => row.status === 'draft').length), text: 'draft spec rows to approve or drop', what: 'review in SPEC.md', target: 'tab:spec' }] : []),
+ ];
+}
// The item lifecycle as pullboard declares it in src/machine.js, embedded when the page is served.
const FLOW = ${JSON.stringify(lifecycle()).replaceAll('<', '\\u003c')};
@@ -404,7 +421,7 @@ async function refresh() {
const next = await api('/api/state' + (root ? '?root=' + encodeURIComponent(root) + (mark === null || mark === undefined ? '' : '&seen=' + encodeURIComponent(mark)) : ''));
// The person switched projects while this answer was on its way: the switch's own refresh shows it.
if (root !== view.root) return;
- if (!next.project && next.projects.some((p) => p.ok)) {
+ if (!next.project && !next.group && next.projects.some((p) => p.ok)) {
view.root = next.projects.find((p) => p.ok).root;
keep('pb.project', view.root);
return refresh();
@@ -426,31 +443,60 @@ async function refresh() {
* this until the new board arrives, so the main column never mixes the old board with the new pick.
*/
function renderSide() {
- // Every project stays in view with what needs the person there, so one look covers them all.
- $('proj-list').innerHTML = data.projects.length ? data.projects.map((x) => {
+ /** Render a repo button or one muted recovery line when its board cannot be read. */
+ const repoButton = (x) => {
+ 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;
- return '<button class="proj' + (on ? ' on' : '') + '"' + (on ? ' aria-current="true"' : '') + ' data-root="' + esc(x.root) + '" title="' + esc(x.root) + '" type="button"><span class="pname">' + esc(x.name) + '</span>' + (needCount(x) ? '<b class="need" title="needs you">' + needCount(x) + '</b>' : '') + (x.ok ? '<small>' + esc(doing(x)) : '<small class="bad">' + esc(x.error)) + '</small></button>';
- }).join('') : '<div class="empty">None yet.</div>';
- const elsewhere = data.projects.filter((x) => x.root !== view.root).reduce((n, x) => n + needCount(x), 0);
+ 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>' + (needCount(x) ? '<b class="need" title="needs you">' + needCount(x) + '</b>' : '') + '<small>' + esc(doing(x)) + '</small></button>';
+ };
+ const groupedRoots = new Set(data.groups.flatMap((group) => group.repos.map((repo) => repo.root)));
+ const grouped = data.groups.map((group) => {
+ const on = group.key === view.root;
+ const needs = group.repos.reduce((total, repo) => total + needCount(repo), 0);
+ const count = group.repos.length;
+ return '<section class="repo-group"><button class="proj project-pick' + (on ? ' on' : '') + '"' + (on ? ' aria-current="true"' : '') + ' data-root="' + esc(group.key) + '" type="button"><span class="pname">' + esc(group.name) + '</span>' + (needs ? '<b class="need" title="needs you">' + needs + '</b>' : '') + '<small>' + count + ' ' + (count === 1 ? 'repo' : 'repos') + '</small></button><div class="repos">' + group.repos.map(repoButton).join('') + '</div></section>';
+ }).join('');
+ const loose = data.projects.filter((repo) => !repo.project && !groupedRoots.has(repo.root)).map(repoButton).join('');
+ $('proj-list').innerHTML = grouped || loose ? grouped + loose : '<div class="empty">None yet.</div>';
+ const currentGroup = data.groups.find((group) => group.key === view.root);
+ const currentRoots = new Set(currentGroup ? currentGroup.repos.map((repo) => repo.root) : [view.root]);
+ const elsewhere = data.projects.filter((x) => !currentRoots.has(x.root)).reduce((n, x) => n + needCount(x), 0);
$('proj-elsewhere').textContent = elsewhere ? elsewhere + ' elsewhere' : '';
$('proj-elsewhere').hidden = !elsewhere;
const p = data.project;
- $('proj-name').textContent = p ? (data.projects.find((x) => x.root === view.root) || { name: p.root.split('/').pop() }).name : 'No 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');
// 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 ? (needs ? '(' + needs + ') ' : '') + $('proj-name').textContent + ' · Pullboard' : 'Pullboard';
+ document.title = p || selectedGroup ? (needs ? '(' + needs + ') ' : '') + $('proj-name').textContent + ' · Pullboard' : 'Pullboard';
+}
+
+/** Draw a project's cross-repo Needs-you list and one activity feed. */
+function renderGroup(group) {
+ const needs = group.repos.flatMap((repo) => projectNeeds(repo.board).map((row) => ({ ...row, repo })));
+ $('group-needs').innerHTML = needs.length ? needs.map((row) => '<button class="group-need" data-root="' + esc(row.repo.root) + '" type="button"><b>' + esc(row.repo.name) + '</b><code>' + esc(row.ref) + '</code><span>' + esc(row.text) + '</span><em>' + esc(row.what) + (row.at ? ', ' + age(row.at) : '') + ' →</em></button>').join('') : '<div class="empty">Nothing needs you across this project.</div>';
+ const events = group.repos.flatMap((repo) => {
+ const titles = new Map(repo.board.items.map((item) => [String(item.id), item.title]));
+ return repo.board.events.map((event) => ({ ...event, repo, title: event.item_id ? titles.get(String(event.item_id)) : null }));
+ }).sort((a, b) => b.event_at.localeCompare(a.event_at)).slice(0, 80);
+ $('group-activity').innerHTML = events.length ? byDay(events, (event) => event.event_at, (event) => '<div><time>' + clock(event.event_at) + '</time><div class="act"><b class="repo-label">' + esc(event.repo.name) + '</b> <span>' + esc(event.event_by) + ' ' + esc(event.event_kind) + (event.item_id ? ' #' + event.item_id + (event.title ? ' ' + esc(event.title) : '') : '') + '</span></div></div>') : '<div class="empty">No activity yet.</div>';
}
/** Draw the board shown: the sidebar, then every tab's panes from the project's board. */
function render() {
const p = data.project;
+ const group = data.group;
renderSide();
if (view.answering && view.answering.root !== view.root) answer(null);
// Until the first board arrives the page shows no tabs or panes, so a machine with none never
// flashes them; with no board to show, one message says how a board starts, in their place.
document.body.classList.remove('loading');
- document.body.classList.toggle('boardless', !p);
+ document.body.classList.toggle('boardless', !p && !group);
+ $('group-view').hidden = !group;
+ $('tabs').hidden = Boolean(group);
+ document.querySelectorAll('[data-pane]').forEach((pane) => { pane.hidden = Boolean(group) || pane.dataset.pane !== view.tab; });
$('products').hidden = !p || !p.products.length;
+ if (group) { renderGroup(group); return; }
if (!p) return;
// Each product's progress (N28): the rows an accepted item cites, and its items by state.
$('prod-list').innerHTML = p.products.map((x) => {
diff --git a/src/serve.js b/src/serve.js
index e27392ef..2385a86a 100644
--- a/src/serve.js
+++ b/src/serve.js
@@ -9,7 +9,7 @@
*/
import { spawn, spawnSync } from 'node:child_process';
import { randomBytes, timingSafeEqual } from 'node:crypto';
-import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
+import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { createServer } from 'node:http';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -106,10 +106,31 @@ function summary(project) {
};
});
} catch (error) {
- return { ...project, ok: false, error: error.message };
+ const reason = !existsSync(project.root) ? 'The folder is missing.'
+ : error?.code === 'NO_CONFIG' ? 'pullboard.json is missing.'
+ : error?.code === 'BAD_CONFIG' ? 'pullboard.json is invalid.'
+ : error?.code === 'NOT_A_REPO' ? 'The folder is not a Git repository.'
+ : 'Repository settings or its board cannot be read.';
+ return { ...project, ok: false, error: `${reason} Run pullboard forget "${project.root}" to remove it.` };
}
}
+/**
+ * Group registered repositories by their configured project name for the sidebar and group view.
+ *
+ * @param {any[]} projects
+ * @returns {{ name: string, key: string, repos: any[] }[]}
+ */
+function projectGroups(projects) {
+ const grouped = new Map();
+ for (const repo of projects) {
+ if (!repo.project) continue;
+ if (!grouped.has(repo.project)) grouped.set(repo.project, []);
+ grouped.get(repo.project).push(repo);
+ }
+ return [...grouped].map(([name, repos]) => ({ name, key: `group:${name}`, repos }));
+}
+
/**
* Everything the page shows for one project. Given the newest shout the person has seen there,
* it also counts every shout since, which the forty it sends cannot always show.
@@ -293,10 +314,20 @@ export function serveView({ port = 0, secret = randomBytes(18).toString('base64u
if (req.method === 'GET' && url.pathname === '/view.css') return reply(res, 200, 'text/css; charset=utf-8', VIEW_CSS);
if (req.method === 'GET' && url.pathname === '/api/state') {
const projects = listProjects().map(summary);
+ const groups = projectGroups(projects);
const root = url.searchParams.get('root');
const known = projects.find((project) => project.root === root && project.ok);
+ const group = root?.startsWith('group:') ? groups.find((entry) => entry.name === root.slice('group:'.length)) : null;
const seen = /^\d+$/.test(url.searchParams.get('seen') ?? '') ? Number(url.searchParams.get('seen')) : null;
- return json(res, 200, { projects, project: known ? projectState(known.root, { seen }) : null });
+ return json(res, 200, {
+ projects,
+ groups,
+ project: known ? projectState(known.root, { seen }) : null,
+ group: group ? {
+ name: group.name,
+ repos: group.repos.filter((repo) => repo.ok).map((repo) => ({ root: repo.root, name: repo.name, board: projectState(repo.root) })),
+ } : null,
+ });
}
if (req.method === 'GET' && url.pathname === '/api/code') {
const root = url.searchParams.get('root');
diff --git a/src/view.css b/src/view.css
index ccc31a98..73a5d4d5 100644
--- a/src/view.css
+++ b/src/view.css
@@ -43,7 +43,21 @@ button, input, select, textarea { font: inherit; color: inherit; }
.proj.on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.proj .pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj small { grid-column: 1 / -1; color: var(--ink-faint); font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; }
-.proj small.bad { color: var(--reject); }
+.repo-group { display: grid; gap: 1px; }
+.project-pick { background: var(--surface-2); }
+.repos { display: grid; gap: 1px; margin-left: 8px; padding-left: 7px; border-left: 1px solid var(--line); }
+.repo-error { margin: 3px 0 5px 8px; padding: 6px 8px; color: var(--ink-faint); font-size: 12px; line-height: 1.4; overflow-wrap: anywhere; }
+.repo-error b { color: var(--ink-muted); }
+.group-view { display: grid; gap: 14px; max-width: 1000px; }
+.group-panel { padding: 14px 16px; }
+.group-panel h2 { margin: 0 0 10px; font-size: 17px; }
+.group-need { display: grid; grid-template-columns: minmax(90px, auto) auto minmax(0, 1fr) auto; align-items: baseline; gap: 5px 10px; width: 100%; padding: 9px 0; text-align: left; border: 0; border-top: 1px solid var(--line); background: none; cursor: pointer; }
+.group-need:hover { background: var(--surface-2); }
+.group-need > b { color: var(--ink-muted); }
+.group-need > code { color: var(--accent-strong); }
+.group-need > span { overflow-wrap: anywhere; }
+.group-need > em { color: var(--ink-faint); font-size: 12px; font-style: normal; }
+.repo-label { color: var(--ink-muted); }
.need { min-width: 20px; padding: 1px 6px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); font: 700 11.5px/1.5 var(--mono); text-align: center; }
.products { padding-top: 6px; }
.prod { display: grid; grid-template-columns: minmax(0, 1fr); gap: 5px; padding: 6px 8px 8px; font-size: 13px; }
@@ -87,8 +101,14 @@ main { padding: 16px 18px 28px; }
.live { display: none; }
main { padding: 12px 10px 24px; }
.two, .two.narrow { grid-template-columns: minmax(0, 1fr); }
+ .group-need { grid-template-columns: minmax(80px, auto) auto minmax(0, 1fr); }
+ .group-need > em { grid-column: 3; }
}
@media (width < 480px) {
+ .group-need { grid-template-columns: minmax(0, 1fr) auto; gap: 3px 8px; }
+ .group-need > b { grid-column: 1; }
+ .group-need > code { grid-column: 2; }
+ .group-need > span, .group-need > em { grid-column: 1 / -1; }
.tabs { flex: 1; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 0; }
.tab { display: grid; grid-template-rows: auto 13px; justify-items: center; align-content: center; padding: 7px 2px 5px; font-size: 13.5px; }
.tab b { margin: 0; line-height: 13px; }
diff --git a/test/cockpit.test.js b/test/cockpit.test.js
index 96c47627..992385c7 100644
--- a/test/cockpit.test.js
+++ b/test/cockpit.test.js
@@ -381,6 +381,63 @@ test('the sidebar lists every project and what needs the person [N26]', async ()
}
});
+test('projects group repos with combined needs and activity, while ungrouped and unreadable repos stay clear [N33, N34, N36]', async () => {
+ const box = machine();
+ const core = project(box, 'core', SPEC, { name: 'Core API', project: 'Atlas' });
+ box.run(core.repo, 'add', 'web', 'Greeting', '--specs', 'G1', '--criterion', 'greets');
+ build(box, core, 1, 'greeting.html');
+ sendBack(box, core, 1, 'the page needs a greeting');
+ const web = project(box, 'web', SPEC, { name: 'Web UI', project: 'Atlas' });
+ box.run(web.repo, 'add', 'web', 'Header', '--specs', 'G1', '--criterion', 'has a header');
+ build(box, web, 1, 'header.html');
+ const standalone = project(box, 'standalone', SPEC, { name: 'Scratchpad' });
+ const broken = project(box, 'broken', SPEC, { name: 'Broken repo', project: 'Atlas' });
+ const view = await startView(box);
+ try {
+ const headers = { 'x-pullboard-key': view.key };
+ let response = await fetch(`${view.base}/api/state`, { headers });
+ let state = await response.json();
+ assert.deepEqual(state.groups.map((group) => [group.name, group.repos.map((repo) => repo.name)]), [['Atlas', ['Core API', 'Web UI', 'Broken repo']]]);
+ writeFileSync(join(broken.repo, 'pullboard.json'), '{not valid json');
+ response = await fetch(`${view.base}/api/state`, { headers });
+ state = await response.json();
+ const unreadable = state.projects.find((repo) => repo.root === broken.repo);
+ assert.equal(unreadable.ok, false);
+ assert.match(unreadable.error, /pullboard\.json is invalid/);
+ assert.match(unreadable.error, /pullboard forget/);
+ assert.doesNotMatch(unreadable.error, /BAD_CONFIG|SyntaxError/);
+
+ const page = await openPage(view);
+ const side = page.show('proj-list');
+ assert.match(side, /class="repo-group"/);
+ assert.match(side, /data-root="group:Atlas"/);
+ assert.match(side, /Core API/);
+ assert.match(side, /Web UI/);
+ assert.match(side, /Scratchpad/);
+ assert.match(side, /class="repo-error" role="status"><b>Broken repo:<\/b> pullboard\.json is invalid\. Run pullboard forget/);
+ assert.doesNotMatch(side, /class="small bad"|class="bad"/);
+
+ await page.click({ root: 'group:Atlas' });
+ assert.equal(page.element('group-view').hidden, false);
+ assert.equal(page.element('tabs').hidden, true);
+ assert.match(page.show('group-needs'), /Core API/);
+ assert.match(page.show('group-needs'), /Web UI/);
+ assert.match(page.show('group-needs'), /sent back: BEHAVIOR_MISMATCH/);
+ assert.match(page.show('group-activity'), /Core API/);
+ assert.match(page.show('group-activity'), /Web UI/);
+ assert.match(page.show('group-activity'), /Greeting|Header/);
+
+ await page.click({ root: core.repo });
+ assert.equal(page.element('group-view').hidden, true);
+ assert.equal(page.element('tabs').hidden, false);
+ assert.match(page.show('chain'), /Greeting/);
+ assert.doesNotMatch(page.show('chain'), /Header/);
+ assert.ok(side.includes(`data-root="${standalone.repo}"`), 'the repo without a project stands alone');
+ } finally {
+ await view.stop();
+ }
+});
+
test('the tabs fit one row on a phone [N26]', async () => {
const view = await startView(machine());
try {