mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-29 23:22:22 +00:00
fix(core): normalize directory page headings (#45641)
This commit is contained in:
parent
e4bc8b765b
commit
fe188f8722
3 changed files with 40 additions and 1 deletions
5
.changeset/directory-page-heading.md
Normal file
5
.changeset/directory-page-heading.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@opencode-ai/core": patch
|
||||
---
|
||||
|
||||
Correct directory page headings when the read offset is zero.
|
||||
|
|
@ -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`
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue