MCPcopy Index your code
hub / github.com/codeaashu/claude-code / kickOutOfAutoIfNeeded

Function kickOutOfAutoIfNeeded

src/utils/permissions/permissionSetup.ts:1190–1226  ·  view source on GitHub ↗
(
    ctx: ToolPermissionContext,
  )

Source from the content-addressed store, hash-verified

1188 // ENTERED auto during the await (possible before setAutoModeCircuitBroken
1189 // landed), we kick them out here.
1190 const kickOutOfAutoIfNeeded = (
1191 ctx: ToolPermissionContext,
1192 ): ToolPermissionContext => {
1193 const inAuto = ctx.mode === 'auto'
1194 logForDebugging(
1195 `[auto-mode] kickOutOfAutoIfNeeded applying: ctx.mode=${ctx.mode} ctx.prePlanMode=${ctx.prePlanMode} reason=${reason}`,
1196 )
1197 // Plan mode with auto active: either from prePlanMode='auto' (entered
1198 // from auto) or from opt-in (strippedDangerousRules present).
1199 const inPlanWithAutoActive =
1200 ctx.mode === 'plan' &&
1201 (ctx.prePlanMode === 'auto' || !!ctx.strippedDangerousRules)
1202 if (!inAuto && !inPlanWithAutoActive) {
1203 return setAvailable(ctx, false)
1204 }
1205 if (inAuto) {
1206 autoModeStateModule?.setAutoModeActive(false)
1207 setNeedsAutoModeExitAttachment(true)
1208 return {
1209 ...applyPermissionUpdate(restoreDangerousPermissions(ctx), {
1210 type: 'setMode',
1211 mode: 'default',
1212 destination: 'session',
1213 }),
1214 isAutoModeAvailable: false,
1215 }
1216 }
1217 // Plan with auto active: deactivate auto, restore permissions, defuse
1218 // prePlanMode so ExitPlanMode goes to default.
1219 autoModeStateModule?.setAutoModeActive(false)
1220 setNeedsAutoModeExitAttachment(true)
1221 return {
1222 ...restoreDangerousPermissions(ctx),
1223 prePlanMode: ctx.prePlanMode === 'auto' ? 'default' : ctx.prePlanMode,
1224 isAutoModeAvailable: false,
1225 }
1226 }
1227
1228 // Notification decisions use the stale context — that's OK: we're deciding
1229 // WHETHER to notify based on what the user WAS doing when this check started.

Callers

nothing calls this directly

Calls 5

logForDebuggingFunction · 0.85
setAvailableFunction · 0.85
applyPermissionUpdateFunction · 0.85

Tested by

no test coverage detected