Skip to content

Commit a6b6c5f

Browse files
committed
fix: scope agent permission recovery to the blocked connection
1 parent 27aaf06 commit a6b6c5f

6 files changed

Lines changed: 67 additions & 24 deletions

File tree

‎DESIGN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,4 @@ Check each affected surface. Documentation-only changes need source, link, and i
333333

334334
Per-connection permission editing uses the existing local Ultimate gate and inline upgrade prompt; Community connection edits preserve saved permission decisions. Connection dialogs group the agent prompt with a collapsed AI permissions section shared by Data Studio and external MCP, separate from SSL and SSH tunnel blocks. Default to system inheritance, show effective allowed actions, and offer visible radio choices for access levels, including Custom. A short description below the option group reflects the selected access level. Custom reveals per-action switches whose labels show Use default (decision) for inherited actions and the explicit decision otherwise. Presets and custom editing change the same permission values and do not form separate policy layers. The system settings page edits action defaults, without a separate connection allowlist or MCP exposure switch. Separate shared AI defaults from MCP service settings using the existing settings cards. Use switches for binary actions, and preserve shared RadioGroup, Switch, Label, Button, neutral surfaces, localized English/Chinese copy, keyboard focus, and loading/error/retry states. See [AI permissions](docs/AI_PERMISSIONS.md) for enforcement and migration behavior.
335335

336-
Data Studio tool outcomes remain visible outside collapsible result details. Policy blocks use a local destructive notice naming the connection, required action, and recorded permission source; user rejection uses warning feedback and explicit rejection copy. Neither uses a success verb. A blocked conversation shows a paused status near the composer. Review permissions reuses existing permission controls, and Retry request starts a fresh checked turn. Keep these notices and outcomes when restoring history; an unknown or interrupted outcome must not appear successful.
336+
Data Studio tool outcomes remain visible outside collapsible result details. Policy blocks use a local destructive notice naming the connection, required action, and recorded permission source; user rejection uses warning feedback and explicit rejection copy. Neither uses a success verb. A blocked conversation shows a paused status near the composer. Review permissions edits the blocked connection using the existing connection permission control, including inherited denials, with Save and Back to chat in one footer row. Global defaults remain in Settings. Retry request starts a fresh checked turn. Keep these notices and outcomes when restoring history; an unknown or interrupted outcome must not appear successful.

‎docs/AI_PERMISSIONS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ Ask and Auto both run permitted reads automatically. Ask requests approval for o
3838

3939
A policy denial records the tool result and pauses the agent through the existing runtime cancellation boundary. The host persists the conversation as blocked and reports that state after the run has settled. Already dispatched work is not undone. Other unresolved calls show an unavailable outcome instead of success. Explicit user rejection remains distinct from a policy block.
4040

41-
Each denied call retains a visible notice with its connection, required action, and decision source when recorded. Review permissions opens the existing system, connection, source, or confirmation-rule control. Saving never executes the blocked action. Retry request starts a new agent turn with the original tool arguments, fresh permissions, and normal confirmation; it does not replay earlier successful work automatically or bypass the application gate.
41+
Each denied call retains a visible notice with its connection, required action, and decision source when recorded. For connection access denials, Review permissions always edits the blocked connection, including when its denied decision is inherited from system defaults. It never changes global defaults from chat. Conversation restrictions and saved confirmation rules retain their own recovery controls. Save and Back to chat share one dialog footer row. Saving never executes the blocked action. Retry request starts a new agent turn with the original tool arguments, fresh permissions, and normal confirmation; it does not replay earlier successful work automatically or bypass the application gate.
4242

4343
History loads persisted tool-call statuses and correlated results rather than assuming every call succeeded. Denials and failures remain visible after reopening. Interrupted or missing outcomes are shown as unavailable; legacy records whose permission source was never recorded retain a generic permission notice.

‎src/__tests__/agentPermissionRecovery.test.ts‎

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
/** @jest-environment jsdom */
22
import { flushPromises, mount } from '@vue/test-utils'
3+
import { reactive } from 'vue'
34
import { saveAiPermissions } from '@/common'
45
import ToolPermissionReview from '@/components/ai-permissions/ToolPermissionReview.vue'
56
import { agentApi } from '@/datasources/agentApi'
67

