Skip to content

Commit 9c8635f

Browse files
dbejarano820claude
andcommitted
feat: add debugging skill with error detection in hooks
Add debugging category with error-reading, debugging-mindset, and common-errors concepts. Add quiz questions for each. Detect error patterns in command output (skip test runners). Closes DOJ-2434 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b96a272 commit 9c8635f

File tree

3 files changed

+125
-1
lines changed

3 files changed

+125
-1
lines changed

data/concept-tree.json

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,36 @@
337337
"triggers": ["cache", "redis", "CDN", "load balancer"]
338338
}
339339
}
340+
},
341+
"debugging": {
342+
"name": "Debugging",
343+
"icon": "🐛",
344+
"belt_requirement": "white",
345+
"concepts": {
346+
"error-reading": {
347+
"name": "Error Reading",
348+
"xp_to_master": 15,
349+
"prerequisites": [],
350+
"description": "Understanding error messages and stack traces",
351+
"triggers": ["error", "Error:", "Traceback", "ENOENT", "stack trace"]
352+
},
353+
"debugging-mindset": {
354+
"name": "Debugging Mindset",
355+
"xp_to_master": 20,
356+
"prerequisites": ["error-reading"],
357+
"description": "Systematic approach to finding and fixing bugs",
358+
"triggers": ["debug", "breakpoint", "console.log", "print("]
359+
},
360+
"common-errors": {
361+
"name": "Common Errors",
362+
"xp_to_master": 25,
363+
"prerequisites": ["error-reading", "debugging-mindset"],
364+
"description": "Recognizing and fixing common programming errors",
365+
"triggers": ["TypeError", "ReferenceError", "SyntaxError", "undefined", "null"]
366+
}
367+
}
340368
}
341369
},
342-
"total_concepts": 42,
370+
"total_concepts": 45,
343371
"mastery_quiz_threshold": 3
344372
}

data/quiz-bank.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,51 @@
217217
"expected_understanding": "Docker packages an app with all its dependencies so it runs the same everywhere. Solves 'works on my machine' problems by creating consistent environments.",
218218
"hint": "Think about shipping a complete kitchen vs. just a recipe."
219219
}
220+
],
221+
"error-reading": [
222+
{
223+
"belt": "white",
224+
"question": "What does a stack trace show you?",
225+
"options": ["The list of files in your project", "The sequence of function calls that led to the error", "All the variables currently in memory"],
226+
"correct": 1,
227+
"explanation": "A stack trace is like a breadcrumb trail — it shows every function that was called, in order, up until the crash. Reading it from bottom to top tells you where the error originated and how the code got there.",
228+
"hint": "Think of it as a history of every step the program took before it fell over."
229+
},
230+
{
231+
"belt": "white",
232+
"question": "What is the first thing you should read in an error message?",
233+
"options": ["The line number at the very bottom", "The error type and the first line of the message", "The full stack trace from top to bottom"],
234+
"correct": 1,
235+
"explanation": "The error type (like `TypeError` or `SyntaxError`) and the first descriptive line tell you WHAT went wrong. Once you know what, you can use the line number and stack trace to figure out WHERE. Start at the top, not the bottom.",
236+
"hint": "Skimming a news article — you read the headline first, then the details."
237+
}
238+
],
239+
"debugging-mindset": [
240+
{
241+
"belt": "yellow",
242+
"question": "What is the most effective first step when debugging?",
243+
"options": ["Delete the code and rewrite it from scratch", "Reproduce the error reliably, then read the error message carefully", "Ask someone else to fix it"],
244+
"correct": 1,
245+
"explanation": "You can't fix what you can't consistently reproduce. Once you can make the bug happen on demand, read the error message carefully — it usually tells you exactly what went wrong and where. Only after understanding the error should you start changing code.",
246+
"hint": "A doctor diagnoses before prescribing. What's the equivalent first step for a bug?"
247+
}
248+
],
249+
"common-errors": [
250+
{
251+
"belt": "orange",
252+
"question": "What typically causes a ReferenceError in JavaScript?",
253+
"options": ["Using the wrong data type in a calculation", "Trying to use a variable that hasn't been declared or is out of scope", "A typo in an HTML tag"],
254+
"correct": 1,
255+
"explanation": "A `ReferenceError` means JavaScript looked for a variable name and couldn't find it anywhere in scope. Common causes: misspelling the variable name, using it before declaring it, or accessing it outside the block where it was defined.",
256+
"hint": "The error name says 'reference' — what does it mean when a reference points to nothing?"
257+
},
258+
{
259+
"belt": "orange",
260+
"format": "free_response",
261+
"question": "What's the difference between a syntax error and a runtime error? Give an example of each.",
262+
"expected_understanding": "A syntax error is caught before the code runs — it's a grammar mistake the interpreter can't parse (e.g., missing closing bracket). A runtime error happens while the code is running, when an operation fails on valid-looking code (e.g., calling a method on null).",
263+
"hint": "Think about the difference between a grammatically incorrect sentence and a sentence that makes sense but describes something impossible."
264+
}
220265
]
221266
}
222267
}

