@leing2021/super-pi 0.16.0 → 0.18.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.
Files changed (89) hide show
  1. package/README.md +143 -12
  2. package/extensions/ce-core/index.ts +55 -24
  3. package/extensions/ce-core/tools/async-mutex.ts +28 -0
  4. package/extensions/ce-core/tools/parallel-subagent.ts +49 -3
  5. package/extensions/ce-core/tools/subagent-depth-guard.ts +86 -0
  6. package/extensions/ce-core/tools/subagent.ts +58 -3
  7. package/package.json +2 -1
  8. package/rules/README.md +111 -0
  9. package/rules/common/agents.md +50 -0
  10. package/rules/common/code-review.md +124 -0
  11. package/rules/common/coding-style.md +90 -0
  12. package/rules/common/development-workflow.md +44 -0
  13. package/rules/common/git-workflow.md +24 -0
  14. package/rules/common/hooks.md +30 -0
  15. package/rules/common/patterns.md +31 -0
  16. package/rules/common/performance.md +55 -0
  17. package/rules/common/security.md +29 -0
  18. package/rules/common/testing.md +57 -0
  19. package/rules/cpp/coding-style.md +44 -0
  20. package/rules/cpp/hooks.md +39 -0
  21. package/rules/cpp/patterns.md +51 -0
  22. package/rules/cpp/security.md +51 -0
  23. package/rules/cpp/testing.md +44 -0
  24. package/rules/csharp/coding-style.md +72 -0
  25. package/rules/csharp/hooks.md +25 -0
  26. package/rules/csharp/patterns.md +50 -0
  27. package/rules/csharp/security.md +58 -0
  28. package/rules/csharp/testing.md +46 -0
  29. package/rules/dart/coding-style.md +159 -0
  30. package/rules/dart/hooks.md +66 -0
  31. package/rules/dart/patterns.md +261 -0
  32. package/rules/dart/security.md +135 -0
  33. package/rules/dart/testing.md +215 -0
  34. package/rules/golang/coding-style.md +32 -0
  35. package/rules/golang/hooks.md +17 -0
  36. package/rules/golang/patterns.md +45 -0
  37. package/rules/golang/security.md +34 -0
  38. package/rules/golang/testing.md +31 -0
  39. package/rules/java/coding-style.md +114 -0
  40. package/rules/java/hooks.md +18 -0
  41. package/rules/java/patterns.md +146 -0
  42. package/rules/java/security.md +100 -0
  43. package/rules/java/testing.md +131 -0
  44. package/rules/kotlin/coding-style.md +86 -0
  45. package/rules/kotlin/hooks.md +17 -0
  46. package/rules/kotlin/patterns.md +146 -0
  47. package/rules/kotlin/security.md +82 -0
  48. package/rules/kotlin/testing.md +128 -0
  49. package/rules/perl/coding-style.md +46 -0
  50. package/rules/perl/hooks.md +22 -0
  51. package/rules/perl/patterns.md +76 -0
  52. package/rules/perl/security.md +69 -0
  53. package/rules/perl/testing.md +54 -0
  54. package/rules/php/coding-style.md +40 -0
  55. package/rules/php/hooks.md +24 -0
  56. package/rules/php/patterns.md +33 -0
  57. package/rules/php/security.md +37 -0
  58. package/rules/php/testing.md +39 -0
  59. package/rules/python/coding-style.md +42 -0
  60. package/rules/python/hooks.md +19 -0
  61. package/rules/python/patterns.md +39 -0
  62. package/rules/python/security.md +30 -0
  63. package/rules/python/testing.md +38 -0
  64. package/rules/rust/coding-style.md +151 -0
  65. package/rules/rust/hooks.md +16 -0
  66. package/rules/rust/patterns.md +168 -0
  67. package/rules/rust/security.md +141 -0
  68. package/rules/rust/testing.md +154 -0
  69. package/rules/swift/coding-style.md +47 -0
  70. package/rules/swift/hooks.md +20 -0
  71. package/rules/swift/patterns.md +66 -0
  72. package/rules/swift/security.md +33 -0
  73. package/rules/swift/testing.md +45 -0
  74. package/rules/typescript/coding-style.md +199 -0
  75. package/rules/typescript/hooks.md +22 -0
  76. package/rules/typescript/patterns.md +52 -0
  77. package/rules/typescript/security.md +28 -0
  78. package/rules/typescript/testing.md +18 -0
  79. package/rules/web/coding-style.md +96 -0
  80. package/rules/web/design-quality.md +63 -0
  81. package/rules/web/hooks.md +120 -0
  82. package/rules/web/patterns.md +79 -0
  83. package/rules/web/performance.md +64 -0
  84. package/rules/web/security.md +57 -0
  85. package/rules/web/testing.md +55 -0
  86. package/skills/02-plan/SKILL.md +1 -0
  87. package/skills/03-work/SKILL.md +1 -0
  88. package/skills/04-review/SKILL.md +1 -0
  89. package/skills/10-rules/SKILL.md +68 -0
@@ -0,0 +1,39 @@
1
+ ---
2
+ paths:
3
+ - "**/*.cpp"
4
+ - "**/*.hpp"
5
+ - "**/*.cc"
6
+ - "**/*.hh"
7
+ - "**/*.cxx"
8
+ - "**/*.h"
9
+ - "**/CMakeLists.txt"
10
+ ---
11
+ # C++ Hooks
12
+
13
+ > This file extends [common/hooks.md](../common/hooks.md) with C++ specific content.
14
+
15
+ ## Build Hooks
16
+
17
+ Run these checks before committing C++ changes:
18
+
19
+ ```bash
20
+ # Format check
21
+ clang-format --dry-run --Werror src/*.cpp src/*.hpp
22
+
23
+ # Static analysis
24
+ clang-tidy src/*.cpp -- -std=c++17
25
+
26
+ # Build
27
+ cmake --build build
28
+
29
+ # Tests
30
+ ctest --test-dir build --output-on-failure
31
+ ```
32
+
33
+ ## Recommended CI Pipeline
34
+
35
+ 1. **clang-format** — formatting check
36
+ 2. **clang-tidy** — static analysis
37
+ 3. **cppcheck** — additional analysis
38
+ 4. **cmake build** — compilation
39
+ 5. **ctest** — test execution with sanitizers
@@ -0,0 +1,51 @@
1
+ ---
2
+ paths:
3
+ - "**/*.cpp"
4
+ - "**/*.hpp"
5
+ - "**/*.cc"
6
+ - "**/*.hh"
7
+ - "**/*.cxx"
8
+ - "**/*.h"
9
+ - "**/CMakeLists.txt"
10
+ ---
11
+ # C++ Patterns
12
+
13
+ > This file extends [common/patterns.md](../common/patterns.md) with C++ specific content.
14
+
15
+ ## RAII (Resource Acquisition Is Initialization)
16
+
17
+ Tie resource lifetime to object lifetime:
18
+
19
+ ```cpp
20
+ class FileHandle {
21
+ public:
22
+ explicit FileHandle(const std::string& path) : file_(std::fopen(path.c_str(), "r")) {}
23
+ ~FileHandle() { if (file_) std::fclose(file_); }
24
+ FileHandle(const FileHandle&) = delete;
25
+ FileHandle& operator=(const FileHandle&) = delete;
26
+ private:
27
+ std::FILE* file_;
28
+ };
29
+ ```
30
+
31
+ ## Rule of Five/Zero
32
+
33
+ - **Rule of Zero**: Prefer classes that need no custom destructor, copy/move constructors, or assignments
34
+ - **Rule of Five**: If you define any of destructor/copy-ctor/copy-assign/move-ctor/move-assign, define all five
35
+
36
+ ## Value Semantics
37
+
38
+ - Pass small/trivial types by value
39
+ - Pass large types by `const&`
40
+ - Return by value (rely on RVO/NRVO)
41
+ - Use move semantics for sink parameters
42
+
43
+ ## Error Handling
44
+
45
+ - Use exceptions for exceptional conditions
46
+ - Use `std::optional` for values that may not exist
47
+ - Use `std::expected` (C++23) or result types for expected failures
48
+
49
+ ## Reference
50
+
51
+ See skill: `cpp-coding-standards` for comprehensive C++ patterns and anti-patterns.
@@ -0,0 +1,51 @@
1
+ ---
2
+ paths:
3
+ - "**/*.cpp"
4
+ - "**/*.hpp"
5
+ - "**/*.cc"
6
+ - "**/*.hh"
7
+ - "**/*.cxx"
8
+ - "**/*.h"
9
+ - "**/CMakeLists.txt"
10
+ ---
11
+ # C++ Security
12
+
13
+ > This file extends [common/security.md](../common/security.md) with C++ specific content.
14
+
15
+ ## Memory Safety
16
+
17
+ - Never use raw `new`/`delete` — use smart pointers
18
+ - Never use C-style arrays — use `std::array` or `std::vector`
19
+ - Never use `malloc`/`free` — use C++ allocation
20
+ - Avoid `reinterpret_cast` unless absolutely necessary
21
+
22
+ ## Buffer Overflows
23
+
24
+ - Use `std::string` over `char*`
25
+ - Use `.at()` for bounds-checked access when safety matters
26
+ - Never use `strcpy`, `strcat`, `sprintf` — use `std::string` or `fmt::format`
27
+
28
+ ## Undefined Behavior
29
+
30
+ - Always initialize variables
31
+ - Avoid signed integer overflow
32
+ - Never dereference null or dangling pointers
33
+ - Use sanitizers in CI:
34
+ ```bash
35
+ cmake -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined" ..
36
+ ```
37
+
38
+ ## Static Analysis
39
+
40
+ - Use **clang-tidy** for automated checks:
41
+ ```bash
42
+ clang-tidy --checks='*' src/*.cpp
43
+ ```
44
+ - Use **cppcheck** for additional analysis:
45
+ ```bash
46
+ cppcheck --enable=all src/
47
+ ```
48
+
49
+ ## Reference
50
+
51
+ See skill: `cpp-coding-standards` for detailed security guidelines.
@@ -0,0 +1,44 @@
1
+ ---
2
+ paths:
3
+ - "**/*.cpp"
4
+ - "**/*.hpp"
5
+ - "**/*.cc"
6
+ - "**/*.hh"
7
+ - "**/*.cxx"
8
+ - "**/*.h"
9
+ - "**/CMakeLists.txt"
10
+ ---
11
+ # C++ Testing
12
+
13
+ > This file extends [common/testing.md](../common/testing.md) with C++ specific content.
14
+
15
+ ## Framework
16
+
17
+ Use **GoogleTest** (gtest/gmock) with **CMake/CTest**.
18
+
19
+ ## Running Tests
20
+
21
+ ```bash
22
+ cmake --build build && ctest --test-dir build --output-on-failure
23
+ ```
24
+
25
+ ## Coverage
26
+
27
+ ```bash
28
+ cmake -DCMAKE_CXX_FLAGS="--coverage" -DCMAKE_EXE_LINKER_FLAGS="--coverage" ..
29
+ cmake --build .
30
+ ctest --output-on-failure
31
+ lcov --capture --directory . --output-file coverage.info
32
+ ```
33
+
34
+ ## Sanitizers
35
+
36
+ Always run tests with sanitizers in CI:
37
+
38
+ ```bash
39
+ cmake -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined" ..
40
+ ```
41
+
42
+ ## Reference
43
+
44
+ See skill: `cpp-testing` for detailed C++ testing patterns, TDD workflow, and GoogleTest/GMock usage.
@@ -0,0 +1,72 @@
1
+ ---
2
+ paths:
3
+ - "**/*.cs"
4
+ - "**/*.csx"
5
+ ---
6
+ # C# Coding Style
7
+
8
+ > This file extends [common/coding-style.md](../common/coding-style.md) with C#-specific content.
9
+
10
+ ## Standards
11
+
12
+ - Follow current .NET conventions and enable nullable reference types
13
+ - Prefer explicit access modifiers on public and internal APIs
14
+ - Keep files aligned with the primary type they define
15
+
16
+ ## Types and Models
17
+
18
+ - Prefer `record` or `record struct` for immutable value-like models
19
+ - Use `class` for entities or types with identity and lifecycle
20
+ - Use `interface` for service boundaries and abstractions
21
+ - Avoid `dynamic` in application code; prefer generics or explicit models
22
+
23
+ ```csharp
24
+ public sealed record UserDto(Guid Id, string Email);
25
+
26
+ public interface IUserRepository
27
+ {
28
+ Task<UserDto?> FindByIdAsync(Guid id, CancellationToken cancellationToken);
29
+ }
30
+ ```
31
+
32
+ ## Immutability
33
+
34
+ - Prefer `init` setters, constructor parameters, and immutable collections for shared state
35
+ - Do not mutate input models in-place when producing updated state
36
+
37
+ ```csharp
38
+ public sealed record UserProfile(string Name, string Email);
39
+
40
+ public static UserProfile Rename(UserProfile profile, string name) =>
41
+ profile with { Name = name };
42
+ ```
43
+
44
+ ## Async and Error Handling
45
+
46
+ - Prefer `async`/`await` over blocking calls like `.Result` or `.Wait()`
47
+ - Pass `CancellationToken` through public async APIs
48
+ - Throw specific exceptions and log with structured properties
49
+
50
+ ```csharp
51
+ public async Task<Order> LoadOrderAsync(
52
+ Guid orderId,
53
+ CancellationToken cancellationToken)
54
+ {
55
+ try
56
+ {
57
+ return await repository.FindAsync(orderId, cancellationToken)
58
+ ?? throw new InvalidOperationException($"Order {orderId} was not found.");
59
+ }
60
+ catch (Exception ex)
61
+ {
62
+ logger.LogError(ex, "Failed to load order {OrderId}", orderId);
63
+ throw;
64
+ }
65
+ }
66
+ ```
67
+
68
+ ## Formatting
69
+
70
+ - Use `dotnet format` for formatting and analyzer fixes
71
+ - Keep `using` directives organized and remove unused imports
72
+ - Prefer expression-bodied members only when they stay readable
@@ -0,0 +1,25 @@
1
+ ---
2
+ paths:
3
+ - "**/*.cs"
4
+ - "**/*.csx"
5
+ - "**/*.csproj"
6
+ - "**/*.sln"
7
+ - "**/Directory.Build.props"
8
+ - "**/Directory.Build.targets"
9
+ ---
10
+ # C# Hooks
11
+
12
+ > This file extends [common/hooks.md](../common/hooks.md) with C#-specific content.
13
+
14
+ ## PostToolUse Hooks
15
+
16
+ Configure in `~/.claude/settings.json`:
17
+
18
+ - **dotnet format**: Auto-format edited C# files and apply analyzer fixes
19
+ - **dotnet build**: Verify the solution or project still compiles after edits
20
+ - **dotnet test --no-build**: Re-run the nearest relevant test project after behavior changes
21
+
22
+ ## Stop Hooks
23
+
24
+ - Run a final `dotnet build` before ending a session with broad C# changes
25
+ - Warn on modified `appsettings*.json` files so secrets do not get committed
@@ -0,0 +1,50 @@
1
+ ---
2
+ paths:
3
+ - "**/*.cs"
4
+ - "**/*.csx"
5
+ ---
6
+ # C# Patterns
7
+
8
+ > This file extends [common/patterns.md](../common/patterns.md) with C#-specific content.
9
+
10
+ ## API Response Pattern
11
+
12
+ ```csharp
13
+ public sealed record ApiResponse<T>(
14
+ bool Success,
15
+ T? Data = default,
16
+ string? Error = null,
17
+ object? Meta = null);
18
+ ```
19
+
20
+ ## Repository Pattern
21
+
22
+ ```csharp
23
+ public interface IRepository<T>
24
+ {
25
+ Task<IReadOnlyList<T>> FindAllAsync(CancellationToken cancellationToken);
26
+ Task<T?> FindByIdAsync(Guid id, CancellationToken cancellationToken);
27
+ Task<T> CreateAsync(T entity, CancellationToken cancellationToken);
28
+ Task<T> UpdateAsync(T entity, CancellationToken cancellationToken);
29
+ Task DeleteAsync(Guid id, CancellationToken cancellationToken);
30
+ }
31
+ ```
32
+
33
+ ## Options Pattern
34
+
35
+ Use strongly typed options for config instead of reading raw strings throughout the codebase.
36
+
37
+ ```csharp
38
+ public sealed class PaymentsOptions
39
+ {
40
+ public const string SectionName = "Payments";
41
+ public required string BaseUrl { get; init; }
42
+ public required string ApiKeySecretName { get; init; }
43
+ }
44
+ ```
45
+
46
+ ## Dependency Injection
47
+
48
+ - Depend on interfaces at service boundaries
49
+ - Keep constructors focused; if a service needs too many dependencies, split responsibilities
50
+ - Register lifetimes intentionally: singleton for stateless/shared services, scoped for request data, transient for lightweight pure workers
@@ -0,0 +1,58 @@
1
+ ---
2
+ paths:
3
+ - "**/*.cs"
4
+ - "**/*.csx"
5
+ - "**/*.csproj"
6
+ - "**/appsettings*.json"
7
+ ---
8
+ # C# Security
9
+
10
+ > This file extends [common/security.md](../common/security.md) with C#-specific content.
11
+
12
+ ## Secret Management
13
+
14
+ - Never hardcode API keys, tokens, or connection strings in source code
15
+ - Use environment variables, user secrets for local development, and a secret manager in production
16
+ - Keep `appsettings.*.json` free of real credentials
17
+
18
+ ```csharp
19
+ // BAD
20
+ const string ApiKey = "sk-live-123";
21
+
22
+ // GOOD
23
+ var apiKey = builder.Configuration["OpenAI:ApiKey"]
24
+ ?? throw new InvalidOperationException("OpenAI:ApiKey is not configured.");
25
+ ```
26
+
27
+ ## SQL Injection Prevention
28
+
29
+ - Always use parameterized queries with ADO.NET, Dapper, or EF Core
30
+ - Never concatenate user input into SQL strings
31
+ - Validate sort fields and filter operators before using dynamic query composition
32
+
33
+ ```csharp
34
+ const string sql = "SELECT * FROM Orders WHERE CustomerId = @customerId";
35
+ await connection.QueryAsync<Order>(sql, new { customerId });
36
+ ```
37
+
38
+ ## Input Validation
39
+
40
+ - Validate DTOs at the application boundary
41
+ - Use data annotations, FluentValidation, or explicit guard clauses
42
+ - Reject invalid model state before running business logic
43
+
44
+ ## Authentication and Authorization
45
+
46
+ - Prefer framework auth handlers instead of custom token parsing
47
+ - Enforce authorization policies at endpoint or handler boundaries
48
+ - Never log raw tokens, passwords, or PII
49
+
50
+ ## Error Handling
51
+
52
+ - Return safe client-facing messages
53
+ - Log detailed exceptions with structured context server-side
54
+ - Do not expose stack traces, SQL text, or filesystem paths in API responses
55
+
56
+ ## References
57
+
58
+ See skill: `security-review` for broader application security review checklists.
@@ -0,0 +1,46 @@
1
+ ---
2
+ paths:
3
+ - "**/*.cs"
4
+ - "**/*.csx"
5
+ - "**/*.csproj"
6
+ ---
7
+ # C# Testing
8
+
9
+ > This file extends [common/testing.md](../common/testing.md) with C#-specific content.
10
+
11
+ ## Test Framework
12
+
13
+ - Prefer **xUnit** for unit and integration tests
14
+ - Use **FluentAssertions** for readable assertions
15
+ - Use **Moq** or **NSubstitute** for mocking dependencies
16
+ - Use **Testcontainers** when integration tests need real infrastructure
17
+
18
+ ## Test Organization
19
+
20
+ - Mirror `src/` structure under `tests/`
21
+ - Separate unit, integration, and end-to-end coverage clearly
22
+ - Name tests by behavior, not implementation details
23
+
24
+ ```csharp
25
+ public sealed class OrderServiceTests
26
+ {
27
+ [Fact]
28
+ public async Task FindByIdAsync_ReturnsOrder_WhenOrderExists()
29
+ {
30
+ // Arrange
31
+ // Act
32
+ // Assert
33
+ }
34
+ }
35
+ ```
36
+
37
+ ## ASP.NET Core Integration Tests
38
+
39
+ - Use `WebApplicationFactory<TEntryPoint>` for API integration coverage
40
+ - Test auth, validation, and serialization through HTTP, not by bypassing middleware
41
+
42
+ ## Coverage
43
+
44
+ - Target 80%+ line coverage
45
+ - Focus coverage on domain logic, validation, auth, and failure paths
46
+ - Run `dotnet test` in CI with coverage collection enabled where available
@@ -0,0 +1,159 @@
1
+ ---
2
+ paths:
3
+ - "**/*.dart"
4
+ - "**/pubspec.yaml"
5
+ - "**/analysis_options.yaml"
6
+ ---
7
+ # Dart/Flutter Coding Style
8
+
9
+ > This file extends [common/coding-style.md](../common/coding-style.md) with Dart and Flutter-specific content.
10
+
11
+ ## Formatting
12
+
13
+ - **dart format** for all `.dart` files — enforced in CI (`dart format --set-exit-if-changed .`)
14
+ - Line length: 80 characters (dart format default)
15
+ - Trailing commas on multi-line argument/parameter lists to improve diffs and formatting
16
+
17
+ ## Immutability
18
+
19
+ - Prefer `final` for local variables and `const` for compile-time constants
20
+ - Use `const` constructors wherever all fields are `final`
21
+ - Return unmodifiable collections from public APIs (`List.unmodifiable`, `Map.unmodifiable`)
22
+ - Use `copyWith()` for state mutations in immutable state classes
23
+
24
+ ```dart
25
+ // BAD
26
+ var count = 0;
27
+ List<String> items = ['a', 'b'];
28
+
29
+ // GOOD
30
+ final count = 0;
31
+ const items = ['a', 'b'];
32
+ ```
33
+
34
+ ## Naming
35
+
36
+ Follow Dart conventions:
37
+ - `camelCase` for variables, parameters, and named constructors
38
+ - `PascalCase` for classes, enums, typedefs, and extensions
39
+ - `snake_case` for file names and library names
40
+ - `SCREAMING_SNAKE_CASE` for constants declared with `const` at top level
41
+ - Prefix private members with `_`
42
+ - Extension names describe the type they extend: `StringExtensions`, not `MyHelpers`
43
+
44
+ ## Null Safety
45
+
46
+ - Avoid `!` (bang operator) — prefer `?.`, `??`, `if (x != null)`, or Dart 3 pattern matching; reserve `!` only where a null value is a programming error and crashing is the right behaviour
47
+ - Avoid `late` unless initialization is guaranteed before first use (prefer nullable or constructor init)
48
+ - Use `required` for constructor parameters that must always be provided
49
+
50
+ ```dart
51
+ // BAD — crashes at runtime if user is null
52
+ final name = user!.name;
53
+
54
+ // GOOD — null-aware operators
55
+ final name = user?.name ?? 'Unknown';
56
+
57
+ // GOOD — Dart 3 pattern matching (exhaustive, compiler-checked)
58
+ final name = switch (user) {
59
+ User(:final name) => name,
60
+ null => 'Unknown',
61
+ };
62
+
63
+ // GOOD — early-return null guard
64
+ String getUserName(User? user) {
65
+ if (user == null) return 'Unknown';
66
+ return user.name; // promoted to non-null after the guard
67
+ }
68
+ ```
69
+
70
+ ## Sealed Types and Pattern Matching (Dart 3+)
71
+
72
+ Use sealed classes to model closed state hierarchies:
73
+
74
+ ```dart
75
+ sealed class AsyncState<T> {
76
+ const AsyncState();
77
+ }
78
+
79
+ final class Loading<T> extends AsyncState<T> {
80
+ const Loading();
81
+ }
82
+
83
+ final class Success<T> extends AsyncState<T> {
84
+ const Success(this.data);
85
+ final T data;
86
+ }
87
+
88
+ final class Failure<T> extends AsyncState<T> {
89
+ const Failure(this.error);
90
+ final Object error;
91
+ }
92
+ ```
93
+
94
+ Always use exhaustive `switch` with sealed types — no default/wildcard:
95
+
96
+ ```dart
97
+ // BAD
98
+ if (state is Loading) { ... }
99
+
100
+ // GOOD
101
+ return switch (state) {
102
+ Loading() => const CircularProgressIndicator(),
103
+ Success(:final data) => DataWidget(data),
104
+ Failure(:final error) => ErrorWidget(error.toString()),
105
+ };
106
+ ```
107
+
108
+ ## Error Handling
109
+
110
+ - Specify exception types in `on` clauses — never use bare `catch (e)`
111
+ - Never catch `Error` subtypes — they indicate programming bugs
112
+ - Use `Result`-style types or sealed classes for recoverable errors
113
+ - Avoid using exceptions for control flow
114
+
115
+ ```dart
116
+ // BAD
117
+ try {
118
+ await fetchUser();
119
+ } catch (e) {
120
+ log(e.toString());
121
+ }
122
+
123
+ // GOOD
124
+ try {
125
+ await fetchUser();
126
+ } on NetworkException catch (e) {
127
+ log('Network error: ${e.message}');
128
+ } on NotFoundException {
129
+ handleNotFound();
130
+ }
131
+ ```
132
+
133
+ ## Async / Futures
134
+
135
+ - Always `await` Futures or explicitly call `unawaited()` to signal intentional fire-and-forget
136
+ - Never mark a function `async` if it never `await`s anything
137
+ - Use `Future.wait` / `Future.any` for concurrent operations
138
+ - Check `context.mounted` before using `BuildContext` after any `await` (Flutter 3.7+)
139
+
140
+ ```dart
141
+ // BAD — ignoring Future
142
+ fetchData(); // fire-and-forget without marking intent
143
+
144
+ // GOOD
145
+ unawaited(fetchData()); // explicit fire-and-forget
146
+ await fetchData(); // or properly awaited
147
+ ```
148
+
149
+ ## Imports
150
+
151
+ - Use `package:` imports throughout — never relative imports (`../`) for cross-feature or cross-layer code
152
+ - Order: `dart:` → external `package:` → internal `package:` (same package)
153
+ - No unused imports — `dart analyze` enforces this with `unused_import`
154
+
155
+ ## Code Generation
156
+
157
+ - Generated files (`.g.dart`, `.freezed.dart`, `.gr.dart`) must be committed or gitignored consistently — pick one strategy per project
158
+ - Never manually edit generated files
159
+ - Keep generator annotations (`@JsonSerializable`, `@freezed`, `@riverpod`, etc.) on the canonical source file only
@@ -0,0 +1,66 @@
1
+ ---
2
+ paths:
3
+ - "**/*.dart"
4
+ - "**/pubspec.yaml"
5
+ - "**/analysis_options.yaml"
6
+ ---
7
+ # Dart/Flutter Hooks
8
+
9
+ > This file extends [common/hooks.md](../common/hooks.md) with Dart and Flutter-specific content.
10
+
11
+ ## PostToolUse Hooks
12
+
13
+ Configure in `~/.claude/settings.json`:
14
+
15
+ - **dart format**: Auto-format `.dart` files after edit
16
+ - **dart analyze**: Run static analysis after editing Dart files and surface warnings
17
+ - **flutter test**: Optionally run affected tests after significant changes
18
+
19
+ ## Recommended Hook Configuration
20
+
21
+ ```json
22
+ {
23
+ "hooks": {
24
+ "PostToolUse": [
25
+ {
26
+ "matcher": { "tool_name": "Edit", "file_paths": ["**/*.dart"] },
27
+ "hooks": [
28
+ { "type": "command", "command": "dart format $CLAUDE_FILE_PATHS" }
29
+ ]
30
+ }
31
+ ]
32
+ }
33
+ }
34
+ ```
35
+
36
+ ## Pre-commit Checks
37
+
38
+ Run before committing Dart/Flutter changes:
39
+
40
+ ```bash
41
+ dart format --set-exit-if-changed .
42
+ dart analyze --fatal-infos
43
+ flutter test
44
+ ```
45
+
46
+ ## Useful One-liners
47
+
48
+ ```bash
49
+ # Format all Dart files
50
+ dart format .
51
+
52
+ # Analyze and report issues
53
+ dart analyze
54
+
55
+ # Run all tests with coverage
56
+ flutter test --coverage
57
+
58
+ # Regenerate code-gen files
59
+ dart run build_runner build --delete-conflicting-outputs
60
+
61
+ # Check for outdated packages
62
+ flutter pub outdated
63
+
64
+ # Upgrade packages within constraints
65
+ flutter pub upgrade
66
+ ```