mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-30 06:42:09 +00:00
refactor(core): reuse read newline locator (#45616)
Reuse the reader newline locator for the terminal tree leaf while preserving accumulated offsets and the whole-tree fallback. Add chunk-boundary coverage.
This commit is contained in:
parent
705606face
commit
284b222489
2 changed files with 17 additions and 6 deletions
|
|
@ -361,12 +361,8 @@ const textOffset = (tree: TextNode, newline: number) => {
|
|||
if (!child) return tree.summary.bytes
|
||||
node = child
|
||||
}
|
||||
for (const [index, byte] of node.bytes.entries()) {
|
||||
if (byte !== 10) continue
|
||||
remaining--
|
||||
if (remaining === 0) return offset + index + 1
|
||||
}
|
||||
return tree.summary.bytes
|
||||
const end = nthNewline(node.bytes, remaining)
|
||||
return end === undefined ? tree.summary.bytes : offset + end
|
||||
}
|
||||
|
||||
const nthNewline = (bytes: Uint8Array, count: number) => {
|
||||
|
|
|
|||
|
|
@ -257,6 +257,21 @@ describe("ReadToolFileSystem", () => {
|
|||
}),
|
||||
)
|
||||
|
||||
it.effect("reads after a newline at the first chunk boundary", () =>
|
||||
Effect.gen(function* () {
|
||||
const { environment, files, directory } = yield* fixture
|
||||
const file = path.join(directory, "boundary.txt")
|
||||
yield* files.writeFileString(file, `${"a".repeat(256 * 1024 - 1)}\nsecond\n`)
|
||||
|
||||
const result = yield* ReadToolFileSystem.read(environment, absolute(file), "boundary.txt", {
|
||||
offset: 2,
|
||||
limit: 1,
|
||||
})
|
||||
|
||||
expect(result).toMatchObject({ type: "text-page", content: "second", offset: 2, truncated: false })
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("preserves the media ingestion limit message", () =>
|
||||
Effect.gen(function* () {
|
||||
const { environment, files, directory } = yield* fixture
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue