@johngaynor/ocnus 2.0.1-next.9 → 2.0.1-next.94

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 (50) hide show
  1. package/README.md +655 -106
  2. package/cli/lib/agents.sh +85 -34
  3. package/cli/lib/asks.sh +837 -0
  4. package/cli/lib/banner.sh +249 -0
  5. package/cli/lib/brief.sh +375 -0
  6. package/cli/lib/chain.sh +501 -0
  7. package/cli/lib/close.sh +5 -3
  8. package/cli/lib/commands.sh +42 -3
  9. package/cli/lib/cost.sh +505 -0
  10. package/cli/lib/events.sh +485 -0
  11. package/cli/lib/finish.sh +30 -4
  12. package/cli/lib/github.sh +106 -26
  13. package/cli/lib/guard.sh +41 -10
  14. package/cli/lib/handoff.sh +279 -37
  15. package/cli/lib/host.sh +470 -475
  16. package/cli/lib/linear.sh +428 -34
  17. package/cli/lib/links.sh +10 -7
  18. package/cli/lib/merges.sh +129 -30
  19. package/cli/lib/progress.sh +301 -0
  20. package/cli/lib/sessions.sh +132 -0
  21. package/cli/lib/settings.sh +35 -19
  22. package/cli/lib/task.sh +170 -54
  23. package/cli/lib/tests.sh +302 -7
  24. package/cli/lib/usage.sh +204 -0
  25. package/cli/ocnus +323 -73
  26. package/herdr/README.md +1264 -268
  27. package/herdr/layouts/default.json +30 -11
  28. package/herdr/layouts/showcase.json +314 -0
  29. package/herdr/layouts/vibe.json +169 -0
  30. package/herdr/layouts/vibe.svg +41 -0
  31. package/herdr/mods/agent-settings/main.js +19 -7
  32. package/herdr/mods/card-list/main.js +658 -0
  33. package/herdr/mods/card-list/mod.json +1 -0
  34. package/herdr/mods/memory/main.js +128 -0
  35. package/herdr/mods/memory/mod.json +1 -0
  36. package/herdr/mods/memory/reading.js +88 -0
  37. package/herdr/mods/names/main.js +22 -4
  38. package/herdr/mods/needs-you/main.js +526 -0
  39. package/herdr/mods/needs-you/mod.json +1 -0
  40. package/herdr/mods/step-counts/main.js +281 -0
  41. package/herdr/mods/step-counts/mod.json +1 -0
  42. package/herdr/mods/usage/main.js +149 -0
  43. package/herdr/mods/usage/mod.json +1 -0
  44. package/package.json +1 -1
  45. package/prompts/task-new.md +1 -1
  46. package/skills/brief/SKILL.md +8 -0
  47. package/skills/sdlc-breakdown/SKILL.md +5 -5
  48. package/skills/sdlc-build/SKILL.md +7 -3
  49. package/skills/sdlc-pr/SKILL.md +2 -2
  50. package/skills/sdlc-review/SKILL.md +5 -5
package/cli/lib/github.sh CHANGED
@@ -8,15 +8,29 @@
8
8
  # GitHub is asked once a minute, however many cards wait, in however many
9
9
  # spaces and repos. The call names each worktree's repo, from its origin
10
10
  # (github_repo), and its branch, and asks for that branch's newest pull
11
- # request. Its answer is read by these rules (GITHUB_READ): only the newest
12
- # pull request counts, an open one that GitHub says conflicts with its
13
- # default branch is conflict, and one whose mergeable is still UNKNOWN,
14
- # while GitHub works that out, is open. Asking
15
- # GitHub sits here alone, so that another host, such as GitLab, can sit
16
- # beside it later.
11
+ # request, with whether it can be merged and what its checks came to. Its
12
+ # answer is read by these rules (GITHUB_READ): only the newest pull request
13
+ # counts, an open one that GitHub says conflicts with its default branch is
14
+ # conflict, and one whose mergeable is still UNKNOWN, while GitHub works
15
+ # that out, is open. An open one is ready to merge, ready, when GitHub says
16
+ # that it can be merged, MERGEABLE, and that every check on its newest
17
+ # commit passed: its statusCheckRollup, which sums up its check runs and
18
+ # commit statuses, is SUCCESS, or null, as for a pull request with no
19
+ # checks. It is open while a check is pending, and once one has failed. A
20
+ # review that the repo's rules ask for is not a check, so ready does not say
21
+ # that GitHub would let it merge. Asking GitHub sits here alone, so that
22
+ # another host, such as GitLab, can sit beside it later.
17
23
  #
