oneie 3.6.24 → 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.
- package/.claude/agents/agent-backend.md +2 -2
- package/.claude/agents/agent-designer.md +1 -0
- package/.claude/agents/agent-director.md +71 -71
- package/.claude/agents/agent-onboard.md +1 -1
- package/.claude/agents/agent-ontology.md +2 -2
- package/.claude/agents/agent-ops.md +58 -38
- package/.claude/agents/agent-sales.md +3 -3
- package/.claude/commands/cascade.md +21 -21
- package/.claude/commands/create.md +19 -19
- package/.claude/commands/deploy.md +82 -104
- package/.claude/commands/mcp-on.md +191 -0
- package/.claude/commands/one.md +267 -92
- package/.claude/commands/plan.md +17 -17
- package/.claude/commands/release.md +65 -14
- package/.claude/hooks/PULL-BEFORE-PUSH-GUIDE.md +473 -0
- package/.claude/hooks/README-knowledge-hooks.md +451 -0
- package/.claude/hooks/README-root-cleanup.md +200 -0
- package/.claude/hooks/README.md +284 -0
- package/.claude/hooks/__pycache__/done.cpython-313.pyc +0 -0
- package/.claude/hooks/__pycache__/todo.cpython-313.pyc +0 -0
- package/.claude/hooks/check-filenames.py +177 -0
- package/.claude/hooks/clean-post.py +468 -0
- package/.claude/hooks/clean-pre.py +393 -0
- package/.claude/hooks/clean-root-markdown.sh +73 -0
- package/.claude/hooks/commit-push.sh +95 -0
- package/.claude/hooks/done.py +236 -0
- package/.claude/hooks/format-hook.sh +163 -0
- package/.claude/hooks/hook-logger.sh +173 -0
- package/.claude/hooks/knowledge-post.py +355 -0
- package/.claude/hooks/knowledge-pre.py +245 -0
- package/.claude/hooks/mcp-on.sh +134 -0
- package/.claude/hooks/notification-hook.sh +279 -0
- package/.claude/hooks/push.sh +101 -0
- package/.claude/hooks/release-cli.sh +16 -8
- package/.claude/hooks/root-cleanup.py +217 -0
- package/.claude/hooks/security-hook.sh +397 -0
- package/.claude/hooks/tag-all-docs.py +464 -0
- package/.claude/hooks/test-validate-ontology.sh +170 -0
- package/.claude/hooks/todo.py +368 -0
- package/.claude/hooks/track-changes.sh +101 -0
- package/.claude/hooks/validate-ontology-structure-summary.md +243 -0
- package/.claude/hooks/validate-ontology-structure.py +518 -0
- package/.claude/skills/INDEX.md +1 -1
- package/.claude/skills/ontology/README.md +1 -1
- package/package.json +1 -1
- package/.claude/commands/mcp-toggle.md +0 -93
- package/.claude/commands/npx.md +0 -84
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
ONE Platform - Metadata Tagging Script
|
|
4
|
+
Applies metadata tags to all documentation files.
|
|
5
|
+
|
|
6
|
+
Usage:
|
|
7
|
+
python3 .claude/hooks/tag-all-docs.py [--dry-run] [--verbose]
|
|
8
|
+
|
|
9
|
+
This script:
|
|
10
|
+
- Scans all markdown files in one/ directory and installation folders
|
|
11
|
+
- Adds metadata frontmatter if missing
|
|
12
|
+
- Infers dimension, category, and tags from file location and content
|
|
13
|
+
- Updates existing metadata if incomplete
|
|
14
|
+
- Supports installation-specific and group-specific documentation
|
|
15
|
+
- Generates a comprehensive report
|
|
16
|
+
"""
|
|
17
|
+
import argparse
|
|
18
|
+
import re
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
from datetime import datetime
|
|
21
|
+
from typing import Dict, List, Tuple, Optional
|
|
22
|
+
import sys
|
|
23
|
+
import os
|
|
24
|
+
|
|
25
|
+
# 6-Dimension Ontology (Universal Reality Model)
|
|
26
|
+
DIMENSION_MAP = {
|
|
27
|
+
"groups": "groups",
|
|
28
|
+
"people": "people",
|
|
29
|
+
"things": "things",
|
|
30
|
+
"connections": "connections",
|
|
31
|
+
"events": "events",
|
|
32
|
+
"knowledge": "knowledge",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
# Category cycle from subdirectories (ontology-aligned)
|
|
36
|
+
CATEGORY_MAP = {
|
|
37
|
+
"agents": "agents",
|
|
38
|
+
"plans": "plans",
|
|
39
|
+
"products": "products",
|
|
40
|
+
"features": "features",
|
|
41
|
+
"components": "components",
|
|
42
|
+
"examples": "examples",
|
|
43
|
+
"claude": "agents",
|
|
44
|
+
"protocols": "protocols",
|
|
45
|
+
"workflows": "workflows",
|
|
46
|
+
"patterns": "patterns",
|
|
47
|
+
"architecture": "architecture",
|
|
48
|
+
"specifications": "specifications",
|
|
49
|
+
"guides": "guides",
|
|
50
|
+
"rules": "governance",
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
# Tag suggestions based on keywords in content (ontology-aligned)
|
|
54
|
+
TAG_KEYWORDS = {
|
|
55
|
+
"ai": ["ai", "artificial-intelligence", "machine-learning"],
|
|
56
|
+
"agent": ["agent", "ai-agent", "automation"],
|
|
57
|
+
"ontology": ["ontology", "6-dimensions", "reality-model"],
|
|
58
|
+
"protocol": ["protocol", "specification", "interoperability"],
|
|
59
|
+
"architecture": ["architecture", "system-design", "patterns"],
|
|
60
|
+
"frontend": ["frontend", "ui", "astro", "react"],
|
|
61
|
+
"backend": ["backend", "convex", "database", "effect"],
|
|
62
|
+
"blockchain": ["blockchain", "crypto", "web3", "sui", "solana"],
|
|
63
|
+
"authentication": ["auth", "better-auth", "authorization"],
|
|
64
|
+
"testing": ["testing", "quality", "validation"],
|
|
65
|
+
"groups": ["groups", "multi-tenant", "hierarchical"],
|
|
66
|
+
"people": ["people", "roles", "authorization", "governance"],
|
|
67
|
+
"things": ["things", "entities", "types"],
|
|
68
|
+
"connections": ["connections", "relationships", "graph"],
|
|
69
|
+
"events": ["events", "actions", "audit-trail"],
|
|
70
|
+
"knowledge": ["knowledge", "rag", "embeddings", "semantic-search"],
|
|
71
|
+
"cycle": ["cycle", "claude", "planning"],
|
|
72
|
+
"installation": ["installation", "customization", "organization"],
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class MetadataTagger:
|
|
77
|
+
def __init__(self, project_dir: str, dry_run: bool = False, verbose: bool = False):
|
|
78
|
+
self.project_dir = Path(project_dir)
|
|
79
|
+
self.dry_run = dry_run
|
|
80
|
+
self.verbose = verbose
|
|
81
|
+
self.files_processed = 0
|
|
82
|
+
self.files_tagged = 0
|
|
83
|
+
self.files_updated = 0
|
|
84
|
+
self.files_skipped = 0
|
|
85
|
+
|
|
86
|
+
def scan_and_tag_all(self):
|
|
87
|
+
"""Scan all markdown files in /one/ and installation folders"""
|
|
88
|
+
markdown_files = []
|
|
89
|
+
|
|
90
|
+
# Scan global /one/ directory
|
|
91
|
+
one_dir = self.project_dir / "one"
|
|
92
|
+
if one_dir.exists():
|
|
93
|
+
global_files = list(one_dir.rglob("*.md"))
|
|
94
|
+
markdown_files.extend(global_files)
|
|
95
|
+
print(f"Found {len(global_files)} files in /one/ (global)")
|
|
96
|
+
else:
|
|
97
|
+
print(f"Warning: {one_dir} does not exist")
|
|
98
|
+
|
|
99
|
+
# Scan installation folders (any top-level dir except known dirs)
|
|
100
|
+
excluded_dirs = {
|
|
101
|
+
"one", "web", "backend", "apps", ".claude", ".git",
|
|
102
|
+
"node_modules", "dist", "build", "cli", "import", "docs",
|
|
103
|
+
"scripts", "one-inc", "nine-padel", "onei-ie", "one.ie"
|
|
104
|
+
}
|
|
105
|
+
for item in self.project_dir.iterdir():
|
|
106
|
+
if item.is_dir() and item.name not in excluded_dirs and not item.name.startswith("."):
|
|
107
|
+
# This might be an installation folder
|
|
108
|
+
installation_files = list(item.rglob("*.md"))
|
|
109
|
+
if installation_files:
|
|
110
|
+
markdown_files.extend(installation_files)
|
|
111
|
+
print(f"Found {len(installation_files)} files in /{item.name}/ (installation)")
|
|
112
|
+
|
|
113
|
+
if not markdown_files:
|
|
114
|
+
print("No markdown files found to process")
|
|
115
|
+
return
|
|
116
|
+
|
|
117
|
+
print(f"\nTotal: {len(markdown_files)} markdown files to process\n")
|
|
118
|
+
|
|
119
|
+
for md_file in markdown_files:
|
|
120
|
+
self.files_processed += 1
|
|
121
|
+
self.process_file(md_file)
|
|
122
|
+
|
|
123
|
+
def process_file(self, file_path: Path):
|
|
124
|
+
"""Process a single markdown file"""
|
|
125
|
+
try:
|
|
126
|
+
content = file_path.read_text()
|
|
127
|
+
relative_path = file_path.relative_to(self.project_dir)
|
|
128
|
+
|
|
129
|
+
# Check if file has metadata
|
|
130
|
+
has_metadata, existing_metadata = self.parse_existing_metadata(content)
|
|
131
|
+
|
|
132
|
+
if has_metadata and self.is_metadata_complete(existing_metadata):
|
|
133
|
+
if self.verbose:
|
|
134
|
+
print(f"✓ {relative_path} - Already has complete metadata")
|
|
135
|
+
self.files_skipped += 1
|
|
136
|
+
return
|
|
137
|
+
|
|
138
|
+
# Generate metadata
|
|
139
|
+
metadata = self.generate_metadata(file_path, content, existing_metadata)
|
|
140
|
+
|
|
141
|
+
# Apply metadata
|
|
142
|
+
if has_metadata:
|
|
143
|
+
new_content = self.update_metadata(content, metadata)
|
|
144
|
+
action = "Updated"
|
|
145
|
+
self.files_updated += 1
|
|
146
|
+
else:
|
|
147
|
+
new_content = self.add_metadata(content, metadata)
|
|
148
|
+
action = "Tagged"
|
|
149
|
+
self.files_tagged += 1
|
|
150
|
+
|
|
151
|
+
if self.dry_run:
|
|
152
|
+
print(f"[DRY RUN] Would {action.lower()}: {relative_path}")
|
|
153
|
+
if self.verbose:
|
|
154
|
+
print(f" Metadata: {metadata}")
|
|
155
|
+
else:
|
|
156
|
+
file_path.write_text(new_content)
|
|
157
|
+
print(f"{action}: {relative_path}")
|
|
158
|
+
if self.verbose:
|
|
159
|
+
print(f" Metadata: {metadata}")
|
|
160
|
+
|
|
161
|
+
except Exception as e:
|
|
162
|
+
print(f"✗ Error processing {file_path.name}: {e}")
|
|
163
|
+
|
|
164
|
+
def parse_existing_metadata(self, content: str) -> Tuple[bool, Dict]:
|
|
165
|
+
"""Parse existing YAML frontmatter"""
|
|
166
|
+
if not content.startswith("---\n"):
|
|
167
|
+
return False, {}
|
|
168
|
+
|
|
169
|
+
# Find end of frontmatter
|
|
170
|
+
end_match = re.search(r"\n---\n", content[4:])
|
|
171
|
+
if not end_match:
|
|
172
|
+
return False, {}
|
|
173
|
+
|
|
174
|
+
frontmatter = content[4:4 + end_match.start()]
|
|
175
|
+
|
|
176
|
+
# Parse YAML-like metadata (simple parsing)
|
|
177
|
+
metadata = {}
|
|
178
|
+
for line in frontmatter.split("\n"):
|
|
179
|
+
if ":" in line:
|
|
180
|
+
key, value = line.split(":", 1)
|
|
181
|
+
metadata[key.strip()] = value.strip()
|
|
182
|
+
|
|
183
|
+
return True, metadata
|
|
184
|
+
|
|
185
|
+
def is_metadata_complete(self, metadata: Dict) -> bool:
|
|
186
|
+
"""Check if metadata has all required fields"""
|
|
187
|
+
required_fields = [
|
|
188
|
+
"title",
|
|
189
|
+
"dimension",
|
|
190
|
+
"category",
|
|
191
|
+
"tags",
|
|
192
|
+
"created",
|
|
193
|
+
"updated",
|
|
194
|
+
"version",
|
|
195
|
+
"ai_context"
|
|
196
|
+
]
|
|
197
|
+
|
|
198
|
+
return all(field in metadata for field in required_fields)
|
|
199
|
+
|
|
200
|
+
def generate_metadata(
|
|
201
|
+
self,
|
|
202
|
+
file_path: Path,
|
|
203
|
+
content: str,
|
|
204
|
+
existing: Dict
|
|
205
|
+
) -> Dict:
|
|
206
|
+
"""Generate metadata for a file"""
|
|
207
|
+
relative_path = file_path.relative_to(self.project_dir)
|
|
208
|
+
parts = relative_path.parts
|
|
209
|
+
|
|
210
|
+
# Detect if this is an installation-specific file
|
|
211
|
+
is_installation = parts[0] not in {"one", "web", "backend", "apps", ".claude"}
|
|
212
|
+
installation_name = parts[0] if is_installation else None
|
|
213
|
+
|
|
214
|
+
# Detect if this is group-specific
|
|
215
|
+
is_group = len(parts) > 2 and parts[1] == "groups" if is_installation else False
|
|
216
|
+
group_slug = parts[2] if is_group else None
|
|
217
|
+
|
|
218
|
+
# Cycle dimension from directory structure
|
|
219
|
+
if is_installation:
|
|
220
|
+
# Installation folders mirror /one/ structure
|
|
221
|
+
dimension = parts[1] if len(parts) > 1 and parts[1] in DIMENSION_MAP else "knowledge"
|
|
222
|
+
else:
|
|
223
|
+
# Global /one/ structure
|
|
224
|
+
dimension = parts[1] if len(parts) > 1 and parts[1] in DIMENSION_MAP else "knowledge"
|
|
225
|
+
|
|
226
|
+
# Cycle category from subdirectories
|
|
227
|
+
category = "general"
|
|
228
|
+
if is_group:
|
|
229
|
+
category = "group-specific"
|
|
230
|
+
elif len(parts) > 2:
|
|
231
|
+
subdir_idx = 3 if is_group else (2 if is_installation else 2)
|
|
232
|
+
if len(parts) > subdir_idx:
|
|
233
|
+
subdir = parts[subdir_idx]
|
|
234
|
+
category = CATEGORY_MAP.get(subdir, subdir)
|
|
235
|
+
|
|
236
|
+
# Generate title from filename
|
|
237
|
+
title = existing.get("title") or file_path.stem.replace("-", " ").title()
|
|
238
|
+
|
|
239
|
+
# Extract/infer tags
|
|
240
|
+
tags = self.infer_tags(content, file_path, existing)
|
|
241
|
+
|
|
242
|
+
# Cycle related dimensions by analyzing content
|
|
243
|
+
related_dimensions = self.infer_related_dimensions(content, dimension)
|
|
244
|
+
|
|
245
|
+
# Generate AI context
|
|
246
|
+
ai_context = self.generate_ai_context(
|
|
247
|
+
file_path, dimension, category, content,
|
|
248
|
+
installation_name, group_slug, related_dimensions
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
metadata = {
|
|
252
|
+
"title": title,
|
|
253
|
+
"dimension": dimension,
|
|
254
|
+
"category": category,
|
|
255
|
+
"tags": ", ".join(tags),
|
|
256
|
+
"related_dimensions": ", ".join(related_dimensions),
|
|
257
|
+
"created": existing.get("created", datetime.now().strftime("%Y-%m-%d")),
|
|
258
|
+
"updated": datetime.now().strftime("%Y-%m-%d"),
|
|
259
|
+
"version": existing.get("version", "1.0.0"),
|
|
260
|
+
"ai_context": ai_context,
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
# Add scope metadata
|
|
264
|
+
if is_installation:
|
|
265
|
+
metadata["scope"] = "installation"
|
|
266
|
+
metadata["installation"] = installation_name
|
|
267
|
+
else:
|
|
268
|
+
metadata["scope"] = "global"
|
|
269
|
+
|
|
270
|
+
if is_group:
|
|
271
|
+
metadata["group"] = group_slug
|
|
272
|
+
|
|
273
|
+
return metadata
|
|
274
|
+
|
|
275
|
+
def infer_tags(self, content: str, file_path: Path, existing: Dict) -> List[str]:
|
|
276
|
+
"""Cycle tags from content and context"""
|
|
277
|
+
tags = set()
|
|
278
|
+
|
|
279
|
+
# Use existing tags if present
|
|
280
|
+
if existing.get("tags"):
|
|
281
|
+
existing_tags_str = existing["tags"].strip("[]")
|
|
282
|
+
tags.update(tag.strip().strip('"').strip("'") for tag in existing_tags_str.split(","))
|
|
283
|
+
|
|
284
|
+
# Add tags based on filename
|
|
285
|
+
filename_lower = file_path.stem.lower()
|
|
286
|
+
for keyword, keyword_tags in TAG_KEYWORDS.items():
|
|
287
|
+
if keyword in filename_lower:
|
|
288
|
+
tags.update(keyword_tags[:2]) # Add first 2 related tags
|
|
289
|
+
|
|
290
|
+
# Add tags based on content (first 1000 chars)
|
|
291
|
+
content_sample = content[:1000].lower()
|
|
292
|
+
for keyword, keyword_tags in TAG_KEYWORDS.items():
|
|
293
|
+
if keyword in content_sample:
|
|
294
|
+
tags.add(keyword_tags[0]) # Add primary tag
|
|
295
|
+
|
|
296
|
+
# Limit to 10 tags
|
|
297
|
+
return sorted(list(tags))[:10]
|
|
298
|
+
|
|
299
|
+
def infer_related_dimensions(self, content: str, primary_dimension: str) -> List[str]:
|
|
300
|
+
"""Cycle which other dimensions this document relates to"""
|
|
301
|
+
related = set()
|
|
302
|
+
content_lower = content[:2000].lower() # Check first 2000 chars
|
|
303
|
+
|
|
304
|
+
# Map dimension keywords to dimensions
|
|
305
|
+
dimension_keywords = {
|
|
306
|
+
"groups": ["group", "organization", "multi-tenant", "hierarchical", "parent", "child"],
|
|
307
|
+
"people": ["people", "user", "role", "authorization", "governance", "actor", "creator"],
|
|
308
|
+
"things": ["thing", "entity", "type", "properties", "status"],
|
|
309
|
+
"connections": ["connection", "relationship", "link", "relate", "junction"],
|
|
310
|
+
"events": ["event", "action", "timestamp", "audit", "log", "happened"],
|
|
311
|
+
"knowledge": ["knowledge", "embedding", "vector", "rag", "search", "semantic", "learn"],
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
for dimension, keywords in dimension_keywords.items():
|
|
315
|
+
if dimension != primary_dimension: # Don't include self
|
|
316
|
+
if any(keyword in content_lower for keyword in keywords):
|
|
317
|
+
related.add(dimension)
|
|
318
|
+
|
|
319
|
+
return sorted(list(related))
|
|
320
|
+
|
|
321
|
+
def generate_ai_context(
|
|
322
|
+
self,
|
|
323
|
+
file_path: Path,
|
|
324
|
+
dimension: str,
|
|
325
|
+
category: str,
|
|
326
|
+
content: str,
|
|
327
|
+
installation_name: Optional[str] = None,
|
|
328
|
+
group_slug: Optional[str] = None,
|
|
329
|
+
related_dimensions: Optional[List[str]] = None
|
|
330
|
+
) -> str:
|
|
331
|
+
"""Generate AI context description"""
|
|
332
|
+
relative_path = file_path.relative_to(self.project_dir)
|
|
333
|
+
|
|
334
|
+
# Extract first heading or first paragraph
|
|
335
|
+
purpose = "Provides information"
|
|
336
|
+
heading_match = re.search(r"^#\s+(.+)$", content, re.MULTILINE)
|
|
337
|
+
if heading_match:
|
|
338
|
+
purpose = f"Documents {heading_match.group(1).lower()}"
|
|
339
|
+
else:
|
|
340
|
+
first_para = re.search(r"^[A-Z].+\.", content, re.MULTILINE)
|
|
341
|
+
if first_para:
|
|
342
|
+
purpose = first_para.group(0)[:100]
|
|
343
|
+
|
|
344
|
+
# Build context string
|
|
345
|
+
context_parts = [
|
|
346
|
+
f"This document is part of the {dimension} dimension in the {category} category.",
|
|
347
|
+
f"Location: {relative_path}",
|
|
348
|
+
f"Purpose: {purpose}",
|
|
349
|
+
]
|
|
350
|
+
|
|
351
|
+
if installation_name:
|
|
352
|
+
context_parts.append(f"Installation: {installation_name}")
|
|
353
|
+
|
|
354
|
+
if group_slug:
|
|
355
|
+
context_parts.append(f"Group: {group_slug}")
|
|
356
|
+
|
|
357
|
+
if related_dimensions:
|
|
358
|
+
context_parts.append(f"Related dimensions: {', '.join(related_dimensions)}")
|
|
359
|
+
|
|
360
|
+
context_parts.append(f"For AI agents: Read this to understand {file_path.stem.replace('-', ' ')}.")
|
|
361
|
+
|
|
362
|
+
return "\n".join(context_parts)
|
|
363
|
+
|
|
364
|
+
def add_metadata(self, content: str, metadata: Dict) -> str:
|
|
365
|
+
"""Add metadata frontmatter to content"""
|
|
366
|
+
# Build frontmatter dynamically
|
|
367
|
+
frontmatter_lines = ["---"]
|
|
368
|
+
frontmatter_lines.append(f"title: {metadata['title']}")
|
|
369
|
+
frontmatter_lines.append(f"dimension: {metadata['dimension']}")
|
|
370
|
+
frontmatter_lines.append(f"category: {metadata['category']}")
|
|
371
|
+
frontmatter_lines.append(f"tags: {metadata['tags']}")
|
|
372
|
+
|
|
373
|
+
if metadata.get('related_dimensions'):
|
|
374
|
+
frontmatter_lines.append(f"related_dimensions: {metadata['related_dimensions']}")
|
|
375
|
+
|
|
376
|
+
frontmatter_lines.append(f"scope: {metadata['scope']}")
|
|
377
|
+
|
|
378
|
+
if metadata.get('installation'):
|
|
379
|
+
frontmatter_lines.append(f"installation: {metadata['installation']}")
|
|
380
|
+
|
|
381
|
+
if metadata.get('group'):
|
|
382
|
+
frontmatter_lines.append(f"group: {metadata['group']}")
|
|
383
|
+
|
|
384
|
+
frontmatter_lines.append(f"created: {metadata['created']}")
|
|
385
|
+
frontmatter_lines.append(f"updated: {metadata['updated']}")
|
|
386
|
+
frontmatter_lines.append(f"version: {metadata['version']}")
|
|
387
|
+
|
|
388
|
+
# Format ai_context as multiline
|
|
389
|
+
ai_context_indented = "\n ".join(metadata['ai_context'].split("\n"))
|
|
390
|
+
frontmatter_lines.append(f"ai_context: |\n {ai_context_indented}")
|
|
391
|
+
frontmatter_lines.append("---\n")
|
|
392
|
+
|
|
393
|
+
return "\n".join(frontmatter_lines) + "\n" + content
|
|
394
|
+
|
|
395
|
+
def update_metadata(self, content: str, metadata: Dict) -> str:
|
|
396
|
+
"""Update existing metadata frontmatter"""
|
|
397
|
+
# Find end of existing frontmatter
|
|
398
|
+
end_match = re.search(r"\n---\n", content[4:])
|
|
399
|
+
if not end_match:
|
|
400
|
+
return self.add_metadata(content, metadata)
|
|
401
|
+
|
|
402
|
+
# Replace with new metadata
|
|
403
|
+
body = content[4 + end_match.end():]
|
|
404
|
+
return self.add_metadata(body, metadata)
|
|
405
|
+
|
|
406
|
+
def print_summary(self):
|
|
407
|
+
"""Print summary of tagging operation"""
|
|
408
|
+
print("\n" + "=" * 70)
|
|
409
|
+
print("METADATA TAGGING SUMMARY")
|
|
410
|
+
print("=" * 70)
|
|
411
|
+
print(f"Files Processed: {self.files_processed}")
|
|
412
|
+
print(f"Files Tagged: {self.files_tagged}")
|
|
413
|
+
print(f"Files Updated: {self.files_updated}")
|
|
414
|
+
print(f"Files Skipped: {self.files_skipped}")
|
|
415
|
+
print("=" * 70)
|
|
416
|
+
|
|
417
|
+
if self.dry_run:
|
|
418
|
+
print("\n[DRY RUN] No files were actually modified.")
|
|
419
|
+
print("Run without --dry-run to apply changes.")
|
|
420
|
+
else:
|
|
421
|
+
print("\n✅ Tagging complete! All files now have metadata.")
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
def main():
|
|
425
|
+
parser = argparse.ArgumentParser(
|
|
426
|
+
description="Add metadata tags to all ONE Platform documentation files"
|
|
427
|
+
)
|
|
428
|
+
parser.add_argument(
|
|
429
|
+
"--dry-run",
|
|
430
|
+
action="store_true",
|
|
431
|
+
help="Show what would be tagged without modifying files"
|
|
432
|
+
)
|
|
433
|
+
parser.add_argument(
|
|
434
|
+
"--verbose",
|
|
435
|
+
action="store_true",
|
|
436
|
+
help="Show detailed output for each file"
|
|
437
|
+
)
|
|
438
|
+
parser.add_argument(
|
|
439
|
+
"--project-dir",
|
|
440
|
+
default=".",
|
|
441
|
+
help="Project root directory (default: current directory)"
|
|
442
|
+
)
|
|
443
|
+
|
|
444
|
+
args = parser.parse_args()
|
|
445
|
+
|
|
446
|
+
tagger = MetadataTagger(
|
|
447
|
+
project_dir=args.project_dir,
|
|
448
|
+
dry_run=args.dry_run,
|
|
449
|
+
verbose=args.verbose
|
|
450
|
+
)
|
|
451
|
+
|
|
452
|
+
print("=" * 70)
|
|
453
|
+
print("ONE PLATFORM METADATA TAGGING")
|
|
454
|
+
print("=" * 70)
|
|
455
|
+
if args.dry_run:
|
|
456
|
+
print("[DRY RUN MODE - No files will be modified]")
|
|
457
|
+
print()
|
|
458
|
+
|
|
459
|
+
tagger.scan_and_tag_all()
|
|
460
|
+
tagger.print_summary()
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
if __name__ == "__main__":
|
|
464
|
+
main()
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Test script for validate-ontology-structure.py hook
|
|
3
|
+
|
|
4
|
+
echo "======================================================================="
|
|
5
|
+
echo "Testing Ontology Structure Validation Hook"
|
|
6
|
+
echo "======================================================================="
|
|
7
|
+
echo ""
|
|
8
|
+
|
|
9
|
+
# Color codes
|
|
10
|
+
GREEN='\033[0;32m'
|
|
11
|
+
RED='\033[0;31m'
|
|
12
|
+
YELLOW='\033[1;33m'
|
|
13
|
+
NC='\033[0m' # No Color
|
|
14
|
+
|
|
15
|
+
test_count=0
|
|
16
|
+
pass_count=0
|
|
17
|
+
fail_count=0
|
|
18
|
+
|
|
19
|
+
# Function to run a test
|
|
20
|
+
run_test() {
|
|
21
|
+
local test_name="$1"
|
|
22
|
+
local file_path="$2"
|
|
23
|
+
local expected_result="$3" # "pass" or "fail"
|
|
24
|
+
|
|
25
|
+
test_count=$((test_count + 1))
|
|
26
|
+
echo "Test $test_count: $test_name"
|
|
27
|
+
|
|
28
|
+
# Run the hook
|
|
29
|
+
output=$(python3 .claude/hooks/validate-ontology-structure.py <<EOF 2>&1
|
|
30
|
+
{
|
|
31
|
+
"hook_event_name": "PostToolUse",
|
|
32
|
+
"tool_name": "Write",
|
|
33
|
+
"tool_input": {
|
|
34
|
+
"file_path": "$file_path",
|
|
35
|
+
"content": "# Test File"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
EOF
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
exit_code=$?
|
|
42
|
+
|
|
43
|
+
# Check if test passed
|
|
44
|
+
if [ "$expected_result" = "pass" ]; then
|
|
45
|
+
# For files in /one, expect ✅ validation message
|
|
46
|
+
# For files outside /one, expect exit 0 with no output (ignored)
|
|
47
|
+
if [ $exit_code -eq 0 ]; then
|
|
48
|
+
if echo "$file_path" | grep -q "/one/"; then
|
|
49
|
+
# Files in /one should have validation output
|
|
50
|
+
if echo "$output" | grep -q "✅"; then
|
|
51
|
+
echo -e "${GREEN}✅ PASS${NC}"
|
|
52
|
+
pass_count=$((pass_count + 1))
|
|
53
|
+
else
|
|
54
|
+
echo -e "${RED}❌ FAIL${NC}"
|
|
55
|
+
echo "Expected: validation pass with ✅"
|
|
56
|
+
echo "Got exit code: $exit_code"
|
|
57
|
+
echo "Output: $output"
|
|
58
|
+
fail_count=$((fail_count + 1))
|
|
59
|
+
fi
|
|
60
|
+
else
|
|
61
|
+
# Files outside /one should be silently ignored
|
|
62
|
+
echo -e "${GREEN}✅ PASS (correctly ignored)${NC}"
|
|
63
|
+
pass_count=$((pass_count + 1))
|
|
64
|
+
fi
|
|
65
|
+
else
|
|
66
|
+
echo -e "${RED}❌ FAIL${NC}"
|
|
67
|
+
echo "Expected: exit code 0"
|
|
68
|
+
echo "Got exit code: $exit_code"
|
|
69
|
+
echo "Output: $output"
|
|
70
|
+
fail_count=$((fail_count + 1))
|
|
71
|
+
fi
|
|
72
|
+
else
|
|
73
|
+
if echo "$output" | grep -q "⚠️"; then
|
|
74
|
+
echo -e "${GREEN}✅ PASS (correctly failed validation)${NC}"
|
|
75
|
+
pass_count=$((pass_count + 1))
|
|
76
|
+
else
|
|
77
|
+
echo -e "${RED}❌ FAIL${NC}"
|
|
78
|
+
echo "Expected: validation failure"
|
|
79
|
+
echo "Got exit code: $exit_code"
|
|
80
|
+
echo "Output: $output"
|
|
81
|
+
fail_count=$((fail_count + 1))
|
|
82
|
+
fi
|
|
83
|
+
fi
|
|
84
|
+
|
|
85
|
+
echo ""
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
echo "Testing valid files in each dimension..."
|
|
89
|
+
echo ""
|
|
90
|
+
|
|
91
|
+
run_test "Valid file in /one/groups/" \
|
|
92
|
+
"/Users/toc/Server/ONE/one/groups/test-group.md" \
|
|
93
|
+
"pass"
|
|
94
|
+
|
|
95
|
+
run_test "Valid file in /one/people/" \
|
|
96
|
+
"/Users/toc/Server/ONE/one/people/test-person.md" \
|
|
97
|
+
"pass"
|
|
98
|
+
|
|
99
|
+
run_test "Valid file in /one/things/" \
|
|
100
|
+
"/Users/toc/Server/ONE/one/things/test-thing.md" \
|
|
101
|
+
"pass"
|
|
102
|
+
|
|
103
|
+
run_test "Valid file in /one/connections/" \
|
|
104
|
+
"/Users/toc/Server/ONE/one/connections/test-connection.md" \
|
|
105
|
+
"pass"
|
|
106
|
+
|
|
107
|
+
run_test "Valid file in /one/events/" \
|
|
108
|
+
"/Users/toc/Server/ONE/one/events/test-event.md" \
|
|
109
|
+
"pass"
|
|
110
|
+
|
|
111
|
+
run_test "Valid file in /one/knowledge/" \
|
|
112
|
+
"/Users/toc/Server/ONE/one/knowledge/test-knowledge.md" \
|
|
113
|
+
"pass"
|
|
114
|
+
|
|
115
|
+
echo "Testing invalid dimensions..."
|
|
116
|
+
echo ""
|
|
117
|
+
|
|
118
|
+
run_test "Invalid dimension /one/invalid/" \
|
|
119
|
+
"/Users/toc/Server/ONE/one/invalid/test.md" \
|
|
120
|
+
"fail"
|
|
121
|
+
|
|
122
|
+
run_test "File directly in /one/ (not a dimension)" \
|
|
123
|
+
"/Users/toc/Server/ONE/one/test.md" \
|
|
124
|
+
"fail"
|
|
125
|
+
|
|
126
|
+
echo "Testing invalid filenames..."
|
|
127
|
+
echo ""
|
|
128
|
+
|
|
129
|
+
run_test "Uppercase filename" \
|
|
130
|
+
"/Users/toc/Server/ONE/one/knowledge/Test_File.md" \
|
|
131
|
+
"fail"
|
|
132
|
+
|
|
133
|
+
run_test "Spaces in filename" \
|
|
134
|
+
"/Users/toc/Server/ONE/one/knowledge/test file.md" \
|
|
135
|
+
"fail"
|
|
136
|
+
|
|
137
|
+
run_test "CamelCase filename" \
|
|
138
|
+
"/Users/toc/Server/ONE/one/knowledge/TestFile.md" \
|
|
139
|
+
"fail"
|
|
140
|
+
|
|
141
|
+
echo "Testing files outside /one (should be ignored)..."
|
|
142
|
+
echo ""
|
|
143
|
+
|
|
144
|
+
run_test "File in /web (should be ignored)" \
|
|
145
|
+
"/Users/toc/Server/ONE/web/src/pages/test.astro" \
|
|
146
|
+
"pass"
|
|
147
|
+
|
|
148
|
+
run_test "File in /backend (should be ignored)" \
|
|
149
|
+
"/Users/toc/Server/ONE/backend/convex/schema.ts" \
|
|
150
|
+
"pass"
|
|
151
|
+
|
|
152
|
+
run_test "File in root (should be ignored)" \
|
|
153
|
+
"/Users/toc/Server/ONE/README.md" \
|
|
154
|
+
"pass"
|
|
155
|
+
|
|
156
|
+
echo "======================================================================="
|
|
157
|
+
echo "Test Summary"
|
|
158
|
+
echo "======================================================================="
|
|
159
|
+
echo -e "Total tests: $test_count"
|
|
160
|
+
echo -e "${GREEN}Passed: $pass_count${NC}"
|
|
161
|
+
echo -e "${RED}Failed: $fail_count${NC}"
|
|
162
|
+
echo ""
|
|
163
|
+
|
|
164
|
+
if [ $fail_count -eq 0 ]; then
|
|
165
|
+
echo -e "${GREEN}✅ All tests passed!${NC}"
|
|
166
|
+
exit 0
|
|
167
|
+
else
|
|
168
|
+
echo -e "${RED}❌ Some tests failed${NC}"
|
|
169
|
+
exit 1
|
|
170
|
+
fi
|