From 6d90281985d14a7b7caa7c08f2d013ebceb367a8 Mon Sep 17 00:00:00 2001 From: unRekable Date: Tue, 17 Feb 2026 16:32:11 +0100 Subject: [PATCH] fix: Replace Unix-only shell commands with cross-platform Node.js hooks - 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. --- bin/hooks/phase-tracker.js | 31 +++++++++++++++++++++++++++++++ template/.claude/settings.json | 21 ++------------------- 2 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 bin/hooks/phase-tracker.js diff --git a/bin/hooks/phase-tracker.js b/bin/hooks/phase-tracker.js new file mode 100644 index 0000000..86bcacc --- /dev/null +++ b/bin/hooks/phase-tracker.js @@ -0,0 +1,31 @@ +#!/usr/bin/env node + +/** + * Phase Tracker Hook + * + * Tracks current agentful phase from .agentful/state.json + * Cross-platform compatible (Windows, macOS, Linux) + */ + +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const STATE_FILE = path.join(process.cwd(), '.agentful', 'state.json'); + +try { + if (fs.existsSync(STATE_FILE)) { + const content = fs.readFileSync(STATE_FILE, 'utf8'); + const state = JSON.parse(content); + const phase = state.current_phase || 'idle'; + // Silent output - just track phase internally + // console.log(phase); + } +} catch (error) { + // Silently fail - phase tracking is optional +} + +process.exit(0); diff --git a/template/.claude/settings.json b/template/.claude/settings.json index 048fbe6..485c5f2 100644 --- a/template/.claude/settings.json +++ b/template/.claude/settings.json @@ -102,24 +102,6 @@ "description": "Protect package.json ownership metadata from accidental corruption" } ] - }, - { - "matcher": "Write|Edit|NotebookEdit", - "hooks": [ - { - "type": "command", - "command": "npx tsc --noEmit 2>&1 | head -5 || true" - } - ] - }, - { - "matcher": "Write|Edit|NotebookEdit", - "hooks": [ - { - "type": "command", - "command": "if [ \"$FILE\" = \"*.md\" ]; then existing=$(find . -name '*.md' -not -path './node_modules/*' -not -path './.git/*' | xargs grep -l \"$(basename '$FILE' | sed 's/_/ /g' | sed 's/.md$//' | head -c 30)\" 2>/dev/null | grep -v \"$FILE\" | head -1); if [ -n \"$existing\" ]; then echo \"\u26a0\ufe0f Similar doc exists: $existing - consider updating instead\"; fi; fi || true" - } - ] } ], "UserPromptSubmit": [ @@ -127,7 +109,8 @@ "hooks": [ { "type": "command", - "command": "if [ -f .agentful/state.json ]; then jq -r '.current_phase // \"idle\"' .agentful/state.json 2>/dev/null || echo 'idle'; else echo 'idle'; fi", + "command": "node bin/hooks/phase-tracker.js", + "timeout": 3, "description": "Track current agentful phase" } ]