@johngaynor/ocnus 0.0.0-stage → 2.0.0
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/LICENSE +21 -0
- package/README.md +988 -2
- package/agents/linear-mcp.json +1 -0
- package/agents/ocnus-build.md +23 -0
- package/agents/ocnus-write-up.md +20 -0
- package/cli/host-mark +36 -0
- package/cli/lib/agents.sh +350 -0
- package/cli/lib/approval.sh +94 -0
- package/cli/lib/archive.sh +447 -0
- package/cli/lib/billing.sh +166 -0
- package/cli/lib/close.sh +189 -0
- package/cli/lib/commands.sh +220 -0
- package/cli/lib/common.sh +215 -0
- package/cli/lib/finish.sh +288 -0
- package/cli/lib/github.sh +162 -0
- package/cli/lib/guard.sh +134 -0
- package/cli/lib/handoff.sh +551 -0
- package/cli/lib/host.sh +1802 -0
- package/cli/lib/linear.sh +1389 -0
- package/cli/lib/links.sh +135 -0
- package/cli/lib/merges.sh +853 -0
- package/cli/lib/recipes.sh +54 -0
- package/cli/lib/settings.sh +465 -0
- package/cli/lib/space.sh +343 -0
- package/cli/lib/task.sh +847 -0
- package/cli/lib/tests.sh +268 -0
- package/cli/lib/trust.sh +70 -0
- package/cli/ocnus +630 -0
- package/herdr/README.md +2238 -0
- package/herdr/layouts/default.json +259 -0
- package/herdr/mods/agent-settings/cog.svg +4 -0
- package/herdr/mods/agent-settings/main.js +356 -0
- package/herdr/mods/agent-settings/mod.json +1 -0
- package/herdr/mods/cards/main.js +450 -0
- package/herdr/mods/cards/mod.json +1 -0
- package/herdr/mods/cards/refresh.svg +4 -0
- package/herdr/mods/cpu/main.js +90 -0
- package/herdr/mods/cpu/mod.json +1 -0
- package/herdr/mods/layout-switch/main.js +48 -0
- package/herdr/mods/layout-switch/mod.json +1 -0
- package/herdr/mods/names/main.js +69 -0
- package/herdr/mods/names/mod.json +1 -0
- package/herdr/mods/ocnus-spaces/main.js +376 -0
- package/herdr/mods/ocnus-spaces/mod.json +1 -0
- package/herdr/mods/steps/main.js +354 -0
- package/herdr/mods/steps/mod.json +1 -0
- package/herdr/spaces/template/SPACE.md +19 -0
- package/package.json +27 -4
- package/prompts/task-build.md +11 -0
- package/prompts/task-new.md +17 -0
- package/skills/brief/SKILL.md +64 -0
- package/skills/sdlc-breakdown/SKILL.md +312 -0
- package/skills/sdlc-build/SKILL.md +182 -0
- package/skills/sdlc-define/SKILL.md +203 -0
- package/skills/sdlc-plan/SKILL.md +202 -0
- package/skills/sdlc-pr/SKILL.md +339 -0
- package/skills/sdlc-review/SKILL.md +227 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# What a repo provides: recipes in a justfile at its root (https://just.systems).
|
|
2
|
+
# ocnus knows recipes by name only, never what they do. This file is the
|
|
3
|
+
# only place that runs `just`.
|
|
4
|
+
|
|
5
|
+
have_just() { command -v just >/dev/null 2>&1; }
|
|
6
|
+
|
|
7
|
+
# Print the justfile at a folder's own root, or return 1 when it has none.
|
|
8
|
+
# `just` would also look in the folders above; a recipe from another repo's
|
|
9
|
+
# justfile must never be run in a repo, so only the root counts.
|
|
10
|
+
root_justfile() {
|
|
11
|
+
local dir=$1 name
|
|
12
|
+
for name in justfile Justfile .justfile; do
|
|
13
|
+
if [ -f "$dir/$name" ]; then printf '%s\n' "$dir/$name"; return 0; fi
|
|
14
|
+
done
|
|
15
|
+
return 1
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
# Print whether a folder provides a recipe, as one word:
|
|
19
|
+
# ok its justfile has the recipe
|
|
20
|
+
# no-justfile it has no justfile at its root
|
|
21
|
+
# no-recipe its justfile has no recipe of that name
|
|
22
|
+
# unreadable just could not read its justfile
|
|
23
|
+
recipe_state() {
|
|
24
|
+
local dir=$1 recipe=$2 file names
|
|
25
|
+
file=$(root_justfile "$dir") || { echo no-justfile; return 0; }
|
|
26
|
+
# --summary prints the recipe names on one line, separated by spaces.
|
|
27
|
+
names=$(just --justfile "$file" --summary 2>/dev/null) || { echo unreadable; return 0; }
|
|
28
|
+
case " $(printf '%s' "$names" | tr '\n\t' ' ') " in
|
|
29
|
+
*" $recipe "*) echo ok ;;
|
|
30
|
+
*) echo no-recipe ;;
|
|
31
|
+
esac
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# Print what a folder's setup makes again, as its `made-by-setup` recipe
|
|
35
|
+
# prints it: patterns like .gitignore's, one per line, such as node_modules/.
|
|
36
|
+
# `task finish` throws away the ignored files they match. When there is no
|
|
37
|
+
# such list it prints nothing on stdout, says why on stderr, and returns 1:
|
|
38
|
+
# just is not installed, there is no justfile or no such recipe, or the recipe
|
|
39
|
+
# failed. Nothing then counts as made again.
|
|
40
|
+
setup_makes() {
|
|
41
|
+
local dir=$1 file
|
|
42
|
+
have_just || { echo "just is not installed" >&2; return 1; }
|
|
43
|
+
case $(recipe_state "$dir" made-by-setup) in
|
|
44
|
+
ok) ;;
|
|
45
|
+
no-justfile) echo "it has no justfile" >&2; return 1 ;;
|
|
46
|
+
no-recipe) echo "its justfile has no made-by-setup recipe" >&2; return 1 ;;
|
|
47
|
+
*) echo "just could not read its justfile" >&2; return 1 ;;
|
|
48
|
+
esac
|
|
49
|
+
file=$(root_justfile "$dir")
|
|
50
|
+
# The recipe runs in the folder its justfile is in. It gets no stdin, so it
|
|
51
|
+
# cannot wait on the terminal.
|
|
52
|
+
just --justfile "$file" made-by-setup < /dev/null 2>/dev/null ||
|
|
53
|
+
{ echo "its made-by-setup recipe failed" >&2; return 1; }
|
|
54
|
+
}
|
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
# The model and effort each agent profile runs on, whether a merged card is
|
|
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.
|
|
5
|
+
|
|
6
|
+
# The file is $SETTINGS, ~/.config/ocnus/settings.json, beside the
|
|
7
|
+
# spaces. It is JSON, not lines of the env file: the settings button in
|
|
8
|
+
# 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.
|
|
11
|
+
# {"profiles": {"write-up": {"model": "opus", "effort": "xhigh"}, ...},
|
|
12
|
+
# "archive": true, "tests": "queue", "approval": {"breakdown": false},
|
|
13
|
+
# "billing": "api"}
|
|
14
|
+
# `install` and `update` make it when it is missing, and never change one
|
|
15
|
+
# that is there. A profile or a value the file leaves out is the default.
|
|
16
|
+
# "archive" is true or false, and off when the file leaves it out; neither
|
|
17
|
+
# `install` nor `update` writes it, so archiving is on only once the human
|
|
18
|
+
# turns it on with `ocnus linear archive on` (archive.sh). "tests" is
|
|
19
|
+
# share or queue, and share when the file leaves it out; neither writes it
|
|
20
|
+
# either, so the test runs go one at a time only once the human sets it with
|
|
21
|
+
# `ocnus tests queue` (tests.sh). test/run.sh reads it with jq alone.
|
|
22
|
+
# "approval" is an object holding true or false for each approval there is,
|
|
23
|
+
# which today is breakdown alone, and an approval it leaves out is on;
|
|
24
|
+
# neither writes it, so breakdown approves a card by itself only once the
|
|
25
|
+
# human sets it with `ocnus approval --breakdown off` (approval.sh).
|
|
26
|
+
# "billing" is subscription or api, and subscription when the file leaves it
|
|
27
|
+
# 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.
|
|
30
|
+
#
|
|
31
|
+
# Each profile's values reach claude in their own way:
|
|
32
|
+
# write-up, build `task new` and `task build` start claude with
|
|
33
|
+
# --model= and --effort=, which beat the profile's own
|
|
34
|
+
# model and the human's own Claude Code settings
|
|
35
|
+
# reviewer, verifier written into the frontmatter of the ocnus-reviewer
|
|
36
|
+
# and ocnus-verifier subagents in $AGENTS_HOME, on a
|
|
37
|
+
# clone: a subagent runs on the model and effort its own
|
|
38
|
+
# file names (write_review_profiles below)
|
|
39
|
+
|
|
40
|
+
# The profiles, in the order they are listed.
|
|
41
|
+
PROFILES='write-up build reviewer verifier'
|
|
42
|
+
DEFAULT_MODEL=opus
|
|
43
|
+
DEFAULT_EFFORT=xhigh
|
|
44
|
+
# claude's aliases for a model, each the latest of its kind.
|
|
45
|
+
MODEL_ALIASES='fable opus sonnet haiku'
|
|
46
|
+
# A model's full name: claude-opus-5-5, or claude-opus-5-5[1m] for its long
|
|
47
|
+
# context. Every letter is spelled out, as in valid_group.
|
|
48
|
+
MODEL_RE='^claude-[abcdefghijklmnopqrstuvwxyz0123456789.-]+(\[1m\])?$'
|
|
49
|
+
EFFORTS='low medium high xhigh max'
|
|
50
|
+
# What each of them takes, for the messages that refuse a value.
|
|
51
|
+
TAKES_PROFILE='write-up, build, reviewer or verifier'
|
|
52
|
+
TAKES_MODEL='an alias (fable, opus, sonnet or haiku) or a full model name, like claude-opus-5-5'
|
|
53
|
+
TAKES_EFFORT='low, medium, high, xhigh or max'
|
|
54
|
+
|
|
55
|
+
# Whether a word is one of the words after it.
|
|
56
|
+
one_of() {
|
|
57
|
+
local want=$1 w
|
|
58
|
+
shift
|
|
59
|
+
for w in "$@"; do [ "$w" != "$want" ] || return 0; done
|
|
60
|
+
return 1
|
|
61
|
+
}
|
|
62
|
+
# shellcheck disable=SC2086
|
|
63
|
+
is_profile() { one_of "${1-}" $PROFILES; }
|
|
64
|
+
# shellcheck disable=SC2086
|
|
65
|
+
is_effort() { one_of "${1-}" $EFFORTS; }
|
|
66
|
+
# shellcheck disable=SC2086
|
|
67
|
+
is_model() { one_of "${1-}" $MODEL_ALIASES || [[ ${1-} =~ $MODEL_RE ]]; }
|
|
68
|
+
|
|
69
|
+
# A profile's place in PROFILES, from 0.
|
|
70
|
+
profile_index() {
|
|
71
|
+
local p i=0
|
|
72
|
+
for p in $PROFILES; do
|
|
73
|
+
[ "$p" != "$1" ] || { printf '%s' "$i"; return 0; }
|
|
74
|
+
i=$((i + 1))
|
|
75
|
+
done
|
|
76
|
+
return 1
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
# What starts on each profile.
|
|
80
|
+
profile_for() {
|
|
81
|
+
case $1 in
|
|
82
|
+
write-up) say "task new" ;;
|
|
83
|
+
build) say "task build" ;;
|
|
84
|
+
reviewer) say "the ocnus-reviewer subagent" ;;
|
|
85
|
+
verifier) say "the ocnus-verifier subagent" ;;
|
|
86
|
+
esac
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
# --- reading the file -------------------------------------------------------
|
|
90
|
+
|
|
91
|
+
# What settings_load read: each profile's model and effort, in the order of
|
|
92
|
+
# PROFILES, the default where the file names none, whether archiving is on,
|
|
93
|
+
# 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.
|
|
97
|
+
SET_MODELS=() SET_EFFORTS=() SET_ARCHIVE=false SET_TESTS=share SET_APPROVAL_BREAKDOWN=true SET_BILLING=subscription
|
|
98
|
+
SETTINGS_WHY='' SETTINGS_LOADED=0
|
|
99
|
+
|
|
100
|
+
# Every value the file holds, read with jq: one line for each profile it
|
|
101
|
+
# names, holding the profile, what its value is, its model and its effort,
|
|
102
|
+
# 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
|
|
106
|
+
# an object, a line @approval, the approval's name and its value, each as
|
|
107
|
+
# JSON, comes next for each approval it names. A line starting with ! says
|
|
108
|
+
# what is wrong with the file as a whole, an "approval" that is not an object
|
|
109
|
+
# among them. -s reads every value in the file, so that an empty file, or one
|
|
110
|
+
# with two values, is caught.
|
|
111
|
+
SETTINGS_JQ='
|
|
112
|
+
if length == 0 then "!it is empty"
|
|
113
|
+
elif length > 1 then "!it holds more than one JSON value"
|
|
114
|
+
else .[0] |
|
|
115
|
+
if type != "object" then "!it is not a JSON object"
|
|
116
|
+
else
|
|
117
|
+
(if has("archive") then "@archive\t" + (.archive | tojson) else empty end),
|
|
118
|
+
(if has("tests") then "@tests\t" + (.tests | tojson) else empty end),
|
|
119
|
+
(if has("billing") then "@billing\t" + (.billing | tojson) else empty end),
|
|
120
|
+
(if has("approval") | not then empty
|
|
121
|
+
elif (.approval | type) != "object"
|
|
122
|
+
then "!its \"approval\" is " + (.approval | tojson) + ", which is not an object like {\"breakdown\":false}"
|
|
123
|
+
else .approval | to_entries[] | ["@approval", (.key | tojson), (.value | tojson)] | join("\t")
|
|
124
|
+
end),
|
|
125
|
+
(if .profiles == null then empty
|
|
126
|
+
elif (.profiles | type) != "object" then "!its \"profiles\" is not an object"
|
|
127
|
+
else .profiles | to_entries[] |
|
|
128
|
+
[(.key | tojson), (.value | type),
|
|
129
|
+
(if (.value | type) == "object" then (.value.model | tojson), (.value.effort | tojson)
|
|
130
|
+
else "null", "null" end)] | join("\t")
|
|
131
|
+
end)
|
|
132
|
+
end
|
|
133
|
+
end'
|
|
134
|
+
|
|
135
|
+
# A JSON string's text, when it is a plain one; anything else as it is, so
|
|
136
|
+
# that it is refused and shown as the file has it.
|
|
137
|
+
json_plain() {
|
|
138
|
+
case $1 in
|
|
139
|
+
\"*\\*) printf '%s' "$1" ;;
|
|
140
|
+
\"*\") local s=${1#\"}; printf '%s' "${s%\"}" ;;
|
|
141
|
+
*) printf '%s' "$1" ;;
|
|
142
|
+
esac
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
# 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,
|
|
148
|
+
# and no jq is needed.
|
|
149
|
+
settings_load() {
|
|
150
|
+
local out name kind model effort p i why=''
|
|
151
|
+
SET_MODELS=() SET_EFFORTS=() SET_ARCHIVE=false SET_TESTS=share SET_APPROVAL_BREAKDOWN=true SET_BILLING=subscription
|
|
152
|
+
SETTINGS_WHY='' SETTINGS_LOADED=0
|
|
153
|
+
for p in $PROFILES; do SET_MODELS+=("$DEFAULT_MODEL"); SET_EFFORTS+=("$DEFAULT_EFFORT"); done
|
|
154
|
+
if [ ! -e "$SETTINGS" ] && [ ! -L "$SETTINGS" ]; then SETTINGS_LOADED=1; return 0; fi
|
|
155
|
+
if [ ! -f "$SETTINGS" ]; then
|
|
156
|
+
SETTINGS_WHY="$SETTINGS is not a file, and ocnus reads each profile's model and effort from a file there. Move it aside, then run: ocnus update"
|
|
157
|
+
return 1
|
|
158
|
+
fi
|
|
159
|
+
if [ ! -r "$SETTINGS" ]; then
|
|
160
|
+
SETTINGS_WHY="cannot read $SETTINGS, which holds each profile's model and effort. Check its owner and permissions, then run this again."
|
|
161
|
+
return 1
|
|
162
|
+
fi
|
|
163
|
+
if ! command -v jq >/dev/null 2>&1; then
|
|
164
|
+
SETTINGS_WHY="jq is not installed, so $SETTINGS, which holds each profile's model and effort, cannot be read. Install it, then run this again."
|
|
165
|
+
return 1
|
|
166
|
+
fi
|
|
167
|
+
if ! out=$(jq -rs "$SETTINGS_JQ" "$SETTINGS" 2>&1); then
|
|
168
|
+
why="it is not JSON ($(printf '%s' "$out" | head -n 1 | sed 's/^jq: //'))"
|
|
169
|
+
else
|
|
170
|
+
while IFS=$'\t' read -r name kind model effort; do
|
|
171
|
+
[ -n "$name" ] || continue
|
|
172
|
+
case $name in '!'*) why=${name#!}; break ;; esac
|
|
173
|
+
if [ "$name" = @archive ]; then
|
|
174
|
+
case $kind in
|
|
175
|
+
true | false) SET_ARCHIVE=$kind ;;
|
|
176
|
+
*) why="its \"archive\" is $kind, which is not true or false"; break ;;
|
|
177
|
+
esac
|
|
178
|
+
continue
|
|
179
|
+
fi
|
|
180
|
+
if [ "$name" = @tests ]; then
|
|
181
|
+
case $kind in
|
|
182
|
+
'"share"' | '"queue"') SET_TESTS=$(json_plain "$kind") ;;
|
|
183
|
+
*) why="its \"tests\" is $kind, which is not share or queue"; break ;;
|
|
184
|
+
esac
|
|
185
|
+
continue
|
|
186
|
+
fi
|
|
187
|
+
if [ "$name" = @billing ]; then
|
|
188
|
+
case $kind in
|
|
189
|
+
'"subscription"' | '"api"') SET_BILLING=$(json_plain "$kind") ;;
|
|
190
|
+
*) why="its \"billing\" is $kind, which is not subscription or api"; break ;;
|
|
191
|
+
esac
|
|
192
|
+
continue
|
|
193
|
+
fi
|
|
194
|
+
# The approval's name is in kind, and its value in model.
|
|
195
|
+
if [ "$name" = @approval ]; then
|
|
196
|
+
if [ "$kind" != '"breakdown"' ]; then
|
|
197
|
+
why="its \"approval\" names $kind, which is not an approval: breakdown is the only one"; break
|
|
198
|
+
fi
|
|
199
|
+
case $model in
|
|
200
|
+
true | false) SET_APPROVAL_BREAKDOWN=$model ;;
|
|
201
|
+
*) why="its \"approval\" has \"breakdown\": $model, which is not true or false"; break ;;
|
|
202
|
+
esac
|
|
203
|
+
continue
|
|
204
|
+
fi
|
|
205
|
+
p=$(json_plain "$name")
|
|
206
|
+
if ! is_profile "$p"; then why="it names the profile $name, which is not one of $TAKES_PROFILE"; break; fi
|
|
207
|
+
if [ "$kind" != object ]; then why="its profile $name is a $kind, not an object holding a model and an effort"; break; fi
|
|
208
|
+
i=$(profile_index "$p")
|
|
209
|
+
if [ "$model" != null ]; then
|
|
210
|
+
if ! is_model "$(json_plain "$model")"; then why="the model of $p is $model, which is not $TAKES_MODEL"; break; fi
|
|
211
|
+
SET_MODELS[$i]=$(json_plain "$model")
|
|
212
|
+
fi
|
|
213
|
+
if [ "$effort" != null ]; then
|
|
214
|
+
if ! is_effort "$(json_plain "$effort")"; then why="the effort of $p is $effort, which is not $TAKES_EFFORT"; break; fi
|
|
215
|
+
SET_EFFORTS[$i]=$(json_plain "$effort")
|
|
216
|
+
fi
|
|
217
|
+
done <<< "$out"
|
|
218
|
+
fi
|
|
219
|
+
if [ -n "$why" ]; then
|
|
220
|
+
SETTINGS_WHY="$SETTINGS is not valid settings: $why. Fix that in the file, or move the file aside to go back to the defaults."
|
|
221
|
+
return 1
|
|
222
|
+
fi
|
|
223
|
+
SETTINGS_LOADED=1
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
# Read the settings file, or stop, saying what is wrong with it.
|
|
227
|
+
settings_check() { settings_load || die "$SETTINGS_WHY"; }
|
|
228
|
+
|
|
229
|
+
# A profile's model and effort, the default where the file names none.
|
|
230
|
+
profile_model() {
|
|
231
|
+
[ "$SETTINGS_LOADED" = 1 ] || settings_check
|
|
232
|
+
printf '%s\n' "${SET_MODELS[$(profile_index "$1")]}"
|
|
233
|
+
}
|
|
234
|
+
profile_effort() {
|
|
235
|
+
[ "$SETTINGS_LOADED" = 1 ] || settings_check
|
|
236
|
+
printf '%s\n' "${SET_EFFORTS[$(profile_index "$1")]}"
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
# --- making and changing the file -------------------------------------------
|
|
240
|
+
|
|
241
|
+
# The file `install` and `update` make: every profile on the default model at
|
|
242
|
+
# the default effort.
|
|
243
|
+
settings_default() {
|
|
244
|
+
local p sep=''
|
|
245
|
+
printf '{\n "profiles": {\n'
|
|
246
|
+
for p in $PROFILES; do
|
|
247
|
+
printf '%s "%s": { "model": "%s", "effort": "%s" }' "$sep" "$p" "$DEFAULT_MODEL" "$DEFAULT_EFFORT"
|
|
248
|
+
sep=$',\n'
|
|
249
|
+
done
|
|
250
|
+
printf '\n }\n}\n'
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
# Make the settings file when there is none. One that is there is the
|
|
254
|
+
# human's, so it is never changed, even when it is not valid settings.
|
|
255
|
+
settings_init() {
|
|
256
|
+
local tmp=$SETTINGS.ocnus.$$
|
|
257
|
+
[ ! -e "$SETTINGS" ] && [ ! -L "$SETTINGS" ] || return 0
|
|
258
|
+
mkdir -p "${SETTINGS%/*}"
|
|
259
|
+
if settings_default > "$tmp" && mv -f "$tmp" "$SETTINGS"; then
|
|
260
|
+
say " made $SETTINGS (every profile on $DEFAULT_MODEL at $DEFAULT_EFFORT effort)"
|
|
261
|
+
else
|
|
262
|
+
rm -f "$tmp"
|
|
263
|
+
say " note could not make $SETTINGS, so every profile runs on $DEFAULT_MODEL at $DEFAULT_EFFORT effort"
|
|
264
|
+
fi
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
need_jq() {
|
|
268
|
+
command -v jq >/dev/null 2>&1 ||
|
|
269
|
+
die "jq is not installed, and ocnus reads and changes $SETTINGS with it. Install it, then run this again."
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
# ocnus profile ls [--json]: each profile's model and effort, and what
|
|
273
|
+
# starts on it. --json prints them as one line for programs, with the models
|
|
274
|
+
# and efforts there are to choose from; the agent-settings mod reads it.
|
|
275
|
+
profile_ls() {
|
|
276
|
+
local json=0 p sep=''
|
|
277
|
+
case ${1:-} in
|
|
278
|
+
--json) json=1 ;;
|
|
279
|
+
'') ;;
|
|
280
|
+
*) die "unknown option for profile ls: $1" ;;
|
|
281
|
+
esac
|
|
282
|
+
[ "$#" -le 1 ] || die "usage: ocnus profile ls [--json]"
|
|
283
|
+
need_jq
|
|
284
|
+
settings_check
|
|
285
|
+
if [ "$json" = 0 ]; then
|
|
286
|
+
for p in $PROFILES; do
|
|
287
|
+
printf '%-9s %-8s %-7s %s\n' "$p" "$(profile_model "$p")" "$(profile_effort "$p")" "$(profile_for "$p")"
|
|
288
|
+
done
|
|
289
|
+
[ -e "$SETTINGS" ] || say "(no $SETTINGS, so these are the defaults; ocnus update makes the file)"
|
|
290
|
+
return
|
|
291
|
+
fi
|
|
292
|
+
printf '{"file":"%s","profiles":[' "$(json_str "$SETTINGS")"
|
|
293
|
+
for p in $PROFILES; do
|
|
294
|
+
printf '%s{"name":"%s","model":"%s","effort":"%s","for":"%s"}' "$sep" "$p" \
|
|
295
|
+
"$(json_str "$(profile_model "$p")")" "$(profile_effort "$p")" "$(profile_for "$p")"
|
|
296
|
+
sep=,
|
|
297
|
+
done
|
|
298
|
+
printf '],"models":['
|
|
299
|
+
sep=''
|
|
300
|
+
for p in $MODEL_ALIASES; do printf '%s"%s"' "$sep" "$p"; sep=,; done
|
|
301
|
+
printf '],"efforts":['
|
|
302
|
+
sep=''
|
|
303
|
+
for p in $EFFORTS; do printf '%s"%s"' "$sep" "$p"; sep=,; done
|
|
304
|
+
printf ']}\n'
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
# ocnus profile set <profile> <model|effort> <value>: change one value in
|
|
308
|
+
# the settings file. Everything is checked before the file is touched, and the
|
|
309
|
+
# new file is checked before it takes the old one's place, so a refusal or a
|
|
310
|
+
# failure leaves the file as it was.
|
|
311
|
+
profile_set() {
|
|
312
|
+
local p=${1:-} field=${2:-} value=${3:-} tmp ok=0
|
|
313
|
+
[ "$#" -eq 3 ] ||
|
|
314
|
+
die "usage: ocnus profile set <profile> <model|effort> <value>, like: ocnus profile set build effort high"
|
|
315
|
+
is_profile "$p" || die "'$p' is not a profile. It takes $TAKES_PROFILE."
|
|
316
|
+
case $field in
|
|
317
|
+
model) is_model "$value" || die "'$value' is not a model. A model is $TAKES_MODEL." ;;
|
|
318
|
+
effort) is_effort "$value" || die "'$value' is not an effort. An effort is $TAKES_EFFORT." ;;
|
|
319
|
+
*) die "'$field' is not something a profile sets. It takes model or effort, like: ocnus profile set $p effort high" ;;
|
|
320
|
+
esac
|
|
321
|
+
need_jq
|
|
322
|
+
settings_check
|
|
323
|
+
mkdir -p "${SETTINGS%/*}"
|
|
324
|
+
tmp=$SETTINGS.ocnus.$$
|
|
325
|
+
# With no file yet, the new one starts from the defaults, so that it names
|
|
326
|
+
# every profile.
|
|
327
|
+
if { if [ -e "$SETTINGS" ]; then cat "$SETTINGS"; else settings_default; fi; } |
|
|
328
|
+
jq --arg p "$p" --arg f "$field" --arg v "$value" '.profiles[$p][$f] = $v' > "$tmp" 2>/dev/null &&
|
|
329
|
+
[ "$(SETTINGS=$tmp; settings_load && "profile_$field" "$p")" = "$value" ] &&
|
|
330
|
+
mv -f "$tmp" "$SETTINGS"; then
|
|
331
|
+
ok=1
|
|
332
|
+
fi
|
|
333
|
+
rm -f "$tmp"
|
|
334
|
+
[ "$ok" = 1 ] || die "could not change $SETTINGS, so it is as it was."
|
|
335
|
+
settings_check
|
|
336
|
+
say "The $p profile's $field is $value now."
|
|
337
|
+
case $p in
|
|
338
|
+
write-up) say "The next ocnus task new starts with it." ;;
|
|
339
|
+
build) say "The next ocnus task build starts with it." ;;
|
|
340
|
+
*) if is_clone; then write_review_profiles "$p"
|
|
341
|
+
else say "Only a clone of ocnus has the review subagents, so nothing else was changed."
|
|
342
|
+
fi ;;
|
|
343
|
+
esac
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
# --- the review subagents ---------------------------------------------------
|
|
347
|
+
|
|
348
|
+
# The subagents for work on ocnus itself, ocnus-reviewer and
|
|
349
|
+
# ocnus-verifier, are .claude/profiles/<name>.md in the repo. They are
|
|
350
|
+
# written into $AGENTS_HOME with the model and effort the settings file names,
|
|
351
|
+
# rather than linked as the other profiles are: a subagent runs on the model
|
|
352
|
+
# and effort of its own frontmatter, the Agent tool takes no effort, and the
|
|
353
|
+
# files in the repo are the same in every checkout and worktree. They are out
|
|
354
|
+
# of .claude/agents/, because Claude Code prefers the agent of the repo it
|
|
355
|
+
# runs in to a person's of the same name. Only a clone writes them, since only a clone
|
|
356
|
+
# works on ocnus.
|
|
357
|
+
REVIEW_SOURCES=$REPO/.claude/profiles
|
|
358
|
+
# The comment that marks a file in $AGENTS_HOME as one ocnus wrote,
|
|
359
|
+
# followed by the file it was written from. ocnus replaces, and removes,
|
|
360
|
+
# only a file with this line in its frontmatter.
|
|
361
|
+
REVIEW_MARK='# Written by ocnus from '
|
|
362
|
+
|
|
363
|
+
# The settings profile of a source: ocnus-reviewer.md is the reviewer's.
|
|
364
|
+
review_profile_of() { local n=${1##*/}; n=${n%.md}; printf '%s' "${n#ocnus-}"; }
|
|
365
|
+
|
|
366
|
+
# The text ocnus writes for a source: the source, with model:, effort:
|
|
367
|
+
# and the mark after its tools: line, or at the end of its frontmatter.
|
|
368
|
+
# $1 the source $2 the model $3 the effort
|
|
369
|
+
review_text() {
|
|
370
|
+
SRC=$1 MODEL=$2 EFFORT=$3 MARK=$REVIEW_MARK P=$(review_profile_of "$1") awk '
|
|
371
|
+
function extra() {
|
|
372
|
+
print "model: " ENVIRON["MODEL"]
|
|
373
|
+
print "effort: " ENVIRON["EFFORT"]
|
|
374
|
+
print ENVIRON["MARK"] ENVIRON["SRC"]
|
|
375
|
+
print "# Change its model and effort with: ocnus profile set " ENVIRON["P"] " model|effort <value>"
|
|
376
|
+
done = 1
|
|
377
|
+
}
|
|
378
|
+
NR == 1 { print; head = ($0 == "---"); next }
|
|
379
|
+
head && $0 == "---" { if (!done) extra(); print; head = 0; next }
|
|
380
|
+
head && /^(model|effort):/ { next }
|
|
381
|
+
{ print }
|
|
382
|
+
head && !done && /^tools:/ { extra() }
|
|
383
|
+
' "$1"
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
# The source a file in $AGENTS_HOME says ocnus wrote it from, or nothing
|
|
387
|
+
# when ocnus did not write it: a link, or a file with no mark in its
|
|
388
|
+
# frontmatter, is someone else's.
|
|
389
|
+
review_source_of() {
|
|
390
|
+
[ -f "$1" ] && [ ! -L "$1" ] || return 0
|
|
391
|
+
MARK=$REVIEW_MARK awk '
|
|
392
|
+
NR == 1 { if ($0 != "---") exit; next }
|
|
393
|
+
$0 == "---" { exit }
|
|
394
|
+
index($0, ENVIRON["MARK"]) == 1 { print substr($0, length(ENVIRON["MARK"]) + 1); exit }
|
|
395
|
+
' "$1" 2>/dev/null || true
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
# written | stale | missing | skipped (someone else's file is there). With
|
|
399
|
+
# $3 set, the settings could not be read, so a file of ocnus's is taken
|
|
400
|
+
# as written without comparing it.
|
|
401
|
+
review_state() {
|
|
402
|
+
local src=$1 dst=$2 unread=${3:-} p
|
|
403
|
+
if [ ! -e "$dst" ] && [ ! -L "$dst" ]; then echo missing; return; fi
|
|
404
|
+
[ -n "$(review_source_of "$dst")" ] || { echo skipped; return; }
|
|
405
|
+
[ -z "$unread" ] || { echo written; return; }
|
|
406
|
+
p=$(review_profile_of "$src")
|
|
407
|
+
if [ "$(cat "$dst")" = "$(review_text "$src" "$(profile_model "$p")" "$(profile_effort "$p")")" ]; then
|
|
408
|
+
echo written
|
|
409
|
+
else
|
|
410
|
+
echo stale
|
|
411
|
+
fi
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
# Write each review subagent into $AGENTS_HOME, or only the profile named,
|
|
415
|
+
# where it is missing or stale, and remove one ocnus wrote whose source
|
|
416
|
+
# is no longer in the repo. A file of someone else's is left alone. Nothing is
|
|
417
|
+
# written when the settings cannot be read, and none of it stops the command
|
|
418
|
+
# it is part of.
|
|
419
|
+
write_review_profiles() {
|
|
420
|
+
local only=${1:-} src dst p model effort tmp from
|
|
421
|
+
is_clone || return 0
|
|
422
|
+
[ -d "$REVIEW_SOURCES" ] || [ -d "$AGENTS_HOME" ] || return 0
|
|
423
|
+
if ! settings_load; then
|
|
424
|
+
say " skipped the review subagents: $SETTINGS_WHY"
|
|
425
|
+
return 0
|
|
426
|
+
fi
|
|
427
|
+
for src in "$REVIEW_SOURCES"/*.md; do
|
|
428
|
+
[ -f "$src" ] || continue
|
|
429
|
+
p=$(review_profile_of "$src")
|
|
430
|
+
is_profile "$p" || continue
|
|
431
|
+
[ -z "$only" ] || [ "$p" = "$only" ] || continue
|
|
432
|
+
dst=$AGENTS_HOME/${src##*/}
|
|
433
|
+
model=$(profile_model "$p") effort=$(profile_effort "$p")
|
|
434
|
+
case $(review_state "$src" "$dst") in
|
|
435
|
+
written) [ -z "$only" ] || say " written $(label "$dst") ($model, $effort effort)" ;;
|
|
436
|
+
missing | stale)
|
|
437
|
+
mkdir -p "$AGENTS_HOME"
|
|
438
|
+
tmp=$dst.ocnus.$$
|
|
439
|
+
if review_text "$src" "$model" "$effort" > "$tmp" && mv -f "$tmp" "$dst"; then
|
|
440
|
+
say " wrote $(label "$dst") ($model, $effort effort)"
|
|
441
|
+
else
|
|
442
|
+
rm -f "$tmp"
|
|
443
|
+
say " skipped $(label "$dst") (it could not be written)"
|
|
444
|
+
fi
|
|
445
|
+
;;
|
|
446
|
+
skipped) say " skipped $(label "$dst") (a file of your own is there; move it aside to use ocnus's)" ;;
|
|
447
|
+
esac
|
|
448
|
+
done
|
|
449
|
+
[ -z "$only" ] || return 0
|
|
450
|
+
for dst in "$AGENTS_HOME"/*.md; do
|
|
451
|
+
from=$(review_source_of "$dst")
|
|
452
|
+
case $from in "$REVIEW_SOURCES"/*) ;; *) continue ;; esac
|
|
453
|
+
[ ! -e "$from" ] || continue
|
|
454
|
+
rm -f "$dst"
|
|
455
|
+
say " removed $(label "$dst") (no longer in the repo)"
|
|
456
|
+
done
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
cmd_profile() {
|
|
460
|
+
case ${1:-} in
|
|
461
|
+
ls | list) shift; profile_ls "$@" ;;
|
|
462
|
+
set) shift; profile_set "$@" ;;
|
|
463
|
+
*) die "usage: ocnus profile ls [--json], or: ocnus profile set <profile> <model|effort> <value> (see: ocnus help)" ;;
|
|
464
|
+
esac
|
|
465
|
+
}
|