Skip to content
9 changes: 5 additions & 4 deletions src/client-ua-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// at ingest (UA_MAX_CHARS) so one hostile UA cannot bloat the pasteable blob.

import { isCodexClient } from "./codex-compact.js";
import { sniffScanClient } from "./thirdparty-scan.js";
import { isAntigravityClient, sniffScanClient } from "./thirdparty-scan.js";
import { safePrefix } from "./text-safe.js";

// Read directly (wire literal) instead of via plugin.ts — same discipline as
Expand All @@ -44,16 +44,17 @@ function headerString(headers: Record<string, string | string[] | undefined>, na
}

/** Client family for UA bookkeeping — mirrors conflictClientOf's resolution
* ladder (declared plugin agent > header sniff > codex UA shape) keyed off
* the raw request headers. "mcp" is not a client name (MCP evidence flip,
* #760b), so it falls through like in conflict-watch. */
* ladder (declared plugin agent > header sniff > codex/antigravity UA shape)
* keyed off the raw request headers. "mcp" is not a client name (MCP evidence
* flip, #760b), so it falls through like in conflict-watch. */
export function clientFamilyOf(headers: Record<string, string | string[] | undefined>): string {
const agent = headerString(headers, BILI_PLUGIN_MARKER);
if (agent && agent !== "mcp") return agent;
const sniffed = sniffScanClient(headers);
if (sniffed) return sniffed;
const ua = headerString(headers, "user-agent");
if (ua && isCodexClient({ "user-agent": ua })) return "codex";
if (ua && isAntigravityClient({ "user-agent": ua })) return "antigravity";
return OTHER_FAMILY;
}

Expand Down
10 changes: 7 additions & 3 deletions src/conflict-watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import { markDirty, type Session } from "./session.js";
import { isCodexClient } from "./codex-compact.js";
import { isDisplayOnlyConflictDetail, isSiblingConflictDetail } from "./thirdparty-scan.js";
import { isAntigravityClient, isDisplayOnlyConflictDetail, isSiblingConflictDetail } from "./thirdparty-scan.js";

type ConflictKind = "third-party-plugin" | "unannounced-rewrite" | "orphan-reap" | "native-compaction" | "native-compaction-inferred" | "identity-orphan" | "id-churn-adoption";

Expand Down Expand Up @@ -106,15 +106,17 @@ export function dshNativeCompactionWitness(session: Session, fingerprint?: Rewri
// Identity is already recorded at request time (#1426): pluginAgent wins when
// present ("mcp" is not a client name — MCP evidence flip, #760b — so fall
// through), then clientHint, which is either an exact sniffScanClient value or
// a UA truncation; codex UA shapes normalize back to "codex" and clean single
// tokens pass through as-is (unknown ones simply get the generic hint).
// a UA truncation; codex/antigravity UA shapes normalize back to their lane
// names (#2219/#4688) and clean single tokens pass through as-is (unknown ones
// simply get the generic hint).
export function conflictClientOf(session: Session): string | undefined {
const pa = session.metadata.pluginAgent;
if (typeof pa === "string" && pa.length > 0 && pa !== "mcp") return pa;
const hint = session.metadata.clientHint;
if (typeof hint !== "string" || !hint) return undefined;
if (/^[a-z][a-z0-9-]*$/.test(hint)) return hint;
if (isCodexClient({ "user-agent": hint })) return "codex";
if (isAntigravityClient({ "user-agent": hint })) return "antigravity";
return undefined;
}

Expand All @@ -138,6 +140,8 @@ export function conflictRemediation(client: string | undefined): string {
case "pi":
case "omp":
return "the bili extension cancels the client's native auto-compaction while it carries the conversation — seeing this suggests missing carriage evidence or an old version; report client + bili version";
case "antigravity":
return "Antigravity manages its own context window and periodically re-slices history without telling bili — expected lane behavior, not double compression; folded content stays offline-recoverable (export --full), but start a new task/session when you need the pruned context back";
default:
return "disable the client's own auto-compaction (or route this session around bili), then start a fresh session — the ledger is per-session, so old entries clear with the old session";
}
Expand Down
21 changes: 18 additions & 3 deletions src/thirdparty-scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,24 @@ export function conflictScanEnabled(env: NodeJS.ProcessEnv = process.env): boole
return !(v === "0" || v === "false");
}

/** #4688: Google Antigravity IDE wire profile — UA shape observed in the wild
* (v2.26.0, Windows session through bili): "antigravity/hub/<ver> (aidev_client; …)".
* Prefix-anchored and case-insensitive, mirroring isCodexClient's prefix style;
* deliberately NOT a bare-token match — a UA merely mentioning antigravity
* elsewhere must not inherit this lane's identity. */
export function isAntigravityClient(headers: Record<string, string | string[] | undefined>): boolean {
const ua = headers["user-agent"];
if (!ua) return false;
const s = Array.isArray(ua) ? ua[0] : ua;
if (typeof s !== "string") return false;
return /^antigravity\//i.test(s);
}

/** Identify the requesting client from wire headers so a standalone proxy
* (no x-bili-plugin header) can still scan the right registry. Codex is
* recognized but returns undefined — it has no scannable plugin registry
* here, and its compaction paths are already intercepted/budget-aligned. */
* (no x-bili-plugin header) can still scan the right registry. Codex and
* Antigravity are recognized but return undefined — closed binaries with no
* scannable plugin registry (#1043); their identity resolves on the conflict
* surfaces via conflictClientOf instead (#2219/#4688). */
export function sniffScanClient(headers: Record<string, string | string[] | undefined>): ScanClient | undefined {
const h = (name: string): string | undefined => {
const v = headers[name];
Expand All @@ -142,6 +156,7 @@ export function sniffScanClient(headers: Record<string, string | string[] | unde
if (h("x-claude-code-session-id")) return "claude";
const ua = h("user-agent");
if (ua && isCodexClient({ "user-agent": ua })) return undefined;
if (ua && isAntigravityClient({ "user-agent": ua })) return undefined;
if (h("x-opencode-session")) return "opencode";
const affinity = h("x-session-affinity");
if (affinity?.startsWith("ses_")) return "opencode";
Expand Down
1 change: 1 addition & 0 deletions src/web/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ export const WEB_CLIENT = `(function () {
case "codex": return t("conflict.hint.codex");
case "pi": return t("conflict.hint.pi");
case "omp": return t("conflict.hint.omp");
case "antigravity": return t("conflict.hint.antigravity");
default: return t("conflict.hint.generic");
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/web/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export const MESSAGES: Record<Locale, Record<string, string>> = {
"conflict.hint.codex": "codex:bili 默认拦截原生压缩(BILI_CODEX_COMPACT=intercept)——若你设了 pass,去掉该覆盖即可;否则请报告你的 bili 版本",
"conflict.hint.pi": "pi:bili 扩展在接管会话时会自动取消客户端原生自动压缩——仍出现说明缺少接管证据或版本过旧,请报告客户端与 bili 版本",
"conflict.hint.omp": "omp:bili 扩展在接管会话时会自动取消客户端原生自动压缩——仍出现说明缺少接管证据或版本过旧,请报告客户端与 bili 版本",
"conflict.hint.antigravity": "antigravity:客户端自行管理上下文窗口并会周期性重切历史(bili 无法阻止)——属该车道预期行为,不是双重压缩;被裁掉跨度上的折叠内容可离线找回(export --full),需要被裁剪的上下文时请开新任务/新会话",
"conflict.hint.generic": "关闭客户端自身的自动压缩(或让本会话绕过 bili),然后开新会话——台账按会话隔离,旧记录随旧会话消失",
"conflict.hint_more": "另有 {n} 个客户端,详见下方 Sessions 页",
"conflict.docs": "完整矩阵:docs/configuration.md「Detecting other compression plugins (#1206)」",
Expand Down Expand Up @@ -1017,6 +1018,7 @@ export const MESSAGES: Record<Locale, Record<string, string>> = {
"conflict.hint.codex": "codex: bili intercepts native compaction by default (BILI_CODEX_COMPACT=intercept) — if you set pass, remove the override to stop; otherwise report your bili version",
"conflict.hint.pi": "pi: the bili extension cancels the client's native auto-compaction while it carries the conversation — seeing this suggests missing carriage evidence or an old version; report client + bili version",
"conflict.hint.omp": "omp: the bili extension cancels the client's native auto-compaction while it carries the conversation — seeing this suggests missing carriage evidence or an old version; report client + bili version",
"conflict.hint.antigravity": "antigravity: the client manages its own context window and periodically re-slices history (bili cannot stop it) — expected lane behavior, not double compression; folded content stays offline-recoverable (export --full), but start a new task/session when you need the pruned context back",
"conflict.hint.generic": "disable the client's own auto-compaction (or route this session around bili), then start a fresh session — the ledger is per-session, so old entries clear with the old session",
"conflict.hint_more": "{n} more client(s) — see the Sessions page below",
"conflict.docs": "full matrix: docs/configuration.md → \"Detecting other compression plugins (#1206)\"",
Expand Down
16 changes: 14 additions & 2 deletions tests/conflict-remediation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ test("conflictClientOf: codex UA truncations normalize to codex, look-alikes do
assert.equal(conflictClientOf(makeSession("f", { clientHint: "claude" })), "claude");
});

test("conflictClientOf: antigravity UA shapes normalize to antigravity, look-alikes do not (#4688)", () => {
assert.equal(conflictClientOf(makeSession("a", { clientHint: "antigravity/hub/2.26.0 (aidev_client; os_type=windows; arch=amd64; cl=1005016104)" })), "antigravity");
assert.equal(conflictClientOf(makeSession("b", { clientHint: "Antigravity/hub/9.9.9" })), "antigravity");
// prefix-anchored only — a mention elsewhere in the UA is not this lane
assert.equal(conflictClientOf(makeSession("c", { clientHint: "vendor/antigravity-wrapper/1.0" })), undefined);
assert.equal(conflictClientOf(makeSession("d", { clientHint: "Mozilla/5.0 antigravity-fan-club" })), undefined);
});

test("conflictRemediation: one line per known client, generic fallback for the rest (#2219)", () => {
const oc = conflictRemediation("opencode");
assert.ok(oc.includes('"compaction": { "auto": false }'), oc);
Expand All @@ -71,12 +79,15 @@ test("conflictRemediation: one line per known client, generic fallback for the r
assert.ok(!cx.includes("never transits"), "#3008: the inline auto-compact DOES transit as an ordinary turn — the old copy was false");
assert.equal(conflictRemediation("pi"), conflictRemediation("omp"), "pi and omp share the carriage-evidence hint");
assert.ok(conflictRemediation("pi").includes("report client + bili version"));
const ag = conflictRemediation("antigravity");
assert.ok(ag.includes("not double compression"), ag);
assert.ok(ag.includes("export --full"), ag);
const gen = conflictRemediation(undefined);
assert.ok(gen.includes("fresh session"), gen);
for (const c of ["dsh", "kimi", "hermes", "zcode", "gemini-cli"]) {
assert.equal(conflictRemediation(c), gen, `${c} falls back to the generic hint`);
}
for (const c of ["opencode", "claude", "codex", "pi", "omp", undefined]) {
for (const c of ["opencode", "claude", "codex", "pi", "omp", "antigravity", undefined]) {
assert.ok(!conflictRemediation(c).includes("\n"), "hints render inline — one line only");
}
});
Expand Down Expand Up @@ -124,6 +135,7 @@ test("i18n: every conflict.hint.* key exists in BOTH locales; server map and web
"conflict.hint.codex",
"conflict.hint.pi",
"conflict.hint.omp",
"conflict.hint.antigravity",
"conflict.hint.generic",
"conflict.hint_more",
"conflict.docs",
Expand All @@ -134,7 +146,7 @@ test("i18n: every conflict.hint.* key exists in BOTH locales; server map and web
assert.ok(typeof zh === "string" && zh.length > 0, `zh-CN missing ${k}`);
assert.ok(typeof en === "string" && en.length > 0, `en missing ${k}`);
}
for (const c of ["opencode", "claude", "codex", "pi", "omp"]) {
for (const c of ["opencode", "claude", "codex", "pi", "omp", "antigravity"]) {
assert.ok(MESSAGES["zh-CN"][`conflict.hint.${c}`] && MESSAGES["en"][`conflict.hint.${c}`], `drift: ${c} missing from i18n`);
}
});
Expand Down
12 changes: 11 additions & 1 deletion tests/issue1206-thirdparty-scan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ process.env.NODE_ENV = "test";

import { createInitialState } from "acp-kernel";
import type { Session } from "../src/session.ts";
import { clearScanCache, conflictScanEnabled, isDesignBenign, isDisplayOnlyConflictDetail, isKnownDisplayOnlyPlugin, isDshLiveCompactEntry, isOpencodeAcpEntry, isSiblingConflictDetail, parsePluginConflictDetail, scanClientPlugins, sniffScanClient, type ThirdPartyFinding } from "../src/thirdparty-scan.js";
import { clearScanCache, conflictScanEnabled, isAntigravityClient, isDesignBenign, isDisplayOnlyConflictDetail, isKnownDisplayOnlyPlugin, isDshLiveCompactEntry, isOpencodeAcpEntry, isSiblingConflictDetail, parsePluginConflictDetail, scanClientPlugins, sniffScanClient, type ThirdPartyFinding } from "../src/thirdparty-scan.js";
import { CONFLICT_LEDGER_MAX, conflictEventsOf, formatConflictSection, recordConflict, summarizeConflicts } from "../src/conflict-watch.js";
import { resolveHermesHome, resolveKimiHome, resolveOmpHome, resolvePiHome } from "../src/client-config.js";
import { SessionStore, _setStoreForTest } from "../src/persist.js";
Expand Down Expand Up @@ -70,12 +70,22 @@ test("sniffScanClient identifies clients from wire headers", () => {
assert.equal(sniffScanClient({ "x-claude-code-session-id": "abc" }), "claude");
assert.equal(sniffScanClient({ "user-agent": "codex_cli_rs/0.50.0" }), undefined);
assert.equal(sniffScanClient({ "user-agent": "codex desktop/1.0" }), undefined);
// antigravity: recognized but no scannable registry — same contract as codex (#4688)
assert.equal(sniffScanClient({ "user-agent": "antigravity/hub/2.26.0 (aidev_client; os_type=windows)" }), undefined);
assert.equal(sniffScanClient({ "x-opencode-session": "ses_123" }), "opencode");
assert.equal(sniffScanClient({ "x-session-affinity": "ses_abc" }), "opencode");
assert.equal(sniffScanClient({ "x-session-affinity": "not-a-session" }), undefined);
assert.equal(sniffScanClient({}), undefined);
});

test("isAntigravityClient matches the antigravity/hub/ UA prefix only (#4688)", () => {
assert.equal(isAntigravityClient({ "user-agent": "antigravity/hub/2.26.0 (aidev_client; os_type=windows; arch=amd64; cl=1005016104)" }), true);
assert.equal(isAntigravityClient({ "user-agent": "Antigravity/hub/1.0" }), true);
assert.equal(isAntigravityClient({ "user-agent": "my-antigravity-tool/2.0" }), false);
assert.equal(isAntigravityClient({}), false);
assert.equal(isAntigravityClient({ "user-agent": [] }), false);
});

test("opencode scan: known conflict + keyword entries, self/context7 skipped", () => {
clearScanCache();
const root = tmp("bili-1206-oc-");
Expand Down
2 changes: 2 additions & 0 deletions tests/issue4649-conflict-report-client-coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ test("#4649 registry: family resolution mirrors the conflict ladder", () => {
assert.equal(clientFamilyOf({ "user-agent": "Codex Desktop/9.9.9" }), "codex", "capitalized variant prefix");
assert.equal(clientFamilyOf({ "user-agent": "vendor/tool codex_foo/1.0" }), "codex", "token-level lenient fallback (#645)");
assert.equal(clientFamilyOf({ "user-agent": "vendor/codex-wrapper" }), "other", "mid-token codex mention is NOT codex (#1641)");
assert.equal(clientFamilyOf({ "user-agent": "antigravity/hub/2.26.0 (aidev_client; os_type=windows)" }), "antigravity", "antigravity UA shape (#4688)");
assert.equal(clientFamilyOf({ "user-agent": "vendor/antigravity-wrapper/1.0" }), "other", "mid-token antigravity mention is NOT antigravity");
assert.equal(clientFamilyOf({ "x-claude-code-session-id": "s", "user-agent": "anything/1" }), "claude", "header sniff beats UA guess");
assert.equal(clientFamilyOf({ "x-opencode-session": "ses_1", "user-agent": "anything/1" }), "opencode", "opencode header sniff");
assert.equal(clientFamilyOf({ "x-bili-plugin": "dsh", "user-agent": "codex_cli_rs/1.0" }), "dsh", "declared plugin agent wins over UA shape");
Expand Down
Loading