Repository navigation
web: mcp__web__fetch — pages as files, answers that cite their lines - #370
Conversation
The living spec for replacing WebFetch with mcp__web__fetch (a new web plugin: a Defuddle clipper and a mod), its A/B evals against WebFetch, and the switch-over once they pass. Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Generation folders for the cache, a network boundary over every request the tool and the page cause, one clipper deadline, replies per non-text kind, a bounded summary input, a CJK-safe token estimate, an authoritative WEB_CHROME, the evals/ ignore rule anchored; the eval gate proposed as a held-out set with a bootstrap bound, pending the human. Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
… at xhigh through the gateway Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
…llisecond generations) Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
…nvironment-dependent tests) Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
web/clipper is the TypeScript package behind web/bin/clip.mjs, the committed esbuild bundle a session runs with plain node. `clip.mjs fetch <url>` saves the page as a generation folder in the shared cache: page.md in Obsidian Web Clipper's shape (Defuddle over linkedom, frontmatter plus `fetched`), its images in assets/, or page.txt / page.json / page.pdf (+ pdftotext) by content type, with meta.json holding the I1 result. Pages that extract to under 50 words are rendered in headless Chromium through an in-process filtering proxy with WebRTC's UDP and QUIC off. Every request the clipper, Defuddle's site extractors and the render make goes to public addresses only, pinned to the checked address. `numbered` feeds the summary; `prune` cleans. Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
…solute roots, numbered cut - A name that does not resolve (or any resolver failure) is now a network error at the transport boundary, so `fetch` prints ok:false and exits 0 instead of crashing with an ENOTFOUND stack; a malformed redirect Location is a network error too. - Image discovery recognizes reference-style images (full, collapsed and shortcut, through their definitions) and rewrites each in place as an inline image, leaving the definition to links that share it; image syntax inside inline code spans, or escaped, is no longer taken for an image. - The cache root is made absolute (option, WEB_CACHE_DIR, XDG_CACHE_HOME), so every dir and file in a result is absolute as I1/I2 promise. - `numbered` prints a first line that alone passes the cap cut to fit, with "cut": true on the JSON line (spec I1). - The under-1-KiB image test fetches served markdown, so the pixel is always found and every assertion runs. Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
A new plugin in this marketplace, `web` (0.1.0, versioned on its own),
whose mod registers mcp__web__fetch at every session's start, in the
prompt's tool list. It runs the clipper (bin/clip.mjs) and replies in the
shape the page needs: the page whole under ~5k tokens (image links made
absolute), else its path and outline; with `prompt`, haiku's answer over
the numbered page citing its lines, retried at half the cap when the
prompt is too long, with the page instead when the summary fails. Non-text
kinds (a PDF without text, an image, a binary) never reach a model. A
failed fetch is the call's error through `{ deny }`, read by the model as
<tool_use_error>fetch failed: …</tool_use_error>. Each summary call's
usage goes to <cache root>/usage.jsonl; the cache's prune starts,
unawaited, when its stamp is a day old.
Wired into the marketplace, the version bump (doperpowers' audit excludes
web/), the mods-types typecheck, and a `web` CI gate (the clipper's tests
with rendering off, the bundle check, the mod tests).
Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Two cache tests published two generations back to back and expected the second to be current. On a fast runner both can land in one millisecond, and then the random suffix orders them, as the design allows for two equally fresh copies; the `web` gate's first CI run failed on the reuse test that way. Each build now names its generation at a distinct time. No clipper behavior changes; the bundle is untouched. Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
…wn summary - The half-cap retry compared the two excerpts' headers, and a cut first line gives `lastLine: 1, cut: true` at either cap, so a one-line page too long for the model was never asked again over its shorter cut. It now compares the excerpts' text. - R1 rewrote only `](assets/NN.ext)`, so an image with a title, spacing or angle brackets around its destination stayed relative. The destination is now rewritten alone, whatever follows it. - A summary request that throws (a model the engine refuses to call) went to the catch-all R4 and lost the fetched page. It is now a failed summary: the page comes back opening with why, its usage line reason `request-failed`. The registration's catch still answers a step that throws before the page is in hand. - The gate's `npm ci` runs with `--ignore-scripts`: no dependency needs its install script, and new warnings stay visible. Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Eight categories of five, two for development and three held out for the final gate; 16 more finals for an inconclusive criterion 1. Every fact is checked against the page's own source (the authoring log stays in the SDE workspace). The root .gitignore's evals/ rule is anchored to the root, so web/evals/ is tracked and only its runs/ are ignored. Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
run.py runs each task in configuration A (WebFetch only) and B (mcp__web__fetch only): claude -p on sol at xhigh, in a temporary HOME whose settings hold only the gateway's keys, copied file to file, and an environment built from nothing. It resumes (a graded result file is skipped), grades each run as it lands, and with --pilot projects the cost of a development round and of the final run. grade.py asks opus, with no tools, over an answer whose paths, tool names and line citations are masked; the verdict follows the facts. report.py judges a run folder against the four pass criteria (a seeded task-level bootstrap for the first). Their unit tests join the web gate. Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
…basis
The pilot's projection.json sat beside the run files, and grade.py's own
folder walk took it for a run. Both scripts now share one filter for I4
run files. The grader's usage keeps Claude Code's costBasis per model
("list" for opus and haiku, "unknown" for sol), so a projection can say
which reported dollars are real.
Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Review findings on the suite, before any development spend: - report.py judged whatever runs a folder held. It now checks them against the matrix the manifest's set calls for (every task x both configurations x the design's runs per task): runs missing, not validly graded (a verdict and a boolean for every key fact), duplicated, or not in the matrix make the folder INCOMPLETE, with no gate verdict and its figures labelled provisional. - A run that reaches its limit gets SIGINT first, on which claude -p writes its result line with its usage; a process deaf to that is killed 30 s later. A run with no result line has its tokens and cost recorded as unavailable (null), not zero, and its wall time as its duration. Medians leave unavailable values out and say how many; criterion 4 cannot pass while a gist run's usage is unavailable. - The grader's mask takes file URIs whole, fragment included, before ordinary paths, along with any cache path and generation name left over. Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
…sk only what is asked The js category had been chosen among pages the clipper's own render handled, which conditioned it on the configuration under test: Terraform (render timeout) and PubChem (unrendered) were dropped for that. It is now re-picked on a rule that never consults the clipper's render: a plain fetch that returns the page with under 50 words, the content present in an independent Playwright render of full Chromium, and a stable page; then a seeded draw (20261025), one page per site, 2 dev / 3 final / 2 reserve. Terraform's vpc module enters as a reserve; PubChem stays out because a headless browser meets only its browser-check page. js-3 (npmgraph [email protected]) and the reserves js-r1 (Terraform vpc 5.0.0) and js-r2 (Bundlephobia [email protected]) are new, their facts checked against their sources; css-vars-ponyfill, tokio and open-vsx were not drawn. The answer keys are swept so each claim holds only what its question asks (the grader counts a claim the answer leaves out as false): unrequested detail such as Mamba's learning rate and batch size, issue numbers, and the gist facts' secondary figures is gone. The candidate table and the list of changed claims are in the authoring log. Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
…fore the final run Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
…s unit
The file-URI pattern matched any "file:" and the text after it, so code-r2's
own code (`Line from file: ${line}`) was masked into a mismatch and a
perfect verbatim answer would fail. It now needs the scheme at a word
boundary and `file://` with a path; a test holds the real code-r2 answer
unchanged and a file:///private/var/… citation still hidden.
exact-detail-2 keeps "30000 (milliseconds)": the unit is what makes an
answer of 30 seconds the same value.
Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
- A connection attempt gets 2.5 s before happy-eyeballs tries the next address (Node's 250 ms lost archive.apache.org from Seoul, its IPv6 unreachable), and a failure that names no message (an AggregateError) is reported by each address and code, not as "network error:". - A 403 to the plain fetch is tried once in headless Chromium; when the render brings back a page, that page is returned with a note saying so (techblog.woowahan.com turns the client away and lets the browser in). - A <noscript> image is kept, in a <figure>, as the content a script would have drawn (the Rust survey's charts: 0 of 19 reached page.md), unless the page already shows it as a lazy image. Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
- The 403 fallback takes the render only when Chromium's NetLog shows the main-frame document answered 2xx. A denial page renders to a DOM like any page, so word count alone turned a site's long denial into a cached success; now the 403 stands, uncached. - The fallback renders the URL the plain fetch ended at, and extracts and records the URL the browser's document was served from, so a page reached by a redirect resolves its relative images and links there. - A <noscript> image is dropped as a lazy image's twin only when that lazy image sits beside it, under the same parent: the same picture as a nav thumbnail no longer removes the article's chart. - The connect-attempt test checks the option reaches the request. Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
…cript twin must sit beside it - The browser's NetLog proves a walled page only when the last main-frame response could have become the document. A 204 or 205, an attachment, a redirect or a type other than HTML replaces nothing, so the DOM is still an earlier document of unknown status, and the 403 stands. A denial that navigated on to a 204 had come back ok, rendered, as /empty. - A <noscript> image is dropped as a lazy image's copy only when its element sibling just before or after is that lazy image (data-src, data-srcset, loading=lazy), alone or in a wrapper; a thumbnail of the same picture nested elsewhere in the article or the body no longer removes the chart. Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
The final run, once, on the frozen tool (542ba02; web/ byte-identical at c4b1772): 192 of 192 runs, every one correct in both configurations. Criterion 1 mean d +0.000 [+0.000, +0.000]; 2 every category 12/12; 3 no tool-caused B error (js-4's 404s are URLs the agent guessed on GitHub); 4 gist median tokens B/A 0.67x. The three dev rounds below it. Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
… served document, CONNECT fallback - Image requests carry a Referer by the browsers' default policy (strict-origin-when-cross-origin), worked out again at every redirect hop: the page URL without fragment or credentials to its own origin, the bare origin to any other, nothing from HTTPS to HTTP. A signed or token-bearing page URL no longer reaches third-party image hosts. A Referer passed as a header is held to the same policy. - A low-word page's render replaces it only when Chromium's NetLog shows the browser was served a 2xx document, as the 403 fallback already required; a long denial, a browser-side 404/5xx or a failed navigation keeps the plain result, with a note saying why. - An accepted render is extracted, its images resolved, its frontmatter `source` and the result's finalUrl set, at the URL of the document the browser ended on, not the one the plain fetch asked for. - The render proxy's CONNECT tunnels try every checked address in turn (happy eyeballs over the pinned lookup, 2.5 s an attempt), so an unreachable first address no longer gives 502; plain proxied requests get the same attempt bound. Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
…sniffs it The served-document check required an explicit HTML Content-Type, so a 2xx main-frame response with none, which Chromium MIME-sniffs and renders as the page, was taken as no evidence and the render discarded: package.elm-lang.org (an eval js task) saved 0 words where the render holds 5,216. A missing type now counts; 204/205, attachments, a redirect with nothing after it, and an explicit non-HTML type are still rejected. Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
…ective Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
… diff on all 40 eval URLs: identical) Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aa361be6b3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const LAZY_ATTRIBUTES = ['data-src', 'data-srcset', 'data-lazy-src', 'data-original'] | ||
|
|
||
| function tidyMarkdown(md: string): string { | ||
| return md.replace(/\r\n?/g, '\n').replace(/\n{3,}/g, '\n\n').trim() + '\n' |
There was a problem hiding this comment.
Preserve blank lines inside extracted code blocks
When an HTML page contains consecutive blank lines inside a code example, this global replacement collapses them inside fenced code blocks as well as prose. I reproduced this through the committed clipper bundle with a Python triple-quoted string containing three consecutive newlines: the saved example contained only two, changing the string's value. Both the full-page reply and summaries then use the altered source, despite the tool supporting exact code retrieval. Restrict blank-line normalization to content outside code blocks.
Useful? React with 👍 / 👎.
| if (lines.slice(bodyStart - 1, firstHeading - 1).some(l => l.trim() !== '')) | ||
| out.push({ level: 0, title: '(top)', line: bodyStart, endLine: firstHeading - 1 }) | ||
| headings.forEach((h, i) => { | ||
| const next = headings.slice(i + 1).find(n => n.level <= h.level) |
There was a problem hiding this comment.
Compute heading boundaries without copying every remaining heading
For pages with many headings, slice(i + 1) copies the entire remaining heading array on every iteration, making outline construction quadratic even when the next sibling immediately satisfies find. A local reproduction with a 640 KB Markdown document containing 40,000 sibling headings took about 23 seconds just to build the outline, which was ultimately capped to one entry. Larger documents remain well below the 50 MB fetch limit but can spend the process budget in this synchronous loop before the page is published; the shared deadline cannot interrupt it. Compute section boundaries with a linear heading-stack pass instead.
Useful? React with 👍 / 👎.
| } else if (r.kind === 'json') { | ||
| const raw = decodeText(res.body, contentType, false) | ||
| let pretty: string | ||
| try { pretty = JSON.stringify(JSON.parse(raw), null, 2) + '\n' } catch { |
There was a problem hiding this comment.
Preserve numeric precision when formatting JSON responses
For JSON responses containing large integer identifiers or high-precision decimal values, parsing and reserializing through JavaScript numbers silently changes the data before it reaches the saved file or summary model. I reproduced this through the committed bundle: a response containing {"id":9007199254740993,"amount":1.0000000000000001} was saved with id equal to 9007199254740992 and amount equal to 1, without any warning. Preserve the original JSON text or use a formatter that retains numeric literals rather than converting them to IEEE-754 numbers.
Useful? React with 👍 / 👎.
Adds
web/, a new plugin in this marketplace (0.1.0), which gives agentsmcp__web__fetchas a replacement for Claude Code'sWebFetch. The tool saves each page as clean markdown in the shape Obsidian Web Clipper produces, with its images downloaded beside it, in a cache every session on the machine shares. It then replies in one of three ways:Readonly the sections it needs.prompt: an answer from Haiku that cites the saved file's line numbers, so each claim can be checked with oneRead.Pages that only render with JavaScript are rendered in headless Chromium behind a filtering proxy, which refuses loopback, private, link-local and CGNAT addresses, with WebRTC and QUIC off. PDFs are saved for
Readalong with their text.The switch-over (M4: denying
WebFetchin~/.claude, installing the plugin) runs after the merge and is not in this PR.Validation Evidence
ci-gatepassed 18 of 18 gates, includingweb(clipper suite, bundle rebuild byte-identical, mod kit tests, eval unit tests) andmods-types(5 plugins): https://github.com/SSFSKIM/doperpowers/actions/runs/40194487825bash web/tests/run.shon this Mac: clipper 105/105 with 0 skipped (Chromium egress traps and pdftotext included), bundle check clean, mod tests 48/48, eval unit tests 55 OK. The CI gate setsWEB_CHROME=none(Decision Log).<img>, afetch, a WebSocket and anRTCPeerConnectionat loopback traps. With the clipper's flags, 0 TCP connections and 0 UDP packets reached any trap, in 3 of 3 runs on the Playwright headless shell. The control cases did leak: 5 connections and packets got through with no proxy, and 1–3 UDP packets with the proxy but without the WebRTC/QUIC flags.127.0.0.1and169.254.169.254were refused.claude -p --plugin-dir websession:Unresolved Review Findings
All are real and narrow. Each was weighed against the design and left as debt.
web/clipper/src/images.ts(~52–60, 80–84).web/hooks/mods/reply.ts(~219–221).assets/NNfile gets rewritten too.web/clipper/src/extract.ts(~90–92).<noscript>chart's twin, even when it also holds other content such as a nav with links. The chart is then dropped.web/clipper/src/render.ts(~187–190).Residue
Acceptwith a 7-wordtext/markdownstub, and served markdown is never rendered. Proposed fix: when served markdown comes in under the 50-word render threshold, fetch again with a browserAcceptand take the HTML path. Only a reserve eval task is affected today.--dump-dom. deps.dev's page loses its "Published" header in extraction.mcp__web__fetchcalls in its web cell, as it doesWebFetch.Readcannot show an.svg, and some pages' charts are SVG; one eval image task was one.Sminos-Session: web-fetch-replacement#700c5e84 (doperpowers on macbook)