kimaki 0.4.43 → 0.4.45

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 (47) hide show
  1. package/dist/channel-management.js +6 -15
  2. package/dist/cli.js +210 -32
  3. package/dist/commands/merge-worktree.js +152 -0
  4. package/dist/commands/permissions.js +21 -5
  5. package/dist/commands/queue.js +5 -1
  6. package/dist/commands/resume.js +8 -16
  7. package/dist/commands/session.js +18 -42
  8. package/dist/commands/user-command.js +8 -17
  9. package/dist/commands/verbosity.js +53 -0
  10. package/dist/commands/worktree-settings.js +88 -0
  11. package/dist/commands/worktree.js +146 -50
  12. package/dist/database.js +85 -0
  13. package/dist/discord-bot.js +97 -55
  14. package/dist/discord-utils.js +51 -13
  15. package/dist/discord-utils.test.js +20 -0
  16. package/dist/escape-backticks.test.js +14 -3
  17. package/dist/interaction-handler.js +15 -0
  18. package/dist/session-handler.js +549 -412
  19. package/dist/system-message.js +25 -1
  20. package/dist/worktree-utils.js +50 -0
  21. package/package.json +1 -1
  22. package/src/__snapshots__/first-session-no-info.md +1344 -0
  23. package/src/__snapshots__/first-session-with-info.md +1350 -0
  24. package/src/__snapshots__/session-1.md +1344 -0
  25. package/src/__snapshots__/session-2.md +291 -0
  26. package/src/__snapshots__/session-3.md +20324 -0
  27. package/src/__snapshots__/session-with-tools.md +1344 -0
  28. package/src/channel-management.ts +6 -17
  29. package/src/cli.ts +250 -35
  30. package/src/commands/merge-worktree.ts +186 -0
  31. package/src/commands/permissions.ts +31 -5
  32. package/src/commands/queue.ts +5 -1
  33. package/src/commands/resume.ts +8 -18
  34. package/src/commands/session.ts +18 -44
  35. package/src/commands/user-command.ts +8 -19
  36. package/src/commands/verbosity.ts +71 -0
  37. package/src/commands/worktree-settings.ts +122 -0
  38. package/src/commands/worktree.ts +174 -55
  39. package/src/database.ts +108 -0
  40. package/src/discord-bot.ts +119 -63
  41. package/src/discord-utils.test.ts +23 -0
  42. package/src/discord-utils.ts +52 -13
  43. package/src/escape-backticks.test.ts +14 -3
  44. package/src/interaction-handler.ts +22 -0
  45. package/src/session-handler.ts +681 -436
  46. package/src/system-message.ts +37 -0
  47. package/src/worktree-utils.ts +78 -0
@@ -2,12 +2,23 @@
2
2
  // Creates the system message injected into every OpenCode session,
3
3
  // including Discord-specific formatting rules, diff commands, and permissions info.
4
4
 
5
+ export type WorktreeInfo = {
6
+ /** The worktree directory path */
7
+ worktreeDirectory: string
8
+ /** The branch name (e.g., opencode/kimaki-feature) */
9
+ branch: string
10
+ /** The main repository directory */
11
+ mainRepoDirectory: string
12
+ }
13
+
5
14
  export function getOpencodeSystemMessage({
6
15
  sessionId,
7
16
  channelId,
17
+ worktree,
8
18
  }: {
9
19
  sessionId: string
10
20
  channelId?: string
21
+ worktree?: WorktreeInfo
11
22
  }) {
12
23
  return `
13
24
  The user is reading your messages from inside Discord, via kimaki.xyz
@@ -58,6 +69,28 @@ Use this for handoff when:
58
69
  - User asks to "handoff", "continue in new thread", or "start fresh session"
59
70
  - You detect you're running low on context window space
60
71
  - A complex task would benefit from a clean slate with summarized context
72
+ `
73
+ : ''
74
+ }${
75
+ worktree
76
+ ? `
77
+ ## worktree
78
+
79
+ This session is running inside a git worktree.
80
+ - **Worktree path:** \`${worktree.worktreeDirectory}\`
81
+ - **Branch:** \`${worktree.branch}\`
82
+ - **Main repo:** \`${worktree.mainRepoDirectory}\`
83
+
84
+ Before finishing a task, ask the user if they want to merge changes back to the main branch.
85
+
86
+ To merge (without leaving the worktree):
87
+ \`\`\`bash
88
+ # Get the default branch name
89
+ DEFAULT_BRANCH=$(git -C ${worktree.mainRepoDirectory} symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@' || echo "main")
90
+
91
+ # Merge worktree branch into main
92
+ git -C ${worktree.mainRepoDirectory} checkout $DEFAULT_BRANCH && git -C ${worktree.mainRepoDirectory} merge ${worktree.branch}
93
+ \`\`\`
61
94
  `
62
95
  : ''
63
96
  }
