@johngaynor/ocnus 2.0.1-next.7 → 2.0.1-next.73
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.
- package/README.md +518 -98
- package/cli/lib/agents.sh +32 -16
- package/cli/lib/asks.sh +762 -0
- package/cli/lib/banner.sh +181 -0
- package/cli/lib/brief.sh +375 -0
- package/cli/lib/chain.sh +363 -0
- package/cli/lib/close.sh +5 -3
- package/cli/lib/cost.sh +500 -0
- package/cli/lib/finish.sh +30 -4
- package/cli/lib/github.sh +106 -26
- package/cli/lib/guard.sh +39 -10
- package/cli/lib/handoff.sh +196 -31
- package/cli/lib/host.sh +340 -384
- package/cli/lib/linear.sh +552 -56
- package/cli/lib/links.sh +6 -3
- package/cli/lib/merges.sh +126 -27
- package/cli/lib/sessions.sh +132 -0
- package/cli/lib/settings.sh +31 -15
- package/cli/lib/task.sh +169 -54
- package/cli/lib/tests.sh +302 -7
- package/cli/lib/usage.sh +204 -0
- package/cli/ocnus +274 -76
- package/herdr/README.md +930 -232
- package/herdr/layouts/default.json +30 -11
- package/herdr/layouts/showcase.json +291 -0
- package/herdr/layouts/vibe.json +162 -0
- package/herdr/layouts/vibe.svg +41 -0
- package/herdr/mods/agent-settings/main.js +19 -7
- package/herdr/mods/memory/main.js +128 -0
- package/herdr/mods/memory/mod.json +1 -0
- package/herdr/mods/memory/reading.js +88 -0
- package/herdr/mods/names/main.js +22 -4
- package/herdr/mods/step-counts/main.js +281 -0
- package/herdr/mods/step-counts/mod.json +1 -0
- package/herdr/mods/usage/main.js +149 -0
- package/herdr/mods/usage/mod.json +1 -0
- package/package.json +1 -1
- package/prompts/task-new.md +1 -1
- package/skills/brief/SKILL.md +8 -0
- package/skills/sdlc-breakdown/SKILL.md +66 -18
- package/skills/sdlc-build/SKILL.md +6 -2
- package/skills/sdlc-pr/SKILL.md +2 -2
- package/skills/sdlc-review/SKILL.md +5 -5
package/cli/lib/links.sh
CHANGED
|
@@ -17,7 +17,10 @@ is_linkable() {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
# The mods and layouts, each (source, destination) pair one per line,
|
|
20
|
-
# tab-separated. They go in Herdr's folder.
|
|
20
|
+
# tab-separated. They go in Herdr's folder. A layout's picture goes with it:
|
|
21
|
+
# the .svg beside it that its "preview" names, which Herdr's Settings shows
|
|
22
|
+
# for the layout and looks for in its own layouts folder. Nothing else in
|
|
23
|
+
# herdr/layouts is linked.
|
|
21
24
|
herdr_wanted() {
|
|
22
25
|
local m l
|
|
23
26
|
for m in "$REPO"/herdr/mods/*/; do
|
|
@@ -25,7 +28,7 @@ herdr_wanted() {
|
|
|
25
28
|
is_linkable "$m" || continue
|
|
26
29
|
printf '%s\t%s\n' "$m" "$APP_HOME/mods/${m##*/}"
|
|
27
30
|
done
|
|
28
|
-
for l in "$REPO"/herdr/layouts/*.json; do
|
|
31
|
+
for l in "$REPO"/herdr/layouts/*.json "$REPO"/herdr/layouts/*.svg; do
|
|
29
32
|
[ -f "$l" ] || continue
|
|
30
33
|
printf '%s\t%s\n' "$l" "$APP_HOME/layouts/${l##*/}"
|
|
31
34
|
done
|
|
@@ -60,7 +63,7 @@ state_of() {
|
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
# A short name for a destination: mods/cpu, layouts/default.json,
|
|
63
|
-
# skills/sdlc-plan, agents/ocnus-build.md.
|
|
66
|
+
# layouts/vibe.svg, skills/sdlc-plan, agents/ocnus-build.md.
|
|
64
67
|
label() {
|
|
65
68
|
local dst=$1
|
|
66
69
|
case $dst in
|
package/cli/lib/merges.sh
CHANGED
|
@@ -49,6 +49,14 @@
|
|
|
49
49
|
# card no longer waits, so the human finishes that task. No agent records the
|
|
50
50
|
# merge or runs `task finish` (sdlc-pr).
|
|
51
51
|
#
|
|
52
|
+
# Then it runs the chain (merge_chain, in chain.sh): it starts each card the
|
|
53
|
+
# merged card was blocking that is ready, and adds each card started, and
|
|
54
|
+
# each one left with why, to the merged row's flags. A pass also runs the
|
|
55
|
+
# chain's catch-up, `task ready` for every space that has a Linear team, once
|
|
56
|
+
# the last one is READY_EVERY seconds old, half an hour, whether or not a
|
|
57
|
+
# card waits on its merge (ready_due, ready_pass): it starts the ready cards
|
|
58
|
+
# that no merge started.
|
|
59
|
+
#
|
|
52
60
|
# A merge is recorded once. The watch's two rows go in one transaction, and
|
|
53
61
|
# only while the card's latest row is still pr needs-human, so an answer the
|
|
54
62
|
# agent recorded first keeps the card from being recorded until it asks
|
|
@@ -58,7 +66,8 @@
|
|
|
58
66
|
#
|
|
59
67
|
# After a pass it sleeps MERGES_PAUSE, a minute, then runs itself again with
|
|
60
68
|
# exec, so that each pass runs the code the machine has then, even after
|
|
61
|
-
# `ocnus update`. It exits once no card waits
|
|
69
|
+
# `ocnus update`. It exits once no card waits, having run a catch-up that
|
|
70
|
+
# was due. --once makes one pass.
|
|
62
71
|
#
|
|
63
72
|
# `task handoff` wakes it once it has recorded a pr needs-human, and `task
|
|
64
73
|
# new`, `task start` and `task build` wake it next to the host recorder, as
|
|
@@ -66,21 +75,29 @@
|
|
|
66
75
|
# The launchd agent that install and update write wakes it every minute too,
|
|
67
76
|
# with `task merges --wake`, so it is back within a minute of herdr-core
|
|
68
77
|
# starting after a restart, however herdr-core was started, and one that died
|
|
69
|
-
# comes back the same way.
|
|
70
|
-
#
|
|
78
|
+
# comes back the same way. With no card waiting, a wake starts it only for a
|
|
79
|
+
# catch-up that is due, and it ends once it has run it. A wake never starts
|
|
80
|
+
# herdr-core, and hc lets one live terminal hold a name, so there is never
|
|
81
|
+
# more than one watch.
|
|
71
82
|
#
|
|
72
83
|
# What it saw is left for `task log`, which says when nothing can see a
|
|
73
|
-
# card's pull requests
|
|
74
|
-
#
|
|
84
|
+
# card's pull requests, and counts the card as ready to merge once every one
|
|
85
|
+
# of them is open and ready (merges_seen, read by card_agent in agents.sh),
|
|
86
|
+
# and for `ocnus status`, which says whether the watch runs (merges_status).
|
|
75
87
|
# As a pass begins it writes the time to merges/.alive, and after each card's
|
|
76
88
|
# turn it writes merges/<space>/<card>: on one line, the time, then what it
|
|
77
|
-
# saw (merges_saw). A
|
|
89
|
+
# saw (merges_saw). A card's turn also keeps the pull requests it saw in
|
|
90
|
+
# merges/<space>/<card>.pulls, a line each, its state then its URL, for `task
|
|
91
|
+
# asks`, which lists the open ones with the card's question (asks.sh). A pass
|
|
92
|
+
# that could ask GitHub about none of them leaves the file as the last pass
|
|
93
|
+
# that could wrote it. A pass whose call to GitHub failed as a whole writes
|
|
78
94
|
# merges/.gh: the time, sign-in when gh needs signing in or else failed, then
|
|
79
95
|
# gh's words. A pass whose call worked, or that asked GitHub nothing, removes
|
|
80
96
|
# it. All of them go once no card waits, as the watch ends then. They are
|
|
81
97
|
# files, not rows in the store, and `task log` and `status` read them afresh
|
|
82
|
-
# each time.
|
|
83
|
-
#
|
|
98
|
+
# each time. merges/.ready holds when the last catch-up began, and stays
|
|
99
|
+
# whatever waits. .alive, .gh and .ready start with a dot, so that none is
|
|
100
|
+
# ever a space's folder.
|
|
84
101
|
|
|
85
102
|
MERGES_TERMINAL=ocnus-merges
|
|
86
103
|
MERGES_USAGE='usage: ocnus task merges [--once | --wake]'
|
|
@@ -129,8 +146,9 @@ task_worktrees() {
|
|
|
129
146
|
}
|
|
130
147
|
}
|
|
131
148
|
|
|
132
|
-
# Start ocnus's watch on the merges while a card waits on its merge,
|
|
133
|
-
# unless it runs already. Nothing waits
|
|
149
|
+
# Start ocnus's watch on the merges while a card waits on its merge, or
|
|
150
|
+
# once its catch-up is due (ready_due), unless it runs already. Nothing waits
|
|
151
|
+
# on it: it starts in the background,
|
|
134
152
|
# and a wake that fails, as a second one does since the name is taken, is
|
|
135
153
|
# ignored. It never starts herdr-core: with herdr-core not running, nothing is
|
|
136
154
|
# woken. The watch gets the PATH of what woke it, which found gh, since
|
|
@@ -138,7 +156,7 @@ task_worktrees() {
|
|
|
138
156
|
# OCNUS_HOME, so that it reads the same store.
|
|
139
157
|
merges_wake() {
|
|
140
158
|
have_hc && have_sqlite || return 0
|
|
141
|
-
[ -n "$(merges_waiting 2>/dev/null)" ] || return 0
|
|
159
|
+
[ -n "$(merges_waiting 2>/dev/null)" ] || ready_due || return 0
|
|
142
160
|
hc_cmd server status --json >/dev/null 2>&1 || return 0
|
|
143
161
|
local env=(PATH="$PATH")
|
|
144
162
|
[ -z "${OCNUS_HOME:-}" ] || env+=(OCNUS_HOME="$OCNUS_HOME")
|
|
@@ -155,8 +173,9 @@ merges_wake() {
|
|
|
155
173
|
# it into the user's own domain, gui/<uid>. launchd runs it once it is
|
|
156
174
|
# loaded, as at login, and every MERGES_PAUSE, a minute, after that. It runs
|
|
157
175
|
# `ocnus task merges --wake` (merges_wake), which starts the watch only
|
|
158
|
-
# while a card waits on its merge
|
|
159
|
-
#
|
|
176
|
+
# while a card waits on its merge, or once its catch-up is due, and
|
|
177
|
+
# herdr-core runs, so the watch is back within a minute of herdr-core
|
|
178
|
+
# starting. It never starts herdr-core.
|
|
160
179
|
MERGES_LABEL=com.johngaynor.ocnus.merges
|
|
161
180
|
MERGES_PLIST=$HOME/Library/LaunchAgents/$MERGES_LABEL.plist
|
|
162
181
|
# What launchd runs, with /bin/sh: the ocnus that wrote it is $0, the
|
|
@@ -337,7 +356,7 @@ merge_finish() {
|
|
|
337
356
|
# when it recorded nothing.
|
|
338
357
|
# merge_record <space> <card ID, in upper case> <each pull request's URL, a space between>
|
|
339
358
|
merge_record() {
|
|
340
|
-
local space=$1 card=$2 urls=$3 at s c summary id notes line kept=''
|
|
359
|
+
local space=$1 card=$2 urls=$3 at s c summary id notes line kept='' chain
|
|
341
360
|
at=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
|
342
361
|
s=$(sql_str "$space") c=$(sql_str "$card")
|
|
343
362
|
summary="Merged on GitHub: ${urls// /, }. Recorded by ocnus's watch."
|
|
@@ -366,6 +385,13 @@ merge_record() {
|
|
|
366
385
|
say "$card's task is left as it is, and task log says why"
|
|
367
386
|
kept=${kept:+$kept; }$(plain_note "task not finished: $FINISH_LEFT")
|
|
368
387
|
}
|
|
388
|
+
# The task is finished first, so that each card the merge frees starts
|
|
389
|
+
# from what is merged, with the merged card's own worktree out of the way.
|
|
390
|
+
chain=$(merge_chain "$space" "$card") || true
|
|
391
|
+
[ -z "$chain" ] || printf '%s\n' "$chain"
|
|
392
|
+
while IFS= read -r line; do
|
|
393
|
+
[ -z "$line" ] || kept=${kept:+$kept; }$(plain_note "$line")
|
|
394
|
+
done <<< "$chain"
|
|
369
395
|
[ "${#kept}" -le "$HANDOFF_LINE_MAX" ] || kept="${kept:0:$((HANDOFF_LINE_MAX - 3))}..."
|
|
370
396
|
[ -z "$kept" ] ||
|
|
371
397
|
store "$STORE" "update handoffs set flags = coalesce(flags || '; ', '') || $(sql_str "$kept") where id = $id;" ||
|
|
@@ -406,9 +432,11 @@ woke_keep() {
|
|
|
406
432
|
if [ -n "$kept" ]; then printf '%s' "$kept" > "$woke"; else woke_forget "$woke"; fi
|
|
407
433
|
}
|
|
408
434
|
|
|
409
|
-
# Remove the .woke file, and the file of what the watch
|
|
410
|
-
# that no longer waits on its merge. With none waiting,
|
|
411
|
-
# .alive and .gh go too, then each folder left with
|
|
435
|
+
# Remove the .woke file, the .pulls file, and the file of what the watch
|
|
436
|
+
# saw, of each card that no longer waits on its merge. With none waiting,
|
|
437
|
+
# the watch ends, so .alive and .gh go too, then each folder left with
|
|
438
|
+
# nothing in it. .ready stays, since it says when the last catch-up ran,
|
|
439
|
+
# whatever waits.
|
|
412
440
|
# merges_tidy <the cards that wait, as merges_waiting prints them>
|
|
413
441
|
merges_tidy() {
|
|
414
442
|
local waiting=$1 f space card sep=$'\x1f'
|
|
@@ -417,6 +445,7 @@ merges_tidy() {
|
|
|
417
445
|
card=${f##*/}
|
|
418
446
|
case $card in
|
|
419
447
|
*.woke) card=${card%.woke} ;;
|
|
448
|
+
*.pulls) card=${card%.pulls} ;;
|
|
420
449
|
*.*) continue ;;
|
|
421
450
|
esac
|
|
422
451
|
space=${f%/*} space=${space##*/}
|
|
@@ -426,12 +455,70 @@ merges_tidy() {
|
|
|
426
455
|
rmdir "$ENT_HOME"/merges/*/ "$ENT_HOME/merges" 2>/dev/null || true
|
|
427
456
|
}
|
|
428
457
|
|
|
458
|
+
# --- the catch-up -----------------------------------------------------------
|
|
459
|
+
|
|
460
|
+
# How old the watch's last catch-up is, in seconds, when it runs the next.
|
|
461
|
+
READY_EVERY=1800
|
|
462
|
+
|
|
463
|
+
# Whether the watch's catch-up is due: its last one began READY_EVERY seconds
|
|
464
|
+
# ago or more, or none has, as merges/.ready says, and there is something for
|
|
465
|
+
# it to do. There is nothing to do with the chain off, with no Linear key
|
|
466
|
+
# saved, or with no space that has a Linear team. Nor without gh or jq: the
|
|
467
|
+
# watch stops before its catch-up without either, so a wake would start it
|
|
468
|
+
# every minute for nothing. A note that cannot be read, or that is from the
|
|
469
|
+
# future, as after the clock was set back, is no note.
|
|
470
|
+
ready_due() {
|
|
471
|
+
local at='' now d
|
|
472
|
+
{ read -r at < "$ENT_HOME/merges/.ready"; } 2>/dev/null || at=''
|
|
473
|
+
case $at in
|
|
474
|
+
'' | *[!0-9]* | 0?* | ????????????*) ;;
|
|
475
|
+
*)
|
|
476
|
+
now=$(date +%s)
|
|
477
|
+
[ "$at" -gt "$now" ] || [ $((now - at)) -ge "$READY_EVERY" ] || return 1
|
|
478
|
+
;;
|
|
479
|
+
esac
|
|
480
|
+
[ -n "${LINEAR_API_KEY:-}" ] || return 1
|
|
481
|
+
command -v gh >/dev/null 2>&1 && command -v jq >/dev/null 2>&1 || return 1
|
|
482
|
+
settings_load 2>/dev/null && [ "$SET_CHAIN" = true ] || return 1
|
|
483
|
+
for d in "$SPACES"/*/; do
|
|
484
|
+
[ -d "$d" ] || continue
|
|
485
|
+
[ -z "$(space_teams "${d%/}" 2>/dev/null)" ] || return 0
|
|
486
|
+
done
|
|
487
|
+
return 1
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
# The watch's catch-up: for every space that has a Linear team, start each
|
|
491
|
+
# card that waits and is ready, as `task ready <space>` does (ready_cards in
|
|
492
|
+
# chain.sh), but for a card whose team more than one space lists. It notes
|
|
493
|
+
# when it began in merges/.ready first, so that a catch-up Linear cannot
|
|
494
|
+
# answer is tried again in READY_EVERY seconds and not at every pass. What
|
|
495
|
+
# each space's cards came to is said, a line each, and nothing is recorded:
|
|
496
|
+
# a card that starts records its own start.
|
|
497
|
+
ready_pass() {
|
|
498
|
+
local d name dir
|
|
499
|
+
merges_write .ready "$(date +%s)"
|
|
500
|
+
for d in "$SPACES"/*/; do
|
|
501
|
+
[ -d "$d" ] || continue
|
|
502
|
+
d=${d%/}
|
|
503
|
+
name=${d##*/}
|
|
504
|
+
[ -n "$(space_teams "$d" 2>/dev/null)" ] || continue
|
|
505
|
+
dir=$(space_dir "$name" 2>/dev/null) || continue
|
|
506
|
+
say "Looking for the cards of '$name' that are ready to start"
|
|
507
|
+
# In a shell of its own: it stops, as die does, when Linear cannot be asked.
|
|
508
|
+
(ready_cards "$name" "$dir" watch) || true
|
|
509
|
+
done
|
|
510
|
+
return 0
|
|
511
|
+
}
|
|
512
|
+
|
|
429
513
|
# What a check of a card's pull requests saw, as MERGES_SAW, for the card's
|
|
430
514
|
# file: closed and the URL of each closed without merging, as a closed one
|
|
431
515
|
# comes first; else conflict and each in conflict; else failed and why
|
|
432
|
-
# GitHub could not be asked about one; else
|
|
433
|
-
#
|
|
434
|
-
#
|
|
516
|
+
# GitHub could not be asked about one; else ready when every pull request of
|
|
517
|
+
# the card is open and ready to merge, as GitHub said of each (GITHUB_READ),
|
|
518
|
+
# or open while one is open and that does not hold, as when another has
|
|
519
|
+
# merged; else merged once all have, or none when the card has none. It is
|
|
520
|
+
# none too for a card the pass did not check, as one whose task is not on
|
|
521
|
+
# this machine.
|
|
435
522
|
# merges_saw <the check's lines>
|
|
436
523
|
MERGES_SAW=none
|
|
437
524
|
merges_saw() {
|
|
@@ -445,6 +532,7 @@ merges_saw() {
|
|
|
445
532
|
if [ -n "$closed" ]; then MERGES_SAW="closed $closed"
|
|
446
533
|
elif [ -n "$conflict" ]; then MERGES_SAW="conflict $conflict"
|
|
447
534
|
elif [ "$CHECK_FAILED" -gt 0 ]; then MERGES_SAW="failed $(plain_note "$CHECK_WHY")"
|
|
535
|
+
elif [ "$CHECK_OPEN" -gt 0 ] && [ "$CHECK_READY" = "$CHECK_OPEN" ] && [ "$CHECK_MERGED" = 0 ]; then MERGES_SAW=ready
|
|
448
536
|
elif [ "$CHECK_OPEN" -gt 0 ]; then MERGES_SAW=open
|
|
449
537
|
elif [ "$CHECK_MERGED" -gt 0 ]; then MERGES_SAW=merged
|
|
450
538
|
else MERGES_SAW=none
|
|
@@ -483,8 +571,8 @@ MERGES_NOW='' MERGES_CORE=''
|
|
|
483
571
|
# is:
|
|
484
572
|
# '' ocnus's watch is watching them, or nothing is
|
|
485
573
|
# known: it ran a pass within MERGES_FRESH seconds and
|
|
486
|
-
# saw them open, merged or none, or has not seen
|
|
487
|
-
# card in that time
|
|
574
|
+
# saw them ready, open, merged or none, or has not seen
|
|
575
|
+
# the card in that time
|
|
488
576
|
# closed, conflict ocnus's watch is running and, within MERGES_FRESH
|
|
489
577
|
# seconds, saw one closed without merging or in
|
|
490
578
|
# conflict: MERGES_PULLS are their URLs, a space between
|
|
@@ -493,13 +581,15 @@ MERGES_NOW='' MERGES_CORE=''
|
|
|
493
581
|
# ocnus's watch has not begun a pass within
|
|
494
582
|
# MERGES_FRESH seconds, or GitHub could not be asked, as
|
|
495
583
|
# its last pass saw
|
|
496
|
-
#
|
|
584
|
+
# MERGES_READY is 1 when ocnus's watch is running and, within MERGES_FRESH
|
|
585
|
+
# seconds, saw every pull request of the card open and ready to merge, and 0
|
|
586
|
+
# otherwise. Whether an agent runs to be woken is card_agent's to say.
|
|
497
587
|
# merges_seen <space> <card ID, in upper case>
|
|
498
588
|
MERGES_FRESH=$((3 * MERGES_PAUSE))
|
|
499
|
-
MERGES_SEEN='' MERGES_PULLS='' MERGES_WHY=''
|
|
589
|
+
MERGES_SEEN='' MERGES_PULLS='' MERGES_WHY='' MERGES_READY=0
|
|
500
590
|
merges_seen() {
|
|
501
591
|
local space=$1 card=$2 at what rest
|
|
502
|
-
MERGES_SEEN='' MERGES_PULLS='' MERGES_WHY=''
|
|
592
|
+
MERGES_SEEN='' MERGES_PULLS='' MERGES_WHY='' MERGES_READY=0
|
|
503
593
|
MERGES_SEEN=unwatched
|
|
504
594
|
have_hc || { MERGES_WHY="Herdr's hc not installed"; return 0; }
|
|
505
595
|
if [ -z "$MERGES_CORE" ]; then
|
|
@@ -519,6 +609,7 @@ merges_seen() {
|
|
|
519
609
|
case $what in
|
|
520
610
|
closed | conflict) [ -z "$rest" ] || MERGES_SEEN=$what MERGES_PULLS=$rest ;;
|
|
521
611
|
failed) MERGES_SEEN=unwatched MERGES_WHY=${rest:-gh failed} ;;
|
|
612
|
+
ready) MERGES_READY=1 ;;
|
|
522
613
|
esac
|
|
523
614
|
}
|
|
524
615
|
|
|
@@ -708,7 +799,9 @@ merge_wake_agent() {
|
|
|
708
799
|
|
|
709
800
|
# What GitHub said of a card's pull requests, from the card's lines of
|
|
710
801
|
# github_pulls: a line for each pull request, merged, open, closed or
|
|
711
|
-
# conflict, then its URL, and the CHECK_* counts.
|
|
802
|
+
# conflict, then its URL, and the CHECK_* counts. An open one that GitHub
|
|
803
|
+
# called ready is open here too, and is counted in CHECK_READY as well. A
|
|
804
|
+
# branch with no pull request is skipped, since the work
|
|
712
805
|
# did not change that repo. One that GitHub could not be asked about is
|
|
713
806
|
# counted in CHECK_FAILED, with the first why in CHECK_WHY, and said on
|
|
714
807
|
# stderr; CHECK_SIGN_IN is 1 for it when gh needs signing in.
|
|
@@ -716,13 +809,14 @@ merge_wake_agent() {
|
|
|
716
809
|
merges_pulls() {
|
|
717
810
|
local key state rest
|
|
718
811
|
CHECK_OPEN=0 CHECK_CLOSED=0 CHECK_MERGED=0 CHECK_CONFLICT=0 CHECK_FAILED=0
|
|
719
|
-
CHECK_SIGN_IN=0 CHECK_WHY=''
|
|
812
|
+
CHECK_READY=0 CHECK_SIGN_IN=0 CHECK_WHY=''
|
|
720
813
|
while read -r key state rest; do
|
|
721
814
|
case $state in
|
|
722
815
|
merged) CHECK_MERGED=$((CHECK_MERGED + 1)); say "merged $rest" ;;
|
|
723
816
|
closed) CHECK_CLOSED=$((CHECK_CLOSED + 1)); say "closed $rest" ;;
|
|
724
817
|
conflict) CHECK_CONFLICT=$((CHECK_CONFLICT + 1)); say "conflict $rest" ;;
|
|
725
818
|
open) CHECK_OPEN=$((CHECK_OPEN + 1)); say "open $rest" ;;
|
|
819
|
+
ready) CHECK_OPEN=$((CHECK_OPEN + 1)); CHECK_READY=$((CHECK_READY + 1)); say "open $rest" ;;
|
|
726
820
|
none) ;;
|
|
727
821
|
*)
|
|
728
822
|
CHECK_FAILED=$((CHECK_FAILED + 1))
|
|
@@ -748,6 +842,8 @@ merges_check() {
|
|
|
748
842
|
[ -s "$pulls" ] || return 0
|
|
749
843
|
merges_pulls "$pulls" > "$scratch/check"
|
|
750
844
|
merges_saw "$scratch/check"
|
|
845
|
+
# The pull requests seen, for `task asks`.
|
|
846
|
+
[ ! -s "$scratch/check" ] || merges_write "$space/$card.pulls" "$(cat "$scratch/check")"
|
|
751
847
|
woke_keep "$woke" "$scratch/check"
|
|
752
848
|
if [ "$CHECK_CLOSED" -gt 0 ] || [ "$CHECK_CONFLICT" -gt 0 ]; then
|
|
753
849
|
merge_wake_agent "$space" "$card" "$scratch/check" "$woke"
|
|
@@ -773,6 +869,7 @@ merges_check() {
|
|
|
773
869
|
# its terminal. A pass asks GitHub about the pull requests of every card that
|
|
774
870
|
# waits on its merge, in one call (github_pulls), then checks each card in
|
|
775
871
|
# turn; then it sleeps a minute and runs itself again, until no card waits.
|
|
872
|
+
# Before that, a pass runs the chain's catch-up when one is due (ready_pass).
|
|
776
873
|
# With --wake it only wakes the watch, as the launchd agent has it do every
|
|
777
874
|
# minute (merges_wake), and says nothing.
|
|
778
875
|
task_merges() {
|
|
@@ -793,6 +890,8 @@ task_merges() {
|
|
|
793
890
|
local waiting
|
|
794
891
|
waiting=$(merges_waiting) || die "could not read the hand-offs in $STORE. It may not be ocnus's store."
|
|
795
892
|
merges_tidy "$waiting"
|
|
893
|
+
# The catch-up, when one is due, whether or not a card waits on its merge.
|
|
894
|
+
! ready_due || ready_pass
|
|
796
895
|
[ -n "$waiting" ] || return 0
|
|
797
896
|
merges_write .alive "$(date +%s)"
|
|
798
897
|
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# The Claude Code sessions of the agents ocnus starts. Sourced by cli/ocnus.
|
|
2
|
+
|
|
3
|
+
# `task new` and `task build` choose the session ID of the claude they start
|
|
4
|
+
# and give it to claude with --session-id=, so ocnus knows which conversation
|
|
5
|
+
# is a card's agent's without asking Claude Code. `task build --continue`
|
|
6
|
+
# continues the card's newest build session by that ID, and `task brief`
|
|
7
|
+
# (brief.sh) makes a copy of the card's newest session to brief the human
|
|
8
|
+
# from. Each start is a row of the sessions table, in the hand-off store
|
|
9
|
+
# (handoff.sh): when, the space, the card, the phase (write-up or build), the
|
|
10
|
+
# harness, and the session ID, which is null for a harness other than claude,
|
|
11
|
+
# whose sessions ocnus cannot name. A session ocnus did not start has no row.
|
|
12
|
+
|
|
13
|
+
# Where Claude Code keeps its transcripts: a folder for each folder a session
|
|
14
|
+
# was started in, holding <session ID>.jsonl for each session there.
|
|
15
|
+
TRANSCRIPTS=${CLAUDE_CONFIG_DIR:-$HOME/.claude}/projects
|
|
16
|
+
# What card_sessions puts between a row's values: the unit separator, which no
|
|
17
|
+
# value can hold, and which lets `read` keep an empty value, as a tab does not.
|
|
18
|
+
SESSION_SEP=$'\x1f'
|
|
19
|
+
|
|
20
|
+
# Print a new session ID: a version 4 UUID in lower case, which is what
|
|
21
|
+
# `claude --session-id` takes. It is read from /dev/urandom, as new_herdr_id
|
|
22
|
+
# reads its ids. The 13th digit is the version, 4, and the 17th the variant,
|
|
23
|
+
# one of 8, 9, a and b.
|
|
24
|
+
session_id() {
|
|
25
|
+
local hex
|
|
26
|
+
hex=$(LC_ALL=C od -A n -t x1 -N 16 /dev/urandom | LC_ALL=C tr -d ' \n')
|
|
27
|
+
[ "${#hex}" = 32 ] || die "could not read /dev/urandom to make a session ID for Claude Code"
|
|
28
|
+
printf '%s-%s-4%s-%x%s-%s\n' "${hex:0:8}" "${hex:8:4}" "${hex:13:3}" \
|
|
29
|
+
"$(( (0x${hex:16:1} & 3) | 8 ))" "${hex:17:3}" "${hex:20:12}"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# Choose the session of a claude that is about to start: its ID in SESSION,
|
|
33
|
+
# and the flag that gives it to claude in SESSION_ARGS, which goes after the
|
|
34
|
+
# profile's flags, last before the first message. --session-id= is Claude
|
|
35
|
+
# Code's, so another harness (HARNESS, in task.sh) is given none, and both
|
|
36
|
+
# are left empty. Call it in the shell that starts the agent, not in a
|
|
37
|
+
# subshell: it sets them, and stops when no ID could be made.
|
|
38
|
+
SESSION='' SESSION_ARGS=()
|
|
39
|
+
session_new() {
|
|
40
|
+
SESSION='' SESSION_ARGS=()
|
|
41
|
+
[ "${HARNESS##*/}" = claude ] || return 0
|
|
42
|
+
SESSION=$(session_id) || exit 1
|
|
43
|
+
SESSION_ARGS=("--session-id=$SESSION")
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
# Make the sessions table on its first use, in a store that has the
|
|
47
|
+
# hand-offs' table too (store_ready), which `task log` reads in any store.
|
|
48
|
+
sessions_ready() {
|
|
49
|
+
store_ready &&
|
|
50
|
+
store "$STORE" 'create table if not exists sessions (
|
|
51
|
+
id integer primary key, at text not null, space text not null,
|
|
52
|
+
card text not null, phase text not null, harness text not null,
|
|
53
|
+
session text);'
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
# Note the session of an agent that is about to start, or has just started,
|
|
57
|
+
# timed now in UTC as a hand-off is. An empty session ID is recorded as null.
|
|
58
|
+
# Like record_start, it never fails the command that starts the agent: it
|
|
59
|
+
# only says when it could not record.
|
|
60
|
+
# session_record <space> <card> <phase> <harness> <session ID, or empty>
|
|
61
|
+
session_record() {
|
|
62
|
+
local at values='' v
|
|
63
|
+
if ! have_sqlite; then
|
|
64
|
+
say " note $SQLITE is not installed, so the agent's session is not recorded"
|
|
65
|
+
return 0
|
|
66
|
+
fi
|
|
67
|
+
at=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
|
68
|
+
for v in "$at" "$@"; do values="$values${values:+, }$(sql_str "$v")"; done
|
|
69
|
+
{ sessions_ready &&
|
|
70
|
+
store "$STORE" "insert into sessions (at, space, card, phase, harness, session) values ($values);"; } ||
|
|
71
|
+
say " note could not record the agent's session in $STORE"
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# Whether the store has the sessions table. A store made before sessions were
|
|
75
|
+
# recorded has none until an agent is started, and reading never makes it. It
|
|
76
|
+
# fails with 2 when the store cannot be read at all.
|
|
77
|
+
store_has_sessions() {
|
|
78
|
+
local n
|
|
79
|
+
[ -e "$STORE" ] || return 1
|
|
80
|
+
n=$(store "$STORE" "select count(*) from sqlite_master where type = 'table' and name = 'sessions';") || return 2
|
|
81
|
+
[ "$n" = 1 ]
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# Print a card's sessions, oldest first, a line each: when it was started,
|
|
85
|
+
# its phase, its harness and its session ID, which is empty for a harness
|
|
86
|
+
# other than claude, with SESSION_SEP between them. It prints nothing for a
|
|
87
|
+
# card with none, with no store, and for a store with no sessions table, and
|
|
88
|
+
# it makes neither. It fails only when the store cannot be read.
|
|
89
|
+
# card_sessions <space> <card>
|
|
90
|
+
card_sessions() {
|
|
91
|
+
local rc=0
|
|
92
|
+
have_sqlite || return 0
|
|
93
|
+
store_has_sessions || rc=$?
|
|
94
|
+
case $rc in
|
|
95
|
+
0) ;;
|
|
96
|
+
1) return 0 ;;
|
|
97
|
+
*) return 1 ;;
|
|
98
|
+
esac
|
|
99
|
+
store -separator "$SESSION_SEP" "$STORE" "select at, phase, harness, coalesce(session, '') from sessions
|
|
100
|
+
where space = $(sql_str "$1") and card = $(sql_str "$2") order by id;"
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
# Print the newest of a card's sessions, as card_sessions prints it, or the
|
|
104
|
+
# newest of one phase when $3 names it: the build agent started last, or the
|
|
105
|
+
# write-up agent. Nothing for a card with none, and it fails as card_sessions
|
|
106
|
+
# does.
|
|
107
|
+
# newest_session <space> <card> [<phase>]
|
|
108
|
+
newest_session() {
|
|
109
|
+
local rows at phase harness session found=''
|
|
110
|
+
rows=$(card_sessions "$1" "$2") || return 1
|
|
111
|
+
while IFS=$SESSION_SEP read -r at phase harness session; do
|
|
112
|
+
[ -n "$at" ] || continue
|
|
113
|
+
[ -z "${3:-}" ] || [ "$phase" = "$3" ] || continue
|
|
114
|
+
found=$at$SESSION_SEP$phase$SESSION_SEP$harness$SESSION_SEP$session
|
|
115
|
+
done <<< "$rows"
|
|
116
|
+
[ -z "$found" ] || printf '%s\n' "$found"
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
# Print the path of a session's transcript, <session ID>.jsonl in one of the
|
|
120
|
+
# folders under TRANSCRIPTS, or fail when Claude Code keeps none. Those
|
|
121
|
+
# folders' names start with a -, so each is looked in by its whole path.
|
|
122
|
+
# session_transcript <session ID>
|
|
123
|
+
session_transcript() {
|
|
124
|
+
local f
|
|
125
|
+
[ -n "${1:-}" ] || return 1
|
|
126
|
+
for f in "$TRANSCRIPTS"/*/"$1.jsonl"; do
|
|
127
|
+
[ -f "$f" ] || continue
|
|
128
|
+
printf '%s\n' "$f"
|
|
129
|
+
return 0
|
|
130
|
+
done
|
|
131
|
+
return 1
|
|
132
|
+
}
|
package/cli/lib/settings.sh
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
# The model and effort each agent profile runs on, whether a merged card is
|
|
2
2
|
# archived, how the runs of ocnus's own tests use the processors,
|
|
3
|
-
# whether breakdown asks the human to approve a card,
|
|
4
|
-
# agents run on,
|
|
3
|
+
# whether breakdown asks the human to approve a card, which account the
|
|
4
|
+
# agents run on, and whether the watch starts the cards a merge frees, kept
|
|
5
|
+
# in ocnus's settings file. Sourced by cli/ocnus.
|
|
5
6
|
|
|
6
7
|
# The file is $SETTINGS, ~/.config/ocnus/settings.json, beside the
|
|
7
8
|
# spaces. It is JSON, not lines of the env file: the settings button in
|
|
8
9
|
# Herdr, the agent-settings mod, reads and changes it through `ocnus
|
|
9
|
-
# profile`, `approval`, `linear archive` and `
|
|
10
|
-
# the keys.
|
|
10
|
+
# profile`, `approval`, `linear archive`, `tests`, `billing` and `chain`, and
|
|
11
|
+
# the env file holds the keys.
|
|
11
12
|
# {"profiles": {"write-up": {"model": "opus", "effort": "xhigh"}, ...},
|
|
12
13
|
# "archive": true, "tests": "queue", "approval": {"breakdown": false},
|
|
13
|
-
# "billing": "api"}
|
|
14
|
+
# "billing": "api", "chain": false}
|
|
14
15
|
# `install` and `update` make it when it is missing, and never change one
|
|
15
16
|
# that is there. A profile or a value the file leaves out is the default.
|
|
16
17
|
# "archive" is true or false, and off when the file leaves it out; neither
|
|
@@ -25,8 +26,11 @@
|
|
|
25
26
|
# human sets it with `ocnus approval --breakdown off` (approval.sh).
|
|
26
27
|
# "billing" is subscription or api, and subscription when the file leaves it
|
|
27
28
|
# out; neither writes it, so the agents run on an Anthropic API key only once
|
|
28
|
-
# the human sets it with `ocnus billing api` (billing.sh).
|
|
29
|
-
#
|
|
29
|
+
# the human sets it with `ocnus billing api` (billing.sh). "chain" is
|
|
30
|
+
# true or false, and on when the file leaves it out; neither writes it, so
|
|
31
|
+
# the watch on the merges stops starting the cards a merge frees only once
|
|
32
|
+
# the human sets it with `ocnus chain off` (chain.sh). Any other value
|
|
33
|
+
# makes the file not valid settings.
|
|
30
34
|
#
|
|
31
35
|
# Each profile's values reach claude in their own way:
|
|
32
36
|
# write-up, build `task new` and `task build` start claude with
|
|
@@ -91,18 +95,21 @@ profile_for() {
|
|
|
91
95
|
# What settings_load read: each profile's model and effort, in the order of
|
|
92
96
|
# PROFILES, the default where the file names none, whether archiving is on,
|
|
93
97
|
# true or false, how the test runs use the processors, share or queue,
|
|
94
|
-
# whether the breakdown approval is on, true or false,
|
|
95
|
-
# agents run on, subscription or api
|
|
96
|
-
# SETTINGS_WHY says why, as a message
|
|
98
|
+
# whether the breakdown approval is on, true or false, which account the
|
|
99
|
+
# agents run on, subscription or api, and whether the chain is on, true or
|
|
100
|
+
# false. When the file cannot be read, SETTINGS_WHY says why, as a message
|
|
101
|
+
# that stops a command.
|
|
97
102
|
SET_MODELS=() SET_EFFORTS=() SET_ARCHIVE=false SET_TESTS=share SET_APPROVAL_BREAKDOWN=true SET_BILLING=subscription
|
|
103
|
+
SET_CHAIN=true
|
|
98
104
|
SETTINGS_WHY='' SETTINGS_LOADED=0
|
|
99
105
|
|
|
100
106
|
# Every value the file holds, read with jq: one line for each profile it
|
|
101
107
|
# names, holding the profile, what its value is, its model and its effort,
|
|
102
108
|
# each as JSON and separated by tabs, so that no text in the file can add a
|
|
103
|
-
# line or a field. When the file has an "archive", a "tests" or
|
|
104
|
-
# "
|
|
105
|
-
# comes first: a profile's name is a JSON string, so it never starts
|
|
109
|
+
# line or a field. When the file has an "archive", a "tests", a "billing" or
|
|
110
|
+
# a "chain", a line @archive, @tests, @billing or @chain and its value, as
|
|
111
|
+
# JSON, comes first: a profile's name is a JSON string, so it never starts
|
|
112
|
+
# with @. When it has an "approval" that is
|
|
106
113
|
# an object, a line @approval, the approval's name and its value, each as
|
|
107
114
|
# JSON, comes next for each approval it names. A line starting with ! says
|
|
108
115
|
# what is wrong with the file as a whole, an "approval" that is not an object
|
|
@@ -117,6 +124,7 @@ SETTINGS_JQ='
|
|
|
117
124
|
(if has("archive") then "@archive\t" + (.archive | tojson) else empty end),
|
|
118
125
|
(if has("tests") then "@tests\t" + (.tests | tojson) else empty end),
|
|
119
126
|
(if has("billing") then "@billing\t" + (.billing | tojson) else empty end),
|
|
127
|
+
(if has("chain") then "@chain\t" + (.chain | tojson) else empty end),
|
|
120
128
|
(if has("approval") | not then empty
|
|
121
129
|
elif (.approval | type) != "object"
|
|
122
130
|
then "!its \"approval\" is " + (.approval | tojson) + ", which is not an object like {\"breakdown\":false}"
|
|
@@ -143,12 +151,13 @@ json_plain() {
|
|
|
143
151
|
}
|
|
144
152
|
|
|
145
153
|
# Read the settings file into SET_MODELS, SET_EFFORTS, SET_ARCHIVE,
|
|
146
|
-
# SET_TESTS, SET_APPROVAL_BREAKDOWN and
|
|
147
|
-
# SETTINGS_WHY saying what is wrong. With no file there is nothing to read,
|
|
154
|
+
# SET_TESTS, SET_APPROVAL_BREAKDOWN, SET_BILLING and SET_CHAIN, or return 1
|
|
155
|
+
# with SETTINGS_WHY saying what is wrong. With no file there is nothing to read,
|
|
148
156
|
# and no jq is needed.
|
|
149
157
|
settings_load() {
|
|
150
158
|
local out name kind model effort p i why=''
|
|
151
159
|
SET_MODELS=() SET_EFFORTS=() SET_ARCHIVE=false SET_TESTS=share SET_APPROVAL_BREAKDOWN=true SET_BILLING=subscription
|
|
160
|
+
SET_CHAIN=true
|
|
152
161
|
SETTINGS_WHY='' SETTINGS_LOADED=0
|
|
153
162
|
for p in $PROFILES; do SET_MODELS+=("$DEFAULT_MODEL"); SET_EFFORTS+=("$DEFAULT_EFFORT"); done
|
|
154
163
|
if [ ! -e "$SETTINGS" ] && [ ! -L "$SETTINGS" ]; then SETTINGS_LOADED=1; return 0; fi
|
|
@@ -191,6 +200,13 @@ settings_load() {
|
|
|
191
200
|
esac
|
|
192
201
|
continue
|
|
193
202
|
fi
|
|
203
|
+
if [ "$name" = @chain ]; then
|
|
204
|
+
case $kind in
|
|
205
|
+
true | false) SET_CHAIN=$kind ;;
|
|
206
|
+
*) why="its \"chain\" is $kind, which is not true or false"; break ;;
|
|
207
|
+
esac
|
|
208
|
+
continue
|
|
209
|
+
fi
|
|
194
210
|
# The approval's name is in kind, and its value in model.
|
|
195
211
|
if [ "$name" = @approval ]; then
|
|
196
212
|
if [ "$kind" != '"breakdown"' ]; then
|