@johngaynor/ocnus 2.0.1-next.17 → 2.0.1-next.20

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
@@ -73,7 +73,8 @@ worked out. Until then the build step itself installs into each worktree what
73
73
  the tests need, and [`just`](https://just.systems) matters only once setup is
74
74
  on; see [what a repo provides](herdr/README.md#what-a-repo-provides). On
75
75
  Linux, the CPU mod in the `default` layout shows an error where its reading
76
- would be, since it reads macOS's `/usr/bin/top`.
76
+ would be, since it reads macOS's `/usr/bin/top`, and so does the Memory mod
77
+ above it, which reads macOS's `sysctl`, `vm_stat` and `ps`.
77
78
 
78
79
  ## Setting up a machine
79
80
 
@@ -88,8 +89,8 @@ and the two phase profiles in [agents/](agents/), which it links into
88
89
  `~/.claude/agents`; see [herdr/README.md](herdr/README.md) for the full
89
90
  walkthrough. `install` ends by telling you to switch Herdr to the `default`
90
91
  layout, which holds ocnus's panels: the Ocnus spaces panel, the Cards
91
- and Steps panels, the Usage section right above CPU, the Layout dropdown and
92
- the settings button. Herdr's own Agents section is not on it. Herdr starts on
92
+ and Steps panels, the Usage section above Memory and CPU, the Layout dropdown
93
+ and the settings button. Herdr's own Agents section is not on it. Herdr starts on
93
94
  its own layout, which has no Layout dropdown, so the first switch is
94
95
  `ctrl-shift-l`, pressed until `default` shows.
95
96
 
@@ -302,7 +303,7 @@ In Herdr, the settings button shows which is set and switches it with a
302
303
  click, through `billing subscription` and `billing api`; the key is saved in a
303
304
  terminal, with `billing key`.
304
305
 
305
- On the subscription, the Usage section, right above CPU in the `default`
306
+ On the subscription, the Usage section, above Memory and CPU in the `default`
306
307
  layout's sidebar, shows how much of your Claude subscription's five-hour and
307
308
  weekly usage limits is used, as a percentage and a bar each, and when each
308
309
  resets.
package/herdr/README.md CHANGED
@@ -8,14 +8,15 @@ a layout (a whole-window arrangement of mods).
8
8
  | Path | What it is |
9
9
  |---|---|
10
10
  | `mods/cpu/` | Live CPU usage with a scrolling history. macOS only (reads `/usr/bin/top`). |
11
- | `mods/usage/` | The Usage section, right above 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). |
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
+ | `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). |
12
13
  | `mods/layout-switch/` | A dropdown that shows the current layout and switches to another. |
13
14
  | `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. |
14
15
  | `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. |
15
16
  | `mods/steps/` | The steps of the card whose tab is selected: what each did, how long it took, and how long it waited on you. With no card's tab selected, the space's cards and where each stands. |
16
17
  | `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). |
17
18
  | `mods/names/` | Draws nothing. 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). |
18
- | `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 Usage section and the CPU mod in the sidebar, with Usage 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. |
19
+ | `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 Usage section, the Memory mod and the CPU mod in the sidebar, with 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. |
19
20
  | `spaces/template/` | The starting `SPACE.md` for every new space. |
20
21
 
21
22
  The skills are in [../skills/](../skills/), outside this folder. They are
@@ -1575,8 +1576,8 @@ ocnus billing key
1575
1576
 
1576
1577
  ### The Usage section
1577
1578
 
1578
- On the `default` layout, the Usage section sits in the sidebar right above
1579
- CPU, and is as small: how much of your Claude subscription's usage limits is
1579
+ On the `default` layout, the Usage section sits in the sidebar above Memory
1580
+ and CPU, and is as small: how much of your Claude subscription's usage limits is
1580
1581
  used, and when each resets, so you can pace the agents without leaving
1581
1582
  Herdr.
1582
1583
 
@@ -80,6 +80,16 @@
80
80
  "mod": "usage"
81
81
  }
82
82
  },
