@johngaynor/ocnus 2.0.1-next.71 → 2.0.1-next.76
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 +31 -10
- package/cli/lib/agents.sh +25 -12
- package/cli/lib/asks.sh +13 -0
- package/cli/lib/handoff.sh +86 -17
- package/cli/lib/host.sh +175 -60
- package/cli/ocnus +19 -13
- package/herdr/README.md +193 -15
- package/herdr/layouts/showcase.json +12 -0
- package/herdr/layouts/vibe.json +4 -2
- package/herdr/mods/card-list/main.js +658 -0
- package/herdr/mods/card-list/mod.json +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,658 @@
|
|
|
1
|
+
// The card list: the cards of the ocnus space that is showing in Herdr, in
|
|
2
|
+
// the middle column of the vibe layout, in two views. Agents lists the cards
|
|
3
|
+
// that are running, the ones that need the human first. Linear lists every
|
|
4
|
+
// open card of the space's teams under its parent card.
|
|
5
|
+
//
|
|
6
|
+
// Which ocnus space a Herdr space is, which cards are open and how each one
|
|
7
|
+
// stands are the ocnus command's to say. `ocnus space ls --json` names the
|
|
8
|
+
// space, and `ocnus task ls <space> --json` lists its open cards, each with
|
|
9
|
+
// its title, its status in Linear, its parent, its place among the parent's
|
|
10
|
+
// sub-issues and whether it is held. `ocnus task log <space> --json` gives
|
|
11
|
+
// each card with hand-offs the step it stands on, whether it is running, its
|
|
12
|
+
// word, the word's mark, its need, how long it has been so and what its
|
|
13
|
+
// agents have used in all, and the steps in order, with its counts. This mod
|
|
14
|
+
// joins the two by card ID and draws them. It holds no rules about steps,
|
|
15
|
+
// agents or hand-offs: which cards are running, each one's word and colour
|
|
16
|
+
// and the order of need all arrive from the command.
|
|
17
|
+
//
|
|
18
|
+
// A click on a running card's row sets Herdr's shared value `ocnus.open` to
|
|
19
|
+
// that card, which the opened agent shows on the right of the layout, and the
|
|
20
|
+
// row is drawn selected while that value names it. A card not approved yet
|
|
21
|
+
// has Start, which runs `ocnus task new <space> <card>` as the Cards panel's
|
|
22
|
+
// Start does.
|
|
23
|
+
import { View, div, svg } from "gpui-kit";
|
|
24
|
+
import { v_flex, h_flex } from "gpui-base";
|
|
25
|
+
import { exec, spaces, panes, terminals, notify, theme, window, checking, appHome, shared, setShared } from "herdr";
|
|
26
|
+
|
|
27
|
+
// How often to see whether another space is showing, or Herdr's tabs in it
|
|
28
|
+
// have changed. A change in them is read at once, so an agent's change of
|
|
29
|
+
// state shows within this and a read.
|
|
30
|
+
const LOOK_MS = 2000;
|
|
31
|
+
const LOG_MS = 6000; // how often to read the log again, for a card's move to another step
|
|
32
|
+
const CARDS_MS = 60000; // how often to read the cards again, for a change in Linear
|
|
33
|
+
const TIMEOUT_MS = 10000;
|
|
34
|
+
const LIST_TIMEOUT_MS = 30000; // task ls waits up to 20s on Linear
|
|
35
|
+
const START_TIMEOUT_MS = 60000;
|
|
36
|
+
// How this mod's own link into the repo that ships it ends.
|
|
37
|
+
const LINKED_AT = "/herdr/mods/card-list";
|
|
38
|
+
// The shared value that names the card whose agent is open on the right of
|
|
39
|
+
// the layout: { space, card }.
|
|
40
|
+
const OPEN = "ocnus.open";
|
|
41
|
+
const SPINNER = "mods/workspace-chrome/spinner.svg";
|
|
42
|
+
const NOT_A_SPACE = "The shown space is not an ocnus space.";
|
|
43
|
+
const OLD_CLI = "This ocnus is too old for the card list. Run: ocnus update";
|
|
44
|
+
const READING = "Reading…";
|
|
45
|
+
const NONE_RUNNING = "No card is running.";
|
|
46
|
+
const NONE_OPEN = "No open card.";
|
|
47
|
+
// The statuses of a card not approved yet, by their type in Linear: those
|
|
48
|
+
// before its team's first not-started status.
|
|
49
|
+
const NOT_STARTED = new Set(["triage", "backlog"]);
|
|
50
|
+
// Where a held card stands: approved, with its work not started, as
|
|
51
|
+
// `task start` holds it.
|
|
52
|
+
const HELD_AT = "start";
|
|
53
|
+
const VIEWS = { agents: "running now · needs you first", linear: "every open card · by parent" };
|
|
54
|
+
|
|
55
|
+
// The colour of each mark, as the Step counts section colours its dots: red
|
|
56
|
+
// for a card that is stuck, amber for one that needs the human, green for
|
|
57
|
+
// one that is ready to merge and blue for one whose agent is working.
|
|
58
|
+
const colors = (t) => ({ stuck: t.ansi1, "needs-human": t.ansi3, ready: t.ansi2, working: t.ansi4 });
|
|
59
|
+
|
|
60
|
+
// `herdr-app check` draws the mod once, with nothing read, which would show
|
|
61
|
+
// one line and none of the rows. It is given these to draw instead: both
|
|
62
|
+
// views, one under the other, then each line that stands in place of the
|
|
63
|
+
// rows, so that a mistake in any of them fails the check. The log gives
|
|
64
|
+
// every word and mark, its cards out of the order of need, a running card
|
|
65
|
+
// that the cards do not list, a row with tokens and rows without. The cards
|
|
66
|
+
// give a card being started, a held card, an approved card in grey, a
|
|
67
|
+
// running parent, a parent with no agent that is not in the list, and cards
|
|
68
|
+
// with no parent.
|
|
69
|
+
const SAMPLE_STEPS = ["define", "plan", "breakdown", "start", "build", "review", "pr"];
|
|
70
|
+
const SAMPLE_LOG = {
|
|
71
|
+
steps: SAMPLE_STEPS,
|
|
72
|
+
cards: [
|
|
73
|
+
{ card: "ABC-12", stand: "build", running: true, word: "Working", mark: "working", need: 3, for: "14m 02s",
|
|
74
|
+
agent: null, tokens: { total: 1800000, short: "1.8M" } },
|
|
75
|
+
{ card: "ABC-17", stand: "build", running: true, word: "Stuck", mark: "stuck", need: 0, for: "1h 02m",
|
|
76
|
+
agent: { state: "stopped", label: "agent stopped without handing off", for: "12m 30s" }, tokens: { total: 900000, short: "900k" } },
|
|
77
|
+
{ card: "ABC-9", stand: "pr", running: true, word: "Merge?", mark: "ready", need: 2, for: "1h 10m",
|
|
78
|
+
agent: null, tokens: { total: 1200000, short: "1.2M" } },
|
|
79
|
+
{ card: "ABC-15", stand: "review", running: true, word: "Permission", mark: "needs-human", need: 1, for: "20m 00s",
|
|
80
|
+
agent: { state: "blocked", kind: "permission", label: "agent waiting on a permission prompt", for: "1m 10s" }, tokens: null },
|
|
81
|
+
{ card: "ABC-22", stand: "breakdown", running: true, word: "Approve?", mark: "needs-human", need: 1, for: "3m 05s",
|
|
82
|
+
agent: null, tokens: { total: 640000, short: "640k" } },
|
|
83
|
+
{ card: "ABC-14", stand: "plan", running: true, word: "Asking", mark: "needs-human", need: 1, for: "6m 40s",
|
|
84
|
+
agent: null, tokens: { total: 520000, short: "520k" } },
|
|
85
|
+
{ card: "ABC-30", stand: "define", running: true, word: "Working", mark: "working", need: 3, for: "2m 00s",
|
|
86
|
+
agent: null, tokens: { total: 0, short: "0" } },
|
|
87
|
+
{ card: "ABC-5", stand: "pr", running: true, word: "Working", mark: "working", need: 3, for: "40s", agent: null, tokens: null },
|
|
88
|
+
{ card: "ABC-19", stand: "pr", running: false, word: "Merge?", mark: "needs-human", need: 2, for: "2h 00m", agent: null, tokens: null },
|
|
89
|
+
{ card: "ABC-11", stand: "start", running: false, word: null, mark: null, need: null, for: "1d 02h", agent: null, tokens: null },
|
|
90
|
+
{ card: "ABC-13", stand: "start", running: false, word: null, mark: null, need: null, for: "3d 04h", agent: null, tokens: null },
|
|
91
|
+
],
|
|
92
|
+
};
|
|
93
|
+
const SAMPLE_PARENT = { id: "ABC-30", title: "Vibe layout in Herdr", subIssues: 4, done: 0 };
|
|
94
|
+
const SAMPLE_OTHER = { id: "ABC-8", title: "Sidebar polish", subIssues: 3, done: 1 };
|
|
95
|
+
const sampleCard = (id, title, more = {}) => ({ id, title, url: "", parent: null, place: null, held: false, waitsOn: [], ...more });
|
|
96
|
+
const SAMPLE_CARDS = {
|
|
97
|
+
space: "sample",
|
|
98
|
+
statuses: [
|
|
99
|
+
{ name: "Backlog", type: "backlog", cards: [
|
|
100
|
+
sampleCard("ABC-20", "Board keyboard nav"),
|
|
101
|
+
sampleCard("ABC-21", "Toast when an agent blocks", { parent: SAMPLE_PARENT, place: 4 }),
|
|
102
|
+
sampleCard("ABC-22", "Held cards show their blockers", { parent: SAMPLE_PARENT, place: 3 }),
|
|
103
|
+
] },
|
|
104
|
+
{ name: "Todo", type: "unstarted", cards: [
|
|
105
|
+
sampleCard("ABC-11", "Space marks on the rail", { held: true, waitsOn: [{ id: "ABC-9", title: "Space colors", status: { name: "In Review", type: "started" } }] }),
|
|
106
|
+
sampleCard("ABC-13", "Idle section remembers fold"),
|
|
107
|
+
] },
|
|
108
|
+
{ name: "In Progress", type: "started", cards: [
|
|
109
|
+
sampleCard("ABC-30", "Vibe layout in Herdr"),
|
|
110
|
+
sampleCard("ABC-15", "Brainstorm pane per space", { parent: SAMPLE_PARENT, place: 1 }),
|
|
111
|
+
sampleCard("ABC-16", "Agent board mod", { parent: SAMPLE_PARENT, place: 2 }),
|
|
112
|
+
sampleCard("ABC-12", "Steps timeline for each card", { parent: SAMPLE_OTHER, place: 2 }),
|
|
113
|
+
sampleCard("ABC-17", "Retry failed Linear sync"),
|
|
114
|
+
sampleCard("ABC-14", "Coach price snapshot importer"),
|
|
115
|
+
] },
|
|
116
|
+
{ name: "In Review", type: "started", cards: [
|
|
117
|
+
sampleCard("ABC-9", "Space colors in the sidebar", { parent: SAMPLE_OTHER, place: 1 }),
|
|
118
|
+
sampleCard("ABC-19", "Pin an agent", { parent: SAMPLE_OTHER, place: 3 }),
|
|
119
|
+
] },
|
|
120
|
+
],
|
|
121
|
+
};
|
|
122
|
+
const SAMPLE_STARTING = "ABC-21";
|
|
123
|
+
const SAMPLE_OPEN = { space: "sample", card: "ABC-14" };
|
|
124
|
+
const SAMPLE_LINES = [
|
|
125
|
+
{ line: READING }, { line: NOT_A_SPACE }, { line: OLD_CLI, error: true }, { line: NONE_RUNNING }, { line: NONE_OPEN },
|
|
126
|
+
{ line: "no Linear key saved. Run: ocnus linear key", error: true },
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
function parse(text) {
|
|
130
|
+
try {
|
|
131
|
+
return JSON.parse(text);
|
|
132
|
+
} catch {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// What a failed command said, without the name it starts its errors with.
|
|
138
|
+
const said = (r) => (r.stderr || r.stdout).trim().replace(/^ocnus: /, "");
|
|
139
|
+
// An ocnus from before --json answers with its usage line, not JSON, and
|
|
140
|
+
// one from before the list of cards asks which card.
|
|
141
|
+
const failure = (r, what) => {
|
|
142
|
+
const text = said(r);
|
|
143
|
+
return text.startsWith("usage:") || text.startsWith("which card?") ? OLD_CLI : text || `${what} failed`;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// The shown space's folder, when that space is on this computer: the only
|
|
147
|
+
// place an ocnus space can be.
|
|
148
|
+
function shownFolder() {
|
|
149
|
+
const space = spaces().find((s) => s.active);
|
|
150
|
+
return space && !space.machine ? space.folder : null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// What Herdr shows of the tabs in the spaces whose folder is `folder`, on
|
|
154
|
+
// this computer: each tab's id and name, and each of its terminals' status
|
|
155
|
+
// and app. `task log` works out from these which cards are running and how
|
|
156
|
+
// each one's agent is doing, so a change in them is read at once. A pane's
|
|
157
|
+
// status has no word for hc's error, so each terminal's own word, from
|
|
158
|
+
// terminals(), is in it too.
|
|
159
|
+
function herdrSees(folder) {
|
|
160
|
+
if (folder === null) return "";
|
|
161
|
+
const word = new Map(terminals().map((t) => [t.address, t.status ?? null]));
|
|
162
|
+
const tabs = new Set();
|
|
163
|
+
const seen = [];
|
|
164
|
+
for (const space of spaces()) {
|
|
165
|
+
if (space.machine || space.folder !== folder) continue;
|
|
166
|
+
for (const tab of space.tabs) {
|
|
167
|
+
tabs.add(tab.id);
|
|
168
|
+
seen.push([tab.id, tab.name]);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
for (const p of panes()) {
|
|
172
|
+
if (p.terminal && tabs.has(p.tab)) seen.push([p.tab, p.terminal, p.status, p.app, word.get(p.terminal) ?? null]);
|
|
173
|
+
}
|
|
174
|
+
return JSON.stringify(seen);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// A card ID's team key and number.
|
|
178
|
+
function idParts(id) {
|
|
179
|
+
const text = String(id ?? "").toUpperCase();
|
|
180
|
+
const m = text.match(/^(.*)-([0-9]+)$/);
|
|
181
|
+
return m ? [m[1], Number(m[2])] : [text, 0];
|
|
182
|
+
}
|
|
183
|
+
// Card IDs in order: by team key, then by number, read as a number, so that
|
|
184
|
+
// ABC-9 comes before ABC-17.
|
|
185
|
+
function idOrder(a, b) {
|
|
186
|
+
const [ka, na] = idParts(a);
|
|
187
|
+
const [kb, nb] = idParts(b);
|
|
188
|
+
return ka < kb ? -1 : ka > kb ? 1 : na - nb;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// What its agents have used, as "640k tok", from the figures `task log`
|
|
192
|
+
// gives the card: nothing for a card with none, never 0.
|
|
193
|
+
function tokens(c) {
|
|
194
|
+
const t = c?.tokens;
|
|
195
|
+
return t && Number(t.total) > 0 && t.short ? `${t.short} tok` : null;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Which sub-issue of which parent card a card is, as "2/4 of ABC-30" and the
|
|
199
|
+
// parent's title, or that it has none.
|
|
200
|
+
function parentLine(k) {
|
|
201
|
+
const p = k.parent;
|
|
202
|
+
if (!p?.id) return "no parent card";
|
|
203
|
+
return `${k.place ?? "?"}/${p.subIssues ?? "?"} of ${p.id} ${p.title ?? ""}`.trim();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// The row of a running card: its ID and title, with the line about its
|
|
207
|
+
// parent when `withParent`, and its steps, word, time and tokens, as the
|
|
208
|
+
// log gives them. `k` is the card as `task ls` lists it, or null.
|
|
209
|
+
function runningRow(c, k, steps, withParent) {
|
|
210
|
+
return {
|
|
211
|
+
id: c.card, title: k?.title ?? "", parent: withParent && k ? parentLine(k) : null,
|
|
212
|
+
steps, at: steps.indexOf(c.stand), box: c.mark ?? null, tip: c.stand ?? "",
|
|
213
|
+
word: c.word ?? "", tone: c.mark ?? null,
|
|
214
|
+
time: c.agent?.for ?? c.for ?? "", tok: tokens(c), opens: true,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// The row of a card in Linear, under its parent's row: `k` as `task ls`
|
|
219
|
+
// lists it, with its status, `c` as the log gives it, or null for a card
|
|
220
|
+
// with no hand-offs, and `place` its place among its parent's sub-issues,
|
|
221
|
+
// undefined for a card with no parent.
|
|
222
|
+
// The first that fits: a running card's row; Not started, with Start, for a
|
|
223
|
+
// card not approved yet; Held, with what it waits on; else its steps and its
|
|
224
|
+
// word, or its status in Linear in grey when it has none.
|
|
225
|
+
function linearRow(k, c, steps, place) {
|
|
226
|
+
if (c?.running === true) return { ...runningRow(c, k, steps, false), place };
|
|
227
|
+
const row = { id: k.id, title: k.title ?? "", parent: null, place, steps, time: null, tok: null, opens: false };
|
|
228
|
+
if (NOT_STARTED.has(k.status?.type)) {
|
|
229
|
+
return { ...row, at: -1, box: null, tip: "", word: "Not started", tone: null, start: true };
|
|
230
|
+
}
|
|
231
|
+
if (k.held === true) {
|
|
232
|
+
const waits = (Array.isArray(k.waitsOn) ? k.waitsOn : []).map((w) => w?.id).filter(Boolean);
|
|
233
|
+
return { ...row, at: steps.indexOf(HELD_AT), box: null, tip: HELD_AT, word: "Held", tone: null,
|
|
234
|
+
waits: waits.length ? `waits on ${waits.join(", ")}` : null };
|
|
235
|
+
}
|
|
236
|
+
return { ...row, at: c ? steps.indexOf(c.stand) : -1, box: c?.word ? c.mark ?? null : null, tip: c?.stand ?? "",
|
|
237
|
+
word: c?.word ?? k.status?.name ?? "", tone: c?.word ? c.mark ?? null : null };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// The cards that are running, as the log says, in the order of need, and
|
|
241
|
+
// then by ID, so that a row moves only when its word changes. A card that
|
|
242
|
+
// `task ls` does not list, as every card when it failed, has no title and no
|
|
243
|
+
// line about its parent.
|
|
244
|
+
function agentRows(log, listed) {
|
|
245
|
+
return log.cards.filter((c) => c?.running === true && typeof c.card === "string")
|
|
246
|
+
.sort((a, b) => (a.need ?? 9) - (b.need ?? 9) || idOrder(a.card, b.card))
|
|
247
|
+
.map((c) => runningRow(c, listed.get(c.card.toUpperCase()) ?? null, log.steps, true));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// The cards `task ls` listed, each under its parent's row: the parents by ID,
|
|
251
|
+
// the highest number first, each card by its place, then the cards with no
|
|
252
|
+
// parent under a line of their own. A parent's row is its ID, its title, its
|
|
253
|
+
// word when it is running or "no agent", and how many of its sub-issues have
|
|
254
|
+
// merged. A card that is a parent heads its own group alone.
|
|
255
|
+
function linearRows(cards, log) {
|
|
256
|
+
const logged = new Map(log.cards.filter((c) => typeof c?.card === "string").map((c) => [c.card.toUpperCase(), c]));
|
|
257
|
+
const heads = new Set(cards.filter((k) => k.parent?.id).map((k) => String(k.parent.id).toUpperCase()));
|
|
258
|
+
const groups = new Map();
|
|
259
|
+
const loose = [];
|
|
260
|
+
for (const k of cards) {
|
|
261
|
+
if (heads.has(k.id.toUpperCase())) continue;
|
|
262
|
+
if (!k.parent?.id) {
|
|
263
|
+
loose.push(k);
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
const id = String(k.parent.id).toUpperCase();
|
|
267
|
+
if (!groups.has(id)) groups.set(id, { parent: k.parent, kids: [] });
|
|
268
|
+
groups.get(id).kids.push(k);
|
|
269
|
+
}
|
|
270
|
+
const rows = [];
|
|
271
|
+
for (const [id, g] of [...groups].sort((a, b) => idOrder(b[0], a[0]))) {
|
|
272
|
+
const c = logged.get(id) ?? null;
|
|
273
|
+
const running = c?.running === true;
|
|
274
|
+
rows.push({ head: true, id: g.parent.id, title: g.parent.title ?? "", word: running ? c.word ?? "" : "no agent",
|
|
275
|
+
tone: running ? c.mark ?? null : null, merged: `${g.parent.done ?? 0}/${g.parent.subIssues ?? 0} merged`, opens: running });
|
|
276
|
+
g.kids.sort((a, b) => (a.place ?? Infinity) - (b.place ?? Infinity) || idOrder(a.id, b.id));
|
|
277
|
+
for (const k of g.kids) {
|
|
278
|
+
const place = `${k.place ?? "?"}/${g.parent.subIssues ?? "?"}`;
|
|
279
|
+
rows.push(linearRow(k, logged.get(k.id.toUpperCase()) ?? null, log.steps, place));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (loose.length) {
|
|
283
|
+
rows.push({ loose: true });
|
|
284
|
+
for (const k of loose.sort((a, b) => idOrder(b.id, a.id))) {
|
|
285
|
+
rows.push(linearRow(k, logged.get(k.id.toUpperCase()) ?? null, log.steps, undefined));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return rows;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// What each view shows of the space in `folder`, from what was read for it:
|
|
292
|
+
// `found`, the space, or why it is not known; `got`, its cards as `task ls`
|
|
293
|
+
// lists them, or what it said; and `log`, what `task log` gives, or what it
|
|
294
|
+
// said. Each view is { rows } or { line }, the one line that stands in their
|
|
295
|
+
// place, and counts are how many cards each side of the toggle has: the
|
|
296
|
+
// running cards and the open ones, or null when they are not known.
|
|
297
|
+
function shape(folder, found, got, log) {
|
|
298
|
+
const line = (text, error = false) => ({ line: text, error });
|
|
299
|
+
const counts = { agents: null, linear: null };
|
|
300
|
+
if (folder === null || (found && !found.space && !found.error)) {
|
|
301
|
+
return { space: null, counts, agents: line(NOT_A_SPACE), linear: line(NOT_A_SPACE) };
|
|
302
|
+
}
|
|
303
|
+
if (!found) return { space: null, counts, agents: line(READING), linear: line(READING) };
|
|
304
|
+
if (found.error) return { space: null, counts, agents: line(found.error, true), linear: line(found.error, true) };
|
|
305
|
+
const cards = [];
|
|
306
|
+
for (const s of got?.statuses ?? []) {
|
|
307
|
+
for (const k of s?.cards ?? []) {
|
|
308
|
+
if (typeof k?.id === "string") cards.push({ ...k, status: { name: s.name, type: s.type } });
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const listed = new Map(cards.map((k) => [k.id.toUpperCase(), k]));
|
|
312
|
+
if (got?.statuses) counts.linear = cards.length;
|
|
313
|
+
let agents;
|
|
314
|
+
if (!log) agents = line(READING);
|
|
315
|
+
else if (log.error) agents = line(log.error, true);
|
|
316
|
+
else {
|
|
317
|
+
const rows = agentRows(log, listed);
|
|
318
|
+
counts.agents = rows.length;
|
|
319
|
+
agents = rows.length ? { rows } : line(NONE_RUNNING);
|
|
320
|
+
}
|
|
321
|
+
let linear;
|
|
322
|
+
if (!got) linear = line(READING);
|
|
323
|
+
else if (got.error) linear = line(got.error, true);
|
|
324
|
+
else if (!log) linear = line(READING);
|
|
325
|
+
else if (log.error) linear = line(log.error, true);
|
|
326
|
+
else {
|
|
327
|
+
const rows = linearRows(cards, log);
|
|
328
|
+
linear = rows.length ? { rows } : line(NONE_OPEN);
|
|
329
|
+
}
|
|
330
|
+
return { space: found.space, counts, agents, linear };
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export default class CardList extends View {
|
|
334
|
+
init(_props, cx) {
|
|
335
|
+
this.cmd = "ocnus"; // the one on PATH, until that cannot start
|
|
336
|
+
this.view = "agents"; // the view that shows, until the human picks the other
|
|
337
|
+
// The folder of the shown space that the space below was looked up for,
|
|
338
|
+
// and what was found: { space } with its name or null, or { error }.
|
|
339
|
+
this.folder = undefined;
|
|
340
|
+
this.found = null;
|
|
341
|
+
// Its cards, as `task ls` lists them: { statuses } or { error }.
|
|
342
|
+
this.got = null;
|
|
343
|
+
this.cardsAt = 0;
|
|
344
|
+
this.cardsBusy = false;
|
|
345
|
+
// What `task log` gives: { cards, steps } or { error }, for the folder
|
|
346
|
+
// logFor, and what Herdr showed of the space's tabs then.
|
|
347
|
+
this.log = null;
|
|
348
|
+
this.logFor = undefined;
|
|
349
|
+
this.logAt = 0;
|
|
350
|
+
this.logBusy = false;
|
|
351
|
+
this.logAgain = false; // read again as soon as the read under way is done
|
|
352
|
+
this.seen = null;
|
|
353
|
+
this.starting = null; // the card whose `task new` is running
|
|
354
|
+
this.drawn = null; // what the last redraw showed, to redraw only on a change
|
|
355
|
+
if (checking()) return;
|
|
356
|
+
cx.timer.every(LOOK_MS, (cx) => this.look(cx));
|
|
357
|
+
this.look(cx);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Runs the ocnus command. With `fallback`, a command that cannot run is
|
|
361
|
+
// tried again as the copy this mod is linked from (Herdr may have been
|
|
362
|
+
// started without the user's PATH). Only the readings ask for that: they
|
|
363
|
+
// only read, and the cards have been listed before there is a card to
|
|
364
|
+
// start. A start never does, because its failure may be a timeout with the
|
|
365
|
+
// first run still opening the tab.
|
|
366
|
+
async ocnus(args, { fallback = false, timeout = TIMEOUT_MS } = {}) {
|
|
367
|
+
try {
|
|
368
|
+
return await exec(this.cmd, args, { timeout });
|
|
369
|
+
} catch (e) {
|
|
370
|
+
if (!fallback || this.cmd !== "ocnus") throw e;
|
|
371
|
+
const link = await exec("readlink", [`${appHome()}/mods/card-list`]);
|
|
372
|
+
const at = link.stdout.trim();
|
|
373
|
+
if (link.code !== 0 || !at.endsWith(LINKED_AT)) throw e;
|
|
374
|
+
this.cmd = `${at.slice(0, -LINKED_AT.length)}/cli/ocnus`;
|
|
375
|
+
return exec(this.cmd, args, { timeout });
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// Read the cards again when another space is showing, or when they are a
|
|
380
|
+
// minute old, and the log as `lookLog` says. When ocnus could not list
|
|
381
|
+
// the spaces, they are tried again as often as the log is read. Nothing is
|
|
382
|
+
// read while nobody can see the window.
|
|
383
|
+
look(cx) {
|
|
384
|
+
if (window()?.visible === false) return;
|
|
385
|
+
const every = this.found?.error ? LOG_MS : CARDS_MS;
|
|
386
|
+
if (shownFolder() !== this.folder || Date.now() - this.cardsAt >= every) this.readCards(cx);
|
|
387
|
+
this.lookLog(cx);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Look up the ocnus space of the shown folder, then read its log at once,
|
|
391
|
+
// and its cards, which wait on Linear.
|
|
392
|
+
readCards(cx) {
|
|
393
|
+
if (this.cardsBusy) return;
|
|
394
|
+
this.cardsBusy = true;
|
|
395
|
+
const folder = shownFolder();
|
|
396
|
+
cx.spawn(async (cx) => {
|
|
397
|
+
const found = await this.find(folder);
|
|
398
|
+
if (folder !== this.folder) this.got = null;
|
|
399
|
+
this.folder = folder;
|
|
400
|
+
this.found = found;
|
|
401
|
+
this.logAgain = true;
|
|
402
|
+
this.lookLog(cx);
|
|
403
|
+
this.redraw(cx);
|
|
404
|
+
const got = found.space ? await this.readList(found.space) : null;
|
|
405
|
+
if (folder === this.folder) this.got = got;
|
|
406
|
+
this.cardsAt = Date.now();
|
|
407
|
+
this.cardsBusy = false;
|
|
408
|
+
this.redraw(cx);
|
|
409
|
+
// A space chosen while this was being read is read now, not at the
|
|
410
|
+
// next look.
|
|
411
|
+
if (shownFolder() !== this.folder) this.readCards(cx);
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Read the log again when Herdr's tabs in the shown space have changed,
|
|
416
|
+
// when it is 6 seconds old, and after the space is looked up. There is
|
|
417
|
+
// nothing to read until the shown folder's space is known.
|
|
418
|
+
lookLog(cx) {
|
|
419
|
+
if (this.logBusy) return;
|
|
420
|
+
const folder = shownFolder();
|
|
421
|
+
const space = folder === this.folder ? this.found?.space : null;
|
|
422
|
+
if (!space) return;
|
|
423
|
+
const seen = herdrSees(folder);
|
|
424
|
+
if (!this.logAgain && folder === this.logFor && seen === this.seen && Date.now() - this.logAt < LOG_MS) return;
|
|
425
|
+
this.logBusy = true;
|
|
426
|
+
this.logAgain = false;
|
|
427
|
+
cx.spawn(async (cx) => {
|
|
428
|
+
const log = await this.readLog(space);
|
|
429
|
+
this.log = log;
|
|
430
|
+
this.logFor = folder;
|
|
431
|
+
this.seen = seen;
|
|
432
|
+
this.logAt = Date.now();
|
|
433
|
+
this.logBusy = false;
|
|
434
|
+
this.redraw(cx);
|
|
435
|
+
if (this.logAgain) this.lookLog(cx);
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// A redraw of a mod redraws the whole window, so only when what the list
|
|
440
|
+
// shows has changed.
|
|
441
|
+
redraw(cx) {
|
|
442
|
+
const drawn = JSON.stringify(this.shown());
|
|
443
|
+
if (drawn === this.drawn) return;
|
|
444
|
+
this.drawn = drawn;
|
|
445
|
+
cx.notify();
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// What both views show of the space that is showing, from what was read
|
|
449
|
+
// for it.
|
|
450
|
+
shown() {
|
|
451
|
+
const folder = shownFolder();
|
|
452
|
+
const mine = folder === this.folder;
|
|
453
|
+
return shape(folder, mine ? this.found : null, mine ? this.got : null, folder === this.logFor ? this.log : null);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// The ocnus space whose folder is `folder`: { space } with its name, or
|
|
457
|
+
// null when it is none, or { error } when ocnus cannot list the spaces.
|
|
458
|
+
async find(folder) {
|
|
459
|
+
if (folder === null) return { space: null };
|
|
460
|
+
try {
|
|
461
|
+
const r = await this.ocnus(["space", "ls", "--json"], { fallback: true });
|
|
462
|
+
const listed = r.code === 0 ? parse(r.stdout)?.spaces : null;
|
|
463
|
+
if (!Array.isArray(listed)) return { error: r.code === 0 ? OLD_CLI : failure(r, "ocnus space ls") };
|
|
464
|
+
return { space: listed.find((s) => s.folder === folder)?.name ?? null };
|
|
465
|
+
} catch (e) {
|
|
466
|
+
return { error: `Could not run ocnus: ${e?.message ?? e}` };
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// The space's open cards, under their statuses, or what `task ls` said.
|
|
471
|
+
async readList(space) {
|
|
472
|
+
try {
|
|
473
|
+
const r = await this.ocnus(["task", "ls", space, "--json"], { fallback: true, timeout: LIST_TIMEOUT_MS });
|
|
474
|
+
const list = r.code === 0 ? parse(r.stdout) : null;
|
|
475
|
+
if (Array.isArray(list?.statuses)) return { statuses: list.statuses };
|
|
476
|
+
return { error: r.code === 0 ? OLD_CLI : failure(r, "ocnus task ls") };
|
|
477
|
+
} catch (e) {
|
|
478
|
+
return { error: `Could not run ocnus: ${e?.message ?? e}` };
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// The space's cards that have hand-offs, as `task log` gives them, with
|
|
483
|
+
// the steps in order, or what it said. An ocnus from before the card list
|
|
484
|
+
// gives the cards without running.
|
|
485
|
+
async readLog(space) {
|
|
486
|
+
try {
|
|
487
|
+
const r = await this.ocnus(["task", "log", space, "--json"], { fallback: true });
|
|
488
|
+
const got = r.code === 0 ? parse(r.stdout) : null;
|
|
489
|
+
if (!Array.isArray(got?.cards) || !Array.isArray(got?.counts)) return { error: r.code === 0 ? OLD_CLI : failure(r, "ocnus task log") };
|
|
490
|
+
if (got.cards.some((c) => typeof c?.running !== "boolean")) return { error: OLD_CLI };
|
|
491
|
+
return { cards: got.cards, steps: got.counts.map((c) => c?.step).filter((s) => typeof s === "string") };
|
|
492
|
+
} catch (e) {
|
|
493
|
+
return { error: `Could not run ocnus: ${e?.message ?? e}` };
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// Runs `task new` for a card, one at a time, as the Cards panel's Start
|
|
498
|
+
// does. Once it is done, the log is read again: the card's tab is open,
|
|
499
|
+
// and its row a running one.
|
|
500
|
+
start(space, id, cx) {
|
|
501
|
+
if (this.starting) return;
|
|
502
|
+
this.starting = id;
|
|
503
|
+
cx.notify();
|
|
504
|
+
cx.spawn(async (cx) => {
|
|
505
|
+
let failed = null;
|
|
506
|
+
try {
|
|
507
|
+
const r = await this.ocnus(["task", "new", space, id], { timeout: START_TIMEOUT_MS });
|
|
508
|
+
if (r.code !== 0) failed = said(r) || "ocnus task new failed";
|
|
509
|
+
} catch (e) {
|
|
510
|
+
failed = `Could not run ocnus: ${e?.message ?? e}`;
|
|
511
|
+
}
|
|
512
|
+
if (failed !== null) notify({ title: `Could not start ${id}`, body: failed, level: "error" });
|
|
513
|
+
this.starting = null;
|
|
514
|
+
cx.notify();
|
|
515
|
+
this.logAgain = true;
|
|
516
|
+
this.lookLog(cx);
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// Show the view `name`, agents or linear.
|
|
521
|
+
pick(name, cx) {
|
|
522
|
+
if (this.view === name) return;
|
|
523
|
+
this.view = name;
|
|
524
|
+
cx.notify();
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// The toggle, each side with how many cards it has, and what the view that
|
|
528
|
+
// shows lists.
|
|
529
|
+
header(view, counts, t) {
|
|
530
|
+
const side = (name, label, n) => h_flex().id(`card-list-${name}`).flex_none().h(26).px(12).gap(6).items_center()
|
|
531
|
+
.rounded(7).text_size(12.5).font_semibold()
|
|
532
|
+
.when(view === name, (el) => el.bg(t.selected).text_color(t.foreground))
|
|
533
|
+
.when(view !== name, (el) => el.text_color(t.muted).cursor_pointer().hover((s) => s.bg(t.hover))
|
|
534
|
+
.on_click((_e, cx) => this.pick(name, cx)))
|
|
535
|
+
.child(label)
|
|
536
|
+
.when(n !== null, (el) => el.child(div().font_normal().text_color(t.dim).child(String(n))));
|
|
537
|
+
return h_flex().h(48).flex_none().px(16).gap(10).items_center()
|
|
538
|
+
.child(h_flex().flex_none().p(2).gap(2).rounded(9).border_1().border_color(t.border).bg(t.chrome)
|
|
539
|
+
.child(side("agents", "Agents", counts.agents))
|
|
540
|
+
.child(side("linear", "Linear", counts.linear)))
|
|
541
|
+
.child(div().flex_1().min_w(0).truncate().text_size(12).text_color(t.dim).child(VIEWS[view]));
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// The seven boxes of a card's steps: those before the step it stands on as
|
|
545
|
+
// done, that step's in the colour of the card's mark, or in grey with
|
|
546
|
+
// none, and the rest empty, with the step's name in the tooltip. A card
|
|
547
|
+
// that stands on no step has empty boxes and no tooltip.
|
|
548
|
+
bar(key, r, t) {
|
|
549
|
+
const now = colors(t)[r.box] ?? t.muted;
|
|
550
|
+
return h_flex().id(`${key}-steps`).flex_none().gap(3).items_center()
|
|
551
|
+
.when(Boolean(r.tip), (el) => el.tooltip(r.tip))
|
|
552
|
+
.children(r.steps.map((_s, i) => div().flex_none().w(10).h(4).rounded(2)
|
|
553
|
+
.bg(i < r.at ? t.dim : i === r.at ? now : t.border)));
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// Start, for a card not approved yet. One card starts at a time: it reads
|
|
557
|
+
// Starting… while its `task new` runs, and the others wait.
|
|
558
|
+
startButton(space, id, starting, t) {
|
|
559
|
+
const mine = starting === id;
|
|
560
|
+
const waiting = Boolean(starting) && !mine;
|
|
561
|
+
return h_flex().id(`card-list-start-${id}`).h(24).flex_none().px(10).gap(5).items_center().rounded(7)
|
|
562
|
+
.border_1().border_color(t.input).bg(t.raised).text_size(11.5).text_color(t.foreground)
|
|
563
|
+
.when(mine, (el) => el.text_color(t.muted)
|
|
564
|
+
.child(svg(SPINNER).size(10).flex_none().text_color(t.working).spin(900)))
|
|
565
|
+
.when(waiting, (el) => el.opacity(0.45))
|
|
566
|
+
.when(!mine && !waiting, (el) => el.cursor_pointer().tooltip(`Start ${id}: open its tab with the agent running`)
|
|
567
|
+
.hover((s) => s.bg(t.hover)).on_click((_e, cx) => this.start(space, id, cx)))
|
|
568
|
+
.child(mine ? "Starting…" : "Start");
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// A card's row: its place under its parent in Linear, its ID, its title
|
|
572
|
+
// and, in Agents, the line about its parent, its steps, its word, and at
|
|
573
|
+
// the end its time and tokens, Start, or what it waits on, which `wide`
|
|
574
|
+
// makes room for in Linear. Only a running card's row has a click, which
|
|
575
|
+
// opens its agent, and it is drawn selected while its agent is the one
|
|
576
|
+
// open.
|
|
577
|
+
row(r, key, space, open, starting, wide, t) {
|
|
578
|
+
const word = colors(t)[r.tone] ?? t.dim;
|
|
579
|
+
const end = v_flex().w(wide ? 96 : 60).flex_none().items_end().justify_center().text_size(11.5).text_color(t.dim);
|
|
580
|
+
return h_flex().id(key).flex_none().min_h(36).px(10).py(4).gap(10).items_center().rounded(8)
|
|
581
|
+
.when(r.opens && open, (el) => el.bg(t.selected))
|
|
582
|
+
.when(r.opens && !open, (el) => el.cursor_pointer().hover((s) => s.bg(t.hover)))
|
|
583
|
+
.when(r.opens, (el) => el.on_click(() => setShared(OPEN, { space, card: r.id })))
|
|
584
|
+
.when(r.place !== undefined, (el) => el.child(div().w(30).flex_none().text_size(11).text_color(t.muted).child(r.place)))
|
|
585
|
+
.child(div().w(58).flex_none().truncate().text_size(11.5).text_color(t.dim).child(r.id))
|
|
586
|
+
.child(v_flex().flex_1().min_w(0)
|
|
587
|
+
.child(div().truncate().text_color(r.opens ? t.foreground : t.muted).child(r.title))
|
|
588
|
+
.when(r.parent !== null, (el) => el.child(div().truncate().text_size(11).text_color(t.dim).child(r.parent))))
|
|
589
|
+
.child(this.bar(key, r, t))
|
|
590
|
+
.child(div().w(84).flex_none().truncate().text_size(12).text_color(word)
|
|
591
|
+
.when(Boolean(r.tone), (el) => el.font_semibold()).child(r.word))
|
|
592
|
+
.child(r.start
|
|
593
|
+
? end.child(this.startButton(space, r.id, starting, t))
|
|
594
|
+
: end
|
|
595
|
+
.when(Boolean(r.waits), (el) => el.child(div().w_full().text_right().truncate().text_size(11).child(r.waits)))
|
|
596
|
+
.when(Boolean(r.time), (el) => el.child(div().child(r.time)))
|
|
597
|
+
.when(Boolean(r.tok), (el) => el.child(div().text_size(10.5).child(r.tok))));
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// A parent card's row: its ID, its title, its word when it is running or
|
|
601
|
+
// "no agent", and how many of its sub-issues have merged. It has no steps
|
|
602
|
+
// and no Start. When it is running, a click opens its agent.
|
|
603
|
+
head(r, key, space, open, t) {
|
|
604
|
+
const word = colors(t)[r.tone] ?? t.dim;
|
|
605
|
+
return h_flex().id(key).flex_none().min_h(32).mt(6).px(10).gap(10).items_center().rounded(8)
|
|
606
|
+
.when(r.opens && open, (el) => el.bg(t.selected))
|
|
607
|
+
.when(r.opens && !open, (el) => el.cursor_pointer().hover((s) => s.bg(t.hover)))
|
|
608
|
+
.when(r.opens, (el) => el.on_click(() => setShared(OPEN, { space, card: r.id })))
|
|
609
|
+
.child(div().w(58).flex_none().truncate().text_size(11.5).text_color(t.dim).child(r.id))
|
|
610
|
+
.child(div().flex_1().min_w(0).truncate().font_semibold().text_color(t.foreground).child(r.title))
|
|
611
|
+
.child(h_flex().flex_none().gap(6).items_center().text_size(11.5)
|
|
612
|
+
.child(div().text_color(word).when(Boolean(r.tone), (el) => el.font_semibold()).child(r.word))
|
|
613
|
+
.child(div().text_color(t.dim).child(`· ${r.merged}`)));
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
// A view's rows. `view` makes each row's id its own, `opened` is the card
|
|
617
|
+
// whose agent is open, and `starting` the card being started.
|
|
618
|
+
items(rows, view, space, opened, starting, t) {
|
|
619
|
+
const open = (id) => opened?.space === space && opened?.card === id;
|
|
620
|
+
return rows.map((r) => {
|
|
621
|
+
if (r.loose) return div().flex_none().px(10).pt(14).pb(4).text_size(11.5).text_color(t.dim).child("No parent card");
|
|
622
|
+
if (r.head) return this.head(r, `${view}-head-${r.id}`, space, open(r.id), t);
|
|
623
|
+
return this.row(r, `${view}-${r.id}`, space, open(r.id), starting, view === "linear", t);
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// The one line that stands in place of a view's rows.
|
|
628
|
+
line(v, t) {
|
|
629
|
+
return div().flex_none().px(10).py(6).text_size(12.5).text_color(v.error ? t.blocked : t.dim).whitespace_normal()
|
|
630
|
+
.child(v.line);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
render() {
|
|
634
|
+
const t = theme();
|
|
635
|
+
const box = () => v_flex().size_full().min_h(0).bg(t.background).text_size(13).text_color(t.foreground);
|
|
636
|
+
const rows = (items) => v_flex().id("card-list-rows").flex_1().min_h(0).px(10).pb(10).overflow_y_scrollbar()
|
|
637
|
+
.children(items);
|
|
638
|
+
if (checking()) {
|
|
639
|
+
const s = shape("sample", { space: "sample" }, SAMPLE_CARDS, SAMPLE_LOG);
|
|
640
|
+
return box()
|
|
641
|
+
.child(this.header("agents", s.counts, t))
|
|
642
|
+
.child(this.header("linear", s.counts, t))
|
|
643
|
+
.child(rows([
|
|
644
|
+
...this.items(s.agents.rows, "agents", "sample", SAMPLE_OPEN, SAMPLE_STARTING, t),
|
|
645
|
+
...this.items(s.linear.rows, "linear", "sample", SAMPLE_OPEN, SAMPLE_STARTING, t),
|
|
646
|
+
...SAMPLE_LINES.map((v) => this.line(v, t)),
|
|
647
|
+
]));
|
|
648
|
+
}
|
|
649
|
+
const s = this.shown();
|
|
650
|
+
const v = s[this.view];
|
|
651
|
+
const opened = shared(OPEN);
|
|
652
|
+
return box()
|
|
653
|
+
.child(this.header(this.view, s.counts, t))
|
|
654
|
+
.child(rows(v.rows
|
|
655
|
+
? this.items(v.rows, this.view, s.space, opened && typeof opened === "object" ? opened : null, this.starting, t)
|
|
656
|
+
: [this.line(v, t)]));
|
|
657
|
+
}
|
|
658
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "place": "none", "title": "Card list" }
|