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