18
24
  # `gh search prs` asks across repos too, but it cannot say whether an open
19
25
  # pull request is in conflict.
26
+ #
27
+ # `task answer` merges a card's pull requests here too, when the human
28
+ # answers its merge with merge (asks.sh). One call of the same shape asks
29
+ # what the merge of each needs (github_mergeable): whether GitHub would merge
30
+ # it as it stands, the commit at its head, and the method GitHub's merge
31
+ # button would use for the human in its repo. Then one mutation merges each
32
+ # (github_merge), by that method and only at that commit. Nothing else here
33
+ # changes anything on GitHub, and nothing turns on auto-merge.
20
34
 
21
35
  # The most worktrees one call asks about. More are asked about in calls of
22
36
  # this many, so the common case stays one call.
@@ -47,18 +61,28 @@ github_repo() {
47
61
  }
48
62
 
49
63
  # GitHub's answer to github_ask's call, read as one line for each branch it
50
- # asked about, p0 to p<$n - 1>, in order: merged, open, closed or conflict,
51
- # then the pull request's URL; none when the branch has none; or failed and
52
- # GitHub's words when it answered that repo with an error, such as one it
53
- # cannot find. A closed pull request is closed, whatever GitHub says of its
54
- # conflicts. An answer that is empty, or holds no data, is an error, so that
55
- # the whole call counts as failed.
64
+ # asked about, p0 to p<$n - 1>, in order: merged, ready, open, closed or
65
+ # conflict, then the pull request's URL; none when the branch has none; or
66
+ # failed and GitHub's words when it answered that repo with an error, such
67
+ # as one it cannot find. A closed pull request is closed, whatever GitHub
68
+ # says of its conflicts, and an open one is ready only when it can be merged
69
+ # and its checks passed, or it has none. An error that GitHub gives for a
70
+ # pull request's checks alone, as when gh's token may not read them, fails
71
+ # nothing: the pull request is read without them, so an open one is open,
72
+ # never ready, and a merged one is still merged. An answer that is empty, or
73
+ # holds no data, is an error, so that the whole call counts as failed. With
74
+ # $merge, the answer is github_mergeable's, and an open pull request's line
75
+ # is open, then GitHub's mergeStateStatus for it, the repo's
76
+ # viewerDefaultMergeMethod, the pull request's id, the commit at its head,
77
+ # and its URL: never ready or conflict, which mergeStateStatus says better.
56
78
  GITHUB_READ='input
57
79
  | if (.data | type) != "object" then error("no data") else . end
58
80
  | . as $all
