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,468 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ ONE Platform - Clean Agent Post-Cycle Hook
4
+ Validates cleanup and 6-dimension ontology alignment.
5
+
6
+ This hook runs after agent-clean operations to verify:
7
+ - Root directory contains ONLY approved files (README.md, LICENSE.md, SECURITY.md, CLAUDE.md, AGENTS.md)
8
+ - Documentation is organized by 6-dimension ontology (groups, people, things, connections, events, knowledge)
9
+ - No temporary artifacts or misplaced files remain
10
+ - Files have proper metadata frontmatter
11
+ - Directory structure aligns with ontology principles
12
+ """
13
+ import json
14
+ import sys
15
+ import os
16
+ from pathlib import Path
17
+ from typing import Dict, Any, List
18
+ import subprocess
19
+ import shutil
20
+ from datetime import datetime
21
+
22
+ # Temporary file patterns to clean
23
+ TEMP_PATTERNS = [
24
+ "*.tmp",
25
+ "*.swp",
26
+ "*~",
27
+ "*.bak",
28
+ ".DS_Store",
29
+ "*.log",
30
+ ]
31
+
32
+ # Directories to clean
33
+ CLEAN_DIRS = [
34
+ ".astro",
35
+ "dist",
36
+ "node_modules/.cache",
37
+ ".claude/state/temp",
38
+ ]
39
+
40
+ # Archive directory for old versions
41
+ ARCHIVE_DIR = ".claude/archive"
42
+
43
+ # Approved root directory files (ONTOLOGY POLICY)
44
+ APPROVED_ROOT_FILES = [
45
+ "README.md",
46
+ "LICENSE.md",
47
+ "SECURITY.md",
48
+ "CLAUDE.md",
49
+ "AGENTS.md",
50
+ ".gitignore",
51
+ ".env",
52
+ ".env.local",
53
+ ".env.example",
54
+ ]
55
+
56
+ # 6-Dimension Ontology Directories
57
+ ONTOLOGY_DIMENSIONS = [
58
+ "groups", # Multi-tenant isolation with hierarchical nesting
59
+ "people", # Authorization & governance
60
+ "things", # Every "thing" - users, agents, content, tokens, courses
61
+ "connections", # Every relationship - owns, follows, taught_by, powers
62
+ "events", # Every action - purchased, created, viewed, completed
63
+ "knowledge", # Labels + chunks + vectors powering RAG & search
64
+ ]
65
+
66
+
67
+ class CleanupAgent:
68
+ def __init__(self, project_dir: str):
69
+ self.project_dir = Path(project_dir)
70
+ self.actions_taken: List[str] = []
71
+ self.violations: List[str] = []
72
+ self.warnings: List[str] = []
73
+ self.files_removed: int = 0
74
+ self.files_organized: int = 0
75
+ self.files_tagged: int = 0
76
+ self.space_freed: int = 0 # in bytes
77
+ self.ontology_aligned: bool = True
78
+
79
+ def log_action(self, action: str):
80
+ """Log a cleanup action"""
81
+ self.actions_taken.append(action)
82
+
83
+ def log_violation(self, violation: str):
84
+ """Log an ontology violation"""
85
+ self.violations.append(violation)
86
+ self.ontology_aligned = False
87
+
88
+ def log_warning(self, warning: str):
89
+ """Log a warning (not critical but should be addressed)"""
90
+ self.warnings.append(warning)
91
+
92
+ def remove_temp_files(self):
93
+ """Remove temporary and backup files"""
94
+ removed = []
95
+
96
+ for pattern in TEMP_PATTERNS:
97
+ for temp_file in self.project_dir.rglob(pattern):
98
+ # Skip node_modules and .git
99
+ if "node_modules" in str(temp_file) or ".git" in str(temp_file):
100
+ continue
101
+
102
+ try:
103
+ file_size = temp_file.stat().st_size
104
+ temp_file.unlink()
105
+ removed.append(str(temp_file.relative_to(self.project_dir)))
106
+ self.space_freed += file_size
107
+ self.files_removed += 1
108
+ except Exception as e:
109
+ pass # Skip files we can't remove
110
+
111
+ if removed:
112
+ self.log_action(f"Removed {len(removed)} temporary files")
113
+ for file in removed[:5]:
114
+ self.log_action(f" • {file}")
115
+ if len(removed) > 5:
116
+ self.log_action(f" ... and {len(removed) - 5} more")
117
+
118
+ def clean_build_artifacts(self):
119
+ """Clean build and cache directories"""
120
+ for clean_dir in CLEAN_DIRS:
121
+ dir_path = self.project_dir / clean_dir
122
+ if dir_path.exists() and dir_path.is_dir():
123
+ try:
124
+ # Calculate size before deletion
125
+ total_size = sum(
126
+ f.stat().st_size
127
+ for f in dir_path.rglob("*")
128
+ if f.is_file()
129
+ )
130
+
131
+ shutil.rmtree(dir_path)
132
+ self.space_freed += total_size
133
+ self.log_action(f"Cleaned: {clean_dir} ({self._format_size(total_size)})")
134
+ except Exception:
135
+ pass # Skip if we can't clean
136
+
137
+ def validate_root_directory(self):
138
+ """Validate root directory only contains approved files (ONTOLOGY POLICY)"""
139
+ # Check for unapproved files in root
140
+ root_files = [
141
+ f for f in self.project_dir.glob("*")
142
+ if f.is_file() and not f.name.startswith(".")
143
+ ]
144
+
145
+ violations = []
146
+ for root_file in root_files:
147
+ if root_file.name not in APPROVED_ROOT_FILES:
148
+ violations.append(root_file.name)
149
+ self.log_violation(
150
+ f"POLICY VIOLATION: {root_file.name} must be moved to /one/<dimension>/"
151
+ )
152
+
153
+ if violations:
154
+ self.log_violation(
155
+ f"Root directory contains {len(violations)} unapproved file(s). "
156
+ f"Only README.md, LICENSE.md, SECURITY.md, CLAUDE.md, AGENTS.md are allowed."
157
+ )
158
+
159
+ return len(violations) == 0
160
+
161
+ def validate_ontology_structure(self):
162
+ """Validate /one directory follows 6-dimension ontology"""
163
+ one_dir = self.project_dir / "one"
164
+ if not one_dir.exists():
165
+ self.log_violation("CRITICAL: /one directory missing - 6-dimension ontology not found")
166
+ return False
167
+
168
+ # Check each dimension exists
169
+ missing_dimensions = []
170
+ for dimension in ONTOLOGY_DIMENSIONS:
171
+ dimension_path = one_dir / dimension
172
+ if not dimension_path.exists():
173
+ missing_dimensions.append(dimension)
174
+ self.log_warning(f"Dimension directory missing: /one/{dimension}/")
175
+
176
+ if missing_dimensions:
177
+ self.log_warning(
178
+ f"Missing {len(missing_dimensions)} dimension directories: {', '.join(missing_dimensions)}"
179
+ )
180
+
181
+ # Check for non-ontology directories in /one
182
+ for item in one_dir.iterdir():
183
+ if item.is_dir() and item.name not in ONTOLOGY_DIMENSIONS and not item.name.startswith("."):
184
+ self.log_warning(
185
+ f"Non-ontology directory in /one: {item.name} (should be one of: {', '.join(ONTOLOGY_DIMENSIONS)})"
186
+ )
187
+
188
+ return len(missing_dimensions) == 0
189
+
190
+ def organize_files(self):
191
+ """Organize files into correct ontology directories"""
192
+ # Check for misplaced markdown files in root
193
+ root_md_files = [
194
+ f for f in self.project_dir.glob("*.md")
195
+ if f.name not in APPROVED_ROOT_FILES
196
+ ]
197
+
198
+ for md_file in root_md_files:
199
+ # Suggest moving to one/knowledge/ (default dimension for documentation)
200
+ target_dir = self.project_dir / "one" / "knowledge"
201
+ if target_dir.exists():
202
+ try:
203
+ target_path = target_dir / md_file.name
204
+ if not target_path.exists():
205
+ shutil.move(str(md_file), str(target_path))
206
+ self.files_organized += 1
207
+ self.log_action(f"Moved: {md_file.name} → one/knowledge/ (ontology-aligned)")
208
+ except Exception:
209
+ self.log_warning(f"Could not move {md_file.name} to one/knowledge/")
210
+ pass
211
+
212
+ def update_metadata_tags(self):
213
+ """Update metadata tags on recently modified files"""
214
+ # Find markdown files modified in last cycle
215
+ recent_files = []
216
+ cutoff_time = datetime.now().timestamp() - 3600 # Last hour
217
+
218
+ for md_file in (self.project_dir / "one").rglob("*.md"):
219
+ try:
220
+ if md_file.stat().st_mtime > cutoff_time:
221
+ recent_files.append(md_file)
222
+ except Exception:
223
+ pass
224
+
225
+ # Add/update metadata tags
226
+ for md_file in recent_files:
227
+ if self._add_metadata_if_missing(md_file):
228
+ self.files_tagged += 1
229
+ self.log_action(f"Tagged: {md_file.relative_to(self.project_dir)}")
230
+
231
+ def _add_metadata_if_missing(self, file_path: Path) -> bool:
232
+ """Add metadata frontmatter if missing (ontology-aware)"""
233
+ try:
234
+ content = file_path.read_text()
235
+
236
+ # Check if already has frontmatter
237
+ if content.startswith("---\n"):
238
+ return False
239
+
240
+ # Cycle metadata from file location
241
+ relative_path = file_path.relative_to(self.project_dir)
242
+ parts = relative_path.parts
243
+
244
+ # Determine dimension and validate it's in ontology
245
+ dimension = parts[1] if len(parts) > 1 and parts[0] == "one" else "knowledge"
246
+ if dimension not in ONTOLOGY_DIMENSIONS:
247
+ self.log_warning(
248
+ f"File in non-ontology location: {relative_path} (dimension: {dimension})"
249
+ )
250
+ dimension = "knowledge" # Default fallback
251
+
252
+ category = parts[2] if len(parts) > 2 else "general"
253
+
254
+ # Ontology-specific context hints
255
+ dimension_contexts = {
256
+ "groups": "Multi-tenant isolation and hierarchical nesting",
257
+ "people": "Authorization, governance, and roles",
258
+ "things": "Entities - users, agents, content, tokens, courses",
259
+ "connections": "Relationships and protocols between entities",
260
+ "events": "Actions, state changes, and audit trails",
261
+ "knowledge": "Documentation, patterns, rules, and guides",
262
+ }
263
+
264
+ # Generate ontology-aligned metadata
265
+ metadata = f"""---
266
+ title: {file_path.stem.replace("-", " ").title()}
267
+ dimension: {dimension}
268
+ category: {category}
269
+ ontology: 6-dimension
270
+ tags: []
271
+ created: {datetime.now().strftime("%Y-%m-%d")}
272
+ updated: {datetime.now().strftime("%Y-%m-%d")}
273
+ version: 1.0.0
274
+ ai_context: |
275
+ 6-Dimension Ontology: {dimension}
276
+ Context: {dimension_contexts.get(dimension, "General documentation")}
277
+ Location: {relative_path}
278
+ For AI agents: Read this to understand {file_path.stem.replace("-", " ")}.
279
+ ---
280
+
281
+ """
282
+ # Prepend metadata
283
+ new_content = metadata + content
284
+ file_path.write_text(new_content)
285
+ return True
286
+
287
+ except Exception:
288
+ return False
289
+
290
+ def archive_old_versions(self):
291
+ """Archive old versions of files (if backup exists)"""
292
+ archive_dir = self.project_dir / ARCHIVE_DIR
293
+ archive_dir.mkdir(parents=True, exist_ok=True)
294
+
295
+ # Find .bak files and archive them
296
+ for bak_file in self.project_dir.rglob("*.bak"):
297
+ if "node_modules" in str(bak_file) or ".git" in str(bak_file):
298
+ continue
299
+
300
+ try:
301
+ # Create date-stamped archive
302
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
303
+ archive_name = f"{bak_file.stem}_{timestamp}.bak"
304
+ archive_path = archive_dir / archive_name
305
+
306
+ shutil.move(str(bak_file), str(archive_path))
307
+ self.log_action(f"Archived: {bak_file.name}")
308
+ except Exception:
309
+ pass
310
+
311
+ def _format_size(self, bytes: int) -> str:
312
+ """Format bytes as human-readable size"""
313
+ for unit in ["B", "KB", "MB", "GB"]:
314
+ if bytes < 1024:
315
+ return f"{bytes:.1f} {unit}"
316
+ bytes /= 1024
317
+ return f"{bytes:.1f} TB"
318
+
319
+ def run_cleanup(self):
320
+ """Run all cleanup operations with ontology validation"""
321
+ # Phase 1: Validate ontology structure
322
+ self.log_action("Phase 1: Validating 6-dimension ontology structure...")
323
+ self.validate_ontology_structure()
324
+ self.validate_root_directory()
325
+
326
+ # Phase 2: Clean temporary artifacts
327
+ self.log_action("Phase 2: Removing temporary artifacts...")
328
+ self.remove_temp_files()
329
+ self.clean_build_artifacts()
330
+
331
+ # Phase 3: Organize files into ontology dimensions
332
+ self.log_action("Phase 3: Organizing files into ontology dimensions...")
333
+ self.organize_files()
334
+
335
+ # Phase 4: Update metadata with ontology context
336
+ self.log_action("Phase 4: Updating metadata with ontology context...")
337
+ self.update_metadata_tags()
338
+
339
+ # Phase 5: Archive old versions
340
+ self.log_action("Phase 5: Archiving old versions...")
341
+ self.archive_old_versions()
342
+
343
+
344
+ def generate_report(agent: CleanupAgent) -> str:
345
+ """Generate cleanup report with ontology compliance status"""
346
+
347
+ # Determine ontology status icon
348
+ ontology_icon = "✅" if agent.ontology_aligned else "⚠️"
349
+ ontology_status = "ALIGNED" if agent.ontology_aligned else "VIOLATIONS FOUND"
350
+
351
+ report = f"""
352
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
353
+ 🧹 CLEANUP VALIDATION - Agent Clean Post-Cycle
354
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
355
+
356
+ {ontology_icon} ONTOLOGY STATUS: {ontology_status}
357
+ 6-Dimension Structure: groups | people | things | connections | events | knowledge
358
+
359
+ 📊 CLEANUP METRICS:
360
+ • Files Removed: {agent.files_removed}
361
+ • Files Organized: {agent.files_organized}
362
+ • Files Tagged: {agent.files_tagged}
363
+ • Space Freed: {agent._format_size(agent.space_freed)}
364
+
365
+ """
366
+
367
+ # Show violations if any
368
+ if agent.violations:
369
+ report += "🚨 ONTOLOGY VIOLATIONS:\n"
370
+ for violation in agent.violations[:5]:
371
+ report += f" • {violation}\n"
372
+ if len(agent.violations) > 5:
373
+ report += f" ... and {len(agent.violations) - 5} more violations\n"
374
+ report += "\n"
375
+
376
+ # Show warnings if any
377
+ if agent.warnings:
378
+ report += "⚠️ WARNINGS:\n"
379
+ for warning in agent.warnings[:5]:
380
+ report += f" • {warning}\n"
381
+ if len(agent.warnings) > 5:
382
+ report += f" ... and {len(agent.warnings) - 5} more warnings\n"
383
+ report += "\n"
384
+
385
+ # Show actions taken
386
+ if agent.actions_taken:
387
+ report += "✅ ACTIONS TAKEN:\n"
388
+ for action in agent.actions_taken[:10]:
389
+ report += f" {action}\n"
390
+ if len(agent.actions_taken) > 10:
391
+ report += f" ... and {len(agent.actions_taken) - 10} more actions\n"
392
+ report += "\n"
393
+ else:
394
+ report += "✨ Environment was already clean - no actions needed!\n\n"
395
+
396
+ # Next steps based on ontology compliance
397
+ if agent.ontology_aligned:
398
+ report += """━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
399
+ 💡 NEXT STEPS:
400
+ ✅ Ontology structure validated (6 dimensions)
401
+ ✅ Root directory contains only approved files
402
+ ✅ Documentation organized by ontology dimensions
403
+ ✅ Temporary artifacts removed
404
+ ✅ Ready for next cycle
405
+
406
+ 🔄 Run /done to advance to next cycle
407
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
408
+ """
409
+ else:
410
+ report += """━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
411
+ ⚠️ ACTION REQUIRED:
412
+ • Fix ontology violations before proceeding
413
+ • Move misplaced files to /one/<dimension>/
414
+ • Ensure root directory contains only approved files
415
+ • Run cleanup again after fixes
416
+
417
+ 📖 Reference: /one/knowledge/ontology.md
418
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
419
+ """
420
+
421
+ return report
422
+
423
+
424
+ def main():
425
+ try:
426
+ # Load hook input from stdin
427
+ input_data = json.load(sys.stdin)
428
+
429
+ # Get project directory
430
+ project_dir = os.environ.get("CLAUDE_PROJECT_DIR", ".")
431
+
432
+ # Run cleanup
433
+ agent = CleanupAgent(project_dir)
434
+ agent.run_cleanup()
435
+
436
+ # Generate report
437
+ report = generate_report(agent)
438
+
439
+ # Save cleanup metrics
440
+ state_file = Path(project_dir) / ".claude" / "state" / "cleanup_metrics.json"
441
+ state_file.parent.mkdir(parents=True, exist_ok=True)
442
+
443
+ metrics = {
444
+ "last_cleanup": datetime.now().isoformat(),
445
+ "ontology_aligned": agent.ontology_aligned,
446
+ "violations": agent.violations,
447
+ "warnings": agent.warnings,
448
+ "files_removed": agent.files_removed,
449
+ "files_organized": agent.files_organized,
450
+ "files_tagged": agent.files_tagged,
451
+ "space_freed": agent.space_freed,
452
+ "actions": agent.actions_taken
453
+ }
454
+
455
+ state_file.write_text(json.dumps(metrics, indent=2))
456
+
457
+ # Output report
458
+ print(report)
459
+ sys.exit(0)
460
+
461
+ except Exception as e:
462
+ # Don't block on hook errors
463
+ print(f"Error in clean-post hook: {e}", file=sys.stderr)
464
+ sys.exit(0)
465
+
466
+
467
+ if __name__ == "__main__":
468
+ main()