fix(opencode): route webfetch through the WebFetch redirect (#1052) - #1059
Open
gegemeimingzi wants to merge 1 commit into
Open
fix(opencode): route webfetch through the WebFetch redirect (#1052)#1059gegemeimingzi wants to merge 1 commit into
gegemeimingzi wants to merge 1 commit into
Conversation
) OpenCode registers its fetch tool as `webfetch`, but TOOL_ALIASES only mapped `fetch`. The alias lookup missed, `canonical` stayed `webfetch`, and the WebFetch redirect branch never matched — the tool executed as a plain allow with zero routing interception. Add the `webfetch: WebFetch` alias so opencode fetch calls are denied and redirected to ctx_fetch_and_index / ctx_search like every other platform's WebFetch. TDD: new test in tests/hooks/core-routing.test.ts (WebFetch domain) failed before the alias (null result), passes after (deny + redirect reason). Real-path check: compiled opencode plugin's tool.execute.before throws the redirect error for a webfetch payload with the alias, and passes through without 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.
What / Why / How
Fixes #1052.
What — Add the missing OpenCode
webfetchalias toTOOL_ALIASESinhooks/core/routing.mjs:Why — OpenCode registers its fetch tool as
webfetch(Tool.define("webfetch")), butTOOL_ALIASESonly mapped"fetch". The alias lookup missed,canonicalstayedwebfetch, and theif (canonical === "WebFetch")redirect branch never matched — so the tool executed as a plain allow with zero routing interception (the page bytes enter the conversation, noctx_fetch_and_index/ctx_searchredirect).How — One-line alias addition, same shape as the neighbouring
"fetch": "WebFetch"entry. Hook-only change:hooks/core/routing.mjsis plain JS loaded fresh on each invocation, no rebuild needed (per CONTRIBUTING "What needs rebuild?").Affected platforms
Test plan
TDD (red → green) — added one test to the existing
tests/hooks/core-routing.test.ts(WebFetch domain, per CONTRIBUTING "Do NOT create new test files"):routePreToolUse("webfetch", { url }, …, "opencode", …)→null(no interception) — test failed as expected{ action: "deny", reason: "WebFetch redirected … ctx_fetch_and_index … ctx_search" }tests/hooks/core-routing.test.ts: 96/96 passnpm run typecheck: passesReal-path verification (no OpenCode CLI on this machine, so done via the compiled plugin's actual hook surface): loaded the compiled
build/adapters/opencode/plugin.jsand invoked its realtool.execute.beforehook with awebfetchpayload:context-mode: WebFetch redirected. Call context-mode_ctx_fetch_and_index(url: …)) → OpenCode blocks the calltool.execute.before's deny path in this plugin isthrow Error, which OpenCode catches and turns into a denied tool call — so the throw observed is the same interception a live OpenCode session would hit.Honest note on
npm test: the full suite on this Windows box reports pre-existing environment failures unrelated to this change —EPERMon symlink creation (Windows needs admin to create symlinks) intests/core/cli.test.ts, missing Python runtime + POSIX-shell expectations intests/executor.test.ts, and temp-dir cleanupEPERMin session-path tests. I verified this by stashing my change and running the suite on the untouchednextbaseline: the same failures appear (49–57 failed depending on run). The routing suite itself (tests/hooks/core-routing.test.ts) passes 96/96 with the change.Checklist
npm testpasses — routing suite 96/96; full-suite failures are pre-existing Windows-environment failures (verified identical on unmodifiednextbaseline; see Test plan)npm run typecheckpassesnextbranch (unless hotfix)