MCPcopy Create free account
hub / github.com/codeaashu/claude-code / handleDenialLimitExceeded

Function handleDenialLimitExceeded

src/utils/permissions/permissions.ts:984–1058  ·  view source on GitHub ↗

* Check if a denial limit was exceeded and return an 'ask' result * so the user can review. Returns null if no limit was hit.

(
  denialState: DenialTrackingState,
  appState: {
    toolPermissionContext: { shouldAvoidPermissionPrompts?: boolean }
  },
  classifierReason: string,
  assistantMessage: AssistantMessage,
  tool: Tool,
  result: PermissionDecision,
  context: ToolUseContext,
)

Source from the content-addressed store, hash-verified

982 * so the user can review. Returns null if no limit was hit.
983 */
984function handleDenialLimitExceeded(
985 denialState: DenialTrackingState,
986 appState: {
987 toolPermissionContext: { shouldAvoidPermissionPrompts?: boolean }
988 },
989 classifierReason: string,
990 assistantMessage: AssistantMessage,
991 tool: Tool,
992 result: PermissionDecision,
993 context: ToolUseContext,
994): PermissionDecision | null {
995 if (!shouldFallbackToPrompting(denialState)) {
996 return null
997 }
998
999 const hitTotalLimit = denialState.totalDenials >= DENIAL_LIMITS.maxTotal
1000 const isHeadless = appState.toolPermissionContext.shouldAvoidPermissionPrompts
1001 // Capture counts before persistDenialState, which may mutate denialState
1002 // in-place via Object.assign for subagents with localDenialTracking.
1003 const totalCount = denialState.totalDenials
1004 const consecutiveCount = denialState.consecutiveDenials
1005 const warning = hitTotalLimit
1006 ? `${totalCount} actions were blocked this session. Please review the transcript before continuing.`
1007 : `${consecutiveCount} consecutive actions were blocked. Please review the transcript before continuing.`
1008
1009 logEvent('tengu_auto_mode_denial_limit_exceeded', {
1010 limit: (hitTotalLimit
1011 ? 'total'
1012 : 'consecutive') as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
1013 mode: (isHeadless
1014 ? 'headless'
1015 : 'cli') as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
1016 messageID: assistantMessage.message
1017 .id as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
1018 consecutiveDenials: consecutiveCount,
1019 totalDenials: totalCount,
1020 toolName: sanitizeToolNameForAnalytics(tool.name),
1021 })
1022
1023 if (isHeadless) {
1024 throw new AbortError(
1025 'Agent aborted: too many classifier denials in headless mode',
1026 )
1027 }
1028
1029 logForDebugging(
1030 `Classifier denial limit exceeded, falling back to prompting: ${warning}`,
1031 { level: 'warn' },
1032 )
1033
1034 if (hitTotalLimit) {
1035 persistDenialState(context, {
1036 ...denialState,
1037 totalDenials: 0,
1038 consecutiveDenials: 0,
1039 })
1040 }
1041

Callers 1

hasPermissionsToUseToolFunction · 0.85

Calls 5

logEventFunction · 0.85
logForDebuggingFunction · 0.85
persistDenialStateFunction · 0.85

Tested by

no test coverage detected