( context: ToolPermissionContext, )
| 1501 | * useAutoModeDuringPlan mid-plan takes effect immediately. |
| 1502 | */ |
| 1503 | export function transitionPlanAutoMode( |
| 1504 | context: ToolPermissionContext, |
| 1505 | ): ToolPermissionContext { |
| 1506 | if (!feature('TRANSCRIPT_CLASSIFIER')) return context |
| 1507 | if (context.mode !== 'plan') return context |
| 1508 | // Mirror prepareContextForPlanMode's entry-time exclusion — never activate |
| 1509 | // auto mid-plan when the user entered from a dangerous mode. |
| 1510 | if (context.prePlanMode === 'bypassPermissions') { |
| 1511 | return context |
| 1512 | } |
| 1513 | |
| 1514 | const want = shouldPlanUseAutoMode() |
| 1515 | const have = autoModeStateModule?.isAutoModeActive() ?? false |
| 1516 | |
| 1517 | if (want && have) { |
| 1518 | // syncPermissionRulesFromDisk (called before us in applySettingsChange) |
| 1519 | // re-adds dangerous rules from disk without touching strippedDangerousRules. |
| 1520 | // Re-strip so the classifier isn't bypassed by prefix-rule allow matches. |
| 1521 | return stripDangerousPermissionsForAutoMode(context) |
| 1522 | } |
| 1523 | if (!want && !have) return context |
| 1524 | |
| 1525 | if (want) { |
| 1526 | autoModeStateModule?.setAutoModeActive(true) |
| 1527 | setNeedsAutoModeExitAttachment(false) |
| 1528 | return stripDangerousPermissionsForAutoMode(context) |
| 1529 | } |
| 1530 | autoModeStateModule?.setAutoModeActive(false) |
| 1531 | setNeedsAutoModeExitAttachment(true) |
| 1532 | return restoreDangerousPermissions(context) |
| 1533 | } |
no test coverage detected