oneie 3.6.26 → 3.6.27
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.
- package/.claude/agents/TROUBLESHOOTING.md +530 -0
- package/.claude/agents/agent-claude.md +645 -0
- package/.claude/agents/agent-frontend.md +162 -21
- package/.claude/commands/chat.md +504 -0
- package/.claude/commands/create.md +134 -18
- package/.claude/commands/fast.md +531 -0
- package/.claude/commands/one.md +12 -85
- package/.claude/commands/optimize.md +74 -0
- package/.claude/commands/plan.md +420 -373
- package/.claude/commands/review.md +99 -0
- package/.claude/commands/test.md +197 -0
- package/.claude/commands/validate.md +140 -0
- package/.claude/hooks/__pycache__/todo.cpython-312.pyc +0 -0
- package/.claude/hooks/auto-format.sh +106 -0
- package/.claude/hooks/formatting.py +187 -0
- package/.claude/hooks/ontology-validation.py +255 -0
- package/.claude/hooks/validate-imports.py +182 -0
- package/.claude/hooks/validate-ontology.py +140 -0
- package/one/knowledge/cascading-context-specification.md +1617 -0
- package/one/knowledge/claude-code-integration.md +1293 -0
- package/one/knowledge/development-commands.md +251 -0
- package/one/knowledge/guidelines.md +314 -0
- package/one/knowledge/parallel-agents.md +932 -0
- package/one/knowledge/performance.md +459 -0
- package/one/knowledge/troubleshooting.md +434 -0
- package/one/things/plans/dsl-claude-code.md +1011 -0
- package/package.json +1 -1
- package/.claude/agents/AUDIT-agent-ops-alignment.md +0 -379
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Formatting Hook - ONE Platform
|
|
4
|
+
PostToolUse hook that auto-formats TypeScript, Astro, and React files
|
|
5
|
+
|
|
6
|
+
Triggered after: Edit, Write tools
|
|
7
|
+
Formats: .ts, .tsx, .astro files using prettier
|
|
8
|
+
Also formats: .json, .css files
|
|
9
|
+
|
|
10
|
+
Uses prettier with ONE Platform configuration:
|
|
11
|
+
- Tailwind v4 CSS formatting
|
|
12
|
+
- TypeScript strict mode
|
|
13
|
+
- React 19 JSX
|
|
14
|
+
- Astro 5 syntax
|
|
15
|
+
|
|
16
|
+
Exit Codes:
|
|
17
|
+
0 - Formatting completed successfully or not needed
|
|
18
|
+
1 - Formatting failed (should not block workflow)
|
|
19
|
+
"""
|
|
20
|
+
import json
|
|
21
|
+
import sys
|
|
22
|
+
import os
|
|
23
|
+
import subprocess
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
|
|
26
|
+
# File extensions to format
|
|
27
|
+
FORMATTABLE_EXTENSIONS = {
|
|
28
|
+
'.ts', '.tsx', '.astro', '.json', '.css', '.js', '.jsx', '.md'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# Files to skip (generated or config)
|
|
32
|
+
SKIP_PATTERNS = [
|
|
33
|
+
'_generated',
|
|
34
|
+
'node_modules',
|
|
35
|
+
'.next',
|
|
36
|
+
'dist',
|
|
37
|
+
'build',
|
|
38
|
+
'.astro',
|
|
39
|
+
'package-lock.json',
|
|
40
|
+
'bun.lockb'
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
def should_format(file_path: str) -> bool:
|
|
44
|
+
"""Check if file should be formatted"""
|
|
45
|
+
# Check extension
|
|
46
|
+
ext = Path(file_path).suffix
|
|
47
|
+
if ext not in FORMATTABLE_EXTENSIONS:
|
|
48
|
+
return False
|
|
49
|
+
|
|
50
|
+
# Skip generated files and dependencies
|
|
51
|
+
for pattern in SKIP_PATTERNS:
|
|
52
|
+
if pattern in file_path:
|
|
53
|
+
return False
|
|
54
|
+
|
|
55
|
+
return True
|
|
56
|
+
|
|
57
|
+
def format_file(file_path: str) -> tuple[bool, str]:
|
|
58
|
+
"""
|
|
59
|
+
Format file using prettier
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
(success, message)
|
|
63
|
+
"""
|
|
64
|
+
if not os.path.exists(file_path):
|
|
65
|
+
return True, "File does not exist (may have been deleted)"
|
|
66
|
+
|
|
67
|
+
try:
|
|
68
|
+
# Determine parser based on extension
|
|
69
|
+
ext = Path(file_path).suffix
|
|
70
|
+
parser_map = {
|
|
71
|
+
'.ts': 'typescript',
|
|
72
|
+
'.tsx': 'typescript',
|
|
73
|
+
'.astro': 'astro',
|
|
74
|
+
'.json': 'json',
|
|
75
|
+
'.css': 'css',
|
|
76
|
+
'.js': 'babel',
|
|
77
|
+
'.jsx': 'babel',
|
|
78
|
+
'.md': 'markdown'
|
|
79
|
+
}
|
|
80
|
+
parser = parser_map.get(ext, 'typescript')
|
|
81
|
+
|
|
82
|
+
# Run prettier
|
|
83
|
+
result = subprocess.run(
|
|
84
|
+
['prettier', '--write', '--parser', parser, file_path],
|
|
85
|
+
capture_output=True,
|
|
86
|
+
text=True,
|
|
87
|
+
timeout=10
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
if result.returncode == 0:
|
|
91
|
+
return True, f"✅ Formatted: {file_path}"
|
|
92
|
+
else:
|
|
93
|
+
# Prettier errors are warnings, not failures
|
|
94
|
+
return True, f"⚠️ Prettier warning: {result.stderr.strip()}"
|
|
95
|
+
|
|
96
|
+
except FileNotFoundError:
|
|
97
|
+
# Prettier not installed - not a blocker
|
|
98
|
+
return True, "⚠️ Prettier not installed (npm install -g prettier)"
|
|
99
|
+
except subprocess.TimeoutExpired:
|
|
100
|
+
return True, f"⚠️ Formatting timeout: {file_path}"
|
|
101
|
+
except Exception as e:
|
|
102
|
+
return True, f"⚠️ Formatting error: {str(e)}"
|
|
103
|
+
|
|
104
|
+
def check_imports(file_path: str) -> tuple[bool, list[str]]:
|
|
105
|
+
"""
|
|
106
|
+
Check import organization and suggest improvements
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
(is_organized, suggestions)
|
|
110
|
+
"""
|
|
111
|
+
suggestions = []
|
|
112
|
+
|
|
113
|
+
try:
|
|
114
|
+
with open(file_path, 'r') as f:
|
|
115
|
+
content = f.read()
|
|
116
|
+
|
|
117
|
+
# Check for React 19 edge imports
|
|
118
|
+
if 'react-dom/server' in content and 'react-dom/server.edge' not in content:
|
|
119
|
+
if file_path.endswith('.astro') or 'ssr' in content.lower():
|
|
120
|
+
suggestions.append("💡 Use 'react-dom/server.edge' for Cloudflare Pages SSR")
|
|
121
|
+
|
|
122
|
+
# Check for proper path aliases
|
|
123
|
+
if '../' * 3 in content: # More than 2 levels up
|
|
124
|
+
suggestions.append("💡 Use path alias '@/' instead of '../../../'")
|
|
125
|
+
|
|
126
|
+
# Check for Convex direct imports in frontend components
|
|
127
|
+
if 'web/src/components' in file_path:
|
|
128
|
+
if 'from "convex"' in content or "from 'convex'" in content:
|
|
129
|
+
suggestions.append("💡 Import Convex hooks from '@/services' layer, not directly")
|
|
130
|
+
|
|
131
|
+
# Check for missing nanostores in frontend-only apps
|
|
132
|
+
if 'web/src/' in file_path and 'useState' in content:
|
|
133
|
+
if 'nanostores' not in content and 'convex' not in content:
|
|
134
|
+
suggestions.append("💡 Consider using nanostores for persistent state (frontend-only)")
|
|
135
|
+
|
|
136
|
+
except Exception:
|
|
137
|
+
pass
|
|
138
|
+
|
|
139
|
+
return len(suggestions) == 0, suggestions
|
|
140
|
+
|
|
141
|
+
def main():
|
|
142
|
+
"""Main hook entry point"""
|
|
143
|
+
try:
|
|
144
|
+
# Read hook event from stdin
|
|
145
|
+
hook_event = json.loads(sys.stdin.read())
|
|
146
|
+
|
|
147
|
+
# Extract file path
|
|
148
|
+
tool_name = hook_event.get("tool_name", "")
|
|
149
|
+
tool_input = hook_event.get("tool_input", {})
|
|
150
|
+
|
|
151
|
+
# Only run on Edit and Write operations
|
|
152
|
+
if tool_name not in ["Edit", "Write"]:
|
|
153
|
+
sys.exit(0)
|
|
154
|
+
|
|
155
|
+
file_path = tool_input.get("file_path", "")
|
|
156
|
+
|
|
157
|
+
# Check if we should format this file
|
|
158
|
+
if not should_format(file_path):
|
|
159
|
+
sys.exit(0)
|
|
160
|
+
|
|
161
|
+
# Format the file
|
|
162
|
+
success, message = format_file(file_path)
|
|
163
|
+
|
|
164
|
+
# Check imports and organization
|
|
165
|
+
is_organized, suggestions = check_imports(file_path)
|
|
166
|
+
|
|
167
|
+
# Print results
|
|
168
|
+
if not success:
|
|
169
|
+
print(message)
|
|
170
|
+
elif suggestions:
|
|
171
|
+
print(f"✅ Formatted: {file_path}")
|
|
172
|
+
print("")
|
|
173
|
+
print("💡 Import Suggestions:")
|
|
174
|
+
for suggestion in suggestions:
|
|
175
|
+
print(f" {suggestion}")
|
|
176
|
+
print("")
|
|
177
|
+
|
|
178
|
+
# Always exit 0 (formatting issues are warnings, not blockers)
|
|
179
|
+
sys.exit(0)
|
|
180
|
+
|
|
181
|
+
except Exception as e:
|
|
182
|
+
# Don't fail the workflow on hook errors
|
|
183
|
+
print(f"⚠️ Formatting hook error: {str(e)}", file=sys.stderr)
|
|
184
|
+
sys.exit(0)
|
|
185
|
+
|
|
186
|
+
if __name__ == "__main__":
|
|
187
|
+
main()
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Ontology Validation Hook - ONE Platform
|
|
4
|
+
PostToolUse hook that validates all code changes map to the 6-dimension ontology
|
|
5
|
+
|
|
6
|
+
Triggered after: Edit, Write tools
|
|
7
|
+
Validates: Entity types, connection types, event types, metadata structures
|
|
8
|
+
|
|
9
|
+
The 6-Dimension Ontology:
|
|
10
|
+
1. groups - Multi-tenant isolation (groupId in all tables)
|
|
11
|
+
2. people - Authorization (represented as things with type: 'creator')
|
|
12
|
+
3. things - All entities (66 types)
|
|
13
|
+
4. connections - All relationships (25 types)
|
|
14
|
+
5. events - All actions (67 types)
|
|
15
|
+
6. knowledge - RAG and embeddings
|
|
16
|
+
|
|
17
|
+
Exit Codes:
|
|
18
|
+
0 - Validation passed or file not relevant to ontology
|
|
19
|
+
1 - Validation failed (ontology violation detected)
|
|
20
|
+
"""
|
|
21
|
+
import json
|
|
22
|
+
import sys
|
|
23
|
+
import os
|
|
24
|
+
import re
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
|
|
27
|
+
# Valid entity types (66 types from ontology)
|
|
28
|
+
VALID_THING_TYPES = {
|
|
29
|
+
# Core (People as Things)
|
|
30
|
+
"creator", "ai_clone", "audience_member", "organization",
|
|
31
|
+
# Business Agents
|
|
32
|
+
"strategy_agent", "research_agent", "marketing_agent", "sales_agent",
|
|
33
|
+
"service_agent", "design_agent", "engineering_agent", "finance_agent",
|
|
34
|
+
"legal_agent", "intelligence_agent",
|
|
35
|
+
# Content
|
|
36
|
+
"blog_post", "video", "podcast", "social_post", "email", "course", "lesson",
|
|
37
|
+
# Products
|
|
38
|
+
"digital_product", "membership", "consultation", "nft",
|
|
39
|
+
# Community
|
|
40
|
+
"community", "conversation", "message",
|
|
41
|
+
# Token
|
|
42
|
+
"token", "token_contract",
|
|
43
|
+
# Knowledge
|
|
44
|
+
"knowledge_item", "embedding",
|
|
45
|
+
# Platform
|
|
46
|
+
"website", "landing_page", "template", "livestream", "recording", "media_asset",
|
|
47
|
+
# Business
|
|
48
|
+
"payment", "subscription", "invoice", "metric", "insight", "prediction", "report",
|
|
49
|
+
# Auth Session
|
|
50
|
+
"session", "oauth_account", "verification_token", "password_reset_token",
|
|
51
|
+
# UI Preferences
|
|
52
|
+
"ui_preferences",
|
|
53
|
+
# Marketing
|
|
54
|
+
"notification", "email_campaign", "announcement", "referral", "campaign", "lead",
|
|
55
|
+
# External
|
|
56
|
+
"external_agent", "external_workflow", "external_connection",
|
|
57
|
+
# Protocol
|
|
58
|
+
"mandate", "product",
|
|
59
|
+
# Workflow
|
|
60
|
+
"idea", "plan", "feature", "test", "design", "task", "lesson"
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# Valid connection types (25 types from ontology)
|
|
64
|
+
VALID_CONNECTION_TYPES = {
|
|
65
|
+
# Ownership
|
|
66
|
+
"owns", "created_by",
|
|
67
|
+
# AI Relationships
|
|
68
|
+
"clone_of", "trained_on", "powers",
|
|
69
|
+
# Content Relationships
|
|
70
|
+
"authored", "generated_by", "published_to", "part_of", "references",
|
|
71
|
+
# Community Relationships
|
|
72
|
+
"member_of", "following", "moderates", "participated_in",
|
|
73
|
+
# Product Relationships
|
|
74
|
+
"holds_tokens", "enrolled_in", "purchased", "subscribed_to",
|
|
75
|
+
# Learning Relationships
|
|
76
|
+
"completed", "taught_by", "mentored_by"
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
# Valid event types (67 types from ontology)
|
|
80
|
+
VALID_EVENT_TYPES = {
|
|
81
|
+
# Thing Events
|
|
82
|
+
"thing_created", "thing_updated", "thing_deleted", "thing_published", "thing_archived",
|
|
83
|
+
# Connection Events
|
|
84
|
+
"connection_created", "connection_updated", "connection_deleted",
|
|
85
|
+
# Knowledge Events
|
|
86
|
+
"knowledge_created", "knowledge_updated", "knowledge_deleted", "knowledge_embedded",
|
|
87
|
+
# Content Events
|
|
88
|
+
"content_published", "content_viewed", "content_liked", "content_commented",
|
|
89
|
+
# Community Events
|
|
90
|
+
"user_joined", "user_invited", "message_sent", "conversation_started",
|
|
91
|
+
# Token Events
|
|
92
|
+
"tokens_minted", "tokens_burned", "tokens_transferred", "tokens_purchased",
|
|
93
|
+
# Commerce Events
|
|
94
|
+
"payment_initiated", "payment_completed", "payment_failed", "subscription_created",
|
|
95
|
+
"subscription_renewed", "subscription_cancelled", "purchase_completed",
|
|
96
|
+
# Learning Events
|
|
97
|
+
"lesson_started", "lesson_completed", "course_enrolled", "course_completed",
|
|
98
|
+
# AI Events
|
|
99
|
+
"clone_interacted", "ai_generated", "embedding_created",
|
|
100
|
+
# Task Events
|
|
101
|
+
"task_created", "task_started", "task_completed", "task_failed",
|
|
102
|
+
# Agent Events
|
|
103
|
+
"agent_started", "agent_completed", "agent_failed", "agent_executed",
|
|
104
|
+
# Cycle Events
|
|
105
|
+
"cycle_started", "cycle_completed", "cycle_validated", "cycle_skipped",
|
|
106
|
+
# Blockchain Events (consolidated with metadata.protocol)
|
|
107
|
+
"transaction_sent", "transaction_confirmed", "transaction_failed",
|
|
108
|
+
"block_created", "contract_deployed", "contract_called",
|
|
109
|
+
"token_minted", "token_burned", "token_transferred",
|
|
110
|
+
"proposal_created", "proposal_voted", "proposal_executed",
|
|
111
|
+
"delegation_created", "delegation_revoked",
|
|
112
|
+
# System Events
|
|
113
|
+
"hook_executed", "insight_generated", "prediction_made", "metric_calculated"
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
# Required metadata fields for each table
|
|
117
|
+
REQUIRED_METADATA = {
|
|
118
|
+
"groups": ["name", "type", "status"],
|
|
119
|
+
"things": ["groupId", "type", "name", "status"],
|
|
120
|
+
"connections": ["groupId", "type", "fromThingId", "toThingId"],
|
|
121
|
+
"events": ["groupId", "type", "timestamp"],
|
|
122
|
+
"knowledge": ["groupId", "content", "labels"]
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
def validate_file(file_path: str, content: str) -> tuple[bool, list[str]]:
|
|
126
|
+
"""
|
|
127
|
+
Validate file for ontology compliance
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
(is_valid, issues) - True if valid, False if violations found
|
|
131
|
+
"""
|
|
132
|
+
issues = []
|
|
133
|
+
|
|
134
|
+
# Only validate backend TypeScript files and schema files
|
|
135
|
+
if not (file_path.endswith('.ts') and ('backend/convex' in file_path or 'web/src/services' in file_path)):
|
|
136
|
+
return True, []
|
|
137
|
+
|
|
138
|
+
# Skip generated files
|
|
139
|
+
if '_generated' in file_path or '.test.' in file_path:
|
|
140
|
+
return True, []
|
|
141
|
+
|
|
142
|
+
# Check for invalid thing types
|
|
143
|
+
thing_type_pattern = r'''type:\s*["']([^"']+)["']'''
|
|
144
|
+
for match in re.finditer(thing_type_pattern, content):
|
|
145
|
+
thing_type = match.group(1)
|
|
146
|
+
if thing_type not in VALID_THING_TYPES:
|
|
147
|
+
issues.append(f"❌ Invalid thing type: '{thing_type}' (line {content[:match.start()].count(chr(10)) + 1})")
|
|
148
|
+
issues.append(f" Valid types: {', '.join(sorted(VALID_THING_TYPES))}")
|
|
149
|
+
|
|
150
|
+
# Check for invalid connection types
|
|
151
|
+
if 'connections' in file_path or 'connection' in content.lower():
|
|
152
|
+
conn_type_pattern = r'''(?:connectionType|type):\s*["']([^"']+)["']'''
|
|
153
|
+
for match in re.finditer(conn_type_pattern, content):
|
|
154
|
+
conn_type = match.group(1)
|
|
155
|
+
# Only validate if it looks like a connection type (snake_case with specific patterns)
|
|
156
|
+
if '_' in conn_type and conn_type not in VALID_CONNECTION_TYPES:
|
|
157
|
+
if any(conn_type.startswith(prefix) for prefix in ['owns', 'created', 'member', 'following', 'holds', 'enrolled', 'purchased']):
|
|
158
|
+
issues.append(f"❌ Invalid connection type: '{conn_type}' (line {content[:match.start()].count(chr(10)) + 1})")
|
|
159
|
+
issues.append(f" Valid types: {', '.join(sorted(VALID_CONNECTION_TYPES))}")
|
|
160
|
+
|
|
161
|
+
# Check for invalid event types
|
|
162
|
+
if 'events' in file_path or 'event' in content.lower():
|
|
163
|
+
event_type_pattern = r'''(?:eventType|type):\s*["']([^"']+)["']'''
|
|
164
|
+
for match in re.finditer(event_type_pattern, content):
|
|
165
|
+
event_type = match.group(1)
|
|
166
|
+
# Only validate if it looks like an event type (snake_case with specific patterns)
|
|
167
|
+
if '_' in event_type and event_type not in VALID_EVENT_TYPES:
|
|
168
|
+
if any(event_type.endswith(suffix) for suffix in ['_created', '_updated', '_deleted', '_completed', '_failed', '_started']):
|
|
169
|
+
issues.append(f"❌ Invalid event type: '{event_type}' (line {content[:match.start()].count(chr(10)) + 1})")
|
|
170
|
+
issues.append(f" Valid types: {', '.join(sorted(VALID_EVENT_TYPES))}")
|
|
171
|
+
|
|
172
|
+
# Check for missing groupId in database operations
|
|
173
|
+
if 'ctx.db.insert' in content or 'ctx.db.query' in content:
|
|
174
|
+
# Check for things table operations
|
|
175
|
+
if re.search(r'ctx\.db\.insert\(["\']things["\']', content):
|
|
176
|
+
if 'groupId' not in content:
|
|
177
|
+
issues.append(f"⚠️ Things table insert missing 'groupId' (multi-tenant isolation required)")
|
|
178
|
+
|
|
179
|
+
# Check for connections table operations
|
|
180
|
+
if re.search(r'ctx\.db\.insert\(["\']connections["\']', content):
|
|
181
|
+
if 'groupId' not in content:
|
|
182
|
+
issues.append(f"⚠️ Connections table insert missing 'groupId' (multi-tenant isolation required)")
|
|
183
|
+
|
|
184
|
+
# Check for events table operations
|
|
185
|
+
if re.search(r'ctx\.db\.insert\(["\']events["\']', content):
|
|
186
|
+
if 'groupId' not in content:
|
|
187
|
+
issues.append(f"⚠️ Events table insert missing 'groupId' (multi-tenant isolation required)")
|
|
188
|
+
|
|
189
|
+
# Check for knowledge table operations
|
|
190
|
+
if re.search(r'ctx\.db\.insert\(["\']knowledge["\']', content):
|
|
191
|
+
if 'groupId' not in content:
|
|
192
|
+
issues.append(f"⚠️ Knowledge table insert missing 'groupId' (multi-tenant isolation required)")
|
|
193
|
+
|
|
194
|
+
# Check for frontend-only violations (backend code when not requested)
|
|
195
|
+
if file_path.startswith('web/src/'):
|
|
196
|
+
# Check for Convex imports in components (should use services layer)
|
|
197
|
+
if re.search(r'''from\s+["']convex/["']''', content) or re.search(r'''from\s+["']@/convex/["']''', content):
|
|
198
|
+
if 'src/services' not in file_path and 'src/providers' not in file_path:
|
|
199
|
+
issues.append(f"⚠️ Direct Convex import in component (use services layer)")
|
|
200
|
+
issues.append(f" Import from '@/services' instead of 'convex'")
|
|
201
|
+
|
|
202
|
+
return len(issues) == 0, issues
|
|
203
|
+
|
|
204
|
+
def main():
|
|
205
|
+
"""Main hook entry point"""
|
|
206
|
+
try:
|
|
207
|
+
# Read hook event from stdin
|
|
208
|
+
hook_event = json.loads(sys.stdin.read())
|
|
209
|
+
|
|
210
|
+
# Extract file path and content
|
|
211
|
+
tool_name = hook_event.get("tool_name", "")
|
|
212
|
+
tool_input = hook_event.get("tool_input", {})
|
|
213
|
+
|
|
214
|
+
# Only run on Edit and Write operations
|
|
215
|
+
if tool_name not in ["Edit", "Write"]:
|
|
216
|
+
sys.exit(0)
|
|
217
|
+
|
|
218
|
+
file_path = tool_input.get("file_path", "")
|
|
219
|
+
|
|
220
|
+
# Get content (different for Edit vs Write)
|
|
221
|
+
if tool_name == "Write":
|
|
222
|
+
content = tool_input.get("content", "")
|
|
223
|
+
else: # Edit
|
|
224
|
+
# For Edit, we need to read the file (it's already been modified)
|
|
225
|
+
try:
|
|
226
|
+
with open(file_path, 'r') as f:
|
|
227
|
+
content = f.read()
|
|
228
|
+
except Exception:
|
|
229
|
+
# If file doesn't exist or can't be read, skip validation
|
|
230
|
+
sys.exit(0)
|
|
231
|
+
|
|
232
|
+
# Validate file
|
|
233
|
+
is_valid, issues = validate_file(file_path, content)
|
|
234
|
+
|
|
235
|
+
if not is_valid:
|
|
236
|
+
print(f"⚠️ Ontology Validation Failed: {file_path}")
|
|
237
|
+
print("")
|
|
238
|
+
for issue in issues:
|
|
239
|
+
print(issue)
|
|
240
|
+
print("")
|
|
241
|
+
print("📖 Reference: /one/knowledge/ontology.md")
|
|
242
|
+
print("🔧 Fix: Use correct ontology types from the 6-dimension specification")
|
|
243
|
+
print("")
|
|
244
|
+
sys.exit(1)
|
|
245
|
+
|
|
246
|
+
# Success (silent for valid files)
|
|
247
|
+
sys.exit(0)
|
|
248
|
+
|
|
249
|
+
except Exception as e:
|
|
250
|
+
# Don't fail the workflow on hook errors
|
|
251
|
+
print(f"⚠️ Ontology validation hook error: {str(e)}", file=sys.stderr)
|
|
252
|
+
sys.exit(0)
|
|
253
|
+
|
|
254
|
+
if __name__ == "__main__":
|
|
255
|
+
main()
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Import Validation Hook for ONE Platform
|
|
4
|
+
|
|
5
|
+
Validates import statements to enforce architecture boundaries:
|
|
6
|
+
1. Frontend cannot import backend code directly (must use Convex client)
|
|
7
|
+
2. Backend cannot import frontend code
|
|
8
|
+
3. Services must follow proper layering
|
|
9
|
+
4. Circular dependencies detected
|
|
10
|
+
5. Convex imports use proper patterns
|
|
11
|
+
|
|
12
|
+
Runs after Edit/Write operations to catch architecture violations.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
import sys
|
|
17
|
+
import re
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import List, Tuple
|
|
20
|
+
|
|
21
|
+
# ANSI color codes
|
|
22
|
+
GREEN = '\033[92m'
|
|
23
|
+
YELLOW = '\033[93m'
|
|
24
|
+
RED = '\033[91m'
|
|
25
|
+
BLUE = '\033[94m'
|
|
26
|
+
RESET = '\033[0m'
|
|
27
|
+
|
|
28
|
+
# Import patterns
|
|
29
|
+
IMPORT_PATTERNS = [
|
|
30
|
+
r'import\s+.*?\s+from\s+["\']([^"\']+)["\']', # ES6 imports
|
|
31
|
+
r'require\(["\']([^"\']+)["\']\)', # CommonJS require
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
def extract_imports(content: str) -> List[str]:
|
|
35
|
+
"""Extract all import paths from file content."""
|
|
36
|
+
imports = []
|
|
37
|
+
for pattern in IMPORT_PATTERNS:
|
|
38
|
+
matches = re.finditer(pattern, content)
|
|
39
|
+
imports.extend([match.group(1) for match in matches])
|
|
40
|
+
return imports
|
|
41
|
+
|
|
42
|
+
def validate_imports(file_path: str, content: str) -> Tuple[List[str], List[str]]:
|
|
43
|
+
"""Validate imports for architecture compliance."""
|
|
44
|
+
|
|
45
|
+
issues = []
|
|
46
|
+
warnings = []
|
|
47
|
+
imports = extract_imports(content)
|
|
48
|
+
|
|
49
|
+
# Determine file location
|
|
50
|
+
is_frontend = '/web/src/' in file_path or '/apps/' in file_path
|
|
51
|
+
is_backend = '/backend/convex/' in file_path
|
|
52
|
+
is_web_convex = '/web/convex/' in file_path # Legacy location
|
|
53
|
+
|
|
54
|
+
for imp in imports:
|
|
55
|
+
# Rule 1: Frontend cannot import backend directly
|
|
56
|
+
if is_frontend and not is_web_convex:
|
|
57
|
+
# Check for direct backend imports (not through Convex client)
|
|
58
|
+
if '../backend/' in imp or 'backend/convex' in imp:
|
|
59
|
+
if not imp.endswith('/_generated/api'):
|
|
60
|
+
issues.append(
|
|
61
|
+
f"Frontend importing backend code directly: '{imp}'\n"
|
|
62
|
+
f" Use Convex client (useQuery/useMutation) instead"
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
# Check for server-only imports in client code
|
|
66
|
+
if imp.startswith('convex/server'):
|
|
67
|
+
issues.append(
|
|
68
|
+
f"Frontend importing server-only code: '{imp}'\n"
|
|
69
|
+
f" Use 'convex/react' or 'convex/browser' instead"
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
# Rule 2: Backend cannot import frontend code
|
|
73
|
+
if is_backend or is_web_convex:
|
|
74
|
+
if '/web/src/components' in imp or '/web/src/pages' in imp:
|
|
75
|
+
issues.append(
|
|
76
|
+
f"Backend importing frontend code: '{imp}'\n"
|
|
77
|
+
f" Backend must remain headless"
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
# Check for React imports in backend
|
|
81
|
+
if imp == 'react' or imp.startswith('react/'):
|
|
82
|
+
issues.append(
|
|
83
|
+
f"Backend importing React: '{imp}'\n"
|
|
84
|
+
f" Backend must be framework-agnostic"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
# Rule 3: Validate Convex import patterns
|
|
88
|
+
if is_backend or is_web_convex:
|
|
89
|
+
# Should use relative imports for local modules
|
|
90
|
+
if imp.startswith('convex/') and not imp.startswith('convex/values'):
|
|
91
|
+
if '_generated' not in imp:
|
|
92
|
+
warnings.append(
|
|
93
|
+
f"Using absolute 'convex/' import: '{imp}'\n"
|
|
94
|
+
f" Consider using relative imports for local modules"
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
# Validate generated imports
|
|
98
|
+
if '_generated' in imp:
|
|
99
|
+
if not (imp.endswith('/api') or imp.endswith('/server') or imp.endswith('/dataModel')):
|
|
100
|
+
warnings.append(
|
|
101
|
+
f"Unusual _generated import: '{imp}'\n"
|
|
102
|
+
f" Typically use /api, /server, or /dataModel"
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
# Rule 4: Check for circular dependency indicators
|
|
106
|
+
if '../' in imp:
|
|
107
|
+
# Count how many levels up
|
|
108
|
+
up_levels = imp.count('../')
|
|
109
|
+
if up_levels > 3:
|
|
110
|
+
warnings.append(
|
|
111
|
+
f"Deep relative import (../{up_levels} levels): '{imp}'\n"
|
|
112
|
+
f" May indicate architectural issues"
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
# Rule 5: Service layer validation
|
|
116
|
+
if '/services/' in file_path:
|
|
117
|
+
# Services should not import UI components
|
|
118
|
+
if '/components/' in imp or '/pages/' in imp:
|
|
119
|
+
issues.append(
|
|
120
|
+
f"Service importing UI code: '{imp}'\n"
|
|
121
|
+
f" Services must be UI-agnostic"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
# Services should use Effect.ts patterns
|
|
125
|
+
if is_backend and 'effect' not in content.lower():
|
|
126
|
+
warnings.append(
|
|
127
|
+
f"Service file without Effect.ts imports\n"
|
|
128
|
+
f" Consider using Effect.ts for services"
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
return issues, warnings
|
|
132
|
+
|
|
133
|
+
def main():
|
|
134
|
+
"""Main hook entry point."""
|
|
135
|
+
|
|
136
|
+
# Get file path from environment or command line
|
|
137
|
+
file_path = os.environ.get('CLAUDE_EDIT_FILE') or (sys.argv[1] if len(sys.argv) > 1 else None)
|
|
138
|
+
|
|
139
|
+
if not file_path:
|
|
140
|
+
print(f"{YELLOW}⚠ Import Validation: No file path provided{RESET}")
|
|
141
|
+
return 0
|
|
142
|
+
|
|
143
|
+
if not os.path.exists(file_path):
|
|
144
|
+
return 0
|
|
145
|
+
|
|
146
|
+
# Only validate TypeScript/JavaScript files
|
|
147
|
+
if not file_path.endswith(('.ts', '.tsx', '.js', '.jsx', '.mjs')):
|
|
148
|
+
return 0
|
|
149
|
+
|
|
150
|
+
# Skip node_modules, dist, generated files
|
|
151
|
+
if any(skip in file_path for skip in ['node_modules', 'dist', '_generated', '.next', '.git']):
|
|
152
|
+
return 0
|
|
153
|
+
|
|
154
|
+
with open(file_path, 'r', encoding='utf-8') as f:
|
|
155
|
+
content = f.read()
|
|
156
|
+
|
|
157
|
+
issues, warnings = validate_imports(file_path, content)
|
|
158
|
+
|
|
159
|
+
file_name = os.path.basename(file_path)
|
|
160
|
+
|
|
161
|
+
# Print results
|
|
162
|
+
if issues:
|
|
163
|
+
print(f"\n{RED}✗ Import Validation Failed: {file_name}{RESET}")
|
|
164
|
+
for issue in issues:
|
|
165
|
+
print(f" {RED}ERROR:{RESET} {issue}")
|
|
166
|
+
if warnings:
|
|
167
|
+
print(f"\n{YELLOW}Warnings:{RESET}")
|
|
168
|
+
for warning in warnings:
|
|
169
|
+
print(f" {YELLOW}⚠{RESET} {warning}")
|
|
170
|
+
return 1
|
|
171
|
+
|
|
172
|
+
if warnings:
|
|
173
|
+
print(f"\n{YELLOW}⚠ Import Validation Warnings: {file_name}{RESET}")
|
|
174
|
+
for warning in warnings:
|
|
175
|
+
print(f" {YELLOW}⚠{RESET} {warning}")
|
|
176
|
+
return 0
|
|
177
|
+
|
|
178
|
+
print(f"{GREEN}✓ Import Validation: {file_name} follows architecture boundaries{RESET}")
|
|
179
|
+
return 0
|
|
180
|
+
|
|
181
|
+
if __name__ == '__main__':
|
|
182
|
+
sys.exit(main())
|