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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Session inspection and archival terminal commands.
|
|
2
2
|
import { goke } from 'goke'
|
|
3
3
|
import { z } from 'zod'
|
|
4
|
+
import dedent from 'string-dedent'
|
|
4
5
|
import { note } from '@clack/prompts'
|
|
5
6
|
import YAML from 'yaml'
|
|
6
7
|
import * as errore from 'errore'
|
|
@@ -16,11 +17,14 @@ import { getBotTokenWithMode, getThreadSession, getThreadIdBySessionId, getSessi
|
|
|
16
17
|
import { ShareMarkdown } from '../markdown.js'
|
|
17
18
|
import { parseSessionSearchPattern, findFirstSessionSearchHit, buildSessionSearchSnippet, getPartSearchTexts } from '../session-search.js'
|
|
18
19
|
import { formatWorktreeName, formatAutoWorktreeName } from '../commands/new-worktree.js'
|
|
20
|
+
import { formatTimeAgo } from '../commands/worktrees.js'
|
|
21
|
+
import { editorsForFile, loadFileEditEvents } from '../file-edit-log.js'
|
|
19
22
|
import { WORKTREE_PREFIX } from '../commands/merge-worktree.js'
|
|
20
23
|
import type { ThreadStartMarker } from '../system-message.js'
|
|
21
24
|
import { buildOpencodeEventLogLine } from '../session-handler/opencode-session-event-log.js'
|
|
22
25
|
import { createDiscordRest } from '../discord-urls.js'
|
|
23
26
|
import { archiveThread, uploadFilesToDiscord, stripMentions } from '../discord-utils.js'
|
|
27
|
+
import { OpenCodeSdkError } from '../errors.js'
|
|
24
28
|
import { setDataDir, setProjectsDir, getDataDir, getProjectsDir } from '../config.js'
|
|
25
29
|
import { execAsync, validateWorktreeDirectory } from '../worktrees.js'
|
|
26
30
|
import { upgrade, getCurrentVersion } from '../upgrade.js'
|
|
@@ -90,8 +94,10 @@ cli
|
|
|
90
94
|
'--project <path>',
|
|
91
95
|
'Project directory to list sessions for (defaults to cwd)',
|
|
92
96
|
)
|
|
97
|
+
.option('--active', 'Only list active sessions; exits 1 when none remain')
|
|
98
|
+
.option('--exclude <sessionId>', 'Exclude one session ID from the results')
|
|
93
99
|
.option('--json', 'Output as JSON')
|
|
94
|
-
.action(async (options
|
|
100
|
+
.action(async (options) => {
|
|
95
101
|
try {
|
|
96
102
|
const projectDirectory = path.resolve(options.project || '.')
|
|
97
103
|
|
|
@@ -106,10 +112,28 @@ cli
|
|
|
106
112
|
|
|
107
113
|
const sessionsResponse = await getClient().session.list()
|
|
108
114
|
const sessions = sessionsResponse.data || []
|
|
115
|
+
const statuses = await (async () => {
|
|
116
|
+
if (!options.active) return null
|
|
117
|
+
const response = await getClient().session.status({
|
|
118
|
+
directory: projectDirectory,
|
|
119
|
+
})
|
|
120
|
+
if (response.error) {
|
|
121
|
+
cliLogger.error('Failed to list active sessions')
|
|
122
|
+
process.exit(EXIT_NO_RESTART)
|
|
123
|
+
}
|
|
124
|
+
return response.data || {}
|
|
125
|
+
})()
|
|
126
|
+
const selectedSessions = sessions.filter((session) => {
|
|
127
|
+
if (session.id === options.exclude) return false
|
|
128
|
+
if (!options.active) return true
|
|
129
|
+
const status = statuses?.[session.id]
|
|
130
|
+
return Boolean(status && status.type !== 'idle')
|
|
131
|
+
})
|
|
109
132
|
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
133
|
+
if (selectedSessions.length === 0) {
|
|
134
|
+
if (options.json) console.log('[]')
|
|
135
|
+
else cliLogger.log(options.active ? 'No active sessions found' : 'No sessions found')
|
|
136
|
+
process.exit(options.active ? 1 : 0)
|
|
113
137
|
}
|
|
114
138
|
|
|
115
139
|
// Look up which sessions were started via kimaki (have a thread mapping)
|
|
@@ -123,7 +147,7 @@ cli
|
|
|
123
147
|
.map((row) => [row.session_id, row.thread_id]),
|
|
124
148
|
)
|
|
125
149
|
const sessionStartSources = await getSessionStartSourcesBySessionIds(
|
|
126
|
-
|
|
150
|
+
selectedSessions.map((session) => session.id),
|
|
127
151
|
)
|
|
128
152
|
|
|
129
153
|
const scheduleModeLabel = ({
|
|
@@ -138,7 +162,7 @@ cli
|
|
|
138
162
|
}
|
|
139
163
|
|
|
140
164
|
if (options.json) {
|
|
141
|
-
const output =
|
|
165
|
+
const output = selectedSessions.map((session) => {
|
|
142
166
|
const startSource = sessionStartSources.get(session.id)
|
|
143
167
|
const startedBy = startSource
|
|
144
168
|
? `scheduled-${scheduleModeLabel({ scheduleKind: startSource.schedule_kind })}`
|
|
@@ -152,13 +176,14 @@ cli
|
|
|
152
176
|
threadId: sessionToThread.get(session.id) || null,
|
|
153
177
|
startedBy,
|
|
154
178
|
scheduledTaskId: startSource?.scheduled_task_id || null,
|
|
179
|
+
status: options.active ? statuses?.[session.id]?.type || 'busy' : undefined,
|
|
155
180
|
}
|
|
156
181
|
})
|
|
157
182
|
console.log(JSON.stringify(output, null, 2))
|
|
158
183
|
process.exit(0)
|
|
159
184
|
}
|
|
160
185
|
|
|
161
|
-
for (const session of
|
|
186
|
+
for (const session of selectedSessions) {
|
|
162
187
|
const threadId = sessionToThread.get(session.id)
|
|
163
188
|
const startSource = sessionStartSources.get(session.id)
|
|
164
189
|
const source = threadId ? '(kimaki)' : '(opencode)'
|
|
@@ -167,8 +192,11 @@ cli
|
|
|
167
192
|
: ''
|
|
168
193
|
const updatedAt = new Date(session.time.updated).toISOString()
|
|
169
194
|
const threadInfo = threadId ? ` | thread: ${threadId}` : ''
|
|
195
|
+
const statusInfo = options.active
|
|
196
|
+
? ` | status: ${statuses?.[session.id]?.type || 'busy'}`
|
|
197
|
+
: ''
|
|
170
198
|
console.log(
|
|
171
|
-
`${session.id} | ${session.title || 'Untitled Session'} | ${session.directory} | ${updatedAt} | ${source}${threadInfo}${startedBy}`,
|
|
199
|
+
`${session.id} | ${session.title || 'Untitled Session'} | ${session.directory} | ${updatedAt} | ${source}${threadInfo}${startedBy}${statusInfo}`,
|
|
172
200
|
)
|
|
173
201
|
}
|
|
174
202
|
|
|
@@ -182,6 +210,89 @@ cli
|
|
|
182
210
|
}
|
|
183
211
|
})
|
|
184
212
|
|
|
213
|
+
cli
|
|
214
|
+
.command(
|
|
215
|
+
'session editors <file>',
|
|
216
|
+
dedent`
|
|
217
|
+
List sessions that last edited a file, newest first.
|
|
218
|
+
|
|
219
|
+
Use this before a commit in another session so the \`Session:\` line
|
|
220
|
+
uses the session that actually edited the file.
|
|
221
|
+
`,
|
|
222
|
+
)
|
|
223
|
+
.option('--json', 'Output as JSON')
|
|
224
|
+
.option(
|
|
225
|
+
'--limit <n>',
|
|
226
|
+
z.number().default(20).describe('Max sessions to show'),
|
|
227
|
+
)
|
|
228
|
+
.example('kimaki session editors src/cli.ts')
|
|
229
|
+
.example('kimaki session editors src/cli.ts --json')
|
|
230
|
+
.action(async (file, options, { console, process }) => {
|
|
231
|
+
try {
|
|
232
|
+
const cwd = process.cwd
|
|
233
|
+
const loaded = loadFileEditEvents({ dataDir: getDataDir() })
|
|
234
|
+
if (loaded instanceof Error) {
|
|
235
|
+
console.error(loaded.message)
|
|
236
|
+
process.exit(EXIT_NO_RESTART)
|
|
237
|
+
return
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const editors = editorsForFile({
|
|
241
|
+
events: loaded,
|
|
242
|
+
filePath: file,
|
|
243
|
+
cwd,
|
|
244
|
+
}).slice(0, options.limit)
|
|
245
|
+
if (editors.length === 0) {
|
|
246
|
+
console.error(`No recorded editors for ${path.resolve(cwd, file)}`)
|
|
247
|
+
process.exit(1)
|
|
248
|
+
return
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const titles = new Map<string, string>()
|
|
252
|
+
try {
|
|
253
|
+
await initDatabase()
|
|
254
|
+
const db = await getDb()
|
|
255
|
+
const sessionRows = await db.query.thread_sessions.findMany({
|
|
256
|
+
columns: { session_id: true, last_synced_name: true },
|
|
257
|
+
where: { session_id: { in: editors.map((editor) => editor.sessionId) } },
|
|
258
|
+
orderBy: { updated_at: 'desc' },
|
|
259
|
+
})
|
|
260
|
+
for (const row of sessionRows) {
|
|
261
|
+
if (!titles.has(row.session_id) && row.last_synced_name) {
|
|
262
|
+
titles.set(row.session_id, row.last_synced_name)
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
} catch (error) {
|
|
266
|
+
console.error(error instanceof Error ? error.message : String(error))
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const rows = editors.map((editor) => {
|
|
270
|
+
const title = titles.get(editor.sessionId) || '-'
|
|
271
|
+
const editedAt = new Date(editor.at)
|
|
272
|
+
return {
|
|
273
|
+
sessionId: editor.sessionId,
|
|
274
|
+
title,
|
|
275
|
+
editedAt: editedAt.toISOString(),
|
|
276
|
+
ago: formatTimeAgo(editedAt),
|
|
277
|
+
}
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
if (options.json) {
|
|
281
|
+
console.log(JSON.stringify(rows, null, 2))
|
|
282
|
+
process.exit(0)
|
|
283
|
+
return
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
for (const row of rows) {
|
|
287
|
+
console.log(`${row.sessionId} | ${row.title} | ${row.ago}`)
|
|
288
|
+
}
|
|
289
|
+
process.exit(0)
|
|
290
|
+
} catch (error) {
|
|
291
|
+
console.error(error instanceof Error ? error.stack : String(error))
|
|
292
|
+
process.exit(EXIT_NO_RESTART)
|
|
293
|
+
}
|
|
294
|
+
})
|
|
295
|
+
|
|
185
296
|
cli
|
|
186
297
|
.command(
|
|
187
298
|
'session read <sessionId>',
|
|
@@ -600,7 +711,7 @@ cli
|
|
|
600
711
|
cli
|
|
601
712
|
.command(
|
|
602
713
|
'session archive [threadId]',
|
|
603
|
-
'Archive a Discord thread
|
|
714
|
+
'Archive a Discord thread without stopping its mapped OpenCode session',
|
|
604
715
|
)
|
|
605
716
|
.option('--session <sessionId>', 'Resolve thread from an OpenCode session ID')
|
|
606
717
|
.action(async (threadIdArg: string | undefined, options: { session?: string }) => {
|
|
@@ -753,6 +864,89 @@ cli
|
|
|
753
864
|
}
|
|
754
865
|
})
|
|
755
866
|
|
|
867
|
+
cli
|
|
868
|
+
.command(
|
|
869
|
+
'session title <title>',
|
|
870
|
+
'Update the OpenCode session title. Discord thread name follows automatically.',
|
|
871
|
+
)
|
|
872
|
+
.option('--session <sessionId>', 'OpenCode session ID')
|
|
873
|
+
.option('--thread <threadId>', 'Discord thread ID')
|
|
874
|
+
.example("kimaki session title 'Fix queue draining' --session ses_xxx")
|
|
875
|
+
.action(async (title, options) => {
|
|
876
|
+
try {
|
|
877
|
+
await initDatabase()
|
|
878
|
+
|
|
879
|
+
const trimmedTitle = title.trim()
|
|
880
|
+
if (!trimmedTitle) {
|
|
881
|
+
cliLogger.error('Title must not be empty')
|
|
882
|
+
process.exit(EXIT_NO_RESTART)
|
|
883
|
+
}
|
|
884
|
+
if (options.session && options.thread) {
|
|
885
|
+
cliLogger.error('Use either --session or --thread, not both')
|
|
886
|
+
process.exit(EXIT_NO_RESTART)
|
|
887
|
+
}
|
|
888
|
+
if (!options.session && !options.thread) {
|
|
889
|
+
cliLogger.error('Provide --session <sessionId> or --thread <threadId>')
|
|
890
|
+
process.exit(EXIT_NO_RESTART)
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
const sessionId = await (async () => {
|
|
894
|
+
if (options.session) return options.session
|
|
895
|
+
const threadId = options.thread
|
|
896
|
+
if (!threadId) return null
|
|
897
|
+
return getThreadSession(threadId)
|
|
898
|
+
})()
|
|
899
|
+
if (!sessionId) {
|
|
900
|
+
cliLogger.error(
|
|
901
|
+
options.thread
|
|
902
|
+
? `No OpenCode session found for thread: ${options.thread}`
|
|
903
|
+
: 'Provide --session <sessionId> or --thread <threadId>',
|
|
904
|
+
)
|
|
905
|
+
process.exit(EXIT_NO_RESTART)
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
const directory = await resolveSessionDirectoryFromDatabase({
|
|
909
|
+
sessionId,
|
|
910
|
+
})
|
|
911
|
+
if (directory instanceof Error) {
|
|
912
|
+
cliLogger.error(directory.message)
|
|
913
|
+
process.exit(EXIT_NO_RESTART)
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
const serverResult = await initializeOpencodeForDirectory(directory)
|
|
917
|
+
if (serverResult instanceof Error) {
|
|
918
|
+
cliLogger.error(`Failed to initialize OpenCode: ${serverResult.message}`)
|
|
919
|
+
process.exit(EXIT_NO_RESTART)
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
const updateResult = await serverResult()
|
|
923
|
+
.session.update({
|
|
924
|
+
sessionID: sessionId,
|
|
925
|
+
title: trimmedTitle,
|
|
926
|
+
})
|
|
927
|
+
.catch((e) =>
|
|
928
|
+
new OpenCodeSdkError({ operation: 'session.update', cause: e }),
|
|
929
|
+
)
|
|
930
|
+
if (updateResult instanceof Error) {
|
|
931
|
+
cliLogger.error(updateResult.message)
|
|
932
|
+
process.exit(EXIT_NO_RESTART)
|
|
933
|
+
}
|
|
934
|
+
if (updateResult.error) {
|
|
935
|
+
cliLogger.error('OpenCode rejected the session title update')
|
|
936
|
+
process.exit(EXIT_NO_RESTART)
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
note(`Updated OpenCode title: ${trimmedTitle}`, 'Title updated')
|
|
940
|
+
process.exit(0)
|
|
941
|
+
} catch (error) {
|
|
942
|
+
cliLogger.error(
|
|
943
|
+
'Error:',
|
|
944
|
+
error instanceof Error ? error.stack : String(error),
|
|
945
|
+
)
|
|
946
|
+
process.exit(EXIT_NO_RESTART)
|
|
947
|
+
}
|
|
948
|
+
})
|
|
949
|
+
|
|
756
950
|
cli
|
|
757
951
|
.command(
|
|
758
952
|
'session discord-url <sessionId>',
|
package/src/cli-commands/task.ts
CHANGED
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
resolveDiscordUserOption,
|
|
40
40
|
sendDiscordMessageWithOptionalAttachment,
|
|
41
41
|
} from '../cli-runner.js'
|
|
42
|
+
import { validateCliModelOption } from '../session-handler/model-utils.js'
|
|
42
43
|
|
|
43
44
|
const cliLogger = createLogger(LogPrefix.CLI)
|
|
44
45
|
const cli = goke()
|
|
@@ -263,6 +264,17 @@ cli
|
|
|
263
264
|
}
|
|
264
265
|
|
|
265
266
|
const newPrompt = trimmedPrompt ?? existingPayload.prompt
|
|
267
|
+
const nextModel = hasModel ? options.model!.trim() || null : existingPayload.model
|
|
268
|
+
if (nextModel) {
|
|
269
|
+
const modelCheck = await validateCliModelOption({
|
|
270
|
+
model: nextModel,
|
|
271
|
+
directory: task.project_directory ?? undefined,
|
|
272
|
+
})
|
|
273
|
+
if (modelCheck instanceof Error) {
|
|
274
|
+
cliLogger.error(modelCheck.message)
|
|
275
|
+
process.exit(EXIT_NO_RESTART)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
266
278
|
// Match send --model/--agent: empty string clears the override (null).
|
|
267
279
|
const updatedPayload: ScheduledTaskPayload = {
|
|
268
280
|
...existingPayload,
|
|
@@ -271,7 +283,7 @@ cli
|
|
|
271
283
|
? { userId: resolvedUser.id, username: resolvedUser.username || null }
|
|
272
284
|
: {}),
|
|
273
285
|
...(hasAgent ? { agent: options.agent!.trim() || null } : {}),
|
|
274
|
-
|
|
286
|
+
...(hasModel ? { model: nextModel } : {}),
|
|
275
287
|
...(hasPreRun ? { preRunCommand: options.preRun!.trim() || null } : {}),
|
|
276
288
|
...(hasAllowConcurrency
|
|
277
289
|
? { allowConcurrency: options.allowConcurrency === 'true' }
|
package/src/cli-parsing.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Regression tests for CLI argument parsing around Discord ID string preservation.
|
|
2
2
|
import { describe, expect, test } from 'vitest'
|
|
3
3
|
import { execAsync } from './exec-async.js'
|
|
4
|
+
import maintenanceCommands from './cli-commands/maintenance.js'
|
|
4
5
|
|
|
5
6
|
async function parseWithGoke(argv: string[]) {
|
|
6
7
|
const script = [
|
|
@@ -8,6 +9,7 @@ async function parseWithGoke(argv: string[]) {
|
|
|
8
9
|
'const cli = goke(\'kimaki\')',
|
|
9
10
|
"cli.command('send', 'Send a message').option('-c, --channel <channelId>', 'Discord channel ID').option('--thread <threadId>', 'Thread ID').option('--session <sessionId>', 'Session ID').option('--send-at <schedule>', 'Schedule')",
|
|
10
11
|
"cli.command('session archive <threadId>', 'Archive a thread')",
|
|
12
|
+
"cli.command('session title <title>', 'Update title').option('--session <sessionId>', 'Session ID').option('--thread <threadId>', 'Thread ID')",
|
|
11
13
|
"cli.command('session search <query>', 'Search sessions').option('--channel <channelId>', 'Discord channel ID').option('--project <path>', 'Project path')",
|
|
12
14
|
"cli.command('session export-events-jsonl', 'Export in-memory events to JSONL').option('--session <sessionId>', 'Session ID').option('--out <file>', 'Output path')",
|
|
13
15
|
"cli.command('add-project', 'Add a project').option('-g, --guild <guildId>', 'Discord guild/server ID')",
|
|
@@ -55,7 +57,7 @@ async function parseRootBotOptions(argv: string[]) {
|
|
|
55
57
|
const script = [
|
|
56
58
|
"import { goke } from 'goke'",
|
|
57
59
|
'const cli = goke(\'kimaki\')',
|
|
58
|
-
"cli.command('', 'bot').option('--no-analytics', 'Disable analytics')",
|
|
60
|
+
"cli.command('', 'bot').option('--no-analytics', 'Disable analytics').option('--skip-footer-mentions', 'Do not mention the thread creator in final footers')",
|
|
59
61
|
`const result = await cli.parse(${JSON.stringify(argv)}, { run: false })`,
|
|
60
62
|
'process.stdout.write(JSON.stringify({ args: result.args, options: result.options }))',
|
|
61
63
|
].join(';')
|
|
@@ -106,6 +108,28 @@ describe('goke CLI ID parsing', () => {
|
|
|
106
108
|
expect(typeof result.options.guild).toBe('string')
|
|
107
109
|
})
|
|
108
110
|
|
|
111
|
+
test('keeps session title and session ID as strings', async () => {
|
|
112
|
+
const sessionId = '001111222233334444'
|
|
113
|
+
const title = 'Fix queue draining'
|
|
114
|
+
|
|
115
|
+
const result = await parseWithGoke(
|
|
116
|
+
[
|
|
117
|
+
'node',
|
|
118
|
+
'kimaki',
|
|
119
|
+
'session',
|
|
120
|
+
'title',
|
|
121
|
+
title,
|
|
122
|
+
'--session',
|
|
123
|
+
sessionId,
|
|
124
|
+
],
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
expect(result.args[0]).toBe(title)
|
|
128
|
+
expect(typeof result.args[0]).toBe('string')
|
|
129
|
+
expect(result.options.session).toBe(sessionId)
|
|
130
|
+
expect(typeof result.options.session).toBe('string')
|
|
131
|
+
})
|
|
132
|
+
|
|
109
133
|
test('keeps session archive thread ID as string', async () => {
|
|
110
134
|
const threadId = '0098765432109876543'
|
|
111
135
|
|
|
@@ -194,13 +218,55 @@ describe('goke CLI ID parsing', () => {
|
|
|
194
218
|
expect(stdout).toContain('multioauth')
|
|
195
219
|
})
|
|
196
220
|
|
|
197
|
-
test('
|
|
221
|
+
test('merge-worktree parses strategy and target branch', async () => {
|
|
222
|
+
const result = await maintenanceCommands.parse(
|
|
223
|
+
[
|
|
224
|
+
'node',
|
|
225
|
+
'kimaki',
|
|
226
|
+
'merge-worktree',
|
|
227
|
+
'--strategy',
|
|
228
|
+
'squash',
|
|
229
|
+
'--target-branch',
|
|
230
|
+
'release',
|
|
231
|
+
'--thread',
|
|
232
|
+
'123456789012345678',
|
|
233
|
+
'--thread-name',
|
|
234
|
+
'feature work',
|
|
235
|
+
],
|
|
236
|
+
{ run: false },
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
expect({
|
|
240
|
+
command: maintenanceCommands.matchedCommandName,
|
|
241
|
+
strategy: result.options.strategy,
|
|
242
|
+
targetBranch: result.options.targetBranch,
|
|
243
|
+
thread: result.options.thread,
|
|
244
|
+
threadName: result.options.threadName,
|
|
245
|
+
}).toMatchInlineSnapshot(`
|
|
246
|
+
{
|
|
247
|
+
"command": "merge-worktree",
|
|
248
|
+
"strategy": "squash",
|
|
249
|
+
"targetBranch": "release",
|
|
250
|
+
"thread": "123456789012345678",
|
|
251
|
+
"threadName": "feature work",
|
|
252
|
+
}
|
|
253
|
+
`)
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
test('parses root bot boolean flags', async () => {
|
|
198
257
|
const result = await parseRootBotOptions([
|
|
199
258
|
'node',
|
|
200
259
|
'kimaki',
|
|
201
260
|
'--no-analytics',
|
|
261
|
+
'--skip-footer-mentions',
|
|
202
262
|
])
|
|
203
263
|
|
|
204
|
-
expect(result.options
|
|
264
|
+
expect(result.options).toMatchInlineSnapshot(`
|
|
265
|
+
{
|
|
266
|
+
"--": [],
|
|
267
|
+
"noAnalytics": true,
|
|
268
|
+
"skipFooterMentions": true,
|
|
269
|
+
}
|
|
270
|
+
`)
|
|
205
271
|
})
|
|
206
272
|
})
|
package/src/cli-runner.test.ts
CHANGED
|
@@ -77,4 +77,53 @@ describe('isTransientNetworkError', () => {
|
|
|
77
77
|
})
|
|
78
78
|
expect(isTransientNetworkError(error)).toBe(true)
|
|
79
79
|
})
|
|
80
|
+
|
|
81
|
+
test('treats undici connect timeouts as transient', () => {
|
|
82
|
+
const error = Object.assign(
|
|
83
|
+
new Error(
|
|
84
|
+
'Connect Timeout Error (attempted address: discord-gateway.kimaki.dev:443, timeout: 10000ms)',
|
|
85
|
+
),
|
|
86
|
+
{
|
|
87
|
+
name: 'ConnectTimeoutError',
|
|
88
|
+
code: 'UND_ERR_CONNECT_TIMEOUT',
|
|
89
|
+
},
|
|
90
|
+
)
|
|
91
|
+
expect(isTransientNetworkError(error)).toBe(true)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('matches undici connect timeouts by message when code is missing', () => {
|
|
95
|
+
expect(
|
|
96
|
+
isTransientNetworkError(
|
|
97
|
+
new Error(
|
|
98
|
+
'Connect Timeout Error (attempted address: discord-gateway.kimaki.dev:443, timeout: 10000ms)',
|
|
99
|
+
),
|
|
100
|
+
),
|
|
101
|
+
).toBe(true)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('walks cause chains for nested undici connect timeouts', () => {
|
|
105
|
+
const cause = Object.assign(
|
|
106
|
+
new Error(
|
|
107
|
+
'Connect Timeout Error (attempted address: discord-gateway.kimaki.dev:443, timeout: 10000ms)',
|
|
108
|
+
),
|
|
109
|
+
{
|
|
110
|
+
name: 'ConnectTimeoutError',
|
|
111
|
+
code: 'UND_ERR_CONNECT_TIMEOUT',
|
|
112
|
+
},
|
|
113
|
+
)
|
|
114
|
+
expect(
|
|
115
|
+
isTransientNetworkError(new Error('Failed to connect to Discord', { cause })),
|
|
116
|
+
).toBe(true)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
test('treats other undici timeout and socket codes as transient', () => {
|
|
120
|
+
for (const [name, code] of [
|
|
121
|
+
['HeadersTimeoutError', 'UND_ERR_HEADERS_TIMEOUT'],
|
|
122
|
+
['BodyTimeoutError', 'UND_ERR_BODY_TIMEOUT'],
|
|
123
|
+
['SocketError', 'UND_ERR_SOCKET'],
|
|
124
|
+
] as const) {
|
|
125
|
+
const error = Object.assign(new Error(name), { name, code })
|
|
126
|
+
expect(isTransientNetworkError(error)).toBe(true)
|
|
127
|
+
}
|
|
128
|
+
})
|
|
80
129
|
})
|
package/src/cli-runner.ts
CHANGED
|
@@ -456,6 +456,10 @@ export function formatTaskScheduleLine(schedule: ParsedSendAt): string {
|
|
|
456
456
|
}
|
|
457
457
|
|
|
458
458
|
export const EXIT_NO_RESTART = 64
|
|
459
|
+
// Temporary failure (sysexits EX_TEMPFAIL). Wrapper retries forever with
|
|
460
|
+
// backoff and does not count this toward the crash-loop detector. Used when
|
|
461
|
+
// Discord login fails because the network is down.
|
|
462
|
+
export const EXIT_TEMPFAIL = 75
|
|
459
463
|
|
|
460
464
|
export type GuildMemberSearchResult = {
|
|
461
465
|
user: { id: string; username: string; global_name?: string }
|
|
@@ -542,6 +546,20 @@ const TRANSIENT_ERROR_CODES = new Set([
|
|
|
542
546
|
'DEPTH_ZERO_SELF_SIGNED_CERT',
|
|
543
547
|
'SELF_SIGNED_CERT_IN_CHAIN',
|
|
544
548
|
'ERR_TLS_CERT_ALTNAME_INVALID',
|
|
549
|
+
// undici fetch/WebSocket connect failures when the network is down.
|
|
550
|
+
// Without these, Discord login exits EXIT_NO_RESTART and the wrapper never
|
|
551
|
+
// comes back after a connect timeout to discord-gateway.kimaki.dev.
|
|
552
|
+
'UND_ERR_CONNECT_TIMEOUT',
|
|
553
|
+
'UND_ERR_HEADERS_TIMEOUT',
|
|
554
|
+
'UND_ERR_BODY_TIMEOUT',
|
|
555
|
+
'UND_ERR_SOCKET',
|
|
556
|
+
])
|
|
557
|
+
|
|
558
|
+
const TRANSIENT_ERROR_NAMES = new Set([
|
|
559
|
+
'ConnectTimeoutError',
|
|
560
|
+
'HeadersTimeoutError',
|
|
561
|
+
'BodyTimeoutError',
|
|
562
|
+
'SocketError',
|
|
545
563
|
])
|
|
546
564
|
|
|
547
565
|
const TRANSIENT_ERROR_MESSAGE_PATTERNS = [
|
|
@@ -549,12 +567,16 @@ const TRANSIENT_ERROR_MESSAGE_PATTERNS = [
|
|
|
549
567
|
/certificate has expired/i,
|
|
550
568
|
/self[- ]signed certificate/i,
|
|
551
569
|
/unable to get local issuer certificate/i,
|
|
570
|
+
/connect timeout error/i,
|
|
571
|
+
/headers timeout error/i,
|
|
572
|
+
/body timeout error/i,
|
|
552
573
|
]
|
|
553
574
|
|
|
554
575
|
export function isTransientNetworkError(error: unknown): boolean {
|
|
555
576
|
if (!(error instanceof Error)) return false
|
|
556
577
|
const code = (error as NodeJS.ErrnoException).code
|
|
557
578
|
if (code && TRANSIENT_ERROR_CODES.has(code)) return true
|
|
579
|
+
if (TRANSIENT_ERROR_NAMES.has(error.name)) return true
|
|
558
580
|
// Fallback when code is stripped by wrappers (discord.js sometimes rethrows by message only).
|
|
559
581
|
if (
|
|
560
582
|
TRANSIENT_ERROR_MESSAGE_PATTERNS.some((pattern) =>
|
|
@@ -1757,12 +1779,14 @@ export async function run({
|
|
|
1757
1779
|
cliLogger.error(
|
|
1758
1780
|
'Error: ' + (error instanceof Error ? error.stack : String(error)),
|
|
1759
1781
|
)
|
|
1760
|
-
// Transient network errors (DNS down, gateway unreachable
|
|
1761
|
-
// the bin.ts wrapper to restart us after a delay.
|
|
1762
|
-
//
|
|
1782
|
+
// Transient network errors (DNS down, gateway unreachable, connect
|
|
1783
|
+
// timeout) should allow the bin.ts wrapper to restart us after a delay.
|
|
1784
|
+
// EXIT_TEMPFAIL skips the crash-loop detector so a long outage cannot
|
|
1785
|
+
// permanently stop the bot. Only truly fatal errors (bad token, invalid
|
|
1786
|
+
// intent, etc.) should use EXIT_NO_RESTART.
|
|
1763
1787
|
if (isTransientNetworkError(error)) {
|
|
1764
1788
|
cliLogger.error('Transient network error, exiting for wrapper restart...')
|
|
1765
|
-
process.exit(
|
|
1789
|
+
process.exit(EXIT_TEMPFAIL)
|
|
1766
1790
|
}
|
|
1767
1791
|
process.exit(EXIT_NO_RESTART)
|
|
1768
1792
|
}
|
|
@@ -412,7 +412,7 @@ describe('kimaki send --channel thread creation', () => {
|
|
|
412
412
|
--- from: assistant (TestBot)
|
|
413
413
|
*using deterministic-provider/deterministic-v2*
|
|
414
414
|
⬥ caught-by-model
|
|
415
|
-
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2*
|
|
415
|
+
*project ⋅ main ⋅ Ns ⋅ N% ⋅ deterministic-v2* <@200000000000000830>
|
|
416
416
|
--- from: user (cli-send-tester)
|
|
417
417
|
--- from: assistant (TestBot)
|
|
418
418
|
I can see you sent a message, but Discord did not include its text.
|