@johngaynor/ocnus 2.0.1-next.94 → 2.0.1-next.98

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.
package/README.md CHANGED
@@ -92,7 +92,8 @@ and the two phase profiles in [agents/](agents/), which it links into
92
92
  walkthrough. `install` ends by telling you to switch Herdr to the `default`
93
93
  layout, which holds ocnus's panels: the Ocnus spaces panel, the Cards
94
94
  and Steps panels, the Step counts section right above the Usage section,
95
- which is above Memory and CPU, the Layout dropdown and the settings button.
95
+ which is above Memory and CPU, the Test runs section right under CPU, the
96
+ Layout dropdown and the settings button.
96
97
  Herdr's own Agents section is not on it. Herdr starts on
97
98
  its own layout, which has no Layout dropdown, so the first switch is
98
99
  `ctrl-shift-l`, pressed until `default` shows. The Layout dropdown lists
@@ -296,7 +297,10 @@ turn, having its turn or running with `OCNUS_TEST_JOBS`, how long ago it
296
297
  started, and how many processors it holds, such as `5/10`. A run that
297
298
  started before a switch and still goes the way it started, sharing though the
298
299
  runs now queue, or waiting though they now share, is marked `old mode`. With
299
- no run going it says so in one line.
300
+ no run going it says so in one line. In Herdr, the Test runs section, right
301
+ under CPU in the `default` layout's sidebar, shows the same, reading
302
+ `ocnus tests ls --json` every 2 seconds: one line with no run going, and a
303
+ row taller for each run going, as far as the window has room.
300
304
 
301
305
  The file also says whether breakdown, the last step of the write-up phase,
302
306
  asks you to approve each card, as `"approval": {"breakdown": true}` or
package/herdr/README.md CHANGED
@@ -10,6 +10,7 @@ layouts (whole-window arrangements of mods).
10
10
  | `mods/cpu/` | Live CPU usage with a scrolling history. macOS only (reads `/usr/bin/top`). |
11
11
  | `mods/memory/` | Live memory use with a scrolling history, like the CPU mod's: memory used out of the Mac's total, in GB, as Activity Monitor's Memory Used counts it. Each reading is a bar as high as the share of the Mac's memory in use, coloured by macOS's memory pressure: green for normal, yellow for warning, red for critical. Under the figure, `claude` is the resident memory of every process whose command is `claude`: ocnus's agents, while their harness is `claude`, and any Claude Code session you opened yourself, but not what they run, such as a test run, which counts in memory used alone. So it is not the recorder's `mem_agents_mb`, which counts every process under a terminal labelled with one of your spaces (see [Recording the host](#recording-the-host)). `swap` is the swap in use. It reads macOS itself, so it shows the same whether recording is on or off. macOS only (reads `sysctl`, `vm_stat` and `ps`). |
12
12
  | `mods/usage/` | The Usage section, above Memory and CPU, and as small: how much of your Claude subscription's five-hour and weekly usage limits is used, as a percentage and a bar each, and when each resets, as the agents ocnus starts last read them. See [The Usage section](#the-usage-section). |
13
+ | `mods/test-runs/` | The Test runs section, right under CPU: the runs of ocnus's own tests going on this machine, a row each with its card or folder, how it is going, how long ago it started and the processors it holds, and whether `ocnus tests` has them share the processors or queue. It is one line with no run going, a row taller for each run going, and never takes room another section of the sidebar needs. See [The Test runs section](#the-test-runs-section). |
13
14
  | `mods/layout-switch/` | A dropdown that shows the current layout and switches to another. |
14
15
  | `mods/ocnus-spaces/` | The Ocnus spaces panel: every space in your config, open or not. Click one to show it; `+` makes a new one. It is not `spaces`, which is Herdr's own list of the spaces it has open. |
15
16
  | `mods/cards/` | The open Linear cards of the space that is showing, under their statuses. Start writes a card up with `task new`; Open shows the tab of a card already started. |
@@ -19,8 +20,8 @@ layouts (whole-window arrangements of mods).
19
20
  | `mods/needs-you/` | Needs you, the right column of `vibe`: the questions that wait on you in the space that is showing, most urgent first, each answered with a click, with nothing typed in the agent's tab. See [Needs you](#needs-you). |
