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
11 changes: 10 additions & 1 deletion CLIENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,23 @@ Two lanes, same plugin (#941):
settings overlay rewrites those providers' `baseURL`s to `/bili/` URLs, so
the traffic reaches the proxy regardless of which fetch the transport uses
or what the attribution state is.
- **Web-profile caveat (#1772):** when a profile's bundles include
`@deepseek-ai/dsh-web-app`, the running `compaction-basic` instance lives
inside an agent preset (`preset-standard.config.plugins`) that no patch
layer can reach by id — dsh's patch engine indexes only top-level rows and
true group children — so the bundled `auto: false` lands on web-app's
already-disabled host-plane row and the preset instance keeps
auto-compaction ON. The plugin logs a one-time `[dsh-client]` warning at
boot in such profiles; ACP compression is unaffected.

Under a `bili dsh` launch the plugin ATTACHES to the launcher's proxy (no
second spawn). Raw upstream URLs rewrite to `<proxy>/bili/<url>` like
spawn mode (a loopback proxy target is never proxied, so the MITM envs are
simply bypassed); already-routed `/bili/`-prefixed requests pass through
untouched except for header stamping. Known limitation: manual
`/compact` has no dsh-side event hook, so its boundary is left to the
kernel's natural ingest diff (auto-compaction is off, so this is rare).
kernel's natural ingest diff (auto-compaction is off in non-web profiles, so
this is rare; see the #1772 caveat above for web profiles).

## Kimi Code (Moonshot)

Expand Down
3 changes: 2 additions & 1 deletion CLIENTS.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
- **Profile 安装(免启动器)——统一泳道(#966):** `bili plugin install dsh` 对每个已存在的 profile 执行 `dsh plugin --profile <name> add billion-context` —— pnpm 把包装进各 profile 自己的 `node_modules`,dsh 自动挂载包内 patch 层(`dsh.bundle.patch.yml`)。装哪个源取决于 bili 自身的安装形态(#925):npm 安装传注册表名,checkout/dev 构建传绝对路径(`link:` 依赖,本地改动实时生效)。旧版受管块(`# bili begin` / `# bili end`,#966 之前的安装所写)在安装与卸载时都会被剥离 —— 用户条目与注释保留,清空的文件还原占位 `[]`。先在每个 profile 里跑过一次 dsh 让目录存在。插件加载时自拉起代理(已有健康实例则附看,不重复拉;父进程 pid 看门狗),经全局 fetch 补丁把模型流量改写为 `<proxy>/bili/<上游URL>`,原样注册清单工具,并按工具就绪门控 plugin 模式头(第一轮走 wire 模式)。退出开关:`BILI_NATIVE_DSH=0`。卸载:`bili plugin remove dsh` 或 `dsh plugin --profile <name> remove billion-context` —— 两者走同一通道。经注册表安装要求 npm 上已发布含 `dsh.bundle.patch.yml` 的版本。若 add 后 dsh 启动即报 `billion-context/dsh` 的 `ERR_MODULE_NOT_FOUND`,说明 profile 从陈旧的包元数据缓存里解析到了不含 bundle 子路径导出的旧版本(#953)——固定版本重装:`dsh plugin --profile <name> add billion-context@latest`。
- **自动更新保持各 profile 同步:** 刷新有两个触发器 —— 全局自更新完成后,以及**profile 自己的代理**在周期检查里发现注册表有新版本时(全局 bili 从不运行也一样刷新,#1196 —— 插件市场安装的用户往往根本没有全局安装)。两种触发器都扫描 `~/.dsh/profiles/*/package.json`,把注册表钉住的 `billion-context` 依赖刷新到目标版本(全局触发器刷到新全局版本,自触发刷到注册表最新),统一经 dsh 自己的 `plugin add` 通道,绝不在位覆盖 —— 加载的插件与代理从此不再漂移(#953);钉在本地源的 profile 不动。刷新是尽力而为,失败下个周期重试,绝不会让代理或更新本身失败。
- **已报告:Profile 安装下部分传输零代理流量(#1158,调查中):** dsh `llm-pi-ai` 层的部分传输服务会话**从未有任何模型请求到达代理**(日志无 `processTurn`,调用 bili 工具返回 404 "no model request has arrived"),而同宿主的其他 provider 正常。根因仍在用运行时证据定性 —— 候选:传输层 fetch 形态(SDK 注入 fetch / 非全局 dispatcher)或宿主侧归属缺口导致流量未被 takeover gate 认领。检测:此类情况会打一次性 `[plugin] NO MODEL REQUESTS seen for conversation …` 告警,dsh 插件还会把归属 gate 放行的每个端点各记一条日志(每进程一次)。期间可靠规避:改用 `bili dsh` 启动 —— 启动器的 settings overlay 会把那些 provider 的 `baseURL` 重写为 `/bili/` URL,无论传输层使用哪种 fetch、归属状态如何,流量都必然过代理。
- **Web profile 说明(#1772):** 当 profile 的 bundles 含 `@deepseek-ai/dsh-web-app` 时,真正运行的 `compaction-basic` 实例位于 agent preset(`preset-standard.config.plugins`)内部 —— dsh 的 patch 引擎只按 id 索引顶层条目与真 group(`group: true` 且 config 为数组)的子项,preset 内的嵌套行任何 patch 层都够不到。于是 bundle 里的 `auto: false` 落在 web-app 已禁用的宿主平面行上,preset 实例保持自动压缩开启。此类 profile 启动时插件打一条一次性 `[dsh-client]` 告警;ACP 压缩不受影响。

`bili dsh` 启动下插件**附看**(attach)启动器的代理(不二次拉起)。裸上游 URL 与 spawn 模式一样重写为 `<proxy>/bili/<url>`(回环代理目标永不被代理 env 拦截,等于直接绕开 MITM);已经路由的 `/bili/` 前缀请求原样放行、只盖章。已知局限:手动 `/compact` 没有 dsh 侧事件钩子,其边界交给内核的自然 ingest diff(自动压缩已关,影响罕见)。
`bili dsh` 启动下插件**附看**(attach)启动器的代理(不二次拉起)。裸上游 URL 与 spawn 模式一样重写为 `<proxy>/bili/<url>`(回环代理目标永不被代理 env 拦截,等于直接绕开 MITM);已经路由的 `/bili/` 前缀请求原样放行、只盖章。已知局限:手动 `/compact` 没有 dsh 侧事件钩子,其边界交给内核的自然 ingest diff(非 web profile 下自动压缩已关,影响罕见;web profile 见上方 #1772 说明)。

## Kimi Code(Moonshot)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ bili claude # launch claude through the proxy
bili omp # pi-style, file-free (#535): env + extension registerProvider + compaction cancel, real ~/.omp untouched
bili opencode # OpenCode (1.x & 2.x): full guide in the [OpenCode](CLIENTS.md#opencode) section below
bili hermes # file-free (#535): hermes proxy env (HTTPS_PROXY + combined CA bundle via SSL_CERT_FILE) — https via CONNECT MITM, http via absolute-form forward proxy; real ~/.hermes untouched
bili dsh # deepseek-harness: full native plugin injected via --patch (#941) — real dsh tools, session-bound /acp + /acp-cache (plugin mode); non-loopback upstreams ride proxy envs, loopback keeps the overlay DSH_HOME rewrite (#535); dsh auto-compaction off
bili dsh # deepseek-harness: full native plugin injected via --patch (#941) — real dsh tools, session-bound /acp + /acp-cache (plugin mode); non-loopback upstreams ride proxy envs, loopback keeps the overlay DSH_HOME rewrite (#535); dsh auto-compaction off outside web profiles (#1772)
bili codebuddy # Tencent CodeBuddy Code CLI: CODEBUDDY_BASE_URL /bili/ rewrite (OpenAI chat completions wire), budget aligned via CODEBUDDY_AUTO_COMPACT_WINDOW; real ~/.codebuddy untouched
bili qoder # qoder: model endpoint is hardcoded https (no /bili/ rewrite possible) — cert-MITM via HTTPS_PROXY + NODE_EXTRA_CA_CERTS, default model hosts whitelisted (#653)
bili trae # Trae CLI (ByteDance, closed Go binary, no base-URL override) — cert-MITM via HTTPS_PROXY + SSL_CERT_FILE, model host from TRAE_CLI_API_HOST or the default enterprise gateway (#655)
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ bili claude # 拉起 claude
bili omp # pi 同款,file-free(#535):环境变量 + 扩展 registerProvider + 压缩取消,真实 ~/.omp 不动
bili opencode # OpenCode(1.x 与 2.x):完整指南见下文 [OpenCode](CLIENTS.zh-CN.md#opencode) 一节
bili hermes # file-free(#535):hermes 代理环境变量(HTTPS_PROXY + SSL_CERT_FILE 组合 CA bundle)—— https 走 CONNECT MITM,http 走绝对形式转发;真实 ~/.hermes 不动
bili dsh # deepseek-harness:经 --patch 注入完整原生插件(#941) —— 真实 dsh 工具、会话绑定 /acp(plugin 模式);非回环上游走代理 env,回环保留 overlay DSH_HOME 改写(#535);dsh 自动压缩关
bili dsh # deepseek-harness:经 --patch 注入完整原生插件(#941) —— 真实 dsh 工具、会话绑定 /acp(plugin 模式);非回环上游走代理 env,回环保留 overlay DSH_HOME 改写(#535);dsh 自动压缩关(web profile 除外——preset 内实例无法经 patch 触及,#1772)
bili codebuddy # Tencent CodeBuddy Code CLI:CODEBUDDY_BASE_URL /bili/ 重写(OpenAI chat completions wire),预算对齐走 CODEBUDDY_AUTO_COMPACT_WINDOW;真实 ~/.codebuddy 不动
bili qoder # qoder:模型端点硬编码 https(无法 /bili/ 改写)—— 证书 MITM(HTTPS_PROXY + NODE_EXTRA_CA_CERTS),默认模型主机已加白名单(#653)
bili trae # Trae CLI(字节跳动,闭源 Go 二进制,无 base-URL 覆盖)—— 证书 MITM(HTTPS_PROXY + SSL_CERT_FILE),模型主机取 TRAE_CLI_API_HOST 或默认企业网关(#655)
Expand Down
38 changes: 38 additions & 0 deletions src/agent/dsh-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ type PluginContext = {
// builds or stripped hosts keep the plugin alive without model info).
llm?: { resolveModelInfo?: (provider: string, model: string, signal?: AbortSignal) => Promise<{ context?: { contextWindow?: number }; defaultMaxTokens?: number } | undefined> };
agentDefaultModel?: { currentSelection?: () => { provider?: string; model?: string } | undefined };
// #1772: boot-provided profile diagnostics ({startedBundles, ...}) — lets
// the plugin warn when the active profile runs its compaction inside an
// agent preset where the bundle patch cannot reach it.
profileContext?: { startedBundles?: readonly string[] | undefined };
inject?: (deps: readonly string[], callback: (sub: PluginContext) => void) => unknown;
// #1590: host event bus (web-profile hosts only) — webserver/index-inject
// gathers per-startup rows for the web index; we push the __BILI__ global
Expand Down Expand Up @@ -120,6 +124,10 @@ type RegisterState = { base: string | undefined; toolsReady: boolean; dead: bool

const register: RegisterState = { base: undefined, toolsReady: false, dead: false, retryAt: 0, pending: undefined };

// #1772: once-per-process — the web-profile compaction caveat is logged a
// single time even though apply() may run again after context re-arming.
let webProfileWarned = false;

// Runtime-info cache (#955): the host's current model selection plus what
// ctx.llm resolved for it (contextWindow / defaultMaxTokens). Written by an
// async refresh; read synchronously by headersFor on every model request.
Expand Down Expand Up @@ -738,6 +746,31 @@ export function apply(ctx: PluginContext): void {
refreshModelInfo(register.base ?? state.origin);
}

// #1772: in profiles bundling @deepseek-ai/dsh-web-app the RUNNING
// compaction-basic instance sits inside an agent preset (preset-standard's
// config.plugins), which no patch layer can reach by id — the bundled
// `auto: false` lands on web-app's already-disabled host-plane row and the
// preset instance keeps auto-compaction ON. Surface it once through the
// durable channel (GUI hosts swallow stderr); ACP compression is unaffected.
if (!webProfileWarned) {
let bundles: readonly string[] | undefined;
try {
if (typeof ctx.inject === "function") {
ctx.inject(["profileContext"], (sub) => {
bundles = sub.profileContext?.startedBundles;
});
} else {
bundles = ctx.profileContext?.startedBundles;
}
} catch {
// older dsh builds without the service: diagnostic only
}
if (bundles !== undefined && bundles.includes("@deepseek-ai/dsh-web-app")) {
webProfileWarned = true;
persistClientEvent("profile bundles include @deepseek-ai/dsh-web-app — its agent presets run their own compaction-basic where the bundle patch cannot set auto:false (#1772); dsh native auto-compaction stays enabled in this profile (ACP compression unaffected)");
}
}

// #1677: forward the host-passed invocation — it carries the invoking agent's
// session id, which the command path cannot recover from currentInitiator().
ctx.commands.register({
Expand Down Expand Up @@ -801,3 +834,8 @@ export function _resetRoutedForTest(): void {
state.routedOrigin = undefined;
state.onRoutedOriginObserved = undefined;
}

/** Test hook (#1772): reset the once-per-process web-profile warning flag. */
export function _resetWebProfileWarningForTest(): void {
webProfileWarned = false;
}
62 changes: 61 additions & 1 deletion tests/dsh-native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import os from "node:os";
import path from "node:path";
import http from "node:http";
import { pathToFileURL } from "node:url";
import { apply, planNativeDsh, shouldBootstrapNativeDsh, persistClientEvent, _resetRegisterForTest, _setSpawnForTest, _stateHeadersForTest, _stateRespawnForTest, _stateTakeoverGateForTest, _noteRoutedForTest, _resetRoutedForTest } from "../src/agent/dsh-native.ts";
import { apply, planNativeDsh, shouldBootstrapNativeDsh, persistClientEvent, _resetRegisterForTest, _setSpawnForTest, _stateHeadersForTest, _stateRespawnForTest, _stateTakeoverGateForTest, _noteRoutedForTest, _resetRoutedForTest, _resetWebProfileWarningForTest } from "../src/agent/dsh-native.ts";
import { rmrf } from "./tmp-rm.ts";

// #1365: legacy dead-attach suites must not pay the 5s routed-evidence grace
Expand Down Expand Up @@ -428,6 +428,8 @@ function mockCtx() {
// replay them through the same dynamic ctx.inject path production uses.
let llm: { resolveModelInfo?: (provider: string, model: string) => Promise<{ context?: { contextWindow?: number }; defaultMaxTokens?: number } | undefined> } | undefined = undefined;
let agentDefaultModel: { currentSelection?: () => { provider?: string; model?: string } | undefined } | undefined = undefined;
// #1772 profile diagnostics: replayed through the same dynamic inject path.
let profileContext: { startedBundles?: readonly string[] } | undefined = undefined;
return {
tools: { register: (t: RegisteredTool) => tools.push(t) },
commands: { register: (c: { name: string; handler: (invocation?: { agent?: { session?: { id?: unknown } } }) => Promise<{ kind: string; text: string }> }) => commands.push(c) },
Expand All @@ -439,11 +441,15 @@ function mockCtx() {
if (deps.includes("llm") && deps.includes("agentDefaultModel") && llm !== undefined && agentDefaultModel !== undefined) {
callback({ llm, agentDefaultModel });
}
if (deps.includes("profileContext") && profileContext !== undefined) {
callback({ profileContext });
}
},
setModelServices: (l: typeof llm, a: typeof agentDefaultModel) => {
llm = l;
agentDefaultModel = a;
},
setProfileContext: (pc: { startedBundles?: readonly string[] } | undefined) => (profileContext = pc),
};
}

Expand Down Expand Up @@ -757,6 +763,60 @@ test("apply() is a no-op under the kill switches", async () => {
}
});

test("#1772 apply(): web-profile compaction caveat warns once in the durable log", async () => {
const proxy = await startMockProxy([]);
const home = fs.mkdtempSync(path.join(os.tmpdir(), "bili-dsh-webwarn-"));
const stateHome = fs.mkdtempSync(path.join(os.tmpdir(), "bili-dsh-webwarn-state-"));
const logFile = path.join(stateHome, "billion-context", "bili.log");
const warnLines = (): string[] => fs.existsSync(logFile)
? fs.readFileSync(logFile, "utf8").split("\n").filter((l) => l.includes("[dsh-client]") && l.includes("@deepseek-ai/dsh-web-app"))
: [];
const webBundles = ["@deepseek-ai/dsh-base", "@deepseek-ai/dsh-web-app", "billion-context"];
try {
await withEnv({ DSH_HOME: home, BILLION_CONTEXT_PROXY: proxy.origin, XDG_STATE_HOME: stateHome, BILI_PROVIDER_REWRITES: undefined, BILI_NATIVE_DSH: undefined, BILLION_CONTEXT_PLUGIN: undefined }, async () => {
_resetRegisterForTest(proxy.origin);
_resetWebProfileWarningForTest();
const ctx = mockCtx();
ctx.setProfileContext({ startedBundles: webBundles });
apply(ctx);
assert.equal(warnLines().length, 1);
assert.match(warnLines()[0], /#1772/);

// once-per-process: a later apply with the same profile adds nothing
const again = mockCtx();
again.setProfileContext({ startedBundles: webBundles });
apply(again);
assert.equal(warnLines().length, 1);

// non-web profile → no warning
fs.rmSync(logFile, { force: true });
_resetRegisterForTest(proxy.origin);
_resetWebProfileWarningForTest();
const plain = mockCtx();
plain.setProfileContext({ startedBundles: ["@deepseek-ai/dsh-base", "@deepseek-ai/dsh-headless", "billion-context"] });
apply(plain);
assert.equal(warnLines().length, 0);

// host shape without inject but with a direct profileContext field
_resetWebProfileWarningForTest();
const bare: Parameters<typeof apply>[0] = {
tools: { register: () => undefined },
commands: { register: () => undefined },
agents: {},
profileContext: { startedBundles: ["@deepseek-ai/dsh-web-app"] },
};
apply(bare);
assert.equal(warnLines().length, 1);
});
} finally {
proxy.close();
fs.rmSync(home, { recursive: true, force: true });
fs.rmSync(stateHome, { recursive: true, force: true });
_resetRegisterForTest(undefined);
_resetWebProfileWarningForTest();
}
});

test("apply() runtime-info (#955): model services stamp model/window/max-output headers", async () => {
const proxy = await startMockProxy([]);
const home = fs.mkdtempSync(path.join(os.tmpdir(), "bili-dsh-ri-"));
Expand Down
Loading