Status: design locked, implementation in progress.
A toggle in the AI panel that switches the chat from suggest-and-apply mode (current) to agent mode. In agent mode, the AI's response is treated as the new content for the file/selection, and the user sees a Monaco diff editor modal with Apply / Reject buttons before any change lands.
Multi-turn: each follow-up message rebuilds the system prompt from the current editor content, so iterative refinement works ("actually only do public functions" → AI starts from the current file state, not the original).
| Question | Answer |
|---|---|
| Tier | B — Diff preview (Monaco diff editor modal) |
| Multi-turn | Yes. Each turn rebuilds the system prompt from current editor content |
| Scope | Selection if present, else whole file (same as current chat) |
| Dangerous edits | No special confirmation. Diff preview already provides review; Ctrl+Z handles rollback if applied in error |
| What shows in chat thread | A summary line ("📝 Proposed change — review diff"), not the raw file content (which is huge) |
| Default mode on panel open | Chat mode (current behaviour). User must explicitly toggle to Agent |
| Toggle persistence | Per-session only — does not persist across app restarts (safer default) |
Agent mode ON:
user types prompt
→ build NEW system prompt with current file content
→ REPLACE aiMessages[0] (system) with the new one
→ append user message
→ call /api/chat as before (keeps multi-turn history)
→ on token: stream into a hidden buffer, NOT the chat thread
→ on done:
- chat thread shows only: "📝 Proposed change · review diff →"
- open diff modal: original (left) vs AI output (right)
- Apply → editor.executeEdits(...) replaces selection or full file
- Reject → close modal, no editor change
- Small badge button next to "+ New chat":
🤖 Chat↔⚡ Agent - Visually distinct when in agent mode (orange/red accent)
- Tooltip: "Toggle Agent mode — AI's reply replaces editor content via diff preview"
┌─ Review AI change ────────────────────────────── × ┐
│ [Apply ✓] [Reject ✕] │
├────────────────────────────────────────────────────┤
│ Original │ AI proposal │
│ ─────────────────────────────────────────────────│
│ function foo(x) { │ /** Adds 1 to x */ │
│ return x + 1; │ function foo(x) { │
│ } │ return x + 1; │
│ │ } │
│ ─────────────────────────────────────────────────│
│ ↑ red = removed ↓ green = added │
└────────────────────────────────────────────────────┘
- Monaco's built-in
monaco.editor.createDiffEditordoes the heavy lifting (gutter markers, hunk navigation, syntax highlighting carries over from the file's language) - Modal closes on Apply, Reject, Esc, or × button
- Reject preserves the chat history → user can ask "actually only public functions" and try again
Instead of dumping the (huge) file content as the assistant's message, we show:
🤖 Assistant
📝 Proposed change — 24 lines added, 3 removed. [Review diff →]
The "Review diff →" link reopens the diff modal even after closing it.
You are an expert coding assistant in agent mode.
Output ONLY the complete updated content of the file/selection. No explanations,
no markdown fences, no preamble. Your response IS the new content — it will
directly replace what's currently there.
Preserve everything you weren't asked to change. Match indentation, style,
language conventions exactly.
Current scope: <selection or whole file>
Current content (this is what you must output an updated version of):
\`\`\`
<content>
\`\`\`
- HTML/CSS — agent toggle button + diff modal shell
- Toggle state —
aiAgentModeboolean +toggleAiAgentMode()+ visual state - Capture mode — when
aiAgentModeis on, route streaming tokens to a hidden buffer instead of the chat thread; replace assistant chat message with the summary line - System-prompt rebuild — on each turn in agent mode, rebuild
aiMessages[0]from the current editor content - Diff modal — Monaco diff editor inside the modal, Apply/Reject wiring, Esc dismiss, "Review diff →" link to reopen
- Apply —
editor.executeEditson selection or whole-file range; close modal; set tab dirty - Reject — just close modal; chat history retained for follow-up
- Hunk-by-hunk Apply / Reject (just whole-diff for now)
- Multi-file edits (one file per turn — future)
- Tool use / terminal access (future "Composer" tier)
- Auto-commit after Apply (defer to manual save)