tarsk 0.4.4 → 0.4.6

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 (366) hide show
  1. package/dist/index.js +447375 -37
  2. package/package.json +2 -2
  3. package/dist/agent/agent.error-utils.d.ts +0 -14
  4. package/dist/agent/agent.error-utils.js +0 -52
  5. package/dist/agent/agent.event-transformer.d.ts +0 -55
  6. package/dist/agent/agent.event-transformer.js +0 -175
  7. package/dist/agent/agent.executor.d.ts +0 -26
  8. package/dist/agent/agent.executor.js +0 -286
  9. package/dist/agent/agent.model-resolver.d.ts +0 -22
  10. package/dist/agent/agent.model-resolver.js +0 -67
  11. package/dist/agent/agent.process-manager.d.ts +0 -57
  12. package/dist/agent/agent.process-manager.js +0 -262
  13. package/dist/agent/agent.processing-state-manager.d.ts +0 -74
  14. package/dist/agent/agent.processing-state-manager.js +0 -87
  15. package/dist/agent/agent.prompt-loader.d.ts +0 -16
  16. package/dist/agent/agent.prompt-loader.js +0 -227
  17. package/dist/agent/agent.subagent-executor.d.ts +0 -35
  18. package/dist/agent/agent.subagent-executor.js +0 -135
  19. package/dist/bun/index.d.ts +0 -2
  20. package/dist/bun/index.js +0 -165
  21. package/dist/cli.d.ts +0 -3
  22. package/dist/cli.js +0 -22
  23. package/dist/core/crypto.d.ts +0 -29
  24. package/dist/core/crypto.js +0 -166
  25. package/dist/core/dev-server-cache.d.ts +0 -46
  26. package/dist/core/dev-server-cache.js +0 -59
  27. package/dist/core/env-manager.d.ts +0 -3
  28. package/dist/core/env-manager.js +0 -60
  29. package/dist/core/error-responses.d.ts +0 -61
  30. package/dist/core/error-responses.js +0 -64
  31. package/dist/core/logger.d.ts +0 -10
  32. package/dist/core/logger.js +0 -47
  33. package/dist/core/paths.d.ts +0 -22
  34. package/dist/core/paths.js +0 -26
  35. package/dist/core/random-words.d.ts +0 -18
  36. package/dist/core/random-words.js +0 -135
  37. package/dist/core/response-builder.d.ts +0 -50
  38. package/dist/core/response-builder.js +0 -56
  39. package/dist/core/route-helpers.d.ts +0 -47
  40. package/dist/core/route-helpers.js +0 -54
  41. package/dist/core/run-command-detector.d.ts +0 -26
  42. package/dist/core/run-command-detector.js +0 -98
  43. package/dist/core/stream-helper.d.ts +0 -44
  44. package/dist/core/stream-helper.js +0 -50
  45. package/dist/core/utils.d.ts +0 -43
  46. package/dist/core/utils.js +0 -113
  47. package/dist/core/validation.d.ts +0 -10
  48. package/dist/core/validation.js +0 -20
  49. package/dist/database/database.d.ts +0 -40
  50. package/dist/database/database.encryption.d.ts +0 -33
  51. package/dist/database/database.encryption.js +0 -62
  52. package/dist/database/database.js +0 -480
  53. package/dist/database/database.state.d.ts +0 -52
  54. package/dist/database/database.state.js +0 -119
  55. package/dist/database/database.test-utils.d.ts +0 -22
  56. package/dist/database/database.test-utils.js +0 -39
  57. package/dist/database/database.types.d.ts +0 -3
  58. package/dist/database/database.types.js +0 -2
  59. package/dist/features/agents/agents.manager.d.ts +0 -24
  60. package/dist/features/agents/agents.manager.js +0 -200
  61. package/dist/features/ask-user/ask-user.routes.d.ts +0 -9
  62. package/dist/features/ask-user/ask-user.routes.js +0 -35
  63. package/dist/features/chat/chat-delete.route.d.ts +0 -15
  64. package/dist/features/chat/chat-delete.route.js +0 -36
  65. package/dist/features/chat/chat-post.route.d.ts +0 -11
  66. package/dist/features/chat/chat-post.route.js +0 -270
  67. package/dist/features/chat/chat-stop.route.d.ts +0 -21
  68. package/dist/features/chat/chat-stop.route.js +0 -22
  69. package/dist/features/chat/chat-subscribe.route.d.ts +0 -9
  70. package/dist/features/chat/chat-subscribe.route.js +0 -71
  71. package/dist/features/chat/chat.routes.d.ts +0 -22
  72. package/dist/features/chat/chat.routes.js +0 -29
  73. package/dist/features/conversations/conversations-delete.route.d.ts +0 -16
  74. package/dist/features/conversations/conversations-delete.route.js +0 -34
  75. package/dist/features/conversations/conversations-get-all.route.d.ts +0 -16
  76. package/dist/features/conversations/conversations-get-all.route.js +0 -39
  77. package/dist/features/conversations/conversations-get-by-id.route.d.ts +0 -16
  78. package/dist/features/conversations/conversations-get-by-id.route.js +0 -38
  79. package/dist/features/conversations/conversations-get-deleted.route.d.ts +0 -15
  80. package/dist/features/conversations/conversations-get-deleted.route.js +0 -34
  81. package/dist/features/conversations/conversations-get-messages.route.d.ts +0 -16
  82. package/dist/features/conversations/conversations-get-messages.route.js +0 -49
  83. package/dist/features/conversations/conversations.content.d.ts +0 -28
  84. package/dist/features/conversations/conversations.content.js +0 -142
  85. package/dist/features/conversations/conversations.database.d.ts +0 -108
  86. package/dist/features/conversations/conversations.database.js +0 -373
  87. package/dist/features/conversations/conversations.manager.d.ts +0 -130
  88. package/dist/features/conversations/conversations.manager.js +0 -162
  89. package/dist/features/conversations/conversations.routes.d.ts +0 -21
  90. package/dist/features/conversations/conversations.routes.js +0 -38
  91. package/dist/features/conversations/token-usage.route.d.ts +0 -41
  92. package/dist/features/conversations/token-usage.route.js +0 -419
  93. package/dist/features/git/git-commit.route.d.ts +0 -12
  94. package/dist/features/git/git-commit.route.js +0 -39
  95. package/dist/features/git/git-create-branch.route.d.ts +0 -28
  96. package/dist/features/git/git-create-branch.route.js +0 -119
  97. package/dist/features/git/git-create-pr.route.d.ts +0 -13
  98. package/dist/features/git/git-create-pr.route.js +0 -50
  99. package/dist/features/git/git-create-repo.route.d.ts +0 -14
  100. package/dist/features/git/git-create-repo.route.js +0 -108
  101. package/dist/features/git/git-diff.route.d.ts +0 -30
  102. package/dist/features/git/git-diff.route.js +0 -189
  103. package/dist/features/git/git-fetch.route.d.ts +0 -12
  104. package/dist/features/git/git-fetch.route.js +0 -31
  105. package/dist/features/git/git-generate-commit-message.route.d.ts +0 -12
  106. package/dist/features/git/git-generate-commit-message.route.js +0 -76
  107. package/dist/features/git/git-generate-pr-info.route.d.ts +0 -13
  108. package/dist/features/git/git-generate-pr-info.route.js +0 -147
  109. package/dist/features/git/git-github-status.route.d.ts +0 -16
  110. package/dist/features/git/git-github-status.route.js +0 -68
  111. package/dist/features/git/git-log.route.d.ts +0 -17
  112. package/dist/features/git/git-log.route.js +0 -33
  113. package/dist/features/git/git-pr-status.route.d.ts +0 -15
  114. package/dist/features/git/git-pr-status.route.js +0 -33
  115. package/dist/features/git/git-pull.route.d.ts +0 -12
  116. package/dist/features/git/git-pull.route.js +0 -35
  117. package/dist/features/git/git-push.route.d.ts +0 -12
  118. package/dist/features/git/git-push.route.js +0 -46
  119. package/dist/features/git/git-status-cache.database.d.ts +0 -7
  120. package/dist/features/git/git-status-cache.database.js +0 -53
  121. package/dist/features/git/git-status.route.d.ts +0 -15
  122. package/dist/features/git/git-status.route.js +0 -62
  123. package/dist/features/git/git-sync-branch.route.d.ts +0 -4
  124. package/dist/features/git/git-sync-branch.route.js +0 -208
  125. package/dist/features/git/git-unified-status.route.d.ts +0 -30
  126. package/dist/features/git/git-unified-status.route.js +0 -165
  127. package/dist/features/git/git-username.route.d.ts +0 -3
  128. package/dist/features/git/git-username.route.js +0 -24
  129. package/dist/features/git/git.manager.d.ts +0 -139
  130. package/dist/features/git/git.manager.js +0 -352
  131. package/dist/features/git/git.routes.d.ts +0 -4
  132. package/dist/features/git/git.routes.js +0 -116
  133. package/dist/features/git/git.utils.d.ts +0 -82
  134. package/dist/features/git/git.utils.js +0 -1040
  135. package/dist/features/mcp/mcp.config.d.ts +0 -27
  136. package/dist/features/mcp/mcp.config.js +0 -148
  137. package/dist/features/mcp/mcp.manager.d.ts +0 -61
  138. package/dist/features/mcp/mcp.manager.js +0 -254
  139. package/dist/features/mcp/mcp.popular.json +0 -103
  140. package/dist/features/mcp/mcp.routes.d.ts +0 -13
  141. package/dist/features/mcp/mcp.routes.js +0 -159
  142. package/dist/features/mcp/mcp.types.d.ts +0 -80
  143. package/dist/features/mcp/mcp.types.js +0 -8
  144. package/dist/features/metadata/metadata.manager.d.ts +0 -126
  145. package/dist/features/metadata/metadata.manager.js +0 -423
  146. package/dist/features/models/model-info-aihubmix.d.ts +0 -25
  147. package/dist/features/models/model-info-aihubmix.js +0 -117
  148. package/dist/features/models/model-info-openrouter.d.ts +0 -25
  149. package/dist/features/models/model-info-openrouter.js +0 -104
  150. package/dist/features/models/model-info.d.ts +0 -37
  151. package/dist/features/models/model-info.js +0 -39
  152. package/dist/features/models/models-catalog.d.ts +0 -49
  153. package/dist/features/models/models-catalog.js +0 -80
  154. package/dist/features/models/models-catalog.route.d.ts +0 -43
  155. package/dist/features/models/models-catalog.route.js +0 -15
  156. package/dist/features/models/models-get-available.route.d.ts +0 -36
  157. package/dist/features/models/models-get-available.route.js +0 -66
  158. package/dist/features/models/models-get-enabled.route.d.ts +0 -33
  159. package/dist/features/models/models-get-enabled.route.js +0 -45
  160. package/dist/features/models/models-get-model-info.route.d.ts +0 -31
  161. package/dist/features/models/models-get-model-info.route.js +0 -84
  162. package/dist/features/models/models-model-disable.route.d.ts +0 -15
  163. package/dist/features/models/models-model-disable.route.js +0 -20
  164. package/dist/features/models/models-model-enable.route.d.ts +0 -13
  165. package/dist/features/models/models-model-enable.route.js +0 -20
  166. package/dist/features/models/models-provider-refresh.route.d.ts +0 -17
  167. package/dist/features/models/models-provider-refresh.route.js +0 -20
  168. package/dist/features/models/models.manager.d.ts +0 -58
  169. package/dist/features/models/models.manager.js +0 -138
  170. package/dist/features/models/models.routes.d.ts +0 -18
  171. package/dist/features/models/models.routes.js +0 -83
  172. package/dist/features/models/open-router-models.d.ts +0 -38
  173. package/dist/features/models/open-router-models.js +0 -73
  174. package/dist/features/models/openai-models.d.ts +0 -63
  175. package/dist/features/models/openai-models.js +0 -150
  176. package/dist/features/onboarding/onboarding-get-git-check.route.d.ts +0 -11
  177. package/dist/features/onboarding/onboarding-get-git-check.route.js +0 -28
  178. package/dist/features/onboarding/onboarding-get-status.route.d.ts +0 -12
  179. package/dist/features/onboarding/onboarding-get-status.route.js +0 -15
  180. package/dist/features/onboarding/onboarding-post-complete.route.d.ts +0 -12
  181. package/dist/features/onboarding/onboarding-post-complete.route.js +0 -15
  182. package/dist/features/onboarding/onboarding-post-reset.route.d.ts +0 -12
  183. package/dist/features/onboarding/onboarding-post-reset.route.js +0 -15
  184. package/dist/features/onboarding/onboarding.routes.d.ts +0 -18
  185. package/dist/features/onboarding/onboarding.routes.js +0 -28
  186. package/dist/features/project-todos/project-todos.database.d.ts +0 -38
  187. package/dist/features/project-todos/project-todos.database.js +0 -91
  188. package/dist/features/project-todos/project-todos.routes.d.ts +0 -4
  189. package/dist/features/project-todos/project-todos.routes.js +0 -94
  190. package/dist/features/projects/projects-ai-files.route.d.ts +0 -148
  191. package/dist/features/projects/projects-ai-files.route.js +0 -425
  192. package/dist/features/projects/projects-commands.route.d.ts +0 -27
  193. package/dist/features/projects/projects-commands.route.js +0 -39
  194. package/dist/features/projects/projects-create.route.d.ts +0 -19
  195. package/dist/features/projects/projects-create.route.js +0 -37
  196. package/dist/features/projects/projects-delete.route.d.ts +0 -24
  197. package/dist/features/projects/projects-delete.route.js +0 -34
  198. package/dist/features/projects/projects-get.route.d.ts +0 -47
  199. package/dist/features/projects/projects-get.route.js +0 -36
  200. package/dist/features/projects/projects-list.route.d.ts +0 -58
  201. package/dist/features/projects/projects-list.route.js +0 -59
  202. package/dist/features/projects/projects-open-folder.route.d.ts +0 -10
  203. package/dist/features/projects/projects-open-folder.route.js +0 -11
  204. package/dist/features/projects/projects-open.route.d.ts +0 -26
  205. package/dist/features/projects/projects-open.route.js +0 -49
  206. package/dist/features/projects/projects-package-scripts.route.d.ts +0 -15
  207. package/dist/features/projects/projects-package-scripts.route.js +0 -96
  208. package/dist/features/projects/projects-run-command.route.d.ts +0 -8
  209. package/dist/features/projects/projects-run-command.route.js +0 -21
  210. package/dist/features/projects/projects-run.route.d.ts +0 -51
  211. package/dist/features/projects/projects-run.route.js +0 -74
  212. package/dist/features/projects/projects-update.route.d.ts +0 -24
  213. package/dist/features/projects/projects-update.route.js +0 -81
  214. package/dist/features/projects/projects.creator.d.ts +0 -33
  215. package/dist/features/projects/projects.creator.js +0 -555
  216. package/dist/features/projects/projects.database.d.ts +0 -61
  217. package/dist/features/projects/projects.database.js +0 -212
  218. package/dist/features/projects/projects.manager.d.ts +0 -291
  219. package/dist/features/projects/projects.manager.js +0 -426
  220. package/dist/features/projects/projects.open-with.d.ts +0 -27
  221. package/dist/features/projects/projects.open-with.js +0 -156
  222. package/dist/features/projects/projects.routes.d.ts +0 -20
  223. package/dist/features/projects/projects.routes.js +0 -255
  224. package/dist/features/projects/terminal-session-manager.d.ts +0 -55
  225. package/dist/features/projects/terminal-session-manager.js +0 -90
  226. package/dist/features/providers/provider-resolver.d.ts +0 -13
  227. package/dist/features/providers/provider-resolver.js +0 -22
  228. package/dist/features/providers/providers-get-credits.route.d.ts +0 -15
  229. package/dist/features/providers/providers-get-credits.route.js +0 -51
  230. package/dist/features/providers/providers-get.route.d.ts +0 -16
  231. package/dist/features/providers/providers-get.route.js +0 -32
  232. package/dist/features/providers/providers-open-external.route.d.ts +0 -15
  233. package/dist/features/providers/providers-open-external.route.js +0 -49
  234. package/dist/features/providers/providers-post-bulk-keys.route.d.ts +0 -14
  235. package/dist/features/providers/providers-post-bulk-keys.route.js +0 -31
  236. package/dist/features/providers/providers-post-keys.route.d.ts +0 -14
  237. package/dist/features/providers/providers-post-keys.route.js +0 -25
  238. package/dist/features/providers/providers.routes.d.ts +0 -19
  239. package/dist/features/providers/providers.routes.js +0 -31
  240. package/dist/features/rules/rules-post.route.d.ts +0 -43
  241. package/dist/features/rules/rules-post.route.js +0 -89
  242. package/dist/features/rules/rules.manager.d.ts +0 -36
  243. package/dist/features/rules/rules.manager.js +0 -203
  244. package/dist/features/rules/rules.routes.d.ts +0 -12
  245. package/dist/features/rules/rules.routes.js +0 -13
  246. package/dist/features/run/run-get-running.route.d.ts +0 -15
  247. package/dist/features/run/run-get-running.route.js +0 -21
  248. package/dist/features/run/run-post-start.route.d.ts +0 -8
  249. package/dist/features/run/run-post-start.route.js +0 -21
  250. package/dist/features/run/run-post-stop.route.d.ts +0 -15
  251. package/dist/features/run/run-post-stop.route.js +0 -24
  252. package/dist/features/run/run-post-suggest.route.d.ts +0 -15
  253. package/dist/features/run/run-post-suggest.route.js +0 -21
  254. package/dist/features/run/run-put-command.route.d.ts +0 -15
  255. package/dist/features/run/run-put-command.route.js +0 -24
  256. package/dist/features/run/run.routes.d.ts +0 -19
  257. package/dist/features/run/run.routes.js +0 -31
  258. package/dist/features/scaffold/index.d.ts +0 -7
  259. package/dist/features/scaffold/index.js +0 -5
  260. package/dist/features/scaffold/scaffold-get-templates.route.d.ts +0 -27
  261. package/dist/features/scaffold/scaffold-get-templates.route.js +0 -17
  262. package/dist/features/scaffold/scaffold-post.route.d.ts +0 -8
  263. package/dist/features/scaffold/scaffold-post.route.js +0 -30
  264. package/dist/features/scaffold/scaffold.routes.d.ts +0 -10
  265. package/dist/features/scaffold/scaffold.routes.js +0 -16
  266. package/dist/features/scaffold/scaffold.runner.d.ts +0 -48
  267. package/dist/features/scaffold/scaffold.runner.js +0 -475
  268. package/dist/features/scaffold/scaffold.types.d.ts +0 -26
  269. package/dist/features/scaffold/scaffold.types.js +0 -5
  270. package/dist/features/skills/skills.activation.d.ts +0 -31
  271. package/dist/features/skills/skills.activation.js +0 -155
  272. package/dist/features/skills/skills.manager.d.ts +0 -35
  273. package/dist/features/skills/skills.manager.js +0 -251
  274. package/dist/features/slash-commands/slash-commands-delete.route.d.ts +0 -23
  275. package/dist/features/slash-commands/slash-commands-delete.route.js +0 -36
  276. package/dist/features/slash-commands/slash-commands-get.route.d.ts +0 -53
  277. package/dist/features/slash-commands/slash-commands-get.route.js +0 -54
  278. package/dist/features/slash-commands/slash-commands-post.route.d.ts +0 -39
  279. package/dist/features/slash-commands/slash-commands-post.route.js +0 -70
  280. package/dist/features/slash-commands/slash-commands-put.route.d.ts +0 -23
  281. package/dist/features/slash-commands/slash-commands-put.route.js +0 -36
  282. package/dist/features/slash-commands/slash-commands.manager.d.ts +0 -46
  283. package/dist/features/slash-commands/slash-commands.manager.js +0 -265
  284. package/dist/features/slash-commands/slash-commands.routes.d.ts +0 -13
  285. package/dist/features/slash-commands/slash-commands.routes.js +0 -20
  286. package/dist/features/threads/threads-ai-files.route.d.ts +0 -153
  287. package/dist/features/threads/threads-ai-files.route.js +0 -287
  288. package/dist/features/threads/threads-conversation-folder-path.route.d.ts +0 -14
  289. package/dist/features/threads/threads-conversation-folder-path.route.js +0 -23
  290. package/dist/features/threads/threads-create.route.d.ts +0 -22
  291. package/dist/features/threads/threads-create.route.js +0 -60
  292. package/dist/features/threads/threads-delete.route.d.ts +0 -25
  293. package/dist/features/threads/threads-delete.route.js +0 -35
  294. package/dist/features/threads/threads-files.route.d.ts +0 -15
  295. package/dist/features/threads/threads-files.route.js +0 -20
  296. package/dist/features/threads/threads-fix-comments.route.d.ts +0 -26
  297. package/dist/features/threads/threads-fix-comments.route.js +0 -45
  298. package/dist/features/threads/threads-get.route.d.ts +0 -30
  299. package/dist/features/threads/threads-get.route.js +0 -38
  300. package/dist/features/threads/threads-list.route.d.ts +0 -56
  301. package/dist/features/threads/threads-list.route.js +0 -58
  302. package/dist/features/threads/threads-messages.route.d.ts +0 -28
  303. package/dist/features/threads/threads-messages.route.js +0 -110
  304. package/dist/features/threads/threads-open.route.d.ts +0 -26
  305. package/dist/features/threads/threads-open.route.js +0 -62
  306. package/dist/features/threads/threads-select.route.d.ts +0 -25
  307. package/dist/features/threads/threads-select.route.js +0 -35
  308. package/dist/features/threads/threads-update.route.d.ts +0 -15
  309. package/dist/features/threads/threads-update.route.js +0 -30
  310. package/dist/features/threads/threads.database.d.ts +0 -68
  311. package/dist/features/threads/threads.database.js +0 -215
  312. package/dist/features/threads/threads.manager.d.ts +0 -204
  313. package/dist/features/threads/threads.manager.js +0 -505
  314. package/dist/features/threads/threads.routes.d.ts +0 -20
  315. package/dist/features/threads/threads.routes.js +0 -230
  316. package/dist/features/todos/todos.database.d.ts +0 -14
  317. package/dist/features/todos/todos.database.js +0 -31
  318. package/dist/features/updates/updates.routes.d.ts +0 -13
  319. package/dist/features/updates/updates.routes.js +0 -40
  320. package/dist/index.d.ts +0 -3
  321. package/dist/project-analyzer.d.ts +0 -26
  322. package/dist/project-analyzer.js +0 -307
  323. package/dist/server.d.ts +0 -12
  324. package/dist/server.js +0 -142
  325. package/dist/tools/agent-tool.d.ts +0 -49
  326. package/dist/tools/agent-tool.js +0 -131
  327. package/dist/tools/ask-user.d.ts +0 -25
  328. package/dist/tools/ask-user.js +0 -74
  329. package/dist/tools/ast-grep.d.ts +0 -28
  330. package/dist/tools/ast-grep.js +0 -273
  331. package/dist/tools/bash.d.ts +0 -33
  332. package/dist/tools/bash.js +0 -186
  333. package/dist/tools/edit-diff.d.ts +0 -24
  334. package/dist/tools/edit-diff.js +0 -136
  335. package/dist/tools/edit.d.ts +0 -28
  336. package/dist/tools/edit.js +0 -78
  337. package/dist/tools/find.d.ts +0 -31
  338. package/dist/tools/find.js +0 -117
  339. package/dist/tools/grep.d.ts +0 -37
  340. package/dist/tools/grep.js +0 -231
  341. package/dist/tools/index.d.ts +0 -93
  342. package/dist/tools/index.js +0 -110
  343. package/dist/tools/ls.d.ts +0 -31
  344. package/dist/tools/ls.js +0 -108
  345. package/dist/tools/mcp-tools.d.ts +0 -31
  346. package/dist/tools/mcp-tools.js +0 -59
  347. package/dist/tools/path-utils.d.ts +0 -14
  348. package/dist/tools/path-utils.js +0 -87
  349. package/dist/tools/read.d.ts +0 -27
  350. package/dist/tools/read.js +0 -86
  351. package/dist/tools/resolve-bin.d.ts +0 -5
  352. package/dist/tools/resolve-bin.js +0 -28
  353. package/dist/tools/shell.d.ts +0 -7
  354. package/dist/tools/shell.js +0 -143
  355. package/dist/tools/skill-reference-tool.d.ts +0 -30
  356. package/dist/tools/skill-reference-tool.js +0 -171
  357. package/dist/tools/skill-tool.d.ts +0 -33
  358. package/dist/tools/skill-tool.js +0 -213
  359. package/dist/tools/todo.d.ts +0 -20
  360. package/dist/tools/todo.js +0 -168
  361. package/dist/tools/tool-helpers.d.ts +0 -78
  362. package/dist/tools/tool-helpers.js +0 -109
  363. package/dist/tools/truncate.d.ts +0 -31
  364. package/dist/tools/truncate.js +0 -164
  365. package/dist/tools/write.d.ts +0 -21
  366. package/dist/tools/write.js +0 -65
