Feature: Real-time mode change awareness for the agent
Problem
When I switch modes mid-session (e.g., Agent → YOLO via Alt+a/y/p), the agent does not immediately know the mode has changed. This leads to a frustrating experience:
- Agent in Agent mode encounters a shell/git/compile operation → says "I can't do shell, you need to manually run:
git stash && cargo check" - I press Alt+y to switch to YOLO mode
- In the next turn, the agent still acts as if shell is blocked, because its conversation history already contains the "I can't do shell" resignation message
Root Cause Analysis
Two gaps in the current design:
Gap 1 — No mode-change signal injected into conversation
set_mode() in app.rs:2180 updates app.mode and the status bar, but does not inject a system message into the conversation. The agent only learns about the mode change when the system prompt refreshes on the next turn — and even then, it sees its own previous "you need to do it manually" message in history and doesn't re-evaluate.
Gap 2 — No runtime mode query tool
The agent has no tool to ask "what mode am I in?" Mode information exists only as static text in the system prompt, which is injected at turn-start. There's no way for the agent to proactively discover a mode change.
Proposed Solutions
I want to implement one (or a combination) of these:
Option A: Inject mode-change system message
When set_mode() is called, push a system message into the conversation:
System: Mode switched to YOLO — all operations now auto-approved. Re-evaluate any previously blocked actions.
Option B: Add a get_mode tool
Let the agent call a tool to query its current mode at runtime. This makes the agent mode-aware without needing a full turn.
Option C: Auto-retry on mode escalation
When mode switches from Agent→YOLO, automatically re-process any pending/blocked tool approvals.
Key Files (preliminary)
crates/tui/src/tui/app.rs—set_mode()needs to emit a mode-change eventcrates/tui/src/core/engine.rs— handleModeChangeop, inject system messagecrates/tui/src/core/ops.rs— newOp::ModeChangevariant (if needed)crates/tui/src/tui/ui.rs— dispatch mode change into engine conversationcrates/tui/src/core/engine/tests.rs— tests
Who
I (@encyc) would like to implement this. /cc @Hmbown for guidance and approval.
Implemented in #2577 — injects a <codewhale:runtime_event kind="mode_change"> message into the conversation when the user switches modes, plus adds mode to every turn <turn_meta> block so mid-turn messages report the correct mode.
Also fixes the user_text_message_with_turn_metadata hardcoded AppMode::Agent bug that would have caused mid-turn steer/REPL/LSP messages to report the wrong mode in YOLO/Plan sessions.
cc @cyq1017 — this is a superset of #2539.