Skip to content

fix: merge adaptive guidance into first system prompt - #29

Closed
BaconDroid wants to merge 8 commits into
ian-pascoe:mainfrom
BaconDroid:fix/upstream-pr21
Closed

BaconDroid wants to merge 8 commits into
ian-pascoe:mainfrom
BaconDroid:fix/upstream-pr21

Conversation

@BaconDroid

Copy link
Copy Markdown

Problem

The plugin used system.push() to inject adaptive-thinking guidance, which creates
a second system message. Strict chat templates (e.g. llama.cpp) require exactly one
system message at the beginning of the conversation and reject additional ones,
breaking template rendering before inference starts.

Fix

Merge the adaptive-thinking guidance into the existing first system prompt instead
of pushing a second one. Only inject a standalone entry when no system prompt exists
yet.

This mirrors the fix from PR #21 by @zoomdbz with adjustments for our V2 plugin API.

Changes

Before:

event.system.push({ type: "text", text: guidance });

After:

const existingSystem = event.system[0];
if (existingSystem === undefined || !existingSystem.text) {
  event.system.push({ type: "text", text: guidance });
} else {
  event.system[0] = { type: "text", text: existingSystem.text + "\n\n" + guidance };
}

Verification

  • ✅ tsc --noEmit passes clean
  • ✅ bun run build:plugin succeeds

Fix the temporary-reset baseline, read assistant-shaped messages, merge
guidance into the first system prompt, and replace Zod config parsing
with a small validator.
Add an optional classifier (default opencode/big-pickle) and
afterIdle/afterUserMessage triggers for the guidance. The classifier uses
the same guidance, the last compaction summary or the current segment,
and the current message last. Session state is bounded at 5,000 entries,
expires after seven days, and is removed when a session is deleted.
V1 plugin implementations do not run in OpenCode V2 (PluginModule.LoadError),
so the V1 plugin function is replaced with Plugin.define({ id, setup }) and the
hooks are mapped to the V2 domains: ctx.tool.transform (set_reasoning_effort),
ctx.event.subscribe (triggers), and session hooks for the classifier/guidance.

The classifier's per-request level is applied to the real provider request via
event.options and scoped model.request/http.request overrides (mutating
event.model never reaches the request on V2). Temporary tool changes restore
the pre-tool session variant at idle and never undo user model/agent choices.

76 tests; verified on opencode 2.0.30 with wire-level probes.
Port to the OpenCode V2 plugin API
…aration succeeds

Installing this repo as a github: plugin spec runs npm's git-dep
preparation (npm install --force --include=dev inside the clone), which
crashes npm 10.9.9's arborist while walking vitest's optional peer set
('Cannot read properties of null (reading 'edgesOut')'). The plugin then
never loads from a github: spec.

The overrides entry makes arborist materialize the
@vitest/browser-playwright node instead of hitting the null peer walk.
Verified against the exact failing install command.
fix: pin @vitest/browser-playwright via overrides so npm git-dep preparation succeeds
…ascoe#21)

Strict chat templates (e.g. llama.cpp) require exactly one system message
and reject additional ones, breaking template rendering. Merge the
adaptive-thinking guidance into the existing first system prompt instead
of pushing a second one; only inject a standalone entry when no system
prompt exists yet.
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​opencode/​plugin@​2.0.32991007896100

View full report

@BaconDroid BaconDroid closed this Nov 19, 2026
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