feat: initial prototype
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 47s

This commit is contained in:
2026-01-14 20:56:28 -08:00
parent daf1bfecb8
commit f393dfb359
68 changed files with 9391 additions and 12 deletions
+7
View File
@@ -0,0 +1,7 @@
# Generated by Cargo
# will have compiled files and executables
/target/
# Generated by Tauri
# will have schema files for capabilities auto-completion
/gen/schemas
+5303
View File
File diff suppressed because it is too large Load Diff
+25
View File
@@ -0,0 +1,25 @@
[package]
name = "hikari-desktop"
version = "0.1.0"
description = "Hikari - Claude Code Visual Assistant"
authors = ["Naomi Carrigan"]
edition = "2021"
[lib]
name = "hikari_desktop_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2", features = [] }
[dependencies]
tauri = { version = "2", features = [] }
tauri-plugin-dialog = "2"
tauri-plugin-opener = "2"
tauri-plugin-shell = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["full"] }
parking_lot = "0.12"
uuid = { version = "1", features = ["v4"] }
+3
View File
@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}
+14
View File
@@ -0,0 +1,14 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"core:default",
"dialog:default",
"opener:default",
"shell:allow-spawn",
"shell:allow-stdin-write",
"shell:allow-kill"
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

+44
View File
@@ -0,0 +1,44 @@
use tauri::{AppHandle, State};
use crate::wsl_bridge::SharedBridge;
#[tauri::command]
pub async fn start_claude(
app: AppHandle,
bridge: State<'_, SharedBridge>,
working_dir: String,
allowed_tools: Option<Vec<String>>,
) -> Result<(), String> {
let mut bridge = bridge.lock();
bridge.start(app, &working_dir, allowed_tools.unwrap_or_default())
}
#[tauri::command]
pub async fn stop_claude(app: AppHandle, bridge: State<'_, SharedBridge>) -> Result<(), String> {
let mut bridge = bridge.lock();
bridge.stop(&app);
Ok(())
}
#[tauri::command]
pub async fn send_prompt(bridge: State<'_, SharedBridge>, message: String) -> Result<(), String> {
let mut bridge = bridge.lock();
bridge.send_message(&message)
}
#[tauri::command]
pub async fn is_claude_running(bridge: State<'_, SharedBridge>) -> Result<bool, String> {
let bridge = bridge.lock();
Ok(bridge.is_running())
}
#[tauri::command]
pub async fn get_working_directory(bridge: State<'_, SharedBridge>) -> Result<String, String> {
let bridge = bridge.lock();
Ok(bridge.get_working_directory().to_string())
}
#[tauri::command]
pub async fn select_wsl_directory() -> Result<String, String> {
Ok("/home".to_string())
}
+27
View File
@@ -0,0 +1,27 @@
mod commands;
mod types;
mod wsl_bridge;
use commands::*;
use wsl_bridge::create_shared_bridge;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
let bridge = create_shared_bridge();
tauri::Builder::default()
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_shell::init())
.manage(bridge)
.invoke_handler(tauri::generate_handler![
start_claude,
stop_claude,
send_prompt,
is_claude_running,
get_working_directory,
select_wsl_directory,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
+6
View File
@@ -0,0 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
hikari_desktop_lib::run()
}
+188
View File
@@ -0,0 +1,188 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum CharacterState {
Idle,
Thinking,
Typing,
Searching,
Coding,
Mcp,
Permission,
Success,
Error,
}
impl Default for CharacterState {
fn default() -> Self {
CharacterState::Idle
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ConnectionStatus {
Disconnected,
Connecting,
Connected,
Error,
}
impl Default for ConnectionStatus {
fn default() -> Self {
ConnectionStatus::Disconnected
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TerminalLine {
pub id: String,
#[serde(rename = "type")]
pub line_type: String,
pub content: String,
pub timestamp: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub tool_name: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PermissionRequest {
pub id: String,
pub tool: String,
pub description: String,
pub input: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PermissionDenial {
pub tool_name: String,
pub tool_use_id: String,
pub tool_input: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum ClaudeMessage {
#[serde(rename = "system")]
System {
subtype: String,
#[serde(default)]
session_id: Option<String>,
#[serde(default)]
cwd: Option<String>,
#[serde(default)]
tools: Option<Vec<String>>,
},
#[serde(rename = "assistant")]
Assistant {
message: AssistantMessageContent,
#[serde(default)]
parent_tool_use_id: Option<String>,
},
#[serde(rename = "user")]
User { message: UserMessageContent },
#[serde(rename = "stream_event")]
StreamEvent { event: StreamEventData },
#[serde(rename = "result")]
Result {
subtype: String,
#[serde(default)]
result: Option<String>,
#[serde(default)]
duration_ms: Option<u64>,
#[serde(default)]
num_turns: Option<u32>,
#[serde(default)]
permission_denials: Option<Vec<PermissionDenial>>,
},
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AssistantMessageContent {
pub content: Vec<ContentBlock>,
#[serde(default)]
pub model: Option<String>,
#[serde(default)]
pub stop_reason: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UserMessageContent {
pub content: Vec<ContentBlock>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum ContentBlock {
#[serde(rename = "text")]
Text { text: String },
#[serde(rename = "thinking")]
Thinking { thinking: String },
#[serde(rename = "tool_use")]
ToolUse {
id: String,
name: String,
input: serde_json::Value,
},
#[serde(rename = "tool_result")]
ToolResult {
tool_use_id: String,
content: serde_json::Value,
#[serde(default)]
is_error: Option<bool>,
},
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StreamEventData {
#[serde(rename = "type")]
pub event_type: String,
#[serde(default)]
pub index: Option<u32>,
#[serde(default)]
pub content_block: Option<ContentBlockStart>,
#[serde(default)]
pub delta: Option<DeltaContent>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContentBlockStart {
#[serde(rename = "type")]
pub block_type: String,
#[serde(default)]
pub id: Option<String>,
#[serde(default)]
pub name: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeltaContent {
#[serde(rename = "type")]
pub delta_type: String,
#[serde(default)]
pub text: Option<String>,
#[serde(default)]
pub thinking: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StateChangeEvent {
pub state: CharacterState,
pub tool_name: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OutputEvent {
pub line_type: String,
pub content: String,
pub tool_name: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PermissionPromptEvent {
pub id: String,
pub tool_name: String,
pub tool_input: serde_json::Value,
pub description: String,
}
+467
View File
@@ -0,0 +1,467 @@
use parking_lot::Mutex;
use std::io::{BufRead, BufReader, Write};
use std::process::{Child, ChildStdin, Command, Stdio};
use std::sync::Arc;
use std::thread;
use tauri::{AppHandle, Emitter};
use crate::types::{CharacterState, ClaudeMessage, ConnectionStatus, ContentBlock, StateChangeEvent, OutputEvent, PermissionPromptEvent};
const SEARCH_TOOLS: [&str; 5] = ["Read", "Glob", "Grep", "WebSearch", "WebFetch"];
const CODING_TOOLS: [&str; 3] = ["Edit", "Write", "NotebookEdit"];
fn detect_wsl() -> bool {
// Check /proc/version for WSL indicators
if let Ok(version) = std::fs::read_to_string("/proc/version") {
let version_lower = version.to_lowercase();
if version_lower.contains("microsoft") || version_lower.contains("wsl") {
return true;
}
}
// Fallback: check for WSLInterop
if std::path::Path::new("/proc/sys/fs/binfmt_misc/WSLInterop").exists() {
return true;
}
// Check for WSL environment variable
if std::env::var("WSL_DISTRO_NAME").is_ok() {
return true;
}
false
}
fn find_claude_binary() -> Option<String> {
// Check common installation locations for claude
let home = std::env::var("HOME").ok()?;
let paths_to_check = [
format!("{}/.local/bin/claude", home),
format!("{}/.claude/local/claude", home),
"/usr/local/bin/claude".to_string(),
"/usr/bin/claude".to_string(),
];
for path in &paths_to_check {
if std::path::Path::new(path).exists() {
return Some(path.clone());
}
}
// Fall back to checking PATH via which
if let Ok(output) = Command::new("which").arg("claude").output() {
if output.status.success() {
let path = String::from_utf8_lossy(&output.stdout).trim().to_string();
if !path.is_empty() {
return Some(path);
}
}
}
None
}
pub struct WslBridge {
process: Option<Child>,
stdin: Option<ChildStdin>,
working_directory: String,
session_id: Option<String>,
}
impl WslBridge {
pub fn new() -> Self {
WslBridge {
process: None,
stdin: None,
working_directory: String::new(),
session_id: None,
}
}
pub fn start(&mut self, app: AppHandle, working_dir: &str, allowed_tools: Vec<String>) -> Result<(), String> {
if self.process.is_some() {
return Err("Process already running".to_string());
}
self.working_directory = working_dir.to_string();
emit_connection_status(&app, ConnectionStatus::Connecting);
// Detect if we're running inside WSL or on Windows
let is_wsl = detect_wsl();
eprintln!("[DEBUG] is_wsl: {}", is_wsl);
eprintln!("[DEBUG] allowed_tools: {:?}", allowed_tools);
let mut command = if is_wsl {
// Running inside WSL - call claude directly
// Try to find claude in common locations since GUI apps may not inherit shell PATH
let claude_path = find_claude_binary()
.ok_or_else(|| "Could not find claude binary. Is Claude Code installed?".to_string())?;
eprintln!("[DEBUG] Found claude at: {}", claude_path);
eprintln!("[DEBUG] Working dir: {}", working_dir);
let mut cmd = Command::new(&claude_path);
cmd.args([
"--output-format", "stream-json",
"--input-format", "stream-json",
"--verbose",
]);
// Add allowed tools if any
for tool in &allowed_tools {
cmd.args(["--allowedTools", tool]);
}
cmd.current_dir(working_dir);
cmd
} else {
// Running on Windows - use wsl to call claude
eprintln!("[DEBUG] Windows path - using wsl");
let mut cmd = Command::new("wsl");
let mut args = vec![
"--cd".to_string(), working_dir.to_string(),
"--".to_string(), "claude".to_string(),
"--output-format".to_string(), "stream-json".to_string(),
"--input-format".to_string(), "stream-json".to_string(),
"--verbose".to_string(),
];
// Add allowed tools if any
for tool in &allowed_tools {
args.push("--allowedTools".to_string());
args.push(tool.clone());
}
cmd.args(&args);
cmd
};
command
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
let mut child = command.spawn().map_err(|e| {
eprintln!("[DEBUG] Spawn error: {:?}", e);
format!("Failed to spawn process: {}", e)
})?;
let stdin = child.stdin.take();
let stdout = child.stdout.take();
let stderr = child.stderr.take();
self.stdin = stdin;
self.process = Some(child);
if let Some(stdout) = stdout {
let app_clone = app.clone();
thread::spawn(move || {
handle_stdout(stdout, app_clone);
});
}
if let Some(stderr) = stderr {
let app_clone = app.clone();
thread::spawn(move || {
handle_stderr(stderr, app_clone);
});
}
emit_connection_status(&app, ConnectionStatus::Connected);
Ok(())
}
pub fn send_message(&mut self, message: &str) -> Result<(), String> {
let stdin = self.stdin.as_mut().ok_or("Process not running")?;
let input = serde_json::json!({
"type": "user",
"message": {
"role": "user",
"content": [{
"type": "text",
"text": message
}]
}
});
let json_line = serde_json::to_string(&input).map_err(|e| e.to_string())?;
stdin
.write_all(format!("{}\n", json_line).as_bytes())
.map_err(|e| format!("Failed to write to stdin: {}", e))?;
stdin.flush().map_err(|e| format!("Failed to flush stdin: {}", e))?;
Ok(())
}
pub fn stop(&mut self, app: &AppHandle) {
if let Some(mut process) = self.process.take() {
let _ = process.kill();
let _ = process.wait();
}
self.stdin = None;
self.session_id = None;
emit_connection_status(app, ConnectionStatus::Disconnected);
}
pub fn is_running(&self) -> bool {
self.process.is_some()
}
pub fn get_working_directory(&self) -> &str {
&self.working_directory
}
}
impl Default for WslBridge {
fn default() -> Self {
Self::new()
}
}
fn handle_stdout(stdout: std::process::ChildStdout, app: AppHandle) {
let reader = BufReader::new(stdout);
for line in reader.lines() {
match line {
Ok(line) if !line.is_empty() => {
if let Err(e) = process_json_line(&line, &app) {
eprintln!("Error processing line: {}", e);
}
}
Err(e) => {
eprintln!("Error reading stdout: {}", e);
break;
}
_ => {}
}
}
emit_connection_status(&app, ConnectionStatus::Disconnected);
}
fn handle_stderr(stderr: std::process::ChildStderr, app: AppHandle) {
let reader = BufReader::new(stderr);
for line in reader.lines() {
match line {
Ok(line) if !line.is_empty() => {
let _ = app.emit("claude:output", OutputEvent {
line_type: "error".to_string(),
content: line,
tool_name: None,
});
}
Err(_) => break,
_ => {}
}
}
}
fn process_json_line(line: &str, app: &AppHandle) -> Result<(), String> {
let message: ClaudeMessage = serde_json::from_str(line)
.map_err(|e| format!("Failed to parse JSON: {} - Line: {}", e, line))?;
match &message {
ClaudeMessage::System { subtype, session_id, cwd, .. } => {
if subtype == "init" {
if let Some(id) = session_id {
let _ = app.emit("claude:session", id.clone());
}
if let Some(dir) = cwd {
let _ = app.emit("claude:cwd", dir.clone());
}
emit_state_change(app, CharacterState::Idle, None);
}
}
ClaudeMessage::Assistant { message, .. } => {
let mut state = CharacterState::Typing;
let mut tool_name = None;
for block in &message.content {
match block {
ContentBlock::ToolUse { name, input, .. } => {
tool_name = Some(name.clone());
state = get_tool_state(name);
let desc = format_tool_description(name, input);
let _ = app.emit("claude:output", OutputEvent {
line_type: "tool".to_string(),
content: desc,
tool_name: Some(name.clone()),
});
}
ContentBlock::Text { text } => {
let _ = app.emit("claude:output", OutputEvent {
line_type: "assistant".to_string(),
content: text.clone(),
tool_name: None,
});
}
ContentBlock::Thinking { thinking } => {
state = CharacterState::Thinking;
let _ = app.emit("claude:output", OutputEvent {
line_type: "system".to_string(),
content: format!("[Thinking] {}", thinking),
tool_name: None,
});
}
_ => {}
}
}
emit_state_change(app, state, tool_name);
}
ClaudeMessage::StreamEvent { event } => {
if event.event_type == "content_block_start" {
if let Some(block) = &event.content_block {
let state = match block.block_type.as_str() {
"thinking" => CharacterState::Thinking,
"text" => CharacterState::Typing,
"tool_use" => {
if let Some(name) = &block.name {
get_tool_state(name)
} else {
CharacterState::Typing
}
}
_ => CharacterState::Typing,
};
emit_state_change(app, state, block.name.clone());
}
} else if event.event_type == "content_block_delta" {
if let Some(delta) = &event.delta {
if let Some(text) = &delta.text {
let _ = app.emit("claude:stream", text.clone());
}
}
}
}
ClaudeMessage::Result { subtype, result, permission_denials, .. } => {
let state = if subtype == "success" {
CharacterState::Success
} else {
CharacterState::Error
};
// Only emit error results - success content is already sent via Assistant message
if subtype != "success" {
if let Some(text) = result {
let _ = app.emit("claude:output", OutputEvent {
line_type: "error".to_string(),
content: text.clone(),
tool_name: None,
});
}
}
// Check for permission denials and emit prompts for each
if let Some(denials) = permission_denials {
for denial in denials {
let description = format_tool_description(&denial.tool_name, &denial.tool_input);
let _ = app.emit("claude:permission", PermissionPromptEvent {
id: denial.tool_use_id.clone(),
tool_name: denial.tool_name.clone(),
tool_input: denial.tool_input.clone(),
description,
});
}
// Show permission state if there were denials
if !denials.is_empty() {
emit_state_change(app, CharacterState::Permission, None);
return Ok(());
}
}
emit_state_change(app, state, None);
}
ClaudeMessage::User { .. } => {
emit_state_change(app, CharacterState::Thinking, None);
}
}
Ok(())
}
fn get_tool_state(tool_name: &str) -> CharacterState {
if SEARCH_TOOLS.contains(&tool_name) {
CharacterState::Searching
} else if CODING_TOOLS.contains(&tool_name) {
CharacterState::Coding
} else if tool_name.starts_with("mcp__") {
CharacterState::Mcp
} else if tool_name == "Task" {
CharacterState::Thinking
} else {
CharacterState::Typing
}
}
fn format_tool_description(name: &str, input: &serde_json::Value) -> String {
match name {
"Read" => {
if let Some(path) = input.get("file_path").and_then(|v| v.as_str()) {
format!("Reading file: {}", path)
} else {
"Reading file...".to_string()
}
}
"Glob" => {
if let Some(pattern) = input.get("pattern").and_then(|v| v.as_str()) {
format!("Searching for files: {}", pattern)
} else {
"Searching for files...".to_string()
}
}
"Grep" => {
if let Some(pattern) = input.get("pattern").and_then(|v| v.as_str()) {
format!("Searching for: {}", pattern)
} else {
"Searching in files...".to_string()
}
}
"Edit" | "Write" => {
if let Some(path) = input.get("file_path").and_then(|v| v.as_str()) {
format!("Editing: {}", path)
} else {
"Editing file...".to_string()
}
}
"Bash" => {
if let Some(cmd) = input.get("command").and_then(|v| v.as_str()) {
let truncated = if cmd.len() > 50 {
format!("{}...", &cmd[..50])
} else {
cmd.to_string()
};
format!("Running: {}", truncated)
} else {
"Running command...".to_string()
}
}
_ => format!("Using tool: {}", name),
}
}
fn emit_state_change(app: &AppHandle, state: CharacterState, tool_name: Option<String>) {
let _ = app.emit("claude:state", StateChangeEvent { state, tool_name });
}
fn emit_connection_status(app: &AppHandle, status: ConnectionStatus) {
let _ = app.emit("claude:connection", status);
}
pub type SharedBridge = Arc<Mutex<WslBridge>>;
pub fn create_shared_bridge() -> SharedBridge {
Arc::new(Mutex::new(WslBridge::new()))
}
+38
View File
@@ -0,0 +1,38 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "hikari-desktop",
"version": "0.1.0",
"identifier": "com.naomi.hikari-desktop",
"build": {
"beforeDevCommand": "pnpm dev",
"devUrl": "http://localhost:1420",
"beforeBuildCommand": "pnpm build",
"frontendDist": "../build"
},
"app": {
"windows": [
{
"title": "Hikari - Claude Code Assistant",
"width": 1200,
"height": 800,
"minWidth": 800,
"minHeight": 600,
"center": true
}
],
"security": {
"csp": null
}
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
}
}