codehere 0.1.0 → 0.2.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.

Potentially problematic release.


This version of codehere might be problematic. Click here for more details.

Files changed (603) hide show
  1. package/README.md +51 -25
  2. package/dist/agents/base.d.ts +107 -0
  3. package/dist/agents/base.d.ts.map +1 -0
  4. package/dist/agents/base.js +101 -0
  5. package/dist/agents/base.js.map +1 -0
  6. package/dist/agents/orchestrator-model-driven.d.ts +41 -0
  7. package/dist/agents/orchestrator-model-driven.d.ts.map +1 -0
  8. package/dist/agents/orchestrator-model-driven.js +141 -0
  9. package/dist/agents/orchestrator-model-driven.js.map +1 -0
  10. package/dist/agents/react-orchestrator-agent.d.ts +15 -0
  11. package/dist/agents/react-orchestrator-agent.d.ts.map +1 -0
  12. package/dist/agents/react-orchestrator-agent.js +54 -0
  13. package/dist/agents/react-orchestrator-agent.js.map +1 -0
  14. package/dist/application/agents/execution-agent.d.ts +68 -0
  15. package/dist/application/agents/execution-agent.d.ts.map +1 -0
  16. package/dist/application/agents/execution-agent.js +299 -0
  17. package/dist/application/agents/execution-agent.js.map +1 -0
  18. package/dist/application/agents/multi-agent-orchestrator.d.ts +64 -0
  19. package/dist/application/agents/multi-agent-orchestrator.d.ts.map +1 -0
  20. package/dist/application/agents/multi-agent-orchestrator.js +209 -0
  21. package/dist/application/agents/multi-agent-orchestrator.js.map +1 -0
  22. package/dist/application/agents/planning-agent.d.ts +61 -0
  23. package/dist/application/agents/planning-agent.d.ts.map +1 -0
  24. package/dist/application/agents/planning-agent.js +357 -0
  25. package/dist/application/agents/planning-agent.js.map +1 -0
  26. package/dist/application/agents/validation-agent.d.ts +64 -0
  27. package/dist/application/agents/validation-agent.d.ts.map +1 -0
  28. package/dist/application/agents/validation-agent.js +182 -0
  29. package/dist/application/agents/validation-agent.js.map +1 -0
  30. package/dist/application/architectures/plan-and-act.d.ts +94 -0
  31. package/dist/application/architectures/plan-and-act.d.ts.map +1 -0
  32. package/dist/application/architectures/plan-and-act.js +242 -0
  33. package/dist/application/architectures/plan-and-act.js.map +1 -0
  34. package/dist/application/index.d.ts +12 -0
  35. package/dist/application/index.d.ts.map +1 -0
  36. package/dist/application/index.js +12 -0
  37. package/dist/application/index.js.map +1 -0
  38. package/dist/application/services/agent-factory.d.ts +9 -0
  39. package/dist/application/services/agent-factory.d.ts.map +1 -0
  40. package/dist/application/services/agent-factory.js +28 -0
  41. package/dist/application/services/agent-factory.js.map +1 -0
  42. package/dist/application/services/dependency-container.d.ts +140 -0
  43. package/dist/application/services/dependency-container.d.ts.map +1 -0
  44. package/dist/application/services/dependency-container.js +402 -0
  45. package/dist/application/services/dependency-container.js.map +1 -0
  46. package/dist/application/services/git-context-service.d.ts +30 -0
  47. package/dist/application/services/git-context-service.d.ts.map +1 -0
  48. package/dist/application/services/git-context-service.js +83 -0
  49. package/dist/application/services/git-context-service.js.map +1 -0
  50. package/dist/application/services/intelligent-router.d.ts +74 -0
  51. package/dist/application/services/intelligent-router.d.ts.map +1 -0
  52. package/dist/application/services/intelligent-router.js +711 -0
  53. package/dist/application/services/intelligent-router.js.map +1 -0
  54. package/dist/application/services/tool-executor-service.d.ts +14 -0
  55. package/dist/application/services/tool-executor-service.d.ts.map +1 -0
  56. package/dist/application/services/tool-executor-service.js +94 -0
  57. package/dist/application/services/tool-executor-service.js.map +1 -0
  58. package/dist/application/use-cases/ask-question-use-case.d.ts +36 -0
  59. package/dist/application/use-cases/ask-question-use-case.d.ts.map +1 -0
  60. package/dist/application/use-cases/ask-question-use-case.js +150 -0
  61. package/dist/application/use-cases/ask-question-use-case.js.map +1 -0
  62. package/dist/application/use-cases/edit-file-use-case.d.ts +76 -0
  63. package/dist/application/use-cases/edit-file-use-case.d.ts.map +1 -0
  64. package/dist/application/use-cases/edit-file-use-case.js +685 -0
  65. package/dist/application/use-cases/edit-file-use-case.js.map +1 -0
  66. package/dist/application/use-cases/explain-file-use-case.d.ts +21 -0
  67. package/dist/application/use-cases/explain-file-use-case.d.ts.map +1 -0
  68. package/dist/application/use-cases/explain-file-use-case.js +50 -0
  69. package/dist/application/use-cases/explain-file-use-case.js.map +1 -0
  70. package/dist/application/use-cases/index-codebase-use-case.d.ts +46 -0
  71. package/dist/application/use-cases/index-codebase-use-case.d.ts.map +1 -0
  72. package/dist/application/use-cases/index-codebase-use-case.js +113 -0
  73. package/dist/application/use-cases/index-codebase-use-case.js.map +1 -0
  74. package/dist/application/use-cases/planning-use-case.d.ts +46 -0
  75. package/dist/application/use-cases/planning-use-case.d.ts.map +1 -0
  76. package/dist/application/use-cases/planning-use-case.js +267 -0
  77. package/dist/application/use-cases/planning-use-case.js.map +1 -0
  78. package/dist/application/use-cases/react-orchestration-use-case.d.ts +51 -0
  79. package/dist/application/use-cases/react-orchestration-use-case.d.ts.map +1 -0
  80. package/dist/application/use-cases/react-orchestration-use-case.js +325 -0
  81. package/dist/application/use-cases/react-orchestration-use-case.js.map +1 -0
  82. package/dist/application/use-cases/reflexion-use-case.d.ts +24 -0
  83. package/dist/application/use-cases/reflexion-use-case.d.ts.map +1 -0
  84. package/dist/application/use-cases/reflexion-use-case.js +30 -0
  85. package/dist/application/use-cases/reflexion-use-case.js.map +1 -0
  86. package/dist/application/workflows/deterministic-workflows.d.ts +61 -0
  87. package/dist/application/workflows/deterministic-workflows.d.ts.map +1 -0
  88. package/dist/application/workflows/deterministic-workflows.js +189 -0
  89. package/dist/application/workflows/deterministic-workflows.js.map +1 -0
  90. package/dist/cache.d.ts.map +1 -1
  91. package/dist/cache.js +1 -3
  92. package/dist/cache.js.map +1 -1
  93. package/dist/chat.js +10 -10
  94. package/dist/chat.js.map +1 -1
  95. package/dist/docs.d.ts.map +1 -1
  96. package/dist/docs.js +1 -2
  97. package/dist/docs.js.map +1 -1
  98. package/dist/domain/entities/code-chunk.d.ts +26 -0
  99. package/dist/domain/entities/code-chunk.d.ts.map +1 -0
  100. package/dist/domain/entities/code-chunk.js +6 -0
  101. package/dist/domain/entities/code-chunk.js.map +1 -0
  102. package/dist/domain/entities/decision.d.ts +37 -0
  103. package/dist/domain/entities/decision.d.ts.map +1 -0
  104. package/dist/domain/entities/decision.js +9 -0
  105. package/dist/domain/entities/decision.js.map +1 -0
  106. package/dist/domain/entities/edit.d.ts +35 -0
  107. package/dist/domain/entities/edit.d.ts.map +1 -0
  108. package/dist/domain/entities/edit.js +6 -0
  109. package/dist/domain/entities/edit.js.map +1 -0
  110. package/dist/domain/entities/knowledge-node.d.ts +83 -0
  111. package/dist/domain/entities/knowledge-node.d.ts.map +1 -0
  112. package/dist/domain/entities/knowledge-node.js +9 -0
  113. package/dist/domain/entities/knowledge-node.js.map +1 -0
  114. package/dist/domain/entities/knowledge-preservation.d.ts +42 -0
  115. package/dist/domain/entities/knowledge-preservation.d.ts.map +1 -0
  116. package/dist/domain/entities/knowledge-preservation.js +10 -0
  117. package/dist/domain/entities/knowledge-preservation.js.map +1 -0
  118. package/dist/domain/entities/memory.d.ts +36 -0
  119. package/dist/domain/entities/memory.d.ts.map +1 -0
  120. package/dist/domain/entities/memory.js +6 -0
  121. package/dist/domain/entities/memory.js.map +1 -0
  122. package/dist/domain/entities/pattern.d.ts +49 -0
  123. package/dist/domain/entities/pattern.d.ts.map +1 -0
  124. package/dist/domain/entities/pattern.js +7 -0
  125. package/dist/domain/entities/pattern.js.map +1 -0
  126. package/dist/domain/entities/plan.d.ts +42 -0
  127. package/dist/domain/entities/plan.d.ts.map +1 -0
  128. package/dist/domain/entities/plan.js +6 -0
  129. package/dist/domain/entities/plan.js.map +1 -0
  130. package/dist/domain/entities/query.d.ts +17 -0
  131. package/dist/domain/entities/query.d.ts.map +1 -0
  132. package/dist/domain/entities/query.js +6 -0
  133. package/dist/domain/entities/query.js.map +1 -0
  134. package/dist/domain/index.d.ts +16 -0
  135. package/dist/domain/index.d.ts.map +1 -0
  136. package/dist/domain/index.js +19 -0
  137. package/dist/domain/index.js.map +1 -0
  138. package/dist/domain/interfaces/ai-service.interface.d.ts +62 -0
  139. package/dist/domain/interfaces/ai-service.interface.d.ts.map +1 -0
  140. package/dist/domain/interfaces/ai-service.interface.js +6 -0
  141. package/dist/domain/interfaces/ai-service.interface.js.map +1 -0
  142. package/dist/domain/interfaces/code-analyzer.interface.d.ts +38 -0
  143. package/dist/domain/interfaces/code-analyzer.interface.d.ts.map +1 -0
  144. package/dist/domain/interfaces/code-analyzer.interface.js +6 -0
  145. package/dist/domain/interfaces/code-analyzer.interface.js.map +1 -0
  146. package/dist/domain/interfaces/decision-repository.interface.d.ts +51 -0
  147. package/dist/domain/interfaces/decision-repository.interface.d.ts.map +1 -0
  148. package/dist/domain/interfaces/decision-repository.interface.js +9 -0
  149. package/dist/domain/interfaces/decision-repository.interface.js.map +1 -0
  150. package/dist/domain/interfaces/embedding-repository.interface.d.ts +28 -0
  151. package/dist/domain/interfaces/embedding-repository.interface.d.ts.map +1 -0
  152. package/dist/domain/interfaces/embedding-repository.interface.js +6 -0
  153. package/dist/domain/interfaces/embedding-repository.interface.js.map +1 -0
  154. package/dist/domain/interfaces/knowledge-graph-repository.interface.d.ts +91 -0
  155. package/dist/domain/interfaces/knowledge-graph-repository.interface.d.ts.map +1 -0
  156. package/dist/domain/interfaces/knowledge-graph-repository.interface.js +9 -0
  157. package/dist/domain/interfaces/knowledge-graph-repository.interface.js.map +1 -0
  158. package/dist/domain/interfaces/knowledge-preservation-repository.interface.d.ts +50 -0
  159. package/dist/domain/interfaces/knowledge-preservation-repository.interface.d.ts.map +1 -0
  160. package/dist/domain/interfaces/knowledge-preservation-repository.interface.js +8 -0
  161. package/dist/domain/interfaces/knowledge-preservation-repository.interface.js.map +1 -0
  162. package/dist/domain/interfaces/memory-repository.interface.d.ts +49 -0
  163. package/dist/domain/interfaces/memory-repository.interface.d.ts.map +1 -0
  164. package/dist/domain/interfaces/memory-repository.interface.js +6 -0
  165. package/dist/domain/interfaces/memory-repository.interface.js.map +1 -0
  166. package/dist/domain/interfaces/pattern-repository.interface.d.ts +48 -0
  167. package/dist/domain/interfaces/pattern-repository.interface.d.ts.map +1 -0
  168. package/dist/domain/interfaces/pattern-repository.interface.js +6 -0
  169. package/dist/domain/interfaces/pattern-repository.interface.js.map +1 -0
  170. package/dist/domain/interfaces/verification-service.interface.d.ts +20 -0
  171. package/dist/domain/interfaces/verification-service.interface.d.ts.map +1 -0
  172. package/dist/domain/interfaces/verification-service.interface.js +6 -0
  173. package/dist/domain/interfaces/verification-service.interface.js.map +1 -0
  174. package/dist/domain/services/codebase-detector.d.ts +18 -0
  175. package/dist/domain/services/codebase-detector.d.ts.map +1 -0
  176. package/dist/domain/services/codebase-detector.js +91 -0
  177. package/dist/domain/services/codebase-detector.js.map +1 -0
  178. package/dist/domain/services/cross-team-pattern-sharing.d.ts +65 -0
  179. package/dist/domain/services/cross-team-pattern-sharing.d.ts.map +1 -0
  180. package/dist/domain/services/cross-team-pattern-sharing.js +125 -0
  181. package/dist/domain/services/cross-team-pattern-sharing.js.map +1 -0
  182. package/dist/domain/services/decision-recorder.d.ts +76 -0
  183. package/dist/domain/services/decision-recorder.d.ts.map +1 -0
  184. package/dist/domain/services/decision-recorder.js +223 -0
  185. package/dist/domain/services/decision-recorder.js.map +1 -0
  186. package/dist/domain/services/decision-retriever.d.ts +75 -0
  187. package/dist/domain/services/decision-retriever.d.ts.map +1 -0
  188. package/dist/domain/services/decision-retriever.js +133 -0
  189. package/dist/domain/services/decision-retriever.js.map +1 -0
  190. package/dist/domain/services/graded-memory-activation.d.ts +37 -0
  191. package/dist/domain/services/graded-memory-activation.d.ts.map +1 -0
  192. package/dist/domain/services/graded-memory-activation.js +69 -0
  193. package/dist/domain/services/graded-memory-activation.js.map +1 -0
  194. package/dist/domain/services/knowledge-access.d.ts +63 -0
  195. package/dist/domain/services/knowledge-access.d.ts.map +1 -0
  196. package/dist/domain/services/knowledge-access.js +132 -0
  197. package/dist/domain/services/knowledge-access.js.map +1 -0
  198. package/dist/domain/services/knowledge-extractor.d.ts +54 -0
  199. package/dist/domain/services/knowledge-extractor.d.ts.map +1 -0
  200. package/dist/domain/services/knowledge-extractor.js +247 -0
  201. package/dist/domain/services/knowledge-extractor.js.map +1 -0
  202. package/dist/domain/services/knowledge-graph-builder.d.ts +70 -0
  203. package/dist/domain/services/knowledge-graph-builder.d.ts.map +1 -0
  204. package/dist/domain/services/knowledge-graph-builder.js +268 -0
  205. package/dist/domain/services/knowledge-graph-builder.js.map +1 -0
  206. package/dist/domain/services/knowledge-graph-query.d.ts +69 -0
  207. package/dist/domain/services/knowledge-graph-query.d.ts.map +1 -0
  208. package/dist/domain/services/knowledge-graph-query.js +187 -0
  209. package/dist/domain/services/knowledge-graph-query.js.map +1 -0
  210. package/dist/domain/services/memory-retriever.d.ts +30 -0
  211. package/dist/domain/services/memory-retriever.d.ts.map +1 -0
  212. package/dist/domain/services/memory-retriever.js +82 -0
  213. package/dist/domain/services/memory-retriever.js.map +1 -0
  214. package/dist/domain/services/memory-synthesizer.d.ts +57 -0
  215. package/dist/domain/services/memory-synthesizer.d.ts.map +1 -0
  216. package/dist/domain/services/memory-synthesizer.js +91 -0
  217. package/dist/domain/services/memory-synthesizer.js.map +1 -0
  218. package/dist/domain/services/pattern-extractor.d.ts +108 -0
  219. package/dist/domain/services/pattern-extractor.d.ts.map +1 -0
  220. package/dist/domain/services/pattern-extractor.js +442 -0
  221. package/dist/domain/services/pattern-extractor.js.map +1 -0
  222. package/dist/domain/services/query-intent-classifier.d.ts +16 -0
  223. package/dist/domain/services/query-intent-classifier.d.ts.map +1 -0
  224. package/dist/domain/services/query-intent-classifier.js +140 -0
  225. package/dist/domain/services/query-intent-classifier.js.map +1 -0
  226. package/dist/domain/services/react-loop.d.ts +44 -0
  227. package/dist/domain/services/react-loop.d.ts.map +1 -0
  228. package/dist/domain/services/react-loop.js +110 -0
  229. package/dist/domain/services/react-loop.js.map +1 -0
  230. package/dist/edit.d.ts +0 -12
  231. package/dist/edit.d.ts.map +1 -1
  232. package/dist/edit.js +76 -351
  233. package/dist/edit.js.map +1 -1
  234. package/dist/embed.d.ts +0 -4
  235. package/dist/embed.d.ts.map +1 -1
  236. package/dist/embed.js +100 -174
  237. package/dist/embed.js.map +1 -1
  238. package/dist/error-handler.d.ts +1 -0
  239. package/dist/error-handler.d.ts.map +1 -1
  240. package/dist/error-handler.js +46 -3
  241. package/dist/error-handler.js.map +1 -1
  242. package/dist/index.js +228 -231
  243. package/dist/index.js.map +1 -1
  244. package/dist/infrastructure/ai/cohere-ai-service.d.ts +54 -0
  245. package/dist/infrastructure/ai/cohere-ai-service.d.ts.map +1 -0
  246. package/dist/infrastructure/ai/cohere-ai-service.js +547 -0
  247. package/dist/infrastructure/ai/cohere-ai-service.js.map +1 -0
  248. package/dist/infrastructure/ai/command-r-evaluation.d.ts +42 -0
  249. package/dist/infrastructure/ai/command-r-evaluation.d.ts.map +1 -0
  250. package/dist/infrastructure/ai/command-r-evaluation.js +206 -0
  251. package/dist/infrastructure/ai/command-r-evaluation.js.map +1 -0
  252. package/dist/infrastructure/ai/model-config.d.ts +47 -0
  253. package/dist/infrastructure/ai/model-config.d.ts.map +1 -0
  254. package/dist/infrastructure/ai/model-config.js +84 -0
  255. package/dist/infrastructure/ai/model-config.js.map +1 -0
  256. package/dist/infrastructure/cache/embedding-cache.d.ts +46 -0
  257. package/dist/infrastructure/cache/embedding-cache.d.ts.map +1 -0
  258. package/dist/infrastructure/cache/embedding-cache.js +104 -0
  259. package/dist/infrastructure/cache/embedding-cache.js.map +1 -0
  260. package/dist/infrastructure/chunking/ast-code-chunker.d.ts +12 -0
  261. package/dist/infrastructure/chunking/ast-code-chunker.d.ts.map +1 -0
  262. package/dist/infrastructure/chunking/ast-code-chunker.js +19 -0
  263. package/dist/infrastructure/chunking/ast-code-chunker.js.map +1 -0
  264. package/dist/infrastructure/chunking/code-aware-chunker.d.ts +63 -0
  265. package/dist/infrastructure/chunking/code-aware-chunker.d.ts.map +1 -0
  266. package/dist/infrastructure/chunking/code-aware-chunker.js +397 -0
  267. package/dist/infrastructure/chunking/code-aware-chunker.js.map +1 -0
  268. package/dist/infrastructure/config/config-manager.d.ts +79 -0
  269. package/dist/infrastructure/config/config-manager.d.ts.map +1 -0
  270. package/dist/infrastructure/config/config-manager.js +162 -0
  271. package/dist/infrastructure/config/config-manager.js.map +1 -0
  272. package/dist/infrastructure/cost/cost-tracker.d.ts +90 -0
  273. package/dist/infrastructure/cost/cost-tracker.d.ts.map +1 -0
  274. package/dist/infrastructure/cost/cost-tracker.js +353 -0
  275. package/dist/infrastructure/cost/cost-tracker.js.map +1 -0
  276. package/dist/infrastructure/file-scanner/file-scanner.d.ts +31 -0
  277. package/dist/infrastructure/file-scanner/file-scanner.d.ts.map +1 -0
  278. package/dist/infrastructure/file-scanner/file-scanner.js +106 -0
  279. package/dist/infrastructure/file-scanner/file-scanner.js.map +1 -0
  280. package/dist/infrastructure/governance/nist-ai-rmf.d.ts +107 -0
  281. package/dist/infrastructure/governance/nist-ai-rmf.d.ts.map +1 -0
  282. package/dist/infrastructure/governance/nist-ai-rmf.js +294 -0
  283. package/dist/infrastructure/governance/nist-ai-rmf.js.map +1 -0
  284. package/dist/infrastructure/governance/policy-as-code.d.ts +90 -0
  285. package/dist/infrastructure/governance/policy-as-code.d.ts.map +1 -0
  286. package/dist/infrastructure/governance/policy-as-code.js +244 -0
  287. package/dist/infrastructure/governance/policy-as-code.js.map +1 -0
  288. package/dist/infrastructure/governance/prompt-to-code-lineage.d.ts +138 -0
  289. package/dist/infrastructure/governance/prompt-to-code-lineage.d.ts.map +1 -0
  290. package/dist/infrastructure/governance/prompt-to-code-lineage.js +241 -0
  291. package/dist/infrastructure/governance/prompt-to-code-lineage.js.map +1 -0
  292. package/dist/infrastructure/index.d.ts +7 -0
  293. package/dist/infrastructure/index.d.ts.map +1 -0
  294. package/dist/infrastructure/index.js +7 -0
  295. package/dist/infrastructure/index.js.map +1 -0
  296. package/dist/infrastructure/observability/execution-tracer.d.ts +105 -0
  297. package/dist/infrastructure/observability/execution-tracer.d.ts.map +1 -0
  298. package/dist/infrastructure/observability/execution-tracer.js +190 -0
  299. package/dist/infrastructure/observability/execution-tracer.js.map +1 -0
  300. package/dist/infrastructure/observability/prompt-versioner.d.ts +67 -0
  301. package/dist/infrastructure/observability/prompt-versioner.d.ts.map +1 -0
  302. package/dist/infrastructure/observability/prompt-versioner.js +145 -0
  303. package/dist/infrastructure/observability/prompt-versioner.js.map +1 -0
  304. package/dist/infrastructure/protocols/a2a-metadata.d.ts +278 -0
  305. package/dist/infrastructure/protocols/a2a-metadata.d.ts.map +1 -0
  306. package/dist/infrastructure/protocols/a2a-metadata.js +137 -0
  307. package/dist/infrastructure/protocols/a2a-metadata.js.map +1 -0
  308. package/dist/infrastructure/protocols/a2a-protocol.d.ts +132 -0
  309. package/dist/infrastructure/protocols/a2a-protocol.d.ts.map +1 -0
  310. package/dist/infrastructure/protocols/a2a-protocol.js +314 -0
  311. package/dist/infrastructure/protocols/a2a-protocol.js.map +1 -0
  312. package/dist/infrastructure/protocols/mcp-oauth.d.ts +91 -0
  313. package/dist/infrastructure/protocols/mcp-oauth.d.ts.map +1 -0
  314. package/dist/infrastructure/protocols/mcp-oauth.js +184 -0
  315. package/dist/infrastructure/protocols/mcp-oauth.js.map +1 -0
  316. package/dist/infrastructure/protocols/mcp-server.d.ts +126 -0
  317. package/dist/infrastructure/protocols/mcp-server.d.ts.map +1 -0
  318. package/dist/infrastructure/protocols/mcp-server.js +333 -0
  319. package/dist/infrastructure/protocols/mcp-server.js.map +1 -0
  320. package/dist/infrastructure/protocols/streaming-handler.d.ts +57 -0
  321. package/dist/infrastructure/protocols/streaming-handler.d.ts.map +1 -0
  322. package/dist/infrastructure/protocols/streaming-handler.js +103 -0
  323. package/dist/infrastructure/protocols/streaming-handler.js.map +1 -0
  324. package/dist/infrastructure/security/ai-sast-scanner.d.ts +55 -0
  325. package/dist/infrastructure/security/ai-sast-scanner.d.ts.map +1 -0
  326. package/dist/infrastructure/security/ai-sast-scanner.js +163 -0
  327. package/dist/infrastructure/security/ai-sast-scanner.js.map +1 -0
  328. package/dist/infrastructure/security/docker-sandbox.d.ts +57 -0
  329. package/dist/infrastructure/security/docker-sandbox.d.ts.map +1 -0
  330. package/dist/infrastructure/security/docker-sandbox.js +178 -0
  331. package/dist/infrastructure/security/docker-sandbox.js.map +1 -0
  332. package/dist/infrastructure/security/enhanced-security-gate.d.ts +51 -0
  333. package/dist/infrastructure/security/enhanced-security-gate.d.ts.map +1 -0
  334. package/dist/infrastructure/security/enhanced-security-gate.js +92 -0
  335. package/dist/infrastructure/security/enhanced-security-gate.js.map +1 -0
  336. package/dist/infrastructure/security/input-validator.d.ts +33 -0
  337. package/dist/infrastructure/security/input-validator.d.ts.map +1 -0
  338. package/dist/infrastructure/security/input-validator.js +152 -0
  339. package/dist/infrastructure/security/input-validator.js.map +1 -0
  340. package/dist/infrastructure/security/license-scanner.d.ts +55 -0
  341. package/dist/infrastructure/security/license-scanner.d.ts.map +1 -0
  342. package/dist/infrastructure/security/license-scanner.js +167 -0
  343. package/dist/infrastructure/security/license-scanner.js.map +1 -0
  344. package/dist/infrastructure/security/provider-bias-detector.d.ts +53 -0
  345. package/dist/infrastructure/security/provider-bias-detector.d.ts.map +1 -0
  346. package/dist/infrastructure/security/provider-bias-detector.js +164 -0
  347. package/dist/infrastructure/security/provider-bias-detector.js.map +1 -0
  348. package/dist/infrastructure/security/sandbox-executor.d.ts +34 -0
  349. package/dist/infrastructure/security/sandbox-executor.d.ts.map +1 -0
  350. package/dist/infrastructure/security/sandbox-executor.js +64 -0
  351. package/dist/infrastructure/security/sandbox-executor.js.map +1 -0
  352. package/dist/infrastructure/storage/memory-stream-service.d.ts +47 -0
  353. package/dist/infrastructure/storage/memory-stream-service.d.ts.map +1 -0
  354. package/dist/infrastructure/storage/memory-stream-service.js +204 -0
  355. package/dist/infrastructure/storage/memory-stream-service.js.map +1 -0
  356. package/dist/infrastructure/storage/sqlite-decision-repository.d.ts +29 -0
  357. package/dist/infrastructure/storage/sqlite-decision-repository.d.ts.map +1 -0
  358. package/dist/infrastructure/storage/sqlite-decision-repository.js +232 -0
  359. package/dist/infrastructure/storage/sqlite-decision-repository.js.map +1 -0
  360. package/dist/infrastructure/storage/sqlite-embedding-repository.d.ts +24 -0
  361. package/dist/infrastructure/storage/sqlite-embedding-repository.d.ts.map +1 -0
  362. package/dist/infrastructure/storage/sqlite-embedding-repository.js +162 -0
  363. package/dist/infrastructure/storage/sqlite-embedding-repository.js.map +1 -0
  364. package/dist/infrastructure/storage/sqlite-knowledge-graph-repository.d.ts +41 -0
  365. package/dist/infrastructure/storage/sqlite-knowledge-graph-repository.d.ts.map +1 -0
  366. package/dist/infrastructure/storage/sqlite-knowledge-graph-repository.js +417 -0
  367. package/dist/infrastructure/storage/sqlite-knowledge-graph-repository.js.map +1 -0
  368. package/dist/infrastructure/storage/sqlite-knowledge-preservation-repository.d.ts +29 -0
  369. package/dist/infrastructure/storage/sqlite-knowledge-preservation-repository.d.ts.map +1 -0
  370. package/dist/infrastructure/storage/sqlite-knowledge-preservation-repository.js +230 -0
  371. package/dist/infrastructure/storage/sqlite-knowledge-preservation-repository.js.map +1 -0
  372. package/dist/infrastructure/storage/sqlite-memory-repository.d.ts +40 -0
  373. package/dist/infrastructure/storage/sqlite-memory-repository.d.ts.map +1 -0
  374. package/dist/infrastructure/storage/sqlite-memory-repository.js +229 -0
  375. package/dist/infrastructure/storage/sqlite-memory-repository.js.map +1 -0
  376. package/dist/infrastructure/storage/sqlite-pattern-repository.d.ts +25 -0
  377. package/dist/infrastructure/storage/sqlite-pattern-repository.d.ts.map +1 -0
  378. package/dist/infrastructure/storage/sqlite-pattern-repository.js +249 -0
  379. package/dist/infrastructure/storage/sqlite-pattern-repository.js.map +1 -0
  380. package/dist/infrastructure/ux/appropriate-friction.d.ts +77 -0
  381. package/dist/infrastructure/ux/appropriate-friction.d.ts.map +1 -0
  382. package/dist/infrastructure/ux/appropriate-friction.js +213 -0
  383. package/dist/infrastructure/ux/appropriate-friction.js.map +1 -0
  384. package/dist/infrastructure/ux/bi-directional-learning.d.ts +109 -0
  385. package/dist/infrastructure/ux/bi-directional-learning.d.ts.map +1 -0
  386. package/dist/infrastructure/ux/bi-directional-learning.js +200 -0
  387. package/dist/infrastructure/ux/bi-directional-learning.js.map +1 -0
  388. package/dist/infrastructure/ux/expectation-management.d.ts +65 -0
  389. package/dist/infrastructure/ux/expectation-management.d.ts.map +1 -0
  390. package/dist/infrastructure/ux/expectation-management.js +193 -0
  391. package/dist/infrastructure/ux/expectation-management.js.map +1 -0
  392. package/dist/infrastructure/ux/hitl-validation.d.ts +104 -0
  393. package/dist/infrastructure/ux/hitl-validation.d.ts.map +1 -0
  394. package/dist/infrastructure/ux/hitl-validation.js +211 -0
  395. package/dist/infrastructure/ux/hitl-validation.js.map +1 -0
  396. package/dist/infrastructure/ux/progressive-disclosure.d.ts +84 -0
  397. package/dist/infrastructure/ux/progressive-disclosure.d.ts.map +1 -0
  398. package/dist/infrastructure/ux/progressive-disclosure.js +235 -0
  399. package/dist/infrastructure/ux/progressive-disclosure.js.map +1 -0
  400. package/dist/infrastructure/ux/team-standards.d.ts +94 -0
  401. package/dist/infrastructure/ux/team-standards.d.ts.map +1 -0
  402. package/dist/infrastructure/ux/team-standards.js +196 -0
  403. package/dist/infrastructure/ux/team-standards.js.map +1 -0
  404. package/dist/infrastructure/verification/verification-service.d.ts +12 -0
  405. package/dist/infrastructure/verification/verification-service.d.ts.map +1 -0
  406. package/dist/infrastructure/verification/verification-service.js +47 -0
  407. package/dist/infrastructure/verification/verification-service.js.map +1 -0
  408. package/dist/infrastructure/xai/attention-visualizer.d.ts +73 -0
  409. package/dist/infrastructure/xai/attention-visualizer.d.ts.map +1 -0
  410. package/dist/infrastructure/xai/attention-visualizer.js +174 -0
  411. package/dist/infrastructure/xai/attention-visualizer.js.map +1 -0
  412. package/dist/infrastructure/xai/cot-visualizer.d.ts +105 -0
  413. package/dist/infrastructure/xai/cot-visualizer.d.ts.map +1 -0
  414. package/dist/infrastructure/xai/cot-visualizer.js +239 -0
  415. package/dist/infrastructure/xai/cot-visualizer.js.map +1 -0
  416. package/dist/infrastructure/xai/decision-tree-log.d.ts +104 -0
  417. package/dist/infrastructure/xai/decision-tree-log.d.ts.map +1 -0
  418. package/dist/infrastructure/xai/decision-tree-log.js +216 -0
  419. package/dist/infrastructure/xai/decision-tree-log.js.map +1 -0
  420. package/dist/infrastructure/xai/interactive-xai.d.ts +106 -0
  421. package/dist/infrastructure/xai/interactive-xai.d.ts.map +1 -0
  422. package/dist/infrastructure/xai/interactive-xai.js +262 -0
  423. package/dist/infrastructure/xai/interactive-xai.js.map +1 -0
  424. package/dist/infrastructure/xai/uncertainty-quantifier.d.ts +80 -0
  425. package/dist/infrastructure/xai/uncertainty-quantifier.d.ts.map +1 -0
  426. package/dist/infrastructure/xai/uncertainty-quantifier.js +201 -0
  427. package/dist/infrastructure/xai/uncertainty-quantifier.js.map +1 -0
  428. package/dist/intelligent-retrieval.d.ts.map +1 -1
  429. package/dist/intelligent-retrieval.js +8 -1
  430. package/dist/intelligent-retrieval.js.map +1 -1
  431. package/dist/intent/classifier.d.ts +6 -0
  432. package/dist/intent/classifier.d.ts.map +1 -0
  433. package/dist/intent/classifier.js +2 -0
  434. package/dist/intent/classifier.js.map +1 -0
  435. package/dist/intent/context.d.ts +4 -0
  436. package/dist/intent/context.d.ts.map +1 -0
  437. package/dist/intent/context.js +2 -0
  438. package/dist/intent/context.js.map +1 -0
  439. package/dist/iterative-refinement.d.ts.map +1 -1
  440. package/dist/iterative-refinement.js +20 -3
  441. package/dist/iterative-refinement.js.map +1 -1
  442. package/dist/learning.d.ts.map +1 -1
  443. package/dist/learning.js +1 -2
  444. package/dist/learning.js.map +1 -1
  445. package/dist/monitoring.d.ts.map +1 -1
  446. package/dist/monitoring.js +1 -2
  447. package/dist/monitoring.js.map +1 -1
  448. package/dist/parallel-processor.d.ts +3 -2
  449. package/dist/parallel-processor.d.ts.map +1 -1
  450. package/dist/parallel-processor.js +183 -56
  451. package/dist/parallel-processor.js.map +1 -1
  452. package/dist/presentation/cli/commands/ask-command.d.ts +8 -0
  453. package/dist/presentation/cli/commands/ask-command.d.ts.map +1 -0
  454. package/dist/presentation/cli/commands/ask-command.js +133 -0
  455. package/dist/presentation/cli/commands/ask-command.js.map +1 -0
  456. package/dist/presentation/cli/commands/config-command.d.ts +9 -0
  457. package/dist/presentation/cli/commands/config-command.d.ts.map +1 -0
  458. package/dist/presentation/cli/commands/config-command.js +123 -0
  459. package/dist/presentation/cli/commands/config-command.js.map +1 -0
  460. package/dist/presentation/cli/commands/cost-command.d.ts +8 -0
  461. package/dist/presentation/cli/commands/cost-command.d.ts.map +1 -0
  462. package/dist/presentation/cli/commands/cost-command.js +191 -0
  463. package/dist/presentation/cli/commands/cost-command.js.map +1 -0
  464. package/dist/presentation/cli/commands/decision-command.d.ts +12 -0
  465. package/dist/presentation/cli/commands/decision-command.d.ts.map +1 -0
  466. package/dist/presentation/cli/commands/decision-command.js +207 -0
  467. package/dist/presentation/cli/commands/decision-command.js.map +1 -0
  468. package/dist/presentation/cli/commands/help-command.d.ts +9 -0
  469. package/dist/presentation/cli/commands/help-command.d.ts.map +1 -0
  470. package/dist/presentation/cli/commands/help-command.js +281 -0
  471. package/dist/presentation/cli/commands/help-command.js.map +1 -0
  472. package/dist/presentation/cli/commands/knowledge-command.d.ts +13 -0
  473. package/dist/presentation/cli/commands/knowledge-command.d.ts.map +1 -0
  474. package/dist/presentation/cli/commands/knowledge-command.js +129 -0
  475. package/dist/presentation/cli/commands/knowledge-command.js.map +1 -0
  476. package/dist/presentation/cli/commands/learning-dashboard-command.d.ts +8 -0
  477. package/dist/presentation/cli/commands/learning-dashboard-command.d.ts.map +1 -0
  478. package/dist/presentation/cli/commands/learning-dashboard-command.js +183 -0
  479. package/dist/presentation/cli/commands/learning-dashboard-command.js.map +1 -0
  480. package/dist/presentation/cli/commands/orchestrate-command.d.ts +8 -0
  481. package/dist/presentation/cli/commands/orchestrate-command.d.ts.map +1 -0
  482. package/dist/presentation/cli/commands/orchestrate-command.js +112 -0
  483. package/dist/presentation/cli/commands/orchestrate-command.js.map +1 -0
  484. package/dist/presentation/cli/commands/plan-command.d.ts +8 -0
  485. package/dist/presentation/cli/commands/plan-command.d.ts.map +1 -0
  486. package/dist/presentation/cli/commands/plan-command.js +114 -0
  487. package/dist/presentation/cli/commands/plan-command.js.map +1 -0
  488. package/dist/presentation/cli/commands/react-command.d.ts +8 -0
  489. package/dist/presentation/cli/commands/react-command.d.ts.map +1 -0
  490. package/dist/presentation/cli/commands/react-command.js +99 -0
  491. package/dist/presentation/cli/commands/react-command.js.map +1 -0
  492. package/dist/presentation/cli/commands/setup-command.d.ts +10 -0
  493. package/dist/presentation/cli/commands/setup-command.d.ts.map +1 -0
  494. package/dist/presentation/cli/commands/setup-command.js +231 -0
  495. package/dist/presentation/cli/commands/setup-command.js.map +1 -0
  496. package/dist/presentation/cli/commands/smart-command.d.ts +6 -0
  497. package/dist/presentation/cli/commands/smart-command.d.ts.map +1 -0
  498. package/dist/presentation/cli/commands/smart-command.js +212 -0
  499. package/dist/presentation/cli/commands/smart-command.js.map +1 -0
  500. package/dist/presentation/cli/commands/trace-command.d.ts +8 -0
  501. package/dist/presentation/cli/commands/trace-command.d.ts.map +1 -0
  502. package/dist/presentation/cli/commands/trace-command.js +125 -0
  503. package/dist/presentation/cli/commands/trace-command.js.map +1 -0
  504. package/dist/presentation/cli/commands/undo-command.d.ts +8 -0
  505. package/dist/presentation/cli/commands/undo-command.d.ts.map +1 -0
  506. package/dist/presentation/cli/commands/undo-command.js +141 -0
  507. package/dist/presentation/cli/commands/undo-command.js.map +1 -0
  508. package/dist/presentation/cli/error-display.d.ts +23 -0
  509. package/dist/presentation/cli/error-display.d.ts.map +1 -0
  510. package/dist/presentation/cli/error-display.js +122 -0
  511. package/dist/presentation/cli/error-display.js.map +1 -0
  512. package/dist/refactor.d.ts.map +1 -1
  513. package/dist/refactor.js +2 -4
  514. package/dist/refactor.js.map +1 -1
  515. package/dist/search.d.ts.map +1 -1
  516. package/dist/search.js +2 -63
  517. package/dist/search.js.map +1 -1
  518. package/dist/session.d.ts.map +1 -1
  519. package/dist/session.js +52 -3
  520. package/dist/session.js.map +1 -1
  521. package/dist/testgen.d.ts.map +1 -1
  522. package/dist/testgen.js +1 -2
  523. package/dist/testgen.js.map +1 -1
  524. package/dist/tools/bash.d.ts +53 -0
  525. package/dist/tools/bash.d.ts.map +1 -0
  526. package/dist/tools/bash.js +213 -0
  527. package/dist/tools/bash.js.map +1 -0
  528. package/dist/tools/edit.d.ts +48 -0
  529. package/dist/tools/edit.d.ts.map +1 -0
  530. package/dist/tools/edit.js +235 -0
  531. package/dist/tools/edit.js.map +1 -0
  532. package/dist/tools/executor.d.ts +29 -0
  533. package/dist/tools/executor.d.ts.map +1 -0
  534. package/dist/tools/executor.js +153 -0
  535. package/dist/tools/executor.js.map +1 -0
  536. package/dist/tools/git-tool.d.ts +87 -0
  537. package/dist/tools/git-tool.d.ts.map +1 -0
  538. package/dist/tools/git-tool.js +292 -0
  539. package/dist/tools/git-tool.js.map +1 -0
  540. package/dist/tools/parser.d.ts +33 -0
  541. package/dist/tools/parser.d.ts.map +1 -0
  542. package/dist/tools/parser.js +158 -0
  543. package/dist/tools/parser.js.map +1 -0
  544. package/dist/tools/registry.d.ts +74 -0
  545. package/dist/tools/registry.d.ts.map +1 -0
  546. package/dist/tools/registry.js +302 -0
  547. package/dist/tools/registry.js.map +1 -0
  548. package/dist/tools/search.d.ts +41 -0
  549. package/dist/tools/search.d.ts.map +1 -0
  550. package/dist/tools/search.js +100 -0
  551. package/dist/tools/search.js.map +1 -0
  552. package/dist/ui.d.ts.map +1 -1
  553. package/dist/ui.js +4 -2
  554. package/dist/ui.js.map +1 -1
  555. package/dist/utils/check-api-status.d.ts +12 -0
  556. package/dist/utils/check-api-status.d.ts.map +1 -0
  557. package/dist/utils/check-api-status.js +82 -0
  558. package/dist/utils/check-api-status.js.map +1 -0
  559. package/dist/utils/diff-parser.d.ts +22 -0
  560. package/dist/utils/diff-parser.d.ts.map +1 -0
  561. package/dist/utils/diff-parser.js +160 -0
  562. package/dist/utils/diff-parser.js.map +1 -0
  563. package/dist/utils/logger.d.ts +34 -0
  564. package/dist/utils/logger.d.ts.map +1 -0
  565. package/dist/utils/logger.js +56 -0
  566. package/dist/utils/logger.js.map +1 -0
  567. package/dist/utils/version.d.ts +21 -0
  568. package/dist/utils/version.d.ts.map +1 -0
  569. package/dist/utils/version.js +52 -0
  570. package/dist/utils/version.js.map +1 -0
  571. package/dist/verification/backup.d.ts +30 -0
  572. package/dist/verification/backup.d.ts.map +1 -0
  573. package/dist/verification/backup.js +238 -0
  574. package/dist/verification/backup.js.map +1 -0
  575. package/dist/verification/compiler.d.ts +20 -0
  576. package/dist/verification/compiler.d.ts.map +1 -0
  577. package/dist/verification/compiler.js +228 -0
  578. package/dist/verification/compiler.js.map +1 -0
  579. package/dist/verification/index.d.ts +59 -0
  580. package/dist/verification/index.d.ts.map +1 -0
  581. package/dist/verification/index.js +273 -0
  582. package/dist/verification/index.js.map +1 -0
  583. package/dist/verification/test-runner.d.ts +27 -0
  584. package/dist/verification/test-runner.d.ts.map +1 -0
  585. package/dist/verification/test-runner.js +379 -0
  586. package/dist/verification/test-runner.js.map +1 -0
  587. package/package.json +39 -14
  588. package/ARCHITECTURE.md +0 -240
  589. package/CHANGELOG.md +0 -44
  590. package/CONTRIBUTING.md +0 -171
  591. package/dist/benchmark.d.ts +0 -39
  592. package/dist/benchmark.d.ts.map +0 -1
  593. package/dist/benchmark.js +0 -195
  594. package/dist/benchmark.js.map +0 -1
  595. package/dist/scaffold.d.ts +0 -14
  596. package/dist/scaffold.d.ts.map +0 -1
  597. package/dist/scaffold.js +0 -85
  598. package/dist/scaffold.js.map +0 -1
  599. package/templates/next-page/app/layout.tsx +0 -19
  600. package/templates/next-page/app/page.tsx +0 -10
  601. package/templates/next-page/package.json +0 -22
  602. package/templates/node-api/index.js +0 -57
  603. package/templates/node-api/package.json +0 -13
@@ -0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,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,MAAM,CAAC,EACnE,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,EACvD,aAAa,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,OAAO,GACnD,OAAO,CAAC,eAAe,CAAC;IAmG3B,aAAa,IAAI,eAAe;CAMjC"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Domain Service: ReAct Loop
3
+ * Implements Thought → Action → Observation cycle
4
+ */
5
+ export class ReActLoop {
6
+ maxTurns;
7
+ trajectory = null;
8
+ consecutiveFailures = 0;
9
+ maxConsecutiveFailures = 3;
10
+ recentToolCalls = new Map(); // Track repeated tool calls
11
+ constructor(maxTurns = 20) {
12
+ this.maxTurns = maxTurns;
13
+ }
14
+ /**
15
+ * Execute ReAct loop with infinite loop prevention
16
+ */
17
+ async execute(query, context, generateThought, generateAction, executeAction, isFinalAnswer) {
18
+ this.trajectory = {
19
+ query,
20
+ steps: [],
21
+ success: false,
22
+ };
23
+ this.consecutiveFailures = 0;
24
+ this.recentToolCalls.clear();
25
+ for (let turn = 0; turn < this.maxTurns; turn++) {
26
+ // 1. Generate Thought
27
+ const thought = await generateThought(query, context, this.trajectory);
28
+ // 2. Generate Action
29
+ const action = await generateAction(thought, context);
30
+ // 3. Check for repeated tool calls (infinite loop detection)
31
+ if (action.type === 'tool') {
32
+ const toolKey = `${action.name}:${JSON.stringify(action.parameters || {})}`;
33
+ const callCount = this.recentToolCalls.get(toolKey) || 0;
34
+ if (callCount >= 2) {
35
+ // Same tool called 3+ times with same parameters - likely stuck
36
+ this.trajectory.steps.push({
37
+ thought,
38
+ action,
39
+ observation: {
40
+ result: null,
41
+ success: false,
42
+ error: `Infinite loop detected: Tool "${action.name}" called ${callCount + 1} times with same parameters. Stopping to prevent infinite loop.`,
43
+ },
44
+ timestamp: new Date(),
45
+ });
46
+ this.trajectory.success = false;
47
+ break;
48
+ }
49
+ this.recentToolCalls.set(toolKey, callCount + 1);
50
+ }
51
+ // 4. Execute Action
52
+ const observation = await executeAction(action);
53
+ // 5. Track consecutive failures
54
+ if (!observation.success) {
55
+ this.consecutiveFailures++;
56
+ if (this.consecutiveFailures >= this.maxConsecutiveFailures) {
57
+ // Too many consecutive failures - stop to prevent infinite loop
58
+ this.trajectory.steps.push({
59
+ thought,
60
+ action,
61
+ observation: {
62
+ result: null,
63
+ success: false,
64
+ error: `Too many consecutive failures (${this.consecutiveFailures}). Stopping to prevent infinite loop. Last error: ${observation.error || 'Unknown error'}`,
65
+ },
66
+ timestamp: new Date(),
67
+ });
68
+ this.trajectory.success = false;
69
+ break;
70
+ }
71
+ }
72
+ else {
73
+ // Reset failure counter on success
74
+ this.consecutiveFailures = 0;
75
+ }
76
+ // 6. Record step
77
+ const step = {
78
+ thought,
79
+ action,
80
+ observation,
81
+ timestamp: new Date(),
82
+ };
83
+ this.trajectory.steps.push(step);
84
+ // 7. Check if done
85
+ if (isFinalAnswer(observation)) {
86
+ this.trajectory.finalAnswer = observation.result;
87
+ this.trajectory.success = true;
88
+ break;
89
+ }
90
+ // 8. Update context with observation
91
+ context = { ...context, lastObservation: observation };
92
+ }
93
+ // Check if we hit max turns without success
94
+ if (!this.trajectory.success && this.trajectory.steps.length >= this.maxTurns) {
95
+ const lastStep = this.trajectory.steps[this.trajectory.steps.length - 1];
96
+ if (lastStep && !lastStep.observation.error) {
97
+ // Add error if we hit max turns
98
+ lastStep.observation.error = `Reached maximum turns (${this.maxTurns}) without finding solution.`;
99
+ }
100
+ }
101
+ return this.trajectory;
102
+ }
103
+ getTrajectory() {
104
+ if (!this.trajectory) {
105
+ throw new Error('Trajectory not initialized. Execute loop first.');
106
+ }
107
+ return this.trajectory;
108
+ }
109
+ }
110
+ //# sourceMappingURL=react-loop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-loop.js","sourceRoot":"","sources":["../../../src/domain/services/react-loop.ts"],"names":[],"mappings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
@@ -1,18 +1,6 @@
1
1
  import type { DiffStats, PolicyResult } from './types.js';
