Repository navigation
Conversation
OpenCode v2 validates the context event's `system` array against
LLM.SystemPart, which is { type: "text", text: string }. This pushed the
PRE_COMPUTE_GUIDANCE template literal directly, which fails schema
validation. Once such an entry lands at system[4] or later, every request
from the session fails, so the failure looks like a dead session rather
than a bad plugin.
Refs anomalyco/opencode#51269
The v2 entry had no test coverage at all, which is how the bare-string push reached main. These four cases drive setup() with a mock context and assert that the "context" hook appends a SystemPart rather than a string, that the guidance text survives, that existing entries are left alone, and that an event without a system array is not mutated. Verified to fail against the pre-fix code (Expected "object", Received "string") and pass after it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
opencode-token-optimizer0.1.0 is a v1 plugin: it builds a v1hooksobject (hooks["tool.execute.before"] = ...) and relies on the v1 plugin loader. On OpenCode 2.0.x that plugin shape doesn't register, so the three tools (track_task,check_duplicate,validate_task_scope) and the pre-computation system-prompt guidance don't load.What this PR does
Adds
src/index.v2.ts— a port to the v2 plugin API ({id, setup(ctx)}):ctx.tool.transform(editor => editor.add({...})).ctx.session.hook("context").tsccompiles it todist/index.v2.jsalongside the existing build; the default v1 entry is untouched.On 2.0.16 (where this is the live, in-production reference implementation):
track_task(taskId, description)— in-memory registry; returns{duplicate, existingTask}so a second delegation of the same work is flagged.check_duplicate(query)— keyword-overlap (significant-word Jaccard, threshold 0.5) against the registry; returns{isDuplicate, matchedTask}.validate_task_scope(prompt, maxConcerns=1)— splits the prompt into concerns (file-path / function-call / capitalized-segment heuristics); if more thanmaxConcerns, returns{valid:false, concerns, suggestion:"Split into N separate tasks…"}.Notes for the maintainer
ctx.tool.transformorctx.session.hookis absent (pre-2.0 host), the tools simply aren't registered (no crash).— famewolf