feat: auto-accept agent edits setting auto accept edit tools (#7993)
* feat: auto accept edit tools * add `isAutoEditToolCall` check * show tooltip in tool section * revert accidental change * refactor * fix: tweaks on auto accept agent edit --------- Co-authored-by: Dallin Romney <dallinromney@gmail.com>
This commit is contained in:
parent
8367d33316
commit
22c6799934
5 changed files with 58 additions and 16 deletions
|
|
@ -19,6 +19,7 @@ import {
|
|||
import { useFontSize } from "../../../components/ui/font";
|
||||
import { useAppSelector } from "../../../redux/hooks";
|
||||
import { addTool, setToolPolicy } from "../../../redux/slices/uiSlice";
|
||||
import { isEditTool } from "../../../util/toolCallState";
|
||||
|
||||
interface ToolPolicyItemProps {
|
||||
tool: Tool;
|
||||
|
|
@ -28,12 +29,22 @@ interface ToolPolicyItemProps {
|
|||
|
||||
export function ToolPolicyItem(props: ToolPolicyItemProps) {
|
||||
const dispatch = useDispatch();
|
||||
const policy = useAppSelector(
|
||||
const toolPolicy = useAppSelector(
|
||||
(state) => state.ui.toolSettings[props.tool.function.name],
|
||||
);
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
const mode = useAppSelector((state) => state.session.mode);
|
||||
|
||||
const autoAcceptEditToolDiffs = useAppSelector(
|
||||
(state) => state.config.config.ui?.autoAcceptEditToolDiffs,
|
||||
);
|
||||
const isAutoAcceptedToolCall =
|
||||
isEditTool(props.tool.function.name) && autoAcceptEditToolDiffs;
|
||||
|
||||
const policy = isAutoAcceptedToolCall
|
||||
? "allowedWithoutPermission"
|
||||
: toolPolicy;
|
||||
|
||||
useEffect(() => {
|
||||
if (!policy) {
|
||||
dispatch(addTool(props.tool));
|
||||
|
|
@ -53,6 +64,7 @@ export function ToolPolicyItem(props: ToolPolicyItemProps) {
|
|||
const fontSize = useFontSize(-2);
|
||||
|
||||
const disabled =
|
||||
isAutoAcceptedToolCall ||
|
||||
!props.isGroupEnabled ||
|
||||
(mode === "plan" &&
|
||||
props.tool.group === BUILT_IN_GROUP_NAME &&
|
||||
|
|
@ -100,6 +112,19 @@ export function ToolPolicyItem(props: ToolPolicyItemProps) {
|
|||
<InformationCircleIcon className="h-3 w-3 flex-shrink-0 cursor-help text-yellow-500" />
|
||||
</ToolTip>
|
||||
) : null}
|
||||
{isAutoAcceptedToolCall ? (
|
||||
<ToolTip
|
||||
place="bottom"
|
||||
className="flex flex-wrap items-center"
|
||||
content={
|
||||
<p className="m-0 p-0">
|
||||
Auto-Accept Agent Edits setting is on
|
||||
</p>
|
||||
}
|
||||
>
|
||||
<InformationCircleIcon className="h-3 w-3 flex-shrink-0 cursor-help text-yellow-500" />
|
||||
</ToolTip>
|
||||
) : null}
|
||||
{props.tool.faviconUrl && (
|
||||
<img
|
||||
src={props.tool.faviconUrl}
|
||||
|
|
@ -139,11 +164,13 @@ export function ToolPolicyItem(props: ToolPolicyItemProps) {
|
|||
data-tooltip-id={disabled ? disabledTooltipId : undefined}
|
||||
>
|
||||
<span className="text-xs">
|
||||
{disabled || policy === "disabled"
|
||||
? "Excluded"
|
||||
: policy === "allowedWithoutPermission"
|
||||
? "Automatic"
|
||||
: "Ask First"}
|
||||
{isAutoAcceptedToolCall
|
||||
? "Automatic"
|
||||
: disabled || policy === "disabled"
|
||||
? "Excluded"
|
||||
: policy === "allowedWithoutPermission"
|
||||
? "Automatic"
|
||||
: "Ask First"}
|
||||
</span>
|
||||
<ChevronDownIcon className="h-3 w-3" />
|
||||
</ListboxButton>
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import {
|
|||
ToolCallState,
|
||||
} from "core";
|
||||
import type { RemoteSessionMetadata } from "core/control-plane/client";
|
||||
import { BuiltInToolNames } from "core/tools/builtIn";
|
||||
import { NEW_SESSION_TITLE } from "core/util/constants";
|
||||
import {
|
||||
renderChatMessage,
|
||||
|
|
@ -36,7 +35,7 @@ import { findLastIndex } from "lodash";
|
|||
import { v4 as uuidv4 } from "uuid";
|
||||
import { type InlineErrorMessageType } from "../../components/mainInput/InlineErrorMessage";
|
||||
import { toolCallCtxItemToCtxItemWithId } from "../../pages/gui/ToolCallDiv/utils";
|
||||
import { addToolCallDeltaToState } from "../../util/toolCallState";
|
||||
import { addToolCallDeltaToState, isEditTool } from "../../util/toolCallState";
|
||||
import { RootState } from "../store";
|
||||
import { streamResponseThunk } from "../thunks/streamResponse";
|
||||
import { findChatHistoryItemByToolCallId, findToolCallById } from "../util";
|
||||
|
|
@ -51,17 +50,10 @@ import { findChatHistoryItemByToolCallId, findToolCallById } from "../util";
|
|||
function filterMultipleEditToolCalls(
|
||||
toolCalls: ToolCallDelta[],
|
||||
): ToolCallDelta[] {
|
||||
const editToolNames = [
|
||||
BuiltInToolNames.EditExistingFile,
|
||||
BuiltInToolNames.SingleFindAndReplace,
|
||||
BuiltInToolNames.MultiEdit,
|
||||
];
|
||||
let hasSeenEditTool = false;
|
||||
|
||||
return toolCalls.filter((toolCall) => {
|
||||
const isEditTool = editToolNames.includes(toolCall.function?.name as any);
|
||||
|
||||
if (isEditTool) {
|
||||
if (toolCall.function?.name && isEditTool(toolCall.function?.name)) {
|
||||
if (hasSeenEditTool) {
|
||||
return false; // Skip this duplicate edit tool
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { ToolPolicy } from "@continuedev/terminal-security";
|
||||
import { Tool, ToolCallState } from "core";
|
||||
import { IIdeMessenger } from "../../context/IdeMessenger";
|
||||
import { isEditTool } from "../../util/toolCallState";
|
||||
import { errorToolCall, updateToolCallOutput } from "../slices/sessionSlice";
|
||||
import { DEFAULT_TOOL_SETTING, ToolPolicies } from "../slices/uiSlice";
|
||||
import { AppThunkDispatch } from "../store";
|
||||
|
|
@ -20,7 +21,16 @@ async function evaluateToolPolicy(
|
|||
activeTools: Tool[],
|
||||
toolCallState: ToolCallState,
|
||||
toolPolicies: ToolPolicies,
|
||||
autoAcceptEditToolDiffs: boolean | undefined,
|
||||
): Promise<EvaluatedPolicy> {
|
||||
// allow edit tool calls without permission if auto-accept is enabled
|
||||
if (
|
||||
isEditTool(toolCallState.toolCall.function.name) &&
|
||||
autoAcceptEditToolDiffs
|
||||
) {
|
||||
return { policy: "allowedWithoutPermission", toolCallState };
|
||||
}
|
||||
|
||||
const basePolicy =
|
||||
toolPolicies[toolCallState.toolCall.function.name] ??
|
||||
activeTools.find(
|
||||
|
|
@ -73,6 +83,7 @@ export async function evaluateToolPolicies(
|
|||
activeTools: Tool[],
|
||||
generatedToolCalls: ToolCallState[],
|
||||
toolPolicies: ToolPolicies,
|
||||
autoAcceptEditToolDiffs: boolean | undefined,
|
||||
): Promise<EvaluatedPolicy[]> {
|
||||
// Check if ALL tool calls are auto-approved using dynamic evaluation
|
||||
const policyResults = await Promise.all(
|
||||
|
|
@ -82,6 +93,7 @@ export async function evaluateToolPolicies(
|
|||
activeTools,
|
||||
toolCallState,
|
||||
toolPolicies,
|
||||
autoAcceptEditToolDiffs,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -268,6 +268,7 @@ export const streamNormalInput = createAsyncThunk<
|
|||
activeTools,
|
||||
generatedCalls3,
|
||||
toolPolicies,
|
||||
state3.config.config.ui?.autoAcceptEditToolDiffs,
|
||||
);
|
||||
const anyRequireApproval = policies.find(
|
||||
({ policy }) => policy === "allowedWithPermission",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { ToolCallDelta, ToolCallState } from "core";
|
||||
import { BuiltInToolNames } from "core/tools/builtIn";
|
||||
import { incrementalParseJson } from "core/util/incrementalParseJson";
|
||||
|
||||
// Merge streamed tool calls
|
||||
|
|
@ -67,3 +68,12 @@ export function addToolCallDeltaToState(
|
|||
parsedArgs,
|
||||
};
|
||||
}
|
||||
|
||||
const editToolNames: string[] = [
|
||||
BuiltInToolNames.EditExistingFile,
|
||||
BuiltInToolNames.SingleFindAndReplace,
|
||||
BuiltInToolNames.MultiEdit,
|
||||
];
|
||||
export function isEditTool(toolName: string) {
|
||||
return editToolNames.includes(toolName);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue