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,221 @@
1
+ import type { KnowledgeGraph, FileNode, SymbolNode, TestNode, ChangeNode } from "../domain/types.js"
2
+ import { getNodesByType, removeNode } from "./engine.js"
3
+ import { existsSync, readFileSync } from "fs"
4
+ import { join } from "path"
5
+
6
+ export interface PruneReport {
7
+ removed_nodes: Array<{ id: string; type: string; name: string; reason: string }>
8
+ deprecated_changes: string[]
9
+ total_removed: number
10
+ total_deprecated: number
11
+ space_freed_estimate: string
12
+ }
13
+
14
+ /**
15
+ * Prune obsolete nodes from the graph:
16
+ * - FileNodes pointing to deleted files
17
+ * - SymbolNodes pointing to non-existent symbols
18
+ * - TestNodes for deleted test files
19
+ * - Old completed ChangeNodes (>30 days)
20
+ * - Duplicate relationships
21
+ */
22
+ export function pruneGraph(graph: KnowledgeGraph, projectDir: string): PruneReport {
23
+ const report: PruneReport = {
24
+ removed_nodes: [],
25
+ deprecated_changes: [],
26
+ total_removed: 0,
27
+ total_deprecated: 0,
28
+ space_freed_estimate: "0 nodes",
29
+ }
30
+
31
+ // 1. Remove FileNodes for deleted files
32
+ pruneDeadFileNodes(graph, projectDir, report)
33
+
34
+ // 2. Remove SymbolNodes for deleted symbols
35
+ pruneDeadSymbolNodes(graph, projectDir, report)
36
+
37
+ // 3. Remove TestNodes for deleted test files
38
+ pruneDeadTestNodes(graph, projectDir, report)
39
+
40
+ // 4. Archive old completed ChangeNodes
41
+ archiveOldChanges(graph, report)
42
+
43
+ // 5. Remove duplicate relationships
44
+ pruneDuplicateRelationships(graph, report)
45
+
46
+ report.space_freed_estimate = `${report.total_removed} node(s) removed, ${report.total_deprecated} change(s) archived`
47
+ return report
48
+ }
49
+
50
+ function pruneDeadFileNodes(graph: KnowledgeGraph, projectDir: string, report: PruneReport): void {
51
+ const fileNodes = getNodesByType<FileNode>(graph, "file")
52
+ for (const fileNode of fileNodes) {
53
+ const path = fileNode.metadata.path
54
+ if (!path) continue
55
+ const fullPath = join(projectDir, path)
56
+ if (!existsSync(fullPath)) {
57
+ report.removed_nodes.push({
58
+ id: fileNode.id,
59
+ type: "file",
60
+ name: fileNode.name,
61
+ reason: `File no longer exists: ${path}`,
62
+ })
63
+ try {
64
+ removeNode(graph, fileNode.id)
65
+ report.total_removed++
66
+ } catch {}
67
+ }
68
+ }
69
+ }
70
+
71
+ function pruneDeadSymbolNodes(graph: KnowledgeGraph, projectDir: string, report: PruneReport): void {
72
+ const symbolNodes = getNodesByType<SymbolNode>(graph, "symbol")
73
+ for (const symNode of symbolNodes) {
74
+ const filePath = symNode.metadata.file_path
75
+ if (!filePath) continue
76
+ const fullPath = join(projectDir, filePath)
77
+ if (!existsSync(fullPath)) {
78
+ report.removed_nodes.push({
79
+ id: symNode.id,
80
+ type: "symbol",
81
+ name: symNode.name,
82
+ reason: `Source file no longer exists: ${filePath}`,
83
+ })
84
+ try {
85
+ removeNode(graph, symNode.id)
86
+ report.total_removed++
87
+ } catch {}
88
+ continue
89
+ }
90
+
91
+ // Check if the symbol still exists in the file
92
+ try {
93
+ const content = readFileSync(fullPath, "utf-8")
94
+ const name = symNode.name.split(".").pop() || symNode.name // Handle Class.method
95
+ if (!content.includes(name)) {
96
+ report.removed_nodes.push({
97
+ id: symNode.id,
98
+ type: "symbol",
99
+ name: symNode.name,
100
+ reason: `Symbol "${name}" no longer found in ${filePath}`,
101
+ })
102
+ try {
103
+ removeNode(graph, symNode.id)
104
+ report.total_removed++
105
+ } catch {}
106
+ }
107
+ } catch {}
108
+ }
109
+ }
110
+
111
+ function pruneDeadTestNodes(graph: KnowledgeGraph, projectDir: string, report: PruneReport): void {
112
+ const testNodes = getNodesByType<TestNode>(graph, "test")
113
+ for (const testNode of testNodes) {
114
+ const target = (testNode.metadata as any).target
115
+ if (!target) continue
116
+ const fullPath = join(projectDir, target)
117
+ if (!existsSync(fullPath)) {
118
+ report.removed_nodes.push({
119
+ id: testNode.id,
120
+ type: "test",
121
+ name: testNode.name,
122
+ reason: `Test file no longer exists: ${target}`,
123
+ })
124
+ try {
125
+ removeNode(graph, testNode.id)
126
+ report.total_removed++
127
+ } catch {}
128
+ }
129
+ }
130
+ }
131
+
132
+ function archiveOldChanges(graph: KnowledgeGraph, report: PruneReport): void {
133
+ const now = Date.now()
134
+ const ARCHIVE_DAYS = 30
135
+
136
+ const changeNodes = getNodesByType<ChangeNode>(graph, "change")
137
+ for (const change of changeNodes) {
138
+ if (change.status !== "COMPLETED") continue
139
+ const age = now - new Date(change.updated_at).getTime()
140
+ if (age > ARCHIVE_DAYS * 24 * 60 * 60 * 1000) {
141
+ change.status = "DEPRECATED"
142
+ change.updated_at = new Date().toISOString()
143
+ change.metadata = {
144
+ ...change.metadata,
145
+ auto_archived: true,
146
+ archived_reason: `Auto-archived: completed ${Math.floor(age / (24 * 60 * 60 * 1000))} days ago`,
147
+ }
148
+ report.deprecated_changes.push(change.id)
149
+ report.total_deprecated++
150
+ }
151
+ }
152
+ }
153
+
154
+ function pruneDuplicateRelationships(graph: KnowledgeGraph, report: PruneReport): void {
155
+ const seen = new Set<string>()
156
+ const toRemove: number[] = []
157
+
158
+ for (let i = 0; i < graph.relationships.length; i++) {
159
+ const rel = graph.relationships[i]
160
+ const key = `${rel.from}||${rel.to}||${rel.type}`
161
+ if (seen.has(key)) {
162
+ toRemove.push(i)
163
+ report.total_removed++
164
+ } else {
165
+ seen.add(key)
166
+ }
167
+ }
168
+
169
+ // Remove in reverse order to maintain indices
170
+ for (let i = toRemove.length - 1; i >= 0; i--) {
171
+ graph.relationships.splice(toRemove[i], 1)
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Format prune report as readable markdown.
177
+ */
178
+ export function formatPruneReport(report: PruneReport): string {
179
+ const lines = [
180
+ "## Graph Pruning Report",
181
+ "",
182
+ ]
183
+
184
+ if (report.total_removed === 0 && report.total_deprecated === 0) {
185
+ lines.push("✅ Graph is clean. No obsolete nodes found.")
186
+ return lines.join("\n")
187
+ }
188
+
189
+ if (report.removed_nodes.length > 0) {
190
+ lines.push(`### Removed Nodes (${report.removed_nodes.length})`)
191
+ const byType = new Map<string, typeof report.removed_nodes>()
192
+ for (const node of report.removed_nodes) {
193
+ const list = byType.get(node.type) || []
194
+ list.push(node)
195
+ byType.set(node.type, list)
196
+ }
197
+ for (const [type, nodes] of byType) {
198
+ lines.push(`\n**${type}** (${nodes.length}):`)
199
+ for (const node of nodes.slice(0, 10)) {
200
+ lines.push(`- ${node.name}: ${node.reason}`)
201
+ }
202
+ if (nodes.length > 10) lines.push(`- ... and ${nodes.length - 10} more`)
203
+ }
204
+ lines.push("")
205
+ }
206
+
207
+ if (report.deprecated_changes.length > 0) {
208
+ lines.push(`### Archived Changes (${report.deprecated_changes.length})`)
209
+ lines.push(`Changes older than 30 days marked as DEPRECATED:`)
210
+ for (const id of report.deprecated_changes.slice(0, 10)) {
211
+ lines.push(`- ${id}`)
212
+ }
213
+ if (report.deprecated_changes.length > 10) {
214
+ lines.push(`- ... and ${report.deprecated_changes.length - 10} more`)
215
+ }
216
+ lines.push("")
217
+ }
218
+
219
+ lines.push(`**Summary:** ${report.space_freed_estimate}`)
220
+ return lines.join("\n")
221
+ }
@@ -0,0 +1,331 @@
1
+ import type { KnowledgeGraph, AnyNode, Relationship } from "../domain/types.js"
2
+ import { getNode, getOutgoing, getIncoming } from "./engine.js"
3
+
4
+ export interface TraverseOptions {
5
+ max_depth?: number
6
+ edge_types?: string[]
7
+ include_start?: boolean
8
+ }
9
+
10
+ export function bfsOutgoing(
11
+ graph: KnowledgeGraph,
12
+ startId: string,
13
+ options: TraverseOptions = {},
14
+ ): { nodes: AnyNode[]; edges: Relationship[]; distances: Map<string, number> } {
15
+ const maxDepth = options.max_depth ?? 10
16
+ const edgeTypes = options.edge_types ? new Set(options.edge_types) : null
17
+
18
+ const visited = new Set<string>()
19
+ const distances = new Map<string, number>()
20
+ const resultNodes: AnyNode[] = []
21
+ const resultEdges: Relationship[] = []
22
+
23
+ const queue: Array<{ id: string; depth: number }> = [{ id: startId, depth: 0 }]
24
+ visited.add(startId)
25
+ distances.set(startId, 0)
26
+
27
+ if (options.include_start) {
28
+ const startNode = getNode(graph, startId)
29
+ if (startNode) resultNodes.push(startNode)
30
+ }
31
+
32
+ while (queue.length > 0) {
33
+ const current = queue.shift()!
34
+ if (current.depth >= maxDepth) continue
35
+
36
+ const outgoing = getOutgoing(graph, current.id)
37
+ for (const edge of outgoing) {
38
+ if (edgeTypes && !edgeTypes.has(edge.type)) continue
39
+ if (visited.has(edge.to)) continue
40
+
41
+ visited.add(edge.to)
42
+ distances.set(edge.to, current.depth + 1)
43
+ resultEdges.push(edge)
44
+
45
+ const targetNode = getNode(graph, edge.to)
46
+ if (targetNode) resultNodes.push(targetNode)
47
+
48
+ queue.push({ id: edge.to, depth: current.depth + 1 })
49
+ }
50
+ }
51
+
52
+ return { nodes: resultNodes, edges: resultEdges, distances }
53
+ }
54
+
55
+ export function bfsIncoming(
56
+ graph: KnowledgeGraph,
57
+ startId: string,
58
+ options: TraverseOptions = {},
59
+ ): { nodes: AnyNode[]; edges: Relationship[]; distances: Map<string, number> } {
60
+ const maxDepth = options.max_depth ?? 10
61
+ const edgeTypes = options.edge_types ? new Set(options.edge_types) : null
62
+
63
+ const visited = new Set<string>()
64
+ const distances = new Map<string, number>()
65
+ const resultNodes: AnyNode[] = []
66
+ const resultEdges: Relationship[] = []
67
+
68
+ const queue: Array<{ id: string; depth: number }> = [{ id: startId, depth: 0 }]
69
+ visited.add(startId)
70
+ distances.set(startId, 0)
71
+
72
+ if (options.include_start) {
73
+ const startNode = getNode(graph, startId)
74
+ if (startNode) resultNodes.push(startNode)
75
+ }
76
+
77
+ while (queue.length > 0) {
78
+ const current = queue.shift()!
79
+ if (current.depth >= maxDepth) continue
80
+
81
+ const incoming = getIncoming(graph, current.id)
82
+ for (const edge of incoming) {
83
+ if (edgeTypes && !edgeTypes.has(edge.type)) continue
84
+ if (visited.has(edge.from)) continue
85
+
86
+ visited.add(edge.from)
87
+ distances.set(edge.from, current.depth + 1)
88
+ resultEdges.push(edge)
89
+
90
+ const sourceNode = getNode(graph, edge.from)
91
+ if (sourceNode) resultNodes.push(sourceNode)
92
+
93
+ queue.push({ id: edge.from, depth: current.depth + 1 })
94
+ }
95
+ }
96
+
97
+ return { nodes: resultNodes, edges: resultEdges, distances }
98
+ }
99
+
100
+ export function bfsBoth(
101
+ graph: KnowledgeGraph,
102
+ startId: string,
103
+ options: TraverseOptions = {},
104
+ ): { nodes: AnyNode[]; edges: Relationship[]; distances: Map<string, number> } {
105
+ const maxDepth = options.max_depth ?? 10
106
+ const edgeTypes = options.edge_types ? new Set(options.edge_types) : null
107
+
108
+ const visited = new Set<string>()
109
+ const distances = new Map<string, number>()
110
+ const resultNodes: AnyNode[] = []
111
+ const resultEdges: Relationship[] = []
112
+
113
+ const queue: Array<{ id: string; depth: number }> = [{ id: startId, depth: 0 }]
114
+ visited.add(startId)
115
+ distances.set(startId, 0)
116
+
117
+ if (options.include_start) {
118
+ const startNode = getNode(graph, startId)
119
+ if (startNode) resultNodes.push(startNode)
120
+ }
121
+
122
+ while (queue.length > 0) {
123
+ const current = queue.shift()!
124
+ if (current.depth >= maxDepth) continue
125
+
126
+ const outgoing = getOutgoing(graph, current.id)
127
+ const incoming = getIncoming(graph, current.id)
128
+ const allEdges = [...outgoing, ...incoming]
129
+
130
+ for (const edge of allEdges) {
131
+ if (edgeTypes && !edgeTypes.has(edge.type)) continue
132
+ const neighborId = edge.from === current.id ? edge.to : edge.from
133
+ if (visited.has(neighborId)) continue
134
+
135
+ visited.add(neighborId)
136
+ distances.set(neighborId, current.depth + 1)
137
+ resultEdges.push(edge)
138
+
139
+ const neighborNode = getNode(graph, neighborId)
140
+ if (neighborNode) resultNodes.push(neighborNode)
141
+
142
+ queue.push({ id: neighborId, depth: current.depth + 1 })
143
+ }
144
+ }
145
+
146
+ return { nodes: resultNodes, edges: resultEdges, distances }
147
+ }
148
+
149
+ export function findPath(
150
+ graph: KnowledgeGraph,
151
+ fromId: string,
152
+ toId: string,
153
+ maxDepth: number = 10,
154
+ ): AnyNode[] | null {
155
+ const visited = new Set<string>()
156
+ const queue: Array<{ id: string; path: string[] }> = [{ id: fromId, path: [fromId] }]
157
+ visited.add(fromId)
158
+
159
+ while (queue.length > 0) {
160
+ const current = queue.shift()!
161
+ if (current.id === toId) {
162
+ return current.path
163
+ .map((id) => getNode(graph, id))
164
+ .filter(Boolean) as AnyNode[]
165
+ }
166
+ if (current.path.length > maxDepth) continue
167
+
168
+ const outgoing = getOutgoing(graph, current.id)
169
+ for (const edge of outgoing) {
170
+ if (!visited.has(edge.to)) {
171
+ visited.add(edge.to)
172
+ queue.push({ id: edge.to, path: [...current.path, edge.to] })
173
+ }
174
+ }
175
+ }
176
+
177
+ return null
178
+ }
179
+
180
+ export function computeImpact(
181
+ graph: KnowledgeGraph,
182
+ nodeId: string,
183
+ maxDepth: number = 5,
184
+ ): { direct: AnyNode[]; indirect: AnyNode[]; potential: AnyNode[] } {
185
+ const depth1 = bfsOutgoing(graph, nodeId, { max_depth: 1, include_start: false })
186
+ const depthN = bfsOutgoing(graph, nodeId, { max_depth: maxDepth, include_start: false })
187
+
188
+ const directIds = new Set(depth1.nodes.map((n) => n.id))
189
+ const indirectIds = new Set<string>()
190
+ const potentialIds = new Set<string>()
191
+
192
+ for (const node of depthN.nodes) {
193
+ if (directIds.has(node.id)) continue
194
+ const dist = depthN.distances.get(node.id) ?? 0
195
+ if (dist <= 2) indirectIds.add(node.id)
196
+ else potentialIds.add(node.id)
197
+ }
198
+
199
+ return {
200
+ direct: depth1.nodes,
201
+ indirect: [...indirectIds].map((id) => getNode(graph, id)).filter(Boolean) as AnyNode[],
202
+ potential: [...potentialIds].map((id) => getNode(graph, id)).filter(Boolean) as AnyNode[],
203
+ }
204
+ }
205
+
206
+ export interface ImpactAction {
207
+ node_id: string
208
+ node_type: string
209
+ node_name: string
210
+ action: "modify" | "create" | "update_relationship" | "add_test" | "update_spec"
211
+ description: string
212
+ target_files: string[]
213
+ priority: "high" | "medium" | "low"
214
+ }
215
+
216
+ /**
217
+ * Compute impact with concrete actions: what files to modify,
218
+ * what relationships to update, what tests to add.
219
+ */
220
+ export function computeImpactActions(
221
+ graph: KnowledgeGraph,
222
+ nodeId: string,
223
+ maxDepth: number = 3,
224
+ ): ImpactAction[] {
225
+ const impact = computeImpact(graph, nodeId, maxDepth)
226
+ const actions: ImpactAction[] = []
227
+ const sourceNode = getNode(graph, nodeId)
228
+ if (!sourceNode) return actions
229
+
230
+ // Direct impact → modify actions
231
+ for (const node of impact.direct) {
232
+ const files = findNodeFiles(graph, node.id)
233
+ const actionType: ImpactAction["action"] = node.type === "file" ? "modify" :
234
+ node.type === "test" ? "add_test" : "update_spec"
235
+
236
+ actions.push({
237
+ node_id: node.id,
238
+ node_type: node.type,
239
+ node_name: node.name,
240
+ action: actionType,
241
+ description: generateActionDescription(sourceNode, node),
242
+ target_files: files,
243
+ priority: "high",
244
+ })
245
+ }
246
+
247
+ // Indirect impact → medium priority
248
+ for (const node of impact.indirect) {
249
+ const files = findNodeFiles(graph, node.id)
250
+ actions.push({
251
+ node_id: node.id,
252
+ node_type: node.type,
253
+ node_name: node.name,
254
+ action: "update_spec",
255
+ description: `Verify ${node.type} "${node.name}" still aligns after changes to "${sourceNode.name}"`,
256
+ target_files: files,
257
+ priority: "medium",
258
+ })
259
+ }
260
+
261
+ // Potential impact → low priority, verification needed
262
+ for (const node of impact.potential.slice(0, 10)) {
263
+ const files = findNodeFiles(graph, node.id)
264
+ actions.push({
265
+ node_id: node.id,
266
+ node_type: node.type,
267
+ node_name: node.name,
268
+ action: "update_spec",
269
+ description: `Check if ${node.type} "${node.name}" needs updates`,
270
+ target_files: files,
271
+ priority: "low",
272
+ })
273
+ }
274
+
275
+ return actions
276
+ }
277
+
278
+ function findNodeFiles(graph: KnowledgeGraph, nodeId: string): string[] {
279
+ const files: string[] = []
280
+ // Check if the node itself is a file
281
+ const node = getNode(graph, nodeId)
282
+ if (node?.type === "file") {
283
+ const path = (node.metadata as any).path
284
+ if (path) files.push(path)
285
+ return files
286
+ }
287
+
288
+ // Find file nodes connected to this node
289
+ for (const rel of graph.relationships) {
290
+ if (rel.from === nodeId || rel.to === nodeId) {
291
+ const otherId = rel.from === nodeId ? rel.to : rel.from
292
+ const other = getNode(graph, otherId)
293
+ if (other?.type === "file") {
294
+ const path = (other.metadata as any).path
295
+ if (path) files.push(path)
296
+ }
297
+ if (other?.type === "symbol") {
298
+ const path = (other.metadata as any).file_path
299
+ if (path) files.push(path)
300
+ }
301
+ }
302
+ }
303
+ return [...new Set(files)]
304
+ }
305
+
306
+ function generateActionDescription(source: AnyNode, target: AnyNode): string {
307
+ const relType = target.type
308
+ if (relType === "entity") return `Update entity "${target.name}" to reflect changes in "${source.name}"`
309
+ if (relType === "endpoint") return `Update endpoint "${target.name}" API contract`
310
+ if (relType === "requirement") return `Verify requirement "${target.name}" is still satisfied`
311
+ if (relType === "test") return `Update test "${target.name}" for new behavior`
312
+ if (relType === "business_rule") return `Check if business rule "${target.name}" still applies`
313
+ if (relType === "file") return `Modify file "${target.name}"`
314
+ return `Update ${relType} "${target.name}"`
315
+ }
316
+
317
+ export function getSubgraph(
318
+ graph: KnowledgeGraph,
319
+ nodeIds: string[],
320
+ ): KnowledgeGraph {
321
+ const idSet = new Set(nodeIds)
322
+ return {
323
+ version: graph.version,
324
+ project_id: graph.project_id,
325
+ nodes: graph.nodes.filter((n) => idSet.has(n.id)),
326
+ relationships: graph.relationships.filter(
327
+ (r) => idSet.has(r.from) && idSet.has(r.to),
328
+ ),
329
+ metadata: { ...graph.metadata },
330
+ }
331
+ }
@@ -0,0 +1,87 @@
1
+ import type { KnowledgeGraph, IncidentNode } from '../domain/types.js'
2
+
3
+ export interface IncidentWorkflow {
4
+ id: string
5
+ title: string
6
+ severity: 'SEV1' | 'SEV2' | 'SEV3' | 'SEV4'
7
+ impact: string
8
+ }
9
+
10
+ export function createIncident(
11
+ _graph: KnowledgeGraph,
12
+ workflow: IncidentWorkflow
13
+ ): IncidentNode {
14
+ const incidentId = `incident-${Date.now()}`
15
+
16
+ const incident: IncidentNode = {
17
+ id: incidentId,
18
+ type: 'incident',
19
+ name: `Incidente: ${workflow.title}`,
20
+ description: workflow.impact,
21
+ status: 'PROPOSED',
22
+ version: 1,
23
+ metadata: {
24
+ incident_title: workflow.title,
25
+ severity: workflow.severity,
26
+ status: 'open',
27
+ impact: workflow.impact,
28
+ timeline: [
29
+ {
30
+ timestamp: new Date().toISOString(),
31
+ action: 'Incidente reportado',
32
+ author: 'system',
33
+ },
34
+ ],
35
+ },
36
+ created_at: new Date().toISOString(),
37
+ updated_at: new Date().toISOString(),
38
+ }
39
+
40
+ return incident
41
+ }
42
+
43
+ export function getIncidentInstructions(incident: IncidentNode): string {
44
+ const lines = [
45
+ '## Gestão de Incidente',
46
+ '',
47
+ `**Título:** ${incident.metadata.incident_title}`,
48
+ `**Severidade:** ${incident.metadata.severity}`,
49
+ `**Status:** ${incident.metadata.status}`,
50
+ `**Impacto:** ${incident.metadata.impact}`,
51
+ '',
52
+ '### Procedimentos por Severidade',
53
+ '',
54
+ '**SEV1 (Crítico):**',
55
+ '- Notificar stakeholders imediatamente',
56
+ '- Ativar equipe de resposta a incidentes',
57
+ '- Comunicação a cada 15 minutos',
58
+ '',
59
+ '**SEV2 (Alto):**',
60
+ '- Notificar equipe responsável',
61
+ '- Atualização a cada 30 minutos',
62
+ '',
63
+ '**SEV3 (Médio):**',
64
+ '- Documentar e agendar correção',
65
+ '- Atualização quando houver progresso',
66
+ '',
67
+ '**SEV4 (Baixo):**',
68
+ '- Documentar para correção futura',
69
+ '',
70
+ '### Timeline',
71
+ ]
72
+
73
+ for (const entry of incident.metadata.timeline) {
74
+ lines.push(`- ${entry.timestamp}: ${entry.action} (${entry.author})`)
75
+ }
76
+
77
+ lines.push(
78
+ '',
79
+ '### Próximos Passos',
80
+ '1. Identificar causa raiz',
81
+ '2. Implementar correção',
82
+ '3. Verificar resolução',
83
+ '4. Documentar lições aprendidas',
84
+ )
85
+
86
+ return lines.join('\n')
87
+ }