@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,343 @@
1
+ # Spaces: groups of repos, each of which opens in Herdr as one space. Sourced
2
+ # by cli/ocnus.
3
+
4
+ # A space is a folder in $SPACES:
5
+ # SPACE.md what the space is and what belongs in each repo ($SPACE_DOC:
6
+ # PROJECT.md on a machine set up before, see cli/ocnus)
7
+ # repos one repo path per line (~/ for the home folder, # for comments)
8
+ # teams the keys of the space's Linear teams, like ABC, one per line
9
+ # links/ generated: a link to each repo, named after its folder
10
+ # CLAUDE.md, AGENTS.md generated: links to the doc, so agents read it
11
+
12
+ valid_name() { case ${1:-} in '' | *[!a-z0-9-]*) return 1 ;; esac; }
13
+
14
+ # Print a space's folder, or stop if there is no such space.
15
+ space_dir() {
16
+ local name=${1:-}
17
+ [ -n "$name" ] || die "which space? See: ocnus space ls"
18
+ valid_name "$name" && [ -d "$SPACES/$name" ] ||
19
+ die "no space called '$name'. Make it with: ocnus space new $name"
20
+ (cd -P "$SPACES/$name" && pwd)
21
+ }
22
+
23
+ # Mark a space's folder as trusted by Claude Code (see trust.sh), when
24
+ # ocnus made it: a folder of its own in $SPACES. A space name that is
25
+ # a link leads to a folder someone else made, perhaps a repo, and ocnus
26
+ # does not answer for that. Claude Code asks about it itself, once.
27
+ trust_space() {
28
+ local name=$1
29
+ [ ! -L "$SPACES/$name" ] || return 0
30
+ # The real path, which is what Claude Code looks up: $SPACES may run
31
+ # through a link.
32
+ trust_folder "$(space_dir "$name")"
33
+ }
34
+
35
+ # Print a space's repo paths, absolute, one per line.
36
+ space_repos() {
37
+ local dir=$1 line
38
+ [ -f "$dir/repos" ] || return 0
39
+ while IFS= read -r line || [ -n "$line" ]; do
40
+ case $line in
41
+ '' | '#'*) continue ;;
42
+ '~/'*) line=$HOME/${line#'~/'} ;;
43
+ esac
44
+ printf '%s\n' "$line"
45
+ done < "$dir/repos"
46
+ }
47
+
48
+ is_repo() { [ -e "$1/.git" ]; }
49
+
50
+ # Rebuild what is generated in a space folder. Only links are ever removed
51
+ # or replaced; a real file in the way is reported and left alone.
52
+ sync_links() {
53
+ local dir=$1 src dst base names=$'\n'
54
+ mkdir -p "$dir/links"
55
+ while IFS= read -r src; do
56
+ base=${src##*/}
57
+ dst=$dir/links/$base
58
+ names+=$base$'\n'
59
+ is_repo "$src" || say " warning: $src is missing or is not a git repo"
60
+ if [ -L "$dst" ]; then
61
+ [ "$(readlink "$dst")" = "$src" ] || { rm "$dst"; ln -s "$src" "$dst"; }
62
+ elif [ -e "$dst" ]; then
63
+ say " skipped links/$base (a real file is in the way)"
64
+ else
65
+ ln -s "$src" "$dst"
66
+ fi
67
+ done < <(space_repos "$dir")
68
+ for dst in "$dir"/links/*; do
69
+ [ -L "$dst" ] || continue
70
+ case $names in *$'\n'"${dst##*/}"$'\n'*) ;; *) rm "$dst" ;; esac
71
+ done
72
+ for base in CLAUDE.md AGENTS.md; do
73
+ [ -e "$dir/$base" ] || [ -L "$dir/$base" ] || ln -s "$SPACE_DOC" "$dir/$base"
74
+ done
75
+ }
76
+
77
+ # Print the real folder of the repo a path names, or stop if it is not one.
78
+ repo_at() {
79
+ local path=$1 abs
80
+ [ -d "$path" ] || die "$path is not a folder"
81
+ abs=$(cd "$path" && pwd -P)
82
+ is_repo "$abs" || die "$abs is not a git repo (the top folder of a clone is needed)"
83
+ printf '%s\n' "$abs"
84
+ }
85
+
86
+ # Add a line for a repo to a space's repos file, with ~/ for the home folder.
87
+ store_repo() {
88
+ local dir=$1 abs=$2
89
+ case $abs in
90
+ "$HOME"/*) abs="~/${abs#"$HOME"/}" ;;
91
+ esac
92
+ printf '%s\n' "$abs" >> "$dir/repos"
93
+ }
94
+
95
+ # With repo paths after the name, the space starts with those repos. The
96
+ # ocnus-spaces mod makes a space this way, in one command.
97
+ space_new() {
98
+ local name=${1:-} dir path abs other
99
+ local -a repos=()
100
+ valid_name "$name" || die "a space name is lowercase letters, digits and dashes, like: my-space"
101
+ dir=$SPACES/$name
102
+ [ ! -e "$dir" ] || die "space '$name' already exists at $dir"
103
+ [ -f "$TEMPLATE/SPACE.md" ] || die "the space template is missing from $TEMPLATE"
104
+ shift
105
+ # Every repo is checked before anything is made, so that a bad one does not
106
+ # leave a space behind with only some of them.
107
+ for path in "$@"; do
108
+ abs=$(repo_at "$path")
109
+ for other in ${repos[@]+"${repos[@]}"}; do
110
+ [ "$other" != "$abs" ] || die "$abs is listed twice"
111
+ [ "${other##*/}" != "${abs##*/}" ] ||
112
+ die "$other and $abs are both called ${abs##*/}; two repos in a space cannot share a folder name"
113
+ done
114
+ repos+=("$abs")
115
+ done
116
+ mkdir -p "$dir"
117
+ sed "s/__NAME__/$name/" "$TEMPLATE/SPACE.md" > "$dir/$SPACE_DOC"
118
+ : > "$dir/repos"
119
+ for abs in ${repos[@]+"${repos[@]}"}; do store_repo "$dir" "$abs"; done
120
+ sync_links "$dir"
121
+ trust_space "$name"
122
+ say "Made space '$name' at $dir"
123
+ for abs in ${repos[@]+"${repos[@]}"}; do say " added ${abs##*/}"; done
124
+ say "Next:"
125
+ [ "${#repos[@]}" -gt 0 ] || say " ocnus space add $name <path to a repo>"
126
+ say " fill in $dir/$SPACE_DOC"
127
+ say " ocnus space open $name"
128
+ }
129
+
130
+ space_add() {
131
+ local name=${1:-} path=${2:-} dir abs other
132
+ dir=$(space_dir "$name")
133
+ [ -n "$path" ] || die "which repo? Usage: ocnus space add $name <path>"
134
+ abs=$(repo_at "$path")
135
+ while IFS= read -r other; do
136
+ [ "$other" != "$abs" ] || die "$abs is already in space '$name'"
137
+ [ "${other##*/}" != "${abs##*/}" ] ||
138
+ die "space '$name' already has a repo called ${abs##*/} ($other); two repos in a space cannot share a folder name"
139
+ done < <(space_repos "$dir")
140
+ store_repo "$dir" "$abs"
141
+ sync_links "$dir"
142
+ say "Added ${abs##*/} to space '$name'"
143
+ say "Describe what it owns in $dir/$SPACE_DOC"
144
+ }
145
+
146
+ # Print the id of the open Herdr space that holds a terminal herdr-core labels
147
+ # with the space, or fail when there is none. That is the space the app made
148
+ # of an agent's herdr.space label, for an agent `task new` or `task start`
149
+ # started with the app closed: its folder is where the agent's terminal
150
+ # started, which is not the space's folder for a task's agent. The space's
151
+ # terminals are listed by hc and found in the tabs of `herdr-app ls`, whose
152
+ # output is given. This needs jq.
153
+ # space_of_terminals <space> <what herdr-app ls printed>
154
+ space_of_terminals() {
155
+ local name=$1 listed=$2 terms
156
+ command -v jq >/dev/null 2>&1 && [ -n "$listed" ] || return 1
157
+ terms=$(hc_cmd ls --json --label "ocnus.space=$name" 2>/dev/null |
158
+ jq -c '[.terminals[]? | .address | strings]' 2>/dev/null) && [ -n "$terms" ] || return 1
159
+ printf '%s' "$listed" | jq -er --argjson terms "$terms" '
160
+ first(.spaces[]? | select(any(.tabs[]?.terminals[]?.terminal; . as $t | any($terms[]; . == $t)))
161
+ | .id | strings)' 2>/dev/null
162
+ }
163
+
164
+ # Show a space in Herdr, making Herdr's space for it if it is not open.
165
+ show_space() {
166
+ local name=$1 dir=$2 listed id
167
+ listed=$(herdr_app ls 2>/dev/null) || true
168
+ # Find an open Herdr space whose folder is this space's. `herdr-app ls`
169
+ # prints indented JSON; a Herdr space's own "id" and "folder" are indented
170
+ # six columns. Closed ones are listed after "recent" in the same shape, so
171
+ # stop there.
172
+ id=$(printf '%s\n' "$listed" | awk -v want="$dir" '
173
+ /^ "recent"/ { exit }
174
+ /^ "id": / { id = $2; gsub(/[",]/, "", id) }
175
+ /^ "folder": / { f = $0; sub(/^ *"folder": "/, "", f); sub(/",?$/, "", f)
176
+ if (f == want) { print id; exit } }') || true
177
+ # Else the one holding the space's agents, which the app took in from
178
+ # herdr-core, so that the space does not get a second one.
179
+ [ -n "$id" ] || id=$(space_of_terminals "$name" "$listed") || id=''
180
+ if [ -n "$id" ]; then
181
+ herdr_app do space.select "{\"id\":\"$id\"}" >/dev/null 2>&1 ||
182
+ die "could not show the space for '$name'. Is Herdr open?"
183
+ say "Showing the space for '$name'"
184
+ else
185
+ herdr_app do space.new "{\"name\":\"$name\",\"folder\":\"$dir\"}" >/dev/null 2>&1 ||
186
+ die "could not make a space for '$name'. Is Herdr open?"
187
+ say "Opened a space for '$name' in $dir"
188
+ fi
189
+ }
190
+
191
+ # Showing a space needs the app's window. With it closed, nothing is changed:
192
+ # not even the links, which the next open makes again.
193
+ space_open() {
194
+ local name=${1:-} dir
195
+ dir=$(space_dir "$name")
196
+ require_herdr
197
+ herdr_running ||
198
+ die "the Herdr app is not open, so there is no window to show space '$name' in. Open Herdr, then run this again."
199
+ sync_links "$dir"
200
+ show_space "$name" "$dir"
201
+ }
202
+
203
+ # The same list for programs: one line of JSON, under the key spaces, each
204
+ # space with its folder (as space_dir prints it) and its repos. The
205
+ # ocnus-spaces, cards and steps mods read this.
206
+ space_ls_json() {
207
+ local d repo sep='' rsep
208
+ printf '{"spaces":['
209
+ for d in "$SPACES"/*/; do
210
+ [ -d "$d" ] || continue
211
+ d=${d%/}
212
+ printf '%s{"name":"%s","folder":"%s","repos":[' "$sep" \
213
+ "$(json_str "${d##*/}")" "$(json_str "$(cd -P "$d" && pwd)")"
214
+ rsep=''
215
+ while IFS= read -r repo; do
216
+ printf '%s"%s"' "$rsep" "$(json_str "$repo")"
217
+ rsep=,
218
+ done < <(space_repos "$d")
219
+ printf ']}'
220
+ sep=,
221
+ done
222
+ printf ']}\n'
223
+ }
224
+
225
+ space_ls() {
226
+ local d any=0 repo
227
+ case ${1:-} in
228
+ --json) space_ls_json; return ;;
229
+ '') ;;
230
+ *) die "unknown option for space ls: $1" ;;
231
+ esac
232
+ for d in "$SPACES"/*/; do
233
+ [ -d "$d" ] || continue
234
+ any=1
235
+ d=${d%/}
236
+ say "${d##*/}"
237
+ while IFS= read -r repo; do say " $repo"; done < <(space_repos "$d")
238
+ done
239
+ [ "$any" = 1 ] || say "No spaces yet. Make one with: ocnus space new <name>"
240
+ }
241
+
242
+ # A team's key is what its cards' IDs start with: ABC for ABC-122.
243
+ TEAM_RE='^[A-Za-z][A-Za-z0-9]*$'
244
+
245
+ # Print a space's Linear teams, one key per line in upper case, each once,
246
+ # or nothing when it has none. The file is the human's to edit, so a # starts
247
+ # a comment anywhere on a line, and white space and blank lines are skipped.
248
+ # A line that is still not a team key stops it, naming the line, before
249
+ # anything is printed: a typo here would otherwise read as a team Linear does
250
+ # not have.
251
+ space_teams() {
252
+ local dir=$1 line n=0 keys=''
253
+ [ -f "$dir/teams" ] || return 0
254
+ # Not read, it would pass for a space with no team.
255
+ [ -r "$dir/teams" ] || die "cannot read $dir/teams. Check its owner and permissions, then run this again."
256
+ while IFS= read -r line || [ -n "$line" ]; do
257
+ n=$((n + 1))
258
+ # The mark some editors put at the start of a file.
259
+ line=${line#$'\357\273\277'}
260
+ line=${line%%#*}
261
+ line=${line#"${line%%[![:space:]]*}"}
262
+ line=${line%"${line##*[![:space:]]}"}
263
+ [ -n "$line" ] || continue
264
+ [[ $line =~ $TEAM_RE ]] ||
265
+ die "line $n of $dir/teams is '$line', which is not a Linear team key. A team's key is what its cards' IDs start with: ABC for ABC-122."
266
+ keys+=$line$'\n'
267
+ done < "$dir/teams"
268
+ [ -n "$keys" ] || return 0
269
+ printf '%s' "$keys" | tr '[:lower:]' '[:upper:]' | awk '!seen[$0]++'
270
+ }
271
+
272
+ # Set the Linear teams whose cards are a space's, or print them when no key
273
+ # is given. `task ls` lists those teams' cards. A space can name several
274
+ # teams, and several spaces can name the same team. The keys given replace
275
+ # the ones there. They are not checked with Linear here, so teams can be set
276
+ # with no network and before a Linear key is saved.
277
+ space_team() {
278
+ local name=${1:-} dir key keys='' teams
279
+ dir=$(space_dir "$name")
280
+ shift
281
+ if [ "$#" -eq 0 ]; then
282
+ teams=$(space_teams "$dir") || exit 1
283
+ [ -n "$teams" ] ||
284
+ die "space '$name' has no Linear team. Set it with: ocnus space team $name <team key>, like: ocnus space team $name ABC"
285
+ say "$teams"
286
+ return
287
+ fi
288
+ # Every key is checked before the file is written, so a bad one does not
289
+ # leave the space with only some of its teams.
290
+ for key in "$@"; do
291
+ [[ $key =~ $TEAM_RE ]] ||
292
+ die "'$key' is not a Linear team key. A team's key is what its cards' IDs start with: ABC for ABC-122."
293
+ key=$(printf '%s' "$key" | tr '[:lower:]' '[:upper:]')
294
+ case $'\n'$keys in *$'\n'"$key"$'\n'*) continue ;; esac
295
+ keys+=$key$'\n'
296
+ done
297
+ printf '%s' "$keys" > "$dir/teams"
298
+ say "Space '$name' lists the cards of: $(printf '%s' "$keys" | tr '\n' ' ' | sed 's/ $//')"
299
+ }
300
+
301
+ # Print what is wrong with each space; return how many problems there are.
302
+ check_spaces() {
303
+ local d repo problems=0 bad
304
+ for d in "$SPACES"/*/; do
305
+ [ -d "$d" ] || continue
306
+ d=${d%/}
307
+ bad=0
308
+ if [ ! -f "$d/$SPACE_DOC" ]; then
309
+ say " problem ${d##*/}: $SPACE_DOC is missing"; bad=$((bad + 1))
310
+ elif grep -qF -- "$TEMPLATE_MARK" "$d/$SPACE_DOC"; then
311
+ say " problem ${d##*/}: $SPACE_DOC is still the template; fill it in and delete its first line"; bad=$((bad + 1))
312
+ fi
313
+ while IFS= read -r repo; do
314
+ is_repo "$repo" || { say " problem ${d##*/}: $repo is missing or is not a git repo"; bad=$((bad + 1)); }
315
+ done < <(space_repos "$d")
316
+ [ "$bad" -gt 0 ] || say " ok ${d##*/}"
317
+ # Notes say what a repo does not provide. They are not problems: a task
318
+ # in the space still starts, only without that step.
319
+ if have_just; then
320
+ while IFS= read -r repo; do
321
+ is_repo "$repo" || continue
322
+ case $(recipe_state "$repo" setup) in
323
+ no-justfile) say " note ${d##*/}: ${repo##*/} has no justfile, so tasks start without setup" ;;
324
+ no-recipe) say " note ${d##*/}: ${repo##*/}'s justfile has no setup recipe" ;;
325
+ unreadable) say " note ${d##*/}: ${repo##*/}'s justfile could not be read by just" ;;
326
+ esac
327
+ done < <(space_repos "$d")
328
+ fi
329
+ problems=$((problems + bad))
330
+ done
331
+ return "$problems"
332
+ }
333
+
334
+ cmd_space() {
335
+ case ${1:-} in
336
+ new) shift; space_new "$@" ;;
337
+ add) shift; space_add "$@" ;;
338
+ open) shift; space_open "$@" ;;
339
+ ls | list) shift; space_ls "$@" ;;
340
+ team) shift; space_team "$@" ;;
341
+ *) die "usage: ocnus space new|add|open|ls|team (see: ocnus help)" ;;
342
+ esac
343
+ }