Skip to content

feat: native OpenCode 2 support and review fixes - #5

Merged
mathewbarnett merged 3 commits into
masterfrom
mbarnett/oc2-review-fixes
Nov 19, 2026
Merged

mathewbarnett merged 3 commits into
masterfrom
mbarnett/oc2-review-fixes

Conversation

@mathewbarnett

Copy link
Copy Markdown
Owner

Summary

Replaces the abandoned upstream OpenCode 1 compatibility layer with a native OpenCode 2 plugin implementation, then applies a round of review-driven fixes. OpenCode 1 is no longer supported; this fork targets OC2 2.3.x+ exclusively.

This is a fork of Tarquinen/opencode-dynamic-context-pruning, whose author moved active development to a commercial product and left an incomplete OC2 shim behind. The AGPL-3.0 core is retained, attribution is preserved, and the OC2 integration is now implemented against the public @opencode/plugin 2.x APIs instead of fabricated V1 objects.

Commits

  1. 8f9317c — feat: native OpenCode 2 support and fork migration
  2. c110bbb — fix: scope /dcp panel events, surface config warnings, address review findings
  3. cab3c66 — fix: retain undated history entries using real neighbouring timestamps

What changed

Native OpenCode 2 architecture

  • New lib/native/ entrypoints: plugin, messages, rpc, permissions, commands, notifications, system-prompt, theme, and tui.
  • index.ts / tui.tsx are thin entrypoints using the native Plugin.Plugin and Plugin.Definition types.
  • lib/native/messages.ts projects stored session entries into the shared engine's message shape and commits edits back onto real provider messages, preserving non-text parts, media, cache metadata, and tool-call/result pairing. No V1 objects are fabricated.
  • Model context limits come from ctx.model.transform; permissions are resolved from the OC2 PermissionRule[] shape (action/resource/effect) and enforced through ctx.permission.hook/assert.
  • Notifications are toasts delivered over a session-scoped RPC event; there is no in-session notification injection under OC2's public API.
  • Removed the V1 auth module, update checker, lib/v2/* shim, and the V1 server entry.

Review fixes

  • /dcp panel no longer pops in every open session. openPanel was an unscoped RPC broadcast; it now carries the invoking sessionID, and the TUI subscriber ignores events for other sessions.
  • Config warnings are now visible. They were routed to a stub client whose showToast only called console.warn, behind a 7-second timer. Warnings are collected during config load and flushed as real toasts once the RPC channel is live.
  • Malformed JSONC is rejected. jsonc-parser records errors in an array rather than throwing; the loader now checks that array so a broken config is ignored instead of partially merged.
  • Removed a duplicate prompts.reload() that re-read every override file twice per request.
  • Bounded debug context snapshots to 10 per session and capped cached session state at 100 sessions.
  • Stopped mutating the loaded config's protected-tool arrays when adding tool aliases.
  • Retained undated history entries using a real neighbouring entry's timestamp rather than silently dropping them; no synthetic timestamps are invented.
  • Removed runtime-dead V1 modules (lib/hooks.ts, lib/host-permissions.ts, server.js) and their tests, keeping live-code coverage in a trimmed test file.

Docs / licensing / packaging

  • Added CHANGELOG.md, NOTICE, and SPDX headers on all 77 source files.
  • README: compatibility matrix, local-data footprint, config reload semantics, and token-count/debug limitations.
  • dcp.schema.json / dcp.example.jsonc: dropped removed V1 options and updated URLs.
  • Package verification enforces tarball contents, runtime import graph, CJS interop, and a fully bundled TUI.

User-visible / config migration notes

  • Requires OpenCode 2.3.x+. OC1 configs and plugins are not supported.
  • Removed options: autoUpdate and pruneNotificationType. They are now reported as unknown keys and ignored; notifications are toasts with verbosity controlled by pruneNotification.
  • dcp.jsonc is read once at plugin load — reload OpenCode to apply edits.
  • Percentage thresholds ("75%", "25%") are recommended over absolute token values so they adapt to each model's context window.
  • Bare /dcp opens the panel only in the session that invoked it.

Testing

  • npm run typecheck — clean
  • npm run format:check — clean
  • npm test — 155 root tests + 8 logger workspace tests, all passing
  • npm run check:package — build and tarball verification passing (167 entries)
  • npm audit --audit-level=high — passing (no high/critical advisories)

Added regression coverage for: session-scoped openPanel events, config warning delivery and malformed JSONC rejection, compression-timing state reset, and undated history entries.

Known limitations

  • Internal title/summarizer sub-agents are detected by system-prompt signature; a host that changes those signatures needs the signature list updated.
  • Token counts use an Anthropic tokenizer for every provider — treat them as approximations for non-Anthropic models.
  • permission: "ask" requires an interactive session.

Work completed by opencode/HY4 Flash Free — code changes, review fixes, tests, documentation, and release packaging for this branch were all done by opencode/HY4 Flash Free.

Replace the upstream V1 compatibility layer with native OC2 plugin APIs:
new lib/native entrypoints for plugin, messages, rpc, permissions, commands,
notifications, system prompt and TUI; shared engine kept provider-agnostic.
Remove V1-only auth/update/v2 shim modules, refresh docs, schema and example
config, and add native/regression test coverage.
… findings

- Scope openPanel RPC events to the invoking session so other open sessions
  no longer pop their panel on /dcp.
- Deliver config warnings/parse errors as real toasts at load time and reject
  malformed JSONC instead of partially merging it (jsonc-parser reports errors
  in an array rather than throwing).
- Remove duplicate prompt reload per request; bound debug context snapshots;
  cap cached session state and avoid mutating loaded config.
- Drop runtime-dead V1 hook/host-permission modules, their tests, and server.js;
  trim tests to live-code coverage.
- Add SPDX headers, NOTICE and CHANGELOG; document compatibility, local data,
  config reload semantics and token/debug limitations.
Entries without time.created were silently dropped from the compress tool's
message view. Resolve a timestamp from an existing neighbouring entry instead
of inventing one; apply the same lookup in the native message projection.
@mathewbarnett
mathewbarnett merged commit c9de3d1 into master Nov 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant