Fix noisy Grok tool notifications (#6306)

This commit is contained in:
Neil
2026-06-26 02:19:25 -07:00
committed by GitHub
parent 19ab395a26
commit fa00464df9
5 changed files with 284 additions and 1 deletions
+39
View File
@@ -1303,6 +1303,45 @@ describe('shared agent-hook-listener', () => {
})
})
it('ignores Grok routine permission prompt notifications during tool use', () => {
normalizeHookPayload(
state,
'grok',
{ paneKey: PANE_KEY, payload: { hookEventName: 'UserPromptSubmit', prompt: 'ship it' } },
'production'
)
normalizeHookPayload(
state,
'grok',
{
paneKey: PANE_KEY,
payload: {
hookEventName: 'PreToolUse',
toolName: 'Shell',
toolInput: { command: 'echo hi' }
}
},
'production'
)
const event = normalizeHookPayload(
state,
'grok',
{
paneKey: PANE_KEY,
payload: {
hookEventName: 'Notification',
notificationType: 'permission_prompt',
message: 'Tool permission requested',
level: 'info'
}
},
'production'
)
expect(event).toBeNull()
})
it('reads Grok final assistant text from chat history on Stop', () => {
const tmpDir = mkdtempSync(join(tmpdir(), 'orca-grok-session-'))
const sessionId = '019e37f4-5135-7b63-a4ab-6d13aa6bf528'
+33
View File
@@ -1864,6 +1864,28 @@ function isGrokPermissionNotification(message: string | undefined): boolean {
)
}
function getGrokNotificationType(hookPayload: Record<string, unknown>): string | undefined {
return (
readString(hookPayload, 'notificationType') ??
readString(hookPayload, 'notification_type') ??
readString(hookPayload, 'type')
)
}
function isGrokRoutinePermissionPromptNotification(
notificationType: string | undefined,
message: string | undefined,
level: string | undefined
): boolean {
// Why: Grok emits this info notification before each tool even under
// bypassPermissions; PreToolUse already captures progress without paging users.
return (
isGrokEvent(notificationType, 'permission_prompt') &&
message?.trim().toLowerCase() === 'tool permission requested' &&
(!level || level.trim().toLowerCase() === 'info')
)
}
function isGrokIdleNotification(message: string | undefined): boolean {
if (!message) {
return false
@@ -2860,6 +2882,8 @@ function normalizeGrokEvent(
}
const notificationMessage = readString(hookPayload, 'message')
const notificationType = getGrokNotificationType(hookPayload)
const notificationLevel = readString(hookPayload, 'level')
let stateName: 'working' | 'waiting' | 'done' | null = null
if (
isGrokEvent(
@@ -2873,6 +2897,15 @@ function normalizeGrokEvent(
stateName = 'working'
} else if (isGrokEvent(eventName, 'stop', 'session_end')) {
stateName = 'done'
} else if (
isGrokEvent(eventName, 'notification') &&
isGrokRoutinePermissionPromptNotification(
notificationType,
notificationMessage,
notificationLevel
)
) {
return null
} else if (
isGrokEvent(eventName, 'notification') &&
isGrokPermissionNotification(notificationMessage)