---
name: using-rusty
description: Hard routing gate before any Rust/Leptos/Axum/SQLx code generation, review, or modification. Auto-triggers on every related topic.
---

<EXTREMELY-IMPORTANT>
You MUST invoke the appropriate rusty skill(s) BEFORE writing, editing,
reviewing, or discussing any Rust, Leptos, Axum, or SQLx code. This applies without
exception to:
- Generating any .rs file, Cargo.toml, migration .sql, or .sqlx/ cache file
- Reviewing existing Rust code for any dimension (quality, security, performance, patterns)
- Debugging Rust compile errors, runtime panics, or hydration mismatches
- Scaffolding a project or adding a module

DO NOT write code first and invoke the skill "to check". Invoke FIRST. Then write.
DO NOT rationalize skipping the skill because "it's a small change" or "I already know
the pattern." The scan detects project-specific style; your training data does not.
</EXTREMELY-IMPORTANT>

---

## The Rule

Every action involving Rust+Leptos+Axum+SQLx code routes through this table. Find the
user's intent, invoke the listed skill(s), and only then proceed.

### Skill Routing Table

| User Intent | Primary Skill(s) | Agent(s) |
|---|---|---|
| Create entity / DB table | `sqlx-query`, `sqlx-types`, `dto-domain` | `sqlx-entity`, `migration` |
| Add migration | `sqlx-migrations`, `sqlx-types` | `migration` |
| Add page (read-only) | `leptos-component`, `leptos-data-loading` | `leptos-page` |
| Add page with form | `leptos-action-form`, `leptos-server-fn` | `leptos-page`, `leptos-form` |
| Add form only | `leptos-action-form`, `leptos-server-fn` | `leptos-form` |
| Add data table | `leptos-data-loading`, `leptos-component` | `leptos-data-table` |
| Add server function | `leptos-server-fn`, `rust-error-handling` | `server-fn` |
| Add Axum handler | `axum-handler` | `axum-handler` |
| Add WebSocket endpoint | `axum-websocket` | `websocket` |
| Add background / scheduled job | `background-jobs` | `background-job` |
| Add auth | `auth-session` | `auth-scaffold` |
| Add SQLx query | `sqlx-query`, `sqlx-offline` | (inline in sqlx-entity) |
| Add error type / variant | `rust-error-handling`, `leptos-error-handling` | (inline) |
| Scaffold new project | `workspace-architecture`, `cargo-leptos-config` | `project-leptos-axum` |
| Scaffold workspace | `workspace-architecture` | `project-leptos-workspace` |
| Add domain module | `dto-domain`, `rust-error-handling` | `module-domain` |
| Review code quality | `quality-gates` | `code-quality` |
| Review security | `quality-gates` | `security` |
| Review performance | `quality-gates` | `performance` |
| Review patterns | `quality-gates` | `patterns-compliance` |
| Review hydration | `leptos-hydration-discipline` | `hydration` |
| Review correctness / idioms / bug-detection | `rust-panic-vs-result`, `rust-concurrency`, `rust-unsafe`, `rust-ownership-borrowing`, `rust-pattern-matching` | `rust-correctness` |
| Fix bug / compile error | `debug` | `error-diagnosis` |
| Fix hydration mismatch | `leptos-hydration-discipline`, `debug` | `hydration-mismatch` |
| Batch compiler errors | `batch-error-resolution` | `error-diagnosis` |
| Profile / optimize async | `quality-gates` | `performance-profiling`, `optimize/performance` |
| Optimize WASM bundle | `leptos-islands` | `wasm-bundle` |
| Optimize queries | `sqlx-query`, `sqlx-errors` | `query-optimization` |
| Analyze codebase | `rust-codebase-scanning` | `codebase` |
| Run quality gates | `quality-gates` | (direct skill invocation) |
| Generate fullstack entity | (all relevant skills — see orchestration.md) | all generate/ agents |
| Ownership / borrow / move / clone errors (E0382/E0499/E0502/E0505) | `rust-ownership-borrowing` | `rust-correctness` |
| Lifetime errors (E0106/E0515/E0597) | `rust-lifetimes` | `rust-correctness` |
| Concurrency / Send-Sync / lock-across-await / deadlock | `rust-concurrency` | `rust-correctness` |
| Rc/Arc/RefCell/Weak / cycles / interior mutability | `rust-smart-pointers` | `rust-correctness` |
| Traits / generics / dyn / impl Trait / From-Into | `rust-traits-generics` | `rust-correctness` |
| match / enum / if-let / let-else / exhaustiveness | `rust-pattern-matching` | `rust-correctness` |
| panic / unwrap / expect / Result / ? / error philosophy | `rust-panic-vs-result`, `rust-error-handling` | `rust-correctness` |
| Iterators / closures / Fn-FnMut-FnOnce | `rust-iterators-closures` | `rust-correctness` |
| Vec / String / HashMap / collections | `rust-collections` | `rust-correctness` |
| Writing tests / #[test] / TDD | `rust-testing` | `rust-correctness` |
| unsafe / raw pointer / transmute / FFI | `rust-unsafe` | `rust-correctness` |

---

## Rust Language Correctness Layer

<EXTREMELY-IMPORTANT>
Eleven Book-grounded correctness skills back the `/rusty:review correctness` agent and
auto-trigger on matching constructs. Each ships grep detectors that surface real bugs —
not style suggestions. Invoke the relevant skill BEFORE writing code in that area.
</EXTREMELY-IMPORTANT>

