From de7acd3dcb591bf38450db7840b3e2b739d102da Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 17 Oct 2026 19:37:10 +0800 Subject: [PATCH 1/3] feat(#3546): settings panel quick-field for outbound image downscale Expose the existing top-level imageRescale key as a checkbox in the web settings panel's quick fields (it was only reachable via raw JSON or BILI_IMAGE_RESCALE). Checked = default-on = key omitted; unchecked writes imageRescale:false. Hint names BILI_IMAGE_RESCALE_MAX_DIM. --- src/web/client.ts | 8 ++++++++ src/web/i18n.ts | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/web/client.ts b/src/web/client.ts index dfce0e086b..64e8c088c0 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -2177,6 +2177,7 @@ export const WEB_CLIENT = `(function () { const cp = compressOf(draft); dbg.inp.checked = draft.debug === true; ptRow.inp.checked = draft.passthrough === true; + imgRow.inp.checked = draft.imageRescale !== false; const pv = (cp && typeof cp.promptPack === "string") ? cp.promptPack : "default"; while (packSel.options.length > 0) packSel.removeChild(packSel.lastChild); ["default", "lean"].forEach((name) => { @@ -2256,6 +2257,13 @@ export const WEB_CLIENT = `(function () { qCtrls.push(ptRow.inp); ptRow.inp.addEventListener("change", () => commit((d) => { if (ptRow.inp.checked) d.passthrough = true; else delete d.passthrough; })); void ptRow.ctl; + const imgRow = row("quick-imgrescale", t("cfg.q_imgrescale")); + qCtrls.push(imgRow.inp); + imgRow.inp.addEventListener("change", () => commit((d) => { if (imgRow.inp.checked) delete d.imageRescale; else d.imageRescale = false; })); + const imgHint = document.createElement("span"); + imgHint.className = "dim small"; + imgHint.textContent = t("cfg.q_imgrescale_hint"); + imgRow.ctl.appendChild(imgHint); const packSel = document.createElement("select"); packSel.className = "field-input mono"; qCtrls.push(packSel); diff --git a/src/web/i18n.ts b/src/web/i18n.ts index dee2ee9f16..7c8fb0c49d 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -373,6 +373,8 @@ export const MESSAGES: Record> = { "cfg.quick_desc": "常用项点一点就改——每次改动实时同步到下方原始 JSON(只改这一个文件,不新增任何配置项);providers 表等高级结构直接用下面的 JSON", "cfg.q_debug": "调试日志(debug)", "cfg.q_passthrough": "透传模式(passthrough)——开启后不注入、不压缩,纯代理", + "cfg.q_imgrescale": "出站图片降采样(imageRescale)——大尺寸出站图片先缩小再发给模型,原图留存本地(默认开)", + "cfg.q_imgrescale_hint": "最长边阈值用环境变量 BILI_IMAGE_RESCALE_MAX_DIM 调(默认 1600)", "cfg.q_pack": "压缩提示词包(compress.promptPack)", "cfg.q_nudge": "压缩增长阈值 tokens(compress.nudgeGrowthTokens)", "cfg.q_nudge_step": "步进 5000", @@ -849,6 +851,8 @@ export const MESSAGES: Record> = { "cfg.quick_desc": "Toggle common options without touching JSON — every change syncs live into the raw editor below (same file, no new config fields); advanced structures like the providers table stay in the JSON", "cfg.q_debug": "Debug logging (debug)", "cfg.q_passthrough": "Passthrough mode (passthrough) — pure proxying, no injection, no compression", + "cfg.q_imgrescale": "Outbound image downscale (imageRescale) — large outbound images are shrunken before reaching the model; originals stay in local session storage (default on)", + "cfg.q_imgrescale_hint": "longest-edge threshold via env BILI_IMAGE_RESCALE_MAX_DIM (default 1600)", "cfg.q_pack": "Compression prompt pack (compress.promptPack)", "cfg.q_nudge": "Compress growth threshold tokens (compress.nudgeGrowthTokens)", "cfg.q_nudge_step": "step of 5000", From f04419ade3f7c3daff428bc6e4f8e7ac2a907a3f Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 17 Oct 2026 19:46:14 +0800 Subject: [PATCH 2/3] feat(#3546): rename read_original_image to acp_read_original_image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Aligns the newest injected tool with the acp_ prefix convention used by every bili tool added after the original three (acp_status/acp_cache/ acp_retrieve) so models and users recognize bili-injected tools at a glance. The feature is unreleased (still in the [Unreleased] batch), so the rename carries zero user-facing compatibility surface — no legacy name support added. Touches: READ_ORIGINAL_IMAGE_TOOL_NAME constant (all four wire shapes and every registration/dispatch site reuse it), model-visible annotation and error text in image-rescale.ts, comments, CONFIGURATION.md en/zh, the CHANGELOG [Unreleased] entry, test assertions (sorted tool-name lists re-sorted for the new position), and the wire-contract goldens regenerated via scripts/update-wire-contract-goldens.ts — only manifest-default.json and manifest-optin.json changed (kernel.json never pinned this host-side tool). --- CHANGELOG.md | 2 +- CONFIGURATION.md | 2 +- CONFIGURATION.zh-CN.md | 2 +- src/absorb.ts | 2 +- src/compress-tool.ts | 5 ++-- src/image-rescale.ts | 24 +++++++++---------- src/plugin.ts | 2 +- src/proxy-tool-result.ts | 2 +- src/server/handle.ts | 2 +- src/store.ts | 4 ++-- tests/cache-proof.test.ts | 2 +- tests/codex-official.test.ts | 2 +- .../wire-contract/manifest-default.json | 8 +++---- .../golden/wire-contract/manifest-optin.json | 8 +++---- tests/issue3400-image-rescale.test.ts | 22 ++++++++--------- tests/launcher-plugin-mode.test.ts | 4 ++-- tests/plugin-fork.test.ts | 2 +- tests/plugin-protocol.test.ts | 12 +++++----- tests/side-lane-invariants.test.ts | 6 ++--- tests/wire-contract.test.ts | 2 +- 20 files changed, 58 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3706816b69..9a07bc11a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ Versions follow the merge of a `*_release-v*` branch; CI publishes to npm on tag - **dsh desktop settings pane: the embed probe is admitted for the Electron scheme origin (#3513, desktop variant).** The dsh DESKTOP app renders its settings pane from the custom scheme origin `dsh-app://app` (not an http origin like dsh web). The #3514 fix echoed the requesting Origin — but the request never reached the echo: `isTrustedAdminOrigin` only accepts http/https origins, so the probe's `GET /__bili/?embed=1` died in the trust gate with a bare 403 and no `access-control-allow-origin` — the pane stayed on "正在连接 bili 代理…" forever (real-world console: "blocked by CORS policy … from origin 'dsh-app://app'"). The gate now admits exactly that one origin (scheme `dsh-app`, hostname `app`): browsers set the Origin header themselves and the `dsh-app` scheme only exists inside the dsh Electron app, so a website can never produce that Origin — while rebinding attacks still arrive with http/https attacker hostnames and stay rejected. Foreign hostnames under the same scheme (`dsh-app://evil`) and every other custom scheme stay 403; the existing #3514 echo then covers the response. - **dist is self-contained again: the zod leak from the jimp image-rescale lane is bundled away, with a build gate to keep it away (#3511 P0).** #3425 inlined jimp (pure-JS image encoder, devDependency), and jimp imports zod at module scope — leaking 16 STATIC `from"zod"` imports into `dist/index.js` and `dist/agent/pi-native.js`. Static imports resolve at module load with no degrade path, so installs that ship the package without its node_modules (dsh profile bare copies, thin plugin copies — the real dsh/pi plugin shapes) died with `ERR_MODULE_NOT_FOUND` and model traffic silently went direct, uncompressed. zod is now bundled like every other transitive of an inlined dependency (dist/index.js grows ~1.4 MB); the ONE sanctioned external consumer — the opencode V1 host interop, which wants the HOST's zod instance and already degrades when unresolvable — keeps its own runtime resolution through an opaque specifier. `npm run build` now fails on any static zod import surviving into dist (`scripts/check-dist-external-zod.mjs`). Verified: a bare `dist/` copy with zero node_modules runs `node dist/index.js --version` clean. - **dsh web settings panel: the embed pre-flight gets its CORS answer (#3513).** The #3100 pre-flight fetches `/__bili/?embed=1` CROSS-origin — the dsh web page lives on the host's port, the proxy on its own, and while both are loopback names (so the trusted-origin gate admits the request), a cors-mode fetch is only readable when the response carries `access-control-allow-origin`. It never did: the browser rejected the probe, the verdict never landed, and the pane stayed on "connecting to the bili proxy…" forever while the proxy itself (model traffic, iframe navigation) kept working. The embed-face GET now echoes the requesting Origin — a static HTML shell with no state, reachable only by origins the #115/#1537 gates already admitted; clients without an Origin header (curl, CLIs) see no header at all, and the DNS-rebinding gates are untouched. -- **Egress image downscale + `read_original_image` (#3400).** Redoes the image pre-compression removed in #3295 in simplified form — **behavior change**: since #3295 every image passed through byte-identical at original resolution; from this version on, large outbound images are sent SHRUNKEN by default. On every outbound request (after kernel folding, before protocol encoding, all protocols share one pass) an image whose longest edge exceeds 1600 px (`BILI_IMAGE_RESCALE_MAX_DIM`) or whose base64 body exceeds 100 KB is re-encoded fit-inside (never upscaled, original format kept) on an OUTBOUND COPY only — session storage keeps the original bytes byte-exact. A re-encode saving less than 20% of the bytes is discarded (keep-smaller), so small and low-benefit images pass through untouched; only PNG/JPEG/BMP are handled (pure-JS jimp encoder, zero native dependencies — sharp does not return). Each shrunken image carries a stable annotation beside it reporting current vs original size; lanes that register bili tools (proxy-injection lanes, plugin lanes via the plugin manifest) also get the tool named in the annotation — `read_original_image("mNNNNN")` returns the original bytes from local session storage — while tool-rejecting lanes (codex) get size-only notes and no tool. Tool results are structurally exempt from re-shrinking (zero-state loop guard against the #3266 guess-reject-resend disease). Output is deterministic (content-hash cached, one encode per unique image; same history → byte-identical outbound bodies) so upstream prefix caching is undisturbed. Observability: one log line per unique image (dims+bytes before/after) and one per original-image read (ref, sizes, session cumulative count+bytes) — no hard cap, the model was told the sizes. Knobs: `BILI_IMAGE_RESCALE` (`"0"`/`"false"` off; default on), `BILI_IMAGE_RESCALE_MAX_DIM` (default 1600, env-only), config-file key `imageRescale`. Legacy `compress.imageCompression.*` INERT warnings remain owned by #3344/#3355. +- **Egress image downscale + `acp_read_original_image` (#3400).** Redoes the image pre-compression removed in #3295 in simplified form — **behavior change**: since #3295 every image passed through byte-identical at original resolution; from this version on, large outbound images are sent SHRUNKEN by default. On every outbound request (after kernel folding, before protocol encoding, all protocols share one pass) an image whose longest edge exceeds 1600 px (`BILI_IMAGE_RESCALE_MAX_DIM`) or whose base64 body exceeds 100 KB is re-encoded fit-inside (never upscaled, original format kept) on an OUTBOUND COPY only — session storage keeps the original bytes byte-exact. A re-encode saving less than 20% of the bytes is discarded (keep-smaller), so small and low-benefit images pass through untouched; only PNG/JPEG/BMP are handled (pure-JS jimp encoder, zero native dependencies — sharp does not return). Each shrunken image carries a stable annotation beside it reporting current vs original size; lanes that register bili tools (proxy-injection lanes, plugin lanes via the plugin manifest) also get the tool named in the annotation — `acp_read_original_image("mNNNNN")` returns the original bytes from local session storage — while tool-rejecting lanes (codex) get size-only notes and no tool. Tool results are structurally exempt from re-shrinking (zero-state loop guard against the #3266 guess-reject-resend disease). Output is deterministic (content-hash cached, one encode per unique image; same history → byte-identical outbound bodies) so upstream prefix caching is undisturbed. Observability: one log line per unique image (dims+bytes before/after) and one per original-image read (ref, sizes, session cumulative count+bytes) — no hard cap, the model was told the sizes. Knobs: `BILI_IMAGE_RESCALE` (`"0"`/`"false"` off; default on), `BILI_IMAGE_RESCALE_MAX_DIM` (default 1600, env-only), config-file key `imageRescale`. Legacy `compress.imageCompression.*` INERT warnings remain owned by #3344/#3355. - **Lane-decisions 收尾:四处 B 类旁路迁入统一决策点 + nudgeOn 单点(#3482,承接 #3417)。** ①omp 身份戳通道(`stampPromptCacheKey` 的 `agent !== "omp"` 门)改为注册表属性 `stampsBodyPromptCacheKey`;OMP Cowork 直连传输的"是否可能"进注册表(`coworkTransportPossible`),逐请求真相仍由环境观察(`ompCoworkTransportBypassesFetch`)给出。②codex/claude-responses 的 instructions 指纹键控从散落头名比较收进 `WIRE_CLIENTS` 注册表(`instructionsFingerprintKeyed`;信号检测留在 session-id,决策表只在注册表)。③计费块(#2189)提取改由 `laneDecisions.billingBlockWanted` 门控:profile 声明(dsh)或 wire 观察到块任一成立即提取——证据优先,与 toolsReachable 同形状;零 wire 字节变更。④四份手抄 `willInjectNudge` 合取收敛为 `nudgeOn()` 九入参纯函数:responses 的两处有意差异(compaction-trigger 豁免、codex-intercept 健康窗)显式入参,openai/google 的冗余 `shouldInject` 合取被 `compressSurfaceOn` 吸收;1024 点布尔立方等价测试 + 四车道旧公式逐位对照钉死。结构守卫扩展:B 类站点禁裸 lane 名门控,`WIRE_CLIENTS` 注册表条目必须有 `matches()`。⑤HostProfile 注册表整体落在零导入叶子模块 `src/host-profiles.ts`(review 修正:首版让 agent 侧直接 import lane-decisions,preflight→kernel 整链被拖进 dist/agent/pi.js、omp.js,两个宿主扩展包体积翻倍;拆出后两者回到原尺寸,结构守卫钉死该模块必须无 import)。`wantsBillingBlock` 死属性落位为真实消费者(上述③)。dshLedgerFloorTokens 本无 lane 名查(issue 前提修正:#1729 守卫故意 identity-blind,#2193)——三处 ledger floor 调用点保持不动并在 PR 说明。 - **Lane decisions extracted to a single resolver (#3417, fixes #3401).** The four wire adapters each carried their own copy of the lane gates (`dshCompressSurfaceOff`, the dsh compact-rebase guard), and the copies drifted: a dsh profile that DOES declare `compress` on the wire still had the model-side compress surface dropped (#3401). New `src/server/lane-decisions.ts`: a `HostProfile` registry (the only place lane names are compared), per-request `WireObservation` (which bili tools this request actually declares), and `resolveLaneDecisions()` — the one gate the four prepares now consume. Observed reachability overrides the dsh host-scope default, so tool-carrying dsh profiles keep the nudge/standing prompt while bare dsh stays off (#3177 preserved). `biliToolsDeclaredOnWire` gained a named-tool variant (the nudge advertises `compress` specifically). Structural guard test pins that prepares carry no raw lane-name comparisons. The dsh native-compaction rebase gate on all four wires now reads the registry property `compactsClientSide`. - **Config epoch: stale effectiveConfig stamps are refused (incident class tracked as ⑥ on #2960).** Every wire request stamps the session's resolved config snapshot (`metadata.effectiveConfig`) — but that snapshot was only refreshed on the NEXT wire request, so tool-path readers (plugin tool API, status panels, nudge re-anchor) executed settings the user had already deleted from the config file, and with several instances on one machine a session could carry a foreign instance's stamp for days (the October externalSummary incident: a user-disabled summary chain kept running). The snapshot is now stamped with `metadata.effectiveConfigEpoch` — a content hash of the config file at resolution time. Readers refuse the snapshot when the epoch no longer matches the live file and re-resolve the file tier (global `compress.*`, including `externalSummary`) onto the base config instead; provider/model cascade levels are re-stamped by the session's next wire request. Epochs are content-keyed (byte-identical files validate cross-instance), legacy snapshots without an epoch keep the old merge semantics, forks inherit the epoch key, and the golden drives pin the new metadata digest. diff --git a/CONFIGURATION.md b/CONFIGURATION.md index e91e6d2da7..a738729299 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -539,7 +539,7 @@ Top-level keys that control how the proxy listens and behaves globally. - **Type:** boolean - **Default:** `true` - **Status:** ACTIVE -- **Description:** Master switch for the egress image downscale pass (#3295 removed the old arrival-time pass; #3400 re-adds it in simplified form). On every outbound request, after kernel folding and before protocol encoding, images whose longest edge exceeds `BILI_IMAGE_RESCALE_MAX_DIM` (default 1600) OR whose base64 body exceeds 100 KB are re-encoded fit-inside (never upscaled, original format kept) on an OUTBOUND COPY only — session storage keeps the original bytes byte-exact. A re-encode that saves less than 20% of the bytes is discarded (keep-smaller), so small/low-benefit images pass through untouched. Only PNG/JPEG/BMP are handled (pure-JS encoder, zero native dependencies); other formats pass through. Each shrunken image gets a stable annotation beside it reporting current vs original size; on lanes that register bili tools (proxy-injection lanes and plugin lanes via the plugin manifest) it also names `read_original_image("")`, which returns the original bytes from local session storage — codex-style lanes that reject injected tools get the size-only annotation and no tool. Results of `read_original_image` are structurally exempt from re-shrinking (the loop guard against the #3266 guess-reject-resend disease). Output is deterministic: the same input bytes always produce the same shrunken bytes and the same annotation text, so repeated resends of one history stay byte-stable and upstream prefix caching is undisturbed. One log line per unique image (content-hash cached; cache hits stay silent). Precedence: `BILI_IMAGE_RESCALE` env var (`"0"`/`"false"` disables; live-read, no restart) > this key > default on. +- **Description:** Master switch for the egress image downscale pass (#3295 removed the old arrival-time pass; #3400 re-adds it in simplified form). On every outbound request, after kernel folding and before protocol encoding, images whose longest edge exceeds `BILI_IMAGE_RESCALE_MAX_DIM` (default 1600) OR whose base64 body exceeds 100 KB are re-encoded fit-inside (never upscaled, original format kept) on an OUTBOUND COPY only — session storage keeps the original bytes byte-exact. A re-encode that saves less than 20% of the bytes is discarded (keep-smaller), so small/low-benefit images pass through untouched. Only PNG/JPEG/BMP are handled (pure-JS encoder, zero native dependencies); other formats pass through. Each shrunken image gets a stable annotation beside it reporting current vs original size; on lanes that register bili tools (proxy-injection lanes and plugin lanes via the plugin manifest) it also names `acp_read_original_image("")`, which returns the original bytes from local session storage — codex-style lanes that reject injected tools get the size-only annotation and no tool. Results of `acp_read_original_image` are structurally exempt from re-shrinking (the loop guard against the #3266 guess-reject-resend disease). Output is deterministic: the same input bytes always produce the same shrunken bytes and the same annotation text, so repeated resends of one history stay byte-stable and upstream prefix caching is undisturbed. One log line per unique image (content-hash cached; cache hits stay silent). Precedence: `BILI_IMAGE_RESCALE` env var (`"0"`/`"false"` disables; live-read, no restart) > this key > default on. ### `resign` diff --git a/CONFIGURATION.zh-CN.md b/CONFIGURATION.zh-CN.md index f45422c0ca..e38137c4e3 100644 --- a/CONFIGURATION.zh-CN.md +++ b/CONFIGURATION.zh-CN.md @@ -539,7 +539,7 @@ - **类型:** boolean - **默认值:** `true` - **状态:** ACTIVE -- **说明:** 出站图片降采样 pass 的总开关(#3295 删除了旧的入站时降采样;#3400 以简化形态重新引入)。每个出站请求在 kernel 折叠之后、协议编码之前,对最长边超过 `BILI_IMAGE_RESCALE_MAX_DIM`(默认 1600)**或** base64 体积超过 100 KB 的图片做 fit-inside 重编码(不放大、保留原格式),且只作用于**出站副本**——会话存储中的原始字节保持逐字节原样。重编码节省不足 20% 字节的结果直接丢弃(keep-smaller),小图与低收益图原样通过。仅处理 PNG/JPEG/BMP(纯 JS 编码器,零原生依赖);其他格式原样通过。每张被缩小的图片旁附一段稳定注释,报告当前与原图尺寸;在注册 bili 工具的车道(代理注入车道,以及经插件 manifest 注册的插件车道)中还会指明 `read_original_image("")`——它从本地会话存储取回原始字节;拒绝注入工具的车道(如 codex)只拿到报尺寸的注释、没有工具。`read_original_image` 的结果**结构性豁免**再次降采样(防 #3266「猜→拒→重发」循环复发的环锁)。输出确定性:同一输入字节永远产出同一缩小字节与同一注释文本,同一历史反复重发保持逐字节稳定,上游前缀缓存不受扰动。每张唯一图片记一条日志(内容 hash 缓存;缓存命中静默)。优先级:`BILI_IMAGE_RESCALE` 环境变量(`"0"`/`"false"` 关闭;实时读取,无需重启)> 本配置键 > 默认开启。 +- **说明:** 出站图片降采样 pass 的总开关(#3295 删除了旧的入站时降采样;#3400 以简化形态重新引入)。每个出站请求在 kernel 折叠之后、协议编码之前,对最长边超过 `BILI_IMAGE_RESCALE_MAX_DIM`(默认 1600)**或** base64 体积超过 100 KB 的图片做 fit-inside 重编码(不放大、保留原格式),且只作用于**出站副本**——会话存储中的原始字节保持逐字节原样。重编码节省不足 20% 字节的结果直接丢弃(keep-smaller),小图与低收益图原样通过。仅处理 PNG/JPEG/BMP(纯 JS 编码器,零原生依赖);其他格式原样通过。每张被缩小的图片旁附一段稳定注释,报告当前与原图尺寸;在注册 bili 工具的车道(代理注入车道,以及经插件 manifest 注册的插件车道)中还会指明 `acp_read_original_image("")`——它从本地会话存储取回原始字节;拒绝注入工具的车道(如 codex)只拿到报尺寸的注释、没有工具。`acp_read_original_image` 的结果**结构性豁免**再次降采样(防 #3266「猜→拒→重发」循环复发的环锁)。输出确定性:同一输入字节永远产出同一缩小字节与同一注释文本,同一历史反复重发保持逐字节稳定,上游前缀缓存不受扰动。每张唯一图片记一条日志(内容 hash 缓存;缓存命中静默)。优先级:`BILI_IMAGE_RESCALE` 环境变量(`"0"`/`"false"` 关闭;实时读取,无需重启)> 本配置键 > 默认开启。 ### `resign` diff --git a/src/absorb.ts b/src/absorb.ts index 38dfa50ba7..ff1cae483f 100644 --- a/src/absorb.ts +++ b/src/absorb.ts @@ -48,7 +48,7 @@ export function storeEffectiveAbsorb(session: Session, config: Config): void { export function isProxyToolFor(name: string, session: Session | undefined, config: Config): boolean { if (PROXY_TOOL_NAMES.has(name)) return true; - // #3400: read_original_image executes server-side on EVERY lane — even + // #3400: acp_read_original_image executes server-side on EVERY lane — even // where it is not registered in the manifest (codex) a hallucinated call // must never reach the client as an unsupported tool. if (name === READ_ORIGINAL_IMAGE_TOOL_NAME) return true; diff --git a/src/compress-tool.ts b/src/compress-tool.ts index e679fdf047..d31601f276 100644 --- a/src/compress-tool.ts +++ b/src/compress-tool.ts @@ -376,13 +376,14 @@ export const RULE_TOOL_OPENAI = { type: "function" as const, function: { name: R export const RULE_TOOL_RESPONSES = { type: "function" as const, name: RULE_TOOL_NAME, description: RULE_TOOL_DESCRIPTION, parameters: RULE_PARAM_SCHEMA }; export const RULE_TOOL_GOOGLE = { name: RULE_TOOL_NAME, description: RULE_TOOL_DESCRIPTION, parameters: RULE_PARAM_SCHEMA }; -// #3400: read_original_image — fetch the ORIGINAL full-resolution bytes of an +// #3400 (renamed to the acp_ prefix convention in #3546): acp_read_original_image — +// fetch the ORIGINAL full-resolution bytes of an // image whose egress copy was downscaled by the rescale pass (the [bili] note // beside the shrunken image quotes the mNNNNN ref). Host-side execution only // (never forwarded to the client — see isProxyToolFor); registration is // lane-gated at the manifest sites (proxy-injection lanes only, never codex), // while the pass itself runs on every lane (codex gets size-only notes). -export const READ_ORIGINAL_IMAGE_TOOL_NAME = "read_original_image"; +export const READ_ORIGINAL_IMAGE_TOOL_NAME = "acp_read_original_image"; const READ_ORIGINAL_IMAGE_TOOL_DESCRIPTION = "Read the ORIGINAL full-resolution image of a message whose picture was downscaled before reaching you. Beside each shrunken image there is a [bili] note quoting its mNNNNN ref and both sizes — pass that ref here. The original bytes are returned as an image attached to this result. The original can be much larger than the downscaled copy, so call this only when you actually need full-resolution detail (small text, colors, pixel alignment); the downscaled version is enough for most work."; const READ_ORIGINAL_IMAGE_PARAM_SCHEMA = { type: "object" as const, diff --git a/src/image-rescale.ts b/src/image-rescale.ts index 76f2437519..46dcad63bc 100644 --- a/src/image-rescale.ts +++ b/src/image-rescale.ts @@ -5,7 +5,7 @@ // only; session storage keeps the originals byte-exact (the wire received // them, the storage holds them — we never rewrite history). A stable // annotation rides beside each shrunken image telling the model both sizes -// and how to fetch the original (read_original_image, registered only on +// and how to fetch the original (acp_read_original_image, registered only on // lanes that support injected tools; codex gets sizes only). // // Design constraints (issue #3400): @@ -14,7 +14,7 @@ // text, so the outbound body is byte-stable across rounds for the same // history (the #3266 75%→28% cache-hit lesson). A process-lifetime hash // cache encodes each unique image once. -// - Structural loop guard: images carried by a read_original_image tool +// - Structural loop guard: images carried by a acp_read_original_image tool // result are NEVER re-shrunk (that exemption is what kills the #3266 // read→resend→re-shrink cycle). Zero state, survives restarts. // - Pure-JS encoder (jimp, optionalDependency loaded lazily at first use): @@ -190,7 +190,7 @@ export function buildRescaleNote(opts: { }): string { const head = `[bili] 本图已降采样:当前 ${opts.width}×${opts.height} / ${opts.kb}KB;原图 ${opts.origWidth}×${opts.origHeight} / ${opts.origKb}KB`; if (opts.ref !== undefined && opts.toolArmed) { - return `${head}(约 ${opts.ratio.toFixed(1)} 倍)。需要原分辨率细节(小字、颜色、对齐)时,调用 read_original_image("${opts.ref}") 读取原图。原图较大,按需读取。`; + return `${head}(约 ${opts.ratio.toFixed(1)} 倍)。需要原分辨率细节(小字、颜色、对齐)时,调用 acp_read_original_image("${opts.ref}") 读取原图。原图较大,按需读取。`; } return `${head}。`; } @@ -215,7 +215,7 @@ interface RescaleCtx { log: Logger; /** Longest-edge target; resolved from the knob by the caller. */ maxDim: number; - /** True when read_original_image is registered for this session's lane — + /** True when acp_read_original_image is registered for this session's lane — * the annotation then carries the invocation entry; otherwise (codex, * plugin mode) it reports sizes only. */ toolArmed: boolean; @@ -431,7 +431,7 @@ export async function applyImageRescalePass(messages: BiliMessage[], ctx: Rescal if (!imageRescaleEnabled()) return messages; const out: BiliMessage[] = []; for (const m of messages) { - // STRUCTURAL LOOP GUARD: a read_original_image result carries the + // STRUCTURAL LOOP GUARD: a acp_read_original_image result carries the // original bytes by design — re-shrinking it would recreate the #3266 // read→resend→re-shrink cycle. Zero state: the marker is the tool // name on the message itself. @@ -507,7 +507,7 @@ export async function applyImageRescaleItems(items: unknown[], ctx: RescaleCtx): for (const item of items) { const i = asPart(item); // Structural loop guard, item form: an output answering a - // read_original_image call carries the original image by design. + // acp_read_original_image call carries the original image by design. if (i && (i.type === "function_call_output" || i.type === "custom_tool_call_output") && typeof i.call_id === "string" && nameByCallId.get(i.call_id) === READ_ORIGINAL_IMAGE_TOOL_NAME) { @@ -551,12 +551,12 @@ export async function applyImageRescaleItems(items: unknown[], ctx: RescaleCtx): } // --------------------------------------------------------------------------- -// read_original_image execution. +// acp_read_original_image execution. // --------------------------------------------------------------------------- const REF_PATTERN = /^m\d{5,}$/; -/** Execute read_original_image: fetch the ORIGINAL bytes for a message ref +/** Execute acp_read_original_image: fetch the ORIGINAL bytes for a message ref * from the local session storage (incoming-image index + spill dir) and * return them as an image attachment — the tool result itself stays TEXT. * The caller attaches the bytes to an ephemeral carrier message whose @@ -568,18 +568,18 @@ export async function executeReadOriginalImage( ): Promise { const ref = typeof args.ref === "string" ? args.ref.trim() : ""; if (!REF_PATTERN.test(ref)) { - return toolFail(`read_original_image: invalid ref "${ref}" — pass the mNNNNN message ref quoted in the [bili] note beside the shrunken image.`); + return toolFail(`acp_read_original_image: invalid ref "${ref}" — pass the mNNNNN message ref quoted in the [bili] note beside the shrunken image.`); } const entries = session.incomingImageIndex?.get(ref); if (!entries || entries.length === 0) { - return toolFail(`read_original_image: no original image stored for ${ref} (it may no longer ride the conversation history). Work from the downscaled version you already have.`); + return toolFail(`acp_read_original_image: no original image stored for ${ref} (it may no longer ride the conversation history). Work from the downscaled version you already have.`); } const entry = entries[0]; let buf: Buffer; try { buf = await readFile(entry.path); } catch { - return toolFail(`read_original_image: the original for ${ref} was evicted from local storage; it becomes readable again while the image rides the resent history.`); + return toolFail(`acp_read_original_image: the original for ${ref} was evicted from local storage; it becomes readable again while the image rides the resent history.`); } const counterMeta = session.metadata.imageRescaleReads; const counter = counterMeta && typeof counterMeta === "object" @@ -588,7 +588,7 @@ export async function executeReadOriginalImage( counter.count += 1; counter.bytes += buf.length; session.metadata.imageRescaleReads = counter; - log("info", `[${session.id}] [image-rescale] read_original_image ${ref}: ${entry.width ?? "?"}x${entry.height ?? "?"}/${formatKb(buf.length)}KB session-cumulative ${counter.count} read(s)/${formatKb(counter.bytes)}KB`); + log("info", `[${session.id}] [image-rescale] acp_read_original_image ${ref}: ${entry.width ?? "?"}x${entry.height ?? "?"}/${formatKb(buf.length)}KB session-cumulative ${counter.count} read(s)/${formatKb(counter.bytes)}KB`); // The receipt always names the local spill path: on the loop/injection // lanes the bytes also ride an ephemeral carrier message (see the loop's // proxyResults handling), but on the plugin lane the string tool protocol diff --git a/src/plugin.ts b/src/plugin.ts index 8b9fa0b10c..cea3eef7b0 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -823,7 +823,7 @@ export function handlePluginManifest(res: import("node:http").ServerResponse, co const ccrOn = config.ccr?.enabled === true; const ccrName = config.ccr?.toolName ?? RETRIEVE_TOOL_NAME; const ccrTools = ccrOn ? retrieveToolsFor(ccrName) : undefined; - // #3400: read_original_image restores the full-resolution original of a + // #3400: acp_read_original_image restores the full-resolution original of a // downscaled image from local session storage. Same conservative #1192 // rule as acp_retrieve: advertised only while the base knob enables the // rescale pass (disabled ⇒ no [bili] note ever names it, so a registered diff --git a/src/proxy-tool-result.ts b/src/proxy-tool-result.ts index 9cdebc6957..343617a9e6 100644 --- a/src/proxy-tool-result.ts +++ b/src/proxy-tool-result.ts @@ -42,7 +42,7 @@ export interface ProxyToolResult { // `parse:missing-content`, `gate:cannot-anchor`) — outcome=refused alone // never says WHY in the [plugin] execution line. reason?: string; - // #3400: original image bytes restored by read_original_image — the loop + // #3400: original image bytes restored by acp_read_original_image — the loop // rides them as an ephemeral carrier message; plugin-lane hosts open the // local path named in the receipt text instead (string protocol). image?: { base64: string; mediaType: string }; diff --git a/src/server/handle.ts b/src/server/handle.ts index de34135e3f..8870b96918 100644 --- a/src/server/handle.ts +++ b/src/server/handle.ts @@ -1723,7 +1723,7 @@ async function handleRequest( // placeholder is ever emitted; regular compress/decompress folding is unaffected // (the codex lane simply keeps large tool results verbatim until they are folded). storeEffectiveCcr(session, opts.compress.injectTool && storeChannelOk && !(protocol === "responses" && isCodexClient(req.headers)) ? pluginCcrStamp : undefined); - // #3400: read_original_image arms where the model can actually reach + // #3400: acp_read_original_image arms where the model can actually reach // it — the injection lanes (proxy owns tool execution) or the plugin // lanes (the agent registers it natively from handlePluginManifest, // base-config gated like every other opt-in tool, #1192). Never on the diff --git a/src/store.ts b/src/store.ts index ea0862337e..9e24628e6b 100644 --- a/src/store.ts +++ b/src/store.ts @@ -58,13 +58,13 @@ export function ccrEnabled(session: Session | undefined): boolean { return effectiveCcr(session)?.enabled === true; } -// #3400: per-request stamp of the read_original_image TOOL registration gate. +// #3400: per-request stamp of the acp_read_original_image TOOL registration gate. // The rescale PASS itself runs on every lane (governed by the BILI_IMAGE_RESCALE // knob); only the manifest registration and the annotation's invocation entry // follow this stamp — codex/plugin lanes get size-only notes. const EFFECTIVE_IMAGE_RESCALE_KEY = "effectiveImageRescale"; -/** Stamp whether read_original_image may be registered for this session's +/** Stamp whether acp_read_original_image may be registered for this session's * lane (per-request; mirrors the storeEffectiveCcr site). */ export function storeEffectiveImageRescale(session: Session, armed: boolean | undefined): void { // Absent == not armed (imageRescaleToolArmed reads === true). Writing only the diff --git a/tests/cache-proof.test.ts b/tests/cache-proof.test.ts index b2b74343f6..46d42020ee 100644 --- a/tests/cache-proof.test.ts +++ b/tests/cache-proof.test.ts @@ -1015,7 +1015,7 @@ function runProof(wire: Wire, bodies: string[], urls: string[], ev: ProofEvents) } -// #3400: pin legacy wire economics - the default-on read_original_image tool +// #3400: pin legacy wire economics - the default-on acp_read_original_image tool // adds ~200 tokens per request, shifting this scenario's nudge timing so the // fold/rearm arithmetic moves by design. Fidelity here is compaction behavior, // not egress policy (tests/issue3400-image-rescale.test.ts covers that). diff --git a/tests/codex-official.test.ts b/tests/codex-official.test.ts index 86542b618a..ef0c225f76 100644 --- a/tests/codex-official.test.ts +++ b/tests/codex-official.test.ts @@ -130,7 +130,7 @@ test("Codex official transport preserves OAuth headers, decodes bodies, and reba // the injected tool set. assert.deepEqual( forwarded.tools.map((t: unknown) => (t as { name: string }).name), - ["shell", "compress", "decompress", "search_context", "acp_status", "acp_cache", "acp_rule", "acp_retrieve", "read_original_image"], + ["shell", "compress", "decompress", "search_context", "acp_status", "acp_cache", "acp_rule", "acp_retrieve", "acp_read_original_image"], ); const session = listSessions().find((candidate) => candidate.meta.label === sessionId); diff --git a/tests/golden/wire-contract/manifest-default.json b/tests/golden/wire-contract/manifest-default.json index ff56c1659e..e911e898d3 100644 --- a/tests/golden/wire-contract/manifest-default.json +++ b/tests/golden/wire-contract/manifest-default.json @@ -10,7 +10,7 @@ "search_context", "acp_status", "acp_cache", - "read_original_image" + "acp_read_original_image" ], "tools": { "anthropic": [ @@ -206,7 +206,7 @@ } }, { - "name": "read_original_image", + "name": "acp_read_original_image", "description": "Read the ORIGINAL full-resolution image of a message whose picture was downscaled before reaching you. Beside each shrunken image there is a [bili] note quoting its mNNNNN ref and both sizes — pass that ref here. The original bytes are returned as an image attached to this result. The original can be much larger than the downscaled copy, so call this only when you actually need full-resolution detail (small text, colors, pixel alignment); the downscaled version is enough for most work.", "input_schema": { "type": "object", @@ -432,7 +432,7 @@ { "type": "function", "function": { - "name": "read_original_image", + "name": "acp_read_original_image", "description": "Read the ORIGINAL full-resolution image of a message whose picture was downscaled before reaching you. Beside each shrunken image there is a [bili] note quoting its mNNNNN ref and both sizes — pass that ref here. The original bytes are returned as an image attached to this result. The original can be much larger than the downscaled copy, so call this only when you actually need full-resolution detail (small text, colors, pixel alignment); the downscaled version is enough for most work.", "parameters": { "type": "object", @@ -648,7 +648,7 @@ }, { "type": "function", - "name": "read_original_image", + "name": "acp_read_original_image", "description": "Read the ORIGINAL full-resolution image of a message whose picture was downscaled before reaching you. Beside each shrunken image there is a [bili] note quoting its mNNNNN ref and both sizes — pass that ref here. The original bytes are returned as an image attached to this result. The original can be much larger than the downscaled copy, so call this only when you actually need full-resolution detail (small text, colors, pixel alignment); the downscaled version is enough for most work.", "parameters": { "type": "object", diff --git a/tests/golden/wire-contract/manifest-optin.json b/tests/golden/wire-contract/manifest-optin.json index ebdb07b6b7..54507d9713 100644 --- a/tests/golden/wire-contract/manifest-optin.json +++ b/tests/golden/wire-contract/manifest-optin.json @@ -13,7 +13,7 @@ "absorb", "acp_rule", "acp_retrieve", - "read_original_image" + "acp_read_original_image" ], "tools": { "anthropic": [ @@ -275,7 +275,7 @@ } }, { - "name": "read_original_image", + "name": "acp_read_original_image", "description": "Read the ORIGINAL full-resolution image of a message whose picture was downscaled before reaching you. Beside each shrunken image there is a [bili] note quoting its mNNNNN ref and both sizes — pass that ref here. The original bytes are returned as an image attached to this result. The original can be much larger than the downscaled copy, so call this only when you actually need full-resolution detail (small text, colors, pixel alignment); the downscaled version is enough for most work.", "input_schema": { "type": "object", @@ -576,7 +576,7 @@ { "type": "function", "function": { - "name": "read_original_image", + "name": "acp_read_original_image", "description": "Read the ORIGINAL full-resolution image of a message whose picture was downscaled before reaching you. Beside each shrunken image there is a [bili] note quoting its mNNNNN ref and both sizes — pass that ref here. The original bytes are returned as an image attached to this result. The original can be much larger than the downscaled copy, so call this only when you actually need full-resolution detail (small text, colors, pixel alignment); the downscaled version is enough for most work.", "parameters": { "type": "object", @@ -836,7 +836,7 @@ }, { "type": "function", - "name": "read_original_image", + "name": "acp_read_original_image", "description": "Read the ORIGINAL full-resolution image of a message whose picture was downscaled before reaching you. Beside each shrunken image there is a [bili] note quoting its mNNNNN ref and both sizes — pass that ref here. The original bytes are returned as an image attached to this result. The original can be much larger than the downscaled copy, so call this only when you actually need full-resolution detail (small text, colors, pixel alignment); the downscaled version is enough for most work.", "parameters": { "type": "object", diff --git a/tests/issue3400-image-rescale.test.ts b/tests/issue3400-image-rescale.test.ts index e26528e0e3..a85f67d4b7 100644 --- a/tests/issue3400-image-rescale.test.ts +++ b/tests/issue3400-image-rescale.test.ts @@ -11,7 +11,7 @@ import type { ProxyOptions } from "../src/config.js"; // #3400: egress image rescale (simplified re-do of #3295's removal). Contract: // big images (>1600 longest edge or >100KB) are downscaled on the OUTBOUND // copy only; originals stay in session storage; the model is told both sizes -// beside the image; read_original_image returns the exact stored bytes and +// beside the image; acp_read_original_image returns the exact stored bytes and // its results are structurally exempt from re-shrinking (the #3266 loop guard). process.env.BILI_CONFIG_FILE = "/nonexistent/bili-issue3400-config.json"; @@ -84,7 +84,7 @@ test("big image shrunk: anthropic standalone gets copied block + adjacent note m assert.notEqual(out[0], input[0], "input object not mutated in place"); assert.equal(out[1].id, "acp_imgnote_msg_img_1"); assert.equal(out[1].role, "user"); - assert.match(String(out[1].text), /^\[bili\] 本图已降采样:当前 \d+×\d+ \/ \d+KB;原图 2400×1800 \/ \d+KB\(约 [\d.]+ 倍\)。需要原分辨率细节\(小字、颜色、对齐\)时,调用 read_original_image\("m12345"\) 读取原图。原图较大,按需读取。$/); + assert.match(String(out[1].text), /^\[bili\] 本图已降采样:当前 \d+×\d+ \/ \d+KB;原图 2400×1800 \/ \d+KB\(约 [\d.]+ 倍\)。需要原分辨率细节\(小字、颜色、对齐\)时,调用 acp_read_original_image\("m12345"\) 读取原图。原图较大,按需读取。$/); // original sidecar untouched in the input array assert.equal((input[0].rawAnthropicBlock as { source: { data: string } }).source.data, BIG.b64); }); @@ -154,7 +154,7 @@ test("openai singular image_url converts to plural parts with inline note", asyn assert.match(url, /^data:image\/png;base64,/); assert.notEqual(url, `data:image/png;base64,${BIG.b64}`); assert.equal(parts[1].type, "text"); - assert.match(String(parts[1].text), /read_original_image\("m20001"\)/); + assert.match(String(parts[1].text), /acp_read_original_image\("m20001"\)/); }); test("google inlineData shrunk, note appended to core text (never a raw text part)", async () => { @@ -169,7 +169,7 @@ test("google inlineData shrunk, note appended to core text (never a raw text par const parts = out[0].rawGoogleParts as Array<{ inlineData?: { data?: string } }>; assert.equal(parts.length, 1); assert.notEqual(parts[0].inlineData?.data, BIG.b64); - assert.match(String(out[0].text), /^hello\n\n\[bili\] 本图已降采样:.*read_original_image\("m30001"\)/); + assert.match(String(out[0].text), /^hello\n\n\[bili\] 本图已降采样:.*acp_read_original_image\("m30001"\)/); }); test("responses item: image url replaced, NO text part inside item, note rides separate message", async () => { @@ -189,7 +189,7 @@ test("responses item: image url replaced, NO text part inside item, note rides s assert.match(String(content[1].image_url), /^data:image\/png;base64,/); assert.notEqual(content[1].image_url, `data:image/png;base64,${BIG.b64}`); assert.equal(out[1].id, "acp_imgnote_msg_r"); - assert.match(String(out[1].text), /read_original_image\("m40001"\)/); + assert.match(String(out[1].text), /acp_read_original_image\("m40001"\)/); }); test("items walker (responses steady path): shrinks + inserts input_text note after the image", async () => { @@ -204,10 +204,10 @@ test("items walker (responses steady path): shrinks + inserts input_text note af assert.match(String(out[0].content[2].text), /^\[bili\] 本图已降采样:/); }); -test("items walker exemption: output answering read_original_image passes verbatim", async () => { +test("items walker exemption: output answering acp_read_original_image passes verbatim", async () => { const { session, ctx } = ctxFor("s-items-exempt"); const items = [ - { type: "function_call", call_id: "call_1", name: "read_original_image", arguments: '{"ref":"m12345"}' }, + { type: "function_call", call_id: "call_1", name: "acp_read_original_image", arguments: '{"ref":"m12345"}' }, { type: "function_call_output", call_id: "call_1", output: [{ type: "input_image", image_url: `data:image/png;base64,${BIG.b64}` }] }, ]; const out = (await applyImageRescaleItems(items, ctx)) as unknown[]; @@ -215,12 +215,12 @@ test("items walker exemption: output answering read_original_image passes verbat assert.equal(out[1], items[1], "exempt tool output must be the SAME object (untouched)"); }); -test("structural loop guard: carrier message with toolName read_original_image is never re-shrunk", async () => { +test("structural loop guard: carrier message with toolName acp_read_original_image is never re-shrunk", async () => { const { session, ctx } = ctxFor("s-guard"); const input: BiliMessage[] = [{ id: "acp_loop_r2_img_call_1", role: "user", contentType: "text", text: "[bili] 原图已读取,完整分辨率的原始图片如下。", - toolName: "read_original_image", imageBase64: BIG.b64, imageMediaType: "image/png", + toolName: "acp_read_original_image", imageBase64: BIG.b64, imageMediaType: "image/png", }]; const out = await applyImageRescalePass(input, ctx); assert.equal(out.length, 1); @@ -246,12 +246,12 @@ test("size-only note when the tool lane is not armed (codex/plugin lanes)", asyn const out = await applyImageRescalePass(input, ctx); assert.equal(out.length, 2); assert.match(String(out[1].text), /^\[bili\] 本图已降采样:当前 \d+×\d+ \/ \d+KB;原图 2400×1800 \/ \d+KB。$/); - assert.doesNotMatch(String(out[1].text), /read_original_image/); + assert.doesNotMatch(String(out[1].text), /acp_read_original_image/); }); test("buildRescaleNote: deterministic templates (full + size-only)", () => { const full = buildRescaleNote({ ref: "m12345", toolArmed: true, width: 1600, height: 1173, kb: 73, origWidth: 2140, origHeight: 1560, origKb: 317, ratio: 4.3 }); - assert.equal(full, "[bili] 本图已降采样:当前 1600×1173 / 73KB;原图 2140×1560 / 317KB(约 4.3 倍)。需要原分辨率细节(小字、颜色、对齐)时,调用 read_original_image(\"m12345\") 读取原图。原图较大,按需读取。"); + assert.equal(full, "[bili] 本图已降采样:当前 1600×1173 / 73KB;原图 2140×1560 / 317KB(约 4.3 倍)。需要原分辨率细节(小字、颜色、对齐)时,调用 acp_read_original_image(\"m12345\") 读取原图。原图较大,按需读取。"); assert.equal(full, buildRescaleNote({ ref: "m12345", toolArmed: true, width: 1600, height: 1173, kb: 73, origWidth: 2140, origHeight: 1560, origKb: 317, ratio: 4.3 })); const sizeOnly = buildRescaleNote({ ref: "m12345", toolArmed: false, width: 1600, height: 1173, kb: 73, origWidth: 2140, origHeight: 1560, origKb: 317, ratio: 4.3 }); assert.equal(sizeOnly, "[bili] 本图已降采样:当前 1600×1173 / 73KB;原图 2140×1560 / 317KB。"); diff --git a/tests/launcher-plugin-mode.test.ts b/tests/launcher-plugin-mode.test.ts index 4e98c07ee3..ca3f431079 100644 --- a/tests/launcher-plugin-mode.test.ts +++ b/tests/launcher-plugin-mode.test.ts @@ -338,7 +338,7 @@ test("mcp stdio shell: manifest → tools/list → tools/call forwards to the pl const init = byId(1) as { result?: { serverInfo?: { name?: string } } }; assert.equal(init.result?.serverInfo?.name, "bili"); const tools = byId(2) as { result?: { tools?: { name: string }[] } }; - assert.deepEqual(tools.result?.tools?.map((t) => t.name).sort(), ["acp_cache", "acp_status", "compress", "decompress", "read_original_image", "search_context"]); + assert.deepEqual(tools.result?.tools?.map((t) => t.name).sort(), ["acp_cache", "acp_read_original_image", "acp_status", "compress", "decompress", "search_context"]); const call = byId(3) as { result?: { content?: { text?: string }[]; isError?: boolean } }; assert.equal(call.result?.isError, false); assert.match(call.result?.content?.[0]?.text ?? "", /CONTEXT BREAKDOWN/, "acp_status result forwarded verbatim"); @@ -409,7 +409,7 @@ test("mcp stdio shell (codex style): BILI_CONVERSATION_ID self-register → head const byId = (n: number): Record => JSON.parse(lines.find((l) => (JSON.parse(l) as { id?: number }).id === n) ?? "{}"); const tools = byId(2) as { result?: { tools?: { name: string }[] } }; - assert.deepEqual(tools.result?.tools?.map((t) => t.name).sort(), ["acp_cache", "acp_status", "compress", "decompress", "read_original_image", "search_context"], "tools listed"); + assert.deepEqual(tools.result?.tools?.map((t) => t.name).sort(), ["acp_cache", "acp_read_original_image", "acp_status", "compress", "decompress", "search_context"], "tools listed"); const call = byId(3) as { result?: { content?: { text?: string }[]; isError?: boolean } }; assert.equal(call.result?.isError, false, `tools/call succeeded (self-registered conversation bound)${call.result?.isError ? ": " + (call.result?.content?.[0]?.text ?? "") : ""}`); assert.match(call.result?.content?.[0]?.text ?? "", /CONTEXT BREAKDOWN/); diff --git a/tests/plugin-fork.test.ts b/tests/plugin-fork.test.ts index fc6ff7314d..57c84c76e7 100644 --- a/tests/plugin-fork.test.ts +++ b/tests/plugin-fork.test.ts @@ -163,7 +163,7 @@ test("HTTP explicit main with only public ACP tools captures initial history, us const h = await harness(false, false); try { const tools = (await h.request("/__bili/plugin/manifest")).body.tools.openai; - assert.deepEqual(tools.map((tool) => tool.function.name), ["compress", "decompress", "search_context", "acp_status", "acp_cache", "read_original_image"]); + assert.deepEqual(tools.map((tool) => tool.function.name), ["compress", "decompress", "search_context", "acp_status", "acp_cache", "acp_read_original_image"]); await sendIntentModel(h, "parent", h.messages, tools, "main"); assert.deepEqual(h.forwarded.at(-1)!.tools, tools, "main tools survive unchanged"); assert.equal(h.forwarded.at(-1)!.max_tokens, 256); diff --git a/tests/plugin-protocol.test.ts b/tests/plugin-protocol.test.ts index 2ec142a2c2..d517889daf 100644 --- a/tests/plugin-protocol.test.ts +++ b/tests/plugin-protocol.test.ts @@ -242,9 +242,9 @@ test("plugin manifest serves the exact wire tool schemas, headers and version", // #1192: every extra tool (absorb, acp_rule) is opt-in and only advertised // when enabled — hosts register manifest tools verbatim, so a disabled // tool must not be listed. acp_cache stays in the base toolset. - assert.deepEqual([...manifest.toolNames].sort(), ["acp_cache", "acp_status", "compress", "decompress", "read_original_image", "search_context"]); + assert.deepEqual([...manifest.toolNames].sort(), ["acp_cache", "acp_read_original_image", "acp_status", "compress", "decompress", "search_context"]); const names = manifest.tools.anthropic!.map((t) => String(t.name)).sort(); - assert.deepEqual(names, ["acp_cache", "acp_status", "compress", "decompress", "read_original_image", "search_context"]); + assert.deepEqual(names, ["acp_cache", "acp_read_original_image", "acp_status", "compress", "decompress", "search_context"]); assert.equal(manifest.tools.openai!.length, 6); assert.equal(manifest.tools.responses!.length, 6); // #841: search_context's conversation_id doubles as a cross-session @@ -278,7 +278,7 @@ test("plugin manifest: acp_rule advertised when rules enabled in config", async const resp = await fetch(`http://127.0.0.1:${h.proxyPort}/__bili/plugin/manifest`); assert.equal(resp.status, 200); const manifest = (await resp.json()) as { toolNames: string[]; tools: Record>> }; - assert.deepEqual([...manifest.toolNames].sort(), ["acp_cache", "acp_rule", "acp_status", "compress", "decompress", "read_original_image", "search_context"]); + assert.deepEqual([...manifest.toolNames].sort(), ["acp_cache", "acp_read_original_image", "acp_rule", "acp_status", "compress", "decompress", "search_context"]); for (const shape of ["anthropic", "openai", "responses"] as const) { const listed = manifest.tools[shape]!.map((t) => { const fn = t.function as { name?: unknown } | undefined; @@ -301,7 +301,7 @@ test("plugin manifest: absorb and acp_rule advertised when enabled in config", a const resp = await fetch(`http://127.0.0.1:${h.proxyPort}/__bili/plugin/manifest`); assert.equal(resp.status, 200); const manifest = (await resp.json()) as { toolNames: string[]; tools: Record>> }; - assert.deepEqual([...manifest.toolNames].sort(), ["absorb", "acp_cache", "acp_rule", "acp_status", "compress", "decompress", "read_original_image", "search_context"]); + assert.deepEqual([...manifest.toolNames].sort(), ["absorb", "acp_cache", "acp_read_original_image", "acp_rule", "acp_status", "compress", "decompress", "search_context"]); for (const shape of ["anthropic", "openai", "responses"] as const) { const listed = manifest.tools[shape]!.map((t) => { const fn = t.function as { name?: unknown } | undefined; @@ -327,7 +327,7 @@ test("plugin manifest: absorb advertised when enabled in the global compress blo const resp = await fetch(`http://127.0.0.1:${h.proxyPort}/__bili/plugin/manifest`); assert.equal(resp.status, 200); const manifest = (await resp.json()) as { toolNames: string[]; tools: Record>> }; - assert.deepEqual([...manifest.toolNames].sort(), ["absorb", "acp_cache", "acp_status", "compress", "decompress", "read_original_image", "search_context"]); + assert.deepEqual([...manifest.toolNames].sort(), ["absorb", "acp_cache", "acp_read_original_image", "acp_status", "compress", "decompress", "search_context"]); for (const shape of ["anthropic", "openai", "responses"] as const) { const listed = manifest.tools[shape]!.map((t) => { const fn = t.function as { name?: unknown } | undefined; @@ -349,7 +349,7 @@ test("plugin manifest: absorb omitted when the global compress block disables it const resp = await fetch(`http://127.0.0.1:${h.proxyPort}/__bili/plugin/manifest`); assert.equal(resp.status, 200); const manifest = (await resp.json()) as { toolNames: string[] }; - assert.deepEqual([...manifest.toolNames].sort(), ["acp_cache", "acp_status", "compress", "decompress", "read_original_image", "search_context"]); + assert.deepEqual([...manifest.toolNames].sort(), ["acp_cache", "acp_read_original_image", "acp_status", "compress", "decompress", "search_context"]); } finally { await h.close(); } diff --git a/tests/side-lane-invariants.test.ts b/tests/side-lane-invariants.test.ts index b10caedb05..88dc356b0a 100644 --- a/tests/side-lane-invariants.test.ts +++ b/tests/side-lane-invariants.test.ts @@ -355,11 +355,11 @@ test("(I) revival (#3402): the absorb tool name is bili-owned again", () => { assert.ok(BILI_TOOL_NAMES.has(RETRIEVE_TOOL_NAME), "retrieve tool still bili-owned"); }); -// (#3400): read_original_image is bili's own context-management tool. A +// (#3400): acp_read_original_image is bili's own context-management tool. A // session-sidecar request that leaks the armed tool set must still be demoted // by #1897, so the name joins the bili-owned set in side-request.ts — and per // #2170 the lane-logic move lands with its dedicated suite pinning the // membership (same discipline as (I) above for the absorb removal). -test("(J) post-#3400: read_original_image is bili-owned for #1897 demotion", () => { - assert.ok(BILI_TOOL_NAMES.has(READ_ORIGINAL_IMAGE_TOOL_NAME), "read_original_image is in the bili-owned set"); +test("(J) post-#3400: acp_read_original_image is bili-owned for #1897 demotion", () => { + assert.ok(BILI_TOOL_NAMES.has(READ_ORIGINAL_IMAGE_TOOL_NAME), "acp_read_original_image is in the bili-owned set"); }); diff --git a/tests/wire-contract.test.ts b/tests/wire-contract.test.ts index cd151d4fd9..cf5a6ac90b 100644 --- a/tests/wire-contract.test.ts +++ b/tests/wire-contract.test.ts @@ -477,7 +477,7 @@ const LANES: Lane[] = [ // #1399: acp_rule is part of the default injected surface on every wire, so // it joins the base expectation here (opt-in lanes below no longer add it). -// #3400: read_original_image likewise — the egress rescale pass defaults ON, +// #3400: acp_read_original_image likewise — the egress rescale pass defaults ON, // so proxy-injection lanes forward it on every wire (tool-rejecting lanes // like codex degrade to size-only notes and never run these rigs). const BASE_EXPECTED: Record = { From 9582c43b5e72cc5e48760a8e6f4e99d1d7b822e1 Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 17 Oct 2026 19:55:51 +0800 Subject: [PATCH 3/3] feat(#3546): settings panel quick-field for compress.absorb toggle Third item from #3546 follow-up: absorb (default off) had no panel control either - enabling it meant hand-editing JSON. Adds the quick-fields checkbox mirroring the imageRescale pattern: checked writes compress.absorb.enabled=true preserving any existing sub-fields, unchecked deletes the whole absorb block (and an emptied compress object). Hint notes the #3422 mediaOnly default (image-bearing results only) and points sub-fields at the JSON editor. CHANGELOG [Unreleased] entry now covers both panel toggles. --- CHANGELOG.md | 1 + src/web/client.ts | 22 ++++++++++++++++++++++ src/web/i18n.ts | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a07bc11a0..b27c5a0666 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Versions follow the merge of a `*_release-v*` branch; CI publishes to npm on tag - **dsh desktop settings pane: the embed probe is admitted for the Electron scheme origin (#3513, desktop variant).** The dsh DESKTOP app renders its settings pane from the custom scheme origin `dsh-app://app` (not an http origin like dsh web). The #3514 fix echoed the requesting Origin — but the request never reached the echo: `isTrustedAdminOrigin` only accepts http/https origins, so the probe's `GET /__bili/?embed=1` died in the trust gate with a bare 403 and no `access-control-allow-origin` — the pane stayed on "正在连接 bili 代理…" forever (real-world console: "blocked by CORS policy … from origin 'dsh-app://app'"). The gate now admits exactly that one origin (scheme `dsh-app`, hostname `app`): browsers set the Origin header themselves and the `dsh-app` scheme only exists inside the dsh Electron app, so a website can never produce that Origin — while rebinding attacks still arrive with http/https attacker hostnames and stay rejected. Foreign hostnames under the same scheme (`dsh-app://evil`) and every other custom scheme stay 403; the existing #3514 echo then covers the response. - **dist is self-contained again: the zod leak from the jimp image-rescale lane is bundled away, with a build gate to keep it away (#3511 P0).** #3425 inlined jimp (pure-JS image encoder, devDependency), and jimp imports zod at module scope — leaking 16 STATIC `from"zod"` imports into `dist/index.js` and `dist/agent/pi-native.js`. Static imports resolve at module load with no degrade path, so installs that ship the package without its node_modules (dsh profile bare copies, thin plugin copies — the real dsh/pi plugin shapes) died with `ERR_MODULE_NOT_FOUND` and model traffic silently went direct, uncompressed. zod is now bundled like every other transitive of an inlined dependency (dist/index.js grows ~1.4 MB); the ONE sanctioned external consumer — the opencode V1 host interop, which wants the HOST's zod instance and already degrades when unresolvable — keeps its own runtime resolution through an opaque specifier. `npm run build` now fails on any static zod import surviving into dist (`scripts/check-dist-external-zod.mjs`). Verified: a bare `dist/` copy with zero node_modules runs `node dist/index.js --version` clean. - **dsh web settings panel: the embed pre-flight gets its CORS answer (#3513).** The #3100 pre-flight fetches `/__bili/?embed=1` CROSS-origin — the dsh web page lives on the host's port, the proxy on its own, and while both are loopback names (so the trusted-origin gate admits the request), a cors-mode fetch is only readable when the response carries `access-control-allow-origin`. It never did: the browser rejected the probe, the verdict never landed, and the pane stayed on "connecting to the bili proxy…" forever while the proxy itself (model traffic, iframe navigation) kept working. The embed-face GET now echoes the requesting Origin — a static HTML shell with no state, reachable only by origins the #115/#1537 gates already admitted; clients without an Origin header (curl, CLIs) see no header at all, and the DNS-rebinding gates are untouched. +- **Settings-panel quick fields for outbound image downscale and absorb (#3546).** The web settings page's quick-fields section exposes two previously JSON-only switches: an outbound image downscale checkbox (`imageRescale`; checked = default-on = key omitted, unchecked writes `false`) with a hint pointing at `BILI_IMAGE_RESCALE_MAX_DIM`, and an instant tool-result absorption checkbox whose checked state writes `compress.absorb.enabled: true` (preserving any existing sub-fields) and whose unchecked state deletes the whole `absorb` block, with a hint noting the #3422 `mediaOnly` default (image-bearing results only). Sub-fields stay in the raw JSON editor; no new config keys. - **Egress image downscale + `acp_read_original_image` (#3400).** Redoes the image pre-compression removed in #3295 in simplified form — **behavior change**: since #3295 every image passed through byte-identical at original resolution; from this version on, large outbound images are sent SHRUNKEN by default. On every outbound request (after kernel folding, before protocol encoding, all protocols share one pass) an image whose longest edge exceeds 1600 px (`BILI_IMAGE_RESCALE_MAX_DIM`) or whose base64 body exceeds 100 KB is re-encoded fit-inside (never upscaled, original format kept) on an OUTBOUND COPY only — session storage keeps the original bytes byte-exact. A re-encode saving less than 20% of the bytes is discarded (keep-smaller), so small and low-benefit images pass through untouched; only PNG/JPEG/BMP are handled (pure-JS jimp encoder, zero native dependencies — sharp does not return). Each shrunken image carries a stable annotation beside it reporting current vs original size; lanes that register bili tools (proxy-injection lanes, plugin lanes via the plugin manifest) also get the tool named in the annotation — `acp_read_original_image("mNNNNN")` returns the original bytes from local session storage — while tool-rejecting lanes (codex) get size-only notes and no tool. Tool results are structurally exempt from re-shrinking (zero-state loop guard against the #3266 guess-reject-resend disease). Output is deterministic (content-hash cached, one encode per unique image; same history → byte-identical outbound bodies) so upstream prefix caching is undisturbed. Observability: one log line per unique image (dims+bytes before/after) and one per original-image read (ref, sizes, session cumulative count+bytes) — no hard cap, the model was told the sizes. Knobs: `BILI_IMAGE_RESCALE` (`"0"`/`"false"` off; default on), `BILI_IMAGE_RESCALE_MAX_DIM` (default 1600, env-only), config-file key `imageRescale`. Legacy `compress.imageCompression.*` INERT warnings remain owned by #3344/#3355. - **Lane-decisions 收尾:四处 B 类旁路迁入统一决策点 + nudgeOn 单点(#3482,承接 #3417)。** ①omp 身份戳通道(`stampPromptCacheKey` 的 `agent !== "omp"` 门)改为注册表属性 `stampsBodyPromptCacheKey`;OMP Cowork 直连传输的"是否可能"进注册表(`coworkTransportPossible`),逐请求真相仍由环境观察(`ompCoworkTransportBypassesFetch`)给出。②codex/claude-responses 的 instructions 指纹键控从散落头名比较收进 `WIRE_CLIENTS` 注册表(`instructionsFingerprintKeyed`;信号检测留在 session-id,决策表只在注册表)。③计费块(#2189)提取改由 `laneDecisions.billingBlockWanted` 门控:profile 声明(dsh)或 wire 观察到块任一成立即提取——证据优先,与 toolsReachable 同形状;零 wire 字节变更。④四份手抄 `willInjectNudge` 合取收敛为 `nudgeOn()` 九入参纯函数:responses 的两处有意差异(compaction-trigger 豁免、codex-intercept 健康窗)显式入参,openai/google 的冗余 `shouldInject` 合取被 `compressSurfaceOn` 吸收;1024 点布尔立方等价测试 + 四车道旧公式逐位对照钉死。结构守卫扩展:B 类站点禁裸 lane 名门控,`WIRE_CLIENTS` 注册表条目必须有 `matches()`。⑤HostProfile 注册表整体落在零导入叶子模块 `src/host-profiles.ts`(review 修正:首版让 agent 侧直接 import lane-decisions,preflight→kernel 整链被拖进 dist/agent/pi.js、omp.js,两个宿主扩展包体积翻倍;拆出后两者回到原尺寸,结构守卫钉死该模块必须无 import)。`wantsBillingBlock` 死属性落位为真实消费者(上述③)。dshLedgerFloorTokens 本无 lane 名查(issue 前提修正:#1729 守卫故意 identity-blind,#2193)——三处 ledger floor 调用点保持不动并在 PR 说明。 - **Lane decisions extracted to a single resolver (#3417, fixes #3401).** The four wire adapters each carried their own copy of the lane gates (`dshCompressSurfaceOff`, the dsh compact-rebase guard), and the copies drifted: a dsh profile that DOES declare `compress` on the wire still had the model-side compress surface dropped (#3401). New `src/server/lane-decisions.ts`: a `HostProfile` registry (the only place lane names are compared), per-request `WireObservation` (which bili tools this request actually declares), and `resolveLaneDecisions()` — the one gate the four prepares now consume. Observed reachability overrides the dsh host-scope default, so tool-carrying dsh profiles keep the nudge/standing prompt while bare dsh stays off (#3177 preserved). `biliToolsDeclaredOnWire` gained a named-tool variant (the nudge advertises `compress` specifically). Structural guard test pins that prepares carry no raw lane-name comparisons. The dsh native-compaction rebase gate on all four wires now reads the registry property `compactsClientSide`. diff --git a/src/web/client.ts b/src/web/client.ts index 64e8c088c0..f686ae69c3 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -2178,6 +2178,8 @@ export const WEB_CLIENT = `(function () { dbg.inp.checked = draft.debug === true; ptRow.inp.checked = draft.passthrough === true; imgRow.inp.checked = draft.imageRescale !== false; + const ab = (cp && cp.absorb && typeof cp.absorb === "object" && !Array.isArray(cp.absorb)) ? cp.absorb : null; + abRow.inp.checked = ab ? ab.enabled === true : false; const pv = (cp && typeof cp.promptPack === "string") ? cp.promptPack : "default"; while (packSel.options.length > 0) packSel.removeChild(packSel.lastChild); ["default", "lean"].forEach((name) => { @@ -2264,6 +2266,26 @@ export const WEB_CLIENT = `(function () { imgHint.className = "dim small"; imgHint.textContent = t("cfg.q_imgrescale_hint"); imgRow.ctl.appendChild(imgHint); + const abRow = row("quick-absorb", t("cfg.q_absorb")); + qCtrls.push(abRow.inp); + abRow.inp.addEventListener("change", () => commit((d) => { + if (abRow.inp.checked) { + if (!compressOf(d)) d.compress = {}; + const a = d.compress.absorb; + d.compress.absorb = (a && typeof a === "object" && !Array.isArray(a)) ? a : {}; + d.compress.absorb.enabled = true; + } else { + const c = compressOf(d); + if (c) { + delete c.absorb; + if (Object.keys(c).length === 0) delete d.compress; + } + } + })); + const abHint = document.createElement("span"); + abHint.className = "dim small"; + abHint.textContent = t("cfg.q_absorb_hint"); + abRow.ctl.appendChild(abHint); const packSel = document.createElement("select"); packSel.className = "field-input mono"; qCtrls.push(packSel); diff --git a/src/web/i18n.ts b/src/web/i18n.ts index 7c8fb0c49d..6ea369f709 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -375,6 +375,8 @@ export const MESSAGES: Record> = { "cfg.q_passthrough": "透传模式(passthrough)——开启后不注入、不压缩,纯代理", "cfg.q_imgrescale": "出站图片降采样(imageRescale)——大尺寸出站图片先缩小再发给模型,原图留存本地(默认开)", "cfg.q_imgrescale_hint": "最长边阈值用环境变量 BILI_IMAGE_RESCALE_MAX_DIM 调(默认 1600)", + "cfg.q_absorb": "工具结果即时蒸馏(absorb)——大工具结果到达时由模型即时蒸馏,原文隐藏到下一轮折叠前(默认关)", + "cfg.q_absorb_hint": "默认只吸含图结果(#3422);mediaOnly: false 可恢复吸全文。子项(minToolTokens、contextThresholdPct、excludeTools)请在下方 JSON 编辑框写", "cfg.q_pack": "压缩提示词包(compress.promptPack)", "cfg.q_nudge": "压缩增长阈值 tokens(compress.nudgeGrowthTokens)", "cfg.q_nudge_step": "步进 5000", @@ -853,6 +855,8 @@ export const MESSAGES: Record> = { "cfg.q_passthrough": "Passthrough mode (passthrough) — pure proxying, no injection, no compression", "cfg.q_imgrescale": "Outbound image downscale (imageRescale) — large outbound images are shrunken before reaching the model; originals stay in local session storage (default on)", "cfg.q_imgrescale_hint": "longest-edge threshold via env BILI_IMAGE_RESCALE_MAX_DIM (default 1600)", + "cfg.q_absorb": "Instant tool-result absorption (absorb) — large tool results are distilled by the model on arrival; originals hidden until the next fold round (default off)", + "cfg.q_absorb_hint": "by default only image-bearing results are absorbed (#3422); set mediaOnly: false to absorb full text. Sub-fields (minToolTokens, contextThresholdPct, excludeTools) go in the JSON editor below", "cfg.q_pack": "Compression prompt pack (compress.promptPack)", "cfg.q_nudge": "Compress growth threshold tokens (compress.nudgeGrowthTokens)", "cfg.q_nudge_step": "step of 5000",