-
-
Notifications
You must be signed in to change notification settings - Fork 9k
fix: support python fallback in continuous-learning observe hook #350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ffc1688
77fcba8
30abf36
f38fd06
fc83235
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,16 @@ | |
|
|
||
| set -e | ||
|
|
||
| # Pick an available Python executable (python3 preferred, python fallback) | ||
| if command -v python3 >/dev/null 2>&1; then | ||
| PYTHON_CMD="python3" | ||
| elif command -v python >/dev/null 2>&1; then | ||
| PYTHON_CMD="python" | ||
| else | ||
| echo "[observe] No python found, skipping observation" >&2 | ||
| exit 0 | ||
| fi | ||
|
Comment on lines
+15
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, check if the file exists and explore the repository structure
find . -type f -name "observe.sh" 2>/dev/null | head -20Repository: affaan-m/everything-claude-code Length of output: 123 🏁 Script executed: # List the continuous-learning-v2 directory structure
fd . "skills/continuous-learning-v2" -type f | head -30Repository: affaan-m/everything-claude-code Length of output: 245 🏁 Script executed: # Read the observe.sh file
cat -n ./skills/continuous-learning-v2/hooks/observe.shRepository: affaan-m/everything-claude-code Length of output: 10034 🏁 Script executed: # Read the detect-project.sh file to understand CLV2_PYTHON_CMD contract
cat -n ./skills/continuous-learning-v2/scripts/detect-project.sh | head -100Repository: affaan-m/everything-claude-code Length of output: 3979 🏁 Script executed: # Read start-observer.sh
cat -n ./skills/continuous-learning-v2/agents/start-observer.sh | head -100Repository: affaan-m/everything-claude-code Length of output: 4040 Honor The early Python detection on Lines 15–24 skips PATH check for Remove the early hardcoded check and instead call 🤖 Prompt for AI Agents |
||
|
|
||
| # Hook phase from CLI argument: "pre" (PreToolUse) or "post" (PostToolUse) | ||
| HOOK_PHASE="${1:-post}" | ||
|
|
||
|
|
@@ -33,7 +43,7 @@ fi | |
|
|
||
| # Extract cwd from the hook JSON to use for project detection. | ||
| # This avoids spawning a separate git subprocess when cwd is available. | ||
| STDIN_CWD=$(echo "$INPUT_JSON" | python3 -c ' | ||
| STDIN_CWD=$(echo "$INPUT_JSON" | "$PYTHON_CMD" -c ' | ||
| import json, sys | ||
| try: | ||
| data = json.load(sys.stdin) | ||
|
|
@@ -74,7 +84,7 @@ fi | |
|
|
||
| # Parse using python via stdin pipe (safe for all JSON payloads) | ||
| # Pass HOOK_PHASE via env var since Claude Code does not include hook type in stdin JSON | ||
| PARSED=$(echo "$INPUT_JSON" | HOOK_PHASE="$HOOK_PHASE" python3 -c ' | ||
| PARSED=$(echo "$INPUT_JSON" | HOOK_PHASE="$HOOK_PHASE" "$PYTHON_CMD" -c ' | ||
| import json | ||
| import sys | ||
| import os | ||
|
|
@@ -122,13 +132,13 @@ except Exception as e: | |
| ') | ||
|
|
||
| # Check if parsing succeeded | ||
| PARSED_OK=$(echo "$PARSED" | python3 -c "import json,sys; print(json.load(sys.stdin).get('parsed', False))" 2>/dev/null || echo "False") | ||
| PARSED_OK=$(echo "$PARSED" | "$PYTHON_CMD" -c "import json,sys; print(json.load(sys.stdin).get('parsed', False))" 2>/dev/null || echo "False") | ||
|
|
||
| if [ "$PARSED_OK" != "True" ]; then | ||
| # Fallback: log raw input for debugging | ||
| timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | ||
| export TIMESTAMP="$timestamp" | ||
| echo "$INPUT_JSON" | python3 -c " | ||
| echo "$INPUT_JSON" | "$PYTHON_CMD" -c " | ||
| import json, sys, os | ||
| raw = sys.stdin.read()[:2000] | ||
| print(json.dumps({'timestamp': os.environ['TIMESTAMP'], 'event': 'parse_error', 'raw': raw})) | ||
|
|
@@ -153,7 +163,7 @@ export PROJECT_ID_ENV="$PROJECT_ID" | |
| export PROJECT_NAME_ENV="$PROJECT_NAME" | ||
| export TIMESTAMP="$timestamp" | ||
|
|
||
| echo "$PARSED" | python3 -c " | ||
| echo "$PARSED" | "$PYTHON_CMD" -c " | ||
| import json, sys, os | ||
|
|
||
| parsed = json.load(sys.stdin) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: affaan-m/everything-claude-code
Length of output: 1379
🏁 Script executed:
Repository: affaan-m/everything-claude-code
Length of output: 793
🏁 Script executed:
Repository: affaan-m/everything-claude-code
Length of output: 1571
🏁 Script executed:
Repository: affaan-m/everything-claude-code
Length of output: 1389
🏁 Script executed:
Repository: affaan-m/everything-claude-code
Length of output: 1581
Export
CLAUDE_PLUGIN_ROOTso child hooks can access it.Lines 7–12 contain duplicate
SCRIPT_DIRcomputation and setCLAUDE_PLUGIN_ROOTwithout exporting it. Child hook scripts—particularly Node scripts likerun-with-flags.js—that callgetPluginRoot()expectCLAUDE_PLUGIN_ROOTto be available in their process environment. Without the export, they cannot access the fallback value set here.Suggested fix
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT:-$(cd "${SCRIPT_DIR}/../.." && pwd)}" - -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DEFAULT_PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" -CLAUDE_PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT:-${DEFAULT_PLUGIN_ROOT}}" +export CLAUDE_PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT:-${DEFAULT_PLUGIN_ROOT}}" +PLUGIN_ROOT="$CLAUDE_PLUGIN_ROOT"🤖 Prompt for AI Agents