mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
fix: guard the Assistant config conversion and place agent permission fallbacks after catch-all rules (OM-179)
The Assistant v1-to-v2 conversion now skips the write when OpenCode returns no converted assistant agent for a customized v1 one, or when the converted config fails validation, and it shares a file lock with ensureAssistantMode so the two never overwrite each other. A new agent wildcard permission rule is inserted after the last catch-all * * rule instead of before it, so the catch-all cannot override it. The event subscription also counts each received event as stream activity.
This commit is contained in:
1 parent
84aa8dbeac
commit
64e87ba1ea
5 files changed
+158
-67
No files matched your search
@@ -341,6 +341,39 @@ describe('AgentDialog', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('places a new wildcard rule after a catch-all rule and before later exceptions', async () => {
|
||||
const onSubmit = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
render(
|
||||
<AgentDialog
|
||||
open
|
||||
onOpenChange={vi.fn()}
|
||||
onSubmit={onSubmit}
|
||||
editingAgent={{
|
||||
name: 'reviewer',
|
||||
agent: {
|
||||
system: 'Review code',
|
||||
permissions: [
|
||||
{ action: '*', resource: '*', effect: 'allow' },
|
||||
{ action: 'shell', resource: 'git status', effect: 'allow' },
|
||||
],
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
)
|
||||
|
||||
await user.click(screen.getByRole('combobox', { name: 'Shell' }))
|
||||
await user.click(screen.getByRole('option', { name: 'Deny' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Update' }))
|
||||
|
||||
const agent = onSubmit.mock.calls[0][1]
|
||||
expect(agent.permissions).toEqual([
|
||||
{ action: '*', resource: '*', effect: 'allow' },
|
||||
{ action: 'shell', resource: '*', effect: 'deny' },
|
||||
{ action: 'shell', resource: 'git status', effect: 'allow' },
|
||||
])
|
||||
})
|
||||
|
||||
it('writes no permissions for a prompt-only save of an agent without permission rules', async () => {
|
||||
const onSubmit = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
|
||||
@@ -48,7 +48,8 @@ const permissionEffect = (
|
||||
* Applies the form effects to the managed wildcard rules in place, so the rule
|
||||
* order OpenCode resolves with last-match-wins stays unchanged. An `inherit`
|
||||
* effect removes the action's wildcard rules so the global permission applies;
|
||||
* any other effect prepends a wildcard rule when the action has none yet.
|
||||
* any other effect adds a wildcard rule when the action has none yet, placed
|
||||
* after the last catch-all `* *` rule so that rule cannot override it.
|
||||
*/
|
||||
const withManagedPermissionEffects = (
|
||||
permissions: OpenCodePermissionRule[] | undefined,
|
||||
@@ -64,7 +65,11 @@ const withManagedPermissionEffects = (
|
||||
const effect = effects[action]
|
||||
return effect === 'inherit' || actionsWithWildcard.has(action) ? [] : [{ action, resource: '*', effect }]
|
||||
})
|
||||
return [...fallbacks, ...updated]
|
||||
const fallbackIndex = updated.reduce(
|
||||
(index, rule, currentIndex) => (rule.action === '*' && rule.resource === '*' ? currentIndex + 1 : index),
|
||||
0,
|
||||
)
|
||||
return [...updated.slice(0, fallbackIndex), ...fallbacks, ...updated.slice(fallbackIndex)]
|
||||
}
|
||||
|
||||
const optionalNumber = (value: string): number | undefined => {
|
||||
|
||||
Reference in new issue
Block a user