@johngaynor/ocnus 2.0.1-next.27 → 2.0.1-next.69

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.
@@ -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, and which account the
4
- # agents run on, kept in ocnus's settings file. Sourced by cli/ocnus.
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 `tests`, and the env file holds
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). Any other
29
- # value makes the file not valid settings.
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, and which account the
95
- # agents run on, subscription or api. When the file cannot be read,
96
- # SETTINGS_WHY says why, as a message that stops a command.
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 a
104
- # "billing", a line @archive, @tests or @billing and its value, as JSON,
105
- # comes first: a profile's name is a JSON string, so it never starts with @. When it has an "approval" that is
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 SET_BILLING, or return 1 with
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
package/cli/lib/task.sh CHANGED
@@ -8,7 +8,10 @@
8
8
  # own, which runs `task build` to start the agent that builds
9
9
  # the card. The write-up agent runs it as soon as the card is
10
10
  # approved. It makes nothing for a card that a card not done
11
- # yet blocks, and the human runs it again once that is done.
11
+ # yet blocks, and puts its write-up session away: the chain
12
+ # starts it once that is done (chain.sh).
13
+ # task ready `task start` for every card of the space's Linear teams that
14
+ # waits and is ready, which the watch runs each half hour
12
15
  # The agent runs `task handoff` as each step ends, and `task log` shows what
13
16
  # it recorded. Both are in handoff.sh. While the pull requests wait on the
14
17
  # human, `task merges`, ocnus's watch on the merges, watches them on
@@ -48,17 +51,24 @@ PROFILE_MCP=$REPO/agents/linear-mcp.json
48
51
  # not read. Each flag holds its value after an =, because --mcp-config takes
49
52
  # several values and would take the first message as one of them. --model=
50
53
  # and --effort= beat the profile's own model and the human's own Claude Code
51
- # settings; only CLAUDE_CODE_EFFORT_LEVEL beats --effort=. While recording
52
- # is on, --settings= gives claude the hooks that mark the time of the agent
53
- # of that card's phase (host_hooks, in host.sh); when they cannot be given,
54
- # the agent starts without them.
54
+ # settings; only CLAUDE_CODE_EFFORT_LEVEL beats --effort=.
55
55
  #
56
- # On the subscription, --settings= also gives claude a statusLine: the
57
- # command Claude Code hands the subscription's usage limits to each time it
58
- # updates the status line, `ocnus usage record` (usage.sh), which saves
59
- # them for the Usage section and prints nothing. With hooks, it goes in their
60
- # object, put together with jq, which the hooks need anyway; without, in an
61
- # object of its own, which needs no jq. It overrides a statusLine of the
56
+ # One --settings= holds everything else claude is given, as one object. It
57
+ # always has the hook behind the agent's permission prompts (ask_hooks, in
58
+ # asks.sh), which lets the human see a prompt with `task asks` and answer it
59
+ # with `task answer`. While recording is on, it has the hooks that mark the
60
+ # time of the agent of that card's phase too (host_hooks, in host.sh), the
61
+ # permission hook beside theirs; when they cannot be given, the agent starts
62
+ # without them. They are put together with jq, which those hooks need
63
+ # anyway; the rest needs no jq, so an agent starts on a machine that has
64
+ # none.
65
+ #
66
+ # On either account, the object also gives claude a statusLine: the command
67
+ # Claude Code hands a JSON to each time it updates the status line, `ocnus
68
+ # usage record` with the agent's space, card, phase and account after it
69
+ # (usage_status_line, in usage.sh). It saves the subscription's usage limits
70
+ # for the Usage section, adds what the session has used to the cost file, as
71
+ # that card's (cost.sh), and prints nothing. It overrides a statusLine of the
62
72
  # human's own, for ocnus's agents alone.
63
73
  #
64
74
  # It also leaves in AGENT_ENV the words claude is started after, which run it
@@ -73,18 +83,19 @@ PROFILE_MCP=$REPO/agents/linear-mcp.json
73
83
  # Another harness gets no words, and starts as it always has.
74
84
  #
75
85
  # With billing on api (billing.sh), the agent runs on the Anthropic API key
76
- # the human saved instead: claude also gets --settings= holding an
77
- # apiKeyHelper, the command it runs to get the key, which comes before the
78
- # /login sign-in in Claude Code's order. The key itself is in no argument and
79
- # in no environment, and env's words still drop the exported variables,
80
- # which would come before the helper. With no key saved it stops, before an
81
- # agent is started. An agent on the API has no usage limits to read, so it
82
- # gets no statusLine. The profile's model and effort hold either way.
86
+ # the human saved instead: the object also holds an apiKeyHelper, the
87
+ # command claude runs to get the key, which comes before the /login sign-in
88
+ # in Claude Code's order. The key itself is in no argument and in no
89
+ # environment, and env's words still drop the exported variables, which
90
+ # would come before the helper. With no key saved it stops, before an agent
91
+ # is started. An agent on the API has no usage limits to read, and its
92
+ # statusLine records what its session used all the same, as spend. The
93
+ # profile's model and effort hold either way.
83
94
  # $1 the profile $2 its name in the settings file
84
95
  # $3 the space $4 the card $5 the phase, write-up or build
85
96
  PROFILE_ARGS=() AGENT_ENV=()
86
97
  profile_args() {
87
- local profile=$1 settings=$2 hooks line both
98
+ local profile=$1 settings=$2 hooks ask more both
88
99
  PROFILE_ARGS=() AGENT_ENV=()
89
100
  [ "${HARNESS##*/}" = claude ] || return 0
90
101
  [ -f "$AGENTS_HOME/$profile.md" ] ||
@@ -92,21 +103,25 @@ profile_args() {
92
103
  settings_check
93
104
  PROFILE_ARGS=("--agent=$profile" --strict-mcp-config "--mcp-config=$PROFILE_MCP"
94
105
  "--model=$(profile_model "$settings")" "--effort=$(profile_effort "$settings")")
95
- hooks=$(host_hooks "$3" "$4" "$5") || hooks=''
96
- if [ "$SET_BILLING" != api ]; then
97
- line=$(usage_status_line)
98
- if [ -z "$hooks" ]; then
99
- hooks="{\"statusLine\":$line}"
100
- elif both=$(jq -c --argjson line "$line" '.statusLine = $line' <<< "$hooks" 2>/dev/null) && [ -n "$both" ]; then
101
- hooks=$both
102
- fi
103
- fi
104
- [ -z "$hooks" ] || PROFILE_ARGS+=("--settings=$hooks")
105
106
  AGENT_ENV=(env -u ANTHROPIC_API_KEY -u ANTHROPIC_AUTH_TOKEN)
107
+ more="{\"statusLine\":$(usage_status_line "$3" "$4" "$5")}"
106
108
  if [ "$SET_BILLING" = api ]; then
107
109
  [ -n "$SAVED_ANTHROPIC_KEY" ] || die "$BILLING_NO_KEY"
108
- PROFILE_ARGS+=("--settings={\"apiKeyHelper\":\"$(json_str "$(billing_helper)")\"}")
110
+ more="{\"apiKeyHelper\":\"$(json_str "$(billing_helper)")\",${more#\{}"
109
111
  fi
112
+ ask=$(ask_hooks "$3" "$4") || ask=''
113
+ hooks=$(host_hooks "$3" "$4" "$5") || hooks=''
114
+ if [ -n "$hooks" ] && both=$(jq -c --argjson ask "${ask:-null}" --argjson more "$more" '
115
+ (if $ask == null then . else .hooks.PermissionRequest += $ask.hooks.PermissionRequest end) + $more' \
116
+ <<< "$hooks" 2>/dev/null) && [ -n "$both" ]; then
117
+ hooks=$both
118
+ elif [ -n "$ask" ]; then
119
+ # Each is one object on a line, so the two are joined as one, without jq.
120
+ hooks="${ask%\}},${more#\{}"
121
+ else
122
+ hooks=$more
123
+ fi
124
+ PROFILE_ARGS+=("--settings=$hooks")
110
125
  }
111
126
 
112
127
  # Stop if Linear has no such card, before an agent is started on it: a
@@ -277,6 +292,9 @@ task_new() {
277
292
  die "the $skill skill is not in $SKILLS_HOME, so the agent could not use it. Run: ocnus update"
278
293
  done
279
294
  profile_args "$CARD_PROFILE" "$CARD_SETTINGS" "$name" "$card" write-up
295
+ # claude is told the ID of its session, so that ocnus knows which
296
+ # conversation is this card's write-up agent's (sessions.sh).
297
+ session_new
280
298
  [ -f "$CARD_PROMPT" ] || die "the agent's first message is missing from $CARD_PROMPT"
281
299
  prompt=$(sed -e "s/{card}/$card/g" -e "s/{space}/$name/g" "$CARD_PROMPT")
282
300
  check_card "$card"
@@ -287,12 +305,15 @@ task_new() {
287
305
  # tab, because the agent meets the trust question the moment it starts.
288
306
  trust_space "$name"
289
307
  # The tab is named after the card, in the space's folder. The argv is env's
290
- # words, the harness and its profile's flags, then the agent's first message.
308
+ # words, the harness and its profile's flags, the session's flag, then the
309
+ # agent's first message.
291
310
  open_agent_tab "$name" "$dir" "$dir" "$card" "$card" "$prompt" ${AGENT_ENV[@]+"${AGENT_ENV[@]}"} \
292
- "$HARNESS" ${PROFILE_ARGS[@]+"${PROFILE_ARGS[@]}"} || die "$AGENT_ERROR"
311
+ "$HARNESS" ${PROFILE_ARGS[@]+"${PROFILE_ARGS[@]}"} ${SESSION_ARGS[@]+"${SESSION_ARGS[@]}"} || die "$AGENT_ERROR"
293
312
  record_start "$name" "$card"
313
+ session_record "$name" "$card" write-up "$HARNESS" "$SESSION"
294
314
  # An agent is open now, so recording, when it is on, starts (host.sh), and
295
- # ocnus's watch on the merges, while a card waits on one (merges.sh).
315
+ # ocnus's watch on the merges, while a card waits on one or its catch-up
316
+ # is due (merges.sh).
296
317
  host_wake
297
318
  merges_wake
298
319
  if [ "$AGENT_IN_APP" = 1 ]; then
@@ -579,18 +600,66 @@ parse_targets() {
579
600
  done
580
601
  }
581
602
 
603
+ # How `task start` starts what it says of a card it holds, after the card's
604
+ # ID. The chain tells a card that was held from a start that stopped by it
605
+ # (chain_start in chain.sh).
606
+ HELD_SAYS='is held: a card that blocks it is not done yet'
607
+
582
608
  # What `task start` says when it holds a card, from CARD_OPEN and
583
609
  # CARD_STATUS (card_branch): each card that blocks it, or the card it was
584
- # sliced from, and is not done yet, and that the card stays where it is.
610
+ # sliced from, and is not done yet, that the card stays where it is, and what
611
+ # starts it once they are done: ocnus's watch, with the chain on (chain.sh),
612
+ # or the human, with it off or with settings that cannot be read.
585
613
  # held_message <card ID>
586
614
  held_message() {
587
- local card=$1 where='where it is in Linear'
615
+ local card=$1 where='where it is in Linear' next='Run this again once the cards that block it are done.'
588
616
  [ -z "$CARD_STATUS" ] || where="in $CARD_STATUS"
589
- printf '%s is held: a card that blocks it is not done yet, so no task was made for it.\n' "$card"
617
+ if settings_load 2>/dev/null; then
618
+ if [ "$SET_CHAIN" = true ]; then
619
+ next="ocnus's watch starts it once the cards that block it are done."
620
+ else
621
+ next="The chain is off, so ocnus's watch will not start it: run this again once the cards that block it are done, or turn the chain on with: ocnus chain on"
622
+ fi
623
+ fi
624
+ printf '%s %s, so no task was made for it.\n' "$card" "$HELD_SAYS"
590
625
  printf '%s' "$CARD_OPEN" | jq -r --arg card "$card" '.[]
591
626
  | " blocker \(.id)\(if .status == "" then "" else ", in \(.status)," end) blocks "
592
627
  + (if .of == $card then $card else "\(.of), the card \($card) was sliced from" end)'
593
- printf '%s stays %s. Run this again once the cards that block it are done.' "$card" "$where"
628
+ printf '%s stays %s. %s' "$card" "$where" "$next"
629
+ }
630
+
631
+ # The write-up sessions `task start` puts away for a card (close.sh), into
632
+ # WRITEUPS: the card's own, and for a sub-issue its parent's, whose tab it
633
+ # was written up in (CARD_PARENT, from card_branch). Only one with a tab open
634
+ # in the space: a card started with no write-up session starts as before.
635
+ # writeups_open <space> <the space's folder> <card ID>
636
+ WRITEUPS=()
637
+ writeups_open() {
638
+ local name=$1 dir=$2 card=$3 writeup sep=$'\x1f' name_seen rest
639
+ WRITEUPS=()
640
+ agents_read "$name" "$dir"
641
+ for writeup in "$card" ${CARD_PARENT:+"$CARD_PARENT"}; do
642
+ while IFS=$sep read -r name_seen rest; do
643
+ [ "$name_seen" != "$writeup" ] || { WRITEUPS+=("$writeup"); break; }
644
+ done <<< "$AGENT_TABS"
645
+ done
646
+ }
647
+
648
+ # ocnus task ready <space>: start every card of the space's Linear teams
649
+ # that waits and is ready, and say what became of each card that waits
650
+ # (ready_cards in chain.sh). It is the catch-up for a start the watch missed
651
+ # at a merge, and what the watch itself runs for every space each half hour.
652
+ # It starts them whether the chain is on or off, since the human ran it, and
653
+ # exits non-zero when a card that was ready could not be started.
654
+ task_ready() {
655
+ local name=${1:-} dir
656
+ [ "$#" -le 1 ] || die "usage: ocnus task ready <space>, like: ocnus task ready $name"
657
+ dir=$(space_dir "$name")
658
+ # Each card's agent runs in a herdr-core terminal, so herdr-core has to be
659
+ # running before Linear is asked anything.
660
+ core_ready
661
+ ready_cards "$name" "$dir" named
662
+ [ "$CHAIN_FAILED" = 0 ] || exit 1
594
663
  }
595
664
 
596
665
  # What `task start` takes after the card.
@@ -668,8 +737,17 @@ task_start() {
668
737
  # once everything here has been checked.
669
738
  card_branch "$name" "$card" "$given_type" "$given_title"
670
739
  # A card waits until every card that blocks it, or the card it was sliced
671
- # from, is done, so it is held before anything is fetched or made.
672
- [ -z "$CARD_OPEN" ] || die "$(held_message "$card")"
740
+ # from, is done, so it is held before anything is fetched or made. All
741
+ # there is to know of a held card is in Linear, its status and its
742
+ # blockers, and the watch opens a new build tab when it starts it, so its
743
+ # write-up session is put away now, as it is once a build tab opens.
744
+ local writeup
745
+ if [ -n "$CARD_OPEN" ]; then
746
+ printf 'ocnus: %s\n' "$(held_message "$card")" >&2
747
+ writeups_open "$name" "$dir" "$card"
748
+ for writeup in ${WRITEUPS[@]+"${WRITEUPS[@]}"}; do start_close "$name" "$writeup" "$dir"; done
749
+ exit 1
750
+ fi
673
751
  branch=$BRANCH
674
752
  task=$(task_name "$branch")
675
753
  tdir=$dir/tasks/$task
@@ -734,18 +812,10 @@ task_start() {
734
812
  setup_line "$tdir" "${repos[@]}"
735
813
  build="ocnus task build $name $card"
736
814
  line=${SETUP_LINE:+$SETUP_LINE && }$build
737
- # The write-up sessions to put away once the build tab is open (close.sh):
738
- # the card's own, and for a sub-issue its parent's, whose tab it was written
739
- # up in. Only one with a tab open in the space: a card started with no
740
- # write-up session starts as before. They are looked for before the build
741
- # tab opens, which is the last thing the app is asked to do.
742
- local writeups=() writeup sep=$'\x1f' name_seen rest
743
- agents_read "$name" "$dir"
744
- for writeup in "$card" ${CARD_PARENT:+"$CARD_PARENT"}; do
745
- while IFS=$sep read -r name_seen rest; do
746
- [ "$name_seen" != "$writeup" ] || { writeups+=("$writeup"); break; }
747
- done <<< "$AGENT_TABS"
748
- done
815
+ # The write-up sessions to put away once the build tab is open. They are
816
+ # looked for before the build tab opens, which is the last thing the app is
817
+ # asked to do.
818
+ writeups_open "$name" "$dir" "$card"
749
819
  # The task exists now. If no tab can be opened for it, keep it, and say
750
820
  # where it is and how to start its agent.
751
821
  open_agent_tab "$name" "$dir" "$folder" "$task" "$card" '' /bin/sh -c "$line" ||
@@ -778,7 +848,7 @@ task_start() {
778
848
  record_start "$name" "$card" start "$notes"
779
849
  # The build phase has started, so the write-up sessions found above are put
780
850
  # away. This comes last, so that a task start that stops leaves them open.
781
- for writeup in ${writeups[@]+"${writeups[@]}"}; do start_close "$name" "$writeup" "$dir"; done
851
+ for writeup in ${WRITEUPS[@]+"${WRITEUPS[@]}"}; do start_close "$name" "$writeup" "$dir"; done
782
852
  say "Opened task '$task' on branch $branch"
783
853
  }
784
854
 
@@ -788,14 +858,21 @@ task_start() {
788
858
  # request. Run it again in the tab to start a new agent when the first one
789
859
  # has stopped.
790
860
  #
791
- # With --continue and a message, it continues claude's last session in this
792
- # folder instead, with that message: ocnus's watch on the merges types
861
+ # With --continue and a message, it continues the card's build session
862
+ # instead, with that message: ocnus's watch on the merges types
793
863
  # it into the tab's shell to wake an agent that has exited (merges.sh). The
794
864
  # session comes back with the build profile, model and effort, which a bare
795
865
  # `claude --continue` would not give it. Only claude has --continue.
866
+ #
867
+ # A new agent is told the ID of its session, which is recorded as the card's
868
+ # newest build session (sessions.sh). --continue continues that one by its
869
+ # ID, with --resume=<ID>, while Claude Code keeps its transcript. With none
870
+ # recorded, as for an agent started before sessions were, it is claude's
871
+ # last session in this folder, with claude's own --continue. Either way it is
872
+ # the same conversation, so no session is recorded for it.
796
873
  TASK_BUILD_USAGE='usage: ocnus task build <space> <card> [--continue <message>]'
797
874
  task_build() {
798
- local name=${1:-} card=${2:-} dir here low skill prompt again=''
875
+ local name=${1:-} card=${2:-} dir here low skill prompt again='' resume=--continue newest
799
876
  dir=$(space_dir "$name")
800
877
  [ -n "$card" ] ||
801
878
  die "which card? Usage: ocnus task build $name <card>, like: ocnus task build $name ABC-122"
@@ -808,7 +885,7 @@ task_build() {
808
885
  *) [ "$#" -le 2 ] || die "$TASK_BUILD_USAGE" ;;
809
886
  esac
810
887
  [ -z "$again" ] || [ "${HARNESS##*/}" = claude ] ||
811
- die "--continue is Claude Code's: it continues claude's last session in this folder, and the harness here is '$HARNESS'. Nothing was started."
888
+ die "--continue is Claude Code's: it continues the card's build session in claude, and the harness here is '$HARNESS'. Nothing was started."
812
889
  card=$(printf '%s' "$card" | tr '[:lower:]' '[:upper:]')
813
890
  low=$(printf '%s' "$card" | tr '[:upper:]' '[:lower:]')
814
891
  # The agent works in the folder it starts in, so that has to be this card's
@@ -829,22 +906,33 @@ task_build() {
829
906
  if [ -z "$again" ]; then
830
907
  [ -f "$BUILD_PROMPT" ] || die "the agent's first message is missing from $BUILD_PROMPT"
831
908
  prompt=$(sed -e "s/{card}/$card/g" -e "s/{space}/$name/g" "$BUILD_PROMPT")
909
+ session_new
910
+ else
911
+ # The session ID is the last value of the card's newest build row.
912
+ newest=$(newest_session "$name" "$card" build 2>/dev/null) || newest=''
913
+ newest=${newest##*"$SESSION_SEP"}
914
+ [ -z "$newest" ] || ! session_transcript "$newest" >/dev/null || resume="--resume=$newest"
832
915
  fi
833
916
  # The agent is about to start in this tab, so recording, when it is on,
834
917
  # starts too, as it does when the build agent is started again here, and
835
- # so does ocnus's watch on the merges, while a card waits on one.
918
+ # so does ocnus's watch on the merges, while a card waits on one or its
919
+ # catch-up is due.
836
920
  host_wake
837
921
  merges_wake
838
922
  # Every command the agent runs is named its space and card, so that
839
923
  # `ocnus tests run` records its test runs as this card's (tests.sh).
840
924
  export OCNUS_SPACE=$name OCNUS_CARD=$card
841
- # The first message goes last, after the profile's flags, and so does the
842
- # message a session continued with, after --continue. Either way claude
843
- # starts through env's words, without the variables that would put it on
844
- # the API (profile_args).
925
+ # The first message goes last, after the profile's flags and the session's,
926
+ # and so does the message a session continued with, after --continue or
927
+ # --resume=<ID>. Either way claude starts through env's words, without the
928
+ # variables that would put it on the API (profile_args).
845
929
  [ -z "$again" ] ||
846
- exec ${AGENT_ENV[@]+"${AGENT_ENV[@]}"} "$HARNESS" ${PROFILE_ARGS[@]+"${PROFILE_ARGS[@]}"} --continue "$again"
847
- exec ${AGENT_ENV[@]+"${AGENT_ENV[@]}"} "$HARNESS" ${PROFILE_ARGS[@]+"${PROFILE_ARGS[@]}"} "$prompt"
930
+ exec ${AGENT_ENV[@]+"${AGENT_ENV[@]}"} "$HARNESS" ${PROFILE_ARGS[@]+"${PROFILE_ARGS[@]}"} "$resume" "$again"
931
+ # Recorded before the agent takes this command's place, since nothing runs
932
+ # after it.
933
+ session_record "$name" "$card" build "$HARNESS" "$SESSION"
934
+ exec ${AGENT_ENV[@]+"${AGENT_ENV[@]}"} "$HARNESS" ${PROFILE_ARGS[@]+"${PROFILE_ARGS[@]}"} \
935
+ ${SESSION_ARGS[@]+"${SESSION_ARGS[@]}"} "$prompt"
848
936
  }
849
937
 
850
938
  # List the open cards of a space's Linear teams, grouped by status: the
@@ -890,12 +978,19 @@ cmd_task() {
890
978
  new) shift; task_new "$@" ;;
891
979
  ls | list) shift; task_ls "$@" ;;
892
980
  start) shift; task_start "$@" ;;
981
+ ready) shift; task_ready "$@" ;;
893
982
  build) shift; task_build "$@" ;;
894
983
  finish) shift; task_finish "$@" ;;
895
984
  close) shift; task_close "$@" ;;
896
985
  merges) shift; task_merges "$@" ;;
897
986
  handoff) shift; task_handoff "$@" ;;
898
987
  log) shift; task_log "$@" ;;
899
- *) die "usage: ocnus task ls <space> [--json], or: ocnus task new <space> <card>, or: ocnus task start <space> <card> $START_ARGS, or: ocnus task build <space> <card> [--continue <message>], or: ocnus task close <space> <card>, or: ocnus task finish <space> <card>, or: ocnus task merges [--once | --wake], or: ocnus task handoff <space> <card>, or: ocnus task log <space> [<card>] [--json] (see: ocnus help)" ;;
988
+ asks) shift; task_asks "$@" ;;
989
+ answer) shift; task_answer "$@" ;;
990
+ # The hook behind a permission prompt, which Claude Code runs (asks.sh).
991
+ # It decides nothing when anything goes wrong, so it never fails.
992
+ hold) shift; task_hold "$@" || true ;;
993
+ brief) shift; task_brief "$@" ;;
994
+ *) die "usage: ocnus task ls <space> [--json], or: ocnus task new <space> <card>, or: ocnus task start <space> <card> $START_ARGS, or: ocnus task ready <space>, or: ocnus task build <space> <card> [--continue <message>], or: ocnus task close <space> <card>, or: ocnus task finish <space> <card>, or: ocnus task merges [--once | --wake], or: ocnus task handoff <space> <card>, or: ocnus task log <space> [<card>] [--json], or: ocnus task asks <space> [--json], or: ocnus task answer <space> <card> <question> <answer>, or: ocnus task brief <space> <card> [--json] [--refresh] (see: ocnus help)" ;;
900
995
  esac
901
996
  }