@dtt_siye/atool 1.1.0

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.
Files changed (463) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +235 -0
  3. package/VERSION +1 -0
  4. package/agents/code-reviewer.md +29 -0
  5. package/bin/atool.js +235 -0
  6. package/bin/postinstall.js +23 -0
  7. package/hooks/doc-sync-reminder +155 -0
  8. package/hooks/hooks-cursor.json +37 -0
  9. package/hooks/hooks.json +37 -0
  10. package/hooks/prompt-guard +135 -0
  11. package/hooks/session-start +286 -0
  12. package/install.sh +603 -0
  13. package/lib/analyze-source.sh +1265 -0
  14. package/lib/common.sh +1041 -0
  15. package/lib/compute-importance.sh +598 -0
  16. package/lib/detect-stack.sh +354 -0
  17. package/lib/generate-visualization.sh +266 -0
  18. package/lib/install-claude.sh +43 -0
  19. package/lib/install-cursor.sh +281 -0
  20. package/lib/install-hooks.sh +285 -0
  21. package/lib/install-kiro.sh +543 -0
  22. package/lib/install-mcp.sh +99 -0
  23. package/lib/install-skills.sh +129 -0
  24. package/lib/knowledge-graph.sh +1014 -0
  25. package/lib/multi-dimensional-analysis.sh +413 -0
  26. package/lib/pre-scan.sh +1045 -0
  27. package/lib/project-init.sh +552 -0
  28. package/lib/visualization-template.html +545 -0
  29. package/mcp/recommended.json +24 -0
  30. package/package.json +39 -0
  31. package/skills/_superpowers/.claude-plugin/marketplace.json +20 -0
  32. package/skills/_superpowers/.claude-plugin/plugin.json +20 -0
  33. package/skills/_superpowers/.codex/INSTALL.md +67 -0
  34. package/skills/_superpowers/.cursor-plugin/plugin.json +25 -0
  35. package/skills/_superpowers/.gitattributes +18 -0
  36. package/skills/_superpowers/.github/FUNDING.yml +3 -0
  37. package/skills/_superpowers/.github/ISSUE_TEMPLATE/bug_report.md +52 -0
  38. package/skills/_superpowers/.github/ISSUE_TEMPLATE/config.yml +5 -0
  39. package/skills/_superpowers/.github/ISSUE_TEMPLATE/feature_request.md +34 -0
  40. package/skills/_superpowers/.github/ISSUE_TEMPLATE/platform_support.md +23 -0
  41. package/skills/_superpowers/.github/PULL_REQUEST_TEMPLATE.md +87 -0
  42. package/skills/_superpowers/.opencode/INSTALL.md +83 -0
  43. package/skills/_superpowers/.opencode/plugins/superpowers.js +107 -0
  44. package/skills/_superpowers/CHANGELOG.md +13 -0
  45. package/skills/_superpowers/CODE_OF_CONDUCT.md +128 -0
  46. package/skills/_superpowers/GEMINI.md +2 -0
  47. package/skills/_superpowers/LICENSE +21 -0
  48. package/skills/_superpowers/README.md +187 -0
  49. package/skills/_superpowers/RELEASE-NOTES.md +1083 -0
  50. package/skills/_superpowers/agents/code-reviewer.md +48 -0
  51. package/skills/_superpowers/commands/brainstorm.md +5 -0
  52. package/skills/_superpowers/commands/execute-plan.md +5 -0
  53. package/skills/_superpowers/commands/write-plan.md +5 -0
  54. package/skills/_superpowers/docs/README.codex.md +126 -0
  55. package/skills/_superpowers/docs/README.opencode.md +130 -0
  56. package/skills/_superpowers/docs/plans/2025-11-22-opencode-support-design.md +294 -0
  57. package/skills/_superpowers/docs/plans/2025-11-22-opencode-support-implementation.md +1095 -0
  58. package/skills/_superpowers/docs/plans/2025-11-28-skills-improvements-from-user-feedback.md +711 -0
  59. package/skills/_superpowers/docs/plans/2026-01-17-visual-brainstorming.md +571 -0
  60. package/skills/_superpowers/docs/superpowers/plans/2026-01-22-document-review-system.md +301 -0
  61. package/skills/_superpowers/docs/superpowers/plans/2026-02-19-visual-brainstorming-refactor.md +523 -0
  62. package/skills/_superpowers/docs/superpowers/plans/2026-03-11-zero-dep-brainstorm-server.md +479 -0
  63. package/skills/_superpowers/docs/superpowers/plans/2026-03-23-codex-app-compatibility.md +564 -0
  64. package/skills/_superpowers/docs/superpowers/specs/2026-01-22-document-review-system-design.md +136 -0
  65. package/skills/_superpowers/docs/superpowers/specs/2026-02-19-visual-brainstorming-refactor-design.md +162 -0
  66. package/skills/_superpowers/docs/superpowers/specs/2026-03-11-zero-dep-brainstorm-server-design.md +118 -0
  67. package/skills/_superpowers/docs/superpowers/specs/2026-03-23-codex-app-compatibility-design.md +244 -0
  68. package/skills/_superpowers/docs/testing.md +303 -0
  69. package/skills/_superpowers/docs/windows/polyglot-hooks.md +212 -0
  70. package/skills/_superpowers/gemini-extension.json +6 -0
  71. package/skills/_superpowers/hooks/hooks-cursor.json +10 -0
  72. package/skills/_superpowers/hooks/hooks.json +16 -0
  73. package/skills/_superpowers/hooks/run-hook.cmd +46 -0
  74. package/skills/_superpowers/hooks/session-start +57 -0
  75. package/skills/_superpowers/package.json +6 -0
  76. package/skills/_superpowers/skills/brainstorming/SKILL.md +164 -0
  77. package/skills/_superpowers/skills/brainstorming/scripts/frame-template.html +214 -0
  78. package/skills/_superpowers/skills/brainstorming/scripts/helper.js +88 -0
  79. package/skills/_superpowers/skills/brainstorming/scripts/server.cjs +354 -0
  80. package/skills/_superpowers/skills/brainstorming/scripts/start-server.sh +148 -0
  81. package/skills/_superpowers/skills/brainstorming/scripts/stop-server.sh +56 -0
  82. package/skills/_superpowers/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
  83. package/skills/_superpowers/skills/brainstorming/visual-companion.md +287 -0
  84. package/skills/_superpowers/skills/dispatching-parallel-agents/SKILL.md +182 -0
  85. package/skills/_superpowers/skills/executing-plans/SKILL.md +70 -0
  86. package/skills/_superpowers/skills/finishing-a-development-branch/SKILL.md +200 -0
  87. package/skills/_superpowers/skills/receiving-code-review/SKILL.md +213 -0
  88. package/skills/_superpowers/skills/requesting-code-review/SKILL.md +105 -0
  89. package/skills/_superpowers/skills/requesting-code-review/code-reviewer.md +146 -0
  90. package/skills/_superpowers/skills/subagent-driven-development/SKILL.md +277 -0
  91. package/skills/_superpowers/skills/subagent-driven-development/code-quality-reviewer-prompt.md +26 -0
  92. package/skills/_superpowers/skills/subagent-driven-development/implementer-prompt.md +113 -0
  93. package/skills/_superpowers/skills/subagent-driven-development/spec-reviewer-prompt.md +61 -0
  94. package/skills/_superpowers/skills/systematic-debugging/CREATION-LOG.md +119 -0
  95. package/skills/_superpowers/skills/systematic-debugging/SKILL.md +296 -0
  96. package/skills/_superpowers/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  97. package/skills/_superpowers/skills/systematic-debugging/condition-based-waiting.md +115 -0
  98. package/skills/_superpowers/skills/systematic-debugging/defense-in-depth.md +122 -0
  99. package/skills/_superpowers/skills/systematic-debugging/find-polluter.sh +63 -0
  100. package/skills/_superpowers/skills/systematic-debugging/root-cause-tracing.md +169 -0
  101. package/skills/_superpowers/skills/systematic-debugging/test-academic.md +14 -0
  102. package/skills/_superpowers/skills/systematic-debugging/test-pressure-1.md +58 -0
  103. package/skills/_superpowers/skills/systematic-debugging/test-pressure-2.md +68 -0
  104. package/skills/_superpowers/skills/systematic-debugging/test-pressure-3.md +69 -0
  105. package/skills/_superpowers/skills/test-driven-development/SKILL.md +371 -0
  106. package/skills/_superpowers/skills/test-driven-development/testing-anti-patterns.md +299 -0
  107. package/skills/_superpowers/skills/using-git-worktrees/SKILL.md +218 -0
  108. package/skills/_superpowers/skills/using-superpowers/SKILL.md +115 -0
  109. package/skills/_superpowers/skills/using-superpowers/references/codex-tools.md +100 -0
  110. package/skills/_superpowers/skills/using-superpowers/references/gemini-tools.md +33 -0
  111. package/skills/_superpowers/skills/verification-before-completion/SKILL.md +139 -0
  112. package/skills/_superpowers/skills/writing-plans/SKILL.md +152 -0
  113. package/skills/_superpowers/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
  114. package/skills/_superpowers/skills/writing-skills/SKILL.md +655 -0
  115. package/skills/_superpowers/skills/writing-skills/anthropic-best-practices.md +1150 -0
  116. package/skills/_superpowers/skills/writing-skills/examples/CLAUDE_MD_TESTING.md +189 -0
  117. package/skills/_superpowers/skills/writing-skills/graphviz-conventions.dot +172 -0
  118. package/skills/_superpowers/skills/writing-skills/persuasion-principles.md +187 -0
  119. package/skills/_superpowers/skills/writing-skills/render-graphs.js +168 -0
  120. package/skills/_superpowers/skills/writing-skills/testing-skills-with-subagents.md +384 -0
  121. package/skills/_superpowers/tests/brainstorm-server/package-lock.json +36 -0
  122. package/skills/_superpowers/tests/brainstorm-server/package.json +10 -0
  123. package/skills/_superpowers/tests/brainstorm-server/server.test.js +427 -0
  124. package/skills/_superpowers/tests/brainstorm-server/windows-lifecycle.test.sh +351 -0
  125. package/skills/_superpowers/tests/brainstorm-server/ws-protocol.test.js +392 -0
  126. package/skills/_superpowers/tests/claude-code/README.md +158 -0
  127. package/skills/_superpowers/tests/claude-code/analyze-token-usage.py +168 -0
  128. package/skills/_superpowers/tests/claude-code/run-skill-tests.sh +187 -0
  129. package/skills/_superpowers/tests/claude-code/test-document-review-system.sh +177 -0
  130. package/skills/_superpowers/tests/claude-code/test-helpers.sh +202 -0
  131. package/skills/_superpowers/tests/claude-code/test-subagent-driven-development-integration.sh +314 -0
  132. package/skills/_superpowers/tests/claude-code/test-subagent-driven-development.sh +165 -0
  133. package/skills/_superpowers/tests/explicit-skill-requests/prompts/action-oriented.txt +3 -0
  134. package/skills/_superpowers/tests/explicit-skill-requests/prompts/after-planning-flow.txt +17 -0
  135. package/skills/_superpowers/tests/explicit-skill-requests/prompts/claude-suggested-it.txt +11 -0
  136. package/skills/_superpowers/tests/explicit-skill-requests/prompts/i-know-what-sdd-means.txt +8 -0
  137. package/skills/_superpowers/tests/explicit-skill-requests/prompts/mid-conversation-execute-plan.txt +3 -0
  138. package/skills/_superpowers/tests/explicit-skill-requests/prompts/please-use-brainstorming.txt +1 -0
  139. package/skills/_superpowers/tests/explicit-skill-requests/prompts/skip-formalities.txt +3 -0
  140. package/skills/_superpowers/tests/explicit-skill-requests/prompts/subagent-driven-development-please.txt +1 -0
  141. package/skills/_superpowers/tests/explicit-skill-requests/prompts/use-systematic-debugging.txt +1 -0
  142. package/skills/_superpowers/tests/explicit-skill-requests/run-all.sh +70 -0
  143. package/skills/_superpowers/tests/explicit-skill-requests/run-claude-describes-sdd.sh +100 -0
  144. package/skills/_superpowers/tests/explicit-skill-requests/run-extended-multiturn-test.sh +113 -0
  145. package/skills/_superpowers/tests/explicit-skill-requests/run-haiku-test.sh +144 -0
  146. package/skills/_superpowers/tests/explicit-skill-requests/run-multiturn-test.sh +143 -0
  147. package/skills/_superpowers/tests/explicit-skill-requests/run-test.sh +136 -0
  148. package/skills/_superpowers/tests/opencode/run-tests.sh +163 -0
  149. package/skills/_superpowers/tests/opencode/setup.sh +73 -0
  150. package/skills/_superpowers/tests/opencode/test-plugin-loading.sh +72 -0
  151. package/skills/_superpowers/tests/opencode/test-priority.sh +198 -0
  152. package/skills/_superpowers/tests/opencode/test-tools.sh +104 -0
  153. package/skills/_superpowers/tests/skill-triggering/prompts/dispatching-parallel-agents.txt +8 -0
  154. package/skills/_superpowers/tests/skill-triggering/prompts/executing-plans.txt +1 -0
  155. package/skills/_superpowers/tests/skill-triggering/prompts/requesting-code-review.txt +3 -0
  156. package/skills/_superpowers/tests/skill-triggering/prompts/systematic-debugging.txt +11 -0
  157. package/skills/_superpowers/tests/skill-triggering/prompts/test-driven-development.txt +7 -0
  158. package/skills/_superpowers/tests/skill-triggering/prompts/writing-plans.txt +10 -0
  159. package/skills/_superpowers/tests/skill-triggering/run-all.sh +60 -0
  160. package/skills/_superpowers/tests/skill-triggering/run-test.sh +88 -0
  161. package/skills/_superpowers/tests/subagent-driven-dev/go-fractals/design.md +81 -0
  162. package/skills/_superpowers/tests/subagent-driven-dev/go-fractals/plan.md +172 -0
  163. package/skills/_superpowers/tests/subagent-driven-dev/go-fractals/scaffold.sh +45 -0
  164. package/skills/_superpowers/tests/subagent-driven-dev/run-test.sh +106 -0
  165. package/skills/_superpowers/tests/subagent-driven-dev/svelte-todo/design.md +70 -0
  166. package/skills/_superpowers/tests/subagent-driven-dev/svelte-todo/plan.md +222 -0
  167. package/skills/_superpowers/tests/subagent-driven-dev/svelte-todo/scaffold.sh +46 -0
  168. package/skills/ai-project-architecture/SKILL.md +632 -0
  169. package/skills/ai-project-architecture/reference/structure-rules.md +406 -0
  170. package/skills/ai-project-architecture/templates/compliance-report.md +300 -0
  171. package/skills/ai-project-architecture/templates/migration-plan.md +433 -0
  172. package/skills/ai-project-architecture/templates/verification-checklist.md +408 -0
  173. package/skills/android-conventions/SKILL.md +125 -0
  174. package/skills/atool-init/SKILL.md +141 -0
  175. package/skills/clarify-before-build/SKILL.md +107 -0
  176. package/skills/code-review/SKILL.md +406 -0
  177. package/skills/code-review/rules/architecture.md +285 -0
  178. package/skills/code-review/rules/coupling-cohesion.md +309 -0
  179. package/skills/code-review/rules/dead-code.md +115 -0
  180. package/skills/code-review/rules/deprecation-debt.md +279 -0
  181. package/skills/code-review/rules/duplication.md +104 -0
  182. package/skills/code-review/rules/error-security.md +143 -0
  183. package/skills/code-review/rules/maintainability.md +203 -0
  184. package/skills/code-review/rules/quality.md +158 -0
  185. package/skills/devops-conventions/SKILL.md +205 -0
  186. package/skills/doc-coauthoring/SKILL.md +392 -0
  187. package/skills/doc-standards-enforcer/SKILL.md +290 -0
  188. package/skills/doc-standards-enforcer/examples/valid-document-example.md +67 -0
  189. package/skills/doc-standards-enforcer/references/101-standards-summary.md +318 -0
  190. package/skills/doc-standards-enforcer/scripts/check_references.py +175 -0
  191. package/skills/doc-standards-enforcer/scripts/fix_common_issues.py +303 -0
  192. package/skills/doc-standards-enforcer/scripts/validate_doc_standards.py +332 -0
  193. package/skills/docx/LICENSE.txt +30 -0
  194. package/skills/docx/SKILL.md +200 -0
  195. package/skills/docx/docx-js.md +350 -0
  196. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  197. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  198. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  199. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  200. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  201. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  202. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  203. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  204. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  205. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  206. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  207. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  208. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  209. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  210. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  211. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  212. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  213. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  214. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  215. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  216. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  217. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  218. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  219. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  220. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  221. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  222. package/skills/docx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  223. package/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  224. package/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  225. package/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  226. package/skills/docx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  227. package/skills/docx/ooxml/schemas/mce/mc.xsd +75 -0
  228. package/skills/docx/ooxml/schemas/microsoft/wml-2010.xsd +560 -0
  229. package/skills/docx/ooxml/schemas/microsoft/wml-2012.xsd +67 -0
  230. package/skills/docx/ooxml/schemas/microsoft/wml-2018.xsd +14 -0
  231. package/skills/docx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -0
  232. package/skills/docx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -0
  233. package/skills/docx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  234. package/skills/docx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -0
  235. package/skills/docx/ooxml/scripts/pack.py +159 -0
  236. package/skills/docx/ooxml/scripts/unpack.py +29 -0
  237. package/skills/docx/ooxml/scripts/validate.py +69 -0
  238. package/skills/docx/ooxml/scripts/validation/__init__.py +15 -0
  239. package/skills/docx/ooxml/scripts/validation/base.py +951 -0
  240. package/skills/docx/ooxml/scripts/validation/docx.py +274 -0
  241. package/skills/docx/ooxml/scripts/validation/pptx.py +315 -0
  242. package/skills/docx/ooxml/scripts/validation/redlining.py +279 -0
  243. package/skills/docx/ooxml.md +610 -0
  244. package/skills/docx/scripts/__init__.py +1 -0
  245. package/skills/docx/scripts/document.py +1276 -0
  246. package/skills/docx/scripts/templates/comments.xml +3 -0
  247. package/skills/docx/scripts/templates/commentsExtended.xml +3 -0
  248. package/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
  249. package/skills/docx/scripts/templates/commentsIds.xml +3 -0
  250. package/skills/docx/scripts/templates/people.xml +3 -0
  251. package/skills/docx/scripts/utilities.py +374 -0
  252. package/skills/flutter-conventions/SKILL.md +70 -0
  253. package/skills/go-conventions/SKILL.md +230 -0
  254. package/skills/harmony-conventions/SKILL.md +156 -0
  255. package/skills/java-conventions/SKILL.md +277 -0
  256. package/skills/pdf/LICENSE.txt +30 -0
  257. package/skills/pdf/SKILL.md +297 -0
  258. package/skills/pdf/forms.md +205 -0
  259. package/skills/pdf/reference.md +612 -0
  260. package/skills/pdf/scripts/check_bounding_boxes.py +70 -0
  261. package/skills/pdf/scripts/check_bounding_boxes_test.py +226 -0
  262. package/skills/pdf/scripts/check_fillable_fields.py +12 -0
  263. package/skills/pdf/scripts/convert_pdf_to_images.py +35 -0
  264. package/skills/pdf/scripts/create_validation_image.py +41 -0
  265. package/skills/pdf/scripts/extract_form_field_info.py +152 -0
  266. package/skills/pdf/scripts/fill_fillable_fields.py +114 -0
  267. package/skills/pdf/scripts/fill_pdf_form_with_annotations.py +108 -0
  268. package/skills/pptx/LICENSE.txt +30 -0
  269. package/skills/pptx/SKILL.md +487 -0
  270. package/skills/pptx/html2pptx.md +625 -0
  271. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  272. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  273. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  274. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  275. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  276. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  277. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  278. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  279. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  280. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  281. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  282. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  283. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  284. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  285. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  286. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  287. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  288. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  289. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  290. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  291. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  292. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  293. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  294. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  295. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  296. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  297. package/skills/pptx/ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  298. package/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  299. package/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  300. package/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  301. package/skills/pptx/ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  302. package/skills/pptx/ooxml/schemas/mce/mc.xsd +75 -0
  303. package/skills/pptx/ooxml/schemas/microsoft/wml-2010.xsd +560 -0
  304. package/skills/pptx/ooxml/schemas/microsoft/wml-2012.xsd +67 -0
  305. package/skills/pptx/ooxml/schemas/microsoft/wml-2018.xsd +14 -0
  306. package/skills/pptx/ooxml/schemas/microsoft/wml-cex-2018.xsd +20 -0
  307. package/skills/pptx/ooxml/schemas/microsoft/wml-cid-2016.xsd +13 -0
  308. package/skills/pptx/ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  309. package/skills/pptx/ooxml/schemas/microsoft/wml-symex-2015.xsd +8 -0
  310. package/skills/pptx/ooxml/scripts/pack.py +159 -0
  311. package/skills/pptx/ooxml/scripts/unpack.py +29 -0
  312. package/skills/pptx/ooxml/scripts/validate.py +69 -0
  313. package/skills/pptx/ooxml/scripts/validation/__init__.py +15 -0
  314. package/skills/pptx/ooxml/scripts/validation/base.py +951 -0
  315. package/skills/pptx/ooxml/scripts/validation/docx.py +274 -0
  316. package/skills/pptx/ooxml/scripts/validation/pptx.py +315 -0
  317. package/skills/pptx/ooxml/scripts/validation/redlining.py +279 -0
  318. package/skills/pptx/ooxml.md +427 -0
  319. package/skills/pptx/scripts/html2pptx.js +979 -0
  320. package/skills/pptx/scripts/inventory.py +1020 -0
  321. package/skills/pptx/scripts/rearrange.py +231 -0
  322. package/skills/pptx/scripts/replace.py +385 -0
  323. package/skills/pptx/scripts/thumbnail.py +450 -0
  324. package/skills/project-analyze/SKILL.md +270 -0
  325. package/skills/project-analyze/phases/phase0-discovery.md +278 -0
  326. package/skills/project-analyze/phases/phase0.5-prescan.md +139 -0
  327. package/skills/project-analyze/phases/phase1-inventory.md +94 -0
  328. package/skills/project-analyze/phases/phase2-deep-analysis.md +249 -0
  329. package/skills/project-analyze/phases/phase2a-l4-analysis.md +94 -0
  330. package/skills/project-analyze/phases/phase2b-l5-analysis.md +97 -0
  331. package/skills/project-analyze/phases/phase3-knowledge-graph.md +120 -0
  332. package/skills/project-analyze/phases/phase3a-multi-dimensional.md +61 -0
  333. package/skills/project-analyze/phases/phase4-code-quality.md +81 -0
  334. package/skills/project-analyze/phases/phase5-synthesis.md +284 -0
  335. package/skills/project-analyze/phases/phase6-validation.md +179 -0
  336. package/skills/project-analyze/prompts/code-review-agent.md +122 -0
  337. package/skills/project-analyze/prompts/deep-analysis-agent.md +107 -0
  338. package/skills/project-analyze/prompts/inventory-agent.md +67 -0
  339. package/skills/project-analyze/prompts/l4-analysis-agent.md +98 -0
  340. package/skills/project-analyze/rules/android.md +282 -0
  341. package/skills/project-analyze/rules/devops.md +443 -0
  342. package/skills/project-analyze/rules/generic.md +243 -0
  343. package/skills/project-analyze/rules/go.md +289 -0
  344. package/skills/project-analyze/rules/harmony.md +257 -0
  345. package/skills/project-analyze/rules/java.md +507 -0
  346. package/skills/project-analyze/rules/mobile-flutter.md +315 -0
  347. package/skills/project-analyze/rules/mobile-react-native.md +283 -0
  348. package/skills/project-analyze/rules/mobile-swift.md +323 -0
  349. package/skills/project-analyze/rules/python.md +317 -0
  350. package/skills/project-analyze/rules/rust-tauri.md +243 -0
  351. package/skills/project-analyze/rules/rust.md +296 -0
  352. package/skills/project-analyze/rules/web-nextjs.md +364 -0
  353. package/skills/project-analyze/rules/web-react.md +298 -0
  354. package/skills/project-analyze/rules/web-vue.md +378 -0
  355. package/skills/project-analyze/rules/web.md +390 -0
  356. package/skills/project-query/SKILL.md +224 -0
  357. package/skills/project-query/rules/query-templates.md +212 -0
  358. package/skills/python-conventions/SKILL.md +169 -0
  359. package/skills/react-native-conventions/SKILL.md +73 -0
  360. package/skills/requirements-writer/README.md +153 -0
  361. package/skills/requirements-writer/SKILL.md +341 -0
  362. package/skills/requirements-writer/examples/prd-outline-example.md +217 -0
  363. package/skills/requirements-writer/templates/module-prd-template.md +362 -0
  364. package/skills/requirements-writer/templates/prd-outline-template.md +185 -0
  365. package/skills/requirements-writer/templates/user-story-template.md +1125 -0
  366. package/skills/rust-conventions/SKILL.md +361 -0
  367. package/skills/smart-dispatch/SKILL.md +296 -0
  368. package/skills/smart-dispatch/implementer-prompt.md +146 -0
  369. package/skills/smart-dispatch/reviewer-prompt.md +199 -0
  370. package/skills/software-architecture/SKILL.md +278 -0
  371. package/skills/swift-conventions/SKILL.md +72 -0
  372. package/skills/ui-ux-pro/SKILL.md +140 -0
  373. package/skills/verification-before-completion/SKILL.md +119 -0
  374. package/skills/web-conventions/SKILL.md +259 -0
  375. package/skills/webapp-testing/LICENSE.txt +202 -0
  376. package/skills/webapp-testing/SKILL.md +97 -0
  377. package/skills/webapp-testing/examples/console_logging.py +35 -0
  378. package/skills/webapp-testing/examples/element_discovery.py +40 -0
  379. package/skills/webapp-testing/examples/static_html_automation.py +33 -0
  380. package/skills/webapp-testing/scripts/with_server.py +106 -0
  381. package/skills/writing-plans/SKILL.md +144 -0
  382. package/skills/xlsx/LICENSE.txt +30 -0
  383. package/skills/xlsx/SKILL.md +292 -0
  384. package/skills/xlsx/recalc.py +178 -0
  385. package/templates/CLAUDE.md.android +57 -0
  386. package/templates/CLAUDE.md.devops +50 -0
  387. package/templates/CLAUDE.md.generic +34 -0
  388. package/templates/CLAUDE.md.go +67 -0
  389. package/templates/CLAUDE.md.harmony +54 -0
  390. package/templates/CLAUDE.md.java +56 -0
  391. package/templates/CLAUDE.md.mobile-flutter +38 -0
  392. package/templates/CLAUDE.md.mobile-react-native +37 -0
  393. package/templates/CLAUDE.md.mobile-swift +40 -0
  394. package/templates/CLAUDE.md.python +65 -0
  395. package/templates/CLAUDE.md.rust +68 -0
  396. package/templates/CLAUDE.md.rust-tauri +120 -0
  397. package/templates/CLAUDE.md.web +63 -0
  398. package/templates/COMPONENT.md.android +58 -0
  399. package/templates/COMPONENT.md.devops +54 -0
  400. package/templates/COMPONENT.md.generic +35 -0
  401. package/templates/COMPONENT.md.go +59 -0
  402. package/templates/COMPONENT.md.harmony +63 -0
  403. package/templates/COMPONENT.md.java +69 -0
  404. package/templates/COMPONENT.md.mobile-flutter +56 -0
  405. package/templates/COMPONENT.md.mobile-react-native +55 -0
  406. package/templates/COMPONENT.md.mobile-swift +56 -0
  407. package/templates/COMPONENT.md.python +67 -0
  408. package/templates/COMPONENT.md.rust +57 -0
  409. package/templates/COMPONENT.md.rust-tauri +66 -0
  410. package/templates/COMPONENT.md.web +39 -0
  411. package/templates/README.md.android +71 -0
  412. package/templates/README.md.devops +68 -0
  413. package/templates/README.md.generic +39 -0
  414. package/templates/README.md.go +70 -0
  415. package/templates/README.md.harmony +72 -0
  416. package/templates/README.md.java +73 -0
  417. package/templates/README.md.mobile-flutter +69 -0
  418. package/templates/README.md.mobile-react-native +65 -0
  419. package/templates/README.md.mobile-swift +69 -0
  420. package/templates/README.md.monorepo +59 -0
  421. package/templates/README.md.python +66 -0
  422. package/templates/README.md.rust +69 -0
  423. package/templates/README.md.rust-tauri +149 -0
  424. package/templates/README.md.web +94 -0
  425. package/templates/UI_STYLE.md.android +74 -0
  426. package/templates/UI_STYLE.md.devops +50 -0
  427. package/templates/UI_STYLE.md.generic +31 -0
  428. package/templates/UI_STYLE.md.go +49 -0
  429. package/templates/UI_STYLE.md.harmony +71 -0
  430. package/templates/UI_STYLE.md.java +61 -0
  431. package/templates/UI_STYLE.md.mobile-flutter +70 -0
  432. package/templates/UI_STYLE.md.mobile-react-native +71 -0
  433. package/templates/UI_STYLE.md.mobile-swift +71 -0
  434. package/templates/UI_STYLE.md.python +58 -0
  435. package/templates/UI_STYLE.md.rust +52 -0
  436. package/templates/UI_STYLE.md.rust-tauri +102 -0
  437. package/templates/UI_STYLE.md.web +92 -0
  438. package/templates/cursor-rules.android.mdc +33 -0
  439. package/templates/cursor-rules.devops.mdc +32 -0
  440. package/templates/cursor-rules.generic.mdc +25 -0
  441. package/templates/cursor-rules.go.mdc +34 -0
  442. package/templates/cursor-rules.harmony.mdc +30 -0
  443. package/templates/cursor-rules.java.mdc +30 -0
  444. package/templates/cursor-rules.mobile-flutter.mdc +42 -0
  445. package/templates/cursor-rules.mobile-react-native.mdc +43 -0
  446. package/templates/cursor-rules.mobile-swift.mdc +42 -0
  447. package/templates/cursor-rules.python.mdc +33 -0
  448. package/templates/cursor-rules.rust-tauri.mdc +67 -0
  449. package/templates/cursor-rules.rust.mdc +30 -0
  450. package/templates/cursor-rules.web.mdc +30 -0
  451. package/templates/kiro-steering.android.md +39 -0
  452. package/templates/kiro-steering.devops.md +32 -0
  453. package/templates/kiro-steering.generic.md +28 -0
  454. package/templates/kiro-steering.go.md +41 -0
  455. package/templates/kiro-steering.harmony.md +36 -0
  456. package/templates/kiro-steering.java.md +37 -0
  457. package/templates/kiro-steering.mobile-flutter.md +73 -0
  458. package/templates/kiro-steering.mobile-react-native.md +71 -0
  459. package/templates/kiro-steering.mobile-swift.md +62 -0
  460. package/templates/kiro-steering.python.md +34 -0
  461. package/templates/kiro-steering.rust-tauri.md +50 -0
  462. package/templates/kiro-steering.rust.md +36 -0
  463. package/templates/kiro-steering.web.md +41 -0
