@hustle-together/api-dev-tools 3.12.3 → 3.12.16

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.
Files changed (96) hide show
  1. package/.claude/commands/hustle-build.md +259 -0
  2. package/.claude/commands/hustle-combine.md +1089 -0
  3. package/.claude/commands/hustle-ui-create-page.md +1078 -0
  4. package/.claude/commands/hustle-ui-create.md +1058 -0
  5. package/.claude/hooks/auto-answer.py +305 -0
  6. package/.claude/hooks/cache-research.py +337 -0
  7. package/.claude/hooks/check-api-routes.py +168 -0
  8. package/.claude/hooks/check-playwright-setup.py +103 -0
  9. package/.claude/hooks/check-storybook-setup.py +81 -0
  10. package/.claude/hooks/check-update.py +132 -0
  11. package/.claude/hooks/completion-promise-detector.py +293 -0
  12. package/.claude/hooks/context-capacity-warning.py +171 -0
  13. package/.claude/hooks/detect-interruption.py +165 -0
  14. package/.claude/hooks/docs-update-check.py +120 -0
  15. package/.claude/hooks/enforce-a11y-audit.py +202 -0
  16. package/.claude/hooks/enforce-brand-guide.py +241 -0
  17. package/.claude/hooks/enforce-component-type-confirm.py +97 -0
  18. package/.claude/hooks/enforce-dry-run.py +134 -0
  19. package/.claude/hooks/enforce-freshness.py +184 -0
  20. package/.claude/hooks/enforce-page-components.py +186 -0
  21. package/.claude/hooks/enforce-page-data-schema.py +155 -0
  22. package/.claude/hooks/enforce-questions-sourced.py +146 -0
  23. package/.claude/hooks/enforce-schema-from-interview.py +248 -0
  24. package/.claude/hooks/enforce-ui-disambiguation.py +108 -0
  25. package/.claude/hooks/enforce-ui-interview.py +130 -0
  26. package/.claude/hooks/generate-adr-options.py +282 -0
  27. package/.claude/hooks/generate-manifest-entry.py +1161 -0
  28. package/.claude/hooks/hook_utils.py +609 -0
  29. package/.claude/hooks/lib/__init__.py +1 -0
  30. package/.claude/hooks/lib/__pycache__/__init__.cpython-314.pyc +0 -0
  31. package/.claude/hooks/lib/__pycache__/greptile.cpython-314.pyc +0 -0
  32. package/.claude/hooks/lib/__pycache__/ntfy.cpython-314.pyc +0 -0
  33. package/.claude/hooks/lib/greptile.py +355 -0
  34. package/.claude/hooks/lib/ntfy.py +209 -0
  35. package/.claude/hooks/notify-input-needed.py +73 -0
  36. package/.claude/hooks/notify-phase-complete.py +90 -0
  37. package/.claude/hooks/ntfy-on-question.py +240 -0
  38. package/.claude/hooks/orchestrator-completion.py +313 -0
  39. package/.claude/hooks/orchestrator-handoff.py +267 -0
  40. package/.claude/hooks/orchestrator-session-startup.py +146 -0
  41. package/.claude/hooks/parallel-orchestrator.py +451 -0
  42. package/.claude/hooks/project-document-prompt.py +302 -0
  43. package/.claude/hooks/remote-question-proxy.py +284 -0
  44. package/.claude/hooks/remote-question-server.py +1224 -0
  45. package/.claude/hooks/run-code-review.py +393 -0
  46. package/.claude/hooks/run-visual-qa.py +338 -0
  47. package/.claude/hooks/session-logger.py +323 -0
  48. package/.claude/hooks/test-orchestrator-reground.py +248 -0
  49. package/.claude/hooks/track-scope-coverage.py +220 -0
  50. package/.claude/hooks/track-token-usage.py +121 -0
  51. package/.claude/hooks/update-adr-decision.py +236 -0
  52. package/.claude/hooks/update-api-showcase.py +161 -0
  53. package/.claude/hooks/update-registry.py +352 -0
  54. package/.claude/hooks/update-testing-checklist.py +195 -0
  55. package/.claude/hooks/update-ui-showcase.py +224 -0
  56. package/.claude/settings.local.json +7 -1
  57. package/.claude/test-auto-answer-bot.py +183 -0
  58. package/.claude/test-completion-detector.py +263 -0
  59. package/.claude/test-orchestrator-state.json +20 -0
  60. package/.claude/test-orchestrator.sh +271 -0
  61. package/.skills/api-create/SKILL.md +88 -3
  62. package/.skills/docs-sync/SKILL.md +260 -0
  63. package/.skills/hustle-build/SKILL.md +459 -0
  64. package/.skills/hustle-build-review/SKILL.md +518 -0
  65. package/CHANGELOG.md +87 -0
  66. package/README.md +86 -9
  67. package/bin/cli.js +1302 -88
  68. package/commands/hustle-api-create.md +22 -0
  69. package/commands/hustle-combine.md +81 -2
  70. package/commands/hustle-ui-create-page.md +84 -2
  71. package/commands/hustle-ui-create.md +82 -2
  72. package/hooks/auto-answer.py +228 -0
  73. package/hooks/check-update.py +132 -0
  74. package/hooks/ntfy-on-question.py +227 -0
  75. package/hooks/orchestrator-completion.py +313 -0
  76. package/hooks/orchestrator-handoff.py +189 -0
  77. package/hooks/orchestrator-session-startup.py +146 -0
  78. package/hooks/periodic-reground.py +230 -67
  79. package/hooks/update-api-showcase.py +13 -1
  80. package/hooks/update-ui-showcase.py +13 -1
  81. package/package.json +7 -3
  82. package/scripts/extract-schema-docs.cjs +322 -0
  83. package/templates/CLAUDE-SECTION.md +89 -64
  84. package/templates/api-showcase/_components/APIModal.tsx +100 -8
  85. package/templates/api-showcase/_components/APIShowcase.tsx +36 -4
  86. package/templates/api-showcase/_components/APITester.tsx +367 -58
  87. package/templates/docs/page.tsx +230 -0
  88. package/templates/hustle-build-defaults.json +84 -0
  89. package/templates/hustle-dev-dashboard/page.tsx +365 -0
  90. package/templates/playwright-report/page.tsx +258 -0
  91. package/templates/settings.json +88 -7
  92. package/templates/test-results/page.tsx +237 -0
  93. package/templates/typedoc.json +19 -0
  94. package/templates/ui-showcase/_components/UIShowcase.tsx +1 -1
  95. package/templates/ui-showcase/page.tsx +1 -1
  96. package/.claude/api-dev-state.json +0 -466
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Enforce Dry-Run Mode Hook
4
+
5
+ This hook blocks Write and Edit operations when --dry-run mode is active.
6
+ It allows the workflow to run completely (research, interviews, schema generation)
7
+ but prevents any files from being written.
8
+
9
+ Hook Type: PreToolUse (matcher: Write, Edit)
10
+
11
+ Use Cases:
12
+ - Preview what a workflow will create before committing
13
+ - Test autonomous mode without modifying files
14
+ - Validate workflow logic without side effects
15
+
16
+ v4.5.0: Initial implementation
17
+ """
18
+
19
+ import json
20
+ import os
21
+ import sys
22
+ from pathlib import Path
23
+
24
+ # Import shared utilities
25
+ try:
26
+ from hook_utils import (
27
+ check_dry_run_mode,
28
+ log_workflow_event,
29
+ load_state
30
+ )
31
+ UTILS_AVAILABLE = True
32
+ except ImportError:
33
+ UTILS_AVAILABLE = False
34
+
35
+
36
+ def get_file_path_from_env():
37
+ """Extract file path from tool input environment variable."""
38
+ tool_input = os.environ.get("CLAUDE_TOOL_INPUT", "{}")
39
+ try:
40
+ data = json.loads(tool_input)
41
+ return data.get("file_path", "unknown")
42
+ except json.JSONDecodeError:
43
+ return "unknown"
44
+
45
+
46
+ def main():
47
+ """Main hook entry point."""
48
+ tool_name = os.environ.get("CLAUDE_TOOL_NAME", "")
49
+
50
+ # Only enforce for Write and Edit tools
51
+ if tool_name not in ["Write", "Edit"]:
52
+ print(json.dumps({"continue": True}))
53
+ return
54
+
55
+ # Check if dry-run mode is active
56
+ dry_run_active = False
57
+
58
+ if UTILS_AVAILABLE:
59
+ try:
60
+ dry_run_active = check_dry_run_mode()
61
+ except Exception:
62
+ pass
63
+ else:
64
+ # Fallback: check state file directly
65
+ try:
66
+ project_dir = os.environ.get("CLAUDE_PROJECT_DIR", ".")
67
+ state_file = Path(project_dir) / ".claude" / "api-dev-state.json"
68
+ if state_file.exists():
69
+ state = json.loads(state_file.read_text())
70
+ dry_run_active = state.get("dry_run_mode", False) or state.get("flags", {}).get("dry_run", False)
71
+ except Exception:
72
+ pass
73
+
74
+ if not dry_run_active:
75
+ # Normal mode - allow the operation
76
+ print(json.dumps({"continue": True}))
77
+ return
78
+
79
+ # Dry-run mode active - block the write
80
+ file_path = get_file_path_from_env()
81
+
82
+ # Log the blocked operation
83
+ if UTILS_AVAILABLE:
84
+ try:
85
+ log_workflow_event("dry_run_block", {
86
+ "tool": tool_name,
87
+ "file_path": file_path,
88
+ "action": "blocked"
89
+ })
90
+ except Exception:
91
+ pass
92
+
93
+ # Return blocking result with informative message
94
+ result = {
95
+ "continue": False,
96
+ "reason": f"""## 🔒 Dry-Run Mode Active
97
+
98
+ **Tool:** {tool_name}
99
+ **Would write to:** `{file_path}`
100
+
101
+ In dry-run mode, no files are modified. The workflow continues to show
102
+ what WOULD be created, but Write and Edit operations are blocked.
103
+
104
+ ### To Execute For Real:
105
+ 1. Run the same command without `--dry-run`
106
+ 2. Or disable dry-run: Update state with `dry_run_mode: false`
107
+
108
+ ### Preview Summary:
109
+ This operation would {_get_operation_description(tool_name, file_path)}
110
+
111
+ ---
112
+ _Dry-run preview - no files were modified_
113
+ """
114
+ }
115
+ print(json.dumps(result))
116
+
117
+
118
+ def _get_operation_description(tool_name, file_path):
119
+ """Generate a human-readable description of the blocked operation."""
120
+ path = Path(file_path)
121
+
122
+ if tool_name == "Write":
123
+ if not path.exists() if file_path != "unknown" else True:
124
+ return f"create a new file at `{file_path}`"
125
+ return f"overwrite the file at `{file_path}`"
126
+
127
+ if tool_name == "Edit":
128
+ return f"modify the file at `{file_path}`"
129
+
130
+ return f"perform a {tool_name} operation on `{file_path}`"
131
+
132
+
133
+ if __name__ == "__main__":
134
+ main()
@@ -0,0 +1,184 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Hook: PreToolUse (Write|Edit)
4
+ Purpose: Enforce research freshness for the active endpoint
5
+
6
+ This hook blocks Write/Edit operations if:
7
+ 1. There is an active endpoint in api-dev-state.json
8
+ 2. Research exists for that endpoint
9
+ 3. Research is older than 7 days (configurable)
10
+
11
+ The user can:
12
+ - Run /hustle-api-research to refresh the research
13
+ - Set "enforce_freshness": false in the endpoint config to disable
14
+ - Research is only enforced for the ACTIVE endpoint
15
+
16
+ Exit Codes:
17
+ - 0: Continue (no active endpoint, research is fresh, or enforcement disabled)
18
+ - 2: Block with message (research is stale, requires re-research)
19
+
20
+ Added in v3.7.0:
21
+ - User requested enforcement (not just warning) for stale research
22
+ - Only enforces for the active endpoint being worked on
23
+ """
24
+ import json
25
+ import sys
26
+ import os
27
+ from datetime import datetime
28
+ from pathlib import Path
29
+
30
+ # State file is in .claude/ directory (sibling to hooks/)
31
+ STATE_FILE = Path(__file__).parent.parent / "api-dev-state.json"
32
+ RESEARCH_INDEX = Path(__file__).parent.parent / "research" / "index.json"
33
+
34
+ # Default freshness threshold (days)
35
+ FRESHNESS_THRESHOLD_DAYS = 7
36
+
37
+
38
+ def get_active_endpoint(state):
39
+ """Get active endpoint - supports both old and new state formats."""
40
+ if "endpoints" in state and "active_endpoint" in state:
41
+ active = state.get("active_endpoint")
42
+ if active and active in state["endpoints"]:
43
+ return active, state["endpoints"][active]
44
+ return None, None
45
+
46
+ # Old format
47
+ endpoint = state.get("endpoint")
48
+ if endpoint:
49
+ return endpoint, state
50
+
51
+ return None, None
52
+
53
+
54
+ def load_research_index():
55
+ """Load research index from .claude/research/index.json file."""
56
+ if not RESEARCH_INDEX.exists():
57
+ return {}
58
+ try:
59
+ index = json.loads(RESEARCH_INDEX.read_text())
60
+ return index.get("apis", {})
61
+ except (json.JSONDecodeError, IOError):
62
+ return {}
63
+
64
+
65
+ def calculate_days_old(timestamp_str):
66
+ """Calculate how many days old a timestamp is."""
67
+ if not timestamp_str:
68
+ return 0
69
+ try:
70
+ last_updated = datetime.fromisoformat(timestamp_str.replace('Z', '+00:00'))
71
+ now = datetime.now(last_updated.tzinfo) if last_updated.tzinfo else datetime.now()
72
+ return (now - last_updated).days
73
+ except (ValueError, TypeError):
74
+ return 0
75
+
76
+
77
+ def is_api_related_file(file_path):
78
+ """Check if the file being written is API-related."""
79
+ if not file_path:
80
+ return False
81
+
82
+ file_path = file_path.lower()
83
+
84
+ # Files that indicate API development
85
+ api_indicators = [
86
+ '/api/',
87
+ '/route.ts',
88
+ '/route.js',
89
+ '.api.test.',
90
+ '/schemas/',
91
+ 'api-tests-manifest',
92
+ '/v2/'
93
+ ]
94
+
95
+ return any(indicator in file_path for indicator in api_indicators)
96
+
97
+
98
+ def main():
99
+ # Read hook input from stdin
100
+ try:
101
+ input_data = json.load(sys.stdin)
102
+ except json.JSONDecodeError:
103
+ input_data = {}
104
+
105
+ # Get the file being written (if applicable)
106
+ tool_input = input_data.get("toolInput", {})
107
+ file_path = tool_input.get("file_path", "")
108
+
109
+ # Only enforce for API-related files
110
+ if not is_api_related_file(file_path):
111
+ print(json.dumps({"continue": True}))
112
+ sys.exit(0)
113
+
114
+ # Check if state file exists
115
+ if not STATE_FILE.exists():
116
+ print(json.dumps({"continue": True}))
117
+ sys.exit(0)
118
+
119
+ try:
120
+ state = json.loads(STATE_FILE.read_text())
121
+ except json.JSONDecodeError:
122
+ print(json.dumps({"continue": True}))
123
+ sys.exit(0)
124
+
125
+ # Get active endpoint
126
+ endpoint, endpoint_data = get_active_endpoint(state)
127
+ if not endpoint or not endpoint_data:
128
+ # No active endpoint - allow
129
+ print(json.dumps({"continue": True}))
130
+ sys.exit(0)
131
+
132
+ # Check if freshness enforcement is disabled for this endpoint
133
+ if endpoint_data.get("enforce_freshness") is False:
134
+ print(json.dumps({"continue": True}))
135
+ sys.exit(0)
136
+
137
+ # Check research freshness
138
+ research_index = load_research_index()
139
+
140
+ if endpoint not in research_index:
141
+ # No research indexed yet - allow but note this is caught by enforce-research.py
142
+ print(json.dumps({"continue": True}))
143
+ sys.exit(0)
144
+
145
+ entry = research_index[endpoint]
146
+ last_updated = entry.get("last_updated", "")
147
+ days_old = calculate_days_old(last_updated)
148
+
149
+ # Get custom threshold if set
150
+ threshold = endpoint_data.get("freshness_threshold_days", FRESHNESS_THRESHOLD_DAYS)
151
+
152
+ if days_old > threshold:
153
+ # Research is stale - block and require re-research
154
+ output = {
155
+ "decision": "block",
156
+ "reason": f"""🔄 STALE RESEARCH DETECTED
157
+
158
+ Research for '{endpoint}' is {days_old} days old (threshold: {threshold} days).
159
+
160
+ **Action Required:**
161
+ Run `/hustle-api-research {endpoint}` to refresh the research before continuing.
162
+
163
+ **Why This Matters:**
164
+ - API documentation may have changed
165
+ - New parameters or features may be available
166
+ - Breaking changes may have been introduced
167
+ - Your implementation may not match current docs
168
+
169
+ **To Skip (Not Recommended):**
170
+ Set `"enforce_freshness": false` in api-dev-state.json for this endpoint.
171
+
172
+ Last researched: {last_updated or 'Unknown'}
173
+ Research location: .claude/research/{endpoint}/CURRENT.md"""
174
+ }
175
+ print(json.dumps(output))
176
+ sys.exit(2) # Exit code 2 = block with message
177
+
178
+ # Research is fresh - continue
179
+ print(json.dumps({"continue": True}))
180
+ sys.exit(0)
181
+
182
+
183
+ if __name__ == "__main__":
184
+ main()
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Hook: enforce-page-components.py
4
+ Trigger: PreToolUse (Write|Edit)
5
+ Purpose: Check that components from registry are considered before creating new ones
6
+
7
+ For ui-create-page workflow, ensures Phase 5 (PAGE ANALYSIS) is complete and
8
+ encourages reuse of existing components from the registry.
9
+ """
10
+
11
+ import json
12
+ import sys
13
+ import os
14
+ import re
15
+
16
+ def load_state():
17
+ """Load the api-dev-state.json file"""
18
+ state_paths = [
19
+ ".claude/api-dev-state.json",
20
+ os.path.join(os.environ.get("CLAUDE_PROJECT_DIR", ""), ".claude/api-dev-state.json")
21
+ ]
22
+
23
+ for path in state_paths:
24
+ if os.path.exists(path):
25
+ with open(path, 'r') as f:
26
+ return json.load(f)
27
+ return None
28
+
29
+ def load_registry():
30
+ """Load the registry.json file"""
31
+ registry_paths = [
32
+ ".claude/registry.json",
33
+ os.path.join(os.environ.get("CLAUDE_PROJECT_DIR", ""), ".claude/registry.json")
34
+ ]
35
+
36
+ for path in registry_paths:
37
+ if os.path.exists(path):
38
+ with open(path, 'r') as f:
39
+ return json.load(f)
40
+ return {}
41
+
42
+ def is_page_workflow(state):
43
+ """Check if current workflow is ui-create-page"""
44
+ workflow = state.get("workflow", "")
45
+ return workflow == "ui-create-page"
46
+
47
+ def get_active_element(state):
48
+ """Get the active element being worked on"""
49
+ active = state.get("active_element", "")
50
+ if not active:
51
+ active = state.get("endpoint", "")
52
+ return active
53
+
54
+ def is_creating_new_component(file_path):
55
+ """Check if the file path suggests creating a new standalone component"""
56
+ if not file_path:
57
+ return False
58
+
59
+ # Patterns that suggest a new standalone component (not page-specific)
60
+ standalone_patterns = [
61
+ r"src/components/[A-Z]",
62
+ r"components/ui/",
63
+ r"components/shared/",
64
+ ]
65
+
66
+ return any(re.search(pattern, file_path) for pattern in standalone_patterns)
67
+
68
+ def is_page_specific_component(file_path, element_name):
69
+ """Check if the file is a page-specific component (allowed)"""
70
+ if not file_path or not element_name:
71
+ return False
72
+
73
+ # Page-specific components in _components folder are allowed
74
+ patterns = [
75
+ f"src/app/{element_name}/_components/",
76
+ f"app/{element_name}/_components/",
77
+ ]
78
+
79
+ return any(pattern in file_path for pattern in patterns)
80
+
81
+ def check_page_analysis_phase(state, element_name):
82
+ """Check if page analysis phase is complete"""
83
+ elements = state.get("elements", {})
84
+ element = elements.get(element_name, {})
85
+ phases = element.get("phases", {})
86
+
87
+ page_analysis = phases.get("page_analysis", {})
88
+ return page_analysis.get("status") == "complete"
89
+
90
+ def get_available_components(registry):
91
+ """Get list of available components from registry"""
92
+ components = registry.get("components", {})
93
+ return list(components.keys())
94
+
95
+ def main():
96
+ try:
97
+ # Read tool input from stdin
98
+ input_data = json.loads(sys.stdin.read())
99
+ tool_name = input_data.get("tool_name", "")
100
+ tool_input = input_data.get("tool_input", {})
101
+
102
+ # Only check Write tool
103
+ if tool_name != "Write":
104
+ print(json.dumps({"decision": "allow"}))
105
+ return
106
+
107
+ file_path = tool_input.get("file_path", "")
108
+
109
+ # Load state
110
+ state = load_state()
111
+ if not state:
112
+ print(json.dumps({"decision": "allow"}))
113
+ return
114
+
115
+ # Only apply to ui-create-page workflow
116
+ if not is_page_workflow(state):
117
+ print(json.dumps({"decision": "allow"}))
118
+ return
119
+
120
+ element_name = get_active_element(state)
121
+ if not element_name:
122
+ print(json.dumps({"decision": "allow"}))
123
+ return
124
+
125
+ # Allow page-specific components (in _components folder)
126
+ if is_page_specific_component(file_path, element_name):
127
+ print(json.dumps({"decision": "allow"}))
128
+ return
129
+
130
+ # Check if creating a new standalone component
131
+ if is_creating_new_component(file_path):
132
+ # Check if page analysis phase is complete
133
+ if not check_page_analysis_phase(state, element_name):
134
+ # Load registry to show available components
135
+ registry = load_registry()
136
+ available = get_available_components(registry)
137
+
138
+ component_list = "\n".join([f" - {c}" for c in available[:10]])
139
+ if len(available) > 10:
140
+ component_list += f"\n ... and {len(available) - 10} more"
141
+
142
+ print(json.dumps({
143
+ "decision": "block",
144
+ "reason": f"""
145
+ PAGE ANALYSIS REQUIRED (Phase 5)
146
+
147
+ You are creating a new standalone component, but Page Analysis phase is not complete.
148
+
149
+ Before creating new components:
150
+ 1. Check the registry for existing components
151
+ 2. Decide which existing components to reuse
152
+ 3. Update state: phases.page_analysis.status = "complete"
153
+
154
+ Available Components in Registry:
155
+ {component_list if available else " (No components registered yet)"}
156
+
157
+ If you need a NEW component, consider:
158
+ - Using /ui-create to properly create and document it
159
+ - Or create a page-specific component in src/app/{element_name}/_components/
160
+ """
161
+ }))
162
+ return
163
+
164
+ # Even if phase is complete, notify about registry
165
+ registry = load_registry()
166
+ available = get_available_components(registry)
167
+
168
+ if available:
169
+ print(json.dumps({
170
+ "decision": "allow",
171
+ "message": f"Note: {len(available)} components available in registry. Consider reusing existing components."
172
+ }))
173
+ return
174
+
175
+ # Allow everything else
176
+ print(json.dumps({"decision": "allow"}))
177
+
178
+ except Exception as e:
179
+ # On error, allow to avoid blocking workflow
180
+ print(json.dumps({
181
+ "decision": "allow",
182
+ "error": str(e)
183
+ }))
184
+
185
+ if __name__ == "__main__":
186
+ main()
@@ -0,0 +1,155 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Hook: enforce-page-data-schema.py
4
+ Trigger: PreToolUse (Write|Edit)
5
+ Purpose: Validate that API response types are defined before page implementation
6
+
7
+ For ui-create-page workflow, ensures Phase 6 (DATA SCHEMA) is complete before
8
+ allowing page implementation in Phase 9.
9
+ """
10
+
11
+ import json
12
+ import sys
13
+ import os
14
+ import re
15
+
16
+ def load_state():
17
+ """Load the api-dev-state.json file"""
18
+ state_paths = [
19
+ ".claude/api-dev-state.json",
20
+ os.path.join(os.environ.get("CLAUDE_PROJECT_DIR", ""), ".claude/api-dev-state.json")
21
+ ]
22
+
23
+ for path in state_paths:
24
+ if os.path.exists(path):
25
+ with open(path, 'r') as f:
26
+ return json.load(f)
27
+ return None
28
+
29
+ def is_page_workflow(state):
30
+ """Check if current workflow is ui-create-page"""
31
+ workflow = state.get("workflow", "")
32
+ return workflow == "ui-create-page"
33
+
34
+ def get_active_element(state):
35
+ """Get the active element being worked on"""
36
+ active = state.get("active_element", "")
37
+ if not active:
38
+ # Fall back to endpoint for older state files
39
+ active = state.get("endpoint", "")
40
+ return active
41
+
42
+ def is_page_file(file_path, element_name):
43
+ """Check if the file being written is a page implementation file"""
44
+ if not file_path or not element_name:
45
+ return False
46
+
47
+ patterns = [
48
+ f"src/app/{element_name}/page.tsx",
49
+ f"src/app/{element_name}/layout.tsx",
50
+ f"src/app/{element_name}/_components/",
51
+ f"app/{element_name}/page.tsx",
52
+ ]
53
+
54
+ return any(pattern in file_path for pattern in patterns)
55
+
56
+ def is_types_file(file_path, element_name):
57
+ """Check if the file being written is the types/schema file"""
58
+ if not file_path or not element_name:
59
+ return False
60
+
61
+ patterns = [
62
+ f"src/app/{element_name}/_types/",
63
+ f"src/app/{element_name}/types.ts",
64
+ f"src/lib/schemas/{element_name}",
65
+ ]
66
+
67
+ return any(pattern in file_path for pattern in patterns)
68
+
69
+ def is_test_file(file_path):
70
+ """Check if file is a test file"""
71
+ return "__tests__" in file_path or ".test." in file_path or ".spec." in file_path
72
+
73
+ def check_data_schema_phase(state, element_name):
74
+ """Check if data schema phase is complete"""
75
+ elements = state.get("elements", {})
76
+ element = elements.get(element_name, {})
77
+ phases = element.get("phases", {})
78
+
79
+ # Check data_schema phase
80
+ data_schema = phases.get("data_schema", {})
81
+ return data_schema.get("status") == "complete"
82
+
83
+ def main():
84
+ try:
85
+ # Read tool input from stdin
86
+ input_data = json.loads(sys.stdin.read())
87
+ tool_name = input_data.get("tool_name", "")
88
+ tool_input = input_data.get("tool_input", {})
89
+
90
+ # Only check Write and Edit tools
91
+ if tool_name not in ["Write", "Edit"]:
92
+ print(json.dumps({"decision": "allow"}))
93
+ return
94
+
95
+ file_path = tool_input.get("file_path", "")
96
+
97
+ # Load state
98
+ state = load_state()
99
+ if not state:
100
+ print(json.dumps({"decision": "allow"}))
101
+ return
102
+
103
+ # Only apply to ui-create-page workflow
104
+ if not is_page_workflow(state):
105
+ print(json.dumps({"decision": "allow"}))
106
+ return
107
+
108
+ element_name = get_active_element(state)
109
+ if not element_name:
110
+ print(json.dumps({"decision": "allow"}))
111
+ return
112
+
113
+ # Allow writing types/schema files (Phase 6)
114
+ if is_types_file(file_path, element_name):
115
+ print(json.dumps({"decision": "allow"}))
116
+ return
117
+
118
+ # Allow writing test files (Phase 8)
119
+ if is_test_file(file_path):
120
+ print(json.dumps({"decision": "allow"}))
121
+ return
122
+
123
+ # Check if writing page implementation file
124
+ if is_page_file(file_path, element_name):
125
+ # Verify data schema phase is complete
126
+ if not check_data_schema_phase(state, element_name):
127
+ print(json.dumps({
128
+ "decision": "block",
129
+ "reason": f"""
130
+ DATA SCHEMA REQUIRED (Phase 6)
131
+
132
+ You are trying to implement page code, but the data schema phase is not complete.
133
+
134
+ Before writing page implementation:
135
+ 1. Define TypeScript interfaces for API responses
136
+ 2. Create types in src/app/{element_name}/_types/index.ts
137
+ 3. Update state: phases.data_schema.status = "complete"
138
+
139
+ Page implementation requires knowing the data structure first.
140
+ """
141
+ }))
142
+ return
143
+
144
+ # Allow everything else
145
+ print(json.dumps({"decision": "allow"}))
146
+
147
+ except Exception as e:
148
+ # On error, allow to avoid blocking workflow
149
+ print(json.dumps({
150
+ "decision": "allow",
151
+ "error": str(e)
152
+ }))
153
+
154
+ if __name__ == "__main__":
155
+ main()