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,749 @@
1
+ """Confidence Scoring System for Auto-SPEC Generation."""
2
+
3
+ import ast
4
+ import logging
5
+ import re
6
+ import time
7
+ from typing import Any, Dict, List, Tuple
8
+
9
+ # Configure logging
10
+ logger = logging.getLogger(__name__)
11
+
12
+
13
+ # SpecGenerator: Placeholder for spec generation functionality
14
+ class SpecGenerator:
15
+ """Placeholder SpecGenerator class for confidence scoring."""
16
+
17
+ def __init__(self):
18
+ self.name = "SpecGenerator"
19
+
20
+ def generate_spec(self, file_path: str, content: str) -> str:
21
+ """Generate a basic SPEC document."""
22
+ return f"SPEC document for {file_path}\n\nConfidence analysis: {content[:100]}..."
23
+
24
+
25
+ class ConfidenceScoringSystem:
26
+ """
27
+ Advanced confidence scoring system for auto-generated SPECs.
28
+
29
+ This system analyzes code structure, domain relevance, and documentation
30
+ quality to provide confidence scores for SPEC auto-generation.
31
+ """
32
+
33
+ def __init__(self):
34
+ self.spec_generator = SpecGenerator()
35
+ self.word_patterns = {
36
+ "security": [
37
+ "auth",
38
+ "login",
39
+ "password",
40
+ "encrypt",
41
+ "security",
42
+ "bcrypt",
43
+ "hash",
44
+ "token",
45
+ ],
46
+ "data": [
47
+ "model",
48
+ "entity",
49
+ "schema",
50
+ "database",
51
+ "persistence",
52
+ "storage",
53
+ "cache",
54
+ ],
55
+ "api": [
56
+ "api",
57
+ "endpoint",
58
+ "route",
59
+ "controller",
60
+ "service",
61
+ "handler",
62
+ "middleware",
63
+ ],
64
+ "ui": [
65
+ "ui",
66
+ "interface",
67
+ "component",
68
+ "widget",
69
+ "layout",
70
+ "theme",
71
+ "display",
72
+ ],
73
+ "business": ["business", "logic", "process", "workflow", "rule", "policy"],
74
+ "testing": [
75
+ "test",
76
+ "mock",
77
+ "fixture",
78
+ "assertion",
79
+ "verification",
80
+ "validation",
81
+ ],
82
+ }
83
+
84
+ def analyze_code_structure(self, file_path: str) -> Dict[str, float]:
85
+ """
86
+ Analyze code structure quality.
87
+
88
+ Args:
89
+ file_path: Path to the Python code file
90
+
91
+ Returns:
92
+ Dictionary with structure scores
93
+ """
94
+ try:
95
+ with open(file_path, "r", encoding="utf-8") as f:
96
+ code_content = f.read()
97
+
98
+ # Parse AST
99
+ tree = ast.parse(code_content)
100
+
101
+ structure_scores = {
102
+ "class_count": 0,
103
+ "function_count": 0,
104
+ "method_count": 0,
105
+ "import_count": 0,
106
+ "complexity_score": 0.0,
107
+ "nesting_depth": 0,
108
+ "docstring_coverage": 0.0,
109
+ "naming_consistency": 0.0,
110
+ }
111
+
112
+ # Analyze AST nodes
113
+ for node in ast.walk(tree):
114
+ if isinstance(node, ast.ClassDef):
115
+ structure_scores["class_count"] += 1
116
+ # Check if class has docstring
117
+ if ast.get_docstring(node):
118
+ structure_scores["docstring_coverage"] += 0.1
119
+ # Count methods
120
+ for child in ast.walk(node):
121
+ if isinstance(child, ast.FunctionDef):
122
+ structure_scores["method_count"] += 1
123
+
124
+ elif isinstance(node, ast.FunctionDef):
125
+ # Check if function is not a method (not inside a class)
126
+ is_method = False
127
+ for parent in ast.walk(tree):
128
+ if isinstance(parent, ast.ClassDef):
129
+ for child in parent.body:
130
+ if child == node:
131
+ is_method = True
132
+ break
133
+
134
+ if not is_method:
135
+ structure_scores["function_count"] += 1
136
+
137
+ # Check if function has docstring
138
+ if ast.get_docstring(node):
139
+ structure_scores["docstring_coverage"] += 0.1
140
+
141
+ elif isinstance(node, ast.Import) or isinstance(node, ast.ImportFrom):
142
+ structure_scores["import_count"] += 1
143
+
144
+ # Calculate complexity score (cyclomatic complexity approximation)
145
+ structure_scores["complexity_score"] = self._calculate_complexity(tree)
146
+
147
+ # Calculate nesting depth
148
+ structure_scores["nesting_depth"] = self._calculate_nesting_depth(tree)
149
+
150
+ # Calculate naming consistency
151
+ structure_scores["naming_consistency"] = self._calculate_naming_consistency(
152
+ tree
153
+ )
154
+
155
+ # Normalize scores (0-1 range)
156
+ max_classes = 5 # Reasonable upper bound
157
+ max_functions = 20
158
+ max_methods = 50
159
+ max_imports = 15
160
+ max_complexity = 10
161
+ max_nesting = 5
162
+ max_docstring = 1.0
163
+
164
+ normalized_scores = {
165
+ "class_ratio": min(structure_scores["class_count"] / max_classes, 1.0),
166
+ "function_ratio": min(
167
+ structure_scores["function_count"] / max_functions, 1.0
168
+ ),
169
+ "method_ratio": min(
170
+ structure_scores["method_count"] / max_methods, 1.0
171
+ ),
172
+ "import_ratio": min(
173
+ structure_scores["import_count"] / max_imports, 1.0
174
+ ),
175
+ "complexity_ratio": max(
176
+ 0, 1.0 - structure_scores["complexity_score"] / max_complexity
177
+ ),
178
+ "nesting_ratio": max(
179
+ 0, 1.0 - structure_scores["nesting_depth"] / max_nesting
180
+ ),
181
+ "docstring_score": min(
182
+ structure_scores["docstring_coverage"] / max_docstring, 1.0
183
+ ),
184
+ "naming_score": structure_scores["naming_consistency"],
185
+ }
186
+
187
+ return normalized_scores
188
+
189
+ except Exception as e:
190
+ logger.error(f"Error analyzing code structure: {e}")
191
+ return self._get_default_structure_scores()
192
+
193
+ def _calculate_complexity(self, tree: ast.AST) -> float:
194
+ """Calculate approximate cyclomatic complexity."""
195
+ complexity = 1 # Base complexity
196
+
197
+ for node in ast.walk(tree):
198
+ if isinstance(node, (ast.If, ast.For, ast.While, ast.Try, ast.With)):
199
+ complexity += 1
200
+ elif isinstance(node, ast.BoolOp):
201
+ complexity += len(node.values) - 1
202
+
203
+ return complexity
204
+
205
+ def _calculate_nesting_depth(self, tree: ast.AST) -> int:
206
+ """Calculate maximum nesting depth."""
207
+ max_depth = 0
208
+
209
+ def _visit(node, depth):
210
+ nonlocal max_depth
211
+ max_depth = max(max_depth, depth)
212
+
213
+ for child in ast.iter_child_nodes(node):
214
+ if isinstance(child, (ast.If, ast.For, ast.While, ast.Try, ast.With)):
215
+ _visit(child, depth + 1)
216
+ else:
217
+ _visit(child, depth)
218
+
219
+ _visit(tree, 0)
220
+ return max_depth
221
+
222
+ def _calculate_naming_consistency(self, tree: ast.AST) -> float:
223
+ """Calculate naming consistency score."""
224
+ names = []
225
+
226
+ for node in ast.walk(tree):
227
+ if isinstance(node, ast.Name):
228
+ names.append(node.id)
229
+ elif isinstance(node, ast.FunctionDef):
230
+ names.append(node.name)
231
+ elif isinstance(node, ast.ClassDef):
232
+ names.append(node.name)
233
+
234
+ if not names:
235
+ return 1.0
236
+
237
+ # Check naming patterns
238
+ snake_case_count = 0
239
+ camel_case_count = 0
240
+
241
+ for name in names:
242
+ if re.match(r"^[a-z]+(?:_[a-z]+)*$", name):
243
+ snake_case_count += 1
244
+ elif re.match(r"^[A-Z][a-zA-Z0-9]*$", name):
245
+ camel_case_count += 1
246
+
247
+ # Calculate consistency
248
+ total_names = len(names)
249
+ if total_names == 0:
250
+ return 1.0
251
+
252
+ snake_case_ratio = snake_case_count / total_names
253
+ camel_case_ratio = camel_case_count / total_names
254
+
255
+ # Favor consistency over specific style
256
+ if snake_case_ratio > 0.7 or camel_case_ratio > 0.7:
257
+ return 0.9
258
+ elif snake_case_ratio > 0.5 or camel_case_ratio > 0.5:
259
+ return 0.7
260
+ else:
261
+ return 0.5
262
+
263
+ def _get_default_structure_scores(self) -> Dict[str, float]:
264
+ """Get default structure scores for error cases."""
265
+ return {
266
+ "class_ratio": 0.5,
267
+ "function_ratio": 0.5,
268
+ "method_ratio": 0.5,
269
+ "import_ratio": 0.5,
270
+ "complexity_ratio": 0.7,
271
+ "nesting_ratio": 0.7,
272
+ "docstring_score": 0.3,
273
+ "naming_score": 0.5,
274
+ }
275
+
276
+ def analyze_domain_relevance(self, file_path: str) -> Dict[str, float]:
277
+ """
278
+ Analyze domain relevance and keyword patterns.
279
+
280
+ Args:
281
+ file_path: Path to the code file
282
+
283
+ Returns:
284
+ Dictionary with domain relevance scores
285
+ """
286
+ try:
287
+ with open(file_path, "r", encoding="utf-8") as f:
288
+ content = f.read()
289
+
290
+ # Normalize content
291
+ content = content.lower()
292
+
293
+ # Check for domain-specific patterns
294
+ domain_scores = {}
295
+
296
+ for domain, patterns in self.word_patterns.items():
297
+ matches = 0
298
+ for pattern in patterns:
299
+ if pattern in content:
300
+ matches += 1
301
+ # Normalize by number of patterns
302
+ domain_scores[f"{domain}_coverage"] = matches / len(patterns)
303
+
304
+ # Calculate overall domain relevance
305
+ total_relevance = sum(domain_scores.values())
306
+ domain_scores["overall_relevance"] = min(
307
+ total_relevance / len(self.word_patterns), 1.0
308
+ )
309
+
310
+ # Calculate domain specificity (how focused the code is)
311
+ max_domain = max(domain_scores.values()) if domain_scores.values() else 0
312
+ domain_scores["specificity"] = max_domain
313
+
314
+ # Calculate technical vocabulary density
315
+ technical_words = len(
316
+ re.findall(
317
+ r"\b(?:api|endpoint|service|controller|model|entity|schema|database|cache|auth|login|password|token|session|user|admin|customer|product|order|payment|billing|subscription|plan|feature|function|method|class|interface|abstract|extends|implements|override|virtual|static|dynamic|async|await|promise|callback|event|handler|middleware|filter|validator|transformer|processor|worker|thread|queue|job|task|cron|scheduler|config|setting|env|variable|constant|property|attribute|field|column|table|index|constraint|foreign|primary|unique|notnull|default|check|trigger|procedure|function|stored|view|materialized|temp|temporary|permanent|persistent|volatile|in-memory|file-based|disk-based|cloud|distributed|clustered|load-balanced|scalable|high-availability|fault-tolerant|redundant|backup|restore|migration|version|branch|merge|conflict|resolve|commit|push|pull|fork|clone|repository|github|gitlab|bitbucket|ci|cd|pipeline|workflow|deployment|staging|production|development|testing|unit|integration|e2e|performance|load|stress|security|vulnerability|attack|breach|authentication|authorization|encryption|decryption|hash|salt|pepper|session|cookie|jwt|oauth|ldap|saml|rbac|abac|detection|prevention|monitoring|logging|tracing|metrics|analytics|dashboard|report|chart|graph|visualization|ui|ux|frontend|backend|fullstack|mobile|web|desktop|cross-platform|native|hybrid|responsive|adaptive|progressive|spa|pwa|ssr|csr|mvc|mvvm|riot|angular|react|vue|ember|backbone|knockout|jquery|vanilla|plain|pure|framework|library|package|module|bundle|dependency|require|import|export|include|extend|inherit|compose|aggregate|delegate|proxy|facade|adapter|bridge|decorator|singleton|factory|builder|prototype|command|observer|strategy|state|chain|iterator|visitor|mediator|composite|flyweight|proxy|interpreter|template|method|abstract|factory|builder|prototype|singleton|adapter|bridge|composite|decorator|facade|flyweight|proxy|chain|command|iterator|mediator|memento|observer|state|strategy|template|visitor)\b",
318
+ content,
319
+ )
320
+ )
321
+ total_words = len(content.split())
322
+
323
+ if total_words > 0:
324
+ domain_scores["technical_density"] = min(
325
+ technical_words / total_words, 1.0
326
+ )
327
+ else:
328
+ domain_scores["technical_density"] = 0.0
329
+
330
+ return domain_scores
331
+
332
+ except Exception as e:
333
+ logger.error(f"Error analyzing domain relevance: {e}")
334
+ return {
335
+ "security_coverage": 0.0,
336
+ "data_coverage": 0.0,
337
+ "api_coverage": 0.0,
338
+ "ui_coverage": 0.0,
339
+ "business_coverage": 0.0,
340
+ "testing_coverage": 0.0,
341
+ "overall_relevance": 0.5,
342
+ "specificity": 0.5,
343
+ "technical_density": 0.3,
344
+ }
345
+
346
+ def analyze_documentation_quality(self, file_path: str) -> Dict[str, float]:
347
+ """
348
+ Analyze documentation quality.
349
+
350
+ Args:
351
+ file_path: Path to the code file
352
+
353
+ Returns:
354
+ Dictionary with documentation scores
355
+ """
356
+ try:
357
+ with open(file_path, "r", encoding="utf-8") as f:
358
+ content = f.read()
359
+
360
+ doc_scores = {
361
+ "docstring_coverage": 0.0,
362
+ "comment_density": 0.0,
363
+ "explanation_quality": 0.0,
364
+ "examples_present": 0.0,
365
+ "parameter_documentation": 0.0,
366
+ "return_documentation": 0.0,
367
+ "exception_documentation": 0.0,
368
+ }
369
+
370
+ # Parse AST for docstring analysis
371
+ tree = ast.parse(content)
372
+
373
+ total_functions = 0
374
+ documented_functions = 0
375
+ documented_classes = 0
376
+ total_classes = 0
377
+
378
+ for node in ast.walk(tree):
379
+ if isinstance(node, ast.FunctionDef):
380
+ total_functions += 1
381
+ if ast.get_docstring(node):
382
+ documented_functions += 1
383
+ # Check for parameter documentation
384
+ if ":" in ast.get_docstring(
385
+ node
386
+ ) or "param" in ast.get_docstring(node):
387
+ doc_scores["parameter_documentation"] = 0.8
388
+ if "return" in ast.get_docstring(
389
+ node
390
+ ) or "->" in ast.get_docstring(node):
391
+ doc_scores["return_documentation"] = 0.8
392
+ if "raise" in ast.get_docstring(
393
+ node
394
+ ) or "exception" in ast.get_docstring(node):
395
+ doc_scores["exception_documentation"] = 0.8
396
+
397
+ elif isinstance(node, ast.ClassDef):
398
+ total_classes += 1
399
+ if ast.get_docstring(node):
400
+ documented_classes += 1
401
+
402
+ # Calculate docstring coverage
403
+ if total_functions > 0:
404
+ doc_scores["docstring_coverage"] = (
405
+ documented_functions / total_functions
406
+ )
407
+ if total_classes > 0:
408
+ class_coverage = documented_classes / total_classes
409
+ doc_scores["docstring_coverage"] = max(
410
+ doc_scores["docstring_coverage"], class_coverage
411
+ )
412
+
413
+ # Calculate comment density
414
+ lines = content.split("\n")
415
+ comment_lines = 0
416
+ code_lines = 0
417
+
418
+ for line in lines:
419
+ stripped = line.strip()
420
+ if stripped.startswith("#"):
421
+ comment_lines += 1
422
+ elif (
423
+ stripped
424
+ and not stripped.startswith('"""')
425
+ and not stripped.startswith("'''")
426
+ ):
427
+ code_lines += 1
428
+
429
+ if code_lines > 0:
430
+ doc_scores["comment_density"] = min(comment_lines / code_lines, 1.0)
431
+
432
+ # Check for examples in docstrings
433
+ total_docstring_length = len(ast.get_docstring(tree) or "")
434
+ if total_docstring_length > 0:
435
+ example_count = len(
436
+ re.findall(r">>>|Example:|example:|\b\d+\.\s", content)
437
+ )
438
+ doc_scores["examples_present"] = min(example_count / 3, 1.0)
439
+
440
+ # Calculate explanation quality based on docstring content
441
+ docstring_content = ast.get_docstring(tree) or ""
442
+ if docstring_content:
443
+ # Check for good explanation indicators
444
+ explanation_indicators = [
445
+ "provides",
446
+ "allows",
447
+ "enables",
448
+ "implements",
449
+ "handles",
450
+ "processes",
451
+ "manages",
452
+ ]
453
+ explanation_count = sum(
454
+ 1
455
+ for indicator in explanation_indicators
456
+ if indicator in docstring_content
457
+ )
458
+ doc_scores["explanation_quality"] = min(
459
+ explanation_count / len(explanation_indicators), 1.0
460
+ )
461
+
462
+ return doc_scores
463
+
464
+ except Exception as e:
465
+ logger.error(f"Error analyzing documentation quality: {e}")
466
+ return {
467
+ "docstring_coverage": 0.3,
468
+ "comment_density": 0.2,
469
+ "explanation_quality": 0.3,
470
+ "examples_present": 0.0,
471
+ "parameter_documentation": 0.2,
472
+ "return_documentation": 0.2,
473
+ "exception_documentation": 0.1,
474
+ }
475
+
476
+ def calculate_confidence_score(
477
+ self,
478
+ file_path: str,
479
+ structure_weights: Dict[str, float] = None,
480
+ domain_weights: Dict[str, float] = None,
481
+ doc_weights: Dict[str, float] = None,
482
+ ) -> Tuple[float, Dict[str, Any]]:
483
+ """
484
+ Calculate overall confidence score for auto-SPEC generation.
485
+
486
+ Args:
487
+ file_path: Path to the code file
488
+ structure_weights: Weights for structure analysis
489
+ domain_weights: Weights for domain analysis
490
+ doc_weights: Weights for documentation analysis
491
+
492
+ Returns:
493
+ Tuple of (confidence_score, detailed_analysis)
494
+ """
495
+ start_time = time.time()
496
+
497
+ # Default weights
498
+ default_structure_weights = {
499
+ "class_ratio": 0.1,
500
+ "function_ratio": 0.1,
501
+ "method_ratio": 0.1,
502
+ "import_ratio": 0.1,
503
+ "complexity_ratio": 0.15,
504
+ "nesting_ratio": 0.15,
505
+ "docstring_score": 0.15,
506
+ "naming_score": 0.15,
507
+ }
508
+
509
+ default_domain_weights = {
510
+ "overall_relevance": 0.3,
511
+ "specificity": 0.2,
512
+ "technical_density": 0.3,
513
+ "security_coverage": 0.1,
514
+ "data_coverage": 0.1,
515
+ }
516
+
517
+ default_doc_weights = {
518
+ "docstring_coverage": 0.3,
519
+ "comment_density": 0.2,
520
+ "explanation_quality": 0.2,
521
+ "examples_present": 0.1,
522
+ "parameter_documentation": 0.1,
523
+ "return_documentation": 0.1,
524
+ }
525
+
526
+ # Use provided weights or defaults
527
+ structure_weights = structure_weights or default_structure_weights
528
+ domain_weights = domain_weights or default_domain_weights
529
+ doc_weights = doc_weights or default_doc_weights
530
+
531
+ # Analyze code
532
+ structure_analysis = self.analyze_code_structure(file_path)
533
+ domain_analysis = self.analyze_domain_relevance(file_path)
534
+ doc_analysis = self.analyze_documentation_quality(file_path)
535
+
536
+ # Calculate weighted scores
537
+ structure_score = sum(
538
+ structure_analysis[key] * structure_weights.get(key, 0)
539
+ for key in structure_analysis
540
+ )
541
+
542
+ domain_score = sum(
543
+ domain_analysis[key] * domain_weights.get(key, 0) for key in domain_analysis
544
+ )
545
+
546
+ doc_score = sum(
547
+ doc_analysis[key] * doc_weights.get(key, 0) for key in doc_analysis
548
+ )
549
+
550
+ # Final confidence score (weighted average)
551
+ total_weights = (
552
+ sum(structure_weights.values())
553
+ + sum(domain_weights.values())
554
+ + sum(doc_weights.values())
555
+ )
556
+
557
+ final_confidence = (structure_score + domain_score + doc_score) / total_weights
558
+
559
+ # Round to 2 decimal places
560
+ final_confidence = round(final_confidence, 2)
561
+
562
+ # Create detailed analysis
563
+ detailed_analysis = {
564
+ "file_path": file_path,
565
+ "analysis_time": time.time() - start_time,
566
+ "confidence_score": final_confidence,
567
+ "structure_analysis": {
568
+ "score": round(structure_score, 2),
569
+ "details": structure_analysis,
570
+ "weights": structure_weights,
571
+ },
572
+ "domain_analysis": {
573
+ "score": round(domain_score, 2),
574
+ "details": domain_analysis,
575
+ "weights": domain_weights,
576
+ },
577
+ "documentation_analysis": {
578
+ "score": round(doc_score, 2),
579
+ "details": doc_analysis,
580
+ "weights": doc_weights,
581
+ },
582
+ "recommendations": self._generate_recommendations(
583
+ structure_analysis, domain_analysis, doc_analysis
584
+ ),
585
+ }
586
+
587
+ return final_confidence, detailed_analysis
588
+
589
+ def _generate_recommendations(
590
+ self, structure_analysis: Dict, domain_analysis: Dict, doc_analysis: Dict
591
+ ) -> List[str]:
592
+ """Generate improvement recommendations."""
593
+ recommendations = []
594
+
595
+ # Structure recommendations
596
+ if structure_analysis.get("docstring_score", 0) < 0.5:
597
+ recommendations.append(
598
+ "Add more docstrings to improve documentation coverage"
599
+ )
600
+
601
+ if structure_analysis.get("complexity_ratio", 0) < 0.7:
602
+ recommendations.append(
603
+ "Consider refactoring complex functions to improve maintainability"
604
+ )
605
+
606
+ if structure_analysis.get("naming_score", 0) < 0.7:
607
+ recommendations.append(
608
+ "Improve naming consistency (use consistent naming convention)"
609
+ )
610
+
611
+ # Domain recommendations
612
+ if domain_analysis.get("overall_relevance", 0) < 0.6:
613
+ recommendations.append(
614
+ "Add domain-specific terminology to improve relevance"
615
+ )
616
+
617
+ if domain_analysis.get("technical_density", 0) < 0.3:
618
+ recommendations.append(
619
+ "Increase technical vocabulary for better specification"
620
+ )
621
+
622
+ # Documentation recommendations
623
+ if doc_analysis.get("examples_present", 0) < 0.5:
624
+ recommendations.append(
625
+ "Add usage examples in docstrings for better understanding"
626
+ )
627
+
628
+ if doc_analysis.get("parameter_documentation", 0) < 0.5:
629
+ recommendations.append("Document function parameters and return values")
630
+
631
+ return recommendations[:5] # Return top 5 recommendations
632
+
633
+ def validate_confidence_threshold(
634
+ self, confidence_score: float, threshold: float = 0.7, strict_mode: bool = False
635
+ ) -> Dict[str, Any]:
636
+ """
637
+ Validate confidence score against threshold.
638
+
639
+ Args:
640
+ confidence_score: Calculated confidence score
641
+ threshold: Minimum confidence threshold
642
+ strict_mode: Whether to use strict validation
643
+
644
+ Returns:
645
+ Validation result
646
+ """
647
+ if strict_mode:
648
+ # Strict mode: all scores must meet threshold
649
+ meets_threshold = confidence_score >= threshold
650
+ else:
651
+ # Normal mode: average score meets threshold
652
+ meets_threshold = confidence_score >= threshold
653
+
654
+ validation_result = {
655
+ "meets_threshold": meets_threshold,
656
+ "confidence_score": confidence_score,
657
+ "threshold": threshold,
658
+ "difference": confidence_score - threshold,
659
+ "recommendation": self._get_threshold_recommendation(
660
+ confidence_score, threshold
661
+ ),
662
+ }
663
+
664
+ return validation_result
665
+
666
+ def _get_threshold_recommendation(
667
+ self, confidence_score: float, threshold: float
668
+ ) -> str:
669
+ """Get recommendation based on confidence score."""
670
+ if confidence_score >= threshold:
671
+ if confidence_score >= 0.9:
672
+ return "Excellent confidence level - auto-spec generation recommended"
673
+ elif confidence_score >= 0.8:
674
+ return "Good confidence level - auto-spec generation recommended"
675
+ else:
676
+ return "Acceptable confidence level - auto-spec generation recommended"
677
+ else:
678
+ if confidence_score >= 0.6:
679
+ return "Marginal confidence level - manual review recommended"
680
+ elif confidence_score >= 0.4:
681
+ return "Low confidence level - significant improvements needed"
682
+ else:
683
+ return "Very low confidence level - complete redesign recommended"
684
+
685
+ def get_confidence_breakdown(self, confidence_score: float) -> Dict[str, Any]:
686
+ """Get detailed breakdown of confidence score components."""
687
+ return {
688
+ "overall_score": confidence_score,
689
+ "interpretation": self._interpret_confidence_score(confidence_score),
690
+ "risk_level": self._get_risk_level(confidence_score),
691
+ "action_required": self._get_action_required(confidence_score),
692
+ }
693
+
694
+ def _interpret_confidence_score(self, score: float) -> str:
695
+ """Interpret confidence score meaning."""
696
+ if score >= 0.9:
697
+ return "Excellent - Very high likelihood of generating a quality SPEC"
698
+ elif score >= 0.8:
699
+ return "Good - High likelihood of generating a quality SPEC"
700
+ elif score >= 0.7:
701
+ return "Acceptable - Moderate likelihood of generating a quality SPEC"
702
+ elif score >= 0.6:
703
+ return "Marginal - Low likelihood of generating a quality SPEC"
704
+ elif score >= 0.4:
705
+ return "Poor - Very low likelihood of generating a quality SPEC"
706
+ else:
707
+ return "Very Poor - Extremely low likelihood of generating a quality SPEC"
708
+
709
+ def _get_risk_level(self, score: float) -> str:
710
+ """Get risk level based on confidence score."""
711
+ if score >= 0.8:
712
+ return "Low"
713
+ elif score >= 0.6:
714
+ return "Medium"
715
+ elif score >= 0.4:
716
+ return "High"
717
+ else:
718
+ return "Critical"
719
+
720
+ def _get_action_required(self, score: float) -> str:
721
+ """Get required action based on confidence score."""
722
+ if score >= 0.7:
723
+ return "Auto-generate SPEC"
724
+ elif score >= 0.5:
725
+ return "Generate SPEC with manual review"
726
+ else:
727
+ return "Do not auto-generate - require manual creation"
728
+
729
+
730
+ # Utility function for backwards compatibility
731
+ def calculate_completion_confidence(analysis: Dict[str, Any]) -> float:
732
+ """
733
+ Backwards compatibility function.
734
+
735
+ Args:
736
+ analysis: Code analysis result
737
+
738
+ Returns:
739
+ Confidence score
740
+ """
741
+ scorer = ConfidenceScoringSystem()
742
+
743
+ # Extract file path from analysis or use default
744
+ file_path = analysis.get("file_path", "dummy_file.py")
745
+
746
+ # Calculate confidence score
747
+ confidence, detailed_analysis = scorer.calculate_confidence_score(file_path)
748
+
749
+ return confidence