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.
- package/dist/agent-model.e2e.test.js +25 -122
- package/dist/anthropic-account-identity.js +1 -0
- package/dist/anthropic-auth-plugin.js +1 -0
- package/dist/anthropic-auth-state.js +1 -0
- package/dist/bin.js +73 -19
- package/dist/cli-commands/maintenance.js +46 -7
- package/dist/cli-commands/send.js +24 -0
- package/dist/cli-commands/session.js +183 -8
- package/dist/cli-commands/task.js +13 -1
- package/dist/cli-parsing.test.js +59 -3
- package/dist/cli-runner.js +28 -4
- package/dist/cli-runner.test.js +27 -0
- package/dist/cli-send-thread.e2e.test.js +1 -1
- package/dist/cli.js +32 -0
- package/dist/commands/abort.js +5 -1
- package/dist/commands/agent.js +6 -8
- package/dist/commands/ask-question.js +21 -32
- package/dist/commands/ask-question.test.js +43 -1
- package/dist/commands/login.js +6 -0
- package/dist/commands/merge-worktree.js +36 -10
- package/dist/commands/model-variant.js +7 -1
- package/dist/commands/model.js +14 -8
- package/dist/commands/multioauth.js +1 -0
- package/dist/commands/new-worktree.js +170 -102
- package/dist/commands/user-command.js +6 -8
- package/dist/commands/worktrees.js +5 -13
- package/dist/config.js +16 -1
- package/dist/database.js +124 -3
- package/dist/db.js +22 -0
- package/dist/db.test.js +167 -1
- package/dist/discord-bot.js +34 -32
- package/dist/discord-command-registration.js +9 -1
- package/dist/discord-utils.js +13 -5
- package/dist/discord-utils.test.js +17 -1
- package/dist/errors.js +5 -0
- package/dist/exec-async.js +17 -5
- package/dist/external-directory-permissions.e2e.test.js +2 -2
- package/dist/file-edit-log.js +197 -0
- package/dist/file-edit-log.test.js +258 -0
- package/dist/format-tables.js +52 -0
- package/dist/format-tables.test.js +93 -0
- package/dist/gateway-proxy-reconnect.e2e.test.js +28 -8
- package/dist/gateway-proxy.e2e.test.js +5 -5
- package/dist/git-worktree-core.js +182 -17
- package/dist/ipc-tools-plugin.js +63 -3
- package/dist/kimaki-opencode-plugin-loading.e2e.test.js +122 -58
- package/dist/kimaki-opencode-plugin.js +7 -3
- package/dist/kimaki-workspace-adaptor.js +33 -10
- package/dist/logger.js +10 -1
- package/dist/markdown.js +3 -1
- package/dist/markdown.test.js +11 -3
- package/dist/message-formatting.js +18 -7
- package/dist/message-formatting.test.js +56 -9
- package/dist/oauth-rotation-shared.js +10 -0
- package/dist/openai-auth-plugin.js +1 -0
- package/dist/openai-auth-state.js +1 -0
- package/dist/opencode-command.test.js +60 -0
- package/dist/opencode.js +53 -12
- package/dist/question-abort-clears-dropdown.e2e.test.js +89 -0
- package/dist/question-text-before-dropdown.e2e.test.js +52 -0
- package/dist/queue-advanced-abort.e2e.test.js +1 -1
- package/dist/queue-advanced-action-buttons.e2e.test.js +3 -3
- package/dist/queue-advanced-e2e-setup.js +78 -5
- package/dist/queue-advanced-footer.e2e.test.js +40 -246
- package/dist/queue-advanced-model-switch.e2e.test.js +2 -2
- package/dist/queue-advanced-permissions-typing.e2e.test.js +7 -9
- package/dist/queue-advanced-question.e2e.test.js +31 -26
- package/dist/queue-advanced-typing-interrupt.e2e.test.js +2 -2
- package/dist/queue-delete-message.e2e.test.js +1 -1
- package/dist/queue-drain-after-interactive-ui.e2e.test.js +2 -2
- package/dist/queue-interrupt-drain.e2e.test.js +112 -2
- package/dist/queue-question-select-drain.e2e.test.js +30 -128
- package/dist/runtime-lifecycle.e2e.test.js +10 -37
- package/dist/schema.js +34 -0
- package/dist/session-handler/event-stream-state.js +267 -50
- package/dist/session-handler/event-stream-state.test.js +415 -8
- package/dist/session-handler/model-utils.js +159 -5
- package/dist/session-handler/model-utils.test.js +345 -0
- package/dist/session-handler/thread-session-runtime.js +252 -182
- package/dist/session-sleep.test.js +224 -0
- package/dist/session-title-rename.test.js +7 -39
- package/dist/sleep.e2e.test.js +491 -0
- package/dist/startup-time.e2e.test.js +2 -1
- package/dist/store.js +3 -0
- package/dist/system-message.js +59 -6
- package/dist/system-message.test.js +76 -6
- package/dist/task-runner.js +94 -4
- package/dist/task-schedule.js +56 -0
- package/dist/task-schedule.test.js +71 -1
- package/dist/thread-message-queue.e2e.test.js +10 -169
- package/dist/undo-redo.e2e.test.js +2 -2
- package/dist/voice-attachment.js +23 -1
- package/dist/voice-message.e2e.test.js +10 -10
- package/dist/voice.test.js +55 -29
- package/dist/worktree-clone-isolation.e2e.test.js +188 -0
- package/dist/worktree-lifecycle.e2e.test.js +29 -10
- package/dist/worktrees.js +226 -443
- package/dist/worktrees.test.js +435 -58
- package/dist/xai-auth-plugin.js +1 -0
- package/dist/xai-auth-state.js +1 -0
- package/package.json +8 -6
- package/skills/errore/SKILL.md +18 -0
- package/skills/goke/SKILL.md +150 -10
- package/skills/holocron/SKILL.md +37 -0
- package/skills/npm-package/SKILL.md +55 -35
- package/skills/profano/SKILL.md +17 -2
- package/skills/spiceflow/SKILL.md +39 -3
- package/skills/strada/SKILL.md +39 -0
- package/skills/zele/SKILL.md +19 -0
- package/src/agent-model.e2e.test.ts +25 -151
- package/src/anthropic-account-identity.ts +1 -0
- package/src/anthropic-auth-plugin.ts +1 -0
- package/src/anthropic-auth-state.ts +1 -0
- package/src/bin.ts +78 -26
- package/src/cli-commands/maintenance.ts +59 -13
- package/src/cli-commands/send.ts +25 -0
- package/src/cli-commands/session.ts +203 -9
- package/src/cli-commands/task.ts +13 -1
- package/src/cli-parsing.test.ts +69 -3
- package/src/cli-runner.test.ts +49 -0
- package/src/cli-runner.ts +28 -4
- package/src/cli-send-thread.e2e.test.ts +1 -1
- package/src/cli.ts +53 -0
- package/src/commands/abort.ts +6 -1
- package/src/commands/agent.ts +6 -6
- package/src/commands/ask-question.test.ts +48 -1
- package/src/commands/ask-question.ts +21 -32
- package/src/commands/login.ts +6 -0
- package/src/commands/merge-worktree.ts +43 -12
- package/src/commands/model-variant.ts +8 -1
- package/src/commands/model.ts +18 -8
- package/src/commands/multioauth.ts +1 -0
- package/src/commands/new-worktree.ts +138 -55
- package/src/commands/user-command.ts +6 -6
- package/src/commands/worktrees.ts +5 -12
- package/src/config.ts +18 -1
- package/src/database.ts +195 -3
- package/src/db.test.ts +188 -0
- package/src/db.ts +26 -0
- package/src/discord-bot.ts +35 -29
- package/src/discord-command-registration.ts +15 -1
- package/src/discord-utils.test.ts +19 -0
- package/src/discord-utils.ts +21 -6
- package/src/errors.ts +5 -0
- package/src/exec-async.ts +20 -11
- package/src/external-directory-permissions.e2e.test.ts +2 -2
- package/src/file-edit-log.test.ts +287 -0
- package/src/file-edit-log.ts +283 -0
- package/src/format-tables.test.ts +101 -0
- package/src/format-tables.ts +75 -0
- package/src/gateway-proxy-reconnect.e2e.test.ts +38 -8
- package/src/gateway-proxy.e2e.test.ts +5 -5
- package/src/git-worktree-core.ts +247 -20
- package/src/ipc-tools-plugin.ts +75 -5
- package/src/kimaki-opencode-plugin-loading.e2e.test.ts +188 -97
- package/src/kimaki-opencode-plugin.ts +7 -3
- package/src/kimaki-workspace-adaptor.ts +40 -11
- package/src/logger.ts +13 -4
- package/src/markdown.test.ts +13 -3
- package/src/markdown.ts +4 -1
- package/src/message-formatting.test.ts +86 -12
- package/src/message-formatting.ts +19 -7
- package/src/oauth-rotation-shared.ts +10 -0
- package/src/openai-auth-plugin.ts +1 -0
- package/src/openai-auth-state.ts +1 -0
- package/src/opencode-command.test.ts +81 -0
- package/src/opencode.ts +71 -11
- package/src/question-abort-clears-dropdown.e2e.test.ts +109 -0
- package/src/question-text-before-dropdown.e2e.test.ts +67 -0
- package/src/queue-advanced-abort.e2e.test.ts +1 -1
- package/src/queue-advanced-action-buttons.e2e.test.ts +3 -3
- package/src/queue-advanced-e2e-setup.ts +83 -4
- package/src/queue-advanced-footer.e2e.test.ts +47 -294
- package/src/queue-advanced-model-switch.e2e.test.ts +2 -2
- package/src/queue-advanced-permissions-typing.e2e.test.ts +7 -9
- package/src/queue-advanced-question.e2e.test.ts +35 -29
- package/src/queue-advanced-typing-interrupt.e2e.test.ts +2 -2
- package/src/queue-delete-message.e2e.test.ts +1 -1
- package/src/queue-drain-after-interactive-ui.e2e.test.ts +2 -2
- package/src/queue-interrupt-drain.e2e.test.ts +123 -2
- package/src/queue-question-select-drain.e2e.test.ts +32 -157
- package/src/runtime-lifecycle.e2e.test.ts +10 -41
- package/src/schema.sql +14 -1
- package/src/schema.ts +36 -0
- package/src/session-handler/event-stream-state.test.ts +437 -7
- package/src/session-handler/event-stream-state.ts +389 -53
- package/src/session-handler/model-utils.test.ts +415 -0
- package/src/session-handler/model-utils.ts +249 -5
- package/src/session-handler/thread-session-runtime.ts +300 -215
- package/src/session-sleep.test.ts +294 -0
- package/src/session-title-rename.test.ts +9 -48
- package/src/sleep.e2e.test.ts +562 -0
- package/src/startup-time.e2e.test.ts +5 -1
- package/src/store.ts +21 -0
- package/src/system-message.test.ts +86 -6
- package/src/system-message.ts +66 -7
- package/src/task-runner.ts +136 -2
- package/src/task-schedule.test.ts +76 -0
- package/src/task-schedule.ts +95 -0
- package/src/thread-message-queue.e2e.test.ts +10 -202
- package/src/undo-redo.e2e.test.ts +2 -2
- package/src/voice-attachment.ts +29 -1
- package/src/voice-message.e2e.test.ts +10 -10
- package/src/voice.test.ts +63 -29
- package/src/worktree-clone-isolation.e2e.test.ts +213 -0
- package/src/worktree-lifecycle.e2e.test.ts +29 -9
- package/src/worktrees.test.ts +505 -64
- package/src/worktrees.ts +257 -603
- package/src/xai-auth-plugin.ts +1 -0
- package/src/xai-auth-state.ts +1 -0
- package/dist/message-finish-field.e2e.test.js +0 -169
- package/dist/subagent-rate-limit-plugin.js +0 -184
- package/src/message-finish-field.e2e.test.ts +0 -196
- package/src/subagent-rate-limit-plugin.ts +0 -228
|
@@ -264,11 +264,11 @@ describe('runtime lifecycle', () => {
|
|
|
264
264
|
}, 5_000)
|
|
265
265
|
|
|
266
266
|
test(
|
|
267
|
-
'
|
|
267
|
+
'two sequential completions reuse same runtime and listener',
|
|
268
268
|
async () => {
|
|
269
|
-
// Sends A, waits for full completion (footer), sends B
|
|
270
|
-
//
|
|
271
|
-
//
|
|
269
|
+
// Sends A, waits for full completion (footer), then sends B and waits
|
|
270
|
+
// for its footer. Proves the listener stays alive across full run cycles
|
|
271
|
+
// without any interrupt/queue involvement.
|
|
272
272
|
// This is the "calm" path — no abort, no queue, just sequential use.
|
|
273
273
|
|
|
274
274
|
// 1. Send first message → thread created, session established
|
|
@@ -323,51 +323,20 @@ describe('runtime lifecycle', () => {
|
|
|
323
323
|
|
|
324
324
|
// Same runtime instance — listener was not recreated
|
|
325
325
|
const runtimeAfterB = getRuntime(thread.id)
|
|
326
|
-
expect(runtimeAfterB).toBe(runtimeAfterA)
|
|
327
|
-
|
|
328
|
-
// 3. Send C after B fully completed
|
|
329
|
-
await th.user(TEST_USER_ID).sendMessage({
|
|
330
|
-
content: 'Reply with exactly: seq-gamma',
|
|
331
|
-
})
|
|
332
|
-
|
|
333
|
-
await waitForBotReplyAfterUserMessage({
|
|
334
|
-
discord,
|
|
335
|
-
threadId: thread.id,
|
|
336
|
-
userId: TEST_USER_ID,
|
|
337
|
-
userMessageIncludes: 'seq-gamma',
|
|
338
|
-
timeout: 4_000,
|
|
339
|
-
})
|
|
340
|
-
|
|
341
|
-
await waitForBotMessageContaining({
|
|
342
|
-
discord,
|
|
343
|
-
threadId: thread.id,
|
|
344
|
-
userId: TEST_USER_ID,
|
|
345
|
-
text: '*project',
|
|
346
|
-
afterUserMessageIncludes: 'seq-gamma',
|
|
347
|
-
timeout: 4_000,
|
|
348
|
-
})
|
|
349
|
-
|
|
350
|
-
// Still the same runtime — three full cycles, one runtime, one listener
|
|
351
|
-
const runtimeAfterC = getRuntime(thread.id)
|
|
352
326
|
expect(await th.text()).toMatchInlineSnapshot(`
|
|
353
327
|
"--- from: user (lifecycle-tester)
|
|
354
328
|
Reply with exactly: seq-alpha
|
|
355
329
|
--- from: assistant (TestBot)
|
|
356
330
|
*using deterministic-provider/deterministic-v2*
|
|
357
331
|
⬥ ok
|
|
358
|
-
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
|
|
332
|
+
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2* <@200000000000000888>
|
|
359
333
|
--- from: user (lifecycle-tester)
|
|
360
334
|
Reply with exactly: seq-beta
|
|
361
335
|
--- from: assistant (TestBot)
|
|
362
336
|
⬥ ok
|
|
363
|
-
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
|
|
364
|
-
--- from: user (lifecycle-tester)
|
|
365
|
-
Reply with exactly: seq-gamma
|
|
366
|
-
--- from: assistant (TestBot)
|
|
367
|
-
⬥ ok
|
|
368
|
-
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
|
|
337
|
+
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2* <@200000000000000888>"
|
|
369
338
|
`)
|
|
370
|
-
expect(
|
|
339
|
+
expect(runtimeAfterB).toBe(runtimeAfterA)
|
|
371
340
|
},
|
|
372
341
|
15_000,
|
|
373
342
|
)
|
|
@@ -413,7 +382,7 @@ describe('runtime lifecycle', () => {
|
|
|
413
382
|
--- from: assistant (TestBot)
|
|
414
383
|
*using deterministic-provider/deterministic-v2*
|
|
415
384
|
⬥ ok
|
|
416
|
-
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
|
|
385
|
+
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2* <@200000000000000888>"
|
|
417
386
|
`)
|
|
418
387
|
expect(footerMessage).toBeDefined()
|
|
419
388
|
if (!footerMessage) {
|
|
@@ -485,12 +454,12 @@ describe('runtime lifecycle', () => {
|
|
|
485
454
|
--- from: assistant (TestBot)
|
|
486
455
|
*using deterministic-provider/deterministic-v2*
|
|
487
456
|
⬥ ok
|
|
488
|
-
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
|
|
457
|
+
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2* <@200000000000000888>
|
|
489
458
|
--- from: user (lifecycle-tester)
|
|
490
459
|
Reply with exactly: reconnect-beta
|
|
491
460
|
--- from: assistant (TestBot)
|
|
492
461
|
⬥ ok
|
|
493
|
-
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
|
|
462
|
+
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2* <@200000000000000888>"
|
|
494
463
|
`)
|
|
495
464
|
|
|
496
465
|
const runtimeAfterRestart = getRuntime(thread.id)
|
package/src/schema.sql
CHANGED
|
@@ -168,6 +168,17 @@ CREATE TABLE IF NOT EXISTS `session_models` (
|
|
|
168
168
|
`created_at` datetime DEFAULT CURRENT_TIMESTAMP
|
|
169
169
|
);
|
|
170
170
|
|
|
171
|
+
CREATE TABLE IF NOT EXISTS `session_sleeps` (
|
|
172
|
+
`session_id` text PRIMARY KEY,
|
|
173
|
+
`wake_at` datetime NOT NULL,
|
|
174
|
+
`reason` text,
|
|
175
|
+
`status` text DEFAULT 'planned' NOT NULL,
|
|
176
|
+
`delivery_id` text NOT NULL,
|
|
177
|
+
`attempts` integer DEFAULT 0 NOT NULL,
|
|
178
|
+
`last_attempt_at` datetime,
|
|
179
|
+
`created_at` datetime DEFAULT CURRENT_TIMESTAMP
|
|
180
|
+
);
|
|
181
|
+
|
|
171
182
|
CREATE TABLE IF NOT EXISTS `session_start_sources` (
|
|
172
183
|
`session_id` text PRIMARY KEY,
|
|
173
184
|
`schedule_kind` text NOT NULL,
|
|
@@ -183,7 +194,8 @@ CREATE TABLE IF NOT EXISTS `thread_sessions` (
|
|
|
183
194
|
`source` text DEFAULT 'kimaki' NOT NULL,
|
|
184
195
|
`last_synced_name` text,
|
|
185
196
|
`parent_session_id` text,
|
|
186
|
-
`created_at` datetime DEFAULT CURRENT_TIMESTAMP
|
|
197
|
+
`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
|
|
198
|
+
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP
|
|
187
199
|
);
|
|
188
200
|
|
|
189
201
|
CREATE TABLE IF NOT EXISTS `thread_workspaces` (
|
|
@@ -219,4 +231,5 @@ CREATE INDEX IF NOT EXISTS `scheduled_tasks_channel_id_status_idx` ON `scheduled
|
|
|
219
231
|
CREATE INDEX IF NOT EXISTS `scheduled_tasks_thread_id_status_idx` ON `scheduled_tasks` (`thread_id`,`status`);
|
|
220
232
|
CREATE INDEX IF NOT EXISTS `session_events_session_id_timestamp_event_index_id_idx` ON `session_events` (`session_id`,`timestamp`,`event_index`,`id`);
|
|
221
233
|
CREATE INDEX IF NOT EXISTS `session_events_thread_id_timestamp_event_index_id_idx` ON `session_events` (`thread_id`,`timestamp`,`event_index`,`id`);
|
|
234
|
+
CREATE INDEX IF NOT EXISTS `session_sleeps_status_wake_at_idx` ON `session_sleeps` (`status`,`wake_at`);
|
|
222
235
|
CREATE INDEX IF NOT EXISTS `session_start_sources_scheduled_task_id_idx` ON `session_start_sources` (`scheduled_task_id`);
|
package/src/schema.ts
CHANGED
|
@@ -33,6 +33,10 @@ export const thread_sessions = sqliteCore.sqliteTable('thread_sessions', {
|
|
|
33
33
|
// Survives bot restarts so child multi-turn system prompts keep the parent ID.
|
|
34
34
|
parent_session_id: sqliteCore.text('parent_session_id'),
|
|
35
35
|
created_at: datetime('created_at').default(orm.sql`CURRENT_TIMESTAMP`),
|
|
36
|
+
// Bumped on every (re)binding of a session to this thread. /resume can map one
|
|
37
|
+
// session to several threads, so session_id -> thread_id needs a tiebreaker.
|
|
38
|
+
// Without it the reverse lookup is arbitrary and tools can target a dead thread.
|
|
39
|
+
updated_at: datetime('updated_at').default(orm.sql`CURRENT_TIMESTAMP`).$onUpdate(() => new Date()),
|
|
36
40
|
})
|
|
37
41
|
|
|
38
42
|
export const session_events = sqliteCore.sqliteTable('session_events', {
|
|
@@ -224,6 +228,36 @@ export const forum_sync_configs = sqliteCore.sqliteTable('forum_sync_configs', {
|
|
|
224
228
|
sqliteCore.uniqueIndex('forum_sync_configs_app_id_forum_channel_id_key').on(table.app_id, table.forum_channel_id),
|
|
225
229
|
])
|
|
226
230
|
|
|
231
|
+
// Durable "wake this session later" rows for the kimaki_sleep tool.
|
|
232
|
+
//
|
|
233
|
+
// Delivery is at-least-once, and ingress makes it at-most-once-per-turn:
|
|
234
|
+
//
|
|
235
|
+
// planned ──► consumed cancelled / failed are terminal
|
|
236
|
+
// ▲ │
|
|
237
|
+
// └───┘ retried until ingress consumes it
|
|
238
|
+
//
|
|
239
|
+
// A row stays `planned` until ingress turns the wake into a turn, so ANY loss
|
|
240
|
+
// (crash before posting, crash after posting, missed gateway event) is covered
|
|
241
|
+
// by the same retry. `delivery_id` is the Discord message nonce, so a retry
|
|
242
|
+
// returns the existing message instead of waking the session twice.
|
|
243
|
+
//
|
|
244
|
+
// There is no thread_id: the owning thread is resolved from session_id at wake
|
|
245
|
+
// time, so a session rebound by /resume wakes in its current thread.
|
|
246
|
+
export const session_sleeps = sqliteCore.sqliteTable('session_sleeps', {
|
|
247
|
+
session_id: sqliteCore.text('session_id').primaryKey().notNull(),
|
|
248
|
+
wake_at: datetime('wake_at').notNull(),
|
|
249
|
+
reason: sqliteCore.text('reason'),
|
|
250
|
+
status: sqliteCore.text('status', { enum: ['planned', 'consumed', 'cancelled', 'failed'] }).notNull().default('planned'),
|
|
251
|
+
// Regenerated per sleep occurrence. Doubles as the Discord nonce and as a
|
|
252
|
+
// generation guard so a stale in-flight wake cannot mutate a newer sleep.
|
|
253
|
+
delivery_id: sqliteCore.text('delivery_id').notNull().$defaultFn(() => crypto.randomUUID()),
|
|
254
|
+
attempts: sqliteCore.integer('attempts', { mode: 'number' }).notNull().default(0),
|
|
255
|
+
last_attempt_at: datetime('last_attempt_at'),
|
|
256
|
+
created_at: datetime('created_at').default(orm.sql`CURRENT_TIMESTAMP`),
|
|
257
|
+
}, (table) => [
|
|
258
|
+
sqliteCore.index('session_sleeps_status_wake_at_idx').on(table.status, table.wake_at),
|
|
259
|
+
])
|
|
260
|
+
|
|
227
261
|
export const ipc_requests = sqliteCore.sqliteTable('ipc_requests', {
|
|
228
262
|
id: sqliteCore.text('id').primaryKey().notNull().$defaultFn(() => crypto.randomUUID()),
|
|
229
263
|
type: sqliteCore.text('type', { enum: ['file_upload', 'action_buttons'] }).notNull(),
|
|
@@ -259,6 +293,7 @@ export const relations = defineRelations({
|
|
|
259
293
|
scheduled_task_runs,
|
|
260
294
|
session_start_sources,
|
|
261
295
|
forum_sync_configs,
|
|
296
|
+
session_sleeps,
|
|
262
297
|
ipc_requests,
|
|
263
298
|
}, (r) => ({
|
|
264
299
|
thread_sessions: {
|
|
@@ -340,6 +375,7 @@ export const relations = defineRelations({
|
|
|
340
375
|
export type BotMode = typeof bot_tokens.$inferSelect.bot_mode
|
|
341
376
|
export type ChannelType = typeof channel_directories.$inferSelect.channel_type
|
|
342
377
|
export type IpcRequestType = typeof ipc_requests.$inferSelect.type
|
|
378
|
+
export type SessionSleepStatus = typeof session_sleeps.$inferSelect.status
|
|
343
379
|
export type SessionEvent = typeof session_events.$inferSelect
|
|
344
380
|
export type ThreadSessionSource = typeof thread_sessions.$inferSelect.source
|
|
345
381
|
export type VerbosityLevel = typeof channel_verbosity.$inferSelect.verbosity
|
|
@@ -17,11 +17,15 @@ import {
|
|
|
17
17
|
getLatestRunInfo,
|
|
18
18
|
getLatestTurnTokenUsage,
|
|
19
19
|
getIdleTokenUsageDelta,
|
|
20
|
+
getTokenUsageSessionIdsForIdle,
|
|
21
|
+
isDerivedChildSession,
|
|
20
22
|
hasAssistantMessageCompletedBefore,
|
|
21
23
|
doesLatestUserTurnHaveNaturalCompletion,
|
|
22
24
|
isAssistantMessageInLatestUserTurn,
|
|
23
25
|
isAssistantMessageNaturalCompletion,
|
|
24
26
|
isSessionBusy,
|
|
27
|
+
isAssistantTextReadyForQuestion,
|
|
28
|
+
deriveLatestUnansweredQuestion,
|
|
25
29
|
type EventBufferEntry,
|
|
26
30
|
} from './event-stream-state.js'
|
|
27
31
|
|
|
@@ -1124,7 +1128,7 @@ describe('getLatestTurnTokenUsage', () => {
|
|
|
1124
1128
|
})
|
|
1125
1129
|
})
|
|
1126
1130
|
|
|
1127
|
-
test('
|
|
1131
|
+
test('sums assistant tokens when the session has no user message', () => {
|
|
1128
1132
|
const sessionId = 'ses_no_user'
|
|
1129
1133
|
const events = [
|
|
1130
1134
|
assistantEvent({
|
|
@@ -1142,16 +1146,16 @@ describe('getLatestTurnTokenUsage', () => {
|
|
|
1142
1146
|
]
|
|
1143
1147
|
|
|
1144
1148
|
expect(getLatestTurnTokenUsage({ events, sessionId })).toEqual({
|
|
1145
|
-
input:
|
|
1146
|
-
output:
|
|
1149
|
+
input: 100,
|
|
1150
|
+
output: 10,
|
|
1147
1151
|
reasoning: 0,
|
|
1148
1152
|
cacheRead: 0,
|
|
1149
1153
|
cacheWrite: 0,
|
|
1150
|
-
total:
|
|
1154
|
+
total: 110,
|
|
1151
1155
|
cost: 0,
|
|
1152
|
-
model:
|
|
1153
|
-
providerID:
|
|
1154
|
-
assistantMessageCount:
|
|
1156
|
+
model: 'gpt-5.3-codex',
|
|
1157
|
+
providerID: 'openai',
|
|
1158
|
+
assistantMessageCount: 1,
|
|
1155
1159
|
userMessageId: undefined,
|
|
1156
1160
|
})
|
|
1157
1161
|
})
|
|
@@ -1323,4 +1327,430 @@ describe('getIdleTokenUsageDelta', () => {
|
|
|
1323
1327
|
total: 20,
|
|
1324
1328
|
})
|
|
1325
1329
|
})
|
|
1330
|
+
|
|
1331
|
+
test('counts child session assistant tokens without a user message.updated', () => {
|
|
1332
|
+
const childSessionId = 'ses_task_child'
|
|
1333
|
+
const events = [
|
|
1334
|
+
eventEntry({
|
|
1335
|
+
type: 'message.updated',
|
|
1336
|
+
properties: {
|
|
1337
|
+
sessionID: childSessionId,
|
|
1338
|
+
info: {
|
|
1339
|
+
id: 'msg_child_asst_1',
|
|
1340
|
+
sessionID: childSessionId,
|
|
1341
|
+
role: 'assistant',
|
|
1342
|
+
time: { created: 2, completed: 3 },
|
|
1343
|
+
parentID: 'msg_child_user_missing',
|
|
1344
|
+
modelID: 'gpt-5.3-codex',
|
|
1345
|
+
providerID: 'openai',
|
|
1346
|
+
mode: 'general',
|
|
1347
|
+
agent: 'general',
|
|
1348
|
+
path: { cwd: '/test', root: '/test' },
|
|
1349
|
+
cost: 0.02,
|
|
1350
|
+
tokens: {
|
|
1351
|
+
total: 40,
|
|
1352
|
+
input: 30,
|
|
1353
|
+
output: 10,
|
|
1354
|
+
reasoning: 4,
|
|
1355
|
+
cache: { read: 0, write: 0 },
|
|
1356
|
+
},
|
|
1357
|
+
finish: 'stop',
|
|
1358
|
+
},
|
|
1359
|
+
},
|
|
1360
|
+
}),
|
|
1361
|
+
idleEvent(childSessionId),
|
|
1362
|
+
]
|
|
1363
|
+
|
|
1364
|
+
expect(getIdleTokenUsageDelta({
|
|
1365
|
+
events,
|
|
1366
|
+
sessionId: childSessionId,
|
|
1367
|
+
idleEventIndex: events.length - 1,
|
|
1368
|
+
})).toMatchObject({
|
|
1369
|
+
input: 30,
|
|
1370
|
+
output: 10,
|
|
1371
|
+
reasoning: 4,
|
|
1372
|
+
total: 40,
|
|
1373
|
+
cost: 0.02,
|
|
1374
|
+
assistantMessageCount: 1,
|
|
1375
|
+
})
|
|
1376
|
+
})
|
|
1377
|
+
|
|
1378
|
+
test('falls back to session.updated Session.tokens for a child with no message.updated', () => {
|
|
1379
|
+
const childSessionId = 'ses_task_child_session_tokens'
|
|
1380
|
+
const events = [
|
|
1381
|
+
eventEntry({
|
|
1382
|
+
type: 'session.updated',
|
|
1383
|
+
properties: {
|
|
1384
|
+
sessionID: childSessionId,
|
|
1385
|
+
info: {
|
|
1386
|
+
id: childSessionId,
|
|
1387
|
+
slug: 'child',
|
|
1388
|
+
projectID: 'prj_1',
|
|
1389
|
+
directory: '/test',
|
|
1390
|
+
parentID: 'ses_main',
|
|
1391
|
+
title: 'child task',
|
|
1392
|
+
version: '1',
|
|
1393
|
+
cost: 0.05,
|
|
1394
|
+
tokens: {
|
|
1395
|
+
input: 100,
|
|
1396
|
+
output: 20,
|
|
1397
|
+
reasoning: 8,
|
|
1398
|
+
cache: { read: 4, write: 1 },
|
|
1399
|
+
},
|
|
1400
|
+
time: { created: 1, updated: 2 },
|
|
1401
|
+
},
|
|
1402
|
+
},
|
|
1403
|
+
}),
|
|
1404
|
+
idleEvent(childSessionId),
|
|
1405
|
+
]
|
|
1406
|
+
|
|
1407
|
+
expect(getIdleTokenUsageDelta({
|
|
1408
|
+
events,
|
|
1409
|
+
sessionId: childSessionId,
|
|
1410
|
+
idleEventIndex: events.length - 1,
|
|
1411
|
+
})).toMatchObject({
|
|
1412
|
+
input: 100,
|
|
1413
|
+
output: 20,
|
|
1414
|
+
reasoning: 8,
|
|
1415
|
+
cacheRead: 4,
|
|
1416
|
+
cacheWrite: 1,
|
|
1417
|
+
total: 133,
|
|
1418
|
+
cost: 0.05,
|
|
1419
|
+
})
|
|
1420
|
+
})
|
|
1421
|
+
|
|
1422
|
+
test('does not re-emit child tokens at parent idle after the child already idled', () => {
|
|
1423
|
+
const childSessionId = 'ses_task_child_dedupe'
|
|
1424
|
+
const events = [
|
|
1425
|
+
eventEntry({
|
|
1426
|
+
type: 'message.updated',
|
|
1427
|
+
properties: {
|
|
1428
|
+
sessionID: childSessionId,
|
|
1429
|
+
info: {
|
|
1430
|
+
id: 'msg_child_asst_1',
|
|
1431
|
+
sessionID: childSessionId,
|
|
1432
|
+
role: 'assistant',
|
|
1433
|
+
time: { created: 2, completed: 3 },
|
|
1434
|
+
parentID: 'msg_child_user_missing',
|
|
1435
|
+
modelID: 'gpt-5.3-codex',
|
|
1436
|
+
providerID: 'openai',
|
|
1437
|
+
mode: 'general',
|
|
1438
|
+
agent: 'general',
|
|
1439
|
+
path: { cwd: '/test', root: '/test' },
|
|
1440
|
+
cost: 0,
|
|
1441
|
+
tokens: {
|
|
1442
|
+
total: 40,
|
|
1443
|
+
input: 30,
|
|
1444
|
+
output: 10,
|
|
1445
|
+
reasoning: 0,
|
|
1446
|
+
cache: { read: 0, write: 0 },
|
|
1447
|
+
},
|
|
1448
|
+
finish: 'stop',
|
|
1449
|
+
},
|
|
1450
|
+
},
|
|
1451
|
+
}),
|
|
1452
|
+
idleEvent(childSessionId),
|
|
1453
|
+
idleEvent('ses_main'),
|
|
1454
|
+
]
|
|
1455
|
+
|
|
1456
|
+
expect(getIdleTokenUsageDelta({
|
|
1457
|
+
events,
|
|
1458
|
+
sessionId: childSessionId,
|
|
1459
|
+
idleEventIndex: 1,
|
|
1460
|
+
})).toMatchObject({ total: 40 })
|
|
1461
|
+
expect(getIdleTokenUsageDelta({
|
|
1462
|
+
events,
|
|
1463
|
+
sessionId: childSessionId,
|
|
1464
|
+
idleEventIndex: 2,
|
|
1465
|
+
})).toBeUndefined()
|
|
1466
|
+
})
|
|
1467
|
+
})
|
|
1468
|
+
|
|
1469
|
+
describe('task child session token tracking', () => {
|
|
1470
|
+
function idleEvent(sessionId: string): EventBufferEntry {
|
|
1471
|
+
return eventEntry({
|
|
1472
|
+
type: 'session.idle',
|
|
1473
|
+
properties: { sessionID: sessionId },
|
|
1474
|
+
})
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
test('isDerivedChildSession is true from session.created parentID before task metadata', () => {
|
|
1478
|
+
const mainSessionId = 'ses_main'
|
|
1479
|
+
const childSessionId = 'ses_child'
|
|
1480
|
+
const events = [
|
|
1481
|
+
eventEntry({
|
|
1482
|
+
type: 'session.created',
|
|
1483
|
+
properties: {
|
|
1484
|
+
sessionID: childSessionId,
|
|
1485
|
+
info: {
|
|
1486
|
+
id: childSessionId,
|
|
1487
|
+
slug: 'child',
|
|
1488
|
+
projectID: 'prj_1',
|
|
1489
|
+
directory: '/test',
|
|
1490
|
+
parentID: mainSessionId,
|
|
1491
|
+
title: 'explore files',
|
|
1492
|
+
version: '1',
|
|
1493
|
+
time: { created: 1, updated: 1 },
|
|
1494
|
+
},
|
|
1495
|
+
},
|
|
1496
|
+
}),
|
|
1497
|
+
]
|
|
1498
|
+
|
|
1499
|
+
expect(isDerivedChildSession({
|
|
1500
|
+
events,
|
|
1501
|
+
mainSessionId,
|
|
1502
|
+
candidateSessionId: childSessionId,
|
|
1503
|
+
})).toBe(true)
|
|
1504
|
+
expect(isDerivedChildSession({
|
|
1505
|
+
events,
|
|
1506
|
+
mainSessionId,
|
|
1507
|
+
candidateSessionId: 'ses_unrelated',
|
|
1508
|
+
})).toBe(false)
|
|
1509
|
+
})
|
|
1510
|
+
|
|
1511
|
+
test('main idle also returns child session ids so their tokens can be tracked', () => {
|
|
1512
|
+
const mainSessionId = 'ses_main'
|
|
1513
|
+
const childSessionId = 'ses_child'
|
|
1514
|
+
const events = [
|
|
1515
|
+
eventEntry({
|
|
1516
|
+
type: 'session.created',
|
|
1517
|
+
properties: {
|
|
1518
|
+
sessionID: childSessionId,
|
|
1519
|
+
info: {
|
|
1520
|
+
id: childSessionId,
|
|
1521
|
+
slug: 'child',
|
|
1522
|
+
projectID: 'prj_1',
|
|
1523
|
+
directory: '/test',
|
|
1524
|
+
parentID: mainSessionId,
|
|
1525
|
+
title: 'child task',
|
|
1526
|
+
version: '1',
|
|
1527
|
+
time: { created: 1, updated: 1 },
|
|
1528
|
+
},
|
|
1529
|
+
},
|
|
1530
|
+
}),
|
|
1531
|
+
eventEntry({
|
|
1532
|
+
type: 'message.part.updated',
|
|
1533
|
+
properties: {
|
|
1534
|
+
part: {
|
|
1535
|
+
id: 'prt_task',
|
|
1536
|
+
sessionID: mainSessionId,
|
|
1537
|
+
messageID: 'msg_asst',
|
|
1538
|
+
type: 'tool',
|
|
1539
|
+
callID: 'call_task',
|
|
1540
|
+
tool: 'task',
|
|
1541
|
+
state: {
|
|
1542
|
+
status: 'running',
|
|
1543
|
+
input: { subagent_type: 'general' },
|
|
1544
|
+
metadata: { sessionId: childSessionId },
|
|
1545
|
+
},
|
|
1546
|
+
},
|
|
1547
|
+
},
|
|
1548
|
+
}),
|
|
1549
|
+
idleEvent(mainSessionId),
|
|
1550
|
+
]
|
|
1551
|
+
|
|
1552
|
+
expect(getTokenUsageSessionIdsForIdle({
|
|
1553
|
+
events,
|
|
1554
|
+
mainSessionId,
|
|
1555
|
+
idleSessionId: mainSessionId,
|
|
1556
|
+
})).toEqual([mainSessionId, childSessionId])
|
|
1557
|
+
expect(getTokenUsageSessionIdsForIdle({
|
|
1558
|
+
events,
|
|
1559
|
+
mainSessionId,
|
|
1560
|
+
idleSessionId: childSessionId,
|
|
1561
|
+
})).toEqual([childSessionId])
|
|
1562
|
+
})
|
|
1563
|
+
})
|
|
1564
|
+
|
|
1565
|
+
describe('question waits for preceding text-end', () => {
|
|
1566
|
+
const sessionId = 'ses_question_text'
|
|
1567
|
+
const messageId = 'msg_asst_question'
|
|
1568
|
+
const questionId = 'que_1'
|
|
1569
|
+
|
|
1570
|
+
const textStart = eventEntry({
|
|
1571
|
+
type: 'message.part.updated',
|
|
1572
|
+
properties: {
|
|
1573
|
+
sessionID: sessionId,
|
|
1574
|
+
part: {
|
|
1575
|
+
id: 'prt_text',
|
|
1576
|
+
sessionID: sessionId,
|
|
1577
|
+
messageID: messageId,
|
|
1578
|
+
type: 'text',
|
|
1579
|
+
text: '',
|
|
1580
|
+
time: { start: 1 },
|
|
1581
|
+
},
|
|
1582
|
+
},
|
|
1583
|
+
})
|
|
1584
|
+
const questionAsked = eventEntry({
|
|
1585
|
+
type: 'question.asked',
|
|
1586
|
+
properties: {
|
|
1587
|
+
id: questionId,
|
|
1588
|
+
sessionID: sessionId,
|
|
1589
|
+
questions: [{
|
|
1590
|
+
question: 'What next?',
|
|
1591
|
+
header: 'Next step',
|
|
1592
|
+
options: [
|
|
1593
|
+
{ label: 'Commit', description: 'Commit these files' },
|
|
1594
|
+
],
|
|
1595
|
+
}],
|
|
1596
|
+
tool: {
|
|
1597
|
+
messageID: messageId,
|
|
1598
|
+
callID: 'call_question',
|
|
1599
|
+
},
|
|
1600
|
+
},
|
|
1601
|
+
})
|
|
1602
|
+
const textEnd = eventEntry({
|
|
1603
|
+
type: 'message.part.updated',
|
|
1604
|
+
properties: {
|
|
1605
|
+
sessionID: sessionId,
|
|
1606
|
+
part: {
|
|
1607
|
+
id: 'prt_text',
|
|
1608
|
+
sessionID: sessionId,
|
|
1609
|
+
messageID: messageId,
|
|
1610
|
+
type: 'text',
|
|
1611
|
+
text: 'Done callout',
|
|
1612
|
+
time: { start: 1, end: 2 },
|
|
1613
|
+
},
|
|
1614
|
+
},
|
|
1615
|
+
})
|
|
1616
|
+
const questionError = eventEntry({
|
|
1617
|
+
type: 'message.part.updated',
|
|
1618
|
+
properties: {
|
|
1619
|
+
sessionID: sessionId,
|
|
1620
|
+
part: {
|
|
1621
|
+
id: 'prt_question',
|
|
1622
|
+
sessionID: sessionId,
|
|
1623
|
+
messageID: messageId,
|
|
1624
|
+
type: 'tool',
|
|
1625
|
+
tool: 'question',
|
|
1626
|
+
callID: 'call_question',
|
|
1627
|
+
state: {
|
|
1628
|
+
status: 'error',
|
|
1629
|
+
error: 'Aborted',
|
|
1630
|
+
time: { start: 2, end: 3 },
|
|
1631
|
+
},
|
|
1632
|
+
},
|
|
1633
|
+
},
|
|
1634
|
+
})
|
|
1635
|
+
|
|
1636
|
+
test('text is not ready when question.asked arrives before time.end', () => {
|
|
1637
|
+
const events = [textStart, questionAsked]
|
|
1638
|
+
expect(isAssistantTextReadyForQuestion({
|
|
1639
|
+
events,
|
|
1640
|
+
sessionId,
|
|
1641
|
+
messageId,
|
|
1642
|
+
})).toBe(false)
|
|
1643
|
+
expect(deriveLatestUnansweredQuestion({
|
|
1644
|
+
events,
|
|
1645
|
+
sessionId,
|
|
1646
|
+
})).toMatchObject({
|
|
1647
|
+
id: questionId,
|
|
1648
|
+
tool: { messageID: messageId },
|
|
1649
|
+
})
|
|
1650
|
+
})
|
|
1651
|
+
|
|
1652
|
+
test('text is ready after time.end, and still unanswered', () => {
|
|
1653
|
+
const events = [textStart, questionAsked, textEnd]
|
|
1654
|
+
expect(isAssistantTextReadyForQuestion({
|
|
1655
|
+
events,
|
|
1656
|
+
sessionId,
|
|
1657
|
+
messageId,
|
|
1658
|
+
})).toBe(true)
|
|
1659
|
+
expect(deriveLatestUnansweredQuestion({
|
|
1660
|
+
events,
|
|
1661
|
+
sessionId,
|
|
1662
|
+
})?.id).toBe(questionId)
|
|
1663
|
+
})
|
|
1664
|
+
|
|
1665
|
+
test('no text part means the question is ready immediately', () => {
|
|
1666
|
+
const events = [questionAsked]
|
|
1667
|
+
expect(isAssistantTextReadyForQuestion({
|
|
1668
|
+
events,
|
|
1669
|
+
sessionId,
|
|
1670
|
+
messageId,
|
|
1671
|
+
})).toBe(true)
|
|
1672
|
+
})
|
|
1673
|
+
|
|
1674
|
+
test('aborted question is not unanswered', () => {
|
|
1675
|
+
const events = [textStart, questionAsked, textEnd, questionError]
|
|
1676
|
+
expect(deriveLatestUnansweredQuestion({
|
|
1677
|
+
events,
|
|
1678
|
+
sessionId,
|
|
1679
|
+
})).toBeUndefined()
|
|
1680
|
+
})
|
|
1681
|
+
|
|
1682
|
+
test('question from an older user turn is not unanswered', () => {
|
|
1683
|
+
const firstUser = eventEntry({
|
|
1684
|
+
type: 'message.updated',
|
|
1685
|
+
properties: {
|
|
1686
|
+
sessionID: sessionId,
|
|
1687
|
+
info: {
|
|
1688
|
+
id: 'msg_user_first',
|
|
1689
|
+
sessionID: sessionId,
|
|
1690
|
+
role: 'user',
|
|
1691
|
+
time: { created: 1 },
|
|
1692
|
+
agent: 'build',
|
|
1693
|
+
model: {
|
|
1694
|
+
providerID: 'deterministic-provider',
|
|
1695
|
+
modelID: 'deterministic-v2',
|
|
1696
|
+
},
|
|
1697
|
+
},
|
|
1698
|
+
},
|
|
1699
|
+
})
|
|
1700
|
+
const questionAssistant = eventEntry({
|
|
1701
|
+
type: 'message.updated',
|
|
1702
|
+
properties: {
|
|
1703
|
+
sessionID: sessionId,
|
|
1704
|
+
info: {
|
|
1705
|
+
id: messageId,
|
|
1706
|
+
sessionID: sessionId,
|
|
1707
|
+
role: 'assistant',
|
|
1708
|
+
time: { created: 2 },
|
|
1709
|
+
parentID: 'msg_user_first',
|
|
1710
|
+
modelID: 'deterministic-v2',
|
|
1711
|
+
providerID: 'deterministic-provider',
|
|
1712
|
+
mode: 'build',
|
|
1713
|
+
agent: 'build',
|
|
1714
|
+
path: { cwd: '/test', root: '/test' },
|
|
1715
|
+
cost: 0,
|
|
1716
|
+
tokens: {
|
|
1717
|
+
input: 1,
|
|
1718
|
+
output: 1,
|
|
1719
|
+
reasoning: 0,
|
|
1720
|
+
cache: { read: 0, write: 0 },
|
|
1721
|
+
},
|
|
1722
|
+
},
|
|
1723
|
+
},
|
|
1724
|
+
})
|
|
1725
|
+
const nextUser = eventEntry({
|
|
1726
|
+
type: 'message.updated',
|
|
1727
|
+
properties: {
|
|
1728
|
+
sessionID: sessionId,
|
|
1729
|
+
info: {
|
|
1730
|
+
id: 'msg_user_commit',
|
|
1731
|
+
sessionID: sessionId,
|
|
1732
|
+
role: 'user',
|
|
1733
|
+
time: { created: 3 },
|
|
1734
|
+
agent: 'build',
|
|
1735
|
+
model: {
|
|
1736
|
+
providerID: 'deterministic-provider',
|
|
1737
|
+
modelID: 'deterministic-v2',
|
|
1738
|
+
},
|
|
1739
|
+
},
|
|
1740
|
+
},
|
|
1741
|
+
})
|
|
1742
|
+
const events = [
|
|
1743
|
+
firstUser,
|
|
1744
|
+
questionAssistant,
|
|
1745
|
+
textStart,
|
|
1746
|
+
questionAsked,
|
|
1747
|
+
textEnd,
|
|
1748
|
+
nextUser,
|
|
1749
|
+
]
|
|
1750
|
+
|
|
1751
|
+
expect(deriveLatestUnansweredQuestion({
|
|
1752
|
+
events,
|
|
1753
|
+
sessionId,
|
|
1754
|
+
})).toBeUndefined()
|
|
1755
|
+
})
|
|
1326
1756
|
})
|