2
2
  export declare function parseDiffStats(diffText: string): DiffStats;
3
3
  export declare function applyUnifiedDiff(originalContent: string, diffText: string): string;
4
- /**
5
- * Generate and validate diff without applying (for dry-run)
6
- */
7
- export declare function generateEditDryRun(filepath: string, instruction: string): Promise<{
8
- success: boolean;
9
- diffText?: string;
10
- diffStats?: DiffStats;
11
- policyResult?: PolicyResult;
12
- error?: string;
13
- newContent?: string;
14
- syntaxValid?: boolean;
15
- }>;
16
4
  /**
17
5
  * Legacy function - kept for backward compatibility
18
6
  * Use generateAndApplyEditWithVerification() for new code
@@ -1 +1 @@
1
- {"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../src/edit.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAK1D,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAkC1D;AAED,wBAAgB,gBAAgB,CAAC,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAsClF;AAwSD;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC;IACT,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC,CAyFD;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,S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,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC/B,CAAC,CAyFD"}
package/dist/edit.js CHANGED
@@ -1,11 +1,63 @@
1
- import { readFileSync, writeFileSync, existsSync, unlinkSync } from 'fs';
1
+ import { readFileSync, writeFileSync, existsSync } from 'fs';
2
2
  import { join } from 'path';
3
- import { execSync } from 'child_process';
4
- import { applyPatch, parsePatch } from 'diff';
5
3
  import { generateDiff } from './chat.js';
6
4
  import { checkPolicy } from './policy.js';
7
5
  import { refineTask } from './iterative-refinement.js';
8
- import { updateFileEmbeddings } from './embed.js';
6
+ /**
7
+ * Fix duplicate module.exports or export statements
8
+ */
9
+ function fixDuplicateExports(content) {
10
+ const lines = content.split('\n');
11
+ const result = [];
12
+ let foundModuleExports = false;
13
+ let foundExport = false;
14
+ let lastExportIndex = -1;
15
+ for (let i = 0; i < lines.length; i++) {
16
+ const line = lines[i].trim();
17
+ // Check for module.exports
18
+ if (line.startsWith('module.exports')) {
19
+ if (foundModuleExports) {
20
+ // Skip duplicate - keep the last one
21
+ // Remove previous export from result
22
+ if (lastExportIndex >= 0) {
23
+ result.splice(lastExportIndex, 1);
24
+ }
25
+ lastExportIndex = result.length;
26
+ result.push(lines[i]);
27
+ }
28
+ else {
29
+ foundModuleExports = true;
30
+ lastExportIndex = result.length;
31
+ result.push(lines[i]);
32
+ }
33
+ }
34
+ // Check for ES6 export default
35
+ else if (line.startsWith('export default')) {
36
+ if (foundExport) {
37
+ // Skip duplicate
38
+ if (lastExportIndex >= 0) {
39
+ result.splice(lastExportIndex, 1);
40
+ }
41
+ lastExportIndex = result.length;
42
+ result.push(lines[i]);
43
+ }
44
+ else {
45
+ foundExport = true;
46
+ lastExportIndex = result.length;
47
+ result.push(lines[i]);
48
+ }
49
+ }
50
+ // Check for ES6 export const/function/class
51
+ else if (line.match(/^export\s+(const|function|class|let|var)\s+/)) {
52
+ // These are usually fine (one per line), but check for duplicates
53
+ result.push(lines[i]);
54
+ }
55
+ else {
56
+ result.push(lines[i]);
57
+ }
58
+ }
59
+ return result.join('\n');
60
+ }
9
61
  export function parseDiffStats(diffText) {
10
62
  const lines = diffText.split('\n');
11
63
  let linesAdded = 0;
@@ -43,75 +95,23 @@ export function parseDiffStats(diffText) {
43
95
  return { linesAdded, linesRemoved, filesChanged };
44
96
  }
45
97
  export function applyUnifiedDiff(originalContent, diffText) {
46
- try {
47
- // Use the diff package's applyPatch function for reliable patch application
48
- const patches = parsePatch(diffText);
49
- if (!patches || patches.length === 0) {
50
- // Fallback to original content if no valid patches
51
- console.warn('No patches parsed from diff');
52
- return originalContent;
53
- }
54
- // Apply all patches
55
- let result = originalContent;
56
- for (let i = 0; i < patches.length; i++) {
57
- const patch = patches[i];
58
- const applied = applyPatch(result, patch);
59
- if (applied === false) {
60
- // Patch application failed - try manual as fallback
61
- console.warn(`Patch ${i} failed to apply, using manual fallback`);
62
- const manualResult = applyUnifiedDiffManual(result, diffText);
63
- // If manual also fails, return original
64
- if (manualResult === result) {
65
- console.warn('Manual diff application also failed, returning original content');
66
- return originalContent;
67
- }
68
- result = manualResult;
69
- }
70
- else {
71
- result = Array.isArray(applied) ? applied.join('\n') : String(applied);
72
- }
73
- }
74
- // Post-process to fix duplicate module.exports
75
- return fixDuplicateExports(result);
76
- }
77
- catch (error) {
78
- // If patch application fails, try manual application
79
- console.warn(`Patch application error: ${error instanceof Error ? error.message : String(error)}`);
80
- return applyUnifiedDiffManual(originalContent, diffText);
81
- }
82
- }
83
- /**
84
- * Manual diff application as fallback when applyPatch fails
85
- * More lenient parsing to handle AI-generated diffs
86
- */
87
- function applyUnifiedDiffManual(originalContent, diffText) {
88
- // If diff is empty or invalid, return original
89
- if (!diffText || !diffText.trim()) {
90
- return originalContent;
91
- }
92
98
  const diffLines = diffText.split('\n');
93
99
  const originalLines = originalContent.split('\n');
94
100
  const result = [];
95
101
  let originalIndex = 0;
96
102
  let i = 0;
97
- // Skip header lines (---, +++)
98
- while (i < diffLines.length && (diffLines[i].startsWith('---') || diffLines[i].startsWith('+++'))) {
99
- i++;
100
- }
101
103
  // Find first hunk
102
104
  while (i < diffLines.length && !diffLines[i].startsWith('@@')) {
103
105
  i++;
104
106
  }
105
- if (i >= diffLines.length) {
106
- // No hunks found, return original
107
- return originalContent;
108
- }
109
107
  while (i < diffLines.length) {
110
108
  const line = diffLines[i];
111
109
  if (line.startsWith('@@')) {
110
+ // Hunk header: @@ -start,count +start,count @@
112
111
  const match = line.match(/^@@\s+-(\d+)(?:,(\d+))?\s+\+(\d+)(?:,(\d+))?\s+@@/);
113
112
  if (match) {
114
- const oldStart = parseInt(match[1], 10) - 1; // Convert to 0-based
113
+ const oldStart = parseInt(match[1], 10) - 1; // Convert to 0-based (line numbers are 1-based)
114
+ const oldCount = match[2] ? parseInt(match[2], 10) : 0;
115
115
  // Add lines before this hunk
116
116
  while (originalIndex < oldStart && originalIndex < originalLines.length) {
117
117
  result.push(originalLines[originalIndex]);
@@ -119,25 +119,22 @@ function applyUnifiedDiffManual(originalContent, diffText) {
119
119
  }
120
120
  i++; // Move past hunk header
121
121
  // Process hunk lines
122
+ let removedCount = 0;
122
123
  while (i < diffLines.length) {
123
124
  const hunkLine = diffLines[i];
124
125
  // Check for next hunk
125
126
  if (hunkLine.startsWith('@@')) {
126
127
  break;
127
128
  }
128
- // Skip empty lines
129
- if (hunkLine.trim() === '') {
130
- i++;
131
- continue;
132
- }
133
129
  if (hunkLine.startsWith('+') && !hunkLine.startsWith('+++')) {
134
130
  // Added line
135
131
  result.push(hunkLine.substring(1));
136
132
  i++;
137
133
  }
138
134
  else if (hunkLine.startsWith('-') && !hunkLine.startsWith('---')) {
139
- // Removed line - skip in original
135
+ // Removed line - skip it in original
140
136
  originalIndex++;
137
+ removedCount++;
141
138
  i++;
142
139
  }
143
140
  else if (hunkLine.startsWith(' ')) {
@@ -146,12 +143,24 @@ function applyUnifiedDiffManual(originalContent, diffText) {
146
143
  result.push(originalLines[originalIndex]);
147
144
  }
148
145
  originalIndex++;
146
+ removedCount++;
147
+ i++;
148
+ }
149
+ else if (hunkLine.trim() === '') {
150
+ // Empty line, skip
149
151
  i++;
150
152
  }
151
153
  else {
152
- // Unknown line type - skip
154
+ // Unknown line type, skip
153
155
  i++;
154
156
  }
157
+ // Safety check: if we've processed all expected removed lines, we might be done
158
+ if (oldCount > 0 && removedCount >= oldCount && !diffLines[i]?.startsWith('@@')) {
159
+ // Check if next line is part of this hunk or next
160
+ if (i < diffLines.length && !diffLines[i].startsWith('@@') && !diffLines[i].startsWith('+') && !diffLines[i].startsWith('-') && !diffLines[i].startsWith(' ')) {
161
+ break;
162
+ }
163
+ }
155
164
  }
156
165
  }
157
166
  else {
@@ -167,262 +176,7 @@ function applyUnifiedDiffManual(originalContent, diffText) {
167
176
  result.push(originalLines[originalIndex]);
168
177
  originalIndex++;
169
178
  }
170
- const appliedContent = result.join('\n');
171
- // Only apply post-processing if content actually changed
172
- if (appliedContent === originalContent) {
173
- return originalContent;
174
- }
175
- return fixDuplicateExports(appliedContent);
176
- }
177
- /**
178
- * Validate JavaScript/TypeScript syntax
179
- */
180
- async function validateSyntax(content, ext, filepath) {
181
- if (ext === 'js' || ext === 'jsx') {
182
- // Use node --check for reliable syntax validation
183
- try {
184
- // Write to temp file and check
185
- const tempFile = filepath + '.tmp';
186
- writeFileSync(tempFile, content, 'utf-8');
187
- try {
188
- execSync(`node --check "${tempFile}"`, { stdio: 'pipe' });
189
- // Clean up temp file
190
- if (existsSync(tempFile)) {
191
- unlinkSync(tempFile);
192
- }
193
- return { valid: true };
194
- }
195
- catch (error) {
196
- // Clean up temp file
197
- if (existsSync(tempFile)) {
198
- unlinkSync(tempFile);
199
- }
200
- const errorMsg = error.stderr?.toString() || error.message || 'Unknown syntax error';
201
- return { valid: false, error: errorMsg };
202
- }
203
- }
204
- catch (error) {
205
- // Fallback to Function constructor if node check fails
206
- try {
207
- new Function(content);
208
- return { valid: true };
209
- }
210
- catch (syntaxError) {
211
- return {
212
- valid: false,
213
- error: syntaxError instanceof Error ? syntaxError.message : String(syntaxError),
214
- };
215
- }
216
- }
217
- }
218
- // For TypeScript, use tsc --noEmit
219
- if (ext === 'ts' || ext === 'tsx') {
220
- try {
221
- // Write to temp file and check
222
- const tempFile = filepath + '.tmp';
223
- writeFileSync(tempFile, content, 'utf-8');
224
- try {
225
- // Try to find tsc in node_modules or use npx
226
- execSync(`npx tsc --noEmit --skipLibCheck "${tempFile}" 2>&1`, { stdio: 'pipe' });
227
- // Clean up temp file
228
- if (existsSync(tempFile)) {
229
- unlinkSync(tempFile);
230
- }
231
- return { valid: true };
232
- }
233
- catch (error) {
234
- // Clean up temp file
235
- if (existsSync(tempFile)) {
236
- unlinkSync(tempFile);
237
- }
238
- const errorMsg = error.stderr?.toString() || error.stdout?.toString() || error.message || 'Unknown TypeScript error';
239
- // If tsc is not found, that's okay - just skip validation
240
- if (errorMsg.includes('command not found') || errorMsg.includes('Cannot find module')) {
241
- return { valid: true }; // Skip if tsc not available
242
- }
243
- return { valid: false, error: errorMsg };
244
- }
245
- }
246
- catch (error) {
247
- // If tsc check fails entirely, skip validation
248
- return { valid: true };
249
- }
250
- }
251
- return { valid: true };
252
- }
253
- /**
254
- * Fix duplicate module.exports lines and update exports when functions are renamed
255
- */
256
- function fixDuplicateExports(content) {
257
- const lines = content.split('\n');
258
- const moduleExportsLines = [];
259
- // Find all module.exports lines
260
- for (let i = 0; i < lines.length; i++) {
261
- const line = lines[i].trim();
262
- if (line.startsWith('module.exports') && (line.includes('=') || line.includes('{'))) {
263
- moduleExportsLines.push(i);
264
- }
265
- }
266
- // If we have duplicates, use the LAST one (most recent/newest)
267
- if (moduleExportsLines.length > 1) {
268
- // Get the last export line (this is the new/correct one)
269
- const lastExportIdx = moduleExportsLines[moduleExportsLines.length - 1];
270
- const lastExportLine = lines[lastExportIdx];
271
- // Remove all duplicate lines (including the last one, we'll re-add it)
272
- for (let i = moduleExportsLines.length - 1; i >= 0; i--) {
273
- lines.splice(moduleExportsLines[i], 1);
274
- }
275
- // Insert the last export line at the position where the last duplicate was
276
- // (usually at end of file)
277
- const insertPos = lastExportIdx - (moduleExportsLines.length - 1); // Adjust for removed lines
278
- lines.splice(insertPos, 0, lastExportLine);
279
- }
280
- // Now fix exports: find function definitions and update exports to match
281
- const contentFixed = lines.join('\n');
282
- return updateExportsForRenamedFunctions(contentFixed);
283
- }
284
- /**
285
- * Update module.exports when functions are renamed
286
- * Detects function renames and updates exports accordingly
287
- */
288
- function updateExportsForRenamedFunctions(content) {
289
- const lines = content.split('\n');
290
- // Find all function definitions
291
- const functionDefs = new Map(); // name -> line number
292
- for (let i = 0; i < lines.length; i++) {
293
- const line = lines[i];
294
- // Match: function functionName(...) {
295
- const funcMatch = line.match(/function\s+(\w+)\s*\(/);
296
- if (funcMatch) {
297
- functionDefs.set(funcMatch[1], i);
298
- }
299
- }
300
- // Find module.exports line
301
- for (let i = 0; i < lines.length; i++) {
302
- const line = lines[i];
303
- if (line.trim().startsWith('module.exports') && line.includes('{')) {
304
- // Extract exported names
305
- const exportMatch = line.match(/module\.exports\s*=\s*\{([^}]+)\}/);
306
- if (exportMatch) {
307
- const exportedNames = exportMatch[1].split(',').map(n => n.trim()).filter(n => n);
308
- // Check if any exported name doesn't exist as a function
309
- const missingFunctions = [];
310
- const validExports = [];
311
- for (const exportName of exportedNames) {
312
- if (functionDefs.has(exportName)) {
313
- validExports.push(exportName);
314
- }
315
- else {
316
- missingFunctions.push(exportName);
317
- }
318
- }
319
- // If we have missing functions, try to find renamed versions
320
- // This is a heuristic: if a function was renamed, the old name might still be in exports
321
- if (missingFunctions.length > 0 && validExports.length > 0) {
322
- // Check if there are functions that aren't exported but should be
323
- const allFunctionNames = Array.from(functionDefs.keys());
324
- const missingFromExports = allFunctionNames.filter(name => !exportedNames.includes(name));
325
- // If we have exactly one missing function and one missing export, likely a rename
326
- if (missingFunctions.length === 1 && missingFromExports.length === 1) {
327
- // Replace old name with new name in exports
328
- const oldName = missingFunctions[0];
329
- const newName = missingFromExports[0];
330
- const newExports = exportedNames.map(name => name === oldName ? newName : name);
331
- lines[i] = line.replace(/\{([^}]+)\}/, `{ ${newExports.join(', ')} }`);
332
- }
333
- else {
334
- // Just remove missing functions from exports
335
- lines[i] = line.replace(/\{([^}]+)\}/, `{ ${validExports.join(', ')} }`);
336
- }
337
- }
338
- }
339
- break; // Only process first module.exports
340
- }
341
- }
342
- return lines.join('\n');
343
- }
344
- /**
345
- * Generate and validate diff without applying (for dry-run)
346
- */
347
- export async function generateEditDryRun(filepath, instruction) {
348
- const fullPath = join(process.cwd(), filepath);
349
- if (!existsSync(fullPath)) {
350
- return {
351
- success: false,
352
- error: `File not found: ${filepath}`,
353
- };
354
- }
355
- const originalContent = readFileSync(fullPath, 'utf-8');
356
- // Generate diff
357
- const diffText = await generateDiff(originalContent, instruction, filepath);
358
- if (!diffText || diffText.trim().length === 0) {
359
- return {
360
- success: false,
361
- error: 'No diff generated',
362
- };
363
- }
364
- // Parse diff stats
365
- const diffStats = parseDiffStats(diffText);
366
- // Check policy
367
- const policyResult = checkPolicy(filepath, diffStats);
368
- if (!policyResult.allowed) {
369
- return {
370
- success: false,
371
- diffText,
372
- policyResult,
373
- diffStats,
374
- error: policyResult.reason,
375
- };
376
- }
377
- // Apply diff to get new content (but don't write)
378
- try {
379
- const newContent = applyUnifiedDiff(originalContent, diffText);
380
- // Check if content actually changed
381
- if (newContent === originalContent) {
382
- return {
383
- success: false,
384
- diffText,
385
- diffStats,
386
- policyResult,
387
- error: 'Diff application resulted in no changes. The generated diff may be invalid or incompatible.',
388
- };
389
- }
390
- // Validate syntax (for JS/TS files)
391
- const ext = filepath.split('.').pop()?.toLowerCase();
392
- let syntaxValid = true;
393
- if (ext === 'js' || ext === 'jsx' || ext === 'ts' || ext === 'tsx') {
394
- const syntaxCheck = await validateSyntax(newContent, ext, fullPath);
395
- syntaxValid = syntaxCheck.valid;
396
- if (!syntaxValid) {
397
- return {
398
- success: false,
399
- diffText,
400
- diffStats,
401
- policyResult,
402
- newContent,
403
- syntaxValid: false,
404
- error: `Syntax error in generated code: ${syntaxCheck.error}`,
405
- };
406
- }
407
- }
408
- return {
409
- success: true,
410
- diffText,
411
- diffStats,
412
- policyResult,
413
- newContent,
414
- syntaxValid: true,
415
- };
416
- }
417
- catch (error) {
418
- return {
419
- success: false,
420
- diffText,
421
- diffStats,
422
- policyResult,
423
- error: `Failed to apply diff: ${error instanceof Error ? error.message : String(error)}`,
424
- };
425
- }
179
+ return result.join('\n');
426
180
  }
427
181
  /**
428
182
  * Legacy function - kept for backward compatibility
@@ -460,36 +214,7 @@ export async function generateAndApplyEdit(filepath, instruction) {
460
214
  // Apply diff
461
215
  try {
462
216
  const newContent = applyUnifiedDiff(originalContent, diffText);
463
- // Check if content actually changed
464
- if (newContent === originalContent) {
465
- return {
466
- success: false,
467
- diffStats,
468
- policyResult,
469
- error: 'Diff application resulted in no changes. The generated diff may be invalid or incompatible.',
470
- };
471
- }
472
- // CRITICAL: Validate syntax BEFORE writing (for JS/TS files)
473
- // Never write broken files to disk under any condition
474
- const ext = filepath.split('.').pop()?.toLowerCase();
475
- if (ext === 'js' || ext === 'jsx' || ext === 'ts' || ext === 'tsx') {
476
- const syntaxCheck = await validateSyntax(newContent, ext, fullPath);
477
- if (!syntaxCheck.valid) {
478
- // Syntax invalid - DO NOT WRITE, return error immediately
479
- return {
480
- success: false,
481
- diffStats,
482
- policyResult,
483
- error: `Syntax validation failed. File NOT modified. Error: ${syntaxCheck.error}`,
484
- };
485
- }
486
- }
487
- // Only write if syntax is valid (or not JS/TS)
488
217
  writeFileSync(fullPath, newContent, 'utf-8');
489
- // Update embeddings for this file (async, don't wait)
490
- updateFileEmbeddings(filepath).catch(() => {
491
- // Silently fail - embedding update is optional
492
- });
493
218
  return {
494
219
  success: true,
495
220
  diffStats,