@iceinvein/agent-skills 0.25.0 → 0.26.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.
Files changed (33) hide show
  1. package/README.md +2 -2
  2. package/dist/cli/index.js +775 -236
  3. package/package.json +2 -1
  4. package/skills/index.json +2 -2
  5. package/skills/magpie/SKILL.md +35 -18
  6. package/skills/magpie/bin/magpie.ts +28 -0
  7. package/skills/magpie/package.json +1 -1
  8. package/skills/magpie/references/critic.md +2 -2
  9. package/skills/magpie/references/peer-review.md +7 -7
  10. package/skills/magpie/references/proof.md +2 -2
  11. package/skills/magpie/scripts/__tests__/peer-run.test.ts +231 -0
  12. package/skills/magpie/scripts/__tests__/preflight.test.ts +22 -1
  13. package/skills/magpie/scripts/__tests__/setup-cmd.test.ts +14 -0
  14. package/skills/magpie/scripts/__tests__/skill-lint.test.ts +45 -4
  15. package/skills/magpie/scripts/peer-run.ts +146 -0
  16. package/skills/magpie/scripts/preflight.ts +20 -20
  17. package/skills/magpie/scripts/setup-cmd.ts +7 -1
  18. package/skills/magpie/skill.json +1 -1
  19. package/skills/sluice/SKILL.md +21 -6
  20. package/skills/sluice/references/deep-channel.md +35 -25
  21. package/skills/sluice/references/finish.md +2 -2
  22. package/skills/sluice/references/intent.md +1 -1
  23. package/skills/sluice/references/status.md +10 -4
  24. package/skills/sluice/references/test-first.md +12 -0
  25. package/skills/sluice/scripts/board-index.sh +59 -37
  26. package/skills/sluice/scripts/board.sh +72 -40
  27. package/skills/sluice/scripts/host.sh +60 -0
  28. package/skills/sluice/scripts/run-stats.sh +41 -3
  29. package/skills/sluice/scripts/session-start.sh +75 -17
  30. package/skills/sluice/scripts/status.sh +9 -5
  31. package/skills/sluice/scripts/stop-guard.sh +101 -37
  32. package/skills/sluice/scripts/transcript.sh +221 -0
  33. package/skills/sluice/skill.json +1 -1
@@ -24,12 +24,40 @@
24
24
  # sections).
25
25
  #
26
26
  # Reads the harness's stop JSON on stdin for `cwd` and `stop_hook_active`. To
27
- # refuse, prints {"decision":"block","reason":...} on stdout. Always exits 0.
27
+ # refuse, prints {"decision":"block","reason":...} on stdout, or on Antigravity
28
+ # {"decision":"continue","reason":...}, the one decision it keeps a turn going
29
+ # on. Always exits 0.
30
+ #
31
+ # Usage: stop-guard.sh [--host <claude|codex|antigravity>]
32
+ #
33
+ # The installer passes --host, and without it the host is Claude, as
34
+ # session-start.sh explains.
28
35
 
29
36
  set -uo pipefail
30
37
 
31
38
  here="$(cd "$(dirname "$0")" && pwd)"
32
39
  STATUS="$here/status.sh"
40
+ source "$here/host.sh"
41
+
42
+ host=""
43
+ while [ $# -gt 0 ]; do
44
+ case "$1" in
45
+ --host)
46
+ if [ $# -lt 2 ]; then
47
+ echo "stop-guard.sh: --host needs a value" >&2
48
+ exit 0
49
+ fi
50
+ host="$2"
51
+ shift 2
52
+ ;;
53
+ *)
54
+ echo "stop-guard.sh: unknown argument '$1'" >&2
55
+ exit 0
56
+ ;;
57
+ esac
58
+ done
59
+ [ -n "$host" ] || host=claude
60
+ state_root="$(sluice_state_root "$host")" || exit 0
33
61
 
34
62
  # jq first: without it nothing below can run, and the stdin read that follows
35
63
  # has a worst case worth not paying for nothing.
@@ -51,6 +79,30 @@ if [ ! -t 0 ]; then
51
79
  done
52
80
  fi
53
81
 
82
+ # Antigravity fires Stop while the agent waits on work it started, a subagent
83
+ # above all, and says so with fullyIdle false. That is neither a handback nor a
84
+ # stall, so it is let through before anything is asked of it, the board
85
+ # included.
86
+ #
87
+ # A subagent fires its own SessionStart and Stop under its own conversation, so
88
+ # it is stamped like the controller and would be nudged and gated for work it
89
+ # was dispatched to do. Its transcript opens with the system message carrying
90
+ # its prompt, and only a controller's holds input the user typed, which it has
91
+ # by its first Stop. Only that opener with no such input is taken as a
92
+ # subagent: a transcript that is empty, unreadable or has lost its opener
93
+ # tells neither apart, and the gates below are left to answer for it.
94
+ if [ "$host" = antigravity ] && [ -n "$input" ]; then
95
+ [ "$(printf '%s' "$input" | jq -r '.fullyIdle' 2>/dev/null)" = "false" ] && exit 0
96
+ agy_transcript="$(printf '%s' "$input" | jq -r '.transcriptPath // empty' 2>/dev/null)"
97
+ if [ -f "$agy_transcript" ]; then
98
+ jq -e -n -R '[ inputs | fromjson? // empty ]
99
+ | length > 0 and .[0].type == "SYSTEM_MESSAGE"
100
+ and (any(.[]; .type == "USER_INPUT" and .source == "USER_EXPLICIT") | not)' \
101
+ "$agy_transcript" >/dev/null 2>&1 && exit 0
102
+ fi
103
+ input="$(printf '%s' "$input" | jq -c '{session_id: .conversationId, cwd: (.cwd // .workspacePaths[0]?), transcript_path: .transcriptPath, stop_hook_active: (.continuationActive // false)}' 2>/dev/null)" || input=""
104
+ fi
105
+
54
106
  cwd="$PWD"
55
107
  active="false"
56
108
  sid=""
@@ -138,29 +190,34 @@ resolve_run_tree() {
138
190
  # A run naming no session is no session's own, as the board draws it, and a
139
191
  # state file that cannot be read names nobody it can be kept for.
140
192
  refused=""
193
+ refuse() {
194
+ local decision=block
195
+ [ "$host" = antigravity ] && decision=continue
196
+ refused=1
197
+ jq -n --arg decision "$decision" --arg reason "$1" '{decision: $decision, reason: $reason}'
198
+ }
199
+
141
200
  board_handback() {
142
201
  local keep="" root owner
143
202
  [ -z "$refused" ] && [ -n "$sid" ] || return 0
144
203
  case "$sid" in */* | .*) return 0 ;; esac
145
- # Must match the root board-index.sh and board.sh resolve.
146
- if [ -n "${SLUICE_BOARD_DIR:-}" ]; then
147
- root="$SLUICE_BOARD_DIR"
148
- elif [ -n "${CLAUDE_CONFIG_DIR:-}" ]; then
149
- root="$CLAUDE_CONFIG_DIR/sluice/board"
150
- elif [ -n "${HOME:-}" ]; then
151
- root="$HOME/.claude/sluice/board"
152
- else
153
- return 0
154
- fi
204
+ # The hook's host names the board, not the environment: a Codex hook carries
205
+ # no CODEX_* variable for board-index.sh to detect it by.
206
+ root="${SLUICE_BOARD_DIR:-$state_root/board}"
155
207
  [ -f "$root/sessions/$sid.json" ] || return 0
156
208
  [ -n "$resolved" ] || resolve_run_tree
157
209
  if [ -n "$run_tree" ] && owner="$(jq -r '.session // empty' "$run_tree/.sluice/run.json" 2>/dev/null)" \
158
210
  && [ "$owner" = "$sid" ]; then
159
211
  keep="--keep-deep"
160
212
  fi
161
- bash "$here/board-index.sh" handback "$sid" $keep >/dev/null 2>&1 || true
213
+ SLUICE_HOST="$host" SLUICE_BOARD_DIR="$root" bash "$here/board-index.sh" handback "$sid" $keep >/dev/null 2>&1 || true
214
+ }
215
+ translated=""
216
+ finish() {
217
+ board_handback
218
+ [ -z "$translated" ] || rm -f "$translated"
162
219
  }
163
- trap board_handback EXIT
220
+ trap finish EXIT
164
221
 
165
222
  [ "$active" = "true" ] && exit 0
166
223
  [ -d "$cwd" ] || exit 0
@@ -177,7 +234,7 @@ read_moved() {
177
234
  local stamp tree line_tree line_digest now
178
235
  [ -n "$sid" ] || return 0
179
236
  case "$sid" in */* | .*) return 0 ;; esac
180
- stamp="${CLAUDE_CONFIG_DIR:-${HOME:-}/.claude}/sluice/stamps/$sid"
237
+ stamp="$state_root/stamps/$sid"
181
238
  [ -f "$stamp" ] || return 0
182
239
 
183
240
  tree="$(git -C "$cwd" rev-parse --show-toplevel 2>/dev/null)" || return 0
@@ -203,6 +260,21 @@ read_moved() {
203
260
  }
204
261
  read_moved
205
262
 
263
+ # The checks below read Claude's transcript shape, so another host's transcript
264
+ # is translated first, and only when a check will read it. A transcript that
265
+ # will not translate leaves those checks unanswered rather than refusing, and
266
+ # transcript.sh says why on stderr.
267
+ unread=""
268
+ if [ -n "$moved_tree" ] && [ -f "$transcript" ]; then
269
+ case "$host" in
270
+ codex | antigravity)
271
+ translated="$(mktemp "${TMPDIR:-/tmp}/sluice-transcript.XXXXXX")" || exit 0
272
+ bash "$here/transcript.sh" --host "$host" "$transcript" >"$translated" || unread=1
273
+ transcript="$translated"
274
+ ;;
275
+ esac
276
+ fi
277
+
206
278
  # A copy of run-stats.sh's `route` pattern, byte for byte, kept in step with
