@johngaynor/ocnus 2.0.1-next.7 → 2.0.1-next.73
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 +518 -98
- package/cli/lib/agents.sh +32 -16
- package/cli/lib/asks.sh +762 -0
- package/cli/lib/banner.sh +181 -0
- package/cli/lib/brief.sh +375 -0
- package/cli/lib/chain.sh +363 -0
- package/cli/lib/close.sh +5 -3
- package/cli/lib/cost.sh +500 -0
- package/cli/lib/finish.sh +30 -4
- package/cli/lib/github.sh +106 -26
- package/cli/lib/guard.sh +39 -10
- package/cli/lib/handoff.sh +196 -31
- package/cli/lib/host.sh +340 -384
- package/cli/lib/linear.sh +552 -56
- package/cli/lib/links.sh +6 -3
- package/cli/lib/merges.sh +126 -27
- package/cli/lib/sessions.sh +132 -0
- package/cli/lib/settings.sh +31 -15
- package/cli/lib/task.sh +169 -54
- package/cli/lib/tests.sh +302 -7
- package/cli/lib/usage.sh +204 -0
- package/cli/ocnus +274 -76
- package/herdr/README.md +930 -232
- package/herdr/layouts/default.json +30 -11
- package/herdr/layouts/showcase.json +291 -0
- package/herdr/layouts/vibe.json +162 -0
- package/herdr/layouts/vibe.svg +41 -0
- package/herdr/mods/agent-settings/main.js +19 -7
- package/herdr/mods/memory/main.js +128 -0
- package/herdr/mods/memory/mod.json +1 -0
- package/herdr/mods/memory/reading.js +88 -0
- package/herdr/mods/names/main.js +22 -4
- package/herdr/mods/step-counts/main.js +281 -0
- package/herdr/mods/step-counts/mod.json +1 -0
- package/herdr/mods/usage/main.js +149 -0
- package/herdr/mods/usage/mod.json +1 -0
- package/package.json +1 -1
- package/prompts/task-new.md +1 -1
- package/skills/brief/SKILL.md +8 -0
- package/skills/sdlc-breakdown/SKILL.md +66 -18
- package/skills/sdlc-build/SKILL.md +6 -2
- package/skills/sdlc-pr/SKILL.md +2 -2
- package/skills/sdlc-review/SKILL.md +5 -5
|
@@ -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/herdr/mods/names/main.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Gives the spaces and tabs the Herdr app took in from herdr-core the names
|
|
2
|
-
// ocnus gave them.
|
|
3
|
-
//
|
|
2
|
+
// ocnus gave them. A layout places it only so that it runs: on `default`,
|
|
3
|
+
// in a block 1px wide, where it draws nothing. Where its block's props have
|
|
4
|
+
// `note`, as on the `showcase` layout, a blank block would say nothing, so
|
|
5
|
+
// it draws a note saying what it does. `herdr-app check` draws the note too.
|
|
4
6
|
//
|
|
5
7
|
// An agent that `ocnus task new` or `task start` started while the app
|
|
6
8
|
// was closed runs in a herdr-core terminal with Herdr's own labels,
|
|
@@ -16,7 +18,11 @@
|
|
|
16
18
|
// space or tab given Herdr's own name again keeps it. It holds no rules of
|
|
17
19
|
// ocnus's: the names are the labels ocnus put on the terminals.
|
|
18
20
|
import { View, div } from "gpui-kit";
|
|
19
|
-
import {
|
|
21
|
+
import { v_flex } from "gpui-base";
|
|
22
|
+
import { checking, props, run, spaces, terminals, theme } from "herdr";
|
|
23
|
+
|
|
24
|
+
// What the note says the mod does.
|
|
25
|
+
const NOTE = "Draws nothing. It gives the spaces and tabs the app takes in from herdr-core the names ocnus gave them.";
|
|
20
26
|
|
|
21
27
|
// A label's value, when it is a name: a string that is not empty.
|
|
22
28
|
function label(labels, key) {
|
|
@@ -64,6 +70,18 @@ export default class Names extends View {
|
|
|
64
70
|
run(command, { id, name });
|
|
65
71
|
}
|
|
66
72
|
}
|
|
67
|
-
|
|
73
|
+
// Nothing to see, unless the layout asks for the note.
|
|
74
|
+
return checking() || props()?.note ? this.note() : div();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// The note: the mod's name, then what it does, wrapping, in a block like
|
|
78
|
+
// the Usage section's, and with its line height, so that three lines fit
|
|
79
|
+
// the 64px the showcase gives its row.
|
|
80
|
+
note() {
|
|
81
|
+
const t = theme();
|
|
82
|
+
return v_flex().size_full().px(14).py(6).gap(2).justify_center().line_height(1.25).overflow_hidden()
|
|
83
|
+
.bg(t.chrome).border_t(1).border_color(t.border).text_size(11)
|
|
84
|
+
.child(div().flex_none().text_color(t.muted).child("names"))
|
|
85
|
+
.child(div().whitespace_normal().text_color(t.dim).child(NOTE));
|
|
68
86
|
}
|
|
69
87
|
}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// The Step counts section: how many cards are at each step, in the ocnus
|
|
2
|
+
// space that is showing, and how each card's agent is doing. It sits above
|
|
3
|
+
// Usage in the default layout's sidebar, and is about as small.
|
|
4
|
+
//
|
|
5
|
+
// All of that is worked out by `ocnus task log <space> --json`, whose
|
|
6
|
+
// `counts` are the steps in order, each with how many cards are on it, a mark
|
|
7
|
+
// for each of those cards and the text to show at its right. This mod draws
|
|
8
|
+
// those counts and holds no rules about hand-offs, steps or agents: where a
|
|
9
|
+
// card stands, what its mark is and what a step's text says all arrive from
|
|
10
|
+
// the command. What is its own is the drawing: a dot of its colour for each
|
|
11
|
+
// mark, as many dots as fit in the row, and "+N" for the rest.
|
|
12
|
+
import { View, div } from "gpui-kit";
|
|
13
|
+
import { v_flex, h_flex } from "gpui-base";
|
|
14
|
+
import { exec, spaces, panes, terminals, theme, layout, window, checking, appHome, settings } from "herdr";
|
|
15
|
+
|
|
16
|
+
// How often to see whether another space is showing, or Herdr's tabs have
|
|
17
|
+
// changed. A change in them is read at once, so an agent's state shows within
|
|
18
|
+
// this and a read.
|
|
19
|
+
const LOOK_MS = 2000;
|
|
20
|
+
const REREAD_MS = 6000; // how often to read the counts again
|
|
21
|
+
const SPACES_MS = 60000; // spaces change rarely
|
|
22
|
+
const TIMEOUT_MS = 10000;
|
|
23
|
+
// How this mod's own link into the repo that ships it ends.
|
|
24
|
+
const LINKED_AT = "/herdr/mods/step-counts";
|
|
25
|
+
|
|
26
|
+
const LEFT = 4; // the steps in the left column; the rest are in the right one
|
|
27
|
+
const COLUMN_GAP = 12;
|
|
28
|
+
const NAME_CH = 6.6; // px a letter of a step's name takes, to line a column's dots up
|
|
29
|
+
const DOT = 6; // px across a mark's dot
|
|
30
|
+
const DOT_GAP = 3;
|
|
31
|
+
const MORE_CH = 7; // px kept for each character of "+N"
|
|
32
|
+
const ROOM = 36; // px a row's dots are taken to have, until the row is measured
|
|
33
|
+
|
|
34
|
+
// The colour of each mark's dot: red for a card whose agent is stuck or has
|
|
35
|
+
// stopped, amber for one that needs the human, green for one that is ready to
|
|
36
|
+
// merge, and blue for one whose agent is working.
|
|
37
|
+
const colors = (t) => ({ stuck: t.ansi1, "needs-human": t.ansi3, ready: t.ansi2, working: t.ansi4 });
|
|
38
|
+
|
|
39
|
+
// `herdr-app check` draws the mod once, with nothing read, which would show
|
|
40
|
+
// one line of text and none of the rows. It is given these to draw, so a
|
|
41
|
+
// mistake in a row fails the check: every mark, a row with more dots than
|
|
42
|
+
// fit, a row with none, and a count of cards that are held. It draws a line
|
|
43
|
+
// under them too, as one stands in place of the rows.
|
|
44
|
+
const SAMPLE = {
|
|
45
|
+
space: "demo",
|
|
46
|
+
counts: [
|
|
47
|
+
{ step: "define", count: 1, marks: ["working"], text: "1" },
|
|
48
|
+
{ step: "plan", count: 0, marks: [], text: "0" },
|
|
49
|
+
{ step: "breakdown", count: 1, marks: ["needs-human"], text: "1" },
|
|
50
|
+
{ step: "start", count: 2, marks: [], text: "2 held" },
|
|
51
|
+
{ step: "build", count: 12, text: "12",
|
|
52
|
+
marks: ["stuck", "needs-human", "needs-human", "working", "working", "working", "working", "working",
|
|
53
|
+
"working", "working", "working", "working"] },
|
|
54
|
+
{ step: "review", count: 2, marks: ["needs-human", "working"], text: "2" },
|
|
55
|
+
{ step: "pr", count: 3, marks: ["stuck", "needs-human", "ready"], text: "3" },
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
function find(node, id) {
|
|
60
|
+
if (node?.id === id) return node;
|
|
61
|
+
for (const child of node?.children ?? []) {
|
|
62
|
+
const found = find(child, id);
|
|
63
|
+
if (found) return found;
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// The sidebar's rail goes by its width, as in Herdr's own lists.
|
|
69
|
+
const narrow = () => (find(layout(), "sidebar")?.size?.px ?? Infinity) < 160;
|
|
70
|
+
|
|
71
|
+
function parse(text) {
|
|
72
|
+
try {
|
|
73
|
+
return JSON.parse(text);
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// What Herdr shows of the tabs in the spaces whose folder is `folder`, on
|
|
80
|
+
// this computer: each tab's id and name, and each of its terminals' status
|
|
81
|
+
// and app. `task log` works out each card's mark from these, so a change in
|
|
82
|
+
// them is read at once. A pane's status has no word for hc's error, so each
|
|
83
|
+
// terminal's own word, from terminals(), is in it too.
|
|
84
|
+
function herdrSees(folder) {
|
|
85
|
+
if (folder === null) return "";
|
|
86
|
+
const word = new Map(terminals().map((t) => [t.address, t.status ?? null]));
|
|
87
|
+
const tabs = new Set();
|
|
88
|
+
const seen = [];
|
|
89
|
+
for (const space of spaces()) {
|
|
90
|
+
if (space.machine || space.folder !== folder) continue;
|
|
91
|
+
for (const tab of space.tabs) {
|
|
92
|
+
tabs.add(tab.id);
|
|
93
|
+
seen.push([tab.id, tab.name]);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (const p of panes()) {
|
|
97
|
+
if (p.terminal && tabs.has(p.tab)) seen.push([p.tab, p.terminal, p.status, p.app, word.get(p.terminal) ?? null]);
|
|
98
|
+
}
|
|
99
|
+
return JSON.stringify(seen);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// What a failed command said, without the name it starts its errors with.
|
|
103
|
+
const said = (r) => (r.stderr || r.stdout).trim().replace(/^ocnus: /, "");
|
|
104
|
+
|
|
105
|
+
const OLD_CLI = "This ocnus is too old for the step counts. Run: ocnus update";
|
|
106
|
+
const NOT_OCNUS = "This space is not an ocnus space.";
|
|
107
|
+
// An ocnus from before --json answers with its usage line, not JSON, and
|
|
108
|
+
// one from before the list of cards asks which card.
|
|
109
|
+
const failure = (r, what) => {
|
|
110
|
+
const text = said(r);
|
|
111
|
+
return text.startsWith("usage:") || text.startsWith("which card?") ? OLD_CLI : text || `${what} failed`;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// The folder of the space that is showing on this computer, or null.
|
|
115
|
+
const selected = () => spaces().find((s) => s.active && !s.machine)?.folder ?? null;
|
|
116
|
+
|
|
117
|
+
// How many dots to draw for a row of `marks` marks in `room` px: all of
|
|
118
|
+
// them when they fit, and else as many as fit beside the "+N" that stands
|
|
119
|
+
// for the rest.
|
|
120
|
+
function fit(marks, room) {
|
|
121
|
+
const wide = (n) => n * DOT + Math.max(0, n - 1) * DOT_GAP;
|
|
122
|
+
if (wide(marks) <= room) return marks;
|
|
123
|
+
for (let n = marks - 1; n > 0; n--) {
|
|
124
|
+
const more = (String(marks - n).length + 1) * MORE_CH;
|
|
125
|
+
if (wide(n) + DOT_GAP + more <= room) return n;
|
|
126
|
+
}
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export default class StepCounts extends View {
|
|
131
|
+
init(_props, cx) {
|
|
132
|
+
this.cmd = "ocnus"; // the one on PATH, until that cannot start
|
|
133
|
+
this.listed = null; // the spaces ocnus listed last
|
|
134
|
+
this.listedAt = 0;
|
|
135
|
+
this.key = null; // the folder that the counts on hand were read for
|
|
136
|
+
this.space = null; // the ocnus space the shown Herdr space is, or null
|
|
137
|
+
this.counts = null; // the counts read last
|
|
138
|
+
this.error = null;
|
|
139
|
+
this.busy = false;
|
|
140
|
+
this.readAt = 0;
|
|
141
|
+
this.seen = null; // what Herdr showed of the space's tabs when it was read
|
|
142
|
+
this.drawn = null; // what the last redraw showed, to redraw only on a change
|
|
143
|
+
this.room = {}; // the px each row has for its dots, as measured, by the row's place
|
|
144
|
+
if (checking()) return;
|
|
145
|
+
cx.timer.every(LOOK_MS, (cx) => this.look(cx));
|
|
146
|
+
this.look(cx);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Runs the ocnus command. One that cannot run is tried again as the
|
|
150
|
+
// copy this mod is linked from: Herdr may have been started without the
|
|
151
|
+
// user's PATH. Everything this mod runs only reads, so twice is safe.
|
|
152
|
+
async ocnus(args) {
|
|
153
|
+
try {
|
|
154
|
+
return await exec(this.cmd, args, { timeout: TIMEOUT_MS });
|
|
155
|
+
} catch (e) {
|
|
156
|
+
if (this.cmd !== "ocnus") throw e;
|
|
157
|
+
const link = await exec("readlink", [`${appHome()}/mods/step-counts`]);
|
|
158
|
+
const at = link.stdout.trim();
|
|
159
|
+
if (link.code !== 0 || !at.endsWith(LINKED_AT)) throw e;
|
|
160
|
+
this.cmd = `${at.slice(0, -LINKED_AT.length)}/cli/ocnus`;
|
|
161
|
+
return exec(this.cmd, args, { timeout: TIMEOUT_MS });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Read the counts again when another space is showing, when Herdr's tabs
|
|
166
|
+
// in the space have changed, or when what is on hand is stale: so does a
|
|
167
|
+
// read that failed, which is tried again. A space that is not an ocnus
|
|
168
|
+
// space is looked up again only as often as the spaces are listed. Nothing
|
|
169
|
+
// is read while nobody can see the section.
|
|
170
|
+
look(cx) {
|
|
171
|
+
if (this.busy || window()?.visible === false || narrow()) return;
|
|
172
|
+
const folder = selected();
|
|
173
|
+
const key = folder ?? "";
|
|
174
|
+
const seen = herdrSees(folder);
|
|
175
|
+
const stale = this.space || this.error
|
|
176
|
+
? Date.now() - this.readAt >= REREAD_MS || seen !== this.seen
|
|
177
|
+
: Date.now() - this.readAt >= SPACES_MS;
|
|
178
|
+
if (key === this.key && !stale) return;
|
|
179
|
+
this.busy = true;
|
|
180
|
+
cx.spawn(async (cx) => {
|
|
181
|
+
let space = null;
|
|
182
|
+
let counts = null;
|
|
183
|
+
let error = null;
|
|
184
|
+
try {
|
|
185
|
+
if (!this.listed || Date.now() - this.listedAt >= SPACES_MS) {
|
|
186
|
+
const r = await this.ocnus(["space", "ls", "--json"]);
|
|
187
|
+
const list = r.code === 0 ? parse(r.stdout)?.spaces : null;
|
|
188
|
+
if (Array.isArray(list)) {
|
|
189
|
+
this.listed = list;
|
|
190
|
+
this.listedAt = Date.now();
|
|
191
|
+
} else {
|
|
192
|
+
error = r.code === 0 ? OLD_CLI : failure(r, "ocnus space ls");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
space = (this.listed ?? []).find((s) => s.folder === folder)?.name ?? null;
|
|
196
|
+
if (!error && space) {
|
|
197
|
+
const r = await this.ocnus(["task", "log", space, "--json"]);
|
|
198
|
+
const got = r.code === 0 ? parse(r.stdout) : null;
|
|
199
|
+
// An ocnus from before the counts gives the list without them.
|
|
200
|
+
if (Array.isArray(got?.counts)) counts = got.counts;
|
|
201
|
+
else error = r.code === 0 ? OLD_CLI : failure(r, "ocnus task log");
|
|
202
|
+
}
|
|
203
|
+
} catch (e) {
|
|
204
|
+
error = `Could not run ocnus: ${e?.message ?? e}`;
|
|
205
|
+
}
|
|
206
|
+
this.key = key;
|
|
207
|
+
this.space = space;
|
|
208
|
+
this.counts = counts;
|
|
209
|
+
this.error = error;
|
|
210
|
+
this.readAt = Date.now();
|
|
211
|
+
this.seen = seen;
|
|
212
|
+
this.busy = false;
|
|
213
|
+
// A redraw of a mod redraws the whole window, so only when what it
|
|
214
|
+
// shows has changed.
|
|
215
|
+
const drawn = JSON.stringify([key, space, counts, error]);
|
|
216
|
+
if (drawn !== this.drawn) {
|
|
217
|
+
this.drawn = drawn;
|
|
218
|
+
cx.notify();
|
|
219
|
+
}
|
|
220
|
+
// A space chosen while this was being read is read now, not at the
|
|
221
|
+
// next look.
|
|
222
|
+
if ((selected() ?? "") !== key) this.look(cx);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// One step, on one line: its name, a dot for each of its cards, as many as
|
|
227
|
+
// fit, with "+N" for the rest, and its text at the right. `i` is its place
|
|
228
|
+
// among the steps, and `name` the px its column gives a name.
|
|
229
|
+
row(c, i, t, name) {
|
|
230
|
+
const marks = Array.isArray(c.marks) ? c.marks : [];
|
|
231
|
+
const color = colors(t);
|
|
232
|
+
const shown = fit(marks.length, this.room[i] ?? ROOM);
|
|
233
|
+
const rest = marks.length - shown;
|
|
234
|
+
return h_flex().flex_none().gap(6).items_center()
|
|
235
|
+
.child(div().flex_none().min_w(name).text_color(t.muted).child(String(c.step ?? "")))
|
|
236
|
+
.child(h_flex().id(`dots-${i}`).flex_1().min_w(0).gap(DOT_GAP).items_center().overflow_hidden()
|
|
237
|
+
// The room the dots have, measured. The size is in window px.
|
|
238
|
+
.on_size_change((size, cx) => {
|
|
239
|
+
const room = size.width / (Number(settings().zoom) || 1);
|
|
240
|
+
const was = this.room[i] ?? ROOM;
|
|
241
|
+
this.room[i] = room;
|
|
242
|
+
if (fit(marks.length, room) !== fit(marks.length, was)) cx.notify();
|
|
243
|
+
})
|
|
244
|
+
.children(marks.slice(0, shown).map((m) =>
|
|
245
|
+
div().flex_none().size(DOT).rounded(DOT / 2).bg(color[m] ?? t.dim)))
|
|
246
|
+
.when(rest > 0, (el) => el.child(div().flex_none().text_color(t.dim).child(`+${rest}`))))
|
|
247
|
+
.child(div().flex_none().text_color(c.count > 0 ? t.foreground : t.dim).child(String(c.text ?? "")));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
render() {
|
|
251
|
+
const t = theme();
|
|
252
|
+
// The block and the line above it, as Usage and CPU have theirs.
|
|
253
|
+
const block = () => v_flex().size_full().bg(t.chrome).border_t(1).border_color(t.border);
|
|
254
|
+
// The sidebar's rail has room for the line alone.
|
|
255
|
+
if (narrow()) return block();
|
|
256
|
+
const sample = checking();
|
|
257
|
+
const counts = (sample ? SAMPLE.counts : this.counts) ?? [];
|
|
258
|
+
// A column of rows, with the room for a name that its longest one needs.
|
|
259
|
+
const column = (from, to) => {
|
|
260
|
+
const rows = counts.slice(from, to);
|
|
261
|
+
const name = Math.ceil(Math.max(0, ...rows.map((c) => String(c.step ?? "").length)) * NAME_CH);
|
|
262
|
+
return v_flex().flex_1().min_w(0).overflow_hidden()
|
|
263
|
+
.children(rows.map((c, i) => this.row(c, from + i, t, name)));
|
|
264
|
+
};
|
|
265
|
+
const rows = () => h_flex().flex_none().gap(COLUMN_GAP).items_start()
|
|
266
|
+
.child(column(0, LEFT))
|
|
267
|
+
.child(column(LEFT, counts.length));
|
|
268
|
+
// The one line that stands in place of the rows.
|
|
269
|
+
const line = (text, color) => div().flex_none().text_color(color).whitespace_normal().child(text);
|
|
270
|
+
let body;
|
|
271
|
+
if (sample) body = [rows(), line(NOT_OCNUS, t.dim)];
|
|
272
|
+
else if ((selected() ?? "") !== this.key) body = [line("Reading…", t.dim)];
|
|
273
|
+
else if (this.error) body = [line(this.error, t.blocked)];
|
|
274
|
+
else if (!this.space) body = [line(NOT_OCNUS, t.dim)];
|
|
275
|
+
else body = [rows()];
|
|
276
|
+
// A line height of its own, so that the four rows of the left column fit
|
|
277
|
+
// the 72px the layout gives the section, whatever the default is.
|
|
278
|
+
return block().px(14).py(6).justify_center().line_height(1.25).overflow_hidden().text_size(11)
|
|
279
|
+
.children(body);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "place": "none", "title": "Step counts" }
|