@@ -81,6 +114,10 @@ bunx critique HEAD~1 --web "Update dependencies"
81
114
 
82
115
  Do this in case you committed the changes yourself (only if the user asks so, never commit otherwise).
83
116
 
117
+ To compare two branches:
118
+
119
+ bunx critique main feature-branch --web "Compare branches"
120
+
84
121
  The command outputs a URL - share that URL with the user so they can see the diff.
85
122
 
86
123
  ## markdown
@@ -0,0 +1,78 @@
1
+ // Worktree utility functions.
2
+ // Wrapper for OpenCode worktree creation that also initializes git submodules.
3
+
4
+ import { exec } from 'node:child_process'
5
+ import { promisify } from 'node:util'
6
+ import { createLogger } from './logger.js'
7
+ import type { getOpencodeClientV2 } from './opencode.js'
8
+
9
+ export const execAsync = promisify(exec)
10
+
11
+ const logger = createLogger('WORKTREE-UTILS')
12
+
13
+ type OpencodeClientV2 = NonNullable<ReturnType<typeof getOpencodeClientV2>>
14
+
15
+ type WorktreeResult = {
16
+ directory: string
17
+ branch: string
18
+ }
19
+
20
+ /**
21
+ * Create a worktree using OpenCode SDK and initialize git submodules.
22
+ * This wrapper ensures submodules are properly set up in new worktrees.
23
+ */
24
+ export async function createWorktreeWithSubmodules({
25
+ clientV2,
26
+ directory,
27
+ name,
28
+ }: {
29
+ clientV2: OpencodeClientV2
30
+ directory: string
31
+ name: string
32
+ }): Promise<WorktreeResult | Error> {
33
+ // 1. Create worktree via OpenCode SDK
34
+ const response = await clientV2.worktree.create({
35
+ directory,
36
+ worktreeCreateInput: { name },
37
+ })
38
+
39
+ if (response.error) {
40
+ return new Error(`SDK error: ${JSON.stringify(response.error)}`)
41
+ }
42
+
43
+ if (!response.data) {
44
+ return new Error('No worktree data returned from SDK')
45
+ }
46
+
47
+ const worktreeDir = response.data.directory
48
+
49
+ // 2. Init submodules in new worktree (don't block on failure)
50
+ try {
51
+ logger.log(`Initializing submodules in ${worktreeDir}`)
52
+ await execAsync('git submodule update --init --recursive', {
53
+ cwd: worktreeDir,
54
+ })
55
+ logger.log(`Submodules initialized in ${worktreeDir}`)
56
+ } catch (e) {
57
+ // Log but don't fail - submodules might not exist
58
+ logger.warn(
59
+ `Failed to init submodules in ${worktreeDir}: ${e instanceof Error ? e.message : String(e)}`,
60
+ )
61
+ }
62
+
63
+ // 3. Install dependencies using ni (detects package manager from lockfile)
64
+ try {
65
+ logger.log(`Installing dependencies in ${worktreeDir}`)
66
+ await execAsync('npx -y ni', {
67
+ cwd: worktreeDir,
68
+ })
69
+ logger.log(`Dependencies installed in ${worktreeDir}`)
70
+ } catch (e) {
71
+ // Log but don't fail - might not be a JS project or might fail for various reasons
72
+ logger.warn(
73
+ `Failed to install dependencies in ${worktreeDir}: ${e instanceof Error ? e.message : String(e)}`,
74
+ )
75
+ }
76
+
77
+ return response.data
78
+ }