fix(hooks): emit the standard SessionStart envelope (#465)

The session-start hook emitted {"priority", "message"} JSON on all three
of its output paths. Codex CLI validates SessionStart hook output and
fails the hook on that shape ('hook returned invalid session start JSON
output', #465); the documented contract for both Codex and Claude Code is

  {"hookSpecificOutput": {"hookEventName": "SessionStart",
                          "additionalContext": "..."}}

Switch all three paths (meta-skill injection, jq-missing fallback,
meta-skill-missing fallback) to that envelope. Verified each path emits
valid JSON of the new shape: happy path via jq shape assertion, jq-missing
via PATH='' run, meta-skill-missing via a copy outside the repo.
This commit is contained in:
ayobamiseun
2026-08-08 18:41:01 +01:00
parent f03b4a84b0
commit abfb0b3200
+8 -4
View File
@@ -1,13 +1,17 @@
#!/bin/bash
# agent-skills session start hook
# Injects the using-agent-skills meta-skill into every new session
#
# Every output path must emit the standard SessionStart envelope
# {"hookSpecificOutput": {"hookEventName": "SessionStart", "additionalContext": "..."}}
# Hosts that validate hook output (Codex CLI, Claude Code) reject other shapes.
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
SKILLS_DIR="$(dirname "$SCRIPT_DIR")/skills"
META_SKILL="$SKILLS_DIR/using-agent-skills/SKILL.md"
if ! command -v jq >/dev/null 2>&1; then
echo '{"priority": "INFO", "message": "agent-skills: jq is required for the session-start hook but was not found on PATH. Install jq (e.g. `brew install jq` or `apt-get install jq`) to enable meta-skill injection. Skills remain available individually."}'
echo '{"hookSpecificOutput": {"hookEventName": "SessionStart", "additionalContext": "agent-skills: jq is required for the session-start hook but was not found on PATH. Install jq (e.g. `brew install jq` or `apt-get install jq`) to enable meta-skill injection. Skills remain available individually."}}'
exit 0
fi
@@ -15,10 +19,10 @@ if [ -f "$META_SKILL" ]; then
CONTENT=$(cat "$META_SKILL")
# Use jq to properly escape and construct valid JSON
jq -cn \
--arg message "agent-skills loaded. Use the skill discovery flowchart to find the right skill for your task.
--arg context "agent-skills loaded. Use the skill discovery flowchart to find the right skill for your task.
$CONTENT" \
'{priority: "IMPORTANT", message: $message}'
'{hookSpecificOutput: {hookEventName: "SessionStart", additionalContext: $context}}'
else
echo '{"priority": "INFO", "message": "agent-skills: using-agent-skills meta-skill not found. Skills may still be available individually."}'
echo '{"hookSpecificOutput": {"hookEventName": "SessionStart", "additionalContext": "agent-skills: using-agent-skills meta-skill not found. Skills may still be available individually."}}'
fi