Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/onboarding-tool-permissions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---

Keep Review-first onboarding permissions editable in Auto-Approve settings.
1 change: 0 additions & 1 deletion packages/kilo-vscode/src/shared/work-style-presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export const WORK_STYLE_PRESETS: Record<WorkStyle, WorkStylePreset> = {
terminal_command_display: "expanded",
auto_collapse_reasoning: false,
permission: {
"*": "ask",
read: {
"*": "allow",
"*.env": "ask",
Expand Down
30 changes: 30 additions & 0 deletions packages/kilo-vscode/tests/unit/permission-editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
clearGroupedPatch,
clearWildcardPatch,
DEFAULT_RULES,
effectiveConfigLevel,
inheritedWildcard,
mostRestrictive,
permissionExceptions,
Expand All @@ -15,6 +16,8 @@ import {
wildcardAction,
effectiveRuleLevel,
} from "../../webview-ui/src/components/settings/permission-utils"
import { ConfigState } from "../../webview-ui/src/utils/config-utils"
import { WORK_STYLE_PRESETS } from "../../src/shared/work-style-presets"
import type { PermissionRule, PermissionRuleItem } from "../../webview-ui/src/types/messages"

describe("effectiveRuleLevel", () => {
Expand Down Expand Up @@ -47,6 +50,33 @@ describe("effectiveRuleLevel", () => {
})
})

describe("Auto-Approve onboarding state", () => {
const permission = WORK_STYLE_PRESETS["human-in-the-loop"].config.permission ?? {}

it("reflects onboarding permissions in Auto-Approve", () => {
expect(effectiveConfigLevel(permission, "edit")).toBe("ask")
expect(effectiveConfigLevel(permission, "bash")).toBe("ask")
expect(effectiveConfigLevel(permission, "glob")).toBe("allow")
expect(effectiveConfigLevel(permission, "grep")).toBe("allow")
})

it("keeps an Auto-Approve change selected after saving", () => {
const state = new ConfigState()
state.handleConfigLoaded({ permission })

expect(effectiveConfigLevel(state.config.permission ?? {}, "edit")).toBe("ask")

state.updateConfig({ permission: { edit: "allow" } })
expect(effectiveConfigLevel(state.config.permission ?? {}, "edit")).toBe("allow")
expect(state.draft).toEqual({ permission: { edit: "allow" } })

state.saveConfig()
state.handleConfigUpdated(state.config)
expect(effectiveConfigLevel(state.config.permission ?? {}, "edit")).toBe("allow")
expect(state.dirty).toBe(false)
})
})

describe("ruleset", () => {
it("preserves backend defaults when config only customizes bash", () => {
const rules = [...DEFAULT_RULES, ...ruleset({ bash: { "*": "ask", "git status *": "allow" } })]
Expand Down
18 changes: 17 additions & 1 deletion packages/kilo-vscode/tests/unit/work-style-apply.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function setup(input?: {
}) {
const settings = new Map<string, unknown>([["agentWorkStyle", "unset"]])
const events: string[] = []
const patches: WorkStyleConfig[] = []
const store: WorkStyleStore = {
read: async () => input?.config ?? {},
inspect: (key) => ({
Expand All @@ -23,10 +24,11 @@ function setup(input?: {
},
patch: async (config) => {
events.push(`patch:${Object.keys(config).sort().join(",")}`)
patches.push(config)
if (input?.failPatch) throw new Error("Failed to patch config")
},
}
return { store, settings, events }
return { store, settings, events, patches }
}

describe("applyWorkStyle", () => {
Expand All @@ -45,6 +47,20 @@ describe("applyWorkStyle", () => {
])
})

it("does not write a top-level permission choice when creating global config", async () => {
const state = setup({ config: {} })

expect(await applyWorkStyle("human-in-the-loop", state.store)).toEqual({ ok: true })
expect(state.patches).toHaveLength(1)
expect(["ask", "allow", "deny"]).not.toContain(state.patches[0].permission?.["*"])
expect(state.patches[0].permission).toMatchObject({
edit: "ask",
glob: "allow",
grep: "allow",
bash: { "*": "ask" },
})
})

it("rolls extension settings back when the CLI config update fails", async () => {
const state = setup({ failPatch: true })

Expand Down
8 changes: 7 additions & 1 deletion packages/kilo-vscode/tests/unit/work-style-presets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("work style presets", () => {
const bash = cfg.permission?.bash as Record<string, string>
expect(cfg.terminal_command_display).toBe("expanded")
expect(cfg.auto_collapse_reasoning).toBe(false)
expect(cfg.permission?.["*"]).toBe("ask")
expect(cfg.permission?.["*"]).toBeUndefined()
expect(cfg.permission?.edit).toBe("ask")
expect(bash).toMatchObject({ "*": "ask", "rg *": "allow", "*>*": "ask" })
expect(Object.keys(bash).at(-1)).toBe("*>*")
Expand Down Expand Up @@ -50,6 +50,12 @@ describe("work style presets", () => {
})
})

it("never defines a top-level permission choice in onboarding presets", () => {
for (const preset of Object.values(WORK_STYLE_PRESETS)) {
expect(["ask", "allow", "deny"]).not.toContain(preset.config.permission?.["*"])
}
})

it("does not overwrite existing new-user settings", () => {
const plan = buildWorkStyleApplyPlan({
style: "human-in-the-loop",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import {
addExceptionPatch,
clearGroupedPatch,
clearWildcardPatch,
effectiveRuleLevel,
effectiveConfigLevel,
inheritedWildcard,
mostRestrictive,
permissionExceptions,
removeExceptionPatch,
ruleset,
setExceptionPatch,
setGroupedPatch,
setWildcardPatch,
Expand Down Expand Up @@ -140,9 +139,8 @@ const PermissionEditor: Component<{
onChange: (patch: PermissionPatch) => void
}> = (props) => {
const perms = createMemo(() => props.permissions ?? {})
const rules = createMemo(() => [...(props.rules ?? []), ...ruleset(perms())])

const levelFor = (tool: string): PermissionLevel => effectiveRuleLevel(rules(), tool)
const levelFor = (tool: string): PermissionLevel => effectiveConfigLevel(perms(), tool, props.rules)

const ruleFor = (tool: string): PermissionRule | undefined => perms()[tool]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export function effectiveRuleLevel(rules: PermissionRuleItem[] | undefined, tool
return "ask"
}

export function effectiveConfigLevel(
config: PermissionConfig,
tool: string,
defaults: PermissionRuleItem[] = DEFAULT_RULES,
): PermissionLevel {
return effectiveRuleLevel([...defaults, ...ruleset(config)], tool)
}

export function ruleset(config: PermissionConfig): PermissionRuleItem[] {
const result: PermissionRuleItem[] = []
for (const [permission, rule] of Object.entries(config)) {
Expand Down
Loading