feat: cooperative proxy mode — forward native tools to billion-context proxy (内外呼应) - #154
Open
ranxianglei wants to merge 4 commits into
Open
feat: cooperative proxy mode — forward native tools to billion-context proxy (内外呼应)#154ranxianglei wants to merge 4 commits into
ranxianglei wants to merge 4 commits into
Conversation
added 4 commits
August 16, 2026 02:21
…t proxy (内外呼应) When the model baseUrl routes through a billion-context proxy (/bili/ zero-config prefix), the extension switches to cooperative mode per the protocol shipped in ranxianglei/billion-context#161: the 4 native tools forward to POST /__bili/plugin/tool under the proxy's session lock, every request announces x-bili-plugin: pi + x-bili-plugin-conversation (pi's real session id), and the in-process pipeline (processTurn, nudges, philosophy prompt) is skipped - the proxy owns compression end-to-end. Detection is a stateless per-call URL check; without a proxy (or with ACP_COOPERATIVE_PROXY=0) behavior is byte-identical. Tests 7/7 new.
…w reporting proxyBaseForContext falls back to BILLION_CONTEXT_PROXY (exported by the billion-context launcher next to HTTPS_PROXY), so bili pi in MITM transparent mode gets the same native-tool cooperative experience as the /bili/ prefix. before_provider_headers now also reports the model's contextWindow (x-bili-plugin-context-window) - the agent-side value becomes the authoritative nudge denominator on the proxy. Tests 8/8 new (300 pass total; 1 pre-existing master failure unchanged).
…ressRange since #148 viable-ranges The '2w limit fires the nudge' assertion (from #145) broke when #148 landed viable-ranges: the kernel now only counts merged ranges with tokens*4 >= minCompressRange (5000 chars) as effective T1 content. The 12x2000-char fixture's ranges all stayed under the gate, so the EMERGENCY nudge was correctly suppressed. Enlarge bulk text to 3000 chars/msg so the merged range clears the gate; the 100w-limit idle assertion is unaffected (2% usage, no pressure). Kernel behavior is intentional — fixture was stale.
Owner
Author
|
已更新:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The "inside" half of the cooperative plugin protocol (billion-context issue dog/billion-context#1, gitea; protocol half = ranxianglei/billion-context#161). When pi's model
baseUrlroutes through a billion-context proxy (the/bili/zero-config prefix), the extension automatically switches to cooperative mode — 有外用外:compress/decompress/search_context/acp_statuskeep their native pi registration (native UX, permissions, audit), butexecutePOSTs to the proxy's/__bili/plugin/tool, which runs them under its session lock against the same view the model saw. Result text returns as the native tool result.x-bili-plugin: pi+x-bili-plugin-conversation: <pi session id>(via the SDK'sbefore_provider_headershook). The proxy keys state by pi's real session id — no more content-fingerprint collisions — and suppresses its own wire tool injection (no double compression).contextreturns pi's messages untouched (the proxy runs processTurn — tags, folding, nudges — at the wire level);before_agent_startdrops the local philosophy prompt (proxy injects it) while keeping the delegate prompt (pi-side feature).Detection
Stateless per-call check:
bilipath segment inctx.model.baseUrl→ proxy origin. Model switches mid-session are picked up on the next call; nothing is cached.ACP_COOPERATIVE_PROXY=0disables entirely.Compatibility
Without a
/bili/baseUrl every path is byte-identical to before (early-return branches only). MITM-mode (transparent proxy, no prefix) is NOT detected — documented; use the/bili/prefix baseURL for cooperative mode.Verification
npm run typecheck✅tests/cooperative.test.ts7/7 (URL matrix, header injection + absence, context identity passthrough, prompt ownership, live HTTP forward with conversation-id/args/result assertions, error propagation, kill switch)npm test: 300 tests — 299 pass + 1 pre-existing failure on pristine master (e2e-compress-config.test.ts"2w limit fires nudge" — verified failing on a clean master checkout before these changes; unrelated)npm run build✅Files
src/cooperative.ts(new) — detection +forwardToolToProxy/tryForwardToolsrc/index.ts—wireProviderHeaders+ cooperative early-returns in context/system-prompt wiringtryForwardToolbranch at top ofexecutetests/cooperative.test.ts, README.md section, CONFIGURATION.mdACP_COOPERATIVE_PROXYdevlog/2026-08-16_cooperative-proxy-mode/— REQ + DESIGN + WORKLOGOrdering note
No code-level coupling, but the endpoints this forwards to land with ranxianglei/billion-context#161 — merge that first for the combination to work end-to-end.
Refs: dog/billion-context#1 (gitea)