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): every shout #id links; a search finds withdrawn items [N26]

Corey Olsondacd7d55b120
diff --git a/src/cockpit.js b/src/cockpit.js
index cf946721..8639203c 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -349,11 +349,12 @@ function render() {
}
const q = $('q').value.trim().toLowerCase();
const lane = $('lane-filter').value;
- // Each chip counts what it would show under the lane and the search.
- const matching = items
+ // Each chip counts what it would show under the lane and the search. A search looks through every
+ // state, withdrawn items included; browsing leaves those out.
+ const matching = (q ? p.items : items)
.filter((i) => !lane || i.lane === lane)
.filter((i) => !q || ('#' + i.id + ' ' + i.title + ' ' + i.specs.join(' ') + ' ' + (i.criterion || '')).toLowerCase().includes(q));
- const inState = (s) => (i) => s === 'all' || (s === 'active' ? stateOf(i) !== 'verified' : stateOf(i) === s);
+ const inState = (s) => (i) => s === 'all' || (s === 'active' ? !['verified', 'withdrawn'].includes(stateOf(i)) : stateOf(i) === s);
const names = { active: 'Active', open: 'Open', building: 'Building', verify: 'To verify', back: 'Sent back', verified: 'Verified', all: 'All' };
$('state-chips').innerHTML = Object.keys(names).map((s) => '<button data-state="' + s + '" class="' + (view.state === s ? 'on' : '') + '" type="button">' + names[s] + '<b>' + matching.filter(inState(s)).length + '</b></button>').join('');
const shown = matching.filter(inState(view.state)).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
@@ -383,10 +384,14 @@ function render() {
+ '<div class="links"><button data-shout="' + esc(item.lane) + '" data-about="' + item.id + '" type="button">Shout the ' + esc(item.lane) + ' lane about #' + item.id + '</button><button data-new type="button">New item</button></div></div>';
}
- // A #id in a shout opens that item. The text is escaped first, so the match skips the '#' that
- // starts an entity such as &#39;, and a number that names no item stays text.
+ // Every #id in a shout that names an item opens it, whatever stands next to it. The ids are found in
+ // the raw text and each piece is escaped on its own, so an apostrophe's &#39; is never read as one;
+ // a number that names no item stays text.
const titles = new Map(p.items.map((i) => [String(i.id), i.title]));
- const linked = (text) => esc(text).replace(/(^|[^&\\w])#(\\d+)\\b/g, (whole, before, id) => titles.has(id) ? before + '<button class="ref" data-go="item:' + id + '" title="' + esc(titles.get(id)) + '" type="button">#' + id + '</button>' : whole);
+ const linked = (text) => String(text ?? '').split(/(#\\d+)/).map((part) => {
+ const id = /^#\\d+$/.test(part) ? String(Number(part.slice(1))) : '';
+ return titles.has(id) ? '<button class="ref" data-go="item:' + id + '" title="' + esc(titles.get(id)) + '" type="button">' + esc(part) + '</button>' : esc(part);
+ }).join('');
$('feed').innerHTML = p.shouts.length ? p.shouts.map((x) => '<div><time>' + clock(x.shout_at) + '</time><div><b>' + esc(x.shout_from) + ' → ' + esc(x.shout_to) + '</b> ' + linked(x.shout_text) + '</div></div>').join('') : '<div class="empty">No shouts yet.</div>';
$('shout-targets').innerHTML = ['all', ...lanes, ...p.agents.map((a) => a.agent_id)].map((t) => '<option value="' + esc(t) + '">').join('');
$('agents').innerHTML = p.agents.length ? p.agents.map((a) => '<div class="agent"><b>' + esc(a.agent_id) + '</b><span class="muted">' + esc(a.agent_lane) + ' lane · ' + esc(a.agent_route) + '</span><small>' + esc(a.agent_path) + '</small></div>').join('') : '<div class="empty">No agents yet.</div>';
diff --git a/test/cockpit.test.js b/test/cockpit.test.js
index 27197649..f029686f 100644
--- a/test/cockpit.test.js
+++ b/test/cockpit.test.js
@@ -418,7 +418,10 @@ test('shout ids, search and narrow windows reach the item [N26]', async () => {
accept(box, p, 2);
// Item 39 exists, so an escaped apostrophe (&#39;) read as an id would turn into a link.
for (let id = 3; id <= 39; id += 1) box.run(p.repo, 'add', 'web', `Filler ${id}`, '--specs', 'G1', '--criterion', 'fills');
+ box.run(p.repo, 'add', 'web', 'Retired widget', '--specs', 'G1', '--criterion', 'retires');
+ box.run(p.repo, 'withdraw', '40', 'nobody needs the widget');
box.run(p.web, 'shout', 'coordinator', "#1 is next; #2 shipped (#99 is not an item) and it's done");
+ box.run(p.web, 'shout', 'coordinator', "#7, see#7 and #7#8: it's 5 o'clock");
const view = await startView(box);
try {
const page = await openPage(view);
@@ -432,12 +435,22 @@ test('shout ids, search and narrow windows reach the item [N26]', async () => {
await page.type('q', '');
assert.equal(page.run('view.state'), 'active', 'clearing the search brings the chip back');
assert.doesNotMatch(page.show('chain'), /Farewell banner/);
+ assert.doesNotMatch(page.show('chain'), /Retired widget/, 'browsing leaves withdrawn items out');
+ await page.type('q', 'retired widget');
+ const found = itemRow(page.show('chain'), 40);
+ assert.match(found, /Retired widget/, 'a search finds the withdrawn item too');
+ assert.match(found, /<span class="chip ">withdrawn<\/span>/);
+ assert.match(page.show('state-chips'), /All<b>1<\/b>/);
+ assert.match(page.show('state-chips'), /Active<b>0<\/b>/, 'a withdrawn item is not active');
+ await page.type('q', '');
const feed = page.show('feed');
assert.ok(feed.includes('<button class="ref" data-go="item:1" title="Greeting" type="button">#1</button> is next;'), feed);
assert.ok(feed.includes('<button class="ref" data-go="item:2" title="Farewell banner" type="button">#2</button> shipped'));
assert.ok(feed.includes('(#99 is not an item) and it&#39;s done'), 'no link for a missing item, and the apostrophe stays intact');
- assert.equal(feed.match(/class="ref"/g).length, 2);
+ const ref = (id, title) => `<button class="ref" data-go="item:${id}" title="${title}" type="button">#${id}</button>`;
+ assert.ok(feed.includes(`${ref(7, 'Filler 7')}, see${ref(7, 'Filler 7')} and ${ref(7, 'Filler 7')}${ref(8, 'Filler 8')}: it&#39;s 5 o&#39;clock`), 'every #id links, whatever stands next to it');
+ assert.equal(feed.match(/class="ref"/g).length, 6);
await page.click({ go: 'item:2', classes: 'ref' });
assert.equal(page.run('view.tab'), 'items', 'the link opens the Items tab');
assert.match(page.show('detail'), /<h2><span>#2<\/span>Farewell banner<\/h2>/, 'on that item');