mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-26 05:27:06 +00:00
* feat(kimi): thinking level selection for remote sessions Kimi Code's ACP session advertises the active model's thinking levels as a thought_level config option (`thinking`: off/on or off plus declared efforts). Expose it like Grok's effort: a session RPC + hub route for the options, the composer effort picker, and per-turn session/set_config_option in the remote launcher. The runner forwards --effort so resumed sessions keep the selection. * fix(kimi): keep thinking options in step with model switches Kimi Code answers session/set_model with no config options and pushes the new model's thought_level via config_option_update; capture it (opt-in in the ACP backend, same hunk as #2348), re-baseline the launcher's level after a switch, report 'switch pending' until the next turn applies it, and have the web poll until discovery succeeds. * fix(kimi): gate thinking discovery on the model the backend applied Compare the model the next queued turn carries with the backend's model instead of session state, so an older queued batch or a failed switch keeps discovery pending; forward the saved effort on terminal resume.
96 lines
4.1 KiB
TypeScript
96 lines
4.1 KiB
TypeScript
import chalk from 'chalk'
|
|
import { authAndSetupMachineIfNeeded } from '@/ui/auth'
|
|
import { initializeToken } from '@/ui/tokenInit'
|
|
import { maybeAutoStartServer } from '@/utils/autoStartServer'
|
|
import type { CommandDefinition } from './types'
|
|
import { KIMI_PERMISSION_MODES } from '@hapi/protocol/modes'
|
|
import type { KimiPermissionMode } from '@hapi/protocol/types'
|
|
|
|
export const kimiCommand: CommandDefinition = {
|
|
name: 'kimi',
|
|
requiresRuntimeAssets: true,
|
|
run: async ({ commandArgs }) => {
|
|
try {
|
|
const options: {
|
|
startedBy?: 'runner' | 'terminal'
|
|
startingMode?: 'local' | 'remote'
|
|
permissionMode?: KimiPermissionMode
|
|
model?: string
|
|
effort?: string
|
|
resumeSessionId?: string
|
|
existingSessionId?: string
|
|
reservedSessionId?: string
|
|
} = {}
|
|
|
|
let hasExplicitPermissionMode = false
|
|
|
|
for (let i = 0; i < commandArgs.length; i++) {
|
|
const arg = commandArgs[i]
|
|
if (arg === '--started-by') {
|
|
options.startedBy = commandArgs[++i] as 'runner' | 'terminal'
|
|
} else if (arg === '--hapi-starting-mode') {
|
|
const value = commandArgs[++i]
|
|
if (value === 'local' || value === 'remote') {
|
|
options.startingMode = value
|
|
} else {
|
|
throw new Error('Invalid --hapi-starting-mode (expected local or remote)')
|
|
}
|
|
} else if (arg === '--hapi-session-id') {
|
|
// Adopt-stub: create bootstrap with reserved id (not reopen).
|
|
const sessionId = commandArgs[++i]
|
|
if (!sessionId) {
|
|
throw new Error('Missing --hapi-session-id value')
|
|
}
|
|
options.reservedSessionId = sessionId
|
|
} else if (arg === '--existing-session-id') {
|
|
const sessionId = commandArgs[++i]
|
|
if (!sessionId) {
|
|
throw new Error('Missing --existing-session-id value')
|
|
}
|
|
options.existingSessionId = sessionId
|
|
} else if (arg === '--permission-mode') {
|
|
const mode = commandArgs[++i]
|
|
if (!mode || !(KIMI_PERMISSION_MODES as readonly string[]).includes(mode)) {
|
|
throw new Error(`Invalid --permission-mode value: ${mode ?? '(missing)'}`)
|
|
}
|
|
options.permissionMode = mode as KimiPermissionMode
|
|
hasExplicitPermissionMode = true
|
|
} else if (arg === '--yolo' && !hasExplicitPermissionMode) {
|
|
options.permissionMode = 'yolo'
|
|
} else if (arg === '--resume') {
|
|
const sessionId = commandArgs[++i]
|
|
if (!sessionId) {
|
|
throw new Error('Missing --resume value')
|
|
}
|
|
options.resumeSessionId = sessionId
|
|
} else if (arg === '--model') {
|
|
const model = commandArgs[++i]
|
|
if (!model) {
|
|
throw new Error('Missing --model value')
|
|
}
|
|
options.model = model
|
|
} else if (arg === '--effort') {
|
|
const effort = commandArgs[++i]
|
|
if (!effort) {
|
|
throw new Error('Missing --effort value')
|
|
}
|
|
options.effort = effort
|
|
}
|
|
}
|
|
|
|
await initializeToken()
|
|
await maybeAutoStartServer()
|
|
await authAndSetupMachineIfNeeded()
|
|
|
|
const { runKimi } = await import('@/kimi/runKimi')
|
|
await runKimi(options)
|
|
} catch (error) {
|
|
console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error')
|
|
if (process.env.DEBUG) {
|
|
console.error(error)
|
|
}
|
|
process.exit(1)
|
|
}
|
|
}
|
|
}
|