Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(REPL): poc for heroku REPL and prompt mode #3176

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

justinwilaby
Copy link
Contributor

@justinwilaby justinwilaby commented Jan 14, 2025

Heroku CLI REPL and Prompt Mode

This PR introduces two new interaction modes for the Heroku CLI:

  1. REPL (Read-Eval-Print Loop) Mode
  2. Prompt Mode

Overview

REPL Mode

A new interactive shell experience that allows users to execute Heroku CLI commands continuously without needing to prefix each command with heroku. This mode maintains command history and supports tab completion for commands, flags, and common Heroku resources (apps, teams, spaces, etc.). Execution time for each command improves by up to 500% when using REPL.

Prompt Mode

An interactive prompt mode that guides users through command execution by asking for required and optional inputs in a structured manner. This is particularly helpful for complex commands or when users are unsure about available options.

Testing Instructions

Testing REPL Mode

  1. Start the REPL:

    heroku
    # OR
    ./bin/run
  2. Try basic commands:

    heroku > apps
    heroku > apps:info
  3. Test tab completion:

    • Type app and press TAB to see available app-related commands
    • Use --app followed by TAB to see your available apps
    • Try teams: followed by TAB to see team-related commands
  4. Test command history:

    • Use UP/DOWN arrows to navigate through previous commands
    • Type history to see command history
  5. Test persistent settings:

    heroku > set app my-app-name
    # Notice prompt changes to: my-app-name >
    heroku > unset app
    # Prompt returns to: heroku >

Testing Prompt Mode

  1. Test with app creation:

    heroku apps:create --prompt
    • Follow the prompts for required inputs (name, if specified)
    • Respond to optional inputs (region, team)
  2. Test with add-ons:

    heroku addons:create --prompt
    • Follow prompts for addon service selection
    • Input addon plan
    • Specify target app
  3. Test with pipeline operations:

    heroku pipelines:create --prompt
    • Follow prompts for pipeline name
    • Select staging app
    • Choose production app

MCP Mode

The CLI supports a special Model Context Protocol (MCP) mode that can be enabled by setting the HEROKU_MCP_MODE=true environment variable. This mode modifies the output format to be more LLM-friendly:

Testing MCP Mode

  1. Enable MCP mode:

    export HEROKU_MCP_MODE=true
    heroku
  2. Execute commands in the REPL:

    heroku > apps:list

    Output will be wrapped with special markers:

    <<<BEGIN RESULTS>>>
    [command output here]
    <<<END RESULTS>>>
    
  3. Error handling:
    When errors occur, they are wrapped in error markers:

    <<<ERROR>>>
    [error message]
    <<<END ERROR>>>
    

MCP Mode Features

  • Structured output markers for easy parsing
  • Disabled tab completion to prevent noise in output
  • Consistent error formatting
  • Ideal for LLMs or programmatic CLI interaction

Key Features

  • Command history persistence between sessions
  • Intelligent tab completion for:
    • Commands and subcommands
    • App names
    • Team names
    • Space names
    • Add-on names
    • Common flag values
  • Session state management (via set and unset commands)
  • Interactive prompt mode for guided command execution

Notes

  • REPL history is stored in ~/.heroku_repl_history
  • REPL state is stored in ~/.heroku_repl_state
  • Tab completion is context-aware and filters based on user access
  • Prompt mode prioritizes required inputs before optional ones

Future Considerations

  • Add support for command aliases in REPL mode
  • Enhance tab completion with more resource types
  • Add support for multi-line command input

@justinwilaby justinwilaby requested a review from a team as a code owner January 14, 2025 20:42
@ekozilforce
Copy link

This looks really 🔥 . I like how this takes advantage of oclif metadata to deliver value without plugin development overhead.

I'm interested in learning how we can iterate on this to allow flexibility for plugin developers to provide their own prompt behavior. If this project goes down that path, I'd love to be an internal tester using our data plugins. 🤙 when the time comes

@sbosio sbosio self-requested a review January 29, 2025 20:11
@justinwilaby justinwilaby force-pushed the feature/interactive-prompt branch from 4a8f384 to c3e72a4 Compare January 29, 2025 22:48
@justinwilaby justinwilaby requested a review from a team as a code owner January 29, 2025 22:48
@justinwilaby justinwilaby force-pushed the feature/interactive-prompt branch from c3c00b6 to eb8e5f6 Compare January 30, 2025 13:37
@justinwilaby justinwilaby force-pushed the feature/interactive-prompt branch from 000fcb1 to 388a1ae Compare March 31, 2025 15:11
@justinwilaby justinwilaby force-pushed the feature/interactive-prompt branch from 388a1ae to 9d01de9 Compare April 1, 2025 18:19
@sbosio sbosio temporarily deployed to AcceptanceTests April 10, 2025 15:07 — with GitHub Actions Inactive
@sbosio sbosio temporarily deployed to AcceptanceTests April 10, 2025 15:07 — with GitHub Actions Inactive
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.

4 participants