moai-adk 0.11.0__py3-none-any.whl → 0.12.1__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 (265) hide show
  1. moai_adk/core/issue_creator.py +2 -2
  2. moai_adk/core/project/detector.py +285 -12
  3. moai_adk/templates/.claude/agents/alfred/cc-manager.md +316 -0
  4. moai_adk/templates/.claude/agents/alfred/debug-helper.md +208 -0
  5. moai_adk/templates/.claude/agents/alfred/doc-syncer.md +214 -0
  6. moai_adk/templates/.claude/agents/alfred/git-manager.md +406 -0
  7. moai_adk/templates/.claude/agents/alfred/implementation-planner.md +350 -0
  8. moai_adk/templates/.claude/agents/alfred/project-manager.md +273 -0
  9. moai_adk/templates/.claude/agents/alfred/quality-gate.md +343 -0
  10. moai_adk/templates/.claude/agents/alfred/skill-factory.md +865 -0
  11. moai_adk/templates/.claude/agents/alfred/spec-builder.md +287 -0
  12. moai_adk/templates/.claude/agents/alfred/tag-agent.md +287 -0
  13. moai_adk/templates/.claude/agents/alfred/tdd-implementer.md +326 -0
  14. moai_adk/templates/.claude/agents/alfred/trust-checker.md +375 -0
  15. moai_adk/templates/.claude/commands/alfred/0-project.md +1187 -0
  16. moai_adk/templates/.claude/commands/alfred/1-plan.md +734 -0
  17. moai_adk/templates/.claude/commands/alfred/2-run.md +551 -0
  18. moai_adk/templates/.claude/commands/alfred/3-sync.md +689 -0
  19. moai_adk/templates/.claude/commands/alfred/9-feedback.md +149 -0
  20. moai_adk/templates/.claude/hooks/alfred/alfred_hooks.py +208 -0
  21. moai_adk/templates/.claude/hooks/alfred/core/project.py +744 -0
  22. moai_adk/templates/.claude/hooks/alfred/core/timeout.py +136 -0
  23. moai_adk/templates/.claude/hooks/alfred/core/ttl_cache.py +109 -0
  24. moai_adk/templates/.claude/hooks/alfred/core/version_cache.py +198 -0
  25. moai_adk/templates/.claude/hooks/alfred/notification__handle_events.py +94 -0
  26. moai_adk/templates/.claude/hooks/alfred/post_tool__log_changes.py +94 -0
  27. moai_adk/templates/.claude/hooks/alfred/pre_tool__auto_checkpoint.py +100 -0
  28. moai_adk/templates/.claude/hooks/alfred/session_end__cleanup.py +94 -0
  29. moai_adk/templates/.claude/hooks/alfred/session_start__show_project_info.py +94 -0
  30. moai_adk/templates/.claude/hooks/alfred/shared/core/__init__.py +170 -0
  31. moai_adk/templates/.claude/hooks/alfred/shared/core/checkpoint.py +271 -0
  32. moai_adk/templates/.claude/hooks/alfred/shared/core/context.py +67 -0
  33. moai_adk/templates/.claude/hooks/alfred/shared/core/project.py +749 -0
  34. moai_adk/templates/.claude/hooks/alfred/shared/core/tags.py +230 -0
  35. moai_adk/templates/.claude/hooks/alfred/shared/core/version_cache.py +198 -0
  36. moai_adk/templates/.claude/hooks/alfred/shared/handlers/__init__.py +21 -0
  37. moai_adk/templates/.claude/hooks/alfred/shared/handlers/notification.py +156 -0
  38. moai_adk/templates/.claude/hooks/alfred/shared/handlers/session.py +174 -0
  39. moai_adk/templates/.claude/hooks/alfred/shared/handlers/tool.py +87 -0
  40. moai_adk/templates/.claude/hooks/alfred/shared/handlers/user.py +61 -0
  41. moai_adk/templates/.claude/hooks/alfred/stop__handle_interrupt.py +94 -0
  42. moai_adk/templates/.claude/hooks/alfred/subagent_stop__handle_subagent_end.py +94 -0
  43. moai_adk/templates/.claude/hooks/alfred/user_prompt__jit_load_docs.py +111 -0
  44. moai_adk/templates/.claude/hooks/alfred/utils/__init__.py +1 -0
  45. moai_adk/templates/.claude/hooks/alfred/utils/timeout.py +136 -0
  46. moai_adk/templates/.claude/output-styles/alfred/agentic-coding.md +640 -0
  47. moai_adk/templates/.claude/output-styles/alfred/moai-adk-learning.md +696 -0
  48. moai_adk/templates/.claude/output-styles/alfred/study-with-alfred.md +474 -0
  49. moai_adk/templates/.claude/settings.json +144 -0
  50. moai_adk/templates/.claude/skills/moai-alfred-ears-authoring/SKILL.md +113 -0
  51. moai_adk/templates/.claude/skills/moai-alfred-ears-authoring/examples.md +29 -0
  52. moai_adk/templates/.claude/skills/moai-alfred-ears-authoring/reference.md +28 -0
  53. moai_adk/templates/.claude/skills/moai-alfred-git-workflow/SKILL.md +122 -0
  54. moai_adk/templates/.claude/skills/moai-alfred-git-workflow/examples.md +29 -0
  55. moai_adk/templates/.claude/skills/moai-alfred-git-workflow/reference.md +29 -0
  56. moai_adk/templates/.claude/skills/moai-alfred-interactive-questions/SKILL.md +237 -0
  57. moai_adk/templates/.claude/skills/moai-alfred-interactive-questions/examples.md +615 -0
  58. moai_adk/templates/.claude/skills/moai-alfred-interactive-questions/reference.md +653 -0
  59. moai_adk/templates/.claude/skills/moai-alfred-language-detection/SKILL.md +113 -0
  60. moai_adk/templates/.claude/skills/moai-alfred-language-detection/examples.md +29 -0
  61. moai_adk/templates/.claude/skills/moai-alfred-language-detection/reference.md +28 -0
  62. moai_adk/templates/.claude/skills/moai-alfred-spec-metadata-validation/SKILL.md +113 -0
  63. moai_adk/templates/.claude/skills/moai-alfred-spec-metadata-validation/examples.md +29 -0
  64. moai_adk/templates/.claude/skills/moai-alfred-spec-metadata-validation/reference.md +28 -0
  65. moai_adk/templates/.claude/skills/moai-alfred-tag-scanning/SKILL.md +113 -0
  66. moai_adk/templates/.claude/skills/moai-alfred-tag-scanning/examples.md +29 -0
  67. moai_adk/templates/.claude/skills/moai-alfred-tag-scanning/reference.md +28 -0
  68. moai_adk/templates/.claude/skills/moai-alfred-trust-validation/SKILL.md +113 -0
  69. moai_adk/templates/.claude/skills/moai-alfred-trust-validation/examples.md +29 -0
  70. moai_adk/templates/.claude/skills/moai-alfred-trust-validation/reference.md +28 -0
  71. moai_adk/templates/.claude/skills/moai-cc-agents/SKILL.md +269 -0
  72. moai_adk/templates/.claude/skills/moai-cc-agents/templates/agent-template.md +32 -0
  73. moai_adk/templates/.claude/skills/moai-cc-claude-md/SKILL.md +298 -0
  74. moai_adk/templates/.claude/skills/moai-cc-claude-md/templates/CLAUDE-template.md +26 -0
  75. moai_adk/templates/.claude/skills/moai-cc-commands/SKILL.md +307 -0
  76. moai_adk/templates/.claude/skills/moai-cc-commands/templates/command-template.md +21 -0
  77. moai_adk/templates/.claude/skills/moai-cc-hooks/SKILL.md +252 -0
  78. moai_adk/templates/.claude/skills/moai-cc-hooks/scripts/pre-bash-check.sh +19 -0
  79. moai_adk/templates/.claude/skills/moai-cc-hooks/scripts/preserve-permissions.sh +19 -0
  80. moai_adk/templates/.claude/skills/moai-cc-hooks/scripts/validate-bash-command.py +24 -0
  81. moai_adk/templates/.claude/skills/moai-cc-mcp-plugins/SKILL.md +199 -0
  82. moai_adk/templates/.claude/skills/moai-cc-mcp-plugins/templates/settings-mcp-template.json +39 -0
  83. moai_adk/templates/.claude/skills/moai-cc-memory/SKILL.md +316 -0
  84. moai_adk/templates/.claude/skills/moai-cc-memory/templates/session-summary-template.md +18 -0
  85. moai_adk/templates/.claude/skills/moai-cc-settings/SKILL.md +263 -0
  86. moai_adk/templates/.claude/skills/moai-cc-settings/templates/settings-complete-template.json +30 -0
  87. moai_adk/templates/.claude/skills/moai-cc-skills/SKILL.md +291 -0
  88. moai_adk/templates/.claude/skills/moai-cc-skills/templates/SKILL-template.md +15 -0
  89. moai_adk/templates/.claude/skills/moai-domain-backend/SKILL.md +290 -0
  90. moai_adk/templates/.claude/skills/moai-domain-backend/examples.md +1633 -0
  91. moai_adk/templates/.claude/skills/moai-domain-backend/reference.md +660 -0
  92. moai_adk/templates/.claude/skills/moai-domain-cli-tool/SKILL.md +123 -0
  93. moai_adk/templates/.claude/skills/moai-domain-cli-tool/examples.md +29 -0
  94. moai_adk/templates/.claude/skills/moai-domain-cli-tool/reference.md +30 -0
  95. moai_adk/templates/.claude/skills/moai-domain-data-science/SKILL.md +123 -0
  96. moai_adk/templates/.claude/skills/moai-domain-data-science/examples.md +29 -0
  97. moai_adk/templates/.claude/skills/moai-domain-data-science/reference.md +30 -0
  98. moai_adk/templates/.claude/skills/moai-domain-database/SKILL.md +123 -0
  99. moai_adk/templates/.claude/skills/moai-domain-database/examples.md +29 -0
  100. moai_adk/templates/.claude/skills/moai-domain-database/reference.md +30 -0
  101. moai_adk/templates/.claude/skills/moai-domain-devops/SKILL.md +124 -0
  102. moai_adk/templates/.claude/skills/moai-domain-devops/examples.md +29 -0
  103. moai_adk/templates/.claude/skills/moai-domain-devops/reference.md +31 -0
  104. moai_adk/templates/.claude/skills/moai-domain-frontend/SKILL.md +124 -0
  105. moai_adk/templates/.claude/skills/moai-domain-frontend/examples.md +29 -0
  106. moai_adk/templates/.claude/skills/moai-domain-frontend/reference.md +31 -0
  107. moai_adk/templates/.claude/skills/moai-domain-ml/SKILL.md +123 -0
  108. moai_adk/templates/.claude/skills/moai-domain-ml/examples.md +29 -0
  109. moai_adk/templates/.claude/skills/moai-domain-ml/reference.md +30 -0
  110. moai_adk/templates/.claude/skills/moai-domain-mobile-app/SKILL.md +123 -0
  111. moai_adk/templates/.claude/skills/moai-domain-mobile-app/examples.md +29 -0
  112. moai_adk/templates/.claude/skills/moai-domain-mobile-app/reference.md +30 -0
  113. moai_adk/templates/.claude/skills/moai-domain-security/SKILL.md +123 -0
  114. moai_adk/templates/.claude/skills/moai-domain-security/examples.md +29 -0
  115. moai_adk/templates/.claude/skills/moai-domain-security/reference.md +30 -0
  116. moai_adk/templates/.claude/skills/moai-domain-web-api/SKILL.md +123 -0
  117. moai_adk/templates/.claude/skills/moai-domain-web-api/examples.md +29 -0
  118. moai_adk/templates/.claude/skills/moai-domain-web-api/reference.md +30 -0
  119. moai_adk/templates/.claude/skills/moai-essentials-debug/SKILL.md +303 -0
  120. moai_adk/templates/.claude/skills/moai-essentials-debug/examples.md +1064 -0
  121. moai_adk/templates/.claude/skills/moai-essentials-debug/reference.md +1047 -0
  122. moai_adk/templates/.claude/skills/moai-essentials-perf/SKILL.md +113 -0
  123. moai_adk/templates/.claude/skills/moai-essentials-perf/examples.md +29 -0
  124. moai_adk/templates/.claude/skills/moai-essentials-perf/reference.md +28 -0
  125. moai_adk/templates/.claude/skills/moai-essentials-refactor/SKILL.md +113 -0
  126. moai_adk/templates/.claude/skills/moai-essentials-refactor/examples.md +29 -0
  127. moai_adk/templates/.claude/skills/moai-essentials-refactor/reference.md +28 -0
  128. moai_adk/templates/.claude/skills/moai-essentials-review/SKILL.md +113 -0
  129. moai_adk/templates/.claude/skills/moai-essentials-review/examples.md +29 -0
  130. moai_adk/templates/.claude/skills/moai-essentials-review/reference.md +28 -0
  131. moai_adk/templates/.claude/skills/moai-foundation-ears/SKILL.md +116 -0
  132. moai_adk/templates/.claude/skills/moai-foundation-ears/examples.md +29 -0
  133. moai_adk/templates/.claude/skills/moai-foundation-ears/reference.md +28 -0
  134. moai_adk/templates/.claude/skills/moai-foundation-git/SKILL.md +122 -0
  135. moai_adk/templates/.claude/skills/moai-foundation-git/examples.md +29 -0
  136. moai_adk/templates/.claude/skills/moai-foundation-git/reference.md +29 -0
  137. moai_adk/templates/.claude/skills/moai-foundation-langs/SKILL.md +113 -0
  138. moai_adk/templates/.claude/skills/moai-foundation-langs/examples.md +29 -0
  139. moai_adk/templates/.claude/skills/moai-foundation-langs/reference.md +28 -0
  140. moai_adk/templates/.claude/skills/moai-foundation-specs/SKILL.md +113 -0
  141. moai_adk/templates/.claude/skills/moai-foundation-specs/examples.md +29 -0
  142. moai_adk/templates/.claude/skills/moai-foundation-specs/reference.md +28 -0
  143. moai_adk/templates/.claude/skills/moai-foundation-tags/SKILL.md +113 -0
  144. moai_adk/templates/.claude/skills/moai-foundation-tags/examples.md +29 -0
  145. moai_adk/templates/.claude/skills/moai-foundation-tags/reference.md +28 -0
  146. moai_adk/templates/.claude/skills/moai-foundation-trust/SKILL.md +307 -0
  147. moai_adk/templates/.claude/skills/moai-foundation-trust/examples.md +0 -0
  148. moai_adk/templates/.claude/skills/moai-foundation-trust/reference.md +1099 -0
  149. moai_adk/templates/.claude/skills/moai-lang-c/SKILL.md +124 -0
  150. moai_adk/templates/.claude/skills/moai-lang-c/examples.md +29 -0
  151. moai_adk/templates/.claude/skills/moai-lang-c/reference.md +31 -0
  152. moai_adk/templates/.claude/skills/moai-lang-cpp/SKILL.md +124 -0
  153. moai_adk/templates/.claude/skills/moai-lang-cpp/examples.md +29 -0
  154. moai_adk/templates/.claude/skills/moai-lang-cpp/reference.md +31 -0
  155. moai_adk/templates/.claude/skills/moai-lang-csharp/SKILL.md +123 -0
  156. moai_adk/templates/.claude/skills/moai-lang-csharp/examples.md +29 -0
  157. moai_adk/templates/.claude/skills/moai-lang-csharp/reference.md +30 -0
  158. moai_adk/templates/.claude/skills/moai-lang-dart/SKILL.md +123 -0
  159. moai_adk/templates/.claude/skills/moai-lang-dart/examples.md +29 -0
  160. moai_adk/templates/.claude/skills/moai-lang-dart/reference.md +30 -0
  161. moai_adk/templates/.claude/skills/moai-lang-go/SKILL.md +124 -0
  162. moai_adk/templates/.claude/skills/moai-lang-go/examples.md +29 -0
  163. moai_adk/templates/.claude/skills/moai-lang-go/reference.md +31 -0
  164. moai_adk/templates/.claude/skills/moai-lang-java/SKILL.md +124 -0
  165. moai_adk/templates/.claude/skills/moai-lang-java/examples.md +29 -0
  166. moai_adk/templates/.claude/skills/moai-lang-java/reference.md +31 -0
  167. moai_adk/templates/.claude/skills/moai-lang-javascript/SKILL.md +125 -0
  168. moai_adk/templates/.claude/skills/moai-lang-javascript/examples.md +29 -0
  169. moai_adk/templates/.claude/skills/moai-lang-javascript/reference.md +32 -0
  170. moai_adk/templates/.claude/skills/moai-lang-kotlin/SKILL.md +124 -0
  171. moai_adk/templates/.claude/skills/moai-lang-kotlin/examples.md +29 -0
  172. moai_adk/templates/.claude/skills/moai-lang-kotlin/reference.md +31 -0
  173. moai_adk/templates/.claude/skills/moai-lang-php/SKILL.md +123 -0
  174. moai_adk/templates/.claude/skills/moai-lang-php/examples.md +29 -0
  175. moai_adk/templates/.claude/skills/moai-lang-php/reference.md +30 -0
  176. moai_adk/templates/.claude/skills/moai-lang-python/SKILL.md +431 -0
  177. moai_adk/templates/.claude/skills/moai-lang-python/examples.md +624 -0
  178. moai_adk/templates/.claude/skills/moai-lang-python/reference.md +316 -0
  179. moai_adk/templates/.claude/skills/moai-lang-r/SKILL.md +123 -0
  180. moai_adk/templates/.claude/skills/moai-lang-r/examples.md +29 -0
  181. moai_adk/templates/.claude/skills/moai-lang-r/reference.md +30 -0
  182. moai_adk/templates/.claude/skills/moai-lang-ruby/SKILL.md +124 -0
  183. moai_adk/templates/.claude/skills/moai-lang-ruby/examples.md +29 -0
  184. moai_adk/templates/.claude/skills/moai-lang-ruby/reference.md +31 -0
  185. moai_adk/templates/.claude/skills/moai-lang-rust/SKILL.md +124 -0
  186. moai_adk/templates/.claude/skills/moai-lang-rust/examples.md +29 -0
  187. moai_adk/templates/.claude/skills/moai-lang-rust/reference.md +31 -0
  188. moai_adk/templates/.claude/skills/moai-lang-scala/SKILL.md +123 -0
  189. moai_adk/templates/.claude/skills/moai-lang-scala/examples.md +29 -0
  190. moai_adk/templates/.claude/skills/moai-lang-scala/reference.md +30 -0
  191. moai_adk/templates/.claude/skills/moai-lang-shell/SKILL.md +123 -0
  192. moai_adk/templates/.claude/skills/moai-lang-shell/examples.md +29 -0
  193. moai_adk/templates/.claude/skills/moai-lang-shell/reference.md +30 -0
  194. moai_adk/templates/.claude/skills/moai-lang-sql/SKILL.md +124 -0
  195. moai_adk/templates/.claude/skills/moai-lang-sql/examples.md +29 -0
  196. moai_adk/templates/.claude/skills/moai-lang-sql/reference.md +31 -0
  197. moai_adk/templates/.claude/skills/moai-lang-swift/SKILL.md +123 -0
  198. moai_adk/templates/.claude/skills/moai-lang-swift/examples.md +29 -0
  199. moai_adk/templates/.claude/skills/moai-lang-swift/reference.md +30 -0
  200. moai_adk/templates/.claude/skills/moai-lang-typescript/SKILL.md +127 -0
  201. moai_adk/templates/.claude/skills/moai-lang-typescript/examples.md +29 -0
  202. moai_adk/templates/.claude/skills/moai-lang-typescript/reference.md +34 -0
  203. moai_adk/templates/.claude/skills/moai-skill-factory/CHECKLIST.md +482 -0
  204. moai_adk/templates/.claude/skills/moai-skill-factory/EXAMPLES.md +278 -0
  205. moai_adk/templates/.claude/skills/moai-skill-factory/INTERACTIVE-DISCOVERY.md +524 -0
  206. moai_adk/templates/.claude/skills/moai-skill-factory/METADATA.md +477 -0
  207. moai_adk/templates/.claude/skills/moai-skill-factory/PARALLEL-ANALYSIS-REPORT.md +429 -0
  208. moai_adk/templates/.claude/skills/moai-skill-factory/PYTHON-VERSION-MATRIX.md +391 -0
  209. moai_adk/templates/.claude/skills/moai-skill-factory/SKILL-FACTORY-WORKFLOW.md +431 -0
  210. moai_adk/templates/.claude/skills/moai-skill-factory/SKILL-UPDATE-ADVISOR.md +577 -0
  211. moai_adk/templates/.claude/skills/moai-skill-factory/SKILL.md +271 -0
  212. moai_adk/templates/.claude/skills/moai-skill-factory/STEP-BY-STEP-GUIDE.md +466 -0
  213. moai_adk/templates/.claude/skills/moai-skill-factory/STRUCTURE.md +583 -0
  214. moai_adk/templates/.claude/skills/moai-skill-factory/WEB-RESEARCH.md +526 -0
  215. moai_adk/templates/.claude/skills/moai-skill-factory/reference.md +465 -0
  216. moai_adk/templates/.claude/skills/moai-skill-factory/scripts/generate-structure.sh +328 -0
  217. moai_adk/templates/.claude/skills/moai-skill-factory/scripts/validate-skill.sh +312 -0
  218. moai_adk/templates/.claude/skills/moai-skill-factory/templates/SKILL_TEMPLATE.md +245 -0
  219. moai_adk/templates/.claude/skills/moai-skill-factory/templates/examples-template.md +285 -0
  220. moai_adk/templates/.claude/skills/moai-skill-factory/templates/reference-template.md +278 -0
  221. moai_adk/templates/.claude/skills/moai-skill-factory/templates/scripts-template.sh +303 -0
  222. moai_adk/templates/.claude/skills/moai-spec-authoring/README.md +137 -0
  223. moai_adk/templates/.claude/skills/moai-spec-authoring/SKILL.md +219 -0
  224. moai_adk/templates/.claude/skills/moai-spec-authoring/examples/validate-spec.sh +161 -0
  225. moai_adk/templates/.claude/skills/moai-spec-authoring/examples.md +541 -0
  226. moai_adk/templates/.claude/skills/moai-spec-authoring/reference.md +622 -0
  227. moai_adk/templates/.github/workflows/c-tag-validation.yml +83 -0
  228. moai_adk/templates/.github/workflows/cpp-tag-validation.yml +79 -0
  229. moai_adk/templates/.github/workflows/csharp-tag-validation.yml +65 -0
  230. moai_adk/templates/.github/workflows/dart-tag-validation.yml +82 -0
  231. moai_adk/templates/.github/workflows/java-tag-validation.yml +75 -0
  232. moai_adk/templates/.github/workflows/kotlin-tag-validation.yml +67 -0
  233. moai_adk/templates/.github/workflows/php-tag-validation.yml +56 -0
  234. moai_adk/templates/.github/workflows/ruby-tag-validation.yml +68 -0
  235. moai_adk/templates/.github/workflows/rust-tag-validation.yml +73 -0
  236. moai_adk/templates/.github/workflows/shell-tag-validation.yml +65 -0
  237. moai_adk/templates/.github/workflows/swift-tag-validation.yml +79 -0
  238. moai_adk/templates/.moai/config.json +113 -0
  239. moai_adk/templates/.moai/memory/CLAUDE-AGENTS-GUIDE.md +208 -0
  240. moai_adk/templates/.moai/memory/CLAUDE-PRACTICES.md +369 -0
  241. moai_adk/templates/.moai/memory/CLAUDE-RULES.md +539 -0
  242. moai_adk/templates/.moai/memory/DEVELOPMENT-GUIDE.md +344 -0
  243. moai_adk/templates/.moai/memory/GITFLOW-PROTECTION-POLICY.md +330 -0
  244. moai_adk/templates/.moai/memory/ISSUE-LABEL-MAPPING.md +150 -0
  245. moai_adk/templates/.moai/memory/SKILLS-DESCRIPTION-POLICY.md +218 -0
  246. moai_adk/templates/.moai/memory/SPEC-METADATA.md +356 -0
  247. moai_adk/templates/.moai/memory/gitflow-protection-policy.md +330 -0
  248. moai_adk/templates/.moai/memory/spec-metadata.md +356 -0
  249. moai_adk/templates/.moai/project/product.md +161 -0
  250. moai_adk/templates/.moai/project/structure.md +156 -0
  251. moai_adk/templates/.moai/project/tech.md +227 -0
  252. moai_adk/templates/CLAUDE.md +90 -10
  253. moai_adk/templates/workflows/go-tag-validation.yml +130 -0
  254. moai_adk/templates/workflows/javascript-tag-validation.yml +135 -0
  255. moai_adk/templates/workflows/python-tag-validation.yml +118 -0
  256. moai_adk/templates/workflows/typescript-tag-validation.yml +154 -0
  257. {moai_adk-0.11.0.dist-info → moai_adk-0.12.1.dist-info}/METADATA +43 -1
  258. moai_adk-0.12.1.dist-info/RECORD +330 -0
  259. moai_adk-0.11.0.dist-info/RECORD +0 -77
  260. /moai_adk/templates/.github/workflows/{release.yml → moai-adk-release.yml} +0 -0
  261. /moai_adk/templates/.github/workflows/{spec-issue-sync.yml → moai-adk-spec-issue-sync.yml} +0 -0
  262. /moai_adk/templates/.github/workflows/{tag-validation.yml → moai-adk-tag-validation.yml} +0 -0
  263. {moai_adk-0.11.0.dist-info → moai_adk-0.12.1.dist-info}/WHEEL +0 -0
  264. {moai_adk-0.11.0.dist-info → moai_adk-0.12.1.dist-info}/entry_points.txt +0 -0
  265. {moai_adk-0.11.0.dist-info → moai_adk-0.12.1.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,744 @@
1
+ #!/usr/bin/env python3
2
+ """Project metadata utilities
3
+
4
+ Project information inquiry (language, Git, SPEC progress, etc.)
5
+ """
6
+
7
+ import json
8
+ import socket
9
+ import subprocess
10
+ from contextlib import contextmanager
11
+
12
+ from .timeout import CrossPlatformTimeout, TimeoutError as PlatformTimeoutError
13
+ from pathlib import Path
14
+ from typing import Any
15
+
16
+ # Cache directory for version check results
17
+ CACHE_DIR_NAME = ".moai/cache"
18
+
19
+
20
+ def find_project_root(start_path: str | Path = ".") -> Path:
21
+ """Find MoAI-ADK project root by searching upward for .moai/config.json
22
+
23
+ Traverses up the directory tree until it finds .moai/config.json or CLAUDE.md,
24
+ which indicates the project root. This ensures cache and other files are
25
+ always created in the correct location, regardless of where hooks execute.
26
+
27
+ Args:
28
+ start_path: Starting directory (default: current directory)
29
+
30
+ Returns:
31
+ Project root Path. If not found, returns start_path as absolute path.
32
+
33
+ Examples:
34
+ >>> find_project_root(".")
35
+ Path("/Users/user/my-project")
36
+ >>> find_project_root(".claude/hooks/alfred")
37
+ Path("/Users/user/my-project") # Found root 3 levels up
38
+
39
+ Notes:
40
+ - Searches for .moai/config.json first (most reliable)
41
+ - Falls back to CLAUDE.md if config.json not found
42
+ - Max depth: 10 levels up (prevent infinite loop)
43
+ - Returns absolute path for consistency
44
+
45
+ TDD History:
46
+ - RED: 4 test scenarios (root, nested, not found, symlinks)
47
+ - GREEN: Minimal upward search with .moai/config.json detection
48
+ - REFACTOR: Add CLAUDE.md fallback, max depth limit, absolute path return
49
+ """
50
+ current = Path(start_path).resolve()
51
+ max_depth = 10 # Prevent infinite loop
52
+
53
+ for _ in range(max_depth):
54
+ # Check for .moai/config.json (primary indicator)
55
+ if (current / ".moai" / "config.json").exists():
56
+ return current
57
+
58
+ # Check for CLAUDE.md (secondary indicator)
59
+ if (current / "CLAUDE.md").exists():
60
+ return current
61
+
62
+ # Move up one level
63
+ parent = current.parent
64
+ if parent == current: # Reached filesystem root
65
+ break
66
+ current = parent
67
+
68
+ # Not found - return start_path as absolute
69
+ return Path(start_path).resolve()
70
+
71
+
72
+ class TimeoutError(Exception):
73
+ """Signal-based timeout exception"""
74
+
75
+ pass
76
+
77
+
78
+ @contextmanager
79
+ def timeout_handler(seconds: int):
80
+ """Hard timeout using SIGALRM (works on Unix systems including macOS)
81
+
82
+ This uses kernel-level signal to interrupt ANY blocking operation,
83
+ even if subprocess.run() timeout fails on macOS.
84
+
85
+ Args:
86
+ seconds: Timeout duration in seconds
87
+
88
+ Raises:
89
+ TimeoutError: If operation exceeds timeout
90
+ """
91
+
92
+ def _handle_timeout(signum, frame):
93
+ raise TimeoutError(f"Operation timed out after {seconds} seconds")
94
+
95
+ # Set the signal handler
96
+ old_handler = signal.signal(signal.SIGALRM, _handle_timeout)
97
+ signal.alarm(seconds)
98
+ try:
99
+ yield
100
+ finally:
101
+ timeout.cancel() # Disable alarm
102
+ signal.signal(signal.SIGALRM, old_handler)
103
+
104
+
105
+ def detect_language(cwd: str) -> str:
106
+ """Detect project language (supports 20 items languages)
107
+
108
+ Browse the File system to detect your project's main development language.
109
+ First, check configuration files such as pyproject.toml and tsconfig.json.
110
+ Apply TypeScript first principles (if tsconfig.json exists).
111
+
112
+ Args:
113
+ cwd: Project root directory path (both absolute and relative paths are possible)
114
+
115
+ Returns:
116
+ Detected language name (lowercase). If detection fails, "Unknown Language" is returned.
117
+ Supported languages: python, typescript, javascript, java, go, rust,
118
+ dart, swift, kotlin, php, ruby, elixir, scala,
119
+ clojure, cpp, c, csharp, haskell, shell, lua
120
+
121
+ Examples:
122
+ >>> detect_language("/path/to/python/project")
123
+ 'python'
124
+ >>> detect_language("/path/to/typescript/project")
125
+ 'typescript'
126
+ >>> detect_language("/path/to/unknown/project")
127
+ 'Unknown Language'
128
+
129
+ TDD History:
130
+ - RED: Write a 21 items language detection test (20 items language + 1 items unknown)
131
+ - GREEN: 20 items language + unknown implementation, all tests passed
132
+ - REFACTOR: Optimize file inspection order, apply TypeScript priority principle
133
+ """
134
+ cwd_path = Path(cwd)
135
+
136
+ # Language detection mapping
137
+ language_files = {
138
+ "pyproject.toml": "python",
139
+ "tsconfig.json": "typescript",
140
+ "package.json": "javascript",
141
+ "pom.xml": "java",
142
+ "go.mod": "go",
143
+ "Cargo.toml": "rust",
144
+ "pubspec.yaml": "dart",
145
+ "Package.swift": "swift",
146
+ "build.gradle.kts": "kotlin",
147
+ "composer.json": "php",
148
+ "Gemfile": "ruby",
149
+ "mix.exs": "elixir",
150
+ "build.sbt": "scala",
151
+ "project.clj": "clojure",
152
+ "CMakeLists.txt": "cpp",
153
+ "Makefile": "c",
154
+ }
155
+
156
+ # Check standard language files
157
+ for file_name, language in language_files.items():
158
+ if (cwd_path / file_name).exists():
159
+ # Special handling for package.json - prefer typescript if tsconfig exists
160
+ if file_name == "package.json" and (cwd_path / "tsconfig.json").exists():
161
+ return "typescript"
162
+ return language
163
+
164
+ # Check for C# project files (*.csproj)
165
+ if any(cwd_path.glob("*.csproj")):
166
+ return "csharp"
167
+
168
+ # Check for Haskell project files (*.cabal)
169
+ if any(cwd_path.glob("*.cabal")):
170
+ return "haskell"
171
+
172
+ # Check for Shell scripts (*.sh)
173
+ if any(cwd_path.glob("*.sh")):
174
+ return "shell"
175
+
176
+ # Check for Lua files (*.lua)
177
+ if any(cwd_path.glob("*.lua")):
178
+ return "lua"
179
+
180
+ return "Unknown Language"
181
+
182
+
183
+ def _run_git_command(args: list[str], cwd: str, timeout: int = 2) -> str:
184
+ """Git command execution with HARD timeout protection
185
+
186
+ Safely execute Git commands and return output.
187
+ Uses SIGALRM (kernel-level interrupt) to handle macOS subprocess timeout bug.
188
+ Eliminates code duplication and provides consistent error handling.
189
+
190
+ Args:
191
+ args: Git command argument list (git adds automatically)
192
+ cwd: Execution directory path
193
+ timeout: Timeout (seconds, default 2 seconds)
194
+
195
+ Returns:
196
+ Git command output (stdout, removing leading and trailing spaces)
197
+
198
+ Raises:
199
+ subprocess.TimeoutExpired: Timeout exceeded (via TimeoutError)
200
+ subprocess.CalledProcessError: Git command failed
201
+
202
+ Examples:
203
+ >>> _run_git_command(["branch", "--show-current"], ".")
204
+ 'main'
205
+
206
+ TDD History:
207
+ - RED: Git command hang scenario test
208
+ - GREEN: SIGALRM-based timeout implementation
209
+ - REFACTOR: Exception conversion to subprocess.TimeoutExpired
210
+ """
211
+ try:
212
+ with timeout_handler(timeout):
213
+ result = subprocess.run(
214
+ ["git"] + args,
215
+ cwd=cwd,
216
+ capture_output=True,
217
+ text=True,
218
+ check=False, # Don't raise on non-zero exit - we'll check manually
219
+ )
220
+
221
+ # Check exit code manually
222
+ if result.returncode != 0:
223
+ raise subprocess.CalledProcessError(
224
+ result.returncode, ["git"] + args, result.stdout, result.stderr
225
+ )
226
+
227
+ return result.stdout.strip()
228
+
229
+ except TimeoutError:
230
+ # Convert to subprocess.TimeoutExpired for consistent error handling
231
+ raise subprocess.TimeoutExpired(["git"] + args, timeout)
232
+
233
+
234
+ def get_git_info(cwd: str) -> dict[str, Any]:
235
+ """Gather Git repository information
236
+
237
+ View the current status of a Git repository.
238
+ Returns the branch name, commit hash, number of changes, and last commit message.
239
+ If it is not a Git repository, it returns an empty dictionary.
240
+
241
+ Args:
242
+ cwd: Project root directory path
243
+
244
+ Returns:
245
+ Git information dictionary. Includes the following keys:
246
+ - branch: Current branch name (str)
247
+ - commit: Current commit hash (str, full hash)
248
+ - changes: Number of changed files (int, staged + unstaged)
249
+ - last_commit: Last commit message (str, subject only)
250
+
251
+ Empty dictionary {} if it is not a Git repository or the query fails.
252
+
253
+ Examples:
254
+ >>> get_git_info("/path/to/git/repo")
255
+ {'branch': 'main', 'commit': 'abc123...', 'changes': 3, 'last_commit': 'Fix bug'}
256
+ >>> get_git_info("/path/to/non-git")
257
+ {}
258
+
259
+ Notes:
260
+ - Timeout: 2 seconds for each Git command
261
+ - Security: Safe execution with subprocess.run(shell=False)
262
+ - Error handling: Returns an empty dictionary in case of all exceptions
263
+ - Commit message limited to 50 characters for display purposes
264
+
265
+ TDD History:
266
+ - RED: 3 items scenario test (Git repo, non-Git, error)
267
+ - GREEN: Implementation of subprocess-based Git command execution
268
+ - REFACTOR: Add timeout (2 seconds), strengthen exception handling, remove duplicates with helper function
269
+ - UPDATE: Added last_commit message field for SessionStart display
270
+ """
271
+ try:
272
+ # Check if it's a git repository
273
+ _run_git_command(["rev-parse", "--git-dir"], cwd)
274
+
275
+ # Get branch name, commit hash, and changes
276
+ branch = _run_git_command(["branch", "--show-current"], cwd)
277
+ commit = _run_git_command(["rev-parse", "HEAD"], cwd)
278
+ status_output = _run_git_command(["status", "--short"], cwd)
279
+ changes = len([line for line in status_output.splitlines() if line])
280
+
281
+ # Get last commit message (subject only, limited to 50 chars)
282
+ last_commit = _run_git_command(["log", "-1", "--format=%s"], cwd)
283
+ if len(last_commit) > 50:
284
+ last_commit = last_commit[:47] + "..."
285
+
286
+ return {
287
+ "branch": branch,
288
+ "commit": commit,
289
+ "changes": changes,
290
+ "last_commit": last_commit,
291
+ }
292
+
293
+ except (subprocess.TimeoutExpired, subprocess.CalledProcessError, FileNotFoundError):
294
+ return {}
295
+
296
+
297
+ def count_specs(cwd: str) -> dict[str, int]:
298
+ """SPEC File count and progress calculation
299
+
300
+ Browse the .moai/specs/ directory to find the number of SPEC Files and
301
+ Counts the number of SPECs with status: completed.
302
+
303
+ Args:
304
+ cwd: Project root directory path (or any subdirectory, will search upward)
305
+
306
+ Returns:
307
+ SPEC progress dictionary. Includes the following keys:
308
+ - completed: Number of completed SPECs (int)
309
+ - total: total number of SPECs (int)
310
+ - percentage: completion percentage (int, 0~100)
311
+
312
+ All 0 if .moai/specs/ directory does not exist
313
+
314
+ Examples:
315
+ >>> count_specs("/path/to/project")
316
+ {'completed': 2, 'total': 5, 'percentage': 40}
317
+ >>> count_specs("/path/to/no-specs")
318
+ {'completed': 0, 'total': 0, 'percentage': 0}
319
+
320
+ Notes:
321
+ - SPEC File Location: .moai/specs/SPEC-{ID}/spec.md
322
+ - Completion condition: Include "status: completed" in YAML front matter
323
+ - If parsing fails, the SPEC is considered incomplete.
324
+ - Automatically finds project root to locate .moai/specs/
325
+
326
+ TDD History:
327
+ - RED: 5 items scenario test (0/0, 2/5, 5/5, no directory, parsing error)
328
+ - GREEN: SPEC search with Path.iterdir(), YAML parsing implementation
329
+ - REFACTOR: Strengthened exception handling, improved percentage calculation safety
330
+ - UPDATE: Add project root detection for consistent path resolution
331
+ """
332
+ # Find project root to ensure we read specs from correct location
333
+ project_root = find_project_root(cwd)
334
+ specs_dir = project_root / ".moai" / "specs"
335
+
336
+ if not specs_dir.exists():
337
+ return {"completed": 0, "total": 0, "percentage": 0}
338
+
339
+ completed = 0
340
+ total = 0
341
+
342
+ for spec_dir in specs_dir.iterdir():
343
+ if not spec_dir.is_dir() or not spec_dir.name.startswith("SPEC-"):
344
+ continue
345
+
346
+ spec_file = spec_dir / "spec.md"
347
+ if not spec_file.exists():
348
+ continue
349
+
350
+ total += 1
351
+
352
+ # Parse YAML front matter
353
+ try:
354
+ content = spec_file.read_text()
355
+ if content.startswith("---"):
356
+ yaml_end = content.find("---", 3)
357
+ if yaml_end > 0:
358
+ yaml_content = content[3:yaml_end]
359
+ if "status: completed" in yaml_content:
360
+ completed += 1
361
+ except (OSError, UnicodeDecodeError):
362
+ # File read failure or encoding error - considered incomplete
363
+ pass
364
+
365
+ percentage = int(completed / total * 100) if total > 0 else 0
366
+
367
+ return {
368
+ "completed": completed,
369
+ "total": total,
370
+ "percentage": percentage,
371
+ }
372
+
373
+
374
+ def get_project_language(cwd: str) -> str:
375
+ """Determine the primary project language (prefers config.json).
376
+
377
+ Args:
378
+ cwd: Project root directory (or any subdirectory, will search upward).
379
+
380
+ Returns:
381
+ Language string in lower-case.
382
+
383
+ Notes:
384
+ - Reads ``.moai/config.json`` first for a quick answer.
385
+ - Falls back to ``detect_language`` if configuration is missing.
386
+ - Automatically finds project root to locate .moai/config.json
387
+ """
388
+ # Find project root to ensure we read config from correct location
389
+ project_root = find_project_root(cwd)
390
+ config_path = project_root / ".moai" / "config.json"
391
+ if config_path.exists():
392
+ try:
393
+ config = json.loads(config_path.read_text())
394
+ lang = config.get("language", "")
395
+ if lang:
396
+ return lang
397
+ except (OSError, json.JSONDecodeError):
398
+ # Fall back to detection on parse errors
399
+ pass
400
+
401
+ # Fall back to the original language detection routine (use project root)
402
+ return detect_language(str(project_root))
403
+
404
+
405
+ # @CODE:CONFIG-INTEGRATION-001
406
+ def get_version_check_config(cwd: str) -> dict[str, Any]:
407
+ """Read version check configuration from .moai/config.json
408
+
409
+ Returns version check settings with sensible defaults.
410
+ Supports frequency-based cache TTL configuration.
411
+
412
+ Args:
413
+ cwd: Project root directory path
414
+
415
+ Returns:
416
+ dict with keys:
417
+ - "enabled": Boolean (default: True)
418
+ - "frequency": "always" | "daily" | "weekly" | "never" (default: "daily")
419
+ - "cache_ttl_hours": TTL in hours based on frequency
420
+
421
+ Frequency to TTL mapping:
422
+ - "always": 0 hours (no caching)
423
+ - "daily": 24 hours
424
+ - "weekly": 168 hours (7 days)
425
+ - "never": infinity (never check)
426
+
427
+ TDD History:
428
+ - RED: 8 test scenarios (defaults, custom, disabled, TTL, etc.)
429
+ - GREEN: Minimal config reading with defaults
430
+ - REFACTOR: Add validation and error handling
431
+ """
432
+ # TTL mapping by frequency
433
+ ttl_by_frequency = {"always": 0, "daily": 24, "weekly": 168, "never": float("inf")}
434
+
435
+ # Default configuration
436
+ defaults = {"enabled": True, "frequency": "daily", "cache_ttl_hours": 24}
437
+
438
+ # Find project root to ensure we read config from correct location
439
+ project_root = find_project_root(cwd)
440
+ config_path = project_root / ".moai" / "config.json"
441
+ if not config_path.exists():
442
+ return defaults
443
+
444
+ try:
445
+ config = json.loads(config_path.read_text())
446
+
447
+ # Extract moai.version_check section
448
+ moai_config = config.get("moai", {})
449
+ version_check_config = moai_config.get("version_check", {})
450
+
451
+ # Read enabled flag (default: True)
452
+ enabled = version_check_config.get("enabled", defaults["enabled"])
453
+
454
+ # Read frequency (default: "daily")
455
+ frequency = moai_config.get("update_check_frequency", defaults["frequency"])
456
+
457
+ # Validate frequency
458
+ if frequency not in ttl_by_frequency:
459
+ frequency = defaults["frequency"]
460
+
461
+ # Calculate TTL from frequency
462
+ cache_ttl_hours = ttl_by_frequency[frequency]
463
+
464
+ # Allow explicit cache_ttl_hours override
465
+ if "cache_ttl_hours" in version_check_config:
466
+ cache_ttl_hours = version_check_config["cache_ttl_hours"]
467
+
468
+ return {"enabled": enabled, "frequency": frequency, "cache_ttl_hours": cache_ttl_hours}
469
+
470
+ except (OSError, json.JSONDecodeError, KeyError):
471
+ # Config read or parse error - return defaults
472
+ return defaults
473
+
474
+
475
+ # @CODE:NETWORK-DETECT-001
476
+ def is_network_available(timeout_seconds: float = 0.1) -> bool:
477
+ """Quick network availability check using socket.
478
+
479
+ Does NOT check PyPI specifically, just basic connectivity.
480
+ Returns immediately on success (< 50ms typically).
481
+ Returns False on any error without raising exceptions.
482
+
483
+ Args:
484
+ timeout_seconds: Socket timeout in seconds (default 0.1s)
485
+
486
+ Returns:
487
+ True if network appears available, False otherwise
488
+
489
+ Examples:
490
+ >>> is_network_available()
491
+ True # Network is available
492
+ >>> is_network_available(timeout_seconds=0.001)
493
+ False # Timeout too short, returns False
494
+
495
+ TDD History:
496
+ - RED: 3 test scenarios (success, failure, timeout)
497
+ - GREEN: Minimal socket.create_connection implementation
498
+ - REFACTOR: Add error handling for all exception types
499
+ """
500
+ try:
501
+ # Try connecting to Google's public DNS server (8.8.8.8:53)
502
+ # This is a reliable host that's typically reachable
503
+ connection = socket.create_connection(("8.8.8.8", 53), timeout=timeout_seconds)
504
+ connection.close()
505
+ return True
506
+ except (socket.timeout, OSError, Exception):
507
+ # Any connection error means network is unavailable
508
+ # This includes: timeout, connection refused, network unreachable, etc.
509
+ return False
510
+
511
+
512
+ # @CODE:VERSION-DETECT-MAJOR-001
513
+ def is_major_version_change(current: str, latest: str) -> bool:
514
+ """Detect if version change is a major version bump.
515
+
516
+ A major version change is when the first (major) component increases:
517
+ - 0.8.1 → 1.0.0: True (0 → 1)
518
+ - 1.2.3 → 2.0.0: True (1 → 2)
519
+ - 0.8.1 → 0.9.0: False (0 → 0, minor changed)
520
+ - 1.2.3 → 1.3.0: False (1 → 1)
521
+
522
+ Args:
523
+ current: Current version string (e.g., "0.8.1")
524
+ latest: Latest version string (e.g., "1.0.0")
525
+
526
+ Returns:
527
+ True if major version increased, False otherwise
528
+
529
+ Examples:
530
+ >>> is_major_version_change("0.8.1", "1.0.0")
531
+ True
532
+ >>> is_major_version_change("0.8.1", "0.9.0")
533
+ False
534
+ >>> is_major_version_change("dev", "1.0.0")
535
+ False # Invalid versions return False
536
+
537
+ TDD History:
538
+ - RED: 4 test scenarios (0→1, 1→2, minor, invalid)
539
+ - GREEN: Minimal version parsing and comparison
540
+ - REFACTOR: Improve error handling for invalid versions
541
+ """
542
+ try:
543
+ # Parse version strings into integer components
544
+ current_parts = [int(x) for x in current.split(".")]
545
+ latest_parts = [int(x) for x in latest.split(".")]
546
+
547
+ # Compare major version (first component)
548
+ if len(current_parts) >= 1 and len(latest_parts) >= 1:
549
+ return latest_parts[0] > current_parts[0]
550
+
551
+ # If parsing succeeds but empty, no major change
552
+ return False
553
+
554
+ except (ValueError, AttributeError, IndexError):
555
+ # Invalid version format - return False (no exception)
556
+ return False
557
+
558
+
559
+ # @CODE:VERSION-CACHE-INTEGRATION-001
560
+ def get_package_version_info(cwd: str = ".") -> dict[str, Any]:
561
+ """Check MoAI-ADK current and latest version with caching and offline support.
562
+
563
+ Execution flow:
564
+ 1. Try to load from cache (< 50ms)
565
+ 2. If cache invalid, check network
566
+ 3. If network available, query PyPI
567
+ 4. If network unavailable, return current version only
568
+ 5. Save result to cache for next time
569
+
570
+ Args:
571
+ cwd: Project root directory (for cache location)
572
+
573
+ Returns:
574
+ dict with keys:
575
+ - "current": Current installed version
576
+ - "latest": Latest version available on PyPI
577
+ - "update_available": Boolean indicating if update is available
578
+ - "upgrade_command": Recommended upgrade command (if update available)
579
+ - "release_notes_url": URL to release notes (Phase 3)
580
+ - "is_major_update": Boolean indicating major version change (Phase 3)
581
+
582
+ Note:
583
+ - Cache hit (< 24 hours): Returns in ~20ms, no network access
584
+ - Cache miss + online: Query PyPI (1s timeout), cache result
585
+ - Cache miss + offline: Return current version only (~100ms)
586
+ - Offline + cached: Return from cache in ~20ms
587
+
588
+ TDD History:
589
+ - RED: 5 test scenarios (network detection, cache integration, offline mode)
590
+ - GREEN: Integrate VersionCache with network detection
591
+ - REFACTOR: Extract cache directory constant, improve error handling
592
+ - Phase 3: Add release_notes_url and is_major_update fields (@CODE:VERSION-INTEGRATE-FIELDS-001)
593
+ """
594
+ import importlib.util
595
+ import urllib.error
596
+ import urllib.request
597
+ from importlib.metadata import PackageNotFoundError, version
598
+
599
+ # Import VersionCache from the same directory (using dynamic import for testing compatibility)
600
+ try:
601
+ version_cache_path = Path(__file__).parent / "version_cache.py"
602
+ spec = importlib.util.spec_from_file_location("version_cache", version_cache_path)
603
+ if spec and spec.loader:
604
+ version_cache_module = importlib.util.module_from_spec(spec)
605
+ spec.loader.exec_module(version_cache_module)
606
+ version_cache_class = version_cache_module.VersionCache
607
+ else:
608
+ # Skip caching if module can't be loaded
609
+ version_cache_class = None
610
+ except (ImportError, OSError) as e:
611
+ # Graceful degradation: skip caching on import errors
612
+ version_cache_class = None
613
+
614
+ # 1. Find project root (ensure cache is always in correct location)
615
+ # This prevents creating .moai/cache in wrong locations when hooks run
616
+ # from subdirectories like .claude/hooks/alfred/
617
+ project_root = find_project_root(cwd)
618
+
619
+ # 2. Initialize cache (skip if VersionCache couldn't be imported)
620
+ cache_dir = project_root / CACHE_DIR_NAME
621
+ version_cache = version_cache_class(cache_dir) if version_cache_class else None
622
+
623
+ # 2. Get current installed version first (needed for cache validation)
624
+ current_version = "unknown"
625
+ try:
626
+ current_version = version("moai-adk")
627
+ except PackageNotFoundError:
628
+ current_version = "dev"
629
+ # Dev mode - skip cache and return immediately
630
+ return {
631
+ "current": "dev",
632
+ "latest": "unknown",
633
+ "update_available": False,
634
+ "upgrade_command": "",
635
+ }
636
+
637
+ # 3. Try to load from cache (fast path with version validation)
638
+ if version_cache and version_cache.is_valid():
639
+ cached_info = version_cache.load()
640
+ if cached_info:
641
+ # Only use cache if the cached version matches current installed version
642
+ # This prevents stale cache when package is upgraded locally
643
+ if cached_info.get("current") == current_version:
644
+ # Ensure new fields exist for backward compatibility
645
+ if "release_notes_url" not in cached_info:
646
+ # Add missing fields to old cached data
647
+ cached_info.setdefault("release_notes_url", None)
648
+ cached_info.setdefault("is_major_update", False)
649
+ return cached_info
650
+ # else: cache is stale (version changed), fall through to re-check
651
+
652
+ # 4. Cache miss or stale - need to query PyPI
653
+ result = {
654
+ "current": current_version,
655
+ "latest": "unknown",
656
+ "update_available": False,
657
+ "upgrade_command": "",
658
+ }
659
+
660
+ # 5. Check if version check is enabled in config
661
+ config = get_version_check_config(cwd)
662
+ if not config["enabled"]:
663
+ # Version check disabled - return only current version
664
+ return result
665
+
666
+ # 6. Check network before PyPI query
667
+ if not is_network_available():
668
+ # Offline mode - return current version only
669
+ return result
670
+
671
+ # 7. Network available - query PyPI
672
+ pypi_data = None
673
+ try:
674
+ with timeout_handler(1):
675
+ url = "https://pypi.org/pypi/moai-adk/json"
676
+ headers = {"Accept": "application/json"}
677
+ req = urllib.request.Request(url, headers=headers)
678
+ with urllib.request.urlopen(req, timeout=0.8) as response:
679
+ pypi_data = json.load(response)
680
+ result["latest"] = pypi_data.get("info", {}).get("version", "unknown")
681
+
682
+ # Extract release notes URL from project_urls
683
+ try:
684
+ project_urls = pypi_data.get("info", {}).get("project_urls", {})
685
+ release_url = project_urls.get("Changelog", "")
686
+ if not release_url:
687
+ # Fallback to GitHub releases URL pattern
688
+ release_url = (
689
+ f"https://github.com/modu-ai/moai-adk/releases/tag/v{result['latest']}"
690
+ )
691
+ result["release_notes_url"] = release_url
692
+ except (KeyError, AttributeError, TypeError):
693
+ result["release_notes_url"] = None
694
+
695
+ except (urllib.error.URLError, TimeoutError, Exception):
696
+ # PyPI query failed - return current version
697
+ result["release_notes_url"] = None
698
+ pass
699
+
700
+ # 7. Compare versions (simple comparison)
701
+ if result["current"] != "unknown" and result["latest"] != "unknown":
702
+ try:
703
+ # Parse versions for comparison
704
+ current_parts = [int(x) for x in result["current"].split(".")]
705
+ latest_parts = [int(x) for x in result["latest"].split(".")]
706
+
707
+ # Pad shorter version with zeros
708
+ max_len = max(len(current_parts), len(latest_parts))
709
+ current_parts.extend([0] * (max_len - len(current_parts)))
710
+ latest_parts.extend([0] * (max_len - len(latest_parts)))
711
+
712
+ if latest_parts > current_parts:
713
+ result["update_available"] = True
714
+ result["upgrade_command"] = f"uv pip install --upgrade moai-adk>={result['latest']}"
715
+
716
+ # Detect major version change
717
+ result["is_major_update"] = is_major_version_change(
718
+ result["current"], result["latest"]
719
+ )
720
+ else:
721
+ result["is_major_update"] = False
722
+ except (ValueError, AttributeError):
723
+ # Version parsing failed - skip comparison
724
+ result["is_major_update"] = False
725
+ pass
726
+
727
+ # 8. Save result to cache (if caching is available)
728
+ if version_cache:
729
+ version_cache.save(result)
730
+
731
+ return result
732
+
733
+
734
+ __all__ = [
735
+ "find_project_root",
736
+ "detect_language",
737
+ "get_git_info",
738
+ "count_specs",
739
+ "get_project_language",
740
+ "get_version_check_config",
741
+ "is_network_available",
742
+ "is_major_version_change",
743
+ "get_package_version_info",
744
+ ]