@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
@@ -9,9 +9,12 @@
9
9
  # board-index.sh handback <id> [--keep-deep]
10
10
  # board-index.sh prune
11
11
  #
12
- # The root is $SLUICE_BOARD_DIR, else $CLAUDE_CONFIG_DIR/sluice/board, else
13
- # $HOME/.claude/sluice/board. With none of the three set there is nowhere safe
14
- # to write, so every verb exits 0 having written nothing. Runs live at
12
+ # Entries are written under $SLUICE_BOARD_DIR, else under the board of the host
13
+ # this runs in (host.sh's sluice_state_root, plus /board), with Claude's board
14
+ # standing in outside any host, where every entry went before there were others.
15
+ # prune sweeps every host's board. A board whose root would be built from an
16
+ # empty HOME is nowhere safe to write, so with no root at all every verb exits 0
17
+ # having written nothing. Runs live at
15
18
  # <root>/runs/<key>, one line naming the tree, where <key> is the tree with %
16
19
  # encoded as %25 and / as %2F. Sessions live at <root>/sessions/<id>.json.
17
20
  #
@@ -22,6 +25,8 @@
22
25
 
23
26
  set -u
24
27
 
28
+ source "$(dirname "$0")/host.sh"
29
+
25
30
  err() { echo "board-index.sh: $*" >&2; }
26
31
 
27
32
  usage() {
@@ -65,14 +70,29 @@ case "$verb" in
65
70
  *) usage ;;
66
71
  esac
67
72
 
73
+ # A root built from an empty HOME would sit at the filesystem root, so a host
74
+ # counts only when HOME, or the variable it reads in place of HOME, is set.
75
+ anchored() { # <host>
76
+ case "$1" in
77
+ claude) [ -n "${CLAUDE_CONFIG_DIR:-}" ] || [ -n "${HOME:-}" ] ;;
78
+ codex) [ -n "${CODEX_HOME:-}" ] || [ -n "${HOME:-}" ] ;;
79
+ *) [ -n "${HOME:-}" ] ;;
80
+ esac
81
+ }
82
+
68
83
  if [ -n "${SLUICE_BOARD_DIR:-}" ]; then
69
84
  ROOT="$SLUICE_BOARD_DIR"
70
- elif [ -n "${CLAUDE_CONFIG_DIR:-}" ]; then
71
- ROOT="$CLAUDE_CONFIG_DIR/sluice/board"
72
- elif [ -n "${HOME:-}" ]; then
73
- ROOT="$HOME/.claude/sluice/board"
85
+ ROOTS=("$ROOT")
74
86
  else
75
- exit 0
87
+ host="$(sluice_host)"
88
+ [ "$host" != unknown ] || host=claude
89
+ anchored "$host" || exit 0
90
+ ROOT="$(sluice_state_root "$host")" || exit 4
91
+ ROOT="$ROOT/board"
92
+ ROOTS=()
93
+ for h in claude codex antigravity; do
94
+ anchored "$h" && ROOTS+=("$(sluice_state_root "$h")/board")
95
+ done
76
96
  fi
77
97
 
78
98
  case "$verb" in
@@ -125,35 +145,37 @@ case "$verb" in
125
145
  ;;
126
146
  prune)
127
147
  need_jq