207
279
  # that file by hand: both checks below read route calls, and a route the meter
208
280
  # counts has to be a route here too. One copy in this file, used by both.
@@ -233,11 +305,12 @@ route_def='def route: "(?:^|[;&|(])[[:space:]]*(?:(?:bash|sh|zsh)[[:space:]]+)?(
233
305
  # answer and takes it.
234
306
  entry_nudge() {
235
307
  [ -n "$moved_tree" ] || return 0
308
+ [ -z "$unread" ] || return 0
236
309
 
237
310
  # Two directories rather than one name and one suffixed name: sharing a
238
311
  # namespace means a session id ending in `.nudged` silently disarms the
239
312
  # session whose id is its prefix.
240
- local root="${CLAUDE_CONFIG_DIR:-${HOME:-}/.claude}/sluice"
313
+ local root="$state_root"
241
314
  [ -f "$root/nudged/$sid" ] && return 0
242
315
 
243
316
  # Whether the session routed is read exactly the way run-stats.sh reads it,
@@ -275,11 +348,7 @@ entry_nudge() {
275
348
 
276
349
  mkdir -p "$root/nudged" 2>/dev/null || true
277
350
  : >"$root/nudged/$sid" 2>/dev/null || true
278
- refused=1
279
- jq -n '{
280
- decision: "block",
281
- reason: "sluice: this session has changed the tree since it opened and no channel was ever announced, so the work is running with none of the rules that its shape calls for and nothing to meter it from. Invoke the sluice skill now, route what you have been doing, and say which channel it is. If it genuinely changed nothing you own (a scratch file, or an edit that was not yours), say so and stop; this will not ask twice."
282
- }'
351
+ refuse "sluice: this session has changed the tree since it opened and no channel was ever announced, so the work is running with none of the rules that its shape calls for and nothing to meter it from. Invoke the sluice skill now, route what you have been doing, and say which channel it is. If it genuinely changed nothing you own (a scratch file, or an edit that was not yours), say so and stop; this will not ask twice."
283
352
  return 1
284
353
  }
285
354
 
