@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
@@ -0,0 +1,501 @@
1
+ # The chain: starting each card once the cards that block it are done.
2
+ # Sourced by cli/ocnus.
3
+
4
+ # sdlc-breakdown records in Linear the cards a card needs merged first, as its
5
+ # blockers, and `task start` holds a card while one of them is not done
6
+ # (task.sh). The chain is what starts a held card once they all are, so that
7
+ # the human does not have to come back and run `task start` again. It runs at
8
+ # two points:
9
+ #
10
+ # - At a merge. Once ocnus's watch on the merges has recorded a card's
11
+ # merge and finished its task (merge_record in merges.sh), merge_chain
12
+ # asks Linear once for the cards that card was blocking, and starts each
13
+ # one that is ready.
14
+ # - At the catch-up. A start can be missed at the merge: `task start`
15
+ # stopped, Linear could not be asked, the chain was off, or the last
16
+ # blocker was closed some other way, such as by hand in Linear. So `ocnus
17
+ # task ready <space>` asks Linear for every card of the space's teams that
18
+ # waits, and starts each one that is ready (ready_cards). The human can
19
+ # run it, and the watch runs it for every space once the last catch-up is
20
+ # READY_EVERY seconds old (merges.sh).
21
+ #
22
+ # A card is ready when it is in a not-started status, such as Todo, which is
23
+ # where the approval puts it; its team is in a space's teams; its description
24
+ # has a Specification and a Plan; and every card that blocks it, or the card
25
+ # it was sliced from, is in a completed status. A blocker that was canceled
26
+ # is not completed, so it still holds the card. A ready card starts with
27
+ # `task start <space> <card>`, the command the human would run, so it gets
28
+ # what any card gets: a branch cut from each repo's default branch as it is on
29
+ # origin now, which is after the merge, a tab that runs its build phase, and a
30
+ # start row. A ready card that was sliced starts through its first sub-issue
31
+ # that is not started, done or canceled, as sdlc-breakdown picks one.
32
+ #
33
+ # Every other card that waits is named, with why it was not started. At a
34
+ # merge, each start and each card not started goes on the merge's flags, so
35
+ # that `task log` shows them (merge_record).
36
+ #
37
+ # At a merge, the watch also tells the human, on the card in Linear, about a
38
+ # card the merge freed in part that another card still holds (chain_tell):
39
+ #
40
+ # - A card that a card not done yet still blocks, itself or the card it was
41
+ # sliced from, gets a comment naming each one, and saying the watch starts
42
+ # it once they are done.
43
+ # - A card that a canceled card blocks can never start by itself, since a
44
+ # canceled card is never done. The comment asks the human what to do:
45
+ # remove the relation in Linear, then start the card, or cancel it. The
46
+ # same question is recorded as a hand-off of the card's, start
47
+ # needs-human, so that `task log`, `task asks` and the Cards panel show
48
+ # the card waiting on the human (agents.sh). The card starting, which
49
+ # records its start, or the human's answer, which `task answer` records
50
+ # as start answered (asks.sh), ends the wait.
51
+ #
52
+ # Nothing removes a relation: ocnus has no way to. The catch-up comments on
53
+ # nothing and records nothing, so that a card that waits is not told the same
54
+ # every half hour.
55
+ #
56
+ # The chain is on unless the settings file says "chain": false (settings.sh),
57
+ # which `ocnus chain off` writes. Off, the watch starts no card, at a merge
58
+ # or at a catch-up. `task ready` starts the ready cards whatever the setting
59
+ # says, since the human ran it.
60
+
61
+ # What `chain` takes after it.
62
+ TAKES_CHAIN='on or off, or nothing to say whether the chain is on (--json for programs)'
63
+
64
+ # --- the setting ------------------------------------------------------------
65
+
66
+ # ocnus chain [on|off|--json]: say whether the chain is on, or turn it on
67
+ # or off. --json prints it as one line for programs, with the file it is kept
68
+ # in, for a Herdr mod. on and off write "chain" into the settings file as
69
+ # archive_set writes "archive": everything is checked before the file is
70
+ # touched, and the new file is checked before it takes the old one's place,
71
+ # so a refusal or a failure leaves the file as it was.
72
+ cmd_chain() {
73
+ local usage="usage: ocnus chain [on|off|--json]: it takes $TAKES_CHAIN"
74
+ case $# in
75
+ 0) chain_show plain ;;
76
+ 1)
77
+ case $1 in
78
+ --json) chain_show json ;;
79
+ on) chain_set true ;;
80
+ off) chain_set false ;;
81
+ *) die "'$1' is not on or off. ocnus chain takes $TAKES_CHAIN." ;;
82
+ esac
83
+ ;;
84
+ *) die "$usage" ;;
85
+ esac
86
+ }
87
+
88
+ # Say whether the chain is on: plain, for a person, or json, for programs.
89
+ chain_show() {
90
+ need_jq
91
+ settings_check
92
+ if [ "$1" = json ]; then
93
+ printf '{"file":"%s","chain":%s}\n' "$(json_str "$SETTINGS")" "$SET_CHAIN"
94
+ elif [ "$SET_CHAIN" = true ]; then
95
+ say "The chain is on: once ocnus's watch has recorded a card's merge, it starts each card that card was blocking that is ready. A card is ready when it is in Todo, has a Specification and a Plan, and every card that blocks it is done."
96
+ say "Every half hour, the watch also starts the ready cards a merge did not start. To start them now: ocnus task ready <space>"
97
+ say "Turn it off with: ocnus chain off"
98
+ else
99
+ say "The chain is off: ocnus's watch starts no card. A card that task start held waits in Todo until you start it."
100
+ say "To start the cards that are ready: ocnus task ready <space>"
101
+ say "Turn it on with: ocnus chain on"
102
+ fi
103
+ }
104
+
105
+ # Write "chain": true or false into the settings file. With no file yet, the
106
+ # new one starts from the defaults, so that it names every profile.
107
+ chain_set() {
108
+ local want=$1 tmp ok=0
109
+ need_jq
110
+ settings_check
111
+ mkdir -p "${SETTINGS%/*}"
112
+ tmp=$SETTINGS.ocnus.$$
113
+ if { if [ -e "$SETTINGS" ]; then cat "$SETTINGS"; else settings_default; fi; } |
114
+ jq --argjson on "$want" '.chain = $on' > "$tmp" 2>/dev/null &&
115
+ [ "$(SETTINGS=$tmp; settings_load && printf '%s' "$SET_CHAIN")" = "$want" ] &&
116
+ mv -f "$tmp" "$SETTINGS"; then
117
+ ok=1
118
+ fi
119
+ rm -f "$tmp"
120
+ [ "$ok" = 1 ] || die "could not change $SETTINGS, so it is as it was."
121
+ settings_check
122
+ if [ "$want" = true ]; then
123
+ say "The chain is on now. Once ocnus's watch has recorded a card's merge, it starts each card that card was blocking that is ready, and every half hour it starts the ready cards a merge did not start."
124
+ else
125
+ say "The chain is off now. ocnus's watch starts no card: a card that task start held waits in Todo until you start it, or run: ocnus task ready <space>"
126
+ fi
127
+ }
128
+
129
+ # --- which cards are ready --------------------------------------------------
130
+
131
+ # Every space's Linear teams, as one line of JSON: each team's key, and the
132
+ # spaces that list it, in the order of their names.
133
+ # {"ABC":["demo"],"XYZ":["shop","web"]}
134
+ # A space whose teams file cannot be read lists none here, and space_teams
135
+ # has said why on stderr.
136
+ chain_teams() {
137
+ local d name keys key lines=''
138
+ for d in "$SPACES"/*/; do
139
+ [ -d "$d" ] || continue
140
+ d=${d%/}
141
+ name=${d##*/}
142
+ valid_name "$name" || continue
143
+ keys=$(space_teams "$d") || continue
144
+ for key in $keys; do lines+=$key$'\t'$name$'\n'; done
145
+ done
146
+ printf '%s' "$lines" | jq -Rcn '[inputs | split("\t")] | reduce .[] as $l ({}; .[$l[0]] += [$l[1]])'
147
+ }
148
+
149
+ # Judge each card that waits, from {cards}, as linear_blocks and
150
+ # linear_waiting print them (CHAIN_DEFS in linear.sh), on stdin. $teams is
151
+ # what chain_teams prints, and $home the space to start a card in when its
152
+ # teams hold the card's team, or '' when there is none. $merged is the card
153
+ # whose merge freed them, or '' at the catch-up. It prints a line for each
154
+ # card that is ready and each that is not, its fields separated by the unit
155
+ # separator:
156
+ # start <card> <the card to start> <its space>
157
+ # skip <card> <> <> <why it was not started>
158
+ # skip <card> <> <its space> <why> <held> <comment> <question> <options>
159
+ # The card to start is the card itself, or its first open slice when it was
160
+ # sliced. A card that is started, done or canceled already does not wait, so
161
+ # it gets no line; neither does a sliced card with every slice started or
162
+ # closed.
163
+ #
164
+ # A card that another card still blocks is held: open when each of them is
165
+ # not done yet, and canceled when one of them was canceled, which no merge
166
+ # will ever make done. At a merge, a held card's line has what chain_tell
167
+ # says of it, each on one line: the comment to make on it, and for a card
168
+ # a canceled card holds, the question to ask the human and its options. They
169
+ # name the command that starts it once the relation is gone: `task start`,
170
+ # of the card itself, or of its first open slice when it was sliced.
171
+ #
172
+ # The space is $home when its teams hold the card's team, or else the one
173
+ # space that lists the team. A card's team is what its ID starts with. The
174
+ # checks come in the order the reasons are worth giving: a card that is not
175
+ # approved is not looked at any further.
176
+ #
177
+ # A slice's own blockers are not read with the card it was sliced from, since
178
+ # Linear caps what one question may cost: `task start` reads them, and holds
179
+ # the slice while one is not done. A slice that waits in its own right is a
180
+ # card here too, with its blockers and a line of its own, and chain_start
181
+ # goes by that line.
182
+ CHAIN_VERDICTS='
183
+ def lacks: if (.spec or .plan) | not then "no Specification and no Plan"
184
+ elif .spec | not then "no Specification"
185
+ elif .plan | not then "no Plan"
186
+ else null end;
187
+ def in_status: if .status == "" then "in a status ocnus could not read" else "in \(.status)" end;
188
+ def over: .type == "started" or .type == "completed" or .type == "canceled";
189
+ def blocks($card): "\(.id), \(in_status), still blocks "
190
+ + (if .of == $card then "it" else "\(.of), the card it was sliced from" end);
191
+ def first_open: [.subs[] | select(over | not)] | .[0];
192
+ def still($c; $why): "\($merged) has merged, but \($watch) did not start \($c.id): \($why). "
193
+ + "\($watch) starts \($c.id) once every card that blocks it"
194
+ + (if $c.parent == null then "" else ", or the card it was sliced from," end) + " is done.";
195
+ def asking($c; $space; $gone; $open):
196
+ $c.id as $id
197
+ | ($gone | length) as $n
198
+ | (if $n == 1 then "the relation" else "those relations" end) as $rel
199
+ | (($gone | map("\(.id), which blocks "
200
+ + (if .of == $id then $id else "\(.of), the card \($id) was sliced from" end)) | join(", and "))
201
+ + ", \(if $n == 1 then "was" else "were" end) canceled, so \($id) cannot start while "
202
+ + (if $n == 1 then "that relation stays." else "those relations stay." end)) as $why
203
+ | "What should happen to \($id)?" as $ask
204
+ | ($c | first_open) as $sub
205
+ | (if $sub == null then "start \($id)" else "start \($sub.id), its first open slice," end) as $how
206
+ | "ocnus task start \($space) \($sub.id // $id)" as $cmd
207
+ | {question: "\($why) \($ask)",
208
+ options: "remove \($rel) in Linear, then \($how) with: \($cmd) | cancel \($id) in Linear",
209
+ comment: ("\($merged) has merged, but \($watch) did not start \($id): \($why) "
210
+ + (if ($open | length) > 0 then ($open | map(blocks($id)) | join(", and ")) + ", too. " else "" end)
211
+ + "\($ask) Remove \($rel) in Linear, then \($how) with: `\($cmd)`. Or cancel \($id).")};
212
+ def sliced: first_open as $sub
213
+ | if $sub == null then empty
214
+ elif $sub.type != "unstarted" then
215
+ {kind: "skip", why: "its first open slice, \($sub.id), is \($sub | in_status), so it is not approved yet"}
216
+ elif ($sub | lacks) != null then {kind: "skip", why: "its first open slice, \($sub.id), has \($sub | lacks)"}
217
+ else {kind: "start", start: $sub.id}
218
+ end;
219
+ .cards[]
220
+ | . as $c
221
+ | (.id | sub("-[0-9]+$"; "") | ascii_upcase) as $team
222
+ | ($teams[$team] // []) as $spaces
223
+ | (if any($spaces[]; . == $home) then $home
224
+ elif ($spaces | length) == 1 then $spaces[0]
225
+ else null end) as $space
226
+ | [.blockers[] | select(.type != "completed")] as $open
227
+ | [$open[] | select(.type == "canceled")] as $gone
228
+ | [$open[] | select(.type != "canceled")] as $waits
229
+ | (if over then empty
230
+ elif .type != "unstarted" then {kind: "skip", why: "it is \(in_status), so it is not approved yet"}
231
+ elif lacks != null then {kind: "skip", why: "it has \(lacks)"}
232
+ elif ($spaces | length) == 0 then {kind: "skip", why: "its team, \($team), is in the teams of no space"}
233
+ elif $space == null then
234
+ {kind: "skip", why: "its team, \($team), is in the teams of more than one space (\($spaces | join(", "))), so ocnus cannot tell which one to start it in"}
235
+ elif ($open | length) > 0 then
236
+ {kind: "skip", why: ($open | map(blocks($c.id)) | join(", and ")),
237
+ held: (if ($gone | length) > 0 then "canceled" else "open" end)}
238
+ | if $merged == "" then .
239
+ elif .held == "canceled" then . + asking($c; $space; $gone; $waits)
240
+ else . + {comment: still($c; .why)} end
241
+ elif .cut then
242
+ {kind: "skip", why: "it, or the card it was sliced from, has more relations in Linear than ocnus reads, so a card that blocks it may be among the rest"}
243
+ elif .subsCut then
244
+ {kind: "skip", why: "it has more sub-issues in Linear than ocnus reads, so its first open slice may be among the rest"}
245
+ elif (.subs | length) > 0 then sliced
246
+ else {kind: "start", start: .id}
247
+ end) as $v
248
+ | [$v.kind, .id, ($v.start // ""), (if $v.kind == "start" or $v.held != null then $space else "" end),
249
+ ($v.why // ""), ($v.held // ""), ($v.comment // ""), ($v.question // ""), ($v.options // "")]
250
+ | join("\u001f")'
251
+
252
+ # Whether a card has a task in a space already: a folder for it under the
253
+ # space's tasks, as task_folder looks for one.
254
+ # chain_has_task <the space's folder> <card ID, in upper case>
255
+ chain_has_task() {
256
+ local low f
257
+ low=$(printf '%s' "$2" | tr '[:upper:]' '[:lower:]')
258
+ for f in "$1/tasks/$low" "$1/tasks/$low-"*; do
259
+ [ ! -d "$f" ] || return 0
260
+ done
261
+ return 1
262
+ }
263
+
264
+ # Whether a card's merge is the last thing recorded of it in a space. Without
265
+ # the store, nothing is recorded of it.
266
+ # chain_merged <space> <card ID, in upper case>
267
+ chain_merged() {
268
+ have_sqlite && [ -e "$STORE" ] || return 1
269
+ [ "$(store "$STORE" "select coalesce((select status = 'done' and next = 'merged' from handoffs
270
+ where space = $(sql_str "$1") and card = $(sql_str "$2") order by id desc limit 1), 0);" 2>/dev/null)" = 1 ]
271
+ }
272
+
273
+ # Start each ready card among the cards given, and print a line, on stdout,
274
+ # for each card started and each card not started:
275
+ # ABC-123 was started
276
+ # ABC-131 was started, the first open slice of ABC-130
277
+ # ABC-124 was not started: ABC-122, in In Review, still blocks it
278
+ # Given the card whose merge freed them, it tells the human about each card
279
+ # another card still holds (chain_tell), and says so at the end of its line:
280
+ # ABC-124 was not started: ABC-122, in In Review, still blocks it (a comment on it in Linear says so)
281
+ # A card is started with `task start <space> <card>`, run as its own command,
282
+ # as the human would run it, so that a start that stops does not stop this.
283
+ # All it prints goes to stderr, for whoever is watching, and a start that
284
+ # stops is a card not started, with why. `task start` reads the card again,
285
+ # and holds it when a card that blocks it is not done after all. A card is
286
+ # never started twice in one run, nor when it has a task on this machine
287
+ # already, nor when its merge is the last thing recorded of it here: Linear
288
+ # may still have such a card where it was, when it could not be moved. Nor
289
+ # is a slice started through the card it was sliced from when it is among
290
+ # the cards given and not ready itself: its own line says why, and a `task
291
+ # start` that could only hold it would ask Linear for nothing.
292
+ #
293
+ # CHAIN_FAILED is 1 when a card that was ready could not be started.
294
+ # chain_start <the cards, as linear_blocks or linear_waiting prints them> <the home space, or ''>
295
+ # [<the card whose merge freed them>]
296
+ CHAIN_FAILED=0
297
+ chain_start() {
298
+ local found=$1 home=$2 merged=${3:-} teams lines sep=$'\x1f' kind card start space why of dir out rc line held stopped
299
+ local tried=' ' left=' ' hold comment question options
300
+ CHAIN_FAILED=0
301
+ teams=$(chain_teams) || teams='{}'
302
+ if ! lines=$(printf '%s' "$found" | jq -r --argjson teams "$teams" --arg home "$home" \
303
+ --arg merged "$merged" --arg watch "ocnus's watch" "$CHAIN_VERDICTS" 2>/dev/null); then
304
+ CHAIN_FAILED=1
305
+ say "no card was started: what Linear said of the cards that wait is not something ocnus can read"
306
+ return 0
307
+ fi
308
+ # The cards that are not ready, each of which has a line of its own.
309
+ while IFS=$sep read -r kind card start space why hold comment question options; do
310
+ [ "$kind" != skip ] || left+="$card "
311
+ done <<< "$lines"
312
+ while IFS=$sep read -r kind card start space why hold comment question options; do
313
+ case $kind in
314
+ skip)
315
+ if [ -n "$merged" ] && [ -n "$hold" ] && [ -n "$comment" ]; then
316
+ say "$card was not started: $why$(chain_tell "$merged" "$space" "$card" "$why" "$hold" "$comment" "$question" "$options")"
317
+ else
318
+ say "$card was not started: $why"
319
+ fi
320
+ continue
321
+ ;;
322
+ start) ;;
323
+ *) continue ;;
324
+ esac
325
+ # A slice of a sliced card may be on the list itself: started once, and
326
+ # not at all when its own line says it is not ready.
327
+ case $tried in *" $start "*) continue ;; esac
328
+ case $left in *" $start "*) continue ;; esac
329
+ tried+="$start "
330
+ of=''
331
+ [ "$start" = "$card" ] || of=", the first open slice of $card"
332
+ if ! dir=$(space_dir "$space" 2>/dev/null); then
333
+ say "$start was not started: there is no space called '$space'"
334
+ continue
335
+ fi
336
+ if chain_has_task "$dir" "$start"; then
337
+ say "$start was not started: it has a task in '$space' already, though Linear has it as a card that waits"
338
+ continue
339
+ fi
340
+ if chain_merged "$space" "$start"; then
341
+ say "$start was not started: its merge is recorded in '$space', though Linear has it as a card that waits"
342
+ continue
343
+ fi
344
+ say "Starting $start in '$space'$of" >&2
345
+ rc=0
346
+ # Nothing it runs may read the list of cards this loop is reading.
347
+ out=$("$REPO/cli/ocnus" task start "$space" "$start" </dev/null 2>&1) || rc=$?
348
+ [ -z "$out" ] || printf '%s\n' "$out" >&2
349
+ if [ "$rc" = 0 ]; then
350
+ say "$start was started$of"
351
+ continue
352
+ fi
353
+ # Why it stopped is the line die printed, the last one. A card that was
354
+ # held is one that still waits, and each card that holds it is on a line
355
+ # of its own (held_message).
356
+ stopped='' held=''
357
+ while IFS= read -r line; do
358
+ case $line in
359
+ 'ocnus: '*) stopped=$line ;;
360
+ ' blocker '*) held=${held:+$held, and }${line# blocker } ;;
361
+ esac
362
+ done <<< "$out"
363
+ case $stopped in
364
+ "ocnus: $start $HELD_SAYS"*)
365
+ say "$start was not started$of: ${held:-a card that blocks it is not done yet}"
366
+ ;;
367
+ *)
368
+ CHAIN_FAILED=1
369
+ [ -n "$stopped" ] || stopped=${out##*$'\n'}
370
+ stopped=$(first_sentence "$stopped")
371
+ say "$start was not started$of: task start stopped${stopped:+: $stopped}"
372
+ ;;
373
+ esac
374
+ done <<< "$lines"
375
+ }
376
+
377
+ # --- at a merge -------------------------------------------------------------
378
+
379
+ # Tell the human about a card that the merge of $1 freed in part, which
380
+ # another card still holds, and print what came of it, for the end of the
381
+ # card's line: a comment on it in Linear, and for a card a canceled card
382
+ # holds, the question recorded too (chain_ask). Neither stops anything: what
383
+ # could not be done is said instead.
384
+ # chain_tell <the merged card> <the card's space> <card> <why it was not started>
385
+ # <open|canceled> <the comment> <the question> <its options>
386
+ chain_tell() {
387
+ local merged=$1 space=$2 card=$3 why=$4 held=$5 comment=$6 question=$7 options=$8 out made=0 told summary
388
+ # In a subshell of its own: it stops, as die does, when Linear cannot make
389
+ # the comment.
390
+ if out=$(linear_comment "$card" "$comment" 2>&1); then
391
+ made=1
392
+ else
393
+ out=$(first_sentence "$out")
394
+ [ -n "$out" ] || out='linear_comment stopped without saying why'
395
+ fi
396
+ if [ "$held" != canceled ]; then
397
+ if [ "$made" = 1 ]; then printf ' (a comment on it in Linear says so)'
398
+ else printf ' (the comment on it in Linear was not made: %s)' "$out"
399
+ fi
400
+ return 0
401
+ fi
402
+ told='a comment on it in Linear asks you what to do'
403
+ summary="$merged has merged, but ocnus's watch did not start $card: $why. Recorded by ocnus's watch."
404
+ if [ "$made" = 1 ]; then
405
+ summary+=" A comment on $card in Linear asks the same."
406
+ else
407
+ told="the comment on it in Linear was not made: $out"
408
+ summary+=" The comment on $card in Linear that asks the same was not made: $out."
409
+ fi
410
+ if chain_ask "$space" "$card" "$summary" "$question" "$options"; then
411
+ if [ "$made" = 1 ]; then printf ' (%s, and task log shows it waiting on you)' "$told"
412
+ else printf ' (%s, but task log shows it waiting on you)' "$told"
413
+ fi
414
+ elif [ "$made" = 1 ]; then
415
+ printf ' (%s, but the question could not be recorded, so task log does not show it)' "$told"
416
+ else
417
+ printf ' (%s, and the question could not be recorded, so task log does not show it)' "$told"
418
+ fi
419
+ }
420
+
421
+ # Record the question ocnus's watch asks about a card a canceled card holds
422
+ # as a hand-off of the card's, step start and status needs-human, so that it
423
+ # waits on the human until the card starts or the human answers it. Only the
424
+ # watch records a start that is not done: `task handoff` refuses step start
425
+ # (handoff.sh). Each line is cut to fit HANDOFF_LINE_MAX. Nothing is recorded
426
+ # when the card's latest hand-off is the same question already, as when a
427
+ # later merge frees it in part again, or is its merge. It fails when the
428
+ # question is not waiting once it is done.
429
+ # chain_ask <space> <card> <summary> <question> <options>
430
+ chain_ask() {
431
+ local space=$1 card=$2 v id lines=()
432
+ for v in "$3" "$4" "$5"; do
433
+ v=$(plain_note "$v")
434
+ [ "${#v}" -le "$HANDOFF_LINE_MAX" ] || v="${v:0:$((HANDOFF_LINE_MAX - 3))}..."
435
+ lines+=("$v")
436
+ done
437
+ have_sqlite && store_ready || return 1
438
+ [ "$(store "$STORE" "select coalesce((select step = 'start' and status = 'needs-human'
439
+ and question is $(sql_str "${lines[1]}") from handoffs
440
+ where space = $(sql_str "$space") and card = $(sql_str "$card") order by id desc limit 1), 0);")" != 1 ] ||
441
+ return 0
442
+ id=$(store_handoff --unless-merged "$space" "$card" start needs-human '' "${lines[0]}" '' "${lines[1]}" "${lines[2]}" '' '' '') ||
443
+ return 1
444
+ case $id in '' | *[!0-9]*) return 1 ;; esac
445
+ }
446
+
447
+ # Start the cards that the card $2, whose merge was just recorded in the
448
+ # space $1, was blocking, and print a line for each card started and each
449
+ # card not started, as chain_start does, for the merge's flags. It asks
450
+ # Linear once for the cards, and once more for each comment on a card another
451
+ # card still holds. It never stops what called it: what it could not do is a
452
+ # line too, and the catch-up starts what it missed.
453
+ #
454
+ # With the chain off, it does nothing. With no Linear key saved, it does
455
+ # nothing either, and says nothing: Linear is not used on this machine, which
456
+ # the note on the card's move says already.
457
+ # merge_chain <space> <card ID, in upper case>
458
+ merge_chain() {
459
+ local space=$1 card=$2 found
460
+ if ! settings_load; then
461
+ say "the cards $card was blocking were not looked for: $(first_sentence "$SETTINGS_WHY")"
462
+ return 0
463
+ fi
464
+ [ "$SET_CHAIN" = true ] || return 0
465
+ [ -n "${LINEAR_API_KEY:-}" ] || return 0
466
+ # Only the last line is the answer: anything before it was said on stderr.
467
+ if ! found=$(linear_blocks "$card" 2>&1); then
468
+ say "the cards $card was blocking were not looked for: $(first_sentence "$found")"
469
+ return 0
470
+ fi
471
+ found=${found##*$'\n'}
472
+ [ "$(printf '%s' "$found" | jq -r '.cut' 2>/dev/null)" != true ] ||
473
+ say "$card blocks more cards in Linear than ocnus reads at once, so some were not looked at"
474
+ chain_start "$found" "$space" "$card"
475
+ }
476
+
477
+ # --- the catch-up -----------------------------------------------------------
478
+
479
+ # Start every card of a space's teams that waits and is ready, and print a
480
+ # line for each card started and each card not started, as chain_start does.
481
+ # It asks Linear once for every WAITING_PAGE cards that wait. It stops, as
482
+ # die does, when the space has no team or Linear cannot be asked.
483
+ #
484
+ # The human names the space, so every card starts in it. The watch names
485
+ # none, so a card whose team more than one space lists is not started: it
486
+ # cannot tell which one the human means.
487
+ # ready_cards <space> <the space's folder> <named|watch>
488
+ ready_cards() {
489
+ local name=$1 dir=$2 how=$3 keys team teams=() found home=$1
490
+ keys=$(space_teams "$dir") || exit 1
491
+ while IFS= read -r team; do [ -z "$team" ] || teams+=("$team"); done <<< "$keys"
492
+ [ "${#teams[@]}" -gt 0 ] ||
493
+ die "space '$name' has no Linear team, so there are no cards to start. Set it with: ocnus space team $name <team key>, like: ocnus space team $name ABC"
494
+ found=$(linear_waiting "${teams[@]}") || exit 1
495
+ if [ "$(printf '%s' "$found" | jq -r '.cards | length' 2>/dev/null)" = 0 ]; then
496
+ say "No card of '$name' waits to start."
497
+ return 0
498
+ fi
499
+ [ "$how" = named ] || home=''
500
+ chain_start "$found" "$home"
501
+ }
package/cli/lib/close.sh CHANGED
@@ -2,8 +2,10 @@
2
2
  # Sourced by cli/ocnus.
3
3
 
4
4
  # Once `task start` has opened a card's build tab, the write-up agent, in the
5
- # tab `task new` named after the card, has nothing left to do. `task start`
6
- # starts `task close` for it (start_close), detached in herdr-core, so that it
5
+ # tab `task new` named after the card, has nothing left to do. Nor has it
6
+ # once `task start` has held the card for a card that blocks it: the card
7
+ # waits in Linear, and the chain opens its build tab later (chain.sh). `task
8
+ # start` starts `task close` for it (start_close), detached in herdr-core, so that it
7
9
  # outlives the turn of the agent that ran `task start`. `task close` waits for
8
10
  # that turn to end, ends the agent's Claude session with /exit, waits for the
9
11
  # tab's own shell to come back, then closes the tab, as `task finish` closes a
@@ -160,7 +162,7 @@ task_close() {
160
162
  }
161
163
 
162
164
  # Start `task close` for a card's write-up session, from `task start` once the
163
- # build tab is open: detached in herdr-core, so that it outlives the turn of
165
+ # build tab is open, or once it has held the card: detached in herdr-core, so that it outlives the turn of
164
166
  # the agent that ran `task start`, and in the space's folder, which stays. Its
165
167
  # terminal has none of ocnus's or Herdr's labels, so the Herdr app does
166
168
  # not show it and `host` does not count it as an agent; no parent, so it goes
@@ -10,39 +10,59 @@ link_line() {
10
10
  fi
11
11
  }
12
12
 
13
+ # install's steps, each named on the line under the bar while it runs, in a
14
+ # terminal that shows the picture (progress.sh): linking, the settings file
15
+ # and the launchd agent on every machine, the dev profiles and PATH on a
16
+ # clone only, and refreshing Herdr once Herdr has been opened. What says
17
+ # that something was skipped, is waiting, could not be done or is left for
18
+ # the human to do is a note, which install prints below the picture once
19
+ # the bar is full.
13
20
  cmd_install() {
21
+ local steps=3
22
+ if is_clone; then steps=$((steps + 2)); fi
23
+ if herdr_opened; then steps=$((steps + 1)); fi
24
+ progress_begin install "$steps"
14
25
  require_herdr
15
26
  CHANGED=0 SKIPPED=0
27
+ if herdr_opened; then progress_next "Linking the mods, layouts, skills and agent profiles"
28
+ else progress_next "Linking the skills and agent profiles"
29
+ fi
16
30
  link_line
17
31
  link_all
18
- herdr_opened || say " waiting $HERDR_WAITS"
32
+ herdr_opened || note " waiting $HERDR_WAITS"
33
+ progress_next "Checking the settings file"
19
34
  settings_init
35
+ if is_clone; then progress_next "Writing the dev profiles"; fi
20
36
  write_review_profiles
21
37
 
22
38
  # npm already put the command on PATH; a clone has to do it itself.
23
39
  if is_clone; then
40
+ progress_next "Putting ocnus on your PATH"
24
41
  say "Putting ocnus on your PATH"
25
42
  mkdir -p "$BIN_DIR"
26
43
  local me=$REPO/cli/ocnus dst=$BIN_DIR/ocnus
27
44
  case $(state_of "$me" "$dst") in
28
45
  linked) say " already at $dst" ;;
29
46
  missing) ln -s "$me" "$dst"; say " linked $dst" ;;
30
- *) say " skipped $dst (something else is already there)" ;;
47
+ *) note " skipped $dst (something else is already there)" ;;
31
48
  esac
32
49
  case ":$PATH:" in
33
50
  *":$BIN_DIR:"*) ;;
34
- *) say " note: $BIN_DIR is not on your PATH; add it to run 'ocnus' from anywhere" ;;
51
+ *) note " note: $BIN_DIR is not on your PATH; add it to run 'ocnus' from anywhere" ;;
35
52
  esac
36
53
  fi
37
54
  # What brings ocnus's watch on the merges back after a restart.
55
+ progress_next "Loading the launchd agent"
38
56
  merges_launchd
39
57
 
40
58
  # Before Herdr's first run there is no app to refresh, and nothing linked
41
59
  # for it to read.
42
60
  if herdr_opened; then
61
+ progress_next "Refreshing Herdr"
43
62
  say "Refreshing Herdr"
44
63
  refresh_herdr
45
64
  fi
65
+ progress_end
46
66
  say "Done. Switch Herdr to the default layout: pick it from the Layout dropdown, or press ctrl-shift-l until it shows, as you must from Herdr's own layout, which has no dropdown."
47
67
  }
48
68
 
@@ -94,7 +114,15 @@ cmd_update() {
94
114
  merges_wake
95
115
  }
96
116
 
117
+ # status's checks, each a step of the picture's (progress.sh): herdr-core,
118
+ # the links, the settings file, the dev profiles on a clone only, the
119
+ # spaces, the watch on the merges, the Linear key, which asks Linear and is
120
+ # the slowest, and billing. Under the picture, status prints its report once
121
+ # the bar is full, as it prints it without the picture.
97
122
  cmd_status() {
123
+ local steps=7
124
+ if is_clone; then steps=8; fi
125
+ progress_begin status "$steps"
98
126
  say "Repo: $REPO"
99
127
  say "Herdr: $APP_HOME"
100
128
  say "Skills: $SKILLS_HOME"
@@ -105,6 +133,7 @@ cmd_status() {
105
133
  # task start start it. herdr-app and hc both come with Herdr, so either one
106
134
  # missing is Herdr not installed. It is asked once, and what it answered
107
135
  # goes to the watch on the merges below.
136
+ progress_next "Checking herdr-core"
108
137
  if ! { have_herdr && have_hc; }; then
109
138
  printf ' %-10s %s\n' problem "Herdr is not installed. Install it: $HERDR_INSTALL"
110
139
  herdr_problems=1
@@ -115,6 +144,7 @@ cmd_status() {
115
144
  core=down
116
145
  printf ' %-10s %s\n' herdr-core "not running; ocnus starts it when a task needs it"
117
146
  fi
147
+ progress_next "Checking the links"
118
148
  # Before Herdr's first run the mods and layouts wait for its folder, which
119
149
  # is in order.
120
150
  if ! herdr_opened; then
@@ -127,6 +157,7 @@ cmd_status() {
127
157
  [ "$s" = linked ] || problems=$((problems + 1))
128
158
  printf ' %-10s %s\n' "$s" "$(label "$dst")"
129
159
  done < <(wanted)
160
+ progress_next "Checking the settings file"
130
161
  # The settings file, which stops task new and task build when it is not
131
162
  # valid settings. Without it read, a review subagent ocnus wrote cannot
132
163
  # be compared with what it would write now.
@@ -136,6 +167,7 @@ cmd_status() {
136
167
  fi
137
168
  # The review subagents a clone writes, rather than links (settings.sh).
138
169
  if is_clone; then
170
+ progress_next "Checking the dev profiles"
139
171
  for src in "$REVIEW_SOURCES"/*.md; do
140
172
  [ -f "$src" ] || continue
141
173
  is_profile "$(review_profile_of "$src")" || continue
@@ -147,6 +179,7 @@ cmd_status() {
147
179
  fi
148
180
  [ "$problems" = 0 ] || say "$problems not linked or not up to date. Run: ocnus update"
149
181
  herdr_opened || say "Herdr has not been opened yet, so the mods and layouts wait. Open it once, then run: ocnus update"
182
+ progress_next "Checking the spaces"
150
183
  say "Spaces: $SPACES"
151
184
  local space_problems=0
152
185
  check_spaces || space_problems=$?
@@ -157,10 +190,12 @@ cmd_status() {
157
190
  if ! have_sqlite && [ -n "$(ls -d "$SPACES"/*/ 2>/dev/null)" ]; then
158
191
  say " note $SQLITE is not installed, so hand-offs are not recorded."
159
192
  fi
193
+ progress_next "Checking the watch on the merges"
160
194
  # ocnus's watch on the merges, and the launchd agent that brings it
161
195
  # back after a restart (merges.sh). It only reads: it starts neither.
162
196
  local merges_problems=0
163
197
  merges_status "$core" || merges_problems=$?
198
+ progress_next "Checking the Linear key"
164
199
  # The Linear key, asked of Linear itself. A key Linear rejects, one that is
165
200
  # no key at all, and one that works but cannot change cards are problems.
166
201
  # With none saved the rest of ocnus still works, and a key that could
@@ -189,6 +224,7 @@ cmd_status() {
189
224
  *) key_out=$(first_sentence "$key_out")
190
225
  printf ' %-10s %s\n' note "the key was not checked${key_out:+: $key_out}" ;;
191
226
  esac
227
+ progress_next "Checking billing"
192
228
  # Which account the agents run on (billing.sh), and whether an Anthropic
193
229
  # API key is saved, never the key itself. On api with none saved, task new
194
230
  # and task build stop before an agent starts, so that is a problem. From a
@@ -210,6 +246,9 @@ cmd_status() {
210
246
  printf ' %-10s %s\n' key "no Anthropic API key is saved, and the subscription needs none"
211
247
  fi
212
248
  fi
249
+ # The bar is full, and the report is printed below the picture: the
250
+ # lines that close it are printed after it, as without the picture.
251
+ progress_end
213
252
  if [ "$problems" -gt 0 ] || [ "$herdr_problems" -gt 0 ] || [ "$space_problems" -gt 0 ] ||
214
253
  [ "$merges_problems" -gt 0 ] || [ "$settings_problems" -gt 0 ] || [ "$key_problems" -gt 0 ] ||
215
254
  [ "$billing_problems" -gt 0 ]; then