[refactor][#593] Extract shared utilities from Python hooks #594
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Simplified repeated logic across
.claude-plugin/hooks/*.pyby centralizing shared utilities insession_utils.py. This refactoring eliminates code duplication without changing hook behavior.Changes
.claude-plugin/lib/session_utils.py:13-52with two new helpers:is_handsoff_enabled()- centralized HANDSOFF_MODE environment variable parsingwrite_issue_index()- centralized issue index file creation for session-to-issue mapping.claude-plugin/hooks/user-prompt-submit.py:23-27,75-78to use new helpers instead of inline code.claude-plugin/hooks/stop.py:13,17-20to useis_handsoff_enabled()instead of inline check.claude-plugin/hooks/post-bash-issue-create.py:29,117-119to usewrite_issue_index()instead of inline creation.claude-plugin/hooks/pre-tool-use.py:22-27to remove redundant sys.path setup insidemain().claude-plugin/lib/session_utils.mdwith complete interface documentation for new helpers.claude-plugin/lib/README.mdwith expanded usage examplesdocs/architecture/handsoff.mdto document centralized handsoff parsingTesting
tests/cli/test-session-utils.shwith 15 test cases covering:is_handsoff_enabled()with various HANDSOFF_MODE values (unset, 1, 0, false, FALSE, off, disable, enabled)write_issue_index()directory creation, JSON payload format, path return valuetest-handsoff-session-path.sh- all tests passtest-handsoff-session-pr-number.sh- all tests passtest-hook-permission-matching.sh- all 40 tests passRelated Issue
Closes #593