83
+ {
84
+ "id": "memory",
85
+ "type": "block",
86
+ "size": {
87
+ "px": 64
88
+ },
89
+ "content": {
90
+ "mod": "memory"
91
+ }
92
+ },
83
93
  {
84
94
  "id": "cpu",
85
95
  "type": "block",
@@ -0,0 +1,128 @@
1
+ // Live memory use, drawn as a scrolling history like the CPU mod's, which it
2
+ // sits above: memory used out of the Mac's total, a bar a reading whose
3
+ // colour is macOS's memory pressure, what the claude processes hold, and the
4
+ // swap in use.
5
+ //
6
+ // macOS only. It reads what macOS's own sysctl, vm_stat and ps print, and
7
+ // nothing that the host's recorder keeps, so it shows the same whether
8
+ // recording is on or off. What a reading is worked out from, and how, is in
9
+ // reading.js, which the tests run with node.
10
+ import { View, div } from "gpui-kit";
11
+ import { h_flex, v_flex } from "gpui-base";
12
+ import { exec, theme, window, checking, settings } from "herdr";
13
+ import { GB, reading, share, gb, outOf } from "./reading.js";
14
+
15
+ const SAMPLE_MS = 2000; // one reading every two seconds
16
+ const TIMEOUT_MS = 10000;
17
+ const BAR = 3; // px per reading
18
+ const GAP = 1;
19
+ const KEEP = 600; // readings kept, enough for a very wide panel
20
+ const HEIGHT = 64; // the block's own, as the layout gives it
21
+
22
+ // `herdr-app check` draws the mod once, and a reading there would run
23
+ // macOS's tools for nothing. It draws these instead: a reading at each
24
+ // pressure, so that a bar of each colour is drawn.
25
+ const SAMPLE = [
26
+ { total: 16 * GB, used: 9.4 * GB, pressure: "normal", swap: 0, claude: 3.3 * GB },
27
+ { total: 16 * GB, used: 13.1 * GB, pressure: "warning", swap: 1.5 * GB, claude: 4.2 * GB },
28
+ { total: 16 * GB, used: 15.2 * GB, pressure: "critical", swap: 6 * GB, claude: 4.4 * GB },
29
+ ];
30
+
31
+ // What a tool printed, or nothing when it could not be run or took too long.
32
+ // reading.js then says which tool gave no reading, in a line short enough to
33
+ // show whole, which Herdr's own words for a tool that is not there are not.
34
+ const printed = (run) => run.then((r) => r.stdout, () => "");
35
+
36
+ export default class Memory extends View {
37
+ init(_props, cx) {
38
+ this.samples = [];
39
+ this.busy = false;
40
+ this.error = null;
41
+ this.graph = { width: 240, height: 40 };
42
+ if (checking()) return;
43
+ cx.timer.every(SAMPLE_MS, (cx) => this.sample(cx));
44
+ this.sample(cx);
45
+ }
46
+
47
+ sample(cx) {
48
+ // Skip while a reading is in flight or nobody can see the window.
49
+ if (this.busy || window()?.visible === false) return;
50
+ this.busy = true;
51
+ cx.spawn(async (cx) => {
52
+ try {
53
+ const [sysctl, vmStat, ps] = await Promise.all([
54
+ printed(exec("/usr/sbin/sysctl", ["hw.memsize", "kern.memorystatus_vm_pressure_level", "vm.swapusage"], { timeout: TIMEOUT_MS })),
55
+ printed(exec("/usr/bin/vm_stat", [], { timeout: TIMEOUT_MS })),
56
+ printed(exec("/bin/ps", ["-axc", "-o", "rss=,comm="], { timeout: TIMEOUT_MS })),
57
+ ]);
58
+ const r = reading(sysctl, vmStat, ps);
59
+ if (r.reason) {
60
+ this.error = r.reason;
61
+ } else {
62
+ this.samples.push(r);
63
+ if (this.samples.length > KEEP) this.samples.shift();
64
+ this.error = null;
65
+ }
66
+ } catch (e) {
67
+ this.error = String(e?.message ?? e);
68
+ }
69
+ this.busy = false;
70
+ cx.notify();
71
+ });
72
+ }
73
+
74
+ render() {
75
+ if (checking()) {
76
+ // Both faces, so that a check draws each of them once: the figures
77
+ // beside a bar of each colour, and the line that takes the figures'
78
+ // place when there is no reading.
79
+ return v_flex().size_full()
80
+ .child(div().h(HEIGHT).child(this.face(SAMPLE, null, "sample")))
81
+ .child(div().h(HEIGHT).child(this.face([], "no reading from sysctl", "none")));
82
+ }
83
+ return this.face(this.samples, this.error, "memory");
84
+ }
85
+
86
+ // The readout, and the history beside it.
87
+ // samples the readings to draw, the newest last
88
+ // error why there is no reading now, or null
89
+ // key what the ids in it start with
90
+ face(samples, error, key) {
91
+ const t = theme();
92
+ // Activity Monitor's colours for memory pressure. A reading whose
93
+ // pressure could not be read has none of them.
94
+ const colors = { normal: t.ansi2, warning: t.ansi3, critical: t.ansi1 };
95
+ // With no reading now, the last one's figures would be stale.
96
+ const last = error ? null : samples.at(-1);
97
+
98
+ const fit = Math.max(1, Math.floor(this.graph.width / (BAR + GAP)));
99
+ const shown = samples.slice(-fit);
100
+ const h = Math.max(1, this.graph.height);
101
+
102
+ const readout = v_flex().flex_none().w(132).gap(2).justify_center()
103
+ .child(h_flex().gap(8).items_end()
104
+ .child(div().text_size(11).text_color(t.muted).child("MEM"))
105
+ .child(div().text_size(20).font_semibold().text_color(t.foreground).child(last ? gb(last.used) : "–"))
106
+ .when(Boolean(last), (el) => el.child(div().text_size(11).text_color(t.muted).child(outOf(last.total)))))
107
+ .child(error
108
+ ? div().text_size(11).text_color(t.blocked).truncate().child(error)
109
+ : h_flex().gap(10).text_size(11).text_color(t.muted)
110
+ .child(div().child(last ? `claude ${gb(last.claude)}` : "claude"))
111
+ .child(div().child(last ? `swap ${gb(last.swap)}` : "swap")));
112
+
113
+ const bars = h_flex().id(`${key}-graph`).flex_1().h_full().min_w(0).overflow_hidden()
114
+ .items_end().justify_end().gap(GAP).rounded(4).bg(t.surface)
115
+ .on_size_change((size, cx) => {
116
+ const zoom = Number(settings().zoom) || 1;
117
+ this.graph = { width: size.width / zoom, height: size.height / zoom };
118
+ cx.notify();
119
+ })
120
+ .children(shown.map((s) =>
121
+ div().flex_none().w(BAR).h(Math.round(share(s) * h)).bg(colors[s.pressure] ?? t.muted)));
122
+
123
+ return h_flex().size_full().px(14).py(8).gap(12).items_center()
124
+ .bg(t.chrome).border_t(1).border_color(t.border)
125
+ .child(readout)
126
+ .child(bars);
127
+ }
128
+ }
@@ -0,0 +1 @@
1
+ { "place": "none", "title": "Memory" }
@@ -0,0 +1,88 @@
1
+ // The Memory mod's arithmetic: from what macOS's tools print to a reading,
2
+ // and from a reading to what main.js draws of it. It is apart from main.js,
3
+ // and imports nothing, so that the tests can run it with node
4
+ // (test/memory.sh). So it uses only what any JavaScript has: nothing of
5
+ // Herdr's, and nothing of node's.
6
+
7
+ export const GB = 1024 ** 3;
8
+ // What `sysctl kern.memorystatus_vm_pressure_level` prints. macOS has these
9
+ // three levels and no other.
10
+ const PRESSURE = { 1: "normal", 2: "warning", 4: "critical" };
11
+ // The units `sysctl vm.swapusage` writes an amount in, in bytes.
12
+ const UNIT = { K: 1024, M: 1024 ** 2, G: GB };
13
+ // The counts of vm_stat's that memory used is worked out from, each by the
14
+ // name its line starts with.
15
+ const COUNTS = ["Anonymous pages", "Pages purgeable", "Pages wired down", "Pages occupied by compressor"];
16
+
17
+ // One of vm_stat's counts, in pages, or null when it has no line for it.
18
+ function pages(vmStat, name) {
19
+ const m = vmStat.match(new RegExp(`^${name}:\\s+(\\d+)\\.?\\s*$`, "m"));
20
+ return m ? Number(m[1]) : null;
21
+ }
22
+
23
+ // The reading that the three tools' output gives:
24
+ // sysctl what sysctl prints for hw.memsize, vm.swapusage and
25
+ // kern.memorystatus_vm_pressure_level, each after its name
26
+ // vmStat what vm_stat prints
27
+ // ps what `ps -axc -o rss=,comm=` prints: each process's resident
28
+ // memory in KB, then its command's name
29
+ // It is { total, used, pressure, swap, claude }: bytes, but for the
30
+ // pressure, which is "normal", "warning" or "critical".
31
+ //
32
+ // Memory used is counted as Activity Monitor's Memory Used counts it, which
33
+ // is how the host's recorder counts mem_used_mb (cli/lib/host.sh): the
34
+ // anonymous pages less the purgeable ones, plus the wired ones and those the
35
+ // compressor occupies. claude is the resident memory of every process whose
36
+ // command is exactly claude, and 0 when ps lists none.
37
+ //
38
+ // Without the Mac's total or memory used there is nothing to draw, so the
39
+ // reading is { reason } instead: one short line that says which tool gave
40
+ // none. Any other value that cannot be read is null, and the rest of the
41
+ // reading is kept.
42
+ export function reading(sysctl = "", vmStat = "", ps = "") {
43
+ const total = Number(sysctl.match(/^hw\.memsize:\s*(\d+)\s*$/m)?.[1] ?? 0);
44
+ if (!(total > 0)) return { reason: "no reading from sysctl" };
45
+
46
+ const page = Number(vmStat.match(/page size of (\d+) bytes/)?.[1] ?? 0);
47
+ const counts = COUNTS.map((name) => pages(vmStat, name));
48
+ if (!(page > 0) || counts.includes(null)) return { reason: "no reading from vm_stat" };
49
+ const [anonymous, purgeable, wired, compressor] = counts;
50
+
51
+ const level = sysctl.match(/^kern\.memorystatus_vm_pressure_level:\s*(\d+)\s*$/m)?.[1];
52
+ const swap = sysctl.match(/^vm\.swapusage:.*\bused = (\d+(?:\.\d+)?)([KMG])/m);
53
+
54
+ // ps lists every process, so one that lists none did not run.
55
+ let listed = 0;
56
+ let held = 0;
57
+ for (const line of ps.split("\n")) {
58
+ const m = line.match(/^\s*(\d+)\s+(.*?)\s*$/);
59
+ if (!m) continue;
60
+ listed += 1;
61
+ if (m[2] === "claude") held += Number(m[1]) * 1024;
62
+ }
63
+
64
+ return {
65
+ total,
66
+ used: (anonymous - purgeable + wired + compressor) * page,
67
+ pressure: PRESSURE[level] ?? null,
68
+ swap: swap ? Math.round(Number(swap[1]) * UNIT[swap[2]]) : null,
69
+ claude: listed ? held : null,
70
+ };
71
+ }
72
+
73
+ // The share of the Mac's memory in use, which is how high a reading's bar
74
+ // is: from 0 to 1, whatever the counts say.
75
+ export const share = (r) => Math.min(1, Math.max(0, r.used / r.total));
76
+
77
+ // An amount of memory as the readout writes it, in GB to one decimal: 9.4.
78
+ // None at all is 0, so that no claude process, or no swap in use, reads as
79
+ // none and not as 0.0, which is an amount too small to show. One that could
80
+ // not be read is –.
81
+ export function gb(bytes) {
82
+ if (bytes == null) return "–";
83
+ return bytes === 0 ? "0" : (bytes / GB).toFixed(1);
84
+ }
85
+
86
+ // The Mac's total as the readout writes it after memory used: / 16 GB. A
87
+ // whole number of GB has no decimal.
88
+ export const outOf = (total) => `/ ${Math.round((total / GB) * 10) / 10} GB`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johngaynor/ocnus",
3
- "version": "2.0.1-next.17",
3
+ "version": "2.0.1-next.20",
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": {