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
|
@@ -52,27 +52,101 @@ describe('formatPart', () => {
|
|
|
52
52
|
})
|
|
53
53
|
|
|
54
54
|
describe('formatTaskToolTitle', () => {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
function taskPart({
|
|
56
|
+
status,
|
|
57
|
+
input = {},
|
|
58
|
+
title = '',
|
|
59
|
+
sessionId,
|
|
60
|
+
}: {
|
|
61
|
+
status: 'running' | 'completed'
|
|
62
|
+
input?: { description?: string; subagent_type?: string }
|
|
63
|
+
title?: string
|
|
64
|
+
sessionId?: string
|
|
65
|
+
}): Extract<Part, { type: 'tool' }> {
|
|
66
|
+
const base = {
|
|
57
67
|
id: 'prt_task',
|
|
58
|
-
type: 'tool',
|
|
68
|
+
type: 'tool' as const,
|
|
59
69
|
tool: 'task',
|
|
60
70
|
callID: 'call_task',
|
|
61
71
|
sessionID: 'ses_parent',
|
|
62
72
|
messageID: 'msg_assistant',
|
|
73
|
+
}
|
|
74
|
+
if (status === 'completed') {
|
|
75
|
+
return {
|
|
76
|
+
...base,
|
|
77
|
+
state: {
|
|
78
|
+
status,
|
|
79
|
+
input,
|
|
80
|
+
output: '',
|
|
81
|
+
title,
|
|
82
|
+
metadata: sessionId ? { sessionId } : {},
|
|
83
|
+
time: { start: 1, end: 2 },
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
...base,
|
|
63
89
|
state: {
|
|
64
|
-
status
|
|
65
|
-
input
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
time: { start: 1, end: 2 },
|
|
90
|
+
status,
|
|
91
|
+
input,
|
|
92
|
+
title,
|
|
93
|
+
metadata: sessionId ? { sessionId } : {},
|
|
94
|
+
time: { start: 1 },
|
|
70
95
|
},
|
|
71
96
|
}
|
|
97
|
+
}
|
|
72
98
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
99
|
+
test('uses the running task title when OpenAI omits the description', () => {
|
|
100
|
+
expect(
|
|
101
|
+
formatTaskToolTitle(
|
|
102
|
+
taskPart({
|
|
103
|
+
status: 'running',
|
|
104
|
+
input: { subagent_type: 'general' },
|
|
105
|
+
title: 'Classify pending changes',
|
|
106
|
+
sessionId: 'ses_child',
|
|
107
|
+
}),
|
|
108
|
+
),
|
|
109
|
+
).toMatchInlineSnapshot(`"┣ general **Classify pending changes**"`)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
test('prefers input description on running parts', () => {
|
|
113
|
+
expect(
|
|
114
|
+
formatTaskToolTitle(
|
|
115
|
+
taskPart({
|
|
116
|
+
status: 'running',
|
|
117
|
+
input: { description: 'inspect repo', subagent_type: 'explore' },
|
|
118
|
+
title: 'ignored title',
|
|
119
|
+
sessionId: 'ses_child',
|
|
120
|
+
}),
|
|
121
|
+
),
|
|
122
|
+
).toMatchInlineSnapshot(`"┣ explore **inspect repo**"`)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
test('does not format completed parts so Discord does not post the line at the end', () => {
|
|
126
|
+
expect(
|
|
127
|
+
formatTaskToolTitle(
|
|
128
|
+
taskPart({
|
|
129
|
+
status: 'completed',
|
|
130
|
+
input: { subagent_type: 'general' },
|
|
131
|
+
title: 'Classify pending changes',
|
|
132
|
+
sessionId: 'ses_child',
|
|
133
|
+
}),
|
|
134
|
+
),
|
|
135
|
+
).toBe('')
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
test('shows queued task calls before the child session exists', () => {
|
|
139
|
+
expect(
|
|
140
|
+
formatTaskToolTitle(
|
|
141
|
+
taskPart({
|
|
142
|
+
status: 'running',
|
|
143
|
+
input: {
|
|
144
|
+
description: 'audit customer pages',
|
|
145
|
+
subagent_type: 'general',
|
|
146
|
+
},
|
|
147
|
+
}),
|
|
148
|
+
),
|
|
149
|
+
).toMatchInlineSnapshot(`"┣ general **audit customer pages**"`)
|
|
76
150
|
})
|
|
77
151
|
})
|
|
78
152
|
|
|
@@ -566,6 +566,22 @@ export function getToolSummaryText(part: Part): string {
|
|
|
566
566
|
return prompt ? `*${escapeInlineMarkdown(prompt.slice(0, 60))}*` : ''
|
|
567
567
|
}
|
|
568
568
|
|
|
569
|
+
// LESSON: tool parts are sent to Discord at `running` status (see
|
|
570
|
+
// shouldSendPart in thread-session-runtime), so `state.title` from the tool
|
|
571
|
+
// result is never rendered here. Everything shown must come from state.input.
|
|
572
|
+
// `until` is already absolute; `duration` is relative, so say "for 2h" —
|
|
573
|
+
// never "until 2h".
|
|
574
|
+
if (part.tool.endsWith('kimaki_sleep')) {
|
|
575
|
+
const until = (part.state.input?.until as string) || ''
|
|
576
|
+
const duration = (part.state.input?.duration as string) || ''
|
|
577
|
+
const reason = (part.state.input?.reason as string) || ''
|
|
578
|
+
const when = until ? `until ${until}` : duration ? `for ${duration}` : ''
|
|
579
|
+
const reasonText = reason ? `_${escapeInlineMarkdown(reason)}_` : ''
|
|
580
|
+
return [when && escapeInlineMarkdown(when), reasonText]
|
|
581
|
+
.filter(Boolean)
|
|
582
|
+
.join(' ')
|
|
583
|
+
}
|
|
584
|
+
|
|
569
585
|
if (!part.state.input) return ''
|
|
570
586
|
|
|
571
587
|
const inputFields = Object.entries(part.state.input)
|
|
@@ -608,15 +624,11 @@ export function formatTodoList(part: Part): string {
|
|
|
608
624
|
}
|
|
609
625
|
|
|
610
626
|
export function formatTaskToolTitle(part: Extract<Part, { type: 'tool' }>): string {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
const childSessionId = part.state.metadata?.sessionId
|
|
614
|
-
if (typeof childSessionId !== 'string' || !childSessionId) return ''
|
|
627
|
+
// Running only. The child session can be created later when many tasks queue.
|
|
628
|
+
if (part.tool !== 'task' || part.state.status !== 'running') return ''
|
|
615
629
|
|
|
616
630
|
const description = part.state.input?.description
|
|
617
|
-
const stateTitle = part.state.
|
|
618
|
-
? part.state.title
|
|
619
|
-
: undefined
|
|
631
|
+
const stateTitle = part.state.title
|
|
620
632
|
const title = typeof description === 'string' && description
|
|
621
633
|
? description
|
|
622
634
|
: typeof stateTitle === 'string'
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LEGACY. Superseded by @subrouter/opencode, registered alongside the kimaki
|
|
3
|
+
* plugin in opencode.ts. This whole rotation path only cycles accounts inside
|
|
4
|
+
* one provider; subrouter also fails over to a different provider when every
|
|
5
|
+
* account of one is exhausted.
|
|
6
|
+
*
|
|
7
|
+
* Kept because opencode ships no Claude Pro/Max auth of its own, so deleting
|
|
8
|
+
* it would strand anyone still picking `anthropic/*` directly. To move to
|
|
9
|
+
* subrouter, log in again through /login and pick Subrouter.
|
|
10
|
+
*/
|
|
1
11
|
/**
|
|
2
12
|
* Shared utilities for multi-provider OAuth account rotation.
|
|
3
13
|
* Used by both anthropic-auth-state.ts and openai-auth-state.ts to avoid
|
package/src/openai-auth-state.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Regression tests for Windows OpenCode command resolution and spawn args.
|
|
2
2
|
|
|
3
3
|
import fs from 'node:fs'
|
|
4
|
+
import { createRequire } from 'node:module'
|
|
4
5
|
import os from 'node:os'
|
|
5
6
|
import path from 'node:path'
|
|
6
7
|
import { afterEach, beforeEach, describe, expect, test } from 'vitest'
|
|
@@ -45,6 +46,86 @@ describe('selectResolvedCommand', () => {
|
|
|
45
46
|
})
|
|
46
47
|
})
|
|
47
48
|
|
|
49
|
+
describe('buildOpencodeServeArgs', () => {
|
|
50
|
+
test('always passes --hostname so opencode.json cannot bind 0.0.0.0', async () => {
|
|
51
|
+
const { buildOpencodeServeArgs } = await import('./opencode.js')
|
|
52
|
+
expect(buildOpencodeServeArgs({ port: 4096 })).toEqual([
|
|
53
|
+
'serve',
|
|
54
|
+
'--port',
|
|
55
|
+
'4096',
|
|
56
|
+
'--hostname',
|
|
57
|
+
'127.0.0.1',
|
|
58
|
+
'--print-logs',
|
|
59
|
+
'--log-level',
|
|
60
|
+
'WARN',
|
|
61
|
+
])
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('passes --hostname when set', async () => {
|
|
65
|
+
const { buildOpencodeServeArgs } = await import('./opencode.js')
|
|
66
|
+
expect(
|
|
67
|
+
buildOpencodeServeArgs({ port: 4096, hostname: '0.0.0.0' }),
|
|
68
|
+
).toEqual([
|
|
69
|
+
'serve',
|
|
70
|
+
'--port',
|
|
71
|
+
'4096',
|
|
72
|
+
'--hostname',
|
|
73
|
+
'0.0.0.0',
|
|
74
|
+
'--print-logs',
|
|
75
|
+
'--log-level',
|
|
76
|
+
'WARN',
|
|
77
|
+
])
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
describe('published runtime artifacts', () => {
|
|
82
|
+
test('lists @subrouter/opencode as a runtime dependency', () => {
|
|
83
|
+
const pkg = JSON.parse(
|
|
84
|
+
fs.readFileSync(path.join(import.meta.dirname, '../package.json'), 'utf8'),
|
|
85
|
+
) as { dependencies?: Record<string, string> }
|
|
86
|
+
expect(pkg.dependencies?.['@subrouter/opencode']).toMatch(/^(workspace:\^|\^)/)
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
describe('resolveSubrouterPluginSpec', () => {
|
|
91
|
+
test('uses npm package identity in production for OpenCode deduplication', async () => {
|
|
92
|
+
const { resolveSubrouterPluginSpec } = await import('./opencode.js')
|
|
93
|
+
const require = createRequire(import.meta.url)
|
|
94
|
+
const packageJsonPath = require.resolve('@subrouter/opencode/package.json')
|
|
95
|
+
const version = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')).version
|
|
96
|
+
expect(resolveSubrouterPluginSpec({ isDev: false })).toBe(
|
|
97
|
+
`@subrouter/opencode@${version}`,
|
|
98
|
+
)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('loads workspace source directly in development', async () => {
|
|
102
|
+
const { resolveSubrouterPluginSpec } = await import('./opencode.js')
|
|
103
|
+
expect(resolveSubrouterPluginSpec({ isDev: true })).toMatch(
|
|
104
|
+
/^file:.*\/subrouter\/opencode\/dist\/index\.js$/,
|
|
105
|
+
)
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
describe('publicOpencodeBindRequiresPassword', () => {
|
|
110
|
+
test('allows loopback without a password', async () => {
|
|
111
|
+
const { publicOpencodeBindRequiresPassword } = await import('./opencode.js')
|
|
112
|
+
expect(publicOpencodeBindRequiresPassword({ hostname: null })).toBe(false)
|
|
113
|
+
expect(publicOpencodeBindRequiresPassword({ hostname: '127.0.0.1' })).toBe(
|
|
114
|
+
false,
|
|
115
|
+
)
|
|
116
|
+
expect(publicOpencodeBindRequiresPassword({ hostname: 'localhost' })).toBe(
|
|
117
|
+
false,
|
|
118
|
+
)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test('requires a password for 0.0.0.0', async () => {
|
|
122
|
+
const { publicOpencodeBindRequiresPassword } = await import('./opencode.js')
|
|
123
|
+
expect(publicOpencodeBindRequiresPassword({ hostname: '0.0.0.0' })).toBe(
|
|
124
|
+
true,
|
|
125
|
+
)
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
|
|
48
129
|
describe('getSpawnCommandAndArgs', () => {
|
|
49
130
|
test('wraps windows cmd shims through cmd.exe without double-quoting by node', () => {
|
|
50
131
|
expect(
|
package/src/opencode.ts
CHANGED
|
@@ -41,7 +41,8 @@ import net from 'node:net'
|
|
|
41
41
|
import os from 'node:os'
|
|
42
42
|
import path from 'node:path'
|
|
43
43
|
import readline from 'node:readline'
|
|
44
|
-
import {
|
|
44
|
+
import { createRequire } from 'node:module'
|
|
45
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
45
46
|
|
|
46
47
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
47
48
|
import {
|
|
@@ -59,10 +60,25 @@ import {
|
|
|
59
60
|
getDataDir,
|
|
60
61
|
getLockPort,
|
|
61
62
|
getRestrictExternalDirectories,
|
|
63
|
+
getOpencodeHostname,
|
|
64
|
+
getOpencodePort,
|
|
62
65
|
} from './config.js'
|
|
63
66
|
import { store } from './store.js'
|
|
64
67
|
import { getHranaUrl } from './hrana-server.js'
|
|
65
68
|
|
|
69
|
+
export function resolveSubrouterPluginSpec({ isDev }: { isDev: boolean }) {
|
|
70
|
+
const require = createRequire(import.meta.url)
|
|
71
|
+
const entry = require.resolve('@subrouter/opencode')
|
|
72
|
+
if (isDev) return pathToFileURL(entry).href
|
|
73
|
+
|
|
74
|
+
const packageJsonPath = require.resolve('@subrouter/opencode/package.json')
|
|
75
|
+
const version = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')).version
|
|
76
|
+
if (typeof version !== 'string' || !version) {
|
|
77
|
+
throw new Error(`Missing @subrouter/opencode version in ${packageJsonPath}`)
|
|
78
|
+
}
|
|
79
|
+
return `@subrouter/opencode@${version}`
|
|
80
|
+
}
|
|
81
|
+
|
|
66
82
|
// SDK Config type is simplified; opencode accepts nested permission objects with path patterns
|
|
67
83
|
type PermissionAction = 'ask' | 'allow' | 'deny'
|
|
68
84
|
type PermissionRule = PermissionAction | Record<string, PermissionAction>
|
|
@@ -108,6 +124,39 @@ export function getOpencodeServerAuthHeaders(): Record<string, string> {
|
|
|
108
124
|
return { Authorization: `Basic ${encoded}` }
|
|
109
125
|
}
|
|
110
126
|
|
|
127
|
+
const LOOPBACK_HOSTNAMES = new Set(['127.0.0.1', 'localhost', '::1'])
|
|
128
|
+
|
|
129
|
+
export function publicOpencodeBindRequiresPassword({
|
|
130
|
+
hostname,
|
|
131
|
+
}: {
|
|
132
|
+
hostname: string | null | undefined
|
|
133
|
+
}): boolean {
|
|
134
|
+
if (!hostname) return false
|
|
135
|
+
return !LOOPBACK_HOSTNAMES.has(hostname)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Always pass --hostname so opencode.json server.hostname / mdns cannot bind 0.0.0.0.
|
|
139
|
+
const DEFAULT_OPENCODE_HOSTNAME = '127.0.0.1'
|
|
140
|
+
|
|
141
|
+
export function buildOpencodeServeArgs({
|
|
142
|
+
port,
|
|
143
|
+
hostname,
|
|
144
|
+
}: {
|
|
145
|
+
port: number
|
|
146
|
+
hostname?: string | null
|
|
147
|
+
}): string[] {
|
|
148
|
+
return [
|
|
149
|
+
'serve',
|
|
150
|
+
'--port',
|
|
151
|
+
port.toString(),
|
|
152
|
+
'--hostname',
|
|
153
|
+
hostname || DEFAULT_OPENCODE_HOSTNAME,
|
|
154
|
+
'--print-logs',
|
|
155
|
+
'--log-level',
|
|
156
|
+
'WARN',
|
|
157
|
+
]
|
|
158
|
+
}
|
|
159
|
+
|
|
111
160
|
// Tracks directories that have been initialized, to avoid repeated log spam
|
|
112
161
|
// from the external sync polling loop.
|
|
113
162
|
const initializedDirectories = new Set<string>()
|
|
@@ -143,6 +192,7 @@ export async function requestHealthcheck({
|
|
|
143
192
|
method: 'GET',
|
|
144
193
|
headers: {
|
|
145
194
|
connection: 'close',
|
|
195
|
+
...getOpencodeServerAuthHeaders(),
|
|
146
196
|
},
|
|
147
197
|
},
|
|
148
198
|
(res) => {
|
|
@@ -682,16 +732,21 @@ async function startSingleServer({
|
|
|
682
732
|
} = {}): Promise<ServerStartError | SingleServer> {
|
|
683
733
|
ensureProcessCleanupHandlersRegistered()
|
|
684
734
|
|
|
685
|
-
const
|
|
735
|
+
const configuredPort = getOpencodePort()
|
|
736
|
+
const port = configuredPort ?? (await getOpenPort())
|
|
737
|
+
const hostname = getOpencodeHostname() ?? DEFAULT_OPENCODE_HOSTNAME
|
|
686
738
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
739
|
+
if (
|
|
740
|
+
publicOpencodeBindRequiresPassword({ hostname }) &&
|
|
741
|
+
!process.env.OPENCODE_SERVER_PASSWORD
|
|
742
|
+
) {
|
|
743
|
+
return new ServerStartError({
|
|
744
|
+
port,
|
|
745
|
+
reason: `OPENCODE_SERVER_PASSWORD is required when --opencode-hostname is ${hostname}`,
|
|
746
|
+
})
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
const serveArgs = buildOpencodeServeArgs({ port, hostname })
|
|
695
750
|
|
|
696
751
|
const {
|
|
697
752
|
command: spawnCommand,
|
|
@@ -772,6 +827,9 @@ async function startSingleServer({
|
|
|
772
827
|
isDev ? './kimaki-opencode-plugin.ts' : './kimaki-opencode-plugin.js',
|
|
773
828
|
import.meta.url,
|
|
774
829
|
).href,
|
|
830
|
+
// npm identity lets opencode dedupe a user-installed copy by package
|
|
831
|
+
// name. Development still loads this workspace's built package directly.
|
|
832
|
+
resolveSubrouterPluginSpec({ isDev }),
|
|
775
833
|
],
|
|
776
834
|
permission: {
|
|
777
835
|
edit: 'allow',
|
|
@@ -862,6 +920,8 @@ async function startSingleServer({
|
|
|
862
920
|
OPENCODE_CONFIG: opencodeConfigPath,
|
|
863
921
|
OPENCODE_PORT: port.toString(),
|
|
864
922
|
KIMAKI: '1',
|
|
923
|
+
// The browser is not on this machine, so no localhost callback fires.
|
|
924
|
+
SUBROUTER_MANUAL_OAUTH: '1',
|
|
865
925
|
OPENCODE_EXPERIMENTAL_WORKSPACES: 'true',
|
|
866
926
|
OPENCODE_ENABLE_EXA: '1',
|
|
867
927
|
KIMAKI_DATA_DIR: getDataDir(),
|
|
@@ -889,7 +949,7 @@ async function startSingleServer({
|
|
|
889
949
|
let serverReady = false
|
|
890
950
|
|
|
891
951
|
logBuffer.push(
|
|
892
|
-
`Spawned opencode
|
|
952
|
+
`Spawned opencode ${serveArgs.join(' ')} (pid: ${serverProcess.pid})`,
|
|
893
953
|
)
|
|
894
954
|
|
|
895
955
|
const stdoutReader = subscribeToProcessLogStream({
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// E2e test: aborting a run must kill the pending question dropdown.
|
|
2
|
+
// Questions have no TTL, so abort is the only thing that clears them while the
|
|
3
|
+
// thread stays alive. Without this, a stale dropdown keeps accepting clicks and
|
|
4
|
+
// answers a question whose run is already dead.
|
|
5
|
+
|
|
6
|
+
import { describe, test, expect } from 'vitest'
|
|
7
|
+
import {
|
|
8
|
+
setupQueueAdvancedSuite,
|
|
9
|
+
TEST_USER_ID,
|
|
10
|
+
} from './queue-advanced-e2e-setup.js'
|
|
11
|
+
import { waitForBotMessageContaining } from './test-utils.js'
|
|
12
|
+
import { pendingQuestionContexts } from './commands/ask-question.js'
|
|
13
|
+
import { getRuntime } from './session-handler/thread-session-runtime.js'
|
|
14
|
+
|
|
15
|
+
const TEXT_CHANNEL_ID = '200000000000001031'
|
|
16
|
+
|
|
17
|
+
describe('abort clears pending question dropdown', () => {
|
|
18
|
+
const ctx = setupQueueAdvancedSuite({
|
|
19
|
+
channelId: TEXT_CHANNEL_ID,
|
|
20
|
+
channelName: 'qa-question-abort',
|
|
21
|
+
dirName: 'qa-question-abort',
|
|
22
|
+
username: 'question-abort-tester',
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test(
|
|
26
|
+
'dropdown stops accepting answers after abort',
|
|
27
|
+
async () => {
|
|
28
|
+
const marker = 'QUESTION_SELECT_QUEUE_MARKER abort-test'
|
|
29
|
+
|
|
30
|
+
await ctx.discord.channel(TEXT_CHANNEL_ID).user(TEST_USER_ID).sendMessage({
|
|
31
|
+
content: marker,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const thread = await ctx.discord.channel(TEXT_CHANNEL_ID).waitForThread({
|
|
35
|
+
timeout: 8_000,
|
|
36
|
+
predicate: (t) => {
|
|
37
|
+
return t.name === marker
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const th = ctx.discord.thread(thread.id)
|
|
42
|
+
|
|
43
|
+
const questionMessages = await waitForBotMessageContaining({
|
|
44
|
+
discord: ctx.discord,
|
|
45
|
+
threadId: thread.id,
|
|
46
|
+
text: 'How to proceed?',
|
|
47
|
+
timeout: 12_000,
|
|
48
|
+
})
|
|
49
|
+
const questionMsg = questionMessages.find((message) => {
|
|
50
|
+
return message.content.includes('How to proceed?')
|
|
51
|
+
})
|
|
52
|
+
if (!questionMsg) {
|
|
53
|
+
throw new Error('Expected question message')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const pendingEntry = [...pendingQuestionContexts.entries()].find(([, context]) => {
|
|
57
|
+
return context.thread.id === thread.id
|
|
58
|
+
})
|
|
59
|
+
if (!pendingEntry) {
|
|
60
|
+
throw new Error('Expected pending question context')
|
|
61
|
+
}
|
|
62
|
+
const contextHash = pendingEntry[0]
|
|
63
|
+
|
|
64
|
+
const runtime = getRuntime(thread.id)
|
|
65
|
+
if (!runtime) {
|
|
66
|
+
throw new Error('Expected runtime for question abort test')
|
|
67
|
+
}
|
|
68
|
+
runtime.abortActiveRun('test-question-abort')
|
|
69
|
+
|
|
70
|
+
// Click the now-dead dropdown. The answer echo must never appear.
|
|
71
|
+
const interaction = await th.user(TEST_USER_ID).selectMenu({
|
|
72
|
+
messageId: questionMsg.id,
|
|
73
|
+
customId: `ask_question:${contextHash}:0`,
|
|
74
|
+
values: ['0'],
|
|
75
|
+
})
|
|
76
|
+
await th.waitForInteractionAck({
|
|
77
|
+
interactionId: interaction.id,
|
|
78
|
+
timeout: 8_000,
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
for (let i = 0; i < 10; i++) {
|
|
82
|
+
const messages = await th.getMessages()
|
|
83
|
+
const answered = messages.find((message) => {
|
|
84
|
+
return message.content.includes('» **question-abort-tester:** Alpha')
|
|
85
|
+
})
|
|
86
|
+
if (answered) {
|
|
87
|
+
throw new Error('Dropdown was still answerable after abort')
|
|
88
|
+
}
|
|
89
|
+
await new Promise<void>((resolve) => {
|
|
90
|
+
setTimeout(resolve, 20)
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const timeline = await th.text({ showInteractions: true })
|
|
95
|
+
expect(timeline).toMatchInlineSnapshot(`
|
|
96
|
+
"--- from: user (question-abort-tester)
|
|
97
|
+
QUESTION_SELECT_QUEUE_MARKER abort-test
|
|
98
|
+
--- from: assistant (TestBot)
|
|
99
|
+
*using deterministic-provider/deterministic-v2*
|
|
100
|
+
**Select action**
|
|
101
|
+
How to proceed?
|
|
102
|
+
[user selects dropdown: 0]
|
|
103
|
+
This question has expired. Please ask the AI again."
|
|
104
|
+
`)
|
|
105
|
+
expect(pendingQuestionContexts.size).toBe(0)
|
|
106
|
+
},
|
|
107
|
+
20_000,
|
|
108
|
+
)
|
|
109
|
+
})
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// E2e: text that precedes a question tool must post before the dropdown.
|
|
2
|
+
// OpenCode can emit question.asked before the text part's time.end; Kimaki
|
|
3
|
+
// must wait so the plan is not hidden under the question UI.
|
|
4
|
+
|
|
5
|
+
import { describe, test, expect } from 'vitest'
|
|
6
|
+
import {
|
|
7
|
+
setupQueueAdvancedSuite,
|
|
8
|
+
TEST_USER_ID,
|
|
9
|
+
} from './queue-advanced-e2e-setup.js'
|
|
10
|
+
import { waitForBotMessageContaining } from './test-utils.js'
|
|
11
|
+
|
|
12
|
+
const TEXT_CHANNEL_ID = '200000000000001042'
|
|
13
|
+
|
|
14
|
+
describe('question text before dropdown', () => {
|
|
15
|
+
const ctx = setupQueueAdvancedSuite({
|
|
16
|
+
channelId: TEXT_CHANNEL_ID,
|
|
17
|
+
channelName: 'qa-question-text-order',
|
|
18
|
+
dirName: 'qa-question-text-order',
|
|
19
|
+
username: 'question-text-tester',
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test(
|
|
23
|
+
'posts plan text before the question dropdown',
|
|
24
|
+
async () => {
|
|
25
|
+
const marker = 'QUESTION_AFTER_TEXT_MARKER'
|
|
26
|
+
await ctx.discord.channel(TEXT_CHANNEL_ID).user(TEST_USER_ID).sendMessage({
|
|
27
|
+
content: marker,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const thread = await ctx.discord.channel(TEXT_CHANNEL_ID).waitForThread({
|
|
31
|
+
timeout: 8_000,
|
|
32
|
+
predicate: (t) => {
|
|
33
|
+
return t.name === marker
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
const th = ctx.discord.thread(thread.id)
|
|
37
|
+
|
|
38
|
+
await waitForBotMessageContaining({
|
|
39
|
+
discord: ctx.discord,
|
|
40
|
+
threadId: thread.id,
|
|
41
|
+
text: 'What next?',
|
|
42
|
+
timeout: 8_000,
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
expect(await th.text()).toMatchInlineSnapshot(`
|
|
46
|
+
"--- from: user (question-text-tester)
|
|
47
|
+
QUESTION_AFTER_TEXT_MARKER
|
|
48
|
+
--- from: assistant (TestBot)
|
|
49
|
+
*using deterministic-provider/deterministic-v2*
|
|
50
|
+
⬥ PLAN_TEXT_BEFORE_QUESTION
|
|
51
|
+
**Next step**
|
|
52
|
+
What next?"
|
|
53
|
+
`)
|
|
54
|
+
|
|
55
|
+
const messages = await th.getMessages()
|
|
56
|
+
const planIndex = messages.findIndex((message) => {
|
|
57
|
+
return message.content.includes('PLAN_TEXT_BEFORE_QUESTION')
|
|
58
|
+
})
|
|
59
|
+
const questionIndex = messages.findIndex((message) => {
|
|
60
|
+
return message.content.includes('What next?')
|
|
61
|
+
})
|
|
62
|
+
expect(planIndex).toBeGreaterThanOrEqual(0)
|
|
63
|
+
expect(questionIndex).toBeGreaterThan(planIndex)
|
|
64
|
+
},
|
|
65
|
+
15_000,
|
|
66
|
+
)
|
|
67
|
+
})
|
|
@@ -204,7 +204,7 @@ e2eTest('queue advanced: abort and retry', () => {
|
|
|
204
204
|
--- from: assistant (TestBot)
|
|
205
205
|
*using deterministic-provider/deterministic-v2*
|
|
206
206
|
⬥ ok
|
|
207
|
-
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
|
|
207
|
+
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2* <@200000000000000991>
|
|
208
208
|
--- from: user (queue-advanced-tester)
|
|
209
209
|
SLOW_ABORT_MARKER run long response"
|
|
210
210
|
`)
|
|
@@ -167,13 +167,13 @@ describe('queue advanced: action buttons', () => {
|
|
|
167
167
|
--- from: assistant (TestBot)
|
|
168
168
|
*using deterministic-provider/deterministic-v2*
|
|
169
169
|
⬥ ok
|
|
170
|
-
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
|
|
170
|
+
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2* <@200000000000000991>
|
|
171
171
|
**Action Required**
|
|
172
172
|
_Selected: Continue action-buttons flow_
|
|
173
173
|
[user clicks button]
|
|
174
174
|
» **queue-action-tester:** Continue action-buttons flow
|
|
175
175
|
⬥ action-buttons-click-continued
|
|
176
|
-
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*"
|
|
176
|
+
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2* <@200000000000000991>"
|
|
177
177
|
`)
|
|
178
178
|
expect(timeline).toContain('action-buttons-click-continued')
|
|
179
179
|
},
|
|
@@ -257,7 +257,7 @@ describe('queue advanced: action buttons', () => {
|
|
|
257
257
|
--- from: assistant (TestBot)
|
|
258
258
|
*using deterministic-provider/deterministic-v2*
|
|
259
259
|
⬥ ok
|
|
260
|
-
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
|
|
260
|
+
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2* <@200000000000000991>
|
|
261
261
|
**Action Required**
|
|
262
262
|
_Buttons dismissed._
|
|
263
263
|
--- from: user (queue-action-tester)
|