scripts/track-command.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,60 @@ if command -v jq &> /dev/null; then
6969
# Sanitize command for JSON (remove quotes and special chars)
7070
SAFE_CMD=$(echo "$COMMAND" | head -c 80 | tr '"' "'" | tr '\\' '/')
7171

72+
# Check if this is a test runner command — skip error detection for those
73+
IS_TEST_RUNNER="false"
74+
case "$COMMAND" in
75+
jest\ *|"jest"|\
76+
pytest\ *|"pytest"|\
77+
vitest\ *|"vitest"|\
78+
bats\ *|"bats"|\
79+
mocha\ *|"mocha"|\
80+
"npm test"*|"npm run test"*|\
81+
"yarn test"*|"yarn run test"*|\
82+
"npx jest"*|"npx vitest"*)
83+
IS_TEST_RUNNER="true"
84+
;;
85+
esac
86+
87+
# Detect error patterns in command output (only for non-test-runner commands)
88+
ERROR_CONCEPT=""
89+
if [ "$IS_TEST_RUNNER" = "false" ]; then
90+
TOOL_RESPONSE=$(echo "$INPUT" | jq -r '.tool_response // ""' 2>/dev/null || echo "")
91+
STDOUT=$(echo "$INPUT" | jq -r '.tool_response.stdout // ""' 2>/dev/null || echo "")
92+
STDERR=$(echo "$INPUT" | jq -r '.tool_response.stderr // ""' 2>/dev/null || echo "")
93+
OUTPUT="${STDOUT}${STDERR}${TOOL_RESPONSE}"
94+
95+
case "$OUTPUT" in
96+
*"Traceback (most recent call last):"*)
97+
ERROR_CONCEPT="error-reading"
98+
;;
99+
*"TypeError"*|*"ReferenceError"*|*"SyntaxError"*)
100+
ERROR_CONCEPT="common-errors"
101+
;;
102+
*"Error:"*|*"ERROR:"*|*"error:"*)
103+
ERROR_CONCEPT="error-reading"
104+
;;
105+
*"ENOENT"*|*"EACCES"*|*"EPERM"*)
106+
ERROR_CONCEPT="error-reading"
107+
;;
108+
*"command not found"*)
109+
ERROR_CONCEPT="error-reading"
110+
;;
111+
*"ModuleNotFoundError"*|*"ImportError"*)
112+
ERROR_CONCEPT="error-reading"
113+
;;
114+
*"fatal:"*)
115+
ERROR_CONCEPT="error-reading"
116+
;;
117+
esac
118+
fi
119+
72120
if [ "$IS_FIRST_EVER" = "true" ] && [ -n "$CONCEPT" ]; then
73121
# First-time encounter: micro-lesson about the concept
74122
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."
123+
elif [ -n "$ERROR_CONCEPT" ]; then
124+
# Error detected in command output: teach debugging
125+
CONTEXT="🥋 CodeSensei inline insight: An error appeared in the command output ($SAFE_CMD). The user's belt level is '$BELT'. This is a great moment to teach '$ERROR_CONCEPT' — briefly explain how to read and interpret this type of error in 1-2 sentences, adapted to their belt level. Keep it supportive and practical."
75126
elif [ -n "$CONCEPT" ]; then
76127
# Already-seen concept: brief inline insight about this specific command
77128
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."

0 commit comments

Comments
 (0)