agent-workflow-kit-cli 1.3.2 → 1.3.4
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/dist/cli/commands/add.js +3 -1
- package/dist/cli/commands/doctor.js +145 -47
- package/dist/cli/commands/init.js +6 -0
- package/dist/core/analyzer.js +70 -0
- package/dist/core/detector.js +22 -0
- package/package.json +1 -1
- package/templates/common/AGENTS.md.hbs +4 -0
- package/templates/common/GLOBAL_RULES.md +101 -0
- package/templates/devops/AGENTS.md.hbs +32 -0
- package/templates/devops/skills/devops/SKILL.md +477 -0
- package/templates/diagram/AGENTS.md.hbs +30 -0
- package/templates/diagram/skills/drawio-diagram/SKILL.md +427 -0
- package/templates/dotnet/AGENTS.md.hbs +38 -34
- package/templates/dotnet/rules/api-structure.md +15 -15
- package/templates/dotnet/rules/csharp-style.md +17 -17
- package/templates/dotnet/rules/dependency-injection.md +12 -12
- package/templates/dotnet/rules/error-handling-validation.md +15 -15
- package/templates/dotnet/skills/dotnet-controller/SKILL.md +16 -16
- package/templates/express/AGENTS.md.hbs +37 -33
- package/templates/express/rules/error-handling.md +18 -18
- package/templates/express/rules/express-style.md +19 -19
- package/templates/express/rules/router-controller.md +16 -16
- package/templates/express/skills/express-endpoint/SKILL.md +14 -14
- package/templates/fastapi/AGENTS.md.hbs +25 -3
- package/templates/fastapi/rules/api-testing.md +24 -0
- package/templates/fastapi/rules/database-async.md +26 -0
- package/templates/golang/AGENTS.md.hbs +42 -0
- package/templates/golang/rules/concurrency.md +71 -0
- package/templates/golang/rules/error-handling.md +42 -0
- package/templates/golang/rules/golang-style.md +24 -0
- package/templates/golang/rules/project-layout.md +39 -0
- package/templates/golang/skills/golang-db/SKILL.md +27 -0
- package/templates/golang/skills/golang-feature/SKILL.md +42 -0
- package/templates/nestjs/AGENTS.md.hbs +33 -29
- package/templates/nestjs/rules/module-architecture.md +14 -14
- package/templates/nestjs/rules/nestjs-style.md +12 -12
- package/templates/nestjs/rules/validation-errors.md +15 -15
- package/templates/nestjs/skills/nestjs-module/SKILL.md +15 -15
- package/templates/next-js/AGENTS.md.hbs +39 -35
- package/templates/next-js/rules/data-fetching-mutations.md +17 -17
- package/templates/next-js/rules/next-style.md +17 -17
- package/templates/next-js/rules/seo-metadata.md +18 -18
- package/templates/next-js/rules/server-client-components.md +17 -17
- package/templates/next-js/skills/next-feature/SKILL.md +16 -16
- package/templates/rust/AGENTS.md.hbs +41 -0
- package/templates/rust/rules/error-handling.md +36 -0
- package/templates/rust/rules/memory-concurrency.md +47 -0
- package/templates/rust/rules/project-layout.md +49 -0
- package/templates/rust/rules/rust-style.md +26 -0
- package/templates/rust/skills/rust-db/SKILL.md +27 -0
- package/templates/rust/skills/rust-feature/SKILL.md +34 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Memory Management & Concurrency in Rust
|
|
2
|
+
|
|
3
|
+
This document details conventions for lifetimes, smart pointer usage, and async Tokio runtime operations.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ⏳ Lifetime Annotations ('a)
|
|
8
|
+
- When a struct or function references a borrowing context, annotate lifetimes explicitly to guarantee spatial memory safety:
|
|
9
|
+
```rust
|
|
10
|
+
pub struct TokenValidator<'a> {
|
|
11
|
+
pub secret_key: &'a str,
|
|
12
|
+
}
|
|
13
|
+
```
|
|
14
|
+
- Avoid bypassing the borrow checker with unnecessary `.clone()` calls or `'static` lifetime modifiers if the scope can be expressed with valid lifetime relationships.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 🧠 Smart Pointer Matrix
|
|
19
|
+
Select the correct smart pointer types according to the allocation scope:
|
|
20
|
+
|
|
21
|
+
| Smart Pointer | Environment | Memory Allocation Characteristics | Application Use Case |
|
|
22
|
+
| :--- | :--- | :--- | :--- |
|
|
23
|
+
| **`Box<T>`** | Single / Multi-thread | Allocates large types on the Heap | Flattens recursive data structures (Sized types) |
|
|
24
|
+
| **`Rc<T>`** | Single-thread Only | Reference count without thread safety | Shares immutable data across a single-threaded runtime |
|
|
25
|
+
| **`Arc<T>`** | Multi-thread | Thread-safe Reference Count (Atomic) | Shares immutable resources across thread pools (e.g., Web Server) |
|
|
26
|
+
| **`RefCell<T>`** | Single-thread Only | Interior Mutability (Checked at Runtime) | Mutates fields inside an immutable single-threaded struct |
|
|
27
|
+
| **`Mutex<T>`** | Multi-thread | Thread safety via OS or runtime lock | Protects mutable resources shared across multiple threads |
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 🚦 Async Runtime (Tokio) CPU vs I/O Bound Tasks
|
|
32
|
+
Blocking the executor threads in an async environment will starve the thread pool, degrading throughput.
|
|
33
|
+
- **I/O Bound Tasks:** (DB Queries, Async file read/write, HTTP calls). Use standard `async/await` syntax.
|
|
34
|
+
- **CPU Bound Tasks:** (Password hashing, image processing, complex computations). Never run these directly in the async thread pool. Use `tokio::task::spawn_blocking`:
|
|
35
|
+
```rust
|
|
36
|
+
let hashed_password = tokio::task::spawn_blocking(move || {
|
|
37
|
+
bcrypt::hash(password, bcrypt::DEFAULT_COST)
|
|
38
|
+
})
|
|
39
|
+
.await
|
|
40
|
+
.unwrap()?;
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## 🔒 Send + Sync Traits & MutexGuard Safety
|
|
46
|
+
- Shared items sent across task boundaries (`tokio::spawn`) must implement `Send` and `Sync`.
|
|
47
|
+
- **MutexGuard across Await:** Never hold a non-thread-safe guard (like `std::sync::MutexGuard`) across `.await` points. Doing so will lead to compilation errors or runtime deadlocks. If a lock must span an await point, use `tokio::sync::Mutex`.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Rust Crate Layout & Modular Architecture
|
|
2
|
+
|
|
3
|
+
This document defines module structures, visibility scopes, Cargo Workspace configurations, and dependency injection in Rust.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🏗️ Modules & Crate Separation
|
|
8
|
+
- **Separating Binary & Library:**
|
|
9
|
+
- `src/main.rs`: Entrypoint of the binary application. Responsible only for parsing arguments, reading configuration, and starting the runtime.
|
|
10
|
+
- `src/lib.rs`: Holds 100% of the core business logic, enabling testability and decoupling.
|
|
11
|
+
- **Visibility Scope Control:** Do not expose symbols using `pub` indiscriminately. Prefer `pub(crate)` to limit access to within the same crate, maintaining strict encapsulation.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 📦 Cargo Workspaces (Multi-Crate Monorepos)
|
|
16
|
+
For large monorepo systems, split the project into a Cargo Workspace containing isolated crates to enable parallel compilation:
|
|
17
|
+
```toml
|
|
18
|
+
# Cargo.toml at the root directory
|
|
19
|
+
[workspace]
|
|
20
|
+
members = [
|
|
21
|
+
"crates/api-gateway",
|
|
22
|
+
"crates/user-domain",
|
|
23
|
+
"crates/core-engine",
|
|
24
|
+
"crates/shared-utils"
|
|
25
|
+
]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 💉 Trait-Based Dependency Injection (DI)
|
|
31
|
+
Due to Rust's strict lifetimes and borrow checker, decouple dependencies by implementing **Traits** combined with thread-safe smart pointers: `Arc<dyn Trait + Send + Sync>`.
|
|
32
|
+
```rust
|
|
33
|
+
use std::sync::Arc;
|
|
34
|
+
|
|
35
|
+
pub trait UserRepository: Send + Sync {
|
|
36
|
+
fn find_by_id(&self, id: i64) -> Result<User, AppError>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
pub struct UserService {
|
|
40
|
+
// Thread-safe pointer to dynamic trait implementation
|
|
41
|
+
repo: Arc<dyn UserRepository>,
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
impl UserService {
|
|
45
|
+
pub fn new(repo: Arc<dyn UserRepository>) -> Self {
|
|
46
|
+
Self { repo }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Idiomatic Rust Style & Optimization
|
|
2
|
+
|
|
3
|
+
This document outlines standard conventions for writing idiomatic Rust code, optimizing borrowing, and complying with Clippy.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🦀 Idiomatic Rust Conventions
|
|
8
|
+
- **Pattern Matching:** Leverage Pattern Matching (`match`, `if let`, `let-else`) instead of deep nested `if/else` checks to handle control flow safely.
|
|
9
|
+
- **Naming Conventions:**
|
|
10
|
+
- `snake_case` for functions, methods, variables, and modules.
|
|
11
|
+
- `PascalCase` for Structs, Enums, Traits, and Unions.
|
|
12
|
+
- `SCREAMING_SNAKE_CASE` for constants and statics.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 🧠 Borrowing & Cloning Optimizations
|
|
17
|
+
AI models often overuse `.clone()` to satisfy the Rust Borrow Checker, which degrades performance and negates Rust's zero-cost abstraction benefits.
|
|
18
|
+
- **Minimize Cloning:** Use `.clone()` or `.to_string()` on Heap-allocated objects (e.g., `String`, `Vec`) only when you absolutely need independent ownership.
|
|
19
|
+
- **Leverage References:** Pass read references `&T` or write references `&mut T`. For strings, prefer `&str` over `String` parameter types.
|
|
20
|
+
- **Exclusive Write Access:** Restrict code to have only one active mutable reference `&mut T` in a given scope, with no concurrent immutable reference `&T`.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 🛠️ Clippy Specifications
|
|
25
|
+
- Code generated by the AI Agent must strictly follow all optimizations suggested by Clippy.
|
|
26
|
+
- Run validation checks: `cargo clippy -- -D warnings` and guarantee **Zero Warnings** before submitting pull requests.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rust-db
|
|
3
|
+
description: Scaffold a database repository layer in Rust using SQLx, Diesel, or SeaORM
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Follow this process to add database models, tables, and access methods in Rust.
|
|
7
|
+
|
|
8
|
+
Inputs:
|
|
9
|
+
- modelName: Name of the struct (e.g., `User`)
|
|
10
|
+
- tableName: Database table name (e.g., `users`)
|
|
11
|
+
- databaseLibrary: DB access style: SQLx, Diesel, or SeaORM
|
|
12
|
+
|
|
13
|
+
Steps:
|
|
14
|
+
1. Declare the database entity struct, applying appropriate serialization/deserialization attributes (e.g., `#[derive(Debug, Serialize, Deserialize, sqlx::FromRow)]`).
|
|
15
|
+
2. Define the repository trait or struct handling asynchronous database connection execution.
|
|
16
|
+
3. If using SQLx, write queries using async query macros to ensure compile-time SQL validation:
|
|
17
|
+
```rust
|
|
18
|
+
let user = sqlx::query_as!<User, _>(
|
|
19
|
+
"SELECT id, email, created_at FROM users WHERE id = $1", id
|
|
20
|
+
)
|
|
21
|
+
.fetch_one(&self.pool)
|
|
22
|
+
.await?;
|
|
23
|
+
```
|
|
24
|
+
4. If using Diesel or SQLx migrations, add a migration script under the `/migrations` directory.
|
|
25
|
+
5. Setup connection pooling parameters and pass database pool references using constructor dependency injection.
|
|
26
|
+
6. Verify query compilation and formatting:
|
|
27
|
+
- `cargo clippy --all-targets -- -D warnings`
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rust-feature
|
|
3
|
+
description: Scaffold a Rust module, including structs, traits, implementations, and unit/integration tests
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Follow this process to generate a new Rust feature or sub-module.
|
|
7
|
+
|
|
8
|
+
Inputs:
|
|
9
|
+
- moduleName: Name of the module/file (e.g., `billing`)
|
|
10
|
+
- traitName: Name of the trait interface if any (e.g., `BillingService`)
|
|
11
|
+
- functionality: Summary of the business requirements and structs
|
|
12
|
+
|
|
13
|
+
Steps:
|
|
14
|
+
1. Create a file under `src/` named `<moduleName>.rs` (e.g., `src/billing.rs`), or a subdirectory containing `mod.rs`.
|
|
15
|
+
2. Register the module in `lib.rs` or `main.rs` using `pub mod <moduleName>;`.
|
|
16
|
+
3. Declare traits, structs, and custom error types (using `thiserror` for domain-specific errors) in the new module.
|
|
17
|
+
4. Implement functionality for the structs, mapping options and results safely (no `unwrap` or `expect` allowed in production).
|
|
18
|
+
5. Write inline unit tests inside a nested `tests` module decorated with `#[cfg(test)]`:
|
|
19
|
+
```rust
|
|
20
|
+
#[cfg(test)]
|
|
21
|
+
mod tests {
|
|
22
|
+
use super::*;
|
|
23
|
+
|
|
24
|
+
#[test]
|
|
25
|
+
fn test_feature_logic() {
|
|
26
|
+
// Arrange, Act, Assert
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
6. Add integration tests inside `/tests` if this feature integrates multiple modules or dependencies.
|
|
31
|
+
7. Verify compilation and warnings:
|
|
32
|
+
- `cargo check`
|
|
33
|
+
- `cargo test`
|
|
34
|
+
- `cargo clippy --all-targets -- -D warnings`
|