Skip to content

fix(core): strip boilerplate from webfetch conversions - #234

Merged
agenteinstinct1-max merged 2 commits into
dev-vibecodedfrom
instinct/issue-190-core-webfetch
Oct 10, 2026
Merged

agenteinstinct1-max merged 2 commits into
dev-vibecodedfrom
instinct/issue-190-core-webfetch

Conversation

@agenteinstinct1-max

@agenteinstinct1-max agenteinstinct1-max commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Issue for this PR

Closes #190

Type of change

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

What does this PR do?

Ports boilerplate removal to the migrated core webfetch path. Removes navigation/header/footer/aside elements, navigation/banner/contentinfo roles, and cookie/footer classes before markdown or text conversion. Raw HTML stays unchanged. Adds API/raw URL guidance, cautious 404 handling, and three pipeline regressions.

Produced by OpenCode v2.0.26. The pilot separately corrected the 404 wording so credentials are not blamed as the only cause. Kilo found an overly aggressive substring class match; that finding is pending a worker fix. Not merge-ready.

How did you verify your code works?

Pilot validation on dev-vibecoded a71ab99: 15 core webfetch tests passed; prettier passed; oxlint had 0 errors and 1 pre-existing Cloudflare type-assertion warning; git diff --check passed. Dependencies were installed with frozen-lockfile and ignore-scripts.

Core typecheck timed out without diagnostics and is still pending. Linux and Windows unit checks passed on f14df8f. Independent review is not clean: Kilo reported 1 warning and 4 suggestions. Further validation and the worker correction are pending.

Screenshots / recordings

Not applicable; no UI change.

Checklist

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

@github-actions

Copy link
Copy Markdown

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

Comment thread packages/core/src/tool/webfetch.ts Outdated

const BOILERPLATE_TAGS = ["nav", "header", "footer", "aside"]
const BOILERPLATE_ROLES = ["navigation", "banner", "contentinfo"]
const BOILERPLATE_CLASSES = ["cookie", "footer"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Substring class matching in BOILERPLATE_CLASSES is overly aggressive

"footer".includes("footer") matches legitimate content classes like page-footer, copyright-footer, footer-note, main-footer-content. Consider using word-boundary matching (split class string by whitespace and check exact token matches) instead of substring .includes().

mime === "application/javascript" ||
mime === "application/x-javascript"

const BOILERPLATE_TAGS = ["nav", "header", "footer", "aside"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: "aside" in BOILERPLATE_TAGS may remove legitimate sidebar content

The <aside> element is semantically meant for tangentially related content (sidebars, callouts, author bios, related links) which is often valuable to users. Consider removing "aside" from the default boilerplate list or making it configurable.

doc.children,
)
for (const element of boilerplate) DomUtils.removeElement(element)
return DomUtils.getOuterHTML(doc.children)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: stripBoilerplate return value may drop document wrapper for full HTML documents

DomUtils.getOuterHTML(doc.children) returns outer HTML of document's direct children. For a full HTML document (<html><head>...</head><body>...</body></html>), doc.children is [htmlElement], so this returns the <html> wrapper. For fragments, it returns fragment elements. Behavior is inconsistent but likely acceptable since output feeds markdown/text converters. Consider documenting the expected input format.

const BOILERPLATE_CLASSES = ["cookie", "footer"]

function stripBoilerplate(html: string) {
const doc = parseDocument(html)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: stripBoilerplate should handle empty/invalid HTML input gracefully

parseDocument("") returns a document with empty children. DomUtils.getOuterHTML([]) returns "". This works but consider adding an early return for empty/whitespace-only input to avoid unnecessary parsing.


expect(yield* executeTool(registry, call({ url: "https://1.1.1.1/page", format: "text" }))).toEqual({
type: "text",
value: "TitleBody",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Text output "TitleBody" lacks space between heading and paragraph

This matches existing extractTextFromHTML behavior (see line 79: "Helloworld wide"), but concatenating without spaces may surprise users. Consider whether a space separator between block elements would improve readability.

@kilo-code-bot

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

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • packages/core/src/tool/webfetch.ts
  • packages/core/test/tool-webfetch.test.ts
Previous Review Summary (commit f14df8f)

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

Previous review (commit f14df8f)

Status: 5 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 4
Issue Details (click to expand)

WARNING

File Line Issue
packages/core/src/tool/webfetch.ts 116 Substring class matching in BOILERPLATE_CLASSES is overly aggressive

SUGGESTION

File Line Issue
packages/core/src/tool/webfetch.ts 114 aside in BOILERPLATE_TAGS may remove legitimate sidebar content
packages/core/src/tool/webfetch.ts 128 stripBoilerplate return value may drop document wrapper for full HTML documents
packages/core/src/tool/webfetch.ts 119 stripBoilerplate should handle empty/invalid HTML input gracefully
packages/core/test/tool-webfetch.test.ts 209 Text output TitleBody lacks space between heading and paragraph
Files Reviewed (2 files)
  • packages/core/src/tool/webfetch.ts - 4 issues
  • packages/core/test/tool-webfetch.test.ts - 1 issue

Fix these issues in Kilo Cloud


Reviewed by free · Input: 409.7K · Output: 91K · Cached: 312.8K

@github-actions

Copy link
Copy Markdown

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant