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