Skip to content

Commit 864d5a0

Browse files
committed
fix: restore valid hook teaching payloads
1 parent b1a52d2 commit 864d5a0

2 files changed

Lines changed: 12 additions & 19 deletions

File tree

scripts/track-code-change.sh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,14 @@ if [ $? -ne 0 ]; then
146146
BELT="white"
147147
fi
148148

149-
# Use json_escape for all dynamic strings embedded in the context JSON value
150-
ESCAPED_TECH=$(json_escape "$TECH")
151-
ESCAPED_FILE_PATH=$(json_escape "$FILE_PATH")
152-
ESCAPED_TOOL_NAME=$(json_escape "$TOOL_NAME")
153-
ESCAPED_BELT=$(json_escape "$BELT")
154-
155149
if [ "$IS_FIRST_EVER" = "true" ]; then
156-
CONTEXT="CodeSensei micro-lesson trigger: The user just encountered ${ESCAPED_TECH} for the FIRST TIME (file: ${ESCAPED_FILE_PATH}). Their belt level is ${ESCAPED_BELT}. Provide a brief 2-sentence explanation of what ${ESCAPED_TECH} is and why it matters for their project. Adapt language to their belt level. Keep it concise and non-intrusive — weave it naturally into your response, don't stop everything for a lecture."
150+
CONTEXT="🥋 CodeSensei micro-lesson trigger: The user just encountered '$TECH' for the FIRST TIME (file: $FILE_PATH). Their belt level is '$BELT'. Provide a brief 2-sentence explanation of what $TECH is and why it matters for their project. Adapt language to their belt level. Keep it concise and non-intrusive — weave it naturally into your response, don't stop everything for a lecture."
157151
else
158-
CONTEXT="CodeSensei inline insight: Claude just used ${ESCAPED_TOOL_NAME} on ${ESCAPED_FILE_PATH} (${ESCAPED_TECH}). The user's belt level is ${ESCAPED_BELT}. Provide a brief 1-2 sentence explanation of what this change does and why, adapted to their belt level. Keep it natural and non-intrusive — weave it into your response as a quick teaching moment."
152+
CONTEXT="🥋 CodeSensei inline insight: Claude just used '$TOOL_NAME' on '$FILE_PATH' ($TECH). The user's belt level is '$BELT'. Provide a brief 1-2 sentence explanation of what this change does and why, adapted to their belt level. Keep it natural and non-intrusive — weave it into your response as a quick teaching moment."
159153
fi
160154

161-
# Build final output — context is already a JSON string from json_escape (with quotes)
162-
printf '{"hookSpecificOutput":{"hookEventName":"PostToolUse","additionalContext":%s}}\n' "$CONTEXT"
155+
# Escape the full context once before embedding it in the hook payload
156+
ESCAPED_CONTEXT=$(json_escape "$CONTEXT")
157+
printf '{"hookSpecificOutput":{"hookEventName":"PostToolUse","additionalContext":%s}}\n' "$ESCAPED_CONTEXT"
163158

164159
exit 0

scripts/track-command.sh

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,18 @@ if [ $? -ne 0 ]; then
144144
BELT="white"
145145
fi
146146

147-
# Use json_escape for all dynamic strings embedded in the context JSON value
148-
ESCAPED_CONCEPT=$(json_escape "$CONCEPT")
149-
ESCAPED_CMD=$(json_escape "$(printf '%s' "$COMMAND" | head -c 80)")
150-
ESCAPED_BELT=$(json_escape "$BELT")
147+
SAFE_CMD=$(printf '%s' "$COMMAND" | head -c 80 | tr '"' "'" | tr '\\' '/')
151148

152149
if [ "$IS_FIRST_EVER" = "true" ] && [ -n "$CONCEPT" ]; then
153-
CONTEXT="CodeSensei micro-lesson trigger: The user just encountered ${ESCAPED_CONCEPT} for the FIRST TIME (command: ${ESCAPED_CMD}). Their belt level is ${ESCAPED_BELT}. Provide a brief 2-sentence explanation of what ${ESCAPED_CONCEPT} means and why it matters. Adapt language to their belt level. Keep it concise and non-intrusive."
150+
CONTEXT="🥋 CodeSensei micro-lesson trigger: The user just encountered '$CONCEPT' for the FIRST TIME (command: $SAFE_CMD). Their belt level is '$BELT'. Provide a brief 2-sentence explanation of what $CONCEPT means and why it matters. Adapt language to their belt level. Keep it concise and non-intrusive."
154151
elif [ -n "$CONCEPT" ]; then
155-
CONTEXT="CodeSensei inline insight: Claude just ran a ${ESCAPED_CONCEPT} command (${ESCAPED_CMD}). The user's belt level is ${ESCAPED_BELT}. Provide a brief 1-sentence explanation of what this command does, adapted to their belt level. Keep it natural and non-intrusive."
152+
CONTEXT="🥋 CodeSensei inline insight: Claude just ran a '$CONCEPT' command ($SAFE_CMD). The user's belt level is '$BELT'. Provide a brief 1-sentence explanation of what this command does, adapted to their belt level. Keep it natural and non-intrusive."
156153
else
157-
CONTEXT="CodeSensei inline insight: Claude just ran a shell command (${ESCAPED_CMD}). The user's belt level is ${ESCAPED_BELT}. If this command is educational, briefly explain what it does in 1 sentence. If trivial, skip the explanation."
154+
CONTEXT="🥋 CodeSensei inline insight: Claude just ran a shell command ($SAFE_CMD). The user's belt level is '$BELT'. If this command is educational, briefly explain what it does in 1 sentence. If trivial, skip the explanation."
158155
fi
159156

160-
# Build final output — context is already a JSON string from json_escape (with quotes)
161-
printf '{"hookSpecificOutput":{"hookEventName":"PostToolUse","additionalContext":%s}}\n' "$CONTEXT"
157+
# Escape the full context once before embedding it in the hook payload
158+
ESCAPED_CONTEXT=$(json_escape "$CONTEXT")
159+
printf '{"hookSpecificOutput":{"hookEventName":"PostToolUse","additionalContext":%s}}\n' "$ESCAPED_CONTEXT"
162160

163161
exit 0

0 commit comments

Comments
 (0)