Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/core/auto-approval/__tests__/checkAutoApproval.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { checkAutoApproval } from "../index"
import { ExtensionState } from "../../../shared/ExtensionMessage"

describe("checkAutoApproval", () => {
const mockAsk = "tool"

it("should approve deleteFile when alwaysAllowDelete is true", async () => {
const state = {
alwaysAllowDelete: true,
autoApprovalEnabled: true,
} as ExtensionState

const text = JSON.stringify({
tool: "deleteFile",
path: "/path/to/file",
})

const result = await checkAutoApproval({ state, ask: mockAsk, text })
expect(result).toEqual({ decision: "approve" })
})

it("should ask for deleteFile when alwaysAllowDelete is false", async () => {
const state = {
alwaysAllowDelete: false,
autoApprovalEnabled: true,
} as ExtensionState

const text = JSON.stringify({
tool: "deleteFile",
path: "/path/to/file",
})

const result = await checkAutoApproval({ state, ask: mockAsk, text })
expect(result).toEqual({ decision: "ask" })
})

it("should ask for deleteFile when alwaysAllowDelete is undefined", async () => {
const state = {
autoApprovalEnabled: true,
} as ExtensionState

const text = JSON.stringify({
tool: "deleteFile",
path: "/path/to/file",
})

const result = await checkAutoApproval({ state, ask: mockAsk, text })
expect(result).toEqual({ decision: "ask" })
})

it("should ask when autoApprovalEnabled is false even if alwaysAllowDelete is true", async () => {
const state = {
alwaysAllowDelete: true,
autoApprovalEnabled: false,
} as ExtensionState

const text = JSON.stringify({
tool: "deleteFile",
path: "/path/to/file",
})

const result = await checkAutoApproval({ state, ask: mockAsk, text })
expect(result).toEqual({ decision: "ask" })
})
})
3 changes: 3 additions & 0 deletions webview-ui/src/components/settings/AutoApproveSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type AutoApproveSettingsProps = HTMLAttributes<HTMLDivElement> & {
alwaysAllowWrite?: boolean
alwaysAllowWriteOutsideWorkspace?: boolean
alwaysAllowWriteProtected?: boolean
alwaysAllowDelete?: boolean
alwaysAllowBrowser?: boolean
alwaysApproveResubmit?: boolean
requestDelaySeconds: number
Expand Down Expand Up @@ -73,6 +74,7 @@ export const AutoApproveSettings = ({
alwaysAllowWrite,
alwaysAllowWriteOutsideWorkspace,
alwaysAllowWriteProtected,
alwaysAllowDelete,
alwaysAllowBrowser,
alwaysApproveResubmit,
requestDelaySeconds,
Expand Down Expand Up @@ -200,6 +202,7 @@ export const AutoApproveSettings = ({
<AutoApproveToggle
alwaysAllowReadOnly={alwaysAllowReadOnly}
alwaysAllowWrite={alwaysAllowWrite}
alwaysAllowDelete={alwaysAllowDelete}
alwaysAllowBrowser={alwaysAllowBrowser}
alwaysApproveResubmit={alwaysApproveResubmit}
alwaysAllowMcp={alwaysAllowMcp}
Expand Down
3 changes: 3 additions & 0 deletions webview-ui/src/components/settings/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>((props, ref)
alwaysAllowWrite,
alwaysAllowWriteOutsideWorkspace,
alwaysAllowWriteProtected,
alwaysAllowDelete, // kilocode_change
alwaysApproveResubmit,
autoCondenseContext,
autoCondenseContextPercent,
Expand Down Expand Up @@ -519,6 +520,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>((props, ref)
alwaysAllowWrite: alwaysAllowWrite ?? undefined,
alwaysAllowWriteOutsideWorkspace: alwaysAllowWriteOutsideWorkspace ?? undefined,
alwaysAllowWriteProtected: alwaysAllowWriteProtected ?? undefined,
alwaysAllowDelete: alwaysAllowDelete ?? undefined, // kilocode_change
alwaysAllowExecute: alwaysAllowExecute ?? undefined,
alwaysAllowBrowser: alwaysAllowBrowser ?? undefined,
alwaysAllowMcp,
Expand Down Expand Up @@ -1027,6 +1029,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>((props, ref)
alwaysAllowWrite={alwaysAllowWrite}
alwaysAllowWriteOutsideWorkspace={alwaysAllowWriteOutsideWorkspace}
alwaysAllowWriteProtected={alwaysAllowWriteProtected}
alwaysAllowDelete={alwaysAllowDelete} // kilocode_change
alwaysAllowBrowser={alwaysAllowBrowser}
alwaysApproveResubmit={alwaysApproveResubmit}
requestDelaySeconds={requestDelaySeconds}
Expand Down
1 change: 1 addition & 0 deletions webview-ui/src/context/ExtensionStateContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
alwaysApproveResubmit: false,
alwaysAllowWrite: true, // kilocode_change
alwaysAllowReadOnly: true, // kilocode_change
alwaysAllowDelete: false, // kilocode_change
requestDelaySeconds: 5,
currentApiConfigName: "default",
listApiConfigMeta: [],
Expand Down