generated from nhcarrigan/template
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
ee201d71c8
|
|||
|
d712bccb91
|
+1
-1
@@ -89,6 +89,6 @@
|
||||
"typescript": "~5.6.2",
|
||||
"typescript-eslint": "^8.53.0",
|
||||
"vite": "^6.0.3",
|
||||
"vitest": "4.0.18"
|
||||
"vitest": "^4.0.17"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+57
-42
@@ -146,10 +146,10 @@ importers:
|
||||
version: 6.9.1
|
||||
'@testing-library/svelte':
|
||||
specifier: ^5.3.1
|
||||
version: 5.3.1(svelte@5.46.3)(vite@6.4.1(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.18(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2))
|
||||
version: 5.3.1(svelte@5.46.3)(vite@6.4.1(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.17(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2))
|
||||
'@vitest/coverage-v8':
|
||||
specifier: ^4.0.18
|
||||
version: 4.0.18(vitest@4.0.18(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2))
|
||||
version: 4.0.18(vitest@4.0.17(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2))
|
||||
eslint:
|
||||
specifier: ^9.39.2
|
||||
version: 9.39.2(jiti@2.6.1)
|
||||
@@ -190,8 +190,8 @@ importers:
|
||||
specifier: ^6.0.3
|
||||
version: 6.4.1(jiti@2.6.1)(lightningcss@1.30.2)
|
||||
vitest:
|
||||
specifier: 4.0.18
|
||||
version: 4.0.18(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2)
|
||||
specifier: ^4.0.17
|
||||
version: 4.0.17(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2)
|
||||
|
||||
packages:
|
||||
|
||||
@@ -1117,11 +1117,11 @@ packages:
|
||||
'@vitest/browser':
|
||||
optional: true
|
||||
|
||||
'@vitest/expect@4.0.18':
|
||||
resolution: {integrity: sha512-8sCWUyckXXYvx4opfzVY03EOiYVxyNrHS5QxX3DAIi5dpJAAkyJezHCP77VMX4HKA2LDT/Jpfo8i2r5BE3GnQQ==}
|
||||
'@vitest/expect@4.0.17':
|
||||
resolution: {integrity: sha512-mEoqP3RqhKlbmUmntNDDCJeTDavDR+fVYkSOw8qRwJFaW/0/5zA9zFeTrHqNtcmwh6j26yMmwx2PqUDPzt5ZAQ==}
|
||||
|
||||
'@vitest/mocker@4.0.18':
|
||||
resolution: {integrity: sha512-HhVd0MDnzzsgevnOWCBj5Otnzobjy5wLBe4EdeeFGv8luMsGcYqDuFRMcttKWZA5vVO8RFjexVovXvAM4JoJDQ==}
|
||||
'@vitest/mocker@4.0.17':
|
||||
resolution: {integrity: sha512-+ZtQhLA3lDh1tI2wxe3yMsGzbp7uuJSWBM1iTIKCbppWTSBN09PUC+L+fyNlQApQoR+Ps8twt2pbSSXg2fQVEQ==}
|
||||
peerDependencies:
|
||||
msw: ^2.4.9
|
||||
vite: ^6.0.0 || ^7.0.0-0
|
||||
@@ -1131,17 +1131,23 @@ packages:
|
||||
vite:
|
||||
optional: true
|
||||
|
||||
'@vitest/pretty-format@4.0.17':
|
||||
resolution: {integrity: sha512-Ah3VAYmjcEdHg6+MwFE17qyLqBHZ+ni2ScKCiW2XrlSBV4H3Z7vYfPfz7CWQ33gyu76oc0Ai36+kgLU3rfF4nw==}
|
||||
|
||||
'@vitest/pretty-format@4.0.18':
|
||||
resolution: {integrity: sha512-P24GK3GulZWC5tz87ux0m8OADrQIUVDPIjjj65vBXYG17ZeU3qD7r+MNZ1RNv4l8CGU2vtTRqixrOi9fYk/yKw==}
|
||||
|
||||
'@vitest/runner@4.0.18':
|
||||
resolution: {integrity: sha512-rpk9y12PGa22Jg6g5M3UVVnTS7+zycIGk9ZNGN+m6tZHKQb7jrP7/77WfZy13Y/EUDd52NDsLRQhYKtv7XfPQw==}
|
||||
'@vitest/runner@4.0.17':
|
||||
resolution: {integrity: sha512-JmuQyf8aMWoo/LmNFppdpkfRVHJcsgzkbCA+/Bk7VfNH7RE6Ut2qxegeyx2j3ojtJtKIbIGy3h+KxGfYfk28YQ==}
|
||||
|
||||
'@vitest/snapshot@4.0.18':
|
||||
resolution: {integrity: sha512-PCiV0rcl7jKQjbgYqjtakly6T1uwv/5BQ9SwBLekVg/EaYeQFPiXcgrC2Y7vDMA8dM1SUEAEV82kgSQIlXNMvA==}
|
||||
'@vitest/snapshot@4.0.17':
|
||||
resolution: {integrity: sha512-npPelD7oyL+YQM2gbIYvlavlMVWUfNNGZPcu0aEUQXt7FXTuqhmgiYupPnAanhKvyP6Srs2pIbWo30K0RbDtRQ==}
|
||||
|
||||
'@vitest/spy@4.0.18':
|
||||
resolution: {integrity: sha512-cbQt3PTSD7P2OARdVW3qWER5EGq7PHlvE+QfzSC0lbwO+xnt7+XH06ZzFjFRgzUX//JmpxrCu92VdwvEPlWSNw==}
|
||||
'@vitest/spy@4.0.17':
|
||||
resolution: {integrity: sha512-I1bQo8QaP6tZlTomQNWKJE6ym4SHf3oLS7ceNjozxxgzavRAgZDc06T7kD8gb9bXKEgcLNt00Z+kZO6KaJ62Ew==}
|
||||
|
||||
'@vitest/utils@4.0.17':
|
||||
resolution: {integrity: sha512-RG6iy+IzQpa9SB8HAFHJ9Y+pTzI+h8553MrciN9eC6TFBErqrQaTas4vG+MVj8S4uKk8uTT2p0vgZPnTdxd96w==}
|
||||
|
||||
'@vitest/utils@4.0.18':
|
||||
resolution: {integrity: sha512-msMRKLMVLWygpK3u2Hybgi4MNjcYJvwTb0Ru09+fOyCXIgT5raYP041DRRdiJiI3k/2U6SEbAETB3YtBrUkCFA==}
|
||||
@@ -2030,18 +2036,18 @@ packages:
|
||||
vite:
|
||||
optional: true
|
||||
|
||||
vitest@4.0.18:
|
||||
resolution: {integrity: sha512-hOQuK7h0FGKgBAas7v0mSAsnvrIgAvWmRFjmzpJ7SwFHH3g1k2u37JtYwOwmEKhK6ZO3v9ggDBBm0La1LCK4uQ==}
|
||||
vitest@4.0.17:
|
||||
resolution: {integrity: sha512-FQMeF0DJdWY0iOnbv466n/0BudNdKj1l5jYgl5JVTwjSsZSlqyXFt/9+1sEyhR6CLowbZpV7O1sCHrzBhucKKg==}
|
||||
engines: {node: ^20.0.0 || ^22.0.0 || >=24.0.0}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
'@edge-runtime/vm': '*'
|
||||
'@opentelemetry/api': ^1.9.0
|
||||
'@types/node': ^20.0.0 || ^22.0.0 || >=24.0.0
|
||||
'@vitest/browser-playwright': 4.0.18
|
||||
'@vitest/browser-preview': 4.0.18
|
||||
'@vitest/browser-webdriverio': 4.0.18
|
||||
'@vitest/ui': 4.0.18
|
||||
'@vitest/browser-playwright': 4.0.17
|
||||
'@vitest/browser-preview': 4.0.17
|
||||
'@vitest/browser-webdriverio': 4.0.17
|
||||
'@vitest/ui': 4.0.17
|
||||
happy-dom: '*'
|
||||
jsdom: '*'
|
||||
peerDependenciesMeta:
|
||||
@@ -2960,14 +2966,14 @@ snapshots:
|
||||
dependencies:
|
||||
svelte: 5.46.3
|
||||
|
||||
'@testing-library/svelte@5.3.1(svelte@5.46.3)(vite@6.4.1(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.18(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2))':
|
||||
'@testing-library/svelte@5.3.1(svelte@5.46.3)(vite@6.4.1(jiti@2.6.1)(lightningcss@1.30.2))(vitest@4.0.17(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2))':
|
||||
dependencies:
|
||||
'@testing-library/dom': 10.4.1
|
||||
'@testing-library/svelte-core': 1.0.0(svelte@5.46.3)
|
||||
svelte: 5.46.3
|
||||
optionalDependencies:
|
||||
vite: 6.4.1(jiti@2.6.1)(lightningcss@1.30.2)
|
||||
vitest: 4.0.18(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2)
|
||||
vitest: 4.0.17(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2)
|
||||
|
||||
'@types/aria-query@5.0.4': {}
|
||||
|
||||
@@ -3075,7 +3081,7 @@ snapshots:
|
||||
'@typescript-eslint/types': 8.53.0
|
||||
eslint-visitor-keys: 4.2.1
|
||||
|
||||
'@vitest/coverage-v8@4.0.18(vitest@4.0.18(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2))':
|
||||
'@vitest/coverage-v8@4.0.18(vitest@4.0.17(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2))':
|
||||
dependencies:
|
||||
'@bcoe/v8-coverage': 1.0.2
|
||||
'@vitest/utils': 4.0.18
|
||||
@@ -3087,41 +3093,50 @@ snapshots:
|
||||
obug: 2.1.1
|
||||
std-env: 3.10.0
|
||||
tinyrainbow: 3.0.3
|
||||
vitest: 4.0.18(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2)
|
||||
vitest: 4.0.17(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2)
|
||||
|
||||
'@vitest/expect@4.0.18':
|
||||
'@vitest/expect@4.0.17':
|
||||
dependencies:
|
||||
'@standard-schema/spec': 1.1.0
|
||||
'@types/chai': 5.2.3
|
||||
'@vitest/spy': 4.0.18
|
||||
'@vitest/utils': 4.0.18
|
||||
'@vitest/spy': 4.0.17
|
||||
'@vitest/utils': 4.0.17
|
||||
chai: 6.2.2
|
||||
tinyrainbow: 3.0.3
|
||||
|
||||
'@vitest/mocker@4.0.18(vite@6.4.1(jiti@2.6.1)(lightningcss@1.30.2))':
|
||||
'@vitest/mocker@4.0.17(vite@6.4.1(jiti@2.6.1)(lightningcss@1.30.2))':
|
||||
dependencies:
|
||||
'@vitest/spy': 4.0.18
|
||||
'@vitest/spy': 4.0.17
|
||||
estree-walker: 3.0.3
|
||||
magic-string: 0.30.21
|
||||
optionalDependencies:
|
||||
vite: 6.4.1(jiti@2.6.1)(lightningcss@1.30.2)
|
||||
|
||||
'@vitest/pretty-format@4.0.17':
|
||||
dependencies:
|
||||
tinyrainbow: 3.0.3
|
||||
|
||||
'@vitest/pretty-format@4.0.18':
|
||||
dependencies:
|
||||
tinyrainbow: 3.0.3
|
||||
|
||||
'@vitest/runner@4.0.18':
|
||||
'@vitest/runner@4.0.17':
|
||||
dependencies:
|
||||
'@vitest/utils': 4.0.18
|
||||
'@vitest/utils': 4.0.17
|
||||
pathe: 2.0.3
|
||||
|
||||
'@vitest/snapshot@4.0.18':
|
||||
'@vitest/snapshot@4.0.17':
|
||||
dependencies:
|
||||
'@vitest/pretty-format': 4.0.18
|
||||
'@vitest/pretty-format': 4.0.17
|
||||
magic-string: 0.30.21
|
||||
pathe: 2.0.3
|
||||
|
||||
'@vitest/spy@4.0.18': {}
|
||||
'@vitest/spy@4.0.17': {}
|
||||
|
||||
'@vitest/utils@4.0.17':
|
||||
dependencies:
|
||||
'@vitest/pretty-format': 4.0.17
|
||||
tinyrainbow: 3.0.3
|
||||
|
||||
'@vitest/utils@4.0.18':
|
||||
dependencies:
|
||||
@@ -3961,15 +3976,15 @@ snapshots:
|
||||
optionalDependencies:
|
||||
vite: 6.4.1(jiti@2.6.1)(lightningcss@1.30.2)
|
||||
|
||||
vitest@4.0.18(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2):
|
||||
vitest@4.0.17(jiti@2.6.1)(jsdom@27.4.0)(lightningcss@1.30.2):
|
||||
dependencies:
|
||||
'@vitest/expect': 4.0.18
|
||||
'@vitest/mocker': 4.0.18(vite@6.4.1(jiti@2.6.1)(lightningcss@1.30.2))
|
||||
'@vitest/pretty-format': 4.0.18
|
||||
'@vitest/runner': 4.0.18
|
||||
'@vitest/snapshot': 4.0.18
|
||||
'@vitest/spy': 4.0.18
|
||||
'@vitest/utils': 4.0.18
|
||||
'@vitest/expect': 4.0.17
|
||||
'@vitest/mocker': 4.0.17(vite@6.4.1(jiti@2.6.1)(lightningcss@1.30.2))
|
||||
'@vitest/pretty-format': 4.0.17
|
||||
'@vitest/runner': 4.0.17
|
||||
'@vitest/snapshot': 4.0.17
|
||||
'@vitest/spy': 4.0.17
|
||||
'@vitest/utils': 4.0.17
|
||||
es-module-lexer: 1.7.0
|
||||
expect-type: 1.3.0
|
||||
magic-string: 0.30.21
|
||||
|
||||
@@ -8,6 +8,7 @@ use crate::bridge_manager::SharedBridgeManager;
|
||||
use crate::config::{ClaudeStartOptions, HikariConfig};
|
||||
use crate::stats::UsageStats;
|
||||
use crate::temp_manager::SharedTempFileManager;
|
||||
use crate::utils::normalize_path_separators;
|
||||
|
||||
const CONFIG_STORE_KEY: &str = "config";
|
||||
|
||||
@@ -126,7 +127,7 @@ pub async fn validate_directory(
|
||||
|
||||
// Expand ~ to home directory
|
||||
let expanded_path = if path.starts_with("~") {
|
||||
if let Some(home) = std::env::var_os("HOME") {
|
||||
if let Some(home) = std::env::var_os("HOME").or_else(|| std::env::var_os("USERPROFILE")) {
|
||||
let home_path = Path::new(&home);
|
||||
if path == Path::new("~") {
|
||||
home_path.to_path_buf()
|
||||
@@ -162,10 +163,10 @@ pub async fn validate_directory(
|
||||
));
|
||||
}
|
||||
|
||||
// Return the canonicalized (absolute) path
|
||||
// Return the canonicalized (absolute) path with forward slashes
|
||||
expanded_path
|
||||
.canonicalize()
|
||||
.map(|p| p.to_string_lossy().to_string())
|
||||
.map(|p| normalize_path_separators(&p.to_string_lossy()))
|
||||
.map_err(|e| format!("Failed to resolve path: {}", e))
|
||||
}
|
||||
|
||||
@@ -205,9 +206,10 @@ pub async fn list_skills() -> Result<Vec<String>, String> {
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
// Get the home directory
|
||||
let home =
|
||||
std::env::var_os("HOME").ok_or_else(|| "Could not determine home directory".to_string())?;
|
||||
// Get the home directory - use HOME on Unix, USERPROFILE on Windows
|
||||
let home = std::env::var_os("HOME")
|
||||
.or_else(|| std::env::var_os("USERPROFILE"))
|
||||
.ok_or_else(|| "Could not determine home directory".to_string())?;
|
||||
|
||||
let skills_dir = Path::new(&home).join(".claude").join("skills");
|
||||
|
||||
@@ -437,9 +439,11 @@ pub async fn list_directory(path: String) -> Result<Vec<FileEntry>, String> {
|
||||
continue;
|
||||
}
|
||||
|
||||
let path_str = normalize_path_separators(&path.to_string_lossy());
|
||||
|
||||
file_entries.push(FileEntry {
|
||||
name,
|
||||
path: path.to_string_lossy().to_string(),
|
||||
path: path_str,
|
||||
is_directory: path.is_dir(),
|
||||
});
|
||||
}
|
||||
@@ -814,4 +818,25 @@ mod tests {
|
||||
assert!(json.contains("/tmp/test.txt"));
|
||||
assert!(json.contains("test.txt"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_validate_directory_normalizes_backslashes() {
|
||||
// This test ensures that paths with backslashes are normalized
|
||||
// Create a temp directory for testing
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
|
||||
// On Windows, the canonicalized path will have backslashes
|
||||
// Our normalize_path_separators should convert them to forward slashes
|
||||
let result = run_async(validate_directory(
|
||||
temp_dir.path().to_string_lossy().to_string(),
|
||||
None,
|
||||
));
|
||||
|
||||
assert!(result.is_ok());
|
||||
let normalized_path = result.unwrap();
|
||||
|
||||
// The result should never contain backslashes
|
||||
assert!(!normalized_path.contains('\\'),
|
||||
"Path should not contain backslashes: {}", normalized_path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ mod stats;
|
||||
mod temp_manager;
|
||||
mod tray;
|
||||
mod types;
|
||||
mod utils;
|
||||
mod vbs_notification;
|
||||
mod windows_toast;
|
||||
mod wsl_bridge;
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/// Utility functions for cross-platform compatibility
|
||||
|
||||
/// Normalize path separators to forward slashes for consistent handling across platforms
|
||||
/// This always normalizes backslashes to forward slashes, regardless of platform,
|
||||
/// because Windows paths may be passed to WSL which expects Unix-style paths
|
||||
pub fn normalize_path_separators(path: &str) -> String {
|
||||
path.replace('\\', "/")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "windows")]
|
||||
fn test_normalize_path_windows() {
|
||||
assert_eq!(normalize_path_separators("C:\\Users\\test"), "C:/Users/test");
|
||||
assert_eq!(normalize_path_separators("path\\to\\file"), "path/to/file");
|
||||
assert_eq!(normalize_path_separators("already/forward"), "already/forward");
|
||||
assert_eq!(normalize_path_separators("mixed\\path/file"), "mixed/path/file");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
fn test_normalize_path_unix() {
|
||||
assert_eq!(normalize_path_separators("/home/user"), "/home/user");
|
||||
assert_eq!(normalize_path_separators("path/to/file"), "path/to/file");
|
||||
// Even on Unix, we normalize backslashes since paths may come from Windows
|
||||
assert_eq!(normalize_path_separators("weird\\path"), "weird/path");
|
||||
assert_eq!(normalize_path_separators("/home/user\\file"), "/home/user/file");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_normalize_wsl_paths() {
|
||||
// Test the exact issue that was happening
|
||||
assert_eq!(
|
||||
normalize_path_separators("/home/naomi/code/naomi/portfolio\\.."),
|
||||
"/home/naomi/code/naomi/portfolio/.."
|
||||
);
|
||||
|
||||
// Test mixed separators in WSL paths
|
||||
assert_eq!(
|
||||
normalize_path_separators("/mnt/c\\Users\\naomi\\Documents"),
|
||||
"/mnt/c/Users/naomi/Documents"
|
||||
);
|
||||
|
||||
// Test Windows paths that might be passed to WSL
|
||||
assert_eq!(
|
||||
normalize_path_separators("C:\\Users\\naomi\\.claude\\skills"),
|
||||
"C:/Users/naomi/.claude/skills"
|
||||
);
|
||||
|
||||
// Test that forward slashes remain unchanged
|
||||
assert_eq!(
|
||||
normalize_path_separators("/home/naomi/.claude/skills"),
|
||||
"/home/naomi/.claude/skills"
|
||||
);
|
||||
|
||||
// Test empty string
|
||||
assert_eq!(normalize_path_separators(""), "");
|
||||
|
||||
// Test single backslash
|
||||
assert_eq!(normalize_path_separators("\\"), "/");
|
||||
|
||||
// Test multiple consecutive backslashes
|
||||
assert_eq!(
|
||||
normalize_path_separators("path\\\\to\\\\file"),
|
||||
"path//to//file"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ use crate::types::{
|
||||
PermissionPromptEvent, QuestionOption, SessionEvent, StateChangeEvent, UserQuestionEvent,
|
||||
WorkingDirectoryEvent,
|
||||
};
|
||||
use crate::utils::normalize_path_separators;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
const SEARCH_TOOLS: [&str; 5] = ["Read", "Glob", "Grep", "WebSearch", "WebFetch"];
|
||||
@@ -136,7 +137,8 @@ impl WslBridge {
|
||||
});
|
||||
|
||||
let working_dir = &options.working_dir;
|
||||
self.working_directory = working_dir.clone();
|
||||
// Normalize path separators to forward slashes
|
||||
self.working_directory = normalize_path_separators(working_dir);
|
||||
|
||||
emit_connection_status(
|
||||
&app,
|
||||
@@ -183,7 +185,7 @@ impl WslBridge {
|
||||
})?;
|
||||
|
||||
eprintln!("[DEBUG] Found claude at: {}", claude_path);
|
||||
eprintln!("[DEBUG] Working dir: {}", working_dir);
|
||||
eprintln!("[DEBUG] Working dir: {}", &self.working_directory);
|
||||
|
||||
let mut cmd = Command::new(&claude_path);
|
||||
cmd.args([
|
||||
@@ -225,7 +227,7 @@ impl WslBridge {
|
||||
}
|
||||
}
|
||||
|
||||
cmd.current_dir(working_dir);
|
||||
cmd.current_dir(&self.working_directory);
|
||||
|
||||
// Set API key as environment variable if specified
|
||||
if let Some(ref api_key) = options.api_key {
|
||||
@@ -241,7 +243,7 @@ impl WslBridge {
|
||||
let mut cmd = Command::new("wsl");
|
||||
|
||||
// Build the claude command with all arguments
|
||||
let mut claude_cmd = format!("cd '{}' && ", working_dir);
|
||||
let mut claude_cmd = format!("cd '{}' && ", &self.working_directory);
|
||||
|
||||
// Set API key as environment variable if specified
|
||||
if let Some(ref api_key) = options.api_key {
|
||||
|
||||
@@ -8,6 +8,7 @@ import type {
|
||||
} from "$lib/types/messages";
|
||||
import type { CharacterState } from "$lib/types/states";
|
||||
import { cleanupConversationTracking } from "$lib/tauri";
|
||||
import { normalizePath } from "$lib/utils/paths";
|
||||
import { characterState } from "$lib/stores/character";
|
||||
import { sessionsStore } from "$lib/stores/sessions";
|
||||
|
||||
@@ -388,7 +389,7 @@ function createConversationsStore() {
|
||||
conversations.update((convs) => {
|
||||
const conv = convs.get(activeId);
|
||||
if (conv) {
|
||||
conv.workingDirectory = dir;
|
||||
conv.workingDirectory = normalizePath(dir);
|
||||
conv.lastActivityAt = new Date();
|
||||
}
|
||||
return convs;
|
||||
@@ -399,7 +400,7 @@ function createConversationsStore() {
|
||||
conversations.update((convs) => {
|
||||
const conv = convs.get(conversationId);
|
||||
if (conv) {
|
||||
conv.workingDirectory = dir;
|
||||
conv.workingDirectory = normalizePath(dir);
|
||||
conv.lastActivityAt = new Date();
|
||||
}
|
||||
return convs;
|
||||
|
||||
+15
-11
@@ -1,6 +1,7 @@
|
||||
import { writable, derived, get } from "svelte/store";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import type { EditorState, EditorTab, FileEntry } from "$lib/types/editor";
|
||||
import { normalizePath, joinPath, getParentPath, getFilename } from "$lib/utils/paths";
|
||||
|
||||
const defaultState: EditorState = {
|
||||
tabs: [],
|
||||
@@ -158,7 +159,7 @@ function createEditorStore() {
|
||||
|
||||
try {
|
||||
const content = await invoke<string>("read_file_content", { path: filePath });
|
||||
const fileName = filePath.split(/[/\\]/).pop() || "untitled";
|
||||
const fileName = getFilename(filePath) || "untitled";
|
||||
const language = getLanguageFromPath(filePath);
|
||||
const newTab: EditorTab = {
|
||||
id: generateTabId(),
|
||||
@@ -247,7 +248,7 @@ function createEditorStore() {
|
||||
}
|
||||
|
||||
async function createFile(parentPath: string, fileName: string): Promise<boolean> {
|
||||
const filePath = `${parentPath}/${fileName}`;
|
||||
const filePath = joinPath(parentPath, fileName);
|
||||
try {
|
||||
await invoke("create_file", { path: filePath });
|
||||
// Refresh the parent directory
|
||||
@@ -261,7 +262,7 @@ function createEditorStore() {
|
||||
}
|
||||
|
||||
async function createDirectory(parentPath: string, dirName: string): Promise<boolean> {
|
||||
const dirPath = `${parentPath}/${dirName}`;
|
||||
const dirPath = joinPath(parentPath, dirName);
|
||||
try {
|
||||
await invoke("create_directory", { path: dirPath });
|
||||
// Refresh the parent directory
|
||||
@@ -284,7 +285,7 @@ function createEditorStore() {
|
||||
closeTab(openTab.id);
|
||||
}
|
||||
// Refresh the parent directory
|
||||
const parentPath = filePath.substring(0, filePath.lastIndexOf("/"));
|
||||
const parentPath = getParentPath(filePath);
|
||||
await refreshDirectory(parentPath);
|
||||
return true;
|
||||
} catch (error) {
|
||||
@@ -299,10 +300,11 @@ function createEditorStore() {
|
||||
await invoke("delete_directory", { path: dirPath });
|
||||
// Close any tabs that are in this directory
|
||||
const currentState = get(state);
|
||||
const tabsToClose = currentState.tabs.filter((t) => t.filePath.startsWith(dirPath + "/"));
|
||||
const normalizedDirPath = normalizePath(dirPath);
|
||||
const tabsToClose = currentState.tabs.filter((t) => normalizePath(t.filePath).startsWith(normalizedDirPath + "/"));
|
||||
tabsToClose.forEach((tab) => closeTab(tab.id));
|
||||
// Refresh the parent directory
|
||||
const parentPath = dirPath.substring(0, dirPath.lastIndexOf("/"));
|
||||
const parentPath = getParentPath(dirPath);
|
||||
await refreshDirectory(parentPath);
|
||||
return true;
|
||||
} catch (error) {
|
||||
@@ -341,8 +343,8 @@ function createEditorStore() {
|
||||
}
|
||||
|
||||
async function renamePath(oldPath: string, newName: string): Promise<boolean> {
|
||||
const parentPath = oldPath.substring(0, oldPath.lastIndexOf("/"));
|
||||
const newPath = `${parentPath}/${newName}`;
|
||||
const parentPath = getParentPath(oldPath);
|
||||
const newPath = joinPath(parentPath, newName);
|
||||
|
||||
try {
|
||||
await invoke("rename_path", { oldPath, newPath });
|
||||
@@ -359,12 +361,14 @@ function createEditorStore() {
|
||||
fileName: newName,
|
||||
};
|
||||
}
|
||||
if (t.filePath.startsWith(oldPath + "/")) {
|
||||
const normalizedOldPath = normalizePath(oldPath);
|
||||
const normalizedFilePath = normalizePath(t.filePath);
|
||||
if (normalizedFilePath.startsWith(normalizedOldPath + "/")) {
|
||||
// File is inside a renamed directory
|
||||
const relativePath = t.filePath.substring(oldPath.length);
|
||||
const relativePath = normalizedFilePath.substring(normalizedOldPath.length);
|
||||
return {
|
||||
...t,
|
||||
filePath: newPath + relativePath,
|
||||
filePath: normalizePath(newPath + relativePath),
|
||||
};
|
||||
}
|
||||
return t;
|
||||
|
||||
+6
-2
@@ -18,6 +18,7 @@ import {
|
||||
handleConnectionStatusChange,
|
||||
handleNewUserMessage,
|
||||
} from "$lib/notifications/rules";
|
||||
import { normalizePath } from "$lib/utils/paths";
|
||||
|
||||
interface StateChangePayload {
|
||||
state: CharacterState;
|
||||
@@ -290,12 +291,15 @@ export async function initializeTauriListeners() {
|
||||
const cwdUnlisten = await listen<WorkingDirectoryPayload>("claude:cwd", (event) => {
|
||||
const { directory, conversation_id } = event.payload;
|
||||
|
||||
// Normalize path separators to forward slashes
|
||||
const normalizedDirectory = normalizePath(directory);
|
||||
|
||||
// Store working directory for the correct conversation
|
||||
if (conversation_id) {
|
||||
claudeStore.setWorkingDirectoryForConversation(conversation_id, directory);
|
||||
claudeStore.setWorkingDirectoryForConversation(conversation_id, normalizedDirectory);
|
||||
} else {
|
||||
// Fallback to active conversation if no conversation_id
|
||||
claudeStore.setWorkingDirectory(directory);
|
||||
claudeStore.setWorkingDirectory(normalizedDirectory);
|
||||
}
|
||||
});
|
||||
unlisteners.push(cwdUnlisten);
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { normalizePath, joinPath, getParentPath, getFilename } from "./paths";
|
||||
|
||||
describe("paths utilities", () => {
|
||||
describe("normalizePath", () => {
|
||||
it("should normalize Windows paths", () => {
|
||||
expect(normalizePath("C:\\Users\\test")).toBe("C:/Users/test");
|
||||
expect(normalizePath("path\\to\\file")).toBe("path/to/file");
|
||||
expect(normalizePath("C:\\Users\\test\\file.txt")).toBe("C:/Users/test/file.txt");
|
||||
});
|
||||
|
||||
it("should leave Unix paths unchanged", () => {
|
||||
expect(normalizePath("/home/user")).toBe("/home/user");
|
||||
expect(normalizePath("path/to/file")).toBe("path/to/file");
|
||||
expect(normalizePath("/usr/local/bin")).toBe("/usr/local/bin");
|
||||
});
|
||||
|
||||
it("should handle mixed separators", () => {
|
||||
expect(normalizePath("mixed\\path/file")).toBe("mixed/path/file");
|
||||
expect(normalizePath("C:\\Users/test\\mixed/path")).toBe("C:/Users/test/mixed/path");
|
||||
});
|
||||
|
||||
it("should handle empty strings", () => {
|
||||
expect(normalizePath("")).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
describe("joinPath", () => {
|
||||
it("should join path segments with forward slashes", () => {
|
||||
expect(joinPath("parent", "child")).toBe("parent/child");
|
||||
expect(joinPath("/home", "user", "documents")).toBe("/home/user/documents");
|
||||
expect(joinPath("C:", "Users", "test")).toBe("C:/Users/test");
|
||||
});
|
||||
|
||||
it("should filter out empty segments", () => {
|
||||
expect(joinPath("parent", "", "child")).toBe("parent/child");
|
||||
expect(joinPath("", "home", "")).toBe("home");
|
||||
expect(joinPath("", "", "")).toBe("");
|
||||
});
|
||||
|
||||
it("should normalize mixed separators in segments", () => {
|
||||
expect(joinPath("parent\\dir", "child")).toBe("parent/dir/child");
|
||||
expect(joinPath("C:\\Users", "test\\file")).toBe("C:/Users/test/file");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getParentPath", () => {
|
||||
it("should get parent directory of Unix paths", () => {
|
||||
expect(getParentPath("/home/user/file.txt")).toBe("/home/user");
|
||||
expect(getParentPath("/home/user/")).toBe("/home");
|
||||
expect(getParentPath("/home")).toBe("/");
|
||||
expect(getParentPath("/")).toBe("/");
|
||||
});
|
||||
|
||||
it("should get parent directory of Windows paths", () => {
|
||||
expect(getParentPath("C:\\Users\\test\\file.txt")).toBe("C:/Users/test");
|
||||
expect(getParentPath("C:\\Users\\test")).toBe("C:/Users");
|
||||
expect(getParentPath("C:\\")).toBe("C:");
|
||||
});
|
||||
|
||||
it("should handle relative paths", () => {
|
||||
expect(getParentPath("parent/child/file.txt")).toBe("parent/child");
|
||||
expect(getParentPath("file.txt")).toBe(".");
|
||||
expect(getParentPath("")).toBe(".");
|
||||
});
|
||||
|
||||
it("should handle paths with trailing slashes", () => {
|
||||
expect(getParentPath("/home/user/")).toBe("/home");
|
||||
expect(getParentPath("parent/child/")).toBe("parent");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getFilename", () => {
|
||||
it("should extract filename from Unix paths", () => {
|
||||
expect(getFilename("/home/user/file.txt")).toBe("file.txt");
|
||||
expect(getFilename("/usr/local/bin/node")).toBe("node");
|
||||
expect(getFilename("/home/user/")).toBe("");
|
||||
});
|
||||
|
||||
it("should extract filename from Windows paths", () => {
|
||||
expect(getFilename("C:\\Users\\test\\file.txt")).toBe("file.txt");
|
||||
expect(getFilename("C:\\Program Files\\app.exe")).toBe("app.exe");
|
||||
expect(getFilename("D:\\folder\\")).toBe("");
|
||||
});
|
||||
|
||||
it("should handle relative paths", () => {
|
||||
expect(getFilename("parent/child/file.txt")).toBe("file.txt");
|
||||
expect(getFilename("file.txt")).toBe("file.txt");
|
||||
expect(getFilename("")).toBe("");
|
||||
});
|
||||
|
||||
it("should handle paths without filename", () => {
|
||||
expect(getFilename("/home/user/")).toBe("");
|
||||
expect(getFilename("folder/")).toBe("");
|
||||
expect(getFilename("/")).toBe("");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Normalize path separators to forward slashes for consistent handling across platforms
|
||||
*/
|
||||
export function normalizePath(path: string): string {
|
||||
// Replace all backslashes with forward slashes
|
||||
return path.replace(/\\/g, "/");
|
||||
}
|
||||
|
||||
/**
|
||||
* Join path segments with forward slashes
|
||||
*/
|
||||
export function joinPath(...segments: string[]): string {
|
||||
// Filter out empty segments
|
||||
const filtered = segments.filter((s) => s);
|
||||
// Join with forward slash and normalize
|
||||
return normalizePath(filtered.join("/"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent directory of a path
|
||||
*/
|
||||
export function getParentPath(path: string): string {
|
||||
let normalized = normalizePath(path);
|
||||
|
||||
// Remove trailing slash if present (unless it's the root)
|
||||
if (normalized.endsWith("/") && normalized.length > 1) {
|
||||
normalized = normalized.slice(0, -1);
|
||||
}
|
||||
|
||||
// Handle Windows drive roots (e.g., "C:" or "C:/")
|
||||
if (/^[A-Za-z]:$/.test(normalized)) {
|
||||
return normalized; // Drive root has no parent
|
||||
}
|
||||
|
||||
const lastSlash = normalized.lastIndexOf("/");
|
||||
if (lastSlash === -1) {
|
||||
// No slash found - could be just a filename or Windows drive letter
|
||||
if (/^[A-Za-z]:/.test(normalized)) {
|
||||
// It's a Windows path like "C:file.txt" - parent is "C:"
|
||||
return normalized.substring(0, 2);
|
||||
}
|
||||
return ".";
|
||||
}
|
||||
if (lastSlash === 0) {
|
||||
return "/";
|
||||
}
|
||||
|
||||
// Check if parent would be a Windows drive root
|
||||
const parent = normalized.substring(0, lastSlash);
|
||||
if (/^[A-Za-z]:$/.test(parent)) {
|
||||
return parent;
|
||||
}
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filename from a path
|
||||
*/
|
||||
export function getFilename(path: string): string {
|
||||
const normalized = normalizePath(path);
|
||||
const lastSlash = normalized.lastIndexOf("/");
|
||||
if (lastSlash === -1) {
|
||||
return normalized;
|
||||
}
|
||||
return normalized.substring(lastSlash + 1);
|
||||
}
|
||||
Reference in New Issue
Block a user