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
@@ -1,7 +1,7 @@
1
1
  // OpenCode system prompt generator.
2
2
  // Creates the system message injected into every OpenCode session,
3
3
  // including Discord-specific formatting rules, diff commands, and permissions info.
4
- export function getOpencodeSystemMessage({ sessionId, channelId, }) {
4
+ export function getOpencodeSystemMessage({ sessionId, channelId, worktree, }) {
5
5
  return `
6
6
  The user is reading your messages from inside Discord, via kimaki.xyz
7
7
 
@@ -50,6 +50,26 @@ Use this for handoff when:
50
50
  - User asks to "handoff", "continue in new thread", or "start fresh session"
51
51
  - You detect you're running low on context window space
52
52
  - A complex task would benefit from a clean slate with summarized context
53
+ `
54
+ : ''}${worktree
55
+ ? `
56
+ ## worktree
57
+
58
+ This session is running inside a git worktree.
59
+ - **Worktree path:** \`${worktree.worktreeDirectory}\`
60
+ - **Branch:** \`${worktree.branch}\`
61
+ - **Main repo:** \`${worktree.mainRepoDirectory}\`
62
+
63
+ Before finishing a task, ask the user if they want to merge changes back to the main branch.
64
+
65
+ To merge (without leaving the worktree):
66
+ \`\`\`bash
67
+ # Get the default branch name
68
+ DEFAULT_BRANCH=$(git -C ${worktree.mainRepoDirectory} symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@' || echo "main")
69
+
70
+ # Merge worktree branch into main
71
+ git -C ${worktree.mainRepoDirectory} checkout $DEFAULT_BRANCH && git -C ${worktree.mainRepoDirectory} merge ${worktree.branch}
72
+ \`\`\`
53
73
  `
54
74
  : ''}
55
75
  ## showing diffs
@@ -72,6 +92,10 @@ bunx critique HEAD~1 --web "Update dependencies"
72
92
 
73
93
  Do this in case you committed the changes yourself (only if the user asks so, never commit otherwise).
74
94
 
95
+ To compare two branches:
96
+
97
+ bunx critique main feature-branch --web "Compare branches"
98
+
75
99
  The command outputs a URL - share that URL with the user so they can see the diff.
76
100
 
77
101
  ## markdown
@@ -0,0 +1,50 @@
1
+ // Worktree utility functions.
2
+ // Wrapper for OpenCode worktree creation that also initializes git submodules.
3
+ import { exec } from 'node:child_process';
4
+ import { promisify } from 'node:util';
5
+ import { createLogger } from './logger.js';
6
+ export const execAsync = promisify(exec);
7
+ const logger = createLogger('WORKTREE-UTILS');
8
+ /**
9
+ * Create a worktree using OpenCode SDK and initialize git submodules.
10
+ * This wrapper ensures submodules are properly set up in new worktrees.
11
+ */
12
+ export async function createWorktreeWithSubmodules({ clientV2, directory, name, }) {
13
+ // 1. Create worktree via OpenCode SDK
14
+ const response = await clientV2.worktree.create({
15
+ directory,
16
+ worktreeCreateInput: { name },
17
+ });
18
+ if (response.error) {
19
+ return new Error(`SDK error: ${JSON.stringify(response.error)}`);
20
+ }
21
+ if (!response.data) {
22
+ return new Error('No worktree data returned from SDK');
23
+ }
24
+ const worktreeDir = response.data.directory;
25
+ // 2. Init submodules in new worktree (don't block on failure)
26
+ try {
27
+ logger.log(`Initializing submodules in ${worktreeDir}`);
28
+ await execAsync('git submodule update --init --recursive', {
29
+ cwd: worktreeDir,
30
+ });
31
+ logger.log(`Submodules initialized in ${worktreeDir}`);
32
+ }
33
+ catch (e) {
34
+ // Log but don't fail - submodules might not exist
35
+ logger.warn(`Failed to init submodules in ${worktreeDir}: ${e instanceof Error ? e.message : String(e)}`);
36
+ }
37
+ // 3. Install dependencies using ni (detects package manager from lockfile)
38
+ try {
39
+ logger.log(`Installing dependencies in ${worktreeDir}`);
40
+ await execAsync('npx -y ni', {
41
+ cwd: worktreeDir,
42
+ });
43
+ logger.log(`Dependencies installed in ${worktreeDir}`);
44
+ }
45
+ catch (e) {
46
+ // Log but don't fail - might not be a JS project or might fail for various reasons
47
+ logger.warn(`Failed to install dependencies in ${worktreeDir}: ${e instanceof Error ? e.message : String(e)}`);
48
+ }
49
+ return response.data;
50
+ }
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.43",
5
+ "version": "0.4.45",
6
6
  "repository": "https://github.com/remorses/kimaki",
7
7
  "bin": "bin.js",
8
8
  "files": [