feat(cli): setup-kilo — configure Kilo Code for OmniRoute (CLI auth + VS Code settings) - #4284
Conversation
… VS Code settings) CLI #5 of the series. `omniroute setup-kilo` configures Kilo Code (kilocode.kilo-code, a Cline/Roo descendant) to use OmniRoute. Two surfaces (both written, matching the dashboard cli-tools/kilo-settings): - ~/.local/share/kilo/auth.json — CLI mode: auth["openai-compatible"] = { apiKey, baseUrl (WITH /v1 — Kilo appends /chat/completions), model }. - VS Code settings.json — extension: kilocode.customProvider (name/baseURL/apiKey) + kilocode.defaultModel. Only touched when the file already exists. Remote-aware (--remote/--api-key → active context → localhost). Model via --model or an interactive pick from /v1/models (Kilo's extension has no auto-discovery). Prints the exact UI settings to paste. Merges both files (preserves existing). Researched against current Kilo docs: confirmed openAiBaseUrl needs /v1 (unlike Cline's root url), the openai-compatible keys, and the export/import + CLI surfaces. Kilo's wire (/v1/chat/completions) already validated → "OK". Tests: buildKiloAuth (provider + /v1 + merge + key fallback), buildKiloVscodeSettings (kilocode.* keys + preserve), resolveKiloTarget (/v1 ensure, key win). 6 unit tests; check:cli-i18n green.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Code Review
This pull request introduces the setup-kilo command to configure Kilo Code for OmniRoute, along with corresponding documentation and unit tests. The review feedback identifies a critical issue where JSON parsing failures in readJson are silently swallowed, returning an empty object. This would cause the command to overwrite and wipe out existing user configurations. The reviewer suggests returning null on parse failures and handling this to abort or skip updates safely.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| function readJson(path) { | ||
| try { | ||
| if (existsSync(path)) return JSON.parse(readFileSync(path, "utf8")); | ||
| } catch { | ||
| /* corrupt/missing */ | ||
| } | ||
| return {}; | ||
| } |
There was a problem hiding this comment.
If JSON.parse fails (which is very common for VS Code settings.json because it often contains comments or trailing commas), readJson silently returns {}. This causes the command to completely overwrite and wipe out the user's entire VS Code settings.json or Kilo auth.json with only the new keys, resulting in catastrophic data loss. Returning null on parse failure allows us to detect corrupt/invalid JSON and skip/abort writing to prevent data loss.
| function readJson(path) { | |
| try { | |
| if (existsSync(path)) return JSON.parse(readFileSync(path, "utf8")); | |
| } catch { | |
| /* corrupt/missing */ | |
| } | |
| return {}; | |
| } | |
| function readJson(path) { | |
| if (!existsSync(path)) return {}; | |
| try { | |
| return JSON.parse(readFileSync(path, "utf8")); | |
| } catch { | |
| return null; | |
| } | |
| } |
| const auth = buildKiloAuth(readJson(authPath), { apiKey, baseUrl, model }); | ||
| // Only touch VS Code settings.json if it already exists (avoid creating a | ||
| // bogus one for users who don't use that VS Code variant). | ||
| const vscodeExists = existsSync(vscodePath); | ||
| const vscodeSettings = vscodeExists | ||
| ? buildKiloVscodeSettings(readJson(vscodePath), { apiKey, baseUrl, model }) | ||
| : null; |
There was a problem hiding this comment.
We must handle the case where readJson returns null (indicating a JSON parsing failure). If so, we should abort or skip the file update to prevent silently wiping out the user's existing configuration.
const existingAuth = readJson(authPath);
if (existingAuth === null) {
printError("Failed to parse Kilo CLI auth file at " + authPath + ". Aborting to prevent data loss.");
return 1;
}
const auth = buildKiloAuth(existingAuth, { apiKey, baseUrl, model });
// Only touch VS Code settings.json if it already exists (avoid creating a
// bogus one for users who don't use that VS Code variant).
const vscodeExists = existsSync(vscodePath);
let vscodeSettings = null;
if (vscodeExists) {
const existingVscode = readJson(vscodePath);
if (existingVscode === null) {
printError("Failed to parse VS Code settings at " + vscodePath + " (it may contain comments or trailing commas). Skipping VS Code settings update to prevent data loss.");
} else {
vscodeSettings = buildKiloVscodeSettings(existingVscode, { apiKey, baseUrl, model });
}
}… VS Code settings) (diegosouzapw#4284) CLI diegosouzapw#5 of the series. `omniroute setup-kilo` configures Kilo Code (kilocode.kilo-code, a Cline/Roo descendant) to use OmniRoute. Two surfaces (both written, matching the dashboard cli-tools/kilo-settings): - ~/.local/share/kilo/auth.json — CLI mode: auth["openai-compatible"] = { apiKey, baseUrl (WITH /v1 — Kilo appends /chat/completions), model }. - VS Code settings.json — extension: kilocode.customProvider (name/baseURL/apiKey) + kilocode.defaultModel. Only touched when the file already exists. Remote-aware (--remote/--api-key → active context → localhost). Model via --model or an interactive pick from /v1/models (Kilo's extension has no auto-discovery). Prints the exact UI settings to paste. Merges both files (preserves existing). Researched against current Kilo docs: confirmed openAiBaseUrl needs /v1 (unlike Cline's root url), the openai-compatible keys, and the export/import + CLI surfaces. Kilo's wire (/v1/chat/completions) already validated → "OK". Tests: buildKiloAuth (provider + /v1 + merge + key fallback), buildKiloVscodeSettings (kilocode.* keys + preserve), resolveKiloTarget (/v1 ensure, key win). 6 unit tests; check:cli-i18n green.
What
CLI #5.
omniroute setup-kiloconfigures Kilo Code (kilocode.kilo-code, a Cline/Roo descendant) to use OmniRoute. Both surfaces (per the VS-code-extension strategy):~/.local/share/kilo/auth.json(CLI mode):auth["openai-compatible"] = { apiKey, baseUrl WITH /v1, model }.settings.json(extension):kilocode.customProvider(name/baseURL/apiKey) +kilocode.defaultModel— only touched when the file already exists.Remote-aware (
--remote/--api-key→ active context → localhost). Model via--modelor an interactive pick from/v1/models. Prints the exact UI settings to paste. Both files merged (preserve existing).Validation
setup-kilo --remote --dry-run --model glm/glm-5-turbo→ correctauth.json(+ VS Code skip when absent) + UI hints./v1/chat/completions) already validated → "OK".check:cli-i18n✓.Series: Codex #4270 · Claude #4274 · OpenCode #4277 · hardening #4278 · Cline #4280 · Kilo (this). Next: Continue, Cursor, Roo, Crush, Goose, Qwen Code, Gemini CLI, Aider.
🤖 Generated with Claude Code