@popcorn245/cornfield 0.34.2 → 0.35.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.
@@ -70,26 +70,29 @@ import { state, nodeById, escHtml, touchScene, onSceneTouch } from './state.js';
70
70
  import { render, isNodeVisible } from './render.js';
71
71
  import { selectNode, repaintThreads } from './panels.js';
72
72
  import { announce, centreOn } from './keyboard.js';
73
+ import { trapTab } from './focusables.js';
73
74
  import { isPhone, registerSheet, expandSheet, collapseSheet } from './sheets.js';
74
75
  import { relativeTime } from './review-model.js';
75
76
  import { LAYER_DEFS, toggleLayer } from './layers.js';
76
77
  import { WORK_URL, groupWork, filterGroups, groupWords, workStatus, markWords } from './agents-model.js';
77
78
  import {
78
- RUNS_URL, runsUrl, stopUrl, runOnThread, threadRunWords, runOnPull, pullRunWords, canRetry, retryRefs, retryWords, limitsFromFields, defaultLimits, LIMIT_KEYS, briefUrl, runTone, answerUrl, answerBody, answerWordsFor, KINDS, aboutWords, statusWords, statusWhy, runMeta, canStop, runsStatus, runnerState, runnerWords, triggerNotice, totalsLines, handLines, startBody, startWords, stopWords, confirmStartWords, litOfRun, changeWords,
79
+ RUNS_URL, runsUrl, stopUrl, runOnThread, threadRunWords, runOnPull, pullRunWords, canRetry, retryRefs, retryWords, limitsFromFields, defaultLimits, LIMIT_KEYS, briefUrl, answerUrl, answerBody, answerWordsFor, KINDS, aboutWords, statusWords, statusWhy, runMeta, canStop, runsStatus, runnerState, runnerWords, triggerNotice, totalsLines, handLines, startBody, startWords, stopWords, confirmStartWords, litOfRun, changeWords,
79
80
  } from './runs-model.js';
80
- import { runsHtml, totalsHtml } from './runs-view.js';
81
+ import { runsHtml, totalsHtml, loadingRowsHtml, runPillHtml } from './runs-view.js';
81
82
  import { setRunsOnMap, clearRunsOnMap } from './runs-map.js';
82
83
  import {
83
84
  STATES, defaultFilters, listUrl, pullUrl, serverState, filterItems, facetsOf, stateWords, metaWords, checkWords, checksWords, litFor, errorWords,
84
85
  landingUrl, cancelLandingUrl, landingWords, mergeBlock, rerunWhy, confirmMerge, mergeBody, actionUrl, actionWords,
85
86
  specBlock, buildOffers, planUrl, confirmSpec, confirmBuild, specBody, buildBody, existingWords,
86
- listKeyOf, litForDeploy, nodesForRestarts, deployWords, deployMeta,
87
+ listKeyOf, litForDeploy, nodesForRestarts, deployWords, deployMeta, emptyWords, approvalWarning,
87
88
  DRAFTS_URL, notesUrl, sinceChoices, notesSummary, validTag, confirmWords, postedWords, draftRequest,
88
89
  threadsUrl, threadUrl, issueUrl, IDEAS_URL, threadKindWords, threadMeta, litForThread, mentionsIndex, ideaRequest, ideaWords,
89
90
  } from './forge-panel-model.js';
90
- import { cornStateAttr } from './corn-state.js';
91
+ import { cornStateAttr, stateIconHtml } from './corn-state.js';
92
+ import { sayResult, clearResult, resultOf, showResultIn, resetFeedbackForTests } from './feedback.js';
93
+ import { isOffline, initConnection, notSentWords, resetConnectionForTests } from './connection.js';
91
94
  import { proposalListing, onProposalListing, loadProposalList, hooks as proposalHooks } from './proposal.js';
92
- import { specRowHtml } from './proposal-model.js';
95
+ import { specRowHtml, mergeSpecs } from './proposal-model.js';
93
96
  import { t } from './strings.js';
94
97
 
95
98
  const $ = (id) => document.getElementById(id);
