Skip to content

feat(main): add non-interactive --ask-agent mode to the CLI#403

Open
vitali87 wants to merge 1 commit intomainfrom
pr-split/add-cmd-question/pr-6
Open

feat(main): add non-interactive --ask-agent mode to the CLI#403
vitali87 wants to merge 1 commit intomainfrom
pr-split/add-cmd-question/pr-6

Conversation

@vitali87
Copy link
Owner

@vitali87 vitali87 commented Mar 1, 2026

Add --ask-agent / -a option to the start command. When provided, runs a single query via main_async_single_query (which uses question_mode logging to stderr) and prints the result to stdout, then exits. Useful for scripting without launching the full interactive REPL.

Dependency graph

Merge in this order:

pr-1: chore: update .gitignore with popular vibe-coding agent directories
pr-2: fix(llm): add retries to RAG orchestrator to handle output validation issues
├── pr-4: feat(mcp/tools): add shell_command, document_analyzer, semantic_search, and ask_agent tools to MCP registry
│   └── pr-5: feat(mcp/client): add MCP client CLI for querying the code graph via MCP server
│       └── pr-7: docs: update README with non-interactive mode, new MCP tools, and agent tool list
└── pr-6: feat(main): add non-interactive --ask-agent mode to the CLI  <-- this PR
    └── pr-7: docs: update README with non-interactive mode, new MCP tools, and agent tool list
pr-3: feat(mcp/server): improve MCP server logging and suppress output during tool execution
└── pr-4: feat(mcp/tools): add shell_command, document_analyzer, semantic_search, and ask_agent tools to MCP registry
    └── pr-5: feat(mcp/client): add MCP client CLI for querying the code graph via MCP server
        └── pr-7: docs: update README with non-interactive mode, new MCP tools, and agent tool list

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the CLI by introducing a non-interactive mode, enabling users to execute single queries programmatically. This feature is particularly useful for scripting and automation, as it allows the agent to process a query and output the result to standard output without launching the full interactive REPL. The change includes a new CLI option, a dedicated function for single query execution, and refined logging to support this new mode.

Highlights

  • Non-interactive CLI Mode: Introduced a new --ask-agent (or -a) command-line option to enable a non-interactive mode for the CLI, allowing users to run a single query and receive its output directly to stdout before exiting.
  • Single Query Execution Function: Added a new asynchronous function, main_async_single_query, which handles the initialization of services and the execution of a single agent query in the non-interactive context.
  • Configurable Logging: Modified the common initialization logic to support a question_mode flag, which adjusts logging behavior to suppress INFO/DEBUG/WARNING messages, showing only errors and direct output to stderr, suitable for scripting.
Changelog
  • codebase_rag/main.py
    • Modified _setup_common_initialization to accept a question_mode boolean parameter, controlling the logger's output level and destination.
    • Added main_async_single_query function to handle the execution of a single agent query in a non-interactive context, printing the result to stdout.
    • Introduced --ask-agent (-a) as a new typer.Option to the start command, allowing users to specify a query for non-interactive execution.
    • Updated the start function's main execution block to conditionally call main_async_single_query if --ask-agent is provided, otherwise defaulting to the existing interactive main_async.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a non-interactive --ask-agent mode to the CLI, a valuable addition for scripting and automation. However, the current implementation lacks critical security controls, allowing the RAG agent to execute sensitive tools (like file editing and shell commands) without user confirmation, making it highly vulnerable to prompt injection. It also exposes a potential arbitrary file read vulnerability through unvalidated image path handling. The implementation is otherwise logical and correctly separates logging from the main output, though there are minor style guide suggestions regarding docstrings which are disallowed by the project's general rules. These security issues should be addressed before merging.

Comment on lines +804 to +807
response = await rag_agent.run(question_with_context, message_history=[])

# Output response to stdout
print(response.output)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-critical critical

The main_async_single_query function executes the RAG agent with user-supplied input but does not implement any confirmation logic for sensitive operations such as file modifications or shell command execution. Since the agent has access to powerful tools (shell_command_tool, file_writer_tool, etc.), an attacker can use prompt injection via the --ask-agent flag to perform unauthorized actions on the system. In non-interactive mode, the application should either block these operations by default or require an explicit override via the --no-confirm flag. Additionally, ensure that the shell_command tool is included in the EDIT_TOOLS list in config.py to be properly detected by is_edit_operation_response.

Suggested change
response = await rag_agent.run(question_with_context, message_history=[])
# Output response to stdout
print(response.output)
response = await rag_agent.run(question_with_context, message_history=[])
# Check for edit operations in non-interactive mode
if confirm_edits_globally and is_edit_operation_response(response.output):
console.print("\n[bold red]Error: The agent attempted to perform file modifications or sensitive operations in non-interactive mode. Use --no-confirm to allow these changes.[/bold red]")
return
# Output response to stdout
print(response.output)

rag_agent = _initialize_services_and_agent(repo_path, ingestor)

