Add --project CLI flag for loading projects at startup

Adds a new --project <PATH> flag that loads project files (brief.md,
contacts.yaml, status.md) at startup, similar to the /project command
but WITHOUT auto-executing the project status prompt.

Changes:
- Add --project flag to cli_args.rs
- Add load_and_validate_project() helper in project.rs (shared by both
  --project flag and /project command)
- Modify run_interactive() to accept optional initial_project parameter
- Wire up --project in lib.rs to load project before interactive mode
- Refactor /project command to use shared helper (reduces duplication)
- Add 4 new tests for load_and_validate_project()
This commit is contained in:
Dhanji R. Prasanna
2026-01-29 11:06:08 +11:00
parent 05d253ee2a
commit 5ea43d7b39
7 changed files with 158 additions and 33 deletions

View File

@@ -45,6 +45,7 @@ use ui_writer_impl::ConsoleUiWriter;
use g3_core::ui_writer::UiWriter;
use utils::{initialize_logging, load_config_with_cli_overrides, setup_workspace_directory};
use template::process_template;
use project::load_and_validate_project;
pub async fn run() -> Result<()> {
let cli = Cli::parse();
@@ -195,6 +196,34 @@ async fn run_console_mode(
agent.set_acd_enabled(true);
}
// Load CLI project if --project flag was specified
let initial_project: Option<project::Project> = if let Some(ref project_path) = cli.project {
match load_and_validate_project(&project_path.to_string_lossy(), &workspace_dir) {
Ok(cli_project) => {
// Set project content in agent's system message
if agent.set_project_content(Some(cli_project.content.clone())) {
// Set project path on UI writer for path shortening
let project_name = cli_project.path
.file_name()
.and_then(|n| n.to_str())
.unwrap_or("project")
.to_string();
agent.ui_writer().set_project_path(cli_project.path.clone(), project_name);
Some(cli_project)
} else {
eprintln!("Warning: Failed to set project content in agent context.");
None
}
}
Err(e) => {
eprintln!("Error loading project: {}", e);
std::process::exit(1);
}
}
} else {
None
};
if cli.autonomous {
let _agent = run_autonomous(
agent,
@@ -233,6 +262,7 @@ async fn run_console_mode(
project.workspace(),
cli.new_session,
None, // agent_name (not in agent mode)
initial_project,
)
.await
}