victauri-plugin 0.10.0

Tauri plugin for Victauri — embedded MCP server with full-stack introspection
Documentation
//! Build script that generates the Tauri command allowlist.

const COMMANDS: &[&str] = &[
    "victauri_eval_js",
    "victauri_eval_callback",
    "victauri_get_window_state",
    "victauri_list_windows",
    "victauri_get_ipc_log",
    "victauri_get_registry",
    "victauri_get_memory_stats",
    "victauri_dom_snapshot",
    "victauri_verify_state",
    "victauri_detect_ghost_commands",
    "victauri_check_ipc_integrity",
];

fn main() {
    // The permission manifest is read by the app's `tauri-build`, so it must come from the
    // `tauri-plugin` of the same major.
    #[cfg(feature = "tauri-v3")]
    tauri3::build();
    #[cfg(not(feature = "tauri-v3"))]
    tauri_plugin::Builder::new(COMMANDS).build();
}

#[cfg(feature = "tauri-v3")]
mod tauri3 {
    use std::path::{Path, PathBuf};

    /// Tauri 3's plugin build step rewrites `permissions/` in place: it deletes
    /// `autogenerated/commands` (Tauri 3 lists commands in `OUT_DIR` instead) and rewrites
    /// `schemas/schema.json` in the Tauri 3 format. In a checkout that also builds against Tauri 2
    /// that dirties tracked files on every Tauri 3 build. So it runs over a copy of the
    /// hand-written permission files staged in `OUT_DIR`. Its outputs are unaffected: the
    /// permission file list it hands the app's `tauri-build` holds canonicalized paths, and its
    /// `rerun-if-changed=permissions` is resolved against this package, i.e. the real directory.
    pub fn build() {
        let manifest_dir =
            PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"));
        let stage =
            PathBuf::from(std::env::var_os("OUT_DIR").expect("OUT_DIR")).join("tauri3-plugin-root");
        let staged_permissions = stage.join("permissions");
        // A stale stage could still hold a permission file deleted from the source tree.
        let _ = std::fs::remove_dir_all(&staged_permissions);
        copy_hand_written(&manifest_dir.join("permissions"), &staged_permissions)
            .expect("stage the plugin permission files for the Tauri 3 build");
        std::env::set_current_dir(&stage).expect("enter the staged plugin root");
        tauri_plugin_v3::Builder::new(super::COMMANDS).build();
    }

    /// Copy `from` to `to`, leaving out the generated `autogenerated/` and `schemas/` folders.
    fn copy_hand_written(from: &Path, to: &Path) -> std::io::Result<()> {
        std::fs::create_dir_all(to)?;
        for entry in std::fs::read_dir(from)? {
            let entry = entry?;
            let name = entry.file_name();
            let target = to.join(&name);
            if entry.file_type()?.is_dir() {
                if name != "autogenerated" && name != "schemas" {
                    copy_hand_written(&entry.path(), &target)?;
                }
            } else {
                std::fs::copy(entry.path(), target)?;
            }
        }
        Ok(())
    }
}