78
const mockRemoveRule = jest.fn().mockResolvedValue(undefined)
9+
const mockConnection = jest.fn()
10+
const mockEntitlement = reactive({ isLocalUltimate: true })
811
jest.mock('@/common', () => ({ saveAiPermissions: jest.fn() }))
912
jest.mock('vue-i18n', () => ({ useI18n: () => ({ t: (key: string) => key }) }))
1013
jest.mock('@/store/dataStudioStore', () => ({ useDataStudioStore: () => ({ activeSession: { id: 'chat', sources: [] }, removeConfirmationRule: mockRemoveRule }) }))
1114
jest.mock('@/datasources/agentApi', () => ({ agentApi: { loadConfirmationRules: jest.fn() } }))
12-
jest.mock('@/components/upgrade', () => ({ PaidGate: { props: ['feature'], template: '<slot />' } }))
15+
jest.mock('@/store', () => ({ useConnectionStore: () => ({ getConnectionById: mockConnection }), useEntitlementStore: () => mockEntitlement }))
1316
jest.mock('@/components/ui/button', () => ({ Button: { template: '<button><slot /></button>' } }))
1417
jest.mock('@/components/ui/dialog', () => Object.fromEntries(['Dialog', 'DialogContent', 'DialogDescription', 'DialogFooter', 'DialogHeader', 'DialogTitle'].map(name => [name, { template: '<section><slot /></section>' }])))
1518
jest.mock('@/views/data-studio/components/modify-source-modal.vue', () => ({ __esModule: true, default: { template: '<div />' } }))
16-
jest.mock('@/components/ai-permissions/DefaultPermissionEditor.vue', () => ({ __esModule: true, default: { template: '<div>System defaults</div>' } }))
1719
jest.mock('@/components/ai-permissions/ConnectionPermissionEditor.vue', () => ({
1820
__esModule: true,
1921
default: {
@@ -33,6 +35,8 @@ const openReview = (source = denial.source as 'connection' | 'system' | 'rule')
3335
describe('permission recovery', () => {
3436
beforeEach(() => {
3537
jest.clearAllMocks()
38+
mockConnection.mockReturnValue({ id: 'db', name: 'Development database' })
39+
mockEntitlement.isLocalUltimate = true
3640
jest.mocked(saveAiPermissions).mockResolvedValue({ permission_defaults: {}, connection_permissions: {} })
3741
})
3842

@@ -42,17 +46,46 @@ describe('permission recovery', () => {
4246
expect(wrapper.text()).toContain('Connection db')
4347
expect(wrapper.text()).not.toContain('System defaults')
4448
const save = wrapper.findAll('button').find(button => button.text() === 'dataStudio.modifySource.saveChanges')!
49+
const back = wrapper.findAll('button').find(button => button.text() === 'dataStudio.agent.message.backToChat')!
50+
expect(save.element.parentElement).toBe(back.element.parentElement)
4551
await save.trigger('click')
4652
await flushPromises()
4753
expect(saveAiPermissions).toHaveBeenCalledWith('db', { manage: true })
4854
expect(wrapper.emitted('update:open')).toEqual([[false]])
4955
expect(wrapper.emitted('retryToolCall')).toBeUndefined()
5056
})
5157

52-
it('opens system defaults when inheritance caused the denial', () => {
58+
it('edits only the blocked connection when inheritance caused the denial', async () => {
5359
const wrapper = openReview('system')
54-
expect(wrapper.text()).toContain('System defaults')
55-
expect(wrapper.text()).not.toContain('Connection db')
60+
await flushPromises()
61+
expect(wrapper.text()).toContain('Connection db')
62+
expect(wrapper.text()).not.toContain('System defaults')
63+
expect(wrapper.text()).toContain('dataStudio.agent.message.reviewConnectionHelp')
64+
const save = wrapper.findAll('button').find(button => button.text() === 'dataStudio.modifySource.saveChanges')!
65+
await save.trigger('click')
66+
await flushPromises()
67+
expect(saveAiPermissions).toHaveBeenCalledWith('db', { manage: true })
68+
})
69+
70+
it('never falls back to editing defaults when a connection cannot be identified', () => {
71+
const wrapper = mount(ToolPermissionReview, { props: { open: true, denial: { ...denial, source: 'system', connectionId: undefined }, toolName: 'ddl', sessionId: 'chat' } })
72+
expect(wrapper.text()).toContain('dataStudio.agent.message.connectionUnavailable')
73+
expect(wrapper.text()).not.toContain('dataStudio.modifySource.saveChanges')
74+
expect(saveAiPermissions).not.toHaveBeenCalled()
75+
})
76+
77+
it('does not offer edits for a deleted connection', () => {
78+
mockConnection.mockReturnValue(undefined)
79+
const wrapper = openReview()
80+
expect(wrapper.text()).toContain('dataStudio.agent.message.connectionUnavailable')
81+
expect(wrapper.text()).not.toContain('dataStudio.modifySource.saveChanges')
82+
expect(saveAiPermissions).not.toHaveBeenCalled()
83+
})
84+
85+
it('keeps the connection permission entitlement gate on recovery', () => {
86+
mockEntitlement.isLocalUltimate = false
87+
const wrapper = openReview()
88+
expect(wrapper.text()).not.toContain('dataStudio.modifySource.saveChanges')
5689
expect(saveAiPermissions).not.toHaveBeenCalled()
5790
})
5891

‎src/components/ai-permissions/ToolPermissionReview.vue‎

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ import { useI18n } from 'vue-i18n'
55
import { saveAiPermissions } from '@/common'
66
import { Button } from '@/components/ui/button'
77
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'
8-
import { PaidGate } from '@/components/upgrade'
98
import { agentApi } from '@/datasources/agentApi'
9+
import { useConnectionStore, useEntitlementStore } from '@/store'
1010
import { useDataStudioStore } from '@/store/dataStudioStore'
1111
import ModifySourceModal from '@/views/data-studio/components/modify-source-modal.vue'
1212
import ConnectionPermissionEditor from './ConnectionPermissionEditor.vue'
13-
import DefaultPermissionEditor from './DefaultPermissionEditor.vue'
1413
1514
const props = defineProps<{ open: boolean, denial: AccessDenial, toolName: string, sessionId: string }>()
1615
const emit = defineEmits<{ 'update:open': [value: boolean] }>()
1716
const { t } = useI18n()
1817
const store = useDataStudioStore()
18+
const connectionStore = useConnectionStore()
19+
const entitlementStore = useEntitlementStore()
20+
const connection = computed(() => props.denial.connectionId ? connectionStore.getConnectionById(props.denial.connectionId) : undefined)
21+
const reviewConnection = computed(() => props.denial.source !== 'rule' && props.denial.source !== 'conversation' && connection.value !== undefined)
1922
const rules = ref<AiPermissions>({})
2023
const editor = ref<InstanceType<typeof ConnectionPermissionEditor> | null>(null)
2124
const saving = ref(false)
@@ -30,7 +33,7 @@ watch(() => [props.open, props.denial], () => {
3033
ruleRemoved.value = false
3134
})
3235
const saveConnection = async () => {
33-
if (!props.denial.connectionId || !editor.value?.ready || saving.value)
36+
if (!reviewConnection.value || !props.denial.connectionId || !entitlementStore.isLocalUltimate || !editor.value?.ready || saving.value)
3437
return
3538
saving.value = true
3639
error.value = ''
@@ -70,8 +73,11 @@ const removeRule = async () => {
7073
<DialogContent class="max-h-[85vh] max-w-[calc(100vw-2rem)] overflow-y-auto sm:max-w-xl">
7174
<DialogHeader>
7275
<DialogTitle>{{ t('dataStudio.agent.message.reviewPermissions') }}</DialogTitle>
73-
<DialogDescription>{{ t('dataStudio.agent.message.reviewHelp') }}</DialogDescription>
76+
<DialogDescription>{{ t(reviewConnection ? 'dataStudio.agent.message.reviewConnectionHelp' : 'dataStudio.agent.message.reviewHelp') }}</DialogDescription>
7477
</DialogHeader>
78+
<p v-if="reviewConnection" class="text-sm font-medium break-words">
79+
{{ t('dataStudio.agent.message.connectionLabel', { name: connection?.name }) }}
80+
</p>
7581
<p v-if="error" role="alert" class="text-sm text-destructive-text break-words">
7682
{{ error }}
7783
</p>
@@ -82,26 +88,26 @@ const removeRule = async () => {
8288
<p v-if="ruleRemoved" role="status" class="text-sm">
8389
{{ t('dataStudio.agent.message.ruleRemoved') }}
8490
</p>
85-
<Button v-else type="button" variant="outline" :disabled="saving" @click="removeRule">
86-
{{ t('dataStudio.agent.message.removeDenyRule') }}
87-
</Button>
8891
</template>
8992
<p v-else-if="denial.source === 'conversation'" class="text-sm leading-relaxed">
9093
{{ t('dataStudio.agent.message.sourceUnavailable') }}
9194
</p>
92-
<PaidGate v-else feature="mcp_bridge">
93-
<DefaultPermissionEditor v-if="denial.source === 'system' || !denial.connectionId" />
94-
<fieldset v-else :disabled="saving" class="min-w-0 space-y-4">
95-
<ConnectionPermissionEditor ref="editor" v-model="rules" :connection-id="denial.connectionId" initially-expanded />
96-
<Button type="button" :disabled="saving || !editor?.ready" @click="saveConnection">
97-
{{ t(saving ? 'aiPermissions.saving' : 'dataStudio.modifySource.saveChanges') }}
98-
</Button>
99-
</fieldset>
100-
</PaidGate>
101-
<DialogFooter>
95+
<fieldset v-else-if="reviewConnection" :disabled="saving" class="min-w-0">
96+
<ConnectionPermissionEditor ref="editor" v-model="rules" :connection-id="denial.connectionId" initially-expanded />
97+
</fieldset>
98+
<p v-else class="text-sm leading-relaxed">
99+
{{ t('dataStudio.agent.message.connectionUnavailable') }}
100+
</p>
101+
<DialogFooter class="pt-4 border-t border-border">
102102
<Button type="button" variant="outline" :disabled="saving" @click="emit('update:open', false)">
103103
{{ t('dataStudio.agent.message.backToChat') }}
104104
</Button>
105+
<Button v-if="denial.source === 'rule' && !ruleRemoved" type="button" :disabled="saving" @click="removeRule">
106+
{{ t('dataStudio.agent.message.removeDenyRule') }}
107+
</Button>
108+
<Button v-else-if="reviewConnection && entitlementStore.isLocalUltimate" type="button" :disabled="saving || !editor?.ready" @click="saveConnection">
109+
{{ t(saving ? 'aiPermissions.saving' : 'dataStudio.modifySource.saveChanges') }}
110+
</Button>
105111
</DialogFooter>
106112
</DialogContent>
107113
</Dialog>

‎src/lang/enUS.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,8 @@ export const enUS = {
10801080
requiredAction: 'Required: {action}',
10811081
reviewPermissions: 'Review permissions',
10821082
reviewHelp: 'Saving permission changes does not run the blocked action. Return to chat and choose Retry request when ready.',
1083+
reviewConnectionHelp: 'Changes apply only to this connection. System defaults stay unchanged. Save, then return to chat to retry the request.',
1084+
connectionUnavailable: 'The saved connection could not be identified. Reattach the connection in chat before reviewing its permissions.',
10831085
backToChat: 'Back to chat',
10841086
retryRequest: 'Retry request',
10851087
retryPrompt: 'Retry the previously blocked or rejected request using {tool} with these original arguments:\n{args}\nRecheck current permissions and request any required approval. Do not repeat earlier successful actions.',

‎src/lang/zhCN.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,8 @@ export const zhCN = {
10801080
requiredAction: '所需权限:{action}',
10811081
reviewPermissions: '检查权限',
10821082
reviewHelp: '保存权限不会执行已阻止的操作。返回对话后,点击「重试请求」继续。',
1083+
reviewConnectionHelp: '仅修改此连接的权限,不影响系统默认权限。保存后返回对话,再重试请求。',
1084+
connectionUnavailable: '无法确定原保存的连接。请在对话中重新添加连接,再检查其权限。',
10831085
backToChat: '返回对话',
10841086
retryRequest: '重试请求',
10851087
retryPrompt: '请使用工具 {tool} 和以下原始参数重试刚才被阻止或拒绝的请求:\n{args}\n重新检查当前权限,并在需要时请求批准。不要重复之前已经成功的操作。',

0 commit comments

Comments
 (0)