Files
agentic-dev-template/.claude/hooks/post-manifest-edit.sh
Danijel Martinek 35da40b782 feat(claude): add 6 lifecycle hooks reinforcing template hard rules
Project-level Claude Code hooks committed to .claude/settings.json with
scripts under .claude/hooks/. Three tiers:

Tier 1 — hard guards (exit 2 to block the tool call):
- bash-guard.sh: blocks bypass flags (verify-skip, sign-skip), forceful
  push variants, destructive resets, force clean, working-tree-wipe
  checkouts/restores, force branch delete, amend, and rm -rf against
  root or home. Reinforces CLAUDE.md Git Safety Protocol.
- generator-first-nudge.sh: blocks creating a new top-level
  packages/<name> or apps/<name> directory by hand. Allows working
  inside an existing package. Reinforces the non-negotiable
  generator-first rule.

Tier 2 — context injection (stdout becomes additional context):
- session-start.sh: prints glossary, AGENTS.md, workflow CLI, and
  conformance pointers on session boot.
- prompt-context.sh: keyword-matches the user prompt against eight
  concept groups (events, realtime, audit, instrumentation, manifest,
  workflow, DI, boundaries) and injects the relevant ADR + rule
  pointers for the turn.

Tier 3 — side-effect automation:
- post-manifest-edit.sh: when Edit/Write touches feature.manifest.ts,
  prints the manifest-first ordering reminder plus the per-feature
  verify commands.
- stop-check-manifest-tests.sh: at agent Stop time, if the working
  tree has manifest changes but no sibling test changes, exits 2 to
  force continuation. Loop-guarded via stop_hook_active.

All hooks are bash + jq, use CLAUDE_PROJECT_DIR for safety, and were
smoke-tested end-to-end (block + allow paths both verified).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 13:17:38 +02:00

32 lines
988 B
Bash
Executable File

#!/usr/bin/env bash
# Tier 3 — when a feature.manifest.ts is edited, remind the agent to surface
# drift and follow manifest-first ordering. Non-blocking (stderr exit 0 is
# visible in transcript; we don't want this to kill the agent's flow).
set -euo pipefail
input=$(cat)
file_path=$(printf '%s' "$input" | jq -r '.tool_input.file_path // ""')
if [[ "$file_path" != *"feature.manifest.ts" ]]; then
exit 0
fi
feature=$(echo "$file_path" | sed -nE 's|.*packages/([^/]+)/src/feature\.manifest\.ts$|\1|p')
cat >&2 <<EOF
[post-manifest-edit] feature.manifest.ts changed (${feature:-unknown feature})
Manifest-first ordering reminder:
(1) manifest entry ← you just did this
(2) contracts — xInputSchema, xOutputSchema, IXUseCase
(3) tests (red) — colocated *.test.ts
(4) implementation — use-case + controller + DI binding
Surface drift now:
pnpm --filter @repo/${feature:-<feature>} test typecheck lint
pnpm conformance
EOF
exit 0