Skip to content

feat: opencode v2 local compression kernel — mode parity with bili pi (compress executes inside opencode, no proxy) #908

Description

@ranxianglei

Background

PR #824 delivered opencode v2 support; #850/#885 added the proxy / launcher / native-spawn modes plus the /acp command. But bili pi users get a fundamentally better shape: the agent-side plugin owns compression locally — no proxy hop, no BILLION_CONTEXT_PROXY, wire traffic goes straight to the real upstream. opencode v2 had no equivalent (its "native" mode still self-spawns a proxy).

User request (paraphrased from session): "bili pi is what we want — bili opencode is the remote mode. pi implements modes 1 (proxy) + 2 (launcher); make opencode match, with pure-local mode 3." Reference for the pure-local shape: https://github.com/ranxianglei/opencode-acp

What this adds

src/agent/opencode-local.ts — an opencode v2 plugin that runs the acp-kernel compression pipeline IN-PROCESS:

  • session registry keyed by conversation id, session.hook rebuilds the wire view through the kernel (folded messages, acp tags on text parts)
  • chat.params.tools injects the kernel's compress/decompress/acp_status tool set; chat.parameters enforces the compress system prompt
  • tool execution goes through the kernel (executeTool), so acp_status renders the same panel as /acp
  • No proxy, no MITM, no env vars: the user's model config is untouched; context compression happens between opencode and the model, invisible on the wire except tags

Verification done

  • unit tests (tests/opencode-local.test.ts, 11 tests) + full suite 1673 pass
  • Docker-isolated E2E with real opencode v2 + local sglang upstream: 4 postures (proxy / launcher / native-spawn / pure local) all green
  • compression stress test in-container: model read ~200K tokens of real source, self-triggered compress 7 times (105K folded), refs strictly monotonic, no id reuse, two successful recall-from-summary answers, no tag leakage

Fixes ride on the same branch and are recorded in #906 (abort-guard, system-array push).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions