oneie 3.6.5 ā 3.6.7
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/commands/onboard.md +179 -0
- package/.claude/commands/one copy.md +565 -0
- package/.claude/commands/one.md +125 -487
- package/.claude/commands/server.md +333 -0
- package/.claude/hooks/README-knowledge-hooks.md +265 -0
- package/.claude/hooks/__pycache__/knowledge-post.cpython-313.pyc +0 -0
- package/.claude/hooks/__pycache__/knowledge-pre.cpython-313.pyc +0 -0
- package/.claude/hooks/__pycache__/todo.cpython-313.pyc +0 -0
- package/.claude/hooks/check-filenames.py +40 -0
- package/.claude/hooks/clean-post.py +301 -0
- package/.claude/hooks/clean-pre.py +308 -0
- package/.claude/hooks/done.py +175 -0
- package/.claude/hooks/format-hook.sh +75 -0
- package/.claude/hooks/hook-logger.sh +59 -0
- package/.claude/hooks/knowledge-post.py +251 -0
- package/.claude/hooks/knowledge-pre.py +150 -0
- package/.claude/hooks/notification-hook.sh +112 -0
- package/.claude/hooks/security-hook.sh +157 -0
- package/.claude/hooks/tag-all-docs.py +338 -0
- package/.claude/hooks/todo.py +298 -0
- package/.claude/hooks/validate-ontology-structure.py +455 -0
- package/.claude/skills/astro/add-content-collection.md +30 -0
- package/.claude/skills/astro/check-build.md +29 -0
- package/.claude/skills/astro/create-component.md +29 -0
- package/.claude/skills/astro/create-page.md +30 -0
- package/.claude/skills/astro/optimize-performance.md +21 -0
- package/.claude/skills/convex/check-deployment.md +46 -0
- package/.claude/skills/convex/create-mutation.md +405 -0
- package/.claude/skills/convex/create-query.md +52 -0
- package/.claude/skills/convex/read-schema.md +373 -0
- package/.claude/skills/convex/test-function.md +50 -0
- package/.claude/skills/deployment/check-deployment-health.md +20 -0
- package/.claude/skills/deployment/create-release.md +21 -0
- package/.claude/skills/deployment/deploy-cloudflare.md +31 -0
- package/.claude/skills/deployment/deploy-convex.md +30 -0
- package/.claude/skills/deployment/sync-repositories.md +19 -0
- package/.claude/skills/design/check-accessibility.md +21 -0
- package/.claude/skills/design/create-component-spec.md +27 -0
- package/.claude/skills/design/generate-design-tokens.md +24 -0
- package/.claude/skills/design/generate-wireframe.md +30 -0
- package/.claude/skills/documentation/create-migration-guide.md +20 -0
- package/.claude/skills/documentation/generate-api-docs.md +27 -0
- package/.claude/skills/documentation/generate-readme.md +22 -0
- package/.claude/skills/documentation/update-knowledge.md +20 -0
- package/.claude/skills/integration/connect-external-system.md +21 -0
- package/.claude/skills/integration/implement-a2a.md +20 -0
- package/.claude/skills/integration/implement-acp.md +20 -0
- package/.claude/skills/integration/verify-integration.md +20 -0
- package/.claude/skills/ontology/README.md +255 -0
- package/.claude/skills/ontology/check-dimension.md +307 -0
- package/.claude/skills/ontology/generate-entity-type.md +339 -0
- package/.claude/skills/ontology/validate-schema.md +229 -0
- package/.claude/skills/ontology/verify-relationships.md +310 -0
- package/.claude/skills/problem-solving/analyze-test-failure.md +21 -0
- package/.claude/skills/problem-solving/identify-root-cause.md +20 -0
- package/.claude/skills/problem-solving/propose-solution.md +29 -0
- package/.claude/skills/problem-solving/verify-fix.md +21 -0
- package/.claude/skills/sales/generate-demo-script.md +21 -0
- package/.claude/skills/sales/qualify-lead.md +30 -0
- package/.claude/skills/sales/track-trial.md +20 -0
- package/.claude/skills/sales/verify-kyc.md +20 -0
- package/.claude/skills/testing/analyze-coverage.md +24 -0
- package/.claude/skills/testing/generate-tests.md +24 -0
- package/.claude/skills/testing/run-tests.md +27 -0
- package/.claude/skills/testing/validate-e2e.md +25 -0
- package/.mcp.json +30 -3
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +13 -6
- package/dist/commands/init.js.map +1 -1
- package/dist/utils/launch-claude.d.ts +3 -2
- package/dist/utils/launch-claude.d.ts.map +1 -1
- package/dist/utils/launch-claude.js +64 -29
- package/dist/utils/launch-claude.js.map +1 -1
- package/folders.yaml +1 -1
- package/one/.obsidian/workspace.json +22 -22
- package/one/events/CREATE-WEBSITE.md +442 -0
- package/one/events/CUSTOM-DOMAIN.md +357 -0
- package/one/events/DEPLOYMENT copy.md +426 -0
- package/one/events/ECOMMERCE-BEFORE-AFTER.md +251 -0
- package/one/events/ECOMMERCE-ENHANCEMENTS.md +576 -0
- package/one/events/ECOMMERCE-HIGH-CONVERTING-ELEMENTS.md +421 -0
- package/one/events/ECOMMERCE-REFACTOR-SUMMARY.md +196 -0
- package/one/events/ECOMMERCE-SETUP-SUMMARY.md +396 -0
- package/one/events/INSTALLATION_FOLDERS.md +516 -0
- package/one/events/INSTALLATION_FOLDERS_FILES.md +205 -0
- package/one/events/INSTALLATION_FOLDERS_SUMMARY.md +419 -0
- package/one/events/LICENSE.md +89 -0
- package/one/events/MCP-CONFIGURATION.md +336 -0
- package/one/events/MCP-SETUP-COMPLETE.md +205 -0
- package/one/events/NODE-UPGRADE.md +111 -0
- package/one/events/PACKAGE-STRUCTURE.md +310 -0
- package/one/events/PLAYBOOK-SETUP-SUMMARY.md +331 -0
- package/one/events/PROMPT_FIX_FRONTEND_ONLY.md +567 -0
- package/one/events/SIMPLE_FIX_FRONTEND_ONLY.md +262 -0
- package/one/events/STRIPE-INTEGRATION.md +414 -0
- package/one/events/STRIPE-SETUP-GUIDE.md +462 -0
- package/one/events/TRANSPARENCY-FIXES.md +275 -0
- package/package.json +4 -2
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
ONE Platform - Clean Agent Post-Inference Hook
|
|
4
|
+
Cleans up and organizes after completing each inference.
|
|
5
|
+
|
|
6
|
+
This hook runs after inference completion to:
|
|
7
|
+
- Remove generated artifacts and temporary files
|
|
8
|
+
- Organize files into correct directories
|
|
9
|
+
- Update metadata tags on modified files
|
|
10
|
+
- Archive old versions
|
|
11
|
+
- Generate cleanup report
|
|
12
|
+
- Update cleanliness metrics
|
|
13
|
+
"""
|
|
14
|
+
import json
|
|
15
|
+
import sys
|
|
16
|
+
import os
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Dict, Any, List
|
|
19
|
+
import subprocess
|
|
20
|
+
import shutil
|
|
21
|
+
from datetime import datetime
|
|
22
|
+
|
|
23
|
+
# Temporary file patterns to clean
|
|
24
|
+
TEMP_PATTERNS = [
|
|
25
|
+
"*.tmp",
|
|
26
|
+
"*.swp",
|
|
27
|
+
"*~",
|
|
28
|
+
"*.bak",
|
|
29
|
+
".DS_Store",
|
|
30
|
+
"*.log",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
# Directories to clean
|
|
34
|
+
CLEAN_DIRS = [
|
|
35
|
+
".astro",
|
|
36
|
+
"dist",
|
|
37
|
+
"node_modules/.cache",
|
|
38
|
+
".claude/state/temp",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
# Archive directory for old versions
|
|
42
|
+
ARCHIVE_DIR = ".claude/archive"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class CleanupAgent:
|
|
46
|
+
def __init__(self, project_dir: str):
|
|
47
|
+
self.project_dir = Path(project_dir)
|
|
48
|
+
self.actions_taken: List[str] = []
|
|
49
|
+
self.files_removed: int = 0
|
|
50
|
+
self.files_organized: int = 0
|
|
51
|
+
self.files_tagged: int = 0
|
|
52
|
+
self.space_freed: int = 0 # in bytes
|
|
53
|
+
|
|
54
|
+
def log_action(self, action: str):
|
|
55
|
+
"""Log a cleanup action"""
|
|
56
|
+
self.actions_taken.append(action)
|
|
57
|
+
|
|
58
|
+
def remove_temp_files(self):
|
|
59
|
+
"""Remove temporary and backup files"""
|
|
60
|
+
removed = []
|
|
61
|
+
|
|
62
|
+
for pattern in TEMP_PATTERNS:
|
|
63
|
+
for temp_file in self.project_dir.rglob(pattern):
|
|
64
|
+
# Skip node_modules and .git
|
|
65
|
+
if "node_modules" in str(temp_file) or ".git" in str(temp_file):
|
|
66
|
+
continue
|
|
67
|
+
|
|
68
|
+
try:
|
|
69
|
+
file_size = temp_file.stat().st_size
|
|
70
|
+
temp_file.unlink()
|
|
71
|
+
removed.append(str(temp_file.relative_to(self.project_dir)))
|
|
72
|
+
self.space_freed += file_size
|
|
73
|
+
self.files_removed += 1
|
|
74
|
+
except Exception as e:
|
|
75
|
+
pass # Skip files we can't remove
|
|
76
|
+
|
|
77
|
+
if removed:
|
|
78
|
+
self.log_action(f"Removed {len(removed)} temporary files")
|
|
79
|
+
for file in removed[:5]:
|
|
80
|
+
self.log_action(f" ⢠{file}")
|
|
81
|
+
if len(removed) > 5:
|
|
82
|
+
self.log_action(f" ... and {len(removed) - 5} more")
|
|
83
|
+
|
|
84
|
+
def clean_build_artifacts(self):
|
|
85
|
+
"""Clean build and cache directories"""
|
|
86
|
+
for clean_dir in CLEAN_DIRS:
|
|
87
|
+
dir_path = self.project_dir / clean_dir
|
|
88
|
+
if dir_path.exists() and dir_path.is_dir():
|
|
89
|
+
try:
|
|
90
|
+
# Calculate size before deletion
|
|
91
|
+
total_size = sum(
|
|
92
|
+
f.stat().st_size
|
|
93
|
+
for f in dir_path.rglob("*")
|
|
94
|
+
if f.is_file()
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
shutil.rmtree(dir_path)
|
|
98
|
+
self.space_freed += total_size
|
|
99
|
+
self.log_action(f"Cleaned: {clean_dir} ({self._format_size(total_size)})")
|
|
100
|
+
except Exception:
|
|
101
|
+
pass # Skip if we can't clean
|
|
102
|
+
|
|
103
|
+
def organize_files(self):
|
|
104
|
+
"""Organize files into correct directories"""
|
|
105
|
+
# Check for misplaced markdown files
|
|
106
|
+
root_md_files = [
|
|
107
|
+
f for f in self.project_dir.glob("*.md")
|
|
108
|
+
if f.name not in ["README.md", "CLAUDE.md", "AGENTS.md", "LICENSE.md", "CHANGELOG.md"]
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
for md_file in root_md_files:
|
|
112
|
+
# Suggest moving to one/knowledge/
|
|
113
|
+
target_dir = self.project_dir / "one" / "knowledge"
|
|
114
|
+
if target_dir.exists():
|
|
115
|
+
try:
|
|
116
|
+
target_path = target_dir / md_file.name
|
|
117
|
+
if not target_path.exists():
|
|
118
|
+
shutil.move(str(md_file), str(target_path))
|
|
119
|
+
self.files_organized += 1
|
|
120
|
+
self.log_action(f"Moved: {md_file.name} ā one/knowledge/")
|
|
121
|
+
except Exception:
|
|
122
|
+
pass
|
|
123
|
+
|
|
124
|
+
def update_metadata_tags(self):
|
|
125
|
+
"""Update metadata tags on recently modified files"""
|
|
126
|
+
# Find markdown files modified in last inference
|
|
127
|
+
recent_files = []
|
|
128
|
+
cutoff_time = datetime.now().timestamp() - 3600 # Last hour
|
|
129
|
+
|
|
130
|
+
for md_file in (self.project_dir / "one").rglob("*.md"):
|
|
131
|
+
try:
|
|
132
|
+
if md_file.stat().st_mtime > cutoff_time:
|
|
133
|
+
recent_files.append(md_file)
|
|
134
|
+
except Exception:
|
|
135
|
+
pass
|
|
136
|
+
|
|
137
|
+
# Add/update metadata tags
|
|
138
|
+
for md_file in recent_files:
|
|
139
|
+
if self._add_metadata_if_missing(md_file):
|
|
140
|
+
self.files_tagged += 1
|
|
141
|
+
self.log_action(f"Tagged: {md_file.relative_to(self.project_dir)}")
|
|
142
|
+
|
|
143
|
+
def _add_metadata_if_missing(self, file_path: Path) -> bool:
|
|
144
|
+
"""Add metadata frontmatter if missing"""
|
|
145
|
+
try:
|
|
146
|
+
content = file_path.read_text()
|
|
147
|
+
|
|
148
|
+
# Check if already has frontmatter
|
|
149
|
+
if content.startswith("---\n"):
|
|
150
|
+
return False
|
|
151
|
+
|
|
152
|
+
# Infer metadata from file location
|
|
153
|
+
relative_path = file_path.relative_to(self.project_dir)
|
|
154
|
+
parts = relative_path.parts
|
|
155
|
+
|
|
156
|
+
# Determine dimension and tags
|
|
157
|
+
dimension = parts[1] if len(parts) > 1 else "knowledge"
|
|
158
|
+
category = parts[2] if len(parts) > 2 else "general"
|
|
159
|
+
|
|
160
|
+
# Generate metadata
|
|
161
|
+
metadata = f"""---
|
|
162
|
+
title: {file_path.stem.replace("-", " ").title()}
|
|
163
|
+
dimension: {dimension}
|
|
164
|
+
category: {category}
|
|
165
|
+
tags: []
|
|
166
|
+
created: {datetime.now().strftime("%Y-%m-%d")}
|
|
167
|
+
updated: {datetime.now().strftime("%Y-%m-%d")}
|
|
168
|
+
version: 1.0.0
|
|
169
|
+
ai_context: |
|
|
170
|
+
This document is part of the {dimension} dimension.
|
|
171
|
+
Location: {relative_path}
|
|
172
|
+
For AI agents: Read this to understand {file_path.stem.replace("-", " ")}.
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
"""
|
|
176
|
+
# Prepend metadata
|
|
177
|
+
new_content = metadata + content
|
|
178
|
+
file_path.write_text(new_content)
|
|
179
|
+
return True
|
|
180
|
+
|
|
181
|
+
except Exception:
|
|
182
|
+
return False
|
|
183
|
+
|
|
184
|
+
def archive_old_versions(self):
|
|
185
|
+
"""Archive old versions of files (if backup exists)"""
|
|
186
|
+
archive_dir = self.project_dir / ARCHIVE_DIR
|
|
187
|
+
archive_dir.mkdir(parents=True, exist_ok=True)
|
|
188
|
+
|
|
189
|
+
# Find .bak files and archive them
|
|
190
|
+
for bak_file in self.project_dir.rglob("*.bak"):
|
|
191
|
+
if "node_modules" in str(bak_file) or ".git" in str(bak_file):
|
|
192
|
+
continue
|
|
193
|
+
|
|
194
|
+
try:
|
|
195
|
+
# Create date-stamped archive
|
|
196
|
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
197
|
+
archive_name = f"{bak_file.stem}_{timestamp}.bak"
|
|
198
|
+
archive_path = archive_dir / archive_name
|
|
199
|
+
|
|
200
|
+
shutil.move(str(bak_file), str(archive_path))
|
|
201
|
+
self.log_action(f"Archived: {bak_file.name}")
|
|
202
|
+
except Exception:
|
|
203
|
+
pass
|
|
204
|
+
|
|
205
|
+
def _format_size(self, bytes: int) -> str:
|
|
206
|
+
"""Format bytes as human-readable size"""
|
|
207
|
+
for unit in ["B", "KB", "MB", "GB"]:
|
|
208
|
+
if bytes < 1024:
|
|
209
|
+
return f"{bytes:.1f} {unit}"
|
|
210
|
+
bytes /= 1024
|
|
211
|
+
return f"{bytes:.1f} TB"
|
|
212
|
+
|
|
213
|
+
def run_cleanup(self):
|
|
214
|
+
"""Run all cleanup operations"""
|
|
215
|
+
self.remove_temp_files()
|
|
216
|
+
self.clean_build_artifacts()
|
|
217
|
+
self.organize_files()
|
|
218
|
+
self.update_metadata_tags()
|
|
219
|
+
self.archive_old_versions()
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def generate_report(agent: CleanupAgent) -> str:
|
|
223
|
+
"""Generate cleanup report"""
|
|
224
|
+
report = f"""
|
|
225
|
+
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
226
|
+
š§¹ CLEANUP COMPLETE - Agent Clean Post-Inference
|
|
227
|
+
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
228
|
+
|
|
229
|
+
š CLEANUP METRICS:
|
|
230
|
+
⢠Files Removed: {agent.files_removed}
|
|
231
|
+
⢠Files Organized: {agent.files_organized}
|
|
232
|
+
⢠Files Tagged: {agent.files_tagged}
|
|
233
|
+
⢠Space Freed: {agent._format_size(agent.space_freed)}
|
|
234
|
+
|
|
235
|
+
"""
|
|
236
|
+
|
|
237
|
+
if agent.actions_taken:
|
|
238
|
+
report += "ā
ACTIONS TAKEN:\n"
|
|
239
|
+
for action in agent.actions_taken[:10]:
|
|
240
|
+
report += f" {action}\n"
|
|
241
|
+
if len(agent.actions_taken) > 10:
|
|
242
|
+
report += f" ... and {len(agent.actions_taken) - 10} more actions\n"
|
|
243
|
+
else:
|
|
244
|
+
report += "⨠Environment was already clean - no actions needed!\n"
|
|
245
|
+
|
|
246
|
+
report += """
|
|
247
|
+
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
248
|
+
š” NEXT STEPS:
|
|
249
|
+
⢠Files are organized and tagged
|
|
250
|
+
⢠Temporary artifacts removed
|
|
251
|
+
⢠Ready for next inference
|
|
252
|
+
|
|
253
|
+
š Run /done to advance to next inference
|
|
254
|
+
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
255
|
+
"""
|
|
256
|
+
|
|
257
|
+
return report
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def main():
|
|
261
|
+
try:
|
|
262
|
+
# Load hook input from stdin
|
|
263
|
+
input_data = json.load(sys.stdin)
|
|
264
|
+
|
|
265
|
+
# Get project directory
|
|
266
|
+
project_dir = os.environ.get("CLAUDE_PROJECT_DIR", ".")
|
|
267
|
+
|
|
268
|
+
# Run cleanup
|
|
269
|
+
agent = CleanupAgent(project_dir)
|
|
270
|
+
agent.run_cleanup()
|
|
271
|
+
|
|
272
|
+
# Generate report
|
|
273
|
+
report = generate_report(agent)
|
|
274
|
+
|
|
275
|
+
# Save cleanup metrics
|
|
276
|
+
state_file = Path(project_dir) / ".claude" / "state" / "cleanup_metrics.json"
|
|
277
|
+
state_file.parent.mkdir(parents=True, exist_ok=True)
|
|
278
|
+
|
|
279
|
+
metrics = {
|
|
280
|
+
"last_cleanup": datetime.now().isoformat(),
|
|
281
|
+
"files_removed": agent.files_removed,
|
|
282
|
+
"files_organized": agent.files_organized,
|
|
283
|
+
"files_tagged": agent.files_tagged,
|
|
284
|
+
"space_freed": agent.space_freed,
|
|
285
|
+
"actions": agent.actions_taken
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
state_file.write_text(json.dumps(metrics, indent=2))
|
|
289
|
+
|
|
290
|
+
# Output report
|
|
291
|
+
print(report)
|
|
292
|
+
sys.exit(0)
|
|
293
|
+
|
|
294
|
+
except Exception as e:
|
|
295
|
+
# Don't block on hook errors
|
|
296
|
+
print(f"Error in clean-post hook: {e}", file=sys.stderr)
|
|
297
|
+
sys.exit(0)
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
if __name__ == "__main__":
|
|
301
|
+
main()
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
ONE Platform - Clean Agent Pre-Inference Hook
|
|
4
|
+
Validates cleanliness before starting each inference.
|
|
5
|
+
|
|
6
|
+
This hook runs before UserPromptSubmit to ensure:
|
|
7
|
+
- File structure is intact
|
|
8
|
+
- No orphaned files exist
|
|
9
|
+
- Naming conventions are followed
|
|
10
|
+
- Documentation is up to date
|
|
11
|
+
- No uncommitted critical changes
|
|
12
|
+
- Metadata tags are present on all docs
|
|
13
|
+
"""
|
|
14
|
+
import json
|
|
15
|
+
import sys
|
|
16
|
+
import os
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Dict, Any, List, Tuple
|
|
19
|
+
import subprocess
|
|
20
|
+
import re
|
|
21
|
+
|
|
22
|
+
# Critical directories that must exist
|
|
23
|
+
REQUIRED_DIRS = [
|
|
24
|
+
"one/connections",
|
|
25
|
+
"one/events",
|
|
26
|
+
"one/knowledge",
|
|
27
|
+
"one/things",
|
|
28
|
+
"one/people",
|
|
29
|
+
"one/groups",
|
|
30
|
+
".claude/hooks",
|
|
31
|
+
".claude/state",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
# File naming conventions
|
|
35
|
+
NAMING_PATTERNS = {
|
|
36
|
+
".md": r"^[a-z0-9\-]+\.md$", # kebab-case for markdown
|
|
37
|
+
".ts": r"^[a-z0-9\-]+\.ts$", # kebab-case for TypeScript
|
|
38
|
+
".tsx": r"^[A-Z][a-zA-Z0-9]+\.tsx$", # PascalCase for React components
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
# Files that should have metadata frontmatter
|
|
42
|
+
METADATA_REQUIRED_PATTERNS = [
|
|
43
|
+
"one/**/*.md",
|
|
44
|
+
"CLAUDE.md",
|
|
45
|
+
"AGENTS.md",
|
|
46
|
+
"README.md",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class CleanlinessValidator:
|
|
51
|
+
def __init__(self, project_dir: str):
|
|
52
|
+
self.project_dir = Path(project_dir)
|
|
53
|
+
self.issues: List[Tuple[str, str]] = [] # (severity, message)
|
|
54
|
+
self.warnings: List[str] = []
|
|
55
|
+
self.metrics: Dict[str, Any] = {}
|
|
56
|
+
|
|
57
|
+
def add_issue(self, severity: str, message: str):
|
|
58
|
+
"""Add a cleanliness issue"""
|
|
59
|
+
self.issues.append((severity, message))
|
|
60
|
+
|
|
61
|
+
def add_warning(self, message: str):
|
|
62
|
+
"""Add a warning"""
|
|
63
|
+
self.warnings.append(message)
|
|
64
|
+
|
|
65
|
+
def validate_directory_structure(self):
|
|
66
|
+
"""Check that all required directories exist"""
|
|
67
|
+
for dir_path in REQUIRED_DIRS:
|
|
68
|
+
full_path = self.project_dir / dir_path
|
|
69
|
+
if not full_path.exists():
|
|
70
|
+
self.add_issue("error", f"Missing required directory: {dir_path}")
|
|
71
|
+
elif not full_path.is_dir():
|
|
72
|
+
self.add_issue("error", f"Path exists but is not a directory: {dir_path}")
|
|
73
|
+
|
|
74
|
+
def validate_file_naming(self):
|
|
75
|
+
"""Check that files follow naming conventions"""
|
|
76
|
+
problematic_files = []
|
|
77
|
+
|
|
78
|
+
# Check markdown files in one/
|
|
79
|
+
for md_file in (self.project_dir / "one").rglob("*.md"):
|
|
80
|
+
if not re.match(NAMING_PATTERNS[".md"], md_file.name):
|
|
81
|
+
problematic_files.append(str(md_file.relative_to(self.project_dir)))
|
|
82
|
+
|
|
83
|
+
if problematic_files:
|
|
84
|
+
self.add_warning(f"Files not following kebab-case convention: {', '.join(problematic_files[:5])}")
|
|
85
|
+
if len(problematic_files) > 5:
|
|
86
|
+
self.add_warning(f"... and {len(problematic_files) - 5} more")
|
|
87
|
+
|
|
88
|
+
def find_orphaned_files(self):
|
|
89
|
+
"""Find files that don't belong anywhere"""
|
|
90
|
+
orphans = []
|
|
91
|
+
|
|
92
|
+
# Check for common temporary/generated files
|
|
93
|
+
temp_patterns = ["*.tmp", "*.swp", "*.bak", "*.DS_Store", "*~"]
|
|
94
|
+
for pattern in temp_patterns:
|
|
95
|
+
for temp_file in self.project_dir.rglob(pattern):
|
|
96
|
+
# Skip node_modules and .git
|
|
97
|
+
if "node_modules" not in str(temp_file) and ".git" not in str(temp_file):
|
|
98
|
+
orphans.append(str(temp_file.relative_to(self.project_dir)))
|
|
99
|
+
|
|
100
|
+
if orphans:
|
|
101
|
+
self.add_warning(f"Found {len(orphans)} temporary/backup files that should be cleaned")
|
|
102
|
+
for orphan in orphans[:3]:
|
|
103
|
+
self.add_warning(f" - {orphan}")
|
|
104
|
+
|
|
105
|
+
def check_metadata_tags(self):
|
|
106
|
+
"""Check that documentation files have metadata frontmatter"""
|
|
107
|
+
missing_metadata = []
|
|
108
|
+
|
|
109
|
+
# Check markdown files in one/
|
|
110
|
+
for md_file in (self.project_dir / "one").rglob("*.md"):
|
|
111
|
+
try:
|
|
112
|
+
content = md_file.read_text()
|
|
113
|
+
# Check for YAML frontmatter
|
|
114
|
+
if not content.startswith("---\n"):
|
|
115
|
+
missing_metadata.append(str(md_file.relative_to(self.project_dir)))
|
|
116
|
+
else:
|
|
117
|
+
# Validate frontmatter has required fields
|
|
118
|
+
frontmatter_end = content.find("\n---\n", 4)
|
|
119
|
+
if frontmatter_end == -1:
|
|
120
|
+
missing_metadata.append(str(md_file.relative_to(self.project_dir)))
|
|
121
|
+
except Exception:
|
|
122
|
+
pass # Skip files we can't read
|
|
123
|
+
|
|
124
|
+
self.metrics["files_without_metadata"] = len(missing_metadata)
|
|
125
|
+
|
|
126
|
+
if missing_metadata:
|
|
127
|
+
self.add_warning(f"{len(missing_metadata)} files missing metadata tags")
|
|
128
|
+
|
|
129
|
+
def check_git_status(self):
|
|
130
|
+
"""Check for uncommitted changes in critical files"""
|
|
131
|
+
try:
|
|
132
|
+
# Only check if we're in a git repo
|
|
133
|
+
if not (self.project_dir / ".git").exists():
|
|
134
|
+
return
|
|
135
|
+
|
|
136
|
+
result = subprocess.run(
|
|
137
|
+
["git", "status", "--porcelain"],
|
|
138
|
+
cwd=self.project_dir,
|
|
139
|
+
capture_output=True,
|
|
140
|
+
text=True,
|
|
141
|
+
timeout=5
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
if result.returncode == 0 and result.stdout:
|
|
145
|
+
lines = result.stdout.strip().split("\n")
|
|
146
|
+
critical_changes = [
|
|
147
|
+
line for line in lines
|
|
148
|
+
if any(pattern in line for pattern in ["CLAUDE.md", "AGENTS.md", "schema.ts"])
|
|
149
|
+
]
|
|
150
|
+
|
|
151
|
+
if critical_changes:
|
|
152
|
+
self.add_warning(f"Uncommitted changes in {len(critical_changes)} critical files")
|
|
153
|
+
|
|
154
|
+
self.metrics["uncommitted_files"] = len(lines)
|
|
155
|
+
except Exception:
|
|
156
|
+
pass # Skip if git check fails
|
|
157
|
+
|
|
158
|
+
def calculate_cleanliness_score(self) -> int:
|
|
159
|
+
"""Calculate overall cleanliness score (0-100)"""
|
|
160
|
+
score = 100
|
|
161
|
+
|
|
162
|
+
# Deduct points for issues
|
|
163
|
+
for severity, _ in self.issues:
|
|
164
|
+
if severity == "error":
|
|
165
|
+
score -= 10
|
|
166
|
+
elif severity == "warning":
|
|
167
|
+
score -= 5
|
|
168
|
+
|
|
169
|
+
# Deduct for warnings
|
|
170
|
+
score -= len(self.warnings) * 2
|
|
171
|
+
|
|
172
|
+
# Bonus for good metrics
|
|
173
|
+
if self.metrics.get("files_without_metadata", 0) == 0:
|
|
174
|
+
score += 5
|
|
175
|
+
if self.metrics.get("uncommitted_files", 0) == 0:
|
|
176
|
+
score += 5
|
|
177
|
+
|
|
178
|
+
return max(0, min(100, score))
|
|
179
|
+
|
|
180
|
+
def run_all_checks(self):
|
|
181
|
+
"""Run all cleanliness validation checks"""
|
|
182
|
+
self.validate_directory_structure()
|
|
183
|
+
self.validate_file_naming()
|
|
184
|
+
self.find_orphaned_files()
|
|
185
|
+
self.check_metadata_tags()
|
|
186
|
+
self.check_git_status()
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def generate_report(validator: CleanlinessValidator) -> str:
|
|
190
|
+
"""Generate cleanliness report"""
|
|
191
|
+
score = validator.calculate_cleanliness_score()
|
|
192
|
+
|
|
193
|
+
# Determine status emoji
|
|
194
|
+
if score >= 90:
|
|
195
|
+
status = "⨠Excellent"
|
|
196
|
+
color = "š¢"
|
|
197
|
+
elif score >= 70:
|
|
198
|
+
status = "š Good"
|
|
199
|
+
color = "š”"
|
|
200
|
+
elif score >= 50:
|
|
201
|
+
status = "ā ļø Needs Attention"
|
|
202
|
+
color = "š "
|
|
203
|
+
else:
|
|
204
|
+
status = "š“ Critical Issues"
|
|
205
|
+
color = "š“"
|
|
206
|
+
|
|
207
|
+
report = f"""
|
|
208
|
+
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
209
|
+
{color} CLEANLINESS VALIDATION - {status} ({score}/100)
|
|
210
|
+
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
211
|
+
"""
|
|
212
|
+
|
|
213
|
+
# Show errors
|
|
214
|
+
errors = [issue for issue in validator.issues if issue[0] == "error"]
|
|
215
|
+
if errors:
|
|
216
|
+
report += "\nš“ ERRORS:\n"
|
|
217
|
+
for _, message in errors:
|
|
218
|
+
report += f" ⢠{message}\n"
|
|
219
|
+
|
|
220
|
+
# Show warnings
|
|
221
|
+
if validator.warnings:
|
|
222
|
+
report += "\nā ļø WARNINGS:\n"
|
|
223
|
+
for warning in validator.warnings[:5]: # Limit to 5
|
|
224
|
+
report += f" ⢠{warning}\n"
|
|
225
|
+
if len(validator.warnings) > 5:
|
|
226
|
+
report += f" ... and {len(validator.warnings) - 5} more warnings\n"
|
|
227
|
+
|
|
228
|
+
# Show metrics
|
|
229
|
+
if validator.metrics:
|
|
230
|
+
report += "\nš METRICS:\n"
|
|
231
|
+
for key, value in validator.metrics.items():
|
|
232
|
+
formatted_key = key.replace("_", " ").title()
|
|
233
|
+
report += f" ⢠{formatted_key}: {value}\n"
|
|
234
|
+
|
|
235
|
+
# Show clean status
|
|
236
|
+
if not errors and not validator.warnings:
|
|
237
|
+
report += "\nā
Everything is clean! Ready to proceed.\n"
|
|
238
|
+
|
|
239
|
+
report += "\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n"
|
|
240
|
+
|
|
241
|
+
# Add recommendations
|
|
242
|
+
if score < 90:
|
|
243
|
+
report += "\nš” RECOMMENDATIONS:\n"
|
|
244
|
+
if validator.metrics.get("files_without_metadata", 0) > 0:
|
|
245
|
+
report += " ⢠Run: Add metadata tags to documentation files\n"
|
|
246
|
+
if validator.metrics.get("uncommitted_files", 0) > 0:
|
|
247
|
+
report += " ⢠Run: git add . && git commit -m 'chore: clean up'\n"
|
|
248
|
+
if any(issue[0] == "error" for issue in validator.issues):
|
|
249
|
+
report += " ⢠Fix critical errors before proceeding with inference\n"
|
|
250
|
+
report += "\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n"
|
|
251
|
+
|
|
252
|
+
return report
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def main():
|
|
256
|
+
try:
|
|
257
|
+
# Load hook input from stdin
|
|
258
|
+
input_data = json.load(sys.stdin)
|
|
259
|
+
prompt = input_data.get("prompt", "")
|
|
260
|
+
|
|
261
|
+
# Get project directory
|
|
262
|
+
project_dir = os.environ.get("CLAUDE_PROJECT_DIR", ".")
|
|
263
|
+
|
|
264
|
+
# Skip validation for workflow commands
|
|
265
|
+
if prompt.strip().startswith("/"):
|
|
266
|
+
sys.exit(0)
|
|
267
|
+
|
|
268
|
+
# Run validation
|
|
269
|
+
validator = CleanlinessValidator(project_dir)
|
|
270
|
+
validator.run_all_checks()
|
|
271
|
+
|
|
272
|
+
# Generate report
|
|
273
|
+
report = generate_report(validator)
|
|
274
|
+
|
|
275
|
+
# Determine if we should block
|
|
276
|
+
score = validator.calculate_cleanliness_score()
|
|
277
|
+
errors = [issue for issue in validator.issues if issue[0] == "error"]
|
|
278
|
+
|
|
279
|
+
# Only block if there are critical errors
|
|
280
|
+
if errors and score < 30:
|
|
281
|
+
output = {
|
|
282
|
+
"hookSpecificOutput": {
|
|
283
|
+
"hookEventName": "UserPromptSubmit",
|
|
284
|
+
"additionalContext": report,
|
|
285
|
+
"blocked": True,
|
|
286
|
+
"blockedMessage": "Critical cleanliness issues detected. Please fix errors before proceeding."
|
|
287
|
+
},
|
|
288
|
+
}
|
|
289
|
+
else:
|
|
290
|
+
# Just show report as context
|
|
291
|
+
output = {
|
|
292
|
+
"hookSpecificOutput": {
|
|
293
|
+
"hookEventName": "UserPromptSubmit",
|
|
294
|
+
"additionalContext": report,
|
|
295
|
+
},
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
print(json.dumps(output))
|
|
299
|
+
sys.exit(0)
|
|
300
|
+
|
|
301
|
+
except Exception as e:
|
|
302
|
+
# Don't block on hook errors
|
|
303
|
+
print(f"Error in clean-pre hook: {e}", file=sys.stderr)
|
|
304
|
+
sys.exit(0)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
if __name__ == "__main__":
|
|
308
|
+
main()
|