Skip to content

perf(kaos): optimize large file reads with range and tail readers#971

Merged
7Sageer merged 1 commit into
MoonshotAI:mainfrom
7Sageer:fix/kaos-readlines
Jun 23, 2026
Merged

perf(kaos): optimize large file reads with range and tail readers#971
7Sageer merged 1 commit into
MoonshotAI:mainfrom
7Sageer:fix/kaos-readlines

Conversation

@7Sageer

@7Sageer 7Sageer commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

Supersedes #966.

Problem

Reading large text files through LocalKaos.readLines loads the whole file into memory, and the Read tool scans the whole file even when only a small line range or tail window is needed.

What changed

  • Stream UTF-8 readLines with chunk-list pending buffering, avoiding O(n²) long-line buffering and preserving BOM semantics after the first line.
  • Add local metadata scan, forward range reads, and reverse tail reads; the Read tool uses them when available and falls back to the existing iterator otherwise.
  • Keep non-UTF-8 reads on the decode-then-split path to preserve existing behavior.
  • Add tests for streaming readLines, range/tail reads, metadata scan, and Read tool optimized paths.

Limitation:

  • Currently only UTF-8 is supported.
  • SSH/ACP is not supported.

Verification

  • pnpm exec vitest run packages/kaos/test/local.test.ts packages/agent-core/test/tools/read.test.ts
  • pnpm lint
  • pnpm typecheck

@changeset-bot

changeset-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a8ac076

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 Patch

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 22, 2026

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

commit: a8ac076

@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
@7Sageer 7Sageer merged commit b84704b into MoonshotAI:main Jun 23, 2026
10 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 23, 2026
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