Add tab completion for commands and file paths

Implement tab completion in interactive mode using rustyline:

- Command completion: /<TAB> shows all commands, /com<TAB> -> /compact
- File path completion: /run <TAB> completes file/directory paths
- Supports tilde expansion for home directory

Architecture is extensible for future semantic completions:
- /resume <TAB> -> session IDs (Phase 2)
- /rehydrate <TAB> -> fragment IDs (Phase 2)

New module: completion.rs with G3Helper struct implementing
rustyline's Completer trait.
This commit is contained in:
Dhanji R. Prasanna
2026-01-20 10:57:33 +05:30
parent 4db2150386
commit dd3db0227d
5 changed files with 170 additions and 4 deletions

View File

@@ -3,7 +3,8 @@
use anyhow::Result;
use crossterm::style::{Color, ResetColor, SetForegroundColor};
use rustyline::error::ReadlineError;
use rustyline::DefaultEditor;
use rustyline::{Config, Editor};
use crate::completion::G3Helper;
use std::path::Path;
use tracing::{debug, error};
@@ -166,7 +167,11 @@ pub async fn run_interactive<W: UiWriter>(
}
// Initialize rustyline editor with history
let mut rl = DefaultEditor::new()?;
let config = Config::builder()
.completion_type(rustyline::CompletionType::List)
.build();
let mut rl = Editor::with_config(config)?;
rl.set_helper(Some(G3Helper::new()));
// Try to load history from a file in the user's home directory
let history_file = dirs::home_dir().map(|mut path| {
@@ -334,7 +339,7 @@ async fn handle_command<W: UiWriter>(
input: &str,
agent: &mut Agent<W>,
output: &SimpleOutput,
rl: &mut DefaultEditor,
rl: &mut Editor<G3Helper, rustyline::history::DefaultHistory>,
show_prompt: bool,
show_code: bool,
) -> Result<bool> {