octocode-cli 1.2.5 → 1.2.7

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 (303) hide show
  1. package/LICENSE +21 -63
  2. package/README.md +86 -109
  3. package/out/octocode-cli.js +7027 -7014
  4. package/package.json +8 -6
  5. package/skills/README.md +97 -120
  6. package/skills/octocode-code-engineer/.claude/settings.local.json +18 -0
  7. package/skills/octocode-code-engineer/.octocode/rfc/RFC-code-engineer-weakness-fixes.md +255 -0
  8. package/skills/octocode-code-engineer/.plan/VALIDATED_PLAN.md +223 -0
  9. package/skills/octocode-code-engineer/README.md +178 -0
  10. package/skills/octocode-code-engineer/SKILL.md +418 -0
  11. package/skills/octocode-code-engineer/coverage/architecture.ts.html +7828 -0
  12. package/skills/octocode-code-engineer/coverage/ast-helpers.ts.html +211 -0
  13. package/skills/octocode-code-engineer/coverage/ast-search.ts.html +1795 -0
  14. package/skills/octocode-code-engineer/coverage/base.css +224 -0
  15. package/skills/octocode-code-engineer/coverage/block-navigation.js +87 -0
  16. package/skills/octocode-code-engineer/coverage/cache.ts.html +376 -0
  17. package/skills/octocode-code-engineer/coverage/cli.ts.html +982 -0
  18. package/skills/octocode-code-engineer/coverage/clover.xml +3217 -0
  19. package/skills/octocode-code-engineer/coverage/collect-effects.ts.html +664 -0
  20. package/skills/octocode-code-engineer/coverage/collect-input-sources.ts.html +577 -0
  21. package/skills/octocode-code-engineer/coverage/collect-performance.ts.html +331 -0
  22. package/skills/octocode-code-engineer/coverage/collect-prototype-pollution.ts.html +421 -0
  23. package/skills/octocode-code-engineer/coverage/collect-security.ts.html +604 -0
  24. package/skills/octocode-code-engineer/coverage/collect-test-profile.ts.html +589 -0
  25. package/skills/octocode-code-engineer/coverage/coverage-final.json +30 -0
  26. package/skills/octocode-code-engineer/coverage/dependencies.ts.html +997 -0
  27. package/skills/octocode-code-engineer/coverage/dependency-summary.ts.html +688 -0
  28. package/skills/octocode-code-engineer/coverage/discovery.ts.html +322 -0
  29. package/skills/octocode-code-engineer/coverage/favicon.png +0 -0
  30. package/skills/octocode-code-engineer/coverage/graph-analytics.ts.html +1510 -0
  31. package/skills/octocode-code-engineer/coverage/index.html +536 -0
  32. package/skills/octocode-code-engineer/coverage/index.ts.html +826 -0
  33. package/skills/octocode-code-engineer/coverage/metrics.ts.html +553 -0
  34. package/skills/octocode-code-engineer/coverage/pipeline.ts.html +2044 -0
  35. package/skills/octocode-code-engineer/coverage/prettify.css +1 -0
  36. package/skills/octocode-code-engineer/coverage/prettify.js +2 -0
  37. package/skills/octocode-code-engineer/coverage/report-analysis.ts.html +1570 -0
  38. package/skills/octocode-code-engineer/coverage/report-writer.ts.html +1102 -0
  39. package/skills/octocode-code-engineer/coverage/security-detectors.ts.html +1747 -0
  40. package/skills/octocode-code-engineer/coverage/semantic-detectors.ts.html +2152 -0
  41. package/skills/octocode-code-engineer/coverage/semantic.ts.html +1897 -0
  42. package/skills/octocode-code-engineer/coverage/sort-arrow-sprite.png +0 -0
  43. package/skills/octocode-code-engineer/coverage/sorter.js +210 -0
  44. package/skills/octocode-code-engineer/coverage/summary-md.ts.html +1222 -0
  45. package/skills/octocode-code-engineer/coverage/test-quality-detectors.ts.html +1039 -0
  46. package/skills/octocode-code-engineer/coverage/tree-sitter-analyzer.ts.html +955 -0
  47. package/skills/octocode-code-engineer/coverage/ts-analyzer.ts.html +1213 -0
  48. package/skills/octocode-code-engineer/coverage/types.ts.html +2473 -0
  49. package/skills/octocode-code-engineer/coverage/utils.ts.html +820 -0
  50. package/skills/octocode-code-engineer/eslint.config.mjs +54 -0
  51. package/skills/octocode-code-engineer/minify-scripts.mjs +32 -0
  52. package/skills/octocode-code-engineer/package.json +54 -0
  53. package/skills/octocode-code-engineer/references/agent-ast-reading-rfc.md +95 -0
  54. package/skills/octocode-code-engineer/references/architecture-techniques.md +121 -0
  55. package/skills/octocode-code-engineer/references/ast-search.md +210 -0
  56. package/skills/octocode-code-engineer/references/ast-tree-search.md +151 -0
  57. package/skills/octocode-code-engineer/references/cli-reference.md +167 -0
  58. package/skills/octocode-code-engineer/references/concepts.md +107 -0
  59. package/skills/octocode-code-engineer/references/finding-categories.md +128 -0
  60. package/skills/octocode-code-engineer/references/improvement-roadmap.md +304 -0
  61. package/skills/octocode-code-engineer/references/output-files.md +144 -0
  62. package/skills/octocode-code-engineer/references/playbooks.md +204 -0
  63. package/skills/octocode-code-engineer/references/present-results.md +136 -0
  64. package/skills/octocode-code-engineer/references/tool-workflows.md +566 -0
  65. package/skills/octocode-code-engineer/references/validate-investigate.md +225 -0
  66. package/skills/octocode-code-engineer/scripts/analysis/dependencies.js +1 -0
  67. package/skills/octocode-code-engineer/scripts/analysis/dependency-summary.js +1 -0
  68. package/skills/octocode-code-engineer/scripts/analysis/discovery.js +1 -0
  69. package/skills/octocode-code-engineer/scripts/analysis/graph-analytics.js +1 -0
  70. package/skills/octocode-code-engineer/scripts/analysis/semantic.js +1 -0
  71. package/skills/octocode-code-engineer/scripts/ast/helpers.js +1 -0
  72. package/skills/octocode-code-engineer/scripts/ast/metrics.js +1 -0
  73. package/skills/octocode-code-engineer/scripts/ast/search.js +2 -0
  74. package/skills/octocode-code-engineer/scripts/ast/tree-search.js +2 -0
  75. package/skills/octocode-code-engineer/scripts/ast/tree-sitter.js +1 -0
  76. package/skills/octocode-code-engineer/scripts/ast/ts-analyzer.js +1 -0
  77. package/skills/octocode-code-engineer/scripts/collectors/chains.js +1 -0
  78. package/skills/octocode-code-engineer/scripts/collectors/effects.js +1 -0
  79. package/skills/octocode-code-engineer/scripts/collectors/input-sources.js +1 -0
  80. package/skills/octocode-code-engineer/scripts/collectors/performance.js +1 -0
  81. package/skills/octocode-code-engineer/scripts/collectors/prototype-pollution.js +1 -0
  82. package/skills/octocode-code-engineer/scripts/collectors/security.js +1 -0
  83. package/skills/octocode-code-engineer/scripts/collectors/test-profile.js +1 -0
  84. package/skills/octocode-code-engineer/scripts/common/is-direct-run.js +1 -0
  85. package/skills/octocode-code-engineer/scripts/common/utils.js +1 -0
  86. package/skills/octocode-code-engineer/scripts/detectors/code-quality.js +1 -0
  87. package/skills/octocode-code-engineer/scripts/detectors/cohesion.js +1 -0
  88. package/skills/octocode-code-engineer/scripts/detectors/coupling.js +1 -0
  89. package/skills/octocode-code-engineer/scripts/detectors/cycle.js +1 -0
  90. package/skills/octocode-code-engineer/scripts/detectors/dead-code.js +1 -0
  91. package/skills/octocode-code-engineer/scripts/detectors/import-style.js +1 -0
  92. package/skills/octocode-code-engineer/scripts/detectors/index.js +1 -0
  93. package/skills/octocode-code-engineer/scripts/detectors/security.js +1 -0
  94. package/skills/octocode-code-engineer/scripts/detectors/semantic.js +1 -0
  95. package/skills/octocode-code-engineer/scripts/detectors/shared.js +1 -0
  96. package/skills/octocode-code-engineer/scripts/detectors/test-quality.js +1 -0
  97. package/skills/octocode-code-engineer/scripts/index.js +1 -0
  98. package/skills/octocode-code-engineer/scripts/pipeline/cache.js +1 -0
  99. package/skills/octocode-code-engineer/scripts/pipeline/cli.js +1 -0
  100. package/skills/octocode-code-engineer/scripts/pipeline/main.js +2 -0
  101. package/skills/octocode-code-engineer/scripts/reporting/analysis.js +1 -0
  102. package/skills/octocode-code-engineer/scripts/reporting/summary-md.js +1 -0
  103. package/skills/octocode-code-engineer/scripts/reporting/writer.js +1 -0
  104. package/skills/octocode-code-engineer/scripts/types/constants.js +1 -0
  105. package/skills/octocode-code-engineer/scripts/types/index.js +1 -0
  106. package/skills/octocode-code-engineer/scripts/types/interfaces.js +1 -0
  107. package/skills/octocode-code-engineer/src/analysis/dependencies.test.ts +545 -0
  108. package/skills/octocode-code-engineer/src/analysis/dependencies.ts +406 -0
  109. package/skills/octocode-code-engineer/src/analysis/dependency-summary.test.ts +566 -0
  110. package/skills/octocode-code-engineer/src/analysis/dependency-summary.ts +257 -0
  111. package/skills/octocode-code-engineer/src/analysis/discovery.test.ts +420 -0
  112. package/skills/octocode-code-engineer/src/analysis/discovery.ts +87 -0
  113. package/skills/octocode-code-engineer/src/analysis/graph-analytics.test.ts +449 -0
  114. package/skills/octocode-code-engineer/src/analysis/graph-analytics.ts +534 -0
  115. package/skills/octocode-code-engineer/src/analysis/semantic.test.ts +1533 -0
  116. package/skills/octocode-code-engineer/src/analysis/semantic.ts +830 -0
  117. package/skills/octocode-code-engineer/src/ast/helpers.test.ts +185 -0
  118. package/skills/octocode-code-engineer/src/ast/helpers.ts +62 -0
  119. package/skills/octocode-code-engineer/src/ast/metrics.test.ts +304 -0
  120. package/skills/octocode-code-engineer/src/ast/metrics.ts +204 -0
  121. package/skills/octocode-code-engineer/src/ast/search.test.ts +647 -0
  122. package/skills/octocode-code-engineer/src/ast/search.ts +648 -0
  123. package/skills/octocode-code-engineer/src/ast/tree-search.test.ts +199 -0
  124. package/skills/octocode-code-engineer/src/ast/tree-search.ts +392 -0
  125. package/skills/octocode-code-engineer/src/ast/tree-sitter.test.ts +407 -0
  126. package/skills/octocode-code-engineer/src/ast/tree-sitter.ts +402 -0
  127. package/skills/octocode-code-engineer/src/ast/ts-analyzer.test.ts +1864 -0
  128. package/skills/octocode-code-engineer/src/ast/ts-analyzer.ts +509 -0
  129. package/skills/octocode-code-engineer/src/collectors/chains.ts +74 -0
  130. package/skills/octocode-code-engineer/src/collectors/effects.test.ts +490 -0
  131. package/skills/octocode-code-engineer/src/collectors/effects.ts +332 -0
  132. package/skills/octocode-code-engineer/src/collectors/input-sources.test.ts +144 -0
  133. package/skills/octocode-code-engineer/src/collectors/input-sources.ts +196 -0
  134. package/skills/octocode-code-engineer/src/collectors/performance.test.ts +82 -0
  135. package/skills/octocode-code-engineer/src/collectors/performance.ts +141 -0
  136. package/skills/octocode-code-engineer/src/collectors/prototype-pollution.test.ts +55 -0
  137. package/skills/octocode-code-engineer/src/collectors/prototype-pollution.ts +162 -0
  138. package/skills/octocode-code-engineer/src/collectors/security.test.ts +124 -0
  139. package/skills/octocode-code-engineer/src/collectors/security.ts +309 -0
  140. package/skills/octocode-code-engineer/src/collectors/test-profile.test.ts +97 -0
  141. package/skills/octocode-code-engineer/src/collectors/test-profile.ts +269 -0
  142. package/skills/octocode-code-engineer/src/common/is-direct-run.test.ts +32 -0
  143. package/skills/octocode-code-engineer/src/common/is-direct-run.ts +13 -0
  144. package/skills/octocode-code-engineer/src/common/utils.test.ts +463 -0
  145. package/skills/octocode-code-engineer/src/common/utils.ts +304 -0
  146. package/skills/octocode-code-engineer/src/detectors/code-quality.ts +966 -0
  147. package/skills/octocode-code-engineer/src/detectors/cohesion.ts +539 -0
  148. package/skills/octocode-code-engineer/src/detectors/coupling.ts +323 -0
  149. package/skills/octocode-code-engineer/src/detectors/cycle.ts +349 -0
  150. package/skills/octocode-code-engineer/src/detectors/dead-code.ts +320 -0
  151. package/skills/octocode-code-engineer/src/detectors/import-style.ts +376 -0
  152. package/skills/octocode-code-engineer/src/detectors/index.test.ts +3061 -0
  153. package/skills/octocode-code-engineer/src/detectors/index.ts +88 -0
  154. package/skills/octocode-code-engineer/src/detectors/security.test.ts +882 -0
  155. package/skills/octocode-code-engineer/src/detectors/security.ts +821 -0
  156. package/skills/octocode-code-engineer/src/detectors/semantic.ts +758 -0
  157. package/skills/octocode-code-engineer/src/detectors/shared.ts +49 -0
  158. package/skills/octocode-code-engineer/src/detectors/test-quality.test.ts +388 -0
  159. package/skills/octocode-code-engineer/src/detectors/test-quality.ts +367 -0
  160. package/skills/octocode-code-engineer/src/index.test.ts +4425 -0
  161. package/skills/octocode-code-engineer/src/index.ts +403 -0
  162. package/skills/octocode-code-engineer/src/pipeline/cache.test.ts +199 -0
  163. package/skills/octocode-code-engineer/src/pipeline/cache.ts +130 -0
  164. package/skills/octocode-code-engineer/src/pipeline/cli.test.ts +493 -0
  165. package/skills/octocode-code-engineer/src/pipeline/cli.ts +344 -0
  166. package/skills/octocode-code-engineer/src/pipeline/main.test.ts +174 -0
  167. package/skills/octocode-code-engineer/src/pipeline/main.ts +1074 -0
  168. package/skills/octocode-code-engineer/src/pipeline.test.ts +84 -0
  169. package/skills/octocode-code-engineer/src/reporting/analysis.test.ts +782 -0
  170. package/skills/octocode-code-engineer/src/reporting/analysis.ts +688 -0
  171. package/skills/octocode-code-engineer/src/reporting/output-contract.test.ts +463 -0
  172. package/skills/octocode-code-engineer/src/reporting/summary-md.test.ts +421 -0
  173. package/skills/octocode-code-engineer/src/reporting/summary-md.ts +714 -0
  174. package/skills/octocode-code-engineer/src/reporting/writer.ts +430 -0
  175. package/skills/octocode-code-engineer/src/sanity.test.ts +47 -0
  176. package/skills/octocode-code-engineer/src/types/constants.ts +248 -0
  177. package/skills/octocode-code-engineer/src/types/index.ts +80 -0
  178. package/skills/octocode-code-engineer/src/types/interfaces.ts +682 -0
  179. package/skills/octocode-code-engineer/tsconfig.json +17 -0
  180. package/skills/octocode-code-engineer/vitest.config.ts +8 -0
  181. package/skills/octocode-documentation-writer/README.md +113 -0
  182. package/skills/octocode-documentation-writer/SKILL.md +886 -0
  183. package/skills/octocode-documentation-writer/references/agent-discovery-analysis.md +453 -0
  184. package/skills/octocode-documentation-writer/references/agent-documentation-writer.md +255 -0
  185. package/skills/octocode-documentation-writer/references/agent-engineer-questions.md +247 -0
  186. package/skills/octocode-documentation-writer/references/agent-orchestrator.md +370 -0
  187. package/skills/octocode-documentation-writer/references/agent-qa-validator.md +227 -0
  188. package/skills/octocode-documentation-writer/references/agent-researcher.md +250 -0
  189. package/skills/octocode-documentation-writer/schemas/analysis-schema.json +886 -0
  190. package/skills/octocode-documentation-writer/schemas/discovery-tasks.json +96 -0
  191. package/skills/octocode-documentation-writer/schemas/documentation-structure.json +373 -0
  192. package/skills/octocode-documentation-writer/schemas/partial-discovery-schema.json +102 -0
  193. package/skills/octocode-documentation-writer/schemas/partial-research-schema.json +98 -0
  194. package/skills/octocode-documentation-writer/schemas/qa-results-schema.json +113 -0
  195. package/skills/octocode-documentation-writer/schemas/questions-schema.json +228 -0
  196. package/skills/octocode-documentation-writer/schemas/research-schema.json +104 -0
  197. package/skills/octocode-documentation-writer/schemas/state-schema.json +222 -0
  198. package/skills/octocode-documentation-writer/schemas/work-assignments-schema.json +74 -0
  199. package/skills/octocode-plan/SKILL.md +122 -116
  200. package/skills/octocode-prompt-optimizer/SKILL.md +617 -0
  201. package/skills/octocode-pull-request-reviewer/README.md +249 -0
  202. package/skills/octocode-pull-request-reviewer/SKILL.md +479 -0
  203. package/skills/octocode-pull-request-reviewer/references/dependency-check.md +74 -0
  204. package/skills/octocode-pull-request-reviewer/references/domain-reviewers.md +24 -0
  205. package/skills/octocode-pull-request-reviewer/references/execution-lifecycle.md +441 -0
  206. package/skills/octocode-pull-request-reviewer/references/flow-analysis-protocol.md +64 -0
  207. package/skills/octocode-pull-request-reviewer/references/output-template.md +174 -0
  208. package/skills/octocode-pull-request-reviewer/references/parallel-agent-protocol.md +182 -0
  209. package/skills/octocode-pull-request-reviewer/references/review-guidelines.md +26 -0
  210. package/skills/octocode-pull-request-reviewer/references/verification-checklist.md +40 -0
  211. package/skills/octocode-research/.claude/settings.local.json +46 -0
  212. package/skills/octocode-research/.octocode/plan/code-review-fixes/plan.md +312 -0
  213. package/skills/octocode-research/.octocode/plan/code-review-fixes/research.md +212 -0
  214. package/skills/octocode-research/.octocode/plans/NODE_SERVER_START_PLAN.md +755 -0
  215. package/skills/octocode-research/.octocode/research/code-review/research.md +371 -0
  216. package/skills/octocode-research/.octocode/review/IMPROVEMENTS.md +391 -0
  217. package/skills/octocode-research/.octocode/review/REVIEW_PLAN.md +289 -0
  218. package/skills/octocode-research/.octocode/review/REVIEW_REPORT.md +356 -0
  219. package/skills/octocode-research/AGENTS.md +349 -0
  220. package/skills/octocode-research/README.md +494 -0
  221. package/skills/octocode-research/SKILL.md +652 -274
  222. package/skills/octocode-research/docs/API_REFERENCE.md +562 -0
  223. package/skills/octocode-research/docs/ARCHITECTURE.md +554 -0
  224. package/skills/octocode-research/docs/FLOWS.md +577 -0
  225. package/skills/octocode-research/docs/OVERVIEW.md +564 -0
  226. package/skills/octocode-research/docs/SERVER_FLOWS.md +631 -0
  227. package/skills/octocode-research/ecosystem.config.cjs +88 -0
  228. package/skills/octocode-research/eslint.config.mjs +27 -0
  229. package/skills/octocode-research/package.json +84 -0
  230. package/skills/octocode-research/references/GUARDRAILS.md +40 -0
  231. package/skills/octocode-research/references/PARALLEL_AGENT_PROTOCOL.md +178 -0
  232. package/skills/octocode-research/references/roast-prompt.md +149 -0
  233. package/skills/octocode-research/scripts/server-init.d.ts +2 -0
  234. package/skills/octocode-research/scripts/server-init.js +2 -0
  235. package/skills/octocode-research/scripts/server.d.ts +8 -0
  236. package/skills/octocode-research/scripts/server.js +445 -0
  237. package/skills/octocode-research/src/__tests__/integration/circuitBreaker.test.ts +205 -0
  238. package/skills/octocode-research/src/__tests__/integration/routes.test.ts +374 -0
  239. package/skills/octocode-research/src/__tests__/unit/circuitBreaker.test.ts +245 -0
  240. package/skills/octocode-research/src/__tests__/unit/errorHandler.test.ts +183 -0
  241. package/skills/octocode-research/src/__tests__/unit/httpPreprocess.test.ts +157 -0
  242. package/skills/octocode-research/src/__tests__/unit/logger.test.ts +143 -0
  243. package/skills/octocode-research/src/__tests__/unit/queryParser.test.ts +130 -0
  244. package/skills/octocode-research/src/__tests__/unit/responseBuilder.test.ts +469 -0
  245. package/skills/octocode-research/src/__tests__/unit/retry.test.ts +205 -0
  246. package/skills/octocode-research/src/index.ts +186 -0
  247. package/skills/octocode-research/src/mcpCache.ts +49 -0
  248. package/skills/octocode-research/src/middleware/errorHandler.ts +65 -0
  249. package/skills/octocode-research/src/middleware/logger.ts +61 -0
  250. package/skills/octocode-research/src/middleware/queryParser.ts +115 -0
  251. package/skills/octocode-research/src/middleware/readiness.ts +17 -0
  252. package/skills/octocode-research/src/routes/github.ts +197 -0
  253. package/skills/octocode-research/src/routes/local.ts +175 -0
  254. package/skills/octocode-research/src/routes/lsp.ts +177 -0
  255. package/skills/octocode-research/src/routes/package.ts +127 -0
  256. package/skills/octocode-research/src/routes/prompts.ts +138 -0
  257. package/skills/octocode-research/src/routes/tools.ts +677 -0
  258. package/skills/octocode-research/src/server-init.ts +363 -0
  259. package/skills/octocode-research/src/server.ts +285 -0
  260. package/skills/octocode-research/src/types/errorGuards.ts +151 -0
  261. package/skills/octocode-research/src/types/express.d.ts +76 -0
  262. package/skills/octocode-research/src/types/guards.ts +98 -0
  263. package/skills/octocode-research/src/types/mcp.ts +119 -0
  264. package/skills/octocode-research/src/types/responses.ts +199 -0
  265. package/skills/octocode-research/src/types/toolTypes.ts +33 -0
  266. package/skills/octocode-research/src/utils/asyncTimeout.ts +116 -0
  267. package/skills/octocode-research/src/utils/circuitBreaker.ts +492 -0
  268. package/skills/octocode-research/src/utils/colors.ts +53 -0
  269. package/skills/octocode-research/src/utils/errorQueue.ts +71 -0
  270. package/skills/octocode-research/src/utils/logEmoji.ts +103 -0
  271. package/skills/octocode-research/src/utils/logger.ts +413 -0
  272. package/skills/octocode-research/src/utils/resilience.ts +169 -0
  273. package/skills/octocode-research/src/utils/responseBuilder.ts +495 -0
  274. package/skills/octocode-research/src/utils/responseFactory.ts +100 -0
  275. package/skills/octocode-research/src/utils/responseParser.ts +272 -0
  276. package/skills/octocode-research/src/utils/retry.ts +280 -0
  277. package/skills/octocode-research/src/utils/routeFactory.ts +117 -0
  278. package/skills/octocode-research/src/utils/url.ts +20 -0
  279. package/skills/octocode-research/src/validation/httpPreprocess.ts +155 -0
  280. package/skills/octocode-research/src/validation/index.ts +2 -0
  281. package/skills/octocode-research/src/validation/schemas.ts +578 -0
  282. package/skills/octocode-research/src/validation/toolCallSchema.ts +132 -0
  283. package/skills/octocode-research/tsconfig.json +21 -0
  284. package/skills/octocode-research/tsdown.config.ts +42 -0
  285. package/skills/octocode-research/vitest.config.ts +20 -0
  286. package/skills/octocode-researcher/SKILL.md +461 -0
  287. package/skills/octocode-researcher/references/fallbacks.md +120 -0
  288. package/skills/{octocode-local-search → octocode-researcher}/references/tool-reference.md +132 -49
  289. package/skills/{octocode-local-search → octocode-researcher}/references/workflow-patterns.md +204 -4
  290. package/skills/octocode-rfc-generator/SKILL.md +223 -0
  291. package/skills/octocode-rfc-generator/references/rfc-template.md +193 -0
  292. package/skills/octocode-roast/SKILL.md +63 -21
  293. package/skills/octocode-implement/SKILL.md +0 -293
  294. package/skills/octocode-implement/references/execution-phases.md +0 -317
  295. package/skills/octocode-implement/references/tool-reference.md +0 -403
  296. package/skills/octocode-implement/references/workflow-patterns.md +0 -385
  297. package/skills/octocode-local-search/SKILL.md +0 -449
  298. package/skills/octocode-pr-review/SKILL.md +0 -391
  299. package/skills/octocode-pr-review/references/domain-reviewers.md +0 -105
  300. package/skills/octocode-pr-review/references/execution-lifecycle.md +0 -116
  301. package/skills/octocode-pr-review/references/research-flows.md +0 -75
  302. package/skills/octocode-research/references/tool-reference.md +0 -304
  303. package/skills/octocode-research/references/workflow-patterns.md +0 -325
@@ -0,0 +1,830 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ import * as ts from 'typescript';
5
+
6
+ import { isTestFile } from '../common/utils.js';
7
+
8
+ import type { DependencyState, FileEntry } from '../types/index.js';
9
+
10
+ export interface SemanticContext {
11
+ service: ts.LanguageService;
12
+ checker: ts.TypeChecker;
13
+ program: ts.Program;
14
+ root: string;
15
+ }
16
+
17
+ export interface UnusedParam {
18
+ functionName: string;
19
+ paramName: string;
20
+ lineStart: number;
21
+ lineEnd: number;
22
+ }
23
+
24
+ export interface InterfaceImpl {
25
+ interfaceName: string;
26
+ className: string;
27
+ classFile: string;
28
+ classLine: number;
29
+ missingMembers: string[];
30
+ anycastMembers: string[];
31
+ }
32
+
33
+ export interface TypeHierarchyInfo {
34
+ name: string;
35
+ depth: number;
36
+ chain: string[];
37
+ lineStart: number;
38
+ }
39
+
40
+ export interface OverrideChainInfo {
41
+ methodName: string;
42
+ className: string;
43
+ depth: number;
44
+ chain: string[];
45
+ lineStart: number;
46
+ }
47
+
48
+ export interface ExportRefInfo {
49
+ count: number;
50
+ uniqueFiles: number;
51
+ lineStart: number;
52
+ lineEnd: number;
53
+ }
54
+
55
+ export interface LeakyReturn {
56
+ functionName: string;
57
+ returnType: string;
58
+ sourceFile: string;
59
+ lineStart: number;
60
+ }
61
+
62
+ export interface NarrowableParam {
63
+ functionName: string;
64
+ paramName: string;
65
+ declaredType: string;
66
+ actualTypes: string[];
67
+ narrowedType: string;
68
+ lineStart: number;
69
+ lineEnd: number;
70
+ }
71
+
72
+ export interface SemanticProfile {
73
+ file: string;
74
+ referenceCountByExport: Map<string, ExportRefInfo>;
75
+ unusedParams: UnusedParam[];
76
+ interfaceImpls: InterfaceImpl[];
77
+ typeHierarchyDepth: number;
78
+ typeHierarchies: TypeHierarchyInfo[];
79
+ overrideChains: OverrideChainInfo[];
80
+ abstractnessRatio: number;
81
+ unusedImports: Array<{ name: string; lineStart: number }>;
82
+ concreteImports: Array<{
83
+ name: string;
84
+ targetFile: string;
85
+ lineStart: number;
86
+ }>;
87
+ leakyReturns: LeakyReturn[];
88
+ narrowableParams: NarrowableParam[];
89
+ }
90
+
91
+ function findTsConfig(root: string): ts.ParsedCommandLine | null {
92
+ const configPath = ts.findConfigFile(
93
+ root,
94
+ ts.sys.fileExists,
95
+ 'tsconfig.json'
96
+ );
97
+ if (!configPath) return null;
98
+ const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
99
+ if (configFile.error) return null;
100
+ return ts.parseJsonConfigFileContent(
101
+ configFile.config,
102
+ ts.sys,
103
+ path.dirname(configPath)
104
+ );
105
+ }
106
+
107
+ export function createSemanticContext(
108
+ files: string[],
109
+ root: string
110
+ ): SemanticContext {
111
+ const parsed = findTsConfig(root);
112
+ const compilerOptions: ts.CompilerOptions = parsed?.options ?? {
113
+ target: ts.ScriptTarget.ES2022,
114
+ module: ts.ModuleKind.ESNext,
115
+ moduleResolution: ts.ModuleResolutionKind.Node10,
116
+ strict: true,
117
+ esModuleInterop: true,
118
+ skipLibCheck: true,
119
+ allowJs: true,
120
+ };
121
+
122
+ const fileSet = new Set(files);
123
+ const fileContents = new Map<string, string>();
124
+ for (const f of files) {
125
+ try {
126
+ fileContents.set(f, fs.readFileSync(f, 'utf8'));
127
+ } catch {
128
+ void 0;
129
+ }
130
+ }
131
+
132
+ const host: ts.LanguageServiceHost = {
133
+ getScriptFileNames: () => [...fileSet],
134
+ getScriptVersion: () => '1',
135
+ getScriptSnapshot: fileName => {
136
+ const content = fileContents.get(fileName);
137
+ if (content != null) return ts.ScriptSnapshot.fromString(content);
138
+ try {
139
+ const text = fs.readFileSync(fileName, 'utf8');
140
+ return ts.ScriptSnapshot.fromString(text);
141
+ } catch {
142
+ return undefined;
143
+ }
144
+ },
145
+ getCurrentDirectory: () => root,
146
+ getCompilationSettings: () => compilerOptions,
147
+ getDefaultLibFileName: ts.getDefaultLibFilePath,
148
+ fileExists: ts.sys.fileExists,
149
+ readFile: ts.sys.readFile,
150
+ readDirectory: ts.sys.readDirectory,
151
+ directoryExists: ts.sys.directoryExists,
152
+ getDirectories: ts.sys.getDirectories,
153
+ };
154
+
155
+ const service = ts.createLanguageService(host, ts.createDocumentRegistry());
156
+ const program = service.getProgram()!;
157
+ const checker = program.getTypeChecker();
158
+
159
+ return { service, checker, program, root };
160
+ }
161
+
162
+ function getExportReferenceInfo(
163
+ ctx: SemanticContext,
164
+ filePath: string,
165
+ exportName: string,
166
+ exportLine: number,
167
+ includeTests: boolean
168
+ ): { count: number; uniqueFiles: number } {
169
+ const sourceFile = ctx.program.getSourceFile(filePath);
170
+ if (!sourceFile) return { count: -1, uniqueFiles: 0 };
171
+
172
+ const node = findSymbolAtLine(sourceFile, exportName, exportLine);
173
+ if (!node) return { count: -1, uniqueFiles: 0 };
174
+
175
+ const refs = ctx.service.findReferences(filePath, node.getStart(sourceFile));
176
+ if (!refs) return { count: 0, uniqueFiles: 0 };
177
+
178
+ let count = 0;
179
+ const files = new Set<string>();
180
+ for (const group of refs) {
181
+ for (const ref of group.references) {
182
+ if (ref.isDefinition) continue;
183
+ if (!includeTests && isTestFile(ref.fileName)) continue;
184
+ count++;
185
+ files.add(ref.fileName);
186
+ }
187
+ }
188
+ return { count, uniqueFiles: files.size };
189
+ }
190
+
191
+ function findSymbolAtLine(
192
+ sourceFile: ts.SourceFile,
193
+ name: string,
194
+ line: number
195
+ ): ts.Node | undefined {
196
+ const lineStart = sourceFile.getPositionOfLineAndCharacter(
197
+ Math.max(0, line - 1),
198
+ 0
199
+ );
200
+ const lineEnd =
201
+ line <
202
+ sourceFile.getLineAndCharacterOfPosition(sourceFile.getEnd()).line + 1
203
+ ? sourceFile.getPositionOfLineAndCharacter(line, 0)
204
+ : sourceFile.getEnd();
205
+
206
+ let found: ts.Node | undefined;
207
+ const visit = (node: ts.Node): void => {
208
+ if (found) return;
209
+ if (node.getStart(sourceFile) >= lineStart && node.getEnd() <= lineEnd) {
210
+ if (ts.isIdentifier(node) && node.text === name) {
211
+ found = node;
212
+ return;
213
+ }
214
+ }
215
+ ts.forEachChild(node, visit);
216
+ };
217
+ ts.forEachChild(sourceFile, visit);
218
+ return found;
219
+ }
220
+
221
+ function getInheritanceDepth(
222
+ checker: ts.TypeChecker,
223
+ type: ts.Type
224
+ ): { depth: number; chain: string[] } {
225
+ const chain: string[] = [];
226
+ let current = type;
227
+ let depth = 0;
228
+ const seen = new Set<string>();
229
+
230
+ while (true) {
231
+ const bases = current.getBaseTypes?.() ?? [];
232
+ if (bases.length === 0) break;
233
+ const base = bases[0];
234
+ const name = checker.typeToString(base);
235
+ if (seen.has(name)) break;
236
+ seen.add(name);
237
+ chain.push(name);
238
+ depth++;
239
+ current = base;
240
+ if (depth > 20) break;
241
+ }
242
+
243
+ return { depth, chain };
244
+ }
245
+
246
+ function collectExportReferences(
247
+ ctx: SemanticContext,
248
+ filePath: string,
249
+ fileEntry: FileEntry,
250
+ includeTests: boolean
251
+ ): Map<string, ExportRefInfo> {
252
+ const result = new Map<string, ExportRefInfo>();
253
+ const exports = fileEntry.dependencyProfile?.declaredExports ?? [];
254
+ for (const exp of exports) {
255
+ if (exp.lineStart == null) continue;
256
+ const refInfo = getExportReferenceInfo(
257
+ ctx,
258
+ filePath,
259
+ exp.name,
260
+ exp.lineStart,
261
+ includeTests
262
+ );
263
+ result.set(exp.name, {
264
+ count: refInfo.count,
265
+ uniqueFiles: refInfo.uniqueFiles,
266
+ lineStart: exp.lineStart,
267
+ lineEnd: exp.lineEnd ?? exp.lineStart,
268
+ });
269
+ }
270
+ return result;
271
+ }
272
+
273
+ function findFunctionNode(
274
+ sourceFile: ts.SourceFile,
275
+ fnName: string,
276
+ lineStart: number,
277
+ lineEnd: number
278
+ ): ts.FunctionLikeDeclaration | undefined {
279
+ const fnPos = sourceFile.getPositionOfLineAndCharacter(
280
+ Math.max(0, lineStart - 1),
281
+ 0
282
+ );
283
+ let fnNode: ts.Node | undefined;
284
+ const findFn = (node: ts.Node): void => {
285
+ if (fnNode) return;
286
+ if (
287
+ node.getStart(sourceFile) >= fnPos &&
288
+ node.getEnd() <=
289
+ sourceFile.getPositionOfLineAndCharacter(
290
+ Math.min(
291
+ lineEnd,
292
+ sourceFile.getLineAndCharacterOfPosition(sourceFile.getEnd())
293
+ .line + 1
294
+ ) - 1,
295
+ 0
296
+ ) +
297
+ 200
298
+ ) {
299
+ if (
300
+ ts.isFunctionDeclaration(node) ||
301
+ ts.isMethodDeclaration(node) ||
302
+ ts.isArrowFunction(node) ||
303
+ ts.isFunctionExpression(node)
304
+ ) {
305
+ const name =
306
+ node.name && ts.isIdentifier(node.name) ? node.name.text : '';
307
+ if (name === fnName || fnName === '<anonymous>') {
308
+ fnNode = node;
309
+ return;
310
+ }
311
+ }
312
+ }
313
+ ts.forEachChild(node, findFn);
314
+ };
315
+ ts.forEachChild(sourceFile, findFn);
316
+ return fnNode as ts.FunctionLikeDeclaration | undefined;
317
+ }
318
+
319
+ function collectUnusedParams(
320
+ ctx: SemanticContext,
321
+ filePath: string,
322
+ sourceFile: ts.SourceFile,
323
+ fileEntry: FileEntry
324
+ ): UnusedParam[] {
325
+ const results: UnusedParam[] = [];
326
+ for (const fn of fileEntry.functions) {
327
+ if (!fn.params || fn.params === 0) continue;
328
+ if (fn.name === '<anonymous>' || fn.name === '') continue;
329
+
330
+ const fnNode = findFunctionNode(sourceFile, fn.name, fn.lineStart, fn.lineEnd);
331
+ if (
332
+ !fnNode ||
333
+ !(
334
+ ts.isFunctionDeclaration(fnNode) ||
335
+ ts.isMethodDeclaration(fnNode) ||
336
+ ts.isArrowFunction(fnNode) ||
337
+ ts.isFunctionExpression(fnNode)
338
+ )
339
+ )
340
+ continue;
341
+
342
+ for (const param of fnNode.parameters) {
343
+ if (!ts.isIdentifier(param.name)) continue;
344
+ const paramName = param.name.text;
345
+ if (paramName.startsWith('_')) continue;
346
+
347
+ const refs = ctx.service.findReferences(
348
+ filePath,
349
+ param.name.getStart(sourceFile)
350
+ );
351
+ let usageCount = 0;
352
+ if (refs) {
353
+ for (const group of refs) {
354
+ for (const ref of group.references) {
355
+ if (!ref.isDefinition) usageCount++;
356
+ }
357
+ }
358
+ }
359
+ if (usageCount === 0) {
360
+ results.push({
361
+ functionName: fn.name,
362
+ paramName,
363
+ lineStart: fn.lineStart,
364
+ lineEnd: fn.lineEnd,
365
+ });
366
+ }
367
+ }
368
+ }
369
+ return results;
370
+ }
371
+
372
+ function analyzeTypeHierarchy(
373
+ ctx: SemanticContext,
374
+ sourceFile: ts.SourceFile,
375
+ fileEntry: FileEntry,
376
+ profile: SemanticProfile
377
+ ): number {
378
+ let abstractCount = 0;
379
+ let totalExportTypes = 0;
380
+ const exports = fileEntry.dependencyProfile?.declaredExports ?? [];
381
+
382
+ const visit = (node: ts.Node): void => {
383
+ if (ts.isClassDeclaration(node) && node.name) {
384
+ const type = ctx.checker.getTypeAtLocation(node);
385
+ const { depth, chain } = getInheritanceDepth(ctx.checker, type);
386
+ if (depth > 0) {
387
+ profile.typeHierarchies.push({
388
+ name: node.name.text,
389
+ depth,
390
+ chain,
391
+ lineStart:
392
+ sourceFile.getLineAndCharacterOfPosition(
393
+ node.getStart(sourceFile)
394
+ ).line + 1,
395
+ });
396
+ if (depth > profile.typeHierarchyDepth) {
397
+ profile.typeHierarchyDepth = depth;
398
+ }
399
+ }
400
+
401
+ if (node.heritageClauses) {
402
+ for (const clause of node.heritageClauses) {
403
+ if (clause.token === ts.SyntaxKind.ImplementsKeyword) {
404
+ for (const expr of clause.types) {
405
+ const ifaceType = ctx.checker.getTypeAtLocation(expr);
406
+ const ifaceName = ctx.checker.typeToString(ifaceType);
407
+ const classType = ctx.checker.getTypeAtLocation(node);
408
+ const ifaceProps = ifaceType.getProperties?.() ?? [];
409
+ const classProps = new Set(
410
+ (classType.getProperties?.() ?? []).map(p => p.name)
411
+ );
412
+ const missing = ifaceProps
413
+ .filter(p => !classProps.has(p.name))
414
+ .map(p => p.name);
415
+
416
+ const anycastMembers: string[] = [];
417
+ for (const prop of ifaceProps) {
418
+ if (classProps.has(prop.name)) {
419
+ const classProp = classType.getProperty?.(prop.name);
420
+ if (classProp) {
421
+ const classPropType = ctx.checker.getTypeOfSymbolAtLocation(
422
+ classProp,
423
+ node
424
+ );
425
+ const typeStr = ctx.checker.typeToString(classPropType);
426
+ if (typeStr === 'any') anycastMembers.push(prop.name);
427
+ }
428
+ }
429
+ }
430
+
431
+ if (missing.length > 0 || anycastMembers.length > 0) {
432
+ profile.interfaceImpls.push({
433
+ interfaceName: ifaceName,
434
+ className: node.name!.text,
435
+ classFile: fileEntry.file,
436
+ classLine:
437
+ sourceFile.getLineAndCharacterOfPosition(
438
+ node.getStart(sourceFile)
439
+ ).line + 1,
440
+ missingMembers: missing,
441
+ anycastMembers,
442
+ });
443
+ }
444
+ }
445
+ }
446
+ }
447
+ }
448
+
449
+ if (node.modifiers?.some(m => m.kind === ts.SyntaxKind.AbstractKeyword)) {
450
+ abstractCount++;
451
+ }
452
+
453
+ const baseMethods = new Map<string, number>();
454
+ const classType = ctx.checker.getTypeAtLocation(node);
455
+ let currentType = classType;
456
+ let baseDepth = 0;
457
+ while (true) {
458
+ const bases = currentType.getBaseTypes?.() ?? [];
459
+ if (bases.length === 0) break;
460
+ baseDepth++;
461
+ const baseType = bases[0];
462
+ for (const prop of baseType.getProperties?.() ?? []) {
463
+ const decl = prop.getDeclarations?.()?.[0];
464
+ if (
465
+ decl &&
466
+ (ts.isMethodDeclaration(decl) || ts.isMethodSignature(decl))
467
+ ) {
468
+ baseMethods.set(
469
+ prop.name,
470
+ Math.max(baseMethods.get(prop.name) ?? 0, baseDepth)
471
+ );
472
+ }
473
+ }
474
+ currentType = baseType;
475
+ if (baseDepth > 20) break;
476
+ }
477
+
478
+ for (const member of node.members) {
479
+ if (
480
+ ts.isMethodDeclaration(member) &&
481
+ member.name &&
482
+ ts.isIdentifier(member.name)
483
+ ) {
484
+ const methodName = member.name.text;
485
+ const overrideDepth = baseMethods.get(methodName);
486
+ if (overrideDepth != null && overrideDepth > 0) {
487
+ profile.overrideChains.push({
488
+ methodName,
489
+ className: node.name!.text,
490
+ depth: overrideDepth,
491
+ chain: [],
492
+ lineStart:
493
+ sourceFile.getLineAndCharacterOfPosition(
494
+ member.getStart(sourceFile)
495
+ ).line + 1,
496
+ });
497
+ }
498
+ }
499
+ }
500
+ }
501
+
502
+ if (ts.isInterfaceDeclaration(node)) {
503
+ abstractCount++;
504
+ totalExportTypes++;
505
+ }
506
+
507
+ if (ts.isTypeAliasDeclaration(node)) {
508
+ totalExportTypes++;
509
+ }
510
+
511
+ ts.forEachChild(node, visit);
512
+ };
513
+ ts.forEachChild(sourceFile, visit);
514
+
515
+ totalExportTypes += exports.length;
516
+ return totalExportTypes > 0 ? abstractCount / totalExportTypes : 0;
517
+ }
518
+
519
+ function analyzeImports(
520
+ ctx: SemanticContext,
521
+ filePath: string,
522
+ sourceFile: ts.SourceFile,
523
+ fileEntry: FileEntry
524
+ ): {
525
+ unusedImports: Array<{ name: string; lineStart: number }>;
526
+ concreteImports: Array<{ name: string; targetFile: string; lineStart: number }>;
527
+ } {
528
+ const unusedImports: Array<{ name: string; lineStart: number }> = [];
529
+ const concreteImports: Array<{ name: string; targetFile: string; lineStart: number }> = [];
530
+
531
+ const imports = fileEntry.dependencyProfile?.importedSymbols ?? [];
532
+ for (const imp of imports) {
533
+ if (imp.lineStart == null) continue;
534
+ const node = findSymbolAtLine(sourceFile, imp.localName, imp.lineStart);
535
+ if (!node) continue;
536
+
537
+ const refs = ctx.service.findReferences(
538
+ filePath,
539
+ node.getStart(sourceFile)
540
+ );
541
+ let sameFileUsageCount = 0;
542
+ if (refs) {
543
+ for (const group of refs) {
544
+ for (const ref of group.references) {
545
+ if (ref.isDefinition) continue;
546
+ if (ref.fileName !== filePath) continue;
547
+ sameFileUsageCount++;
548
+ }
549
+ }
550
+ }
551
+
552
+ if (sameFileUsageCount === 0) {
553
+ unusedImports.push({ name: imp.localName, lineStart: imp.lineStart });
554
+ }
555
+
556
+ if (imp.resolvedModule) {
557
+ const targetSrc = ctx.program.getSourceFile(
558
+ path.resolve(ctx.root, imp.resolvedModule)
559
+ );
560
+ if (targetSrc) {
561
+ const sym = ctx.checker.getSymbolAtLocation(node);
562
+ if (sym) {
563
+ const aliased =
564
+ sym.flags & ts.SymbolFlags.Alias
565
+ ? ctx.checker.getAliasedSymbol(sym)
566
+ : sym;
567
+ const decl = aliased.getDeclarations?.()?.[0];
568
+ if (decl && ts.isClassDeclaration(decl)) {
569
+ const isAbstract = decl.modifiers?.some(
570
+ m => m.kind === ts.SyntaxKind.AbstractKeyword
571
+ );
572
+ if (!isAbstract) {
573
+ concreteImports.push({
574
+ name: imp.localName,
575
+ targetFile: imp.resolvedModule,
576
+ lineStart: imp.lineStart,
577
+ });
578
+ }
579
+ }
580
+ }
581
+ }
582
+ }
583
+ }
584
+ return { unusedImports, concreteImports };
585
+ }
586
+
587
+ function detectLeakyReturns(
588
+ ctx: SemanticContext,
589
+ filePath: string,
590
+ sourceFile: ts.SourceFile,
591
+ fileEntry: FileEntry
592
+ ): LeakyReturn[] {
593
+ const results: LeakyReturn[] = [];
594
+ const exportedFns = fileEntry.functions.filter(fn =>
595
+ fileEntry.dependencyProfile?.declaredExports?.some(e => e.name === fn.name)
596
+ );
597
+ for (const fn of exportedFns) {
598
+ const fnPos = sourceFile.getPositionOfLineAndCharacter(
599
+ Math.max(0, fn.lineStart - 1),
600
+ 0
601
+ );
602
+ let fnNode: ts.FunctionDeclaration | ts.MethodDeclaration | undefined;
603
+ const findFnDecl = (node: ts.Node): void => {
604
+ if (fnNode) return;
605
+ if (
606
+ (ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node)) &&
607
+ node.name &&
608
+ ts.isIdentifier(node.name) &&
609
+ node.name.text === fn.name &&
610
+ node.getStart(sourceFile) >= fnPos
611
+ ) {
612
+ fnNode = node;
613
+ return;
614
+ }
615
+ ts.forEachChild(node, findFnDecl);
616
+ };
617
+ ts.forEachChild(sourceFile, findFnDecl);
618
+
619
+ if (fnNode) {
620
+ const sig = ctx.checker.getSignatureFromDeclaration(fnNode);
621
+ if (sig) {
622
+ const retType = ctx.checker.getReturnTypeOfSignature(sig);
623
+ const retSymbol = retType.symbol || retType.aliasSymbol;
624
+ if (retSymbol?.declarations?.[0]) {
625
+ const retDeclFile =
626
+ retSymbol.declarations[0].getSourceFile().fileName;
627
+ const relRetFile = path.relative(ctx.root, retDeclFile);
628
+ if (
629
+ retDeclFile !== filePath &&
630
+ !relRetFile.startsWith('node_modules') &&
631
+ !retDeclFile.includes('lib.')
632
+ ) {
633
+ results.push({
634
+ functionName: fn.name,
635
+ returnType: ctx.checker.typeToString(retType),
636
+ sourceFile: relRetFile,
637
+ lineStart: fn.lineStart,
638
+ });
639
+ }
640
+ }
641
+ }
642
+ }
643
+ }
644
+ return results;
645
+ }
646
+
647
+ function detectNarrowableParams(
648
+ ctx: SemanticContext,
649
+ filePath: string,
650
+ sourceFile: ts.SourceFile,
651
+ fileEntry: FileEntry
652
+ ): NarrowableParam[] {
653
+ const results: NarrowableParam[] = [];
654
+ const exportedFns = fileEntry.functions.filter(fn =>
655
+ fileEntry.dependencyProfile?.declaredExports?.some(e => e.name === fn.name)
656
+ );
657
+ for (const fn of exportedFns) {
658
+ if (!fn.params || fn.params < 1) continue;
659
+ const fnPos = sourceFile.getPositionOfLineAndCharacter(
660
+ Math.max(0, fn.lineStart - 1),
661
+ 0
662
+ );
663
+ let fnDeclNode: ts.FunctionDeclaration | undefined;
664
+ const findDecl = (node: ts.Node): void => {
665
+ if (fnDeclNode) return;
666
+ if (
667
+ ts.isFunctionDeclaration(node) &&
668
+ node.name?.text === fn.name &&
669
+ node.getStart(sourceFile) >= fnPos
670
+ ) {
671
+ fnDeclNode = node;
672
+ return;
673
+ }
674
+ ts.forEachChild(node, findDecl);
675
+ };
676
+ ts.forEachChild(sourceFile, findDecl);
677
+ if (!fnDeclNode) continue;
678
+
679
+ for (const param of fnDeclNode.parameters) {
680
+ if (!ts.isIdentifier(param.name)) continue;
681
+ const paramType = ctx.checker.getTypeAtLocation(param);
682
+ if (
683
+ !paramType.isUnion() &&
684
+ !(paramType.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown))
685
+ )
686
+ continue;
687
+
688
+ const declaredStr = ctx.checker.typeToString(paramType);
689
+ const refs = ctx.service.findReferences(
690
+ filePath,
691
+ fnDeclNode.name!.getStart(sourceFile)
692
+ );
693
+ if (!refs) continue;
694
+
695
+ const argTypes: string[] = [];
696
+ let allNarrow = true;
697
+ let callSiteCount = 0;
698
+
699
+ for (const group of refs) {
700
+ for (const ref of group.references) {
701
+ if (ref.isDefinition) continue;
702
+ const refSrc = ctx.program.getSourceFile(ref.fileName);
703
+ if (!refSrc) continue;
704
+ let tokenNode: ts.Node = refSrc;
705
+ const findToken = (n: ts.Node): void => {
706
+ if (
707
+ n.getStart(refSrc!) <= ref.textSpan.start &&
708
+ n.getEnd() >= ref.textSpan.start + ref.textSpan.length
709
+ ) {
710
+ tokenNode = n;
711
+ ts.forEachChild(n, findToken);
712
+ }
713
+ };
714
+ ts.forEachChild(refSrc, findToken);
715
+ let callExpr: ts.CallExpression | undefined;
716
+ let ancestor: ts.Node | undefined = tokenNode;
717
+ while (ancestor) {
718
+ if (ts.isCallExpression(ancestor)) {
719
+ callExpr = ancestor;
720
+ break;
721
+ }
722
+ ancestor = ancestor.parent;
723
+ }
724
+ if (!callExpr?.arguments) continue;
725
+
726
+ const paramIdx = fnDeclNode.parameters.indexOf(param);
727
+ if (paramIdx < 0 || paramIdx >= callExpr.arguments.length) {
728
+ allNarrow = false;
729
+ continue;
730
+ }
731
+
732
+ const argType = ctx.checker.getTypeAtLocation(
733
+ callExpr.arguments[paramIdx]
734
+ );
735
+ const argStr = ctx.checker.typeToString(argType);
736
+ argTypes.push(argStr);
737
+ callSiteCount++;
738
+
739
+ if (
740
+ argStr === declaredStr ||
741
+ argStr === 'any' ||
742
+ argStr === 'unknown'
743
+ ) {
744
+ allNarrow = false;
745
+ }
746
+ }
747
+ }
748
+
749
+ if (allNarrow && callSiteCount >= 2 && argTypes.length > 0) {
750
+ const uniqueArgTypes = [...new Set(argTypes)];
751
+ if (uniqueArgTypes.length <= 2) {
752
+ results.push({
753
+ functionName: fn.name,
754
+ paramName: param.name.text,
755
+ declaredType: declaredStr,
756
+ actualTypes: uniqueArgTypes,
757
+ narrowedType:
758
+ uniqueArgTypes.length === 1
759
+ ? uniqueArgTypes[0]
760
+ : uniqueArgTypes.join(' | '),
761
+ lineStart: fn.lineStart,
762
+ lineEnd: fn.lineEnd,
763
+ });
764
+ }
765
+ }
766
+ }
767
+ }
768
+ return results;
769
+ }
770
+
771
+ export function analyzeSemanticProfile(
772
+ ctx: SemanticContext,
773
+ filePath: string,
774
+ fileEntry: FileEntry,
775
+ includeTests = true
776
+ ): SemanticProfile {
777
+ const profile: SemanticProfile = {
778
+ file: fileEntry.file,
779
+ referenceCountByExport: new Map(),
780
+ unusedParams: [],
781
+ interfaceImpls: [],
782
+ typeHierarchyDepth: 0,
783
+ typeHierarchies: [],
784
+ overrideChains: [],
785
+ abstractnessRatio: 0,
786
+ unusedImports: [],
787
+ concreteImports: [],
788
+ leakyReturns: [],
789
+ narrowableParams: [],
790
+ };
791
+
792
+ const sourceFile = ctx.program.getSourceFile(filePath);
793
+ if (!sourceFile) return profile;
794
+
795
+ profile.referenceCountByExport = collectExportReferences(
796
+ ctx, filePath, fileEntry, includeTests
797
+ );
798
+ profile.unusedParams = collectUnusedParams(ctx, filePath, sourceFile, fileEntry);
799
+ profile.abstractnessRatio = analyzeTypeHierarchy(ctx, sourceFile, fileEntry, profile);
800
+
801
+ const importResults = analyzeImports(ctx, filePath, sourceFile, fileEntry);
802
+ profile.unusedImports = importResults.unusedImports;
803
+ profile.concreteImports = importResults.concreteImports;
804
+
805
+ profile.leakyReturns = detectLeakyReturns(ctx, filePath, sourceFile, fileEntry);
806
+ profile.narrowableParams = detectNarrowableParams(ctx, filePath, sourceFile, fileEntry);
807
+
808
+ return profile;
809
+ }
810
+
811
+ export function collectAllAbsoluteFiles(
812
+ fileSummaries: FileEntry[],
813
+ dependencyState: DependencyState,
814
+ root: string
815
+ ): string[] {
816
+ const files = new Set<string>();
817
+ for (const entry of fileSummaries) {
818
+ files.add(path.resolve(root, entry.file));
819
+ }
820
+ for (const relFile of dependencyState.files) {
821
+ files.add(path.resolve(root, relFile));
822
+ }
823
+ return [...files].filter(f => {
824
+ try {
825
+ return fs.statSync(f).isFile();
826
+ } catch {
827
+ return false;
828
+ }
829
+ });
830
+ }