From b8b915739cb52afce9e899f76bbc8f6ec571dbd5 Mon Sep 17 00:00:00 2001 From: "kilo-code-bot[bot]" <240665456+kilo-code-bot[bot]@users.noreply.github.com> Date: Mon, 4 May 2026 10:55:19 +0200 Subject: [PATCH] refactor(prompts): hoist Kilo model-specific prompt checks to the front (#9815) * refactor(cli): hoist Kilo model-specific prompt checks to the front Extract the Kilo metadata-driven prompt selection into a dedicated kiloPrompt() helper and invoke it with an early return at the top of provider(). This ensures Kilo-specific prompt routing takes priority over upstream heuristics and leaves the upstream if-chain untouched, reducing future merge conflicts when opencode adjusts its own model-specific prompt branching. No behavior change. * fix(cli): preserve Ling prompt fallback precedence * fix(cli): keep prompt annotations scoped --------- Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com> Co-authored-by: marius-kilocode --- packages/opencode/src/session/system.ts | 40 +++++++++++-------- .../test/kilocode/system-prompt.test.ts | 19 +++++++++ 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/packages/opencode/src/session/system.ts b/packages/opencode/src/session/system.ts index 8b610e48865..7b30357d791 100644 --- a/packages/opencode/src/session/system.ts +++ b/packages/opencode/src/session/system.ts @@ -37,24 +37,30 @@ export function soul() { export function provider(model: Provider.Model) { // kilocode_change start - switch (model.prompt) { - case "anthropic": - return [PROMPT_ANTHROPIC] - case "anthropic_without_todo": - return [PROMPT_DEFAULT] - case "beast": - return [PROMPT_BEAST] - case "codex": - return [PROMPT_CODEX] - case "gemini": - return [PROMPT_GEMINI] - case "gpt55": - return [PROMPT_GPT55] - case "ling": - return [PROMPT_LING] - case "trinity": - return [PROMPT_TRINITY] + function prompt() { + switch (model.prompt) { + case "anthropic": + return [PROMPT_ANTHROPIC] + case "anthropic_without_todo": + return [PROMPT_DEFAULT] + case "beast": + return [PROMPT_BEAST] + case "codex": + return [PROMPT_CODEX] + case "gemini": + return [PROMPT_GEMINI] + case "gpt55": + return [PROMPT_GPT55] + case "ling": + return [PROMPT_LING] + case "trinity": + return [PROMPT_TRINITY] + } + return undefined } + + const kilo = prompt() + if (kilo) return kilo // kilocode_change end if (model.api.id.includes("gpt-4") || model.api.id.includes("o1") || model.api.id.includes("o3")) diff --git a/packages/opencode/test/kilocode/system-prompt.test.ts b/packages/opencode/test/kilocode/system-prompt.test.ts index d54b94dc03b..4945204e622 100644 --- a/packages/opencode/test/kilocode/system-prompt.test.ts +++ b/packages/opencode/test/kilocode/system-prompt.test.ts @@ -9,6 +9,7 @@ import PROMPT_CODEX from "../../src/session/prompt/codex.txt" import PROMPT_GEMINI from "../../src/session/prompt/gemini.txt" import PROMPT_GPT from "../../src/session/prompt/gpt.txt" import PROMPT_GPT55 from "../../src/session/prompt/kilocode-gpt-5.5.txt" +import PROMPT_LING from "../../src/session/prompt/ling.txt" import PROMPT_TRINITY from "../../src/session/prompt/trinity.txt" describe("SystemPrompt.provider", () => { @@ -78,6 +79,24 @@ describe("SystemPrompt.provider", () => { expect(result).toEqual([PROMPT_ANTHROPIC]) }) + test("Ling fallback runs after upstream model id heuristics", () => { + const model = ProviderTest.model({ + prompt: undefined, + api: { id: "gpt-5-ling", url: "https://example.com", npm: "@ai-sdk/openai" }, + }) + const result = SystemPrompt.provider(model) + expect(result).toEqual([PROMPT_GPT]) + }) + + test("Ling fallback is selected after upstream heuristics miss", () => { + const model = ProviderTest.model({ + prompt: undefined, + api: { id: "ling-2", url: "https://example.com", npm: "@ai-sdk/openai" }, + }) + const result = SystemPrompt.provider(model) + expect(result).toEqual([PROMPT_LING]) + }) + test("GPT-5.5 model ids are not prompt-special without metadata", () => { const model = ProviderTest.model({ prompt: undefined,