Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,13 @@ For each request, the proxy resolves the settings by longest-URL-prefix match (t
- **Status:** ACTIVE
- **Description:** With `stripImages: true`, how many trailing messages keep their images verbatim. Ignored unless `stripImages` is enabled.

#### `visibilityMarkers`

- **Type:** `boolean`
- **Default:** `true`
- **Status:** ACTIVE
- **Description:** Controls the 📦/❌ ACP visibility markers emitted after the proxy executes a proxy tool call (`compress` / `decompress` / `search_context` / `acp_status`). When on, each execution appends a marker line to the response stream and/or re-injects a marker message into that round's rebuilt history so the model can see what happened on later turns. Set `false` to suppress both artifacts — for deployments where models imitate or narrate around the markers (outputting their own confirmation lines or commentary; see issue #862). The tool executions themselves are unaffected: calls still run, and paired tool-call/tool-result messages are still recorded as usual; only the marker line/message is omitted. Same three-level merge as every other field. The #717 anti-forgery stripping of model-emitted fake markers is independent of this flag and stays active.

### Injection toggles (global only)

These two toggles are honoured only at the **global** level. Setting them inside a per-provider or per-model `compress` block has no effect.
Expand Down
7 changes: 7 additions & 0 deletions CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,13 @@
- **状态:** ACTIVE
- **说明:** 在 `stripImages: true` 时,末尾多少条消息保留其图像逐字转发。仅在启用 `stripImages` 时生效。

#### `visibilityMarkers`

- **类型:** `boolean`
- **默认值:** `true`
- **状态:** ACTIVE
- **说明:** 控制代理执行 proxy 工具调用(`compress` / `decompress` / `search_context` / `acp_status`)后输出的 📦/❌ ACP 可见标记。开启时,每次执行会在响应流中追加一行标记,并/或把标记消息重新注入该轮重建后的历史,让模型在后续回合看到发生了什么。设为 `false` 可完全抑制这两类产物 —— 适用于模型会模仿或围绕标记进行旁白的部署场景(自行输出确认行或中文旁白;见 issue #862)。工具执行本身不受影响:调用照常执行、成对的 tool-call/tool-result 消息照常记录,只是省略标记行/标记消息。与其他字段相同的三级合并。#717 对模型伪造标记的防伪造剥离逻辑独立于本开关,始终生效。

### 注入开关(仅全局生效)

这两个开关只在**全局**层级生效。在按 provider 或按模型的 `compress` 块中设置它们无效。
Expand Down
7 changes: 5 additions & 2 deletions src/compress-loop-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ interface CompressLoopResponsesCtx {
/** Resolved upstream proxy URL (http://host:port) or undefined for direct. */
proxyUrl?: string;
textProtocol?: boolean;
/** #862: when `false`, suppress 📦/❌ visibility markers (same contract as
* LoopCtx.visibilityMarkers). Default (undefined) keeps markers on. */
visibilityMarkers?: boolean;
}

interface RequestOptions {
Expand Down Expand Up @@ -160,7 +163,7 @@ function surfaceReadonlyJson(
result = `\u274c [ACP] ${call.name} FAILED: ${String(e)}`;
ctx.log(`[acp-proxy: responses JSON ${call.name} (read-only) FAILED: ${String(e)}]`);
}
markers.push(buildVisibilityMarker(call.name, result));
if (ctx.visibilityMarkers !== false) markers.push(buildVisibilityMarker(call.name, result));
}
if (markers.length === 0) return current;
const out = Array.isArray(current.output) ? [...(current.output as unknown[])] : [];
Expand Down Expand Up @@ -212,7 +215,7 @@ export async function compressLoopResponsesJson(
}
const result = executeProxyTool(call.name, args, ctx);
ctx.log(`[acp-proxy: responses JSON ${call.name} → ${result.slice(0, 120).replace(/\n/g, " ")}]`);
inputItems.push({ type: "message", role: "developer", content: buildVisibilityMarker(call.name, result) });
if (ctx.visibilityMarkers !== false) inputItems.push({ type: "message", role: "developer", content: buildVisibilityMarker(call.name, result) });
}
requestBody.input = hoistTrappedToolItems(inputItems as ToolPairItem[]);
const result = await fetchWithRetry(requestOptions.url, {
Expand Down
1 change: 1 addition & 0 deletions src/compress-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export function mergeCompress(

stripImages: pick("stripImages"),
stripImagesKeepRecent: pick("stripImagesKeepRecent"),
visibilityMarkers: pick("visibilityMarkers"),
// `reasoning` is a third nested-object field merged sub-field-wise
// exactly like `absorb`/`prompts`: a model-level `threshold` must not
// discard a provider-level `drop: false`.
Expand Down
10 changes: 10 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ export type CompressSettings = {
minCompressRange?: number;
/** Enable multi-tier (T2/T3) distillation (kernel `tiers.enabled`). */
tiers?: boolean;
/** Emit 📦/❌ ACP visibility markers after proxy tool executions
* (compress / decompress / search_context / acp_status) — both the marker
* line streamed to the client and the marker message re-injected into
* rebuilt history. `false` suppresses them entirely, for deployments where
* models imitate or narrate around the markers (#862). Default `true`. */
visibilityMarkers?: boolean;
/** Override the kernel's compression prompt text (compressPhilosophy /
* howToCompressRules / tier2DistillRules / tier3CondenseRules). All four
* fields are LOAD-BEARING: the kernel rules were tuned in production and
Expand Down Expand Up @@ -709,6 +715,10 @@ export function parseCompressSettings(v: unknown): (CompressSettings & { injectT
if (typeof obj.stripImages !== "boolean") ok = false;
else out.stripImages = obj.stripImages;
}
if ("visibilityMarkers" in obj) {
if (typeof obj.visibilityMarkers !== "boolean") ok = false;
else out.visibilityMarkers = obj.visibilityMarkers;
}
// Injection toggles are file-level fields (FileConfig.compress) honored by
// loadOptions via `=== false`; the web UI shows them from the raw file
// block, so they must round-trip here. Dropping them would silently
Expand Down
10 changes: 8 additions & 2 deletions src/loop/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export interface LoopCtx {
// compute the true context total correctly (Anthropic reports
// input_tokens as NEW-only; OpenAI/Responses report the TOTAL).
protocol?: WireProtocol;
/** #862: when `false`, suppress the 📦/❌ ACP visibility markers emitted
* after proxy tool executions — both the marker line streamed to the
* client (`emitMarker`) and the orphan marker message re-injected into
* rebuilt history. Default (undefined) keeps markers on. Paired
* tool-call/tool-result messages are unaffected. */
visibilityMarkers?: boolean;
}

export interface RequestOptions {
Expand Down Expand Up @@ -569,7 +575,7 @@ export async function* runCompressLoop(
}
const result = executeProxyTool(call.name, parsedArgs, ctx, call.callId);
proxyResults.push({ name: call.name, callId: call.callId, result, arguments: call.arguments });
yield adapter.emitMarker(call.name, result);
if (ctx.visibilityMarkers !== false) yield adapter.emitMarker(call.name, result);
} else {
realToolCalls.push(call);
realCalls += 1;
Expand Down Expand Up @@ -643,7 +649,7 @@ export async function* runCompressLoop(
toolCallId: pr.callId,
text: pr.result,
});
} else {
} else if (ctx.visibilityMarkers !== false) {
coreMessages.push({
id: `acp_loop_r${round}_marker_${pr.callId}`,
role: "system",
Expand Down
6 changes: 4 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3958,9 +3958,10 @@ async function forward(
const records = current.filter((m) => typeof m.id === "string" && m.id.startsWith("acp_loop_"));
return repairResponsesAssistantOrdering(stripKernelSummaries([...viewed, ...records] as BiliMessage[], turn.state), prepared.originalMessages);
};
const visibilityMarkers = resolveCompress(opts.routes, route?.rewrittenUrl, (parsedReq as { model?: string }).model, opts.compress).visibilityMarkers ?? true;
const loop = runCompressLoop(
streamToRead,
{ core, config, messages: prepared.processedMessages.length > 0 ? prepared.processedMessages : prepared.originalMessages, compressMessages: prepared.originalMessages, session: prepared.session, log: ctx.log, proxyUrl, protocol: prepared.protocol, textProtocol, debug: opts.debug, refreshFolded },
{ core, config, messages: prepared.processedMessages.length > 0 ? prepared.processedMessages : prepared.originalMessages, compressMessages: prepared.originalMessages, session: prepared.session, log: ctx.log, proxyUrl, protocol: prepared.protocol, textProtocol, debug: opts.debug, refreshFolded, visibilityMarkers },
parsedReq,
{ url: upstreamUrl, headers: reqHeaders, wireTransform },
adapter,
Expand Down Expand Up @@ -4013,9 +4014,10 @@ async function forward(
if (prepared.protocol === "responses" && prepared.responsesTextProtocol) {
const requestBody = JSON.parse(typeof body === "string" ? body : body.toString("utf8")) as Record<string, unknown>;
const requestHeaders = buildForwardHeaders(headers);
const visibilityMarkers = resolveCompress(opts.routes, route?.rewrittenUrl, (requestBody as { model?: string }).model, opts.compress).visibilityMarkers ?? true;
json = await compressLoopResponsesJson(
json,
{ core, config, messages: prepared.originalMessages, session: prepared.session, log: ctx.log, proxyUrl, textProtocol: true },
{ core, config, messages: prepared.originalMessages, session: prepared.session, log: ctx.log, proxyUrl, textProtocol: true, visibilityMarkers },
requestBody,
{ url: upstreamUrl, headers: requestHeaders, wireTransform },
);
Expand Down
2 changes: 1 addition & 1 deletion src/web/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ export function renderPage(origin: string, version: string): string {
<div class="card"><div class="card-head"><h2>ZCode(编程套餐)</h2><span class="badge">MITM</span><button class="btn small copy-btn" data-copy="${caPathEsc}">复制 CA 路径</button></div><dl class="kv"><dt>方式</dt><dd>MITM 透明代理</dd><dt>设置</dt><dd>Settings → Network → HTTP Proxy = <span class="mono">${origin}</span></dd><dt>CA 证书</dt><dd class="mono">${caPathEsc}${caReady ? "" : "(尚未生成,启动代理后自动创建)"}</dd></dl><p class="hint">CA 路径是本机 bili 实际生成的绝对路径,点"复制 CA 路径"后直接粘贴进 ZCode。⚠️ Windows 上 ZCode 不会展开 <span class="mono">~</span>,请勿手填 <span class="mono">~/…</span> 形式的路径。</p></div></section>
<section id="page-upstream" class="page"><h1>上游网络</h1><p class="lead">控制 bili 如何访问真实 Provider,不会改变客户端的本地路由地址。</p><div class="card"><div class="card-head"><h2>全局代理</h2></div><div class="modes"><label><input type="radio" name="proxy-mode" value="direct" checked>直连(默认)</label><label><input type="radio" name="proxy-mode" value="manual">手动代理</label><label><input type="radio" name="proxy-mode" value="auto">自动(跟随系统)</label></div><div class="field"><label>HTTP / HTTPS Proxy</label><input id="proxy-url" class="mono" placeholder="http://127.0.0.1:7897"></div><dl class="kv"><dt>当前来源</dt><dd id="upstream-source">直连</dd><dt>有效代理</dt><dd id="upstream-effective" class="mono">direct</dd><dt>系统 PAC</dt><dd id="upstream-pac" class="mono">—</dd><dt>状态</dt><dd id="upstream-state" class="status">尚未测试</dd></dl><div class="actions"><button id="save-upstream" class="btn primary">保存并热更新</button><button id="test-upstream" class="btn">测试连接</button></div></div><div class="card"><div class="card-head"><h2>按 URL 覆盖</h2></div><p class="status">为特定 Provider 单独设置上游代理,覆盖全局设置。留空 = 继承全局。</p><div id="upstream-overrides" class="status">加载中</div><div class="actions"><button id="save-overrides" class="btn primary">保存覆盖并热更新</button></div></div></section>
<section id="page-sessions" class="page"><div class="card-head"><div><h1>会话</h1><p class="lead">ACP 压缩状态与上游用量。</p></div><button id="refresh-sessions" class="btn">刷新</button></div><div class="card"><table><thead><tr><th>标题</th><th>协议</th><th>标识</th><th>请求</th><th>上下文</th><th title="相信窗口 / 近期成功最大输入(差距大 = provider 虚标)">窗口</th><th>最后活动</th></tr></thead><tbody id="sessions-body"></tbody></table></div></section>
<section id="page-settings" class="page"><h1>高级设置</h1><p class="lead">直接编辑 providers JSON(添加新 Provider、配置模型上下文窗口、按 URL 代理等);保存后立即热更新。</p><div class="card"><div class="field"><label>providers JSON</label><textarea id="providers-json">{}</textarea></div><div class="actions"><button id="save-providers" class="btn primary">保存并应用</button></div></div><div class="card"><div class="card-head"><h2>压缩参数(全局)</h2></div><p class="status">全局 compress 配置(modelContextLimit / maxContextLimit / emergencyThresholdPercent / nudgeGrowthTokens / preserveRecentMessages / preserveRecentTokens / minCompressRangeChars(单位:字符,旧名 minCompressRange 兼容) / stripImages / stripImagesKeepRecent(历史图像剥离,默认关) / tiers / injectTool / injectNudge)。保存后热更新,无需重启。置空 = 恢复默认。</p><div class="field"><label>compress JSON</label><textarea id="compress-json" placeholder='{"modelContextLimit": 200000}'></textarea></div><div class="actions"><button id="save-compress" class="btn primary">保存并热更新</button></div></div></section></main></div><div id="toast" class="toast"></div><script>${WEB_CLIENT}</script></body></html>`;
<section id="page-settings" class="page"><h1>高级设置</h1><p class="lead">直接编辑 providers JSON(添加新 Provider、配置模型上下文窗口、按 URL 代理等);保存后立即热更新。</p><div class="card"><div class="field"><label>providers JSON</label><textarea id="providers-json">{}</textarea></div><div class="actions"><button id="save-providers" class="btn primary">保存并应用</button></div></div><div class="card"><div class="card-head"><h2>压缩参数(全局)</h2></div><p class="status">全局 compress 配置(modelContextLimit / maxContextLimit / emergencyThresholdPercent / nudgeGrowthTokens / preserveRecentMessages / preserveRecentTokens / minCompressRangeChars(单位:字符,旧名 minCompressRange 兼容) / stripImages / stripImagesKeepRecent(历史图像剥离,默认关) / visibilityMarkers(📦/❌ 可见标记,默认开) / tiers / injectTool / injectNudge)。保存后热更新,无需重启。置空 = 恢复默认。</p><div class="field"><label>compress JSON</label><textarea id="compress-json" placeholder='{"modelContextLimit": 200000}'></textarea></div><div class="actions"><button id="save-compress" class="btn primary">保存并热更新</button></div></div></section></main></div><div id="toast" class="toast"></div><script>${WEB_CLIENT}</script></body></html>`;
}
Loading
Loading