(
ctx: ToolPermissionContext,
)
| 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. |
nothing calls this directly
no test coverage detected