Skip to content

Enhancement: tab-completion for magic commands #1697

@thehighnotes

Description

@thehighnotes

Description

OI already imports readline and uses it for up-arrow history recall, but there is no tab-completion for magic commands. Users must remember the exact spelling of %save_message, %load_message, %verbose, etc. There are 12+ magic commands with no discoverability.

Suggested implementation

Add a readline completer that activates when input starts with %:

def _oi_completer(text, state):
    MAGIC_COMMANDS = [
        "%help", "%reset", "%undo", "%verbose", "%auto_run",
        "%save_message", "%load_message", "%tokens",
        "%info", "%jupyter", "%markdown", "%%",
    ]
    if text.startswith("%"):
        matches = [c for c in MAGIC_COMMANDS if c.startswith(text)]
    else:
        matches = []
    return matches[state] if state < len(matches) else None

Register in the existing readline try block in terminal_interface.py:

readline.set_completer(_oi_completer)
readline.set_completer_delims(" \t\n")
readline.parse_and_bind("tab: complete")

Behavior:

  • % + Tab → shows all magic commands
  • %re + Tab → completes to %reset
  • Non-% input → no completion (preserves default behavior)
  • Up-arrow history unaffected

Minimal change (~15 lines), no new dependencies.

Environment

  • open-interpreter 0.4.3
  • Python 3.10, Linux (readline available)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions