From 642c42bde2f880b52023c68b7d52c99250695a50 Mon Sep 17 00:00:00 2001 From: awork Date: Fri, 9 Oct 2026 23:09:53 +0800 Subject: [PATCH 1/2] fix: tier conflict evidence - read-only viewers neutral, unconfirmed signals never escalate (#2545) --- CONFIGURATION.md | 4 +- CONFIGURATION.zh-CN.md | 4 +- src/conflict-watch.ts | 107 +++++++++++++++------ src/thirdparty-scan.ts | 54 ++++++++--- src/web/client.ts | 66 ++++++++----- src/web/i18n.ts | 10 ++ src/web/sessions-data.ts | 11 ++- tests/conflict-lifecycle.test.ts | 5 +- tests/issue1206-thirdparty-scan.test.ts | 120 +++++++++++++++++++++++- tests/web-conflict-banner.test.ts | 67 ++++++++++++- 10 files changed, 371 insertions(+), 77 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index a41d25970e..8909c081ad 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -2057,9 +2057,9 @@ Kill switch: `BILLION_CONTEXT_PLUGIN=0` disables plugin mode entirely (wire-leve Two compressors on one conversation double-compress and corrupt message refs, so bili actively looks for other compressors co-resident with itself: -- **Scan** (read-only, best-effort, 5-minute cache): opencode global + project config `plugin` arrays; pi global + project `.pi/settings.json` `packages`; omp `config.yml` `extensions`; claude settings `enabledPlugins`/`plugins` keys + `~/.claude/plugins/` dir; kimi `plugins/installed.json`; hermes `~/.hermes/plugins/` dir; dsh profile `package.json` dependencies. Two tiers: **known conflicts** (`opencode-acp`, legacy `billion-context-pi` — deterministic) and **keyword-suspected** entries (names matching compress / compact / acp / summar* / context*; bili's own entries are always skipped, non-compression tools like `context7` do not match). +- **Scan** (read-only, best-effort, 5-minute cache): opencode global + project config `plugin` arrays; pi global + project `.pi/settings.json` `packages`; omp `config.yml` `extensions`; claude settings `enabledPlugins`/`plugins` keys + `~/.claude/plugins/` dir; kimi `plugins/installed.json`; hermes `~/.hermes/plugins/` dir; dsh profile `package.json` dependencies. Two tiers: **known conflicts** (`opencode-acp`, legacy `billion-context-pi` — deterministic) and **keyword-suspected** entries (names matching compress* / compact* / acp / summar*; bare `context` deliberately does NOT match — it names the domain, not the act of compressing, so read-only tools like `context7`/`dsh-context` do not flag); verified read-only/display-only plugins (e.g. `pi-compact-transcript`, `pi-context-inspector`) are exempt outright. - **Where findings surface:** launcher stderr before the client starts; a proxy warn log on each session's first request (client identified from the `x-bili-plugin` header or wire headers); and the session's conflict ledger — `acp_status`'s `COMPRESSION CONFLICTS` section, `GET /__bili/stats` → `conflicts`, web-UI banner. -- **Runtime evidence:** unannounced history rewrites (#1001) and orphan-gc deactivations (summarized content deleted out of the client's history) are recorded in the same ledger, so *suspected* coexistence and *observed* interference cross-check each other. +- **Runtime evidence, tiered for display (#2545):** unannounced history rewrites (#1001) and orphan-gc deactivations (summarized content deleted out of the client's history) are recorded in the same ledger as *suspected* coexistence. Severity surfaces grade by EVIDENCE TIER: **confirmed** = a detected client-native compaction landing (bili rebases onto it, #2372/#2432) or a non-suspected plugin finding — only this triggers the imperative "keep one compressor" warning; **unconfirmed signals** = unannounced rewrites + orphan-gc deactivations — observed changes whose cause is NOT identified ("history changed, cause unknown"), never presented as native auto-compaction or a second compressor; name-only [suspected] matches stay in the soft "verify first" tier (#1736). Stock ledger records naming verified read-only plugins are neutralized at display time instead of persisting as alarms, and cross-session aggregate counts of unconfirmed signals never escalate to a same-conversation double-compression claim. - **dsh's `auto: false` disables only the automatic triggers.** The `compaction-basic: { auto: false }` line installed by the profile bundle patch (`dsh.bundle.patch.yml`) skips pressure/overflow auto-compaction — a manual `/compact` (and idle-session compaction) still fires. Calls routed through bili are refused by the server-side guard (#1729/#2360); calls that reach the provider without transiting bili (desktop-lane paths the plugin's takeover gate does not attribute) land, and bili detects them on the next replay — checkpoint framing + decimated fold coverage — rebasing its compression state in one turn instead of failing every later compress forever (#2432). #### Turning dsh native auto-compaction OFF in a web profile (#1772/#2474) diff --git a/CONFIGURATION.zh-CN.md b/CONFIGURATION.zh-CN.md index 3e3c7f2765..1e0a6752ca 100644 --- a/CONFIGURATION.zh-CN.md +++ b/CONFIGURATION.zh-CN.md @@ -2028,9 +2028,9 @@ bili plugin remove pi # 撤销(原文件一次性备份为 *.bili-bak) 两个压缩器作用于同一会话会双压缩、破坏消息引用,所以 bili 会主动查找与自己并存的另一个压缩器: -- **扫描**(只读、尽力而为、5 分钟缓存):opencode 全局 + 项目配置的 `plugin` 数组;pi 全局 + 项目 `.pi/settings.json` 的 `packages`;omp `config.yml` 的 `extensions`;claude 设置的 `enabledPlugins`/`plugins` 键 + `~/.claude/plugins/` 目录;kimi `plugins/installed.json`;hermes `~/.hermes/plugins/` 目录;dsh profile 的 `package.json` 依赖。两个层级:**已知冲突**(`opencode-acp`、遗留 `billion-context-pi`,确定性判定)和**关键词疑似**条目(名称匹配 compress / compact / acp / summar* / context*;bili 自身条目永远跳过,`context7` 这类非压缩工具不会误报)。 +- **扫描**(只读、尽力而为、5 分钟缓存):opencode 全局 + 项目配置的 `plugin` 数组;pi 全局 + 项目 `.pi/settings.json` 的 `packages`;omp `config.yml` 的 `extensions`;claude 设置的 `enabledPlugins`/`plugins` 键 + `~/.claude/plugins/` 目录;kimi `plugins/installed.json`;hermes `~/.hermes/plugins/` 目录;dsh profile 的 `package.json` 依赖。两个层级:**已知冲突**(`opencode-acp`、遗留 `billion-context-pi`,确定性判定)和**关键词疑似**条目(名称匹配 compress* / compact* / acp / summar*;裸 `context` 刻意不匹配——它指领域而非压缩动作本身,`context7`/`dsh-context` 这类只读工具不会误报);已验证的只读/仅显示插件(如 `pi-compact-transcript`、`pi-context-inspector`)直接豁免。 - **发现结果的出口**:客户端启动前的 launcher stderr;每个会话首个请求的一次性代理 warn 日志(client 由 `x-bili-plugin` 头或 wire 头识别);会话冲突台账 —— `acp_status` 的 `COMPRESSION CONFLICTS` 段、`GET /__bili/stats` → `conflicts`、Web UI 横幅。 -- **运行时证据**:未宣告的历史改写(#1001)与孤儿块废弃(被摘要的内容从客户端历史中被删掉)记入同一台账,让「疑似并存」与「实际观测到的干扰」互相印证。 +- **运行时证据,按证据层级展示(#2545)**:未宣告的历史改写(#1001)与孤儿块废弃(被摘要的内容从客户端历史中被删掉)与「疑似并存」记入同一台账。严重程度表面按**证据层级**分级:**已确认** = 检测到的客户端原生压缩落点(bili 会 rebase 到其上,#2372/#2432)或非 suspected 的插件发现——只有它会触发「请只保留一个压缩器」的强制告警;**未确认信号** = 未宣告改写 + 孤儿块废弃——观测到变化但原因未确认(「历史发生了变化,原因未知」),绝不呈现为原生自动压缩或第二个压缩器;纯名称匹配的 [suspected] 停留在软性的「先核实」层级(#1736)。指向已验证只读插件的存量台账记录在显示期被中和,而不是持续作为告警残留;跨会话聚合的未确认信号计数永远不会升级成「同一会话双压缩」的结论。 - **dsh 的 `auto: false` 只关闭自动触发**。profile bundle patch(`dsh.bundle.patch.yml`)写入的 `compaction-basic: { auto: false }` 跳过压力/溢出自压缩 —— 手动 `/compact`(以及空闲会话压缩)仍会触发。经 bili 路由的调用会被服务端闸门拒绝(#1729/#2360);未经过 bili 直达上游的调用(桌面端插件接管门无法归因的路径)会落地,bili 在下次重放时检测出来(checkpoint 框架 + 折叠覆盖缺口),一个 turn 内重建自己的压缩状态,而不是让之后每次 compress 永久失败(#2432)。 #### 在 web profile 下关掉 dsh 原生自动压缩(#1772/#2474) diff --git a/src/conflict-watch.ts b/src/conflict-watch.ts index a5f4b6c518..73a1464158 100644 --- a/src/conflict-watch.ts +++ b/src/conflict-watch.ts @@ -11,7 +11,7 @@ import { markDirty, type Session } from "./session.js"; import { isCodexClient } from "./codex-compact.js"; -import { isSiblingConflictDetail } from "./thirdparty-scan.js"; +import { isDisplayOnlyConflictDetail, isSiblingConflictDetail } from "./thirdparty-scan.js"; type ConflictKind = "third-party-plugin" | "unannounced-rewrite" | "orphan-reap" | "native-compaction"; @@ -107,13 +107,43 @@ function isSuspectedEvent(e: ConflictEvent): boolean { return e.kind === "third-party-plugin" && e.detail.endsWith("[suspected]"); } +// #2545: evidence tiers. NEUTRAL = records naming things that are NOT second +// compressors by verification: bili's own siblings (stand down while bili drives +// the session, #2261) and KNOWN_DISPLAY_ONLY read-only plugins (#2324/#2545). +// CONFIRMED = bili identified who rewrote the conversation: a detected +// native-compaction landing, or a plugin finding that is not name-only +// [suspected]. UNCONFIRMED SIGNALS = observations consistent with external +// rewriting whose CAUSE is not identified: unannounced rewrites (ref coverage +// dropped) and orphan reaps (summarized content left the client history). +// Severity surfaces must grade by tier — cross-session aggregate counts of +// unconfirmed signals are NOT evidence of same-conversation double compression. +function isNeutralEvent(e: ConflictEvent): boolean { + return e.kind === "third-party-plugin" && (isSiblingConflictDetail(e.detail) || isDisplayOnlyConflictDetail(e.detail)); +} + +export function isConfirmedConflictEvent(e: ConflictEvent): boolean { + if (e.kind === "native-compaction") return true; + if (e.kind !== "third-party-plugin") return false; + return !isNeutralEvent(e) && !isSuspectedEvent(e); +} + export function formatConflictSection(events: ConflictEvent[], now: number = Date.now(), client?: string): string[] { const lines: string[] = []; // #2102: label the age split up front — an all-historical section must not // read as a live alarm (it previously said "two compressors ..." imperatively // even when every event was months old). const { active, historical } = splitConflictEvents(events, now); - lines.push(`COMPRESSION CONFLICTS — ${events.length} event(s) in this session (${active.length} active · ${historical.length} historical; active = within ${CONFLICT_ACTIVE_WINDOW_MS / 86_400_000} days). Two compressors on one conversation (bili + another compression plugin — third-party or bili's own sibling — or client native compaction) double-compress and corrupt message refs:`); + // #2545: tier the ledger BEFORE choosing framing — the double-compression + // claim in the header is only made when confirmed evidence is present. + const meaningful = events.filter((e) => !isNeutralEvent(e)); + const confirmed = meaningful.filter(isConfirmedConflictEvent); + const foreignConfirmed = confirmed.some((e) => e.kind === "third-party-plugin"); + const nativePresent = confirmed.some((e) => e.kind === "native-compaction"); + const signals = meaningful.filter((e) => e.kind === "unannounced-rewrite" || e.kind === "orphan-reap"); + const activeConfirmed = confirmed.some((e) => now - e.at <= CONFLICT_ACTIVE_WINDOW_MS); + lines.push(`COMPRESSION CONFLICTS — ${events.length} event(s) in this session (${active.length} active · ${historical.length} historical; active = within ${CONFLICT_ACTIVE_WINDOW_MS / 86_400_000} days). ${foreignConfirmed || nativePresent + ? "Two compressors on one conversation (bili + another compression plugin — third-party or bili's own sibling — or client native compaction) double-compress and corrupt message refs:" + : "Diagnostic evidence that something outside bili touched this conversation — how strong that evidence is is tiered below:"}`); for (const e of events.slice(-10)) { lines.push(` [${fmtTime(e.at)}] ${e.kind} — ${e.detail}`); } @@ -124,34 +154,42 @@ export function formatConflictSection(events: ConflictEvent[], now: number = Dat if (suspectedCount > 0) { lines.push(" [suspected] = name-only keyword match — verify the plugin actually compresses before acting; a context dashboard/viewer/tool is NOT a compressor."); } - const allSuspected = suspectedCount > 0 && suspectedCount === events.length; - // #2432: a ledger pointing at the client's OWN native compaction landing is - // not "a second compressor fighting you" — commanding the model to hunt for - // and disable another plugin sends it on a useless errand (the incident - // model did exactly that). Only foreign CONFIRMED third-party events keep - // the one-compressor command; suspected names never do (#1736 tiering). - const foreignConfirmed = events.some((e) => e.kind === "third-party-plugin" && !isSuspectedEvent(e)); - const nativePresent = events.some((e) => e.kind === "native-compaction"); - // #2261: a ledger naming ONLY bili's own siblings (billion-context-pi / - // opencode-acp) is not a foreign-compressor alarm — they stand down while - // bili drives the session (#820/#920), so never command removal for them. - const siblingEvents = events.filter((e) => e.kind === "third-party-plugin" && isSiblingConflictDetail(e.detail)); - const siblingsOnly = siblingEvents.length > 0 && siblingEvents.length === events.length; - lines.push(siblingsOnly - ? "Every event above names bili's OWN sibling extension (billion-context-pi / opencode-acp), not a third-party compressor: while bili drives the session it stands down automatically (BILLION_CONTEXT_NATIVE marker in native mode, /bili/ baseUrl self-check otherwise), so no second compressor is active. Verify your bili/sibling versions are recent, then clear this ledger — Web UI conflict banner / session page, or POST /__bili/conflicts/clear." - : active.length === 0 - ? "All events above are older than 7 days (historical stock): the double-compression risk may no longer be live. Verify the other compression plugin is removed or blocked by bili, then clear this ledger — Web UI conflict banner / session page, or POST /__bili/conflicts/clear?session=." - : allSuspected - ? "Every event above is [suspected]: confirm each named plugin really compresses before removing anything — do not drop a read-only tool on the strength of its name." - : nativePresent && !foreignConfirmed - ? "The events above point at the client's OWN native compaction landing (host-side), not a third-party plugin — do not go hunting for a second plugin to disable. bili detects such landings and rebuilds the fold state onto them where possible (#2373/#2432); if compress still fails afterwards, this session's fold base is gone — start a fresh conversation." - : "Keep exactly ONE compressor per conversation: remove/disable the other plugin (or its native auto-compaction), then start a fresh session."); + // #2545 branch ladder, first match wins: + // neutral-only -> stand-down: siblings + verified read-only viewers + // foreign confirmed -> strong one-compressor command (live) or verify-then-clear (stock) + // native landing (no foreign)-> host-side explanation, no plugin hunt (#2432) + // pure [suspected] -> #1736 soft wording + // unconfirmed signals -> "cause not identified" framing, never imperative + let advice: string; + if (meaningful.length === 0) { + advice = "Every event above names bili's OWN sibling extension (billion-context-pi / opencode-acp) or a verified read-only plugin (display-only by design): while bili drives the session the sibling stands down automatically (BILLION_CONTEXT_NATIVE marker in native mode, /bili/ baseUrl self-check otherwise) and the read-only plugin does not compress anything, so no second compressor is active. Verify your bili/sibling versions are recent, then clear this ledger — Web UI conflict banner / session page, or POST /__bili/conflicts/clear."; + } else if (foreignConfirmed) { + advice = activeConfirmed + ? "Keep exactly ONE compressor per conversation: remove/disable the other plugin (or its native auto-compaction), then start a fresh session." + : "The confirmed event(s) above are older than 7 days (historical stock): the double-compression risk may no longer be live. Verify the other compression plugin is removed or blocked by bili, then clear this ledger — Web UI conflict banner / session page, or POST /__bili/conflicts/clear?session=."; + } else if (nativePresent) { + // #2432: a ledger pointing at the client's OWN native compaction landing is + // not "a second compressor fighting you" — commanding the model to hunt for + // and disable another plugin sends it on a useless errand (the incident + // model did exactly that). Only foreign CONFIRMED third-party events keep + // the one-compressor command; suspected names never do (#1736 tiering). + advice = "The events above point at the client's OWN native compaction landing (host-side), not a third-party plugin — do not go hunting for a second plugin to disable. bili detects such landings and rebuilds the fold state onto them where possible (#2373/#2432); if compress still fails afterwards, this session's fold base is gone — start a fresh conversation."; + } else if (signals.length === 0) { + advice = active.length > 0 + ? "Every event above is [suspected]: confirm each named plugin really compresses before removing anything — do not drop a read-only tool on the strength of its name." + : "Every event above is [suspected] AND older than 7 days (historical stock): confirm each named plugin really compresses before removing anything — do not drop a read-only tool on the strength of its name. If none of them turns out to compress, clear this ledger — Web UI conflict banner / session page, or POST /__bili/conflicts/clear?session=."; + } else { + advice = active.length > 0 + ? "Every event above is an UNCONFIRMED signal: history changes were observed (rewrites without a recognized compaction marker, summarized blocks leaving the client history) and/or name-only [suspected] plugin matches, but nothing here identifies WHO rewrote the conversation — the cause is not confirmed. Do not drop a read-only tool or viewer on the strength of these records; verify the named plugins and the client's auto-compaction settings before acting." + : "All events above are UNCONFIRMED signals older than 7 days (historical stock): history changes were observed but their cause was never identified, and no second compressor is confirmed. If the affected sessions are gone, clear this ledger — Web UI conflict banner / session page, or POST /__bili/conflicts/clear?session=."; + } + lines.push(advice); // #2219: actionable per-client remediation — the surfaces used to stop at // WHAT happened; answering HOW required digging out four separate doc // locations, none linked from any conflict surface. Skipped for the #2261 - // siblings-only ledger: its footer already says no second compressor is + // neutral-only ledger: its footer already says no second compressor is // active, so a per-client fix command would contradict it. - if (!siblingsOnly) { + if (meaningful.length > 0) { lines.push("", `Fix${client ? ` (${client})` : ""}: ${conflictRemediation(client)}`); lines.push(CONFLICT_DOCS_POINTER); } @@ -176,6 +214,16 @@ interface ConflictSummary { * additive, so display surfaces can stop treating unverified name matches as * confirmed compressors. Disjoint from `sibling` (siblings are never suspected). */ suspected: number; + /** #2545: plugin-kind events naming VERIFIED read-only (display-only) plugins — + * display-time classification of recorded details (stock ledgers written by pre-#1736 + * keyword rules carry them as [suspected]). Additive within kinds["third-party-plugin"], + * disjoint from `sibling`, and OVERLAPPING `suspected` for those stock records — display + * surfaces subtract it BEFORE suspected so the records count for no severity. */ + displayOnly: number; + /** #2545: CONFIRMED-tier events (isConfirmedConflictEvent) within the active window — + * liveness of the confirmed evidence itself, so a fresh unconfirmed signal cannot + * re-light a stale confirmed ledger as a live alarm. Subset of `active`. */ + activeConfirmed: number; latest: Array<{ sessionId: string; at: number; kind: ConflictKind; detail: string }>; /** #2219: distinct resolved clients of sessions carrying events (first-seen * order) — lets the web banner show per-client remediation hints. */ @@ -183,7 +231,7 @@ interface ConflictSummary { } export function summarizeConflicts(sessions: Session[], now: number = Date.now()): ConflictSummary { - const summary: ConflictSummary = { sessions: 0, events: 0, active: 0, historical: 0, lastAt: null, kinds: {}, latest: [], sibling: 0, suspected: 0, clients: [] }; + const summary: ConflictSummary = { sessions: 0, events: 0, active: 0, historical: 0, lastAt: null, kinds: {}, latest: [], sibling: 0, suspected: 0, displayOnly: 0, activeConfirmed: 0, clients: [] }; for (const s of sessions) { const events = conflictEventsOf(s); if (events.length === 0) continue; @@ -194,8 +242,11 @@ export function summarizeConflicts(sessions: Session[], now: number = Date.now() for (const e of events) { summary.kinds[e.kind] = (summary.kinds[e.kind] ?? 0) + 1; if (e.kind === "third-party-plugin" && isSiblingConflictDetail(e.detail)) summary.sibling += 1; + if (e.kind === "third-party-plugin" && isDisplayOnlyConflictDetail(e.detail)) summary.displayOnly += 1; if (isSuspectedEvent(e)) summary.suspected += 1; - if (now - e.at <= CONFLICT_ACTIVE_WINDOW_MS) summary.active += 1; else summary.historical += 1; + const isActive = now - e.at <= CONFLICT_ACTIVE_WINDOW_MS; + if (isActive) summary.active += 1; else summary.historical += 1; + if (isActive && isConfirmedConflictEvent(e)) summary.activeConfirmed += 1; if (summary.lastAt === null || e.at > summary.lastAt) summary.lastAt = e.at; } const last = events[events.length - 1]!; diff --git a/src/thirdparty-scan.ts b/src/thirdparty-scan.ts index 772419b7b3..a5c110367c 100644 --- a/src/thirdparty-scan.ts +++ b/src/thirdparty-scan.ts @@ -61,19 +61,43 @@ export function isDesignBenign(finding: ThirdPartyFinding, pluginAgent: string | return false; } -/** #2261: reverse-map a recorded conflict detail back to its plugin entry so - * display surfaces can tell bili's OWN siblings apart from true third parties - * — every other surface labels the whole "third-party-plugin" kind as a - * foreign compressor, which mislabels first-party siblings and commands - * removal of extensions that stand down by design (#820/#920). Detail shape - * (single producer, server.ts scan site): ": ()[ [suspected]]". - * Classifying at display time (not record time) also covers stock ledgers - * written by older versions before any sibling tag existed. */ -export function isSiblingConflictDetail(detail: string): boolean { +/** #2261/#2545: parse a recorded third-party-plugin conflict detail back into + * its identity parts so display surfaces can classify what the record actually + * names. Detail shape (single producer, server.ts scan site): + * ": ()[ [suspected]]". Classifying at display time + * (not record time) also covers stock ledgers written by older versions before + * any of these tags existed. Non-plugin detail shapes (unannounced-rewrite / + * orphan-reap / native-compaction) never match. */ +export interface ParsedPluginConflictDetail { + client: string; + entry: string; + source: string; + suspected: boolean; +} + +export function parsePluginConflictDetail(detail: string): ParsedPluginConflictDetail | undefined { const m = /^(\S+): (.+) \((.+)\)( \[suspected\])?$/.exec(detail.trim()); - if (!m) return false; - const entry = m[2]!; - return isLegacyBcpEntry(entry) || isOpencodeAcpEntry(entry); + if (!m) return undefined; + return { client: m[1]!, entry: m[2]!, source: m[3]!, suspected: m[4] !== undefined }; +} + +/** #2261: true when the recorded detail names bili's OWN sibling extension + * (billion-context-pi / opencode-acp) — first-party family that stands down + * while bili drives the session (#820/#920), never a foreign-compressor alarm. */ +export function isSiblingConflictDetail(detail: string): boolean { + const p = parsePluginConflictDetail(detail); + if (!p) return false; + return isLegacyBcpEntry(p.entry) || isOpencodeAcpEntry(p.entry); +} + +/** #2545: true when the recorded detail names a VERIFIED read-only plugin from + * KNOWN_DISPLAY_ONLY. Such records were only ever written as [suspected] by + * pre-#1736 keyword rules (which matched bare "context"), and must count for + * NO conflict severity on any display surface — the plugin does not compress. */ +export function isDisplayOnlyConflictDetail(detail: string): boolean { + const p = parsePluginConflictDetail(detail); + if (!p) return false; + return isKnownDisplayOnlyPlugin(p.entry); } const SCAN_CACHE_TTL_MS = 5 * 60 * 1000; @@ -176,6 +200,12 @@ const KNOWN_DISPLAY_ONLY = new Set([ // registers display toggles; README states "changes display only" — no context // replacement or compression handler (#2324). "pi-compact-transcript", + // pi context viewer: read-only /context overlay showing tokens, system prompt, + // tools and messages; its source registers only /context and reads context/tool + // info — no compression or history-rewrite API (#2545). Pre-#1736 keyword rules + // matched its name (bare "context") and wrote stock [suspected] ledger records; + // isDisplayOnlyConflictDetail neutralizes those at display time. + "pi-context-inspector", ]); export function isKnownDisplayOnlyPlugin(entry: string): boolean { diff --git a/src/web/client.ts b/src/web/client.ts index 310f705281..e01e4b4fbc 100644 --- a/src/web/client.ts +++ b/src/web/client.ts @@ -81,33 +81,51 @@ export const WEB_CLIENT = `(function () { if (hidden > 0) line += " · …+" + hidden + " more (GET /__bili/stats → conflicts)"; return line; } - // #2324: pick the banner title/risk wording from the ledger families present. Name-only - // [suspected] matches are NEVER treated as confirmed compressors — they get a softer - // "verify first" framing, not the imperative double-compression warning. Old payloads - // without c.suspected degrade to the previous all-confirmed view. Pure (reads only c), - // exported for tests the same way bili_conflictLine is. + // #2324/#2545: pick the banner title/risk wording from the ledger EVIDENCE TIERS. + // CONFIRMED = non-suspected third-party plugin findings + detected native-compaction + // landings only. UNCONFIRMED SIGNALS = unannounced rewrites + orphan reaps (observed + // history changes whose cause is NOT identified) — counting them as confirmed turned + // one unexplained rewrite into a "two compressors on one conversation" alarm (#2545); + // they outrank name-only [suspected] matches (an observed change is stronger than a + // name guess), so any signal takes the unconfirmed tier even next to suspected names. + // SUSPECTED-ONLY keeps the #2324 verify-first tier. Siblings and verified read-only + // (display-only) plugins are NEUTRAL. Old payloads without c.suspected / c.displayOnly + // degrade to the previous view; without c.activeConfirmed, liveness falls back to c.active. + // Pure (reads only c), exported for tests the same way bili_conflictLine is. function bili_conflictSeverity(c) { - const pluginN = (c.kinds && c.kinds["third-party-plugin"]) || 0; + const kinds = c.kinds || {}; + const pluginN = kinds["third-party-plugin"] || 0; const siblingN = Math.max(0, Math.min(typeof c.sibling === "number" ? c.sibling : 0, pluginN)); - const suspectedN = Math.max(0, Math.min(typeof c.suspected === "number" ? c.suspected : 0, pluginN - siblingN)); - const confirmedTpN = Math.max(0, pluginN - siblingN - suspectedN); - const nativeN = Math.max(0, c.events - pluginN); + // Stock ledgers written by pre-#1736 keyword rules carry display-only plugins as + // [suspected]; subtract display-only BEFORE suspected so they count for no severity. + const displayOnlyN = Math.max(0, Math.min(typeof c.displayOnly === "number" ? c.displayOnly : 0, pluginN - siblingN)); + const suspectedN = Math.max(0, Math.min(typeof c.suspected === "number" ? c.suspected : 0, pluginN - siblingN - displayOnlyN)); + const confirmedTpN = Math.max(0, pluginN - siblingN - displayOnlyN - suspectedN); + const confirmedNativeN = kinds["native-compaction"] || 0; + const signalN = Math.max(0, c.events - pluginN - confirmedNativeN); const whatParts = []; if (confirmedTpN > 0) whatParts.push(t("conflict.what_plugin")); if (suspectedN > 0) whatParts.push(t("conflict.what_suspected")); // #2430: siblings are family, never a warning — they no longer appear in the // "what" enumeration even in mixed ledgers (pure-sibling banners are hidden outright). - if (nativeN > 0) whatParts.push(t("conflict.what_native")); + if (confirmedNativeN > 0) whatParts.push(t("conflict.what_native")); + if (signalN > 0) whatParts.push(t("conflict.what_signal")); const active = typeof c.active === "number" ? c.active : c.events; - const hasConfirmed = confirmedTpN > 0 || nativeN > 0; + // Liveness of the CONFIRMED evidence itself — a fresh unconfirmed signal must not + // re-light a stale confirmed ledger as a live alarm. + const activeConfirmed = typeof c.activeConfirmed === "number" ? Math.min(c.activeConfirmed, active) : active; + const hasConfirmed = confirmedTpN > 0 || confirmedNativeN > 0; // Resolve each branch through a direct translate call (not a key-to-text lookup table) // so the #1024 static ref-scanner still counts every conflict.* key used here; surface // both the key (locale-independent, asserted by tests) and the rendered text. let onKey, riskKey, onText, riskText; if (hasConfirmed) { onKey = "conflict.on"; onText = t("conflict.on"); - if (active > 0) { riskKey = "conflict.risk_active"; riskText = t("conflict.risk_active"); } + if (activeConfirmed > 0) { riskKey = "conflict.risk_active"; riskText = t("conflict.risk_active"); } else { riskKey = "conflict.risk_historical"; riskText = t("conflict.risk_historical"); } + } else if (signalN > 0) { + onKey = "conflict.on_unconfirmed"; onText = t("conflict.on_unconfirmed"); + riskKey = "conflict.risk_unconfirmed"; riskText = t("conflict.risk_unconfirmed"); } else if (suspectedN > 0) { onKey = "conflict.on_suspected"; onText = t("conflict.on_suspected"); riskKey = "conflict.risk_suspected"; riskText = t("conflict.risk_suspected"); @@ -115,10 +133,11 @@ export const WEB_CLIENT = `(function () { onKey = "conflict.on"; onText = t("conflict.on"); riskKey = "conflict.risk_sibling"; riskText = t("conflict.risk_sibling"); } - // #2430: a ledger that is ONLY bili's own siblings stands down completely — they are - // compatible family, not conflicts; the web banner must stay hidden for them. - const siblingOnly = !hasConfirmed && suspectedN === 0 && siblingN > 0; - return { onKey: onKey, riskKey: riskKey, onText: onText, riskText: riskText, hasConfirmed: hasConfirmed, siblingOnly: siblingOnly, what: whatParts.join(t("conflict.what_join")), active: active }; + // #2430/#2545: a ledger naming ONLY bili's own siblings or verified read-only viewers + // stands down completely — compatible family / non-compressors, not conflicts. + const siblingOnly = !hasConfirmed && suspectedN === 0 && signalN === 0 && siblingN > 0; + const neutralOnly = !hasConfirmed && suspectedN === 0 && signalN === 0 && (siblingN + displayOnlyN) > 0; + return { onKey: onKey, riskKey: riskKey, onText: onText, riskText: riskText, hasConfirmed: hasConfirmed, siblingOnly: siblingOnly, neutralOnly: neutralOnly, what: whatParts.join(t("conflict.what_join")), active: active, activeConfirmed: activeConfirmed }; } window.bili_conflictLine = bili_conflictLine; window.bili_conflictSeverity = bili_conflictSeverity; @@ -488,11 +507,12 @@ export const WEB_CLIENT = `(function () { const cb = $("conflicts-banner"); if (cb) { const c = d.conflicts; - // #2430: siblings-only ledgers stand down — bili's own family (billion-context-pi / - // opencode-acp) is compatible, so a pure-sibling ledger is not a warning. The events - // stay recorded (acp_status keeps the calm #2261 footer); only the banner goes quiet. + // #2430/#2545: neutral-only ledgers stand down — bili's own family (billion- + // context-pi / opencode-acp) is compatible and verified read-only viewers are not + // compressors, so such ledgers are not warnings. The events stay recorded + // (acp_status keeps the calm #2261 footer); only the banner goes quiet. const sev0 = c && c.events > 0 ? bili_conflictSeverity(c) : null; - if (c && c.events > 0 && !(sev0 && sev0.siblingOnly)) { + if (c && c.events > 0 && !(sev0 && sev0.neutralOnly)) { cb.hidden = false; cb.classList.add("show"); // #2102: attribute per kind family present; split active from historical @@ -506,8 +526,10 @@ export const WEB_CLIENT = `(function () { // details pointer — clients[] comes from summarizeConflicts (server-side // resolution); payloads without it degrade to the generic hint only. cb.innerHTML = '' + sev.onText + "" + t("conflict.found") + escapeHtml(sev.what) + sev.riskText + '(' + bili_conflictLine(c) + ")" + conflictHintBlock(c.clients) + t("conflict.where") + '"; - cb.classList.toggle("info", !(sev.hasConfirmed && sev.active > 0)); - cb.classList.toggle("warn", sev.hasConfirmed && sev.active > 0); + // #2545: red styling follows CONFIRMED liveness — a fresh unconfirmed + // signal beside a stale confirmed ledger renders as info, not warn. + cb.classList.toggle("info", !(sev.hasConfirmed && sev.activeConfirmed > 0)); + cb.classList.toggle("warn", sev.hasConfirmed && sev.activeConfirmed > 0); const btn = $("conflicts-clear-btn"); if (btn) { btn.addEventListener("click", async () => { diff --git a/src/web/i18n.ts b/src/web/i18n.ts index e982c615dc..a4f545b5a3 100644 --- a/src/web/i18n.ts +++ b/src/web/i18n.ts @@ -119,6 +119,12 @@ export const MESSAGES: Record> = { "conflict.on_suspected": "检测到疑似压缩插件", "conflict.what_suspected": "名称含压缩关键词的插件(尚未确认其是否真的压缩上下文)", "conflict.risk_suspected": "——这仅是按名称关键词匹配的【疑似】信号,不是已观察到的双压缩证据。请确认其是否真的改写发给模型的上下文;只改终端显示 / 折叠工具输出的插件(如 pi-compact-transcript)不会双压缩、无需移除。", + // #2545: unconfirmed-signal tier — observed history changes whose cause is NOT + // identified (unannounced rewrites, orphan reaps) must never be presented as a + // confirmed second compressor or attributed to native auto-compaction. + "conflict.on_unconfirmed": "检测到未确认的压缩相关信号", + "conflict.what_signal": "会话历史被改写的痕迹(观察到变化,原因未确认)", + "conflict.risk_unconfirmed": "。这些只是【未确认】信号,不能证明存在第二个压缩器——原因可能是客户端自身改动、未被识别的压缩形态或其他插件。请核实后再行动;只读上下文查看器、仅改终端显示/折叠工具输出的插件不是压缩器,无需移除。", // #2324: the age split describes record recency, not whether a plugin is running now. "conflict.age_active": "近 7 天 {n} 条", "conflict.age_historical": "更早 {n} 条", @@ -536,6 +542,10 @@ export const MESSAGES: Record> = { "conflict.on_suspected": "Possible compression plugin detected", "conflict.what_suspected": "a plugin whose name matches compression keywords (not yet verified to actually compress context)", "conflict.risk_suspected": " — a name-only [suspected] signal, not observed evidence of double-compression. Confirm it actually rewrites the model context before acting; a display / tool-output-folding plugin (e.g. pi-compact-transcript) does not double-compress and needs no removal.", + // #2545: see the zh entries above — unconfirmed signals never presented as a confirmed compressor. + "conflict.on_unconfirmed": "Unconfirmed compression-related signals detected", + "conflict.what_signal": "conversation history being rewritten (a change was observed, cause not yet identified)", + "conflict.risk_unconfirmed": " — all of the above are UNCONFIRMED signals: they do not prove a second compressor exists (possible causes: client-side edits, an unrecognized compaction shape, or another plugin). Verify before acting; a read-only context viewer or a display / tool-output-folding plugin is not a compressor and needs no removal.", // #2324: age split = record recency, not whether a plugin is running now. "conflict.age_active": "{n} in last 7 days", "conflict.age_historical": "{n} older", diff --git a/src/web/sessions-data.ts b/src/web/sessions-data.ts index 426ea8193b..48e3b2e851 100644 --- a/src/web/sessions-data.ts +++ b/src/web/sessions-data.ts @@ -1,7 +1,7 @@ import { orderedRefPair } from "acp-kernel"; import { listSessions, displayContextBest, type ContextBest, type Session } from "../session.js"; import { conflictClientOf, conflictEventsOf } from "../conflict-watch.js"; -import { isSiblingConflictDetail } from "../thirdparty-scan.js"; +import { isDisplayOnlyConflictDetail, isSiblingConflictDetail } from "../thirdparty-scan.js"; import { SessionStore, fileNameMatchesId, isValidRecord, relPathFor } from "../persist.js"; import { flatFileNameFor } from "acp-kernel/persist"; import { renderHandoff } from "../export.js"; @@ -820,10 +820,11 @@ function renderDetail(session: Session, live: boolean): WebSessionDetail { const pluginAgent = typeof session.metadata["pluginAgent"] === "string" ? session.metadata["pluginAgent"] : undefined; const clientHint = pluginAgent ?? (typeof session.metadata["clientHint"] === "string" ? session.metadata["clientHint"] : undefined); const sysPrompt = typeof session.metadata["systemPromptTokens"] === "number" ? session.metadata["systemPromptTokens"] : 0; - // #2430: bili's own siblings (billion-context-pi / opencode-acp) are compatible family, - // not conflicts — keep them out of the session evidence card so a siblings-only session - // renders no conflict block at all. Recording (acp_status #2261 calm footer) is unchanged. - const conflicts = conflictEventsOf(session).filter((e) => !(e.kind === "third-party-plugin" && isSiblingConflictDetail(e.detail))); + // #2430/#2545: bili's own siblings (billion-context-pi / opencode-acp) are compatible + // family and verified read-only plugins (KNOWN_DISPLAY_ONLY) are not compressors — keep + // both out of the session evidence card so such sessions render no conflict block at all. + // Recording (acp_status #2261 calm footer) is unchanged. + const conflicts = conflictEventsOf(session).filter((e) => !(e.kind === "third-party-plugin" && (isSiblingConflictDetail(e.detail) || isDisplayOnlyConflictDetail(e.detail)))); const conflictClient = conflicts.length > 0 ? conflictClientOf(session) : undefined; return { diff --git a/tests/conflict-lifecycle.test.ts b/tests/conflict-lifecycle.test.ts index e208679610..2952efbfc9 100644 --- a/tests/conflict-lifecycle.test.ts +++ b/tests/conflict-lifecycle.test.ts @@ -94,7 +94,10 @@ test("formatConflictSection: header age split + advice switches with liveness (# ]; const mixedText = formatConflictSection(mixed, now).join("\n"); assert.ok(mixedText.includes("(1 active · 1 historical; active = within 7 days)"), mixedText); - assert.ok(mixedText.includes("Keep exactly ONE compressor"), "recent event keeps the imperative advice"); + // #2545: unannounced rewrites alone are UNCONFIRMED signals — a fresh one no + // longer escalates to the imperative one-compressor command (cause unverified). + assert.ok(mixedText.includes("UNCONFIRMED signal"), "tiered as unconfirmed diagnosis"); + assert.ok(!mixedText.includes("Keep exactly ONE compressor"), "no imperative without confirmed evidence"); const allOld: ConflictEvent[] = [ { at: now - 30 * DAY, kind: "unannounced-rewrite", detail: "stock" }, diff --git a/tests/issue1206-thirdparty-scan.test.ts b/tests/issue1206-thirdparty-scan.test.ts index 17bcd912da..3f03353a93 100644 --- a/tests/issue1206-thirdparty-scan.test.ts +++ b/tests/issue1206-thirdparty-scan.test.ts @@ -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, isKnownDisplayOnlyPlugin, isOpencodeAcpEntry, isSiblingConflictDetail, scanClientPlugins, sniffScanClient, type ThirdPartyFinding } from "../src/thirdparty-scan.js"; +import { clearScanCache, conflictScanEnabled, isDesignBenign, isDisplayOnlyConflictDetail, isKnownDisplayOnlyPlugin, 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"; @@ -375,7 +375,10 @@ test("formatConflictSection lists last 10 events with guidance", () => { assert.ok(lines.some((l) => l.includes("reaped 2"))); assert.ok(!lines.some((l) => l.includes("reaped 0 ")), "only the last 10 events are listed"); assert.ok(lines.some((l) => l.includes("/__bili/stats")), "overflow pointer present"); - assert.ok(lines.some((l) => l.toLowerCase().includes("one compressor")), "guidance footer present"); + // #2545: orphan reaps are UNCONFIRMED signals (observed change, cause not + // identified) — guidance exists but must not read as a confirmed conflict. + assert.ok(lines.some((l) => l.includes("UNCONFIRMED signal")), "soft unconfirmed-signal guidance present"); + assert.ok(!lines.some((l) => l.toLowerCase().includes("keep exactly one compressor")), "no imperative for unconfirmed signals"); }); test("formatConflictSection marks [suspected] as name-only and softens the footer when nothing confirmed (#1736)", () => { @@ -387,11 +390,19 @@ test("formatConflictSection marks [suspected] as name-only and softens the foote assert.ok(!lines.some((l) => l.toLowerCase().includes("one compressor")), "no confirmed events -> no hard remove/disable command"); const s2 = makeSession(); - recordConflict(s2, "third-party-plugin", "opencode: opencode-acp (global config)"); + // #2545: a sibling standing down next to an orphan reap is NOT confirmed foreign + // evidence — the strong footer requires a real non-suspected plugin finding. + recordConflict(s2, "third-party-plugin", "pi: npm:real-compressor-x (/u/.pi/settings.json)"); recordConflict(s2, "orphan-reap", "1 block(s) deactivated: b1"); const lines2 = formatConflictSection(conflictEventsOf(s2)); assert.ok(lines2.some((l) => l.toLowerCase().includes("one compressor")), "confirmed events keep the strong footer"); assert.ok(!lines2.some((l) => l.includes("[suspected] = name-only")), "no note when nothing is suspected"); + + const s3 = makeSession(); + recordConflict(s3, "third-party-plugin", "opencode: opencode-acp (global config)"); + recordConflict(s3, "orphan-reap", "1 block(s) deactivated: b1"); + const lines3 = formatConflictSection(conflictEventsOf(s3)); + assert.ok(!lines3.some((l) => l.toLowerCase().includes("keep exactly one compressor")), "sibling + unconfirmed signal stays in the soft tier (#2261/#2545)"); }); test("summarizeConflicts aggregates across sessions", () => { @@ -432,6 +443,33 @@ test("isKnownDisplayOnlyPlugin resolves bare/npm-versioned/path forms, rejects l assert.ok(!isKnownDisplayOnlyPlugin("pi-context"), "unrelated name not excluded"); }); +test("isKnownDisplayOnlyPlugin exempts verified read-only context viewer in every spec form (#2545)", () => { + assert.ok(isKnownDisplayOnlyPlugin("pi-context-inspector")); + assert.ok(isKnownDisplayOnlyPlugin("npm:pi-context-inspector")); + assert.ok(isKnownDisplayOnlyPlugin("npm:pi-context-inspector@1.3.0")); + assert.ok(isKnownDisplayOnlyPlugin("/u/.pi/agent/npm/node_modules/pi-context-inspector/index.js")); + assert.ok(isKnownDisplayOnlyPlugin("C:\\Users\\Administrator\\.pi\\agent\\npm\\node_modules\\pi-context-inspector\\index.js"), "windows path form"); + assert.ok(!isKnownDisplayOnlyPlugin("my-pi-context-inspector-fork"), "lookalike NOT excluded"); + assert.ok(!isKnownDisplayOnlyPlugin("pi-context-compressor"), "a real compressor sharing the prefix stays flagged"); +}); + +test("pi scan: pi-context-inspector never flagged in any spec form, real compressors still flagged (#2545)", () => { + clearScanCache(); + const root = tmp("bili-2545-pi-"); + const cwd = tmp("bili-2545-pi-cwd-"); + const env: NodeJS.ProcessEnv = { ...hermeticEnv(root), PI_HOME: path.join(root, ".pi", "agent") }; + const home = resolvePiHome(env); + assertTestOwned(path.join(home, "settings.json"), root); + // the issue's exact install shape (npm spec as pi-managed) plus a bare name and a + // REAL compressor that must stay flagged. + writeFile(path.join(home, "settings.json"), JSON.stringify({ + packages: ["npm:billion-context", "npm:pi-context-inspector", "npm:pi-context-inspector@1.3.0", "npm:context-compactor"], + })); + const res = scanClientPlugins("pi", { env, cwd }); + assert.ok(!res.findings.some((f) => f.entry.includes("pi-context-inspector")), "read-only viewer never flagged, any spec form"); + assert.ok(res.findings.some((f) => f.entry === "npm:context-compactor" && f.match === "keyword"), "real compressor still flagged"); +}); + test("isSiblingConflictDetail maps recorded details back to sibling entries (#2261)", () => { assert.ok(isSiblingConflictDetail("pi: npm:billion-context-pi (/home/dog/.pi/agent/settings.json)")); assert.ok(isSiblingConflictDetail("pi: billion-context-pi@0.1.75 (~/.pi/settings.json)")); @@ -494,3 +532,79 @@ test("formatConflictSection: sibling-only ledgers drop the one-compressor comman const mixedText = formatConflictSection(conflictEventsOf(mixed)).join("\n"); assert.ok(mixedText.toLowerCase().includes("keep exactly one compressor"), "any non-sibling event keeps the strong footer"); }); + +// #2545: evidence tiers — verified read-only viewers are neutralized at display +// time (stock ledgers written by pre-#1736 keyword rules carry them as +// [suspected]), and unconfirmed signals never escalate into a confirmed +// double-compression verdict. + +test("parsePluginConflictDetail splits client/entry/source/suspected; non-plugin shapes stay undefined (#2545)", () => { + assert.deepEqual( + parsePluginConflictDetail("pi: npm:context-forge (/home/dog/.pi/agent/settings.json) [suspected]"), + { client: "pi", entry: "npm:context-forge", source: "/home/dog/.pi/agent/settings.json", suspected: true }); + assert.deepEqual( + parsePluginConflictDetail("opencode: opencode-acp (global config)"), + { client: "opencode", entry: "opencode-acp", source: "global config", suspected: false }); + // the issue's own stock record shape — Windows path inside the parens must parse. + const w = parsePluginConflictDetail("pi: npm:pi-context-inspector (C:\\Users\\Administrator\\.pi\\agent\\settings.json) [suspected]"); + assert.equal(w?.entry, "npm:pi-context-inspector"); + assert.equal(w?.suspected, true); + assert.equal(parsePluginConflictDetail("event 5"), undefined); + assert.equal(parsePluginConflictDetail("47/247 incoming message(s) carry pre-turn refs of 290 known"), undefined); +}); + +test("isDisplayOnlyConflictDetail neutralizes stock records of verified read-only viewers (#2545)", () => { + assert.ok(isDisplayOnlyConflictDetail("pi: npm:pi-context-inspector (C:\\Users\\Administrator\\.pi\\agent\\settings.json) [suspected]"), "the issue's exact stock detail"); + assert.ok(isDisplayOnlyConflictDetail("pi: pi-compact-transcript (/u/.pi/settings.json)")); + assert.ok(!isDisplayOnlyConflictDetail("pi: npm:context-forge (/home/dog/.pi/agent/settings.json) [suspected]")); + assert.ok(!isDisplayOnlyConflictDetail("dsh: dsh-context (profile/package.json) [suspected]")); + assert.ok(!isDisplayOnlyConflictDetail("event 5"), "non-plugin shapes never classify"); +}); + +test("summarizeConflicts counts displayOnly and activeConfirmed tiers (#2545)", () => { + const a = makeSession(); + recordConflict(a, "third-party-plugin", "pi: npm:pi-context-inspector (C:\\Users\\Administrator\\.pi\\agent\\settings.json) [suspected]"); + recordConflict(a, "third-party-plugin", "pi: npm:context-forge (/home/dog/.pi/agent/settings.json) [suspected]"); + const b = makeSession(); + recordConflict(b, "native-compaction", "codex: compaction_trigger item"); + const s = summarizeConflicts([a, b]); + assert.equal(s.events, 3); + assert.equal(s.suspected, 2); + assert.equal(s.displayOnly, 1, "the inspector record classifies as display-only (overlaps suspected)"); + assert.equal(s.activeConfirmed, 1, "only the native-compaction landing is confirmed-tier"); + assert.equal(s.active, 3); +}); + +test("formatConflictSection: display-only-only ledger stands down neutrally (#2545)", () => { + const s = makeSession(); + recordConflict(s, "third-party-plugin", "pi: npm:pi-context-inspector (C:\\Users\\Administrator\\.pi\\agent\\settings.json) [suspected]"); + recordConflict(s, "third-party-plugin", "pi: npm:pi-context-inspector@1.3.0 (C:\\Users\\Administrator\\.pi\\agent\\settings.json) [suspected]"); + const text = formatConflictSection(conflictEventsOf(s)).join("\n"); + assert.ok(text.includes("verified read-only plugin"), "names the verified read-only tier"); + assert.ok(!text.includes("Two compressors on one conversation"), "header claim requires confirmed/native evidence"); + assert.ok(!text.toLowerCase().includes("keep exactly one compressor"), "no removal command for non-compressors"); + assert.ok(text.includes("/__bili/conflicts/clear"), "points at the clear path"); +}); + +test("formatConflictSection: rewrite signal + display-only stock stays an UNCONFIRMED diagnosis (#2545)", () => { + const s = makeSession(); + recordConflict(s, "unannounced-rewrite", "47/247 incoming message(s) carry pre-turn refs of 290 known"); + recordConflict(s, "third-party-plugin", "pi: npm:pi-context-inspector (C:\\Users\\Administrator\\.pi\\agent\\settings.json) [suspected]"); + const text = formatConflictSection(conflictEventsOf(s)).join("\n"); + assert.ok(text.includes("UNCONFIRMED signal"), "tiered as unconfirmed"); + assert.ok(text.includes("cause is not confirmed"), "cause explicitly unidentified"); + assert.ok(!text.includes("Two compressors on one conversation"), "header claim requires confirmed/native evidence"); + assert.ok(!text.toLowerCase().includes("keep exactly one compressor"), "no imperative without confirmed evidence"); +}); + +test("formatConflictSection: stale confirmed stock next to a fresh signal -> verify-then-clear, not live alarm (#2545)", () => { + const s = makeSession(); + s.metadata.conflictEvents = [ + { at: Date.now() - 30 * 86_400_000, kind: "third-party-plugin", detail: "pi: npm:real-compressor-x (/home/dog/.pi/agent/settings.json)" }, + { at: Date.now(), kind: "unannounced-rewrite", detail: "47/247 incoming message(s) carry pre-turn refs of 290 known" }, + ]; + const text = formatConflictSection(conflictEventsOf(s)).join("\n"); + assert.ok(text.includes("older than 7 days (historical stock)"), "confirmed ledger graded by its own age"); + assert.ok(text.includes("Two compressors on one conversation"), "header claim holds while confirmed evidence exists"); + assert.ok(!text.toLowerCase().includes("keep exactly one compressor"), "stock confirmed events get verify-then-clear, not the live command"); +}); diff --git a/tests/web-conflict-banner.test.ts b/tests/web-conflict-banner.test.ts index 8216953d18..406a906def 100644 --- a/tests/web-conflict-banner.test.ts +++ b/tests/web-conflict-banner.test.ts @@ -17,8 +17,9 @@ const END_MARK = "window.bili_conflictLine = bili_conflictLine;"; type LatestEntry = { kind: string; detail?: string; at?: number; sessionId?: string }; type BannerInput = { events?: number; sessions?: number; active?: number; historical?: number; kinds?: Record; latest?: LatestEntry[] }; -type SeverityInput = BannerInput & { sibling?: number; suspected?: number }; -interface Severity { onKey: string; riskKey: string; hasConfirmed: boolean; siblingOnly?: boolean; what: string; active: number } +// #2545: displayOnly/activeConfirmed are additive payload fields from summarizeConflicts. +type SeverityInput = BannerInput & { sibling?: number; suspected?: number; displayOnly?: number; activeConfirmed?: number }; +interface Severity { onKey: string; riskKey: string; hasConfirmed: boolean; siblingOnly?: boolean; neutralOnly?: boolean; what: string; active: number; activeConfirmed: number } // Both helpers share the same extracted slice (they sit together in WEB_CLIENT); // the slice ends at the first window.* export so no `window` reference runs under Node. @@ -201,6 +202,68 @@ test("#2324 old payload without c.suspected degrades to the previous all-confirm assert.strictEqual(r.riskKey, "conflict.risk_active"); }); +// #2545: unannounced rewrites / orphan reaps are UNCONFIRMED signals — they must +// never count as confirmed native evidence, verified read-only viewers are neutral, +// and liveness follows the confirmed tier, not any fresh event. + +test("#2545 the issue's exact aggregate: rewrite ×1 + suspected inspector ×2 across 3 sessions -> unconfirmed diagnosis", () => { + const sev = bannerSeverity(); + const r = sev({ + events: 3, sessions: 3, + kinds: { "unannounced-rewrite": 1, "third-party-plugin": 2 }, + sibling: 0, suspected: 2, displayOnly: 2, + active: 1, historical: 2, activeConfirmed: 0, + }); + assert.strictEqual(r.hasConfirmed, false, "no confirmed compressor evidence in this mix"); + assert.strictEqual(r.onKey, "conflict.on_unconfirmed"); + assert.strictEqual(r.riskKey, "conflict.risk_unconfirmed"); + assert.ok(r.what.length > 0, "names the observed-rewrite family"); + assert.ok(!r.neutralOnly, "a genuine rewrite signal keeps the banner visible"); +}); + +test("#2545 display-only-only ledger stands down completely (banner hidden via neutralOnly)", () => { + const sev = bannerSeverity(); + const r = sev({ events: 2, kinds: { "third-party-plugin": 2 }, sibling: 0, suspected: 2, displayOnly: 2, active: 2 }); + assert.strictEqual(r.hasConfirmed, false); + assert.strictEqual(r.siblingOnly, false, "display-only records are not siblings"); + assert.strictEqual(r.neutralOnly, true, "verified read-only viewers are not conflicts"); +}); + +test("#2545 a lone unannounced-rewrite was escalated to a confirmed warning before — now unconfirmed", () => { + const sev = bannerSeverity(); + const r = sev({ events: 1, sessions: 1, kinds: { "unannounced-rewrite": 1 }, active: 1 }); + assert.strictEqual(r.hasConfirmed, false); + assert.strictEqual(r.onKey, "conflict.on_unconfirmed"); + assert.strictEqual(r.riskKey, "conflict.risk_unconfirmed"); +}); + +test("#2545 stale confirmed stock + fresh unconfirmed signal -> confirmed framing graded by its own age", () => { + const sev = bannerSeverity(); + const stale = sev({ + events: 2, sessions: 2, + kinds: { "native-compaction": 1, "unannounced-rewrite": 1 }, + active: 2, historical: 0, activeConfirmed: 0, + }); + assert.strictEqual(stale.hasConfirmed, true, "native-compaction IS confirmed evidence"); + assert.strictEqual(stale.riskKey, "conflict.risk_historical", "liveness follows the confirmed evidence, not the fresh signal"); + + const fresh = sev({ + events: 2, sessions: 2, + kinds: { "native-compaction": 1, "unannounced-rewrite": 1 }, + active: 2, historical: 0, activeConfirmed: 1, + }); + assert.strictEqual(fresh.riskKey, "conflict.risk_active"); +}); + +test("#2545 old payload without displayOnly degrades: stock suspected records keep the soft tier", () => { + const sev = bannerSeverity(); + const r = sev({ events: 2, kinds: { "third-party-plugin": 2 }, suspected: 2, active: 2 }); + assert.strictEqual(r.hasConfirmed, false); + assert.strictEqual(r.onKey, "conflict.on_suspected"); + assert.strictEqual(r.riskKey, "conflict.risk_suspected"); + assert.ok(!r.neutralOnly, "without displayOnly data the pre-#2545 soft behavior holds"); +}); + test("banner wiring: conflicts-banner branch renders bili_conflictLine (drift guard)", () => { assert.ok(WEB_CLIENT.includes("window.bili_conflictLine = bili_conflictLine;"), "test seam export present"); assert.ok(WEB_CLIENT.includes("bili_conflictLine(c)"), "banner branch calls the helper"); From a9eb0b050f8d20d6da4f2985ddc0e46b523ac8e3 Mon Sep 17 00:00:00 2001 From: ework-daemon Date: Fri, 9 Oct 2026 23:24:45 +0800 Subject: [PATCH 2/2] fix: drop leading export on two INTERNAL_ONLY symbols flagged by check-unused-exports (#2545) Review of #2549: isConfirmedConflictEvent (conflict-watch.ts) and ParsedPluginConflictDetail (thirdparty-scan.ts) have no cross-module consumers (tests exercise them through public behavior); the unused-exports CI gate fails on them. Make them module-private per the gate's own fix. --- src/conflict-watch.ts | 2 +- src/thirdparty-scan.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/conflict-watch.ts b/src/conflict-watch.ts index 73a1464158..f8351ca7b4 100644 --- a/src/conflict-watch.ts +++ b/src/conflict-watch.ts @@ -121,7 +121,7 @@ function isNeutralEvent(e: ConflictEvent): boolean { return e.kind === "third-party-plugin" && (isSiblingConflictDetail(e.detail) || isDisplayOnlyConflictDetail(e.detail)); } -export function isConfirmedConflictEvent(e: ConflictEvent): boolean { +function isConfirmedConflictEvent(e: ConflictEvent): boolean { if (e.kind === "native-compaction") return true; if (e.kind !== "third-party-plugin") return false; return !isNeutralEvent(e) && !isSuspectedEvent(e); diff --git a/src/thirdparty-scan.ts b/src/thirdparty-scan.ts index a5c110367c..b36826f50d 100644 --- a/src/thirdparty-scan.ts +++ b/src/thirdparty-scan.ts @@ -68,7 +68,7 @@ export function isDesignBenign(finding: ThirdPartyFinding, pluginAgent: string | * (not record time) also covers stock ledgers written by older versions before * any of these tags existed. Non-plugin detail shapes (unannounced-rewrite / * orphan-reap / native-compaction) never match. */ -export interface ParsedPluginConflictDetail { +interface ParsedPluginConflictDetail { client: string; entry: string; source: string;