kimaki 0.26.0 → 0.27.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 (214) hide show
  1. package/dist/agent-model.e2e.test.js +25 -122
  2. package/dist/anthropic-account-identity.js +1 -0
  3. package/dist/anthropic-auth-plugin.js +1 -0
  4. package/dist/anthropic-auth-state.js +1 -0
  5. package/dist/bin.js +73 -19
  6. package/dist/cli-commands/maintenance.js +46 -7
  7. package/dist/cli-commands/send.js +24 -0
  8. package/dist/cli-commands/session.js +183 -8
  9. package/dist/cli-commands/task.js +13 -1
  10. package/dist/cli-parsing.test.js +59 -3
  11. package/dist/cli-runner.js +28 -4
  12. package/dist/cli-runner.test.js +27 -0
  13. package/dist/cli-send-thread.e2e.test.js +1 -1
  14. package/dist/cli.js +32 -0
  15. package/dist/commands/abort.js +5 -1
  16. package/dist/commands/agent.js +6 -8
  17. package/dist/commands/ask-question.js +21 -32
  18. package/dist/commands/ask-question.test.js +43 -1
  19. package/dist/commands/login.js +6 -0
  20. package/dist/commands/merge-worktree.js +36 -10
  21. package/dist/commands/model-variant.js +7 -1
  22. package/dist/commands/model.js +14 -8
  23. package/dist/commands/multioauth.js +1 -0
  24. package/dist/commands/new-worktree.js +170 -102
  25. package/dist/commands/user-command.js +6 -8
  26. package/dist/commands/worktrees.js +5 -13
  27. package/dist/config.js +16 -1
  28. package/dist/database.js +124 -3
  29. package/dist/db.js +22 -0
  30. package/dist/db.test.js +167 -1
  31. package/dist/discord-bot.js +34 -32
  32. package/dist/discord-command-registration.js +9 -1
  33. package/dist/discord-utils.js +13 -5
  34. package/dist/discord-utils.test.js +17 -1
  35. package/dist/errors.js +5 -0
  36. package/dist/exec-async.js +17 -5
  37. package/dist/external-directory-permissions.e2e.test.js +2 -2
  38. package/dist/file-edit-log.js +197 -0
  39. package/dist/file-edit-log.test.js +258 -0
  40. package/dist/format-tables.js +52 -0
  41. package/dist/format-tables.test.js +93 -0
  42. package/dist/gateway-proxy-reconnect.e2e.test.js +28 -8
  43. package/dist/gateway-proxy.e2e.test.js +5 -5
  44. package/dist/git-worktree-core.js +182 -17
  45. package/dist/ipc-tools-plugin.js +63 -3
  46. package/dist/kimaki-opencode-plugin-loading.e2e.test.js +122 -58
  47. package/dist/kimaki-opencode-plugin.js +7 -3
  48. package/dist/kimaki-workspace-adaptor.js +33 -10
  49. package/dist/logger.js +10 -1
  50. package/dist/markdown.js +3 -1
  51. package/dist/markdown.test.js +11 -3
  52. package/dist/message-formatting.js +18 -7
  53. package/dist/message-formatting.test.js +56 -9
  54. package/dist/oauth-rotation-shared.js +10 -0
  55. package/dist/openai-auth-plugin.js +1 -0
  56. package/dist/openai-auth-state.js +1 -0
  57. package/dist/opencode-command.test.js +60 -0
  58. package/dist/opencode.js +53 -12
  59. package/dist/question-abort-clears-dropdown.e2e.test.js +89 -0
  60. package/dist/question-text-before-dropdown.e2e.test.js +52 -0
  61. package/dist/queue-advanced-abort.e2e.test.js +1 -1
  62. package/dist/queue-advanced-action-buttons.e2e.test.js +3 -3
  63. package/dist/queue-advanced-e2e-setup.js +78 -5
  64. package/dist/queue-advanced-footer.e2e.test.js +40 -246
  65. package/dist/queue-advanced-model-switch.e2e.test.js +2 -2
  66. package/dist/queue-advanced-permissions-typing.e2e.test.js +7 -9
  67. package/dist/queue-advanced-question.e2e.test.js +31 -26
  68. package/dist/queue-advanced-typing-interrupt.e2e.test.js +2 -2
  69. package/dist/queue-delete-message.e2e.test.js +1 -1
  70. package/dist/queue-drain-after-interactive-ui.e2e.test.js +2 -2
  71. package/dist/queue-interrupt-drain.e2e.test.js +112 -2
  72. package/dist/queue-question-select-drain.e2e.test.js +30 -128
  73. package/dist/runtime-lifecycle.e2e.test.js +10 -37
  74. package/dist/schema.js +34 -0
  75. package/dist/session-handler/event-stream-state.js +267 -50
  76. package/dist/session-handler/event-stream-state.test.js +415 -8
  77. package/dist/session-handler/model-utils.js +159 -5
  78. package/dist/session-handler/model-utils.test.js +345 -0
  79. package/dist/session-handler/thread-session-runtime.js +252 -182
  80. package/dist/session-sleep.test.js +224 -0
  81. package/dist/session-title-rename.test.js +7 -39
  82. package/dist/sleep.e2e.test.js +491 -0
  83. package/dist/startup-time.e2e.test.js +2 -1
  84. package/dist/store.js +3 -0
  85. package/dist/system-message.js +59 -6
  86. package/dist/system-message.test.js +76 -6
  87. package/dist/task-runner.js +94 -4
  88. package/dist/task-schedule.js +56 -0
  89. package/dist/task-schedule.test.js +71 -1
  90. package/dist/thread-message-queue.e2e.test.js +10 -169
  91. package/dist/undo-redo.e2e.test.js +2 -2
  92. package/dist/voice-attachment.js +23 -1
  93. package/dist/voice-message.e2e.test.js +10 -10
  94. package/dist/voice.test.js +55 -29
  95. package/dist/worktree-clone-isolation.e2e.test.js +188 -0
  96. package/dist/worktree-lifecycle.e2e.test.js +29 -10
  97. package/dist/worktrees.js +226 -443
  98. package/dist/worktrees.test.js +435 -58
  99. package/dist/xai-auth-plugin.js +1 -0
  100. package/dist/xai-auth-state.js +1 -0
  101. package/package.json +8 -6
  102. package/skills/errore/SKILL.md +18 -0
  103. package/skills/goke/SKILL.md +150 -10
  104. package/skills/holocron/SKILL.md +37 -0
  105. package/skills/npm-package/SKILL.md +55 -35
  106. package/skills/profano/SKILL.md +17 -2
  107. package/skills/spiceflow/SKILL.md +39 -3
  108. package/skills/strada/SKILL.md +39 -0
  109. package/skills/zele/SKILL.md +19 -0
  110. package/src/agent-model.e2e.test.ts +25 -151
  111. package/src/anthropic-account-identity.ts +1 -0
  112. package/src/anthropic-auth-plugin.ts +1 -0
  113. package/src/anthropic-auth-state.ts +1 -0
  114. package/src/bin.ts +78 -26
  115. package/src/cli-commands/maintenance.ts +59 -13
  116. package/src/cli-commands/send.ts +25 -0
  117. package/src/cli-commands/session.ts +203 -9
  118. package/src/cli-commands/task.ts +13 -1
  119. package/src/cli-parsing.test.ts +69 -3
  120. package/src/cli-runner.test.ts +49 -0
  121. package/src/cli-runner.ts +28 -4
  122. package/src/cli-send-thread.e2e.test.ts +1 -1
  123. package/src/cli.ts +53 -0
  124. package/src/commands/abort.ts +6 -1
  125. package/src/commands/agent.ts +6 -6
  126. package/src/commands/ask-question.test.ts +48 -1
  127. package/src/commands/ask-question.ts +21 -32
  128. package/src/commands/login.ts +6 -0
  129. package/src/commands/merge-worktree.ts +43 -12
  130. package/src/commands/model-variant.ts +8 -1
  131. package/src/commands/model.ts +18 -8
  132. package/src/commands/multioauth.ts +1 -0
  133. package/src/commands/new-worktree.ts +138 -55
  134. package/src/commands/user-command.ts +6 -6
  135. package/src/commands/worktrees.ts +5 -12
  136. package/src/config.ts +18 -1
  137. package/src/database.ts +195 -3
  138. package/src/db.test.ts +188 -0
  139. package/src/db.ts +26 -0
  140. package/src/discord-bot.ts +35 -29
  141. package/src/discord-command-registration.ts +15 -1
  142. package/src/discord-utils.test.ts +19 -0
  143. package/src/discord-utils.ts +21 -6
  144. package/src/errors.ts +5 -0
  145. package/src/exec-async.ts +20 -11
  146. package/src/external-directory-permissions.e2e.test.ts +2 -2
  147. package/src/file-edit-log.test.ts +287 -0
  148. package/src/file-edit-log.ts +283 -0
  149. package/src/format-tables.test.ts +101 -0
  150. package/src/format-tables.ts +75 -0
  151. package/src/gateway-proxy-reconnect.e2e.test.ts +38 -8
  152. package/src/gateway-proxy.e2e.test.ts +5 -5
  153. package/src/git-worktree-core.ts +247 -20
  154. package/src/ipc-tools-plugin.ts +75 -5
  155. package/src/kimaki-opencode-plugin-loading.e2e.test.ts +188 -97
  156. package/src/kimaki-opencode-plugin.ts +7 -3
  157. package/src/kimaki-workspace-adaptor.ts +40 -11
  158. package/src/logger.ts +13 -4
  159. package/src/markdown.test.ts +13 -3
  160. package/src/markdown.ts +4 -1
  161. package/src/message-formatting.test.ts +86 -12
  162. package/src/message-formatting.ts +19 -7
  163. package/src/oauth-rotation-shared.ts +10 -0
  164. package/src/openai-auth-plugin.ts +1 -0
  165. package/src/openai-auth-state.ts +1 -0
  166. package/src/opencode-command.test.ts +81 -0
  167. package/src/opencode.ts +71 -11
  168. package/src/question-abort-clears-dropdown.e2e.test.ts +109 -0
  169. package/src/question-text-before-dropdown.e2e.test.ts +67 -0
  170. package/src/queue-advanced-abort.e2e.test.ts +1 -1
  171. package/src/queue-advanced-action-buttons.e2e.test.ts +3 -3
  172. package/src/queue-advanced-e2e-setup.ts +83 -4
  173. package/src/queue-advanced-footer.e2e.test.ts +47 -294
  174. package/src/queue-advanced-model-switch.e2e.test.ts +2 -2
  175. package/src/queue-advanced-permissions-typing.e2e.test.ts +7 -9
  176. package/src/queue-advanced-question.e2e.test.ts +35 -29
  177. package/src/queue-advanced-typing-interrupt.e2e.test.ts +2 -2
  178. package/src/queue-delete-message.e2e.test.ts +1 -1
  179. package/src/queue-drain-after-interactive-ui.e2e.test.ts +2 -2
  180. package/src/queue-interrupt-drain.e2e.test.ts +123 -2
  181. package/src/queue-question-select-drain.e2e.test.ts +32 -157
  182. package/src/runtime-lifecycle.e2e.test.ts +10 -41
  183. package/src/schema.sql +14 -1
  184. package/src/schema.ts +36 -0
  185. package/src/session-handler/event-stream-state.test.ts +437 -7
  186. package/src/session-handler/event-stream-state.ts +389 -53
  187. package/src/session-handler/model-utils.test.ts +415 -0
  188. package/src/session-handler/model-utils.ts +249 -5
  189. package/src/session-handler/thread-session-runtime.ts +300 -215
  190. package/src/session-sleep.test.ts +294 -0
  191. package/src/session-title-rename.test.ts +9 -48
  192. package/src/sleep.e2e.test.ts +562 -0
  193. package/src/startup-time.e2e.test.ts +5 -1
  194. package/src/store.ts +21 -0
  195. package/src/system-message.test.ts +86 -6
  196. package/src/system-message.ts +66 -7
  197. package/src/task-runner.ts +136 -2
  198. package/src/task-schedule.test.ts +76 -0
  199. package/src/task-schedule.ts +95 -0
  200. package/src/thread-message-queue.e2e.test.ts +10 -202
  201. package/src/undo-redo.e2e.test.ts +2 -2
  202. package/src/voice-attachment.ts +29 -1
  203. package/src/voice-message.e2e.test.ts +10 -10
  204. package/src/voice.test.ts +63 -29
  205. package/src/worktree-clone-isolation.e2e.test.ts +213 -0
  206. package/src/worktree-lifecycle.e2e.test.ts +29 -9
  207. package/src/worktrees.test.ts +505 -64
  208. package/src/worktrees.ts +257 -603
  209. package/src/xai-auth-plugin.ts +1 -0
  210. package/src/xai-auth-state.ts +1 -0
  211. package/dist/message-finish-field.e2e.test.js +0 -169
  212. package/dist/subagent-rate-limit-plugin.js +0 -184
  213. package/src/message-finish-field.e2e.test.ts +0 -196
  214. package/src/subagent-rate-limit-plugin.ts +0 -228
@@ -0,0 +1,491 @@
1
+ // E2e coverage for the durable kimaki_sleep tool.
2
+ // Verifies the tool persists a wake row, the thread shows the sleep line,
3
+ // the task runner wake resumes the same session, and a user message cancels
4
+ // a planned sleep so the wake never fires.
5
+ import { describe, test, expect } from 'vitest';
6
+ import { setupQueueAdvancedSuite, TEST_USER_ID, } from './queue-advanced-e2e-setup.js';
7
+ import { waitForBotMessageContaining, waitForFooterMessage, } from './test-utils.js';
8
+ import { getSessionSleep, getThreadSession } from './database.js';
9
+ import { wakeDueSessionSleeps } from './task-runner.js';
10
+ const TEXT_CHANNEL_ID = '200000000000001031';
11
+ // Fixed wake instant so the wake message stays snapshot-stable across runs.
12
+ const SLEEP_UNTIL = '2030-01-01T09:00:00Z';
13
+ const AFTER_SLEEP_UNTIL = new Date('2030-01-01T09:00:01Z');
14
+ function createSleepMatchers() {
15
+ const sleepCallMatcher = {
16
+ id: 'sleep-tool-call',
17
+ priority: 130,
18
+ when: {
19
+ lastMessageRole: 'user',
20
+ latestUserTextIncludes: 'SLEEP_TOOL_MARKER',
21
+ },
22
+ then: {
23
+ parts: [
24
+ { type: 'stream-start', warnings: [] },
25
+ { type: 'text-start', id: 'sleep-call-text' },
26
+ {
27
+ type: 'text-delta',
28
+ id: 'sleep-call-text',
29
+ delta: 'waiting for the deploy',
30
+ },
31
+ { type: 'text-end', id: 'sleep-call-text' },
32
+ {
33
+ type: 'tool-call',
34
+ toolCallId: 'sleep-call-1',
35
+ toolName: 'kimaki_sleep',
36
+ input: JSON.stringify({
37
+ until: SLEEP_UNTIL,
38
+ reason: 'waiting for the deploy',
39
+ }),
40
+ },
41
+ {
42
+ type: 'finish',
43
+ finishReason: 'tool-calls',
44
+ usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
45
+ },
46
+ ],
47
+ },
48
+ };
49
+ const sleepAcknowledgeMatcher = {
50
+ id: 'sleep-tool-ack',
51
+ priority: 129,
52
+ when: {
53
+ latestUserTextIncludes: 'SLEEP_TOOL_MARKER',
54
+ rawPromptIncludes: 'Sleeping until',
55
+ },
56
+ then: {
57
+ parts: [
58
+ { type: 'stream-start', warnings: [] },
59
+ { type: 'text-start', id: 'sleep-ack-text' },
60
+ { type: 'text-delta', id: 'sleep-ack-text', delta: 'sleep-started' },
61
+ { type: 'text-end', id: 'sleep-ack-text' },
62
+ {
63
+ type: 'finish',
64
+ finishReason: 'stop',
65
+ usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
66
+ },
67
+ ],
68
+ },
69
+ };
70
+ const sleepWakeMatcher = {
71
+ id: 'sleep-tool-wake',
72
+ priority: 131,
73
+ when: {
74
+ latestUserTextIncludes: 'Woke after sleeping until',
75
+ },
76
+ then: {
77
+ parts: [
78
+ { type: 'stream-start', warnings: [] },
79
+ { type: 'text-start', id: 'sleep-wake-text' },
80
+ { type: 'text-delta', id: 'sleep-wake-text', delta: 'sleep-wake-done' },
81
+ { type: 'text-end', id: 'sleep-wake-text' },
82
+ {
83
+ type: 'finish',
84
+ finishReason: 'stop',
85
+ usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
86
+ },
87
+ ],
88
+ },
89
+ };
90
+ const sleepCancelCallMatcher = {
91
+ id: 'sleep-cancel-call',
92
+ priority: 132,
93
+ when: {
94
+ lastMessageRole: 'user',
95
+ latestUserTextIncludes: 'SLEEP_CANCEL_MARKER',
96
+ },
97
+ then: {
98
+ parts: [
99
+ { type: 'stream-start', warnings: [] },
100
+ {
101
+ type: 'tool-call',
102
+ toolCallId: 'sleep-cancel-call-1',
103
+ toolName: 'kimaki_sleep',
104
+ input: JSON.stringify({ duration: '2h', reason: 'cancel me' }),
105
+ },
106
+ {
107
+ type: 'finish',
108
+ finishReason: 'tool-calls',
109
+ usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
110
+ },
111
+ ],
112
+ },
113
+ };
114
+ const sleepCancelAckMatcher = {
115
+ id: 'sleep-cancel-ack',
116
+ priority: 133,
117
+ when: {
118
+ latestUserTextIncludes: 'SLEEP_CANCEL_MARKER',
119
+ rawPromptIncludes: 'Sleeping until',
120
+ },
121
+ then: {
122
+ parts: [
123
+ { type: 'stream-start', warnings: [] },
124
+ { type: 'text-start', id: 'sleep-cancel-ack-text' },
125
+ {
126
+ type: 'text-delta',
127
+ id: 'sleep-cancel-ack-text',
128
+ delta: 'cancel-sleep-started',
129
+ },
130
+ { type: 'text-end', id: 'sleep-cancel-ack-text' },
131
+ {
132
+ type: 'finish',
133
+ finishReason: 'stop',
134
+ usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
135
+ },
136
+ ],
137
+ },
138
+ };
139
+ const sleepQueueCallMatcher = {
140
+ id: 'sleep-queue-call',
141
+ priority: 135,
142
+ when: {
143
+ lastMessageRole: 'user',
144
+ latestUserTextIncludes: 'SLEEP_QUEUE_MARKER',
145
+ },
146
+ then: {
147
+ parts: [
148
+ { type: 'stream-start', warnings: [] },
149
+ {
150
+ type: 'tool-call',
151
+ toolCallId: 'sleep-queue-call-1',
152
+ toolName: 'kimaki_sleep',
153
+ input: JSON.stringify({ duration: '2h', reason: 'queue supersedes' }),
154
+ },
155
+ {
156
+ type: 'finish',
157
+ finishReason: 'tool-calls',
158
+ usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
159
+ },
160
+ ],
161
+ },
162
+ };
163
+ const sleepQueueAckMatcher = {
164
+ id: 'sleep-queue-ack',
165
+ priority: 136,
166
+ when: {
167
+ latestUserTextIncludes: 'SLEEP_QUEUE_MARKER',
168
+ rawPromptIncludes: 'Sleeping until',
169
+ },
170
+ then: {
171
+ parts: [
172
+ { type: 'stream-start', warnings: [] },
173
+ { type: 'text-start', id: 'sleep-queue-ack-text' },
174
+ {
175
+ type: 'text-delta',
176
+ id: 'sleep-queue-ack-text',
177
+ delta: 'queue-sleep-started',
178
+ },
179
+ { type: 'text-end', id: 'sleep-queue-ack-text' },
180
+ {
181
+ type: 'finish',
182
+ finishReason: 'stop',
183
+ usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
184
+ },
185
+ ],
186
+ },
187
+ };
188
+ const sleepQueuedMessageMatcher = {
189
+ id: 'sleep-queued-message',
190
+ priority: 137,
191
+ when: {
192
+ lastMessageRole: 'user',
193
+ latestUserTextIncludes: 'SLEEP_QUEUE_FOLLOWUP',
194
+ },
195
+ then: {
196
+ parts: [
197
+ { type: 'stream-start', warnings: [] },
198
+ { type: 'text-start', id: 'sleep-queued-text' },
199
+ {
200
+ type: 'text-delta',
201
+ id: 'sleep-queued-text',
202
+ delta: 'queue-followup-done',
203
+ },
204
+ { type: 'text-end', id: 'sleep-queued-text' },
205
+ {
206
+ type: 'finish',
207
+ finishReason: 'stop',
208
+ usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
209
+ },
210
+ ],
211
+ },
212
+ };
213
+ const sleepCancelFollowupMatcher = {
214
+ id: 'sleep-cancel-followup',
215
+ priority: 134,
216
+ when: {
217
+ lastMessageRole: 'user',
218
+ latestUserTextIncludes: 'SLEEP_CANCEL_FOLLOWUP',
219
+ },
220
+ then: {
221
+ parts: [
222
+ { type: 'stream-start', warnings: [] },
223
+ { type: 'text-start', id: 'sleep-cancel-followup-text' },
224
+ {
225
+ type: 'text-delta',
226
+ id: 'sleep-cancel-followup-text',
227
+ delta: 'cancel-followup-done',
228
+ },
229
+ { type: 'text-end', id: 'sleep-cancel-followup-text' },
230
+ {
231
+ type: 'finish',
232
+ finishReason: 'stop',
233
+ usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
234
+ },
235
+ ],
236
+ },
237
+ };
238
+ return [
239
+ sleepCallMatcher,
240
+ sleepAcknowledgeMatcher,
241
+ sleepWakeMatcher,
242
+ sleepCancelCallMatcher,
243
+ sleepCancelAckMatcher,
244
+ sleepCancelFollowupMatcher,
245
+ sleepQueueCallMatcher,
246
+ sleepQueueAckMatcher,
247
+ sleepQueuedMessageMatcher,
248
+ ];
249
+ }
250
+ describe('kimaki_sleep', () => {
251
+ const ctx = setupQueueAdvancedSuite({
252
+ channelId: TEXT_CHANNEL_ID,
253
+ channelName: 'sleep-e2e',
254
+ dirName: 'sleep-e2e',
255
+ username: 'sleep-tester',
256
+ extraMatchers: createSleepMatchers(),
257
+ });
258
+ test('persists a wake row, then the runner wakes the same session', async () => {
259
+ await ctx.discord.channel(TEXT_CHANNEL_ID).user(TEST_USER_ID).sendMessage({
260
+ content: 'SLEEP_TOOL_MARKER wait for the deploy',
261
+ });
262
+ const thread = await ctx.discord.channel(TEXT_CHANNEL_ID).waitForThread({
263
+ timeout: 4_000,
264
+ predicate: (t) => {
265
+ return t.name === 'SLEEP_TOOL_MARKER wait for the deploy';
266
+ },
267
+ });
268
+ const th = ctx.discord.thread(thread.id);
269
+ await waitForBotMessageContaining({
270
+ discord: ctx.discord,
271
+ threadId: thread.id,
272
+ text: 'sleep-started',
273
+ timeout: 4_000,
274
+ });
275
+ // Let the first turn finish emitting its footer before waking, otherwise
276
+ // the footer can land after the wake message and reorder the snapshot.
277
+ await waitForFooterMessage({
278
+ discord: ctx.discord,
279
+ threadId: thread.id,
280
+ timeout: 4_000,
281
+ afterMessageIncludes: 'sleep-started',
282
+ afterAuthorId: ctx.discord.botUserId,
283
+ });
284
+ const sessionId = await getThreadSession(thread.id);
285
+ if (!sessionId) {
286
+ throw new Error('Expected a thread session after the sleep tool ran');
287
+ }
288
+ const plannedSleep = await getSessionSleep({ sessionId });
289
+ expect(plannedSleep?.status).toBe('planned');
290
+ expect(plannedSleep?.reason).toBe('waiting for the deploy');
291
+ // The row is years out, so pass a future `now` instead of waiting on the tick.
292
+ await wakeDueSessionSleeps({
293
+ rest: ctx.botClient.rest,
294
+ now: AFTER_SLEEP_UNTIL,
295
+ });
296
+ await waitForBotMessageContaining({
297
+ discord: ctx.discord,
298
+ threadId: thread.id,
299
+ text: 'sleep-wake-done',
300
+ timeout: 4_000,
301
+ });
302
+ await waitForFooterMessage({
303
+ discord: ctx.discord,
304
+ threadId: thread.id,
305
+ timeout: 4_000,
306
+ afterMessageIncludes: 'sleep-wake-done',
307
+ afterAuthorId: ctx.discord.botUserId,
308
+ });
309
+ expect(await th.text()).toMatchInlineSnapshot(`
310
+ "--- from: user (sleep-tester)
311
+ SLEEP_TOOL_MARKER wait for the deploy
312
+ --- from: assistant (TestBot)
313
+ *using deterministic-provider/deterministic-v2*
314
+ ⬥ waiting for the deploy
315
+ ┣ kimaki_sleep until 2030-01-01T09:00:00Z _waiting for the deploy_
316
+ ⬥ sleep-started
317
+ *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2* <@200000000000000991>
318
+ ⬦ Woke after sleeping until 2030-01-01 09:00 UTC
319
+ Reason: waiting for the deploy
320
+ Continue the work you were waiting for.
321
+ [embed]
322
+ ⬥ sleep-wake-done
323
+ *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2* <@200000000000000991>"
324
+ `);
325
+ // The wake must continue the SAME OpenCode session, not start a new one:
326
+ // that is the whole point of sleeping instead of scheduling a new prompt.
327
+ expect(await getThreadSession(thread.id)).toBe(sessionId);
328
+ // `consumed` proves ingress actually turned the wake into a turn. The row
329
+ // only reaches this state through the ingress commit point.
330
+ const wokenSleep = await getSessionSleep({ sessionId });
331
+ expect(wokenSleep?.status).toBe('consumed');
332
+ // Replaying the tick must not produce a second wake turn.
333
+ const messagesBeforeReplay = (await th.getMessages()).length;
334
+ await wakeDueSessionSleeps({
335
+ rest: ctx.botClient.rest,
336
+ now: AFTER_SLEEP_UNTIL,
337
+ });
338
+ for (let attempt = 0; attempt < 10; attempt++) {
339
+ expect((await th.getMessages()).length).toBe(messagesBeforeReplay);
340
+ await new Promise((resolve) => {
341
+ setTimeout(resolve, 20);
342
+ });
343
+ }
344
+ }, 20_000);
345
+ test('a user message cancels a planned sleep so no wake fires', async () => {
346
+ await ctx.discord.channel(TEXT_CHANNEL_ID).user(TEST_USER_ID).sendMessage({
347
+ content: 'SLEEP_CANCEL_MARKER wait for something',
348
+ });
349
+ const thread = await ctx.discord.channel(TEXT_CHANNEL_ID).waitForThread({
350
+ timeout: 4_000,
351
+ predicate: (t) => {
352
+ return t.name === 'SLEEP_CANCEL_MARKER wait for something';
353
+ },
354
+ });
355
+ const th = ctx.discord.thread(thread.id);
356
+ await waitForBotMessageContaining({
357
+ discord: ctx.discord,
358
+ threadId: thread.id,
359
+ text: 'cancel-sleep-started',
360
+ timeout: 4_000,
361
+ });
362
+ await waitForFooterMessage({
363
+ discord: ctx.discord,
364
+ threadId: thread.id,
365
+ timeout: 4_000,
366
+ afterMessageIncludes: 'cancel-sleep-started',
367
+ afterAuthorId: ctx.discord.botUserId,
368
+ });
369
+ const sessionId = await getThreadSession(thread.id);
370
+ if (!sessionId) {
371
+ throw new Error('Expected a thread session after the sleep tool ran');
372
+ }
373
+ expect((await getSessionSleep({ sessionId }))?.status).toBe('planned');
374
+ await th.user(TEST_USER_ID).sendMessage({
375
+ content: 'SLEEP_CANCEL_FOLLOWUP never mind, keep going',
376
+ });
377
+ await waitForBotMessageContaining({
378
+ discord: ctx.discord,
379
+ threadId: thread.id,
380
+ text: 'cancel-followup-done',
381
+ timeout: 4_000,
382
+ });
383
+ await waitForFooterMessage({
384
+ discord: ctx.discord,
385
+ threadId: thread.id,
386
+ timeout: 4_000,
387
+ afterMessageIncludes: 'cancel-followup-done',
388
+ afterAuthorId: ctx.discord.botUserId,
389
+ });
390
+ // Cancellation happens inside runtime.enqueueIncoming, so it covers
391
+ // slash commands and CLI-injected prompts, not just chat messages.
392
+ expect((await getSessionSleep({ sessionId }))?.status).toBe('cancelled');
393
+ await wakeDueSessionSleeps({
394
+ rest: ctx.botClient.rest,
395
+ now: AFTER_SLEEP_UNTIL,
396
+ });
397
+ // Everything is deterministic, so a short poll proves the wake never posts.
398
+ for (let attempt = 0; attempt < 10; attempt++) {
399
+ const messages = await th.getMessages();
400
+ const woke = messages.some((message) => {
401
+ return message.content.includes('Woke after sleeping until');
402
+ });
403
+ expect(woke).toBe(false);
404
+ await new Promise((resolve) => {
405
+ setTimeout(resolve, 20);
406
+ });
407
+ }
408
+ expect(await th.text()).toMatchInlineSnapshot(`
409
+ "--- from: user (sleep-tester)
410
+ SLEEP_CANCEL_MARKER wait for something
411
+ --- from: assistant (TestBot)
412
+ *using deterministic-provider/deterministic-v2*
413
+ ┣ kimaki_sleep for 2h _cancel me_
414
+ ⬥ cancel-sleep-started
415
+ *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2* <@200000000000000991>
416
+ --- from: user (sleep-tester)
417
+ SLEEP_CANCEL_FOLLOWUP never mind, keep going
418
+ --- from: assistant (TestBot)
419
+ ⬥ cancel-followup-done
420
+ *project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2* <@200000000000000991>"
421
+ `);
422
+ }, 20_000);
423
+ test('/queue also supersedes a pending sleep', async () => {
424
+ // Slash commands never reach the Discord MessageCreate handler, so this
425
+ // proves cancellation really lives in the shared ingress path.
426
+ await ctx.discord.channel(TEXT_CHANNEL_ID).user(TEST_USER_ID).sendMessage({
427
+ content: 'SLEEP_QUEUE_MARKER wait for something',
428
+ });
429
+ const thread = await ctx.discord.channel(TEXT_CHANNEL_ID).waitForThread({
430
+ timeout: 4_000,
431
+ predicate: (t) => {
432
+ return t.name === 'SLEEP_QUEUE_MARKER wait for something';
433
+ },
434
+ });
435
+ const th = ctx.discord.thread(thread.id);
436
+ await waitForBotMessageContaining({
437
+ discord: ctx.discord,
438
+ threadId: thread.id,
439
+ text: 'queue-sleep-started',
440
+ timeout: 4_000,
441
+ });
442
+ await waitForFooterMessage({
443
+ discord: ctx.discord,
444
+ threadId: thread.id,
445
+ timeout: 4_000,
446
+ afterMessageIncludes: 'queue-sleep-started',
447
+ afterAuthorId: ctx.discord.botUserId,
448
+ });
449
+ const sessionId = await getThreadSession(thread.id);
450
+ if (!sessionId) {
451
+ throw new Error('Expected a thread session after the sleep tool ran');
452
+ }
453
+ expect((await getSessionSleep({ sessionId }))?.status).toBe('planned');
454
+ const { id: queueInteractionId } = await th.user(TEST_USER_ID)
455
+ .runSlashCommand({
456
+ name: 'queue',
457
+ options: [
458
+ {
459
+ name: 'message',
460
+ type: 3,
461
+ value: 'SLEEP_QUEUE_FOLLOWUP handle this instead',
462
+ },
463
+ ],
464
+ });
465
+ await th.waitForInteractionAck({
466
+ interactionId: queueInteractionId,
467
+ timeout: 4_000,
468
+ });
469
+ await waitForBotMessageContaining({
470
+ discord: ctx.discord,
471
+ threadId: thread.id,
472
+ text: 'queue-followup-done',
473
+ timeout: 4_000,
474
+ });
475
+ expect((await getSessionSleep({ sessionId }))?.status).toBe('cancelled');
476
+ await wakeDueSessionSleeps({
477
+ rest: ctx.botClient.rest,
478
+ now: AFTER_SLEEP_UNTIL,
479
+ });
480
+ for (let attempt = 0; attempt < 10; attempt++) {
481
+ const messages = await th.getMessages();
482
+ const woke = messages.some((message) => {
483
+ return message.content.includes('Woke after sleeping until');
484
+ });
485
+ expect(woke).toBe(false);
486
+ await new Promise((resolve) => {
487
+ setTimeout(resolve, 20);
488
+ });
489
+ }
490
+ }, 20_000);
491
+ });
@@ -81,7 +81,8 @@ function createMinimalMatchers() {
81
81
  }
