Skip to content

webfetch: add offset/limit so the model can page through large fetched content #204

Closed

Description

@mdev34-lab

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:

  1. Apply the windowing after format conversion. webfetch supports text, markdown, and html, and the conversion runs on the raw response. offset/limit should 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 make offset mean something different per format.

  2. 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. read also tracks more separately 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

  • webfetch accepts offset and limit
  • 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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions