@johngaynor/ocnus 0.0.0-stage → 2.0.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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +988 -2
  3. package/agents/linear-mcp.json +1 -0
  4. package/agents/ocnus-build.md +23 -0
  5. package/agents/ocnus-write-up.md +20 -0
  6. package/cli/host-mark +36 -0
  7. package/cli/lib/agents.sh +350 -0
  8. package/cli/lib/approval.sh +94 -0
  9. package/cli/lib/archive.sh +447 -0
  10. package/cli/lib/billing.sh +166 -0
  11. package/cli/lib/close.sh +189 -0
  12. package/cli/lib/commands.sh +220 -0
  13. package/cli/lib/common.sh +215 -0
  14. package/cli/lib/finish.sh +288 -0
  15. package/cli/lib/github.sh +162 -0
  16. package/cli/lib/guard.sh +134 -0
  17. package/cli/lib/handoff.sh +551 -0
  18. package/cli/lib/host.sh +1802 -0
  19. package/cli/lib/linear.sh +1389 -0
  20. package/cli/lib/links.sh +135 -0
  21. package/cli/lib/merges.sh +853 -0
  22. package/cli/lib/recipes.sh +54 -0
  23. package/cli/lib/settings.sh +465 -0
  24. package/cli/lib/space.sh +343 -0
  25. package/cli/lib/task.sh +847 -0
  26. package/cli/lib/tests.sh +268 -0
  27. package/cli/lib/trust.sh +70 -0
  28. package/cli/ocnus +630 -0
  29. package/herdr/README.md +2238 -0
  30. package/herdr/layouts/default.json +259 -0
  31. package/herdr/mods/agent-settings/cog.svg +4 -0
  32. package/herdr/mods/agent-settings/main.js +356 -0
  33. package/herdr/mods/agent-settings/mod.json +1 -0
  34. package/herdr/mods/cards/main.js +450 -0
  35. package/herdr/mods/cards/mod.json +1 -0
  36. package/herdr/mods/cards/refresh.svg +4 -0
  37. package/herdr/mods/cpu/main.js +90 -0
  38. package/herdr/mods/cpu/mod.json +1 -0
  39. package/herdr/mods/layout-switch/main.js +48 -0
  40. package/herdr/mods/layout-switch/mod.json +1 -0
  41. package/herdr/mods/names/main.js +69 -0
  42. package/herdr/mods/names/mod.json +1 -0
  43. package/herdr/mods/ocnus-spaces/main.js +376 -0
  44. package/herdr/mods/ocnus-spaces/mod.json +1 -0
  45. package/herdr/mods/steps/main.js +354 -0
  46. package/herdr/mods/steps/mod.json +1 -0
  47. package/herdr/spaces/template/SPACE.md +19 -0
  48. package/package.json +27 -4
  49. package/prompts/task-build.md +11 -0
  50. package/prompts/task-new.md +17 -0
  51. package/skills/brief/SKILL.md +64 -0
  52. package/skills/sdlc-breakdown/SKILL.md +312 -0
  53. package/skills/sdlc-build/SKILL.md +182 -0
  54. package/skills/sdlc-define/SKILL.md +203 -0
  55. package/skills/sdlc-plan/SKILL.md +202 -0
  56. package/skills/sdlc-pr/SKILL.md +339 -0
  57. package/skills/sdlc-review/SKILL.md +227 -0
@@ -0,0 +1,376 @@
1
+ // Every ocnus space in the config, open or not. Herdr knows a space only
2
+ // while it is open there, with a tab, so the list comes from the ocnus
3
+ // command, which owns where spaces live and what counts as one. Click a space
4
+ // to show it; one that is not open in Herdr is opened by the command.
5
+ //
6
+ // The mod is ocnus-spaces, since spaces is Herdr's own list, a mod Herdr
7
+ // ships. One mod, two faces: the list a layout places, and the New space
8
+ // dialog (the same mod again, with props { create: true }). The + above the
9
+ // list asks for a repo's folder with the system's picker, then opens the
10
+ // dialog on it. The dialog makes the space with the command too.
11
+ import { View, div } from "gpui-kit";
12
+ import { v_flex, h_flex, InputState, Input } from "gpui-base";
13
+ import {
14
+ exec, spaces, run, notify, theme, layout, window, checking, appHome, home, props,
15
+ pickFolder, openOverlay, closeOverlay, nextCommand,
16
+ } from "herdr";
17
+
18
+ const REFRESH_MS = 15000; // spaces change rarely; the open marks are live anyway
19
+ const TIMEOUT_MS = 10000;
20
+ const ROW = 30;
21
+ const RAIL_CELL = 32;
22
+ // How this mod's own link into the repo that ships it ends.
23
+ const LINKED_AT = "/herdr/mods/ocnus-spaces";
24
+ const EMPTY = "No ocnus spaces yet. Make one with the + above.";
25
+ const OLD_CLI = "This ocnus is too old for the Ocnus spaces panel. Run: ocnus update";
26
+
27
+ // `herdr-app check` draws the mod once, with nothing listed and no space open,
28
+ // which would draw one line of text and none of the rows. It is given these
29
+ // to draw instead: a space open in Herdr and shown, one being opened, and one
30
+ // that is not open.
31
+ const SAMPLE = [
32
+ { name: "sample", folder: "/sample/sample", repos: ["/sample/api", "/sample/web"] },
33
+ { name: "opening", folder: "/sample/opening", repos: ["/sample/api"] },
34
+ { name: "closed", folder: "/sample/closed", repos: [] },
35
+ ];
36
+ const SAMPLE_OPENING = "opening";
37
+ const SAMPLE_OPEN = [{ id: "s", folder: "/sample/sample", active: true }];
38
+
39
+ function find(node, id) {
40
+ if (node?.id === id) return node;
41
+ for (const child of node?.children ?? []) {
42
+ const found = find(child, id);
43
+ if (found) return found;
44
+ }
45
+ return null;
46
+ }
47
+
48
+ // The sidebar's rail goes by its width, as in Herdr's own lists.
49
+ const narrow = () => (find(layout(), "sidebar")?.size?.px ?? Infinity) < 160;
50
+
51
+ // The listing, or null when the output is not the JSON this mod reads: an
52
+ // older ocnus prints the plain list whatever the option, or lists the
53
+ // spaces under another key.
54
+ function parse(text) {
55
+ try {
56
+ const list = JSON.parse(text).spaces;
57
+ return Array.isArray(list) ? list : null;
58
+ } catch {
59
+ return null;
60
+ }
61
+ }
62
+
63
+ // What a failed command said, without the name it starts its errors with.
64
+ const said = (r) => (r.stderr || r.stdout).trim().replace(/^ocnus: /, "");
65
+
66
+ // A picked folder without the slash a picker may end it with.
67
+ const tidy = (path) => (path.length > 1 ? path.replace(/\/+$/, "") : path);
68
+ const base = (path) => path.split("/").pop();
69
+ const tilde = (path) => (path.startsWith(`${home()}/`) ? `~${path.slice(home().length)}` : path);
70
+ // A name to start the dialog with, from the first repo's folder. Only a
71
+ // suggestion: the command decides what a space may be called.
72
+ const suggest = (text) => text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
73
+
74
+ export default class OcnusSpaces extends View {
75
+ init(_props, cx) {
76
+ this.listed = null; // the spaces ocnus lists, null until it first answers
77
+ this.error = null;
78
+ this.busy = false;
79
+ this.opening = null; // the space a click is opening in Herdr
80
+ this.cmd = "ocnus"; // the one on PATH, until that cannot start
81
+ this.picking = false; // the system's folder picker is up
82
+ if (props()?.create) return this.initForm(cx);
83
+ if (checking()) return;
84
+ cx.timer.every(REFRESH_MS, (cx) => this.refresh(cx));
85
+ // The dialog says when it has made a space, so its row need not wait
86
+ // for the timer.
87
+ cx.spawn(async (cx) => {
88
+ for (;;) {
89
+ if ((await nextCommand()) === "refresh") this.refresh(cx);
90
+ cx.notify();
91
+ }
92
+ });
93
+ this.refresh(cx);
94
+ }
95
+
96
+ // The dialog. props: { create: true, folder: the first repo, cmd: the
97
+ // ocnus command the list found, overlay }.
98
+ initForm(cx) {
99
+ const p = props() ?? {};
100
+ if (p.cmd) this.cmd = p.cmd;
101
+ this.repos = p.folder ? [tidy(p.folder)] : [];
102
+ this.name = suggest(base(this.repos[0] ?? ""));
103
+ this.error = "";
104
+ this.working = false;
105
+ this.input = InputState.new({ value: this.name, placeholder: "my-space" });
106
+ if (this.name) this.input.set_selected_range({ start: 0, end: this.name.length });
107
+ this.input.on("change", (_e, cx) => { this.name = this.input.value(); this.error = ""; cx.notify(); });
108
+ this.input.on("submit", (_e, cx) => this.submit(cx));
109
+ this.inputFocused = true;
110
+ this.input.on("focus", (_e, cx) => { this.inputFocused = true; cx.notify(); });
111
+ this.input.on("blur", (_e, cx) => { this.inputFocused = false; cx.notify(); });
112
+ this.handle = cx.focus_handle();
113
+ // Twice, as Herdr's own prompt does: the first lands before the dialog shows.
114
+ this.input.focus();
115
+ cx.timer.after(600, () => this.input.focus());
116
+ }
117
+
118
+ // Runs the ocnus command. With `fallback`, a command that cannot run is
119
+ // tried again as the copy this mod is linked from (Herdr may have been
120
+ // started without the user's PATH). Only the listing asks for that: it is
121
+ // safe to run twice, and it has answered before there is a row to click. An
122
+ // open never does, because its failure may be a timeout with the first run
123
+ // still making the space.
124
+ async ocnus(args, { fallback = false } = {}) {
125
+ try {
126
+ return await exec(this.cmd, args, { timeout: TIMEOUT_MS });
127
+ } catch (e) {
128
+ if (!fallback || this.cmd !== "ocnus") throw e;
129
+ const link = await exec("readlink", [`${appHome()}/mods/ocnus-spaces`]);
130
+ const at = link.stdout.trim();
131
+ if (link.code !== 0 || !at.endsWith(LINKED_AT)) throw e;
132
+ this.cmd = `${at.slice(0, -LINKED_AT.length)}/cli/ocnus`;
133
+ return exec(this.cmd, args, { timeout: TIMEOUT_MS });
134
+ }
135
+ }
136
+
137
+ refresh(cx) {
138
+ // Skip while a listing is in flight or nobody can see the window.
139
+ if (this.busy || window()?.visible === false) return;
140
+ this.busy = true;
141
+ cx.spawn(async (cx) => {
142
+ try {
143
+ const r = await this.ocnus(["space", "ls", "--json"], { fallback: true });
144
+ const list = r.code === 0 ? parse(r.stdout) : null;
145
+ if (list) this.listed = list;
146
+ this.error = list ? null : r.code === 0 ? OLD_CLI : said(r) || "ocnus space ls failed";
147
+ } catch (e) {
148
+ this.error = `Could not run ocnus: ${e?.message ?? e}`;
149
+ }
150
+ this.busy = false;
151
+ cx.notify();
152
+ });
153
+ }
154
+
155
+ // `s`: a space ocnus listed. `open`: the space Herdr has open for it,
156
+ // or null.
157
+ pick(s, open, cx) {
158
+ if (open) {
159
+ run("space.select", { id: open.id });
160
+ return;
161
+ }
162
+ // One at a time: a second open would not see the first one's space yet.
163
+ if (this.opening) return;
164
+ this.opening = s.name;
165
+ cx.notify();
166
+ cx.spawn(async (cx) => {
167
+ let failed = null;
168
+ try {
169
+ const r = await this.ocnus(["space", "open", s.name]);
170
+ if (r.code !== 0) failed = said(r);
171
+ } catch (e) {
172
+ failed = String(e?.message ?? e);
173
+ }
174
+ if (failed !== null) notify({ title: `Could not open ${s.name}`, body: failed, level: "error" });
175
+ this.opening = null;
176
+ this.refresh(cx);
177
+ cx.notify();
178
+ });
179
+ }
180
+
181
+ // The + above the list: choose the first repo, then name the space.
182
+ create(cx) {
183
+ if (this.picking) return;
184
+ this.picking = true;
185
+ cx.spawn(async (cx) => {
186
+ let folder = null;
187
+ try {
188
+ folder = await pickFolder({ prompt: "Choose" });
189
+ } catch (e) {
190
+ notify({ title: "Could not open the folder picker", body: String(e?.message ?? e), level: "error" });
191
+ }
192
+ this.picking = false;
193
+ if (folder) {
194
+ openOverlay({
195
+ mod: "ocnus-spaces", kind: "dialog", modal: true, width: 480,
196
+ props: { create: true, folder, cmd: this.cmd },
197
+ });
198
+ }
199
+ cx.notify();
200
+ });
201
+ }
202
+
203
+ // `opening`: the space a click is opening, if any.
204
+ row(s, open, opening, t) {
205
+ const on = Boolean(open?.active);
206
+ const n = (s.repos ?? []).length;
207
+ const tail = opening === s.name ? "Opening…" : `${n} repo${n === 1 ? "" : "s"}`;
208
+ const dot = div().size(7).rounded(4).flex_none();
209
+ return h_flex().id(`space-${s.name}`).h(ROW).flex_none().px(8).gap(9).items_center().rounded(8)
210
+ .when(on, (el) => el.bg(t.selected))
211
+ .when(!on, (el) => el.hover((st) => st.bg(t.hover)))
212
+ .on_click((_e, cx) => this.pick(s, open, cx))
213
+ .child(h_flex().size(18).flex_none().items_center().justify_center()
214
+ .child(open ? dot.bg(t.ansi2) : dot.border_1().border_color(t.dim)))
215
+ .child(div().flex_1().min_w(0).truncate().text_color(open ? t.foreground : t.muted).child(s.name))
216
+ .child(div().flex_none().text_size(11.5).text_color(t.dim).child(tail));
217
+ }
218
+
219
+ // On the sidebar's rail: the space's first letter.
220
+ compact(s, open, t) {
221
+ const on = Boolean(open?.active);
222
+ return h_flex().flex_none().justify_center().child(
223
+ h_flex().id(`space-${s.name}`).w(RAIL_CELL).h(26).rounded(6).items_center().justify_center()
224
+ .tooltip(s.name)
225
+ .when(on, (el) => el.bg(t.selected))
226
+ .when(!on, (el) => el.hover((st) => st.bg(t.hover)))
227
+ .on_click((_e, cx) => this.pick(s, open, cx))
228
+ .child(div().text_color(open ? t.foreground : t.dim).child((s.name[0] ?? "?").toUpperCase())));
229
+ }
230
+
231
+ render() {
232
+ return props()?.create ? this.form() : this.list();
233
+ }
234
+
235
+ list() {
236
+ const t = theme();
237
+ const collapsed = narrow();
238
+ const sample = checking();
239
+ const listed = sample ? SAMPLE : this.listed;
240
+ const opening = sample ? SAMPLE_OPENING : this.opening;
241
+ // A space is open when Herdr has a space on this computer with its folder.
242
+ const local = sample ? SAMPLE_OPEN : spaces().filter((h) => !h.machine);
243
+ const note = (text, color) => div().px(8).py(6).text_size(12).text_color(color).child(text);
244
+ const items = [];
245
+ if (!collapsed && !sample) {
246
+ if (this.error) items.push(note(this.error, t.blocked));
247
+ else if (listed === null) items.push(note("Loading…", t.dim));
248
+ else if (listed.length === 0) items.push(note(EMPTY, t.dim));
249
+ }
250
+ for (const s of listed ?? []) {
251
+ const open = local.find((h) => h.folder === s.folder) ?? null;
252
+ items.push(collapsed ? this.compact(s, open, t) : this.row(s, open, opening, t));
253
+ }
254
+ return v_flex().size_full().min_h(0).bg(t.chrome).text_size(13)
255
+ .child(h_flex().h(31).flex_none().pl(16).pr(10).items_center().justify_between()
256
+ .text_size(11.5).text_color(t.dim)
257
+ .when(collapsed, (el) => el.pl(0).pr(0).justify_center())
258
+ .when(!collapsed, (el) => el.child("Ocnus spaces"))
259
+ .child(div().id("space-new").size(26).flex_none().flex().items_center().justify_center()
260
+ .rounded(6).text_size(15).tooltip("New space")
261
+ .hover((s) => s.bg(t.hover).text_color(t.foreground))
262
+ .on_click((_e, cx) => this.create(cx))
263
+ .child("+")))
264
+ .child(v_flex().id("space-list").flex_1().min_h(0).px(collapsed ? 0 : 8).pb(14)
265
+ .overflow_y_scrollbar().mode("always").children(items));
266
+ }
267
+
268
+ // --- the New space dialog ------------------------------------------------
269
+
270
+ close() {
271
+ closeOverlay(props().overlay);
272
+ }
273
+
274
+ // Another repo for the space, from the system's picker.
275
+ addRepo(cx) {
276
+ if (this.picking || this.working) return;
277
+ this.picking = true;
278
+ cx.spawn(async (cx) => {
279
+ try {
280
+ const folder = await pickFolder({ prompt: "Add" });
281
+ if (folder && !this.repos.includes(tidy(folder))) this.repos.push(tidy(folder));
282
+ this.error = "";
283
+ } catch (e) {
284
+ this.error = `Could not open the folder picker: ${e?.message ?? e}`;
285
+ }
286
+ this.picking = false;
287
+ this.input.focus();
288
+ cx.notify();
289
+ });
290
+ }
291
+
292
+ // Makes the space and shows it in Herdr. The command checks the name and
293
+ // every repo before it makes anything, so what it refuses is shown here and
294
+ // the dialog stays open to be put right.
295
+ submit(cx) {
296
+ if (this.working) return;
297
+ const name = this.name.trim();
298
+ this.working = true;
299
+ this.error = "";
300
+ cx.notify();
301
+ cx.spawn(async (cx) => {
302
+ let failed = null;
303
+ try {
304
+ const r = await this.ocnus(["space", "new", name, ...this.repos]);
305
+ if (r.code !== 0) failed = said(r) || "ocnus space new failed";
306
+ } catch (e) {
307
+ failed = `Could not run ocnus: ${e?.message ?? e}`;
308
+ }
309
+ if (failed !== null) {
310
+ this.working = false;
311
+ this.error = failed;
312
+ cx.notify();
313
+ return;
314
+ }
315
+ // Tell the list. With no list showing there is nobody to tell, and that
316
+ // must not stop the space from opening.
317
+ try { run("ocnus-spaces.refresh"); } catch {}
318
+ // The space is made, so one that will not open in Herdr is not this
319
+ // dialog's to keep asking about: say so and leave it in the list.
320
+ let unopened = null;
321
+ try {
322
+ const r = await this.ocnus(["space", "open", name]);
323
+ if (r.code !== 0) unopened = said(r);
324
+ } catch (e) {
325
+ unopened = String(e?.message ?? e);
326
+ }
327
+ if (unopened !== null) notify({ title: `Made ${name}, but could not open it`, body: unopened, level: "error" });
328
+ this.close();
329
+ });
330
+ }
331
+
332
+ form() {
333
+ const t = theme();
334
+ const label = (text) => div().pt(16).pb(7).text_size(11.5).text_color(t.dim).child(text);
335
+ const button = (id, text, primary, action) =>
336
+ h_flex().id(id).h(32).px(14).items_center().rounded(8)
337
+ .border_1().border_color(primary ? t.solid : t.input).bg(primary ? t.solid : t.raised)
338
+ .text_color(primary ? t.solid_foreground : t.foreground).text_size(12.5).font_medium()
339
+ .cursor_pointer().hover((s) => s.opacity(0.88)).on_click(action).child(text);
340
+ const repo = (path, i) =>
341
+ h_flex().h(ROW).flex_none().pl(10).pr(4).gap(10).items_center().rounded(8).bg(t.raised)
342
+ .child(div().flex_none().max_w(180).truncate().child(base(path)))
343
+ .child(div().flex_1().min_w(0).truncate().text_size(11.5).text_color(t.dim).child(tilde(path)))
344
+ .child(div().id(`space-new-drop-${i}`).size(22).flex_none().flex().items_center().justify_center()
345
+ .rounded(6).text_color(t.dim).tooltip("Leave this repo out")
346
+ .hover((s) => s.bg(t.hover).text_color(t.foreground))
347
+ .on_click((_e, cx) => { this.repos.splice(i, 1); this.error = ""; cx.notify(); })
348
+ .child("×"));
349
+ return v_flex().id("space-new-form").track_focus(this.handle)
350
+ .on_key_down((e, cx) => { if (e.key === "escape") { this.close(); cx.stop_propagation(); } })
351
+ .w_full().min_h(0).p(18).bg(t.popover).text_color(t.foreground).text_size(13)
352
+ .child(h_flex().items_center()
353
+ .child(div().flex_1().text_size(15).font_semibold().child("New space"))
354
+ .child(div().text_size(11).text_color(t.dim).child("Esc")))
355
+ .child(div().pt(6).text_size(12.8).text_color(t.muted)
356
+ .child("A space groups the repos that belong together and opens in Herdr as one space."))
357
+ .child(label("Name"))
358
+ .child(Input.new(this.input).h(36).px(10).rounded(9).border_1()
359
+ .border_color(this.inputFocused ? t.accent : t.input).bg(t.background)
360
+ .text_size(12.8).text_color(t.foreground))
361
+ .child(label("Repos"))
362
+ .child(v_flex().id("space-new-repos").max_h(200).min_h(0).flex_shrink(1).gap(4)
363
+ .overflow_y_scroll().children(this.repos.map(repo)))
364
+ .child(h_flex().id("space-new-add").h(ROW).flex_none().mt(this.repos.length ? 4 : 0).px(10)
365
+ .items_center().rounded(8).text_color(t.muted).cursor_pointer()
366
+ .hover((s) => s.bg(t.hover).text_color(t.foreground))
367
+ .on_click((_e, cx) => this.addRepo(cx))
368
+ .child(this.repos.length ? "+ Add another repo…" : "+ Add a repo…"))
369
+ .when(Boolean(this.error), (el) =>
370
+ el.child(div().pt(12).text_size(12).text_color(t.blocked).child(this.error)))
371
+ .child(h_flex().pt(20).gap(8).justify_end()
372
+ .child(button("space-new-cancel", "Cancel", false, () => this.close()))
373
+ .child(button("space-new-create", this.working ? "Creating…" : "Create", true,
374
+ (_e, cx) => this.submit(cx))));
375
+ }
376
+ }
@@ -0,0 +1 @@
1
+ { "place": "none", "title": "Ocnus spaces" }