Repository navigation
Description
Problem
webfetch (packages/opencode/src/tool/webfetch.ts) has no way to window its output. Its Parameters schema is exactly url, format, and timeout — there is no offset and no limit, and no line-based truncation notice.
The tool always returns the entire converted content in one shot, bounded only by MAX_RESPONSE_SIZE = 5 * 1024 * 1024 on the raw response. Once the model has a large page, it has no way to ask for the next chunk. A model that wants lines 4000–6000 of a long document must either re-fetch and re-parse everything, or simply not page at all.
read (packages/opencode/src/tool/read.ts) already solves the identical problem for local files:
offset: Schema.optional(NonNegativeInt) // "The line number to start reading from (1-indexed)"
limit: Schema.optional(NonNegativeInt) // "The maximum number of lines to read (defaults to 2000)"and it emits continuation notices so the model knows more exists:
(Showing lines ${file.offset}-${last} of ${file.count}. Use offset=${next} to continue.)(Output capped at ${MAX_BYTES_LABEL}. Showing lines ${file.offset}-${last}. Use offset=${next} to continue.)(End of file - total ${file.count} lines)
Proposal
Mirror read's semantics on webfetch:
| param | meaning |
|---|---|
offset |
1-indexed line number to start returning from |
limit |
maximum number of lines to return; pick a default analogous to read's DEFAULT_READ_LIMIT |
Two design points worth settling explicitly rather than by analogy:
-
Apply the windowing after format conversion.
webfetchsupportstext,markdown, andhtml, and the conversion runs on the raw response.offset/limitshould operate on the content the model actually receives, i.e. post-conversion. Line numbers are only stable once conversion has settled — windowing the raw bytes would makeoffsetmean something different performat. -
Emit the same continuation notices as
read. Without a "use offset=N to continue" hint the parameters are nearly unusable, because the model cannot otherwise tell truncation from a complete result.readalso tracksmoreseparately from the byte cap, and that distinction should be preserved: hitting the line limit is resumable, hitting a byte cap may not be.
Worth considering while this is open: the raw-response 5MB cap is checked before conversion, so the effective ceiling on returned content is a conversion-dependent multiple of 5MB. #190 covers a different webfetch problem (page chrome being returned verbatim) but the two are adjacent.
Why this matters
Fetching long documentation or a large API reference is a normal thing to do, and today the only mitigation is to go find a more specific URL and re-fetch — which costs a round trip per chunk and often fails because the specific URL does not exist.
Acceptance
webfetchacceptsoffsetandlimit- windowing applies to the post-conversion content for every
format - output states the window and how to continue, matching
read's wording - no behaviour change when neither param is supplied
Activity