kimaki 0.31.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (989) hide show
  1. package/dist/agent-ui.d.ts +33 -0
  2. package/dist/agent-ui.e2e.test.d.ts +1 -0
  3. package/dist/agent-ui.e2e.test.js +140 -0
  4. package/dist/agent-ui.e2e.test.js.map +1 -0
  5. package/dist/agent-ui.js +199 -0
  6. package/dist/agent-ui.js.map +1 -0
  7. package/dist/analytics.d.ts +42 -0
  8. package/dist/analytics.e2e.test.d.ts +1 -0
  9. package/dist/analytics.e2e.test.js +112 -0
  10. package/dist/analytics.e2e.test.js.map +1 -0
  11. package/dist/analytics.js +162 -223
  12. package/dist/analytics.js.map +1 -0
  13. package/dist/analytics.test.d.ts +1 -0
  14. package/dist/analytics.test.js +121 -157
  15. package/dist/analytics.test.js.map +1 -0
  16. package/dist/autostart.d.ts +7 -0
  17. package/dist/autostart.js +75 -0
  18. package/dist/autostart.js.map +1 -0
  19. package/dist/bot.d.ts +90 -0
  20. package/dist/bot.js +120 -0
  21. package/dist/bot.js.map +1 -0
  22. package/dist/btw.e2e.test.d.ts +1 -0
  23. package/dist/btw.e2e.test.js +102 -0
  24. package/dist/btw.e2e.test.js.map +1 -0
  25. package/dist/catalog-refresh.e2e.test.d.ts +1 -0
  26. package/dist/catalog-refresh.e2e.test.js +90 -0
  27. package/dist/catalog-refresh.e2e.test.js.map +1 -0
  28. package/dist/cli/bot.d.ts +5 -0
  29. package/dist/cli/bot.js +427 -0
  30. package/dist/cli/bot.js.map +1 -0
  31. package/dist/cli/discord.d.ts +3 -0
  32. package/dist/cli/discord.js +118 -0
  33. package/dist/cli/discord.js.map +1 -0
  34. package/dist/cli/project.d.ts +5 -0
  35. package/dist/cli/project.js +143 -0
  36. package/dist/cli/project.js.map +1 -0
  37. package/dist/cli/schedule.d.ts +3 -0
  38. package/dist/cli/schedule.js +156 -0
  39. package/dist/cli/schedule.js.map +1 -0
  40. package/dist/cli/session.d.ts +4 -0
  41. package/dist/cli/session.js +281 -0
  42. package/dist/cli/session.js.map +1 -0
  43. package/dist/cli/shared.d.ts +55 -0
  44. package/dist/cli/shared.js +138 -0
  45. package/dist/cli/shared.js.map +1 -0
  46. package/dist/cli-discord.e2e.test.d.ts +1 -0
  47. package/dist/cli-discord.e2e.test.js +64 -0
  48. package/dist/cli-discord.e2e.test.js.map +1 -0
  49. package/dist/cli-lock.e2e.test.d.ts +1 -0
  50. package/dist/cli-lock.e2e.test.js +520 -0
  51. package/dist/cli-lock.e2e.test.js.map +1 -0
  52. package/dist/cli-read.e2e.test.d.ts +1 -0
  53. package/dist/cli-read.e2e.test.js +81 -0
  54. package/dist/cli-read.e2e.test.js.map +1 -0
  55. package/dist/cli-sessions.e2e.test.d.ts +1 -0
  56. package/dist/cli-sessions.e2e.test.js +116 -0
  57. package/dist/cli-sessions.e2e.test.js.map +1 -0
  58. package/dist/cli.d.ts +2 -0
  59. package/dist/cli.js +34 -263
  60. package/dist/cli.js.map +1 -0
  61. package/dist/commands/login-commands.d.ts +59 -0
  62. package/dist/commands/login-commands.js +341 -0
  63. package/dist/commands/login-commands.js.map +1 -0
  64. package/dist/commands/preference-commands.d.ts +44 -0
  65. package/dist/commands/preference-commands.js +551 -0
  66. package/dist/commands/preference-commands.js.map +1 -0
  67. package/dist/commands/session-commands.d.ts +8 -0
  68. package/dist/commands/session-commands.js +267 -0
  69. package/dist/commands/session-commands.js.map +1 -0
  70. package/dist/commands/thread-commands.d.ts +16 -0
  71. package/dist/commands/thread-commands.js +285 -0
  72. package/dist/commands/thread-commands.js.map +1 -0
  73. package/dist/commands/worktree-commands.d.ts +41 -0
  74. package/dist/commands/worktree-commands.js +279 -0
  75. package/dist/commands/worktree-commands.js.map +1 -0
  76. package/dist/commands.e2e.test.d.ts +1 -0
  77. package/dist/commands.e2e.test.js +255 -0
  78. package/dist/commands.e2e.test.js.map +1 -0
  79. package/dist/credentials.d.ts +84 -0
  80. package/dist/credentials.js +320 -0
  81. package/dist/credentials.js.map +1 -0
  82. package/dist/db.d.ts +1532 -0
  83. package/dist/db.js +57 -245
  84. package/dist/db.js.map +1 -0
  85. package/dist/db.test.d.ts +1 -0
  86. package/dist/db.test.js +351 -682
  87. package/dist/db.test.js.map +1 -0
  88. package/dist/duration.d.ts +2 -0
  89. package/dist/duration.js +18 -0
  90. package/dist/duration.js.map +1 -0
  91. package/dist/effects.d.ts +15 -0
  92. package/dist/effects.js +291 -0
  93. package/dist/effects.js.map +1 -0
  94. package/dist/errors.d.ts +38 -0
  95. package/dist/errors.js +40 -175
  96. package/dist/errors.js.map +1 -0
  97. package/dist/event-loop.d.ts +40 -0
  98. package/dist/event-loop.js +414 -0
  99. package/dist/event-loop.js.map +1 -0
  100. package/dist/file-edit-log.d.ts +41 -0
  101. package/dist/file-edit-log.js +122 -164
  102. package/dist/file-edit-log.js.map +1 -0
  103. package/dist/file-edit-log.test.d.ts +1 -0
  104. package/dist/file-edit-log.test.js +68 -244
  105. package/dist/file-edit-log.test.js.map +1 -0
  106. package/dist/format-parts.d.ts +137 -0
  107. package/dist/format-parts.js +300 -0
  108. package/dist/format-parts.js.map +1 -0
  109. package/dist/format-parts.test.d.ts +1 -0
  110. package/dist/format-parts.test.js +144 -0
  111. package/dist/format-parts.test.js.map +1 -0
  112. package/dist/gateway-replay.e2e.test.d.ts +1 -0
  113. package/dist/gateway-replay.e2e.test.js +95 -0
  114. package/dist/gateway-replay.e2e.test.js.map +1 -0
  115. package/dist/harness.e2e.test.d.ts +1 -0
  116. package/dist/harness.e2e.test.js +107 -0
  117. package/dist/harness.e2e.test.js.map +1 -0
  118. package/dist/hello-thread.e2e.test.d.ts +1 -0
  119. package/dist/hello-thread.e2e.test.js +194 -0
  120. package/dist/hello-thread.e2e.test.js.map +1 -0
  121. package/dist/ingress.d.ts +7 -0
  122. package/dist/ingress.js +337 -0
  123. package/dist/ingress.js.map +1 -0
  124. package/dist/interaction-context.d.ts +45 -0
  125. package/dist/interaction-context.js +77 -0
  126. package/dist/interaction-context.js.map +1 -0
  127. package/dist/interrupt.e2e.test.d.ts +1 -0
  128. package/dist/interrupt.e2e.test.js +124 -0
  129. package/dist/interrupt.e2e.test.js.map +1 -0
  130. package/dist/legacy.e2e.test.d.ts +1 -0
  131. package/dist/legacy.e2e.test.js +85 -0
  132. package/dist/legacy.e2e.test.js.map +1 -0
  133. package/dist/live-call.d.ts +51 -0
  134. package/dist/live-call.js +207 -0
  135. package/dist/live-call.js.map +1 -0
  136. package/dist/lock-routes.d.ts +812 -0
  137. package/dist/lock-routes.js +635 -0
  138. package/dist/lock-routes.js.map +1 -0
  139. package/dist/lock-server.d.ts +36 -0
  140. package/dist/lock-server.js +223 -0
  141. package/dist/lock-server.js.map +1 -0
  142. package/dist/logger.d.ts +13 -0
  143. package/dist/logger.js +112 -162
  144. package/dist/logger.js.map +1 -0
  145. package/dist/login.e2e.test.d.ts +1 -0
  146. package/dist/login.e2e.test.js +83 -0
  147. package/dist/login.e2e.test.js.map +1 -0
  148. package/dist/main.d.ts +32 -0
  149. package/dist/main.js +190 -0
  150. package/dist/main.js.map +1 -0
  151. package/dist/markdown/components.d.ts +10 -0
  152. package/dist/markdown/components.js +77 -0
  153. package/dist/markdown/components.js.map +1 -0
  154. package/dist/markdown/markdown.test.d.ts +1 -0
  155. package/dist/markdown/markdown.test.js +393 -0
  156. package/dist/markdown/markdown.test.js.map +1 -0
  157. package/dist/markdown/render-markdown.d.ts +30 -0
  158. package/dist/markdown/render-markdown.js +265 -0
  159. package/dist/markdown/render-markdown.js.map +1 -0
  160. package/dist/message-tool.e2e.test.d.ts +1 -0
  161. package/dist/message-tool.e2e.test.js +39 -0
  162. package/dist/message-tool.e2e.test.js.map +1 -0
  163. package/dist/migrations.d.ts +8 -0
  164. package/dist/migrations.js +187 -0
  165. package/dist/migrations.js.map +1 -0
  166. package/dist/onboarding-cli.e2e.test.d.ts +1 -0
  167. package/dist/onboarding-cli.e2e.test.js +178 -0
  168. package/dist/onboarding-cli.e2e.test.js.map +1 -0
  169. package/dist/onboarding.d.ts +36 -0
  170. package/dist/onboarding.e2e.test.d.ts +1 -0
  171. package/dist/onboarding.e2e.test.js +148 -0
  172. package/dist/onboarding.e2e.test.js.map +1 -0
  173. package/dist/onboarding.js +261 -0
  174. package/dist/onboarding.js.map +1 -0
  175. package/dist/opencode-server.d.ts +54 -0
  176. package/dist/opencode-server.js +413 -0
  177. package/dist/opencode-server.js.map +1 -0
  178. package/dist/opencode-server.test.d.ts +1 -0
  179. package/dist/opencode-server.test.js +21 -0
  180. package/dist/opencode-server.test.js.map +1 -0
  181. package/dist/permissions.d.ts +31 -0
  182. package/dist/permissions.e2e.test.d.ts +1 -0
  183. package/dist/permissions.e2e.test.js +166 -0
  184. package/dist/permissions.e2e.test.js.map +1 -0
  185. package/dist/permissions.js +95 -0
  186. package/dist/permissions.js.map +1 -0
  187. package/dist/plugin/anthropic/index.d.ts +13 -0
  188. package/dist/plugin/anthropic/index.js +201 -0
  189. package/dist/plugin/anthropic/index.js.map +1 -0
  190. package/dist/plugin/anthropic/index.test.d.ts +1 -0
  191. package/dist/plugin/anthropic/index.test.js +39 -0
  192. package/dist/plugin/anthropic/index.test.js.map +1 -0
  193. package/dist/plugin/index.d.ts +3 -0
  194. package/dist/plugin/index.js +106 -0
  195. package/dist/plugin/index.js.map +1 -0
  196. package/dist/plugin/session-id/index.d.ts +3 -0
  197. package/dist/plugin/session-id/index.js +18 -0
  198. package/dist/plugin/session-id/index.js.map +1 -0
  199. package/dist/plugin.e2e.test.d.ts +1 -0
  200. package/dist/plugin.e2e.test.js +87 -0
  201. package/dist/plugin.e2e.test.js.map +1 -0
  202. package/dist/preference-commands.e2e.test.d.ts +1 -0
  203. package/dist/preference-commands.e2e.test.js +555 -0
  204. package/dist/preference-commands.e2e.test.js.map +1 -0
  205. package/dist/probe-live.tmp.d.ts +1 -0
  206. package/dist/probe-live.tmp.js +82 -0
  207. package/dist/probe-live.tmp.js.map +1 -0
  208. package/dist/project.d.ts +58 -0
  209. package/dist/project.js +169 -0
  210. package/dist/project.js.map +1 -0
  211. package/dist/prompt.d.ts +112 -0
  212. package/dist/prompt.js +578 -0
  213. package/dist/prompt.js.map +1 -0
  214. package/dist/questions.d.ts +59 -0
  215. package/dist/questions.e2e.test.d.ts +1 -0
  216. package/dist/questions.e2e.test.js +290 -0
  217. package/dist/questions.e2e.test.js.map +1 -0
  218. package/dist/questions.js +231 -0
  219. package/dist/questions.js.map +1 -0
  220. package/dist/queue.d.ts +45 -0
  221. package/dist/queue.e2e.test.d.ts +1 -0
  222. package/dist/queue.e2e.test.js +220 -0
  223. package/dist/queue.e2e.test.js.map +1 -0
  224. package/dist/queue.js +132 -0
  225. package/dist/queue.js.map +1 -0
  226. package/dist/remote-send.d.ts +32 -0
  227. package/dist/remote-send.e2e.test.d.ts +1 -0
  228. package/dist/remote-send.e2e.test.js +89 -0
  229. package/dist/remote-send.e2e.test.js.map +1 -0
  230. package/dist/remote-send.js +105 -0
  231. package/dist/remote-send.js.map +1 -0
  232. package/dist/renderer.e2e.test.d.ts +1 -0
  233. package/dist/renderer.e2e.test.js +357 -0
  234. package/dist/renderer.e2e.test.js.map +1 -0
  235. package/dist/restart.e2e.test.d.ts +1 -0
  236. package/dist/restart.e2e.test.js +68 -0
  237. package/dist/restart.e2e.test.js.map +1 -0
  238. package/dist/routes.d.ts +24 -0
  239. package/dist/routes.js +42 -0
  240. package/dist/routes.js.map +1 -0
  241. package/dist/routes.test.d.ts +1 -0
  242. package/dist/routes.test.js +79 -0
  243. package/dist/routes.test.js.map +1 -0
  244. package/dist/routines.e2e.test.d.ts +1 -0
  245. package/dist/routines.e2e.test.js +188 -0
  246. package/dist/routines.e2e.test.js.map +1 -0
  247. package/dist/scheduler.d.ts +116 -0
  248. package/dist/scheduler.e2e.test.d.ts +1 -0
  249. package/dist/scheduler.e2e.test.js +163 -0
  250. package/dist/scheduler.e2e.test.js.map +1 -0
  251. package/dist/scheduler.js +602 -0
  252. package/dist/scheduler.js.map +1 -0
  253. package/dist/scheduler.test.d.ts +1 -0
  254. package/dist/scheduler.test.js +180 -0
  255. package/dist/scheduler.test.js.map +1 -0
  256. package/dist/schema-sql.d.ts +1 -0
  257. package/dist/schema-sql.js +3 -0
  258. package/dist/schema-sql.js.map +1 -0
  259. package/dist/schema.d.ts +2968 -0
  260. package/dist/schema.js +95 -252
  261. package/dist/schema.js.map +1 -0
  262. package/dist/session-commands.e2e.test.d.ts +1 -0
  263. package/dist/session-commands.e2e.test.js +285 -0
  264. package/dist/session-commands.e2e.test.js.map +1 -0
  265. package/dist/session-events.d.ts +55 -0
  266. package/dist/session-events.js +190 -0
  267. package/dist/session-events.js.map +1 -0
  268. package/dist/session-ops.e2e.test.d.ts +1 -0
  269. package/dist/session-ops.e2e.test.js +114 -0
  270. package/dist/session-ops.e2e.test.js.map +1 -0
  271. package/dist/sessions.d.ts +121 -0
  272. package/dist/sessions.js +662 -0
  273. package/dist/sessions.js.map +1 -0
  274. package/dist/shell.e2e.test.d.ts +1 -0
  275. package/dist/shell.e2e.test.js +147 -0
  276. package/dist/shell.e2e.test.js.map +1 -0
  277. package/dist/slash-commands.d.ts +62 -0
  278. package/dist/slash-commands.js +475 -0
  279. package/dist/slash-commands.js.map +1 -0
  280. package/dist/slash-commands.test.d.ts +1 -0
  281. package/dist/slash-commands.test.js +87 -0
  282. package/dist/slash-commands.test.js.map +1 -0
  283. package/dist/sleep.e2e.test.d.ts +1 -0
  284. package/dist/sleep.e2e.test.js +115 -487
  285. package/dist/sleep.e2e.test.js.map +1 -0
  286. package/dist/sleeps.d.ts +37 -0
  287. package/dist/sleeps.js +220 -0
  288. package/dist/sleeps.js.map +1 -0
  289. package/dist/store.d.ts +10 -0
  290. package/dist/store.js +8 -28
  291. package/dist/store.js.map +1 -0
  292. package/dist/system-prompt.d.ts +65 -0
  293. package/dist/system-prompt.js +875 -0
  294. package/dist/system-prompt.js.map +1 -0
  295. package/dist/tasks.e2e.test.d.ts +1 -0
  296. package/dist/tasks.e2e.test.js +173 -0
  297. package/dist/tasks.e2e.test.js.map +1 -0
  298. package/dist/test/auth-plugin/index.d.ts +3 -0
  299. package/dist/test/auth-plugin/index.js +18 -0
  300. package/dist/test/auth-plugin/index.js.map +1 -0
  301. package/dist/test/fake-mcp-server.d.ts +1 -0
  302. package/dist/test/fake-mcp-server.js +45 -0
  303. package/dist/test/fake-mcp-server.js.map +1 -0
  304. package/dist/test/harness.d.ts +246 -0
  305. package/dist/test/harness.js +704 -0
  306. package/dist/test/harness.js.map +1 -0
  307. package/dist/test/replay.d.ts +14 -0
  308. package/dist/test/replay.js +75 -0
  309. package/dist/test/replay.js.map +1 -0
  310. package/dist/thread-reducer.d.ts +172 -0
  311. package/dist/thread-reducer.fixtures.test.d.ts +1 -0
  312. package/dist/thread-reducer.fixtures.test.js +360 -0
  313. package/dist/thread-reducer.fixtures.test.js.map +1 -0
  314. package/dist/thread-reducer.js +497 -0
  315. package/dist/thread-reducer.js.map +1 -0
  316. package/dist/thread-reducer.test.d.ts +1 -0
  317. package/dist/thread-reducer.test.js +369 -0
  318. package/dist/thread-reducer.test.js.map +1 -0
  319. package/dist/tts.test.d.ts +1 -0
  320. package/dist/tts.test.js +147 -0
  321. package/dist/tts.test.js.map +1 -0
  322. package/dist/voice-agent.d.ts +33 -0
  323. package/dist/voice-agent.js +159 -0
  324. package/dist/voice-agent.js.map +1 -0
  325. package/dist/voice-attachments.e2e.test.d.ts +1 -0
  326. package/dist/voice-attachments.e2e.test.js +253 -0
  327. package/dist/voice-attachments.e2e.test.js.map +1 -0
  328. package/dist/voice-call.d.ts +59 -0
  329. package/dist/voice-call.e2e.test.d.ts +1 -0
  330. package/dist/voice-call.e2e.test.js +259 -0
  331. package/dist/voice-call.e2e.test.js.map +1 -0
  332. package/dist/voice-call.js +760 -0
  333. package/dist/voice-call.js.map +1 -0
  334. package/dist/voice-openai.e2e.test.d.ts +1 -0
  335. package/dist/voice-openai.e2e.test.js +161 -0
  336. package/dist/voice-openai.e2e.test.js.map +1 -0
  337. package/dist/voice.d.ts +116 -0
  338. package/dist/voice.js +619 -717
  339. package/dist/voice.js.map +1 -0
  340. package/dist/working-directory.e2e.test.d.ts +1 -0
  341. package/dist/working-directory.e2e.test.js +231 -0
  342. package/dist/working-directory.e2e.test.js.map +1 -0
  343. package/dist/worktrees.d.ts +54 -0
  344. package/dist/worktrees.js +247 -709
  345. package/dist/worktrees.js.map +1 -0
  346. package/dist/worktrees.test.d.ts +1 -0
  347. package/dist/worktrees.test.js +97 -952
  348. package/dist/worktrees.test.js.map +1 -0
  349. package/package.json +38 -74
  350. package/src/agent-ui.e2e.test.ts +134 -0
  351. package/src/agent-ui.ts +216 -0
  352. package/src/analytics.e2e.test.ts +138 -0
  353. package/src/analytics.test.ts +122 -182
  354. package/src/analytics.ts +206 -258
  355. package/src/autostart.ts +78 -0
  356. package/src/bot.ts +194 -0
  357. package/src/btw.e2e.test.ts +130 -0
  358. package/src/catalog-refresh.e2e.test.ts +112 -0
  359. package/src/cli/bot.ts +419 -0
  360. package/src/cli/discord.ts +116 -0
  361. package/src/cli/project.ts +147 -0
  362. package/src/cli/schedule.ts +151 -0
  363. package/src/cli/session.ts +285 -0
  364. package/src/cli/shared.ts +139 -0
  365. package/src/cli-discord.e2e.test.ts +62 -0
  366. package/src/cli-lock.e2e.test.ts +530 -0
  367. package/src/cli-read.e2e.test.ts +78 -0
  368. package/src/cli-sessions.e2e.test.ts +122 -0
  369. package/src/cli.ts +35 -418
  370. package/src/commands/login-commands.ts +360 -0
  371. package/src/commands/preference-commands.ts +586 -0
  372. package/src/commands/session-commands.ts +289 -0
  373. package/src/commands/thread-commands.ts +324 -0
  374. package/src/commands/worktree-commands.ts +288 -0
  375. package/src/commands.e2e.test.ts +290 -0
  376. package/src/credentials.ts +425 -0
  377. package/src/db.test.ts +344 -759
  378. package/src/db.ts +66 -284
  379. package/src/duration.ts +18 -0
  380. package/src/effects.ts +303 -0
  381. package/src/errors.ts +39 -228
  382. package/src/event-loop.ts +462 -0
  383. package/src/file-edit-log.test.ts +68 -272
  384. package/src/file-edit-log.ts +108 -231
  385. package/src/fixtures/v1-schema.sql +241 -0
  386. package/src/fixtures/voice.ogg +0 -0
  387. package/src/format-parts.test.ts +150 -0
  388. package/src/format-parts.ts +405 -0
  389. package/src/gateway-replay.e2e.test.ts +116 -0
  390. package/src/harness.e2e.test.ts +124 -0
  391. package/src/hello-thread.e2e.test.ts +223 -0
  392. package/src/ingress.ts +334 -0
  393. package/src/interaction-context.ts +131 -0
  394. package/src/interrupt.e2e.test.ts +151 -0
  395. package/src/legacy.e2e.test.ts +105 -0
  396. package/src/live-call.ts +249 -0
  397. package/src/lock-routes.ts +625 -0
  398. package/src/lock-server.ts +233 -0
  399. package/src/logger.ts +120 -207
  400. package/src/login.e2e.test.ts +86 -0
  401. package/src/main.ts +230 -0
  402. package/src/markdown/components.ts +102 -0
  403. package/src/markdown/markdown.test.ts +414 -0
  404. package/src/markdown/render-markdown.ts +288 -0
  405. package/src/migrations.ts +198 -0
  406. package/src/onboarding-cli.e2e.test.ts +215 -0
  407. package/src/onboarding.e2e.test.ts +171 -0
  408. package/src/onboarding.ts +297 -0
  409. package/src/opencode-server.test.ts +24 -0
  410. package/src/opencode-server.ts +461 -0
  411. package/src/permissions.e2e.test.ts +191 -0
  412. package/src/permissions.ts +121 -0
  413. package/src/plugin/anthropic/index.test.ts +39 -0
  414. package/src/plugin/anthropic/index.ts +213 -0
  415. package/src/plugin/index.ts +93 -0
  416. package/src/plugin/session-id/index.ts +19 -0
  417. package/src/plugin.e2e.test.ts +112 -0
  418. package/src/preference-commands.e2e.test.ts +597 -0
  419. package/src/project.ts +216 -0
  420. package/src/prompt.ts +664 -0
  421. package/src/questions.e2e.test.ts +328 -0
  422. package/src/questions.ts +322 -0
  423. package/src/queue.e2e.test.ts +253 -0
  424. package/src/queue.ts +158 -0
  425. package/src/remote-send.e2e.test.ts +91 -0
  426. package/src/remote-send.ts +110 -0
  427. package/src/renderer.e2e.test.ts +390 -0
  428. package/src/restart.e2e.test.ts +90 -0
  429. package/src/routes.test.ts +81 -0
  430. package/src/routes.ts +48 -0
  431. package/src/routines.e2e.test.ts +210 -0
  432. package/src/scheduler.e2e.test.ts +182 -0
  433. package/src/scheduler.test.ts +183 -0
  434. package/src/scheduler.ts +648 -0
  435. package/src/schema-sql.ts +3 -0
  436. package/src/schema.ts +95 -271
  437. package/src/session-commands.e2e.test.ts +326 -0
  438. package/src/session-events.ts +218 -0
  439. package/src/session-ops.e2e.test.ts +141 -0
  440. package/src/sessions.ts +803 -0
  441. package/src/shell.e2e.test.ts +173 -0
  442. package/src/slash-commands.test.ts +89 -0
  443. package/src/slash-commands.ts +539 -0
  444. package/src/sleep.e2e.test.ts +135 -552
  445. package/src/sleeps.ts +230 -0
  446. package/src/store.ts +19 -217
  447. package/src/system-prompt.ts +944 -0
  448. package/src/test/auth-plugin/index.ts +17 -0
  449. package/src/test/fake-mcp-server.ts +49 -0
  450. package/src/test/harness.ts +957 -0
  451. package/src/test/replay.ts +90 -0
  452. package/src/thread-reducer.fixtures.test.ts +374 -0
  453. package/src/thread-reducer.test.ts +380 -0
  454. package/src/thread-reducer.ts +671 -0
  455. package/src/tts.test.ts +150 -0
  456. package/src/voice-agent.ts +196 -0
  457. package/src/voice-attachments.e2e.test.ts +298 -0
  458. package/src/voice-call.e2e.test.ts +293 -0
  459. package/src/voice-call.ts +764 -0
  460. package/src/voice-openai.e2e.test.ts +191 -0
  461. package/src/voice.ts +668 -988
  462. package/src/working-directory.e2e.test.ts +226 -0
  463. package/src/worktrees.test.ts +89 -1115
  464. package/src/worktrees.ts +195 -957
  465. package/bin.js +0 -2
  466. package/dist/agent-model.e2e.test.js +0 -1223
  467. package/dist/ai-tool-to-genai.js +0 -233
  468. package/dist/ai-tool-to-genai.test.js +0 -267
  469. package/dist/ai-tool.js +0 -6
  470. package/dist/anthropic-account-identity.js +0 -70
  471. package/dist/anthropic-account-identity.test.js +0 -38
  472. package/dist/anthropic-auth-plugin.js +0 -958
  473. package/dist/anthropic-auth-plugin.test.js +0 -115
  474. package/dist/anthropic-auth-state.js +0 -186
  475. package/dist/anthropic-auth-state.test.js +0 -203
  476. package/dist/bash-tool-schema-plugin.js +0 -50
  477. package/dist/bash-tool-schema-plugin.test.js +0 -68
  478. package/dist/bin.js +0 -151
  479. package/dist/bot-lifecycle.test.js +0 -206
  480. package/dist/btw-prefix-detection.js +0 -24
  481. package/dist/btw-prefix-detection.test.js +0 -130
  482. package/dist/cache-drift-plugin.js +0 -183
  483. package/dist/cache-rewrite.js +0 -39
  484. package/dist/cache-rewrite.test.js +0 -41
  485. package/dist/channel-management.js +0 -347
  486. package/dist/cli-commands/bot.js +0 -254
  487. package/dist/cli-commands/maintenance.js +0 -171
  488. package/dist/cli-commands/misc.js +0 -153
  489. package/dist/cli-commands/project.js +0 -510
  490. package/dist/cli-commands/send.js +0 -659
  491. package/dist/cli-commands/session.js +0 -889
  492. package/dist/cli-commands/task.js +0 -277
  493. package/dist/cli-commands/thread.js +0 -63
  494. package/dist/cli-commands/user.js +0 -145
  495. package/dist/cli-parsing.test.js +0 -226
  496. package/dist/cli-runner.js +0 -1591
  497. package/dist/cli-runner.test.js +0 -119
  498. package/dist/cli-send-thread.e2e.test.js +0 -470
  499. package/dist/cloudflare-transcription.js +0 -56
  500. package/dist/commands/abort.js +0 -84
  501. package/dist/commands/action-buttons.js +0 -248
  502. package/dist/commands/add-project.js +0 -111
  503. package/dist/commands/agent.js +0 -658
  504. package/dist/commands/ask-question.js +0 -371
  505. package/dist/commands/ask-question.test.js +0 -150
  506. package/dist/commands/btw.js +0 -275
  507. package/dist/commands/compact.js +0 -117
  508. package/dist/commands/context-usage.js +0 -194
  509. package/dist/commands/context-usage.test.js +0 -49
  510. package/dist/commands/create-new-project.js +0 -138
  511. package/dist/commands/diff.js +0 -63
  512. package/dist/commands/file-upload.js +0 -280
  513. package/dist/commands/fork-subagent.js +0 -175
  514. package/dist/commands/fork.js +0 -291
  515. package/dist/commands/gemini-apikey.js +0 -123
  516. package/dist/commands/last-sessions.js +0 -129
  517. package/dist/commands/login.js +0 -893
  518. package/dist/commands/mcp.js +0 -239
  519. package/dist/commands/memory-snapshot.js +0 -24
  520. package/dist/commands/mention-mode.js +0 -42
  521. package/dist/commands/merge-worktree.js +0 -205
  522. package/dist/commands/model-variant.js +0 -390
  523. package/dist/commands/model.js +0 -1012
  524. package/dist/commands/multioauth.js +0 -425
  525. package/dist/commands/new-worktree.js +0 -625
  526. package/dist/commands/paginated-select.js +0 -57
  527. package/dist/commands/permissions.js +0 -327
  528. package/dist/commands/queue.js +0 -347
  529. package/dist/commands/queue.test.js +0 -15
  530. package/dist/commands/remove-project.js +0 -111
  531. package/dist/commands/restart-opencode-server.js +0 -133
  532. package/dist/commands/resume.js +0 -148
  533. package/dist/commands/run-command.js +0 -79
  534. package/dist/commands/screenshare.js +0 -307
  535. package/dist/commands/screenshare.test.js +0 -20
  536. package/dist/commands/session-id.js +0 -78
  537. package/dist/commands/session.js +0 -248
  538. package/dist/commands/share.js +0 -80
  539. package/dist/commands/tasks.js +0 -296
  540. package/dist/commands/types.js +0 -2
  541. package/dist/commands/undo-redo.js +0 -313
  542. package/dist/commands/unset-model.js +0 -116
  543. package/dist/commands/upgrade.js +0 -41
  544. package/dist/commands/user-command.js +0 -196
  545. package/dist/commands/verbosity.js +0 -124
  546. package/dist/commands/vscode.js +0 -295
  547. package/dist/commands/worktrees.js +0 -548
  548. package/dist/condense-memory.js +0 -33
  549. package/dist/config.js +0 -126
  550. package/dist/context-awareness-plugin.js +0 -357
  551. package/dist/context-awareness-plugin.test.js +0 -126
  552. package/dist/cpu-profiler.js +0 -211
  553. package/dist/cpu-profiler.test.js +0 -160
  554. package/dist/critique-utils.js +0 -95
  555. package/dist/database.js +0 -1074
  556. package/dist/debounce-timeout.js +0 -28
  557. package/dist/debounced-process-flush.js +0 -77
  558. package/dist/default-channel-provisioning.test.js +0 -149
  559. package/dist/discord-bot.js +0 -1432
  560. package/dist/discord-command-registration.js +0 -519
  561. package/dist/discord-command-registration.test.js +0 -17
  562. package/dist/discord-urls.js +0 -81
  563. package/dist/discord-utils.js +0 -789
  564. package/dist/discord-utils.test.js +0 -400
  565. package/dist/escape-backticks.test.js +0 -429
  566. package/dist/event-stream-real-capture.e2e.test.js +0 -533
  567. package/dist/eventsource-parser.test.js +0 -327
  568. package/dist/exec-async.js +0 -38
  569. package/dist/external-directory-permissions.e2e.test.js +0 -86
  570. package/dist/external-directory-project-deny.e2e.test.js +0 -70
  571. package/dist/external-opencode-sync.js +0 -620
  572. package/dist/external-opencode-sync.test.js +0 -206
  573. package/dist/extract-sdk-error-message.test.js +0 -13
  574. package/dist/format-tables.js +0 -728
  575. package/dist/format-tables.test.js +0 -915
  576. package/dist/forum-sync/config.js +0 -79
  577. package/dist/forum-sync/discord-operations.js +0 -157
  578. package/dist/forum-sync/index.js +0 -5
  579. package/dist/forum-sync/markdown.js +0 -110
  580. package/dist/forum-sync/sync-to-discord.js +0 -417
  581. package/dist/forum-sync/sync-to-files.js +0 -190
  582. package/dist/forum-sync/types.js +0 -53
  583. package/dist/forum-sync/watchers.js +0 -322
  584. package/dist/gateway-proxy-reconnect.e2e.test.js +0 -414
  585. package/dist/gateway-proxy.e2e.test.js +0 -488
  586. package/dist/genai-worker-wrapper.js +0 -111
  587. package/dist/genai-worker.js +0 -309
  588. package/dist/genai.js +0 -232
  589. package/dist/git-worktree-core.js +0 -461
  590. package/dist/guild-categories.test.js +0 -225
  591. package/dist/heap-monitor.js +0 -122
  592. package/dist/hrana-server.js +0 -322
  593. package/dist/hrana-server.test.js +0 -99
  594. package/dist/html-actions.js +0 -123
  595. package/dist/html-actions.test.js +0 -70
  596. package/dist/html-components.js +0 -115
  597. package/dist/html-components.test.js +0 -34
  598. package/dist/image-optimizer-plugin.js +0 -153
  599. package/dist/image-utils.js +0 -112
  600. package/dist/interaction-handler.js +0 -578
  601. package/dist/ipc-polling.js +0 -245
  602. package/dist/ipc-tools-plugin.js +0 -251
  603. package/dist/kimaki-digital-twin.e2e.test.js +0 -161
  604. package/dist/kimaki-opencode-plugin-loading.e2e.test.js +0 -158
  605. package/dist/kimaki-opencode-plugin.js +0 -33
  606. package/dist/kimaki-opencode-plugin.test.js +0 -126
  607. package/dist/kimaki-workspace-adaptor.js +0 -118
  608. package/dist/limit-heading-depth.js +0 -25
  609. package/dist/limit-heading-depth.test.js +0 -105
  610. package/dist/list-channel-threads.js +0 -163
  611. package/dist/list-channel-threads.test.js +0 -80
  612. package/dist/markdown.js +0 -455
  613. package/dist/markdown.test.js +0 -411
  614. package/dist/memory-overview-plugin.js +0 -123
  615. package/dist/message-formatting.js +0 -788
  616. package/dist/message-formatting.test.js +0 -1132
  617. package/dist/message-preprocessing.js +0 -419
  618. package/dist/oauth-rotation-shared.js +0 -253
  619. package/dist/onboarding-tutorial.js +0 -163
  620. package/dist/onboarding-welcome.js +0 -37
  621. package/dist/openai-auth-plugin.js +0 -125
  622. package/dist/openai-auth-state.js +0 -237
  623. package/dist/openai-realtime.js +0 -224
  624. package/dist/opencode-command-detection.js +0 -65
  625. package/dist/opencode-command-detection.test.js +0 -240
  626. package/dist/opencode-command.js +0 -181
  627. package/dist/opencode-command.test.js +0 -218
  628. package/dist/opencode-interrupt-plugin.js +0 -253
  629. package/dist/opencode-interrupt-plugin.test.js +0 -293
  630. package/dist/opencode.js +0 -1217
  631. package/dist/parse-permission-rules.test.js +0 -117
  632. package/dist/patch-text-parser.js +0 -97
  633. package/dist/plugin-logger.js +0 -105
  634. package/dist/plugin-opencode-client.js +0 -54
  635. package/dist/privacy-sanitizer.js +0 -105
  636. package/dist/project-add.test.js +0 -62
  637. package/dist/question-abort-clears-dropdown.e2e.test.js +0 -89
  638. package/dist/question-abort-resume.e2e.test.js +0 -100
  639. package/dist/question-abort-retry-text-before-dropdown.e2e.test.js +0 -150
  640. package/dist/question-text-before-dropdown.e2e.test.js +0 -52
  641. package/dist/queue-advanced-abort.e2e.test.js +0 -348
  642. package/dist/queue-advanced-action-buttons.e2e.test.js +0 -209
  643. package/dist/queue-advanced-e2e-setup.js +0 -1043
  644. package/dist/queue-advanced-footer.e2e.test.js +0 -286
  645. package/dist/queue-advanced-model-switch.e2e.test.js +0 -297
  646. package/dist/queue-advanced-permissions-typing.e2e.test.js +0 -189
  647. package/dist/queue-advanced-question.e2e.test.js +0 -266
  648. package/dist/queue-advanced-typing-interrupt.e2e.test.js +0 -113
  649. package/dist/queue-advanced-typing.e2e.test.js +0 -151
  650. package/dist/queue-delete-message.e2e.test.js +0 -216
  651. package/dist/queue-drain-after-interactive-ui.e2e.test.js +0 -120
  652. package/dist/queue-interrupt-drain.e2e.test.js +0 -256
  653. package/dist/queue-question-select-drain.e2e.test.js +0 -162
  654. package/dist/runtime-idle-sweeper.js +0 -52
  655. package/dist/runtime-lifecycle.e2e.test.js +0 -570
  656. package/dist/sentry.js +0 -23
  657. package/dist/session-handler/agent-utils.js +0 -65
  658. package/dist/session-handler/event-stream-state.js +0 -1225
  659. package/dist/session-handler/event-stream-state.test.js +0 -3160
  660. package/dist/session-handler/global-event-listener.js +0 -212
  661. package/dist/session-handler/model-utils.js +0 -311
  662. package/dist/session-handler/model-utils.test.js +0 -445
  663. package/dist/session-handler/opencode-session-event-log.js +0 -121
  664. package/dist/session-handler/thread-ingress.test.js +0 -41
  665. package/dist/session-handler/thread-runtime-state.js +0 -209
  666. package/dist/session-handler/thread-session-runtime-summary.test.js +0 -121
  667. package/dist/session-handler/thread-session-runtime.js +0 -4320
  668. package/dist/session-handler.js +0 -9
  669. package/dist/session-search.js +0 -219
  670. package/dist/session-search.test.js +0 -287
  671. package/dist/session-sleep.test.js +0 -224
  672. package/dist/session-title-rename.test.js +0 -128
  673. package/dist/skill-filter.js +0 -43
  674. package/dist/skill-filter.test.js +0 -86
  675. package/dist/startup-service.js +0 -153
  676. package/dist/startup-time.e2e.test.js +0 -297
  677. package/dist/system-message.js +0 -806
  678. package/dist/system-message.test.js +0 -917
  679. package/dist/task-id-plugin.js +0 -16
  680. package/dist/task-runner.js +0 -554
  681. package/dist/task-schedule.js +0 -298
  682. package/dist/task-schedule.test.js +0 -366
  683. package/dist/test-utils.js +0 -385
  684. package/dist/thinking-utils.js +0 -45
  685. package/dist/thinking-utils.test.js +0 -35
  686. package/dist/thread-message-queue.e2e.test.js +0 -1227
  687. package/dist/tools.js +0 -357
  688. package/dist/undo-redo.e2e.test.js +0 -171
  689. package/dist/unnest-code-blocks.js +0 -146
  690. package/dist/unnest-code-blocks.test.js +0 -673
  691. package/dist/upgrade.js +0 -114
  692. package/dist/utils.js +0 -148
  693. package/dist/voice-attachment.js +0 -56
  694. package/dist/voice-handler.js +0 -727
  695. package/dist/voice-message.e2e.test.js +0 -1254
  696. package/dist/voice-routing-input.e2e.test.js +0 -195
  697. package/dist/voice-routing-question.e2e.test.js +0 -182
  698. package/dist/voice.test.js +0 -500
  699. package/dist/wait-session.js +0 -193
  700. package/dist/websockify.js +0 -69
  701. package/dist/worker-types.js +0 -4
  702. package/dist/worktree-clone-isolation.e2e.test.js +0 -188
  703. package/dist/worktree-lifecycle.e2e.test.js +0 -735
  704. package/dist/worktree-utils.js +0 -3
  705. package/dist/xai-auth-plugin.js +0 -238
  706. package/dist/xai-auth-state.js +0 -234
  707. package/dist/xai-auth-state.test.js +0 -183
  708. package/dist/xml.js +0 -92
  709. package/dist/xml.test.js +0 -32
  710. package/skills/bump-holocron-consumers/SKILL.md +0 -137
  711. package/skills/critique/SKILL.md +0 -116
  712. package/skills/egaki/SKILL.md +0 -86
  713. package/skills/errore/SKILL.md +0 -501
  714. package/skills/goke/SKILL.md +0 -695
  715. package/skills/holocron/SKILL.md +0 -942
  716. package/skills/lintcn/SKILL.md +0 -873
  717. package/skills/new-skill/SKILL.md +0 -339
  718. package/skills/npm-package/SKILL.md +0 -692
  719. package/skills/opensrc/SKILL.md +0 -102
  720. package/skills/playwriter/SKILL.md +0 -35
  721. package/skills/profano/SKILL.md +0 -33
  722. package/skills/readme.md +0 -20
  723. package/skills/sigillo/SKILL.md +0 -370
  724. package/skills/spiceflow/SKILL.md +0 -80
  725. package/skills/strada/SKILL.md +0 -104
  726. package/skills/termcast/SKILL.md +0 -133
  727. package/skills/tuistory/SKILL.md +0 -237
  728. package/skills/usecomputer/SKILL.md +0 -264
  729. package/skills/zele/SKILL.md +0 -81
  730. package/src/agent-model.e2e.test.ts +0 -1557
  731. package/src/ai-tool-to-genai.test.ts +0 -296
  732. package/src/ai-tool-to-genai.ts +0 -283
  733. package/src/ai-tool.ts +0 -39
  734. package/src/anthropic-account-identity.test.ts +0 -52
  735. package/src/anthropic-account-identity.ts +0 -96
  736. package/src/anthropic-auth-plugin.test.ts +0 -135
  737. package/src/anthropic-auth-plugin.ts +0 -1180
  738. package/src/anthropic-auth-state.test.ts +0 -259
  739. package/src/anthropic-auth-state.ts +0 -272
  740. package/src/bash-tool-schema-plugin.test.ts +0 -84
  741. package/src/bash-tool-schema-plugin.ts +0 -77
  742. package/src/bin.ts +0 -173
  743. package/src/bot-lifecycle.test.ts +0 -252
  744. package/src/btw-prefix-detection.test.ts +0 -142
  745. package/src/btw-prefix-detection.ts +0 -30
  746. package/src/cache-drift-plugin.ts +0 -249
  747. package/src/cache-rewrite.test.ts +0 -49
  748. package/src/cache-rewrite.ts +0 -96
  749. package/src/channel-management.ts +0 -494
  750. package/src/cli-commands/bot.ts +0 -374
  751. package/src/cli-commands/maintenance.ts +0 -237
  752. package/src/cli-commands/misc.ts +0 -208
  753. package/src/cli-commands/project.ts +0 -680
  754. package/src/cli-commands/send.ts +0 -885
  755. package/src/cli-commands/session.ts +0 -1181
  756. package/src/cli-commands/task.ts +0 -358
  757. package/src/cli-commands/thread.ts +0 -86
  758. package/src/cli-commands/user.ts +0 -195
  759. package/src/cli-parsing.test.ts +0 -305
  760. package/src/cli-runner.test.ts +0 -166
  761. package/src/cli-runner.ts +0 -2157
  762. package/src/cli-send-thread.e2e.test.ts +0 -609
  763. package/src/cloudflare-transcription.ts +0 -76
  764. package/src/commands/abort.ts +0 -113
  765. package/src/commands/action-buttons.ts +0 -371
  766. package/src/commands/add-project.ts +0 -146
  767. package/src/commands/agent.ts +0 -911
  768. package/src/commands/ask-question.test.ts +0 -177
  769. package/src/commands/ask-question.ts +0 -532
  770. package/src/commands/btw.ts +0 -356
  771. package/src/commands/compact.ts +0 -154
  772. package/src/commands/context-usage.test.ts +0 -57
  773. package/src/commands/context-usage.ts +0 -267
  774. package/src/commands/create-new-project.ts +0 -203
  775. package/src/commands/diff.ts +0 -91
  776. package/src/commands/file-upload.ts +0 -398
  777. package/src/commands/fork-subagent.ts +0 -262
  778. package/src/commands/fork.ts +0 -421
  779. package/src/commands/gemini-apikey.ts +0 -205
  780. package/src/commands/last-sessions.ts +0 -176
  781. package/src/commands/login.ts +0 -1182
  782. package/src/commands/mcp.ts +0 -307
  783. package/src/commands/memory-snapshot.ts +0 -30
  784. package/src/commands/mention-mode.ts +0 -66
  785. package/src/commands/merge-worktree.ts +0 -282
  786. package/src/commands/model-variant.ts +0 -522
  787. package/src/commands/model.ts +0 -1377
  788. package/src/commands/multioauth.ts +0 -508
  789. package/src/commands/new-worktree.ts +0 -835
  790. package/src/commands/paginated-select.ts +0 -81
  791. package/src/commands/permissions.ts +0 -458
  792. package/src/commands/queue.test.ts +0 -19
  793. package/src/commands/queue.ts +0 -471
  794. package/src/commands/remove-project.ts +0 -152
  795. package/src/commands/restart-opencode-server.ts +0 -173
  796. package/src/commands/resume.ts +0 -229
  797. package/src/commands/run-command.ts +0 -123
  798. package/src/commands/screenshare.test.ts +0 -30
  799. package/src/commands/screenshare.ts +0 -388
  800. package/src/commands/session-id.ts +0 -109
  801. package/src/commands/session.ts +0 -319
  802. package/src/commands/share.ts +0 -106
  803. package/src/commands/tasks.ts +0 -399
  804. package/src/commands/types.ts +0 -25
  805. package/src/commands/undo-redo.ts +0 -394
  806. package/src/commands/unset-model.ts +0 -152
  807. package/src/commands/upgrade.ts +0 -51
  808. package/src/commands/user-command.ts +0 -260
  809. package/src/commands/verbosity.ts +0 -172
  810. package/src/commands/vscode.ts +0 -378
  811. package/src/commands/worktrees.ts +0 -762
  812. package/src/condense-memory.ts +0 -36
  813. package/src/config.ts +0 -147
  814. package/src/context-awareness-plugin.test.ts +0 -144
  815. package/src/context-awareness-plugin.ts +0 -508
  816. package/src/cpu-profiler.test.ts +0 -183
  817. package/src/cpu-profiler.ts +0 -293
  818. package/src/critique-utils.ts +0 -139
  819. package/src/database.ts +0 -1484
  820. package/src/debounce-timeout.ts +0 -43
  821. package/src/debounced-process-flush.ts +0 -104
  822. package/src/default-channel-provisioning.test.ts +0 -156
  823. package/src/discord-bot.ts +0 -1852
  824. package/src/discord-command-registration.test.ts +0 -20
  825. package/src/discord-command-registration.ts +0 -704
  826. package/src/discord-urls.ts +0 -88
  827. package/src/discord-utils.test.ts +0 -470
  828. package/src/discord-utils.ts +0 -1079
  829. package/src/escape-backticks.test.ts +0 -469
  830. package/src/event-stream-real-capture.e2e.test.ts +0 -692
  831. package/src/eventsource-parser.test.ts +0 -351
  832. package/src/exec-async.ts +0 -44
  833. package/src/external-directory-permissions.e2e.test.ts +0 -103
  834. package/src/external-directory-project-deny.e2e.test.ts +0 -84
  835. package/src/external-opencode-sync.test.ts +0 -248
  836. package/src/external-opencode-sync.ts +0 -867
  837. package/src/extract-sdk-error-message.test.ts +0 -18
  838. package/src/format-tables.test.ts +0 -988
  839. package/src/format-tables.ts +0 -1031
  840. package/src/forum-sync/config.ts +0 -92
  841. package/src/forum-sync/discord-operations.ts +0 -245
  842. package/src/forum-sync/index.ts +0 -9
  843. package/src/forum-sync/markdown.ts +0 -172
  844. package/src/forum-sync/sync-to-discord.ts +0 -595
  845. package/src/forum-sync/sync-to-files.ts +0 -294
  846. package/src/forum-sync/types.ts +0 -175
  847. package/src/forum-sync/watchers.ts +0 -474
  848. package/src/gateway-proxy-reconnect.e2e.test.ts +0 -553
  849. package/src/gateway-proxy.e2e.test.ts +0 -648
  850. package/src/genai-worker-wrapper.ts +0 -164
  851. package/src/genai-worker.ts +0 -385
  852. package/src/genai.ts +0 -318
  853. package/src/git-worktree-core.ts +0 -616
  854. package/src/guild-categories.test.ts +0 -260
  855. package/src/heap-monitor.ts +0 -152
  856. package/src/hrana-server.test.ts +0 -130
  857. package/src/hrana-server.ts +0 -399
  858. package/src/html-actions.test.ts +0 -87
  859. package/src/html-actions.ts +0 -174
  860. package/src/html-components.test.ts +0 -38
  861. package/src/html-components.ts +0 -177
  862. package/src/image-optimizer-plugin.ts +0 -194
  863. package/src/image-utils.ts +0 -150
  864. package/src/interaction-handler.ts +0 -775
  865. package/src/ipc-polling.ts +0 -325
  866. package/src/ipc-tools-plugin.ts +0 -306
  867. package/src/kimaki-digital-twin.e2e.test.ts +0 -199
  868. package/src/kimaki-opencode-plugin-loading.e2e.test.ts +0 -208
  869. package/src/kimaki-opencode-plugin.test.ts +0 -142
  870. package/src/kimaki-opencode-plugin.ts +0 -34
  871. package/src/kimaki-workspace-adaptor.ts +0 -144
  872. package/src/limit-heading-depth.test.ts +0 -116
  873. package/src/limit-heading-depth.ts +0 -26
  874. package/src/list-channel-threads.test.ts +0 -90
  875. package/src/list-channel-threads.ts +0 -252
  876. package/src/markdown.test.ts +0 -498
  877. package/src/markdown.ts +0 -577
  878. package/src/memory-overview-plugin.ts +0 -159
  879. package/src/message-formatting.test.ts +0 -1401
  880. package/src/message-formatting.ts +0 -999
  881. package/src/message-preprocessing.ts +0 -557
  882. package/src/oauth-rotation-shared.ts +0 -332
  883. package/src/onboarding-tutorial.ts +0 -167
  884. package/src/onboarding-welcome.ts +0 -49
  885. package/src/openai-auth-plugin.ts +0 -158
  886. package/src/openai-auth-state.ts +0 -297
  887. package/src/openai-realtime.ts +0 -358
  888. package/src/opencode-command-detection.test.ts +0 -307
  889. package/src/opencode-command-detection.ts +0 -76
  890. package/src/opencode-command.test.ts +0 -290
  891. package/src/opencode-command.ts +0 -251
  892. package/src/opencode-interrupt-plugin.test.ts +0 -419
  893. package/src/opencode-interrupt-plugin.ts +0 -306
  894. package/src/opencode.ts +0 -1590
  895. package/src/parse-permission-rules.test.ts +0 -127
  896. package/src/patch-text-parser.ts +0 -107
  897. package/src/plugin-logger.ts +0 -139
  898. package/src/plugin-opencode-client.ts +0 -71
  899. package/src/privacy-sanitizer.ts +0 -142
  900. package/src/project-add.test.ts +0 -80
  901. package/src/question-abort-clears-dropdown.e2e.test.ts +0 -109
  902. package/src/question-abort-resume.e2e.test.ts +0 -121
  903. package/src/question-abort-retry-text-before-dropdown.e2e.test.ts +0 -172
  904. package/src/question-text-before-dropdown.e2e.test.ts +0 -67
  905. package/src/queue-advanced-abort.e2e.test.ts +0 -449
  906. package/src/queue-advanced-action-buttons.e2e.test.ts +0 -271
  907. package/src/queue-advanced-e2e-setup.ts +0 -1164
  908. package/src/queue-advanced-footer.e2e.test.ts +0 -357
  909. package/src/queue-advanced-model-switch.e2e.test.ts +0 -382
  910. package/src/queue-advanced-permissions-typing.e2e.test.ts +0 -256
  911. package/src/queue-advanced-question.e2e.test.ts +0 -322
  912. package/src/queue-advanced-typing-interrupt.e2e.test.ts +0 -147
  913. package/src/queue-advanced-typing.e2e.test.ts +0 -199
  914. package/src/queue-delete-message.e2e.test.ts +0 -262
  915. package/src/queue-drain-after-interactive-ui.e2e.test.ts +0 -152
  916. package/src/queue-interrupt-drain.e2e.test.ts +0 -299
  917. package/src/queue-question-select-drain.e2e.test.ts +0 -209
  918. package/src/runtime-idle-sweeper.ts +0 -76
  919. package/src/runtime-lifecycle.e2e.test.ts +0 -714
  920. package/src/schema.sql +0 -251
  921. package/src/sentry.ts +0 -26
  922. package/src/session-handler/agent-utils.ts +0 -104
  923. package/src/session-handler/event-stream-fixtures/real-session-action-buttons.jsonl +0 -45
  924. package/src/session-handler/event-stream-fixtures/real-session-footer-suppressed-on-pre-idle-interrupt.jsonl +0 -40
  925. package/src/session-handler/event-stream-fixtures/real-session-permission-external-file.jsonl +0 -23
  926. package/src/session-handler/event-stream-fixtures/real-session-task-normal.jsonl +0 -22
  927. package/src/session-handler/event-stream-fixtures/real-session-task-three-parallel-sleeps.jsonl +0 -277
  928. package/src/session-handler/event-stream-fixtures/real-session-task-user-interruption.jsonl +0 -46
  929. package/src/session-handler/event-stream-fixtures/session-abort-after-idle-race.jsonl +0 -21
  930. package/src/session-handler/event-stream-fixtures/session-concurrent-messages-serialized.jsonl +0 -56
  931. package/src/session-handler/event-stream-fixtures/session-explicit-abort.jsonl +0 -44
  932. package/src/session-handler/event-stream-fixtures/session-normal-completion.jsonl +0 -29
  933. package/src/session-handler/event-stream-fixtures/session-tool-call-noisy-stream.jsonl +0 -29
  934. package/src/session-handler/event-stream-fixtures/session-two-completions-same-session.jsonl +0 -50
  935. package/src/session-handler/event-stream-fixtures/session-user-interruption.jsonl +0 -59
  936. package/src/session-handler/event-stream-fixtures/session-voice-queued-followup.jsonl +0 -52
  937. package/src/session-handler/event-stream-state.test.ts +0 -3431
  938. package/src/session-handler/event-stream-state.ts +0 -1792
  939. package/src/session-handler/global-event-listener.ts +0 -258
  940. package/src/session-handler/model-utils.test.ts +0 -537
  941. package/src/session-handler/model-utils.ts +0 -489
  942. package/src/session-handler/opencode-session-event-log.ts +0 -159
  943. package/src/session-handler/thread-ingress.test.ts +0 -54
  944. package/src/session-handler/thread-runtime-state.ts +0 -358
  945. package/src/session-handler/thread-session-runtime-summary.test.ts +0 -169
  946. package/src/session-handler/thread-session-runtime.ts +0 -5696
  947. package/src/session-handler.ts +0 -15
  948. package/src/session-search.test.ts +0 -331
  949. package/src/session-search.ts +0 -382
  950. package/src/session-sleep.test.ts +0 -294
  951. package/src/session-title-rename.test.ts +0 -186
  952. package/src/skill-filter.test.ts +0 -110
  953. package/src/skill-filter.ts +0 -63
  954. package/src/startup-service.ts +0 -200
  955. package/src/startup-time.e2e.test.ts +0 -377
  956. package/src/system-message.test.ts +0 -1013
  957. package/src/system-message.ts +0 -1043
  958. package/src/task-id-plugin.ts +0 -17
  959. package/src/task-runner.ts +0 -768
  960. package/src/task-schedule.test.ts +0 -424
  961. package/src/task-schedule.ts +0 -470
  962. package/src/test-utils.ts +0 -549
  963. package/src/thinking-utils.test.ts +0 -46
  964. package/src/thinking-utils.ts +0 -82
  965. package/src/thread-message-queue.e2e.test.ts +0 -1468
  966. package/src/tools.ts +0 -430
  967. package/src/undici.d.ts +0 -12
  968. package/src/undo-redo.e2e.test.ts +0 -219
  969. package/src/unnest-code-blocks.test.ts +0 -713
  970. package/src/unnest-code-blocks.ts +0 -185
  971. package/src/upgrade.ts +0 -127
  972. package/src/utils.ts +0 -216
  973. package/src/voice-attachment.ts +0 -79
  974. package/src/voice-handler.ts +0 -1000
  975. package/src/voice-message.e2e.test.ts +0 -1513
  976. package/src/voice-routing-input.e2e.test.ts +0 -203
  977. package/src/voice-routing-question.e2e.test.ts +0 -188
  978. package/src/voice.test.ts +0 -565
  979. package/src/wait-session.ts +0 -291
  980. package/src/websockify.ts +0 -101
  981. package/src/worker-types.ts +0 -64
  982. package/src/worktree-clone-isolation.e2e.test.ts +0 -213
  983. package/src/worktree-lifecycle.e2e.test.ts +0 -900
  984. package/src/worktree-utils.ts +0 -4
  985. package/src/xai-auth-plugin.ts +0 -303
  986. package/src/xai-auth-state.test.ts +0 -224
  987. package/src/xai-auth-state.ts +0 -294
  988. package/src/xml.test.ts +0 -38
  989. package/src/xml.ts +0 -121
