Public: anyone can read this; the crew can change it.

Bridge v1.1: h/l across lanes, an obvious close, honest resource figures, and a phone tap that selects #16941

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

bridge-tap → main 0 commits 5 threads · 5 unresolved

  • Merged. bridge-tap was merged into main as 3254601.

Review

Sign in to review this change.
8 files changed +289 −34
docs/design/areas/home-flow.md +1 −1
@@ -16,7 +16,7 @@
1616 - `.lane-times` — one line under the health, "now 18m · typical 9m" (the median age of the cards the viewer can see, and the median time cards spent in it over 24 hours; a viewer who is not a forge admin sees "typical —"). It is one line tall, empty where there is nothing to say. `.lane-bottleneck` — the word "Slowest" at `--fg` weight in the head of the lane whose now median is furthest above its typical (`data-bottleneck` on the lane); at most one lane wears it. A tile's clock is its age in the lane.
1717 - `.lane-list` — the lane's tiles, in the order the next worker takes them.
1818 - `.lane-more`, `.lane-more-link`, `.lane-more-lg`, `.lane-more-md`, `.lane-more-sm`, `.lane-toggle`, `.lane-all` — what lies past the tiles. On a desk "N more" opens the table filtered to the lane. On a phone a lane shows its first four tiles (two lines each: the title, then the app, who has it and where it is, with the clock beside the title); with script "Show all N" opens the lane in place up to twelve tiles, then "All N in the table", and the lane keeps `data-open` through every redraw; without script "N more" is the table link.
19 - `.br-bar`, `.br-body`, `.br-head`, `.br-verbs`, `.br-said` — the bridge (`src/web/bridge_client.ts`): the selected tile's verbs in one bar under the lanes, each a button with its key (`data-shortcut`, so `?` lists them), docked at the foot of the screen with the safe area under it. It is empty and hidden until a tile is selected (`j`/`k`, a focus, or a first tap on a phone); a selected tile wears an accent outline (`data-selected`). No motion: it is used many times a day.
19 - `.br-bar`, `.br-body`, `.br-top`, `.br-close`, `.br-head`, `.br-verbs`, `.br-said`, `.br-room` (`data-over` when that many do not fit: the danger colour, and the words themselves say they do not fit, so the colour is never the only signal) — the bridge (`src/web/bridge_client.ts`): the selected tile's verbs in one bar under the lanes, each a button with its key (`data-shortcut`, so `?` lists them), docked at the foot of the screen with the safe area under it. It is empty and hidden until a tile is selected (`j`/`k`, a focus, or a first tap on a phone); a selected tile wears an accent outline (`data-selected`). No motion: it is used many times a day.
2020 - `.tile`, `.tile-link`, `.tile-top`, `.tile-app`, `.tile-no`, `.tile-clock`, `.tile-title`, `.tile-hint`, `.tile-who` — one change: the app and number, how long it has been in this lane, its title in plain words, who has it and one sentence of where it is. `data-key` is stable across lanes, so the page glides a tile from the lane it left to the lane it reached (`home_flow_client.ts`); `data-state` is `waiting`, `active` (a pulse on the clock) or `done` (live).
2121 - `.hf-forges` — the hosted forges in one line: how many, how many awake, any that is awake but silent.
2222 - `.hf-foot` — a line saying what the page shows, and the way to the feed.
docs/features/bridge.md +3 −3
@@ -6,10 +6,10 @@ row: The bridge: act on a tile from home
66
77 The owner, of home: "the one thing i actually feel proud of… but then from there i feel like i have little to no control other than telling an agent my thoughts". Home's lanes are now the bridge: the tile you are on has its verbs in one bar under the lanes, each a key, and every verb is an action that already exists on its own page.
88
9 - **Select.** `j` and `k` move between tiles (each tile's link is a row, `data-nav`), a focus selects, and on a phone the first tap selects and the second opens. Escape, or focus anywhere else, clears. A lane the live stream redraws keeps the selection: the tile with the same key, wherever it moved.
10 - **A run** (Building, Checks, Review): `w` watch it live (its run page), `h` take the wheel (its run page at the steer box, where words reach the running agent), `s` stop. A stopped run offers `r` Queue it again.
9 - **Select.** The lanes are a grid: `h` and `l` (or the arrow keys) cross to the next lane at the same row, as near as that lane has, and `j` and `k` move along one lane; below a lane's last tile `j` goes to the slots figures and `k` comes back. A focus selects, and on a phone the first tap selects and the second opens. The bar is a line at the foot of the page, not a sheet, and always shows how to put it away: its **× Close** button (`Esc`), Escape, or a click, tap or focus anywhere else. A lane the live stream redraws keeps the selection: the tile with the same key, wherever it moved.
10 - **A run** (Building, Checks, Review): `w` watch it live (its run page), `i` take the wheel (its run page at the steer box, where words reach the running agent), `s` stop. A stopped run offers `r` Queue it again.
1111 - **An issue:** `a` assign (its page's assignee field), `e` sharpen (the planner plans it again), `p` park (behind the Later gate). Sharpen and park answer with their receipt, where Undo is.
12 - **A figure** (an admin's): the slots under the lanes, checks and crew runs (`src/web/flow_slots.ts`), are selectable too. `-` and `+` turn the setting and the bar says, labelled an estimate, how long a new run would wait at it ("Estimate: a new check would wait about 6m with 8 slots (44m now). Checks cost nothing extra."): what waits now, worked off at the median run's length over the 24 hours, that many at a time. Enter sets it through Capacity's own save, and the estimate is kept with the change (its reason); `z` puts it back. Each figure then says how the last change's estimate held up ("since then a new one waited ~5m"), and when it was more than twice off either way it says so and calls the next estimate rough.
12 - **A figure** (an admin's): the slots under the lanes, checks and crew runs (`src/web/flow_slots.ts`), are selectable too. `-` and `+` turn the setting, and the bar says two things about it. First, labelled an estimate, how long a new run would wait at it: what waits now, worked off at the median run's length over the 24 hours, that many at a time ("Estimate: a new check would wait about 6m with 8 slots (44m now)."). Second, what that many would take from the machine against what is free beside serving, and plainly when they do not fit ("8 checks would need up to 128 cores and 64 GiB, more than this machine has free beside serving (78 cores and 380 GiB): they would slow each other and the pages."). A check's share is the runner pool's (forge.json's `check.limits`, else 4 cores and 4 GiB, which it says); a crew run's is what `crewForMemory` sizes by, 3 GiB beside the forge's own 2 GiB, with its CPU not measured, which it says. The machine is the cgroup's limits, else the host's (`slotRoom`, `src/flow/slots.ts`). Enter sets it through Capacity's own save, and the estimate is kept with the change (its reason); `z` puts it back. Each figure then says how the last change's estimate held up ("since then a new one waited ~5m"), and when it was more than twice off either way it says so and calls the next estimate rough.
1313 - **A pull:** `m` merge, `x` close, `u` bring it up to date, `b` send it back (its review box: a send-back needs words). A merge is the one verb that asks for a second `m`, because it is not undone; everything else applies at once and answers with what was done and its receipt (where close's Undo is).

Principle 8: the sentence breaks at (slotRoom, src/flow/slots.ts).: what waits now.... The old text is glued on after the new. Split it into two clean sentences.

1414 - Stop, queue again, close, sharpen, park and merge go through home's one action route, `POST /home/act` (`src/web/pages/home_table.ts`), as the table's action bar does; Update posts the pull's own update route. The bar's keys are buttons that exist only while a tile is selected, so `?` lists them and no key is taken from home otherwise (`t` stays Tell the crew). The bar has no motion and docks at the foot of the screen, above the safe area.
1515 - **In the terminal** the tile verbs are on the run and pull screens (`src/tui/screens/runs.ts`, `src/tui/screens/pull.ts`); the dashboard (`src/tui/screens/dashboard.ts`) is the terminal's home. The slots are set on the Capacity screen (`src/tui/screens/capacity.ts`: `e` on `checks.concurrency` or `crew.concurrency`, then `y`), without the estimate or its Undo: those are on the page only, for now.
src/core/capacity.ts +8 −1
@@ -459,13 +459,20 @@ export function maxAwake(db: Database): number {
459459 return Number(capacityValue(db, "children.awake"));
460460 }
461461
462 /**
463 * What one crew run is taken to hold, and what the forge keeps for itself, in MiB: what
464 * {@link crewForMemory} sizes by, and what the bridge's slot figure says a crew run takes.
465 */
466 export const CREW_RUN_MIB = 3072;
467 export const FORGE_OWN_MIB = 2048;
468
462469 /**
463470 * One crew run per 3 GiB of room above the forge's own 2 GiB (32 GiB gives
464471 * 10, 64 GiB the ceiling of 16), never fewer than two: a big machine runs
465472 * the crew it can hold without an override the sentinel then flags (#2548).
466473 */
467474 export function crewForMemory(bytes: number): number {
468 const n = Math.floor((bytes - 2 * GIB) / (3 * GIB));
475 const n = Math.floor((bytes - FORGE_OWN_MIB * MIB) / (CREW_RUN_MIB * MIB));
469476 return Math.min(MAX_CREW, Math.max(MIN_CREW, Number.isFinite(n) ? n : MIN_CREW));
470477 }
471478 const MIN_CREW = 2;
src/flow/slots.ts +52 −2
@@ -11,8 +11,12 @@
1111 */
1212
1313 import type { Database } from "bun:sqlite";
14 import { readFileSync } from "node:fs";
15 import { join } from "node:path";
1416 import type { App } from "../app.ts";
15 import { capacityValues } from "../core/capacity.ts";
17 import { declaredCheckLimits, shapeFromRepository, type PoolShape } from "../checks/runner_pool.ts";
18 import { capacityValues, cpuLimit, CREW_RUN_MIB, FORGE_OWN_MIB } from "../core/capacity.ts";
19 import { memoryLimitBytes } from "../system/memory_limit.ts";
1620 import { forgeRepo } from "../core/forge_repo.ts";
1721 import { repoPace } from "../crew/autonomy_pace.ts";
1822 import { median } from "./estimate_score.ts";
@@ -50,6 +54,25 @@ export interface SlotLine {
5054 * The last estimate a change of this setting was made on, and what happened since: kept honest.
5155 */
5256 readonly lastEstimate?: { readonly at: string; readonly slots: number; readonly saidMs: number; readonly actualMs: number | null };
57 /** What one of this kind takes from the machine, and what the machine has (`slotRoom`). */
58 readonly room?: SlotRoom;
59 }
60
61 /**
62 * The machine against one slot: its cores and memory (the cgroup's limits, else the host's), what
63 * serving keeps, and what one check or crew run is taken to use. A check's share is the runner
64 * pool's (`checks/runner_pool.ts`: forge.json's `check.limits`, else 4 cores and 4 GiB); a crew
65 * run's is the 3 GiB `crewForMemory` sizes by, beside the forge's own 2 GiB, and its CPU is not
66 * measured (`perCpus` null). `declared` says whether the share is the repository's own words.
67 */
68 export interface SlotRoom {
69 readonly cpus: number;
70 readonly memoryMiB: number;
71 readonly keepCpus: number;
72 readonly keepMiB: number;
73 readonly perCpus: number | null;
74 readonly perMiB: number;
75 readonly declared: boolean;
5376 }
5477
5578 const KEY: Readonly<Record<SlotLine["kind"], "checks.concurrency" | "crew.concurrency">> = { checks: "checks.concurrency", crew: "crew.concurrency" };
@@ -166,6 +189,33 @@ function lastEstimates(db: Database): Map<string, { at: string; slots: number; m
166189 return out;
167190 }
168191
192 /**
193 * The forge's own check share, read once from its own forge.json (a release replaces the process).
194 */
195 let ownShape: { shape: PoolShape; declared: boolean } | undefined;
196 function checkShape(): { shape: PoolShape; declared: boolean } {
197 if (ownShape !== undefined) return ownShape;
198 const root = join(import.meta.dir, "..", "..");
199 let declared = false;
200 try {
201 declared = declaredCheckLimits(readFileSync(join(root, "forge.json"), "utf8")) !== undefined;
202 } catch {
203 declared = false;
204 }
205 ownShape = { shape: shapeFromRepository(root), declared };
206 return ownShape;
207 }
208
209
210 /** The machine against one slot of `kind`, as {@link SlotRoom} says. */
outdated

Two ways to do one thing: these constants copy what crewForMemory uses. Export them from there and import them so the bar cannot drift from the real sizing.

211 export function slotRoom(kind: SlotLine["kind"]): SlotRoom {
212 const machine = { cpus: cpuLimit(), memoryMiB: Math.floor(memoryLimitBytes() / 1_048_576) };
213 const { shape, declared } = checkShape();
214 return kind === "checks"
215 ? { ...machine, keepCpus: shape.servingCpus, keepMiB: shape.servingMemoryMiB, perCpus: shape.perRunnerCpus, perMiB: shape.perRunnerMemoryMiB, declared }
216 : { ...machine, keepCpus: shape.servingCpus, keepMiB: FORGE_OWN_MIB, perCpus: null, perMiB: CREW_RUN_MIB, declared: false };
217 }
218
169219 /** The setting as a count: what is in force now, so the line moves the moment it is changed. */
170220 const slotsOf = (v: string): number => Math.max(1, Number(v) || 1);
171221
@@ -199,7 +249,7 @@ export function readSlots(app: App, now: Date = new Date(), o: { readonly pace?:
199249 const runs = rows(app.db, since);
200250 const said = lastEstimates(app.db);
201251 const line = (kind: SlotLine["kind"], mine: readonly Row[]): SlotLine => {
202 const l = slotLine(kind, slotsOf(set[KEY[kind]]), mine, now.getTime());
252 const l = { ...slotLine(kind, slotsOf(set[KEY[kind]]), mine, now.getTime()), room: slotRoom(kind) };
203253 const e = said.get(KEY[kind]);
204254 return e === undefined ? l : { ...l, lastEstimate: { at: e.at, slots: e.slots, saidMs: e.ms, actualMs: waitedSince(mine, e.at) } };
205255 };
src/web/bridge_client.ts +100 −15
@@ -1,12 +1,13 @@
11 /**
22 * The bridge (the owner: "i could rip a crew member off a terminal and fire the guns myself"): on
33 * home's lanes, the tile or figure a person is on has its verbs in one bar under the lanes, each a
4 * key. The selection is the shell's own: `j`/`k` move between tiles and figures (they are
5 * `data-nav` rows), a tap or a focus selects; Escape or focus elsewhere clears. Every verb is an
6 * action that already exists at its own page, so with no script each tile is still a link to where
7 * they are.
4 * key. The tiles are a grid: `h`/`l` (or the arrows) move across the lanes at the same row, as near
5 * as the next lane has, and `j`/`k` move along one lane; below a lane's last tile `j` goes to the
6 * slots figures and `k` comes back. A tap or a focus selects; the bar's Close, Escape, or a click
7 * or focus anywhere else clears. Every verb is an action that already exists at its own page, so
8 * with no script each tile is still a link to where they are.
89 *
9 * A run (building, checks, review): `w` watches it live (its page), `h` takes the wheel (its page
10 * A run (building, checks, review): `w` watches it live (its page), `i` takes the wheel (its page
1011 * at the steer box, where words reach the running agent; steering from the bar itself, and a live
1112 * terminal of the run, come later), `s` stops it and `r` queues it again.
1213 *
@@ -19,7 +20,9 @@
1920 *
2021 * A slots figure (an admin's): `-` and `+` turn the setting, Enter sets it with its estimate (a new
2122 * run's wait at that setting, said as an estimate) kept with the change, `z` puts it back; the
22 * figure says how the last estimate held up, and when it was more than twice off.
23 * figure says how the last estimate held up, and when it was more than twice off. It also says
24 * what that many would take from the machine against what is free beside serving, and says
25 * plainly when they do not fit; what the forge cannot measure it says it cannot.
2326 *
2427 * Stop, queue again, close, sharpen, park and merge go through home's one action route (`POST
2528 * /home/act`, `home_table.ts`): applied at once, answered with what was done and the receipt, where
@@ -62,6 +65,15 @@ export const bridgeJs = /* js */ `
6265 if (act.run) b.addEventListener('click', function (e) { e.preventDefault(); act.run(b); });
6366 return b;
6467 }
68 // The bar always says how to put it away: a Close button with its key, beside the head.
69 function top(head) {
70 var row = el('div', 'br-top', null), b = el('button', 'btn br-close', null);

The aria-label 'Close the bar' does not match the visible '× Close Esc'. Speech users who say 'click Close Esc' won't match it. Lead the label with the visible text, or add aria-keyshortcuts instead.

71 b.type = 'button'; b.setAttribute('data-size', 'sm'); b.setAttribute('data-variant', 'ghost'); b.setAttribute('aria-label', 'Close the bar (Escape)'); b.setAttribute('aria-keyshortcuts', 'Escape');
72 b.appendChild(el('span', null, '\u00d7 Close')); b.appendChild(el('kbd', null, 'Esc'));
73 b.addEventListener('click', function () { clear(); if (D.activeElement && D.activeElement.blur) D.activeElement.blur(); });
74 row.appendChild(head); row.appendChild(b);
75 return row;
76 }
6577 function say(text, extra) {
6678 said.textContent = text;
6779 if (extra) { said.appendChild(D.createTextNode(' ')); said.appendChild(extra); }
@@ -93,7 +105,7 @@ export const bridgeJs = /* js */ `
93105 var d = t.dataset, out = [], base = '/' + d.repo;
94106 if (d.run) {
95107 out.push(verb('w', 'Watch live', { href: base + '/runs/' + d.run }));
96 out.push(verb('h', 'Take the wheel', { href: base + '/runs/' + d.run + '#run-steer' }));
108 out.push(verb('i', 'Take the wheel', { href: base + '/runs/' + d.run + '#run-steer' }));
97109 out.push(verb('s', 'Stop', { run: function () {
98110 act('stop', [d.run], function () {
99111 var again = verb('r', 'Queue it again', { run: function () { act('requeue', [d.run]); } });
@@ -120,19 +132,40 @@ export const bridgeJs = /* js */ `
120132 }
121133 // A figure (a slots line): its setting, turned here, with the estimate said before and recorded with
122134 // the change after, so what was promised can be held to what happens (flow/slots.ts estimateOf).
123 var WORD = { checks: 'check', crew: 'crew run' }, NAME = { checks: 'Checks', crew: 'Crew runs' }, KEY = { checks: 'checks.concurrency', crew: 'crew.concurrency' };
135 var WORD = { checks: 'check', crew: 'crew run' }, WORDS = { checks: 'checks', crew: 'crew runs' }, NAME = { checks: 'Checks', crew: 'Crew runs' }, KEY = { checks: 'checks.concurrency', crew: 'crew.concurrency' };
136 function gib(mib) { return (Math.round(mib / 102.4) / 10) + ' GiB'; }
137 // What n of a kind take from the machine (flow/slots.ts slotRoom: the machine's cores and memory, what
138 // serving keeps, what one takes), against what is free beside serving. Never "free" when unknown.
139 function roomSays(d, kind, n) {
140 if (d.roomCpus === undefined || d.roomCpus === '') return { text: 'This forge cannot read its machine, so it cannot say whether ' + n + ' ' + (n === 1 ? WORD[kind] : WORDS[kind]) + ' fit.', over: false };
141 var freeC = Math.max(0, Number(d.roomCpus) - Number(d.roomKeepCpus)), freeM = Math.max(0, Number(d.roomMem) - Number(d.roomKeepMem));
142 var perC = d.roomPerCpus === '' ? null : Number(d.roomPerCpus), perM = Number(d.roomPerMem);
143 var needC = perC === null ? null : n * perC, needM = n * perM;
144 var what = n + ' ' + (n === 1 ? WORD[kind] : WORDS[kind]);
145 var over = (needC !== null && needC > freeC) || needM > freeM;
146 var need = (needC === null ? '' : needC + ' cores and ') + gib(needM), free = (needC === null ? '' : freeC + ' cores and ') + gib(freeM);
147 var text = over
148 ? what + ' would need up to ' + need + ', more than this machine has free beside serving (' + free + '): they would slow each other and the pages.'
149 : what + ' would use up to ' + need + ' of the ' + free + ' free beside serving.';
150 if (perC === null) text += ' Their CPU is not measured.';
151 text += d.roomDeclared === '1' ? '' : ' Each ' + WORD[kind] + ' is taken as ' + (perC === null ? '' : perC + ' cores and ') + gib(perM) + (kind === 'checks' ? ', since forge.json declares no check limits.' : '.');
152 return { text: text, over: over };
153 }
124154 function figure(t) {
125155 var d = t.dataset, kind = d.kind, from = Number(d.slots), n = from;
126156 var run = d.runMs === '' ? null : Number(d.runMs), waiting = Number(d.waiting);
127157 function est(k) { return run === null ? null : Math.round(waiting * run / k); }
128158 var head = el('p', 'br-head', null), verbs = el('div', 'br-verbs', null);
129159 verbs.setAttribute('data-verbs', '');
130 var line = el('p', 'br-said small', '');
160 var line = el('p', 'br-said small', ''), room = el('p', 'br-said br-room small', '');
131161 function show() {
132162 head.replaceChildren(el('strong', null, NAME[kind] + ' slots'), D.createTextNode(' ' + from + (n === from ? '' : ' → ' + n)));
133163 var e = est(n), now = est(from);
134164 line.textContent = e === null ? 'No ' + WORD[kind] + ' has finished in 24 hours, so there is no estimate yet.'
135 : 'Estimate: a new ' + WORD[kind] + ' would wait about ' + span(e) + ' with ' + n + ' slots (' + span(now) + ' now). ' + (kind === 'checks' ? 'Checks cost nothing extra.' : 'More crew runs at once use the week faster.') + (d.off === '1' ? ' The last estimate was more than twice off, so take this one as rough.' : '');
165 : 'Estimate: a new ' + WORD[kind] + ' would wait about ' + span(e) + ' with ' + n + ' slots (' + span(now) + ' now).' + (kind === 'crew' ? ' More crew runs at once use the week faster.' : '') + (d.off === '1' ? ' The last estimate was more than twice off, so take this one as rough.' : '');
166 var r = roomSays(d, kind, n);
167 room.textContent = r.text;
168 if (r.over) room.setAttribute('data-over', ''); else room.removeAttribute('data-over');
136169 }
137170 verbs.appendChild(verb('-', 'Fewer', { run: function () { if (n > 1) { n--; show(); } } }));
138171 verbs.appendChild(verb('+', 'More', { run: function () { if (n < 64) { n++; show(); } } }));
@@ -160,7 +193,7 @@ export const bridgeJs = /* js */ `
160193 .catch(function () { say('Could not reach the forge. Nothing changed.'); });
161194 } }));
162195 show();
163 body.replaceChildren(head, line, verbs); said.textContent = '';
196 body.replaceChildren(top(head), line, room, verbs); said.textContent = '';
164197 bar.hidden = false;
165198 }
166199 function draw(t) {
@@ -174,7 +207,7 @@ export const bridgeJs = /* js */ `
174207 var list = verbsFor(t);
175208 if (list.length === 0) verbs.appendChild(el('span', 'muted small', 'Nothing to do from here: open it with Enter.'));
176209 list.forEach(function (b) { verbs.appendChild(b); });
177 body.replaceChildren(head, verbs); said.textContent = '';
210 body.replaceChildren(top(head), verbs); said.textContent = '';
178211 bar.hidden = false;
179212 }
180213 function select(t) {
@@ -192,11 +225,63 @@ export const bridgeJs = /* js */ `
192225 if (t) select(t);
193226 else if (sel && !bar.contains(e.target)) clear();
194227 });
195 // On a phone the first tap selects and the second opens: the bar is where a thumb is.
228 // The lanes as a grid. h and l (or the arrows) cross to the next lane at the same row, as near as it
229 // has; j and k stay in the lane, and below its last tile j goes to the slots figures, k comes back.
230 // Read on the window before the shell's own j/k, and only while a tile or figure has the focus
231 // (h and l from nowhere start at the first tile); g then h is still the shell's go-home.
232 function shown(root) { return Array.prototype.filter.call(root.querySelectorAll('.tile[data-key]'), function (t) { return t.getClientRects().length > 0; }); }
233 function lanes() { return Array.prototype.filter.call(D.querySelectorAll('.lane[data-lane]'), function (l) { return shown(l).length > 0; }); }
234 function figs() { return Array.prototype.slice.call(D.querySelectorAll('.sl[data-nav]')); }
235 // The selection follows the move itself, not only the focus event it brings.
236 function go(t) { var a = t.classList.contains('sl') ? t : t.querySelector('a[data-nav]') || t.querySelector('a'); if (a) { a.focus(); a.scrollIntoView({ block: 'nearest', inline: 'nearest' }); } select(t); }
237 var lastTile = null, prevKey = '', prevAt = 0;
238 function nextFor(at, k) {
239 if (at && at.classList.contains('sl')) {
240 var fs = figs(), i = fs.indexOf(at);
241 if (k === 'h' || k === 'l') return fs[Math.min(Math.max(i + (k === 'l' ? 1 : -1), 0), fs.length - 1)];
242 return k === 'k' && lastTile && D.contains(lastTile) ? lastTile : at;
243 }
244 var ls = lanes();
245 if (!at) return ls[0] ? shown(ls[0])[0] : null;
246 var lane = at.closest('.lane'), col = shown(lane), row = col.indexOf(at);
247 if (k === 'j') return row < col.length - 1 ? col[row + 1] : figs()[0] || at;
248 if (k === 'k') return col[Math.max(row - 1, 0)];
249 var to = ls[ls.indexOf(lane) + (k === 'l' ? 1 : -1)];
250 if (!to) return at;
251 var c = shown(to);
252 return c[Math.min(row, c.length - 1)];
253 }
254 window.addEventListener('keydown', function (e) {
255 var afterG = prevKey === 'g' && Date.now() - prevAt < 1000;
256 prevKey = e.key; prevAt = Date.now();
257 if (e.metaKey || e.ctrlKey || e.altKey || e.defaultPrevented || afterG) return;
258 var k = e.key === 'ArrowLeft' ? 'h' : e.key === 'ArrowRight' ? 'l' : e.key;
259 if (k !== 'h' && k !== 'l' && k !== 'j' && k !== 'k') return;
260 var t = e.target;
261 if (t && t.closest && t.closest('input, textarea, select, [contenteditable], dialog[open]')) return;
262 var at = tileOf(D.activeElement);
263 if (!at && (k === 'j' || k === 'k' || !D.querySelector('.lane[data-lane] .tile[data-key]'))) return;
264 var next = nextFor(at, k);
265 if (!next) return;
266 e.preventDefault(); e.stopImmediatePropagation();
267 if (!next.classList.contains('sl')) lastTile = next;
268 go(next);
269 }, true);
270 // A click or tap anywhere but the bar or a tile puts the bar away, as a focus elsewhere does.
196271 D.addEventListener('click', function (e) {
197 var t = tileOf(e.target);
272 if (!sel || bar.contains(e.target) || tileOf(e.target)) return;
273 clear();
274 });
275 // On a phone the first tap selects and the second opens: the bar is where a thumb is. A real tap
276 // focuses the link before its click, and the focus selects, so the click asks what was selected
277 // when the finger came down; a click no touch began (Enter on a link) asks what is selected now.
278 var downSel;
279 D.addEventListener('pointerdown', function (e) { if (e.pointerType !== 'mouse' && tileOf(e.target)) downSel = sel; }, true);
280 D.addEventListener('click', function (e) {
281 var t = tileOf(e.target), was = downSel === undefined ? sel : downSel;
282 downSel = undefined;
198283 if (!t || !coarse || e.metaKey || e.ctrlKey) return;
199 if (sel !== keyOf(t)) { e.preventDefault(); select(t); }
284 if (was !== keyOf(t)) { e.preventDefault(); select(t); }
200285 }, true);
201286 D.addEventListener('keydown', function (e) { if (e.key === 'Escape' && sel && !e.defaultPrevented) clear(); });
202287 // A lane swapped by the live stream keeps the selection: the tile with the same key, wherever it moved.
src/web/flow_slots.ts +6 −2
@@ -9,7 +9,7 @@
99 import { html, type Html } from "./html.ts";
1010 import { badge } from "./ui.ts";
1111 import { span } from "../flow/pipeline.ts";
12 import { isFull, offByMore, SLOT_POINTS, waitEstimate, type SlotLine } from "../flow/slots.ts";
12 import { isFull, offByMore, SLOT_POINTS, waitEstimate, type SlotLine, type SlotRoom } from "../flow/slots.ts";
1313
1414 const NAME: Readonly<Record<SlotLine["kind"], string>> = { checks: "Checks", crew: "Crew runs" };
1515 const H = 32;
@@ -64,6 +64,10 @@ function kept(l: SlotLine): Html | null {
6464 return html`<p class="sl-say small" data-estimate ${offByMore(e) ? html`data-off` : null}>Last change's estimate: ~${span(e.saidMs)} at ${String(e.slots)} slots; ${since}${offByMore(e) ? ", more than twice off: take the next estimate as rough" : ""}.</p>`;
6565 }
6666
67 /** The machine against one slot, for the bridge to say what a setting would take (`slotRoom`). */
68 const roomData = (r: SlotRoom): Html =>
69 html` data-room-cpus="${String(r.cpus)}" data-room-mem="${String(r.memoryMiB)}" data-room-keep-cpus="${String(r.keepCpus)}" data-room-keep-mem="${String(r.keepMiB)}" data-room-per-cpus="${r.perCpus === null ? "" : String(r.perCpus)}" data-room-per-mem="${String(r.perMiB)}" data-room-declared="${r.declared ? "1" : ""}"`;
70
6771 /**
6872 * One kind's line. For an admin it is also a figure the bridge can select (`bridge_client.ts`):
6973 * what waits, the median run, and the wait estimated at today's setting ride on it as data.
@@ -78,7 +82,7 @@ function line(l: SlotLine, now: number, admin = false): Html {
7882 ...(l.pace === undefined ? [] : [html`<span data-pace="${String(l.pace.allows)}">pace allows ${String(l.pace.allows)}: ${l.pace.why}</span>`]),
7983 ];
8084 const est = waitEstimate(l, l.slots);
81 const pick = admin ? html` tabindex="0" role="group" aria-label="${NAME[l.kind]} slots, ${String(l.slots)}" data-nav data-slots="${String(l.slots)}" data-waiting="${String(l.waiting)}" data-run-ms="${l.medianRunMs === null ? "" : String(Math.round(l.medianRunMs))}" data-wait-ms="${est === null ? "" : String(est)}" data-off="${l.lastEstimate !== undefined && offByMore(l.lastEstimate) ? "1" : ""}"` : null;
85 const pick = admin ? html` tabindex="0" role="group" aria-label="${NAME[l.kind]} slots, ${String(l.slots)}" data-nav data-slots="${String(l.slots)}" data-waiting="${String(l.waiting)}" data-run-ms="${l.medianRunMs === null ? "" : String(Math.round(l.medianRunMs))}" data-wait-ms="${est === null ? "" : String(est)}" data-off="${l.lastEstimate !== undefined && offByMore(l.lastEstimate) ? "1" : ""}"${l.room === undefined ? null : roomData(l.room)}` : null;
8286 return html`<div class="sl" data-kind="${l.kind}" ${full ? html`data-full` : null}${pick}>
8387 <p class="sl-head">
8488 <strong>${NAME[l.kind]}</strong>
src/web/pages/home_flow_style.ts +6 −1
@@ -60,7 +60,12 @@ export const homeFlowCss = /* css */ `
6060 .tile[data-state="done"] { border-left: 2px solid var(--success); }
6161 /* The bridge (bridge_client.ts): the selected tile, and the bar of its verbs under the lanes. No motion. */
6262 .tile[data-selected] { outline: 2px solid var(--accent); outline-offset: 1px; }
63 .br-bar { position: sticky; bottom: 0; display: grid; gap: 4px; margin: 12px 0 0; padding: 8px 16px max(8px, env(safe-area-inset-bottom)); border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; background: var(--card); box-shadow: var(--shadow-2); }
63 /* A line at the foot of the page, like a status line, not a sheet: one rule above it, the page's own ground. */
64 .br-bar { position: sticky; bottom: 0; display: grid; gap: 4px; margin: 12px 0 0; padding: 8px 16px max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--bg); }
65 .br-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
66 .br-close { min-height: 44px; gap: 6px; flex: none; }
67 .br-close kbd { font-size: var(--fs-min); }
68 .br-room[data-over] { color: var(--danger); }
6469 .br-bar[hidden] { display: none; }
6570 .br-body { display: grid; gap: 4px; }
6671 .br-head, .br-said { margin: 0; }
test/bridge.test.ts +113 −9
@@ -17,8 +17,9 @@ import { serve, type Servers } from "../src/http/server.ts";
1717 import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts";
1818 import { quietLogs } from "./helpers/globals.ts";
1919 import { seedHomeFlow, type HomeFlowSeed } from "./helpers/home-flow-seed.ts";
20 import { setCapacity } from "../src/core/capacity.ts";
21 import { estimateOf, offByMore, readSlots, waitEstimate } from "../src/flow/slots.ts";
20 import { CREW_RUN_MIB, FORGE_OWN_MIB, provideCpusForTest, setCapacity } from "../src/core/capacity.ts";
21 import { declaredCheckLimits, shapeFromRepository } from "../src/checks/runner_pool.ts";
22 import { estimateOf, offByMore, readSlots, slotRoom, waitEstimate } from "../src/flow/slots.ts";

Second import from the same module as setCapacity above. Merge into one.

2223 import { slotsBlock } from "../src/web/flow_slots.ts";
2324 import { bridgeJs } from "../src/web/bridge_client.ts";
2425
@@ -123,7 +124,7 @@ test.skipIf(skip)("keys: j selects and the bar offers the tile's verbs; m asks a
123124 const seen = JSON.stringify(s);
124125 expect(s.runBar, seen).toBe(true);
125126 expect(s.selected, seen).toBe(true);
126 expect(s.runVerbs, seen).toEqual(expect.arrayContaining(["w Watch live", "h Take the wheel", "s Stop"]));
127 expect(s.runVerbs, seen).toEqual(expect.arrayContaining(["w Watch live", "i Take the wheel", "s Stop"]));
127128 expect(s.stopped, seen).toContain("Stop: 1 done");
128129 expect(s.again, seen).toBe(true);
129130 expect(s.pullVerbs, seen).toEqual(expect.arrayContaining(["m", "x", "u", "b"]));
@@ -134,20 +135,97 @@ test.skipIf(skip)("keys: j selects and the bar offers the tile's verbs; m asks a
134135 expect(s.cleared, seen).toBe(true);
135136 }, 30_000);
136137
138 test.skipIf(skip)("the lanes are a grid: l and h cross lanes at the same row, j and k stay in one, j below the last tile reaches the slots; Close, Escape and a click outside put the bar away", async () => {
139 if (chromium === undefined) throw new Error("no Chromium starts in this check, so the bridge is not driven: the check's image must carry one (FORGE_CHROMIUM)");
140 const s = await inPage(1280, `(async () => {
141 ${WAIT} ${KEY} ${PICK}
142 await wait(() => document.querySelector('.tile[data-key]'));
143 const bar = document.getElementById('bridge');
144 const shown = (l) => [...l.querySelectorAll('.tile[data-key]')].filter((t) => t.getClientRects().length > 0);
145 const lanes = [...document.querySelectorAll('.lane[data-lane]')].filter((l) => shown(l).length > 0);
146 const where = () => { const t = document.querySelector('[data-selected]'); if (!t) return null; if (t.classList.contains('sl')) return 'slots:' + t.getAttribute('data-kind'); const l = t.closest('.lane'); return lanes.indexOf(l) + ':' + shown(l).indexOf(t); };
147 const out = { lanes: lanes.map((l) => shown(l).length) };
148 // The lane with the most tiles, its second tile, so l and h have a row to keep or clamp.
149 const from = lanes.reduce((a, b) => (shown(b).length > shown(a).length ? b : a));
150 const fi = lanes.indexOf(from);
151 pick(shown(from)[Math.min(1, shown(from).length - 1)]);
152 out.start = where();
153 key('l'); out.l = where();
154 key('h'); out.h = where();
155 key('ArrowRight'); out.right = where();
156 key('ArrowLeft'); out.left = where();
157 key('k'); out.k = where();
158 key('j'); out.j = where();
159 for (let i = 0; i < 40; i++) key('j');
160 out.bottom = where();
161 key('l'); out.figL = where();
162 key('k'); out.back = where();
163 out.fi = fi;
164 out.close = bar.querySelector('.br-close')?.textContent.trim() ?? null;
165 bar.querySelector('.br-close').click();
166 out.closed = bar.hidden && !document.querySelector('[data-selected]');
167 pick(shown(from)[0]);
168 out.reopened = !bar.hidden;
169 document.querySelector('h1').click();
170 out.outside = bar.hidden;
171 pick(shown(from)[0]);
172 key('Escape');
173 out.escaped = bar.hidden;
174 return JSON.stringify(out);
175 })()`);
176 const seen = JSON.stringify(s);
177 const fi = s.fi as number;
178 const rowIn = (lane: number, row: number) => `${String(lane)}:${String(Math.min(row, (s.lanes as number[])[lane]! - 1))}`;
179 const row0 = Math.min(1, (s.lanes as number[])[fi]! - 1);
180 expect(s.start, seen).toBe(`${String(fi)}:${String(row0)}`);
181 const right = fi + 1 < (s.lanes as number[]).length ? rowIn(fi + 1, row0) : s.start;
182 expect(s.l, seen).toBe(right);
183 expect(s.h, seen).toBe(fi + 1 < (s.lanes as number[]).length ? rowIn(fi, Math.min(row0, (s.lanes as number[])[fi + 1]! - 1)) : s.start);
184 expect(s.right, seen).toBe(s.l);
185 expect(s.left, seen).toBe(s.h);
186 expect(String(s.k).split(":")[0], seen).toBe(String(s.left).split(":")[0]);
187 expect(String(s.j).split(":")[0], seen).toBe(String(s.left).split(":")[0]);
188 expect(s.bottom, seen).toBe("slots:checks");
189 expect(s.figL, seen).toBe("slots:crew");
190 expect(String(s.back), seen).toMatch(/^\d+:\d+$/);
191 expect(s.close, seen).toBe("× CloseEsc");
192 expect(s.closed, seen).toBe(true);
193 expect(s.reopened, seen).toBe(true);
194 expect(s.outside, seen).toBe(true);
195 expect(s.escaped, seen).toBe(true);
196 }, 30_000);
197
137198 test.skipIf(skip)("on a phone the first tap selects and the bar docks at the foot; the second tap opens", async () => {
138199 if (chromium === undefined) throw new Error("no Chromium starts in this check, so the bridge is not driven: the check's image must carry one (FORGE_CHROMIUM)");
139200 const s = await inPage(390, `(async () => {
140201 ${WAIT}
141202 await wait(() => document.querySelector('.tile[data-key] a'));
142203 const a = document.querySelector('.tile[data-key] a');
143 const tap = new MouseEvent('click', { bubbles: true, cancelable: true });
144 a.dispatchEvent(tap);
204 a.setAttribute('href', '#opened');
205 // A real tap, in the order a phone sends it: the finger down, the link focused (which selects
206 // it), then the click.
207 const tapOnce = () => {
208 a.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, cancelable: true, pointerType: 'touch' }));
209 a.focus();
210 a.dispatchEvent(new FocusEvent('focusin', { bubbles: true }));
211 const click = new MouseEvent('click', { bubbles: true, cancelable: true });
212 a.dispatchEvent(click);
213 return click.defaultPrevented;
214 };
215 const held = tapOnce();
145216 const bar = document.getElementById('bridge');
146 const box = bar.getBoundingClientRect();
147 return JSON.stringify({ held: tap.defaultPrevented, shown: !bar.hidden, position: getComputedStyle(bar).position, sw: document.documentElement.scrollWidth, minH: Math.min(...[...bar.querySelectorAll('.btn')].map((b) => b.getBoundingClientRect().height)) });
217 const out = { held, shown: !bar.hidden, position: getComputedStyle(bar).position, sw: document.documentElement.scrollWidth, minH: Math.min(...[...bar.querySelectorAll('.btn')].map((b) => b.getBoundingClientRect().height)) };
218 out.secondHeld = tapOnce();
219 // Enter on the selected link is a click no touch began: it opens.
220 const enter = new MouseEvent('click', { bubbles: true, cancelable: true });
221 a.dispatchEvent(enter);
222 out.enterHeld = enter.defaultPrevented;
223 return JSON.stringify(out);
148224 })()`);
149225 const seen = JSON.stringify(s);
150226 expect(s.held, seen).toBe(true);
227 expect(s.secondHeld, seen).toBe(false);
228 expect(s.enterHeld, seen).toBe(false);
151229 expect(s.shown, seen).toBe(true);
152230 expect(s.position, seen).toBe("sticky");
153231 expect(s.sw, seen).toBeLessThanOrEqual(390);
@@ -193,6 +271,29 @@ test("a change made on an estimate is held to it: the figure says what was said
193271 expect(((await bad.json()) as { ok: boolean; flash: string }).flash).toContain("Nothing saved.");
194272 });
195273
274 test("a slot's room is the machine against what one takes: a check is forge.json's declared share, a crew run 3 GiB with its CPU unmeasured, and a machine too small says so", async () => {
275 // The share is what the runner pool reads from the forge's own forge.json, whatever it says.
276 const root = join(import.meta.dir, "..");
277 const shape = shapeFromRepository(root);
outdated

The test pins forge.json's literal limits (16 cores, 8192 MiB, keep 2/4096), so an edit to forge.json breaks it. Compute the expectation from shapeFromRepository on the same file.

278 const declared = declaredCheckLimits(await Bun.file(join(root, "forge.json")).text()) !== undefined;
279 const checks = slotRoom("checks");
280 expect(checks).toMatchObject({ perCpus: shape.perRunnerCpus, perMiB: shape.perRunnerMemoryMiB, declared, keepCpus: shape.servingCpus, keepMiB: shape.servingMemoryMiB });
281 expect(checks.cpus).toBeGreaterThan(0);
282 expect(checks.memoryMiB).toBeGreaterThan(0);
283 expect(slotRoom("crew")).toMatchObject({ perCpus: null, perMiB: CREW_RUN_MIB, keepMiB: FORGE_OWN_MIB, declared: false });
284 provideCpusForTest(4);
285 try {
286 const page = await lanes();
287 const fig = /<div class="sl" data-kind="checks"[^>]*>/.exec(page)![0];
288 expect(fig).toContain('data-room-cpus="4"');
289 expect(fig).toContain(`data-room-per-cpus="${String(shape.perRunnerCpus)}"`);
290 expect(fig).toContain(`data-room-declared="${declared ? "1" : ""}"`);
291 expect(/<div class="sl" data-kind="crew"[^>]*>/.exec(page)![0]).toContain('data-room-per-cpus=""');
292 } finally {
293 provideCpusForTest(undefined);
294 }
295 });
296
196297 test("the slots are a forge admin's: a member's home has no slots, no figure and no estimate", async () => {
197298 const member = app.db.query<{ id: string; is_admin: number }, []>("SELECT id, is_admin FROM user WHERE username = 'scout'").get()!;
198299 expect(member.is_admin).toBe(0);
@@ -218,7 +319,8 @@ test.skipIf(skip)("keys on a figure: + turns the setting with its estimate, Ente
218319 out.head0 = bar.querySelector('.br-head').textContent;
219320 key('+');
220321 out.head1 = bar.querySelector('.br-head').textContent;
221 out.estimate = [...bar.querySelectorAll('.br-said')].map((p) => p.textContent).join(' | ');
322 out.estimate = [...bar.querySelectorAll('.br-said:not(.br-room)')].map((p) => p.textContent).join(' | ');
323 out.room = bar.querySelector('.br-room')?.textContent ?? '';
222324 key('Enter');
223325 await wait(() => (bar.querySelector('[data-said]')?.textContent ?? '').includes('→'));
224326 out.set = bar.querySelector('[data-said]').textContent;
@@ -239,7 +341,9 @@ test.skipIf(skip)("keys on a figure: + turns the setting with its estimate, Ente
239341 // Recorded with the estimate when there was a finished check to estimate from; said as one either
240342 // way.
241343 if (changes[1]!.reason !== "") expect(changes[1]!.reason).toMatch(/^Estimate: a new check waits ~\S+ at 5 slots \(\d+ s\)\.$/);
344 expect(s.room, seen).toMatch(/^5 checks would (use up to|need up to) \d+ cores and [\d.]+ GiB/);
345 expect(s.estimate + s.room, seen).not.toMatch(/nothing extra|free\b(?! beside)/);
242346 // The bar says it in plain words; the machine-readable form is only in the saved reason.
243 expect(s.estimate, seen).toMatch(/Estimate: a new check would wait about \S+ with 5 slots \(\S+ now\)\. Checks cost nothing extra\.|no estimate yet/);
347 expect(s.estimate, seen).toMatch(/Estimate: a new check would wait about \S+ with 5 slots \(\S+ now\)\.|no estimate yet/);
244348 expect(s.estimate, seen).not.toMatch(/\$0|machine| s\)/);
245349 }, 30_000);

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs