@johngaynor/entourage 0.4.1-next.26 → 0.4.1-next.30

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/herdr/README.md CHANGED
@@ -10,9 +10,10 @@ 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/layout-switch/` | A dropdown that shows the current layout and switches to another. |
12
12
  | `mods/projects/` | Every project in your config, open or not. Click one to show its space; `+` makes a new one. |
13
+ | `mods/cards/` | The open Linear cards of the project whose space is showing, under their statuses. Start writes a card up with `task new`; Open shows the tab of a card already started. |
13
14
  | `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 project's cards and where each stands. |
14
15
  | `layouts/default.json` | Herdr's own layout, plus the layout dropdown. |
15
- | `layouts/test.json` | `default` with the projects list in place of spaces, plus the Steps panel and the CPU mod in the sidebar. |
16
+ | `layouts/test.json` | `default` with the projects list in place of spaces, plus the Cards and Steps panels and the CPU mod in the sidebar. |
16
17
  | `projects/template/` | The starting `PROJECT.md` for every new project. |
17
18
 
18
19
  The skills are in [../skills/](../skills/), outside this folder. They are
@@ -211,6 +212,36 @@ entourage task new <project> <card>
211
212
  `~/.claude/skills` stops it before anything is opened. Run
212
213
  `entourage update` to link the skills.
213
214
 
215
+ ### The Cards panel
216
+
217
+ On the `test` layout, the Cards panel under the projects list shows the open
218
+ cards of the project whose space is showing, each with a button that writes
219
+ the card up.
220
+
221
+ - **It shows what `task ls` lists**: the same statuses in the same order, each
222
+ with its count, and the cards under them. A click on a status closes its
223
+ group, and another opens it again. Which groups are closed is kept between
224
+ starts of Herdr.
225
+ - **Start runs `entourage task new <project> <card>`**, so the card's tab
226
+ opens in the project's space with the agent running. One card starts at a
227
+ time. The button reads Starting… until the command is done, and if the
228
+ command fails, a notification shows what it said.
229
+ - **A card whose tab is open reads Open**, and a click shows that tab rather
230
+ than starting the card a second time. A tab is the card's when it is named
231
+ after the card's ID, as `task new` names it.
232
+ - **When the cards cannot be listed, the panel shows why**, in the words of
233
+ `task ls`: no Linear key saved, a project with no team, Linear out of reach.
234
+ A space that is not a project says so.
235
+ - **It reads the cards again** when another space is shown, about once a
236
+ minute while the window is visible, and when the refresh button above the
237
+ list is clicked.
238
+ - **It works nothing out itself.** The project comes from
239
+ `entourage project ls --json` and the cards from
240
+ `entourage task ls <project> --json`, so the panel and the commands always
241
+ agree. It needs what `task ls` needs: the Linear key and the project's teams.
242
+ - **On the sidebar's narrow rail**, each card shows as its number, and a click
243
+ does what its button would.
244
+
214
245
  ### Hand-offs
215
246
 
216
247
  Each step of a write-up ends by handing off: which step it was, how it ended
@@ -46,6 +46,17 @@
46
46
  },
47
47
  "min": 90
48
48
  },
