From 80b085cfb36c0dfe5f6740a3a4764d16429a8228 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Thu, 22 Oct 2026 22:21:48 +0000 Subject: fix(opencode): inject the V2 bootstrap on compaction and generate requests The V2 plugin registered its bootstrap injector only on ctx.session.hook('context'). OpenCode 2 prepares each model request kind through its own hook: normal agent turns through `context`, the compaction (summary) request through `compaction`, and session-scoped one-shot generation through `generate` (packages/core/src/session/model-request.ts). Every built-in V2 plugin registers its handler on all three, and the upstream V1 migration guide says to do the same when a transform must apply to every request kind. So the compaction request's first user message lacked the bootstrap that every prior turn carried, and the prompt diverged right after system + tools. On a provider with prefix caching that is a cold re-prefill of the whole session on its largest request (#2391). Reproduced on real OpenCode 2.1.2 and 2.1.3 with a scripted stub model that pushes the session over the compaction ceiling: before, the compaction request shares 26.5k of 30.8k serialized chars with the previous agent request and differs at the first user message; after, the previous request is a full prefix of the compaction request. The handler body is unchanged (child-session skip, idempotence guard, checkpoint-only append), lifted into a named function and registered on all three hooks, each in its own try/catch. Based on PR #2409. Fixes #2391 Co-authored-by: Aashish <145881415+aashish254@users.noreply.github.com> Claude-Session: https://claude.ai/code/session_01SHANcr4A71nzuU9et4Fnba --- docs/README.opencode.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/README.opencode.md') diff --git a/docs/README.opencode.md b/docs/README.opencode.md index 3ffdd81..35e8226 100644 --- a/docs/README.opencode.md +++ b/docs/README.opencode.md @@ -126,7 +126,7 @@ The plugin does two things, using host-flavor-specific APIs: - **V2:** via the `setup()` function using `ctx.skill.transform()` (V2 native API, confirmed active at runtime) 2. **Injects bootstrap context** with a flavor-specific tool mapping: V1 sessions get the V1 tool names below, and V2 sessions get the V2 names. - **V1:** via `experimental.chat.messages.transform` hook - - **V2:** via `ctx.session.hook("context")` — the V2 equivalent (confirmed active at runtime) + - **V2:** via `ctx.session.hook()` on `context`, `compaction`, and `generate` — the V2 equivalent (confirmed active at runtime). Registering on all three keeps compaction requests on the same cached prompt prefix as normal turns. Controller sessions receive the using-superpowers bootstrap in transient model context. Delegated child sessions keep access to native skills but do not receive @@ -234,7 +234,7 @@ package name, not a local directory. ### Bootstrap not appearing - **V1:** Check OpenCode version supports `experimental.chat.messages.transform` hook. Restart OpenCode after config changes. -- **V2:** The plugin uses `ctx.session.hook("context")` for bootstrap injection. Verify the plugin loaded via `opencode api get /api/plugin`. Restart with `opencode service restart` after config changes. The `opencode2` command may be available as an alias. +- **V2:** The plugin uses `ctx.session.hook()` on `context`, `compaction`, and `generate` for bootstrap injection. Verify the plugin loaded via `opencode api get /api/plugin`. Restart with `opencode service restart` after config changes. The `opencode2` command may be available as an alias. ## Getting Help -- cgit