apps/desktop: Tauri 2 shell for the Strata desktop app
The Tauri shell (src-tauri Rust, 400-odd lines) that starts the Node App Host and opens the owner's UI, with the macOS entitlements, icons and generated schemas, and the build scripts in apps/desktop/scripts that package the app around a private Node sidecar (digest-verified fetch). The Node binary, Rust target/ and DMGs are not in git; src-tauri/resources/node/ keeps only its .gitignore placeholder. Windows and Linux packaging is not working yet (the sidecar lookup expects "node" and the scripts are bash-only); see the S0 notes. From the owner's rebuild branch strata/rebuild-2026-10.
No files matched your search
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "strata-desktop",
|
||||
"productName": "Strata",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"description": "Strata Desktop - local AI, tuned to one model.",
|
||||
"scripts": {
|
||||
"build:ui": "npm --prefix ../host run build",
|
||||
"typecheck:ui": "npm --prefix ../host run typecheck",
|
||||
"test:ui": "npm --prefix ../host test",
|
||||
"tauri": "cargo tauri",
|
||||
"dev": "npm run build:ui && cargo tauri dev",
|
||||
"build": "npm run build:ui && cargo tauri build",
|
||||
"build:app": "npm run build:ui && cargo tauri build --bundles app",
|
||||
"dmg": "npm run build:ui && cargo tauri build --bundles dmg"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
#!/usr/bin/env bash
|
||||
# Fetch and verify the private Node runtime the desktop bundle ships.
|
||||
#
|
||||
# The App Host is an ordinary Node program, and the packaging requirement is that an end user
|
||||
# supplies no runtime of their own. The desktop bundle therefore carries a pinned standalone Node
|
||||
# beside the host.
|
||||
#
|
||||
# It is NOT committed. It is a ~117 MB platform binary: committing it would bloat every clone, it
|
||||
# cannot be reviewed in a diff, and it is not source. This script is the reproducible substitute —
|
||||
# it downloads the official build for the target and refuses to install anything whose SHA-256 does
|
||||
# not match the recorded digest.
|
||||
#
|
||||
# Usage:
|
||||
# apps/desktop/scripts/fetch-node.sh # host platform
|
||||
# apps/desktop/scripts/fetch-node.sh --target linux-x64
|
||||
# apps/desktop/scripts/fetch-node.sh --check # verify what is already installed
|
||||
#
|
||||
# The Node version must satisfy the App Host's own `engines.node` (>= 24.12.0).
|
||||
set -euo pipefail
|
||||
|
||||
NODE_VERSION="${STRATA_NODE_VERSION:-24.12.0}"
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
DEST="$HERE/../src-tauri/resources/node"
|
||||
|
||||
# Published SHA-256 of each official nodejs.org archive, recorded so a tampered or truncated
|
||||
# download is refused rather than shipped. Add a row when bumping the version.
|
||||
# Taken from nodejs.org's own SHASUMS256.txt for v24.12.0, which is published over HTTPS beside
|
||||
# the archives. Recorded here so the fetch is verified against a value that does not come from the
|
||||
# same response as the payload.
|
||||
digest_for() {
|
||||
case "$1" in
|
||||
darwin-arm64) echo "319f221adc5e44ff0ed57e8a441b2284f02b8dc6fc87b8eb92a6a93643fd8080" ;;
|
||||
linux-x64) echo "6159227e0af7d7c3c6bb2fa900452b04a6cb8841a702a79acc613209d70b04d0" ;;
|
||||
linux-arm64) echo "9b2a2eeb98a8eb37361224e2a1d060300ad2dd143af58dfdb16de785df0f1228" ;;
|
||||
win-x64) echo "9c125f61ae947b52e779095830f9cac267846a043ef7192183c84016aaad2812" ;;
|
||||
*) echo "" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
target() {
|
||||
if [ "${1:-}" = "--target" ]; then echo "${2:?--target needs a value}"; return; fi
|
||||
case "$(uname -s)-$(uname -m)" in
|
||||
Darwin-arm64) echo darwin-arm64 ;;
|
||||
Linux-x86_64) echo linux-x64 ;;
|
||||
Linux-aarch64) echo linux-arm64 ;;
|
||||
MINGW*|MSYS*|CYGWIN*) echo win-x64 ;;
|
||||
*) echo "unsupported host: $(uname -s)-$(uname -m)" >&2; exit 2 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
TARGET="$(target "$@")"
|
||||
EXE="node"
|
||||
case "$TARGET" in win-*) EXE="node.exe" ;; esac
|
||||
INSTALLED="$DEST/$EXE"
|
||||
|
||||
if [ "${1:-}" = "--check" ]; then
|
||||
if [ ! -x "$INSTALLED" ]; then echo "fetch-node: not installed at $INSTALLED" >&2; exit 1; fi
|
||||
got="$("$INSTALLED" --version)"
|
||||
echo "fetch-node: $INSTALLED is $got"
|
||||
case "$got" in "v$NODE_VERSION") exit 0 ;; *) echo "fetch-node: expected v$NODE_VERSION" >&2; exit 1 ;; esac
|
||||
fi
|
||||
|
||||
# The official archive for this target.
|
||||
case "$TARGET" in
|
||||
darwin-arm64) ARCHIVE="node-v$NODE_VERSION-darwin-arm64.tar.gz" ;;
|
||||
darwin-x64) ARCHIVE="node-v$NODE_VERSION-darwin-x64.tar.gz" ;;
|
||||
linux-x64) ARCHIVE="node-v$NODE_VERSION-linux-x64.tar.gz" ;;
|
||||
linux-arm64) ARCHIVE="node-v$NODE_VERSION-linux-arm64.tar.gz" ;;
|
||||
win-x64) ARCHIVE="node-v$NODE_VERSION-win-x64.zip" ;;
|
||||
*) echo "fetch-node: no archive known for $TARGET" >&2; exit 2 ;;
|
||||
esac
|
||||
URL="https://nodejs.org/dist/v$NODE_VERSION/$ARCHIVE"
|
||||
|
||||
EXPECTED="$(digest_for "$TARGET")"
|
||||
WORK="$(mktemp -d -t strata-node)"
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
|
||||
echo "fetch-node: $URL"
|
||||
curl -fsSL -o "$WORK/$ARCHIVE" "$URL"
|
||||
|
||||
ACTUAL="$(shasum -a 256 "$WORK/$ARCHIVE" 2>/dev/null | cut -d' ' -f1 || sha256sum "$WORK/$ARCHIVE" | cut -d' ' -f1)"
|
||||
if [ -n "$EXPECTED" ]; then
|
||||
if [ "$ACTUAL" != "$EXPECTED" ]; then
|
||||
echo "fetch-node: REFUSING — $ARCHIVE hashes $ACTUAL, expected $EXPECTED" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "fetch-node: sha256 verified against the recorded digest"
|
||||
else
|
||||
# Without a recorded digest the download cannot be authenticated. Say so loudly and keep the
|
||||
# computed value so it can be recorded, rather than implying a verification that did not happen.
|
||||
echo "fetch-node: WARNING — no recorded digest for $TARGET; this download is NOT authenticated." >&2
|
||||
echo "fetch-node: computed sha256 $ACTUAL — record it in $(basename "${BASH_SOURCE[0]}") to enable verification." >&2
|
||||
fi
|
||||
|
||||
mkdir -p "$DEST"
|
||||
case "$ARCHIVE" in
|
||||
*.zip) unzip -q -j "$WORK/$ARCHIVE" "node-v$NODE_VERSION-win-x64/node.exe" -d "$DEST" ;;
|
||||
*) tar xzf "$WORK/$ARCHIVE" -C "$WORK"
|
||||
cp "$WORK/node-v$NODE_VERSION-$TARGET/bin/node" "$DEST/node" ;;
|
||||
esac
|
||||
chmod +x "$DEST/$EXE"
|
||||
|
||||
echo "fetch-node: installed $("$DEST/$EXE" --version) at $DEST/$EXE"
|
||||
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env bash
|
||||
# Build the Strata DMG without a Finder session.
|
||||
#
|
||||
# Tauri's default DMG step runs an AppleScript that asks Finder to arrange the window (icon
|
||||
# positions, background). Finder AppleEvents time out in a non-GUI or sandboxed context — observed
|
||||
# here as `Finder got an error: AppleEvent timed out. (-1712)` — so the default path cannot be
|
||||
# relied on for an automated build. The upstream `create-dmg` script already supports exactly this
|
||||
# case via `--skip-jenkins`, which produces a plain, correct DMG with the app and the Applications
|
||||
# drop link and no cosmetic arrangement.
|
||||
#
|
||||
# Usage: scripts/make-dmg.sh [output.dmg]
|
||||
set -euo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
DESKTOP="$(cd "$HERE/.." && pwd)"
|
||||
BUNDLE="$DESKTOP/src-tauri/target/release/bundle"
|
||||
APP="$BUNDLE/macos/Strata.app"
|
||||
OUT="${1:-$BUNDLE/dmg/Strata_0.1.0_aarch64.dmg}"
|
||||
|
||||
if [ ! -d "$APP" ]; then
|
||||
echo "error: $APP does not exist; run 'cargo tauri build --bundles app' first" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
WORK="$(mktemp -d -t strata-dmg)"
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
|
||||
# A staging folder is what create-dmg copies into the image: the app, and nothing else.
|
||||
#
|
||||
# The Applications drop link is created by `--app-drop-link` below. Adding one here as well makes
|
||||
# create-dmg fail with "File exists", because it links into the volume it is assembling.
|
||||
mkdir -p "$WORK/stage"
|
||||
cp -R "$APP" "$WORK/stage/"
|
||||
|
||||
# Reuse Tauri's vendored create-dmg if the bundler left it behind, otherwise take it from the
|
||||
# bundle cache. Building it yourself is not necessary and not expected.
|
||||
SCRIPT="$BUNDLE/dmg/bundle_dmg.sh"
|
||||
if [ ! -x "$SCRIPT" ]; then
|
||||
echo "error: $SCRIPT not found; run 'cargo tauri build --bundles dmg' once to vendor it" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$(dirname "$OUT")"
|
||||
rm -f "$OUT"
|
||||
|
||||
# --skip-jenkins: no Finder AppleScript. Everything else is the same code path Tauri uses.
|
||||
"$SCRIPT" \
|
||||
--volname "Strata 0.1.0" \
|
||||
--volicon "$BUNDLE/macos/Strata.app/Contents/Resources/Strata.icns" \
|
||||
--app-drop-link 400 200 \
|
||||
--skip-jenkins \
|
||||
--no-internet-enable \
|
||||
"$OUT" "$WORK/stage"
|
||||
|
||||
echo
|
||||
echo "built: $OUT"
|
||||
ls -lh "$OUT" | awk '{print "size: " $5}'
|
||||
shasum -a 256 "$OUT"
|
||||
@@ -0,0 +1,2 @@
|
||||
# Rust build output. Regenerated by `cargo tauri build`; never committed.
|
||||
/target/
|
||||
@@ -0,0 +1,23 @@
|
||||
[package]
|
||||
name = "strata-desktop"
|
||||
version = "0.1.0"
|
||||
description = "Strata Desktop — local AI, tuned to one model."
|
||||
edition = "2021"
|
||||
rust-version = "1.77"
|
||||
license = "MIT"
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = [] }
|
||||
tauri-plugin-shell = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
lto = true
|
||||
opt-level = "s"
|
||||
panic = "abort"
|
||||
strip = true
|
||||
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<!-- Tauri uses the system WKWebView, so this bundle needs no JIT entitlement of its own;
|
||||
the web content process gets what it needs from the OS. The App Host runs as an ordinary
|
||||
child process and needs no special rights. Kept minimal on purpose. -->
|
||||
<key>com.apple.security.files.user-selected.read-write</key>
|
||||
<true/>
|
||||
<key>com.apple.security.network.client</key>
|
||||
<true/>
|
||||
<key>com.apple.security.network.server</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1 @@
|
||||
{"core":{"default_permission":{"identifier":"default","description":"Default core plugins set.","permissions":["core:path:default","core:event:default","core:window:default","core:webview:default","core:app:default","core:image:default","core:resources:default","core:menu:default","core:tray:default"]},"permissions":{},"permission_sets":{},"global_scope_schema":null},"core:app":{"default_permission":{"identifier":"default","description":"Default permissions for the plugin.","permissions":["allow-version","allow-name","allow-tauri-version","allow-identifier","allow-bundle-type","allow-register-listener","allow-remove-listener","allow-supports-multiple-windows"]},"permissions":{"allow-app-hide":{"identifier":"allow-app-hide","description":"Enables the app_hide command without any pre-configured scope.","commands":{"allow":["app_hide"],"deny":[]}},"allow-app-show":{"identifier":"allow-app-show","description":"Enables the app_show command without any pre-configured scope.","commands":{"allow":["app_show"],"deny":[]}},"allow-bundle-type":{"identifier":"allow-bundle-type","description":"Enables the bundle_type command without any pre-configured scope.","commands":{"allow":["bundle_type"],"deny":[]}},"allow-default-window-icon":{"identifier":"allow-default-window-icon","description":"Enables the default_window_icon command without any pre-configured scope.","commands":{"allow":["default_window_icon"],"deny":[]}},"allow-exit":{"identifier":"allow-exit","description":"Enables the exit command without any pre-configured scope.","commands":{"allow":["exit"],"deny":[]}},"allow-fetch-data-store-identifiers":{"identifier":"allow-fetch-data-store-identifiers","description":"Enables the fetch_data_store_identifiers command without any pre-configured scope.","commands":{"allow":["fetch_data_store_identifiers"],"deny":[]}},"allow-identifier":{"identifier":"allow-identifier","description":"Enables the identifier command without any pre-configured scope.","commands":{"allow":["identifier"],"deny":[]}},"allow-name":{"identifier":"allow-name","description":"Enables the name command without any pre-configured scope.","commands":{"allow":["name"],"deny":[]}},"allow-register-listener":{"identifier":"allow-register-listener","description":"Enables the register_listener command without any pre-configured scope.","commands":{"allow":["register_listener"],"deny":[]}},"allow-remove-data-store":{"identifier":"allow-remove-data-store","description":"Enables the remove_data_store command without any pre-configured scope.","commands":{"allow":["remove_data_store"],"deny":[]}},"allow-remove-listener":{"identifier":"allow-remove-listener","description":"Enables the remove_listener command without any pre-configured scope.","commands":{"allow":["remove_listener"],"deny":[]}},"allow-set-app-theme":{"identifier":"allow-set-app-theme","description":"Enables the set_app_theme command without any pre-configured scope.","commands":{"allow":["set_app_theme"],"deny":[]}},"allow-set-dock-visibility":{"identifier":"allow-set-dock-visibility","description":"Enables the set_dock_visibility command without any pre-configured scope.","commands":{"allow":["set_dock_visibility"],"deny":[]}},"allow-supports-multiple-windows":{"identifier":"allow-supports-multiple-windows","description":"Enables the supports_multiple_windows command without any pre-configured scope.","commands":{"allow":["supports_multiple_windows"],"deny":[]}},"allow-tauri-version":{"identifier":"allow-tauri-version","description":"Enables the tauri_version command without any pre-configured scope.","commands":{"allow":["tauri_version"],"deny":[]}},"allow-version":{"identifier":"allow-version","description":"Enables the version command without any pre-configured scope.","commands":{"allow":["version"],"deny":[]}},"deny-app-hide":{"identifier":"deny-app-hide","description":"Denies the app_hide command without any pre-configured scope.","commands":{"allow":[],"deny":["app_hide"]}},"deny-app-show":{"identifier":"deny-app-show","description":"Denies the app_show command without any pre-configured scope.","commands":{"allow":[],"deny":["app_show"]}},"deny-bundle-type":{"identifier":"deny-bundle-type","description":"Denies the bundle_type command without any pre-configured scope.","commands":{"allow":[],"deny":["bundle_type"]}},"deny-default-window-icon":{"identifier":"deny-default-window-icon","description":"Denies the default_window_icon command without any pre-configured scope.","commands":{"allow":[],"deny":["default_window_icon"]}},"deny-exit":{"identifier":"deny-exit","description":"Denies the exit command without any pre-configured scope.","commands":{"allow":[],"deny":["exit"]}},"deny-fetch-data-store-identifiers":{"identifier":"deny-fetch-data-store-identifiers","description":"Denies the fetch_data_store_identifiers command without any pre-configured scope.","commands":{"allow":[],"deny":["fetch_data_store_identifiers"]}},"deny-identifier":{"identifier":"deny-identifier","description":"DenLine truncated
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 7.5 KiB |
|
After Width: | Height: | Size: 882 B |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 8.5 KiB |
|
After Width: | Height: | Size: 771 B |
|
After Width: | Height: | Size: 9.2 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
</adaptive-icon>
|
||||
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 949 B |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 9.7 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="ic_launcher_background">#FFFFFF</color>
|
||||
</resources>
|
||||
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 504 B |
|
After Width: | Height: | Size: 1019 B |
|
After Width: | Height: | Size: 1019 B |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 794 B |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 1019 B |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 4.9 KiB |
@@ -0,0 +1,6 @@
|
||||
# The private Node runtime is a build input, not source.
|
||||
#
|
||||
# It is a 117 MB platform binary that would bloat every clone and cannot be reviewed in a diff.
|
||||
# `packaging/README.md` and `apps/desktop/scripts/fetch-node.sh` record exactly how to obtain it:
|
||||
# the official nodejs.org build for the target, verified against its published SHA-256.
|
||||
/node
|
||||
@@ -0,0 +1,403 @@
|
||||
//! Strata Desktop — Tauri shell.
|
||||
//!
|
||||
//! The shell is a *carrier*, not an owner. It does exactly three things:
|
||||
//!
|
||||
//! 1. finds its bundled resources (the private Node runtime, the App Host, the built UI) and
|
||||
//! starts the App Host on a free loopback port;
|
||||
//! 2. opens one webview window on the host's own origin, so the renderer and the API share an
|
||||
//! origin exactly as the browser build does and the supplied UI's relative `/api/...` calls
|
||||
//! keep working with no rewrite;
|
||||
//! 3. stops the host when the app exits.
|
||||
//!
|
||||
//! Ownership stays where the architecture puts it. The App Host owns the local client API and the
|
||||
//! engine lifecycle; Strata Control owns components, models, profiles and jobs; DeepSeek Harness
|
||||
//! owns the agent loop and durable sessions. There is deliberately no second supervisor, no
|
||||
//! conversation store and no agent loop in this file.
|
||||
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use std::net::TcpListener;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Child, Command, Stdio};
|
||||
use std::sync::Mutex;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use tauri::{Manager, WebviewUrl, WebviewWindowBuilder};
|
||||
|
||||
/// The running App Host, kept so it can be stopped on exit.
|
||||
struct HostProcess(Mutex<Option<Child>>);
|
||||
|
||||
/// The port the App Host bound, so the window (and the frontend) can be pointed at it.
|
||||
struct HostPort(Mutex<Option<u16>>);
|
||||
|
||||
/// Ask the OS for an unused loopback port.
|
||||
///
|
||||
/// The port is released before the host binds it, so there is a small race; the host reports a
|
||||
/// clear "port already in use" error if another process takes it first, and that surfaces in the
|
||||
/// window instead of failing silently.
|
||||
fn pick_port() -> Result<u16, String> {
|
||||
let listener = TcpListener::bind(("127.0.0.1", 0)).map_err(|e| format!("bind: {e}"))?;
|
||||
let port = listener.local_addr().map_err(|e| format!("addr: {e}"))?.port();
|
||||
drop(listener);
|
||||
Ok(port)
|
||||
}
|
||||
|
||||
/// Locate a bundled resource.
|
||||
///
|
||||
/// In a packaged `.app` Tauri places `bundle.resources` under `Contents/Resources`. During
|
||||
/// development they are not copied, so the repository layout is the fallback. Both are tried so
|
||||
/// `tauri dev` and the packaged bundle behave the same way.
|
||||
fn resource_dir(app: &tauri::AppHandle) -> Result<PathBuf, String> {
|
||||
if let Ok(dir) = app.path().resource_dir() {
|
||||
if dir.join("host").join("server").join("index.mjs").exists() {
|
||||
return Ok(dir);
|
||||
}
|
||||
}
|
||||
// development: apps/desktop/src-tauri -> ../../host and ./resources
|
||||
let manifest = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
Ok(manifest)
|
||||
}
|
||||
|
||||
/// The private Node runtime that ships with the bundle.
|
||||
fn node_binary(res: &Path) -> Result<PathBuf, String> {
|
||||
let bundled = res.join("node").join("node");
|
||||
if bundled.exists() {
|
||||
return Ok(bundled);
|
||||
}
|
||||
// development fallback: the sidecar prepared alongside the checkout
|
||||
let dev = res
|
||||
.join("..")
|
||||
.join("..")
|
||||
.join("..")
|
||||
.join("toolchain")
|
||||
.join("node")
|
||||
.join("node-v24.12.0-darwin-arm64")
|
||||
.join("bin")
|
||||
.join("node");
|
||||
if dev.exists() {
|
||||
return Ok(dev);
|
||||
}
|
||||
Err(format!(
|
||||
"the bundled Node runtime is missing (looked for {} and {})",
|
||||
bundled.display(),
|
||||
dev.display()
|
||||
))
|
||||
}
|
||||
|
||||
/// Wait until the host answers `/api/health`, or give up.
|
||||
fn wait_for_health(port: u16, timeout: Duration) -> Result<(), String> {
|
||||
let deadline = Instant::now() + timeout;
|
||||
let url = format!("http://127.0.0.1:{port}/api/health");
|
||||
let mut last = String::from("no attempt made");
|
||||
while Instant::now() < deadline {
|
||||
match ureq_get_ok(&url) {
|
||||
Ok(true) => return Ok(()),
|
||||
Ok(false) => last = "the host answered with a non-2xx status".into(),
|
||||
Err(e) => last = e,
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(250));
|
||||
}
|
||||
Err(format!("the Strata App Host did not become healthy at {url}: {last}"))
|
||||
}
|
||||
|
||||
/// A minimal blocking HTTP GET, so the shell needs no async runtime for one health probe.
|
||||
fn ureq_get_ok(url: &str) -> Result<bool, String> {
|
||||
use std::io::{Read, Write};
|
||||
let rest = url.strip_prefix("http://").ok_or("only http:// is supported")?;
|
||||
let (authority, path) = match rest.find('/') {
|
||||
Some(i) => (&rest[..i], &rest[i..]),
|
||||
None => (rest, "/"),
|
||||
};
|
||||
let mut stream = std::net::TcpStream::connect_timeout(
|
||||
&authority
|
||||
.parse()
|
||||
.map_err(|e| format!("bad authority {authority}: {e}"))?,
|
||||
Duration::from_millis(800),
|
||||
)
|
||||
.map_err(|e| e.to_string())?;
|
||||
stream
|
||||
.set_read_timeout(Some(Duration::from_millis(1500)))
|
||||
.map_err(|e| e.to_string())?;
|
||||
stream
|
||||
.write_all(format!("GET {path} HTTP/1.1\r\nHost: {authority}\r\nConnection: close\r\n\r\n").as_bytes())
|
||||
.map_err(|e| e.to_string())?;
|
||||
let mut buf = String::new();
|
||||
stream.read_to_string(&mut buf).map_err(|e| e.to_string())?;
|
||||
let status = buf.lines().next().unwrap_or_default();
|
||||
Ok(status.contains(" 200") || status.contains(" 204"))
|
||||
}
|
||||
|
||||
/// Start the App Host and return the port it should serve on.
|
||||
fn start_host(app: &tauri::AppHandle) -> Result<u16, String> {
|
||||
let res = resource_dir(app)?;
|
||||
let host_dir = if res.join("host").join("server").join("index.mjs").exists() {
|
||||
res.join("host")
|
||||
} else {
|
||||
res.join("..").join("host")
|
||||
};
|
||||
let entry = host_dir.join("server").join("index.mjs");
|
||||
if !entry.exists() {
|
||||
return Err(format!("the App Host entry is missing at {}", entry.display()));
|
||||
}
|
||||
let dist = host_dir.join("dist");
|
||||
if !dist.exists() {
|
||||
return Err(format!(
|
||||
"the built UI is missing at {}; run \"npm --prefix host run build\"",
|
||||
dist.display()
|
||||
));
|
||||
}
|
||||
let node = node_binary(&res)?;
|
||||
|
||||
let port = pick_port()?;
|
||||
|
||||
let mut cmd = Command::new(&node);
|
||||
cmd.arg(&entry)
|
||||
.current_dir(&host_dir)
|
||||
.env("STRATA_PORT", port.to_string())
|
||||
.env("STRATA_DIST", &dist)
|
||||
.env("NODE_ENV", "production")
|
||||
// U12: a packaged build must have no success path that uses demo responses or demo
|
||||
// metrics. `STRATA_PACKAGED` makes the host refuse to simulate; `STRATA_REAL_ENGINE` is set
|
||||
// for the same reason, so the monitor reports `none` instead of fabricated numbers.
|
||||
.env("STRATA_PACKAGED", "1")
|
||||
.env("STRATA_REAL_ENGINE", "1")
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::inherit())
|
||||
.stderr(Stdio::inherit());
|
||||
// A user with the Strata API worker on a different port sets this; unset means the worker's
|
||||
// documented loopback default.
|
||||
if let Ok(url) = std::env::var("STRATA_SERVER_URL") {
|
||||
cmd.env("STRATA_SERVER_URL", url);
|
||||
}
|
||||
|
||||
let child = cmd
|
||||
.spawn()
|
||||
.map_err(|e| format!("could not start the App Host on {}: {e}", node.display()))?;
|
||||
*app.state::<HostProcess>().0.lock().unwrap() = Some(child);
|
||||
*app.state::<HostPort>().0.lock().unwrap() = Some(port);
|
||||
|
||||
wait_for_health(port, Duration::from_secs(60))?;
|
||||
Ok(port)
|
||||
}
|
||||
|
||||
/// Stop the App Host.
|
||||
///
|
||||
/// Only this process is signalled. The engine worker and any jobs belong to Strata Control and are
|
||||
/// deliberately not touched here: quitting the window must not kill inference another client is
|
||||
/// using.
|
||||
fn stop_host(app: &tauri::AppHandle) {
|
||||
if let Some(state) = app.try_state::<HostProcess>() {
|
||||
if let Some(mut child) = state.0.lock().unwrap().take() {
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse `--self-test[=path]`; returns the report path when the flag is present.
|
||||
fn self_test_path(args: &[String]) -> Option<String> {
|
||||
for a in args.iter().skip(1) {
|
||||
if a == "--self-test" {
|
||||
return Some(
|
||||
std::env::temp_dir()
|
||||
.join("strata-desktop-self-test.json")
|
||||
.to_string_lossy()
|
||||
.into_owned(),
|
||||
);
|
||||
}
|
||||
if let Some(rest) = a.strip_prefix("--self-test=") {
|
||||
return Some(rest.to_string());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Start the host from the packaged resources and report what actually happened.
|
||||
fn run_self_test(report_path: &str) -> i32 {
|
||||
let mut steps: Vec<(String, bool, String)> = Vec::new();
|
||||
let mut record = |name: &str, ok: bool, detail: String| {
|
||||
steps.push((name.to_string(), ok, detail));
|
||||
};
|
||||
|
||||
// Resolve resources the same way the real app does: `Contents/Resources` next to the
|
||||
// executable when packaged, the repository layout otherwise.
|
||||
let exe = std::env::current_exe().unwrap_or_default();
|
||||
let packaged_res = exe
|
||||
.parent()
|
||||
.and_then(|p| p.parent())
|
||||
.map(|p| p.join("Resources"))
|
||||
.filter(|p| p.join("host").join("server").join("index.mjs").exists());
|
||||
|
||||
let res = match packaged_res {
|
||||
Some(p) => {
|
||||
record("resources-packaged", true, p.display().to_string());
|
||||
p
|
||||
}
|
||||
None => {
|
||||
let dev = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
record(
|
||||
"resources-packaged",
|
||||
false,
|
||||
format!("not a packaged layout; using development root {}", dev.display()),
|
||||
);
|
||||
dev
|
||||
}
|
||||
};
|
||||
|
||||
let host_dir = if res.join("host").join("server").join("index.mjs").exists() {
|
||||
res.join("host")
|
||||
} else {
|
||||
res.join("..").join("host")
|
||||
};
|
||||
let entry = host_dir.join("server").join("index.mjs");
|
||||
let dist = host_dir.join("dist");
|
||||
record("host-entry-present", entry.exists(), entry.display().to_string());
|
||||
record("ui-dist-present", dist.join("index.html").exists(), dist.display().to_string());
|
||||
|
||||
let node = match node_binary(&res) {
|
||||
Ok(n) => {
|
||||
let version_ok = Command::new(&n)
|
||||
.arg("--version")
|
||||
.output()
|
||||
.map(|o| o.status.success())
|
||||
.unwrap_or(false);
|
||||
record("private-node-runtime", version_ok, n.display().to_string());
|
||||
n
|
||||
}
|
||||
Err(e) => {
|
||||
record("private-node-runtime", false, e.clone());
|
||||
return write_self_test_report(report_path, steps, &e);
|
||||
}
|
||||
};
|
||||
|
||||
let port = match pick_port() {
|
||||
Ok(p) => p,
|
||||
Err(e) => return write_self_test_report(report_path, steps, &e),
|
||||
};
|
||||
|
||||
let mut cmd = Command::new(&node);
|
||||
cmd.arg(&entry)
|
||||
.current_dir(&host_dir)
|
||||
.env("STRATA_PORT", port.to_string())
|
||||
.env("STRATA_DIST", &dist)
|
||||
.env("STRATA_PACKAGED", "1")
|
||||
.env("STRATA_REAL_ENGINE", "1")
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null());
|
||||
let mut child = match cmd.spawn() {
|
||||
Ok(c) => {
|
||||
record("host-spawned", true, format!("pid {}", c.id()));
|
||||
c
|
||||
}
|
||||
Err(e) => {
|
||||
let msg = format!("spawn failed: {e}");
|
||||
record("host-spawned", false, msg.clone());
|
||||
return write_self_test_report(report_path, steps, &msg);
|
||||
}
|
||||
};
|
||||
|
||||
let healthy = wait_for_health(port, Duration::from_secs(45));
|
||||
record("host-healthy", healthy.is_ok(), match &healthy {
|
||||
Ok(()) => format!("http://127.0.0.1:{port}/api/health answered 2xx"),
|
||||
Err(e) => e.clone(),
|
||||
});
|
||||
|
||||
// The UI must actually be served from the bundle, not merely present on disk.
|
||||
let ui_ok = ureq_get_ok(&format!("http://127.0.0.1:{port}/")).unwrap_or(false);
|
||||
record("ui-served", ui_ok, format!("http://127.0.0.1:{port}/"));
|
||||
|
||||
// The API the renderer will call must be reachable on the same origin.
|
||||
let api_ok = ureq_get_ok(&format!("http://127.0.0.1:{port}/api/health")).unwrap_or(false);
|
||||
record("api-reachable-on-same-origin", api_ok, "GET /api/health".into());
|
||||
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
|
||||
let msg = if steps.iter().all(|(_, ok, _)| *ok) {
|
||||
String::new()
|
||||
} else {
|
||||
"one or more steps failed".into()
|
||||
};
|
||||
write_self_test_report(report_path, steps, &msg)
|
||||
}
|
||||
|
||||
/// Write the JSON report and return the process exit code.
|
||||
fn write_self_test_report(path: &str, steps: Vec<(String, bool, String)>, error: &str) -> i32 {
|
||||
let ok = !steps.is_empty() && steps.iter().all(|(_, o, _)| *o);
|
||||
let steps_json: Vec<serde_json::Value> = steps
|
||||
.iter()
|
||||
.map(|(name, ok, detail)| {
|
||||
serde_json::json!({ "name": name, "ok": ok, "detail": detail })
|
||||
})
|
||||
.collect();
|
||||
let report = serde_json::json!({
|
||||
"schemaVersion": 1,
|
||||
"kind": "strata-desktop-self-test",
|
||||
"carrier": "tauri",
|
||||
"ok": ok,
|
||||
"error": error,
|
||||
"steps": steps_json,
|
||||
});
|
||||
let text = serde_json::to_string_pretty(&report).unwrap_or_else(|_| "{}".into());
|
||||
if let Err(e) = std::fs::write(path, &text) {
|
||||
eprintln!("[strata] could not write the self-test report to {path}: {e}");
|
||||
}
|
||||
println!("{text}");
|
||||
if ok {
|
||||
0
|
||||
} else {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// ------------------------------------------------------------------ self-test
|
||||
//
|
||||
// `Strata.app/Contents/MacOS/strata-desktop --self-test[=path]` starts the App Host from the
|
||||
// *packaged resources*, waits for it to answer, checks that it serves the supplied UI, writes a
|
||||
// JSON report and exits 0/1. This is what makes the shipped artifact verifiable without a human
|
||||
// at the screen — the lesson from the Electron attempt, where a packaged app that never started
|
||||
// its host hung with no output at all.
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
if let Some(path) = self_test_path(&args) {
|
||||
let code = run_self_test(&path);
|
||||
std::process::exit(code);
|
||||
}
|
||||
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.manage(HostProcess(Mutex::new(None)))
|
||||
.manage(HostPort(Mutex::new(None)))
|
||||
.setup(|app| {
|
||||
let handle = app.handle().clone();
|
||||
let port = start_host(&handle).map_err(|e| {
|
||||
// A startup failure must be visible, not a blank window.
|
||||
eprintln!("[strata] {e}");
|
||||
Box::<dyn std::error::Error>::from(e)
|
||||
})?;
|
||||
|
||||
let origin = format!("http://127.0.0.1:{port}");
|
||||
let url = origin.parse().expect("a valid loopback URL");
|
||||
|
||||
WebviewWindowBuilder::new(app, "main", WebviewUrl::External(url))
|
||||
.title("Strata")
|
||||
.inner_size(1440.0, 920.0)
|
||||
.min_inner_size(900.0, 600.0)
|
||||
.build()?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|window, event| {
|
||||
if let tauri::WindowEvent::Destroyed = event {
|
||||
stop_host(&window.app_handle().clone());
|
||||
}
|
||||
})
|
||||
.build(tauri::generate_context!())
|
||||
.expect("error while building the Strata application")
|
||||
.run(|app, event| {
|
||||
if let tauri::RunEvent::ExitRequested { .. } | tauri::RunEvent::Exit = event {
|
||||
stop_host(app);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "Strata",
|
||||
"version": "0.1.0",
|
||||
"identifier": "ai.strata.desktop",
|
||||
"build": {
|
||||
"frontendDist": "../../host/dist"
|
||||
},
|
||||
"app": {
|
||||
"withGlobalTauri": false,
|
||||
"windows": [],
|
||||
"security": {
|
||||
"csp": null,
|
||||
"dangerousDisableAssetCspModification": false
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": [
|
||||
"dmg",
|
||||
"app",
|
||||
"nsis",
|
||||
"appimage",
|
||||
"deb"
|
||||
],
|
||||
"icon": [
|
||||
"icons/icon.png"
|
||||
],
|
||||
"category": "DeveloperTool",
|
||||
"shortDescription": "Local AI, tuned to one model.",
|
||||
"longDescription": "Strata runs one local model, tuned to your machine. Desktop and Terminal share the same model inventory, profiles, runtime and agent sessions.",
|
||||
"resources": {
|
||||
"../../host/dist": "host/dist",
|
||||
"../../host/server": "host/server",
|
||||
"../../host/package.json": "host/package.json",
|
||||
"resources/node": "node"
|
||||
},
|
||||
"macOS": {
|
||||
"minimumSystemVersion": "11.0",
|
||||
"entitlements": "entitlements.plist"
|
||||
},
|
||||
"createUpdaterArtifacts": false,
|
||||
"windows": {
|
||||
"nsis": {
|
||||
"installMode": "currentUser",
|
||||
"compression": "lzma",
|
||||
"languages": [
|
||||
"English"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"plugins": {}
|
||||
}
|
||||