refactor(auto-recall): accept parsed hook input directly#42
Merged
Conversation
Remove the stdout-mocking hack in hook-handlers.ts by introducing autoRecallFromInput(input: HookInput). The CLI entry autoRecall() now reads STDIN and delegates to autoRecallFromInput, which returns the hook output JSON (or null). This makes the handler testable without intercepting process.stdout and keeps the existing CLI behavior backward-compatible. - Export HookInput type from auto-recall.ts - Add autoRecallFromInput() containing the core recall logic - Keep autoRecall() as the STDIN-based CLI wrapper - Update autoRecallHandler to parse stdin and call autoRecallFromInput - Add unit tests for autoRecallFromInput - Update hook-handlers mock/test for the new function
…nId helper - Add parseHookInput() to normalize tool_name/tool_input/tool_output/session_id from hook payloads; return null for unidentified tools - Refactor readStdin() and autoRecallHandler to use parseHookInput - Extract deriveSessionId() into src/utils/session-id.ts with optional includeCwd - Adopt deriveSessionId across dashboard-collector, todowrite-hint, and contribute-check - Expand unit tests for parseHookInput, autoRecallFromInput edge cases, and deriveSessionId
a1e4830 to
1fdc50f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Remove the stdout-mocking hack in hook-handlers.ts by introducing autoRecallFromInput(input: HookInput). The CLI entry autoRecall() now reads STDIN and delegates to autoRecallFromInput, which returns the hook output JSON (or null). This makes the handler testable without intercepting process.stdout and keeps the existing CLI behavior backward-compatible.
Subsequent commits further reduce duplication:
Type of Change
Test Plan
px tsc --noEmit passes
px vitest run src/tests/auto-recall.test.ts src/tests/hook-handlers.test.ts src/tests/session-id.test.ts src/tests/dashboard-collector.test.ts src/tests/todowrite-hint.test.ts src/tests/contribute-check.test.ts src/tests/contribute-check-phase2.test.ts src/tests/auto-recall-quality.test.ts passes
Related Issues
N/A
Notes for Reviewers
The PR keeps existing behavior unchanged: