Tauri

From j4flmao/agent-skills · View interactive version

Tauri is an AI agent skill from the GitHub repository j4flmao/agent-skills. Use when the user asks to build a desktop app with Tauri and a Rust backend, Tauri v2, commands and invoke, capabilities and permissions, Tauri plugins, the updater or mobile targets. Produces secure Tauri 2 apps with typed IPC, capability files and bundling. Not for Electron apps (use desktop-elect

How to use this skill

Skill file

Tauri 2 Desktop Development

Purpose

Tauri builds desktop (Windows, macOS, Linux) and mobile (iOS, Android) apps from a web frontend rendered in the OS webview (WebView2, WKWebView, WebKitGTK) and a Rust core. Tauri 2 replaced the v1 allowlist with a capability/permission system: the frontend can call nothing unless a capability grants it. This skill produces secure command, permission and plugin setups.

Agent Protocol

Trigger

"tauri", "src-tauri", "#[tauri::command]", "invoke", "capabilities", "permissions", "tauri plugin", "tauri updater", "tauri.conf.json".

Input Context

Output Artifact

Rust commands, lib.rs builder setup, capability JSON, frontend IPC wrappers.

Response Format

Command: {name}({args}) -> Result<{T}, {Error}>
Permission: {capability file} grants {plugin:permission | allow-<command>}
Frontend: invoke<{T}>('{name}', { ... })
Windows/webviews: {labels}
Risk: {what the frontend can now do}

Project Layout (v2)

src-tauri/
  Cargo.toml
  tauri.conf.json          # app identifier, windows, bundle, security.csp
  capabilities/default.json# which windows get which permissions
  src/main.rs              # desktop entry: calls app_lib::run()
  src/lib.rs               # shared entry for desktop + mobile

Commands (Rust)

// src-tauri/src/lib.rs
use serde::Serialize;
use std::sync::Mutex;
use tauri::State;

#[derive(Debug, thiserror::Error)]
pub enum AppError {
    #[error("note title must not be empty")]
    EmptyTitle,
    #[error(transparent)]
    Io(#[from] std::io::Error),
}

// Errors must be serializable to reach the frontend.
impl Serialize for AppError {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        s.serialize_str(&self.to_string())
    }
}

#[derive(Default)]
struct Notes(Mutex<Vec<String>>);

#[tauri::command]
fn add_note(title: String, notes: State<'_, Notes>) -> Result<usize, AppError> {
    let title = title.trim();
    if title.is_empty() {
        return Err(AppError::EmptyTitle);
    }
    let mut list = notes.0.lock().expect("notes mutex poisoned");
    list.push(title.to_owned());
    Ok(list.len())
}

#[tauri::command]
async fn read_config(app: tauri::AppHandle) -> Result<String, AppError> {
    use tauri::Manager;
    let dir = app.path().app_config_dir().map_err(|e| std::io::Error::other(e.to_string()))?;
    Ok(tokio::fs::read_to_string(dir.join("config.json")).await?)
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_dialog::init())
        .manage(Notes::default())
        .invoke_handler(tauri::generate_handler![add_note, read_config])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

Rules: async commands run on the async runtime (use them for I/O); sync commands run on the main thread unless declared async. Async commands cannot take borrowed args like &str (use String). Command arguments are camelCase on the JS side by default (#[tauri::command(rename_all = "snake_case")] to change).

Frontend IPC

// v2 path is @tauri-apps/api/core (v1 used @tauri-apps/api/tauri)
import { invoke } from '@tauri-apps/api/core';

export async function addNote(title: string): Promise<number> {
  try {
    return await invoke<number>('add_note', { title });
  } catch (err) {
    throw new Error(`add_note failed for title "${title}": ${String(err)}`);
  }
}

Capabilities & Permissions

// src-tauri/capabilities/default.json
{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "default",
  "description": "Main window permissions",
  "windows": ["main"],
  "permissions": [
    "core:default",
    "dialog:allow-open",
    "fs:allow-read-text-file",
    { "identifier": "fs:scope", "allow": [{ "path": "$APPDATA/**" }] }
  ]
}

Events

use tauri::Emitter;
app.emit("download-progress", 42u32)?;           // to all listeners
import { listen } from '@tauri-apps/api/event';
const unlisten = await listen<number>('download-progress', (e) => setProgress(e.payload));
// call unlisten() on unmount

For high-frequency streams from Rust to JS, use tauri::ipc::Channel<T> as a command argument instead of global events.

Security Settings

Common Plugins (v2)

| Need | Crate / npm |

|------|-------------|

| File system | tauri-plugin-fs / @tauri-apps/plugin-fs |

| Dialogs | tauri-plugin-dialog |

| Shell / open URLs | tauri-plugin-shell, tauri-plugin-opener |

| Persistent key-value | tauri-plugin-store |

| HTTP from Rust | tauri-plugin-http |

| Auto-update | tauri-plugin-updater (signed with tauri signer generate) |

| Single instance | tauri-plugin-single-instance |

Add plugins with npm run tauri add <name> (or cargo tauri add), which wires the crate, npm package and default permission.

Build & Distribution

Tauri vs Electron (short)

| Factor | Tauri | Electron |

|--------|-------|----------|

| Rendering | OS webview (engine differences per OS) | Bundled Chromium (identical everywhere) |

| Binary size | Small (no bundled browser) | Large (Chromium + Node) |

| Backend language | Rust | Node.js |

| Security model | Deny-by-default capabilities | Context isolation + sandbox + preload |

See references/tauri-vs-electron.md.

Anti-patterns

| Anti-pattern | Fix |

|--------------|-----|

| import { invoke } from '@tauri-apps/api/tauri' in v2 | @tauri-apps/api/core |

| Granting fs:default + wide scope for one file | Single allow-* permission + narrow scope |

| Blocking I/O in sync commands | async command + tokio APIs |

| Returning String errors everywhere | Typed error enum implementing Serialize |

| Passing user strings to shell | Rust-side implementation with validation |

Checklist

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.