moai-adk 0.15.1__py3-none-any.whl → 0.25.4__py3-none-any.whl

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.

Potentially problematic release.


This version of moai-adk might be problematic. Click here for more details.

Files changed (417) hide show
  1. moai_adk/__init__.py +1 -2
  2. moai_adk/__main__.py +85 -2
  3. moai_adk/cli/__init__.py +0 -1
  4. moai_adk/cli/commands/__init__.py +0 -1
  5. moai_adk/cli/commands/analyze.py +127 -0
  6. moai_adk/cli/commands/backup.py +5 -3
  7. moai_adk/cli/commands/doctor.py +35 -11
  8. moai_adk/cli/commands/improve_user_experience.py +348 -0
  9. moai_adk/cli/commands/init.py +150 -23
  10. moai_adk/cli/commands/language.py +269 -0
  11. moai_adk/cli/commands/migrate.py +158 -0
  12. moai_adk/cli/commands/status.py +13 -12
  13. moai_adk/cli/commands/update.py +364 -60
  14. moai_adk/cli/commands/validate_links.py +118 -0
  15. moai_adk/cli/main.py +3 -2
  16. moai_adk/cli/prompts/init_prompts.py +79 -82
  17. moai_adk/core/__init__.py +0 -1
  18. moai_adk/core/analysis/__init__.py +9 -0
  19. moai_adk/core/analysis/session_analyzer.py +439 -0
  20. moai_adk/core/claude_integration.py +421 -0
  21. moai_adk/core/command_helpers.py +270 -0
  22. moai_adk/core/config/__init__.py +6 -0
  23. moai_adk/core/config/auto_spec_config.py +346 -0
  24. moai_adk/core/config/migration.py +133 -12
  25. moai_adk/core/context_manager.py +279 -0
  26. moai_adk/core/diagnostics/slash_commands.py +0 -1
  27. moai_adk/core/error_recovery_system.py +1289 -0
  28. moai_adk/core/git/__init__.py +0 -1
  29. moai_adk/core/git/branch.py +0 -1
  30. moai_adk/core/git/branch_manager.py +4 -4
  31. moai_adk/core/git/checkpoint.py +1 -5
  32. moai_adk/core/git/commit.py +0 -1
  33. moai_adk/core/git/event_detector.py +3 -5
  34. moai_adk/core/git/manager.py +0 -1
  35. moai_adk/core/hooks/post_tool_auto_spec_completion.py +925 -0
  36. moai_adk/core/integration/__init__.py +22 -0
  37. moai_adk/core/integration/engine.py +169 -0
  38. moai_adk/core/integration/integration_tester.py +225 -0
  39. moai_adk/core/integration/models.py +88 -0
  40. moai_adk/core/integration/utils.py +211 -0
  41. moai_adk/core/issue_creator.py +28 -18
  42. moai_adk/core/language_config.py +202 -0
  43. moai_adk/core/language_validator.py +556 -0
  44. moai_adk/core/mcp/setup.py +113 -0
  45. moai_adk/core/migration/__init__.py +18 -0
  46. moai_adk/core/migration/backup_manager.py +208 -0
  47. moai_adk/core/migration/file_migrator.py +218 -0
  48. moai_adk/core/migration/version_detector.py +143 -0
  49. moai_adk/core/migration/version_migrator.py +228 -0
  50. moai_adk/core/performance/__init__.py +6 -0
  51. moai_adk/core/performance/cache_system.py +318 -0
  52. moai_adk/core/performance/parallel_processor.py +116 -0
  53. moai_adk/core/project/__init__.py +0 -1
  54. moai_adk/core/project/backup_utils.py +2 -7
  55. moai_adk/core/project/checker.py +3 -3
  56. moai_adk/core/project/detector.py +20 -40
  57. moai_adk/core/project/initializer.py +42 -17
  58. moai_adk/core/project/phase_executor.py +415 -58
  59. moai_adk/core/project/validator.py +6 -25
  60. moai_adk/core/quality/__init__.py +1 -1
  61. moai_adk/core/quality/trust_checker.py +64 -110
  62. moai_adk/core/quality/validators/__init__.py +1 -1
  63. moai_adk/core/quality/validators/base_validator.py +1 -1
  64. moai_adk/core/rollback_manager.py +993 -0
  65. moai_adk/core/session_manager.py +667 -0
  66. moai_adk/core/spec/confidence_scoring.py +749 -0
  67. moai_adk/core/spec/ears_template_engine.py +1182 -0
  68. moai_adk/core/spec/quality_validator.py +721 -0
  69. moai_adk/core/spec_status_manager.py +488 -0
  70. moai_adk/core/template/__init__.py +0 -1
  71. moai_adk/core/template/backup.py +41 -1
  72. moai_adk/core/template/config.py +11 -12
  73. moai_adk/core/template/languages.py +0 -1
  74. moai_adk/core/template/merger.py +79 -22
  75. moai_adk/core/template/processor.py +614 -40
  76. moai_adk/core/template_engine.py +36 -27
  77. moai_adk/foundation/git/commit_templates.py +565 -0
  78. moai_adk/foundation/trust/trust_principles.py +725 -0
  79. moai_adk/foundation/trust/validation_checklist.py +1678 -0
  80. moai_adk/statusline/__init__.py +38 -0
  81. moai_adk/statusline/alfred_detector.py +107 -0
  82. moai_adk/statusline/config.py +364 -0
  83. moai_adk/statusline/enhanced_output_style_detector.py +364 -0
  84. moai_adk/statusline/git_collector.py +190 -0
  85. moai_adk/statusline/main.py +228 -0
  86. moai_adk/statusline/metrics_tracker.py +78 -0
  87. moai_adk/statusline/renderer.py +327 -0
  88. moai_adk/statusline/update_checker.py +135 -0
  89. moai_adk/statusline/version_reader.py +647 -0
  90. moai_adk/templates/.git-hooks/pre-commit +66 -0
  91. moai_adk/templates/.git-hooks/pre-push +116 -4
  92. moai_adk/templates/.github/workflows/moai-gitflow.yml +1 -7
  93. moai_adk/templates/.github/workflows/spec-issue-sync.yml +0 -1
  94. moai_adk/templates/.gitignore +44 -0
  95. moai_adk/templates/.mcp.json +22 -0
  96. moai_adk/templates/CLAUDE.md +450 -1071
  97. moai_adk/utils/__init__.py +0 -1
  98. moai_adk/utils/banner.py +0 -1
  99. moai_adk/utils/common.py +308 -0
  100. moai_adk/utils/link_validator.py +249 -0
  101. moai_adk/utils/logger.py +4 -9
  102. moai_adk/utils/safe_file_reader.py +210 -0
  103. moai_adk/utils/user_experience.py +531 -0
  104. moai_adk-0.25.4.dist-info/METADATA +2279 -0
  105. moai_adk-0.25.4.dist-info/RECORD +112 -0
  106. moai_adk/core/tags/__init__.py +0 -86
  107. moai_adk/core/tags/ci_validator.py +0 -463
  108. moai_adk/core/tags/cli.py +0 -283
  109. moai_adk/core/tags/generator.py +0 -109
  110. moai_adk/core/tags/inserter.py +0 -99
  111. moai_adk/core/tags/mapper.py +0 -126
  112. moai_adk/core/tags/parser.py +0 -76
  113. moai_adk/core/tags/pre_commit_validator.py +0 -393
  114. moai_adk/core/tags/reporter.py +0 -956
  115. moai_adk/core/tags/tags.py +0 -149
  116. moai_adk/core/tags/validator.py +0 -897
  117. moai_adk/templates/.claude/agents/alfred/backend-expert.md +0 -319
  118. moai_adk/templates/.claude/agents/alfred/cc-manager.md +0 -316
  119. moai_adk/templates/.claude/agents/alfred/debug-helper.md +0 -208
  120. moai_adk/templates/.claude/agents/alfred/devops-expert.md +0 -464
  121. moai_adk/templates/.claude/agents/alfred/doc-syncer.md +0 -214
  122. moai_adk/templates/.claude/agents/alfred/frontend-expert.md +0 -357
  123. moai_adk/templates/.claude/agents/alfred/git-manager.md +0 -406
  124. moai_adk/templates/.claude/agents/alfred/implementation-planner.md +0 -423
  125. moai_adk/templates/.claude/agents/alfred/project-manager.md +0 -312
  126. moai_adk/templates/.claude/agents/alfred/quality-gate.md +0 -343
  127. moai_adk/templates/.claude/agents/alfred/skill-factory.md +0 -865
  128. moai_adk/templates/.claude/agents/alfred/spec-builder.md +0 -426
  129. moai_adk/templates/.claude/agents/alfred/tag-agent.md +0 -361
  130. moai_adk/templates/.claude/agents/alfred/tdd-implementer.md +0 -428
  131. moai_adk/templates/.claude/agents/alfred/trust-checker.md +0 -375
  132. moai_adk/templates/.claude/agents/alfred/ui-ux-expert.md +0 -571
  133. moai_adk/templates/.claude/commands/alfred/0-project.md +0 -1854
  134. moai_adk/templates/.claude/commands/alfred/1-plan.md +0 -880
  135. moai_adk/templates/.claude/commands/alfred/2-run.md +0 -793
  136. moai_adk/templates/.claude/commands/alfred/3-sync.md +0 -1084
  137. moai_adk/templates/.claude/commands/alfred/9-feedback.md +0 -149
  138. moai_adk/templates/.claude/hooks/alfred/core/project.py +0 -748
  139. moai_adk/templates/.claude/hooks/alfred/core/timeout.py +0 -136
  140. moai_adk/templates/.claude/hooks/alfred/core/ttl_cache.py +0 -108
  141. moai_adk/templates/.claude/hooks/alfred/core/version_cache.py +0 -198
  142. moai_adk/templates/.claude/hooks/alfred/handlers/__init__.py +0 -29
  143. moai_adk/templates/.claude/hooks/alfred/post_tool__log_changes.py +0 -94
  144. moai_adk/templates/.claude/hooks/alfred/pre_tool__auto_checkpoint.py +0 -100
  145. moai_adk/templates/.claude/hooks/alfred/session_end__cleanup.py +0 -94
  146. moai_adk/templates/.claude/hooks/alfred/session_start__show_project_info.py +0 -94
  147. moai_adk/templates/.claude/hooks/alfred/shared/core/__init__.py +0 -170
  148. moai_adk/templates/.claude/hooks/alfred/shared/core/checkpoint.py +0 -271
  149. moai_adk/templates/.claude/hooks/alfred/shared/core/context.py +0 -67
  150. moai_adk/templates/.claude/hooks/alfred/shared/core/project.py +0 -749
  151. moai_adk/templates/.claude/hooks/alfred/shared/core/tags.py +0 -230
  152. moai_adk/templates/.claude/hooks/alfred/shared/core/version_cache.py +0 -198
  153. moai_adk/templates/.claude/hooks/alfred/shared/handlers/__init__.py +0 -21
  154. moai_adk/templates/.claude/hooks/alfred/shared/handlers/notification.py +0 -154
  155. moai_adk/templates/.claude/hooks/alfred/shared/handlers/session.py +0 -174
  156. moai_adk/templates/.claude/hooks/alfred/shared/handlers/tool.py +0 -87
  157. moai_adk/templates/.claude/hooks/alfred/shared/handlers/user.py +0 -61
  158. moai_adk/templates/.claude/hooks/alfred/user_prompt__jit_load_docs.py +0 -112
  159. moai_adk/templates/.claude/hooks/alfred/utils/__init__.py +0 -1
  160. moai_adk/templates/.claude/hooks/alfred/utils/timeout.py +0 -161
  161. moai_adk/templates/.claude/settings.json +0 -144
  162. moai_adk/templates/.claude/skills/moai-alfred-agent-guide/SKILL.md +0 -70
  163. moai_adk/templates/.claude/skills/moai-alfred-agent-guide/examples.md +0 -62
  164. moai_adk/templates/.claude/skills/moai-alfred-agent-guide/reference.md +0 -242
  165. moai_adk/templates/.claude/skills/moai-alfred-config-schema/SKILL.md +0 -56
  166. moai_adk/templates/.claude/skills/moai-alfred-config-schema/examples.md +0 -28
  167. moai_adk/templates/.claude/skills/moai-alfred-config-schema/reference.md +0 -444
  168. moai_adk/templates/.claude/skills/moai-alfred-context-budget/SKILL.md +0 -62
  169. moai_adk/templates/.claude/skills/moai-alfred-context-budget/examples.md +0 -28
  170. moai_adk/templates/.claude/skills/moai-alfred-context-budget/reference.md +0 -405
  171. moai_adk/templates/.claude/skills/moai-alfred-dev-guide/SKILL.md +0 -51
  172. moai_adk/templates/.claude/skills/moai-alfred-dev-guide/examples.md +0 -355
  173. moai_adk/templates/.claude/skills/moai-alfred-dev-guide/reference.md +0 -239
  174. moai_adk/templates/.claude/skills/moai-alfred-ears-authoring/SKILL.md +0 -113
  175. moai_adk/templates/.claude/skills/moai-alfred-ears-authoring/examples.md +0 -29
  176. moai_adk/templates/.claude/skills/moai-alfred-ears-authoring/reference.md +0 -28
  177. moai_adk/templates/.claude/skills/moai-alfred-expertise-detection/SKILL.md +0 -323
  178. moai_adk/templates/.claude/skills/moai-alfred-expertise-detection/examples.md +0 -286
  179. moai_adk/templates/.claude/skills/moai-alfred-expertise-detection/reference.md +0 -126
  180. moai_adk/templates/.claude/skills/moai-alfred-git-workflow/SKILL.md +0 -122
  181. moai_adk/templates/.claude/skills/moai-alfred-git-workflow/examples.md +0 -29
  182. moai_adk/templates/.claude/skills/moai-alfred-git-workflow/reference.md +0 -29
  183. moai_adk/templates/.claude/skills/moai-alfred-gitflow-policy/SKILL.md +0 -74
  184. moai_adk/templates/.claude/skills/moai-alfred-gitflow-policy/examples.md +0 -4
  185. moai_adk/templates/.claude/skills/moai-alfred-gitflow-policy/reference.md +0 -269
  186. moai_adk/templates/.claude/skills/moai-alfred-interactive-questions/SKILL.md +0 -237
  187. moai_adk/templates/.claude/skills/moai-alfred-interactive-questions/examples.md +0 -615
  188. moai_adk/templates/.claude/skills/moai-alfred-interactive-questions/reference.md +0 -653
  189. moai_adk/templates/.claude/skills/moai-alfred-issue-labels/SKILL.md +0 -19
  190. moai_adk/templates/.claude/skills/moai-alfred-issue-labels/examples.md +0 -4
  191. moai_adk/templates/.claude/skills/moai-alfred-issue-labels/reference.md +0 -150
  192. moai_adk/templates/.claude/skills/moai-alfred-language-detection/SKILL.md +0 -113
  193. moai_adk/templates/.claude/skills/moai-alfred-language-detection/examples.md +0 -29
  194. moai_adk/templates/.claude/skills/moai-alfred-language-detection/reference.md +0 -28
  195. moai_adk/templates/.claude/skills/moai-alfred-persona-roles/SKILL.md +0 -198
  196. moai_adk/templates/.claude/skills/moai-alfred-persona-roles/examples.md +0 -431
  197. moai_adk/templates/.claude/skills/moai-alfred-persona-roles/reference.md +0 -141
  198. moai_adk/templates/.claude/skills/moai-alfred-practices/SKILL.md +0 -89
  199. moai_adk/templates/.claude/skills/moai-alfred-practices/examples.md +0 -122
  200. moai_adk/templates/.claude/skills/moai-alfred-practices/reference.md +0 -369
  201. moai_adk/templates/.claude/skills/moai-alfred-proactive-suggestions/SKILL.md +0 -508
  202. moai_adk/templates/.claude/skills/moai-alfred-proactive-suggestions/examples.md +0 -481
  203. moai_adk/templates/.claude/skills/moai-alfred-proactive-suggestions/reference.md +0 -100
  204. moai_adk/templates/.claude/skills/moai-alfred-reporting/SKILL.md +0 -273
  205. moai_adk/templates/.claude/skills/moai-alfred-rules/SKILL.md +0 -77
  206. moai_adk/templates/.claude/skills/moai-alfred-rules/examples.md +0 -265
  207. moai_adk/templates/.claude/skills/moai-alfred-rules/reference.md +0 -539
  208. moai_adk/templates/.claude/skills/moai-alfred-session-state/SKILL.md +0 -19
  209. moai_adk/templates/.claude/skills/moai-alfred-session-state/examples.md +0 -4
  210. moai_adk/templates/.claude/skills/moai-alfred-session-state/reference.md +0 -84
  211. moai_adk/templates/.claude/skills/moai-alfred-spec-authoring/README.md +0 -137
  212. moai_adk/templates/.claude/skills/moai-alfred-spec-authoring/SKILL.md +0 -219
  213. moai_adk/templates/.claude/skills/moai-alfred-spec-authoring/examples/validate-spec.sh +0 -161
  214. moai_adk/templates/.claude/skills/moai-alfred-spec-authoring/examples.md +0 -541
  215. moai_adk/templates/.claude/skills/moai-alfred-spec-authoring/reference.md +0 -622
  216. moai_adk/templates/.claude/skills/moai-alfred-spec-metadata-extended/SKILL.md +0 -115
  217. moai_adk/templates/.claude/skills/moai-alfred-spec-metadata-extended/examples.md +0 -4
  218. moai_adk/templates/.claude/skills/moai-alfred-spec-metadata-extended/reference.md +0 -348
  219. moai_adk/templates/.claude/skills/moai-alfred-spec-metadata-validation/SKILL.md +0 -113
  220. moai_adk/templates/.claude/skills/moai-alfred-spec-metadata-validation/examples.md +0 -29
  221. moai_adk/templates/.claude/skills/moai-alfred-spec-metadata-validation/reference.md +0 -28
  222. moai_adk/templates/.claude/skills/moai-alfred-tag-scanning/SKILL.md +0 -113
  223. moai_adk/templates/.claude/skills/moai-alfred-tag-scanning/examples.md +0 -29
  224. moai_adk/templates/.claude/skills/moai-alfred-tag-scanning/reference.md +0 -28
  225. moai_adk/templates/.claude/skills/moai-alfred-todowrite-pattern/SKILL.md +0 -19
  226. moai_adk/templates/.claude/skills/moai-alfred-todowrite-pattern/examples.md +0 -4
  227. moai_adk/templates/.claude/skills/moai-alfred-todowrite-pattern/reference.md +0 -211
  228. moai_adk/templates/.claude/skills/moai-alfred-trust-validation/SKILL.md +0 -113
  229. moai_adk/templates/.claude/skills/moai-alfred-trust-validation/examples.md +0 -29
  230. moai_adk/templates/.claude/skills/moai-alfred-trust-validation/reference.md +0 -28
  231. moai_adk/templates/.claude/skills/moai-alfred-workflow/SKILL.md +0 -288
  232. moai_adk/templates/.claude/skills/moai-cc-agents/SKILL.md +0 -269
  233. moai_adk/templates/.claude/skills/moai-cc-agents/templates/agent-template.md +0 -32
  234. moai_adk/templates/.claude/skills/moai-cc-claude-md/SKILL.md +0 -298
  235. moai_adk/templates/.claude/skills/moai-cc-claude-md/templates/CLAUDE-template.md +0 -26
  236. moai_adk/templates/.claude/skills/moai-cc-commands/SKILL.md +0 -307
  237. moai_adk/templates/.claude/skills/moai-cc-commands/templates/command-template.md +0 -21
  238. moai_adk/templates/.claude/skills/moai-cc-hooks/SKILL.md +0 -252
  239. moai_adk/templates/.claude/skills/moai-cc-hooks/scripts/pre-bash-check.sh +0 -19
  240. moai_adk/templates/.claude/skills/moai-cc-hooks/scripts/preserve-permissions.sh +0 -19
  241. moai_adk/templates/.claude/skills/moai-cc-hooks/scripts/validate-bash-command.py +0 -24
  242. moai_adk/templates/.claude/skills/moai-cc-mcp-plugins/SKILL.md +0 -199
  243. moai_adk/templates/.claude/skills/moai-cc-mcp-plugins/templates/settings-mcp-template.json +0 -39
  244. moai_adk/templates/.claude/skills/moai-cc-memory/SKILL.md +0 -316
  245. moai_adk/templates/.claude/skills/moai-cc-memory/templates/session-summary-template.md +0 -18
  246. moai_adk/templates/.claude/skills/moai-cc-settings/SKILL.md +0 -263
  247. moai_adk/templates/.claude/skills/moai-cc-settings/templates/settings-complete-template.json +0 -30
  248. moai_adk/templates/.claude/skills/moai-cc-skill-descriptions/SKILL.md +0 -19
  249. moai_adk/templates/.claude/skills/moai-cc-skill-descriptions/examples.md +0 -4
  250. moai_adk/templates/.claude/skills/moai-cc-skill-descriptions/reference.md +0 -218
  251. moai_adk/templates/.claude/skills/moai-cc-skill-factory/CHECKLIST.md +0 -482
  252. moai_adk/templates/.claude/skills/moai-cc-skill-factory/EXAMPLES.md +0 -278
  253. moai_adk/templates/.claude/skills/moai-cc-skill-factory/INTERACTIVE-DISCOVERY.md +0 -524
  254. moai_adk/templates/.claude/skills/moai-cc-skill-factory/METADATA.md +0 -477
  255. moai_adk/templates/.claude/skills/moai-cc-skill-factory/PARALLEL-ANALYSIS-REPORT.md +0 -429
  256. moai_adk/templates/.claude/skills/moai-cc-skill-factory/PYTHON-VERSION-MATRIX.md +0 -391
  257. moai_adk/templates/.claude/skills/moai-cc-skill-factory/SKILL-FACTORY-WORKFLOW.md +0 -431
  258. moai_adk/templates/.claude/skills/moai-cc-skill-factory/SKILL-UPDATE-ADVISOR.md +0 -577
  259. moai_adk/templates/.claude/skills/moai-cc-skill-factory/SKILL.md +0 -271
  260. moai_adk/templates/.claude/skills/moai-cc-skill-factory/STEP-BY-STEP-GUIDE.md +0 -466
  261. moai_adk/templates/.claude/skills/moai-cc-skill-factory/STRUCTURE.md +0 -583
  262. moai_adk/templates/.claude/skills/moai-cc-skill-factory/WEB-RESEARCH.md +0 -526
  263. moai_adk/templates/.claude/skills/moai-cc-skill-factory/reference.md +0 -465
  264. moai_adk/templates/.claude/skills/moai-cc-skill-factory/scripts/generate-structure.sh +0 -328
  265. moai_adk/templates/.claude/skills/moai-cc-skill-factory/scripts/validate-skill.sh +0 -312
  266. moai_adk/templates/.claude/skills/moai-cc-skill-factory/templates/SKILL_TEMPLATE.md +0 -245
  267. moai_adk/templates/.claude/skills/moai-cc-skill-factory/templates/examples-template.md +0 -285
  268. moai_adk/templates/.claude/skills/moai-cc-skill-factory/templates/reference-template.md +0 -278
  269. moai_adk/templates/.claude/skills/moai-cc-skill-factory/templates/scripts-template.sh +0 -303
  270. moai_adk/templates/.claude/skills/moai-cc-skills/SKILL.md +0 -291
  271. moai_adk/templates/.claude/skills/moai-cc-skills/templates/SKILL-template.md +0 -15
  272. moai_adk/templates/.claude/skills/moai-design-systems/SKILL.md +0 -802
  273. moai_adk/templates/.claude/skills/moai-design-systems/examples.md +0 -1238
  274. moai_adk/templates/.claude/skills/moai-design-systems/reference.md +0 -673
  275. moai_adk/templates/.claude/skills/moai-domain-backend/SKILL.md +0 -290
  276. moai_adk/templates/.claude/skills/moai-domain-backend/examples.md +0 -1633
  277. moai_adk/templates/.claude/skills/moai-domain-backend/reference.md +0 -660
  278. moai_adk/templates/.claude/skills/moai-domain-cli-tool/SKILL.md +0 -123
  279. moai_adk/templates/.claude/skills/moai-domain-cli-tool/examples.md +0 -29
  280. moai_adk/templates/.claude/skills/moai-domain-cli-tool/reference.md +0 -30
  281. moai_adk/templates/.claude/skills/moai-domain-data-science/SKILL.md +0 -123
  282. moai_adk/templates/.claude/skills/moai-domain-data-science/examples.md +0 -29
  283. moai_adk/templates/.claude/skills/moai-domain-data-science/reference.md +0 -30
  284. moai_adk/templates/.claude/skills/moai-domain-database/SKILL.md +0 -123
  285. moai_adk/templates/.claude/skills/moai-domain-database/examples.md +0 -29
  286. moai_adk/templates/.claude/skills/moai-domain-database/reference.md +0 -30
  287. moai_adk/templates/.claude/skills/moai-domain-devops/SKILL.md +0 -124
  288. moai_adk/templates/.claude/skills/moai-domain-devops/examples.md +0 -29
  289. moai_adk/templates/.claude/skills/moai-domain-devops/reference.md +0 -31
  290. moai_adk/templates/.claude/skills/moai-domain-frontend/SKILL.md +0 -128
  291. moai_adk/templates/.claude/skills/moai-domain-frontend/examples.md +0 -29
  292. moai_adk/templates/.claude/skills/moai-domain-frontend/reference.md +0 -31
  293. moai_adk/templates/.claude/skills/moai-domain-ml/SKILL.md +0 -123
  294. moai_adk/templates/.claude/skills/moai-domain-ml/examples.md +0 -29
  295. moai_adk/templates/.claude/skills/moai-domain-ml/reference.md +0 -30
  296. moai_adk/templates/.claude/skills/moai-domain-mobile-app/SKILL.md +0 -123
  297. moai_adk/templates/.claude/skills/moai-domain-mobile-app/examples.md +0 -29
  298. moai_adk/templates/.claude/skills/moai-domain-mobile-app/reference.md +0 -30
  299. moai_adk/templates/.claude/skills/moai-domain-security/SKILL.md +0 -123
  300. moai_adk/templates/.claude/skills/moai-domain-security/examples.md +0 -29
  301. moai_adk/templates/.claude/skills/moai-domain-security/reference.md +0 -30
  302. moai_adk/templates/.claude/skills/moai-domain-web-api/SKILL.md +0 -123
  303. moai_adk/templates/.claude/skills/moai-domain-web-api/examples.md +0 -29
  304. moai_adk/templates/.claude/skills/moai-domain-web-api/reference.md +0 -30
  305. moai_adk/templates/.claude/skills/moai-essentials-debug/SKILL.md +0 -303
  306. moai_adk/templates/.claude/skills/moai-essentials-debug/examples.md +0 -1064
  307. moai_adk/templates/.claude/skills/moai-essentials-debug/reference.md +0 -1047
  308. moai_adk/templates/.claude/skills/moai-essentials-perf/SKILL.md +0 -113
  309. moai_adk/templates/.claude/skills/moai-essentials-perf/examples.md +0 -29
  310. moai_adk/templates/.claude/skills/moai-essentials-perf/reference.md +0 -28
  311. moai_adk/templates/.claude/skills/moai-essentials-refactor/SKILL.md +0 -113
  312. moai_adk/templates/.claude/skills/moai-essentials-refactor/examples.md +0 -29
  313. moai_adk/templates/.claude/skills/moai-essentials-refactor/reference.md +0 -28
  314. moai_adk/templates/.claude/skills/moai-essentials-review/SKILL.md +0 -113
  315. moai_adk/templates/.claude/skills/moai-essentials-review/examples.md +0 -29
  316. moai_adk/templates/.claude/skills/moai-essentials-review/reference.md +0 -28
  317. moai_adk/templates/.claude/skills/moai-foundation-ears/SKILL.md +0 -116
  318. moai_adk/templates/.claude/skills/moai-foundation-ears/examples.md +0 -29
  319. moai_adk/templates/.claude/skills/moai-foundation-ears/reference.md +0 -28
  320. moai_adk/templates/.claude/skills/moai-foundation-git/SKILL.md +0 -122
  321. moai_adk/templates/.claude/skills/moai-foundation-git/examples.md +0 -29
  322. moai_adk/templates/.claude/skills/moai-foundation-git/reference.md +0 -29
  323. moai_adk/templates/.claude/skills/moai-foundation-langs/SKILL.md +0 -113
  324. moai_adk/templates/.claude/skills/moai-foundation-langs/examples.md +0 -29
  325. moai_adk/templates/.claude/skills/moai-foundation-langs/reference.md +0 -28
  326. moai_adk/templates/.claude/skills/moai-foundation-specs/SKILL.md +0 -113
  327. moai_adk/templates/.claude/skills/moai-foundation-specs/examples.md +0 -29
  328. moai_adk/templates/.claude/skills/moai-foundation-specs/reference.md +0 -28
  329. moai_adk/templates/.claude/skills/moai-foundation-tags/SKILL.md +0 -113
  330. moai_adk/templates/.claude/skills/moai-foundation-tags/examples.md +0 -29
  331. moai_adk/templates/.claude/skills/moai-foundation-tags/reference.md +0 -28
  332. moai_adk/templates/.claude/skills/moai-foundation-trust/SKILL.md +0 -307
  333. moai_adk/templates/.claude/skills/moai-foundation-trust/examples.md +0 -0
  334. moai_adk/templates/.claude/skills/moai-foundation-trust/reference.md +0 -1099
  335. moai_adk/templates/.claude/skills/moai-lang-c/SKILL.md +0 -124
  336. moai_adk/templates/.claude/skills/moai-lang-c/examples.md +0 -29
  337. moai_adk/templates/.claude/skills/moai-lang-c/reference.md +0 -31
  338. moai_adk/templates/.claude/skills/moai-lang-cpp/SKILL.md +0 -124
  339. moai_adk/templates/.claude/skills/moai-lang-cpp/examples.md +0 -29
  340. moai_adk/templates/.claude/skills/moai-lang-cpp/reference.md +0 -31
  341. moai_adk/templates/.claude/skills/moai-lang-csharp/SKILL.md +0 -123
  342. moai_adk/templates/.claude/skills/moai-lang-csharp/examples.md +0 -29
  343. moai_adk/templates/.claude/skills/moai-lang-csharp/reference.md +0 -30
  344. moai_adk/templates/.claude/skills/moai-lang-dart/SKILL.md +0 -123
  345. moai_adk/templates/.claude/skills/moai-lang-dart/examples.md +0 -29
  346. moai_adk/templates/.claude/skills/moai-lang-dart/reference.md +0 -30
  347. moai_adk/templates/.claude/skills/moai-lang-go/SKILL.md +0 -127
  348. moai_adk/templates/.claude/skills/moai-lang-go/examples.md +0 -29
  349. moai_adk/templates/.claude/skills/moai-lang-go/reference.md +0 -31
  350. moai_adk/templates/.claude/skills/moai-lang-java/SKILL.md +0 -126
  351. moai_adk/templates/.claude/skills/moai-lang-java/examples.md +0 -29
  352. moai_adk/templates/.claude/skills/moai-lang-java/reference.md +0 -31
  353. moai_adk/templates/.claude/skills/moai-lang-javascript/SKILL.md +0 -125
  354. moai_adk/templates/.claude/skills/moai-lang-javascript/examples.md +0 -29
  355. moai_adk/templates/.claude/skills/moai-lang-javascript/reference.md +0 -32
  356. moai_adk/templates/.claude/skills/moai-lang-kotlin/SKILL.md +0 -124
  357. moai_adk/templates/.claude/skills/moai-lang-kotlin/examples.md +0 -29
  358. moai_adk/templates/.claude/skills/moai-lang-kotlin/reference.md +0 -31
  359. moai_adk/templates/.claude/skills/moai-lang-php/SKILL.md +0 -126
  360. moai_adk/templates/.claude/skills/moai-lang-php/examples.md +0 -29
  361. moai_adk/templates/.claude/skills/moai-lang-php/reference.md +0 -30
  362. moai_adk/templates/.claude/skills/moai-lang-python/SKILL.md +0 -433
  363. moai_adk/templates/.claude/skills/moai-lang-python/examples.md +0 -624
  364. moai_adk/templates/.claude/skills/moai-lang-python/reference.md +0 -316
  365. moai_adk/templates/.claude/skills/moai-lang-r/SKILL.md +0 -123
  366. moai_adk/templates/.claude/skills/moai-lang-r/examples.md +0 -29
  367. moai_adk/templates/.claude/skills/moai-lang-r/reference.md +0 -30
  368. moai_adk/templates/.claude/skills/moai-lang-ruby/SKILL.md +0 -124
  369. moai_adk/templates/.claude/skills/moai-lang-ruby/examples.md +0 -29
  370. moai_adk/templates/.claude/skills/moai-lang-ruby/reference.md +0 -31
  371. moai_adk/templates/.claude/skills/moai-lang-rust/SKILL.md +0 -127
  372. moai_adk/templates/.claude/skills/moai-lang-rust/examples.md +0 -29
  373. moai_adk/templates/.claude/skills/moai-lang-rust/reference.md +0 -31
  374. moai_adk/templates/.claude/skills/moai-lang-scala/SKILL.md +0 -125
  375. moai_adk/templates/.claude/skills/moai-lang-scala/examples.md +0 -29
  376. moai_adk/templates/.claude/skills/moai-lang-scala/reference.md +0 -30
  377. moai_adk/templates/.claude/skills/moai-lang-shell/SKILL.md +0 -123
  378. moai_adk/templates/.claude/skills/moai-lang-shell/examples.md +0 -29
  379. moai_adk/templates/.claude/skills/moai-lang-shell/reference.md +0 -30
  380. moai_adk/templates/.claude/skills/moai-lang-sql/SKILL.md +0 -124
  381. moai_adk/templates/.claude/skills/moai-lang-sql/examples.md +0 -29
  382. moai_adk/templates/.claude/skills/moai-lang-sql/reference.md +0 -31
  383. moai_adk/templates/.claude/skills/moai-lang-swift/SKILL.md +0 -123
  384. moai_adk/templates/.claude/skills/moai-lang-swift/examples.md +0 -29
  385. moai_adk/templates/.claude/skills/moai-lang-swift/reference.md +0 -30
  386. moai_adk/templates/.claude/skills/moai-lang-typescript/SKILL.md +0 -133
  387. moai_adk/templates/.claude/skills/moai-lang-typescript/examples.md +0 -29
  388. moai_adk/templates/.claude/skills/moai-lang-typescript/reference.md +0 -34
  389. moai_adk/templates/.claude/skills/moai-project-documentation.md +0 -622
  390. moai_adk/templates/.github/workflows/c-tag-validation.yml +0 -11
  391. moai_adk/templates/.github/workflows/cpp-tag-validation.yml +0 -11
  392. moai_adk/templates/.github/workflows/csharp-tag-validation.yml +0 -11
  393. moai_adk/templates/.github/workflows/dart-tag-validation.yml +0 -11
  394. moai_adk/templates/.github/workflows/go-tag-validation.yml +0 -130
  395. moai_adk/templates/.github/workflows/java-tag-validation.yml +0 -11
  396. moai_adk/templates/.github/workflows/javascript-tag-validation.yml +0 -135
  397. moai_adk/templates/.github/workflows/kotlin-tag-validation.yml +0 -11
  398. moai_adk/templates/.github/workflows/php-tag-validation.yml +0 -11
  399. moai_adk/templates/.github/workflows/python-tag-validation.yml +0 -118
  400. moai_adk/templates/.github/workflows/release.yml +0 -118
  401. moai_adk/templates/.github/workflows/ruby-tag-validation.yml +0 -11
  402. moai_adk/templates/.github/workflows/rust-tag-validation.yml +0 -11
  403. moai_adk/templates/.github/workflows/shell-tag-validation.yml +0 -11
  404. moai_adk/templates/.github/workflows/swift-tag-validation.yml +0 -11
  405. moai_adk/templates/.github/workflows/tag-report.yml +0 -269
  406. moai_adk/templates/.github/workflows/tag-validation.yml +0 -186
  407. moai_adk/templates/.github/workflows/typescript-tag-validation.yml +0 -154
  408. moai_adk/templates/.moai/config.json +0 -115
  409. moai_adk/templates/workflows/go-tag-validation.yml +0 -30
  410. moai_adk/templates/workflows/javascript-tag-validation.yml +0 -41
  411. moai_adk/templates/workflows/python-tag-validation.yml +0 -42
  412. moai_adk/templates/workflows/typescript-tag-validation.yml +0 -31
  413. moai_adk-0.15.1.dist-info/METADATA +0 -3094
  414. moai_adk-0.15.1.dist-info/RECORD +0 -365
  415. {moai_adk-0.15.1.dist-info → moai_adk-0.25.4.dist-info}/WHEEL +0 -0
  416. {moai_adk-0.15.1.dist-info → moai_adk-0.25.4.dist-info}/entry_points.txt +0 -0
  417. {moai_adk-0.15.1.dist-info → moai_adk-0.25.4.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,925 @@
1
+ """PostToolUse Hook for Automated SPEC Completion System."""
2
+
3
+ import hashlib
4
+ import logging
5
+ import os
6
+ import re
7
+ import time
8
+ from typing import Any, Dict, List
9
+
10
+
11
+ # SpecGenerator: Placeholder for spec generation functionality
12
+ class SpecGenerator:
13
+ """Placeholder SpecGenerator class for auto-spec completion."""
14
+
15
+ def __init__(self):
16
+ self.name = "SpecGenerator"
17
+
18
+ def generate_spec(self, file_path: str, content: str) -> str:
19
+ """Generate a basic SPEC document."""
20
+ return f"SPEC document for {file_path}\n\nContent analysis:\n{content[:200]}..."
21
+
22
+
23
+ # BaseHook: Simplified base hook class for auto-spec completion
24
+ class BaseHook:
25
+ """Base hook class for auto-spec completion."""
26
+
27
+ def __init__(self):
28
+ self.name = "PostToolAutoSpecCompletion"
29
+ self.description = "PostToolUse Hook for Automated SPEC Completion System"
30
+
31
+
32
+ # Configure logging
33
+ logger = logging.getLogger(__name__)
34
+
35
+
36
+ class PostToolAutoSpecCompletion(BaseHook):
37
+ """
38
+ PostToolUse Hook for automated SPEC completion.
39
+
40
+ This hook detects code file changes after Write/Edit/MultiEdit tools
41
+ and automatically generates complete SPEC documents in EARS format.
42
+ """
43
+
44
+ def __init__(self):
45
+ super().__init__()
46
+ self.spec_generator = SpecGenerator()
47
+ self.auto_config = self._get_auto_spec_config()
48
+
49
+ # Track processed files to avoid duplicates
50
+ self.processed_files = set()
51
+
52
+ def _get_auto_spec_config(self) -> Dict[str, Any]:
53
+ """Get auto-spec completion configuration."""
54
+ try:
55
+ from moai_adk.core.config.config_manager import ConfigManager
56
+
57
+ config = ConfigManager()
58
+ return config.get_value(
59
+ "auto_spec_completion",
60
+ {
61
+ "enabled": True,
62
+ "min_confidence": 0.7,
63
+ "auto_open_editor": True,
64
+ "supported_languages": ["python", "javascript", "typescript", "go"],
65
+ "excluded_patterns": ["test_", "spec_", "__tests__"],
66
+ },
67
+ )
68
+ except ImportError:
69
+ return {
70
+ "enabled": True,
71
+ "min_confidence": 0.7,
72
+ "auto_open_editor": True,
73
+ "supported_languages": ["python", "javascript", "typescript", "go"],
74
+ "excluded_patterns": ["test_", "spec_", "__tests__"],
75
+ }
76
+
77
+ def should_trigger_spec_completion(
78
+ self, tool_name: str, tool_args: Dict[str, Any]
79
+ ) -> bool:
80
+ """
81
+ Determine if spec completion should be triggered.
82
+
83
+ Args:
84
+ tool_name: Name of the tool that was executed
85
+ tool_args: Arguments passed to the tool
86
+
87
+ Returns:
88
+ True if spec completion should be triggered
89
+ """
90
+ # Check if auto-spec completion is enabled
91
+ if not self.auto_config.get("enabled", True):
92
+ logger.debug("Auto-spec completion is disabled")
93
+ return False
94
+
95
+ # Only trigger for Write/Edit/MultiEdit tools
96
+ if tool_name not in ["Write", "Edit", "MultiEdit"]:
97
+ logger.debug(f"Tool {tool_name} does not trigger spec completion")
98
+ return False
99
+
100
+ # Extract file paths from tool arguments
101
+ file_paths = self._extract_file_paths(tool_args)
102
+
103
+ if not file_paths:
104
+ logger.debug("No file paths found in tool arguments")
105
+ return False
106
+
107
+ # Check if any file is a supported language
108
+ supported_files = []
109
+ for file_path in file_paths:
110
+ if self._is_supported_file(file_path):
111
+ supported_files.append(file_path)
112
+ else:
113
+ logger.debug(
114
+ f"File {file_path} is not supported for auto-spec completion"
115
+ )
116
+
117
+ if not supported_files:
118
+ logger.debug("No supported files found")
119
+ return False
120
+
121
+ # Check for excluded patterns
122
+ excluded_files = []
123
+ for file_path in supported_files:
124
+ if self._is_excluded_file(file_path):
125
+ excluded_files.append(file_path)
126
+
127
+ # Filter out excluded files
128
+ target_files = [f for f in supported_files if f not in excluded_files]
129
+
130
+ if not target_files:
131
+ logger.debug("All files are excluded from auto-spec completion")
132
+ return False
133
+
134
+ return True
135
+
136
+ def _extract_file_paths(self, tool_args: Dict[str, Any]) -> List[str]:
137
+ """Extract file paths from tool arguments."""
138
+ file_paths = []
139
+
140
+ # Handle Write tool
141
+ if "file_path" in tool_args:
142
+ file_paths.append(tool_args["file_path"])
143
+
144
+ # Handle Edit tool
145
+ if "file_path" in tool_args:
146
+ file_paths.append(tool_args["file_path"])
147
+
148
+ # Handle MultiEdit tool
149
+ if "edits" in tool_args:
150
+ for edit in tool_args["edits"]:
151
+ if "file_path" in edit:
152
+ file_paths.append(edit["file_path"])
153
+
154
+ # Remove duplicates and resolve relative paths
155
+ unique_paths = []
156
+ for path in file_paths:
157
+ if path not in unique_paths:
158
+ abs_path = os.path.abspath(path)
159
+ unique_paths.append(abs_path)
160
+
161
+ return unique_paths
162
+
163
+ def _is_supported_file(self, file_path: str) -> bool:
164
+ """Check if file is supported for auto-spec completion."""
165
+ # Get file extension
166
+ file_ext = os.path.splitext(file_path)[1].lower()
167
+
168
+ # Map extensions to languages
169
+ supported_extensions = {
170
+ ".py": "python",
171
+ ".js": "javascript",
172
+ ".jsx": "javascript",
173
+ ".ts": "typescript",
174
+ ".tsx": "typescript",
175
+ ".go": "go",
176
+ }
177
+
178
+ if file_ext not in supported_extensions:
179
+ return False
180
+
181
+ # Check if language is supported
182
+ language = supported_extensions[file_ext]
183
+ supported_languages = self.auto_config.get("supported_languages", [])
184
+ return language in supported_languages
185
+
186
+ def _is_excluded_file(self, file_path: str) -> bool:
187
+ """Check if file should be excluded from auto-spec completion."""
188
+ file_name = os.path.basename(file_path)
189
+ file_dir = os.path.basename(os.path.dirname(file_path))
190
+
191
+ excluded_patterns = self.auto_config.get("excluded_patterns", [])
192
+
193
+ for pattern in excluded_patterns:
194
+ # Check filename patterns
195
+ if re.search(pattern, file_name):
196
+ return True
197
+ # Check directory patterns
198
+ if re.search(pattern, file_dir):
199
+ return True
200
+
201
+ return False
202
+
203
+ def detect_code_changes(
204
+ self, tool_name: str, tool_args: Dict[str, Any], result: Any
205
+ ) -> List[str]:
206
+ """
207
+ Detect code changes from tool execution.
208
+
209
+ Args:
210
+ tool_name: Name of the tool that was executed
211
+ tool_args: Arguments passed to the tool
212
+ result: Result from tool execution
213
+
214
+ Returns:
215
+ List of affected file paths
216
+ """
217
+ file_paths = []
218
+
219
+ # Write tool creates new files
220
+ if tool_name == "Write":
221
+ if "file_path" in tool_args:
222
+ file_paths.append(tool_args["file_path"])
223
+
224
+ # Edit tool modifies existing files
225
+ elif tool_name == "Edit":
226
+ if "file_path" in tool_args:
227
+ file_paths.append(tool_args["file_path"])
228
+
229
+ # MultiEdit tool can modify multiple files
230
+ elif tool_name == "MultiEdit":
231
+ if "edits" in tool_args:
232
+ for edit in tool_args["edits"]:
233
+ if "file_path" in edit:
234
+ file_paths.append(edit["file_path"])
235
+
236
+ # Convert to absolute paths
237
+ abs_paths = [os.path.abspath(path) for path in file_paths]
238
+
239
+ # Filter out already processed files
240
+ new_paths = [path for path in abs_paths if path not in self.processed_files]
241
+
242
+ # Add to processed files
243
+ self.processed_files.update(new_paths)
244
+
245
+ return new_paths
246
+
247
+ def calculate_completion_confidence(self, analysis: Dict[str, Any]) -> float:
248
+ """
249
+ Calculate confidence score for SPEC completion.
250
+
251
+ Args:
252
+ analysis: Code analysis result
253
+
254
+ Returns:
255
+ Confidence score between 0.0 and 1.0
256
+ """
257
+ # Default confidence if analysis is incomplete
258
+ if not analysis:
259
+ return 0.5
260
+
261
+ structure_score = analysis.get("structure_score", 0.5)
262
+ domain_accuracy = analysis.get("domain_accuracy", 0.5)
263
+ documentation_level = analysis.get("documentation_level", 0.5)
264
+
265
+ # Weighted calculation
266
+ # Structure clarity: 30%
267
+ # Domain accuracy: 40%
268
+ # Documentation level: 30%
269
+ confidence = (
270
+ structure_score * 0.3 + domain_accuracy * 0.4 + documentation_level * 0.3
271
+ )
272
+
273
+ return min(max(confidence, 0.0), 1.0)
274
+
275
+ def generate_complete_spec(
276
+ self, analysis: Dict[str, Any], file_path: str
277
+ ) -> Dict[str, str]:
278
+ """
279
+ Generate complete SPEC documents in EARS format.
280
+
281
+ Args:
282
+ analysis: Code analysis result
283
+ file_path: Path to the analyzed file
284
+
285
+ Returns:
286
+ Dictionary containing spec.md, plan.md, and acceptance.md
287
+ """
288
+ spec_id = self._generate_spec_id(file_path)
289
+ file_name = os.path.basename(file_path)
290
+
291
+ # Generate basic spec content
292
+ spec_md = self._generate_spec_content(analysis, spec_id, file_name)
293
+ plan_md = self._generate_plan_content(analysis, spec_id, file_name)
294
+ acceptance_md = self._generate_acceptance_content(analysis, spec_id, file_name)
295
+
296
+ return {
297
+ "spec_id": spec_id,
298
+ "spec_md": spec_md,
299
+ "plan_md": plan_md,
300
+ "acceptance_md": acceptance_md,
301
+ }
302
+
303
+ def _generate_spec_id(self, file_path: str) -> str:
304
+ """Generate unique SPEC ID from file path."""
305
+ # Extract meaningful name from file path
306
+ file_name = os.path.basename(file_path)
307
+ name_parts = file_name.split("_")
308
+
309
+ # Convert to uppercase and join
310
+ meaningful_name = "".join(part.upper() for part in name_parts if part)
311
+
312
+ # Add hash to ensure uniqueness
313
+ file_hash = hashlib.md5(file_path.encode()).hexdigest()[:4]
314
+
315
+ return f"{meaningful_name}-{file_hash}"
316
+
317
+ def _generate_spec_content(
318
+ self, analysis: Dict[str, Any], spec_id: str, file_name: str
319
+ ) -> str:
320
+ """Generate main spec.md content."""
321
+ template = f"""---
322
+ "id": "SPEC-{spec_id}",
323
+ "title": "Auto-generated SPEC for {file_name}",
324
+ "title_en": "Auto-generated SPEC for {file_name}",
325
+ "version": "1.0.0",
326
+ "status": "pending",
327
+ "created": "{time.strftime('%Y-%m-%d')}",
328
+ "author": "@alfred-auto",
329
+ "reviewer": "",
330
+ "category": "FEATURE",
331
+ "priority": "MEDIUM",
332
+ "tags": ["auto-generated", "{spec_id}"],
333
+ "language": "en",
334
+ "estimated_complexity": "auto"
335
+ }}
336
+ ---
337
+
338
+ ## Auto-generated SPEC for {file_name}
339
+
340
+ ### Overview
341
+
342
+ {analysis.get('description', 'This spec was auto-generated based on code analysis.')}
343
+
344
+ ### Environment
345
+
346
+ - **Project**: MoAI-ADK Auto-generated SPEC
347
+ - **Language**: {analysis.get('language', 'Python')}
348
+ - **File**: {file_name}
349
+ - **Generation Method**: Automatic analysis-based
350
+ - **Status**: Review required
351
+
352
+ ### Assumptions
353
+
354
+ 1. Code structure is clearly defined
355
+ 2. Domain-specific terminology is expected to be used
356
+ 3. Standard development practices are assumed to be followed
357
+ 4. Generated SPEC will be finalized after user review
358
+
359
+ ### Requirements
360
+
361
+ #### Ubiquitous Requirements
362
+
363
+ - **REQ-001**: System must perform the functionality of {file_name}
364
+ - **REQ-002**: Generated functionality must be stable
365
+ - **REQ-003**: Code must be written in a maintainable form
366
+ - **REQ-004**: Tests must satisfy functional requirements
367
+ - **REQ-005**: Code must comply with project coding standards
368
+
369
+ #### State-driven Requirements
370
+
371
+ {analysis.get('state_requirements', '- **REQ-006**: System must transition from initial state to target state')}
372
+
373
+ #### Event-driven Requirements
374
+
375
+ {analysis.get('event_requirements', '- **REQ-007**: System must respond when user input occurs')}
376
+
377
+ ### Specifications
378
+
379
+ {analysis.get('specifications', '- **SPEC-001**: System must implement requirements')}
380
+
381
+ ### Traceability
382
+
383
+
384
+ ### Edit Guide
385
+
386
+ **User Review Recommendations:**
387
+ 1. ✅ Verify technical clarity
388
+ 2. ✅ Specify requirements
389
+ 3. ✅ Review domain-specific terminology
390
+ 4. ✅ Define state and event requirements
391
+ 5. ✅ Detail specifications
392
+
393
+ **Quality Improvement Suggestions:**
394
+ - Add domain-specific terminology
395
+ - Specify user cases
396
+ - Define performance requirements
397
+ - Add security requirements
398
+ """
399
+ return template
400
+
401
+ def _generate_plan_content(
402
+ self, analysis: Dict[str, Any], spec_id: str, file_name: str
403
+ ) -> str:
404
+ """Generate plan.md content."""
405
+ return f"""---
406
+ "id": "PLAN-{spec_id}",
407
+ "spec_id": "SPEC-{spec_id}",
408
+ "title": "Auto-generated Implementation Plan for {file_name}",
409
+ "version": "1.0.0",
410
+ "status": "pending",
411
+ "created": "{time.strftime('%Y-%m-%d')}",
412
+ "author": "@alfred-auto"
413
+ }}
414
+ ---
415
+
416
+ ## Auto-generated Implementation Plan for {file_name}
417
+
418
+ ### Implementation Phases
419
+
420
+ #### Phase 1: Basic Structure Review (Priority: High)
421
+
422
+ - [ ] Complete code structure analysis
423
+ - [ ] Identify core functionality
424
+ - [ ] Verify dependencies
425
+ - [ ] Set up test environment
426
+
427
+ #### Phase 2: Requirements Specification (Priority: Medium)
428
+
429
+ - [ ] Specify ubiquitous requirements
430
+ - [ ] Define state-driven requirements
431
+ - [ ] Review event-driven requirements
432
+ - [ ] Set performance requirements
433
+
434
+ #### Phase 3: Implementation Planning (Priority: Medium)
435
+
436
+ - [ ] Design module architecture
437
+ - [ ] Define interfaces
438
+ - [ ] Design data structures
439
+ - [ ] Plan error handling
440
+
441
+ #### Phase 4: Test Strategy Development (Priority: High)
442
+
443
+ - [ ] Plan unit tests
444
+ - [ ] Plan integration tests
445
+ - [ ] User story-based testing
446
+ - [ ] Implement test automation
447
+
448
+ ### Technical Approach
449
+
450
+ #### Architecture Design
451
+
452
+ ```
453
+ {analysis.get('architecture', 'User Input → Validation → Business Logic → Data Processing → Output')}
454
+
455
+ [Core Components] → [External Services] → [Data Layer]
456
+ ```
457
+
458
+ #### Core Components
459
+
460
+ 1. **{analysis.get('main_component', 'Main Class')}**: Handle primary business logic
461
+ 2. **{analysis.get('service_component', 'Service Layer')}**: Integrate external services
462
+ 3. **{analysis.get('data_component', 'Data Layer')}**: Process and store data
463
+ 4. **{analysis.get('component_4', 'Validation Layer')}**: Validate input and check validity
464
+
465
+ #### Dependency Management
466
+
467
+ **Utilize Existing Modules:**
468
+ - {analysis.get('existing_modules', 'Utilize standard libraries')}
469
+
470
+ **Add New Modules:**
471
+ - {analysis.get('new_modules', 'Add as needed')}
472
+
473
+ ### Success Criteria
474
+
475
+ #### Functional Criteria
476
+
477
+ - ✅ All requirements implemented
478
+ - ✅ Test coverage 85% or higher
479
+ - ✅ Performance targets met
480
+ - ✅ User requirements satisfied
481
+
482
+ #### Performance Criteria
483
+
484
+ - ✅ Response time {analysis.get('performance_target', 'within 1 second')}
485
+ - ✅ Memory usage optimized
486
+ - ✅ Parallel processing supported
487
+ - ✅ Scalability verified
488
+
489
+ #### Quality Criteria
490
+
491
+ - ✅ Code quality verification passed
492
+ - ✅ Security scanning passed
493
+ - ✅ Documentation completeness verified
494
+ - ✅ Maintainability validated
495
+
496
+ ### Next Steps
497
+
498
+ 1. **Immediate**: Basic structure review (1-2 days)
499
+ 2. **Weekly Goal**: Requirements specification (3-5 days)
500
+ 3. **2-Week Goal**: Implementation completion (7-14 days)
501
+ 4. **Release Preparation**: Testing and validation (14-16 days)
502
+ """
503
+
504
+ def _generate_acceptance_content(
505
+ self, analysis: Dict[str, Any], spec_id: str, file_name: str
506
+ ) -> str:
507
+ """Generate acceptance.md content."""
508
+ return f"""---
509
+ "id": "ACCEPT-{spec_id}",
510
+ "spec_id": "SPEC-{spec_id}",
511
+ "title": "Auto-generated Acceptance Criteria for {file_name}",
512
+ "version": "1.0.0",
513
+ "status": "pending",
514
+ "created": "{time.strftime('%Y-%m-%d')}",
515
+ "author": "@alfred-auto"
516
+ }}
517
+ ---
518
+
519
+ ## Auto-generated Acceptance Criteria for {file_name}
520
+
521
+ ### Acceptance Criteria
522
+
523
+ #### Basic Functionality
524
+
525
+ **Must-have:**
526
+ - [ ] {analysis.get('must_have_1', 'System must operate normally')}
527
+ - [ ] {analysis.get('must_have_2', 'User interface must display correctly')}
528
+ - [ ] {analysis.get('must_have_3', 'Data processing logic must function properly')}
529
+
530
+ **Should-have:**
531
+ - [ ] {analysis.get('should_have_1', 'User experience must be smooth')}
532
+ - [ ] {analysis.get('should_have_2', 'Performance targets must be met')}
533
+
534
+ #### Performance Testing
535
+
536
+ **Performance Requirements:**
537
+ - [ ] Response time: {analysis.get('response_time', 'within 1 second')}
538
+ - [ ] Concurrent users: support {analysis.get('concurrent_users', '100 users')} or more
539
+ - [ ] Memory usage: {analysis.get('memory_usage', '100MB or less')}
540
+ - [ ] CPU utilization: {analysis.get('cpu_usage', '50% or less')}
541
+
542
+ **Load Testing:**
543
+ - [ ] Functional load testing passed
544
+ - [ ] Long-term stability testing passed
545
+ - [ ] Recovery testing passed
546
+
547
+ #### Security Testing
548
+
549
+ **Security Requirements:**
550
+ - [ ] {analysis.get('security_req_1', 'Authentication and authorization verification passed')}
551
+ - [ ] {analysis.get('security_req_2', 'Input validation passed')}
552
+ - [ ] {analysis.get('security_req_3', 'SQL injection protection passed')}
553
+
554
+ **Vulnerability Testing:**
555
+ - [ ] OWASP Top 10 inspection passed
556
+ - [ ] Security scanning passed
557
+ - [ ] Permission settings verification passed
558
+
559
+ #### Compatibility Testing
560
+
561
+ **Browser Compatibility:**
562
+ - [ ] Chrome latest version
563
+ - [ ] Firefox latest version
564
+ - [ ] Safari latest version
565
+ - [ ] Edge latest version
566
+
567
+ **Device Compatibility:**
568
+ - [ ] Desktop (1920x1080)
569
+ - [ ] Tablet (768x1024)
570
+ - [ ] Mobile (375x667)
571
+
572
+ #### User Acceptance Testing
573
+
574
+ **User Scenarios:**
575
+ - [ ] {analysis.get('user_scenario_1', 'General user scenario testing passed')}
576
+ - [ ] {analysis.get('user_scenario_2', 'Administrator scenario testing passed')}
577
+ - [ ] {analysis.get('user_scenario_3', 'Error handling scenario testing passed')}
578
+
579
+ **User Feedback:**
580
+ - [ ] User satisfaction 80% or higher
581
+ - [ ] Feature usability evaluation
582
+ - [ ] Design and UI/UX verification
583
+
584
+ ### Validation Process
585
+
586
+ #### Phase 1: Unit Tests
587
+
588
+ - [ ] Developer testing completed
589
+ - [ ] Code review passed
590
+ - [ ] Automated testing passed
591
+ - [ ] Code coverage 85% or higher
592
+
593
+ #### Phase 2: Integration Tests
594
+
595
+ - [ ] Inter-module integration testing
596
+ - [ ] API integration testing
597
+ - [ ] Database integration testing
598
+ - [ ] External service integration testing
599
+
600
+ #### Phase 3: System Tests
601
+
602
+ - [ ] Full system functionality testing
603
+ - [ ] Performance testing
604
+ - [ ] Security testing
605
+ - [ ] Stability testing
606
+
607
+ #### Phase 4: User Tests
608
+
609
+ - [ ] Internal user testing
610
+ - [ ] Actual user testing
611
+ - [ ] Feedback collection and incorporation
612
+ - [ ] Final acceptance approval
613
+
614
+ ### Validation Templates
615
+
616
+ #### Functionality Validation Template
617
+
618
+ | Function ID | Function Name | Expected Result | Actual Result | Status | Notes |
619
+ |-------------|---------------|-----------------|---------------|--------|-------|
620
+ | FUNC-001 | Function 1 | Success | Testing | In Progress | Description |
621
+ | FUNC-002 | Function 2 | Success | Success | Passed | Description |
622
+ | FUNC-003 | Function 3 | Success | Failed | Failed | Description |
623
+
624
+ #### Performance Validation Template
625
+
626
+ | Test Item | Target | Measured | Status | Notes |
627
+ |-----------|--------|----------|--------|-------|
628
+ | Response time | 1s | 0.8s | Passed | Description |
629
+ | Memory usage | 100MB | 85MB | Passed | Description |
630
+ | CPU utilization | 50% | 45% | Passed | Description |
631
+
632
+ ### Completion Criteria
633
+
634
+ #### Pass Criteria
635
+
636
+ - ✅ All required functionality validation passed
637
+ - ✅ Performance requirements met
638
+ - ✅ Security testing passed
639
+ - ✅ User acceptance passed
640
+ - ✅ Documentation validation completed
641
+
642
+ #### Reporting
643
+
644
+ - [ ] Validation report created
645
+ - [ ] Identified issues documented
646
+ - [ ] Improvements defined
647
+ - [ ] Acceptance approval document prepared
648
+
649
+ **Validation Team:**
650
+ - Developer: @developer
651
+ - QA: @qa_engineer
652
+ - Product Owner: @product_owner
653
+ - Final Approver: @stakeholder
654
+ """
655
+
656
+ def validate_generated_spec(self, spec_content: Dict[str, str]) -> Dict[str, Any]:
657
+ """
658
+ Validate quality of generated spec.
659
+
660
+ Args:
661
+ spec_content: Dictionary with spec.md, plan.md, acceptance_md
662
+
663
+ Returns:
664
+ Validation result with quality metrics
665
+ """
666
+ quality_score = 0.0
667
+ suggestions = []
668
+
669
+ # Check EARS format compliance
670
+ ears_compliance = self._check_ears_compliance(spec_content)
671
+ quality_score += ears_compliance * 0.4
672
+
673
+ # Check completeness
674
+ completeness = self._check_completeness(spec_content)
675
+ quality_score += completeness * 0.3
676
+
677
+ # Check content quality
678
+ content_quality = self._check_content_quality(spec_content)
679
+ quality_score += content_quality * 0.3
680
+
681
+ # Generate suggestions
682
+ if ears_compliance < 0.9:
683
+ suggestions.append("Improvement needed to fully comply with EARS format.")
684
+
685
+ if completeness < 0.8:
686
+ suggestions.append(
687
+ "Requirements and specifications need to be more detailed."
688
+ )
689
+
690
+ if content_quality < 0.7:
691
+ suggestions.append(
692
+ "Domain-specific terminology and technical content need to be added."
693
+ )
694
+
695
+ return {
696
+ "quality_score": min(max(quality_score, 0.0), 1.0),
697
+ "ears_compliance": ears_compliance,
698
+ "completeness": completeness,
699
+ "content_quality": content_quality,
700
+ "suggestions": suggestions,
701
+ }
702
+
703
+ def _check_ears_compliance(self, spec_content: Dict[str, str]) -> float:
704
+ """Check EARS format compliance."""
705
+ spec_md = spec_content.get("spec_md", "")
706
+
707
+ required_sections = [
708
+ "Overview",
709
+ "Environment",
710
+ "Assumptions",
711
+ "Requirements",
712
+ "Specifications",
713
+ ]
714
+
715
+ found_sections = 0
716
+ for section in required_sections:
717
+ if section in spec_md:
718
+ found_sections += 1
719
+
720
+ return found_sections / len(required_sections)
721
+
722
+ def _check_completeness(self, spec_content: Dict[str, str]) -> float:
723
+ """Check content completeness."""
724
+ spec_md = spec_content.get("spec_md", "")
725
+ plan_md = spec_content.get("plan_md", "")
726
+ acceptance_md = spec_content.get("acceptance_md", "")
727
+
728
+ # Check minimum content length
729
+ total_length = len(spec_md) + len(plan_md) + len(acceptance_md)
730
+ length_score = min(total_length / 2000, 1.0) # 2000 chars as baseline
731
+
732
+ # Check for content diversity
733
+ has_requirements = "Requirements" in spec_md
734
+ has_planning = "Implementation Plan" in plan_md
735
+ has_acceptance = "Acceptance" in acceptance_md
736
+
737
+ diversity_score = 0.0
738
+ if has_requirements:
739
+ diversity_score += 0.3
740
+ if has_planning:
741
+ diversity_score += 0.3
742
+ if has_acceptance:
743
+ diversity_score += 0.4
744
+
745
+ return (length_score + diversity_score) / 2
746
+
747
+ def _check_content_quality(self, spec_content: Dict[str, str]) -> float:
748
+ """Check content quality."""
749
+ spec_md = spec_content.get("spec_md", "")
750
+
751
+ # Check for technical terms
752
+ technical_indicators = [
753
+ "API",
754
+ "data",
755
+ "interface",
756
+ "module",
757
+ "component",
758
+ "architecture",
759
+ ]
760
+ technical_score = sum(
761
+ 1 for term in technical_indicators if term in spec_md
762
+ ) / len(technical_indicators)
763
+
764
+ # Check for specificity
765
+ has_requirements = re.search(r"REQ-\d+", spec_md)
766
+ has_specifications = re.search(r"SPEC-\d+", spec_md)
767
+
768
+ specificity_score = 0.0
769
+ if has_requirements:
770
+ specificity_score += 0.5
771
+ if has_specifications:
772
+ specificity_score += 0.5
773
+
774
+ return (technical_score + specificity_score) / 2
775
+
776
+ def create_spec_files(
777
+ self, spec_id: str, content: Dict[str, str], base_dir: str = ".moai/specs"
778
+ ) -> bool:
779
+ """
780
+ Create SPEC files in the correct directory structure.
781
+
782
+ Args:
783
+ spec_id: SPEC identifier
784
+ content: Dictionary with spec_md, plan_md, acceptance_md
785
+ base_dir: Base directory for specs
786
+
787
+ Returns:
788
+ True if files were created successfully
789
+ """
790
+ try:
791
+ # Create spec directory
792
+ spec_dir = os.path.join(base_dir, f"SPEC-{spec_id}")
793
+ os.makedirs(spec_dir, exist_ok=True)
794
+
795
+ # Create files
796
+ files_to_create = [
797
+ ("spec.md", content.get("spec_md", "")),
798
+ ("plan.md", content.get("plan_md", "")),
799
+ ("acceptance.md", content.get("acceptance_md", "")),
800
+ ]
801
+
802
+ for filename, content_text in files_to_create:
803
+ file_path = os.path.join(spec_dir, filename)
804
+ with open(file_path, "w", encoding="utf-8") as f:
805
+ f.write(content_text)
806
+
807
+ logger.info(f"Created spec file: {file_path}")
808
+
809
+ return True
810
+
811
+ except Exception as e:
812
+ logger.error(f"Failed to create spec files: {e}")
813
+ return False
814
+
815
+ def execute(
816
+ self, tool_name: str, tool_args: Dict[str, Any], result: Any = None
817
+ ) -> Dict[str, Any]:
818
+ """
819
+ Execute the auto-spec completion hook.
820
+
821
+ Args:
822
+ tool_name: Name of the tool that was executed
823
+ tool_args: Arguments passed to the tool
824
+ result: Result from tool execution
825
+
826
+ Returns:
827
+ Execution result
828
+ """
829
+ start_time = time.time()
830
+
831
+ try:
832
+ # Check if we should trigger spec completion
833
+ if not self.should_trigger_spec_completion(tool_name, tool_args):
834
+ return {
835
+ "success": False,
836
+ "message": "Auto-spec completion not triggered",
837
+ "execution_time": time.time() - start_time,
838
+ }
839
+
840
+ # Detect code changes
841
+ changed_files = self.detect_code_changes(tool_name, tool_args, result)
842
+
843
+ if not changed_files:
844
+ return {
845
+ "success": False,
846
+ "message": "No code changes detected",
847
+ "execution_time": time.time() - start_time,
848
+ }
849
+
850
+ # Process each changed file
851
+ results = []
852
+ for file_path in changed_files:
853
+ try:
854
+ # Analyze the code file
855
+ analysis = self.spec_generator.analyze(file_path)
856
+
857
+ # Calculate confidence
858
+ confidence = self.calculate_completion_confidence(analysis)
859
+
860
+ # Skip if confidence is too low
861
+ min_confidence = self.auto_config.get("min_confidence", 0.7)
862
+ if confidence < min_confidence:
863
+ logger.info(
864
+ f"Confidence {confidence} below threshold {min_confidence}"
865
+ )
866
+ continue
867
+
868
+ # Generate complete spec
869
+ spec_content = self.generate_complete_spec(analysis, file_path)
870
+
871
+ # Validate quality
872
+ validation = self.validate_generated_spec(spec_content)
873
+
874
+ # Create spec files
875
+ spec_id = spec_content["spec_id"]
876
+ created = self.create_spec_files(spec_id, spec_content)
877
+
878
+ results.append(
879
+ {
880
+ "file_path": file_path,
881
+ "spec_id": spec_id,
882
+ "confidence": confidence,
883
+ "quality_score": validation["quality_score"],
884
+ "created": created,
885
+ }
886
+ )
887
+
888
+ logger.info(f"Auto-generated SPEC for {file_path}: {spec_id}")
889
+
890
+ except Exception as e:
891
+ logger.error(f"Error processing {file_path}: {e}")
892
+ results.append({"file_path": file_path, "error": str(e)})
893
+
894
+ # Generate summary
895
+ successful_creations = [r for r in results if r.get("created", False)]
896
+ failed_creations = [r for r in results if not r.get("created", False)]
897
+
898
+ execution_result = {
899
+ "success": len(successful_creations) > 0,
900
+ "generated_specs": successful_creations,
901
+ "failed_files": failed_creations,
902
+ "execution_time": time.time() - start_time,
903
+ }
904
+
905
+ # Add notification message
906
+ if successful_creations:
907
+ execution_result["message"] = (
908
+ f"Auto-generated {len(successful_creations)} SPEC(s)"
909
+ )
910
+ elif failed_creations:
911
+ execution_result["message"] = (
912
+ "Auto-spec completion attempted but no specs created"
913
+ )
914
+ else:
915
+ execution_result["message"] = "No files required auto-spec completion"
916
+
917
+ return execution_result
918
+
919
+ except Exception as e:
920
+ logger.error(f"Error in auto-spec completion: {e}")
921
+ return {
922
+ "success": False,
923
+ "error": str(e),
924
+ "execution_time": time.time() - start_time,
925
+ }