oneie 3.6.23 → 3.6.25

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 (47) hide show
  1. package/.claude/agents/agent-backend.md +2 -2
  2. package/.claude/agents/agent-designer.md +1 -0
  3. package/.claude/agents/agent-director.md +71 -71
  4. package/.claude/agents/agent-onboard.md +1 -1
  5. package/.claude/agents/agent-ontology.md +2 -2
  6. package/.claude/agents/agent-ops.md +58 -38
  7. package/.claude/agents/agent-sales.md +3 -3
  8. package/.claude/commands/cascade.md +21 -21
  9. package/.claude/commands/create.md +19 -19
  10. package/.claude/commands/deploy.md +82 -104
  11. package/.claude/commands/mcp-on.md +191 -0
  12. package/.claude/commands/one.md +267 -92
  13. package/.claude/commands/plan.md +17 -17
  14. package/.claude/commands/release.md +65 -14
  15. package/.claude/hooks/PULL-BEFORE-PUSH-GUIDE.md +473 -0
  16. package/.claude/hooks/README-knowledge-hooks.md +451 -0
  17. package/.claude/hooks/README-root-cleanup.md +200 -0
  18. package/.claude/hooks/README.md +284 -0
  19. package/.claude/hooks/__pycache__/done.cpython-313.pyc +0 -0
  20. package/.claude/hooks/__pycache__/todo.cpython-313.pyc +0 -0
  21. package/.claude/hooks/check-filenames.py +177 -0
  22. package/.claude/hooks/clean-post.py +468 -0
  23. package/.claude/hooks/clean-pre.py +393 -0
  24. package/.claude/hooks/clean-root-markdown.sh +73 -0
  25. package/.claude/hooks/commit-push.sh +95 -0
  26. package/.claude/hooks/done.py +236 -0
  27. package/.claude/hooks/format-hook.sh +163 -0
  28. package/.claude/hooks/hook-logger.sh +173 -0
  29. package/.claude/hooks/knowledge-post.py +355 -0
  30. package/.claude/hooks/knowledge-pre.py +245 -0
  31. package/.claude/hooks/mcp-on.sh +134 -0
  32. package/.claude/hooks/notification-hook.sh +279 -0
  33. package/.claude/hooks/push.sh +101 -0
  34. package/.claude/hooks/release-cli.sh +16 -8
  35. package/.claude/hooks/root-cleanup.py +217 -0
  36. package/.claude/hooks/security-hook.sh +397 -0
  37. package/.claude/hooks/tag-all-docs.py +464 -0
  38. package/.claude/hooks/test-validate-ontology.sh +170 -0
  39. package/.claude/hooks/todo.py +368 -0
  40. package/.claude/hooks/track-changes.sh +101 -0
  41. package/.claude/hooks/validate-ontology-structure-summary.md +243 -0
  42. package/.claude/hooks/validate-ontology-structure.py +518 -0
  43. package/.claude/skills/INDEX.md +1 -1
  44. package/.claude/skills/ontology/README.md +1 -1
  45. package/package.json +1 -1
  46. package/.claude/commands/mcp-toggle.md +0 -93
  47. package/.claude/commands/npx.md +0 -84
