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

Function executeImmediateCommand

src/screens/REPL.tsx:3211–3281  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3209
3210 // Execute the command directly
3211 const executeImmediateCommand = async (): Promise<void> => {
3212 let doneWasCalled = false;
3213 const onDone = (result?: string, doneOptions?: {
3214 display?: CommandResultDisplay;
3215 metaMessages?: string[];
3216 }): void => {
3217 doneWasCalled = true;
3218 setToolJSX({
3219 jsx: null,
3220 shouldHidePromptInput: false,
3221 clearLocalJSX: true
3222 });
3223 const newMessages: MessageType[] = [];
3224 if (result && doneOptions?.display !== 'skip') {
3225 addNotification({
3226 key: `immediate-${matchingCommand.name}`,
3227 text: result,
3228 priority: 'immediate'
3229 });
3230 // In fullscreen the command just showed as a centered modal
3231 // pane — the notification above is enough feedback. Adding
3232 // "❯ /config" + "⎿ dismissed" to the transcript is clutter
3233 // (those messages are type:system subtype:local_command —
3234 // user-visible but NOT sent to the model, so skipping them
3235 // doesn't change model context). Outside fullscreen the
3236 // transcript entry stays so scrollback shows what ran.
3237 if (!isFullscreenEnvEnabled()) {
3238 newMessages.push(createCommandInputMessage(formatCommandInputTags(getCommandName(matchingCommand), commandArgs)), createCommandInputMessage(`<${LOCAL_COMMAND_STDOUT_TAG}>${escapeXml(result)}</${LOCAL_COMMAND_STDOUT_TAG}>`));
3239 }
3240 }
3241 // Inject meta messages (model-visible, user-hidden) into the transcript
3242 if (doneOptions?.metaMessages?.length) {
3243 newMessages.push(...doneOptions.metaMessages.map(content => createUserMessage({
3244 content,
3245 isMeta: true
3246 })));
3247 }
3248 if (newMessages.length) {
3249 setMessages(prev => [...prev, ...newMessages]);
3250 }
3251 // Restore stashed prompt after local-jsx command completes.
3252 // The normal stash restoration path (below) is skipped because
3253 // local-jsx commands return early from onSubmit.
3254 if (stashedPrompt !== undefined) {
3255 setInputValue(stashedPrompt.text);
3256 helpers.setCursorOffset(stashedPrompt.cursorOffset);
3257 setPastedContents(stashedPrompt.pastedContents);
3258 setStashedPrompt(undefined);
3259 }
3260 };
3261
3262 // Build context for the command (reuses existing getToolUseContext).
3263 // Read messages via ref to keep onSubmit stable across message
3264 // updates — matches the pattern at L2384/L2400/L2662 and avoids
3265 // pinning stale REPL render scopes in downstream closures.
3266 const context = getToolUseContext(messagesRef.current, [], createAbortController(), mainLoopModel);
3267 const mod = await matchingCommand.load();
3268 const jsx = await mod.call(onDone, context, commandArgs);

Callers 1

REPLFunction · 0.85

Calls 2

createAbortControllerFunction · 0.85
loadMethod · 0.80

Tested by

no test coverage detected