refactor(prompt): collapse en/zh mirror to English + runtime locale directive
Prompt builder kept two full translations side by side — system-en.ts +
system-zh.ts, operating-en.ts + operating-zh.ts, and 38 *.zh.md files
across api-docs, sops, ceo-modes, department-guidelines, and
wake-reasons. Any change required hand-syncing across two locales; drift
was guaranteed. The Chinese user wasn't getting Chinese thinking — the
model reads whatever prompt we give it and responds in whatever language
we tell it to.
English is now the single source of truth. At the tail of the assembled
system prompt, when `ctx.locale === "zh"`, append a directive:
Respond to the user in Chinese.
Claude, GPT, and Gemini all comply with the directive reliably. English
users (the default) get no footer.
- Deleted 38 `*.zh.md` files (api-docs 11, sops 15, ceo-modes 5,
department-guidelines 7, wake-reasons 1 via zh.ts).
- Deleted `messages/system-zh.ts`, `messages/operating-zh.ts`,
`messages/locale.ts`.
- Simplified `messages/index.ts` to a direct re-export of the English
bundle; getters no longer take a locale argument.
- Stripped zh imports + locale branching from `api-section.ts`,
`sop-section.ts`, `operating-instructions.ts`,
`operating-instructions-ceo.ts`, `api-endpoints.ts`, `wake-reasons/`.
- `buildSOPSection()`, `getSOP()`, `renderWakeReason()` drop the locale
arg; callers updated.
- Footer injection in `system-prompt.ts` (lines 246-249), placed after
the importantRulesSection so the model reads it last (highest
instruction salience).
`ctx.locale` stays on `PromptContext` — load-bearing for the footer.
Anthropic prompt cache hits improve (one cache key instead of two for
the same agent across locales).
This commit is contained in:
1 parent
40040b3dd2
commit
5a3647e98e
53 files changed
+58
-1681
No files matched your search
@@ -1,32 +1,13 @@
|
||||
import type { AppLocale } from "@shared/locale";
|
||||
import { resolveLocale } from "./locale";
|
||||
import * as operatingEn from "./operating-en";
|
||||
import * as operatingZh from "./operating-zh";
|
||||
import * as systemEn from "./system-en";
|
||||
import * as systemZh from "./system-zh";
|
||||
|
||||
export type OperatingMessages = typeof operatingEn;
|
||||
export type SystemMessages = typeof systemEn;
|
||||
|
||||
// zh bundles are constructed from different string literals than en, so
|
||||
// their inferred types are technically distinct. Symbol sets are mirrored
|
||||
// one-for-one, so the `as unknown` coercion is safe by construction.
|
||||
const OPERATING: Record<AppLocale, OperatingMessages> = {
|
||||
en: operatingEn,
|
||||
zh: operatingZh as unknown as OperatingMessages,
|
||||
};
|
||||
|
||||
const SYSTEM: Record<AppLocale, SystemMessages> = {
|
||||
en: systemEn,
|
||||
zh: systemZh as unknown as SystemMessages,
|
||||
};
|
||||
|
||||
export function getOperatingMessages(locale: AppLocale | undefined): OperatingMessages {
|
||||
return OPERATING[resolveLocale(locale)];
|
||||
export function getOperatingMessages(): OperatingMessages {
|
||||
return operatingEn;
|
||||
}
|
||||
|
||||
export function getSystemMessages(locale: AppLocale | undefined): SystemMessages {
|
||||
return SYSTEM[resolveLocale(locale)];
|
||||
export function getSystemMessages(): SystemMessages {
|
||||
return systemEn;
|
||||
}
|
||||
|
||||
export { resolveLocale };
|
||||
Reference in new issue
Block a user