From 7f30ae93c82b8b55749796920819d22ec9803051 Mon Sep 17 00:00:00 2001 From: Aiden Cline Date: Mon, 26 Jan 2026 09:04:36 -0500 Subject: [PATCH] fixes --- .../src/cli/cmd/tui/routes/session/index.tsx | 24 +++++++----- packages/opencode/src/session/instruction.ts | 39 +++++++++++++------ packages/opencode/src/tool/read.ts | 11 +++--- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx b/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx index aceb0c5096..8929fdbdc4 100644 --- a/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx +++ b/packages/opencode/src/cli/cmd/tui/routes/session/index.tsx @@ -1707,22 +1707,26 @@ function Glob(props: ToolProps) { function Read(props: ToolProps) { const { theme } = useTheme() const loaded = createMemo(() => { - if (props.part.state.status !== "completed") return - if (props.part.state.time.compacted) return - return props.metadata.loaded + if (props.part.state.status !== "completed") return [] + if (props.part.state.time.compacted) return [] + const value = props.metadata.loaded + if (!value) return [] + return Array.isArray(value) ? value : [value] }) return ( <> Read {normalizePath(props.input.filePath!)} {input(props.input, ["filePath"])} - - - - ↳ Loaded {normalizePath(loaded())} - - - + + {(filepath) => ( + + + ↳ Loaded {normalizePath(filepath)} + + + )} + ) } diff --git a/packages/opencode/src/session/instruction.ts b/packages/opencode/src/session/instruction.ts index 33db55a20e..7ea65e86c2 100644 --- a/packages/opencode/src/session/instruction.ts +++ b/packages/opencode/src/session/instruction.ts @@ -119,8 +119,13 @@ export namespace InstructionPrompt { for (const part of msg.parts) { if (part.type === "tool" && part.tool === "read" && part.state.status === "completed") { if (part.state.time.compacted) continue - const filepath = part.state.metadata?.loaded - if (filepath) paths.add(filepath) + const loaded = part.state.metadata?.loaded + if (!loaded) continue + if (Array.isArray(loaded)) { + loaded.forEach((p) => paths.add(p)) + } else { + paths.add(loaded) + } } } } @@ -134,18 +139,28 @@ export namespace InstructionPrompt { } } - export async function resolve(messages: MessageV2.WithParts[], dir: string) { - const filepath = await find(dir) - if (!filepath) return undefined + export async function resolve(messages: MessageV2.WithParts[], filepath: string) { + const system = await systemPaths() + const already = loaded(messages) + const results: { filepath: string; content: string }[] = [] - if ((await systemPaths()).has(filepath)) return undefined - if (loaded(messages).has(filepath)) return undefined + let current = path.dirname(path.resolve(filepath)) + const root = path.resolve(Instance.directory) - const content = await Bun.file(filepath) - .text() - .catch(() => undefined) - if (!content) return undefined + while (current.startsWith(root)) { + const found = await find(current) + if (found && !system.has(found) && !already.has(found)) { + const content = await Bun.file(found) + .text() + .catch(() => undefined) + if (content) { + results.push({ filepath: found, content: "Instructions from: " + found + "\n" + content }) + } + } + if (current === root) break + current = path.dirname(current) + } - return { filepath, content: "Instructions from: " + filepath + "\n" + content } + return results } } diff --git a/packages/opencode/src/tool/read.ts b/packages/opencode/src/tool/read.ts index abb4241417..028a007ccc 100644 --- a/packages/opencode/src/tool/read.ts +++ b/packages/opencode/src/tool/read.ts @@ -60,8 +60,7 @@ export const ReadTool = Tool.define("read", { throw new Error(`File not found: ${filepath}`) } - const dir = path.dirname(filepath) - const instruction = await InstructionPrompt.resolve(ctx.messages, dir) + const instructions = await InstructionPrompt.resolve(ctx.messages, filepath) // Exclude SVG (XML-based) and vnd.fastbidsheet (.fbs extension, commonly FlatBuffers schema files) const isImage = @@ -76,7 +75,7 @@ export const ReadTool = Tool.define("read", { metadata: { preview: msg, truncated: false, - ...(instruction && { loaded: instruction.filepath }), + ...(instructions.length > 0 && { loaded: instructions.map((i) => i.filepath) }), }, attachments: [ { @@ -138,8 +137,8 @@ export const ReadTool = Tool.define("read", { LSP.touchFile(filepath, false) FileTime.read(ctx.sessionID, filepath) - if (instruction) { - output += `\n\n\n${instruction.content}\n` + if (instructions.length > 0) { + output += `\n\n\n${instructions.map((i) => i.content).join("\n\n")}\n` } return { @@ -148,7 +147,7 @@ export const ReadTool = Tool.define("read", { metadata: { preview, truncated, - ...(instruction && { loaded: instruction.filepath }), + ...(instructions.length > 0 && { loaded: instructions.map((i) => i.filepath) }), }, } },