DiffWriter
Human-in-the-loop file writing with diff display and approval.
Installation
Want to customize? Run co copy diff_writer to get an editable copy.
API
write(agent, path, content)
Write content to a file with diff display and user approval. agent is injected automatically when this is used as an agent tool — the LLM never sees that parameter.
diff(path, content)
Show diff without writing (preview mode).
read(path)
Read file contents.
Approval Options
When a file change is proposed in mode="normal", DiffWriter sends a diff preview and an approval question over agent.io (a WebSocket channel) — there's no built-in terminal prompt. The frontend renders whatever UI it wants around these three options:
| Option | Effect |
|---|---|
| "Yes, apply this change" | Apply this change, ask again for next change |
| "Yes to all (auto-approve)" | Apply this and switch to auto mode for the rest of the session |
| "No, reject and give feedback" | Reject + provide feedback for agent to try again |
If no io channel is attached (e.g. running outside a hosted/web session), the write is auto-approved without prompting.
Modes
mode
Three permission modes, like Claude Code's Shift+Tab cycle.
Use with Agent
Feedback Flow
When the user rejects a change:
- User is asked: "What should the agent do instead for hello.py?"
- User types feedback, e.g., "use snake_case for function names"
- Agent receives:
"User rejected changes to hello.py. Feedback: use snake_case for function names" - Agent can retry with the feedback
Common Use Cases
Customizing
Need to modify DiffWriter's behavior? Copy the source to your project:
Then import from your local copy:
ConnectOnion