6.6 KiB
Always Show Comment Buttons Regardless of AI State — Technical Spec
Problem
The code review panel gates all comment and add-as-context button visibility on AISettings::is_any_ai_enabled(). This hides the buttons entirely when AI is disabled, even though CLI agent terminals (Claude Code, Gemini) can accept review comments without Warp AI. The implementation needs to decouple button visibility from AI state, restrict non-CLI terminal availability when AI is off, and surface the correct reason when the send button is disabled.
Relevant Code
app/src/code_review/code_review_header.rs (127-231)— header dropdown buttons gated byis_ai_enabledapp/src/code_review/code_review_view.rs:5175— per-file "add as context" button gated byis_ai_enabledapp/src/code/editor/element.rs (418, 516, 959, 1170, 1176, 1315, 1517)—EditorWrapperfield, constructor param, and 5 usage sitesapp/src/code/editor/view.rs (628, 2216)— bothEditorWrapper::newcall sites passis_ai_enabledapp/src/code/editor/view/actions.rs (1070, 1082)—NewCommentOnLineandRequestOpenSavedCommentgated by AI checkapp/src/workspace/right_panel.rs (341, 1067, 1154, 1184, 1218)—RightPanelView::new,route_review_comments,is_terminal_available_for_review,find_available_terminal_for_review,recompute_terminal_availabilityapp/src/code_review/comment_list_view.rs (864, 888)—send_button_tooltip_text,render_send_button
Current State
is_ai_enabledis checked byAISettings::as_ref(ctx).is_any_ai_enabled(ctx), which evaluates global toggle + login state + remote session org policy.AISettingsChangedEvent::IsAnyAIEnabledis auto-generated by thedefine_settings_group!macro and fires when AI state changes.ReviewDestinationenum inright_panel.rs:None,Warp,Cli(CLIAgent).recompute_terminal_availabilitycurrently computesReviewDestinationpurely from terminal state — returnsWarpfor any idle, non-executing terminal regardless of AI setting.RightPanelViewdoes not currently subscribe toAISettingsChangedEvent.
Proposed Changes
1. Remove AI gate from header and per-file buttons
Files: code_review_header.rs, code_review_view.rs
Remove is_ai_enabled from the visibility conditions in render_wide_layout (line 138), render_compact_layout (line 220), and render_file_header (line 5175). The conditions become purely feature-flag-based:
- Header:
FeatureFlag::DiffSetAsContext.is_enabled() && !has_no_changes - Per-file:
FeatureFlag::DiffSetAsContext.is_enabled()
2. Remove is_ai_enabled from EditorWrapper
Files: code/editor/element.rs, code/editor/view.rs, code/editor/view/actions.rs
- Delete
is_ai_enabled: boolfield (line 418) and constructor parameter (line 516). - Simplify the 5 internal usages to check only the feature flag:
- Line 959:
if FeatureFlag::InlineCodeReview.is_enabled() - Line 1170:
self.add_hunk_as_context_button.is_some() - Line 1176:
FeatureFlag::InlineCodeReview.is_enabled() && ... - Lines 1315, 1517:
FeatureFlag::InlineCodeReview.is_enabled()
- Line 959:
- Remove the
is_ai_enabledargument from bothEditorWrapper::newcall sites inview.rs(lines 628, 2216). - Remove the
AISettings::as_ref(ctx).is_any_ai_enabled(ctx)guard fromNewCommentOnLine(line 1070) andRequestOpenSavedComment(line 1082) inactions.rs.
3. Filter non-CLI terminals when AI is disabled
File: right_panel.rs
- Add
ai_enabled: boolparameter tois_terminal_available_for_review(line 1154). Whenfalse, reject terminals that don't have an active CLI agent. - Thread
ai_enabledthroughfind_available_terminal_for_review(line 1184). - In
recompute_terminal_availability(line 1218), readAISettings::as_ref(ctx).is_any_ai_enabled(ctx)and pass it down. - In
route_review_comments(line 1067), also readis_any_ai_enabledand pass it through so routing respects AI state at submission time.
4. Subscribe to AI settings changes
File: right_panel.rs — new() (around line 341)
Subscribe to the AISettings model, matching on AISettingsChangedEvent::IsAnyAIEnabled, and call recompute_terminal_availability(ctx). This ensures the send button's enabled state and tooltip update immediately when the user toggles AI.
Import needed: use crate::settings::ai::{AISettings, AISettingsChangedEvent}.
5. Differentiate disabled button tooltip
File: comment_list_view.rs
- Add
ai_enabled: boolparameter tosend_button_tooltip_text(line 864). New priority:- CLI agent destination → existing CLI tooltip
!ai_enabled→ "AI must be enabled to send comments to Agent"!ai_available→ "Agent code review requires AI credits" (existing)ReviewDestination::None→ "All terminals are busy" (clarified)!has_sendable_comments→ existing- Default → existing
- In
render_send_button(line 888), readAISettings::as_ref(ctx).is_any_ai_enabled(ctx)and pass it to the tooltip function.
End-to-End Flow
- User opens code review panel with AI disabled.
- Comment and add-as-context buttons are visible (changes 1+2).
- User creates an inline comment via gutter button.
recompute_terminal_availabilityruns, sees AI is off, filters to CLI-only terminals (change 3).- If a CLI agent terminal exists →
ReviewDestination::Cli(agent)→ send button enabled. - If no CLI agents →
ReviewDestination::None→ send button disabled, tooltip says "AI must be enabled to send comments to Agent" (change 5). - User toggles AI on → subscription fires (change 4) → recompute includes non-CLI terminals → button updates.
Risks and Mitigations
- Deadlock risk: Changes 3–4 read
AISettingsinright_panel.rs. The AI settings model is separate from the terminal model, so no lock contention with existingTerminalModellocks. - Regression risk: Removing
is_ai_enabledfromEditorWrappertouches many lines. Mitigated by the field being entirely removed (compiler will catch any missed references).
Testing and Validation
- Build verification:
cargo check,cargo fmt,cargo clippy. - Manual testing: toggle AI on/off with and without CLI agents; verify button visibility and tooltip in each combination.
- WASM build per repo convention.
Parallelization
Changes 1+2 (button visibility) are independent from changes 3+4+5 (terminal availability and tooltip). These can be implemented concurrently:
- Agent A: Changes 1+2 —
code_review_header.rs,code_review_view.rs,code/editor/element.rs,code/editor/view.rs,code/editor/view/actions.rs - Agent B: Changes 3+4+5 —
right_panel.rs,comment_list_view.rs
Follow-Ups
None currently.