Add template processing to one-shot and agent modes

Template variables like {{today}} are now processed in:
- One-shot mode: g3 "task with {{today}}"
- Agent mode: g3 --agent carmack "task with {{today}}"

This completes template support across all prompt entry points:
- --include-prompt files
- /run command
- One-shot task argument
- Agent mode task argument
This commit is contained in:
Dhanji R. Prasanna
2026-01-20 21:39:43 +05:30
parent 6e8dc2e866
commit a882ac8893
2 changed files with 7 additions and 3 deletions

View File

@@ -14,6 +14,7 @@ use crate::simple_output::SimpleOutput;
use crate::embedded_agents::load_agent_prompt;
use crate::ui_writer_impl::ConsoleUiWriter;
use crate::interactive::run_interactive;
use crate::template::process_template;
/// Run agent mode - loads a specialized agent prompt and executes a single task.
pub async fn run_agent_mode(
@@ -252,7 +253,8 @@ pub async fn run_agent_mode(
"Begin your analysis and work on the current project. Follow your mission and workflow as specified in your instructions."
};
// Use provided task if available, otherwise use the default initial_task
let final_task = task.as_deref().unwrap_or(initial_task);
let task_str = task.as_deref().unwrap_or(initial_task);
let final_task = process_template(task_str);
// If chat mode is enabled, run interactive loop instead of single task
if chat {
@@ -269,7 +271,7 @@ pub async fn run_agent_mode(
}
// Single-shot mode: execute the task and exit
let _result = agent.execute_task(final_task, None, true).await?;
let _result = agent.execute_task(&final_task, None, true).await?;
// Send auto-memory reminder if enabled and tools were called
if let Err(e) = agent.send_auto_memory_reminder().await {

View File

@@ -42,6 +42,7 @@ use project_files::{combine_project_content, read_agents_config, read_include_pr
use simple_output::SimpleOutput;
use ui_writer_impl::ConsoleUiWriter;
use utils::{initialize_logging, load_config_with_cli_overrides, setup_workspace_directory};
use template::process_template;
pub async fn run() -> Result<()> {
let cli = Cli::parse();
@@ -205,9 +206,10 @@ async fn run_console_mode(
Ok(())
} else if let Some(task) = cli.task {
// Single-shot mode
let processed_task = process_template(&task);
let output = SimpleOutput::new();
let result = agent
.execute_task_with_timing(&task, None, false, cli.show_prompt, cli.show_code, true, None)
.execute_task_with_timing(&processed_task, None, false, cli.show_prompt, cli.show_code, true, None)
.await?;
// Only print response if it's not empty (streaming already displayed it)
if !result.response.trim().is_empty() {