20
21
  | `mods/agent-settings/` | The settings button, a cog at the right end of the tab bar, and the popup it opens: the model and effort of each phase profile and dev profile, then the breakdown approval, archiving, the tests setting and billing, each of which a click changes. See [The settings button](#the-settings-button). |
21
22
  | `mods/names/` | Draws nothing but a note saying what it does, and that only where a layout asks for it, as `showcase` does. It gives the spaces and tabs the app takes in from herdr-core, for agents started while the app was closed, the names ocnus gave them. See [Writing the card up](#writing-the-card-up). |
22
- | `layouts/default.json` | Herdr's own layout with ocnus's panels: the Ocnus spaces panel, the `ocnus-spaces` mod, in place of Herdr's own list of spaces; the layout dropdown, the Cards and Steps panels, the Step counts section, the Usage section, the Memory mod and the CPU mod in the sidebar, with the Step counts right above Usage, Usage above Memory and CPU, and Memory right above CPU; and the settings button beside the tabs. Herdr's Agents section, its `agents` mod, is not on it. The tab bar is a row of Herdr's `tabs`, `agent-settings` and `names`, in a block 1px wide, since a mod runs only while a layout places it. |
23
- | `layouts/showcase.json` | For seeing each mod working before you choose what to put in a layout of your own: it places every mod ocnus ships, each in a block of its own that shows as soon as the layout opens, and each is the mod itself, on this machine's own data, as on `default`. It is `default` with four changes: the card list, which `default` does not have, is a column of its own left of the terminals, 540px wide; Needs you, which `default` does not have either, is a column of its own right of them, 368px wide; the Usage section, the Memory mod and the CPU mod leave the sidebar for a row along the bottom, under the terminals; and `names` sits at the end of that row, where it draws a note saying that it draws nothing, and what it does. `npm test` fails, naming the mod, when a mod in `mods/` is not on it, so a card that adds a mod adds it here too. |
23
+ | `layouts/default.json` | Herdr's own layout with ocnus's panels: the Ocnus spaces panel, the `ocnus-spaces` mod, in place of Herdr's own list of spaces; the layout dropdown, the Cards and Steps panels, the Step counts section, the Usage section, the Memory mod, the CPU mod and the Test runs section in the sidebar, with the Step counts right above Usage, Usage above Memory and CPU, Memory right above CPU, and the Test runs section right under CPU; and the settings button beside the tabs. Herdr's Agents section, its `agents` mod, is not on it. The tab bar is a row of Herdr's `tabs`, `agent-settings` and `names`, in a block 1px wide, since a mod runs only while a layout places it. |
24
+ | `layouts/showcase.json` | For seeing each mod working before you choose what to put in a layout of your own: it places every mod ocnus ships, each in a block of its own that shows as soon as the layout opens, and each is the mod itself, on this machine's own data, as on `default`. It is `default` with four changes: the card list, which `default` does not have, is a column of its own left of the terminals, 540px wide; Needs you, which `default` does not have either, is a column of its own right of them, 368px wide; the Usage section, the Memory mod and the CPU mod leave the sidebar for a row along the bottom, under the terminals, which leaves the Test runs section right under the Step counts; and `names` sits at the end of that row, where it draws a note saying that it draws nothing, and what it does. `npm test` fails, naming the mod, when a mod in `mods/` is not on it, so a card that adds a mod adds it here too. |
24
25
  | `layouts/vibe.json` | Three columns side by side, each the window's full height, for steering every agent without reading code. The left one is the sidebar, 268px wide as `default`'s is: Herdr's brand, the layout dropdown, the Ocnus spaces panel and, at its bottom, the Step counts section, the Usage section, the Memory mod and the CPU mod, stacked in that order with nothing between them. The middle one is the card list, the `card-list` mod, which fills its place there (see [The card list](#the-card-list)), above the place for Brainstorm (LAB-240), and the right one is Needs you, the `needs-you` mod (see [Needs you](#needs-you)), which turns into the opened agent (LAB-239). The place for Brainstorm is still empty: it is a column with nothing in it, which its card swaps for the mod's block, so the layout names no mod that is not installed. It shows no files, diffs or split terminals: it has no Files panel, no Changes panel, no tab bar and no block for a tab's terminals, shown or hidden, so code is only in the pull requests. It has no settings button and no footer either: the settings button is on `default`, and Herdr's Settings still opens by its key. The `names` mod is beside the brand, in a block 1px wide. `layouts/vibe.svg`, beside it, is its picture in Herdr's Settings: `ocnus install` and `ocnus update` link it, and `ocnus status` lists it, as they do a layout. |
25
26
  | `spaces/template/` | The starting `SPACE.md` for every new space. |
26
27
 
@@ -2274,7 +2275,8 @@ ocnus tests ls [--json]
2274
2275
  `card` is null outside a task, `state` is `share`, `wait`, `jobs` or
2275
2276
  `turn`, and `doing` gives its words, `mark` is `"old mode"` or null, and
2276
2277
  `tip` says what the mark means, `age` is how long ago the run started, as
2277
- text, and `holds` is its `slots` out of `cpus`, such as `"5/10"`.
2278
+ text, and `holds` is its `slots` out of `cpus`, such as `"5/10"`. The
2279
+ Test runs section draws it (see [The Test runs section](#the-test-runs-section)).
2278
2280
  - **In Herdr, the settings button shows it and switches it** between share
2279
2281
  and queue with a click, through these commands (see
2280
2282
  [The settings button](#the-settings-button)).
@@ -2288,6 +2290,54 @@ ocnus tests ls [--json]
2288
2290
  `npm test` through it shares the processors, or waits its turn, as it
2289
2291
  does run alone.
2290
2292
 
2293
+ ### The Test runs section
2294
+
2295
+ On the `default` layout, the Test runs section sits in the sidebar right
2296
+ under CPU, with the same line above it as the Usage and CPU sections: the
2297
+ runs of ocnus's own tests going on this machine, and whether `ocnus tests`
2298
+ has them share the processors or queue. So you can see why the CPU looks as
2299
+ it does, and why a run still shares after a switch to queue, without leaving
2300
+ Herdr.
2301
+
2302
+ - **Its first line is `Test runs`, with `share` or `queue` at its right**:
2303
+ which way `ocnus tests` is set (see
2304
+ [Test runs one at a time](#test-runs-one-at-a-time)). With no run going,
2305
+ that one line is all it is, and says `No test runs going`.
2306
+ - **A row for each run going**, in the order the runs started, which is the
2307
+ order the waiting ones get their turns. A row shows the run's card, such
2308
+ as `LAB-241`, when it was started in a task's folder, and its folder's
2309
+ name otherwise; how it is going, `sharing`, `waiting`, `its turn` or
2310
+ `OCNUS_TEST_JOBS`, with `old mode` after it in yellow for a run started
2311
+ before a switch that still goes the way it started; how long ago it
2312
+ started, its wait for a turn included, such as `13m 02s`; and the
2313
+ processors it holds out of the machine's, such as `5/10`. Over a marked
2314
+ row, the tooltip says what the mark means.
2315
+ - **It is as tall as what it shows**, with no click: one line with no run
2316
+ going, a row taller for each run going, and smaller again as runs end. It
2317
+ resizes its own block, and Herdr keeps that size as a click of the
2318
+ layout's, in `~/.config/herdr-app/layouts/.state/`, never in
2319
+ `default.json`.
2320
+ - **It never takes room another section needs.** It grows only into what
2321
+ the window has left once every other section of the sidebar has its size
2322
+ and each list its least height. When that is short of a row for every run,
2323
+ the rows that fit show, the first ones in that order, and a last line,
2324
+ `+N more`, says how many more runs there are; with room for one line
2325
+ alone, that line says it. A window made taller or shorter shows more rows
2326
+ or fewer from the next read.
2327
+ - **It reads every 2 seconds** while the window can be seen, with
2328
+ `ocnus tests ls --json`, and works nothing out itself: each run's name,
2329
+ how it is going, its mark and what the mark means, how long ago it started
2330
+ and the processors it holds come from the command. So a run that starts,
2331
+ ends or gets its turn, and a switch of the setting, show within a few
2332
+ seconds. When `ocnus` is not on Herdr's `PATH`, it runs the copy the mod
2333
+ is linked from.
2334
+ - **When it cannot read the runs or the setting**, its one line says why,
2335
+ as `ocnus tests ls` does, and an `ocnus` from before `tests ls` says to
2336
+ run `ocnus update`. The rest of the sidebar works as before.
2337
+ - **On the sidebar's rail** it shows only how many runs are going.
2338
+ - **It only shows.** The settings button, `ocnus tests share` and
2339
+ `ocnus tests queue` switch the setting.
2340
+
2291
2341
  ### The breakdown approval
2292
2342
 
2293
2343
  The settings file also says whether breakdown, the last step of the write-up
@@ -110,6 +110,16 @@
110
110
  "mod": "cpu"
111
111
  }
112
112
  },
113
+ {
114
+ "id": "test-runs",
115
+ "type": "block",
116
+ "size": {
117
+ "px": 27
118
+ },
119
+ "content": {
120
+ "mod": "test-runs"
121
+ }
122
+ },
113
123
  {
114
124
  "id": "sidebar-footer",
115
125
  "type": "block",
@@ -76,6 +76,16 @@
76
76
  "mod": "step-counts"
77
77
  }
78
78
  },
79
+ {
80
+ "id": "test-runs",
81
+ "type": "block",
82
+ "size": {
83
+ "px": 27
84
+ },
85
+ "content": {
86
+ "mod": "test-runs"
87
+ }
88
+ },
79
89
  {
80
90
  "id": "sidebar-footer",
81
91
  "type": "block",
@@ -0,0 +1,78 @@
1
+ // How tall the Test runs section's block is, and how many of its rows show.
2
+ // It is apart from main.js, and imports nothing, so that the tests can run it
3
+ // with node (test/test-runs.sh). So it uses only what any JavaScript has:
4
+ // nothing of Herdr's, and nothing of node's.
5
+ //
6
+ // The block is as tall as what it shows: one line with no run going, and a
7
+ // row taller for each run going. It takes no more than the room its column
8
+ // leaves it, so it never squeezes another section of the sidebar, or a list
9
+ // below its min. When the room is short of a row for every run, the rows
10
+ // that fit show, and a line says how many more runs there are.
11
+
12
+ // The section's sizes, in the layout's px, as main.js draws it: the line
13
+ // above it, its padding above and below, a line of its 11px text at a line
14
+ // height of 1.25, and the gap between two lines. A row is one line.
15
+ export const BORDER = 1;
16
+ export const PAD = 6;
17
+ export const LINE = 11 * 1.25;
18
+ export const GAP = 2;
19
+
20
+ // The block's px for this many lines, rounded up to a whole px: the first
21
+ // line, then a line for each row, and one for how many more runs there are.
22
+ export const height = (lines) => Math.ceil(BORDER + 2 * PAD + lines * LINE + (lines - 1) * GAP);
23
+
24
+ // The first node of the layout, in the order it lists them, that passes the
25
+ // test, and the node it is a child of: { node, parent }, or null when there
26
+ // is none. The root's parent is null.
27
+ export function find(node, test, parent = null) {
28
+ if (!node || typeof node !== "object") return null;
29
+ if (test(node)) return { node, parent };
30
+ for (const child of Array.isArray(node.children) ? node.children : []) {
31
+ const found = find(child, test, node);
32
+ if (found) return found;
33
+ }
34
+ return null;
35
+ }
36
+
37
+ // The least height of a layout node: its px, else its min, else what its
38
+ // children need, which is all of them in a column and the tallest of them
39
+ // otherwise. A hidden node needs none.
40
+ export function least(node) {
41
+ if (!node || typeof node !== "object" || node.hidden) return 0;
42
+ const px = node.size?.px;
43
+ if (typeof px === "number") return px;
44
+ if (typeof node.min === "number") return node.min;
45
+ const needs = (Array.isArray(node.children) ? node.children : []).map(least);
46
+ if (!needs.length) return 0;
47
+ return node.type === "column" ? needs.reduce((all, one) => all + one, 0) : Math.max(...needs);
48
+ }
49
+
50
+ // The room the block may take, in px: the window's height less the least
51
+ // of every other child of its column. at is the block, as find gives it.
52
+ // Null when the block is not a column's child, since its px would then be
53
+ // its width, or when the window's height is not known.
54
+ export function room(at, tall) {
55
+ if (!at || at.parent?.type !== "column" || !(tall > 0)) return null;
56
+ return at.parent.children.reduce((left, child) => (child === at.node ? left : left - least(child)), tall);
57
+ }
58
+
59
+ // With count runs going and room px for the block, { rows, more, px }: how
60
+ // many rows show, how many more runs there are than rows, and the block's
61
+ // px. Every row shows when the room holds them all. Otherwise the first rows
62
+ // that fit show, and a line under them says how many more there are; with
63
+ // no room for that line either, the first line says it. The px is never less
64
+ // than one line, which is all it is with no run going. With room null, every
65
+ // row shows, and there is no px.
66
+ export function fit(count, room) {
67
+ const runs = Math.max(0, Math.floor(Number(count)) || 0);
68
+ if (room === null || room === undefined) return { rows: runs, more: 0, px: null };
69
+ if (!runs || height(1 + runs) <= room) return { rows: runs, more: 0, px: height(1 + runs) };
70
+ let rows = runs - 1;
71
+ while (rows > 0 && height(2 + rows) > room) rows -= 1;
72
+ if (!rows && height(2) > room) return { rows: 0, more: runs, px: height(1) };
73
+ return { rows, more: runs - rows, px: height(2 + rows) };
74
+ }
75
+
76
+ // Whether, in the block fit gives, how many more runs there are has a line
77
+ // of its own under the rows. When it does not, the first line says it.
78
+ export const below = (shown) => shown.more > 0 && shown.px !== null && shown.px > height(1 + shown.rows);
@@ -0,0 +1,242 @@
1
+ // The Test runs section: the runs of ocnus's own tests going on this
2
+ // machine, a row each, and which way `ocnus tests` is set. It sits under CPU
3
+ // in the default layout's sidebar, and is as tall as what it shows: one line
4
+ // with no run going, and a row taller for each run going.
5
+ //
6
+ // All of that is worked out by `ocnus tests ls --json`, which reads the pool
7
+ // test/run.sh keeps the runs in. This mod draws what that command returns
8
+ // and holds no rules about the runs: each run's name, what it is doing, its
9
+ // mark and what the mark means, how long ago it started and the processors
10
+ // it holds all arrive as text, and so does the line to show with no run
11
+ // going. How tall the block may grow, and how many rows show, is worked out
12
+ // in fit.js, which the tests run with node. The mod resizes its own block to
13
+ // that, and Herdr keeps the size as a click of the layout's, never in the
14
+ // layout's file.
15
+ import { View, div } from "gpui-kit";
16
+ import { h_flex, v_flex } from "gpui-base";
17
+ import { exec, run, theme, window, layout, settings, checking, appHome } from "herdr";
18
+ import { find, room, fit, below, height } from "./fit.js";
19
+
20
+ // A run that starts, ends or gets its turn shows within this and a read.
21
+ const READ_MS = 2000;
22
+ const TIMEOUT_MS = 10000;
23
+ // The mod, as a layout's block names it.
24
+ const MOD = "test-runs";
25
+ // How this mod's own link into the repo that ships it ends.
26
+ const LINKED_AT = "/herdr/mods/test-runs";
27
+
28
+ // `herdr-app check` draws the mod once, with nothing read. It is given
29
+ // this to draw, so a mistake in a row fails the check: a run in each state,
30
+ // two of them marked old mode, and more runs than there is room for.
31
+ const SAMPLE = {
32
+ tests: "queue", cpus: 10, note: null,
33
+ runs: [
34
+ { number: 1, pid: 101, name: "LAB-248", state: "turn", doing: "its turn", mark: null, tip: null, age: "4m 10s", holds: "10/10" },
35
+ { number: 2, pid: 102, name: "ocnus", state: "share", doing: "sharing", mark: "old mode",
36
+ tip: "Started before the switch to queue, so it still shares the processors", age: "3m 02s", holds: "2/10" },
37
+ { number: 3, pid: 103, name: "LAB-7", state: "jobs", doing: "OCNUS_TEST_JOBS", mark: "old mode",
38
+ tip: "Started before the switch to queue, so it still runs beside the runs ahead of it", age: "1m 05s", holds: "4/10" },
39
+ { number: 4, pid: 104, name: "ABC-9", state: "wait", doing: "waiting", mark: null, tip: null, age: "50s", holds: "0/10" },
40
+ { number: 5, pid: 105, name: "LAB-12", state: "wait", doing: "waiting", mark: null, tip: null, age: "12s", holds: "0/10" },
41
+ { number: 6, pid: 106, name: "LAB-13", state: "wait", doing: "waiting", mark: null, tip: null, age: "3s", holds: "0/10" },
42
+ ],
43
+ };
44
+ // Room for four of the sample's six rows, and the line that says there are
45
+ // two more.
46
+ const SAMPLE_FIT = fit(6, height(6));
47
+
48
+ function parse(text) {
49
+ try {
50
+ return JSON.parse(text);
51
+ } catch {
52
+ return null;
53
+ }
54
+ }
55
+
56
+ // What a failed command said, without the name it starts its errors with.
57
+ const said = (r) => (r.stderr || r.stdout).trim().replace(/^ocnus: /, "");
58
+
59
+ const OLD_CLI = "This ocnus is too old for Test runs. Run: ocnus update";
60
+ // An ocnus from before `tests ls` answers `tests ls --json` with the usage
61
+ // of `tests`, and one from before `tests` with its help, not JSON.
62
+ const failure = (r) => {
63
+ const text = said(r);
64
+ return text.startsWith("set up and maintain") || text.startsWith("usage:") ? OLD_CLI : text || "ocnus tests ls failed";
65
+ };
66
+
67
+ // The sidebar's rail goes by its width, as in Herdr's own lists.
68
+ const narrow = () => (find(layout(), (n) => n.id === "sidebar")?.node.size?.px ?? Infinity) < 160;
69
+
70
+ export default class TestRuns extends View {
71
+ init(_props, cx) {
72
+ this.cmd = "ocnus"; // the one on PATH, until that cannot start
73
+ this.view = null;
74
+ this.error = null;
75
+ this.busy = false;
76
+ this.loaded = false; // whether a read has ended yet
77
+ this.tall = null; // the window's height in the layout's px, as last drawn
78
+ this.shown = fit(0, null); // how many rows show, how many more there are, and the block's px
79
+ this.drawn = null; // what the last redraw showed, to redraw only on a change
80
+ if (checking()) return;
81
+ cx.timer.every(READ_MS, (cx) => this.look(cx));
82
+ this.look(cx);
83
+ }
84
+
85
+ // Runs the ocnus command. One that cannot run is tried again as the
86
+ // copy this mod is linked from: Herdr may have been started without the
87
+ // user's PATH. `tests ls --json` only reads, so twice is safe.
88
+ async ocnus(args) {
89
+ try {
90
+ return await exec(this.cmd, args, { timeout: TIMEOUT_MS });
91
+ } catch (e) {
92
+ if (this.cmd !== "ocnus") throw e;
93
+ const link = await exec("readlink", [`${appHome()}/mods/${MOD}`]);
94
+ const to = link.stdout.trim();
95
+ if (link.code !== 0 || !to.endsWith(LINKED_AT)) throw e;
96
+ this.cmd = `${to.slice(0, -LINKED_AT.length)}/cli/ocnus`;
97
+ return exec(this.cmd, args, { timeout: TIMEOUT_MS });
98
+ }
99
+ }
100
+
101
+ // Read the runs again, unless a read is in flight or nobody can see the
102
+ // window, then fit the block to what it shows.
103
+ look(cx) {
104
+ if (this.busy || window()?.visible === false) return;
105
+ this.busy = true;
106
+ cx.spawn(async (cx) => {
107
+ let view = null;
108
+ let error = null;
109
+ try {
110
+ const r = await this.ocnus(["tests", "ls", "--json"]);
111
+ const got = r.code === 0 ? parse(r.stdout) : null;
112
+ if (got && typeof got === "object" && Array.isArray(got.runs)) view = got;
113
+ else error = r.code === 0 ? OLD_CLI : failure(r);
114
+ } catch (e) {
115
+ error = `Could not run ocnus: ${e?.message ?? e}`;
116
+ }
117
+ this.view = view;
118
+ this.error = error;
119
+ this.loaded = true;
120
+ this.busy = false;
121
+ this.size();
122
+ // A redraw of a mod redraws the whole window, so only when what it
123
+ // shows has changed, such as the age of a run going.
124
+ const drawn = JSON.stringify([view, error, this.shown]);
125
+ if (drawn !== this.drawn) {
126
+ this.drawn = drawn;
127
+ cx.notify();
128
+ }
129
+ });
130
+ }
131
+
132
+ // Fit the block to what it shows: a row for each run going, when the
133
+ // window has room for them all, and never less than one line, which is
134
+ // all it is on the sidebar's rail and when the runs cannot be read. Its
135
+ // block is the one of the shown layout that places this mod.
136
+ size() {
137
+ const count = this.error || narrow() ? 0 : this.view?.runs.length ?? 0;
138
+ const at = find(layout(), (n) => n.content?.mod === MOD);
139
+ this.shown = fit(count, room(at, this.tall));
140
+ const px = this.shown.px;
141
+ if (px === null || !at?.node.id || Math.abs((at.node.size?.px ?? 0) - px) < 0.5) return;
142
+ try {
143
+ run("layout.resize", { id: at.node.id, px });
144
+ } catch {
145
+ // The block keeps the size it has, and shows what fits in it.
146
+ }
147
+ }
148
+
149
+ // Note the window's height in the layout's px, which the block's room is
150
+ // worked out from. Herdr's own global window gives it, only while a mod
151
+ // draws; the window this mod imports from Herdr hides that name.
152
+ measure() {
153
+ try {
154
+ const tall = globalThis.window.viewport_size().height / (Number(settings().zoom) || 1);
155
+ if (tall > 0) this.tall = tall;
156
+ } catch {
157
+ // A Herdr without it: the block keeps the size it has.
158
+ }
159
+ }
160
+
161
+ // A run on one line: its name, what it is doing with its mark after it,
162
+ // how long ago it started, and the processors it holds. What the mark
163
+ // means is the row's tooltip.
164
+ row(r, t) {
165
+ return h_flex().id(`test-run-${r.number}-${r.pid}`).flex_none().gap(6).items_center()
166
+ .when(Boolean(r.tip), (el) => el.tooltip(r.tip))
167
+ .child(div().w(56).flex_none().text_color(t.foreground).truncate().child(r.name ?? ""))
168
+ .child(h_flex().flex_1().min_w(0).gap(4).items_center()
169
+ .child(div().min_w(0).text_color(t.muted).truncate().child(r.doing ?? ""))
170
+ .when(Boolean(r.mark), (el) => el.child(div().flex_none().text_color(t.ansi3).child(r.mark))))
171
+ .child(div().flex_none().text_color(t.dim).child(r.age ?? ""))
172
+ .child(h_flex().min_w(30).flex_none().justify_end().text_color(t.muted).child(r.holds ?? ""));
173
+ }
174
+
175
+ // The section: its first line, a row for each run that shows, in the order
176
+ // the command gives them, and how many more runs there are. view is what
177
+ // `tests ls --json` gave, error what went wrong reading it, and shown what
178
+ // fit gives for it. With 11px text at a line height of 1.25, every line is
179
+ // as tall as fit.js counts it.
180
+ face(t, view, error, shown, loaded) {
181
+ const runs = error ? [] : view?.runs ?? [];
182
+ const more = `+${shown.more} more`;
183
+ const note = (text, color) => div().flex_1().min_w(0).text_color(color).truncate().child(text);
184
+ // Between the title and the setting: that it is reading, what went
185
+ // wrong, that no run is going, or how many more runs there are when the
186
+ // block has no line for that.
187
+ let middle = div().flex_1();
188
+ if (!loaded) middle = note("Reading…", t.dim);
189
+ else if (error) middle = div().id("test-runs-error").flex_1().min_w(0).text_color(t.blocked).truncate().tooltip(error).child(error);
190
+ else if (view?.note) middle = note(view.note, t.dim);
191
+ else if (shown.more > 0 && !below(shown)) middle = note(more, t.dim);
192
+ return v_flex().size_full().px(14).py(6).gap(2).line_height(1.25).overflow_hidden()
193
+ .text_size(11).bg(t.chrome).border_t(1).border_color(t.border)
194
+ .child(h_flex().flex_none().gap(8).items_center()
195
+ .child(div().flex_none().text_color(t.muted).child("Test runs"))
196
+ .child(middle)
197
+ .child(div().flex_none().text_color(t.dim).child(error ? "" : view?.tests ?? "")))
198
+ .children(runs.slice(0, shown.rows).map((r) => this.row(r, t)))
199
+ .when(below(shown), (el) => el.child(div().flex_none().text_color(t.dim).child(more)));
200
+ }
201
+
202
+ // On the sidebar's rail there is no room for the rows: how many runs are
203
+ // going, on its one line, or a mark when they cannot be read, with the
204
+ // words in its tooltip.
205
+ rail(t, view, error, loaded) {
206
+ const count = view?.runs.length ?? 0;
207
+ const words = view?.note ?? `${count} test run${count === 1 ? "" : "s"} going`;
208
+ return v_flex().size_full().py(6).line_height(1.25).overflow_hidden().items_center()
209
+ .text_size(11).bg(t.chrome).border_t(1).border_color(t.border)
210
+ .child(error
211
+ ? div().id("test-runs-error").text_color(t.blocked).tooltip(error).child("!")
212
+ : div().id("test-runs-count").text_color(count ? t.foreground : t.dim)
213
+ .tooltip(loaded ? words : "Reading…").child(loaded ? String(count) : "…"));
214
+ }
215
+
216
+ // What `herdr-app check` draws: each face of the section once, so that a
217
+ // mistake in any of them fails the check. The sample, with a line for how
218
+ // many more runs there are; no run going; a failure; the sample in one
219
+ // line, which then says how many more there are; reading; and the rail.
220
+ checked(t) {
221
+ const one = height(1);
222
+ const none = { tests: "share", cpus: 10, note: "No test runs going", runs: [] };
223
+ const tight = fit(SAMPLE.runs.length, one);
224
+ const face = (shown, view, error, loaded = true) =>
225
+ div().h(shown.px).flex_none().child(this.face(t, view, error, shown, loaded));
226
+ return v_flex().size_full()
227
+ .child(face(SAMPLE_FIT, SAMPLE, null))
228
+ .child(face(fit(0, one), none, null))
229
+ .child(face(fit(0, one), null, OLD_CLI))
230
+ .child(face(tight, SAMPLE, null))
231
+ .child(face(fit(0, one), null, null, false))
232
+ .child(div().w(44).h(one).flex_none().child(this.rail(t, SAMPLE, null, true)));
233
+ }
234
+
235
+ render() {
236
+ const t = theme();
237
+ if (checking()) return this.checked(t);
238
+ this.measure();
239
+ if (narrow()) return this.rail(t, this.view, this.error, this.loaded);
240
+ return this.face(t, this.view, this.error, this.shown, this.loaded);
241
+ }
242
+ }
@@ -0,0 +1 @@
1
+ { "place": "none", "title": "Test runs" }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johngaynor/ocnus",
3
- "version": "2.0.1-next.94",
3
+ "version": "2.0.1-next.98",
4
4
  "description": "A software factory: agent skills and the Herdr setup to run them, installed with one command.",
5
5
  "license": "MIT",
6
6
  "bin": {