Skip to content

feat: read up to 2000 lines per call, exact continuation calls, CLI read --all - #30

Merged
qiansc merged 1 commit into
mainfrom
feat/read-ranges
Nov 30, 2026
Merged

qiansc merged 1 commit into
mainfrom
feat/read-ranges

Conversation

@qiansc

@qiansc qiansc commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Background

A single read returned at most 500 lines, so reading a whole file meant many calls, and agents had to work out the next call from NextStartLine themselves. The command line read 200 lines at a time with no way to read a whole file.

Changes

  • Read limit: read (MCP and POST /v1/repo/read) returns up to 2000 lines per call; the 256 KiB byte limit is unchanged and whichever comes first stops the read. An MCP read without end_line still reads 500 lines. A larger range is not an error: the first 2000 lines come back with Truncated, HasMore and NextStartLine.
  • read_many unchanged: 500 lines per item (now enforced inside the batch reader, independent of the single-read limit) and 1000 lines / 256 KiB / 30 seconds per batch.
  • MCP continuation hints: when more of the requested range remains, the text gives the exact next call, e.g. Next call: read {"repo":"…","revision":"<full SHA>","path":"<canonical path>","start_line":N,"end_line":min(requested end, N+1999)}, including an explicitly passed plugins value. A complete range that ends before the file only says from which line the file continues. Unread read_many items (READ_BUDGET_EXCEEDED, READ_TIMEOUT) with a valid range get a Retry call with their original range. Tool descriptions and schemas updated.
  • CLI 0.7.0: sourcegraph read <repo> <path> --all [--rev] [--start] reads a whole file page by page (2000 lines per request; older servers answer 500) pinned to the first page's commit, with continuous line numbers. It checks every page (start line, advancing, contiguous NextStartLine) and stops after 20000 lines with exit code 0, a shell-safe continue command on stderr (-- before repo and path) and HasMore/NextStartLine in --json output. --start N without --end now reads lines N..N+199 instead of an invalid N..200 range. Plugin version 0.7.0.
  • Docs: docs/interfaces.md, skill, CLI README and web/plugins/llms.txt.

Risks

  • Explicit large ranges now return up to four times more text per call; omitted ranges and read_many are unchanged, so default context use does not grow.

Compatibility

No new fields and no breaking change. Older clients keep paging; each page can be longer. The new CLI works against older servers (500-line pages).

Testing

  • go test for internal/gitstore, internal/service, internal/mcpserver, internal/httpserver, plus the external plugin tests with a built context-evidence artifact; bun run check; scripts/audit-public.py; cd cli && bun test (10 tests against a fake server: 500- and 2000-line pages, 20000-line stop, quoting, misbehaving servers, --json).
  • New tests: line caps (500 default, 2000 explicit, 2000 + continuation for larger ranges, byte limit first, batch item 500); read_many item 500 while read returns 2000; hint contents (requested-end clipping, served commit, unusual paths, plugins) and a round trip that feeds the hint back through the MCP handler (symlink alias, quoted and Unicode paths).

🤖 Generated with Claude Code

…ead --all

- read: an omitted end line still reads 500 lines; an explicit range returns
  up to 2000 lines and 256 KiB, whichever comes first, then continues at
  NextStartLine. read_many keeps 500 lines per item and 1000 per batch.
- MCP: when more of the requested range remains, the text gives the exact
  next read call (repo, full commit, canonical path, start_line, end_line
  within the requested end, explicit plugins); a complete range that ends
  before the file only says where the file continues. Unread read_many
  items with a valid range get a retry call.
- CLI 0.7.0: `sourcegraph read --all` reads a whole file page by page at one
  commit with continuous line numbers, checks every page, and stops after
  20000 lines (exit 0) with a shell-safe continue command; `--start N` alone
  reads N..N+199.
- Docs, skill and CLI README describe the limits and hints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@qiansc
qiansc merged commit d2dc55c into main Nov 30, 2026
3 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.

1 participant