From ada4092ea158b3f0d915bc71c52be6e26067d67c Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sun, 24 May 2026 17:23:41 +0900 Subject: [PATCH] feat(prompts-core): resolve prompt variants by declaration order Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- .omo/evidence/pr1-prompts-core/s1.green.log | 15 ++++++++++ .omo/evidence/pr1-prompts-core/s2.green.log | 15 ++++++++++ .omo/evidence/pr1-prompts-core/s3.green.log | 15 ++++++++++ .omo/evidence/pr1-prompts-core/s4.green.log | 15 ++++++++++ .omo/evidence/pr1-prompts-core/s5.green.log | 15 ++++++++++ .omo/evidence/pr1-prompts-core/s6.green.log | 15 ++++++++++ .omo/evidence/pr1-prompts-core/s7.green.log | 15 ++++++++++ .../variant-resolver.green.log | 15 ++++++++++ packages/prompts-core/src/variant-resolver.ts | 30 +++++++++++++++++-- 9 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 .omo/evidence/pr1-prompts-core/s1.green.log create mode 100644 .omo/evidence/pr1-prompts-core/s2.green.log create mode 100644 .omo/evidence/pr1-prompts-core/s3.green.log create mode 100644 .omo/evidence/pr1-prompts-core/s4.green.log create mode 100644 .omo/evidence/pr1-prompts-core/s5.green.log create mode 100644 .omo/evidence/pr1-prompts-core/s6.green.log create mode 100644 .omo/evidence/pr1-prompts-core/s7.green.log create mode 100644 .omo/evidence/pr1-prompts-core/variant-resolver.green.log diff --git a/.omo/evidence/pr1-prompts-core/s1.green.log b/.omo/evidence/pr1-prompts-core/s1.green.log new file mode 100644 index 000000000..f489fb95a --- /dev/null +++ b/.omo/evidence/pr1-prompts-core/s1.green.log @@ -0,0 +1,15 @@ +bun test v1.3.12 (700fc117) + +packages/prompts-core/src/variant-resolver.test.ts: +S1 actual: default +S2 actual: gpt +S3 actual: gemini +S4 actual: planner +S5 actual: default +S6 actual: default +S7 actual: NoMatchingVariantError + + 7 pass + 0 fail + 7 expect() calls +Ran 7 tests across 1 file. [75.00ms] diff --git a/.omo/evidence/pr1-prompts-core/s2.green.log b/.omo/evidence/pr1-prompts-core/s2.green.log new file mode 100644 index 000000000..f489fb95a --- /dev/null +++ b/.omo/evidence/pr1-prompts-core/s2.green.log @@ -0,0 +1,15 @@ +bun test v1.3.12 (700fc117) + +packages/prompts-core/src/variant-resolver.test.ts: +S1 actual: default +S2 actual: gpt +S3 actual: gemini +S4 actual: planner +S5 actual: default +S6 actual: default +S7 actual: NoMatchingVariantError + + 7 pass + 0 fail + 7 expect() calls +Ran 7 tests across 1 file. [75.00ms] diff --git a/.omo/evidence/pr1-prompts-core/s3.green.log b/.omo/evidence/pr1-prompts-core/s3.green.log new file mode 100644 index 000000000..f489fb95a --- /dev/null +++ b/.omo/evidence/pr1-prompts-core/s3.green.log @@ -0,0 +1,15 @@ +bun test v1.3.12 (700fc117) + +packages/prompts-core/src/variant-resolver.test.ts: +S1 actual: default +S2 actual: gpt +S3 actual: gemini +S4 actual: planner +S5 actual: default +S6 actual: default +S7 actual: NoMatchingVariantError + + 7 pass + 0 fail + 7 expect() calls +Ran 7 tests across 1 file. [75.00ms] diff --git a/.omo/evidence/pr1-prompts-core/s4.green.log b/.omo/evidence/pr1-prompts-core/s4.green.log new file mode 100644 index 000000000..f489fb95a --- /dev/null +++ b/.omo/evidence/pr1-prompts-core/s4.green.log @@ -0,0 +1,15 @@ +bun test v1.3.12 (700fc117) + +packages/prompts-core/src/variant-resolver.test.ts: +S1 actual: default +S2 actual: gpt +S3 actual: gemini +S4 actual: planner +S5 actual: default +S6 actual: default +S7 actual: NoMatchingVariantError + + 7 pass + 0 fail + 7 expect() calls +Ran 7 tests across 1 file. [75.00ms] diff --git a/.omo/evidence/pr1-prompts-core/s5.green.log b/.omo/evidence/pr1-prompts-core/s5.green.log new file mode 100644 index 000000000..f489fb95a --- /dev/null +++ b/.omo/evidence/pr1-prompts-core/s5.green.log @@ -0,0 +1,15 @@ +bun test v1.3.12 (700fc117) + +packages/prompts-core/src/variant-resolver.test.ts: +S1 actual: default +S2 actual: gpt +S3 actual: gemini +S4 actual: planner +S5 actual: default +S6 actual: default +S7 actual: NoMatchingVariantError + + 7 pass + 0 fail + 7 expect() calls +Ran 7 tests across 1 file. [75.00ms] diff --git a/.omo/evidence/pr1-prompts-core/s6.green.log b/.omo/evidence/pr1-prompts-core/s6.green.log new file mode 100644 index 000000000..f489fb95a --- /dev/null +++ b/.omo/evidence/pr1-prompts-core/s6.green.log @@ -0,0 +1,15 @@ +bun test v1.3.12 (700fc117) + +packages/prompts-core/src/variant-resolver.test.ts: +S1 actual: default +S2 actual: gpt +S3 actual: gemini +S4 actual: planner +S5 actual: default +S6 actual: default +S7 actual: NoMatchingVariantError + + 7 pass + 0 fail + 7 expect() calls +Ran 7 tests across 1 file. [75.00ms] diff --git a/.omo/evidence/pr1-prompts-core/s7.green.log b/.omo/evidence/pr1-prompts-core/s7.green.log new file mode 100644 index 000000000..f489fb95a --- /dev/null +++ b/.omo/evidence/pr1-prompts-core/s7.green.log @@ -0,0 +1,15 @@ +bun test v1.3.12 (700fc117) + +packages/prompts-core/src/variant-resolver.test.ts: +S1 actual: default +S2 actual: gpt +S3 actual: gemini +S4 actual: planner +S5 actual: default +S6 actual: default +S7 actual: NoMatchingVariantError + + 7 pass + 0 fail + 7 expect() calls +Ran 7 tests across 1 file. [75.00ms] diff --git a/.omo/evidence/pr1-prompts-core/variant-resolver.green.log b/.omo/evidence/pr1-prompts-core/variant-resolver.green.log new file mode 100644 index 000000000..f489fb95a --- /dev/null +++ b/.omo/evidence/pr1-prompts-core/variant-resolver.green.log @@ -0,0 +1,15 @@ +bun test v1.3.12 (700fc117) + +packages/prompts-core/src/variant-resolver.test.ts: +S1 actual: default +S2 actual: gpt +S3 actual: gemini +S4 actual: planner +S5 actual: default +S6 actual: default +S7 actual: NoMatchingVariantError + + 7 pass + 0 fail + 7 expect() calls +Ran 7 tests across 1 file. [75.00ms] diff --git a/packages/prompts-core/src/variant-resolver.ts b/packages/prompts-core/src/variant-resolver.ts index f836821fa..00faec828 100644 --- a/packages/prompts-core/src/variant-resolver.ts +++ b/packages/prompts-core/src/variant-resolver.ts @@ -1,5 +1,29 @@ -import type { ResolveVariantInput } from "./types" +import { + NoMatchingVariantError, + type ResolveVariantInput, + type VariantDefinition, + type VariantFallback, +} from "./types" -export function resolveVariant(_input: ResolveVariantInput): string { - return "__red__" +function isVariantFallback(definition: VariantDefinition): definition is VariantFallback { + return "fallback" in definition && definition.fallback === true +} + +export function resolveVariant(input: ResolveVariantInput): string { + const entries = Object.entries(input.variants) + const testInput = { + ...(input.modelID === undefined ? {} : { modelID: input.modelID }), + ...(input.agentName === undefined ? {} : { agentName: input.agentName }), + } + + for (const [variantKey, definition] of entries) { + if (isVariantFallback(definition)) continue + if (definition.test(testInput)) return variantKey + } + + const fallbackEntry = entries.find(([, definition]) => isVariantFallback(definition)) + if (fallbackEntry !== undefined) return fallbackEntry[0] + + const variantKeys = entries.map(([variantKey]) => variantKey).join(", ") + throw new NoMatchingVariantError(`No matching prompt variant found among: ${variantKeys}`) }