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(panel): follow app language and add Japanese UI
chipfighter5a812f26c8e4
diff --git a/hooks/register.js b/hooks/register.jsindex 96e3dea..b894c7d 100644--- a/hooks/register.js+++ b/hooks/register.js@@ -73,6 +73,22 @@ const WORDS = {failed: 'Switching the endpoint failed; this session connects directly: checks have no effect',},},+ ja: {+ title: 'コンテキスト素材',+ open: '素材パネルを開く', copy: 'リンクをコピー', copied: 'リンクをコピーしました',+ opened: 'Claude 内蔵のブラウザーでパネルを開きました。',+ hint: 'パネルはローカルエンジンが提供するページで、Codex のパネルと同じです。画像の選択、プレビュー、絞り込み、自動選択ができます。上のリンクを開くか、コピーしてブラウザーに貼り付けてください。',+ summary: (images, off) => `このセッションの画像 ${images} 枚${off ? `、未送信 ${off} 枚` : ''}`,+ routing: {+ on: (port) => `このセッションはローカルエンジン(ポート ${port})に接続しています`,+ waiting: 'ローカルエンジンの起動を待っています…',+ 'other-endpoint': 'このセッションは別の接続先を使用しています。画像の選択は反映されません',+ provider: 'このセッションは外部のモデルサービスを使用しています。画像の選択は反映されません',+ 'engine-old': '実行中のエンジンが古く、個別の接続経路に対応していません。Codex を終了して cam install を実行し、新しいセッションを開始してください',+ 'no-engine': 'ローカルエンジンが起動していないため、直接接続しています。画像の選択は反映されません',+ failed: '接続先の切り替えに失敗したため、直接接続しています。画像の選択は反映されません',+ },+ },}// What the pane shows, kept between redraws: the routing state, whether /cam opened the page in Claude's browser, and@@ -331,14 +347,14 @@ async function pageTurnEnds($) {keepPageLater($, 'end')}-async function loadOverview($) {+async function loadOverview($, redraw = true) {try {const state = await api($, `/__cam/claude/panel?session=${encodeURIComponent(await $.session.id())}`)overview = { lang: state.lang, images: state.totals.images, off: state.totals.unchecked }} catch {overview = null}- await $.ui.invalidate('ui.render')+ if (redraw) await $.ui.invalidate('ui.render')}// New images come with a turn, and /clear or /resume brings another session: the count follows, without holding up@@ -351,13 +367,13 @@ async function openPane($) {routingState = (await readRouting($)) ?? routingStatecopied = falsepaneOpened = true- await $.ui.open({ id: PANE, title: WORDS.zh.title, focus: true, closeOnEscape: true })- await loadOverview($)+ await loadOverview($, false)+ await $.ui.open({ id: PANE, title: (WORDS[overview?.lang] ?? WORDS.en).title, focus: true, closeOnEscape: true })}async function drawPane($, e) {const { Box, Text, Button, Link } = $.ui.resolve(e)- const w = WORDS[overview?.lang === 'en' ? 'en' : 'zh']+ const w = WORDS[overview?.lang] ?? WORDS.enconst url = panelUrl(await $.session.id())const routing = routingStateconst status = routing?.active ? w.routing.on(routing.port) : w.routing[routing?.reason ?? 'waiting'] ?? w.routing.waitingdiff --git a/plugin/src/panel-language.ts b/plugin/src/panel-language.tsnew file mode 100644index 0000000..ab92994--- /dev/null+++ b/plugin/src/panel-language.ts@@ -0,0 +1,45 @@+// Panel-only language selection. Claude Desktop persists its app language in userData/config.json's locale;+// read that setting without writing it or sharing Codex's remembered model language. Paths are best-effort:+// Claude has used both standard Electron folders and a per-package Claude-Data folder on Windows.+import { readFileSync, readdirSync } from "node:fs";+import { homedir } from "node:os";+import { join } from "node:path";++export type PanelLang = "en" | "zh" | "ja";+type Options = { settingsFiles?: readonly string[]; env?: NodeJS.ProcessEnv; platform?: NodeJS.Platform; home?: string };++function panelLangOf(tag: unknown): PanelLang | null {+ if (typeof tag !== "string" || !tag.trim()) return null;+ const value = tag.trim().toLowerCase();+ if (value === "c" || value === "posix" || value.startsWith("c.")) return null;+ return value.startsWith("zh") ? "zh" : value.startsWith("ja") ? "ja" : "en";+}++function settingsFiles(env: NodeJS.ProcessEnv, platform: NodeJS.Platform, home: string): string[] {+ if (platform === "darwin") return [join(home, "Library", "Application Support", "Claude", "config.json")];+ if (platform !== "win32") return [join(env.XDG_CONFIG_HOME || join(home, ".config"), "Claude", "config.json")];+ const local = env.LOCALAPPDATA || join(home, "AppData", "Local");+ const roaming = env.APPDATA || join(home, "AppData", "Roaming");+ const native = join(local, "Claude-Data");+ let packages: string[] = [];+ try { packages = readdirSync(native, { withFileTypes: true }).filter(entry => entry.isDirectory() && /^claude_/i.test(entry.name)).map(entry => entry.name).sort(); } catch {}+ return [+ ...packages.map(name => join(native, name, "config.json")),+ join(native, "config.json"), join(local, "Claude", "config.json"), join(roaming, "Claude", "config.json"),+ ];+}++export function claudePanelLanguage(options: Options = {}): PanelLang {+ const env = options.env ?? process.env;+ const system = () => {+ for (const name of ["LC_ALL", "LC_MESSAGES", "LANG"]) { const lang = panelLangOf(env[name]); if (lang) return lang; }+ return panelLangOf(Intl.DateTimeFormat().resolvedOptions().locale) ?? "en";+ };+ for (const file of options.settingsFiles ?? settingsFiles(env, options.platform ?? process.platform, options.home ?? homedir())) {+ try {+ const settings = JSON.parse(readFileSync(file, "utf8").replace(/^\uFEFF/, ""));+ return panelLangOf(settings?.locale) ?? system();+ } catch {}+ }+ return system();+}diff --git a/plugin/src/panel.html b/plugin/src/panel.htmlindex 23bf171..86f5892 100644--- a/plugin/src/panel.html+++ b/plugin/src/panel.html@@ -284,7 +284,7 @@<label class="check" id="viewerCheck"><input type="checkbox"><span class="box"></span><span class="label"></span></label></div></div>-<!-- The panel's words (v0.1-14): Simplified Chinese and English, the same keys in both (a unit test checks it);+<!-- The panel's words: Simplified Chinese, English and Japanese, with matching keys (a unit test checks it);"key_one" is the English text for a count of one. --><script type="application/json" id="messages">{@@ -535,6 +535,128 @@"error.disable": "Could not disable: {message}","error.noReply": "Codex did not respond","error.call": "The call failed"+ },+ "ja": {+ "page.title": "コンテキスト素材",+ "title.loading": "コンテキスト素材",+ "title.newTask": "新しいタスク",+ "title.unnamed": "無題のタスク",+ "refresh": "更新",+ "refresh.at": "更新(最終更新 {time})",+ "refresh.stale": "更新(しばらく更新されていません。最終更新 {time})",+ "plugin.disable": "プラグインを無効化",+ "plugin.enable": "プラグインを有効化",+ "meter.loading": "読み込み中…",+ "meter.failed": "読み込めませんでした",+ "meter.empty": "まだ画像はありません",+ "meter.request": "推定リクエスト量",+ "meter.images": "推定画像データ量",+ "meter.atLeast": "{bytes} 以上",+ "meter.autoNote": "このターンでモデルが取得する画像は含みません(事前には分からないため)",+ "meter.full": "全画像 {full} · {percent}% 削減",+ "meter.none": "省略した画像はありません",+ "next.label": "次のメッセージ",+ "next.auto": "毎ターン送信 {sent} 枚",+ "next.manual": "送信 {sent} 枚",+ "next.dropped": " · 代替テキスト {dropped} 枚",+ "next.duplicates": "(うち重複 {duplicates} 枚)",+ "next.gone": " · コンテキスト外 {gone} 枚",+ "card.more": "詳細を表示",+ "card.less": "詳細を閉じる",+ "last.label": "前回のリクエスト {time}",+ "last.labelNone": "前回のリクエスト",+ "last.noBaseline": "プロキシを経由した完全なリクエストがないため、画像サイズから推定しています",+ "last.skipped": "置換できず、そのまま送信 {bytes}",+ "last.replaced": "{count} 枚を置換 · {saved} 削減",+ "last.none": "置換なし、{bytes} を送信",+ "last.resent": "圧縮前から {resent} 枚を再送 · {count} 枚を置換",+ "fetched.label": "前のターンでモデルが取得",+ "fetched.none": "取得なし",+ "children.label": "サブエージェント・サイドチャット {count} 件",+ "children.saved": "前回合計 {saved} 削減",+ "children.none": "前回は置換なし",+ "needs.title": "モデルが未送信の画像 {count} 枚を必要としています",+ "id.jump": "一覧で {id} を探す",+ "search.placeholder": "画像の内容や、そのときの言葉",+ "search.label": "画像を検索",+ "chips.label": "画像を絞り込む",+ "chip.all": "すべて",+ "chip.upload": "アップロード",+ "chip.generated": "生成",+ "chip.other": "その他",+ "chips.more": "ほか {count} 件",+ "chips.less": "閉じる",+ "kind.upload": "アップロード画像",+ "kind.view": "表示した画像",+ "kind.generated": "生成した画像",+ "kind.tool": "ツールの結果",+ "kind.pdf": "PDF ページ",+ "kind.browser": "ウェブページの画像",+ "mark.pinned": "毎ターン送信",+ "mark.fetched": "取得済み",+ "mark.notSent": "送信しない",+ "mark.requested": "モデルが要求",+ "mark.locked": "解除不可",+ "mark.gone": "コンテキスト外",+ "mark.compacted": "圧縮前",+ "corner.pdf": "PDF {page} ページ",+ "corner.pdfAny": "PDF",+ "corner.browser": "ウェブ",+ "turn.n": "ターン {n}",+ "turn.earlier": "それ以前",+ "turn.all": "ターン {n} の全画像を送信",+ "turn.allEarlier": "それ以前の全画像を送信",+ "turn.shown": "ターン {n} の表示中の画像を送信",+ "turn.shownEarlier": "それ以前の表示中の画像を送信",+ "turn.pinAll": "ターン {n} の全画像を毎ターン送信",+ "turn.pinAllEarlier": "それ以前の全画像を毎ターン送信",+ "turn.pinShown": "ターン {n} の表示中の画像を毎ターン送信",+ "turn.pinShownEarlier": "それ以前の表示中の画像を毎ターン送信",+ "tile.open": "{id} をプレビュー",+ "preview.label": "画像プレビュー",+ "preview.close": "プレビューを閉じる",+ "preview.closeTitle": "閉じる(Esc)",+ "preview.pin": "毎ターン送信",+ "preview.send": "送信",+ "preview.loading": "読み込み中…",+ "preview.none": "この画像はプレビューできません",+ "preview.sameAs": "{id} と同じ画像",+ "preview.locked": "この画像は解除できず、毎ターン送信されます",+ "preview.gone": "この画像はコンテキスト外のため、送信されません",+ "preview.compacted": "圧縮前の画像:選択するとプラグインが再送します",+ "empty.title": "このタスクにはまだ画像がありません",+ "empty.text": "アップロードした画像や、モデルが表示・生成した画像が順番に並びます。",+ "empty.search": "一致する画像がありません",+ "notice.retry": "再試行",+ "notice.enabled": "有効にしました。Codex を再起動すると反映されます。",+ "notice.disabled": "無効にしました。Codex を再起動すると直接接続に戻ります。「プラグインを有効化」で元に戻せます。アンインストールする場合は、プラグイン画面から削除できます。",+ "notice.notEnabled": "プラグインが無効です。Codex が直接接続しているため、ここでの設定は反映されません。右上の「プラグインを有効化」を押して、Codex を再起動してください。",+ "notice.waiting": "このタスクはまだ始まっていません。最初のメッセージを送ると、パネルがそのタスクに切り替わります。",+ "notice.historyMissing": "このタスクの以前の履歴の一部が見つかりません。元のタスクが削除された可能性があるため、その部分の画像は表示されません。",+ "notice.engineDown": "プロキシが起動していないため、現在ここでの設定は反映されません。通常は Codex を終了して開き直すと復旧します。",+ "notice.skipped": "前回のリクエスト({time})では設定どおりに置換できず、画像をそのまま送信しました。理由:{reason}。",+ "notice.websocket": "設定変更時にこのターンはまだ実行中だったため、残りのリクエストには元の画像が含まれます。変更は次のメッセージから反映されます。",+ "notice.thinking": "このアカウントは思考履歴を検証します。前回のリクエスト({time})では設定に合わなくなった思考履歴を {count} 件省略したため、モデルが再思考してトークン消費が増える場合があります。",+ "reason.undecodable": "リクエストを展開できませんでした",+ "reason.unparsable": "リクエストを解析できませんでした",+ "reason.format": "リクエストの形式が想定と異なります",+ "reason.integer": "安全に書き換えられない大きさの整数が含まれています",+ "reason.index": "このタスクの履歴を読み取れませんでした",+ "reason.other": "書き換え中にエラーが発生しました",+ "reason.thinking": "このアカウントでは会話履歴の編集が思考履歴の検証で拒否されたため、元のリクエストを送信しました",+ "chooser.title": "複数のタスクが始まりました。どのタスクを表示しますか?",+ "chooser.untitled": "新しいタスク",+ "footer.hint": "全画像を送信します。除外するにはプレビューで選択を解除してください",+ "footer.hintAuto": "残りの画像はモデルが必要に応じて取得します",+ "auto.label": "自動選択",+ "auto.title": "有効にすると、以前のターンの画像は原則省略され、必要な画像をモデルが番号で取得します。プレビューで「毎ターン送信」にした画像は毎回送信されます",+ "error.load": "読み込みに失敗しました:{message}",+ "error.save": "保存に失敗しました:{message}",+ "error.switch": "切り替えに失敗しました:{message}",+ "error.enable": "有効化に失敗しました:{message}",+ "error.disable": "無効化に失敗しました:{message}",+ "error.noReply": "Codex から応答がありません",+ "error.call": "呼び出しに失敗しました"}}</script>@@ -548,7 +670,7 @@// ---- language (v0.1-14): Codex's interface language when the host context gives one, else the system's ----const MESSAGES = JSON.parse($("messages").textContent);- const langOf = (tag) => (typeof tag === "string" && tag.trim() ? (tag.trim().toLowerCase().startsWith("zh") ? "zh" : "en") : null);+ const langOf = (tag) => (typeof tag === "string" && tag.trim() ? (tag.trim().toLowerCase().startsWith("zh") ? "zh" : tag.trim().toLowerCase().startsWith("ja") ? "ja" : "en") : null);let lang = langOf(navigator.language) ?? "en";let langSource = "system";const template = (key, count) => {@@ -575,7 +697,7 @@}// The texts outside what render() draws, and the caches that hold words.function applyLanguage() {- document.documentElement.lang = lang === "zh" ? "zh-CN" : "en";+ document.documentElement.lang = lang === "zh" ? "zh-CN" : lang === "ja" ? "ja" : "en";document.title = t("page.title");$("refresh").setAttribute("aria-label", t("refresh"));$("search").placeholder = t("search.placeholder");@@ -937,7 +1059,7 @@if (Number.isNaN(date.getTime())) return "";const today = date.toDateString() === new Date().toDateString();const time = { hour: "2-digit", minute: "2-digit", hourCycle: "h23" };- return new Intl.DateTimeFormat(lang === "zh" ? "zh-CN" : "en-US", today ? time : { month: lang === "zh" ? "long" : "short", day: "numeric", ...time }).format(date);+ return new Intl.DateTimeFormat(lang === "zh" ? "zh-CN" : lang === "ja" ? "ja-JP" : "en-US", today ? time : { month: lang === "zh" ? "long" : "short", day: "numeric", ...time }).format(date);}// ---- the request card ----diff --git a/plugin/src/proxy.ts b/plugin/src/proxy.tsindex 60b6dd5..757f64d 100644--- a/plugin/src/proxy.ts+++ b/plugin/src/proxy.ts@@ -37,6 +37,7 @@ import { isEntryPoint } from "./entry.ts";import { currentLang } from "./language.ts";import { migrateDataOnce } from "./migrate-data.ts";import { say } from "./messages.ts";+import { claudePanelLanguage } from "./panel-language.ts";import { applyClaudeSelection, claudeImageFor, loadClaudePanelState, type ClaudePanelOptions } from "./panel-state.ts";import { claudeRequestStatsDirOf, claudeSelectionDirOf, dataDir, pixelCacheDirOf, proxyLogDirOf, selectionDirOf } from "./paths.ts";import { recordRequest } from "./request-stats.ts";@@ -533,12 +534,12 @@ export function claudePanelPage(dir = here): string {}export const PANEL_PAGE_CSP = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:; font-src data:; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'";-export function claudePanelApi(method: string, url: string, headers: IncomingHttpHeaders, body: string | null, options: ClaudePanelOptions = {}): { status: number; body: Json } {+export function claudePanelApi(method: string, url: string, headers: IncomingHttpHeaders, body: string | null, options: ClaudePanelOptions & { panelLocaleFiles?: readonly string[] } = {}): { status: number; body: Json } {if (!ownRequest(headers) || headers["x-cam-panel"] !== "1") return { status: 403, body: { error: "forbidden" } };const parsed = new URL(url, "http://localhost");const session = parsed.searchParams.get("session") ?? "";if (!SESSION_ID.test(session)) return { status: 400, body: { error: "no session" } };- const lang = currentLang();+ const lang = claudePanelLanguage({ settingsFiles: options.panelLocaleFiles });try {if (method === "GET" && parsed.pathname === "/__cam/claude/panel") return { status: 200, body: { ...loadClaudePanelState(session, options), lang } };if (method === "GET" && parsed.pathname === "/__cam/claude/image") {diff --git a/spike/scripts/panel-dev.ts b/spike/scripts/panel-dev.tsindex b3e9878..2afaee7 100644--- a/spike/scripts/panel-dev.ts+++ b/spike/scripts/panel-dev.ts@@ -430,7 +430,7 @@ const HOST = `<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><titwindow.addEventListener("message", async (event) => {const m = event.data;if (!m || event.source !== frame.contentWindow) return;- if (m.method === "ui/initialize") send({ id: m.id, result: { protocolVersion: "2026-01-26", hostInfo: { name: "panel-dev" }, hostCapabilities: { serverTools: {} }, hostContext: { theme, displayMode: "inline", locale: params.get("lang") === "en" ? "en-US" : "zh-CN", ...(sized ? { containerDimensions: dimensions() } : {}) } } });+ if (m.method === "ui/initialize") send({ id: m.id, result: { protocolVersion: "2026-01-26", hostInfo: { name: "panel-dev" }, hostCapabilities: { serverTools: {} }, hostContext: { theme, displayMode: "inline", locale: params.get("lang") === "en" ? "en-US" : params.get("lang") === "ja" ? "ja-JP" : "zh-CN", ...(sized ? { containerDimensions: dimensions() } : {}) } } });else if (m.method === "ui/notifications/size-changed") { if (sized) frame.style.height = Math.min(m.params.height, dimensions().maxHeight, cap) + "px"; }else if (m.method === "ui/notifications/initialized") { send({ method: "ui/notifications/tool-result", params: await call("cam_panel", {}) }); demo(); }else if (m.method === "tools/call") { const delay = params.get("slow") ? 900 : 60; const result = await call(m.params.name, m.params.arguments); setTimeout(() => send({ id: m.id, result }), delay); }diff --git a/spike/src/claude-panel.test.ts b/spike/src/claude-panel.test.tsindex adb6480..76c57a0 100644--- a/spike/src/claude-panel.test.ts+++ b/spike/src/claude-panel.test.ts@@ -22,14 +22,29 @@ const panelHeaders = { "x-cam-panel": "1", host: "127.0.0.1:17891" };function setup() {const home = mkdtempSync(join(tmpdir(), "cam-claude-home-"));const dataRoot = mkdtempSync(join(tmpdir(), "cam-claude-data-"));+ const desktopSettings = join(home, "desktop-config.json");+ writeFileSync(desktopSettings, JSON.stringify({ locale: "zh-CN" }));const { t, p1 } = usualSession();mkdirSync(join(home, "projects", "D--work"), { recursive: true });writeFileSync(join(home, "projects", "D--work", `${session}.jsonl`), t.records.map((record) => JSON.stringify(record)).join("\n") + "\n");- return { options: { home, dataRoot }, p1 };+ return { options: { home, dataRoot, panelLocaleFiles: [desktopSettings] }, p1 };}const get = (path: string, options: object) => claudePanelApi("GET", path, panelHeaders, "", options);const post = (path: string, change: object, options: object) => claudePanelApi("POST", path, panelHeaders, JSON.stringify(change), options);+test("Claude's panel follows its app setting without sharing the model or Codex language", () => {+ const { options } = setup();+ const originalTitle = get(`/__cam/claude/panel?session=${session}`, options).body.title;+ for (const [locale, expected] of [["ja-JP", "ja"], ["en-US", "en"], ["zh-CN", "zh"]]) {+ writeFileSync(options.panelLocaleFiles[0], JSON.stringify({ locale }));+ const answer = get(`/__cam/claude/panel?session=${session}`, options);+ assert.equal(answer.body.lang, expected);+ assert.equal(answer.body.title, originalTitle);+ assert.equal(post(`/__cam/claude/select?session=${session}`, { checkAll: true }, options).body.lang, expected);+ }+ assert.equal(process.env.CAM_LANG, "zh", "the model's language remains untouched");+});+test("under Claude Code only the fetch tool is listed for the model", () => {assert.deepEqual(claudeToolsFor("zh").map((tool) => tool.name), ["cam_view_image"]);});@@ -132,3 +147,25 @@ test("the panel page is the Codex panel.html with the engine bridge before its oconst own = page.indexOf("const post = (message) => (window.camHost");assert.ok(bridge > 0 && own > bridge);});++test("the Claude browser bridge uses the app language and notifies an already open panel when it changes", async () => {+ const script = readFileSync(new URL("../../plugin/src/panel-web.js", import.meta.url), "utf8");+ let language = "ja";+ const messages: any[] = [];+ const window = {+ innerHeight: 700,+ matchMedia: () => ({ matches: false, addEventListener() {} }),+ addEventListener() {},+ dispatchEvent: (event: MessageEvent) => { messages.push(event.data); return true; },+ camHost: null as any,+ };+ new Function("window", "navigator", "location", "fetch", "MessageEvent", script)(window, { language: "en-US" }, { search: `?session=${session}` }, async () => ({ ok: true, json: async () => ({ lang: language }) }), MessageEvent);+ const flush = () => new Promise(resolve => setImmediate(resolve));+ window.camHost.post({ id: 1, method: "ui/initialize", params: {} });+ await flush();+ assert.equal(messages.find(message => message.id === 1).result.hostContext.locale, "ja");+ language = "en";+ window.camHost.post({ id: 2, method: "tools/call", params: { name: "cam_panel" } });+ await flush();+ assert.ok(messages.some(message => message.method === "ui/notifications/host-context-changed" && message.params.locale === "en"));+});diff --git a/spike/src/panel-language.test.ts b/spike/src/panel-language.test.tsnew file mode 100644index 0000000..cb6ba36--- /dev/null+++ b/spike/src/panel-language.test.ts@@ -0,0 +1,68 @@+// Panel-only localization: the host selects en/zh/ja; Claude reads its own desktop setting, never Codex's language.+import assert from "node:assert/strict";+import { mkdtempSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";+import test from "node:test";++const page = readFileSync(new URL("../../plugin/src/panel.html", import.meta.url), "utf8");+const texts = JSON.parse(/<script type="application\/json" id="messages">([\s\S]*?)<\/script>/.exec(page)![1]);++test("the panel recognizes Japanese host locales without changing the model language parser", async () => {+ const expression = /const langOf = ([^;]+);/.exec(page)![1];+ const panelLangOf = new Function(`return (${expression})`)();+ assert.deepEqual(["en-US", "zh-CN", "zh-TW", "ja", "ja-JP", "fr-FR"].map(panelLangOf), ["en", "zh", "zh", "ja", "ja", "en"]);+ const { langOf } = await import("../../plugin/src/language.ts");+ assert.equal(langOf("ja-JP"), "en", "Japanese panel support must not extend the model's existing language contract");+});++test("every Japanese panel label exists and keeps the same interpolation values", () => {+ assert.ok(texts.ja, "a Japanese text table is required");+ const base = (table: Record<string,string>) => Object.keys(table).filter(k => !k.endsWith("_one")).sort();+ const values = (text: string) => [...text.matchAll(/\{(\w+)\}/g)].map(m => m[1]).sort();+ assert.deepEqual(base(texts.ja), base(texts.zh));+ for (const key of base(texts.zh)) assert.deepEqual(values(texts.ja[key]), values(texts.zh[key]), key);+ assert.equal(texts.ja["auto.label"], "自動選択");+});++test("Claude's fallback pane also has a complete Japanese interface", () => {+ const mod = readFileSync(new URL("../../hooks/register.js", import.meta.url), "utf8");+ const words = new Function(`return (${/const WORDS = (\{[\s\S]*?\n\})/.exec(mod)![1]})`)();+ assert.ok(words.ja, "the fallback pane must not fall back to Chinese for Japanese users");+ assert.deepEqual(Object.keys(words.ja).sort(), Object.keys(words.en).sort());+ assert.deepEqual(Object.keys(words.ja.routing).sort(), Object.keys(words.en.routing).sort());+ assert.equal(words.ja.copy, "リンクをコピー");+});++test("Claude uses its own locale, rereads changes, and leaves the settings read-only", async () => {+ const { claudePanelLanguage } = await import("../../plugin/src/panel-language.ts");+ const root = mkdtempSync(join(tmpdir(), "cam-panel-locale-"));+ const config = join(root, "config.json");+ const options = { settingsFiles: [config], env: { LANG: "en_US.UTF-8", CAM_LANG: "zh" }, home: root };+ const set = (locale: unknown) => writeFileSync(config, JSON.stringify({ locale, unrelated: "preserve" }));+ set("ja-JP");+ const original = readFileSync(config, "utf8");+ assert.equal(claudePanelLanguage(options), "ja");+ assert.equal(readFileSync(config, "utf8"), original);+ set("zh-CN"); assert.equal(claudePanelLanguage(options), "zh");+ set("en-US"); assert.equal(claudePanelLanguage(options), "en");+ set("fr-FR"); assert.equal(claudePanelLanguage(options), "en");+ writeFileSync(config, "{partial"); assert.equal(claudePanelLanguage(options), "en");+ set(null); assert.equal(claudePanelLanguage(options), "en");+});++test("Claude desktop settings are located for Windows, macOS and Linux", async () => {+ const { claudePanelLanguage } = await import("../../plugin/src/panel-language.ts");+ const home = mkdtempSync(join(tmpdir(), "cam-desktop-locale-"));+ const local = join(home, "local"), roaming = join(home, "roaming"), xdg = join(home, "xdg");+ const cases = [+ { platform: "win32", env: { LOCALAPPDATA: local, APPDATA: roaming }, path: join(local, "Claude-Data", "claude_testpublisher", "config.json") },+ { platform: "darwin", env: {}, path: join(home, "Library", "Application Support", "Claude", "config.json") },+ { platform: "linux", env: { XDG_CONFIG_HOME: xdg }, path: join(xdg, "Claude", "config.json") },+ ] as const;+ for (const item of cases) {+ mkdirSync(join(item.path, ".."), {recursive: true});+ writeFileSync(item.path, JSON.stringify({locale: "ja-JP"}));+ assert.equal(claudePanelLanguage({...item, home}), "ja", item.platform);+ }+});diff --git a/spike/src/panel-state.test.ts b/spike/src/panel-state.test.tsindex 33c8c18..6026563 100644--- a/spike/src/panel-state.test.ts+++ b/spike/src/panel-state.test.ts@@ -444,4 +444,19 @@ test("the image preview supports Ctrl+wheel zoom and preserves keyboard and backviewer.dispatchEvent({ type: "click", target: viewerStage });assert.deepEqual([viewer.hidden, documentObj.activeElement], [true, tile2], "backdrop click closes and restores focus to opening tile");++ // Host language changes only translate panel chrome; the session title is content.+ const hostLocale = (locale: string) => {+ for (const fn of winListeners.get("message") ?? []) fn({ data: { method: "ui/notifications/host-context-changed", params: { locale } } });+ };+ hostLocale("ja-JP");+ assert.equal(byId.get("search")!.placeholder, "画像の内容や、そのときの言葉");+ assert.equal(documentObj.documentElement.lang, "ja");+ assert.equal(byId.get("title")!.textContent, "Focus test");+ hostLocale("zh-CN");+ assert.equal(byId.get("search")!.placeholder, "画面,或你当时说过的话");+ assert.equal(byId.get("title")!.textContent, "Focus test");+ hostLocale("en-US");+ assert.equal(byId.get("search")!.placeholder, "What it shows, or what you said then");+ assert.equal(byId.get("title")!.textContent, "Focus test");});