cloving 0.3.19 → 1.0.1

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 (507) hide show
  1. package/{LICENSE.md → LICENSE} +1 -1
  2. package/README.md +475 -182
  3. package/dist/src/authority/budgets.d.ts +12 -0
  4. package/dist/src/authority/budgets.js +42 -0
  5. package/dist/src/authority/commands.d.ts +7 -0
  6. package/dist/src/authority/commands.js +263 -0
  7. package/dist/src/authority/details.d.ts +28 -0
  8. package/dist/src/authority/details.js +33 -0
  9. package/dist/src/authority/dispatch-decision.d.ts +40 -0
  10. package/dist/src/authority/dispatch-decision.js +47 -0
  11. package/dist/src/authority/effect-requests.d.ts +2 -0
  12. package/dist/src/authority/effect-requests.js +139 -0
  13. package/dist/src/authority/effect-results.d.ts +4 -0
  14. package/dist/src/authority/effect-results.js +236 -0
  15. package/dist/src/authority/events.d.ts +2 -0
  16. package/dist/src/authority/events.js +45 -0
  17. package/dist/src/authority/gate-reduction.d.ts +8 -0
  18. package/dist/src/authority/gate-reduction.js +109 -0
  19. package/dist/src/authority/gates.d.ts +48 -0
  20. package/dist/src/authority/gates.js +77 -0
  21. package/dist/src/authority/history-state.d.ts +15 -0
  22. package/dist/src/authority/history-state.js +61 -0
  23. package/dist/src/authority/history.d.ts +13 -0
  24. package/dist/src/authority/history.js +37 -0
  25. package/dist/src/authority/instants.d.ts +3 -0
  26. package/dist/src/authority/instants.js +38 -0
  27. package/dist/src/authority/leases.d.ts +15 -0
  28. package/dist/src/authority/leases.js +113 -0
  29. package/dist/src/authority/operations.d.ts +101 -0
  30. package/dist/src/authority/operations.js +75 -0
  31. package/dist/src/authority/reconciliation.d.ts +27 -0
  32. package/dist/src/authority/reconciliation.js +147 -0
  33. package/dist/src/authority/reducer.d.ts +41 -0
  34. package/dist/src/authority/reducer.js +139 -0
  35. package/dist/src/authority/reduction-state.d.ts +36 -0
  36. package/dist/src/authority/reduction-state.js +68 -0
  37. package/dist/src/authority/reduction.d.ts +6 -0
  38. package/dist/src/authority/reduction.js +160 -0
  39. package/dist/src/authority/status-closure.d.ts +4 -0
  40. package/dist/src/authority/status-closure.js +57 -0
  41. package/dist/src/authority/status-effects.d.ts +17 -0
  42. package/dist/src/authority/status-effects.js +43 -0
  43. package/dist/src/authority/status-input.d.ts +45 -0
  44. package/dist/src/authority/status-input.js +9 -0
  45. package/dist/src/authority/status.d.ts +32 -0
  46. package/dist/src/authority/status.js +256 -0
  47. package/dist/src/authority/stop-sequence.d.ts +37 -0
  48. package/dist/src/authority/stop-sequence.js +91 -0
  49. package/dist/src/authority/transitions.d.ts +63 -0
  50. package/dist/src/authority/transitions.js +122 -0
  51. package/dist/src/broker/actor/adapter-calls.d.ts +13 -0
  52. package/dist/src/broker/actor/adapter-calls.js +34 -0
  53. package/dist/src/broker/actor/adapter-outcomes.d.ts +28 -0
  54. package/dist/src/broker/actor/adapter-outcomes.js +80 -0
  55. package/dist/src/broker/actor/authority-actor.d.ts +25 -0
  56. package/dist/src/broker/actor/authority-actor.js +169 -0
  57. package/dist/src/broker/actor/authority-changes.d.ts +31 -0
  58. package/dist/src/broker/actor/authority-changes.js +46 -0
  59. package/dist/src/broker/actor/authority-connection.d.ts +15 -0
  60. package/dist/src/broker/actor/authority-connection.js +44 -0
  61. package/dist/src/broker/actor/authority-conversion.d.ts +10 -0
  62. package/dist/src/broker/actor/authority-conversion.js +72 -0
  63. package/dist/src/broker/actor/authority-delivery.d.ts +13 -0
  64. package/dist/src/broker/actor/authority-delivery.js +162 -0
  65. package/dist/src/broker/actor/authority-logger.d.ts +2 -0
  66. package/dist/src/broker/actor/authority-logger.js +19 -0
  67. package/dist/src/broker/actor/authority-policy.d.ts +9 -0
  68. package/dist/src/broker/actor/authority-policy.js +11 -0
  69. package/dist/src/broker/actor/authority-queries.d.ts +45 -0
  70. package/dist/src/broker/actor/authority-queries.js +85 -0
  71. package/dist/src/broker/actor/authority-receipts.d.ts +28 -0
  72. package/dist/src/broker/actor/authority-receipts.js +84 -0
  73. package/dist/src/broker/actor/authority-release.d.ts +13 -0
  74. package/dist/src/broker/actor/authority-release.js +69 -0
  75. package/dist/src/broker/actor/authority-runtime.d.ts +60 -0
  76. package/dist/src/broker/actor/authority-runtime.js +204 -0
  77. package/dist/src/broker/actor/authority-session.d.ts +65 -0
  78. package/dist/src/broker/actor/authority-session.js +252 -0
  79. package/dist/src/broker/actor/authority-settings.d.ts +33 -0
  80. package/dist/src/broker/actor/authority-settings.js +63 -0
  81. package/dist/src/broker/actor/authority-upgrades.d.ts +16 -0
  82. package/dist/src/broker/actor/authority-upgrades.js +12 -0
  83. package/dist/src/broker/actor/authority-watchdog.d.ts +14 -0
  84. package/dist/src/broker/actor/authority-watchdog.js +41 -0
  85. package/dist/src/broker/actor/authority.d.ts +14 -0
  86. package/dist/src/broker/actor/authority.js +115 -0
  87. package/dist/src/broker/actor/delivery-intents.d.ts +68 -0
  88. package/dist/src/broker/actor/delivery-intents.js +77 -0
  89. package/dist/src/broker/actor/delivery-plan.d.ts +2 -0
  90. package/dist/src/broker/actor/delivery-plan.js +109 -0
  91. package/dist/src/broker/actor/delivery-results.d.ts +11 -0
  92. package/dist/src/broker/actor/delivery-results.js +63 -0
  93. package/dist/src/broker/actor/effect-delivery.d.ts +19 -0
  94. package/dist/src/broker/actor/effect-delivery.js +118 -0
  95. package/dist/src/broker/actor/effect-plan.d.ts +41 -0
  96. package/dist/src/broker/actor/effect-plan.js +173 -0
  97. package/dist/src/broker/actor/effect-queries.d.ts +27 -0
  98. package/dist/src/broker/actor/effect-queries.js +80 -0
  99. package/dist/src/broker/actor/effect-turn.d.ts +25 -0
  100. package/dist/src/broker/actor/effect-turn.js +84 -0
  101. package/dist/src/broker/actor/pin-check.d.ts +6 -0
  102. package/dist/src/broker/actor/pin-check.js +12 -0
  103. package/dist/src/broker/actor/runtime-parts.d.ts +23 -0
  104. package/dist/src/broker/actor/runtime-parts.js +34 -0
  105. package/dist/src/broker/actor/stop-plan.d.ts +20 -0
  106. package/dist/src/broker/actor/stop-plan.js +46 -0
  107. package/dist/src/broker/actor/stop-turn.d.ts +17 -0
  108. package/dist/src/broker/actor/stop-turn.js +42 -0
  109. package/dist/src/broker/actor/turn-draft.d.ts +31 -0
  110. package/dist/src/broker/actor/turn-draft.js +138 -0
  111. package/dist/src/broker/actor/turn-plan.d.ts +17 -0
  112. package/dist/src/broker/actor/turn-plan.js +136 -0
  113. package/dist/src/broker/actor/turn-refusals.d.ts +8 -0
  114. package/dist/src/broker/actor/turn-refusals.js +35 -0
  115. package/dist/src/broker/actor/turn-staging.d.ts +78 -0
  116. package/dist/src/broker/actor/turn-staging.js +34 -0
  117. package/dist/src/broker/actor/turn-state.d.ts +34 -0
  118. package/dist/src/broker/actor/turn-state.js +208 -0
  119. package/dist/src/broker/authority-admission.d.ts +21 -0
  120. package/dist/src/broker/authority-admission.js +70 -0
  121. package/dist/src/broker/authority-restore.d.ts +30 -0
  122. package/dist/src/broker/authority-restore.js +165 -0
  123. package/dist/src/broker/decision-restore.d.ts +16 -0
  124. package/dist/src/broker/decision-restore.js +158 -0
  125. package/dist/src/broker/decision-upgrade.d.ts +3 -0
  126. package/dist/src/broker/decision-upgrade.js +12 -0
  127. package/dist/src/broker/effect-restore.d.ts +20 -0
  128. package/dist/src/broker/effect-restore.js +111 -0
  129. package/dist/src/broker/effect-upgrade.d.ts +3 -0
  130. package/dist/src/broker/effect-upgrade.js +9 -0
  131. package/dist/src/broker/operation-digest.d.ts +1 -0
  132. package/dist/src/broker/operation-digest.js +4 -0
  133. package/dist/src/broker/socket-address.d.ts +9 -0
  134. package/dist/src/broker/socket-address.js +14 -0
  135. package/dist/src/broker/workflow-pin.d.ts +2 -0
  136. package/dist/src/broker/workflow-pin.js +5 -0
  137. package/dist/src/chats/destination.d.ts +4 -0
  138. package/dist/src/chats/destination.js +94 -0
  139. package/dist/src/chats/import.d.ts +13 -0
  140. package/dist/src/chats/import.js +71 -0
  141. package/dist/src/chats/normalize.d.ts +20 -0
  142. package/dist/src/chats/normalize.js +139 -0
  143. package/dist/src/chats/reader.d.ts +15 -0
  144. package/dist/src/chats/reader.js +87 -0
  145. package/dist/src/cli/arguments.d.ts +23 -0
  146. package/dist/src/cli/arguments.js +154 -0
  147. package/dist/src/cli/client.d.ts +15 -0
  148. package/dist/src/cli/client.js +122 -0
  149. package/dist/src/cli/commands.d.ts +14 -0
  150. package/dist/src/cli/commands.js +253 -0
  151. package/dist/src/cli/main.d.ts +1 -0
  152. package/dist/src/cli/main.js +80 -0
  153. package/dist/src/cli/render.d.ts +8 -0
  154. package/dist/src/cli/render.js +186 -0
  155. package/dist/src/cli/runtime-arguments.d.ts +73 -0
  156. package/dist/src/cli/runtime-arguments.js +248 -0
  157. package/dist/src/cli/runtime-directory.d.ts +4 -0
  158. package/dist/src/cli/runtime-directory.js +25 -0
  159. package/dist/src/cli/toolchain.d.ts +3 -0
  160. package/dist/src/cli/toolchain.js +74 -0
  161. package/dist/src/cli/usage.d.ts +4 -0
  162. package/dist/src/cli/usage.js +124 -0
  163. package/dist/src/cli/validate.d.ts +38 -0
  164. package/dist/src/cli/validate.js +116 -0
  165. package/dist/src/cli/watch-board-view.d.ts +22 -0
  166. package/dist/src/cli/watch-board-view.js +128 -0
  167. package/dist/src/cli/watch-board.d.ts +15 -0
  168. package/dist/src/cli/watch-board.js +174 -0
  169. package/dist/src/cli/watch-element.d.ts +11 -0
  170. package/dist/src/cli/watch-element.js +6 -0
  171. package/dist/src/cli/watch-model.d.ts +29 -0
  172. package/dist/src/cli/watch-model.js +261 -0
  173. package/dist/src/cli/watch-navigation.d.ts +9 -0
  174. package/dist/src/cli/watch-navigation.js +40 -0
  175. package/dist/src/cli/watch-page.d.ts +1 -0
  176. package/dist/src/cli/watch-page.js +272 -0
  177. package/dist/src/cli/watch-paths.d.ts +2 -0
  178. package/dist/src/cli/watch-paths.js +52 -0
  179. package/dist/src/cli/watch-phases.d.ts +7 -0
  180. package/dist/src/cli/watch-phases.js +148 -0
  181. package/dist/src/cli/watch-reads.d.ts +28 -0
  182. package/dist/src/cli/watch-reads.js +244 -0
  183. package/dist/src/cli/watch-render.d.ts +139 -0
  184. package/dist/src/cli/watch-render.js +95 -0
  185. package/dist/src/cli/watch-server.d.ts +10 -0
  186. package/dist/src/cli/watch-server.js +176 -0
  187. package/dist/src/cli/watch-stream.d.ts +11 -0
  188. package/dist/src/cli/watch-stream.js +128 -0
  189. package/dist/src/cli/watch-turn.d.ts +29 -0
  190. package/dist/src/cli/watch-turn.js +130 -0
  191. package/dist/src/cli/watch-view.d.ts +39 -0
  192. package/dist/src/cli/watch-view.js +223 -0
  193. package/dist/src/cli.d.ts +2 -0
  194. package/dist/src/cli.js +62 -0
  195. package/dist/src/daemon/claude-turn.d.ts +28 -0
  196. package/dist/src/daemon/claude-turn.js +135 -0
  197. package/dist/src/daemon/claude-worker.d.ts +26 -0
  198. package/dist/src/daemon/claude-worker.js +224 -0
  199. package/dist/src/daemon/codex-stream.d.ts +4 -0
  200. package/dist/src/daemon/codex-stream.js +113 -0
  201. package/dist/src/daemon/daemon.d.ts +46 -0
  202. package/dist/src/daemon/daemon.js +186 -0
  203. package/dist/src/daemon/delivery-router.d.ts +10 -0
  204. package/dist/src/daemon/delivery-router.js +34 -0
  205. package/dist/src/daemon/github-calls.d.ts +29 -0
  206. package/dist/src/daemon/github-calls.js +127 -0
  207. package/dist/src/daemon/github-issue-methods.d.ts +3 -0
  208. package/dist/src/daemon/github-issue-methods.js +99 -0
  209. package/dist/src/daemon/github-issue-privacy.d.ts +6 -0
  210. package/dist/src/daemon/github-issue-privacy.js +131 -0
  211. package/dist/src/daemon/github-merge.d.ts +18 -0
  212. package/dist/src/daemon/github-merge.js +259 -0
  213. package/dist/src/daemon/github-methods.d.ts +5 -0
  214. package/dist/src/daemon/github-methods.js +198 -0
  215. package/dist/src/daemon/github-operation.d.ts +38 -0
  216. package/dist/src/daemon/github-operation.js +57 -0
  217. package/dist/src/daemon/github-worker.d.ts +17 -0
  218. package/dist/src/daemon/github-worker.js +281 -0
  219. package/dist/src/daemon/host-environment.d.ts +8 -0
  220. package/dist/src/daemon/host-environment.js +14 -0
  221. package/dist/src/daemon/issue-queue.d.ts +9 -0
  222. package/dist/src/daemon/issue-queue.js +163 -0
  223. package/dist/src/daemon/notify-message.d.ts +14 -0
  224. package/dist/src/daemon/notify-message.js +48 -0
  225. package/dist/src/daemon/notify.d.ts +12 -0
  226. package/dist/src/daemon/notify.js +161 -0
  227. package/dist/src/daemon/operation-journal.d.ts +42 -0
  228. package/dist/src/daemon/operation-journal.js +53 -0
  229. package/dist/src/daemon/ticket-registration.d.ts +33 -0
  230. package/dist/src/daemon/ticket-registration.js +177 -0
  231. package/dist/src/daemon/ticket-source.d.ts +17 -0
  232. package/dist/src/daemon/ticket-source.js +36 -0
  233. package/dist/src/daemon/work-tree.d.ts +26 -0
  234. package/dist/src/daemon/work-tree.js +206 -0
  235. package/dist/src/effect-authorization.d.ts +21 -0
  236. package/dist/src/effect-authorization.js +14 -0
  237. package/dist/src/execution-pin.d.ts +4 -0
  238. package/dist/src/execution-pin.js +68 -0
  239. package/dist/src/host/start-delivery.d.ts +41 -0
  240. package/dist/src/host/start-delivery.js +68 -0
  241. package/dist/src/host/step-bridge-host.d.ts +79 -0
  242. package/dist/src/host/step-bridge-host.js +205 -0
  243. package/dist/src/host/step-claims.d.ts +31 -0
  244. package/dist/src/host/step-claims.js +85 -0
  245. package/dist/src/host/world-host.d.ts +21 -0
  246. package/dist/src/host/world-host.js +51 -0
  247. package/dist/src/host/world-reconciliation.d.ts +37 -0
  248. package/dist/src/host/world-reconciliation.js +75 -0
  249. package/dist/src/host/world-runs.d.ts +14 -0
  250. package/dist/src/host/world-runs.js +61 -0
  251. package/dist/src/operation-identity.d.ts +7 -0
  252. package/dist/src/operation-identity.js +59 -0
  253. package/dist/src/protocol.d.ts +35 -0
  254. package/dist/src/protocol.js +64 -0
  255. package/dist/src/resource-files.d.ts +1 -0
  256. package/dist/src/resource-files.js +29 -0
  257. package/dist/src/service/changes.d.ts +11 -0
  258. package/dist/src/service/changes.js +32 -0
  259. package/dist/src/service/decision-handler.d.ts +9 -0
  260. package/dist/src/service/decision-handler.js +233 -0
  261. package/dist/src/service/event-handler.d.ts +10 -0
  262. package/dist/src/service/event-handler.js +70 -0
  263. package/dist/src/service/expiry.d.ts +13 -0
  264. package/dist/src/service/expiry.js +53 -0
  265. package/dist/src/service/gateway.d.ts +21 -0
  266. package/dist/src/service/gateway.js +120 -0
  267. package/dist/src/service/registry.d.ts +40 -0
  268. package/dist/src/service/registry.js +13 -0
  269. package/dist/src/service/replies.d.ts +26 -0
  270. package/dist/src/service/replies.js +56 -0
  271. package/dist/src/service/run-handlers.d.ts +4 -0
  272. package/dist/src/service/run-handlers.js +271 -0
  273. package/dist/src/service/service.d.ts +58 -0
  274. package/dist/src/service/service.js +212 -0
  275. package/dist/src/service/submission-handler.d.ts +4 -0
  276. package/dist/src/service/submission-handler.js +206 -0
  277. package/dist/src/service/transport.d.ts +16 -0
  278. package/dist/src/service/transport.js +141 -0
  279. package/dist/src/service/worker-port.d.ts +85 -0
  280. package/dist/src/service/worker-port.js +126 -0
  281. package/dist/src/step-bridge.d.ts +57 -0
  282. package/dist/src/step-bridge.js +4 -0
  283. package/dist/src/steps/decision-gate.d.ts +2 -0
  284. package/dist/src/steps/decision-gate.js +8 -0
  285. package/dist/src/steps/load-cycle.d.ts +10 -0
  286. package/dist/src/steps/load-cycle.js +11 -0
  287. package/dist/src/steps/protected-effect.d.ts +2 -0
  288. package/dist/src/steps/protected-effect.js +8 -0
  289. package/dist/src/storage/decision-rows.d.ts +54 -0
  290. package/dist/src/storage/decision-rows.js +72 -0
  291. package/dist/src/storage/decision-snapshots.d.ts +17 -0
  292. package/dist/src/storage/decision-snapshots.js +25 -0
  293. package/dist/src/storage/domain-changes.d.ts +48 -0
  294. package/dist/src/storage/domain-changes.js +213 -0
  295. package/dist/src/storage/domain-rows.d.ts +85 -0
  296. package/dist/src/storage/domain-rows.js +129 -0
  297. package/dist/src/storage/domain-schema.d.ts +32 -0
  298. package/dist/src/storage/domain-schema.js +193 -0
  299. package/dist/src/storage/effect-changes.d.ts +5 -0
  300. package/dist/src/storage/effect-changes.js +105 -0
  301. package/dist/src/storage/effect-rows.d.ts +67 -0
  302. package/dist/src/storage/effect-rows.js +74 -0
  303. package/dist/src/storage/effect-schema.d.ts +1 -0
  304. package/dist/src/storage/effect-schema.js +59 -0
  305. package/dist/src/storage/statements.d.ts +9 -0
  306. package/dist/src/storage/statements.js +8 -0
  307. package/dist/src/submission.d.ts +42 -0
  308. package/dist/src/submission.js +71 -0
  309. package/dist/src/turn-profile.d.ts +13 -0
  310. package/dist/src/turn-profile.js +100 -0
  311. package/dist/src/workflow-admission.d.ts +45 -0
  312. package/dist/src/workflow-admission.js +151 -0
  313. package/dist/src/workflow-contracts.d.ts +27 -0
  314. package/dist/src/workflow-contracts.js +88 -0
  315. package/dist/src/workflow-declaration.d.ts +11 -0
  316. package/dist/src/workflow-declaration.js +57 -0
  317. package/dist/src/workflow-resources.d.ts +8 -0
  318. package/dist/src/workflow-resources.js +14 -0
  319. package/dist/src/workflows.d.ts +5 -0
  320. package/dist/src/workflows.js +3 -0
  321. package/dist/tools/compile-workflows.d.ts +1 -0
  322. package/dist/tools/compile-workflows.js +33 -0
  323. package/dist/tools/self-host-processes.d.ts +10 -0
  324. package/dist/tools/self-host-processes.js +151 -0
  325. package/dist/tools/self-host-workflows.d.ts +15 -0
  326. package/dist/tools/self-host-workflows.js +78 -0
  327. package/dist/tools/self-host.d.ts +1 -0
  328. package/dist/tools/self-host.js +261 -0
  329. package/dist/tools/self-update-host.d.ts +6 -0
  330. package/dist/tools/self-update-host.js +41 -0
  331. package/dist/tools/self-update.d.ts +10 -0
  332. package/dist/tools/self-update.js +105 -0
  333. package/dist/tools/workflow-manifest.d.ts +3 -0
  334. package/dist/tools/workflow-manifest.js +34 -0
  335. package/dist/workflows/develop-prd.d.ts +7 -0
  336. package/dist/workflows/develop-prd.js +97 -0
  337. package/dist/workflows/develop-ticket.d.ts +15 -0
  338. package/dist/workflows/develop-ticket.js +301 -0
  339. package/dist/workflows/issue-labels.d.ts +14 -0
  340. package/dist/workflows/issue-labels.js +36 -0
  341. package/package.json +82 -75
  342. package/.DS_Store +0 -0
  343. package/.aider.chat.history.md +0 -16978
  344. package/.aider.input.history +0 -15
  345. package/.aider.tags.cache.v3/cache.db +0 -0
  346. package/.aider.tags.cache.v3/cache.db-shm +0 -0
  347. package/.aider.tags.cache.v3/cache.db-wal +0 -0
  348. package/.cursorrules +0 -77
  349. package/.github/workflows/auto-release.yml +0 -83
  350. package/.github/workflows/ci.yml +0 -32
  351. package/.github/workflows/npm-publish.yml +0 -34
  352. package/.gitignore +0 -67
  353. package/.husky/_/.gitignore +0 -1
  354. package/.husky/_/applypatch-msg +0 -2
  355. package/.husky/_/commit-msg +0 -2
  356. package/.husky/_/h +0 -22
  357. package/.husky/_/husky.sh +0 -9
  358. package/.husky/_/post-applypatch +0 -2
  359. package/.husky/_/post-checkout +0 -2
  360. package/.husky/_/post-commit +0 -2
  361. package/.husky/_/post-merge +0 -2
  362. package/.husky/_/post-rewrite +0 -2
  363. package/.husky/_/pre-applypatch +0 -2
  364. package/.husky/_/pre-auto-gc +0 -2
  365. package/.husky/_/pre-commit +0 -2
  366. package/.husky/_/pre-merge-commit +0 -2
  367. package/.husky/_/pre-push +0 -2
  368. package/.husky/_/pre-rebase +0 -2
  369. package/.husky/_/prepare-commit-msg +0 -2
  370. package/.husky/pre-commit +0 -1
  371. package/.husky/pre-push +0 -1
  372. package/.prettierrc.json +0 -7
  373. package/.tool-versions +0 -2
  374. package/SECURITY.md +0 -15
  375. package/cloving.json +0 -67
  376. package/dist/abstract_gpt/index.js +0 -55
  377. package/dist/cloving_gpt/adapters/Adapter.js +0 -2
  378. package/dist/cloving_gpt/adapters/azureopenai.js +0 -69
  379. package/dist/cloving_gpt/adapters/claude.js +0 -128
  380. package/dist/cloving_gpt/adapters/gemini.js +0 -135
  381. package/dist/cloving_gpt/adapters/gpt4all.js +0 -29
  382. package/dist/cloving_gpt/adapters/index.js +0 -2
  383. package/dist/cloving_gpt/adapters/mistral.js +0 -128
  384. package/dist/cloving_gpt/adapters/ollama.js +0 -128
  385. package/dist/cloving_gpt/adapters/openai.js +0 -100
  386. package/dist/cloving_gpt/index.js +0 -192
  387. package/dist/commands/analyze.js +0 -47
  388. package/dist/commands/chat.js +0 -14
  389. package/dist/commands/check.js +0 -7
  390. package/dist/commands/commit.js +0 -44
  391. package/dist/commands/config.js +0 -167
  392. package/dist/commands/describe.js +0 -235
  393. package/dist/commands/generate/code.js +0 -21
  394. package/dist/commands/generate/commit.js +0 -11
  395. package/dist/commands/generate/context.js +0 -82
  396. package/dist/commands/generate/docs.js +0 -11
  397. package/dist/commands/generate/documentation.js +0 -11
  398. package/dist/commands/generate/fizzbuzz.js +0 -35
  399. package/dist/commands/generate/init.js +0 -15
  400. package/dist/commands/generate/review.js +0 -11
  401. package/dist/commands/generate/sh.js +0 -95
  402. package/dist/commands/generate/shell.js +0 -11
  403. package/dist/commands/generate/unit_tests.js +0 -11
  404. package/dist/commands/init.js +0 -13
  405. package/dist/commands/models.js +0 -22
  406. package/dist/commands/project/build.js +0 -88
  407. package/dist/commands/project/complete.js +0 -12
  408. package/dist/commands/project/init.js +0 -82
  409. package/dist/commands/project/plan.js +0 -108
  410. package/dist/commands/proxy.js +0 -11
  411. package/dist/commands/review.js +0 -50
  412. package/dist/commands/tokens.js +0 -75
  413. package/dist/commands/unit_tests.js +0 -150
  414. package/dist/commands/update.js +0 -7
  415. package/dist/file2.js +0 -4
  416. package/dist/index.js +0 -134
  417. package/dist/managers/BlockManager.js +0 -120
  418. package/dist/managers/ChatManager.js +0 -653
  419. package/dist/managers/ChunkManager.js +0 -32
  420. package/dist/managers/CodeManager.js +0 -185
  421. package/dist/managers/CommitManager.js +0 -64
  422. package/dist/managers/DocsManager.js +0 -88
  423. package/dist/managers/DocumentationManager.js +0 -114
  424. package/dist/managers/InitManager.js +0 -230
  425. package/dist/managers/ProxyManager.js +0 -210
  426. package/dist/managers/ReviewManager.js +0 -131
  427. package/dist/managers/ShellManager.js +0 -163
  428. package/dist/managers/StreamManager.js +0 -308
  429. package/dist/managers/UnitTestManager.js +0 -243
  430. package/dist/managers/src/managers/ProxyManager.js +0 -1
  431. package/dist/newfile.js +0 -2
  432. package/dist/package.json +0 -86
  433. package/dist/utils/command_utils.js +0 -384
  434. package/dist/utils/config_utils.js +0 -249
  435. package/dist/utils/gitUtils.js +0 -42
  436. package/dist/utils/git_utils.js +0 -217
  437. package/dist/utils/modelUtils.js +0 -7
  438. package/dist/utils/model_utils.js +0 -7
  439. package/dist/utils/prompt_utils.js +0 -333
  440. package/dist/utils/prompts/CODEGEN_COULDNT_APPLY.md +0 -5
  441. package/dist/utils/prompts/CODEGEN_EXAMPLES.md +0 -82
  442. package/dist/utils/prompts/CODEGEN_INSTRUCTIONS.md +0 -43
  443. package/dist/utils/prompts/DOCS_INSTRUCTIONS.md +0 -9
  444. package/dist/utils/prompts/INIT_INSTRUCTIONS.md +0 -132
  445. package/dist/utils/prompts/REVIEW_INSTRUCTIONS.md +0 -49
  446. package/dist/utils/prompts/SHELL_INSTRUCTIONS.md +0 -15
  447. package/dist/utils/prompts/SPECIAL_FILES.md +0 -66
  448. package/dist/utils/prompts/index.js +0 -27
  449. package/dist/utils/string_utils.js +0 -505
  450. package/dist/utils/types.js +0 -2
  451. package/jest.config.js +0 -11
  452. package/src/cloving_gpt/adapters/azureopenai.ts +0 -83
  453. package/src/cloving_gpt/adapters/claude.ts +0 -140
  454. package/src/cloving_gpt/adapters/gemini.ts +0 -146
  455. package/src/cloving_gpt/adapters/index.ts +0 -43
  456. package/src/cloving_gpt/adapters/mistral.ts +0 -142
  457. package/src/cloving_gpt/adapters/ollama.ts +0 -136
  458. package/src/cloving_gpt/adapters/openai.ts +0 -113
  459. package/src/cloving_gpt/index.ts +0 -229
  460. package/src/commands/chat.ts +0 -12
  461. package/src/commands/config.ts +0 -192
  462. package/src/commands/generate/code.ts +0 -18
  463. package/src/commands/generate/commit.ts +0 -9
  464. package/src/commands/generate/context.ts +0 -93
  465. package/src/commands/generate/docs.ts +0 -9
  466. package/src/commands/generate/review.ts +0 -9
  467. package/src/commands/generate/shell.ts +0 -9
  468. package/src/commands/generate/unit_tests.ts +0 -9
  469. package/src/commands/init.ts +0 -9
  470. package/src/commands/models.ts +0 -21
  471. package/src/commands/proxy.ts +0 -9
  472. package/src/commands/tokens.ts +0 -82
  473. package/src/index.ts +0 -197
  474. package/src/managers/BlockManager.ts +0 -126
  475. package/src/managers/ChatManager.ts +0 -755
  476. package/src/managers/ChunkManager.ts +0 -31
  477. package/src/managers/CodeManager.ts +0 -226
  478. package/src/managers/CommitManager.ts +0 -71
  479. package/src/managers/DocsManager.ts +0 -101
  480. package/src/managers/InitManager.ts +0 -263
  481. package/src/managers/ProxyManager.ts +0 -240
  482. package/src/managers/ReviewManager.ts +0 -154
  483. package/src/managers/ShellManager.ts +0 -172
  484. package/src/managers/StreamManager.ts +0 -353
  485. package/src/managers/UnitTestManager.ts +0 -293
  486. package/src/utils/config_utils.ts +0 -271
  487. package/src/utils/git_utils.ts +0 -230
  488. package/src/utils/model_utils.ts +0 -3
  489. package/src/utils/prompt_utils.ts +0 -375
  490. package/src/utils/prompts/CODEGEN_COULDNT_APPLY.md +0 -5
  491. package/src/utils/prompts/CODEGEN_EXAMPLES.md +0 -82
  492. package/src/utils/prompts/CODEGEN_INSTRUCTIONS.md +0 -43
  493. package/src/utils/prompts/DOCS_INSTRUCTIONS.md +0 -9
  494. package/src/utils/prompts/INIT_INSTRUCTIONS.md +0 -132
  495. package/src/utils/prompts/REVIEW_INSTRUCTIONS.md +0 -49
  496. package/src/utils/prompts/SHELL_INSTRUCTIONS.md +0 -15
  497. package/src/utils/prompts/SPECIAL_FILES.md +0 -66
  498. package/src/utils/prompts/index.ts +0 -37
  499. package/src/utils/string_utils.ts +0 -552
  500. package/src/utils/types.ts +0 -127
  501. package/tests/commands/generate/unit_tests.test.ts +0 -27
  502. package/tests/utils/git_utils.test.ts +0 -116
  503. package/tests/utils/model_utils.test.ts +0 -27
  504. package/tests/utils/prompt_utils.test.ts +0 -33
  505. package/tests/utils/string_utils.test.ts +0 -560
  506. package/tsconfig.json +0 -14
  507. package/yarn.lock +0 -5823
