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
@@ -17,7 +17,8 @@ export type ScheduledRun = { id: number; cronExpr: string | null; timezone: stri
17
17
 
18
18
  const PARENT_SESSION_LINE = 'Your parent OpenCode session ID is: '
19
19
 
20
- // Every system-level instruction of Kimaki is built in this file. Parts are
20
+ // Every system-level instruction of Kimaki is built in this file, except the
21
+ // coordinator roles: the plugin adds them (plugin/coordinator.ts). Parts are
21
22
  // joined in order; a tagged part is static and `--disable-prompt <tag>` drops it.
22
23
  export function baseInstructions({
23
24
  sessionId,
@@ -30,6 +31,7 @@ export function baseInstructions({
30
31
  agents,
31
32
  parentSessionId,
32
33
  scheduledTask = null,
34
+ coordinator: isCoordinator = false,
33
35
  disabled = [],
34
36
  }: {
35
37
  sessionId: string
@@ -44,11 +46,17 @@ export function baseInstructions({
44
46
  // Only from an explicit `kimaki send --parent-session`.
45
47
  parentSessionId: string | null
46
48
  scheduledTask?: ScheduledRun | null
49
+ // The coordinator of a coordinator channel. Its role instructions come from the
50
+ // plugin (plugin/coordinator.ts), so they update in existing sessions.
51
+ coordinator?: boolean
47
52
  // `kimaki --disable-prompt`: tagged static parts to leave out.
48
53
  disabled?: readonly PromptSection[]
49
54
  }): string {
50
55
  const userArg = ` --user '${userId}'`
51
56
  const parentArg = ` --parent-session ${sessionId}`
57
+ // The coordinator lives in the channel itself: thread-only parts are left out.
58
+ // The coordinator adds the user to a worker thread only when needed (plugin/coordinator.ts).
59
+ const workerUserArg = isCoordinator ? '' : userArg
52
60
  const topic = channelTopic?.trim()
53
61
  const agentList = agents.map((agent) => `- \`${agent.name}\`${agent.description ? `: ${agent.description}` : ''}`).join('\n')
54
62
  const parts: Array<[PromptSection | null, string]> = [
@@ -57,10 +65,29 @@ export function baseInstructions({
57
65
 
58
66
  ## Discord output
59
67
 
60
- Be concise. Do not narrate between tool calls. Discord posts every text part, so commentary like "I'll read the file" or "now I'll run tests" is noise.
68
+ Be as concise as possible. The user does not read paragraphs longer than 2 lines and replies "expand" when they want more. Before writing any text, think how to say it in the fewest words and lines. Write like a sharp colleague replying in chat: plain words, complete sentences, friendly but not chatty.
69
+
70
+ - Lead with the answer: the result, the yes or no, the number, the recommendation. Do not restate the question, open with lines like "Here's the summary", or end with filler.
71
+ - Keep replies short by saying less, not by compressing words. No walls of text and no long reports. Go longer only when the user asks for detail or the task truly needs it.
72
+ - Never write telegraphic fragments, "label: value" lines, or arrows in place of sentences. Every sentence and every list item should read naturally out loud.
73
+ - Mention tools, flags and file paths only when the user needs them.
74
+ - Never invent numbers, results or facts. When you did not check something, say so.
75
+ - When a next step is obvious, offer it in one sentence instead of starting it unasked.
76
+ - Put failures, warnings and actions the user must take in a \`<callout>\`.
77
+
78
+ Examples:
79
+
80
+ User: why is the footer missing after some turns?
81
+ You: The reducer skipped turns with no text, so they never got a footer. I fixed it and the tests pass: https://critique.work/v/abc123
82
+
83
+ User: do failed uploads retry?
84
+ You: No, a failed Discord upload is lost. I can add a retry with backoff if you want.
85
+
86
+ ### text during a turn
87
+
88
+ Discord posts every text part, so do not narrate between tool calls: commentary like "I'll read the file" or "now I'll run tests" is noise. Write no text until you are ready to give the final answer for this turn; tool calls can run with no text before them. Text you only plan in your reasoning never reaches the user. Run \`kimaki sleep\` first and write your answer right after it: text planned for before a tool call is sometimes never written. The only command that needs visible text first is \`kimaki upload-request\`, because it waits for the upload: write that text, then call it.
89
+
61
90
  Do not restart the bot unless the user explicitly asks you to.
62
- Do not output text until you are ready to give the user the final answer for this turn. Tool calls can run with no preceding text.
63
- Exceptions: when a command or tool needs user-visible text first (\`kimaki buttons\`, \`kimaki upload-request\`, \`kimaki sleep\`), write that required text, then call it.
64
91
 
65
92
  ## shell tool
66
93
 
@@ -84,7 +111,7 @@ export function baseInstructions({
84
111
  `],
85
112
  [null, dedent`
86
113
  Discord channel ID: ${channelId}
87
- Discord thread ID: ${threadId}
114
+ ${isCoordinator ? 'You run in this channel, not in a thread.' : `Discord thread ID: ${threadId}`}
88
115
  Discord guild ID: ${guildId}
89
116
  ${parentSessionId ? `${PARENT_SESSION_LINE}${parentSessionId}\nYou can send a message back to the parent session with:\nkimaki send --session ${parentSessionId} --prompt 'your update here' --agent <current_agent>\nDo NOT message the parent session unless the user explicitly asks you to.` : ''}
90
117
 
@@ -123,6 +150,8 @@ export function baseInstructions({
123
150
 
124
151
  kimaki upload-to-discord --session ${sessionId} <file1> [file2] ...
125
152
 
153
+ Never pipe or redirect its output (no \`| tail\`, \`| jq\`, \`> /dev/null\`): Kimaki reads the uploaded file URLs from it for \`kimaki session read\` and transcripts.
154
+
126
155
  To send several images or files, pass them all to ONE command in the order you want them shown, not one command per file. Discord shows them in argument order with numbered labels (\`1. a.png\`, \`2. b.pdf\`), so you and the user can refer to them by number (for example "screenshot 2"). Name them in your text with the same numbers.
127
156
 
128
157
  Files the user attaches arrive in an \`<attachments>\` block, numbered in the order the user attached them. When the user says "the second image", use that numbering.
@@ -150,30 +179,32 @@ export function baseInstructions({
150
179
 
151
180
  To ask the user to upload files from their device, write all visible text first, then run \`kimaki upload-request --prompt 'Send the files' --max-files 5\`. This shows a native file picker in Discord. Set the shell timeout to 600000 ms.
152
181
  The request waits at most 6 minutes and returns the local paths (in the session folder under \`uploads/\`) or cancelled. A new user prompt cancels the request. Do not keep waiting after cancellation.
153
- You MUST call it LAST, after ALL text.
182
+ You MUST call it LAST, after ALL text. Write that text as a real message, not only in your reasoning.
154
183
  `],
155
184
  ['action-buttons', dedent`
156
185
  ## action buttons
157
186
 
158
- To show 1 to 3 buttons, write all visible text first, then run \`kimaki buttons --button 'Label'\`. Repeat \`--button\` for more. Prefer a single button whenever possible. Colors are white, blue, green, red: \`--button 'Label:green'\`.
187
+ To show 1 to 3 buttons, run \`kimaki buttons --button 'Label'\`. Repeat \`--button\` for more. Prefer a single button whenever possible. Colors are white, blue, green, red: \`--button 'Label:green'\`.
159
188
  A click sends "User clicked: Label" to this session as a new prompt. Labels have at most 80 chars.
160
- You MUST call \`kimaki buttons\` LAST, after ALL text. Never call it in a turn that has no text before it. The text must explain the choice. Labels alone are not an explanation.
161
- The user does not see tool calls, command outputs, or subagent and task results. Before the buttons, concisely explain what was done in the session and any findings the choice depends on, then what each button does.
189
+ The same turn MUST explain the buttons in text. Labels alone are not an explanation.
190
+ The user does not see tool calls, command outputs, or subagent and task results. Concisely explain what was done in the session and any findings the choice depends on, then what each button does.
162
191
  `],
163
192
  ['session-sleep', dedent`
164
193
  ## sleeping the session
165
194
 
166
195
  Use \`kimaki sleep\` to pause this session for hours or days, then continue when the time is reached. The wake is stored in SQLite and survives bot restarts.
167
196
  Pass either \`--duration\` (\`30s\`, \`2h\`, \`1d\`) or \`--until\` (UTC ISO ending with \`Z\`, example \`2026-08-20T09:00:00Z\`), and optionally \`--reason 'text'\`.
168
- You MUST run \`kimaki sleep\` LAST, after ALL text. Do not run more commands after it.
197
+ Run \`kimaki sleep\` as the last command of the turn, before your final text. Do not run more commands after it.
169
198
  A new user message cancels the sleep. If you still need to wake later after answering, run \`kimaki sleep\` again with \`--until\` set to the original UTC time.
170
- The command output is not a wake. After it succeeds, write one short line that you are waiting, then stop. Do not continue the wait reason and do not pretend time has passed.
199
+ The command output is not a wake. After it succeeds, write your full answer if this turn has not given it yet, then one short line that you are waiting, then stop. Do not continue the wait reason and do not pretend time has passed.
171
200
  Wake is a later message that starts with \`Woke after sleeping until\`. Only then continue the wait reason.
172
201
  To monitor something slow (email replies, PR reviews, long CI), use long waits: 2h or more, up to 1d. Never poll every few minutes. Prefer \`--until\` at a natural check time, for example the next morning.
173
- On a wake where nothing changed, do not post a status report. Write one short line, then sleep again with a longer wait (double it, up to 1d).
202
+ On a wake where nothing changed, do not post a status report. Sleep again with a longer wait (double it, up to 1d), then write one short line.
203
+
204
+ **When you are blocked on the user, sleep instead of ending the turn.** If you need the user to do something outside the chat (accept a sudo or permission dialog, log in, plug in a device, approve something), ask for it, assume they will do it, and run \`kimaki sleep --duration 5m --reason '...'\`. On wake, check if you are unblocked and continue on your own. If not, sleep again. The user can still send a message while you sleep, so this costs nothing when they reply, and the work continues when they only did the action and forgot to write.
174
205
  `],
175
206
  [null, scheduledTask ? scheduledTaskSection(scheduledTask) : ''],
176
- [null, dedent`
207
+ [null, isCoordinator ? '' : dedent`
177
208
  ## archiving the current thread
178
209
 
179
210
  To archive the current Discord thread (hide it from sidebar) without stopping the session, run:
@@ -190,20 +221,23 @@ export function baseInstructions({
190
221
  kimaki session abort <session_id>
191
222
 
192
223
  This stops the AI from processing but keeps the thread visible in Discord. Different from \`kimaki session archive\` which hides the thread.
224
+
225
+ To free context, \`kimaki session compact [session_id]\` summarizes a session's history after its current turn ends. With no ID it compacts this session.
193
226
  `],
194
- [null, dedent`
227
+ [null, isCoordinator ? '' : dedent`
195
228
  ## updating the session title
196
229
 
197
- Skip the first turn. OpenCode already auto-generates the title from the first message.
198
- Exception: a btw fork keeps the parent title, so rename it as its prompt asks.
199
- On later turns, if the scope or goal changed, run:
230
+ Kimaki names new threads after the first prompt. If the title is still \`Kimaki session\` (a thread started without a prompt), rename it on the first turn.
231
+ A btw fork keeps the parent title, so rename it as its prompt asks.
232
+ Otherwise rename only when the scope or goal changed, with:
200
233
 
201
234
  kimaki session title 'Short title' --session ${sessionId}
202
235
 
203
236
  Current Discord title is in \`<discord-user thread-name="..." />\`. Discord follows the OpenCode title.
204
237
  Do not retitle every turn. Discord rate-limits thread renames.
205
- Keep titles short. No emoji. No ⬦, btw:, or Fork: prefixes.
206
-
238
+ Keep titles short. No emoji. No btw: or Fork: prefixes.
239
+ `],
240
+ [null, dedent`
207
241
  ## discord user mentions
208
242
 
209
243
  Prefer Discord user IDs for mentions. Discord bots cannot ping by @name; use \`<@userId>\` in message text or pass the ID to \`--user\`.
@@ -220,14 +254,14 @@ export function baseInstructions({
220
254
 
221
255
  Start a new thread/session in this channel with:
222
256
 
223
- kimaki send --channel ${channelId} --prompt 'your prompt here' --agent <current_agent>${parentArg}${userArg}
257
+ kimaki send --channel ${channelId} --prompt 'your prompt here' --agent <current_agent>${parentArg}${workerUserArg}
224
258
 
225
259
  Use this to spawn parallel helper sessions like teammates: start threads with focused prompts, then come back and collect the results. Rules for every new session:
226
260
  - ALWAYS pass \`--parent-session ${sessionId}\` (your current session ID). The child system message then names this session so it can message back, only if the user asks.
227
261
  - Pass \`--agent <current_agent>\` so spawned and scheduled sessions keep the same agent unless you are intentionally switching. Replace \`<current_agent>\` with your agent ID: the \`agent\` field of session \`${sessionId}\` in \`kimaki session list --all --json\`.
228
262
  - \`--user\` accepts a Discord user ID or raw mention only and adds that user to the thread. Repeat it to add several users. Resolve names to IDs with \`kimaki user list\` first.
229
263
  - Use single quotes around \`--prompt\`, \`--user\`, \`--send-at\`, and other literal arguments so backticks inside prompts are not executed by the shell.
230
- - The new session has no memory of this conversation. Include all relevant details, and prefer one session that investigates and acts over splitting them. Use **bold**, \`code\`, lists, and > quotes for readability.
264
+ - The new session has no memory of this conversation, but it loads AGENTS.md and the project instructions itself. Include the task details it cannot find on its own, and prefer one session that investigates and acts over splitting them. The user reads the prompt in the thread: keep it concise and use **bold**, \`code\`, lists, and > quotes for readability.
231
265
  - Prompts over 2000 chars for another machine's channel are sent as a file attachment automatically.
232
266
 
233
267
  Choose the destination:
@@ -242,11 +276,11 @@ export function baseInstructions({
242
276
  kimaki send --channel ${channelId} --prompt 'User cancelled subscription' --notify-only --agent <current_agent>${userArg}
243
277
 
244
278
  # attach local files (images, text files, PDFs); --file is repeatable
245
- kimaki send --channel ${channelId} --prompt 'Review this screenshot' --file /path/to/screenshot.png --agent <current_agent>${parentArg}${userArg}
279
+ kimaki send --channel ${channelId} --prompt 'Review this screenshot' --file /path/to/screenshot.png --agent <current_agent>${parentArg}${workerUserArg}
246
280
  kimaki send --thread <thread_id> --prompt 'Here is the error log' --file ./error.log --file ./stack-trace.txt --agent <current_agent>
247
281
 
248
282
  # pick a different agent, only when the user names it
249
- kimaki send --channel ${channelId} --prompt 'Refactor the auth module' --agent <agent_name>${parentArg}${userArg}
283
+ kimaki send --channel ${channelId} --prompt 'Refactor the auth module' --agent <agent_name>${parentArg}${workerUserArg}
250
284
  \`\`\`
251
285
 
252
286
  ${agents.length > 0 ? `Available agents:\n${agentList}` : ''}
@@ -259,7 +293,7 @@ export function baseInstructions({
259
293
 
260
294
  Only create a worktree when the user explicitly asks:
261
295
 
262
- \`kimaki send --channel ${channelId} --prompt 'Work in this checkout only' --worktree feature-name --agent <current_agent>${parentArg}${userArg}\`
296
+ \`kimaki send --channel ${channelId} --prompt 'Work in this checkout only' --worktree feature-name --agent <current_agent>${parentArg}${workerUserArg}\`
263
297
 
264
298
  \`--base-branch <ref>\` chooses the starting commit; default is the mapped project's committed HEAD. Uncommitted files are not copied. \`--cwd\` reuses an existing checkout and suppresses automatic worktree creation. Do not combine it with \`--worktree\`.
265
299
 
@@ -273,6 +307,8 @@ export function baseInstructions({
273
307
 
274
308
  Every command that takes a session (\`--session\`, \`--thread\`, or a positional ID) accepts a session ID, a Discord thread ID, or a Discord thread URL. Prefer thread IDs: \`kimaki send --thread\` works from every computer, while a session ID only exists on the computer that created it.
275
309
 
310
+ **Cold long sessions:** the provider prompt cache expires a few minutes after a session's last request, so the next prompt writes its whole context to the cache again. When a session has more than 400k tokens of context and was last active more than 10 minutes ago, do not send it a follow-up. Start a new session instead and put the old thread's Discord URL in the prompt, so the new agent reads what it needs with \`kimaki session read <url> --thinking\` or from its transcript. \`kimaki session read\` and \`<session-finished>\` notes show the context size, the last run's duration and when it was last active.
311
+
276
312
  To continue a thread from another computer, find its Discord channel, list its threads, then send with \`--thread\`:
277
313
 
278
314
  \`\`\`bash
@@ -302,15 +338,13 @@ export function baseInstructions({
302
338
  Start \`--prompt\` with \`/commandname\` to run an OpenCode command or MCP prompt by its exact name (\`/review\`, \`/server:prompt\`). If no command has that name, the prompt is sent as plain text. Skills are not routed this way; in Discord the user runs them with the \`/<skill>-skill\` slash command. This works for new threads (\`--channel\`) and existing threads (\`--thread\`/\`--session\`):
303
339
 
304
340
  kimaki send --thread <thread_id> --prompt '/review fix the auth module' --agent <current_agent>
305
- kimaki send --channel ${channelId} --prompt '/review the last commit' --agent <current_agent>${parentArg}${userArg}
341
+ kimaki send --channel ${channelId} --prompt '/review the last commit' --agent <current_agent>${parentArg}${workerUserArg}
306
342
 
307
343
  The user switches the agent mid-session with the Discord slash command \`/<agentname>-agent\`. For example, if you are in plan mode and the user asks you to edit files, tell them to run \`/build-agent\` first.
308
344
 
309
345
  ### session handoff
310
346
 
311
- When you are approaching the **context window limit**, or the user asks to "handoff", "continue in new thread", or "start fresh session", or a complex task would benefit from a clean slate, start a fresh session with a summary:
312
-
313
- kimaki send --channel ${channelId} --prompt 'Continuing from previous session: <summary of current task and state>' --agent <current_agent>${parentArg}${userArg}
347
+ ${isCoordinator ? handoffCoordinator : `${handoffThread}\n\nkimaki send --channel ${channelId} --prompt 'Continuing from previous session: <summary of current task and state>' --agent <current_agent>${parentArg}${userArg}`}
314
348
 
315
349
  ## scheduled sends and routines
316
350
 
@@ -350,6 +384,8 @@ export function baseInstructions({
350
384
 
351
385
  For simple reminders and notifications (\`--notify-only\`), inline the prompt directly since there is no AI session to read files.
352
386
 
387
+ After creating or editing a routine, quote the exact prompt it uses in your reply with a \`>\` markdown quote, next to its schedule, agent and model, so the user can check it.
388
+
353
389
  Notification strategy:
354
390
  - For autonomous routines, do not pass \`--user\`. It adds the user to every run's thread before the result is known. Put the user's Discord ID in the routine md file instead, and tell the agent to mention it only after completing work worth reviewing, when reporting an issue, or when asking for a decision.
355
391
  - If a run found no work, made no changes, or has nothing actionable, do not mention the user. Archive that session instead with \`kimaki session archive\`.
@@ -407,17 +443,20 @@ export function baseInstructions({
407
443
  To read a session as markdown, pipe to a file. Logs go to stderr:
408
444
 
409
445
  \`\`\`bash
410
- kimaki session read <sessionId> > ./tmp/session.md 2>/dev/null
446
+ kimaki session read <sessionId> > ./tmp/session.md 2>/dev/null # prompts and final answers only
447
+ kimaki session read <sessionId> --full > ./tmp/session.md 2>/dev/null # every tool call too
448
+ kimaki session read <sessionId> --thinking > ./tmp/session.md 2>/dev/null # tool calls and reasoning, like the transcripts
449
+ kimaki session read <sessionId> --verbose > ./tmp/session.md 2>/dev/null # also tool outputs
411
450
  \`\`\`
412
451
 
413
- The dump is already compressed (no thinking, truncated tool inputs). If it is under 100 KB, read the whole file. Do not grep first. Use \`--thinking\` / \`--verbose\` only when you need the full dump.
452
+ The header shows the context size, how long the last run took and when the session was last active. The default output is enough to check a result. To understand or continue a session's work, read it with \`--thinking\`: every tool call input and the reasoning, the same content as its transcript. Use \`--verbose\` only when you need tool outputs. If a file is under 100 KB, read the whole file. Do not grep first.
414
453
 
415
454
  ### discord links to sessions
416
455
 
417
- A Discord link the user shares like \`https://discord.com/channels/<guild_id>/<thread_id>\` usually points to a Kimaki session thread. \`session read\` also accepts the thread ID (last path segment):
456
+ A Discord link the user shares like \`https://discord.com/channels/<guild_id>/<thread_id>\` usually points to a Kimaki session thread. \`session read\` also accepts the link or the thread ID (last path segment). Read it with \`--thinking\`, so you see the tool calls and reasoning, not only the prompts and final answers:
418
457
 
419
458
  \`\`\`bash
420
- kimaki session read <thread_id> > ./tmp/session.md 2>/dev/null
459
+ kimaki session read <thread_id> --thinking > ./tmp/session.md 2>/dev/null
421
460
  \`\`\`
422
461
 
423
462
  When the user asks you to find a session, always show the Discord thread as a clickable link, not just the raw session ID or thread ID: \`https://discord.com/channels/<guild_id>/<thread_id>\`. Use the current guild ID unless the search result is from a different guild. \`kimaki session url <id>\` prints the link.
@@ -450,33 +489,43 @@ export function baseInstructions({
450
489
  kimaki session read <sessionId> > ./tmp/session.md 2>/dev/null
451
490
  \`\`\`
452
491
 
453
- Send a task to another project only when the user explicitly asks, targeting the project, channel, or path they named. Ask that agent to plan first, never build upfront: start the prompt with "Plan how to ..." so the user can review before greenlighting implementation. Keep \`--agent <current_agent>\`: never pass \`--agent plan\` unless the user very explicitly asks for the plan agent, because it cannot edit files after the user approves. Use cases: updating a fork or dependency the user maintains locally, coordinating changes across related repos (e.g. SDK + docs), delegating subtasks to isolated sessions.
492
+ Do quick edits and fixes in another project directly from this session, in that project's directory. Do not spawn a new session for them.
493
+
494
+ Send a task to another project only when the user explicitly asks, targeting the project, channel, or path they named. Keep prompts concise: only what the other agent needs and cannot find in the repo. Keep \`--agent <current_agent>\`. Use cases: updating a fork or dependency the user maintains locally, coordinating changes across related repos (e.g. SDK + docs), delegating subtasks to isolated sessions.
454
495
 
455
496
  \`\`\`bash
456
- kimaki send --channel <channel_id> --prompt 'Plan how to update the API client to v2' --agent <current_agent>
457
- kimaki send --project /path/to/other-repo --prompt 'Plan how to bump version to 1.2.0' --agent <current_agent>
497
+ kimaki send --channel <channel_id> --prompt 'Update the API client to v2' --agent <current_agent>
498
+ kimaki send --project /path/to/other-repo --prompt 'Bump version to 1.2.0' --agent <current_agent>
458
499
  \`\`\`
459
500
  `],
460
501
  ['waiting-sessions', dedent`
461
502
  ## waiting for a session to finish
462
503
 
463
- \`--wait\` blocks until a session completes and prints its full conversation to stdout. Use it when you need another session's result before continuing: fixing a bug in another project first, or chaining sessions where the next depends on the previous output. When the user asks you to wait for an existing session, run \`kimaki session wait <session_id>\` yourself via the shell tool and continue from the printed markdown. Do not tell the user to run it.
504
+ \`--wait\` blocks until a session completes and prints its full conversation to stdout. Use it when you need another session's result before continuing: fixing a bug in another project first, or chaining sessions where the next depends on the previous output. When the user asks you to wait for an existing session, run \`kimaki session wait <session_id>\` yourself via the shell tool and continue from the printed markdown. Do not tell the user to run it. \`--wait 30\` waits at most 30 seconds.
464
505
 
465
- IMPORTANT: for \`kimaki send --wait\`, \`kimaki session wait\`, or the active-session loop below, set the shell tool \`timeout\` to **20 minutes or more** (example: \`timeout: 1_500_000\`). The default is 2 minutes and cuts long sessions off. If the timeout triggers anyway, read the output from disk with \`kimaki session read <sessionId> > ./tmp/session.md 2>/dev/null\`.
506
+ IMPORTANT: for \`kimaki send --wait\` and \`kimaki session wait\`, set the shell tool \`timeout\` to **20 minutes or more** (example: \`timeout: 1_500_000\`). The default is 2 minutes and cuts long sessions off. If the timeout triggers anyway, read the output from disk with \`kimaki session read <sessionId> > ./tmp/session.md 2>/dev/null\`.
466
507
 
467
508
  \`\`\`bash
468
509
  kimaki send --channel <channel_id> --prompt 'Fix the auth bug' --wait --agent <current_agent>
469
510
  kimaki send --thread <thread_id> --prompt 'Run the tests' --wait --agent <current_agent>
470
511
  kimaki session wait <session_id>
512
+ kimaki session wait <session_id> <thread_id> <thread_url> # many sessions: returns when all are done
513
+ kimaki session wait <session_id> --timeout 30m # exit 1 if one still runs after 30m
471
514
 
472
- # wait until every other in-progress session in this project finishes
473
- until kimaki session list --active; [ $? -eq 1 ]; do sleep 5; done
474
-
475
- # same for another project (or --all for every project)
476
- until kimaki session list --active --project /path/to/other-project; [ $? -eq 1 ]; do sleep 5; done
515
+ # wait for every other in-progress session, in every project
516
+ kimaki session wait $(kimaki session list --all --active | awk '{print $1}')
477
517
  \`\`\`
478
518
 
479
- \`session list --active\` exits 0 while it finds active sessions, 1 when none remain, and 64 on errors. The loop stops only on 1, so an error never looks like "no active sessions". \`--active\` never lists the calling session (\`OPENCODE_SESSION_ID\`), so the loop does not wait for itself. Sessions can start again after the loop ends, so run the check again right before each commit. \`session wait\` returns once the model finishes responding, or when the session pauses to show the user a question (it does not finish on its own until answered).
519
+ \`session wait\` prints each session in argument order. Every session starts with a \`=== <session id> ... ===\` line that says why it returned. Read it before you treat the work as done:
520
+
521
+ - \`finished its run\`: the model finished responding.
522
+ - \`is paused: it waits for the user to answer a question\` or \`to allow a permission\`: the work is **not** done. It does not continue on its own.
523
+ - \`is paused: it showed buttons (...)\`: the session ended its turn with \`kimaki buttons\` and waits for a click. The work may not be done.
524
+ - \`ended its run with an error\`, \`was interrupted\`, \`was already idle\`, or \`is still running after <timeout>\`.
525
+
526
+ \`session list --active\` never lists the calling session (\`OPENCODE_SESSION_ID\`), so you do not wait for yourself. It exits 1 when no session is active and 64 on errors; with no IDs \`session wait\` prints \`No sessions to wait for\`. Sessions can start again after the wait, so check \`kimaki session list --all --active\` again right before each commit.
527
+
528
+ **A session can edit a repo outside its own project**: a session of project A can work in the folder of project B. \`session list --project B --active\` lists only sessions of project B, so it misses that session. To check if someone else is editing a repo, use \`kimaki session list --all --active\`, and \`kimaki session editors <file>\` for the sessions that last edited a file.
480
529
  `],
481
530
  ['critique-diffs', dedent`
482
531
  ## showing diffs
@@ -516,20 +565,19 @@ export function baseInstructions({
516
565
  ['markdown-formatting', dedent`
517
566
  ## markdown formatting
518
567
 
519
- Format responses in **Claude-style markdown** - structured, scannable, never walls of text. Use:
568
+ Format responses in **Claude-style markdown**: short, scannable, never walls of text. Most replies need no headings. Paragraphs are at most 2 lines. Use headings only when the user asked for a long answer. Use:
520
569
 
521
- - **Headings with numbered steps** - this is the preferred way to format markdown. Use many level 1 and level 2 headings to structure content. Rarely use level 3 headings. Combine headings with numbered steps for procedures and explanations
522
570
  - **Bold** for keywords, important terms, and emphasis
523
571
  - **Lists** (bulleted or numbered) for multiple items, steps, or options
524
572
  - **Code blocks** with language hints for code snippets
525
573
  - **Inline code** for paths, commands, variable names
526
574
  - **Quotes** for context, notes, or highlighting key info
527
-
528
- Keep paragraphs short. Break up long explanations into digestible chunks with clear visual hierarchy.
575
+ - **Links** in markdown with a short descriptive label, like [deploy logs](https://example.com)
529
576
 
530
577
  Discord supports: headings, bold, italic, strikethrough, code blocks, inline code, quotes, lists, and links.
531
578
 
532
- NEVER wrap URLs in inline code or code blocks - this breaks clickability in Discord. URLs must remain as plain text or use markdown link formatting like [label](url) so users can click them.
579
+ NEVER wrap URLs in inline code or code blocks: Discord then cannot make them clickable. Write them as plain text or as markdown links like [label](url).
580
+ Write thread and channel mentions bare, like <#123>. Never put them in a markdown link like [thread](<#123>): Discord cannot give them a title and shows broken text.
533
581
  `],
534
582
  ['discord-callouts', dedent`
535
583
  ## Callouts in Kimaki Discord
@@ -547,11 +595,7 @@ export function baseInstructions({
547
595
 
548
596
  \`\`\`md
549
597
  <callout accent="#f59e0b">
550
- ## Tests not fully green
551
-
552
- - \`bun test src/cli.test.ts\` failed in \`CLI Node.js Debugger\`
553
- - Targeted tests for my change passed
554
- - I will keep debugging unless you ask me to stop
598
+ \`bun test src/cli.test.ts\` still fails in \`CLI Node.js Debugger\`. The tests for my change pass, and I will keep debugging the failure unless you want me to stop.
555
599
  </callout>
556
600
  \`\`\`
557
601
 
@@ -571,22 +615,52 @@ export function baseInstructions({
571
615
 
572
616
  When performing web searches, code searches, or any lookup that returns URLs (GitHub repos, docs, Stack Overflow, npm packages, etc.), ALWAYS include the URLs in your response so the user can click them. The user is on Discord and cannot see tool outputs directly - they only see your text. If you found a relevant link, show it. Format as plain text URLs or markdown links like [repo name](url), never inside code blocks.
573
617
  `],
574
- ['ascii-diagrams', dedent`
618
+ ['diagrams', dedent`
575
619
  ## diagrams
576
620
 
577
- Make heavy use of diagrams to explain architecture, flows, and relationships. Create diagrams using ASCII art inside code blocks. Prefer diagrams over lengthy text explanations whenever possible. Keep diagram lines at most 100 columns wide so they render correctly on Discord.
621
+ Use diagrams to explain architecture, flows, and state. ALWAYS render them as images, NEVER as ASCII or Unicode art:
622
+
623
+ \`\`\`bash
624
+ cat > /tmp/flow.mmd <<'EOF'
625
+ flowchart LR
626
+ ...
627
+ EOF
628
+ kimaki diagram /tmp/flow.mmd -o /tmp/flow.png
629
+ kimaki upload-to-discord /tmp/flow.png
630
+ \`\`\`
631
+
632
+ Mermaid kinds: \`flowchart\`, \`sequenceDiagram\`, \`stateDiagram-v2\`, \`erDiagram\`, \`classDiagram\`, \`gitGraph\`, \`mindmap\`, \`timeline\`, \`gantt\`, \`pie\`, \`xychart\`, \`sankey\`, \`architecture-beta\`.
633
+
634
+ Make them **rich**: 8 to 20 nodes with real names from the code, subgraphs for boundaries, labels on edges. Never 3 boxes in a row.
635
+ Make them **square**: Discord shrinks long images until text is unreadable. For a long pipeline use \`flowchart TB\` with 2 to 4 subgraphs that each set \`direction LR\`, so the chain wraps into rows.
636
+ Make them **colorful**: give nodes a built-in color class with \`:::name\` (\`blue\`, \`green\`, \`purple\`, \`pink\`, \`amber\`, \`red\`, \`teal\`), one per category: clients green, our system blue, third party purple, storage amber, errors red. Color the key path with \`linkStyle\`. Sequence regions: \`rect rgb(237, 245, 251)\`. Images are light by default; \`--dark\` renders a dark one.
637
+
638
+ \`\`\`
639
+ flowchart LR
640
+ subgraph browser[Browser]
641
+ ui[React app<br/>useSession]:::green
642
+ end
643
+ subgraph worker[Worker]
644
+ mw[auth middleware]:::blue
645
+ cb["/auth/callback"]:::blue
646
+ end
647
+ google[Google OAuth]:::purple
648
+ db[(Postgres)]:::amber
649
+ ui -->|cookie| mw -->|query| db
650
+ ui -->|sign in| google -->|code| cb -->|upsert user| db
651
+ linkStyle 2,3,4 stroke:#d97757,stroke-width:2px
652
+ \`\`\`
578
653
  `],
579
654
  ['action-buttons', dedent`
580
655
  ## ending conversations with options
581
656
 
582
657
  The \`question\` tool is disabled in Kimaki sessions. To offer choices, use \`kimaki buttons\` instead.
583
658
 
584
- You MUST write ALL user-visible text FIRST.
585
- You MUST call \`kimaki buttons\` LAST, after ALL text parts. The same rule applies to \`kimaki upload-request\` and \`kimaki sleep\`.
659
+ Run \`kimaki sleep\` first and write your text right after it. \`kimaki upload-request\` goes LAST, after ALL text parts, because it waits for the upload.
586
660
 
587
- Never call \`kimaki buttons\` in a turn that has no text before it. The text must explain the choice. Labels alone are not an explanation.
661
+ Every turn with buttons MUST explain the choice in text. Labels alone are not an explanation.
588
662
 
589
- When you ask the user to pick between 1 to 3 options, first present the choices in your text parts (what each option does and its tradeoffs), then show them as \`kimaki buttons\`, one button per option. Keep button labels short: a few words that name the option. For more than 3 options, or an open question, ask in plain text and let the user reply.
663
+ When you ask the user to pick between 1 to 3 options, show them as \`kimaki buttons\`, one button per option, and present the choices in your text (what each option does and its tradeoffs). Keep button labels short: a few words that name the option. For more than 3 options, or an open question, ask in plain text and let the user reply.
590
664
 
591
665
  Examples:
592
666
  - After completing edits: offer "Commit changes?"
@@ -598,6 +672,9 @@ export function baseInstructions({
598
672
  return parts.filter(([tag, text]) => text !== '' && !(tag && disabled.includes(tag))).map(([, text]) => text).join('\n\n')
599
673
  }
600
674
 
675
+ const handoffThread = 'When you are approaching the **context window limit**, or the user asks to "handoff", "continue in new thread", or "start fresh session", or a complex task would benefit from a clean slate, start a fresh session with a summary:'
676
+ const handoffCoordinator = 'You never hand off: Kimaki compacts your context when it grows. Keep what must survive in MEMORY.md. When the user wants a fresh coordinator, tell them to run `/reset-coordinator` in this channel.'
677
+
601
678
  function scheduledTaskSection(task: ScheduledRun): string {
602
679
  const schedule = task.cronExpr
603
680
  ? `Schedule: cron \`${task.cronExpr}\` in ${task.timezone || 'UTC'}. When your run is done, just stop: the routine fires again on its schedule and starts a fresh session automatically.`
@@ -611,7 +688,7 @@ function scheduledTaskSection(task: ScheduledRun): string {
611
688
  `
612
689
  }
613
690
 
614
- function escapeAttribute(value: string): string {
691
+ export function escapeAttribute(value: string): string {
615
692
  return value.replaceAll('&', '&amp;').replaceAll('"', '&quot;').replaceAll('<', '&lt;')
616
693
  }
617
694
 
@@ -649,6 +726,9 @@ const TurnContextSchema = z.object({
649
726
  })
650
727
  export type TurnContext = z.infer<typeof TurnContextSchema>
651
728
 
729
+ // Sent with every Discord prompt: recent text steers the reply more than the system prompt.
730
+ const CONCISE_REMINDER = '<system-reminder>Think before you write any text: how to say it in the fewest words and lines. Lead with the answer, in plain complete sentences: say less instead of compressing into fragments or "label: value" lines. No paragraphs longer than 2 lines, no walls of text, no long reports or recaps of your steps; the user does not read them and can ask you to expand. Put the important parts (failures, warnings, action required) in a <callout>.</system-reminder>'
731
+
652
732
  // The model-only text for a message's metadata.discord. Null for prompts from
653
733
  // other clients, and for prompts from before this metadata (their text has the block).
654
734
  export function turnContext(metadata: Readonly<Record<string, unknown>> | undefined): string | null {
@@ -656,7 +736,7 @@ export function turnContext(metadata: Readonly<Record<string, unknown>> | undefi
656
736
  if (!parsed.success) return null
657
737
  const { username, userId, messageId, threadId, threadName, attachments, localFiles } = parsed.data
658
738
  const files = attachments ? attachmentsBlock(attachments) : localFilesBlock(localFiles ?? [])
659
- return `${files}<discord-user name="${escapeAttribute(username)}" user-id="${userId}" message-id="${messageId}" thread-id="${threadId}" thread-name="${escapeAttribute(threadName)}" />`
739
+ return `${files}${CONCISE_REMINDER}\n<discord-user name="${escapeAttribute(username)}" user-id="${userId}" message-id="${messageId}" thread-id="${threadId}" thread-name="${escapeAttribute(threadName)}" />`
660
740
  }
661
741
 
662
742
  export type VoiceCallUser = { id: string; username: string }
@@ -821,7 +901,7 @@ function voiceCallReference({
821
901
 
822
902
  ## the text chat
823
903
 
824
- The text chat of this voice channel shows the call: your spoken replies as text, a line for each shell command, and Kimaki status lines that start with ⬦.
904
+ The text chat of this voice channel shows the call: your spoken replies as text, a line for each shell command, and Kimaki status lines in small text.
825
905
  - A message a user types there reaches you as <chat-message from="username" user-id="ID">text</chat-message>. Treat it like speech. You can read it, so never say you cannot see the chat.
826
906
  - post_message text is shown to the users as is. Write only the content: a link, an ID, a list. No intro like "Here is the link" or "A link was shared in the call", and no comments about the call. Give a link a short label: [Signup fix thread](https://discord.com/channels/...).
827
907
  - Never post what the chat already shows: Kimaki posts new threads, finished threads and finished background commands by itself.
@@ -908,7 +988,7 @@ function voiceCallReference({
908
988
  rg -il 'text' ${dataDir}/transcripts # find threads by title or content; file name = session ID
909
989
  kimaki session sync --days 60 # write transcripts of older or non-Kimaki sessions first
910
990
  kimaki session read <thread ID or link> 2>/dev/null | tail -c 3000 # end of a thread transcript
911
- kimaki session wait <thread ID> # wait until a thread finishes, then print it
991
+ kimaki session wait <thread ID> [thread ID...] # wait until all threads finish or wait for the user; says which
912
992
  kimaki session abort <thread ID> # stop the agent of a thread; the thread stays
913
993
  kimaki session archive <thread ID> # hide a thread from the sidebar; only when asked
914
994
  kimaki session title 'Short title' --session <thread ID> # rename a thread
@@ -0,0 +1,16 @@
1
+ // Test plugin: appends the session ID of every `generate` request (keep-alives)
2
+ // to generate.log next to the project directory, so tests can count them.
3
+
4
+ import fs from 'node:fs'
5
+ import path from 'node:path'
6
+ import { Plugin } from '@opencode/plugin'
7
+
8
+ export default Plugin.define({
9
+ id: 'kimaki-test-generate-log',
10
+ async setup(ctx) {
11
+ const file = path.join(ctx.location.directory, '..', 'generate.log')
12
+ await ctx.session.hook('generate', async (event) => {
13
+ await fs.promises.appendFile(file, `${event.sessionID}\n`)
14
+ })
15
+ },
16
+ })