49
+ {
50
+ "id": "cards",
51
+ "type": "block",
52
+ "content": {
53
+ "mod": "cards"
54
+ },
55
+ "size": {
56
+ "weight": 1
57
+ },
58
+ "min": 90
59
+ },
49
60
  {
50
61
  "id": "agents",
51
62
  "type": "block",
@@ -0,0 +1,330 @@
1
+ // The open Linear cards of the project whose space is showing, under their
2
+ // statuses, with a button on each card that starts it.
3
+ //
4
+ // Which project a space is, and which cards are open, are the entourage
5
+ // command's to say: `entourage project ls --json` and
6
+ // `entourage task ls <project> --json`. This mod draws what they answer and
7
+ // holds no rules about projects or Linear. A card's button runs
8
+ // `entourage task new <project> <card>`, which opens the card's tab in the
9
+ // project's space with the agent running in it.
10
+ //
11
+ // A click on a status opens or closes its group.
12
+ import { View, div, svg } from "gpui-kit";
13
+ import { v_flex, h_flex } from "gpui-base";
14
+ import { exec, spaces, run, notify, theme, layout, window, checking, appHome } from "herdr";
15
+
16
+ const LOOK_MS = 1000; // how often to see whether another space is showing
17
+ const REFRESH_MS = 60000; // how often to read the cards again
18
+ const TIMEOUT_MS = 10000;
19
+ const LIST_TIMEOUT_MS = 30000; // task ls waits up to 20s on Linear
20
+ const START_TIMEOUT_MS = 60000;
21
+ const ROW = 30;
22
+ const RAIL_CELL = 32;
23
+ // How this mod's own link into the repo that ships it ends.
24
+ const LINKED_AT = "/herdr/mods/cards";
25
+ const NOT_A_PROJECT = "The shown space is not an entourage project.";
26
+ const OLD_CLI = "This entourage cannot list a project's cards. Run: entourage update";
27
+ const CHEVRON = "mods/workspace-chrome/chevron";
28
+ const SPINNER = "mods/workspace-chrome/spinner.svg";
29
+
30
+ // `herdr-app check` draws the mod once, with no space showing, which would
31
+ // draw one line of text and none of the rows. It is given these to draw
32
+ // instead: an open group, a closed one, an empty one, a card being started
33
+ // and a card whose tab is open.
34
+ const SAMPLE = {
35
+ project: "sample",
36
+ statuses: [
37
+ { name: "Backlog", type: "backlog", cards: [
38
+ { id: "ABC-1", title: "A card", url: "" },
39
+ { id: "ABC-2", title: "A card being started", url: "" },
40
+ ] },
41
+ { name: "Todo", type: "unstarted", cards: [{ id: "ABC-3", title: "A card in a closed group", url: "" }] },
42
+ { name: "In Progress", type: "started", cards: [{ id: "ABC-4", title: "A card with its tab open", url: "" }] },
43
+ { name: "In Review", type: "started", cards: [] },
44
+ ],
45
+ };
46
+ const SAMPLE_STARTING = "ABC-2";
47
+ const SAMPLE_CLOSED = new Set(["sample/Todo"]);
48
+ const SAMPLE_TABS = new Map([["ABC-4", { space: { id: "s", active: true }, tab: { id: "t", active: true } }]]);
49
+
50
+ function find(node, id) {
51
+ if (node?.id === id) return node;
52
+ for (const child of node?.children ?? []) {
53
+ const found = find(child, id);
54
+ if (found) return found;
55
+ }
56
+ return null;
57
+ }
58
+
59
+ // The sidebar's rail goes by its width, as in Herdr's own lists.
60
+ const narrow = () => (find(layout(), "sidebar")?.size?.px ?? Infinity) < 160;
61
+
62
+ function parse(text) {
63
+ try {
64
+ return JSON.parse(text);
65
+ } catch {
66
+ return null;
67
+ }
68
+ }
69
+
70
+ // What a failed command said, without the name it starts its errors with.
71
+ const said = (r) => (r.stderr || r.stdout).trim().replace(/^entourage: /, "");
72
+ // An entourage from before `task ls` answers with its usage line, not JSON.
73
+ const failure = (r, what) => {
74
+ const text = said(r);
75
+ return text.startsWith("usage:") ? OLD_CLI : text || `${what} failed`;
76
+ };
77
+
78
+ // The shown space's folder, when that space is on this computer: the only
79
+ // place an entourage project can be.
80
+ function shownFolder() {
81
+ const space = spaces().find((s) => s.active);
82
+ return space && !space.machine ? space.folder : null;
83
+ }
84
+
85
+ // The tabs `task new` has opened in the project's spaces, by card: it names
86
+ // each one after its card.
87
+ function cardTabs(folder) {
88
+ const tabs = new Map();
89
+ for (const space of spaces()) {
90
+ if (space.machine || space.folder !== folder) continue;
91
+ for (const tab of space.tabs) {
92
+ const id = tab.name.toUpperCase();
93
+ // The shown space's tab wins over another space of the same folder.
94
+ if (!tabs.has(id) || space.active) tabs.set(id, { space, tab });
95
+ }
96
+ }
97
+ return tabs;
98
+ }
99
+
100
+ // Which groups are closed: "<project>/<status>", kept between starts.
101
+ function loadClosed() {
102
+ try {
103
+ const list = JSON.parse(localStorage.getItem("closed") ?? "[]");
104
+ return new Set(Array.isArray(list) ? list : []);
105
+ } catch {
106
+ return new Set();
107
+ }
108
+ }
109
+
110
+ export default class Cards extends View {
111
+ init(_props, cx) {
112
+ this.cmd = "entourage"; // the one on PATH, until that cannot start
113
+ this.closed = loadClosed();
114
+ // What the last listing said for each shown folder: { project, folder,
115
+ // statuses } or { error }. A space shown again draws its last answer
116
+ // while it is read again.
117
+ this.lists = new Map();
118
+ this.key = undefined; // the folder the last listing was read for
119
+ this.readAt = 0;
120
+ this.busy = false;
121
+ this.starting = null; // the card whose `task new` is running
122
+ if (checking()) return;
123
+ cx.timer.every(LOOK_MS, (cx) => this.look(cx));
124
+ this.refresh(cx);
125
+ }
126
+
127
+ // Runs the entourage command. With `fallback`, a command that cannot run is
128
+ // tried again as the copy this mod is linked from (Herdr may have been
129
+ // started without the user's PATH). Only the listing asks for that: it
130
+ // only reads, and it has answered before there is a card to start. A start
131
+ // never does, because its failure may be a timeout with the first run still
132
+ // opening the tab.
133
+ async entourage(args, { fallback = false, timeout = TIMEOUT_MS } = {}) {
134
+ try {
135
+ return await exec(this.cmd, args, { timeout });
136
+ } catch (e) {
137
+ if (!fallback || this.cmd !== "entourage") throw e;
138
+ const link = await exec("readlink", [`${appHome()}/mods/cards`]);
139
+ const at = link.stdout.trim();
140
+ if (link.code !== 0 || !at.endsWith(LINKED_AT)) throw e;
141
+ this.cmd = `${at.slice(0, -LINKED_AT.length)}/cli/entourage`;
142
+ return exec(this.cmd, args, { timeout });
143
+ }
144
+ }
145
+
146
+ // Read again when another space is showing, or the cards on hand are a
147
+ // minute old. Nothing is read while nobody can see the window.
148
+ look(cx) {
149
+ if (this.busy || window()?.visible === false) return;
150
+ if (shownFolder() === this.key && Date.now() - this.readAt < REFRESH_MS) return;
151
+ this.refresh(cx);
152
+ }
153
+
154
+ refresh(cx) {
155
+ if (this.busy) return;
156
+ this.busy = true;
157
+ const folder = shownFolder();
158
+ cx.spawn(async (cx) => {
159
+ cx.notify(); // the refresh button turns while the cards are read
160
+ const got = await this.read(folder);
161
+ this.lists.set(folder, got);
162
+ this.key = folder;
163
+ this.readAt = Date.now();
164
+ this.busy = false;
165
+ cx.notify();
166
+ });
167
+ }
168
+
169
+ // The project whose folder is `folder`, and its open cards.
170
+ async read(folder) {
171
+ if (folder === null) return { project: null };
172
+ try {
173
+ const r = await this.entourage(["project", "ls", "--json"], { fallback: true });
174
+ const projects = r.code === 0 ? parse(r.stdout)?.projects : null;
175
+ if (!Array.isArray(projects)) return { error: r.code === 0 ? OLD_CLI : failure(r, "entourage project ls") };
176
+ const project = projects.find((p) => p.folder === folder);
177
+ if (!project) return { project: null };
178
+ const c = await this.entourage(["task", "ls", project.name, "--json"], { timeout: LIST_TIMEOUT_MS });
179
+ const list = c.code === 0 ? parse(c.stdout) : null;
180
+ if (Array.isArray(list?.statuses)) return { project: project.name, folder, statuses: list.statuses };
181
+ return { project: project.name, error: c.code === 0 ? OLD_CLI : failure(c, "entourage task ls") };
182
+ } catch (e) {
183
+ return { error: `Could not run entourage: ${e?.message ?? e}` };
184
+ }
185
+ }
186
+
187
+ // Runs `task new` for a card, one at a time.
188
+ start(project, card, cx) {
189
+ if (this.starting) return;
190
+ this.starting = card.id;
191
+ cx.notify();
192
+ cx.spawn(async (cx) => {
193
+ let failed = null;
194
+ try {
195
+ const r = await this.entourage(["task", "new", project, card.id], { timeout: START_TIMEOUT_MS });
196
+ if (r.code !== 0) failed = said(r) || "entourage task new failed";
197
+ } catch (e) {
198
+ failed = `Could not run entourage: ${e?.message ?? e}`;
199
+ }
200
+ if (failed !== null) notify({ title: `Could not start ${card.id}`, body: failed, level: "error" });
201
+ this.starting = null;
202
+ cx.notify();
203
+ });
204
+ }
205
+
206
+ // Shows the card's tab, in its space.
207
+ show(open) {
208
+ if (!open.space.active) run("space.select", { id: open.space.id });
209
+ run("tab.select", { id: open.tab.id });
210
+ }
211
+
212
+ // What a click on a card does: show its tab, or start it.
213
+ act(project, card, open, cx) {
214
+ if (open) this.show(open);
215
+ else this.start(project, card, cx);
216
+ }
217
+
218
+ toggle(key, cx) {
219
+ if (this.closed.has(key)) this.closed.delete(key);
220
+ else this.closed.add(key);
221
+ localStorage.setItem("closed", JSON.stringify([...this.closed]));
222
+ cx.notify();
223
+ }
224
+
225
+ // A status's header row: its name and how many cards it has.
226
+ header(project, s, i, closed, t) {
227
+ const n = (s.cards ?? []).length;
228
+ return h_flex().id(`status-${i}`).h(26).flex_none().mt(i ? 4 : 0).px(8).gap(7).items_center().rounded(7)
229
+ .text_size(11).text_color(t.dim).cursor_pointer().hover((el) => el.bg(t.hover))
230
+ .on_click((_e, cx) => this.toggle(`${project}/${s.name}`, cx))
231
+ .child(div().flex_1().min_w(0).truncate().child(s.name))
232
+ .child(div().flex_none().child(String(n)))
233
+ .child(svg(`${CHEVRON}-${closed ? "right" : "down"}.svg`).size(11).flex_none());
234
+ }
235
+
236
+ // A card: its ID, its title and its button. `open`: its tab, or null.
237
+ // `starting`: the card being started, if any.
238
+ row(project, card, open, starting, t) {
239
+ const on = Boolean(open?.space.active && open.tab.active);
240
+ const mine = starting === card.id;
241
+ const waiting = Boolean(starting) && !mine && !open; // another card is starting
242
+ const label = open ? "Open" : mine ? "Starting…" : "Start";
243
+ const tip = open ? `Show the tab of ${card.id}` : `Start ${card.id}: open its tab with the agent running`;
244
+ const button = h_flex().id(`card-go-${card.id}`).h(22).flex_none().px(8).gap(5).items_center().rounded(6)
245
+ .border_1().border_color(t.input).bg(t.raised).text_size(11.5).text_color(t.foreground)
246
+ .when(mine, (el) => el.text_color(t.muted)
247
+ .child(svg(SPINNER).size(10).flex_none().text_color(t.working).spin(900)))
248
+ .when(waiting, (el) => el.opacity(0.45))
249
+ .when(!mine && !waiting, (el) => el.cursor_pointer().tooltip(tip).hover((s) => s.bg(t.hover))
250
+ .on_click((_e, cx) => this.act(project, card, open, cx)))
251
+ .child(label);
252
+ return h_flex().id(`card-${card.id}`).h(ROW).flex_none().px(8).gap(8).items_center().rounded(8)
253
+ .when(on, (el) => el.bg(t.selected))
254
+ .when(!on, (el) => el.hover((s) => s.bg(t.hover)))
255
+ .child(div().flex_none().text_size(11.5).text_color(t.dim).child(card.id))
256
+ .child(div().id(`card-title-${card.id}`).flex_1().min_w(0).truncate().tooltip(card.title ?? "")
257
+ .text_color(open ? t.foreground : t.muted).child(card.title ?? ""))
258
+ .child(button);
259
+ }
260
+
261
+ // On the sidebar's rail: the card's number. A click does what its button
262
+ // would.
263
+ compact(project, card, open, starting, t) {
264
+ const on = Boolean(open?.space.active && open.tab.active);
265
+ const mine = starting === card.id;
266
+ const tip = `${card.id}: ${card.title ?? ""}\n${open ? "Click to show its tab" : mine ? "Starting…" : "Click to start it"}`;
267
+ return h_flex().flex_none().justify_center().child(
268
+ h_flex().id(`card-${card.id}`).w(RAIL_CELL).h(26).rounded(6).items_center().justify_center()
269
+ .text_size(11).tooltip(tip)
270
+ .when(on, (el) => el.bg(t.selected))
271
+ .when(!on, (el) => el.hover((s) => s.bg(t.hover)))
272
+ .on_click((_e, cx) => this.act(project, card, open, cx))
273
+ .child(mine
274
+ ? svg(SPINNER).size(11).text_color(t.working).spin(900)
275
+ : div().text_color(open ? t.foreground : t.dim).child(card.id.split("-").pop())));
276
+ }
277
+
278
+ render() {
279
+ const t = theme();
280
+ const collapsed = narrow();
281
+ const sample = checking();
282
+ const folder = sample ? "sample" : shownFolder();
283
+ const got = sample ? SAMPLE : this.lists.get(folder) ?? null;
284
+ const closed = sample ? SAMPLE_CLOSED : this.closed;
285
+ const starting = sample ? SAMPLE_STARTING : this.starting;
286
+ const tabs = sample ? SAMPLE_TABS : got?.statuses ? cardTabs(got.folder) : new Map();
287
+ const note = (text, color) =>
288
+ div().px(8).py(6).text_size(12).text_color(color).whitespace_normal().child(text);
289
+ const items = [];
290
+ if (!got) {
291
+ if (!collapsed) items.push(note(folder === null ? NOT_A_PROJECT : "Loading…", t.dim));
292
+ } else if (got.error) {
293
+ // On the rail there is no room for the words: a mark, with them in its tooltip.
294
+ items.push(collapsed
295
+ ? h_flex().flex_none().justify_center().child(div().id("cards-error").w(RAIL_CELL).h(26)
296
+ .flex().items_center().justify_center().text_color(t.blocked).tooltip(got.error).child("!"))
297
+ : note(got.error, t.blocked));
298
+ } else if (!got.project) {
299
+ if (!collapsed) items.push(note(NOT_A_PROJECT, t.dim));
300
+ } else {
301
+ got.statuses.forEach((s, i) => {
302
+ const shut = closed.has(`${got.project}/${s.name}`);
303
+ if (!collapsed) items.push(this.header(got.project, s, i, shut, t));
304
+ if (shut) return;
305
+ for (const card of s.cards ?? []) {
306
+ const open = tabs.get(card.id.toUpperCase()) ?? null;
307
+ items.push(collapsed
308
+ ? this.compact(got.project, card, open, starting, t)
309
+ : this.row(got.project, card, open, starting, t));
310
+ }
311
+ });
312
+ }
313
+ const spin = !sample && this.busy;
314
+ return v_flex().size_full().min_h(0).bg(t.chrome).text_size(13)
315
+ .child(h_flex().h(31).flex_none().pl(16).pr(10).gap(6).items_center().justify_between()
316
+ .text_size(11.5).text_color(t.dim)
317
+ .when(collapsed, (el) => el.pl(0).pr(0).justify_center())
318
+ .when(!collapsed, (el) => el.child(div().flex_none().child("Cards"))
319
+ .child(div().flex_1().min_w(0).truncate().text_right().child(got?.project ?? "")))
320
+ .child(div().id("cards-refresh").size(26).flex_none().flex().items_center().justify_center()
321
+ .rounded(6).tooltip("Read the cards again")
322
+ .hover((s) => s.bg(t.hover).text_color(t.foreground))
323
+ .on_click((_e, cx) => this.refresh(cx))
324
+ .child(spin
325
+ ? svg("mods/cards/refresh.svg").size(13).spin(900)
326
+ : svg("mods/cards/refresh.svg").size(13))))
327
+ .child(v_flex().id("card-list").flex_1().min_h(0).px(collapsed ? 0 : 8).pb(14)
328
+ .overflow_y_scrollbar().mode("always").children(items));
329
+ }
330
+ }
@@ -0,0 +1 @@
1
+ { "place": "none", "title": "Cards" }
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
2
+ <path d="M20 12a8 8 0 1 1-2.34-5.66"/>
3
+ <path d="M18 2.5v4h-4"/>
4
+ </svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johngaynor/entourage",
3
- "version": "0.4.1-next.26",
3
+ "version": "0.4.1-next.30",
4
4
  "description": "A software factory: agent skills and the Herdr setup to run them, installed with one command.",
5
5
  "bin": {
6
6
  "entourage": "cli/entourage"