Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/opencode/src/tool/edit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ Performs exact string replacements in files.

Usage:
- You must use your `Read` tool at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file.
- When editing text from Read tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears AFTER the line number prefix. The line number prefix format is: spaces + line number + tab. Everything after that tab is the actual file content to match. Never include any part of the line number prefix in the oldString or newString.
- When editing text from Read tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears AFTER the `|` separator. The line number prefix format is: spaces + line number + tab. Everything after that `|` is the actual file content to match. Never include any part of the line number prefix in the oldString or newString.
- The format is: [line_number] |[actual_file_content]
- Everything before the `|` (including spaces) should be discarded
- Everything after the `|` (including ALL leading indentation) is the actual file content
Example:
42 | function foo() {
↑ ↑
metadata actual indentation (spaces/tabs to preserve)
- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
- Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked.
- The edit will FAIL if `oldString` is not found in the file with an error "oldString not found in content".
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/src/tool/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const ReadTool = Tool.define("read", {
}

const content = raw.map((line, index) => {
return `${(index + offset + 1).toString().padStart(5, "0")}| ${line}`
return `${(index + offset + 1).toString().padStart(5, "0")} |${line}`
})
const preview = raw.slice(0, 20).join("\n")

Expand Down
Loading