Add --new-session flag to skip session resumption in agent mode
Adds a new CLI flag that allows users to force a new session when running in agent mode, bypassing the automatic detection and resumption of incomplete sessions. Usage: g3 --agent my-agent --new-session
This commit is contained in:
@@ -392,6 +392,10 @@ pub struct Cli {
|
|||||||
/// Run as a specialized agent (loads prompt from agents/<name>.md)
|
/// Run as a specialized agent (loads prompt from agents/<name>.md)
|
||||||
#[arg(long, value_name = "NAME", conflicts_with_all = ["autonomous", "auto", "chat", "planning"])]
|
#[arg(long, value_name = "NAME", conflicts_with_all = ["autonomous", "auto", "chat", "planning"])]
|
||||||
pub agent: Option<String>,
|
pub agent: Option<String>,
|
||||||
|
|
||||||
|
/// Skip session resumption and force a new session (for agent mode)
|
||||||
|
#[arg(long)]
|
||||||
|
pub new_session: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run() -> Result<()> {
|
pub async fn run() -> Result<()> {
|
||||||
@@ -437,6 +441,7 @@ pub async fn run() -> Result<()> {
|
|||||||
cli.workspace.clone(),
|
cli.workspace.clone(),
|
||||||
cli.config.as_deref(),
|
cli.config.as_deref(),
|
||||||
cli.quiet,
|
cli.quiet,
|
||||||
|
cli.new_session,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
@@ -448,6 +453,7 @@ pub async fn run() -> Result<()> {
|
|||||||
cli.workspace.clone(),
|
cli.workspace.clone(),
|
||||||
cli.config.as_deref(),
|
cli.config.as_deref(),
|
||||||
cli.quiet,
|
cli.quiet,
|
||||||
|
cli.new_session,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
@@ -655,6 +661,7 @@ async fn run_agent_mode(
|
|||||||
workspace: Option<PathBuf>,
|
workspace: Option<PathBuf>,
|
||||||
config_path: Option<&str>,
|
config_path: Option<&str>,
|
||||||
_quiet: bool,
|
_quiet: bool,
|
||||||
|
new_session: bool,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
use g3_core::get_agent_system_prompt;
|
use g3_core::get_agent_system_prompt;
|
||||||
use g3_core::find_incomplete_agent_session;
|
use g3_core::find_incomplete_agent_session;
|
||||||
@@ -679,8 +686,14 @@ async fn run_agent_mode(
|
|||||||
// Change to the workspace directory first so session scanning works correctly
|
// Change to the workspace directory first so session scanning works correctly
|
||||||
std::env::set_current_dir(&workspace_dir)?;
|
std::env::set_current_dir(&workspace_dir)?;
|
||||||
|
|
||||||
// Check for incomplete agent sessions before starting a new one
|
// Check for incomplete agent sessions before starting a new one (unless --new-session is set)
|
||||||
let resuming_session = find_incomplete_agent_session(agent_name).ok().flatten();
|
let resuming_session = if new_session {
|
||||||
|
output.print("\n🆕 Starting new session (--new-session flag set)");
|
||||||
|
output.print("");
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
find_incomplete_agent_session(agent_name).ok().flatten()
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(ref incomplete_session) = resuming_session {
|
if let Some(ref incomplete_session) = resuming_session {
|
||||||
output.print(&format!(
|
output.print(&format!(
|
||||||
|
|||||||
Reference in New Issue
Block a user