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(view): the lifecycle as the README draws it, closable [M1,N26]
Corey Olson3462c79df620
diff --git a/src/cockpit.js b/src/cockpit.jsindex d4f16a38..f7fa9990 100644--- a/src/cockpit.js+++ b/src/cockpit.js@@ -111,7 +111,8 @@ export function cockpitPage(key = '') {<aside class="card-panel detail" aria-label="Practice row"><div id="doctrine-detail"></div></aside></section><section data-pane="activity">- <figure class="card-panel flow"><div id="flow"></div><figcaption>The lifecycle every item follows, as pullboard declares it. Boxes count the items in each state now, arrows the moves made so far; hover over one for what it means and checks.</figcaption></figure>+ <figure class="card-panel flow" id="flow-panel"><button class="flow-hide" id="flow-hide" type="button" title="Hide the lifecycle" aria-label="Hide the lifecycle">×</button><div id="flow"></div><figcaption>The lifecycle every item follows, as pullboard declares it. Boxes count the items in each state now, labels the moves made along each route, and ↻ the moves that keep an item where it is; hover over one for what it means and checks.</figcaption></figure>+ <button class="ghost flow-show" id="flow-show" type="button" hidden>Show the lifecycle</button><div class="card-panel feed" id="activity"></div></section></main>@@ -248,11 +249,14 @@ function timeline(item) {}/**- * The lifecycle drawn as SVG with this board's counts. The longest way from the start to a final- * state runs along a row, the first-declared final winning a tie, and any other state sits below,- * under the states that lead to it. One arrow joins each pair of states some move joins: forward- * along the row, arcing above it back to an earlier state, down to a state below, or looping at the- * corner of a box it stays in. Boxes count the items there now; arrows count the moves made along them.+ * The lifecycle drawn as SVG with this board's counts, the way the README's figure draws it. The+ * longest way from the start to a final state runs along a row, the first-declared final winning a+ * tie, its states joined by straight arrows. A pair of states a move leads back along takes a dashed+ * square route above the row, the further back the higher. The moves that keep a state are written+ * in its box after a ↻. A state off the row sits below the last state on the row that leads to it,+ * and the routes into it join into one, labelled once. Final states have a double border. Boxes+ * count the items there now; labels count the moves made along each route, or name its moves when+ * none was. Words are wrapped and placed by a generous estimate of their width, so none overlaps.*/function flowSvg(p) {const counts = moveCounts(p.items);@@ -268,14 +272,7 @@ function flowSvg(p) {for (const next of new Set(leads(at))) if (!trail.includes(next)) walk([...trail, next]);};walk([FLOW.initial]);- const W = 800, L = 44, BW = 116, BH = 56, Y = 136;- const step = (W - 2 * L - BW) / Math.max(row.length - 1, 1);- const pos = new Map(row.map((s, i) => [s, { x: L + BW / 2 + i * step, y: Y }]));- for (const s of FLOW.states.filter((s) => !pos.has(s.id))) {- const from = row.filter((r) => leads(r).includes(s.id));- pos.set(s.id, { x: from.length ? from.reduce((n, r) => n + pos.get(r).x, 0) / from.length : W / 2, y: Y + 150 });- }- const H = Math.max(...[...pos.values()].map((q) => q.y)) + BH / 2 + 20;+ const W = 880, L = 20, BW = 160, step = (W - 2 * L - BW) / Math.max(row.length - 1, 1);const f = (v) => String(Math.round(v * 10) / 10);const col = (s) => row.indexOf(s);const pairs = [];@@ -286,48 +283,112 @@ function flowSvg(p) {}const made = (pair, m) => counts.get(pair.from + '>' + pair.to + ':' + m.verb) || 0;const says = (pair) => pair.moves.map((m) => m.verb + ', ' + pair.from + ' to ' + pair.to + ', by the ' + m.by.join(' or ') + ': ' + m.how + '. Made ' + count(made(pair, m), 'time', 'times') + (m.checks.length ? '.\\nChecks, in order:\\n' + m.checks.map((c) => ' ' + c).join('\\n') : '.')).join('\\n\\n');- const text = (x, y, words, cls, anchor = 'middle') => '<text class="' + cls + '" x="' + f(x) + '" y="' + f(y) + '" text-anchor="' + anchor + '">' + esc(words) + '</text>';- const arrows = pairs.map((pair) => {- const a = pos.get(pair.from), b = pos.get(pair.to);- const done = pair.moves.filter((m) => made(pair, m));- const words = (done.length ? done.map((m) => m.verb + ' ' + made(pair, m)) : pair.moves.map((m) => m.verb)).join(' · ');- const tone = pair.moves.some((m) => m.verb === 'reject') ? ' no' : '';- const cls = 'tag' + (done.length ? '' : ' idle') + tone;- let d, label = '';- if (pair.from === pair.to) {- // A move that stays: a loop out of the box's bottom edge and back into its left side.- const sx = a.x - BW / 2 + 26, sy = a.y + BH / 2, ex = a.x - BW / 2, ey = a.y + BH / 2 - 16;- d = 'M' + f(sx) + ' ' + f(sy) + 'C' + f(sx) + ' ' + f(sy + 28) + ' ' + f(ex - 28) + ' ' + f(ey) + ' ' + f(ex) + ' ' + f(ey);- label = text(a.x - BW / 2 - 18, a.y + BH / 2 + 34, words, cls, 'start');- } else if (col(pair.from) >= 0 && col(pair.to) > col(pair.from)) {- d = 'M' + f(a.x + BW / 2) + ' ' + f(a.y) + 'L' + f(b.x - BW / 2) + ' ' + f(b.y);- label = text((a.x + b.x) / 2, a.y - 9, words, cls);- } else if (col(pair.from) >= 0 && col(pair.to) >= 0) {- // Back along the row: an arc above it, higher the further back it goes.- const span = col(pair.from) - col(pair.to), sx = a.x - 16 * span, ex = b.x + 16 * span, top = a.y - BH / 2, cy = top - 36 * span - 8;- d = 'M' + f(sx) + ' ' + f(top) + 'C' + f(sx) + ' ' + f(cy) + ' ' + f(ex) + ' ' + f(cy) + ' ' + f(ex) + ' ' + f(top);- label = text((sx + ex) / 2, (top + 3 * cy) / 4 - 7, words, cls);- } else {- // Down to a state off the row: the arrows spread across its top, each labelled along its way,- // on the side away from the others.- const sy = a.y + BH / 2, ex = b.x + (a.x - b.x) * 0.3, ey = b.y - BH / 2;- d = 'M' + f(a.x) + ' ' + f(sy) + 'L' + f(ex) + ' ' + f(ey);- const lx = a.x + (ex - a.x) * 0.6, ly = sy + (ey - sy) * 0.6 + 4;- // A straight drop, its ends equal but for rounding, keeps its label on the right.- label = a.x < b.x - 0.5 ? text(lx - 6, ly, words, cls, 'end') : text(lx + 6, ly, words, cls, 'start');+ // What some pairs' moves come to: each verb with how often it was made, or every verb when none was.+ const told = (list) => {+ const sums = new Map();+ for (const pair of list) for (const m of pair.moves) sums.set(m.verb, (sums.get(m.verb) || 0) + made(pair, m));+ const done = [...sums].filter(([, n]) => n);+ return { words: done.length ? done.map(([verb, n]) => verb + ' ' + n) : [...sums.keys()], idle: !done.length };+ };+ // A generous width for words at a size, and words joined by dots into the fewest even lines that+ // fit a room, as the README's figure splits them.+ const wide = (words, size) => words.length * size * 0.56;+ const wrap = (words, room, size) => {+ for (let n = 1; ; n += 1) {+ const per = Math.ceil(words.length / n), lines = [];+ for (let i = 0; i < words.length; i += per) lines.push(words.slice(i, i + per).join(' · '));+ if (per === 1 || lines.every((line) => wide(line, size) <= room)) return lines;}- return '<g><title>' + esc(says(pair)) + '</title><path class="edge' + tone + '" d="' + d + '" marker-end="url(#pb-head' + (tone ? '-no' : '') + ')"/>' + label + '</g>';- });+ };+ const text = (x, y, words, cls, anchor = 'middle') => '<text class="' + cls + '" x="' + f(x) + '" y="' + f(y) + '" text-anchor="' + anchor + '">' + esc(words) + '</text>';+ const lines = (x, y, said, cls, anchor) => said.map((line, i) => text(x, y - 15 * (said.length - 1 - i), line, cls, anchor)).join('');+ const path = (points) => 'M' + points.map(([x, y]) => f(x) + ' ' + f(y)).join('L');++ // Inside each box: its name and count, then the moves that keep it, then any items sent back.const back = p.items.filter((i) => stateOf(i) === 'back').length;+ const inside = new Map(FLOW.states.map((s) => {+ const keeps = pairs.find((pair) => pair.from === s.id && pair.to === s.id);+ const said = keeps ? told([keeps]) : null;+ const kept = said ? wrap(said.words, BW - 28 - wide('↻ ', 11), 11).map((line, i) => (i ? ' ' : '↻ ') + line) : [];+ return [s.id, { keeps, said, kept, back: s.id === FLOW.initial && back ? back + ' sent back' : '' }];+ }));+ const BH = 44 + 15 * Math.max(1, ...[...inside.values()].map((box) => box.kept.length + (box.back ? 1 : 0)));++ // Routes back along the row, each at a level by how far back it goes; their words above them.+ const ups = pairs.filter((pair) => pair.from !== pair.to && col(pair.from) >= 0 && col(pair.to) >= 0 && col(pair.to) !== col(pair.from) + 1)+ .map((pair) => ({ pair, span: Math.abs(col(pair.from) - col(pair.to)) })).sort((a, b) => a.span - b.span);+ const spans = [...new Set(ups.map((up) => up.span))];+ for (const up of ups) {+ up.level = spans.indexOf(up.span);+ const a = L + BW / 2 + col(up.pair.from) * step, b = L + BW / 2 + col(up.pair.to) * step;+ const before = (key, value) => ups.filter((other) => other !== up && other.pair[key] === value && other.span < up.span).length;+ up.start = a + (a > b ? 16 : -16) + (a > b ? 26 : -26) * before('from', up.pair.from);+ up.end = b + (a > b ? BW / 2 - 40 : 40 - BW / 2) + (a > b ? -30 : 30) * before('to', up.pair.to);+ up.said = told([up.pair]);+ up.lines = wrap(up.said.words, Math.abs(up.start - up.end) - 20, 12);+ }+ // Each level stands clear of the words of the level below it.+ const rise = [];+ for (const level of spans.keys()) {+ const below = ups.filter((up) => up.level === level - 1);+ rise[level] = level ? rise[level - 1] + 18 + 15 * Math.max(...below.map((up) => up.lines.length)) : 30;+ }+ const highest = ups.length ? Math.max(...ups.map((up) => rise[up.level] + 21 + 15 * (up.lines.length - 1))) : 0;+ const top = 12 + highest, Y = top + BH / 2, bottom = top + BH;+ const pos = new Map(row.map((s, i) => [s, { x: L + BW / 2 + i * step, y: Y }]));++ // A state off the row sits below the last state on it that leads there.+ const below = FLOW.states.filter((s) => !pos.has(s.id));+ for (const s of below) {+ const from = row.filter((r) => leads(r).includes(s.id));+ pos.set(s.id, { x: from.length ? pos.get(from[from.length - 1]).x : W / 2, y: bottom + 80 + BH / 2 });+ }+ const H = (below.length ? bottom + 80 + BH : bottom) + 14;++ const group = (pairList, route, label) => pairList.map((pair, n) => '<g><title>' + esc(says(pair)) + '</title><path class="edge' + (route.back ? ' back' : '') + '" d="' + route.d + '" marker-end="url(#pb-head' + (route.back ? '-back' : '') + ')"/>' + (n === 0 ? label : '') + '</g>').join('');+ const tone = (said, extra = '') => 'tag' + (said.idle ? ' idle' : '') + extra;+ const routes = [];+ // Straight along the row.+ for (const pair of pairs.filter((pair) => col(pair.from) >= 0 && col(pair.to) === col(pair.from) + 1)) {+ const a = pos.get(pair.from), b = pos.get(pair.to), said = told([pair]);+ routes.push(group([pair], { d: path([[a.x + BW / 2, Y], [b.x - BW / 2 - 1, Y]]) }, text((a.x + b.x) / 2, Y - 8, said.words.join(' · '), tone(said))));+ }+ // Square, above the row.+ for (const up of ups) {+ const isBack = col(up.pair.to) < col(up.pair.from), y = top - rise[up.level];+ routes.push(group([up.pair], { back: isBack, d: path([[up.start, top], [up.start, y], [up.end, y], [up.end, top - 1]]) }, lines((up.start + up.end) / 2, y - 7, up.lines, tone(up.said, isBack ? ' back' : ''))));+ }+ // Down from the row, joining into one route per state below, labelled once on the way in.+ for (const s of below) {+ const t = pos.get(s.id), into = pairs.filter((pair) => pair.to === s.id && pos.has(pair.from) && pair.from !== s.id);+ const said = told(into), tTop = t.y - BH / 2;+ const xs = into.map((pair) => pos.get(pair.from).x).sort((a, b) => a - b);+ const left = xs.filter((x) => x < t.x - 0.5), right = xs.filter((x) => x > t.x + 0.5);+ const label = left.length+ ? lines((left[0] + (left[1] ?? t.x - BW / 2)) / 2, t.y - 8, wrap(said.words, (left[1] ?? t.x - BW / 2) - left[0] - 20, 12), tone(said))+ : right.length+ ? lines((right[right.length - 1] + (right[right.length - 2] ?? t.x + BW / 2)) / 2, t.y - 8, wrap(said.words, right[right.length - 1] - (right[right.length - 2] ?? t.x + BW / 2) - 20, 12), tone(said))+ : lines(t.x + 10, (bottom + tTop) / 2 + 4, said.words, tone(said), 'start');+ // The label goes with the route that reaches furthest, drawn first; the others join it.+ const order = [...into].sort((p1, p2) => Math.abs(pos.get(p2.from).x - t.x) - Math.abs(pos.get(p1.from).x - t.x));+ order.forEach((pair, n) => {+ const a = pos.get(pair.from);+ const d = Math.abs(a.x - t.x) < 0.5 ? path([[a.x, bottom], [t.x, tTop - 1]]) : path([[a.x, bottom], [a.x, t.y], [a.x < t.x ? t.x - BW / 2 - 1 : t.x + BW / 2 + 1, t.y]]);+ routes.push(group([pair], { d }, n === 0 ? label : ''));+ });+ }+const boxes = FLOW.states.map((s) => {- const { x, y } = pos.get(s.id);+ const { x, y } = pos.get(s.id), box = inside.get(s.id), left = x - BW / 2, boxTop = y - BH / 2;const tip = s.id + ': ' + s.means + (s.entry.length ? '.\\nEvery way in checks:\\n' + s.entry.map((r) => ' ' + r).join('\\n') : '.');- return '<g class="s-' + esc(s.id) + '"><title>' + esc(tip) + '</title><rect class="box" x="' + f(x - BW / 2) + '" y="' + f(y - BH / 2) + '" width="' + BW + '" height="' + BH + '" rx="10"/>'- + text(x - BW / 2 + 12, y - 9, s.id, 'name', 'start') + text(x - BW / 2 + 12, y + 18, String(p.items.filter((i) => i.status === s.id).length), 'n', 'start')- + (s.id === FLOW.initial && back ? text(x + BW / 2 - 10, y + 17, back + ' sent back', 'sub', 'end') : '') + '</g>';+ const keeps = box.kept.length ? '<g><title>' + esc(says(box.keeps)) + '</title>' + box.kept.map((line, i) => text(left + 14, boxTop + 47 + 15 * i, line, 'keep' + (box.said.idle ? ' idle' : ''), 'start')).join('') + '</g>' : '';+ return '<g class="s-' + esc(s.id) + '"><title>' + esc(tip) + '</title><rect class="box" x="' + f(left) + '" y="' + f(boxTop) + '" width="' + BW + '" height="' + BH + '" rx="10"/>'+ + (s.final ? '<rect class="box inner" x="' + f(left + 4) + '" y="' + f(boxTop + 4) + '" width="' + (BW - 8) + '" height="' + (BH - 8) + '" rx="7"/>' : '')+ + text(left + 14, boxTop + 25, s.id, 'name', 'start') + text(x + BW / 2 - 14, boxTop + 29, String(p.items.filter((i) => i.status === s.id).length), 'n', 'end')+ + keeps + (box.back ? text(left + 14, boxTop + 47 + 15 * box.kept.length, box.back, 'sub', 'start') : '') + '</g>';});const head = (id, cls) => '<marker id="' + id + '" class="' + cls + '" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10z"/></marker>';- return '<svg viewBox="0 0 ' + W + ' ' + f(H) + '" role="img" aria-label="The item lifecycle, with counts from this board"><defs>' + head('pb-head', '') + head('pb-head-no', 'no') + '</defs>' + arrows.join('') + boxes.join('') + '</svg>';+ return '<svg viewBox="0 0 ' + W + ' ' + f(H) + '" role="img" aria-label="The item lifecycle, with counts from this board"><defs>' + head('pb-head', '') + head('pb-head-back', 'back') + '</defs>' + routes.join('') + boxes.join('') + '</svg>';}async function api(path, body) {@@ -530,11 +591,23 @@ function render() {$(kind + '-detail').innerHTML = row ? '<div class="stack tight"><h2><span>' + esc(row.id) + '</span>' + esc(row.text) + '</h2><div class="meta"><span class="chip ' + tone(row.status) + '">' + esc(row.status) + '</span>' + (row.tier ? '<span class="chip">' + esc(row.tier) + '</span>' : '') + '</div><dl class="kv"><dt>section</dt><dd>' + esc(row.section) + '</dd>' + (row.gate ? '<dt>gate</dt><dd>' + esc(row.gate) + '</dd>' : '') + (row.serves && row.serves.length ? '<dt>serves</dt><dd>' + esc(row.serves.join(', ')) + '</dd>' : '') + '</dl><div><h3>Items that cite it</h3>' + (citing.length ? '<div class="links">' + citing.map((i) => '<button data-go="item:' + i.id + '" type="button">#' + i.id + ' ' + esc(i.title) + '</button>').join('') + '</div>' : '<div class="muted">None yet.</div>') + '</div><div class="muted">Rows change in ' + (kind === 'spec' ? 'SPEC.md' : 'PRACTICE.md') + ', and only you approve them.</div></div>' : '<div class="empty">Pick a row to see it, and the items that cite it.</div>';}- $('flow').innerHTML = flowSvg(p);+ if (keep('pb.flow') !== 'hidden') $('flow').innerHTML = flowSvg(p);$('activity').innerHTML = p.events.length ? byDay(p.events, (e) => e.event_at, (e) => '<div><time>' + clock(e.event_at) + '</time><div class="act"><b>' + esc(e.event_by) + '</b> ' + esc(e.event_kind) + (e.item_id ? ' <button class="ref" data-go="item:' + e.item_id + '" type="button">#' + e.item_id + '</button>' + (titles.has(String(e.item_id)) ? ' <span class="what">' + esc(titles.get(String(e.item_id))) + '</span>' : '') : '') + '</div></div>') : '<div class="empty">No activity yet.</div>';showTab();}+/**+ * Show or hide the lifecycle on Activity, and keep the choice: a person who closed it has learned+ * it, so it stays closed across reloads, and across restarts of the view, which serves from the+ * same address again, until they open it. While hidden it is not drawn.+ */+function showFlow(shown) {+ keep('pb.flow', shown ? 'shown' : 'hidden');+ $('flow-panel').hidden = !shown;+ $('flow-show').hidden = shown;+ if (shown && data && data.project) $('flow').innerHTML = flowSvg(data.project);+}+function showTab() {document.querySelectorAll('[data-pane]').forEach((pane) => { pane.hidden = pane.dataset.pane !== view.tab; });document.querySelectorAll('.tab').forEach((button) => button.classList.toggle('on', button.dataset.tab === view.tab));@@ -719,6 +792,10 @@ document.addEventListener('click', (event) => {$('new-item').addEventListener('click', () => { view.adding = true; render(); $('add-title').focus(); });$('add-cancel').addEventListener('click', () => { view.adding = false; render(); });$('answer-cancel').addEventListener('click', () => answer(null));+$('flow-hide').addEventListener('click', () => showFlow(false));+$('flow-show').addEventListener('click', () => showFlow(true));+$('flow-panel').hidden = keep('pb.flow') === 'hidden';+$('flow-show').hidden = !$('flow-panel').hidden;// Each press moves on one, from the system's theme to light, then dark, and back; this browser keeps it.$('theme').addEventListener('click', () => {const next = { light: 'dark', dark: 'system' }[document.documentElement.dataset.theme] || 'light';diff --git a/src/serve.js b/src/serve.jsindex 845b0bc1..e27392ef 100644--- a/src/serve.js+++ b/src/serve.js@@ -9,16 +9,16 @@*/import { spawn, spawnSync } from 'node:child_process';import { randomBytes, timingSafeEqual } from 'node:crypto';-import { readFileSync } from 'node:fs';+import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';import { createServer } from 'node:http';-import { join } from 'node:path';+import { dirname, join } from 'node:path';import { fileURLToPath } from 'node:url';import * as store from './board.js';import { cockpitPage } from './cockpit.js';import { COORDINATOR, loadConfig } from './config.js';import { repoInfo, resolveCommit } from './git.js';import { productSummaries } from './products.js';-import { listProjects } from './projects.js';+import { listProjects, registryFile } from './projects.js';import { Refused } from './refused.js';import { loadSpec } from './spec.js';@@ -27,6 +27,39 @@ const BIN = fileURLToPath(new URL('../bin/pullboard.js', import.meta.url));const VIEW_CSS = readFileSync(new URL('./view.css', import.meta.url), 'utf8');export const LOOPBACK = '127.0.0.1';+/** Where the view keeps the port it last served from, beside the machine's list of projects. */+const lastPortFile = () => join(dirname(registryFile()), 'view.json');++/**+ * The port the view last served from, or 0 when it has none to offer. A browser keeps what the page+ * stores per address, port included, so serving from the same port again is what lets the person's+ * choices, such as a hidden figure or a theme, outlive a restart.+ *+ * @returns {number}+ */+export function lastPort() {+ try {+ const port = JSON.parse(readFileSync(lastPortFile(), 'utf8')).port;+ return Number.isInteger(port) && port >= 1024 && port <= 65535 ? port : 0;+ } catch {+ return 0;+ }+}++/**+ * Remember the port the view serves from. Failing to is no reason to stop serving, so it never throws.+ *+ * @param {number} port+ */+function rememberPort(port) {+ try {+ mkdirSync(dirname(lastPortFile()), { recursive: true });+ writeFileSync(lastPortFile(), `${JSON.stringify({ port })}\n`);+ } catch {+ // The next start picks a free port instead.+ }+}+/*** Open a project's board, read from it, and always close it.*@@ -296,15 +329,25 @@ export function serveView({ port = 0, secret = randomBytes(18).toString('base64ureturn json(res, 500, { error: error.message });}});+ // Asked for any port, the view tries the one it last served from first, and takes any free one+ // when that is busy; a port the person names is used as named.+ const asked = port;+ const last = asked === 0 ? lastPort() : 0;return new Promise((ready, fail) => {- server.once('error', fail);- server.listen(port, LOOPBACK, () => {- bound = /** @type {any} */ (server.address()).port;- ready({- url: `http://${LOOPBACK}:${bound}/?k=${secret}`,- port: bound,- close: () => new Promise((closed) => server.close(() => closed())),+ const listen = (port) => {+ const failed = (error) => (port !== 0 && port === last && error.code === 'EADDRINUSE' ? listen(0) : fail(error));+ server.once('error', failed);+ server.listen(port, LOOPBACK, () => {+ server.off('error', failed);+ bound = /** @type {any} */ (server.address()).port;+ if (asked === 0) rememberPort(bound);+ ready({+ url: `http://${LOOPBACK}:${bound}/?k=${secret}`,+ port: bound,+ close: () => new Promise((closed) => server.close(() => closed())),+ });});- });+ };+ listen(last || asked);});}diff --git a/src/view.css b/src/view.cssindex 7a8ec69f..ccc31a98 100644--- a/src/view.css+++ b/src/view.css@@ -232,20 +232,24 @@ input:disabled { background: var(--surface-2); color: var(--ink-muted); }.srow.on { background: var(--accent-soft); }.srow code { font: 600 12px var(--mono); }@media (width < 480px) { .srow { grid-template-columns: auto minmax(0, 1fr); } .srow > span:last-child { grid-column: 1 / -1; } }-.flow { margin: 0 0 12px; padding: 10px 12px 8px; overflow-x: auto; }-.flow svg { display: block; width: 100%; min-width: 680px; max-width: 900px; height: auto; margin: 0 auto; }-.flow figcaption { color: var(--ink-faint); font-size: 12px; padding: 2px 2px 0; }-.flow .box { fill: var(--surface); stroke: var(--line-strong); stroke-width: 1.3; }-.flow .s-claimed .box { stroke: var(--blue); } .flow .s-submitted .box { stroke: var(--warn); }-.flow .s-verified .box { stroke: var(--accent); fill: var(--accent-soft); } .flow .s-withdrawn .box { stroke-dasharray: 4 3; }+.flow { position: relative; margin: 0 0 12px; padding: 10px 12px 8px; overflow-x: auto; }+.flow svg { display: block; width: 100%; min-width: 680px; max-width: 920px; height: auto; margin: 0 auto; }+.flow figcaption { color: var(--ink-faint); font-size: 12px; padding: 2px 34px 0 2px; }+.flow-hide { position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border: 0; border-radius: 8px; background: none; color: var(--ink-faint); font: 18px/1 var(--sans); cursor: pointer; }+.flow-hide:hover { background: var(--surface-2); color: var(--ink); }+.flow-show { margin: 0 0 12px; }+.flow .box { fill: var(--surface-2); stroke: var(--line-strong); stroke-width: 1.2; }+.flow .box.inner { fill: none; }+.flow .s-verified .box { fill: var(--accent-soft); stroke: var(--accent); } .flow .s-verified .box.inner { fill: none; }.flow .name { font: 600 11px var(--mono); letter-spacing: .06em; fill: var(--ink-faint); }.flow .n { font: 800 22px var(--sans); fill: var(--ink); }-.flow .sub { font: 12px var(--sans); fill: var(--reject); }+.flow .keep { font: 11px var(--sans); fill: var(--ink-muted); } .flow .keep.idle { fill: var(--ink-faint); }+.flow .sub { font: 11px var(--sans); fill: var(--reject); }.flow .edge { fill: none; stroke: var(--line-strong); stroke-width: 1.4; }-.flow .edge.no { stroke: var(--reject); }-.flow marker path { fill: var(--line-strong); } .flow marker.no path { fill: var(--reject); }-.flow .tag { font: 12px var(--sans); fill: var(--ink-muted); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }-.flow .tag.idle { fill: var(--ink-faint); } .flow .tag.no { fill: var(--reject); }-.flow g:hover .box, .flow g:hover .edge { stroke-width: 2.4; }+.flow .edge.back { stroke: var(--reject); stroke-dasharray: 5 4; }+.flow marker path { fill: var(--line-strong); } .flow marker.back path { fill: var(--reject); }+.flow .tag { font: 12px var(--sans); fill: var(--ink-muted); }+.flow .tag.idle { fill: var(--ink-faint); } .flow .tag.back { fill: var(--reject); }+.flow g:hover > .box, .flow g:hover > .edge { stroke-width: 2.2; }.console { position: fixed; right: 16px; bottom: 16px; width: min(560px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow); padding: 10px 12px; font: 12px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 38vh; overflow: auto; z-index: 20; cursor: pointer; }.console.ok { border-color: var(--accent); } .console.no { border-color: var(--reject); }diff --git a/test/cockpit.test.js b/test/cockpit.test.jsindex 9469e80a..96c47627 100644--- a/test/cockpit.test.js+++ b/test/cockpit.test.js@@ -7,7 +7,7 @@import assert from 'node:assert/strict';import { execFileSync, spawn, spawnSync } from 'node:child_process';import { chmodSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';-import { request } from 'node:http';+import { createServer, request } from 'node:http';import { tmpdir } from 'node:os';import { join, resolve } from 'node:path';import { after, test } from 'node:test';@@ -735,22 +735,48 @@ test('each row says what it waits on [N26]', async () => {}});/**- * The lifecycle drawing: each box's state, count and title; each arrow's title, the pair of states- * its title starts with, and the label drawn with it, if any.+ * The lifecycle drawing: each box's state, title, count, the moves that keep it and whether it has a+ * second border; each route's title, the pair of states its title starts with, its class, its+ * points, and the words drawn with it, if any; and what the box of the first state says came back.*/function drawing(svg) {return {- boxes: [...svg.matchAll(/<g class="s-([^"]+)"><title>([^<]*)<\/title>[^]*?<text class="n"[^>]*>(\d+)<\/text>/g)].map((match) => ({ state: match[1], title: match[2], count: Number(match[3]) })),- arrows: [...svg.matchAll(/<g><title>([^<]*)<\/title><path class="edge[^"]*"[^>]*\/>(?:<text class="tag([^"]*)"[^>]*>([^<]*)<\/text>)?<\/g>/g)].map((match) => ({+ boxes: [...svg.matchAll(/<g class="s-([^"]+)"><title>([^<]*)<\/title>([^]*?)<\/g>(?=<g class="s-|<\/svg>)/g)].map((match) => ({+ state: match[1],+ title: match[2],+ count: Number(/<text class="n"[^>]*>(\d+)<\/text>/.exec(match[3])[1]),+ keeps: [...match[3].matchAll(/<text class="keep( idle)?"[^>]*>([^<]*)<\/text>/g)].map((line) => line[2].trim()).join(' ') + (/class="keep idle"/.test(match[3]) ? ' (none yet)' : ''),+ double: match[3].includes('<rect class="box inner"'),+ })),+ routes: [...svg.matchAll(/<g><title>([^<]*)<\/title><path class="edge([^"]*)" d="([^"]*)"[^>]*\/>((?:<text class="tag[^"]*"[^>]*>[^<]*<\/text>)*)<\/g>/g)].map((match) => ({title: match[1],pair: /^\w+, (\w+) to (\w+),/.exec(match[1]).slice(1).join('>'),- label: match[3] === undefined ? null : match[3] + (match[2].includes('idle') ? ' (none yet)' : ''),+ back: match[2] === ' back',+ points: [...match[3].matchAll(/([\d.]+) ([\d.]+)/g)].map((point) => [Number(point[1]), Number(point[2])]),+ label: match[4] ? [...match[4].matchAll(/>([^<]*)<\/text>/g)].map((line) => line[1]).join(' · ') + (match[4].includes(' idle') ? ' (none yet)' : '') : null,})),sentBack: /<text class="sub"[^>]*>([^<]*)<\/text>/.exec(svg)?.[1],};}-test('the activity tab draws the lifecycle from the declaration, with live counts [N26]', async () => {+/**+ * Where each piece of text in a drawing sits: its words, and a box from a little above its baseline+ * to a little below, as wide as the widest a font is likely to set it at the size its class gives.+ */+function textBoxes(svg) {+ const sizes = { tag: [12, 0.58], keep: [11, 0.58], sub: [11, 0.58], name: [11, 0.7], n: [22, 0.64] };+ return [...svg.matchAll(/<text class="([^"]+)" x="([\d.-]+)" y="([\d.-]+)" text-anchor="(start|middle|end)">([^<]*)<\/text>/g)].map(([, cls, x, y, anchor, words]) => {+ const [size, per] = sizes[cls.split(' ')[0]];+ const width = words.replace(/&[a-z#0-9]+;/g, '&').length * size * per;+ const left = anchor === 'start' ? Number(x) : anchor === 'end' ? Number(x) - width : Number(x) - width / 2;+ return { words, inside: cls !== 'tag' && !cls.startsWith('tag '), left, right: left + width, top: Number(y) - size * 0.8, bottom: Number(y) + size * 0.25 };+ });+}++/** Whether two boxes, each with left, right, top and bottom, come within a gap of each other. */+const meet = (a, b, gap = 0) => a.left - gap < b.right && b.left - gap < a.right && a.top - gap < b.bottom && b.top - gap < a.bottom;++test('the activity tab draws the lifecycle from the declaration, as the README does, with live counts [N26, M1]', async () => {const box = machine();const alpha = project(box, 'alpha');for (const title of ['Greeting', 'Farewell', 'Header', 'Footer', 'Sidebar', 'Banner', 'Menu', 'Search']) box.run(alpha.repo, 'add', 'web', title, '--specs', 'G1', '--criterion', 'renders');@@ -758,7 +784,7 @@ test('the activity tab draws the lifecycle from the declaration, with live countaccept(box, alpha, 1);build(box, alpha, 2, 'farewell.html');sendBack(box, alpha, 2, 'no farewell');- // Withdrawn from claimed twice, from submitted once and from open once, so each arrow has its count.+ // Withdrawn from claimed twice, from submitted once and from open once, so each route has its count.for (const id of ['6', '8']) {box.run(alpha.web, 'claim', id);box.run(alpha.repo, 'withdraw', id, 'not this release');@@ -773,7 +799,8 @@ test('the activity tab draws the lifecycle from the declaration, with live countconst page = await openPage(view);assert.doesNotMatch(page.html, /id="metrics"/, 'the drawing replaces the metric cards');assert.ok(!page.html.includes('pullboard claim <id>'), 'the declaration is embedded with < escaped');- const { boxes, arrows, sentBack } = drawing(page.show('flow'));+ const svg = page.show('flow');+ const { boxes, routes, sentBack } = drawing(svg);const esc = (text) => text.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", ''');assert.deepEqual(boxes.map((entry) => entry.state), MACHINE.states.map((state) => state.id), 'a box for every declared state');@@ -781,26 +808,55 @@ test('the activity tab draws the lifecycle from the declaration, with live countassert.match(boxes.find((entry) => entry.state === 'verified').title, /Every way in checks:\n {2}the caller's checkout contains the submitted commit\n {2}the caller did not build it/);assert.deepEqual(Object.fromEntries(boxes.map((entry) => [entry.state, entry.count])), { open: 2, claimed: 1, submitted: 0, verified: 1, withdrawn: 4 });assert.equal(sentBack, '1 sent back');+ assert.deepEqual(boxes.filter((entry) => entry.double).map((entry) => entry.state), MACHINE.states.filter((state) => state.final).map((state) => state.id), 'a final state has a double border');++ // The moves that keep a state are written in its box, not drawn as loops.+ const keeping = MACHINE.states.filter((state) => MACHINE.moves.some((move) => move.to === state.id && move.from.includes(state.id))).map((state) => state.id);+ assert.deepEqual(Object.fromEntries(boxes.filter((entry) => entry.keeps).map((entry) => [entry.state, entry.keeps])), {+ open: '↻ escalate · refreeze (none yet)',+ claimed: '↻ claim 1',+ submitted: '↻ reserve (none yet)',+ });+ assert.deepEqual(boxes.filter((entry) => entry.keeps).map((entry) => entry.state), keeping, 'each state a move keeps');- const pairs = new Set(MACHINE.moves.flatMap((move) => move.from.map((from) => `${from}>${move.to}`)));- assert.deepEqual(arrows.map((arrow) => arrow.pair).sort(), [...pairs].sort(), 'one arrow per pair of states a move joins');+ const pairs = new Set(MACHINE.moves.flatMap((move) => move.from.filter((from) => from !== move.to).map((from) => `${from}>${move.to}`)));+ assert.deepEqual(routes.map((route) => route.pair).sort(), [...pairs].sort(), 'one route per pair of states a move joins');for (const move of MACHINE.moves) {- for (const from of move.from) assert.ok(arrows.find((arrow) => arrow.pair === `${from}>${move.to}`).title.includes(`${move.verb}, ${from} to ${move.to}, by the ${move.by.join(' or ')}: `), `${move.verb} from ${from} is on its arrow`);+ for (const from of move.from.filter((from) => from !== move.to)) assert.ok(routes.find((route) => route.pair === `${from}>${move.to}`).title.includes(`${move.verb}, ${from} to ${move.to}, by the ${move.by.join(' or ')}: `), `${move.verb} from ${from} is on its route`);}- assert.ok(arrows.some((arrow) => arrow.title.includes('claim, open to claimed, by the agent or coordinator: pullboard claim <id>. Made 6 times.\nChecks, in order:\n the caller is the main checkout, or a worktree that joined a lane (NOT_JOINED)\n the item exists (NO_ITEM)\n the item is open or claimed (NOT_CLAIMABLE)')), 'each check in order, escaped');- // Every arrow carries its own label: the moves made along it and how often, or its moves when none was.- assert.deepEqual(Object.fromEntries(arrows.map((arrow) => [arrow.pair, arrow.label])), {+ assert.ok(routes.some((route) => route.title.includes('claim, open to claimed, by the agent or coordinator: pullboard claim <id>. Made 6 times.\nChecks, in order:\n the caller is the main checkout, or a worktree that joined a lane (NOT_JOINED)\n the item exists (NO_ITEM)\n the item is open or claimed (NOT_CLAIMABLE)')), 'each check in order, escaped');+ // The moves made along a route and how often, or its moves when none was; the routes into the+ // state below the row join into one, labelled once with their total.+ assert.deepEqual(Object.fromEntries(routes.map((route) => [route.pair, route.label])), {'open>claimed': 'claim 6',- 'claimed>claimed': 'claim 1','claimed>open': 'release · lapse · escalate · refreeze (none yet)','claimed>submitted': 'submit 3',- 'submitted>submitted': 'reserve (none yet)','submitted>verified': 'accept 1','submitted>open': 'reject 1',- 'open>open': 'escalate · refreeze (none yet)',- 'open>withdrawn': 'withdraw 1',- 'claimed>withdrawn': 'withdraw 2',- 'submitted>withdrawn': 'withdraw 1',+ 'open>withdrawn': 'withdraw 4',+ 'claimed>withdrawn': null,+ 'submitted>withdrawn': null,+ });++ // Every route is square, and the ones back to an earlier state are dashed, each at its own height.+ for (const route of routes) {+ route.points.slice(1).forEach(([x, y], n) => assert.ok(x === route.points[n][0] || y === route.points[n][1], `${route.pair} runs square: ${JSON.stringify(route.points)}`));+ }+ const backs = routes.filter((route) => route.back);+ assert.deepEqual(backs.map((route) => route.pair).sort(), ['claimed>open', 'submitted>open'], 'the routes back are the ones to an earlier state');+ assert.equal(new Set(backs.map((route) => route.points[1][1])).size, backs.length, 'each at its own height');+ assert.match(await styleOf(view), /\n\.flow \.edge\.back \{ stroke: var\(--reject\); stroke-dasharray: 5 4; \}/, 'dashed');++ // No word comes within two units of another, a box it is not in, or a route.+ const texts = textBoxes(svg);+ const rects = [...svg.matchAll(/<rect class="box" x="([\d.]+)" y="([\d.]+)" width="([\d.]+)" height="([\d.]+)"/g)].map(([, x, y, w, h]) => ({ left: Number(x), top: Number(y), right: Number(x) + Number(w), bottom: Number(y) + Number(h) }));+ const segments = routes.flatMap((route) => route.points.slice(1).map(([x, y], n) => ({ left: Math.min(x, route.points[n][0]), right: Math.max(x, route.points[n][0]) + 0.01, top: Math.min(y, route.points[n][1]), bottom: Math.max(y, route.points[n][1]) + 0.01 })));+ texts.forEach((one, n) => {+ for (const other of texts.slice(n + 1)) assert.ok(!meet(one, other, 2), `"${one.words}" and "${other.words}" overlap`);+ const home = rects.filter((rect) => meet(one, rect, one.inside ? 0 : 2));+ assert.deepEqual(home.length, one.inside ? 1 : 0, `"${one.words}" sits ${one.inside ? 'in its box' : 'clear of every box'}`);+ if (one.inside) assert.ok(one.left >= home[0].left && one.right <= home[0].right && one.top >= home[0].top && one.bottom <= home[0].bottom, `"${one.words}" fits inside its box`);+ for (const segment of segments) assert.ok(!meet(one, segment, 2), `"${one.words}" is clear of every route`);});// The clock's lapse is never logged: an item that reads open after its claim, and a claim logged@@ -814,6 +870,54 @@ test('the activity tab draws the lifecycle from the declaration, with live countawait view.stop();}});+test('a closed lifecycle stays closed, across a reload and a restart of the view [N26]', async () => {+ const box = machine();+ const alpha = project(box, 'alpha');+ box.run(alpha.repo, 'add', 'web', 'Greeting', '--specs', 'G1', '--criterion', 'greets');+ const first = await startView(box);+ const store = storage();+ let port;+ try {+ port = first.link.port;+ const page = await openPage(first, { store });+ await page.click({ tab: 'activity' });+ assert.match(page.show('flow'), /^<svg /, 'the figure shows at first');+ assert.deepEqual([page.element('flow-panel').hidden, page.element('flow-show').hidden], [false, true]);+ await page.fire('flow-hide', 'click');+ assert.deepEqual([page.element('flow-panel').hidden, page.element('flow-show').hidden], [true, false], 'closed, with a way to show it again');++ const reloaded = await openPage(first, { store });+ assert.deepEqual([reloaded.element('flow-panel').hidden, reloaded.element('flow-show').hidden], [true, false], 'a reload keeps it closed');+ assert.equal(reloaded.element('flow').writes, 0, 'and a closed figure is not drawn');+ } finally {+ await first.stop();+ }+ // The browser keeps the choice per address, so the view comes back on the port it last used.+ const second = await startView(box);+ try {+ assert.equal(second.link.port, port, 'a restarted view serves from the same port, where the browser kept the choice');+ const page = await openPage(second, { store });+ assert.equal(page.element('flow-panel').hidden, true, 'still closed');+ await page.fire('flow-show', 'click');+ assert.deepEqual([page.element('flow-panel').hidden, page.element('flow-show').hidden], [false, true], 'shown again on request');+ assert.match(page.show('flow'), /^<svg /, 'and drawn');+ assert.equal(store.getItem('pb.flow'), 'shown');+ } finally {+ await second.stop();+ }+ // With its last port taken, the view takes any free one rather than failing.+ const taken = await new Promise((done) => { const server = createServer(); server.listen(Number(port), '127.0.0.1', () => done(server)); });+ try {+ const third = await startView(box);+ try {+ assert.notEqual(third.link.port, port, 'a busy port is passed over');+ } finally {+ await third.stop();+ }+ } finally {+ await new Promise((done) => taken.close(done));+ }+});test('ages stay true while the board is quiet [N26]', async () => {const box = machine();const alpha = project(box, 'alpha');