@giamme/forge 0.13.0 → 0.13.1

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.
@@ -25,7 +25,7 @@
25
25
  };
26
26
  const DIFFS = ['low', 'medium', 'high'];
27
27
 
28
- // FNV-1a: a short stable id for a project (its repo path)
28
+ // FNV-1a: a short stable id for a project (its repository root)
29
29
  function hashId(s) {
30
30
  let h = 0x811c9dc5;
31
31
  for (let i = 0; i < s.length; i++) { h ^= s.charCodeAt(i); h = Math.imul(h, 0x01000193) >>> 0; }
@@ -35,11 +35,13 @@
35
35
  const startOf = r => num(r.created) ?? num(r.updated) ?? 0;
36
36
 
37
37
  /* ---------- projects and per-run facts ---------- */
38
+ // a run's project is its repository root (RM.repoKey), so a run started from a worktree joins its repository's project
39
+ const projectId = r => hashId(RM.repoKey(r) || '?');
38
40
  function projects(runs) {
39
41
  const by = new Map();
40
42
  for (const r of list(runs)) {
41
- const repo = r.repo || '?', id = hashId(repo);
42
- if (!by.has(id)) by.set(id, { id, repo: r.repo || null, name: RM.basename(r.repo), keys: [], first: Infinity, last: -Infinity, count: 0 });
43
+ const id = projectId(r), key = RM.repoKey(r);
44
+ if (!by.has(id)) by.set(id, { id, repo: key, name: RM.basename(key), keys: [], first: Infinity, last: -Infinity, count: 0 });
43
45
  const p = by.get(id), t = startOf(r);
44
46
  p.keys.push(r.key); p.count++; p.first = Math.min(p.first, t); p.last = Math.max(p.last, num(r.updated) ?? t);
45
47
  }
@@ -61,7 +63,7 @@
61
63
  if (state === 'live' && num(now) !== null && num(run.updated) !== null && now - run.updated > 7200) state = 'stale';
62
64
  const n = Math.max(1, num(run.task_count) || tasks.length || 1);
63
65
  const aliases = specs => new Set(list(specs).map(RM.alias).filter(Boolean));
64
- return { key: run.key, run, project: hashId(run.repo || '?'), n, bucket: bucket(n), diff, dominant, state, t: startOf(run),
66
+ return { key: run.key, run, project: projectId(run), checkout: hashId(run.repo || '?'), n, bucket: bucket(n), diff, dominant, state, t: startOf(run),
65
67
  dwarf: aliases(run.dwarf_models || run.models), qa: aliases(run.qa_models || []), all: aliases(run.models),
66
68
  review: RM.runReviewStatus(run) || null, verification: run.verification_status || null, decompose: run.decompose_level || null, kind: run.kind };
67
69
  }
@@ -89,7 +91,8 @@
89
91
  const hay = [r.goal, r.repo, r.run_id, r.path, ...list(r.models), ...list(r.task_statuses).flatMap(t => [t.id, t.title])];
90
92
  if (!hay.some(v => String(v || '').toLowerCase().includes(text))) return false;
91
93
  }
92
- if (f.projects.length && !f.projects.includes(fact.project)) return false;
94
+ // a saved project may be the checkout a run started in (a worktree, before it joined its root): the run still matches it
95
+ if (f.projects.length && !f.projects.includes(fact.project) && !f.projects.includes(fact.checkout)) return false;
93
96
  if (f.states.length && !f.states.includes(fact.state)) return false;
94
97
  if (f.kinds.length && !f.kinds.includes(fact.kind)) return false;
95
98
  if (f.difficulty.levels.length) {
@@ -59,15 +59,17 @@
59
59
  function inPeriod(created, f, now) {
60
60
  return !f.days || num(now) === null || (num(created) !== null && created >= now - f.days * DAY);
61
61
  }
62
- // a run's own facts (repo, kind, created): from its task rows, else from the run summaries
62
+ // a run's own facts (repo, repo_root, kind, created): from its task rows, else from the run summaries
63
63
  function runIndex(data, runs) {
64
64
  const by = new Map();
65
- for (const t of list(data.tasks)) if (obj(t) && t.run && !by.has(t.run)) by.set(t.run, { repo: t.repo || null, kind: t.kind || null, created: num(t.created) });
66
- for (const r of list(runs)) if (obj(r) && r.key && !by.has(r.key)) by.set(r.key, { repo: r.repo || null, kind: r.kind || null, created: num(r.created) });
65
+ for (const t of list(data.tasks)) if (obj(t) && t.run && !by.has(t.run)) by.set(t.run, { repo: t.repo || null, repo_root: t.repo_root || null, kind: t.kind || null, created: num(t.created) });
66
+ for (const r of list(runs)) if (obj(r) && r.key && !by.has(r.key)) by.set(r.key, { repo: r.repo || null, repo_root: r.repo_root || null, kind: r.kind || null, created: num(r.created) });
67
67
  return by;
68
68
  }
69
+ // a project is a repository root; a saved project that names the checkout a row started in still matches that row
70
+ const inProject = (row, project) => !project || RM.repoKey(row) === project || row.repo === project;
69
71
  function taskMatch(t, f, now) {
70
- if (f.project && t.repo !== f.project) return false;
72
+ if (!inProject(t, f.project)) return false;
71
73
  if (f.difficulty && diffOf(t) !== f.difficulty) return false;
72
74
  if (f.kind && t.kind !== f.kind) return false;
73
75
  if (!inPeriod(t.created, f, now)) return false;
@@ -81,8 +83,9 @@
81
83
  if (t) return taskMatch(t, f, now);
82
84
  }
83
85
  if (f.difficulty || f.exploratoryOnly) return false;
84
- const r = runs.get(v.run) || {};
85
- if (f.project && r.repo !== f.project) return false;
86
+ // no run summary loaded yet: the review row's own repo_root (reviews carry no repo) still names the project
87
+ const r = runs.get(v.run) || { repo_root: v.repo_root || null };
88
+ if (!inProject(r, f.project)) return false;
86
89
  if (f.kind && r.kind !== f.kind) return false;
87
90
  return inPeriod(r.created, f, now);
88
91
  }
@@ -101,7 +104,8 @@
101
104
  const repos = new Map(), diff = {}, kinds = {}, aliases = new Set();
102
105
  let first = null, last = null, explored = 0;
103
106
  for (const t of tasks) {
104
- if (t.repo) repos.set(t.repo, (repos.get(t.repo) || 0) + 1);
107
+ const key = RM.repoKey(t);
108
+ if (key) repos.set(key, (repos.get(key) || 0) + 1);
105
109
  const d = diffOf(t); diff[d] = (diff[d] || 0) + 1;
106
110
  if (t.kind) kinds[t.kind] = (kinds[t.kind] || 0) + 1;
107
111
  const c = num(t.created);
@@ -114,7 +118,7 @@
114
118
  for (const v of list(data.reviews)) {
115
119
  if (!obj(v)) continue;
116
120
  const x = aliasOf(v); if (x) aliases.add(x);
117
- const r = idx.get(v.run); if (r && r.repo && !repos.has(r.repo)) repos.set(r.repo, 0);
121
+ const key = RM.repoKey(idx.get(v.run) || v); if (key && !repos.has(key)) repos.set(key, 0);
118
122
  }
119
123
  return {
120
124
  projects: projectNames(repos),
@@ -22,6 +22,22 @@
22
22
  const weight = t => WEIGHT[String(t && t.difficulty || '').toLowerCase()] || 2;
23
23
  const alias = spec => spec ? String(spec).split(':')[0] : null;
24
24
  const basename = p => p ? String(p).split(/[\\/]/).filter(Boolean).pop() || String(p) : '—';
25
+ // What a run (or a models row) is grouped under: its repository root, else the checkout it started in (an older server).
26
+ const repoKey = run => (run && (run.repo_root || run.repo)) || null;
27
+ // The run list's "by repo" order: the name of each run's repository root.
28
+ const compareRepo = (a, b) => basename(repoKey(a)).localeCompare(basename(repoKey(b)));
29
+ // What a run shows where its repository is named. `name` is the root's basename. `worktree` is the
30
+ // checkout it started in when that is not the root — "forge-c2 (fix/milestone-c2)", or the basename
31
+ // alone when the branch is unknown — and null for the main checkout. A summary that lacks
32
+ // repo_root, repo_worktree and repo_branch (an older server or export) keeps basename(repo).
33
+ const repoLabel = run => {
34
+ const name = basename(run && (run.repo_root || run.repo));
35
+ const path = run && typeof run.repo_worktree === 'string' ? run.repo_worktree : '';
36
+ if (!path) return { name, worktree: null };
37
+ const branch = typeof run.repo_branch === 'string' ? run.repo_branch.trim() : '';
38
+ const leaf = basename(path);
39
+ return { name, worktree: branch ? `${leaf} (${branch})` : leaf };
40
+ };
25
41
  function fmtDur(s) {
26
42
  s = num(s); if (s === null) return '—';
27
43
  s = Math.max(0, Math.round(s));
@@ -112,7 +128,8 @@
112
128
  const text = String(f.text || '').trim().toLowerCase();
113
129
  if (text && ![run.goal, run.repo, run.run_id, run.path, ...list(run.models)].some(v => String(v || '').toLowerCase().includes(text))) return false;
114
130
  if (f.state && runState(run) !== f.state) return false;
115
- if (f.repo && run.repo !== f.repo) return false;
131
+ // a saved filter may name the checkout a run started in (a worktree) rather than its root: it still matches that run
132
+ if (f.repo && repoKey(run) !== f.repo && run.repo !== f.repo) return false;
116
133
  if (f.kind && run.kind !== f.kind) return false;
117
134
  if (f.model && !list(run.models).some(m => alias(m) === f.model)) return false;
118
135
  if (f.ageDays && num(now) !== null && !(num(run.updated) !== null && run.updated >= now - f.ageDays * 86400)) return false;
@@ -127,7 +144,8 @@
127
144
  function filterOptions(runs) {
128
145
  const repos = new Map(), models = new Set();
129
146
  for (const r of list(runs)) {
130
- if (r.repo && !repos.has(r.repo)) repos.set(r.repo, basename(r.repo));
147
+ const key = repoKey(r);
148
+ if (key && !repos.has(key)) repos.set(key, basename(key));
131
149
  for (const m of list(r.models)) if (alias(m)) models.add(alias(m));
132
150
  }
133
151
  return { repos: [...repos].map(([path, name]) => ({ path, name })), models: [...models].sort() };
@@ -145,11 +163,12 @@
145
163
  shown = (recent.length >= Math.min(floor, sorted.length) ? recent : sorted.slice(0, floor)).slice(0, limit);
146
164
  }
147
165
  const layers = [], seen = new Set();
166
+ const layerOf = r => 'repo:' + (repoKey(r) || '?');
148
167
  for (const r of shown) {
149
- const id = 'repo:' + (r.repo || '?');
150
- if (!seen.has(id)) { seen.add(id); layers.push({ id, name: basename(r.repo), repo: r.repo || null }); }
168
+ const id = layerOf(r), key = repoKey(r);
169
+ if (!seen.has(id)) { seen.add(id); layers.push({ id, name: basename(key), repo: key }); }
151
170
  }
152
- const modules = shown.map(r => ({ id: r.key, layer: 'repo:' + (r.repo || '?'), run: r, state: runState(r),
171
+ const modules = shown.map(r => ({ id: r.key, layer: layerOf(r), run: r, state: runState(r),
153
172
  tasks: list(r.task_statuses).length ? list(r.task_statuses) : Object.entries(r.counts || {}).flatMap(([s, n]) => Array.from({ length: Math.min(n, 60) }, (_, i) => ({ id: s + i, status: s }))),
154
173
  match: matchRun(r, f, now) }));
155
174
  const p = plate({ modules, layers }, atlasSize);
@@ -893,7 +912,7 @@
893
912
  return { pos, edges, cols, rows: next };
894
913
  }
895
914
 
896
- return { liveNow, runState, execStatus, matchRun, filterOptions, atlasModel, columns, planModel, finishState,
915
+ return { liveNow, runState, execStatus, matchRun, filterOptions, atlasModel, repoKey, repoLabel, compareRepo, columns, planModel, finishState,
897
916
  finalStatus, runReviewStatus, reviewSinceLine, reviewAt, taskStatus, taskVerdict, attemptStatus, attemptNote, attemptFailed, isWaiting,
898
917
  attributionLine, taskParts,
899
918
  taskTimes, metricValue, overlap, projectSchedule, execModel, verifyLeds, criticalPath, concurrency, stateAt, timeRange, events, lineage, structureKey, innerKey,
@@ -10,10 +10,11 @@
10
10
  with controls on. */
11
11
  (function (root, factory) {
12
12
  'use strict';
13
- const api = factory(root);
13
+ const RM = typeof module === 'object' && module.exports ? require('./runmodel.js') : root.ForgeRunModel;
14
+ const api = factory(root, RM);
14
15
  if (typeof module === 'object' && module.exports) module.exports = api;
15
16
  else root.ForgeSettings = api;
16
- })(typeof self !== 'undefined' ? self : this, function (root) {
17
+ })(typeof self !== 'undefined' ? self : this, function (root, RM) {
17
18
  'use strict';
18
19
 
19
20
  const FILES = ['verify', 'setup', 'verify-subset'];
@@ -172,7 +173,7 @@
172
173
  }
173
174
 
174
175
  // The runs a repository can be taken from (those that name one), newest first.
175
- const withRepo = runs => list(runs).filter(r => r && r.key != null && typeof r.repo === 'string' && r.repo);
176
+ const withRepo = runs => list(runs).filter(r => r && r.key != null && typeof RM.repoKey(r) === 'string');
176
177
  const newestFirst = (a, b) => (Number(b.updated) || 0) - (Number(a.updated) || 0);
177
178
  // The run whose repository the page opens on: the current run when it is in the list, else the most recent one.
178
179
  function pickDefault(runs, current) {
@@ -181,19 +182,37 @@
181
182
  const latest = usable.slice().sort(newestFirst)[0];
182
183
  return latest ? latest.key : null;
183
184
  }
184
- // The choices grouped by repository: [{repo, name, runs}], the repository of the newest run first.
185
+ // The choices grouped by repository root: [{repo, name, runs}], the repository of the newest run first.
185
186
  function groupRuns(runs) {
186
187
  const groups = new Map();
187
188
  for (const r of withRepo(runs).sort(newestFirst)) {
188
- if (!groups.has(r.repo)) groups.set(r.repo, { repo: r.repo, name: basename(r.repo), runs: [] });
189
- groups.get(r.repo).runs.push(r);
189
+ const repo = RM.repoKey(r);
190
+ if (!groups.has(repo)) groups.set(repo, { repo, name: basename(repo), runs: [] });
191
+ groups.get(repo).runs.push(r);
190
192
  }
191
193
  return [...groups.values()];
192
194
  }
195
+ // The run inside its repository's group. The worktree it started in belongs to the run too, and the picker shows it
196
+ // beside this label as secondary text; the group names the repository.
193
197
  const optionLabel = r => {
194
198
  const goal = text(r.goal).split('\n')[0].trim();
195
- return [r.run_id || r.key, goal.length > 60 ? goal.slice(0, 59) + '…' : goal].filter(Boolean).join(' · ');
199
+ const short = goal.length > 60 ? goal.slice(0, 59) + '…' : goal;
200
+ return [r.run_id || r.key, short].filter(Boolean).join(' · ');
196
201
  };
202
+ // The option the picker's type-ahead lands on: the first label that starts with `query`, ignoring case, searching on from
203
+ // the active one `from` and wrapping round; -1 when none does. One letter typed again and again steps through the labels
204
+ // that start with it, so the search starts after the active label; a longer query starts at it, which stays put.
205
+ function typeAhead(labels, from, query) {
206
+ const all = list(labels), q = text(query).toLowerCase();
207
+ if (!q || !all.length) return -1;
208
+ const repeat = [...q].every(ch => ch === q[0]);
209
+ const want = repeat ? q[0] : q, start = repeat ? from + 1 : Math.max(from, 0);
210
+ for (let i = 0; i < all.length; i++) {
211
+ const at = (start + i) % all.length;
212
+ if (text(all[at]).toLowerCase().startsWith(want)) return at;
213
+ }
214
+ return -1;
215
+ }
197
216
 
198
217
  // An editor's unsaved text. `base` is the file as last read, `draft` the textarea (null: untouched). The CLI ends a saved
199
218
  // file with a newline, so trailing newlines do not count as an edit.
@@ -226,7 +245,7 @@
226
245
  function render(host, ctx) {
227
246
  const UI = root.ForgeUI, c = ctx || {};
228
247
  const el = (tag, t, cls) => UI.el(tag, t, cls);
229
- const s = { run: null, data: null, dataText: null, error: null, writes: false, loading: true, editors: {}, moved: {}, models: {}, modelMoved: {}, hold: 0, redraw: false, seq: 0, gen: 0, runsSig: null, ready: false, loadedAt: 0, repo: null, gone: false, asking: 0, asks: 0, pickerLate: false };
248
+ const s = { run: null, data: null, dataText: null, error: null, writes: false, loading: true, editors: {}, moved: {}, models: {}, modelMoved: {}, hold: 0, redraw: false, seq: 0, gen: 0, runsSig: null, ready: false, loadedAt: 0, repo: null, gone: false, asking: 0, asks: 0, pickerLate: false, listOpen: false };
230
249
  const key_ = (label, cls, onclick) => { const b = el('button', label, cls); b.type = 'button'; if (onclick) b.addEventListener('click', onclick); return b; };
231
250
 
232
251
  const head = el('header', undefined, 'set-head');
@@ -243,10 +262,26 @@
243
262
  host.replaceChildren(head, picker, note, stale, body);
244
263
  const staleNote = msg => { stale.hidden = !msg; stale.textContent = msg ? `The last read of the configuration failed: ${msg}. This shows the read before it; the next refresh tries again.` : ''; };
245
264
 
246
- /* the repository picker */
265
+ /* the repository picker: a button and a listbox rather than a native select, whose options hold plain text only, so
266
+ that each run can show the worktree it started in as secondary text. */
267
+ // The repository the configuration was read from, as the server answered; until then the run's root.
268
+ const repoPath = () => text(object(object(s.data).repo).path) || s.repo || '';
269
+ // A run as the picker shows it: its label, then its worktree as secondary text, with the full path and branch in its title.
270
+ function runFace(r) {
271
+ const face = [el('span', optionLabel(r), 'set-run-label')];
272
+ const worktree = RM.repoLabel(r).worktree;
273
+ if (worktree) {
274
+ const wt = el('span', worktree, 'muted repo-wt');
275
+ const branch = typeof r.repo_branch === 'string' ? r.repo_branch.trim() : '';
276
+ wt.title = r.repo_worktree + (branch ? `\nbranch ${branch}` : '');
277
+ face.push(wt);
278
+ }
279
+ return face;
280
+ }
247
281
  function drawPicker() {
248
- // The switch confirm lives in the picker: while it is open the rebuild waits, and runs when it is answered.
249
- if (s.asking) { s.pickerLate = true; return; }
282
+ // The switch confirm lives in the picker, and the open list is part of it: while either is open the rebuild waits,
283
+ // and runs when the confirm is answered or the list closes.
284
+ if (s.asking || s.listOpen) { s.pickerLate = true; return; }
250
285
  const runs = c.runs ? c.runs() : [];
251
286
  const groups = groupRuns(runs);
252
287
  const before = s.run, usable = withRepo(runs);
@@ -255,48 +290,130 @@
255
290
  if (s.run != null && !usable.some(r => r.key === s.run)) {
256
291
  // The run left the list. Another run of the same repository carries on with the editors as they are; with unsaved
257
292
  // text and no such run the page stays on it, flagged, rather than throwing the text away.
258
- const sibling = usable.slice().sort(newestFirst).find(r => r.repo === s.repo);
293
+ const sibling = usable.slice().sort(newestFirst).find(r => RM.repoKey(r) === s.repo);
259
294
  if (sibling) { s.run = sibling.key; kept = true; }
260
295
  else if (FILES.some(n => isDirty(s.editors[n]))) s.gone = true;
261
296
  else s.run = null;
262
297
  }
263
298
  if (s.run == null) s.run = pickDefault(runs, c.key);
264
299
  const now = usable.find(r => r.key === s.run);
265
- if (now) s.repo = now.repo;
300
+ if (now) s.repo = RM.repoKey(now);
266
301
  if (s.run !== before) {
267
302
  if (!kept) resetRun();
268
303
  if (s.ready) { if (!kept) drawBody(); load(); } // the default arrived, or the run went away
269
304
  }
270
- const sig = JSON.stringify([s.run, s.gone, groups.map(g => [g.repo, g.runs.map(r => [r.key, optionLabel(r)])])]);
305
+ const sig = JSON.stringify([s.run, s.gone, repoPath(), groups.map(g => [g.repo, g.runs.map(r => [r.key, optionLabel(r), r.repo_worktree || null, r.repo_branch || null])])]);
271
306
  if (sig === s.runsSig) return;
272
307
  s.runsSig = sig;
273
308
  if (!groups.length) { picker.replaceChildren(el('p', 'No run names a repository yet, so there is nothing to configure.', 'muted')); return; }
274
- const sel = el('select'); sel.id = 'set-run';
275
- if (s.gone) { const o = el('option', 'This run is no longer listed'); o.value = ''; o.selected = true; o.disabled = true; sel.append(o); }
276
- for (const g of groups) {
277
- const og = el('optgroup'); og.label = g.name + ' · ' + g.repo;
278
- for (const r of g.runs) { const o = el('option', optionLabel(r)); o.value = r.key; o.selected = r.key === s.run; og.append(o); }
279
- sel.append(og);
309
+ const refocus = document.activeElement && document.activeElement.id === 'set-run';
310
+ const current = s.gone ? null : usable.find(r => r.key === s.run);
311
+
312
+ const btn = el('button', undefined, 'set-run'); btn.type = 'button'; btn.id = 'set-run';
313
+ btn.dataset.run = current ? current.key : '';
314
+ btn.setAttribute('aria-haspopup', 'listbox'); btn.setAttribute('aria-expanded', 'false');
315
+ btn.setAttribute('aria-controls', 'set-run-list'); btn.setAttribute('aria-labelledby', 'set-run-cap set-run');
316
+ if (current) btn.append(...runFace(current));
317
+ else btn.append(el('span', 'This run is no longer listed', 'set-run-label'));
318
+ const pop = el('div', undefined, 'set-run-pop popover'); pop.popover = 'auto'; pop.id = 'set-run-pop';
319
+ const box = el('div', undefined, 'set-run-list'); box.id = 'set-run-list'; box.tabIndex = -1;
320
+ box.setAttribute('role', 'listbox'); box.setAttribute('aria-labelledby', 'set-run-cap');
321
+ const options = [];
322
+ groups.forEach((g, i) => {
323
+ const group = el('div', undefined, 'set-run-group'); group.setAttribute('role', 'group');
324
+ const name = el('div', undefined, 'set-run-group-name'); name.id = 'set-run-g' + i;
325
+ name.append(el('span', g.name, 'plate'), el('span', g.repo, 'muted mono'));
326
+ group.setAttribute('aria-labelledby', name.id); group.append(name);
327
+ for (const r of g.runs) {
328
+ const o = el('div', undefined, 'set-run-opt'); o.id = 'set-run-o-' + r.key; o.dataset.run = r.key;
329
+ o.setAttribute('role', 'option'); o.setAttribute('aria-selected', String(r.key === btn.dataset.run));
330
+ o.append(...runFace(r)); group.append(o); options.push(o);
331
+ }
332
+ box.append(group);
333
+ });
334
+ pop.append(box);
335
+
336
+ let active = -1, query = '', queryAt = 0; // the type-ahead's letters, and when the last came
337
+ const typing = () => query !== '' && Date.now() - queryAt < 700;
338
+ function activate(i) {
339
+ active = i;
340
+ options.forEach((o, j) => o.classList.toggle('is-active', j === i));
341
+ if (i < 0) { box.removeAttribute('aria-activedescendant'); return; }
342
+ box.setAttribute('aria-activedescendant', options[i].id);
343
+ options[i].scrollIntoView({ block: 'nearest' });
280
344
  }
281
- sel.addEventListener('change', async () => {
345
+ const isOpen = () => pop.matches(':popover-open');
346
+ const close = () => { s.listOpen = false; btn.setAttribute('aria-expanded', 'false'); if (isOpen()) pop.hidePopover(); };
347
+ btn.popoverTargetElement = pop; // a click toggles the list; Escape or a click elsewhere closes it
348
+ btn.addEventListener('keydown', e => {
349
+ if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;
350
+ e.preventDefault();
351
+ if (!isOpen()) pop.showPopover();
352
+ });
353
+ // The open state as the list starts to open or close (beforetoggle runs at once); where it sits and the focus once it has
354
+ // (toggle runs after).
355
+ pop.addEventListener('beforetoggle', e => {
356
+ s.listOpen = e.newState === 'open'; btn.setAttribute('aria-expanded', String(s.listOpen));
357
+ });
358
+ pop.addEventListener('toggle', e => {
359
+ if (e.newState === 'open') {
360
+ // under the button, or above it when the button sits low on the screen
361
+ const r = btn.getBoundingClientRect();
362
+ pop.style.minWidth = Math.round(r.width) + 'px';
363
+ const h = pop.offsetHeight, below = window.innerHeight - r.bottom > h + 16;
364
+ pop.style.left = Math.round(Math.max(8, Math.min(window.innerWidth - pop.offsetWidth - 8, r.left))) + 'px';
365
+ pop.style.top = Math.round(below ? r.bottom + 4 : Math.max(8, r.top - h - 4)) + 'px';
366
+ query = '';
367
+ activate(Math.max(0, options.findIndex(o => o.dataset.run === btn.dataset.run)));
368
+ box.focus({ preventScroll: true });
369
+ return;
370
+ }
371
+ // Focus left with the list goes back to the button, the one on the page now (a choice may have rebuilt it).
372
+ const at = document.activeElement;
373
+ if (!at || at === document.body || pop.contains(at)) { const b = document.getElementById('set-run'); if (b) b.focus({ preventScroll: true }); }
374
+ if (s.pickerLate && !s.asking) { s.pickerLate = false; drawPicker(); }
375
+ });
376
+ box.addEventListener('keydown', e => {
377
+ const k = e.key, last = options.length - 1;
378
+ if (k === 'ArrowDown') activate(Math.min(last, active + 1));
379
+ else if (k === 'ArrowUp') activate(Math.max(0, active - 1));
380
+ else if (k === 'Home') activate(0);
381
+ else if (k === 'End') activate(last);
382
+ else if (k === 'Enter' || (k === ' ' && !typing())) { if (active >= 0) choose(options[active].dataset.run); }
383
+ else if (k === 'Tab') { close(); return; }
384
+ else if (k.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
385
+ query = (typing() ? query : '') + k; queryAt = Date.now();
386
+ const at = typeAhead(options.map(o => o.firstChild.textContent), active, query);
387
+ if (at >= 0) activate(at);
388
+ } else return;
389
+ e.preventDefault();
390
+ });
391
+ box.addEventListener('mousemove', e => { const o = e.target.closest('[role=option]'); if (o && options.indexOf(o) !== active) activate(options.indexOf(o)); });
392
+ box.addEventListener('click', e => { const o = e.target.closest('[role=option]'); if (o) choose(o.dataset.run); });
393
+ async function choose(key) {
394
+ close();
395
+ if (key === btn.dataset.run) return; // the run already shown
282
396
  const unsaved = FILES.filter(n => s.editors[n] && isDirty(s.editors[n]));
283
397
  if (unsaved.length) {
284
398
  const ask = s.asking = ++s.asks;
285
399
  const yes = await UI.confirmInline(picker, `Switch repository and discard the unsaved edits to ${unsaved.map(n => '.forge/' + n).join(', ')}?`, { danger: true });
286
- if (s.asking !== ask) return; // a later change asked again, and that confirm decides
400
+ if (s.asking !== ask) return; // a later choice asked again, and that confirm decides
287
401
  const late = s.pickerLate;
288
402
  s.asking = 0; s.pickerLate = false;
289
- if (!yes) { sel.value = s.gone ? '' : s.run; if (late) drawPicker(); return; }
403
+ if (!yes) { if (late) drawPicker(); return; }
290
404
  }
291
- pick(sel.value);
292
- });
405
+ pick(key);
406
+ }
407
+
293
408
  const lab = el('label', undefined, 'set-field'); lab.htmlFor = 'set-run';
294
- lab.append(el('span', 'Repository of run', 'plate'));
409
+ const cap = el('span', 'Repository of run', 'plate'); cap.id = 'set-run-cap';
410
+ lab.append(cap);
295
411
  const path = el('p', undefined, 'set-repo-path');
296
- path.append(el('i', undefined, 'lamp lamp-route'), el('span', s.repo || '', 'mono'));
297
- const row = el('div', undefined, 'set-picker-row'); row.append(lab, sel);
412
+ path.append(el('i', undefined, 'lamp lamp-route'), el('span', repoPath(), 'mono'));
413
+ const row = el('div', undefined, 'set-picker-row'); row.append(lab, btn, pop);
298
414
  picker.replaceChildren(row, path);
299
415
  if (s.gone) picker.append(el('p', 'The run is gone from the list. Your unsaved edits are kept; pick another run to continue, which discards them.', 'warn set-problem'));
416
+ if (refocus) btn.focus({ preventScroll: true });
300
417
  }
301
418
  // A new run: nothing of the old one stays, and confirms of the old body (now detached) no longer hold a redraw.
302
419
  function resetRun() {
@@ -340,6 +457,7 @@
340
457
  const t = JSON.stringify(res.data);
341
458
  if (t === s.dataText && !s.redraw) return;
342
459
  s.data = res.data; s.dataText = t;
460
+ drawPicker(); // its path line names the repository this read came from
343
461
  if (s.hold > 0) { s.redraw = true; return; } // a confirm or a write is open: draw after it
344
462
  drawBody();
345
463
  }
@@ -725,6 +843,6 @@
725
843
  }
726
844
 
727
845
  return { render, configBody, repoKey, gateKey, targetPath, subsetOk, valueProblem, decideTextProblem, describeDecide, gateTags, replayDate,
728
- pickDefault, groupRuns, optionLabel, editorOf, isDirty, dirtyState, edited, typed, shown, readFailure,
846
+ pickDefault, groupRuns, optionLabel, typeAhead, editorOf, isDirty, dirtyState, edited, typed, shown, readFailure,
729
847
  FILES, GATES, MODES, VALUE_MAX, DECIDE_VALUE_MAX, ADD_COMMAND };
730
848
  });
@@ -307,6 +307,13 @@ body.resizing.rows { cursor: row-resize; }
307
307
  .run-sub { display: flex; gap: var(--s-2); align-items: baseline; font-size: var(--t-xs); color: var(--muted); min-width: 0; white-space: nowrap; }
308
308
  .run-sub .mono { font-size: var(--t-xs); overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
309
309
  .run-sub .repo { color: var(--ink-2); font-weight: 600; flex: none; }
310
+ /* the repository name and, for a worktree run, its checkout: the name never gives way; the worktree's leaf truncates first, its branch keeps its place */
311
+ .repo-line { display: inline-flex; align-items: baseline; max-width: 100%; min-width: 0; overflow: hidden; vertical-align: baseline; }
312
+ .repo-line > .repo { flex: none; }
313
+ .run-sub .repo-line { flex: 0 1 auto; }
314
+ .repo-wt { display: flex; align-items: baseline; min-width: 0; color: var(--muted); font-weight: 400; white-space: nowrap; }
315
+ .repo-leaf { flex: 0 100 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; } /* shrinks far more than the branch, which only gives way once the leaf is gone */
316
+ .repo-branch { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
310
317
  .run-sub .updated { margin-left: auto; flex: none; }
311
318
  .run-item .chips { margin-top: 3px; }
312
319
  .run-item .chip { font-size: .786rem; padding: 0 5px 0 4px; }
@@ -500,11 +507,15 @@ dialog.keys-sheet::backdrop { background: light-dark(rgb(17 22 19 / .35), rgb(0
500
507
  .run-title-row { display: flex; align-items: center; gap: 6px var(--s-3); min-width: 0; }
501
508
  .run-title-row > .lamp { margin-right: -4px; }
502
509
  .run-title-row > h2 { flex: 1 1 auto; min-width: 14ch; margin: 0; font-size: var(--t-md); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
503
- .run-where { flex: none; white-space: nowrap; color: var(--muted); font-size: var(--t-sm); } /* the id is copied: only the goal gives way */
510
+ .run-where { flex: 0 1 auto; min-width: 0; display: flex; align-items: baseline; gap: 0 var(--s-2); white-space: nowrap; color: var(--muted); font-size: var(--t-sm); } /* the id is copied: only the goal and the worktree give way */
511
+ .run-where > .mono { flex: none; }
504
512
  .run-where .repo { font-weight: 600; color: var(--ink-2); }
513
+ .run-where > .repo { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
514
+ .run-where .repo-wt { max-width: 36ch; } /* a long worktree name must not take the goal's room */
505
515
  .run-title-row > .describer { flex: none; }
506
516
  @container (max-width: 860px) {
507
517
  .run-title-row { flex-wrap: wrap; } .run-title-row > h2 { flex-basis: calc(100% - 24px); }
518
+ .run-title-row > .run-where { flex: 0 1 auto; min-width: 0; max-width: 100%; } /* on its own line, the repository and its worktree give way before the id */
508
519
  .run-title-row > .describer { flex: 0 1 auto; max-width: 100%; flex-wrap: wrap; white-space: normal; row-gap: 2px; }
509
520
  }
510
521
  .run-actions { display: flex; gap: 6px; flex: none; margin-left: auto; }
@@ -1328,7 +1339,31 @@ dialog.del-dialog::backdrop { background: light-dark(rgb(17 22 19 / .35), rgb(0
1328
1339
  .set-head { display: flex; align-items: baseline; gap: var(--s-4); flex-wrap: wrap; }
1329
1340
  .set-lede { margin: 0; font-size: var(--t-sm); }
1330
1341
  .set-picker-row { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-3); }
1331
- .set-picker select { min-width: 22em; max-width: 100%; }
1342
+ /* the run picker: a button drawn as a field, and its listbox of runs grouped by repository */
1343
+ button.set-run { justify-content: flex-start; align-items: baseline; gap: var(--s-2); min-width: 22em; max-width: 100%; padding: 6px 28px 6px 10px;
1344
+ border-color: var(--rule-2); box-shadow: none; text-align: left;
1345
+ font-family: inherit; font-weight: 400; font-size: inherit; letter-spacing: normal; text-transform: none; line-height: 1.3; }
1346
+ /* the select's drawn chevron, also on hover: the base button:hover sets the whole background */
1347
+ button.set-run, button.set-run:hover:not(:disabled) { background-color: var(--field);
1348
+ background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
1349
+ background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
1350
+ button.set-run:hover:not(:disabled) { border-color: var(--ink-2); }
1351
+ button.set-run:active:not(:disabled) { scale: 1; }
1352
+ button.set-run[aria-expanded=true] { border-color: var(--route); }
1353
+ .set-run-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1354
+ .set-run .repo-wt, .set-run-opt .repo-wt { flex: none; font-size: var(--t-sm); }
1355
+ .set-run-pop { margin: 0; inset: auto; position: fixed; max-width: min(640px, calc(100vw - 16px)); max-height: min(60vh, 480px); overflow: auto; padding: 6px;
1356
+ border: 1px solid var(--rule); border-radius: var(--r-module); background: var(--module); color: var(--ink); box-shadow: var(--ply-2); }
1357
+ .set-run-list { display: grid; gap: 2px; outline: none; }
1358
+ .set-run-group { display: grid; gap: 1px; }
1359
+ .set-run-group + .set-run-group { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--rule); }
1360
+ .set-run-group-name { display: flex; align-items: baseline; gap: var(--s-2); min-width: 0; padding: 4px 10px 2px; font-size: var(--t-xs); }
1361
+ .set-run-group-name .mono { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1362
+ .set-run-opt { position: relative; display: flex; align-items: baseline; gap: var(--s-2); min-height: 36px; padding: 9px 10px 9px 14px; border-radius: var(--r-key); cursor: pointer; }
1363
+ .set-run-opt[aria-selected=true]::before { content: ''; position: absolute; left: 4px; top: 9px; bottom: 9px; width: 2px; border-radius: 1px; background: var(--route); }
1364
+ .set-run-opt[aria-selected=true] .set-run-label { font-weight: 650; }
1365
+ .set-run-opt.is-active { background: var(--wash); box-shadow: inset 0 0 0 1px var(--rule-2); }
1366
+ .set-run-list:focus-visible .set-run-opt.is-active { box-shadow: inset 0 0 0 2px var(--route); }
1332
1367
  .set-field { display: inline-flex; align-items: center; }
1333
1368
  .set-repo-path, .set-why, .set-state-line, .set-file-status { display: flex; align-items: flex-start; gap: 7px; margin: var(--s-2) 0 0; font-size: var(--t-sm); overflow-wrap: anywhere; }
1334
1369
  .set-repo-path .lamp, .set-why .lamp, .set-state-line .lamp, .set-file-status .lamp { margin-top: .42em; }
@@ -1348,7 +1383,7 @@ button.set-switch { gap: 8px; padding: 0 10px 0 4px; }
1348
1383
  .set-switch-knob::after { content: ''; position: absolute; top: 2px; left: 2px; width: 10px; height: 10px; border-radius: 50%; background: var(--key); box-shadow: 0 0 0 1px var(--lamp-edge); transition: translate var(--relay); }
1349
1384
  button.set-switch[aria-checked=true] .set-switch-knob { background: var(--lamp-green); }
1350
1385
  button.set-switch[aria-checked=true] .set-switch-knob::after { translate: 12px 0; }
1351
- button.set-switch:focus-visible, .set-editor:focus-visible, .set-picker select:focus-visible, .set-gate select:focus-visible, .set-gate input:focus-visible { outline: 2px solid var(--route); outline-offset: 2px; }
1386
+ button.set-switch:focus-visible, .set-editor:focus-visible, button.set-run:focus-visible, .set-gate select:focus-visible, .set-gate input:focus-visible { outline: 2px solid var(--route); outline-offset: 2px; }
1352
1387
  .set-file { display: grid; gap: var(--s-2); width: 100%; padding: var(--s-3); border: 1px solid var(--rule); border-radius: var(--r-key); background: var(--module-2); }
1353
1388
  .set-file > * { margin-block: 0; }
1354
1389
  .set-file-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; }