Skip to content

fix: wait for CLI readiness before SendPrompt to prevent prompt loss#267

Open
DragonFSKY wants to merge 1 commit intosmtg-ai:mainfrom
DragonFSKY:fix/wait-for-cli-ready-before-send-prompt
Open

fix: wait for CLI readiness before SendPrompt to prevent prompt loss#267
DragonFSKY wants to merge 1 commit intosmtg-ai:mainfrom
DragonFSKY:fix/wait-for-cli-ready-before-send-prompt

Conversation

@DragonFSKY
Copy link
Copy Markdown

Summary

  • Fix timing race condition where SendPrompt() sends text before CLI (Claude, Aider, Codex, etc.) finishes initialization, causing the prompt to be lost when using Shift+N to create an instance with a prompt
  • Add IsCliReady() / WaitForCliReady() methods to detect CLI input-ready state by checking program-specific prompt patterns (❯ for Claude, > for Aider/Gemini/Codex) with content-stability fallback for unknown CLIs
  • Change the instanceStartedMsg handler to send the prompt asynchronously via tea.Cmd, so the UI remains responsive during the wait

Test plan

  • Create instance via Shift+N with prompt using Codex CLI — confirm prompt is delivered
  • Create instance via Shift+N with prompt using Claude CLI — confirm prompt is delivered
  • Create instance via Shift+N without prompt — confirm no regression
  • Create instance via regular N flow — confirm no regression
  • Verify UI does not freeze while waiting for CLI readiness

Fixes #266

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 17, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@DragonFSKY
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

When creating an instance with a prompt via Shift+N, SendPrompt() was
called synchronously right after the instance started, before the CLI
(Claude, Aider, Codex, etc.) had finished initializing. This caused
the prompt text to be lost.

Changes:
- Add ProgramCodex constant for Codex CLI detection
- Add IsCliReady() to detect CLI input-ready state by checking
  program-specific prompt indicators (❯ for Claude, > for others)
- Add WaitForCliReady() with polling (200ms interval, 30s timeout)
  and content stability fallback for unknown CLIs
- Add Instance.WaitForCliReady() wrapper method
- Change instanceStartedMsg handler to send prompt asynchronously
  via tea.Cmd, preventing UI blocking during the wait

Fixes smtg-ai#266
@DragonFSKY DragonFSKY force-pushed the fix/wait-for-cli-ready-before-send-prompt branch from 931456b to 4627594 Compare March 17, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: SendPrompt sends text before CLI (Codex/others) is ready, prompt lost

1 participant