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
1 change: 1 addition & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed
| `BILI_NATIVE_OPENCODE` | boolean-ish | off | — | Host posture: marks an opencode-native plugin process. |
| `BILI_NATIVE_PI` | boolean-ish | off | — | Host posture: marks a pi-native plugin process. |
| `BILI_PI_INLINE` | boolean-ish | off | — | Host posture: pi inline lane (#3278) — the pi extension compresses IN-PROCESS through the pseudo-origin instead of spawning its own proxy; outranks a preset BILLION_CONTEXT_PROXY attach target. Truthy = any non-empty value except 0/false/no/off (on/yes/TRUE all enable; a miss used to silently fall back to spawning a proxy). Codex Responses WS traffic is routed through a loopback-only bridge booted with the engine; if that bridge fails, the WS lane degrades DIRECT (warned) while HTTP compression stays in-process. |
| `BILI_INLINE_DEBUG` | boolean-ish | off | — | Inline lane (#3278) only: keep the engine's log lines on stderr after muting them (the inline engine runs inside the pi process, where stderr is the interactive TUI — every [persist]/[storage]/[inline] line would scroll the input box away; default keeps them in bili.log only). |
| `BILI_NATIVE_ZCODE` | boolean-ish | off | — | Host posture: marks a zcode-native plugin process. |
| `BILI_PI_BIN` | string | pi (PATH lookup) | — | Host posture: explicit binary path for the pi client binary. |
| `BILI_DSH_BIN` | string | dsh (PATH lookup) | — | Host posture: explicit binary path for the dsh client binary. |
Expand Down
1 change: 1 addition & 0 deletions CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@
| `BILI_NATIVE_OPENCODE` | boolean-ish | off | — | 宿主姿态:标记 opencode 原生插件进程。 |
| `BILI_NATIVE_PI` | boolean-ish | off | — | 宿主姿态:标记 pi 原生插件进程。 |
| `BILI_PI_INLINE` | boolean-ish | off | — | 宿主姿态:pi 内联压缩通道(#3278)——pi 扩展在进程内通过伪源站直接压缩,不再另起代理进程;优先于预置的 BILLION_CONTEXT_PROXY 附着目标。除 0/false/no/off 外任何非空值均算开启(on/yes/TRUE 均可;旧版不认这些写法会静默回退成另起代理)。codex 的 Responses WS 流量改走随引擎启动的仅回环桥;桥起不来时该通道退回直连(打 warn),HTTP 压缩仍留在进程内。 |
| `BILI_INLINE_DEBUG` | boolean-ish | off | — | 仅内联通道(#3278):把引擎日志保留在 stderr 上(默认关闭——内联引擎跑在 pi 进程里,stderr 就是交互终端,每行 [persist]/[storage]/[inline] 都会把输入框挤掉;默认只写 bili.log)。 |
| `BILI_NATIVE_ZCODE` | boolean-ish | off | — | 宿主姿态:标记 zcode 原生插件进程。 |
| `BILI_PI_BIN` | string | pi (PATH lookup) | — | 宿主姿态:pi 客户端二进制的显式路径。 |
| `BILI_DSH_BIN` | string | dsh (PATH lookup) | — | 宿主姿态:dsh 客户端二进制的显式路径。 |
Expand Down
1 change: 1 addition & 0 deletions scripts/ci-pretest-cache.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const MARKER_NAME: string;
export const COMPONENTS: PretestCacheComponent[];
export function hashComponent(root: string, comp: PretestCacheComponent, platform?: string): string;
export function markerIsFresh(distDir: string, hash: string): boolean;
export function refreshDistMtimes(distDir: string, now?: Date): number;
export function runPretestCache(opts?: {
root?: string;
components?: PretestCacheComponent[];
Expand Down
6 changes: 4 additions & 2 deletions src/agent/dsh-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1284,8 +1284,10 @@ function noteForkVerdict(verdict: Extract<ForkChildVerdict, { ok: false }>): voi
// exactly what #4215 needs named in the log (C10b).
if (noticedForkBlindSpot) return;
noticedForkBlindSpot = true;
const scoped = sidScope.getStore();
const scopedActive = typeof scoped === "string" && scoped.length > 0;
// #4491 generalized the scope to LlmDispatchScope (dispatchScope);
// scoped attribution is active when that store carries a sid.
const scopedStore = dispatchScope.getStore();
const scopedActive = scopedStore !== undefined && typeof scopedStore.sid === "string" && scopedStore.sid.length > 0;
const shape =
verdict.reason === "initiator-threw" ? `threw (${verdict.detail ?? "unknown"})`
: verdict.reason === "initiator-missing" ? "returned no agent"
Expand Down
2 changes: 2 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Usage:
bili [start] [options] start the proxy (default: reads ${defaultConfigFile()})
bili pi [opts --] [args] start a proxy + launch pi against it (cert-MITM)
bili pi-test [opts --] [args] like bili pi but injects --no-extensions (clean test)
bili pi-inline [opts --] [args] launch pi on the in-process engine — no proxy at all (BILI_PI_INLINE)
bili codex [opts --] [args] start a proxy + launch codex against it (cert-MITM)
bili claude [opts --] [args] start a proxy + launch claude against it (cert-MITM)
bili omp [opts --] [args] start a proxy + launch omp against it (cert-MITM)
Expand Down Expand Up @@ -132,6 +133,7 @@ Launcher (bili pi / bili codex / bili claude / bili omp / bili opencode / bili h
bili pi # launch pi through the proxy
bili pi -- print "hi" # args after the client are passed through
bili pi-test # pi through the proxy with extensions off (proxy owns compression)
bili pi-inline # pi with the in-process engine — no proxy, no MITM certs
bili codex # launch codex through the proxy
bili claude # launch claude through the proxy
bili omp # launch omp through the proxy (pi-based; /bili/ rewrite)
Expand Down
12 changes: 11 additions & 1 deletion src/inline-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { createEngineContext, type EngineContext } from "./server.js";
import { handle } from "./server/handle.js";
import { withFetchTransport } from "./fetch-transport.js";
import type { FetchOptions } from "./fetch-util.js";
import { log as loggerLog } from "./logger.js";
import { log as loggerLog, muteStderrLeg } from "./logger.js";

/** Pseudo-origin of the inline lane. Never DNS-resolved: any request reaching
* this host is served in-process by installInlineTransport before egress. */
Expand Down Expand Up @@ -359,6 +359,16 @@ export function _resetInlineEngineForTest(): void {
}

async function startInlineEngine(): Promise<InlineEngine> {
// The engine runs INSIDE the host agent's process (#3278 inline lane),
// and that process's stderr IS the interactive TUI terminal (pi, dsh,
// …). The tee logger's stderr leg would print every engine line —
// storage mode, persist warm-up, the background index scan 1-2 s after
// boot — straight onto the TUI, scrolling the input box away (field
// report: "启动的时候都是日志 输入框没了"). Keep the durable bili.log file
// leg, mute the terminal leg; the logger re-enables stderr itself if the
// file leg ever dies (#2864), and BILI_INLINE_DEBUG=1 opts back in for
// live troubleshooting.
if (!process.env.BILI_INLINE_DEBUG) muteStderrLeg();
// Same pre-flight as the CLI server path (cli.ts `start`): template
// config, resolved options, sqlite engine self-bootstrap (#2833).
ensureConfigTemplate();
Expand Down
50 changes: 48 additions & 2 deletions src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ import { conflictRemediation } from "./conflict-watch.js";
import { conflictScanEnabled, isDesignBenign, scanClientPlugins } from "./thirdparty-scan.js";

export const LAUNCHER_DEFAULT_HOST = "127.0.0.1";
export const LAUNCH_CLIENTS = ["pi", "codex", "claude", "omp", "opencode", "hermes", "dsh", "codebuddy", "qoder", "trae", "jcode", "kimi", "gemini", "iflow", "qwen", "mcode", "aider", "copilot", "amp", "crush", "zed", "goose", "antigravity", "pi-test"] as const;
export const LAUNCH_CLIENTS = ["pi", "codex", "claude", "omp", "opencode", "hermes", "dsh", "codebuddy", "qoder", "trae", "jcode", "kimi", "gemini", "iflow", "qwen", "mcode", "aider", "copilot", "amp", "crush", "zed", "goose", "antigravity", "pi-test", "pi-inline"] as const;
export type ClientName = (typeof LAUNCH_CLIENTS)[number];
type BaseClientName = "claude" | "codex" | "pi" | "omp" | "opencode" | "hermes" | "dsh" | "codebuddy" | "qoder" | "trae" | "jcode" | "kimi" | "gemini" | "iflow" | "qwen" | "mcode" | "aider" | "copilot" | "amp" | "crush" | "zed" | "goose" | "antigravity";

Expand Down Expand Up @@ -333,7 +333,7 @@ export function isLaunchClient(value: string): value is ClientName {
}

export function baseClientName(client: ClientName): BaseClientName {
return client === "pi-test" ? "pi" : client;
return client === "pi-test" || client === "pi-inline" ? "pi" : client;
}

/** `pi-test` injects `--no-extensions` so the billion-context-pi client extension doesn't double-compress alongside the proxy. */
Expand Down Expand Up @@ -5763,6 +5763,52 @@ export async function runLaunch(params: RunLaunchParams, deps: LauncherDeps = {}
);
}
}
// `bili pi-inline` (#3278/#4526): launch pi on the IN-PROCESS engine — no
// proxy is spawned at all. BILI_PI_INLINE outranks ambient attach envs in
// planNativePi, so the child's own bili extension arms inline mode and
// (with the loopback WS bridge) also takes the codex WebSocket lane. The
// extension MUST be loadable here: with no proxy there is no wire-mode
// fallback, so a missing extension would silently run uncompressed.
if (params.client === "pi-inline") {
const piExt = selfDistFile("agent/pi.js");
const extAvailable = (piExt !== undefined && fs.existsSync(piExt)) || piPluginInstalled(piRealHome);
if (!extAvailable) {
console.error(
"bili: pi-inline needs the bili pi extension — run `bili plugin install pi` or reinstall billion-context " +
"(dist/agent/pi.js missing and the plugin is not installed in " + piRealHome + "/settings.json)",
);
process.exit(2);
return;
}
// Clean slate for the child: a stale inherited BILLION_CONTEXT_PROXY
// would make planNativePi ATTACH instead of arming the in-process
// engine, and inherited proxy/MITM env has nothing to do inline (no
// TLS is terminated in this lane).
const inlineEnv = stripInheritedProxy(process.env);
delete inlineEnv.BILLION_CONTEXT_PROXY;
delete inlineEnv.BILI_MITM_HOSTS;
inlineEnv.BILI_PI_INLINE = "1";
let inlineArgs = params.clientArgs;
// Same single-load rule as the proxy lane: when settings.json already
// loads the plugin, `-e` on top would double-register it.
if (piExt && fs.existsSync(piExt) && !piPluginInstalled(piRealHome)) {
inlineArgs = ["-e", piExt, ...inlineArgs];
}
console.error("bili: pi-inline — compression runs inside pi (in-process engine + loopback WS bridge); no proxy is started.");
const { command, prefixArgs } = resolveClientCommand("pi", process.env, deps.platform ?? process.platform);
let inlineCode = 0;
try {
inlineCode = await runClient(command, [...prefixArgs, ...inlineArgs], inlineEnv, {
spawnImpl: deps.spawnImpl,
platform: deps.platform,
});
} catch (err) {
console.error(`bili: failed to launch pi-inline: ${err instanceof Error ? err.message : String(err)}`);
inlineCode = 1;
}
process.exit(inlineCode ?? 0);
return;
}
if (base === "omp" && routes.httpRewrites.length > 0) {
const ompExt = selfDistFile("agent/omp.js");
const extAvailable = (ompExt !== undefined && fs.existsSync(ompExt)) || ompPluginLoadedFrom(ompRealHome);
Expand Down
Loading
Loading