opencode-telos 1.0.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 (568) hide show
  1. package/README.md +927 -0
  2. package/dist/code-intelligence/analyzer.d.ts +9 -0
  3. package/dist/code-intelligence/analyzer.d.ts.map +1 -0
  4. package/dist/code-intelligence/analyzer.js +321 -0
  5. package/dist/code-intelligence/analyzer.js.map +1 -0
  6. package/dist/code-intelligence/ast/cache.d.ts +16 -0
  7. package/dist/code-intelligence/ast/cache.d.ts.map +1 -0
  8. package/dist/code-intelligence/ast/cache.js +44 -0
  9. package/dist/code-intelligence/ast/cache.js.map +1 -0
  10. package/dist/code-intelligence/ast/common.d.ts +8 -0
  11. package/dist/code-intelligence/ast/common.d.ts.map +1 -0
  12. package/dist/code-intelligence/ast/common.js +42 -0
  13. package/dist/code-intelligence/ast/common.js.map +1 -0
  14. package/dist/code-intelligence/ast/component.d.ts +10 -0
  15. package/dist/code-intelligence/ast/component.d.ts.map +1 -0
  16. package/dist/code-intelligence/ast/component.js +38 -0
  17. package/dist/code-intelligence/ast/component.js.map +1 -0
  18. package/dist/code-intelligence/ast/fallback.d.ts +9 -0
  19. package/dist/code-intelligence/ast/fallback.d.ts.map +1 -0
  20. package/dist/code-intelligence/ast/fallback.js +38 -0
  21. package/dist/code-intelligence/ast/fallback.js.map +1 -0
  22. package/dist/code-intelligence/ast/index.d.ts +5 -0
  23. package/dist/code-intelligence/ast/index.d.ts.map +1 -0
  24. package/dist/code-intelligence/ast/index.js +5 -0
  25. package/dist/code-intelligence/ast/index.js.map +1 -0
  26. package/dist/code-intelligence/ast/ir.d.ts +72 -0
  27. package/dist/code-intelligence/ast/ir.d.ts.map +1 -0
  28. package/dist/code-intelligence/ast/ir.js +2 -0
  29. package/dist/code-intelligence/ast/ir.js.map +1 -0
  30. package/dist/code-intelligence/ast/metrics.d.ts +25 -0
  31. package/dist/code-intelligence/ast/metrics.d.ts.map +1 -0
  32. package/dist/code-intelligence/ast/metrics.js +38 -0
  33. package/dist/code-intelligence/ast/metrics.js.map +1 -0
  34. package/dist/code-intelligence/ast/registry.d.ts +5 -0
  35. package/dist/code-intelligence/ast/registry.d.ts.map +1 -0
  36. package/dist/code-intelligence/ast/registry.js +22 -0
  37. package/dist/code-intelligence/ast/registry.js.map +1 -0
  38. package/dist/code-intelligence/ast/tree-sitter.d.ts +8 -0
  39. package/dist/code-intelligence/ast/tree-sitter.d.ts.map +1 -0
  40. package/dist/code-intelligence/ast/tree-sitter.js +247 -0
  41. package/dist/code-intelligence/ast/tree-sitter.js.map +1 -0
  42. package/dist/code-intelligence/ast/typescript.d.ts +8 -0
  43. package/dist/code-intelligence/ast/typescript.d.ts.map +1 -0
  44. package/dist/code-intelligence/ast/typescript.js +147 -0
  45. package/dist/code-intelligence/ast/typescript.js.map +1 -0
  46. package/dist/index.d.ts +10 -0
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +18 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/mcp/server.d.ts +27 -0
  51. package/dist/mcp/server.d.ts.map +1 -0
  52. package/dist/mcp/server.js +67 -0
  53. package/dist/mcp/server.js.map +1 -0
  54. package/dist/opencode/hooks.d.ts +9 -0
  55. package/dist/opencode/hooks.d.ts.map +1 -0
  56. package/dist/opencode/hooks.js +583 -0
  57. package/dist/opencode/hooks.js.map +1 -0
  58. package/dist/opencode/router/categories.d.ts +31 -0
  59. package/dist/opencode/router/categories.d.ts.map +1 -0
  60. package/dist/opencode/router/categories.js +165 -0
  61. package/dist/opencode/router/categories.js.map +1 -0
  62. package/dist/opencode/router/embeddings.d.ts +41 -0
  63. package/dist/opencode/router/embeddings.d.ts.map +1 -0
  64. package/dist/opencode/router/embeddings.js +136 -0
  65. package/dist/opencode/router/embeddings.js.map +1 -0
  66. package/dist/opencode/router/graph-state-snapshot.d.ts +35 -0
  67. package/dist/opencode/router/graph-state-snapshot.d.ts.map +1 -0
  68. package/dist/opencode/router/graph-state-snapshot.js +129 -0
  69. package/dist/opencode/router/graph-state-snapshot.js.map +1 -0
  70. package/dist/opencode/router/index.d.ts +21 -0
  71. package/dist/opencode/router/index.d.ts.map +1 -0
  72. package/dist/opencode/router/index.js +23 -0
  73. package/dist/opencode/router/index.js.map +1 -0
  74. package/dist/opencode/router/intent-classifier.d.ts +35 -0
  75. package/dist/opencode/router/intent-classifier.d.ts.map +1 -0
  76. package/dist/opencode/router/intent-classifier.js +108 -0
  77. package/dist/opencode/router/intent-classifier.js.map +1 -0
  78. package/dist/opencode/router/semantic-nudge.d.ts +42 -0
  79. package/dist/opencode/router/semantic-nudge.d.ts.map +1 -0
  80. package/dist/opencode/router/semantic-nudge.js +73 -0
  81. package/dist/opencode/router/semantic-nudge.js.map +1 -0
  82. package/dist/opencode/router/state-gate.d.ts +25 -0
  83. package/dist/opencode/router/state-gate.d.ts.map +1 -0
  84. package/dist/opencode/router/state-gate.js +178 -0
  85. package/dist/opencode/router/state-gate.js.map +1 -0
  86. package/dist/opencode/router/tool-embeddings.d.ts +36 -0
  87. package/dist/opencode/router/tool-embeddings.d.ts.map +1 -0
  88. package/dist/opencode/router/tool-embeddings.js +140 -0
  89. package/dist/opencode/router/tool-embeddings.js.map +1 -0
  90. package/dist/opencode/router/tool-registry.d.ts +45 -0
  91. package/dist/opencode/router/tool-registry.d.ts.map +1 -0
  92. package/dist/opencode/router/tool-registry.js +103 -0
  93. package/dist/opencode/router/tool-registry.js.map +1 -0
  94. package/dist/opencode/router/tool-taxonomy.d.ts +51 -0
  95. package/dist/opencode/router/tool-taxonomy.d.ts.map +1 -0
  96. package/dist/opencode/router/tool-taxonomy.js +250 -0
  97. package/dist/opencode/router/tool-taxonomy.js.map +1 -0
  98. package/dist/opencode/router/tools-composite.d.ts +21 -0
  99. package/dist/opencode/router/tools-composite.d.ts.map +1 -0
  100. package/dist/opencode/router/tools-composite.js +684 -0
  101. package/dist/opencode/router/tools-composite.js.map +1 -0
  102. package/dist/opencode/shell-hooks.d.ts +7 -0
  103. package/dist/opencode/shell-hooks.d.ts.map +1 -0
  104. package/dist/opencode/shell-hooks.js +96 -0
  105. package/dist/opencode/shell-hooks.js.map +1 -0
  106. package/dist/opencode/system-prompt.d.ts +10 -0
  107. package/dist/opencode/system-prompt.d.ts.map +1 -0
  108. package/dist/opencode/system-prompt.js +600 -0
  109. package/dist/opencode/system-prompt.js.map +1 -0
  110. package/dist/opencode/tools.d.ts +8 -0
  111. package/dist/opencode/tools.d.ts.map +1 -0
  112. package/dist/opencode/tools.js +3731 -0
  113. package/dist/opencode/tools.js.map +1 -0
  114. package/dist/opencode/workflows/chains.d.ts +52 -0
  115. package/dist/opencode/workflows/chains.d.ts.map +1 -0
  116. package/dist/opencode/workflows/chains.js +170 -0
  117. package/dist/opencode/workflows/chains.js.map +1 -0
  118. package/dist/opencode/workflows/executor.d.ts +52 -0
  119. package/dist/opencode/workflows/executor.d.ts.map +1 -0
  120. package/dist/opencode/workflows/executor.js +130 -0
  121. package/dist/opencode/workflows/executor.js.map +1 -0
  122. package/dist/opencode/workflows/index.d.ts +14 -0
  123. package/dist/opencode/workflows/index.d.ts.map +1 -0
  124. package/dist/opencode/workflows/index.js +15 -0
  125. package/dist/opencode/workflows/index.js.map +1 -0
  126. package/dist/opencode/workflows/tools-workflow.d.ts +24 -0
  127. package/dist/opencode/workflows/tools-workflow.d.ts.map +1 -0
  128. package/dist/opencode/workflows/tools-workflow.js +85 -0
  129. package/dist/opencode/workflows/tools-workflow.js.map +1 -0
  130. package/dist/opencode/workflows/types.d.ts +32 -0
  131. package/dist/opencode/workflows/types.d.ts.map +1 -0
  132. package/dist/opencode/workflows/types.js +13 -0
  133. package/dist/opencode/workflows/types.js.map +1 -0
  134. package/dist/sdd/analysis/compliance.d.ts +30 -0
  135. package/dist/sdd/analysis/compliance.d.ts.map +1 -0
  136. package/dist/sdd/analysis/compliance.js +251 -0
  137. package/dist/sdd/analysis/compliance.js.map +1 -0
  138. package/dist/sdd/analysis/scalability.d.ts +15 -0
  139. package/dist/sdd/analysis/scalability.d.ts.map +1 -0
  140. package/dist/sdd/analysis/scalability.js +72 -0
  141. package/dist/sdd/analysis/scalability.js.map +1 -0
  142. package/dist/sdd/analysis/security.d.ts +25 -0
  143. package/dist/sdd/analysis/security.d.ts.map +1 -0
  144. package/dist/sdd/analysis/security.js +94 -0
  145. package/dist/sdd/analysis/security.js.map +1 -0
  146. package/dist/sdd/brownfield/scanner.d.ts +31 -0
  147. package/dist/sdd/brownfield/scanner.d.ts.map +1 -0
  148. package/dist/sdd/brownfield/scanner.js +228 -0
  149. package/dist/sdd/brownfield/scanner.js.map +1 -0
  150. package/dist/sdd/cache/manager.d.ts +237 -0
  151. package/dist/sdd/cache/manager.d.ts.map +1 -0
  152. package/dist/sdd/cache/manager.js +770 -0
  153. package/dist/sdd/cache/manager.js.map +1 -0
  154. package/dist/sdd/cache/snapshot-store.d.ts +39 -0
  155. package/dist/sdd/cache/snapshot-store.d.ts.map +1 -0
  156. package/dist/sdd/cache/snapshot-store.js +156 -0
  157. package/dist/sdd/cache/snapshot-store.js.map +1 -0
  158. package/dist/sdd/changes/manager.d.ts +58 -0
  159. package/dist/sdd/changes/manager.d.ts.map +1 -0
  160. package/dist/sdd/changes/manager.js +235 -0
  161. package/dist/sdd/changes/manager.js.map +1 -0
  162. package/dist/sdd/cicd/generators.d.ts +16 -0
  163. package/dist/sdd/cicd/generators.d.ts.map +1 -0
  164. package/dist/sdd/cicd/generators.js +1042 -0
  165. package/dist/sdd/cicd/generators.js.map +1 -0
  166. package/dist/sdd/code-quality/complexity.d.ts +38 -0
  167. package/dist/sdd/code-quality/complexity.d.ts.map +1 -0
  168. package/dist/sdd/code-quality/complexity.js +161 -0
  169. package/dist/sdd/code-quality/complexity.js.map +1 -0
  170. package/dist/sdd/code-quality/conventions.d.ts +33 -0
  171. package/dist/sdd/code-quality/conventions.d.ts.map +1 -0
  172. package/dist/sdd/code-quality/conventions.js +193 -0
  173. package/dist/sdd/code-quality/conventions.js.map +1 -0
  174. package/dist/sdd/code-quality/dependencies.d.ts +27 -0
  175. package/dist/sdd/code-quality/dependencies.d.ts.map +1 -0
  176. package/dist/sdd/code-quality/dependencies.js +142 -0
  177. package/dist/sdd/code-quality/dependencies.js.map +1 -0
  178. package/dist/sdd/code-quality/import-analyzer.d.ts +49 -0
  179. package/dist/sdd/code-quality/import-analyzer.d.ts.map +1 -0
  180. package/dist/sdd/code-quality/import-analyzer.js +213 -0
  181. package/dist/sdd/code-quality/import-analyzer.js.map +1 -0
  182. package/dist/sdd/code-quality/metrics.d.ts +35 -0
  183. package/dist/sdd/code-quality/metrics.d.ts.map +1 -0
  184. package/dist/sdd/code-quality/metrics.js +172 -0
  185. package/dist/sdd/code-quality/metrics.js.map +1 -0
  186. package/dist/sdd/code-quality/smells.d.ts +38 -0
  187. package/dist/sdd/code-quality/smells.d.ts.map +1 -0
  188. package/dist/sdd/code-quality/smells.js +319 -0
  189. package/dist/sdd/code-quality/smells.js.map +1 -0
  190. package/dist/sdd/code-quality/symbol-parser.d.ts +28 -0
  191. package/dist/sdd/code-quality/symbol-parser.d.ts.map +1 -0
  192. package/dist/sdd/code-quality/symbol-parser.js +230 -0
  193. package/dist/sdd/code-quality/symbol-parser.js.map +1 -0
  194. package/dist/sdd/code-quality/usage-tracker.d.ts +59 -0
  195. package/dist/sdd/code-quality/usage-tracker.d.ts.map +1 -0
  196. package/dist/sdd/code-quality/usage-tracker.js +402 -0
  197. package/dist/sdd/code-quality/usage-tracker.js.map +1 -0
  198. package/dist/sdd/code-quality/utils.d.ts +6 -0
  199. package/dist/sdd/code-quality/utils.d.ts.map +1 -0
  200. package/dist/sdd/code-quality/utils.js +14 -0
  201. package/dist/sdd/code-quality/utils.js.map +1 -0
  202. package/dist/sdd/codegen/generator.d.ts +42 -0
  203. package/dist/sdd/codegen/generator.d.ts.map +1 -0
  204. package/dist/sdd/codegen/generator.js +1023 -0
  205. package/dist/sdd/codegen/generator.js.map +1 -0
  206. package/dist/sdd/constitution/validator.d.ts +37 -0
  207. package/dist/sdd/constitution/validator.d.ts.map +1 -0
  208. package/dist/sdd/constitution/validator.js +192 -0
  209. package/dist/sdd/constitution/validator.js.map +1 -0
  210. package/dist/sdd/cost/estimator.d.ts +31 -0
  211. package/dist/sdd/cost/estimator.d.ts.map +1 -0
  212. package/dist/sdd/cost/estimator.js +92 -0
  213. package/dist/sdd/cost/estimator.js.map +1 -0
  214. package/dist/sdd/coverage/tracker.d.ts +47 -0
  215. package/dist/sdd/coverage/tracker.d.ts.map +1 -0
  216. package/dist/sdd/coverage/tracker.js +251 -0
  217. package/dist/sdd/coverage/tracker.js.map +1 -0
  218. package/dist/sdd/disaster/recovery.d.ts +11 -0
  219. package/dist/sdd/disaster/recovery.d.ts.map +1 -0
  220. package/dist/sdd/disaster/recovery.js +55 -0
  221. package/dist/sdd/disaster/recovery.js.map +1 -0
  222. package/dist/sdd/discovery/adaptive.d.ts +14 -0
  223. package/dist/sdd/discovery/adaptive.d.ts.map +1 -0
  224. package/dist/sdd/discovery/adaptive.js +145 -0
  225. package/dist/sdd/discovery/adaptive.js.map +1 -0
  226. package/dist/sdd/discovery/briefing-analyzer.d.ts +66 -0
  227. package/dist/sdd/discovery/briefing-analyzer.d.ts.map +1 -0
  228. package/dist/sdd/discovery/briefing-analyzer.js +672 -0
  229. package/dist/sdd/discovery/briefing-analyzer.js.map +1 -0
  230. package/dist/sdd/discovery/briefing.d.ts +109 -0
  231. package/dist/sdd/discovery/briefing.d.ts.map +1 -0
  232. package/dist/sdd/discovery/briefing.js +617 -0
  233. package/dist/sdd/discovery/briefing.js.map +1 -0
  234. package/dist/sdd/discovery/graph-builder.d.ts +10 -0
  235. package/dist/sdd/discovery/graph-builder.d.ts.map +1 -0
  236. package/dist/sdd/discovery/graph-builder.js +510 -0
  237. package/dist/sdd/discovery/graph-builder.js.map +1 -0
  238. package/dist/sdd/documentation/generator.d.ts +7 -0
  239. package/dist/sdd/documentation/generator.d.ts.map +1 -0
  240. package/dist/sdd/documentation/generator.js +119 -0
  241. package/dist/sdd/documentation/generator.js.map +1 -0
  242. package/dist/sdd/domain/types.d.ts +460 -0
  243. package/dist/sdd/domain/types.d.ts.map +1 -0
  244. package/dist/sdd/domain/types.js +25 -0
  245. package/dist/sdd/domain/types.js.map +1 -0
  246. package/dist/sdd/drift/detector.d.ts +28 -0
  247. package/dist/sdd/drift/detector.d.ts.map +1 -0
  248. package/dist/sdd/drift/detector.js +379 -0
  249. package/dist/sdd/drift/detector.js.map +1 -0
  250. package/dist/sdd/drift/exclusion.d.ts +54 -0
  251. package/dist/sdd/drift/exclusion.d.ts.map +1 -0
  252. package/dist/sdd/drift/exclusion.js +179 -0
  253. package/dist/sdd/drift/exclusion.js.map +1 -0
  254. package/dist/sdd/drift/signals.d.ts +52 -0
  255. package/dist/sdd/drift/signals.d.ts.map +1 -0
  256. package/dist/sdd/drift/signals.js +470 -0
  257. package/dist/sdd/drift/signals.js.map +1 -0
  258. package/dist/sdd/enforcement/interceptor.d.ts +47 -0
  259. package/dist/sdd/enforcement/interceptor.d.ts.map +1 -0
  260. package/dist/sdd/enforcement/interceptor.js +365 -0
  261. package/dist/sdd/enforcement/interceptor.js.map +1 -0
  262. package/dist/sdd/enforcement/workflow-tracker.d.ts +66 -0
  263. package/dist/sdd/enforcement/workflow-tracker.d.ts.map +1 -0
  264. package/dist/sdd/enforcement/workflow-tracker.js +229 -0
  265. package/dist/sdd/enforcement/workflow-tracker.js.map +1 -0
  266. package/dist/sdd/graph/engine.d.ts +44 -0
  267. package/dist/sdd/graph/engine.d.ts.map +1 -0
  268. package/dist/sdd/graph/engine.js +203 -0
  269. package/dist/sdd/graph/engine.js.map +1 -0
  270. package/dist/sdd/graph/index.d.ts +160 -0
  271. package/dist/sdd/graph/index.d.ts.map +1 -0
  272. package/dist/sdd/graph/index.js +624 -0
  273. package/dist/sdd/graph/index.js.map +1 -0
  274. package/dist/sdd/graph/integrity-guard.d.ts +129 -0
  275. package/dist/sdd/graph/integrity-guard.d.ts.map +1 -0
  276. package/dist/sdd/graph/integrity-guard.js +263 -0
  277. package/dist/sdd/graph/integrity-guard.js.map +1 -0
  278. package/dist/sdd/graph/integrity.d.ts +79 -0
  279. package/dist/sdd/graph/integrity.d.ts.map +1 -0
  280. package/dist/sdd/graph/integrity.js +462 -0
  281. package/dist/sdd/graph/integrity.js.map +1 -0
  282. package/dist/sdd/graph/pruner.d.ts +27 -0
  283. package/dist/sdd/graph/pruner.d.ts.map +1 -0
  284. package/dist/sdd/graph/pruner.js +203 -0
  285. package/dist/sdd/graph/pruner.js.map +1 -0
  286. package/dist/sdd/graph/traverse.d.ts +43 -0
  287. package/dist/sdd/graph/traverse.d.ts.map +1 -0
  288. package/dist/sdd/graph/traverse.js +265 -0
  289. package/dist/sdd/graph/traverse.js.map +1 -0
  290. package/dist/sdd/incidents/manager.d.ts +10 -0
  291. package/dist/sdd/incidents/manager.d.ts.map +1 -0
  292. package/dist/sdd/incidents/manager.js +63 -0
  293. package/dist/sdd/incidents/manager.js.map +1 -0
  294. package/dist/sdd/knowledge/transfer.d.ts +24 -0
  295. package/dist/sdd/knowledge/transfer.d.ts.map +1 -0
  296. package/dist/sdd/knowledge/transfer.js +94 -0
  297. package/dist/sdd/knowledge/transfer.js.map +1 -0
  298. package/dist/sdd/migrations/fixes.d.ts +2 -0
  299. package/dist/sdd/migrations/fixes.d.ts.map +1 -0
  300. package/dist/sdd/migrations/fixes.js +159 -0
  301. package/dist/sdd/migrations/fixes.js.map +1 -0
  302. package/dist/sdd/migrations/index.d.ts +2 -0
  303. package/dist/sdd/migrations/index.d.ts.map +1 -0
  304. package/dist/sdd/migrations/index.js +5 -0
  305. package/dist/sdd/migrations/index.js.map +1 -0
  306. package/dist/sdd/migrations/migration-runner.d.ts +41 -0
  307. package/dist/sdd/migrations/migration-runner.d.ts.map +1 -0
  308. package/dist/sdd/migrations/migration-runner.js +91 -0
  309. package/dist/sdd/migrations/migration-runner.js.map +1 -0
  310. package/dist/sdd/monitoring/setup.d.ts +40 -0
  311. package/dist/sdd/monitoring/setup.d.ts.map +1 -0
  312. package/dist/sdd/monitoring/setup.js +177 -0
  313. package/dist/sdd/monitoring/setup.js.map +1 -0
  314. package/dist/sdd/monitoring/telemetry.d.ts +18 -0
  315. package/dist/sdd/monitoring/telemetry.d.ts.map +1 -0
  316. package/dist/sdd/monitoring/telemetry.js +37 -0
  317. package/dist/sdd/monitoring/telemetry.js.map +1 -0
  318. package/dist/sdd/patterns/anti-patterns.d.ts +21 -0
  319. package/dist/sdd/patterns/anti-patterns.d.ts.map +1 -0
  320. package/dist/sdd/patterns/anti-patterns.js +286 -0
  321. package/dist/sdd/patterns/anti-patterns.js.map +1 -0
  322. package/dist/sdd/patterns/ast-clones.d.ts +23 -0
  323. package/dist/sdd/patterns/ast-clones.d.ts.map +1 -0
  324. package/dist/sdd/patterns/ast-clones.js +171 -0
  325. package/dist/sdd/patterns/ast-clones.js.map +1 -0
  326. package/dist/sdd/patterns/config-drift.d.ts +16 -0
  327. package/dist/sdd/patterns/config-drift.d.ts.map +1 -0
  328. package/dist/sdd/patterns/config-drift.js +322 -0
  329. package/dist/sdd/patterns/config-drift.js.map +1 -0
  330. package/dist/sdd/patterns/contradictions.d.ts +38 -0
  331. package/dist/sdd/patterns/contradictions.d.ts.map +1 -0
  332. package/dist/sdd/patterns/contradictions.js +237 -0
  333. package/dist/sdd/patterns/contradictions.js.map +1 -0
  334. package/dist/sdd/patterns/learner.d.ts +49 -0
  335. package/dist/sdd/patterns/learner.d.ts.map +1 -0
  336. package/dist/sdd/patterns/learner.js +226 -0
  337. package/dist/sdd/patterns/learner.js.map +1 -0
  338. package/dist/sdd/permissions/access.d.ts +69 -0
  339. package/dist/sdd/permissions/access.d.ts.map +1 -0
  340. package/dist/sdd/permissions/access.js +333 -0
  341. package/dist/sdd/permissions/access.js.map +1 -0
  342. package/dist/sdd/persistence/repository.d.ts +60 -0
  343. package/dist/sdd/persistence/repository.d.ts.map +1 -0
  344. package/dist/sdd/persistence/repository.js +96 -0
  345. package/dist/sdd/persistence/repository.js.map +1 -0
  346. package/dist/sdd/persistence/sqlite.d.ts +122 -0
  347. package/dist/sdd/persistence/sqlite.d.ts.map +1 -0
  348. package/dist/sdd/persistence/sqlite.js +602 -0
  349. package/dist/sdd/persistence/sqlite.js.map +1 -0
  350. package/dist/sdd/persistence/yaml.d.ts +41 -0
  351. package/dist/sdd/persistence/yaml.d.ts.map +1 -0
  352. package/dist/sdd/persistence/yaml.js +382 -0
  353. package/dist/sdd/persistence/yaml.js.map +1 -0
  354. package/dist/sdd/promises/classifier.d.ts +48 -0
  355. package/dist/sdd/promises/classifier.d.ts.map +1 -0
  356. package/dist/sdd/promises/classifier.js +215 -0
  357. package/dist/sdd/promises/classifier.js.map +1 -0
  358. package/dist/sdd/promises/tracker.d.ts +20 -0
  359. package/dist/sdd/promises/tracker.d.ts.map +1 -0
  360. package/dist/sdd/promises/tracker.js +204 -0
  361. package/dist/sdd/promises/tracker.js.map +1 -0
  362. package/dist/sdd/quality/scorer.d.ts +44 -0
  363. package/dist/sdd/quality/scorer.d.ts.map +1 -0
  364. package/dist/sdd/quality/scorer.js +216 -0
  365. package/dist/sdd/quality/scorer.js.map +1 -0
  366. package/dist/sdd/rollback/manager.d.ts +45 -0
  367. package/dist/sdd/rollback/manager.d.ts.map +1 -0
  368. package/dist/sdd/rollback/manager.js +266 -0
  369. package/dist/sdd/rollback/manager.js.map +1 -0
  370. package/dist/sdd/session/handoff.d.ts +52 -0
  371. package/dist/sdd/session/handoff.d.ts.map +1 -0
  372. package/dist/sdd/session/handoff.js +264 -0
  373. package/dist/sdd/session/handoff.js.map +1 -0
  374. package/dist/sdd/sla/tracker.d.ts +11 -0
  375. package/dist/sdd/sla/tracker.d.ts.map +1 -0
  376. package/dist/sdd/sla/tracker.js +52 -0
  377. package/dist/sdd/sla/tracker.js.map +1 -0
  378. package/dist/sdd/sync/git-sync.d.ts +61 -0
  379. package/dist/sdd/sync/git-sync.d.ts.map +1 -0
  380. package/dist/sdd/sync/git-sync.js +297 -0
  381. package/dist/sdd/sync/git-sync.js.map +1 -0
  382. package/dist/sdd/toggle/state.d.ts +8 -0
  383. package/dist/sdd/toggle/state.d.ts.map +1 -0
  384. package/dist/sdd/toggle/state.js +32 -0
  385. package/dist/sdd/toggle/state.js.map +1 -0
  386. package/dist/sdd/transactions/manager.d.ts +12 -0
  387. package/dist/sdd/transactions/manager.d.ts.map +1 -0
  388. package/dist/sdd/transactions/manager.js +80 -0
  389. package/dist/sdd/transactions/manager.js.map +1 -0
  390. package/dist/sdd/validation/coverage-index.d.ts +117 -0
  391. package/dist/sdd/validation/coverage-index.d.ts.map +1 -0
  392. package/dist/sdd/validation/coverage-index.js +251 -0
  393. package/dist/sdd/validation/coverage-index.js.map +1 -0
  394. package/dist/sdd/validation/executable.d.ts +26 -0
  395. package/dist/sdd/validation/executable.d.ts.map +1 -0
  396. package/dist/sdd/validation/executable.js +122 -0
  397. package/dist/sdd/validation/executable.js.map +1 -0
  398. package/dist/sdd/validation/smart-validator.d.ts +53 -0
  399. package/dist/sdd/validation/smart-validator.d.ts.map +1 -0
  400. package/dist/sdd/validation/smart-validator.js +347 -0
  401. package/dist/sdd/validation/smart-validator.js.map +1 -0
  402. package/dist/sdd/validation/validator.d.ts +39 -0
  403. package/dist/sdd/validation/validator.d.ts.map +1 -0
  404. package/dist/sdd/validation/validator.js +512 -0
  405. package/dist/sdd/validation/validator.js.map +1 -0
  406. package/dist/sdd/workflow/exporter.d.ts +36 -0
  407. package/dist/sdd/workflow/exporter.d.ts.map +1 -0
  408. package/dist/sdd/workflow/exporter.js +112 -0
  409. package/dist/sdd/workflow/exporter.js.map +1 -0
  410. package/dist/sdd/workflows/ab-testing.d.ts +18 -0
  411. package/dist/sdd/workflows/ab-testing.d.ts.map +1 -0
  412. package/dist/sdd/workflows/ab-testing.js +67 -0
  413. package/dist/sdd/workflows/ab-testing.js.map +1 -0
  414. package/dist/sdd/workflows/bug-fix.d.ts +13 -0
  415. package/dist/sdd/workflows/bug-fix.d.ts.map +1 -0
  416. package/dist/sdd/workflows/bug-fix.js +65 -0
  417. package/dist/sdd/workflows/bug-fix.js.map +1 -0
  418. package/dist/sdd/workflows/data-migration.d.ts +14 -0
  419. package/dist/sdd/workflows/data-migration.d.ts.map +1 -0
  420. package/dist/sdd/workflows/data-migration.js +68 -0
  421. package/dist/sdd/workflows/data-migration.js.map +1 -0
  422. package/dist/sdd/workflows/deprecation.d.ts +15 -0
  423. package/dist/sdd/workflows/deprecation.d.ts.map +1 -0
  424. package/dist/sdd/workflows/deprecation.js +68 -0
  425. package/dist/sdd/workflows/deprecation.js.map +1 -0
  426. package/dist/sdd/workflows/feature-flags.d.ts +14 -0
  427. package/dist/sdd/workflows/feature-flags.d.ts.map +1 -0
  428. package/dist/sdd/workflows/feature-flags.js +73 -0
  429. package/dist/sdd/workflows/feature-flags.js.map +1 -0
  430. package/dist/sdd/workflows/hotfix.d.ts +13 -0
  431. package/dist/sdd/workflows/hotfix.d.ts.map +1 -0
  432. package/dist/sdd/workflows/hotfix.js +67 -0
  433. package/dist/sdd/workflows/hotfix.js.map +1 -0
  434. package/dist/sdd/workflows/multi-tenancy.d.ts +13 -0
  435. package/dist/sdd/workflows/multi-tenancy.d.ts.map +1 -0
  436. package/dist/sdd/workflows/multi-tenancy.js +68 -0
  437. package/dist/sdd/workflows/multi-tenancy.js.map +1 -0
  438. package/dist/sdd/workflows/onboarding.d.ts +7 -0
  439. package/dist/sdd/workflows/onboarding.d.ts.map +1 -0
  440. package/dist/sdd/workflows/onboarding.js +43 -0
  441. package/dist/sdd/workflows/onboarding.js.map +1 -0
  442. package/dist/sdd/workflows/refactoring.d.ts +14 -0
  443. package/dist/sdd/workflows/refactoring.d.ts.map +1 -0
  444. package/dist/sdd/workflows/refactoring.js +73 -0
  445. package/dist/sdd/workflows/refactoring.js.map +1 -0
  446. package/dist/server/events.d.ts +64 -0
  447. package/dist/server/events.d.ts.map +1 -0
  448. package/dist/server/events.js +149 -0
  449. package/dist/server/events.js.map +1 -0
  450. package/dist/server/server.d.ts +33 -0
  451. package/dist/server/server.d.ts.map +1 -0
  452. package/dist/server/server.js +1019 -0
  453. package/dist/server/server.js.map +1 -0
  454. package/marketplace.json +39 -0
  455. package/package.json +65 -0
  456. package/src/code-intelligence/analyzer.ts +350 -0
  457. package/src/code-intelligence/ast/cache.ts +61 -0
  458. package/src/code-intelligence/ast/common.ts +62 -0
  459. package/src/code-intelligence/ast/component.ts +39 -0
  460. package/src/code-intelligence/ast/fallback.ts +44 -0
  461. package/src/code-intelligence/ast/index.ts +4 -0
  462. package/src/code-intelligence/ast/ir.ts +91 -0
  463. package/src/code-intelligence/ast/metrics.ts +65 -0
  464. package/src/code-intelligence/ast/registry.ts +28 -0
  465. package/src/code-intelligence/ast/tree-sitter.ts +226 -0
  466. package/src/code-intelligence/ast/typescript.ts +140 -0
  467. package/src/index.ts +22 -0
  468. package/src/mcp/server.ts +77 -0
  469. package/src/opencode/hooks.ts +728 -0
  470. package/src/opencode/router/categories.ts +192 -0
  471. package/src/opencode/router/embeddings.ts +149 -0
  472. package/src/opencode/router/graph-state-snapshot.ts +163 -0
  473. package/src/opencode/router/index.ts +44 -0
  474. package/src/opencode/router/intent-classifier.ts +140 -0
  475. package/src/opencode/router/semantic-nudge.ts +89 -0
  476. package/src/opencode/router/state-gate.ts +192 -0
  477. package/src/opencode/router/tool-embeddings.ts +162 -0
  478. package/src/opencode/router/tool-registry.ts +135 -0
  479. package/src/opencode/router/tool-taxonomy.ts +284 -0
  480. package/src/opencode/router/tools-composite.ts +685 -0
  481. package/src/opencode/shell-hooks.ts +115 -0
  482. package/src/opencode/system-prompt.ts +617 -0
  483. package/src/opencode/tools.ts +4102 -0
  484. package/src/opencode/workflows/chains.ts +205 -0
  485. package/src/opencode/workflows/executor.ts +172 -0
  486. package/src/opencode/workflows/index.ts +21 -0
  487. package/src/opencode/workflows/tools-workflow.ts +91 -0
  488. package/src/opencode/workflows/types.ts +42 -0
  489. package/src/sdd/analysis/compliance.ts +279 -0
  490. package/src/sdd/analysis/scalability.ts +97 -0
  491. package/src/sdd/analysis/security.ts +135 -0
  492. package/src/sdd/brownfield/scanner.ts +276 -0
  493. package/src/sdd/cache/manager.ts +899 -0
  494. package/src/sdd/cache/snapshot-store.ts +185 -0
  495. package/src/sdd/changes/manager.ts +326 -0
  496. package/src/sdd/cicd/generators.ts +1095 -0
  497. package/src/sdd/code-quality/complexity.ts +235 -0
  498. package/src/sdd/code-quality/conventions.ts +220 -0
  499. package/src/sdd/code-quality/dependencies.ts +203 -0
  500. package/src/sdd/code-quality/import-analyzer.ts +294 -0
  501. package/src/sdd/code-quality/metrics.ts +232 -0
  502. package/src/sdd/code-quality/smells.ts +415 -0
  503. package/src/sdd/code-quality/symbol-parser.ts +335 -0
  504. package/src/sdd/code-quality/usage-tracker.ts +527 -0
  505. package/src/sdd/code-quality/utils.ts +13 -0
  506. package/src/sdd/codegen/generator.ts +1181 -0
  507. package/src/sdd/constitution/validator.ts +253 -0
  508. package/src/sdd/cost/estimator.ts +147 -0
  509. package/src/sdd/coverage/tracker.ts +342 -0
  510. package/src/sdd/disaster/recovery.ts +79 -0
  511. package/src/sdd/discovery/adaptive.ts +167 -0
  512. package/src/sdd/discovery/briefing-analyzer.ts +802 -0
  513. package/src/sdd/discovery/briefing.ts +770 -0
  514. package/src/sdd/discovery/graph-builder.ts +598 -0
  515. package/src/sdd/documentation/generator.ts +158 -0
  516. package/src/sdd/domain/types.ts +658 -0
  517. package/src/sdd/drift/detector.ts +465 -0
  518. package/src/sdd/drift/exclusion.ts +223 -0
  519. package/src/sdd/drift/signals.ts +577 -0
  520. package/src/sdd/enforcement/interceptor.ts +444 -0
  521. package/src/sdd/enforcement/workflow-tracker.ts +263 -0
  522. package/src/sdd/graph/engine.ts +277 -0
  523. package/src/sdd/graph/index.ts +700 -0
  524. package/src/sdd/graph/integrity-guard.ts +348 -0
  525. package/src/sdd/graph/integrity.ts +628 -0
  526. package/src/sdd/graph/pruner.ts +221 -0
  527. package/src/sdd/graph/traverse.ts +331 -0
  528. package/src/sdd/incidents/manager.ts +87 -0
  529. package/src/sdd/knowledge/transfer.ts +140 -0
  530. package/src/sdd/migrations/fixes.ts +154 -0
  531. package/src/sdd/migrations/index.ts +14 -0
  532. package/src/sdd/migrations/migration-runner.ts +118 -0
  533. package/src/sdd/monitoring/setup.ts +237 -0
  534. package/src/sdd/monitoring/telemetry.ts +44 -0
  535. package/src/sdd/patterns/anti-patterns.ts +333 -0
  536. package/src/sdd/patterns/ast-clones.ts +214 -0
  537. package/src/sdd/patterns/config-drift.ts +346 -0
  538. package/src/sdd/patterns/contradictions.ts +323 -0
  539. package/src/sdd/patterns/learner.ts +266 -0
  540. package/src/sdd/permissions/access.ts +478 -0
  541. package/src/sdd/persistence/repository.ts +166 -0
  542. package/src/sdd/persistence/sqlite.ts +703 -0
  543. package/src/sdd/persistence/yaml.ts +409 -0
  544. package/src/sdd/promises/classifier.ts +253 -0
  545. package/src/sdd/promises/tracker.ts +258 -0
  546. package/src/sdd/quality/scorer.ts +263 -0
  547. package/src/sdd/rollback/manager.ts +361 -0
  548. package/src/sdd/session/handoff.ts +354 -0
  549. package/src/sdd/sla/tracker.ts +68 -0
  550. package/src/sdd/sync/git-sync.ts +401 -0
  551. package/src/sdd/toggle/state.ts +38 -0
  552. package/src/sdd/transactions/manager.ts +93 -0
  553. package/src/sdd/validation/coverage-index.ts +339 -0
  554. package/src/sdd/validation/executable.ts +127 -0
  555. package/src/sdd/validation/smart-validator.ts +470 -0
  556. package/src/sdd/validation/validator.ts +641 -0
  557. package/src/sdd/workflow/exporter.ts +169 -0
  558. package/src/sdd/workflows/ab-testing.ts +90 -0
  559. package/src/sdd/workflows/bug-fix.ts +81 -0
  560. package/src/sdd/workflows/data-migration.ts +86 -0
  561. package/src/sdd/workflows/deprecation.ts +87 -0
  562. package/src/sdd/workflows/feature-flags.ts +91 -0
  563. package/src/sdd/workflows/hotfix.ts +83 -0
  564. package/src/sdd/workflows/multi-tenancy.ts +84 -0
  565. package/src/sdd/workflows/onboarding.ts +82 -0
  566. package/src/sdd/workflows/refactoring.ts +90 -0
  567. package/src/server/events.ts +184 -0
  568. package/src/server/server.ts +1088 -0