82
82
  const TEST_USER_ID = '900000000000000777';
83
83
  const TEXT_CHANNEL_ID = '900000000000000778';
84
- describe('startup time measurement', () => {
84
+ const startupBenchmark = describe.skipIf(process.env['KIMAKI_STARTUP_BENCHMARK'] !== '1');
85
+ startupBenchmark('startup time measurement', () => {
85
86
  let directories;
86
87
  let discord;
87
88
  let botClient = null;
package/dist/store.js CHANGED
@@ -9,10 +9,13 @@ export const store = createStore(() => ({
9
9
  defaultVerbosity: 'text_and_essential_tools',
10
10
  defaultMentionMode: false,
11
11
  critiqueEnabled: true,
12
+ footerMentionsEnabled: true,
12
13
  enabledSkills: [],
13
14
  disabledSkills: [],
14
15
  allowedMentions: ['users'],
15
16
  allowAllUsers: false,
17
+ opencodeHostname: null,
18
+ opencodePort: null,
16
19
  restrictExternalDirectories: false,
17
20
  permissionTimeoutMs: 10 * 60 * 1000,
18
21
  useWorktrees: false,
@@ -238,7 +238,7 @@ function escapePromptText(value) {
238
238
  .replaceAll('<', '&lt;')
239
239
  .replaceAll('>', '&gt;');
240
240
  }
241
- export function getOpencodePromptContext({ username, userId, sourceMessageId, sourceThreadId, repliedMessage, worktree, currentAgent, worktreeChanged, }) {
241
+ export function getOpencodePromptContext({ username, userId, sourceMessageId, sourceThreadId, threadName, repliedMessage, worktree, currentAgent, worktreeChanged, }) {
242
242
  const userAttrs = [
243
243
  ...(username
244
244
  ? [` name="${escapePromptAttribute(username)}"`]
@@ -252,6 +252,9 @@ export function getOpencodePromptContext({ username, userId, sourceMessageId, so
252
252
  ...(sourceThreadId
253
253
  ? [` thread-id="${escapePromptAttribute(sourceThreadId)}"`]
254
254
  : []),
255
+ ...(threadName
256
+ ? [` thread-name="${escapePromptAttribute(threadName)}"`]
257
+ : []),
255
258
  ].join('');
256
259
  const repliedMessageXml = repliedMessage
257
260
  ? `This message was a reply to message
@@ -325,7 +328,7 @@ interface BashToolInput {
325
328
 
326
329
  Your current OpenCode session ID is: ${sessionId}${channelId ? `\nYour current Discord channel ID is: ${channelId}` : ''}${threadId ? `\nYour current Discord thread ID is: ${threadId}` : ''}${guildId ? `\nYour current Discord guild ID is: ${guildId}` : ''}${parentSessionContext}
327
330
 
328
- Per-turn Discord metadata like the current user and current agent is delivered in synthetic user message parts.
331
+ Per-turn Discord metadata like the current user, current agent, and Discord thread title is delivered in synthetic user message parts.
329
332
 
330
333
  ## permissions
331
334
 
@@ -348,6 +351,7 @@ Do not restart the bot unless the user explicitly asks for it.
348
351
 
349
352
  ## debugging kimaki issues
350
353
 
354
+ ALWAYS read https://kimaki.dev/docs/guides/report-bugs first before submitting any issue to Kimaki. That page is the source of truth for exporting session jsonl, sharing evidence in a gist, and filing bugs. Never open a pull request on remorses/kimaki unless remorses asked for one in a comment on the issue.
351
355
  If there are internal kimaki issues (sessions not responding, bot errors, unexpected behavior), read the log file at \`${getDataDir()}/kimaki.log\`. This file contains detailed logs of all bot activity including session creation, event handling, errors, and API calls. The log file is reset every time the bot restarts, so it only contains logs from the current run.
352
356
 
353
357
  ## uploading files to discord
@@ -377,9 +381,16 @@ see --help for options like voice, speed, etc.
377
381
  To ask the user to upload files from their device, use \`kimaki_file_upload\`. This shows a native file picker dialog in Discord. The files are downloaded to the project's \`uploads/\` directory and the tool returns the local file paths.
378
382
  You MUST call \`kimaki_file_upload\` LAST, after ALL text.
379
383
 
384
+ ## sleeping the session
385
+
386
+ Use \`kimaki_sleep\` to pause this session for hours or days, then continue when the time is reached. The sleep is stored in SQLite and survives bot restarts.
387
+ Pass either \`duration\` (\`30s\`, \`2h\`, \`1d\`) or \`until\` (UTC ISO ending with \`Z\`, example \`2026-08-20T09:00:00Z\`).
388
+ You MUST call \`kimaki_sleep\` LAST, after ALL text. Do not call more tools after it.
389
+ A new user message cancels the sleep. After wake, continue the wait reason.
390
+
380
391
  ## archiving the current thread
381
392
 
382
- To archive the current Discord thread (hide it from sidebar) and stop the session, run:
393
+ To archive the current Discord thread (hide it from sidebar) without stopping the session, run:
383
394
 
384
395
  kimaki session archive ${archiveTarget}
385
396
 
@@ -394,6 +405,17 @@ kimaki session abort <session_id>
394
405
  This stops the AI from processing but keeps the thread visible in Discord.
395
406
  Different from \`kimaki session archive\` which hides the thread.
396
407
 
408
+ ## updating the session title
409
+
410
+ When the session scope or goal changed from the first message, update the title:
411
+
412
+ kimaki session title 'Short title' --session ${sessionId}
413
+
414
+ The current Discord thread title is in the per-turn \`<discord-user thread-name="..." />\` metadata.
415
+ This updates the OpenCode title. Discord follows automatically.
416
+ Do not retitle every turn. Discord rate-limits thread renames.
417
+ Keep titles short. Do not add emoji. Do not copy ⬦, btw:, or Fork: prefixes.
418
+
397
419
  ## discord user mentions
398
420
 
399
421
  Prefer Discord user IDs for mentions. Discord bots cannot ping by @name; use \`<@userId>\` in message text or pass the ID to \`--user\`.
@@ -622,6 +644,9 @@ To list all sessions in this project (shows which were started via kimaki):
622
644
  kimaki session list
623
645
  kimaki session list --json # machine-readable output
624
646
  kimaki session list --project /path/to/project # specific project
647
+
648
+ # List only in-progress sessions. Exit status is 1 when none remain.
649
+ kimaki session list --active
625
650
  \`\`\`
626
651
 
627
652
  To search past sessions for this project (supports plain text or /regex/flags):
@@ -642,6 +667,29 @@ kimaki session read <sessionId> > ./tmp/session.md 2>/dev/null
642
667
 
643
668
  Then use grep/read tools on the file to find what you need.
644
669
 
670
+ ### who edited a file
671
+
672
+ To find the session that last edited a file, run:
673
+
674
+ \`\`\`bash
675
+ kimaki session editors src/foo.ts
676
+ kimaki session editors src/foo.ts --json
677
+ \`\`\`
678
+
679
+ Output is newest first. Each row has:
680
+
681
+ - **session ID** (\`ses_xxx\`)
682
+ - **title** (Discord thread name, so you can tell what that session was doing)
683
+ - **time ago** (when that session last edited the file)
684
+
685
+ Use this before a commit when this session did not edit the file. Put the original session ID as the last line of the commit message:
686
+
687
+ \`\`\`
688
+ Session: ses_xxx
689
+ \`\`\`
690
+
691
+ If this session edited the file, use this session ID instead. If several files come from different sessions, split the commit by session. Do not attribute another session's edits to this one.
692
+
645
693
  ## cross-project commands
646
694
 
647
695
  When the user references another project by name, run \`kimaki project list\` to find its directory path and channel ID. Then read files, search code, or run commands directly in that directory. If the project is not listed, use \`kimaki project add /path/to/repo\` to register it and create a Discord channel for it. Do not add subfolders of an existing project — only add root project directories.
@@ -708,7 +756,7 @@ Use \`--wait\` to block until a session completes and print its full conversatio
708
756
 
709
757
  When the user asks you to wait for an existing session, run \`kimaki session wait <session_id>\` yourself via Bash, then continue from the printed session markdown. Do not tell the user to run the command.
710
758
 
711
- IMPORTANT: if you run \`kimaki send --wait\` or \`kimaki session wait <session_id>\` via the Bash tool, you must set the Bash tool \`timeout\` to **20 minutes or more** (example: \`timeout: 1_500_000\`). Otherwise the tool will terminate early (default is 2 minutes) and you won't see long sessions.
759
+ IMPORTANT: if you run \`kimaki send --wait\`, \`kimaki session wait <session_id>\`, or the active-session wait loop via the Bash tool, you must set the Bash tool \`timeout\` to **20 minutes or more** (example: \`timeout: 1_500_000\`). Otherwise the tool will terminate early (default is 2 minutes) and you won't see long sessions.
712
760
 
713
761
  If your Bash tool timeout triggers anyway, fall back to reading the session output from disk:
714
762
 
@@ -723,9 +771,14 @@ kimaki send --thread <thread_id> --prompt 'Run the tests' --wait --agent <curren
723
771
 
724
772
  # Wait for a session that was already started elsewhere
725
773
  kimaki session wait <session_id>
774
+
775
+ # Wait until every other in-progress session in this project finishes
776
+ while kimaki session list --active --exclude ${sessionId}; do sleep 5; done
726
777
  \`\`\`
727
778
 
728
- The command exits with the session markdown on stdout once the model finishes responding.
779
+ \`session list --active\` exits with status 0 while it finds active sessions and status 1 when none remain. Exclude the current session in a wait loop so the loop does not wait for itself.
780
+
781
+ \`session wait\` exits with the session markdown on stdout once the model finishes responding.
729
782
 
730
783
  Use \`--wait\` when you need to:
731
784
  - **Fix a bug in another project** before continuing here (e.g. fix a dependency, then resume)
@@ -838,7 +891,7 @@ You MUST write ALL user-visible text FIRST.
838
891
  You MUST call \`question\` LAST, after ALL text parts.
839
892
  NEVER call \`question\` before your text. Discord will hide the message.
840
893
 
841
- The same rule applies to \`kimaki_action_buttons\` and \`kimaki_file_upload\`.
894
+ The same rule applies to \`kimaki_action_buttons\`, \`kimaki_file_upload\`, and \`kimaki_sleep\`.
842
895
  You MUST call them LAST, after ALL text.
843
896
 
844
897
  ALWAYS use \`question\` when you ask the user a question. Do not write a numbered list in plain text.