agent-workflow-kit-cli 1.3.2 → 1.3.3

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.
Files changed (39) hide show
  1. package/dist/cli/commands/add.js +3 -1
  2. package/dist/cli/commands/init.js +6 -0
  3. package/dist/core/analyzer.js +70 -0
  4. package/dist/core/detector.js +22 -0
  5. package/package.json +1 -1
  6. package/templates/common/AGENTS.md.hbs +4 -0
  7. package/templates/common/GLOBAL_RULES.md +101 -0
  8. package/templates/dotnet/AGENTS.md.hbs +34 -34
  9. package/templates/dotnet/rules/api-structure.md +15 -15
  10. package/templates/dotnet/rules/csharp-style.md +17 -17
  11. package/templates/dotnet/rules/dependency-injection.md +12 -12
  12. package/templates/dotnet/rules/error-handling-validation.md +15 -15
  13. package/templates/dotnet/skills/dotnet-controller/SKILL.md +16 -16
  14. package/templates/express/AGENTS.md.hbs +33 -33
  15. package/templates/express/rules/error-handling.md +18 -18
  16. package/templates/express/rules/express-style.md +19 -19
  17. package/templates/express/rules/router-controller.md +16 -16
  18. package/templates/express/skills/express-endpoint/SKILL.md +14 -14
  19. package/templates/golang/AGENTS.md.hbs +36 -0
  20. package/templates/golang/rules/concurrency.md +71 -0
  21. package/templates/golang/rules/error-handling.md +42 -0
  22. package/templates/golang/rules/golang-style.md +24 -0
  23. package/templates/golang/rules/project-layout.md +39 -0
  24. package/templates/nestjs/AGENTS.md.hbs +29 -29
  25. package/templates/nestjs/rules/module-architecture.md +14 -14
  26. package/templates/nestjs/rules/nestjs-style.md +12 -12
  27. package/templates/nestjs/rules/validation-errors.md +15 -15
  28. package/templates/nestjs/skills/nestjs-module/SKILL.md +15 -15
  29. package/templates/next-js/AGENTS.md.hbs +32 -32
  30. package/templates/next-js/rules/data-fetching-mutations.md +17 -17
  31. package/templates/next-js/rules/next-style.md +17 -17
  32. package/templates/next-js/rules/seo-metadata.md +18 -18
  33. package/templates/next-js/rules/server-client-components.md +17 -17
  34. package/templates/next-js/skills/next-feature/SKILL.md +16 -16
  35. package/templates/rust/AGENTS.md.hbs +34 -0
  36. package/templates/rust/rules/error-handling.md +36 -0
  37. package/templates/rust/rules/memory-concurrency.md +47 -0
  38. package/templates/rust/rules/project-layout.md +49 -0
  39. package/templates/rust/rules/rust-style.md +26 -0
@@ -1,27 +1,27 @@
1
1
  # React Server Components (RSC) vs React Client Components (RCC)
2
2
 
3
- Tài liệu này quy định ranh giới kiến trúc quy tắc phân loại component trong ứng dụng Next.js sử dụng App Router.
3
+ This document establishes architectural boundaries and classification rules for components in Next.js App Router projects.
4
4
 
5
5
  ---
6
6
 
7
7
  ## 🏛️ React Server Components (RSC)
8
- - **Mặc định:** Tất cả các page, layout component được tạo bên trong thư mục routing `app/` mặc định phải React Server Components (RSC).
9
- - **Lợi ích của RSC:**
10
- - Gọi dữ liệu (data fetching) trực tiếp sử dụng async/await.
11
- - Sử dụng an toàn các thư viện phía server (truy vấn DB, đọc file, import khóa bảo mật).
12
- - Giảm dung lượng bundle size gửi xuống client do nguồn RSC chỉ biên dịch chạy trên server.
13
- - **Quy tắc:**
14
- - Thực hiện toàn bộ việc nạp dữ liệu cấu trúc khung trang bên trong các RSC.
15
- - Không thêm `"use client"` vào các layout hoặc page entry points trừ khi bắt buộc.
8
+ - **Default Behavior:** All pages, layouts, and components created within the `app/` routing directory must default to React Server Components (RSC).
9
+ - **RSC Benefits:**
10
+ - Fetch data directly using async/await syntax at the server level.
11
+ - Securely utilize server-side libraries and APIs (e.g., database queries, file reading, private tokens).
12
+ - Decrease client-side bundle sizes because RSC code remains on the server and is not sent to the browser.
13
+ - **Rules:**
14
+ - Perform all data fetching and layout structure setups within RSCs.
15
+ - Never add the `"use client"` directive to layout or page entrypoint files unless absolutely necessary.
16
16
 
17
17
  ---
18
18
 
19
19
  ## 💻 React Client Components (RCC)
20
- - **Định nghĩa:** Các component chạy trên trình duyệt để hỗ trợ tương tác cập nhật trạng thái động từ người dùng.
21
- - **Dấu hiệu nhận biết RCC:** Chỉ gắn directive `"use client"` lớp component (Leaf Components) khi component:
22
- - Sử dụng các Hook vòng đời và trạng thái của React (`useState`, `useReducer`, `useEffect`, `useLayoutEffect`).
23
- - Gọi các API đặc trưng của trình duyệt (`window`, `localStorage`, custom viewport hooks).
24
- - Đăng các callback lắng nghe sự kiện DOM (như `onClick`, `onChange`, `onSubmit`).
25
- - **Phân tách ranh giới RCC:**
26
- - Giữ RCC cấp (Leaf Components) cuối cùng của cây dựng hình để tối ưu hiệu năng.
27
- - * dụ:* Nếu trang danh sách sản phẩm (RSC) thanh tìm kiếm (RCC), hãy tách thanh tìm kiếm thành một component riêng (`<SearchBar />` `"use client"`) import vào trang cha chạy phía server.
20
+ - **Definition:** Components that execute on the browser to support dynamic user interactions and state updates.
21
+ - **Identifying RCCs:** Attach the `"use client"` directive only at leaf component levels when they:
22
+ - Use React hooks (`useState`, `useReducer`, `useEffect`, `useLayoutEffect`).
23
+ - Use browser-specific APIs (e.g., `window`, `localStorage`, custom viewport hooks).
24
+ - Bind DOM event listeners (e.g., `onClick`, `onChange`, `onSubmit`).
25
+ - **RCC Isolation Guidelines:**
26
+ - Keep RCCs at the absolute leaf level of the rendering tree to optimize loading speed.
27
+ - *Example:* If a product list page (RSC) includes a search input (RCC), encapsulate the search input in its own component (e.g., `<SearchBar />` marked with `"use client"`) and import it into the server-rendered parent page.
@@ -1,25 +1,25 @@
1
1
  ---
2
2
  name: next-feature
3
- description: Sinh hoặc mở rộng một page hoặc route handler Next.js + TypeScript mới kèm caching metadata
3
+ description: Generate or extend a new Next.js + TypeScript page or route handler with caching and metadata
4
4
  ---
5
5
 
6
- Tuân thủ quy trình này để tạo một page, layout hoặc API route handler mới trong Next.js.
6
+ Follow this process to generate a new page, layout, or API route handler in Next.js.
7
7
 
8
- Đầu vào (Inputs):
9
- - featureName: Tên của route hoặc trang ( dụ: `dashboard`)
10
- - targetPath: Thư mục chứa route bên trong `app/` để triển khai
11
- - userFlow: tả tóm tắt hành vi bố cục giao diện của trang
8
+ Inputs:
9
+ - featureName: Name of the route or page (e.g., `dashboard`)
10
+ - targetPath: The directory inside the `app/` folder to implement the route
11
+ - userFlow: Brief description of the page behavior and layout
12
12
 
13
- Các bước thực hiện (Steps):
14
- 1. Quét các thư mục lân cận trong `app/` để tham chiếu các layout chung ranh giới xử lý lỗi (`error.tsx`).
15
- 2. Thiết lập cấu trúc thư mục route theo chuẩn Next.js ( dụ: `app/(dashboard)/billing`).
16
- 3. Khai báo interface cho route params query parameters.
17
- 4. Triển khai cấu trúc trang hoặc layout dưới dạng **React Server Component (RSC)**.
18
- 5. Nếu tương tác người dùng hoặc form, hãy tách thành các component con cấp (RCC) được đánh dấu `"use client"` rồi import vào RSC.
19
- 6. Thiết lập chế cache ràng cho toàn bộ các thao tác gọi dữ liệu `fetch()`.
20
- 7. Cấu hình metadata tĩnh hoặc động thông qua hàm `generateMetadata`.
21
- 8. Định nghĩa file xử lỗi cục bộ (`error.tsx`) tại thư mục route gần nhất để bắt lỗi runtime.
22
- 9. Thực hiện kiểm tra lỗi cục bộ:
13
+ Steps:
14
+ 1. Scan neighboring directories in the `app/` folder to check for shared layouts and error boundaries (`error.tsx`).
15
+ 2. Set up the route directory structure according to Next.js standards (e.g., `app/(dashboard)/billing`).
16
+ 3. Declare TypeScript interfaces for route parameters and query parameters.
17
+ 4. Implement the page or layout structure as a **React Server Component (RSC)**.
18
+ 5. If user interaction or form handling is needed, isolate it in a leaf Client Component (RCC) marked with `"use client"` and import it into the parent RSC.
19
+ 6. Configure explicit caching parameters for all data fetching `fetch()` calls.
20
+ 7. Set up static or dynamic SEO metadata using the `generateMetadata` function.
21
+ 8. Define a local error handler file (`error.tsx`) in the route directory to catch runtime exceptions.
22
+ 9. Execute local validation:
23
23
  - `{{runCommand}} lint`
