diff --git a/adapters/cloudflare-workflow/wrangler.cgl-opencode.toml b/adapters/cloudflare-workflow/wrangler.cgl-opencode.toml index 5984085..87add24 100644 --- a/adapters/cloudflare-workflow/wrangler.cgl-opencode.toml +++ b/adapters/cloudflare-workflow/wrangler.cgl-opencode.toml @@ -6,6 +6,7 @@ compatibility_date = "2026-01-01" AI_REVIEW_PROVIDER = "opencode" AI_REVIEW_PROVIDER_ROLE = "primary" OPENCODE_MODEL = "glm-5.3" +OPENCODE_CROSS_REVIEW_MODEL = "kimi-k3.1-pro" GITHUB_APP_ID = "1234567" REVIEWER_LOGIN = "cgl-opencode-reviewer[bot]" FALLBACK_GRACE_MINUTES = "10" diff --git a/scripts/refresh-opencode-model.mjs b/scripts/refresh-opencode-model.mjs index 84a9c71..ba9302a 100644 --- a/scripts/refresh-opencode-model.mjs +++ b/scripts/refresh-opencode-model.mjs @@ -3,18 +3,29 @@ import { resolve, dirname } from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; const GLM_VERSION_RE = /^(?:opencode-go\/)?glm-(\d+)(?:\.(\d+))?(?:\.(\d+))?$/i; +const KIMI_VERSION_RE = /^(?:opencode-go\/)?kimi-k(\d+)(?:\.(\d+))?(?:\.(\d+))?(-pro)?$/i; export function parseGlmVersion(modelId) { const text = String(modelId || '').trim(); - if (!text || /deepseek/i.test(text) || /flash|lite|mini|preview|beta/i.test(text)) return null; + if (!text || /deepseek/i.test(text) || /flash|lite|mini|preview|beta|free/i.test(text)) return null; const match = GLM_VERSION_RE.exec(text); if (!match) return null; return [Number(match[1]), Number(match[2] || 0), Number(match[3] || 0)]; } +export function parseKimiVersion(modelId) { + const text = String(modelId || '').trim(); + if (!text || /deepseek/i.test(text) || /flash|lite|mini|preview|beta|free/i.test(text)) return null; + const match = KIMI_VERSION_RE.exec(text); + if (!match) return null; + return [Number(match[1]), Number(match[2] || 0), Number(match[3] || 0), match[4] ? 1 : 0]; +} + export function compareVersions(a, b) { - for (let i = 0; i < 3; i += 1) { - if (a[i] !== b[i]) return a[i] - b[i]; + const len = Math.max(a.length, b.length); + for (let i = 0; i < len; i += 1) { + const diff = (a[i] || 0) - (b[i] || 0); + if (diff !== 0) return diff; } return 0; } @@ -32,6 +43,19 @@ export function selectLatestOpenCodeGlmModel(modelIds = []) { return best ? best.id : null; } +export function selectLatestOpenCodeKimiModel(modelIds = []) { + let best = null; + for (const rawId of modelIds) { + const version = parseKimiVersion(rawId); + if (!version) continue; + const bare = String(rawId).trim().replace(/^opencode-go\//i, ''); + if (!best || compareVersions(version, best.version) > 0) { + best = { id: bare, version }; + } + } + return best ? best.id : null; +} + export function isNewerGlmModel(candidateModel, currentModel) { const candidateVersion = parseGlmVersion(candidateModel); if (!candidateVersion) return false; @@ -40,6 +64,14 @@ export function isNewerGlmModel(candidateModel, currentModel) { return compareVersions(candidateVersion, currentVersion) > 0; } +export function isNewerKimiModel(candidateModel, currentModel) { + const candidateVersion = parseKimiVersion(candidateModel); + if (!candidateVersion) return false; + const currentVersion = parseKimiVersion(currentModel); + if (!currentVersion) return true; + return compareVersions(candidateVersion, currentVersion) > 0; +} + export function updateWranglerOpenCodeModel(content, newModel) { if (!newModel || /deepseek/i.test(newModel) || /^replace-with-/i.test(newModel)) { throw new Error(`Refusing invalid OPENCODE_MODEL: ${newModel}`); @@ -54,6 +86,20 @@ export function updateWranglerOpenCodeModel(content, newModel) { return replaced; } +export function updateWranglerCrossReviewModel(content, newModel) { + if (!newModel || /deepseek/i.test(newModel) || /^replace-with-/i.test(newModel)) { + throw new Error(`Refusing invalid OPENCODE_CROSS_REVIEW_MODEL: ${newModel}`); + } + const replaced = content.replace( + /^OPENCODE_CROSS_REVIEW_MODEL\s*=\s*"[^"]*"/m, + `OPENCODE_CROSS_REVIEW_MODEL = "${newModel}"` + ); + if (replaced === content && !content.includes(`OPENCODE_CROSS_REVIEW_MODEL = "${newModel}"`)) { + throw new Error('Could not locate OPENCODE_CROSS_REVIEW_MODEL line in wrangler config'); + } + return replaced; +} + export async function fetchOpenCodeModels({ catalogUrl = 'https://models.dev/api.json', } = {}, fetchImpl = fetch) { @@ -76,6 +122,7 @@ export async function runCli(argv = process.argv.slice(2), fetchImpl = fetch) { if (!latest) { throw new Error('No eligible flagship GLM model found in OpenCode Go catalog'); } + const latestCross = selectLatestOpenCodeKimiModel(modelIds); const targets = [ 'adapters/cloudflare-workflow/wrangler.qsl-opencode.toml', @@ -87,15 +134,22 @@ export async function runCli(argv = process.argv.slice(2), fetchImpl = fetch) { for (const rel of targets) { const abs = resolve(rootDir, rel); const before = readFileSync(abs, 'utf8'); - const current = /^OPENCODE_MODEL\s*=\s*"([^"]*)"/m.exec(before)?.[1] || ''; - if (!isNewerGlmModel(latest, current)) continue; - const after = updateWranglerOpenCodeModel(before, latest); - if (after !== before) { - if (write) writeFileSync(abs, after, 'utf8'); - changes.push({ file: rel, from: current, to: latest }); + let next = before; + const current = /^OPENCODE_MODEL\s*=\s*"([^"]*)"/m.exec(next)?.[1] || ''; + if (isNewerGlmModel(latest, current)) { + next = updateWranglerOpenCodeModel(next, latest); + changes.push({ file: rel, key: 'OPENCODE_MODEL', from: current, to: latest }); + } + const currentCross = /^OPENCODE_CROSS_REVIEW_MODEL\s*=\s*"([^"]*)"/m.exec(next)?.[1] || ''; + if (currentCross && latestCross && isNewerKimiModel(latestCross, currentCross)) { + next = updateWranglerCrossReviewModel(next, latestCross); + changes.push({ file: rel, key: 'OPENCODE_CROSS_REVIEW_MODEL', from: currentCross, to: latestCross }); + } + if (next !== before && write) { + writeFileSync(abs, next, 'utf8'); } } - console.log(JSON.stringify({ latest, changed: changes.length > 0, changes }, null, 2)); + console.log(JSON.stringify({ latest, latestCross, changed: changes.length > 0, changes }, null, 2)); } const isMain = process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href; diff --git a/tests/refresh-opencode-model.test.mjs b/tests/refresh-opencode-model.test.mjs index f9a03eb..7803c58 100644 --- a/tests/refresh-opencode-model.test.mjs +++ b/tests/refresh-opencode-model.test.mjs @@ -2,7 +2,10 @@ import test from 'node:test'; import assert from 'node:assert/strict'; import { isNewerGlmModel, + isNewerKimiModel, selectLatestOpenCodeGlmModel, + selectLatestOpenCodeKimiModel, + updateWranglerCrossReviewModel, updateWranglerOpenCodeModel, } from '../scripts/refresh-opencode-model.mjs'; @@ -31,3 +34,19 @@ test('updateWranglerOpenCodeModel updates OPENCODE_MODEL and rejects invalid mod assert.throws(() => updateWranglerOpenCodeModel(sample, 'deepseek-v4'), /Refusing invalid/); assert.throws(() => updateWranglerOpenCodeModel(sample, 'replace-with-opencode-model'), /Refusing invalid/); }); + +test('selectLatestOpenCodeKimiModel and updateWranglerCrossReviewModel track latest Kimi flagship', () => { + const latest = selectLatestOpenCodeKimiModel([ + 'opencode-go/kimi-k2.5', + 'opencode-go/kimi-k3', + 'opencode-go/kimi-k3.1-pro', + 'opencode-go/kimi-k3.2-preview', + 'opencode-go/deepseek-v4-pro', + ]); + assert.equal(latest, 'kimi-k3.1-pro'); + assert.equal(isNewerKimiModel('kimi-k3.1-pro', 'kimi-k3'), true); + assert.equal(isNewerKimiModel('kimi-k3', 'kimi-k3.1-pro'), false); + const sample = '[vars]\nOPENCODE_MODEL = "glm-5.3"\nOPENCODE_CROSS_REVIEW_MODEL = "kimi-k3"\n'; + const updated = updateWranglerCrossReviewModel(sample, 'kimi-k3.1-pro'); + assert.match(updated, /OPENCODE_CROSS_REVIEW_MODEL = "kimi-k3\.1-pro"/); +});