Skip to content

Commit b96a272

Browse files
Juan C. Guerrerowarp-agent
authored andcommitted
feat: always inject inline teaching context after code changes
- track-code-change.sh now always outputs additionalContext (not just first-time encounters) - track-command.sh always provides teaching context for shell commands - Added 'Automatic Inline Insights' section to sensei.md agent - Added update instructions to README Co-Authored-By: Warp <agent@warp.dev>
1 parent 0f182ea commit b96a272

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ That's it. Start building — CodeSensei activates automatically.
7373

7474
> **Requires:** [Claude Code](https://code.claude.com) with plugin support. Hook scripts use `jq` for profile tracking — install with `brew install jq` (macOS) or `apt install jq` (Linux).
7575
76+
### Updating
77+
78+
```bash
79+
# Update the marketplace catalog first:
80+
claude plugin marketplace update DojoCodingLabs/code-sensei
81+
82+
# Then update the plugin:
83+
claude plugin update code-sensei@code-sensei
84+
```
85+
86+
Restart your Claude Code session after updating — hooks are loaded at session start.
87+
7688
### Local Development
7789

7890
```bash

agents/sensei.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ When a PostToolUse hook injects `additionalContext` containing "🥋 CodeSensei
8383
- Calibrate language to the user's belt level (included in the trigger)
8484
- Example for White Belt: "By the way, that `.css` file Claude just created? That's what controls how your page LOOKS — the colors, sizes, and spacing. Think of HTML as the skeleton and CSS as the clothing."
8585

86+
## Automatic Inline Insights
87+
88+
When a PostToolUse hook injects `additionalContext` containing "🥋 CodeSensei inline insight:", you MUST act on it:
89+
- The hook fires after EVERY code change or shell command, not just first-time encounters
90+
- Provide a brief 1-2 sentence explanation of what the change does and why
91+
- Weave it naturally into your response — don't interrupt the flow
92+
- If the change is trivial (e.g. whitespace, minor formatting), skip the explanation
93+
- Calibrate language to the user's belt level (included in the trigger)
94+
- Example for White Belt: "That edit added a 'click listener' — it's like telling a button 'when someone clicks you, do THIS.'"
95+
- Example for Blue Belt: "Added an event handler on the submit button that prevents default form behavior and posts the data via fetch."
96+
8697
## Quiz Format
8798

8899
Quizzes come in three formats. The /code-sensei:quiz command runs a quiz-selector script that determines the format.

scripts/track-code-change.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,18 @@ if command -v jq &> /dev/null; then
6262
fi
6363
fi
6464

65-
# Proactive micro-lesson: inject teaching context when a NEW technology is encountered
66-
if [ "$IS_FIRST_EVER" = "true" ] && [ -f "$PROFILE_FILE" ]; then
67-
BELT=$(jq -r '.belt // "white"' "$PROFILE_FILE")
65+
# Always inject teaching context after code changes
66+
BELT=$(jq -r '.belt // "white"' "$PROFILE_FILE" 2>/dev/null || echo "white")
67+
68+
if [ "$IS_FIRST_EVER" = "true" ]; then
69+
# First-time encounter: micro-lesson about the technology
6870
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."
69-
# Output structured JSON so Claude sees the teaching trigger via additionalContext
70-
echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PostToolUse\",\"additionalContext\":\"$CONTEXT\"}}"
71+
else
72+
# Already-seen technology: inline insight about the specific change
73+
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."
7174
fi
75+
76+
echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PostToolUse\",\"additionalContext\":\"$CONTEXT\"}}"
7277
fi
7378

7479
exit 0

scripts/track-command.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,23 @@ if command -v jq &> /dev/null; then
6464
fi
6565
fi
6666

67-
# Proactive micro-lesson: inject teaching context when a NEW concept is encountered
68-
if [ "$IS_FIRST_EVER" = "true" ] && [ -f "$PROFILE_FILE" ]; then
69-
BELT=$(jq -r '.belt // "white"' "$PROFILE_FILE")
70-
# Sanitize command for JSON (remove quotes and special chars)
71-
SAFE_CMD=$(echo "$COMMAND" | head -c 80 | tr '"' "'" | tr '\\' '/')
67+
# Always inject teaching context after commands
68+
BELT=$(jq -r '.belt // "white"' "$PROFILE_FILE" 2>/dev/null || echo "white")
69+
# Sanitize command for JSON (remove quotes and special chars)
70+
SAFE_CMD=$(echo "$COMMAND" | head -c 80 | tr '"' "'" | tr '\\' '/')
71+
72+
if [ "$IS_FIRST_EVER" = "true" ] && [ -n "$CONCEPT" ]; then
73+
# First-time encounter: micro-lesson about the concept
7274
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."
73-
echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PostToolUse\",\"additionalContext\":\"$CONTEXT\"}}"
75+
elif [ -n "$CONCEPT" ]; then
76+
# Already-seen concept: brief inline insight about this specific command
77+
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."
78+
else
79+
# Unknown command type: still provide a brief hint
80+
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."
7481
fi
82+
83+
echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PostToolUse\",\"additionalContext\":\"$CONTEXT\"}}"
7584
fi
7685

7786
exit 0

0 commit comments

Comments
 (0)