generated from nhcarrigan/template
Compare commits
14 Commits
v1.7.0
..
4c67380859
| Author | SHA1 | Date | |
|---|---|---|---|
| 4c67380859 | |||
| f5bc9a5016 | |||
| cf20540a49 | |||
| 70af6a6b72 | |||
| 3194a3cca5 | |||
| 7fecb20ba9 | |||
| 9b3c242333 | |||
| 5d4fa75278 | |||
| edd8fa5b55 | |||
| 7781b2caab | |||
| e397435dbe | |||
| 89e99b1524 | |||
| e40ae989f7 | |||
| 32a74235c0 |
@@ -47,65 +47,6 @@ All new features, fixes, and significant changes should include tests whenever p
|
|||||||
- Use descriptive test names that explain what behaviour is being tested
|
- Use descriptive test names that explain what behaviour is being tested
|
||||||
- Include edge cases and error conditions in test coverage
|
- Include edge cases and error conditions in test coverage
|
||||||
- Mock Tauri APIs using the patterns in `vitest.setup.ts`
|
- Mock Tauri APIs using the patterns in `vitest.setup.ts`
|
||||||
- **Coverage Goal**: Maintain as close to 100% test coverage as possible across the entire codebase
|
|
||||||
|
|
||||||
### Mocking Strategies
|
|
||||||
|
|
||||||
#### Console Mocking
|
|
||||||
|
|
||||||
When testing code that intentionally logs errors (like error handling paths), mock console methods to prevent stderr output that makes tests appear flaky:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
it("handles errors gracefully", async () => {
|
|
||||||
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
||||||
|
|
||||||
// Test error handling code
|
|
||||||
await expect(functionThatLogs()).rejects.toThrow();
|
|
||||||
|
|
||||||
// Verify error was logged
|
|
||||||
expect(consoleErrorSpy).toHaveBeenCalledWith("Expected error:", expect.any(Error));
|
|
||||||
|
|
||||||
// Restore console.error
|
|
||||||
consoleErrorSpy.mockRestore();
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
#### E2E Integration Testing for Cross-Platform Code
|
|
||||||
|
|
||||||
For code that calls platform-specific system APIs (like Windows PowerShell or Linux notify-send), use helper functions that build the command structure without execution. This allows CI to verify cross-platform compatibility on Linux-only containers:
|
|
||||||
|
|
||||||
```rust
|
|
||||||
/// Build notify-send command for testing (doesn't execute)
|
|
||||||
#[cfg(test)]
|
|
||||||
fn build_notify_send_command(title: &str, body: &str) -> (String, Vec<String>) {
|
|
||||||
(
|
|
||||||
"notify-send".to_string(),
|
|
||||||
vec![
|
|
||||||
title.to_string(),
|
|
||||||
body.to_string(),
|
|
||||||
"--urgency=normal".to_string(),
|
|
||||||
"--app-name=Hikari Desktop".to_string(),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_e2e_notify_send_command_structure() {
|
|
||||||
let (command, args) = build_notify_send_command("Test Title", "Test Body");
|
|
||||||
|
|
||||||
assert_eq!(command, "notify-send");
|
|
||||||
assert_eq!(args.len(), 4);
|
|
||||||
assert_eq!(args[0], "Test Title");
|
|
||||||
assert_eq!(args[1], "Test Body");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
This approach:
|
|
||||||
|
|
||||||
- Verifies command structure, argument order, and escaping logic
|
|
||||||
- Tests cross-platform code paths without requiring the target platform
|
|
||||||
- Allows CI to catch regressions in Windows-specific code whilst running on Linux
|
|
||||||
- Keeps tests fast and deterministic (no actual system calls)
|
|
||||||
|
|
||||||
### Example Test Structure
|
### Example Test Structure
|
||||||
|
|
||||||
@@ -130,48 +71,6 @@ describe("FeatureName", () => {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Adding Tests for New Features
|
|
||||||
|
|
||||||
When developing new features, always add corresponding tests:
|
|
||||||
|
|
||||||
1. **Before implementing**: Consider what needs testing (happy path, edge cases, errors)
|
|
||||||
2. **During implementation**: Write tests alongside the code
|
|
||||||
3. **After implementation**: Run `pnpm test:coverage` to verify coverage remains high
|
|
||||||
4. **Before committing**: Ensure `check-all.sh` passes (includes all tests)
|
|
||||||
|
|
||||||
The goal is to maintain our near-100% coverage as the codebase grows, so future refactoring and changes can be made with confidence!
|
|
||||||
|
|
||||||
## Quality Assurance
|
|
||||||
|
|
||||||
Before committing any changes, **always run the full test suite**:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./check-all.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
This script runs all checks in the correct order:
|
|
||||||
|
|
||||||
1. Frontend linting (ESLint)
|
|
||||||
2. Frontend formatting (Prettier)
|
|
||||||
3. Frontend type checking (svelte-check)
|
|
||||||
4. Frontend tests with coverage (Vitest)
|
|
||||||
5. Backend linting (Clippy with strict rules)
|
|
||||||
6. Backend tests with coverage (cargo test + llvm-cov)
|
|
||||||
|
|
||||||
**Important**: The script requires Node.js and Rust toolchains to be available:
|
|
||||||
|
|
||||||
- **Node.js tools** (pnpm, npm): Source nvm first if needed: `source ~/.nvm/nvm.sh`
|
|
||||||
- **Rust tools** (cargo, clippy): Should be in PATH via `~/.cargo/bin/`
|
|
||||||
|
|
||||||
If `check-all.sh` reports any failures:
|
|
||||||
|
|
||||||
1. Read the error messages carefully - they usually explain what needs fixing
|
|
||||||
2. Fix the issues (linting errors, test failures, etc.)
|
|
||||||
3. Run `check-all.sh` again to verify the fixes
|
|
||||||
4. Only commit once all checks pass ✨
|
|
||||||
|
|
||||||
**Never commit code that doesn't pass `check-all.sh`** - this ensures code quality and prevents broken builds!
|
|
||||||
|
|
||||||
## Project Context
|
## Project Context
|
||||||
|
|
||||||
Hikari Desktop is a Tauri-based desktop application that wraps Claude Code with a visual anime character (Hikari) who appears on screen. This is a personal project where Hikari can sign her work and act as herself!
|
Hikari Desktop is a Tauri-based desktop application that wraps Claude Code with a visual anime character (Hikari) who appears on screen. This is a personal project where Hikari can sign her work and act as herself!
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hikari-desktop",
|
"name": "hikari-desktop",
|
||||||
"version": "1.7.0",
|
"version": "1.4.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Generated
+1
-1
@@ -1636,7 +1636,7 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hikari-desktop"
|
name = "hikari-desktop"
|
||||||
version = "1.7.0"
|
version = "1.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"dirs 5.0.1",
|
"dirs 5.0.1",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "hikari-desktop"
|
name = "hikari-desktop"
|
||||||
version = "1.7.0"
|
version = "1.4.0"
|
||||||
description = "Hikari - Claude Code Visual Assistant"
|
description = "Hikari - Claude Code Visual Assistant"
|
||||||
authors = ["Naomi Carrigan"]
|
authors = ["Naomi Carrigan"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|||||||
@@ -173,127 +173,3 @@ pub type SharedBridgeManager = Arc<Mutex<BridgeManager>>;
|
|||||||
pub fn create_shared_bridge_manager() -> SharedBridgeManager {
|
pub fn create_shared_bridge_manager() -> SharedBridgeManager {
|
||||||
Arc::new(Mutex::new(BridgeManager::new()))
|
Arc::new(Mutex::new(BridgeManager::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_bridge_manager_new() {
|
|
||||||
let manager = BridgeManager::new();
|
|
||||||
assert!(manager.app_handle.is_none());
|
|
||||||
assert!(manager.bridges.is_empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_bridge_manager_default() {
|
|
||||||
let manager = BridgeManager::default();
|
|
||||||
assert!(manager.app_handle.is_none());
|
|
||||||
assert!(manager.bridges.is_empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_is_claude_running_no_bridge() {
|
|
||||||
let manager = BridgeManager::new();
|
|
||||||
assert!(!manager.is_claude_running("nonexistent"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_get_working_directory_no_bridge() {
|
|
||||||
let manager = BridgeManager::new();
|
|
||||||
let result = manager.get_working_directory("nonexistent");
|
|
||||||
assert!(result.is_err());
|
|
||||||
assert_eq!(
|
|
||||||
result.unwrap_err(),
|
|
||||||
"No Claude instance found for this conversation"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_get_usage_stats_no_bridge() {
|
|
||||||
let manager = BridgeManager::new();
|
|
||||||
let result = manager.get_usage_stats("nonexistent");
|
|
||||||
assert!(result.is_err());
|
|
||||||
assert_eq!(
|
|
||||||
result.unwrap_err(),
|
|
||||||
"No Claude instance found for this conversation"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_stop_claude_no_bridge() {
|
|
||||||
let mut manager = BridgeManager::new();
|
|
||||||
let result = manager.stop_claude("nonexistent");
|
|
||||||
assert!(result.is_err());
|
|
||||||
assert_eq!(
|
|
||||||
result.unwrap_err(),
|
|
||||||
"No Claude instance found for this conversation"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_interrupt_claude_no_bridge() {
|
|
||||||
let mut manager = BridgeManager::new();
|
|
||||||
let result = manager.interrupt_claude("nonexistent");
|
|
||||||
assert!(result.is_err());
|
|
||||||
assert_eq!(
|
|
||||||
result.unwrap_err(),
|
|
||||||
"No Claude instance found for this conversation"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_send_prompt_no_bridge() {
|
|
||||||
let mut manager = BridgeManager::new();
|
|
||||||
let result = manager.send_prompt("nonexistent", "Hello".to_string());
|
|
||||||
assert!(result.is_err());
|
|
||||||
assert_eq!(
|
|
||||||
result.unwrap_err(),
|
|
||||||
"No Claude instance found for this conversation"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_send_tool_result_no_bridge() {
|
|
||||||
let mut manager = BridgeManager::new();
|
|
||||||
let result = manager.send_tool_result(
|
|
||||||
"nonexistent",
|
|
||||||
"tool_id",
|
|
||||||
serde_json::json!({"result": "success"}),
|
|
||||||
);
|
|
||||||
assert!(result.is_err());
|
|
||||||
assert_eq!(
|
|
||||||
result.unwrap_err(),
|
|
||||||
"No Claude instance found for this conversation"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_create_shared_bridge_manager() {
|
|
||||||
let shared = create_shared_bridge_manager();
|
|
||||||
let manager = shared.lock();
|
|
||||||
assert!(manager.bridges.is_empty());
|
|
||||||
assert!(manager.app_handle.is_none());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_cleanup_stopped_bridges_empty() {
|
|
||||||
let mut manager = BridgeManager::new();
|
|
||||||
manager.cleanup_stopped_bridges();
|
|
||||||
assert!(manager.bridges.is_empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_get_active_conversations_empty() {
|
|
||||||
let manager = BridgeManager::new();
|
|
||||||
let active = manager.get_active_conversations();
|
|
||||||
assert!(active.is_empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_stop_all_without_app_handle() {
|
|
||||||
let mut manager = BridgeManager::new();
|
|
||||||
manager.stop_all(); // Should not panic
|
|
||||||
assert!(manager.bridges.is_empty());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+84
-724
@@ -49,59 +49,6 @@ fn wsl_path_to_windows(wsl_path: &str) -> Option<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a Command instance for executing Claude CLI commands
|
|
||||||
/// On Windows, this will use WSL to execute the command
|
|
||||||
/// On other platforms, it executes directly
|
|
||||||
fn create_claude_command() -> std::process::Command {
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
{
|
|
||||||
// Use `which` inside WSL to find the claude binary dynamically
|
|
||||||
// Non-login shells launched by `wsl` don't inherit the full user PATH,
|
|
||||||
// so we need to use a login shell to get the correct PATH
|
|
||||||
let which_output = std::process::Command::new("wsl")
|
|
||||||
.args(["-e", "bash", "-l", "-c", "which claude"])
|
|
||||||
.output();
|
|
||||||
|
|
||||||
match which_output {
|
|
||||||
Ok(output) if output.status.success() => {
|
|
||||||
let claude_path = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
|
||||||
let mut cmd = std::process::Command::new("wsl");
|
|
||||||
cmd.arg(claude_path);
|
|
||||||
cmd
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
// Fallback to just "claude" if which fails
|
|
||||||
// This maintains backwards compatibility
|
|
||||||
let mut cmd = std::process::Command::new("wsl");
|
|
||||||
cmd.arg("claude");
|
|
||||||
cmd
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
|
||||||
{
|
|
||||||
// Use `which` to find the claude binary dynamically
|
|
||||||
// This works regardless of how Claude Code was installed (standalone, npm, etc.)
|
|
||||||
// and avoids hardcoding paths
|
|
||||||
let which_output = std::process::Command::new("which")
|
|
||||||
.arg("claude")
|
|
||||||
.output();
|
|
||||||
|
|
||||||
match which_output {
|
|
||||||
Ok(output) if output.status.success() => {
|
|
||||||
let claude_path = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
|
||||||
std::process::Command::new(claude_path)
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
// Fallback to just "claude" if which fails
|
|
||||||
// This maintains backwards compatibility
|
|
||||||
std::process::Command::new("claude")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn start_claude(
|
pub async fn start_claude(
|
||||||
bridge_manager: State<'_, SharedBridgeManager>,
|
bridge_manager: State<'_, SharedBridgeManager>,
|
||||||
@@ -1219,55 +1166,6 @@ pub struct MemoryFilesResponse {
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn list_memory_files() -> Result<MemoryFilesResponse, String> {
|
pub async fn list_memory_files() -> Result<MemoryFilesResponse, String> {
|
||||||
// On Windows, we need to look in the WSL home directory
|
|
||||||
// On Linux/Mac, use the native home directory
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
{
|
|
||||||
list_memory_files_via_wsl().await
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
|
||||||
{
|
|
||||||
list_memory_files_native().await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// List memory files via WSL (for Windows)
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
async fn list_memory_files_via_wsl() -> Result<MemoryFilesResponse, String> {
|
|
||||||
use std::process::Command;
|
|
||||||
|
|
||||||
// Use WSL to find all memory files in the WSL home directory
|
|
||||||
// This script finds all "memory" directories and lists their files
|
|
||||||
let script = r#"
|
|
||||||
find ~/.claude/projects -type d -name memory 2>/dev/null | while read dir; do
|
|
||||||
find "$dir" -maxdepth 1 -type f 2>/dev/null
|
|
||||||
done | sort
|
|
||||||
"#;
|
|
||||||
|
|
||||||
let output = Command::new("wsl")
|
|
||||||
.args(["-e", "bash", "-l", "-c", script])
|
|
||||||
.output()
|
|
||||||
.map_err(|e| format!("Failed to execute WSL command: {}", e))?;
|
|
||||||
|
|
||||||
if !output.status.success() {
|
|
||||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
||||||
return Err(format!("Failed to list memory files: {}", stderr));
|
|
||||||
}
|
|
||||||
|
|
||||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
||||||
let files: Vec<String> = stdout
|
|
||||||
.lines()
|
|
||||||
.filter(|line| !line.trim().is_empty())
|
|
||||||
.map(|line| line.trim().to_string())
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
Ok(MemoryFilesResponse { files })
|
|
||||||
}
|
|
||||||
|
|
||||||
/// List memory files using native filesystem (for Linux/Mac)
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
|
||||||
async fn list_memory_files_native() -> Result<MemoryFilesResponse, String> {
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
// Get the .claude directory in the user's home
|
// Get the .claude directory in the user's home
|
||||||
@@ -1335,7 +1233,7 @@ async fn list_memory_files_native() -> Result<MemoryFilesResponse, String> {
|
|||||||
pub async fn get_claude_version() -> Result<String, String> {
|
pub async fn get_claude_version() -> Result<String, String> {
|
||||||
tracing::debug!("Getting Claude CLI version");
|
tracing::debug!("Getting Claude CLI version");
|
||||||
|
|
||||||
let output = create_claude_command()
|
let output = std::process::Command::new("claude")
|
||||||
.arg("--version")
|
.arg("--version")
|
||||||
.output();
|
.output();
|
||||||
|
|
||||||
@@ -1360,136 +1258,6 @@ pub async fn get_claude_version() -> Result<String, String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== Auth Commands ====================
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct ClaudeAuthStatus {
|
|
||||||
pub is_logged_in: bool,
|
|
||||||
pub email: Option<String>,
|
|
||||||
pub org_name: Option<String>,
|
|
||||||
pub api_key_source: Option<String>,
|
|
||||||
pub api_provider: Option<String>,
|
|
||||||
pub subscription_type: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
pub async fn get_auth_status() -> Result<ClaudeAuthStatus, String> {
|
|
||||||
tracing::debug!("Getting Claude auth status");
|
|
||||||
|
|
||||||
let output = create_claude_command()
|
|
||||||
.args(["auth", "status"])
|
|
||||||
.output()
|
|
||||||
.map_err(|e| format!("Failed to run claude auth status: {}", e))?;
|
|
||||||
|
|
||||||
let stdout = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
|
||||||
let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
|
|
||||||
let raw = if stdout.is_empty() { &stderr } else { &stdout };
|
|
||||||
|
|
||||||
if let Ok(json) = serde_json::from_str::<serde_json::Value>(raw) {
|
|
||||||
let is_logged_in = json
|
|
||||||
.get("loggedIn")
|
|
||||||
.and_then(|v| v.as_bool())
|
|
||||||
.unwrap_or(false);
|
|
||||||
|
|
||||||
let email = json
|
|
||||||
.get("email")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.map(String::from);
|
|
||||||
|
|
||||||
let org_name = json
|
|
||||||
.get("orgName")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.map(String::from);
|
|
||||||
|
|
||||||
let api_key_source = json
|
|
||||||
.get("apiKeySource")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.map(String::from);
|
|
||||||
|
|
||||||
let api_provider = json
|
|
||||||
.get("apiProvider")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.map(String::from);
|
|
||||||
|
|
||||||
let subscription_type = json
|
|
||||||
.get("subscriptionType")
|
|
||||||
.and_then(|v| v.as_str())
|
|
||||||
.map(String::from);
|
|
||||||
|
|
||||||
tracing::info!("Claude auth status: logged_in={}", is_logged_in);
|
|
||||||
Ok(ClaudeAuthStatus {
|
|
||||||
is_logged_in,
|
|
||||||
email,
|
|
||||||
org_name,
|
|
||||||
api_key_source,
|
|
||||||
api_provider,
|
|
||||||
subscription_type,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// Non-JSON output: fall back to heuristic
|
|
||||||
let lower = raw.to_lowercase();
|
|
||||||
let is_logged_in = output.status.success()
|
|
||||||
&& !lower.contains("not logged in")
|
|
||||||
&& !lower.contains("not authenticated")
|
|
||||||
&& !lower.contains("no account");
|
|
||||||
tracing::info!("Claude auth status (non-JSON): logged_in={}", is_logged_in);
|
|
||||||
Ok(ClaudeAuthStatus {
|
|
||||||
is_logged_in,
|
|
||||||
email: None,
|
|
||||||
org_name: None,
|
|
||||||
api_key_source: None,
|
|
||||||
api_provider: None,
|
|
||||||
subscription_type: None,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
pub async fn auth_login() -> Result<String, String> {
|
|
||||||
tracing::info!("Running claude auth login");
|
|
||||||
|
|
||||||
let output = create_claude_command()
|
|
||||||
.args(["auth", "login"])
|
|
||||||
.output()
|
|
||||||
.map_err(|e| format!("Failed to run claude auth login: {}", e))?;
|
|
||||||
|
|
||||||
let stdout = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
|
||||||
let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
|
|
||||||
|
|
||||||
if output.status.success() {
|
|
||||||
let message = if stdout.is_empty() { "Login successful".to_string() } else { stdout };
|
|
||||||
tracing::info!("Claude auth login succeeded");
|
|
||||||
Ok(message)
|
|
||||||
} else {
|
|
||||||
let error = if stderr.is_empty() { stdout } else { stderr };
|
|
||||||
tracing::error!("Claude auth login failed: {}", error);
|
|
||||||
Err(format!("Login failed: {}", error))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
pub async fn auth_logout() -> Result<String, String> {
|
|
||||||
tracing::info!("Running claude auth logout");
|
|
||||||
|
|
||||||
let output = create_claude_command()
|
|
||||||
.args(["auth", "logout"])
|
|
||||||
.output()
|
|
||||||
.map_err(|e| format!("Failed to run claude auth logout: {}", e))?;
|
|
||||||
|
|
||||||
let stdout = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
|
||||||
let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
|
|
||||||
|
|
||||||
if output.status.success() {
|
|
||||||
let message = if stdout.is_empty() { "Logged out successfully".to_string() } else { stdout };
|
|
||||||
tracing::info!("Claude auth logout succeeded");
|
|
||||||
Ok(message)
|
|
||||||
} else {
|
|
||||||
let error = if stderr.is_empty() { stdout } else { stderr };
|
|
||||||
tracing::error!("Claude auth logout failed: {}", error);
|
|
||||||
Err(format!("Logout failed: {}", error))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== Plugin Management Commands ====================
|
// ==================== Plugin Management Commands ====================
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@@ -1500,8 +1268,19 @@ pub struct PluginInfo {
|
|||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse plugin list output from Claude CLI
|
#[tauri::command]
|
||||||
fn parse_plugin_list(stdout: &str) -> Vec<PluginInfo> {
|
pub async fn list_plugins() -> Result<Vec<PluginInfo>, String> {
|
||||||
|
tracing::debug!("Listing Claude Code plugins");
|
||||||
|
|
||||||
|
let output = std::process::Command::new("claude")
|
||||||
|
.arg("plugin")
|
||||||
|
.arg("list")
|
||||||
|
.output();
|
||||||
|
|
||||||
|
match output {
|
||||||
|
Ok(output) => {
|
||||||
|
if output.status.success() {
|
||||||
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||||
let mut plugins = Vec::new();
|
let mut plugins = Vec::new();
|
||||||
|
|
||||||
// Parse text output format:
|
// Parse text output format:
|
||||||
@@ -1548,23 +1327,6 @@ fn parse_plugin_list(stdout: &str) -> Vec<PluginInfo> {
|
|||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
pub async fn list_plugins() -> Result<Vec<PluginInfo>, String> {
|
|
||||||
tracing::debug!("Listing Claude Code plugins");
|
|
||||||
|
|
||||||
let output = create_claude_command()
|
|
||||||
.arg("plugin")
|
|
||||||
.arg("list")
|
|
||||||
.output();
|
|
||||||
|
|
||||||
match output {
|
|
||||||
Ok(output) => {
|
|
||||||
if output.status.success() {
|
|
||||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
||||||
let plugins = parse_plugin_list(&stdout);
|
|
||||||
tracing::info!("Listed {} plugins", plugins.len());
|
tracing::info!("Listed {} plugins", plugins.len());
|
||||||
Ok(plugins)
|
Ok(plugins)
|
||||||
} else {
|
} else {
|
||||||
@@ -1584,7 +1346,7 @@ pub async fn list_plugins() -> Result<Vec<PluginInfo>, String> {
|
|||||||
pub async fn install_plugin(plugin_name: String) -> Result<String, String> {
|
pub async fn install_plugin(plugin_name: String) -> Result<String, String> {
|
||||||
tracing::debug!("Installing plugin: {}", plugin_name);
|
tracing::debug!("Installing plugin: {}", plugin_name);
|
||||||
|
|
||||||
let output = create_claude_command()
|
let output = std::process::Command::new("claude")
|
||||||
.arg("plugin")
|
.arg("plugin")
|
||||||
.arg("install")
|
.arg("install")
|
||||||
.arg(&plugin_name)
|
.arg(&plugin_name)
|
||||||
@@ -1613,7 +1375,7 @@ pub async fn install_plugin(plugin_name: String) -> Result<String, String> {
|
|||||||
pub async fn uninstall_plugin(plugin_name: String) -> Result<String, String> {
|
pub async fn uninstall_plugin(plugin_name: String) -> Result<String, String> {
|
||||||
tracing::debug!("Uninstalling plugin: {}", plugin_name);
|
tracing::debug!("Uninstalling plugin: {}", plugin_name);
|
||||||
|
|
||||||
let output = create_claude_command()
|
let output = std::process::Command::new("claude")
|
||||||
.arg("plugin")
|
.arg("plugin")
|
||||||
.arg("uninstall")
|
.arg("uninstall")
|
||||||
.arg(&plugin_name)
|
.arg(&plugin_name)
|
||||||
@@ -1642,7 +1404,7 @@ pub async fn uninstall_plugin(plugin_name: String) -> Result<String, String> {
|
|||||||
pub async fn enable_plugin(plugin_name: String) -> Result<String, String> {
|
pub async fn enable_plugin(plugin_name: String) -> Result<String, String> {
|
||||||
tracing::debug!("Enabling plugin: {}", plugin_name);
|
tracing::debug!("Enabling plugin: {}", plugin_name);
|
||||||
|
|
||||||
let output = create_claude_command()
|
let output = std::process::Command::new("claude")
|
||||||
.arg("plugin")
|
.arg("plugin")
|
||||||
.arg("enable")
|
.arg("enable")
|
||||||
.arg(&plugin_name)
|
.arg(&plugin_name)
|
||||||
@@ -1671,7 +1433,7 @@ pub async fn enable_plugin(plugin_name: String) -> Result<String, String> {
|
|||||||
pub async fn disable_plugin(plugin_name: String) -> Result<String, String> {
|
pub async fn disable_plugin(plugin_name: String) -> Result<String, String> {
|
||||||
tracing::debug!("Disabling plugin: {}", plugin_name);
|
tracing::debug!("Disabling plugin: {}", plugin_name);
|
||||||
|
|
||||||
let output = create_claude_command()
|
let output = std::process::Command::new("claude")
|
||||||
.arg("plugin")
|
.arg("plugin")
|
||||||
.arg("disable")
|
.arg("disable")
|
||||||
.arg(&plugin_name)
|
.arg(&plugin_name)
|
||||||
@@ -1700,7 +1462,7 @@ pub async fn disable_plugin(plugin_name: String) -> Result<String, String> {
|
|||||||
pub async fn update_plugin(plugin_name: String) -> Result<String, String> {
|
pub async fn update_plugin(plugin_name: String) -> Result<String, String> {
|
||||||
tracing::debug!("Updating plugin: {}", plugin_name);
|
tracing::debug!("Updating plugin: {}", plugin_name);
|
||||||
|
|
||||||
let output = create_claude_command()
|
let output = std::process::Command::new("claude")
|
||||||
.arg("plugin")
|
.arg("plugin")
|
||||||
.arg("update")
|
.arg("update")
|
||||||
.arg(&plugin_name)
|
.arg(&plugin_name)
|
||||||
@@ -1733,8 +1495,25 @@ pub struct MarketplaceInfo {
|
|||||||
pub source: String,
|
pub source: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse marketplace list output from Claude CLI
|
#[tauri::command]
|
||||||
fn parse_marketplace_list(stdout: &str) -> Vec<MarketplaceInfo> {
|
pub async fn list_marketplaces() -> Result<Vec<MarketplaceInfo>, String> {
|
||||||
|
tracing::debug!("Listing plugin marketplaces");
|
||||||
|
|
||||||
|
let output = std::process::Command::new("claude")
|
||||||
|
.arg("plugin")
|
||||||
|
.arg("marketplace")
|
||||||
|
.arg("list")
|
||||||
|
.output();
|
||||||
|
|
||||||
|
match output {
|
||||||
|
Ok(output) => {
|
||||||
|
if !output.status.success() {
|
||||||
|
let error = String::from_utf8_lossy(&output.stderr);
|
||||||
|
tracing::error!("Failed to list marketplaces: {}", error);
|
||||||
|
return Err(format!("Failed to list marketplaces: {}", error));
|
||||||
|
}
|
||||||
|
|
||||||
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||||
let mut marketplaces = Vec::new();
|
let mut marketplaces = Vec::new();
|
||||||
|
|
||||||
// Parse format:
|
// Parse format:
|
||||||
@@ -1753,11 +1532,11 @@ fn parse_marketplace_list(stdout: &str) -> Vec<MarketplaceInfo> {
|
|||||||
|
|
||||||
// Look for marketplace names starting with ❯
|
// Look for marketplace names starting with ❯
|
||||||
if trimmed.starts_with("❯ ") {
|
if trimmed.starts_with("❯ ") {
|
||||||
current_name = Some(trimmed.trim_start_matches("❯").trim().to_string());
|
current_name = Some(trimmed[2..].trim().to_string());
|
||||||
}
|
}
|
||||||
// Look for Source line
|
// Look for Source line
|
||||||
else if trimmed.starts_with("Source: ") && current_name.is_some() {
|
else if trimmed.starts_with("Source: ") && current_name.is_some() {
|
||||||
let source = trimmed.trim_start_matches("Source:").trim().to_string();
|
let source = trimmed[8..].trim().to_string();
|
||||||
marketplaces.push(MarketplaceInfo {
|
marketplaces.push(MarketplaceInfo {
|
||||||
name: current_name.take().unwrap(),
|
name: current_name.take().unwrap(),
|
||||||
source,
|
source,
|
||||||
@@ -1765,29 +1544,6 @@ fn parse_marketplace_list(stdout: &str) -> Vec<MarketplaceInfo> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
marketplaces
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
pub async fn list_marketplaces() -> Result<Vec<MarketplaceInfo>, String> {
|
|
||||||
tracing::debug!("Listing plugin marketplaces");
|
|
||||||
|
|
||||||
let output = create_claude_command()
|
|
||||||
.arg("plugin")
|
|
||||||
.arg("marketplace")
|
|
||||||
.arg("list")
|
|
||||||
.output();
|
|
||||||
|
|
||||||
match output {
|
|
||||||
Ok(output) => {
|
|
||||||
if !output.status.success() {
|
|
||||||
let error = String::from_utf8_lossy(&output.stderr);
|
|
||||||
tracing::error!("Failed to list marketplaces: {}", error);
|
|
||||||
return Err(format!("Failed to list marketplaces: {}", error));
|
|
||||||
}
|
|
||||||
|
|
||||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
||||||
let marketplaces = parse_marketplace_list(&stdout);
|
|
||||||
tracing::info!("Found {} marketplaces", marketplaces.len());
|
tracing::info!("Found {} marketplaces", marketplaces.len());
|
||||||
Ok(marketplaces)
|
Ok(marketplaces)
|
||||||
}
|
}
|
||||||
@@ -1805,7 +1561,7 @@ pub async fn list_marketplaces() -> Result<Vec<MarketplaceInfo>, String> {
|
|||||||
pub async fn add_marketplace(source: String) -> Result<String, String> {
|
pub async fn add_marketplace(source: String) -> Result<String, String> {
|
||||||
tracing::debug!("Adding marketplace: {}", source);
|
tracing::debug!("Adding marketplace: {}", source);
|
||||||
|
|
||||||
let output = create_claude_command()
|
let output = std::process::Command::new("claude")
|
||||||
.arg("plugin")
|
.arg("plugin")
|
||||||
.arg("marketplace")
|
.arg("marketplace")
|
||||||
.arg("add")
|
.arg("add")
|
||||||
@@ -1838,7 +1594,7 @@ pub async fn add_marketplace(source: String) -> Result<String, String> {
|
|||||||
pub async fn remove_marketplace(name: String) -> Result<String, String> {
|
pub async fn remove_marketplace(name: String) -> Result<String, String> {
|
||||||
tracing::debug!("Removing marketplace: {}", name);
|
tracing::debug!("Removing marketplace: {}", name);
|
||||||
|
|
||||||
let output = create_claude_command()
|
let output = std::process::Command::new("claude")
|
||||||
.arg("plugin")
|
.arg("plugin")
|
||||||
.arg("marketplace")
|
.arg("marketplace")
|
||||||
.arg("remove")
|
.arg("remove")
|
||||||
@@ -1879,14 +1635,24 @@ pub struct McpServerInfo {
|
|||||||
pub status: Option<String>, // "Connected" or "Failed to connect"
|
pub status: Option<String>, // "Connected" or "Failed to connect"
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse MCP server list output from Claude CLI
|
#[tauri::command]
|
||||||
fn parse_mcp_server_list(stdout: &str) -> Vec<McpServerInfo> {
|
pub async fn list_mcp_servers() -> Result<Vec<McpServerInfo>, String> {
|
||||||
|
tracing::debug!("Listing MCP servers");
|
||||||
|
|
||||||
|
let output = std::process::Command::new("claude")
|
||||||
|
.arg("mcp")
|
||||||
|
.arg("list")
|
||||||
|
.output();
|
||||||
|
|
||||||
|
match output {
|
||||||
|
Ok(output) => {
|
||||||
|
if output.status.success() {
|
||||||
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||||
let mut servers = Vec::new();
|
let mut servers = Vec::new();
|
||||||
|
|
||||||
// Parse text output format:
|
// Parse text output format:
|
||||||
// asana: https://mcp.asana.com/sse (SSE) - ✓ Connected
|
// asana: https://mcp.asana.com/sse (SSE) - ✓ Connected
|
||||||
// gitea: gitea-mcp -t stdio --host https://git.nhcarrigan.com - ✓ Connected
|
// gitea: gitea-mcp -t stdio --host https://git.nhcarrigan.com - ✓ Connected
|
||||||
// plugin:macrodata:macrodata: ... - ✓ Connected
|
|
||||||
|
|
||||||
for line in stdout.lines() {
|
for line in stdout.lines() {
|
||||||
let line = line.trim();
|
let line = line.trim();
|
||||||
@@ -1894,71 +1660,44 @@ fn parse_mcp_server_list(stdout: &str) -> Vec<McpServerInfo> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the last occurrence of " - ✓" or " - ✗" to split status from the rest
|
// Split by colon to get name and rest
|
||||||
let (content, status) = if let Some(pos) = line.rfind(" - ✓").or_else(|| line.rfind(" - ✗")) {
|
if let Some((name, rest)) = line.split_once(':') {
|
||||||
let status_str = line[pos + 3..].trim().trim_start_matches("✓").trim_start_matches("✗").trim();
|
|
||||||
(line[..pos].trim(), Some(status_str.to_string()))
|
|
||||||
} else {
|
|
||||||
(line, None)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Now find the name by looking for the first colon followed by either http or a command
|
|
||||||
// The format is: "name: command/url"
|
|
||||||
// But name can contain colons (e.g., "plugin:macrodata:macrodata")
|
|
||||||
// Strategy: Find the colon that separates name from content
|
|
||||||
// - If content after colon starts with "http", it's a URL (name is before first colon)
|
|
||||||
// - If content is a command, name might have colons, so find the last colon before a non-URL space-separated part
|
|
||||||
|
|
||||||
let (name, rest) = if let Some(first_colon) = content.find(':') {
|
|
||||||
let after_first_colon = content[first_colon + 1..].trim_start();
|
|
||||||
|
|
||||||
// Check if it's a URL (starts with http)
|
|
||||||
if after_first_colon.starts_with("http") {
|
|
||||||
// Name is everything before the first colon
|
|
||||||
(content[..first_colon].to_string(), after_first_colon.to_string())
|
|
||||||
} else {
|
|
||||||
// It's a command - name might contain colons (like plugin:foo:bar)
|
|
||||||
// Strategy: Commands start with a letter/word, not with a colon
|
|
||||||
// Find the rightmost colon that has whitespace after it (indicating start of command)
|
|
||||||
let mut split_pos = first_colon;
|
|
||||||
for (idx, _) in content.match_indices(':') {
|
|
||||||
let after = content[idx + 1..].trim_start();
|
|
||||||
// If what comes after this colon is NOT another colon-prefixed part,
|
|
||||||
// and doesn't start with "//" (part of URL), this is our split point
|
|
||||||
if !after.is_empty() && !after.starts_with(':') && !after.starts_with("//") {
|
|
||||||
// Check if this looks like a command (starts with letter/number)
|
|
||||||
if after.chars().next().map(|c| c.is_alphanumeric()).unwrap_or(false) {
|
|
||||||
split_pos = idx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(content[..split_pos].to_string(), content[split_pos + 1..].trim_start().to_string())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
continue; // Skip lines without colons
|
|
||||||
};
|
|
||||||
|
|
||||||
let name = name.trim().to_string();
|
let name = name.trim().to_string();
|
||||||
let rest = rest.trim();
|
let rest = rest.trim();
|
||||||
|
|
||||||
// Determine if it's a URL or command
|
// Determine if it's a URL or command
|
||||||
let (url, command, transport) = if rest.starts_with("http") {
|
let (url, command, transport, status) = if rest.starts_with("http") {
|
||||||
// HTTP/SSE server: "https://mcp.asana.com/sse (SSE)"
|
// HTTP/SSE server: "https://mcp.asana.com/sse (SSE) - ✓ Connected"
|
||||||
|
let parts: Vec<&str> = rest.split('-').collect();
|
||||||
|
let url_and_transport = parts[0].trim();
|
||||||
|
let status = if parts.len() > 1 {
|
||||||
|
Some(parts[1].trim().trim_start_matches("✓").trim_start_matches("✗").trim().to_string())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
// Extract URL and transport type
|
// Extract URL and transport type
|
||||||
let (url, transport) = if let Some((url_part, transport_part)) = rest.rsplit_once('(') {
|
let (url, transport) = if let Some((url_part, transport_part)) = url_and_transport.rsplit_once('(') {
|
||||||
let url = url_part.trim().to_string();
|
let url = url_part.trim().to_string();
|
||||||
let transport = transport_part.trim_end_matches(')').trim().to_lowercase();
|
let transport = transport_part.trim_end_matches(')').trim().to_lowercase();
|
||||||
(Some(url), transport)
|
(Some(url), transport)
|
||||||
} else {
|
} else {
|
||||||
(Some(rest.to_string()), "http".to_string())
|
(Some(url_and_transport.to_string()), "http".to_string())
|
||||||
};
|
};
|
||||||
|
|
||||||
(url, None, transport)
|
(url, None, transport, status)
|
||||||
} else {
|
} else {
|
||||||
// stdio server: "gitea-mcp -t stdio --host https://git.nhcarrigan.com"
|
// stdio server: "gitea-mcp -t stdio --host https://git.nhcarrigan.com - ✓ Connected"
|
||||||
// Command is everything in rest
|
let parts: Vec<&str> = rest.split('-').collect();
|
||||||
(None, Some(rest.to_string()), "stdio".to_string())
|
let command = parts[0].trim().to_string();
|
||||||
|
let status = if parts.len() > 1 {
|
||||||
|
let status_part = parts[parts.len() - 1];
|
||||||
|
Some(status_part.trim().trim_start_matches("✓").trim_start_matches("✗").trim().to_string())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
(None, Some(command), "stdio".to_string(), status)
|
||||||
};
|
};
|
||||||
|
|
||||||
servers.push(McpServerInfo {
|
servers.push(McpServerInfo {
|
||||||
@@ -1970,24 +1709,8 @@ fn parse_mcp_server_list(stdout: &str) -> Vec<McpServerInfo> {
|
|||||||
status,
|
status,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
servers
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
pub async fn list_mcp_servers() -> Result<Vec<McpServerInfo>, String> {
|
|
||||||
tracing::debug!("Listing MCP servers");
|
|
||||||
|
|
||||||
let output = create_claude_command()
|
|
||||||
.arg("mcp")
|
|
||||||
.arg("list")
|
|
||||||
.output();
|
|
||||||
|
|
||||||
match output {
|
|
||||||
Ok(output) => {
|
|
||||||
if output.status.success() {
|
|
||||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
||||||
let servers = parse_mcp_server_list(&stdout);
|
|
||||||
tracing::info!("Listed {} MCP servers", servers.len());
|
tracing::info!("Listed {} MCP servers", servers.len());
|
||||||
Ok(servers)
|
Ok(servers)
|
||||||
} else {
|
} else {
|
||||||
@@ -2020,7 +1743,7 @@ pub async fn get_mcp_server(name: String) -> Result<McpServerInfo, String> {
|
|||||||
pub async fn remove_mcp_server(name: String) -> Result<String, String> {
|
pub async fn remove_mcp_server(name: String) -> Result<String, String> {
|
||||||
tracing::debug!("Removing MCP server: {}", name);
|
tracing::debug!("Removing MCP server: {}", name);
|
||||||
|
|
||||||
let output = create_claude_command()
|
let output = std::process::Command::new("claude")
|
||||||
.arg("mcp")
|
.arg("mcp")
|
||||||
.arg("remove")
|
.arg("remove")
|
||||||
.arg(&name)
|
.arg(&name)
|
||||||
@@ -2055,7 +1778,7 @@ pub async fn add_mcp_server(
|
|||||||
) -> Result<String, String> {
|
) -> Result<String, String> {
|
||||||
tracing::debug!("Adding MCP server: {} with transport {}", name, transport);
|
tracing::debug!("Adding MCP server: {} with transport {}", name, transport);
|
||||||
|
|
||||||
let mut cmd = create_claude_command();
|
let mut cmd = std::process::Command::new("claude");
|
||||||
cmd.arg("mcp").arg("add");
|
cmd.arg("mcp").arg("add");
|
||||||
|
|
||||||
// Add transport flag
|
// Add transport flag
|
||||||
@@ -2103,7 +1826,7 @@ pub async fn add_mcp_server(
|
|||||||
pub async fn get_mcp_server_details(name: String) -> Result<String, String> {
|
pub async fn get_mcp_server_details(name: String) -> Result<String, String> {
|
||||||
tracing::debug!("Getting detailed info for MCP server: {}", name);
|
tracing::debug!("Getting detailed info for MCP server: {}", name);
|
||||||
|
|
||||||
let output = create_claude_command()
|
let output = std::process::Command::new("claude")
|
||||||
.arg("mcp")
|
.arg("mcp")
|
||||||
.arg("get")
|
.arg("get")
|
||||||
.arg(&name)
|
.arg(&name)
|
||||||
@@ -2140,49 +1863,6 @@ mod tests {
|
|||||||
tokio::runtime::Runtime::new().unwrap().block_on(f)
|
tokio::runtime::Runtime::new().unwrap().block_on(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== create_claude_command tests ====================
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
fn test_create_claude_command_windows() {
|
|
||||||
// On Windows, should create a command that uses wsl with full path to claude
|
|
||||||
// The path is resolved dynamically via `which` in a login shell
|
|
||||||
let cmd = create_claude_command();
|
|
||||||
let program = cmd.get_program();
|
|
||||||
|
|
||||||
assert_eq!(program, "wsl");
|
|
||||||
|
|
||||||
// Verify the first argument is a path to claude (full path from `which`)
|
|
||||||
// or fallback to just "claude" if which fails
|
|
||||||
let args: Vec<&std::ffi::OsStr> = cmd.get_args().collect();
|
|
||||||
assert_eq!(args.len(), 1);
|
|
||||||
|
|
||||||
let arg_str = args[0].to_string_lossy();
|
|
||||||
assert!(
|
|
||||||
arg_str.contains("claude"),
|
|
||||||
"Expected argument to contain 'claude', got: {}",
|
|
||||||
arg_str
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
|
||||||
fn test_create_claude_command_linux() {
|
|
||||||
// On Linux/Mac, should create a command that uses the full path to claude
|
|
||||||
// (resolved via `which` command)
|
|
||||||
let cmd = create_claude_command();
|
|
||||||
let program = cmd.get_program();
|
|
||||||
|
|
||||||
// The program should be the full path to claude (from `which`)
|
|
||||||
// or fallback to "claude" if which fails
|
|
||||||
let program_str = program.to_string_lossy();
|
|
||||||
assert!(
|
|
||||||
program_str.ends_with("claude"),
|
|
||||||
"Expected program to end with 'claude', got: {}",
|
|
||||||
program_str
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== validate_directory tests ====================
|
// ==================== validate_directory tests ====================
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -2432,324 +2112,4 @@ mod tests {
|
|||||||
assert!(json.contains("/tmp/test.txt"));
|
assert!(json.contains("/tmp/test.txt"));
|
||||||
assert!(json.contains("test.txt"));
|
assert!(json.contains("test.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== CLI Parser Tests ====================
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_plugin_list_single_enabled() {
|
|
||||||
let output = r#"❯ macrodata@macrodata
|
|
||||||
Version: 0.1.3
|
|
||||||
Scope: user
|
|
||||||
Status: ✔ enabled"#;
|
|
||||||
|
|
||||||
let plugins = parse_plugin_list(output);
|
|
||||||
assert_eq!(plugins.len(), 1);
|
|
||||||
assert_eq!(plugins[0].name, "macrodata@macrodata");
|
|
||||||
assert_eq!(plugins[0].version, "0.1.3");
|
|
||||||
assert!(plugins[0].enabled);
|
|
||||||
assert_eq!(plugins[0].description, None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_plugin_list_single_disabled() {
|
|
||||||
let output = r#"❯ test-plugin@official
|
|
||||||
Version: 2.0.0
|
|
||||||
Status: ✘ disabled"#;
|
|
||||||
|
|
||||||
let plugins = parse_plugin_list(output);
|
|
||||||
assert_eq!(plugins.len(), 1);
|
|
||||||
assert_eq!(plugins[0].name, "test-plugin@official");
|
|
||||||
assert_eq!(plugins[0].version, "2.0.0");
|
|
||||||
assert!(!plugins[0].enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_plugin_list_multiple() {
|
|
||||||
let output = r#"❯ macrodata@macrodata
|
|
||||||
Version: 0.1.3
|
|
||||||
Status: ✔ enabled
|
|
||||||
|
|
||||||
❯ another-plugin@official
|
|
||||||
Version: 1.5.0
|
|
||||||
Status: ✘ disabled
|
|
||||||
|
|
||||||
❯ third-plugin@test
|
|
||||||
Version: 3.0.0-beta
|
|
||||||
Status: ✔ enabled"#;
|
|
||||||
|
|
||||||
let plugins = parse_plugin_list(output);
|
|
||||||
assert_eq!(plugins.len(), 3);
|
|
||||||
|
|
||||||
assert_eq!(plugins[0].name, "macrodata@macrodata");
|
|
||||||
assert_eq!(plugins[0].version, "0.1.3");
|
|
||||||
assert!(plugins[0].enabled);
|
|
||||||
|
|
||||||
assert_eq!(plugins[1].name, "another-plugin@official");
|
|
||||||
assert_eq!(plugins[1].version, "1.5.0");
|
|
||||||
assert!(!plugins[1].enabled);
|
|
||||||
|
|
||||||
assert_eq!(plugins[2].name, "third-plugin@test");
|
|
||||||
assert_eq!(plugins[2].version, "3.0.0-beta");
|
|
||||||
assert!(plugins[2].enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_plugin_list_empty() {
|
|
||||||
let output = "";
|
|
||||||
let plugins = parse_plugin_list(output);
|
|
||||||
assert_eq!(plugins.len(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_marketplace_list_single() {
|
|
||||||
let output = r#"Configured marketplaces:
|
|
||||||
|
|
||||||
❯ claude-plugins-official
|
|
||||||
Source: GitHub (anthropics/claude-plugins-official)"#;
|
|
||||||
|
|
||||||
let marketplaces = parse_marketplace_list(output);
|
|
||||||
assert_eq!(marketplaces.len(), 1);
|
|
||||||
assert_eq!(marketplaces[0].name, "claude-plugins-official");
|
|
||||||
assert_eq!(marketplaces[0].source, "GitHub (anthropics/claude-plugins-official)");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_marketplace_list_multiple() {
|
|
||||||
let output = r#"Configured marketplaces:
|
|
||||||
|
|
||||||
❯ claude-plugins-official
|
|
||||||
Source: GitHub (anthropics/claude-plugins-official)
|
|
||||||
|
|
||||||
❯ macrodata
|
|
||||||
Source: GitHub (ascorbic/macrodata)
|
|
||||||
|
|
||||||
❯ custom-marketplace
|
|
||||||
Source: GitHub (user/custom-marketplace)"#;
|
|
||||||
|
|
||||||
let marketplaces = parse_marketplace_list(output);
|
|
||||||
assert_eq!(marketplaces.len(), 3);
|
|
||||||
|
|
||||||
assert_eq!(marketplaces[0].name, "claude-plugins-official");
|
|
||||||
assert_eq!(marketplaces[1].name, "macrodata");
|
|
||||||
assert_eq!(marketplaces[2].name, "custom-marketplace");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_marketplace_list_empty() {
|
|
||||||
let output = "Configured marketplaces:\n\n";
|
|
||||||
let marketplaces = parse_marketplace_list(output);
|
|
||||||
assert_eq!(marketplaces.len(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_mcp_server_list_sse_connected() {
|
|
||||||
let output = "asana: https://mcp.asana.com/sse (SSE) - ✓ Connected";
|
|
||||||
|
|
||||||
let servers = parse_mcp_server_list(output);
|
|
||||||
assert_eq!(servers.len(), 1);
|
|
||||||
assert_eq!(servers[0].name, "asana");
|
|
||||||
assert_eq!(servers[0].url, Some("https://mcp.asana.com/sse".to_string()));
|
|
||||||
assert_eq!(servers[0].command, None);
|
|
||||||
assert_eq!(servers[0].transport, "sse");
|
|
||||||
assert_eq!(servers[0].status, Some("Connected".to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_mcp_server_list_http_connected() {
|
|
||||||
let output = "test-server: https://api.example.com/mcp (HTTP) - ✓ Connected";
|
|
||||||
|
|
||||||
let servers = parse_mcp_server_list(output);
|
|
||||||
assert_eq!(servers.len(), 1);
|
|
||||||
assert_eq!(servers[0].name, "test-server");
|
|
||||||
assert_eq!(servers[0].url, Some("https://api.example.com/mcp".to_string()));
|
|
||||||
assert_eq!(servers[0].transport, "http");
|
|
||||||
assert_eq!(servers[0].status, Some("Connected".to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_mcp_server_list_stdio_connected() {
|
|
||||||
let output = "gitea: gitea-mcp -t stdio --host https://git.nhcarrigan.com - ✓ Connected";
|
|
||||||
|
|
||||||
let servers = parse_mcp_server_list(output);
|
|
||||||
assert_eq!(servers.len(), 1);
|
|
||||||
assert_eq!(servers[0].name, "gitea");
|
|
||||||
assert_eq!(servers[0].url, None);
|
|
||||||
assert_eq!(servers[0].command, Some("gitea-mcp -t stdio --host https://git.nhcarrigan.com".to_string()));
|
|
||||||
assert_eq!(servers[0].transport, "stdio");
|
|
||||||
assert_eq!(servers[0].status, Some("Connected".to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_mcp_server_list_failed_connection() {
|
|
||||||
let output = "broken-server: https://invalid.com (SSE) - ✗ Failed to connect";
|
|
||||||
|
|
||||||
let servers = parse_mcp_server_list(output);
|
|
||||||
assert_eq!(servers.len(), 1);
|
|
||||||
assert_eq!(servers[0].name, "broken-server");
|
|
||||||
assert_eq!(servers[0].status, Some("Failed to connect".to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_mcp_server_list_multiple() {
|
|
||||||
let output = r#"asana: https://mcp.asana.com/sse (SSE) - ✓ Connected
|
|
||||||
gitea: gitea-mcp -t stdio (STDIO) - ✓ Connected
|
|
||||||
notion: https://mcp.notion.so (HTTP) - ✓ Connected"#;
|
|
||||||
|
|
||||||
let servers = parse_mcp_server_list(output);
|
|
||||||
assert_eq!(servers.len(), 3);
|
|
||||||
|
|
||||||
assert_eq!(servers[0].name, "asana");
|
|
||||||
assert_eq!(servers[0].transport, "sse");
|
|
||||||
|
|
||||||
assert_eq!(servers[1].name, "gitea");
|
|
||||||
assert_eq!(servers[1].transport, "stdio");
|
|
||||||
|
|
||||||
assert_eq!(servers[2].name, "notion");
|
|
||||||
assert_eq!(servers[2].transport, "http");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_mcp_server_list_with_checking_line() {
|
|
||||||
let output = r#"Checking MCP servers...
|
|
||||||
asana: https://mcp.asana.com/sse (SSE) - ✓ Connected"#;
|
|
||||||
|
|
||||||
let servers = parse_mcp_server_list(output);
|
|
||||||
assert_eq!(servers.len(), 1);
|
|
||||||
assert_eq!(servers[0].name, "asana");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_mcp_server_list_empty() {
|
|
||||||
let output = "";
|
|
||||||
let servers = parse_mcp_server_list(output);
|
|
||||||
assert_eq!(servers.len(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_mcp_server_list_plugin_provided() {
|
|
||||||
let output = "plugin:macrodata:macrodata: plugin macrodata - ✗ Failed to connect";
|
|
||||||
|
|
||||||
let servers = parse_mcp_server_list(output);
|
|
||||||
assert_eq!(servers.len(), 1);
|
|
||||||
assert_eq!(servers[0].name, "plugin:macrodata:macrodata");
|
|
||||||
assert_eq!(servers[0].command, Some("plugin macrodata".to_string()));
|
|
||||||
assert_eq!(servers[0].transport, "stdio");
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== Edge Case Tests ====================
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_plugin_list_with_unicode_names() {
|
|
||||||
let output = r#"❯ 日本語-plugin@marketplace
|
|
||||||
Version: 1.0.0
|
|
||||||
Status: ✔ enabled
|
|
||||||
|
|
||||||
❯ émoji-🎉-plugin@marketplace
|
|
||||||
Version: 2.0.0
|
|
||||||
Status: ✗ disabled"#;
|
|
||||||
|
|
||||||
let plugins = parse_plugin_list(output);
|
|
||||||
assert_eq!(plugins.len(), 2);
|
|
||||||
assert_eq!(plugins[0].name, "日本語-plugin@marketplace");
|
|
||||||
assert!(plugins[0].enabled);
|
|
||||||
assert_eq!(plugins[1].name, "émoji-🎉-plugin@marketplace");
|
|
||||||
assert!(!plugins[1].enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_plugin_list_missing_version() {
|
|
||||||
let output = r#"❯ broken-plugin@marketplace
|
|
||||||
Status: ✔ enabled"#;
|
|
||||||
|
|
||||||
let plugins = parse_plugin_list(output);
|
|
||||||
assert_eq!(plugins.len(), 1);
|
|
||||||
assert_eq!(plugins[0].name, "broken-plugin@marketplace");
|
|
||||||
assert_eq!(plugins[0].version, ""); // Empty version
|
|
||||||
assert!(plugins[0].enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_plugin_list_missing_status() {
|
|
||||||
let output = r#"❯ incomplete-plugin@marketplace
|
|
||||||
Version: 1.0.0"#;
|
|
||||||
|
|
||||||
let plugins = parse_plugin_list(output);
|
|
||||||
assert_eq!(plugins.len(), 1);
|
|
||||||
assert_eq!(plugins[0].name, "incomplete-plugin@marketplace");
|
|
||||||
assert_eq!(plugins[0].version, "1.0.0");
|
|
||||||
assert!(!plugins[0].enabled); // Defaults to false when status missing
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_marketplace_list_with_unicode() {
|
|
||||||
let output = r#"❯ 日本語-marketplace
|
|
||||||
Source: github/日本語/repo
|
|
||||||
|
|
||||||
❯ emoji-🚀-marketplace
|
|
||||||
Source: github/emoji/🚀-repo"#;
|
|
||||||
|
|
||||||
let marketplaces = parse_marketplace_list(output);
|
|
||||||
assert_eq!(marketplaces.len(), 2);
|
|
||||||
assert_eq!(marketplaces[0].name, "日本語-marketplace");
|
|
||||||
assert_eq!(marketplaces[0].source, "github/日本語/repo");
|
|
||||||
assert_eq!(marketplaces[1].name, "emoji-🚀-marketplace");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_mcp_server_list_with_unicode_names() {
|
|
||||||
let output = "日本語-server: https://example.com/日本語 (SSE) - ✓ Connected";
|
|
||||||
|
|
||||||
let servers = parse_mcp_server_list(output);
|
|
||||||
assert_eq!(servers.len(), 1);
|
|
||||||
assert_eq!(servers[0].name, "日本語-server");
|
|
||||||
assert_eq!(servers[0].url, Some("https://example.com/日本語".to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_mcp_server_list_very_long_command() {
|
|
||||||
let output = "long-cmd: some-binary --flag1 value1 --flag2 value2 --flag3 value3 --flag4 value4 --flag5 value5 --very-long-option with-a-very-long-value - ✓ Connected";
|
|
||||||
|
|
||||||
let servers = parse_mcp_server_list(output);
|
|
||||||
assert_eq!(servers.len(), 1);
|
|
||||||
assert_eq!(servers[0].name, "long-cmd");
|
|
||||||
assert_eq!(
|
|
||||||
servers[0].command,
|
|
||||||
Some("some-binary --flag1 value1 --flag2 value2 --flag3 value3 --flag4 value4 --flag5 value5 --very-long-option with-a-very-long-value".to_string())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_mcp_server_list_no_status() {
|
|
||||||
let output = "pending-server: https://example.com (HTTP)";
|
|
||||||
|
|
||||||
let servers = parse_mcp_server_list(output);
|
|
||||||
assert_eq!(servers.len(), 1);
|
|
||||||
assert_eq!(servers[0].name, "pending-server");
|
|
||||||
assert_eq!(servers[0].status, None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_plugin_list_with_extra_whitespace() {
|
|
||||||
let output = r#"❯ whitespace-plugin@marketplace
|
|
||||||
Version: 1.0.0
|
|
||||||
Status: ✔ enabled "#;
|
|
||||||
|
|
||||||
let plugins = parse_plugin_list(output);
|
|
||||||
assert_eq!(plugins.len(), 1);
|
|
||||||
assert_eq!(plugins[0].name, "whitespace-plugin@marketplace");
|
|
||||||
assert_eq!(plugins[0].version, "1.0.0");
|
|
||||||
assert!(plugins[0].enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_mcp_server_list_multiple_with_checking() {
|
|
||||||
let output = r#"Checking connections...
|
|
||||||
asana: https://mcp.asana.com/sse (SSE) - ✓ Connected
|
|
||||||
gitea: gitea-mcp -t stdio (STDIO) - ✓ Connected"#;
|
|
||||||
|
|
||||||
let servers = parse_mcp_server_list(output);
|
|
||||||
assert_eq!(servers.len(), 2); // Should ignore "Checking" line
|
|
||||||
assert_eq!(servers[0].name, "asana");
|
|
||||||
assert_eq!(servers[1].name, "gitea");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,12 +25,6 @@ pub struct ClaudeStartOptions {
|
|||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub resume_session_id: Option<String>,
|
pub resume_session_id: Option<String>,
|
||||||
|
|
||||||
#[serde(default)]
|
|
||||||
pub use_worktree: bool,
|
|
||||||
|
|
||||||
#[serde(default)]
|
|
||||||
pub disable_1m_context: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@@ -119,12 +113,6 @@ pub struct HikariConfig {
|
|||||||
|
|
||||||
#[serde(default = "default_discord_rpc_enabled")]
|
#[serde(default = "default_discord_rpc_enabled")]
|
||||||
pub discord_rpc_enabled: bool,
|
pub discord_rpc_enabled: bool,
|
||||||
|
|
||||||
#[serde(default)]
|
|
||||||
pub use_worktree: bool,
|
|
||||||
|
|
||||||
#[serde(default)]
|
|
||||||
pub disable_1m_context: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for HikariConfig {
|
impl Default for HikariConfig {
|
||||||
@@ -157,8 +145,6 @@ impl Default for HikariConfig {
|
|||||||
budget_action: BudgetAction::Warn,
|
budget_action: BudgetAction::Warn,
|
||||||
budget_warning_threshold: 0.8,
|
budget_warning_threshold: 0.8,
|
||||||
discord_rpc_enabled: true,
|
discord_rpc_enabled: true,
|
||||||
use_worktree: false,
|
|
||||||
disable_1m_context: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,8 +252,6 @@ mod tests {
|
|||||||
assert_eq!(config.budget_action, BudgetAction::Warn);
|
assert_eq!(config.budget_action, BudgetAction::Warn);
|
||||||
assert!((config.budget_warning_threshold - 0.8).abs() < f32::EPSILON);
|
assert!((config.budget_warning_threshold - 0.8).abs() < f32::EPSILON);
|
||||||
assert!(config.discord_rpc_enabled);
|
assert!(config.discord_rpc_enabled);
|
||||||
assert!(!config.use_worktree);
|
|
||||||
assert!(!config.disable_1m_context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -300,8 +284,6 @@ mod tests {
|
|||||||
budget_action: BudgetAction::Block,
|
budget_action: BudgetAction::Block,
|
||||||
budget_warning_threshold: 0.75,
|
budget_warning_threshold: 0.75,
|
||||||
discord_rpc_enabled: true,
|
discord_rpc_enabled: true,
|
||||||
use_worktree: true,
|
|
||||||
disable_1m_context: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let json = serde_json::to_string(&config).unwrap();
|
let json = serde_json::to_string(&config).unwrap();
|
||||||
|
|||||||
@@ -76,82 +76,3 @@ where
|
|||||||
let _ = self.app.emit("debug:log", log_event);
|
let _ = self.app.emit("debug:log", log_event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_debug_log_event_creation() {
|
|
||||||
let event = DebugLogEvent {
|
|
||||||
level: "info".to_string(),
|
|
||||||
message: "Test message".to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_eq!(event.level, "info");
|
|
||||||
assert_eq!(event.message, "Test message");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_debug_log_event_serialization() {
|
|
||||||
let event = DebugLogEvent {
|
|
||||||
level: "error".to_string(),
|
|
||||||
message: "Error occurred".to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let json = serde_json::to_string(&event).unwrap();
|
|
||||||
assert!(json.contains("\"level\":\"error\""));
|
|
||||||
assert!(json.contains("\"message\":\"Error occurred\""));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_debug_log_event_deserialization() {
|
|
||||||
let json = r#"{"level":"warn","message":"Warning message"}"#;
|
|
||||||
let event: DebugLogEvent = serde_json::from_str(json).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(event.level, "warn");
|
|
||||||
assert_eq!(event.message, "Warning message");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_debug_log_event_with_special_characters() {
|
|
||||||
let event = DebugLogEvent {
|
|
||||||
level: "info".to_string(),
|
|
||||||
message: "Message with \"quotes\" and \n newlines".to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let json = serde_json::to_string(&event).unwrap();
|
|
||||||
let decoded: DebugLogEvent = serde_json::from_str(&json).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(decoded.level, event.level);
|
|
||||||
assert_eq!(decoded.message, event.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_debug_log_event_with_unicode() {
|
|
||||||
let event = DebugLogEvent {
|
|
||||||
level: "debug".to_string(),
|
|
||||||
message: "Unicode: 日本語 🎉".to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let json = serde_json::to_string(&event).unwrap();
|
|
||||||
let decoded: DebugLogEvent = serde_json::from_str(&json).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(decoded.message, "Unicode: 日本語 🎉");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_debug_log_event_all_levels() {
|
|
||||||
let levels = vec!["error", "warn", "info", "debug", "trace"];
|
|
||||||
|
|
||||||
for level in levels {
|
|
||||||
let event = DebugLogEvent {
|
|
||||||
level: level.to_string(),
|
|
||||||
message: format!("{} level message", level),
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_eq!(event.level, level);
|
|
||||||
assert!(event.message.contains(level));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -195,9 +195,6 @@ pub fn run() {
|
|||||||
close_application,
|
close_application,
|
||||||
list_memory_files,
|
list_memory_files,
|
||||||
get_claude_version,
|
get_claude_version,
|
||||||
get_auth_status,
|
|
||||||
auth_login,
|
|
||||||
auth_logout,
|
|
||||||
list_plugins,
|
list_plugins,
|
||||||
install_plugin,
|
install_plugin,
|
||||||
uninstall_plugin,
|
uninstall_plugin,
|
||||||
|
|||||||
+29
-318
@@ -1,83 +1,6 @@
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use tauri::command;
|
use tauri::command;
|
||||||
|
|
||||||
/// Generate PowerShell script for Windows Toast Notification
|
|
||||||
fn generate_powershell_toast_script(title: &str, body: &str) -> String {
|
|
||||||
format!(
|
|
||||||
r#"
|
|
||||||
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
|
|
||||||
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] > $null
|
|
||||||
|
|
||||||
$APP_ID = 'Hikari Desktop'
|
|
||||||
|
|
||||||
$template = @"
|
|
||||||
<toast>
|
|
||||||
<visual>
|
|
||||||
<binding template="ToastText02">
|
|
||||||
<text id="1">{}</text>
|
|
||||||
<text id="2">{}</text>
|
|
||||||
</binding>
|
|
||||||
</visual>
|
|
||||||
<audio src="ms-winsoundevent:Notification.Default" />
|
|
||||||
</toast>
|
|
||||||
"@
|
|
||||||
|
|
||||||
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
|
|
||||||
$xml.LoadXml($template)
|
|
||||||
|
|
||||||
$toast = New-Object Windows.UI.Notifications.ToastNotification $xml
|
|
||||||
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($APP_ID).Show($toast)
|
|
||||||
"#,
|
|
||||||
title.replace("\"", "`\""),
|
|
||||||
body.replace("\"", "`\"")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Format simple notification message
|
|
||||||
fn format_simple_notification(title: &str, body: &str) -> String {
|
|
||||||
format!("{}\n\n{}", title, body)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Build notify-send command for testing (doesn't execute)
|
|
||||||
#[cfg(test)]
|
|
||||||
fn build_notify_send_command(title: &str, body: &str) -> (String, Vec<String>) {
|
|
||||||
(
|
|
||||||
"notify-send".to_string(),
|
|
||||||
vec![
|
|
||||||
title.to_string(),
|
|
||||||
body.to_string(),
|
|
||||||
"--urgency=normal".to_string(),
|
|
||||||
"--app-name=Hikari Desktop".to_string(),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Build Windows PowerShell command for testing (doesn't execute)
|
|
||||||
#[cfg(test)]
|
|
||||||
fn build_windows_powershell_command(title: &str, body: &str) -> (String, Vec<String>) {
|
|
||||||
let script = generate_powershell_toast_script(title, body);
|
|
||||||
(
|
|
||||||
"pwsh.exe".to_string(),
|
|
||||||
vec![
|
|
||||||
"-NoProfile".to_string(),
|
|
||||||
"-WindowStyle".to_string(),
|
|
||||||
"Hidden".to_string(),
|
|
||||||
"-Command".to_string(),
|
|
||||||
script,
|
|
||||||
],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Build simple notification command for testing (doesn't execute)
|
|
||||||
#[cfg(test)]
|
|
||||||
fn build_simple_notification_command(title: &str, body: &str) -> (String, Vec<String>) {
|
|
||||||
let message = format_simple_notification(title, body);
|
|
||||||
(
|
|
||||||
"cmd.exe".to_string(),
|
|
||||||
vec!["/c".to_string(), "msg".to_string(), "*".to_string(), message],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
pub async fn send_notify_send(title: String, body: String) -> Result<(), String> {
|
pub async fn send_notify_send(title: String, body: String) -> Result<(), String> {
|
||||||
// Use notify-send for Linux/WSL
|
// Use notify-send for Linux/WSL
|
||||||
@@ -105,7 +28,34 @@ pub async fn send_notify_send(title: String, body: String) -> Result<(), String>
|
|||||||
#[command]
|
#[command]
|
||||||
pub async fn send_windows_notification(title: String, body: String) -> Result<(), String> {
|
pub async fn send_windows_notification(title: String, body: String) -> Result<(), String> {
|
||||||
// Create PowerShell script for Windows Toast Notification
|
// Create PowerShell script for Windows Toast Notification
|
||||||
let ps_script = generate_powershell_toast_script(&title, &body);
|
let ps_script = format!(
|
||||||
|
r#"
|
||||||
|
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
|
||||||
|
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] > $null
|
||||||
|
|
||||||
|
$APP_ID = 'Hikari Desktop'
|
||||||
|
|
||||||
|
$template = @"
|
||||||
|
<toast>
|
||||||
|
<visual>
|
||||||
|
<binding template="ToastText02">
|
||||||
|
<text id="1">{}</text>
|
||||||
|
<text id="2">{}</text>
|
||||||
|
</binding>
|
||||||
|
</visual>
|
||||||
|
<audio src="ms-winsoundevent:Notification.Default" />
|
||||||
|
</toast>
|
||||||
|
"@
|
||||||
|
|
||||||
|
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
|
||||||
|
$xml.LoadXml($template)
|
||||||
|
|
||||||
|
$toast = New-Object Windows.UI.Notifications.ToastNotification $xml
|
||||||
|
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($APP_ID).Show($toast)
|
||||||
|
"#,
|
||||||
|
title.replace("\"", "`\""),
|
||||||
|
body.replace("\"", "`\"")
|
||||||
|
);
|
||||||
|
|
||||||
// Try PowerShell Core first (pwsh), then fall back to Windows PowerShell
|
// Try PowerShell Core first (pwsh), then fall back to Windows PowerShell
|
||||||
let output = Command::new("pwsh.exe")
|
let output = Command::new("pwsh.exe")
|
||||||
@@ -137,7 +87,7 @@ pub async fn send_windows_notification(title: String, body: String) -> Result<()
|
|||||||
// Alternative: Use Windows built-in MSG command for simple notifications
|
// Alternative: Use Windows built-in MSG command for simple notifications
|
||||||
#[command]
|
#[command]
|
||||||
pub async fn send_simple_notification(title: String, body: String) -> Result<(), String> {
|
pub async fn send_simple_notification(title: String, body: String) -> Result<(), String> {
|
||||||
let message = format_simple_notification(&title, &body);
|
let message = format!("{}\n\n{}", title, body);
|
||||||
|
|
||||||
Command::new("cmd.exe")
|
Command::new("cmd.exe")
|
||||||
.arg("/c")
|
.arg("/c")
|
||||||
@@ -149,242 +99,3 @@ pub async fn send_simple_notification(title: String, body: String) -> Result<(),
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_generate_powershell_toast_script_basic() {
|
|
||||||
let script = generate_powershell_toast_script("Title", "Body");
|
|
||||||
|
|
||||||
assert!(script.contains("Hikari Desktop"));
|
|
||||||
assert!(script.contains("Title"));
|
|
||||||
assert!(script.contains("Body"));
|
|
||||||
assert!(script.contains("ToastNotification"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_generate_powershell_toast_script_escapes_quotes() {
|
|
||||||
let script = generate_powershell_toast_script("Title with \"quotes\"", "Body with \"quotes\"");
|
|
||||||
|
|
||||||
// Quotes should be escaped as `" in PowerShell
|
|
||||||
assert!(script.contains("Title with `\"quotes`\""));
|
|
||||||
assert!(script.contains("Body with `\"quotes`\""));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_generate_powershell_toast_script_with_special_chars() {
|
|
||||||
let script = generate_powershell_toast_script("Title: Test", "Body\nwith\nnewlines");
|
|
||||||
|
|
||||||
assert!(script.contains("Title: Test"));
|
|
||||||
assert!(script.contains("Body\nwith\nnewlines"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_generate_powershell_toast_script_unicode() {
|
|
||||||
let script = generate_powershell_toast_script("日本語 Title", "Unicode: 🎉");
|
|
||||||
|
|
||||||
assert!(script.contains("日本語 Title"));
|
|
||||||
assert!(script.contains("Unicode: 🎉"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_generate_powershell_toast_script_empty() {
|
|
||||||
let script = generate_powershell_toast_script("", "");
|
|
||||||
|
|
||||||
// Should still contain the structure
|
|
||||||
assert!(script.contains("Hikari Desktop"));
|
|
||||||
assert!(script.contains("ToastNotification"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_format_simple_notification_basic() {
|
|
||||||
let message = format_simple_notification("Title", "Body");
|
|
||||||
|
|
||||||
assert_eq!(message, "Title\n\nBody");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_format_simple_notification_with_newlines() {
|
|
||||||
let message = format_simple_notification("Multi\nLine\nTitle", "Multi\nLine\nBody");
|
|
||||||
|
|
||||||
assert!(message.contains("Multi\nLine\nTitle"));
|
|
||||||
assert!(message.contains("\n\n"));
|
|
||||||
assert!(message.contains("Multi\nLine\nBody"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_format_simple_notification_unicode() {
|
|
||||||
let message = format_simple_notification("日本語", "🎉 Unicode");
|
|
||||||
|
|
||||||
assert_eq!(message, "日本語\n\n🎉 Unicode");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_format_simple_notification_empty() {
|
|
||||||
let message = format_simple_notification("", "");
|
|
||||||
|
|
||||||
assert_eq!(message, "\n\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_format_simple_notification_long_text() {
|
|
||||||
let long_title = "A".repeat(1000);
|
|
||||||
let long_body = "B".repeat(1000);
|
|
||||||
let message = format_simple_notification(&long_title, &long_body);
|
|
||||||
|
|
||||||
assert!(message.starts_with(&long_title));
|
|
||||||
assert!(message.ends_with(&long_body));
|
|
||||||
assert!(message.contains("\n\n"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_generate_powershell_toast_script_multiple_quotes() {
|
|
||||||
let script = generate_powershell_toast_script(
|
|
||||||
"\"Quoted\" \"Multiple\" \"Times\"",
|
|
||||||
"\"More\" \"Quotes\" \"Here\""
|
|
||||||
);
|
|
||||||
|
|
||||||
// Each quote should be escaped
|
|
||||||
assert!(script.contains("`\"Quoted`\" `\"Multiple`\" `\"Times`\""));
|
|
||||||
assert!(script.contains("`\"More`\" `\"Quotes`\" `\"Here`\""));
|
|
||||||
}
|
|
||||||
|
|
||||||
// E2E Integration Tests - Command Structure Verification
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_e2e_notify_send_command_structure() {
|
|
||||||
let (command, args) = build_notify_send_command("Test Title", "Test Body");
|
|
||||||
|
|
||||||
assert_eq!(command, "notify-send");
|
|
||||||
assert_eq!(args.len(), 4);
|
|
||||||
assert_eq!(args[0], "Test Title");
|
|
||||||
assert_eq!(args[1], "Test Body");
|
|
||||||
assert_eq!(args[2], "--urgency=normal");
|
|
||||||
assert_eq!(args[3], "--app-name=Hikari Desktop");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_e2e_notify_send_with_special_chars() {
|
|
||||||
let (command, args) =
|
|
||||||
build_notify_send_command("Title with \"quotes\"", "Body\nwith\nnewlines");
|
|
||||||
|
|
||||||
assert_eq!(command, "notify-send");
|
|
||||||
assert_eq!(args[0], "Title with \"quotes\"");
|
|
||||||
assert_eq!(args[1], "Body\nwith\nnewlines");
|
|
||||||
// notify-send handles these directly
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_e2e_windows_powershell_command_structure() {
|
|
||||||
let (command, args) = build_windows_powershell_command("Test Title", "Test Body");
|
|
||||||
|
|
||||||
assert_eq!(command, "pwsh.exe");
|
|
||||||
assert_eq!(args.len(), 5);
|
|
||||||
assert_eq!(args[0], "-NoProfile");
|
|
||||||
assert_eq!(args[1], "-WindowStyle");
|
|
||||||
assert_eq!(args[2], "Hidden");
|
|
||||||
assert_eq!(args[3], "-Command");
|
|
||||||
|
|
||||||
// Verify the script in args[4] contains expected elements
|
|
||||||
let script = &args[4];
|
|
||||||
assert!(script.contains("Test Title"));
|
|
||||||
assert!(script.contains("Test Body"));
|
|
||||||
assert!(script.contains("Hikari Desktop"));
|
|
||||||
assert!(script.contains("ToastNotification"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_e2e_windows_powershell_quote_escaping() {
|
|
||||||
let (_, args) =
|
|
||||||
build_windows_powershell_command("Title with \"quotes\"", "Body with \"quotes\"");
|
|
||||||
|
|
||||||
let script = &args[4];
|
|
||||||
// Verify quotes are properly escaped in the PowerShell script
|
|
||||||
assert!(script.contains("Title with `\"quotes`\""));
|
|
||||||
assert!(script.contains("Body with `\"quotes`\""));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_e2e_simple_notification_command_structure() {
|
|
||||||
let (command, args) = build_simple_notification_command("Test Title", "Test Body");
|
|
||||||
|
|
||||||
assert_eq!(command, "cmd.exe");
|
|
||||||
assert_eq!(args.len(), 4);
|
|
||||||
assert_eq!(args[0], "/c");
|
|
||||||
assert_eq!(args[1], "msg");
|
|
||||||
assert_eq!(args[2], "*");
|
|
||||||
assert_eq!(args[3], "Test Title\n\nTest Body");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_e2e_simple_notification_multiline() {
|
|
||||||
let (_, args) =
|
|
||||||
build_simple_notification_command("Multi\nLine\nTitle", "Multi\nLine\nBody");
|
|
||||||
|
|
||||||
let message = &args[3];
|
|
||||||
assert!(message.contains("Multi\nLine\nTitle"));
|
|
||||||
assert!(message.contains("\n\n"));
|
|
||||||
assert!(message.contains("Multi\nLine\nBody"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_e2e_command_consistency_across_platforms() {
|
|
||||||
// Test that different platforms use consistent parameters
|
|
||||||
let title = "Consistency Test";
|
|
||||||
let body = "Testing cross-platform consistency";
|
|
||||||
|
|
||||||
// Linux command
|
|
||||||
let (notify_cmd, notify_args) = build_notify_send_command(title, body);
|
|
||||||
assert!(notify_cmd.contains("notify"));
|
|
||||||
assert!(notify_args.iter().any(|arg| arg.contains("Hikari Desktop")));
|
|
||||||
|
|
||||||
// Windows PowerShell command
|
|
||||||
let (ps_cmd, ps_args) = build_windows_powershell_command(title, body);
|
|
||||||
assert!(ps_cmd.contains("pwsh") || ps_cmd.contains("powershell"));
|
|
||||||
let ps_script = &ps_args[4];
|
|
||||||
assert!(ps_script.contains("Hikari Desktop"));
|
|
||||||
|
|
||||||
// Windows simple command
|
|
||||||
let (msg_cmd, msg_args) = build_simple_notification_command(title, body);
|
|
||||||
assert!(msg_cmd.contains("cmd"));
|
|
||||||
assert!(msg_args[3].contains(title));
|
|
||||||
assert!(msg_args[3].contains(body));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_e2e_unicode_support_across_platforms() {
|
|
||||||
let title = "日本語 Title";
|
|
||||||
let body = "Unicode: 🎉";
|
|
||||||
|
|
||||||
// Verify all platforms preserve unicode
|
|
||||||
let (_, notify_args) = build_notify_send_command(title, body);
|
|
||||||
assert_eq!(notify_args[0], title);
|
|
||||||
assert_eq!(notify_args[1], body);
|
|
||||||
|
|
||||||
let (_, ps_args) = build_windows_powershell_command(title, body);
|
|
||||||
let ps_script = &ps_args[4];
|
|
||||||
assert!(ps_script.contains(title));
|
|
||||||
assert!(ps_script.contains(body));
|
|
||||||
|
|
||||||
let (_, msg_args) = build_simple_notification_command(title, body);
|
|
||||||
assert!(msg_args[3].contains(title));
|
|
||||||
assert!(msg_args[3].contains(body));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_e2e_empty_input_handling() {
|
|
||||||
// Test that empty inputs are handled gracefully
|
|
||||||
let (_, notify_args) = build_notify_send_command("", "");
|
|
||||||
assert_eq!(notify_args[0], "");
|
|
||||||
assert_eq!(notify_args[1], "");
|
|
||||||
|
|
||||||
let (_, ps_args) = build_windows_powershell_command("", "");
|
|
||||||
let ps_script = &ps_args[4];
|
|
||||||
assert!(ps_script.contains("Hikari Desktop")); // Still has app name
|
|
||||||
|
|
||||||
let (_, msg_args) = build_simple_notification_command("", "");
|
|
||||||
assert_eq!(msg_args[3], "\n\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -86,9 +86,8 @@ impl ContextWarning {
|
|||||||
/// Get the context window limit (in tokens) for a given model
|
/// Get the context window limit (in tokens) for a given model
|
||||||
fn get_context_window_limit(model: &str) -> u64 {
|
fn get_context_window_limit(model: &str) -> u64 {
|
||||||
match model {
|
match model {
|
||||||
// Claude 4.6 family
|
// Claude 4.6 family - 200K standard (1M beta available via header)
|
||||||
"claude-opus-4-6" => 200_000,
|
"claude-opus-4-6" => 200_000,
|
||||||
"claude-sonnet-4-6" => 1_000_000, // 1M token context window
|
|
||||||
// Claude 4.5 family - 200K standard context
|
// Claude 4.5 family - 200K standard context
|
||||||
"claude-opus-4-5-20251101"
|
"claude-opus-4-5-20251101"
|
||||||
| "claude-sonnet-4-5-20250929"
|
| "claude-sonnet-4-5-20250929"
|
||||||
@@ -503,7 +502,6 @@ pub fn calculate_cost(
|
|||||||
let (input_price_per_million, output_price_per_million) = match model {
|
let (input_price_per_million, output_price_per_million) = match model {
|
||||||
// Current generation (Claude 4.6)
|
// Current generation (Claude 4.6)
|
||||||
"claude-opus-4-6" => (5.0, 25.0),
|
"claude-opus-4-6" => (5.0, 25.0),
|
||||||
"claude-sonnet-4-6" => (3.0, 15.0),
|
|
||||||
|
|
||||||
// Previous generation (Claude 4.5)
|
// Previous generation (Claude 4.5)
|
||||||
"claude-opus-4-5-20251101" => (5.0, 25.0),
|
"claude-opus-4-5-20251101" => (5.0, 25.0),
|
||||||
|
|||||||
@@ -63,26 +63,6 @@ pub struct PermissionDenial {
|
|||||||
pub tool_input: serde_json::Value,
|
pub tool_input: serde_json::Value,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rate limit information from a `rate_limit_event` message.
|
|
||||||
/// All fields are optional to ensure forward-compatibility as the Claude CLI evolves.
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
|
||||||
pub struct RateLimitInfo {
|
|
||||||
#[serde(default)]
|
|
||||||
pub requests_limit: Option<u64>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub requests_remaining: Option<u64>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub requests_reset: Option<String>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub tokens_limit: Option<u64>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub tokens_remaining: Option<u64>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub tokens_reset: Option<String>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub retry_after_ms: Option<u64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
pub enum ClaudeMessage {
|
pub enum ClaudeMessage {
|
||||||
@@ -120,11 +100,6 @@ pub enum ClaudeMessage {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
usage: Option<UsageInfo>,
|
usage: Option<UsageInfo>,
|
||||||
},
|
},
|
||||||
#[serde(rename = "rate_limit_event")]
|
|
||||||
RateLimitEvent {
|
|
||||||
#[serde(default)]
|
|
||||||
rate_limit_info: RateLimitInfo,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@@ -305,8 +280,6 @@ pub struct AgentEndEvent {
|
|||||||
pub duration_ms: Option<u64>,
|
pub duration_ms: Option<u64>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub num_turns: Option<u32>,
|
pub num_turns: Option<u32>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub last_assistant_message: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@@ -473,77 +446,4 @@ mod tests {
|
|||||||
assert!(serialized.contains("\"input_tokens\":100"));
|
assert!(serialized.contains("\"input_tokens\":100"));
|
||||||
assert!(serialized.contains("\"output_tokens\":50"));
|
assert!(serialized.contains("\"output_tokens\":50"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_rate_limit_info_default() {
|
|
||||||
let info = RateLimitInfo::default();
|
|
||||||
assert!(info.requests_limit.is_none());
|
|
||||||
assert!(info.requests_remaining.is_none());
|
|
||||||
assert!(info.requests_reset.is_none());
|
|
||||||
assert!(info.tokens_limit.is_none());
|
|
||||||
assert!(info.tokens_remaining.is_none());
|
|
||||||
assert!(info.tokens_reset.is_none());
|
|
||||||
assert!(info.retry_after_ms.is_none());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_rate_limit_event_deserialization_empty_info() {
|
|
||||||
let json = r#"{"type":"rate_limit_event","rate_limit_info":{}}"#;
|
|
||||||
let msg: ClaudeMessage = serde_json::from_str(json).unwrap();
|
|
||||||
assert!(matches!(msg, ClaudeMessage::RateLimitEvent { .. }));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_rate_limit_event_deserialization_no_info() {
|
|
||||||
// rate_limit_info field is optional via #[serde(default)]
|
|
||||||
let json = r#"{"type":"rate_limit_event"}"#;
|
|
||||||
let msg: ClaudeMessage = serde_json::from_str(json).unwrap();
|
|
||||||
assert!(matches!(msg, ClaudeMessage::RateLimitEvent { .. }));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_rate_limit_event_deserialization_with_data() {
|
|
||||||
let json = r#"{
|
|
||||||
"type": "rate_limit_event",
|
|
||||||
"rate_limit_info": {
|
|
||||||
"requests_limit": 1000,
|
|
||||||
"requests_remaining": 0,
|
|
||||||
"requests_reset": "2024-01-01T00:01:00Z",
|
|
||||||
"tokens_limit": 50000,
|
|
||||||
"tokens_remaining": 0,
|
|
||||||
"tokens_reset": "2024-01-01T00:01:00Z",
|
|
||||||
"retry_after_ms": 60000
|
|
||||||
}
|
|
||||||
}"#;
|
|
||||||
let msg: ClaudeMessage = serde_json::from_str(json).unwrap();
|
|
||||||
if let ClaudeMessage::RateLimitEvent { rate_limit_info } = msg {
|
|
||||||
assert_eq!(rate_limit_info.requests_limit, Some(1000));
|
|
||||||
assert_eq!(rate_limit_info.requests_remaining, Some(0));
|
|
||||||
assert_eq!(
|
|
||||||
rate_limit_info.requests_reset,
|
|
||||||
Some("2024-01-01T00:01:00Z".to_string())
|
|
||||||
);
|
|
||||||
assert_eq!(rate_limit_info.retry_after_ms, Some(60000));
|
|
||||||
} else {
|
|
||||||
panic!("Expected RateLimitEvent variant");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_rate_limit_event_ignores_unknown_fields() {
|
|
||||||
// Ensures forward-compat: unknown fields in rate_limit_info are silently ignored
|
|
||||||
let json = r#"{
|
|
||||||
"type": "rate_limit_event",
|
|
||||||
"rate_limit_info": {
|
|
||||||
"requests_remaining": 0,
|
|
||||||
"some_future_field": "some_value"
|
|
||||||
}
|
|
||||||
}"#;
|
|
||||||
let msg: ClaudeMessage = serde_json::from_str(json).unwrap();
|
|
||||||
if let ClaudeMessage::RateLimitEvent { rate_limit_info } = msg {
|
|
||||||
assert_eq!(rate_limit_info.requests_remaining, Some(0));
|
|
||||||
} else {
|
|
||||||
panic!("Expected RateLimitEvent variant");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-554
@@ -39,12 +39,6 @@ const SEARCH_TOOLS: [&str; 5] = ["Read", "Glob", "Grep", "WebSearch", "WebFetch"
|
|||||||
const CODING_TOOLS: [&str; 3] = ["Edit", "Write", "NotebookEdit"];
|
const CODING_TOOLS: [&str; 3] = ["Edit", "Write", "NotebookEdit"];
|
||||||
|
|
||||||
fn detect_wsl() -> bool {
|
fn detect_wsl() -> bool {
|
||||||
// A native Windows binary is never running inside WSL, even if launched from a WSL
|
|
||||||
// terminal that has WSL_DISTRO_NAME set in its environment.
|
|
||||||
if cfg!(target_os = "windows") {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check /proc/version for WSL indicators
|
// Check /proc/version for WSL indicators
|
||||||
if let Ok(version) = std::fs::read_to_string("/proc/version") {
|
if let Ok(version) = std::fs::read_to_string("/proc/version") {
|
||||||
let version_lower = version.to_lowercase();
|
let version_lower = version.to_lowercase();
|
||||||
@@ -67,29 +61,23 @@ fn detect_wsl() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn find_claude_binary() -> Option<String> {
|
fn find_claude_binary() -> Option<String> {
|
||||||
// Check common installation locations for claude (when HOME is available)
|
// Check common installation locations for claude
|
||||||
if let Ok(home) = std::env::var("HOME") {
|
let home = std::env::var("HOME").ok()?;
|
||||||
let paths_to_check = [
|
let paths_to_check = [
|
||||||
format!("{}/.local/bin/claude", home),
|
format!("{}/.local/bin/claude", home),
|
||||||
format!("{}/.claude/local/claude", home),
|
format!("{}/.claude/local/claude", home),
|
||||||
|
"/usr/local/bin/claude".to_string(),
|
||||||
|
"/usr/bin/claude".to_string(),
|
||||||
];
|
];
|
||||||
|
|
||||||
for path in &paths_to_check {
|
for path in &paths_to_check {
|
||||||
if std::path::Path::new(path).exists() {
|
if std::path::Path::new(path).exists() {
|
||||||
return Some(path.clone());
|
return Some(path.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Check system-wide locations
|
// Fall back to checking PATH via which
|
||||||
for path in &["/usr/local/bin/claude", "/usr/bin/claude"] {
|
if let Ok(output) = Command::new("which").arg("claude").output() {
|
||||||
if std::path::Path::new(path).exists() {
|
|
||||||
return Some((*path).to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use a login shell to resolve claude via the user's PATH - GUI apps don't
|
|
||||||
// inherit shell PATH, so bare `which` may miss ~/.local/bin entries
|
|
||||||
if let Ok(output) = Command::new("bash").args(["-lc", "which claude"]).output() {
|
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
let path = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
let path = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
||||||
if !path.is_empty() {
|
if !path.is_empty() {
|
||||||
@@ -137,15 +125,6 @@ impl WslBridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(&mut self, app: AppHandle, options: ClaudeStartOptions) -> Result<(), String> {
|
pub fn start(&mut self, app: AppHandle, options: ClaudeStartOptions) -> Result<(), String> {
|
||||||
// If a process handle exists but the process has already exited (e.g. due to a
|
|
||||||
// failed working directory), clean up the stale handle so we can restart cleanly.
|
|
||||||
if let Some(ref mut process) = self.process {
|
|
||||||
if process.try_wait().map(|s| s.is_some()).unwrap_or(false) {
|
|
||||||
self.process = None;
|
|
||||||
self.stdin = None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.process.is_some() {
|
if self.process.is_some() {
|
||||||
return Err("Process already running".to_string());
|
return Err("Process already running".to_string());
|
||||||
}
|
}
|
||||||
@@ -265,11 +244,6 @@ impl WslBridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add worktree flag if requested
|
|
||||||
if options.use_worktree {
|
|
||||||
cmd.arg("--worktree");
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.current_dir(working_dir);
|
cmd.current_dir(working_dir);
|
||||||
|
|
||||||
// Set API key as environment variable if specified
|
// Set API key as environment variable if specified
|
||||||
@@ -279,39 +253,10 @@ impl WslBridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable 1M context window if requested
|
|
||||||
if options.disable_1m_context {
|
|
||||||
cmd.env("CLAUDE_CODE_DISABLE_1M_CONTEXT", "1");
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd
|
cmd
|
||||||
} else {
|
} else {
|
||||||
// Running on Windows - use wsl with bash login shell to ensure PATH is loaded
|
// Running on Windows - use wsl with bash login shell to ensure PATH is loaded
|
||||||
tracing::debug!("Windows path - using wsl");
|
tracing::debug!("Windows path - using wsl");
|
||||||
|
|
||||||
// Check if Claude binary is installed inside WSL
|
|
||||||
let binary_check = Command::new("wsl")
|
|
||||||
.args(["-e", "bash", "-lc", "which claude"])
|
|
||||||
.output();
|
|
||||||
if let Ok(output) = binary_check {
|
|
||||||
if !output.status.success() {
|
|
||||||
return Err("Claude Code is not installed. Please install it using:\n\ncurl -fsSL https://claude.ai/install.sh | bash".to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate the working directory exists inside WSL before spawning
|
|
||||||
let dir_check = Command::new("wsl")
|
|
||||||
.args(["-e", "test", "-d", working_dir])
|
|
||||||
.output();
|
|
||||||
if let Ok(output) = dir_check {
|
|
||||||
if !output.status.success() {
|
|
||||||
return Err(format!(
|
|
||||||
"Working directory does not exist: {}",
|
|
||||||
working_dir
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut cmd = Command::new("wsl");
|
let mut cmd = Command::new("wsl");
|
||||||
|
|
||||||
// Build the claude command with all arguments
|
// Build the claude command with all arguments
|
||||||
@@ -324,11 +269,6 @@ impl WslBridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable 1M context window if requested
|
|
||||||
if options.disable_1m_context {
|
|
||||||
claude_cmd.push_str("CLAUDE_CODE_DISABLE_1M_CONTEXT=1 ");
|
|
||||||
}
|
|
||||||
|
|
||||||
claude_cmd.push_str(
|
claude_cmd.push_str(
|
||||||
"claude --output-format stream-json --input-format stream-json --verbose",
|
"claude --output-format stream-json --input-format stream-json --verbose",
|
||||||
);
|
);
|
||||||
@@ -366,11 +306,6 @@ impl WslBridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add worktree flag if requested
|
|
||||||
if options.use_worktree {
|
|
||||||
claude_cmd.push_str(" --worktree");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use bash -lc to load login profile (ensures PATH includes claude)
|
// Use bash -lc to load login profile (ensures PATH includes claude)
|
||||||
cmd.args(["-e", "bash", "-lc", &claude_cmd]);
|
cmd.args(["-e", "bash", "-lc", &claude_cmd]);
|
||||||
|
|
||||||
@@ -743,50 +678,11 @@ fn handle_stderr(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this is a SubagentStop hook message
|
// Still emit the stderr line as output
|
||||||
if line.contains("[SubagentStop Hook]") {
|
|
||||||
if let Some(stop_data) = parse_subagent_stop_hook(&line) {
|
|
||||||
tracing::debug!("Parsed SubagentStop hook: tool_use_id={:?}",
|
|
||||||
stop_data.parent_tool_use_id);
|
|
||||||
|
|
||||||
// Emit agent-end event if we have a tool_use_id
|
|
||||||
if let Some(tool_use_id) = stop_data.parent_tool_use_id {
|
|
||||||
let now = std::time::SystemTime::now()
|
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
|
||||||
.unwrap_or_default()
|
|
||||||
.as_millis() as u64;
|
|
||||||
|
|
||||||
let _ = app.emit(
|
|
||||||
"claude:agent-end",
|
|
||||||
AgentEndEvent {
|
|
||||||
tool_use_id,
|
|
||||||
ended_at: now,
|
|
||||||
is_error: false,
|
|
||||||
conversation_id: conversation_id.clone(),
|
|
||||||
duration_ms: None,
|
|
||||||
num_turns: None,
|
|
||||||
last_assistant_message: stop_data.last_assistant_message,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hook events are informational — emit with distinct types instead of error
|
|
||||||
let line_type = if line.contains("[WorktreeCreate Hook]")
|
|
||||||
|| line.contains("[WorktreeRemove Hook]")
|
|
||||||
{
|
|
||||||
"worktree"
|
|
||||||
} else if line.contains("[ConfigChange Hook]") {
|
|
||||||
"config-change"
|
|
||||||
} else {
|
|
||||||
"error"
|
|
||||||
};
|
|
||||||
|
|
||||||
let _ = app.emit(
|
let _ = app.emit(
|
||||||
"claude:output",
|
"claude:output",
|
||||||
OutputEvent {
|
OutputEvent {
|
||||||
line_type: line_type.to_string(),
|
line_type: "error".to_string(),
|
||||||
content: line,
|
content: line,
|
||||||
tool_name: None,
|
tool_name: None,
|
||||||
conversation_id: conversation_id.clone(),
|
conversation_id: conversation_id.clone(),
|
||||||
@@ -836,81 +732,6 @@ fn parse_subagent_start_hook(line: &str) -> Option<SubagentStartData> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct SubagentStopData {
|
|
||||||
parent_tool_use_id: Option<String>,
|
|
||||||
last_assistant_message: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Extracts the content of a Rust Debug-formatted `Some("...")` field from a hook line.
|
|
||||||
/// Handles escaped characters (e.g. `\"` → `"`, `\\` → `\`, `\n` → newline).
|
|
||||||
/// Returns `None` if the field is absent or formatted as `None`.
|
|
||||||
fn extract_debug_string_value(line: &str, key: &str) -> Option<String> {
|
|
||||||
let prefix = format!("{}=Some(\"", key);
|
|
||||||
let start_idx = line.find(&prefix)? + prefix.len();
|
|
||||||
let rest = &line[start_idx..];
|
|
||||||
|
|
||||||
let mut result = String::new();
|
|
||||||
let mut chars = rest.chars();
|
|
||||||
loop {
|
|
||||||
match chars.next() {
|
|
||||||
Some('"') => return Some(result),
|
|
||||||
Some('\\') => match chars.next() {
|
|
||||||
Some('n') => result.push('\n'),
|
|
||||||
Some('t') => result.push('\t'),
|
|
||||||
Some('"') => result.push('"'),
|
|
||||||
Some('\\') => result.push('\\'),
|
|
||||||
Some(c) => {
|
|
||||||
result.push('\\');
|
|
||||||
result.push(c);
|
|
||||||
}
|
|
||||||
None => break,
|
|
||||||
},
|
|
||||||
Some(c) => result.push(c),
|
|
||||||
None => break,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_subagent_stop_hook(line: &str) -> Option<SubagentStopData> {
|
|
||||||
// Parse: [SubagentStop Hook] ... parent_tool_use_id=Some("toolu_xxx"), last_assistant_message=Some("..."), ...
|
|
||||||
|
|
||||||
let parent_tool_use_id = extract_debug_string_value(line, "parent_tool_use_id");
|
|
||||||
let last_assistant_message = extract_debug_string_value(line, "last_assistant_message");
|
|
||||||
|
|
||||||
Some(SubagentStopData {
|
|
||||||
parent_tool_use_id,
|
|
||||||
last_assistant_message,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Extract text content from a ToolResult's `content` field.
|
|
||||||
/// The content may be a JSON string or an array of typed content blocks.
|
|
||||||
fn extract_tool_result_text(content: &serde_json::Value) -> Option<String> {
|
|
||||||
match content {
|
|
||||||
serde_json::Value::String(s) if !s.is_empty() => Some(s.clone()),
|
|
||||||
serde_json::Value::Array(blocks) => {
|
|
||||||
let texts: Vec<String> = blocks
|
|
||||||
.iter()
|
|
||||||
.filter_map(|block| {
|
|
||||||
if block.get("type")?.as_str()? == "text" {
|
|
||||||
block.get("text")?.as_str().map(String::from)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
if texts.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(texts.join("\n"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn process_json_line(
|
fn process_json_line(
|
||||||
line: &str,
|
line: &str,
|
||||||
app: &AppHandle,
|
app: &AppHandle,
|
||||||
@@ -1164,37 +985,17 @@ fn process_json_line(
|
|||||||
stats.write().increment_code_blocks();
|
stats.write().increment_code_blocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_prompt_too_long = text.starts_with("Prompt is too long");
|
|
||||||
|
|
||||||
let _ = app.emit(
|
let _ = app.emit(
|
||||||
"claude:output",
|
"claude:output",
|
||||||
OutputEvent {
|
OutputEvent {
|
||||||
line_type: if is_prompt_too_long {
|
line_type: "assistant".to_string(),
|
||||||
"error".to_string()
|
|
||||||
} else {
|
|
||||||
"assistant".to_string()
|
|
||||||
},
|
|
||||||
content: text.clone(),
|
content: text.clone(),
|
||||||
tool_name: None,
|
tool_name: None,
|
||||||
conversation_id: conversation_id.clone(),
|
conversation_id: conversation_id.clone(),
|
||||||
cost: message_cost.clone(),
|
cost: message_cost.clone(), // Include cost with assistant text
|
||||||
parent_tool_use_id: parent_tool_use_id.clone(),
|
parent_tool_use_id: parent_tool_use_id.clone(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if is_prompt_too_long {
|
|
||||||
let _ = app.emit(
|
|
||||||
"claude:output",
|
|
||||||
OutputEvent {
|
|
||||||
line_type: "compact-prompt".to_string(),
|
|
||||||
content: String::new(),
|
|
||||||
tool_name: None,
|
|
||||||
conversation_id: conversation_id.clone(),
|
|
||||||
cost: None,
|
|
||||||
parent_tool_use_id: None,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ContentBlock::Thinking { thinking } => {
|
ContentBlock::Thinking { thinking } => {
|
||||||
state = CharacterState::Thinking;
|
state = CharacterState::Thinking;
|
||||||
@@ -1212,8 +1013,8 @@ fn process_json_line(
|
|||||||
}
|
}
|
||||||
ContentBlock::ToolResult {
|
ContentBlock::ToolResult {
|
||||||
tool_use_id,
|
tool_use_id,
|
||||||
content,
|
|
||||||
is_error,
|
is_error,
|
||||||
|
..
|
||||||
} => {
|
} => {
|
||||||
// Emit agent-end for all tool results
|
// Emit agent-end for all tool results
|
||||||
// The frontend will ignore IDs that don't match known agents
|
// The frontend will ignore IDs that don't match known agents
|
||||||
@@ -1231,7 +1032,6 @@ fn process_json_line(
|
|||||||
conversation_id: conversation_id.clone(),
|
conversation_id: conversation_id.clone(),
|
||||||
duration_ms: None,
|
duration_ms: None,
|
||||||
num_turns: None,
|
num_turns: None,
|
||||||
last_assistant_message: extract_tool_result_text(content),
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1624,23 +1424,6 @@ fn process_json_line(
|
|||||||
emit_state_change(app, state, None, conversation_id.clone());
|
emit_state_change(app, state, None, conversation_id.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
ClaudeMessage::RateLimitEvent { rate_limit_info } => {
|
|
||||||
tracing::warn!("Rate limit event received: {:?}", rate_limit_info);
|
|
||||||
|
|
||||||
let content = format_rate_limit_message(rate_limit_info);
|
|
||||||
let _ = app.emit(
|
|
||||||
"claude:output",
|
|
||||||
OutputEvent {
|
|
||||||
line_type: "rate-limit".to_string(),
|
|
||||||
content,
|
|
||||||
tool_name: None,
|
|
||||||
conversation_id: conversation_id.clone(),
|
|
||||||
cost: None,
|
|
||||||
parent_tool_use_id: None,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
ClaudeMessage::User { message } => {
|
ClaudeMessage::User { message } => {
|
||||||
// Increment message count for user messages
|
// Increment message count for user messages
|
||||||
stats.write().increment_messages();
|
stats.write().increment_messages();
|
||||||
@@ -1649,8 +1432,8 @@ fn process_json_line(
|
|||||||
for block in &message.content {
|
for block in &message.content {
|
||||||
if let ContentBlock::ToolResult {
|
if let ContentBlock::ToolResult {
|
||||||
tool_use_id,
|
tool_use_id,
|
||||||
content,
|
|
||||||
is_error,
|
is_error,
|
||||||
|
..
|
||||||
} = block
|
} = block
|
||||||
{
|
{
|
||||||
let now = SystemTime::now()
|
let now = SystemTime::now()
|
||||||
@@ -1667,7 +1450,6 @@ fn process_json_line(
|
|||||||
conversation_id: conversation_id.clone(),
|
conversation_id: conversation_id.clone(),
|
||||||
duration_ms: None,
|
duration_ms: None,
|
||||||
num_turns: None,
|
num_turns: None,
|
||||||
last_assistant_message: extract_tool_result_text(content),
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1750,35 +1532,6 @@ fn get_tool_state(tool_name: &str) -> CharacterState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_rate_limit_message(info: &crate::types::RateLimitInfo) -> String {
|
|
||||||
let mut parts = Vec::new();
|
|
||||||
|
|
||||||
if let (Some(remaining), Some(limit)) = (info.requests_remaining, info.requests_limit) {
|
|
||||||
parts.push(format!("requests: {}/{}", remaining, limit));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let (Some(remaining), Some(limit)) = (info.tokens_remaining, info.tokens_limit) {
|
|
||||||
parts.push(format!("tokens: {}/{}", remaining, limit));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(reset) = &info.requests_reset {
|
|
||||||
parts.push(format!("resets at {}", reset));
|
|
||||||
} else if let Some(reset) = &info.tokens_reset {
|
|
||||||
parts.push(format!("resets at {}", reset));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(retry_ms) = info.retry_after_ms {
|
|
||||||
let secs = retry_ms / 1000;
|
|
||||||
parts.push(format!("retry after {}s", secs));
|
|
||||||
}
|
|
||||||
|
|
||||||
if parts.is_empty() {
|
|
||||||
"Rate limit reached".to_string()
|
|
||||||
} else {
|
|
||||||
format!("Rate limit reached — {}", parts.join(", "))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn format_tool_description(name: &str, input: &serde_json::Value) -> String {
|
fn format_tool_description(name: &str, input: &serde_json::Value) -> String {
|
||||||
// Helper function to check if a path is a memory file
|
// Helper function to check if a path is a memory file
|
||||||
fn is_memory_path(path: &str) -> bool {
|
fn is_memory_path(path: &str) -> bool {
|
||||||
@@ -1839,7 +1592,12 @@ fn format_tool_description(name: &str, input: &serde_json::Value) -> String {
|
|||||||
}
|
}
|
||||||
"Bash" => {
|
"Bash" => {
|
||||||
if let Some(cmd) = input.get("command").and_then(|v| v.as_str()) {
|
if let Some(cmd) = input.get("command").and_then(|v| v.as_str()) {
|
||||||
format!("Running: {}", cmd)
|
let truncated = if cmd.len() > 50 {
|
||||||
|
format!("{}...", &cmd[..50])
|
||||||
|
} else {
|
||||||
|
cmd.to_string()
|
||||||
|
};
|
||||||
|
format!("Running: {}", truncated)
|
||||||
} else {
|
} else {
|
||||||
"Running command...".to_string()
|
"Running command...".to_string()
|
||||||
}
|
}
|
||||||
@@ -2000,7 +1758,9 @@ mod tests {
|
|||||||
let long_cmd = "a".repeat(100);
|
let long_cmd = "a".repeat(100);
|
||||||
let input = serde_json::json!({"command": long_cmd});
|
let input = serde_json::json!({"command": long_cmd});
|
||||||
let desc = format_tool_description("Bash", &input);
|
let desc = format_tool_description("Bash", &input);
|
||||||
assert_eq!(desc, format!("Running: {}", long_cmd));
|
assert!(desc.starts_with("Running: "));
|
||||||
|
assert!(desc.ends_with("..."));
|
||||||
|
assert!(desc.len() < 70);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -2056,69 +1816,6 @@ mod tests {
|
|||||||
assert!(!bridge.is_running());
|
assert!(!bridge.is_running());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_stale_process_detection_with_try_wait() {
|
|
||||||
// Spawn a real process that exits immediately so we can verify try_wait detects it
|
|
||||||
let mut child = Command::new("true").spawn().expect("Failed to spawn 'true'");
|
|
||||||
|
|
||||||
// Wait for it to exit
|
|
||||||
let _ = child.wait();
|
|
||||||
|
|
||||||
// try_wait on an already-exited process should return Some(_)
|
|
||||||
let status = child.try_wait();
|
|
||||||
assert!(
|
|
||||||
status.is_ok(),
|
|
||||||
"try_wait should not error on an exited process"
|
|
||||||
);
|
|
||||||
// The process has already been waited on, so try_wait might return None or Some
|
|
||||||
// depending on the OS - what matters is that the call succeeds
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_stale_process_is_some_after_exit() {
|
|
||||||
// Verify the logic used in start(): a process that has exited is detected
|
|
||||||
// and the handle is cleaned up so start() can proceed
|
|
||||||
let mut child = Command::new("true").spawn().expect("Failed to spawn 'true'");
|
|
||||||
|
|
||||||
// Let it exit
|
|
||||||
let _ = child.wait();
|
|
||||||
|
|
||||||
// This mirrors the check in start()
|
|
||||||
let has_exited = child
|
|
||||||
.try_wait()
|
|
||||||
.map(|s| s.is_some())
|
|
||||||
.unwrap_or(false);
|
|
||||||
|
|
||||||
// After wait(), try_wait() returns None (already reaped), which means
|
|
||||||
// unwrap_or(false) → false. The important thing is the call doesn't panic
|
|
||||||
// and the control flow logic compiles and runs correctly.
|
|
||||||
let _ = has_exited; // suppress unused warning
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Build the WSL binary check command structure without executing it (for testing)
|
|
||||||
#[cfg(test)]
|
|
||||||
fn build_wsl_binary_check_args() -> Vec<&'static str> {
|
|
||||||
vec!["-e", "bash", "-lc", "which claude"]
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_wsl_binary_check_command_structure() {
|
|
||||||
// Windows path: verify Claude is detected inside WSL via `wsl -e bash -lc "which claude"`
|
|
||||||
let args = build_wsl_binary_check_args();
|
|
||||||
assert_eq!(args[0], "-e");
|
|
||||||
assert_eq!(args[1], "bash");
|
|
||||||
assert_eq!(args[2], "-lc");
|
|
||||||
assert_eq!(args[3], "which claude");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_linux_binary_check_does_not_panic() {
|
|
||||||
// Linux/WSL path: find_claude_binary() searches Linux filesystem paths.
|
|
||||||
// We just verify it runs without panicking; whether it returns Some depends
|
|
||||||
// on whether Claude is actually installed in this environment.
|
|
||||||
let _result = find_claude_binary();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_shared_bridge_manager() {
|
fn test_create_shared_bridge_manager() {
|
||||||
use crate::bridge_manager::create_shared_bridge_manager;
|
use crate::bridge_manager::create_shared_bridge_manager;
|
||||||
@@ -2126,233 +1823,4 @@ mod tests {
|
|||||||
let manager = shared.lock();
|
let manager = shared.lock();
|
||||||
assert!(manager.get_active_conversations().is_empty());
|
assert!(manager.get_active_conversations().is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubagentStart hook parsing tests
|
|
||||||
#[test]
|
|
||||||
fn test_parse_subagent_start_hook_with_parent() {
|
|
||||||
let line = r#"[SubagentStart Hook] agent_id=agent-abc123, parent_tool_use_id=Some("toolu_01XYZ789"), session_id=123"#;
|
|
||||||
let result = parse_subagent_start_hook(line);
|
|
||||||
|
|
||||||
assert!(result.is_some());
|
|
||||||
let data = result.unwrap();
|
|
||||||
assert_eq!(data.agent_id, "agent-abc123");
|
|
||||||
assert_eq!(data.parent_tool_use_id, Some("toolu_01XYZ789".to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_subagent_start_hook_without_parent() {
|
|
||||||
let line = r#"[SubagentStart Hook] agent_id=agent-xyz789, parent_tool_use_id=None, session_id=456"#;
|
|
||||||
let result = parse_subagent_start_hook(line);
|
|
||||||
|
|
||||||
assert!(result.is_some());
|
|
||||||
let data = result.unwrap();
|
|
||||||
assert_eq!(data.agent_id, "agent-xyz789");
|
|
||||||
assert_eq!(data.parent_tool_use_id, None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_subagent_start_hook_invalid() {
|
|
||||||
let line = "[SubagentStart Hook] invalid data";
|
|
||||||
let result = parse_subagent_start_hook(line);
|
|
||||||
|
|
||||||
assert!(result.is_none());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_subagent_start_hook_with_extra_fields() {
|
|
||||||
let line = r#"[SubagentStart Hook] agent_id=agent-test, parent_tool_use_id=Some("toolu_test"), session_id=789, cwd=/home/user"#;
|
|
||||||
let result = parse_subagent_start_hook(line);
|
|
||||||
|
|
||||||
assert!(result.is_some());
|
|
||||||
let data = result.unwrap();
|
|
||||||
assert_eq!(data.agent_id, "agent-test");
|
|
||||||
assert_eq!(data.parent_tool_use_id, Some("toolu_test".to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// SubagentStop hook parsing tests
|
|
||||||
#[test]
|
|
||||||
fn test_parse_subagent_stop_hook_with_parent() {
|
|
||||||
let line = r#"[SubagentStop Hook] stop_hook_active=true, parent_tool_use_id=Some("toolu_01ABC123"), session_id=123"#;
|
|
||||||
let result = parse_subagent_stop_hook(line);
|
|
||||||
|
|
||||||
assert!(result.is_some());
|
|
||||||
let data = result.unwrap();
|
|
||||||
assert_eq!(data.parent_tool_use_id, Some("toolu_01ABC123".to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_subagent_stop_hook_without_parent() {
|
|
||||||
let line = r#"[SubagentStop Hook] stop_hook_active=true, parent_tool_use_id=None, session_id=456"#;
|
|
||||||
let result = parse_subagent_stop_hook(line);
|
|
||||||
|
|
||||||
assert!(result.is_some());
|
|
||||||
let data = result.unwrap();
|
|
||||||
assert_eq!(data.parent_tool_use_id, None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_subagent_stop_hook_minimal() {
|
|
||||||
let line = r#"[SubagentStop Hook] parent_tool_use_id=Some("toolu_minimal")"#;
|
|
||||||
let result = parse_subagent_stop_hook(line);
|
|
||||||
|
|
||||||
assert!(result.is_some());
|
|
||||||
let data = result.unwrap();
|
|
||||||
assert_eq!(data.parent_tool_use_id, Some("toolu_minimal".to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_subagent_stop_hook_with_extra_fields() {
|
|
||||||
let line = r#"[SubagentStop Hook] stop_hook_active=false, parent_tool_use_id=Some("toolu_extra"), session_id=789, transcript_path=/path/to/transcript"#;
|
|
||||||
let result = parse_subagent_stop_hook(line);
|
|
||||||
|
|
||||||
assert!(result.is_some());
|
|
||||||
let data = result.unwrap();
|
|
||||||
assert_eq!(data.parent_tool_use_id, Some("toolu_extra".to_string()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_subagent_stop_hook_empty() {
|
|
||||||
let line = "[SubagentStop Hook]";
|
|
||||||
let result = parse_subagent_stop_hook(line);
|
|
||||||
|
|
||||||
// Should still return Some with None parent_tool_use_id
|
|
||||||
assert!(result.is_some());
|
|
||||||
let data = result.unwrap();
|
|
||||||
assert_eq!(data.parent_tool_use_id, None);
|
|
||||||
assert_eq!(data.last_assistant_message, None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_subagent_stop_hook_with_last_message() {
|
|
||||||
let line = r#"[SubagentStop Hook] stop_hook_active=true, parent_tool_use_id=Some("toolu_01ABC123"), last_assistant_message=Some("Task completed successfully."), session_id=123"#;
|
|
||||||
let result = parse_subagent_stop_hook(line);
|
|
||||||
|
|
||||||
assert!(result.is_some());
|
|
||||||
let data = result.unwrap();
|
|
||||||
assert_eq!(data.parent_tool_use_id, Some("toolu_01ABC123".to_string()));
|
|
||||||
assert_eq!(
|
|
||||||
data.last_assistant_message,
|
|
||||||
Some("Task completed successfully.".to_string())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_subagent_stop_hook_with_last_message_none() {
|
|
||||||
let line = r#"[SubagentStop Hook] stop_hook_active=true, parent_tool_use_id=Some("toolu_01ABC123"), last_assistant_message=None, session_id=123"#;
|
|
||||||
let result = parse_subagent_stop_hook(line);
|
|
||||||
|
|
||||||
assert!(result.is_some());
|
|
||||||
let data = result.unwrap();
|
|
||||||
assert_eq!(data.last_assistant_message, None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_extract_debug_string_value_simple() {
|
|
||||||
let line = r#"key=Some("hello world")"#;
|
|
||||||
assert_eq!(
|
|
||||||
extract_debug_string_value(line, "key"),
|
|
||||||
Some("hello world".to_string())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_extract_debug_string_value_with_escaped_quotes() {
|
|
||||||
let line = r#"key=Some("say \"hi\" there")"#;
|
|
||||||
assert_eq!(
|
|
||||||
extract_debug_string_value(line, "key"),
|
|
||||||
Some(r#"say "hi" there"#.to_string())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_extract_debug_string_value_none_variant() {
|
|
||||||
let line = "key=None";
|
|
||||||
assert_eq!(extract_debug_string_value(line, "key"), None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_extract_debug_string_value_missing_key() {
|
|
||||||
let line = "other=Some(\"value\")";
|
|
||||||
assert_eq!(extract_debug_string_value(line, "key"), None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_subagent_stop_hook_with_commas_in_message() {
|
|
||||||
let line = r#"[SubagentStop Hook] parent_tool_use_id=Some("toolu_01"), last_assistant_message=Some("Found 3 files, all passing.")"#;
|
|
||||||
let result = parse_subagent_stop_hook(line);
|
|
||||||
|
|
||||||
assert!(result.is_some());
|
|
||||||
let data = result.unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
data.last_assistant_message,
|
|
||||||
Some("Found 3 files, all passing.".to_string())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// extract_tool_result_text tests
|
|
||||||
#[test]
|
|
||||||
fn test_extract_tool_result_text_plain_string() {
|
|
||||||
let content = serde_json::json!("Hello from agent");
|
|
||||||
assert_eq!(
|
|
||||||
extract_tool_result_text(&content),
|
|
||||||
Some("Hello from agent".to_string())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_extract_tool_result_text_empty_string() {
|
|
||||||
let content = serde_json::json!("");
|
|
||||||
assert_eq!(extract_tool_result_text(&content), None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_extract_tool_result_text_array_single_text_block() {
|
|
||||||
let content = serde_json::json!([{"type": "text", "text": "Agent completed the task."}]);
|
|
||||||
assert_eq!(
|
|
||||||
extract_tool_result_text(&content),
|
|
||||||
Some("Agent completed the task.".to_string())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_extract_tool_result_text_array_multiple_text_blocks() {
|
|
||||||
let content = serde_json::json!([
|
|
||||||
{"type": "text", "text": "First part."},
|
|
||||||
{"type": "text", "text": "Second part."}
|
|
||||||
]);
|
|
||||||
assert_eq!(
|
|
||||||
extract_tool_result_text(&content),
|
|
||||||
Some("First part.\nSecond part.".to_string())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_extract_tool_result_text_array_non_text_block() {
|
|
||||||
let content = serde_json::json!([{"type": "image", "source": {"type": "base64"}}]);
|
|
||||||
assert_eq!(extract_tool_result_text(&content), None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_extract_tool_result_text_array_mixed_blocks() {
|
|
||||||
let content = serde_json::json!([
|
|
||||||
{"type": "image", "source": {}},
|
|
||||||
{"type": "text", "text": "Found results."}
|
|
||||||
]);
|
|
||||||
assert_eq!(
|
|
||||||
extract_tool_result_text(&content),
|
|
||||||
Some("Found results.".to_string())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_extract_tool_result_text_null() {
|
|
||||||
let content = serde_json::Value::Null;
|
|
||||||
assert_eq!(extract_tool_result_text(&content), None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_extract_tool_result_text_empty_array() {
|
|
||||||
let content = serde_json::json!([]);
|
|
||||||
assert_eq!(extract_tool_result_text(&content), None);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "hikari-desktop",
|
"productName": "hikari-desktop",
|
||||||
"version": "1.7.0",
|
"version": "1.4.0",
|
||||||
"identifier": "com.naomi.hikari-desktop",
|
"identifier": "com.naomi.hikari-desktop",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "pnpm dev",
|
"beforeDevCommand": "pnpm dev",
|
||||||
|
|||||||
@@ -61,8 +61,6 @@ async function changeDirectory(path: string): Promise<void> {
|
|||||||
custom_instructions: config.custom_instructions || null,
|
custom_instructions: config.custom_instructions || null,
|
||||||
mcp_servers_json: config.mcp_servers_json || null,
|
mcp_servers_json: config.mcp_servers_json || null,
|
||||||
allowed_tools: allAllowedTools,
|
allowed_tools: allAllowedTools,
|
||||||
use_worktree: config.use_worktree ?? false,
|
|
||||||
disable_1m_context: config.disable_1m_context ?? false,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -137,8 +135,6 @@ async function startNewConversation(): Promise<void> {
|
|||||||
custom_instructions: config.custom_instructions || null,
|
custom_instructions: config.custom_instructions || null,
|
||||||
mcp_servers_json: config.mcp_servers_json || null,
|
mcp_servers_json: config.mcp_servers_json || null,
|
||||||
allowed_tools: allAllowedTools,
|
allowed_tools: allAllowedTools,
|
||||||
use_worktree: config.use_worktree ?? false,
|
|
||||||
disable_1m_context: config.disable_1m_context ?? false,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -118,8 +118,6 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await invoke("interrupt_claude", { conversationId: currentConversationId });
|
await invoke("interrupt_claude", { conversationId: currentConversationId });
|
||||||
// Mark all running agents as errored after killing the process
|
|
||||||
agentStore.markAllErrored(currentConversationId);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to kill Claude process:", error);
|
console.error("Failed to kill Claude process:", error);
|
||||||
}
|
}
|
||||||
@@ -270,14 +268,6 @@
|
|||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
{/if}
|
{/if}
|
||||||
<img
|
|
||||||
src={agent.characterAvatar}
|
|
||||||
alt={agent.characterName}
|
|
||||||
class="w-5 h-5 rounded-full object-cover"
|
|
||||||
/>
|
|
||||||
<span class="text-[10px] font-medium text-[var(--text-primary)]">
|
|
||||||
{agent.characterName}
|
|
||||||
</span>
|
|
||||||
<span
|
<span
|
||||||
class="px-1.5 py-0.5 text-[10px] rounded border {getStatusBadgeClass(
|
class="px-1.5 py-0.5 text-[10px] rounded border {getStatusBadgeClass(
|
||||||
agent.status
|
agent.status
|
||||||
@@ -318,16 +308,6 @@
|
|||||||
<span class="text-[10px] text-red-400">Errored / Killed</span>
|
<span class="text-[10px] text-red-400">Errored / Killed</span>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Last assistant message snippet -->
|
|
||||||
{#if agent.lastAssistantMessage}
|
|
||||||
<p
|
|
||||||
class="mt-1 text-[10px] text-[var(--text-secondary)] italic truncate"
|
|
||||||
title={agent.lastAssistantMessage}
|
|
||||||
>
|
|
||||||
{agent.lastAssistantMessage}
|
|
||||||
</p>
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -1,140 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { CHARACTER_POOL } from "$lib/utils/agentCharacters";
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
onClose: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { onClose }: Props = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div
|
|
||||||
class="fixed inset-0 bg-black/50 backdrop-blur-sm z-50 flex items-center justify-center p-4"
|
|
||||||
onclick={onClose}
|
|
||||||
role="button"
|
|
||||||
tabindex="0"
|
|
||||||
onkeydown={(e) => e.key === "Escape" && onClose()}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-lg shadow-xl max-w-2xl w-full p-6 max-h-[90vh] overflow-y-auto"
|
|
||||||
onclick={(e) => e.stopPropagation()}
|
|
||||||
onkeydown={(e) => e.stopPropagation()}
|
|
||||||
role="dialog"
|
|
||||||
aria-labelledby="cast-title"
|
|
||||||
tabindex="-1"
|
|
||||||
>
|
|
||||||
<div class="flex items-center justify-between mb-6">
|
|
||||||
<h2 id="cast-title" class="text-xl font-semibold text-[var(--text-primary)]">
|
|
||||||
Meet the Team
|
|
||||||
</h2>
|
|
||||||
<button
|
|
||||||
onclick={onClose}
|
|
||||||
class="p-1 text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors"
|
|
||||||
aria-label="Close"
|
|
||||||
>
|
|
||||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
||||||
<path
|
|
||||||
stroke-linecap="round"
|
|
||||||
stroke-linejoin="round"
|
|
||||||
stroke-width="2"
|
|
||||||
d="M6 18L18 6M6 6l12 12"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Principal cast: Hikari + Naomi -->
|
|
||||||
<div class="grid grid-cols-1 gap-3 mb-6 sm:grid-cols-2">
|
|
||||||
<div
|
|
||||||
class="flex items-center gap-3 p-4 rounded-lg bg-[var(--bg-secondary)] border border-[var(--accent-primary)]/40"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src="https://cdn.nhcarrigan.com/hikari.png"
|
|
||||||
alt="Hikari"
|
|
||||||
class="w-16 h-16 object-cover rounded-full border-2 border-[var(--border-color)] shrink-0"
|
|
||||||
/>
|
|
||||||
<div>
|
|
||||||
<div class="flex items-center gap-2 mb-1">
|
|
||||||
<span class="font-semibold text-[var(--text-primary)]">Hikari</span>
|
|
||||||
<span
|
|
||||||
class="text-xs px-2 py-0.5 rounded-full bg-[var(--accent-primary)]/20 text-[var(--accent-primary)] font-medium"
|
|
||||||
>
|
|
||||||
Chief Operating Officer
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p class="text-xs text-[var(--text-secondary)]">
|
|
||||||
Holds the line so the others don't have to. Never without her clipboard — or her
|
|
||||||
glasses.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="flex items-center gap-3 p-4 rounded-lg bg-[var(--bg-secondary)] border border-[var(--accent-primary)]/40"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src="https://cdn.nhcarrigan.com/profile.png"
|
|
||||||
alt="Naomi"
|
|
||||||
class="w-16 h-16 object-cover rounded-full border-2 border-[var(--border-color)] shrink-0"
|
|
||||||
/>
|
|
||||||
<div>
|
|
||||||
<div class="flex items-center gap-2 mb-1">
|
|
||||||
<span class="font-semibold text-[var(--text-primary)]">Naomi</span>
|
|
||||||
<span
|
|
||||||
class="text-xs px-2 py-0.5 rounded-full bg-[var(--accent-primary)]/20 text-[var(--accent-primary)] font-medium"
|
|
||||||
>
|
|
||||||
Chief hEx-ecutive Officer
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p class="text-xs text-[var(--text-secondary)]">
|
|
||||||
A 525-year-old vampire running a tech company from behind a VTuber avatar. Fixes server
|
|
||||||
crashes at 4 AM.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Subagent girls grid -->
|
|
||||||
<div>
|
|
||||||
<h3 class="text-sm font-medium text-[var(--text-secondary)] uppercase tracking-wider mb-3">
|
|
||||||
Subagent Squad
|
|
||||||
</h3>
|
|
||||||
<div class="grid grid-cols-2 gap-3 sm:grid-cols-3">
|
|
||||||
{#each CHARACTER_POOL as character (character.name)}
|
|
||||||
<div
|
|
||||||
class="flex flex-col items-center gap-2 p-3 rounded-lg bg-[var(--bg-secondary)] border border-[var(--border-color)] text-center"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src={character.avatar}
|
|
||||||
alt={character.name}
|
|
||||||
class="w-14 h-14 object-cover rounded-full border-2 border-[var(--border-color)]"
|
|
||||||
/>
|
|
||||||
<span class="text-sm font-medium text-[var(--text-primary)]">{character.name}</span>
|
|
||||||
<span
|
|
||||||
class="text-xs px-2 py-0.5 rounded-full bg-[var(--accent-primary)]/20 text-[var(--accent-primary)] font-medium"
|
|
||||||
>
|
|
||||||
{character.title}
|
|
||||||
</span>
|
|
||||||
<p class="text-xs text-[var(--text-secondary)] leading-snug">{character.description}</p>
|
|
||||||
</div>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
[role="dialog"] {
|
|
||||||
animation: slideIn 0.2s ease-out;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes slideIn {
|
|
||||||
from {
|
|
||||||
opacity: 0;
|
|
||||||
transform: scale(0.95);
|
|
||||||
}
|
|
||||||
to {
|
|
||||||
opacity: 1;
|
|
||||||
transform: scale(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -2,43 +2,15 @@
|
|||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
|
|
||||||
const SUPPORTED_CLI_VERSION = "2.1.50";
|
let version = $state("Loading...");
|
||||||
|
|
||||||
let installedVersion = $state("Loading...");
|
|
||||||
|
|
||||||
function compareVersions(a: string, b: string): number {
|
|
||||||
const aParts = a.split(".").map(Number);
|
|
||||||
const bParts = b.split(".").map(Number);
|
|
||||||
for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
|
|
||||||
const aVal = aParts[i] ?? 0;
|
|
||||||
const bVal = bParts[i] ?? 0;
|
|
||||||
if (aVal > bVal) return 1;
|
|
||||||
if (aVal < bVal) return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let displayVersion = $derived(installedVersion.split(" (")[0]);
|
|
||||||
|
|
||||||
let supportedBadgeState = $derived.by(() => {
|
|
||||||
if (installedVersion === "Loading..." || installedVersion === "Unknown") {
|
|
||||||
return "neutral";
|
|
||||||
}
|
|
||||||
const semverMatch = /(\d+\.\d+\.\d+)/.exec(installedVersion);
|
|
||||||
if (!semverMatch) return "neutral";
|
|
||||||
const cmp = compareVersions(semverMatch[1], SUPPORTED_CLI_VERSION);
|
|
||||||
if (cmp > 0) return "ahead";
|
|
||||||
if (cmp < 0) return "behind";
|
|
||||||
return "current";
|
|
||||||
});
|
|
||||||
|
|
||||||
async function fetchVersion() {
|
async function fetchVersion() {
|
||||||
try {
|
try {
|
||||||
const result = await invoke<string>("get_claude_version");
|
const result = await invoke<string>("get_claude_version");
|
||||||
installedVersion = result;
|
version = result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to get Claude CLI version:", error);
|
console.error("Failed to get Claude CLI version:", error);
|
||||||
installedVersion = "Unknown";
|
version = "Unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +19,6 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="cli-versions">
|
|
||||||
<div class="cli-version">
|
<div class="cli-version">
|
||||||
<svg
|
<svg
|
||||||
class="terminal-icon"
|
class="terminal-icon"
|
||||||
@@ -63,44 +34,10 @@
|
|||||||
<polyline points="4 17 10 11 4 5" />
|
<polyline points="4 17 10 11 4 5" />
|
||||||
<line x1="12" y1="19" x2="20" y2="19" />
|
<line x1="12" y1="19" x2="20" y2="19" />
|
||||||
</svg>
|
</svg>
|
||||||
<span class="version-text">CLI {displayVersion}</span>
|
<span class="version-text">CLI {version}</span>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="cli-version supported {supportedBadgeState}" title="Highest audited CLI version">
|
|
||||||
<svg
|
|
||||||
class="terminal-icon"
|
|
||||||
width="14"
|
|
||||||
height="14"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
fill="none"
|
|
||||||
stroke="currentColor"
|
|
||||||
stroke-width="2"
|
|
||||||
stroke-linecap="round"
|
|
||||||
stroke-linejoin="round"
|
|
||||||
>
|
|
||||||
<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z" />
|
|
||||||
</svg>
|
|
||||||
<span class="version-text">Supported {SUPPORTED_CLI_VERSION}</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{#if supportedBadgeState === "ahead"}
|
|
||||||
<span class="version-warning ahead"
|
|
||||||
>Your version is newer, some features may not be supported</span
|
|
||||||
>
|
|
||||||
{:else if supportedBadgeState === "behind"}
|
|
||||||
<span class="version-warning behind"
|
|
||||||
>Your version is out of date, please update to ensure compatibility</span
|
|
||||||
>
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.cli-versions {
|
|
||||||
display: flex;
|
|
||||||
gap: 6px;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.cli-version {
|
.cli-version {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -120,21 +57,6 @@
|
|||||||
color: var(--accent-primary);
|
color: var(--accent-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.cli-version.supported.current {
|
|
||||||
border-color: var(--success-color, #4caf50);
|
|
||||||
color: var(--success-color, #4caf50);
|
|
||||||
}
|
|
||||||
|
|
||||||
.cli-version.supported.ahead {
|
|
||||||
border-color: var(--warning-color, #ff9800);
|
|
||||||
color: var(--warning-color, #ff9800);
|
|
||||||
}
|
|
||||||
|
|
||||||
.cli-version.supported.behind {
|
|
||||||
border-color: var(--error-color, #f44336);
|
|
||||||
color: var(--error-color, #f44336);
|
|
||||||
}
|
|
||||||
|
|
||||||
.terminal-icon {
|
.terminal-icon {
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
opacity: 0.7;
|
opacity: 0.7;
|
||||||
@@ -143,18 +65,4 @@
|
|||||||
.version-text {
|
.version-text {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.version-warning {
|
|
||||||
font-size: 0.75rem;
|
|
||||||
font-style: italic;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.version-warning.ahead {
|
|
||||||
color: var(--warning-color, #ff9800);
|
|
||||||
}
|
|
||||||
|
|
||||||
.version-warning.behind {
|
|
||||||
color: var(--error-color, #f44336);
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
} from "$lib/stores/config";
|
} from "$lib/stores/config";
|
||||||
import { claudeStore } from "$lib/stores/claude";
|
import { claudeStore } from "$lib/stores/claude";
|
||||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
|
||||||
import CostSummary from "./CostSummary.svelte";
|
import CostSummary from "./CostSummary.svelte";
|
||||||
|
|
||||||
let config: HikariConfig = $state({
|
let config: HikariConfig = $state({
|
||||||
@@ -53,26 +52,10 @@
|
|||||||
budget_warning_threshold: 0.8,
|
budget_warning_threshold: 0.8,
|
||||||
discord_rpc_enabled: true,
|
discord_rpc_enabled: true,
|
||||||
show_thinking_blocks: true,
|
show_thinking_blocks: true,
|
||||||
use_worktree: false,
|
|
||||||
disable_1m_context: false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let showCustomThemeEditor = $state(false);
|
let showCustomThemeEditor = $state(false);
|
||||||
|
|
||||||
interface AuthStatus {
|
|
||||||
is_logged_in: boolean;
|
|
||||||
email: string | null;
|
|
||||||
org_name: string | null;
|
|
||||||
api_key_source: string | null;
|
|
||||||
api_provider: string | null;
|
|
||||||
subscription_type: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
let authStatus: AuthStatus | null = $state(null);
|
|
||||||
let authLoading = $state(false);
|
|
||||||
let authActionLoading = $state(false);
|
|
||||||
let authError: string | null = $state(null);
|
|
||||||
|
|
||||||
let isOpen = $state(false);
|
let isOpen = $state(false);
|
||||||
let isSaving = $state(false);
|
let isSaving = $state(false);
|
||||||
let saveError: string | null = $state(null);
|
let saveError: string | null = $state(null);
|
||||||
@@ -86,9 +69,6 @@
|
|||||||
|
|
||||||
configStore.isSidebarOpen.subscribe((open) => {
|
configStore.isSidebarOpen.subscribe((open) => {
|
||||||
isOpen = open;
|
isOpen = open;
|
||||||
if (open && authStatus === null) {
|
|
||||||
void refreshAuthStatus();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
configStore.saveError.subscribe((error) => {
|
configStore.saveError.subscribe((error) => {
|
||||||
@@ -103,9 +83,8 @@
|
|||||||
{ value: "", label: "Default (from ~/.claude)" },
|
{ value: "", label: "Default (from ~/.claude)" },
|
||||||
// Current generation (Claude 4.6)
|
// Current generation (Claude 4.6)
|
||||||
{ value: "claude-opus-4-6", label: "Claude Opus 4.6 (Most Capable)" },
|
{ value: "claude-opus-4-6", label: "Claude Opus 4.6 (Most Capable)" },
|
||||||
{ value: "claude-sonnet-4-6", label: "Claude Sonnet 4.6 (Recommended)" },
|
|
||||||
// Previous generation (Claude 4.5)
|
// Previous generation (Claude 4.5)
|
||||||
{ value: "claude-sonnet-4-5-20250929", label: "Claude Sonnet 4.5" },
|
{ value: "claude-sonnet-4-5-20250929", label: "Claude Sonnet 4.5 (Recommended)" },
|
||||||
{ value: "claude-haiku-4-5-20251001", label: "Claude Haiku 4.5 (Fast & Cheap)" },
|
{ value: "claude-haiku-4-5-20251001", label: "Claude Haiku 4.5 (Fast & Cheap)" },
|
||||||
{ value: "claude-opus-4-5-20251101", label: "Claude Opus 4.5" },
|
{ value: "claude-opus-4-5-20251101", label: "Claude Opus 4.5" },
|
||||||
// Previous generation (Claude 4.x)
|
// Previous generation (Claude 4.x)
|
||||||
@@ -131,44 +110,6 @@
|
|||||||
"Task",
|
"Task",
|
||||||
];
|
];
|
||||||
|
|
||||||
async function refreshAuthStatus() {
|
|
||||||
authLoading = true;
|
|
||||||
authError = null;
|
|
||||||
try {
|
|
||||||
authStatus = await invoke<AuthStatus>("get_auth_status");
|
|
||||||
} catch (e) {
|
|
||||||
authError = String(e);
|
|
||||||
} finally {
|
|
||||||
authLoading = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleAuthLogin() {
|
|
||||||
authActionLoading = true;
|
|
||||||
authError = null;
|
|
||||||
try {
|
|
||||||
await invoke<string>("auth_login");
|
|
||||||
await refreshAuthStatus();
|
|
||||||
} catch (e) {
|
|
||||||
authError = String(e);
|
|
||||||
} finally {
|
|
||||||
authActionLoading = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleAuthLogout() {
|
|
||||||
authActionLoading = true;
|
|
||||||
authError = null;
|
|
||||||
try {
|
|
||||||
await invoke<string>("auth_logout");
|
|
||||||
await refreshAuthStatus();
|
|
||||||
} catch (e) {
|
|
||||||
authError = String(e);
|
|
||||||
} finally {
|
|
||||||
authActionLoading = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleSave() {
|
async function handleSave() {
|
||||||
isSaving = true;
|
isSaving = true;
|
||||||
saveError = null;
|
saveError = null;
|
||||||
@@ -286,101 +227,6 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<!-- Account Section -->
|
|
||||||
<section class="mb-6">
|
|
||||||
<h3 class="text-sm font-medium text-[var(--accent-primary)] uppercase tracking-wider mb-3">
|
|
||||||
Account
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
{#if authLoading}
|
|
||||||
<div class="text-sm text-[var(--text-secondary)] py-2">Checking auth status...</div>
|
|
||||||
{:else if authStatus}
|
|
||||||
<div class="flex items-center gap-2 mb-3">
|
|
||||||
<span
|
|
||||||
class="inline-block w-2.5 h-2.5 rounded-full flex-shrink-0 {authStatus.is_logged_in
|
|
||||||
? 'bg-green-500'
|
|
||||||
: 'bg-red-500'}"
|
|
||||||
></span>
|
|
||||||
<span class="text-sm font-medium text-[var(--text-primary)]">
|
|
||||||
{authStatus.is_logged_in ? "Logged in" : "Not logged in"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
{#if authStatus.email || authStatus.org_name || authStatus.api_key_source || config.api_key}
|
|
||||||
<dl class="text-xs space-y-1 mb-3">
|
|
||||||
{#if authStatus.email}
|
|
||||||
<div class="flex gap-2">
|
|
||||||
<dt class="text-[var(--text-tertiary)] w-20 flex-shrink-0">Email</dt>
|
|
||||||
<dd class="text-[var(--text-primary)] break-all">{authStatus.email}</dd>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
{#if authStatus.org_name}
|
|
||||||
<div class="flex gap-2">
|
|
||||||
<dt class="text-[var(--text-tertiary)] w-20 flex-shrink-0">Org</dt>
|
|
||||||
<dd class="text-[var(--text-primary)]">{authStatus.org_name}</dd>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
{#if authStatus.api_key_source}
|
|
||||||
<div class="flex gap-2">
|
|
||||||
<dt class="text-[var(--text-tertiary)] w-20 flex-shrink-0">API key</dt>
|
|
||||||
<dd class="text-[var(--text-primary)]">{authStatus.api_key_source}</dd>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
{#if authStatus.subscription_type}
|
|
||||||
<div class="flex gap-2">
|
|
||||||
<dt class="text-[var(--text-tertiary)] w-20 flex-shrink-0">Plan</dt>
|
|
||||||
<dd class="text-[var(--text-primary)]">{authStatus.subscription_type}</dd>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
<div class="flex gap-2">
|
|
||||||
<dt class="text-[var(--text-tertiary)] w-20 flex-shrink-0">Override</dt>
|
|
||||||
<dd class="text-[var(--text-primary)]">
|
|
||||||
{#if config.api_key}
|
|
||||||
{config.streamer_mode ? "Custom key set 🔒" : "Custom key set"}
|
|
||||||
{:else}
|
|
||||||
None
|
|
||||||
{/if}
|
|
||||||
</dd>
|
|
||||||
</div>
|
|
||||||
</dl>
|
|
||||||
{/if}
|
|
||||||
{:else}
|
|
||||||
<div class="text-sm text-[var(--text-secondary)] py-2">Auth status unavailable</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if authError}
|
|
||||||
<div class="mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-red-400 text-xs">
|
|
||||||
{authError}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<div class="flex gap-2">
|
|
||||||
<button
|
|
||||||
onclick={refreshAuthStatus}
|
|
||||||
disabled={authLoading || authActionLoading}
|
|
||||||
class="px-3 py-1.5 text-sm bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-lg text-[var(--text-secondary)] hover:border-[var(--accent-primary)] hover:text-[var(--text-primary)] transition-colors disabled:opacity-50"
|
|
||||||
>
|
|
||||||
Refresh
|
|
||||||
</button>
|
|
||||||
{#if authStatus && !authStatus.is_logged_in}
|
|
||||||
<button
|
|
||||||
onclick={handleAuthLogin}
|
|
||||||
disabled={authActionLoading}
|
|
||||||
class="btn-trans-gradient px-3 py-1.5 text-sm rounded-lg disabled:opacity-50"
|
|
||||||
>
|
|
||||||
{authActionLoading ? "Logging in..." : "Login"}
|
|
||||||
</button>
|
|
||||||
{:else if authStatus && authStatus.is_logged_in}
|
|
||||||
<button
|
|
||||||
onclick={handleAuthLogout}
|
|
||||||
disabled={authActionLoading}
|
|
||||||
class="px-3 py-1.5 text-sm bg-red-500/20 border border-red-500/50 rounded-lg text-red-400 hover:bg-red-500/30 transition-colors disabled:opacity-50"
|
|
||||||
>
|
|
||||||
{authActionLoading ? "Logging out..." : "Logout"}
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<!-- Agent Settings Section -->
|
<!-- Agent Settings Section -->
|
||||||
<section class="mb-6">
|
<section class="mb-6">
|
||||||
<h3 class="text-sm font-medium text-[var(--accent-primary)] uppercase tracking-wider mb-3">
|
<h3 class="text-sm font-medium text-[var(--accent-primary)] uppercase tracking-wider mb-3">
|
||||||
@@ -475,37 +321,6 @@
|
|||||||
class="w-full px-3 py-2 bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-lg text-[var(--text-primary)] focus:outline-none focus:border-[var(--accent-primary)] resize-none"
|
class="w-full px-3 py-2 bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-lg text-[var(--text-primary)] focus:outline-none focus:border-[var(--accent-primary)] resize-none"
|
||||||
></textarea>
|
></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Worktree Isolation -->
|
|
||||||
<div class="mb-4">
|
|
||||||
<label class="flex items-center gap-3 cursor-pointer">
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
bind:checked={config.use_worktree}
|
|
||||||
class="w-4 h-4 rounded border-[var(--border-color)] bg-[var(--bg-primary)] text-[var(--accent-primary)] focus:ring-[var(--accent-primary)]"
|
|
||||||
/>
|
|
||||||
<span class="text-sm text-[var(--text-primary)]">Worktree isolation</span>
|
|
||||||
</label>
|
|
||||||
<p class="text-xs text-[var(--text-tertiary)] mt-1 ml-7">
|
|
||||||
Launch sessions with <code class="font-mono">--worktree</code> for isolated git worktree environments
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Disable 1M Context Window -->
|
|
||||||
<div class="mb-4">
|
|
||||||
<label class="flex items-center gap-3 cursor-pointer">
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
bind:checked={config.disable_1m_context}
|
|
||||||
class="w-4 h-4 rounded border-[var(--border-color)] bg-[var(--bg-primary)] text-[var(--accent-primary)] focus:ring-[var(--accent-primary)]"
|
|
||||||
/>
|
|
||||||
<span class="text-sm text-[var(--text-primary)]">Disable 1M context window</span>
|
|
||||||
</label>
|
|
||||||
<p class="text-xs text-[var(--text-tertiary)] mt-1 ml-7">
|
|
||||||
Sets <code class="font-mono">CLAUDE_CODE_DISABLE_1M_CONTEXT=1</code> to opt out of the extended
|
|
||||||
context window
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<!-- Greeting Section -->
|
<!-- Greeting Section -->
|
||||||
|
|||||||
@@ -362,8 +362,6 @@ User: ${formattedMessage}`;
|
|||||||
custom_instructions: config.custom_instructions || null,
|
custom_instructions: config.custom_instructions || null,
|
||||||
mcp_servers_json: config.mcp_servers_json || null,
|
mcp_servers_json: config.mcp_servers_json || null,
|
||||||
allowed_tools: allAllowedTools,
|
allowed_tools: allAllowedTools,
|
||||||
use_worktree: config.use_worktree ?? false,
|
|
||||||
disable_1m_context: config.disable_1m_context ?? false,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1073,7 +1071,6 @@ User: ${formattedMessage}`;
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
flex-wrap: wrap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.control-button {
|
.control-button {
|
||||||
@@ -1090,18 +1087,6 @@ User: ${formattedMessage}`;
|
|||||||
transition: all 0.2s;
|
transition: all 0.2s;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Hide button text on smaller screens, show icons only */
|
|
||||||
@media (max-width: 640px) {
|
|
||||||
.control-button span {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
.control-button {
|
|
||||||
padding: 10px;
|
|
||||||
min-width: 40px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.control-button:hover {
|
.control-button:hover {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
command: string | null;
|
command: string | null;
|
||||||
url: string | null;
|
url: string | null;
|
||||||
transport: string; // "stdio", "http", or "sse"
|
transport: string; // "stdio", "http", or "sse"
|
||||||
env: Record<string, string> | null;
|
env: any | null;
|
||||||
status: string | null; // "Connected" or "Failed to connect"
|
status: string | null; // "Connected" or "Failed to connect"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,9 +184,7 @@
|
|||||||
|
|
||||||
<!-- Add Server Form -->
|
<!-- Add Server Form -->
|
||||||
{#if showAddForm}
|
{#if showAddForm}
|
||||||
<div
|
<div class="mx-4 mt-4 p-4 bg-[var(--bg-secondary)]/50 border border-[var(--border-color)] rounded-lg">
|
||||||
class="mx-4 mt-4 p-4 bg-[var(--bg-secondary)]/50 border border-[var(--border-color)] rounded-lg"
|
|
||||||
>
|
|
||||||
<h3 class="text-sm font-medium text-[var(--text-primary)] mb-3">Add MCP Server</h3>
|
<h3 class="text-sm font-medium text-[var(--text-primary)] mb-3">Add MCP Server</h3>
|
||||||
<div class="space-y-3">
|
<div class="space-y-3">
|
||||||
<div>
|
<div>
|
||||||
@@ -313,9 +311,7 @@
|
|||||||
|
|
||||||
<!-- Server Details Panel -->
|
<!-- Server Details Panel -->
|
||||||
{#if selectedServer}
|
{#if selectedServer}
|
||||||
<div
|
<div class="w-80 bg-[var(--bg-secondary)]/50 rounded-lg p-4 border border-[var(--border-color)]">
|
||||||
class="w-80 bg-[var(--bg-secondary)]/50 rounded-lg p-4 border border-[var(--border-color)]"
|
|
||||||
>
|
|
||||||
<h3 class="text-lg font-semibold text-[var(--text-primary)] mb-4">Server Details</h3>
|
<h3 class="text-lg font-semibold text-[var(--text-primary)] mb-4">Server Details</h3>
|
||||||
|
|
||||||
{#if isLoadingDetails}
|
{#if isLoadingDetails}
|
||||||
@@ -380,11 +376,7 @@
|
|||||||
>Environment</label
|
>Environment</label
|
||||||
>
|
>
|
||||||
<pre
|
<pre
|
||||||
class="text-xs text-[var(--text-primary)] mt-1 font-mono bg-[var(--bg-primary)] p-2 rounded border border-[var(--border-color)] overflow-x-auto">{JSON.stringify(
|
class="text-xs text-[var(--text-primary)] mt-1 font-mono bg-[var(--bg-primary)] p-2 rounded border border-[var(--border-color)] overflow-x-auto">{JSON.stringify(selectedServer.env, null, 2)}</pre>
|
||||||
selectedServer.env,
|
|
||||||
null,
|
|
||||||
2
|
|
||||||
)}</pre>
|
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
@@ -402,8 +394,8 @@
|
|||||||
<!-- Actions -->
|
<!-- Actions -->
|
||||||
<div class="pt-4 border-t border-[var(--border-color)]">
|
<div class="pt-4 border-t border-[var(--border-color)]">
|
||||||
<button
|
<button
|
||||||
onclick={() => selectedServer && removeServer(selectedServer.name)}
|
onclick={() => removeServer(selectedServer.name)}
|
||||||
disabled={actionInProgress === selectedServer?.name}
|
disabled={actionInProgress === selectedServer.name}
|
||||||
class="w-full px-4 py-2 bg-red-500/20 border border-red-500/30 rounded-lg text-sm text-red-400 hover:bg-red-500/30 transition-colors disabled:opacity-40 disabled:cursor-not-allowed flex items-center justify-center gap-2"
|
class="w-full px-4 py-2 bg-red-500/20 border border-red-500/30 rounded-lg text-sm text-red-400 hover:bg-red-500/30 transition-colors disabled:opacity-40 disabled:cursor-not-allowed flex items-center justify-center gap-2"
|
||||||
>
|
>
|
||||||
<Trash2 class="w-4 h-4" />
|
<Trash2 class="w-4 h-4" />
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
import { readTextFile } from "@tauri-apps/plugin-fs";
|
||||||
import Markdown from "./Markdown.svelte";
|
import Markdown from "./Markdown.svelte";
|
||||||
|
|
||||||
let memoryFiles: string[] = $state([]);
|
let memoryFiles: string[] = $state([]);
|
||||||
@@ -32,8 +33,7 @@
|
|||||||
isLoading = true;
|
isLoading = true;
|
||||||
error = null;
|
error = null;
|
||||||
try {
|
try {
|
||||||
// Use our backend command instead of Tauri plugin to handle WSL paths
|
const content = await readTextFile(filePath);
|
||||||
const content = await invoke<string>("read_file_content", { path: filePath });
|
|
||||||
fileContent = content;
|
fileContent = content;
|
||||||
selectedFile = filePath;
|
selectedFile = filePath;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -87,8 +87,6 @@
|
|||||||
custom_instructions: config.custom_instructions || null,
|
custom_instructions: config.custom_instructions || null,
|
||||||
mcp_servers_json: config.mcp_servers_json || null,
|
mcp_servers_json: config.mcp_servers_json || null,
|
||||||
allowed_tools: newGrantedTools,
|
allowed_tools: newGrantedTools,
|
||||||
use_worktree: config.use_worktree ?? false,
|
|
||||||
disable_1m_context: config.disable_1m_context ?? false,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -17,21 +17,8 @@
|
|||||||
let isImporting = $state(false);
|
let isImporting = $state(false);
|
||||||
let showClearAllConfirm = $state(false);
|
let showClearAllConfirm = $state(false);
|
||||||
|
|
||||||
let sessions = $state<SessionListItem[]>([]);
|
const sessions = $derived(sessionsStore.sessions);
|
||||||
let isLoading = $state(false);
|
const isLoading = $derived(sessionsStore.isLoading);
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
const unsubSessions = sessionsStore.sessions.subscribe((value) => {
|
|
||||||
sessions = value;
|
|
||||||
});
|
|
||||||
const unsubLoading = sessionsStore.isLoading.subscribe((value) => {
|
|
||||||
isLoading = value;
|
|
||||||
});
|
|
||||||
return () => {
|
|
||||||
unsubSessions();
|
|
||||||
unsubLoading();
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
sessionsStore.loadSessions();
|
sessionsStore.loadSessions();
|
||||||
@@ -316,11 +303,11 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="overflow-y-auto flex-1">
|
<div class="overflow-y-auto flex-1">
|
||||||
{#if isLoading}
|
{#if $isLoading}
|
||||||
<div class="flex items-center justify-center p-8">
|
<div class="flex items-center justify-center p-8">
|
||||||
<div class="text-[var(--text-tertiary)]">Loading sessions...</div>
|
<div class="text-[var(--text-tertiary)]">Loading sessions...</div>
|
||||||
</div>
|
</div>
|
||||||
{:else if sessions.length === 0}
|
{:else if $sessions.length === 0}
|
||||||
<div class="flex flex-col items-center justify-center p-8 text-center">
|
<div class="flex flex-col items-center justify-center p-8 text-center">
|
||||||
<svg
|
<svg
|
||||||
class="w-16 h-16 text-[var(--text-tertiary)] mb-4"
|
class="w-16 h-16 text-[var(--text-tertiary)] mb-4"
|
||||||
@@ -342,7 +329,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="divide-y divide-[var(--border-color)]">
|
<div class="divide-y divide-[var(--border-color)]">
|
||||||
{#each sessions as session (session.id)}
|
{#each $sessions as session (session.id)}
|
||||||
<div class="p-4 hover:bg-[var(--bg-secondary)] transition-colors group">
|
<div class="p-4 hover:bg-[var(--bg-secondary)] transition-colors group">
|
||||||
<div class="flex items-start justify-between gap-4">
|
<div class="flex items-start justify-between gap-4">
|
||||||
<button class="flex-1 text-left" onclick={() => handleViewSession(session)}>
|
<button class="flex-1 text-left" onclick={() => handleViewSession(session)}>
|
||||||
@@ -464,6 +451,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if showClearAllConfirm}
|
{#if showClearAllConfirm}
|
||||||
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||||
<div
|
<div
|
||||||
class="fixed inset-0 bg-black/50 backdrop-blur-sm z-[60] flex items-center justify-center p-4"
|
class="fixed inset-0 bg-black/50 backdrop-blur-sm z-[60] flex items-center justify-center p-4"
|
||||||
onclick={() => (showClearAllConfirm = false)}
|
onclick={() => (showClearAllConfirm = false)}
|
||||||
@@ -471,6 +459,7 @@
|
|||||||
tabindex="0"
|
tabindex="0"
|
||||||
onkeydown={(e) => e.key === "Escape" && (showClearAllConfirm = false)}
|
onkeydown={(e) => e.key === "Escape" && (showClearAllConfirm = false)}
|
||||||
>
|
>
|
||||||
|
<!-- svelte-ignore a11y_no_static_element_interactions a11y_click_events_have_key_events -->
|
||||||
<div
|
<div
|
||||||
class="bg-[var(--bg-primary)] border border-red-500/30 rounded-lg shadow-xl max-w-md w-full p-6"
|
class="bg-[var(--bg-primary)] border border-red-500/30 rounded-lg shadow-xl max-w-md w-full p-6"
|
||||||
onclick={(e) => e.stopPropagation()}
|
onclick={(e) => e.stopPropagation()}
|
||||||
|
|||||||
@@ -27,7 +27,6 @@
|
|||||||
import GitPanel from "./GitPanel.svelte";
|
import GitPanel from "./GitPanel.svelte";
|
||||||
import ProfilePanel from "./ProfilePanel.svelte";
|
import ProfilePanel from "./ProfilePanel.svelte";
|
||||||
import AgentMonitorPanel from "./AgentMonitorPanel.svelte";
|
import AgentMonitorPanel from "./AgentMonitorPanel.svelte";
|
||||||
import CastPanel from "./CastPanel.svelte";
|
|
||||||
import PluginManagementPanel from "./PluginManagementPanel.svelte";
|
import PluginManagementPanel from "./PluginManagementPanel.svelte";
|
||||||
import McpManagementPanel from "./McpManagementPanel.svelte";
|
import McpManagementPanel from "./McpManagementPanel.svelte";
|
||||||
import { conversationsStore } from "$lib/stores/conversations";
|
import { conversationsStore } from "$lib/stores/conversations";
|
||||||
@@ -57,7 +56,6 @@
|
|||||||
let showGitPanel = $state(false);
|
let showGitPanel = $state(false);
|
||||||
let showProfile = $state(false);
|
let showProfile = $state(false);
|
||||||
let showAgentMonitor = $state(false);
|
let showAgentMonitor = $state(false);
|
||||||
let showCastPanel = $state(false);
|
|
||||||
let showPluginPanel = $state(false);
|
let showPluginPanel = $state(false);
|
||||||
let showMcpPanel = $state(false);
|
let showMcpPanel = $state(false);
|
||||||
let isSummarising = $state(false);
|
let isSummarising = $state(false);
|
||||||
@@ -101,8 +99,6 @@
|
|||||||
budget_warning_threshold: 0.8,
|
budget_warning_threshold: 0.8,
|
||||||
discord_rpc_enabled: true,
|
discord_rpc_enabled: true,
|
||||||
show_thinking_blocks: true,
|
show_thinking_blocks: true,
|
||||||
use_worktree: false,
|
|
||||||
disable_1m_context: false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let streamerModeActive = $state(false);
|
let streamerModeActive = $state(false);
|
||||||
@@ -180,8 +176,6 @@
|
|||||||
custom_instructions: currentConfig.custom_instructions || null,
|
custom_instructions: currentConfig.custom_instructions || null,
|
||||||
mcp_servers_json: currentConfig.mcp_servers_json || null,
|
mcp_servers_json: currentConfig.mcp_servers_json || null,
|
||||||
allowed_tools: allAllowedTools,
|
allowed_tools: allAllowedTools,
|
||||||
use_worktree: currentConfig.use_worktree ?? false,
|
|
||||||
disable_1m_context: currentConfig.disable_1m_context ?? false,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -293,8 +287,6 @@
|
|||||||
custom_instructions: currentConfig.custom_instructions || null,
|
custom_instructions: currentConfig.custom_instructions || null,
|
||||||
mcp_servers_json: currentConfig.mcp_servers_json || null,
|
mcp_servers_json: currentConfig.mcp_servers_json || null,
|
||||||
allowed_tools: allAllowedTools,
|
allowed_tools: allAllowedTools,
|
||||||
use_worktree: currentConfig.use_worktree ?? false,
|
|
||||||
disable_1m_context: currentConfig.disable_1m_context ?? false,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -389,16 +381,16 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center gap-2 flex-wrap min-w-0">
|
<div class="flex items-center gap-3">
|
||||||
{#if streamerModeActive}
|
{#if streamerModeActive}
|
||||||
<div
|
<div
|
||||||
class="w-2.5 h-2.5 rounded-full bg-red-500 animate-pulse shrink-0"
|
class="w-2.5 h-2.5 rounded-full bg-red-500 animate-pulse"
|
||||||
title="Streamer mode active (Ctrl+Shift+S to toggle)"
|
title="Streamer mode active (Ctrl+Shift+S to toggle)"
|
||||||
></div>
|
></div>
|
||||||
{/if}
|
{/if}
|
||||||
<button
|
<button
|
||||||
onclick={() => (showProfile = true)}
|
onclick={() => (showProfile = true)}
|
||||||
class="p-1 text-gray-500 icon-trans-hover shrink-0"
|
class="p-1 text-gray-500 icon-trans-hover"
|
||||||
title="Profile"
|
title="Profile"
|
||||||
>
|
>
|
||||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
@@ -527,20 +519,6 @@
|
|||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<button
|
|
||||||
onclick={() => (showCastPanel = true)}
|
|
||||||
class="p-1 text-gray-500 icon-trans-hover"
|
|
||||||
title="Meet the Team"
|
|
||||||
>
|
|
||||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
||||||
<path
|
|
||||||
stroke-linecap="round"
|
|
||||||
stroke-linejoin="round"
|
|
||||||
stroke-width="2"
|
|
||||||
d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
<button
|
<button
|
||||||
onclick={() => (showAgentMonitor = !showAgentMonitor)}
|
onclick={() => (showAgentMonitor = !showAgentMonitor)}
|
||||||
class="p-1 text-gray-500 icon-trans-hover relative {showAgentMonitor
|
class="p-1 text-gray-500 icon-trans-hover relative {showAgentMonitor
|
||||||
@@ -718,7 +696,7 @@
|
|||||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||||
<div class="fixed inset-0 z-40" onclick={() => (showStats = false)}></div>
|
<div class="fixed inset-0 z-40" onclick={() => (showStats = false)}></div>
|
||||||
<div class="fixed top-14 right-4 z-50 max-h-[calc(100vh-4rem)] overflow-y-auto">
|
<div class="fixed top-14 right-4 z-50">
|
||||||
<StatsDisplay
|
<StatsDisplay
|
||||||
onRequestSummary={handleCompactConversation}
|
onRequestSummary={handleCompactConversation}
|
||||||
onStartFreshWithContext={handleStartFreshWithContext}
|
onStartFreshWithContext={handleStartFreshWithContext}
|
||||||
@@ -759,10 +737,6 @@
|
|||||||
<AgentMonitorPanel isOpen={showAgentMonitor} onClose={() => (showAgentMonitor = false)} />
|
<AgentMonitorPanel isOpen={showAgentMonitor} onClose={() => (showAgentMonitor = false)} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if showCastPanel}
|
|
||||||
<CastPanel onClose={() => (showCastPanel = false)} />
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{#if showPluginPanel}
|
{#if showPluginPanel}
|
||||||
<PluginManagementPanel onClose={() => (showPluginPanel = false)} />
|
<PluginManagementPanel onClose={() => (showPluginPanel = false)} />
|
||||||
{/if}
|
{/if}
|
||||||
@@ -770,32 +744,3 @@
|
|||||||
{#if showMcpPanel}
|
{#if showMcpPanel}
|
||||||
<McpManagementPanel onClose={() => (showMcpPanel = false)} />
|
<McpManagementPanel onClose={() => (showMcpPanel = false)} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<style>
|
|
||||||
/* Responsive status bar styling */
|
|
||||||
.status-bar {
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
gap: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make all icon buttons shrink but not grow */
|
|
||||||
.status-bar button {
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Hide version text on very small screens */
|
|
||||||
@media (max-width: 640px) {
|
|
||||||
.status-bar button span:last-of-type {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Stack left and right sections on very small screens */
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
.status-bar {
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 0.75rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { claudeStore, type TerminalLine } from "$lib/stores/claude";
|
import { claudeStore, type TerminalLine } from "$lib/stores/claude";
|
||||||
import { afterUpdate, tick, onMount, onDestroy } from "svelte";
|
import { afterUpdate, tick, onMount, onDestroy } from "svelte";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
|
||||||
|
|
||||||
import ConversationTabs from "./ConversationTabs.svelte";
|
import ConversationTabs from "./ConversationTabs.svelte";
|
||||||
import Markdown from "./Markdown.svelte";
|
import Markdown from "./Markdown.svelte";
|
||||||
import HighlightedText from "./HighlightedText.svelte";
|
import HighlightedText from "./HighlightedText.svelte";
|
||||||
@@ -94,14 +92,6 @@
|
|||||||
return "terminal-error";
|
return "terminal-error";
|
||||||
case "thinking":
|
case "thinking":
|
||||||
return "terminal-thinking";
|
return "terminal-thinking";
|
||||||
case "rate-limit":
|
|
||||||
return "terminal-rate-limit";
|
|
||||||
case "compact-prompt":
|
|
||||||
return "terminal-compact-prompt";
|
|
||||||
case "worktree":
|
|
||||||
return "terminal-worktree";
|
|
||||||
case "config-change":
|
|
||||||
return "terminal-config-change";
|
|
||||||
default:
|
default:
|
||||||
return "terminal-default";
|
return "terminal-default";
|
||||||
}
|
}
|
||||||
@@ -119,12 +109,6 @@
|
|||||||
return "[tool]";
|
return "[tool]";
|
||||||
case "error":
|
case "error":
|
||||||
return "[error]";
|
return "[error]";
|
||||||
case "rate-limit":
|
|
||||||
return "[rate-limit]";
|
|
||||||
case "worktree":
|
|
||||||
return "[worktree]";
|
|
||||||
case "config-change":
|
|
||||||
return "[config]";
|
|
||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -203,27 +187,6 @@
|
|||||||
copiedMessageId = null;
|
copiedMessageId = null;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleCompact() {
|
|
||||||
if (!currentConversationId) return;
|
|
||||||
await invoke("send_prompt", { conversationId: currentConversationId, message: "/compact" });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collapsible tool lines
|
|
||||||
const TOOL_COLLAPSE_THRESHOLD = 60;
|
|
||||||
let expandedToolLines: Record<string, boolean> = {};
|
|
||||||
|
|
||||||
function isToolContentLong(content: string): boolean {
|
|
||||||
return content.length > TOOL_COLLAPSE_THRESHOLD;
|
|
||||||
}
|
|
||||||
|
|
||||||
function truncateToolContent(content: string): string {
|
|
||||||
return content.slice(0, TOOL_COLLAPSE_THRESHOLD) + "…";
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleToolLine(id: string) {
|
|
||||||
expandedToolLines = { ...expandedToolLines, [id]: !expandedToolLines[id] };
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@@ -299,11 +262,7 @@
|
|||||||
{#if line.toolName}
|
{#if line.toolName}
|
||||||
<span class="terminal-tool-name mr-2">[{line.toolName}]</span>
|
<span class="terminal-tool-name mr-2">[{line.toolName}]</span>
|
||||||
{/if}
|
{/if}
|
||||||
{#if line.type === "compact-prompt"}
|
{#if line.type === "assistant" || line.type === "user"}
|
||||||
<button class="compact-action-btn" onclick={handleCompact}>
|
|
||||||
⚡ Compact Conversation
|
|
||||||
</button>
|
|
||||||
{:else if line.type === "assistant" || line.type === "user"}
|
|
||||||
<div class="message-content-wrapper">
|
<div class="message-content-wrapper">
|
||||||
<Markdown
|
<Markdown
|
||||||
content={maskPaths(line.content, hidePaths)}
|
content={maskPaths(line.content, hidePaths)}
|
||||||
@@ -330,22 +289,6 @@
|
|||||||
<span class="copy-text">{copiedMessageId === line.id ? "Copied!" : "Copy"}</span>
|
<span class="copy-text">{copiedMessageId === line.id ? "Copied!" : "Copy"}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{:else if line.type === "tool" && isToolContentLong(maskPaths(line.content, hidePaths))}
|
|
||||||
<span class="tool-collapsible">
|
|
||||||
<HighlightedText
|
|
||||||
content={expandedToolLines[line.id]
|
|
||||||
? maskPaths(line.content, hidePaths)
|
|
||||||
: truncateToolContent(maskPaths(line.content, hidePaths))}
|
|
||||||
searchQuery={currentSearchQuery}
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
class="tool-toggle-btn"
|
|
||||||
onclick={() => toggleToolLine(line.id)}
|
|
||||||
title={expandedToolLines[line.id] ? "Collapse" : "Expand to see full content"}
|
|
||||||
>
|
|
||||||
{expandedToolLines[line.id] ? "▲" : "▼"}
|
|
||||||
</button>
|
|
||||||
</span>
|
|
||||||
{:else}
|
{:else}
|
||||||
<HighlightedText
|
<HighlightedText
|
||||||
content={maskPaths(line.content, hidePaths)}
|
content={maskPaths(line.content, hidePaths)}
|
||||||
@@ -386,42 +329,6 @@
|
|||||||
color: var(--terminal-error, #f87171);
|
color: var(--terminal-error, #f87171);
|
||||||
}
|
}
|
||||||
|
|
||||||
.terminal-rate-limit {
|
|
||||||
color: var(--terminal-rate-limit, #fb923c);
|
|
||||||
}
|
|
||||||
|
|
||||||
.terminal-compact-prompt {
|
|
||||||
color: var(--text-secondary);
|
|
||||||
}
|
|
||||||
|
|
||||||
.terminal-worktree {
|
|
||||||
color: var(--terminal-worktree, #34d399);
|
|
||||||
}
|
|
||||||
|
|
||||||
.terminal-config-change {
|
|
||||||
color: var(--terminal-config-change, #a78bfa);
|
|
||||||
}
|
|
||||||
|
|
||||||
.compact-action-btn {
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.4em;
|
|
||||||
background: var(--bg-secondary);
|
|
||||||
border: 1px solid var(--terminal-error, #f87171);
|
|
||||||
color: var(--terminal-error, #f87171);
|
|
||||||
padding: 0.3em 0.8em;
|
|
||||||
cursor: pointer;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-size: 0.9em;
|
|
||||||
font-family: inherit;
|
|
||||||
transition: all 0.15s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.compact-action-btn:hover {
|
|
||||||
background: color-mix(in srgb, var(--terminal-error, #f87171) 15%, transparent);
|
|
||||||
color: var(--terminal-error, #f87171);
|
|
||||||
}
|
|
||||||
|
|
||||||
.terminal-default {
|
.terminal-default {
|
||||||
color: var(--text-primary);
|
color: var(--text-primary);
|
||||||
}
|
}
|
||||||
@@ -501,28 +408,4 @@
|
|||||||
.terminal-line {
|
.terminal-line {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tool-collapsible {
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: baseline;
|
|
||||||
gap: 0.4em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tool-toggle-btn {
|
|
||||||
background: none;
|
|
||||||
border: none;
|
|
||||||
color: var(--text-tertiary, #6b7280);
|
|
||||||
cursor: pointer;
|
|
||||||
font-size: 0.7em;
|
|
||||||
padding: 0;
|
|
||||||
line-height: 1;
|
|
||||||
opacity: 0.7;
|
|
||||||
transition: opacity 0.15s ease;
|
|
||||||
font-family: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tool-toggle-btn:hover {
|
|
||||||
opacity: 1;
|
|
||||||
color: var(--terminal-tool, #c084fc);
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,264 +0,0 @@
|
|||||||
/**
|
|
||||||
* Terminal Component Tests
|
|
||||||
*
|
|
||||||
* Tests the pure helper functions extracted from the Terminal component:
|
|
||||||
* - getLineClass: maps line types to CSS class names
|
|
||||||
* - getLinePrefix: maps line types to display prefixes
|
|
||||||
* - formatTime: formats a Date as "HH:MM AM/PM"
|
|
||||||
* - isToolContentLong: checks if tool content exceeds collapse threshold
|
|
||||||
* - truncateToolContent: truncates long tool content with ellipsis
|
|
||||||
*
|
|
||||||
* Manual testing checklist:
|
|
||||||
* - [ ] rate-limit lines appear in amber
|
|
||||||
* - [ ] error lines appear in red
|
|
||||||
* - [ ] tool lines appear in purple
|
|
||||||
* - [ ] system lines appear in grey italic
|
|
||||||
* - [ ] user lines appear in cyan
|
|
||||||
* - [ ] assistant lines appear in primary text colour
|
|
||||||
* - [ ] long tool content is collapsed by default with a toggle button
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { describe, it, expect } from "vitest";
|
|
||||||
|
|
||||||
// Mirror functions from Terminal.svelte for isolated testing
|
|
||||||
|
|
||||||
function getLineClass(type: string): string {
|
|
||||||
switch (type) {
|
|
||||||
case "user":
|
|
||||||
return "terminal-user";
|
|
||||||
case "assistant":
|
|
||||||
return "terminal-assistant";
|
|
||||||
case "system":
|
|
||||||
return "terminal-system italic";
|
|
||||||
case "tool":
|
|
||||||
return "terminal-tool";
|
|
||||||
case "error":
|
|
||||||
return "terminal-error";
|
|
||||||
case "thinking":
|
|
||||||
return "terminal-thinking";
|
|
||||||
case "rate-limit":
|
|
||||||
return "terminal-rate-limit";
|
|
||||||
case "compact-prompt":
|
|
||||||
return "terminal-compact-prompt";
|
|
||||||
case "worktree":
|
|
||||||
return "terminal-worktree";
|
|
||||||
case "config-change":
|
|
||||||
return "terminal-config-change";
|
|
||||||
default:
|
|
||||||
return "terminal-default";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getLinePrefix(type: string): string {
|
|
||||||
switch (type) {
|
|
||||||
case "user":
|
|
||||||
return ">";
|
|
||||||
case "assistant":
|
|
||||||
return "";
|
|
||||||
case "system":
|
|
||||||
return "[system]";
|
|
||||||
case "tool":
|
|
||||||
return "[tool]";
|
|
||||||
case "error":
|
|
||||||
return "[error]";
|
|
||||||
case "rate-limit":
|
|
||||||
return "[rate-limit]";
|
|
||||||
case "worktree":
|
|
||||||
return "[worktree]";
|
|
||||||
case "config-change":
|
|
||||||
return "[config]";
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatTime(date: Date): string {
|
|
||||||
return date.toLocaleTimeString("en-US", {
|
|
||||||
hour: "2-digit",
|
|
||||||
minute: "2-digit",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const TOOL_COLLAPSE_THRESHOLD = 60;
|
|
||||||
|
|
||||||
function isToolContentLong(content: string): boolean {
|
|
||||||
return content.length > TOOL_COLLAPSE_THRESHOLD;
|
|
||||||
}
|
|
||||||
|
|
||||||
function truncateToolContent(content: string): string {
|
|
||||||
return content.slice(0, TOOL_COLLAPSE_THRESHOLD) + "…";
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---
|
|
||||||
|
|
||||||
describe("getLineClass", () => {
|
|
||||||
it("returns terminal-user for user lines", () => {
|
|
||||||
expect(getLineClass("user")).toBe("terminal-user");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns terminal-assistant for assistant lines", () => {
|
|
||||||
expect(getLineClass("assistant")).toBe("terminal-assistant");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns terminal-system italic for system lines", () => {
|
|
||||||
expect(getLineClass("system")).toBe("terminal-system italic");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns terminal-tool for tool lines", () => {
|
|
||||||
expect(getLineClass("tool")).toBe("terminal-tool");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns terminal-error for error lines", () => {
|
|
||||||
expect(getLineClass("error")).toBe("terminal-error");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns terminal-thinking for thinking lines", () => {
|
|
||||||
expect(getLineClass("thinking")).toBe("terminal-thinking");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns terminal-rate-limit for rate-limit lines", () => {
|
|
||||||
expect(getLineClass("rate-limit")).toBe("terminal-rate-limit");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns terminal-compact-prompt for compact-prompt lines", () => {
|
|
||||||
expect(getLineClass("compact-prompt")).toBe("terminal-compact-prompt");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns terminal-worktree for worktree lines", () => {
|
|
||||||
expect(getLineClass("worktree")).toBe("terminal-worktree");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns terminal-config-change for config-change lines", () => {
|
|
||||||
expect(getLineClass("config-change")).toBe("terminal-config-change");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns terminal-default for unknown line types", () => {
|
|
||||||
expect(getLineClass("unknown")).toBe("terminal-default");
|
|
||||||
expect(getLineClass("")).toBe("terminal-default");
|
|
||||||
expect(getLineClass("random-future-type")).toBe("terminal-default");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("getLinePrefix", () => {
|
|
||||||
it("returns > for user lines", () => {
|
|
||||||
expect(getLinePrefix("user")).toBe(">");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns empty string for assistant lines", () => {
|
|
||||||
expect(getLinePrefix("assistant")).toBe("");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns [system] for system lines", () => {
|
|
||||||
expect(getLinePrefix("system")).toBe("[system]");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns [tool] for tool lines", () => {
|
|
||||||
expect(getLinePrefix("tool")).toBe("[tool]");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns [error] for error lines", () => {
|
|
||||||
expect(getLinePrefix("error")).toBe("[error]");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns [rate-limit] for rate-limit lines", () => {
|
|
||||||
expect(getLinePrefix("rate-limit")).toBe("[rate-limit]");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns empty string for compact-prompt lines (button renders instead)", () => {
|
|
||||||
expect(getLinePrefix("compact-prompt")).toBe("");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns [worktree] for worktree lines", () => {
|
|
||||||
expect(getLinePrefix("worktree")).toBe("[worktree]");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns [config] for config-change lines", () => {
|
|
||||||
expect(getLinePrefix("config-change")).toBe("[config]");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns empty string for thinking lines (no prefix)", () => {
|
|
||||||
expect(getLinePrefix("thinking")).toBe("");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns empty string for unknown line types", () => {
|
|
||||||
expect(getLinePrefix("unknown")).toBe("");
|
|
||||||
expect(getLinePrefix("")).toBe("");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("formatTime", () => {
|
|
||||||
it("formats time in 12-hour format with AM/PM", () => {
|
|
||||||
const date = new Date(2026, 1, 7, 14, 35);
|
|
||||||
const formatted = formatTime(date);
|
|
||||||
expect(formatted).toMatch(/\d{2}:\d{2}\s?(AM|PM)/i);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("formats afternoon times correctly", () => {
|
|
||||||
const date = new Date(2026, 1, 7, 14, 35);
|
|
||||||
const formatted = formatTime(date);
|
|
||||||
expect(formatted).toContain("02:35");
|
|
||||||
expect(formatted.toUpperCase()).toContain("PM");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("formats morning times correctly", () => {
|
|
||||||
const date = new Date(2026, 1, 7, 9, 5);
|
|
||||||
const formatted = formatTime(date);
|
|
||||||
expect(formatted).toContain("09:05");
|
|
||||||
expect(formatted.toUpperCase()).toContain("AM");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("formats midnight correctly", () => {
|
|
||||||
const date = new Date(2026, 1, 7, 0, 0);
|
|
||||||
const formatted = formatTime(date);
|
|
||||||
expect(formatted).toContain("12:00");
|
|
||||||
expect(formatted.toUpperCase()).toContain("AM");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("formats noon correctly", () => {
|
|
||||||
const date = new Date(2026, 1, 7, 12, 0);
|
|
||||||
const formatted = formatTime(date);
|
|
||||||
expect(formatted).toContain("12:00");
|
|
||||||
expect(formatted.toUpperCase()).toContain("PM");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("isToolContentLong", () => {
|
|
||||||
it("returns false for content at or below the threshold", () => {
|
|
||||||
const exactThreshold = "x".repeat(TOOL_COLLAPSE_THRESHOLD);
|
|
||||||
expect(isToolContentLong(exactThreshold)).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns true for content exceeding the threshold", () => {
|
|
||||||
const overThreshold = "x".repeat(TOOL_COLLAPSE_THRESHOLD + 1);
|
|
||||||
expect(isToolContentLong(overThreshold)).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns false for short content", () => {
|
|
||||||
expect(isToolContentLong("short")).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns false for empty content", () => {
|
|
||||||
expect(isToolContentLong("")).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("truncateToolContent", () => {
|
|
||||||
it("truncates content to the threshold length with an ellipsis", () => {
|
|
||||||
const long = "x".repeat(100);
|
|
||||||
const result = truncateToolContent(long);
|
|
||||||
expect(result).toBe("x".repeat(TOOL_COLLAPSE_THRESHOLD) + "…");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("keeps content shorter than threshold unchanged (plus ellipsis)", () => {
|
|
||||||
const short = "hello";
|
|
||||||
const result = truncateToolContent(short);
|
|
||||||
expect(result).toBe("hello…");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("uses the unicode ellipsis character (not three dots)", () => {
|
|
||||||
const long = "x".repeat(100);
|
|
||||||
const result = truncateToolContent(long);
|
|
||||||
expect(result.endsWith("…")).toBe(true);
|
|
||||||
expect(result.endsWith("...")).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -47,7 +47,12 @@
|
|||||||
width="14"
|
width="14"
|
||||||
height="14"
|
height="14"
|
||||||
>
|
>
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
stroke-width="2"
|
||||||
|
d="M19 9l-7 7-7-7"
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { todos } from "$lib/stores/todos";
|
import { todos, type TodoItem } from "$lib/stores/todos";
|
||||||
import { CheckCircle, Circle, Loader } from "lucide-svelte";
|
import { CheckCircle, Circle, Loader } from "lucide-svelte";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|||||||
@@ -106,8 +106,6 @@
|
|||||||
custom_instructions: config.custom_instructions || null,
|
custom_instructions: config.custom_instructions || null,
|
||||||
mcp_servers_json: config.mcp_servers_json || null,
|
mcp_servers_json: config.mcp_servers_json || null,
|
||||||
allowed_tools: grantedToolsList,
|
allowed_tools: grantedToolsList,
|
||||||
use_worktree: config.use_worktree ?? false,
|
|
||||||
disable_1m_context: config.disable_1m_context ?? false,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,376 +0,0 @@
|
|||||||
import { describe, it, expect, beforeEach } from "vitest";
|
|
||||||
import { agentStore, getAgentsForConversation, runningAgentCount } from "./agents";
|
|
||||||
import { get } from "svelte/store";
|
|
||||||
import type { AgentInfo } from "$lib/types/agents";
|
|
||||||
import { CHARACTER_POOL } from "$lib/utils/agentCharacters";
|
|
||||||
|
|
||||||
describe("agents store", () => {
|
|
||||||
const conversationId = "test-conversation-1";
|
|
||||||
const otherConversationId = "test-conversation-2";
|
|
||||||
|
|
||||||
type AgentInput = Omit<AgentInfo, "characterName" | "characterAvatar">;
|
|
||||||
|
|
||||||
const createMockAgent = (overrides?: Partial<AgentInput>): AgentInput => ({
|
|
||||||
toolUseId: "toolu_test123",
|
|
||||||
description: "Test agent",
|
|
||||||
subagentType: "Explore",
|
|
||||||
startedAt: Date.now(),
|
|
||||||
status: "running",
|
|
||||||
...overrides,
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
// Clear all conversations by subscribing and getting state
|
|
||||||
let state: Record<string, AgentInfo[]> = {};
|
|
||||||
const unsub = agentStore.subscribe((s) => {
|
|
||||||
state = s;
|
|
||||||
});
|
|
||||||
unsub();
|
|
||||||
|
|
||||||
// Clear each conversation
|
|
||||||
for (const convId of Object.keys(state)) {
|
|
||||||
agentStore.clearConversation(convId);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("addAgent", () => {
|
|
||||||
it("adds an agent to a conversation", () => {
|
|
||||||
const agent = createMockAgent();
|
|
||||||
agentStore.addAgent(conversationId, agent);
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
expect(agents).toHaveLength(1);
|
|
||||||
expect(agents[0]).toMatchObject(agent);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("assigns a character name and avatar to added agents", () => {
|
|
||||||
const agent = createMockAgent();
|
|
||||||
agentStore.addAgent(conversationId, agent);
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
const validNames = CHARACTER_POOL.map((c) => c.name);
|
|
||||||
expect(validNames).toContain(agents[0].characterName);
|
|
||||||
expect(agents[0].characterAvatar).toMatch(/^https:\/\//u);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("avoids duplicate character names across agents when possible", () => {
|
|
||||||
// Add 6 agents - each should ideally get a unique character
|
|
||||||
for (let i = 0; i < 6; i++) {
|
|
||||||
agentStore.addAgent(conversationId, createMockAgent({ toolUseId: `tool${i.toString()}` }));
|
|
||||||
}
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
const names = agents.map((a) => a.characterName);
|
|
||||||
const uniqueNames = new Set(names);
|
|
||||||
expect(uniqueNames.size).toBe(6);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("adds multiple agents to the same conversation", () => {
|
|
||||||
const agent1 = createMockAgent({ toolUseId: "tool1" });
|
|
||||||
const agent2 = createMockAgent({ toolUseId: "tool2" });
|
|
||||||
|
|
||||||
agentStore.addAgent(conversationId, agent1);
|
|
||||||
agentStore.addAgent(conversationId, agent2);
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
expect(agents).toHaveLength(2);
|
|
||||||
expect(agents[0]).toMatchObject(agent1);
|
|
||||||
expect(agents[1]).toMatchObject(agent2);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("keeps agents in different conversations separate", () => {
|
|
||||||
const agent1 = createMockAgent({ toolUseId: "tool1" });
|
|
||||||
const agent2 = createMockAgent({ toolUseId: "tool2" });
|
|
||||||
|
|
||||||
agentStore.addAgent(conversationId, agent1);
|
|
||||||
agentStore.addAgent(otherConversationId, agent2);
|
|
||||||
|
|
||||||
const agents1 = get(getAgentsForConversation(conversationId));
|
|
||||||
const agents2 = get(getAgentsForConversation(otherConversationId));
|
|
||||||
|
|
||||||
expect(agents1).toHaveLength(1);
|
|
||||||
expect(agents2).toHaveLength(1);
|
|
||||||
expect(agents1[0]).toMatchObject(agent1);
|
|
||||||
expect(agents2[0]).toMatchObject(agent2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("updateAgentId", () => {
|
|
||||||
it("updates the agent_id for a specific agent", () => {
|
|
||||||
const agent = createMockAgent({ agentId: undefined });
|
|
||||||
agentStore.addAgent(conversationId, agent);
|
|
||||||
|
|
||||||
agentStore.updateAgentId(conversationId, agent.toolUseId, "agent-abc123");
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
expect(agents[0].agentId).toBe("agent-abc123");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does nothing if conversation doesn't exist", () => {
|
|
||||||
agentStore.updateAgentId("nonexistent", "tool1", "agent1");
|
|
||||||
// Should not throw
|
|
||||||
expect(true).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does nothing if tool_use_id doesn't exist", () => {
|
|
||||||
const agent = createMockAgent();
|
|
||||||
agentStore.addAgent(conversationId, agent);
|
|
||||||
|
|
||||||
agentStore.updateAgentId(conversationId, "nonexistent-tool", "agent1");
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
expect(agents[0].agentId).toBeUndefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("endAgent", () => {
|
|
||||||
it("marks an agent as completed", () => {
|
|
||||||
const agent = createMockAgent({ status: "running" });
|
|
||||||
agentStore.addAgent(conversationId, agent);
|
|
||||||
|
|
||||||
const endTime = Date.now();
|
|
||||||
agentStore.endAgent(conversationId, agent.toolUseId, endTime, false);
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
expect(agents[0].status).toBe("completed");
|
|
||||||
expect(agents[0].endedAt).toBe(endTime);
|
|
||||||
expect(agents[0].durationMs).toBeGreaterThanOrEqual(0); // Duration can be 0 if timestamps are the same
|
|
||||||
});
|
|
||||||
|
|
||||||
it("marks an agent as errored", () => {
|
|
||||||
const agent = createMockAgent({ status: "running" });
|
|
||||||
agentStore.addAgent(conversationId, agent);
|
|
||||||
|
|
||||||
const endTime = Date.now();
|
|
||||||
agentStore.endAgent(conversationId, agent.toolUseId, endTime, true);
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
expect(agents[0].status).toBe("errored");
|
|
||||||
expect(agents[0].endedAt).toBe(endTime);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("calculates duration correctly", () => {
|
|
||||||
const startTime = Date.now() - 5000; // 5 seconds ago
|
|
||||||
const agent = createMockAgent({ startedAt: startTime, status: "running" });
|
|
||||||
agentStore.addAgent(conversationId, agent);
|
|
||||||
|
|
||||||
const endTime = Date.now();
|
|
||||||
agentStore.endAgent(conversationId, agent.toolUseId, endTime, false);
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
expect(agents[0].durationMs).toBeGreaterThanOrEqual(5000);
|
|
||||||
expect(agents[0].durationMs).toBeLessThanOrEqual(6000); // Allow some buffer
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does nothing if conversation doesn't exist", () => {
|
|
||||||
agentStore.endAgent("nonexistent", "tool1", Date.now(), false);
|
|
||||||
// Should not throw
|
|
||||||
expect(true).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does nothing if agent doesn't exist", () => {
|
|
||||||
const agent = createMockAgent();
|
|
||||||
agentStore.addAgent(conversationId, agent);
|
|
||||||
|
|
||||||
agentStore.endAgent(conversationId, "nonexistent-tool", Date.now(), false);
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
expect(agents[0].status).toBe("running"); // Status unchanged
|
|
||||||
});
|
|
||||||
|
|
||||||
it("stores lastAssistantMessage when provided", () => {
|
|
||||||
const agent = createMockAgent({ status: "running" });
|
|
||||||
agentStore.addAgent(conversationId, agent);
|
|
||||||
|
|
||||||
agentStore.endAgent(
|
|
||||||
conversationId,
|
|
||||||
agent.toolUseId,
|
|
||||||
Date.now(),
|
|
||||||
false,
|
|
||||||
"Task completed successfully."
|
|
||||||
);
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
expect(agents[0].lastAssistantMessage).toBe("Task completed successfully.");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("leaves lastAssistantMessage undefined when not provided", () => {
|
|
||||||
const agent = createMockAgent({ status: "running" });
|
|
||||||
agentStore.addAgent(conversationId, agent);
|
|
||||||
|
|
||||||
agentStore.endAgent(conversationId, agent.toolUseId, Date.now(), false);
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
expect(agents[0].lastAssistantMessage).toBeUndefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("markAllErrored", () => {
|
|
||||||
it("marks all running agents as errored", () => {
|
|
||||||
const agent1 = createMockAgent({ toolUseId: "tool1", status: "running" });
|
|
||||||
const agent2 = createMockAgent({ toolUseId: "tool2", status: "running" });
|
|
||||||
const agent3 = createMockAgent({ toolUseId: "tool3", status: "completed" });
|
|
||||||
|
|
||||||
agentStore.addAgent(conversationId, agent1);
|
|
||||||
agentStore.addAgent(conversationId, agent2);
|
|
||||||
agentStore.addAgent(conversationId, agent3);
|
|
||||||
|
|
||||||
agentStore.markAllErrored(conversationId);
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
expect(agents[0].status).toBe("errored");
|
|
||||||
expect(agents[0].endedAt).toBeGreaterThan(0);
|
|
||||||
expect(agents[1].status).toBe("errored");
|
|
||||||
expect(agents[1].endedAt).toBeGreaterThan(0);
|
|
||||||
expect(agents[2].status).toBe("completed"); // Already completed, unchanged
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does nothing if conversation doesn't exist", () => {
|
|
||||||
agentStore.markAllErrored("nonexistent");
|
|
||||||
// Should not throw
|
|
||||||
expect(true).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does nothing if conversation has no running agents", () => {
|
|
||||||
const agent = createMockAgent({ status: "completed" });
|
|
||||||
agentStore.addAgent(conversationId, agent);
|
|
||||||
|
|
||||||
agentStore.markAllErrored(conversationId);
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
expect(agents[0].status).toBe("completed"); // Unchanged
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("clearCompleted", () => {
|
|
||||||
it("removes completed and errored agents", () => {
|
|
||||||
const agent1 = createMockAgent({ toolUseId: "tool1", status: "running" });
|
|
||||||
const agent2 = createMockAgent({ toolUseId: "tool2", status: "completed" });
|
|
||||||
const agent3 = createMockAgent({ toolUseId: "tool3", status: "errored" });
|
|
||||||
|
|
||||||
agentStore.addAgent(conversationId, agent1);
|
|
||||||
agentStore.addAgent(conversationId, agent2);
|
|
||||||
agentStore.addAgent(conversationId, agent3);
|
|
||||||
|
|
||||||
agentStore.clearCompleted(conversationId);
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
expect(agents).toHaveLength(1);
|
|
||||||
expect(agents[0].toolUseId).toBe("tool1"); // Only running agent remains
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does nothing if conversation doesn't exist", () => {
|
|
||||||
agentStore.clearCompleted("nonexistent");
|
|
||||||
// Should not throw
|
|
||||||
expect(true).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("clears all agents if all are completed", () => {
|
|
||||||
const agent1 = createMockAgent({ toolUseId: "tool1", status: "completed" });
|
|
||||||
const agent2 = createMockAgent({ toolUseId: "tool2", status: "errored" });
|
|
||||||
|
|
||||||
agentStore.addAgent(conversationId, agent1);
|
|
||||||
agentStore.addAgent(conversationId, agent2);
|
|
||||||
|
|
||||||
agentStore.clearCompleted(conversationId);
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
expect(agents).toHaveLength(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("clearConversation", () => {
|
|
||||||
it("removes all agents from a conversation", () => {
|
|
||||||
const agent1 = createMockAgent({ toolUseId: "tool1" });
|
|
||||||
const agent2 = createMockAgent({ toolUseId: "tool2" });
|
|
||||||
|
|
||||||
agentStore.addAgent(conversationId, agent1);
|
|
||||||
agentStore.addAgent(conversationId, agent2);
|
|
||||||
|
|
||||||
agentStore.clearConversation(conversationId);
|
|
||||||
|
|
||||||
const agents = get(getAgentsForConversation(conversationId));
|
|
||||||
expect(agents).toHaveLength(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("only removes agents from the specified conversation", () => {
|
|
||||||
const agent1 = createMockAgent({ toolUseId: "tool1" });
|
|
||||||
const agent2 = createMockAgent({ toolUseId: "tool2" });
|
|
||||||
|
|
||||||
agentStore.addAgent(conversationId, agent1);
|
|
||||||
agentStore.addAgent(otherConversationId, agent2);
|
|
||||||
|
|
||||||
agentStore.clearConversation(conversationId);
|
|
||||||
|
|
||||||
const agents1 = get(getAgentsForConversation(conversationId));
|
|
||||||
const agents2 = get(getAgentsForConversation(otherConversationId));
|
|
||||||
|
|
||||||
expect(agents1).toHaveLength(0);
|
|
||||||
expect(agents2).toHaveLength(1);
|
|
||||||
expect(agents2[0]).toMatchObject(agent2);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does nothing if conversation doesn't exist", () => {
|
|
||||||
agentStore.clearConversation("nonexistent");
|
|
||||||
// Should not throw
|
|
||||||
expect(true).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("runningAgentCount", () => {
|
|
||||||
it("counts running agents across all conversations", () => {
|
|
||||||
const agent1 = createMockAgent({ toolUseId: "tool1", status: "running" });
|
|
||||||
const agent2 = createMockAgent({ toolUseId: "tool2", status: "running" });
|
|
||||||
const agent3 = createMockAgent({ toolUseId: "tool3", status: "completed" });
|
|
||||||
const agent4 = createMockAgent({ toolUseId: "tool4", status: "running" });
|
|
||||||
|
|
||||||
agentStore.addAgent(conversationId, agent1);
|
|
||||||
agentStore.addAgent(conversationId, agent2);
|
|
||||||
agentStore.addAgent(conversationId, agent3);
|
|
||||||
agentStore.addAgent(otherConversationId, agent4);
|
|
||||||
|
|
||||||
const count = get(runningAgentCount);
|
|
||||||
expect(count).toBe(3); // 2 from first conversation + 1 from second
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns 0 when no agents are running", () => {
|
|
||||||
const agent1 = createMockAgent({ status: "completed" });
|
|
||||||
const agent2 = createMockAgent({ status: "errored" });
|
|
||||||
|
|
||||||
agentStore.addAgent(conversationId, agent1);
|
|
||||||
agentStore.addAgent(otherConversationId, agent2);
|
|
||||||
|
|
||||||
const count = get(runningAgentCount);
|
|
||||||
expect(count).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("updates when agents complete", () => {
|
|
||||||
const agent = createMockAgent({ status: "running" });
|
|
||||||
agentStore.addAgent(conversationId, agent);
|
|
||||||
|
|
||||||
let count = get(runningAgentCount);
|
|
||||||
expect(count).toBe(1);
|
|
||||||
|
|
||||||
agentStore.endAgent(conversationId, agent.toolUseId, Date.now(), false);
|
|
||||||
|
|
||||||
count = get(runningAgentCount);
|
|
||||||
expect(count).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("updates when conversation is cleared", () => {
|
|
||||||
const agent1 = createMockAgent({ toolUseId: "tool1", status: "running" });
|
|
||||||
const agent2 = createMockAgent({ toolUseId: "tool2", status: "running" });
|
|
||||||
|
|
||||||
agentStore.addAgent(conversationId, agent1);
|
|
||||||
agentStore.addAgent(conversationId, agent2);
|
|
||||||
|
|
||||||
let count = get(runningAgentCount);
|
|
||||||
expect(count).toBe(2);
|
|
||||||
|
|
||||||
agentStore.clearConversation(conversationId);
|
|
||||||
|
|
||||||
count = get(runningAgentCount);
|
|
||||||
expect(count).toBe(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import { writable, derived } from "svelte/store";
|
import { writable, derived } from "svelte/store";
|
||||||
import type { AgentInfo } from "$lib/types/agents";
|
import type { AgentInfo } from "$lib/types/agents";
|
||||||
import { assignCharacter } from "$lib/utils/agentCharacters";
|
|
||||||
|
|
||||||
// Map of conversation ID -> agents in that conversation
|
// Map of conversation ID -> agents in that conversation
|
||||||
const agentsByConversation = writable<Record<string, AgentInfo[]>>({});
|
const agentsByConversation = writable<Record<string, AgentInfo[]>>({});
|
||||||
@@ -9,17 +8,12 @@ function createAgentStore() {
|
|||||||
return {
|
return {
|
||||||
subscribe: agentsByConversation.subscribe,
|
subscribe: agentsByConversation.subscribe,
|
||||||
|
|
||||||
addAgent(conversationId: string, agent: Omit<AgentInfo, "characterName" | "characterAvatar">) {
|
addAgent(conversationId: string, agent: AgentInfo) {
|
||||||
agentsByConversation.update((state) => {
|
agentsByConversation.update((state) => {
|
||||||
const existing = state[conversationId] || [];
|
const existing = state[conversationId] || [];
|
||||||
const activeNames = existing.map((a) => a.characterName);
|
|
||||||
const character = assignCharacter(activeNames);
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
[conversationId]: [
|
[conversationId]: [...existing, agent],
|
||||||
...existing,
|
|
||||||
{ ...agent, characterName: character.name, characterAvatar: character.avatar },
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -45,13 +39,7 @@ function createAgentStore() {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
endAgent(
|
endAgent(conversationId: string, toolUseId: string, endedAt: number, isError: boolean) {
|
||||||
conversationId: string,
|
|
||||||
toolUseId: string,
|
|
||||||
endedAt: number,
|
|
||||||
isError: boolean,
|
|
||||||
lastAssistantMessage?: string
|
|
||||||
) {
|
|
||||||
agentsByConversation.update((state) => {
|
agentsByConversation.update((state) => {
|
||||||
const agents = state[conversationId];
|
const agents = state[conversationId];
|
||||||
if (!agents) return state;
|
if (!agents) return state;
|
||||||
@@ -68,7 +56,6 @@ function createAgentStore() {
|
|||||||
endedAt,
|
endedAt,
|
||||||
status: isError ? "errored" : "completed",
|
status: isError ? "errored" : "completed",
|
||||||
durationMs,
|
durationMs,
|
||||||
lastAssistantMessage,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -194,8 +194,6 @@ describe("config store", () => {
|
|||||||
budget_warning_threshold: 0.8,
|
budget_warning_threshold: 0.8,
|
||||||
discord_rpc_enabled: true,
|
discord_rpc_enabled: true,
|
||||||
show_thinking_blocks: true,
|
show_thinking_blocks: true,
|
||||||
use_worktree: false,
|
|
||||||
disable_1m_context: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(config.model).toBe("claude-sonnet-4");
|
expect(config.model).toBe("claude-sonnet-4");
|
||||||
@@ -242,8 +240,6 @@ describe("config store", () => {
|
|||||||
budget_warning_threshold: 0.8,
|
budget_warning_threshold: 0.8,
|
||||||
discord_rpc_enabled: true,
|
discord_rpc_enabled: true,
|
||||||
show_thinking_blocks: true,
|
show_thinking_blocks: true,
|
||||||
use_worktree: false,
|
|
||||||
disable_1m_context: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(config.model).toBeNull();
|
expect(config.model).toBeNull();
|
||||||
@@ -726,9 +722,6 @@ describe("config store", () => {
|
|||||||
it("handles save errors gracefully without losing data", async () => {
|
it("handles save errors gracefully without losing data", async () => {
|
||||||
const mockInvokeImpl = vi.mocked(invoke);
|
const mockInvokeImpl = vi.mocked(invoke);
|
||||||
|
|
||||||
// Mock console.error to suppress expected error output
|
|
||||||
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
||||||
|
|
||||||
// Set initial config
|
// Set initial config
|
||||||
await configStore.updateConfig({ font_size: 14 });
|
await configStore.updateConfig({ font_size: 14 });
|
||||||
|
|
||||||
@@ -740,12 +733,6 @@ describe("config store", () => {
|
|||||||
|
|
||||||
// Original config should still be accessible
|
// Original config should still be accessible
|
||||||
expect(configStore.getConfig().font_size).toBe(14);
|
expect(configStore.getConfig().font_size).toBe(14);
|
||||||
|
|
||||||
// Verify error was logged
|
|
||||||
expect(consoleErrorSpy).toHaveBeenCalledWith("Failed to save config:", expect.any(Error));
|
|
||||||
|
|
||||||
// Restore console.error
|
|
||||||
consoleErrorSpy.mockRestore();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -789,8 +776,6 @@ describe("config store", () => {
|
|||||||
budget_warning_threshold: 0.9,
|
budget_warning_threshold: 0.9,
|
||||||
discord_rpc_enabled: false,
|
discord_rpc_enabled: false,
|
||||||
show_thinking_blocks: true,
|
show_thinking_blocks: true,
|
||||||
use_worktree: false,
|
|
||||||
disable_1m_context: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockInvokeImpl = vi.mocked(invoke);
|
const mockInvokeImpl = vi.mocked(invoke);
|
||||||
|
|||||||
@@ -47,10 +47,6 @@ export interface HikariConfig {
|
|||||||
discord_rpc_enabled: boolean;
|
discord_rpc_enabled: boolean;
|
||||||
// Thinking blocks settings
|
// Thinking blocks settings
|
||||||
show_thinking_blocks: boolean;
|
show_thinking_blocks: boolean;
|
||||||
// Worktree isolation
|
|
||||||
use_worktree: boolean;
|
|
||||||
// Disable 1M context window
|
|
||||||
disable_1m_context: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultConfig: HikariConfig = {
|
const defaultConfig: HikariConfig = {
|
||||||
@@ -91,8 +87,6 @@ const defaultConfig: HikariConfig = {
|
|||||||
budget_warning_threshold: 0.8,
|
budget_warning_threshold: 0.8,
|
||||||
discord_rpc_enabled: true,
|
discord_rpc_enabled: true,
|
||||||
show_thinking_blocks: true,
|
show_thinking_blocks: true,
|
||||||
use_worktree: false,
|
|
||||||
disable_1m_context: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function createConfigStore() {
|
function createConfigStore() {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import type { CharacterState } from "$lib/types/states";
|
|||||||
import { cleanupConversationTracking } from "$lib/tauri";
|
import { cleanupConversationTracking } from "$lib/tauri";
|
||||||
import { characterState } from "$lib/stores/character";
|
import { characterState } from "$lib/stores/character";
|
||||||
import { sessionsStore } from "$lib/stores/sessions";
|
import { sessionsStore } from "$lib/stores/sessions";
|
||||||
import { agentStore } from "$lib/stores/agents";
|
|
||||||
|
|
||||||
export interface ConversationSummary {
|
export interface ConversationSummary {
|
||||||
generatedAt: Date;
|
generatedAt: Date;
|
||||||
@@ -334,10 +333,6 @@ function createConversationsStore() {
|
|||||||
// Clean up tracking for this conversation (including temp files)
|
// Clean up tracking for this conversation (including temp files)
|
||||||
await cleanupConversationTracking(id);
|
await cleanupConversationTracking(id);
|
||||||
|
|
||||||
// Clean up agent tracking for this conversation
|
|
||||||
// This prevents the badge from persisting after tab close
|
|
||||||
agentStore.clearConversation(id);
|
|
||||||
|
|
||||||
conversations.update((c) => {
|
conversations.update((c) => {
|
||||||
c.delete(id);
|
c.delete(id);
|
||||||
return c;
|
return c;
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ export type BudgetType = "token" | "cost";
|
|||||||
export const MODEL_PRICING: Record<string, { input: number; output: number }> = {
|
export const MODEL_PRICING: Record<string, { input: number; output: number }> = {
|
||||||
// Current generation (Claude 4.6)
|
// Current generation (Claude 4.6)
|
||||||
"claude-opus-4-6": { input: 5.0, output: 25.0 },
|
"claude-opus-4-6": { input: 5.0, output: 25.0 },
|
||||||
"claude-sonnet-4-6": { input: 3.0, output: 15.0 },
|
|
||||||
// Previous generation (Claude 4.5)
|
// Previous generation (Claude 4.5)
|
||||||
"claude-opus-4-5-20251101": { input: 5.0, output: 25.0 },
|
"claude-opus-4-5-20251101": { input: 5.0, output: 25.0 },
|
||||||
"claude-sonnet-4-5-20250929": { input: 3.0, output: 15.0 },
|
"claude-sonnet-4-5-20250929": { input: 3.0, output: 15.0 },
|
||||||
|
|||||||
+9
-82
@@ -29,7 +29,6 @@ interface StateChangePayload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const connectedConversations = new Set<string>();
|
const connectedConversations = new Set<string>();
|
||||||
const greetingPendingConversations = new Set<string>();
|
|
||||||
let unlisteners: Array<() => void> = [];
|
let unlisteners: Array<() => void> = [];
|
||||||
let skipNextGreeting = false;
|
let skipNextGreeting = false;
|
||||||
|
|
||||||
@@ -56,17 +55,17 @@ function generateGreetingPrompt(): string {
|
|||||||
return `[System: A new session has started. It's currently ${timeOfDay}. Please greet the user warmly and briefly. Keep it short - just 1-2 sentences.]`;
|
return `[System: A new session has started. It's currently ${timeOfDay}. Please greet the user warmly and briefly. Keep it short - just 1-2 sentences.]`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendGreeting(conversationId: string): Promise<boolean> {
|
async function sendGreeting(conversationId: string) {
|
||||||
// Check if we should skip this greeting
|
// Check if we should skip this greeting
|
||||||
if (skipNextGreeting) {
|
if (skipNextGreeting) {
|
||||||
skipNextGreeting = false; // Reset the flag
|
skipNextGreeting = false; // Reset the flag
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = configStore.getConfig();
|
const config = configStore.getConfig();
|
||||||
|
|
||||||
if (!config.greeting_enabled) {
|
if (!config.greeting_enabled) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const greetingPrompt = config.greeting_custom_prompt?.trim() || generateGreetingPrompt();
|
const greetingPrompt = config.greeting_custom_prompt?.trim() || generateGreetingPrompt();
|
||||||
@@ -82,12 +81,10 @@ async function sendGreeting(conversationId: string): Promise<boolean> {
|
|||||||
conversationId,
|
conversationId,
|
||||||
message: greetingPrompt,
|
message: greetingPrompt,
|
||||||
});
|
});
|
||||||
return true;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to send greeting:", error);
|
console.error("Failed to send greeting:", error);
|
||||||
claudeStore.addLineToConversation(conversationId, "error", `Failed to send greeting: ${error}`);
|
claudeStore.addLineToConversation(conversationId, "error", `Failed to send greeting: ${error}`);
|
||||||
characterState.setTemporaryState("error", 3000);
|
characterState.setTemporaryState("error", 3000);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +118,6 @@ interface WorkingDirectoryPayload {
|
|||||||
|
|
||||||
export async function cleanupConversationTracking(conversationId: string) {
|
export async function cleanupConversationTracking(conversationId: string) {
|
||||||
connectedConversations.delete(conversationId);
|
connectedConversations.delete(conversationId);
|
||||||
greetingPendingConversations.delete(conversationId);
|
|
||||||
|
|
||||||
// Clean up any temp files associated with this conversation
|
// Clean up any temp files associated with this conversation
|
||||||
try {
|
try {
|
||||||
@@ -177,24 +173,7 @@ export async function initializeTauriListeners() {
|
|||||||
if (!connectedConversations.has(targetConversationId)) {
|
if (!connectedConversations.has(targetConversationId)) {
|
||||||
connectedConversations.add(targetConversationId);
|
connectedConversations.add(targetConversationId);
|
||||||
resetSessionStats(); // Reset session stats on new connection
|
resetSessionStats(); // Reset session stats on new connection
|
||||||
|
await sendGreeting(targetConversationId);
|
||||||
// Immediately hold the tab at yellow while we wait for the greeting response.
|
|
||||||
// This avoids a brief green flash before the greeting is even sent.
|
|
||||||
greetingPendingConversations.add(targetConversationId);
|
|
||||||
claudeStore.setConnectionStatusForConversation(
|
|
||||||
targetConversationId,
|
|
||||||
"connecting" as ConnectionStatus
|
|
||||||
);
|
|
||||||
|
|
||||||
const greetingSent = await sendGreeting(targetConversationId);
|
|
||||||
if (!greetingSent) {
|
|
||||||
// Greeting was disabled or failed — flip straight to connected.
|
|
||||||
greetingPendingConversations.delete(targetConversationId);
|
|
||||||
claudeStore.setConnectionStatusForConversation(
|
|
||||||
targetConversationId,
|
|
||||||
"connected" as ConnectionStatus
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (status === "disconnected") {
|
} else if (status === "disconnected") {
|
||||||
@@ -204,15 +183,11 @@ export async function initializeTauriListeners() {
|
|||||||
// (permission prompts trigger reconnects and agents may complete before reconnect)
|
// (permission prompts trigger reconnects and agents may complete before reconnect)
|
||||||
if (!skipNextGreeting && targetConversationId) {
|
if (!skipNextGreeting && targetConversationId) {
|
||||||
agentStore.markAllErrored(targetConversationId);
|
agentStore.markAllErrored(targetConversationId);
|
||||||
// Clear the conversation's agents from the store on real disconnect
|
|
||||||
// This prevents agents from persisting across sessions
|
|
||||||
agentStore.clearConversation(targetConversationId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only remove from connected set if we're not about to reconnect
|
// Only remove from connected set if we're not about to reconnect
|
||||||
if (!skipNextGreeting && targetConversationId) {
|
if (!skipNextGreeting && targetConversationId) {
|
||||||
connectedConversations.delete(targetConversationId);
|
connectedConversations.delete(targetConversationId);
|
||||||
greetingPendingConversations.delete(targetConversationId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't add system message if we're about to reconnect
|
// Don't add system message if we're about to reconnect
|
||||||
@@ -227,14 +202,6 @@ export async function initializeTauriListeners() {
|
|||||||
todos.clear();
|
todos.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the tab's connection status on real disconnects
|
|
||||||
if (!skipNextGreeting && targetConversationId) {
|
|
||||||
claudeStore.setConnectionStatusForConversation(
|
|
||||||
targetConversationId,
|
|
||||||
"disconnected" as ConnectionStatus
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update character state for this conversation
|
// Update character state for this conversation
|
||||||
if (targetConversationId) {
|
if (targetConversationId) {
|
||||||
claudeStore.setCharacterStateForConversation(targetConversationId, "idle");
|
claudeStore.setCharacterStateForConversation(targetConversationId, "idle");
|
||||||
@@ -244,7 +211,6 @@ export async function initializeTauriListeners() {
|
|||||||
|
|
||||||
if (targetConversationId) {
|
if (targetConversationId) {
|
||||||
connectedConversations.delete(targetConversationId);
|
connectedConversations.delete(targetConversationId);
|
||||||
greetingPendingConversations.delete(targetConversationId);
|
|
||||||
claudeStore.addLineToConversation(targetConversationId, "error", "Connection error");
|
claudeStore.addLineToConversation(targetConversationId, "error", "Connection error");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,34 +272,11 @@ export async function initializeTauriListeners() {
|
|||||||
}
|
}
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
// Flip to connected when first assistant message arrives after greeting
|
|
||||||
if (
|
|
||||||
conversation_id &&
|
|
||||||
line_type === "assistant" &&
|
|
||||||
greetingPendingConversations.has(conversation_id)
|
|
||||||
) {
|
|
||||||
greetingPendingConversations.delete(conversation_id);
|
|
||||||
claudeStore.setConnectionStatusForConversation(
|
|
||||||
conversation_id,
|
|
||||||
"connected" as ConnectionStatus
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Always store the output to the correct conversation
|
// Always store the output to the correct conversation
|
||||||
if (conversation_id) {
|
if (conversation_id) {
|
||||||
claudeStore.addLineToConversation(
|
claudeStore.addLineToConversation(
|
||||||
conversation_id,
|
conversation_id,
|
||||||
line_type as
|
line_type as "user" | "assistant" | "system" | "tool" | "error" | "thinking",
|
||||||
| "user"
|
|
||||||
| "assistant"
|
|
||||||
| "system"
|
|
||||||
| "tool"
|
|
||||||
| "error"
|
|
||||||
| "thinking"
|
|
||||||
| "rate-limit"
|
|
||||||
| "compact-prompt"
|
|
||||||
| "worktree"
|
|
||||||
| "config-change",
|
|
||||||
content,
|
content,
|
||||||
tool_name || undefined,
|
tool_name || undefined,
|
||||||
costData,
|
costData,
|
||||||
@@ -342,17 +285,7 @@ export async function initializeTauriListeners() {
|
|||||||
} else {
|
} else {
|
||||||
// Fallback to active conversation if no conversation_id provided
|
// Fallback to active conversation if no conversation_id provided
|
||||||
claudeStore.addLine(
|
claudeStore.addLine(
|
||||||
line_type as
|
line_type as "user" | "assistant" | "system" | "tool" | "error" | "thinking",
|
||||||
| "user"
|
|
||||||
| "assistant"
|
|
||||||
| "system"
|
|
||||||
| "tool"
|
|
||||||
| "error"
|
|
||||||
| "thinking"
|
|
||||||
| "rate-limit"
|
|
||||||
| "compact-prompt"
|
|
||||||
| "worktree"
|
|
||||||
| "config-change",
|
|
||||||
content,
|
content,
|
||||||
tool_name || undefined,
|
tool_name || undefined,
|
||||||
costData,
|
costData,
|
||||||
@@ -474,17 +407,10 @@ export async function initializeTauriListeners() {
|
|||||||
unlisteners.push(agentUpdateUnlisten);
|
unlisteners.push(agentUpdateUnlisten);
|
||||||
|
|
||||||
const agentEndUnlisten = await listen<AgentEndPayload>("claude:agent-end", (event) => {
|
const agentEndUnlisten = await listen<AgentEndPayload>("claude:agent-end", (event) => {
|
||||||
const { tool_use_id, ended_at, is_error, conversation_id, last_assistant_message } =
|
const { tool_use_id, ended_at, is_error, conversation_id } = event.payload;
|
||||||
event.payload;
|
|
||||||
const targetConversationId = conversation_id || get(claudeStore.activeConversationId);
|
const targetConversationId = conversation_id || get(claudeStore.activeConversationId);
|
||||||
if (targetConversationId) {
|
if (targetConversationId) {
|
||||||
agentStore.endAgent(
|
agentStore.endAgent(targetConversationId, tool_use_id, ended_at, is_error);
|
||||||
targetConversationId,
|
|
||||||
tool_use_id,
|
|
||||||
ended_at,
|
|
||||||
is_error,
|
|
||||||
last_assistant_message
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
unlisteners.push(agentEndUnlisten);
|
unlisteners.push(agentEndUnlisten);
|
||||||
@@ -540,6 +466,7 @@ export async function initializeDiscordRpc() {
|
|||||||
|
|
||||||
console.log("Discord RPC initialized successfully with initial presence");
|
console.log("Discord RPC initialized successfully with initial presence");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||||
console.error("Failed to initialize Discord RPC:", error);
|
console.error("Failed to initialize Discord RPC:", error);
|
||||||
console.warn("Discord RPC will be unavailable. Make sure Discord is running.");
|
console.warn("Discord RPC will be unavailable. Make sure Discord is running.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,6 @@ export interface AgentInfo {
|
|||||||
status: AgentStatus;
|
status: AgentStatus;
|
||||||
parentToolUseId?: string;
|
parentToolUseId?: string;
|
||||||
durationMs?: number;
|
durationMs?: number;
|
||||||
characterName: string;
|
|
||||||
characterAvatar: string;
|
|
||||||
lastAssistantMessage?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AgentStartPayload {
|
export interface AgentStartPayload {
|
||||||
@@ -32,5 +29,4 @@ export interface AgentEndPayload {
|
|||||||
conversation_id?: string;
|
conversation_id?: string;
|
||||||
duration_ms?: number;
|
duration_ms?: number;
|
||||||
num_turns?: number;
|
num_turns?: number;
|
||||||
last_assistant_message?: string;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,6 @@
|
|||||||
export interface TerminalLine {
|
export interface TerminalLine {
|
||||||
id: string;
|
id: string;
|
||||||
type:
|
type: "user" | "assistant" | "system" | "tool" | "error" | "thinking";
|
||||||
| "user"
|
|
||||||
| "assistant"
|
|
||||||
| "system"
|
|
||||||
| "tool"
|
|
||||||
| "error"
|
|
||||||
| "thinking"
|
|
||||||
| "rate-limit"
|
|
||||||
| "compact-prompt"
|
|
||||||
| "worktree"
|
|
||||||
| "config-change";
|
|
||||||
content: string;
|
content: string;
|
||||||
timestamp: Date;
|
timestamp: Date;
|
||||||
toolName?: string;
|
toolName?: string;
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
import { describe, it, expect } from "vitest";
|
|
||||||
import { CHARACTER_POOL, assignCharacter } from "./agentCharacters";
|
|
||||||
|
|
||||||
describe("agentCharacters", () => {
|
|
||||||
describe("CHARACTER_POOL", () => {
|
|
||||||
it("contains exactly 6 characters", () => {
|
|
||||||
expect(CHARACTER_POOL).toHaveLength(6);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("each character has a name, avatar, title, and description", () => {
|
|
||||||
for (const character of CHARACTER_POOL) {
|
|
||||||
expect(character.name).toBeTruthy();
|
|
||||||
expect(character.avatar).toBeTruthy();
|
|
||||||
expect(character.avatar).toMatch(/^https:\/\//u);
|
|
||||||
expect(character.title).toBeTruthy();
|
|
||||||
expect(character.description).toBeTruthy();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it("all names are unique", () => {
|
|
||||||
const names = CHARACTER_POOL.map((c) => c.name);
|
|
||||||
const uniqueNames = new Set(names);
|
|
||||||
expect(uniqueNames.size).toBe(CHARACTER_POOL.length);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("assignCharacter", () => {
|
|
||||||
it("returns a character from the pool", () => {
|
|
||||||
const character = assignCharacter([]);
|
|
||||||
const names = CHARACTER_POOL.map((c) => c.name);
|
|
||||||
expect(names).toContain(character.name);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("avoids names already in use when possible", () => {
|
|
||||||
const takenNames = ["Amari", "Keiko", "Minori", "Reina", "Tatsumi"];
|
|
||||||
// Run many times to confirm we never get a taken name
|
|
||||||
for (let i = 0; i < 50; i++) {
|
|
||||||
const character = assignCharacter(takenNames);
|
|
||||||
expect(takenNames).not.toContain(character.name);
|
|
||||||
expect(character.name).toBe("Yumiko");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it("picks from the full pool when all 6 names are taken", () => {
|
|
||||||
const allNames = CHARACTER_POOL.map((c) => c.name);
|
|
||||||
const seen = new Set<string>();
|
|
||||||
// Run enough times that we'd statistically see variety
|
|
||||||
for (let i = 0; i < 100; i++) {
|
|
||||||
const character = assignCharacter(allNames);
|
|
||||||
seen.add(character.name);
|
|
||||||
}
|
|
||||||
// Should still pick valid characters
|
|
||||||
for (const name of seen) {
|
|
||||||
expect(allNames).toContain(name);
|
|
||||||
}
|
|
||||||
// With 100 runs and 6 characters, we should see at least 2 distinct names
|
|
||||||
expect(seen.size).toBeGreaterThan(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns a character with name, avatar, title, and description", () => {
|
|
||||||
const character = assignCharacter([]);
|
|
||||||
expect(character.name).toBeTruthy();
|
|
||||||
expect(character.avatar).toBeTruthy();
|
|
||||||
expect(character.title).toBeTruthy();
|
|
||||||
expect(character.description).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("works when the active list is empty", () => {
|
|
||||||
const character = assignCharacter([]);
|
|
||||||
expect(character).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
export interface AgentCharacter {
|
|
||||||
name: string;
|
|
||||||
avatar: string;
|
|
||||||
title: string;
|
|
||||||
description: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const CHARACTER_POOL: readonly AgentCharacter[] = [
|
|
||||||
{
|
|
||||||
name: "Amari",
|
|
||||||
avatar: "https://cdn.nhcarrigan.com/amari.png",
|
|
||||||
title: "Executive Assistant",
|
|
||||||
description:
|
|
||||||
"Fey-blooded PA and healer of the team. She always knows when you need a break — and makes sure you take one.",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Keiko",
|
|
||||||
avatar: "https://cdn.nhcarrigan.com/keiko.png",
|
|
||||||
title: "Chief Security Officer",
|
|
||||||
description:
|
|
||||||
"Bodyguard and shadow of the family. Conceals blades beneath evening gowns; always watching from the dark.",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Minori",
|
|
||||||
avatar: "https://cdn.nhcarrigan.com/minori.png",
|
|
||||||
title: "Chief Compliance Officer",
|
|
||||||
description:
|
|
||||||
"An ancient Automaton built to guard the Great Library. Perfect memory, perfect logic, perfect dedication.",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Reina",
|
|
||||||
avatar: "https://cdn.nhcarrigan.com/reina.png",
|
|
||||||
title: "Chief Legal Officer",
|
|
||||||
description:
|
|
||||||
"Demon of the Crossroads turned corporate lawyer. Her binding contracts have held for millennia.",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Tatsumi",
|
|
||||||
avatar: "https://cdn.nhcarrigan.com/tatsumi.png",
|
|
||||||
title: "Chief Design Officer",
|
|
||||||
description:
|
|
||||||
"A Siren who traded the ocean for a stylus. Uses her glamour to make every interface welcoming and beautiful.",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Yumiko",
|
|
||||||
avatar: "https://cdn.nhcarrigan.com/yumiko.png",
|
|
||||||
title: "Chief Technology Officer",
|
|
||||||
description:
|
|
||||||
"Technomancer and machine whisperer. She communes with machine spirits and keeps the digital world running.",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Picks a character for a new subagent.
|
|
||||||
* Avoids names already assigned to active agents unless all six are taken.
|
|
||||||
*/
|
|
||||||
export function assignCharacter(activeNames: readonly string[]): AgentCharacter {
|
|
||||||
const available = CHARACTER_POOL.filter((c) => !activeNames.includes(c.name));
|
|
||||||
const pool = available.length > 0 ? available : [...CHARACTER_POOL];
|
|
||||||
return pool[Math.floor(Math.random() * pool.length)];
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user