59
81
  | ($all.errors // []) as $errors
60
82
  | range(0; $n) | "p\(.)" as $alias
61
- | ([$errors[] | select((.path // [])[0] == $alias) | .message] | first) as $own
83
+ | [$errors[] | select((.path // [])[0] == $alias)] as $mine
84
+ | ([$mine[] | select(any(.path[]; . == "statusCheckRollup") | not) | .message] | first) as $own
85
+ | any($mine[]; any(.path[]; . == "statusCheckRollup")) as $unchecked
62
86
  | $all.data[$alias] as $repo
63
87
  | if $own != null then "failed \($own)"
64
88
  elif $repo == null then "failed \(([$errors[] | .message] | first) // "GitHub gave no answer for it")"
@@ -66,7 +90,11 @@ GITHUB_READ='input
66
90
  | if $pr == null then "none"
67
91
  elif $pr.state == "MERGED" then "merged \($pr.url)"
68
92
  elif $pr.state == "CLOSED" then "closed \($pr.url)"
93
+ elif $merge then
94
+ "open \($pr.mergeStateStatus // "UNKNOWN") \($repo.viewerDefaultMergeMethod // "MERGE") \($pr.id // "-") \($pr.headRefOid // "-") \($pr.url)"
69
95
  elif $pr.state == "OPEN" and $pr.mergeable == "CONFLICTING" then "conflict \($pr.url)"
96
+ elif $pr.state == "OPEN" and $pr.mergeable == "MERGEABLE" and ($unchecked | not)
97
+ and ($pr.statusCheckRollup == null or $pr.statusCheckRollup.state == "SUCCESS") then "ready \($pr.url)"
70
98
  else "open \($pr.url)" end
71
99
  end
72
100
  | split("\r") | join(" ") | split("\n") | join(" ")'
@@ -83,19 +111,22 @@ GITHUB_CALL_WHY=''
83
111
  # or in calls of GITHUB_BATCH when more are given. Each line on stdin is a
84
112
  # key, which holds no space, the worktree, and its branch, with the unit
85
113
  # separator between them. It prints a line for each, in the same order:
86
- # <key> merged|open|closed|conflict <the pull request's URL>
114
+ # <key> merged|ready|open|closed|conflict <the pull request's URL>
87
115
  # <key> none the branch has no pull request
88
116
  # <key> failed <the worktree's folder>: <why>
89
- # A call that fails as a whole, such as with GitHub out of reach, fails
90
- # every line it asked about, with gh's words, which GITHUB_CALL_WHY keeps.
117
+ # ready is an open pull request that can be merged and whose checks passed
118
+ # (GITHUB_READ). A call that fails as a whole, such as with GitHub out of
119
+ # reach, fails every line it asked about, with gh's words, which
120
+ # GITHUB_CALL_WHY keeps.
91
121
  # GITHUB_SIGN_IN is 1 then when gh needs signing in: it exits 4 when it has
92
122
  # no sign-in (gh help exit-codes), and names HTTP 401 when GitHub refuses its
93
123
  # token. A repo that GitHub answers with an error fails only its own lines,
94
124
  # with GitHub's words, and a worktree whose origin is not on GitHub is not
95
- # asked about.
96
- # github_pulls <a folder for gh's answers>
125
+ # asked about. With merge, it asks what github_mergeable does instead.
126
+ # github_pulls <a folder for gh's answers> [merge]
97
127
  github_pulls() {
98
- local scratch=$1 sep=$'\x1f' key wt branch keys=() wts=() lines=() asks=() i n
128
+ local scratch=$1 merge=false sep=$'\x1f' key wt branch keys=() wts=() lines=() asks=() i n
129
+ [ "${2:-}" != merge ] || merge=true
99
130
  GITHUB_SIGN_IN=0 GITHUB_CALL_WHY=''
100
131
  while IFS=$sep read -r key wt branch; do
101
132
  [ -n "$key" ] || continue
@@ -109,7 +140,7 @@ github_pulls() {
109
140
  done
110
141
  [ "${#keys[@]}" -gt 0 ] || return 0
111
142
  for ((n = 0; n < ${#asks[@]}; n += GITHUB_BATCH)); do
112
- github_ask "$scratch" "${asks[@]:n:GITHUB_BATCH}"
143
+ github_ask "$scratch" "$merge" "${asks[@]:n:GITHUB_BATCH}"
113
144
  done
114
145
  for ((i = 0; i < ${#keys[@]}; i++)); do
115
146
  printf '%s %s\n' "${keys[i]}" "${lines[i]}"
@@ -123,17 +154,21 @@ github_pulls() {
123
154
  # variables, so that nothing in them is read as GraphQL. It sets
124
155
  # github_pulls's line for each, in its lines, reading its wts for the
125
156
  # worktree's folder, and GITHUB_SIGN_IN and GITHUB_CALL_WHY when the call
126
- # fails as a whole.
127
- # github_ask <a folder for gh's answers> <ask>...
157
+ # fails as a whole. The second argument is true for github_mergeable's call,
158
+ # which asks of each pull request what its merge needs, and of each repo the
159
+ # method GitHub's merge button would use for the human.
160
+ # github_ask <a folder for gh's answers> <true|false> <ask>...
128
161
  github_ask() {
129
- local scratch=$1 sep=$'\x1f' ask i owner name branch n=0 at=() args=() vars='' body='' code=0 why answer line
130
- shift
162
+ local scratch=$1 merge=$2 sep=$'\x1f' ask i owner name branch n=0 at=() args=() vars='' body='' code=0 why answer line
163
+ local fields='nodes { url state mergeable statusCheckRollup { state } } }'
164
+ [ "$merge" != true ] || fields='nodes { id url state mergeStateStatus headRefOid } } viewerDefaultMergeMethod'
165
+ shift 2
131
166
  for ask in "$@"; do
132
167
  IFS=$sep read -r i owner name branch <<< "$ask"
133
168
  at+=("$i")
134
169
  lines[i]="failed ${wts[i]##*/}: its answer could not be read"
135
170
  vars="$vars, \$o$n: String!, \$n$n: String!, \$b$n: String!"
136
- body="$body p$n: repository(owner: \$o$n, name: \$n$n) { pullRequests(headRefName: \$b$n, states: [OPEN, CLOSED, MERGED], first: 1, orderBy: {field: CREATED_AT, direction: DESC}) { nodes { url state mergeable } } }"
171
+ body="$body p$n: repository(owner: \$o$n, name: \$n$n) { pullRequests(headRefName: \$b$n, states: [OPEN, CLOSED, MERGED], first: 1, orderBy: {field: CREATED_AT, direction: DESC}) { $fields }"
137
172
  args+=(-f "o$n=$owner" -f "n$n=$name" -f "b$n=$branch")
138
173
  n=$((n + 1))
139
174
  done
@@ -141,7 +176,7 @@ github_ask() {
141
176
  # then exits 1, so the answer is read whatever gh exits with.
142
177
  gh api graphql -f "query=query(${vars#, }) {$body }" "${args[@]}" > "$scratch/answer" 2> "$scratch/err" ||
143
178
  code=$?
144
- if answer=$(jq -rn --argjson n "$n" "$GITHUB_READ" "$scratch/answer" 2>/dev/null); then
179
+ if answer=$(jq -rn --argjson n "$n" --argjson merge "$merge" "$GITHUB_READ" "$scratch/answer" 2>/dev/null); then
145
180
  n=0
146
181
  while IFS= read -r line; do
147
182
  [ "$n" -lt "${#at[@]}" ] || break
@@ -160,3 +195,48 @@ github_ask() {
160
195
  [ -n "$GITHUB_CALL_WHY" ] || GITHUB_CALL_WHY=${why:-gh failed}
161
196
  for i in "${at[@]}"; do lines[i]="failed ${wts[i]##*/}: ${why:-gh failed}"; done
162
197
  }
198
+
199
+ # Ask GitHub what the merge of each branch's newest pull request needs, in
200
+ # one call, as github_pulls asks for each one's state: the same lines on
201
+ # stdin, and the same lines printed, but for an open pull request, whose line
202
+ # is:
203
+ # <key> open <mergeStateStatus> <method> <id> <head commit> <URL>
204
+ # mergeStateStatus is GitHub's word for whether it would merge it as it
205
+ # stands: CLEAN, or HAS_HOOKS or UNSTABLE, which it merges too, or why not,
206
+ # as DIRTY for a conflict, BLOCKED for a required check or review, BEHIND,
207
+ # DRAFT, or UNKNOWN while it works that out. The method is the repo's
208
+ # viewerDefaultMergeMethod, the one GitHub's merge button would use for the
209
+ # human: MERGE, SQUASH or REBASE.
210
+ # github_mergeable <a folder for gh's answers>
211
+ github_mergeable() { github_pulls "$1" merge; }
212
+
213
+ # Merge one pull request, as GitHub's merge button does: by the method given,
214
+ # and only while the commit at its head is still the one given, so that a
215
+ # push since github_mergeable asked is not merged unseen. The id, the method
216
+ # and the commit are passed as variables, so that nothing in them is read as
217
+ # GraphQL. It succeeds only when GitHub answers that the pull request has
218
+ # merged. Else it fails, with why in GITHUB_MERGE_WHY: GitHub's own words
219
+ # when it refuses, as for a required check that has not passed, or gh's when
220
+ # the call fails. GitHub is asked for the merge as it stands and no more:
221
+ # nothing is forced past what protects the branch, and no auto-merge is
222
+ # turned on.
223
+ # github_merge <a folder for gh's answers> <the pull request's id> <MERGE|SQUASH|REBASE> <head commit>
224
+ GITHUB_MERGE_WHY=''
225
+ github_merge() {
226
+ local scratch=$1 state why
227
+ GITHUB_MERGE_WHY=''
228
+ # gh prints GitHub's answer even when it refuses, and then exits 1, so the
229
+ # answer is read whatever gh exits with.
230
+ gh api graphql \
231
+ -f 'query=mutation($id: ID!, $method: PullRequestMergeMethod!, $oid: GitObjectID!) { mergePullRequest(input: {pullRequestId: $id, mergeMethod: $method, expectedHeadOid: $oid}) { pullRequest { url state } } }' \
232
+ -f "id=$2" -f "method=$3" -f "oid=$4" > "$scratch/merged" 2> "$scratch/err" || true
233
+ state=$(jq -r '.data.mergePullRequest.pullRequest.state // empty' "$scratch/merged" 2>/dev/null) || state=''
234
+ [ "$state" != MERGED ] || return 0
235
+ why=$(jq -r '[.errors[]?.message | strings] | first // empty' "$scratch/merged" 2>/dev/null) || why=''
236
+ [ -n "$why" ] || why=$(sed -n '/[^[:space:]]/{p;q;}' "$scratch/err" 2>/dev/null) || why=''
237
+ [ -z "$state" ] ||
238
+ why="GitHub took the merge, but the pull request is still $state, as in a repo that merges through a queue"
239
+ why=${why//[[:cntrl:]]/ }
240
+ GITHUB_MERGE_WHY=${why:-gh failed}
241
+ return 1
242
+ }
package/cli/lib/guard.sh CHANGED
@@ -33,24 +33,47 @@ is_worktree_copy() {
33
33
  # read. Each of these leaves the machine as it was, the hand-off store
34
34
  # included; `task ls` asks Linear, and only reads. `task merges` asks
35
35
  # GitHub, but it records the merges it sees and moves their cards in Linear,
36
- # so it is not a read and is not here.
36
+ # so it is not a read and is not here. `task asks` reads the questions that
37
+ # wait on the human, from the store, the files beside it and hc. `task
38
+ # events` reads a card's steps from the store and what its agents did from
39
+ # the transcripts Claude Code keeps, and writes nothing. `task
40
+ # answer` types into an agent's terminal or merges pull requests on GitHub,
41
+ # and `task hold`, the hook behind a permission prompt, writes its question
42
+ # and can allow a tool, so neither is a read. Nor is `task brief`, though it
43
+ # leaves the agent and its card alone: a new brief is a model call, paid for
44
+ # on the human's account, and it writes the brief it keeps into the store.
37
45
  # `profile ls` reads the settings file; `profile set` changes it,
38
46
  # and the review subagents in Claude Code's agents folder. `linear archive`
39
47
  # alone, or with --json, reads whether archiving is on; with on or off it
40
48
  # changes the settings file. `tests` alone, or with --json, reads how the
41
49
  # test runs use the processors; with share or queue it changes the settings
42
- # file too.
50
+ # file too. `tests ls`, alone or with --json, reads the test runs going from
51
+ # the pool test/run.sh keeps, and removes nothing from it, not even an entry
52
+ # whose process has gone.
43
53
  # `approval` alone, or with --json, reads whether the breakdown approval is
44
54
  # on; with --breakdown on or off it changes the settings file. `billing`
45
55
  # alone, or with --json, reads which account the agents run on, and whether
46
56
  # an Anthropic key is saved; with api or subscription it changes the
47
57
  # settings file, and with key the env file. `billing key --print` changes
48
58
  # nothing, but it prints the saved key, so it is not a read either: it is for
49
- # an agent's apiKeyHelper, which runs the copy that started the agent. `host`
59
+ # an agent's apiKeyHelper, which runs the copy that started the agent. `chain`
60
+ # alone, or with --json, reads whether the chain is on; with on or off it
61
+ # changes the settings file. `task ready` starts cards, as `task start`
62
+ # does, so it is not a read.
63
+ # `usage` alone, or with --json, reads the last reading of the Claude usage
64
+ # limits, and with billing on api what the agents spent, from the cost file;
65
+ # `usage record` writes the reading, and with an agent's space, card, phase
66
+ # and account after it the cost file too, so it is refused with the words or
67
+ # without, and is for an agent's statusLine. `task log` reads the cost file
68
+ # beside the store, both read-only. `host`
50
69
  # alone says whether the host is recorded, and `host report` reads its
51
- # readings; `host on` and `host off` make and delete them, and `host record`
52
- # writes them.
70
+ # readings: alone, with a period, or as `host report --card <space> <card>
71
+ # --json`, a card's readings, which is six words with --card and --json
72
+ # among them. Any other number of words is refused, as `host report 7d 1h`
73
+ # is. `host on` and `host off` make and delete the readings, and `host
74
+ # record` writes them.
53
75
  is_read() {
76
+ local word card=0 json=0
54
77
  case ${1:-help} in
55
78
  help | -h | --help | status) return 0 ;;
56
79
  space)
@@ -78,11 +101,12 @@ is_read() {
78
101
  tests)
79
102
  case $# in
80
103
  1) return 0 ;;
81
- 2) [ "$2" = --json ] ;;
104
+ 2) [ "$2" = --json ] || [ "$2" = ls ] ;;
105
+ 3) [ "$2" = ls ] && [ "$3" = --json ] ;;
82
106
  *) return 1 ;;
83
107
  esac
84
108
  ;;
85
- approval | billing)
109
+ approval | billing | chain | usage)
86
110
  case $# in
87
111
  1) return 0 ;;
88
112
  2) [ "$2" = --json ] ;;
@@ -91,14 +115,21 @@ is_read() {
91
115
  ;;
92
116
  task)
93
117
  case ${2:-} in
94
- ls | list | log) return 0 ;;
118
+ ls | list | log | asks | events) return 0 ;;
95
119
  *) return 1 ;;
96
120
  esac
97
121
  ;;
98
122
  host)
99
123
  case ${2:-} in
100
124
  '') [ "$#" -le 1 ] ;;
101
- report) [ "$#" -le 3 ] ;;
125
+ report)
126
+ [ "$#" -gt 3 ] || return 0
127
+ [ "$#" -eq 6 ] || return 1
128
+ for word in "${@:3}"; do
129
+ case $word in --card) card=1 ;; --json) json=1 ;; esac
130
+ done
131
+ [ "$card$json" = 11 ]
132
+ ;;
102
133
  *) return 1 ;;
103
134
  esac
104
135
  ;;
@@ -126,7 +157,7 @@ guard_worktree() {
126
157
  [ "${OCNUS_LIVE:-}" != 1 ] || return 0
127
158
  GUARDED=1
128
159
  ! is_read "$@" || return 0
129
- die "this is the copy of ocnus in the worktree $REPO. It runs only the commands that read (help, status, space ls, space team <name>, profile ls, linear archive, tests, approval, billing, task ls, task log, host and host report), so \`$(shell_words "$@")\` was not run: it could change this machine's Herdr, spaces and tasks, hand-offs, host readings, Linear key or cards, or Claude Code's skills, agents and trust file.
160
+ die "this is the copy of ocnus in the worktree $REPO. It runs only the commands that read (help, status, space ls, space team <name>, profile ls, linear archive, tests, tests ls, approval, billing, chain, usage, task ls, task log, task asks, task events, host and host report), so \`$(shell_words "$@")\` was not run: it could change this machine's Herdr, spaces and tasks, hand-offs, host readings, Linear key or cards, or Claude Code's skills, agents and trust file.
130
161
  - For the card's own steps, such as recording a hand-off, run plain \`ocnus\`: the copy this machine runs, not this one.
131
162
  - To try a command that changes the machine, write a test case for it, in test/.
132
163
  - To run it on this machine for real, only when that is wanted: