@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
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
# What a card's agents did, step by step: `ocnus task events`. Sourced by
|
|
2
|
+
# cli/ocnus.
|
|
3
|
+
|
|
4
|
+
# The list is read from three places, and nothing is written to any of them:
|
|
5
|
+
# - the card's steps, from the hand-off store through log_view
|
|
6
|
+
# (handoff.sh), so that they cannot disagree with `task log`. A step is
|
|
7
|
+
# each time the card was in it, as `host report --card` has it
|
|
8
|
+
# (host_card, in host.sh), so that the Trace's layers line up: hand-offs
|
|
9
|
+
# of one step in a row, from the hand-off before the first to the last.
|
|
10
|
+
# The step under way is open and runs to now. `new` and `start` have no
|
|
11
|
+
# entry.
|
|
12
|
+
# - the card's sessions, which `task new` and `task build` record as they
|
|
13
|
+
# start its agents (card_sessions, in sessions.sh): when each started,
|
|
14
|
+
# its phase and its session ID.
|
|
15
|
+
# - each session's transcript, <session ID>.jsonl, which Claude Code keeps
|
|
16
|
+
# (session_transcript), read by EVENTS_READ.
|
|
17
|
+
# An entry of a write-up session, a line of its transcript, goes in define,
|
|
18
|
+
# plan or breakdown, and one of a build session in build, review or pr, of
|
|
19
|
+
# the run the session started in: the first of those steps that ends at or
|
|
20
|
+
# after the entry's second, else the last. So the command that records a
|
|
21
|
+
# hand-off is in the step it ends, the write-up agent's `task start` is
|
|
22
|
+
# under breakdown, and nothing a session wrote lands in the other phase's
|
|
23
|
+
# steps. A step is recorded when a transcript has an entry in it, and so is
|
|
24
|
+
# the step under way once the newest session of its phase has a transcript,
|
|
25
|
+
# so that a step that has just started is not taken for one whose agent was
|
|
26
|
+
# not recorded. Any other step is not recorded: its events are null, never a
|
|
27
|
+
# list with nothing in it.
|
|
28
|
+
#
|
|
29
|
+
# What makes an event, in the main conversation, a subagent's left out:
|
|
30
|
+
# edit an Edit or Write call that worked. Calls with no other event
|
|
31
|
+
# between them, in one step, are one event, which names each file
|
|
32
|
+
# once: from the folder the session started in, or by its whole
|
|
33
|
+
# path outside it.
|
|
34
|
+
# test run a Bash call whose command, with its heredocs' bodies taken out,
|
|
35
|
+
# runs `ocnus tests run`. Its totals are the last line it printed
|
|
36
|
+
# with "<n> passed", and "<n> failed" from that line when it is
|
|
37
|
+
# there: the form of ocnus's own runner, jest, vitest, pytest and
|
|
38
|
+
# cargo. A run whose output went to a file, or that ran in the
|
|
39
|
+
# background, takes them from the first command after it that
|
|
40
|
+
# names the file and printed such a line, up to a test run that
|
|
41
|
+
# writes the file again. With no result, or in the background
|
|
42
|
+
# with neither totals nor Claude Code's notice that it ended, it
|
|
43
|
+
# is running; with no such line it has no totals.
|
|
44
|
+
# commit a Bash call that worked, runs `git commit` and printed the new
|
|
45
|
+
# commit: git's own "[<branch> <hash>] <subject>" line, or a
|
|
46
|
+
# `git log --oneline` line whose subject is the first line of the
|
|
47
|
+
# message the command gave, or the first such line when it gave
|
|
48
|
+
# none, as `git commit --no-edit` does. One that printed neither
|
|
49
|
+
# is a command.
|
|
50
|
+
# question an `ocnus task handoff` call that worked and whose block says
|
|
51
|
+
# status: needs-human: its question line.
|
|
52
|
+
# answer a prompt the human typed: not the first prompt of a transcript,
|
|
53
|
+
# which is ocnus's first message, not one from ocnus's watch,
|
|
54
|
+
# which starts ocnus-merges:, and not brief or /brief.
|
|
55
|
+
# command any other Bash call: what it was for, as the agent described it
|
|
56
|
+
# when it ran it, or the program it ran when it gave no
|
|
57
|
+
# description.
|
|
58
|
+
# Every text is one line of at most EVENTS_TEXT_MAX characters. Of what a
|
|
59
|
+
# command printed, only a test run's totals and a commit's hash and subject
|
|
60
|
+
# are given, and nothing of a file's contents or a diff is.
|
|
61
|
+
|
|
62
|
+
EVENTS_USAGE='usage: ocnus task events <space> <card> [--step <step>] [--json]'
|
|
63
|
+
# The most characters a text holds. A longer one is cut, and ends with ...
|
|
64
|
+
EVENTS_TEXT_MAX=200
|
|
65
|
+
|
|
66
|
+
# What every jq program here starts with. one makes a text one line of at
|
|
67
|
+
# most $max characters: control characters, newlines among them, become
|
|
68
|
+
# spaces, and runs of spaces one.
|
|
69
|
+
# shellcheck disable=SC2016
|
|
70
|
+
EVENTS_DEFS='
|
|
71
|
+
def one: gsub("[[:cntrl:]]"; " ") | gsub(" {2,}"; " ") | ltrimstr(" ") | rtrimstr(" ")
|
|
72
|
+
| if length > $max then .[0:$max - 3] + "..." else . end;
|
|
73
|
+
'
|
|
74
|
+
|
|
75
|
+
# The jq that reads one session's transcript, as raw lines on stdin, and
|
|
76
|
+
# prints the session as one line of JSON for EVENTS_JOIN: when it started
|
|
77
|
+
# and its phase, $at and $phase, read true, entries, the second of each line
|
|
78
|
+
# of the main conversation, and events, each with its second, the number of
|
|
79
|
+
# its line and of its block in the line, its kind, its text and what its
|
|
80
|
+
# kind has (an edit has the one file it changed, which EVENTS_JOIN joins).
|
|
81
|
+
# A line that is not whole JSON, such as the one Claude Code is writing, is
|
|
82
|
+
# passed over, and so is one with no time. Each line is made small as it is
|
|
83
|
+
# read, so that a long transcript is never held whole:
|
|
84
|
+
# nohd a command with its heredocs' bodies taken out, so that what an
|
|
85
|
+
# agent writes into a file or a hand-off is never taken for a
|
|
86
|
+
# command it ran
|
|
87
|
+
# words a command's words, without quotes, for finding a file it names
|
|
88
|
+
# targets the files a command sends its output to, as > or >> name them
|
|
89
|
+
# program the program a command runs: past assignments and cd
|
|
90
|
+
# asked a hand-off block's question, when its status is needs-human
|
|
91
|
+
# message the first line of the message a `git commit` gives, with -m or
|
|
92
|
+
# --message, in quotes or a heredoc
|
|
93
|
+
# result what a call's result holds: whether it failed, and for a
|
|
94
|
+
# command's, whether it went to the background and the file it
|
|
95
|
+
# writes, its totals, git's line for a commit, and the first
|
|
96
|
+
# `git log --oneline` lines
|
|
97
|
+
# said what a prompt the human typed says, or null when it is not an
|
|
98
|
+
# answer
|
|
99
|
+
# A command's result is read from what Claude Code kept of it: stdout and
|
|
100
|
+
# stderr, or for one that failed, its text, which starts with its exit code.
|
|
101
|
+
# \u0027 is a single quote.
|
|
102
|
+
# shellcheck disable=SC2016
|
|
103
|
+
EVENTS_READ='
|
|
104
|
+
def stamp: if type == "string" and test("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}")
|
|
105
|
+
then (try (.[0:19] + "Z" | fromdateiso8601) catch null) else null end;
|
|
106
|
+
def text_of: if type == "string" then .
|
|
107
|
+
elif type == "array" then [.[] | objects | select(.type == "text") | .text | strings] | join("\n")
|
|
108
|
+
else "" end;
|
|
109
|
+
def plain: gsub("\u001b\\[[0-9;?]*[ -/]*[@-~]"; "");
|
|
110
|
+
def bare: gsub("[\"\u0027]"; "");
|
|
111
|
+
def nohd:
|
|
112
|
+
reduce (split("\n")[] | rtrimstr("\r")) as $l ({out: [], wait: []};
|
|
113
|
+
if (.wait | length) > 0 then
|
|
114
|
+
(if .wait[0].dash then ($l | sub("^\t+"; "")) else $l end) as $c
|
|
115
|
+
| if $c == .wait[0].word then .wait |= .[1:] else . end
|
|
116
|
+
else
|
|
117
|
+
.out += [$l]
|
|
118
|
+
| .wait = [$l | match("(?<!<)<<(?!<)(-?)[ \t]*\\\\?([\"\u0027]?)([A-Za-z0-9_.-]+)\\2"; "g")
|
|
119
|
+
| {dash: (.captures[0].string == "-"), word: .captures[2].string}]
|
|
120
|
+
end)
|
|
121
|
+
| .out | join("\n");
|
|
122
|
+
def words: [splits("[\\s;&|()<>]+") | bare | select(length > 0)];
|
|
123
|
+
def targets: [match("(?<![0-9<>&])(?:&|1)?>>?(?!&)[ \t]*(\"[^\"]*\"|\u0027[^\u0027]*\u0027|[^\\s;&|()<>]+)"; "g")
|
|
124
|
+
| .captures[0].string | bare | select(length > 0 and (startswith("/dev/") | not))];
|
|
125
|
+
def runs($re): test("(^|[\\s;&|(!{])([^\\s;&|(){}<>]*/)?" + $re + "(\\s|$)");
|
|
126
|
+
def program:
|
|
127
|
+
[splits("&&|\\|\\||[;|&\n]")
|
|
128
|
+
| [splits("[\\s()]+") | select(length > 0)]
|
|
129
|
+
| until(length == 0 or (.[0] | test("^([A-Za-z_][A-Za-z0-9_]*=.*|!|\\{|\\}|then|do|else|time)$") | not); .[1:])
|
|
130
|
+
| select(length > 0 and .[0] != "cd" and .[0] != "pushd" and (.[0] | startswith("#") | not))
|
|
131
|
+
| .[0] | bare | sub(".*/"; "") | select(length > 0)]
|
|
132
|
+
| .[0] // "";
|
|
133
|
+
def asked:
|
|
134
|
+
[split("\n")[] | rtrimstr("\r")] as $ls
|
|
135
|
+
| if any($ls[]; test("^[ \t]*status:[ \t]*needs-human[ \t]*$"))
|
|
136
|
+
then [$ls[] | capture("^[ \t]*question:[ \t]*(?<q>.*[^ \t])[ \t]*$") | .q] | .[0]
|
|
137
|
+
else null end;
|
|
138
|
+
def commit_re: "(^|[\\s;&|(!{])git(\\s+-[Cc]\\s+\\S+|\\s+--?[A-Za-z]\\S*)*\\s+commit(\\s|$)";
|
|
139
|
+
def message:
|
|
140
|
+
([match(commit_re)] | .[0]) as $m
|
|
141
|
+
| if $m == null then null
|
|
142
|
+
else .[$m.offset + $m.length - 1:]
|
|
143
|
+
| ([capture("(?:^|\\s)(?:-[A-Za-z]*m|--message)(?:[ \t]+|=)?(?:\"\\$\\(cat[ \t]+<<-?[ \t]*\\\\?[\"\u0027]?[A-Za-z0-9_.-]+[\"\u0027]?[ \t]*\n(?<hb>[^\n]*)|\u0027(?<sq>[^\u0027]*)\u0027|\"(?<dq>(?:[^\"\\\\]|\\\\.)*)\"|(?<w>[^\\s;&|()<>\"\u0027]+))")] | .[0])
|
|
144
|
+
| if . == null then null
|
|
145
|
+
elif .hb != null then .hb
|
|
146
|
+
elif .sq != null then .sq
|
|
147
|
+
elif .dq != null then .dq | gsub("\\\\(?<c>[\"\\\\$`])"; .c)
|
|
148
|
+
else .w end
|
|
149
|
+
| if . == null then null else split("\n")[0] | one end
|
|
150
|
+
end;
|
|
151
|
+
def bash_call:
|
|
152
|
+
(.command | if type == "string" then . else "" end) as $cmd
|
|
153
|
+
| ($cmd | nohd) as $run
|
|
154
|
+
| ($run | test(commit_re)) as $commit
|
|
155
|
+
| {test: ($run | runs("ocnus\\s+tests\\s+run")),
|
|
156
|
+
question: (if $run | runs("ocnus\\s+task\\s+handoff") then $cmd | asked else null end),
|
|
157
|
+
commit: $commit,
|
|
158
|
+
message: (if $commit then $cmd | message else null end),
|
|
159
|
+
desc: (.description | if type == "string" then one else "" end),
|
|
160
|
+
targets: ($run | targets),
|
|
161
|
+
words: ($run | words),
|
|
162
|
+
program: ($run | program)};
|
|
163
|
+
def result($t; $b):
|
|
164
|
+
(.content | text_of) as $text
|
|
165
|
+
| (($t | type) == "string" or (($t | type) == "object" and ($t | has("stdout"))) or $t == null) as $shell
|
|
166
|
+
| {k: "result", b: $b, id: .tool_use_id, err: (.is_error == true)}
|
|
167
|
+
+ (if $shell | not then {}
|
|
168
|
+
else
|
|
169
|
+
((if ($t | type) == "object" and ($t.stdout | type) == "string"
|
|
170
|
+
then $t.stdout + "\n" + ($t.stderr | if type == "string" then . else "" end)
|
|
171
|
+
else $text end) | plain | split("\n")) as $out
|
|
172
|
+
| {bg: ((($t | type) == "object" and $t.backgroundTaskId != null)
|
|
173
|
+
or ($text | startswith("Command running in background"))),
|
|
174
|
+
bgfile: (if ($t | type) == "object" and ($t.backgroundOutputPath | type) == "string"
|
|
175
|
+
then $t.backgroundOutputPath
|
|
176
|
+
else [$text | capture("Output is being written to: (?<f>\\S+?)\\.?(\\s|$)") | .f] | .[0] end),
|
|
177
|
+
totals: ([$out[] | select(test("[0-9]+ passed"))] | last
|
|
178
|
+
| if . == null then null
|
|
179
|
+
else {passed: (capture("(?<n>[0-9]+) passed") | .n | tonumber),
|
|
180
|
+
failed: ([capture("(?<n>[0-9]+) failed") | .n | tonumber] | .[0])} end),
|
|
181
|
+
git: ([$out[] | capture("^\\[[^\\]]* (?<hash>[0-9a-f]{7,40})\\] (?<subject>.+)$")] | .[0]),
|
|
182
|
+
onelines: [limit(50; $out[] | capture("^(?<hash>[0-9a-f]{7,40}) (?:\\([^)]*\\) )?(?<subject>.+)$"))]}
|
|
183
|
+
end);
|
|
184
|
+
def from_assistant:
|
|
185
|
+
(.message | if type == "object" then .content else null end)
|
|
186
|
+
| if type == "array" then to_entries[] else empty end
|
|
187
|
+
| .key as $b | .value | objects
|
|
188
|
+
| select(.type == "tool_use" and (.id | type) == "string")
|
|
189
|
+
| (.input | if type == "object" then . else {} end) as $in
|
|
190
|
+
| if .name == "Bash" then {k: "call", b: $b, id, name: "Bash"} + ($in | bash_call)
|
|
191
|
+
elif .name == "Edit" or .name == "Write" then {k: "call", b: $b, id, name: "Edit", file: ($in.file_path | strings)}
|
|
192
|
+
else empty end;
|
|
193
|
+
def from_user:
|
|
194
|
+
(.message | if type == "object" then .content else null end) as $c
|
|
195
|
+
| [$c | if type == "array" then .[] else empty end | objects | select(.type == "tool_result")] as $rs
|
|
196
|
+
| if ($rs | length) > 0 then
|
|
197
|
+
.toolUseResult as $tur
|
|
198
|
+
| $rs | to_entries[] | .key as $b | .value
|
|
199
|
+
| result(if ($rs | length) == 1 then $tur else null end; $b)
|
|
200
|
+
elif .isMeta == true or .isCompactSummary == true then empty
|
|
201
|
+
else
|
|
202
|
+
($c | text_of) as $text
|
|
203
|
+
| (.origin | if type == "object" then .kind else null end) as $origin
|
|
204
|
+
| if $origin == "task-notification" or ($text | test("^\\s*<task-notification>")) then
|
|
205
|
+
[$text | capture("<tool-use-id>(?<id>[^<]+)</tool-use-id>") | {k: "ended", id}] | .[0] // empty
|
|
206
|
+
else {k: "prompt", human: ($origin == "human"), text: $text} end
|
|
207
|
+
end;
|
|
208
|
+
def said:
|
|
209
|
+
(if test("<command-name>") then
|
|
210
|
+
([capture("<command-name>(?<n>[^<]*)</command-name>") | .n] | .[0] // "")
|
|
211
|
+
+ ([capture("<command-args>(?<a>[^<]*)</command-args>") | .a] | .[0] // "" | if length > 0 then " " + . else "" end)
|
|
212
|
+
else . end | one) as $t
|
|
213
|
+
| if $t == "" or ($t | ascii_downcase | . == "brief" or . == "/brief")
|
|
214
|
+
or ($t | startswith("ocnus-merges:")) or ($t | startswith("[Request interrupted"))
|
|
215
|
+
or test("^\\s*<(local-command-|bash-|system-reminder|task-notification)")
|
|
216
|
+
then null else $t end;
|
|
217
|
+
[inputs | (try fromjson catch null) | objects
|
|
218
|
+
| select((.type == "user" or .type == "assistant") and .isSidechain != true)
|
|
219
|
+
| (.timestamp | stamp) as $sec | select($sec != null)
|
|
220
|
+
| {sec: $sec, cwd: (.cwd | if type == "string" then . else null end),
|
|
221
|
+
items: [if .type == "assistant" then from_assistant else from_user end]}]
|
|
222
|
+
| . as $lines
|
|
223
|
+
| (first($lines[] | .cwd | strings) // null) as $cwd
|
|
224
|
+
| [range(0; $lines | length) as $i | $lines[$i] | .sec as $sec | .items[] | . + {i: $i, sec: $sec}] as $items
|
|
225
|
+
| [$items[] | select(.k == "call" and .name == "Bash")] as $bash
|
|
226
|
+
| (reduce range(0; $bash | length) as $x ({}; .[$bash[$x].id] = $x)) as $pos
|
|
227
|
+
| (reduce ($items[] | select(.k == "result" and (.id | type) == "string")) as $r ({};
|
|
228
|
+
if has($r.id) then . else .[$r.id] = $r end)) as $res
|
|
229
|
+
| (reduce ($items[] | select(.k == "ended")) as $e ({}; .[$e.id] = true)) as $ended
|
|
230
|
+
| ([$items[] | select(.k == "prompt")] | if length > 0 then .[0].i else -1 end) as $first
|
|
231
|
+
| def set: map({(.): true}) | add // {};
|
|
232
|
+
def later($j; $files):
|
|
233
|
+
reduce range($j + 1; $bash | length) as $x ({done: false, totals: null};
|
|
234
|
+
if .done then .
|
|
235
|
+
else $bash[$x] as $c
|
|
236
|
+
| if $c.test and any($c.targets[]; $files[.] == true) then .done = true
|
|
237
|
+
elif any($c.words[]; $files[.] == true) and $res[$c.id].totals != null
|
|
238
|
+
then {done: true, totals: $res[$c.id].totals}
|
|
239
|
+
else . end
|
|
240
|
+
end)
|
|
241
|
+
| .totals;
|
|
242
|
+
def where: if $cwd != null and startswith($cwd + "/") then .[($cwd | length) + 1:] else . end;
|
|
243
|
+
def commit_of($c; $r):
|
|
244
|
+
(if $r.git != null then $r.git
|
|
245
|
+
elif $c.message != null then first(($r.onelines // [])[] | select((.subject | one) == $c.message)) // null
|
|
246
|
+
else ($r.onelines // [])[0] end)
|
|
247
|
+
| if . == null then null else {hash, subject: (.subject | one)} end;
|
|
248
|
+
[$items[] | {sec, i, b} as $here
|
|
249
|
+
| if .k == "call" and .name == "Edit" then
|
|
250
|
+
select(($res[.id] // {err: true}).err | not) | $here + {kind: "edit", file: (.file | where)}
|
|
251
|
+
elif .k == "call" then
|
|
252
|
+
. as $c | $res[$c.id] as $r
|
|
253
|
+
| if $c.test then
|
|
254
|
+
(if $r == null then {totals: null, running: true}
|
|
255
|
+
elif $r.bg == true then
|
|
256
|
+
later($pos[$c.id]; $c.targets + [$r.bgfile // empty] | set) as $totals
|
|
257
|
+
| {totals: $totals, running: ($totals == null and $ended[$c.id] != true)}
|
|
258
|
+
elif $r.totals != null then {totals: $r.totals, running: false}
|
|
259
|
+
elif ($c.targets | length) > 0 then {totals: later($pos[$c.id]; $c.targets | set), running: false}
|
|
260
|
+
else {totals: null, running: false} end) as $how
|
|
261
|
+
| $here + {kind: "test run",
|
|
262
|
+
text: (if $how.totals != null
|
|
263
|
+
then "Ran the tests: \($how.totals.passed) passed"
|
|
264
|
+
+ (if $how.totals.failed != null then ", \($how.totals.failed) failed" else "" end)
|
|
265
|
+
elif $how.running then "Running the tests"
|
|
266
|
+
else "Ran the tests, no totals" end),
|
|
267
|
+
passed: $how.totals.passed, failed: $how.totals.failed, running: $how.running}
|
|
268
|
+
elif $c.question != null and $r != null and ($r.err | not) then
|
|
269
|
+
$here + {kind: "question", text: ("Asked you: " + $c.question | one)}
|
|
270
|
+
elif $c.commit and $r != null and ($r.err | not) and commit_of($c; $r) != null then
|
|
271
|
+
commit_of($c; $r) as $m
|
|
272
|
+
| $here + {kind: "commit", text: ("Committed \($m.hash) \"\($m.subject)\"" | one),
|
|
273
|
+
hash: $m.hash, subject: $m.subject}
|
|
274
|
+
else
|
|
275
|
+
$here + {kind: "command",
|
|
276
|
+
text: (if $c.desc != "" then $c.desc
|
|
277
|
+
elif $c.program != "" then "Ran " + $c.program | one
|
|
278
|
+
else "Ran a command" end)}
|
|
279
|
+
end
|
|
280
|
+
elif .k == "prompt" and .human and .i != $first then
|
|
281
|
+
(.text | said) as $t | select($t != null) | $here + {kind: "answer", text: ("You said: " + $t | one)}
|
|
282
|
+
else empty end] as $events
|
|
283
|
+
| {at: $at, phase: $phase, read: true, entries: ([$lines[].sec] | unique), events: $events}
|
|
284
|
+
'
|
|
285
|
+
|
|
286
|
+
# The jq that puts each session's events under the card's steps and prints
|
|
287
|
+
# the list as one line of JSON: $base is the card's steps and when each of
|
|
288
|
+
# its runs began, from events_base, and stdin each session as EVENTS_READ
|
|
289
|
+
# prints it, oldest first, or as one whose transcript was not read, with
|
|
290
|
+
# read false. $only, when it is not empty, is the one step to list, and
|
|
291
|
+
# $writeup and $building the steps of each phase. Edits made one after
|
|
292
|
+
# another in one step are joined here, into one event that names each file
|
|
293
|
+
# once.
|
|
294
|
+
# shellcheck disable=SC2016
|
|
295
|
+
EVENTS_JOIN='
|
|
296
|
+
($writeup | split(" ")) as $w
|
|
297
|
+
| ($building | split(" ")) as $bl
|
|
298
|
+
| def phase_of($s): if ($w | index([$s])) != null then "write-up" elif ($bl | index([$s])) != null then "build" else null end;
|
|
299
|
+
def run_of($t): [$base.news[] | select(. <= $t)] | length;
|
|
300
|
+
def join_edits:
|
|
301
|
+
reduce .[] as $e ([];
|
|
302
|
+
if $e.kind == "edit" and length > 0 and .[length - 1].kind == "edit" and .[length - 1].n == $e.n
|
|
303
|
+
then .[length - 1].files |= (if index([$e.file]) == null then . + [$e.file] else . end)
|
|
304
|
+
else . + [if $e.kind == "edit" then $e + {files: [$e.file]} else $e end] end);
|
|
305
|
+
def shape:
|
|
306
|
+
{at: (.sec | todate), clock: (.sec | strflocaltime("%H:%M")), kind,
|
|
307
|
+
text: (if .kind != "edit" then .text
|
|
308
|
+
elif (.files | length) == 1 then "Edited 1 file: " + .files[0] | one
|
|
309
|
+
else "Edited \(.files | length) files: " + (.files | join(", ")) | one end)}
|
|
310
|
+
+ (if .kind == "edit" then {files, count: (.files | length)}
|
|
311
|
+
elif .kind == "test run" then {passed, failed, running}
|
|
312
|
+
elif .kind == "commit" then {hash, subject}
|
|
313
|
+
else {} end);
|
|
314
|
+
[to_entries[] | .key as $k | .value | objects
|
|
315
|
+
| . + {k: $k, run: run_of(.at | try fromdateiso8601 catch 0)}] as $sessions
|
|
316
|
+
| [$sessions[] | . as $s
|
|
317
|
+
| [$base.steps[] | select(.run == $s.run and phase_of(.step) == $s.phase)] as $c
|
|
318
|
+
| def place($t): if ($c | length) == 0 then null
|
|
319
|
+
else first(($c[] | select(.e >= $t) | .n), $c[-1].n) end;
|
|
320
|
+
{run, phase, read,
|
|
321
|
+
hit: [(.entries // [])[] | place(.) | select(. != null)],
|
|
322
|
+
events: ([(.events // [])[] | . + {n: place(.sec), k: $s.k} | select(.n != null)] | join_edits)}] as $placed
|
|
323
|
+
| ([$placed[].hit[] | tostring] | map({(.): true}) | add // {}) as $hit
|
|
324
|
+
| {space: $space, card: $card,
|
|
325
|
+
steps: [$base.steps[] | select($only == "" or .step == $only) | . as $st
|
|
326
|
+
| ($hit[$st.n | tostring] == true
|
|
327
|
+
or ($st.open and ([$placed[] | select(.run == $st.run and .phase == phase_of($st.step))] | last | .read) == true)) as $rec
|
|
328
|
+
| {run, step, start: (.s | todate), end: (.e | todate), open, recorded: $rec,
|
|
329
|
+
events: (if $rec then [$placed[].events[] | select(.n == $st.n)] | sort_by([.sec, .k, .i, .b]) | map(shape)
|
|
330
|
+
else null end)}]}
|
|
331
|
+
'
|
|
332
|
+
|
|
333
|
+
# The jq that prints the list in words: the card, then each step with its
|
|
334
|
+
# start, then a line an event with its time, its kind and its text, or not
|
|
335
|
+
# recorded. $rows is how many hand-offs the card has, and $only the step
|
|
336
|
+
# asked for.
|
|
337
|
+
# shellcheck disable=SC2016
|
|
338
|
+
EVENTS_WORDS='
|
|
339
|
+
if (.steps | length) == 0 then
|
|
340
|
+
if $rows == 0 then "No hand-offs recorded for \(.card) in \u0027\(.space)\u0027."
|
|
341
|
+
elif $only != "" then "\(.card) in \u0027\(.space)\u0027 has not been in \($only)."
|
|
342
|
+
else "\(.card) in \u0027\(.space)\u0027 has not been in a step yet." end
|
|
343
|
+
else
|
|
344
|
+
"\(.card) in \u0027\(.space)\u0027",
|
|
345
|
+
(.steps[]
|
|
346
|
+
| "\(.step + " " | .[0:10]) \(.start)\(if .open then ", under way" else "" end)",
|
|
347
|
+
(if .events == null then " not recorded"
|
|
348
|
+
elif (.events | length) == 0 then " nothing to list"
|
|
349
|
+
else .events[] | " \(.clock) \(.kind + " " | .[0:9]) \(.text)" end))
|
|
350
|
+
end
|
|
351
|
+
'
|
|
352
|
+
|
|
353
|
+
# ocnus task events <space> <card> [--step <step>] [--json]: list what the
|
|
354
|
+
# card's agents did, step by step, oldest first, in words or, with --json,
|
|
355
|
+
# as one line for programs. --step lists one step alone, each time the card
|
|
356
|
+
# was in it. It only reads.
|
|
357
|
+
task_events() {
|
|
358
|
+
local json=0 only='' asked=0 args=()
|
|
359
|
+
while [ "$#" -gt 0 ]; do
|
|
360
|
+
case $1 in
|
|
361
|
+
--json) json=1 ;;
|
|
362
|
+
--step)
|
|
363
|
+
[ "$asked" = 0 ] || die "--step is given once: $EVENTS_USAGE"
|
|
364
|
+
[ "$#" -ge 2 ] && case $2 in --*) false ;; *) true ;; esac ||
|
|
365
|
+
die "--step takes the step to list, one of $HOST_WRITE_UP_STEPS $HOST_BUILD_STEPS: $EVENTS_USAGE"
|
|
366
|
+
asked=1 only=$2
|
|
367
|
+
shift
|
|
368
|
+
;;
|
|
369
|
+
-*) die "$EVENTS_USAGE" ;;
|
|
370
|
+
*) args+=("$1") ;;
|
|
371
|
+
esac
|
|
372
|
+
shift
|
|
373
|
+
done
|
|
374
|
+
set -- ${args[@]+"${args[@]}"}
|
|
375
|
+
local name=${1:-} card=${2:-}
|
|
376
|
+
[ -n "$name" ] || die "$EVENTS_USAGE"
|
|
377
|
+
space_named "$name" || die "there is no ocnus space called '$name'. See: ocnus space ls"
|
|
378
|
+
[ "$#" -le 2 ] || die "$EVENTS_USAGE"
|
|
379
|
+
card=$(handoff_card "$name" "$card" events) || exit 1
|
|
380
|
+
[ "$asked" = 0 ] || in_list "$only" "$HOST_WRITE_UP_STEPS $HOST_BUILD_STEPS" ||
|
|
381
|
+
die "'$only' is not a step an agent runs. Ask for one of: $HOST_WRITE_UP_STEPS $HOST_BUILD_STEPS"
|
|
382
|
+
have_sqlite || die "$SQLITE is not installed, so no hand-offs have been recorded on this machine."
|
|
383
|
+
command -v jq >/dev/null 2>&1 ||
|
|
384
|
+
die "jq is not installed, so the transcripts of the card's agents cannot be read. Install it, then run this again."
|
|
385
|
+
|
|
386
|
+
local base rows sessions out
|
|
387
|
+
base=$(events_base "$name" "$card") && [ -n "$base" ] ||
|
|
388
|
+
die "could not read the hand-offs in $STORE. It may not be ocnus's store."
|
|
389
|
+
rows=$(jq -r '.rows' <<< "$base") || die "could not read the hand-offs in $STORE. It may not be ocnus's store."
|
|
390
|
+
sessions=''
|
|
391
|
+
[ "$rows" = 0 ] || sessions=$(events_sessions "$name" "$card" "$only") ||
|
|
392
|
+
die "could not read the hand-offs in $STORE. It may not be ocnus's store."
|
|
393
|
+
out=$(printf '%s' "$sessions" | jq -s -c --argjson base "$base" --arg only "$only" --arg space "$name" \
|
|
394
|
+
--arg card "$card" --arg writeup "$HOST_WRITE_UP_STEPS" --arg building "$HOST_BUILD_STEPS" \
|
|
395
|
+
--argjson max "$EVENTS_TEXT_MAX" "$EVENTS_DEFS$EVENTS_JOIN") && [ -n "$out" ] ||
|
|
396
|
+
die "could not put what $card's agents did under its steps."
|
|
397
|
+
if [ "$json" = 1 ]; then
|
|
398
|
+
printf '%s\n' "$out"
|
|
399
|
+
else
|
|
400
|
+
jq -r --argjson rows "$rows" --arg only "$only" "$EVENTS_WORDS" <<< "$out"
|
|
401
|
+
fi
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
# Print the card's steps for EVENTS_JOIN, as one line of JSON: rows, how
|
|
405
|
+
# many hand-offs it has; news, the second of each `new` row, which begins a
|
|
406
|
+
# run; and steps, each with its number n, its run, the step, the seconds it
|
|
407
|
+
# started and ended, s and e, and whether it is open. With no store it has
|
|
408
|
+
# none. The steps are worked out as host_card works them out, from the same
|
|
409
|
+
# view, so that a step here is the step there: the start step is no step,
|
|
410
|
+
# so neither is the question ocnus's watch asks about a card it could not
|
|
411
|
+
# start, nor the human's answer to it.
|
|
412
|
+
# events_base <space> <card>
|
|
413
|
+
events_base() {
|
|
414
|
+
local now
|
|
415
|
+
if [ ! -e "$STORE" ]; then
|
|
416
|
+
printf '{"rows":0,"news":[],"steps":[]}\n'
|
|
417
|
+
return 0
|
|
418
|
+
fi
|
|
419
|
+
now=$(date +%s)
|
|
420
|
+
store "$STORE" "$(log_view "$1" "$2"),
|
|
421
|
+
flagged(id, run, step, kind, status, next, after, t, prev_t, first) as (
|
|
422
|
+
select id, run, step, kind, status, next, after,
|
|
423
|
+
cast(strftime('%s', at) as integer), cast(strftime('%s', prev_at) as integer),
|
|
424
|
+
case when lag(step) over (order by id) is step then 0 else 1 end
|
|
425
|
+
from shown),
|
|
426
|
+
grouped(id, run, step, kind, status, next, after, t, prev_t, g) as (
|
|
427
|
+
select id, run, step, kind, status, next, after, t, prev_t,
|
|
428
|
+
sum(first) over (order by id rows between unbounded preceding and current row)
|
|
429
|
+
from flagged),
|
|
430
|
+
spans(g, first_id, last_id) as (
|
|
431
|
+
select g, min(id), max(id) from grouped where kind != 'start' and step != 'start' group by g),
|
|
432
|
+
latest(run, step, t, under) as (
|
|
433
|
+
select run, step, t, case when step = 'start' and status <> 'done' then null
|
|
434
|
+
when status in ('answered', 'needs-human') then step
|
|
435
|
+
when status = 'done' and coalesce(next, '') not in ('', 'start', 'setup', 'merged') then next end
|
|
436
|
+
from grouped where after is null),
|
|
437
|
+
ended(o, run, step, s, e, open) as (
|
|
438
|
+
select sp.g, l.run, l.step, coalesce(f.prev_t, f.t), l.t, l.after is null and l.step is u.under
|
|
439
|
+
from spans sp join grouped f on f.id = sp.first_id join grouped l on l.id = sp.last_id left join latest u on 1
|
|
440
|
+
union all
|
|
441
|
+
select (select max(g) from grouped) + 1, run, under, t, t, 1 from latest
|
|
442
|
+
where under is not null and under is not step),
|
|
443
|
+
steps(n, run, step, s, e, open) as (
|
|
444
|
+
select row_number() over (order by o), run, step, s, case when open then max($now, e) else e end, open from ended)
|
|
445
|
+
select json_object('rows', (select count(*) from shown),
|
|
446
|
+
'news', json((select json_group_array(cast(strftime('%s', at) as integer)) from shown where step = 'new')),
|
|
447
|
+
'steps', json((select json_group_array(json(entry)) from (
|
|
448
|
+
select json_object('n', n, 'run', run, 'step', step, 's', s, 'e', e,
|
|
449
|
+
'open', json(case when open then 'true' else 'false' end)) as entry
|
|
450
|
+
from steps order by n))));"
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
# Print each of the card's sessions, oldest first, as a line of JSON for
|
|
454
|
+
# EVENTS_JOIN: what EVENTS_READ makes of its transcript, or, for one with no
|
|
455
|
+
# session ID, as an agent in another harness has, or whose transcript Claude
|
|
456
|
+
# Code no longer keeps or that could not be read, when it started and its
|
|
457
|
+
# phase, with read false. A session recorded twice is read once. With a step
|
|
458
|
+
# asked for, only the sessions of that step's phase are read. It fails only
|
|
459
|
+
# when the store cannot be read.
|
|
460
|
+
# events_sessions <space> <card> [<step>]
|
|
461
|
+
events_sessions() {
|
|
462
|
+
local rows at phase harness session file one want='' seen=' '
|
|
463
|
+
if [ -n "${3:-}" ]; then
|
|
464
|
+
want=build
|
|
465
|
+
! in_list "$3" "$HOST_WRITE_UP_STEPS" || want=write-up
|
|
466
|
+
fi
|
|
467
|
+
rows=$(card_sessions "$1" "$2") || return 1
|
|
468
|
+
while IFS=$SESSION_SEP read -r at phase harness session; do
|
|
469
|
+
[ -n "$at" ] || continue
|
|
470
|
+
[ -z "$want" ] || [ "$phase" = "$want" ] || continue
|
|
471
|
+
one=''
|
|
472
|
+
if [ -n "$session" ] && file=$(session_transcript "$session"); then
|
|
473
|
+
case $seen in
|
|
474
|
+
*" $session "*) one="{\"at\":\"$(json_str "$at")\",\"phase\":\"$(json_str "$phase")\",\"read\":true}" ;;
|
|
475
|
+
*)
|
|
476
|
+
seen="$seen$session "
|
|
477
|
+
one=$(jq -R -n -c --arg at "$at" --arg phase "$phase" --argjson max "$EVENTS_TEXT_MAX" \
|
|
478
|
+
"$EVENTS_DEFS$EVENTS_READ" < "$file" 2>/dev/null) || one=''
|
|
479
|
+
;;
|
|
480
|
+
esac
|
|
481
|
+
fi
|
|
482
|
+
[ -n "$one" ] || one="{\"at\":\"$(json_str "$at")\",\"phase\":\"$(json_str "$phase")\",\"read\":false}"
|
|
483
|
+
printf '%s\n' "$one"
|
|
484
|
+
done <<< "$rows"
|
|
485
|
+
}
|
package/cli/lib/finish.sh
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
# - commits on the branch that are not in the remote's default branch, even
|
|
12
12
|
# pushed ones, such as a fix pushed after the pull request merged;
|
|
13
13
|
# - ignored files that the repo's setup does not make again (setup_makes,
|
|
14
|
-
# in recipes.sh), which `git worktree remove` deletes without a word
|
|
14
|
+
# in recipes.sh), which `git worktree remove` deletes without a word,
|
|
15
|
+
# other than what gpui-shell writes into a mod's folder (gpui_shells);
|
|
15
16
|
# - anything in the task folder outside its worktrees.
|
|
16
17
|
# scripts/after-merge makes the same checks for Claude Code's own worktrees.
|
|
17
18
|
# A task that would lose work is still removed by hand.
|
|
@@ -19,6 +20,28 @@
|
|
|
19
20
|
# Lines on stdin, indented under a heading: at most 20, then how many more.
|
|
20
21
|
listed() { awk 'NR <= 20 { print " " $0 } END { if (NR > 20) print " and " NR - 20 " more" }'; }
|
|
21
22
|
|
|
23
|
+
# Print the lines on stdin, paths in the worktree $1, that are not what
|
|
24
|
+
# gpui-shell wrote. gpui-shell, which runs Herdr's mods, writes two files into
|
|
25
|
+
# the folder of each mod it runs, in any repo and whatever its setup says:
|
|
26
|
+
# gpui-kit.d.ts, which it rewrites on every run, and jsconfig.json, which it
|
|
27
|
+
# writes once, when there is none, and which is then the user's. So any
|
|
28
|
+
# gpui-kit.d.ts goes, but a jsconfig.json goes only while it is still
|
|
29
|
+
# gpui-shell's: it says it was written by gpui-shell, and a gpui-kit.d.ts is
|
|
30
|
+
# beside it. A jsconfig.json of the repo's own is still work.
|
|
31
|
+
gpui_shells() {
|
|
32
|
+
local wt=$1 f
|
|
33
|
+
while IFS= read -r f; do
|
|
34
|
+
case /$f in
|
|
35
|
+
*/gpui-kit.d.ts) continue ;;
|
|
36
|
+
*/jsconfig.json)
|
|
37
|
+
[ -f "$wt/${f%jsconfig.json}gpui-kit.d.ts" ] &&
|
|
38
|
+
grep -qF 'Written once by gpui-shell' "$wt/$f" 2>/dev/null && continue
|
|
39
|
+
;;
|
|
40
|
+
esac
|
|
41
|
+
printf '%s\n' "$f"
|
|
42
|
+
done
|
|
43
|
+
}
|
|
44
|
+
|
|
22
45
|
# Print the folder of a card's task, or stop when it has none on this
|
|
23
46
|
# machine: tasks/<card>-<short name>, or tasks/<card> for a title with no
|
|
24
47
|
# plain words, as `task build` finds it. Linear is not asked.
|
|
@@ -118,8 +141,10 @@ check_worktree() {
|
|
|
118
141
|
fi
|
|
119
142
|
|
|
120
143
|
# Ignored files, file by file: each counts as work unless it is, or is in,
|
|
121
|
-
# something the patterns that setup_makes prints match
|
|
122
|
-
#
|
|
144
|
+
# something the patterns that setup_makes prints match, or is what
|
|
145
|
+
# gpui-shell wrote (gpui_shells). git quotes an odd name the same way in
|
|
146
|
+
# both lists, so they can be compared line by line; a quoted name is never
|
|
147
|
+
# taken for gpui-shell's, so it counts as work.
|
|
123
148
|
if ! git -C "$wt" ls-files --others --ignored --exclude-standard > "$scratch/ignored" 2>/dev/null; then
|
|
124
149
|
add_problem " git could not list its ignored files, so what removing it would lose is not known"
|
|
125
150
|
elif [ -s "$scratch/ignored" ]; then
|
|
@@ -130,7 +155,8 @@ check_worktree() {
|
|
|
130
155
|
else
|
|
131
156
|
why=$(head -n 1 "$scratch/why"); : > "$scratch/made"
|
|
132
157
|
fi
|
|
133
|
-
out=$(awk 'FILENAME == ARGV[1] { made[$0]; next } !($0 in made)' "$scratch/made" "$scratch/ignored"
|
|
158
|
+
out=$(awk 'FILENAME == ARGV[1] { made[$0]; next } !($0 in made)' "$scratch/made" "$scratch/ignored" |
|
|
159
|
+
gpui_shells "$wt")
|
|
134
160
|
if [ -n "$out" ]; then
|
|
135
161
|
if [ -n "$why" ]; then add_problem " ignored files, all of them counted as work since $why:"
|
|
136
162
|
else add_problem " ignored files that its setup does not make again:"
|