24
24
  - `{{runCommand}} typecheck`
25
25
  - `{{runCommand}} test`
@@ -0,0 +1,34 @@
1
+ ## 🗺️ Rust Development Guide
2
+
3
+ ### 🔄 Agent Development Lifecycle
4
+ The AI Agent must execute all Rust tasks following this 4-step workflow:
5
+ 1. **Design & Implementation:** Implement business logic adhering to Rust conventions. Enforce structural separation: `main.rs` (for binary application setup) and `lib.rs` (for core business logic that can be reused and tested).
6
+ 2. **Comprehensive Testing:** Write unit tests inside internal test modules and integration tests in the `/tests` directory. Run tests with: `cargo test`.
7
+ 3. **Code Quality & Linting:** Run check tools regularly to ensure a warning-free state:
8
+ - Formatting: `cargo fmt`
9
+ - Linting: `cargo clippy --all-targets -- -D warnings`
10
+ - Build Validation: `cargo build`
11
+ 4. **Dependency Management:** Add external libraries using `cargo add [library_name]`. Never manually edit the `Cargo.lock` file.
12
+
13
+ ---
14
+
15
+ ### 🏗️ Template Blueprint
16
+ Refer to the detailed rules below:
17
+ - Idiomatic Rust, clippy lints, and cloning optimizations: `@rust-style.md`
18
+ - Crate modules, Cargo Workspaces, and Trait-based Dependency Injection: `@project-layout.md`
19
+ - Failures management, Result/Option, `thiserror`, and `anyhow`: `@error-handling.md`
20
+ - Lifetimes `'a`, Smart Pointers, and async Tokio safety: `@memory-concurrency.md`
21
+
22
+ ---
23
+
24
+ ### 🏛️ Strict Development Rules
25
+
26
+ #### 1. Ownership & Borrowing
27
+ - **Avoid Over-Cloning:** Call `.clone()` on Heap types only when you must own an independent copy. Otherwise, design functions to receive read references `&T` or write references `&mut T`.
28
+ - **Exclusive Mutable Borrow:** Ensure only one mutable reference `&mut T` exists at a time, and never let it coexist with any read references `&T` in the same scope.
29
+
30
+ #### 2. Safe Error Handling
31
+ - **No Unwraps:** Never use `.unwrap()` or `.expect()` in production code (except in tests). Propagate errors using `Result<T, E>` or `Option<T>` to ensure system reliability.
32
+
33
+ #### 3. Async Concurrency (Tokio)
34
+ - **CPU-Bound Tasks:** Never run heavy CPU operations (e.g., encryption, intensive loops) directly inside async contexts. Offload them using `tokio::task::spawn_blocking`.
@@ -0,0 +1,36 @@
1
+ # Error Handling & Fault Control in Rust
2
+
3
+ This document defines strict rules for handling, wrapping, and propagating failures using idiomatic Rust patterns.
4
+
5
+ ---
6
+
7
+ ## 🚫 Avoid Panics in Production
8
+ - **Strict Rule:** Never use `panic!`, `.unwrap()`, or `.expect()` in production application code. Doing so triggers process termination, resulting in service interruption.
9
+ - **Exceptions:** Only use panics in:
10
+ - Unit and Integration Tests.
11
+ - Initial bootstrapping (e.g., parsing critical files at startup) when missing items make recovery impossible.
12
+ - Invariants where the logic guarantees a failure is impossible.
13
+
14
+ ---
15
+
16
+ ## 🔄 Result Propagation with the `?` Operator
17
+ - All fallible business logic operations must return `Result<T, E>` or `Option<T>`.
18
+ - Use the `?` operator to propagate errors up the call stack, maintaining a clean syntax.
19
+
20
+ ---
21
+
22
+ ## 📚 Error Libraries: `thiserror` vs `anyhow`
23
+ Never mix these libraries arbitrarily. Comply with the following separation:
24
+ - **Use `thiserror` for Library Crates / Domain Modules:** Creates strongly-typed, detailed error definitions with custom display messages.
25
+ ```rust
26
+ use thiserror::Error;
27
+
28
+ #[derive(Error, Debug)]
29
+ pub enum DatabaseError {
30
+ #[error("User not found with ID {0}")]
31
+ UserNotFound(i64),
32
+ #[error("Database connection failure: {0}")]
33
+ ConnectionFailed(String),
34
+ }
35
+ ```
36
+ - **Use `anyhow` for Application Entrypoints (API Gateway / CLI main):** Ideal for general error grouping and stack propagation without complex type mapping.
@@ -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.