pi-rust-skills 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/CONTRIBUTING.md +32 -0
- package/LICENSE +21 -0
- package/README.md +162 -0
- package/SECURITY.md +18 -0
- package/examples/prompts.md +75 -0
- package/extensions/rust-skills.ts +182 -0
- package/package.json +70 -0
- package/references/RUST_AGENT_GUIDE.md +72 -0
- package/references/RUST_COMMANDS.md +69 -0
- package/scripts/list-skills.mjs +47 -0
- package/scripts/validate-skills.mjs +97 -0
- package/skills/rust-async-tokio/SKILL.md +92 -0
- package/skills/rust-build-cross/SKILL.md +54 -0
- package/skills/rust-cli/SKILL.md +113 -0
- package/skills/rust-code-review/SKILL.md +106 -0
- package/skills/rust-crate-publishing/SKILL.md +101 -0
- package/skills/rust-database/SKILL.md +57 -0
- package/skills/rust-debugging/SKILL.md +100 -0
- package/skills/rust-embedded-no-std/SKILL.md +55 -0
- package/skills/rust-ffi/SKILL.md +103 -0
- package/skills/rust-performance/SKILL.md +101 -0
- package/skills/rust-proc-macro/SKILL.md +55 -0
- package/skills/rust-project-bootstrap/SKILL.md +130 -0
- package/skills/rust-refactor-migration/SKILL.md +94 -0
- package/skills/rust-security-audit/SKILL.md +111 -0
- package/skills/rust-testing/SKILL.md +105 -0
- package/skills/rust-toolchain-ci/SKILL.md +102 -0
- package/skills/rust-wasm/SKILL.md +103 -0
- package/skills/rust-web-api/SKILL.md +48 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rust-refactor-migration
|
|
3
|
+
description: Refactors Rust code safely across modules, crates, editions, dependency upgrades, async conversions, error type migrations, API cleanup, and workspace restructuring. Use for planned Rust codebase modernization.
|
|
4
|
+
license: MIT
|
|
5
|
+
compatibility: Rust stable with cargo recommended.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Rust Refactor Migration
|
|
9
|
+
|
|
10
|
+
Use this skill for non-trivial Rust refactors where behavior must stay stable while structure changes.
|
|
11
|
+
|
|
12
|
+
## Workflow
|
|
13
|
+
|
|
14
|
+
1. Inspect `Cargo.toml`, workspace shape, feature flags, target crates, and `rust_project_context` output when available.
|
|
15
|
+
2. Establish baseline validation before changes:
|
|
16
|
+
```bash
|
|
17
|
+
cargo fmt --check
|
|
18
|
+
cargo clippy --workspace --all-targets --all-features -- -D warnings
|
|
19
|
+
cargo test --workspace --all-features
|
|
20
|
+
```
|
|
21
|
+
3. Identify public API and compatibility constraints.
|
|
22
|
+
4. Make refactors in small mechanical steps.
|
|
23
|
+
5. Keep tests passing between steps when possible.
|
|
24
|
+
6. Separate behavior changes from structure changes.
|
|
25
|
+
7. Document migration notes for users or future agents.
|
|
26
|
+
|
|
27
|
+
## Common refactors
|
|
28
|
+
|
|
29
|
+
### Split a large module
|
|
30
|
+
|
|
31
|
+
- Move types first, then functions.
|
|
32
|
+
- Re-export public API from the old module if compatibility matters.
|
|
33
|
+
- Keep visibility narrow: prefer `pub(crate)` over `pub`.
|
|
34
|
+
- Add deprecation notes before removing old public paths unless a breaking change is intended.
|
|
35
|
+
|
|
36
|
+
### Convert binary logic into library logic
|
|
37
|
+
|
|
38
|
+
- Move business logic from `main.rs` into `lib.rs` or modules.
|
|
39
|
+
- Keep CLI parsing and process exit behavior in `main.rs`.
|
|
40
|
+
- Add integration tests against library functions and CLI smoke tests.
|
|
41
|
+
|
|
42
|
+
### Error migration
|
|
43
|
+
|
|
44
|
+
- Replace string errors with typed errors in libraries.
|
|
45
|
+
- Add context at boundaries.
|
|
46
|
+
- Avoid exposing `anyhow::Error` in reusable library APIs unless intentionally application-facing.
|
|
47
|
+
|
|
48
|
+
### Edition migration
|
|
49
|
+
|
|
50
|
+
Use Cargo's migration support:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
cargo fix --edition
|
|
54
|
+
cargo fmt
|
|
55
|
+
cargo test --all-features
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Then manually review changed code for readability.
|
|
59
|
+
|
|
60
|
+
### Dependency upgrade
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
cargo update -p crate_name
|
|
64
|
+
cargo tree -d
|
|
65
|
+
cargo test --all-features
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Review changelog for breaking behavior, not just compiler errors.
|
|
69
|
+
|
|
70
|
+
## API compatibility
|
|
71
|
+
|
|
72
|
+
- Use `cargo semver-checks` when installed for public libraries.
|
|
73
|
+
- Compare docs, exported types, trait bounds, feature flags, and re-exports before and after the refactor.
|
|
74
|
+
- Keep compatibility re-exports until downstream users have a migration path.
|
|
75
|
+
- Stage large migrations as mechanical move, compatibility shim, behavior change, then cleanup.
|
|
76
|
+
|
|
77
|
+
## Refactor safety rules
|
|
78
|
+
|
|
79
|
+
- Do not rewrite working Rust into clever Rust.
|
|
80
|
+
- Prefer explicit intermediate variables when they clarify ownership.
|
|
81
|
+
- Avoid introducing generics unless reuse is proven.
|
|
82
|
+
- Keep public names stable unless a breaking change is requested.
|
|
83
|
+
- If tests are weak, add characterization tests before refactoring.
|
|
84
|
+
- Review dependency changelogs before changing major versions or feature defaults.
|
|
85
|
+
|
|
86
|
+
## Output expectations
|
|
87
|
+
|
|
88
|
+
Summarize baseline status, refactor steps completed, behavior changes if any, validation results, and follow-up cleanup tickets.
|
|
89
|
+
|
|
90
|
+
## Avoid
|
|
91
|
+
|
|
92
|
+
- Do not mix mechanical moves with behavior changes in the same step.
|
|
93
|
+
- Do not remove compatibility shims without calling out the breaking change.
|
|
94
|
+
- Do not accept a green narrow test when public API or workspace behavior changed.
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rust-security-audit
|
|
3
|
+
description: Audits Rust projects for unsafe code, dependency vulnerabilities, secret handling, injection risks, path traversal, deserialization hazards, cryptography misuse, supply-chain risk, and cargo-audit/cargo-deny findings. Use for Rust security reviews.
|
|
4
|
+
license: MIT
|
|
5
|
+
compatibility: Rust stable. Optional tools include cargo-audit, cargo-deny, cargo-geiger, and cargo-vet.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Rust Security Audit
|
|
9
|
+
|
|
10
|
+
Use this skill for Rust security reviews, dependency audits, unsafe-code reviews, and hardening tasks.
|
|
11
|
+
|
|
12
|
+
## Workflow
|
|
13
|
+
|
|
14
|
+
1. Inspect `Cargo.toml`, workspace shape, feature flags, target crates, and `rust_project_context` output when available.
|
|
15
|
+
2. Define the trust boundary: inputs, files, network, environment variables, subprocesses, database queries, and external services.
|
|
16
|
+
3. Inspect `Cargo.lock`, features, build scripts, unsafe code, and parsing/deserialization paths.
|
|
17
|
+
4. Run available security tools.
|
|
18
|
+
5. Review risky code manually; do not rely only on scanners.
|
|
19
|
+
6. Produce findings with severity, exploitability, evidence, and fix.
|
|
20
|
+
|
|
21
|
+
## Commands
|
|
22
|
+
|
|
23
|
+
Use what is available; do not fail the task only because optional tools are missing.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
cargo audit
|
|
27
|
+
cargo deny check
|
|
28
|
+
cargo geiger
|
|
29
|
+
cargo tree -e features
|
|
30
|
+
cargo update -p vulnerable_crate
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Always run core validation after changes:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
cargo fmt --check
|
|
37
|
+
cargo clippy --workspace --all-targets --all-features -- -D warnings
|
|
38
|
+
cargo test --workspace --all-features
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
For package-specific audits, narrow to the affected crate with `-p crate_name` after workspace context is understood.
|
|
42
|
+
|
|
43
|
+
## Threat model
|
|
44
|
+
|
|
45
|
+
| Boundary | Review focus |
|
|
46
|
+
|---|---|
|
|
47
|
+
| Files and paths | Traversal, symlink handling, overwrite rules, temp file safety |
|
|
48
|
+
| Network and HTTP | SSRF, TLS settings, redirects, request size, timeout policy |
|
|
49
|
+
| Environment and config | Secret leakage, unsafe defaults, untrusted config parsing |
|
|
50
|
+
| Subprocesses | Shell injection, inherited environment, argument escaping |
|
|
51
|
+
| Dependencies and build scripts | Vulnerabilities, native code, scripts, maintainer and license risk |
|
|
52
|
+
|
|
53
|
+
## Checklist
|
|
54
|
+
|
|
55
|
+
### Unsafe code
|
|
56
|
+
|
|
57
|
+
- Every unsafe block has a precise safety comment.
|
|
58
|
+
- No unsound aliasing, lifetime extension, or invalid initialization.
|
|
59
|
+
- FFI boundaries validate null pointers and buffer lengths.
|
|
60
|
+
- Unsafe abstractions expose safe APIs that enforce invariants.
|
|
61
|
+
|
|
62
|
+
### Input handling
|
|
63
|
+
|
|
64
|
+
- Validate paths to prevent traversal and unintended overwrite.
|
|
65
|
+
- Treat environment variables and config files as untrusted.
|
|
66
|
+
- Avoid shell injection; prefer `Command::new(program).arg(value)` over shell strings.
|
|
67
|
+
- Bound input size for parsers and decompression.
|
|
68
|
+
|
|
69
|
+
### Secrets
|
|
70
|
+
|
|
71
|
+
- Do not log secrets, tokens, cookies, private keys, or passwords.
|
|
72
|
+
- Use secret-specific types or redaction wrappers when possible.
|
|
73
|
+
- Avoid storing secrets in panic messages, errors, or snapshots.
|
|
74
|
+
- Search for committed secrets and generated fixtures that may contain credentials.
|
|
75
|
+
|
|
76
|
+
### Deserialization
|
|
77
|
+
|
|
78
|
+
- Avoid deserializing untrusted data into overly permissive types.
|
|
79
|
+
- Validate semantic constraints after parsing.
|
|
80
|
+
- Watch for YAML, regex, XML, archive, and compression edge cases.
|
|
81
|
+
|
|
82
|
+
### Crypto
|
|
83
|
+
|
|
84
|
+
- Prefer well-reviewed high-level crates.
|
|
85
|
+
- Avoid custom crypto.
|
|
86
|
+
- Use constant-time comparison for secrets when relevant.
|
|
87
|
+
- Validate randomness source and nonce uniqueness.
|
|
88
|
+
|
|
89
|
+
### Supply chain
|
|
90
|
+
|
|
91
|
+
- Review `build.rs`, proc macros, git dependencies, path dependencies, and broad feature flags.
|
|
92
|
+
- Prefer `cargo-deny` policies for advisories, duplicate versions, licenses, and banned crates.
|
|
93
|
+
- Generate SBOM or dependency inventory when the project or release process requires it.
|
|
94
|
+
|
|
95
|
+
## Finding format
|
|
96
|
+
|
|
97
|
+
```markdown
|
|
98
|
+
### Severity: High - Path traversal allows overwrite outside output directory
|
|
99
|
+
|
|
100
|
+
- Location: `src/archive.rs:42`
|
|
101
|
+
- Evidence: user-controlled archive path is joined without normalization checks
|
|
102
|
+
- Impact: attacker can overwrite arbitrary writable files
|
|
103
|
+
- Fix: reject absolute paths and components containing `..`; canonicalize destination
|
|
104
|
+
- Validation: added regression test and ran `cargo test --all-features`
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Avoid
|
|
108
|
+
|
|
109
|
+
- Do not treat scanner output as complete coverage.
|
|
110
|
+
- Do not silence advisories without documenting exploitability and compensation.
|
|
111
|
+
- Do not add secret values to tests, logs, snapshots, or issue reports.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rust-testing
|
|
3
|
+
description: Designs and implements Rust unit tests, integration tests, doc tests, property tests, snapshot tests, test fixtures, cargo-nextest workflows, and CI validation. Use when adding or improving Rust test coverage.
|
|
4
|
+
license: MIT
|
|
5
|
+
compatibility: Rust stable toolchain with cargo recommended. Optional tools include cargo-nextest, insta, proptest, and tarpaulin.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Rust Testing
|
|
9
|
+
|
|
10
|
+
Use this skill when writing tests, improving test structure, reproducing bugs, or creating a validation plan for a Rust project.
|
|
11
|
+
|
|
12
|
+
## Workflow
|
|
13
|
+
|
|
14
|
+
1. Inspect `Cargo.toml`, workspace shape, feature flags, target crates, and `rust_project_context` output when available.
|
|
15
|
+
2. Identify the behavior contract before writing tests.
|
|
16
|
+
3. Choose the right test type:
|
|
17
|
+
- Unit tests inside modules for small pure logic.
|
|
18
|
+
- Integration tests under `tests/` for public behavior.
|
|
19
|
+
- Doc tests for public APIs and examples.
|
|
20
|
+
- Property tests for parser, serializer, state machine, or invariant-heavy code.
|
|
21
|
+
- Snapshot tests for stable text or structured output.
|
|
22
|
+
- Compile-fail tests for macros, trait errors, and public API guarantees.
|
|
23
|
+
- Concurrency model tests for lock-free or synchronization-heavy code.
|
|
24
|
+
4. Write at least one failing test before fixing a bug when practical.
|
|
25
|
+
5. Keep test data small, explicit, and local to the test.
|
|
26
|
+
6. Validate with all relevant feature flags.
|
|
27
|
+
|
|
28
|
+
## Commands
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
cargo test
|
|
32
|
+
cargo test --all-features
|
|
33
|
+
cargo test --workspace --all-targets
|
|
34
|
+
cargo test -p crate_name --all-features
|
|
35
|
+
cargo test test_name -- --nocapture
|
|
36
|
+
cargo test --doc
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
If `cargo-nextest` is installed:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
cargo nextest run --all-features
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Test design rules
|
|
46
|
+
|
|
47
|
+
- Tests should explain behavior, not implementation details.
|
|
48
|
+
- Prefer descriptive test names like `returns_error_when_config_file_is_missing`.
|
|
49
|
+
- Avoid sleeps in async tests; use controlled clocks, channels, or timeouts.
|
|
50
|
+
- Avoid tests that depend on the user's machine, network, current date, or global state.
|
|
51
|
+
- Use temporary directories for filesystem tests.
|
|
52
|
+
- Keep fixtures minimal and local. Store large reusable fixtures under `tests/fixtures/` with names that explain the scenario.
|
|
53
|
+
- Assert exact errors when the error is part of the contract; otherwise assert stable categories.
|
|
54
|
+
- For snapshots, review diffs before accepting updates and never bless unrelated churn.
|
|
55
|
+
|
|
56
|
+
## Specialized tools
|
|
57
|
+
|
|
58
|
+
- Use `trybuild` for proc macro and compile-fail API tests.
|
|
59
|
+
- Use `loom` for synchronization code where interleavings matter.
|
|
60
|
+
- Use `miri` for unsafe code, aliasing-sensitive logic, and UB checks when it is available.
|
|
61
|
+
- Use `insta` snapshots for stable structured output, not volatile logs.
|
|
62
|
+
|
|
63
|
+
## Async tests
|
|
64
|
+
|
|
65
|
+
For Tokio projects:
|
|
66
|
+
|
|
67
|
+
```rust
|
|
68
|
+
#[tokio::test]
|
|
69
|
+
async fn handles_timeout() {
|
|
70
|
+
// test body
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Use `#[tokio::test(flavor = "multi_thread")]` only when concurrency behavior needs it. Prefer `current_thread` for deterministic tests.
|
|
75
|
+
|
|
76
|
+
Use `tokio::time::pause` and explicit time advancement when timer behavior must be deterministic.
|
|
77
|
+
|
|
78
|
+
## Property tests
|
|
79
|
+
|
|
80
|
+
Use property tests when input space matters more than examples:
|
|
81
|
+
|
|
82
|
+
```rust
|
|
83
|
+
proptest! {
|
|
84
|
+
#[test]
|
|
85
|
+
fn round_trips(value in any::<u32>()) {
|
|
86
|
+
let encoded = encode(value);
|
|
87
|
+
prop_assert_eq!(decode(&encoded).unwrap(), value);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Output expectations
|
|
93
|
+
|
|
94
|
+
When finished, report:
|
|
95
|
+
|
|
96
|
+
- Test cases added.
|
|
97
|
+
- Bug or behavior each test protects.
|
|
98
|
+
- Commands run and pass/fail status.
|
|
99
|
+
- Coverage gaps that remain.
|
|
100
|
+
|
|
101
|
+
## Avoid
|
|
102
|
+
|
|
103
|
+
- Do not add sleeps, real network calls, or machine-dependent paths unless the behavior under test requires them.
|
|
104
|
+
- Do not broaden assertions until failures stop being useful.
|
|
105
|
+
- Do not update snapshots without explaining the intended behavior change.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rust-toolchain-ci
|
|
3
|
+
description: Configures Rust toolchains, rust-toolchain.toml, cargo aliases, rustfmt, clippy lint policy, GitHub Actions, caching, cross-platform CI, MSRV checks, and release validation. Use for Rust project automation and CI setup.
|
|
4
|
+
license: MIT
|
|
5
|
+
compatibility: Rust stable with cargo. CI examples target GitHub Actions but can be adapted.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Rust Toolchain CI
|
|
9
|
+
|
|
10
|
+
Use this skill when setting up Rust automation, linting policy, formatting, MSRV checks, and CI workflows.
|
|
11
|
+
|
|
12
|
+
## Workflow
|
|
13
|
+
|
|
14
|
+
1. Inspect `Cargo.toml`, workspace shape, feature flags, target crates, and `rust_project_context` output when available.
|
|
15
|
+
2. Inspect the project's supported Rust version, edition, targets, and workspace shape.
|
|
16
|
+
3. Decide whether to pin Rust with `rust-toolchain.toml`.
|
|
17
|
+
4. Add consistent local commands via docs or Cargo aliases.
|
|
18
|
+
5. Add CI that matches local validation.
|
|
19
|
+
6. Keep CI fast enough that developers will trust it.
|
|
20
|
+
|
|
21
|
+
## rust-toolchain.toml
|
|
22
|
+
|
|
23
|
+
```toml
|
|
24
|
+
[toolchain]
|
|
25
|
+
channel = "stable"
|
|
26
|
+
components = ["rustfmt", "clippy"]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Use a specific version only when MSRV or reproducibility matters:
|
|
30
|
+
|
|
31
|
+
```toml
|
|
32
|
+
[toolchain]
|
|
33
|
+
channel = "1.85.0"
|
|
34
|
+
components = ["rustfmt", "clippy"]
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Cargo aliases
|
|
38
|
+
|
|
39
|
+
`.cargo/config.toml`:
|
|
40
|
+
|
|
41
|
+
```toml
|
|
42
|
+
[alias]
|
|
43
|
+
xtask = "run --package xtask --"
|
|
44
|
+
ci-check = "check --workspace --all-targets --all-features"
|
|
45
|
+
ci-test = "test --workspace --all-features"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## GitHub Actions baseline
|
|
49
|
+
|
|
50
|
+
```yaml
|
|
51
|
+
name: CI
|
|
52
|
+
|
|
53
|
+
on:
|
|
54
|
+
push:
|
|
55
|
+
branches: [main]
|
|
56
|
+
pull_request:
|
|
57
|
+
|
|
58
|
+
jobs:
|
|
59
|
+
rust:
|
|
60
|
+
strategy:
|
|
61
|
+
fail-fast: false
|
|
62
|
+
matrix:
|
|
63
|
+
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
64
|
+
runs-on: ${{ matrix.os }}
|
|
65
|
+
permissions:
|
|
66
|
+
contents: read
|
|
67
|
+
steps:
|
|
68
|
+
- uses: actions/checkout@v4
|
|
69
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
70
|
+
with:
|
|
71
|
+
components: rustfmt, clippy
|
|
72
|
+
- uses: Swatinem/rust-cache@v2
|
|
73
|
+
- run: cargo fmt --check
|
|
74
|
+
- run: cargo clippy --workspace --all-targets --all-features -- -D warnings
|
|
75
|
+
- run: cargo test --workspace --all-features
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
For cross-platform projects, add a matrix for `ubuntu-latest`, `windows-latest`, and `macos-latest`.
|
|
79
|
+
|
|
80
|
+
For Pi packages or mixed Node/Rust repositories, include package validation such as `npm test`, `npm run list`, or `npm pack --dry-run` in a separate Node job.
|
|
81
|
+
|
|
82
|
+
## CI policy
|
|
83
|
+
|
|
84
|
+
- Set minimal permissions, usually `contents: read`.
|
|
85
|
+
- Cache Cargo dependencies with keys that include OS, toolchain, and lockfile.
|
|
86
|
+
- Add a docs job with `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --workspace --all-features` for libraries.
|
|
87
|
+
- Add optional audit jobs with `cargo audit` or `cargo deny check` when the project has the tool config.
|
|
88
|
+
- Keep MSRV checks focused on `cargo check` unless old clippy behavior is part of the policy.
|
|
89
|
+
|
|
90
|
+
## MSRV
|
|
91
|
+
|
|
92
|
+
If the crate declares `rust-version`, add a separate MSRV job. Keep MSRV checks focused; do not require clippy on old compilers unless necessary.
|
|
93
|
+
|
|
94
|
+
## Output expectations
|
|
95
|
+
|
|
96
|
+
Explain local commands, CI jobs, caching choices, MSRV policy, and any follow-up release automation.
|
|
97
|
+
|
|
98
|
+
## Avoid
|
|
99
|
+
|
|
100
|
+
- Do not make CI stricter than documented local commands without explaining the policy.
|
|
101
|
+
- Do not run privileged tokens or write permissions on pull request checks unless required.
|
|
102
|
+
- Do not hide flaky tests by allowing failures in the required validation path.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rust-wasm
|
|
3
|
+
description: Builds Rust WebAssembly projects with wasm-pack, wasm-bindgen, web-sys, js-sys, browser or Node targets, bundler integration, size optimization, and wasm tests. Use for Rust code compiled to WebAssembly.
|
|
4
|
+
license: MIT
|
|
5
|
+
compatibility: Rust stable with wasm32 target. Optional tools include wasm-pack, wasm-bindgen-cli, trunk, and wasm-opt.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Rust WASM
|
|
9
|
+
|
|
10
|
+
Use this skill for Rust projects targeting WebAssembly for browser apps, Node packages, plugin sandboxes, or shared computational modules.
|
|
11
|
+
|
|
12
|
+
## Workflow
|
|
13
|
+
|
|
14
|
+
1. Inspect `Cargo.toml`, workspace shape, feature flags, target crates, and `rust_project_context` output when available.
|
|
15
|
+
2. Confirm target environment: browser, Node, bundler, no-bundler, WASI, or embedded runtime.
|
|
16
|
+
3. Add the correct crate type:
|
|
17
|
+
```toml
|
|
18
|
+
[lib]
|
|
19
|
+
crate-type = ["cdylib", "rlib"]
|
|
20
|
+
```
|
|
21
|
+
4. Keep the core logic platform-neutral. Put browser bindings behind a thin `wasm-bindgen` layer.
|
|
22
|
+
5. Minimize boundary crossings between JavaScript and Rust.
|
|
23
|
+
6. Validate both native tests for core logic and wasm-specific tests for bindings.
|
|
24
|
+
|
|
25
|
+
## Common setup
|
|
26
|
+
|
|
27
|
+
```toml
|
|
28
|
+
[dependencies]
|
|
29
|
+
wasm-bindgen = "0.2"
|
|
30
|
+
|
|
31
|
+
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
|
32
|
+
js-sys = "0.3"
|
|
33
|
+
web-sys = { version = "0.3", features = ["console"] }
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Add target:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
rustup target add wasm32-unknown-unknown
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Build with wasm-pack:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
wasm-pack build --target web
|
|
46
|
+
wasm-pack build --target bundler
|
|
47
|
+
wasm-pack build --target nodejs
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Choose `web` for browser-native loading, `bundler` for Vite/Webpack/Rollup packages, and `nodejs` for Node consumers and CI tests.
|
|
51
|
+
|
|
52
|
+
## Design rules
|
|
53
|
+
|
|
54
|
+
- Avoid exposing complex Rust lifetimes across the wasm boundary.
|
|
55
|
+
- Prefer simple structs, strings, numbers, typed arrays, and serialized data at the boundary.
|
|
56
|
+
- Keep panics visible during development with `console_error_panic_hook` when appropriate.
|
|
57
|
+
- Watch binary size. Review dependencies, feature flags, and `wee_alloc` only if justified.
|
|
58
|
+
- Avoid assuming browser APIs exist in Node or test environments.
|
|
59
|
+
- Generate TypeScript declarations when publishing JS-facing packages.
|
|
60
|
+
- Keep feature gates clear for native-only and wasm-only dependencies.
|
|
61
|
+
|
|
62
|
+
## Testing
|
|
63
|
+
|
|
64
|
+
Native core tests:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
cargo test
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
WASM tests with wasm-pack:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
wasm-pack test --node
|
|
74
|
+
wasm-pack test --headless --firefox
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Use `wasm-bindgen-test` for binding behavior and native `cargo test` for platform-neutral logic.
|
|
78
|
+
|
|
79
|
+
## Optimization
|
|
80
|
+
|
|
81
|
+
For release builds:
|
|
82
|
+
|
|
83
|
+
```toml
|
|
84
|
+
[profile.release]
|
|
85
|
+
opt-level = "z"
|
|
86
|
+
lto = true
|
|
87
|
+
codegen-units = 1
|
|
88
|
+
panic = "abort"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Use `wasm-opt` only after confirming it is installed and appropriate for the pipeline.
|
|
92
|
+
|
|
93
|
+
Set a size budget when package size matters, and compare the generated `.wasm` artifact before and after dependency or profile changes.
|
|
94
|
+
|
|
95
|
+
## Output expectations
|
|
96
|
+
|
|
97
|
+
State the selected wasm target, JS integration path, files changed, build/test commands, and any size or compatibility tradeoffs.
|
|
98
|
+
|
|
99
|
+
## Avoid
|
|
100
|
+
|
|
101
|
+
- Do not expose complex lifetimes or Rust-only types across the JS boundary.
|
|
102
|
+
- Do not assume browser APIs in Node targets or CI.
|
|
103
|
+
- Do not add wasm size optimizations before measuring the artifact.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rust-web-api
|
|
3
|
+
description: Builds and reviews Rust web APIs with Axum, Actix Web, Hyper, routing, extractors, middleware, request validation, auth boundaries, OpenAPI, graceful shutdown, and HTTP integration tests. Use for Rust server and web service work.
|
|
4
|
+
license: MIT
|
|
5
|
+
compatibility: Rust stable. Common stacks include Axum, Actix Web, Hyper, Tower, Tokio, Serde, and utoipa.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Rust Web API
|
|
9
|
+
|
|
10
|
+
Use this skill when creating, changing, testing, or reviewing Rust HTTP APIs and services.
|
|
11
|
+
|
|
12
|
+
## Workflow
|
|
13
|
+
|
|
14
|
+
1. Inspect `Cargo.toml`, workspace shape, feature flags, target crates, and `rust_project_context` output when available.
|
|
15
|
+
2. Identify the API contract: routes, methods, request and response schemas, auth, errors, and compatibility expectations.
|
|
16
|
+
3. Keep transport concerns near the router and business logic in testable modules.
|
|
17
|
+
4. Add integration tests for happy paths, validation errors, auth failures, and shutdown behavior.
|
|
18
|
+
5. Validate with workspace-aware cargo commands and any service-specific tests.
|
|
19
|
+
|
|
20
|
+
## Design rules
|
|
21
|
+
|
|
22
|
+
- Prefer explicit typed extractors and response types over ad hoc JSON maps.
|
|
23
|
+
- Validate request size, content type, path/query parameters, and semantic constraints.
|
|
24
|
+
- Keep auth and authorization boundaries visible in middleware or extractors.
|
|
25
|
+
- Use structured errors that map predictably to HTTP status codes and response bodies.
|
|
26
|
+
- Add tracing spans for request IDs, route names, latency, and error classification.
|
|
27
|
+
- Document public APIs with OpenAPI only when consumers need a stable contract.
|
|
28
|
+
- Implement graceful shutdown for long-running services and background tasks.
|
|
29
|
+
|
|
30
|
+
## Testing
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
cargo test --workspace --all-features
|
|
34
|
+
cargo test -p crate_name --test api
|
|
35
|
+
cargo clippy --workspace --all-targets --all-features -- -D warnings
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Test handlers through the router when possible. Use real HTTP only when socket behavior, TLS, middleware layers, or deployment wiring matters.
|
|
39
|
+
|
|
40
|
+
## Avoid
|
|
41
|
+
|
|
42
|
+
- Do not put database, auth, and business logic directly in route handlers.
|
|
43
|
+
- Do not return inconsistent error shapes for the same API.
|
|
44
|
+
- Do not log tokens, cookies, request bodies with secrets, or authorization headers.
|
|
45
|
+
|
|
46
|
+
## Output expectations
|
|
47
|
+
|
|
48
|
+
Report the API contract changed, routes affected, validation commands, and any compatibility or auth implications.
|