Skip to content

fix(opencode): strip webfetch page boilerplate and document API endpoints - #219

Merged
mdev34-lab merged 2 commits into
dev-vibecodedfrom
arena/c27e983e-alphacode
Oct 7, 2026
Merged

mdev34-lab merged 2 commits into
dev-vibecodedfrom
arena/c27e983e-alphacode

Conversation

@mdev34-lab

Copy link
Copy Markdown
Owner

Issue for this PR

Closes #190

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Rendered HTML fetches returned page chrome instead of content: fetching a GitHub PR/checks page produced roughly 10 KB of nav menus, sign-in prompts, cookie text and footer links with only a few lines of real content, and the follow-up call to an unauthenticated api.github.com endpoint 404'd. This PR implements both halves of the issue.

Code (packages/opencode/src/tool/webfetch.ts): HTML is parsed before conversion and boilerplate elements are removed — nav, header, footer, aside, [role='navigation'], [role='banner'], [role='contentinfo'], and class names containing cookie or footer. One deviation from the issue's snippet: doc.querySelectorAll is not usable here. querySelectorAll is provided by css-select, which is not in this package's tree — htmlparser2 only ships parseDocument and the domutils traversal helpers (including through its DomUtils re-export). Adding css-select would have broken the "no new dependency" criterion, so the same selector list is matched structurally against the parsed tree and re-serialized for conversion. No dependency, no per-domain rule. The strip runs on the markdown and text HTML paths; format: "html" still returns the page verbatim.

Prompt (packages/opencode/src/tool/webfetch.txt): added the requested note about page chrome, preferring API endpoints / raw URLs, and not retrying unauthenticated requests that 404.

One honest caveat on the acceptance criteria: on today's GitHub markup the nav, footer, cookie and marketing blocks are gone, but GitHub's "Skip to content" anchor sits in a plain header-wrapper div that is a sibling of <header>, so the selector list from the issue does not match it. I kept the list exactly as specified instead of adding a GitHub-specific rule or a broad [class*='header'] rule that would risk dropping real article headers.

How did you verify your code works?

  • cd packages/opencode && bun test test/tool/webfetch.test.ts — 25 pass / 0 fail, including 4 new tests: boilerplate stripping for markdown (tag, role and class selectors), stripping in text output, format: "html" left untouched, and the new tool-description text being wired through to the model-facing description.
  • Scoped tsc --noEmit over src/tool/webfetch.ts + its test file with the package tsconfig: clean apart from a pre-existing, unrelated photon_rs_bg.wasm resolution error caused by installing with --ignore-scripts in this sandbox. The full bun run typecheck cannot complete here — tsc/tsgo are OOM-killed at ~2–3 GB heap on this 4 GB box.
  • prettier --check on both changed TS files: clean. oxlint: only a pre-existing warning in the test file's layer helper.
  • Real page check: served a live GitHub PR page through the tool; converted markdown went from 40.2 KB / 979 lines to 32.7 KB / 779 lines, with Terms, Privacy, cookie and Footer text gone and the conversation content still present.
  • bun test test/tool/ (whole directory): 529 pass, 3 fail — tool parameters > JSON Schema (wire shape) > task and tool.registry > hides task background parameter unless experimental background subagents are enabled fail identically on a clean dev checkout (confirmed by stashing this change), and tool.shell abort > streams metadata updates progressively passes in isolation, i.e. a flake under full-suite load.
  • packages/core/test/tool-webfetch.test.ts: 12 pass (untouched, checked for regressions).

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@kilo-code-bot

kilo-code-bot Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Code Review Summary

This review did not finish. The model reached its output limit before it
could write the review — a reasoning model can spend the whole budget thinking.
Re-run the review, or lower the model's thinking effort, and it should get
further. Any inline comments below are from an earlier review.

Previous Review Summary

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review

This review did not finish. The model reached its output limit before it
could write the review — a reasoning model can spend the whole budget thinking.
Re-run the review, or lower the model's thinking effort, and it should get
further. Any inline comments below are from an earlier review.

dev is already an ancestor of this branch (behind_by 0), so there is nothing to
rebase or merge and the diff is unchanged; this empty commit re-runs the PR
checks so a review is produced on the current head.

Co-authored-by: arena-agent <[email protected]>
@mdev34-lab
mdev34-lab changed the base branch from dev to dev-vibecoded October 7, 2026 11:31
@mdev34-lab
mdev34-lab merged commit c8b77fc into dev-vibecoded Oct 7, 2026
7 of 9 checks 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.

webfetch returns page chrome verbatim and gives no guidance on API endpoints — strip boilerplate before markdown conversion, document 404 handling

1 participant