cornfield 0.36.1 → 0.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -71,7 +71,7 @@ import { render, isNodeVisible } from './render.js';
71
71
  import { selectNode, repaintThreads } from './panels.js';
72
72
  import { announce, centreOn } from './keyboard.js';
73
73
  import { trapTab } from './focusables.js';
74
- import { isPhone, registerSheet, expandSheet, collapseSheet } from './sheets.js';
74
+ import { isPhone, registerSheet, expandSheet, collapseSheet, showSheet, refreshStubs } from './sheets.js';
75
75
  import { relativeTime } from './review-model.js';
76
76
  import { LAYER_DEFS, toggleLayer } from './layers.js';
77
77
  import { WORK_URL, groupWork, filterGroups, groupWords, workStatus, markWords } from './agents-model.js';
@@ -88,12 +88,15 @@ import {
88
88
  DRAFTS_URL, notesUrl, sinceChoices, notesSummary, validTag, confirmWords, postedWords, draftRequest,
89
89
  threadsUrl, threadUrl, issueUrl, IDEAS_URL, threadKindWords, threadMeta, litForThread, mentionsIndex, ideaRequest, ideaWords,
90
90
  } from './forge-panel-model.js';
91
- import { cornStateAttr, stateIconHtml } from './corn-state.js';
91
+ import { cornStateAttr, markStateAttr, stateIconHtml } from './corn-state.js';
92
92
  import { sayResult, clearResult, resultOf, showResultIn, resetFeedbackForTests } from './feedback.js';
93
93
  import { isOffline, initConnection, notSentWords, resetConnectionForTests } from './connection.js';
94
94
  import { proposalListing, onProposalListing, loadProposalList, hooks as proposalHooks } from './proposal.js';
95
- import { specRowHtml, mergeSpecs } from './proposal-model.js';
95
+ import { mergeSpecs } from './proposal-model.js';
96
96
  import { t } from './strings.js';
97
+ import { waiting, specGroups, workButtonName, waitingWords, runWaitingOn } from './waiting-model.js';
98
+ import { paintWaitingLine, resetWaitingLineForTests } from './waiting-line.js';
99
+ import { specGroupsHtml } from './waiting-view.js';
97
100
 
98
101
  const $ = (id) => document.getElementById(id);
99
102
  const FORGE_NAMES = { github: 'GitHub', forgejo: 'Forgejo' };
@@ -108,6 +111,8 @@ const ui = {
108
111
  filters: defaultFilters(),
109
112
  lists: {}, // `${kind}|${server state}` -> { items, at, rate, stale }
110
113
  work: null, // { grouped, problem, at, rate, stale } of the Agents tab
114
+ specQuery: '', // the Specs tab's search (spec 0010 D5)
115
+ draftsOpen: null, // the Drafts group opened (true) or folded (false) by hand; null: as the model has it (folded past 10 rows)
111
116
  workFilters: { agentsOnly: false, finished: false },
112
117
  loading: false,
113
118
  error: '',
@@ -172,11 +177,15 @@ const forgeName = () => FORGE_NAMES[ui.config && ui.config.forge && ui.config.fo
172
177
  const listKey = () => listKeyOf(ui.kind, ui.filters.state);
173
178
  const current = () => (ui.kind === 'work' ? ui.work : ui.kind === 'specs' ? specsList() : ui.lists[listKey()]) || null;
174
179
  /** The proposals the Proposals menu lists (proposal.js reads them), as a list of the panel's own shape; null before the first answer */
180
+ let merged = { entries: null, items: [] }; // mergeSpecs of the listing last seen: it is asked for many times a paint
175
181
  function specsList() {
176
182
  const { entries, problem, forgeProblem, at } = proposalListing();
177
183
  // One row for a proposal, however many places it is in: its spec PR and the copy in a checkout or a worktree are one (mergeSpecs)
178
- return entries ? { items: mergeSpecs(entries), at: at ? new Date(at).toISOString() : '', rate: '', stale: '', problem: problem || forgeProblem || '' } : null;
184
+ if (entries && merged.entries !== entries) merged = { entries, items: mergeSpecs(entries) };
185
+ return entries ? { items: merged.items, at: at ? new Date(at).toISOString() : '', rate: '', stale: '', problem: problem || forgeProblem || '' } : null;
179
186
  }
187
+ /** What waits on the maintainer now (spec 0010 D1): the specs to decide and the runs that wait on an answer, from what has been read */
188
+ const waitingNow = () => waiting({ specs: specsList() && specsList().items, runs: ui.runs && ui.runs.data ? ui.runs.data.runs : null });
180
189
  const groupsShown = () => (ui.work ? filterGroups(ui.work.grouped.groups, ui.workFilters) : []);
181
190
  const plural = (n, word, more = `${word}s`) => `${n} ${n === 1 ? word : more}`;
182
191
  const kindWords = () => ({ specs: 'spec', pulls: 'pull request', issues: 'issue', threads: 'thread', deploys: 'deploy' })[ui.kind] || 'piece of work';
@@ -228,6 +237,7 @@ async function loadRuns(refresh, { say = true } = {}) {
228
237
  const before = ui.runs && ui.runs.data ? ui.runs.data.runs : null;
229
238
  const res = await request(runsUrl(refresh), refresh);
230
239
  ui.runs = res.ok && Array.isArray(res.body.runs) ? { data: res.body, error: '' } : { data: ui.runs && ui.runs.data, error: failWords(res, 'the runs') };
240
+ paintWaiting(); // the number follows the runs, whether or not the panel is open
231
241
  if (!(ui.runs && ui.runs.data)) return;
232
242
  // The map shows the open runs' nodes; a run lit on the map follows its nodes; what changed is said, once the first answer is in
233
243
  setRunsOnMap(ui.runs.data.runs);
@@ -308,10 +318,43 @@ async function loadSpecs(token, quiet) {
308
318
  ui.loading = false;
309
319
  const { entries, problem } = proposalListing();
310
320
  if (!entries) ui.error = `Could not load the proposals. ${problem || 'cornfield did not answer.'}`;
311
- if (!quiet) announce(ui.error || `${plural(entries.length, 'spec')} shown`);
321
+ if (!quiet) announce(ui.error || specsShownWords());
312
322
  paint();
313
323
  }
314
324
 
325
+ /** What the Specs tab says when it is read or searched: how many rows show, and how many of them wait on a decision */
326
+ function specsShownWords() {
327
+ const list = current();
328
+ if (!list) return 'Looking for proposals';
329
+ const shown = specGroups(list.items, { query: ui.specQuery }).reduce((n, g) => n + g.shown, 0);
330
+ if (ui.specQuery.trim() && !shown) return `No spec matches ${ui.specQuery.trim()}`;
331
+ const decide = waitingNow().specs;
332
+ return `${plural(shown, 'spec')} shown${decide ? `, ${decide} ${t('toDecide').toLowerCase()}` : ''}`;
333
+ }
334
+
335
+ /** How often the specs are read again for the number while the page is open (spec 0010 D2: at most every 5 minutes; the server keeps what it read by PR head) */
336
+ export const SPECS_POLL_MS = 5 * 60_000;
337
+ let specsTimer = 0;
338
+ let specsReading = false;
339
+
340
+ /** Reads the proposals now, quietly (the number and the list follow); one read at a time */
341
+ async function readSpecsQuiet() {
342
+ if (specsReading) return;
343
+ specsReading = true;
344
+ try { await loadProposalList(); } finally { specsReading = false; }
345
+ paintWaiting();
346
+ }
347
+
348
+ /** The specs part of the number is read again every `SPECS_POLL_MS`, never while the page is hidden or put away; one timer at most */
349
+ function syncSpecsPoll() {
350
+ if (specsTimer || !ui.config) return;
351
+ specsTimer = setTimeout(async () => {
352
+ specsTimer = 0;
353
+ if (!pageAway && !(typeof document !== 'undefined' && document.hidden)) await readSpecsQuiet();
354
+ syncSpecsPoll();
355
+ }, SPECS_POLL_MS);
356
+ }
357
+
315
358
  /** The counts on the tabs, read quietly the first time the panel opens: the open pull requests and issues (the Threads and Runs counts come from what those tabs read anyway) */
316
359
  function primeCounts() {
317
360
  for (const kind of ['pulls', 'issues']) {
@@ -324,7 +367,7 @@ function primeCounts() {
324
367
  });
325
368
  }
326
369
  if (!primed.has('threads')) { primed.add('threads'); ensureThreadsList(); }
327
- if (ui.kind !== 'specs' && !proposalListing().entries) loadProposalList();
370
+ if (ui.kind !== 'specs') readSpecsQuiet(); // the specs part of the number is read when Work opens (spec 0010 D2)
328
371
  }
329
372
  const primed = new Set();
330
373
 
@@ -713,6 +756,7 @@ function paintIdea() {
713
756
  if (ui.idea.message && ui.idea.link && safeUrl(ui.idea.link)) {
714
757
  const link = document.createElement('a');
715
758
  link.className = 'hx-link';
759
+ link.dataset.corn = 'text-link';
716
760
  link.href = ui.idea.link;
717
761
  link.target = '_blank';
718
762
  link.rel = 'noreferrer';
@@ -865,6 +909,7 @@ function paintNotes() {
865
909
  if (n.message && n.link && safeUrl(n.link)) {
866
910
  const link = document.createElement('a');
867
911
  link.className = 'hx-link';
912
+ link.dataset.corn = 'text-link';
868
913
  link.href = n.link;
869
914
  link.target = '_blank';
870
915
  link.rel = 'noreferrer';
@@ -936,17 +981,17 @@ function lightsWords(deploy) {
936
981
 
937
982
  function deployHtml(d) {
938
983
  const link = safeUrl(d.url);
939
- const out = link ? `<a class="hx-forge-out" href="${escHtml(link)}" target="_blank" rel="noreferrer" aria-label="Open deploy ${escHtml(d.name)} on ${escHtml(forgeName())} (new tab)">↗</a>` : '';
984
+ const out = link ? `<a data-corn="out-link" class="hx-forge-out" href="${escHtml(link)}" target="_blank" rel="noreferrer" aria-label="Open deploy ${escHtml(d.name)} on ${escHtml(forgeName())} (new tab)">↗</a>` : '';
940
985
  return `<li class="hx-forge-item"><button type="button" class="hx-forge-row" data-forge-deploy="${escHtml(d.id)}" aria-pressed="${ui.deploy === d.id}" data-corn="row">
941
986
  <span class="hx-forge-title">${escHtml(d.name)}${d.title && d.title !== d.name ? `<span class="hx-faint"> · ${escHtml(d.title)}</span>` : ''}</span>
942
987
  <span class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(d.state)}" data-corn="state-pill"${cornStateAttr(d.state)}>${stateIconHtml(d.state)}${escHtml(deployWords(d))}</span> ${escHtml(deployMeta(d, now()))}</span>
943
- <span class="hx-forge-labels"><span class="hx-forge-label">${escHtml(lightsWords(d))}</span></span></button>${out}</li>`;
988
+ <span class="hx-forge-labels"><span class="hx-forge-label" data-corn="tag">${escHtml(lightsWords(d))}</span></span></button>${out}</li>`;
944
989
  }
945
990
 
946
991
  /** One thread in the list: a row that opens it, and a link out to the forge */
947
992
  function threadHtml(t) {
948
993
  const link = safeUrl(t.url);
949
- const out = link ? `<a class="hx-forge-out" href="${escHtml(link)}" target="_blank" rel="noreferrer" aria-label="Open thread ${t.number} on ${escHtml(forgeName())} (new tab)">↗</a>` : '';
994
+ const out = link ? `<a data-corn="out-link" class="hx-forge-out" href="${escHtml(link)}" target="_blank" rel="noreferrer" aria-label="Open thread ${t.number} on ${escHtml(forgeName())} (new tab)">↗</a>` : '';
950
995
  const note = [t.proposals && t.proposals.length ? `Proposal ${t.proposals.map((p) => p.slug).join(', ')}` : '', t.idea ? `Idea #${t.idea}` : ''].filter(Boolean).join(' · ');
951
996
  // The run that is about this thread, as a word (issue #104): the Agents tab's list, read for every tab, says it; the row only names its state
952
997
  const runs = ui.runs && ui.runs.data ? ui.runs.data.runs : null;
@@ -954,26 +999,26 @@ function threadHtml(t) {
954
999
  const runWord = run ? `${runPillHtml({ esc: escHtml }, run, threadRunWords(runs, t.number), ` data-thread-run="${escHtml(run.runId)}"`)} ` : '';
955
1000
  return `<li class="hx-forge-item"><button type="button" class="hx-forge-row" data-forge-thread="${t.number}" aria-pressed="${ui.thread === t.number}" data-corn="row">
956
1001
  <span class="hx-forge-title">${escHtml(t.title)}</span>
957
- <span class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(t.state)}" data-corn="state-pill"${cornStateAttr(t.state)}>${escHtml(t.state === 'open' ? 'Open' : 'Closed')}</span> ${runWord}<span class="hx-forge-label">${escHtml(threadKindWords(t))}</span> ${escHtml(threadMeta(t, now()))}</span>${note ? `<span class="hx-forge-meta">${escHtml(note)}</span>` : ''}</button>${out}</li>`;
1002
+ <span class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(t.state)}" data-corn="state-pill"${cornStateAttr(t.state)}>${escHtml(t.state === 'open' ? 'Open' : 'Closed')}</span> ${runWord}<span class="hx-forge-label" data-corn="tag">${escHtml(threadKindWords(t))}</span> ${escHtml(threadMeta(t, now()))}</span>${note ? `<span class="hx-forge-meta">${escHtml(note)}</span>` : ''}</button>${out}</li>`;
958
1003
  }
959
1004
 
960
1005
  function itemHtml(item, before = '', after = '') {
961
1006
  if (ui.kind === 'deploys') return deployHtml(item);
962
1007
  if (ui.kind === 'threads') return threadHtml(item);
963
1008
  const link = safeUrl(item.url);
964
- const labels = item.labels.length ? `<span class="hx-forge-labels">${item.labels.map((l) => `<span class="hx-forge-label">${escHtml(l)}</span>`).join('')}</span>` : '';
1009
+ const labels = item.labels.length ? `<span class="hx-forge-labels">${item.labels.map((l) => `<span class="hx-forge-label" data-corn="tag">${escHtml(l)}</span>`).join('')}</span>` : '';
965
1010
  const inner = `<span class="hx-forge-title">${escHtml(item.title)}</span>
966
1011
  <span class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(item.draft ? 'draft' : item.state)}" data-corn="state-pill"${cornStateAttr(item.draft ? 'draft' : item.state)}>${escHtml(stateWords(item))}</span> ${escHtml(metaWords(item, now()))}</span>${before}${after}${labels}`;
967
- const out = link ? `<a class="hx-forge-out" href="${escHtml(link)}" target="_blank" rel="noreferrer" aria-label="Open ${escHtml(item.head ? 'pull request' : 'issue')} ${item.number} on ${escHtml(forgeName())} (new tab)">↗</a>` : '';
1012
+ const out = link ? `<a data-corn="out-link" class="hx-forge-out" href="${escHtml(link)}" target="_blank" rel="noreferrer" aria-label="Open ${escHtml(item.head ? 'pull request' : 'issue')} ${item.number} on ${escHtml(forgeName())} (new tab)">↗</a>` : '';
968
1013
  if (ui.kind !== 'issues') {
969
1014
  return `<li class="hx-forge-item"><button type="button" class="hx-forge-row" data-forge-pr="${item.number}" aria-pressed="${ui.selected === item.number}" data-corn="row">${inner}</button>${out}</li>`;
970
1015
  }
971
1016
  // An issue has no more to show here: its row is the link out; an open one also starts its spec (step 1 of the pipeline)
972
1017
  const spec = specBlock(item) === null
973
- ? `<button type="button" class="hx-btn hx-forge-act hx-forge-startspec" data-forge-spec="${item.number}" aria-label="Start a spec for issue ${item.number}"${ui.busy ? ' disabled' : ''}>Start a spec …</button>`
1018
+ ? `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act hx-forge-startspec" data-forge-spec="${item.number}" aria-label="Start a spec for issue ${item.number}"${ui.busy ? ' disabled' : ''}>Start a spec …</button>`
974
1019
  : '';
975
1020
  const agent = item.state === 'open'
976
- ? `<button type="button" class="hx-btn hx-forge-act hx-forge-startspec" data-forge-agent="issue:${item.number}" aria-label="${escHtml(t('startAgent'))} on issue ${item.number}">${escHtml(t('startAgent'))} …</button>`
1021
+ ? `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act hx-forge-startspec" data-forge-agent="issue:${item.number}" aria-label="${escHtml(t('startAgent'))} on issue ${item.number}">${escHtml(t('startAgent'))} …</button>`
977
1022
  : '';
978
1023
  return link
979
1024
  ? `<li class="hx-forge-item"><a class="hx-forge-row" href="${escHtml(link)}" target="_blank" rel="noreferrer" data-corn="row">${inner}<span class="hx-sr-only"> (opens ${escHtml(forgeName())} in a new tab)</span></a>${spec}${agent}</li>`
@@ -994,9 +1039,9 @@ function workHtml(e) {
994
1039
  /** The Agents tab's groups, each a heading and its work */
995
1040
  function groupsHtml(groups) {
996
1041
  return groups.map((g, i) => {
997
- const link = g.issue && safeUrl(g.issue.url) ? ` <a class="hx-link hx-forge-gout" href="${escHtml(g.issue.url)}" target="_blank" rel="noreferrer" aria-label="Open issue ${g.number} on ${escHtml(forgeName())} (new tab)">↗</a>` : '';
1042
+ const link = g.issue && safeUrl(g.issue.url) ? ` <a data-corn="text-link" class="hx-link hx-forge-gout" href="${escHtml(g.issue.url)}" target="_blank" rel="noreferrer" aria-label="Open issue ${g.number} on ${escHtml(forgeName())} (new tab)">↗</a>` : '';
998
1043
  const startRef = g.kind === 'issue' && g.issue && g.issue.state === 'open' ? `issue:${g.number}` : g.kind === 'proposal' ? `proposal:${g.slug}` : null;
999
- const start = startRef ? ` <button type="button" class="hx-btn hx-forge-act" data-forge-agent="${escHtml(startRef)}" aria-label="${escHtml(t('startAgent'))} on ${escHtml(g.kind === 'issue' ? `issue ${g.number}` : `proposal ${g.slug}`)}">${escHtml(t('startAgent'))} …</button>` : '';
1044
+ const start = startRef ? ` <button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-forge-agent="${escHtml(startRef)}" aria-label="${escHtml(t('startAgent'))} on ${escHtml(g.kind === 'issue' ? `issue ${g.number}` : `proposal ${g.slug}`)}">${escHtml(t('startAgent'))} …</button>` : '';
1000
1045
  return `<li class="hx-forge-group"><h3 class="hx-forge-gtitle" id="forge-group-${i}">${escHtml(g.title)}${link}</h3>${start}<p class="hx-forge-meta">${escHtml(groupWords(g))}</p><ul class="hx-forge-list" aria-labelledby="forge-group-${i}">${g.entries.map(workHtml).join('')}</ul></li>`;
1001
1046
  }).join('');
1002
1047
  }
@@ -1010,40 +1055,40 @@ function detailKey() {
1010
1055
  }
1011
1056
 
1012
1057
  /** The back control of a detail: an arrow and the name of the list it returns to ("All pull requests") */
1013
- const backHtml = (action, words) => `<button type="button" class="hx-forge-back" data-action="${action}"><svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true"><path d="M10 3L5 8l5 5"/></svg><span class="hx-forge-back-text">${escHtml(words)}</span></button>`;
1058
+ const backHtml = (action, words) => `<button data-corn="back" type="button" class="hx-forge-back" data-action="${action}"><svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true"><path d="M10 3L5 8l5 5"/></svg><span class="hx-forge-back-text">${escHtml(words)}</span></button>`;
1014
1059
 
1015
1060
  /** The selected deploy: what it was, and the nodes it restarted (each a button that selects it on the map) */
1016
1061
  function deployDetailHtml() {
1017
1062
  const d = ui.deployItem;
1018
1063
  const lit = ui.litDeploy;
1019
1064
  const url = safeUrl(d.url);
1020
- const head = `${backHtml('clear-forge-deploy', 'All deploys')}<h3 class="hx-forge-detail-title">${escHtml(d.name)}</h3>
1021
- <p class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(d.state)}" data-corn="state-pill"${cornStateAttr(d.state)}>${stateIconHtml(d.state)}${escHtml(deployWords(d))}</span> ${escHtml(deployMeta(d, now()))}${url ? ` · <a class="hx-link" href="${escHtml(url)}" target="_blank" rel="noreferrer">Open on ${escHtml(forgeName())} ↗</a>` : ''}</p>`;
1065
+ const head = `${backHtml('clear-forge-deploy', 'All deploys')}<h3 class="hx-forge-detail-title" data-corn="detail-title">${escHtml(d.name)}</h3>
1066
+ <p class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(d.state)}" data-corn="state-pill"${cornStateAttr(d.state)}>${stateIconHtml(d.state)}${escHtml(deployWords(d))}</span> ${escHtml(deployMeta(d, now()))}${url ? ` · <a data-corn="text-link" class="hx-link" href="${escHtml(url)}" target="_blank" rel="noreferrer">Open on ${escHtml(forgeName())} ↗</a>` : ''}</p>`;
1022
1067
  const stale = ui.lists.deploys && ui.lists.deploys.stale;
1023
1068
  let body;
1024
1069
  if (!d.restarts.length) {
1025
1070
  body = '<p class="hx-forge-notice" data-corn="notice">No node is mapped to this deploy, so nothing is lit. Say what it restarts under <code class="hx-code">deploys.restarts</code> in cornfield.config.js (docs/deploys.md).</p>';
1026
1071
  } else {
1027
- const rows = lit.nodes.map((n) => `<li class="hx-forge-file"><button type="button" class="hx-forge-node" data-forge-node="${escHtml(n.id)}" aria-label="Show ${escHtml(n.label)} on the map${isNodeVisible(n) ? '' : ' (its layer is off)'}">${escHtml(n.label)}${isNodeVisible(n) ? '' : ' · layer off'}</button> <span class="hx-faint">${escHtml(n.type)}</span></li>`).join('');
1072
+ const rows = lit.nodes.map((n) => `<li class="hx-forge-file" data-corn="file"><button data-corn="node-chip" type="button" class="hx-forge-node" data-forge-node="${escHtml(n.id)}" aria-label="Show ${escHtml(n.label)} on the map${isNodeVisible(n) ? '' : ' (its layer is off)'}">${escHtml(n.label)}${isNodeVisible(n) ? '' : ' · layer off'}</button> <span class="hx-faint">${escHtml(n.type)}</span></li>`).join('');
1028
1073
  const missing = lit.missing.length ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(lit.missing.join(', '))} ${lit.missing.length === 1 ? 'is' : 'are'} named in the config but not on the map.</p>` : '';
1029
- const key = lit.nodes.length ? `<p class="hx-forge-key hx-faint"><span class="hx-mark-dot hx-mark-dot--${d.state === 'failure' ? 'removed' : 'changed'}" aria-hidden="true"></span>${d.state === 'failure' ? 'restarted by a deploy that failed' : 'restarted by this deploy'}</p>` : '';
1074
+ const key = lit.nodes.length ? `<p class="hx-forge-key hx-faint"><span class="hx-mark-dot hx-mark-dot--${d.state === 'failure' ? 'removed' : 'changed'}" data-corn="mark-dot"${markStateAttr(d.state === 'failure' ? 'removed' : 'changed')} aria-hidden="true"></span>${d.state === 'failure' ? 'restarted by a deploy that failed' : 'restarted by this deploy'}</p>` : '';
1030
1075
  body = `<h4 class="hx-forge-sub">${escHtml(`Restarted: ${plural(lit.nodes.length, 'node')} on the map`)}</h4>${key}${rows ? `<ul class="hx-forge-files">${rows}</ul>` : ''}${missing}`;
1031
1076
  }
1032
1077
  return `${head}${stale ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(`This is an older answer. ${stale}`)}</p>` : ''}${body}`;
1033
1078
  }
1034
1079
 
1035
1080
  /** A node button, as in a pull request's files: it selects the node on the map */
1036
- const nodeButton = (n) => `<button type="button" class="hx-forge-node" data-forge-node="${escHtml(n.id)}" aria-label="Show ${escHtml(n.label)} on the map${isNodeVisible(n) ? '' : ' (its layer is off)'}">${escHtml(n.label)}${isNodeVisible(n) ? '' : ' · layer off'}</button>`;
1081
+ const nodeButton = (n) => `<button data-corn="node-chip" type="button" class="hx-forge-node" data-forge-node="${escHtml(n.id)}" aria-label="Show ${escHtml(n.label)} on the map${isNodeVisible(n) ? '' : ' (its layer is off)'}">${escHtml(n.label)}${isNodeVisible(n) ? '' : ' · layer off'}</button>`;
1037
1082
 
1038
1083
  /** The selected thread: read-only, its messages as written, a way to reply on the forge, and the nodes its text lights */
1039
1084
  function threadDetailHtml() {
1040
- const head = (title) => `${backHtml('clear-forge-thread', 'All threads')}<h3 class="hx-forge-detail-title">${title}</h3>`;
1085
+ const head = (title) => `${backHtml('clear-forge-thread', 'All threads')}<h3 class="hx-forge-detail-title" data-corn="detail-title">${title}</h3>`;
1041
1086
  if (ui.threadError) return `${head(`Thread ${ui.thread}`)}<p class="hx-forge-notice" data-corn="notice">${escHtml(ui.threadError)}</p>`;
1042
1087
  if (!ui.threadDetail) return `${head(`Thread ${ui.thread}`)}<p class="hx-faint">Loading its messages …</p>`;
1043
1088
  const { thread: t, stale } = ui.threadDetail;
1044
1089
  const lit = ui.litThread;
1045
1090
  const url = safeUrl(t.url);
1046
- const reply = url ? `<a class="hx-link" href="${escHtml(url)}" target="_blank" rel="noreferrer">Reply on ${escHtml(forgeName())} (new tab)</a>` : '';
1091
+ const reply = url ? `<a data-corn="text-link" class="hx-link" href="${escHtml(url)}" target="_blank" rel="noreferrer">Reply on ${escHtml(forgeName())} (new tab)</a>` : '';
1047
1092
  const named = [
1048
1093
  ...(t.proposals || []).map((p) => `Proposal <code class="hx-code">${escHtml(p.slug)}</code> in pull request #${p.pull}`),
1049
1094
  ...(t.kind === 'proposal' ? [`Spec pull request for <code class="hx-code">${escHtml((t.slugs || []).join(', '))}</code>`] : []),
@@ -1051,13 +1096,13 @@ function threadDetailHtml() {
1051
1096
  ];
1052
1097
  const msgs = t.messages.map((m) => {
1053
1098
  const own = lit.perMessage.get(m.id) || { nodes: [], unresolved: [] };
1054
- const link = safeUrl(m.url) ? ` <a class="hx-link" href="${escHtml(m.url)}" target="_blank" rel="noreferrer" aria-label="Open this message on ${escHtml(forgeName())} (new tab)">↗</a>` : '';
1099
+ const link = safeUrl(m.url) ? ` <a data-corn="out-link" class="hx-link" href="${escHtml(m.url)}" target="_blank" rel="noreferrer" aria-label="Open this message on ${escHtml(forgeName())} (new tab)">↗</a>` : '';
1055
1100
  const chips = own.nodes.length || own.unresolved.length
1056
1101
  ? `<span class="hx-forge-nodes hx-thread-nodes">${own.nodes.map(nodeButton).join('')}${own.unresolved.length ? `<span class="hx-faint">not on the map: ${own.unresolved.map((r) => `<code class="hx-code">${escHtml(r)}</code>`).join(' ')}</span>` : ''}</span>`
1057
1102
  : '';
1058
- return `<li class="hx-thread-msg"><p class="hx-forge-meta"><strong class="hx-strong">${escHtml(m.author ? m.author.login : 'someone')}</strong>${m.opening ? ' opened this' : ''} · ${escHtml(relativeTime(m.createdAt, now()))}${link}</p><p class="hx-thread-body">${escHtml(m.body.trim() === '' ? '(no text)' : m.body)}${m.cut ? '\n… (cut here; the rest is on the forge)' : ''}</p>${chips}</li>`;
1103
+ return `<li class="hx-thread-msg" data-corn="thread-message"><p class="hx-forge-meta"><strong class="hx-strong">${escHtml(m.author ? m.author.login : 'someone')}</strong>${m.opening ? ' opened this' : ''} · ${escHtml(relativeTime(m.createdAt, now()))}${link}</p><p class="hx-thread-body">${escHtml(m.body.trim() === '' ? '(no text)' : m.body)}${m.cut ? '\n… (cut here; the rest is on the forge)' : ''}</p>${chips}</li>`;
1059
1104
  }).join('');
1060
- const key = lit.nodes.length ? `<p class="hx-forge-key hx-faint"><span class="hx-mark-dot hx-mark-dot--changed" aria-hidden="true"></span>a node this thread mentions</p>` : '';
1105
+ const key = lit.nodes.length ? `<p class="hx-forge-key hx-faint"><span class="hx-mark-dot hx-mark-dot--changed" data-corn="mark-dot" data-corn-state="changed" aria-hidden="true"></span>a node this thread mentions</p>` : '';
1061
1106
  return `${head(`#${t.number} ${escHtml(t.title)}`)}
1062
1107
  <p class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(t.state)}" data-corn="state-pill"${cornStateAttr(t.state)}>${t.state === 'open' ? 'Open' : 'Closed'}</span> ${escHtml(threadKindWords(t))} · ${escHtml(threadMeta({ ...t, comments: t.messages.length - (t.kind === 'idea' ? 1 : 0) + (t.hidden || 0) }, now()))}</p>
1063
1108
  <p class="hx-forge-why hx-faint">Read-only here: a thread is a conversation on ${escHtml(forgeName())}, so you reply there. ${reply}</p>
@@ -1077,7 +1122,7 @@ function detailHtml() {
1077
1122
  if (shown.startsWith('thread:')) return threadDetailHtml();
1078
1123
  if (shown.startsWith('deploy:')) return deployDetailHtml();
1079
1124
  if (!shown) return '';
1080
- const head = (title, meta) => `${backHtml('clear-forge-pr', ui.kind === 'work' ? 'All work' : 'All pull requests')}${meta || ''}<h3 class="hx-forge-detail-title">${title}</h3>`;
1125
+ const head = (title, meta) => `${backHtml('clear-forge-pr', ui.kind === 'work' ? 'All work' : 'All pull requests')}${meta || ''}<h3 class="hx-forge-detail-title" data-corn="detail-title">${title}</h3>`;
1081
1126
  if (ui.detailError) return `${head(`Pull request ${ui.selected}`)}<p class="hx-forge-notice" data-corn="notice">${escHtml(ui.detailError)}</p>`;
1082
1127
  if (!ui.detail) return `${head(`Pull request ${ui.selected}`)}<p class="hx-faint">Loading its files and checks …</p><ul class="hx-forge-list" aria-hidden="true">${loadingRowsHtml(4)}</ul>`;
1083
1128
  const { pull, checks, stale } = ui.detail;
@@ -1093,10 +1138,10 @@ function detailHtml() {
1093
1138
  ? `Lights ${failed.tests.map((t) => `<code class="hx-code">${escHtml(t.path)}</code>${t.nodes.length ? '' : ' (not on the map)'}`).join(', ')}`
1094
1139
  : 'Names no test file, so lights nothing'}</span>`
1095
1140
  : '';
1096
- const name = safeUrl(c.url) ? `<a class="hx-link" href="${escHtml(c.url)}" target="_blank" rel="noreferrer">${escHtml(c.name)}</a>` : `<span class="hx-name">${escHtml(c.name)}</span>`;
1141
+ const name = safeUrl(c.url) ? `<a data-corn="text-link" class="hx-link" href="${escHtml(c.url)}" target="_blank" rel="noreferrer">${escHtml(c.name)}</a>` : `<span class="hx-name">${escHtml(c.name)}</span>`;
1097
1142
  const why = rerunWhy(c, forgeName());
1098
1143
  const again = c.state === 'failure' && c.canRerun
1099
- ? `<button type="button" class="hx-btn hx-forge-act" data-forge-rerun="${escHtml(c.id)}" aria-label="Re-run ${escHtml(c.name)}"${ui.busy ? ' disabled' : ''}>Re-run</button>`
1144
+ ? `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-forge-rerun="${escHtml(c.id)}" aria-label="Re-run ${escHtml(c.name)}"${ui.busy ? ' disabled' : ''}>Re-run</button>`
1100
1145
  : '';
1101
1146
  const whyNot = why ? `<span class="hx-faint hx-forge-lights">${escHtml(why)}</span>` : '';
1102
1147
  return `<li class="hx-forge-check"><span class="hx-forge-state hx-forge-state--${escHtml(c.state)}" data-corn="state-pill"${cornStateAttr(c.state)}>${stateIconHtml(c.state)}${escHtml(checkWords(c))}</span> ${name}${again}${lights}${whyNot}</li>`;
@@ -1104,10 +1149,10 @@ function detailHtml() {
1104
1149
 
1105
1150
  const fileRows = lit.files.map((f) => {
1106
1151
  const nodes = f.nodes.length
1107
- ? f.nodes.map((n) => `<button type="button" class="hx-forge-node" data-forge-node="${escHtml(n.id)}" aria-label="Show ${escHtml(n.label)} on the map${isNodeVisible(n) ? '' : ' (its layer is off)'}">${escHtml(n.label)}${isNodeVisible(n) ? '' : ' · layer off'}</button>`).join('')
1152
+ ? f.nodes.map((n) => `<button data-corn="node-chip" type="button" class="hx-forge-node" data-forge-node="${escHtml(n.id)}" aria-label="Show ${escHtml(n.label)} on the map${isNodeVisible(n) ? '' : ' (its layer is off)'}">${escHtml(n.label)}${isNodeVisible(n) ? '' : ' · layer off'}</button>`).join('')
1108
1153
  : '<span class="hx-faint">not on the map</span>';
1109
1154
  const renamed = f.status === 'renamed' && f.previousPath ? `<span class="hx-faint"> from ${escHtml(f.previousPath)}</span>` : '';
1110
- return `<li class="hx-forge-file"><span class="hx-forge-fstatus">${escHtml(f.status)}</span> <code class="hx-code">${escHtml(f.path)}</code>${renamed} <span class="hx-good">+${f.additions}</span> <span class="hx-forge-del">−${f.deletions}</span><span class="hx-forge-nodes">${nodes}</span></li>`;
1155
+ return `<li class="hx-forge-file" data-corn="file"><span class="hx-forge-fstatus">${escHtml(f.status)}</span> <code class="hx-code">${escHtml(f.path)}</code>${renamed} <span class="hx-good">+${f.additions}</span> <span class="hx-forge-del">−${f.deletions}</span><span class="hx-forge-nodes">${nodes}</span></li>`;
1111
1156
  }).join('');
1112
1157
 
1113
1158
  // Land it is the one primary action, with Open on the forge beside it; a pull request that cannot land says why in one line
@@ -1115,10 +1160,10 @@ function detailHtml() {
1115
1160
  const land = block
1116
1161
  ? `<button type="button" class="hx-btn hx-btn--approve" disabled data-corn-kind="approve">${escHtml(t('landIt'))}</button>`
1117
1162
  : `<button type="button" class="hx-btn hx-btn--approve hx-forge-act" data-forge-merge="${escHtml(String(pull.number))}"${ui.busy ? ' disabled' : ''} data-corn-kind="approve">${escHtml(t('landIt'))} …</button>`;
1118
- const act = `<div class="hx-forge-cta">${land}${url ? `<a class="hx-btn hx-forge-open" href="${escHtml(url)}" target="_blank" rel="noreferrer">Open on ${escHtml(forgeName())} ↗</a>` : ''}</div>${block ? `<p class="hx-forge-why hx-faint">${escHtml(block)}</p>` : ''}${approvalWarning(ui.detail) ? `<p class="hx-forge-why hx-faint" data-corn="notice" data-corn-state="waiting">${escHtml(approvalWarning(ui.detail))}</p>` : ''}`;
1163
+ const act = `<div class="hx-forge-cta">${land}${url ? `<a data-corn="open-link" data-corn-kind="secondary" class="hx-btn hx-forge-open" href="${escHtml(url)}" target="_blank" rel="noreferrer">Open on ${escHtml(forgeName())} ↗</a>` : ''}</div>${block ? `<p class="hx-forge-why hx-faint">${escHtml(block)}</p>` : ''}${approvalWarning(ui.detail) ? `<p class="hx-forge-why hx-faint" data-corn="notice" data-corn-state="waiting">${escHtml(approvalWarning(ui.detail))}</p>` : ''}`;
1119
1164
  // A spec approved with `proposals.approveLands` waits for its checks: said here, with a way to stop it
1120
1165
  const waiting = ui.landing && pull.state === 'open'
1121
- ? `<div class="hx-forge-step"><p class="hx-forge-notice hx-forge-notice--ok" role="status" data-corn="notice" data-corn-state="success">${escHtml(landingWords(ui.landing, now()))}</p><button type="button" class="hx-btn hx-forge-act" data-forge-landing-cancel="${pull.number}"${ui.busy ? ' disabled' : ''}>Cancel</button></div>`
1166
+ ? `<div class="hx-forge-step"><p class="hx-forge-notice hx-forge-notice--ok" role="status" data-corn="notice" data-corn-state="success">${escHtml(landingWords(ui.landing, now()))}</p><button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-forge-landing-cancel="${pull.number}"${ui.busy ? ' disabled' : ''}>Cancel</button></div>`
1122
1167
  : '';
1123
1168
  const note = ui.note ? `<p class="hx-forge-notice${ui.note.ok ? ' hx-forge-notice--ok' : ''}" data-corn="notice"${ui.note.ok ? ' data-corn-state="success"' : ''}>${escHtml(ui.note.text)}</p>` : '';
1124
1169
  // Step 2 of the pipeline: a spec pull request with an approved proposal opens its build issue
@@ -1130,7 +1175,7 @@ function detailHtml() {
1130
1175
  : '';
1131
1176
 
1132
1177
  const key = lit.changed.size || lit.failing.size
1133
- ? `<p class="hx-forge-key hx-faint">${lit.changed.size ? '<span class="hx-mark-dot hx-mark-dot--changed" aria-hidden="true"></span>a file this pull request changes ' : ''}${lit.failing.size ? '<span class="hx-mark-dot hx-mark-dot--removed" aria-hidden="true"></span>a test a failing check names' : ''}</p>`
1178
+ ? `<p class="hx-forge-key hx-faint">${lit.changed.size ? '<span class="hx-mark-dot hx-mark-dot--changed" data-corn="mark-dot" data-corn-state="changed" aria-hidden="true"></span>a file this pull request changes ' : ''}${lit.failing.size ? '<span class="hx-mark-dot hx-mark-dot--removed" data-corn="mark-dot" data-corn-state="removed" aria-hidden="true"></span>a test a failing check names' : ''}</p>`
1134
1179
  : '';
1135
1180
  // Its run: who is running it, their state, the time and the cost (the runs are read for the Runs tab, and once for the first PR selected)
1136
1181
  const runs = ui.runs && ui.runs.data ? ui.runs.data.runs : null;
@@ -1161,6 +1206,7 @@ function findAgain(el) {
1161
1206
  if (el.dataset.forgeDeploy) return `[data-forge-deploy="${el.dataset.forgeDeploy}"]`;
1162
1207
  if (el.dataset.forgeThread) return `[data-forge-thread="${el.dataset.forgeThread}"]`;
1163
1208
  if (el.dataset.forgeNode) return `[data-forge-node="${el.dataset.forgeNode}"]`;
1209
+ if (el.dataset.specGroupToggle) return `[data-spec-group-toggle="${el.dataset.specGroupToggle}"]`;
1164
1210
  if (el.dataset.forgeMerge) return '[data-forge-merge]';
1165
1211
  if (el.dataset.forgeSpec) return `[data-forge-spec="${el.dataset.forgeSpec}"]`;
1166
1212
  if (el.dataset.forgeBuild) return `[data-forge-build="${el.dataset.forgeBuild}"]`;
@@ -1227,15 +1273,57 @@ function paintCounts() {
1227
1273
  const specs = specsList() && specsList().items;
1228
1274
  const runs = ui.runs && ui.runs.data ? ui.runs.data.open : null;
1229
1275
  const counts = { specs: specs ? specs.length : null, pulls: open('pulls|open'), issues: open('issues|open'), threads: ui.config && ui.config.threads === false ? null : open('threads|open'), work: runs };
1276
+ // What waits on you shows as a filled badge on its tab: Specs the specs to decide, Runs the runs that need an answer (spec 0010 D2); with nothing
1277
+ // waiting, the tab shows its plain total like the others. One number a tab, and its name says so.
1278
+ const w = waitingNow();
1279
+ const share = { specs: w.specs, work: w.runs };
1230
1280
  for (const btn of document.querySelectorAll('#forge-panel [data-forge-kind]')) {
1231
- const n = counts[btn.dataset.forgeKind];
1281
+ const kind = btn.dataset.forgeKind;
1232
1282
  const el = btn.querySelector('.hx-forge-count');
1233
1283
  if (!el) continue;
1234
- el.hidden = !(btn.dataset.forgeKind in counts); // a tab with no count at all (Deploys) shows none; the others hold their width while empty
1284
+ const waits = share[kind] || 0;
1285
+ const n = waits || counts[kind];
1286
+ el.hidden = !(kind in counts); // a tab with no count at all (Deploys) shows none; the others hold their width while empty
1235
1287
  el.textContent = n ? String(n) : '';
1288
+ // The hook says which it is: a filled badge for what waits on you, a plain count for the total
1289
+ el.dataset.corn = waits ? 'waiting-badge' : 'count';
1290
+ el.classList.toggle('hx-forge-count--waiting', !!waits);
1291
+ const label = btn.querySelector('[data-corn-string]');
1292
+ if (waits && label) btn.setAttribute('aria-label', `${label.textContent}, ${waitingWords(waits)}`); else btn.removeAttribute('aria-label');
1236
1293
  }
1237
1294
  }
1238
1295
 
1296
+ /** The one number, wherever it shows: the tabs' badges, the Work button's, and the browser tab's title; called whenever the specs or the runs were read */
1297
+ function paintWaiting() {
1298
+ paintCounts();
1299
+ paintButton();
1300
+ paintTitle();
1301
+ paintBarLine();
1302
+ refreshStubs();
1303
+ }
1304
+
1305
+ /** The proposal bar's line: a run waits on the open proposal (spec 0010 D2) */
1306
+ function paintBarLine(open = !!state.proposal) {
1307
+ const run = open && state.proposalSlug && ui.runs && ui.runs.data ? runWaitingOn(ui.runs.data.runs, state.proposalSlug) : null;
1308
+ paintWaitingLine(run, `${state.proposalSource || ''}/${state.proposalSlug || ''}`);
1309
+ }
1310
+
1311
+ /** Answer, on the proposal bar's line: Work opens on Runs at that run with its reply field focused */
1312
+ async function answerFromBar(id) {
1313
+ if (!(await openRunLink(id))) return;
1314
+ const field = $('forge-runs-list').querySelector(`[data-run-reply="${id}"]`);
1315
+ if (field) field.focus();
1316
+ }
1317
+
1318
+ /** The browser tab's title starts "(3) " while something waits, then the page's own title (the app's configured name, whatever the server wrote) */
1319
+ let baseTitle = null;
1320
+ function paintTitle() {
1321
+ if (typeof document === 'undefined') return;
1322
+ if (baseTitle === null) baseTitle = document.title.replace(/^\(\d+\) /, '');
1323
+ const n = waitingNow().total;
1324
+ document.title = n > 0 ? `(${n}) ${baseTitle}` : baseTitle;
1325
+ }
1326
+
1239
1327
  /** Says (on the panel's top, for the CSS) that the tabs run on past an edge: a fade shows on that side, so Deploys is not simply missing on a phone */
1240
1328
  function paintTabsMore() {
1241
1329
  const top = document.querySelector('#forge-panel .hx-forge-top');
@@ -1272,6 +1360,8 @@ function draw(panel) {
1272
1360
  const specs = ui.kind === 'specs';
1273
1361
  const showing = detailKey();
1274
1362
  $('forge-filters').hidden = notes || ui.kind === 'work' || specs;
1363
+ const searchBox = $('forge-specs-search');
1364
+ if (searchBox) searchBox.hidden = !specs || !!showing;
1275
1365
  $('forge-work-filters').hidden = ui.kind !== 'work';
1276
1366
  $('forge-bar').hidden = !!showing;
1277
1367
  paintChip();
@@ -1292,7 +1382,7 @@ function draw(panel) {
1292
1382
  if (ui.loading && !list) status.textContent = work ? `Loading the work from ${forgeName()} …` : specs ? 'Looking for proposals …' : `Loading ${kindWords()}s from ${forgeName()} …`;
1293
1383
  else if (!list) status.textContent = '';
1294
1384
  else if (work) status.textContent = workStatus(groups, list.at, now());
1295
- else if (specs) status.textContent = `${plural(list.items.length, 'proposal')}${list.at ? `, as of ${relativeTime(list.at, now())}` : ''}`;
1385
+ else if (specs) status.textContent = `${waitingNow().specs ? `${waitingNow().specs} ${t('toDecide').toLowerCase()} \u00b7 ` : ''}${plural(list.items.length, 'proposal')}${list.at ? `, as of ${relativeTime(list.at, now())}` : ''}`;
1296
1386
  else status.textContent = `${shown.length} of ${plural(list.items.length, kindWords())}${list.at ? `, as of ${relativeTime(list.at, now())}` : ''}`;
1297
1387
 
1298
1388
  const notice = $('forge-notice');
@@ -1305,7 +1395,7 @@ function draw(panel) {
1305
1395
  const link = ui.actNote && safeUrl(ui.actNote.url);
1306
1396
  act.className = `hx-forge-notice${ui.actNote && ui.actNote.ok ? ' hx-forge-notice--ok' : ''}`;
1307
1397
  if (ui.actNote && ui.actNote.ok) act.dataset.cornState = 'success'; else delete act.dataset.cornState;
1308
- act.innerHTML = ui.actNote ? `${escHtml(ui.actNote.text)}${link ? ` <a class="hx-link" href="${escHtml(link)}" target="_blank" rel="noreferrer">Open on ${escHtml(forgeName())} ↗</a>` : ''}` : '';
1398
+ act.innerHTML = ui.actNote ? `${escHtml(ui.actNote.text)}${link ? ` <a data-corn="text-link" class="hx-link" href="${escHtml(link)}" target="_blank" rel="noreferrer">Open on ${escHtml(forgeName())} ↗</a>` : ''}` : '';
1309
1399
  }
1310
1400
 
1311
1401
  const rows = $('forge-list');
@@ -1317,7 +1407,10 @@ function draw(panel) {
1317
1407
  if (!list) rows.innerHTML = ui.loading && !(work && !(ui.runs && ui.runs.data)) ? loadingRowsHtml(4) : '';
1318
1408
  else if (specs) {
1319
1409
  const open = state.proposal ? { slug: state.proposalSlug, source: state.proposalSource } : null;
1320
- rows.innerHTML = list.items.length ? list.items.map((e) => specRowHtml(e, { current: open })).join('') : empty(emptyWords('specs', forgeName()));
1410
+ const groups = specGroups(list.items, { query: ui.specQuery });
1411
+ rows.innerHTML = groups.length ? specGroupsHtml(groups, { current: open, nowMs: now(), draftsOpen: ui.draftsOpen })
1412
+ : list.items.length ? `<li class="hx-forge-empty hx-faint" data-corn="empty">No spec matches \u201c${escHtml(ui.specQuery.trim())}\u201d. <button type="button" class="hx-btn hx-forge-act" data-corn-kind="quiet" data-action="clear-specs-search">Clear the search</button></li>`
1413
+ : empty(emptyWords('specs', forgeName()));
1321
1414
  }
1322
1415
  else if (work) rows.innerHTML = groups.length ? groupsHtml(groups) : empty(ui.work.grouped.groups.length ? 'No work matches these filters.' : emptyWords('work', forgeName()));
1323
1416
  else rows.innerHTML = shown.length ? shown.map((i) => itemHtml(i)).join('') : empty(list.items.length ? `No ${kindWords()} matches these filters.` : emptyWords(ui.kind, forgeName()));
@@ -1524,7 +1617,13 @@ function paintButton() {
1524
1617
  tag.hidden = !lit;
1525
1618
  tag.textContent = ui.runSel ? 'run' : ui.thread !== null ? `thread #${ui.thread}` : ui.deployItem ? 'deploy' : lit ? `#${ui.selected}` : '';
1526
1619
  }
1527
- btn.setAttribute('aria-label', `${t('issuesAndPrs')}${ui.runSel ? ', a run lit on the map' : ui.thread !== null ? `, thread ${ui.thread} selected` : ui.deployItem ? ', a deploy selected' : lit ? `, pull request ${ui.selected} selected` : ''}`);
1620
+ const n = waitingNow().total;
1621
+ const badge = $('forge-btn-waiting');
1622
+ if (badge) {
1623
+ badge.hidden = n === 0;
1624
+ badge.textContent = n ? String(n) : '';
1625
+ }
1626
+ btn.setAttribute('aria-label', `${workButtonName(t('issuesAndPrs'), n)}${ui.runSel ? ', a run lit on the map' : ui.thread !== null ? `, thread ${ui.thread} selected` : ui.deployItem ? ', a deploy selected' : lit ? `, pull request ${ui.selected} selected` : ''}`);
1528
1627
  }
1529
1628
 
1530
1629
  // ---------------------------------------------------------------------------
@@ -1587,7 +1686,7 @@ function showConfirm(what, goLabel, state) {
1587
1686
  $('forge-confirm-title').textContent = what.title;
1588
1687
  $('forge-confirm-body').innerHTML = `<dl class="hx-confirm-facts">${what.lines.map(([k, v]) => `<dt>${escHtml(k)}</dt><dd>${asCode.includes(k) ? `<code class="hx-code">${escHtml(v)}</code>` : escHtml(v)}</dd>`).join('')}</dl>
1589
1688
  ${(what.checks || []).length ? `<ul class="hx-confirm-checks">${what.checks.map((c) => `<li><span class="hx-forge-state hx-forge-state--success" data-corn="state-pill" data-corn-state="success">${escHtml(c.words)}</span> ${escHtml(c.name)}</li>`).join('')}</ul>` : ''}
1590
- ${(what.previews || []).map((pv) => `<p class="hx-confirm-label">${escHtml(pv.label)}</p><pre class="hx-confirm-pre" tabindex="0" role="region" aria-label="${escHtml(pv.label)}">${escHtml(pv.text)}</pre>`).join('')}
1689
+ ${(what.previews || []).map((pv) => `<p class="hx-confirm-label">${escHtml(pv.label)}</p><pre class="hx-confirm-pre" data-corn="confirm-preview" tabindex="0" role="region" aria-label="${escHtml(pv.label)}">${escHtml(pv.text)}</pre>`).join('')}
1591
1690
  <p class="hx-confirm-note">${escHtml(what.note)}</p>`;
1592
1691
  const go = el.querySelector('[data-action="forge-confirm-go"]');
1593
1692
  go.disabled = false;
@@ -2007,11 +2106,20 @@ export function openForge({ load = true, tab } = {}) {
2007
2106
  ui.kind = tab;
2008
2107
  ui.filters = defaultFilters(tab);
2009
2108
  ui.actNote = null;
2109
+ } else if (!tab && load && !ui.open) {
2110
+ // Opened by a toggle: on the tab with the oldest thing waiting on you, else the tab used last (spec 0010 D2)
2111
+ const oldest = waitingNow().oldest;
2112
+ if (oldest && oldest !== ui.kind) {
2113
+ ui.kind = oldest;
2114
+ ui.filters = defaultFilters(oldest);
2115
+ ui.actNote = null;
2116
+ paintFilters();
2117
+ }
2010
2118
  }
2011
2119
  ui.open = true;
2012
2120
  panel.inert = false;
2013
2121
  panel.classList.add('forge-open');
2014
- if (isPhone()) expandSheet('forge');
2122
+ if (isPhone()) { showSheet('forge'); if (tab) expandSheet('forge'); } // a peek; only a link that names a tab (a deep link, "Open the Specs list") opens it expanded
2015
2123
  paintButton();
2016
2124
  const title = $('forge-title');
2017
2125
  title.focus();
@@ -2185,6 +2293,15 @@ function onClick(e) {
2185
2293
  if (ui.kind === 'specs') { paint(); loadList(false, true); announce(current() ? `${plural(current().items.length, 'spec')} shown` : 'Looking for proposals'); } else if (current()) filtersChanged(); else { paint(); loadList(); }
2186
2294
  return;
2187
2295
  }
2296
+ const fold = t.closest('[data-spec-group-toggle]');
2297
+ if (fold) {
2298
+ // Drafts folded behind their header, opened by hand and folded again; the focus stays on the header (findAgain)
2299
+ const drafts = specGroups(specsList() ? specsList().items : [], { query: ui.specQuery }).find((g) => g.key === 'drafts');
2300
+ const folded = ui.draftsOpen === null ? !!(drafts && drafts.collapsed) : !ui.draftsOpen;
2301
+ ui.draftsOpen = folded;
2302
+ paint();
2303
+ return;
2304
+ }
2188
2305
  const pr = t.closest('[data-forge-pr]');
2189
2306
  if (pr) {
2190
2307
  const n = Number(pr.dataset.forgePr);
@@ -2245,6 +2362,14 @@ function onClick(e) {
2245
2362
  if (!action) return;
2246
2363
  if (action.dataset.action === 'close-forge') closeForge();
2247
2364
  else if (action.dataset.action === 'refresh-forge' || action.dataset.action === 'retry-forge') refreshForge();
2365
+ else if (action.dataset.action === 'clear-specs-search') {
2366
+ ui.specQuery = '';
2367
+ const box = $('specs-search');
2368
+ if (box) { box.value = ''; }
2369
+ paint();
2370
+ announce(specsShownWords());
2371
+ if (box) box.focus();
2372
+ }
2248
2373
  else if (action.dataset.action === 'copy-notes') copyNotes();
2249
2374
  else if (action.dataset.action === 'post-notes') { if (ui.notes.confirm) closeNotesConfirm(); else openNotesConfirm(); }
2250
2375
  else if (action.dataset.action === 'confirm-notes') postDraft();
@@ -2319,6 +2444,13 @@ function onInput(e) {
2319
2444
  if (said && !said.ok && e.target.value.trim()) { clearResult(id); showResultIn(e.target.closest('[data-run]') && e.target.closest('[data-run]').querySelector(`[data-run-result="${id}"]`), id); }
2320
2445
  return;
2321
2446
  }
2447
+ if (e.target.id === 'specs-search') {
2448
+ ui.specQuery = e.target.value;
2449
+ paint();
2450
+ clearTimeout(searchTimer);
2451
+ searchTimer = setTimeout(() => announce(specsShownWords()), SEARCH_ANNOUNCE_MS);
2452
+ return;
2453
+ }
2322
2454
  if (e.target.id !== 'forge-text') return;
2323
2455
  ui.filters.text = e.target.value;
2324
2456
  filtersChanged(false);
@@ -2378,13 +2510,35 @@ export function initForgePanel(config, opts = {}) {
2378
2510
  const tab = panel.querySelector('[data-forge-kind="threads"]');
2379
2511
  if (tab) tab.hidden = !threadsOn;
2380
2512
  state.threadIndex = threadsOn ? { for: threadsFor, ensure: ensureThreadsList, open: openThread, start: startThread, forge: forgeName } : null;
2381
- registerSheet('forge', panel);
2513
+ // On a phone Work is a sheet: it opens as a peek and displaces the node panel; folded to a stub it says its title and what waits on you (spec 0010 D7)
2514
+ registerSheet('forge', panel, {
2515
+ stub: () => { const n = waitingNow().total; return { title: t('issuesAndPrs'), badge: n ? String(n) : '', label: workButtonName(t('issuesAndPrs'), n) }; },
2516
+ away: () => closeForge({ restoreFocus: false }),
2517
+ });
2382
2518
  paintFilters();
2383
2519
  paint();
2384
2520
  // The map shows the open runs whether or not the panel is open: read them once now, and again now and then while any is open
2385
2521
  if (config.agents && config.agents.runs) {
2386
2522
  loadRuns(false).then(() => { if (ui.kind === 'work') paint(); }, () => {});
2387
2523
  }
2524
+ // The specs part of what waits on you is read once now and every 5 minutes after (the server keeps it by PR head), and after a review is sent
2525
+ proposalHooks.reviewed = () => { readSpecsQuiet(); };
2526
+ // The proposal bar says so when a run waits on the proposal it shows: drawn with the bar, and again as the runs are read
2527
+ if (!(proposalHooks.bar && proposalHooks.bar.waitingLine)) {
2528
+ const barBefore = proposalHooks.bar;
2529
+ proposalHooks.bar = (open) => { if (barBefore) barBefore(open); paintBarLine(open); };
2530
+ proposalHooks.bar.waitingLine = true;
2531
+ }
2532
+ const bar = $('proposal-bar');
2533
+ if (bar && !bar.dataset.waitingWired) {
2534
+ bar.dataset.waitingWired = '1';
2535
+ bar.addEventListener('click', (e) => {
2536
+ const go = e.target.closest && e.target.closest('[data-waiting-answer]');
2537
+ if (go) { e.preventDefault(); e.stopPropagation(); answerFromBar(go.dataset.waitingAnswer); }
2538
+ }, true);
2539
+ }
2540
+ readSpecsQuiet();
2541
+ syncSpecsPoll();
2388
2542
  if (!wired) {
2389
2543
  wired = true;
2390
2544
  initConnection();
@@ -2415,7 +2569,7 @@ export function initForgePanel(config, opts = {}) {
2415
2569
  }
2416
2570
  offScene = onSceneTouch(onNodesChange);
2417
2571
  // The header's Proposals menu reads the same list: when it is read again the Specs tab and its count follow
2418
- offListing = onProposalListing(() => { if (ui.open) paint(); });
2572
+ offListing = onProposalListing(() => { paintWaiting(); if (ui.open) paint(); });
2419
2573
  // A node's panel lists the threads that mention it; a click there shows one in this panel
2420
2574
  const drawer = $('spec-drawer');
2421
2575
  if (drawer) drawer.addEventListener('click', (e) => {
@@ -2457,9 +2611,16 @@ export function resetForgePanelForTests(clock = () => Date.now()) {
2457
2611
  state.threadIndex = null;
2458
2612
  clearTimeout(runsTimer);
2459
2613
  runsTimer = 0;
2614
+ clearTimeout(specsTimer);
2615
+ specsTimer = 0;
2616
+ specsReading = false;
2617
+ merged = { entries: null, items: [] };
2618
+ resetWaitingLineForTests();
2619
+ if (typeof document !== 'undefined' && baseTitle !== null) document.title = baseTitle;
2620
+ baseTitle = null;
2460
2621
  pageAway = false;
2461
2622
  clearRunsOnMap();
2462
- Object.assign(ui, { runSel: null, runTimelines: new Set(), runReplies: new Map(), thread: null, threadDetail: null, threadError: '', litThread: null, idea: freshIdea(), config: null, open: false, kind: 'specs', filtersOpen: false, filters: defaultFilters(), lists: {}, work: null, workFilters: { agentsOnly: false, finished: false }, loading: false, error: '', selected: null, selectedOn: '', detail: null, landing: null, detailError: '', lit: null, deploy: null, deployItem: null, litDeploy: null, nodesSeen: null, busy: '', note: null, confirm: null, actNote: null, notes: freshNotes(), runs: null, runnerSaid: null, runNote: null, agent: null, retrying: false });
2623
+ Object.assign(ui, { specQuery: '', draftsOpen: null, runSel: null, runTimelines: new Set(), runReplies: new Map(), thread: null, threadDetail: null, threadError: '', litThread: null, idea: freshIdea(), config: null, open: false, kind: 'specs', filtersOpen: false, filters: defaultFilters(), lists: {}, work: null, workFilters: { agentsOnly: false, finished: false }, loading: false, error: '', selected: null, selectedOn: '', detail: null, landing: null, detailError: '', lit: null, deploy: null, deployItem: null, litDeploy: null, nodesSeen: null, busy: '', note: null, confirm: null, actNote: null, notes: freshNotes(), runs: null, runnerSaid: null, runNote: null, agent: null, retrying: false });
2463
2624
  resetFeedbackForTests();
2464
2625
  resetConnectionForTests();
2465
2626
  }