[Feature] Add an ACP method to read timeline before-images (pre-edit snapshots) so clients can show only the agent's changes
Description
Nanocoder already saves a copy of each file before a mutating tool call touches it (the action timeline behind timeline/revert). ACP clients can list those checkpoints with timeline/list, but cannot read the saved contents.
I'd like a read-only ACP extension method that returns the before-image of a path for a checkpoint, with a clear result when no before-image exists.
Background: Nano-Collective/docs#109 (Git diff cannot reliably attribute agent changes), where this was proposed. Tracked from Nano-Collective/nanocoder-desktop#12 (item 6).
Use Case
Nanocoder Desktop has a Git review view. When a user has uncommitted edits in a file the agent also edits, the Git diff mixes both sets of changes, and the user must re-review their own earlier edits. The desktop wants an "Agent changes" view that diffs each touched file against its before-image from just before the agent's turn, and keeps the full Git diff alongside it.
The before-image is exactly what Nanocoder's timeline already stores, so the baseline is already on disk. Clients can't read it. The same method would help any ACP client that shows per-turn diffs.
The desktop needs this by its Milestone 2 if the "Agent changes" view is in v1, and otherwise later. Without it, the desktop falls back to labelling files "touched this turn".
Proposed Solution
Add a read-only extension method, for example timeline/read, taking {sessionId, checkpointId, path} and returning one of:
{kind: "text", content}: the file's contents before that tool call.{kind: "created"}: the file did not exist before that tool call. There is no before-image.{kind: "unavailable", reason}: no before-image exists, for example the file is binary, the checkpoint was pruned, or the path is not part of the checkpoint.
Details:
- The method only reads. It never changes files, history or the index.
- The path must be one of the checkpoint's
filesChanged, validated like the revert path (toRelativePath), so it cannot read arbitrary files. timeline/listalso reports whichfilesChangedentries were created, so a client can tell created from edited without a read.- Document how a client finds the baseline for a turn. Each checkpoint is one tool call, and a turn can have several, so the baseline for a path is the earliest checkpoint in that turn that touched it. Checkpoints from one turn share
truncateToMessageIndex. - Advertise the method under
_metainagentCapabilities, so clients detect support from the capability and not from the version.
Alternatives Considered
- Return the contents inside
timeline/list. Simple, but it makes every list call carry file contents, with up to 50 checkpoints per session. - Clients read
.nanocoder/timeline/<sessionId>/entries/<id>/files/directly. Works for a local client, but it couples clients to an internal storage layout, which Nanocoder may change, and it breaks if the agent is remote. - A higher-level method such as "agent changes since checkpoint N" that returns the before and after. More convenient, but it commits Nanocoder to diff semantics. A plain read keeps the policy in the client.
- Git-only attribution. Rejected in docs#109: it can't separate the user's uncommitted edits from the agent's in the same file.
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] This feature aligns with the project's goals (local-first AI assistance)
Current behavior, checked against main at fc01e23:
source/acp/acp-agent.ts(~L734):timeline/listreturns{entries: session.timeline.list()}. Each entry hasid,seq,toolCallId,toolName,title,timestamp,truncateToMessageIndexandfilesChanged. It requires the session to be loaded (requireSession).source/services/timeline-manager.ts:- Before-images are stored as UTF-8 under
.nanocoder/timeline/<sessionId>/entries/<id>/files/<relative path>(~L287-295). createdFilesis stored in the index, buttoMeta(~L480) leaves it out of whattimeline/listreturns.- Binary files are dropped from snapshots (~L226).
MAX_TIMELINE_ENTRIES = 50,MAX_TIMELINE_SESSIONS = 20, and sessions older than 7 days are pruned (source/constants.ts~L72-74).revertTodeletes the entries it reverts (~L332).
- Before-images are stored as UTF-8 under
source/acp/acp-timeline.ts: for shell commands and other tools whose targets are not known up front, a checkpoint is recorded only when the Git scan before and after the call is complete. A scan that hit its file cap or could not run produces no checkpoint (~L149-166, L195-198).- The existing methods (
renameSession,timeline/list,timeline/revert,retryTurn) use bare names, not the_prefix ACP asks for custom methods, and are not advertised inagentCapabilities. That is a separate topic.
Implementation Notes (optional)
The storage layout and list() already exist, so a TimelineManager.readBefore(checkpointId, relativePath) method would read the file under entries/<id>/files/ after checking that the path is in the entry's filesChanged (or createdFiles), and extMethod would add the new branch.
Open questions for maintainers:
- Method name.
timeline/readfollows the existing bare names._nanocoder/timelineReadfollows ACP's rule for custom methods. Is there a plan to rename the existing methods (nanocoder-desktop#12 item 7)? - Should the response include
created(as proposed) or should it be reported only intimeline/list? - Size limit. Should there be a cap on the returned content, or a truncation flag, for very large files?
- Pruning. Should reads fail clearly after pruning (proposed
unavailable) or should Nanocoder pin entries a client has asked for?
Acceptance criteria:
- [ ] A client can read the before-image of a path for a checkpoint of a loaded session.
- [ ] A created file returns
created, with no content. - [ ] A binary, missing or pruned before-image returns
unavailablewith a reason, never an error or partial content. - [ ] A path outside the checkpoint's
filesChanged, or one that escapes the workspace, is rejected. - [ ] The method never modifies files, the index or session history.
- [ ]
timeline/listreports which files were created. - [ ] The method is advertised under
_metainagentCapabilities. - [ ] Docs describe the method, how to find a turn's baseline, and the limits: binary files, 50 entries per session, pruning after 7 days or beyond 20 sessions, shell-command checkpoints only when the Git scan is complete, and the session must be loaded.
Test plan:
- Unit (
timeline-manager): reading a text before-image, a created file, a binary-skipped path, a pruned entry, and an invalid path. - ACP spec: edit a file twice in one turn and read the earliest checkpoint's before-image.
- ACP spec: reading after
timeline/revertreturnsunavailable. - ACP spec: reading a session that isn't loaded fails the same way
timeline/listdoes. - Regression:
timeline/listandtimeline/revertbehave as before, apart from the added created-file field.
Out of scope: the "Agent changes" UI, diffing, restoring or reverting files, and renaming the existing extension methods.
@addyCooks if no one is on this on can you assign it to me
Thanks for asking @Vishesh-Verma-07, but I'm taking this one. It has a dependency, so it's a priority.
okay no worries.