kimaki 1.3.0 → 1.5.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 (346) hide show
  1. package/assets/fonts/Geist-Bold.ttf +0 -0
  2. package/assets/fonts/Geist-Regular.ttf +0 -0
  3. package/assets/fonts/GeistMono-Regular.ttf +0 -0
  4. package/assets/fonts/OFL.txt +92 -0
  5. package/dist/agent-ui.e2e.test.js +27 -13
  6. package/dist/agent-ui.e2e.test.js.map +1 -1
  7. package/dist/agent-ui.js +2 -1
  8. package/dist/agent-ui.js.map +1 -1
  9. package/dist/analytics.e2e.test.js +1 -1
  10. package/dist/analytics.e2e.test.js.map +1 -1
  11. package/dist/autostart.d.ts +4 -0
  12. package/dist/autostart.js +55 -10
  13. package/dist/autostart.js.map +1 -1
  14. package/dist/bot.d.ts +13 -6
  15. package/dist/bot.js +17 -15
  16. package/dist/bot.js.map +1 -1
  17. package/dist/btw.e2e.test.js +3 -3
  18. package/dist/builtin-skills.d.ts +3 -0
  19. package/dist/builtin-skills.js +29 -0
  20. package/dist/builtin-skills.js.map +1 -1
  21. package/dist/builtin-skills.test.js +72 -1
  22. package/dist/builtin-skills.test.js.map +1 -1
  23. package/dist/catalog-refresh.e2e.test.js +2 -2
  24. package/dist/cli/bot.d.ts +1 -1
  25. package/dist/cli/bot.js +33 -18
  26. package/dist/cli/bot.js.map +1 -1
  27. package/dist/cli/discord.js +32 -6
  28. package/dist/cli/discord.js.map +1 -1
  29. package/dist/cli/schedule.js +23 -9
  30. package/dist/cli/schedule.js.map +1 -1
  31. package/dist/cli/session.js +37 -12
  32. package/dist/cli/session.js.map +1 -1
  33. package/dist/cli/shared.d.ts +5 -3
  34. package/dist/cli/shared.js +45 -10
  35. package/dist/cli/shared.js.map +1 -1
  36. package/dist/cli-discord.e2e.test.js +13 -8
  37. package/dist/cli-discord.e2e.test.js.map +1 -1
  38. package/dist/cli-lock.e2e.test.js +87 -20
  39. package/dist/cli-lock.e2e.test.js.map +1 -1
  40. package/dist/cli-read.e2e.test.js +18 -9
  41. package/dist/cli-read.e2e.test.js.map +1 -1
  42. package/dist/cli-sessions.e2e.test.js +4 -3
  43. package/dist/cli-sessions.e2e.test.js.map +1 -1
  44. package/dist/cli.js +2 -0
  45. package/dist/cli.js.map +1 -1
  46. package/dist/commands/preference-commands.d.ts +4 -0
  47. package/dist/commands/preference-commands.js +38 -4
  48. package/dist/commands/preference-commands.js.map +1 -1
  49. package/dist/commands/session-commands.js +11 -8
  50. package/dist/commands/session-commands.js.map +1 -1
  51. package/dist/commands/thread-commands.js +94 -24
  52. package/dist/commands/thread-commands.js.map +1 -1
  53. package/dist/commands/worktree-commands.d.ts +5 -6
  54. package/dist/commands/worktree-commands.js +8 -7
  55. package/dist/commands/worktree-commands.js.map +1 -1
  56. package/dist/commands.e2e.test.js +25 -21
  57. package/dist/commands.e2e.test.js.map +1 -1
  58. package/dist/coordinator-agents.e2e.test.d.ts +1 -0
  59. package/dist/coordinator-agents.e2e.test.js +113 -0
  60. package/dist/coordinator-agents.e2e.test.js.map +1 -0
  61. package/dist/coordinator-idle.e2e.test.d.ts +1 -0
  62. package/dist/coordinator-idle.e2e.test.js +100 -0
  63. package/dist/coordinator-idle.e2e.test.js.map +1 -0
  64. package/dist/coordinator-queue.e2e.test.d.ts +1 -0
  65. package/dist/coordinator-queue.e2e.test.js +244 -0
  66. package/dist/coordinator-queue.e2e.test.js.map +1 -0
  67. package/dist/coordinator-warmup.e2e.test.d.ts +1 -0
  68. package/dist/coordinator-warmup.e2e.test.js +131 -0
  69. package/dist/coordinator-warmup.e2e.test.js.map +1 -0
  70. package/dist/coordinator.d.ts +6 -0
  71. package/dist/coordinator.e2e.test.d.ts +1 -0
  72. package/dist/coordinator.e2e.test.js +505 -0
  73. package/dist/coordinator.e2e.test.js.map +1 -0
  74. package/dist/coordinator.js +164 -0
  75. package/dist/coordinator.js.map +1 -0
  76. package/dist/db.d.ts +78 -3
  77. package/dist/db.test.js +1 -0
  78. package/dist/db.test.js.map +1 -1
  79. package/dist/diagram.d.ts +11 -0
  80. package/dist/diagram.js +232 -0
  81. package/dist/diagram.js.map +1 -0
  82. package/dist/diagram.test.d.ts +1 -0
  83. package/dist/diagram.test.js +52 -0
  84. package/dist/diagram.test.js.map +1 -0
  85. package/dist/duration.js +13 -5
  86. package/dist/duration.js.map +1 -1
  87. package/dist/effects.d.ts +6 -1
  88. package/dist/effects.js +97 -26
  89. package/dist/effects.js.map +1 -1
  90. package/dist/event-loop.d.ts +2 -3
  91. package/dist/event-loop.js +74 -44
  92. package/dist/event-loop.js.map +1 -1
  93. package/dist/format-parts.d.ts +21 -4
  94. package/dist/format-parts.js +40 -23
  95. package/dist/format-parts.js.map +1 -1
  96. package/dist/gateway-replay.e2e.test.js +4 -4
  97. package/dist/harness.e2e.test.js +2 -2
  98. package/dist/harness.e2e.test.js.map +1 -1
  99. package/dist/hello-thread.e2e.test.js +56 -5
  100. package/dist/hello-thread.e2e.test.js.map +1 -1
  101. package/dist/ingress.js +47 -12
  102. package/dist/ingress.js.map +1 -1
  103. package/dist/interaction-context.d.ts +4 -4
  104. package/dist/interaction-context.js +9 -7
  105. package/dist/interaction-context.js.map +1 -1
  106. package/dist/interrupt.e2e.test.js +8 -5
  107. package/dist/interrupt.e2e.test.js.map +1 -1
  108. package/dist/legacy.e2e.test.js +1 -1
  109. package/dist/lock-routes.d.ts +83 -31
  110. package/dist/lock-routes.js +68 -8
  111. package/dist/lock-routes.js.map +1 -1
  112. package/dist/lock-server.d.ts +3 -2
  113. package/dist/lock-server.js +23 -7
  114. package/dist/lock-server.js.map +1 -1
  115. package/dist/main.d.ts +6 -3
  116. package/dist/main.js +14 -4
  117. package/dist/main.js.map +1 -1
  118. package/dist/mainmast-idle.e2e.test.d.ts +1 -0
  119. package/dist/mainmast-idle.e2e.test.js +99 -0
  120. package/dist/mainmast-idle.e2e.test.js.map +1 -0
  121. package/dist/mainmast-queue.e2e.test.d.ts +1 -0
  122. package/dist/mainmast-queue.e2e.test.js +244 -0
  123. package/dist/mainmast-queue.e2e.test.js.map +1 -0
  124. package/dist/mainmast-warmup.e2e.test.d.ts +1 -0
  125. package/dist/mainmast-warmup.e2e.test.js +130 -0
  126. package/dist/mainmast-warmup.e2e.test.js.map +1 -0
  127. package/dist/mainmast.d.ts +6 -0
  128. package/dist/mainmast.e2e.test.d.ts +1 -0
  129. package/dist/mainmast.e2e.test.js +428 -0
  130. package/dist/mainmast.e2e.test.js.map +1 -0
  131. package/dist/mainmast.js +156 -0
  132. package/dist/mainmast.js.map +1 -0
  133. package/dist/markdown/markdown.test.js +14 -4
  134. package/dist/markdown/markdown.test.js.map +1 -1
  135. package/dist/markdown/render-markdown.js +9 -6
  136. package/dist/markdown/render-markdown.js.map +1 -1
  137. package/dist/onboarding-cli.e2e.test.js +7 -6
  138. package/dist/onboarding-cli.e2e.test.js.map +1 -1
  139. package/dist/onboarding.d.ts +3 -10
  140. package/dist/onboarding.e2e.test.js +8 -10
  141. package/dist/onboarding.e2e.test.js.map +1 -1
  142. package/dist/onboarding.js +14 -24
  143. package/dist/onboarding.js.map +1 -1
  144. package/dist/permissions.e2e.test.js +3 -3
  145. package/dist/plugin/coordinator.d.ts +4 -0
  146. package/dist/plugin/coordinator.js +389 -0
  147. package/dist/plugin/coordinator.js.map +1 -0
  148. package/dist/plugin/index.js +93 -61
  149. package/dist/plugin/index.js.map +1 -1
  150. package/dist/plugin/mainmast.d.ts +4 -0
  151. package/dist/plugin/mainmast.js +379 -0
  152. package/dist/plugin/mainmast.js.map +1 -0
  153. package/dist/plugin.e2e.test.js +1 -1
  154. package/dist/preference-commands.e2e.test.js +103 -24
  155. package/dist/preference-commands.e2e.test.js.map +1 -1
  156. package/dist/project.d.ts +1 -1
  157. package/dist/prompt.d.ts +22 -9
  158. package/dist/prompt.js +64 -48
  159. package/dist/prompt.js.map +1 -1
  160. package/dist/questions.e2e.test.js +13 -13
  161. package/dist/queue-sources.e2e.test.d.ts +1 -0
  162. package/dist/queue-sources.e2e.test.js +168 -0
  163. package/dist/queue-sources.e2e.test.js.map +1 -0
  164. package/dist/queue.d.ts +9 -1
  165. package/dist/queue.e2e.test.js +48 -30
  166. package/dist/queue.e2e.test.js.map +1 -1
  167. package/dist/queue.js +97 -24
  168. package/dist/queue.js.map +1 -1
  169. package/dist/queue.test.d.ts +1 -0
  170. package/dist/queue.test.js +57 -0
  171. package/dist/queue.test.js.map +1 -0
  172. package/dist/remote-send.e2e.test.js +6 -6
  173. package/dist/remote-send.js +2 -1
  174. package/dist/remote-send.js.map +1 -1
  175. package/dist/renderer.e2e.test.js +7 -7
  176. package/dist/restart.e2e.test.js +2 -2
  177. package/dist/routines.e2e.test.js +2 -2
  178. package/dist/scheduler.d.ts +3 -3
  179. package/dist/scheduler.e2e.test.js +43 -20
  180. package/dist/scheduler.e2e.test.js.map +1 -1
  181. package/dist/scheduler.js +4 -2
  182. package/dist/scheduler.js.map +1 -1
  183. package/dist/schema-sql.d.ts +1 -1
  184. package/dist/schema-sql.js +1 -1
  185. package/dist/schema-sql.js.map +1 -1
  186. package/dist/schema.d.ts +152 -6
  187. package/dist/schema.js +12 -0
  188. package/dist/schema.js.map +1 -1
  189. package/dist/session-commands.e2e.test.js +36 -11
  190. package/dist/session-commands.e2e.test.js.map +1 -1
  191. package/dist/session-events.d.ts +18 -6
  192. package/dist/session-events.js +175 -27
  193. package/dist/session-events.js.map +1 -1
  194. package/dist/session-ops.e2e.test.js +63 -12
  195. package/dist/session-ops.e2e.test.js.map +1 -1
  196. package/dist/sessions.d.ts +44 -21
  197. package/dist/sessions.js +177 -65
  198. package/dist/sessions.js.map +1 -1
  199. package/dist/shell.e2e.test.js +4 -4
  200. package/dist/slash-commands.js +6 -4
  201. package/dist/slash-commands.js.map +1 -1
  202. package/dist/slash-commands.test.js +2 -0
  203. package/dist/slash-commands.test.js.map +1 -1
  204. package/dist/sleep.e2e.test.js +29 -14
  205. package/dist/sleep.e2e.test.js.map +1 -1
  206. package/dist/sleeps.d.ts +2 -1
  207. package/dist/sleeps.js +21 -3
  208. package/dist/sleeps.js.map +1 -1
  209. package/dist/store.d.ts +1 -0
  210. package/dist/store.js +3 -2
  211. package/dist/store.js.map +1 -1
  212. package/dist/system-prompt.d.ts +5 -15
  213. package/dist/system-prompt.js +180 -131
  214. package/dist/system-prompt.js.map +1 -1
  215. package/dist/test/generate-log-plugin/index.d.ts +3 -0
  216. package/dist/test/generate-log-plugin/index.js +15 -0
  217. package/dist/test/generate-log-plugin/index.js.map +1 -0
  218. package/dist/test/harness.d.ts +20 -2
  219. package/dist/test/harness.js +51 -11
  220. package/dist/test/harness.js.map +1 -1
  221. package/dist/test/replay.js +11 -8
  222. package/dist/test/replay.js.map +1 -1
  223. package/dist/thread-reducer.d.ts +29 -6
  224. package/dist/thread-reducer.fixtures.test.js +58 -51
  225. package/dist/thread-reducer.fixtures.test.js.map +1 -1
  226. package/dist/thread-reducer.js +109 -50
  227. package/dist/thread-reducer.js.map +1 -1
  228. package/dist/thread-reducer.test.js +190 -48
  229. package/dist/thread-reducer.test.js.map +1 -1
  230. package/dist/tunnel.d.ts +9 -0
  231. package/dist/tunnel.js +117 -28
  232. package/dist/tunnel.js.map +1 -1
  233. package/dist/tunnel.test.js +81 -5
  234. package/dist/tunnel.test.js.map +1 -1
  235. package/dist/voice-attachments.e2e.test.js +108 -18
  236. package/dist/voice-attachments.e2e.test.js.map +1 -1
  237. package/dist/voice-call.e2e.test.js +9 -9
  238. package/dist/voice-call.js +6 -6
  239. package/dist/voice-call.js.map +1 -1
  240. package/dist/voice-openai.e2e.test.js +59 -23
  241. package/dist/voice-openai.e2e.test.js.map +1 -1
  242. package/dist/voice.d.ts +1 -1
  243. package/dist/voice.js +72 -24
  244. package/dist/voice.js.map +1 -1
  245. package/dist/working-directory.e2e.test.js +11 -11
  246. package/dist/working-directory.e2e.test.js.map +1 -1
  247. package/package.json +11 -5
  248. package/skills/kimaki-tunnel/SKILL.md +3 -2
  249. package/src/agent-ui.e2e.test.ts +27 -13
  250. package/src/agent-ui.ts +2 -1
  251. package/src/analytics.e2e.test.ts +1 -1
  252. package/src/autostart.ts +55 -10
  253. package/src/bot.ts +36 -19
  254. package/src/btw.e2e.test.ts +3 -3
  255. package/src/builtin-skills.test.ts +73 -1
  256. package/src/builtin-skills.ts +33 -0
  257. package/src/catalog-refresh.e2e.test.ts +2 -2
  258. package/src/cli/bot.ts +30 -19
  259. package/src/cli/discord.ts +30 -6
  260. package/src/cli/schedule.ts +23 -9
  261. package/src/cli/session.ts +35 -12
  262. package/src/cli/shared.ts +43 -8
  263. package/src/cli-discord.e2e.test.ts +13 -8
  264. package/src/cli-lock.e2e.test.ts +88 -20
  265. package/src/cli-read.e2e.test.ts +17 -8
  266. package/src/cli-sessions.e2e.test.ts +4 -3
  267. package/src/cli.ts +2 -0
  268. package/src/commands/preference-commands.ts +38 -4
  269. package/src/commands/session-commands.ts +12 -7
  270. package/src/commands/thread-commands.ts +92 -24
  271. package/src/commands/worktree-commands.ts +10 -9
  272. package/src/commands.e2e.test.ts +25 -21
  273. package/src/coordinator-agents.e2e.test.ts +145 -0
  274. package/src/coordinator-idle.e2e.test.ts +122 -0
  275. package/src/coordinator-queue.e2e.test.ts +279 -0
  276. package/src/coordinator-warmup.e2e.test.ts +158 -0
  277. package/src/coordinator.e2e.test.ts +545 -0
  278. package/src/coordinator.ts +168 -0
  279. package/src/db.test.ts +1 -0
  280. package/src/diagram.test.ts +56 -0
  281. package/src/diagram.ts +243 -0
  282. package/src/duration.ts +13 -5
  283. package/src/effects.ts +99 -27
  284. package/src/event-loop.ts +71 -45
  285. package/src/format-parts.ts +53 -22
  286. package/src/gateway-replay.e2e.test.ts +4 -4
  287. package/src/harness.e2e.test.ts +2 -2
  288. package/src/hello-thread.e2e.test.ts +59 -5
  289. package/src/ingress.ts +44 -11
  290. package/src/interaction-context.ts +12 -11
  291. package/src/interrupt.e2e.test.ts +8 -5
  292. package/src/legacy.e2e.test.ts +1 -1
  293. package/src/lock-routes.ts +62 -8
  294. package/src/lock-server.ts +23 -7
  295. package/src/main.ts +26 -10
  296. package/src/markdown/markdown.test.ts +15 -4
  297. package/src/markdown/render-markdown.ts +9 -6
  298. package/src/onboarding-cli.e2e.test.ts +7 -6
  299. package/src/onboarding.e2e.test.ts +8 -10
  300. package/src/onboarding.ts +13 -29
  301. package/src/permissions.e2e.test.ts +3 -3
  302. package/src/plugin/coordinator.ts +401 -0
  303. package/src/plugin/index.ts +86 -59
  304. package/src/plugin.e2e.test.ts +1 -1
  305. package/src/preference-commands.e2e.test.ts +103 -23
  306. package/src/prompt.ts +87 -43
  307. package/src/questions.e2e.test.ts +13 -13
  308. package/src/queue-sources.e2e.test.ts +197 -0
  309. package/src/queue.e2e.test.ts +48 -30
  310. package/src/queue.test.ts +59 -0
  311. package/src/queue.ts +104 -24
  312. package/src/remote-send.e2e.test.ts +6 -6
  313. package/src/remote-send.ts +2 -1
  314. package/src/renderer.e2e.test.ts +7 -7
  315. package/src/restart.e2e.test.ts +2 -2
  316. package/src/routines.e2e.test.ts +2 -2
  317. package/src/scheduler.e2e.test.ts +45 -19
  318. package/src/scheduler.ts +4 -2
  319. package/src/schema-sql.ts +1 -1
  320. package/src/schema.ts +13 -0
  321. package/src/session-commands.e2e.test.ts +38 -11
  322. package/src/session-events.ts +168 -25
  323. package/src/session-ops.e2e.test.ts +64 -11
  324. package/src/sessions.ts +217 -67
  325. package/src/shell.e2e.test.ts +4 -4
  326. package/src/slash-commands.test.ts +2 -0
  327. package/src/slash-commands.ts +6 -4
  328. package/src/sleep.e2e.test.ts +30 -13
  329. package/src/sleeps.ts +20 -3
  330. package/src/store.ts +5 -2
  331. package/src/system-prompt.ts +190 -134
  332. package/src/test/generate-log-plugin/index.ts +16 -0
  333. package/src/test/harness.ts +77 -17
  334. package/src/test/replay.ts +12 -7
  335. package/src/thread-reducer.fixtures.test.ts +58 -51
  336. package/src/thread-reducer.test.ts +199 -49
  337. package/src/thread-reducer.ts +135 -66
  338. package/src/tunnel.test.ts +81 -5
  339. package/src/tunnel.ts +124 -25
  340. package/src/voice-attachments.e2e.test.ts +110 -18
  341. package/src/voice-call.e2e.test.ts +9 -9
  342. package/src/voice-call.ts +6 -6
  343. package/src/voice-openai.e2e.test.ts +64 -24
  344. package/src/voice.ts +93 -26
  345. package/src/working-directory.e2e.test.ts +11 -11
  346. package/src/message-tool.e2e.test.ts +0 -45
@@ -1,4 +1,4 @@
1
- // Commands for the session of the current thread: run control (/abort,
1
+ // Commands for the session of the current thread: run control (/abort, /reset-coordinator,
2
2
  // /queue, /queue-command, /clear-queue, /btw), history (/compact, /undo,
3
3
  // /redo) and info (/context-usage, /session-id, /diff). They only call the
4
4
  // writers in prompt.ts and sessions.ts; session output comes from events.
@@ -28,10 +28,11 @@ import {
28
28
  type InteractionRoutes,
29
29
  type SessionTarget,
30
30
  } from '../interaction-context.ts'
31
- import { shellQuote } from '../onboarding.ts'
31
+ import { shellQuote } from '../lock-server.ts'
32
32
  import { abort, clearQueue, dispatch, redo, undo } from '../prompt.ts'
33
33
  import type { Route } from '../routes.ts'
34
- import { forkBtw } from '../sessions.ts'
34
+ import { formatDuration, type Message } from '../session-events.ts'
35
+ import { endCoordinator, forkBtw } from '../sessions.ts'
35
36
 
36
37
  const execFileAsync = promisify(execFile)
37
38
 
@@ -91,34 +92,52 @@ export function parseCritiqueOutput(output: string): { ok: true; url: string; id
91
92
 
92
93
  // --- Run control
93
94
 
94
- async function abortCommand(bot: Bot, interaction: ChatInputCommandInteraction, { thread }: SessionTarget) {
95
+ async function abortCommand(bot: Bot, interaction: ChatInputCommandInteraction, { conversation }: SessionTarget) {
95
96
  await interaction.deferReply()
96
- const result = await abort(bot, { threadId: thread.id })
97
+ const result = await abort(bot, { threadId: conversation.id })
97
98
  if (result instanceof Error) return replyError(interaction, result)
98
99
  const note = result.cleared > 0 ? `, cleared ${result.cleared} queued message${result.cleared > 1 ? 's' : ''}` : ''
99
100
  await interaction.editReply({ content: `Request **aborted**${note}` })
100
101
  }
101
102
 
103
+ // Also with coordinator mode off: the channel keeps its binding until a reset.
104
+ async function resetCoordinatorCommand(bot: Bot, interaction: ChatInputCommandInteraction) {
105
+ const target = await resolveTarget(bot, interaction.channelId)
106
+ if (target instanceof Error) return replyError(interaction, target)
107
+ if (target.conversation?.isThread()) return replyError(interaction, new ConfigError({ reason: 'Use /reset-coordinator in the project channel, not in a thread' }))
108
+ const channelId = target.channelId
109
+ if (!bot.store.getState().roots[channelId]) {
110
+ await interaction.reply({ content: 'This channel has no coordinator session', flags: MessageFlags.Ephemeral })
111
+ return
112
+ }
113
+ await interaction.deferReply()
114
+ const stopped = await abort(bot, { threadId: channelId })
115
+ if (stopped instanceof Error) return replyError(interaction, stopped)
116
+ const ended = await endCoordinator(bot, channelId)
117
+ if (ended instanceof Error) return replyError(interaction, ended)
118
+ await interaction.editReply({ content: 'Coordinator context reset. The next message starts a new coordinator session' })
119
+ }
120
+
102
121
  // /queue and /queue-command: the echo reply is the queued message the ack points at.
103
- async function queueInput(bot: Bot, { interaction, thread, route, echo }: { interaction: ChatInputCommandInteraction; thread: SessionTarget['thread']; route: Route; echo: string }) {
122
+ async function queueInput(bot: Bot, { interaction, conversation, route, echo }: { interaction: ChatInputCommandInteraction; conversation: SessionTarget['conversation']; route: Route; echo: string }) {
104
123
  const author = authorOf(interaction)
105
124
  const reply = await replyWithEcho(interaction, { author, text: echo })
106
125
  if (reply instanceof Error) return replyError(interaction, reply)
107
- const result = await dispatch(bot, { thread, route, author, messageId: reply.id })
126
+ const result = await dispatch(bot, { conversation, route, author, messageId: reply.id })
108
127
  if (result instanceof Error) return replyError(interaction, result)
109
128
  }
110
129
 
111
- async function queueCommand(bot: Bot, interaction: ChatInputCommandInteraction, { thread }: SessionTarget) {
130
+ async function queueCommand(bot: Bot, interaction: ChatInputCommandInteraction, { conversation }: SessionTarget) {
112
131
  const text = interaction.options.getString('message', true).trim()
113
- return queueInput(bot, { interaction, thread, route: { kind: 'queue', text }, echo: text })
132
+ return queueInput(bot, { interaction, conversation, route: { kind: 'queue', text }, echo: text })
114
133
  }
115
134
 
116
- async function queueOpencodeCommand(bot: Bot, interaction: ChatInputCommandInteraction, { thread }: SessionTarget) {
135
+ async function queueOpencodeCommand(bot: Bot, interaction: ChatInputCommandInteraction, { conversation }: SessionTarget) {
117
136
  const name = interaction.options.getString('command')?.trim().replace(/^\//, '') ?? ''
118
137
  const args = (interaction.options.getString('arguments') ?? '').trim()
119
138
  if (!name) return replyError(interaction, new ConfigError({ reason: 'Pass a command name, for example /queue-command command:review' }))
120
139
  const echo = `/${name} ${args}`.trim()
121
- return queueInput(bot, { interaction, thread, route: { kind: 'command', name, arguments: args, queue: true }, echo })
140
+ return queueInput(bot, { interaction, conversation, route: { kind: 'command', name, arguments: args, queue: true }, echo })
122
141
  }
123
142
 
124
143
  async function queueCommandChoices(bot: Bot, interaction: AutocompleteInteraction) {
@@ -135,19 +154,19 @@ async function queueCommandChoices(bot: Bot, interaction: AutocompleteInteractio
135
154
  )
136
155
  }
137
156
 
138
- async function clearQueueCommand(bot: Bot, interaction: ChatInputCommandInteraction, { thread }: SessionTarget) {
157
+ async function clearQueueCommand(bot: Bot, interaction: ChatInputCommandInteraction, { conversation }: SessionTarget) {
139
158
  await interaction.deferReply()
140
- const result = await clearQueue(bot, { threadId: thread.id, position: interaction.options.getInteger('position') })
159
+ const result = await clearQueue(bot, { threadId: conversation.id, position: interaction.options.getInteger('position') })
141
160
  if (result instanceof Error) return replyError(interaction, result)
142
161
  const content =
143
162
  result.cleared === 0 ? 'No queued messages' : `-# Cleared ${result.cleared} queued message${result.cleared > 1 ? 's' : ''}`
144
163
  await interaction.editReply({ content })
145
164
  }
146
165
 
147
- async function btwCommand(bot: Bot, interaction: ChatInputCommandInteraction, { thread }: SessionTarget) {
166
+ async function btwCommand(bot: Bot, interaction: ChatInputCommandInteraction, { conversation }: SessionTarget) {
148
167
  const text = interaction.options.getString('prompt', true).trim()
149
168
  await interaction.deferReply()
150
- const result = await forkBtw(bot, { sourceThread: thread, text, author: authorOf(interaction), messageId: interaction.id })
169
+ const result = await forkBtw(bot, { source: conversation, text, author: authorOf(interaction), messageId: interaction.id })
151
170
  if (result instanceof Error) return replyError(interaction, result)
152
171
  await interaction.editReply({ content: `Session forked! Continue in <#${result.threadId}>` })
153
172
  }
@@ -161,9 +180,9 @@ async function compactCommand(bot: Bot, interaction: ChatInputCommandInteraction
161
180
  await interaction.editReply({ content: 'Compacting the session context' })
162
181
  }
163
182
 
164
- async function undoCommand(bot: Bot, interaction: ChatInputCommandInteraction, { thread }: SessionTarget) {
183
+ async function undoCommand(bot: Bot, interaction: ChatInputCommandInteraction, { conversation }: SessionTarget) {
165
184
  await interaction.deferReply()
166
- const result = await undo(bot, { threadId: thread.id })
185
+ const result = await undo(bot, { threadId: conversation.id })
167
186
  if (result instanceof Error) return replyError(interaction, result)
168
187
  if (!result.reverted) {
169
188
  await interaction.editReply({ content: 'No messages to undo' })
@@ -172,9 +191,9 @@ async function undoCommand(bot: Bot, interaction: ChatInputCommandInteraction, {
172
191
  await interaction.editReply({ content: 'Undone - removed the last turn from the session. File changes were kept' })
173
192
  }
174
193
 
175
- async function redoCommand(bot: Bot, interaction: ChatInputCommandInteraction, { thread }: SessionTarget) {
194
+ async function redoCommand(bot: Bot, interaction: ChatInputCommandInteraction, { conversation }: SessionTarget) {
176
195
  await interaction.deferReply()
177
- const result = await redo(bot, { threadId: thread.id })
196
+ const result = await redo(bot, { threadId: conversation.id })
178
197
  if (result instanceof Error) return replyError(interaction, result)
179
198
  const content = {
180
199
  nothing: 'Nothing to redo - no previous undo found',
@@ -186,18 +205,62 @@ async function redoCommand(bot: Bot, interaction: ChatInputCommandInteraction, {
186
205
 
187
206
  // --- Info
188
207
 
208
+ // What the session does right now, from OpenCode's own message timestamps. Newest-first messages.
209
+ function sessionStatus({ running, messages, now }: { running: boolean; messages: readonly Message[]; now: number }): string[] {
210
+ const ago = (time: number) => formatDuration(now - time)
211
+ const promptIndex = messages.findIndex((message) => message.type === 'user')
212
+ const replyIndex = messages.findIndex((message) => message.type === 'assistant')
213
+ const prompt = messages[promptIndex]
214
+ const latest = messages[replyIndex]
215
+ const reply = latest?.type === 'assistant' ? latest : undefined
216
+ const unanswered = prompt !== undefined && (reply === undefined || replyIndex > promptIndex)
217
+ if (!running) {
218
+ if (unanswered) return [`**Status:** idle, the last prompt (${ago(prompt.time.created)} ago) has no reply`]
219
+ return [reply ? `**Status:** idle for ${ago(reply.time.completed ?? reply.time.created)}` : '**Status:** idle']
220
+ }
221
+ // A run starts at a user prompt; synthetic items also arrive mid-run, so they count only without one.
222
+ const start = prompt ?? messages.find((message) => message.type === 'synthetic')
223
+ const status = start ? `**Status:** running for ${ago(start.time.created)}` : '**Status:** running'
224
+ if (unanswered || !reply) return [`${status}, waiting for the first model response`]
225
+ const tool = reply.content.findLast((part) => part.type === 'tool' && part.time.completed === undefined)
226
+ const reasoning = reply.content.findLast((part) => part.type === 'reasoning' && part.time !== undefined && part.time.completed === undefined)
227
+ const doing =
228
+ reply.time.completed !== undefined ? 'between steps'
229
+ : tool?.type === 'tool' ? `running ${tool.name} for ${ago(tool.time.ran ?? tool.time.created)}`
230
+ : reasoning?.type === 'reasoning' && reasoning.time ? `thinking for ${ago(reasoning.time.created)}`
231
+ : reply.time.streamed === undefined ? `waiting for the model for ${ago(reply.time.created)}`
232
+ : 'writing'
233
+ const activity = [
234
+ { at: reply.time.streamed, what: 'output' },
235
+ { at: reply.time.completed, what: 'step ended' },
236
+ ...reply.content.flatMap((part) => {
237
+ if (part.type === 'tool') return [{ at: part.time.completed ?? part.time.ran ?? part.time.created, what: part.name }]
238
+ if (part.type === 'reasoning') return [{ at: part.time?.completed ?? part.time?.created, what: 'thinking' }]
239
+ return []
240
+ }),
241
+ ]
242
+ const last = activity.reduce<{ at: number; what: string }>(
243
+ (latest, { at, what }) => (at !== undefined && at >= latest.at ? { at, what } : latest),
244
+ { at: reply.time.created, what: 'step started' },
245
+ )
246
+ return [`${status}, ${doing}`, `**Last activity:** ${ago(last.at)} ago, ${last.what}`]
247
+ }
248
+
189
249
  async function contextUsageCommand(bot: Bot, interaction: ChatInputCommandInteraction, { sessionId, directory }: SessionTarget) {
190
250
  await interaction.deferReply()
191
- const [info, messages, models] = await Promise.all([
251
+ const [info, messages, models, recent, active] = await Promise.all([
192
252
  oc(bot, 'session.get', (client) => client.session.get({ sessionID: sessionId })),
193
253
  oc(bot, 'message.list', (client) => client.message.list({ sessionID: sessionId, type: 'assistant', order: 'desc', limit: 20 })),
194
254
  oc(bot, 'model.list', (client) => client.model.list({ location: { directory } })),
255
+ oc(bot, 'message.list', (client) => client.message.list({ sessionID: sessionId, order: 'desc', limit: 20 })),
256
+ oc(bot, 'session.active', (client) => client.session.active()),
195
257
  ])
196
258
  if (info instanceof Error) return replyError(interaction, info)
197
259
  if (messages instanceof Error) return replyError(interaction, messages)
260
+ const status = recent instanceof Error || active instanceof Error ? [] : sessionStatus({ running: active[sessionId] !== undefined, messages: recent.data, now: Date.now() })
198
261
  const last = messages.data.find((message) => message.type === 'assistant' && message.tokens)
199
262
  if (!last || last.type !== 'assistant' || !last.tokens) {
200
- await interaction.editReply({ content: 'Token usage not available for this session yet' })
263
+ await interaction.editReply({ content: ['Token usage not available for this session yet', ...status].join('\n') })
201
264
  return
202
265
  }
203
266
  const { tokens, model } = last
@@ -210,6 +273,7 @@ async function contextUsageCommand(bot: Bot, interaction: ChatInputCommandIntera
210
273
  : `**Context usage:** ${formatted} tokens (context limit unavailable)`,
211
274
  `**Model:** ${model.providerID}/${model.id}`,
212
275
  ...(info.cost > 0 ? [`**Session cost:** $${info.cost.toFixed(4)}`] : []),
276
+ ...status,
213
277
  ]
214
278
  await interaction.editReply({ content: lines.join('\n') })
215
279
  }
@@ -217,12 +281,12 @@ async function contextUsageCommand(bot: Bot, interaction: ChatInputCommandIntera
217
281
  async function sessionIdCommand(bot: Bot, interaction: ChatInputCommandInteraction) {
218
282
  const target = await resolveTarget(bot, interaction.channelId)
219
283
  if (target instanceof Error) return replyError(interaction, target)
220
- if (!target.thread || !target.sessionId) {
284
+ if (!target.conversation || !target.sessionId) {
221
285
  await interaction.reply({ content: 'Run /session-id inside a Kimaki session thread.', flags: MessageFlags.Ephemeral })
222
286
  return
223
287
  }
224
288
  await interaction.reply({
225
- content: sessionIdReply({ sessionId: target.sessionId, threadId: target.thread.id, directory: target.directory }),
289
+ content: sessionIdReply({ sessionId: target.sessionId, threadId: target.conversation.id, directory: target.directory }),
226
290
  flags: MessageFlags.Ephemeral,
227
291
  })
228
292
  }
@@ -269,6 +333,10 @@ export const threadRoutes: InteractionRoutes = {
269
333
  definition: new SlashCommandBuilder().setName('abort').setDescription('Stop the current run and clear the queue'),
270
334
  run: inThread(abortCommand),
271
335
  },
336
+ 'reset-coordinator': {
337
+ definition: new SlashCommandBuilder().setName('reset-coordinator').setDescription('Reset the context of this channel: the next message starts a fresh coordinator session'),
338
+ run: resetCoordinatorCommand,
339
+ },
272
340
  queue: {
273
341
  definition: new SlashCommandBuilder()
274
342
  .setName('queue')
@@ -311,7 +379,7 @@ export const threadRoutes: InteractionRoutes = {
311
379
  run: diffCommand,
312
380
  },
313
381
  'context-usage': {
314
- definition: new SlashCommandBuilder().setName('context-usage').setDescription('Show token usage and context window percentage'),
382
+ definition: new SlashCommandBuilder().setName('context-usage').setDescription('Show token usage, context window percentage and whether the session is working'),
315
383
  run: inThread(contextUsageCommand),
316
384
  },
317
385
  'session-id': {
@@ -7,9 +7,9 @@
7
7
  // /merge-worktree ─▶ mergeWorktree, refused while a session runs there
8
8
 
9
9
  import crypto from 'node:crypto'
10
- import { ButtonStyle, ComponentType, SlashCommandBuilder, type ButtonInteraction, type ChatInputCommandInteraction, type ThreadChannel } from 'discord.js'
10
+ import { ButtonStyle, ComponentType, SlashCommandBuilder, type ButtonInteraction, type ChatInputCommandInteraction } from 'discord.js'
11
11
 
12
- import { oc, projectOf, rootSession, sessionDirectory, type Author, type Bot } from '../bot.ts'
12
+ import { oc, projectOf, rootSession, sessionDirectory, type Author, type Bot, type Conversation } from '../bot.ts'
13
13
  import { ConfigError, DbError } from '../errors.ts'
14
14
  import { canonicalPath } from '../file-edit-log.ts'
15
15
  import * as schema from '../schema.ts'
@@ -35,15 +35,15 @@ const identity = (tree: GitWorktree) => crypto.createHash('sha256').update(`${tr
35
35
  // A new session in a fresh checkout. In a thread the session is a fork, so it keeps the context.
36
36
  export async function newWorktree(
37
37
  bot: Bot,
38
- { channelId, sourceThread, name, baseBranch, author }: { channelId: string; sourceThread?: ThreadChannel; name?: string; baseBranch?: string; author: Author },
38
+ { channelId, source, name, baseBranch, author }: { channelId: string; source?: Conversation; name?: string; baseBranch?: string; author: Author },
39
39
  ) {
40
40
  const slug = name || `session-${crypto.randomBytes(4).toString('hex')}`
41
41
  const valid = worktreeName(slug)
42
42
  if (valid instanceof Error) return valid
43
- if (sourceThread) {
44
- const sessionId = rootSession(bot, sourceThread.id)
43
+ if (source) {
44
+ const sessionId = rootSession(bot, source.id)
45
45
  if (sessionId instanceof Error) return sessionId
46
- return fork(bot, { sourceThread, sessionId, author, name: `⬦ ${slug}`, worktree: { name: slug, baseBranch } })
46
+ return fork(bot, { source, sessionId, author, name: slug, worktree: { name: slug, baseBranch } })
47
47
  }
48
48
  const project = await projectOf(bot, channelId)
49
49
  if (project instanceof Error) return project
@@ -167,8 +167,8 @@ async function deferredTarget(bot: Bot, interaction: ChatInputCommandInteraction
167
167
  async function cwdCommand(bot: Bot, interaction: ChatInputCommandInteraction) {
168
168
  const target = await deferredTarget(bot, interaction)
169
169
  if (!target) return
170
- if (!target.thread || !target.sessionId) return replyError(interaction, new ConfigError({ reason: 'Use /cwd in a session thread.' }))
171
- const result = await sessionCwd(bot, { thread: target.thread, directory: interaction.options.getString('path') ?? undefined })
170
+ if (!target.conversation || !target.sessionId) return replyError(interaction, new ConfigError({ reason: 'Use /cwd in a session thread.' }))
171
+ const result = await sessionCwd(bot, { conversation: target.conversation, directory: interaction.options.getString('path') ?? undefined })
172
172
  if (result instanceof Error) return replyError(interaction, result)
173
173
  const content = result.requestedDirectory ? `Directory change requested: \`${result.requestedDirectory}\`` : `Working directory: \`${result.directory}\``
174
174
  return interaction.editReply({ content })
@@ -187,7 +187,8 @@ async function newWorktreeCommand(bot: Bot, interaction: ChatInputCommandInterac
187
187
  if (!target) return
188
188
  const result = await newWorktree(bot, {
189
189
  channelId: target.channelId,
190
- sourceThread: target.thread ?? undefined,
190
+ // In a coordinator channel a new worktree is a fresh session, not a fork of the coordinator.
191
+ source: target.conversation?.isThread() ? target.conversation : undefined,
191
192
  name: interaction.options.getString('name') ?? undefined,
192
193
  baseBranch: interaction.options.getString('base-branch') ?? undefined,
193
194
  author: authorOf(interaction),
@@ -79,7 +79,7 @@ test('the bot registers exactly the static and catalog commands in the guild', a
79
79
  "/clear-queue: Remove queued messages",
80
80
  "/command: Run any OpenCode command in this project",
81
81
  "/compact: Compact the session context by summarizing the history",
82
- "/context-usage: Show token usage and context window percentage",
82
+ "/context-usage: Show token usage, context window percentage and whether the session is working",
83
83
  "/cwd: Show or change this session working directory",
84
84
  "/diff: Show the git diff as a shareable URL",
85
85
  "/fork: Fork the session from a past user message",
@@ -98,11 +98,13 @@ test('the bot registers exactly the static and catalog commands in the guild', a
98
98
  "/queue-command: Queue an OpenCode command to run after the current run finishes",
99
99
  "/redo: Redo the previously undone turn",
100
100
  "/report-skill: Use when the user wants to report an opencode issue or bug. Collect standard diagnostics, add user-s",
101
+ "/reset-coordinator: Reset the context of this channel: the next message starts a fresh coordinator session",
101
102
  "/resume: Resume an existing OpenCode session in a new thread",
102
103
  "/review-cmd: review changes [commit|branch|pr], defaults to uncommitted",
103
104
  "/routines: List routines, run one now, or delete it",
104
105
  "/session-id: Show the OpenCode session ID of this thread and how to open it in OpenCode",
105
106
  "/skill: Run any OpenCode skill in this project",
107
+ "/toggle-coordinator: Turn coordinator mode on or off: one long session in this channel that starts threads",
106
108
  "/transcription-key: Set the OpenAI or Gemini API key for voice transcription and speech",
107
109
  "/undo: Undo the last turn (file changes are kept)",
108
110
  "/verbosity: Set what the bot shows in this channel",
@@ -131,13 +133,13 @@ test('/skill and /command run catalog entries through project autocomplete', asy
131
133
  --- from: assistant (TestBot)
132
134
  -# *using deterministic-provider/deterministic-v2 ⋅ build*
133
135
  ok
134
- -# *project ⋅ main ⋅ Ns ⋅ deterministic-v2*
135
- » **tommy:** /opencode explain skill-marker
136
+ -# *main ⋅ Ns ⋅ deterministic-v2*
137
+ -# » **tommy:** /opencode explain skill-marker
136
138
  skill reply
137
- -# *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
138
- » **tommy:** /hello world
139
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
140
+ -# » **tommy:** /hello world
139
141
  command reply
140
- -# *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
142
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
141
143
  `)
142
144
  })
143
145
 
@@ -181,14 +183,14 @@ test('/<agent>-agent sets the channel agent, or starts a session with a prompt',
181
183
  --- from: assistant (TestBot)
182
184
  -# *using deterministic-provider/deterministic-v2 ⋅ plan*
183
185
  plan reply
184
- -# *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2 ⋅ plan*"
186
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
185
187
  `)
186
188
  expect(await discord.thread(built.id).text()).toMatchInlineSnapshot(`
187
189
  "--- from: assistant (TestBot)
188
- » **tommy:** Build it build-marker
190
+ -# » **tommy:** Build it build-marker
189
191
  -# *using deterministic-provider/deterministic-v2 ⋅ build*
190
192
  build reply
191
- -# *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
193
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2 ⋅ build*"
192
194
  `)
193
195
  })
194
196
 
@@ -209,18 +211,18 @@ test('/<cmd>-cmd, /<skill>-skill and a `/server:prompt` message run in the threa
209
211
  --- from: assistant (TestBot)
210
212
  -# *using deterministic-provider/deterministic-v2 ⋅ plan*
211
213
  ok
212
- -# *project ⋅ main ⋅ Ns ⋅ deterministic-v2 ⋅ plan*
213
- » **tommy:** /hello world
214
+ -# *main ⋅ Ns ⋅ deterministic-v2*
215
+ -# » **tommy:** /hello world
214
216
  command reply
215
- -# *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2 ⋅ plan*
216
- » **tommy:** /opencode explain skill-marker
217
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
218
+ -# » **tommy:** /opencode explain skill-marker
217
219
  skill reply
218
- -# *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2 ⋅ plan*
220
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
219
221
  --- from: user (tommy)
220
222
  /fake:greet World
221
223
  --- from: assistant (TestBot)
222
224
  mcp reply
223
- -# *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2 ⋅ plan*"
225
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
224
226
  `)
225
227
 
226
228
  const sessionId = bot.store.getState().roots[thread.id]!
@@ -274,17 +276,19 @@ test('/queue-command queues an OpenCode command after the current run', async ()
274
276
  })
275
277
  await waitForBotMessageContaining({ discord, threadId: thread.id, text: 'queued command reply' })
276
278
  await waitForFooter({ discord, threadId: thread.id, count: 2 })
277
- expect(await discord.thread(thread.id).text()).toMatchInlineSnapshot(`
279
+ expect(await discord.thread(thread.id).text({ showReplies: true })).toMatchInlineSnapshot(`
278
280
  "--- from: user (tommy)
279
281
  Long run slow-marker
280
282
  --- from: assistant (TestBot)
281
283
  -# *using deterministic-provider/deterministic-v2 ⋅ plan*
282
- » **tommy:** /later please
283
- -# Queued message sent
284
+ -# » **tommy:** /later please
285
+ [reply to TestBot: -# » **tommy:** /later please]
286
+ -# Queued
284
287
  slow-done
285
- -# *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2 ⋅ plan*
286
- » **tommy:** /later please
288
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
289
+ [reply to TestBot: -# » **tommy:** /later please]
290
+ -# Queued message sent
287
291
  queued command reply
288
- -# *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2 ⋅ plan*"
292
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
289
293
  `)
290
294
  })
@@ -0,0 +1,145 @@
1
+ // Agent picks in a coordinator channel: `/<agent>-agent prompt:` and a spoken
2
+ // agent start a new thread with that agent, and `kimaki send --agent --model`
3
+ // to the coordinator (workers pass --agent <current_agent>) keeps its agent and model.
4
+
5
+ import fs from 'node:fs'
6
+ import type { DeterministicMatcher } from 'opencode-deterministic-provider'
7
+ import { afterAll, beforeAll, expect, test } from 'vitest'
8
+
9
+ import type { BotHandle } from './main.ts'
10
+ import { send } from './prompt.ts'
11
+ import { TRANSCRIPTION_KEY_MODAL } from './voice.ts'
12
+ import {
13
+ TEST_USER_ID,
14
+ isFooter,
15
+ seedProjectChannel,
16
+ startFakeGemini,
17
+ startOpencodeTestServer,
18
+ startTestBot,
19
+ startTwin,
20
+ tempDataDir,
21
+ textParts,
22
+ voiceUrl,
23
+ waitForBotMessageContaining,
24
+ waitForFooter,
25
+ warmUp,
26
+ type FakeGemini,
27
+ type OpencodeTestServer,
28
+ type TestTwin,
29
+ } from './test/harness.ts'
30
+
31
+ function reply(marker: string, text: string): DeterministicMatcher {
32
+ return { id: marker, priority: 50, when: { latestUserTextIncludes: marker }, then: { parts: textParts(text) } }
33
+ }
34
+
35
+ const matchers: DeterministicMatcher[] = [
36
+ reply('hello-marker', 'hello'),
37
+ reply('slash-agent-marker', 'slash agent ok'),
38
+ reply('voice-agent-marker', 'voice agent ok'),
39
+ reply('worker-note-marker', 'IDLE'),
40
+ ]
41
+
42
+ let server: OpencodeTestServer
43
+ let twin: TestTwin
44
+ let bot: BotHandle
45
+ let gemini: FakeGemini
46
+ const dataDir = tempDataDir()
47
+ // Agent and model of the coordinator session after its first turn.
48
+ let initial: Awaited<ReturnType<typeof coordinator>>
49
+
50
+ beforeAll(async () => {
51
+ ;[server, twin, gemini] = await Promise.all([
52
+ startOpencodeTestServer({
53
+ matchers,
54
+ models: { 'deterministic-thinker': { name: 'Thinker' } },
55
+ agents: { thinker: { mode: 'primary', model: 'deterministic-provider/deterministic-thinker' } },
56
+ }),
57
+ startTwin(),
58
+ startFakeGemini(),
59
+ ])
60
+ await seedProjectChannel({ dataDir, channelId: twin.channelId, guildId: twin.discord.guildId, directory: server.projectDirectory })
61
+ await warmUp({ server })
62
+ bot = await startTestBot({ dataDir, twin, server, coordinator: true, geminiBaseUrl: gemini.baseUrl })
63
+ const user = twin.discord.channel(twin.channelId).user(TEST_USER_ID)
64
+ const { id } = await user.runSlashCommand({ name: 'transcription-key' })
65
+ await twin.discord.channel(twin.channelId).waitForInteractionAck({ interactionId: id })
66
+ await user.submitModal({ customId: TRANSCRIPTION_KEY_MODAL, fields: [{ customId: 'apikey', value: 'AIza-test-gemini-key' }] })
67
+ await waitForBotMessageContaining({ discord: twin.discord, threadId: twin.channelId, text: 'Gemini API key saved' })
68
+ // The coordinator session exists before any test.
69
+ await user.sendMessage({ content: 'Start hello-marker' })
70
+ await waitForFooter({ discord: twin.discord, threadId: twin.channelId })
71
+ initial = await coordinator()
72
+ }, 60_000)
73
+
74
+ afterAll(async () => {
75
+ await bot?.stop()
76
+ await twin?.stop()
77
+ await server?.stop()
78
+ await gemini?.stop()
79
+ fs.rmSync(dataDir, { recursive: true, force: true })
80
+ })
81
+
82
+ async function coordinator() {
83
+ const info = await (await server.client()).session.get({ sessionID: bot.store.getState().roots[twin.channelId]! })
84
+ return { agent: info.agent, model: info.model?.id }
85
+ }
86
+
87
+ async function newThread(start: () => Promise<unknown>) {
88
+ const { discord, channelId } = twin
89
+ const before = new Set((await discord.channel(channelId).getThreads()).map((thread) => thread.id))
90
+ await start()
91
+ const thread = await discord.channel(channelId).waitForThread({ timeout: 8_000, predicate: (candidate) => !before.has(candidate.id) })
92
+ await waitForFooter({ discord, threadId: thread.id })
93
+ return thread
94
+ }
95
+
96
+ test('/<agent>-agent with a prompt starts a thread with that agent; the coordinator keeps its agent and model', async () => {
97
+ const thread = await newThread(() =>
98
+ twin.discord.channel(twin.channelId).user(TEST_USER_ID).runSlashCommand({ name: 'thinker-agent', options: [{ name: 'prompt', type: 3, value: 'Think slash-agent-marker' }] }),
99
+ )
100
+ expect(await twin.discord.thread(thread.id).text()).toMatchInlineSnapshot(`
101
+ "--- from: assistant (TestBot)
102
+ -# » **tommy:** Think slash-agent-marker
103
+ -# *using deterministic-provider/deterministic-thinker ⋅ thinker*
104
+ slash agent ok
105
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-thinker ⋅ thinker*"
106
+ `)
107
+ expect(await coordinator()).toEqual(initial)
108
+ })
109
+
110
+ test('a spoken agent starts a thread with that agent; the coordinator keeps its agent and model', async () => {
111
+ const thread = await newThread(() =>
112
+ twin.discord.channel(twin.channelId).user(TEST_USER_ID).sendVoiceMessage({ url: voiceUrl({ transcription: 'Think voice-agent-marker', route: 'steer', agent: 'thinker' }) }),
113
+ )
114
+ expect(await twin.discord.thread(thread.id).text()).toMatchInlineSnapshot(`
115
+ "--- from: assistant (TestBot)
116
+ -# » **tommy:** Think voice-agent-marker
117
+ -# *using deterministic-provider/deterministic-thinker ⋅ thinker*
118
+ voice agent ok
119
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-thinker ⋅ thinker*"
120
+ `)
121
+ expect(await coordinator()).toEqual(initial)
122
+ })
123
+
124
+ test('kimaki send --agent --model to the coordinator keeps its agent and model', async () => {
125
+ const { discord, channelId } = twin
126
+ const footers = (await discord.channel(channelId).getMessages()).filter(isFooter).length
127
+ const root = bot.store.getState().roots[channelId]!
128
+ const sent = await send(bot, { sessionId: root, prompt: 'Done worker-note-marker', agent: 'thinker', model: 'deterministic-provider/deterministic-thinker' })
129
+ if (sent instanceof Error) throw sent
130
+ await waitForBotMessageContaining({ discord, threadId: channelId, text: 'Done worker-note-marker' })
131
+ // IDLE posts nothing; the next coordinator turn still runs on the default agent and model.
132
+ await (await server.client()).session.wait({ sessionID: root })
133
+ await discord.channel(channelId).user(TEST_USER_ID).sendMessage({ content: 'Again hello-marker' })
134
+ await waitForFooter({ discord, threadId: channelId, count: footers + 1 })
135
+ const text = await discord.channel(channelId).text()
136
+ expect(text.slice(text.lastIndexOf('Done worker-note-marker'))).toMatchInlineSnapshot(`
137
+ "Done worker-note-marker
138
+ --- from: user (tommy)
139
+ Again hello-marker
140
+ --- from: assistant (TestBot)
141
+ hello
142
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
143
+ `)
144
+ expect(await coordinator()).toEqual(initial)
145
+ })