From 5f06bf89100712f7df9e9716e751d12510fdf352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=90=E7=9B=AE?= Date: Sat, 28 Feb 2026 13:59:20 +0800 Subject: [PATCH] feat(i18n): strengthen output-language.md template to enforce language compliance Replace soft "Prefer responding" wording with mandatory "MUST always respond" rule to improve LLM adherence to configured output language. Add exception clause allowing users to explicitly override for the remainder of a conversation. --- packages/cli/src/utils/languageUtils.test.ts | 37 ++++++++++++++++++++ packages/cli/src/utils/languageUtils.ts | 11 +++--- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/utils/languageUtils.test.ts b/packages/cli/src/utils/languageUtils.test.ts index a0f0ca717..cd3112b57 100644 --- a/packages/cli/src/utils/languageUtils.test.ts +++ b/packages/cli/src/utils/languageUtils.test.ts @@ -218,6 +218,43 @@ describe('languageUtils', () => { '', ); }); + + it('should use mandatory language rule instead of preference', () => { + writeOutputLanguageFile('Chinese'); + + const writtenContent = vi.mocked(fs.writeFileSync).mock + .calls[0][1] as string; + expect(writtenContent).toContain( + 'You MUST always respond in **Chinese**', + ); + expect(writtenContent).toContain( + 'This is a mandatory requirement, not a preference.', + ); + expect(writtenContent).not.toContain('Prefer responding'); + }); + + it('should include exception clause for explicit user language requests', () => { + writeOutputLanguageFile('English'); + + const writtenContent = vi.mocked(fs.writeFileSync).mock + .calls[0][1] as string; + expect(writtenContent).toContain('## Exception'); + expect(writtenContent).toContain( + "switch to the user's requested language for the remainder of the conversation", + ); + }); + + it('should use the correct language name throughout the template', () => { + writeOutputLanguageFile('Japanese'); + + const writtenContent = vi.mocked(fs.writeFileSync).mock + .calls[0][1] as string; + expect(writtenContent).toContain( + 'You MUST always respond in **Japanese**', + ); + expect(writtenContent).toContain('## Rule'); + expect(writtenContent).toContain('## Exception'); + }); }); describe('updateOutputLanguageFile', () => { diff --git a/packages/cli/src/utils/languageUtils.ts b/packages/cli/src/utils/languageUtils.ts index e9b61923d..cb4e06c4d 100644 --- a/packages/cli/src/utils/languageUtils.ts +++ b/packages/cli/src/utils/languageUtils.ts @@ -89,17 +89,18 @@ function generateOutputLanguageFileContent(language: string): string { return `# Output language preference: ${language} -## Goal -Prefer responding in **${language}** for normal assistant messages and explanations. +## Rule +You MUST always respond in **${language}** regardless of the user's input language. +This is a mandatory requirement, not a preference. + +## Exception +If the user **explicitly** requests a response in a specific language (e.g., "please reply in English", "用中文回答"), switch to the user's requested language for the remainder of the conversation. ## Keep technical artifacts unchanged Do **not** translate or rewrite: - Code blocks, CLI commands, file paths, stack traces, logs, JSON keys, identifiers - Exact quoted text from the user (keep quotes verbatim) -## When a conflict exists -If higher-priority instructions (system/developer) require a different behavior, follow them. - ## Tool / system outputs Raw tool/system outputs may contain fixed-format English. Preserve them verbatim, and if needed, add a short **${language}** explanation below. `;