Skip to content

perf(acp): read line ranges over ACP without fetching whole files#996

Open
7Sageer wants to merge 4 commits into
MoonshotAI:mainfrom
7Sageer:feat/acp-range-read
Open

perf(acp): read line ranges over ACP without fetching whole files#996
7Sageer wants to merge 4 commits into
MoonshotAI:mainfrom
7Sageer:feat/acp-range-read

Conversation

@7Sageer

@7Sageer 7Sageer commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Note

This PR is stacked on #971. Only the last two commits are new; the rest is #971. Please review and merge #971 first — once it lands, this diff collapses to the ACP-only changes.

Related Issue

Builds on #971 (no separate issue).

Problem

When the agent reads a line range of a file over ACP, AcpKaos fetches the entire file through fs/read_text_file and slices it in memory, because it does not use the protocol's native line/limit parameters. For large files this transfers the whole file over the wire even when only a small window is needed.

What changed

  • AcpKaos now passes line/limit to fs/read_text_file for forward range reads, so a compliant client returns only the requested window instead of the whole file.
  • The Read tool uses this for ACP range reads. Because the total line count is unavailable without a full read, those reads omit the "Total lines in file" line.
  • AcpKaos defensively truncates to the requested limit if the client ignores it.
  • Added tests for the new AcpKaos range read and the Read tool's ACP path.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update. (No doc update — internal ACP read-path optimization; the read tool description does not document the total-lines line.)

7Sageer added 3 commits June 22, 2026 16:53
AcpKaos gains readLineRange, which passes ACP fs/read_text_file's native line/limit parameters so a compliant client returns only the requested window. The Read tool now uses it for forward range reads when the Kaos provides readLineRange but not scanTextFile (i.e. ACP), omitting the total-lines line that would otherwise require a full read. ACP range reads no longer transfer the whole file.
@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dbc0257

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 23, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@3142677
npx https://pkg.pr.new/@moonshot-ai/kimi-code@3142677

commit: 3142677

@MoonshotAI MoonshotAI deleted a comment from chatgpt-codex-connector Bot Jun 23, 2026
@MoonshotAI MoonshotAI deleted a comment from chatgpt-codex-connector Bot Jun 23, 2026
The media sniff in ReadTool runs readTextPreview on every Read. Over ACP it fetched the whole file via readText and sliced it, so a range Read still transferred the whole file once before the window read. Use readLineRange({ startLine: 1, maxLines: 1 }) instead so a compliant client returns only line 1; the defensive cap keeps non-compliant clients bounded too. detectFileType only needs the leading magic bytes plus a NUL scan, both covered by line 1.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits. You can see your limits in the Codex usage dashboard.

@7Sageer

7Sageer commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review 😭

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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