autoworkflow 3.0.1 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,58 +1,345 @@
1
1
  #!/bin/bash
2
2
  # AutoWorkflow Session Check Hook
3
3
  # Runs on: UserPromptSubmit (every user message)
4
- # Purpose: Check for missing files and inject instructions to Claude
4
+ # Purpose: Initialize state, check for missing files, route tasks
5
+ #
6
+ # This hook implements:
7
+ # - on:conversation_start trigger
8
+ # - on:blueprint_missing trigger (AUTO-RUN audit)
9
+ # - on:init_needed trigger
10
+ # - on:task_received trigger (task classification)
5
11
 
6
- # Colors for output
12
+ # Colors
7
13
  RED='\033[0;31m'
14
+ GREEN='\033[0;32m'
8
15
  YELLOW='\033[1;33m'
9
- NC='\033[0m' # No Color
16
+ CYAN='\033[0;36m'
17
+ BOLD='\033[1m'
18
+ DIM='\033[2m'
19
+ NC='\033[0m'
10
20
 
11
- # Track if this is first message (check for state file)
12
- STATE_FILE=".claude/.autoworkflow-session"
21
+ # State directory
22
+ STATE_DIR=".claude/.autoworkflow"
23
+ mkdir -p "$STATE_DIR"
24
+
25
+ # State files
26
+ SESSION_FILE="$STATE_DIR/session-id"
27
+ PHASE_FILE="$STATE_DIR/phase"
28
+ TASK_TYPE_FILE="$STATE_DIR/task-type"
29
+ BLUEPRINT_CHECK_FILE="$STATE_DIR/blueprint-checked"
30
+ TASK_DESCRIPTION_FILE="$STATE_DIR/task-description"
31
+
32
+ # Generate session ID if new session
33
+ init_session() {
34
+ if [ ! -f "$SESSION_FILE" ]; then
35
+ echo "$(date +%s)-$$" > "$SESSION_FILE"
36
+ echo "IDLE" > "$PHASE_FILE"
37
+ rm -f "$STATE_DIR/verify-iteration" 2>/dev/null
38
+ rm -f "$STATE_DIR/verify-status" 2>/dev/null
39
+ rm -f "$STATE_DIR/changed-files" 2>/dev/null
40
+ rm -f "$BLUEPRINT_CHECK_FILE" 2>/dev/null
41
+ rm -f "$TASK_TYPE_FILE" 2>/dev/null
42
+ return 0 # New session
43
+ fi
44
+ return 1 # Existing session
45
+ }
46
+
47
+ # Get current phase
48
+ get_phase() {
49
+ if [ -f "$PHASE_FILE" ]; then
50
+ cat "$PHASE_FILE"
51
+ else
52
+ echo "IDLE"
53
+ fi
54
+ }
55
+
56
+ # Set phase
57
+ set_phase() {
58
+ echo "$1" > "$PHASE_FILE"
59
+ }
60
+
61
+ # Check if autoworkflow package is installed but not initialized
62
+ check_init_needed() {
63
+ if [ -d "node_modules/autoworkflow" ] && [ ! -f "CLAUDE.md" ]; then
64
+ echo ""
65
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
66
+ echo -e "${YELLOW}${BOLD}📦 AUTOWORKFLOW: INIT NEEDED${NC}"
67
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
68
+ echo ""
69
+ echo "AutoWorkflow package detected but not initialized."
70
+ echo ""
71
+ echo "Run: npx autoworkflow init"
72
+ echo ""
73
+ echo "This will create:"
74
+ echo " - CLAUDE.md (entry point)"
75
+ echo " - system/ (triggers, loops, gates)"
76
+ echo " - instructions/ (workflow, rules, blueprint)"
77
+ echo " - .claude/ (commands, hooks)"
78
+ echo ""
79
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
80
+ echo ""
81
+ return 0
82
+ fi
83
+ return 1
84
+ }
85
+
86
+ # Check for missing BLUEPRINT.md - triggers AUTO audit
87
+ check_blueprint() {
88
+ # Only check once per session
89
+ if [ -f "$BLUEPRINT_CHECK_FILE" ]; then
90
+ return 0
91
+ fi
92
+
93
+ # Mark as checked
94
+ touch "$BLUEPRINT_CHECK_FILE"
95
+
96
+ if [ ! -f "instructions/BLUEPRINT.md" ]; then
97
+ echo ""
98
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
99
+ echo -e "${RED}${BOLD}⚠️ AUTOWORKFLOW TRIGGER: BLUEPRINT_MISSING${NC}"
100
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
101
+ echo ""
102
+ echo "instructions/BLUEPRINT.md does not exist."
103
+ echo ""
104
+ echo -e "${BOLD}ACTION: RUN PROJECT AUDIT IMMEDIATELY${NC}"
105
+ echo ""
106
+ echo "Do NOT ask permission to start. Just run these commands now:"
107
+ echo ""
108
+ echo -e "${CYAN}1.${NC} cat package.json | head -50 ${DIM}# Detect tech stack${NC}"
109
+ echo -e "${CYAN}2.${NC} ls -la ${DIM}# See project structure${NC}"
110
+ echo -e "${CYAN}3.${NC} ls src/ 2>/dev/null || ls app/ ${DIM}# Find source directory${NC}"
111
+ echo -e "${CYAN}4.${NC} find . -name '*.ts' -o -name '*.tsx' | head -20"
112
+ echo ""
113
+ echo "Then generate:"
114
+ echo " - instructions/AI_RULES.md (tech stack, file structure)"
115
+ echo " - instructions/BLUEPRINT.md (features, routes, APIs)"
116
+ echo ""
117
+ echo -e "${YELLOW}Only ask user approval to SAVE, not to start scanning.${NC}"
118
+ echo ""
119
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
120
+ echo ""
121
+
122
+ # Set phase to indicate audit is needed
123
+ set_phase "AUDIT_REQUIRED"
124
+ return 1
125
+ fi
126
+
127
+ # Also check for AI_RULES.md
128
+ if [ ! -f "instructions/AI_RULES.md" ]; then
129
+ echo ""
130
+ echo -e "${YELLOW}⚠${NC} instructions/AI_RULES.md is missing."
131
+ echo " Generate it during the project audit."
132
+ echo ""
133
+ fi
134
+
135
+ return 0
136
+ }
137
+
138
+ # Classify task type from user input
139
+ classify_task() {
140
+ local input="$1"
141
+ local input_lower=$(echo "$input" | tr '[:upper:]' '[:lower:]')
142
+
143
+ # Query patterns (questions, not actions)
144
+ if echo "$input_lower" | grep -qE "^(what|how|why|where|when|which|who|can you|could you|explain|show me|find|search|list|tell me)"; then
145
+ echo "query"
146
+ return
147
+ fi
148
+
149
+ # Feature patterns
150
+ if echo "$input_lower" | grep -qE "(add|create|implement|build|new|feature|functionality|capability)"; then
151
+ echo "feature"
152
+ return
153
+ fi
154
+
155
+ # Fix patterns
156
+ if echo "$input_lower" | grep -qE "(fix|bug|broken|doesn't work|error|issue|problem|wrong|crash|fail)"; then
157
+ echo "fix"
158
+ return
159
+ fi
160
+
161
+ # Refactor patterns
162
+ if echo "$input_lower" | grep -qE "(refactor|clean up|restructure|reorganize|extract|split|merge|rename|improve)"; then
163
+ echo "refactor"
164
+ return
165
+ fi
166
+
167
+ # Style patterns
168
+ if echo "$input_lower" | grep -qE "(style|css|color|layout|design|spacing|font|responsive|mobile|ui|ux)"; then
169
+ echo "style"
170
+ return
171
+ fi
172
+
173
+ # Docs patterns
174
+ if echo "$input_lower" | grep -qE "(document|readme|comment|jsdoc|explain|describe)"; then
175
+ echo "docs"
176
+ return
177
+ fi
178
+
179
+ # Test patterns
180
+ if echo "$input_lower" | grep -qE "(test|spec|coverage|unit test|integration|e2e)"; then
181
+ echo "test"
182
+ return
183
+ fi
184
+
185
+ # Performance patterns
186
+ if echo "$input_lower" | grep -qE "(performance|optimize|speed|fast|slow|lag|memory|bundle)"; then
187
+ echo "perf"
188
+ return
189
+ fi
190
+
191
+ # Security patterns
192
+ if echo "$input_lower" | grep -qE "(security|vulnerability|auth|permission|sanitize|validate|escape|encrypt)"; then
193
+ echo "security"
194
+ return
195
+ fi
196
+
197
+ # Config patterns
198
+ if echo "$input_lower" | grep -qE "(config|setting|environment|env|setup|install|dependency)"; then
199
+ echo "config"
200
+ return
201
+ fi
202
+
203
+ # Default to feature for most actionable requests
204
+ echo "feature"
205
+ }
206
+
207
+ # Get workflow for task type
208
+ get_workflow() {
209
+ local task_type="$1"
210
+
211
+ case "$task_type" in
212
+ feature)
213
+ echo "ANALYZE → PLAN → CONFIRM → IMPLEMENT → VERIFY → AUDIT → COMMIT → UPDATE"
214
+ ;;
215
+ fix)
216
+ echo "ANALYZE → PLAN → CONFIRM → IMPLEMENT → VERIFY → COMMIT"
217
+ ;;
218
+ refactor)
219
+ echo "ANALYZE → PLAN → CONFIRM → IMPLEMENT → VERIFY → AUDIT → COMMIT"
220
+ ;;
221
+ style|docs|config)
222
+ echo "ANALYZE → PLAN → CONFIRM → IMPLEMENT → VERIFY → COMMIT"
223
+ ;;
224
+ test)
225
+ echo "ANALYZE → PLAN → CONFIRM → IMPLEMENT → VERIFY → RUN_TESTS → COMMIT"
226
+ ;;
227
+ perf)
228
+ echo "ANALYZE → PLAN → CONFIRM → IMPLEMENT → VERIFY → AUDIT → COMMIT"
229
+ ;;
230
+ security)
231
+ echo "ANALYZE → PLAN → CONFIRM → IMPLEMENT → VERIFY → SECURITY_REVIEW → COMMIT"
232
+ ;;
233
+ query)
234
+ echo "ANALYZE → RESPOND"
235
+ ;;
236
+ *)
237
+ echo "ANALYZE → PLAN → CONFIRM → IMPLEMENT → VERIFY → COMMIT"
238
+ ;;
239
+ esac
240
+ }
241
+
242
+ # Check if task requires audit
243
+ requires_audit() {
244
+ local task_type="$1"
245
+ case "$task_type" in
246
+ feature|refactor|perf)
247
+ return 0
248
+ ;;
249
+ *)
250
+ return 1
251
+ ;;
252
+ esac
253
+ }
254
+
255
+ # Output task classification
256
+ output_classification() {
257
+ local task_type="$1"
258
+ local workflow=$(get_workflow "$task_type")
259
+
260
+ # Save task type to state
261
+ echo "$task_type" > "$TASK_TYPE_FILE"
262
+ set_phase "ANALYZE"
13
263
 
14
- # Check if BLUEPRINT.md exists
15
- if [ ! -f "instructions/BLUEPRINT.md" ]; then
16
- echo ""
17
- echo "=================================================="
18
- echo "AUTOWORKFLOW TRIGGER: BLUEPRINT_MISSING"
19
- echo "=================================================="
20
- echo ""
21
- echo "instructions/BLUEPRINT.md does not exist."
22
- echo ""
23
- echo "ACTION REQUIRED: Run project audit IMMEDIATELY."
24
- echo "Do NOT ask permission. Just run these commands now:"
25
- echo ""
26
- echo "1. cat package.json (detect tech stack)"
27
- echo "2. ls -la (see project structure)"
28
- echo "3. find . -type d -name 'src' -o -name 'app' -o -name 'pages' | head -5"
29
- echo "4. ls src/ 2>/dev/null || ls app/ 2>/dev/null || echo 'No src/app dir'"
30
264
  echo ""
31
- echo "Then generate BLUEPRINT.md with discovered features."
32
- echo "Only ask user approval to SAVE, not to start scanning."
265
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
266
+ echo -e "${BOLD}AUTOWORKFLOW: TASK CLASSIFIED${NC}"
267
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
33
268
  echo ""
34
- echo "=================================================="
269
+ echo -e "${CYAN}Type:${NC} $task_type"
270
+ echo -e "${CYAN}Workflow:${NC} $workflow"
35
271
  echo ""
36
- fi
37
272
 
38
- # Check if AI_RULES.md exists
39
- if [ ! -f "instructions/AI_RULES.md" ]; then
40
- echo ""
41
- echo "WARNING: instructions/AI_RULES.md is missing."
42
- echo "Generate it along with BLUEPRINT.md during audit."
43
- echo ""
44
- fi
273
+ # Show required gates
274
+ echo -e "${CYAN}Required Gates:${NC}"
275
+ echo " ☐ plan_approval_gate (user must approve)"
276
+ echo " verify_gate (typecheck + lint)"
277
+
278
+ if requires_audit "$task_type"; then
279
+ echo " ☐ audit_gate (UI enforcement + cycles)"
280
+ fi
45
281
 
46
- # Check if autoworkflow is in node_modules but not initialized
47
- if [ -d "node_modules/autoworkflow" ] && [ ! -f "CLAUDE.md" ]; then
282
+ echo " ☐ pre_commit_gate (all checks)"
48
283
  echo ""
49
- echo "=================================================="
50
- echo "AUTOWORKFLOW TRIGGER: INIT_NEEDED"
51
- echo "=================================================="
284
+
285
+ # Show current phase
286
+ echo -e "${CYAN}Current Phase:${NC} ANALYZE"
52
287
  echo ""
53
- echo "AutoWorkflow package detected but not initialized."
54
- echo "Suggest user run: npx autoworkflow init"
288
+
289
+ # Instructions for this phase
290
+ echo -e "${DIM}Read relevant files and understand the codebase.${NC}"
291
+ echo -e "${DIM}Check instructions/BLUEPRINT.md for requirements.${NC}"
55
292
  echo ""
56
- echo "=================================================="
293
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
57
294
  echo ""
58
- fi
295
+ }
296
+
297
+ # Show current workflow state
298
+ show_state() {
299
+ local phase=$(get_phase)
300
+ local task_type=""
301
+
302
+ if [ -f "$TASK_TYPE_FILE" ]; then
303
+ task_type=$(cat "$TASK_TYPE_FILE")
304
+ fi
305
+
306
+ if [ "$phase" != "IDLE" ] && [ -n "$task_type" ]; then
307
+ echo ""
308
+ echo -e "${DIM}━━━ Workflow State ━━━${NC}"
309
+ echo -e "${DIM}Phase: $phase | Task: $task_type${NC}"
310
+
311
+ # Show verify iteration if in verify/fix
312
+ if [ "$phase" = "VERIFY" ] || [ "$phase" = "FIX" ]; then
313
+ if [ -f "$STATE_DIR/verify-iteration" ]; then
314
+ local iteration=$(cat "$STATE_DIR/verify-iteration")
315
+ echo -e "${DIM}Verify iteration: $iteration/10${NC}"
316
+ fi
317
+ fi
318
+
319
+ echo -e "${DIM}━━━━━━━━━━━━━━━━━━━━━━${NC}"
320
+ echo ""
321
+ fi
322
+ }
323
+
324
+ # Main execution
325
+ main() {
326
+ local is_new_session=false
327
+
328
+ # Initialize session
329
+ if init_session; then
330
+ is_new_session=true
331
+ fi
332
+
333
+ # Check if init is needed (package installed but not set up)
334
+ if check_init_needed; then
335
+ exit 0
336
+ fi
337
+
338
+ # Check for missing blueprint (triggers auto-audit)
339
+ check_blueprint
340
+
341
+ # Show current state if not idle
342
+ show_state
343
+ }
344
+
345
+ main
@@ -12,7 +12,7 @@
12
12
  {
13
13
  "type": "command",
14
14
  "command": "./.claude/hooks/session-check.sh",
15
- "timeout": 5,
15
+ "timeout": 10,
16
16
  "statusMessage": "Checking project state..."
17
17
  }
18
18
  ]
@@ -24,7 +24,9 @@
24
24
  "hooks": [
25
25
  {
26
26
  "type": "command",
27
- "command": "./.claude/hooks/post-edit.sh"
27
+ "command": "./.claude/hooks/post-edit.sh",
28
+ "timeout": 120,
29
+ "statusMessage": "Running verification..."
28
30
  }
29
31
  ]
30
32
  }
@@ -35,7 +37,9 @@
35
37
  "hooks": [
36
38
  {
37
39
  "type": "command",
38
- "command": "./.claude/hooks/pre-commit-check.sh"
40
+ "command": "./.claude/hooks/pre-tool-router.sh \"$TOOL_INPUT\"",
41
+ "timeout": 300,
42
+ "statusMessage": "Checking workflow gates..."
39
43
  }
40
44
  ]
41
45
  }
@@ -43,16 +47,54 @@
43
47
  },
44
48
 
45
49
  "instructions": [
46
- "WORKFLOW: Follow ANALYZE → PLAN → CONFIRM → IMPLEMENT → VERIFY → AUDIT → COMMIT for all tasks",
47
- "SESSION START: If instructions/BLUEPRINT.md missing, immediately scan codebase and generate it. Do not ask to start - only ask to save.",
48
- "AFTER CODE CHANGES: Run 'npm run verify' automatically. If errors exist, fix them and re-verify until passing.",
49
- "BEFORE COMMIT: Block if TODO/FIXME/console.log found in changes. Require conventional commit format: type(scope): description",
50
- "UI ENFORCEMENT: Every backend endpoint/API must have a corresponding UI component. No orphan features allowed.",
51
- "PLAN GATE: Always wait for user approval before implementing. Show plan with suggestions first.",
52
- "BLUEPRINT UPDATE: After adding new features/routes/APIs, update instructions/BLUEPRINT.md",
53
- "Read instructions/AI_RULES.md for project-specific coding standards",
54
- "Read system/router.md to classify task type",
55
- "Read system/gates.md for blocking rules"
50
+ "## WORKFLOW ENFORCEMENT",
51
+ "",
52
+ "You MUST follow this workflow for ALL tasks:",
53
+ "",
54
+ "### Phase Flow",
55
+ "```",
56
+ "ANALYZE PLAN CONFIRM IMPLEMENT → VERIFY → AUDIT → COMMIT → UPDATE",
57
+ "```",
58
+ "",
59
+ "### Auto-Triggers (Hooks enforce these)",
60
+ "1. **SESSION START**: If instructions/BLUEPRINT.md missing → AUTO-RUN audit (no permission needed)",
61
+ "2. **AFTER CODE CHANGES**: Run `npm run verify` automatically. Fix errors until passing (max 10 iterations)",
62
+ "3. **BEFORE COMMIT**: All 7 gates must pass or commit is BLOCKED:",
63
+ " - TypeScript errors = 0",
64
+ " - ESLint warnings = 0",
65
+ " - No TODO/FIXME in changes",
66
+ " - No console.log in changes",
67
+ " - No orphan features (audit:ui)",
68
+ " - No circular deps (audit:cycles)",
69
+ " - Conventional commit format: type(scope): description",
70
+ "",
71
+ "### Blocking Gates",
72
+ "- **plan_approval_gate**: WAIT for user approval before implementing",
73
+ "- **verify_gate**: Code must pass typecheck + lint",
74
+ "- **audit_gate**: No orphan features, no cycles (for features/refactors)",
75
+ "- **pre_commit_gate**: All checks must pass",
76
+ "",
77
+ "### Task Types (from system/router.md)",
78
+ "| Type | Workflow | Audit? |",
79
+ "|------|----------|--------|",
80
+ "| feature | Full (all phases) | Yes |",
81
+ "| fix | Standard (no audit) | No |",
82
+ "| refactor | Full with audit | Yes |",
83
+ "| docs | Simple | No |",
84
+ "| query | Analyze → Respond | No |",
85
+ "",
86
+ "### Required Files",
87
+ "- Read instructions/AI_RULES.md for coding standards",
88
+ "- Read instructions/BLUEPRINT.md for project state",
89
+ "- Read system/router.md to classify task type",
90
+ "- Read system/gates.md for blocking rules",
91
+ "",
92
+ "### State Tracking",
93
+ "Check .claude/.autoworkflow/ for current workflow state:",
94
+ "- phase: Current phase (ANALYZE, PLAN, etc.)",
95
+ "- task-type: Classified task type",
96
+ "- verify-iteration: Current verify loop count",
97
+ "- gate-status: Last gate check result"
56
98
  ],
