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.

fix(view): the board counts unseen shouts, not the forty loaded [N26]

Corey Olsone036bb8a908e
diff --git a/src/cockpit.js b/src/cockpit.js
index 0dcdc219..a00bee0e 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -522,7 +522,8 @@ async function api(path, body) {
async function refresh() {
const root = view.root;
- const next = await api('/api/state' + (root ? '?root=' + encodeURIComponent(root) : ''));
+ const mark = root ? view.seen['pb.seen.' + root] ?? keep('pb.seen.' + root) : null;
+ 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)) {
@@ -698,7 +699,9 @@ function showTab() {
* Count on the Shouts tab the shouts that came after the newest one the person has seen in this
* project. Seeing means having the Shouts tab open with the board drawn; a project shown for the
* first time has seen everything so far. The mark is kept in this browser, so a reload counts
- * nothing old, and the count is never just how many shouts were loaded.
+ * nothing old. The board counts the shouts since the mark the last refresh sent, so a burst larger
+ * than the forty loaded still counts in full; until a moved mark reaches the board, the loaded
+ * shouts count, which is exact then since the mark only ever moves to the newest.
*/
function countUnseen() {
const p = data && data.project;
@@ -708,7 +711,7 @@ function countUnseen() {
const newest = p.shouts.length ? p.shouts[0].shout_id : 0;
const seen = view.tab === 'shouts' || kept === null || kept === undefined ? newest : Number(kept);
if (String(seen) !== String(kept)) { view.seen[key] = seen; keep(key, String(seen)); }
- $('count-shouts').textContent = p.shouts.filter((x) => x.shout_id > seen).length || '';
+ $('count-shouts').textContent = (p.unseen && p.unseen.since === seen ? p.unseen.count : p.shouts.filter((x) => x.shout_id > seen).length) || '';
}
function go(target) {
diff --git a/src/serve.js b/src/serve.js
index 4a0dcadf..a1e42ca5 100644
--- a/src/serve.js
+++ b/src/serve.js
@@ -73,12 +73,14 @@ function summary(project) {
}
/**
- * Everything the page shows for one project.
+ * 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.
*
* @param {string} root
+ * @param {{ seen?: number | null }} [options]
* @returns {any}
*/
-export function projectState(root) {
+export function projectState(root, { seen = null } = {}) {
return withProject(root, (board, info, config) => {
const all = store.listItems(board, { all: true });
const status = new Map(all.map((item) => [item.item_id, item.item_status]));
@@ -120,6 +122,7 @@ export function projectState(root) {
holds: store.laneHolds(board),
spec: rows(config.spec),
practice: rows(config.practice),
+ unseen: seen === null ? null : { since: seen, count: board.db.prepare('SELECT COUNT(*) AS n FROM shout WHERE shout_id > ?').get(seen).n },
// Each product's progress, counted as pullboard status counts it (N28).
products: productSummaries(config, loadSpec(info.root, config), all),
};
@@ -205,7 +208,8 @@ export function serveView({ port = 0, secret = randomBytes(18).toString('base64u
const projects = listProjects().map(summary);
const root = url.searchParams.get('root');
const known = projects.find((project) => project.root === root && project.ok);
- return json(res, 200, { projects, project: known ? projectState(known.root) : 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 });
}
if (req.method === 'POST' && url.pathname === '/api/act' && String(req.headers['content-type']).startsWith('application/json')) {
let raw = '';
diff --git a/test/cockpit.test.js b/test/cockpit.test.js
index 52a5c3c2..530e6678 100644
--- a/test/cockpit.test.js
+++ b/test/cockpit.test.js
@@ -866,6 +866,8 @@ test('the shouts tab counts shouts you have not seen [N26]', async () => {
const alpha = project(box, 'alpha');
box.run(alpha.repo, 'shout', 'web', 'first');
box.run(alpha.repo, 'shout', 'web', 'second');
+ const beta = project(box, 'beta');
+ box.run(beta.repo, 'shout', 'web', 'beta has its own');
const view = await startView(box);
try {
const store = storage();
@@ -889,6 +891,20 @@ test('the shouts tab counts shouts you have not seen [N26]', async () => {
assert.equal(count(reloaded), '1', 'what was seen is remembered across a reload');
await reloaded.click({ tab: 'shouts' });
assert.equal(count(reloaded), '');
+
+ // A burst larger than the forty shouts the page loads still counts in full, after a reload too.
+ await reloaded.click({ tab: 'items' });
+ for (let n = 1; n <= 41; n += 1) box.run(alpha.web, 'shout', 'coordinator', `burst ${n}`);
+ await reloaded.run('refresh()');
+ assert.equal(count(reloaded), '41', 'every arrival counts, not just the forty loaded');
+ const again = await openPage(view, { store });
+ assert.equal(count(again), '41');
+
+ // Each project keeps its own mark: a first look at beta sees its shouts, and alpha still counts.
+ await again.click({ root: beta.repo, classes: 'proj side' });
+ assert.equal(count(again), '');
+ await again.click({ root: alpha.repo, classes: 'proj side' });
+ assert.equal(count(again), '41');
} finally {
await view.stop();
}