Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

Phase 12: Per-tool approval overrides + mode scopes (v2.4.0)

PurpleDoubleDf439b8aadb52
diff --git a/src/api/mcp/__tests__/tool-registry-external.test.ts b/src/api/mcp/__tests__/tool-registry-external.test.ts
index 960d5f3e..ea989033 100644
--- a/src/api/mcp/__tests__/tool-registry-external.test.ts
+++ b/src/api/mcp/__tests__/tool-registry-external.test.ts
@@ -90,6 +90,46 @@ describe('ToolRegistry — registerExternal name binding', () => {
})
})
+describe('ToolRegistry — getPermissionLevelWithOverrides (Phase 12)', () => {
+ it('returns the per-tool override when set', () => {
+ const registry = new ToolRegistry()
+ registry.registerBuiltin(
+ { ...mkTool('file_write'), source: 'builtin', category: 'filesystem' },
+ async () => 'ok'
+ )
+ const lvl = registry.getPermissionLevelWithOverrides(
+ 'file_write',
+ { ...fullPerms, filesystem: 'confirm' },
+ { file_write: 'auto' }
+ )
+ expect(lvl).toBe('auto')
+ })
+
+ it('falls back to category when no per-tool override exists', () => {
+ const registry = new ToolRegistry()
+ registry.registerBuiltin(
+ { ...mkTool('file_write'), source: 'builtin', category: 'filesystem' },
+ async () => 'ok'
+ )
+ const lvl = registry.getPermissionLevelWithOverrides(
+ 'file_write',
+ { ...fullPerms, filesystem: 'confirm' },
+ {}
+ )
+ expect(lvl).toBe('confirm')
+ })
+
+ it('returns confirm for unknown tool regardless of overrides', () => {
+ const registry = new ToolRegistry()
+ // Override set for a tool that is not registered at all.
+ const lvl = registry.getPermissionLevelWithOverrides('mystery', fullPerms, {
+ mystery: 'auto',
+ })
+ // Override wins — tool-existence is orthogonal to the level lookup.
+ expect(lvl).toBe('auto')
+ })
+})
+
describe('external-client — resolveCommandForPlatform', () => {
it('appends .cmd for known Node-based commands on Windows', () => {
expect(resolveCommandForPlatform('npx', 'Win32')).toBe('npx.cmd')
diff --git a/src/api/mcp/tool-registry.ts b/src/api/mcp/tool-registry.ts
index b777804c..116ecf78 100644
--- a/src/api/mcp/tool-registry.ts
+++ b/src/api/mcp/tool-registry.ts
@@ -83,6 +83,23 @@ export class ToolRegistry {
return permissions[tool.category]
}
+ /**
+ * Phase 12 — resolve the effective permission for a tool with a per-tool
+ * override map layered on top of category defaults. The override map is
+ * typically sourced from permissionStore.perToolOverrides and takes
+ * precedence over the category permission; when no override exists we
+ * fall back to getPermissionLevel() semantics.
+ */
+ getPermissionLevelWithOverrides(
+ toolName: string,
+ permissions: PermissionMap,
+ perToolOverrides: Record<string, PermissionLevel>
+ ): PermissionLevel {
+ const override = perToolOverrides[toolName]
+ if (override) return override
+ return this.getPermissionLevel(toolName, permissions)
+ }
+
// ── Execution ─────────────────────────────────────────────────
async execute(name: string, args: Record<string, any>, maxRetries = 1): Promise<string> {
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.ts
index 477cc7a5..6d270d2c 100644
--- a/src/hooks/useAgentChat.ts
+++ b/src/hooks/useAgentChat.ts
@@ -521,10 +521,15 @@ export function useAgentChat() {
type BatchEntry = { tc: typeof toolCalls[number]; ac: AgentToolCall; blockId: string }
const batch: BatchEntry[] = []
budget.addToolCalls(toolCalls.length)
+ const perToolOverrides = usePermissionStore.getState().perToolOverrides
for (const tc of toolCalls) {
const toolCallId = uuid()
const blockId = uuid()
- const permLevel = toolRegistry.getPermissionLevel(tc.function.name, permissions)
+ const permLevel = toolRegistry.getPermissionLevelWithOverrides(
+ tc.function.name,
+ permissions,
+ perToolOverrides
+ )
const needsApproval = permLevel !== 'auto'
const ac: AgentToolCall = {
id: toolCallId,
diff --git a/src/stores/__tests__/permissionStore-v24.test.ts b/src/stores/__tests__/permissionStore-v24.test.ts
new file mode 100644
index 00000000..588c40ee
--- /dev/null
+++ b/src/stores/__tests__/permissionStore-v24.test.ts
@@ -0,0 +1,105 @@
+import { describe, it, expect, beforeEach } from 'vitest'
+import {
+ usePermissionStore,
+ MODE_SCOPE_ALLOWED_CATEGORIES,
+ modeAllowsCategory,
+} from '../permissionStore'
+
+describe('permissionStore — Phase 12 per-tool overrides', () => {
+ beforeEach(() => {
+ usePermissionStore.getState().resetToDefaults()
+ })
+
+ it('setToolOverride stores a per-tool level', () => {
+ usePermissionStore.getState().setToolOverride('file_write', 'auto')
+ expect(usePermissionStore.getState().perToolOverrides['file_write']).toBe('auto')
+ })
+
+ it('clearToolOverride removes the entry', () => {
+ const s = usePermissionStore.getState()
+ s.setToolOverride('file_write', 'auto')
+ s.clearToolOverride('file_write')
+ expect(usePermissionStore.getState().perToolOverrides['file_write']).toBeUndefined()
+ })
+
+ it('getEffectivePermissionForTool returns the override when set', () => {
+ const s = usePermissionStore.getState()
+ s.setToolOverride('file_write', 'auto')
+ // Even if category default would be 'confirm', override wins.
+ s.setGlobalPermission('filesystem', 'confirm')
+ const level = usePermissionStore
+ .getState()
+ .getEffectivePermissionForTool('file_write', 'filesystem')
+ expect(level).toBe('auto')
+ })
+
+ it('getEffectivePermissionForTool falls back to category when no override', () => {
+ usePermissionStore.getState().setGlobalPermission('terminal', 'auto')
+ const level = usePermissionStore
+ .getState()
+ .getEffectivePermissionForTool('shell_execute', 'terminal')
+ expect(level).toBe('auto')
+ })
+
+ it('resetToDefaults clears per-tool overrides', () => {
+ const s = usePermissionStore.getState()
+ s.setToolOverride('file_write', 'auto')
+ s.resetToDefaults()
+ expect(usePermissionStore.getState().perToolOverrides).toEqual({})
+ })
+
+ it('per-conversation override still applies on top of global when no per-tool override', () => {
+ const s = usePermissionStore.getState()
+ s.setGlobalPermission('filesystem', 'confirm')
+ s.setConversationOverride('c1', 'filesystem', 'auto')
+ // No per-tool override → resolves through per-conv layer.
+ const lvl = usePermissionStore
+ .getState()
+ .getEffectivePermissionForTool('file_read', 'filesystem', 'c1')
+ expect(lvl).toBe('auto')
+ })
+})
+
+describe('permissionStore — Phase 12 mode scopes', () => {
+ beforeEach(() => {
+ usePermissionStore.getState().resetToDefaults()
+ })
+
+ it('defaults to agent mode', () => {
+ expect(usePermissionStore.getState().modeScope).toBe('agent')
+ })
+
+ it('setModeScope mutates the field', () => {
+ usePermissionStore.getState().setModeScope('chat')
+ expect(usePermissionStore.getState().modeScope).toBe('chat')
+ })
+
+ it('chat scope allows web + system only', () => {
+ expect(modeAllowsCategory('chat', 'web')).toBe(true)
+ expect(modeAllowsCategory('chat', 'system')).toBe(true)
+ expect(modeAllowsCategory('chat', 'filesystem')).toBe(false)
+ expect(modeAllowsCategory('chat', 'terminal')).toBe(false)
+ expect(modeAllowsCategory('chat', 'image')).toBe(false)
+ })
+
+ it('edit scope adds filesystem', () => {
+ expect(modeAllowsCategory('edit', 'filesystem')).toBe(true)
+ expect(modeAllowsCategory('edit', 'terminal')).toBe(false)
+ expect(modeAllowsCategory('edit', 'image')).toBe(false)
+ })
+
+ it('agent scope allows every category', () => {
+ const all: ReadonlyArray<string> = [
+ 'filesystem', 'terminal', 'desktop', 'web', 'system', 'image', 'video', 'workflow',
+ ]
+ for (const c of all) expect(modeAllowsCategory('agent', c as any)).toBe(true)
+ })
+
+ it('allowed-category table is monotonic chat ⊆ edit ⊆ agent', () => {
+ const chat = new Set(MODE_SCOPE_ALLOWED_CATEGORIES.chat)
+ const edit = new Set(MODE_SCOPE_ALLOWED_CATEGORIES.edit)
+ const agent = new Set(MODE_SCOPE_ALLOWED_CATEGORIES.agent)
+ for (const c of chat) expect(edit.has(c)).toBe(true)
+ for (const c of edit) expect(agent.has(c)).toBe(true)
+ })
+})
diff --git a/src/stores/permissionStore.ts b/src/stores/permissionStore.ts
index 9bdd3985..15d9a4df 100644
--- a/src/stores/permissionStore.ts
+++ b/src/stores/permissionStore.ts
@@ -3,17 +3,49 @@ import { persist } from 'zustand/middleware'
import type { PermissionMap, PermissionLevel, ToolCategory } from '../api/mcp/types'
import { DEFAULT_PERMISSIONS } from '../api/mcp/types'
+/** Per-tool override: takes precedence over the tool's category default. */
+export type ToolOverrides = Record<string, PermissionLevel>
+
+/**
+ * Agent mode scope — filters which tool categories the model can see at
+ * tools[] payload construction time. v2.4.0 introduces this so the same
+ * agent code can serve a read-only "chat" scope, an edit-capable "edit"
+ * scope, or the full "agent" scope.
+ *
+ * chat → no filesystem-write, no terminal, no image_generate, no workflow
+ * edit → filesystem + web only (no shell, no codegen, no comfy)
+ * agent → everything (current default behaviour)
+ */
+export type ModeScope = 'chat' | 'edit' | 'agent'
+
interface PermissionState {
globalPermissions: PermissionMap
conversationOverrides: Record<string, Partial<PermissionMap>>
+ /** Per-tool-name override (applies to every conversation). */
+ perToolOverrides: ToolOverrides
+ /** Current mode scope. 'agent' preserves v2.3 behaviour. */
+ modeScope: ModeScope
// Getters
getEffectivePermissions: (conversationId?: string) => PermissionMap
+ /**
+ * Effective level for a specific tool, consulting:
+ * 1. perToolOverrides[toolName] (wins if set)
+ * 2. category default from getEffectivePermissions(convId)
+ */
+ getEffectivePermissionForTool: (
+ toolName: string,
+ toolCategory: ToolCategory,
+ conversationId?: string
+ ) => PermissionLevel
// Setters
setGlobalPermission: (category: ToolCategory, level: PermissionLevel) => void
setConversationOverride: (convId: string, category: ToolCategory, level: PermissionLevel) => void
clearConversationOverrides: (convId: string) => void
+ setToolOverride: (toolName: string, level: PermissionLevel) => void
+ clearToolOverride: (toolName: string) => void
+ setModeScope: (scope: ModeScope) => void
resetToDefaults: () => void
}
@@ -22,6 +54,8 @@ export const usePermissionStore = create<PermissionState>()(
(set, get) => ({
globalPermissions: { ...DEFAULT_PERMISSIONS },
conversationOverrides: {},
+ perToolOverrides: {},
+ modeScope: 'agent',
getEffectivePermissions: (conversationId?) => {
const global = get().globalPermissions
@@ -31,6 +65,13 @@ export const usePermissionStore = create<PermissionState>()(
return { ...global, ...overrides }
},
+ getEffectivePermissionForTool: (toolName, toolCategory, conversationId?) => {
+ const perTool = get().perToolOverrides[toolName]
+ if (perTool) return perTool
+ const categoryMap = get().getEffectivePermissions(conversationId)
+ return categoryMap[toolCategory]
+ },
+
setGlobalPermission: (category, level) =>
set((state) => ({
globalPermissions: { ...state.globalPermissions, [category]: level },
@@ -53,9 +94,50 @@ export const usePermissionStore = create<PermissionState>()(
return { conversationOverrides: rest }
}),
+ setToolOverride: (toolName, level) =>
+ set((state) => ({
+ perToolOverrides: { ...state.perToolOverrides, [toolName]: level },
+ })),
+
+ clearToolOverride: (toolName) =>
+ set((state) => {
+ const { [toolName]: _, ...rest } = state.perToolOverrides
+ return { perToolOverrides: rest }
+ }),
+
+ setModeScope: (scope) => set({ modeScope: scope }),
+
resetToDefaults: () =>
- set({ globalPermissions: { ...DEFAULT_PERMISSIONS }, conversationOverrides: {} }),
+ set({
+ globalPermissions: { ...DEFAULT_PERMISSIONS },
+ conversationOverrides: {},
+ perToolOverrides: {},
+ modeScope: 'agent',
+ }),
}),
{ name: 'locally-uncensored-permissions' }
)
)
+
+/**
+ * Tool categories allowed by each mode scope (Phase 12). Keep these
+ * conservative — a more permissive scope only adds categories that the
+ * less permissive one already has.
+ */
+export const MODE_SCOPE_ALLOWED_CATEGORIES: Record<ModeScope, ReadonlyArray<ToolCategory>> = {
+ // Read-only conversation: filesystem READ-style tools, web lookup, system probes.
+ chat: ['web', 'system'],
+ // Editing: adds filesystem writes. No shell, no codegen, no ComfyUI.
+ edit: ['filesystem', 'web', 'system'],
+ // Full agent: everything.
+ agent: ['filesystem', 'terminal', 'desktop', 'web', 'system', 'image', 'video', 'workflow'],
+}
+
+/**
+ * Given a mode scope and a tool category, return true if the category is
+ * allowed at that scope. Used by tool-registry callers to filter tools[]
+ * payloads before the LLM even sees them.
+ */
+export function modeAllowsCategory(scope: ModeScope, category: ToolCategory): boolean {
+ return MODE_SCOPE_ALLOWED_CATEGORIES[scope].includes(category)
+}