@johngaynor/entourage 0.2.0 → 0.3.0

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/cli/entourage CHANGED
@@ -17,7 +17,7 @@ Usage:
17
17
  entourage project new <name> make a project from the template
18
18
  entourage project add <name> <path> add a repo that is already on this machine
19
19
  entourage project open <name> show the project as a Herdr space
20
- entourage project ls list projects and their repos
20
+ entourage project ls [--json] list projects and their repos (--json for programs)
21
21
  entourage task new <project> <card> write a card up: an agent defines, plans and breaks it down
22
22
  entourage task start <project> <branch> [<repo>[:<group>[,<group>...]] ...]
23
23
  start the work: a worktree per repo, opened as a tab
package/cli/lib/common.sh CHANGED
@@ -38,9 +38,15 @@ require_herdr() {
38
38
  [ -d "$APP_HOME" ] || die "$APP_HOME does not exist yet. Open Herdr once so it creates its folder, then run this again."
39
39
  }
40
40
 
41
- # Print a string as the inside of a JSON string. sed and awk do the work so
42
- # that the result does not depend on the bash version's quoting rules.
41
+ # Print a string as the inside of a JSON string. Most strings have nothing to
42
+ # escape and are printed as they are, with no program started. For the rest,
43
+ # sed and awk do the work so that the result does not depend on the bash
44
+ # version's quoting rules.
43
45
  json_str() {
46
+ case $1 in
47
+ *[\\\"[:cntrl:]]*) ;;
48
+ *) printf '%s' "$1"; return ;;
49
+ esac
44
50
  printf '%s' "$1" | tr '\t\r' ' ' |
45
51
  sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' |
46
52
  awk 'BEGIN { ORS = "" } NR > 1 { print "\\n" } { print }'
@@ -128,8 +128,34 @@ project_open() {
128
128
  show_space "$name" "$dir"
129
129
  }
130
130
 
131
+ # The same list for programs: one line of JSON, each project with its folder
132
+ # (as project_dir prints it) and its repos. The projects mod reads this.
133
+ project_ls_json() {
134
+ local d repo sep='' rsep
135
+ printf '{"projects":['
136
+ for d in "$PROJECTS"/*/; do
137
+ [ -d "$d" ] || continue
138
+ d=${d%/}
139
+ printf '%s{"name":"%s","folder":"%s","repos":[' "$sep" \
140
+ "$(json_str "${d##*/}")" "$(json_str "$(cd -P "$d" && pwd)")"
141
+ rsep=''
142
+ while IFS= read -r repo; do
143
+ printf '%s"%s"' "$rsep" "$(json_str "$repo")"
144
+ rsep=,
145
+ done < <(project_repos "$d")
146
+ printf ']}'
147
+ sep=,
148
+ done
149
+ printf ']}\n'
150
+ }
151
+
131
152
  project_ls() {
132
153
  local d any=0 repo
154
+ case ${1:-} in
155
+ --json) project_ls_json; return ;;
156
+ '') ;;
157
+ *) die "unknown option for project ls: $1" ;;
158
+ esac
133
159
  for d in "$PROJECTS"/*/; do
134
160
  [ -d "$d" ] || continue
135
161
  any=1
@@ -178,7 +204,7 @@ cmd_project() {
178
204
  new) shift; project_new "$@" ;;
179
205
  add) shift; project_add "$@" ;;
180
206
  open) shift; project_open "$@" ;;
181
- ls | list) shift; project_ls ;;
207
+ ls | list) shift; project_ls "$@" ;;
182
208
  *) die "usage: entourage project new|add|open|ls (see: entourage help)" ;;
183
209
  esac
184
210
  }
package/herdr/README.md CHANGED
@@ -9,8 +9,9 @@ layouts (whole-window arrangements of mods).
9
9
  |---|---|
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
+ | `mods/projects/` | Every project in your config, open or not. Click one to show its space. |
12
13
  | `layouts/default.json` | Herdr's own layout, plus the layout dropdown. |
13
- | `layouts/test.json` | `default` plus the CPU mod in the sidebar. |
14
+ | `layouts/test.json` | `default` with the projects list in place of spaces, plus the CPU mod in the sidebar. |
14
15
  | `projects/template/` | The starting `PROJECT.md` for every new project. |
15
16
 
16
17
  The skills are in [../skills/](../skills/), outside this folder. They are
@@ -102,6 +103,8 @@ template is in this repo. Your own projects are in
102
103
  - **Open it:** `entourage project open <name>` rebuilds the links and shows
103
104
  the project's space, making it if it is not open. The space's folder is the
104
105
  project folder.
106
+ - **List them:** `entourage project ls`. `--json` prints the same list as
107
+ JSON with each project's folder; the projects mod reads it.
105
108
  - **Check them:** `entourage status` reports a repo that has moved or gone,
106
109
  and a `PROJECT.md` that is still the template. Delete the template's first
107
110
  line once you have filled it in.
@@ -36,10 +36,10 @@
36
36
  "type": "column",
37
37
  "children": [
38
38
  {
39
- "id": "spaces",
39
+ "id": "projects",
40
40
  "type": "block",
41
41
  "content": {
42
- "mod": "spaces"
42
+ "mod": "projects"
43
43
  },
44
44
  "size": {
45
45
  "weight": 1
@@ -0,0 +1,167 @@
1
+ // Every project in the entourage config, open or not. Herdr only knows a
2
+ // project while its space has a tab, so the list comes from the entourage
3
+ // command, which owns where projects live and what counts as one. Click a
4
+ // project to show its space; one with no space is opened by the command.
5
+ import { View, div } from "gpui-kit";
6
+ import { v_flex, h_flex } from "gpui-base";
7
+ import { exec, spaces, run, notify, theme, layout, window, checking, appHome } from "herdr";
8
+
9
+ const REFRESH_MS = 15000; // projects change rarely; the open marks are live anyway
10
+ const TIMEOUT_MS = 10000;
11
+ const ROW = 30;
12
+ const RAIL_CELL = 32;
13
+ // How this mod's own link into the repo that ships it ends.
14
+ const LINKED_AT = "/herdr/mods/projects";
15
+ const EMPTY = "No projects yet. Make one with: entourage project new <name>";
16
+ const OLD_CLI = "This entourage cannot list projects as JSON. Run: entourage update";
17
+
18
+ function find(node, id) {
19
+ if (node?.id === id) return node;
20
+ for (const child of node?.children ?? []) {
21
+ const found = find(child, id);
22
+ if (found) return found;
23
+ }
24
+ return null;
25
+ }
26
+
27
+ // The sidebar's rail goes by its width, as in Herdr's own lists.
28
+ const narrow = () => (find(layout(), "sidebar")?.size?.px ?? Infinity) < 160;
29
+
30
+ // The listing, or null when the output is not the JSON this mod reads (an
31
+ // older entourage prints the plain list whatever the option).
32
+ function parse(text) {
33
+ try {
34
+ const list = JSON.parse(text).projects;
35
+ return Array.isArray(list) ? list : null;
36
+ } catch {
37
+ return null;
38
+ }
39
+ }
40
+
41
+ // What a failed command said, without the name it starts its errors with.
42
+ const said = (r) => (r.stderr || r.stdout).trim().replace(/^entourage: /, "");
43
+
44
+ export default class Projects extends View {
45
+ init(_props, cx) {
46
+ this.projects = null; // null until the first listing answers
47
+ this.error = null;
48
+ this.busy = false;
49
+ this.opening = null; // the project a click is making a space for
50
+ this.cmd = "entourage"; // the one on PATH, until that cannot start
51
+ if (checking()) return;
52
+ cx.timer.every(REFRESH_MS, (cx) => this.refresh(cx));
53
+ this.refresh(cx);
54
+ }
55
+
56
+ // Runs the entourage command. With `fallback`, a command that cannot run is
57
+ // tried again as the copy this mod is linked from (Herdr may have been
58
+ // started without the user's PATH). Only the listing asks for that: it is
59
+ // safe to run twice, and it has answered before there is a row to click. An
60
+ // open never does, because its failure may be a timeout with the first run
61
+ // still making the space.
62
+ async entourage(args, { fallback = false } = {}) {
63
+ try {
64
+ return await exec(this.cmd, args, { timeout: TIMEOUT_MS });
65
+ } catch (e) {
66
+ if (!fallback || this.cmd !== "entourage") throw e;
67
+ const link = await exec("readlink", [`${appHome()}/mods/projects`]);
68
+ const at = link.stdout.trim();
69
+ if (link.code !== 0 || !at.endsWith(LINKED_AT)) throw e;
70
+ this.cmd = `${at.slice(0, -LINKED_AT.length)}/cli/entourage`;
71
+ return exec(this.cmd, args, { timeout: TIMEOUT_MS });
72
+ }
73
+ }
74
+
75
+ refresh(cx) {
76
+ // Skip while a listing is in flight or nobody can see the window.
77
+ if (this.busy || window()?.visible === false) return;
78
+ this.busy = true;
79
+ cx.spawn(async (cx) => {
80
+ try {
81
+ const r = await this.entourage(["project", "ls", "--json"], { fallback: true });
82
+ const list = r.code === 0 ? parse(r.stdout) : null;
83
+ if (list) this.projects = list;
84
+ this.error = list ? null : r.code === 0 ? OLD_CLI : said(r) || "entourage project ls failed";
85
+ } catch (e) {
86
+ this.error = `Could not run entourage: ${e?.message ?? e}`;
87
+ }
88
+ this.busy = false;
89
+ cx.notify();
90
+ });
91
+ }
92
+
93
+ // `space`: the project's open space, or null.
94
+ pick(p, space, cx) {
95
+ if (space) {
96
+ run("space.select", { id: space.id });
97
+ return;
98
+ }
99
+ // One at a time: a second open would not see the first one's space yet.
100
+ if (this.opening) return;
101
+ this.opening = p.name;
102
+ cx.notify();
103
+ cx.spawn(async (cx) => {
104
+ let failed = null;
105
+ try {
106
+ const r = await this.entourage(["project", "open", p.name]);
107
+ if (r.code !== 0) failed = said(r);
108
+ } catch (e) {
109
+ failed = String(e?.message ?? e);
110
+ }
111
+ if (failed !== null) notify({ title: `Could not open ${p.name}`, body: failed, level: "error" });
112
+ this.opening = null;
113
+ this.refresh(cx);
114
+ cx.notify();
115
+ });
116
+ }
117
+
118
+ row(p, space, t) {
119
+ const on = Boolean(space?.active);
120
+ const n = (p.repos ?? []).length;
121
+ const tail = this.opening === p.name ? "Opening…" : `${n} repo${n === 1 ? "" : "s"}`;
122
+ const dot = div().size(7).rounded(4).flex_none();
123
+ return h_flex().id(`project-${p.name}`).h(ROW).flex_none().px(8).gap(9).items_center().rounded(8)
124
+ .when(on, (el) => el.bg(t.selected))
125
+ .when(!on, (el) => el.hover((s) => s.bg(t.hover)))
126
+ .on_click((_e, cx) => this.pick(p, space, cx))
127
+ .child(h_flex().size(18).flex_none().items_center().justify_center()
128
+ .child(space ? dot.bg(t.ansi2) : dot.border_1().border_color(t.dim)))
129
+ .child(div().flex_1().min_w(0).truncate().text_color(space ? t.foreground : t.muted).child(p.name))
130
+ .child(div().flex_none().text_size(11.5).text_color(t.dim).child(tail));
131
+ }
132
+
133
+ // On the sidebar's rail: the project's first letter.
134
+ compact(p, space, t) {
135
+ const on = Boolean(space?.active);
136
+ return h_flex().flex_none().justify_center().child(
137
+ h_flex().id(`project-${p.name}`).w(RAIL_CELL).h(26).rounded(6).items_center().justify_center()
138
+ .tooltip(p.name)
139
+ .when(on, (el) => el.bg(t.selected))
140
+ .when(!on, (el) => el.hover((s) => s.bg(t.hover)))
141
+ .on_click((_e, cx) => this.pick(p, space, cx))
142
+ .child(div().text_color(space ? t.foreground : t.dim).child((p.name[0] ?? "?").toUpperCase())));
143
+ }
144
+
145
+ render() {
146
+ const t = theme();
147
+ const collapsed = narrow();
148
+ // A project is open when a space on this computer has its folder.
149
+ const local = spaces().filter((s) => !s.machine);
150
+ const note = (text, color) => div().px(8).py(6).text_size(12).text_color(color).child(text);
151
+ const items = [];
152
+ if (!collapsed) {
153
+ if (this.error) items.push(note(this.error, t.blocked));
154
+ else if (this.projects === null) items.push(note("Loading…", t.dim));
155
+ else if (this.projects.length === 0) items.push(note(EMPTY, t.dim));
156
+ }
157
+ for (const p of this.projects ?? []) {
158
+ const space = local.find((s) => s.folder === p.folder) ?? null;
159
+ items.push(collapsed ? this.compact(p, space, t) : this.row(p, space, t));
160
+ }
161
+ return v_flex().size_full().min_h(0).bg(t.chrome).text_size(13)
162
+ .child(h_flex().h(31).flex_none().pl(16).pr(10).items_center().text_size(11.5).text_color(t.dim)
163
+ .when(!collapsed, (el) => el.child("Projects")))
164
+ .child(v_flex().id("project-list").flex_1().min_h(0).px(collapsed ? 0 : 8).pb(14)
165
+ .overflow_y_scrollbar().mode("always").children(items));
166
+ }
167
+ }
@@ -0,0 +1 @@
1
+ { "place": "none", "title": "Projects" }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johngaynor/entourage",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
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"