@@ -1,39 +0,0 @@
1
- /**
2
- * Test Database Utilities
3
- *
4
- * Provides in-memory SQLite database for testing using libsql-js
5
- * for compatibility with Node test environment.
6
- */
7
- import { createClient } from "@libsql/client";
8
- import { initializeSchema } from './database.js';
9
- /**
10
- * Initialize database schema with all required tables for testing
11
- * @param db libsql-js database instance
12
- */
13
- async function initializeTestSchema(db) {
14
- await initializeSchema(db);
15
- }
16
- /**
17
- * Create an in-memory database for testing
18
- * @returns SQLite database instance compatible with libsql-js API
19
- */
20
- export async function createTestDatabase() {
21
- const db = createClient({
22
- url: ":memory:",
23
- });
24
- await initializeTestSchema(db);
25
- return db;
26
- }
27
- /**
28
- * Mock the database module for testing
29
- * @returns Mock database functions
30
- */
31
- export async function createMockDatabase() {
32
- const db = await createTestDatabase();
33
- return {
34
- initializeDatabase: () => db,
35
- getDatabase: () => db,
36
- getDatabasePath: () => ":memory:",
37
- };
38
- }
39
- //# sourceMappingURL=database.test-utils.js.map
@@ -1,3 +0,0 @@
1
- import { Client } from "@libsql/client";
2
- export type Database = Client;
3
- //# sourceMappingURL=database.types.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=database.types.js.map
@@ -1,24 +0,0 @@
1
- /**
2
- * Agent Manager
3
- *
4
- * Loads and manages agent definitions from AGENT.md files with frontmatter.
5
- * Agents can be stored in:
6
- * - Project-specific: ./.agents/agents/ (relative to thread path)
7
- * - Global: ~/.agents/agents/
8
- *
9
- * Project agents override global ones with the same name.
10
- */
11
- import type { AgentDefinition } from "@tarsk/shared";
12
- /**
13
- * AgentsManager handles loading and validating agent definitions
14
- */
15
- export declare class AgentsManager {
16
- /**
17
- * Load all available agent definitions for a given thread.
18
- * Project agents override global ones with the same name.
19
- */
20
- loadAgents(threadPath: string): Promise<AgentDefinition[]>;
21
- private loadAgentsFromDir;
22
- getAgent(name: string, threadPath: string): Promise<AgentDefinition | null>;
23
- }
24
- //# sourceMappingURL=agents.manager.d.ts.map
@@ -1,200 +0,0 @@
1
- /**
2
- * Agent Manager
3
- *
4
- * Loads and manages agent definitions from AGENT.md files with frontmatter.
5
- * Agents can be stored in:
6
- * - Project-specific: ./.agents/agents/ (relative to thread path)
7
- * - Global: ~/.agents/agents/
8
- *
9
- * Project agents override global ones with the same name.
10
- */
11
- import { readdir, readFile } from "fs/promises";
12
- import { join } from "path";
13
- import { existsSync } from "fs";
14
- import { homedir } from "os";
15
- /**
16
- * Parse frontmatter from AGENT.md content.
17
- * Returns { metadata, content } where content is the body after frontmatter.
18
- */
19
- function parseFrontmatter(markdown) {
20
- const lines = markdown.split("\n");
21
- if (lines[0]?.trim() !== "---") {
22
- return { metadata: {}, content: markdown.trim() };
23
- }
24
- let endIndex = -1;
25
- for (let i = 1; i < lines.length; i++) {
26
- if (lines[i]?.trim() === "---") {
27
- endIndex = i;
28
- break;
29
- }
30
- }
31
- if (endIndex === -1) {
32
- return { metadata: {}, content: markdown.trim() };
33
- }
34
- const frontmatterLines = lines.slice(1, endIndex);
35
- const metadata = {};
36
- for (const line of frontmatterLines) {
37
- const colonIndex = line.indexOf(":");
38
- if (colonIndex === -1)
39
- continue;
40
- const key = line.slice(0, colonIndex).trim();
41
- const value = line.slice(colonIndex + 1).trim();
42
- if (key === "name") {
43
- metadata.name = value;
44
- }
45
- else if (key === "description") {
46
- metadata.description = value;
47
- }
48
- else if (key === "tools") {
49
- metadata.tools = value;
50
- }
51
- else if (key === "agents") {
52
- // Parse comma or space separated list, strip brackets if present
53
- const cleaned = value.replace(/[[\]]/g, "");
54
- metadata.agents = cleaned
55
- .split(/[,\s]+/)
56
- .map((s) => s.trim())
57
- .filter(Boolean);
58
- }
59
- else if (key === "user-invocable") {
60
- metadata.userInvocable = value.toLowerCase() !== "false";
61
- }
62
- else if (key === "disable-model-invocation") {
63
- metadata.disableModelInvocation = value.toLowerCase() === "true";
64
- }
65
- else if (key === "model") {
66
- metadata.model = value;
67
- }
68
- else if (key === "provider") {
69
- metadata.provider = value;
70
- }
71
- }
72
- const content = lines
73
- .slice(endIndex + 1)
74
- .join("\n")
75
- .trim();
76
- return { metadata, content };
77
- }
78
- /**
79
- * Validate agent name format — same rules as skill names.
80
- * 1-64 chars, lowercase alphanumeric + hyphens, no leading/trailing/consecutive hyphens.
81
- */
82
- function validateAgentName(name) {
83
- if (!name || name.length === 0 || name.length > 64)
84
- return false;
85
- if (!/^[a-z0-9-]+$/.test(name))
86
- return false;
87
- if (name.startsWith("-") || name.endsWith("-"))
88
- return false;
89
- if (name.includes("--"))
90
- return false;
91
- return true;
92
- }
93
- function validateDescription(description) {
94
- return !!description && description.length > 0 && description.length <= 1024;
95
- }
96
- function getGlobalAgentsDir() {
97
- return join(homedir(), ".agents", "agents");
98
- }
99
- function getProjectAgentsDir(threadPath) {
100
- return join(threadPath, ".agents", "agents");
101
- }
102
- /**
103
- * AgentsManager handles loading and validating agent definitions
104
- */
105
- export class AgentsManager {
106
- /**
107
- * Load all available agent definitions for a given thread.
108
- * Project agents override global ones with the same name.
109
- */
110
- async loadAgents(threadPath) {
111
- const agents = new Map();
112
- const globalDir = getGlobalAgentsDir();
113
- if (existsSync(globalDir)) {
114
- const globalAgents = await this.loadAgentsFromDir(globalDir, "global");
115
- for (const agent of globalAgents) {
116
- agents.set(agent.name, agent);
117
- }
118
- }
119
- const projectDir = getProjectAgentsDir(threadPath);
120
- if (existsSync(projectDir)) {
121
- const projectAgents = await this.loadAgentsFromDir(projectDir, "project");
122
- for (const agent of projectAgents) {
123
- agents.set(agent.name, agent);
124
- }
125
- }
126
- return Array.from(agents.values());
127
- }
128
- async loadAgentsFromDir(dir, scope) {
129
- const agents = [];
130
- try {
131
- const entries = await readdir(dir, { withFileTypes: true });
132
- for (const entry of entries) {
133
- if (!entry.isDirectory())
134
- continue;
135
- const agentDirName = entry.name;
136
- const agentPath = join(dir, agentDirName);
137
- const agentFilePath = join(agentPath, "AGENT.md");
138
- if (!existsSync(agentFilePath)) {
139
- console.warn(`[agents] Skipping agent directory ${agentDirName}: AGENT.md not found`);
140
- continue;
141
- }
142
- try {
143
- const fileContent = await readFile(agentFilePath, "utf-8");
144
- const { metadata, content } = parseFrontmatter(fileContent);
145
- if (!metadata.name) {
146
- console.warn(`[agents] Skipping agent in ${agentDirName}: missing 'name' in frontmatter`);
147
- continue;
148
- }
149
- if (!metadata.description) {
150
- console.warn(`[agents] Skipping agent in ${agentDirName}: missing 'description' in frontmatter`);
151
- continue;
152
- }
153
- if (!validateAgentName(metadata.name)) {
154
- console.warn(`[agents] Skipping agent in ${agentDirName}: invalid name '${metadata.name}'. ` +
155
- `Must be 1-64 chars, lowercase alphanumeric + hyphens.`);
156
- continue;
157
- }
158
- if (!validateDescription(metadata.description)) {
159
- console.warn(`[agents] Skipping agent in ${agentDirName}: description must be 1-1024 characters`);
160
- continue;
161
- }
162
- if (metadata.name !== agentDirName) {
163
- console.warn(`[agents] Skipping agent in ${agentDirName}: directory name must match frontmatter name '${metadata.name}'`);
164
- continue;
165
- }
166
- const agent = {
167
- name: metadata.name,
168
- description: metadata.description,
169
- scope,
170
- agentPath,
171
- userInvocable: metadata.userInvocable ?? true,
172
- disableModelInvocation: metadata.disableModelInvocation ?? false,
173
- systemPrompt: content,
174
- };
175
- if (metadata.tools)
176
- agent.tools = metadata.tools;
177
- if (metadata.agents)
178
- agent.agents = metadata.agents;
179
- if (metadata.model)
180
- agent.model = metadata.model;
181
- if (metadata.provider)
182
- agent.provider = metadata.provider;
183
- agents.push(agent);
184
- }
185
- catch (error) {
186
- console.error(`[agents] Failed to load agent from ${agentDirName}:`, error);
187
- }
188
- }
189
- }
190
- catch (error) {
191
- console.error(`[agents] Failed to load agents from ${dir}:`, error);
192
- }
193
- return agents;
194
- }
195
- async getAgent(name, threadPath) {
196
- const agents = await this.loadAgents(threadPath);
197
- return agents.find((a) => a.name === name) ?? null;
198
- }
199
- }
200
- //# sourceMappingURL=agents.manager.js.map
@@ -1,9 +0,0 @@
1
- /**
2
- * Ask-user routes for the REST API
3
- *
4
- * Handles user responses to agent questions:
5
- * - POST /api/ask-user/respond - Submit an answer to a pending question
6
- */
7
- import { Hono } from "hono";
8
- export declare function createAskUserRoutes(): Hono;
9
- //# sourceMappingURL=ask-user.routes.d.ts.map
@@ -1,35 +0,0 @@
1
- /**
2
- * Ask-user routes for the REST API
3
- *
4
- * Handles user responses to agent questions:
5
- * - POST /api/ask-user/respond - Submit an answer to a pending question
6
- */
7
- import { Hono } from "hono";
8
- import { submitAnswer } from "../../tools/ask-user.js";
9
- import { errorResponse } from "../../core/route-helpers.js";
10
- import { ErrorCodes } from "../../core/error-responses.js";
11
- export function createAskUserRoutes() {
12
- const router = new Hono();
13
- router.post("/respond", async (c) => {
14
- try {
15
- const body = await c.req.json();
16
- const { toolCallId, answer } = body;
17
- if (!toolCallId || typeof toolCallId !== "string") {
18
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "toolCallId is required and must be a string", 400);
19
- }
20
- if (answer === undefined || answer === null || typeof answer !== "string") {
21
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "answer is required and must be a string", 400);
22
- }
23
- const resolved = submitAnswer(toolCallId, answer);
24
- if (!resolved) {
25
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "No pending question found for this toolCallId", 404);
26
- }
27
- return c.json({ success: true });
28
- }
29
- catch (error) {
30
- return errorResponse(c, ErrorCodes.REQUEST_PARSE_ERROR, "Failed to parse request body", 400, error instanceof Error ? error.message : String(error));
31
- }
32
- });
33
- return router;
34
- }
35
- //# sourceMappingURL=ask-user.routes.js.map
@@ -1,15 +0,0 @@
1
- /**
2
- * DELETE /api/chat/:threadId
3
- * Start a new conversation (generates new conversation ID) and deletes all todos for the thread
4
- */
5
- import type { Context } from "hono";
6
- import type { ThreadManager } from "../threads/threads.manager.js";
7
- export declare function deleteChat(c: Context, threadManager: ThreadManager): Promise<(Response & import("hono").TypedResponse<{
8
- error: {
9
- code: string;
10
- message: string;
11
- details?: import("hono/utils/types").JSONValue | undefined;
12
- timestamp: string;
13
- };
14
- }, any, "json">) | (Response & import("hono").TypedResponse<import("hono/utils/types").JSONValue, any, "json">)>;
15
- //# sourceMappingURL=chat-delete.route.d.ts.map
@@ -1,36 +0,0 @@
1
- /**
2
- * DELETE /api/chat/:threadId
3
- * Start a new conversation (generates new conversation ID) and deletes all todos for the thread
4
- */
5
- import { randomUUID } from "crypto";
6
- import { errorResponse, successResponse } from "../../core/route-helpers.js";
7
- import { ErrorCodes } from "../../core/error-responses.js";
8
- import { getDatabase } from "../../database/database.js";
9
- export async function deleteChat(c, threadManager) {
10
- try {
11
- const threadId = c.req.param("threadId");
12
- if (!threadId || typeof threadId !== "string") {
13
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "threadId is required and must be a string", 400);
14
- }
15
- // Get thread metadata
16
- const thread = await threadManager.getThread(threadId);
17
- if (!thread) {
18
- return errorResponse(c, ErrorCodes.THREAD_NOT_FOUND, `Thread not found: ${threadId}`, 404);
19
- }
20
- // Delete all todos for this thread
21
- const db = await getDatabase();
22
- await db.execute({
23
- sql: "DELETE FROM todos WHERE threadId = ?",
24
- args: [threadId],
25
- });
26
- // Generate a new conversation ID
27
- const newConversationId = randomUUID();
28
- // Update thread with new conversation ID
29
- await threadManager.updateThread(threadId, { currentConversationId: newConversationId });
30
- return successResponse(c, { message: "New conversation started", conversationId: newConversationId }, 200);
31
- }
32
- catch (error) {
33
- return errorResponse(c, ErrorCodes.NEW_CONVERSATION_ERROR, "Failed to start new conversation", 500, error instanceof Error ? error.message : String(error));
34
- }
35
- }
36
- //# sourceMappingURL=chat-delete.route.js.map
@@ -1,11 +0,0 @@
1
- /**
2
- * POST /api/chat
3
- * Send a message to the agent
4
- */
5
- import type { Context } from "hono";
6
- import type { ThreadManager } from "../threads/threads.manager.js";
7
- import type { AgentExecutor } from "../../agent/agent.executor.js";
8
- import type { ConversationManager } from "../conversations/conversations.manager.js";
9
- import type { ProcessingStateManager } from "../../agent/agent.processing-state-manager.js";
10
- export declare function postChatMessage(c: Context, threadManager: ThreadManager, agentExecutor: AgentExecutor, conversationManager: ConversationManager, processingStateManager: ProcessingStateManager): Promise<Response>;
11
- //# sourceMappingURL=chat-post.route.d.ts.map
@@ -1,270 +0,0 @@
1
- /**
2
- * POST /api/chat
3
- * Send a message to the agent
4
- */
5
- import { randomUUID } from "crypto";
6
- import { SkillManager } from "../skills/skills.manager.js";
7
- import { activateSkills } from "../skills/skills.activation.js";
8
- import { AgentsManager } from "../agents/agents.manager.js";
9
- import { delay } from "../../core/utils.js";
10
- import { streamAsyncGenerator } from "../../core/stream-helper.js";
11
- import { extractAssistantContent, formatConversationContext, isToolLikeContent, } from "../conversations/conversations.content.js";
12
- import { errorResponse } from "../../core/route-helpers.js";
13
- import { ErrorCodes } from "../../core/error-responses.js";
14
- import { readFile, unlink } from "fs/promises";
15
- import { join } from "path";
16
- import { getDatabase } from "../../database/database.js";
17
- import { clearWorkingByThreadId, getTodoByThreadId, updateTodo, } from "../project-todos/project-todos.database.js";
18
- import { invalidateGitStatusCache } from "../git/git-status-cache.database.js";
19
- export async function postChatMessage(c, threadManager, agentExecutor, conversationManager, processingStateManager) {
20
- try {
21
- const body = await c.req.json();
22
- const { threadId, content, model: baseModel, provider, attachments, planMode } = body;
23
- // Prepend provider name (lowercased) to the model if provider is provided
24
- let model = baseModel;
25
- if (provider && typeof provider === "string") {
26
- const providerPrefix = provider.toLowerCase();
27
- // Only prepend if the model doesn't already start with this provider prefix
28
- if (!model.startsWith(providerPrefix + "/")) {
29
- model = `${providerPrefix}/${model}`;
30
- }
31
- }
32
- // Validate required fields
33
- if (!threadId || typeof threadId !== "string") {
34
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "threadId is required and must be a string", 400);
35
- }
36
- if (!content || typeof content !== "string") {
37
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "content is required and must be a string", 400);
38
- }
39
- if (!model || typeof model !== "string") {
40
- return errorResponse(c, ErrorCodes.INVALID_REQUEST, "model is required and must be a string", 400);
41
- }
42
- console.log(`[chat] User message (thread: ${threadId}): ${content}`);
43
- // Get thread metadata to build execution context
44
- const thread = await threadManager.getThread(threadId);
45
- if (!thread) {
46
- return errorResponse(c, ErrorCodes.THREAD_NOT_FOUND, `Thread not found: ${threadId}`, 404);
47
- }
48
- // Capture thread path for use in generators
49
- const threadPath = thread.path;
50
- // Check if this is a replay request
51
- if (content.trim().toLowerCase() === "replay") {
52
- console.log("[ChatRoute] Replay request detected");
53
- // Get conversation ID for replay
54
- const conversationId = thread.currentConversationId;
55
- if (!conversationId) {
56
- return errorResponse(c, ErrorCodes.NO_CONVERSATION, "No active conversation found to replay", 404);
57
- }
58
- // Get the last message from conversation history
59
- const lastMessages = await conversationManager.getLastMessages(threadPath, conversationId, 1);
60
- if (lastMessages.length === 0) {
61
- return errorResponse(c, ErrorCodes.NO_HISTORY, "No previous conversation found to replay", 404);
62
- }
63
- const lastMessage = lastMessages[0];
64
- // Check if message has a completed response
65
- if (!lastMessage.response) {
66
- return errorResponse(c, ErrorCodes.NO_RESPONSE, "Previous message has no completed response to replay", 404);
67
- }
68
- console.log("[ChatRoute] Replaying message:", {
69
- messageId: lastMessage.id,
70
- timestamp: lastMessage.timestamp,
71
- eventCount: lastMessage.response.events.length,
72
- });
73
- // Extract response to ensure TypeScript narrowing
74
- const response = lastMessage.response;
75
- // Create a generator for replay events
76
- async function* replayGenerator() {
77
- // First, send a replay indicator event
78
- const replayEvent = {
79
- type: "message",
80
- role: "system",
81
- content: `🔄 Replaying previous conversation from ${lastMessage.timestamp}`,
82
- };
83
- await delay(1000);
84
- yield replayEvent;
85
- // Then stream all the captured events
86
- for (const event of response.events) {
87
- console.log("[ChatRoute] Replaying event:", event);
88
- await delay(1000);
89
- yield event;
90
- }
91
- // Finally, send a completion indicator
92
- const completeEvent = {
93
- type: "message",
94
- role: "system",
95
- content: "✓ Replay complete",
96
- };
97
- await delay(1000);
98
- yield completeEvent;
99
- }
100
- return streamAsyncGenerator(c, replayGenerator());
101
- }
102
- // Normal chat flow - capture and execute
103
- // Use current conversation ID or generate a new one
104
- let conversationId = thread.currentConversationId;
105
- if (!conversationId) {
106
- conversationId = randomUUID();
107
- // Delete all todos for this thread when starting a new conversation
108
- const db = await getDatabase();
109
- await db.execute({
110
- sql: "DELETE FROM todos WHERE threadId = ?",
111
- args: [threadId],
112
- });
113
- // Update thread with the new conversation ID to maintain conversation continuity
114
- await threadManager.updateThread(threadId, { currentConversationId: conversationId });
115
- }
116
- // Load and activate skills
117
- const skillManager = new SkillManager();
118
- const allSkills = await skillManager.loadSkills(threadPath);
119
- const activatedSkills = await activateSkills(allSkills, content, thread);
120
- if (activatedSkills.length > 0) {
121
- console.log("[ChatRoute] Activated skills:", activatedSkills.map((s) => s.name).join(", "));
122
- }
123
- // Load agent definitions
124
- const agentsManager = new AgentsManager();
125
- const agents = await agentsManager.loadAgents(threadPath);
126
- if (agents.length > 0) {
127
- console.log("[ChatRoute] Loaded agents:", agents.map((a) => a.name).join(", "));
128
- }
129
- // Build execution context with activated skills and agents
130
- const context = {
131
- threadId,
132
- threadPath,
133
- model,
134
- provider,
135
- attachments,
136
- planMode,
137
- skills: activatedSkills,
138
- agents,
139
- };
140
- console.log("[ChatRoute] Execution context:", {
141
- threadId,
142
- threadPath,
143
- model,
144
- planMode,
145
- conversationId,
146
- attachmentCount: attachments?.length ?? 0,
147
- attachmentDetails: (attachments ?? []).map((a) => ({
148
- name: a.name,
149
- mimeType: a.mimeType,
150
- contentLength: a.content?.length ?? 0,
151
- })),
152
- });
153
- // Start capturing the conversation
154
- const messageId = await conversationManager.startMessage(threadId, threadPath, conversationId, content, model, attachments, planMode);
155
- // Load prior conversation context (completed messages only, excluding current, from current conversation)
156
- const history = await conversationManager.getConversationHistoryByConversationId(threadPath, conversationId);
157
- const priorMessages = (history?.messages ?? []).filter((m) => m.id !== messageId && m.response != null);
158
- const contextBlock = formatConversationContext(priorMessages);
159
- const promptWithContext = contextBlock.length > 0 ? `${contextBlock}\n\nCurrent message:\nUser: ${content}` : content;
160
- // Use the request's abort signal to handle client disconnect
161
- const abortController = new AbortController();
162
- const requestSignal = c.req.raw.signal;
163
- // If the request is already aborted, abort our controller
164
- if (requestSignal.aborted) {
165
- abortController.abort();
166
- }
167
- else {
168
- // Listen for request abort and propagate to our controller
169
- requestSignal.addEventListener("abort", () => {
170
- abortController.abort();
171
- }, { once: true });
172
- }
173
- // Mark thread as processing and register the abort controller so the
174
- // stop endpoint can cancel execution independently of connection state
175
- processingStateManager.setProcessing(threadId);
176
- processingStateManager.registerAbortController(threadId, abortController);
177
- // Create a generator for chat execution events
178
- async function* chatExecutionGenerator() {
179
- const capturedEvents = [];
180
- let fullContent = "";
181
- try {
182
- for await (const event of agentExecutor.execute(promptWithContext, context, abortController.signal)) {
183
- // Capture the event
184
- capturedEvents.push(event);
185
- // Accumulate content from message events (for fallback when extracting)
186
- if (event.type === "message" && event.content) {
187
- fullContent += event.content;
188
- }
189
- // Emit thinking progress for tool-related messages so the UI shows progress
190
- if (event.type === "message" &&
191
- typeof event.content === "string" &&
192
- (event.role === "tool" || isToolLikeContent(event.content))) {
193
- const thinkingEvent = { type: "thinking", content: event.content };
194
- processingStateManager.pushEvent(threadId, thinkingEvent);
195
- yield thinkingEvent;
196
- continue;
197
- }
198
- // Buffer the event for late subscribers
199
- processingStateManager.pushEvent(threadId, event);
200
- yield event;
201
- }
202
- const finalContent = extractAssistantContent(capturedEvents, fullContent);
203
- await conversationManager.completeMessage(messageId, finalContent, capturedEvents);
204
- console.log("[ChatRoute] Conversation captured:", {
205
- messageId,
206
- eventCount: capturedEvents.length,
207
- contentLength: finalContent.length,
208
- });
209
- }
210
- catch (error) {
211
- const errorMessage = error instanceof Error ? error.message : String(error);
212
- const errorEvent = {
213
- type: "error",
214
- content: errorMessage,
215
- error: {
216
- code: ErrorCodes.STREAM_ERROR,
217
- message: errorMessage,
218
- details: error instanceof Error ? { stack: error.stack } : undefined,
219
- },
220
- };
221
- capturedEvents.push(errorEvent);
222
- yield errorEvent;
223
- try {
224
- const finalContent = extractAssistantContent(capturedEvents, fullContent);
225
- await conversationManager.completeMessage(messageId, finalContent, capturedEvents);
226
- }
227
- catch (saveError) {
228
- console.error("[ChatRoute] Failed to save partial conversation:", saveError);
229
- }
230
- }
231
- finally {
232
- processingStateManager.clearProcessing(threadId);
233
- try {
234
- const db = await getDatabase();
235
- await invalidateGitStatusCache(db, threadId);
236
- await clearWorkingByThreadId(db, threadId);
237
- try {
238
- const todo = await getTodoByThreadId(db, threadId);
239
- if (todo && todo.status === "Plan") {
240
- const planFilePath = join(threadPath, `${todo.id}-plan.md`);
241
- try {
242
- const planContent = await readFile(planFilePath, "utf-8");
243
- await updateTodo(db, todo.id, { description: planContent.trim() });
244
- await unlink(planFilePath);
245
- }
246
- catch {
247
- // Plan file not found or unreadable — skip silently
248
- }
249
- }
250
- }
251
- catch (e) {
252
- console.error("[ChatRoute] Failed to process plan file for todo:", e);
253
- }
254
- }
255
- catch (e) {
256
- console.error("[ChatRoute] Failed to clear working state for thread todos:", e);
257
- }
258
- }
259
- }
260
- async function* withCompleteSignal() {
261
- yield* chatExecutionGenerator();
262
- yield { type: "complete" };
263
- }
264
- return streamAsyncGenerator(c, withCompleteSignal(), { abortController });
265
- }
266
- catch (error) {
267
- return errorResponse(c, ErrorCodes.REQUEST_PARSE_ERROR, "Failed to parse request body", 400, error instanceof Error ? error.message : String(error));
268
- }
269
- }
270
- //# sourceMappingURL=chat-post.route.js.map