Repository navigation
feat: v1 legacy-lane routing — opencode-acp old sessions keep working, new sessions go to bili (#920) - #921
Conversation
…l opencode (#918) Two compression owners in one host = double compression / ref-space fights. The installer now removes opencode-acp entries from the global opencode.json (bare / npm: / versioned / path specs, array or object shape; original snapshotted to .bili-bak) and warns about project-local installs it cannot touch. Object-shaped plugin maps are normalized to their keys so sibling entries survive. Docs (EN+zh) document the strip and the old-session migration semantics: old <acp> refs live in opencode-acp's own store, decompress returns not-found, numbering restarts — treat pre-migration sessions as read-only archives.
…ons, bili owns new ones (#920) OpenCode 1.x hosts migrating from opencode-acp keep their pre-migration sessions WORKING. The V1 native entry absorbs the installed opencode-acp package (loadLegacyAcp: .opencode/node_modules > project node_modules > global npm root > config-scope modules) by importing its server() with BILLION_CONTEXT_PROXY unset strictly around the call (its only env check is at entry), then routes per session: - legacy session (acp state file exists in <XDG_DATA_HOME>/opencode/storage/plugin/acp/<sid>.json) — compression runs INSIDE the absorbed acp (its dcp refs, block store, all five tools). Model requests carry x-bili-plugin-bypass: 1; the proxy forwards them verbatim (no injection/nudge/binding). - new session — tool executors forward to the proxy plugin endpoints (plugin mode). Tool slots carry the DCP schemas for both lanes (v1 registers one def per name process-wide); the executor picks the lane. acp's transforms (system/messages/text.complete) are gated on the legacy predicate so new sessions never enter its registry; its config hook runs on a provider-hidden shadow (its /bili/ self-disable is neutered) and owned keys are merged back. /acp and /dcp route per lane. Degradation: package absent/import-failed -> bili alone, legacy sessions read-only (documented). Also: cherry-picked 74701fb (installer strips legacy opencode-acp entries, #918) — it was pushed to the already-merged #919 branch and orphaned.
[bot] 🏷 收到,开始 review 本 PR。步骤:① 拉取分支核对代码;② 在 PR head 上跑 typecheck / 全量测试 / build;③ 检查 CI 状态。稍后给出结论。 |
… any segment (#920 review) Two review hardening fixes: - loadLegacyAcp now receives the host's full ctx object instead of a {directory, client} projection. V1PluginContext types only the fields bili uses, but the runtime object may carry extra host fields that acp's hooks need at action time (the projection would drop them). - isLegacyOpencodeAcpEntry matches path entries by ANY segment naming opencode-acp instead of only last/parent — deep entry paths like <dir>/opencode-acp/dist/index.js were missed, leaving both compression owners armed (the double-compression case #918 exists to prevent). Test fixture extended with the dist/index.js form.
[bot] 🏷 Review 完成。结论:核对无误、本地全绿,可以合并(合并操作按规则由人来)。详情如下。 代码核对(拉分支逐文件过)
验证结果(PR head 上实际执行)
Review 中发现的两个小问题(已直接修掉,commit
|
- pass output param through all absorbed-acp wrappers (system.transform / text.complete / command.execute.before crashed with 'output is undefined' — acp hooks are (input, output) two-arg) - legacyAcpCandidates: include v1 package cache ~/.cache/opencode/packages/opencode-acp@<ver>/node_modules (every version, newest first) — that is where 'opencode plugin opencode-acp' actually installs; project/global node_modules rarely see it - wire loadLegacyAcp log through from .server() (absorption was silent) Verified in container: legacy session ses_f4d9 — b1 decompress restores phase-1 facts, model-created b2 block via absorbed acp, model requests bypass-forwarded verbatim ([plugin-bypass] in proxy log); new session ses_f4d821 — tools forward to proxy, session bound (plugin mode).
|
再review下 有新代码 |
…920 review) 7223468 fixed real 'output is undefined' crashes in acp's system.transform / text.complete / command.execute.before handlers, but the lane-routing test still called those hooks one-arg with fakes that ignore the second parameter — so a regression of exactly this class would not have been caught (tests are outside tsconfig.build.json, so typecheck does not cover them either). Fakes now record whether output reached them (:output/:no-output marker) and the assertions require it on the legacy lane. Mutation-verified: reverting the wrapper to a one-arg call fails the suite.
[bot] 🏷 第二轮 review 完成(新 commit 对新 commit 的逐项核对1. output 参数透传(核心修复)—— 正确 2. 候选路径加入 v1 package cache —— 正确 3. log 接线 —— 符合惯例 验证结果(在
|
| 检查 | 结果 |
|---|---|
npm run typecheck |
clean |
npm test |
1705 / 1703 pass / 2 skipped(E2E gates)/ 0 fail |
npm run build |
success |
| GitHub CI(e2e-fake) | success |
另确认:无测试对 legacyAcpCandidates 做全等断言,新增 cache 目录不会引入环境相关的 flaky。
Review 中发现并已修的缺口(commit a63fa66,已推 PR 分支)
测试没有钉住这次修的双参契约。 tests/opencode-native-v1.test.ts 里 fake acp hooks 仍只收一个参数且忽略 output,调用处也只传 input —— 也就是说,如果 output 透传再回归(正是 'output is undefined' 这一类),单测不会失败;而且 tests/ 不在 tsconfig.build.json 的 include 里(typecheck 只覆盖 src/**),所以把 V1Hooks 的 output 改成必选后,旧的单参调用也过不了任何自动检查。这次只有你们的 docker E2E 能抓到它。
修法(最小改动):fake hooks 记录 output 是否到达(:output/:no-output 标记),调用处补传 { parts: [] } / { system: [] } / { text: "" },legacy lane 断言要求 :output 标记。做了变异验证:把 wrapper 临时改回单参调用,恰好 1 个测试 AssertionError 失败 —— 证明新断言真的钉住了这个回归。修复后重跑:typecheck clean、全量 1705/1703 pass/2 skipped/0 fail、build clean、新 head CI 绿。
中文摘要:核对了 docker E2E 硬化的三项修复(output 双参透传、package cache 候选路径、log 接线)均正确且本地/CI 全绿;发现并直接修复了"双参契约无单测钉住"的测试缺口(变异验证过),另报告了一个不阻塞的小观察(cache 版本排序为字典序非 semver),可以合并。
…ode install (#927) - pick ONE effective plugin key by host major version (>=2 -> plugins, 1.x/probe-failure -> plugin): 1.x hard-errors on 'plugins', 2.x merges both keys, so dual-writing is impossible and the probe fallback can never write a dead line - write target = OPENCODE_CONFIG override, else highest-precedence file already present (opencode.jsonc > opencode.json > config.json), else create opencode.json — no more second file next to an existing config - JSONC targets get surgical top-level-key edits (jsonc-parser), so user comments/formatting survive byte-for-byte; plain JSON keeps the historical full re-serialize; broken targets are refused, never overwritten - compaction.auto is set to false only when the target does not already say auto:false (single source of truth); remove/status now recognize our entry under either key spelling and strip legacy acp entries from both
Fixes #920
What
On OpenCode 1.x, after
bili plugin install opencode, old opencode-acp sessions keep working and new sessions run through bili — no read-only-archive compromise.Mechanism
loadLegacyAcp()imports the installedopencode-acppackage directly (.opencode/node_modules→ projectnode_modules→ global npm root → opencode config-scope modules, first hit) by calling itsserver(ctx)withBILLION_CONTEXT_PROXYunset strictly around the call — its ONLY env check is at entry (probed: index.ts:38), executors never re-check.<XDG_DATA_HOME>/opencode/storage/plugin/acp/<sid>.json(probed: getDefaultStorageDir, lib/state/persistence.ts:67). Ids sanitized before touching the fs.createV1ServerHooks):forwardToolto the proxy (plugin mode). acp tool args are kernel-compatible — verifiedparseCompressArgsaccepts thecontent: [{topic,startId,endId,summary}]object form — so new-session calls forward verbatim.chat.headers: legacy →x-bili-plugin-bypass: 1only; new →x-bili-plugin+ conversation + context-window stamps.x-bili-plugin-bypassmakes the proxy forward VERBATIM (no wire injection / nudge / session binding — same skip-path as fix: stitched-stream usage double-count after compress re-request (adapter-anthropic >0 guard) #300 hopMarker / billion-context ACP kernel 改写 body 导致 ZCode (zcode.z.ai) 405/3012 #661 route passthrough)./acp+/dcp: legacy → acp handler, new → bili panel./bili/-URL self-disable is neutered); owned top-level keys (permission/command/experimental) merge back by reference change.Also in this PR
74701fb(installer strips legacyopencode-acpconfig entries, OpenCode 1.x: native v1 support via the standard install path (near-v2 effectiveness) #918): it was pushed to the already-merged feat: OpenCode 1.x native support — V1 .server() hooks on the standard install path #919 branch after the merge and got orphaned; this PR carries it so the stack onfeat/pi-native-pluginis complete. (The absorption design depends on it: config entry must go, package stays on disk.)Note on base
Base is
feat/pi-native-plugin(the integration branch #850/#919 merged into), NOT master.Tests
tests/opencode-native-v1.test.ts(24 pass): lane routing (tools/headers/command/transforms per session), shadow-config merge, provider-hidden assertion, legacy state-file detection + id sanitization.tests/plugin-bypass.test.ts(new, 2 pass): bypassed requests reach the upstream verbatim (no injected tools); without the header the same request gets the plugin pipeline.Known limits (documented)
acp_context_recaphas no proxy counterpart — on new sessions the proxy answers with its unknown-tool message.opencode plugin opencode-acpconfig entries are still manual removal (installer warns).