@@ -0,0 +1,235 @@
1
+ import { fileMatchesFocus } from "./utils.js"
2
+
3
+ export interface FunctionComplexity {
4
+ name: string
5
+ file: string
6
+ line_start: number
7
+ line_end: number
8
+ cyclomatic: number
9
+ cognitive: number
10
+ lines: number
11
+ risk: 'low' | 'medium' | 'high' | 'very_high'
12
+ }
13
+
14
+ export interface ComplexityReport {
15
+ functions: FunctionComplexity[]
16
+ summary: {
17
+ total_functions: number
18
+ average_cyclomatic: number
19
+ average_cognitive: number
20
+ high_risk_count: number
21
+ very_high_risk_count: number
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Options for controlling complexity analysis scope.
27
+ */
28
+ export interface ComplexityAnalysisOptions {
29
+ /** Only analyze functions whose name matches these patterns. */
30
+ focusFunctions?: string[]
31
+ /** Skip functions whose name matches these patterns. */
32
+ excludeFunctions?: string[]
33
+ /** Minimum risk level to include in results. */
34
+ minRisk?: "low" | "medium" | "high" | "very_high"
35
+ /** Only analyze files matching these name patterns (supports * wildcard). */
36
+ focusFiles?: string[]
37
+ /** Maximum functions to report. */
38
+ maxResults?: number
39
+ }
40
+
41
+ function calculateCyclomaticComplexity(code: string): number {
42
+ let complexity = 1
43
+
44
+ const keywords = [
45
+ /\bif\b/g,
46
+ /\belse\s+if\b/g,
47
+ /\bwhile\b/g,
48
+ /\bfor\b/g,
49
+ /\bdo\b/g,
50
+ /\bswitch\b/g,
51
+ /\bcase\b/g,
52
+ /\bcatch\b/g,
53
+ /\b\?\:/g,
54
+ /\&\&/g,
55
+ /\|\|/g,
56
+ /\?\./g,
57
+ ]
58
+
59
+ for (const keyword of keywords) {
60
+ const matches = code.match(keyword)
61
+ if (matches) {
62
+ complexity += matches.length
63
+ }
64
+ }
65
+
66
+ return complexity
67
+ }
68
+
69
+ function calculateCognitiveComplexity(code: string): number {
70
+ let complexity = 0
71
+ let nestingLevel = 0
72
+
73
+ const lines = code.split('\n')
74
+
75
+ for (const line of lines) {
76
+ const trimmed = line.trim()
77
+
78
+ if (trimmed.match(/\b(if|else\s+if|else|while|for|do|switch|catch)\b/)) {
79
+ complexity += 1 + nestingLevel
80
+ nestingLevel++
81
+ }
82
+
83
+ if (trimmed.match(/\}/)) {
84
+ nestingLevel = Math.max(0, nestingLevel - 1)
85
+ }
86
+
87
+ if (trimmed.match(/\b(break|continue)\b/)) {
88
+ complexity += 1
89
+ }
90
+
91
+ if (trimmed.match(/\b(goto)\b/)) {
92
+ complexity += 2
93
+ }
94
+ }
95
+
96
+ return complexity
97
+ }
98
+
99
+ function assessRisk(cyclomatic: number, cognitive: number): FunctionComplexity['risk'] {
100
+ if (cyclomatic > 20 || cognitive > 30) return 'very_high'
101
+ if (cyclomatic > 10 || cognitive > 15) return 'high'
102
+ if (cyclomatic > 5 || cognitive > 8) return 'medium'
103
+ return 'low'
104
+ }
105
+
106
+ export function analyzeComplexity(
107
+ code: string,
108
+ fileName: string,
109
+ options?: ComplexityAnalysisOptions,
110
+ ): ComplexityReport {
111
+ // Early return if file doesn't match focusFiles
112
+ if (options?.focusFiles?.length && !fileMatchesFocus(fileName, options.focusFiles)) {
113
+ return { functions: [], summary: { total_functions: 0, average_cyclomatic: 0, average_cognitive: 0, high_risk_count: 0, very_high_risk_count: 0 } }
114
+ }
115
+
116
+ const functions: FunctionComplexity[] = []
117
+ const riskOrder: Record<string, number> = { low: 0, medium: 1, high: 2, very_high: 3 }
118
+ const minRiskLevel = options?.minRisk ? riskOrder[options.minRisk] ?? 0 : 0
119
+
120
+ const functionRegex = /(?:function\s+(\w+)|(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s*)?\(|(?:async\s+)?(\w+)\s*\([^)]*\)\s*(?::\s*\w+\s*)?\{)/g
121
+
122
+ let match
123
+ while ((match = functionRegex.exec(code)) !== null) {
124
+ const name = match[1] || match[2] || match[3]
125
+
126
+ // Apply focus/exclude filters
127
+ if (options?.focusFunctions?.length && !options.focusFunctions.some(p => name.includes(p))) continue
128
+ if (options?.excludeFunctions?.length && options.excludeFunctions.some(p => name.includes(p))) continue
129
+
130
+ const startLine = code.substring(0, match.index).split('\n').length
131
+
132
+ let braceCount = 0
133
+ let endLine = startLine
134
+ let inFunction = false
135
+
136
+ for (let i = match.index; i < code.length; i++) {
137
+ if (code[i] === '{') {
138
+ braceCount++
139
+ inFunction = true
140
+ } else if (code[i] === '}') {
141
+ braceCount--
142
+ if (inFunction && braceCount === 0) {
143
+ endLine = code.substring(0, i + 1).split('\n').length
144
+ break
145
+ }
146
+ }
147
+ }
148
+
149
+ const functionCode = code.substring(match.index, code.indexOf('}', code.indexOf('{', match.index)) + 1)
150
+ const lines = endLine - startLine + 1
151
+
152
+ const cyclomatic = calculateCyclomaticComplexity(functionCode)
153
+ const cognitive = calculateCognitiveComplexity(functionCode)
154
+ const risk = assessRisk(cyclomatic, cognitive)
155
+
156
+ // Apply risk filter
157
+ if (riskOrder[risk] < minRiskLevel) continue
158
+
159
+ functions.push({
160
+ name,
161
+ file: fileName,
162
+ line_start: startLine,
163
+ line_end: endLine,
164
+ cyclomatic,
165
+ cognitive,
166
+ lines,
167
+ risk,
168
+ })
169
+ }
170
+
171
+ // Apply max results limit
172
+ const limitedFunctions = options?.maxResults ? functions.slice(0, options.maxResults) : functions
173
+
174
+ const totalFunctions = limitedFunctions.length
175
+ const avgCyclomatic = totalFunctions > 0 ? limitedFunctions.reduce((sum, f) => sum + f.cyclomatic, 0) / totalFunctions : 0
176
+ const avgCognitive = totalFunctions > 0 ? limitedFunctions.reduce((sum, f) => sum + f.cognitive, 0) / totalFunctions : 0
177
+ const highRiskCount = limitedFunctions.filter(f => f.risk === 'high').length
178
+ const veryHighRiskCount = limitedFunctions.filter(f => f.risk === 'very_high').length
179
+
180
+ return {
181
+ functions: limitedFunctions,
182
+ summary: {
183
+ total_functions: totalFunctions,
184
+ average_cyclomatic: Math.round(avgCyclomatic * 100) / 100,
185
+ average_cognitive: Math.round(avgCognitive * 100) / 100,
186
+ high_risk_count: highRiskCount,
187
+ very_high_risk_count: veryHighRiskCount,
188
+ },
189
+ }
190
+ }
191
+
192
+ export function formatComplexityReport(report: ComplexityReport): string {
193
+ const lines = [
194
+ '## Relatório de Complexidade',
195
+ '',
196
+ `**Total de Funções:** ${report.summary.total_functions}`,
197
+ `**Complexidade Ciclomática Média:** ${report.summary.average_cyclomatic}`,
198
+ `**Complexidade Cognitiva Média:** ${report.summary.average_cognitive}`,
199
+ `**Alto Risco:** ${report.summary.high_risk_count}`,
200
+ `**Risco Muito Alto:** ${report.summary.very_high_risk_count}`,
201
+ '',
202
+ ]
203
+
204
+ const highRisk = report.functions.filter(f => f.risk === 'high' || f.risk === 'very_high')
205
+
206
+ if (highRisk.length > 0) {
207
+ lines.push('### Funções de Alto Risco')
208
+ for (const func of highRisk) {
209
+ lines.push(`#### ${func.name} (${func.risk})`)
210
+ lines.push(`- **Arquivo:** ${func.file}`)
211
+ lines.push(`- **Linhas:** ${func.line_start}-${func.line_end} (${func.lines} linhas)`)
212
+ lines.push(`- **Ciclomática:** ${func.cyclomatic}`)
213
+ lines.push(`- **Cognitiva:** ${func.cognitive}`)
214
+ lines.push('')
215
+ }
216
+ }
217
+
218
+ const mediumRisk = report.functions.filter(f => f.risk === 'medium')
219
+ if (mediumRisk.length > 0) {
220
+ lines.push('### Funções de Risco Médio')
221
+ for (const func of mediumRisk) {
222
+ lines.push(`- **${func.name}**: ciclomática=${func.cyclomatic}, cognitiva=${func.cognitive}`)
223
+ }
224
+ }
225
+
226
+ lines.push(
227
+ '',
228
+ '### Recomendações',
229
+ '- Funções com complexidade ciclomática > 10 devem ser refatoradas',
230
+ '- Funções com complexidade cognitiva > 15 são difíceis de entender',
231
+ '- Considere extrair lógica complexa em funções menores',
232
+ )
233
+
234
+ return lines.join('\n')
235
+ }
@@ -0,0 +1,220 @@
1
+ import { readFileSync, existsSync, readdirSync } from "fs"
2
+ import { join, extname, relative } from "path"
3
+
4
+ export interface ProjectConventions {
5
+ naming: {
6
+ variables: "camelCase" | "snake_case" | "PascalCase" | "unknown"
7
+ functions: "camelCase" | "snake_case" | "PascalCase" | "unknown"
8
+ files: "camelCase" | "snake_case" | "PascalCase" | "kebab-case" | "unknown"
9
+ constants: "camelCase" | "UPPER_SNAKE_CASE" | "unknown"
10
+ }
11
+ imports: {
12
+ style: "relative" | "absolute" | "mixed"
13
+ useBarrelFiles: boolean
14
+ extension: "always" | "never" | "ts-only" | "unknown"
15
+ }
16
+ async: {
17
+ style: "async-await" | "promises" | "callbacks" | "mixed"
18
+ errorHandling: "try-catch" | "Result" | "error-first-cb" | "mixed"
19
+ }
20
+ structure: {
21
+ organization: "domain" | "feature" | "layer" | "flat" | "unknown"
22
+ hasIndexFiles: boolean
23
+ testLocation: "co-located" | "separate" | "mixed"
24
+ }
25
+ metadata: Record<string, unknown>
26
+ }
27
+
28
+ const EXTENSIONS = [".ts", ".tsx", ".js", ".jsx"]
29
+ const EXCLUDE_DIRS = ["node_modules", ".sdd", "dist", "build", ".git", ".opencode", "__pycache__"]
30
+
31
+ /**
32
+ * Analyze a project directory to detect coding conventions.
33
+ * Samples up to 20 files for performance.
34
+ */
35
+ export function detectConventions(projectDir: string): ProjectConventions {
36
+ const files = sampleFiles(projectDir, 20)
37
+ if (files.length === 0) return defaultConventions()
38
+
39
+ const allContent = files.map(f => ({
40
+ path: f.relPath,
41
+ content: readFileSync(f.fullPath, "utf-8"),
42
+ }))
43
+
44
+ return {
45
+ naming: detectNamingConventions(allContent),
46
+ imports: detectImportConventions(allContent),
47
+ async: detectAsyncConventions(allContent),
48
+ structure: detectStructureConventions(projectDir, allContent),
49
+ metadata: { filesSampled: files.length },
50
+ }
51
+ }
52
+
53
+ function defaultConventions(): ProjectConventions {
54
+ return {
55
+ naming: { variables: "camelCase", functions: "camelCase", files: "kebab-case", constants: "UPPER_SNAKE_CASE" },
56
+ imports: { style: "relative", useBarrelFiles: false, extension: "ts-only" },
57
+ async: { style: "async-await", errorHandling: "try-catch" },
58
+ structure: { organization: "unknown", hasIndexFiles: false, testLocation: "separate" },
59
+ metadata: {},
60
+ }
61
+ }
62
+
63
+ interface SampledFile { fullPath: string; relPath: string }
64
+
65
+ function sampleFiles(projectDir: string, maxFiles: number): SampledFile[] {
66
+ const result: SampledFile[] = []
67
+ const srcDir = join(projectDir, "src")
68
+ const scanDir = existsSync(srcDir) ? srcDir : projectDir
69
+
70
+ function walk(dir: string): void {
71
+ if (result.length >= maxFiles) return
72
+ if (!existsSync(dir)) return
73
+ const entries = readdirSync(dir, { withFileTypes: true })
74
+ for (const entry of entries) {
75
+ if (result.length >= maxFiles) return
76
+ if (EXCLUDE_DIRS.includes(entry.name)) continue
77
+ const fullPath = join(dir, entry.name)
78
+ if (entry.isDirectory()) {
79
+ walk(fullPath)
80
+ } else if (EXTENSIONS.includes(extname(entry.name))) {
81
+ result.push({ fullPath, relPath: relative(projectDir, fullPath) })
82
+ }
83
+ }
84
+ }
85
+ walk(scanDir)
86
+ return result
87
+ }
88
+
89
+ function detectNamingConventions(files: Array<{ path: string; content: string }>): ProjectConventions["naming"] {
90
+ let camelCase = 0, snakeCase = 0, pascalCase = 0, upperSnake = 0
91
+
92
+ for (const file of files) {
93
+ const lines = file.content.split("\n")
94
+ for (const line of lines.slice(0, 100)) {
95
+ // Variable declarations
96
+ const varMatch = line.match(/(?:const|let|var)\s+(\w+)/)
97
+ if (varMatch) {
98
+ const name = varMatch[1]
99
+ if (/^[A-Z][a-zA-Z0-9]+$/.test(name)) pascalCase++
100
+ else if (/^[a-z][a-zA-Z0-9]+$/.test(name)) camelCase++
101
+ else if (/^[a-z][a-z0-9_]+$/.test(name)) snakeCase++
102
+ else if (/^[A-Z][A-Z0-9_]+$/.test(name)) upperSnake++
103
+ }
104
+ }
105
+
106
+ // File naming
107
+ const fileName = file.path.split("/").pop() || ""
108
+ if (/^[a-z][a-z0-9-]+\.[tj]sx?$/.test(fileName)) camelCase++
109
+ else if (/^[a-z][a-z0-9_]+\.[tj]sx?$/.test(fileName)) snakeCase++
110
+ }
111
+
112
+ const detectVar = (c: number, s: number, p: number): "camelCase" | "snake_case" | "PascalCase" | "unknown" => {
113
+ const total = c + s + p
114
+ if (total === 0) return "unknown"
115
+ if (c / total > 0.6) return "camelCase"
116
+ if (s / total > 0.6) return "snake_case"
117
+ if (p / total > 0.6) return "PascalCase"
118
+ return "unknown"
119
+ }
120
+
121
+ return {
122
+ variables: detectVar(camelCase, snakeCase, pascalCase),
123
+ functions: detectVar(camelCase, snakeCase, pascalCase),
124
+ files: camelCase > snakeCase ? "camelCase" : snakeCase > camelCase ? "snake_case" : "unknown",
125
+ constants: upperSnake > camelCase ? "UPPER_SNAKE_CASE" : "camelCase",
126
+ }
127
+ }
128
+
129
+ function detectImportConventions(files: Array<{ path: string; content: string }>): ProjectConventions["imports"] {
130
+ let relativeImports = 0, absoluteImports = 0, barrelImports = 0, extensionCount = 0, totalImports = 0
131
+
132
+ for (const file of files) {
133
+ const importMatches = file.content.matchAll(/(?:import|from)\s+['"]([^'"]+)['"]/g)
134
+ for (const match of importMatches) {
135
+ const imp = match[1]
136
+ totalImports++
137
+ if (imp.startsWith(".")) relativeImports++
138
+ else absoluteImports++
139
+ if (imp.endsWith("/index") || (!imp.includes("/") && !imp.startsWith("."))) barrelImports++
140
+ if (imp.endsWith(".js") || imp.endsWith(".ts")) extensionCount++
141
+ }
142
+ }
143
+
144
+ return {
145
+ style: relativeImports > absoluteImports * 2 ? "relative" : absoluteImports > relativeImports * 2 ? "absolute" : "mixed",
146
+ useBarrelFiles: barrelImports > totalImports * 0.3,
147
+ extension: totalImports === 0 ? "unknown" : extensionCount > totalImports * 0.5 ? "always" : extensionCount > 0 ? "ts-only" : "never",
148
+ }
149
+ }
150
+
151
+ function detectAsyncConventions(files: Array<{ path: string; content: string }>): ProjectConventions["async"] {
152
+ let asyncAwait = 0, promises = 0, callbacks = 0, tryCatch = 0, resultType = 0
153
+
154
+ for (const file of files) {
155
+ asyncAwait += (file.content.match(/await\s+/g) || []).length
156
+ promises += (file.content.match(/\.then\(/g) || []).length
157
+ callbacks += (file.content.match(/callback\s*\(/g) || []).length
158
+ tryCatch += (file.content.match(/try\s*\{/g) || []).length
159
+ resultType += (file.content.match(/Result<|ResultType|isOk|isErr/g) || []).length
160
+ }
161
+
162
+ return {
163
+ style: asyncAwait > promises * 2 ? "async-await" : promises > asyncAwait * 2 ? "promises" : callbacks > 5 ? "callbacks" : "mixed",
164
+ errorHandling: tryCatch > resultType * 2 ? "try-catch" : resultType > tryCatch * 2 ? "Result" : "mixed",
165
+ }
166
+ }
167
+
168
+ function detectStructureConventions(projectDir: string, files: Array<{ path: string; content: string }>): ProjectConventions["structure"] {
169
+ // Check for index files
170
+ let indexCount = 0
171
+ for (const file of files) {
172
+ if (file.path.split("/").pop()?.startsWith("index.")) indexCount++
173
+ }
174
+
175
+ // Check test location
176
+ const coLocated = files.filter(f => f.path.includes(".test.") || f.path.includes(".spec.")).length
177
+ const separateDir = files.filter(f => f.path.includes("/__tests__/") || f.path.includes("/test/")).length
178
+
179
+ // Detect organization pattern
180
+ const pathParts = files.map(f => f.path.split("/"))
181
+ const hasDomain = pathParts.some(p => p.length > 2 && ["domain", "models", "entities"].includes(p[1]))
182
+ const hasFeature = pathParts.some(p => p.length > 2 && ["features", "modules", "pages"].includes(p[1]))
183
+ const hasLayer = pathParts.some(p => p.length > 2 && ["controllers", "services", "repositories", "routes"].includes(p[1]))
184
+
185
+ return {
186
+ organization: hasDomain ? "domain" : hasFeature ? "feature" : hasLayer ? "layer" : "flat",
187
+ hasIndexFiles: indexCount > files.length * 0.2,
188
+ testLocation: coLocated > separateDir ? "co-located" : separateDir > coLocated ? "separate" : "mixed",
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Format conventions as a readable report.
194
+ */
195
+ export function formatConventions(c: ProjectConventions): string {
196
+ const lines = [
197
+ "## Project Conventions",
198
+ "",
199
+ "### Naming",
200
+ `- Variables: ${c.naming.variables}`,
201
+ `- Functions: ${c.naming.functions}`,
202
+ `- Files: ${c.naming.files}`,
203
+ `- Constants: ${c.naming.constants}`,
204
+ "",
205
+ "### Imports",
206
+ `- Style: ${c.imports.style}`,
207
+ `- Barrel files: ${c.imports.useBarrelFiles ? "yes" : "no"}`,
208
+ `- Extensions: ${c.imports.extension}`,
209
+ "",
210
+ "### Async",
211
+ `- Style: ${c.async.style}`,
212
+ `- Error handling: ${c.async.errorHandling}`,
213
+ "",
214
+ "### Structure",
215
+ `- Organization: ${c.structure.organization}`,
216
+ `- Index files: ${c.structure.hasIndexFiles ? "yes" : "no"}`,
217
+ `- Test location: ${c.structure.testLocation}`,
218
+ ]
219
+ return lines.join("\n")
220
+ }
@@ -0,0 +1,203 @@
1
+ import type { KnowledgeGraph } from '../domain/types.js'
2
+
3
+ export interface DependencyNode {
4
+ id: string
5
+ name: string
6
+ type: string
7
+ dependencies: string[]
8
+ dependents: string[]
9
+ }
10
+
11
+ export interface DependencyReport {
12
+ nodes: DependencyNode[]
13
+ cycles: string[][]
14
+ coupling: {
15
+ afferent: Record<string, number>
16
+ efferent: Record<string, number>
17
+ instability: Record<string, number>
18
+ }
19
+ summary: {
20
+ total_nodes: number
21
+ total_dependencies: number
22
+ cycles_found: number
23
+ most_coupled: string
24
+ least_stable: string
25
+ }
26
+ }
27
+
28
+ function detectCycles(nodes: DependencyNode[]): string[][] {
29
+ const cycles: string[][] = []
30
+ const visited = new Set<string>()
31
+ const recursionStack = new Set<string>()
32
+
33
+ function dfs(nodeId: string, path: string[]): void {
34
+ visited.add(nodeId)
35
+ recursionStack.add(nodeId)
36
+ path.push(nodeId)
37
+
38
+ const node = nodes.find(n => n.id === nodeId)
39
+ if (node) {
40
+ for (const dep of node.dependencies) {
41
+ if (!visited.has(dep)) {
42
+ dfs(dep, [...path])
43
+ } else if (recursionStack.has(dep)) {
44
+ const cycleStart = path.indexOf(dep)
45
+ if (cycleStart !== -1) {
46
+ cycles.push(path.slice(cycleStart))
47
+ }
48
+ }
49
+ }
50
+ }
51
+
52
+ recursionStack.delete(nodeId)
53
+ }
54
+
55
+ for (const node of nodes) {
56
+ if (!visited.has(node.id)) {
57
+ dfs(node.id, [])
58
+ }
59
+ }
60
+
61
+ return cycles
62
+ }
63
+
64
+ function calculateCoupling(nodes: DependencyNode[]): DependencyReport['coupling'] {
65
+ const afferent: Record<string, number> = {}
66
+ const efferent: Record<string, number> = {}
67
+ const instability: Record<string, number> = {}
68
+
69
+ for (const node of nodes) {
70
+ afferent[node.id] = node.dependents.length
71
+ efferent[node.id] = node.dependencies.length
72
+
73
+ const total = afferent[node.id] + efferent[node.id]
74
+ instability[node.id] = total > 0 ? efferent[node.id] / total : 0
75
+ }
76
+
77
+ return { afferent, efferent, instability }
78
+ }
79
+
80
+ export function analyzeDependencies(graph: KnowledgeGraph): DependencyReport {
81
+ const nodes: DependencyNode[] = []
82
+
83
+ for (const node of graph.nodes) {
84
+ const dependencies = graph.relationships
85
+ .filter(r => r.from === node.id && ['depends_on', 'uses', 'calls', 'requires'].includes(r.type))
86
+ .map(r => r.to)
87
+
88
+ const dependents = graph.relationships
89
+ .filter(r => r.to === node.id && ['depends_on', 'uses', 'calls', 'requires'].includes(r.type))
90
+ .map(r => r.from)
91
+
92
+ nodes.push({
93
+ id: node.id,
94
+ name: node.name,
95
+ type: node.type,
96
+ dependencies,
97
+ dependents,
98
+ })
99
+ }
100
+
101
+ const cycles = detectCycles(nodes)
102
+ const coupling = calculateCoupling(nodes)
103
+
104
+ const totalDependencies = nodes.reduce((sum, n) => sum + n.dependencies.length, 0)
105
+ const mostCoupled = nodes.reduce((most, n) =>
106
+ (n.dependencies.length + n.dependents.length) > (most.dependencies.length + most.dependents.length) ? n : most
107
+ , nodes[0])
108
+
109
+ const leastStable = Object.entries(coupling.instability)
110
+ .reduce((max, [id, value]) => value > max.value ? { id, value } : max, { id: '', value: 0 })
111
+
112
+ return {
113
+ nodes,
114
+ cycles,
115
+ coupling,
116
+ summary: {
117
+ total_nodes: nodes.length,
118
+ total_dependencies: totalDependencies,
119
+ cycles_found: cycles.length,
120
+ most_coupled: mostCoupled?.name || 'N/A',
121
+ least_stable: leastStable.id ? nodes.find(n => n.id === leastStable.id)?.name || 'N/A' : 'N/A',
122
+ },
123
+ }
124
+ }
125
+
126
+ export function formatDependencyReport(report: DependencyReport): string {
127
+ const lines = [
128
+ '## Análise de Dependências',
129
+ '',
130
+ `**Total de Nós:** ${report.summary.total_nodes}`,
131
+ `**Total de Dependências:** ${report.summary.total_dependencies}`,
132
+ `**Ciclos Encontrados:** ${report.summary.cycles_found}`,
133
+ `**Mais Acoplado:** ${report.summary.most_coupled}`,
134
+ `**Menos Estável:** ${report.summary.least_stable}`,
135
+ '',
136
+ ]
137
+
138
+ if (report.cycles.length > 0) {
139
+ lines.push('### ⚠️ Ciclos de Dependência Detectados')
140
+ for (let i = 0; i < report.cycles.length; i++) {
141
+ const cycle = report.cycles[i]
142
+ lines.push(`**Ciclo ${i + 1}:**`)
143
+ lines.push(cycle.map(id => {
144
+ const node = report.nodes.find(n => n.id === id)
145
+ return node?.name || id
146
+ }).join(' → '))
147
+ }
148
+ lines.push('')
149
+ lines.push('**Recomendação:** Quebre os ciclos introduzindo interfaces ou invertendo dependências.')
150
+ lines.push('')
151
+ }
152
+
153
+ lines.push('### Acoplamento')
154
+ lines.push('#### Nós com Maior Acoplamento (Efferent)')
155
+ const sortedByEfferent = Object.entries(report.coupling.efferent)
156
+ .sort(([, a], [, b]) => b - a)
157
+ .slice(0, 5)
158
+
159
+ for (const [id, count] of sortedByEfferent) {
160
+ const node = report.nodes.find(n => n.id === id)
161
+ if (node && count > 0) {
162
+ lines.push(`- **${node.name}** (${node.type}): ${count} dependências`)
163
+ }
164
+ }
165
+
166
+ lines.push('')
167
+ lines.push('#### Nós com Maior Reuso (Afferent)')
168
+ const sortedByAfferent = Object.entries(report.coupling.afferent)
169
+ .sort(([, a], [, b]) => b - a)
170
+ .slice(0, 5)
171
+
172
+ for (const [id, count] of sortedByAfferent) {
173
+ const node = report.nodes.find(n => n.id === id)
174
+ if (node && count > 0) {
175
+ lines.push(`- **${node.name}** (${node.type}): ${count} dependentes`)
176
+ }
177
+ }
178
+
179
+ lines.push('')
180
+ lines.push('#### Instabilidade')
181
+ const sortedByInstability = Object.entries(report.coupling.instability)
182
+ .sort(([, a], [, b]) => b - a)
183
+ .slice(0, 5)
184
+
185
+ for (const [id, value] of sortedByInstability) {
186
+ const node = report.nodes.find(n => n.id === id)
187
+ if (node) {
188
+ const stability = value < 0.3 ? '🟢 Estável' : value < 0.7 ? '🟡 Moderado' : '🔴 Instável'
189
+ lines.push(`- **${node.name}**: ${(value * 100).toFixed(0)}% ${stability}`)
190
+ }
191
+ }
192
+
193
+ lines.push(
194
+ '',
195
+ '### Recomendações',
196
+ '- Evite ciclos de dependência',
197
+ '- Mantenha a instabilidade baixa para módulos reutilizáveis',
198
+ '- Use inversão de dependência para desacoplar módulos',
199
+ '- Princípio Dependency Inversion (SOLID)',
200
+ )
201
+
202
+ return lines.join('\n')
203
+ }