agentleFS
kevinlinkevinlin/cowork-z/.claude/skills/add-tauri-command/SKILL.md

add-tauri-command

Skill13 starsChanged 4 months agoMITView on GitHub

Use when adding a new Tauri command to Cowork-Z — a new backend capability the React frontend must call, a new `#[tauri::command]` fn, or a new `invoke()` wrapper in tauri-api.ts. Also use when a newly written command returns "Command not found" at runtime.

4 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions4 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 4

    1. openfootmanager/openfootmanager★ 1.2ksame name
    2. Mooshieblob1/MooshieUI★ 225same name
    3. devlint/GitWand★ 198same name
    4. Konadu-Akwasi-Akuoko/katto★ 2same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repositoryOne other file it gives its agents.

The file

Files
SKILL.md

Add a Tauri Command

A command is not usable until it exists in four places. Miss one and it fails at runtime, not at build time — generate_handler! takes any path that compiles, and invoke() takes any string.

The four edits

OrderFileEdit
1src-tauri/src/commands/<domain>.rsthe #[tauri::command] fn
2src-tauri/src/commands/mod.rspub mod <domain>; — only when the file is new
3src-tauri/src/lib.rsone line in tauri::generate_handler![], under the matching // Domain comment
4src/lib/tauri-api.tsthe typed invoke() wrapper

Pick an existing domain file before creating one. There are 22; a new domain is rare.

Step 1 — the command

Copy templates/command.rs. Two shapes: plain, and path-taking.

Any command that accepts a caller-supplied path MUST go through path_guard. The renderer is untrusted — an agent will pass whatever path its model produced. Model it on the validate_path helper at the top of src-tauri/src/commands/files.rs, and validate before any fs:: call, never after.

Return Result<T, String>. T must be Serialize; shared shapes live in src-tauri/src/types.rs.

Step 2 — register

lib.rs groups the handler list by domain with // comments. Add the line to its group, not the end of the list.

Step 3 — the frontend wrapper

Copy templates/wrapper.ts.

Argument names cross the bridge as camelCase in TS, snake_case in Rust — Tauri converts them. invoke('add_workspace', { folderPath }) binds to folder_path: String. Get this wrong and the argument silently arrives empty.

The function name is camelCase; the invoke string is the exact Rust fn name.

New return types go in src/shared/ and must mirror the Rust struct's serde casing (rename_all = "camelCase" on the Rust side).

Step 4 — verify

cd src-tauri && cargo check     # Rust compiles
pnpm typecheck                  # TS compiles

Then check the wiring, which neither compiler sees:

grep -c '<fn_name>' src-tauri/src/lib.rs src/lib/tauri-api.ts   # both must be >= 1

Rust changes need an app restart (pnpm tauri dev); the frontend hot-reloads. Do not report the command as working until you have seen it return in the running app or in a test.

Capabilities

If the command calls a Tauri plugin API (shell, dialog, opener, updater, process), the calling window needs the permission in src-tauri/capabilities/. Those files are protected — do not edit them. Say which permission is needed and which window needs it, and let the user make the change.

Plain Rust (std::fs, rusqlite, reqwest) needs no capability entry.

Tests

Rust: #[cfg(test)] mod tests in the same file, cd src-tauri && cargo test. Pure logic — extract it out of the command body so it is testable without a State.

Frontend: __tests__/ next to the code, pnpm test --run.

Common mistakes

SymptomCause
Command <name> not foundStep 2 skipped — not in generate_handler![]
Argument arrives empty or NonecamelCase/snake_case mismatch between the invoke object and the Rust param
Command compiles, never reachableNew file, no pub mod line in commands/mod.rs
Works in dev, fails on a user's machinePath used without path_guard — outside the sandbox roots
unknown permission at runtimePlugin API called from a window whose capability file does not grant it

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.