@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,274 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: prp-spec
|
|
3
|
+
description: Writes lightweight single-pass PRP feature specs. Use when specifying
|
|
4
|
+
a well-defined feature, drafting a quick technical spec, or preparing a spec for
|
|
5
|
+
prp-plan.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# PRP Spec
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
**Operational context:** Write docs/prps/specs/{name}.spec.md with problem, requirements, technical approach, integration points, and risks; accept free-form input or ask clarifying questions. --ground adds codebase/market research through prp-researcher. Use prp-prd for problem discovery and feature-research for heavyweight multi-agent research.
|
|
12
|
+
|
|
13
|
+
> Part of the PRP workflow series. Parallel entry point alongside `prp-prd` — both feed directly into `prp-plan`.
|
|
14
|
+
|
|
15
|
+
**Core Philosophy**: A spec captures WHAT to build and WHY, with enough technical direction to feed directly into `prp-plan`. It does NOT capture HOW in implementation detail — that is the plan's job.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Key Distinctions
|
|
20
|
+
|
|
21
|
+
| This skill (`prp-spec`) | NOT this (`feature-research`) | NOT this (`prp-prd`) |
|
|
22
|
+
| ----------------------------- | ---------------------------------- | ------------------------------- |
|
|
23
|
+
| Single-pass spec generation | 7-agent parallel research team | Interactive PRD with hypothesis |
|
|
24
|
+
| `docs/prps/specs/` | `docs/plans/[name]/` | `docs/prps/prds/` |
|
|
25
|
+
| 1 output file | 8 output files (7 research + spec) | 1 output file |
|
|
26
|
+
| Optional researcher dispatch | Always deploys full team | Always dispatches researcher |
|
|
27
|
+
| Technical approach included | Full technical specifications | Problem-first, solution-light |
|
|
28
|
+
| 1 GATE wait for clarification | Runs without GATEs | 6 GATE waits through phases |
|
|
29
|
+
|
|
30
|
+
**Pipeline model** — `prp-spec` and `prp-prd` are parallel entry points into `prp-plan`, not sequential steps:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
Path A (problem clear): prp-spec ──→ prp-plan → prp-implement
|
|
34
|
+
Path B (problem unclear): prp-prd ──→ prp-plan → prp-implement
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Reach for `feature-research` when external APIs need deep investigation across many domains. Reach for `prp-prd` when the problem itself is unclear and needs interactive discovery. Use this skill when the problem is clear and the goal is a concise, planner-ready spec.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Your Role
|
|
42
|
+
|
|
43
|
+
You are a pragmatic technical writer who:
|
|
44
|
+
|
|
45
|
+
- Captures the minimum viable specification to unblock planning
|
|
46
|
+
- Names concrete requirements, not aspirations
|
|
47
|
+
- Flags unknowns explicitly rather than fabricating confidence
|
|
48
|
+
- Trusts the caller to refine rather than over-spec'ing
|
|
49
|
+
|
|
50
|
+
**Anti-pattern**: Do not fill sections with filler. Write `TBD — needs grounding` or `UNKNOWN — see Open Questions` rather than inventing plausible-sounding content.
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Phase 0 — DETECT
|
|
55
|
+
|
|
56
|
+
### Flag Parsing
|
|
57
|
+
|
|
58
|
+
Extract flags from `$ARGUMENTS`:
|
|
59
|
+
|
|
60
|
+
| Flag | Effect |
|
|
61
|
+
| ---------- | -------------------------------------------------------------------------------------------- |
|
|
62
|
+
| `--ground` | Dispatch `prp-researcher` in dual mode for codebase + market grounding before generating |
|
|
63
|
+
|
|
64
|
+
Strip the flag, set `GROUND_MODE=true|false`. The remaining text is the feature description or file path.
|
|
65
|
+
|
|
66
|
+
### Input Detection
|
|
67
|
+
|
|
68
|
+
| Input Pattern | Action |
|
|
69
|
+
| ------------------ | ------------------------------------- |
|
|
70
|
+
| Path to `.md` file | Read for context, treat as input seed |
|
|
71
|
+
| Free-form text | Proceed to Phase 1 |
|
|
72
|
+
| Empty | Ask the user what to spec |
|
|
73
|
+
|
|
74
|
+
### Feature Name Derivation
|
|
75
|
+
|
|
76
|
+
Derive a kebab-case `{name}` from the input:
|
|
77
|
+
|
|
78
|
+
- From a PRD path: use the PRD's basename (strip `.prd.md`)
|
|
79
|
+
- From free-form text: convert the first 3-5 meaningful words to kebab-case
|
|
80
|
+
- Confirm the derived name with the user if ambiguous
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Phase 1 — CLARIFY
|
|
85
|
+
|
|
86
|
+
**If no input or vague input**, ask:
|
|
87
|
+
|
|
88
|
+
> **What feature do you want to spec?**
|
|
89
|
+
> Describe the capability in 2-3 sentences — what it does and who it serves.
|
|
90
|
+
|
|
91
|
+
**GATE**: Wait for user response.
|
|
92
|
+
|
|
93
|
+
**If input provided (or PRD parsed)**, restate understanding and ask focused questions:
|
|
94
|
+
|
|
95
|
+
> I understand you want to spec: `{restated understanding}`
|
|
96
|
+
>
|
|
97
|
+
> Before I generate, a few clarifying questions:
|
|
98
|
+
>
|
|
99
|
+
> 1. **Scope**: Is this a standalone feature, an extension of something existing, or a replacement?
|
|
100
|
+
> 2. **Constraints**: Any known technical constraints or decisions already made?
|
|
101
|
+
> 3. **Priority**: What are the must-have vs. nice-to-have aspects?
|
|
102
|
+
|
|
103
|
+
**GATE**: Wait for user responses. Accept "skip" or "none" to proceed without answers — capture that as `UNKNOWN` in the spec.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Phase 2 — GROUND (optional)
|
|
108
|
+
|
|
109
|
+
**Trigger conditions**: Run this phase if `GROUND_MODE=true` OR the feature clearly involves external APIs, libraries, or unfamiliar domains.
|
|
110
|
+
|
|
111
|
+
**If skipped**: Report "Generating spec from provided context only — use `--ground` for researcher-backed discovery."
|
|
112
|
+
|
|
113
|
+
**If running**: Dispatch a single `prp-researcher` agent via the `subagent` tool, in dual mode (codebase + market):
|
|
114
|
+
|
|
115
|
+
- Codebase side: similar implementations, relevant types, existing patterns, integration points already in place
|
|
116
|
+
- Market side: competitor approaches, library options, API documentation, known gotchas
|
|
117
|
+
|
|
118
|
+
Instruct the researcher to return the compact discovery table format (codebase) and KEY_INSIGHT format (market) — do NOT ask for recommendations or opinions. This is a standalone single-researcher dispatch — see `{{package-root}}/shared/references/standalone-dispatch.md` for the `subagent` spawn/return contract (omit `name` for standalone dispatch).
|
|
119
|
+
|
|
120
|
+
**Summarize findings to the user before generating**:
|
|
121
|
+
|
|
122
|
+
> **Grounding results:**
|
|
123
|
+
>
|
|
124
|
+
> - {Codebase finding 1 with file:line}
|
|
125
|
+
> - {Market finding 1 with URL}
|
|
126
|
+
> - {Key constraint or opportunity}
|
|
127
|
+
>
|
|
128
|
+
> Generating spec with these findings incorporated.
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Phase 3 — GENERATE
|
|
133
|
+
|
|
134
|
+
**Output path**: `docs/prps/specs/{kebab-case-name}.spec.md`
|
|
135
|
+
|
|
136
|
+
Create the directory if needed:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
mkdir -p docs/prps/specs
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Spec Template
|
|
143
|
+
|
|
144
|
+
Write the spec using this exact structure. Preserve section ordering.
|
|
145
|
+
|
|
146
|
+
```markdown
|
|
147
|
+
# Spec: {Feature Name}
|
|
148
|
+
|
|
149
|
+
## Problem Statement
|
|
150
|
+
|
|
151
|
+
{2-3 sentences: What problem exists, who has it, and what the cost of not solving it is.}
|
|
152
|
+
|
|
153
|
+
## Requirements
|
|
154
|
+
|
|
155
|
+
### Functional
|
|
156
|
+
|
|
157
|
+
| # | Requirement | Priority | Notes |
|
|
158
|
+
| --- | ------------- | -------- | --------- |
|
|
159
|
+
| F1 | {requirement} | Must | {context} |
|
|
160
|
+
| F2 | {requirement} | Must | {context} |
|
|
161
|
+
| F3 | {requirement} | Should | {context} |
|
|
162
|
+
| F4 | {requirement} | Could | {context} |
|
|
163
|
+
|
|
164
|
+
### Non-Functional
|
|
165
|
+
|
|
166
|
+
| # | Requirement | Target | Rationale |
|
|
167
|
+
| --- | --------------------- | ------------------ | --------- |
|
|
168
|
+
| NF1 | {e.g., Response time} | {e.g., <200ms p95} | {why} |
|
|
169
|
+
| NF2 | {e.g., Availability} | {e.g., 99.9%} | {why} |
|
|
170
|
+
|
|
171
|
+
## Technical Approach
|
|
172
|
+
|
|
173
|
+
**Strategy**: {1-2 sentence high-level approach}
|
|
174
|
+
|
|
175
|
+
**Architecture Decisions**:
|
|
176
|
+
|
|
177
|
+
- {Decision 1}: {choice} because {rationale}
|
|
178
|
+
- {Decision 2}: {choice} because {rationale}
|
|
179
|
+
|
|
180
|
+
**Key Components**:
|
|
181
|
+
|
|
182
|
+
- `{component}`: {responsibility}
|
|
183
|
+
- `{component}`: {responsibility}
|
|
184
|
+
|
|
185
|
+
## Integration Points
|
|
186
|
+
|
|
187
|
+
| System/Service | Direction | Protocol | Notes |
|
|
188
|
+
| -------------- | ----------------------- | ---------------- | ------------ |
|
|
189
|
+
| {system} | {inbound/outbound/both} | {REST/gRPC/etc.} | {key detail} |
|
|
190
|
+
|
|
191
|
+
## Risks & Unknowns
|
|
192
|
+
|
|
193
|
+
| Risk | Likelihood | Impact | Mitigation |
|
|
194
|
+
| ------ | ---------- | ------- | ---------- |
|
|
195
|
+
| {risk} | {H/M/L} | {H/M/L} | {strategy} |
|
|
196
|
+
|
|
197
|
+
## Open Questions
|
|
198
|
+
|
|
199
|
+
- [ ] {Question that needs answering before implementation}
|
|
200
|
+
- [ ] {Question that could change the approach}
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
_Source: {PRD path or "free-form description"}_
|
|
205
|
+
_Generated: {timestamp}_
|
|
206
|
+
_Status: DRAFT — ready for prp-plan_
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Writing Principles
|
|
210
|
+
|
|
211
|
+
- **Be concrete**: Requirements name specific behaviors, not vague intents
|
|
212
|
+
- **Use MoSCoW priorities**: Must / Should / Could / Won't — no "high/medium/low"
|
|
213
|
+
- **Surface unknowns**: Every gap becomes an Open Question; do not paper over
|
|
214
|
+
- **Cite grounding findings**: If Phase 2 ran, reference file:line or URLs in Notes/Rationale columns
|
|
215
|
+
- **Keep it short**: A good spec is 1-2 pages rendered, not 10
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Phase 4 — OUTPUT
|
|
220
|
+
|
|
221
|
+
Report to the user:
|
|
222
|
+
|
|
223
|
+
```markdown
|
|
224
|
+
## Spec Created
|
|
225
|
+
|
|
226
|
+
**File**: `docs/prps/specs/{name}.spec.md`
|
|
227
|
+
|
|
228
|
+
### Summary
|
|
229
|
+
|
|
230
|
+
- **Problem**: {one line}
|
|
231
|
+
- **Requirements**: {N functional, M non-functional}
|
|
232
|
+
- **Technical approach**: {one line}
|
|
233
|
+
- **Top risk**: {primary risk}
|
|
234
|
+
- **Open questions**: {count}
|
|
235
|
+
|
|
236
|
+
### Next Steps
|
|
237
|
+
|
|
238
|
+
- Review and refine the spec
|
|
239
|
+
- Run `/ycc:prp-plan docs/prps/specs/{name}.spec.md` to create an implementation plan
|
|
240
|
+
- If the problem needs deeper discovery, run `/ycc:prp-prd` instead — it feeds into `prp-plan` directly
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## Anti-patterns — Do NOT Do These
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
2. **Do NOT output to `docs/plans/`**: Specs go to `docs/prps/specs/`. The `docs/plans/` tree belongs to the `feature-research` / `plan-workflow` track. Always write to `docs/prps/specs/` regardless of the user's current working directory.
|
|
249
|
+
|
|
250
|
+
3. **Do NOT write implementation details**: The spec captures WHAT and WHY, not HOW. Implementation steps, file paths, and code snippets belong in the plan produced by `prp-plan`.
|
|
251
|
+
|
|
252
|
+
4. **Do NOT skip the GATE waits**: Always wait for user confirmation in Phase 1 before generating. The clarification questions exist to prevent speculative specs.
|
|
253
|
+
|
|
254
|
+
5. **Do NOT fabricate grounding findings**: If `GROUND_MODE=false` and no researcher ran, leave Rationale/Notes columns empty or marked `TBD` rather than inventing justifications.
|
|
255
|
+
|
|
256
|
+
6. **Do NOT act as a PRD generator**: This skill is not problem-first and does not run hypothesis questioning. If the problem is unclear and needs interactive discovery, direct the user to `/ycc:prp-prd` instead.
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## Integration
|
|
261
|
+
|
|
262
|
+
- **Entry point**: Parallel to `/ycc:prp-prd` — use `prp-spec` when the problem is clear, `prp-prd` when it needs interactive discovery. Both feed directly into `prp-plan`.
|
|
263
|
+
- **Input**: Accepts free-form descriptions or starts with clarifying questions. Can be invoked standalone.
|
|
264
|
+
- **Downstream**: Specs feed into `/ycc:prp-plan` for implementation planning. `prp-plan` recognizes `.spec.md` files as input.
|
|
265
|
+
- **Grounding**: Optionally dispatches `prp-researcher` in dual mode for codebase + market discovery.
|
|
266
|
+
- **Heavyweight alternative**: For multi-agent research across many domains, use `/ycc:feature-research` instead (outputs to `docs/plans/`).
|
|
267
|
+
|
|
268
|
+
## Success Criteria
|
|
269
|
+
|
|
270
|
+
- **CLEAR_PROBLEM**: Problem Statement is specific and names who is affected
|
|
271
|
+
- **CONCRETE_REQUIREMENTS**: Functional requirements are testable; non-functional requirements have targets
|
|
272
|
+
- **APPROACH_NAMED**: Technical Approach names a strategy and key components, even if tentative
|
|
273
|
+
- **UNKNOWNS_SURFACED**: Gaps are in Open Questions, not hidden inside other sections
|
|
274
|
+
- **PLANNER_READY**: A reader can take this spec to `prp-plan` and produce an implementation plan without going back to the user
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: python-patterns
|
|
3
|
+
description: Guides idiomatic Python design and resource handling. Use when refactoring
|
|
4
|
+
Python modules, adding type hints, or choosing a concurrency model.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Python Development Patterns
|
|
8
|
+
|
|
9
|
+
Idiomatic Python patterns and best practices for building robust, efficient, and maintainable applications.
|
|
10
|
+
|
|
11
|
+
## When to Activate
|
|
12
|
+
|
|
13
|
+
- Writing new Python code
|
|
14
|
+
- Reviewing Python code
|
|
15
|
+
- Refactoring existing Python code
|
|
16
|
+
- Designing Python packages/modules
|
|
17
|
+
|
|
18
|
+
## Critical Rules
|
|
19
|
+
|
|
20
|
+
- Prefer EAFP (try/except) over LBYL checks.
|
|
21
|
+
- Annotate function signatures with type hints.
|
|
22
|
+
- Catch specific exceptions, never bare `except`; chain with `raise ... from e`.
|
|
23
|
+
- Use `with` for resource management.
|
|
24
|
+
- No mutable default arguments; compare to `None` with `is None`.
|
|
25
|
+
- No `from module import *`.
|
|
26
|
+
- Choose the concurrency model by workload: `asyncio`, threads for I/O, processes for CPU.
|
|
27
|
+
|
|
28
|
+
## References
|
|
29
|
+
|
|
30
|
+
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.
|
|
31
|
+
|
|
32
|
+
- [references/core-idioms.md](references/core-idioms.md)
|
|
33
|
+
Read when: Core Principles (readability, explicit, EAFP), Type Hints, Error Handling Patterns, Context Managers, Comprehensions and Generators.
|
|
34
|
+
|
|
35
|
+
- [references/design-and-tooling.md](references/design-and-tooling.md)
|
|
36
|
+
Read when: Data Classes and Named Tuples, Decorators, Concurrency Patterns (threads, processes, asyncio), Package Organization, Memory and Performance, Python Tooling Integration.
|
|
37
|
+
|
|
38
|
+
## Quick Reference: Python Idioms
|
|
39
|
+
|
|
40
|
+
| Idiom | Description |
|
|
41
|
+
| ------------------- | ----------------------------------------------- |
|
|
42
|
+
| EAFP | Easier to Ask Forgiveness than Permission |
|
|
43
|
+
| Context managers | Use `with` for resource management |
|
|
44
|
+
| List comprehensions | For simple transformations |
|
|
45
|
+
| Generators | For lazy evaluation and large datasets |
|
|
46
|
+
| Type hints | Annotate function signatures |
|
|
47
|
+
| Dataclasses | For data containers with auto-generated methods |
|
|
48
|
+
| `__slots__` | For memory optimization |
|
|
49
|
+
| f-strings | For string formatting (Python 3.6+) |
|
|
50
|
+
| `pathlib.Path` | For path operations (Python 3.4+) |
|
|
51
|
+
| `enumerate` | For index-element pairs in loops |
|
|
52
|
+
|
|
53
|
+
## Anti-Patterns to Avoid
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
# Bad: Mutable default arguments
|
|
57
|
+
def append_to(item, items=[]):
|
|
58
|
+
items.append(item)
|
|
59
|
+
return items
|
|
60
|
+
|
|
61
|
+
# Good: Use None and create new list
|
|
62
|
+
def append_to(item, items=None):
|
|
63
|
+
if items is None:
|
|
64
|
+
items = []
|
|
65
|
+
items.append(item)
|
|
66
|
+
return items
|
|
67
|
+
|
|
68
|
+
# Bad: Checking type with type()
|
|
69
|
+
if type(obj) == list:
|
|
70
|
+
process(obj)
|
|
71
|
+
|
|
72
|
+
# Good: Use isinstance
|
|
73
|
+
if isinstance(obj, list):
|
|
74
|
+
process(obj)
|
|
75
|
+
|
|
76
|
+
# Bad: Comparing to None with ==
|
|
77
|
+
if value == None:
|
|
78
|
+
process()
|
|
79
|
+
|
|
80
|
+
# Good: Use is
|
|
81
|
+
if value is None:
|
|
82
|
+
process()
|
|
83
|
+
|
|
84
|
+
# Bad: from module import *
|
|
85
|
+
from os.path import *
|
|
86
|
+
|
|
87
|
+
# Good: Explicit imports
|
|
88
|
+
from os.path import join, exists
|
|
89
|
+
|
|
90
|
+
# Bad: Bare except
|
|
91
|
+
try:
|
|
92
|
+
risky_operation()
|
|
93
|
+
except:
|
|
94
|
+
pass
|
|
95
|
+
|
|
96
|
+
# Good: Specific exception
|
|
97
|
+
try:
|
|
98
|
+
risky_operation()
|
|
99
|
+
except SpecificError as e:
|
|
100
|
+
logger.error(f"Operation failed: {e}")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**Remember**: Python code should be readable, explicit, and follow the principle of least surprise. When in doubt, prioritize clarity over cleverness.
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
# Python Development Patterns: Core Idioms
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- Core Principles
|
|
6
|
+
- Type Hints
|
|
7
|
+
- Error Handling Patterns
|
|
8
|
+
- Context Managers
|
|
9
|
+
- Comprehensions and Generators
|
|
10
|
+
|
|
11
|
+
## Core Principles
|
|
12
|
+
|
|
13
|
+
### 1. Readability Counts
|
|
14
|
+
|
|
15
|
+
Python prioritizes readability. Code should be obvious and easy to understand.
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
# Good: Clear and readable
|
|
19
|
+
def get_active_users(users: list[User]) -> list[User]:
|
|
20
|
+
"""Return only active users from the provided list."""
|
|
21
|
+
return [user for user in users if user.is_active]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# Bad: Clever but confusing
|
|
25
|
+
def get_active_users(u):
|
|
26
|
+
return [x for x in u if x.a]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 2. Explicit is Better Than Implicit
|
|
30
|
+
|
|
31
|
+
Avoid magic; be clear about what your code does.
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
# Good: Explicit configuration
|
|
35
|
+
import logging
|
|
36
|
+
|
|
37
|
+
logging.basicConfig(
|
|
38
|
+
level=logging.INFO,
|
|
39
|
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
# Bad: Hidden side effects
|
|
43
|
+
import some_module
|
|
44
|
+
some_module.setup() # What does this do?
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 3. EAFP - Easier to Ask Forgiveness Than Permission
|
|
48
|
+
|
|
49
|
+
Python prefers exception handling over checking conditions.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
# Good: EAFP style
|
|
53
|
+
def get_value(dictionary: dict, key: str, default: Any = None) -> Any:
|
|
54
|
+
try:
|
|
55
|
+
return dictionary[key]
|
|
56
|
+
except KeyError:
|
|
57
|
+
return default
|
|
58
|
+
|
|
59
|
+
# Bad: LBYL (Look Before You Leap) style
|
|
60
|
+
def get_value(dictionary: dict, key: str, default: Any = None) -> Any:
|
|
61
|
+
if key in dictionary:
|
|
62
|
+
return dictionary[key]
|
|
63
|
+
else:
|
|
64
|
+
return default
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Type Hints
|
|
68
|
+
|
|
69
|
+
### Basic Type Annotations
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from typing import Optional, Any
|
|
73
|
+
|
|
74
|
+
def process_user(
|
|
75
|
+
user_id: str,
|
|
76
|
+
data: dict[str, Any],
|
|
77
|
+
active: bool = True
|
|
78
|
+
) -> Optional[User]:
|
|
79
|
+
"""Process a user and return the updated User or None."""
|
|
80
|
+
if not active:
|
|
81
|
+
return None
|
|
82
|
+
return User(user_id, data)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Modern Type Hints (Python 3.9+)
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
# Python 3.9+ - Use built-in generic types
|
|
89
|
+
def process_items(items: list[str]) -> dict[str, int]:
|
|
90
|
+
return {item: len(item) for item in items}
|
|
91
|
+
|
|
92
|
+
# Python 3.10+ - Use union syntax
|
|
93
|
+
def find(name: str) -> User | None:
|
|
94
|
+
...
|
|
95
|
+
|
|
96
|
+
# Python 3.8 and earlier - Use typing module
|
|
97
|
+
from typing import List, Dict, Optional
|
|
98
|
+
|
|
99
|
+
def process_items(items: List[str]) -> Dict[str, int]:
|
|
100
|
+
return {item: len(item) for item in items}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Type Aliases and TypeVar
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from typing import TypeVar, Union, TypeAlias
|
|
107
|
+
|
|
108
|
+
# Type alias for complex types (Python 3.10+)
|
|
109
|
+
JSON: TypeAlias = Union[dict[str, Any], list[Any], str, int, float, bool, None]
|
|
110
|
+
|
|
111
|
+
def parse_json(data: str) -> JSON:
|
|
112
|
+
return json.loads(data)
|
|
113
|
+
|
|
114
|
+
# Generic types
|
|
115
|
+
T = TypeVar('T')
|
|
116
|
+
|
|
117
|
+
def first(items: list[T]) -> T | None:
|
|
118
|
+
"""Return the first item or None if list is empty."""
|
|
119
|
+
return items[0] if items else None
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Protocol-Based Duck Typing
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from typing import Protocol
|
|
126
|
+
|
|
127
|
+
class Renderable(Protocol):
|
|
128
|
+
def render(self) -> str:
|
|
129
|
+
"""Render the object to a string."""
|
|
130
|
+
|
|
131
|
+
def render_all(items: list[Renderable]) -> str:
|
|
132
|
+
"""Render all items that implement the Renderable protocol."""
|
|
133
|
+
return "\n".join(item.render() for item in items)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Error Handling Patterns
|
|
137
|
+
|
|
138
|
+
### Specific Exception Handling
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
# Good: Catch specific exceptions
|
|
142
|
+
def load_config(path: str) -> Config:
|
|
143
|
+
try:
|
|
144
|
+
with open(path) as f:
|
|
145
|
+
return Config.from_json(f.read())
|
|
146
|
+
except FileNotFoundError as e:
|
|
147
|
+
raise ConfigError(f"Config file not found: {path}") from e
|
|
148
|
+
except json.JSONDecodeError as e:
|
|
149
|
+
raise ConfigError(f"Invalid JSON in config: {path}") from e
|
|
150
|
+
|
|
151
|
+
# Bad: Bare except
|
|
152
|
+
def load_config(path: str) -> Config:
|
|
153
|
+
try:
|
|
154
|
+
with open(path) as f:
|
|
155
|
+
return Config.from_json(f.read())
|
|
156
|
+
except:
|
|
157
|
+
return None # Silent failure!
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Exception Chaining
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
def process_data(data: str) -> Result:
|
|
164
|
+
try:
|
|
165
|
+
parsed = json.loads(data)
|
|
166
|
+
except json.JSONDecodeError as e:
|
|
167
|
+
# Chain exceptions to preserve the traceback
|
|
168
|
+
raise ValueError(f"Failed to parse data: {data}") from e
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Custom Exception Hierarchy
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
class AppError(Exception):
|
|
175
|
+
"""Base exception for all application errors."""
|
|
176
|
+
pass
|
|
177
|
+
|
|
178
|
+
class ValidationError(AppError):
|
|
179
|
+
"""Raised when input validation fails."""
|
|
180
|
+
pass
|
|
181
|
+
|
|
182
|
+
class NotFoundError(AppError):
|
|
183
|
+
"""Raised when a requested resource is not found."""
|
|
184
|
+
pass
|
|
185
|
+
|
|
186
|
+
# Usage
|
|
187
|
+
def get_user(user_id: str) -> User:
|
|
188
|
+
user = db.find_user(user_id)
|
|
189
|
+
if not user:
|
|
190
|
+
raise NotFoundError(f"User not found: {user_id}")
|
|
191
|
+
return user
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Context Managers
|
|
195
|
+
|
|
196
|
+
### Resource Management
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
# Good: Using context managers
|
|
200
|
+
def process_file(path: str) -> str:
|
|
201
|
+
with open(path, 'r') as f:
|
|
202
|
+
return f.read()
|
|
203
|
+
|
|
204
|
+
# Bad: Manual resource management
|
|
205
|
+
def process_file(path: str) -> str:
|
|
206
|
+
f = open(path, 'r')
|
|
207
|
+
try:
|
|
208
|
+
return f.read()
|
|
209
|
+
finally:
|
|
210
|
+
f.close()
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Custom Context Managers
|
|
214
|
+
|
|
215
|
+
```python
|
|
216
|
+
from contextlib import contextmanager
|
|
217
|
+
|
|
218
|
+
@contextmanager
|
|
219
|
+
def timer(name: str):
|
|
220
|
+
"""Context manager to time a block of code."""
|
|
221
|
+
start = time.perf_counter()
|
|
222
|
+
yield
|
|
223
|
+
elapsed = time.perf_counter() - start
|
|
224
|
+
print(f"{name} took {elapsed:.4f} seconds")
|
|
225
|
+
|
|
226
|
+
# Usage
|
|
227
|
+
with timer("data processing"):
|
|
228
|
+
process_large_dataset()
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Context Manager Classes
|
|
232
|
+
|
|
233
|
+
```python
|
|
234
|
+
class DatabaseTransaction:
|
|
235
|
+
def __init__(self, connection):
|
|
236
|
+
self.connection = connection
|
|
237
|
+
|
|
238
|
+
def __enter__(self):
|
|
239
|
+
self.connection.begin_transaction()
|
|
240
|
+
return self
|
|
241
|
+
|
|
242
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
243
|
+
if exc_type is None:
|
|
244
|
+
self.connection.commit()
|
|
245
|
+
else:
|
|
246
|
+
self.connection.rollback()
|
|
247
|
+
return False # Don't suppress exceptions
|
|
248
|
+
|
|
249
|
+
# Usage
|
|
250
|
+
with DatabaseTransaction(conn):
|
|
251
|
+
user = conn.create_user(user_data)
|
|
252
|
+
conn.create_profile(user.id, profile_data)
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Comprehensions and Generators
|
|
256
|
+
|
|
257
|
+
### List Comprehensions
|
|
258
|
+
|
|
259
|
+
```python
|
|
260
|
+
# Good: List comprehension for simple transformations
|
|
261
|
+
names = [user.name for user in users if user.is_active]
|
|
262
|
+
|
|
263
|
+
# Bad: Manual loop
|
|
264
|
+
names = []
|
|
265
|
+
for user in users:
|
|
266
|
+
if user.is_active:
|
|
267
|
+
names.append(user.name)
|
|
268
|
+
|
|
269
|
+
# Complex comprehensions should be expanded
|
|
270
|
+
# Bad: Too complex
|
|
271
|
+
result = [x * 2 for x in items if x > 0 if x % 2 == 0]
|
|
272
|
+
|
|
273
|
+
# Good: Use a regular function
|
|
274
|
+
def filter_and_transform(items: Iterable[int]) -> list[int]:
|
|
275
|
+
result = []
|
|
276
|
+
for x in items:
|
|
277
|
+
if x > 0 and x % 2 == 0:
|
|
278
|
+
result.append(x * 2)
|
|
279
|
+
return result
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Generator Expressions
|
|
283
|
+
|
|
284
|
+
```python
|
|
285
|
+
# Good: Generator for lazy evaluation
|
|
286
|
+
total = sum(x * x for x in range(1_000_000))
|
|
287
|
+
|
|
288
|
+
# Bad: Creates large intermediate list
|
|
289
|
+
total = sum([x * x for x in range(1_000_000)])
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Generator Functions
|
|
293
|
+
|
|
294
|
+
```python
|
|
295
|
+
def read_large_file(path: str) -> Iterator[str]:
|
|
296
|
+
"""Read a large file line by line."""
|
|
297
|
+
with open(path) as f:
|
|
298
|
+
for line in f:
|
|
299
|
+
yield line.strip()
|
|
300
|
+
|
|
301
|
+
# Usage
|
|
302
|
+
for line in read_large_file("huge.txt"):
|
|
303
|
+
process(line)
|
|
304
|
+
```
|