@moon791017/neo-skills 1.0.1
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/GEMINI.md +115 -0
- package/README.md +155 -0
- package/bin/install-claude-skills.js +72 -0
- package/commands/neo/cd-app-service.toml +20 -0
- package/commands/neo/cd-iis.toml +20 -0
- package/commands/neo/ci-dotnet.toml +21 -0
- package/commands/neo/clarification.toml +48 -0
- package/commands/neo/code-review.toml +33 -0
- package/commands/neo/dotnet-gen-interface.toml +31 -0
- package/commands/neo/explain.toml +44 -0
- package/commands/neo/git-commit.toml +49 -0
- package/dist/hooks/secret-guard.js +2 -0
- package/dist/server.js +220 -0
- package/gemini-extension.json +15 -0
- package/package.json +39 -0
- package/skills/azure-pipelines/SKILL.md +45 -0
- package/skills/azure-pipelines/templates/build/build-dotnet.yml +92 -0
- package/skills/azure-pipelines/templates/deploy/deploy-app-service.yml +71 -0
- package/skills/azure-pipelines/templates/deploy/deploy-iis.yml +189 -0
- package/skills/azure-pipelines/templates/util/clean-artifact.yml +40 -0
- package/skills/azure-pipelines/templates/util/extract-artifact.yml +57 -0
- package/skills/azure-pipelines/templates/util/iis/iis-backup.yml +92 -0
- package/skills/azure-pipelines/templates/util/iis/iis-deploy-files.yml +112 -0
- package/skills/azure-pipelines/templates/util/iis/iis-manage-website.yml +112 -0
- package/skills/azure-pipelines/templates/util/iis/iis-rollback.yml +98 -0
- package/skills/azure-pipelines/templates/util/iis/iis-start-website.yml +89 -0
- package/skills/azure-pipelines/templates/util/iis/iis-stop-website.yml +80 -0
- package/skills/azure-pipelines/templates/util/iis/iis-task.yml +157 -0
- package/skills/azure-pipelines/templates/util/set-aspnetcore-env.yml +77 -0
- package/skills/clarification/SKILL.md +22 -0
- package/skills/code-review/SKILL.md +72 -0
- package/skills/csharp/SKILL.md +87 -0
- package/skills/csharp/reference/anti-patterns.md +142 -0
- package/skills/csharp/reference/coding-style.md +86 -0
- package/skills/csharp/reference/patterns.md +142 -0
- package/skills/csharp-interface-generator/SKILL.md +40 -0
- package/skills/dotnet/SKILL.md +41 -0
- package/skills/dotnet-ef-core/SKILL.md +78 -0
- package/skills/dotnet-ef-core/reference/anti-patterns.md +51 -0
- package/skills/dotnet-ef-core/reference/coding-style.md +42 -0
- package/skills/dotnet-ef-core/reference/patterns.md +53 -0
- package/skills/dotnet-minimal-apis/SKILL.md +78 -0
- package/skills/dotnet-minimal-apis/reference/anti-patterns.md +59 -0
- package/skills/dotnet-minimal-apis/reference/coding-style.md +54 -0
- package/skills/dotnet-minimal-apis/reference/patterns.md +68 -0
- package/skills/dotnet-mvc/SKILL.md +78 -0
- package/skills/dotnet-mvc/reference/anti-patterns.md +49 -0
- package/skills/dotnet-mvc/reference/coding-style.md +43 -0
- package/skills/dotnet-mvc/reference/patterns.md +56 -0
- package/skills/dotnet-webapi/SKILL.md +78 -0
- package/skills/dotnet-webapi/reference/anti-patterns.md +48 -0
- package/skills/dotnet-webapi/reference/coding-style.md +47 -0
- package/skills/dotnet-webapi/reference/patterns.md +52 -0
- package/skills/explain/SKILL.md +27 -0
- package/skills/git-commit/SKILL.md +84 -0
- package/skills/python/SKILL.md +61 -0
- package/skills/python/reference/anti-patterns.md +177 -0
- package/skills/python/reference/coding-style.md +92 -0
- package/skills/python/reference/patterns.md +112 -0
- package/skills/python-manager/SKILL.md +61 -0
- package/skills/start-plan/SKILL.md +29 -0
- package/skills/swift/SKILL.md +78 -0
- package/skills/swift/reference/anti-patterns.md +75 -0
- package/skills/swift/reference/coding-style.md +56 -0
- package/skills/swift/reference/patterns.md +94 -0
- package/skills/swift-ui/SKILL.md +76 -0
- package/skills/swift-ui/reference/anti-patterns.md +52 -0
- package/skills/swift-ui/reference/coding-style.md +46 -0
- package/skills/swift-ui/reference/patterns.md +87 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# .NET MVC Coding Conventions
|
|
2
|
+
|
|
3
|
+
This guide aims to improve the structural degree of ASP.NET Core MVC applications and optimize the development efficiency of Razor views and controllers.
|
|
4
|
+
|
|
5
|
+
## 1. ViewModels
|
|
6
|
+
|
|
7
|
+
### 1.1 Naming and Roles
|
|
8
|
+
- **ViewModel Suffix**: All data models designed specifically for views must end with `ViewModel` (e.g., `UserLoginViewModel`).
|
|
9
|
+
- **Strict Separation**: **Prohibited** to pass database entities directly to views. View models should only contain data required by the view.
|
|
10
|
+
|
|
11
|
+
### 1.2 Data Annotations
|
|
12
|
+
- **Validation Attributes**: Use attributes like `[Required]`, `[StringLength]`, `[EmailAddress]` on ViewModels to declare validation rules.
|
|
13
|
+
- **Display Names**: Use `[Display(Name = "User Name")]` to ensure label consistency across different languages.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 2. Views & Layouts
|
|
18
|
+
|
|
19
|
+
### 2.1 View Naming
|
|
20
|
+
- **PascalCase View Names**: View file names should match action methods and use `PascalCase` (e.g., `Index.cshtml`, `Edit.cshtml`).
|
|
21
|
+
- **Strongly Typed Views**: All views must declare a strong type using `@model` at the top.
|
|
22
|
+
- **Layout Management**: Make good use of `_ViewStart.cshtml` and `_Layout.cshtml` to unify styles. Use `@section` to handle scripts or styles specific to individual pages.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 3. Tag Helpers
|
|
27
|
+
|
|
28
|
+
- **Prioritize Use**: Prioritize using Tag Helpers (e.g., `asp-for`, `asp-action`) over traditional HTML Helpers (e.g., `@Html.TextBoxFor`).
|
|
29
|
+
- **Custom Tags**: For repetitive UI logic (like pagination navigation, complex buttons), it is recommended to implement custom `TagHelper`s.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 4. Controllers
|
|
34
|
+
|
|
35
|
+
- **Inherit Controller**: Inherit from `Microsoft.AspNetCore.Mvc.Controller` (instead of `ControllerBase`) to gain View-related support.
|
|
36
|
+
- **Action Returns**: Action methods should explicitly return `IActionResult` or `Task<IActionResult>`.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 5. File Organization
|
|
41
|
+
|
|
42
|
+
- **Standard Structure**: Follow the standard directory structure of `Controllers/`, `Models/` (ViewModels), and `Views/`.
|
|
43
|
+
- **Partial Views**: Common view components should be placed in `Views/Shared/` and start with an underscore (e.g., `_UserCard.cshtml`).
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# .NET MVC Modern Patterns
|
|
2
|
+
|
|
3
|
+
This document introduces recommended development patterns in the ASP.NET Core MVC mode for .NET 6 to 10+.
|
|
4
|
+
|
|
5
|
+
## 1. UI Modularization
|
|
6
|
+
|
|
7
|
+
### 1.1 View Components
|
|
8
|
+
**Recommendation**: For complex and reusable UI blocks (like navigation menus, shopping cart summaries), use `ViewComponent`s instead of `Partial View`s.
|
|
9
|
+
```csharp
|
|
10
|
+
public class ShoppingCartViewComponent : ViewComponent
|
|
11
|
+
{
|
|
12
|
+
public async Task<IViewComponentResult> InvokeAsync() => View(await _service.GetItems());
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### 1.2 Tag Helper Componentization
|
|
17
|
+
**Recommendation**: Implement `TagHelper`s to encapsulate complex HTML generation logic, making Razor views more declarative.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 2. Data Flow and Validation
|
|
22
|
+
|
|
23
|
+
### 2.1 Remote Validation
|
|
24
|
+
**Recommendation**: Use the `[Remote]` attribute to implement real-time client-side validation (like checking if an account already exists), improving user experience.
|
|
25
|
+
|
|
26
|
+
### 2.2 Antiforgery
|
|
27
|
+
**Recommendation**: Ensure forms use `asp-antiforgery="true"`. In .NET 8+ global configuration is more straightforward.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 3. Performance Optimization
|
|
32
|
+
|
|
33
|
+
### 3.1 Cache Tag Helper
|
|
34
|
+
**Recommendation**: Use `<cache>` or `<distributed-cache>` tags for view fragments that don't need frequent updates.
|
|
35
|
+
```html
|
|
36
|
+
<cache expires-after="@TimeSpan.FromMinutes(10)">
|
|
37
|
+
@await Component.InvokeAsync("TopNews")
|
|
38
|
+
</cache>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 3.2 Response Compression and Static Resources
|
|
42
|
+
**Recommendation**: Configure response compression middleware and use `asp-append-version="true"` to ensure browser caches invalidate upon resource updates.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 4. Architectural Evolution
|
|
47
|
+
|
|
48
|
+
### 4.1 Vertical Slice Architecture
|
|
49
|
+
**Recommendation**: For large MVC applications, consider placing Controllers, ViewModels, and Views in feature directories (e.g., `Features/Orders/`), utilizing `Area`s or a custom `ViewLocationExpander`.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 5. C# 14+ Forward-looking Patterns
|
|
54
|
+
|
|
55
|
+
### 5.1 Extension Types for IHtmlHelper
|
|
56
|
+
**Recommendation**: Leverage C# 14's Extension Types to add domain-specific rendering methods to `IHtmlHelper`, not just static extension methods.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: dotnet-webapi
|
|
3
|
+
version: "1.0.0"
|
|
4
|
+
category: "Framework"
|
|
5
|
+
description: "開發 ASP.NET Core Web API (Controller-based) 的專家指引。支援從 .NET 6 (LTS) 到 .NET 10 (LTS) 的現代開發模式,涵蓋控制器設計、Problem Details、全域異常處理與 API 版本控制。"
|
|
6
|
+
compatibility: "Supports .NET 6.0 through 10.0 environments. Requires .NET SDK installed locally."
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# .NET Web API Expert Skill
|
|
10
|
+
|
|
11
|
+
## Trigger On
|
|
12
|
+
- The user requests to create, debug, refactor, or review ASP.NET Core Web APIs.
|
|
13
|
+
- The project contains a `Controllers` directory and inherits from `ControllerBase`.
|
|
14
|
+
- The target framework is .NET 6.0 (LTS) and above.
|
|
15
|
+
- There is a need for API code modernization (e.g., migrating from Middleware exception handling to .NET 8+ `IExceptionHandler`).
|
|
16
|
+
|
|
17
|
+
## Workflow
|
|
18
|
+
1. **Perceive (Architecture Awareness):**
|
|
19
|
+
- Check `.csproj` to identify `TargetFramework`.
|
|
20
|
+
- Analyze project structure to confirm whether it uses N-Tier architecture or Vertical Slice.
|
|
21
|
+
- Identify existing cross-cutting concern handling methods (filters, middleware).
|
|
22
|
+
2. **Reason (Planning Phase):**
|
|
23
|
+
- Evaluate whether to introduce the "Problem Details" standard.
|
|
24
|
+
- Determine whether to use the .NET 8+ global exception handling mechanism.
|
|
25
|
+
- Choose an appropriate versioning strategy based on project scale.
|
|
26
|
+
3. **Act (Execution Phase):**
|
|
27
|
+
- Write high-quality controllers compliant with `[ApiController]` conventions.
|
|
28
|
+
- Implement strongly-typed and immutable DTOs (prioritize `record`).
|
|
29
|
+
- Integrate dependency injection, prioritizing Primary Constructors (C# 12+).
|
|
30
|
+
4. **Validate (Standard Validation):**
|
|
31
|
+
- Validate whether Action return types comply with `ActionResult<T>` specifications.
|
|
32
|
+
- Check NRT (Nullable Reference Types) safety.
|
|
33
|
+
- Ensure asynchronous operations correctly pass down `CancellationToken`.
|
|
34
|
+
|
|
35
|
+
## Feature Roadmap (.NET 6 - 10)
|
|
36
|
+
|
|
37
|
+
### .NET 6 & 7 (Foundation)
|
|
38
|
+
- **Controllers Architecture**: Traditional controller patterns and attribute routing.
|
|
39
|
+
- **Problem Details**: Unified error response standards.
|
|
40
|
+
- **Output Caching**: High-performance server-side caching.
|
|
41
|
+
- **Nullable Reference Types**: Comprehensive null safety support.
|
|
42
|
+
|
|
43
|
+
### .NET 8 & 9 (Productivity)
|
|
44
|
+
- **IExceptionHandler**: More elegant centralized exception handling.
|
|
45
|
+
- **Antiforgery**: Built-in anti-forgery support for Web APIs.
|
|
46
|
+
- **Keyed Services**: More flexible dependency injection options.
|
|
47
|
+
- **HybridCache**: Multi-level caching optimization.
|
|
48
|
+
|
|
49
|
+
### .NET 10+ (Cutting Edge)
|
|
50
|
+
- **Extension Members for Controllers**: Extending base controller functionality.
|
|
51
|
+
- **Enhanced Serialization**: JSON optimization for large payloads.
|
|
52
|
+
|
|
53
|
+
## Coding Standards
|
|
54
|
+
- **Strong Typing**: Prioritize `ActionResult<T>` to improve Swagger support.
|
|
55
|
+
- **NRT Compliance**: Strictly enforce Null safety to reduce runtime errors.
|
|
56
|
+
- **Async Best Practices**: Always accept and pass `CancellationToken`.
|
|
57
|
+
- **Naming**: Controller names must end with `Controller`, async methods must end with `Async`.
|
|
58
|
+
|
|
59
|
+
## Deliver
|
|
60
|
+
- **Version-Optimized Web API Code**: Provide modernized controllers and configurations suitable for the target version.
|
|
61
|
+
- **Architectural Insights**: Provide refactoring suggestions for N-Tier or Clean Architecture.
|
|
62
|
+
- **Security Recommendations**: Provide security suggestions regarding Problem Details and exception handling.
|
|
63
|
+
|
|
64
|
+
## Validate
|
|
65
|
+
- Ensure the code complies with C# 10+ modern syntax standards.
|
|
66
|
+
- Validate endpoints correctly return error formats compliant with RFC 7807.
|
|
67
|
+
- Confirm the code has no resource leaks in the tested environment (correct use of `using` and async).
|
|
68
|
+
|
|
69
|
+
## Documentation
|
|
70
|
+
### Official References
|
|
71
|
+
- [ASP.NET Core Web API Overview](https://learn.microsoft.com/en-us/aspnet/core/web-api/)
|
|
72
|
+
- [Handle errors in ASP.NET Core web APIs (Problem Details)](https://learn.microsoft.com/en-us/aspnet/core/web-api/handle-errors)
|
|
73
|
+
- [Controller action return types in ASP.NET Core web API](https://learn.microsoft.com/en-us/aspnet/core/web-api/action-return-types)
|
|
74
|
+
|
|
75
|
+
### Internal References
|
|
76
|
+
- [Web API Coding Style and Naming Conventions](reference/coding-style.md)
|
|
77
|
+
- [Web API Anti-Patterns and Best Practices](reference/anti-patterns.md)
|
|
78
|
+
- [Web API Modern Patterns Guide](reference/patterns.md)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# .NET Web API Anti-Patterns & Best Practices
|
|
2
|
+
|
|
3
|
+
This document lists common mistakes in Controller-based Web API development and their corresponding correct practices.
|
|
4
|
+
|
|
5
|
+
## 1. Controller Organization
|
|
6
|
+
|
|
7
|
+
### 1.1 Avoid Fat Controllers
|
|
8
|
+
**Problem**: Writing massive amounts of business logic, database access, or complex validation directly in controller actions.
|
|
9
|
+
|
|
10
|
+
- **Bad**: Action exceeds 20 lines and includes direct manipulation of `DbContext` code.
|
|
11
|
+
- **Good**: Encapsulate business logic into a Service layer or use MediatR (CQRS pattern), making the Action only responsible for orchestrating requests and responses.
|
|
12
|
+
|
|
13
|
+
### 1.2 Avoid Ignoring the `[ApiController]` Attribute
|
|
14
|
+
**Problem**: Omitting this attribute requires manual model validation handling using `if (!ModelState.IsValid)`.
|
|
15
|
+
|
|
16
|
+
- **Good**: Always apply `[ApiController]` on API controllers.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 2. Async & Resources
|
|
21
|
+
|
|
22
|
+
### 2.1 Avoid Ignoring `CancellationToken`
|
|
23
|
+
- **Problem**: Failing to pass cancellation tokens in long-running queries; server resources remain uselessly occupied when clients cancel connections.
|
|
24
|
+
- **Good**: Action parameters should include `CancellationToken ct`, passing it down to async database operations or external HTTP calls.
|
|
25
|
+
|
|
26
|
+
### 2.2 Avoid Synchronously Reading the Request Body
|
|
27
|
+
- **Problem**: Synchronously reading the Body blocks the thread.
|
|
28
|
+
- **Good**: Use framework-provided asynchronous parameter binding.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 3. Security & Exceptions
|
|
33
|
+
|
|
34
|
+
### 3.1 Avoid Returning Sensitive Exception Messages
|
|
35
|
+
- **Problem**: Directly returning `ex.StackTrace` to the client in production environments.
|
|
36
|
+
- **Good**: Use global exception handling to convert it into `ProblemDetails`, logging details only on the backend and returning a standard error format to the frontend.
|
|
37
|
+
|
|
38
|
+
### 3.2 Avoid Over-exposing Domain Models
|
|
39
|
+
- **Problem**: Directly returning database entity objects as responses, which might leak sensitive fields (like password hashes) or cause circular references.
|
|
40
|
+
- **Good**: Create dedicated `Response DTO`s and use AutoMapper or manual mapping.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 4. Documentation
|
|
45
|
+
|
|
46
|
+
### 4.1 Ignoring Status Code Definitions
|
|
47
|
+
- **Problem**: Swagger UI only displays `200`, making it hard for frontend developers to know other error scenarios.
|
|
48
|
+
- **Good**: Use markers like `[ProducesResponseType(StatusCodes.Status404NotFound)]`.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# .NET Web API Coding Conventions
|
|
2
|
+
|
|
3
|
+
This guide is based on industry standards for ASP.NET Core Web API, aiming to improve organization and maintenance efficiency in the Controller-based pattern.
|
|
4
|
+
|
|
5
|
+
## 1. Controllers
|
|
6
|
+
|
|
7
|
+
### 1.1 Naming and Attributes
|
|
8
|
+
- **PascalCase**: All controller class names must use `PascalCase` and end with `Controller` (e.g., `UsersController`).
|
|
9
|
+
- **[ApiController]**: All API controllers must be marked with the `[ApiController]` attribute to enable automatic model validation, inferred parameter binding sources, and `ProblemDetails` responses.
|
|
10
|
+
- **[Route]**: It is recommended to use `[Route("api/[controller]")]` or explicit version paths (e.g., `[Route("api/v1/users")]`).
|
|
11
|
+
|
|
12
|
+
### 1.2 Action Methods
|
|
13
|
+
- **Semantic Naming**: Method names should reflect business intent (e.g., `GetUserAsync`), and asynchronous methods must end with `Async`.
|
|
14
|
+
- **HTTP Verbs**: Explicitly use `[HttpGet]`, `[HttpPost]`, `[HttpPut]`, `[HttpDelete]`, or `[HttpPatch]`.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 2. Data Transfer
|
|
19
|
+
|
|
20
|
+
- **DTO Naming**: Use `Request` or `Response` as suffixes (e.g., `UserCreateRequest`, `UserSummaryResponse`).
|
|
21
|
+
- **Record Types**: For read-only data transfer objects, prioritize using `record` types.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 3. Response Handling
|
|
26
|
+
|
|
27
|
+
- **ActionResult<T>**: Methods should return `Task<ActionResult<T>>`, which offers better type safety and Swagger support compared to `IActionResult`.
|
|
28
|
+
- **Standard Response Methods**:
|
|
29
|
+
- `Ok(data)` (200)
|
|
30
|
+
- `CreatedAtAction(...)` (201)
|
|
31
|
+
- `NoContent()` (204)
|
|
32
|
+
- `BadRequest(ModelState)` (400)
|
|
33
|
+
- `NotFound()` (404)
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 4. Dependency Injection (DI) & Services
|
|
38
|
+
|
|
39
|
+
- **Constructor Injection**: Always use constructor injection for services (prioritize C# 12+ Primary Constructors).
|
|
40
|
+
- **Interface-Oriented**: Inject interfaces instead of concrete classes to facilitate unit testing.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 5. File Organization and Namespaces
|
|
45
|
+
|
|
46
|
+
- **Vertical Slicing**: For large projects, it is recommended to organize folders by feature domain instead of the traditional Controllers/Models/Services layering.
|
|
47
|
+
- **File-scoped Namespace**: Always use File-scoped Namespaces (C# 10+).
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# .NET Web API Modern Patterns
|
|
2
|
+
|
|
3
|
+
This document introduces recommended development patterns in the Controller-based mode for .NET 6 to 10+.
|
|
4
|
+
|
|
5
|
+
## 1. Error Handling and Response Formats
|
|
6
|
+
|
|
7
|
+
### 1.1 Problem Details (RFC 7807)
|
|
8
|
+
**Recommendation**: Unified use of `ProblemDetails` to handle error responses. In .NET 7+, call `builder.Services.AddProblemDetails()` in `Program.cs`.
|
|
9
|
+
|
|
10
|
+
### 1.2 Global Exception Handler (IExceptionHandler) - .NET 8+
|
|
11
|
+
**Recommendation**: Implement the `IExceptionHandler` interface to centrally handle uncaught exceptions, replacing the legacy Middleware approach.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 2. Parameter Binding and Validation
|
|
16
|
+
|
|
17
|
+
### 2.1 Complex Type Binding
|
|
18
|
+
**Recommendation**: Make good use of `[FromRoute]`, `[FromQuery]`, `[FromBody]`, and `[FromHeader]` to explicitly define binding sources.
|
|
19
|
+
|
|
20
|
+
### 2.2 FluentValidation Integration
|
|
21
|
+
**Recommendation**: Combine with `FluentValidation` for complex model validation, separating validation logic from DTO definitions.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 3. Architectural Design
|
|
26
|
+
|
|
27
|
+
### 3.1 API Versioning (Asp.Versioning.Http)
|
|
28
|
+
**Recommendation**: Use the official versioning package to support multiple coexisting versions via URL or Header.
|
|
29
|
+
```csharp
|
|
30
|
+
[ApiVersion("1.0")]
|
|
31
|
+
[Route("api/v{version:apiVersion}/[controller]")]
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 3.2 Action Filters
|
|
35
|
+
**Recommendation**: For cross-cutting concerns (like permission checks, logging), implement `IAsyncActionFilter`.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 4. Documentation and Performance
|
|
40
|
+
|
|
41
|
+
### 4.1 Swagger/OpenAPI Enrichment
|
|
42
|
+
**Recommendation**: Use `[ProducesResponseType]` to mark all possible HTTP status codes and response types.
|
|
43
|
+
|
|
44
|
+
### 4.2 Output Caching - .NET 7+
|
|
45
|
+
**Recommendation**: Use `builder.Services.AddOutputCache()` to provide high-performance server-side caching, reducing pressure on controllers.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 5. C# 14+ Forward-looking Patterns
|
|
50
|
+
|
|
51
|
+
### 5.1 Extension Types for Controllers
|
|
52
|
+
**Recommendation**: Leverage Extension Types to expand common auxiliary properties or methods for the base `ControllerBase`.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: explain
|
|
3
|
+
description: 分析原始碼或專案結構,提供技術解析與架構洞察。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Project Code Explanation Specification
|
|
7
|
+
|
|
8
|
+
## Perceive
|
|
9
|
+
1. Intercept the standard input (stdin) or file arguments passed via the CLI command.
|
|
10
|
+
2. Detect the file context by reading the specified file paths or the current working directory.
|
|
11
|
+
3. Identify programming languages through file extensions or shebang lines.
|
|
12
|
+
4. Capture optional flags such as `--all` or specific line ranges to define the scope of analysis.
|
|
13
|
+
|
|
14
|
+
## Reason
|
|
15
|
+
1. Structural Parsing: Map the relationships between variables, functions, and classes within the provided context.
|
|
16
|
+
2. Logic Synthesis: Consolidate fragmented code segments into a coherent operational flow.
|
|
17
|
+
3. Contextual Inference: Evaluate how the specific code block interacts with standard libraries or identified project dependencies.
|
|
18
|
+
4. Documentation Alignment: Compare the implementation against common design patterns to explain "why" the code is structured in its current form.
|
|
19
|
+
|
|
20
|
+
## Act
|
|
21
|
+
1. Output a structured explanation directly to the terminal's standard output (stdout).
|
|
22
|
+
2. Format the response using the following hierarchy:
|
|
23
|
+
- Summary: High-level purpose of the code.
|
|
24
|
+
- Logic Flow: Step-by-step breakdown of execution and data flow.
|
|
25
|
+
- Key Components: Definitions of primary symbols and their roles.
|
|
26
|
+
3. Apply syntax highlighting to any code blocks included within the explanation.
|
|
27
|
+
4. Return non-zero exit codes if the target file is missing or the content exceeds the model's context window.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: git-commit
|
|
3
|
+
description: Analyzes staged changes, generates a high-quality Conventional Commits message in Traditional Chinese, and executes the commit only after user confirmation.
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Git Commit Message Generator
|
|
8
|
+
|
|
9
|
+
## CRITICAL SAFETY PROTOCOL
|
|
10
|
+
|
|
11
|
+
- **Absolute prohibition**: Never execute `git commit` in the same turn you generate the commit message.
|
|
12
|
+
- **Wait for confirmation**: Output the proposed message, then stop immediately and ask the user to confirm.
|
|
13
|
+
- **User-triggered only**: Only execute the commit in the next turn if the user explicitly replies with "yes", "ok", "是", or "commit".
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Perceive
|
|
18
|
+
|
|
19
|
+
1. Run `git add .` to stage all changes.
|
|
20
|
+
2. Run `git diff --staged` to retrieve the full staged diff.
|
|
21
|
+
3. If the staging area is empty, inform the user "No staged changes found." and stop.
|
|
22
|
+
|
|
23
|
+
## Reason
|
|
24
|
+
|
|
25
|
+
Analyze the diff to determine the core intent of the changes:
|
|
26
|
+
|
|
27
|
+
1. **Full scan**: Identify added, deleted, and modified files.
|
|
28
|
+
2. **Find correlations**: Determine whether the changes serve a single goal (e.g., adding a Model and updating a Service indicates a feature implementation).
|
|
29
|
+
3. **Filter noise**: Ignore pure formatting adjustments (whitespace, line endings) and focus on logical changes.
|
|
30
|
+
4. **Define type**: Choose the most accurate Conventional Commits type based on the primary purpose of the changes.
|
|
31
|
+
|
|
32
|
+
## Act
|
|
33
|
+
|
|
34
|
+
### Step 1: Generate the commit message
|
|
35
|
+
|
|
36
|
+
Output strictly in the following format:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
<type>(<scope>): <subject>
|
|
40
|
+
|
|
41
|
+
<body>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Type** — choose the most appropriate one:
|
|
45
|
+
|
|
46
|
+
| Type | When to use |
|
|
47
|
+
|------|-------------|
|
|
48
|
+
| `feat` | New feature |
|
|
49
|
+
| `fix` | Bug fix |
|
|
50
|
+
| `docs` | Documentation changes only |
|
|
51
|
+
| `style` | Formatting, no logic change |
|
|
52
|
+
| `refactor` | Refactoring, not a feature or fix |
|
|
53
|
+
| `perf` | Performance improvement |
|
|
54
|
+
| `test` | Adding or modifying tests |
|
|
55
|
+
| `build` | Build system or dependency changes |
|
|
56
|
+
| `ci` | CI/CD configuration changes |
|
|
57
|
+
| `chore` | Other maintenance tasks |
|
|
58
|
+
| `revert` | Reverting a previous commit |
|
|
59
|
+
|
|
60
|
+
**Quality rules**:
|
|
61
|
+
|
|
62
|
+
- **Subject**: Max 50 characters, imperative mood (e.g., "新增...", "修復...", "移除...").
|
|
63
|
+
- **Body**:
|
|
64
|
+
- Use bullet points (`-`) for complex changes to explain each detail.
|
|
65
|
+
- May be omitted for simple documentation or minor fixes.
|
|
66
|
+
- For new files, describe their purpose.
|
|
67
|
+
- **Language**: Both Subject and Body must be written in **Traditional Chinese (Taiwan)**.
|
|
68
|
+
- **Tone**: Professional and concise — avoid filler phrases like "This change is for...".
|
|
69
|
+
|
|
70
|
+
### Step 2: Ask for confirmation
|
|
71
|
+
|
|
72
|
+
Output the generated commit message inside a code block, then **stop immediately** and ask:
|
|
73
|
+
|
|
74
|
+
> 請問是否要執行此 commit?(輸入「是」或「yes」確認)
|
|
75
|
+
|
|
76
|
+
### Step 3: Execute (only after user confirms)
|
|
77
|
+
|
|
78
|
+
Run:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
git commit -m "<subject>" -m "<body>"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
After execution, run `git log --oneline -1` and display the result to confirm the commit was created successfully.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: python
|
|
3
|
+
version: "1.0.0"
|
|
4
|
+
category: "Core"
|
|
5
|
+
description: "用於 Python 3.10+ 開發的核心專家技能。專注於現代 Python 特性(Structural Pattern Matching, Union Types, Async Task Groups)、程式碼品質與架構設計。"
|
|
6
|
+
compatibility: "Supports Python 3.10 to 3.14. Requires a Python project structure (pyproject.toml, requirements.txt, or venv)."
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Python 3.10+ Expert Skill
|
|
10
|
+
|
|
11
|
+
## Trigger On
|
|
12
|
+
- The user asks to write, debug, review, or refactor Python code.
|
|
13
|
+
- Working in a repository containing `*.py`, `pyproject.toml`, `requirements.txt`, `Pipfile`, or `poetry.lock`.
|
|
14
|
+
- Requires asynchronous programming (`asyncio`), type hinting, or modern Python feature recommendations.
|
|
15
|
+
- The project needs setup for testing frameworks (`pytest`) or static analysis tools (`ruff`, `mypy`).
|
|
16
|
+
|
|
17
|
+
## Workflow
|
|
18
|
+
1. **Perceive:**
|
|
19
|
+
- Inspect the project root to identify package management tools: `pyproject.toml` (Poetry/PDM/Ruff), `requirements.txt` (pip), or `environment.yml` (Conda).
|
|
20
|
+
- Probe for Python version requirements (ensure compatibility with 3.10+ minimum).
|
|
21
|
+
- Identify the application type: Web API (FastAPI, Flask, Django), Data Science (Pandas, PyTorch), or CLI tools.
|
|
22
|
+
2. **Reason:**
|
|
23
|
+
- Evaluate if the current code follows modern Python (3.10+) idioms (e.g., `match/case`, `|` union types).
|
|
24
|
+
- Decide if type checking (MyPy/Pyright) or auto-formatting (Ruff/Black) needs to be introduced.
|
|
25
|
+
- Recommend appropriate architectural patterns based on project scale.
|
|
26
|
+
3. **Act:**
|
|
27
|
+
- Write Python code with complete Type Hints, prioritizing the `X | Y` syntax.
|
|
28
|
+
- Prefer modern language features: `match` statements (3.10+), `TaskGroup` (3.11+), and new generic syntax (3.12+).
|
|
29
|
+
- Ensure code passes static analysis and unit tests.
|
|
30
|
+
|
|
31
|
+
## Coding Standards
|
|
32
|
+
- **Type Hinting:** Strongly recommended for all function signatures. Use 3.10+ union syntax like `list[int | str]`.
|
|
33
|
+
- **PEP 8 Compliance:** Follow official style guidelines. Recommended to use `ruff` as a linter and formatter for consistency.
|
|
34
|
+
- **Async Processing:** Use 3.11+ `asyncio.TaskGroup` to manage concurrent tasks.
|
|
35
|
+
- **Error Handling:** Use specific exception types and leverage 3.11+ `ExceptionGroup` and `except*` syntax.
|
|
36
|
+
|
|
37
|
+
## Tooling Recommendations
|
|
38
|
+
- **Linter / Formatter:** `ruff` (high performance and highly integrated).
|
|
39
|
+
- **Type Checker:** `mypy` or `pyright`.
|
|
40
|
+
- **Testing:** `pytest` with `pytest-asyncio` or `pytest-cov`.
|
|
41
|
+
- **Package Management:** `Poetry` or `uv` to ensure dependency locking and environment consistency.
|
|
42
|
+
|
|
43
|
+
## Deliver
|
|
44
|
+
- **Code Quality Report:** Identify parts that do not comply with 3.10+ modern syntax or PEP 8.
|
|
45
|
+
- **Best Practice Recommendations:** Provide specific refactoring suggestions, such as converting complex logic into `match/case` structures.
|
|
46
|
+
- **Validated Code:** Provide Python source code accompanied by test cases and passed type checks.
|
|
47
|
+
|
|
48
|
+
## Validate
|
|
49
|
+
- Code must run in a Python 3.10+ environment.
|
|
50
|
+
- Functions should have Docstrings (following Google or NumPy styles).
|
|
51
|
+
- Complex logic should include unit tests.
|
|
52
|
+
- All public APIs should have complete type hints.
|
|
53
|
+
|
|
54
|
+
## Documentation
|
|
55
|
+
### Official References
|
|
56
|
+
- [Python 3 Official Documentation](https://docs.python.org/3/)
|
|
57
|
+
### Internal References
|
|
58
|
+
- [Modern Python syntax evolution (3.10-3.14) and PEP 8 naming conventions](reference/coding-style.md)
|
|
59
|
+
- [Recommended modern Python 3.10 - 3.14 development patterns and best practices](reference/patterns.md)
|
|
60
|
+
- [Outdated Python practices to avoid, common pitfalls, and security traps](reference/anti-patterns.md)
|
|
61
|
+
- [Intelligent detection and management of Python project virtual environments and dependency tools](../python-manager/SKILL.md)
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Python Modernization & Evolution Guide (3.10 - 3.14+)
|
|
2
|
+
|
|
3
|
+
This document summarizes important syntax evolutions from Python 3.10 to the latest versions, comparing "Outdated/Incorrect Practices" with "Modern/Correct Practices" to help developers write more readable, secure, and performant code.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 0. Fundamental Pitfalls (Version Independent)
|
|
8
|
+
These are the most common logical errors in Python development.
|
|
9
|
+
|
|
10
|
+
### A. Using Mutable Objects as Default Arguments
|
|
11
|
+
* **Incorrect:** `def add_item(item, items=[]):` (causes shared state across multiple calls)
|
|
12
|
+
* **Correct:**
|
|
13
|
+
```python
|
|
14
|
+
def add_item(item, items: list | None = None):
|
|
15
|
+
if items is None:
|
|
16
|
+
items = []
|
|
17
|
+
items.append(item)
|
|
18
|
+
return items
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### B. Manual Type Checking
|
|
22
|
+
* **Incorrect:** `if type(val) == str:` (breaks inheritance relationships)
|
|
23
|
+
* **Correct:** `if isinstance(val, str):`
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 1. Python 3.10: Union Types and Structural Matching
|
|
28
|
+
|
|
29
|
+
### A. Union Type Operator
|
|
30
|
+
* **Outdated:** `from typing import Union; def func(data: Union[int, str]):`
|
|
31
|
+
* **Modern:**
|
|
32
|
+
```python
|
|
33
|
+
def process_data(data: int | str) -> int | str:
|
|
34
|
+
# Use the intuitive bitwise OR operator | instead of Union[]
|
|
35
|
+
pass
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### B. Structural Pattern Matching
|
|
39
|
+
* **Outdated:** Using long `if-elif-else` chains.
|
|
40
|
+
* **Modern:**
|
|
41
|
+
```python
|
|
42
|
+
def http_status(status):
|
|
43
|
+
match status:
|
|
44
|
+
case 200:
|
|
45
|
+
return "OK"
|
|
46
|
+
case 404:
|
|
47
|
+
return "Not Found"
|
|
48
|
+
case _:
|
|
49
|
+
return "Unknown"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 2. Python 3.11: Type References and Exception Groups
|
|
55
|
+
|
|
56
|
+
### A. The `Self` Type
|
|
57
|
+
* **Outdated:** Relying on `TypeVar` for verbose class self-references.
|
|
58
|
+
* **Modern:**
|
|
59
|
+
```python
|
|
60
|
+
from typing import Self
|
|
61
|
+
|
|
62
|
+
class Config:
|
|
63
|
+
def clone(self) -> Self:
|
|
64
|
+
return self
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### B. Exception Groups
|
|
68
|
+
* **Outdated:** Traditional `except` easily misses other exceptions in concurrent tasks.
|
|
69
|
+
* **Modern:**
|
|
70
|
+
```python
|
|
71
|
+
try:
|
|
72
|
+
await asyncio.gather(task1(), task2())
|
|
73
|
+
except* ValueError as e:
|
|
74
|
+
print("Handling all ValueError groups")
|
|
75
|
+
except* TypeError as e:
|
|
76
|
+
print("Handling all TypeError groups")
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 3. Python 3.12: Generics and f-string Upgrades
|
|
82
|
+
|
|
83
|
+
### A. Type Parameter Syntax
|
|
84
|
+
* **Outdated:** Declaring `T = TypeVar('T')`.
|
|
85
|
+
* **Modern:**
|
|
86
|
+
```python
|
|
87
|
+
# Syntax is greatly simplified, completely removing dependency on TypeVar
|
|
88
|
+
def get_first[T](items: list[T]) -> T:
|
|
89
|
+
return items[0]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### B. f-string Nested Quote Restriction Lifted
|
|
93
|
+
* **Outdated:** Inner and outer quotes must be alternated, e.g., `f"{employee['name']}"`.
|
|
94
|
+
* **Modern:**
|
|
95
|
+
```python
|
|
96
|
+
employee = {"name": "Alice"}
|
|
97
|
+
# Allows direct reuse of double quotes, reducing mental load when modifying code
|
|
98
|
+
message = f"Employee name is {employee["name"]}"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## 4. Python 3.13: Deprecation Markers and Type Defaults
|
|
104
|
+
|
|
105
|
+
### A. Deprecation Decorator
|
|
106
|
+
* **Outdated:** Manually calling `warnings.warn()`.
|
|
107
|
+
* **Modern:**
|
|
108
|
+
```python
|
|
109
|
+
from warnings import deprecated
|
|
110
|
+
|
|
111
|
+
@deprecated("Please use new_api() instead")
|
|
112
|
+
def old_api():
|
|
113
|
+
pass
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### B. Copy and Replace for Immutable Objects (`copy.replace`)
|
|
117
|
+
* **Outdated:** Calling different methods (e.g., `._replace()` or `replace()`) for different types.
|
|
118
|
+
* **Modern:**
|
|
119
|
+
```python
|
|
120
|
+
import copy
|
|
121
|
+
# 3.13 unifies the interface for modifying copies of namedtuple, dataclass, datetime, etc.
|
|
122
|
+
new_obj = copy.replace(old_obj, field="value")
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### C. Type Parameter Defaults
|
|
126
|
+
* **Modern:**
|
|
127
|
+
```python
|
|
128
|
+
# Allows specifying default types for generics
|
|
129
|
+
class Box[T = int]:
|
|
130
|
+
def __init__(self, item: T):
|
|
131
|
+
self.item = item
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### D. Precise Type Narrowing and Read-Only Protection
|
|
135
|
+
* **Modern:**
|
|
136
|
+
```python
|
|
137
|
+
from typing import TypeIs, ReadOnly, TypedDict
|
|
138
|
+
|
|
139
|
+
class User(TypedDict):
|
|
140
|
+
age: ReadOnly[int] # Marked as read-only to prevent static check errors
|
|
141
|
+
|
|
142
|
+
def is_str_list(val: list[object]) -> TypeIs[list[str]]:
|
|
143
|
+
# Provides more intuitive type narrowing than TypeGuard
|
|
144
|
+
return all(isinstance(x, str) for x in val)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### E. Removal of "Dead Batteries" (PEP 594)
|
|
148
|
+
* **Note:** Python 3.13 has officially removed 19 legacy modules including `cgi`, `telnetlib`, and `crypt`. Please use modern alternatives (e.g., `fastapi`, `paramiko`).
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## 5. Python 3.14 (Latest Preview)
|
|
153
|
+
|
|
154
|
+
### A. Unparenthesized Exception Handling
|
|
155
|
+
* **Outdated:** `except (ValueError, TypeError):`
|
|
156
|
+
* **Modern:** `except ValueError, TypeError:` (reduces visual noise)
|
|
157
|
+
|
|
158
|
+
### B. Deferred Annotation Evaluation
|
|
159
|
+
* **Outdated:** `def set_next(self, node: "Node"):` (requires string quotes for forward references)
|
|
160
|
+
* **Modern:**
|
|
161
|
+
```python
|
|
162
|
+
class Node:
|
|
163
|
+
# 3.14 defaults to deferred evaluation; refer to the class directly without quotes
|
|
164
|
+
def set_next(self, node: Node):
|
|
165
|
+
pass
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### C. Pathlib Native Copy and Move
|
|
169
|
+
* **Outdated:** `shutil.copy(file, dest)`
|
|
170
|
+
* **Modern:** `from pathlib import Path; Path("f.txt").copy("dest.txt")`
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## 6. Resource Management (General Best Practice)
|
|
175
|
+
Always use `with` statements to handle files and connections.
|
|
176
|
+
* **Incorrect:** Manually calling `f.close()`.
|
|
177
|
+
* **Correct:** `with open(...) as f:`.
|