-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Summary
Add PostToolUse hooks that automatically run fast quality checks after file edits — formatting, type checking, console.log detection. Distinct from PreToolUse enforcement (#98) which blocks unwanted actions; PostToolUse hooks run AFTER successful tool execution and provide advisory feedback.
Motivation (from Harness Alpha Analysis)
Harness Alpha implements 7 PostToolUse hooks that catch issues at edit-time rather than waiting for end-of-workflow review:
| Hook | Trigger | Action |
|---|---|---|
| post-edit-format | After Edit/Write on .js/.ts | Auto-format with Biome or Prettier (async) |
| post-edit-typecheck | After Edit/Write on .ts | Run tsc --noEmit on changed file (async) |
| post-edit-console-warn | After Edit/Write | Warn if console.log was introduced |
| quality-gate | After Edit/Write | Fast quality checklist (async, non-blocking) |
| build-complete | After Bash (build commands) | Analyze build output for warnings |
| pr-created | After Bash (gh pr create) | Log PR URL and suggest review command |
| observe | After any tool | Capture observations for learning (async) |
Why This Is Different from #98
| Aspect | #98 (PreToolUse) | This Issue (PostToolUse) |
|---|---|---|
| Timing | Before tool runs | After tool completes |
| Purpose | Block unwanted actions | Catch quality issues |
| Effect | Prevents execution (exit 2) | Advisory feedback |
| Blocking? | Yes (gate) | No (inform) |
| Example | "Reviewer can't Write" | "Your edit introduced a type error" |
Why This Matters for DevFlow
Currently, quality issues accumulate during implementation and are caught either by:
- Scrutinizer (end of
/implement— late feedback) - Manual
npm run build/tsc(user-initiated) - Self-review (
/self-review— explicit command)
PostToolUse hooks catch issues immediately — before the agent moves on. This prevents cascading errors where one type error leads to workarounds in subsequent edits.
Technical Approach
Phase 1: Core Hooks (High Value, Low Risk)
1. Auto-Format Hook
# scripts/hooks/post-edit-format.sh
# Triggers: PostToolUse on Edit/Write for .ts/.tsx/.js/.jsx
# Detects: Biome (biome.json) → Prettier (.prettierrc) → skip
# Runs: async, non-blocking, 5-second timeout
# Output: Silent on success, warn on format diff2. TypeScript Check Hook
# scripts/hooks/post-edit-typecheck.sh
# Triggers: PostToolUse on Edit/Write for .ts/.tsx
# Runs: tsc --noEmit --pretty on the changed file
# Output: Warn with error details if type errors found
# Async: Yes, non-blocking3. Console.log Detection Hook
# scripts/hooks/post-edit-console-warn.sh
# Triggers: PostToolUse on Edit/Write
# Checks: Did the edit introduce console.log/console.debug/console.warn?
# Output: Advisory warning (not blocking)Phase 2: Extended Hooks (Future)
- Build analysis after Bash commands containing build keywords
- PR creation logging and review command suggestion
- Test result capture after Bash test commands
Integration with Existing Infrastructure
- Hook profiles (Research Report: Harness Alpha Competitive Analysis — 13 Enhancement Opportunities #107 item 2): PostToolUse hooks should respect
DEVFLOW_HOOK_PROFILEwhen implemented - Memory hooks: PostToolUse hooks are independent of session memory hooks (different lifecycle events)
- Ambient mode: PostToolUse hooks are always-on regardless of ambient classification (they're quality enforcement, not intent-based)
CLI Management
devflow init --quality-hooks # Enable PostToolUse quality hooks
devflow init --no-quality-hooks # Skip (default for now)Register in settings.json under hooks.PostToolUse[].
Effort & Impact
- Effort: Medium (3 hook scripts + CLI integration + tests)
- Impact: High — catches errors at edit-time instead of end-of-workflow
- Risk: Low — hooks are async and non-blocking; worst case is a false positive warning
Cross-Reference
- Distinct from PreToolUse Hook Enforcement System #98 (PreToolUse enforcement — blocking, policy-based)
- Complements Scrutinizer (which catches issues at end-of-workflow)
- Relates to Research Report: Harness Alpha Competitive Analysis — 13 Enhancement Opportunities #107 item 2 (Hook Profile Gating — PostToolUse hooks should be profile-gated)