Description
file.edited event should include line number information
We're building a plugin to track file edit positions using the file.edited event, but the event doesn't provide enough information to determine which line(s) were edited.
Currently, file.edited only provides:
{
"type": "file.edited",
"properties": {
"file": ".opencode/plugin/README.md"
}
}
This tells us which file was edited, but not where in the file the edit occurred.
Use Case
We want to track the line numbers of edits made by OpenCode agents so users can navigate through their edit history using commands like "jump to previous/next edit location". This is similar to how IDEs track code changes.
Our plugin integrates with agent-last-position, a service that maintains a history of (file_path, line_number) pairs and allows navigation between them.
Attempted Workarounds
1. Using session.diff event
We tried using session.diff which provides before and after file contents:
{
"type": "session.diff",
"properties": {
"diff": [
{
"file": "path/to/file",
"before": "", // Often empty!
"after": "full file contents...",
"additions": 42,
"deletions": 0
}
]
}
}
Problems:
- The
before field is empty ("") for files created during the session, even after they've been edited multiple times within the same session
- When
before is empty, we can't determine which lines were actually changed - the diff just shows the entire file as new
- The diff is cumulative (shows all changes since session start), not incremental (changes since last event)
- We have to run
diff(1) on before and after to extract line numbers, which is inefficient
- For files where
before IS populated (files that existed before the session), we do get proper diffs, but this inconsistency makes it unreliable
Proposed Solution
Enhance the file.edited event to include edit location information:
{
"type": "file.edited",
"properties": {
"file": ".opencode/plugin/README.md",
"edits": [
{
"range": {
"start": { "line": 32, "character": 0 },
"end": { "line": 33, "character": 15 }
},
"newText": "..."
}
]
}
}
This would provide:
- The file path (already present)
- An array of edits with line/character positions (like LSP TextEdit format)
- The new text content (optional, but useful)
Alternative Solutions
-
Make tool.execute.before / tool.execute.after available as event types so plugins can capture file state before/after edits
-
Fix session.diff to include proper before/after states for all files, not just files that existed before the session started
-
Add a separate file.line.edited event that fires with just the line number for simpler use cases
Related
This is similar to how LSP provides textDocument/didChange with contentChanges that include range information.
OpenCode version
1.0.132
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
NixOS 25.05
Terminal
alacritty