kimaki 0.4.35 → 0.4.36

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 (75) hide show
  1. package/dist/ai-tool-to-genai.js +1 -3
  2. package/dist/channel-management.js +1 -1
  3. package/dist/cli.js +135 -39
  4. package/dist/commands/abort.js +1 -1
  5. package/dist/commands/add-project.js +1 -1
  6. package/dist/commands/agent.js +6 -2
  7. package/dist/commands/ask-question.js +2 -1
  8. package/dist/commands/fork.js +7 -7
  9. package/dist/commands/queue.js +2 -2
  10. package/dist/commands/remove-project.js +109 -0
  11. package/dist/commands/resume.js +3 -5
  12. package/dist/commands/session.js +2 -2
  13. package/dist/commands/share.js +1 -1
  14. package/dist/commands/undo-redo.js +2 -2
  15. package/dist/commands/user-command.js +3 -6
  16. package/dist/config.js +1 -1
  17. package/dist/discord-bot.js +4 -10
  18. package/dist/discord-utils.js +33 -9
  19. package/dist/genai.js +4 -6
  20. package/dist/interaction-handler.js +8 -1
  21. package/dist/markdown.js +1 -3
  22. package/dist/message-formatting.js +7 -3
  23. package/dist/openai-realtime.js +3 -5
  24. package/dist/opencode.js +1 -1
  25. package/dist/session-handler.js +25 -15
  26. package/dist/system-message.js +5 -3
  27. package/dist/tools.js +9 -22
  28. package/dist/voice-handler.js +9 -12
  29. package/dist/voice.js +5 -3
  30. package/dist/xml.js +2 -4
  31. package/package.json +3 -2
  32. package/src/__snapshots__/compact-session-context-no-system.md +24 -24
  33. package/src/__snapshots__/compact-session-context.md +31 -31
  34. package/src/ai-tool-to-genai.ts +3 -11
  35. package/src/channel-management.ts +14 -25
  36. package/src/cli.ts +282 -195
  37. package/src/commands/abort.ts +1 -3
  38. package/src/commands/add-project.ts +8 -14
  39. package/src/commands/agent.ts +16 -9
  40. package/src/commands/ask-question.ts +8 -7
  41. package/src/commands/create-new-project.ts +8 -14
  42. package/src/commands/fork.ts +23 -27
  43. package/src/commands/model.ts +14 -11
  44. package/src/commands/permissions.ts +1 -1
  45. package/src/commands/queue.ts +6 -19
  46. package/src/commands/remove-project.ts +136 -0
  47. package/src/commands/resume.ts +11 -30
  48. package/src/commands/session.ts +4 -13
  49. package/src/commands/share.ts +1 -3
  50. package/src/commands/types.ts +1 -3
  51. package/src/commands/undo-redo.ts +6 -18
  52. package/src/commands/user-command.ts +8 -10
  53. package/src/config.ts +5 -5
  54. package/src/database.ts +10 -8
  55. package/src/discord-bot.ts +22 -46
  56. package/src/discord-utils.ts +35 -18
  57. package/src/escape-backticks.test.ts +0 -2
  58. package/src/format-tables.ts +1 -4
  59. package/src/genai-worker-wrapper.ts +3 -9
  60. package/src/genai-worker.ts +4 -19
  61. package/src/genai.ts +10 -42
  62. package/src/interaction-handler.ts +133 -121
  63. package/src/markdown.test.ts +10 -32
  64. package/src/markdown.ts +6 -14
  65. package/src/message-formatting.ts +13 -14
  66. package/src/openai-realtime.ts +25 -47
  67. package/src/opencode.ts +24 -34
  68. package/src/session-handler.ts +91 -61
  69. package/src/system-message.ts +13 -3
  70. package/src/tools.ts +13 -39
  71. package/src/utils.ts +1 -4
  72. package/src/voice-handler.ts +34 -78
  73. package/src/voice.ts +11 -19
  74. package/src/xml.test.ts +1 -1
  75. package/src/xml.ts +3 -12
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "kimaki",
3
3
  "module": "index.ts",
4
4
  "type": "module",
5
- "version": "0.4.35",
5
+ "version": "0.4.36",
6
6
  "scripts": {
7
7
  "dev": "tsx --env-file .env src/cli.ts",
8
8
  "prepublishOnly": "pnpm tsc",
@@ -11,7 +11,8 @@
11
11
  "test:events": "tsx test-events.ts",
12
12
  "pcm-to-mp3": "bun scripts/pcm-to-mp3",
13
13
  "test:send": "tsx send-test-message.ts",
14
- "register-commands": "tsx scripts/register-commands.ts"
14
+ "register-commands": "tsx scripts/register-commands.ts",
15
+ "format": "oxfmt src"
15
16
  },
