KeiSeiKit-1.0/hooks/assemble-agents.sh
Parfii-bot 16d4b48c77 fix(hooks): guard against missing jq; drop UUOC
All three hooks used `set -eu` + `cat | jq …`. Without jq installed, jq
would fail and `-e` would abort the hook → non-zero exit → Claude Code
refuses Edit/Write/Bash system-wide. Now each hook probes for jq BEFORE
`set -eu` and exits 0 silently if absent. Also dropped the useless `cat |`
pipe — `jq -r` reads stdin directly.

Companion: install.sh jq check upgraded from warn to hard `exit 1` because
without jq the hooks are dead weight; message states jq is required on
any machine that will activate the hooks.
2026-04-21 02:55:07 +08:00

39 lines
1.2 KiB
Bash
Executable file

#!/usr/bin/env bash
# PostToolUse(Edit|Write) — auto-regenerate agent .md files.
#
# Trigger logic:
# - manifest edited (_manifests/<name>.toml) → rebuild that one agent
# - block edited (_blocks/<name>.md) → rebuild ALL agents
# - otherwise → no-op
#
# Stdin: JSON with tool_input.file_path
# Exit 0 always (non-blocking advisory)
# Silent fall-through if jq is absent; otherwise `set -eu` would abort and
# Claude Code would refuse the tool call system-wide.
command -v jq >/dev/null 2>&1 || exit 0
set -eu
ASSEMBLER="$HOME/.claude/agents/_assembler/target/release/assemble"
[ -x "$ASSEMBLER" ] || exit 0
FILE=$(jq -r '.tool_input.file_path // empty')
[ -n "$FILE" ] || exit 0
case "$FILE" in
*/agents/_manifests/*.toml)
# Single-manifest rebuild
"$ASSEMBLER" --in-place "$FILE" 2>&1 | sed 's/^/[assemble-agents] /'
;;
*/agents/_blocks/*.md)
# Block changed → rebuild everything (block is shared)
echo "[assemble-agents] block changed, rebuilding all agents..."
"$ASSEMBLER" --in-place 2>&1 | sed 's/^/[assemble-agents] /' | head -40
;;
*)
exit 0
;;
esac
exit 0