@@ -306,6 +375,7 @@ fi
306
375
  verify_gate() {
307
376
  local channel recorded now
308
377
  [ -n "$moved_tree" ] || return 0
378
+ [ -z "$unread" ] || return 0
309
379
  [ -f "$transcript" ] || return 0
310
380
 
311
381
  # Unparseable lines are dropped for the reason the entry check gives: the
@@ -326,11 +396,7 @@ verify_gate() {
326
396
  [ -f "$moved_tree/.sluice/verified" ] && recorded="$(sed -n '1p' "$moved_tree/.sluice/verified" 2>/dev/null)"
327
397
  [ "$recorded" = "$now" ] && return 0
328
398
 
329
- refused=1
330
- jq -n --arg channel "$channel" '{
331
- decision: "block",
332
- reason: ("sluice: this \($channel) session has changed the tree and no passing check is recorded against it as it stands now, so the handback would carry a change nothing has proved. Run the check that proves it through the recorder: status.sh verify -- <cmd> (the tests, the build, whatever exercises this change). If no check can cover it (docs, config), record why: status.sh verify --none \"<reason>\". Then hand back.")
333
- }'
399
+ refuse "$(jq -rn --arg channel "$channel" '("sluice: this \($channel) session has changed the tree and no passing check is recorded against it as it stands now, so the handback would carry a change nothing has proved. Run the check that proves it through the recorder: status.sh verify -- <cmd> (the tests, the build, whatever exercises this change). If no check can cover it (docs, config), record why: status.sh verify --none \"<reason>\". Then hand back.")')"
334
400
  return 1
335
401
  }
336
402
 
@@ -407,13 +473,9 @@ test_gate() {
407
473
 
408
474
  # Paths land in a reason the harness prints, so control bytes are stripped
409
475
  # as the run guard strips them from the topic and tree.
410
- refused=1
411
- jq -n --arg paths "$missing" --arg base "$base" '{
412
- decision: "block",
413
- reason: ("sluice: this session changed existing tests in a way that asks less of the code (an edited or removed assertion, a deleted test, a skip or focus marker), and nothing records why: "
476
+ refuse "$(jq -rn --arg paths "$missing" --arg base "$base" '("sluice: this session changed existing tests in a way that asks less of the code (an edited or removed assertion, a deleted test, a skip or focus marker), and nothing records why: "
414
477
  + ($paths | split("\n") | map(select(. != "") | gsub("[\u0000-\u001f\u007f]"; "")) | join(", "))
415
- + ". A test bent to fit new code proves nothing about it, so each one needs a record against the session base \($base). Prove it fails on the old code: status.sh tests-changed --because \"<the behaviour the change replaces>\" -- <the suite, scoped to these files> (the run is in a scratch worktree of the base, so a node suite usually needs --with node_modules). If it cannot run on the old code, record why: status.sh tests-changed --because \"<the behaviour the change replaces>\" --none \"<why it cannot run on the old code>\". No run can prove a deleted test, so prove the edited ones first, then record each deletion with --none. --only <path> proves or records just those paths, so a fixture that cannot be proved can go to --none --only <fixture> on its own. Then name each changed test, and why it changed, in your reply. The base is where this tree stood when the session opened, so a test that arrived through a merge of another session into this tree since then is listed too. Do not give a reason for a change that is not yours: record it as what it is, status.sh tests-changed --because \"arrived through the merge of <branch>, not from this session\" --none \"not this session to prove\" --only <path>, and name it in your reply as not from this session.")
416
- }'
478
+ + ". A test bent to fit new code proves nothing about it, so each one needs a record against the session base \($base). Prove it fails on the old code: status.sh tests-changed --because \"<the behaviour the change replaces>\" -- <the suite, scoped to these files> (the run is in a scratch worktree of the base, so a node suite usually needs --with node_modules). If it cannot run on the old code, record why: status.sh tests-changed --because \"<the behaviour the change replaces>\" --none \"<why it cannot run on the old code>\". No run can prove a deleted test, so prove the edited ones first, then record each deletion with --none. --only <path> proves or records just those paths, so a fixture that cannot be proved can go to --none --only <fixture> on its own. Then name each changed test, and why it changed, in your reply. The base is where this tree stood when the session opened, so a test that arrived through a merge of another session into this tree since then is listed too. Do not give a reason for a change that is not yours: record it as what it is, status.sh tests-changed --because \"arrived through the merge of <branch>, not from this session\" --none \"not this session to prove\" --only <path>, and name it in your reply as not from this session.")')"
417
479
  return 1
418
480
  }
419
481
 
@@ -430,6 +492,12 @@ tree="$run_tree"
430
492
  run="$(bash "$STATUS" show --json --dir "$tree" 2>/dev/null)" || exit 0
431
493
  [ -n "$run" ] || exit 0
432
494
 
495
+ # Antigravity fires Stop for each subagent's conversation as well as for the
496
+ # controller's, and only the controller is the one a stall here belongs to.
497
+ if [ "$host" = antigravity ]; then
498
+ [ -n "$sid" ] && [ "$(printf '%s' "$run" | jq -r '.session // empty' 2>/dev/null)" = "$sid" ] || exit 0
499
+ fi
500
+
433
501
  # One JSON object out, read back with jq: the topic is user text, and word
434
502
  # splitting it would truncate at the first space and glob on the rest.
435
503
  verdict="$(printf '%s' "$run" | jq -c --argjson now "$(date -u +%s)" --arg tree "$tree" --arg here "$top" '
@@ -475,15 +543,11 @@ verdict="$(printf '%s' "$run" | jq -c --argjson now "$(date -u +%s)" --arg tree
475
543
  # anyone into. What replaces it is the step `move` could not take -- the session
476
544
  # following the run -- because a controller guarded here is a controller sitting
477
545
  # in the tree its own run left.
478
- refused=1
479
- printf '%s' "$verdict" | jq 2>/dev/null '{
480
- decision: "block",
481
- reason: ("sluice: the deep run \(.topic) is \(.progress) done with tasks still to go and nothing marked blocked or paused, so ending the turn here hands a live run back with nothing for your partner to decide. Still open: \(.open)."
546
+ refuse "$(printf '%s' "$verdict" | jq -r 2>/dev/null '("sluice: the deep run \(.topic) is \(.progress) done with tasks still to go and nothing marked blocked or paused, so ending the turn here hands a live run back with nothing for your partner to decide. Still open: \(.open)."
482
547
  + (if .elsewhere then " The run lives in \(.tree), not in this tree: `move` relocated the run and not this session. If it is yours, move this session into that tree -- the worktree tool in your harness enters one that already exists -- and go on from there." else "" end)
483
548
  + " Continue: run status.sh ready and dispatch the next wave in this same message. If a task genuinely needs them, mark it: status.sh task <id> --status blocked. If the run has to stand still for a reason, record it: status.sh pause --reason \"<why>\", then say so and stop."
484
549
  + (if .elsewhere
485
550
  then " If the run is not yours, it belongs to the session working in \(.tree): say so and stop, rather than closing it from here."
486
551
  else " If this run is not the work you were asked to do, it was left open: status.sh close."
487
- end))
488
- }'
552
+ end))')"
489
553
  exit 0
@@ -0,0 +1,221 @@
1
+ #!/usr/bin/env bash
2
+ # Translate a Codex rollout or an Antigravity transcript into the subset of
3
+ # Claude's transcript shape that run-stats.sh and stop-guard.sh read, so their
4
+ # jq runs unchanged on every host.
5
+ #
6
+ # Usage: transcript.sh --host <codex|antigravity> <path>
7
+ # transcript.sh --host <codex|antigravity> --locate <session id>
8
+ # transcript.sh --host <codex|antigravity> --agents <path>
9
+ #
10
+ # Exit 0 printed the translation, the path, or the agent list. 1 the
11
+ # transcript could not be read or found. 4 a usage error, an unknown host
12
+ # included.
13
+
14
+ set -uo pipefail
15
+
16
+ err() {
17
+ printf 'transcript: %s\n' "$1" >&2
18
+ }
19
+
20
+ usage() {
21
+ err "$1"
22
+ err "usage: transcript.sh --host <codex|antigravity> <path> | --locate <session id> | --agents <path>"
23
+ exit 4
24
+ }
25
+
26
+ HOST=""
27
+ MODE="translate"
28
+ ARG=""
29
+
30
+ # shift 2 with one argument left fails without shifting, and the loop would
31
+ # then spin forever on the same flag.
32
+ while [ $# -gt 0 ]; do
33
+ case "$1" in
34
+ --host|--locate|--agents) [ $# -ge 2 ] || usage "$1 needs a value" ;;
35
+ esac
36
+ case "$1" in
37
+ --host) HOST="$2"; shift 2 ;;
38
+ --locate) MODE="locate"; ARG="$2"; shift 2 ;;
39
+ --agents) MODE="agents"; ARG="$2"; shift 2 ;;
40
+ -*) usage "unknown argument '$1'" ;;
41
+ *) ARG="$1"; shift ;;
42
+ esac
43
+ done
44
+
45
+ case "$HOST" in
46
+ codex|antigravity) ;;
47
+ *) usage "unknown host '$HOST'" ;;
48
+ esac
49
+ [ -n "$ARG" ] || usage "no path or session id given"
50
+
51
+ if ! command -v jq >/dev/null 2>&1; then
52
+ err "jq is required and was not found on PATH"
53
+ exit 1
54
+ fi
55
+
56
+ # The two hosts keep a session's transcript where the session id alone names
57
+ # it, so a lookup needs no hook to have recorded the path.
58
+ locate() {
59
+ local id="$1" path
60
+ case "$HOST" in
61
+ codex)
62
+ path="$(ls "${CODEX_HOME:-$HOME/.codex}"/sessions/*/*/*/rollout-*-"$id".jsonl 2>/dev/null | head -1)"
63
+ ;;
64
+ antigravity)
65
+ path="$HOME/.gemini/antigravity-cli/brain/$id/.system_generated/logs/transcript_full.jsonl"
66
+ ;;
67
+ esac
68
+ if [ -z "$path" ] || [ ! -f "$path" ]; then
69
+ err "no $HOST transcript found for session $id"
70
+ return 1
71
+ fi
72
+ printf '%s\n' "$path"
73
+ }
74
+
75
+ # Shared by the translation and --agents: Antigravity records a subagent's id
76
+ # only in the step after the call, so calls and created ids are paired in order.
77
+ AGY_SUBAGENTS='[ .[] | select(.type == "GENERIC" and ((.content // "") | test("Created the following subagent:")))
78
+ | (.content | capture("\"conversationId\"[[:space:]]*:[[:space:]]*\"(?<id>[^\"]+)\"").id) ]'
79
+
80
+ CODEX_JQ='
81
+ def assistant($ts; $id; $model; $content):
82
+ { type: "assistant", timestamp: $ts, message: { id: $id, model: $model, content: [ $content ] } };
83
+ def text_of: if type == "array" then [ .[]? | .text? // empty ] | join("\n") else (. // "") end;
84
+ # Codex runs every command as [shell, "-lc", script]. The script is what the
85
+ # agent wrote, and the route and test-change patterns anchor on its start.
86
+ def command_of:
87
+ if type == "array" and length == 3 and (.[1] == "-lc" or .[1] == "-c") then .[2]
88
+ elif type == "array" then join(" ")
89
+ else (. // "") end;
90
+ reduce .[] as $l ({ model: "?", out: [] };
91
+ .model as $m
92
+ | if $l.type == "turn_context" then .model = ($l.payload.model // $m)
93
+ elif $l.type == "token_usage_record" and (($l.payload.usage.output_tokens | type) == "number") then
94
+ .out += [ { type: "assistant", timestamp: $l.timestamp,
95
+ message: { id: ($l.payload.response_id // "usage-\($l.ordinal)"), model: $m, content: [],
96
+ usage: { output_tokens: $l.payload.usage.output_tokens } } } ]
97
+ elif $l.type == "event_msg" and $l.payload.type == "item_completed" then
98
+ $l.payload.item as $i
99
+ | if $i.type == "UserMessage" then
100
+ .out += [ { type: "user", timestamp: $l.timestamp, message: { content: ($i.content | text_of) } } ]
101
+ elif $i.type == "AgentMessage" and (($i.content | text_of) != "") then
102
+ .out += [ assistant($l.timestamp; $i.id; $m; { type: "text", text: ($i.content | text_of) }) ]
103
+ elif $i.type == "CommandExecution" then
104
+ .out += [ assistant($l.timestamp; $i.id; $m;
105
+ { type: "tool_use", id: $i.id, name: "Bash", input: { command: ($i.command | command_of) } }) ]
106
+ elif $i.type == "FileChange" then
107
+ .out += [ $i.changes | to_entries[]
108
+ | if .value.type == "add" then
109
+ assistant($l.timestamp; $i.id; $m;
110
+ { type: "tool_use", id: $i.id, name: "Write", input: { file_path: .key, content: .value.content } })
111
+ else
112
+ assistant($l.timestamp; $i.id; $m;
113
+ { type: "tool_use", id: $i.id, name: "Edit", input: { file_path: .key, unified_diff: .value.unified_diff } })
114
+ end ]
115
+ elif $i.type == "SubAgentActivity" and $i.kind == "started" then
116
+ .out += [ assistant($l.timestamp; $i.id; $m;
117
+ { type: "tool_use", id: $i.id, name: "Agent",
118
+ input: { description: $i.agent_path, model: $i.model } })
119
+ + { toolUseResult: { agentId: $i.agent_thread_id } } ]
120
+ else . end
121
+ else . end)
122
+ | .out[]'
123
+
124
+ AGY_JQ='
125
+ def args_of: if (.args | type) == "string" then (.args | fromjson) else (.args // {}) end;
126
+ '"$AGY_SUBAGENTS"' as $subs
127
+ | reduce .[] as $l ({ n: 0, out: [] };
128
+ if $l.type == "USER_INPUT" then
129
+ .out += [ { type: "user", timestamp: $l.created_at, message: { content: ($l.content // "") } } ]
130
+ elif $l.type == "PLANNER_RESPONSE" then
131
+ ({ id: "step-\($l.step_index)", model: ($l.model // "?") }
132
+ + (if ($l.output_tokens | type) == "number" then { usage: { output_tokens: $l.output_tokens } } else {} end)) as $msg
133
+ | def line($c): { type: "assistant", timestamp: $l.created_at, message: ($msg + { content: [ $c ] }) };
134
+ (if ($l.content // "") != "" then .out += [ line({ type: "text", text: $l.content }) ] else . end)
135
+ | reduce (($l.tool_calls // []) | to_entries[]) as $e (.;
136
+ $e.value as $c
137
+ | ($c | args_of) as $a
138
+ | "step-\($l.step_index)-\($e.key)" as $tid
139
+ | if $c.name == "run_command" then
140
+ .out += [ line({ type: "tool_use", id: $tid, name: "Bash", input: { command: $a.CommandLine } }) ]
141
+ elif $c.name == "write_file" then
142
+ .out += [ line({ type: "tool_use", id: $tid, name: "Write", input: { file_path: $a.Path, content: $a.Content } }) ]
143
+ elif $c.name == "edit_file" then
144
+ .out += [ line({ type: "tool_use", id: $tid, name: "Edit",
145
+ input: { file_path: $a.Path, old_string: $a.Target, new_string: $a.Replacement } }) ]
146
+ elif $c.name == "invoke_subagent" then
147
+ .n as $n
148
+ | .out += [ line({ type: "tool_use", id: $tid, name: "Agent",
149
+ input: { description: $a.Role, prompt: $a.Prompt, subagent_type: $a.TypeName } })
150
+ + (if $subs[$n] then { toolUseResult: { agentId: $subs[$n] } } else {} end) ]
151
+ | .n += 1
152
+ else . end)
153
+ else . end)
154
+ | .out[]'
155
+
156
+ if [ "$MODE" = "locate" ]; then
157
+ locate "$ARG"
158
+ exit $?
159
+ fi
160
+
161
+ if [ ! -r "$ARG" ] || [ -d "$ARG" ]; then
162
+ err "transcript not found: $ARG"
163
+ exit 1
164
+ fi
165
+
166
+ # A host may still be appending its last line when a hook reads the file, so
167
+ # that line alone may be cut short, and is dropped. An invalid line anywhere
168
+ # else is a file this mapping does not know, and fails rather than leaving
169
+ # counts quietly short.
170
+ parsed() {
171
+ jq -cRs '[ split("\n")[] | select(test("\\S")) ] | (length - 1) as $last
172
+ | to_entries[] | .key as $i
173
+ | .value | try fromjson catch (if $i == $last then empty else error("not JSON") end)' "$ARG" 2>/dev/null
174
+ }
175
+
176
+ LINES="$(parsed)" || {
177
+ err "transcript format not recognised for $HOST: a line before the last is not JSON in $ARG"
178
+ exit 1
179
+ }
180
+
181
+ if [ "$MODE" = "agents" ]; then
182
+ case "$HOST" in
183
+ codex)
184
+ ids="$(jq -r 'select(.type == "event_msg" and .payload.item.type == "SubAgentActivity"
185
+ and .payload.item.kind == "started") | .payload.item.agent_thread_id' <<<"$LINES" 2>/dev/null)" ;;
186
+ antigravity)
187
+ ids="$(jq -rs "$AGY_SUBAGENTS"' | .[]' <<<"$LINES" 2>/dev/null)" ;;
188
+ esac
189
+ # An agent whose transcript is gone is reported on stderr and skipped: the
190
+ # ones still on disk are worth listing, and the caller sees which one was missed.
191
+ while IFS= read -r id; do
192
+ [ -n "$id" ] || continue
193
+ path="$(locate "$id")" || continue
194
+ printf '%s\t%s\n' "$id" "$path"
195
+ done < <(printf '%s\n' "$ids" | awk 'NF && !seen[$0]++')
196
+ exit 0
197
+ fi
198
+
199
+ case "$HOST" in
200
+ codex) program="$CODEX_JQ" ;;
201
+ antigravity) program="$AGY_JQ" ;;
202
+ esac
203
+
204
+ out="$(jq -cs "$program" <<<"$LINES" 2>/dev/null)"
205
+
206
+ # Codex calls its rollout format unstable, so a file that yields nothing is a
207
+ # format the mapping no longer knows, and a ledger of zeros would read as a run
208
+ # that did nothing.
209
+ said="$(jq -s '[ .[] | select(.type == "assistant" and (.message.content | length) > 0) ] | length' <<<"$out" 2>/dev/null)"
210
+ if [ -z "$out" ] || [ "${said:-0}" -eq 0 ]; then
211
+ err "transcript format not recognised for $HOST"
212
+ exit 1
213
+ fi
214
+
215
+ priced="$(jq -s '[ .[] | select(.message.usage) ] | length' <<<"$out")"
216
+ if [ "$priced" -eq 0 ]; then
217
+ err "transcript format not recognised for $HOST: no output tokens in $ARG"
218
+ exit 1
219
+ fi
220
+
221
+ printf '%s\n' "$out"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sluice",
3
- "version": "0.29.0",
3
+ "version": "0.30.0",
4
4
  "description": "Routes work by change shape into four channels (bypass, fast, main, deep) and applies only the rules each channel needs, so a one-line fix does not pay the cost of a multi-subsystem build. Carries nine rules as one-liners in the router and the full treatment in references read only on friction. Deep runs read the repo before designing, map the spec's intent to its decisions, and check spec against intent and plan against spec with a fresh reader, with plan.sh validate enforcing that every decision is covered. Checks the finished plan with plan.sh validate rather than trusting it to memory, seeds the run state from it, keeps a deep run's task breakdown in .sluice/run.json so a statusline segment, one status command and a SessionStart hook can answer where the run is (the hook prints a live run at every session start, compaction included), lists every live deep run and routed fast or main session on the machine in one board.sh view (drawn once, watched, or as JSON), and closes each run with a ledger read out of the session transcript: elapsed, tools, tokens, and what each dispatched agent cost where the transcript recorded it. Two Stop hooks hold a handback: one refuses a tree that moved since its last recorded check, the other refuses a changed existing test not proven to fail on the session's starting code (or recorded with a reason). Claude Code only; stands down where the superpowers pipeline governs the repo.",
5
5
  "author": "iceinvein",
6
6
  "type": "prompt",