fix: Replace Unix shell commands with cross-platform Node.js equivalents#13
Open
unRekable wants to merge 2 commits intoitz4blitz:mainfrom
Open
fix: Replace Unix shell commands with cross-platform Node.js equivalents#13unRekable wants to merge 2 commits intoitz4blitz:mainfrom
unRekable wants to merge 2 commits intoitz4blitz:mainfrom
Conversation
- Add phase-tracker.js: Cross-platform Node.js replacement for jq/bash UserPromptSubmit hook - Remove inline Unix shell commands from settings.json: - Removed: npx tsc --noEmit 2>&1 | head -5 (uses Unix head command) - Removed: Complex bash find/grep/sed command for similar docs detection - Removed: if [ -f ... ]; then jq ... bash command for phase tracking - All hooks now use Node.js which works on Windows, macOS, and Linux Fixes UserPromptSubmit hook error on Windows.
This PR provides 1:1 equivalent Node.js implementations for all Unix-only shell commands in settings.json, ensuring identical behavior on Windows. ## New Cross-Platform Hooks ### 1. typecheck-limiter.js Equivalent to: `npx tsc --noEmit 2>&1 | head -5 || true` - Runs TypeScript compiler in no-emit mode - Shows first 5 lines of errors (like `head -5`) - Always exits 0 (like `|| true`) - Finds local tsc in node_modules first, then global ### 2. similar-doc-detector.js Equivalent to the bash find/grep/sed command: - Reads file path from stdin (Claude Code hook standard) - Extracts search term from filename (first 30 chars, underscores → spaces) - Recursively finds all .md/.mdx files - Warns if similar documentation exists - Excludes node_modules and .git directories ### 3. phase-tracker.js Equivalent to: `if [ -f .agentful/state.json ]; then jq -r '.current_phase // "idle"' ...` - Reads current_phase from .agentful/state.json - Defaults to "idle" if not found - Cross-platform file existence check ## Technical Details All hooks: - Read input from stdin as per Claude Code hook standard - Exit 0 for informational output (non-blocking) - Work on Windows, macOS, and Linux - No external dependencies (pure Node.js) ## Files Changed - bin/hooks/typecheck-limiter.js (new) - bin/hooks/similar-doc-detector.js (new) - bin/hooks/phase-tracker.js (updated) - template/.claude/settings.json (use new hooks)
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.
Summary
This PR provides 1:1 equivalent Node.js implementations for all Unix-only shell commands in settings.json, ensuring identical behavior on Windows.
New Cross-Platform Hooks
1.
bin/hooks/typecheck-limiter.jsEquivalent to:
npx tsc --noEmit 2>&1 | head -5 || truetsc --noEmitspawn(tsc, ['--noEmit'])head -5|| trueprocess.exit(0)alwaysnode_modules/.bin/tscfirst2.
bin/hooks/similar-doc-detector.jsEquivalent to: The complex bash find/grep/sed command
find . -name '*.md'fs.readdirSync()-not -path './node_modules/*'node_modulesin loop-not -path './.git/*'.gitin loopbasename '$FILE'path.basename(filePath)sed 's/_/ /g'.replace(/_/g, ' ')sed 's/.md$//'.replace(/\.mdx?$/, '')head -c 30.substring(0, 30)xargs grep -lfs.readFileSync()+includes()grep -v "$FILE"head -1breakafter first match$FILEfrom envtool_input.file_path3.
bin/hooks/phase-tracker.jsEquivalent to:
if [ -f .agentful/state.json ]; then jq -r '.current_phase // "idle"' .agentful/state.json 2>/dev/null || echo 'idle'; else echo 'idle'; fi[ -f ... ]fs.existsSync()jq -r '.current_phase'JSON.parse().current_phase// "idle"|| 'idle'2>/dev/nulltry/catchblockTechnical Details
All hooks:
tool_input.file_path)Testing
Files Changed
bin/hooks/typecheck-limiter.js(new) - TypeScript check with output limitingbin/hooks/similar-doc-detector.js(new) - Detect similar markdown docsbin/hooks/phase-tracker.js(updated) - Track agentful phasetemplate/.claude/settings.json- Use new Node.js hooks instead of shell commands