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
refactor(language): the core picks the language, Codex adds its setting
chipfighterabe2dda3bf32
diff --git a/AGENTS.md b/AGENTS.mdindex 7ef1770..9d85e01 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -30,7 +30,7 @@ Context Attachment Manager(上下文素材管理器,2026-10-11 前叫 Codex- 先在 Windows 上开发和测试。技术栈用 TypeScript/Node。- 界面开发:Claude 自己截图检查效果;做到界面的关键节点时,截图给用户看,停下来等反馈再继续(用户 2026-09-24 确认)。- 测试时调用模型一律用 `gpt-6-sol`,推理强度 `low`,包括脚本自测和桌面版测试,为了省 token(用户 2026-09-24 要求)。-- 界面和提示文字分简体中文、英文两份:面板的在 `plugin/src/panel/panel.html` 的文字表里,插件服务和命令行的在 `plugin/src/messages.ts`。新增或修改文字时两份一起改,单元测试会检查条目一一对应。改发给模型的占位符和说明(`plugin/src/core/words.ts`)时,中文、英文(`--lang en`)各跑一次 `spike/src/v01-placeholder-selftest.ts`(用户 2026-09-25 要求)和 `spike/src/v01-needs-selftest.ts`(没有名字的工具截图全部取消后,模型能不能按编号要图、面板能不能认出来;用户 2026-09-26 要求);改的是自动选图的文字(自动版的占位符和说明、`cam_view_image` 的说明和返回的文字)时,再跑 `spike/src/v03-auto-selftest.ts`(模型该取图时会不会取、不该取时会不会不取;用户 2026-10-06 要求);改的是特征行说明时,再跑 `spike/src/v08-features-selftest.ts`(模型会不会给新图写特征行、照原话记评价、正文里不提,压缩后能不能靠特征行拿对图;v0.8);改的是压缩后放回的说明和清单时,再跑 `spike/src/v10-compaction-selftest.ts`(Codex 压缩之后,模型能不能靠清单认出之前的图、要看原图时按编号取对;v0.10)。这些自测三个 GPT-6 模型都要跑:`gpt-6-sol`、`gpt-6-luna`、`gpt-6-astra`,推理强度 low,用环境变量 `CAM_TEST_MODEL` 切换(用户 2026-09-28 要求)。自测在用户的 Codex 里建的任务,测完由脚本自动归档,不留给用户手动整理(用户 2026-09-28 要求);遗留的可以用 `spike/scripts/archive-test-threads.ts` 归档。+- 界面和提示文字分简体中文、英文两份:面板的在 `plugin/src/panel/panel.html` 的文字表里,插件服务和命令行的在 `plugin/src/core/messages.ts`。新增或修改文字时两份一起改,单元测试会检查条目一一对应。改发给模型的占位符和说明(`plugin/src/core/words.ts`)时,中文、英文(`--lang en`)各跑一次 `spike/src/v01-placeholder-selftest.ts`(用户 2026-09-25 要求)和 `spike/src/v01-needs-selftest.ts`(没有名字的工具截图全部取消后,模型能不能按编号要图、面板能不能认出来;用户 2026-09-26 要求);改的是自动选图的文字(自动版的占位符和说明、`cam_view_image` 的说明和返回的文字)时,再跑 `spike/src/v03-auto-selftest.ts`(模型该取图时会不会取、不该取时会不会不取;用户 2026-10-06 要求);改的是特征行说明时,再跑 `spike/src/v08-features-selftest.ts`(模型会不会给新图写特征行、照原话记评价、正文里不提,压缩后能不能靠特征行拿对图;v0.8);改的是压缩后放回的说明和清单时,再跑 `spike/src/v10-compaction-selftest.ts`(Codex 压缩之后,模型能不能靠清单认出之前的图、要看原图时按编号取对;v0.10)。这些自测三个 GPT-6 模型都要跑:`gpt-6-sol`、`gpt-6-luna`、`gpt-6-astra`,推理强度 low,用环境变量 `CAM_TEST_MODEL` 切换(用户 2026-09-28 要求)。自测在用户的 Codex 里建的任务,测完由脚本自动归档,不留给用户手动整理(用户 2026-09-28 要求);遗留的可以用 `spike/scripts/archive-test-threads.ts` 归档。- 分工:Claude 维护 `docs/` 下的规格和方案,并负责开发和测试(阶段 0 的 T0–T2 由 Codex 完成;测试需要在 Codex 之外启动 app-server,所以从 T3 起改由 Claude 执行)。其他协作者不修改 spec.md 和 design.md。## Git 规范diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 13c08ba..7dcd947 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -23,7 +23,7 @@ Bug reports, ideas and pull requests are all welcome. For a bug, an [issue](http- Install from source into your Codex: quit Codex, run `cam install` in the repository (`./cam install` on macOS and Linux), then start Codex. `cam status` shows the installation, `cam uninstall` removes it. Run `cam install` again after changing runtime code, so Codex's copy of the plugin is updated.- Run the tests with Node 24 or later: `cd spike && node --test`. CI runs them on Windows, macOS and Linux, then installs the plugin with Codex's CLI and runs the install and uninstall scripts.- Work on the panel without Codex: `node spike/scripts/panel-dev.ts`, then open `http://127.0.0.1:17895/?solo=1`, or `?solo=1&thread=v08` for a task with the model's notes (add `&lang=en` for English). The page uses synthetic images and a temporary Codex folder, so your real data is never read or changed.-- Text in the panel and the command line comes in English and Simplified Chinese: the panel's in the string table of `plugin/src/panel/panel.html`, the rest in `plugin/src/messages.ts`. Change both; a unit test checks that they match.+- Text in the panel and the command line comes in English and Simplified Chinese: the panel's in the string table of `plugin/src/panel/panel.html`, the rest in `plugin/src/core/messages.ts`. Change both; a unit test checks that they match.- When you change the text the model sees (`plugin/src/core/words.ts`), run the self-tests in `spike/src/v01-placeholder-selftest.ts` and `spike/src/v01-needs-selftest.ts`, and for Auto-select's wording `spike/src/v03-auto-selftest.ts`, in Chinese and with `--lang en`; `spike/src/v07-children-selftest.ts` covers subagents and side chats, and `spike/src/v08-features-selftest.ts` the model's notes, including after a compaction. They start their own engine and app-server, use your Codex account, and archive the test tasks they create.## Pull requestsdiff --git a/docs/design.md b/docs/design.mdindex 2b348b7..c285fc6 100644--- a/docs/design.md+++ b/docs/design.md@@ -16,7 +16,7 @@另一条路线是在新任务里重建历史(阶段 0 验证过,技术上可行)。没有采用,因为用户要在同一个任务里看到连续的对话,见 [history/v0.1/phase0-report.md](history/v0.1/phase0-report.md)。-v0.11 起代码分成三层([v0.11/plan.md](v0.11/plan.md)):`core/` 是不认识任何平台的核心,`panel/` 是面板,`adapters/<平台>/` 是各平台的接入;`plugin/src` 顶层放入口(`plugin-server.ts`、`proxy.ts`、`cam.ts`)和还没拆完的文件。分层规则由 `spike/src/layers.test.ts` 检查。+v0.11 起代码分成三层([v0.11/plan.md](v0.11/plan.md)):`core/` 是不认识任何平台的核心,`panel/` 是面板,`adapters/<平台>/` 是各平台的接入;`plugin/src` 顶层只放入口(`plugin-server.ts`、`proxy.ts`、`cam.ts`)和引擎的生命周期(`engine.ts`)。分层规则由 `spike/src/layers.test.ts` 检查。| 部分 | 代码(`plugin/src`) | 作用 ||---|---|---|@@ -26,7 +26,7 @@ v0.11 起代码分成三层([v0.11/plan.md](v0.11/plan.md)):`core/` 是不| 任务索引 | `adapters/codex/thread-index.ts`、`adapters/codex/children.ts`、`adapters/protocols/openai-responses/images.ts`、`core/images.ts`、`core/session.ts`、`core/pixels.ts`、`core/thumbnail.ts`、`core/png.ts`、`adapters/codex/thread-names.ts` | 从 Codex 的任务记录里只读地找出图片和它的来源、编号、生成缩略图、读任务名 || 改写 | `core/plan.ts`、`core/words.ts`、`adapters/protocols/openai-responses/rewrite.ts`、`core/selection.ts`、`adapters/codex/selection.ts`、`adapters/claude/selection.ts`、`core/request-stats.ts`、`core/notes.ts` | 每张图发不发、换成什么字(两个平台共用);发给模型的全部文字;把决定落进 Responses 请求;勾选状态;请求统计;特征行 || 接入和安装 | `adapters/codex/`:`codexconfig.ts`、`setup.ts`、`install.ts`、`codexcli.ts`、`plugin-cache.ts`、`binding.ts`;`cam.ts` | 管理 Codex 配置里带标记的块;用 Codex 的命令行装卸插件;保护升级中的旧运行文件;新任务绑定;`cam` 命令行 |-| 其他 | `language.ts`、`messages.ts`、`core/paths.ts`、`core/migrate-data.ts`、`core/entry.ts` | 语言、文字表、数据目录、旧数据迁移 |+| 其他 | `core/language.ts`、`adapters/codex/language.ts`、`core/messages.ts`、`core/paths.ts`、`core/migrate-data.ts`、`core/entry.ts` | 语言、文字表、数据目录、旧数据迁移 || Claude 接入(v0.4) | `hooks/register.js`(Mod,不在 `plugin/src`) | 把会话的请求地址指向引擎;`/cam` 打开面板(v0.6 起有图时自动打开);取图工具免确认 || Claude 会话索引和改写(v0.4) | `adapters/claude/claude-index.ts`、`adapters/claude/claude-rewrite.ts`、`adapters/protocols/anthropic-messages/rewrite.ts` | 从 Claude Code 的会话记录找图、编号,把请求里的图对上记录;把决定落进 Anthropic Messages 请求 || Claude 思考记录和提示缓存(v0.4、v0.10) | `adapters/protocols/anthropic-messages/thinking.ts`、`adapters/protocols/anthropic-messages/cache.ts` | 账号校验思考记录时,去掉和实际发出的历史对不上的思考;改过历史后,让提示缓存仍能读到 |diff --git a/plugin/src/adapters/claude/engine.ts b/plugin/src/adapters/claude/engine.tsindex 50010cd..d8f210f 100644--- a/plugin/src/adapters/claude/engine.ts+++ b/plugin/src/adapters/claude/engine.ts@@ -8,7 +8,8 @@import type { IncomingHttpHeaders } from "node:http";import { decodeBody, encodeBody, hasUnsafeInteger } from "../../core/engine/transport.ts";import { claudeSelectionDirOf } from "../../core/paths.ts";-import { currentLang } from "../../language.ts";+import type { Lang } from "../../core/lang.ts";+import { currentLang } from "../../core/language.ts";import { claudeSelection } from "./selection.ts";import { stableIdsSince } from "../../core/selection.ts";import { awaitingLine } from "../../core/session.ts";@@ -81,7 +82,8 @@ export const LATE_STEP_MS = 100;// turn is the transcript's latest prompt: Claude Code writes it before it sends the request.// CAM_EXPERIMENT_BLOCK_BINDING (experiments only, docs/v0.4/tasks.md T04-01): asks Anthropic to check thinking with// that prefix_mismatch_behavior, as for an account created from 2026-08-31; the report names the beta header to add.-export function rewriteClaudeBody(original: Buffer, encoding: string | undefined, sessionId: string, dir = claudeSelectionDirOf(), home = claudeHome(), env = process.env, thinking: ThinkingRecord | null = null, previous: SentPrefix[] = []): { body: Buffer; report: Json; attempts: ClaudeAttempt[]; prefix?: SentPrefix } {+// v0.11: lang, the language of the text for the model; the engine passes the one the core and Codex's setting choose.+export function rewriteClaudeBody(original: Buffer, encoding: string | undefined, sessionId: string, dir = claudeSelectionDirOf(), home = claudeHome(), env = process.env, thinking: ThinkingRecord | null = null, previous: SentPrefix[] = [], lang: Lang = currentLang()): { body: Buffer; report: Json; attempts: ClaudeAttempt[]; prefix?: SentPrefix } {const asIs = (report: Json) => ({ body: original, report, attempts: [] });const decoded = decodeBody(original, encoding);if (!decoded) return asIs({ skipped: "undecodable body" });@@ -103,7 +105,6 @@ export function rewriteClaudeBody(original: Buffer, encoding: string | undefinedleaveOut = new Set(index.images.filter((image) => image.replaceable && image.turn !== null && image.turn < current && !pinned[image.key] && !awaiting.has(image.key)).map((image) => image.key));}const pixels = (ref: RequestImage) => (ref.key ? index.byKey.get(ref.key)?.pixelSha256 : undefined) ?? pixelHashOfData(ref, ref.block.source.data);- const lang = currentLang();// v0.5: after a compaction, the images from before it go back right after the summary (anthropic-messages/rewrite.ts): the ones// the user keeps sending (checked, or pinned with automatic selection) read from the transcript, the others as// placeholders. With any of those, the full note follows the summary, and later messages get only their short notes.diff --git a/plugin/src/adapters/codex/engine.ts b/plugin/src/adapters/codex/engine.tsindex c409230..903d199 100644--- a/plugin/src/adapters/codex/engine.ts+++ b/plugin/src/adapters/codex/engine.ts@@ -10,7 +10,7 @@ import type { IncomingHttpHeaders } from "node:http";import { join } from "node:path";import { decodeBody, encodeBody, hasUnsafeInteger } from "../../core/engine/transport.ts";import type { Described } from "../../core/words.ts";-import { currentLang } from "../../language.ts";+import { currentLang } from "./language.ts";import { effectiveSelection, sideChatSelection } from "./selection.ts";import { selectionDir } from "../../core/selection.ts";import { findImages, type ImageRef } from "../protocols/openai-responses/images.ts";diff --git a/plugin/src/adapters/codex/install.ts b/plugin/src/adapters/codex/install.tsindex 73dfd16..0b19dde 100644--- a/plugin/src/adapters/codex/install.ts+++ b/plugin/src/adapters/codex/install.ts@@ -6,8 +6,8 @@// Input: current texts and the user's persisted proxy variables. Output: next texts (envText null = delete the file).import { coversLoopback, disableMcpServer, disableProxy, enableNoProxy, enableProxy, noProxyValue } from "./codexconfig.ts";-import { systemLang } from "../../language.ts";-import { say } from "../../messages.ts";+import { systemLang } from "../../core/language.ts";+import { say } from "../../core/messages.ts";export const PLUGIN = "codex-attachment-manager";export const MARKETPLACE = "codex-attachment-manager";diff --git a/plugin/src/adapters/codex/language.ts b/plugin/src/adapters/codex/language.tsnew file mode 100644index 0000000..da5ba2e--- /dev/null+++ b/plugin/src/adapters/codex/language.ts@@ -0,0 +1,29 @@+// Purpose: v0.1-20 — Codex's own language setting (user 2026-09-26), 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. The language as Codex shows it is the core's choice+// (core/language.ts) with that setting (v0.11: split from language.ts, docs/v0.11/plan.md).+// Input: Codex's computer-use/config.json (read only). Output: "zh" | "en".++import { readFileSync } from "node:fs";+import { join } from "node:path";+import type { Lang } from "../../core/lang.ts";+import { currentLang as langWith, languageFileOf, rememberLang as rememberWith, type LangSource } from "../../core/language.ts";+import { codexHome } from "./codexconfig.ts";++// 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 const rememberLang = (lang: Lang, source: LangSource, file = languageFileOf(), setting = codexUiFileOf()): void => rememberWith(lang, source, file, codexUiLocale(setting));+export const currentLang = (file = languageFileOf(), setting = codexUiFileOf()): Lang => langWith(file, codexUiLocale(setting));diff --git a/plugin/src/cam.ts b/plugin/src/cam.tsindex aa4a169..f7e9ca9 100644--- a/plugin/src/cam.ts+++ b/plugin/src/cam.ts@@ -20,8 +20,9 @@ import { findCodexCli, runCodex } from "./adapters/codex/codexcli.ts";import { codexHome, MCP_BEGIN, noProxyStatus, proxyStatus } from "./adapters/codex/codexconfig.ts";import { buildOf, DEFAULT_PORT, engineHealth, ensureEngine } from "./engine.ts";import { isEntryPoint } from "./core/entry.ts";-import { codexUiLocale, currentLang, storedLang, systemLang } from "./language.ts";-import { say, type MessageKey } from "./messages.ts";+import { codexUiLocale, currentLang } from "./adapters/codex/language.ts";+import { storedLang, systemLang } from "./core/language.ts";+import { say, type MessageKey } from "./core/messages.ts";import { migrateDataOnce } from "./core/migrate-data.ts";import { MARKETPLACE, PLUGIN, PLUGIN_ID, pluginStatus } from "./adapters/codex/install.ts";import { applySelection, loadPanelState } from "./adapters/codex/panel.ts";diff --git a/plugin/src/language.ts b/plugin/src/core/language.tssimilarity index 60%rename from plugin/src/language.tsrename to plugin/src/core/language.tsindex df3136d..de38acf 100644--- a/plugin/src/language.ts+++ b/plugin/src/core/language.ts@@ -1,26 +1,23 @@// 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+// v0.1; Chinese of any region gets Simplified Chinese, every other language gets English). A panel learns the host'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. 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 }.+// v0.1-20 (user 2026-09-26) — the host's own language setting counts too (Codex: adapters/codex/language.ts). 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.+// v0.11: split from language.ts (docs/v0.11/plan.md); the host's setting comes in as `uiLocale`.+// 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": "…", "codexLocale": "zh-CN" | null }.import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";import { dirname, join } from "node:path";-import { codexHome } from "./adapters/codex/codexconfig.ts";-import { dataDir } from "./core/paths.ts";+import type { Lang } from "./lang.ts";+import { dataDir } from "./paths.ts";-import type { Lang } from "./core/lang.ts";-export type { Lang };-// codex: the panel got Codex's interface language; system: it only had the system's.+// codex: the panel got the host's interface language; system: it only had the system's.export type LangSource = "codex" | "system";-// codexLocale: Codex's language setting when the panel reported (absent in records from before v0.1-20).+// codexLocale: the host'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 {@@ -43,21 +40,6 @@ 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);@@ -73,8 +55,8 @@ 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(), setting = codexUiFileOf()): void {- const codexLocale = codexUiLocale(setting);+export function rememberLang(lang: Lang, source: LangSource, file = languageFileOf(), uiLocale: string | null = null): void {+ const codexLocale = uiLocale;const known = storedLang(file);if (known?.lang === lang && known.source === source && known.codexLocale === codexLocale) return;mkdirSync(dirname(file), { recursive: true });@@ -83,13 +65,13 @@ export function rememberLang(lang: Lang, source: LangSource, file = languageFilecache = null;}-export function currentLang(file = languageFileOf(), setting = codexUiFileOf()): Lang {+export function currentLang(file = languageFileOf(), uiLocale: string | null = null): Lang {const fixed = process.env.CAM_LANG;if (fixed === "zh" || fixed === "en") return fixed;- const codexLocale = codexUiLocale(setting);+ const codexLocale = uiLocale;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.+ // Otherwise the setting: no panel has reported yet, or the user has changed the host's language since.return langOf(codexLocale) ?? stored?.lang ?? systemLang();}diff --git a/plugin/src/messages.ts b/plugin/src/core/messages.tssimilarity index 99%rename from plugin/src/messages.tsrename to plugin/src/core/messages.tsindex a0746f4..c0d7b2b 100644--- a/plugin/src/messages.ts+++ b/plugin/src/core/messages.ts@@ -4,7 +4,7 @@// languages (a unit test checks it), so changing a text means changing both.// Input: a language and a key, with {name} values filled in. Output: strings.-import type { Lang } from "./language.ts";+import type { Lang } from "./lang.ts";const zh = {// Codex's tool list; the panel tool's title is the tab's title.diff --git a/plugin/src/plugin-server.ts b/plugin/src/plugin-server.tsindex 5e0437c..17a43c5 100644--- a/plugin/src/plugin-server.ts+++ b/plugin/src/plugin-server.ts@@ -31,8 +31,10 @@ import { bindThread, isUserThread, newThreads, resolveThread } from "./adapters/import { claudeStartedAt, loadClaudeIndex } from "./adapters/claude/claude-index.ts";import { DEFAULT_PORT, ensureEngine } from "./engine.ts";import { isEntryPoint } from "./core/entry.ts";-import { currentLang, langOf, rememberLang, type Lang } from "./language.ts";-import { say } from "./messages.ts";+import { currentLang, rememberLang } from "./adapters/codex/language.ts";+import { langOf } from "./core/language.ts";+import type { Lang } from "./core/lang.ts";+import { say } from "./core/messages.ts";import { migrateDataOnce } from "./core/migrate-data.ts";import { panelHtml } from "./panel/page.ts";import { applySelection, imageFor, loadPanelState } from "./adapters/codex/panel.ts";diff --git a/plugin/src/proxy.ts b/plugin/src/proxy.tsindex 06e8af0..ae1d0ae 100644--- a/plugin/src/proxy.ts+++ b/plugin/src/proxy.ts@@ -43,8 +43,8 @@ import { claudeRequestStatsDirOf, claudeSelectionDirOf, dataDir, pixelCacheDirOfimport { recordRequest } from "./core/request-stats.ts";import { readRoute, registerRoute, routeBaseUrl, routingPort, validateBaseUrl, type Platform } from "./core/routes.ts";import { buildOf, DEFAULT_PORT, ENGINE_SERVICE, engineHealth, versionOf, watchForCodex } from "./engine.ts";-import { currentLang } from "./language.ts";-import { say } from "./messages.ts";+import { currentLang } from "./adapters/codex/language.ts";+import { say } from "./core/messages.ts";import { ensureAutoDefault, ensureStableIds, selectionDir, stableIdsSince } from "./core/selection.ts";type Json = Record<string, any>;@@ -484,7 +484,7 @@ async function main(): Promise<void> {const original = Buffer.concat(chunks);const encoding = req.headers["content-encoding"] as string | undefined;const rewriteNow = (): { body: Buffer; report: Json; attempts?: ClaudeAttempt[]; prefix?: SentPrefix } => {- try { return claudeRewrite ? rewriteClaudeBody(original, encoding, claudeSession!, undefined, undefined, undefined, thinking, sentPrefixes.get(claudeSession!) ?? []) : rewriteBody(original, encoding, identity.threadId!, sessionsDir, selectionDir, identity.turnId, identity.forkedFrom); }+ try { return claudeRewrite ? rewriteClaudeBody(original, encoding, claudeSession!, undefined, undefined, undefined, thinking, sentPrefixes.get(claudeSession!) ?? [], currentLang()) : rewriteBody(original, encoding, identity.threadId!, sessionsDir, selectionDir, identity.turnId, identity.forkedFrom); }catch (error) { return { body: original, report: { skipped: `rewrite failed: ${String(error)}` } }; }};let out = rewriteNow();diff --git a/spike/src/eval-keyframes.ts b/spike/src/eval-keyframes.tsindex 14a695c..4a1990f 100644--- a/spike/src/eval-keyframes.ts+++ b/spike/src/eval-keyframes.ts@@ -31,7 +31,8 @@ import { fileURLToPath } from "node:url";import { AppServer, findBundledCodex } from "./appserver.ts";import { codexHome } from "../../plugin/src/adapters/codex/codexconfig.ts";import { engineHealth } from "../../plugin/src/engine.ts";-import { languageFileOf, rememberLang } from "../../plugin/src/language.ts";+import { languageFileOf } from "../../plugin/src/core/language.ts";+import { rememberLang } from "../../plugin/src/adapters/codex/language.ts";import { selectionDirOf } from "../../plugin/src/core/paths.ts";import { loadThreadIndex } from "../../plugin/src/adapters/codex/thread-index.ts";import { archiveThreads, png, TEST_EFFORT, TEST_MODEL, text } from "./testkit.ts";diff --git a/spike/src/language.test.ts b/spike/src/language.test.tsindex f4e8540..dc3174a 100644--- a/spike/src/language.test.ts+++ b/spike/src/language.test.ts@@ -9,8 +9,9 @@ import { tmpdir } from "node:os";import { dirname, join } from "node:path";import test from "node:test";import { fileURLToPath } from "node:url";-import { codexUiLocale, currentLang, langOf, rememberLang, storedLang, systemLang } from "../../plugin/src/language.ts";-import { MESSAGES, say } from "../../plugin/src/messages.ts";+import { codexUiLocale, currentLang, rememberLang } from "../../plugin/src/adapters/codex/language.ts";+import { langOf, storedLang, systemLang } from "../../plugin/src/core/language.ts";+import { MESSAGES, say } from "../../plugin/src/core/messages.ts";import { callTool, toolsFor } from "../../plugin/src/plugin-server.ts";import { OMISSION_NOTE, omissionNote, type Described } from "../../plugin/src/core/words.ts";import { rewriteItems } from "../../plugin/src/adapters/protocols/openai-responses/rewrite.ts";diff --git a/spike/src/layers.test.ts b/spike/src/layers.test.tsindex 8d047d1..e585a97 100644--- a/spike/src/layers.test.ts+++ b/spike/src/layers.test.ts@@ -1,10 +1,10 @@// Purpose: v0.11 — keeps the plugin's three layers apart (docs/v0.11/plan.md 3.6). The core imports only the core;// the panel only the core; a request-format translator (adapters/protocols) the core and other translators; a// platform (adapters/<name>) the core, the translators and its own files, and the panel when it shows one (Codex-// desktop, Claude Desktop). Files at the top of plugin/src are the entry points and the ones not sorted yet; they may+// desktop, Claude Desktop). Files at the top of plugin/src are the entry points and the engine's lifecycle; they may// import anything.-// PENDING lists the imports that still break a rule while the split goes on. It may only shrink: a new break fails,-// and so does an entry that no longer occurs, so the list never keeps a stale exception.+// PENDING lists imports allowed to break a rule for a while (empty once the v0.11 split was done). It may only shrink:+// a new break fails, and so does an entry that no longer occurs, so the list never keeps a stale exception.// Input: the source files of plugin/src. Output: test results.import assert from "node:assert/strict";import { readdirSync, readFileSync } from "node:fs";@@ -14,12 +14,7 @@ import { fileURLToPath } from "node:url";const src = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "plugin", "src");-const PENDING = new Set<string>([- "adapters/claude/engine.ts -> language.ts",- "adapters/codex/engine.ts -> language.ts",- "adapters/codex/install.ts -> language.ts",- "adapters/codex/install.ts -> messages.ts",-]);+const PENDING = new Set<string>([]);type Layer = "core" | "panel" | "protocols" | `adapter:${string}` | "top";diff --git a/spike/src/panel-language.test.ts b/spike/src/panel-language.test.tsindex 78e5bb3..2aeffab 100644--- a/spike/src/panel-language.test.ts+++ b/spike/src/panel-language.test.ts@@ -12,7 +12,7 @@ test("the panel recognizes Japanese host locales without changing the model langconst 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");+ const { langOf } = await import("../../plugin/src/core/language.ts");assert.equal(langOf("ja-JP"), "en", "Japanese panel support must not extend the model's existing language contract");});diff --git a/spike/src/v01-needs-selftest.ts b/spike/src/v01-needs-selftest.tsindex 1123b03..9b37b63 100644--- a/spike/src/v01-needs-selftest.ts+++ b/spike/src/v01-needs-selftest.ts@@ -18,7 +18,8 @@ import { fileURLToPath } from "node:url";import { AppServer, findBundledCodex } from "./appserver.ts";import { codexHome } from "../../plugin/src/adapters/codex/codexconfig.ts";import { engineHealth } from "../../plugin/src/engine.ts";-import { languageFileOf, rememberLang } from "../../plugin/src/language.ts";+import { languageFileOf } from "../../plugin/src/core/language.ts";+import { rememberLang } from "../../plugin/src/adapters/codex/language.ts";import { askedIn } from "../../plugin/src/panel/panel-state.ts";import { selectionDirOf } from "../../plugin/src/core/paths.ts";import { readRequestStats } from "../../plugin/src/core/request-stats.ts";diff --git a/spike/src/v01-placeholder-selftest.ts b/spike/src/v01-placeholder-selftest.tsindex 7bc65d9..1e9bf19 100644--- a/spike/src/v01-placeholder-selftest.ts+++ b/spike/src/v01-placeholder-selftest.ts@@ -17,7 +17,8 @@ import { fileURLToPath } from "node:url";import { AppServer, findBundledCodex } from "./appserver.ts";import { codexHome } from "../../plugin/src/adapters/codex/codexconfig.ts";import { engineHealth } from "../../plugin/src/engine.ts";-import { languageFileOf, rememberLang } from "../../plugin/src/language.ts";+import { languageFileOf } from "../../plugin/src/core/language.ts";+import { rememberLang } from "../../plugin/src/adapters/codex/language.ts";import { selectionDirOf } from "../../plugin/src/core/paths.ts";import { readRequestStats } from "../../plugin/src/core/request-stats.ts";import { writeSelection } from "../../plugin/src/core/selection.ts";diff --git a/spike/src/v03-auto-selftest.ts b/spike/src/v03-auto-selftest.tsindex c578298..e4c0000 100644--- a/spike/src/v03-auto-selftest.ts+++ b/spike/src/v03-auto-selftest.ts@@ -24,7 +24,9 @@ import { fileURLToPath } from "node:url";import { AppServer, findBundledCodex } from "./appserver.ts";import { codexHome } from "../../plugin/src/adapters/codex/codexconfig.ts";import { engineHealth } from "../../plugin/src/engine.ts";-import { languageFileOf, rememberLang, type Lang } from "../../plugin/src/language.ts";+import { languageFileOf } from "../../plugin/src/core/language.ts";+import { rememberLang } from "../../plugin/src/adapters/codex/language.ts";+import type { Lang } from "../../plugin/src/core/lang.ts";import { requestStatsDirOf, selectionDirOf } from "../../plugin/src/core/paths.ts";import { readRequestStats } from "../../plugin/src/core/request-stats.ts";import { writeSelection } from "../../plugin/src/core/selection.ts";diff --git a/spike/src/v07-children-selftest.ts b/spike/src/v07-children-selftest.tsindex a10ddf9..fcc7ddc 100644--- a/spike/src/v07-children-selftest.ts+++ b/spike/src/v07-children-selftest.ts@@ -21,7 +21,9 @@ import { fileURLToPath } from "node:url";import { AppServer, findBundledCodex } from "./appserver.ts";import { codexHome } from "../../plugin/src/adapters/codex/codexconfig.ts";import { engineHealth } from "../../plugin/src/engine.ts";-import { languageFileOf, rememberLang, type Lang } from "../../plugin/src/language.ts";+import { languageFileOf } from "../../plugin/src/core/language.ts";+import { rememberLang } from "../../plugin/src/adapters/codex/language.ts";+import type { Lang } from "../../plugin/src/core/lang.ts";import { loadPanelState } from "../../plugin/src/adapters/codex/panel.ts";import { requestStatsDirOf } from "../../plugin/src/core/paths.ts";import { readRequestStats } from "../../plugin/src/core/request-stats.ts";diff --git a/spike/src/v08-features-selftest.ts b/spike/src/v08-features-selftest.tsindex 13b99f9..d3df640 100644--- a/spike/src/v08-features-selftest.ts+++ b/spike/src/v08-features-selftest.ts@@ -24,7 +24,9 @@ import { fileURLToPath } from "node:url";import { AppServer, findBundledCodex } from "./appserver.ts";import { codexHome } from "../../plugin/src/adapters/codex/codexconfig.ts";import { engineHealth } from "../../plugin/src/engine.ts";-import { languageFileOf, rememberLang, type Lang } from "../../plugin/src/language.ts";+import { languageFileOf } from "../../plugin/src/core/language.ts";+import { rememberLang } from "../../plugin/src/adapters/codex/language.ts";+import type { Lang } from "../../plugin/src/core/lang.ts";import { sceneOf } from "../../plugin/src/core/notes.ts";import { loadThreadIndex } from "../../plugin/src/adapters/codex/thread-index.ts";import { archiveThreads, CORNER_IMAGES, png, runTurn, TEST_EFFORT, TEST_MODEL, text } from "./testkit.ts";diff --git a/spike/src/v10-compaction-selftest.ts b/spike/src/v10-compaction-selftest.tsindex f64d068..44f3444 100644--- a/spike/src/v10-compaction-selftest.ts+++ b/spike/src/v10-compaction-selftest.ts@@ -18,7 +18,9 @@ import { fileURLToPath } from "node:url";import { AppServer, findBundledCodex } from "./appserver.ts";import { codexHome } from "../../plugin/src/adapters/codex/codexconfig.ts";import { engineHealth } from "../../plugin/src/engine.ts";-import { languageFileOf, rememberLang, type Lang } from "../../plugin/src/language.ts";+import { languageFileOf } from "../../plugin/src/core/language.ts";+import { rememberLang } from "../../plugin/src/adapters/codex/language.ts";+import type { Lang } from "../../plugin/src/core/lang.ts";import { loadThreadIndex } from "../../plugin/src/adapters/codex/thread-index.ts";import { archiveThreads, CORNER_IMAGES, png, runTurn, says, TEST_EFFORT, TEST_MODEL, text } from "./testkit.ts";