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): lists say when older history is still loading [H5,N26]
Corey Olson29436e617b91
diff --git a/src/cockpit.js b/src/cockpit.jsindex 90d7eb93..6e5fe46e 100644--- a/src/cockpit.js+++ b/src/cockpit.js@@ -38,6 +38,7 @@ import { pageScriptPart1 } from './view/page-script-1.js';import { pageScriptPart2 } from './view/page-script-2.js';import { pageScriptPart3 } from './view/page-script-3.js';import { pageScriptPart4 } from './view/page-script-4.js';+import { historyLoadingScript } from './view/history-loading.js';/** The CLI's default phrases, ordered by depth for the existing prose inventory guard. */export const PULLBOARD_COMMANDS = Object.freeze(commandPhrases().sort((left, right) => right.split(' ').length - left.split(' ').length));@@ -1279,7 +1280,8 @@ function render() {// Opened from the status bar's unread, the feed is exactly those shouts, the ones after the mark the person had.const unread = view.unread?.root === view.root ? view.unread : null;const addressed = addressedShouts.get(JSON.stringify([view.root, view.shout]));- const feedShouts = addressed?.shout && !p.shouts.some((entry) => entry.shout_id === view.shout) ? [...p.shouts, addressed.shout] : p.shouts;+ const shownShouts = addressed?.shout && !p.shouts.some((entry) => entry.shout_id === view.shout) ? [...p.shouts, addressed.shout] : p.shouts;+ const feedShouts = [...shownShouts, ...olderShoutsOf(view.root, shownShouts)];const heard = unread ? feedShouts.filter((x) => x.shout_id > unread.after) : view.agent ? feedShouts.filter((x) => x.shout_from === view.agent || x.shout_to === view.agent) : feedShouts;const bar = !unread && !view.agent ? '' : '<div class="feed-bar">' + (unread ? '<span><b>' + heard.length + '</b> unread <button class="link" data-unread type="button">show all</button></span>': '<span>Shouts with <b>' + esc(agentName(view.agent)) + '</b> <button class="link" data-agent="" type="button">show all</button></span>') + '</div>';@@ -1431,6 +1433,7 @@ function render() {showTab();revealPlace();updateRoadmapPanel();+ drawHistoryNotes();}/**@@ -1438,7 +1441,7 @@ function render() {* 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.*/-${pageScriptPart4(pageScope)}</script>+${pageScriptPart4(pageScope)}${historyLoadingScript()}</script></body></html>`;}diff --git a/src/view.css b/src/view.cssindex 25eee66d..29bdcd3f 100644--- a/src/view.css+++ b/src/view.css@@ -523,6 +523,9 @@ form.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; paddin.feed { padding: 6px 10px 10px; display: grid; }.feed > div { display: grid; grid-template-columns: 4.6em minmax(0, 1fr); gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); overflow-wrap: break-word; }.feed > .empty { display: block; }+/* Older history still streaming to a phone (#956): one quiet line at the end of the list, gone once complete. */+.history-note { margin: 0; padding: 12px 10px; color: var(--ink-muted); font-size: 13px; text-align: center; }+.history-note.failed { color: var(--ink); }.feed > div:first-child, .feed > .day + div { border-top: 0; }/* The shout composer: one bar, to on the left, the message growing with what is typed, send on the right. */.shout-form { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px; }diff --git a/src/view/history-loading.js b/src/view/history-loading.jsnew file mode 100644index 00000000..2960756e--- /dev/null+++ b/src/view/history-loading.js@@ -0,0 +1,135 @@+/**+ * Older history still on its way (#956). After #903 a phone opens a relay board from its current state and+ * streams the older shouts, item threads and event log in the background. While that stream runs, Shouts,+ * Activity and an item's history end in one quiet line saying older entries are still loading, with how far+ * along it is when the transport knows. Reaching that line asks for the next page instead of stopping there.+ * Once the history is complete the line goes away. A board that holds all its history never shows it.+ */++/**+ * The line for one list, or '' when nothing is loading. The page embeds this function's source, so it reads+ * nothing outside itself, its own escaping included.+ *+ * @param {{loaded?: number, total?: number|null, complete?: boolean, error?: string}|null} progress - The transport's historyProgress(boardId).+ * @param {'shouts'|'activity'|'item'} kind - Which list the line ends.+ * @returns {string} The line's markup, or ''.+ */+export function historyNote(progress, kind) {+ if (!progress || progress.complete) return '';+ const escape = (text) => String(text).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);+ const what = kind === 'shouts' ? 'Older shouts are' : kind === 'activity' ? 'Older activity is' : 'Older entries are';+ const known = Number.isFinite(progress.total) && progress.total > 0 && Number.isFinite(progress.loaded);+ const share = known ? Math.min(99, Math.floor(progress.loaded / progress.total * 100)) : null;+ const text = progress.error ? String(progress.error) : what + ' still loading' + (share === null ? '.' : ' (' + share + '%).');+ return '<p class="history-note' + (progress.error ? ' failed' : '') + '" role="status" data-history-note="' + kind + '">' + escape(text) + '</p>';+}++/**+ * The page's script for the line: where it goes, how it follows the transport's count, and the next page it+ * asks for at the end of a list. Shouts read the next ten older shouts by their addresses, which the relay+ * answers from its sealed pages; Activity and an item's history ask the transport for the board again, which+ * draws what has arrived and resumes a stream that stopped.+ *+ * @returns {string} Script text for the page, inside its template literal.+ */+export function historyLoadingScript() {+ return `const historyNote = (${historyNote.toString()});+// Older shouts read at the end of the feed while history streams, by board, newest first.+const olderShouts = new Map();+const HISTORY_PAGE = 10;+let historyWatch = null, historyTicker = null, historyAsking = false, historyAskedAt = 0;+// The lists whose end is in view: each tick asks for their next page while it stays there.+const historyAtEnd = new Set();++/** The shown board's history progress while it is still arriving, or null once complete or for a local board. */+function historyProgressFor(root = view.root) {+ const board = data?.projects?.find((entry) => entry.root === root && entry.ok);+ if (!board || !relayProject(root)) return null;+ const live = typeof transport?.historyProgress === 'function' ? transport.historyProgress(board.id) : null;+ const progress = live || (data.root === root ? data.project?.historyProgress : null);+ return progress && !progress.complete ? progress : null;+}++/** The older shouts already read for this board that its current forty do not hold. */+function olderShoutsOf(root, shouts) {+ const kept = olderShouts.get(root);+ if (!kept) return [];+ const held = new Set(shouts.map((shout) => shout.shout_id));+ return kept.shouts.filter((shout) => !held.has(shout.shout_id));+}++/** End Shouts, Activity and the open item's history with the loading line, and watch each end for the next page. */+function drawHistoryNotes() {+ const progress = historyProgressFor();+ if (!progress) { stopHistoryNotes(); return; }+ for (const old of document.querySelectorAll('[data-history-note]')) old.remove();+ const places = [['shouts', $('feed')], ['activity', $('activity')],+ ['item', [...$('detail').querySelectorAll('h3')].find((head) => head.textContent === 'History')?.parentElement]];+ historyWatch?.disconnect(); historyAtEnd.clear();+ historyWatch = typeof IntersectionObserver === 'function' ? new IntersectionObserver((seen) => {+ for (const entry of seen) {+ const kind = entry.target.dataset.historyNote;+ if (entry.isIntersecting) { historyAtEnd.add(kind); void historyNextPage(kind); } else historyAtEnd.delete(kind);+ }+ }, { rootMargin: '0px 0px 200px 0px' }) : null;+ for (const [kind, place] of places) {+ if (!place) continue;+ place.insertAdjacentHTML('beforeend', historyNote(progress, kind));+ historyWatch?.observe(place.lastElementChild);+ }+ historyTicker ??= setInterval(tickHistoryNotes, 500);+}++/** Follow the transport's count in place and keep paging a list whose end stays in view; once complete, the lines go. */+function tickHistoryNotes() {+ const progress = historyProgressFor();+ if (!progress) { stopHistoryNotes(); return; }+ for (const note of document.querySelectorAll('[data-history-note]')) {+ const fresh = historyNote(progress, note.dataset.historyNote);+ if (fresh === note.outerHTML) continue;+ historyWatch?.unobserve(note);+ note.insertAdjacentHTML('afterend', fresh);+ historyWatch?.observe(note.nextElementSibling);+ note.remove();+ }+ for (const kind of historyAtEnd) void historyNextPage(kind);+}++/** Take the lines away and stop following the count. */+function stopHistoryNotes() {+ if (historyTicker === null && historyWatch === null) return;+ clearInterval(historyTicker); historyTicker = null;+ historyWatch?.disconnect(); historyWatch = null; historyAtEnd.clear();+ for (const note of document.querySelectorAll('[data-history-note]')) note.remove();+}++/**+ * The end of a list is in view while history streams: ask for its next page, one at a time. The relay+ * answers an addressed shout from its sealed pages, so the feed grows by ten older shouts; the board read+ * again at most every two seconds draws whatever older activity and threads have arrived.+ */+async function historyNextPage(kind) {+ const root = view.root;+ if (historyAsking || !historyProgressFor(root)) return;+ const kept = olderShouts.get(root) ?? { shouts: [], below: null };+ const shown = [...(data.project?.shouts ?? []), ...kept.shouts].map((shout) => shout.shout_id);+ const below = kept.below ?? (shown.length ? Math.min(...shown) : 0);+ if (kind === 'shouts' ? below <= 1 : Date.now() - historyAskedAt < 2000) return;+ historyAsking = true;+ try {+ if (kind === 'shouts') {+ const ids = Array.from({ length: Math.min(HISTORY_PAGE, below - 1) }, (_, n) => below - 1 - n);+ const read = await Promise.allSettled(ids.map((id) => api(boardPath(root) + '/shouts/' + id)));+ const found = read.filter((reply) => reply.status === 'fulfilled' && reply.value?.shout).map((reply) => reply.value.shout);+ olderShouts.set(root, { shouts: [...kept.shouts, ...found].sort((a, b) => b.shout_id - a.shout_id), below: ids.at(-1) });+ if (view.root === root) render();+ } else {+ historyAskedAt = Date.now();+ await refresh();+ }+ } catch (error) {+ $('live').textContent = 'offline: ' + (error.message || error);+ } finally { historyAsking = false; }+}+`;+}diff --git a/test/cockpit/activity.test.js b/test/cockpit/activity.test.jsindex 2b3af162..66b9c0ab 100644--- a/test/cockpit/activity.test.js+++ b/test/cockpit/activity.test.js@@ -1,11 +1,12 @@/** Cockpit activity checks, using the shared real-board fixtures [N26]. */import assert from 'node:assert/strict';-import { mkdtempSync, rmSync } from 'node:fs';+import { mkdtempSync, readFileSync, rmSync } from 'node:fs';import { createServer } from 'node:http';import { tmpdir } from 'node:os';import { join } from 'node:path';import { test } from 'node:test';import { IN_STATE, MACHINE, effectiveGuards } from '../../src/machine.js';+import { cockpitPage } from '../../src/cockpit.js';import { machine, project, build, sendBack, fetchLive, startView, styleOf, element, storage, openPage, timelineRows, agentEntries, drawing, textBoxes, meet, accept, itemRow, chromeExecutable, openSnapshotChrome, closeSnapshotChrome } from './fixture.js';const verifiedIsFinal = Boolean(MACHINE.states.find((state) => state.id === 'verified').final);@@ -486,3 +487,93 @@ test('activity names the item each event moved [N26]', async () => {await view.stop();}});++/** Verify a phone board whose older history still streams says so on each list, pages on demand, then reads as complete. */+test('older history says it is still loading until the stream completes [N26,H5]', { timeout: 120_000 }, async (t) => { // budget: hang ceiling for one real board, 43 CLI runs and one owned Chrome, not a throughput assertion.+ const executable = chromeExecutable();+ if (!executable) return t.skip('Install Chrome or set PULLBOARD_CHROME for the history-loading proof.');+ const box = machine();+ const streaming = project(box, 'streaming');+ box.run(streaming.repo, 'add', 'web', 'Greet the visitor', '--criterion', 'greets');+ box.run(streaming.repo, 'shout', 'web', 'The oldest shout, read once the feed reaches its end');+ for (let n = 1; n <= 41; n++) box.run(streaming.repo, 'shout', 'web', `Filler ${n}`);+ const live = await startView(box);+ const reads = [];+ // The relay transport's shape (#903): board reads, plus historyProgress(boardId) the test moves by hand.+ const moduleSource = `/** Read the real private board, reporting history progress the test sets. */+export async function createTransport({ onUpdate }) {+ window.__history = { loaded: 120, total: 400, complete: false, sequence: 1 };+ window.__transportUpdate = onUpdate;+ return {+ historyProgress: () => ({ ...window.__history }),+ async request(path, body) {+ if (body != null) throw new Error('The stand-in permits board reads only.');+ const response = await fetch('/fixture' + path);+ const document = await response.json();+ if (!response.ok) throw new Error(document.error ? '[' + document.error.code + '] ' + document.error.message : 'read failed: ' + response.status);+ return document;+ },+ };+}`;+ const server = createServer((request, response) => {+ const url = new URL(request.url, 'http://127.0.0.1');+ if (url.pathname === '/') return response.writeHead(200, { 'content-type': 'text/html; charset=utf-8' }).end(cockpitPage('', { readOnly: true, transportModule: '/transport.js', stylesheet: '/view.css' }));+ if (url.pathname === '/transport.js') return response.writeHead(200, { 'content-type': 'text/javascript' }).end(moduleSource);+ if (url.pathname === '/view.css') return response.writeHead(200, { 'content-type': 'text/css' }).end(readFileSync(new URL('../../src/view.css', import.meta.url)));+ if (!url.pathname.startsWith('/fixture/') || request.method !== 'GET') return response.writeHead(404).end();+ reads.push(url.pathname);+ fetchLive(live.base + url.pathname.slice('/fixture'.length) + url.search, { headers: { 'x-pullboard-key': live.key } })+ .then(async (reply) => response.writeHead(reply.status, { 'content-type': 'application/json' }).end(await reply.text()))+ .catch(() => response.writeHead(502).end());+ });+ const profile = mkdtempSync(join(tmpdir(), 'pullboard-history-loading-'));+ let chrome;+ try {+ await new Promise((ready) => server.listen(0, '127.0.0.1', ready));+ chrome = await openSnapshotChrome(executable, `http://127.0.0.1:${server.address().port}/`, profile);+ await chrome.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: true });+ await chrome.waitFor(`data?.project?.items.some((item) => item.title === 'Greet the visitor')`);+ const note = (kind) => `(document.querySelector('[data-history-note="${kind}"]')?.textContent ?? null)`;++ // Streaming: the feed ends in the line, with how far along it is, and its end reads ten older shouts at a time.+ await chrome.click(`document.querySelector('[data-tab="shouts"]')`);+ await chrome.waitFor(`${note('shouts')} === 'Older shouts are still loading (30%).'`);+ assert.equal(await chrome.stable(`document.querySelector('#feed').lastElementChild.dataset.historyNote`), 'shouts', 'the line ends the feed');+ assert.equal(await chrome.stable(`document.querySelector('#feed').textContent.includes('The oldest shout')`), false, 'the oldest shout is not among the forty on hand');+ await chrome.stable(`document.querySelector('[data-history-note="shouts"]').scrollIntoView({ block: 'end' })`);+ await chrome.waitFor(`document.querySelector('#feed').textContent.includes('The oldest shout, read once the feed reaches its end')`);+ assert.ok(reads.some((path) => /\/shouts\/\d+$/.test(path)), 'the next page came from addressed shout reads');+ assert.equal(await chrome.stable(`document.querySelector('#feed').lastElementChild.dataset.historyNote`), 'shouts', 'the line still ends the longer feed');+ assert.equal(await chrome.stable('document.documentElement.scrollWidth <= document.documentElement.clientWidth'), true, 'no sideways scroll at 390px');++ // Activity: the same line; its end asks the transport for the board again, and the count moves in place.+ await chrome.click(`document.querySelector('[data-tab="activity"]')`);+ await chrome.waitFor(`${note('activity')} === 'Older activity is still loading (30%).'`);+ await chrome.stable(`(() => { const read = refresh; window.__pages = 0; refresh = (...args) => { if (new Error().stack.includes('historyNextPage')) window.__pages += 1; return read(...args); }; return true; })()`);+ await chrome.stable(`document.querySelector('[data-history-note="activity"]').scrollIntoView({ block: 'end' })`);+ await chrome.waitFor('window.__pages >= 1');+ await chrome.stable('window.__history.loaded = 300');+ await chrome.waitFor(`${note('activity')} === 'Older activity is still loading (75%).'`);++ // An item's thread ends its history with the line.+ await chrome.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false });+ await chrome.click(`document.querySelector('[data-tab="items"]')`);+ await chrome.click(`document.querySelector('#chain [data-item]')`);+ await chrome.waitFor(`${note('item')} === 'Older entries are still loading (75%).'`);++ // Complete: every line goes, and a redraw brings none back.+ await chrome.stable('window.__history = { loaded: 400, total: 400, complete: true, sequence: 1 }');+ await chrome.waitFor(`document.querySelectorAll('[data-history-note]').length === 0`);+ await chrome.stable('render()');+ for (const tab of ['shouts', 'activity', 'items']) {+ await chrome.click(`document.querySelector('[data-tab="${tab}"]')`);+ assert.equal(await chrome.stable(`document.querySelectorAll('[data-history-note]').length`), 0, `${tab} reads as complete`);+ }+ assert.deepEqual(chrome.exceptions, []);+ } finally {+ if (chrome) await closeSnapshotChrome(chrome);+ rmSync(profile, { recursive: true, force: true });+ await new Promise((closed) => server.close(closed));+ await live.stop();+ }+});