oneie 3.6.26 → 3.6.28
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-clone.md +2 -0
- package/.claude/agents/agent-frontend.md +162 -21
- package/.claude/agents/agent-writer.md +722 -0
- 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 +79 -90
- package/.claude/commands/optimize.md +74 -0
- package/.claude/commands/plan.md +420 -373
- package/.claude/commands/review.md +99 -0
- package/.claude/commands/server.md +97 -48
- package/.claude/commands/start.md +182 -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/.claude/hooks/write-news.sh +194 -0
- package/CLAUDE.md +150 -1057
- 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/one/things/plans/video-backend.md +638 -0
- package/one/things/plans/video-frontend.md +432 -0
- package/one/things/plans/video-old-archived.md +656 -0
- package/package.json +1 -1
- package/.claude/agents/AUDIT-agent-ops-alignment.md +0 -379
|
@@ -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())
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Ontology Validation Hook for ONE Platform
|
|
4
|
+
|
|
5
|
+
Validates that code changes adhere to the 6-dimension ontology:
|
|
6
|
+
1. groups - Multi-tenant isolation with hierarchical nesting
|
|
7
|
+
2. people - Authorization & governance (represented as things with role)
|
|
8
|
+
3. things - All entities (66+ types)
|
|
9
|
+
4. connections - All relationships (25+ types)
|
|
10
|
+
5. events - All actions and state changes (67+ types)
|
|
11
|
+
6. knowledge - Labels, embeddings, semantic search
|
|
12
|
+
|
|
13
|
+
Runs after Edit/Write operations to ensure ontology compliance.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import os
|
|
17
|
+
import sys
|
|
18
|
+
import re
|
|
19
|
+
import json
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
# ANSI color codes
|
|
23
|
+
GREEN = '\033[92m'
|
|
24
|
+
YELLOW = '\033[93m'
|
|
25
|
+
RED = '\033[91m'
|
|
26
|
+
BLUE = '\033[94m'
|
|
27
|
+
RESET = '\033[0m'
|
|
28
|
+
|
|
29
|
+
# Valid dimension tables (5 tables for 6 dimensions)
|
|
30
|
+
VALID_TABLES = ['groups', 'things', 'connections', 'events', 'knowledge']
|
|
31
|
+
|
|
32
|
+
# Regex patterns for validation
|
|
33
|
+
PATTERNS = {
|
|
34
|
+
'db_insert': r'ctx\.db\.insert\(["\'](\w+)["\']',
|
|
35
|
+
'db_query': r'ctx\.db\.query\(["\'](\w+)["\']',
|
|
36
|
+
'group_id': r'groupId\s*:\s*',
|
|
37
|
+
'thing_type': r'type\s*:\s*["\'](\w+)["\']',
|
|
38
|
+
'connection_type': r'type\s*:\s*["\'](\w+)["\']',
|
|
39
|
+
'event_type': r'type\s*:\s*["\'](\w+)["\']',
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
def validate_file(file_path: str) -> dict:
|
|
43
|
+
"""Validate a single file for ontology compliance."""
|
|
44
|
+
|
|
45
|
+
if not os.path.exists(file_path):
|
|
46
|
+
return {'status': 'skip', 'reason': 'File does not exist'}
|
|
47
|
+
|
|
48
|
+
# Only validate TypeScript files in backend/convex
|
|
49
|
+
if not file_path.endswith(('.ts', '.tsx')) or 'backend/convex' not in file_path:
|
|
50
|
+
return {'status': 'skip', 'reason': 'Not a backend TypeScript file'}
|
|
51
|
+
|
|
52
|
+
# Skip generated files
|
|
53
|
+
if '_generated' in file_path:
|
|
54
|
+
return {'status': 'skip', 'reason': 'Generated file'}
|
|
55
|
+
|
|
56
|
+
with open(file_path, 'r', encoding='utf-8') as f:
|
|
57
|
+
content = f.read()
|
|
58
|
+
|
|
59
|
+
issues = []
|
|
60
|
+
warnings = []
|
|
61
|
+
|
|
62
|
+
# Check 1: Validate table names in db.insert and db.query
|
|
63
|
+
for match in re.finditer(PATTERNS['db_insert'], content):
|
|
64
|
+
table = match.group(1)
|
|
65
|
+
if table not in VALID_TABLES:
|
|
66
|
+
issues.append(f"Invalid table '{table}' in db.insert() - must be one of {VALID_TABLES}")
|
|
67
|
+
|
|
68
|
+
for match in re.finditer(PATTERNS['db_query'], content):
|
|
69
|
+
table = match.group(1)
|
|
70
|
+
if table not in VALID_TABLES:
|
|
71
|
+
issues.append(f"Invalid table '{table}' in db.query() - must be one of {VALID_TABLES}")
|
|
72
|
+
|
|
73
|
+
# Check 2: Ensure things/connections/events/knowledge have groupId
|
|
74
|
+
for table in ['things', 'connections', 'events', 'knowledge']:
|
|
75
|
+
if f'db.insert("{table}"' in content or f"db.insert('{table}'" in content:
|
|
76
|
+
# Look for groupId in the same logical block (rough heuristic)
|
|
77
|
+
insert_matches = list(re.finditer(rf'db\.insert\(["\']({table})["\']', content))
|
|
78
|
+
for insert_match in insert_matches:
|
|
79
|
+
# Check if groupId appears within next 500 chars
|
|
80
|
+
context = content[insert_match.start():insert_match.start() + 500]
|
|
81
|
+
if 'groupId' not in context:
|
|
82
|
+
warnings.append(f"db.insert('{table}') may be missing groupId for multi-tenant scoping")
|
|
83
|
+
|
|
84
|
+
# Check 3: Validate common entity types (basic check)
|
|
85
|
+
common_types = [
|
|
86
|
+
'user', 'agent', 'ai_clone', 'content', 'course', 'token',
|
|
87
|
+
'creator', 'fan', 'product', 'service', 'organization'
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
# Check 4: Look for people dimension (role-based access)
|
|
91
|
+
if 'things' in content and 'type:' in content:
|
|
92
|
+
if 'role' in content and 'platform_owner' not in content and 'org_owner' not in content:
|
|
93
|
+
# Has role but not using standard role types
|
|
94
|
+
warnings.append("Found 'role' field but no standard role types (platform_owner, org_owner, org_user, customer)")
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
'status': 'validated',
|
|
98
|
+
'issues': issues,
|
|
99
|
+
'warnings': warnings
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
def main():
|
|
103
|
+
"""Main hook entry point."""
|
|
104
|
+
|
|
105
|
+
# Get file path from environment or command line
|
|
106
|
+
file_path = os.environ.get('CLAUDE_EDIT_FILE') or (sys.argv[1] if len(sys.argv) > 1 else None)
|
|
107
|
+
|
|
108
|
+
if not file_path:
|
|
109
|
+
print(f"{YELLOW}⚠ Ontology Validation: No file path provided{RESET}")
|
|
110
|
+
return 0
|
|
111
|
+
|
|
112
|
+
result = validate_file(file_path)
|
|
113
|
+
|
|
114
|
+
if result['status'] == 'skip':
|
|
115
|
+
return 0
|
|
116
|
+
|
|
117
|
+
# Print results
|
|
118
|
+
file_name = os.path.basename(file_path)
|
|
119
|
+
|
|
120
|
+
if result['issues']:
|
|
121
|
+
print(f"\n{RED}✗ Ontology Validation Failed: {file_name}{RESET}")
|
|
122
|
+
for issue in result['issues']:
|
|
123
|
+
print(f" {RED}ERROR:{RESET} {issue}")
|
|
124
|
+
if result['warnings']:
|
|
125
|
+
print(f"\n{YELLOW}Warnings:{RESET}")
|
|
126
|
+
for warning in result['warnings']:
|
|
127
|
+
print(f" {YELLOW}⚠{RESET} {warning}")
|
|
128
|
+
return 1
|
|
129
|
+
|
|
130
|
+
if result['warnings']:
|
|
131
|
+
print(f"\n{YELLOW}⚠ Ontology Validation Warnings: {file_name}{RESET}")
|
|
132
|
+
for warning in result['warnings']:
|
|
133
|
+
print(f" {YELLOW}⚠{RESET} {warning}")
|
|
134
|
+
return 0
|
|
135
|
+
|
|
136
|
+
print(f"{GREEN}✓ Ontology Validation: {file_name} complies with 6-dimension model{RESET}")
|
|
137
|
+
return 0
|
|
138
|
+
|
|
139
|
+
if __name__ == '__main__':
|
|
140
|
+
sys.exit(main())
|