@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
package/cli/ocnus ADDED
@@ -0,0 +1,630 @@
1
+ #!/usr/bin/env bash
2
+ # ocnus: set up and maintain this machine's copy of the software factory.
3
+ # It links the Herdr mods and layouts under herdr/, the agent skills under
4
+ # skills/ and the agent profiles under agents/, keeps the model and effort
5
+ # each profile runs on, and manages spaces (groups of repos, each of which
6
+ # opens in Herdr as one space) and their tasks (a card an agent writes up, then
7
+ # a worktree of each repo on one branch, each shown as a tab in its space).
8
+ set -euo pipefail
9
+
10
+ usage() {
11
+ cat <<'EOF'
12
+ ocnus: set up and maintain this machine from the ocnus repo
13
+
14
+ Usage:
15
+ ocnus install first-time setup: link everything into the tools on this machine
16
+ ocnus update [--no-pull] get the latest ocnus, link anything new, drop stale links, refresh Herdr
17
+ ocnus status show whether herdr-core is running and what is linked and what is
18
+ not, check your spaces and your Linear key: whose it is, and
19
+ whether it can change cards, and say which account the agents
20
+ run on and whether an Anthropic API key is saved
21
+ ocnus space new <name> [<path>...] make a space from the template, with the repos at those paths
22
+ ocnus space add <name> <path> add a repo that is already on this machine
23
+ ocnus space open <name> show the space in Herdr
24
+ ocnus space ls [--json] list spaces and their repos (--json for programs)
25
+ ocnus space team <name> [<team>...] set the Linear teams whose cards are the space's, or print them
26
+ ocnus profile ls [--json] show the model and effort each agent profile runs on
27
+ (--json for programs)
28
+ ocnus profile set <profile> <model|effort> <value>
29
+ set the model or the effort of one profile: write-up,
30
+ build, reviewer or verifier
31
+ ocnus task ls <space> [--json] list the open cards of the space's Linear teams, by status
32
+ ocnus task new <space> <card> write a card up: an agent defines, plans and breaks it down
33
+ ocnus task start <space> <card> [--type <type> --title <title>] [<repo>[:<group>[,<group>...]] ...]
34
+ start the work: a worktree per repo, opened as a tab
35
+ where the agent builds the card
36
+ ocnus task build <space> <card> [--continue <message>]
37
+ start the agent that builds the card, in its task's tab
38
+ (--continue: continue claude's last session there, with the message)
39
+ ocnus task close <space> <card> put away the card's write-up session once its agent's turn
40
+ ends: end its Claude session with /exit, then close its tab
41
+ (task start runs it once the build tab is open)
42
+ ocnus task finish <space> <card> end a task whose work has merged: remove its worktrees,
43
+ its branch in each repo and its folder, and close its tab
44
+ ocnus task merges [--once | --wake] ocnus's watch on the merges: record the merge of each card
45
+ whose pull requests have all merged and finish its task, and
46
+ wake the agent of one that is closed or in conflict, checking
47
+ every minute until no card waits (--once: check once; --wake:
48
+ only start it, while a card waits and herdr-core runs, as the
49
+ launchd agent install writes does every minute)
50
+ ocnus task handoff <space> <card> record how a step ended: a handoff block on stdin
51
+ ocnus task log <space> [<card>] [--json]
52
+ list a card's hand-offs and how long each step took,
53
+ or with no card the cards that have hand-offs and where each stands
54
+ ocnus linear key save your Linear API key, so ocnus can read and write Linear cards
55
+ (it says when the key can read cards but not change them)
56
+ ocnus linear read <card> [--json] print a card whole: its head, description, comments and
57
+ sub-issues (--json for programs)
58
+ ocnus linear type <card> <feat|fix|chore>
59
+ set a card's type, its label in the Type group
60
+ ocnus linear section <card> <Specification|Plan|Breakdown|Review> [--replace]
61
+ add a section to a card, its body on stdin
62
+ ocnus linear slices <card> make a card's slices as its sub-issues, each with the card's
63
+ type and blocked by the one before; the slices on stdin,
64
+ and a run again makes only the ones still missing
65
+ ocnus linear move <card> <approved|started|review|done>
66
+ move a card forward in Linear: to its team's first
67
+ not-started status (Todo) with its sub-issues, its first
68
+ started status, its last started one (In Review), or Done
69
+ ocnus linear archive [on|off|--json] say whether a merged card is archived in Linear, or turn
70
+ that on or off (--json for programs)
71
+ ocnus tests [share|queue|--json] say whether the runs of ocnus's own tests on this
72
+ machine share its processors or go one at a time, or set it
73
+ (--json for programs)
74
+ ocnus tests run <command> [<arg>...] run a test command as it is, and record the test run while
75
+ the host is recorded, as the build phase's skills do
76
+ ocnus approval [--json | --breakdown on|off]
77
+ say whether breakdown asks you to approve each card, or turn
78
+ that off, so it approves a card it has no doubt about and
79
+ starts it (--json for programs)
80
+ ocnus billing [--json | api | subscription]
81
+ say whether every agent runs on your Claude subscription
82
+ or on an Anthropic API key, or set it (--json for programs)
83
+ ocnus billing key save the Anthropic API key the agents run on with billing
84
+ on api
85
+ ocnus host say whether how hard this machine works is recorded
86
+ ocnus host on record it every 10 seconds while an agent is open
87
+ ocnus host off stop recording, and delete every reading
88
+ ocnus host report [<period>] how often CPU, memory and disk were at their limit, how often
89
+ CPU or memory was with each number of agents working, and
90
+ how much slower test runs were then, the work going in the
91
+ 5 longest stretches when it was, the steps, phases and test
92
+ runs that used the most CPU and memory, where the steps'
93
+ time went, whether the network may be the cause of slow
94
+ waits on the model, and a verdict on what to upgrade first:
95
+ <n>d or <n>h back from now (7d when none is given), a day
96
+ YYYY-MM-DD, or <day>..<day>
97
+ ocnus help
98
+
99
+ A space groups repos that belong together, with a SPACE.md saying what
100
+ each repo is for, and opens in Herdr as one space. A repo can be in several
101
+ spaces. `space new` also marks the space's folder as trusted in Claude
102
+ Code's own file (~/.claude.json), so an agent started there is not stopped
103
+ by the trust question. It needs jq; without it Claude Code asks once.
104
+
105
+ A task is one piece of work in a space, usually a Linear card.
106
+ `task ls` lists the cards `task new` can be given: every card of the
107
+ space's Linear teams that is not done, cancelled or a duplicate, under its
108
+ status. It needs two things set once. `linear key` asks for a Linear API key
109
+ and saves it (make one in Linear, under Settings, Account, Security & access,
110
+ Personal API keys; Read permission is enough to list cards and for
111
+ `linear read`, which the card skills read a card with, and the card skills'
112
+ writes, `linear type`, `linear section`, `linear slices` and `linear move`,
113
+ need Write too).
114
+ `linear key` and `status` check whether the key can change cards, by asking
115
+ Linear to change a card that cannot exist, which changes nothing. A key that
116
+ can read cards but not change them is still saved, and `linear key` says
117
+ so; `status` lists it as a problem and exits non-zero. Make a key with Write
118
+ permission and save it with `linear key` to fix it.
119
+ `space team` names the space's teams by their keys: ABC for the team
120
+ whose cards are ABC-122. A space can name several teams, and several
121
+ spaces can name the same one. Linear is asked with curl and its answer read
122
+ with jq.
123
+ `task new` takes the card's ID, like ABC-122. It opens a tab in the space,
124
+ in Herdr, and starts an agent there, which writes the card up with the
125
+ sdlc-define, sdlc-plan and sdlc-breakdown skills and asks you to approve it.
126
+ Once you do, it runs task start, unless you hold the build phase for later.
127
+ With the breakdown approval off (see `approval` below), it asks only about a
128
+ card it has a doubt about, and approves and starts any other by itself.
129
+ The Herdr app need not be open: with it closed, the agent starts in a
130
+ herdr-core terminal, which `hc attach` shows and which the app shows as a tab
131
+ once it is opened. herdr-core is started when it is not running.
132
+ claude starts with the ocnus-write-up profile (see below).
133
+ With a Linear key saved, it first checks that Linear has the card, and stops
134
+ on a mistyped ID; when Linear cannot be asked, it starts the card anyway.
135
+ `task start` takes the card's ID too, once the card is written up. It asks
136
+ Linear for the card and names the branch from it, <type>/<card-id>-<short-name>
137
+ (https://conventionalbranch.org): the type is the card's label in the Type
138
+ group, and the short name is the first four words of its title, leaving out
139
+ a, an and the, like feat/abc-122-export-orders-as-csv. It stops before it
140
+ makes anything when Linear has no such card, the card has no type, no key is
141
+ saved, or Linear cannot be asked. Without a key Linear accepts, give the
142
+ card's type and title after it, as the command the write-up phase runs or
143
+ gives you then does: `--type feat --title 'Export orders as CSV'` names the
144
+ branch Linear's would. They are used only when no key is saved or Linear cannot be
145
+ asked (a rejected key, the network, no curl or jq), with a note saying why.
146
+ With a key Linear accepts, Linear's type and title win, with a note naming
147
+ each given one that differs. Both are given or neither, and a type that is
148
+ not a branch type stops it. It makes a folder in the space's tasks/ folder
149
+ with a worktree of each repo on that branch, and opens a tab for it whose
150
+ command is `ocnus task build <space> <card>`, which starts the agent on
151
+ the card, with no one typing there. As for `task new`, the Herdr app need not
152
+ be open: with it closed, the tab's terminal starts in herdr-core, which
153
+ `hc attach` shows. herdr-core is started when it is not running.
154
+ Setup is off for now: with OCNUS_SETUP=1, a repo with a justfile that has
155
+ a `setup` recipe gets `just setup` run in that tab first, so the checkout is
156
+ ready to work in before the agent starts. When Claude Code has not trusted the
157
+ repo yet, `task start` says that Claude Code will ask once in the tab.
158
+ Targets after the card narrow the task: `app` takes only that repo, and
159
+ `app:athlete` sets it up for its athlete group (`just setup athlete`).
160
+ Join several groups with a comma: `app:athlete,coach`.
161
+ `task build` starts the agent in the folder it is run in, which has to be the
162
+ card's task, with the ocnus-build profile when it is claude (see below),
163
+ and with the first message in prompts/task-build.md: build the card
164
+ with the sdlc-build skill, review the build with the sdlc-review skill, then
165
+ put it up as a pull request with the sdlc-pr skill.
166
+ Run it again in the tab if the agent stops. With `--continue <message>` it
167
+ continues claude's last session in the task instead, with that message, on
168
+ the same profile, model and effort; another harness refuses it. The build step makes the change
169
+ the card's Plan describes, runs the tests and commits on the task's branch.
170
+ It first installs what the tests need, the way the repo's docs say, and
171
+ starts no app, server or database. The review step runs the tests, unless
172
+ it ran in the same session as the build step and saw them pass on exactly
173
+ what it reviews, checks each Done when item against the card's Plan and
174
+ writes what it found on the card as a Review. Neither pushes anything. What is not met goes back to sdlc-build.
175
+ When all is met, sdlc-pr pushes the task's branch and opens a pull request
176
+ into the default branch of each repo the work changed, saying how the review
177
+ step showed each Done when item. You merge it. Meanwhile the agent waits,
178
+ and runs no watch of its own: ocnus's watch is the only one. It records
179
+ the merge once every pull request for the card has merged, with no one
180
+ typing in the tab, and finishes the task, within a few minutes, with the
181
+ Herdr app open or closed; telling the agent in the tab that they have merged
182
+ has it say so, and do nothing more. That watch is `task merges`, in a
183
+ herdr-core terminal called ocnus-merges, which `task handoff` wakes once
184
+ the pull requests wait on you, as do `task new`, `task start`, `task build`
185
+ and `update`. After a restart, a launchd agent that `install` and `update`
186
+ write wakes it, with `task merges --wake` every minute, so it is back within
187
+ a minute of herdr-core starting, however herdr-core was started; a machine
188
+ with no launchctl has none. It checks every minute while a card waits,
189
+ records nothing while the card's agent is busy, leaving it for a later pass,
190
+ and never starts herdr-core. Once
191
+ the merge is recorded, `task handoff` refuses any other block for the card,
192
+ so it is recorded once. When one is closed, or in conflict, ocnus's
193
+ watch wakes the card's agent once for it: an agent idle in the tab is told
194
+ what was seen, and to bring it up to date or to ask you whether to stop,
195
+ and one that has exited, leaving its shell, is started again with
196
+ `task build --continue` and that message. A busy agent, or a closed tab, is
197
+ woken at a later pass. The agent then goes on as below. When one is closed
198
+ without merging, it asks you whether to stop. When one is in conflict with its
199
+ default branch, it merges the default branch in, never by a rebase, fixes what
200
+ the tests find, has the review check it again and pushes, never forced; it
201
+ asks you only when the tests cannot pass or the fix would change a Done when
202
+ item. No agent merges a pull request.
203
+ ocnus moves the card in Linear at four points: once your approval is
204
+ recorded, to the team's first not-started status (Todo in Lab, Ready for Dev
205
+ in PHY), and each of its sub-issues with it; once `task start` has opened
206
+ the tab, to the first started status (In Progress); once sdlc-pr has opened
207
+ every pull request, with `linear move <card> review`, to its last started
208
+ one (In Review); and once the merge is recorded, to its first completed one
209
+ (Done). A slice's start and its merge move the card it was sliced from too:
210
+ its start to In Progress, and its merge to Done once every one of that
211
+ card's sub-issues is closed, while the note names any still open. A status
212
+ is picked by its kind and its place in the team's order, not by its name; a
213
+ card only moves forward, one that is done or canceled is never moved, and
214
+ the key needs Write permission. A move that cannot be made never stops the
215
+ step: the approval, `task start` and the merge say so in a note naming each
216
+ card not moved, and sdlc-pr in its hand-off. `linear move` alone exits
217
+ non-zero then, saying why.
218
+ Each skill also runs alone in an agent: `/sdlc-build ABC-122`,
219
+ `/sdlc-review ABC-122`, `/sdlc-pr ABC-122`.
220
+ Once `task start` has opened the build tab, it puts the card's write-up
221
+ session away, and for a sub-issue the session of the card it was sliced
222
+ from: it starts `task close` for it in herdr-core, detached, with no tab.
223
+ `task close` waits for the write-up agent's turn to end, ends its Claude
224
+ session with /exit, which archives it in the Claude app's list, then closes
225
+ its tab, or with the Herdr app closed ends its terminal. It never kills a
226
+ live agent: one that has not exited 30 seconds after /exit, or a program in
227
+ the tab that reports no status, leaves the tab open. With start later, the
228
+ session stays open until task start is run, and a task start that stops
229
+ leaves it open. Run in the write-up tab itself, task close refuses.
230
+ `task finish` ends a task once its work has merged: it removes the task's
231
+ worktrees, deletes its branch in each repo, deletes its folder and closes its
232
+ tab, or with the Herdr app closed ends the tab's terminals in herdr-core. It
233
+ checks first, and removes nothing when that would lose work: changes
234
+ that are not committed, commits that are not in the remote's default branch
235
+ (pushed or not), anything in the task folder outside its worktrees, or ignored
236
+ files the repo's `made-by-setup` recipe does not say its setup makes again.
237
+ It names every problem in every repo in one go.
238
+ `task handoff` is run by the agent each time a step ends or pauses, and
239
+ when the human answers a question. It reads a handoff block on stdin (step,
240
+ status, next and so on, one per line), refuses one that breaks the rules, and
241
+ records it. `task log` lists what was recorded for a card, with how long each
242
+ step took and how long it waited on the human. With no card it lists the
243
+ space's cards that have hand-offs, newest first, each with where it stands
244
+ and for how long: a card whose pull requests have merged stands at merged.
245
+ With --json it prints the same view as one line, for
246
+ programs: the Steps panel in Herdr draws it. Run
247
+ `ocnus task handoff <space> <card>` with no block to see the rules.
248
+
249
+ `host on` turns on a record of how hard this machine, the host, works while
250
+ ocnus's agents are open, and `host off` turns it off and deletes every
251
+ reading. It is off until turned on, and works on macOS only. While it is on,
252
+ `task new`, `task start` and `task build` start the recorder, a terminal in
253
+ herdr-core called ocnus-host, which `hc attach ocnus-host` shows. It
254
+ takes a reading every 10 seconds while an agent is open, and stops once none
255
+ is. Nothing starts it with the machine: after a restart it starts again with
256
+ the next agent. A reading is numbers: CPU (busy, system, and by core type
257
+ where the Mac has them), memory (pressure, used, swap, compressed), disk
258
+ (read, written, free space on the home folder's disk), network (bytes in
259
+ and out, Wi-Fi or wired, the share of TCP bytes sent again, Wi-Fi signal and
260
+ noise) and power and heat (on battery, Low Power Mode, thermal state). With
261
+ it goes each agent's share of the CPU and memory, everything it started
262
+ included, named by the card it works on, its phase and the step that card
263
+ is in. Each reading counts the agents working, taking their turn, and those
264
+ open but waiting, and each share says which its agent was. Beside the
265
+ readings go the test runs that agents start through `tests run`, each named
266
+ by its card and repo, with when it started, how long it took, the CPU it
267
+ used and the most memory it held at once, and each reading holds the share
268
+ of each test run going then too. Those are the only names the readings
269
+ hold. They hold no app's name, command line, file, window title, prompt or
270
+ reply, no address, host or site reached, and not the network's name: a test
271
+ run's command is kept only as a fingerprint, a number the same for the same
272
+ command, from which its text cannot be read back. It needs no admin rights,
273
+ and is never sent off the machine. Readings are kept for 90 days, in
274
+ ~/.config/ocnus/host/readings.db. `host report` says, for a period, how
275
+ much of it was recorded and how much of that CPU, memory and disk were each
276
+ at their limit: CPU at least 90% busy across all cores, memory pressure at
277
+ warning or critical, and under 10% of the home folder's disk free. Time with
278
+ no reading, such as when no agent was open, is shown as missing, never as
279
+ idle. It also says how much of the CPU recording used, watching the test
280
+ runs included. For each number of agents working at once, it says how long
281
+ that many were working and how much of that time CPU or memory was at its
282
+ limit, and names the fewest working at which that was at least a quarter of
283
+ the time, as the number from which the host was the limit. For each number
284
+ from 2 up, it says how much slower test runs were than with one working,
285
+ setting only runs of the same command in the same repo against each other,
286
+ once a command has run at least 3 times with each; until then, it says it
287
+ cannot tell yet. It names the 5 longest stretches when CPU or memory was at
288
+ its limit, each with when it started, how long it lasted, which was at its
289
+ limit, and every card's step and every test run going then, with its share
290
+ of the CPU and the most memory it held, and for each card how much of the
291
+ stretch its agent was working. Then it lists the 10 steps and the 10
292
+ phases, each one card's own, that used the most CPU time, and that held the
293
+ most memory at once, then the 10 test runs that did.
294
+
295
+ While the host is recorded, `task new` and `task build` also start claude
296
+ with hooks that mark when its agent starts and stops, is given a prompt,
297
+ starts and ends each tool, and asks for permission: a word and a time each,
298
+ in ~/.config/ocnus/host/marks, and nothing of what the agent was given
299
+ or did. From them each reading splits each agent's time into time on the
300
+ host, while its tools run, waiting on the model, and the rest, such as
301
+ waiting on you. Then `host report` says where the steps' time went: the
302
+ agents' time in all on the host, waiting on the model and the rest, the
303
+ same for the 10 steps open longest, and how many steps had no split, as an
304
+ agent started in another harness or while recording was off has none.
305
+
306
+ Each wait on the model is kept too, as its start and end alone, for 90
307
+ days. A wait is slow when it took over twice the median of every wait
308
+ kept. When waits in the period were slow while CPU, memory and disk were
309
+ all below their limit, `host report` says the network may be the cause,
310
+ with how many were slow and the median.
311
+
312
+ Last, `host report` gives its verdict, one line with its numbers. With
313
+ fewer than 10 steps with their time split in the period, or under an hour
314
+ of the agents' time on the host, the time their tools ran, there is too
315
+ little data yet. Otherwise, of CPU, memory and disk, the one at its limit
316
+ for the most of the agents' time on the host, when that is at least 10% of
317
+ it, is the one to upgrade first, unless over half of its time at its limit
318
+ was on battery, in Low Power Mode or with the thermal state at serious or
319
+ critical: then the power state was the limit. With none at 10%, the network
320
+ was the limit when at least 10% of the period's waits on the model were
321
+ slow while CPU, memory and disk were below their limit, and otherwise no
322
+ upgrade is needed.
323
+
324
+ `tests run <command> [<arg>...]` runs a repo's test command, whole suite or
325
+ part, as in `ocnus tests run npm test`: its output goes straight
326
+ through, it gets the stdin, and it exits as the command did. The build
327
+ phase's skills run every test command through it. While the host is
328
+ recorded, it also records the test run, when it runs in one of the space's
329
+ repos, or a worktree of one, with a card named: its card and repo, when it
330
+ started, how long it took, the CPU it and all it waited for used, from
331
+ macOS's time, the most memory its processes held at once, from ps every
332
+ second while it runs, and the fingerprint of its command. `task build`
333
+ names the card and the space to its agent as OCNUS_CARD and
334
+ OCNUS_SPACE. Otherwise, it runs the command and records nothing.
335
+
336
+ Herdr's folder is ~/.config/herdr-app (HERDR_APP_HOME picks another), which
337
+ Herdr makes when it is first opened. Until then install and update link the
338
+ skills and profiles, and the mods and layouts wait: open Herdr once, then run
339
+ ocnus update. Neither needs the app open.
340
+ Skills are linked into ~/.claude/skills, and agent profiles into
341
+ ~/.claude/agents (CLAUDE_CONFIG_DIR picks another ~/.claude). The harness is
342
+ claude (OCNUS_HARNESS picks another command).
343
+ Your spaces are in ~/.config/ocnus/spaces (OCNUS_HOME picks
344
+ another ~/.config/ocnus), each with a SPACE.md.
345
+ A machine set up before keeps ~/.config/ocnus/projects and PROJECT.md.
346
+ Hand-offs are recorded beside them, in ocnus.db, with sqlite3
347
+ (OCNUS_SQLITE picks another command).
348
+
349
+ A profile is a Claude Code agent definition: the tools a session has,
350
+ whatever your own sessions have. claude starts with one, ocnus-write-up
351
+ for `task new` and ocnus-build for `task build`, and with Linear's MCP
352
+ server alone (agents/linear-mcp.json), not the servers of your own sessions.
353
+ Claude Code asks once to sign in to Linear as linear-server on a machine
354
+ where it is not signed in under that name. When the profile is not linked,
355
+ both stop before starting anything; run `ocnus update`. Another harness
356
+ starts as it is, with no profile, model or effort.
357
+
358
+ Each profile runs on the model and effort that ~/.config/ocnus/settings.json
359
+ names for it. `install` and `update` make the file when it is missing, with
360
+ every profile on opus at xhigh effort, and never change one that is there.
361
+ `profile ls` shows them, and `profile set` changes one: write-up is the agent
362
+ `task new` starts, build the one `task build` starts, and reviewer and
363
+ verifier the ocnus-reviewer and ocnus-verifier subagents, for work on
364
+ ocnus itself. A model is one of claude's aliases (fable, opus, sonnet,
365
+ haiku) or a full model name like claude-opus-5-5, and an effort is low,
366
+ medium, high, xhigh or max; anything else is refused, and the file is left as
367
+ it was. claude starts with --model= and --effort=, which beat the profile's
368
+ own model and your own Claude Code settings; only CLAUDE_CODE_EFFORT_LEVEL
369
+ beats the effort. A clone of ocnus writes the two subagents into
370
+ ~/.claude/agents, with their model and effort, at `install`, at `update` and
371
+ at each `profile set` for one of them, and replaces or removes only a file it
372
+ wrote; an npm install writes neither. A profile or value the file leaves out
373
+ is opus at xhigh. A file that is not valid settings stops `task new` and
374
+ `task build` before an agent starts, saying what in it is wrong, and
375
+ `status` says so too. The file is read with jq. The settings button, a cog at
376
+ the right end of Herdr's tab bar, shows and changes them with these commands,
377
+ and the "archive", "tests", "approval" and "billing" settings below with
378
+ their own.
379
+ The file also holds "archive", true or false: `linear archive on` and
380
+ `linear archive off` set it, leaving the profiles as they are, and
381
+ `linear archive` says whether it is on. It is off with no "archive", and
382
+ `install` and `update` never write one. With it on, recording a card's merge
383
+ archives the card in Linear once its move has put it in Done, and every other
384
+ done, canceled or duplicate card of the space's teams, so that closed cards
385
+ stop counting against Linear's free plan's 250. A sliced card is archived
386
+ with its slices once the card and all of them are closed, each slice and
387
+ then the card, and left as it is while any is open. An archived card can
388
+ still be opened by its ID and restored from its team's archive. A card that
389
+ is not archived never stops the merge: the note names it and says why, and
390
+ the first call Linear refuses or cannot answer ends the archiving, which the
391
+ next merge goes on with.
392
+ The file holds "tests" too, share or queue: how the runs of ocnus's own
393
+ tests (npm test) on this machine use its processors. `tests` says which is
394
+ set, and `tests --json` says it as one line for programs, and `tests share`
395
+ and `tests queue` set it, leaving the rest of the file as it is. They share with no "tests", and `install` and `update` never write
396
+ one: runs going at the same time run one case per processor between them.
397
+ With queue, a run that starts while another is going says it is waiting, and
398
+ how many runs are ahead of it, and starts no case until none that started
399
+ before it is going; then it has every processor. A run with
400
+ OCNUS_TEST_JOBS set waits its turn too. Each run reads the file as it
401
+ starts.
402
+ The file holds "approval" too, as {"breakdown": true} or false: whether
403
+ breakdown, the last step of the write-up phase, asks you to approve each card
404
+ and waits for your answer. `approval --breakdown off` turns that off and
405
+ `approval --breakdown on` turns it on again, leaving the rest of the file as
406
+ it is, and `approval` says which is set. It is on with no "approval", and
407
+ `install` and `update` never write one. With it off, breakdown approves a card
408
+ it has no doubt about by itself and runs `task start`, as for an approval to
409
+ start now, without asking. A card it has a doubt about still waits for you:
410
+ one it thinks too big, one that looks like several cards, or a sub-issue that
411
+ looks too big to stay one piece. So do the questions define and plan ask
412
+ earlier. Breakdown reads the setting when it gets to the approval.
413
+ The file holds "billing" too, subscription or api: which account every agent
414
+ `task new` and `task build` start runs on. `billing api` and
415
+ `billing subscription` set it, leaving the rest of the file as it is, and
416
+ `billing` says which is set and whether a key is saved. It is the
417
+ subscription with no "billing", and `install` and `update` never write one.
418
+ On the subscription, claude starts without ANTHROPIC_API_KEY and
419
+ ANTHROPIC_AUTH_TOKEN, so it runs on the Claude subscription it is signed in
420
+ to with /login, even when your shell exports either. On api, it runs on the
421
+ Anthropic API key `billing key` saved, which it asks ocnus for through an
422
+ apiKeyHelper given with --settings=, so the key is in no argument and in no
423
+ agent's environment; an exported key is still kept from it. `billing key`
424
+ asks for the key, or reads it from stdin, and saves it in the env file as
425
+ `linear key` saves the Linear key; the key is never an argument, and it is not
426
+ checked with Anthropic. On api with no key saved, `task new` and `task build`
427
+ stop before an agent starts, and `status` lists that as a problem. A change
428
+ reaches the next agent started; one already running keeps the account it
429
+ started on. The profiles' model and effort hold either way, and another
430
+ harness starts as it always has. A Claude Code signed in with /login to a
431
+ Console API key uses that key whatever is set. The settings button switches
432
+ it with `billing api` and `billing subscription`; the key is saved in a
433
+ terminal.
434
+
435
+ These variables, and your Linear key as LINEAR_API_KEY, can be exported in
436
+ your shell or written as NAME=value lines in ~/.config/ocnus/.env, which
437
+ `linear key` writes for you and only you can read. A variable you export wins
438
+ over its line in the file, unless it is empty; of two lines for a name, the
439
+ last is used. The Anthropic API key, ANTHROPIC_API_KEY, which `billing key`
440
+ writes there, is read from the file alone: an exported one is never taken
441
+ for it. Herdr starts commands without your shell's exports, so what a
442
+ mod's run of ocnus needs has to be in the file. OCNUS_HOME,
443
+ OCNUS_LIVE, OCNUS_SPACE and OCNUS_CARD are the variables the
444
+ file cannot set.
445
+
446
+ The copy of ocnus in a git worktree of the ocnus repo, run as
447
+ ./cli/ocnus, is a change being built. It runs only the commands that
448
+ read: help, status, space ls, space team <name> with no teams,
449
+ profile ls, linear archive alone or with --json, tests alone or with
450
+ --json, approval alone or with --json, billing alone or with --json, task ls
451
+ and task log. Every other command
452
+ stops before it does anything, says why, and leaves this machine as it was.
453
+ OCNUS_LIVE=1, set for that one run, runs it for real. The installed
454
+ ocnus is never stopped, whatever folder it is run from.
455
+ EOF
456
+ }
457
+
458
+ # --- where things are -------------------------------------------------------
459
+
460
+ # The repo root, found from this script's real location (it may be run through
461
+ # the ~/.local/bin/ocnus link).
462
+ self=${BASH_SOURCE[0]}
463
+ while [ -L "$self" ]; do
464
+ dir=$(cd -P "$(dirname "$self")" && pwd)
465
+ self=$(readlink "$self")
466
+ case $self in /*) ;; *) self=$dir/$self ;; esac
467
+ done
468
+ REPO=$(cd -P "$(dirname "$self")/.." && pwd)
469
+
470
+ # The user's own things: their spaces, and what ocnus keeps for them.
471
+ # They live outside the repo so that they are never published and an npm
472
+ # reinstall does not delete them.
473
+ ENT_HOME=${OCNUS_HOME:-$HOME/.config/ocnus}
474
+
475
+ # ocnus's own environment: NAME=value lines in this file, for the
476
+ # variables that would otherwise be exported in a shell. Herdr starts a
477
+ # command without a shell's exports, so a variable set only in a shell profile
478
+ # is missing when a mod runs ocnus, and the file is where it is found.
479
+ ENV_FILE=$ENT_HOME/.env
480
+ # Whether the Linear key came with the environment, before the file is read.
481
+ KEY_EXPORTED=${LINEAR_API_KEY:+1}
482
+
483
+ # Take ocnus's variables from the file. The file is read, never run: a
484
+ # line that is not NAME=value is skipped, and nothing in a value is expanded.
485
+ # What a line may hold:
486
+ # - export before the name, spaces around the =, one pair of quotes around
487
+ # the value, and a # comment after a value with no quotes;
488
+ # - of two lines for a name, the last one;
489
+ # - a variable already in the environment wins over the file, unless it is
490
+ # empty, which counts as not set.
491
+ # Only the variables ocnus reads are taken: a line for PATH or anything
492
+ # else is skipped, and so is OCNUS_HOME, which says where this file is.
493
+ # OCNUS_LIVE is skipped too: it lets a worktree's copy change the
494
+ # machine, so it is set for one run, never left on in the file (guard.sh).
495
+ # So are OCNUS_SPACE and OCNUS_CARD, which `task build` sets for its
496
+ # agent alone: in the file, they would name a card to every test run.
497
+ # HERDR_APP_HOME and CLAUDE_CONFIG_DIR are exported, so a program ocnus
498
+ # starts finds the same folders it does. The Linear key is not: only
499
+ # ocnus reads it, and it hands it to curl on stdin.
500
+ # The Anthropic key that `billing key` saves, ANTHROPIC_API_KEY, is read from
501
+ # the file alone, whatever the environment holds, into SAVED_ANTHROPIC_KEY,
502
+ # which is not exported: an ANTHROPIC_API_KEY exported in the shell is the
503
+ # human's own, never the saved one, and only claude's apiKeyHelper is given
504
+ # the saved one, by `billing key --print` (billing.sh). The exported one is
505
+ # left as it is, and `task new` and `task build` keep it from claude.
506
+ unset SAVED_ANTHROPIC_KEY
507
+ SAVED_ANTHROPIC_KEY=''
508
+ load_env() {
509
+ local line name value from_file=' '
510
+ local re='^[[:space:]]*(export[[:space:]]+)?([A-Za-z_][A-Za-z0-9_]*)[[:space:]]*=[[:space:]]*(.*)$'
511
+ [ -e "$ENV_FILE" ] || return 0
512
+ # Stop rather than go on without the file: its settings would be missing,
513
+ # and `linear key` would write it anew with only the key in it. Anything
514
+ # there that is not a file, such as a folder, stops it too.
515
+ [ -f "$ENV_FILE" ] || {
516
+ printf 'ocnus: %s is not a file, and ocnus reads its settings from a file there. Move it aside, then run this again.\n' \
517
+ "$ENV_FILE" >&2
518
+ exit 1
519
+ }
520
+ [ -r "$ENV_FILE" ] || {
521
+ printf 'ocnus: cannot read %s. It should be yours, and readable by you only: check its owner, then run: chmod 600 %s\n' \
522
+ "$ENV_FILE" "$ENV_FILE" >&2
523
+ exit 1
524
+ }
525
+ while IFS= read -r line || [ -n "$line" ]; do
526
+ line=${line%$'\r'}
527
+ # The mark some editors put at the start of a file.
528
+ line=${line#$'\357\273\277'}
529
+ [[ $line =~ $re ]] || continue
530
+ name=${BASH_REMATCH[2]} value=${BASH_REMATCH[3]}
531
+ case $name in
532
+ OCNUS_HOME | OCNUS_LIVE | OCNUS_SPACE | OCNUS_CARD) continue ;;
533
+ OCNUS_* | LINEAR_API_KEY | ANTHROPIC_API_KEY | HERDR_APP_HOME | CLAUDE_CONFIG_DIR) ;;
534
+ *) continue ;;
535
+ esac
536
+ # A name the file has set already is set again; one that came with the
537
+ # environment is left as it is. The Anthropic key is the file's alone.
538
+ if [ "$name" != ANTHROPIC_API_KEY ]; then
539
+ case $from_file in
540
+ *" $name "*) ;;
541
+ *) [ -z "${!name:-}" ] || continue ;;
542
+ esac
543
+ from_file="$from_file$name "
544
+ fi
545
+ # A # after a space starts a comment, in a value with no quotes.
546
+ case $value in
547
+ \"* | \'*) ;;
548
+ \#*) value= ;;
549
+ *) value=${value%%[[:space:]]#*} ;;
550
+ esac
551
+ # Spaces after the value, then one pair of quotes around it.
552
+ value=${value%"${value##*[![:space:]]}"}
553
+ case $value in
554
+ \"*\") value=${value#\"}; value=${value%\"} ;;
555
+ \'*\') value=${value#\'}; value=${value%\'} ;;
556
+ esac
557
+ if [ "$name" = LINEAR_API_KEY ]; then
558
+ # Set for ocnus alone. -n also covers a key that came exported but
559
+ # empty, so that no program ocnus starts finds it either way.
560
+ LINEAR_API_KEY=$value
561
+ export -n LINEAR_API_KEY
562
+ elif [ "$name" = ANTHROPIC_API_KEY ]; then
563
+ SAVED_ANTHROPIC_KEY=$value
564
+ else
565
+ export "$name=$value"
566
+ fi
567
+ done < "$ENV_FILE"
568
+ }
569
+ load_env
570
+
571
+ APP_HOME=${HERDR_APP_HOME:-$HOME/.config/herdr-app}
572
+ # Where Claude Code looks for a person's own skills.
573
+ SKILLS_HOME=${CLAUDE_CONFIG_DIR:-$HOME/.claude}/skills
574
+ # Where Claude Code looks for a person's own agent definitions: the profiles
575
+ # `task new` and `task build` start claude with.
576
+ AGENTS_HOME=${CLAUDE_CONFIG_DIR:-$HOME/.claude}/agents
577
+ # Claude Code's own record for this machine. Among much else it holds the
578
+ # folders Claude Code starts in without asking.
579
+ CLAUDE_STATE=${CLAUDE_CONFIG_DIR:-$HOME}/.claude.json
580
+ BIN_DIR=$HOME/.local/bin
581
+ HERDR_INSTALL='curl -fsSL https://releases.herdr.dev/app/install.sh | sh'
582
+ # What `update` reinstalls when ocnus came from npm rather than a git clone.
583
+ NPM_SPEC=${OCNUS_NPM_SPEC:-@johngaynor/ocnus}
584
+
585
+ # The spaces, and the doc each one has: what the space is and what belongs
586
+ # in each repo. A machine set up before spaces were made in spaces/ keeps
587
+ # them in projects/, each with a PROJECT.md, for as long as it has no
588
+ # spaces/; nothing is moved.
589
+ if [ -d "$ENT_HOME/projects" ] && [ ! -e "$ENT_HOME/spaces" ]; then
590
+ SPACES=$ENT_HOME/projects SPACE_DOC=PROJECT.md
591
+ else
592
+ SPACES=$ENT_HOME/spaces SPACE_DOC=SPACE.md
593
+ fi
594
+ # The model and effort each agent profile runs on (settings.sh). Not the env
595
+ # file: a Herdr mod changes it, and the env file holds the Linear key.
596
+ SETTINGS=$ENT_HOME/settings.json
597
+ # What a new space starts from: SPACE.md, written to $SPACE_DOC.
598
+ TEMPLATE=$REPO/herdr/spaces/template
599
+ # A space's doc that still has this line has not been filled in.
600
+ TEMPLATE_MARK='<!-- ocnus:template -->'
601
+
602
+ # --- the rest of the CLI ----------------------------------------------------
603
+
604
+ # Sourced, so every file shares the settings above and each other's functions.
605
+ LIB=$REPO/cli/lib
606
+ for part in common guard links recipes trust settings space linear archive tests approval billing task finish close agents github merges handoff host commands; do
607
+ [ -f "$LIB/$part.sh" ] ||
608
+ { printf 'ocnus: %s is missing; reinstall ocnus\n' "$LIB/$part.sh" >&2; exit 1; }
609
+ # shellcheck source=/dev/null
610
+ . "$LIB/$part.sh"
611
+ done
612
+
613
+ # A worktree's copy runs only the commands that read, unless asked (guard.sh).
614
+ guard_worktree "$@"
615
+
616
+ case ${1:-help} in
617
+ install) shift; cmd_install "$@" ;;
618
+ update) shift; cmd_update "$@" ;;
619
+ status) shift; cmd_status "$@" ;;
620
+ space) shift; cmd_space "$@" ;;
621
+ task) shift; cmd_task "$@" ;;
622
+ linear) shift; cmd_linear "$@" ;;
623
+ profile) shift; cmd_profile "$@" ;;
624
+ tests) shift; cmd_tests "$@" ;;
625
+ approval) shift; cmd_approval "$@" ;;
626
+ billing) shift; cmd_billing "$@" ;;
627
+ host) shift; cmd_host "$@" ;;
628
+ help | -h | --help) usage ;;
629
+ *) usage >&2; exit 2 ;;
630
+ esac