Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions crates/goose-cli/src/commands/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ fn format_date(date: DateTime<chrono::Utc>) -> String {
///
/// Offers options to resume the most recently accessed project
pub fn handle_project_default() -> Result<()> {
let goose_bin = std::env::current_exe()
.map(|p| p.to_string_lossy().into_owned())
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve non-UTF-8 executable paths

When goose is launched from a path that contains non-UTF-8 bytes, current_exe() still returns a valid PathBuf, but to_string_lossy() replaces those bytes with U+FFFD; the later Command::new(&goose_bin) then tries to execute a different path and goose project cannot start the session. Command::new accepts the PathBuf/OsStr directly, so keeping the path in its native representation avoids breaking these installs; the same lossy value is used for all project spawns.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch is consistent with how this is done else where in the code base:
term.rs:

let goose_bin = std::env::current_exe()
    .map(|p| p.to_string_lossy().into_owned())
    .unwrap_or_else(|_| "goose".to_string());

I'm ok with solving this issue as well, but didn't want to change more than just the issue I found.

.unwrap_or_else(|_| "goose".to_string());
let tracker = ProjectTracker::load()?;
let mut projects = tracker.list_projects();

if projects.is_empty() {
// If no projects exist, just start a new one in the current directory
println!("No previous projects found. Starting a new session in the current directory.");
let mut command = std::process::Command::new("goose");
let mut command = std::process::Command::new(&goose_bin);
command.arg("session");
let status = command.status()?;

Expand Down Expand Up @@ -102,7 +105,7 @@ pub fn handle_project_default() -> Result<()> {
std::env::set_current_dir(project_dir)?;

// Build the command to run goose
let mut command = std::process::Command::new("goose");
let mut command = std::process::Command::new(&goose_bin);
command.arg("session");

if let Some(id) = session_id {
Expand All @@ -127,7 +130,7 @@ pub fn handle_project_default() -> Result<()> {
std::env::set_current_dir(project_dir)?;

// Build the command to run goose with a fresh session
let mut command = std::process::Command::new("goose");
let mut command = std::process::Command::new(&goose_bin);
command.arg("session");

// Execute the command
Expand All @@ -141,7 +144,7 @@ pub fn handle_project_default() -> Result<()> {
let _ = outro("Starting a new session in the current directory");

// Build the command to run goose
let mut command = std::process::Command::new("goose");
let mut command = std::process::Command::new(&goose_bin);
command.arg("session");

// Execute the command
Expand All @@ -163,6 +166,9 @@ pub fn handle_project_default() -> Result<()> {
///
/// Shows a list of projects and lets the user select one to resume
pub fn handle_projects_interactive() -> Result<()> {
let goose_bin = std::env::current_exe()
.map(|p| p.to_string_lossy().into_owned())
.unwrap_or_else(|_| "goose".to_string());
let tracker = ProjectTracker::load()?;
let mut projects = tracker.list_projects();

Expand Down Expand Up @@ -281,7 +287,7 @@ pub fn handle_projects_interactive() -> Result<()> {
};

// Build the command to run goose
let mut command = std::process::Command::new("goose");
let mut command = std::process::Command::new(&goose_bin);
command.arg("session");

if resume_session {
Expand Down
Loading