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:
@@ -14,6 +14,7 @@ use crate::simple_output::SimpleOutput;
|
|||||||
use crate::embedded_agents::load_agent_prompt;
|
use crate::embedded_agents::load_agent_prompt;
|
||||||
use crate::ui_writer_impl::ConsoleUiWriter;
|
use crate::ui_writer_impl::ConsoleUiWriter;
|
||||||
use crate::interactive::run_interactive;
|
use crate::interactive::run_interactive;
|
||||||
|
use crate::template::process_template;
|
||||||
|
|
||||||
/// Run agent mode - loads a specialized agent prompt and executes a single task.
|
/// Run agent mode - loads a specialized agent prompt and executes a single task.
|
||||||
pub async fn run_agent_mode(
|
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."
|
"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
|
// 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 mode is enabled, run interactive loop instead of single task
|
||||||
if chat {
|
if chat {
|
||||||
@@ -269,7 +271,7 @@ pub async fn run_agent_mode(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Single-shot mode: execute the task and exit
|
// 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
|
// Send auto-memory reminder if enabled and tools were called
|
||||||
if let Err(e) = agent.send_auto_memory_reminder().await {
|
if let Err(e) = agent.send_auto_memory_reminder().await {
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ use project_files::{combine_project_content, read_agents_config, read_include_pr
|
|||||||
use simple_output::SimpleOutput;
|
use simple_output::SimpleOutput;
|
||||||
use ui_writer_impl::ConsoleUiWriter;
|
use ui_writer_impl::ConsoleUiWriter;
|
||||||
use utils::{initialize_logging, load_config_with_cli_overrides, setup_workspace_directory};
|
use utils::{initialize_logging, load_config_with_cli_overrides, setup_workspace_directory};
|
||||||
|
use template::process_template;
|
||||||
|
|
||||||
pub async fn run() -> Result<()> {
|
pub async fn run() -> Result<()> {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
@@ -205,9 +206,10 @@ async fn run_console_mode(
|
|||||||
Ok(())
|
Ok(())
|
||||||
} else if let Some(task) = cli.task {
|
} else if let Some(task) = cli.task {
|
||||||
// Single-shot mode
|
// Single-shot mode
|
||||||
|
let processed_task = process_template(&task);
|
||||||
let output = SimpleOutput::new();
|
let output = SimpleOutput::new();
|
||||||
let result = agent
|
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?;
|
.await?;
|
||||||
// Only print response if it's not empty (streaming already displayed it)
|
// Only print response if it's not empty (streaming already displayed it)
|
||||||
if !result.response.trim().is_empty() {
|
if !result.response.trim().is_empty() {
|
||||||
|
|||||||
Reference in New Issue
Block a user