@@ -1,653 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const copy_paste_1 = __importDefault(require("copy-paste"));
7
- const colors_1 = __importDefault(require("colors"));
8
- const cli_highlight_1 = __importDefault(require("cli-highlight"));
9
- const readline_1 = __importDefault(require("readline"));
10
- const child_process_1 = require("child_process");
11
- const CommitManager_1 = __importDefault(require("./CommitManager"));
12
- const ReviewManager_1 = __importDefault(require("./ReviewManager"));
13
- const string_utils_1 = require("../utils/string_utils");
14
- const config_utils_1 = require("../utils/config_utils");
15
- const prompt_utils_1 = require("../utils/prompt_utils");
16
- const prompts_1 = require("../utils/prompts");
17
- const StreamManager_1 = __importDefault(require("./StreamManager"));
18
- const specialCommands = [
19
- 'save',
20
- 'commit',
21
- 'copy',
22
- 'review',
23
- 'add <file-path>',
24
- 'find <file-name>',
25
- 'rm <pattern>',
26
- 'ls <pattern>',
27
- 'git <command>',
28
- 'help',
29
- 'exit',
30
- ];
31
- class ChatManager extends StreamManager_1.default {
32
- /**
33
- * Creates an instance of ChatManager.
34
- * @param {ClovingGPTOptions} options - Configuration options for the ChatManager.
35
- */
36
- constructor(options) {
37
- super(options);
38
- this.commandHistory = [];
39
- this.historyIndex = -1;
40
- this.multilineInput = '';
41
- this.isMultilineMode = false;
42
- this.isSilent = false;
43
- this.isSilent = options.silent || (0, config_utils_1.getConfig)(options).globalSilent || false;
44
- options.stream = true;
45
- options.silent = true;
46
- this.rl = readline_1.default.createInterface({
47
- input: process.stdin,
48
- output: process.stdout,
49
- prompt: colors_1.default.green.bold('cloving> '),
50
- historySize: 1000,
51
- });
52
- }
53
- /**
54
- * Initializes the ChatManager by loading context files, displaying a welcome message,
55
- * and setting up event listeners.
56
- * @returns {Promise<void>}
57
- */
58
- async initialize() {
59
- await this.checkForLatestVersion();
60
- await this.loadContextFiles();
61
- console.log(`\n🍀 🍀 🍀 ${colors_1.default.bold('Welcome to Cloving REPL')} 🍀 🍀 🍀\n`);
62
- this.displayAvailableCommands();
63
- console.log('\nWhat would you like to do?');
64
- this.setupReadline();
65
- }
66
- displayAvailableCommands() {
67
- console.log(`Type a freeform request or question to interact with your Cloving AI pair programmer.\n`);
68
- console.log('Available special commands:');
69
- console.log(` - ${colors_1.default.yellow(colors_1.default.bold('save'))} Save all the changes from the last response to files`);
70
- console.log(` - ${colors_1.default.yellow(colors_1.default.bold('commit'))} Commit the changes to git with an AI-generated message that you can edit`);
71
- console.log(` - ${colors_1.default.yellow(colors_1.default.bold('copy'))} Copy the last response to clipboard`);
72
- console.log(` - ${colors_1.default.yellow(colors_1.default.bold('review'))} Start a code review`);
73
- console.log(` - ${colors_1.default.yellow(colors_1.default.bold('find <file-name>'))} Find and add files matching the name to the chat context (supports * for glob matching)`);
74
- console.log(` - ${colors_1.default.yellow(colors_1.default.bold('add <file-path>'))} Add a file to the chat context (supports * for glob matching)`);
75
- console.log(` - ${colors_1.default.yellow(colors_1.default.bold('rm <pattern>'))} Remove files from the chat context (supports * for glob matching)`);
76
- console.log(` - ${colors_1.default.yellow(colors_1.default.bold('ls <pattern>'))} List files in the chat context (supports * for glob matching)`);
77
- console.log(` - ${colors_1.default.yellow(colors_1.default.bold('git <command>'))} Run a git command`);
78
- console.log(` - ${colors_1.default.yellow(colors_1.default.bold('help'))} Display this help message`);
79
- console.log(` - ${colors_1.default.yellow(colors_1.default.bold('exit'))} Quit this session`);
80
- }
81
- /**
82
- * Sets up readline and event listeners for the readline interface and process input.
83
- * @private
84
- */
85
- setupReadline() {
86
- this.rl.prompt();
87
- this.rl.on('line', this.handleLine.bind(this));
88
- this.rl.on('close', this.handleClose.bind(this));
89
- process.stdin.on('keypress', this.handleKeypress.bind(this));
90
- }
91
- /**
92
- * Handles each line of input from the user.
93
- * @private
94
- * @param {string} line - The input line from the user.
95
- * @returns {Promise<void>}
96
- */
97
- async handleLine(line) {
98
- if (this.isProcessing) {
99
- return;
100
- }
101
- const trimmedLine = line.trim();
102
- if (this.isPastedCode(trimmedLine)) {
103
- this.multilineInput = trimmedLine;
104
- this.isMultilineMode = true;
105
- await this.handleCommand(this.multilineInput);
106
- this.multilineInput = '';
107
- this.isMultilineMode = false;
108
- return;
109
- }
110
- if (this.handleMultilineInput(trimmedLine)) {
111
- return;
112
- }
113
- if (trimmedLine === '') {
114
- this.displayPrompt();
115
- return;
116
- }
117
- this.updateCommandHistory(trimmedLine);
118
- if (this.handleExitCommand(trimmedLine)) {
119
- return;
120
- }
121
- await this.handleCommand(trimmedLine);
122
- }
123
- handleMultilineInput(line) {
124
- if (this.isMultilineMode) {
125
- if (line === '```') {
126
- this.isMultilineMode = false;
127
- this.handleCommand(this.multilineInput);
128
- this.multilineInput = '';
129
- }
130
- else {
131
- this.multilineInput += line + '\n';
132
- this.rl.prompt();
133
- }
134
- return true;
135
- }
136
- else if (line === '```') {
137
- this.isMultilineMode = true;
138
- this.multilineInput = '';
139
- console.log('Entering multiline mode. Type ``` on a new line to end.\n');
140
- this.rl.prompt();
141
- return true;
142
- }
143
- return false;
144
- }
145
- isPastedCode(line) {
146
- // Check if the line contains multiple lines (indicating a paste)
147
- return line.includes('\n') || line.length > 100;
148
- }
149
- handleExitCommand(command) {
150
- if (command.toLowerCase() === 'exit') {
151
- this.rl.close();
152
- return true;
153
- }
154
- return false;
155
- }
156
- updateCommandHistory(command) {
157
- if (this.commandHistory[0] !== command) {
158
- this.commandHistory.unshift(command);
159
- if (this.commandHistory.length > 1000) {
160
- this.commandHistory.pop();
161
- }
162
- }
163
- this.historyIndex = -1;
164
- }
165
- /**
166
- * Handles various commands entered by the user.
167
- * This function acts as a command router, delegating to specific handlers based on the input.
168
- *
169
- * @private
170
- * @param {string} command - The command entered by the user.
171
- * @returns {Promise<void>}
172
- *
173
- * @description
174
- * Supported commands:
175
- * - 'copy': Copies the last response to clipboard.
176
- * - 'save': Saves changes to files.
177
- * - 'commit': Commits changes to git with an AI-generated message.
178
- * - 'ls': Lists files in the context (equivalent to 'ls *').
179
- * - 'rm': Removes all files from the context (equivalent to 'rm *').
180
- * - 'review': Starts a code review.
181
- * - 'add <file-path>': Adds a file to the context.
182
- * - 'rm <pattern>': Removes files matching the pattern from the context.
183
- * - 'ls <pattern>': Lists files in the context matching the pattern.
184
- * - 'git <command>': Executes a git command.
185
- * - Any other input is processed as a user query to the AI.
186
- */
187
- async handleCommand(command) {
188
- // Check if the command is a single character and map it to the first matching special command
189
- if (command.length === 1) {
190
- const matchingCommand = specialCommands.find((cmd) => cmd.startsWith(command));
191
- if (matchingCommand) {
192
- command = matchingCommand.split(' ')[0]; // Use only the command part without arguments
193
- }
194
- else {
195
- console.log(`No matching command found for '${command}'. Processing as user input.`);
196
- await this.processUserInput(command);
197
- return;
198
- }
199
- }
200
- switch (command) {
201
- case 'help':
202
- this.displayHelp();
203
- break;
204
- case 'copy':
205
- await this.handleCopy();
206
- break;
207
- case 'save':
208
- await this.handleSave();
209
- break;
210
- case 'commit':
211
- await this.handleCommit();
212
- break;
213
- case 'ls':
214
- this.handleList('ls *');
215
- break;
216
- case 'rm':
217
- await this.handleRemove('rm *');
218
- break;
219
- case 'review':
220
- await this.handleReview();
221
- break;
222
- default:
223
- if (this.isAddCommand(command)) {
224
- await this.handleAdd(command);
225
- }
226
- else if (this.isFindCommand(command)) {
227
- await this.handleFind(command);
228
- }
229
- else if (this.isRemoveCommand(command)) {
230
- await this.handleRemove(command);
231
- }
232
- else if (this.isListCommand(command)) {
233
- this.handleList(command);
234
- }
235
- else if (this.isGitCommand(command)) {
236
- this.executeGitCommand(command);
237
- }
238
- else {
239
- await this.processUserInput(command);
240
- }
241
- }
242
- }
243
- isFindCommand(command) {
244
- const parts = command.trim().split(/\s+/);
245
- return parts.length === 2 && parts[0] === 'find';
246
- }
247
- async handleFind(command) {
248
- const fileName = command.slice(5).trim();
249
- if (fileName) {
250
- try {
251
- const foundFiles = await this.findFiles(fileName);
252
- if (foundFiles.length === 0) {
253
- console.log(`No files found matching ${colors_1.default.bold(colors_1.default.red(fileName))}.`);
254
- }
255
- else {
256
- for (const filePath of foundFiles) {
257
- this.contextFiles = await (0, prompt_utils_1.addFileOrDirectoryToContext)(filePath, this.contextFiles, this.options);
258
- const content = this.contextFiles[filePath];
259
- const tokenEstimate = this.estimateTokens(content);
260
- console.log(`\nAdded ${colors_1.default.bold(colors_1.default.green(filePath))} to this chat session's context (${colors_1.default.yellow(`~${tokenEstimate.toLocaleString()} tokens`)})`);
261
- }
262
- const totalTokens = this.calculateTotalTokens();
263
- console.log(colors_1.default.yellow(`\n📊 Total tokens in context now: ${totalTokens.toLocaleString()}\n`));
264
- }
265
- }
266
- catch (error) {
267
- console.error(`Failed to find and add files matching ${colors_1.default.bold(colors_1.default.red(fileName))}:`, error);
268
- }
269
- }
270
- else {
271
- console.log('No file name provided.');
272
- }
273
- this.rl.prompt();
274
- }
275
- async findFiles(fileName) {
276
- const { exec } = require('child_process');
277
- return new Promise((resolve, reject) => {
278
- exec(`find . -name "${fileName}"`, (error, stdout) => {
279
- if (error) {
280
- return reject(error);
281
- }
282
- const files = stdout
283
- .split('\n')
284
- .filter((filePath) => filePath.trim() !== '')
285
- .map((filePath) => (filePath.startsWith('./') ? filePath.slice(2) : filePath));
286
- resolve(files);
287
- });
288
- });
289
- }
290
- displayHelp() {
291
- console.log('');
292
- this.displayAvailableCommands();
293
- console.log('\nFor any other input, I will process it as a request or question.\n');
294
- this.rl.prompt();
295
- }
296
- isAddCommand(command) {
297
- const parts = command.trim().split(/\s+/);
298
- return parts.length === 2 && parts[0] === 'add';
299
- }
300
- async handleAdd(command) {
301
- const filePath = command.slice(4).trim();
302
- if (filePath) {
303
- try {
304
- this.contextFiles = await (0, prompt_utils_1.addFileOrDirectoryToContext)(filePath, this.contextFiles, this.options);
305
- console.log(`\nAdded ${colors_1.default.bold(colors_1.default.green(filePath))} to this chat session's context`);
306
- this.refreshContext();
307
- }
308
- catch (error) {
309
- console.error(`Failed to add ${colors_1.default.bold(colors_1.default.red(filePath))} to this chat session's context:`, error);
310
- }
311
- }
312
- else {
313
- console.log('No file path provided.');
314
- }
315
- this.rl.prompt();
316
- }
317
- isRemoveCommand(command) {
318
- return command.startsWith('rm ');
319
- }
320
- // Function to convert glob-like pattern to a regular expression
321
- globToRegExp(glob) {
322
- const escapedGlob = glob.replace(/[-/\\^$+?.()|[\]{}]/g, '\\$&');
323
- const regexString = escapedGlob.replace(/\*/g, '.*');
324
- return new RegExp(`^${regexString}$`);
325
- }
326
- // Function to filter paths using the pattern
327
- filterPaths(paths, pattern) {
328
- const regex = this.globToRegExp(pattern);
329
- return paths.filter((path) => regex.test(path));
330
- }
331
- async handleRemove(command) {
332
- const pattern = command.slice(3).trim();
333
- if (pattern) {
334
- const matchedFiles = this.filterPaths(Object.keys(this.contextFiles), pattern);
335
- if (matchedFiles.length > 0) {
336
- matchedFiles.forEach((filePath) => {
337
- delete this.contextFiles[filePath];
338
- console.log(`Removed ${colors_1.default.bold(colors_1.default.green(filePath))} from this chat session's context files`);
339
- });
340
- }
341
- else {
342
- console.log(`No files matching pattern "${colors_1.default.bold(pattern)}" found in this chat session's context files, try running ${colors_1.default.yellow('ls')} to see the list of files.`);
343
- }
344
- }
345
- else {
346
- console.log('No pattern provided.');
347
- }
348
- this.rl.prompt();
349
- }
350
- isListCommand(command) {
351
- return command.startsWith('ls ');
352
- }
353
- estimateTokens(text) {
354
- // A simple estimation: 1 token ≈ 4 characters
355
- return Math.ceil(text.length / 4);
356
- }
357
- handleList(command) {
358
- const pattern = command.slice(3).trim();
359
- const fileNames = Object.keys(this.contextFiles);
360
- const matchedFiles = pattern ? this.filterPaths(fileNames, pattern) : fileNames;
361
- if (matchedFiles.length > 0) {
362
- console.log(`\nFiles in the current chat session context:`);
363
- let totalTokens = 0;
364
- matchedFiles.forEach((fileName) => {
365
- const content = this.contextFiles[fileName];
366
- const tokenEstimate = this.estimateTokens(content);
367
- totalTokens += tokenEstimate;
368
- console.log(` - ${colors_1.default.bold(colors_1.default.green(fileName))} (${colors_1.default.yellow(`~${tokenEstimate.toLocaleString()} tokens`)})`);
369
- });
370
- console.log(`\nTotal files: ${matchedFiles.length}`);
371
- console.log(`Total estimated tokens: ${colors_1.default.yellow(totalTokens.toLocaleString())}\n`);
372
- }
373
- else {
374
- console.log('No files currently in context.');
375
- }
376
- this.rl.prompt();
377
- }
378
- async handleCopy() {
379
- const lastResponse = this.chatHistory.filter((msg) => msg.role === 'assistant').pop();
380
- if (lastResponse) {
381
- copy_paste_1.default.copy(lastResponse.content, () => {
382
- console.info('Last response copied to clipboard.');
383
- this.rl.prompt();
384
- });
385
- }
386
- else {
387
- console.error('No response to copy.');
388
- }
389
- }
390
- async handleReview() {
391
- this.options.stream = false;
392
- const reviewManager = new ReviewManager_1.default(this.options);
393
- await reviewManager.generateReview();
394
- this.options.stream = true;
395
- this.rl.prompt();
396
- }
397
- async handleCommit() {
398
- this.options.stream = false;
399
- const commitManager = new CommitManager_1.default(this.options);
400
- await commitManager.generateCommit();
401
- this.options.stream = true;
402
- this.rl.prompt();
403
- }
404
- async handleSave() {
405
- const lastResponse = this.chatHistory
406
- .slice()
407
- .reverse()
408
- .find((msg) => msg.role === 'assistant');
409
- if (lastResponse) {
410
- const currentNewBlocks = (0, string_utils_1.extractCurrentNewBlocks)(lastResponse.content);
411
- if (Object.keys(currentNewBlocks).length > 0) {
412
- await (0, string_utils_1.applyAndSaveCurrentNewBlocks)(currentNewBlocks);
413
- console.info(`\n${colors_1.default.bold('save')} has finished\n`);
414
- this.rl.prompt();
415
- }
416
- else {
417
- console.info('No changes found to save in the last response.');
418
- this.rl.prompt();
419
- }
420
- }
421
- else {
422
- console.error('No response to save files from.');
423
- this.rl.prompt();
424
- }
425
- }
426
- isGitCommand(command) {
427
- return command.split(' ').length <= 3 && command.startsWith('git ');
428
- }
429
- executeGitCommand(command) {
430
- try {
431
- (0, child_process_1.execSync)(command, { stdio: 'inherit' });
432
- }
433
- catch (error) {
434
- console.error('Error running command:', error);
435
- }
436
- this.rl.prompt();
437
- }
438
- /**
439
- * Processes user input by sending it to the AI model and handling the response.
440
- *
441
- * This method manages the interaction with the AI model by:
442
- * 1. Checking if a request is already being processed.
443
- * 2. Initializing the chat history and generating a prompt.
444
- * 3. Streaming the response from the AI model.
445
- * 4. Handling the response stream and updating the chat history.
446
- *
447
- * @param {string} input - The user's input or request to be processed.
448
- * @returns {Promise<void>} - A promise that resolves when the processing is complete.
449
- */
450
- async processUserInput(input) {
451
- if (this.isProcessing) {
452
- console.log('Please wait for the current request to complete.');
453
- return;
454
- }
455
- this.isProcessing = true;
456
- try {
457
- await this.refreshContext();
458
- this.addUserPrompt(this.generatePrompt(input));
459
- if (!this.gpt.silent) {
460
- const fullPrompt = this.chatHistory
461
- .map((m) => {
462
- const content = m.content
463
- .split('\n')
464
- .map((line) => {
465
- if (line.startsWith('###')) {
466
- return colors_1.default.red.bold(line);
467
- }
468
- else if (line.startsWith('##')) {
469
- return colors_1.default.yellow.bold(line);
470
- }
471
- return line;
472
- })
473
- .join('\n');
474
- return m.role === 'user'
475
- ? `${colors_1.default.yellow.bold('## User Prompt')}\n\n${content}`
476
- : `${colors_1.default.green.bold("## 🍀 Cloving's Response 🍀")}\n\n${content}`;
477
- })
478
- .join('\n\n');
479
- // Review the prompt using the REPL
480
- const tokenCount = Math.ceil(fullPrompt.length / 4).toLocaleString();
481
- console.log(`${colors_1.default.yellow.bold('INFORMATION')} The generated prompt is approximately ${tokenCount} tokens long. Would you like to review the prompt before sending it? ${colors_1.default.gray('(Y/n)')}`);
482
- const reviewPrompt = await this.askQuestion('cloving> ');
483
- if (reviewPrompt.startsWith('y') || reviewPrompt === '') {
484
- this.reviewPrompt(fullPrompt);
485
- console.log(`Do you want to proceed with this prompt? ${colors_1.default.gray('(Y/n)')}`);
486
- const confirmPrompt = await this.askQuestion('cloving> ');
487
- if (!confirmPrompt.startsWith('y') && confirmPrompt !== '') {
488
- console.log('Operation cancelled by user.');
489
- this.isProcessing = false;
490
- this.rl.prompt();
491
- return;
492
- }
493
- }
494
- }
495
- const responseStream = await this.gpt.streamText({
496
- prompt: this.prompt,
497
- messages: this.chatHistory,
498
- });
499
- this.handleResponseStream(responseStream);
500
- }
501
- catch (err) {
502
- this.handleError(err);
503
- }
504
- }
505
- askQuestion(prompt) {
506
- return new Promise((resolve) => {
507
- this.rl.question(colors_1.default.green.bold(prompt), (answer) => {
508
- resolve(answer.trim().toLowerCase());
509
- });
510
- });
511
- }
512
- reviewPrompt(fullPrompt) {
513
- console.log(colors_1.default.gray.bold('\n---------------------- PROMPT START ----------------------\n'));
514
- const promptParts = fullPrompt.split('\n```');
515
- const highlightedPrompt = promptParts
516
- .map((part, index) => (index % 2 === 1 ? (0, cli_highlight_1.default)(part, { language: 'typescript' }) : part))
517
- .join('\n```');
518
- console.log(highlightedPrompt);
519
- console.log(colors_1.default.gray.bold('\n---------------------- PROMPT END ----------------------\n'));
520
- }
521
- async finalizeResponse() {
522
- this.addAssistantResponse(this.responseString);
523
- this.isProcessing = false;
524
- process.stdout.write('\b'.repeat(100));
525
- if (this.responseString !== '') {
526
- const currentNewBlocks = (0, string_utils_1.extractCurrentNewBlocks)(this.responseString);
527
- const [canApply, summary] = await (0, string_utils_1.checkBlocksApplicability)(currentNewBlocks);
528
- if (!canApply) {
529
- if (this.retryCount < this.maxRetries) {
530
- console.log(`\n\n${summary}\n\n${colors_1.default.yellow.bold('WARNING')} Some of the provided code blocks could not be automatically applied. Retrying (Attempt ${this.retryCount + 1}/${this.maxRetries})...\n`);
531
- this.retryCount++;
532
- this.processUserInput(`${prompts_1.CODEGEN_COULDNT_APPLY}\n\n${summary}`);
533
- return;
534
- }
535
- else {
536
- console.log(`\n\n${colors_1.default.red.bold('ERROR')} Failed to generate a diff that could be cleanly applied after ${this.maxRetries} attempts. Please review the changes manually and try again.\n`);
537
- this.retryCount = 0; // Reset the retry count for future attempts
538
- }
539
- }
540
- else {
541
- this.retryCount = 0; // Reset the retry count on successful application
542
- }
543
- }
544
- process.stdout.write(`
545
-
546
- You can follow up with another request or:
547
- - type ${colors_1.default.yellow(colors_1.default.bold('"save"'))} to save all the changes to files
548
- - type ${colors_1.default.yellow(colors_1.default.bold('"commit"'))} to commit the changes to git with a AI - generated message
549
- - type ${colors_1.default.yellow(colors_1.default.bold('"copy"'))} to copy the last response to clipboard
550
- - type ${colors_1.default.yellow(colors_1.default.bold('"review"'))} to start a code review
551
- - type ${colors_1.default.yellow(colors_1.default.bold('"add <file-path>"'))} to add a file to the chat context
552
- - type ${colors_1.default.yellow(colors_1.default.bold('"rm <pattern>"'))} to remove files from the chat context
553
- - type ${colors_1.default.yellow(colors_1.default.bold('"ls <pattern>"'))} to list files in the chat context
554
- - type ${colors_1.default.yellow(colors_1.default.bold('"git <command>"'))} to run a git command
555
- - type ${colors_1.default.yellow(colors_1.default.bold('"exit"'))} to quit this session
556
- `);
557
- this.rl.prompt();
558
- }
559
- handleError(error) {
560
- let errorMessage = error.message || 'An error occurred.';
561
- const errorNumber = error.response?.status || 'unknown';
562
- switch (errorNumber) {
563
- case 400:
564
- errorMessage = 'Invalid model or prompt size too large. Try specifying fewer files.';
565
- break;
566
- case 403:
567
- errorMessage = 'Inactive subscription or usage limit reached';
568
- break;
569
- case 429:
570
- errorMessage = 'Rate limit error';
571
- break;
572
- case 500:
573
- errorMessage = 'Internal server error';
574
- break;
575
- }
576
- const statusMessage = error.response?.data?.statusMessage;
577
- console.error(colors_1.default.red(`\nError (${errorNumber}) while submitting the prompt to the AI API\n\n${statusMessage}\n`));
578
- this.isProcessing = false;
579
- this.rl.prompt();
580
- }
581
- /**
582
- * Generates a comprehensive prompt for the AI model.
583
- *
584
- * This function constructs a detailed prompt that includes:
585
- * 1. The user's current request
586
- * 2. Contents of all context files
587
- * 3. Full chat history (excluding the current request)
588
- * 4. The current request repeated at the end
589
- *
590
- * @private
591
- * @param {string} prompt - The user's current request or input.
592
- * @returns {string} A formatted string containing the complete prompt for the AI.
593
- *
594
- * @description
595
- * The generated prompt follows this structure:
596
- * 1. "### Request" section with the current prompt
597
- * 2. Contents of all context files, each prefixed with its file name
598
- * 3. "### Full Chat History Context" section with all previous messages
599
- * 4. "### Current Request" section repeating the current prompt
600
- *
601
- * This structure provides the AI with comprehensive context for generating
602
- * accurate and relevant responses.
603
- */
604
- generatePrompt(prompt) {
605
- return `### Request
606
-
607
- ${prompt}
608
-
609
- ### Note
610
-
611
- Whenever possible, break up the changes into pieces and make sure every change is in its own *CURRENT/NEW* Blocks.
612
- Do not allow empty CURRENT blocks in *CURRENT/NEW* Blocks and if you add content to the CURRENT block, you also have to add the same content to the NEW block.`;
613
- }
614
- handleClose() {
615
- console.log('Goodbye!');
616
- process.exit(0);
617
- }
618
- /**
619
- * Displays the prompt in green and bold.
620
- * This method should be used instead of directly calling this.rl.prompt().
621
- * @private
622
- */
623
- displayPrompt() {
624
- this.rl.setPrompt(colors_1.default.green.bold('cloving> '));
625
- this.rl.prompt();
626
- }
627
- handleKeypress(_, key) {
628
- if (key && (key.name === 'up' || key.name === 'down')) {
629
- if (key.name === 'up' && this.historyIndex < this.commandHistory.length - 1) {
630
- this.historyIndex++;
631
- }
632
- else if (key.name === 'down' && this.historyIndex > -1) {
633
- this.historyIndex--;
634
- }
635
- if (this.historyIndex >= 0) {
636
- this.rl.write(null, { ctrl: true, name: 'u' });
637
- this.rl.write(this.commandHistory[this.historyIndex]);
638
- }
639
- else if (this.historyIndex === -1) {
640
- this.rl.write(null, { ctrl: true, name: 'u' });
641
- }
642
- }
643
- else if (key && key.name === 'tab') {
644
- const line = this.rl.line.trim();
645
- const hits = specialCommands.filter((command) => command.startsWith(line));
646
- if (hits.length > 0) {
647
- this.rl.write(null, { ctrl: true, name: 'u' });
648
- this.rl.write(hits[0]);
649
- }
650
- }
651
- }
652
- }
653
- exports.default = ChatManager;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const events_1 = require("events");
4
- // A chunk is a JSON object with different keys depending on the AI service provider
5
- //
6
- // Some providers produce single response in a single chunk
7
- //
8
- // Others produce multiple responses in a single chunk
9
- //
10
- // This Chunk Manager's job is to buffer the chunks and emit them as a single string
11
- // without automatically clearing the buffer until clearBuffer is called.
12
- // That way, the consumer of the chunk can process it and clear the buffer after
13
- // they have received enough data.
14
- class ChunkManager extends events_1.EventEmitter {
15
- constructor() {
16
- super(...arguments);
17
- this.buffer = '';
18
- }
19
- addChunk(chunk) {
20
- if (!chunk)
21
- return;
22
- this.buffer += chunk;
23
- this.emit('content', this.buffer);
24
- }
25
- clearBuffer(lastChar) {
26
- this.buffer = this.buffer.substring(lastChar);
27
- }
28
- getBuffer() {
29
- return this.buffer;
30
- }
31
- }
32
- exports.default = ChunkManager;