@@ -171,7 +174,8 @@ const current = () => (ui.kind === 'work' ? ui.work : ui.kind === 'specs' ? spec
171
174
  /** The proposals the Proposals menu lists (proposal.js reads them), as a list of the panel's own shape; null before the first answer */
172
175
  function specsList() {
173
176
  const { entries, problem, forgeProblem, at } = proposalListing();
174
- return entries ? { items: entries, at: at ? new Date(at).toISOString() : '', rate: '', stale: '', problem: problem || forgeProblem || '' } : null;
177
+ // 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;
175
179
  }
176
180
  const groupsShown = () => (ui.work ? filterGroups(ui.work.grouped.groups, ui.workFilters) : []);
177
181
  const plural = (n, word, more = `${word}s`) => `${n} ${n === 1 ? word : more}`;
@@ -183,6 +187,9 @@ const safeUrl = (u) => (typeof u === 'string' && /^https?:\/\//i.test(u) ? u : n
183
187
  // Asking the server
184
188
  // ---------------------------------------------------------------------------
185
189
 
190
+ /** A failed answer in words (the model's), said as offline when the browser is, and naming what could not be loaded */
191
+ const failWords = (res, what = '') => errorWords(res.status, res.body, { offline: isOffline(), what });
192
+
186
193
  /** One GET (or the one POST, with its JSON); `{ ok, status, body }`, with a status of null when the server did not answer */
187
194
  async function request(url, refresh, post) {
188
195
  try {
@@ -210,7 +217,7 @@ async function loadWork(refresh, token) {
210
217
  ui.work = { grouped: groupWork(b), problem: b.specsProblem || '', at: b.at, rate: b.rate || '', stale: b.stale || '' };
211
218
  announce(`${workStatus(groupsShown(), '', now())}${ui.work.stale ? '. This is an older answer' : ''}`);
212
219
  } else {
213
- ui.error = errorWords(res.status, res.body);
220
+ ui.error = failWords(res, 'the work');
214
221
  announce(ui.error);
215
222
  }
216
223
  paint();
@@ -220,7 +227,7 @@ async function loadWork(refresh, token) {
220
227
  async function loadRuns(refresh, { say = true } = {}) {
221
228
  const before = ui.runs && ui.runs.data ? ui.runs.data.runs : null;
222
229
  const res = await request(runsUrl(refresh), refresh);
223
- ui.runs = res.ok && Array.isArray(res.body.runs) ? { data: res.body, error: '' } : { data: ui.runs && ui.runs.data, error: errorWords(res.status, res.body) };
230
+ ui.runs = res.ok && Array.isArray(res.body.runs) ? { data: res.body, error: '' } : { data: ui.runs && ui.runs.data, error: failWords(res, 'the runs') };
224
231
  if (!(ui.runs && ui.runs.data)) return;
225
232
  // 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
226
233
  setRunsOnMap(ui.runs.data.runs);
@@ -284,7 +291,7 @@ async function loadList(refresh = false, quiet = false) {
284
291
  }
285
292
  if (!quiet) announce(`${plural(filterItems(ui.lists[key].items, ui.kind, ui.filters).length, kindWords())} shown${ui.lists[key].stale ? '. This is an older answer' : ''}`);
286
293
  } else {
287
- ui.error = errorWords(res.status, res.body);
294
+ ui.error = failWords(res, `the ${kindWords()}s`);
288
295
  if (!quiet) announce(ui.error);
289
296
  }
290
297
  paintFilters();
@@ -300,7 +307,7 @@ async function loadSpecs(token, quiet) {
300
307
  if (token !== listToken) return;
301
308
  ui.loading = false;
302
309
  const { entries, problem } = proposalListing();
303
- if (!entries) ui.error = `The proposals could not be listed: ${problem || 'no answer'}`;
310
+ if (!entries) ui.error = `Could not load the proposals. ${problem || 'cornfield did not answer.'}`;
304
311
  if (!quiet) announce(ui.error || `${plural(entries.length, 'spec')} shown`);
305
312
  paint();
306
313
  }
@@ -342,7 +349,7 @@ async function selectPull(n) {
342
349
  const res = await request(pullUrl(n), false);
343
350
  if (token !== pullToken) return;
344
351
  if (!res.ok) {
345
- ui.detailError = errorWords(res.status, res.body);
352
+ ui.detailError = failWords(res, `pull request ${n}`);
346
353
  announce(ui.detailError);
347
354
  paint();
348
355
  return;
@@ -507,7 +514,7 @@ async function selectThread(n) {
507
514
  // An answer without a thread in it is a failure too: nothing to show or light
508
515
  const thread = threadOf(res);
509
516
  if (!thread) {
510
- ui.threadError = res.ok ? `Thread ${n} could not be read: the answer had no thread in it. Refresh to ask again.` : errorWords(res.status, res.body);
517
+ ui.threadError = res.ok ? `Thread ${n} could not be read: the answer had no thread in it. Refresh to ask again.` : failWords(res, `thread ${n}`);
511
518
  announce(ui.threadError);
512
519
  paint();
513
520
  return;
@@ -752,7 +759,7 @@ async function loadNotes(refresh = false) {
752
759
  n.data = res.body;
753
760
  announce(`Release notes drafted. ${notesSummary(n.data)}${n.data.stale ? ' This is an older answer' : ''}`);
754
761
  } else {
755
- n.error = errorWords(res.status, res.body);
762
+ n.error = failWords(res, 'the release notes');
756
763
  announce(n.error);
757
764
  }
758
765
  paint();
@@ -826,7 +833,7 @@ async function postDraft() {
826
833
  $('notes-post').focus();
827
834
  return;
828
835
  }
829
- say(res.status === 401 ? 'Your sign-in has ended. Sign in again to post a draft.' : errorWords(res.status, res.body), true);
836
+ say(res.status === 401 ? 'Your sign-in has ended. Sign in again to post a draft.' : failWords(res), true);
830
837
  $('notes-tag').focus();
831
838
  }
832
839
 
@@ -932,7 +939,7 @@ function deployHtml(d) {
932
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>` : '';
933
940
  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">
934
941
  <span class="hx-forge-title">${escHtml(d.name)}${d.title && d.title !== d.name ? `<span class="hx-faint"> · ${escHtml(d.title)}</span>` : ''}</span>
935
- <span class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(d.state)}" data-corn="state-pill"${cornStateAttr(d.state)}>${escHtml(deployWords(d))}</span> ${escHtml(deployMeta(d, now()))}</span>
942
+ <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>
936
943
  <span class="hx-forge-labels"><span class="hx-forge-label">${escHtml(lightsWords(d))}</span></span></button>${out}</li>`;
937
944
  }
938
945
 
@@ -944,7 +951,7 @@ function threadHtml(t) {
944
951
  // 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
945
952
  const runs = ui.runs && ui.runs.data ? ui.runs.data.runs : null;
946
953
  const run = runOnThread(runs, t.number);
947
- const runWord = run ? `<span class="hx-forge-state hx-forge-state--${runTone(run)}" data-thread-run="${escHtml(run.runId)}" data-corn="state-pill"${cornStateAttr(run.status)}>${escHtml(threadRunWords(runs, t.number))}</span> ` : '';
954
+ const runWord = run ? `${runPillHtml({ esc: escHtml }, run, threadRunWords(runs, t.number), ` data-thread-run="${escHtml(run.runId)}"`)} ` : '';
948
955
  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">
949
956
  <span class="hx-forge-title">${escHtml(t.title)}</span>
950
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>`;
@@ -1011,7 +1018,7 @@ function deployDetailHtml() {
1011
1018
  const lit = ui.litDeploy;
1012
1019
  const url = safeUrl(d.url);
1013
1020
  const head = `${backHtml('clear-forge-deploy', 'All deploys')}<h3 class="hx-forge-detail-title">${escHtml(d.name)}</h3>
1014
- <p class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(d.state)}" data-corn="state-pill"${cornStateAttr(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>`;
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>`;
1015
1022
  const stale = ui.lists.deploys && ui.lists.deploys.stale;
1016
1023
  let body;
1017
1024
  if (!d.restarts.length) {
@@ -1072,7 +1079,7 @@ function detailHtml() {
1072
1079
  if (!shown) return '';
1073
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>`;
1074
1081
  if (ui.detailError) return `${head(`Pull request ${ui.selected}`)}<p class="hx-forge-notice" data-corn="notice">${escHtml(ui.detailError)}</p>`;
1075
- if (!ui.detail) return `${head(`Pull request ${ui.selected}`)}<p class="hx-faint">Loading its files and checks …</p>`;
1082
+ 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>`;
1076
1083
  const { pull, checks, stale } = ui.detail;
1077
1084
  const lit = ui.lit;
1078
1085
  const mapped = lit.files.filter((f) => f.nodes.length).length;
@@ -1092,7 +1099,7 @@ function detailHtml() {
1092
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>`
1093
1100
  : '';
1094
1101
  const whyNot = why ? `<span class="hx-faint hx-forge-lights">${escHtml(why)}</span>` : '';
1095
- return `<li class="hx-forge-check"><span class="hx-forge-state hx-forge-state--${escHtml(c.state)}" data-corn="state-pill"${cornStateAttr(c.state)}>${escHtml(checkWords(c))}</span> ${name}${again}${lights}${whyNot}</li>`;
1102
+ 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>`;
1096
1103
  }).join('');
1097
1104
 
1098
1105
  const fileRows = lit.files.map((f) => {
@@ -1108,7 +1115,7 @@ function detailHtml() {
1108
1115
  const land = block
1109
1116
  ? `<button type="button" class="hx-btn hx-btn--approve" disabled data-corn-kind="approve">${escHtml(t('landIt'))}</button>`
1110
1117
  : `<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>`;
1111
- 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>` : ''}`;
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>` : ''}`;
1112
1119
  // A spec approved with `proposals.approveLands` waits for its checks: said here, with a way to stop it
1113
1120
  const waiting = ui.landing && pull.state === 'open'
1114
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>`
@@ -1123,13 +1130,13 @@ function detailHtml() {
1123
1130
  : '';
1124
1131
 
1125
1132
  const key = lit.changed.size || lit.failing.size
1126
- ? `<p class="hx-forge-key hx-faint"><span class="hx-mark-dot hx-mark-dot--changed" aria-hidden="true"></span>a file this pull request changes <span class="hx-mark-dot hx-mark-dot--removed" aria-hidden="true"></span>a test a failing check names</p>`
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>`
1127
1134
  : '';
1128
1135
  // 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)
1129
1136
  const runs = ui.runs && ui.runs.data ? ui.runs.data.runs : null;
1130
1137
  const made = runOnPull(runs, pull.number);
1131
1138
  const runSection = made
1132
- ? `<h4 class="hx-forge-sub">Run</h4><p class="hx-forge-runline"${cornStateAttr(made.status)} data-corn="run">${escHtml(pullRunWords(made, now()))}</p>`
1139
+ ? `<h4 class="hx-forge-sub">Run</h4><p class="hx-forge-runline"${cornStateAttr(made.status)} data-corn="run">${runPillHtml({ esc: escHtml }, made, statusWords(made))} ${escHtml(pullRunWords(made, now(), { state: false }))}</p>`
1133
1140
  : '';
1134
1141
  const meta = `<p class="hx-forge-meta hx-forge-dmeta"><span class="hx-forge-state hx-forge-state--${escHtml(pull.draft ? 'draft' : pull.state)}" data-corn="state-pill"${cornStateAttr(pull.draft ? 'draft' : pull.state)}>${escHtml(stateWords(pull))}</span> <span>#${escHtml(String(pull.number))}</span> <span>${escHtml(pull.head.ref)} → ${escHtml(pull.base.ref)}</span> <span>${escHtml(pull.author ? pull.author.login : 'someone')}</span> <span>${escHtml(relativeTime(pull.createdAt || pull.updatedAt, now()))}</span></p>`;
1135
1142
  return `${head(escHtml(pull.title), meta)}
@@ -1173,15 +1180,30 @@ let shownKey = '';
1173
1180
  let shownKind = '';
1174
1181
  let returnTo = null; // the selector of the row that opened the selection
1175
1182
 
1183
+ const key0 = () => detailKey();
1184
+
1176
1185
  /** Everything the panel shows, from `ui` (a row or node button that had the focus has it again) */
1177
1186
  function paint() {
1178
1187
  const panel = $('forge-panel');
1179
1188
  if (!panel) return;
1180
1189
  const had = panel.contains(document.activeElement) ? document.activeElement : null;
1181
1190
  const again = had ? findAgain(had) : null;
1191
+ // A list drawn again must not move what the person is looking at: the scroll of the panel stays where it was
1192
+ const scroller = panel.querySelector('.hx-forge-body');
1193
+ const scrolled = scroller ? scroller.scrollTop : 0;
1194
+ const keyBefore = shownKey;
1182
1195
  draw(panel);
1196
+ if (scroller && scrolled && key0() === keyBefore && scroller.scrollTop !== scrolled) scroller.scrollTop = scrolled;
1183
1197
  const back = again && panel.querySelector(again);
1184
1198
  if (back && back !== document.activeElement && !back.closest('[hidden]')) back.focus();
1199
+ // Retry was pressed and its notice is gone (the list is being read again): the focus goes to the panel's title, never to the page
1200
+ if (had && had.dataset && had.dataset.action === 'retry-forge' && !panel.contains(document.activeElement)) $('forge-title').focus();
1201
+ // A control of a run card that is no longer drawn (the run went on): the focus goes to that run's card, never to the page
1202
+ const hadRun = had && !had.isConnected && had.closest('[data-run]');
1203
+ if (hadRun && !panel.contains(document.activeElement)) {
1204
+ const card = [...panel.querySelectorAll('[data-run]')].find((c) => c.dataset.run === hadRun.dataset.run);
1205
+ if (card) card.focus();
1206
+ }
1185
1207
  // A selection replaces the list: the focus goes to its back control, and returns to the row when it is let go of
1186
1208
  // (a tab changed leaves the focus on the tab)
1187
1209
  const key = detailKey();
@@ -1202,7 +1224,7 @@ function paint() {
1202
1224
  /** The tabs' counts, where there is one: the proposals, the open pull requests and issues and threads, the runs still open */
1203
1225
  function paintCounts() {
1204
1226
  const open = (key) => (ui.lists[key] ? ui.lists[key].items.length : null);
1205
- const specs = proposalListing().entries;
1227
+ const specs = specsList() && specsList().items;
1206
1228
  const runs = ui.runs && ui.runs.data ? ui.runs.data.open : null;
1207
1229
  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 };
1208
1230
  for (const btn of document.querySelectorAll('#forge-panel [data-forge-kind]')) {
@@ -1214,6 +1236,35 @@ function paintCounts() {
1214
1236
  }
1215
1237
  }
1216
1238
 
1239
+ /** 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
+ function paintTabsMore() {
1241
+ const top = document.querySelector('#forge-panel .hx-forge-top');
1242
+ const tabs = top && top.querySelector('.hx-forge-tabs');
1243
+ if (!tabs) return;
1244
+ const more = [];
1245
+ if (tabs.scrollLeft > 1) more.push('start');
1246
+ if (tabs.scrollWidth - tabs.clientWidth - tabs.scrollLeft > 1) more.push('end');
1247
+ if (more.length) top.dataset.more = more.join(' '); else delete top.dataset.more;
1248
+ // A row given the focus is scrolled clear of the fixed top, never left under it (its height changes with the theme and the width)
1249
+ const body = top.parentElement;
1250
+ if (body) body.style.scrollPaddingTop = `${top.offsetHeight}px`;
1251
+ }
1252
+
1253
+ /** A notice line: its words, and a Retry that reads the tab again (for a failure or an older answer) */
1254
+ function setNotice(el, words, retry) {
1255
+ el.hidden = !words;
1256
+ el.textContent = words;
1257
+ if (words && retry) {
1258
+ const again = document.createElement('button');
1259
+ again.type = 'button';
1260
+ again.className = 'hx-btn hx-forge-act';
1261
+ again.dataset.action = 'retry-forge';
1262
+ again.dataset.cornKind = 'quiet';
1263
+ again.textContent = 'Retry';
1264
+ el.append(' ', again);
1265
+ }
1266
+ }
1267
+
1217
1268
  function draw(panel) {
1218
1269
  for (const btn of panel.querySelectorAll('[data-forge-kind]')) btn.setAttribute('aria-pressed', String(btn.dataset.forgeKind === (ui.kind === 'notes' ? 'pulls' : ui.kind)));
1219
1270
  paintCounts();
@@ -1241,13 +1292,12 @@ function draw(panel) {
1241
1292
  if (ui.loading && !list) status.textContent = work ? `Loading the work from ${forgeName()} …` : specs ? 'Looking for proposals …' : `Loading ${kindWords()}s from ${forgeName()} …`;
1242
1293
  else if (!list) status.textContent = '';
1243
1294
  else if (work) status.textContent = workStatus(groups, list.at, now());
1244
- else if (specs) status.textContent = `${plural(list.items.length, 'open spec')}${list.at ? `, as of ${relativeTime(list.at, now())}` : ''}`;
1295
+ else if (specs) status.textContent = `${plural(list.items.length, 'proposal')}${list.at ? `, as of ${relativeTime(list.at, now())}` : ''}`;
1245
1296
  else status.textContent = `${shown.length} of ${plural(list.items.length, kindWords())}${list.at ? `, as of ${relativeTime(list.at, now())}` : ''}`;
1246
1297
 
1247
1298
  const notice = $('forge-notice');
1248
1299
  const words = ui.error || (list && list.stale ? `Showing an older answer. ${list.stale}` : '') || (specs && list && list.problem ? `The spec PRs could not be listed: ${list.problem}` : '') || (work && list && list.problem ? `Spec pull requests could not all be read: ${list.problem}` : '') || (ui.kind === 'threads' && list && list.problem ? `Some threads could not all be read: ${list.problem}` : '');
1249
- notice.hidden = !words;
1250
- notice.textContent = words;
1300
+ setNotice(notice, words, !!words);
1251
1301
 
1252
1302
  const act = $('forge-act-note');
1253
1303
  if (act) {
@@ -1259,13 +1309,16 @@ function draw(panel) {
1259
1309
  }
1260
1310
 
1261
1311
  const rows = $('forge-list');
1262
- if (!list) rows.innerHTML = '';
1312
+ const empty = (words) => `<li class="hx-forge-empty hx-faint" data-corn="empty">${escHtml(words)}</li>`;
1313
+ rows.setAttribute('aria-busy', String(!!ui.loading && !list));
1314
+ // A list that is being read holds its height with rows of the right size, so nothing jumps when the data comes
1315
+ if (!list) rows.innerHTML = ui.loading ? loadingRowsHtml(4) : '';
1263
1316
  else if (specs) {
1264
1317
  const open = state.proposal ? { slug: state.proposalSlug, source: state.proposalSource } : null;
1265
- rows.innerHTML = list.items.length ? list.items.map((e) => specRowHtml(e, { current: open })).join('') : '<li class="hx-forge-empty hx-faint">No proposals</li>';
1318
+ rows.innerHTML = list.items.length ? list.items.map((e) => specRowHtml(e, { current: open })).join('') : empty(emptyWords('specs', forgeName()));
1266
1319
  }
1267
- else if (work) rows.innerHTML = groups.length ? groupsHtml(groups) : `<li class="hx-forge-empty hx-faint">${ui.work.grouped.groups.length ? 'No work matches these filters.' : 'No work here yet.'}</li>`;
1268
- else rows.innerHTML = shown.length ? shown.map((i) => itemHtml(i)).join('') : `<li class="hx-forge-empty hx-faint">${list.items.length ? `No ${kindWords()} matches these filters.` : `No ${kindWords()}s here.`}</li>`;
1320
+ else if (work) rows.innerHTML = groups.length ? groupsHtml(groups) : empty(ui.work.grouped.groups.length ? 'No work matches these filters.' : emptyWords('work', forgeName()));
1321
+ else rows.innerHTML = shown.length ? shown.map((i) => itemHtml(i)).join('') : empty(list.items.length ? `No ${kindWords()} matches these filters.` : emptyWords(ui.kind, forgeName()));
1269
1322
 
1270
1323
  const detail = $('forge-detail');
1271
1324
  detail.hidden = !showing;
@@ -1278,6 +1331,7 @@ function draw(panel) {
1278
1331
  $('forge-rate').textContent = rate;
1279
1332
  paintRuns();
1280
1333
  paintButton();
1334
+ paintTabsMore();
1281
1335
  }
1282
1336
 
1283
1337
  /** The runs of the Agents tab: state, what each is about, links, and Stop. A runner's words are escaped like any text from the forge. */
@@ -1289,11 +1343,11 @@ function paintRuns() {
1289
1343
  const data = ui.runs && ui.runs.data;
1290
1344
  $('forge-runs-status').textContent = data ? runsStatus(data) : ui.loading ? 'Loading the runs …' : '';
1291
1345
  const note = $('forge-runs-note');
1292
- const words = (ui.runs && ui.runs.error) || (ui.runNote ? ui.runNote.text : '');
1293
- note.hidden = !words;
1294
- note.className = `hx-forge-notice${!(ui.runs && ui.runs.error) && ui.runNote && ui.runNote.ok ? ' hx-forge-notice--ok' : ''}`;
1295
- if (!(ui.runs && ui.runs.error) && ui.runNote && ui.runNote.ok) note.dataset.cornState = 'success'; else delete note.dataset.cornState;
1296
- note.textContent = words;
1346
+ const failed = ui.runs && ui.runs.error;
1347
+ const words = failed || (ui.runNote ? ui.runNote.text : '');
1348
+ note.className = `hx-forge-notice${!failed && ui.runNote && ui.runNote.ok ? ' hx-forge-notice--ok' : ''}`;
1349
+ if (!failed && ui.runNote && ui.runNote.ok) note.dataset.cornState = 'success'; else delete note.dataset.cornState;
1350
+ setNotice(note, words, !!failed);
1297
1351
  paintRunner('forge-runs-runner', data);
1298
1352
  const trig = $('forge-runs-trigger');
1299
1353
  if (trig) {
@@ -1314,8 +1368,77 @@ function paintRuns() {
1314
1368
  hand.innerHTML = lines.map((l) => `<li>${escHtml(l)}</li>`).join('');
1315
1369
  }
1316
1370
  const list = $('forge-runs-list');
1317
- if (!data) { list.innerHTML = ''; return; }
1318
- list.innerHTML = data.runs.length ? runsHtml(viewContext(), data.runs) : '<li class="hx-forge-empty hx-faint">No agent has been asked for yet. Start one from an issue or a proposal.</li>';
1371
+ list.setAttribute('aria-busy', String(!data && !!ui.loading));
1372
+ if (!data) { list.innerHTML = ui.loading ? loadingRowsHtml(3) : ''; return; }
1373
+ patchList(list, data.runs.length ? runsHtml(viewContext(), data.runs) : '<li class="hx-forge-empty hx-faint" data-corn="empty">No agent has been asked for yet. Start one from an issue or a proposal: Issues, then Start an agent.</li>');
1374
+ }
1375
+
1376
+ /**
1377
+ * Draws a list again without disturbing what the person is doing in it. The new rows are made first and set against the old by their key
1378
+ * (a run's id, a compare group's): a row that has not changed is left alone, a row that has is replaced, and **a row that holds the focus in
1379
+ * a field, or a reply typed and not sent, is kept as it is** (its result line is the one part brought up to date), so the caret, the
1380
+ * selection, the focus and the text stay where they were. A row whose field is no longer asked for is replaced like any other.
1381
+ */
1382
+ function patchList(list, html) {
1383
+ const tpl = document.createElement('template');
1384
+ tpl.innerHTML = html;
1385
+ const fresh = [...tpl.content.children];
1386
+ const keyOf = (el) => el.dataset.key || el.dataset.run || null;
1387
+ const old = new Map([...list.children].filter((el) => keyOf(el)).map((el) => [keyOf(el), el]));
1388
+ const typing = (el) => el.contains(document.activeElement) && document.activeElement.matches('input, textarea');
1389
+ const redraw = new Set(redrawRuns); // runs the page has just acted on: their cards say what the action did, so they are drawn anew (the focus is put back by hand)
1390
+ redrawRuns.clear();
1391
+ const unsent = (el) => [...el.querySelectorAll('[data-run-reply]')].some((f) => f.value !== '');
1392
+ const target = fresh.map((f) => {
1393
+ const was = keyOf(f) && old.get(keyOf(f));
1394
+ if (!was) return f;
1395
+ if (was.outerHTML === f.outerHTML) return was;
1396
+ const field = was.querySelector('[data-run-reply]');
1397
+ const twin = field && f.querySelector(`[data-run-reply="${field.dataset.runReply}"]`);
1398
+ if (!redraw.has(keyOf(f)) && (typing(was) || unsent(was)) && twin) {
1399
+ // The field stays (the very element, never taken out of the page, so the focus, caret, selection and a phone's keyboard stay);
1400
+ // everything around it is the new card's, so a state that changed is shown (graftAround)
1401
+ const theirs = twin.getAttribute('value') || '';
1402
+ graftAround(was, field, twin);
1403
+ // The typed text is in `ui.runReplies` as well, always (every keystroke); a field that differs from it was changed by the page itself
1404
+ if (field.value !== theirs) field.value = theirs;
1405
+ return was;
1406
+ }
1407
+ return f;
1408
+ });
1409
+ target.forEach((node, i) => {
1410
+ const at = list.children[i];
1411
+ if (at === node) return;
1412
+ if (at && keyOf(at) && keyOf(at) === keyOf(node)) at.replaceWith(node); else list.insertBefore(node, at || null);
1413
+ });
1414
+ while (list.children.length > target.length) list.lastElementChild.remove();
1415
+ }
1416
+
1417
+ /**
1418
+ * Makes `root` (an old row) what `fresh` (its new drawing) is, except that `keep` (inside `root`) stays the same element in the same place,
1419
+ * standing for `twin` (its match inside `fresh`): at each level from `keep` up to `root`, the parent takes the new parent's attributes and
1420
+ * children, with the kept branch in its place. `keep` itself is never taken out of the page.
1421
+ */
1422
+ function graftAround(root, keep, twin) {
1423
+ const sync = (to, from) => {
1424
+ for (const a of [...to.attributes]) if (!from.hasAttribute(a.name) && a.name !== 'value') to.removeAttribute(a.name);
1425
+ for (const a of [...from.attributes]) if (a.name !== 'value' && to.getAttribute(a.name) !== a.value) to.setAttribute(a.name, a.value);
1426
+ };
1427
+ sync(keep, twin);
1428
+ let w = keep;
1429
+ let f = twin;
1430
+ while (w !== root && w.parentElement && f.parentElement) {
1431
+ const wp = w.parentElement;
1432
+ const fp = f.parentElement;
1433
+ sync(wp, fp);
1434
+ const kids = [...fp.childNodes];
1435
+ const at = kids.indexOf(f);
1436
+ for (const n of [...wp.childNodes]) if (n !== w) n.remove();
1437
+ for (const n of kids.slice(0, at)) wp.insertBefore(n, w);
1438
+ for (const n of kids.slice(at + 1)) wp.append(n);
1439
+ w = wp;
1440
+ f = fp;
1441
+ }
1319
1442
  }
1320
1443
 
1321
1444
  /** The one line on whether a runner is polling (pull transport only), in the Runs view and the Start dialog; hidden where it does not apply */
@@ -1334,6 +1457,7 @@ function viewContext() {
1334
1457
  return {
1335
1458
  esc: escHtml, safeUrl, forgeName: forgeName(), forgeType: f ? f.type : 'github', repoUrl: base && f.repo ? `${base}/${f.repo}` : null,
1336
1459
  now: now(), nodes: state.nodes, selected: ui.runSel, timelines: ui.runTimelines, replies: ui.runReplies, busy: !!ui.busy,
1460
+ results: { get: (id) => resultOf(id) },
1337
1461
  };
1338
1462
  }
1339
1463
 
@@ -1377,8 +1501,7 @@ function drawNotes() {
1377
1501
  $('forge-status').textContent = n.loading && !n.data ? `Drafting the release notes from ${forgeName()} …` : n.data ? notesSummary(n.data) : '';
1378
1502
  const notice = $('forge-notice');
1379
1503
  const words = n.error || (n.data && n.data.stale ? `Showing an older answer. ${n.data.stale}` : '');
1380
- notice.hidden = !words;
1381
- notice.textContent = words;
1504
+ setNotice(notice, words, !!words);
1382
1505
  $('forge-detail').hidden = true;
1383
1506
  paintIdea();
1384
1507
  $('forge-rate').textContent = (n.data && n.data.rate) || '';
@@ -1584,13 +1707,7 @@ function onConfirmKey(e) {
1584
1707
  if (!ui.busy) closeConfirm();
1585
1708
  return;
1586
1709
  }
1587
- if (e.key !== 'Tab') return;
1588
- const buttons = [...confirmEl().querySelectorAll('button:not([disabled])')];
1589
- if (!buttons.length) { e.preventDefault(); return; }
1590
- const at = buttons.indexOf(document.activeElement);
1591
- const next = e.shiftKey ? (at <= 0 ? buttons.length - 1 : at - 1) : (at === -1 || at === buttons.length - 1 ? 0 : at + 1);
1592
- e.preventDefault();
1593
- buttons[next].focus();
1710
+ trapTab(e, confirmEl());
1594
1711
  }
1595
1712
 
1596
1713
  function onConfirmClick(e) {
@@ -1669,7 +1786,7 @@ async function startAgain(runId) {
1669
1786
  const res = await request(briefUrl(runId), false);
1670
1787
  ui.retrying = false;
1671
1788
  if (!res.ok || typeof res.body.brief !== 'string') {
1672
- ui.runNote = { text: `The brief of ${runId} could not be read, so Start again did not open: ${errorWords(res.status, res.body)}`, ok: false };
1789
+ ui.runNote = { text: `The brief of ${runId} could not be read, so Start again did not open: ${failWords(res)}`, ok: false };
1673
1790
  paint();
1674
1791
  announce(ui.runNote.text);
1675
1792
  return;
@@ -1784,13 +1901,7 @@ function onAgentKey(e) {
1784
1901
  if (!ui.agent || !ui.agent.posting) closeAgent();
1785
1902
  return;
1786
1903
  }
1787
- if (e.key !== 'Tab') return;
1788
- const fields = [...agentEl().querySelectorAll('select, textarea, input, button')].filter((el) => !el.disabled && !el.closest('[hidden]'));
1789
- if (!fields.length) { e.preventDefault(); return; }
1790
- const at = fields.indexOf(document.activeElement);
1791
- const next = e.shiftKey ? (at <= 0 ? fields.length - 1 : at - 1) : (at === -1 || at === fields.length - 1 ? 0 : at + 1);
1792
- e.preventDefault();
1793
- fields[next].focus();
1904
+ trapTab(e, agentEl());
1794
1905
  }
1795
1906
 
1796
1907
  function onAgentClick(e) {
@@ -1799,29 +1910,59 @@ function onAgentClick(e) {
1799
1910
  if (t.closest && t.closest('[data-action="agent-start-cancel"]') && ui.agent && !ui.agent.posting) closeAgent();
1800
1911
  }
1801
1912
 
1802
- /** Asks a run to stop: one POST, then the runs are read again */
1913
+ /** The runs whose card is drawn anew at the next paint, whatever holds the focus in it (the page itself changed what it says) */
1914
+ const redrawRuns = new Set();
1915
+
1916
+ /** Gives the focus to the first of `selectors` that is there and not disabled, inside the card of a run (else the card itself) */
1917
+ function focusInRun(runId, selectors) {
1918
+ const panel = $('forge-panel');
1919
+ const card = panel && [...panel.querySelectorAll('[data-run]')].find((c) => c.dataset.run === runId);
1920
+ if (!card) return;
1921
+ const to = selectors.map((sel) => card.querySelector(sel)).find((el) => el && !el.disabled) || card;
1922
+ if (to !== document.activeElement) to.focus();
1923
+ if (to.matches('input') && typeof to.setSelectionRange === 'function') to.setSelectionRange(to.value.length, to.value.length); // typing goes on at the end of what is there
1924
+ }
1925
+
1926
+ /** Back online: a tab that could not be read is read again, so its error does not outlive the cause (the same function each time, added once) */
1927
+ function readOnline() {
1928
+ if (ui.open && (ui.error || (ui.runs && ui.runs.error) || ui.detailError || (ui.kind === 'notes' && ui.notes.error))) refreshForge({ quiet: true });
1929
+ }
1930
+
1931
+ /** Lets go of a reply that was not sent because its run stopped waiting: the field goes, and the focus goes to the run's card */
1932
+ function discardReply(runId) {
1933
+ ui.runReplies.delete(runId);
1934
+ redrawRuns.add(runId);
1935
+ paint();
1936
+ focusInRun(runId, []);
1937
+ }
1938
+
1939
+ /** Asks a run to stop: one POST, then the runs are read again. What it came to is said in the run's own card, and to a screen reader */
1803
1940
  async function stopRun(runId) {
1804
1941
  if (ui.busy) return;
1805
1942
  ui.busy = 'stop';
1806
1943
  ui.runNote = null;
1807
- announce(`Asking ${runId} to stop`);
1944
+ clearResult(runId);
1945
+ announce('Asking this run to stop'); // the focus is in the run's card, whose controls name it
1808
1946
  paint();
1809
1947
  const res = await post(stopUrl(runId), {});
1810
1948
  ui.busy = '';
1811
- ui.runNote = { text: stopWords(res.status, res.body, runId), ok: res.ok };
1812
- announce(ui.runNote.text);
1949
+ sayResult(runId, res.status === null ? notSentWords('The stop request') : stopWords(res.status, res.body, 'this run'), res.ok);
1813
1950
  await loadRuns(false, { say: false });
1951
+ redrawRuns.add(runId);
1814
1952
  paint();
1953
+ // The Stop button is gone once the stop is asked for: the focus goes to the run's row, never to the page
1954
+ focusInRun(runId, [`[data-forge-stop="${runId}"]`]);
1815
1955
  }
1816
1956
 
1817
1957
  /** Answers a waiting run: Continue, Stop, or a reply with the text typed. One POST, then the runs are read again */
1818
1958
  async function answerRun(runId, action) {
1819
1959
  if (ui.busy) return;
1820
1960
  const text = ui.runReplies.get(runId) || '';
1961
+ clearResult(runId);
1821
1962
  if (action === 'reply' && text.trim() === '') {
1822
- ui.runNote = { text: 'Write a reply first.', ok: false };
1823
- announce(ui.runNote.text);
1963
+ sayResult(runId, 'Write a reply first.', false);
1824
1964
  paint();
1965
+ focusInRun(runId, [`[data-run-reply="${runId}"]`]);
1825
1966
  return;
1826
1967
  }
1827
1968
  // Where the focus goes back to once it is sent: the reply field after a reply (empty, for the next one), the button after Continue; while the
@@ -1829,18 +1970,17 @@ async function answerRun(runId, action) {
1829
1970
  const back = action === 'reply' ? `[data-run-reply="${runId}"]` : `[data-run-answer="${action}"][data-run-id="${runId}"]`;
1830
1971
  ui.busy = 'answer';
1831
1972
  ui.runNote = null;
1832
- announce(`Answering ${runId}`);
1973
+ announce(action === 'reply' ? 'Sending your reply' : 'Sending your answer');
1833
1974
  paint();
1834
1975
  const res = await post(answerUrl(runId), answerBody(action, text));
1835
1976
  ui.busy = '';
1836
- if (res.ok && action === 'reply') ui.runReplies.delete(runId);
1837
- ui.runNote = { text: answerWordsFor(res.status, res.body, runId, action), ok: res.ok };
1838
- announce(ui.runNote.text);
1977
+ if (res.ok && action === 'reply') ui.runReplies.delete(runId); // sent: the field is empty for the next; a reply that was not sent stays as it was typed
1978
+ const words = res.status === null ? notSentWords(action === 'reply' ? 'Your reply' : 'The answer') : answerWordsFor(res.status, res.body, 'this run', action);
1979
+ sayResult(runId, words, res.ok);
1839
1980
  await loadRuns(false, { say: false });
1981
+ redrawRuns.add(runId);
1840
1982
  paint();
1841
- const panel = $('forge-panel');
1842
- const to = panel && [back, `[data-run-timeline="${runId}"]`].map((sel) => panel.querySelector(sel)).find((el) => el && !el.disabled);
1843
- if (to && to !== document.activeElement) to.focus();
1983
+ focusInRun(runId, [back, `[data-run-timeline="${runId}"]`]);
1844
1984
  }
1845
1985
 
1846
1986
  // ---------------------------------------------------------------------------
@@ -1953,7 +2093,7 @@ async function issueNotListed(n) {
1953
2093
  announce(ui.actNote.text);
1954
2094
  return false;
1955
2095
  }
1956
- return linkMissing(res.status === 404 ? `There is no issue ${n}.` : errorWords(res.status, res.body));
2096
+ return linkMissing(res.status === 404 ? `There is no issue ${n}.` : failWords(res, `issue ${n}`));
1957
2097
  }
1958
2098
 
1959
2099
  /** Whether the Start dialog can open now: the server runs agents and the page has the dialog (the node panel's "Start a run" asks) */
@@ -2081,6 +2221,8 @@ function onClick(e) {
2081
2221
  if (goto) { goToRun(goto.dataset.runGoto); return; }
2082
2222
  const answer = t.closest('[data-run-answer]');
2083
2223
  if (answer) { answerRun(answer.dataset.runId, answer.dataset.runAnswer); return; }
2224
+ const discard = t.closest('[data-run-discard]');
2225
+ if (discard) { discardReply(discard.dataset.runDiscard); return; }
2084
2226
  const pick = t.closest('[data-run-select]');
2085
2227
  if (pick) { selectRun(pick.dataset.runSelect); return; }
2086
2228
  const timeline = t.closest('[data-run-timeline]');
@@ -2098,7 +2240,7 @@ function onClick(e) {
2098
2240
  const action = t.closest('[data-action]');
2099
2241
  if (!action) return;
2100
2242
  if (action.dataset.action === 'close-forge') closeForge();
2101
- else if (action.dataset.action === 'refresh-forge') refreshForge();
2243
+ else if (action.dataset.action === 'refresh-forge' || action.dataset.action === 'retry-forge') refreshForge();
2102
2244
  else if (action.dataset.action === 'copy-notes') copyNotes();
2103
2245
  else if (action.dataset.action === 'post-notes') { if (ui.notes.confirm) closeNotesConfirm(); else openNotesConfirm(); }
2104
2246
  else if (action.dataset.action === 'confirm-notes') postDraft();
@@ -2165,7 +2307,14 @@ function onChange(e) {
2165
2307
  }
2166
2308
 
2167
2309
  function onInput(e) {
2168
- if (e.target.dataset && e.target.dataset.runReply) { ui.runReplies.set(e.target.dataset.runReply, e.target.value); return; }
2310
+ if (e.target.dataset && e.target.dataset.runReply) {
2311
+ const id = e.target.dataset.runReply;
2312
+ ui.runReplies.set(id, e.target.value);
2313
+ // "Write a reply first" goes once something is written: a refusal does not outlive what it was about
2314
+ const said = resultOf(id);
2315
+ 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); }
2316
+ return;
2317
+ }
2169
2318
  if (e.target.id !== 'forge-text') return;
2170
2319
  ui.filters.text = e.target.value;
2171
2320
  filtersChanged(false);
@@ -2234,6 +2383,11 @@ export function initForgePanel(config, opts = {}) {
2234
2383
  }
2235
2384
  if (!wired) {
2236
2385
  wired = true;
2386
+ initConnection();
2387
+ if (typeof window !== 'undefined') window.addEventListener('online', readOnline);
2388
+ const tabs = panel.querySelector('.hx-forge-tabs');
2389
+ if (tabs) tabs.addEventListener('scroll', paintTabsMore, { passive: true });
2390
+ if (typeof window !== 'undefined') window.addEventListener('resize', paintTabsMore);
2237
2391
  wireToggles();
2238
2392
  panel.addEventListener('click', onClick);
2239
2393
  panel.addEventListener('change', onChange);
@@ -2302,4 +2456,6 @@ export function resetForgePanelForTests(clock = () => Date.now()) {
2302
2456
  pageAway = false;
2303
2457
  clearRunsOnMap();
2304
2458
  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 });
2459
+ resetFeedbackForTests();
2460
+ resetConnectionForTests();
2305
2461
  }