128
- # The builtin read rather than a process per pointer, because prune runs
129
- # on every init and route and pointers pile up; read whole, so a tree
130
- # path holding a newline still names its tree. read -d '' stops at EOF
131
- # with a non-zero status, so a failed open is told from a short read by
132
- # whether the file is readable; a pointer that cannot be read is kept.
133
- for f in "$ROOT"/runs/*; do
134
- [ -f "$f" ] || continue
135
- tree=""
136
- { IFS= read -r -d '' tree; } 2>/dev/null <"$f" || [ -n "$tree" ] || [ -r "$f" ] || continue
137
- tree="${tree%$'\n'}"
138
- [ -f "$tree/.sluice/run.json" ] || rm -f "$f"
139
- done
140
- # One jq for every session rather than one each, because prune runs on
141
- # every route and a jq per file made each route slower than the last day
142
- # of sessions. Contents go on stdin as NUL-separated name and contents
143
- # records, as board.sh feeds them, so no count of files meets the argv
144
- # limit. Anything unreadable or unparseable comes back to be removed.
145
- for f in "$ROOT"/sessions/*.json; do
146
- [ -f "$f" ] || continue
147
- entry=""
148
- { IFS= read -r -d '' entry; } 2>/dev/null <"$f"
149
- printf '%s\0%s\0' "$f" "$entry"
150
- done | jq -R -s -j '
151
- (split("\u0000") | .[:-1]) as $p
152
- | range(0; $p | length; 2)
153
- | select(($p[. + 1] | try (fromjson | (now - (.updated | fromdateiso8601)) <= 86400) catch false) != true)
154
- | $p[.] + "\u0000"
155
- ' 2>/dev/null | while IFS= read -r -d '' f; do
156
- rm -f "$f"
148
+ for root in "${ROOTS[@]}"; do
149
+ # The builtin read rather than a process per pointer, because prune runs
150
+ # on every init and route and pointers pile up; read whole, so a tree
151
+ # path holding a newline still names its tree. read -d '' stops at EOF
152
+ # with a non-zero status, so a failed open is told from a short read by
153
+ # whether the file is readable; a pointer that cannot be read is kept.
154
+ for f in "$root"/runs/*; do
155
+ [ -f "$f" ] || continue
156
+ tree=""
157
+ { IFS= read -r -d '' tree; } 2>/dev/null <"$f" || [ -n "$tree" ] || [ -r "$f" ] || continue
158
+ tree="${tree%$'\n'}"
159
+ [ -f "$tree/.sluice/run.json" ] || rm -f "$f"
160
+ done
161
+ # One jq for every session rather than one each, because prune runs on
162
+ # every route and a jq per file made each route slower than the last day
163
+ # of sessions. Contents go on stdin as NUL-separated name and contents
164
+ # records, as board.sh feeds them, so no count of files meets the argv
165
+ # limit. Anything unreadable or unparseable comes back to be removed.
166
+ for f in "$root"/sessions/*.json; do
167
+ [ -f "$f" ] || continue
168
+ entry=""
169
+ { IFS= read -r -d '' entry; } 2>/dev/null <"$f"
170
+ printf '%s\0%s\0' "$f" "$entry"
171
+ done | jq -R -s -j '
172
+ (split("\u0000") | .[:-1]) as $p
173
+ | range(0; $p | length; 2)
174
+ | select(($p[. + 1] | try (fromjson | (now - (.updated | fromdateiso8601)) <= 86400) catch false) != true)
175
+ | $p[.] + "\u0000"
176
+ ' 2>/dev/null | while IFS= read -r -d '' f; do
177
+ rm -f "$f"
178
+ done
157
179
  done
158
180
  ;;
159
181
  esac
@@ -6,13 +6,17 @@
6
6
  #
7
7
  # --json prints the combined state instead of drawing it. --watch redraws every
8
8
  # <seconds> (default 2) until interrupted. The index is read, never written.
9
- # The root is $SLUICE_BOARD_DIR, else $CLAUDE_CONFIG_DIR/sluice/board, else
10
- # $HOME/.claude/sluice/board; with none of the three set the index is empty.
9
+ # The index is read from $SLUICE_BOARD_DIR, else from every host's board
10
+ # (host.sh's sluice_board_roots), so runs and sessions from Claude, Codex and
11
+ # Antigravity share one board. A host whose board would be built from an empty
12
+ # HOME is left out, and with none left the index is empty.
11
13
  #
12
14
  # Exit: 0 ok, 4 bad arguments, 5 jq missing, 6 the board could not be read.
13
15
 
14
16
  set -u
15
17
 
18
+ source "$(dirname "$0")/host.sh"
19
+
16
20
  err() { echo "board.sh: $*" >&2; }
17
21
 
18
22
  usage() {
@@ -52,14 +56,25 @@ fi
52
56
 
53
57
  command -v jq >/dev/null 2>&1 || { err "jq is required"; exit 5; }
54
58
 
55
- if [ -n "${SLUICE_BOARD_DIR:-}" ]; then
56
- ROOT="$SLUICE_BOARD_DIR"
57
- elif [ -n "${CLAUDE_CONFIG_DIR:-}" ]; then
58
- ROOT="$CLAUDE_CONFIG_DIR/sluice/board"
59
- elif [ -n "${HOME:-}" ]; then
60
- ROOT="$HOME/.claude/sluice/board"
59
+ # A root built from an empty HOME would sit at the filesystem root, so a host
60
+ # counts only when HOME, or the variable it reads in place of HOME, is set.
61
+ anchored() { # <host>
62
+ case "$1" in
63
+ claude) [ -n "${CLAUDE_CONFIG_DIR:-}" ] || [ -n "${HOME:-}" ] ;;
64
+ codex) [ -n "${CODEX_HOME:-}" ] || [ -n "${HOME:-}" ] ;;
65
+ *) [ -n "${HOME:-}" ] ;;
66
+ esac
67
+ }
68
+
69
+ ROOTS=()
70
+ if [ -n "${SLUICE_BOARD_DIR:-}" ] || [ -n "${HOME:-}" ]; then
71
+ while IFS= read -r root; do
72
+ ROOTS+=("$root")
73
+ done < <(sluice_board_roots)
61
74
  else
62
- ROOT=""
75
+ for h in claude codex antigravity; do
76
+ anchored "$h" && ROOTS+=("$(sluice_state_root "$h")/board")
77
+ done
63
78
  fi
64
79
 
65
80
  ESC="$(printf '\033')"
@@ -77,50 +92,67 @@ paint() { # <sgr> <text>
77
92
  fi
78
93
  }
79
94
 
95
+ # Two hosts can resolve to one directory (CODEX_HOME set to Claude's config
96
+ # dir, say), and reading it twice would list each of its sessions twice. A root
97
+ # not created yet has no real path, and is kept as written.
98
+ UNIQUE=()
99
+ REALS=()
100
+ for root in "${ROOTS[@]+"${ROOTS[@]}"}"; do
101
+ real="$(cd "$root" 2>/dev/null && pwd -P)" || real="$root"
102
+ seen=0
103
+ for r in "${REALS[@]+"${REALS[@]}"}"; do
104
+ [ "$r" = "$real" ] && seen=1
105
+ done
106
+ [ "$seen" = 1 ] && continue
107
+ REALS+=("$real")
108
+ UNIQUE+=("$root")
109
+ done
110
+ ROOTS=("${UNIQUE[@]+"${UNIQUE[@]}"}")
111
+
80
112
  # The board polls for hours while runs close and sessions are pruned under it,
81
113
  # so each file is read into a variable first and skipped when that read fails,
82
114
  # and jq gets contents rather than paths that may be gone by the time it opens
83
115
  # them. The read is the builtin, so a frame spawns no process per file. TREES
84
116
  # keeps each run's path by index, so a path holding a newline or a tab reaches
85
117
  # status.sh whole rather than through a line-split read. KEYS and VALUES are
86
- # the records emit hands jq. Returns 1 when the root, runs/ or sessions/
118
+ # the records emit hands jq. Returns 1 when any root, runs/ or sessions/
87
119
  # exists but cannot be listed: one not yet created is empty, since nothing has
88
120
  # been written there, but one that cannot be read would draw as nothing running
89
121
  # when it may hold every run on the machine.
90
122
  gather() {
91
- local n=0 f tree run entry d
123
+ local n=0 m=0 f tree run entry d root
92
124
  TREES=()
93
125
  KEYS=()
94
126
  VALUES=()
95
- [ -n "$ROOT" ] || return 0
96
- for d in "$ROOT" "$ROOT/runs" "$ROOT/sessions"; do
97
- if [ -e "$d" ] || [ -L "$d" ]; then
98
- [ -d "$d" ] && [ -r "$d" ] && [ -x "$d" ] || return 1
99
- fi
100
- done
101
- for f in "$ROOT"/runs/*; do
102
- [ -f "$f" ] || continue
103
- # read -d '' stops at EOF with a non-zero status, so a short read is told
104
- # from a failed open by whether anything arrived.
105
- tree=""
106
- { IFS= read -r -d '' tree || [ -n "$tree" ]; } 2>/dev/null <"$f" || continue
107
- tree="${tree%$'\n'}"
108
- [ -n "$tree" ] || continue
109
- run=""
110
- { IFS= read -r -d '' run || [ -n "$run" ]; } 2>/dev/null <"$tree/.sluice/run.json" || continue
111
- TREES[$n]="$tree"
112
- KEYS+=("t$n" "r$n")
113
- VALUES+=("$tree" "$run")
114
- n=$((n + 1))
115
- done
116
- n=0
117
- for f in "$ROOT"/sessions/*.json; do
118
- [ -f "$f" ] || continue
119
- entry=""
120
- { IFS= read -r -d '' entry || [ -n "$entry" ]; } 2>/dev/null <"$f" || continue
121
- KEYS+=("s$n")
122
- VALUES+=("$entry")
123
- n=$((n + 1))
127
+ for root in "${ROOTS[@]+"${ROOTS[@]}"}"; do
128
+ for d in "$root" "$root/runs" "$root/sessions"; do
129
+ if [ -e "$d" ] || [ -L "$d" ]; then
130
+ [ -d "$d" ] && [ -r "$d" ] && [ -x "$d" ] || return 1
131
+ fi
132
+ done
133
+ for f in "$root"/runs/*; do
134
+ [ -f "$f" ] || continue
135
+ # read -d '' stops at EOF with a non-zero status, so a short read is told
136
+ # from a failed open by whether anything arrived.
137
+ tree=""
138
+ { IFS= read -r -d '' tree || [ -n "$tree" ]; } 2>/dev/null <"$f" || continue
139
+ tree="${tree%$'\n'}"
140
+ [ -n "$tree" ] || continue
141
+ run=""
142
+ { IFS= read -r -d '' run || [ -n "$run" ]; } 2>/dev/null <"$tree/.sluice/run.json" || continue
143
+ TREES[$n]="$tree"
144
+ KEYS+=("t$n" "r$n")
145
+ VALUES+=("$tree" "$run")
146
+ n=$((n + 1))
147
+ done
148
+ for f in "$root"/sessions/*.json; do
149
+ [ -f "$f" ] || continue
150
+ entry=""
151
+ { IFS= read -r -d '' entry || [ -n "$entry" ]; } 2>/dev/null <"$f" || continue
152
+ KEYS+=("s$m")
153
+ VALUES+=("$entry")
154
+ m=$((m + 1))
155
+ done
124
156
  done
125
157
  }
126
158
 
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env bash
2
+ # sluice host: which agent host this shell runs under, its session id, and
3
+ # where that host keeps sluice's state. Sourced, never run:
4
+ #
5
+ # source host.sh
6
+ # sluice_host claude | codex | antigravity | unknown
7
+ # sluice_session the host's session id, empty for unknown
8
+ # sluice_state_root <host> the host's sluice state directory
9
+ # sluice_board_roots every board root, one per line
10
+ #
11
+ # $SLUICE_HOST overrides detection, for a hook whose host does not export its
12
+ # session variable. sluice_state_root exits 4 on a host it does not know, so
13
+ # call it in a subshell. No set options here: a sourced file would change
14
+ # them for its caller, and every caller sets its own.
15
+
16
+ sluice_host() {
17
+ if [ -n "${SLUICE_HOST:-}" ]; then
18
+ echo "$SLUICE_HOST"
19
+ elif [ -n "${CLAUDE_CODE_SESSION_ID:-}" ]; then
20
+ echo claude
21
+ elif [ -n "${CODEX_THREAD_ID:-}" ]; then
22
+ echo codex
23
+ elif [ -n "${ANTIGRAVITY_CONVERSATION_ID:-}" ]; then
24
+ echo antigravity
25
+ else
26
+ echo unknown
27
+ fi
28
+ }
29
+
30
+ sluice_session() {
31
+ case "$(sluice_host)" in
32
+ claude) echo "${CLAUDE_CODE_SESSION_ID:-}" ;;
33
+ codex) echo "${CODEX_THREAD_ID:-}" ;;
34
+ antigravity) echo "${ANTIGRAVITY_CONVERSATION_ID:-}" ;;
35
+ *) echo "" ;;
36
+ esac
37
+ }
38
+
39
+ sluice_state_root() {
40
+ case "${1:-}" in
41
+ claude) echo "${CLAUDE_CONFIG_DIR:-${HOME:-}/.claude}/sluice" ;;
42
+ codex) echo "${CODEX_HOME:-${HOME:-}/.codex}/sluice" ;;
43
+ antigravity) echo "${HOME:-}/.gemini/sluice" ;;
44
+ *)
45
+ echo "host.sh: unknown host '${1:-}'" >&2
46
+ exit 4
47
+ ;;
48
+ esac
49
+ }
50
+
51
+ sluice_board_roots() {
52
+ if [ -n "${SLUICE_BOARD_DIR:-}" ]; then
53
+ echo "$SLUICE_BOARD_DIR"
54
+ return
55
+ fi
56
+ local host
57
+ for host in claude codex antigravity; do
58
+ echo "$(sluice_state_root "$host")/board"
59
+ done
60
+ }
@@ -8,12 +8,18 @@
8
8
  # Usage: run-stats.sh [--tests "<what the suite reported>"] [--base <git-ref>]
9
9
  # [--transcript <path>]
10
10
  #
11
+ # With no --transcript the session is the host's own (host.sh). On Codex and
12
+ # Antigravity its transcript, and each dispatched agent's, is translated by
13
+ # transcript.sh into Claude's shape first. A --transcript is read as Claude's.
14
+ #
11
15
  # Exit 0 printed a ledger, 2 no run to report. Any other non-zero is the tool
12
16
  # failing rather than a fact about the run: no jq, no readable transcript, an
13
17
  # unknown argument, an unresolvable session id. Each prints its reason first.
14
18
 
15
19
  set -uo pipefail
16
20
 
21
+ source "$(dirname "$0")/host.sh"
22
+
17
23
  TESTS=""
18
24
  BASE=""
19
25
  TRANSCRIPT=""
@@ -23,7 +29,7 @@ while [ $# -gt 0 ]; do
23
29
  --tests) TESTS="${2-}"; shift 2 ;;
24
30
  --base) BASE="${2-}"; shift 2 ;;
25
31
  --transcript) TRANSCRIPT="${2-}"; shift 2 ;;
26
- -h|--help) sed -n '2,11p' "$0" | cut -c3-; exit 0 ;;
32
+ -h|--help) sed -n '2,15p' "$0" | cut -c3-; exit 0 ;;
27
33
  *) echo "run-stats: unknown argument '$1'" >&2; exit 1 ;;
28
34
  esac
29
35
  done
@@ -33,12 +39,44 @@ if ! command -v jq >/dev/null 2>&1; then
33
39
  exit 1
34
40
  fi
35
41
 
42
+ HOST="$(sluice_host)"
36
43
  if [ -z "$TRANSCRIPT" ]; then
37
- sid="${CLAUDE_CODE_SESSION_ID:-}"
44
+ sid="$(sluice_session)"
38
45
  if [ -z "$sid" ]; then
39
- echo "run-stats: no --transcript given and CLAUDE_CODE_SESSION_ID is unset" >&2
46
+ echo "run-stats: no --transcript given and the host gives no session id" >&2
40
47
  exit 1
41
48
  fi
49
+ fi
50
+
51
+ # Laid out as Claude lays a session out, <sid>.jsonl with its agents under
52
+ # <sid>/subagents/, so everything below reads one shape whatever the host.
53
+ if [ -z "$TRANSCRIPT" ] && [ "$HOST" != claude ]; then
54
+ # The id becomes a file name in the temp directory, so one that could climb
55
+ # out of it is refused rather than followed.
56
+ case "$sid" in
57
+ */* | .*) echo "run-stats: session id $sid is not a file name" >&2; exit 1 ;;
58
+ esac
59
+ TRANSLATE="$(dirname "$0")/transcript.sh"
60
+ source_path="$(bash "$TRANSLATE" --host "$HOST" --locate "$sid")" || exit 1
61
+ WORK="$(mktemp -d)" || { echo "run-stats: could not create a temp directory" >&2; exit 1; }
62
+ trap 'rm -rf "$WORK"' EXIT
63
+ # Bash skips the EXIT trap on a signal it has no trap for.
64
+ trap 'exit 130' INT
65
+ trap 'exit 143' TERM
66
+ TRANSCRIPT="$WORK/$sid.jsonl"
67
+ bash "$TRANSLATE" --host "$HOST" "$source_path" >"$TRANSCRIPT" || exit 1
68
+ agents="$(bash "$TRANSLATE" --host "$HOST" --agents "$source_path")" || exit 1
69
+ mkdir -p "$WORK/$sid/subagents" || { echo "run-stats: could not write under $WORK" >&2; exit 1; }
70
+ while IFS=$'\t' read -r id path; do
71
+ [ -n "$id" ] || continue
72
+ # An agent whose log does not translate stays in the ledger unpriced, which
73
+ # the row says, and the translator's reason is already on stderr.
74
+ bash "$TRANSLATE" --host "$HOST" "$path" >"$WORK/$sid/subagents/agent-$id.jsonl" ||
75
+ rm -f "$WORK/$sid/subagents/agent-$id.jsonl"
76
+ done <<<"$agents"
77
+ fi
78
+
79
+ if [ -z "$TRANSCRIPT" ]; then
42
80
  # The session id is unique across projects, so glob rather than guess the slug.
43
81
  # The harness writes under whichever config dir it was started with, so read
44
82
  # CLAUDE_CONFIG_DIR first and fall back to the default: a machine that has run
@@ -10,11 +10,44 @@
10
10
  # Reads the harness's session JSON on stdin for `cwd` and `source`, falling back
11
11
  # to $PWD when there is none. Always exits 0: a hook that fails is noise in a
12
12
  # session that has not started yet.
13
+ #
14
+ # Usage: session-start.sh [--host <claude|codex|antigravity>] [--directive <text>]
15
+ #
16
+ # The installer passes --host, because it knows which host's config it wrote
17
+ # the hook into. Every non-Claude install passes it and no Claude install ever
18
+ # has, so without it the host is Claude, whatever session variable leaks in.
19
+ # --directive is said ahead of the run, for a host that cannot run an `echo`
20
+ # of its own beside the hook.
13
21
 
14
22
  set -uo pipefail
15
23
 
16
24
  here="$(cd "$(dirname "$0")" && pwd)"
17
25
  STATUS="$here/status.sh"
26
+ source "$here/host.sh"
27
+
28
+ host=""
29
+ directive=""
30
+ while [ $# -gt 0 ]; do
31
+ case "$1" in
32
+ --host | --directive)
33
+ if [ $# -lt 2 ]; then
34
+ echo "session-start.sh: $1 needs a value" >&2
35
+ exit 0
36
+ fi
37
+ case "$1" in
38
+ --host) host="$2" ;;
39
+ --directive) directive="$2" ;;
40
+ esac
41
+ shift 2
42
+ ;;
43
+ *)
44
+ echo "session-start.sh: unknown argument '$1'" >&2
45
+ exit 0
46
+ ;;
47
+ esac
48
+ done
49
+ [ -n "$host" ] || host=claude
50
+ state_root="$(sluice_state_root "$host")" || exit 0
18
51
 