# Handle images in the question
question_with_context = _handle_chat_images(question, project_root)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

The main_async_single_query function passes the user-supplied question to _handle_chat_images, which identifies absolute file paths ending in image extensions and copies them to a temporary directory without any path validation. This could allow an attacker to read arbitrary files on the system if they can be tricked into having an image extension or if the agent is manipulated to read them. It is recommended to validate that any identified file paths are within the allowed project directory in the _handle_chat_images function.

Comment on lines +163 to +168
"""Common setup logic for both main and optimize functions.

Args:
repo_path: Path to the repository
question_mode: If True, suppress INFO/DEBUG/WARNING logs (only show errors and direct output)
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the project's general rules, docstrings are not allowed. Please replace this multi-line docstring with a regular comment to adhere to the project's coding standards.

    # Common setup logic for interactive, optimization, and single-query modes.
    # When question_mode is True, logs are suppressed and only errors are sent to stderr.
References
  1. Docstrings are not allowed in this project, as enforced by a pre-commit hook.

async def main_async_single_query(
repo_path: str, batch_size: int, question: str
) -> None:
"""Initializes services and runs a single query in non-interactive mode."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The project's general rules state that docstrings are not allowed. To maintain consistency with the project's standards, please replace this docstring with a regular comment.

    # Initializes services and runs a single query in non-interactive mode.
References
  1. Docstrings are not allowed in this project, as enforced by a pre-commit hook.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 1, 2026

Greptile Summary

Adds a --ask-agent / -a CLI option to run a single non-interactive query and exit, enabling scriptable usage. The implementation cleanly separates concerns by introducing a question_mode parameter that configures logging appropriately (errors to stderr, result to stdout).

Key changes:

  • Modified _setup_common_initialization() to accept a question_mode parameter that configures logger output (stderr for errors only vs stdout for all logs)
  • Added main_async_single_query() function to handle non-interactive single query execution
  • Extended start() command with --ask-agent option that branches between interactive and non-interactive modes
  • Uses print() for stdout output in non-interactive mode (appropriate for scriptable tools despite style preference for loguru)

Minor style notes:

  • Added docstrings to new and modified functions (custom instructions prefer self-documenting code without docstrings, though existing codebase has many)
  • Uses print() instead of loguru for final output (acceptable pattern for CLI tools where data goes to stdout and logs go to stderr)

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk. The changes are focused, maintain backward compatibility, and follow existing patterns.
  • Implementation is straightforward and focused. The new functionality is properly isolated from existing code, uses optional parameters for backward compatibility, and follows established patterns in the codebase. Only minor style notes about docstrings (which already exist throughout the codebase).
  • No files require special attention

Important Files Changed

Filename Overview
codebase_rag/main.py Adds non-interactive --ask-agent mode with proper logging configuration and clean stdout output for scripting. Changes are minimal, focused, and maintain backward compatibility.

Last reviewed commit: a879523

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +162 to +168
def _setup_common_initialization(repo_path: str, question_mode: bool = False) -> Path:
"""Common setup logic for both main and optimize functions.

Args:
repo_path: Path to the repository
question_mode: If True, suppress INFO/DEBUG/WARNING logs (only show errors and direct output)
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring added to existing function

Custom instructions state "No Comments or Docstrings" - code should be self-documenting. While the codebase has existing docstrings, consider whether this addition is necessary or if the code is clear without it.

Prompt To Fix With AI
This is a comment left during a code review.
Path: codebase_rag/main.py
Line: 162-168

Comment:
docstring added to existing function

Custom instructions state "No Comments or Docstrings" - code should be self-documenting. While the codebase has existing docstrings, consider whether this addition is necessary or if the code is clear without it.

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +787 to +790
async def main_async_single_query(
repo_path: str, batch_size: int, question: str
) -> None:
"""Initializes services and runs a single query in non-interactive mode."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring added to new function

Custom instructions state "No Comments or Docstrings". While the existing codebase has docstrings, consider if this one is needed or if the function name and signature are self-explanatory.

Prompt To Fix With AI
This is a comment left during a code review.
Path: codebase_rag/main.py
Line: 787-790

Comment:
docstring added to new function

Custom instructions state "No Comments or Docstrings". While the existing codebase has docstrings, consider if this one is needed or if the function name and signature are self-explanatory.

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

response = await rag_agent.run(question_with_context, message_history=[])

# Output response to stdout
print(response.output)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uses print() instead of logger

Custom instructions prefer loguru over print(). However, this is likely intentional for clean stdout output in non-interactive mode (logs go to stderr). This is a standard CLI pattern for scriptable tools.

Prompt To Fix With AI
This is a comment left during a code review.
Path: codebase_rag/main.py
Line: 807

Comment:
uses `print()` instead of logger

Custom instructions prefer `loguru` over `print()`. However, this is likely intentional for clean stdout output in non-interactive mode (logs go to stderr). This is a standard CLI pattern for scriptable tools.

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants