fix: Replace Bun.stdin with process.stdin in 10 v3.0 hooks (Windows/MSYS)#713
fix: Replace Bun.stdin with process.stdin in 10 v3.0 hooks (Windows/MSYS)#713chrisglick wants to merge 3 commits intodanielmiessler:mainfrom
Conversation
f529c73 to
c029678
Compare
|
Thanks for the thorough Windows compatibility work @chrisglick! We're reviewing the Windows PR series (#704, #706, #713) as a batch since they're interconnected. We don't have a Windows test environment so we'll coordinate with other Windows users to verify before merging. Great contribution! 🙏 |
…in in hooks for Windows/MSYS) # Conflicts: # Releases/v3.0/.claude/hooks/SecurityValidator.hook.ts
|
Tested on Windows 11, Git Bash (MINGW64). Here's what I got:
Hook responses:
None of them hung. Looks good to me. |
…s/MSYS compatibility Bun.stdin.text() returns empty and Bun.stdin.stream().getReader() can hang indefinitely on Windows/MSYS. All 10 remaining hooks now use process.stdin with event listeners and a timeout fallback, matching the pattern already used by 11 other hooks. Fixes danielmiessler#385 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Addresses code review feedback from nsalvacao's Gemini audit:
- Extract duplicated process.stdin pattern into reusable readStdinWithTimeout()
- All 10 hooks now import from lib/stdin.ts instead of inline patterns
- Fix require('os').homedir() → import { homedir } from 'os' for consistency
- stdin.destroy() on timeout prevents event loop hanging (DoS mitigation)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Addresses Gemini Code Assist security findings: - Add sanitizeSessionId() to lib/paths.ts — strips path traversal chars - Apply sanitization in SessionSummary, WorkCompletionLearning, StartupGreeting - Replace inline BASE_DIR with getPaiDir() from lib/paths.ts (DRY) - Remove unused homedir imports after centralizing Mitigates: path traversal via crafted session_id in stdin input. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c029678 to
d02c07e
Compare
Update: Rebased, DRY refactor, and security improvementsThanks @kaimagnus for coordinating the batch review, and @fayerman-source for the Windows 11 testing — great to have confirmation it works clean on Git Bash/MINGW64. What changed in this pushI've rebased onto latest 1. DRY refactor (
2. Security hardening (
On the failing CI checkThe CreditThe DRY and security findings came from @nsalvacao's fork (Experiments-Nuno-Salvacao#5) which ran Gemini Code Assist reviews against these changes. The path traversal findings in particular were valuable — Test plan (updated)
|
…ening Replace Bun.stdin (broken on Windows) with shared readStdinWithTimeout() utility across 10 hooks. Add sanitizeSessionId() to prevent path traversal. Changes: - Create hooks/lib/stdin.ts with cross-platform stdin reading - Migrate 10 hooks from Bun.stdin.text()/stream() to readStdinWithTimeout() - Add sanitizeSessionId() to hooks/lib/paths.ts for path traversal prevention - Update PRD with Phase 2 verification evidence (7/30 ISC passing) Hooks migrated: AlgorithmTracker, IntegrityCheck, SecurityValidator, StopOrchestrator, VoiceGate, QuestionAnswered, SessionAutoName, SessionSummary, StartupGreeting, WorkCompletionLearning Inspired by chrisglick's PR danielmiessler#713 analysis (adapted for native Windows). Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
|
Thanks for this contribution! PAI v4.0 significantly restructured the architecture — new directory layout, Algorithm v3.6.0 (up from v1.x), hooks/lib/paths.ts for path resolution, and many of the underlying systems this PR targets have been rewritten. This PR targets the v3.0 architecture and can't be cleanly applied to v4.0.x. Closing as superseded. The latest release is v4.0.2. We're actively working on platform compatibility and other bigger items. If there's still a gap not covered by the new releases, we'd welcome a fresh PR against the current codebase. Thanks again! |
Thanks for the credit! 👍 :) |
Summary
Bun.stdin.text()orBun.stdin.stream().getReader(), which fail silently on Windows/MSYS (empty return or indefinite hang)process.stdinwith event listeners and a timeout fallback — the same cross-platform pattern already used by the other 11 hooksBun.stdinremain in any v3.0 hook fileFiles Changed
AlgorithmTrackerstream().getReader()IntegrityCheckstream().getReader()QuestionAnsweredBun.stdin.text()SecurityValidatorPromise.race+Bun.stdin.text()SessionAutoNamestream().getReader()SessionSummaryPromise.race+Bun.stdin.text()StartupGreetingBun.stdin.text()StopOrchestratorstream().getReader()VoiceGatestream().getReader()WorkCompletionLearningPromise.race+Bun.stdin.text()The Pattern
Test plan
grep -r "Bun\.stdin" Releases/v3.0/.claude/hooks/returns zero matchesFixes #385
🤖 Generated with Claude Code