mirror of
https://github.com/stablyai/orca.git
synced 2026-11-18 11:54:46 +00:00
fix(droid): stop installing the unsupported PermissionRequest hook (#40612)
Factory Droid has no PermissionRequest hook event, so `droid doctor` flagged the hook Orca wrote into ~/.factory/settings.json as unsupported. The installer no longer registers it; reinstall drops only the previously managed Orca command on that event and keeps user hooks. Approval waits continue to come from PreToolUse and Notification, and the now-unreachable PermissionRequest listener handling is removed. Fixes #40607 Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import type * as NodeOs from 'node:os'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const sandbox = vi.hoisted(() => ({ home: '' }))
|
||||
vi.mock('node:os', async (importOriginal) => ({
|
||||
...(await importOriginal<typeof NodeOs>()),
|
||||
homedir: () => sandbox.home
|
||||
}))
|
||||
|
||||
import { DroidHookService } from './hook-service'
|
||||
|
||||
describe('DroidHookService', () => {
|
||||
beforeEach(() => {
|
||||
sandbox.home = mkdtempSync(join(tmpdir(), 'orca-droid-home-'))
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
rmSync(sandbox.home, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
it('drops a previously managed PermissionRequest hook but keeps the user hook on it', () => {
|
||||
const configPath = join(sandbox.home, '.factory', 'settings.json')
|
||||
const userDefinition = {
|
||||
matcher: 'Edit',
|
||||
hooks: [{ type: 'command', command: '/usr/local/bin/my-approval.sh' }]
|
||||
}
|
||||
const managedCommand = join(sandbox.home, '.orca', 'agent-hooks', 'droid-hook.sh')
|
||||
mkdirSync(dirname(configPath), { recursive: true })
|
||||
writeFileSync(
|
||||
configPath,
|
||||
JSON.stringify({
|
||||
hooks: {
|
||||
PermissionRequest: [
|
||||
{ matcher: '*', hooks: [{ type: 'command', command: managedCommand }] },
|
||||
userDefinition
|
||||
]
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
expect(new DroidHookService().install().state).toBe('installed')
|
||||
|
||||
const installed = JSON.parse(readFileSync(configPath, 'utf8'))
|
||||
expect(installed.hooks.PermissionRequest).toEqual([userDefinition])
|
||||
})
|
||||
})
|
||||
@@ -49,11 +49,7 @@ const DROID_EVENTS = [
|
||||
eventName: 'PostToolUse',
|
||||
definition: { matcher: '*', hooks: [{ type: 'command', command: '' }] }
|
||||
},
|
||||
// PermissionRequest covers Edit approvals that have no PreToolUse riskLevel.
|
||||
{
|
||||
eventName: 'PermissionRequest',
|
||||
definition: { matcher: '*', hooks: [{ type: 'command', command: '' }] }
|
||||
},
|
||||
// Droid has no PermissionRequest hook event; approval waits come from PreToolUse and Notification.
|
||||
{ eventName: 'Notification', definition: { hooks: [{ type: 'command', command: '' }] } }
|
||||
] as const
|
||||
|
||||
|
||||
@@ -43,8 +43,6 @@ export function normalizeDroidEvent(
|
||||
stateName = 'working'
|
||||
} else if (eventName === 'Stop') {
|
||||
stateName = 'done'
|
||||
} else if (eventName === 'PermissionRequest') {
|
||||
stateName = 'waiting'
|
||||
} else if (eventName === 'Notification' && isDroidPermissionNotification(notificationMessage)) {
|
||||
stateName = 'waiting'
|
||||
} else if (eventName === 'Notification' && isDroidIdleNotification(notificationMessage)) {
|
||||
|
||||
@@ -60,11 +60,7 @@ export function extractDroidToolFields(
|
||||
eventName: unknown,
|
||||
hookPayload: Record<string, unknown>
|
||||
): ToolSnapshot {
|
||||
if (
|
||||
eventName === 'PreToolUse' ||
|
||||
eventName === 'PostToolUse' ||
|
||||
eventName === 'PermissionRequest'
|
||||
) {
|
||||
if (eventName === 'PreToolUse' || eventName === 'PostToolUse') {
|
||||
const toolName = readString(hookPayload, 'tool_name') ?? readString(hookPayload, 'name')
|
||||
const toolInput =
|
||||
deriveToolInputPreview(toolName, hookPayload.tool_input) ??
|
||||
|
||||
Reference in New Issue
Block a user