@@ -1,893 +0,0 @@
1
- // /login command — authenticate with AI providers (OAuth or API key).
2
- //
3
- // Uses a unified select handler (`login_select:<hash>`) for all sequential
4
- // select menus (provider → method → plugin prompts). The context tracks a
5
- // `step` field so one handler drives the whole flow.
6
- //
7
- // CustomId patterns:
8
- // login_select:<hash> — all select menus (provider, method, prompts)
9
- // login_apikey:<hash> — API key modal submission
10
- // login_text:<hash> — text prompt modal submission
11
- import { ChatInputCommandInteraction, StringSelectMenuInteraction, StringSelectMenuBuilder, ActionRowBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, ModalSubmitInteraction, ButtonBuilder, ButtonStyle, ChannelType, MessageFlags, } from 'discord.js';
12
- import crypto from 'node:crypto';
13
- import { initializeOpencodeForDirectory, getOpencodeServerPort, getOpencodeServerAuthHeaders, } from '../opencode.js';
14
- import { resolveTextChannel, getKimakiMetadata } from '../discord-utils.js';
15
- import { clearModelListCache } from '../session-handler/model-utils.js';
16
- import { createLogger, LogPrefix } from '../logger.js';
17
- import { buildPaginatedOptions, parsePaginationValue } from './paginated-select.js';
18
- const loginLogger = createLogger(LogPrefix.LOGIN);
19
- // ── Context store ───────────────────────────────────────────────
20
- // Keyed by random hash to stay under Discord's 100-char customId limit.
21
- // TTL prevents unbounded growth when users open /login and never interact.
22
- const LOGIN_CONTEXT_TTL_MS = 10 * 60 * 1000;
23
- const pendingLoginContexts = new Map();
24
- function createContextHash(context) {
25
- const hash = crypto.randomBytes(8).toString('hex');
26
- pendingLoginContexts.set(hash, context);
27
- setTimeout(() => {
28
- pendingLoginContexts.delete(hash);
29
- }, LOGIN_CONTEXT_TTL_MS).unref();
30
- return hash;
31
- }
32
- // ── Provider popularity order ───────────────────────────────────
33
- // Discord select menus cap at 25 options, so we show popular ones first.
34
- // IDs sourced from opencode's provider.list() API (scripts/list-providers.ts).
35
- // `subrouter` leads: it pools every subscription and cycles across them.
36
- const PROVIDER_POPULARITY_ORDER = [
37
- 'subrouter',
38
- 'anthropic',
39
- 'openai',
40
- 'google',
41
- 'github-copilot',
42
- 'xai',
43
- 'groq',
44
- 'deepseek',
45
- 'opencode',
46
- 'opencode-go',
47
- 'mistral',
48
- 'openrouter',
49
- 'fireworks-ai',
50
- 'togetherai',
51
- 'amazon-bedrock',
52
- 'azure',
53
- 'google-vertex',
54
- 'google-vertex-anthropic',
55
- // 'cohere',
56
- 'cerebras',
57
- // 'perplexity',
58
- 'cloudflare-workers-ai',
59
- // 'novita-ai',
60
- // 'huggingface',
61
- 'deepinfra',
62
- 'github-models',
63
- 'lmstudio',
64
- 'llama',
65
- ];
66
- // ── Helpers ─────────────────────────────────────────────────────
67
- function extractErrorMessage({ error, fallback, }) {
68
- if (!error || typeof error !== 'object') {
69
- return fallback;
70
- }
71
- const parsed = error;
72
- return parsed.data?.message || parsed.message || fallback;
73
- }
74
- function shouldShowPrompt(prompt, inputs) {
75
- if (!prompt.when) {
76
- return true;
77
- }
78
- const value = inputs[prompt.when.key];
79
- if (prompt.when.op === 'eq') {
80
- return value === prompt.when.value;
81
- }
82
- if (prompt.when.op === 'neq') {
83
- return value !== prompt.when.value;
84
- }
85
- return true;
86
- }
87
- function buildSelectMenu({ customId, placeholder, options, }) {
88
- const menu = new StringSelectMenuBuilder()
89
- .setCustomId(customId)
90
- .setPlaceholder(placeholder)
91
- .addOptions(options);
92
- return new ActionRowBuilder().addComponents(menu);
93
- }
94
- // ── /login command ──────────────────────────────────────────────
95
- export async function handleLoginCommand({ interaction, }) {
96
- loginLogger.log('[LOGIN] handleLoginCommand called');
97
- await interaction.deferReply({ flags: MessageFlags.Ephemeral });
98
- const channel = interaction.channel;
99
- if (!channel) {
100
- await interaction.editReply({
101
- content: 'This command can only be used in a channel',
102
- });
103
- return;
104
- }
105
- const isThread = [
106
- ChannelType.PublicThread,
107
- ChannelType.PrivateThread,
108
- ChannelType.AnnouncementThread,
109
- ].includes(channel.type);
110
- let projectDirectory;
111
- let targetChannelId;
112
- if (isThread) {
113
- const thread = channel;
114
- const textChannel = await resolveTextChannel(thread);
115
- const metadata = await getKimakiMetadata(textChannel);
116
- projectDirectory = metadata.projectDirectory;
117
- targetChannelId = textChannel?.id || channel.id;
118
- }
119
- else if (channel.type === ChannelType.GuildText) {
120
- const metadata = await getKimakiMetadata(channel);
121
- projectDirectory = metadata.projectDirectory;
122
- targetChannelId = channel.id;
123
- }
124
- else {
125
- await interaction.editReply({
126
- content: 'This command can only be used in text channels or threads',
127
- });
128
- return;
129
- }
130
- if (!projectDirectory) {
131
- await interaction.editReply({
132
- content: 'This channel is not configured with a project directory',
133
- });
134
- return;
135
- }
136
- try {
137
- const getClient = await initializeOpencodeForDirectory(projectDirectory);
138
- if (getClient instanceof Error) {
139
- await interaction.editReply({ content: getClient.message });
140
- return;
141
- }
142
- const providersResponse = await getClient().provider.list({
143
- directory: projectDirectory,
144
- });
145
- if (!providersResponse.data) {
146
- await interaction.editReply({ content: 'Failed to fetch providers' });
147
- return;
148
- }
149
- const { all: allProviders, connected } = providersResponse.data;
150
- if (allProviders.length === 0) {
151
- await interaction.editReply({ content: 'No providers available.' });
152
- return;
153
- }
154
- const allProviderOptions = [...allProviders]
155
- .sort((a, b) => {
156
- const rankA = PROVIDER_POPULARITY_ORDER.indexOf(a.id);
157
- const rankB = PROVIDER_POPULARITY_ORDER.indexOf(b.id);
158
- const posA = rankA === -1 ? Infinity : rankA;
159
- const posB = rankB === -1 ? Infinity : rankB;
160
- if (posA !== posB) {
161
- return posA - posB;
162
- }
163
- return a.name.localeCompare(b.name);
164
- })
165
- .map((provider) => {
166
- const isConnected = connected.includes(provider.id);
167
- return {
168
- label: `${provider.name}${isConnected ? ' ✓' : ''}`.slice(0, 100),
169
- value: provider.id,
170
- description: isConnected
171
- ? 'Connected - select to re-authenticate'
172
- : 'Not connected',
173
- };
174
- });
175
- const { options } = buildPaginatedOptions({
176
- allOptions: allProviderOptions,
177
- page: 0,
178
- });
179
- const context = {
180
- dir: projectDirectory,
181
- channelId: targetChannelId,
182
- steps: [{ type: 'provider' }],
183
- stepIndex: 0,
184
- inputs: {},
185
- };
186
- const hash = createContextHash(context);
187
- await interaction.editReply({
188
- content: '**Authenticate with Provider**\nSelect a provider:',
189
- components: [
190
- buildSelectMenu({
191
- customId: `login_select:${hash}`,
192
- placeholder: 'Select a provider to authenticate',
193
- options,
194
- }),
195
- ],
196
- });
197
- }
198
- catch (error) {
199
- loginLogger.error('Error loading providers:', error);
200
- await interaction.editReply({
201
- content: `Failed to load providers: ${error instanceof Error ? error.message : 'Unknown error'}`,
202
- });
203
- }
204
- }
205
- // ── Unified select handler ──────────────────────────────────────
206
- // Handles all select menu interactions for the login flow.
207
- // Reads the current step from context, processes the answer,
208
- // then either shows the next step or proceeds to authorize/API key.
209
- export async function handleLoginSelect(interaction) {
210
- if (!interaction.customId.startsWith('login_select:')) {
211
- return;
212
- }
213
- const hash = interaction.customId.replace('login_select:', '');
214
- const ctx = pendingLoginContexts.get(hash);
215
- if (!ctx) {
216
- await interaction.deferUpdate();
217
- await interaction.editReply({
218
- content: 'Selection expired. Please run /login again.',
219
- components: [],
220
- });
221
- return;
222
- }
223
- const value = interaction.values[0];
224
- if (!value) {
225
- await interaction.deferUpdate();
226
- await interaction.editReply({
227
- content: 'No option selected.',
228
- components: [],
229
- });
230
- return;
231
- }
232
- const step = ctx.steps[ctx.stepIndex];
233
- if (!step) {
234
- await interaction.deferUpdate();
235
- await interaction.editReply({
236
- content: 'Invalid state. Please run /login again.',
237
- components: [],
238
- });
239
- return;
240
- }
241
- try {
242
- if (step.type === 'provider') {
243
- await handleProviderStep(interaction, ctx, hash, value);
244
- }
245
- else if (step.type === 'method') {
246
- await handleMethodStep(interaction, ctx, hash, value, step);
247
- }
248
- else if (step.type === 'prompt') {
249
- await handlePromptStep(interaction, ctx, hash, value, step);
250
- }
251
- }
252
- catch (error) {
253
- loginLogger.error('Error in login select:', error);
254
- if (!interaction.deferred && !interaction.replied) {
255
- await interaction.deferUpdate();
256
- }
257
- await interaction.editReply({
258
- content: `Login error: ${error instanceof Error ? error.message : 'Unknown error'}`,
259
- components: [],
260
- });
261
- }
262
- }
263
- // ── Step handlers ───────────────────────────────────────────────
264
- async function handleProviderStep(interaction, ctx, hash, providerId) {
265
- // Handle pagination nav — re-render the same provider select with new page
266
- const navPage = parsePaginationValue(providerId);
267
- if (navPage !== undefined) {
268
- await interaction.deferUpdate();
269
- ctx.providerPage = navPage;
270
- const getClient = await initializeOpencodeForDirectory(ctx.dir);
271
- if (getClient instanceof Error) {
272
- await interaction.editReply({ content: getClient.message, components: [] });
273
- return;
274
- }
275
- const providersResponse = await getClient().provider.list({ directory: ctx.dir });
276
- if (!providersResponse.data) {
277
- await interaction.editReply({ content: 'Failed to fetch providers', components: [] });
278
- return;
279
- }
280
- const { all: allProviders, connected } = providersResponse.data;
281
- const allProviderOptions = [...allProviders]
282
- .sort((a, b) => {
283
- const rankA = PROVIDER_POPULARITY_ORDER.indexOf(a.id);
284
- const rankB = PROVIDER_POPULARITY_ORDER.indexOf(b.id);
285
- const posA = rankA === -1 ? Infinity : rankA;
286
- const posB = rankB === -1 ? Infinity : rankB;
287
- if (posA !== posB) {
288
- return posA - posB;
289
- }
290
- return a.name.localeCompare(b.name);
291
- })
292
- .map((p) => {
293
- const isConnected = connected.includes(p.id);
294
- return {
295
- label: `${p.name}${isConnected ? ' ✓' : ''}`.slice(0, 100),
296
- value: p.id,
297
- description: isConnected ? 'Connected - select to re-authenticate' : 'Not connected',
298
- };
299
- });
300
- const { options } = buildPaginatedOptions({ allOptions: allProviderOptions, page: navPage });
301
- await interaction.editReply({
302
- content: '**Authenticate with Provider**\nSelect a provider:',
303
- components: [
304
- buildSelectMenu({
305
- customId: `login_select:${hash}`,
306
- placeholder: 'Select a provider to authenticate',
307
- options,
308
- }),
309
- ],
310
- });
311
- return;
312
- }
313
- const getClient = await initializeOpencodeForDirectory(ctx.dir);
314
- if (getClient instanceof Error) {
315
- await interaction.deferUpdate();
316
- await interaction.editReply({ content: getClient.message, components: [] });
317
- return;
318
- }
319
- const providersResponse = await getClient().provider.list({
320
- directory: ctx.dir,
321
- });
322
- const provider = providersResponse.data?.all.find((p) => p.id === providerId);
323
- const providerName = provider?.name || providerId;
324
- const authResponse = await getClient().provider.auth({ directory: ctx.dir });
325
- if (!authResponse.data) {
326
- await interaction.deferUpdate();
327
- await interaction.editReply({
328
- content: 'Failed to fetch authentication methods',
329
- components: [],
330
- });
331
- return;
332
- }
333
- // The server returns prompts in the auth response when the opencode
334
- // version supports it (dev branch, not yet released as of v1.2.27).
335
- // Once released, plugin-defined prompts will be collected and passed
336
- // as inputs to the authorize call automatically.
337
- const methods = authResponse.data[providerId] || [
338
- { type: 'api', label: 'API Key' },
339
- ];
340
- if (methods.length === 0) {
341
- await interaction.deferUpdate();
342
- await interaction.editReply({
343
- content: `No authentication methods available for ${providerName}`,
344
- components: [],
345
- });
346
- return;
347
- }
348
- ctx.providerId = providerId;
349
- ctx.providerName = providerName;
350
- if (methods.length === 1) {
351
- // Single method — skip method select, go straight to prompts or action
352
- const method = methods[0];
353
- ctx.methodIndex = 0;
354
- ctx.methodType = method.type;
355
- const promptSteps = buildPromptSteps(method);
356
- if (promptSteps.length > 0) {
357
- // Has prompts — defer and show first prompt
358
- ctx.steps = promptSteps;
359
- ctx.stepIndex = 0;
360
- await interaction.deferUpdate();
361
- await showNextStep(interaction, ctx, hash);
362
- }
363
- else if (method.type === 'api') {
364
- // API key with no prompts — show modal directly (don't defer)
365
- await showApiKeyModal(interaction, hash, providerName);
366
- }
367
- else {
368
- // OAuth with no prompts — defer and authorize
369
- await interaction.deferUpdate();
370
- await startOAuthFlow(interaction, ctx, hash);
371
- }
372
- return;
373
- }
374
- // Multiple methods — show method select
375
- ctx.steps = [
376
- { type: 'method', methods },
377
- ];
378
- ctx.stepIndex = 0;
379
- await interaction.deferUpdate();
380
- await showNextStep(interaction, ctx, hash);
381
- }
382
- async function handleMethodStep(interaction, ctx, hash, value, step) {
383
- const methodIndex = parseInt(value, 10);
384
- const method = step.methods[methodIndex];
385
- if (!method) {
386
- await interaction.deferUpdate();
387
- await interaction.editReply({
388
- content: 'Invalid method selected.',
389
- components: [],
390
- });
391
- return;
392
- }
393
- ctx.methodIndex = methodIndex;
394
- ctx.methodType = method.type;
395
- const promptSteps = buildPromptSteps(method);
396
- if (promptSteps.length > 0) {
397
- // Replace remaining steps with prompt steps
398
- ctx.steps = promptSteps;
399
- ctx.stepIndex = 0;
400
- await interaction.deferUpdate();
401
- await showNextStep(interaction, ctx, hash);
402
- }
403
- else if (method.type === 'api') {
404
- // API key with no prompts — show modal directly (don't defer)
405
- await showApiKeyModal(interaction, hash, ctx.providerName || '');
406
- }
407
- else {
408
- // OAuth with no prompts
409
- await interaction.deferUpdate();
410
- await startOAuthFlow(interaction, ctx, hash);
411
- }
412
- }
413
- async function handlePromptStep(interaction, ctx, hash, value, step) {
414
- // Store the answer
415
- ctx.inputs[step.prompt.key] = value;
416
- ctx.stepIndex++;
417
- // Find the next prompt step that passes its `when` condition
418
- await interaction.deferUpdate();
419
- await showNextStep(interaction, ctx, hash);
420
- }
421
- // ── Step rendering ──────────────────────────────────────────────
422
- // Advances through steps, skipping prompts whose `when` condition
423
- // fails, until it finds one to show or reaches the end.
424
- async function showNextStep(interaction, ctx, hash) {
425
- // Skip prompts whose `when` condition doesn't match
426
- while (ctx.stepIndex < ctx.steps.length) {
427
- const step = ctx.steps[ctx.stepIndex];
428
- if (step.type === 'prompt' && !shouldShowPrompt(step.prompt, ctx.inputs)) {
429
- ctx.stepIndex++;
430
- continue;
431
- }
432
- break;
433
- }
434
- if (ctx.stepIndex >= ctx.steps.length) {
435
- // All steps done — proceed to action
436
- if (ctx.methodType === 'api') {
437
- // We're deferred, so show a button that opens the API key modal
438
- const button = new ButtonBuilder()
439
- .setCustomId(`login_apikey_btn:${hash}`)
440
- .setLabel('Enter API Key')
441
- .setStyle(ButtonStyle.Primary);
442
- await interaction.editReply({
443
- content: `**Authenticate with ${ctx.providerName}**\nClick to enter your API key.`,
444
- components: [
445
- new ActionRowBuilder().addComponents(button),
446
- ],
447
- });
448
- }
449
- else {
450
- await startOAuthFlow(interaction, ctx, hash);
451
- }
452
- return;
453
- }
454
- const step = ctx.steps[ctx.stepIndex];
455
- pendingLoginContexts.set(hash, ctx);
456
- if (step.type === 'method') {
457
- const options = step.methods.slice(0, 25).map((method, index) => ({
458
- label: method.label.slice(0, 100),
459
- value: String(index),
460
- description: method.type === 'oauth'
461
- ? 'OAuth authentication'
462
- : 'Enter API key manually',
463
- }));
464
- await interaction.editReply({
465
- content: `**Authenticate with ${ctx.providerName}**\nSelect authentication method:`,
466
- components: [
467
- buildSelectMenu({
468
- customId: `login_select:${hash}`,
469
- placeholder: 'Select authentication method',
470
- options,
471
- }),
472
- ],
473
- });
474
- return;
475
- }
476
- if (step.type === 'prompt') {
477
- const prompt = step.prompt;
478
- if (prompt.type === 'select') {
479
- const options = prompt.options.slice(0, 25).map((opt) => ({
480
- label: opt.label.slice(0, 100),
481
- value: opt.value,
482
- description: opt.hint?.slice(0, 100),
483
- }));
484
- await interaction.editReply({
485
- content: `**Authenticate with ${ctx.providerName}**\n${prompt.message}`,
486
- components: [
487
- buildSelectMenu({
488
- customId: `login_select:${hash}`,
489
- placeholder: prompt.message.slice(0, 150),
490
- options,
491
- }),
492
- ],
493
- });
494
- return;
495
- }
496
- if (prompt.type === 'text') {
497
- // Text prompts need a modal, but we're deferred. Show a button.
498
- const button = new ButtonBuilder()
499
- .setCustomId(`login_text_btn:${hash}`)
500
- .setLabel(prompt.message.slice(0, 80))
501
- .setStyle(ButtonStyle.Primary);
502
- await interaction.editReply({
503
- content: `**Authenticate with ${ctx.providerName}**\n${prompt.message}`,
504
- components: [
505
- new ActionRowBuilder().addComponents(button),
506
- ],
507
- });
508
- return;
509
- }
510
- }
511
- }
512
- function buildPromptSteps(method) {
513
- return (method.prompts || []).map((prompt) => ({
514
- type: 'prompt',
515
- prompt,
516
- }));
517
- }
518
- // ── Text prompt button + modal ──────────────────────────────────
519
- // When a text prompt needs to be shown but we're in a deferred state,
520
- // we show a button. Clicking it opens a modal for text input.
521
- export async function handleLoginTextButton(interaction) {
522
- if (!interaction.customId.startsWith('login_text_btn:')) {
523
- return;
524
- }
525
- const hash = interaction.customId.replace('login_text_btn:', '');
526
- const ctx = pendingLoginContexts.get(hash);
527
- if (!ctx) {
528
- await interaction.reply({
529
- content: 'Selection expired. Please run /login again.',
530
- flags: MessageFlags.Ephemeral,
531
- });
532
- return;
533
- }
534
- const step = ctx.steps[ctx.stepIndex];
535
- if (!step || step.type !== 'prompt' || step.prompt.type !== 'text') {
536
- await interaction.reply({
537
- content: 'Invalid state. Please run /login again.',
538
- flags: MessageFlags.Ephemeral,
539
- });
540
- return;
541
- }
542
- const modal = new ModalBuilder()
543
- .setCustomId(`login_text:${hash}`)
544
- .setTitle(`${ctx.providerName || 'Provider'} Login`.slice(0, 45));
545
- const textInput = new TextInputBuilder()
546
- .setCustomId('prompt_value')
547
- .setLabel(step.prompt.message.slice(0, 45))
548
- .setPlaceholder(step.prompt.type === 'text' ? (step.prompt.placeholder || '') : '')
549
- .setStyle(TextInputStyle.Short)
550
- .setRequired(true);
551
- modal.addComponents(new ActionRowBuilder().addComponents(textInput));
552
- await interaction.showModal(modal);
553
- }
554
- export async function handleLoginTextModalSubmit(interaction) {
555
- if (!interaction.customId.startsWith('login_text:')) {
556
- return;
557
- }
558
- await interaction.deferUpdate();
559
- const hash = interaction.customId.replace('login_text:', '');
560
- const ctx = pendingLoginContexts.get(hash);
561
- if (!ctx) {
562
- await interaction.editReply({
563
- content: 'Selection expired. Please run /login again.',
564
- components: [],
565
- });
566
- return;
567
- }
568
- const step = ctx.steps[ctx.stepIndex];
569
- if (!step || step.type !== 'prompt' || step.prompt.type !== 'text') {
570
- await interaction.editReply({
571
- content: 'Invalid state. Please run /login again.',
572
- components: [],
573
- });
574
- return;
575
- }
576
- const value = interaction.fields.getTextInputValue('prompt_value');
577
- if (!value?.trim()) {
578
- await interaction.editReply({
579
- content: 'A value is required.',
580
- components: [],
581
- });
582
- return;
583
- }
584
- ctx.inputs[step.prompt.key] = value.trim();
585
- ctx.stepIndex++;
586
- await showNextStep(interaction, ctx, hash);
587
- }
588
- // ── API key button + modal ──────────────────────────────────────
589
- // When we're deferred and need an API key modal, show a button first.
590
- export async function handleLoginApiKeyButton(interaction) {
591
- if (!interaction.customId.startsWith('login_apikey_btn:')) {
592
- return;
593
- }
594
- const hash = interaction.customId.replace('login_apikey_btn:', '');
595
- const ctx = pendingLoginContexts.get(hash);
596
- if (!ctx || !ctx.providerName) {
597
- await interaction.reply({
598
- content: 'Selection expired. Please run /login again.',
599
- flags: MessageFlags.Ephemeral,
600
- });
601
- return;
602
- }
603
- await showApiKeyModal(interaction, hash, ctx.providerName);
604
- }
605
- async function showApiKeyModal(interaction, hash, providerName) {
606
- const modal = new ModalBuilder()
607
- .setCustomId(`login_apikey:${hash}`)
608
- .setTitle(`${providerName} API Key`.slice(0, 45));
609
- const apiKeyInput = new TextInputBuilder()
610
- .setCustomId('apikey')
611
- .setLabel('API Key')
612
- .setPlaceholder('sk-...')
613
- .setStyle(TextInputStyle.Short)
614
- .setRequired(true);
615
- modal.addComponents(new ActionRowBuilder().addComponents(apiKeyInput));
616
- await interaction.showModal(modal);
617
- }
618
- // ── OAuth code submission (code mode) ───────────────────────────
619
- // When the OAuth flow returns method="code", the user completes login
620
- // in a browser (possibly on a different machine) and pastes the final
621
- // callback URL or authorization code here.
622
- export async function handleOAuthCodeButton(interaction) {
623
- if (!interaction.customId.startsWith('login_oauth_code_btn:')) {
624
- return;
625
- }
626
- const hash = interaction.customId.replace('login_oauth_code_btn:', '');
627
- const ctx = pendingLoginContexts.get(hash);
628
- if (!ctx || !ctx.providerId || !ctx.providerName) {
629
- await interaction.reply({
630
- content: 'Selection expired. Please run /login again.',
631
- flags: MessageFlags.Ephemeral,
632
- });
633
- return;
634
- }
635
- const modal = new ModalBuilder()
636
- .setCustomId(`login_oauth_code:${hash}`)
637
- .setTitle(`${ctx.providerName} Authorization`.slice(0, 45));
638
- const codeInput = new TextInputBuilder()
639
- .setCustomId('oauth_code')
640
- .setLabel('Authorization code or callback URL')
641
- .setPlaceholder('Paste the code or full callback URL')
642
- .setStyle(TextInputStyle.Paragraph)
643
- .setRequired(true);
644
- modal.addComponents(new ActionRowBuilder().addComponents(codeInput));
645
- await interaction.showModal(modal);
646
- }
647
- export async function handleOAuthCodeModalSubmit(interaction) {
648
- if (!interaction.customId.startsWith('login_oauth_code:')) {
649
- return;
650
- }
651
- await interaction.deferUpdate();
652
- const hash = interaction.customId.replace('login_oauth_code:', '');
653
- const ctx = pendingLoginContexts.get(hash);
654
- if (!ctx || !ctx.providerId || !ctx.providerName || ctx.methodIndex === undefined) {
655
- await interaction.editReply({
656
- content: 'Session expired. Please run /login again.',
657
- components: [],
658
- });
659
- return;
660
- }
661
- const code = interaction.fields.getTextInputValue('oauth_code')?.trim();
662
- if (!code) {
663
- await interaction.editReply({
664
- content: 'Authorization code is required.',
665
- components: [],
666
- });
667
- return;
668
- }
669
- try {
670
- const getClient = await initializeOpencodeForDirectory(ctx.dir);
671
- if (getClient instanceof Error) {
672
- await interaction.editReply({
673
- content: getClient.message,
674
- components: [],
675
- });
676
- return;
677
- }
678
- await interaction.editReply({
679
- content: `**Authenticating with ${ctx.providerName}**\nVerifying authorization...`,
680
- components: [],
681
- });
682
- const callbackResponse = await getClient().provider.oauth.callback({
683
- providerID: ctx.providerId,
684
- method: ctx.methodIndex,
685
- code,
686
- directory: ctx.dir,
687
- });
688
- if (callbackResponse.error) {
689
- pendingLoginContexts.delete(hash);
690
- await interaction.editReply({
691
- content: `**Authentication Failed**\n${extractErrorMessage({ error: callbackResponse.error, fallback: 'Authorization code was invalid or expired' })}`,
692
- components: [],
693
- });
694
- return;
695
- }
696
- await getClient().instance.dispose({ directory: ctx.dir });
697
- clearModelListCache();
698
- pendingLoginContexts.delete(hash);
699
- await interaction.editReply({
700
- content: `✅ **Successfully authenticated with ${ctx.providerName}!**\n\nYou can now use models from this provider.`,
701
- components: [],
702
- });
703
- }
704
- catch (error) {
705
- loginLogger.error('OAuth code submission error:', error);
706
- pendingLoginContexts.delete(hash);
707
- await interaction.editReply({
708
- content: `**Authentication Failed**\n${error instanceof Error ? error.message : 'Unknown error'}`,
709
- components: [],
710
- });
711
- }
712
- }
713
- export async function handleApiKeyModalSubmit(interaction) {
714
- if (!interaction.customId.startsWith('login_apikey:')) {
715
- return;
716
- }
717
- await interaction.deferReply({ flags: MessageFlags.Ephemeral });
718
- const hash = interaction.customId.replace('login_apikey:', '');
719
- const ctx = pendingLoginContexts.get(hash);
720
- if (!ctx || !ctx.providerId || !ctx.providerName) {
721
- await interaction.editReply({
722
- content: 'Session expired. Please run /login again.',
723
- });
724
- return;
725
- }
726
- const apiKey = interaction.fields.getTextInputValue('apikey');
727
- if (!apiKey?.trim()) {
728
- await interaction.editReply({ content: 'API key is required.' });
729
- return;
730
- }
731
- try {
732
- const getClient = await initializeOpencodeForDirectory(ctx.dir);
733
- if (getClient instanceof Error) {
734
- await interaction.editReply({ content: getClient.message });
735
- return;
736
- }
737
- await getClient().auth.set({
738
- providerID: ctx.providerId,
739
- auth: { type: 'api', key: apiKey.trim() },
740
- });
741
- // Dispose to refresh provider state so new credentials are recognized
742
- await getClient().instance.dispose({ directory: ctx.dir });
743
- clearModelListCache();
744
- await interaction.editReply({
745
- content: `✅ **Successfully authenticated with ${ctx.providerName}!**\n\nYou can now use models from this provider.`,
746
- });
747
- pendingLoginContexts.delete(hash);
748
- }
749
- catch (error) {
750
- loginLogger.error('API key save error:', error);
751
- await interaction.editReply({
752
- content: `**Failed to save API key**\n${error instanceof Error ? error.message : 'Unknown error'}`,
753
- });
754
- }
755
- }
756
- // ── OAuth flow ──────────────────────────────────────────────────
757
- async function startOAuthFlow(interaction, ctx, hash) {
758
- if (!ctx.providerId || ctx.methodIndex === undefined) {
759
- await interaction.editReply({
760
- content: 'Invalid context for OAuth flow',
761
- components: [],
762
- });
763
- return;
764
- }
765
- try {
766
- const getClient = await initializeOpencodeForDirectory(ctx.dir);
767
- if (getClient instanceof Error) {
768
- await interaction.editReply({
769
- content: getClient.message,
770
- components: [],
771
- });
772
- return;
773
- }
774
- await interaction.editReply({
775
- content: `**Authenticating with ${ctx.providerName}**\nStarting authorization...`,
776
- components: [],
777
- });
778
- // Direct fetch to the server because the SDK's buildClientParams drops
779
- // unknown keys — `inputs` would be silently stripped. The server accepts
780
- // `inputs` in the body (see opencode server/routes/provider.ts).
781
- const port = getOpencodeServerPort();
782
- if (!port) {
783
- await interaction.editReply({
784
- content: 'OpenCode server is not running. Please try again.',
785
- components: [],
786
- });
787
- return;
788
- }
789
- const hasInputs = Object.keys(ctx.inputs).length > 0;
790
- const authorizeUrl = new URL(`/provider/${encodeURIComponent(ctx.providerId)}/oauth/authorize`, `http://127.0.0.1:${port}`);
791
- authorizeUrl.searchParams.set('directory', ctx.dir);
792
- const fetchHeaders = {
793
- 'Content-Type': 'application/json',
794
- 'x-opencode-directory': ctx.dir,
795
- ...getOpencodeServerAuthHeaders(),
796
- };
797
- const authorizeRes = await fetch(authorizeUrl, {
798
- method: 'POST',
799
- headers: fetchHeaders,
800
- body: JSON.stringify({
801
- method: ctx.methodIndex,
802
- ...(hasInputs ? { inputs: ctx.inputs } : {}),
803
- }),
804
- });
805
- if (!authorizeRes.ok) {
806
- const errorText = await authorizeRes.text().catch(() => '');
807
- let errorMessage = 'Unknown error';
808
- try {
809
- const parsed = JSON.parse(errorText);
810
- errorMessage = parsed?.data?.message || parsed?.message || errorMessage;
811
- }
812
- catch {
813
- errorMessage = errorText || errorMessage;
814
- }
815
- await interaction.editReply({
816
- content: `Failed to start authorization: ${errorMessage}`,
817
- components: [],
818
- });
819
- return;
820
- }
821
- const loginData = (await authorizeRes.json());
822
- if (!loginData) {
823
- await interaction.editReply({
824
- content: 'Failed to parse authorization response',
825
- components: [],
826
- });
827
- return;
828
- }
829
- const { url, method, instructions } = loginData;
830
- let message = `**Authenticating with ${ctx.providerName}**\n\n`;
831
- message += `Open this URL to authorize:\n${url}\n\n`;
832
- if (instructions) {
833
- // Match "code: ABC-123" or "code: WXYZ1234" but not natural language
834
- // like "code will". Require a colon separator and uppercase alphanum code.
835
- const codeMatch = instructions.match(/code:\s*([A-Z0-9][A-Z0-9-]+)/);
836
- if (codeMatch) {
837
- message += `**Code:** \`${codeMatch[1]}\`\n\n`;
838
- }
839
- else {
840
- message += `${instructions}\n\n`;
841
- }
842
- }
843
- if (method === 'auto') {
844
- message += '_Waiting for authorization to complete..._';
845
- }
846
- if (method === 'code') {
847
- // Code mode: show a button to paste the auth code/URL after
848
- // completing login in a browser (possibly on a different machine).
849
- const button = new ButtonBuilder()
850
- .setCustomId(`login_oauth_code_btn:${hash}`)
851
- .setLabel('Paste authorization code or callback url')
852
- .setStyle(ButtonStyle.Primary);
853
- await interaction.editReply({
854
- content: message,
855
- components: [
856
- new ActionRowBuilder().addComponents(button),
857
- ],
858
- });
859
- // Don't delete context — we need it for the code submission
860
- return;
861
- }
862
- await interaction.editReply({ content: message, components: [] });
863
- // Auto mode: poll for completion (device flow / localhost callback)
864
- const callbackResponse = await getClient().provider.oauth.callback({
865
- providerID: ctx.providerId,
866
- method: ctx.methodIndex,
867
- directory: ctx.dir,
868
- });
869
- if (callbackResponse.error) {
870
- pendingLoginContexts.delete(hash);
871
- await interaction.editReply({
872
- content: `**Authentication Failed**\n${extractErrorMessage({ error: callbackResponse.error, fallback: 'Authorization was not completed' })}`,
873
- components: [],
874
- });
875
- return;
876
- }
877
- await getClient().instance.dispose({ directory: ctx.dir });
878
- clearModelListCache();
879
- pendingLoginContexts.delete(hash);
880
- await interaction.editReply({
881
- content: `✅ **Successfully authenticated with ${ctx.providerName}!**\n\nYou can now use models from this provider.`,
882
- components: [],
883
- });
884
- }
885
- catch (error) {
886
- loginLogger.error('OAuth flow error:', error);
887
- pendingLoginContexts.delete(hash);
888
- await interaction.editReply({
889
- content: `**Authentication Failed**\n${error instanceof Error ? error.message : 'Unknown error'}`,
890
- components: [],
891
- });
892
- }
893
- }