diff --git a/frontend/chat.py b/frontend/chat.py index e55e911..872b7d9 100644 --- a/frontend/chat.py +++ b/frontend/chat.py @@ -85,6 +85,12 @@ def _reject_action(feedback: str): st.session_state.agent_pending_action = next_action st.session_state.agent_status = "waiting_approval" +def _handle_reject(): + feedback = st.session_state.agent_reject_feedback + with st.spinner("Agent is replanning..."): + _reject_action(feedback) + st.session_state.agent_reject_feedback = "" + def _followup_agent(question: str): """Continue a finished task by injecting a follow-up question and resuming the loop.""" @@ -225,7 +231,10 @@ def render_agent_mode(): if args: _render_arguments(args) - feedback = st.text_input( + if "agent_reject_feedback" not in st.session_state: + st.session_state.agent_reject_feedback = "" + + st.text_input( "Rejection feedback (optional):", key="agent_reject_feedback", placeholder="e.g. Use a different approach...", @@ -238,10 +247,11 @@ def render_agent_mode(): _approve_action() st.rerun() with col2: - if st.button("Reject", use_container_width=True): - with st.spinner("Agent is replanning..."): - _reject_action(feedback) - st.rerun() + st.button( + "Reject", + use_container_width=True, + on_click=_handle_reject, + ) with col3: if st.button("Abort Task", use_container_width=True): _reset_agent() @@ -583,6 +593,44 @@ def render_normal_chat(): st.session_state.chat_history.append({"role": "assistant", "content": ai_response}) st.rerun() + # 5d — Clear Chat opens a confirmation dialog instead of deleting immediately. + if st.button("🗑️ Clear Chat"): + _clear_chat_dialog() + + # Toggle to switch to Agent Mode (render_normal_chat and render_agent_mode are + # mutually exclusive, so the same key here causes no DuplicateWidgetID conflict). + st.toggle("Agent Mode", key="agent_mode") + + # 5h — Settings expander: file context toggle, model, token limit, custom prompt. + with st.expander("⚙️ Settings", expanded=False): + current_file = st.session_state.get("active_file") + if current_file: + st.toggle(f"Include current file as context: **{Path(current_file).name}**", key="include_file_context", value=True) + + + st.divider() + + default_model = chat_manager.model or "" + model_options = [default_model] if default_model else [] + + st.selectbox("Model", model_options, key="selected_model") + + st.slider( + "Max Response Tokens", + min_value=256, max_value=8000, + value=chat_manager.max_tokens, + step=256, key="chat_max_tokens", + ) + + st.divider() + + st.text_area( + "Custom System Prompt (overrides default if set)", + key="custom_system_prompt", + height=120, + placeholder="Leave empty to use the default assistant prompt with optional file context.", + ) + # ── Entry point ───────────────────────────────────────────────────────────────