19
52
  # Bounded, and skipped on a terminal: the harness closes stdin after the JSON,
20
53
  # but a hook that inherits an open, silent stdin would otherwise never return,
@@ -32,6 +65,11 @@ fi
32
65
  cwd="$PWD"
33
66
  source=""
34
67
  sid=""
68
+ # Antigravity names the same fields its own way; renamed here so nothing below
69
+ # knows which host it is answering.
70
+ if [ "$host" = antigravity ] && [ -n "$input" ] && command -v jq >/dev/null 2>&1; then
71
+ input="$(printf '%s' "$input" | jq -c '{session_id: .conversationId, cwd: (.cwd // .workspacePaths[0]?), transcript_path: .transcriptPath}' 2>/dev/null)" || input=""
72
+ fi
35
73
  if [ -n "$input" ] && command -v jq >/dev/null 2>&1; then
36
74
  got="$(printf '%s' "$input" | jq -r '.cwd // empty' 2>/dev/null || true)"
37
75
  [ -n "$got" ] && cwd="$got"
@@ -56,7 +94,7 @@ stamp_baseline() {
56
94
  tree="$(git -C "$cwd" rev-parse --show-toplevel 2>/dev/null)" || return 0
57
95
  [ -n "$tree" ] || return 0
58
96
 
59
- local dir="${CLAUDE_CONFIG_DIR:-${HOME:-}/.claude}/sluice/stamps"
97
+ local dir="$state_root/stamps"
60
98
  mkdir -p "$dir" 2>/dev/null || return 0
61
99
 
62
100
  # This hook fires again on compact, resume and clear, all carrying the
@@ -130,26 +168,46 @@ stamp_baseline() {
130
168
  }
131
169
  stamp_baseline "$sid" "$source"
132
170
 
171
+ # Claude and Codex add plain stdout to the context; Antigravity adds only the
172
+ # steps it is handed as JSON. Each argument is one message, empty ones dropped.
173
+ say() {
174
+ local part parts=()
175
+ for part in "$@"; do
176
+ [ -n "$part" ] && parts+=("$part")
177
+ done
178
+ [ "${#parts[@]}" -gt 0 ] || return 0
179
+ case "$host" in
180
+ antigravity)
181
+ if ! command -v jq >/dev/null 2>&1; then
182
+ echo "session-start.sh: jq is required to answer antigravity" >&2
183
+ return 0
184
+ fi
185
+ jq -n '{injectSteps: [$ARGS.positional[] | {systemMessage: {systemMessage: .}}]}' --args "${parts[@]}"
186
+ ;;
187
+ *) printf '%s\n' "${parts[@]}" ;;
188
+ esac
189
+ }
190
+
133
191
  # No gate of its own beyond the directory existing: status.sh anchors on the
