@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.
- package/README.md +655 -106
- package/cli/lib/agents.sh +85 -34
- package/cli/lib/asks.sh +837 -0
- package/cli/lib/banner.sh +249 -0
- package/cli/lib/brief.sh +375 -0
- package/cli/lib/chain.sh +501 -0
- package/cli/lib/close.sh +5 -3
- package/cli/lib/commands.sh +42 -3
- package/cli/lib/cost.sh +505 -0
- package/cli/lib/events.sh +485 -0
- package/cli/lib/finish.sh +30 -4
- package/cli/lib/github.sh +106 -26
- package/cli/lib/guard.sh +41 -10
- package/cli/lib/handoff.sh +279 -37
- package/cli/lib/host.sh +470 -475
- package/cli/lib/linear.sh +428 -34
- package/cli/lib/links.sh +10 -7
- package/cli/lib/merges.sh +129 -30
- package/cli/lib/progress.sh +301 -0
- package/cli/lib/sessions.sh +132 -0
- package/cli/lib/settings.sh +35 -19
- package/cli/lib/task.sh +170 -54
- package/cli/lib/tests.sh +302 -7
- package/cli/lib/usage.sh +204 -0
- package/cli/ocnus +323 -73
- package/herdr/README.md +1264 -268
- package/herdr/layouts/default.json +30 -11
- package/herdr/layouts/showcase.json +314 -0
- package/herdr/layouts/vibe.json +169 -0
- package/herdr/layouts/vibe.svg +41 -0
- package/herdr/mods/agent-settings/main.js +19 -7
- package/herdr/mods/card-list/main.js +658 -0
- package/herdr/mods/card-list/mod.json +1 -0
- 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/needs-you/main.js +526 -0
- package/herdr/mods/needs-you/mod.json +1 -0
- 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 +5 -5
- package/skills/sdlc-build/SKILL.md +7 -3
- package/skills/sdlc-pr/SKILL.md +2 -2
- package/skills/sdlc-review/SKILL.md +5 -5
package/cli/lib/brief.sh
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
# The brief of a card's agent, from outside its tab: `ocnus task brief`.
|
|
2
|
+
# Sourced by cli/ocnus.
|
|
3
|
+
|
|
4
|
+
# The brief skill gives a brief in the session it is asked in: the original
|
|
5
|
+
# task, what has happened so far and what the agent is doing right now, in no
|
|
6
|
+
# more than five lines (skills/brief). `task brief` gets the human that brief
|
|
7
|
+
# of a card's agent without going near the agent. claude makes it in a copy of
|
|
8
|
+
# the card's newest Claude Code session, the one ocnus recorded when it
|
|
9
|
+
# started the agent (sessions.sh), asked with the /brief skill:
|
|
10
|
+
# claude -p --resume=<ID> --fork-session --no-session-persistence --tools=
|
|
11
|
+
# --strict-mcp-config --model=haiku --effort=low --output-format=json
|
|
12
|
+
# --fork-session gives the copy a session of its own and
|
|
13
|
+
# --no-session-persistence keeps it from being saved, so the agent's
|
|
14
|
+
# conversation gains no message and nothing is sent to its tab: the agent
|
|
15
|
+
# goes on as it was, whatever it is doing. The copy has no tools and no MCP
|
|
16
|
+
# servers, so it can only answer. In place of what the skill reads for
|
|
17
|
+
# itself, ocnus gives it the card's log, the card and its parent in Linear,
|
|
18
|
+
# and the commits on the task's branches, after `/brief ocnus task brief`,
|
|
19
|
+
# which the skill's section for such a copy starts from.
|
|
20
|
+
#
|
|
21
|
+
# The copy starts as an agent does (profile_args, in task.sh): without
|
|
22
|
+
# ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN, and with billing on api with
|
|
23
|
+
# the apiKeyHelper that gives it the saved key, so that a brief is paid for
|
|
24
|
+
# as the agents are. It starts without the variables of a Claude Code
|
|
25
|
+
# session that ran the command (without_claude_session), in the space's
|
|
26
|
+
# folder, which is there for as long as the space is: claude finds a session
|
|
27
|
+
# by its ID in any of its folders of transcripts, so a build session started
|
|
28
|
+
# in the task's folder, which `task finish` removes, is found from there.
|
|
29
|
+
#
|
|
30
|
+
# A new brief is a model call, so the last one of each card is kept, in the
|
|
31
|
+
# briefs table of the hand-off store, with the card's latest hand-off and the
|
|
32
|
+
# session it was made from. Asked again before the card has another hand-off,
|
|
33
|
+
# or another agent, the command gives the kept one, saying when it was made,
|
|
34
|
+
# with no model call; --refresh makes a new one. Nothing else is written: no
|
|
35
|
+
# hand-off and no session, and nothing in Linear, the space's repos or the
|
|
36
|
+
# task.
|
|
37
|
+
|
|
38
|
+
BRIEF_USAGE='usage: ocnus task brief <space> <card> [--json] [--refresh]'
|
|
39
|
+
# A brief only reads, so it is made on a small, quick model at low effort.
|
|
40
|
+
# OCNUS_BRIEF_MODEL picks another model.
|
|
41
|
+
BRIEF_DEFAULT_MODEL=haiku BRIEF_EFFORT=low
|
|
42
|
+
# What claude said, in a reason, is cut to this many characters.
|
|
43
|
+
BRIEF_SAID_MAX=400
|
|
44
|
+
# What stops a new brief on api with no key saved.
|
|
45
|
+
BRIEF_NO_KEY="billing is on api, and no Anthropic API key is saved, so no brief was made: a new brief is a model call, paid for as the agents are. Save one with: ocnus billing key, or go back to the subscription with: ocnus billing subscription"
|
|
46
|
+
|
|
47
|
+
# What task_brief found, for brief_show: the phase and the session ID of the
|
|
48
|
+
# card's newest agent, when the brief was made, whether it is the kept one
|
|
49
|
+
# (true or false), its three parts, and why there is none.
|
|
50
|
+
B_PHASE='' B_SESSION='' B_AT='' B_KEPT=false B_TASK='' B_SO_FAR='' B_NOW='' B_WHY=''
|
|
51
|
+
|
|
52
|
+
# ocnus task brief <space> <card> [--json] [--refresh]: give the brief of the
|
|
53
|
+
# card's newest agent, in words or, with --json, as one line for programs. It
|
|
54
|
+
# exits non-zero, saying why, when there is none.
|
|
55
|
+
task_brief() {
|
|
56
|
+
local json=0 refresh=0 a
|
|
57
|
+
local args=()
|
|
58
|
+
for a in "$@"; do
|
|
59
|
+
case $a in
|
|
60
|
+
--json) json=1 ;;
|
|
61
|
+
--refresh) refresh=1 ;;
|
|
62
|
+
-*) die "$BRIEF_USAGE" ;;
|
|
63
|
+
*) args+=("$a") ;;
|
|
64
|
+
esac
|
|
65
|
+
done
|
|
66
|
+
set -- ${args[@]+"${args[@]}"}
|
|
67
|
+
local name=${1:-} card=${2:-}
|
|
68
|
+
[ -n "$name" ] || die "$BRIEF_USAGE"
|
|
69
|
+
space_named "$name" || die "there is no ocnus space called '$name'. See: ocnus space ls"
|
|
70
|
+
[ "$#" -le 2 ] || die "$BRIEF_USAGE"
|
|
71
|
+
card=$(handoff_card "$name" "$card" brief) || exit 1
|
|
72
|
+
need_jq
|
|
73
|
+
settings_check
|
|
74
|
+
B_PHASE='' B_SESSION='' B_AT='' B_KEPT=false B_TASK='' B_SO_FAR='' B_NOW='' B_WHY=''
|
|
75
|
+
brief_find "$name" "$card" "$refresh"
|
|
76
|
+
brief_show "$name" "$card" "$json"
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
# Find the brief to give, into B_PHASE to B_NOW: the kept one, when the card
|
|
80
|
+
# has had no hand-off and no agent since it was made, or else a new one. When
|
|
81
|
+
# there is none it says why in B_WHY. Every reason there can be no new brief
|
|
82
|
+
# is found before claude is run.
|
|
83
|
+
# brief_find <space> <card> <refresh: 1 or 0>
|
|
84
|
+
brief_find() {
|
|
85
|
+
local name=$1 card=$2 refresh=$3 newest at harness handoff kept model
|
|
86
|
+
local k_at k_handoff k_session k_task k_so_far k_now
|
|
87
|
+
if ! have_sqlite; then
|
|
88
|
+
B_WHY="$SQLITE is not installed, so ocnus has recorded no agent's session on this machine, and there is no brief to give."
|
|
89
|
+
return
|
|
90
|
+
fi
|
|
91
|
+
newest=$(newest_session "$name" "$card") || die "could not read the hand-offs in $STORE. It may not be ocnus's store."
|
|
92
|
+
[ -z "$newest" ] || IFS=$SESSION_SEP read -r at B_PHASE harness B_SESSION <<< "$newest"
|
|
93
|
+
handoff=$(brief_handoff "$name" "$card") || die "could not read the hand-offs in $STORE. It may not be ocnus's store."
|
|
94
|
+
if [ "$refresh" = 0 ] && [ -n "$B_SESSION" ]; then
|
|
95
|
+
kept=$(brief_kept "$name" "$card") || die "could not read the briefs kept in $STORE. It may not be ocnus's store."
|
|
96
|
+
if [ -n "$kept" ]; then
|
|
97
|
+
IFS=$SESSION_SEP read -r k_at k_handoff k_session k_task k_so_far k_now <<< "$kept"
|
|
98
|
+
if [ "$k_handoff" = "$handoff" ] && [ "$k_session" = "$B_SESSION" ]; then
|
|
99
|
+
B_AT=$k_at B_KEPT=true B_TASK=$k_task B_SO_FAR=$k_so_far B_NOW=$k_now
|
|
100
|
+
return
|
|
101
|
+
fi
|
|
102
|
+
fi
|
|
103
|
+
fi
|
|
104
|
+
if [ -z "$newest" ]; then
|
|
105
|
+
B_WHY="ocnus has recorded no Claude Code session of $card's agent, so there is no brief to give: no agent was started on $card, or only before ocnus recorded sessions."
|
|
106
|
+
return
|
|
107
|
+
fi
|
|
108
|
+
if [ -z "$B_SESSION" ]; then
|
|
109
|
+
B_WHY="$card's $B_PHASE agent was started in $harness, not claude, so it has no Claude Code session to brief from."
|
|
110
|
+
return
|
|
111
|
+
fi
|
|
112
|
+
if ! session_transcript "$B_SESSION" >/dev/null; then
|
|
113
|
+
B_WHY="Claude Code no longer keeps the transcript of $card's $B_PHASE session, $B_SESSION, so there is nothing to brief from."
|
|
114
|
+
return
|
|
115
|
+
fi
|
|
116
|
+
if [ ! -f "$SKILLS_HOME/brief/SKILL.md" ]; then
|
|
117
|
+
B_WHY="the brief skill is not in $SKILLS_HOME, so Claude Code could not give the brief. Run: ocnus update"
|
|
118
|
+
return
|
|
119
|
+
fi
|
|
120
|
+
if [ "$SET_BILLING" = api ] && [ -z "$SAVED_ANTHROPIC_KEY" ]; then
|
|
121
|
+
B_WHY=$BRIEF_NO_KEY
|
|
122
|
+
return
|
|
123
|
+
fi
|
|
124
|
+
model=${OCNUS_BRIEF_MODEL:-$BRIEF_DEFAULT_MODEL}
|
|
125
|
+
if ! is_model "$model"; then
|
|
126
|
+
B_WHY="OCNUS_BRIEF_MODEL is '$model', which is not $TAKES_MODEL, so no brief was made."
|
|
127
|
+
return
|
|
128
|
+
fi
|
|
129
|
+
if ! command -v "$harness" >/dev/null 2>&1; then
|
|
130
|
+
B_WHY="'$harness', which started $card's $B_PHASE agent, is not on your PATH, so no brief was made."
|
|
131
|
+
return
|
|
132
|
+
fi
|
|
133
|
+
brief_make "$name" "$card" "$harness" "$model" "$handoff"
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
# Print the id of the card's latest hand-off, the row the brief is made at,
|
|
137
|
+
# or nothing when it has none.
|
|
138
|
+
# brief_handoff <space> <card>
|
|
139
|
+
brief_handoff() {
|
|
140
|
+
[ -e "$STORE" ] || return 0
|
|
141
|
+
store "$STORE" "select coalesce(max(id), '') from handoffs where space = $(sql_str "$1") and card = $(sql_str "$2");"
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
# Print the card's kept brief, with SESSION_SEP between its values: when it
|
|
145
|
+
# was made, the hand-off it was made at, the session it was made from, then
|
|
146
|
+
# its three parts. Nothing when no brief of the card is kept, and none when
|
|
147
|
+
# the store has no briefs table, which is made only to keep one.
|
|
148
|
+
# brief_kept <space> <card>
|
|
149
|
+
brief_kept() {
|
|
150
|
+
local n
|
|
151
|
+
[ -e "$STORE" ] || return 0
|
|
152
|
+
n=$(store "$STORE" "select count(*) from sqlite_master where type = 'table' and name = 'briefs';") || return 1
|
|
153
|
+
[ "$n" = 1 ] || return 0
|
|
154
|
+
store -separator "$SESSION_SEP" "$STORE" "select at, coalesce(handoff, ''), session, task, so_far, now from briefs
|
|
155
|
+
where space = $(sql_str "$1") and card = $(sql_str "$2");"
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
# Keep the brief just made, in place of the card's last one, with the
|
|
159
|
+
# hand-off it was made at and the session it was made from. A brief that
|
|
160
|
+
# cannot be kept is still given, with a note that the next one is a model
|
|
161
|
+
# call too.
|
|
162
|
+
# brief_keep <space> <card> <hand-off id, or empty>
|
|
163
|
+
brief_keep() {
|
|
164
|
+
store "$STORE" "create table if not exists briefs (
|
|
165
|
+
space text not null, card text not null, at text not null, handoff integer,
|
|
166
|
+
session text not null, task text not null, so_far text not null, now text not null,
|
|
167
|
+
primary key (space, card));
|
|
168
|
+
insert or replace into briefs (space, card, at, handoff, session, task, so_far, now)
|
|
169
|
+
values ($(sql_str "$1"), $(sql_str "$2"), $(sql_str "$B_AT"), $(sql_str "$3"), $(sql_str "$B_SESSION"),
|
|
170
|
+
$(sql_str "$B_TASK"), $(sql_str "$B_SO_FAR"), $(sql_str "$B_NOW"));" ||
|
|
171
|
+
printf 'ocnus: could not keep the brief in %s, so asking again makes a new one.\n' "$STORE" >&2
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
# Make a new brief: run claude on a copy of the session in B_SESSION, with
|
|
175
|
+
# the prompt brief_prompt writes on its stdin, and take the brief's three
|
|
176
|
+
# parts out of its answer. When claude exits non-zero, its answer is marked
|
|
177
|
+
# as an error, or it has not all three parts, it says why in B_WHY, with
|
|
178
|
+
# what Claude Code said, and keeps nothing.
|
|
179
|
+
# brief_make <space> <card> <the claude to run> <model> <hand-off id, or empty>
|
|
180
|
+
brief_make() {
|
|
181
|
+
local name=$1 card=$2 harness=$3 model=$4 handoff=$5 dir scratch rc=0 said result error
|
|
182
|
+
local args=(-p "--resume=$B_SESSION" --fork-session --no-session-persistence --tools= --strict-mcp-config
|
|
183
|
+
"--model=$model" "--effort=$BRIEF_EFFORT" --output-format=json)
|
|
184
|
+
# The account the agents run on (profile_args): with billing on api, the
|
|
185
|
+
# apiKeyHelper that gives claude the saved key, which is in no argument.
|
|
186
|
+
[ "$SET_BILLING" != api ] || args+=("--settings={\"apiKeyHelper\":\"$(json_str "$(billing_helper)")\"}")
|
|
187
|
+
dir=$(cd -P "$SPACES/$name" && pwd)
|
|
188
|
+
scratch=$(mktemp -d) || die "could not make a folder for the brief's prompt. No brief was made."
|
|
189
|
+
# shellcheck disable=SC2064
|
|
190
|
+
trap "rm -rf $(sh_quote "$scratch")" EXIT
|
|
191
|
+
trap 'exit 130' INT
|
|
192
|
+
trap 'exit 143' TERM
|
|
193
|
+
brief_prompt "$name" "$card" "$dir" "$scratch" > "$scratch/prompt"
|
|
194
|
+
if (without_claude_session; cd "$dir" && exec env -u ANTHROPIC_API_KEY -u ANTHROPIC_AUTH_TOKEN "$harness" "${args[@]}") \
|
|
195
|
+
< "$scratch/prompt" > "$scratch/out" 2> "$scratch/err"; then
|
|
196
|
+
rc=0
|
|
197
|
+
else
|
|
198
|
+
rc=$?
|
|
199
|
+
fi
|
|
200
|
+
# Claude Code's JSON is one value: its answer is .result, and is_error is
|
|
201
|
+
# true when it is not one.
|
|
202
|
+
result=$(jq -rs 'last | if type == "object" and (.result | type) == "string" then .result else empty end' \
|
|
203
|
+
"$scratch/out" 2>/dev/null) || result=''
|
|
204
|
+
error=$(jq -rs 'last | if type == "object" then (.is_error == true | tostring) else "none" end' \
|
|
205
|
+
"$scratch/out" 2>/dev/null) || error=none
|
|
206
|
+
said=$(brief_said "$(cat "$scratch/err" 2>/dev/null)")
|
|
207
|
+
[ -n "$said" ] || said=$(brief_said "$result")
|
|
208
|
+
[ -n "$said" ] || said=$(brief_said "$(cat "$scratch/out" 2>/dev/null)")
|
|
209
|
+
rm -rf "$scratch"
|
|
210
|
+
trap - EXIT INT TERM
|
|
211
|
+
if [ "$rc" != 0 ]; then
|
|
212
|
+
B_WHY="Claude Code could not make the brief: claude exited $rc${said:+, saying: $said}"
|
|
213
|
+
elif [ "$error" = none ]; then
|
|
214
|
+
B_WHY="Claude Code's answer was not the JSON ocnus asked for, so there is no brief${said:+. It said: $said}"
|
|
215
|
+
elif [ "$error" = true ]; then
|
|
216
|
+
B_WHY="Claude Code could not make the brief${said:+: $said}"
|
|
217
|
+
elif ! brief_parts "$result"; then
|
|
218
|
+
B_WHY="Claude Code gave no brief with its three parts, Task, So far and Now${said:+. It said: $said}"
|
|
219
|
+
fi
|
|
220
|
+
if [ -n "$B_WHY" ]; then
|
|
221
|
+
B_TASK='' B_SO_FAR='' B_NOW=''
|
|
222
|
+
return
|
|
223
|
+
fi
|
|
224
|
+
B_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
|
225
|
+
brief_keep "$name" "$card" "$handoff"
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
# Write the copy's prompt: the brief skill's name and `ocnus task brief`,
|
|
229
|
+
# which its section for such a copy starts from, then what the skill reads
|
|
230
|
+
# for a card: its log, whose last line is what Herdr sees of the agent, the
|
|
231
|
+
# card and its parent in Linear, and, while the task's folder is there, the
|
|
232
|
+
# commits on its branch in each of its worktrees. A part that cannot be read
|
|
233
|
+
# says why, and the brief is still made.
|
|
234
|
+
# brief_prompt <space> <card> <the space's folder> <a folder for its files>
|
|
235
|
+
brief_prompt() {
|
|
236
|
+
local name=$1 card=$2 dir=$3 scratch=$4 parent tdir why i wt base log
|
|
237
|
+
printf '/brief ocnus task brief %s %s\n\n' "$name" "$card"
|
|
238
|
+
printf '%s\n\n' "ocnus made you from a copy of the session of $card's $B_PHASE agent, in the ocnus space $name, to give the human its brief from outside the agent's tab. The agent goes on in its tab without you. Here is what the brief skill reads for a card, read by ocnus as the copy was made."
|
|
239
|
+
brief_part "ocnus task log $name $card" "$scratch" task_log "$name" "$card"
|
|
240
|
+
brief_part "ocnus linear read $card" "$scratch" linear_read "$card"
|
|
241
|
+
# The card's parent is on a line of its own in the card's head, which ends
|
|
242
|
+
# at its first empty line.
|
|
243
|
+
parent=$(printf '%s\n' "$BRIEF_READ" |
|
|
244
|
+
sed -n -e '/^$/q' -e 's/^Parent: \([A-Za-z][A-Za-z0-9]*-[0-9][0-9]*\) .*$/\1/p' | head -n 1) || parent=''
|
|
245
|
+
[ -z "$parent" ] || brief_part "ocnus linear read $parent, $card's parent" "$scratch" linear_read "$parent"
|
|
246
|
+
printf '## The commits on the task'\''s branch\n\n'
|
|
247
|
+
if ! tdir=$(task_folder "$dir" "$card" 2>"$scratch/part-err"); then
|
|
248
|
+
why=$(brief_plain "$(sed 's/^ocnus: //' "$scratch/part-err")")
|
|
249
|
+
printf '%s\n' "${why% Nothing was changed.}"
|
|
250
|
+
return
|
|
251
|
+
fi
|
|
252
|
+
if ! task_worktrees "$dir" "$tdir" "$card"; then
|
|
253
|
+
# Its reason is the watch's on the merges, which a brief has no use for.
|
|
254
|
+
why=$TASK_WHY
|
|
255
|
+
case $why in *', so it has no pull request to watch.') why="${why%, so it has no pull request to watch.}." ;; esac
|
|
256
|
+
printf 'They could not be read: %s\n' "$why"
|
|
257
|
+
return
|
|
258
|
+
fi
|
|
259
|
+
for i in "${!TASK_WTS[@]}"; do
|
|
260
|
+
wt=${TASK_WTS[$i]}
|
|
261
|
+
base=$(base_ref "$wt" 2>/dev/null) || base=''
|
|
262
|
+
if [ -z "$base" ]; then
|
|
263
|
+
printf '%s, on %s: its default branch could not be found, so its commits could not be read.\n\n' \
|
|
264
|
+
"${wt##*/}" "${TASK_BRANCHES[$i]}"
|
|
265
|
+
continue
|
|
266
|
+
fi
|
|
267
|
+
printf '%s, on %s: git log --oneline %s..HEAD\n' "${wt##*/}" "${TASK_BRANCHES[$i]}" "$base"
|
|
268
|
+
log=$(git -C "$wt" log --oneline "$base..HEAD" 2>&1) || log="It could not be read: $(brief_plain "$log")"
|
|
269
|
+
printf '%s\n\n' "${log:-No commits yet.}"
|
|
270
|
+
done
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
# Write one part of the prompt: a heading, then what the command printed, run
|
|
274
|
+
# in a subshell of its own, or why it could not be read. What it printed is
|
|
275
|
+
# left in BRIEF_READ too, which is empty when it failed.
|
|
276
|
+
# brief_part <heading> <a folder for its files> <command> [<argument>...]
|
|
277
|
+
BRIEF_READ=''
|
|
278
|
+
brief_part() {
|
|
279
|
+
local title=$1 scratch=$2 why
|
|
280
|
+
shift 2
|
|
281
|
+
printf '## %s\n\n' "$title"
|
|
282
|
+
if BRIEF_READ=$("$@" 2>"$scratch/part-err"); then
|
|
283
|
+
printf '%s\n\n' "${BRIEF_READ:-It printed nothing.}"
|
|
284
|
+
return
|
|
285
|
+
fi
|
|
286
|
+
BRIEF_READ=''
|
|
287
|
+
why=$(brief_plain "$(sed 's/^ocnus: //' "$scratch/part-err")")
|
|
288
|
+
printf 'It could not be read: %s\n\n' "${why:-the command failed.}"
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
# Take the brief's three parts out of claude's answer, each made one plain
|
|
292
|
+
# line, into B_TASK, B_SO_FAR and B_NOW, or fail when one is missing or
|
|
293
|
+
# empty. A part is the text after its name, **Task:**, **So far:** or
|
|
294
|
+
# **Now:**, up to the next part's name: Task and So far may run onto more
|
|
295
|
+
# lines, but Now is the rest of its own line. What comes before Task, such as
|
|
296
|
+
# a line saying here is the brief, and what comes after Now's line, such as
|
|
297
|
+
# the agent's question asked again, is dropped, and so is a list's mark left
|
|
298
|
+
# before a part's name.
|
|
299
|
+
brief_parts() {
|
|
300
|
+
local text=$1 line part='' task='' so_far='' now='' mark
|
|
301
|
+
local only_mark='^[[:space:]]*([-*+]|[0-9]+[.)])?[[:space:]]*$'
|
|
302
|
+
# Each part's name starts a line of its own, so that what is before it on
|
|
303
|
+
# its line, such as a list's mark, is left on the line before.
|
|
304
|
+
for mark in '**Task:**' '**So far:**' '**Now:**'; do
|
|
305
|
+
text=${text//"$mark"/$'\n'"$mark"}
|
|
306
|
+
done
|
|
307
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
308
|
+
case $line in
|
|
309
|
+
'**Task:**'*) part=task task=${line#'**Task:**'} ;;
|
|
310
|
+
'**So far:**'*)
|
|
311
|
+
[ "$part" = task ] || return 1
|
|
312
|
+
part=so_far so_far=${line#'**So far:**'} ;;
|
|
313
|
+
'**Now:**'*)
|
|
314
|
+
[ "$part" = so_far ] || return 1
|
|
315
|
+
part=now now=${line#'**Now:**'}
|
|
316
|
+
break ;;
|
|
317
|
+
*)
|
|
318
|
+
[[ ! $line =~ $only_mark ]] || continue
|
|
319
|
+
case $part in
|
|
320
|
+
task) task="$task $line" ;;
|
|
321
|
+
so_far) so_far="$so_far $line" ;;
|
|
322
|
+
esac ;;
|
|
323
|
+
esac
|
|
324
|
+
done <<< "$text"
|
|
325
|
+
[ "$part" = now ] || return 1
|
|
326
|
+
B_TASK=$(brief_plain "$task") B_SO_FAR=$(brief_plain "$so_far") B_NOW=$(brief_plain "$now")
|
|
327
|
+
[ -n "$B_TASK" ] && [ -n "$B_SO_FAR" ] && [ -n "$B_NOW" ]
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
# Text made one plain line: each control character, a newline among them, a
|
|
331
|
+
# space, as plain_note makes one, then each run of spaces one space, with
|
|
332
|
+
# none at either end.
|
|
333
|
+
brief_plain() {
|
|
334
|
+
local s
|
|
335
|
+
s=$(plain_note "$1" | tr -s ' ')
|
|
336
|
+
s=${s#"${s%%[![:space:]]*}"}
|
|
337
|
+
printf '%s' "${s%"${s##*[![:space:]]}"}"
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
# What Claude Code said, for a reason: one plain line, cut to
|
|
341
|
+
# BRIEF_SAID_MAX characters.
|
|
342
|
+
brief_said() {
|
|
343
|
+
local s
|
|
344
|
+
s=$(brief_plain "$1")
|
|
345
|
+
[ "${#s}" -le "$BRIEF_SAID_MAX" ] || s="${s:0:$BRIEF_SAID_MAX}..."
|
|
346
|
+
printf '%s' "$s"
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
# Give what brief_find found: in words, a first line with the card, its
|
|
350
|
+
# agent's phase, when the brief was made and whether it is the kept one, then
|
|
351
|
+
# Task, So far and Now, a line each; with --json, one line with each of them.
|
|
352
|
+
# With no brief, it says why, on stderr in words, and exits non-zero.
|
|
353
|
+
# brief_show <space> <card> <json: 1 or 0>
|
|
354
|
+
brief_show() {
|
|
355
|
+
local name=$1 card=$2 json=$3
|
|
356
|
+
if [ "$json" = 1 ]; then
|
|
357
|
+
jq -cn --arg space "$name" --arg card "$card" --arg phase "$B_PHASE" --arg session "$B_SESSION" \
|
|
358
|
+
--arg at "$B_AT" --argjson kept "$B_KEPT" --arg task "$B_TASK" --arg so_far "$B_SO_FAR" \
|
|
359
|
+
--arg now "$B_NOW" --arg why "$B_WHY" '
|
|
360
|
+
def v: if . == "" then null else . end;
|
|
361
|
+
{space: $space, card: $card, phase: ($phase | v), session: ($session | v), at: ($at | v),
|
|
362
|
+
kept: $kept, task: ($task | v), so_far: ($so_far | v), now: ($now | v), why: ($why | v)}'
|
|
363
|
+
[ -z "$B_WHY" ] || exit 1
|
|
364
|
+
return 0
|
|
365
|
+
fi
|
|
366
|
+
[ -z "$B_WHY" ] || die "$B_WHY"
|
|
367
|
+
if [ "$B_KEPT" = true ]; then
|
|
368
|
+
say "Brief of $card's $B_PHASE agent, kept from $B_AT: no hand-off since, so no model call (--refresh makes a new one)"
|
|
369
|
+
else
|
|
370
|
+
say "Brief of $card's $B_PHASE agent, made $B_AT"
|
|
371
|
+
fi
|
|
372
|
+
say "Task: $B_TASK"
|
|
373
|
+
say "So far: $B_SO_FAR"
|
|
374
|
+
say "Now: $B_NOW"
|
|
375
|
+
}
|