fix-registry.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. #!/usr/bin/env python3
  2. """
  3. Registry Fix Script
  4. Fixes dead references and adds orphaned files to registry.json
  5. """
  6. import json
  7. import os
  8. from pathlib import Path
  9. REPO_ROOT = Path(__file__).parent.parent.parent
  10. REGISTRY_FILE = REPO_ROOT / "registry.json"
  11. def load_registry():
  12. with open(REGISTRY_FILE, 'r') as f:
  13. return json.load(f)
  14. def save_registry(registry):
  15. with open(REGISTRY_FILE, 'w') as f:
  16. json.dump(registry, f, indent=2)
  17. print(f"✓ Registry saved to {REGISTRY_FILE}")
  18. def remove_dead_references(registry):
  19. """Remove entries that point to non-existent files"""
  20. dead_entries = [
  21. "workflows-delegation", # Split into multiple files
  22. "design-iteration", # Split into multiple files
  23. "design-assets", # Doesn't exist
  24. "animation-patterns", # Split into animation-*.md files
  25. "adding-agent", # Split into adding-agent-*.md
  26. "adding-skill", # Split into adding-skill-*.md
  27. "navigation-design", # Split into navigation-design-*.md
  28. "claude-agent-skills", # Directory doesn't exist
  29. "claude-create-subagents", # Directory doesn't exist
  30. "claude-hooks", # Directory doesn't exist
  31. "claude-plugins", # Directory doesn't exist
  32. "external-libraries", # Split into external-libraries-*.md
  33. "navigation", # Duplicate/to-be-consumed doesn't exist
  34. ]
  35. removed = []
  36. for category in ['contexts']:
  37. if category in registry['components']:
  38. original_count = len(registry['components'][category])
  39. registry['components'][category] = [
  40. c for c in registry['components'][category]
  41. if c['id'] not in dead_entries
  42. ]
  43. removed_count = original_count - len(registry['components'][category])
  44. if removed_count > 0:
  45. removed.append(f"{category}: {removed_count} entries")
  46. print(f"✓ Removed dead references: {', '.join(removed) if removed else 'None'}")
  47. return registry
  48. def add_split_file_entries(registry):
  49. """Add entries for split files that exist on disk"""
  50. new_entries = [
  51. # Task Delegation (split files)
  52. {
  53. "id": "task-delegation-basics",
  54. "name": "Task Delegation Basics",
  55. "type": "context",
  56. "path": ".opencode/context/core/workflows/task-delegation-basics.md",
  57. "description": "Task delegation fundamentals and basic usage patterns",
  58. "tags": ["workflows", "delegation"],
  59. "dependencies": [],
  60. "category": "standard"
  61. },
  62. {
  63. "id": "task-delegation-specialists",
  64. "name": "Task Delegation Specialists",
  65. "type": "context",
  66. "path": ".opencode/context/core/workflows/task-delegation-specialists.md",
  67. "description": "Specialist subagents for task delegation workflows",
  68. "tags": ["workflows", "delegation", "subagents"],
  69. "dependencies": [],
  70. "category": "standard"
  71. },
  72. {
  73. "id": "task-delegation-caching",
  74. "name": "Task Delegation Caching",
  75. "type": "context",
  76. "path": ".opencode/context/core/workflows/task-delegation-caching.md",
  77. "description": "Caching strategies for task delegation workflows",
  78. "tags": ["workflows", "delegation", "caching"],
  79. "dependencies": [],
  80. "category": "standard"
  81. },
  82. # Design Iteration (split files)
  83. {
  84. "id": "design-iteration-overview",
  85. "name": "Design Iteration Overview",
  86. "type": "context",
  87. "path": ".opencode/context/core/workflows/design-iteration-overview.md",
  88. "description": "Overview of the design iteration workflow process",
  89. "tags": ["workflows", "design", "iteration"],
  90. "dependencies": [],
  91. "category": "standard"
  92. },
  93. {
  94. "id": "design-iteration-plan-file",
  95. "name": "Design Iteration Plan File",
  96. "type": "context",
  97. "path": ".opencode/context/core/workflows/design-iteration-plan-file.md",
  98. "description": "Structure and format for design iteration plan files",
  99. "tags": ["workflows", "design", "planning"],
  100. "dependencies": [],
  101. "category": "standard"
  102. },
  103. {
  104. "id": "design-iteration-plan-iterations",
  105. "name": "Design Iteration Plan Iterations",
  106. "type": "context",
  107. "path": ".opencode/context/core/workflows/design-iteration-plan-iterations.md",
  108. "description": "Planning iterations in the design workflow",
  109. "tags": ["workflows", "design", "planning"],
  110. "dependencies": [],
  111. "category": "standard"
  112. },
  113. {
  114. "id": "design-iteration-stage-layout",
  115. "name": "Design Iteration Stage - Layout",
  116. "type": "context",
  117. "path": ".opencode/context/core/workflows/design-iteration-stage-layout.md",
  118. "description": "Layout stage guidelines for design iteration",
  119. "tags": ["workflows", "design", "layout"],
  120. "dependencies": [],
  121. "category": "standard"
  122. },
  123. {
  124. "id": "design-iteration-stage-theme",
  125. "name": "Design Iteration Stage - Theme",
  126. "type": "context",
  127. "path": ".opencode/context/core/workflows/design-iteration-stage-theme.md",
  128. "description": "Theme stage guidelines for design iteration",
  129. "tags": ["workflows", "design", "theme"],
  130. "dependencies": [],
  131. "category": "standard"
  132. },
  133. {
  134. "id": "design-iteration-stage-implementation",
  135. "name": "Design Iteration Stage - Implementation",
  136. "type": "context",
  137. "path": ".opencode/context/core/workflows/design-iteration-stage-implementation.md",
  138. "description": "Implementation stage guidelines for design iteration",
  139. "tags": ["workflows", "design", "implementation"],
  140. "dependencies": [],
  141. "category": "standard"
  142. },
  143. {
  144. "id": "design-iteration-stage-animation",
  145. "name": "Design Iteration Stage - Animation",
  146. "type": "context",
  147. "path": ".opencode/context/core/workflows/design-iteration-stage-animation.md",
  148. "description": "Animation stage guidelines for design iteration",
  149. "tags": ["workflows", "design", "animation"],
  150. "dependencies": [],
  151. "category": "standard"
  152. },
  153. {
  154. "id": "design-iteration-visual-content",
  155. "name": "Design Iteration Visual Content",
  156. "type": "context",
  157. "path": ".opencode/context/core/workflows/design-iteration-visual-content.md",
  158. "description": "Visual content guidelines for design iteration",
  159. "tags": ["workflows", "design", "visual"],
  160. "dependencies": [],
  161. "category": "standard"
  162. },
  163. {
  164. "id": "design-iteration-best-practices",
  165. "name": "Design Iteration Best Practices",
  166. "type": "context",
  167. "path": ".opencode/context/core/workflows/design-iteration-best-practices.md",
  168. "description": "Best practices for design iteration workflows",
  169. "tags": ["workflows", "design", "best-practices"],
  170. "dependencies": [],
  171. "category": "standard"
  172. },
  173. # External Libraries (split files)
  174. {
  175. "id": "external-libraries-workflow",
  176. "name": "External Libraries Workflow",
  177. "type": "context",
  178. "path": ".opencode/context/core/workflows/external-libraries-workflow.md",
  179. "description": "Workflow for managing external library dependencies",
  180. "tags": ["workflows", "external", "libraries"],
  181. "dependencies": [],
  182. "category": "standard"
  183. },
  184. {
  185. "id": "external-libraries-scenarios",
  186. "name": "External Libraries Scenarios",
  187. "type": "context",
  188. "path": ".opencode/context/core/workflows/external-libraries-scenarios.md",
  189. "description": "Common scenarios for external library integration",
  190. "tags": ["workflows", "external", "libraries", "scenarios"],
  191. "dependencies": [],
  192. "category": "standard"
  193. },
  194. {
  195. "id": "external-libraries-faq",
  196. "name": "External Libraries FAQ",
  197. "type": "context",
  198. "path": ".opencode/context/core/workflows/external-libraries-faq.md",
  199. "description": "Frequently asked questions about external libraries",
  200. "tags": ["workflows", "external", "libraries", "faq"],
  201. "dependencies": [],
  202. "category": "standard"
  203. },
  204. # Adding Agent (split files)
  205. {
  206. "id": "adding-agent-basics",
  207. "name": "Adding Agent - Basics",
  208. "type": "context",
  209. "path": ".opencode/context/openagents-repo/guides/adding-agent-basics.md",
  210. "description": "Basic guide for adding new agents",
  211. "tags": ["guides", "agents", "basics"],
  212. "dependencies": [],
  213. "category": "standard"
  214. },
  215. {
  216. "id": "adding-agent-testing",
  217. "name": "Adding Agent - Testing",
  218. "type": "context",
  219. "path": ".opencode/context/openagents-repo/guides/adding-agent-testing.md",
  220. "description": "Testing guide for new agents",
  221. "tags": ["guides", "agents", "testing"],
  222. "dependencies": [],
  223. "category": "standard"
  224. },
  225. # Adding Skill (split files)
  226. {
  227. "id": "adding-skill-basics",
  228. "name": "Adding Skill - Basics",
  229. "type": "context",
  230. "path": ".opencode/context/openagents-repo/guides/adding-skill-basics.md",
  231. "description": "Basic guide for adding new skills",
  232. "tags": ["guides", "skills", "basics"],
  233. "dependencies": [],
  234. "category": "standard"
  235. },
  236. {
  237. "id": "adding-skill-implementation",
  238. "name": "Adding Skill - Implementation",
  239. "type": "context",
  240. "path": ".opencode/context/openagents-repo/guides/adding-skill-implementation.md",
  241. "description": "Implementation guide for new skills",
  242. "tags": ["guides", "skills", "implementation"],
  243. "dependencies": [],
  244. "category": "standard"
  245. },
  246. {
  247. "id": "adding-skill-example",
  248. "name": "Adding Skill - Example",
  249. "type": "context",
  250. "path": ".opencode/context/openagents-repo/guides/adding-skill-example.md",
  251. "description": "Example of adding a new skill",
  252. "tags": ["guides", "skills", "examples"],
  253. "dependencies": [],
  254. "category": "standard"
  255. },
  256. # Navigation Design (split files)
  257. {
  258. "id": "navigation-design-basics",
  259. "name": "Navigation Design Basics",
  260. "type": "context",
  261. "path": ".opencode/context/core/context-system/guides/navigation-design-basics.md",
  262. "description": "Basics of designing navigation files",
  263. "tags": ["context-system", "navigation", "design"],
  264. "dependencies": [],
  265. "category": "standard"
  266. },
  267. {
  268. "id": "navigation-templates",
  269. "name": "Navigation Templates",
  270. "type": "context",
  271. "path": ".opencode/context/core/context-system/guides/navigation-templates.md",
  272. "description": "Templates for navigation files",
  273. "tags": ["context-system", "navigation", "templates"],
  274. "dependencies": [],
  275. "category": "standard"
  276. },
  277. # Animation Patterns (split files)
  278. {
  279. "id": "animation-basics",
  280. "name": "Animation Basics",
  281. "type": "context",
  282. "path": ".opencode/context/ui/web/animation-basics.md",
  283. "description": "Basic animation patterns and guidelines",
  284. "tags": ["ui", "web", "animation"],
  285. "dependencies": [],
  286. "category": "standard"
  287. },
  288. {
  289. "id": "animation-advanced",
  290. "name": "Animation Advanced",
  291. "type": "context",
  292. "path": ".opencode/context/ui/web/animation-advanced.md",
  293. "description": "Advanced animation patterns and techniques",
  294. "tags": ["ui", "web", "animation"],
  295. "dependencies": [],
  296. "category": "standard"
  297. },
  298. {
  299. "id": "animation-components",
  300. "name": "Animation Components",
  301. "type": "context",
  302. "path": ".opencode/context/ui/web/animation-components.md",
  303. "description": "Component-specific animation patterns",
  304. "tags": ["ui", "web", "animation", "components"],
  305. "dependencies": [],
  306. "category": "standard"
  307. },
  308. {
  309. "id": "animation-forms",
  310. "name": "Animation Forms",
  311. "type": "context",
  312. "path": ".opencode/context/ui/web/animation-forms.md",
  313. "description": "Animation patterns for forms",
  314. "tags": ["ui", "web", "animation", "forms"],
  315. "dependencies": [],
  316. "category": "standard"
  317. },
  318. {
  319. "id": "animation-chat",
  320. "name": "Animation Chat",
  321. "type": "context",
  322. "path": ".opencode/context/ui/web/animation-chat.md",
  323. "description": "Animation patterns for chat interfaces",
  324. "tags": ["ui", "web", "animation", "chat"],
  325. "dependencies": [],
  326. "category": "standard"
  327. },
  328. {
  329. "id": "animation-loading",
  330. "name": "Animation Loading",
  331. "type": "context",
  332. "path": ".opencode/context/ui/web/animation-loading.md",
  333. "description": "Loading animation patterns",
  334. "tags": ["ui", "web", "animation", "loading"],
  335. "dependencies": [],
  336. "category": "standard"
  337. },
  338. ]
  339. # Verify files exist before adding
  340. verified_entries = []
  341. for entry in new_entries:
  342. file_path = REPO_ROOT / entry['path']
  343. if file_path.exists():
  344. verified_entries.append(entry)
  345. else:
  346. print(f"⚠ File doesn't exist: {entry['path']}")
  347. # Add to registry
  348. if 'contexts' not in registry['components']:
  349. registry['components']['contexts'] = []
  350. existing_ids = {c['id'] for c in registry['components']['contexts']}
  351. added = 0
  352. for entry in verified_entries:
  353. if entry['id'] not in existing_ids:
  354. registry['components']['contexts'].append(entry)
  355. added += 1
  356. print(f"✓ Added {added} new split-file entries")
  357. return registry
  358. def update_dependencies(registry):
  359. """Update dependencies that referenced old split files"""
  360. # Update OpenCoder dependencies
  361. for agent in registry['components'].get('agents', []):
  362. if agent['id'] == 'opencoder':
  363. # Replace workflows-delegation with task-delegation-basics
  364. agent['dependencies'] = [
  365. dep.replace('context:workflows-delegation', 'context:task-delegation-basics')
  366. for dep in agent['dependencies']
  367. ]
  368. print(f"✓ Updated dependencies for agent: {agent['id']}")
  369. # Update context dependencies
  370. for ctx in registry['components'].get('contexts', []):
  371. if 'dependencies' in ctx:
  372. # Replace external-libraries with external-libraries-workflow
  373. ctx['dependencies'] = [
  374. dep.replace('context:external-libraries', 'context:external-libraries-workflow')
  375. for dep in ctx['dependencies']
  376. ]
  377. # Replace adding-agent with adding-agent-basics
  378. ctx['dependencies'] = [
  379. dep.replace('context:adding-agent', 'context:adding-agent-basics')
  380. for dep in ctx['dependencies']
  381. ]
  382. # Replace adding-skill with adding-skill-basics
  383. ctx['dependencies'] = [
  384. dep.replace('context:adding-skill', 'context:adding-skill-basics')
  385. for dep in ctx['dependencies']
  386. ]
  387. print(f"✓ Updated dependencies referencing split files")
  388. return registry
  389. def main():
  390. print("=" * 60)
  391. print("Registry Fix Script")
  392. print("=" * 60)
  393. # Load registry
  394. registry = load_registry()
  395. print(f"✓ Loaded registry with {len(registry['components'].get('contexts', []))} contexts")
  396. # Fix steps
  397. registry = remove_dead_references(registry)
  398. registry = add_split_file_entries(registry)
  399. registry = update_dependencies(registry)
  400. # Save registry
  401. save_registry(registry)
  402. # Validate
  403. context_count = len(registry['components'].get('contexts', []))
  404. print(f"\n✓ Registry now has {context_count} context entries")
  405. print("\nNext: Run validation to check results")
  406. print(" bun run scripts/registry/validate-registry.ts")
  407. if __name__ == "__main__":
  408. main()