Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions crates/goose/src/recipe/read_recipe_file_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,25 @@ pub fn read_recipe_file<P: AsRef<Path>>(recipe_path: P) -> Result<RecipeFile> {

fn convert_path_with_tilde_expansion(path: &Path) -> PathBuf {
if let Some(path_str) = path.to_str() {
// Handle exact "~" (Windows only to avoid changing behavior on Unix)
if cfg!(windows) && path_str == "~" {
if let Some(home_dir) = dirs::home_dir() {
return home_dir;
}
}
// Handle Unix-style "~/..."
if let Some(stripped) = path_str.strip_prefix("~/") {
if let Some(home_dir) = dirs::home_dir() {
return home_dir.join(stripped);
}
}
// Handle Windows-style "~\\..." (Windows only)
#[cfg(windows)]
if let Some(stripped) = path_str.strip_prefix("~\\") {
if let Some(home_dir) = dirs::home_dir() {
return home_dir.join(stripped);
}
}
}
PathBuf::from(path)
}
57 changes: 32 additions & 25 deletions ui/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1581,37 +1581,44 @@ ipcMain.handle('get-binary-path', (_event, binaryName) => {
return getBinaryPath(app, binaryName);
});

ipcMain.handle('read-file', (_event, filePath) => {
return new Promise((resolve) => {
// Expand tilde to home directory
ipcMain.handle('read-file', async (_event, filePath) => {
try {
const expandedPath = expandTilde(filePath);
if (process.platform === 'win32') {
const buffer = await fs.readFile(expandedPath);
return { file: buffer.toString('utf8'), filePath: expandedPath, error: null, found: true };
}
// Non-Windows: keep previous behavior via cat for parity
return await new Promise((resolve) => {
const cat = spawn('cat', [expandedPath]);
let output = '';
let errorOutput = '';

const cat = spawn('cat', [expandedPath]);
let output = '';
let errorOutput = '';

cat.stdout.on('data', (data) => {
output += data.toString();
});
cat.stdout.on('data', (data) => {
output += data.toString();
});

cat.stderr.on('data', (data) => {
errorOutput += data.toString();
});
cat.stderr.on('data', (data) => {
errorOutput += data.toString();
});

cat.on('close', (code) => {
if (code !== 0) {
// File not found or error
resolve({ file: '', filePath: expandedPath, error: errorOutput || null, found: false });
return;
}
resolve({ file: output, filePath: expandedPath, error: null, found: true });
});
cat.on('close', (code) => {
if (code !== 0) {
resolve({ file: '', filePath: expandedPath, error: errorOutput || null, found: false });
return;
}
resolve({ file: output, filePath: expandedPath, error: null, found: true });
});

cat.on('error', (error) => {
console.error('Error reading file:', error);
resolve({ file: '', filePath: expandedPath, error, found: false });
cat.on('error', (error) => {
console.error('Error reading file:', error);
resolve({ file: '', filePath: expandedPath, error, found: false });
});
});
});
} catch (error) {
console.error('Error reading file:', error);
return { file: '', filePath: expandTilde(filePath), error, found: false };
}
});

ipcMain.handle('write-file', async (_event, filePath, content) => {
Expand Down
11 changes: 11 additions & 0 deletions ui/desktop/src/utils/pathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,18 @@ const addPaths = (
* @returns The expanded path with tilde replaced by home directory
*/
export function expandTilde(filePath: string): string {
if (!filePath || typeof filePath !== 'string') return filePath;
// Support "~", "~/..." and "~\\..." on Windows
if (filePath === '~') {
return os.homedir();
}
if (filePath.startsWith('~/') || (process.platform === 'win32' && filePath.startsWith('~\\'))) {
// Remove the leading "~" and any separator that follows, then join
const remainder = filePath.slice(2);
return path.join(os.homedir(), remainder);
}
if (filePath.startsWith('~')) {
// Generic fallback: replace only the first leading tilde
return path.join(os.homedir(), filePath.slice(1));
}
return filePath;
Expand Down
Loading