hatch3r 1.9.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -143
- package/dist/cli/index.js +28453 -15831
- package/dist/content/agents/hatch3r-architect.md +39 -9
- package/dist/content/agents/hatch3r-brownfield-spec.md +254 -0
- package/dist/content/agents/hatch3r-ci-watcher.md +8 -1
- package/dist/content/agents/hatch3r-context-rules.md +19 -1
- package/dist/content/agents/hatch3r-creator.md +65 -26
- package/dist/content/agents/hatch3r-dependency-drafter.md +162 -0
- package/dist/content/agents/hatch3r-devops.md +11 -1
- package/dist/content/agents/hatch3r-docs-writer.md +11 -1
- package/dist/content/agents/hatch3r-edge-case-analyst.md +134 -0
- package/dist/content/agents/hatch3r-enhancability.md +192 -0
- package/dist/content/agents/hatch3r-fixer.md +59 -8
- package/dist/content/agents/hatch3r-greenfield-spec.md +256 -0
- package/dist/content/agents/hatch3r-handoff-loader.md +29 -3
- package/dist/content/agents/hatch3r-handoff-preparer.md +10 -1
- package/dist/content/agents/hatch3r-implementer.md +139 -8
- package/dist/content/agents/hatch3r-incident-responder.md +96 -0
- package/dist/content/agents/hatch3r-learnings-loader.md +122 -88
- package/dist/content/agents/hatch3r-lint-fixer.md +15 -3
- package/dist/content/agents/hatch3r-maintainability.md +183 -0
- package/dist/content/agents/hatch3r-pack-installer.md +113 -0
- package/dist/content/agents/hatch3r-performance.md +179 -0
- package/dist/content/agents/hatch3r-reliability.md +193 -0
- package/dist/content/agents/hatch3r-researcher.md +27 -4
- package/dist/content/agents/hatch3r-reviewer.md +153 -103
- package/dist/content/agents/hatch3r-scalability.md +162 -0
- package/dist/content/agents/hatch3r-security.md +197 -0
- package/dist/content/agents/hatch3r-testability.md +204 -0
- package/dist/content/agents/hatch3r-ui.md +175 -0
- package/dist/content/agents/hatch3r-ux.md +160 -0
- package/dist/content/agents/modes/requirements-elicitation.md +1 -1
- package/dist/content/agents/modes/user-flows.md +2 -2
- package/dist/content/agents/shared/clarification-default-block.md +44 -0
- package/dist/content/agents/shared/confidence-gate.md +42 -0
- package/dist/content/agents/shared/cq-specialist-roster.md +26 -0
- package/dist/content/agents/shared/efficiency-patterns.md +32 -1
- package/dist/content/agents/shared/injection-patterns.md +18 -7
- package/dist/content/agents/shared/principles.md +60 -0
- package/dist/content/agents/shared/prompt-structure.md +7 -1
- package/dist/content/agents/shared/quality-charter.md +48 -12
- package/dist/content/agents/shared/quality-specialist-frame.md +141 -0
- package/dist/content/agents/shared/rigor-contract.md +151 -0
- package/dist/content/agents/shared/severity-mapping.md +92 -0
- package/dist/content/agents/shared/triage-vocabulary.md +46 -0
- package/dist/content/agents/shared/user-content-templates.md +34 -8
- package/dist/content/agents/shared/user-question-protocol.md +45 -3
- package/dist/content/checks/README.md +5 -0
- package/dist/content/checks/accessibility.md +14 -7
- package/dist/content/checks/code-quality.md +1 -1
- package/dist/content/checks/performance.md +7 -4
- package/dist/content/checks/security.md +6 -6
- package/dist/content/checks/testing.md +1 -1
- package/dist/content/commands/board/pickup-delegation-multi.md +37 -10
- package/dist/content/commands/board/pickup-delegation.md +7 -5
- package/dist/content/commands/board/pickup-modes.md +1 -0
- package/dist/content/commands/board/pickup-post-impl.md +1 -1
- package/dist/content/commands/hatch3r-api-spec.md +79 -2
- package/dist/content/commands/hatch3r-auth-scaffold.md +250 -0
- package/dist/content/commands/hatch3r-benchmark.md +90 -7
- package/dist/content/commands/hatch3r-board-fill.md +97 -11
- package/dist/content/commands/hatch3r-board-pickup.md +93 -9
- package/dist/content/commands/hatch3r-bug-pipeline.md +240 -0
- package/dist/content/commands/hatch3r-bug-plan.md +79 -3
- package/dist/content/commands/hatch3r-codebase-map.md +80 -4
- package/dist/content/commands/hatch3r-create.md +105 -7
- package/dist/content/commands/hatch3r-debug.md +102 -14
- package/dist/content/commands/hatch3r-diagnose.md +238 -0
- package/dist/content/commands/hatch3r-feature-plan.md +125 -5
- package/dist/content/commands/hatch3r-handoff.md +83 -3
- package/dist/content/commands/hatch3r-healthcheck.md +105 -5
- package/dist/content/commands/hatch3r-incident-response.md +228 -0
- package/dist/content/commands/hatch3r-migration-plan.md +79 -3
- package/dist/content/commands/hatch3r-onboard.md +94 -3
- package/dist/content/commands/hatch3r-pack-install.md +243 -0
- package/dist/content/commands/hatch3r-pr-resolve.md +106 -23
- package/dist/content/commands/hatch3r-project-spec.md +82 -6
- package/dist/content/commands/hatch3r-quick-change.md +108 -13
- package/dist/content/commands/hatch3r-refactor-plan.md +78 -2
- package/dist/content/commands/hatch3r-release.md +401 -0
- package/dist/content/commands/hatch3r-revision.md +98 -12
- package/dist/content/commands/hatch3r-roadmap.md +92 -10
- package/dist/content/commands/hatch3r-security-audit.md +105 -5
- package/dist/content/commands/hatch3r-slo-scaffold.md +246 -0
- package/dist/content/commands/hatch3r-spec.md +216 -0
- package/dist/content/commands/hatch3r-test-plan.md +85 -9
- package/dist/content/commands/hatch3r-workflow.md +165 -41
- package/dist/content/commands/revision/revision-delegation.md +6 -5
- package/dist/content/commands/revision/revision-modes.md +49 -4
- package/dist/content/commands/revision/revision-quality.md +10 -7
- package/dist/content/commands/shared/orchestration-frame.md +119 -0
- package/dist/content/github-agents/hatch3r-docs-agent.md +21 -1
- package/dist/content/github-agents/hatch3r-lint-agent.md +21 -1
- package/dist/content/github-agents/hatch3r-security-agent.md +21 -1
- package/dist/content/github-agents/hatch3r-test-agent.md +21 -1
- package/dist/content/hooks/hatch3r-file-save.md +1 -1
- package/dist/content/hooks/hatch3r-pre-push.md +4 -4
- package/dist/content/hooks/hatch3r-review-loop-cap.md +52 -0
- package/dist/content/mcp/mcp.json +7 -5
- package/dist/content/rules/hatch3r-accessibility-standards.md +14 -2
- package/dist/content/rules/hatch3r-accessibility-standards.mdc +12 -1
- package/dist/content/rules/hatch3r-agent-orchestration-detail.md +58 -19
- package/dist/content/rules/hatch3r-agent-orchestration-detail.mdc +58 -19
- package/dist/content/rules/hatch3r-agent-orchestration.md +87 -213
- package/dist/content/rules/hatch3r-agent-orchestration.mdc +87 -213
- package/dist/content/rules/hatch3r-ai-evals.md +5 -4
- package/dist/content/rules/hatch3r-ai-evals.mdc +3 -3
- package/dist/content/rules/hatch3r-ai-ux-patterns.md +6 -2
- package/dist/content/rules/hatch3r-ai-ux-patterns.mdc +4 -1
- package/dist/content/rules/hatch3r-android-patterns.md +107 -0
- package/dist/content/rules/hatch3r-android-patterns.mdc +102 -0
- package/dist/content/rules/hatch3r-anti-duplication.md +115 -0
- package/dist/content/rules/hatch3r-anti-duplication.mdc +115 -0
- package/dist/content/rules/hatch3r-api-design.md +5 -1
- package/dist/content/rules/hatch3r-api-design.mdc +3 -0
- package/dist/content/rules/hatch3r-api-versioning.md +2 -1
- package/dist/content/rules/hatch3r-auth-patterns.md +3 -1
- package/dist/content/rules/hatch3r-auth-patterns.mdc +1 -0
- package/dist/content/rules/hatch3r-browser-verification.md +2 -0
- package/dist/content/rules/hatch3r-browser-verification.mdc +2 -0
- package/dist/content/rules/hatch3r-capability-matrix.md +108 -0
- package/dist/content/rules/hatch3r-capability-matrix.mdc +108 -0
- package/dist/content/rules/hatch3r-ci-cd.md +8 -1
- package/dist/content/rules/hatch3r-ci-cd.mdc +6 -0
- package/dist/content/rules/hatch3r-clarification-default.md +73 -0
- package/dist/content/rules/hatch3r-clarification-default.mdc +73 -0
- package/dist/content/rules/hatch3r-code-standards.md +23 -47
- package/dist/content/rules/hatch3r-code-standards.mdc +22 -46
- package/dist/content/rules/hatch3r-component-conventions.md +3 -0
- package/dist/content/rules/hatch3r-component-conventions.mdc +3 -0
- package/dist/content/rules/hatch3r-container-hardening.md +11 -2
- package/dist/content/rules/hatch3r-container-hardening.mdc +9 -1
- package/dist/content/rules/hatch3r-contract-testing.md +2 -1
- package/dist/content/rules/hatch3r-cost-visibility.md +135 -0
- package/dist/content/rules/hatch3r-cost-visibility.mdc +135 -0
- package/dist/content/rules/hatch3r-cq-rule-frame.md +54 -0
- package/dist/content/rules/hatch3r-cq-rule-frame.mdc +49 -0
- package/dist/content/rules/hatch3r-data-classification.md +3 -1
- package/dist/content/rules/hatch3r-data-classification.mdc +2 -1
- package/dist/content/rules/hatch3r-deep-context.md +13 -13
- package/dist/content/rules/hatch3r-deep-context.mdc +13 -13
- package/dist/content/rules/hatch3r-dependency-management.md +16 -3
- package/dist/content/rules/hatch3r-dependency-management.mdc +15 -3
- package/dist/content/rules/hatch3r-design-system-detection.md +2 -1
- package/dist/content/rules/hatch3r-dotnet-patterns.md +104 -0
- package/dist/content/rules/hatch3r-dotnet-patterns.mdc +99 -0
- package/dist/content/rules/hatch3r-edge-case-discipline.md +65 -0
- package/dist/content/rules/hatch3r-edge-case-discipline.mdc +65 -0
- package/dist/content/rules/hatch3r-enhancability.md +147 -0
- package/dist/content/rules/hatch3r-enhancability.mdc +142 -0
- package/dist/content/rules/hatch3r-event-schema-evolution.md +2 -1
- package/dist/content/rules/hatch3r-fan-out-discipline.md +91 -0
- package/dist/content/rules/hatch3r-fan-out-discipline.mdc +91 -0
- package/dist/content/rules/hatch3r-feature-flags.md +2 -0
- package/dist/content/rules/hatch3r-feature-flags.mdc +2 -0
- package/dist/content/rules/hatch3r-flutter-patterns.md +88 -0
- package/dist/content/rules/hatch3r-flutter-patterns.mdc +83 -0
- package/dist/content/rules/hatch3r-git-conventions.md +4 -1
- package/dist/content/rules/hatch3r-git-conventions.mdc +2 -0
- package/dist/content/rules/hatch3r-go-patterns.md +98 -0
- package/dist/content/rules/hatch3r-go-patterns.mdc +93 -0
- package/dist/content/rules/hatch3r-handoff-readiness.md +10 -0
- package/dist/content/rules/hatch3r-handoff-readiness.mdc +10 -0
- package/dist/content/rules/hatch3r-i18n.md +2 -0
- package/dist/content/rules/hatch3r-i18n.mdc +2 -0
- package/dist/content/rules/hatch3r-iteration-summary.md +75 -57
- package/dist/content/rules/hatch3r-iteration-summary.mdc +77 -54
- package/dist/content/rules/hatch3r-learning-system.md +202 -0
- package/dist/content/rules/hatch3r-learning-system.mdc +202 -0
- package/dist/content/rules/hatch3r-maintainability.md +157 -0
- package/dist/content/rules/hatch3r-maintainability.mdc +152 -0
- package/dist/content/rules/hatch3r-migrations.md +2 -1
- package/dist/content/rules/hatch3r-observability-logging.md +1 -1
- package/dist/content/rules/hatch3r-observability-metrics.md +1 -1
- package/dist/content/rules/hatch3r-observability-tracing.md +45 -36
- package/dist/content/rules/hatch3r-observability-tracing.mdc +44 -35
- package/dist/content/rules/hatch3r-operability.md +2 -1
- package/dist/content/rules/hatch3r-passkey-server.md +2 -1
- package/dist/content/rules/hatch3r-performance-budgets.md +2 -0
- package/dist/content/rules/hatch3r-performance-budgets.mdc +2 -0
- package/dist/content/rules/hatch3r-php-laravel-patterns.md +109 -0
- package/dist/content/rules/hatch3r-php-laravel-patterns.mdc +104 -0
- package/dist/content/rules/hatch3r-progressive-delivery.md +5 -1
- package/dist/content/rules/hatch3r-progressive-delivery.mdc +3 -0
- package/dist/content/rules/hatch3r-proof-model.md +131 -0
- package/dist/content/rules/hatch3r-proof-model.mdc +131 -0
- package/dist/content/rules/hatch3r-python-patterns.md +70 -0
- package/dist/content/rules/hatch3r-python-patterns.mdc +65 -0
- package/dist/content/rules/hatch3r-react-native-patterns.md +83 -0
- package/dist/content/rules/hatch3r-react-native-patterns.mdc +78 -0
- package/dist/content/rules/hatch3r-resilience-patterns.md +2 -1
- package/dist/content/rules/hatch3r-reviewer-calibration.md +84 -0
- package/dist/content/rules/hatch3r-reviewer-calibration.mdc +84 -0
- package/dist/content/rules/hatch3r-right-sizing.md +68 -0
- package/dist/content/rules/hatch3r-right-sizing.mdc +66 -0
- package/dist/content/rules/hatch3r-ruby-rails-patterns.md +111 -0
- package/dist/content/rules/hatch3r-ruby-rails-patterns.mdc +106 -0
- package/dist/content/rules/hatch3r-rust-patterns.md +107 -0
- package/dist/content/rules/hatch3r-rust-patterns.mdc +102 -0
- package/dist/content/rules/hatch3r-scalability.md +137 -0
- package/dist/content/rules/hatch3r-scalability.mdc +132 -0
- package/dist/content/rules/hatch3r-secrets-management.md +10 -1
- package/dist/content/rules/hatch3r-secrets-management.mdc +8 -0
- package/dist/content/rules/hatch3r-security-patterns.md +36 -34
- package/dist/content/rules/hatch3r-security-patterns.mdc +35 -34
- package/dist/content/rules/hatch3r-security.md +97 -0
- package/dist/content/rules/hatch3r-security.mdc +92 -0
- package/dist/content/rules/hatch3r-swiftui-patterns.md +98 -0
- package/dist/content/rules/hatch3r-swiftui-patterns.mdc +93 -0
- package/dist/content/rules/hatch3r-testability.md +115 -0
- package/dist/content/rules/hatch3r-testability.mdc +110 -0
- package/dist/content/rules/hatch3r-testing.md +4 -1
- package/dist/content/rules/hatch3r-testing.mdc +2 -0
- package/dist/content/rules/hatch3r-theming.md +2 -0
- package/dist/content/rules/hatch3r-theming.mdc +2 -0
- package/dist/content/rules/hatch3r-tool-currency.md +91 -0
- package/dist/content/rules/hatch3r-tool-currency.mdc +86 -0
- package/dist/content/rules/hatch3r-tooling-hierarchy.md +29 -31
- package/dist/content/rules/hatch3r-tooling-hierarchy.mdc +27 -30
- package/dist/content/rules/hatch3r-typescript-patterns.md +58 -0
- package/dist/content/rules/hatch3r-typescript-patterns.mdc +53 -0
- package/dist/content/rules/hatch3r-ux-states-and-flows.md +11 -4
- package/dist/content/rules/hatch3r-ux-states-and-flows.mdc +9 -3
- package/dist/content/skills/hatch3r-a11y-audit/SKILL.md +10 -8
- package/dist/content/skills/hatch3r-a11y-audit/references/manual-audit-checklist.md +7 -5
- package/dist/content/skills/hatch3r-adhoc-orchestrate/SKILL.md +131 -0
- package/dist/content/skills/hatch3r-ai-feature/SKILL.md +4 -6
- package/dist/content/skills/hatch3r-api-spec/SKILL.md +27 -2
- package/dist/content/skills/hatch3r-architecture-review/SKILL.md +4 -7
- package/dist/content/skills/hatch3r-board-groom/SKILL.md +11 -0
- package/dist/content/skills/hatch3r-board-init/SKILL.md +17 -1
- package/dist/content/skills/hatch3r-board-refresh/SKILL.md +12 -1
- package/dist/content/skills/hatch3r-board-shared/SKILL.md +38 -1
- package/dist/content/skills/hatch3r-browser-verify/SKILL.md +307 -0
- package/dist/content/skills/hatch3r-bug-fix/SKILL.md +15 -2
- package/dist/content/skills/hatch3r-ci-pipeline/SKILL.md +17 -7
- package/dist/content/skills/hatch3r-cli-fd/SKILL.md +33 -1
- package/dist/content/skills/hatch3r-cli-fzf/SKILL.md +33 -1
- package/dist/content/skills/hatch3r-cli-gh/SKILL.md +50 -1
- package/dist/content/skills/hatch3r-cli-jq/SKILL.md +40 -6
- package/dist/content/skills/hatch3r-cli-ripgrep/SKILL.md +33 -1
- package/dist/content/skills/hatch3r-cli-toolbox/SKILL.md +130 -23
- package/dist/content/skills/hatch3r-containerize/SKILL.md +157 -0
- package/dist/content/skills/hatch3r-context-health/SKILL.md +9 -7
- package/dist/content/skills/hatch3r-cost-tracking/SKILL.md +37 -17
- package/dist/content/skills/hatch3r-customize/SKILL.md +5 -8
- package/dist/content/skills/hatch3r-dep-audit/SKILL.md +23 -7
- package/dist/content/skills/hatch3r-design-system-detect/SKILL.md +3 -7
- package/dist/content/skills/hatch3r-docs-writing/SKILL.md +159 -0
- package/dist/content/skills/hatch3r-enhancability-verify/SKILL.md +152 -0
- package/dist/content/skills/hatch3r-feature/SKILL.md +53 -3
- package/dist/content/skills/hatch3r-feedback/SKILL.md +103 -0
- package/dist/content/skills/hatch3r-gh-agentic-workflows/SKILL.md +10 -8
- package/dist/content/skills/hatch3r-handoff-prepare/SKILL.md +4 -7
- package/dist/content/skills/hatch3r-handoff-resume/SKILL.md +4 -7
- package/dist/content/{commands/hatch3r-hooks.md → skills/hatch3r-hooks/SKILL.md} +48 -137
- package/dist/content/skills/hatch3r-incident-response/SKILL.md +66 -7
- package/dist/content/skills/hatch3r-issue-workflow/SKILL.md +11 -0
- package/dist/content/skills/hatch3r-learn/SKILL.md +317 -0
- package/dist/content/skills/hatch3r-logical-refactor/SKILL.md +6 -7
- package/dist/content/skills/hatch3r-maintainability-verify/SKILL.md +146 -0
- package/dist/content/skills/hatch3r-migration/SKILL.md +8 -7
- package/dist/content/skills/hatch3r-observability-verify/SKILL.md +17 -12
- package/dist/content/skills/hatch3r-perf-audit/SKILL.md +13 -9
- package/dist/content/skills/hatch3r-pr-creation/SKILL.md +4 -7
- package/dist/content/skills/hatch3r-qa-validation/SKILL.md +6 -5
- package/dist/content/skills/hatch3r-recipe/SKILL.md +63 -60
- package/dist/content/skills/hatch3r-refactor/SKILL.md +6 -7
- package/dist/content/skills/hatch3r-release/SKILL.md +123 -11
- package/dist/content/skills/hatch3r-reliability-verify/SKILL.md +9 -5
- package/dist/content/{commands/hatch3r-report.md → skills/hatch3r-report/SKILL.md} +20 -17
- package/dist/content/skills/hatch3r-scalability-verify/SKILL.md +145 -0
- package/dist/content/skills/hatch3r-security-verify/SKILL.md +144 -0
- package/dist/content/skills/hatch3r-team-convention-author/SKILL.md +126 -0
- package/dist/content/skills/hatch3r-testability-verify/SKILL.md +147 -0
- package/dist/content/skills/hatch3r-ui-ux-verify/SKILL.md +19 -11
- package/dist/content/skills/hatch3r-visual-refactor/SKILL.md +11 -7
- package/package.json +50 -31
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.js.map +0 -1
- package/dist/content/agents/hatch3r-a11y-auditor.md +0 -159
- package/dist/content/agents/hatch3r-dependency-auditor.md +0 -219
- package/dist/content/agents/hatch3r-perf-profiler.md +0 -166
- package/dist/content/agents/hatch3r-security-auditor.md +0 -180
- package/dist/content/agents/hatch3r-test-writer.md +0 -171
- package/dist/content/commands/hatch3r-learn.md +0 -312
- package/dist/content/rules/hatch3r-learning-consult.md +0 -42
- package/dist/content/rules/hatch3r-learning-consult.mdc +0 -38
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: hatch3r-flutter-patterns
|
|
3
|
+
type: rule
|
|
4
|
+
description: Flutter and Dart conventions covering null safety, state management (Riverpod/Bloc), Material 3, FFI, performance, platform channels, and integration testing
|
|
5
|
+
scope: conditional
|
|
6
|
+
globs: "**/*.dart,**/pubspec.yaml,**/pubspec.lock,**/analysis_options.yaml,**/build.yaml,**/lib/**,**/test/**,**/integration_test/**,**/ios/Runner/**,**/android/app/**,**/windows/runner/**,**/macos/Runner/**,**/linux/**,**/web/index.html"
|
|
7
|
+
tags: [implementation]
|
|
8
|
+
quality_charter: agents/shared/quality-charter.md
|
|
9
|
+
cache_friendly: true
|
|
10
|
+
---
|
|
11
|
+
# Flutter Patterns
|
|
12
|
+
|
|
13
|
+
**Pillars:** P2 (Scientific & Practical Quality), CQ8 (Maintainability Quality)
|
|
14
|
+
|
|
15
|
+
> Applies when the project ships a Flutter app or Dart package. Detection signals: `pubspec.yaml` with `flutter:` block, `lib/main.dart` entrypoint, or `pubspec.yaml` at repo root.
|
|
16
|
+
|
|
17
|
+
## Dart Language Floor
|
|
18
|
+
|
|
19
|
+
- Use Dart 3.5+ with sound null safety. Every nullable field is explicit (`String?`), every late variable initialized before access. No `!` (bang operator) outside of test fixtures or proven-non-null hot paths.
|
|
20
|
+
- Records and patterns: prefer records (`(int, String)`) and pattern matching (`switch (value) { ... }`) over tuple classes and visitor patterns for simple variant returns.
|
|
21
|
+
- Sealed classes for closed-set hierarchies (state, events, errors): `sealed class AuthState { ... }` + `final class Authenticated extends AuthState { ... }` so the analyzer enforces exhaustive switches.
|
|
22
|
+
- Enable strict analyzer mode in `analysis_options.yaml` with `flutter_lints` plus `very_good_analysis`. Treat warnings as errors in CI.
|
|
23
|
+
|
|
24
|
+
## Project Structure
|
|
25
|
+
|
|
26
|
+
- Feature-first layout under `lib/`: `lib/features/<feature>/{data,domain,presentation}/` with a `lib/core/` for shared utilities. Avoid `lib/widgets/` / `lib/screens/` flat layouts beyond toy apps.
|
|
27
|
+
- Single entrypoint per flavor: `lib/main_dev.dart`, `lib/main_staging.dart`, `lib/main_prod.dart`. Each delegates to a shared `lib/bootstrap.dart` after environment binding.
|
|
28
|
+
- Public APIs documented with `///` doc comments. `dartdoc` runs in CI for the `lib/` public surface — undocumented public APIs are a warning.
|
|
29
|
+
|
|
30
|
+
## State Management
|
|
31
|
+
|
|
32
|
+
- Pick ONE state-management approach per app and document it in `docs/architecture.md`:
|
|
33
|
+
- **Riverpod 2.x** (`flutter_riverpod` + `riverpod_generator`) — recommended default. Code-gen typed providers via `@riverpod` annotations.
|
|
34
|
+
- **Bloc** (`flutter_bloc`) — when the team prefers event-sourcing semantics.
|
|
35
|
+
- **InheritedNotifier / ChangeNotifier** — only for trivial widget-local state. Provider package is in maintenance — do not adopt for new code.
|
|
36
|
+
- Riverpod: prefer `@riverpod`-generated providers over manual `Provider`/`StateProvider`. Async providers return `AsyncValue<T>` — surface `loading` / `error` / `data` states in the UI.
|
|
37
|
+
- Bloc: separate events (input) from states (output). Avoid `setState` inside `BlocBuilder` — all mutation flows via `add(event)` to the bloc.
|
|
38
|
+
- Never call `notifyListeners()` inside `build()`. Never read providers in a constructor.
|
|
39
|
+
|
|
40
|
+
## UI & Material 3
|
|
41
|
+
|
|
42
|
+
- Material 3 (Material You) is the default for Android-leaning apps: `ThemeData(useMaterial3: true)`. Configure `colorSchemeSeed` rather than ad-hoc primary/accent colors so dynamic color works.
|
|
43
|
+
- For iOS-leaning apps, use Cupertino widgets directly or `flutter_platform_widgets` for hybrid surfaces. Do not use `Material` on a `CupertinoPageScaffold`.
|
|
44
|
+
- Responsive layout: use `LayoutBuilder`, `MediaQuery.sizeOf(context)`, and `Flexible`/`Expanded` for breakpoints. Avoid hard-coded pixel widths.
|
|
45
|
+
- Accessibility: every interactive widget has a `Semantics(label: ...)` wrapper or uses a built-in widget that emits semantics. Test with TalkBack (Android) and VoiceOver (iOS); the `flutter_test` semantics tester catches static violations.
|
|
46
|
+
|
|
47
|
+
## Performance
|
|
48
|
+
|
|
49
|
+
- Avoid expensive work in `build()`. Lift `MaterialPageRoute` factories, regex literals, and constant widgets to `const` constructors so Flutter can skip the rebuild.
|
|
50
|
+
- Use `const` constructors aggressively — `const SizedBox(height: 8)` is allocation-free and a major frame-budget win.
|
|
51
|
+
- For long scrollable lists, use `ListView.builder` with `itemExtent` set when row height is uniform. `ListView()` (default) builds every child up-front.
|
|
52
|
+
- Image loading: `cached_network_image` or `flutter_image_compress` for network images. The default `Image.network` does not persist a disk cache.
|
|
53
|
+
- Profile with DevTools: target 60fps on mid-range Android (Pixel 4a class). Frame times above 16ms are regressions; profile the Timeline view for jank.
|
|
54
|
+
|
|
55
|
+
## Platform Channels & FFI
|
|
56
|
+
|
|
57
|
+
- Native interop: prefer `dart:ffi` for synchronous C/C++ bindings (≥10x faster than channels). Use platform channels only when the API is event-driven or requires UI-thread context.
|
|
58
|
+
- `package:ffigen` generates Dart bindings from C headers — never hand-roll `Pointer<Native...>` signatures.
|
|
59
|
+
- Pigeon (`package:pigeon`) generates type-safe platform-channel code from a Dart interface declaration. Stop writing raw `MethodChannel` calls — Pigeon-generated code prevents schema drift.
|
|
60
|
+
|
|
61
|
+
## Testing
|
|
62
|
+
|
|
63
|
+
- Three test layers in `test/` (unit + widget) and `integration_test/` (full app on real device or emulator):
|
|
64
|
+
- Unit tests: pure Dart logic, no Flutter binding. Run with `flutter test`.
|
|
65
|
+
- Widget tests: pumped `WidgetTester` flows with mocked dependencies. Use `find.byKey` over `find.text` for resilience to copy changes.
|
|
66
|
+
- Integration tests: `integration_test/` with `IntegrationTestWidgetsFlutterBinding`. Run on devices via `flutter drive` and on CI matrices.
|
|
67
|
+
- Coverage: `flutter test --coverage` + `lcov` reports. Floor: 80% line coverage in `lib/features/**`; critical features (auth, payments) 90%.
|
|
68
|
+
- Golden tests for visual regressions: `goldenFileComparator` with the `alchemist` package for multi-platform/multi-device goldens. Update goldens via PR review, never blanket-update.
|
|
69
|
+
- Mock HTTP: `package:http_mock_adapter` for Dio, `nock` for `package:http`. Never hit real network in tests.
|
|
70
|
+
|
|
71
|
+
## Builds & Distribution
|
|
72
|
+
|
|
73
|
+
- Flavors via `--flavor` flag + matching Android/iOS configs (`android/app/build.gradle` flavors, `ios/Runner/Configurations`). Bake the API base URL per flavor.
|
|
74
|
+
- App size: enable `--obfuscate --split-debug-info=<path>` for release builds. Track size regressions via `flutter build apk --analyze-size` in CI.
|
|
75
|
+
- Use Codemagic, Bitrise, or Fastlane for store deploys. Sign Android with Play App Signing; iOS via App Store Connect API keys (avoid Apple ID password auth — deprecated).
|
|
76
|
+
|
|
77
|
+
## References
|
|
78
|
+
|
|
79
|
+
- Dart 3 release notes: https://dart.dev/guides/whats-new (accessed 2026-05-27, official-docs)
|
|
80
|
+
- Flutter Material 3: https://docs.flutter.dev/ui/design/material (accessed 2026-05-27, official-docs)
|
|
81
|
+
- Riverpod 2.x: https://riverpod.dev/docs/introduction/getting_started (accessed 2026-05-27, official-docs)
|
|
82
|
+
- Pigeon: https://pub.dev/packages/pigeon (accessed 2026-05-27, official-docs)
|
|
83
|
+
|
|
84
|
+
## Cross-References
|
|
85
|
+
|
|
86
|
+
- `rules/hatch3r-component-conventions.md` — four-state surface contract maps to Flutter `AsyncValue` patterns.
|
|
87
|
+
- `rules/hatch3r-testing.md` — coverage thresholds and determinism rules apply to Dart tests.
|
|
88
|
+
- `rules/hatch3r-accessibility-standards.md` — WCAG mapping for `Semantics` widget usage.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Flutter and Dart conventions covering null safety, state management (Riverpod/Bloc), Material 3, FFI, performance, platform channels, and integration testing
|
|
3
|
+
globs: ["**/*.dart", "**/pubspec.yaml", "**/pubspec.lock", "**/analysis_options.yaml", "**/build.yaml", "**/lib/**", "**/test/**", "**/integration_test/**", "**/ios/Runner/**", "**/android/app/**", "**/windows/runner/**", "**/macos/Runner/**", "**/linux/**", "**/web/index.html"]
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
# Flutter Patterns
|
|
7
|
+
|
|
8
|
+
**Pillars:** P2 (Scientific & Practical Quality), CQ8 (Maintainability Quality)
|
|
9
|
+
|
|
10
|
+
> Applies when the project ships a Flutter app or Dart package. Detection signals: `pubspec.yaml` with `flutter:` block, `lib/main.dart` entrypoint, or `pubspec.yaml` at repo root.
|
|
11
|
+
|
|
12
|
+
## Dart Language Floor
|
|
13
|
+
|
|
14
|
+
- Use Dart 3.5+ with sound null safety. Every nullable field is explicit (`String?`), every late variable initialized before access. No `!` (bang operator) outside of test fixtures or proven-non-null hot paths.
|
|
15
|
+
- Records and patterns: prefer records (`(int, String)`) and pattern matching (`switch (value) { ... }`) over tuple classes and visitor patterns for simple variant returns.
|
|
16
|
+
- Sealed classes for closed-set hierarchies (state, events, errors): `sealed class AuthState { ... }` + `final class Authenticated extends AuthState { ... }` so the analyzer enforces exhaustive switches.
|
|
17
|
+
- Enable strict analyzer mode in `analysis_options.yaml` with `flutter_lints` plus `very_good_analysis`. Treat warnings as errors in CI.
|
|
18
|
+
|
|
19
|
+
## Project Structure
|
|
20
|
+
|
|
21
|
+
- Feature-first layout under `lib/`: `lib/features/<feature>/{data,domain,presentation}/` with a `lib/core/` for shared utilities. Avoid `lib/widgets/` / `lib/screens/` flat layouts beyond toy apps.
|
|
22
|
+
- Single entrypoint per flavor: `lib/main_dev.dart`, `lib/main_staging.dart`, `lib/main_prod.dart`. Each delegates to a shared `lib/bootstrap.dart` after environment binding.
|
|
23
|
+
- Public APIs documented with `///` doc comments. `dartdoc` runs in CI for the `lib/` public surface — undocumented public APIs are a warning.
|
|
24
|
+
|
|
25
|
+
## State Management
|
|
26
|
+
|
|
27
|
+
- Pick ONE state-management approach per app and document it in `docs/architecture.md`:
|
|
28
|
+
- **Riverpod 2.x** (`flutter_riverpod` + `riverpod_generator`) — recommended default. Code-gen typed providers via `@riverpod` annotations.
|
|
29
|
+
- **Bloc** (`flutter_bloc`) — when the team prefers event-sourcing semantics.
|
|
30
|
+
- **InheritedNotifier / ChangeNotifier** — only for trivial widget-local state. Provider package is in maintenance — do not adopt for new code.
|
|
31
|
+
- Riverpod: prefer `@riverpod`-generated providers over manual `Provider`/`StateProvider`. Async providers return `AsyncValue<T>` — surface `loading` / `error` / `data` states in the UI.
|
|
32
|
+
- Bloc: separate events (input) from states (output). Avoid `setState` inside `BlocBuilder` — all mutation flows via `add(event)` to the bloc.
|
|
33
|
+
- Never call `notifyListeners()` inside `build()`. Never read providers in a constructor.
|
|
34
|
+
|
|
35
|
+
## UI & Material 3
|
|
36
|
+
|
|
37
|
+
- Material 3 (Material You) is the default for Android-leaning apps: `ThemeData(useMaterial3: true)`. Configure `colorSchemeSeed` rather than ad-hoc primary/accent colors so dynamic color works.
|
|
38
|
+
- For iOS-leaning apps, use Cupertino widgets directly or `flutter_platform_widgets` for hybrid surfaces. Do not use `Material` on a `CupertinoPageScaffold`.
|
|
39
|
+
- Responsive layout: use `LayoutBuilder`, `MediaQuery.sizeOf(context)`, and `Flexible`/`Expanded` for breakpoints. Avoid hard-coded pixel widths.
|
|
40
|
+
- Accessibility: every interactive widget has a `Semantics(label: ...)` wrapper or uses a built-in widget that emits semantics. Test with TalkBack (Android) and VoiceOver (iOS); the `flutter_test` semantics tester catches static violations.
|
|
41
|
+
|
|
42
|
+
## Performance
|
|
43
|
+
|
|
44
|
+
- Avoid expensive work in `build()`. Lift `MaterialPageRoute` factories, regex literals, and constant widgets to `const` constructors so Flutter can skip the rebuild.
|
|
45
|
+
- Use `const` constructors aggressively — `const SizedBox(height: 8)` is allocation-free and a major frame-budget win.
|
|
46
|
+
- For long scrollable lists, use `ListView.builder` with `itemExtent` set when row height is uniform. `ListView()` (default) builds every child up-front.
|
|
47
|
+
- Image loading: `cached_network_image` or `flutter_image_compress` for network images. The default `Image.network` does not persist a disk cache.
|
|
48
|
+
- Profile with DevTools: target 60fps on mid-range Android (Pixel 4a class). Frame times above 16ms are regressions; profile the Timeline view for jank.
|
|
49
|
+
|
|
50
|
+
## Platform Channels & FFI
|
|
51
|
+
|
|
52
|
+
- Native interop: prefer `dart:ffi` for synchronous C/C++ bindings (≥10x faster than channels). Use platform channels only when the API is event-driven or requires UI-thread context.
|
|
53
|
+
- `package:ffigen` generates Dart bindings from C headers — never hand-roll `Pointer<Native...>` signatures.
|
|
54
|
+
- Pigeon (`package:pigeon`) generates type-safe platform-channel code from a Dart interface declaration. Stop writing raw `MethodChannel` calls — Pigeon-generated code prevents schema drift.
|
|
55
|
+
|
|
56
|
+
## Testing
|
|
57
|
+
|
|
58
|
+
- Three test layers in `test/` (unit + widget) and `integration_test/` (full app on real device or emulator):
|
|
59
|
+
- Unit tests: pure Dart logic, no Flutter binding. Run with `flutter test`.
|
|
60
|
+
- Widget tests: pumped `WidgetTester` flows with mocked dependencies. Use `find.byKey` over `find.text` for resilience to copy changes.
|
|
61
|
+
- Integration tests: `integration_test/` with `IntegrationTestWidgetsFlutterBinding`. Run on devices via `flutter drive` and on CI matrices.
|
|
62
|
+
- Coverage: `flutter test --coverage` + `lcov` reports. Floor: 80% line coverage in `lib/features/**`; critical features (auth, payments) 90%.
|
|
63
|
+
- Golden tests for visual regressions: `goldenFileComparator` with the `alchemist` package for multi-platform/multi-device goldens. Update goldens via PR review, never blanket-update.
|
|
64
|
+
- Mock HTTP: `package:http_mock_adapter` for Dio, `nock` for `package:http`. Never hit real network in tests.
|
|
65
|
+
|
|
66
|
+
## Builds & Distribution
|
|
67
|
+
|
|
68
|
+
- Flavors via `--flavor` flag + matching Android/iOS configs (`android/app/build.gradle` flavors, `ios/Runner/Configurations`). Bake the API base URL per flavor.
|
|
69
|
+
- App size: enable `--obfuscate --split-debug-info=<path>` for release builds. Track size regressions via `flutter build apk --analyze-size` in CI.
|
|
70
|
+
- Use Codemagic, Bitrise, or Fastlane for store deploys. Sign Android with Play App Signing; iOS via App Store Connect API keys (avoid Apple ID password auth — deprecated).
|
|
71
|
+
|
|
72
|
+
## References
|
|
73
|
+
|
|
74
|
+
- Dart 3 release notes: https://dart.dev/guides/whats-new (accessed 2026-05-27, official-docs)
|
|
75
|
+
- Flutter Material 3: https://docs.flutter.dev/ui/design/material (accessed 2026-05-27, official-docs)
|
|
76
|
+
- Riverpod 2.x: https://riverpod.dev/docs/introduction/getting_started (accessed 2026-05-27, official-docs)
|
|
77
|
+
- Pigeon: https://pub.dev/packages/pigeon (accessed 2026-05-27, official-docs)
|
|
78
|
+
|
|
79
|
+
## Cross-References
|
|
80
|
+
|
|
81
|
+
- `rules/hatch3r-component-conventions.md` — four-state surface contract maps to Flutter `AsyncValue` patterns.
|
|
82
|
+
- `rules/hatch3r-testing.md` — coverage thresholds and determinism rules apply to Dart tests.
|
|
83
|
+
- `rules/hatch3r-accessibility-standards.md` — WCAG mapping for `Semantics` widget usage.
|
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
id: hatch3r-git-conventions
|
|
3
3
|
type: rule
|
|
4
4
|
description: Conventional Commits type list, subject line rules, breaking-change footer format, and branch naming template for type/short-description
|
|
5
|
-
scope:
|
|
5
|
+
scope: conditional
|
|
6
|
+
globs: "**/.git/**,**/.gitignore,**/.gitattributes,**/.gitmodules,**/COMMIT_EDITMSG"
|
|
6
7
|
tags: [orchestration]
|
|
7
8
|
quality_charter: agents/shared/quality-charter.md
|
|
8
9
|
cache_friendly: true
|
|
9
10
|
---
|
|
10
11
|
# Git Conventions
|
|
11
12
|
|
|
13
|
+
**Pillars:** P2 (Scientific & Practical Quality), P5 (Governance Self-Quality)
|
|
14
|
+
|
|
12
15
|
## Commit Messages
|
|
13
16
|
|
|
14
17
|
Follow [Conventional Commits](https://www.conventionalcommits.org/):
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: hatch3r-go-patterns
|
|
3
|
+
type: rule
|
|
4
|
+
description: Go 1.23+ conventions covering modules, error wrapping, context propagation, generics, testing with table-driven tests, and the standard library net/http + log/slog
|
|
5
|
+
scope: conditional
|
|
6
|
+
globs: "**/*.go,**/go.mod,**/go.sum,**/go.work,**/go.work.sum,**/Makefile,**/.golangci.yml,**/.golangci.yaml"
|
|
7
|
+
tags: [implementation, lang:go]
|
|
8
|
+
quality_charter: agents/shared/quality-charter.md
|
|
9
|
+
cache_friendly: true
|
|
10
|
+
---
|
|
11
|
+
# Go Patterns
|
|
12
|
+
|
|
13
|
+
**Pillars:** P2 (Scientific & Practical Quality), CQ8 (Maintainability Quality)
|
|
14
|
+
|
|
15
|
+
> Applies when the project ships a Go module or binary. Detection signals: `go.mod` at repo root, `*.go` source files, or `go.work` for multi-module workspaces.
|
|
16
|
+
|
|
17
|
+
## Go Language Floor
|
|
18
|
+
|
|
19
|
+
- Target Go 1.23+ (range-over-int and range-over-func now stable). Use Go modules — `GO111MODULE=on` is the default and `GOPATH` mode is end-of-life for new code.
|
|
20
|
+
- Treat `go vet` and `staticcheck` errors as build failures. Configure `golangci-lint` with `errcheck`, `gosimple`, `govet`, `ineffassign`, `staticcheck`, `unused`, `gosec`, `gocritic` enabled.
|
|
21
|
+
- Use generics (Go 1.18+) for collection / container utilities. Prefer the standard library `slices` / `maps` packages over hand-rolled helpers. Do not retrofit generics onto existing interface-based code without measurable benefit.
|
|
22
|
+
- Format with `gofumpt` (stricter than `gofmt`) in CI. `goimports` for import ordering.
|
|
23
|
+
|
|
24
|
+
## Project Layout
|
|
25
|
+
|
|
26
|
+
- Follow the Standard Project Layout pattern (community convention, not an official Go spec):
|
|
27
|
+
- `cmd/<binary>/main.go` — entrypoints per binary.
|
|
28
|
+
- `internal/` — code not importable outside this module (compiler-enforced).
|
|
29
|
+
- `pkg/` — reusable code imported by other modules. Only create when there is a concrete external consumer; default is `internal/`.
|
|
30
|
+
- `api/` — `.proto` or OpenAPI specs.
|
|
31
|
+
- `web/` — static assets if any.
|
|
32
|
+
- Public API lives in `pkg/`; everything else under `internal/`. Internal-by-default reduces surface area and prevents accidental coupling.
|
|
33
|
+
- Avoid deep nesting. Three levels under `internal/` is a refactor signal.
|
|
34
|
+
|
|
35
|
+
## Error Handling
|
|
36
|
+
|
|
37
|
+
- Always handle errors at the call site. Never use `_ = err` to discard.
|
|
38
|
+
- Wrap with `fmt.Errorf("context: %w", err)` to preserve the chain. Use `errors.Is` / `errors.As` to inspect at the boundary — never compare error strings.
|
|
39
|
+
- Define sentinel errors as `var ErrXyz = errors.New("xyz")` package variables for stable error contracts. For richer payloads, define typed error structs implementing `error` + a `Code() string` method.
|
|
40
|
+
- The error is part of the function signature — design it deliberately. Returning `error` from every function is fine; returning generic `error` when callers need to distinguish causes is a smell.
|
|
41
|
+
|
|
42
|
+
## Concurrency
|
|
43
|
+
|
|
44
|
+
- Use `context.Context` as the first parameter of every function that does I/O or blocking work. Propagate cancellation through every layer.
|
|
45
|
+
- Never call `context.Background()` in library code — accept a context from the caller. `context.TODO()` is only acceptable as a temporary stand-in marked with a `// TODO:` comment.
|
|
46
|
+
- Goroutine lifecycle: every `go func()` has a clear shutdown path. Use `errgroup.Group` for fan-out with error propagation, or `sync.WaitGroup` for fire-and-forget patterns.
|
|
47
|
+
- Channels for ownership-transfer / signaling, mutexes for shared state. Do not chain channels into pseudo-state-machines — use a sync package primitive when the operation is "read/modify/write".
|
|
48
|
+
- Race detector enabled in CI: `go test -race ./...`. A failing race-detector run blocks merge.
|
|
49
|
+
|
|
50
|
+
## HTTP Servers
|
|
51
|
+
|
|
52
|
+
- Use the standard `net/http` + `ServeMux` (Go 1.22+) for new services. The 1.22 `ServeMux` supports method-scoped routes (`POST /users/{id}`) — no third-party router needed for typical APIs.
|
|
53
|
+
- For complex routing requirements: chi (`go-chi/chi`) — minimal, std-lib-compatible. Avoid frameworks that hide `net/http` semantics (gin, fiber) unless the team has explicit performance evidence.
|
|
54
|
+
- Middleware: function composition pattern — `func(http.Handler) http.Handler`. Order matters: logging → recovery → auth → rate-limit → handler.
|
|
55
|
+
- Server timeouts: always set `ReadHeaderTimeout`, `ReadTimeout`, `WriteTimeout`, `IdleTimeout` on `http.Server`. Default timeouts are 0 (unbounded) — production servers must override.
|
|
56
|
+
- Graceful shutdown: `server.Shutdown(ctx)` on `SIGTERM` / `SIGINT`. Bound shutdown with a context timeout (e.g., 30s) and force-close on expiry.
|
|
57
|
+
|
|
58
|
+
## Logging & Observability
|
|
59
|
+
|
|
60
|
+
- Use `log/slog` (standard library, Go 1.21+) for structured logging. Configure a JSON handler in production, text handler in development.
|
|
61
|
+
- Always emit a request-scoped logger from middleware: `logger := slog.With("request_id", id)` and store in `context`. Handlers retrieve via `slog.Default()` from context. Never use the package-level logger inside request paths.
|
|
62
|
+
- Tracing: OpenTelemetry Go SDK (`go.opentelemetry.io/otel`). Wrap HTTP handlers with `otelhttp.NewHandler` and outbound HTTP clients with `otelhttp.NewTransport`. Avoid handcrafted span creation in business logic.
|
|
63
|
+
|
|
64
|
+
## Testing
|
|
65
|
+
|
|
66
|
+
- Table-driven tests are the floor: `tests := []struct { name string; ... }` + `for _, tc := range tests { t.Run(tc.name, ...) }`. Subtests give per-case isolation.
|
|
67
|
+
- Use `t.Parallel()` inside subtests for I/O-bound suites. Race-detector in CI catches data races introduced by parallelism.
|
|
68
|
+
- Mocking: prefer hand-rolled fakes implementing the interface. `gomock` / `mockery` only when the interface surface is wide (>5 methods) and stable.
|
|
69
|
+
- HTTP tests with `httptest.NewServer` for integration, `httptest.NewRecorder` + handler call for unit tests. Never start a real network listener for unit tests.
|
|
70
|
+
- Coverage: `go test -coverprofile=cover.out ./...`. Floor: 80% statement coverage in `pkg/` and `internal/`; critical paths (auth, billing) at 90%.
|
|
71
|
+
- `go test -fuzz=Fuzz` for fuzz testing untrusted-input parsers — at least one fuzz target per public parser.
|
|
72
|
+
|
|
73
|
+
## Concurrency Idioms
|
|
74
|
+
|
|
75
|
+
- Errgroup for parallel work that must all succeed or fail together: `g, ctx := errgroup.WithContext(ctx)`; on first error, the context cancels remaining workers.
|
|
76
|
+
- Semaphore (`golang.org/x/sync/semaphore`) for bounded concurrency: limit DB connections, HTTP calls, file handles.
|
|
77
|
+
- Singleflight (`golang.org/x/sync/singleflight`) to deduplicate concurrent fetches of the same key (cache miss storms).
|
|
78
|
+
- Avoid `time.Sleep` for backoff — use `time.NewTimer` with context-aware cancellation. Sleep cannot be interrupted by context cancellation.
|
|
79
|
+
|
|
80
|
+
## Dependency Hygiene
|
|
81
|
+
|
|
82
|
+
- `go mod tidy` on every PR — drift between `go.mod` and imports is a merge blocker.
|
|
83
|
+
- Pin dependencies via `go.sum`. Use `go mod verify` in CI to catch supply-chain tampering.
|
|
84
|
+
- Vulnerability scanning: `govulncheck` (official Go tool) in CI. Block merge on known CVE matches in the dependency graph.
|
|
85
|
+
- Avoid `replace` directives in `go.mod` for production builds — they suggest unresolved upstream issues. Acceptable in development with a `// TODO: remove when upstream merges PR#X` comment.
|
|
86
|
+
|
|
87
|
+
## References
|
|
88
|
+
|
|
89
|
+
- Go 1.23 release notes: https://go.dev/doc/go1.23 (accessed 2026-05-27, official-docs)
|
|
90
|
+
- log/slog: https://pkg.go.dev/log/slog (accessed 2026-05-27, official-docs)
|
|
91
|
+
- net/http ServeMux 1.22+: https://go.dev/blog/routing-enhancements (accessed 2026-05-27, official-docs)
|
|
92
|
+
- Effective Go: https://go.dev/doc/effective_go (accessed 2026-05-27, official-docs)
|
|
93
|
+
|
|
94
|
+
## Cross-References
|
|
95
|
+
|
|
96
|
+
- `rules/hatch3r-api-design.md` — REST/GraphQL/gRPC contract floors apply to Go services.
|
|
97
|
+
- `rules/hatch3r-testing.md` — coverage thresholds carry over to `go test -cover`.
|
|
98
|
+
- `rules/hatch3r-observability-logging.md` — slog integration with the canonical logging contract.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Go 1.23+ conventions covering modules, error wrapping, context propagation, generics, testing with table-driven tests, and the standard library net/http + log/slog
|
|
3
|
+
globs: ["**/*.go", "**/go.mod", "**/go.sum", "**/go.work", "**/go.work.sum", "**/Makefile", "**/.golangci.yml", "**/.golangci.yaml"]
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
# Go Patterns
|
|
7
|
+
|
|
8
|
+
**Pillars:** P2 (Scientific & Practical Quality), CQ8 (Maintainability Quality)
|
|
9
|
+
|
|
10
|
+
> Applies when the project ships a Go module or binary. Detection signals: `go.mod` at repo root, `*.go` source files, or `go.work` for multi-module workspaces.
|
|
11
|
+
|
|
12
|
+
## Go Language Floor
|
|
13
|
+
|
|
14
|
+
- Target Go 1.23+ (range-over-int and range-over-func now stable). Use Go modules — `GO111MODULE=on` is the default and `GOPATH` mode is end-of-life for new code.
|
|
15
|
+
- Treat `go vet` and `staticcheck` errors as build failures. Configure `golangci-lint` with `errcheck`, `gosimple`, `govet`, `ineffassign`, `staticcheck`, `unused`, `gosec`, `gocritic` enabled.
|
|
16
|
+
- Use generics (Go 1.18+) for collection / container utilities. Prefer the standard library `slices` / `maps` packages over hand-rolled helpers. Do not retrofit generics onto existing interface-based code without measurable benefit.
|
|
17
|
+
- Format with `gofumpt` (stricter than `gofmt`) in CI. `goimports` for import ordering.
|
|
18
|
+
|
|
19
|
+
## Project Layout
|
|
20
|
+
|
|
21
|
+
- Follow the Standard Project Layout pattern (community convention, not an official Go spec):
|
|
22
|
+
- `cmd/<binary>/main.go` — entrypoints per binary.
|
|
23
|
+
- `internal/` — code not importable outside this module (compiler-enforced).
|
|
24
|
+
- `pkg/` — reusable code imported by other modules. Only create when there is a concrete external consumer; default is `internal/`.
|
|
25
|
+
- `api/` — `.proto` or OpenAPI specs.
|
|
26
|
+
- `web/` — static assets if any.
|
|
27
|
+
- Public API lives in `pkg/`; everything else under `internal/`. Internal-by-default reduces surface area and prevents accidental coupling.
|
|
28
|
+
- Avoid deep nesting. Three levels under `internal/` is a refactor signal.
|
|
29
|
+
|
|
30
|
+
## Error Handling
|
|
31
|
+
|
|
32
|
+
- Always handle errors at the call site. Never use `_ = err` to discard.
|
|
33
|
+
- Wrap with `fmt.Errorf("context: %w", err)` to preserve the chain. Use `errors.Is` / `errors.As` to inspect at the boundary — never compare error strings.
|
|
34
|
+
- Define sentinel errors as `var ErrXyz = errors.New("xyz")` package variables for stable error contracts. For richer payloads, define typed error structs implementing `error` + a `Code() string` method.
|
|
35
|
+
- The error is part of the function signature — design it deliberately. Returning `error` from every function is fine; returning generic `error` when callers need to distinguish causes is a smell.
|
|
36
|
+
|
|
37
|
+
## Concurrency
|
|
38
|
+
|
|
39
|
+
- Use `context.Context` as the first parameter of every function that does I/O or blocking work. Propagate cancellation through every layer.
|
|
40
|
+
- Never call `context.Background()` in library code — accept a context from the caller. `context.TODO()` is only acceptable as a temporary stand-in marked with a `// TODO:` comment.
|
|
41
|
+
- Goroutine lifecycle: every `go func()` has a clear shutdown path. Use `errgroup.Group` for fan-out with error propagation, or `sync.WaitGroup` for fire-and-forget patterns.
|
|
42
|
+
- Channels for ownership-transfer / signaling, mutexes for shared state. Do not chain channels into pseudo-state-machines — use a sync package primitive when the operation is "read/modify/write".
|
|
43
|
+
- Race detector enabled in CI: `go test -race ./...`. A failing race-detector run blocks merge.
|
|
44
|
+
|
|
45
|
+
## HTTP Servers
|
|
46
|
+
|
|
47
|
+
- Use the standard `net/http` + `ServeMux` (Go 1.22+) for new services. The 1.22 `ServeMux` supports method-scoped routes (`POST /users/{id}`) — no third-party router needed for typical APIs.
|
|
48
|
+
- For complex routing requirements: chi (`go-chi/chi`) — minimal, std-lib-compatible. Avoid frameworks that hide `net/http` semantics (gin, fiber) unless the team has explicit performance evidence.
|
|
49
|
+
- Middleware: function composition pattern — `func(http.Handler) http.Handler`. Order matters: logging → recovery → auth → rate-limit → handler.
|
|
50
|
+
- Server timeouts: always set `ReadHeaderTimeout`, `ReadTimeout`, `WriteTimeout`, `IdleTimeout` on `http.Server`. Default timeouts are 0 (unbounded) — production servers must override.
|
|
51
|
+
- Graceful shutdown: `server.Shutdown(ctx)` on `SIGTERM` / `SIGINT`. Bound shutdown with a context timeout (e.g., 30s) and force-close on expiry.
|
|
52
|
+
|
|
53
|
+
## Logging & Observability
|
|
54
|
+
|
|
55
|
+
- Use `log/slog` (standard library, Go 1.21+) for structured logging. Configure a JSON handler in production, text handler in development.
|
|
56
|
+
- Always emit a request-scoped logger from middleware: `logger := slog.With("request_id", id)` and store in `context`. Handlers retrieve via `slog.Default()` from context. Never use the package-level logger inside request paths.
|
|
57
|
+
- Tracing: OpenTelemetry Go SDK (`go.opentelemetry.io/otel`). Wrap HTTP handlers with `otelhttp.NewHandler` and outbound HTTP clients with `otelhttp.NewTransport`. Avoid handcrafted span creation in business logic.
|
|
58
|
+
|
|
59
|
+
## Testing
|
|
60
|
+
|
|
61
|
+
- Table-driven tests are the floor: `tests := []struct { name string; ... }` + `for _, tc := range tests { t.Run(tc.name, ...) }`. Subtests give per-case isolation.
|
|
62
|
+
- Use `t.Parallel()` inside subtests for I/O-bound suites. Race-detector in CI catches data races introduced by parallelism.
|
|
63
|
+
- Mocking: prefer hand-rolled fakes implementing the interface. `gomock` / `mockery` only when the interface surface is wide (>5 methods) and stable.
|
|
64
|
+
- HTTP tests with `httptest.NewServer` for integration, `httptest.NewRecorder` + handler call for unit tests. Never start a real network listener for unit tests.
|
|
65
|
+
- Coverage: `go test -coverprofile=cover.out ./...`. Floor: 80% statement coverage in `pkg/` and `internal/`; critical paths (auth, billing) at 90%.
|
|
66
|
+
- `go test -fuzz=Fuzz` for fuzz testing untrusted-input parsers — at least one fuzz target per public parser.
|
|
67
|
+
|
|
68
|
+
## Concurrency Idioms
|
|
69
|
+
|
|
70
|
+
- Errgroup for parallel work that must all succeed or fail together: `g, ctx := errgroup.WithContext(ctx)`; on first error, the context cancels remaining workers.
|
|
71
|
+
- Semaphore (`golang.org/x/sync/semaphore`) for bounded concurrency: limit DB connections, HTTP calls, file handles.
|
|
72
|
+
- Singleflight (`golang.org/x/sync/singleflight`) to deduplicate concurrent fetches of the same key (cache miss storms).
|
|
73
|
+
- Avoid `time.Sleep` for backoff — use `time.NewTimer` with context-aware cancellation. Sleep cannot be interrupted by context cancellation.
|
|
74
|
+
|
|
75
|
+
## Dependency Hygiene
|
|
76
|
+
|
|
77
|
+
- `go mod tidy` on every PR — drift between `go.mod` and imports is a merge blocker.
|
|
78
|
+
- Pin dependencies via `go.sum`. Use `go mod verify` in CI to catch supply-chain tampering.
|
|
79
|
+
- Vulnerability scanning: `govulncheck` (official Go tool) in CI. Block merge on known CVE matches in the dependency graph.
|
|
80
|
+
- Avoid `replace` directives in `go.mod` for production builds — they suggest unresolved upstream issues. Acceptable in development with a `// TODO: remove when upstream merges PR#X` comment.
|
|
81
|
+
|
|
82
|
+
## References
|
|
83
|
+
|
|
84
|
+
- Go 1.23 release notes: https://go.dev/doc/go1.23 (accessed 2026-05-27, official-docs)
|
|
85
|
+
- log/slog: https://pkg.go.dev/log/slog (accessed 2026-05-27, official-docs)
|
|
86
|
+
- net/http ServeMux 1.22+: https://go.dev/blog/routing-enhancements (accessed 2026-05-27, official-docs)
|
|
87
|
+
- Effective Go: https://go.dev/doc/effective_go (accessed 2026-05-27, official-docs)
|
|
88
|
+
|
|
89
|
+
## Cross-References
|
|
90
|
+
|
|
91
|
+
- `rules/hatch3r-api-design.md` — REST/GraphQL/gRPC contract floors apply to Go services.
|
|
92
|
+
- `rules/hatch3r-testing.md` — coverage thresholds carry over to `go test -cover`.
|
|
93
|
+
- `rules/hatch3r-observability-logging.md` — slog integration with the canonical logging contract.
|
|
@@ -37,6 +37,16 @@ Before writing a handoff to `.hatch3r/handoffs/active/`, verify each criterion.
|
|
|
37
37
|
|
|
38
38
|
The `hatch3r-handoff-preparer` agent applies this checklist before invoking `writeHandoff` in `src/content/handoffs/index.ts`. The `validateHandoffContent` function in `src/content/handoffs/validation.ts` runs criteria 1-7 as `errors[]` and 8-10 as `warnings[]`.
|
|
39
39
|
|
|
40
|
+
## Retro-Discredit Rule (D13 — handoff self-assessment trust gate)
|
|
41
|
+
|
|
42
|
+
Handoff confidence and completeness are self-rated by the preparing agent. When the resuming agent (or human) detects that the prior handoff overstated completeness — work flagged Done but reverted, tests claimed passing but failing on resume, blockers omitted — the resumer MUST:
|
|
43
|
+
|
|
44
|
+
1. Append a `retro_discredit:` block to the handoff manifest (`.hatch3r/handoffs/active/<id>.md` frontmatter) with: `discredited_by: <resumer-id-or-human>`, `discredited_on: <ISO-8601>`, `discredit_reason: <one-sentence cause>`, `prior_confidence: <high|medium|low>`, `effective_confidence: <high|medium|low>` (downgraded post-discredit).
|
|
45
|
+
2. Append a single line to `.hatch3r/handoffs/discredit-log.jsonl` (append-only, atomic append per `src/merge/safeWrite.ts`) with `{ts, handoff_id, discredited_by, prior_confidence, effective_confidence, reason}`.
|
|
46
|
+
3. The `hatch3r-handoff-preparer` and `hatch3r-handoff-loader` agents consult the discredit-log on next write/read — if a handoff's preparer has a discredit ratio above 25% across the last 10 handoffs, downgrade the new handoff's preparer-rated confidence one band before accepting.
|
|
47
|
+
|
|
48
|
+
Effect: self-assessed confidence becomes a track-record signal rather than a single-shot self-claim. Closes D13 SA13.4 F2 retro path (resumer undoes prior work but the handoff's confidence rating persists unchallenged).
|
|
49
|
+
|
|
40
50
|
## Cross-references
|
|
41
51
|
|
|
42
52
|
- Body sections schema: `.hatch3r/handoffs/README.md`
|
|
@@ -32,6 +32,16 @@ Before writing a handoff to `.hatch3r/handoffs/active/`, verify each criterion.
|
|
|
32
32
|
|
|
33
33
|
The `hatch3r-handoff-preparer` agent applies this checklist before invoking `writeHandoff` in `src/content/handoffs/index.ts`. The `validateHandoffContent` function in `src/content/handoffs/validation.ts` runs criteria 1-7 as `errors[]` and 8-10 as `warnings[]`.
|
|
34
34
|
|
|
35
|
+
## Retro-Discredit Rule (D13 — handoff self-assessment trust gate)
|
|
36
|
+
|
|
37
|
+
Handoff confidence and completeness are self-rated by the preparing agent. When the resuming agent (or human) detects that the prior handoff overstated completeness — work flagged Done but reverted, tests claimed passing but failing on resume, blockers omitted — the resumer MUST:
|
|
38
|
+
|
|
39
|
+
1. Append a `retro_discredit:` block to the handoff manifest (`.hatch3r/handoffs/active/<id>.md` frontmatter) with: `discredited_by: <resumer-id-or-human>`, `discredited_on: <ISO-8601>`, `discredit_reason: <one-sentence cause>`, `prior_confidence: <high|medium|low>`, `effective_confidence: <high|medium|low>` (downgraded post-discredit).
|
|
40
|
+
2. Append a single line to `.hatch3r/handoffs/discredit-log.jsonl` (append-only, atomic append per `src/merge/safeWrite.ts`) with `{ts, handoff_id, discredited_by, prior_confidence, effective_confidence, reason}`.
|
|
41
|
+
3. The `hatch3r-handoff-preparer` and `hatch3r-handoff-loader` agents consult the discredit-log on next write/read — if a handoff's preparer has a discredit ratio above 25% across the last 10 handoffs, downgrade the new handoff's preparer-rated confidence one band before accepting.
|
|
42
|
+
|
|
43
|
+
Effect: self-assessed confidence becomes a track-record signal rather than a single-shot self-claim. Closes D13 SA13.4 F2 retro path (resumer undoes prior work but the handoff's confidence rating persists unchallenged).
|
|
44
|
+
|
|
35
45
|
## Cross-references
|
|
36
46
|
|
|
37
47
|
- Body sections schema: `.hatch3r/handoffs/README.md`
|
|
@@ -10,6 +10,8 @@ cache_friendly: true
|
|
|
10
10
|
---
|
|
11
11
|
# Internationalization & RTL
|
|
12
12
|
|
|
13
|
+
**Pillars:** P2 (Scientific & Practical Quality), CQ2 (UX Quality)
|
|
14
|
+
|
|
13
15
|
## Locale Management
|
|
14
16
|
|
|
15
17
|
- Detect locale via resolution chain: explicit user preference → `Accept-Language` header (server) → `navigator.language` (client) → default locale.
|
|
@@ -5,6 +5,8 @@ alwaysApply: false
|
|
|
5
5
|
---
|
|
6
6
|
# Internationalization & RTL
|
|
7
7
|
|
|
8
|
+
**Pillars:** P2 (Scientific & Practical Quality), CQ2 (UX Quality)
|
|
9
|
+
|
|
8
10
|
## Locale Management
|
|
9
11
|
|
|
10
12
|
- Detect locale via resolution chain: explicit user preference → `Accept-Language` header (server) → `navigator.language` (client) → default locale.
|