Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

gui: 0.0.12 — codegraff <path> opens that folder in the app (code-style) (#24)

Rachd74a439bc7da
diff --git a/gui/package.json b/gui/package.json
index 768d36f2..f43e6e57 100644
--- a/gui/package.json
+++ b/gui/package.json
@@ -1,7 +1,7 @@
{
"name": "codegraff-gui",
"private": true,
- "version": "0.0.11",
+ "version": "0.0.12",
"license": "Apache-2.0",
"packageManager": "[email protected]",
"type": "module",
diff --git a/gui/src-tauri/Cargo.lock b/gui/src-tauri/Cargo.lock
index 011757d8..ae34713c 100644
--- a/gui/src-tauri/Cargo.lock
+++ b/gui/src-tauri/Cargo.lock
@@ -81,6 +81,126 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
+[[package]]
+name = "async-broadcast"
+version = "0.7.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532"
+dependencies = [
+ "event-listener",
+ "event-listener-strategy",
+ "futures-core",
+ "pin-project-lite",
+]
+
+[[package]]
+name = "async-channel"
+version = "2.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "924ed96dd52d1b75e9c1a3e6275715fd320f5f9439fb5a4a11fa51f4221158d2"
+dependencies = [
+ "concurrent-queue",
+ "event-listener-strategy",
+ "futures-core",
+ "pin-project-lite",
+]
+
+[[package]]
+name = "async-executor"
+version = "1.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c96bf972d85afc50bf5ab8fe2d54d1586b4e0b46c97c50a0c9e71e2f7bcd812a"
+dependencies = [
+ "async-task",
+ "concurrent-queue",
+ "fastrand",
+ "futures-lite",
+ "pin-project-lite",
+ "slab",
+]
+
+[[package]]
+name = "async-io"
+version = "2.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc"
+dependencies = [
+ "autocfg",
+ "cfg-if",
+ "concurrent-queue",
+ "futures-io",
+ "futures-lite",
+ "parking",
+ "polling",
+ "rustix",
+ "slab",
+ "windows-sys 0.61.2",
+]
+
+[[package]]
+name = "async-lock"
+version = "3.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "290f7f2596bd5b78a9fec8088ccd89180d7f9f55b94b0576823bbbdc72ee8311"
+dependencies = [
+ "event-listener",
+ "event-listener-strategy",
+ "pin-project-lite",
+]
+
+[[package]]
+name = "async-process"
+version = "2.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fc50921ec0055cdd8a16de48773bfeec5c972598674347252c0399676be7da75"
+dependencies = [
+ "async-channel",
+ "async-io",
+ "async-lock",
+ "async-signal",
+ "async-task",
+ "blocking",
+ "cfg-if",
+ "event-listener",
+ "futures-lite",
+ "rustix",
+]
+
+[[package]]
+name = "async-recursion"
+version = "1.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.117",
+]
+
+[[package]]
+name = "async-signal"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "52b5aaafa020cf5053a01f2a60e8ff5dccf550f0f77ec54a4e47285ac2bab485"
+dependencies = [
+ "async-io",
+ "async-lock",
+ "atomic-waker",
+ "cfg-if",
+ "futures-core",
+ "futures-io",
+ "rustix",
+ "signal-hook-registry",
+ "slab",
+ "windows-sys 0.61.2",
+]
+
+[[package]]
+name = "async-task"
+version = "4.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de"
+
[[package]]
name = "async-trait"
version = "0.1.89"
@@ -242,6 +362,19 @@ dependencies = [
"objc2",
]
+[[package]]
+name = "blocking"
+version = "1.6.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e83f8d02be6967315521be875afa792a316e28d57b5a2d401897e2a7921b7f21"
+dependencies = [
+ "async-channel",
+ "async-task",
+ "futures-io",
+ "futures-lite",
+ "piper",
+]
+
[[package]]
name = "borsh"
version = "1.6.1"
@@ -501,7 +634,7 @@ dependencies = [
[[package]]
name = "codegraff-gui"
-version = "0.0.11"
+version = "0.0.12"
dependencies = [
"anyhow",
"async-trait",
@@ -524,6 +657,7 @@ dependencies = [
"tauri-build",
"tauri-plugin-dialog",
"tauri-plugin-log",
+ "tauri-plugin-single-instance",
"tokio",
"tonic",
"ts-rs",
@@ -548,6 +682,15 @@ dependencies = [
"memchr",
]
+[[package]]
+name = "concurrent-queue"
+version = "2.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973"
+dependencies = [
+ "crossbeam-utils",
+]
+
[[package]]
name = "convert_case"
version = "0.4.0"
@@ -1052,6 +1195,12 @@ version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ef6b89e5b37196644d8796de5268852ff179b44e96276cf4290264843743bb7"
+[[package]]
+name = "endi"
+version = "1.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "66b7e2430c6dff6a955451e2cfc438f09cea1965a9d6f87f7e3b90decc014099"
+
[[package]]
name = "enum-as-inner"
version = "0.6.1"
@@ -1064,6 +1213,27 @@ dependencies = [
"syn 2.0.117",
]
+[[package]]
+name = "enumflags2"
+version = "0.7.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1027f7680c853e056ebcec683615fb6fbbc07dbaa13b4d5d9442b146ded4ecef"
+dependencies = [
+ "enumflags2_derive",
+ "serde",
+]
+
+[[package]]
+name = "enumflags2_derive"
+version = "0.7.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "67c78a4d8fdf9953a5c9d458f9efe940fd97a0cab0941c075a813ac594733827"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.117",
+]
+
[[package]]
name = "env_filter"
version = "0.1.4"
@@ -1101,6 +1271,27 @@ dependencies = [
"windows-sys 0.61.2",
]
+[[package]]
+name = "event-listener"
+version = "5.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab"
+dependencies = [
+ "concurrent-queue",
+ "parking",
+ "pin-project-lite",
+]
+
+[[package]]
+name = "event-listener-strategy"
+version = "0.5.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93"
+dependencies = [
+ "event-listener",
+ "pin-project-lite",
+]
+
[[package]]
name = "fastrand"
version = "2.4.1"
@@ -1280,6 +1471,19 @@ version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718"
+[[package]]
+name = "futures-lite"
+version = "2.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad"
+dependencies = [
+ "fastrand",
+ "futures-core",
+ "futures-io",
+ "parking",
+ "pin-project-lite",
+]
+
[[package]]
name = "futures-macro"
version = "0.3.32"
@@ -1711,6 +1915,12 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
+[[package]]
+name = "hermit-abi"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
+
[[package]]
name = "hex"
version = "0.4.3"
@@ -2343,6 +2553,12 @@ dependencies = [
"vcpkg",
]
+[[package]]
+name = "linux-raw-sys"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
+
[[package]]
name = "litemap"
version = "0.8.2"
@@ -2757,6 +2973,16 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
+[[package]]
+name = "ordered-stream"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9aa2b01e1d916879f73a53d01d1d6cee68adbb31d6d9177a8cfce093cced1d50"
+dependencies = [
+ "futures-core",
+ "pin-project-lite",
+]
+
[[package]]
name = "pango"
version = "0.18.3"
@@ -2782,6 +3008,12 @@ dependencies = [
"system-deps",
]
+[[package]]
+name = "parking"
+version = "2.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba"
+
[[package]]
name = "parking_lot"
version = "0.12.5"
@@ -3024,6 +3256,17 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
+[[package]]
+name = "piper"
+version = "0.2.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c835479a4443ded371d6c535cbfd8d31ad92c5d23ae9770a61bc155e4992a3c1"
+dependencies = [
+ "atomic-waker",
+ "fastrand",
+ "futures-io",
+]
+
[[package]]
name = "pkg-config"
version = "0.3.33"
@@ -3069,6 +3312,20 @@ dependencies = [
"miniz_oxide",
]
+[[package]]
+name = "polling"
+version = "3.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218"
+dependencies = [
+ "cfg-if",
+ "concurrent-queue",
+ "hermit-abi",
+ "pin-project-lite",
+ "rustix",
+ "windows-sys 0.61.2",
+]
+
[[package]]
name = "portable-atomic"
version = "1.13.1"
@@ -3727,6 +3984,19 @@ dependencies = [
"semver",
]
+[[package]]
+name = "rustix"
+version = "1.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190"
+dependencies = [
+ "bitflags 2.11.1",
+ "errno",
+ "libc",
+ "linux-raw-sys",
+ "windows-sys 0.61.2",
+]
+
[[package]]
name = "rustls"
version = "0.23.38"
@@ -4637,6 +4907,21 @@ dependencies = [
"time",
]
+[[package]]
+name = "tauri-plugin-single-instance"
+version = "2.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c8f29386f5e9fdc699182388a33ee80a56de436d91b67459e86afef426282af"
+dependencies = [
+ "serde",
+ "serde_json",
+ "tauri",
+ "thiserror 2.0.18",
+ "tracing",
+ "windows-sys 0.60.2",
+ "zbus",
+]
+
[[package]]
name = "tauri-runtime"
version = "2.10.1"
@@ -4737,6 +5022,19 @@ dependencies = [
"toml 0.9.12+spec-1.1.0",
]
+[[package]]
+name = "tempfile"
+version = "3.27.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
+dependencies = [
+ "fastrand",
+ "getrandom 0.4.2",
+ "once_cell",
+ "rustix",
+ "windows-sys 0.61.2",
+]
+
[[package]]
name = "tendril"
version = "0.4.3"
@@ -5204,6 +5502,17 @@ version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
+[[package]]
+name = "uds_windows"
+version = "1.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2f6fb2847f6742cd76af783a2a2c49e9375d0a111c7bef6f71cd9e738c72d6e"
+dependencies = [
+ "memoffset",
+ "tempfile",
+ "windows-sys 0.61.2",
+]
+
[[package]]
name = "unic-char-property"
version = "0.9.0"
@@ -6343,6 +6652,67 @@ dependencies = [
"synstructure",
]
+[[package]]
+name = "zbus"
+version = "5.16.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eee682d202a77e4a9f3b2c2bdf48a7b28af5c08c34ddf66f98c93e5e39464285"
+dependencies = [
+ "async-broadcast",
+ "async-executor",
+ "async-io",
+ "async-lock",
+ "async-process",
+ "async-recursion",
+ "async-task",
+ "async-trait",
+ "blocking",
+ "enumflags2",
+ "event-listener",
+ "futures-core",
+ "futures-lite",
+ "hex",
+ "libc",
+ "ordered-stream",
+ "rustix",
+ "serde",
+ "serde_repr",
+ "tracing",
+ "uds_windows",
+ "uuid",
+ "windows-sys 0.61.2",
+ "winnow 1.0.1",
+ "zbus_macros",
+ "zbus_names",
+ "zvariant",
+]
+
+[[package]]
+name = "zbus_macros"
+version = "5.16.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "adf1bd45a81a103745b1757754762a26e8cd01e4532e4d6c8ec431624b80d1d6"
+dependencies = [
+ "proc-macro-crate 3.5.0",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.117",
+ "zbus_names",
+ "zvariant",
+ "zvariant_utils",
+]
+
+[[package]]
+name = "zbus_names"
+version = "4.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7074f3e50b894eac91750142016d30d0a89be8e67dbfd9704fb875825760e52d"
+dependencies = [
+ "serde",
+ "winnow 1.0.1",
+ "zvariant",
+]
+
[[package]]
name = "zerocopy"
version = "0.8.48"
@@ -6443,3 +6813,43 @@ checksum = "27bc9d5b815bc103f142aa054f561d9187d191692ec7c2d1e2b4737f8dbd7296"
dependencies = [
"zune-core",
]
+
+[[package]]
+name = "zvariant"
+version = "5.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a192a0bde63360d77a7523c833d4b4ce6070a927e2c53246e4c540b1a3e27be0"
+dependencies = [
+ "endi",
+ "enumflags2",
+ "serde",
+ "winnow 1.0.1",
+ "zvariant_derive",
+ "zvariant_utils",
+]
+
+[[package]]
+name = "zvariant_derive"
+version = "5.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "90bc6cde9c01c511074be97f7ccb6c19d0da89e3f8662e812e999dcfd4638737"
+dependencies = [
+ "proc-macro-crate 3.5.0",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.117",
+ "zvariant_utils",
+]
+
+[[package]]
+name = "zvariant_utils"
+version = "3.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e8535915cfa75547e559d8c68e8139909a4aeee076831e4ef7fc59d8172c4d6"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "serde",
+ "syn 2.0.117",
+ "winnow 1.0.1",
+]
diff --git a/gui/src-tauri/Cargo.toml b/gui/src-tauri/Cargo.toml
index 1558f0c5..3600006a 100644
--- a/gui/src-tauri/Cargo.toml
+++ b/gui/src-tauri/Cargo.toml
@@ -6,7 +6,7 @@
[package]
name = "codegraff-gui"
-version = "0.0.11"
+version = "0.0.12"
description = "Desktop coding agent interface powered by Codegraff"
authors = ["Codegraff contributors"]
license = "Apache-2.0"
@@ -38,6 +38,7 @@ roxmltree = "0.20"
similar = "3.1.0"
tauri = { version = "2.10.3", features = ["macos-private-api"] }
tauri-plugin-dialog = "2"
+tauri-plugin-single-instance = "2"
tauri-plugin-log = "2"
tokio = { version = "1.51.0", features = ["io-util", "macros", "net", "process", "rt-multi-thread", "sync", "time"] }
tonic = { version = "0.14.5", features = ["tls-webpki-roots"] }
diff --git a/gui/src-tauri/src/cli_install.rs b/gui/src-tauri/src/cli_install.rs
index 2da04c0e..b7b38363 100644
--- a/gui/src-tauri/src/cli_install.rs
+++ b/gui/src-tauri/src/cli_install.rs
@@ -1,32 +1,50 @@
-//! First-run install of the bundled `codegraff` CLI onto the user's PATH.
+//! First-run install of the `codegraff` launcher command (VS Code `code`-style).
//!
-//! The app bundles the Zig-native harness binary at
-//! `Codegraff.app/Contents/Resources/codegraff`. On macOS we expose it as a
-//! `codegraff` terminal command by symlinking it into a PATH directory the
-//! first time the app launches (VS Code `code`-style).
+//! Writes a small shell script onto the user's PATH so `codegraff <path>` opens
+//! that folder in the Codegraff desktop app, and bare `codegraff` opens the app.
+//! The script launches this app's own binary detached; the single-instance
+//! plugin forwards the path to an already-running window (see `lib.rs`).
//!
-//! Best-effort by design: it never fails app startup. In dev the bundled
-//! resource does not exist, so this is a natural no-op. When `/usr/local/bin`
-//! is not writable (common on stock macOS without Homebrew) it falls back to
-//! `~/.local/bin`.
+//! Best-effort by design: it never fails app startup, and is a no-op in dev
+//! (it only acts for an installed `.app` bundle). Prefers `/usr/local/bin`,
+//! falling back to `~/.local/bin` when that isn't writable.
#[cfg(target_os = "macos")]
pub fn ensure_cli_symlink(app: &tauri::App) {
- use std::os::unix::fs::symlink;
+ use std::io::Write;
+ use std::os::unix::fs::PermissionsExt;
use std::path::PathBuf;
use tauri::Manager;
- let resource = match app.path().resource_dir() {
- Ok(dir) => dir.join("codegraff"),
+ // …/Codegraff.app/Contents/MacOS/codegraff-gui — the binary the launcher runs.
+ let exe = match std::env::current_exe() {
+ Ok(p) => p,
Err(_) => return,
};
- // Only present in a bundled .app — absent in dev, so this returns quietly.
- if !resource.exists() {
+ // Only install from a real bundle; skip `cargo tauri dev` runs out of target/.
+ if !exe.to_string_lossy().contains(".app/Contents/MacOS/") {
return;
}
- // Preferred PATH dirs, in order. /usr/local/bin matches the VS Code `code`
- // convention; ~/.local/bin is the no-admin fallback.
+ // `code`-style launcher. Resolves the first arg to an absolute path and
+ // launches the app detached (nohup + &) so the terminal returns immediately.
+ let script = format!(
+ "#!/bin/sh\n\
+ # codegraff — open a path in the Codegraff desktop app (code-style).\n\
+ # Auto-generated by Codegraff on launch; safe to delete.\n\
+ APP_BIN=\"{exe}\"\n\
+ if [ \"$#\" -eq 0 ]; then\n\
+ \x20 nohup \"$APP_BIN\" >/dev/null 2>&1 &\n\
+ \x20 exit 0\n\
+ fi\n\
+ target=\"$1\"\n\
+ if [ -e \"$target\" ]; then\n\
+ \x20 target=\"$(cd \"$(dirname \"$target\")\" 2>/dev/null && pwd)/$(basename \"$target\")\"\n\
+ fi\n\
+ nohup \"$APP_BIN\" \"$target\" >/dev/null 2>&1 &\n",
+ exe = exe.display()
+ );
+
let mut targets: Vec<PathBuf> = vec![PathBuf::from("/usr/local/bin")];
if let Ok(home) = app.path().home_dir() {
targets.push(home.join(".local").join("bin"));
@@ -34,29 +52,31 @@ pub fn ensure_cli_symlink(app: &tauri::App) {
for dir in targets {
let link = dir.join("codegraff");
- // Already linked to this exact build -> nothing to do.
- if let Ok(existing) = std::fs::read_link(&link) {
- if existing == resource {
- log::info!("codegraff CLI already linked at {}", link.display());
+ // Already current (handles app moves and the prior symlink form)?
+ if let Ok(existing) = std::fs::read_to_string(&link) {
+ if existing == script {
+ log::info!("codegraff launcher already current at {}", link.display());
return;
}
}
if std::fs::create_dir_all(&dir).is_err() {
continue;
}
- // Clear any stale link/file we own before relinking.
+ // Clear any stale file/symlink (e.g. the 0.0.11 binary symlink).
let _ = std::fs::remove_file(&link);
- match symlink(&resource, &link) {
+ let written = (|| -> std::io::Result<()> {
+ let mut f = std::fs::File::create(&link)?;
+ f.write_all(script.as_bytes())?;
+ f.set_permissions(std::fs::Permissions::from_mode(0o755))?;
+ Ok(())
+ })();
+ match written {
Ok(()) => {
- log::info!(
- "codegraff CLI linked: {} -> {}",
- link.display(),
- resource.display()
- );
+ log::info!("codegraff launcher installed at {}", link.display());
return;
}
Err(err) => {
- log::warn!("could not link codegraff into {}: {err}", dir.display());
+ log::warn!("could not write codegraff launcher into {}: {err}", dir.display());
}
}
}
diff --git a/gui/src-tauri/src/lib.rs b/gui/src-tauri/src/lib.rs
index d86a21aa..225c086c 100644
--- a/gui/src-tauri/src/lib.rs
+++ b/gui/src-tauri/src/lib.rs
@@ -42,13 +42,24 @@ use commands::{
};
use persistence::project_store::ProjectStore;
use runtime::DesktopState;
-use tauri::Manager;
+use tauri::{Emitter, Manager};
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
install_rustls_crypto_provider();
- let builder = tauri::Builder::default().plugin(tauri_plugin_dialog::init());
+ // single-instance must be registered first. A second `codegraff <path>`
+ // invocation lands here: open the path in the running window and focus it.
+ let builder = tauri::Builder::default()
+ .plugin(tauri_plugin_single_instance::init(|app, argv, _cwd| {
+ if let Some(path) = workspace_path_from_args(argv) {
+ let _ = app.emit("open-workspace-path", path);
+ }
+ if let Some(window) = app.get_webview_window("main") {
+ let _ = window.set_focus();
+ }
+ }))
+ .plugin(tauri_plugin_dialog::init());
#[cfg(debug_assertions)]
let builder = builder.plugin(
tauri_plugin_log::Builder::default()
@@ -70,7 +81,11 @@ pub fn run() {
app_dir.join("managed-chats"),
)?);
app.manage(DesktopState::new(emitter, projects));
- // First run: expose the bundled `codegraff` CLI on PATH (macOS).
+ // Cold start: stash a `codegraff <path>` arg so the UI opens it once ready.
+ app.manage(PendingOpen(std::sync::Mutex::new(workspace_path_from_args(
+ std::env::args(),
+ ))));
+ // First run: install the `codegraff` launcher command on PATH (macOS).
cli_install::ensure_cli_symlink(app);
Ok(())
})
@@ -144,11 +159,36 @@ pub fn run() {
terminal_open,
terminal_write,
terminal_resize,
- terminal_close
+ terminal_close,
+ drain_pending_open
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
+/// Holds a workspace path passed on the command line before the UI was ready
+/// (cold start). The frontend drains it via `drain_pending_open` once mounted.
+struct PendingOpen(std::sync::Mutex<Option<String>>);
+
+/// Resolve a `codegraff <path>` argument to an absolute workspace path. Skips
+/// the executable (argv[0]) and any leading flags, then takes the first
+/// argument that exists on disk and canonicalizes it.
+fn workspace_path_from_args<I: IntoIterator<Item = String>>(args: I) -> Option<String> {
+ for arg in args.into_iter().skip(1) {
+ if arg.starts_with('-') {
+ continue;
+ }
+ if let Ok(abs) = std::fs::canonicalize(&arg) {
+ return Some(abs.to_string_lossy().into_owned());
+ }
+ }
+ None
+}
+
+/// Hand the UI any path passed to `codegraff <path>` at cold start (consumed once).
+#[tauri::command]
+fn drain_pending_open(pending: tauri::State<'_, PendingOpen>) -> Option<String> {
+ pending.0.lock().ok().and_then(|mut slot| slot.take())
+}
fn install_rustls_crypto_provider() {
if rustls::crypto::CryptoProvider::get_default().is_some() {
diff --git a/gui/src-tauri/src/runtime/simple.rs b/gui/src-tauri/src/runtime/simple.rs
index 5125ae9f..bdec943d 100644
--- a/gui/src-tauri/src/runtime/simple.rs
+++ b/gui/src-tauri/src/runtime/simple.rs
@@ -124,6 +124,11 @@ impl RuntimeManager {
self.projects.add_project(Path::new(&workspace_path))?;
let mut state = self.state.lock().await;
set_active_workspace(&mut state, &workspace_path);
+ // Focus this workspace's own conversation (None for a fresh project).
+ // Otherwise active_conversation_id still points at the previously active
+ // workspace's chat, and the UI's (workspace, conversation) view lookup
+ // misses — leaving the panel stuck on an endless loading spinner.
+ state.active_conversation_id = state.selected_by_workspace.get(&workspace_path).cloned();
drop(state);
self.snapshot().await
}
diff --git a/gui/src-tauri/tauri.conf.json b/gui/src-tauri/tauri.conf.json
index 3da80490..271247ff 100644
--- a/gui/src-tauri/tauri.conf.json
+++ b/gui/src-tauri/tauri.conf.json
@@ -1,7 +1,7 @@
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "Codegraff",
- "version": "0.0.11",
+ "version": "0.0.12",
"identifier": "dev.codegraff.gui",
"build": {
"frontendDist": "../dist",
@@ -42,9 +42,6 @@
"icons/icon.icns",
"icons/icon.ico"
],
- "resources": {
- "binaries/codegraff": "codegraff"
- },
"macOS": {
"signingIdentity": "Developer ID Application: Rachit Pradhan (WWP9DLJ27P)",
"hardenedRuntime": true
diff --git a/gui/src/app/SessionProvider.tsx b/gui/src/app/SessionProvider.tsx
index ba4a3196..29f60997 100644
--- a/gui/src/app/SessionProvider.tsx
+++ b/gui/src/app/SessionProvider.tsx
@@ -136,6 +136,35 @@ export function SessionProvider({ children }: SessionProviderProps) {
syncBoardSelectionFromSnapshot,
]);
+ // `codegraff <path>` (code-style): open the path the launcher handed us —
+ // either stashed before launch (cold start) or forwarded to this running
+ // instance (single-instance). No-op in the browser/QA mock.
+ useEffect(() => {
+ let cancelled = false;
+ let unlisten: (() => void) | undefined;
+ void (async () => {
+ try {
+ const pending = await desktopClient.drainPendingOpen();
+ if (!cancelled && pending) {
+ void openWorkspaceByPath(pending);
+ }
+ } catch {
+ // No pending path (or not running under Tauri) — ignore.
+ }
+ try {
+ unlisten = await desktopClient.onOpenWorkspacePath((path) => {
+ void openWorkspaceByPath(path);
+ });
+ } catch {
+ // Event bridge unavailable (browser mode) — ignore.
+ }
+ })();
+ return () => {
+ cancelled = true;
+ unlisten?.();
+ };
+ }, [openWorkspaceByPath]);
+
const actionState = useMemo(
() => ({
checkoutBranch: async (branchName: string) => {
diff --git a/gui/src/services/desktop/client.ts b/gui/src/services/desktop/client.ts
index 4796e40f..86e51614 100644
--- a/gui/src/services/desktop/client.ts
+++ b/gui/src/services/desktop/client.ts
@@ -333,6 +333,19 @@ export function openWorkspace(path: string): Promise<SessionSnapshot> {
return invokeCommand("open_workspace", { path });
}
+// Drains a path passed to `codegraff <path>` before the app launched (cold start).
+export function drainPendingOpen(): Promise<string | null> {
+ return invokeCommand("drain_pending_open");
+}
+
+// Fires when a second `codegraff <path>` invocation forwards a path to this
+// already-running instance (single-instance plugin).
+export function onOpenWorkspacePath(
+ handler: (path: string) => void,
+): Promise<UnlistenFn> {
+ return listenEvent<string>("open-workspace-path", handler);
+}
+
export function getRuntimeStatus(
workspacePath?: string | null,
): Promise<RuntimeStatus> {