16
17
  "repository": "https://github.com/remorses/kimaki",
17
18
  "bin": "bin.js",
@@ -1,35 +1,35 @@
1
1
  [Assistant]: Still not showing. The session might not have a `system` field and the first assistant message might not have `synthetic: true`. Let me add debug logging to see what's available:
2
2
 
3
- [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= // Get system prompt if requested
4
- if (includeSystemPrompt) {
5
- // try session.system fie, newString= // Get system prompt if requested
6
- if (includeSystemPrompt) {
7
- // try session.system fie
8
- [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= } else if (messages.length > 0) {
9
- // fallback: look for synthetic text part in first a, newString= } else if (messages.length > 0) {
10
- // fallback: look for synthetic text part in first a
3
+ [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= // Get system prompt if requested
4
+ if (includeSystemPrompt) {
5
+ // try session.system fie, newString= // Get system prompt if requested
6
+ if (includeSystemPrompt) {
7
+ // try session.system fie
8
+ [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= } else if (messages.length > 0) {
9
+ // fallback: look for synthetic text part in first a, newString= } else if (messages.length > 0) {
10
+ // fallback: look for synthetic text part in first a
11
11
  [Tool bash]: command=pnpm vitest run --testNamePattern "getCompactSessionContext generates" 2>&1 | tail -30, description=run test and check output, workdir=/Users/morse/Documents/GitHub/kimakivoice/discord, timeout=120000
12
12
  [Tool bash]: command=grep -i "session keys\|text parts" tmp/kimaki.log | tail -10, description=check debug output, workdir=/Users/morse/Documents/GitHub/kimakivoice/discord
13
13
  [Assistant]: Session doesn't have a `system` field. Let me fix the debug logging:
14
14
 
15
- [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= const textParts = (firstAssistant.parts || []).filter((p) => p.type === 'text')
16
- , newString= const textParts = (firstAssistant.parts || []).filter((p) => p.type === 'text')
17
-
15
+ [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= const textParts = (firstAssistant.parts || []).filter((p) => p.type === 'text')
16
+ , newString= const textParts = (firstAssistant.parts || []).filter((p) => p.type === 'text')
17
+
18
18
  [Tool bash]: command=pnpm vitest run --testNamePattern "getCompactSessionContext generates" 2>&1 && grep -i "text parts" , description=run test and check debug, workdir=/Users/morse/Documents/GitHub/kimakivoice/discord, timeout=120000
19
19
  [Assistant]: I see - the first assistant text part has **no `synthetic` field** (it's `undefined`), and it's only 44 chars. The session doesn't expose the system prompt.
20
20
 
21
21
  Let me remove debug logging and fix the test:
22
22
 
23
- [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= // Get system prompt if requested
24
- if (includeSystemPrompt) {
25
- // try session.system fie, newString= // Get system prompt if requested
26
- // Note: OpenCode SDK doesn't expose system prompt directl
27
- [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= try {
28
- // fetch session info to get system prompt
29
- const sessionResponse = await client.sess, newString= try {
30
- const messagesResponse = await client.session.messages({
31
- [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.test.ts, oldString= expect(context).toBeTruthy()
32
- expect(context.length).toBeGreaterThan(0)
33
- // should have tool cal, newString= expect(context).toBeTruthy()
34
- expect(context.length).toBeGreaterThan(0)
35
- // should have tool cal
23
+ [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= // Get system prompt if requested
24
+ if (includeSystemPrompt) {
25
+ // try session.system fie, newString= // Get system prompt if requested
26
+ // Note: OpenCode SDK doesn't expose system prompt directl
27
+ [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= try {
28
+ // fetch session info to get system prompt
29
+ const sessionResponse = await client.sess, newString= try {
30
+ const messagesResponse = await client.session.messages({
31
+ [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.test.ts, oldString= expect(context).toBeTruthy()
32
+ expect(context.length).toBeGreaterThan(0)
33
+ // should have tool cal, newString= expect(context).toBeTruthy()
34
+ expect(context.length).toBeGreaterThan(0)
35
+ // should have tool cal
@@ -2,46 +2,46 @@
2
2
  [Tool read]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, offset=248, limit=35
3
3
  [Assistant]: Let me update the code to also look for system role messages and fetch session info:
4
4
 
5
- [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= try {
6
- const messagesResponse = await client.session.messages({
7
- path: { id: sessionId },
8
- , newString= try {
9
- // fetch session info to get system prompt
10
- const sessionResponse = await client.sess
5
+ [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= try {
6
+ const messagesResponse = await client.session.messages({
7
+ path: { id: sessionId },
8
+ , newString= try {
9
+ // fetch session info to get system prompt
10
+ const sessionResponse = await client.sess
11
11
  [Tool bash]: command=pnpm vitest run -u --testNamePattern "getCompactSessionContext", description=run tests to check system prompt, workdir=/Users/morse/Documents/GitHub/kimakivoice/discord, timeout=120000
12
- [Tool bash]: command=head -30 discord/src/__snapshots__/compact-session-context.md, description=check if system prompt is in snapshot
12
+ [Tool bash]: command=head -30 discord/src/**snapshots**/compact-session-context.md, description=check if system prompt is in snapshot
13
13
  [Assistant]: Still not showing. The session might not have a `system` field and the first assistant message might not have `synthetic: true`. Let me add debug logging to see what's available:
14
14
 
15
- [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= // Get system prompt if requested
16
- if (includeSystemPrompt) {
17
- // try session.system fie, newString= // Get system prompt if requested
18
- if (includeSystemPrompt) {
19
- // try session.system fie
20
- [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= } else if (messages.length > 0) {
21
- // fallback: look for synthetic text part in first a, newString= } else if (messages.length > 0) {
22
- // fallback: look for synthetic text part in first a
15
+ [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= // Get system prompt if requested
16
+ if (includeSystemPrompt) {
17
+ // try session.system fie, newString= // Get system prompt if requested
18
+ if (includeSystemPrompt) {
19
+ // try session.system fie
20
+ [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= } else if (messages.length > 0) {
21
+ // fallback: look for synthetic text part in first a, newString= } else if (messages.length > 0) {
22
+ // fallback: look for synthetic text part in first a
23
23
  [Tool bash]: command=pnpm vitest run --testNamePattern "getCompactSessionContext generates" 2>&1 | tail -30, description=run test and check output, workdir=/Users/morse/Documents/GitHub/kimakivoice/discord, timeout=120000
24
24
  [Tool bash]: command=grep -i "session keys\|text parts" tmp/kimaki.log | tail -10, description=check debug output, workdir=/Users/morse/Documents/GitHub/kimakivoice/discord
25
25
  [Assistant]: Session doesn't have a `system` field. Let me fix the debug logging:
26
26
 
27
- [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= const textParts = (firstAssistant.parts || []).filter((p) => p.type === 'text')
28
- , newString= const textParts = (firstAssistant.parts || []).filter((p) => p.type === 'text')
29
-
27
+ [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= const textParts = (firstAssistant.parts || []).filter((p) => p.type === 'text')
28
+ , newString= const textParts = (firstAssistant.parts || []).filter((p) => p.type === 'text')
29
+
30
30
  [Tool bash]: command=pnpm vitest run --testNamePattern "getCompactSessionContext generates" 2>&1 && grep -i "text parts" , description=run test and check debug, workdir=/Users/morse/Documents/GitHub/kimakivoice/discord, timeout=120000
31
31
  [Assistant]: I see - the first assistant text part has **no `synthetic` field** (it's `undefined`), and it's only 44 chars. The session doesn't expose the system prompt.
32
32
 
33
33
  Let me remove debug logging and fix the test:
34
34
 
35
- [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= // Get system prompt if requested
36
- if (includeSystemPrompt) {
37
- // try session.system fie, newString= // Get system prompt if requested
38
- // Note: OpenCode SDK doesn't expose system prompt directl
39
- [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= try {
40
- // fetch session info to get system prompt
41
- const sessionResponse = await client.sess, newString= try {
42
- const messagesResponse = await client.session.messages({
43
- [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.test.ts, oldString= expect(context).toBeTruthy()
44
- expect(context.length).toBeGreaterThan(0)
45
- // should have tool cal, newString= expect(context).toBeTruthy()
46
- expect(context.length).toBeGreaterThan(0)
47
- // should have tool cal
35
+ [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= // Get system prompt if requested
36
+ if (includeSystemPrompt) {
37
+ // try session.system fie, newString= // Get system prompt if requested
38
+ // Note: OpenCode SDK doesn't expose system prompt directl
39
+ [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.ts, oldString= try {
40
+ // fetch session info to get system prompt
41
+ const sessionResponse = await client.sess, newString= try {
42
+ const messagesResponse = await client.session.messages({
43
+ [Tool edit]: filePath=/Users/morse/Documents/GitHub/kimakivoice/discord/src/markdown.test.ts, oldString= expect(context).toBeTruthy()
44
+ expect(context.length).toBeGreaterThan(0)
45
+ // should have tool cal, newString= expect(context).toBeTruthy()
46
+ expect(context.length).toBeGreaterThan(0)
47
+ // should have tool cal
@@ -119,9 +119,7 @@ function jsonSchemaToGenAISchema(jsonSchema: any): Schema {
119
119
  /**
120
120
  * Convert AI SDK Tool to GenAI FunctionDeclaration
121
121
  */
122
- export function aiToolToGenAIFunction(
123
- tool: Tool<any, any>,
124
- ): FunctionDeclaration {
122
+ export function aiToolToGenAIFunction(tool: Tool<any, any>): FunctionDeclaration {
125
123
  // Extract the input schema - assume it's a Zod schema
126
124
  const inputSchema = tool.inputSchema as z.ZodType<any>
127
125
 
@@ -183,11 +181,7 @@ export function aiToolToCallableTool(
183
181
 
184
182
  for (const functionCall of functionCalls) {
185
183
  // Check if this function call matches our tool
186
- if (
187
- functionCall.name !== toolName &&
188
- name &&
189
- functionCall.name !== name
190
- ) {
184
+ if (functionCall.name !== toolName && name && functionCall.name !== name) {
191
185
  continue
192
186
  }
193
187
 
@@ -249,7 +243,5 @@ export function extractSchemaFromTool(tool: Tool<any, any>): any {
249
243
  export function callableToolsFromObject(
250
244
  tools: Record<string, Tool<any, any>>,
251
245
  ): Array<CallableTool & { name: string }> {
252
- return Object.entries(tools).map(([name, tool]) =>
253
- aiToolToCallableTool(tool, name),
254
- )
246
+ return Object.entries(tools).map(([name, tool]) => aiToolToCallableTool(tool, name))
255
247
  }
@@ -2,12 +2,7 @@
2
2
  // Creates and manages Kimaki project channels (text + voice pairs),
3
3
  // extracts channel metadata from topic tags, and ensures category structure.
4
4
 
5
- import {
6
- ChannelType,
7
- type CategoryChannel,
8
- type Guild,
9
- type TextChannel,
10
- } from 'discord.js'
5
+ import { ChannelType, type CategoryChannel, type Guild, type TextChannel } from 'discord.js'
11
6
  import path from 'node:path'
12
7
  import { getDatabase } from './database.js'
13
8
  import { extractTagsArrays } from './xml.js'
@@ -18,15 +13,13 @@ export async function ensureKimakiCategory(
18
13
  ): Promise<CategoryChannel> {
19
14
  const categoryName = botName ? `Kimaki ${botName}` : 'Kimaki'
20
15
 
21
- const existingCategory = guild.channels.cache.find(
22
- (channel): channel is CategoryChannel => {
23
- if (channel.type !== ChannelType.GuildCategory) {
24
- return false
25
- }
16
+ const existingCategory = guild.channels.cache.find((channel): channel is CategoryChannel => {
17
+ if (channel.type !== ChannelType.GuildCategory) {
18
+ return false
19
+ }
26
20
 
27
- return channel.name.toLowerCase() === categoryName.toLowerCase()
28
- },
29
- )
21
+ return channel.name.toLowerCase() === categoryName.toLowerCase()
22
+ })
30
23
 
31
24
  if (existingCategory) {
32
25
  return existingCategory
@@ -44,15 +37,13 @@ export async function ensureKimakiAudioCategory(
44
37
  ): Promise<CategoryChannel> {
45
38
  const categoryName = botName ? `Kimaki Audio ${botName}` : 'Kimaki Audio'
46
39
 
47
- const existingCategory = guild.channels.cache.find(
48
- (channel): channel is CategoryChannel => {
49
- if (channel.type !== ChannelType.GuildCategory) {
50
- return false
51
- }
40
+ const existingCategory = guild.channels.cache.find((channel): channel is CategoryChannel => {
41
+ if (channel.type !== ChannelType.GuildCategory) {
42
+ return false
43
+ }
52
44
 
53
- return channel.name.toLowerCase() === categoryName.toLowerCase()
54
- },
55
- )
45
+ return channel.name.toLowerCase() === categoryName.toLowerCase()
46
+ })
56
47
 
57
48
  if (existingCategory) {
58
49
  return existingCategory
@@ -124,9 +115,7 @@ export type ChannelWithTags = {
124
115
  kimakiApp?: string
125
116
  }
126
117
 
127
- export async function getChannelsWithDescriptions(
128
- guild: Guild,
129
- ): Promise<ChannelWithTags[]> {
118
+ export async function getChannelsWithDescriptions(guild: Guild): Promise<ChannelWithTags[]> {
130
119
  const channels: ChannelWithTags[] = []
131
120
 
132
121
  guild.channels.cache