fix(core): normalize directory page headings (#45641)

This commit is contained in:
Kit Langton 2026-08-28 13:29:41 -04:00 committed by GitHub
parent e4bc8b765b
commit fe188f8722
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
"@opencode-ai/core": patch
---
Correct directory page headings when the read offset is zero.

View file

@ -169,7 +169,7 @@ export const toModelContent = (path: string, offset: number | undefined, output:
] as const
if (output.type === "list-page") {
const start = offset ?? 1
const start = offset || 1
const content = [
output.entries.length === 0
? `Read directory ${path}, 0 entries`

View file

@ -678,6 +678,40 @@ describe("ReadTool", () => {
}),
)
it.effect("normalizes a zero directory offset in the model heading", () =>
Effect.gen(function* () {
readResult = new ReadToolFileSystem.ListPage({
type: "list-page",
entries: [FileSystem.Entry.make({ path: RelativePath.make("index.ts"), type: "file" })],
truncated: true,
next: 2,
})
const registry = yield* Tool.Service
const result = yield* executeTool(registry, {
sessionID,
...toolIdentity,
call: {
type: "tool-call",
id: "call-read-directory-zero",
name: "read",
input: { path: "src", offset: 0, limit: 1 },
},
})
expect(result.status).toBe("completed")
if (result.status !== "completed") return
expect(result.content).toEqual([
{
type: "text",
text: "Read directory src, entries 1-1\nindex.ts\n[Output truncated. Continue reading with offset: 2]",
},
])
expect(readCalls).toEqual([
{ input: AbsolutePath.make(path.join(process.cwd(), "src")), page: { offset: 0, limit: 1 } },
])
}),
)
it.effect("does not list a directory when permission is denied", () =>
Effect.gen(function* () {
allow = false