From 8a7baaaa489596e6e8b74149883d76becfcd1f9a Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 3 Jul 2025 20:45:23 -0700 Subject: [PATCH] plan mode --- gui/src/components/ModeSelect/ModeIcon.tsx | 10 +- gui/src/components/ModeSelect/ModeSelect.tsx | 89 +++++++++++++++-- gui/src/components/gui/Switch.tsx | 8 +- .../tool-policies/ToolPoliciesSection.tsx | 96 +++++++++++++------ .../sections/tool-policies/ToolPolicyItem.tsx | 15 ++- gui/src/redux/slices/sessionSlice.ts | 6 ++ gui/src/redux/store.ts | 1 + gui/src/redux/thunks/streamNormalInput.ts | 10 +- 8 files changed, 187 insertions(+), 48 deletions(-) diff --git a/gui/src/components/ModeSelect/ModeIcon.tsx b/gui/src/components/ModeSelect/ModeIcon.tsx index 83201d5ae..1a34eb988 100644 --- a/gui/src/components/ModeSelect/ModeIcon.tsx +++ b/gui/src/components/ModeSelect/ModeIcon.tsx @@ -1,8 +1,12 @@ -import { ChatBubbleLeftIcon, SparklesIcon } from "@heroicons/react/24/outline"; +import { + ChatBubbleLeftIcon, + SparklesIcon, + SwatchIcon, +} from "@heroicons/react/24/outline"; import { MessageModes } from "core"; interface ModeIconProps { - mode: MessageModes; + mode: MessageModes | "plan"; className?: string; } @@ -13,6 +17,8 @@ export function ModeIcon({ switch (mode) { case "agent": return ; + case "plan": + return ; case "chat": return ; } diff --git a/gui/src/components/ModeSelect/ModeSelect.tsx b/gui/src/components/ModeSelect/ModeSelect.tsx index 9e1b5afef..df29976a9 100644 --- a/gui/src/components/ModeSelect/ModeSelect.tsx +++ b/gui/src/components/ModeSelect/ModeSelect.tsx @@ -1,11 +1,16 @@ -import { CheckIcon, ChevronDownIcon } from "@heroicons/react/24/outline"; +import { + CheckIcon, + ChevronDownIcon, + InformationCircleIcon, +} from "@heroicons/react/24/outline"; import { MessageModes } from "core"; import { modelSupportsTools } from "core/llm/autodetect"; import { useCallback, useEffect, useMemo } from "react"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { selectSelectedChatModel } from "../../redux/slices/configSlice"; -import { setMode } from "../../redux/slices/sessionSlice"; +import { setMode, setReadOnly } from "../../redux/slices/sessionSlice"; import { getFontSize, getMetaKeyLabel } from "../../util"; +import { ToolTip } from "../gui/Tooltip"; import { useMainEditor } from "../mainInput/TipTapEditor"; import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from "../ui"; import { ModeIcon } from "./ModeIcon"; @@ -32,13 +37,25 @@ export function ModeSelect() { } }, [mode, agentModeSupported, dispatch, selectedModel]); + const readOnlyMode = useAppSelector((store) => store.session.readOnlyMode); + const pseudoMode = useMemo(() => { + return mode === "chat" ? "chat" : readOnlyMode ? "plan" : "agent"; + }, [mode, readOnlyMode]); const cycleMode = useCallback(() => { - dispatch(setMode(mode === "chat" ? "agent" : "chat")); + if (pseudoMode === "chat") { + dispatch(setMode("agent")); + dispatch(setReadOnly(true)); + } else if (pseudoMode === "plan") { + dispatch(setReadOnly(false)); + } else { + dispatch(setReadOnly(true)); + dispatch(setMode("chat")); + } // Only focus main editor if another one doesn't already have focus if (!document.activeElement?.classList?.contains("ProseMirror")) { mainEditor?.commands.focus(); } - }, [mode, mainEditor]); + }, [pseudoMode, mainEditor]); const selectMode = useCallback( (newMode: MessageModes) => { @@ -72,9 +89,13 @@ export function ModeSelect() { data-testid="mode-select-button" className="xs:px-2 text-description bg-lightgray/20 gap-1 rounded-full border-none px-1.5 py-0.5 transition-colors duration-200 hover:brightness-110" > - + - {mode.charAt(0).toUpperCase() + mode.slice(1)} + {pseudoMode === "chat" + ? "Chat" + : pseudoMode === "agent" + ? "Agent" + : "Plan"} - {mode === "chat" && } + {pseudoMode === "chat" && } - { + dispatch(setReadOnly(true)); + }} + > +
+ + Agent (Plan) + + + In Plan mode, the Agent can only use read-only tools + +
+ {agentModeSupported ? ( + + ) : ( + (Not supported) + )} +
+ { + dispatch(setReadOnly(false)); + }} >
- Agent + Agent (Act) + + + In Act mode, the Agent can use create/edit tools +
{agentModeSupported ? ( - mode === "agent" && + ) : ( (Not supported) )} diff --git a/gui/src/components/gui/Switch.tsx b/gui/src/components/gui/Switch.tsx index 7004ae9d8..2422c6cd5 100644 --- a/gui/src/components/gui/Switch.tsx +++ b/gui/src/components/gui/Switch.tsx @@ -7,6 +7,7 @@ type ToggleSwitchProps = { text: string; size?: number; showIfToggled?: ReactNode; + disabled?: boolean; }; const ToggleSwitch: React.FC = ({ @@ -15,15 +16,18 @@ const ToggleSwitch: React.FC = ({ text, size = 16, showIfToggled, + disabled = false, }) => { return ( -
+
{text}
{isToggled && !!showIfToggled && showIfToggled}
void; + isSelected: boolean; +} +const ModeBadge = ({ text, onClick, isSelected, icon }: ModeBadgeProps) => { + return ( +
+ {icon} + {text} +
+ ); +}; + export const ToolPoliciesSection = () => { + const mode = useAppSelector((state) => state.session.mode); + const readOnlyMode = useAppSelector((state) => state.session.readOnlyMode); const availableTools = useAppSelector((state) => state.config.config.tools); const toolGroupSettings = useAppSelector( (store) => store.ui.toolGroupSettings, @@ -39,38 +60,57 @@ export const ToolPoliciesSection = () => { ); }, [availableTools]); + const allToolsOff = mode === "chat"; + + const pseudoMode = mode === "chat" ? "chat" : readOnlyMode ? "plan" : "act"; + const message = + pseudoMode === "chat" + ? "All tools are disabled in Chat mode" + : pseudoMode === "plan" + ? "Plan mode: only MCP and read-only tools" + : "Act mode: all tool policies apply"; + return ( <> - {toolsByGroup.map(([groupName, tools]) => ( -
-
-

- {groupName} -

- dispatch(toggleToolGroupSetting(groupName))} - text="" - size={10} - /> -
-
- {tools.map((tool) => ( - + + {message} +
+ {toolsByGroup.map(([groupName, tools]) => { + const isGroupEnabled = + !allToolsOff && toolGroupSettings[groupName] !== "exclude"; + return ( +
+
+

+ {groupName} +

+ dispatch(toggleToolGroupSetting(groupName))} + text="" + size={10} + disabled={allToolsOff} /> - ))} +
+
+ {tools.map((tool) => ( + + ))} +
-
- ))} + ); + })} ); }; diff --git a/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPolicyItem.tsx b/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPolicyItem.tsx index b92816839..38f9416fe 100644 --- a/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPolicyItem.tsx +++ b/gui/src/components/mainInput/Lump/sections/tool-policies/ToolPolicyItem.tsx @@ -3,6 +3,7 @@ import { InformationCircleIcon, } from "@heroicons/react/24/outline"; import { Tool } from "core"; +import { BUILT_IN_GROUP_NAME } from "core/tools/builtIn"; import { useEffect, useMemo, useState } from "react"; import { useDispatch } from "react-redux"; import { useAppSelector } from "../../../../../redux/hooks"; @@ -16,7 +17,7 @@ import { useFontSize } from "../../../../ui/font"; interface ToolDropdownItemProps { tool: Tool; duplicatesDetected: boolean; - excluded: boolean; + isGroupEnabled: boolean; } function ToolPolicyItem(props: ToolDropdownItemProps) { @@ -25,6 +26,7 @@ function ToolPolicyItem(props: ToolDropdownItemProps) { (state) => state.ui.toolSettings[props.tool.function.name], ); const [isExpanded, setIsExpanded] = useState(false); + const readOnlyMode = useAppSelector((state) => state.session.readOnlyMode); useEffect(() => { if (!policy) { @@ -44,6 +46,12 @@ function ToolPolicyItem(props: ToolDropdownItemProps) { const fontSize = useFontSize(-2); + const disabled = + !props.isGroupEnabled || + (readOnlyMode && + props.tool.group === BUILT_IN_GROUP_NAME && + !props.tool.readonly); + if (!policy) { return null; } @@ -106,8 +114,9 @@ function ToolPolicyItem(props: ToolDropdownItemProps) {
+
{ dispatch(toggleToolSetting(props.tool.function.name)); @@ -115,7 +124,7 @@ function ToolPolicyItem(props: ToolDropdownItemProps) { e.preventDefault(); }} > - {props.excluded || policy === "disabled" ? ( + {disabled || policy === "disabled" ? ( <> Off diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 6cd96dd8e..c48a9840d 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -54,6 +54,7 @@ type SessionState = { mainEditorContentTrigger?: JSONContent | undefined; symbols: FileSymbolMap; mode: MessageModes; + readOnlyMode: boolean; isInEdit: boolean; codeBlockApplyStates: { states: ApplyState[]; @@ -73,6 +74,7 @@ const initialState: SessionState = { streamAborter: new AbortController(), symbols: {}, mode: "chat", + readOnlyMode: false, isInEdit: false, codeBlockApplyStates: { states: [], @@ -668,6 +670,9 @@ export const sessionSlice = createSlice({ setMode: (state, action: PayloadAction) => { state.mode = action.payload; }, + setReadOnly: (state, action: PayloadAction) => { + state.readOnlyMode = action.payload; + }, setIsInEdit: (state, action: PayloadAction) => { state.isInEdit = action.payload; }, @@ -768,6 +773,7 @@ export const { setToolGenerated, updateToolCallOutput, setMode, + setReadOnly, setIsSessionMetadataLoading, setAllSessionMetadata, addSessionMetadata, diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index 10ecdd2e5..40bd76160 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -42,6 +42,7 @@ const saveSubsetFilters = [ // Persist edit mode in case closes in middle "mode", + "readOnlyMode", // higher risk to persist // codeBlockApplyStates diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index c7c4de02d..2d25f9e29 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -40,12 +40,16 @@ export const streamNormalInput = createAsyncThunk< // Get tools const activeTools = selectActiveTools(state); const toolsSupported = modelSupportsTools(selectedChatModel); + const readOnlyMode = state.session.readOnlyMode; + const filteredTools = readOnlyMode + ? activeTools.filter((t) => t.readonly) + : activeTools; // Construct completion options let completionOptions: LLMFullCompletionOptions = {}; - if (toolsSupported && activeTools.length > 0) { + if (toolsSupported && filteredTools.length > 0) { completionOptions = { - tools: activeTools, + tools: filteredTools, }; } @@ -125,7 +129,7 @@ export const streamNormalInput = createAsyncThunk< modelTitle: selectedChatModel.title, sessionId: state.session.id, ...(state.session.mode === "agent" && { - tools: activeTools.map((tool) => tool.function.name), + tools: filteredTools.map((tool) => tool.function.name), }), }, });