From e5d2470a019aa0d7b144eb43fe886a01f8c61542 Mon Sep 17 00:00:00 2001 From: awork Date: Thu, 15 Oct 2026 12:53:31 +0800 Subject: [PATCH 1/3] fix: plugin manifest serves top-level promptPack tool descriptions (#3243) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit handlePluginManifest now takes an optional ToolPrompts surface and applies it to the ACP core tool arrays exactly like the wire injector; the admin manifest endpoint resolves it from the global compress settings via resolveCompressSurfaceDetailed. Registered plugin tools previously always carried kernel-default descriptions regardless of compress.promptPack — now they follow the top-level pack. Provider/model-level promptPack still shapes per-request system prompts only (the manifest has no route/model context, #1192 conservative boundary). Regression tests pin lean-pack descriptions on all three wires, unchanged defaults without a pack, and the route-level-only boundary. --- src/plugin.ts | 16 +- src/server/admin.ts | 9 +- tests/issue3243-manifest-prompt-pack.test.ts | 158 +++++++++++++++++++ 3 files changed, 176 insertions(+), 7 deletions(-) create mode 100644 tests/issue3243-manifest-prompt-pack.test.ts diff --git a/src/plugin.ts b/src/plugin.ts index 4f82de0268..869e08cb89 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -1,4 +1,4 @@ -import { BLOCKED_REF, COMPRESS_TOOL_NAME, type CompressionCore, type Config, type CoreMessage, type NudgeDecision, type RetrievalExport, applyRetrieve, countMessageTokens, parseStoredPlaceholder, prune } from "acp-kernel"; +import { BLOCKED_REF, COMPRESS_TOOL_NAME, type CompressionCore, type Config, type CoreMessage, type NudgeDecision, type RetrievalExport, type ToolPrompts, applyAcpToolOverrides, applyRetrieve, countMessageTokens, parseStoredPlaceholder, prune } from "acp-kernel"; import { publicSnapshotCapBytes } from "./knobs.js"; import { buildStatusPanel } from "acp-kernel/panel"; import { fileURLToPath } from "node:url"; @@ -803,7 +803,7 @@ export function handlePluginSessionName(payload: string, res: import("node:http" // arbitration; see tool-ring.ts). Wire-mode injection serves the kernel // constants directly, which never carried the param. -export function handlePluginManifest(res: import("node:http").ServerResponse, config: Config): void { +export function handlePluginManifest(res: import("node:http").ServerResponse, config: Config, toolPrompts?: ToolPrompts): void { // #1192: hosts register whatever the manifest serves verbatim (pi/omp/dsh/ // opencode native plugins, MCP shims), so advertising an opt-in tool this // proxy's config leaves disabled guarantees a rejected call the moment the @@ -813,6 +813,12 @@ export function handlePluginManifest(res: import("node:http").ServerResponse, co // enablement stays enforced at execution (isProxyToolFor / executeProxyTool). // #1359: the advertised name is the base-config toolName, matching the // plugin-lane gate (which adjudicates the same base block). + // #3243: toolPrompts is the pack surface's tool descriptions, resolved by the + // caller from the GLOBAL compress settings — the manifest has no route/model + // context (hosts fetch it before any request arrives), so provider/model-level + // promptPack still shapes each request's system prompt while registered tool + // descriptions follow the top-level pack only. Applied exactly like the wire + // injector (applyAcpToolOverrides on the ACP core arrays before extras merge). const absorbOn = absorbEnabled(config); const absorbName = config.absorb?.toolName ?? ABSORB_TOOL_NAME; const absorbTools = absorbOn ? absorbToolsFor(absorbName) : undefined; @@ -830,13 +836,13 @@ export function handlePluginManifest(res: import("node:http").ServerResponse, co // rule as acp_retrieve above. CCR-off manifests serve the no-range variants so // a registered agent never sees range fields execution would refuse. const externalSummary = externalSummaryEnabled(config); - const acpAnthropic = withExternalSummaryTools(ccrOn ? BILI_ACP_TOOLS_ANTHROPIC : BILI_ACP_TOOLS_ANTHROPIC_NO_RANGE, externalSummary); - const acpOpenai = withExternalSummaryTools(ccrOn ? BILI_ACP_TOOLS_OPENAI : BILI_ACP_TOOLS_OPENAI_NO_RANGE, externalSummary); + const acpAnthropic = withExternalSummaryTools(applyAcpToolOverrides(ccrOn ? BILI_ACP_TOOLS_ANTHROPIC : BILI_ACP_TOOLS_ANTHROPIC_NO_RANGE, toolPrompts), externalSummary); + const acpOpenai = withExternalSummaryTools(applyAcpToolOverrides(ccrOn ? BILI_ACP_TOOLS_OPENAI : BILI_ACP_TOOLS_OPENAI_NO_RANGE, toolPrompts), externalSummary); // Responses wire: plugin mode structurally disarms CCR there (#1271 — // PLUGIN_CCR_WIRES excludes it), so range restore can never execute for a // registered agent on that wire — always the no-range variant, mirroring // how ccrTools above is never spread into the responses array. - const acpResponses = withExternalSummaryTools(BILI_ACP_TOOLS_RESPONSES_NO_RANGE, externalSummary); + const acpResponses = withExternalSummaryTools(applyAcpToolOverrides(BILI_ACP_TOOLS_RESPONSES_NO_RANGE, toolPrompts), externalSummary); res.writeHead(200, { "content-type": "application/json" }); res.end(JSON.stringify({ ok: true, diff --git a/src/server/admin.ts b/src/server/admin.ts index 468f20d7fd..38be34f83a 100644 --- a/src/server/admin.ts +++ b/src/server/admin.ts @@ -6,7 +6,7 @@ import { APIG_RESIGN_SCHEME, KNOWN_SIGNATURE_SCHEMES, readPendingRefusals, unres import { handleAcpCache, readKeySwitchStats, readModelSwitchStats, readProjSwitchStats, readPromptSwitchStats } from "../cache-ledger.js"; import type { ProxyOptions } from "../config.js"; import { loadNamedProviders, loadOptions, loadRoutes, resolveResignSettings } from "../config.js"; -import { applyCompressSettings } from "../compress-settings.js"; +import { applyCompressSettings, resolveCompressSurfaceDetailed } from "../compress-settings.js"; import { clearConflictEvents, summarizeConflicts } from "../conflict-watch.js"; import { cannotResolveTarget, getAdvisoryState } from "../advisory.js"; import { detectCostAdvisories } from "../plugin-advisory.js"; @@ -317,7 +317,12 @@ export async function handleAdminRoute(req: http.IncomingMessage, res: http.Serv // (DEFAULT_CCR_CONFIG et al. inside applyCompressSettings); per-request/route overrides // are still enforced at execution time, so the manifest stays conservative as #1192 // requires. Do not "simplify" this back to `config`. - return handlePluginManifest(res, applyCompressSettings(config, opts.modelContextLimit, opts.compress, { ...agentProviderRecipes(), ...opts.namedProviders ?? {} })); + // #3243: pass the pack surface's tool descriptions too — resolved from the SAME + // global settings (no route/model context exists at manifest time), so registered + // tool descriptions follow the top-level promptPack while per-request system prompts + // may still honor deeper provider/model levels. + const packSurface = resolveCompressSurfaceDetailed(opts.compress ?? {}); + return handlePluginManifest(res, applyCompressSettings(config, opts.modelContextLimit, opts.compress, { ...agentProviderRecipes(), ...opts.namedProviders ?? {} }), packSurface.surface.toolPrompts); } if (req.method === "GET" && req.url?.split("?")[0] === "/__bili/plugin/snapshot") { return await handlePluginSnapshot(new URL(req.url, "http://localhost").searchParams.get("conversationId") ?? "", res); diff --git a/tests/issue3243-manifest-prompt-pack.test.ts b/tests/issue3243-manifest-prompt-pack.test.ts new file mode 100644 index 0000000000..f4740f4af7 --- /dev/null +++ b/tests/issue3243-manifest-prompt-pack.test.ts @@ -0,0 +1,158 @@ +// #3243 regression: the plugin manifest (/__bili/plugin/manifest) must serve +// the pack surface's tool descriptions. Before the fix handlePluginManifest +// built every tool array from kernel constants and never applied toolPrompts — +// a configured compress.promptPack shaped each request's system prompt (proxy +// AND plugin mode) while registered native-lane tools (pi/omp/dsh/opencode/MCP) +// always saw kernel-default descriptions. The manifest resolves the surface +// from the GLOBAL compress settings only (#1192 conservative rule: hosts fetch +// it before any request arrives, no route/model context); route/model-level +// promptPack still shapes per-request system prompts but never the manifest. +// Expectations come from the installed kernel's builtin lean pack via the SAME +// resolver the server uses, so this pins the wiring, not any wording. + +import test from "node:test"; +import assert from "node:assert/strict"; +import http from "node:http"; +import { once } from "node:events"; +import { ACP_TOOLS_ANTHROPIC, ACP_TOOLS_OPENAI, ACP_TOOLS_RESPONSES, defaultConfig } from "acp-kernel"; +import { startServer } from "../src/server.ts"; +import { resolveCompressSurface } from "../src/compress-settings.ts"; +import { SessionStore, _setStoreForTest } from "../src/persist.ts"; +import type { CompressSettings, ProxyOptions } from "../src/config.ts"; + +type GlobalCompress = CompressSettings & { injectTool?: boolean; injectNudge?: boolean }; +import { _setForTest as setRegistryForTest } from "../src/registry.ts"; + +function leanToolPrompts() { + const tp = resolveCompressSurface({ promptPack: "lean" }).toolPrompts; + assert.ok(tp && Object.keys(tp).length > 0, "builtin lean pack resolves with non-empty toolPrompts"); + assert.ok(tp.compress?.description, "lean compress carries a description override"); + assert.ok(tp.compress?.paramDescriptions?.content, "lean compress carries a content paramDescription"); + return tp; +} + +type Harness = { proxyPort: number; close(): Promise }; + +function listen(server: http.Server): Promise { + if (server.listening) return Promise.resolve(); + return once(server, "listening").then(() => undefined); +} + +async function startHarness(globalCompress: GlobalCompress, routeCompress?: CompressSettings): Promise { + _setStoreForTest(new SessionStore({ enabled: false })); + setRegistryForTest({}); + const upstream = http.createServer((_req, res) => { + res.writeHead(200, { "content-type": "application/json" }); + res.end(JSON.stringify({ id: "r1", object: "chat.completion", choices: [{ index: 0, message: { role: "assistant", content: "ok" }, finish_reason: "stop" }] })); + }); + upstream.listen(0, "127.0.0.1"); + await listen(upstream); + const upstreamPort = (upstream.address() as { port: number }).port; + const proxy = await startServer({ + port: 0, + host: "127.0.0.1", + upstream: "http://127.0.0.1", + routes: { [`http://127.0.0.1:${upstreamPort}`]: { compress: routeCompress } }, + modelContextLimit: 400_000, + kernelConfig: defaultConfig(400_000), + compress: globalCompress, + promptCache: { routing: "auto" }, + sessionHeader: "x-acp-session", + log: false, + debug: false, + passthrough: false, + autoUpdate: false, + mitm: { enabled: false, domains: [] }, + compat: { roles: {} }, streamErrorShape: "protocol", passthroughSource: null, autoRestartOnUpdate: false, updateTag: "latest", advisoryCheck: false, releaseNotesCheck: false, + } as ProxyOptions); + await listen(proxy); + return { + proxyPort: (proxy.address() as { port: number }).port, + close: async () => { + await new Promise((resolve, reject) => proxy.close((error) => (error ? reject(error) : resolve()))); + await new Promise((resolve, reject) => upstream.close((error) => (error ? reject(error) : resolve()))); + }, + }; +} + +async function fetchManifest(h: Harness): Promise> { + const res = await fetch(`http://127.0.0.1:${h.proxyPort}/__bili/plugin/manifest`); + assert.equal(res.status, 200, "manifest endpoint reachable on loopback"); + const doc = (await res.json()) as { ok: boolean; tools: Record }; + assert.ok(doc.ok, "manifest reports ok"); + return doc.tools; +} + +function findTool(tools: unknown[], name: string): Record { + const t = tools.find((x) => { + const o = x as Record; + return o?.name === name || o?.function?.name === name; + }); + assert.ok(t, `${name} advertised`); + return t as Record; +} + +function descriptionOf(t: Record): string { + return typeof t.description === "string" ? t.description : t.function.description; +} + +function parametersOf(t: Record): Record | undefined { + return t.input_schema ?? t.parameters ?? t.function?.parameters; +} + +const WIRES = [["anthropic", ACP_TOOLS_ANTHROPIC], ["openai", ACP_TOOLS_OPENAI], ["responses", ACP_TOOLS_RESPONSES]] as const; + +test("#3243: global promptPack reaches plugin-manifest tool descriptions on all three wires", async () => { + const h = await startHarness({ injectTool: true, injectNudge: true, promptPack: "lean" }); + try { + const tools = await fetchManifest(h); + const tp = leanToolPrompts(); + for (const [wire, defaults] of WIRES) { + for (const [name, overrides] of Object.entries(tp)) { + const tool = findTool(tools[wire], name); + if (overrides.description !== undefined) { + assert.equal(descriptionOf(tool), overrides.description, `${wire}.${name} description from lean pack`); + } + } + // CCR is off in this rig, so decompress here is the NO_RANGE variant — + // the pack override must land on it too (matched by tool name). + const compress = findTool(tools[wire], "compress"); + const kernelDefault = (defaults as readonly Record[]).find((d) => d.name === "compress" || d.function?.name === "compress")!; + const defaultDesc = typeof kernelDefault.description === "string" ? kernelDefault.description : kernelDefault.function.description; + assert.notEqual(descriptionOf(compress), defaultDesc, `${wire}.compress not the kernel default`); + assert.equal(parametersOf(compress)?.properties?.content?.description, tp.compress.paramDescriptions?.content, `${wire}.compress paramDescriptions applied`); + } + } finally { + await h.close(); + } +}); + +test("#3243: no promptPack — manifest keeps kernel-default compress descriptions", async () => { + const h = await startHarness({ injectTool: true, injectNudge: true }); + try { + const tools = await fetchManifest(h); + for (const [wire, defaults] of WIRES) { + const compress = findTool(tools[wire], "compress"); + const kernelDefault = (defaults as readonly Record[]).find((d) => d.name === "compress" || d.function?.name === "compress")!; + const defaultDesc = typeof kernelDefault.description === "string" ? kernelDefault.description : kernelDefault.function.description; + assert.equal(descriptionOf(compress), defaultDesc, `${wire}.compress stays kernel default`); + } + } finally { + await h.close(); + } +}); + +test("#3243: route-level promptPack never leaks into the manifest (#1192 conservative boundary)", async () => { + const h = await startHarness({ injectTool: true, injectNudge: true }, { promptPack: "lean" }); + try { + const tools = await fetchManifest(h); + for (const [wire, defaults] of WIRES) { + const compress = findTool(tools[wire], "compress"); + const kernelDefault = (defaults as readonly Record[]).find((d) => d.name === "compress" || d.function?.name === "compress")!; + const defaultDesc = typeof kernelDefault.description === "string" ? kernelDefault.description : kernelDefault.function.description; + assert.equal(descriptionOf(compress), defaultDesc, `${wire}.compress unaffected by route-level pack`); + } + } finally { + await h.close(); + } +}); From 541d7d38e6ac45def0dc0badfd2b9b643e02e894 Mon Sep 17 00:00:00 2001 From: awork Date: Thu, 15 Oct 2026 12:53:31 +0800 Subject: [PATCH 2/3] docs: document promptPack mode behavior in CONFIGURATION en/zh (#3243) --- CONFIGURATION.md | 2 +- CONFIGURATION.zh-CN.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 20b44334fb..a7917b5959 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -1328,7 +1328,7 @@ For each request, the proxy resolves the settings by longest-URL-prefix match (t - **Type:** `string` (pack name, e.g. `"lean"`) - **Default:** `default` *(unset is equivalent — identity surface, kernel defaults everywhere)* - **Status:** ACTIVE -- **Description:** Select a named prompt pack — a curated surface preset covering tool descriptions, compress system-prompt sections, and nudge sections — resolved from the kernel's pack chain: **project** `./.billion-context/packs/.json` → **user** `/packs/.json` → **builtin** (`default`, `lean`). Built-in `lean` swaps the four ACP tool descriptions for one-liners (no snippet/guideline chrome) while keeping the compression rules default. Unknown names fall back to the identity surface with a one-time warning. Same three-level merge as the other fields; pack-surface sections (tool/section overrides) apply directly, without the `acknowledgePromptsRisk` gate — that gate governs only inline `compress.prompts` rule-text overrides. Note a pack's `prompts` block is ignored by this proxy: rule-text overrides are possible only via inline `compress.prompts`. Requires `acp-kernel` >= 0.0.66. +- **Description:** Select a named prompt pack — a curated surface preset covering tool descriptions, compress system-prompt sections, and nudge sections — resolved from the kernel's pack chain: **project** `./.billion-context/packs/.json` → **user** `/packs/.json` → **builtin** (`default`, `lean`). Built-in `lean` swaps the four ACP tool descriptions for one-liners (no snippet/guideline chrome) while keeping the compression rules default. Unknown names fall back to the identity surface with a one-time warning. Same three-level merge as the other fields; pack-surface sections (tool/section overrides) apply directly, without the `acknowledgePromptsRisk` gate — that gate governs only inline `compress.prompts` rule-text overrides. Note a pack's `prompts` block is ignored by this proxy: rule-text overrides are possible only via inline `compress.prompts`. Requires `acp-kernel` >= 0.0.66. **Mode behavior (#3243):** in proxy (wire) mode the pack surface follows the full global → provider → model cascade for BOTH the system prompt and the injected tool descriptions; in native plugin mode (pi/omp/dsh/opencode/MCP lanes) the registered tool descriptions follow the **top-level** `compress.promptPack` only — the plugin manifest is static and session-independent (hosts fetch it before any request arrives, with no model context), while each request's system prompt still honors provider/model-level packs. Set `promptPack` at the top level when you want tool descriptions to follow the pack across all models. #### `reconcile` diff --git a/CONFIGURATION.zh-CN.md b/CONFIGURATION.zh-CN.md index 1f1d89204c..bd79f533a0 100644 --- a/CONFIGURATION.zh-CN.md +++ b/CONFIGURATION.zh-CN.md @@ -1333,7 +1333,7 @@ ACP 原生 agent(当前为 `pi` 扩展)会在每个进程内向代理上报 - **类型:** `string`(包名,如 `"lean"`) - **默认值:** `default`(未设置等同——恒等表面,全部使用内核默认值) - **状态:** ACTIVE -- **说明:** 选择一个具名 prompt pack —— 一套策划好的表面预设,覆盖工具描述、压缩系统提示词段落、nudge 段落 —— 从内核的包解析链解析:**项目** `./.billion-context/packs/.json` → **用户** `/packs/.json` → **内置**(`default`、`lean`)。内置 `lean` 把四个 ACP 工具描述换成单行版(无 snippet/guideline 包装),压缩规则保持默认。未知包名回退到恒等表面并记录一次警告。与其他字段一样三级级联合并;包的表面覆盖(工具/段落)直接生效,不经 `acknowledgePromptsRisk` 门控——该门控只管内联 `compress.prompts` 的规则文本覆盖。注意:包文件里的 `prompts` 块会被本代理忽略,规则文本只能经内联 `compress.prompts` 设置。需要 `acp-kernel` >= 0.0.66。 +- **说明:** 选择一个具名 prompt pack —— 一套策划好的表面预设,覆盖工具描述、压缩系统提示词段落、nudge 段落 —— 从内核的包解析链解析:**项目** `./.billion-context/packs/.json` → **用户** `/packs/.json` → **内置**(`default`、`lean`)。内置 `lean` 把四个 ACP 工具描述换成单行版(无 snippet/guideline 包装),压缩规则保持默认。未知包名回退到恒等表面并记录一次警告。与其他字段一样三级级联合并;包的表面覆盖(工具/段落)直接生效,不经 `acknowledgePromptsRisk` 门控——该门控只管内联 `compress.prompts` 的规则文本覆盖。注意:包文件里的 `prompts` 块会被本代理忽略,规则文本只能经内联 `compress.prompts` 设置。需要 `acp-kernel` >= 0.0.66。**模式行为(#3243):** 代理(wire)模式下,包表面同时作用于系统提示词与注入的工具描述,且遵循全局 → provider → model 的完整三级级联;原生插件模式(pi/omp/dsh/opencode/MCP 车道)中,注册的工具描述只跟随**顶层** `compress.promptPack` —— 插件清单是静态的、与会话无关(宿主在任何请求到达前就拉取它,拿不到 model 上下文),而每请求的系统提示词仍遵循 provider/model 层的包。若希望所有 model 的工具描述都跟随包,请在顶层设置 `promptPack`。 #### `reconcile` From d23197db3c0e5bc6bda57e221196a09e43f2436d Mon Sep 17 00:00:00 2001 From: awork Date: Thu, 15 Oct 2026 13:36:03 +0800 Subject: [PATCH 3/3] test: harden #1706 stall-guard first-byte assertion against loaded-CI timing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Observed flake while reviewing #3247: CI run 38683949356, shard 'test (windows-latest, 22, 2)' failed this test with 'first chunk should have flowed through' — the fixed 2s wall-clock sleep expired before the first byte arrived on the loaded runner; rerun of the same job on the same head passed. Replace the fixed sleep with a bounded poll (first byte or 15s deadline); all three assertions keep their teeth (a real non-streaming bug still fails at the deadline). --- tests/issue1452-socket-hardening.test.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/issue1452-socket-hardening.test.ts b/tests/issue1452-socket-hardening.test.ts index 1958f7a62c..e4d8288a91 100644 --- a/tests/issue1452-socket-hardening.test.ts +++ b/tests/issue1452-socket-hardening.test.ts @@ -400,7 +400,14 @@ test("retired stall guard: mid-stream silence survives any short window even wit }, ); req.end(STREAM_BODY); - await new Promise((r) => setTimeout(r, 2000)); + // Poll for the first byte instead of a fixed 2s sleep: on loaded CI + // runners the first byte can legitimately take longer (observed flake, + // windows shard 2026-10-15, rerun green); a real non-streaming bug + // still fails here at the 15s deadline. + const firstByteDeadline = Date.now() + 15_000; + while (seen.length === 0 && Date.now() < firstByteDeadline) { + await new Promise((r) => setTimeout(r, 50)); + } const soFar = seen.join(""); assert.ok(soFar.length > 0, "first chunk should have flowed through"); assert.ok(!soFar.includes("stream error"), `retired guard must not emit a truncation error: ${soFar.slice(0, 300)}`);