MCPcopy Create free account
hub / github.com/freecodexyz/free-code / processInitialMessage

Function processInitialMessage

src/screens/REPL.tsx:3038–3142  ·  view source on GitHub ↗
(initialMsg: NonNullable<typeof pending>)

Source from the content-addressed store, hash-verified

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

Callers 1

REPLFunction · 0.85

Calls 13

getPlanSlugFunction · 0.85
clearConversationFunction · 0.85
setPlanSlugFunction · 0.85
getSessionIdFunction · 0.85
isEnvTruthyFunction · 0.85
applyPermissionUpdatesFunction · 0.85
buildPermissionUpdatesFunction · 0.85
fileHistoryEnabledFunction · 0.85
fileHistoryMakeSnapshotFunction · 0.85
onSubmitFunction · 0.85
createAbortControllerFunction · 0.85

Tested by

no test coverage detected