kimaki 1.4.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 (335) 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 +10 -1
  15. package/dist/bot.js +14 -6
  16. package/dist/bot.js.map +1 -1
  17. package/dist/btw.e2e.test.js +3 -3
  18. package/dist/builtin-skills.d.ts +1 -1
  19. package/dist/builtin-skills.js +1 -1
  20. package/dist/builtin-skills.js.map +1 -1
  21. package/dist/builtin-skills.test.js +3 -4
  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.js +25 -14
  25. package/dist/cli/bot.js.map +1 -1
  26. package/dist/cli/discord.js +32 -6
  27. package/dist/cli/discord.js.map +1 -1
  28. package/dist/cli/schedule.js +23 -9
  29. package/dist/cli/schedule.js.map +1 -1
  30. package/dist/cli/session.js +37 -12
  31. package/dist/cli/session.js.map +1 -1
  32. package/dist/cli/shared.d.ts +5 -3
  33. package/dist/cli/shared.js +45 -10
  34. package/dist/cli/shared.js.map +1 -1
  35. package/dist/cli-discord.e2e.test.js +13 -8
  36. package/dist/cli-discord.e2e.test.js.map +1 -1
  37. package/dist/cli-lock.e2e.test.js +87 -20
  38. package/dist/cli-lock.e2e.test.js.map +1 -1
  39. package/dist/cli-read.e2e.test.js +18 -9
  40. package/dist/cli-read.e2e.test.js.map +1 -1
  41. package/dist/cli-sessions.e2e.test.js +4 -3
  42. package/dist/cli-sessions.e2e.test.js.map +1 -1
  43. package/dist/cli.js +2 -0
  44. package/dist/cli.js.map +1 -1
  45. package/dist/commands/preference-commands.d.ts +4 -0
  46. package/dist/commands/preference-commands.js +38 -4
  47. package/dist/commands/preference-commands.js.map +1 -1
  48. package/dist/commands/session-commands.js +11 -8
  49. package/dist/commands/session-commands.js.map +1 -1
  50. package/dist/commands/thread-commands.js +94 -24
  51. package/dist/commands/thread-commands.js.map +1 -1
  52. package/dist/commands/worktree-commands.d.ts +5 -6
  53. package/dist/commands/worktree-commands.js +8 -7
  54. package/dist/commands/worktree-commands.js.map +1 -1
  55. package/dist/commands.e2e.test.js +25 -21
  56. package/dist/commands.e2e.test.js.map +1 -1
  57. package/dist/coordinator-agents.e2e.test.d.ts +1 -0
  58. package/dist/coordinator-agents.e2e.test.js +113 -0
  59. package/dist/coordinator-agents.e2e.test.js.map +1 -0
  60. package/dist/coordinator-idle.e2e.test.d.ts +1 -0
  61. package/dist/coordinator-idle.e2e.test.js +100 -0
  62. package/dist/coordinator-idle.e2e.test.js.map +1 -0
  63. package/dist/coordinator-queue.e2e.test.d.ts +1 -0
  64. package/dist/coordinator-queue.e2e.test.js +244 -0
  65. package/dist/coordinator-queue.e2e.test.js.map +1 -0
  66. package/dist/coordinator-warmup.e2e.test.d.ts +1 -0
  67. package/dist/coordinator-warmup.e2e.test.js +131 -0
  68. package/dist/coordinator-warmup.e2e.test.js.map +1 -0
  69. package/dist/coordinator.d.ts +6 -0
  70. package/dist/coordinator.e2e.test.d.ts +1 -0
  71. package/dist/coordinator.e2e.test.js +505 -0
  72. package/dist/coordinator.e2e.test.js.map +1 -0
  73. package/dist/coordinator.js +164 -0
  74. package/dist/coordinator.js.map +1 -0
  75. package/dist/db.d.ts +78 -3
  76. package/dist/db.test.js +1 -0
  77. package/dist/db.test.js.map +1 -1
  78. package/dist/diagram.d.ts +11 -0
  79. package/dist/diagram.js +232 -0
  80. package/dist/diagram.js.map +1 -0
  81. package/dist/diagram.test.d.ts +1 -0
  82. package/dist/diagram.test.js +52 -0
  83. package/dist/diagram.test.js.map +1 -0
  84. package/dist/duration.js +13 -5
  85. package/dist/duration.js.map +1 -1
  86. package/dist/effects.d.ts +6 -1
  87. package/dist/effects.js +97 -26
  88. package/dist/effects.js.map +1 -1
  89. package/dist/event-loop.d.ts +1 -1
  90. package/dist/event-loop.js +73 -43
  91. package/dist/event-loop.js.map +1 -1
  92. package/dist/format-parts.d.ts +21 -4
  93. package/dist/format-parts.js +40 -23
  94. package/dist/format-parts.js.map +1 -1
  95. package/dist/gateway-replay.e2e.test.js +4 -4
  96. package/dist/harness.e2e.test.js +2 -2
  97. package/dist/harness.e2e.test.js.map +1 -1
  98. package/dist/hello-thread.e2e.test.js +56 -5
  99. package/dist/hello-thread.e2e.test.js.map +1 -1
  100. package/dist/ingress.js +47 -12
  101. package/dist/ingress.js.map +1 -1
  102. package/dist/interaction-context.d.ts +4 -4
  103. package/dist/interaction-context.js +9 -7
  104. package/dist/interaction-context.js.map +1 -1
  105. package/dist/interrupt.e2e.test.js +8 -5
  106. package/dist/interrupt.e2e.test.js.map +1 -1
  107. package/dist/legacy.e2e.test.js +1 -1
  108. package/dist/lock-routes.d.ts +83 -31
  109. package/dist/lock-routes.js +68 -8
  110. package/dist/lock-routes.js.map +1 -1
  111. package/dist/lock-server.d.ts +3 -2
  112. package/dist/lock-server.js +23 -7
  113. package/dist/lock-server.js.map +1 -1
  114. package/dist/main.d.ts +4 -2
  115. package/dist/main.js +13 -3
  116. package/dist/main.js.map +1 -1
  117. package/dist/mainmast-idle.e2e.test.d.ts +1 -0
  118. package/dist/mainmast-idle.e2e.test.js +99 -0
  119. package/dist/mainmast-idle.e2e.test.js.map +1 -0
  120. package/dist/mainmast-queue.e2e.test.d.ts +1 -0
  121. package/dist/mainmast-queue.e2e.test.js +244 -0
  122. package/dist/mainmast-queue.e2e.test.js.map +1 -0
  123. package/dist/mainmast-warmup.e2e.test.d.ts +1 -0
  124. package/dist/mainmast-warmup.e2e.test.js +130 -0
  125. package/dist/mainmast-warmup.e2e.test.js.map +1 -0
  126. package/dist/mainmast.d.ts +6 -0
  127. package/dist/mainmast.e2e.test.d.ts +1 -0
  128. package/dist/mainmast.e2e.test.js +428 -0
  129. package/dist/mainmast.e2e.test.js.map +1 -0
  130. package/dist/mainmast.js +156 -0
  131. package/dist/mainmast.js.map +1 -0
  132. package/dist/markdown/markdown.test.js +4 -4
  133. package/dist/markdown/render-markdown.js +6 -5
  134. package/dist/markdown/render-markdown.js.map +1 -1
  135. package/dist/onboarding-cli.e2e.test.js +7 -6
  136. package/dist/onboarding-cli.e2e.test.js.map +1 -1
  137. package/dist/onboarding.d.ts +3 -10
  138. package/dist/onboarding.e2e.test.js +8 -10
  139. package/dist/onboarding.e2e.test.js.map +1 -1
  140. package/dist/onboarding.js +14 -24
  141. package/dist/onboarding.js.map +1 -1
  142. package/dist/permissions.e2e.test.js +3 -3
  143. package/dist/plugin/coordinator.d.ts +4 -0
  144. package/dist/plugin/coordinator.js +389 -0
  145. package/dist/plugin/coordinator.js.map +1 -0
  146. package/dist/plugin/index.js +76 -17
  147. package/dist/plugin/index.js.map +1 -1
  148. package/dist/plugin/mainmast.d.ts +4 -0
  149. package/dist/plugin/mainmast.js +379 -0
  150. package/dist/plugin/mainmast.js.map +1 -0
  151. package/dist/plugin.e2e.test.js +1 -1
  152. package/dist/preference-commands.e2e.test.js +103 -24
  153. package/dist/preference-commands.e2e.test.js.map +1 -1
  154. package/dist/project.d.ts +1 -1
  155. package/dist/prompt.d.ts +22 -9
  156. package/dist/prompt.js +64 -48
  157. package/dist/prompt.js.map +1 -1
  158. package/dist/questions.e2e.test.js +13 -13
  159. package/dist/queue-sources.e2e.test.d.ts +1 -0
  160. package/dist/queue-sources.e2e.test.js +168 -0
  161. package/dist/queue-sources.e2e.test.js.map +1 -0
  162. package/dist/queue.d.ts +9 -1
  163. package/dist/queue.e2e.test.js +48 -30
  164. package/dist/queue.e2e.test.js.map +1 -1
  165. package/dist/queue.js +97 -24
  166. package/dist/queue.js.map +1 -1
  167. package/dist/queue.test.d.ts +1 -0
  168. package/dist/queue.test.js +57 -0
  169. package/dist/queue.test.js.map +1 -0
  170. package/dist/remote-send.e2e.test.js +6 -6
  171. package/dist/remote-send.js +2 -1
  172. package/dist/remote-send.js.map +1 -1
  173. package/dist/renderer.e2e.test.js +7 -7
  174. package/dist/restart.e2e.test.js +2 -2
  175. package/dist/routines.e2e.test.js +2 -2
  176. package/dist/scheduler.d.ts +3 -3
  177. package/dist/scheduler.e2e.test.js +43 -20
  178. package/dist/scheduler.e2e.test.js.map +1 -1
  179. package/dist/scheduler.js +4 -2
  180. package/dist/scheduler.js.map +1 -1
  181. package/dist/schema-sql.d.ts +1 -1
  182. package/dist/schema-sql.js +1 -1
  183. package/dist/schema-sql.js.map +1 -1
  184. package/dist/schema.d.ts +152 -6
  185. package/dist/schema.js +12 -0
  186. package/dist/schema.js.map +1 -1
  187. package/dist/session-commands.e2e.test.js +36 -11
  188. package/dist/session-commands.e2e.test.js.map +1 -1
  189. package/dist/session-events.d.ts +18 -6
  190. package/dist/session-events.js +166 -22
  191. package/dist/session-events.js.map +1 -1
  192. package/dist/session-ops.e2e.test.js +63 -12
  193. package/dist/session-ops.e2e.test.js.map +1 -1
  194. package/dist/sessions.d.ts +44 -21
  195. package/dist/sessions.js +174 -63
  196. package/dist/sessions.js.map +1 -1
  197. package/dist/shell.e2e.test.js +4 -4
  198. package/dist/slash-commands.js +6 -4
  199. package/dist/slash-commands.js.map +1 -1
  200. package/dist/slash-commands.test.js +2 -0
  201. package/dist/slash-commands.test.js.map +1 -1
  202. package/dist/sleep.e2e.test.js +29 -14
  203. package/dist/sleep.e2e.test.js.map +1 -1
  204. package/dist/sleeps.d.ts +2 -1
  205. package/dist/sleeps.js +21 -3
  206. package/dist/sleeps.js.map +1 -1
  207. package/dist/store.d.ts +1 -0
  208. package/dist/store.js +3 -2
  209. package/dist/store.js.map +1 -1
  210. package/dist/system-prompt.d.ts +3 -1
  211. package/dist/system-prompt.js +138 -64
  212. package/dist/system-prompt.js.map +1 -1
  213. package/dist/test/generate-log-plugin/index.d.ts +3 -0
  214. package/dist/test/generate-log-plugin/index.js +15 -0
  215. package/dist/test/generate-log-plugin/index.js.map +1 -0
  216. package/dist/test/harness.d.ts +20 -1
  217. package/dist/test/harness.js +51 -10
  218. package/dist/test/harness.js.map +1 -1
  219. package/dist/test/replay.js +11 -7
  220. package/dist/test/replay.js.map +1 -1
  221. package/dist/thread-reducer.d.ts +29 -3
  222. package/dist/thread-reducer.fixtures.test.js +58 -51
  223. package/dist/thread-reducer.fixtures.test.js.map +1 -1
  224. package/dist/thread-reducer.js +112 -25
  225. package/dist/thread-reducer.js.map +1 -1
  226. package/dist/thread-reducer.test.js +197 -24
  227. package/dist/thread-reducer.test.js.map +1 -1
  228. package/dist/voice-attachments.e2e.test.js +108 -18
  229. package/dist/voice-attachments.e2e.test.js.map +1 -1
  230. package/dist/voice-call.e2e.test.js +9 -9
  231. package/dist/voice-call.js +6 -6
  232. package/dist/voice-call.js.map +1 -1
  233. package/dist/voice-openai.e2e.test.js +59 -23
  234. package/dist/voice-openai.e2e.test.js.map +1 -1
  235. package/dist/voice.d.ts +1 -1
  236. package/dist/voice.js +72 -24
  237. package/dist/voice.js.map +1 -1
  238. package/dist/working-directory.e2e.test.js +11 -11
  239. package/dist/working-directory.e2e.test.js.map +1 -1
  240. package/package.json +12 -6
  241. package/src/agent-ui.e2e.test.ts +27 -13
  242. package/src/agent-ui.ts +2 -1
  243. package/src/analytics.e2e.test.ts +1 -1
  244. package/src/autostart.ts +55 -10
  245. package/src/bot.ts +29 -5
  246. package/src/btw.e2e.test.ts +3 -3
  247. package/src/builtin-skills.test.ts +3 -4
  248. package/src/builtin-skills.ts +1 -1
  249. package/src/catalog-refresh.e2e.test.ts +2 -2
  250. package/src/cli/bot.ts +23 -14
  251. package/src/cli/discord.ts +30 -6
  252. package/src/cli/schedule.ts +23 -9
  253. package/src/cli/session.ts +35 -12
  254. package/src/cli/shared.ts +43 -8
  255. package/src/cli-discord.e2e.test.ts +13 -8
  256. package/src/cli-lock.e2e.test.ts +88 -20
  257. package/src/cli-read.e2e.test.ts +17 -8
  258. package/src/cli-sessions.e2e.test.ts +4 -3
  259. package/src/cli.ts +2 -0
  260. package/src/commands/preference-commands.ts +38 -4
  261. package/src/commands/session-commands.ts +12 -7
  262. package/src/commands/thread-commands.ts +92 -24
  263. package/src/commands/worktree-commands.ts +10 -9
  264. package/src/commands.e2e.test.ts +25 -21
  265. package/src/coordinator-agents.e2e.test.ts +145 -0
  266. package/src/coordinator-idle.e2e.test.ts +122 -0
  267. package/src/coordinator-queue.e2e.test.ts +279 -0
  268. package/src/coordinator-warmup.e2e.test.ts +158 -0
  269. package/src/coordinator.e2e.test.ts +545 -0
  270. package/src/coordinator.ts +168 -0
  271. package/src/db.test.ts +1 -0
  272. package/src/diagram.test.ts +56 -0
  273. package/src/diagram.ts +243 -0
  274. package/src/duration.ts +13 -5
  275. package/src/effects.ts +99 -27
  276. package/src/event-loop.ts +71 -42
  277. package/src/format-parts.ts +53 -22
  278. package/src/gateway-replay.e2e.test.ts +4 -4
  279. package/src/harness.e2e.test.ts +2 -2
  280. package/src/hello-thread.e2e.test.ts +59 -5
  281. package/src/ingress.ts +44 -11
  282. package/src/interaction-context.ts +12 -11
  283. package/src/interrupt.e2e.test.ts +8 -5
  284. package/src/legacy.e2e.test.ts +1 -1
  285. package/src/lock-routes.ts +62 -8
  286. package/src/lock-server.ts +23 -7
  287. package/src/main.ts +22 -7
  288. package/src/markdown/markdown.test.ts +4 -4
  289. package/src/markdown/render-markdown.ts +6 -5
  290. package/src/onboarding-cli.e2e.test.ts +7 -6
  291. package/src/onboarding.e2e.test.ts +8 -10
  292. package/src/onboarding.ts +13 -29
  293. package/src/permissions.e2e.test.ts +3 -3
  294. package/src/plugin/coordinator.ts +401 -0
  295. package/src/plugin/index.ts +68 -15
  296. package/src/plugin.e2e.test.ts +1 -1
  297. package/src/preference-commands.e2e.test.ts +103 -23
  298. package/src/prompt.ts +87 -43
  299. package/src/questions.e2e.test.ts +13 -13
  300. package/src/queue-sources.e2e.test.ts +197 -0
  301. package/src/queue.e2e.test.ts +48 -30
  302. package/src/queue.test.ts +59 -0
  303. package/src/queue.ts +104 -24
  304. package/src/remote-send.e2e.test.ts +6 -6
  305. package/src/remote-send.ts +2 -1
  306. package/src/renderer.e2e.test.ts +7 -7
  307. package/src/restart.e2e.test.ts +2 -2
  308. package/src/routines.e2e.test.ts +2 -2
  309. package/src/scheduler.e2e.test.ts +45 -19
  310. package/src/scheduler.ts +4 -2
  311. package/src/schema-sql.ts +1 -1
  312. package/src/schema.ts +13 -0
  313. package/src/session-commands.e2e.test.ts +38 -11
  314. package/src/session-events.ts +160 -21
  315. package/src/session-ops.e2e.test.ts +64 -11
  316. package/src/sessions.ts +214 -64
  317. package/src/shell.e2e.test.ts +4 -4
  318. package/src/slash-commands.test.ts +2 -0
  319. package/src/slash-commands.ts +6 -4
  320. package/src/sleep.e2e.test.ts +30 -13
  321. package/src/sleeps.ts +20 -3
  322. package/src/store.ts +5 -2
  323. package/src/system-prompt.ts +143 -63
  324. package/src/test/generate-log-plugin/index.ts +16 -0
  325. package/src/test/harness.ts +77 -14
  326. package/src/test/replay.ts +12 -6
  327. package/src/thread-reducer.fixtures.test.ts +58 -51
  328. package/src/thread-reducer.test.ts +207 -26
  329. package/src/thread-reducer.ts +138 -37
  330. package/src/voice-attachments.e2e.test.ts +110 -18
  331. package/src/voice-call.e2e.test.ts +9 -9
  332. package/src/voice-call.ts +6 -6
  333. package/src/voice-openai.e2e.test.ts +64 -24
  334. package/src/voice.ts +93 -26
  335. package/src/working-directory.e2e.test.ts +11 -11
@@ -12,7 +12,7 @@
12
12
  //
13
13
  // root text, tool lines, banner, footer, retries, errors
14
14
  // child foreground: tool lines labelled "┣ general ⋅ glob ..."
15
- // background: no tool lines, one "⬦ general finished: ..." line
15
+ // background: no tool lines, one "general finished: ..." line
16
16
  // never text, banner or footer
17
17
  //
18
18
  // busy = root execution running OR any child running (29.2 #3). Typing
@@ -36,9 +36,12 @@ import {
36
36
  executeCalls,
37
37
  formatExecuteFailures,
38
38
  buttonRow,
39
+ formatAgentSwitched,
39
40
  formatBanner,
40
41
  formatCacheMiss,
42
+ formatCompacted,
41
43
  formatError,
44
+ formatModelSwitched,
42
45
  formatRetry,
43
46
  formatShellEnded,
44
47
  formatShellFinished,
@@ -52,6 +55,7 @@ import {
52
55
  type ToolInput,
53
56
  type UiMessage,
54
57
  } from './format-parts.ts'
58
+ import { IDLE_REPLY } from './plugin/coordinator.ts'
55
59
  import { closePermission, hydratePermissions, showPermission, STATUS, type PendingPermission } from './permissions.ts'
56
60
  import { closeForm, formatAnswer, hydrateForms, showForm, withAnswer, type PendingForm } from './questions.ts'
57
61
  import { cancelQueued, deliverQueued, enqueueInput, hydrateQueue, promoteQueued, queuedItems, type PendingInput } from './queue.ts'
@@ -64,6 +68,10 @@ export type Turn = {
64
68
  tokens: number
65
69
  // `kimaki sleep` ran in this turn: the session wakes later, so the footer is silent.
66
70
  slept: boolean
71
+ // Discord message the next answer text replies to (a coordinator prompt, queue.ts). Taken by the first text.
72
+ replyTo: string | null
73
+ // The current answer posted model text. A coordinator answer without it gets no footer.
74
+ texted: boolean
67
75
  }
68
76
 
69
77
  export type Child = {
@@ -95,6 +103,8 @@ export type ThreadView = {
95
103
  sessionId: string
96
104
  // Project channel of the thread: its verbosity applies.
97
105
  channelId: string
106
+ // The view is a coordinator channel itself, not a thread.
107
+ coordinator: boolean
98
108
  // Current working directory of the root session (session.moved changes it).
99
109
  directory: string
100
110
  // True only for sessions this bot created: the first step shows a banner.
@@ -107,16 +117,19 @@ export type ThreadView = {
107
117
  children: Readonly<Record<string, Child>>
108
118
  // Background shells started by tool calls: shell ID -> label, until their job ends.
109
119
  shells: Readonly<Record<string, string>>
110
- // Blank line between text and tool blocks.
120
+ // Blank line between text and tool blocks. null: the current answer posted nothing yet (no footer).
111
121
  lastKind: 'text' | 'tool' | null
112
122
  lastRetryAt: number | null
113
123
  // Prompt tokens the provider holds in cache after the last root step, and when that step ended.
114
124
  cached: { tokens: number; at: number } | null
125
+ // The root context was compacted: the next root step (or the execution end) posts the new size.
126
+ compacted: boolean
115
127
  // Root inbox: user items not delivered yet, in order (queuedItems() for the queue).
116
128
  inbox: readonly PendingInput[]
117
129
  // Kimaki runs an OpenCode command (kimaki.command): the next root user item
118
130
  // without Discord metadata is its expanded prompt, shown as the typed command.
119
- commandPending: { text: string; username: string } | null
131
+ // `echo` is set when no Discord message shows the command (CLI, routines).
132
+ commandPending: { text: string; username: string; messageId: string | null; echo: string | null } | null
120
133
  // Questions and permission requests waiting for the user (root and children).
121
134
  forms: Readonly<Record<string, PendingForm>>
122
135
  permissions: Readonly<Record<string, PendingPermission>>
@@ -127,19 +140,22 @@ export type UploadFile = { path: string; name: string; size: number }
127
140
  export type Effect =
128
141
  // Bot-formatted Discord content (tool lines, banner, errors).
129
142
  // Effects are silent unless `notify` is set (format-parts.ts message flags).
130
- | { type: 'send'; text: string; notify?: boolean }
143
+ // `echo`: user text (a prompt echo), posted with mentions disabled.
144
+ | { type: 'send'; text: string; notify?: boolean; echo?: boolean }
131
145
  // Model markdown, rendered and split by the executor.
132
- | { type: 'markdown'; text: string; blankLineBefore: boolean }
146
+ // `replyTo`: the first message replies to this Discord message.
147
+ | { type: 'markdown'; text: string; blankLineBefore: boolean; replyTo: string | null }
133
148
  | { type: 'typing'; on: boolean }
134
149
  // Files from `kimaki upload-to-discord` (never from the reducer). `settle`
135
- // answers the waiting CLI call: null once posted, or why not.
136
- | { type: 'attachments'; files: readonly UploadFile[]; settle: (error: Error | null) => void }
137
- // The executor adds folder and git branch of `directory` when it posts.
138
- | { type: 'footer'; directory: string; durationMs: number; contextPercent: number | null; model: ModelRef; agent: string | null; notify: boolean }
139
- // Posts the messages in order; the first replies to `replyTo` when set.
140
- | { type: 'show'; key: string; messages: readonly UiMessage[]; replyTo: string | null; notify: boolean }
141
- // Edits the messages `show` posted under `key` (by index; the last one covers the rest).
142
- | { type: 'edit'; key: string; messages: readonly UiMessage[] }
150
+ // answers the waiting CLI call: the Discord URL of each file once posted, or why not.
151
+ | { type: 'attachments'; files: readonly UploadFile[]; settle: (result: Error | string[]) => void }
152
+ // The executor adds the git branch of `directory` and the defaults of `channelId` when it posts.
153
+ | { type: 'footer'; channelId: string; directory: string; durationMs: number; contextPercent: number | null; model: ModelRef; agent: string | null; notify: boolean }
154
+ // Posts the messages in order; the first replies to `replyTo` when set. `echo`: holds user text, no mentions.
155
+ | { type: 'show'; key: string; messages: readonly UiMessage[]; replyTo: string | null; notify: boolean; echo?: boolean }
156
+ // Edits the messages `show` posted under `key` (by index; the last one covers the rest),
157
+ // then posts `reply` as a reply to `replyTo`, or to the first of them when null.
158
+ | { type: 'edit'; key: string; messages: readonly UiMessage[]; reply?: string; replyTo?: string | null }
143
159
  // Marks the root execution that went idle at `idle` as read in OpenCode, once
144
160
  // the lines before it are posted. Bots cannot see Discord read state.
145
161
  | { type: 'viewed'; sessionId: string; idle: number }
@@ -165,7 +181,7 @@ export type KimakiEvent =
165
181
  // Kimaki is about to run an OpenCode command (prompt.ts). Prompts without
166
182
  // Discord metadata are echoed as sent from elsewhere; this one must not be.
167
183
  // TODO: pass metadata.discord to session.command once its payload accepts metadata, then drop this event.
168
- | { type: 'kimaki.command'; text: string; username: string }
184
+ | { type: 'kimaki.command'; text: string; username: string; messageId: string | null; echo: string | null }
169
185
  // session.command failed, so no prompt follows.
170
186
  | { type: 'kimaki.command-failed' }
171
187
  // A session found by walking parentID after a bot restart.
@@ -184,12 +200,13 @@ export function isKimakiEvent(event: ThreadEvent): event is KimakiEvent {
184
200
 
185
201
  export type Prefs = {
186
202
  verbosity: Verbosity
187
- // "providerID/modelID" -> context window size in tokens.
188
- contextLimits: Readonly<Record<string, number>>
203
+ // "providerID/modelID" -> display name and context window size in tokens.
204
+ models: Readonly<Record<string, { name: string; context: number }>>
189
205
  }
190
206
 
191
207
  const RETRY_NOTICE_INTERVAL_MS = 10_000
192
208
  const CACHE_MISS_SLACK = 1_024
209
+ const CACHE_MISS_MIN_WRITE_SHARE = 0.5
193
210
  const REPLAY_LIMIT = 30
194
211
 
195
212
  export function emptyView({
@@ -197,15 +214,18 @@ export function emptyView({
197
214
  channelId,
198
215
  directory,
199
216
  isNew,
217
+ coordinator,
200
218
  }: {
201
219
  sessionId: string
202
220
  channelId: string
203
221
  directory: string
204
222
  isNew: boolean
223
+ coordinator: boolean
205
224
  }): ThreadView {
206
225
  return {
207
226
  sessionId,
208
227
  channelId,
228
+ coordinator,
209
229
  directory,
210
230
  bannerPending: isNew,
211
231
  turn: null,
@@ -216,6 +236,7 @@ export function emptyView({
216
236
  lastKind: null,
217
237
  lastRetryAt: null,
218
238
  cached: null,
239
+ compacted: false,
219
240
  inbox: [],
220
241
  commandPending: null,
221
242
  forms: {},
@@ -223,13 +244,37 @@ export function emptyView({
223
244
  }
224
245
  }
225
246
 
247
+ function newTurn(startedAt: number): Turn {
248
+ return { startedAt, model: null, agent: null, tokens: 0, slept: false, replyTo: null, texted: false }
249
+ }
250
+
226
251
  export function isBusy(view: ThreadView): boolean {
227
252
  return view.turn !== null || Object.values(view.children).some((child) => child.running)
228
253
  }
229
254
 
255
+ function waitsForUser(view: ThreadView): boolean {
256
+ return Object.keys(view.forms).length > 0 || Object.keys(view.permissions).length > 0
257
+ }
258
+
230
259
  // Typing stops while the agent waits for the user (spec 6.6).
231
260
  function isTyping(view: ThreadView): boolean {
232
- return isBusy(view) && Object.keys(view.forms).length === 0 && Object.keys(view.permissions).length === 0
261
+ return isBusy(view) && !waitsForUser(view)
262
+ }
263
+
264
+ // Typing of one conversation across all views: a coordinator (a view whose channel
265
+ // is its own conversation) also types while a thread of its channel does, so
266
+ // background workers show there. Other conversations: isTyping of their view.
267
+ export function conversationTyping({ threads, threadId }: { threads: Readonly<Record<string, ThreadView>>; threadId: string }): boolean {
268
+ const view = threads[threadId]
269
+ if (!view || waitsForUser(view)) return false
270
+ if (isBusy(view)) return true
271
+ if (!view.coordinator) return false
272
+ return workersTyping({ threads, channelId: threadId })
273
+ }
274
+
275
+ // A thread of the channel runs and does not wait for the user.
276
+ export function workersTyping({ threads, channelId }: { threads: Readonly<Record<string, ThreadView>>; channelId: string }): boolean {
277
+ return Object.entries(threads).some(([id, thread]) => id !== channelId && thread.channelId === channelId && isTyping(thread))
233
278
  }
234
279
 
235
280
  export function eventSessionId(event: V2Event): string | null {
@@ -272,24 +317,41 @@ function toolLine({ draft, emit }: Context, text: string) {
272
317
  draft.lastKind = 'tool'
273
318
  }
274
319
 
275
- function contextPercent({ turn, prefs }: { turn: Draft<Turn>; prefs: Prefs }): number | null {
276
- if (!turn.model || turn.tokens <= 0) return null
277
- const limit = prefs.contextLimits[`${turn.model.providerID}/${turn.model.id}`]
320
+ function showCompacted(context: Context, size: { tokens: number | null; percent: number | null }) {
321
+ context.draft.compacted = false
322
+ toolLine(context, formatCompacted(size))
323
+ }
324
+
325
+ // A compaction in an execution with no model step (`/compact`, the idle coordinator compaction) stays silent:
326
+ // the user did not ask for anything, so the line is only noise. Auto compaction in a turn shows.
327
+ function endCompaction(context: Context) {
328
+ if (context.draft.compacted && context.draft.turn?.model) showCompacted(context, { tokens: null, percent: null })
329
+ context.draft.compacted = false
330
+ }
331
+
332
+ function contextPercent({ tokens, model, prefs }: { tokens: number; model: ModelRef | null; prefs: Prefs }): number | null {
333
+ if (!model || tokens <= 0) return null
334
+ const limit = prefs.models[`${model.providerID}/${model.id}`]?.context
278
335
  if (!limit || limit <= 0) return null
279
- return Math.round((turn.tokens / limit) * 100)
336
+ return Math.round((tokens / limit) * 100)
280
337
  }
281
338
 
282
339
  // The footer closing the answer of `turn` at `at`.
283
340
  function emitFooter({ draft, prefs, emit, turn, at, notify }: Context & { turn: Draft<Turn>; at: number; notify: boolean }) {
284
341
  // No model step ran (a compaction-only execution): nothing to summarize.
285
342
  if (!turn.model) return
343
+ // The answer posted no text or tool line (e.g. an IDLE_REPLY, only hidden tools).
344
+ if (draft.lastKind === null) return
345
+ // A coordinator answer with only tool lines (it started a worker, then answered IDLE): its thread shows the work.
346
+ if (draft.coordinator && !turn.texted) return
286
347
  // A child still runs: the answer comes later.
287
348
  if (Object.values(draft.children).some((child) => child.running)) return
288
349
  emit({
289
350
  type: 'footer',
351
+ channelId: draft.channelId,
290
352
  directory: draft.directory,
291
353
  durationMs: at - turn.startedAt,
292
- contextPercent: contextPercent({ turn, prefs }),
354
+ contextPercent: contextPercent({ tokens: turn.tokens, model: turn.model, prefs }),
293
355
  model: { providerID: turn.model.providerID, id: turn.model.id },
294
356
  agent: turn.agent,
295
357
  notify,
@@ -320,7 +382,8 @@ function applyOpencode({ draft, event, prefs, emit }: Context & { event: V2Event
320
382
  // Questions and permissions of subagents show in this thread too.
321
383
  const label = child?.agent ?? null
322
384
  if (event.type === 'session.inbox.enqueued' && event.data.item.type === 'synthetic' && !child?.background) {
323
- return showShellFinished({ draft, prefs, emit, metadata: event.data.item.payload.metadata ?? {}, label })
385
+ const metadata = event.data.item.payload.metadata ?? {}
386
+ return showShellFinished({ draft, prefs, emit, metadata, label })
324
387
  }
325
388
  switch (event.type) {
326
389
  case 'form.created':
@@ -346,14 +409,28 @@ function applyRoot(context: Context & { event: V2Event }) {
346
409
  emit({ type: 'send', text: asSubtext(`Working directory changed to ${event.data.location.directory}`) })
347
410
  return
348
411
  case 'session.execution.started':
349
- draft.turn ??= { startedAt: event.created, model: null, agent: null, tokens: 0, slept: false }
412
+ draft.turn ??= newTurn(event.created)
413
+ return
414
+ // A new session's banner already shows its first model and agent.
415
+ case 'session.model.selected': {
416
+ const { model, previous } = event.data
417
+ const same = previous && previous.providerID === model.providerID && previous.id === model.id && previous.variant === model.variant
418
+ if (draft.bannerPending || same) return
419
+ emit({ type: 'send', text: formatModelSwitched({ name: prefs.models[`${model.providerID}/${model.id}`]?.name ?? `${model.providerID}/${model.id}`, variant: model.variant }) })
420
+ return
421
+ }
422
+ case 'session.agent.selected': {
423
+ const { agent, previous } = event.data
424
+ if (draft.bannerPending || agent === previous) return
425
+ emit({ type: 'send', text: formatAgentSwitched({ agent, previous }) })
350
426
  return
427
+ }
351
428
  case 'session.step.started': {
352
429
  const model = { providerID: event.data.model.providerID, id: event.data.model.id }
353
- draft.turn ??= { startedAt: event.created, model: null, agent: null, tokens: 0, slept: false }
430
+ draft.turn ??= newTurn(event.created)
354
431
  draft.turn.model = model
355
432
  draft.turn.agent = event.data.agent
356
- if (draft.bannerPending) emit({ type: 'send', text: formatBanner({ model: event.data.model, agent: event.data.agent }) })
433
+ if (draft.bannerPending) emit({ type: 'send', text: formatBanner({ model: event.data.model, agent: event.data.agent, coordinator: draft.coordinator }) })
357
434
  draft.bannerPending = false
358
435
  return
359
436
  }
@@ -361,10 +438,17 @@ function applyRoot(context: Context & { event: V2Event }) {
361
438
  if (!draft.turn) return
362
439
  const { tokens } = event.data
363
440
  draft.turn.tokens = tokens.input + tokens.output + tokens.reasoning + tokens.cache.read + tokens.cache.write
441
+ if (draft.compacted) {
442
+ const prompt = tokens.input + tokens.cache.read + tokens.cache.write
443
+ showCompacted(context, { tokens: prompt, percent: contextPercent({ tokens: prompt, model: draft.turn.model, prefs }) })
444
+ }
364
445
  // The prompt only grows, so the cached prefix should too. A drop means the provider
365
446
  // re-read it: changed prefix, other model, or cache expired (TTL). The slack absorbs cache block rounding.
447
+ // Only a step that rewrote most of the prompt is a full loss; a smaller rewrite is a partial miss, not worth a line.
366
448
  const previous = draft.cached
367
- if (previous && tokens.cache.read + CACHE_MISS_SLACK < previous.tokens) {
449
+ const promptTokens = tokens.input + tokens.cache.read + tokens.cache.write
450
+ const rewroteMost = tokens.cache.write >= promptTokens * CACHE_MISS_MIN_WRITE_SHARE
451
+ if (previous && rewroteMost && tokens.cache.read + CACHE_MISS_SLACK < previous.tokens) {
368
452
  toolLine(context, formatCacheMiss({ read: tokens.cache.read, expected: previous.tokens, idleMs: event.created - previous.at }))
369
453
  }
370
454
  draft.cached = { tokens: tokens.cache.read + tokens.cache.write, at: event.created }
@@ -372,8 +456,15 @@ function applyRoot(context: Context & { event: V2Event }) {
372
456
  }
373
457
  case 'session.text.ended': {
374
458
  const text = event.data.text.trim()
375
- if (!text) return
376
- emit({ type: 'markdown', text, blankLineBefore: draft.lastKind === 'tool' })
459
+ // A coordinator turn with nothing for the user (a note, a started worker) answers IDLE_REPLY: Discord shows nothing.
460
+ if (!text || text === IDLE_REPLY) return
461
+ const replyTo = draft.turn?.replyTo ?? null
462
+ // The reply header already sets the text apart from the tool lines above.
463
+ emit({ type: 'markdown', text, blankLineBefore: draft.lastKind === 'tool' && !replyTo, replyTo })
464
+ if (draft.turn) {
465
+ draft.turn.replyTo = null
466
+ draft.turn.texted = true
467
+ }
377
468
  draft.lastKind = 'text'
378
469
  return
379
470
  }
@@ -401,24 +492,28 @@ function applyRoot(context: Context & { event: V2Event }) {
401
492
  case 'session.compaction.ended':
402
493
  // A compacted history has a new prefix: its first miss is expected.
403
494
  draft.cached = null
404
- return toolLine(context, asSubtext('⬦ context compacted'))
495
+ // Its size is only known when the next step reads it.
496
+ draft.compacted = true
497
+ return
405
498
  case 'session.compaction.failed':
406
499
  return toolLine(context, formatError(`compaction failed: ${event.data.error.message}`))
407
500
  case 'session.execution.succeeded': {
408
- const turn = draft.turn
501
+ endCompaction(context)
502
+ if (draft.turn) emitFooter({ ...context, turn: draft.turn, at: event.created, notify: !draft.turn.slept })
409
503
  draft.turn = null
410
504
  draft.lastKind = null
411
- if (turn) emitFooter({ ...context, turn, at: event.created, notify: !turn.slept })
412
505
  emit({ type: 'viewed', sessionId: draft.sessionId, idle: event.created })
413
506
  return
414
507
  }
415
508
  case 'session.execution.failed':
509
+ endCompaction(context)
416
510
  draft.turn = null
417
511
  draft.lastKind = null
418
512
  emit({ type: 'send', text: formatError(event.data.error.message), notify: true })
419
513
  emit({ type: 'viewed', sessionId: draft.sessionId, idle: event.created })
420
514
  return
421
515
  case 'session.execution.interrupted':
516
+ endCompaction(context)
422
517
  draft.turn = null
423
518
  draft.lastKind = null
424
519
  // A shutdown does not make the session idle in OpenCode.
@@ -429,11 +524,16 @@ function applyRoot(context: Context & { event: V2Event }) {
429
524
  case 'session.inbox.delivered': {
430
525
  // OpenCode runs queued items in the same execution: close the answer
431
526
  // before each one with a silent footer, like V1 did per turn.
432
- const queued = queuedItems(draft).some((item) => item.inboxID === event.data.inboxID)
527
+ const item = draft.inbox.find((candidate) => candidate.inboxID === event.data.inboxID)
528
+ const queued = item?.delivery === 'queue'
529
+ // Each user prompt the run takes gets its own reply; synthetic items keep the current one.
530
+ // An acked item's "Queued message sent" reply already marks where its answer starts.
531
+ if (item && draft.turn) draft.turn.replyTo = item.acked ? null : item.replyTo
433
532
  if (queued && draft.turn?.model) {
434
533
  emitFooter({ ...context, turn: draft.turn, at: event.created, notify: false })
435
534
  draft.turn.startedAt = event.created
436
535
  draft.turn.slept = false
536
+ draft.turn.texted = false
437
537
  draft.lastKind = null
438
538
  }
439
539
  return deliverQueued({ draft, emit, inboxID: event.data.inboxID })
@@ -557,6 +657,7 @@ function showShellFinished({
557
657
  ...context
558
658
  }: Context & { metadata: Readonly<Record<string, unknown>>; label: string | null }) {
559
659
  const { shellID, jobID, state, exit } = metadata
660
+ // A <session-finished> note (coordinator.ts) shows nothing: the coordinator reports the outcome.
560
661
  if (metadata['source'] !== 'shell' || typeof shellID !== 'string' || typeof jobID !== 'string') return
561
662
  const description = context.draft.shells[shellID] ?? null
562
663
  delete context.draft.shells[shellID]
@@ -581,7 +682,7 @@ function showAgentPrompt({ draft, emit, prompt }: Pick<Context, 'draft' | 'emit'
581
682
  function dismissAgentPrompts({ draft, emit, ids, result = 'dismissed' }: Pick<Context, 'draft' | 'emit'> & { ids: readonly string[]; result?: string }) {
582
683
  if (ids.length === 0) return
583
684
  draft.agentUi = draft.agentUi.filter((prompt) => !ids.includes(prompt.id))
584
- for (const id of ids) emit({ type: 'edit', key: `agent:${id}`, messages: [textOnly(asSubtext(`⬦ ${result}`))] })
685
+ for (const id of ids) emit({ type: 'edit', key: `agent:${id}`, messages: [textOnly(asSubtext(result))] })
585
686
  }
586
687
 
587
688
  function applyKimaki({ draft, event, prefs, emit }: Context & { event: KimakiEvent }) {
@@ -594,7 +695,7 @@ function applyKimaki({ draft, event, prefs, emit }: Context & { event: KimakiEve
594
695
  if (draft.turn) draft.turn.slept = true
595
696
  return
596
697
  case 'kimaki.command':
597
- draft.commandPending = { text: event.text, username: event.username }
698
+ draft.commandPending = { text: event.text, username: event.username, messageId: event.messageId, echo: event.echo }
598
699
  return
599
700
  case 'kimaki.command-failed':
600
701
  draft.commandPending = null
@@ -613,7 +714,7 @@ function applyKimaki({ draft, event, prefs, emit }: Context & { event: KimakiEve
613
714
  const active = new Set(event.activeSessionIds)
614
715
  for (const [id, child] of Object.entries(draft.children)) child.running = active.has(id)
615
716
  if (!active.has(draft.sessionId)) draft.turn = null
616
- else draft.turn ??= { startedAt: event.at, model: null, agent: null, tokens: 0, slept: false }
717
+ else draft.turn ??= newTurn(event.at)
617
718
  // Nothing runs: tool calls whose end was missed while disconnected are over.
618
719
  if (!isBusy(draft)) draft.tools = {}
619
720
  for (const session of event.sessions) {
@@ -660,7 +761,7 @@ export function replayEffects({
660
761
  const skipped = blocks.length - kept.length
661
762
  const effects = kept.map((block, index): Effect => {
662
763
  const previous = kept[index - 1]?.kind ?? null
663
- if (block.kind === 'text') return { type: 'markdown', text: block.text, blankLineBefore: previous === 'tool' }
764
+ if (block.kind === 'text') return { type: 'markdown', text: block.text, blankLineBefore: previous === 'tool', replyTo: null }
664
765
  return { type: 'send', text: previous === 'text' ? `\n${block.text}` : block.text }
665
766
  })
666
767
  return [
@@ -39,9 +39,9 @@ const matchers: DeterministicMatcher[] = [
39
39
  {
40
40
  id: 'image',
41
41
  priority: 500,
42
- // The plugin adds the numbered <attachments> and <discord-user> to the model request only.
42
+ // The plugin adds the numbered <attachments>, the concise reminder and <discord-user> to the model request only.
43
43
  when: {
44
- latestUserTextRegex: 'image-marker[\\s\\S]*<attachments>[\\s\\S]*1\\. dot\\.png \\(inline\\): [^\\n]*\\n2\\. notes\\.txt: [^\\n]*\\n3\\. archive\\.zip: [^\\n]*\\n</attachments>\\n<discord-user ',
44
+ latestUserTextRegex: 'image-marker[\\s\\S]*<attachments>[\\s\\S]*1\\. dot\\.png \\(inline\\): [^\\n]*\\n2\\. notes\\.txt: [^\\n]*\\n3\\. archive\\.zip: [^\\n]*\\n</attachments>\\n<system-reminder>[^\\n]*</system-reminder>\\n<discord-user ',
45
45
  rawPromptIncludes: 'image/png',
46
46
  },
47
47
  then: { parts: textParts('I see an image') },
@@ -51,6 +51,10 @@ const matchers: DeterministicMatcher[] = [
51
51
  reply('voice-btw', 'voice btw ok'),
52
52
  reply('voice-new', 'voice new session ok'),
53
53
  reply('voice-plan', 'voice plan ok'),
54
+ reply('order-start', 'order start ok'),
55
+ // Above order-start: the thread name in <discord-user> repeats that marker.
56
+ { ...reply('order-voice', 'order voice ok'), priority: 600 },
57
+ { ...reply('order-text', 'order text ok'), priority: 600 },
54
58
  ]
55
59
 
56
60
  let server: OpencodeTestServer
@@ -130,7 +134,7 @@ test('image and text attachments reach the model as files', async () => {
130
134
  --- from: assistant (TestBot)
131
135
  -# *using deterministic-provider/deterministic-v2 ⋅ build*
132
136
  I see an image
133
- -# *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
137
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
134
138
  `)
135
139
  const sessionId = bot.store.getState().roots[thread.id]!
136
140
  const messages = await (await server.client()).message.list({ sessionID: sessionId })
@@ -156,13 +160,78 @@ test('voice in a channel starts a session with the transcription and the spoken
156
160
  "--- from: user (tommy)
157
161
  [attachment: voice-message.ogg]
158
162
  --- from: assistant (TestBot)
159
- » **tommy:** Plan the refactor voice-plan
163
+ -# » **tommy:** Plan the refactor voice-plan
160
164
  -# *using deterministic-provider/deterministic-v2 ⋅ plan*
161
165
  voice plan ok
162
- -# *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2 ⋅ plan*"
166
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2 ⋅ plan*"
163
167
  `)
164
168
  })
165
169
 
170
+ test('a text sent while a voice message is transcribed waits for it', async () => {
171
+ const thread = await newThread(() => twin.discord.channel(twin.channelId).user(TEST_USER_ID).sendMessage({ content: 'Start order-start' }))
172
+ await waitForFooter({ discord: twin.discord, threadId: thread.id })
173
+ const user = twin.discord.thread(thread.id).user(TEST_USER_ID)
174
+ await user.sendVoiceMessage({ url: voiceUrl({ transcription: 'Spoken first order-voice', route: 'queue', delayMs: 500 }) })
175
+ await user.sendMessage({ content: 'Typed second order-text' })
176
+ await waitForBotMessageContaining({ discord: twin.discord, threadId: thread.id, text: 'order text ok' })
177
+ await waitForFooter({ discord: twin.discord, threadId: thread.id, count: 2 })
178
+ expect(await twin.discord.thread(thread.id).text()).toMatchInlineSnapshot(`
179
+ "--- from: user (tommy)
180
+ Start order-start
181
+ --- from: assistant (TestBot)
182
+ -# *using deterministic-provider/deterministic-v2 ⋅ build*
183
+ order start ok
184
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
185
+ --- from: user (tommy)
186
+ [attachment: voice-message.ogg]
187
+ Typed second order-text
188
+ --- from: assistant (TestBot)
189
+ -# » **tommy:** Spoken first order-voice
190
+ order text ok
191
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
192
+ `)
193
+ const sessionId = bot.store.getState().roots[thread.id]!
194
+ const messages = await (await server.client()).message.list({ sessionID: sessionId, order: 'asc' })
195
+ expect(messages.data.flatMap((message) => (message.type === 'user' ? [message.text] : []))).toMatchInlineSnapshot(`
196
+ [
197
+ "Start order-start",
198
+ "Spoken first order-voice",
199
+ "Typed second order-text",
200
+ ]
201
+ `)
202
+ })
203
+
204
+ // https://github.com/remorses/kimaki/issues/246
205
+ test('a long voice transcript is echoed in full over several messages, in a channel and in a thread', async () => {
206
+ const words = Array.from({ length: 450 }, (_, index) => `w${index}`)
207
+ const transcription = `Long voice-steer ${words.join(' ')}`
208
+ const voice = { url: voiceUrl({ transcription, route: 'steer' }) }
209
+ const thread = await newThread(() => twin.discord.channel(twin.channelId).user(TEST_USER_ID).sendVoiceMessage(voice))
210
+ await waitForFooter({ discord: twin.discord, threadId: thread.id })
211
+ await twin.discord.thread(thread.id).user(TEST_USER_ID).sendVoiceMessage(voice)
212
+ await waitForFooter({ discord: twin.discord, threadId: thread.id, count: 2 })
213
+ const text = await twin.discord.thread(thread.id).text()
214
+ expect(text.replace(/w\d+( w\d+)*/g, (run) => `<${run.split(' ')[0]}..${run.split(' ').at(-1)}>`)).toMatchInlineSnapshot(`
215
+ "--- from: user (tommy)
216
+ [attachment: voice-message.ogg]
217
+ --- from: assistant (TestBot)
218
+ -# » **tommy:** Long voice-steer <w0..w414>
219
+ -# <w415..w449>
220
+ -# *using deterministic-provider/deterministic-v2 ⋅ build*
221
+ voice steer ok
222
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
223
+ --- from: user (tommy)
224
+ [attachment: voice-message.ogg]
225
+ --- from: assistant (TestBot)
226
+ -# » **tommy:** Long voice-steer <w0..w414>
227
+ -# <w415..w449>
228
+ voice steer ok
229
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
230
+ `)
231
+ const echoed = (await twin.discord.thread(thread.id).getMessages()).map((message) => message.content).filter((content) => /\bw\d/.test(content))
232
+ expect(echoed.join(' ').replaceAll('-# ', '')).toBe(`» **tommy:** ${transcription} » **tommy:** ${transcription}`)
233
+ })
234
+
166
235
  // https://github.com/remorses/kimaki/issues/235
167
236
  test('uploaded audio files with odd Discord media types are transcribed', async () => {
168
237
  const user = twin.discord.channel(twin.channelId).user(TEST_USER_ID)
@@ -179,10 +248,10 @@ test('uploaded audio files with odd Discord media types are transcribed', async
179
248
  "--- from: user (tommy)
180
249
  [attachment: memo.m4a]
181
250
  --- from: assistant (TestBot)
182
- » **tommy:** From m4a voice-steer
251
+ -# » **tommy:** From m4a voice-steer
183
252
  -# *using deterministic-provider/deterministic-v2 ⋅ build*
184
253
  voice steer ok
185
- -# *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
254
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
186
255
  `)
187
256
  expect([m4a.name, mp3.name]).toMatchInlineSnapshot(`
188
257
  [
@@ -217,7 +286,7 @@ test('voice in a busy thread: queue waits, btw forks, new-session starts a threa
217
286
  await waitForFooter({ discord: twin.discord, threadId: thread.id, count: 2 })
218
287
 
219
288
  const hide = (text: string) => text.replace(/<#\d+>/g, '<#THREAD>')
220
- expect(hide(await twin.discord.thread(thread.id).text())).toMatchInlineSnapshot(`
289
+ expect(hide(await twin.discord.thread(thread.id).text({ showReplies: true }))).toMatchInlineSnapshot(`
221
290
  "--- from: user (tommy)
222
291
  Long work slow-marker
223
292
  --- from: assistant (TestBot)
@@ -225,23 +294,30 @@ test('voice in a busy thread: queue waits, btw forks, new-session starts a threa
225
294
  --- from: user (tommy)
226
295
  [attachment: voice-message.ogg]
227
296
  --- from: assistant (TestBot)
228
- » **tommy:** Afterwards voice-queue
229
- -# Queued message sent
297
+ [reply to tommy: ]
298
+ -# » **tommy:** Afterwards voice-queue
299
+ [reply to tommy: ]
300
+ -# Queued
230
301
  --- from: user (tommy)
231
302
  [attachment: voice-message.ogg]
232
303
  --- from: assistant (TestBot)
233
- » **tommy:** Side voice-btw
304
+ [reply to tommy: ]
305
+ -# » **tommy:** Side voice-btw
306
+ [reply to tommy: ]
234
307
  Session forked! Continue in <#THREAD>
235
308
  --- from: user (tommy)
236
309
  [attachment: voice-message.ogg]
237
310
  --- from: assistant (TestBot)
238
- » **tommy:** Fresh start voice-new
311
+ [reply to tommy: ]
312
+ -# » **tommy:** Fresh start voice-new
313
+ [reply to tommy: ]
239
314
  Started a new session in <#THREAD>
240
315
  slow-done
241
- -# *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
242
- » **tommy:** Afterwards voice-queue
316
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
317
+ [reply to tommy: ]
318
+ -# Queued message sent
243
319
  voice queue ok
244
- -# *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
320
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
245
321
  `)
246
322
  expect([btw.name, fresh.name]).toMatchInlineSnapshot(`
247
323
  [
@@ -254,14 +330,14 @@ test('voice in a busy thread: queue waits, btw forks, new-session starts a threa
254
330
  Reusing context from <#THREAD> to answer prompt...
255
331
  Side voice-btw
256
332
  voice btw ok
257
- -# *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
333
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
258
334
  `)
259
335
  expect(hide(await twin.discord.thread(fresh.id).text())).toMatchInlineSnapshot(`
260
336
  "--- from: assistant (TestBot)
261
- » **tommy:** Fresh start voice-new
337
+ -# » **tommy:** Fresh start voice-new
262
338
  -# *using deterministic-provider/deterministic-v2 ⋅ build*
263
339
  voice new session ok
264
- -# *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
340
+ -# *main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
265
341
  `)
266
342
  // The transcription request offers btw and queue only inside a session thread.
267
343
  expect(gemini.requests.map((request) => request.routes)).toMatchInlineSnapshot(`
@@ -270,6 +346,22 @@ test('voice in a busy thread: queue waits, btw forks, new-session starts a threa
270
346
  "steer",
271
347
  "new-session",
272
348
  ],
349
+ [
350
+ "steer",
351
+ "queue",
352
+ "btw",
353
+ "new-session",
354
+ ],
355
+ [
356
+ "steer",
357
+ "new-session",
358
+ ],
359
+ [
360
+ "steer",
361
+ "queue",
362
+ "btw",
363
+ "new-session",
364
+ ],
273
365
  [
274
366
  "steer",
275
367
  "new-session",