oh-my-customcodex 0.1.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/LICENSE +21 -0
- package/README.md +327 -0
- package/dist/cli/index.js +32054 -0
- package/dist/index.js +5469 -0
- package/package.json +89 -0
- package/templates/.claude/agents/arch-documenter.md +38 -0
- package/templates/.claude/agents/arch-speckit-agent.md +66 -0
- package/templates/.claude/agents/be-django-expert.md +47 -0
- package/templates/.claude/agents/be-express-expert.md +31 -0
- package/templates/.claude/agents/be-fastapi-expert.md +45 -0
- package/templates/.claude/agents/be-go-backend-expert.md +45 -0
- package/templates/.claude/agents/be-nestjs-expert.md +29 -0
- package/templates/.claude/agents/be-springboot-expert.md +42 -0
- package/templates/.claude/agents/db-alembic-expert.md +73 -0
- package/templates/.claude/agents/db-postgres-expert.md +38 -0
- package/templates/.claude/agents/db-redis-expert.md +38 -0
- package/templates/.claude/agents/db-supabase-expert.md +37 -0
- package/templates/.claude/agents/de-airflow-expert.md +48 -0
- package/templates/.claude/agents/de-dbt-expert.md +36 -0
- package/templates/.claude/agents/de-kafka-expert.md +83 -0
- package/templates/.claude/agents/de-pipeline-expert.md +34 -0
- package/templates/.claude/agents/de-snowflake-expert.md +38 -0
- package/templates/.claude/agents/de-spark-expert.md +38 -0
- package/templates/.claude/agents/fe-design-expert.md +120 -0
- package/templates/.claude/agents/fe-flutter-agent.md +48 -0
- package/templates/.claude/agents/fe-svelte-agent.md +33 -0
- package/templates/.claude/agents/fe-vercel-agent.md +40 -0
- package/templates/.claude/agents/fe-vuejs-agent.md +34 -0
- package/templates/.claude/agents/infra-aws-expert.md +49 -0
- package/templates/.claude/agents/infra-docker-expert.md +49 -0
- package/templates/.claude/agents/lang-golang-expert.md +46 -0
- package/templates/.claude/agents/lang-java21-expert.md +42 -0
- package/templates/.claude/agents/lang-kotlin-expert.md +45 -0
- package/templates/.claude/agents/lang-python-expert.md +45 -0
- package/templates/.claude/agents/lang-rust-expert.md +45 -0
- package/templates/.claude/agents/lang-typescript-expert.md +45 -0
- package/templates/.claude/agents/mgr-claude-code-bible.md +62 -0
- package/templates/.claude/agents/mgr-creator.md +57 -0
- package/templates/.claude/agents/mgr-gitnerd.md +50 -0
- package/templates/.claude/agents/mgr-sauron.md +163 -0
- package/templates/.claude/agents/mgr-supplier.md +39 -0
- package/templates/.claude/agents/mgr-updater.md +40 -0
- package/templates/.claude/agents/qa-engineer.md +36 -0
- package/templates/.claude/agents/qa-planner.md +78 -0
- package/templates/.claude/agents/qa-writer.md +32 -0
- package/templates/.claude/agents/sec-codeql-expert.md +56 -0
- package/templates/.claude/agents/slack-cli-expert.md +98 -0
- package/templates/.claude/agents/souls/lang-golang-expert.soul.md +21 -0
- package/templates/.claude/agents/sys-memory-keeper.md +123 -0
- package/templates/.claude/agents/sys-naggy.md +76 -0
- package/templates/.claude/agents/tool-bun-expert.md +26 -0
- package/templates/.claude/agents/tool-npm-expert.md +31 -0
- package/templates/.claude/agents/tool-optimizer.md +37 -0
- package/templates/.claude/agents/wiki-curator.md +72 -0
- package/templates/.claude/config/required-plugins.json +30 -0
- package/templates/.claude/contexts/dev.md +20 -0
- package/templates/.claude/contexts/ecomode.md +110 -0
- package/templates/.claude/contexts/index.yaml +41 -0
- package/templates/.claude/contexts/research.md +28 -0
- package/templates/.claude/contexts/review.md +23 -0
- package/templates/.claude/hooks/hooks.json +533 -0
- package/templates/.claude/hooks/scripts/adaptive-harness-scan.sh +45 -0
- package/templates/.claude/hooks/scripts/agent-start-recorder.sh +40 -0
- package/templates/.claude/hooks/scripts/agent-teams-advisor.sh +76 -0
- package/templates/.claude/hooks/scripts/audit-log.sh +64 -0
- package/templates/.claude/hooks/scripts/auto-continue-guard.sh +33 -0
- package/templates/.claude/hooks/scripts/content-hash-validator.sh +75 -0
- package/templates/.claude/hooks/scripts/context-budget-advisor.sh +107 -0
- package/templates/.claude/hooks/scripts/cost-cap-advisor.sh +71 -0
- package/templates/.claude/hooks/scripts/cwd-change-detector.sh +36 -0
- package/templates/.claude/hooks/scripts/eval-core-batch-save.sh +46 -0
- package/templates/.claude/hooks/scripts/feedback-collector.sh +92 -0
- package/templates/.claude/hooks/scripts/file-change-validator.sh +26 -0
- package/templates/.claude/hooks/scripts/git-delegation-guard.sh +57 -0
- package/templates/.claude/hooks/scripts/model-escalation-advisor.sh +106 -0
- package/templates/.claude/hooks/scripts/omcodex-auto-update.sh +4 -0
- package/templates/.claude/hooks/scripts/omcustom-auto-update.sh +177 -0
- package/templates/.claude/hooks/scripts/rtk-intercept.sh +77 -0
- package/templates/.claude/hooks/scripts/rule-deletion-guard.sh +60 -0
- package/templates/.claude/hooks/scripts/schema-validator.sh +106 -0
- package/templates/.claude/hooks/scripts/secret-filter.sh +100 -0
- package/templates/.claude/hooks/scripts/session-autofix-prompt.sh +34 -0
- package/templates/.claude/hooks/scripts/session-autofix.sh +146 -0
- package/templates/.claude/hooks/scripts/session-env-check.sh +254 -0
- package/templates/.claude/hooks/scripts/skill-extractor-analyzer.sh +49 -0
- package/templates/.claude/hooks/scripts/stage-blocker.sh +16 -0
- package/templates/.claude/hooks/scripts/stale-todo-scanner.sh +91 -0
- package/templates/.claude/hooks/scripts/stall-detection-advisor.sh +112 -0
- package/templates/.claude/hooks/scripts/stop-console-audit.sh +46 -0
- package/templates/.claude/hooks/scripts/stuck-detector.sh +199 -0
- package/templates/.claude/hooks/scripts/task-outcome-recorder.sh +119 -0
- package/templates/.claude/hooks/scripts/task-state-precompact.sh +58 -0
- package/templates/.claude/hooks/scripts/user-prompt-preprocessor.sh +32 -0
- package/templates/.claude/hooks/skill-count-reminder.sh +34 -0
- package/templates/.claude/install-hooks.sh +100 -0
- package/templates/.claude/ontology/agents.yaml +546 -0
- package/templates/.claude/ontology/graphs/agent-skill.json +102 -0
- package/templates/.claude/ontology/graphs/full-graph.json +629 -0
- package/templates/.claude/ontology/graphs/routing.json +112 -0
- package/templates/.claude/ontology/graphs/skill-rule.json +78 -0
- package/templates/.claude/ontology/rules.yaml +251 -0
- package/templates/.claude/ontology/schema.yaml +144 -0
- package/templates/.claude/ontology/skills.yaml +575 -0
- package/templates/.claude/rules/MAY-optimization.md +42 -0
- package/templates/.claude/rules/MUST-agent-design.md +340 -0
- package/templates/.claude/rules/MUST-agent-identification.md +77 -0
- package/templates/.claude/rules/MUST-agent-teams.md +293 -0
- package/templates/.claude/rules/MUST-completion-verification.md +112 -0
- package/templates/.claude/rules/MUST-continuous-improvement.md +69 -0
- package/templates/.claude/rules/MUST-enforcement-policy.md +50 -0
- package/templates/.claude/rules/MUST-intent-transparency.md +74 -0
- package/templates/.claude/rules/MUST-language-policy.md +28 -0
- package/templates/.claude/rules/MUST-orchestrator-coordination.md +399 -0
- package/templates/.claude/rules/MUST-parallel-execution.md +184 -0
- package/templates/.claude/rules/MUST-permissions.md +32 -0
- package/templates/.claude/rules/MUST-safety.md +23 -0
- package/templates/.claude/rules/MUST-sync-verification.md +145 -0
- package/templates/.claude/rules/MUST-tool-identification.md +97 -0
- package/templates/.claude/rules/SHOULD-ecomode.md +123 -0
- package/templates/.claude/rules/SHOULD-error-handling.md +33 -0
- package/templates/.claude/rules/SHOULD-hud-statusline.md +51 -0
- package/templates/.claude/rules/SHOULD-interaction.md +77 -0
- package/templates/.claude/rules/SHOULD-memory-integration.md +371 -0
- package/templates/.claude/rules/SHOULD-ontology-rag-routing.md +49 -0
- package/templates/.claude/rules/SHOULD-wiki-sync.md +73 -0
- package/templates/.claude/rules/index.yaml +141 -0
- package/templates/.claude/schemas/tool-inputs.json +62 -0
- package/templates/.claude/skills/action-validator/SKILL.md +89 -0
- package/templates/.claude/skills/adaptive-harness/SKILL.md +335 -0
- package/templates/.claude/skills/adversarial-review/SKILL.md +80 -0
- package/templates/.claude/skills/agora/SKILL.md +194 -0
- package/templates/.claude/skills/airflow-best-practices/SKILL.md +94 -0
- package/templates/.claude/skills/alembic-best-practices/SKILL.md +295 -0
- package/templates/.claude/skills/ambiguity-gate/SKILL.md +94 -0
- package/templates/.claude/skills/analysis/SKILL.md +223 -0
- package/templates/.claude/skills/audit-agents/SKILL.md +118 -0
- package/templates/.claude/skills/aws-best-practices/SKILL.md +281 -0
- package/templates/.claude/skills/claude-code-bible/SKILL.md +93 -0
- package/templates/.claude/skills/claude-code-bible/scripts/fetch-docs.js +244 -0
- package/templates/.claude/skills/claude-native/SKILL.md +215 -0
- package/templates/.claude/skills/codex-exec/SKILL.md +206 -0
- package/templates/.claude/skills/codex-exec/scripts/codex-wrapper.cjs +430 -0
- package/templates/.claude/skills/create-agent/SKILL.md +94 -0
- package/templates/.claude/skills/cve-triage/SKILL.md +91 -0
- package/templates/.claude/skills/dag-orchestration/SKILL.md +201 -0
- package/templates/.claude/skills/dbt-best-practices/SKILL.md +55 -0
- package/templates/.claude/skills/de-lead-routing/SKILL.md +230 -0
- package/templates/.claude/skills/deep-plan/SKILL.md +344 -0
- package/templates/.claude/skills/deep-verify/SKILL.md +111 -0
- package/templates/.claude/skills/dev-lead-routing/SKILL.md +161 -0
- package/templates/.claude/skills/dev-refactor/SKILL.md +234 -0
- package/templates/.claude/skills/dev-review/SKILL.md +172 -0
- package/templates/.claude/skills/django-best-practices/SKILL.md +334 -0
- package/templates/.claude/skills/docker-best-practices/SKILL.md +276 -0
- package/templates/.claude/skills/evaluator-optimizer/SKILL.md +421 -0
- package/templates/.claude/skills/fastapi-best-practices/SKILL.md +271 -0
- package/templates/.claude/skills/fix-refs/SKILL.md +109 -0
- package/templates/.claude/skills/flutter-best-practices/SKILL.md +325 -0
- package/templates/.claude/skills/gemini-exec/SKILL.md +215 -0
- package/templates/.claude/skills/gemini-exec/scripts/gemini-wrapper.cjs +485 -0
- package/templates/.claude/skills/go-backend-best-practices/SKILL.md +135 -0
- package/templates/.claude/skills/go-best-practices/SKILL.md +204 -0
- package/templates/.claude/skills/hada-scout/SKILL.md +92 -0
- package/templates/.claude/skills/harness-eval/SKILL.md +95 -0
- package/templates/.claude/skills/harness-synthesizer/SKILL.md +145 -0
- package/templates/.claude/skills/help/SKILL.md +127 -0
- package/templates/.claude/skills/idea/SKILL.md +88 -0
- package/templates/.claude/skills/impeccable-design/SKILL.md +173 -0
- package/templates/.claude/skills/intent-detection/SKILL.md +293 -0
- package/templates/.claude/skills/intent-detection/patterns/agent-triggers.yaml +438 -0
- package/templates/.claude/skills/java21-best-practices/SKILL.md +190 -0
- package/templates/.claude/skills/jinja2-prompts/SKILL.md +86 -0
- package/templates/.claude/skills/kafka-best-practices/SKILL.md +53 -0
- package/templates/.claude/skills/kotlin-best-practices/SKILL.md +257 -0
- package/templates/.claude/skills/lists/SKILL.md +80 -0
- package/templates/.claude/skills/memory-management/SKILL.md +196 -0
- package/templates/.claude/skills/memory-recall/SKILL.md +172 -0
- package/templates/.claude/skills/memory-save/SKILL.md +128 -0
- package/templates/.claude/skills/model-escalation/SKILL.md +62 -0
- package/templates/.claude/skills/monitoring-setup/SKILL.md +215 -0
- package/templates/.claude/skills/multi-model-verification/SKILL.md +130 -0
- package/templates/.claude/skills/npm-audit/SKILL.md +74 -0
- package/templates/.claude/skills/npm-publish/SKILL.md +65 -0
- package/templates/.claude/skills/npm-version/SKILL.md +104 -0
- package/templates/.claude/skills/omcodex-auto-improve/SKILL.md +136 -0
- package/templates/.claude/skills/omcodex-feedback/SKILL.md +205 -0
- package/templates/.claude/skills/omcodex-improve-report/SKILL.md +65 -0
- package/templates/.claude/skills/omcodex-loop/SKILL.md +45 -0
- package/templates/.claude/skills/omcodex-release-notes/SKILL.md +117 -0
- package/templates/.claude/skills/omcodex-takeover/SKILL.md +115 -0
- package/templates/.claude/skills/omcodex-web/SKILL.md +95 -0
- package/templates/.claude/skills/optimize-analyze/SKILL.md +57 -0
- package/templates/.claude/skills/optimize-bundle/SKILL.md +69 -0
- package/templates/.claude/skills/optimize-report/SKILL.md +76 -0
- package/templates/.claude/skills/peer-messaging/SKILL.md +59 -0
- package/templates/.claude/skills/pipeline/SKILL.md +103 -0
- package/templates/.claude/skills/pipeline-architecture-patterns/SKILL.md +84 -0
- package/templates/.claude/skills/pipeline-guards/SKILL.md +173 -0
- package/templates/.claude/skills/post-release-followup/SKILL.md +134 -0
- package/templates/.claude/skills/postgres-best-practices/SKILL.md +67 -0
- package/templates/.claude/skills/pr-auto-improve/SKILL.md +129 -0
- package/templates/.claude/skills/professor-triage/SKILL.md +321 -0
- package/templates/.claude/skills/python-best-practices/SKILL.md +223 -0
- package/templates/.claude/skills/qa-lead-routing/SKILL.md +104 -0
- package/templates/.claude/skills/react-best-practices/SKILL.md +102 -0
- package/templates/.claude/skills/reasoning-sandwich/SKILL.md +64 -0
- package/templates/.claude/skills/redis-best-practices/SKILL.md +84 -0
- package/templates/.claude/skills/release-plan/SKILL.md +207 -0
- package/templates/.claude/skills/research/SKILL.md +493 -0
- package/templates/.claude/skills/result-aggregation/SKILL.md +165 -0
- package/templates/.claude/skills/rtk-exec/SKILL.md +199 -0
- package/templates/.claude/skills/rtk-exec/scripts/rtk-wrapper.cjs +377 -0
- package/templates/.claude/skills/rust-best-practices/SKILL.md +268 -0
- package/templates/.claude/skills/sauron-watch/SKILL.md +239 -0
- package/templates/.claude/skills/scout/SKILL.md +250 -0
- package/templates/.claude/skills/sdd/SKILL.md +24 -0
- package/templates/.claude/skills/sdd-dev/SKILL.md +257 -0
- package/templates/.claude/skills/sdd-development/SKILL.md +24 -0
- package/templates/.claude/skills/secretary-routing/SKILL.md +132 -0
- package/templates/.claude/skills/skill-extractor/SKILL.md +155 -0
- package/templates/.claude/skills/skills-sh-search/SKILL.md +210 -0
- package/templates/.claude/skills/snowflake-best-practices/SKILL.md +66 -0
- package/templates/.claude/skills/spark-best-practices/SKILL.md +53 -0
- package/templates/.claude/skills/springboot-best-practices/SKILL.md +74 -0
- package/templates/.claude/skills/springboot-best-practices/examples/config-properties-example.java +22 -0
- package/templates/.claude/skills/springboot-best-practices/examples/controller-example.java +28 -0
- package/templates/.claude/skills/springboot-best-practices/examples/controller-test-example.java +33 -0
- package/templates/.claude/skills/springboot-best-practices/examples/entity-example.java +22 -0
- package/templates/.claude/skills/springboot-best-practices/examples/exception-handler-example.java +30 -0
- package/templates/.claude/skills/springboot-best-practices/examples/repository-example.java +17 -0
- package/templates/.claude/skills/springboot-best-practices/examples/repository-test-example.java +23 -0
- package/templates/.claude/skills/springboot-best-practices/examples/security-config-example.java +27 -0
- package/templates/.claude/skills/springboot-best-practices/examples/service-example.java +33 -0
- package/templates/.claude/skills/status/SKILL.md +155 -0
- package/templates/.claude/skills/structured-dev-cycle/SKILL.md +200 -0
- package/templates/.claude/skills/stuck-recovery/SKILL.md +80 -0
- package/templates/.claude/skills/supabase-postgres-best-practices/SKILL.md +100 -0
- package/templates/.claude/skills/systematic-debugging/SKILL.md +288 -0
- package/templates/.claude/skills/systematic-debugging/condition-based-waiting-example.ts +278 -0
- package/templates/.claude/skills/systematic-debugging/condition-based-waiting.md +240 -0
- package/templates/.claude/skills/systematic-debugging/defense-in-depth.md +252 -0
- package/templates/.claude/skills/systematic-debugging/find-polluter.sh +147 -0
- package/templates/.claude/skills/systematic-debugging/root-cause-tracing.md +87 -0
- package/templates/.claude/skills/task-decomposition/SKILL.md +197 -0
- package/templates/.claude/skills/typescript-best-practices/SKILL.md +322 -0
- package/templates/.claude/skills/update-docs/SKILL.md +142 -0
- package/templates/.claude/skills/update-external/SKILL.md +169 -0
- package/templates/.claude/skills/vercel-deploy/SKILL.md +75 -0
- package/templates/.claude/skills/web-design-guidelines/SKILL.md +119 -0
- package/templates/.claude/skills/wiki/SKILL.md +426 -0
- package/templates/.claude/skills/wiki-rag/SKILL.md +154 -0
- package/templates/.claude/skills/worker-reviewer-pipeline/SKILL.md +165 -0
- package/templates/.claude/skills/writing-clearly-and-concisely/SKILL.md +66 -0
- package/templates/.claude/statusline.sh +380 -0
- package/templates/.claude/uninstall-hooks.sh +52 -0
- package/templates/.github/workflows/wiki-sync.yml +132 -0
- package/templates/AGENTS.md.en +255 -0
- package/templates/AGENTS.md.ko +255 -0
- package/templates/CLAUDE.md +263 -0
- package/templates/CLAUDE.md.en +256 -0
- package/templates/CLAUDE.md.ko +256 -0
- package/templates/deprecated-files.json +10 -0
- package/templates/guides/agents-md-quality/README.md +110 -0
- package/templates/guides/airflow/README.md +47 -0
- package/templates/guides/alembic/README.md +438 -0
- package/templates/guides/aws/common-patterns.md +169 -0
- package/templates/guides/aws/index.yaml +26 -0
- package/templates/guides/aws/well-architected.md +143 -0
- package/templates/guides/cc-token-saver/README.md +97 -0
- package/templates/guides/claude-code/01-overview.md +42 -0
- package/templates/guides/claude-code/03-tools.md +107 -0
- package/templates/guides/claude-code/04-agent-skills.md +90 -0
- package/templates/guides/claude-code/05-agent-sdk.md +129 -0
- package/templates/guides/claude-code/06-mcp.md +165 -0
- package/templates/guides/claude-code/07-prompt-engineering.md +100 -0
- package/templates/guides/claude-code/08-testing.md +56 -0
- package/templates/guides/claude-code/09-guardrails.md +78 -0
- package/templates/guides/claude-code/10-monitoring.md +87 -0
- package/templates/guides/claude-code/11-sub-agents.md +159 -0
- package/templates/guides/claude-code/12-workflow-patterns.md +182 -0
- package/templates/guides/claude-code/13-cli-flags.md +151 -0
- package/templates/guides/claude-code/index.yaml +61 -0
- package/templates/guides/dbt/README.md +32 -0
- package/templates/guides/django-best-practices/README.md +476 -0
- package/templates/guides/docker/compose-best-practices.md +284 -0
- package/templates/guides/docker/dockerfile-best-practices.md +262 -0
- package/templates/guides/docker/index.yaml +26 -0
- package/templates/guides/drizzle-orm/README.md +69 -0
- package/templates/guides/elements-of-style/elements-of-style.html +2609 -0
- package/templates/guides/fastapi/best-practices.md +232 -0
- package/templates/guides/fastapi/index.yaml +21 -0
- package/templates/guides/flutter/architecture.md +141 -0
- package/templates/guides/flutter/fundamentals.md +119 -0
- package/templates/guides/flutter/index.yaml +44 -0
- package/templates/guides/flutter/performance.md +119 -0
- package/templates/guides/flutter/security.md +120 -0
- package/templates/guides/flutter/state-management.md +144 -0
- package/templates/guides/flutter/testing.md +155 -0
- package/templates/guides/git-worktree-workflow/README.md +138 -0
- package/templates/guides/go-backend/index.yaml +26 -0
- package/templates/guides/go-backend/project-layout.md +243 -0
- package/templates/guides/go-backend/uber-style.md +212 -0
- package/templates/guides/golang/concurrency.md +282 -0
- package/templates/guides/golang/effective-go.md +309 -0
- package/templates/guides/golang/error-handling.md +250 -0
- package/templates/guides/golang/index.yaml +27 -0
- package/templates/guides/hook-data-flow/README.md +135 -0
- package/templates/guides/iceberg/README.md +49 -0
- package/templates/guides/impeccable-design/color-and-contrast.md +278 -0
- package/templates/guides/impeccable-design/index.yaml +12 -0
- package/templates/guides/impeccable-design/motion-design.md +390 -0
- package/templates/guides/impeccable-design/typography.md +386 -0
- package/templates/guides/impeccable-design/ux-writing.md +400 -0
- package/templates/guides/index.yaml +265 -0
- package/templates/guides/java21/index.yaml +29 -0
- package/templates/guides/java21/java-style-guide.md +248 -0
- package/templates/guides/java21/modern-java21.md +303 -0
- package/templates/guides/kafka/README.md +32 -0
- package/templates/guides/kotlin/coding-conventions.md +247 -0
- package/templates/guides/kotlin/idioms.md +234 -0
- package/templates/guides/kotlin/index.yaml +26 -0
- package/templates/guides/multi-model-routing/README.md +101 -0
- package/templates/guides/multi-provider-exec/README.md +83 -0
- package/templates/guides/postgres/README.md +58 -0
- package/templates/guides/python/index.yaml +26 -0
- package/templates/guides/python/pep8-style-guide.md +202 -0
- package/templates/guides/python/zen-of-python.md +79 -0
- package/templates/guides/redis/README.md +50 -0
- package/templates/guides/rust/error-handling.md +262 -0
- package/templates/guides/rust/index.yaml +26 -0
- package/templates/guides/rust/ownership.md +180 -0
- package/templates/guides/skill-bundle-design/README.md +106 -0
- package/templates/guides/slack-cli/README.md +145 -0
- package/templates/guides/snowflake/README.md +32 -0
- package/templates/guides/spark/README.md +32 -0
- package/templates/guides/springboot/best-practices.md +361 -0
- package/templates/guides/springboot/index.yaml +22 -0
- package/templates/guides/supabase-postgres/README.md +32 -0
- package/templates/guides/supabase-postgres/index.yaml +19 -0
- package/templates/guides/typescript/advanced-types.md +225 -0
- package/templates/guides/typescript/index.yaml +26 -0
- package/templates/guides/typescript/type-system.md +219 -0
- package/templates/guides/web-design/accessibility.md +66 -0
- package/templates/guides/web-design/index.yaml +20 -0
- package/templates/guides/web-design/performance.md +102 -0
- package/templates/guides/web-scraping/README.md +926 -0
- package/templates/guides/web-scraping/index.yaml +19 -0
- package/templates/guides/worktree-lifecycle/README.md +104 -0
- package/templates/index.yaml +18 -0
- package/templates/manifest.json +49 -0
- package/templates/workflows/auto-dev.yaml +46 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# PostgreSQL Guide
|
|
2
|
+
|
|
3
|
+
Reference documentation for pure PostgreSQL database administration and PG-specific SQL patterns.
|
|
4
|
+
|
|
5
|
+
## Source
|
|
6
|
+
|
|
7
|
+
Based on [PostgreSQL official documentation](https://www.postgresql.org/docs/current/) and community best practices.
|
|
8
|
+
|
|
9
|
+
## Categories
|
|
10
|
+
|
|
11
|
+
| Priority | Category | Impact |
|
|
12
|
+
|----------|----------|--------|
|
|
13
|
+
| 1 | Query Optimization | CRITICAL |
|
|
14
|
+
| 2 | Indexing Strategies | CRITICAL |
|
|
15
|
+
| 3 | Partitioning | HIGH |
|
|
16
|
+
| 4 | PG-Specific SQL Dialect | HIGH |
|
|
17
|
+
| 5 | Replication & HA | HIGH |
|
|
18
|
+
| 6 | Maintenance & Vacuum | MEDIUM |
|
|
19
|
+
| 7 | Extensions | MEDIUM |
|
|
20
|
+
| 8 | Security & Roles | LOW-MEDIUM |
|
|
21
|
+
|
|
22
|
+
## PG-Specific SQL Quick Reference
|
|
23
|
+
|
|
24
|
+
### Beyond ANSI SQL
|
|
25
|
+
|
|
26
|
+
| Feature | Syntax | Use Case |
|
|
27
|
+
|---------|--------|----------|
|
|
28
|
+
| UPSERT | `INSERT ... ON CONFLICT DO UPDATE` | Idempotent writes |
|
|
29
|
+
| RETURNING | `INSERT/UPDATE/DELETE ... RETURNING *` | Get affected rows |
|
|
30
|
+
| DISTINCT ON | `SELECT DISTINCT ON (col) ...` | Top-1-per-group |
|
|
31
|
+
| LATERAL | `FROM t1, LATERAL (SELECT ... WHERE t1.id = ...)` | Correlated subquery as join |
|
|
32
|
+
| FILTER | `count(*) FILTER (WHERE condition)` | Conditional aggregation |
|
|
33
|
+
| JSONB ops | `->>`, `@>`, `?`, `jsonb_path_query` | JSON document queries |
|
|
34
|
+
| Array ops | `ANY(array)`, `array_agg`, `unnest` | Array manipulation |
|
|
35
|
+
| generate_series | `generate_series(1, 100)` | Sequence generation |
|
|
36
|
+
| GROUPING SETS | `GROUP BY GROUPING SETS ((a), (b), ())` | Multi-level aggregation |
|
|
37
|
+
| Recursive CTE | `WITH RECURSIVE ... UNION ALL` | Tree/graph traversal |
|
|
38
|
+
|
|
39
|
+
## Relationship to Other DB Agents
|
|
40
|
+
|
|
41
|
+
| Agent | Scope | When to Use |
|
|
42
|
+
|-------|-------|------------|
|
|
43
|
+
| db-postgres-expert | Pure PostgreSQL | Any PostgreSQL without Supabase |
|
|
44
|
+
| db-supabase-expert | Supabase + PostgreSQL | Supabase projects with RLS, Edge Functions |
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
This guide is referenced by:
|
|
49
|
+
- **Agent**: db-postgres-expert
|
|
50
|
+
- **Skill**: postgres-best-practices
|
|
51
|
+
|
|
52
|
+
## External Resources
|
|
53
|
+
|
|
54
|
+
- [PostgreSQL Docs](https://www.postgresql.org/docs/current/)
|
|
55
|
+
- [PostgreSQL Wiki](https://wiki.postgresql.org/)
|
|
56
|
+
- [pganalyze Blog](https://pganalyze.com/blog)
|
|
57
|
+
- [Use The Index, Luke](https://use-the-index-luke.com/)
|
|
58
|
+
- [PostgreSQL Exercises](https://pgexercises.com/)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Python Guide
|
|
2
|
+
|
|
3
|
+
metadata:
|
|
4
|
+
name: python
|
|
5
|
+
description: Python language reference documentation
|
|
6
|
+
|
|
7
|
+
source:
|
|
8
|
+
type: external
|
|
9
|
+
origin: python.org
|
|
10
|
+
urls:
|
|
11
|
+
- https://peps.python.org/pep-0008/
|
|
12
|
+
- https://peps.python.org/pep-0020/
|
|
13
|
+
- https://google.github.io/styleguide/pyguide.html
|
|
14
|
+
last_fetched: "2026-01-22"
|
|
15
|
+
|
|
16
|
+
documents:
|
|
17
|
+
- name: pep8-style-guide
|
|
18
|
+
path: ./pep8-style-guide.md
|
|
19
|
+
description: PEP 8 - Official Python Style Guide
|
|
20
|
+
|
|
21
|
+
- name: zen-of-python
|
|
22
|
+
path: ./zen-of-python.md
|
|
23
|
+
description: PEP 20 - The Zen of Python
|
|
24
|
+
|
|
25
|
+
used_by:
|
|
26
|
+
- lang-python-expert
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# PEP 8 - Style Guide for Python Code
|
|
2
|
+
|
|
3
|
+
> Source: https://peps.python.org/pep-0008/
|
|
4
|
+
|
|
5
|
+
## Introduction
|
|
6
|
+
|
|
7
|
+
This document gives coding conventions for the Python code comprising the standard library. The key insight is that code is read much more often than it is written. Prioritize readability.
|
|
8
|
+
|
|
9
|
+
## Code Layout
|
|
10
|
+
|
|
11
|
+
### Indentation
|
|
12
|
+
|
|
13
|
+
Use 4 spaces per indentation level.
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
# Aligned with opening delimiter
|
|
17
|
+
foo = long_function_name(var_one, var_two,
|
|
18
|
+
var_three, var_four)
|
|
19
|
+
|
|
20
|
+
# Hanging indent with additional level
|
|
21
|
+
def long_function_name(
|
|
22
|
+
var_one, var_two, var_three,
|
|
23
|
+
var_four):
|
|
24
|
+
print(var_one)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Maximum Line Length
|
|
28
|
+
|
|
29
|
+
- Limit all lines to 79 characters
|
|
30
|
+
- Docstrings/comments: limit to 72 characters
|
|
31
|
+
- Teams may agree on longer lines (up to 99)
|
|
32
|
+
|
|
33
|
+
### Binary Operators
|
|
34
|
+
|
|
35
|
+
Break before binary operators:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
# Correct:
|
|
39
|
+
income = (gross_wages
|
|
40
|
+
+ taxable_interest
|
|
41
|
+
+ (dividends - qualified_dividends))
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Blank Lines
|
|
45
|
+
|
|
46
|
+
- Two blank lines around top-level definitions
|
|
47
|
+
- One blank line between method definitions
|
|
48
|
+
- Extra blank lines sparingly to separate logical sections
|
|
49
|
+
|
|
50
|
+
## Imports
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
# Standard library
|
|
54
|
+
import os
|
|
55
|
+
import sys
|
|
56
|
+
|
|
57
|
+
# Third party
|
|
58
|
+
import numpy as np
|
|
59
|
+
|
|
60
|
+
# Local
|
|
61
|
+
from myproject import mymodule
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Rules:
|
|
65
|
+
- One import per line
|
|
66
|
+
- Absolute imports preferred
|
|
67
|
+
- Avoid wildcard imports
|
|
68
|
+
|
|
69
|
+
## Whitespace
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
# Correct:
|
|
73
|
+
spam(ham[1], {eggs: 2})
|
|
74
|
+
x = 1
|
|
75
|
+
y = 2
|
|
76
|
+
long_variable = 3
|
|
77
|
+
|
|
78
|
+
# Wrong:
|
|
79
|
+
spam( ham[ 1 ], { eggs: 2 } )
|
|
80
|
+
x = 1
|
|
81
|
+
y = 2
|
|
82
|
+
long_variable = 3
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Comments
|
|
86
|
+
|
|
87
|
+
### Block Comments
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
# This is a block comment that
|
|
91
|
+
# spans multiple lines and describes
|
|
92
|
+
# the following code block.
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Inline Comments
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
x = x + 1 # Increment x
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Docstrings
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
def complex(real=0.0, imag=0.0):
|
|
105
|
+
"""Form a complex number.
|
|
106
|
+
|
|
107
|
+
Keyword arguments:
|
|
108
|
+
real -- the real part (default 0.0)
|
|
109
|
+
imag -- the imaginary part (default 0.0)
|
|
110
|
+
"""
|
|
111
|
+
pass
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Naming Conventions
|
|
115
|
+
|
|
116
|
+
| Type | Convention | Example |
|
|
117
|
+
|------|------------|---------|
|
|
118
|
+
| Module | lowercase_underscore | `my_module` |
|
|
119
|
+
| Package | lowercase | `mypackage` |
|
|
120
|
+
| Class | CapWords | `MyClass` |
|
|
121
|
+
| Exception | CapWords + Error | `CustomError` |
|
|
122
|
+
| Function | lowercase_underscore | `my_function` |
|
|
123
|
+
| Variable | lowercase_underscore | `my_var` |
|
|
124
|
+
| Constant | UPPER_UNDERSCORE | `MAX_SIZE` |
|
|
125
|
+
| Method | lowercase_underscore | `my_method` |
|
|
126
|
+
|
|
127
|
+
### Special Naming
|
|
128
|
+
|
|
129
|
+
- `_single_leading`: weak "internal use" indicator
|
|
130
|
+
- `__double_leading`: name mangling in classes
|
|
131
|
+
- `__double_both__`: "magic" methods
|
|
132
|
+
|
|
133
|
+
## Programming Recommendations
|
|
134
|
+
|
|
135
|
+
### Comparisons
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
# Correct:
|
|
139
|
+
if foo is not None:
|
|
140
|
+
if isinstance(obj, int):
|
|
141
|
+
|
|
142
|
+
# Wrong:
|
|
143
|
+
if foo != None:
|
|
144
|
+
if type(obj) is int:
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Sequences
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
# Correct:
|
|
151
|
+
if not seq:
|
|
152
|
+
if seq:
|
|
153
|
+
|
|
154
|
+
# Wrong:
|
|
155
|
+
if len(seq) == 0:
|
|
156
|
+
if len(seq) > 0:
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Exception Handling
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
# Correct:
|
|
163
|
+
try:
|
|
164
|
+
value = collection[key]
|
|
165
|
+
except KeyError:
|
|
166
|
+
return key_not_found(key)
|
|
167
|
+
|
|
168
|
+
# Wrong:
|
|
169
|
+
try:
|
|
170
|
+
value = collection[key]
|
|
171
|
+
except: # Bare except
|
|
172
|
+
return key_not_found(key)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Context Managers
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
# Correct:
|
|
179
|
+
with open('file.txt') as f:
|
|
180
|
+
contents = f.read()
|
|
181
|
+
|
|
182
|
+
# Wrong:
|
|
183
|
+
f = open('file.txt')
|
|
184
|
+
contents = f.read()
|
|
185
|
+
f.close()
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Return Statements
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
# Correct:
|
|
192
|
+
def foo(x):
|
|
193
|
+
if x >= 0:
|
|
194
|
+
return math.sqrt(x)
|
|
195
|
+
else:
|
|
196
|
+
return None
|
|
197
|
+
|
|
198
|
+
# Wrong:
|
|
199
|
+
def foo(x):
|
|
200
|
+
if x >= 0:
|
|
201
|
+
return math.sqrt(x)
|
|
202
|
+
```
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# The Zen of Python (PEP 20)
|
|
2
|
+
|
|
3
|
+
> Source: https://peps.python.org/pep-0020/
|
|
4
|
+
|
|
5
|
+
Long time Pythoneer Tim Peters succinctly channels the BDFL's guiding principles for Python's design into 20 aphorisms, only 19 of which have been written down.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
>>> import this
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## The 19 Aphorisms
|
|
12
|
+
|
|
13
|
+
1. **Beautiful is better than ugly.**
|
|
14
|
+
- Write elegant, readable code
|
|
15
|
+
|
|
16
|
+
2. **Explicit is better than implicit.**
|
|
17
|
+
- Don't hide behavior; make intentions clear
|
|
18
|
+
|
|
19
|
+
3. **Simple is better than complex.**
|
|
20
|
+
- Choose straightforward solutions
|
|
21
|
+
|
|
22
|
+
4. **Complex is better than complicated.**
|
|
23
|
+
- When complexity is needed, keep it manageable
|
|
24
|
+
|
|
25
|
+
5. **Flat is better than nested.**
|
|
26
|
+
- Avoid deep nesting; keep structures flat
|
|
27
|
+
|
|
28
|
+
6. **Sparse is better than dense.**
|
|
29
|
+
- Don't pack too much into one line
|
|
30
|
+
|
|
31
|
+
7. **Readability counts.**
|
|
32
|
+
- Code is read more often than written
|
|
33
|
+
|
|
34
|
+
8. **Special cases aren't special enough to break the rules.**
|
|
35
|
+
- Consistency matters
|
|
36
|
+
|
|
37
|
+
9. **Although practicality beats purity.**
|
|
38
|
+
- Be pragmatic when needed
|
|
39
|
+
|
|
40
|
+
10. **Errors should never pass silently.**
|
|
41
|
+
- Handle or propagate errors explicitly
|
|
42
|
+
|
|
43
|
+
11. **Unless explicitly silenced.**
|
|
44
|
+
- Intentional suppression is acceptable
|
|
45
|
+
|
|
46
|
+
12. **In the face of ambiguity, refuse the temptation to guess.**
|
|
47
|
+
- Ask for clarification; don't assume
|
|
48
|
+
|
|
49
|
+
13. **There should be one-- and preferably only one --obvious way to do it.**
|
|
50
|
+
- Python favors one canonical approach
|
|
51
|
+
|
|
52
|
+
14. **Although that way may not be obvious at first unless you're Dutch.**
|
|
53
|
+
- (A nod to Guido van Rossum)
|
|
54
|
+
|
|
55
|
+
15. **Now is better than never.**
|
|
56
|
+
- Don't over-plan; start implementing
|
|
57
|
+
|
|
58
|
+
16. **Although never is often better than *right* now.**
|
|
59
|
+
- But don't rush without thought
|
|
60
|
+
|
|
61
|
+
17. **If the implementation is hard to explain, it's a bad idea.**
|
|
62
|
+
- Complexity is a warning sign
|
|
63
|
+
|
|
64
|
+
18. **If the implementation is easy to explain, it may be a good idea.**
|
|
65
|
+
- Simplicity suggests good design
|
|
66
|
+
|
|
67
|
+
19. **Namespaces are one honking great idea -- let's do more of those!**
|
|
68
|
+
- Organize code into clear namespaces
|
|
69
|
+
|
|
70
|
+
## Application
|
|
71
|
+
|
|
72
|
+
When writing Python code, ask yourself:
|
|
73
|
+
- Is this beautiful or ugly?
|
|
74
|
+
- Is this explicit or implicit?
|
|
75
|
+
- Is this simple or complex?
|
|
76
|
+
- Is this readable?
|
|
77
|
+
- Could I easily explain this to someone else?
|
|
78
|
+
|
|
79
|
+
The Zen of Python is not just style guidance—it's a philosophy for writing maintainable, understandable code.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Redis Guide
|
|
2
|
+
|
|
3
|
+
Reference documentation for Redis in-memory data store best practices and command patterns.
|
|
4
|
+
|
|
5
|
+
## Source
|
|
6
|
+
|
|
7
|
+
Based on [Redis official documentation](https://redis.io/docs/) and community best practices.
|
|
8
|
+
|
|
9
|
+
## Categories
|
|
10
|
+
|
|
11
|
+
| Priority | Category | Impact |
|
|
12
|
+
|----------|----------|--------|
|
|
13
|
+
| 1 | Caching Patterns | CRITICAL |
|
|
14
|
+
| 2 | Data Structure Selection | CRITICAL |
|
|
15
|
+
| 3 | Pub/Sub & Streams | HIGH |
|
|
16
|
+
| 4 | Lua Scripting | HIGH |
|
|
17
|
+
| 5 | Clustering & HA | HIGH |
|
|
18
|
+
| 6 | Performance Optimization | MEDIUM |
|
|
19
|
+
| 7 | Persistence | MEDIUM |
|
|
20
|
+
| 8 | Security | LOW-MEDIUM |
|
|
21
|
+
|
|
22
|
+
## Data Structure Selection Guide
|
|
23
|
+
|
|
24
|
+
| Use Case | Data Structure | Key Commands |
|
|
25
|
+
|----------|---------------|-------------|
|
|
26
|
+
| Simple cache | String | GET, SET, SETEX, MGET |
|
|
27
|
+
| Object cache | Hash | HSET, HGET, HGETALL, HINCRBY |
|
|
28
|
+
| Message queue | List | LPUSH, BRPOP, LRANGE |
|
|
29
|
+
| Unique items | Set | SADD, SMEMBERS, SINTER |
|
|
30
|
+
| Leaderboard | Sorted Set | ZADD, ZRANGE, ZRANGEBYSCORE |
|
|
31
|
+
| Event log | Stream | XADD, XREAD, XRANGE |
|
|
32
|
+
| Count uniques | HyperLogLog | PFADD, PFCOUNT, PFMERGE |
|
|
33
|
+
| Feature flags | Bitmap | SETBIT, GETBIT, BITCOUNT |
|
|
34
|
+
| Rate limiting | Sorted Set or String | ZADD+ZCARD or INCR+EXPIRE |
|
|
35
|
+
| Distributed lock | String | SET NX EX, Redlock algorithm |
|
|
36
|
+
| Session store | Hash | HSET, HGETALL, EXPIRE |
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
This guide is referenced by:
|
|
41
|
+
- **Agent**: db-redis-expert
|
|
42
|
+
- **Skill**: redis-best-practices
|
|
43
|
+
|
|
44
|
+
## External Resources
|
|
45
|
+
|
|
46
|
+
- [Redis Docs](https://redis.io/docs/)
|
|
47
|
+
- [Redis Commands](https://redis.io/commands/)
|
|
48
|
+
- [Redis University](https://university.redis.com/)
|
|
49
|
+
- [Redis Best Practices](https://redis.io/docs/management/optimization/)
|
|
50
|
+
- [Redis Patterns](https://redis.io/docs/manual/patterns/)
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# Rust Error Handling
|
|
2
|
+
|
|
3
|
+
> Reference for error handling patterns in Rust
|
|
4
|
+
|
|
5
|
+
## Result Type
|
|
6
|
+
|
|
7
|
+
```rust
|
|
8
|
+
enum Result<T, E> {
|
|
9
|
+
Ok(T),
|
|
10
|
+
Err(E),
|
|
11
|
+
}
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### Basic Usage
|
|
15
|
+
|
|
16
|
+
```rust
|
|
17
|
+
use std::fs::File;
|
|
18
|
+
|
|
19
|
+
fn main() {
|
|
20
|
+
let f = File::open("hello.txt");
|
|
21
|
+
|
|
22
|
+
let f = match f {
|
|
23
|
+
Ok(file) => file,
|
|
24
|
+
Err(error) => panic!("Problem opening file: {:?}", error),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Matching Different Errors
|
|
30
|
+
|
|
31
|
+
```rust
|
|
32
|
+
use std::fs::File;
|
|
33
|
+
use std::io::ErrorKind;
|
|
34
|
+
|
|
35
|
+
fn main() {
|
|
36
|
+
let f = File::open("hello.txt");
|
|
37
|
+
|
|
38
|
+
let f = match f {
|
|
39
|
+
Ok(file) => file,
|
|
40
|
+
Err(error) => match error.kind() {
|
|
41
|
+
ErrorKind::NotFound => match File::create("hello.txt") {
|
|
42
|
+
Ok(fc) => fc,
|
|
43
|
+
Err(e) => panic!("Problem creating file: {:?}", e),
|
|
44
|
+
},
|
|
45
|
+
other_error => panic!("Problem opening file: {:?}", other_error),
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Shortcuts
|
|
52
|
+
|
|
53
|
+
```rust
|
|
54
|
+
// unwrap: panics on error
|
|
55
|
+
let f = File::open("hello.txt").unwrap();
|
|
56
|
+
|
|
57
|
+
// expect: panics with custom message
|
|
58
|
+
let f = File::open("hello.txt").expect("Failed to open hello.txt");
|
|
59
|
+
|
|
60
|
+
// unwrap_or: provides default value
|
|
61
|
+
let f = File::open("hello.txt").unwrap_or(default_file);
|
|
62
|
+
|
|
63
|
+
// unwrap_or_else: computes default on error
|
|
64
|
+
let f = File::open("hello.txt").unwrap_or_else(|error| {
|
|
65
|
+
panic!("Problem opening file: {:?}", error)
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Propagating Errors
|
|
70
|
+
|
|
71
|
+
### With match
|
|
72
|
+
|
|
73
|
+
```rust
|
|
74
|
+
use std::fs::File;
|
|
75
|
+
use std::io::{self, Read};
|
|
76
|
+
|
|
77
|
+
fn read_username() -> Result<String, io::Error> {
|
|
78
|
+
let f = File::open("hello.txt");
|
|
79
|
+
|
|
80
|
+
let mut f = match f {
|
|
81
|
+
Ok(file) => file,
|
|
82
|
+
Err(e) => return Err(e),
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
let mut s = String::new();
|
|
86
|
+
|
|
87
|
+
match f.read_to_string(&mut s) {
|
|
88
|
+
Ok(_) => Ok(s),
|
|
89
|
+
Err(e) => Err(e),
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### With ? Operator
|
|
95
|
+
|
|
96
|
+
```rust
|
|
97
|
+
use std::fs::File;
|
|
98
|
+
use std::io::{self, Read};
|
|
99
|
+
|
|
100
|
+
fn read_username() -> Result<String, io::Error> {
|
|
101
|
+
let mut f = File::open("hello.txt")?;
|
|
102
|
+
let mut s = String::new();
|
|
103
|
+
f.read_to_string(&mut s)?;
|
|
104
|
+
Ok(s)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Chained version
|
|
108
|
+
fn read_username_chained() -> Result<String, io::Error> {
|
|
109
|
+
let mut s = String::new();
|
|
110
|
+
File::open("hello.txt")?.read_to_string(&mut s)?;
|
|
111
|
+
Ok(s)
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Custom Error Types
|
|
116
|
+
|
|
117
|
+
### Simple Custom Error
|
|
118
|
+
|
|
119
|
+
```rust
|
|
120
|
+
use std::fmt;
|
|
121
|
+
|
|
122
|
+
#[derive(Debug)]
|
|
123
|
+
struct MyError {
|
|
124
|
+
message: String,
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
impl fmt::Display for MyError {
|
|
128
|
+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
129
|
+
write!(f, "{}", self.message)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
impl std::error::Error for MyError {}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Error Enum
|
|
137
|
+
|
|
138
|
+
```rust
|
|
139
|
+
use std::io;
|
|
140
|
+
use std::num::ParseIntError;
|
|
141
|
+
|
|
142
|
+
#[derive(Debug)]
|
|
143
|
+
enum AppError {
|
|
144
|
+
Io(io::Error),
|
|
145
|
+
Parse(ParseIntError),
|
|
146
|
+
Custom(String),
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
impl fmt::Display for AppError {
|
|
150
|
+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
151
|
+
match self {
|
|
152
|
+
AppError::Io(e) => write!(f, "IO error: {}", e),
|
|
153
|
+
AppError::Parse(e) => write!(f, "Parse error: {}", e),
|
|
154
|
+
AppError::Custom(msg) => write!(f, "{}", msg),
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
impl std::error::Error for AppError {}
|
|
160
|
+
|
|
161
|
+
impl From<io::Error> for AppError {
|
|
162
|
+
fn from(error: io::Error) -> Self {
|
|
163
|
+
AppError::Io(error)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
impl From<ParseIntError> for AppError {
|
|
168
|
+
fn from(error: ParseIntError) -> Self {
|
|
169
|
+
AppError::Parse(error)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Option Type
|
|
175
|
+
|
|
176
|
+
```rust
|
|
177
|
+
enum Option<T> {
|
|
178
|
+
Some(T),
|
|
179
|
+
None,
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Usage
|
|
184
|
+
|
|
185
|
+
```rust
|
|
186
|
+
fn divide(a: f64, b: f64) -> Option<f64> {
|
|
187
|
+
if b == 0.0 {
|
|
188
|
+
None
|
|
189
|
+
} else {
|
|
190
|
+
Some(a / b)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Pattern matching
|
|
195
|
+
match divide(10.0, 2.0) {
|
|
196
|
+
Some(result) => println!("Result: {}", result),
|
|
197
|
+
None => println!("Cannot divide by zero"),
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Combinators
|
|
201
|
+
let result = divide(10.0, 2.0)
|
|
202
|
+
.map(|x| x * 2.0)
|
|
203
|
+
.unwrap_or(0.0);
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Panic
|
|
207
|
+
|
|
208
|
+
### When to Panic
|
|
209
|
+
|
|
210
|
+
```rust
|
|
211
|
+
// Unrecoverable errors
|
|
212
|
+
panic!("crash and burn");
|
|
213
|
+
|
|
214
|
+
// Assertion failures
|
|
215
|
+
assert!(x > 0, "x must be positive");
|
|
216
|
+
assert_eq!(a, b, "values must be equal");
|
|
217
|
+
|
|
218
|
+
// Unreachable code
|
|
219
|
+
unreachable!("this should never happen");
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Panic vs Result
|
|
223
|
+
|
|
224
|
+
- Use `Result` for recoverable errors
|
|
225
|
+
- Use `panic!` for unrecoverable errors
|
|
226
|
+
- Library code should return `Result`
|
|
227
|
+
- `main` can panic or return `Result`
|
|
228
|
+
|
|
229
|
+
## Best Practices
|
|
230
|
+
|
|
231
|
+
```rust
|
|
232
|
+
// 1. Use ? for propagation
|
|
233
|
+
fn process() -> Result<Data, Error> {
|
|
234
|
+
let input = read_input()?;
|
|
235
|
+
let parsed = parse(input)?;
|
|
236
|
+
Ok(transform(parsed))
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// 2. Add context with map_err
|
|
240
|
+
let file = File::open(&path)
|
|
241
|
+
.map_err(|e| format!("Failed to open {}: {}", path, e))?;
|
|
242
|
+
|
|
243
|
+
// 3. Use anyhow for applications
|
|
244
|
+
use anyhow::{Context, Result};
|
|
245
|
+
|
|
246
|
+
fn main() -> Result<()> {
|
|
247
|
+
let config = read_config()
|
|
248
|
+
.context("Failed to read configuration")?;
|
|
249
|
+
Ok(())
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// 4. Use thiserror for libraries
|
|
253
|
+
use thiserror::Error;
|
|
254
|
+
|
|
255
|
+
#[derive(Error, Debug)]
|
|
256
|
+
pub enum DataError {
|
|
257
|
+
#[error("Invalid input: {0}")]
|
|
258
|
+
InvalidInput(String),
|
|
259
|
+
#[error("IO error")]
|
|
260
|
+
Io(#[from] std::io::Error),
|
|
261
|
+
}
|
|
262
|
+
```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Rust Guide
|
|
2
|
+
|
|
3
|
+
metadata:
|
|
4
|
+
name: rust
|
|
5
|
+
description: Rust language reference documentation
|
|
6
|
+
|
|
7
|
+
source:
|
|
8
|
+
type: external
|
|
9
|
+
origin: rust-lang.org
|
|
10
|
+
urls:
|
|
11
|
+
- https://doc.rust-lang.org/book/
|
|
12
|
+
- https://rust-lang.github.io/api-guidelines/
|
|
13
|
+
- https://doc.rust-lang.org/nightly/style-guide/
|
|
14
|
+
last_fetched: "2026-01-22"
|
|
15
|
+
|
|
16
|
+
documents:
|
|
17
|
+
- name: ownership
|
|
18
|
+
path: ./ownership.md
|
|
19
|
+
description: Ownership, borrowing, and lifetimes
|
|
20
|
+
|
|
21
|
+
- name: error-handling
|
|
22
|
+
path: ./error-handling.md
|
|
23
|
+
description: Error handling patterns in Rust
|
|
24
|
+
|
|
25
|
+
used_by:
|
|
26
|
+
- lang-rust-expert
|