feat(cli): add --headless-interactive flag for multi-turn stdin sessions#23367
Closed
GoBeromsu wants to merge 1 commit intogoogle-gemini:mainfrom
Closed
feat(cli): add --headless-interactive flag for multi-turn stdin sessions#23367GoBeromsu wants to merge 1 commit intogoogle-gemini:mainfrom
GoBeromsu wants to merge 1 commit intogoogle-gemini:mainfrom
Conversation
Add a new `--headless-interactive` flag that enables headless interactive mode: reads newline-delimited prompts from stdin, maintains conversation state across prompts, and outputs responses to stdout without the Ink UI. This addresses the gap described in google-gemini#13924 where programmatic consumers (Java, Node.js, backend services) cannot maintain multi-turn sessions because `stdin.isTTY === false` forces non-interactive single-prompt mode. While ACP mode (`--acp`) technically provides headless interactive capabilities, it requires ndJSON protocol handshake and SDK dependency. This flag offers a simpler plain-text stdin/stdout interface for shell pipeline use cases. Changes: - Add `--headless-interactive` CLI flag with mutual exclusivity checks - Add routing branch in main() between ACP and interactive mode - Create `headlessInteractiveCli.ts` with readline-based REPL runner Fixes google-gemini#13924
Author
|
Closing draft — need to address review findings before resubmitting. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--headless-interactiveCLI flag that enables headless interactive mode for programmatic consumersstdin.isTTY === falseContext
Issue #13924 requests the ability to keep the CLI alive for multi-turn sessions when launched programmatically (e.g., from Java, Node.js, or backend services). Currently,
isHeadlessMode()forces non-interactive mode when stdin is not a TTY, which reads all stdin as one prompt and exits.I investigated existing solutions:
--acp) technically provides headless interactive capabilities, but requires ndJSON protocol handshake (initialize → authenticate → newSession → prompt) and SDK dependency--prompt) supports session resumption via--resume, but each invocation is independent — no persistent processThis PR offers a lightweight alternative: a plain-text stdin/stdout interface following the same pattern as
nonInteractiveCli.ts. It's complementary to both ACP and the daemon approach — different interface for different use cases.How to Validate
Changes
packages/cli/src/config/config.ts--headless-interactiveflag,CliArgsfield, mutual exclusivity checkspackages/cli/src/gemini.tsxpackages/cli/src/headlessInteractiveCli.tsRelated Issues
Fixes #13924
Related: #15338, PR #20700
Pre-Merge Checklist