🐛 Optimize wishes with flash instead of the coding model

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 <noreply@anthropic.com>
This commit is contained in:
eust-w 2026-11-02 15:25:21 +08:00
parent 8247cc209a
commit 7dfd5b159c
4 changed files with 45 additions and 1 deletions

View File

@ -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)

View File

@ -18,6 +18,8 @@ export async function askClaude(
system: string;
prompt: string;
schema: Record<string, unknown>;
/** 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)) },

View File

@ -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,

View File

@ -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 () => ({}));