134
192
  # main worktree of whatever tree it is given, which is what lets a session
135
193
  # opened in a subdirectory or a linked worktree find the run, and on a tree
136
194
  # with no run it exits 2 in silence. Once per session start, that is cheap.
137
- [ -d "$cwd" ] || exit 0
138
- [ -f "$STATUS" ] || exit 0
195
+ report=""
196
+ if [ -d "$cwd" ] && [ -f "$STATUS" ] &&
197
+ shown="$(bash "$STATUS" show --dir "$cwd" ${sid:+--session "$sid"} 2>/dev/null)" && [ -n "$shown" ]; then
198
+ case "$source" in
199
+ compact | resume | clear)
200
+ advice="This session's context was summarised, resumed or cleared. Read the run record before the next dispatch and trust the two files over what you remember."
201
+ ;;
202
+ *)
203
+ advice="If this run is not the work you were asked to continue, it was left open: close it with status.sh close before starting another."
204
+ ;;
205
+ esac
206
+ report="A sluice run is live. Its state, from .sluice/run.json:
139
207
 
140
- shown="$(bash "$STATUS" show --dir "$cwd" ${sid:+--session "$sid"} 2>/dev/null)" || exit 0
141
- [ -n "$shown" ] || exit 0
208
+ $shown
142
209
 
143
- echo "A sluice run is live. Its state, from .sluice/run.json:"
144
- echo
145
- echo "$shown"
146
- echo
147
- case "$source" in
148
- compact | resume | clear)
149
- echo "This session's context was summarised, resumed or cleared. Read the run record before the next dispatch and trust the two files over what you remember."
150
- ;;
151
- *)
152
- echo "If this run is not the work you were asked to continue, it was left open: close it with status.sh close before starting another."
153
- ;;
154
- esac
210
+ $advice"
211
+ fi
212
+ say "$directive" "$report"
155
213
  exit 0
@@ -43,7 +43,9 @@
43
43
  # neither records anything. Its exit 1 also covers a tree whose changed tests
44
44
  # cannot be read.
45
45
  #
46
- # --session <id> names the session asking (default: $CLAUDE_CODE_SESSION_ID).
46
+ # --session <id> names the session asking (default: the host's own session id,
47
+ # from host.sh: $CLAUDE_CODE_SESSION_ID, $CODEX_THREAD_ID or
48
+ # $ANTIGRAVITY_CONVERSATION_ID).
47
49
  # `init` records it in the run and leaves <main tree>/.sluice/sessions/<id>
48
50
  # naming the tree the run is in, so that session finds its run from the main
49
51
  # tree however many other runs the set holds.
@@ -62,6 +64,8 @@
62
64
 
63
65
  set -uo pipefail
64
66
 
67
+ source "$(dirname "$0")/host.sh"
68
+
65
69
  STATUSES="todo active review done blocked"
66
70
  CHANNELS="bypass fast main deep"
67
71
 
@@ -109,7 +113,7 @@ in_set() {
109
113
  # subcommand's own flag loop ever sees it. Everything after `--` is verify's
110
114
  # command, kept verbatim: a `--dir` in it belongs to that command, not to us.
111
115
  DIR="$PWD"
112
- SESSION="${CLAUDE_CODE_SESSION_ID-}"
116
+ SESSION="$(sluice_session)"
113
117
  ARGS=()
114
118
  while [ $# -gt 0 ]; do
115
119
  case "$1" in
@@ -589,12 +593,12 @@ $(cd "$MAIN_ROOT" && pwd -P)"
589
593
  # stamp. A missing line or one gc has pruned is unknown, and guessing a base
590
594
  # would prove the tests against code they were never changed from.
591
595
  if [ -z "$BASE" ]; then
592
- SID="${CLAUDE_CODE_SESSION_ID-}"
593
- [ -n "$SID" ] || { err "tests-changed needs --base <ref> when CLAUDE_CODE_SESSION_ID is not set"; exit 4; }
596
+ SID="$(sluice_session)"
597
+ [ -n "$SID" ] || { err "tests-changed needs --base <ref> when the host gives no session id"; exit 4; }
594
598
  case "$SID" in
595
599
  */* | .*) err "session id $SID is not a stamp name; pass --base <ref>"; exit 4 ;;
596
600
  esac
597
- BASE="$(sed -n 3p "${CLAUDE_CONFIG_DIR:-$HOME/.claude}/sluice/stamps/$SID" 2>/dev/null)"
601
+ BASE="$(sed -n 3p "$(sluice_state_root "$(sluice_host)")/stamps/$SID" 2>/dev/null)"
598
602
  [ -n "$BASE" ] || { err "the session stamp holds no base commit, so the base is unknown; pass --base <ref>"; exit 4; }
599
603
  fi
600
604
  BASE_SHA="$(git -C "$TREE" rev-parse --verify --quiet "$BASE^{commit}" 2>/dev/null)"