@@ -0,0 +1,217 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Root Cleanup Hook - 6-Dimension Ontology Aligned
4
+
5
+ Automatically moves misplaced files from root to appropriate /one/<dimension>/ directories.
6
+ Keeps root clean with only essential documentation files.
7
+
8
+ 6-Dimension Ontology:
9
+ - groups: Hierarchical containers (organizations, teams, communities)
10
+ - people: Authorization & governance (roles, users, governance)
11
+ - things: Entities (specs, plans, components, agents)
12
+ - connections: Relationships (protocols, workflows, integrations)
13
+ - events: Actions & state changes (deployments, releases, reports)
14
+ - knowledge: Labels & learning (architecture, patterns, rules, guides)
15
+ """
16
+ import os
17
+ import re
18
+ import shutil
19
+ from pathlib import Path
20
+ from typing import Optional, Tuple
21
+
22
+ # Root directory
23
+ root_dir = Path("/Users/toc/Server/ONE")
24
+
25
+ # Files allowed to stay in root (per CLAUDE.md)
26
+ ALLOWED_ROOT_FILES = {
27
+ "README.md",
28
+ "LICENSE.md",
29
+ "SECURITY.md",
30
+ "CLAUDE.md",
31
+ "AGENTS.md",
32
+ }
33
+
34
+ # Installation/project folders to ignore (not part of ONE platform docs)
35
+ INSTALLATION_FOLDERS = {
36
+ "web", "backend", "apps", "cli", "scripts", "node_modules",
37
+ "docs", "media", "import", ".git", ".claude", ".vscode",
38
+ # Installation-specific folders (examples from codebase)
39
+ "one-inc", "nine-padel", "onei-ie", "one.ie",
40
+ }
41
+
42
+
43
+ def classify_file(filename: str, content_preview: str = "") -> Tuple[str, str]:
44
+ """
45
+ Classify a file to determine which dimension directory it belongs to.
46
+ Returns (dimension, reason).
47
+ """
48
+ lower = filename.lower()
49
+
50
+ # Groups: Group-specific docs, organization structures
51
+ if any(word in lower for word in ["group", "organization", "org-", "team", "community", "hierarchy"]):
52
+ return ("groups", "Group-related content")
53
+
54
+ # People: Roles, governance, authorization
55
+ if any(word in lower for word in ["role", "user", "people", "governance", "authorization", "auth", "permission"]):
56
+ return ("people", "People/authorization content")
57
+
58
+ # Things: Specifications, plans, components, agents, features
59
+ if any(word in lower for word in [
60
+ "spec", "plan", "component", "agent", "feature",
61
+ "implementation", "design", "blueprint", "architecture-diagram"
62
+ ]):
63
+ return ("things", "Thing/entity specification")
64
+
65
+ # Connections: Protocols, workflows, integrations, relationships
66
+ if any(word in lower for word in [
67
+ "protocol", "workflow", "integration", "connection",
68
+ "api", "sync", "communication", "relationship"
69
+ ]):
70
+ return ("connections", "Connection/protocol content")
71
+
72
+ # Events: Deployments, releases, reports, audits, summaries
73
+ if any(word in lower for word in [
74
+ "deploy", "release", "report", "audit", "summary",
75
+ "event", "log", "history", "status", "result", "demo", "deliverable"
76
+ ]):
77
+ return ("events", "Event/report content")
78
+
79
+ # Knowledge: Architecture, patterns, rules, guides, documentation
80
+ if any(word in lower for word in [
81
+ "guide", "pattern", "rule", "architecture", "knowledge",
82
+ "best-practice", "convention", "standard", "ontology",
83
+ "documentation", "tutorial", "learning"
84
+ ]):
85
+ return ("knowledge", "Knowledge/learning content")
86
+
87
+ # Default to events for unclassified files (reports, misc docs)
88
+ return ("events", "General documentation/report")
89
+
90
+
91
+ def is_installation_folder(path: Path) -> bool:
92
+ """Check if a path is within an installation folder."""
93
+ parts = path.parts
94
+ root_parts = root_dir.parts
95
+
96
+ if len(parts) <= len(root_parts):
97
+ return False
98
+
99
+ # Get the immediate subdirectory of root
100
+ subdir = parts[len(root_parts)]
101
+ return subdir in INSTALLATION_FOLDERS
102
+
103
+
104
+ def move_file(file_path: Path) -> Optional[Tuple[str, str, str]]:
105
+ """
106
+ Move a file to the appropriate dimension directory.
107
+ Returns (filename, dimension, reason) if moved, None if skipped.
108
+ """
109
+ filename = file_path.name
110
+
111
+ # Skip allowed files
112
+ if filename in ALLOWED_ROOT_FILES:
113
+ return None
114
+
115
+ # Read first 500 chars for classification hints
116
+ content_preview = ""
117
+ try:
118
+ if file_path.suffix in [".md", ".txt"]:
119
+ content_preview = file_path.read_text(encoding="utf-8", errors="ignore")[:500]
120
+ except:
121
+ pass
122
+
123
+ # Classify the file
124
+ dimension, reason = classify_file(filename, content_preview)
125
+
126
+ # Create destination directory
127
+ dest_dir = root_dir / "one" / dimension
128
+ dest_dir.mkdir(parents=True, exist_ok=True)
129
+
130
+ # Move file
131
+ try:
132
+ dest = dest_dir / filename
133
+
134
+ # Handle duplicates by appending number
135
+ counter = 1
136
+ while dest.exists():
137
+ stem = file_path.stem
138
+ suffix = file_path.suffix
139
+ dest = dest_dir / f"{stem}_{counter}{suffix}"
140
+ counter += 1
141
+
142
+ shutil.move(str(file_path), str(dest))
143
+ return (filename, dimension, reason)
144
+ except Exception as e:
145
+ print(f"❌ Failed to move {filename}: {e}")
146
+ return None
147
+
148
+
149
+ def main():
150
+ """Main cleanup routine."""
151
+ files_moved = []
152
+ files_skipped = []
153
+
154
+ # Process markdown files
155
+ for file_path in root_dir.glob("*.md"):
156
+ result = move_file(file_path)
157
+ if result:
158
+ files_moved.append(result)
159
+ else:
160
+ files_skipped.append(file_path.name)
161
+
162
+ # Process text files (deliverables, notes)
163
+ for file_path in root_dir.glob("*.txt"):
164
+ # Skip git-related files
165
+ if file_path.name in {"package-lock.txt", ".gitignore"}:
166
+ continue
167
+
168
+ result = move_file(file_path)
169
+ if result:
170
+ files_moved.append(result)
171
+
172
+ # Report results
173
+ print("=" * 70)
174
+ print("🧹 ROOT CLEANUP - 6-Dimension Ontology Alignment")
175
+ print("=" * 70)
176
+ print()
177
+
178
+ if files_moved:
179
+ print(f"✅ Moved {len(files_moved)} files to dimension directories:")
180
+ print()
181
+
182
+ # Group by dimension
183
+ by_dimension = {}
184
+ for filename, dimension, reason in files_moved:
185
+ if dimension not in by_dimension:
186
+ by_dimension[dimension] = []
187
+ by_dimension[dimension].append((filename, reason))
188
+
189
+ for dimension in ["groups", "people", "things", "connections", "events", "knowledge"]:
190
+ if dimension in by_dimension:
191
+ files = by_dimension[dimension]
192
+ print(f" 📁 /one/{dimension}/ ({len(files)} files)")
193
+ for filename, reason in files:
194
+ print(f" • {filename}")
195
+ print(f" └─ {reason}")
196
+ print()
197
+
198
+ if files_skipped:
199
+ print(f"✅ Kept {len(files_skipped)} essential files in root:")
200
+ for f in sorted(files_skipped):
201
+ print(f" • {f}")
202
+ print()
203
+
204
+ if not files_moved and not files_skipped:
205
+ print("✅ Root is clean - no files to move!")
206
+ print()
207
+
208
+ print("=" * 70)
209
+ print("📖 Approved root files: README.md, LICENSE.md, SECURITY.md,")
210
+ print(" CLAUDE.md, AGENTS.md")
211
+ print()
212
+ print("📁 6 Dimensions: groups, people, things, connections, events, knowledge")
213
+ print("=" * 70)
214
+
215
+
216
+ if __name__ == "__main__":
217
+ main()
@@ -0,0 +1,397 @@
1
+ #!/bin/bash
2
+
3
+ # Security Hook - ONE Platform
4
+ # Protects sensitive files and scans for credentials
5
+ # Enforces 6-dimension ontology security patterns
6
+
7
+ set -e
8
+
9
+ # Get project directory
10
+ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
11
+ CLAUDE_PROJECT_DIR="${CLAUDE_PROJECT_DIR:-$(cd "$SCRIPT_DIR/../.." && pwd)}"
12
+
13
+ # Source the logger
14
+ source "$CLAUDE_PROJECT_DIR/.claude/hooks/hook-logger.sh"
15
+
16
+ # Configuration
17
+ FILE_PATH="${1:-}"
18
+ MODE="${2:-protect}" # protect, scan, audit, ontology
19
+ ACTION="${3:-warn}" # warn, block, log
20
+
21
+ # Sensitive file patterns
22
+ SENSITIVE_PATTERNS=(
23
+ "**/.env*"
24
+ "**/secrets/**"
25
+ "**/*secret*"
26
+ "**/.ssh/**"
27
+ "**/*.pem"
28
+ "**/*.p12"
29
+ "**/credentials/**"
30
+ "**/*token*"
31
+ "**/*apikey*"
32
+ "**/*private*"
33
+ "**/installation/**/secrets/**"
34
+ )
35
+
36
+ # Credential regex patterns
37
+ CREDENTIAL_PATTERNS=(
38
+ "api[_-]?key[s]?\s*[:=]\s*['\"]?[a-zA-Z0-9_-]{16,}"
39
+ "secret[_-]?key[s]?\s*[:=]\s*['\"]?[a-zA-Z0-9_-]{16,}"
40
+ "password[s]?\s*[:=]\s*['\"]?[a-zA-Z0-9!@#$%^&*()_+-=]{8,}"
41
+ "Bearer [a-zA-Z0-9_.-]{16,}"
42
+ "mongodb://[a-zA-Z0-9_:/@.-]+"
43
+ "postgres://[a-zA-Z0-9_:/@.-]+"
44
+ "CLOUDFLARE_[A-Z_]*=.*"
45
+ "CONVEX_[A-Z_]*=.*"
46
+ "RESEND_[A-Z_]*=.*"
47
+ )
48
+
49
+ # 6-DIMENSION ONTOLOGY SECURITY PATTERNS
50
+ # Validates code follows security patterns for each dimension
51
+
52
+ # GROUPS: Multi-tenant isolation patterns
53
+ GROUPS_PATTERNS=(
54
+ "groupId:\s*v\.id\(\"groups\"\)" # groupId required in args
55
+ "\.get\(args\.groupId\)" # Group validation
56
+ "group\.status\s*!==\s*['\"]active['\"]" # Active group check
57
+ "withIndex\(['\"]group_" # Group-scoped indexes
58
+ )
59
+
60
+ # PEOPLE: Authorization patterns
61
+ PEOPLE_PATTERNS=(
62
+ "ctx\.auth\.getUserIdentity\(\)" # Authentication check
63
+ "if\s*\(!identity\)" # Auth validation
64
+ "properties\.role" # Role checking
65
+ "properties\.userId" # User identity linking
66
+ )
67
+
68
+ # THINGS: Entity permission patterns
69
+ THINGS_PATTERNS=(
70
+ "isThingType\(args\.type\)" # Type validation
71
+ "thing\.groupId\s*!==\s*args\.groupId" # Group ownership check
72
+ "\.get\(.*entityId" # Entity access validation
73
+ )
74
+
75
+ # CONNECTIONS: Relationship authorization patterns
76
+ CONNECTIONS_PATTERNS=(
77
+ "isConnectionType\(args\.relationshipType\)" # Type validation
78
+ "fromEntityId.*toEntityId" # Bidirectional validation
79
+ "validateConnection" # Connection validator
80
+ )
81
+
82
+ # EVENTS: Actor tracking patterns
83
+ EVENTS_PATTERNS=(
84
+ "actorId:\s*actor\._id" # Actor logging
85
+ "await ctx\.db\.insert\(['\"]events['\"]" # Event creation
86
+ "type:\s*['\"].*_(created|updated|deleted)" # Event type pattern
87
+ "timestamp:\s*Date\.now\(\)" # Timestamp required
88
+ )
89
+
90
+ # KNOWLEDGE: Embedding security patterns
91
+ KNOWLEDGE_PATTERNS=(
92
+ "embedding:\s*v\.optional" # Vector storage
93
+ "groupId:\s*v\.id\(\"groups\"\)" # Knowledge scoped to groups
94
+ "sourceThingId" # Source tracking
95
+ )
96
+
97
+ # Log start
98
+ log_message "INFO" "security-hook: $MODE mode for ${FILE_PATH:-all files}"
99
+ START_TIME=$(get_time_ms)
100
+
101
+ # Check if file matches sensitive patterns
102
+ is_sensitive_file() {
103
+ local file="$1"
104
+
105
+ for pattern in "${SENSITIVE_PATTERNS[@]}"; do
106
+ # Convert glob to regex
107
+ local regex=$(echo "$pattern" | sed 's/\*\*/.*/' | sed 's/\*/[^\/]*/')
108
+ if [[ "$file" =~ $regex ]]; then
109
+ return 0
110
+ fi
111
+ done
112
+ return 1
113
+ }
114
+
115
+ # Scan file content for credentials
116
+ scan_credentials() {
117
+ local file="$1"
118
+
119
+ if [ ! -f "$file" ]; then
120
+ return 0
121
+ fi
122
+
123
+ local found=0
124
+ for pattern in "${CREDENTIAL_PATTERNS[@]}"; do
125
+ if grep -qE "$pattern" "$file" 2>/dev/null; then
126
+ local line_num=$(grep -nE "$pattern" "$file" | head -1 | cut -d: -f1)
127
+ echo "⚠️ Line $line_num: Potential credential detected"
128
+ log_message "WARN" "Credential pattern in $file:$line_num"
129
+ found=1
130
+ fi
131
+ done
132
+
133
+ return $found
134
+ }
135
+
136
+ # Validate ontology security patterns for a specific dimension
137
+ validate_dimension() {
138
+ local file="$1"
139
+ local dimension="$2"
140
+
141
+ if [ ! -f "$file" ]; then
142
+ return 0
143
+ fi
144
+
145
+ local violations=0
146
+
147
+ # Only check TypeScript files in backend/convex
148
+ if [[ ! "$file" =~ backend/convex/.*\.(ts|js)$ ]]; then
149
+ return 0
150
+ fi
151
+
152
+ # Detect if file is a mutation (requires stricter checks)
153
+ local is_mutation=0
154
+ if [[ "$file" =~ mutations/ ]]; then
155
+ is_mutation=1
156
+ fi
157
+
158
+ # Check for required patterns based on dimension
159
+ case "$dimension" in
160
+ "GROUPS")
161
+ # Mutations must validate groupId
162
+ if [ $is_mutation -eq 1 ]; then
163
+ if ! grep -q "groupId:" "$file" 2>/dev/null; then
164
+ echo "❌ GROUPS: Missing groupId parameter in mutation"
165
+ violations=1
166
+ fi
167
+ if ! grep -qE "\.get\(.*groupId\)" "$file" 2>/dev/null; then
168
+ echo "⚠️ GROUPS: No group validation detected"
169
+ violations=1
170
+ fi
171
+ fi
172
+ ;;
173
+ "PEOPLE")
174
+ # Mutations must authenticate
175
+ if [ $is_mutation -eq 1 ]; then
176
+ if ! grep -q "getUserIdentity()" "$file" 2>/dev/null; then
177
+ echo "❌ PEOPLE: Missing authentication check in mutation"
178
+ violations=1
179
+ fi
180
+ fi
181
+ ;;
182
+ "EVENTS")
183
+ # Mutations creating/updating entities should log events
184
+ if [ $is_mutation -eq 1 ]; then
185
+ if grep -qE "ctx\.db\.insert\(['\"]entities['\"]" "$file" 2>/dev/null; then
186
+ if ! grep -qE "ctx\.db\.insert\(['\"]events['\"]" "$file" 2>/dev/null; then
187
+ echo "⚠️ EVENTS: Entity mutation without event logging"
188
+ violations=1
189
+ fi
190
+ if ! grep -q "actorId:" "$file" 2>/dev/null; then
191
+ echo "⚠️ EVENTS: Event logging without actorId"
192
+ violations=1
193
+ fi
194
+ fi
195
+ fi
196
+ ;;
197
+ esac
198
+
199
+ return $violations
200
+ }
201
+
202
+ # Comprehensive ontology security scan
203
+ scan_ontology_security() {
204
+ local file="$1"
205
+
206
+ if [ ! -f "$file" ]; then
207
+ return 0
208
+ fi
209
+
210
+ # Only check backend TypeScript files
211
+ if [[ ! "$file" =~ backend/convex/.*\.(ts|js)$ ]]; then
212
+ return 0
213
+ fi
214
+
215
+ echo "🔒 Scanning ontology security patterns: $file"
216
+
217
+ local violations=0
218
+
219
+ # Check each dimension
220
+ validate_dimension "$file" "GROUPS" GROUPS_PATTERNS
221
+ violations=$((violations + $?))
222
+
223
+ validate_dimension "$file" "PEOPLE" PEOPLE_PATTERNS
224
+ violations=$((violations + $?))
225
+
226
+ validate_dimension "$file" "EVENTS" EVENTS_PATTERNS
227
+ violations=$((violations + $?))
228
+
229
+ # Check for cross-group data leakage patterns (CRITICAL)
230
+ if grep -qE "ctx\.db\.query\(['\"]entities['\"]\)" "$file" 2>/dev/null; then
231
+ if ! grep -q "withIndex" "$file" 2>/dev/null; then
232
+ echo "❌ CRITICAL: Unscoped query detected (potential data leakage)"
233
+ echo " Use .withIndex('group_type', ...) to scope by groupId"
234
+ violations=$((violations + 1))
235
+ fi
236
+ fi
237
+
238
+ # Check for missing soft delete filtering
239
+ if grep -qE "ctx\.db\.query\(['\"]entities['\"]\)" "$file" 2>/dev/null; then
240
+ if ! grep -q "deletedAt" "$file" 2>/dev/null; then
241
+ echo "⚠️ WARNING: Query may return soft-deleted entities"
242
+ echo " Add .filter(q => q.eq(q.field('deletedAt'), undefined))"
243
+ violations=$((violations + 1))
244
+ fi
245
+ fi
246
+
247
+ if [ $violations -eq 0 ]; then
248
+ echo "✅ Ontology security patterns validated"
249
+ else
250
+ log_message "WARN" "Ontology violations in $file: $violations"
251
+ fi
252
+
253
+ return $violations
254
+ }
255
+
256
+ # Create audit entry
257
+ audit() {
258
+ local file="$1"
259
+ local event="$2"
260
+ local action="$3"
261
+
262
+ local audit_file="$CLAUDE_PROJECT_DIR/.claude/security-audit.log"
263
+ local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
264
+
265
+ echo "[$timestamp] $event | $file | $action" >> "$audit_file"
266
+ }
267
+
268
+ EXIT_CODE=0
269
+
270
+ case "$MODE" in
271
+ "protect")
272
+ if [ -n "$FILE_PATH" ] && is_sensitive_file "$FILE_PATH"; then
273
+ case "$ACTION" in
274
+ "block")
275
+ echo "🚫 BLOCKED: Cannot modify sensitive file: $FILE_PATH"
276
+ log_message "ERROR" "Blocked: $FILE_PATH"
277
+ audit "$FILE_PATH" "BLOCKED" "sensitive file"
278
+ EXIT_CODE=2
279
+ ;;
280
+ "warn")
281
+ echo "⚠️ WARNING: Modifying sensitive file: $FILE_PATH"
282
+ echo " Ensure no secrets are being committed"
283
+ log_message "WARN" "Sensitive file modified: $FILE_PATH"
284
+ audit "$FILE_PATH" "WARNED" "sensitive file"
285
+ ;;
286
+ "log")
287
+ log_message "INFO" "Sensitive file access: $FILE_PATH"
288
+ audit "$FILE_PATH" "LOGGED" "sensitive file"
289
+ ;;
290
+ esac
291
+ fi
292
+ ;;
293
+
294
+ "scan")
295
+ if [ -n "$FILE_PATH" ] && [ -f "$FILE_PATH" ]; then
296
+ echo "🔍 Scanning $FILE_PATH for credentials..."
297
+ if ! scan_credentials "$FILE_PATH"; then
298
+ echo "✅ No credentials detected"
299
+ audit "$FILE_PATH" "SCAN_PASSED" "clean"
300
+ else
301
+ audit "$FILE_PATH" "SCAN_FAILED" "credentials found"
302
+ if [ "$ACTION" = "block" ]; then
303
+ EXIT_CODE=2
304
+ fi
305
+ fi
306
+ fi
307
+ ;;
308
+
309
+ "ontology")
310
+ if [ -n "$FILE_PATH" ] && [ -f "$FILE_PATH" ]; then
311
+ echo "🔒 Validating ontology security patterns..."
312
+ if ! scan_ontology_security "$FILE_PATH"; then
313
+ audit "$FILE_PATH" "ONTOLOGY_PASSED" "compliant"
314
+ else
315
+ echo ""
316
+ echo "📖 Ontology Security Reference:"
317
+ echo " GROUPS: All mutations must validate groupId and check group.status === 'active'"
318
+ echo " PEOPLE: All mutations must call ctx.auth.getUserIdentity() and check authentication"
319
+ echo " THINGS: Use isThingType() to validate entity types from ontology"
320
+ echo " CONNECTIONS: Validate both fromEntityId and toEntityId belong to same group"
321
+ echo " EVENTS: Log events with actorId after successful mutations"
322
+ echo " KNOWLEDGE: Scope embeddings to groupId and track sourceThingId"
323
+ echo ""
324
+ echo " For details, see: one/knowledge/ontology.md"
325
+ audit "$FILE_PATH" "ONTOLOGY_VIOLATIONS" "security issues found"
326
+ if [ "$ACTION" = "block" ]; then
327
+ EXIT_CODE=2
328
+ else
329
+ EXIT_CODE=1
330
+ fi
331
+ fi
332
+ else
333
+ echo "❌ File not found: $FILE_PATH"
334
+ EXIT_CODE=1
335
+ fi
336
+ ;;
337
+
338
+ "audit")
339
+ echo "📋 Security Audit Summary"
340
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
341
+ echo ""
342
+ echo "6-DIMENSION ONTOLOGY SECURITY MODEL"
343
+ echo "───────────────────────────────────────"
344
+ echo "1. GROUPS: Multi-tenant isolation (groupId scoping)"
345
+ echo "2. PEOPLE: Authentication & authorization (role-based access)"
346
+ echo "3. THINGS: Entity permissions (type validation)"
347
+ echo "4. CONNECTIONS: Relationship authorization (bidirectional validation)"
348
+ echo "5. EVENTS: Actor tracking (audit trail)"
349
+ echo "6. KNOWLEDGE: Embedding security (source tracking)"
350
+ echo ""
351
+
352
+ AUDIT_FILE="$CLAUDE_PROJECT_DIR/.claude/security-audit.log"
353
+
354
+ if [ -f "$AUDIT_FILE" ]; then
355
+ echo "Recent security events (last 10):"
356
+ echo "───────────────────────────────────────"
357
+ tail -10 "$AUDIT_FILE"
358
+ echo ""
359
+ echo "Statistics:"
360
+ echo "───────────────────────────────────────"
361
+ echo " Blocked: $(grep -c "BLOCKED" "$AUDIT_FILE" 2>/dev/null || echo 0)"
362
+ echo " Warned: $(grep -c "WARNED" "$AUDIT_FILE" 2>/dev/null || echo 0)"
363
+ echo " Credential scans failed: $(grep -c "SCAN_FAILED" "$AUDIT_FILE" 2>/dev/null || echo 0)"
364
+ echo " Ontology violations: $(grep -c "ONTOLOGY_VIOLATIONS" "$AUDIT_FILE" 2>/dev/null || echo 0)"
365
+ echo " Ontology compliant: $(grep -c "ONTOLOGY_PASSED" "$AUDIT_FILE" 2>/dev/null || echo 0)"
366
+ else
367
+ echo "No audit log found"
368
+ echo "Run security scans to generate audit trail"
369
+ fi
370
+ echo ""
371
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
372
+ ;;
373
+
374
+ *)
375
+ echo "❌ Unknown security mode: $MODE"
376
+ echo ""
377
+ echo "Usage: security-hook.sh <file> <mode> <action>"
378
+ echo ""
379
+ echo "Modes:"
380
+ echo " protect - Protect sensitive files from modification"
381
+ echo " scan - Scan files for hardcoded credentials"
382
+ echo " ontology - Validate 6-dimension ontology security patterns"
383
+ echo " audit - Display security audit summary"
384
+ echo ""
385
+ echo "Actions:"
386
+ echo " warn - Display warnings (default)"
387
+ echo " block - Block operations that fail validation"
388
+ echo " log - Log events only"
389
+ EXIT_CODE=1
390
+ ;;
391
+ esac
392
+
393
+ # Log completion
394
+ END_TIME=$(get_time_ms)
395
+ log_hook_execution "security-hook" "$MODE $FILE_PATH" "$START_TIME" "$END_TIME" "$EXIT_CODE"
396
+
397
+ exit $EXIT_CODE