@yandy-r/ycc-opencode 0.0.0-stage → 6.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/AGENTS.md +38 -0
- package/LICENSE +21 -0
- package/README.md +41 -2
- package/agents/ansible-automation-expert.md +115 -0
- package/agents/api-docs-expert.md +146 -0
- package/agents/api-documenter.md +105 -0
- package/agents/architect.md +264 -0
- package/agents/architecture-analyst.md +99 -0
- package/agents/backport-conflict-resolver.md +134 -0
- package/agents/cloudflare-architect.md +85 -0
- package/agents/cloudflare-developer.md +196 -0
- package/agents/code-architect.md +101 -0
- package/agents/code-documenter.md +114 -0
- package/agents/code-explorer.md +99 -0
- package/agents/code-finder.md +83 -0
- package/agents/code-researcher.md +102 -0
- package/agents/code-reviewer.md +268 -0
- package/agents/code-simplifier.md +77 -0
- package/agents/codebase-advisor.md +130 -0
- package/agents/db-modifier.md +235 -0
- package/agents/docs-git-committer.md +220 -0
- package/agents/documentation-writer.md +92 -0
- package/agents/feature-researcher.md +121 -0
- package/agents/feature-writer.md +89 -0
- package/agents/frontend-ui-developer.md +98 -0
- package/agents/git-cleanup.md +173 -0
- package/agents/go-api-architect.md +172 -0
- package/agents/go-expert-architect.md +147 -0
- package/agents/implementor.md +167 -0
- package/agents/library-docs-writer.md +128 -0
- package/agents/nextjs-ux-ui-expert.md +127 -0
- package/agents/nodejs-backend-architect.md +112 -0
- package/agents/nodejs-backend-developer.md +184 -0
- package/agents/planner.md +257 -0
- package/agents/pr-comment-fixer.md +284 -0
- package/agents/practices-researcher.md +80 -0
- package/agents/project-file-cleaner.md +140 -0
- package/agents/prp-researcher.md +231 -0
- package/agents/python-developer.md +171 -0
- package/agents/python-expert-architect.md +188 -0
- package/agents/readme-generator.md +100 -0
- package/agents/release-fix-applier.md +194 -0
- package/agents/releaser.md +147 -0
- package/agents/research-specialist.md +106 -0
- package/agents/reverse-proxy-architect.md +131 -0
- package/agents/review-fixer.md +264 -0
- package/agents/root-cause-analyzer.md +105 -0
- package/agents/rust-build-resolver.md +183 -0
- package/agents/rust-expert-architect.md +149 -0
- package/agents/rust-reviewer.md +126 -0
- package/agents/sql-database-developer.md +195 -0
- package/agents/systems-engineering-expert.md +203 -0
- package/agents/terraform-architect.md +109 -0
- package/agents/terraform-developer.md +229 -0
- package/agents/test-strategy-planner.md +126 -0
- package/agents/turso-database-architect.md +139 -0
- package/agents/typescript-developer.md +170 -0
- package/agents/typescript-expert-architect.md +167 -0
- package/index.js +260 -0
- package/package.json +35 -4
- package/registration.json +4384 -0
- package/shared/references/agent-native-setup.md +121 -0
- package/shared/references/branch-prep.md +31 -0
- package/shared/references/branching-model.md +162 -0
- package/shared/references/ci-monitoring.md +445 -0
- package/shared/references/forge-detection.md +162 -0
- package/shared/references/goal-pairing.md +53 -0
- package/shared/references/pr-base-and-backport.md +143 -0
- package/shared/references/review-artifact-format.md +141 -0
- package/shared/references/review-checklist.md +161 -0
- package/shared/references/review-dispatch.md +71 -0
- package/shared/references/session-state.md +159 -0
- package/shared/references/standalone-dispatch.md +298 -0
- package/shared/references/target-capability-matrix.md +325 -0
- package/shared/references/visual-mode.md +155 -0
- package/shared/references/worktree-strategy.md +310 -0
- package/shared/scripts/backport-audit.sh +283 -0
- package/shared/scripts/ci-monitor.sh +637 -0
- package/shared/scripts/lib/backport-lib.sh +47 -0
- package/shared/scripts/lib/ci-classify.sh +103 -0
- package/shared/scripts/lib/forge.sh +264 -0
- package/shared/scripts/lib/release-state-lib.sh +300 -0
- package/shared/scripts/list-worktrees.sh +178 -0
- package/shared/scripts/merge-children.sh +82 -0
- package/shared/scripts/move-plan-to-worktree.sh +231 -0
- package/shared/scripts/pr-guard.sh +283 -0
- package/shared/scripts/prepare-feature-branch.sh +326 -0
- package/shared/scripts/release-ci-monitor.sh +671 -0
- package/shared/scripts/release-state-update.sh +216 -0
- package/shared/scripts/release-state.sh +178 -0
- package/shared/scripts/report-bundle-drift.sh +343 -0
- package/shared/scripts/require-python.sh +17 -0
- package/shared/scripts/resolve-plans-dir.sh +262 -0
- package/shared/scripts/rules-pointer.sh +20 -0
- package/shared/scripts/rules_pointer.py +267 -0
- package/shared/scripts/setup-worktree.sh +288 -0
- package/shared/scripts/validate-file-paths.sh +249 -0
- package/shared/scripts/visual-egress-guard.sh +303 -0
- package/shared/scripts/visual-recap-collect.sh +247 -0
- package/shared/scripts/worktree-paths.sh +86 -0
- package/skills/backport/SKILL.md +291 -0
- package/skills/backport/scripts/cherry-pick-pr.sh +232 -0
- package/skills/backport/scripts/find-pending.sh +199 -0
- package/skills/blueprint/SKILL.md +410 -0
- package/skills/blueprint/references/bootstrap-mapping.md +87 -0
- package/skills/bundle-author/SKILL.md +119 -0
- package/skills/bundle-author/references/surface-map.md +128 -0
- package/skills/bundle-author/references/templates/agent-template.md +21 -0
- package/skills/bundle-author/references/templates/skill-template.md +36 -0
- package/skills/bundle-author/references/when-not-to-scaffold.md +85 -0
- package/skills/bundle-author/scripts/scaffold-skill.sh +156 -0
- package/skills/bundle-release/SKILL.md +188 -0
- package/skills/bundle-release/references/release-checklist.md +196 -0
- package/skills/bundle-release/references/release-notes-template.md +48 -0
- package/skills/bundle-release/references/version-policy.md +150 -0
- package/skills/bundle-release/scripts/bump-version.sh +97 -0
- package/skills/bundle-release/scripts/draft-notes.sh +222 -0
- package/skills/bundle-release/scripts/preflight.sh +164 -0
- package/skills/bundle-release/scripts/release_versions.py +361 -0
- package/skills/clean/SKILL.md +107 -0
- package/skills/clean/references/agent-prompts.md +199 -0
- package/skills/clean/references/safety-config.md +125 -0
- package/skills/clean/scripts/detect-project-type.sh +423 -0
- package/skills/clean/scripts/generate-report.sh +245 -0
- package/skills/clean/scripts/validate-safety.sh +401 -0
- package/skills/code-report/SKILL.md +375 -0
- package/skills/code-report/scripts/check-prerequisites.sh +65 -0
- package/skills/code-report/templates/report-structure.md +202 -0
- package/skills/code-review/SKILL.md +153 -0
- package/skills/code-review/references/pr-procedure.md +311 -0
- package/skills/compatibility-audit/SKILL.md +226 -0
- package/skills/compatibility-audit/references/reading-the-report.md +159 -0
- package/skills/compatibility-audit/scripts/audit-install-assumptions.sh +372 -0
- package/skills/compatibility-audit/scripts/audit-target-features.sh +558 -0
- package/skills/deep-research/SKILL.md +251 -0
- package/skills/deep-research/references/analysis-prompts.md +702 -0
- package/skills/deep-research/references/completion-summary-template.md +66 -0
- package/skills/deep-research/references/persona-analogical.md +159 -0
- package/skills/deep-research/references/persona-archaeological.md +69 -0
- package/skills/deep-research/references/persona-contrarian.md +155 -0
- package/skills/deep-research/references/persona-futurist.md +70 -0
- package/skills/deep-research/references/persona-historical.md +142 -0
- package/skills/deep-research/references/persona-journalistic.md +69 -0
- package/skills/deep-research/references/persona-negative-space.md +70 -0
- package/skills/deep-research/references/persona-systems.md +69 -0
- package/skills/deep-research/references/synthesis-template.md +569 -0
- package/skills/deep-research/references/verification-log-template.md +32 -0
- package/skills/deep-research/scripts/check-prerequisites.sh +153 -0
- package/skills/deep-research/scripts/validate-research.sh +244 -0
- package/skills/feature-research/SKILL.md +292 -0
- package/skills/feature-research/scripts/validate-research.sh +159 -0
- package/skills/feature-research/scripts/validate-spec.sh +270 -0
- package/skills/feature-research/templates/research-agents.md +569 -0
- package/skills/feature-research/templates/spec-structure.md +437 -0
- package/skills/formatters/SKILL.md +207 -0
- package/skills/formatters/references/best-practices.md +78 -0
- package/skills/formatters/references/flag-reference.md +178 -0
- package/skills/formatters/references/stack-detection.md +119 -0
- package/skills/formatters/references/templates/husky-pre-commit.tmpl +13 -0
- package/skills/formatters/references/templates/justfile-snippet.just.tmpl +31 -0
- package/skills/formatters/references/templates/lefthook.yml.tmpl +22 -0
- package/skills/formatters/references/templates/lint-autofix.yml.tmpl +94 -0
- package/skills/formatters/references/templates/lint.yml.tmpl +85 -0
- package/skills/formatters/references/templates/makefile-snippet.mk.tmpl +34 -0
- package/skills/formatters/references/templates/package-json-scripts.json.tmpl +14 -0
- package/skills/formatters/references/templates/readme-section.md.tmpl +118 -0
- package/skills/formatters/scripts/apply-aliases.sh +245 -0
- package/skills/formatters/scripts/apply-ci.sh +136 -0
- package/skills/formatters/scripts/apply-docs.sh +187 -0
- package/skills/formatters/scripts/apply-hooks.sh +261 -0
- package/skills/formatters/scripts/bundle/format.sh +15 -0
- package/skills/formatters/scripts/bundle/go-tools.sh +119 -0
- package/skills/formatters/scripts/bundle/init-formatters.sh +517 -0
- package/skills/formatters/scripts/bundle/install-shellcheck.sh +85 -0
- package/skills/formatters/scripts/bundle/lib/excludes.sh +179 -0
- package/skills/formatters/scripts/bundle/lib/modified-files.sh +222 -0
- package/skills/formatters/scripts/bundle/lib/shellcheck-resolve.sh +81 -0
- package/skills/formatters/scripts/bundle/lib/shellcheck-version.sh +5 -0
- package/skills/formatters/scripts/bundle/lint.sh +15 -0
- package/skills/formatters/scripts/bundle/style.sh +1410 -0
- package/skills/formatters/scripts/bundle/templates/biome.json +81 -0
- package/skills/formatters/scripts/bundle/templates/clippy.toml +2 -0
- package/skills/formatters/scripts/bundle/templates/markdownlint.json +14 -0
- package/skills/formatters/scripts/bundle/templates/markdownlintignore +38 -0
- package/skills/formatters/scripts/bundle/templates/prettierignore +45 -0
- package/skills/formatters/scripts/bundle/templates/prettierrc.json +11 -0
- package/skills/formatters/scripts/bundle/templates/python-pyproject.toml +80 -0
- package/skills/formatters/scripts/bundle/templates/rustfmt.toml +41 -0
- package/skills/formatters/scripts/bundle/templates/tsconfig.json +21 -0
- package/skills/formatters/scripts/profile-style.sh +264 -0
- package/skills/frontend-design/SKILL.md +151 -0
- package/skills/frontend-patterns/SKILL.md +66 -0
- package/skills/frontend-patterns/references/animation.md +21 -0
- package/skills/frontend-patterns/references/components-and-state.md +40 -0
- package/skills/frontend-patterns/references/data-and-performance.md +34 -0
- package/skills/frontend-patterns/references/forms-errors-a11y.md +35 -0
- package/skills/git-cleanup/SKILL.md +286 -0
- package/skills/git-cleanup/references/active-code-rules.md +318 -0
- package/skills/git-cleanup/references/host-detection.md +217 -0
- package/skills/git-workflow/SKILL.md +130 -0
- package/skills/git-workflow/references/ci-monitoring-phase.md +130 -0
- package/skills/git-workflow/references/commit-phases.md +247 -0
- package/skills/git-workflow/references/examples-and-troubleshooting.md +47 -0
- package/skills/git-workflow/references/goal-pairing.md +23 -0
- package/skills/git-workflow/references/pr-creation.md +269 -0
- package/skills/git-workflow/scripts/analyze-changes.sh +266 -0
- package/skills/git-workflow/scripts/create-pr.sh +464 -0
- package/skills/git-workflow/scripts/validate-commit.sh +235 -0
- package/skills/git-workflow/templates/agent-prompts.md +518 -0
- package/skills/git-workflow/templates/commit-types.md +504 -0
- package/skills/git-workflow/templates/documentation-decision.md +509 -0
- package/skills/git-workflow/templates/pr-template.md +772 -0
- package/skills/go-patterns/SKILL.md +89 -0
- package/skills/go-patterns/references/design-and-tooling.md +336 -0
- package/skills/go-patterns/references/errors-and-concurrency.md +292 -0
- package/skills/go-testing/SKILL.md +133 -0
- package/skills/go-testing/references/advanced-testing.md +349 -0
- package/skills/go-testing/references/test-structure.md +277 -0
- package/skills/hooks-workflow/SKILL.md +232 -0
- package/skills/hooks-workflow/references/support-notes.md +134 -0
- package/skills/hooks-workflow/references/templates/claude-settings.json.tmpl +13 -0
- package/skills/hooks-workflow/references/templates/codex-config-fragment.toml.tmpl +9 -0
- package/skills/hooks-workflow/references/templates/cursor-rule-fragment.mdc.tmpl +16 -0
- package/skills/hooks-workflow/scripts/build-hook-config.sh +487 -0
- package/skills/hooks-workflow/scripts/verify-hooks.sh +257 -0
- package/skills/implement-plan/SKILL.md +221 -0
- package/skills/implement-plan/references/agent-task-prompt.md +214 -0
- package/skills/implement-plan/references/output-formats.md +150 -0
- package/skills/implement-plan/references/plan-inputs.md +126 -0
- package/skills/implement-plan/scripts/check-prerequisites.sh +78 -0
- package/skills/implement-plan/scripts/parse-dependencies.sh +206 -0
- package/skills/init/SKILL.md +272 -0
- package/skills/init/references/conventional-commits.md +114 -0
- package/skills/init/references/flag-reference.md +236 -0
- package/skills/init/references/label-taxonomy.md +115 -0
- package/skills/init/references/project-profile-heuristics.md +156 -0
- package/skills/init/references/template-library.md +129 -0
- package/skills/init/scripts/count-source-files.sh +60 -0
- package/skills/init/scripts/generate-agent-catalog.sh +193 -0
- package/skills/init/scripts/generate-mcp-catalog.sh +214 -0
- package/skills/init/scripts/migrate-rules.py +459 -0
- package/skills/init/scripts/migrate-rules.sh +26 -0
- package/skills/init/scripts/profile-project.sh +453 -0
- package/skills/init/scripts/render-template.py +226 -0
- package/skills/init/scripts/render-template.sh +25 -0
- package/skills/init/scripts/rules-report.sh +31 -0
- package/skills/init/scripts/rules_file_lib.py +41 -0
- package/skills/init/templates/AGENTS.md.tmpl +38 -0
- package/skills/init/templates/CLAUDE.md.tmpl +7 -0
- package/skills/init/templates/ai-rule.md.tmpl +3 -0
- package/skills/init/templates/cursor-rule.mdc.tmpl +7 -0
- package/skills/init/templates/git/commitlint.config.cjs.tmpl +40 -0
- package/skills/init/templates/git/gitignore.tmpl +120 -0
- package/skills/init/templates/git/gitmessage.tmpl +27 -0
- package/skills/init/templates/git/install-lefthook.sh.tmpl +131 -0
- package/skills/init/templates/git/lefthook-usage.md.tmpl +101 -0
- package/skills/init/templates/git/lefthook.yml.tmpl +64 -0
- package/skills/init/templates/github/bug_report.yml.tmpl +78 -0
- package/skills/init/templates/github/config.yml.tmpl +5 -0
- package/skills/init/templates/github/copilot-instructions.md.tmpl +24 -0
- package/skills/init/templates/github/docs_request.yml.tmpl +41 -0
- package/skills/init/templates/github/feature_request.yml.tmpl +59 -0
- package/skills/init/templates/github/labels.md.tmpl +75 -0
- package/skills/init/templates/github/pull_request_template.md.tmpl +66 -0
- package/skills/init/templates/github/workflows/pr-title-autofix.yml.tmpl +101 -0
- package/skills/init/templates/github/workflows/pr-title.yml.tmpl +55 -0
- package/skills/init/templates/workspace-report.md +83 -0
- package/skills/orchestrate/SKILL.md +165 -0
- package/skills/orchestrate/references/agent-catalog.md +601 -0
- package/skills/orchestrate/references/agent-prompts.md +495 -0
- package/skills/orchestrate/references/dispatch-playbook.md +333 -0
- package/skills/orchestrate/references/task-breakdown.md +410 -0
- package/skills/orchestrate/scripts/analyze-task.sh +139 -0
- package/skills/orchestrate/scripts/summarize-results.sh +160 -0
- package/skills/orchestrate/scripts/validate-agents.sh +92 -0
- package/skills/parallel-plan/SKILL.md +124 -0
- package/skills/plan/SKILL.md +134 -0
- package/skills/plan/references/enhanced-personas.md +131 -0
- package/skills/plan/references/personas-and-merge.md +77 -0
- package/skills/plan/references/plan-validation.md +65 -0
- package/skills/plan/references/planner-prompts.md +68 -0
- package/skills/plan/references/planning-tracks.md +73 -0
- package/skills/plan-workflow/SKILL.md +406 -0
- package/skills/plan-workflow/references/checkpoint-messages.md +370 -0
- package/skills/plan-workflow/references/plan-structure.md +238 -0
- package/skills/plan-workflow/references/planning-agents.md +511 -0
- package/skills/plan-workflow/references/research-agents-optimized.md +348 -0
- package/skills/plan-workflow/references/research-agents.md +436 -0
- package/skills/plan-workflow/references/shared-structure.md +152 -0
- package/skills/plan-workflow/references/validation-agents.md +363 -0
- package/skills/plan-workflow/scripts/check-prerequisites.sh +65 -0
- package/skills/plan-workflow/scripts/check-state.sh +190 -0
- package/skills/plan-workflow/scripts/persist-or-fail.sh +135 -0
- package/skills/plan-workflow/scripts/validate-analysis-artifacts.sh +216 -0
- package/skills/plan-workflow/scripts/validate-research-artifacts.sh +225 -0
- package/skills/plan-workflow/scripts/validate-shared.sh +229 -0
- package/skills/plan-workflow/scripts/validate-workflow-plan.sh +256 -0
- package/skills/pr-autofix/SKILL.md +307 -0
- package/skills/pr-autofix/references/ci-loop.md +64 -0
- package/skills/pr-autofix/references/comment-sources.md +197 -0
- package/skills/pr-autofix/references/data-shapes.md +87 -0
- package/skills/pr-autofix/references/goal-example.md +30 -0
- package/skills/pr-autofix/references/output-templates.md +162 -0
- package/skills/pr-autofix/references/prompt-injection-safety.md +165 -0
- package/skills/pr-autofix/references/related-skills.md +11 -0
- package/skills/pr-autofix/references/severity-mapping.md +146 -0
- package/skills/pr-autofix/scripts/fetch-pr-comments.sh +364 -0
- package/skills/pr-autofix/scripts/post-summary.sh +226 -0
- package/skills/pr-autofix/scripts/resolve-thread.sh +251 -0
- package/skills/prp-commit/SKILL.md +128 -0
- package/skills/prp-implement/SKILL.md +177 -0
- package/skills/prp-implement/references/agent-task-prompt.md +36 -0
- package/skills/prp-implement/references/detection.md +49 -0
- package/skills/prp-implement/references/dry-run.md +0 -0
- package/skills/prp-implement/references/report-output.md +204 -0
- package/skills/prp-implement/references/validation-and-failures.md +118 -0
- package/skills/prp-plan/SKILL.md +323 -0
- package/skills/prp-plan/references/enhanced-researchers.md +425 -0
- package/skills/prp-plan/references/parallel-additions.md +56 -0
- package/skills/prp-plan/references/plan-template.md +264 -0
- package/skills/prp-plan/references/synthesis-map.md +25 -0
- package/skills/prp-plan/scripts/preflight-enhanced-agents.sh +111 -0
- package/skills/prp-plan/scripts/validate-prp-plan.sh +368 -0
- package/skills/prp-pr/SKILL.md +402 -0
- package/skills/prp-prd/SKILL.md +442 -0
- package/skills/prp-spec/SKILL.md +274 -0
- package/skills/python-patterns/SKILL.md +103 -0
- package/skills/python-patterns/references/core-idioms.md +304 -0
- package/skills/python-patterns/references/design-and-tooling.md +407 -0
- package/skills/python-testing/SKILL.md +114 -0
- package/skills/python-testing/references/mocking-and-integration.md +395 -0
- package/skills/python-testing/references/pytest-core.md +366 -0
- package/skills/quick-fix/SKILL.md +246 -0
- package/skills/quick-review/SKILL.md +304 -0
- package/skills/release-model/SKILL.md +231 -0
- package/skills/release-model/references/pointer-and-labels.md +83 -0
- package/skills/release-model/references/signals-and-proposal.md +68 -0
- package/skills/release-model/references/template-placeholders.md +42 -0
- package/skills/release-model/references/upgrade-and-audit.md +131 -0
- package/skills/release-model/scripts/collect-signals.sh +459 -0
- package/skills/release-model/scripts/pointer-targets.sh +29 -0
- package/skills/release-model/templates/RELEASING.md.tmpl +151 -0
- package/skills/releaser/SKILL.md +251 -0
- package/skills/releaser/references/ci-optimization-checklist.md +149 -0
- package/skills/releaser/references/ci-templates/docker-release.yml +88 -0
- package/skills/releaser/references/ci-templates/generic-release.yml +69 -0
- package/skills/releaser/references/ci-templates/go-release.yml +50 -0
- package/skills/releaser/references/ci-templates/node-release.yml +126 -0
- package/skills/releaser/references/ci-templates/python-release.yml +95 -0
- package/skills/releaser/references/ci-templates/rust-release.yml +128 -0
- package/skills/releaser/references/ci-workflow-modes.md +42 -0
- package/skills/releaser/references/goal-pairing.md +37 -0
- package/skills/releaser/references/output-templates.md +143 -0
- package/skills/releaser/references/project-type-matrix.md +144 -0
- package/skills/releaser/references/release-branches.md +138 -0
- package/skills/releaser/references/release-ci-loop.md +249 -0
- package/skills/releaser/references/release-notes-template.md +42 -0
- package/skills/releaser/references/release-preparation.md +210 -0
- package/skills/releaser/scripts/check-release-branch.sh +235 -0
- package/skills/releaser/scripts/detect-project.sh +234 -0
- package/skills/releaser/scripts/draft-changelog.sh +387 -0
- package/skills/releaser/scripts/publish-release.sh +302 -0
- package/skills/research-to-issues/SKILL.md +285 -0
- package/skills/research-to-issues/references/label-taxonomy.md +48 -0
- package/skills/research-to-issues/references/parse-deep-research.md +86 -0
- package/skills/research-to-issues/references/parse-feature-spec.md +143 -0
- package/skills/research-to-issues/references/parse-parallel-plan.md +124 -0
- package/skills/research-to-issues/references/parse-prd.md +184 -0
- package/skills/research-to-issues/references/parse-prp-plan.md +237 -0
- package/skills/research-to-issues/references/plan-display-format.md +136 -0
- package/skills/research-to-issues/scripts/validate-prerequisites.sh +312 -0
- package/skills/research-to-issues/templates/feature-issue.md +131 -0
- package/skills/research-to-issues/templates/task-issue.md +104 -0
- package/skills/research-to-issues/templates/tracking-issue.md +126 -0
- package/skills/resume-session/SKILL.md +152 -0
- package/skills/review-fix/SKILL.md +229 -0
- package/skills/review-fix/references/fix-report.md +121 -0
- package/skills/review-fix/references/fixer-dispatch.md +79 -0
- package/skills/review-fix/references/plan.md +119 -0
- package/skills/rust-patterns/SKILL.md +85 -0
- package/skills/rust-patterns/references/concurrency-unsafe-modules.md +243 -0
- package/skills/rust-patterns/references/ownership-errors-types.md +262 -0
- package/skills/rust-testing/SKILL.md +99 -0
- package/skills/rust-testing/references/advanced-testing.md +247 -0
- package/skills/rust-testing/references/unit-and-integration.md +193 -0
- package/skills/save-session/SKILL.md +159 -0
- package/skills/shared-context/SKILL.md +101 -0
- package/skills/ts-patterns/SKILL.md +159 -0
- package/skills/ts-patterns/references/async-runtimes-tooling.md +375 -0
- package/skills/ts-patterns/references/types-errors-modules.md +336 -0
- package/skills/ts-testing/SKILL.md +151 -0
- package/skills/ts-testing/references/advanced-testing.md +350 -0
- package/skills/ts-testing/references/vitest-core.md +318 -0
- package/skills/visual-plan/SKILL.md +221 -0
- package/skills/visual-plan/references/canvas.md +132 -0
- package/skills/visual-plan/references/document-quality.md +178 -0
- package/skills/visual-plan/references/exemplar.md +120 -0
- package/skills/visual-plan/references/wireframe.md +212 -0
- package/skills/visual-plan/scripts/derive-visual-dir.sh +77 -0
- package/skills/visual-recap/SKILL.md +238 -0
- package/skills/visual-recap/references/wireframe.md +237 -0
- package/skills/write-docs/SKILL.md +354 -0
- package/skills/write-docs/scripts/audit-documentation.sh +190 -0
- package/skills/write-docs/scripts/generate-doc-index.sh +125 -0
- package/skills/write-docs/scripts/verify-links.sh +81 -0
- package/skills/write-docs/templates/docs-readme.md +34 -0
- package/skills/write-docs/templates/documentation-strategy.md +91 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Fix Plan (review-fix Phase 3 / Phase 4 lead-in)
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Batching rules
|
|
6
|
+
- Batch construction algorithm
|
|
7
|
+
- Display the plan
|
|
8
|
+
- Worktree-mode batching override
|
|
9
|
+
- Phase 4 lead-in
|
|
10
|
+
- Worktree-mode lifecycle
|
|
11
|
+
|
|
12
|
+
## Batching rules
|
|
13
|
+
|
|
14
|
+
1. **Findings in the same file go in the same group.** Concurrent edits to one file cause write conflicts, so same-file findings are ALWAYS processed sequentially within a single `review-fixer` agent.
|
|
15
|
+
2. **Findings in different files are parallel candidates.** They can go in the same batch and be dispatched concurrently.
|
|
16
|
+
3. **Within a same-file group, sort by line number DESCENDING.** This ensures earlier edits don't shift the line numbers of later findings.
|
|
17
|
+
4. **Severity ordering across batches**: process CRITICAL findings first, then HIGH, then MEDIUM, then LOW. This gives the user the highest-value fixes immediately and ensures that if the pipeline stops mid-run, the worst issues are addressed first.
|
|
18
|
+
|
|
19
|
+
## Batch construction algorithm
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
1. Group eligible findings by file → same_file_groups[]
|
|
23
|
+
2. Sort same_file_groups by max severity of the group (CRITICAL first)
|
|
24
|
+
3. For each severity level (CRITICAL, HIGH, MEDIUM, LOW):
|
|
25
|
+
- Collect all same_file_groups whose MAX severity matches this level
|
|
26
|
+
- If those groups are all for different files, they become one batch (parallel-eligible)
|
|
27
|
+
- Otherwise split into multiple batches (unlikely since groups are keyed by file)
|
|
28
|
+
4. Within each group, sort findings by line number DESCENDING
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Display the plan
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
Fix Plan:
|
|
35
|
+
Eligible findings: M
|
|
36
|
+
Same-file groups: G
|
|
37
|
+
Batches: B
|
|
38
|
+
Max parallel width: W (largest batch size)
|
|
39
|
+
|
|
40
|
+
Batch 1 (CRITICAL, 3 fixes, 3 files):
|
|
41
|
+
- F001 (src/auth.ts:42) SQL injection in user lookup
|
|
42
|
+
- F002 (src/api.ts:17) Missing null check
|
|
43
|
+
- F003 (src/db/query.ts:8) Unescaped input
|
|
44
|
+
|
|
45
|
+
Batch 2 (HIGH, 2 fixes, 1 file with 2 findings):
|
|
46
|
+
- src/utils/format.ts:
|
|
47
|
+
- F005 (line 112) Function exceeds 50 lines
|
|
48
|
+
- F004 (line 78) Missing error handling
|
|
49
|
+
|
|
50
|
+
...
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Worktree-mode batching override (`WORKTREE_ACTIVE=true`)
|
|
54
|
+
|
|
55
|
+
When `WORKTREE_ACTIVE=true`, override the default same-file batching with severity-keyed batching:
|
|
56
|
+
|
|
57
|
+
- **Batch N = all eligible findings at one severity level.**
|
|
58
|
+
- Batch order: CRITICAL (Batch 1) → HIGH (Batch 2) → MEDIUM (Batch 3) → LOW (Batch 4), stopping at `MIN_SEVERITY`. Severities with no eligible findings are skipped.
|
|
59
|
+
- Within a severity batch, preserve the existing same-file grouping (findings in the same file stay together, sorted by line DESCENDING). Different files within the batch can still parallelize under Path B/C.
|
|
60
|
+
Example plan summary when `WORKTREE_ACTIVE=true`:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
Worktree-mode plan (4 severity batches, 7 findings, 5 files):
|
|
64
|
+
|
|
65
|
+
Batch 1 — CRITICAL (2 fixes, 2 files)
|
|
66
|
+
- F001 (src/auth.ts:42)
|
|
67
|
+
- F002 (src/api.ts:17)
|
|
68
|
+
|
|
69
|
+
Batch 2 — HIGH (3 fixes, 2 files)
|
|
70
|
+
- F003 (src/db/query.ts:112)
|
|
71
|
+
- F004 (src/db/query.ts:87) ← same file as F003, descending line order
|
|
72
|
+
- F005 (src/utils/format.ts:9)
|
|
73
|
+
|
|
74
|
+
Batch 3 — MEDIUM (1 fix, 1 file)
|
|
75
|
+
- F006 (src/logging.ts:45)
|
|
76
|
+
|
|
77
|
+
(LOW batch skipped — 0 eligible findings or below MIN_SEVERITY)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
When `--dry-run` is combined with `--worktree`, print this summary and exit. All batches would run inside the parent worktree at `$PARENT_PATH`.
|
|
81
|
+
|
|
82
|
+
## Phase 4 lead-in
|
|
83
|
+
|
|
84
|
+
Select the execution path from the flags: neither flag → **Path A** — sequential execution (default); `PARALLEL_MODE` → **Path B** — parallel standalone sub-agent batches; `` → **Path C** — agent-team batch execution.
|
|
85
|
+
|
|
86
|
+
## Worktree-mode lifecycle (`WORKTREE_ACTIVE=true`)
|
|
87
|
+
|
|
88
|
+
When worktree mode is active, every batch — regardless of Path A / B / C — runs
|
|
89
|
+
inside the single feature worktree from
|
|
90
|
+
`{{package-root}}/shared/references/worktree-strategy.md` §1. There are
|
|
91
|
+
no per-severity child worktrees and no fan-in merge.
|
|
92
|
+
|
|
93
|
+
**One-time parent setup** (only when `WORKTREE_MODE=true` was forced and
|
|
94
|
+
`$PARENT_PATH` needs creation; skip if already ensured by `/ycc:code-review`):
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
PARENT_PATH=$(bash "{{package-root}}/shared/scripts/setup-worktree.sh" \
|
|
98
|
+
parent "${REPO}" "${SLUG}" --base-ref "${PARENT_BRANCH}")
|
|
99
|
+
WORKTREE_ACTIVE=true
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Per-batch steps** (repeat for each severity batch in order):
|
|
103
|
+
|
|
104
|
+
1. **Dispatch** review-fixer agents with `Working directory: $PARENT_PATH` appended to
|
|
105
|
+
their prompt, plus the coordination note: "Other agents in this batch are working
|
|
106
|
+
in the same directory — do not run destructive git commands (reset, clean, checkout)."
|
|
107
|
+
Do **not** pass `isolation: "worktree"` here; that creates a separate harness worktree per review-fixer and breaks the single-worktree contract.
|
|
108
|
+
|
|
109
|
+
2. **Validate** inside `$PARENT_PATH` after the batch completes:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
( cd "$PARENT_PATH" && $TYPECHECK_CMD ) && ( cd "$PARENT_PATH" && $TEST_CMD )
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
3. **Advance** to the next severity batch. No merge step. No child worktree removal.
|
|
116
|
+
|
|
117
|
+
**Status updates**: Edit the `Status:` field in the review artifact file in place
|
|
118
|
+
(Open → Fixed / Failed) after each agent completes its finding. The artifact lives
|
|
119
|
+
in the active worktree at `$PARENT_PATH/docs/prps/reviews/pr-<N>-review.md`.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rust-patterns
|
|
3
|
+
description: Guides idiomatic Rust ownership, errors, and concurrency. Use when resolving
|
|
4
|
+
borrow or lifetime design, structuring crates, or choosing traits and error types.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Rust Development Patterns
|
|
8
|
+
|
|
9
|
+
Idiomatic Rust patterns and best practices for building safe, performant, and maintainable applications.
|
|
10
|
+
|
|
11
|
+
## When to Use
|
|
12
|
+
|
|
13
|
+
- Writing new Rust code
|
|
14
|
+
- Reviewing Rust code
|
|
15
|
+
- Refactoring existing Rust code
|
|
16
|
+
- Designing crate structure and module layout
|
|
17
|
+
|
|
18
|
+
## How It Works
|
|
19
|
+
|
|
20
|
+
This skill enforces idiomatic Rust conventions across six key areas: ownership and borrowing to prevent data races at compile time, `Result`/`?` error propagation with `thiserror` for libraries and `anyhow` for applications, enums and exhaustive pattern matching to make illegal states unrepresentable, traits and generics for zero-cost abstraction, safe concurrency via `Arc<Mutex<T>>`, channels, and async/await, and minimal `pub` surfaces organized by domain.
|
|
21
|
+
|
|
22
|
+
## Critical Rules
|
|
23
|
+
|
|
24
|
+
- Borrow by default; take ownership only to store or consume; avoid clones to appease the borrow checker.
|
|
25
|
+
- Use `Result` with `?` for error propagation — no `unwrap()` in production or library code.
|
|
26
|
+
- `thiserror` for libraries, `anyhow` for applications; avoid `Box<dyn Error>` in library APIs.
|
|
27
|
+
- Match exhaustively on business-critical enums — no wildcard `_` arms.
|
|
28
|
+
- Use newtypes to wrap primitives and prevent argument mix-ups.
|
|
29
|
+
- Seal closed extension points with a private supertrait so downstream crates cannot implement the trait.
|
|
30
|
+
- Keep `pub` surface minimal; `pub(crate)` for internal APIs.
|
|
31
|
+
- Every `unsafe` block needs a `// SAFETY:` comment stating the invariant.
|
|
32
|
+
|
|
33
|
+
## References
|
|
34
|
+
|
|
35
|
+
Paths are relative to this SKILL.md's directory. Read only the file that matches the task. If a file cannot be read, say so.
|
|
36
|
+
|
|
37
|
+
- [references/ownership-errors-types.md](references/ownership-errors-types.md)
|
|
38
|
+
Read when: ownership and borrowing, lifetimes, `Cow`; error handling with `Result`, `?`, `thiserror`/`anyhow`; enums and exhaustive pattern matching; traits, generics, trait objects; sealed traits; serde-tagged response envelopes.
|
|
39
|
+
|
|
40
|
+
- [references/concurrency-unsafe-modules.md](references/concurrency-unsafe-modules.md)
|
|
41
|
+
Read when: structs and data modeling, newtypes; iterators and closures; concurrency (`Arc`, `Mutex`, channels, async); unsafe code with SAFETY invariants; module system and crate structure; tooling (clippy, rustfmt, cargo commands).
|
|
42
|
+
|
|
43
|
+
## Quick Reference: Rust Idioms
|
|
44
|
+
|
|
45
|
+
| Idiom | Description |
|
|
46
|
+
| ----------------------------------- | ---------------------------------------------------------- |
|
|
47
|
+
| Borrow, don't clone | Pass `&T` instead of cloning unless ownership is needed |
|
|
48
|
+
| Make illegal states unrepresentable | Use enums to model valid states only |
|
|
49
|
+
| `?` over `unwrap()` | Propagate errors, never panic in library/production code |
|
|
50
|
+
| Parse, don't validate | Convert unstructured data to typed structs at the boundary |
|
|
51
|
+
| Newtype for type safety | Wrap primitives in newtypes to prevent argument swaps |
|
|
52
|
+
| Sealed trait for closed extension | Private supertrait blocks downstream implementations |
|
|
53
|
+
| Prefer iterators over loops | Declarative chains are clearer and often faster |
|
|
54
|
+
| `#[must_use]` on Results | Ensure callers handle return values |
|
|
55
|
+
| `Cow` for flexible ownership | Avoid allocations when borrowing suffices |
|
|
56
|
+
| Exhaustive matching | No wildcard `_` for business-critical enums |
|
|
57
|
+
| Minimal `pub` surface | Use `pub(crate)` for internal APIs |
|
|
58
|
+
|
|
59
|
+
## Anti-Patterns to Avoid
|
|
60
|
+
|
|
61
|
+
```rust
|
|
62
|
+
// Bad: .unwrap() in production code
|
|
63
|
+
let value = map.get("key").unwrap();
|
|
64
|
+
|
|
65
|
+
// Bad: .clone() to satisfy borrow checker without understanding why
|
|
66
|
+
let data = expensive_data.clone();
|
|
67
|
+
process(&original, &data);
|
|
68
|
+
|
|
69
|
+
// Bad: Using String when &str suffices
|
|
70
|
+
fn greet(name: String) { /* should be &str */ }
|
|
71
|
+
|
|
72
|
+
// Bad: Box<dyn Error> in libraries (use thiserror instead)
|
|
73
|
+
fn parse(input: &str) -> Result<Data, Box<dyn std::error::Error>> { todo!() }
|
|
74
|
+
|
|
75
|
+
// Bad: Ignoring must_use warnings
|
|
76
|
+
let _ = validate(input); // Silently discarding a Result
|
|
77
|
+
|
|
78
|
+
// Bad: Blocking in async context
|
|
79
|
+
async fn bad_async() {
|
|
80
|
+
std::thread::sleep(Duration::from_secs(1)); // Blocks the executor!
|
|
81
|
+
// Use: tokio::time::sleep(Duration::from_secs(1)).await;
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Remember**: If it compiles, it's probably correct — but only if you avoid `unwrap()`, minimize `unsafe`, and let the type system work for you.
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# Rust Development Patterns: Concurrency, Unsafe, and Modules
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Structs and Data Modeling
|
|
6
|
+
- Iterators and Closures
|
|
7
|
+
- Concurrency
|
|
8
|
+
- Unsafe Code
|
|
9
|
+
- Module System and Crate Structure
|
|
10
|
+
- Tooling Integration
|
|
11
|
+
|
|
12
|
+
## Structs and Data Modeling
|
|
13
|
+
|
|
14
|
+
### Builder Pattern for Complex Construction
|
|
15
|
+
|
|
16
|
+
```rust
|
|
17
|
+
struct ServerConfig {
|
|
18
|
+
host: String,
|
|
19
|
+
port: u16,
|
|
20
|
+
max_connections: usize,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
impl ServerConfig {
|
|
24
|
+
fn builder(host: impl Into<String>, port: u16) -> ServerConfigBuilder {
|
|
25
|
+
ServerConfigBuilder { host: host.into(), port, max_connections: 100 }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
struct ServerConfigBuilder { host: String, port: u16, max_connections: usize }
|
|
30
|
+
|
|
31
|
+
impl ServerConfigBuilder {
|
|
32
|
+
fn max_connections(mut self, n: usize) -> Self { self.max_connections = n; self }
|
|
33
|
+
fn build(self) -> ServerConfig {
|
|
34
|
+
ServerConfig { host: self.host, port: self.port, max_connections: self.max_connections }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Usage: ServerConfig::builder("localhost", 8080).max_connections(200).build()
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Iterators and Closures
|
|
42
|
+
|
|
43
|
+
### Prefer Iterator Chains Over Manual Loops
|
|
44
|
+
|
|
45
|
+
```rust
|
|
46
|
+
// Good: Declarative, lazy, composable
|
|
47
|
+
let active_emails: Vec<String> = users.iter()
|
|
48
|
+
.filter(|u| u.is_active)
|
|
49
|
+
.map(|u| u.email.clone())
|
|
50
|
+
.collect();
|
|
51
|
+
|
|
52
|
+
// Bad: Imperative accumulation
|
|
53
|
+
let mut active_emails = Vec::new();
|
|
54
|
+
for user in &users {
|
|
55
|
+
if user.is_active {
|
|
56
|
+
active_emails.push(user.email.clone());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Use `collect()` with Type Annotation
|
|
62
|
+
|
|
63
|
+
```rust
|
|
64
|
+
// Collect into different types
|
|
65
|
+
let names: Vec<_> = items.iter().map(|i| &i.name).collect();
|
|
66
|
+
let lookup: HashMap<_, _> = items.iter().map(|i| (i.id, i)).collect();
|
|
67
|
+
let combined: String = parts.iter().copied().collect();
|
|
68
|
+
|
|
69
|
+
// Collect Results — short-circuits on first error
|
|
70
|
+
let parsed: Result<Vec<i32>, _> = strings.iter().map(|s| s.parse()).collect();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Concurrency
|
|
74
|
+
|
|
75
|
+
### `Arc<Mutex<T>>` for Shared Mutable State
|
|
76
|
+
|
|
77
|
+
```rust
|
|
78
|
+
use std::sync::{Arc, Mutex};
|
|
79
|
+
|
|
80
|
+
let counter = Arc::new(Mutex::new(0));
|
|
81
|
+
let handles: Vec<_> = (0..10).map(|_| {
|
|
82
|
+
let counter = Arc::clone(&counter);
|
|
83
|
+
std::thread::spawn(move || {
|
|
84
|
+
let mut num = counter.lock().expect("mutex poisoned");
|
|
85
|
+
*num += 1;
|
|
86
|
+
})
|
|
87
|
+
}).collect();
|
|
88
|
+
|
|
89
|
+
for handle in handles {
|
|
90
|
+
handle.join().expect("worker thread panicked");
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Channels for Message Passing
|
|
95
|
+
|
|
96
|
+
```rust
|
|
97
|
+
use std::sync::mpsc;
|
|
98
|
+
|
|
99
|
+
let (tx, rx) = mpsc::sync_channel(16); // Bounded channel with backpressure
|
|
100
|
+
|
|
101
|
+
for i in 0..5 {
|
|
102
|
+
let tx = tx.clone();
|
|
103
|
+
std::thread::spawn(move || {
|
|
104
|
+
tx.send(format!("message {i}")).expect("receiver disconnected");
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
drop(tx); // Close sender so rx iterator terminates
|
|
108
|
+
|
|
109
|
+
for msg in rx {
|
|
110
|
+
println!("{msg}");
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Async with Tokio
|
|
115
|
+
|
|
116
|
+
```rust
|
|
117
|
+
use tokio::time::Duration;
|
|
118
|
+
|
|
119
|
+
async fn fetch_with_timeout(url: &str) -> Result<String> {
|
|
120
|
+
// Time both the request and the body read — a stalled body also times out
|
|
121
|
+
tokio::time::timeout(Duration::from_secs(5), async {
|
|
122
|
+
reqwest::get(url)
|
|
123
|
+
.await
|
|
124
|
+
.context("request failed")?
|
|
125
|
+
.text()
|
|
126
|
+
.await
|
|
127
|
+
.context("failed to read body")
|
|
128
|
+
})
|
|
129
|
+
.await
|
|
130
|
+
.context("request timed out")?
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Spawn concurrent tasks
|
|
134
|
+
async fn fetch_all(urls: Vec<String>) -> Vec<Result<String>> {
|
|
135
|
+
let handles: Vec<_> = urls.into_iter()
|
|
136
|
+
.map(|url| tokio::spawn(async move {
|
|
137
|
+
fetch_with_timeout(&url).await
|
|
138
|
+
}))
|
|
139
|
+
.collect();
|
|
140
|
+
|
|
141
|
+
let mut results = Vec::with_capacity(handles.len());
|
|
142
|
+
for handle in handles {
|
|
143
|
+
results.push(handle.await.unwrap_or_else(|e| panic!("spawned task panicked: {e}")));
|
|
144
|
+
}
|
|
145
|
+
results
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Unsafe Code
|
|
150
|
+
|
|
151
|
+
### When Unsafe Is Acceptable
|
|
152
|
+
|
|
153
|
+
```rust
|
|
154
|
+
// Acceptable: FFI boundary with documented invariants (Rust 2024+)
|
|
155
|
+
/// # Safety
|
|
156
|
+
/// `ptr` must be a valid, aligned pointer to an initialized `Widget`.
|
|
157
|
+
/// The `Widget` must stay valid (not moved out of or dropped) for the whole
|
|
158
|
+
/// returned lifetime `'a` — a raw pointer cannot bound it itself.
|
|
159
|
+
unsafe fn widget_from_raw<'a>(ptr: *const Widget) -> &'a Widget {
|
|
160
|
+
// SAFETY: caller guarantees ptr is valid and aligned
|
|
161
|
+
unsafe { &*ptr }
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Acceptable: Performance-critical path with proof of correctness
|
|
165
|
+
// SAFETY: index is always < len due to the loop bound
|
|
166
|
+
unsafe { slice.get_unchecked(index) }
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### When Unsafe Is NOT Acceptable
|
|
170
|
+
|
|
171
|
+
```rust
|
|
172
|
+
// Bad: Using unsafe to bypass borrow checker
|
|
173
|
+
// Bad: Using unsafe for convenience
|
|
174
|
+
// Bad: Using unsafe without a Safety comment
|
|
175
|
+
// Bad: Transmuting between unrelated types
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Module System and Crate Structure
|
|
179
|
+
|
|
180
|
+
### Organize by Domain, Not by Type
|
|
181
|
+
|
|
182
|
+
```text
|
|
183
|
+
my_app/
|
|
184
|
+
├── src/
|
|
185
|
+
│ ├── main.rs
|
|
186
|
+
│ ├── lib.rs
|
|
187
|
+
│ ├── auth/ # Domain module
|
|
188
|
+
│ │ ├── mod.rs
|
|
189
|
+
│ │ ├── token.rs
|
|
190
|
+
│ │ └── middleware.rs
|
|
191
|
+
│ ├── orders/ # Domain module
|
|
192
|
+
│ │ ├── mod.rs
|
|
193
|
+
│ │ ├── model.rs
|
|
194
|
+
│ │ └── service.rs
|
|
195
|
+
│ └── db/ # Infrastructure
|
|
196
|
+
│ ├── mod.rs
|
|
197
|
+
│ └── pool.rs
|
|
198
|
+
├── tests/ # Integration tests
|
|
199
|
+
├── benches/ # Benchmarks
|
|
200
|
+
└── Cargo.toml
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Visibility — Expose Minimally
|
|
204
|
+
|
|
205
|
+
```rust
|
|
206
|
+
// Good: pub(crate) for internal sharing
|
|
207
|
+
pub(crate) fn validate_input(input: &str) -> bool {
|
|
208
|
+
!input.is_empty()
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Good: Re-export public API from lib.rs
|
|
212
|
+
pub mod auth;
|
|
213
|
+
pub use auth::AuthMiddleware;
|
|
214
|
+
|
|
215
|
+
// Bad: Making everything pub
|
|
216
|
+
pub fn internal_helper() {} // Should be pub(crate) or private
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Tooling Integration
|
|
220
|
+
|
|
221
|
+
### Essential Commands
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
# Build and check
|
|
225
|
+
cargo build
|
|
226
|
+
cargo check # Fast type checking without codegen
|
|
227
|
+
cargo clippy # Lints and suggestions
|
|
228
|
+
cargo fmt # Format code
|
|
229
|
+
|
|
230
|
+
# Testing
|
|
231
|
+
cargo test
|
|
232
|
+
cargo test -- --nocapture # Show println output
|
|
233
|
+
cargo test --lib # Unit tests only
|
|
234
|
+
cargo test --test integration # Integration tests only
|
|
235
|
+
|
|
236
|
+
# Dependencies
|
|
237
|
+
cargo audit # Security audit
|
|
238
|
+
cargo tree # Dependency tree
|
|
239
|
+
cargo update # Update dependencies
|
|
240
|
+
|
|
241
|
+
# Performance
|
|
242
|
+
cargo bench # Run benchmarks
|
|
243
|
+
```
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# Rust Development Patterns: Ownership, Errors, and Types
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Core Principles
|
|
6
|
+
- Error Handling
|
|
7
|
+
- Enums and Pattern Matching
|
|
8
|
+
- Traits and Generics (including sealed traits and the serde response envelope)
|
|
9
|
+
|
|
10
|
+
## Core Principles
|
|
11
|
+
|
|
12
|
+
### 1. Ownership and Borrowing
|
|
13
|
+
|
|
14
|
+
Rust's ownership system prevents data races and memory bugs at compile time.
|
|
15
|
+
|
|
16
|
+
```rust
|
|
17
|
+
// Good: Pass references when you don't need ownership
|
|
18
|
+
fn process(data: &[u8]) -> usize {
|
|
19
|
+
data.len()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Good: Take ownership only when you need to store or consume
|
|
23
|
+
fn store(data: Vec<u8>) -> Record {
|
|
24
|
+
Record { payload: data }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Bad: Cloning unnecessarily to avoid borrow checker
|
|
28
|
+
fn process_bad(data: &Vec<u8>) -> usize {
|
|
29
|
+
let cloned = data.clone(); // Wasteful — just borrow
|
|
30
|
+
cloned.len()
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Use `Cow` for Flexible Ownership
|
|
35
|
+
|
|
36
|
+
```rust
|
|
37
|
+
use std::borrow::Cow;
|
|
38
|
+
|
|
39
|
+
fn normalize(input: &str) -> Cow<'_, str> {
|
|
40
|
+
if input.contains(' ') {
|
|
41
|
+
Cow::Owned(input.replace(' ', "_"))
|
|
42
|
+
} else {
|
|
43
|
+
Cow::Borrowed(input) // Zero-cost when no mutation needed
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Error Handling
|
|
49
|
+
|
|
50
|
+
### Use `Result` and `?` — Never `unwrap()` in Production
|
|
51
|
+
|
|
52
|
+
```rust
|
|
53
|
+
// Good: Propagate errors with context
|
|
54
|
+
use anyhow::{Context, Result};
|
|
55
|
+
|
|
56
|
+
fn load_config(path: &str) -> Result<Config> {
|
|
57
|
+
let content = std::fs::read_to_string(path)
|
|
58
|
+
.with_context(|| format!("failed to read config from {path}"))?;
|
|
59
|
+
let config: Config = toml::from_str(&content)
|
|
60
|
+
.with_context(|| format!("failed to parse config from {path}"))?;
|
|
61
|
+
Ok(config)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Bad: Panics on error
|
|
65
|
+
fn load_config_bad(path: &str) -> Config {
|
|
66
|
+
let content = std::fs::read_to_string(path).unwrap(); // Panics!
|
|
67
|
+
toml::from_str(&content).unwrap()
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Library Errors with `thiserror`, Application Errors with `anyhow`
|
|
72
|
+
|
|
73
|
+
```rust
|
|
74
|
+
// Library code: structured, typed errors
|
|
75
|
+
use thiserror::Error;
|
|
76
|
+
|
|
77
|
+
#[derive(Debug, Error)]
|
|
78
|
+
pub enum StorageError {
|
|
79
|
+
#[error("record not found: {id}")]
|
|
80
|
+
NotFound { id: String },
|
|
81
|
+
#[error("connection failed")]
|
|
82
|
+
Connection(#[from] std::io::Error),
|
|
83
|
+
#[error("invalid data: {0}")]
|
|
84
|
+
InvalidData(String),
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Application code: flexible error handling
|
|
88
|
+
use anyhow::{bail, Result};
|
|
89
|
+
|
|
90
|
+
fn run() -> Result<()> {
|
|
91
|
+
let config = load_config("app.toml")?;
|
|
92
|
+
if config.workers == 0 {
|
|
93
|
+
bail!("worker count must be > 0");
|
|
94
|
+
}
|
|
95
|
+
Ok(())
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### `Option` Combinators Over Nested Matching
|
|
100
|
+
|
|
101
|
+
```rust
|
|
102
|
+
// Good: Combinator chain
|
|
103
|
+
fn find_user_email(users: &[User], id: u64) -> Option<String> {
|
|
104
|
+
users.iter()
|
|
105
|
+
.find(|u| u.id == id)
|
|
106
|
+
.map(|u| u.email.clone())
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Bad: Deeply nested matching
|
|
110
|
+
fn find_user_email_bad(users: &[User], id: u64) -> Option<String> {
|
|
111
|
+
match users.iter().find(|u| u.id == id) {
|
|
112
|
+
Some(user) => match &user.email {
|
|
113
|
+
email => Some(email.clone()),
|
|
114
|
+
},
|
|
115
|
+
None => None,
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Enums and Pattern Matching
|
|
121
|
+
|
|
122
|
+
### Model States as Enums
|
|
123
|
+
|
|
124
|
+
```rust
|
|
125
|
+
// Good: Impossible states are unrepresentable
|
|
126
|
+
enum ConnectionState {
|
|
127
|
+
Disconnected,
|
|
128
|
+
Connecting { attempt: u32 },
|
|
129
|
+
Connected { session_id: String },
|
|
130
|
+
Failed { reason: String, retries: u32 },
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
fn handle(state: &ConnectionState) {
|
|
134
|
+
match state {
|
|
135
|
+
ConnectionState::Disconnected => connect(),
|
|
136
|
+
ConnectionState::Connecting { attempt } if *attempt > 3 => abort(),
|
|
137
|
+
ConnectionState::Connecting { .. } => wait(),
|
|
138
|
+
ConnectionState::Connected { session_id } => use_session(session_id),
|
|
139
|
+
ConnectionState::Failed { retries, .. } if *retries < 5 => retry(),
|
|
140
|
+
ConnectionState::Failed { reason, .. } => log_failure(reason),
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Exhaustive Matching — No Catch-All for Business Logic
|
|
146
|
+
|
|
147
|
+
```rust
|
|
148
|
+
// Good: Handle every variant explicitly
|
|
149
|
+
match command {
|
|
150
|
+
Command::Start => start_service(),
|
|
151
|
+
Command::Stop => stop_service(),
|
|
152
|
+
Command::Restart => restart_service(),
|
|
153
|
+
// Adding a new variant forces handling here
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Bad: Wildcard hides new variants
|
|
157
|
+
match command {
|
|
158
|
+
Command::Start => start_service(),
|
|
159
|
+
_ => {} // Silently ignores Stop, Restart, and future variants
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Traits and Generics
|
|
164
|
+
|
|
165
|
+
### Accept Generics, Return Concrete Types
|
|
166
|
+
|
|
167
|
+
```rust
|
|
168
|
+
// Good: Generic input, concrete output
|
|
169
|
+
fn read_all(reader: &mut impl Read) -> std::io::Result<Vec<u8>> {
|
|
170
|
+
let mut buf = Vec::new();
|
|
171
|
+
reader.read_to_end(&mut buf)?;
|
|
172
|
+
Ok(buf)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Good: Trait bounds for multiple constraints
|
|
176
|
+
fn process<T: Display + Send + 'static>(item: T) -> String {
|
|
177
|
+
format!("processed: {item}")
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Trait Objects for Dynamic Dispatch
|
|
182
|
+
|
|
183
|
+
```rust
|
|
184
|
+
// Use when you need heterogeneous collections or plugin systems
|
|
185
|
+
trait Handler: Send + Sync {
|
|
186
|
+
fn handle(&self, request: &Request) -> Response;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
struct Router {
|
|
190
|
+
handlers: Vec<Box<dyn Handler>>,
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Use generics when you need performance (monomorphization)
|
|
194
|
+
fn fast_process<H: Handler>(handler: &H, request: &Request) -> Response {
|
|
195
|
+
handler.handle(request)
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Newtype Pattern for Type Safety
|
|
200
|
+
|
|
201
|
+
```rust
|
|
202
|
+
// Good: Distinct types prevent mixing up arguments
|
|
203
|
+
struct UserId(u64);
|
|
204
|
+
struct OrderId(u64);
|
|
205
|
+
|
|
206
|
+
fn get_order(user: UserId, order: OrderId) -> Result<Order> {
|
|
207
|
+
// Can't accidentally swap user and order IDs
|
|
208
|
+
todo!()
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Bad: Easy to swap arguments
|
|
212
|
+
fn get_order_bad(user_id: u64, order_id: u64) -> Result<Order> {
|
|
213
|
+
todo!()
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Sealed Traits for Closed Extension
|
|
218
|
+
|
|
219
|
+
Use a private supertrait when a public trait must stay open to use but closed to
|
|
220
|
+
implementation. Downstream crates cannot name `private::Sealed`, so they cannot add
|
|
221
|
+
implementations — new variants stay under this crate's control.
|
|
222
|
+
|
|
223
|
+
```rust
|
|
224
|
+
mod private {
|
|
225
|
+
pub trait Sealed {}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
pub trait Format: private::Sealed {
|
|
229
|
+
fn encode(&self, data: &[u8]) -> Vec<u8>;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
pub struct Json;
|
|
233
|
+
impl private::Sealed for Json {}
|
|
234
|
+
impl Format for Json {
|
|
235
|
+
fn encode(&self, data: &[u8]) -> Vec<u8> {
|
|
236
|
+
todo!()
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Reach for this when the set of implementations must remain under crate control or
|
|
242
|
+
external implementations would break crate invariants; use plain public traits for
|
|
243
|
+
true extension points.
|
|
244
|
+
|
|
245
|
+
### API Response Envelope with serde
|
|
246
|
+
|
|
247
|
+
Model API responses as a single internally tagged enum so every endpoint shares one
|
|
248
|
+
consistent wire envelope:
|
|
249
|
+
|
|
250
|
+
```rust
|
|
251
|
+
#[derive(Debug, serde::Serialize)]
|
|
252
|
+
#[serde(tag = "status")]
|
|
253
|
+
pub enum ApiResponse<T: serde::Serialize> {
|
|
254
|
+
#[serde(rename = "ok")]
|
|
255
|
+
Ok { data: T },
|
|
256
|
+
#[serde(rename = "error")]
|
|
257
|
+
Error { message: String },
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Clients discriminate success from failure on the `status` tag instead of parsing two
|
|
262
|
+
different response shapes.
|