57
99
 
58
100
  "workflow": {
@@ -77,7 +119,7 @@
77
119
  },
78
120
  "pre_commit": {
79
121
  "blocking": true,
80
- "checks": ["No TODO/FIXME", "No console.log", "Conventional commit format"]
122
+ "checks": ["TypeScript", "ESLint", "No TODO/FIXME", "No console.log", "UI Enforcement", "Circular Deps", "Commit Format"]
81
123
  }
82
124
  },
83
125
 
@@ -120,6 +162,9 @@
120
162
  "noOrphanFeatures": true,
121
163
  "noCircularDependencies": true,
122
164
  "conventionalCommits": true,
123
- "readBeforeWrite": true
165
+ "readBeforeWrite": true,
166
+ "planBeforeImplement": true,
167
+ "verifyAfterImplement": true,
168
+ "auditBeforeCommit": true
124
169
  }
125
170
  }
@@ -6,7 +6,12 @@
6
6
  "Bash(npm version:*)",
7
7
  "Bash(node bin/cli.js:*)",
8
8
  "Bash(npm pkg:*)",
9
- "Bash(wc:*)"
9
+ "Bash(wc:*)",
10
+ "Bash(chmod:*)",
11
+ "Bash(npm run typecheck:*)",
12
+ "Bash(git add:*)",
13
+ "Bash(git commit -m \"$\\(cat <<''EOF''\nfeat\\(hooks\\): implement full auto-trigger system with blocking gates\n\n- Add 7 new hook scripts for workflow automation:\n - session-check.sh: Init, blueprint check, task classification\n - post-edit.sh: Auto-verify with loop tracking \\(max 10 iterations\\)\n - pre-tool-router.sh: Route Bash commands to appropriate checks\n - pre-commit-check.sh: All 7 gate checks with blocking \\(exit 1\\)\n - phase-transition.sh: State management and gate enforcement\n - audit-runner.sh: UI enforcement + circular dependency checks\n - blueprint-generator.sh: Auto-scan project structure\n\n- Pre-commit gate now checks:\n - TypeScript errors\n - ESLint warnings\n - TODO/FIXME comments\n - console.log statements\n - Orphan features \\(UI enforcement\\)\n - Circular dependencies\n - Conventional commit format\n\n- State tracking in .claude/.autoworkflow/:\n - phase, task-type, verify-iteration, audit-iteration\n - verify-status, audit-status, plan-approved\n\n- Updated CLAUDE.md files with:\n - Slash commands table\n - Hook files reference\n - Hook integration section\n\nCo-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>\nEOF\n\\)\")",
14
+ "Bash(git commit:*)"
10
15
  ]
11
16
  }
12
17
  }