Skip to content

fix(hooks): use hardcoded expanduser path in python3 always_on checks#152

Open
xiaolai wants to merge 1 commit intotanweai:mainfrom
xiaolai:fix/nlpm-pua-config-interpolation
Open

fix(hooks): use hardcoded expanduser path in python3 always_on checks#152
xiaolai wants to merge 1 commit intotanweai:mainfrom
xiaolai:fix/nlpm-pua-config-interpolation

Conversation

@xiaolai
Copy link
Copy Markdown

@xiaolai xiaolai commented Apr 26, 2026

Automated audit: This PR was generated by NLPM, a natural language programming linter, running via claude-code-action. Please evaluate the diff on its merits.

What's broken

hooks/failure-detector.sh (line 10) and hooks/frustration-trigger.sh (line 8) both check whether PUA is enabled with:

PUA_CONFIG="${HOME:-~}/.pua/config.json"
ALWAYS_ON=$(python3 -c "import json; print(json.load(open('$PUA_CONFIG')).get('always_on', True))" 2>/dev/null || echo "True")

$PUA_CONFIG is interpolated into the Python source string at the shell level. If a user's $HOME path contains a single quote (e.g. /home/o'malley) or other shell-special characters, the Python expression becomes a syntax error. Because the 2>/dev/null swallows the error and || echo "True" provides the fallback, the hook silently assumes always_on=True — meaning /pua:off has no effect for those users.

Fix

Replace the interpolated path with os.path.expanduser('~/.pua/config.json') using a hardcoded tilde. This is the same pattern already used safely in stop-feedback.sh and session-restore.sh:

ALWAYS_ON=$(python3 -c "import os,json; print(json.load(open(os.path.expanduser('~/.pua/config.json'))).get('always_on', True))" 2>/dev/null || echo "True")

One-line change per file; zero behavioral change for users with standard home directories.

failure-detector.sh and frustration-trigger.sh both used:
  python3 -c "...open('$PUA_CONFIG')..."

$PUA_CONFIG is interpolated into the Python source string at the shell
level. A config path containing a single quote or other shell-special
characters would silently break the expression (syntax error), causing
the hooks to default to 'True' / always-on even when the user has
disabled PUA via /pua:off.

Fix: use os.path.expanduser('~/.pua/config.json') with a hardcoded path,
eliminating the interpolation entirely. This matches the safe pattern
already used in stop-feedback.sh and session-restore.sh.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants