(initialMsg: NonNullable<typeof pending>)
| 3033 | // Mark as processing to prevent re-entry |
| 3034 | initialMessageRef.current = true; |
| 3035 | async function processInitialMessage(initialMsg: NonNullable<typeof pending>) { |
| 3036 | // Clear context if requested (plan mode exit) |
| 3037 | if (initialMsg.clearContext) { |
| 3038 | // Preserve the plan slug before clearing context, so the new session |
| 3039 | // can access the same plan file after regenerateSessionId() |
| 3040 | const oldPlanSlug = initialMsg.message.planContent ? getPlanSlug() : undefined; |
| 3041 | const { |
| 3042 | clearConversation |
| 3043 | } = await import('../commands/clear/conversation.js'); |
| 3044 | await clearConversation({ |
| 3045 | setMessages, |
| 3046 | readFileState: readFileState.current, |
| 3047 | discoveredSkillNames: discoveredSkillNamesRef.current, |
| 3048 | loadedNestedMemoryPaths: loadedNestedMemoryPathsRef.current, |
| 3049 | getAppState: () => store.getState(), |
| 3050 | setAppState, |
| 3051 | setConversationId |
| 3052 | }); |
| 3053 | haikuTitleAttemptedRef.current = false; |
| 3054 | setHaikuTitle(undefined); |
| 3055 | bashTools.current.clear(); |
| 3056 | bashToolsProcessedIdx.current = 0; |
| 3057 | |
| 3058 | // Restore the plan slug for the new session so getPlan() finds the file |
| 3059 | if (oldPlanSlug) { |
| 3060 | setPlanSlug(getSessionId(), oldPlanSlug); |
| 3061 | } |
| 3062 | } |
| 3063 | |
| 3064 | // Atomically: clear initial message, set permission mode and rules, and store plan for verification |
| 3065 | const shouldStorePlanForVerification = initialMsg.message.planContent && "external" === 'ant' && isEnvTruthy(undefined); |
| 3066 | setAppState(prev => { |
| 3067 | // Build and apply permission updates (mode + allowedPrompts rules) |
| 3068 | let updatedToolPermissionContext = initialMsg.mode ? applyPermissionUpdates(prev.toolPermissionContext, buildPermissionUpdates(initialMsg.mode, initialMsg.allowedPrompts)) : prev.toolPermissionContext; |
| 3069 | // For auto, override the mode (buildPermissionUpdates maps |
| 3070 | // it to 'default' via toExternalPermissionMode) and strip dangerous rules |
| 3071 | if (feature('TRANSCRIPT_CLASSIFIER') && initialMsg.mode === 'auto') { |
| 3072 | updatedToolPermissionContext = stripDangerousPermissionsForAutoMode({ |
| 3073 | ...updatedToolPermissionContext, |
| 3074 | mode: 'auto', |
| 3075 | prePlanMode: undefined |
| 3076 | }); |
| 3077 | } |
| 3078 | return { |
| 3079 | ...prev, |
| 3080 | initialMessage: null, |
| 3081 | toolPermissionContext: updatedToolPermissionContext, |
| 3082 | ...(shouldStorePlanForVerification && { |
| 3083 | pendingPlanVerification: { |
| 3084 | plan: initialMsg.message.planContent!, |
| 3085 | verificationStarted: false, |
| 3086 | verificationCompleted: false |
| 3087 | } |
| 3088 | }) |
| 3089 | }; |
| 3090 | }); |
| 3091 | |
| 3092 | // Create file history snapshot for code rewind |
no test coverage detected