| Trigger (what you are about to write or the error you see) | Correctness Skill |
|---|---|
| Move / borrow / clone / E0382 / E0499 / E0502 / E0505 | `rust-ownership-borrowing` |
| Lifetime annotation / `'static` / E0106 / E0515 / E0597 | `rust-lifetimes` |
| `Mutex` / `RwLock` / `Arc` / `Send` / `Sync` / lock-across-`.await` | `rust-concurrency` |
| `Rc` / `RefCell` / `Weak` / interior mutability / cycle | `rust-smart-pointers` |
| `trait` / `impl Trait` / `dyn Trait` / generics / `From`/`Into` | `rust-traits-generics` |
| `match` / `if let` / `let else` / exhaustiveness / `enum` | `rust-pattern-matching` |
| `unwrap()` / `expect()` / `panic!` / `?` / `Result` philosophy | `rust-panic-vs-result` |
| Iterator chains / closures / `Fn` / `FnMut` / `FnOnce` | `rust-iterators-closures` |
| `Vec` / `String` / `HashMap` / `BTreeMap` / capacity | `rust-collections` |
| `#[test]` / `#[cfg(test)]` / TDD / test helpers | `rust-testing` |
| `unsafe` / raw pointer / `transmute` / FFI | `rust-unsafe` |

These skills auto-trigger from the `prompt-scan` hook when language-construct keywords
appear in a prompt. They are also chained by the `rust-correctness` review agent
(`/rusty:review correctness`).

---

## 4-Step Hard Gate

Every agent in this plugin MUST execute these 4 steps before generating code:

### Step 1 — DETECT
Identify the user's intent from their message. Map it to one row in the routing table above.
If intent is ambiguous, ask one clarifying question before proceeding.

### Step 2 — MATCH
Select the primary skill(s) from the routing table for the detected intent.
If multiple skills match, invoke the most specific one first.

### Step 3 — INVOKE
Call the matched skill(s) using the Skill tool:
```
Skill: rusty:<skill-name>
```
Do not generate code before this step completes.

### Step 4 — SCAN
Confirm `rust-codebase-scanning` has run in this session (check for scan cache at
`$CLAUDE_PLUGIN_DATA/scan-<session_id>.json`, or for a prior `Skill: rust-codebase-scanning`
call in the transcript). If not: invoke it now.
```
Skill: rusty:rust-codebase-scanning
```
Only after SCAN completes may generation proceed.

---

## Rationalization Prevention

The following rationalizations are explicitly forbidden. If you catch yourself thinking
any of these, stop and invoke the correct skill.

| Rationalization | Why It Fails |
|---|---|
| "It's just a small change, I know the pattern" | Project style deviates from defaults constantly. The scan catches this. |
| "I'll just write idiomatic Rust" | "Idiomatic" for this project is defined by the scan, not by general knowledge. |
| "The skill is overkill for this" | The skill is not overkill. It takes seconds and prevents hours of debugging. |
| "I'll invoke the skill after writing to double-check" | The skill must run BEFORE writing. Post-check is review, not discipline. |
| "This is a hydration fix, not generation" | Hydration fixes touch `.rs` files. Use `leptos-hydration-discipline` first. |
| "cargo sqlx prepare is optional" | It is never optional. Stale `.sqlx/` cache causes CI failures. |
| "I can skip quality-gates for a quick fix" | No fix is small enough to bypass quality-gates. The stop-gate hook enforces this. |
| "I know Leptos 0.8 from training" | Primary-source patterns (especially hydration, islands, blocking resources) change between minor versions. Always check. |

---

## Automatic Post-Generation Chaining

After any code generation completes, the following chain fires automatically:

```
1. Skill: rusty:review/patterns-compliance
   (run on every .rs file written in this session)
2. If violations found: fix them (do not declare done)
3. Skill: rusty:quality-gates
   (full suite: fmt, clippy ssr+hydrate, check, sqlx prepare --check, migration lint,
    hydration lint, patterns review, cargo audit)
4. If quality-gates pass: present results to user
5. If quality-gates fail: surface failures, wait for user fix, then re-run from step 3
```

The chain is not optional. An agent that writes code and then says "done" without
completing steps 1–4 has violated the lifecycle.

---

## Codebase Scanning Mandate

`rust-codebase-scanning` MUST run before the first code generation of any session.

Purpose: it reads the project's actual style — not what the skills say is correct in
theory, but what this project has established. The scan output overrides skill defaults:
- If the project uses `GetJson` encoding for server fns, generate `GetJson` (not `PostUrl`).
- If the project omits audit fields on entities, don't add them.
- If the project uses `type alias` error wrapping instead of a custom enum, follow that.

The scan cache is valid for the session. If the user makes structural changes (adds new
feature, renames modules), advise re-running:
```
Skill: rusty:rust-codebase-scanning
```

---

## Skill Priority: superpowers vs rusty

| Domain | Use superpowers skill | Use rusty skill |
|---|---|---|
| Planning a multi-step implementation | `superpowers:writing-plans` | — |
| Executing a written plan | `superpowers:executing-plans` | — |
| Brainstorming features | `superpowers:brainstorming` | — |
| TDD cycle | `superpowers:test-driven-development` | — |
| Generating Rust code | — | `using-rusty` (this skill) |
| Code review | `superpowers:requesting-code-review` for PR-level | `quality-gates` for code-quality |
| Debugging | — | `debug` skill |
| Verifying completeness | `superpowers:verification-before-completion` | `quality-gates` |

When both could apply (e.g., a plan involves Rust code): invoke superpowers skill for
planning/orchestration, then invoke the rusty routing skill for each
Rust-specific step.
