Stop paying the multimodal tax. Your AI agent keeps every image it has seen but only sends the ones it needs: lighter chats, no endless reconnecting, no starting over. Works with Codex, Claude Code, Cline, Gemini CLI, OpenCode, WorkBuddy and more. Install once, forget it.
TypeScript ai-agentsai-imageclaude-codeclaude-code-pluginclinecodexcodex-plugincomputer-usecontext-engineeringcontext-managementdeveloper-toolsgemini-cliimage-generationmcpmultimodalmultimodal-aiopencodeqwen-codetoken-optimizationvision-language-model
feat(language): 标签页标题和发给模型的说明跟随 Codex 自己的语言设置
chipfighterff6d4f3f80e1
diff --git a/plugin/src/cam.ts b/plugin/src/cam.tsindex 36b05c0..46e41fb 100644--- a/plugin/src/cam.ts+++ b/plugin/src/cam.ts@@ -20,7 +20,7 @@ import { findCodexCli, runCodex } from "./codexcli.ts";import { codexHome, MCP_BEGIN, noProxyStatus, proxyStatus } from "./codexconfig.ts";import { buildOf, DEFAULT_PORT, engineHealth, ensureEngine } from "./engine.ts";import { isEntryPoint } from "./entry.ts";-import { storedLang, systemLang } from "./language.ts";+import { codexUiLocale, currentLang, storedLang, systemLang } from "./language.ts";import { say, type MessageKey } from "./messages.ts";import { migrateDataOnce } from "./migrate-data.ts";import { MARKETPLACE, PLUGIN, PLUGIN_ID, planInstall, pluginStatus } from "./install.ts";@@ -202,8 +202,9 @@ async function main(): Promise<void> {dotenv: noProxyStatus(readEnv() ?? ""),engine: health ? { running: true, pid: health.pid, startedAt: health.startedAt, version: health.version ?? null, build: health.build ?? null, sameAsInstalled: health.build === buildOf(join(pluginCacheDir(version), "src")) } : { running: false },codexCli: findCodexCli(),- // Codex's interface language as the panel last reported it; the text for the model follows it.- language: storedLang() ?? { lang: systemLang(), source: "system", note: t("cli.language.notReported") },+ // The language the tab's title and the text for the model use, from Codex's language setting and the panel's last+ // report (language.ts).+ language: { speaks: currentLang(), codexSetting: codexUiLocale(), panelReport: storedLang() },dataDir: dataDir(),}, null, 2));return;diff --git a/plugin/src/language.ts b/plugin/src/language.tsindex fe224cb..71ccf86 100644--- a/plugin/src/language.ts+++ b/plugin/src/language.ts@@ -1,19 +1,26 @@// Purpose: v0.1-14 — which language the plugin speaks: Simplified Chinese or English (user 2026-09-25: these two for// v0.1; Chinese of any region gets Simplified Chinese, every other language gets English). The panel learns Codex's// interface language and reports it with its calls; it is kept in the data directory, where the engine (the text for-// the model) and the plugin service (the tab's title) read it. Until a panel has reported one, the system language-// counts; the command line always follows the system language. CAM_LANG=zh|en (tests, development) fixes the language.-// Input: language tags (BCP 47 or POSIX, e.g. "zh-CN", "zh_TW.UTF-8", "en-US"), the environment, the data directory.-// Output: "zh" | "en"; <data dir>/language.json = { "lang": "zh", "source": "codex" | "system", "at": "…" }.+// the model) and the plugin service (the tab's title) read it. The command line always follows the system language.+// CAM_LANG=zh|en (tests, development) fixes the language.+// v0.1-20 (user 2026-09-26) — Codex's own language setting counts too, so the tab's title is right before any panel is+// opened, and after the user changes Codex's language: the desktop app writes the interface language it uses for its+// Computer Use helper to <CODEX_HOME>/computer-use/config.json. Order: a panel's report while that setting is the one+// it was seen with, else the setting, else the last report, else the system language.+// Input: language tags (BCP 47 or POSIX, e.g. "zh-CN", "zh_TW.UTF-8", "en-US"), the environment, the data directory,+// Codex's computer-use/config.json (read only). Output: "zh" | "en";+// <data dir>/language.json = { "lang": "zh", "source": "codex" | "system", "at": "…", "codexLocale": "zh-CN" | null }.import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";import { dirname, join } from "node:path";+import { codexHome } from "./codexconfig.ts";import { dataDir } from "./paths.ts";export type Lang = "zh" | "en";// codex: the panel got Codex's interface language; system: it only had the system's.export type LangSource = "codex" | "system";-type Stored = { lang: Lang; source: LangSource; at: string };+// codexLocale: Codex's language setting when the panel reported (absent in records from before v0.1-20).+type Stored = { lang: Lang; source: LangSource; at: string; codexLocale?: string | null };export function langOf(tag: unknown): Lang | null {if (typeof tag !== "string") return null;@@ -35,13 +42,28 @@ export function systemLang(env: NodeJS.ProcessEnv = process.env): Lang {export const languageFileOf = (root = dataDir()) => join(root, "language.json");let cache: { file: string; mtimeMs: number; value: Stored | null } | null = null;+// Codex's language setting as the desktop app writes it for its Computer Use helper ({ "locale": "en-US", … }): the+// language chosen in Codex's settings, else the app's own locale. Desktop 26.924 rewrites it when the user changes the+// language or the theme, and whenever it builds a task's tool configuration. Not a documented interface, so it is only+// read, and anything missing or unexpected (other platforms, other versions) counts as no setting.+export const codexUiFileOf = (home = codexHome()) => join(home, "computer-use", "config.json");++export function codexUiLocale(file = codexUiFileOf()): string | null {+ try {+ const locale = JSON.parse(readFileSync(file, "utf8"))?.locale;+ return typeof locale === "string" && locale.trim() ? locale.trim() : null;+ } catch {+ return null;+ }+}+export function storedLang(file = languageFileOf()): Stored | null {try {const { mtimeMs } = statSync(file);if (cache?.file === file && cache.mtimeMs === mtimeMs) return cache.value;const raw = JSON.parse(readFileSync(file, "utf8"));const lang = raw?.lang === "zh" || raw?.lang === "en" ? (raw.lang as Lang) : null;- const value: Stored | null = lang ? { lang, source: raw.source === "codex" ? "codex" : "system", at: String(raw.at ?? "") } : null;+ const value: Stored | null = lang ? { lang, source: raw.source === "codex" ? "codex" : "system", at: String(raw.at ?? ""), ...("codexLocale" in raw ? { codexLocale: typeof raw.codexLocale === "string" ? raw.codexLocale : null } : {}) } : null;cache = { file, mtimeMs, value };return value;} catch {@@ -50,17 +72,23 @@ export function storedLang(file = languageFileOf()): Stored | null {}// Written only when it changes, whole file then renamed, so readers never see half of it.-export function rememberLang(lang: Lang, source: LangSource, file = languageFileOf()): void {+export function rememberLang(lang: Lang, source: LangSource, file = languageFileOf(), setting = codexUiFileOf()): void {+ const codexLocale = codexUiLocale(setting);const known = storedLang(file);- if (known?.lang === lang && known.source === source) return;+ if (known?.lang === lang && known.source === source && known.codexLocale === codexLocale) return;mkdirSync(dirname(file), { recursive: true });- writeFileSync(`${file}.tmp`, JSON.stringify({ lang, source, at: new Date().toISOString() }));+ writeFileSync(`${file}.tmp`, JSON.stringify({ lang, source, at: new Date().toISOString(), codexLocale }));renameSync(`${file}.tmp`, file);cache = null;}-export function currentLang(file = languageFileOf()): Lang {+export function currentLang(file = languageFileOf(), setting = codexUiFileOf()): Lang {const fixed = process.env.CAM_LANG;if (fixed === "zh" || fixed === "en") return fixed;- return storedLang(file)?.lang ?? systemLang();+ const codexLocale = codexUiLocale(setting);+ const stored = storedLang(file);+ // A panel saw the interface itself, which can differ from the app's locale; that holds while the setting is unchanged.+ if (stored?.source === "codex" && stored.codexLocale === codexLocale) return stored.lang;+ // Otherwise the setting: no panel has reported yet, or the user has changed Codex's language since.+ return langOf(codexLocale) ?? stored?.lang ?? systemLang();}diff --git a/plugin/src/messages.ts b/plugin/src/messages.tsindex 31ff7c4..99e4b28 100644--- a/plugin/src/messages.ts+++ b/plugin/src/messages.ts@@ -76,7 +76,6 @@ const zh = {"cli.list": "、","cli.next.install": "重启 Codex 后生效。面板在任务右侧的侧边面板:新建标签页 → 插件和 MCP → 上下文素材","cli.next.uninstall": "重启 Codex 后生效;引擎会在 Codex 全部退出后自己退出。勾选记录留在数据目录里,不需要可以删掉",- "cli.language.notReported": "还没有面板报告过 Codex 的界面语言,暂用系统语言",};const en: Record<keyof typeof zh, string> = {@@ -144,7 +143,6 @@ const en: Record<keyof typeof zh, string> = {"cli.list": ", ","cli.next.install": "Restart Codex for this to take effect. The panel is in the task's side panel: New tab > Plugins and MCP > Context Assets","cli.next.uninstall": "Restart Codex for this to take effect; the engine exits by itself once Codex has quit. Your selections stay in the data folder; delete it if you no longer need them",- "cli.language.notReported": "No panel has reported Codex's interface language yet; the system language is used for now",};export type MessageKey = keyof typeof zh;diff --git a/plugin/src/plugin-server.ts b/plugin/src/plugin-server.tsindex 3182fd1..97c162f 100644--- a/plugin/src/plugin-server.ts+++ b/plugin/src/plugin-server.ts@@ -10,7 +10,7 @@// and switches to one with cam_bind; from then on its calls are about that thread (binding.ts). v0.1-11 — slow calls// are logged with their duration; pixel fingerprints are shared with the engine through the data directory.// v0.1-14 — the panel reports Codex's interface language with its calls; it is remembered (language.ts), and the tool-// list (the tab's title), results and refusals speak it (messages.ts).+// list (the tab's title), results and refusals speak it (messages.ts). v0.1-20 — Codex's language setting counts too.// Input: MCP JSON-RPC over stdio. Env: CAM_ENGINE_PORT (default 17891), CAM_NO_ENGINE=1 (tests), CAM_DATA_DIR.// Output: tool results; <data dir>/plugin-server.jsonl (events and counts only, no conversation content).@@ -37,7 +37,9 @@ const here = dirname(fileURLToPath(import.meta.url));export const PANEL_URI = "ui://codex-attachment-manager/panel.html";export const PANEL_MIME = "text/html;profile=mcp-app";const APP_ONLY = { ui: { visibility: ["app"] } };-// The tool list is read when Codex starts this service: it speaks the language last reported by a panel (or the system's).+// The tool list speaks the language at the moment Codex starts this service (language.ts). Codex keeps it: desktop 26.924+// shares it between tasks for up to 30 minutes and ignores notifications that it changed, so after the user changes+// Codex's language the tab's title follows once Codex restarts.export function toolsFor(lang: Lang) {const threadArg = { threadId: { type: "string", description: say(lang, "tool.threadId") } };const langArg = { lang: { type: "string", description: say(lang, "tool.lang") } };diff --git a/spike/src/language.test.ts b/spike/src/language.test.tsindex 8879d12..db98b9f 100644--- a/spike/src/language.test.ts+++ b/spike/src/language.test.ts@@ -1,15 +1,15 @@// Purpose: v0.1-14 — the plugin speaks Simplified Chinese or English: which language a tag or the system gives, the// language the panel reports is remembered, every text exists in both languages with the same {values}, and the text-// for the model and the plugin's answers follow the language.-// Input: synthetic tags, environments and temporary data folders; output: Node test assertions only.+// for the model and the plugin's answers follow the language. v0.1-20 — Codex's own language setting counts too.+// Input: synthetic tags, environments, Codex settings files and temporary data folders; output: Node test assertions.import assert from "node:assert/strict";-import { mkdtempSync, readFileSync } from "node:fs";+import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { dirname, join } from "node:path";import test from "node:test";import { fileURLToPath } from "node:url";-import { currentLang, langOf, rememberLang, storedLang, systemLang } from "../../plugin/src/language.ts";+import { codexUiLocale, currentLang, langOf, rememberLang, storedLang, systemLang } from "../../plugin/src/language.ts";import { MESSAGES, say } from "../../plugin/src/messages.ts";import { callTool, toolsFor } from "../../plugin/src/plugin-server.ts";import { OMISSION_NOTE, omissionNote, rewriteItems, type Described } from "../../plugin/src/rewrite.ts";@@ -27,18 +27,64 @@ test("any Chinese is Simplified Chinese, anything else English; locale variablestest("the language a panel reports is kept, with where it came from; without one the system decides", () => {const file = join(mkdtempSync(join(tmpdir(), "cam-lang-")), "language.json");+ const noSetting = join(dirname(file), "codex-home", "computer-use", "config.json");assert.equal(storedLang(file), null);- assert.equal(currentLang(file), systemLang());- rememberLang("en", "codex", file);+ assert.equal(currentLang(file, noSetting), systemLang());+ rememberLang("en", "codex", file, noSetting);assert.deepEqual([storedLang(file)?.lang, storedLang(file)?.source], ["en", "codex"]);- assert.equal(currentLang(file), "en");+ assert.equal(currentLang(file, noSetting), "en");const written = readFileSync(file, "utf8");- rememberLang("en", "codex", file);+ rememberLang("en", "codex", file, noSetting);assert.equal(readFileSync(file, "utf8"), written, "unchanged: not written again");- rememberLang("zh", "system", file);- assert.deepEqual([currentLang(file), storedLang(file)?.source], ["zh", "system"]);+ rememberLang("zh", "system", file, noSetting);+ assert.deepEqual([currentLang(file, noSetting), storedLang(file)?.source], ["zh", "system"]);process.env.CAM_LANG = "en";- try { assert.deepEqual([currentLang(file), systemLang({ CAM_LANG: "en", LANG: "zh_CN.UTF-8" })], ["en", "en"], "CAM_LANG fixes it (tests, development)"); } finally { delete process.env.CAM_LANG; }+ try { assert.deepEqual([currentLang(file, noSetting), systemLang({ CAM_LANG: "en", LANG: "zh_CN.UTF-8" })], ["en", "en"], "CAM_LANG fixes it (tests, development)"); } finally { delete process.env.CAM_LANG; }+});++// v0.1-20 — the desktop app writes its interface language for its Computer Use helper (<CODEX_HOME>/computer-use/+// config.json). The user's case of 2026-09-26: the panel had reported Chinese; after Codex was set to English, the tab+// kept its Chinese title until a panel was opened again and Codex restarted.+test("Codex's own language setting counts before a panel reports one, and again once the user changes it", () => {+ const dir = mkdtempSync(join(tmpdir(), "cam-lang-"));+ const file = join(dir, "language.json");+ const setting = join(dir, "codex-home", "computer-use", "config.json");+ const setTo = (locale: string) => {+ mkdirSync(dirname(setting), { recursive: true });+ writeFileSync(setting, `${JSON.stringify({ accentColor: "#339cff", direction: "ltr", locale, strings: {} })}\n`);+ };+ assert.deepEqual([codexUiLocale(setting), currentLang(file, setting)], [null, systemLang()], "neither: the system decides");+ setTo("en-US");+ assert.deepEqual([codexUiLocale(setting), currentLang(file, setting)], ["en-US", "en"], "before any panel: Codex's setting");+ setTo("zh-CN");+ assert.equal(currentLang(file, setting), "zh");++ rememberLang("zh", "codex", file, setting);+ assert.deepEqual([storedLang(file)?.lang, storedLang(file)?.codexLocale], ["zh", "zh-CN"], "kept beside the setting it was seen with");+ setTo("en-US");+ assert.equal(currentLang(file, setting), "en", "the user changed Codex's language since: its setting wins");+ rememberLang("en", "codex", file, setting);+ assert.deepEqual([storedLang(file)?.codexLocale, currentLang(file, setting)], ["en-US", "en"], "written again for the new setting");++ // The panel sees what the interface shows, which can differ from the app's locale: it holds while the setting stays.+ rememberLang("en", "codex", file, setting);+ setTo("zh-CN");+ rememberLang("en", "codex", file, setting);+ assert.equal(currentLang(file, setting), "en");++ // A record from before v0.1-20 (no setting beside it), or one from the system's language only, yields to the setting.+ // (New files each time: records are cached by modification time, which Windows may not advance between quick writes.)+ const record = (name: string, value: object) => { const path = join(dir, name); writeFileSync(path, JSON.stringify(value)); return path; };+ const older = record("older.json", { lang: "en", source: "codex", at: "2026-09-25T12:42:36.434Z" });+ assert.equal(currentLang(older, setting), "zh");+ const systemOnly = record("system-only.json", { lang: "en", source: "system", at: "2026-09-26T06:00:00.000Z", codexLocale: "zh-CN" });+ assert.equal(currentLang(systemOnly, setting), "zh");++ // An unreadable setting is ignored: the record, else the system.+ writeFileSync(setting, "{not json");+ assert.deepEqual([codexUiLocale(setting), currentLang(systemOnly, setting)], [null, "en"]);+ writeFileSync(setting, JSON.stringify({ locale: 7 }));+ assert.equal(codexUiLocale(setting), null);});test("the plugin's texts exist in both languages with the same {values}", () => {@@ -61,6 +107,8 @@ test("the tab's title and the tools speak the language; the panel's calls are anassert.deepEqual([toolsFor("zh")[0].title, toolsFor("en")[0].title], ["上下文素材", "Context Assets"]);const { sessionsDir, dataRoot } = sampleSessions();process.env.CAM_DATA_DIR = dataRoot;+ // A Codex home without a language setting, so this machine's Codex settings do not count.+ process.env.CODEX_HOME = join(dirname(dataRoot), "codex-home");try {const model = { "x-codex-turn-metadata": { thread_id: "01a0d301-0000-7000-8000-00000000abcd" } };assert.throws(() => callTool("cam_set_selection", { uncheck: ["IMG-001"], lang: "en" }, model, sessionsDir), /Only the user can check or uncheck images; if you need an image, reply "need IMG-xxx"/);@@ -70,6 +118,7 @@ test("the tab's title and the tools speak the language; the panel's calls are anassert.equal(callTool("cam_panel", {}, panel, sessionsDir).content[0].text, "Images: 3, unchecked: 0.", "a call without a language gets the remembered one");} finally {delete process.env.CAM_DATA_DIR;+ delete process.env.CODEX_HOME;}});