(
opts: CLIOptions,
version: string,
runOptions: { readonly migrateOnly?: boolean } = {},
)
| 32 | import { createKimiCodeHostIdentity } from './version'; |
| 33 | |
| 34 | export async function runShell( |
| 35 | opts: CLIOptions, |
| 36 | version: string, |
| 37 | runOptions: { readonly migrateOnly?: boolean } = {}, |
| 38 | ): Promise<void> { |
| 39 | const startedAt = Date.now(); |
| 40 | const configStartedAt = startedAt; |
| 41 | let tuiConfig: TuiConfig; |
| 42 | let configWarning: string | undefined; |
| 43 | try { |
| 44 | tuiConfig = await loadTuiConfig(); |
| 45 | } catch (error) { |
| 46 | if (!(error instanceof TuiConfigParseError)) throw error; |
| 47 | tuiConfig = error.fallback; |
| 48 | configWarning = error.message; |
| 49 | } |
| 50 | |
| 51 | // Initialise the global Theme singleton before pi-tui grabs stdin. |
| 52 | const palette = await getColorPalette(tuiConfig.theme); |
| 53 | currentTheme.setPalette(palette); |
| 54 | |
| 55 | const workDir = process.cwd(); |
| 56 | const telemetryBootstrap = createCliTelemetryBootstrap(); |
| 57 | const telemetryClient: TelemetryClient = { |
| 58 | track, |
| 59 | withContext: withTelemetryContext, |
| 60 | setContext: setTelemetryContext, |
| 61 | }; |
| 62 | const harness = createKimiHarness({ |
| 63 | homeDir: telemetryBootstrap.homeDir, |
| 64 | identity: createKimiCodeHostIdentity(version), |
| 65 | telemetry: telemetryClient, |
| 66 | onOAuthRefresh: (outcome) => { |
| 67 | if (outcome.success) { |
| 68 | track('oauth_refresh', { outcome: 'success' }); |
| 69 | return; |
| 70 | } |
| 71 | track('oauth_refresh', { |
| 72 | outcome: 'error', |
| 73 | reason: outcome.reason, |
| 74 | }); |
| 75 | }, |
| 76 | sessionStartedProperties: { yolo: opts.yolo, auto: opts.auto, plan: opts.plan, afk: false }, |
| 77 | }); |
| 78 | log.info('kimi-code starting', { |
| 79 | version, |
| 80 | uiMode: CLI_UI_MODE, |
| 81 | nodeVersion: process.version, |
| 82 | platform: `${process.platform}/${process.arch}`, |
| 83 | workDir, |
| 84 | }); |
| 85 | |
| 86 | await harness.ensureConfigFile(); |
| 87 | const migrationPlan = await detectPendingMigration({ |
| 88 | sourceHome: join(homedir(), '.kimi'), |
| 89 | targetHome: harness.homeDir, |
| 90 | ignoreMarker: runOptions.migrateOnly, |
| 91 | }); |
no test coverage detected