@@ -0,0 +1,1045 @@
1
+ #!/usr/bin/env bash
2
+ # aTool - lib/pre-scan.sh
3
+ # Fast structural metadata extraction using grep/awk/jq — no AI required
4
+ #
5
+ # Extracts per-file: imports, exports, classes, functions, decorators,
6
+ # API endpoints, call references, and data models. Output feeds directly
7
+ # into project-analyze Phase 1 (inventory) and Phase 2 (deep analysis)
8
+ # to eliminate redundant AI file reads.
9
+ #
10
+ # Usage: source lib/pre-scan.sh
11
+ # pre_scan_project <PROJECT_ROOT> <OUTPUT_DIR>
12
+
13
+ set -euo pipefail
14
+
15
+ # shellcheck source=lib/common.sh
16
+ # shellcheck disable=SC1091
17
+ source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
18
+
19
+ # === Configuration ===
20
+
21
+ PRESCAN_EXCLUDE_DIRS=(
22
+ "node_modules" ".git" "dist" "build" "target" "vendor"
23
+ "__pycache__" ".next" ".nuxt" ".output" ".atool-docs"
24
+ "coverage" ".cache" ".turbo" ".gradle" ".mvn"
25
+ "migrations" "alembic" "htmlcov" ".idea" ".vscode"
26
+ "gen" "generated" "proto" ".venv" "venv" "env"
27
+ )
28
+
29
+ PRESCAN_EXCLUDE_PATTERNS=(
30
+ "*.generated.*" "*.pb.go" "*.min.js" "*.min.css"
31
+ "*.bundle.js" "*.d.ts" "__pycache__"
32
+ )
33
+
34
+ # Language detection is done via detect_file_language() below (case-based, bash 3.2 compatible)
35
+
36
+ # === Language Detection ===
37
+
38
+ # Detect language from file extension
39
+ # Args: FILE_PATH
40
+ # Outputs: language name or "unknown"
41
+ detect_file_language() {
42
+ local file="$1"
43
+ local ext=".${file##*.}"
44
+ case "$ext" in
45
+ .py|.pyw) echo "python" ;;
46
+ .java) echo "java" ;;
47
+ .kt|.kts) echo "kotlin" ;;
48
+ .ts|.tsx) echo "typescript" ;;
49
+ .js|.jsx) echo "javascript" ;;
50
+ .go) echo "go" ;;
51
+ .rs) echo "rust" ;;
52
+ .swift) echo "swift" ;;
53
+ .dart) echo "dart" ;;
54
+ .vue) echo "vue" ;;
55
+ .svelte) echo "svelte" ;;
56
+ .ets) echo "harmony" ;;
57
+ .c|.h) echo "c" ;;
58
+ .cpp|.hpp) echo "cpp" ;;
59
+ *) echo "unknown" ;;
60
+ esac
61
+ }
62
+
63
+ # === Exclude Helper ===
64
+
65
+ # Build find exclude arguments
66
+ # Outputs: space-separated -not -path args
67
+ _prescan_exclude_args() {
68
+ local args=""
69
+ for d in "${PRESCAN_EXCLUDE_DIRS[@]}"; do
70
+ args+="-not -path */${d}/* "
71
+ done
72
+ printf '%s' "$args"
73
+ }
74
+
75
+ # Check if a file should be excluded
76
+ # Args: FILE_PATH
77
+ # Returns: 0 (include), 1 (exclude)
78
+ _should_scan_file() {
79
+ local file="$1"
80
+ for d in "${PRESCAN_EXCLUDE_DIRS[@]}"; do
81
+ [[ "$file" == *"/${d}/"* ]] && return 1
82
+ done
83
+ for pat in "${PRESCAN_EXCLUDE_PATTERNS[@]}"; do
84
+ # Check filename against glob pattern
85
+ case "$(basename "$file")" in
86
+ $pat) return 1 ;;
87
+ esac
88
+ done
89
+ return 0
90
+ }
91
+
92
+ # === Python Extractor ===
93
+
94
+ # Extract metadata from a Python file using grep+awk
95
+ # Args: FILE_PATH, RELATIVE_PATH
96
+ # Outputs: JSON object to stdout
97
+ _extract_python() {
98
+ local file="$1"
99
+ local rel_path="$2"
100
+ local hash line_count
101
+
102
+ hash=$(file_checksum "$file")
103
+ line_count=$(wc -l < "$file" | tr -d ' ')
104
+
105
+ # --- Imports ---
106
+ local imports_json="[]"
107
+ imports_json=$({ grep -n -E '^(from |import )' "$file" 2>/dev/null || true; } | awk -F: '
108
+ {
109
+ line = $1; content = $2
110
+ if (content ~ /^from /) {
111
+ gsub(/^from /, "", content)
112
+ split(content, parts, " import ")
113
+ mod = parts[1]
114
+ syms = parts[2]
115
+ gsub(/ /, "", syms)
116
+ n = split(syms, s, ",")
117
+ for (i = 1; i <= n; i++) {
118
+ if (s[i] != "") {
119
+ is_local = (mod ~ /^\./ || mod ~ /^app\./ || mod ~ /^src\./) ? "true" : "false"
120
+ printf "{\"from\":\"%s\",\"import\":\"%s\",\"line\":%s,\"is_local\":%s}\n", mod, s[i], line, is_local
121
+ }
122
+ }
123
+ } else if (content ~ /^import /) {
124
+ gsub(/^import /, "", content)
125
+ gsub(/ /, "", content)
126
+ n = split(content, s, ",")
127
+ for (i = 1; i <= n; i++) {
128
+ if (s[i] != "") {
129
+ printf "{\"from\":null,\"import\":\"%s\",\"line\":%s,\"is_local\":false}\n", s[i], line
130
+ }
131
+ }
132
+ }
133
+ }' | jq -s '.' 2>/dev/null || echo '[]')
134
+
135
+ # --- Classes ---
136
+ local classes_json="[]"
137
+ classes_json=$({ grep -n -E '^class ' "$file" 2>/dev/null || true; } | awk -F: '
138
+ {
139
+ line = $1; content = $2
140
+ gsub(/^class /, "", content)
141
+ gsub(/:.*$/, "", content)
142
+ # Split name and bases
143
+ if (index(content, "(") > 0) {
144
+ split(content, parts, "(")
145
+ name = parts[1]
146
+ bases_str = content
147
+ sub(/^[^(]*\(/, "", bases_str)
148
+ sub(/\).*$/, "", bases_str)
149
+ gsub(/ /, "", bases_str)
150
+ n = split(bases_str, b, ",")
151
+ bases = ""
152
+ for (i = 1; i <= n; i++) {
153
+ if (b[i] != "") bases = bases (bases ? "," : "") "\"" b[i] "\""
154
+ }
155
+ } else {
156
+ name = content
157
+ bases = ""
158
+ }
159
+ gsub(/ /, "", name)
160
+ printf "{\"name\":\"%s\",\"bases\":[%s],\"line\":%s}\n", name, bases, line
161
+ }' | jq -s '.' 2>/dev/null || echo '[]')
162
+
163
+ # --- Functions ---
164
+ local functions_json="[]"
165
+ functions_json=$({ grep -n -E '^( )?def |^( )?async def ' "$file" 2>/dev/null || true; } | awk -F: '
166
+ {
167
+ line = $1; content = $2
168
+ gsub(/^( )?(async )?def /, "", content)
169
+ # Extract name and params
170
+ if (index(content, "(") > 0) {
171
+ split(content, parts, "(")
172
+ name = parts[1]
173
+ params = content
174
+ sub(/^[^(]*\(/, "", params)
175
+ sub(/\).*$/, "", params)
176
+ gsub(/ /, "", params)
177
+ } else {
178
+ name = content
179
+ params = ""
180
+ }
181
+ is_method = ($2 ~ /^ /) ? "true" : "false"
182
+ gsub(/ /, "", name)
183
+ printf "{\"name\":\"%s\",\"params\":\"%s\",\"line\":%s,\"is_method\":%s}\n", name, params, line, is_method
184
+ }' | jq -s '.' 2>/dev/null || echo '[]')
185
+
186
+ # --- Decorators ---
187
+ local decorators_json="[]"
188
+ decorators_json=$({ grep -n -E '^@' "$file" 2>/dev/null || true; } | awk -F: '
189
+ {
190
+ line = $1; content = $2
191
+ gsub(/^@/, "", content)
192
+ gsub(/ *$/, "", content)
193
+ # Check for API route decorators
194
+ is_route = (index(content,".get(")>0||index(content,".post(")>0||index(content,".put(")>0||index(content,".delete(")>0||index(content,".patch(")>0||index(content,".api_route(")>0||index(content,".route(")>0) ? "true" : "false"
195
+ printf "{\"name\":\"%s\",\"line\":%s,\"is_route\":%s}\n", content, line, is_route
196
+ }' | jq -s '.' 2>/dev/null || echo '[]')
197
+
198
+ # --- API Endpoints ---
199
+ local endpoints_json="[]"
200
+ # FastAPI/Sanic/Falcon route patterns
201
+ endpoints_json=$({ grep -n -E '@(app|router|bp|blueprint|api)\.(get|post|put|delete|patch|api_route|route)\(' "$file" 2>/dev/null || true; } | awk -F: '
202
+ {
203
+ line = $1; content = $2
204
+ # Extract decorator name and path
205
+ gsub(/^@/, "", content)
206
+ method = "unknown"
207
+ if (index(content, ".get(") > 0) method = "GET"
208
+ else if (index(content, ".post(") > 0) method = "POST"
209
+ else if (index(content, ".put(") > 0) method = "PUT"
210
+ else if (index(content, ".delete(") > 0) method = "DELETE"
211
+ else if (index(content, ".patch(") > 0) method = "PATCH"
212
+ # Extract path argument
213
+ path = ""
214
+ if (match(content, /\("[^"]*"/)) {
215
+ path = substr(content, RSTART+2, RLENGTH-3)
216
+ }
217
+ printf "{\"method\":\"%s\",\"path\":\"%s\",\"line\":%s}\n", method, path, line
218
+ }' | jq -s '.' 2>/dev/null || echo '[]')
219
+
220
+ # --- Data Models (SQLAlchemy/Tortoise/Pydantic) ---
221
+ local models_json="[]"
222
+ models_json=$({ grep -n -E 'class .+\((.*Model.*|.*Base.*|.*Schema.*|.*Entity.*|.*Table.*|.*Mixin.*)\)' "$file" 2>/dev/null || true; } | awk -F: '
223
+ {
224
+ line = $1; content = $2
225
+ gsub(/^class /, "", content)
226
+ split(content, parts, "(")
227
+ name = parts[1]
228
+ gsub(/ /, "", name)
229
+ bases = content
230
+ sub(/^[^(]*\(/, "", bases)
231
+ sub(/\).*$/, "", bases)
232
+ model_type = "unknown"
233
+ if (bases ~ /Base/ || bases ~ /Model/) model_type = "orm_model"
234
+ else if (bases ~ /Schema/ || bases ~ /BaseModel/) model_type = "pydantic"
235
+ else if (bases ~ /Table/) model_type = "table"
236
+ printf "{\"name\":\"%s\",\"type\":\"%s\",\"line\":%s}\n", name, model_type, line
237
+ }' | jq -s '.' 2>/dev/null || echo '[]')
238
+
239
+ # --- Exports (module-level names, i.e. non-method functions + classes) ---
240
+ local exports_json="[]"
241
+ exports_json=$(jq -n \
242
+ --argjson classes "$classes_json" \
243
+ --argjson functions "$functions_json" \
244
+ '[$classes[] | {name: .name, type: "class", line: .line}] +
245
+ [$functions[] | select(.is_method == false) | {name: .name, type: "function", line: .line}]' 2>/dev/null || echo '[]')
246
+
247
+ # --- Assemble file JSON ---
248
+ jq -n \
249
+ --arg path "$rel_path" \
250
+ --arg hash "$hash" \
251
+ --argjson lines "$line_count" \
252
+ --argjson imports "$imports_json" \
253
+ --argjson exports "$exports_json" \
254
+ --argjson classes "$classes_json" \
255
+ --argjson functions "$functions_json" \
256
+ --argjson decorators "$decorators_json" \
257
+ --argjson api_endpoints "$endpoints_json" \
258
+ --argjson data_models "$models_json" \
259
+ '{
260
+ path: $path,
261
+ hash: $hash,
262
+ lines: $lines,
263
+ language: "python",
264
+ imports: $imports,
265
+ exports: $exports,
266
+ classes: $classes,
267
+ functions: $functions,
268
+ decorators: $decorators,
269
+ api_endpoints: $api_endpoints,
270
+ data_models: $data_models,
271
+ extraction_confidence: "high"
272
+ }'
273
+ }
274
+
275
+ # === Java/Kotlin Extractor ===
276
+
277
+ _extract_java() {
278
+ local file="$1"
279
+ local rel_path="$2"
280
+ local hash line_count
281
+
282
+ hash=$(file_checksum "$file")
283
+ line_count=$(wc -l < "$file" | tr -d ' ')
284
+
285
+ # Detect if Kotlin
286
+ local lang="java"
287
+ [[ "$rel_path" == *.kt || "$rel_path" == *.kts ]] && lang="kotlin"
288
+
289
+ # --- Imports ---
290
+ local imports_json="[]"
291
+ imports_json=$({ grep -n -E '^import ' "$file" 2>/dev/null || true; } | awk -F: '
292
+ {
293
+ line = $1; content = $2
294
+ gsub(/^import /, "", content)
295
+ gsub(/;.*$/, "", content)
296
+ gsub(/ *$/, "", content)
297
+ is_local = (content ~ /^com\.example/) ? "false" : "false"
298
+ # Java imports are almost always external
299
+ printf "{\"from\":\"%s\",\"import\":null,\"line\":%s,\"is_local\":false}\n", content, line
300
+ }' | jq -s '.' 2>/dev/null || echo '[]')
301
+
302
+ # --- Classes/Interfaces/Enums ---
303
+ local classes_json="[]"
304
+ classes_json=$({ grep -n -E '(public |private |protected )?(static )?(abstract )?(final )?(class |interface |enum |@interface )' "$file" 2>/dev/null || true; } | awk -F: '
305
+ {
306
+ line = $1; content = $2
307
+ gsub(/public |private |protected |static |abstract |final |/, "", content)
308
+ decl_type = "class"
309
+ if (content ~ /^interface /) decl_type = "interface"
310
+ else if (content ~ /^enum /) decl_type = "enum"
311
+ else if (content ~ /^@interface /) decl_type = "annotation"
312
+ gsub(/^(class |interface |enum |@interface )/, "", content)
313
+ # Extract name and possible extends/implements
314
+ name = content
315
+ gsub(/[ ({:].*$/, "", name)
316
+ gsub(/ /, "", name)
317
+ printf "{\"name\":\"%s\",\"type\":\"%s\",\"line\":%s}\n", name, decl_type, line
318
+ }' | jq -s '.' 2>/dev/null || echo '[]')
319
+
320
+ # --- Methods ---
321
+ local functions_json="[]"
322
+ functions_json=$({ grep -n -E '(public|private|protected).*\([^)]*\)\s*(\{|throws|@)' "$file" 2>/dev/null || true; } | awk -F: '
323
+ {
324
+ line = $1; content = $2
325
+ # Simplified method signature extraction
326
+ gsub(/public |private |protected |static |abstract |final |synchronized |/, "", content)
327
+ gsub(/ *$/, "", content)
328
+ # Extract return type and method name
329
+ if (match(content, /[a-zA-Z_][a-zA-Z0-9_]*\(/)) {
330
+ pre = substr(content, 1, RSTART - 1)
331
+ method_with_paren = substr(content, RSTART)
332
+ gsub(/\(.*/, "", method_with_paren)
333
+ printf "{\"name\":\"%s\",\"params\":\"\",\"line\":%s}\n", method_with_paren, line
334
+ }
335
+ }' | jq -s '.' 2>/dev/null || echo '[]')
336
+
337
+ # --- Annotations (Spring) ---
338
+ local decorators_json="[]"
339
+ decorators_json=$({ grep -n -E '@\w+' "$file" 2>/dev/null || true; } | awk -F: '
340
+ {
341
+ line = $1; content = $2
342
+ gsub(/ /, "", content)
343
+ gsub(/^ */, "", content)
344
+ is_route = (content ~ /Mapping|Controller|RestController|RequestMapping/) ? "true" : "false"
345
+ printf "{\"name\":\"%s\",\"line\":%s,\"is_route\":%s}\n", content, line, is_route
346
+ }' | jq -s '.' 2>/dev/null || echo '[]')
347
+
348
+ # --- API Endpoints (Spring) ---
349
+ local endpoints_json="[]"
350
+ endpoints_json=$({ grep -n -E '@(Get|Post|Put|Delete|Patch|Request)Mapping' "$file" 2>/dev/null || true; } | awk -F: '
351
+ {
352
+ line = $1; content = $2
353
+ method = "unknown"
354
+ if (index(content, "@GetMapping") > 0) method = "GET"
355
+ else if (index(content, "@PostMapping") > 0) method = "POST"
356
+ else if (index(content, "@PutMapping") > 0) method = "PUT"
357
+ else if (index(content, "@DeleteMapping") > 0) method = "DELETE"
358
+ else if (index(content, "@PatchMapping") > 0) method = "PATCH"
359
+ else if (index(content, "@RequestMapping") > 0) method = "ANY"
360
+ path = ""
361
+ if (match(content, /\("[^"]*"/)) {
362
+ path = substr(content, RSTART+2, RLENGTH-3)
363
+ } else if (index(content, "/") > 0) {
364
+ if (match(content, /"[^"]*"/)) {
365
+ path = substr(content, RSTART+1, RLENGTH-2)
366
+ }
367
+ }
368
+ printf "{\"method\":\"%s\",\"path\":\"%s\",\"line\":%s}\n", method, path, line
369
+ }' | jq -s '.' 2>/dev/null || echo '[]')
370
+
371
+ # --- Data Models (JPA/Entity) ---
372
+ local models_json="[]"
373
+ models_json=$({ grep -n -E '@(Entity|Table)' "$file" 2>/dev/null || true; } | awk -F: '
374
+ {
375
+ line = $1
376
+ printf "{\"type\":\"jpa_entity\",\"line\":%s}\n", line
377
+ }' | jq -s '.' 2>/dev/null || echo '[]')
378
+
379
+ # --- Exports ---
380
+ local exports_json
381
+ exports_json=$(jq -n \
382
+ --argjson classes "$classes_json" \
383
+ --argjson functions "$functions_json" \
384
+ '[$classes[] | {name: .name, type: .type, line: .line}] +
385
+ [$functions[] | {name: .name, type: "method", line: .line}]' 2>/dev/null || echo '[]')
386
+
387
+ # --- Assemble ---
388
+ jq -n \
389
+ --arg path "$rel_path" \
390
+ --arg lang "$lang" \
391
+ --arg hash "$hash" \
392
+ --argjson lines "$line_count" \
393
+ --argjson imports "$imports_json" \
394
+ --argjson exports "$exports_json" \
395
+ --argjson classes "$classes_json" \
396
+ --argjson functions "$functions_json" \
397
+ --argjson decorators "$decorators_json" \
398
+ --argjson api_endpoints "$endpoints_json" \
399
+ --argjson data_models "$models_json" \
400
+ '{
401
+ path: $path,
402
+ hash: $hash,
403
+ lines: $lines,
404
+ language: $lang,
405
+ imports: $imports,
406
+ exports: $exports,
407
+ classes: $classes,
408
+ functions: $functions,
409
+ decorators: $decorators,
410
+ api_endpoints: $api_endpoints,
411
+ data_models: $data_models,
412
+ extraction_confidence: "high"
413
+ }'
414
+ }
415
+
416
+ # === TypeScript/JavaScript Extractor ===
417
+
418
+ _extract_typescript() {
419
+ local file="$1"
420
+ local rel_path="$2"
421
+ local hash line_count
422
+
423
+ hash=$(file_checksum "$file")
424
+ line_count=$(wc -l < "$file" | tr -d ' ')
425
+
426
+ local lang="typescript"
427
+ [[ "$rel_path" == *.js || "$rel_path" == *.jsx ]] && lang="javascript"
428
+
429
+ # --- Imports ---
430
+ local imports_json="[]"
431
+ imports_json=$({ grep -n -E '^(import |const .* = require)' "$file" 2>/dev/null || true; } | awk -F: '
432
+ {
433
+ line = $1; content = $2
434
+ gsub(/\047/, "\"", content)
435
+ if (content ~ /^import /) {
436
+ # ES module import
437
+ source = ""
438
+ if (match(content, /from "[^"]*"/)) {
439
+ source = substr(content, RSTART+6, RLENGTH-7)
440
+ } else if (match(content, /"[^"]*"/)) {
441
+ source = substr(content, RSTART+1, RLENGTH-2)
442
+ }
443
+ is_local = (source ~ /^\./ || source ~ /^@/) ? "true" : "false"
444
+ printf "{\"from\":\"%s\",\"import\":null,\"line\":%s,\"is_local\":%s}\n", source, line, is_local
445
+ } else if (index(content, "require(") > 0) {
446
+ source = ""
447
+ if (match(content, /"[^"]*"/)) {
448
+ source = substr(content, RSTART+1, RLENGTH-2)
449
+ }
450
+ is_local = (source ~ /^\./ || source ~ /^@/) ? "true" : "false"
451
+ printf "{\"from\":\"%s\",\"import\":null,\"line\":%s,\"is_local\":%s}\n", source, line, is_local
452
+ }
453
+ }' | jq -s '.' 2>/dev/null || echo '[]')
454
+
455
+ # --- Classes/Interfaces/Types/Enums ---
456
+ local classes_json="[]"
457
+ classes_json=$({ grep -n -E '^(export )?(default )?(abstract )?(class |interface |type |enum )' "$file" 2>/dev/null || true; } | awk -F: '
458
+ {
459
+ line = $1; content = $2
460
+ is_export = (content ~ /^export /) ? "true" : "false"
461
+ gsub(/^export (default )?/, "", content)
462
+ gsub(/^abstract /, "", content)
463
+ decl_type = "class"
464
+ if (content ~ /^interface /) decl_type = "interface"
465
+ else if (content ~ /^type /) decl_type = "type"
466
+ else if (content ~ /^enum /) decl_type = "enum"
467
+ gsub(/^(class |interface |type |enum )/, "", content)
468
+ name = content
469
+ gsub(/[ <({:].*$/, "", name)
470
+ gsub(/ /, "", name)
471
+ printf "{\"name\":\"%s\",\"type\":\"%s\",\"line\":%s,\"exported\":%s}\n", name, decl_type, line, is_export
472
+ }' | jq -s '.' 2>/dev/null || echo '[]')
473
+
474
+ # --- Functions/Arrow Functions ---
475
+ local functions_json="[]"
476
+ functions_json=$({ grep -n -E '^(export )?(default )?(async )?(function |const [a-zA-Z]+ = (\(.*\) =>|\(.*\):))' "$file" 2>/dev/null || true; } | awk -F: '
477
+ {
478
+ line = $1; content = $2
479
+ gsub(/^export (default )?/, "", content)
480
+ gsub(/^async /, "", content)
481
+ name = ""
482
+ if (content ~ /^function /) {
483
+ gsub(/^function /, "", content)
484
+ name = content
485
+ gsub(/[( ].*$/, "", name)
486
+ } else if (content ~ /^const /) {
487
+ gsub(/^const /, "", content)
488
+ name = content
489
+ gsub(/ *=.*$/, "", name)
490
+ }
491
+ gsub(/ /, "", name)
492
+ if (name != "") {
493
+ printf "{\"name\":\"%s\",\"line\":%s}\n", name, line
494
+ }
495
+ }' | jq -s '.' 2>/dev/null || echo '[]')
496
+
497
+ # --- Decorators ---
498
+ local decorators_json="[]"
499
+ decorators_json=$({ grep -n -E '^\s*@\w+' "$file" 2>/dev/null || true; } | awk -F: '
500
+ {
501
+ line = $1; content = $2
502
+ gsub(/^\s*/, "", content)
503
+ gsub(/^@/, "", content)
504
+ gsub(/ *$/, "", content)
505
+ printf "{\"name\":\"%s\",\"line\":%s}\n", content, line
506
+ }' | jq -s '.' 2>/dev/null || echo '[]')
507
+
508
+ # --- API Endpoints (Express/Fastify/Nuxt/Next) ---
509
+ local endpoints_json="[]"
510
+ endpoints_json=$({ grep -n -E '(app|router|server|fastify)\.(get|post|put|delete|patch)\(' "$file" 2>/dev/null || true; } | awk -F: '
511
+ {
512
+ line = $1; content = $2
513
+ method = "unknown"
514
+ if (index(content, ".get(") > 0) method = "GET"
515
+ else if (index(content, ".post(") > 0) method = "POST"
516
+ else if (index(content, ".put(") > 0) method = "PUT"
517
+ else if (index(content, ".delete(") > 0) method = "DELETE"
518
+ else if (index(content, ".patch(") > 0) method = "PATCH"
519
+ path = ""
520
+ if (match(content, /"[^"]*"/)) {
521
+ path = substr(content, RSTART+1, RLENGTH-2)
522
+ }
523
+ printf "{\"method\":\"%s\",\"path\":\"%s\",\"line\":%s}\n", method, path, line
524
+ }' | jq -s '.' 2>/dev/null || echo '[]')
525
+
526
+ # --- Data Models ---
527
+ local models_json="[]"
528
+ models_json=$({ grep -n -E '(interface|type|class).*(Props|State|Model|Schema|Entity|DTO|Dto|Response|Request|Input|Output)' "$file" 2>/dev/null || true; } | awk -F: '
529
+ {
530
+ line = $1; content = $2
531
+ gsub(/^(export )?(default )?(abstract )?/, "", content)
532
+ name = content
533
+ gsub(/^[a-z]+ /, "", name)
534
+ gsub(/[ <({:].*$/, "", name)
535
+ printf "{\"name\":\"%s\",\"type\":\"typescript_interface\",\"line\":%s}\n", name, line
536
+ }' | jq -s '.' 2>/dev/null || echo '[]')
537
+
538
+ # --- Exports ---
539
+ local exports_json
540
+ exports_json=$(jq -n \
541
+ --argjson classes "$classes_json" \
542
+ --argjson functions "$functions_json" \
543
+ '[$classes[] | select(.exported == true) | {name: .name, type: .type, line: .line}] +
544
+ [$functions[] | {name: .name, type: "function", line: .line}]' 2>/dev/null || echo '[]')
545
+
546
+ # --- Assemble ---
547
+ jq -n \
548
+ --arg path "$rel_path" \
549
+ --arg lang "$lang" \
550
+ --arg hash "$hash" \
551
+ --argjson lines "$line_count" \
552
+ --argjson imports "$imports_json" \
553
+ --argjson exports "$exports_json" \
554
+ --argjson classes "$classes_json" \
555
+ --argjson functions "$functions_json" \
556
+ --argjson decorators "$decorators_json" \
557
+ --argjson api_endpoints "$endpoints_json" \
558
+ --argjson data_models "$models_json" \
559
+ '{
560
+ path: $path,
561
+ hash: $hash,
562
+ lines: $lines,
563
+ language: $lang,
564
+ imports: $imports,
565
+ exports: $exports,
566
+ classes: $classes,
567
+ functions: $functions,
568
+ decorators: $decorators,
569
+ api_endpoints: $api_endpoints,
570
+ data_models: $data_models,
571
+ extraction_confidence: "high"
572
+ }'
573
+ }
574
+
575
+ # === Go Extractor ===
576
+
577
+ _extract_go() {
578
+ local file="$1"
579
+ local rel_path="$2"
580
+ local hash line_count
581
+
582
+ hash=$(file_checksum "$file")
583
+ line_count=$(wc -l < "$file" | tr -d ' ')
584
+
585
+ # --- Imports ---
586
+ local imports_json="[]"
587
+ imports_json=$({ grep -n -E '^[[:space:]]+"' "$file" 2>/dev/null || true; } | awk -F: '
588
+ {
589
+ line = $1; content = $2
590
+ gsub(/^[[:space:]]*"/, "", content)
591
+ gsub(/".*$/, "", content)
592
+ if (content != "") {
593
+ printf "{\"from\":\"%s\",\"import\":null,\"line\":%s,\"is_local\":false}\n", content, line
594
+ }
595
+ }' | jq -s '.' 2>/dev/null || echo '[]')
596
+
597
+ # --- Structs and Interfaces ---
598
+ local classes_json="[]"
599
+ classes_json=$({ grep -n -E '^type \w+ (struct|interface)' "$file" 2>/dev/null || true; } | awk -F: '
600
+ {
601
+ line = $1; content = $2
602
+ gsub(/^type /, "", content)
603
+ if (content ~ / struct/) {
604
+ gsub(/ struct.*$/, "", content)
605
+ printf "{\"name\":\"%s\",\"type\":\"struct\",\"line\":%s}\n", content, line
606
+ } else if (content ~ / interface/) {
607
+ gsub(/ interface.*$/, "", content)
608
+ printf "{\"name\":\"%s\",\"type\":\"interface\",\"line\":%s}\n", content, line
609
+ }
610
+ }' | jq -s '.' 2>/dev/null || echo '[]')
611
+
612
+ # --- Functions ---
613
+ local functions_json="[]"
614
+ functions_json=$({ grep -n -E '^func ' "$file" 2>/dev/null || true; } | awk -F: '
615
+ {
616
+ line = $1; content = $2
617
+ gsub(/^func /, "", content)
618
+ # Check for method receiver
619
+ if (content ~ /^\(/) {
620
+ # Method: func (r *Receiver) Name(params)
621
+ sub(/^\([^)]*\)\s*/, "", content)
622
+ }
623
+ name = content
624
+ gsub(/[( ].*$/, "", name)
625
+ printf "{\"name\":\"%s\",\"line\":%s}\n", name, line
626
+ }' | jq -s '.' 2>/dev/null || echo '[]')
627
+
628
+ # --- API Endpoints (net/http patterns) ---
629
+ local endpoints_json="[]"
630
+ endpoints_json=$({ grep -n -E '(http\.(HandleFunc|Handle)|\.GET\(|\.POST\(|\.PUT\(|\.DELETE\(|\.Group\()' "$file" 2>/dev/null || true; } | awk -F: '
631
+ {
632
+ line = $1; content = $2
633
+ method = "unknown"
634
+ if (index(content, ".GET(") > 0) method = "GET"
635
+ else if (index(content, ".POST(") > 0) method = "POST"
636
+ else if (index(content, ".PUT(") > 0) method = "PUT"
637
+ else if (index(content, ".DELETE(") > 0) method = "DELETE"
638
+ else if (index(content, "HandleFunc") > 0) method = "ANY"
639
+ path = ""
640
+ if (match(content, /"[^"]*"/)) {
641
+ path = substr(content, RSTART+1, RLENGTH-2)
642
+ }
643
+ printf "{\"method\":\"%s\",\"path\":\"%s\",\"line\":%s}\n", method, path, line
644
+ }' | jq -s '.' 2>/dev/null || echo '[]')
645
+
646
+ # --- Exports (capitalized names) ---
647
+ local exports_json
648
+ exports_json=$(jq -n \
649
+ --argjson classes "$classes_json" \
650
+ --argjson functions "$functions_json" \
651
+ '[$classes[] | {name: .name, type: .type, line: .line}] +
652
+ [$functions[] | {name: .name, type: "function", line: .line}]' 2>/dev/null || echo '[]')
653
+
654
+ # --- Assemble ---
655
+ jq -n \
656
+ --arg path "$rel_path" \
657
+ --arg hash "$hash" \
658
+ --argjson lines "$line_count" \
659
+ --argjson imports "$imports_json" \
660
+ --argjson exports "$exports_json" \
661
+ --argjson classes "$classes_json" \
662
+ --argjson functions "$functions_json" \
663
+ --argjson api_endpoints "$endpoints_json" \
664
+ '{
665
+ path: $path,
666
+ hash: $hash,
667
+ lines: $lines,
668
+ language: "go",
669
+ imports: $imports,
670
+ exports: $exports,
671
+ classes: $classes,
672
+ functions: $functions,
673
+ decorators: [],
674
+ api_endpoints: $api_endpoints,
675
+ data_models: [],
676
+ extraction_confidence: "high"
677
+ }'
678
+ }
679
+
680
+ # === Rust Extractor ===
681
+
682
+ _extract_rust() {
683
+ local file="$1"
684
+ local rel_path="$2"
685
+ local hash line_count
686
+
687
+ hash=$(file_checksum "$file")
688
+ line_count=$(wc -l < "$file" | tr -d ' ')
689
+
690
+ # --- Imports ---
691
+ local imports_json="[]"
692
+ imports_json=$({ grep -n -E '^use ' "$file" 2>/dev/null || true; } | awk '
693
+ {
694
+ colon_pos = index($0, ":")
695
+ line = substr($0, 1, colon_pos - 1)
696
+ content = substr($0, colon_pos + 1)
697
+ gsub(/^use /, "", content)
698
+ gsub(/;.*$/, "", content)
699
+ gsub(/ *$/, "", content)
700
+ printf "{\"from\":\"%s\",\"import\":null,\"line\":%s,\"is_local\":false}\n", content, line
701
+ }' | jq -s '.' 2>/dev/null || echo '[]')
702
+
703
+ # --- Structs/Enums/Traits ---
704
+ local classes_json="[]"
705
+ classes_json=$({ grep -n -E '^(pub )?(struct |enum |trait )' "$file" 2>/dev/null || true; } | awk -F: '
706
+ {
707
+ line = $1; content = $2
708
+ gsub(/^pub /, "", content)
709
+ decl_type = "struct"
710
+ if (content ~ /^enum /) decl_type = "enum"
711
+ else if (content ~ /^trait /) decl_type = "trait"
712
+ gsub(/^(struct |enum |trait )/, "", content)
713
+ name = content
714
+ gsub(/[ <({:].*$/, "", name)
715
+ printf "{\"name\":\"%s\",\"type\":\"%s\",\"line\":%s}\n", name, decl_type, line
716
+ }' | jq -s '.' 2>/dev/null || echo '[]')
717
+
718
+ # --- Functions ---
719
+ local functions_json="[]"
720
+ functions_json=$({ grep -n -E '^(pub )?(async )?fn ' "$file" 2>/dev/null || true; } | awk -F: '
721
+ {
722
+ line = $1; content = $2
723
+ gsub(/^(pub )?(async )?fn /, "", content)
724
+ name = content
725
+ gsub(/[( <:].*$/, "", name)
726
+ printf "{\"name\":\"%s\",\"line\":%s}\n", name, line
727
+ }' | jq -s '.' 2>/dev/null || echo '[]')
728
+
729
+ # --- Exports ---
730
+ local exports_json
731
+ exports_json=$(jq -n \
732
+ --argjson classes "$classes_json" \
733
+ --argjson functions "$functions_json" \
734
+ '[$classes[] | {name: .name, type: .type, line: .line}] +
735
+ [$functions[] | {name: .name, type: "function", line: .line}]' 2>/dev/null || echo '[]')
736
+
737
+ # --- Assemble ---
738
+ jq -n \
739
+ --arg path "$rel_path" \
740
+ --arg hash "$hash" \
741
+ --argjson lines "$line_count" \
742
+ --argjson imports "$imports_json" \
743
+ --argjson exports "$exports_json" \
744
+ --argjson classes "$classes_json" \
745
+ --argjson functions "$functions_json" \
746
+ '{
747
+ path: $path,
748
+ hash: $hash,
749
+ lines: $lines,
750
+ language: "rust",
751
+ imports: $imports,
752
+ exports: $exports,
753
+ classes: $classes,
754
+ functions: $functions,
755
+ decorators: [],
756
+ api_endpoints: [],
757
+ data_models: [],
758
+ extraction_confidence: "high"
759
+ }'
760
+ }
761
+
762
+ # === Generic Extractor (fallback) ===
763
+
764
+ _extract_generic() {
765
+ local file="$1"
766
+ local rel_path="$2"
767
+ local hash line_count
768
+
769
+ hash=$(file_checksum "$file")
770
+ line_count=$(wc -l < "$file" | tr -d ' ')
771
+
772
+ # --- Generic import patterns ---
773
+ local imports_json="[]"
774
+ imports_json=$({ grep -n -E '^(import |from |use |require\(|include |#include )' "$file" 2>/dev/null || true; } | awk -F: '
775
+ {
776
+ line = $1; content = $2
777
+ gsub(/ /, "", content)
778
+ printf "{\"from\":null,\"import\":\"%s\",\"line\":%s,\"is_local\":false}\n", content, line
779
+ }' | jq -s '.' 2>/dev/null || echo '[]')
780
+
781
+ # --- Generic function patterns ---
782
+ local functions_json="[]"
783
+ functions_json=$({ grep -n -E '^( )?(function |def |func |fn |sub |proc )' "$file" 2>/dev/null || true; } | awk -F: '
784
+ {
785
+ line = $1; content = $2
786
+ gsub(/^( )?(function |def |func |fn |sub |proc )/, "", content)
787
+ name = content
788
+ gsub(/[( {:].*$/, "", name)
789
+ gsub(/ /, "", name)
790
+ if (name != "") {
791
+ printf "{\"name\":\"%s\",\"line\":%s}\n", name, line
792
+ }
793
+ }' | jq -s '.' 2>/dev/null || echo '[]')
794
+
795
+ # --- Generic class patterns ---
796
+ local classes_json="[]"
797
+ classes_json=$({ grep -n -E '^(export )?(class |struct |interface |type |enum )' "$file" 2>/dev/null || true; } | awk -F: '
798
+ {
799
+ line = $1; content = $2
800
+ gsub(/^export /, "", content)
801
+ decl_type = "class"
802
+ if (content ~ /^interface /) decl_type = "interface"
803
+ else if (content ~ /^struct /) decl_type = "struct"
804
+ else if (content ~ /^type /) decl_type = "type"
805
+ else if (content ~ /^enum /) decl_type = "enum"
806
+ gsub(/^(class |struct |interface |type |enum )/, "", content)
807
+ name = content
808
+ gsub(/[ <({:].*$/, "", name)
809
+ if (name != "") {
810
+ printf "{\"name\":\"%s\",\"type\":\"%s\",\"line\":%s}\n", name, decl_type, line
811
+ }
812
+ }' | jq -s '.' 2>/dev/null || echo '[]')
813
+
814
+ # --- Assemble ---
815
+ jq -n \
816
+ --arg path "$rel_path" \
817
+ --arg hash "$hash" \
818
+ --argjson lines "$line_count" \
819
+ --argjson imports "$imports_json" \
820
+ --argjson classes "$classes_json" \
821
+ --argjson functions "$functions_json" \
822
+ '{
823
+ path: $path,
824
+ hash: $hash,
825
+ lines: $lines,
826
+ language: "unknown",
827
+ imports: $imports,
828
+ exports: [],
829
+ classes: $classes,
830
+ functions: $functions,
831
+ decorators: [],
832
+ api_endpoints: [],
833
+ data_models: [],
834
+ extraction_confidence: "low"
835
+ }'
836
+ }
837
+
838
+ # === File Metadata Dispatcher ===
839
+
840
+ # Extract metadata from a single file
841
+ # Args: FILE_PATH, PROJECT_ROOT
842
+ # Outputs: JSON object to stdout
843
+ extract_file_metadata() {
844
+ local file="$1"
845
+ local project_root="$2"
846
+ local rel_path="${file#${project_root}/}"
847
+
848
+ local lang
849
+ lang=$(detect_file_language "$file")
850
+
851
+ case "$lang" in
852
+ python) _extract_python "$file" "$rel_path" ;;
853
+ java|kotlin) _extract_java "$file" "$rel_path" ;;
854
+ typescript|javascript|vue|svelte) _extract_typescript "$file" "$rel_path" ;;
855
+ go) _extract_go "$file" "$rel_path" ;;
856
+ rust) _extract_rust "$file" "$rel_path" ;;
857
+ *) _extract_generic "$file" "$rel_path" ;;
858
+ esac
859
+ }
860
+
861
+ # === Module Aggregator ===
862
+
863
+ # Aggregate per-file scans into a module-level JSON
864
+ # Args: MODULE_DIR, MODULE_SLUG, PROJECT_ROOT, OUTPUT_DIR
865
+ aggregate_module_prescan() {
866
+ local module_dir="$1"
867
+ local module_slug="$2"
868
+ local project_root="$3"
869
+ local output_dir="$4"
870
+
871
+ local tmpdir
872
+ tmpdir=$(mktemp -d)
873
+ local file_idx=0
874
+
875
+ # Collect source files in this module
876
+ local exclude_args=()
877
+ for d in "${PRESCAN_EXCLUDE_DIRS[@]}"; do
878
+ exclude_args+=(-not -path "*/${d}/*")
879
+ done
880
+
881
+ while IFS= read -r src_file; do
882
+ [[ -z "$src_file" ]] && continue
883
+ _should_scan_file "$src_file" || continue
884
+
885
+ local result
886
+ if result=$(extract_file_metadata "$src_file" "$project_root" 2>/dev/null); then
887
+ echo "$result" > "$tmpdir/file_${file_idx}.json"
888
+ file_idx=$((file_idx + 1))
889
+ fi
890
+ done < <(find "$module_dir" -type f "${exclude_args[@]}" 2>/dev/null | head -500)
891
+
892
+ # Merge all file JSONs into module JSON
893
+ if [[ $file_idx -eq 0 ]]; then
894
+ echo '{"files":[],"module_summary":{"total_files":0}}'
895
+ rm -rf "$tmpdir"
896
+ return 0
897
+ fi
898
+
899
+ local files_array
900
+ files_array=$(jq -s '.' "$tmpdir"/file_*.json 2>/dev/null || echo '[]')
901
+
902
+ # Generate module summary
903
+ local summary
904
+ summary=$(echo "$files_array" | jq '{
905
+ total_files: length,
906
+ total_imports: ([.[].imports | length] | add),
907
+ total_exports: ([.[].exports | length] | add),
908
+ total_classes: ([.[].classes | length] | add),
909
+ total_functions: ([.[].functions | length] | add),
910
+ total_api_endpoints: ([.[].api_endpoints | length] | add),
911
+ total_data_models: ([.[].data_models | length] | add),
912
+ local_imports: [.[].imports[] | select(.is_local == true)] | group_by(.from) | map({module: .[0].from, count: length}),
913
+ external_deps: [.[].imports[] | select(.is_local == false)] | group_by(.from) | map({package: .[0].from, count: length}) | sort_by(-.count) | .[0:20]
914
+ }' 2>/dev/null || echo '{}')
915
+
916
+ # Assemble module JSON
917
+ jq -n \
918
+ --arg module "$module_slug" \
919
+ --argjson files "$files_array" \
920
+ --argjson summary "$summary" \
921
+ '{
922
+ module: $module,
923
+ scan_metadata: {
924
+ scan_timestamp: (now | todate),
925
+ extraction_method: "grep+awk+jq"
926
+ },
927
+ files: $files,
928
+ module_summary: $summary
929
+ }' > "${output_dir}/${module_slug}.json"
930
+
931
+ rm -rf "$tmpdir"
932
+ }
933
+
934
+ # === Main Entry Point ===
935
+
936
+ # Pre-scan an entire project
937
+ # Args: PROJECT_ROOT, OUTPUT_DIR
938
+ # Outputs: writes .atool-docs/pre-scan/*.json and manifest.json
939
+ pre_scan_project() {
940
+ local project_root="$1"
941
+ local output_dir="$2"
942
+
943
+ check_jq
944
+
945
+ ensure_dir "$output_dir"
946
+
947
+ local start_time
948
+ start_time=$(date +%s)
949
+
950
+ # Read module list from analysis-state.json
951
+ local state_file="$project_root/.atool-docs/analysis-state.json"
952
+ if [[ ! -f "$state_file" ]]; then
953
+ log_error "analysis-state.json not found — run Phase 0 discovery first"
954
+ return 1
955
+ fi
956
+
957
+ # Extract module paths and slugs from state
958
+ # Modules can be: (1) object keyed by slug, or (2) array of objects
959
+ local modules_json
960
+ modules_json=$(jq 'if (.modules | type) == "object" then
961
+ [.modules | to_entries[] | {slug: .key, path: (if .value.path then .value.path elif .value.dir then .value.dir else .key end)}]
962
+ elif (.modules | type) == "array" then
963
+ [.modules[] | {slug: (if .slug then .slug elif .name then .name else .path end), path: (if .path then .path else .dir end)}]
964
+ else [] end' "$state_file" 2>/dev/null)
965
+
966
+ local module_count
967
+ module_count=$(echo "$modules_json" | jq 'length' 2>/dev/null || echo "0")
968
+
969
+ if [[ "$module_count" -eq 0 ]]; then
970
+ log_warn "No modules found in analysis-state.json"
971
+ return 0
972
+ fi
973
+
974
+ log_info "Pre-scanning $module_count modules..."
975
+
976
+ local modules_processed=0
977
+ for ((i = 0; i < module_count; i++)); do
978
+ local module_slug module_path
979
+ module_slug=$(echo "$modules_json" | jq -r ".[$i].slug" 2>/dev/null)
980
+ module_path=$(echo "$modules_json" | jq -r ".[$i].path" 2>/dev/null)
981
+
982
+ [[ -z "$module_slug" || "$module_slug" == "null" ]] && continue
983
+ [[ -z "$module_path" || "$module_path" == "null" ]] && continue
984
+
985
+ local full_module_path="$project_root/$module_path"
986
+
987
+ if [[ ! -d "$full_module_path" ]]; then
988
+ log_warn "Module directory not found: $full_module_path"
989
+ continue
990
+ fi
991
+
992
+ # Check for incremental update
993
+ local prescan_file="$output_dir/${module_slug}.json"
994
+ if [[ -f "$prescan_file" ]]; then
995
+ # Check if any source file changed since last scan
996
+ local needs_rescan=false
997
+ local stored_hash
998
+ while IFS= read -r src_file; do
999
+ [[ -z "$src_file" ]] && continue
1000
+ local rel_path="${src_file#${project_root}/}"
1001
+ local current_hash
1002
+ current_hash=$(file_checksum "$src_file")
1003
+ stored_hash=$(jq -r --arg p "$rel_path" '.files[] | select(.path == $p) | .hash // ""' "$prescan_file" 2>/dev/null)
1004
+ if [[ "$current_hash" != "$stored_hash" ]]; then
1005
+ needs_rescan=true
1006
+ break
1007
+ fi
1008
+ done < <(find "$full_module_path" -type f \( -name '*.py' -o -name '*.java' -o -name '*.kt' \
1009
+ -o -name '*.ts' -o -name '*.tsx' -o -name '*.js' -o -name '*.jsx' \
1010
+ -o -name '*.go' -o -name '*.rs' -o -name '*.vue' -o -name '*.svelte' \
1011
+ -o -name '*.swift' -o -name '*.dart' -o -name '*.ets' \) 2>/dev/null | head -200)
1012
+
1013
+ if [[ "$needs_rescan" == "false" ]]; then
1014
+ log_info "Module $module_slug: unchanged, skipping"
1015
+ modules_processed=$((modules_processed + 1))
1016
+ continue
1017
+ fi
1018
+ fi
1019
+
1020
+ log_info "Scanning module: $module_slug ($module_path)"
1021
+ aggregate_module_prescan "$full_module_path" "$module_slug" "$project_root" "$output_dir"
1022
+ modules_processed=$((modules_processed + 1))
1023
+ done
1024
+
1025
+ # Generate manifest
1026
+ local end_time duration
1027
+ end_time=$(date +%s)
1028
+ duration=$((end_time - start_time))
1029
+
1030
+ local manifest
1031
+ manifest=$(jq -s '{
1032
+ version: "1.0",
1033
+ generated_at: (now | todate),
1034
+ total_modules: length,
1035
+ scan_duration_seconds: null,
1036
+ modules: [.[].module_summary // {} | {total_files, total_classes, total_functions, total_api_endpoints, total_data_models}]
1037
+ }' "$output_dir"/*.json 2>/dev/null || echo '{}')
1038
+
1039
+ # Add duration to manifest
1040
+ manifest=$(echo "$manifest" | jq --argjson dur "$duration" '.scan_duration_seconds = $dur')
1041
+
1042
+ echo "$manifest" > "$output_dir/manifest.json"
1043
+
1044
+ log_success "Pre-scan complete: $modules_processed modules in ${duration}s"
1045
+ }