mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-24 14:55:19 +00:00
fixes
This commit is contained in:
@@ -1707,22 +1707,26 @@ function Glob(props: ToolProps<typeof GlobTool>) {
|
||||
function Read(props: ToolProps<typeof ReadTool>) {
|
||||
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 (
|
||||
<>
|
||||
<InlineTool icon="→" pending="Reading file..." complete={props.input.filePath} part={props.part}>
|
||||
Read {normalizePath(props.input.filePath!)} {input(props.input, ["filePath"])}
|
||||
</InlineTool>
|
||||
<Show when={loaded()}>
|
||||
<box paddingLeft={3}>
|
||||
<text paddingLeft={3} fg={theme.textMuted}>
|
||||
↳ Loaded {normalizePath(loaded())}
|
||||
</text>
|
||||
</box>
|
||||
</Show>
|
||||
<For each={loaded()}>
|
||||
{(filepath) => (
|
||||
<box paddingLeft={3}>
|
||||
<text paddingLeft={3} fg={theme.textMuted}>
|
||||
↳ Loaded {normalizePath(filepath)}
|
||||
</text>
|
||||
</box>
|
||||
)}
|
||||
</For>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<system-reminder>\n${instruction.content}\n</system-reminder>`
|
||||
if (instructions.length > 0) {
|
||||
output += `\n\n<system-reminder>\n${instructions.map((i) => i.content).join("\n\n")}\n</system-reminder>`
|
||||
}
|
||||
|
||||
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) }),
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user