From 7dfd5b159c5c7d0cfa54c6a4233f09f13b45f102 Mon Sep 17 00:00:00 2001 From: eust-w Date: Mon, 2 Nov 2026 15:25:21 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Optimize=20wishes=20with=20flash?= =?UTF-8?q?=20instead=20of=20the=20coding=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AI optimization called Claude CLI with no --model, so it used deepseek-pro and hit the 120 s limit. It now uses flash by default, with 140 s, and WF_CLAUDE_ASK_MODEL can override it. Co-Authored-By: Claude Fable 5 --- apps/api/src/domain/wish-refiner.ts | 4 ++++ packages/runtime/src/providers/claude-ask.ts | 3 +++ packages/runtime/test/claude-ask.test.ts | 15 ++++++++++++ tests/wish-refiner.test.ts | 24 +++++++++++++++++++- 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/apps/api/src/domain/wish-refiner.ts b/apps/api/src/domain/wish-refiner.ts index 5ec6657..4143db1 100644 --- a/apps/api/src/domain/wish-refiner.ts +++ b/apps/api/src/domain/wish-refiner.ts @@ -139,6 +139,10 @@ export class WishRefiner { 2, ), schema, + // A rewrite of a few hundred words: the gateway's small model, and enough time for the + // console's 150 s proxy. The executor's default (ANTHROPIC_MODEL) is the large coding model. + model: this.env.WF_CLAUDE_ASK_MODEL || 'deepseek-flash@latest[1m]', + timeoutMs: 140_000, }); const parsed = answer.safeParse(output); if (!parsed.success) diff --git a/packages/runtime/src/providers/claude-ask.ts b/packages/runtime/src/providers/claude-ask.ts index b191b43..ff2d81b 100644 --- a/packages/runtime/src/providers/claude-ask.ts +++ b/packages/runtime/src/providers/claude-ask.ts @@ -18,6 +18,8 @@ export async function askClaude( system: string; prompt: string; schema: Record; + /** Model the CLI should use; otherwise it uses ANTHROPIC_MODEL from the operator's settings. */ + model?: string; timeoutMs?: number; signal?: AbortSignal; }, @@ -46,6 +48,7 @@ export async function askClaude( input.system, '--json-schema', JSON.stringify(input.schema), + ...(input.model ? ['--model', input.model] : []), ], cwd: directory, env: { PATH: process.env.PATH, HOME: input.home, ...(await localCredentialEnv(input.home)) }, diff --git a/packages/runtime/test/claude-ask.test.ts b/packages/runtime/test/claude-ask.test.ts index c829c15..bc7718b 100644 --- a/packages/runtime/test/claude-ask.test.ts +++ b/packages/runtime/test/claude-ask.test.ts @@ -39,9 +39,24 @@ describe('asking the local Claude CLI', () => { expect(args[args.indexOf('--system-prompt') + 1]).toBe('Rewrite the wish.'); expect(JSON.parse(args[args.indexOf('--json-schema') + 1]!)).toEqual({ type: 'object' }); expect(seen!.env).toMatchObject({ HOME: '/nonexistent-home' }); + expect(args).not.toContain('--model'); expect(seen!.env).not.toHaveProperty('WF_DEV_AUTH_TOKEN'); expect(existsSync(seen!.cwd!)).toBe(false); }); + it('passes a named model to the CLI', async () => { + let seen: Command | undefined; + await askClaude({ ...input, model: 'deepseek-flash@latest[1m]', timeoutMs: 140_000 }, async command => { + seen = command; + return { + exitCode: 0, + stdout: JSON.stringify({ is_error: false, structured_output: { goal: 'y' } }), + stderr: '', + durationMs: 1, + }; + }); + expect(seen!.args[seen!.args.indexOf('--model') + 1]).toBe('deepseek-flash@latest[1m]'); + expect(seen!.timeoutMs).toBe(140_000); + }); it('takes the JSON object from a text answer, and fails on an error result', async () => { const text = await askClaude(input, async () => ({ exitCode: 0, diff --git a/tests/wish-refiner.test.ts b/tests/wish-refiner.test.ts index dfc8c7c..b3e78f1 100644 --- a/tests/wish-refiner.test.ts +++ b/tests/wish-refiner.test.ts @@ -84,7 +84,29 @@ describe('wish optimization', () => { expect(criteria.questions).toEqual([]); expect(asked[0]!.system).toContain('验收标准必须包含新增的单元测试'); expect(JSON.parse(asked[0]!.prompt)).toMatchObject({ project: 'Pilot', goal: '下载文件名要带上类型' }); - expect(asked[0]).toMatchObject({ binary: '/usr/local/bin/claude', home: '/Users/operator' }); + expect(asked[0]).toMatchObject({ + binary: '/usr/local/bin/claude', + home: '/Users/operator', + model: 'deepseek-flash@latest[1m]', + timeoutMs: 140_000, + }); + }); + it('lets the operator name a different model for optimization', async () => { + const asked: { model?: string }[] = []; + const refiner = new WishRefiner( + store, + { ...env, WF_CLAUDE_ASK_MODEL: 'deepseek-pro@latest[1m]' }, + async input => { + asked.push(input); + return { + goal: '下载文件名带上数据集类型。\n范围:例如 xxx-episode.zip。', + acceptanceCriteria: ['现有测试、类型检查和构建全部通过'], + questions: [], + }; + }, + ); + await refiner.refine(owner, projectId, { goal: '下载文件名要带上类型' }); + expect(asked[0]!.model).toBe('deepseek-pro@latest[1m]'); }); it('says so when no local Claude account serves this tenant, and when the answer is unusable', async () => { const unavailable = new WishRefiner(store, { ...env, WF_DEPLOYMENT_MODE: 'production' }, async () => ({}));