cfsa-antigravity 1.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/bin/cli.mjs +324 -0
- package/package.json +34 -0
- package/template/.agent/instructions/commands.md +48 -0
- package/template/.agent/instructions/patterns.md +61 -0
- package/template/.agent/instructions/structure.md +29 -0
- package/template/.agent/instructions/tech-stack.md +43 -0
- package/template/.agent/instructions/workflow.md +41 -0
- package/template/.agent/kit-sync.md +15 -0
- package/template/.agent/rules/boundary-not-placeholder.md +146 -0
- package/template/.agent/rules/completion-checklist.md +48 -0
- package/template/.agent/rules/decision-classification.md +103 -0
- package/template/.agent/rules/extensibility.md +47 -0
- package/template/.agent/rules/question-vs-command.md +81 -0
- package/template/.agent/rules/security-first.md +43 -0
- package/template/.agent/rules/specificity-standards.md +54 -0
- package/template/.agent/rules/tdd-contract-first.md +57 -0
- package/template/.agent/rules/vertical-slices.md +42 -0
- package/template/.agent/skill-library/MANIFEST.md +480 -0
- package/template/.agent/skill-library/README.md +38 -0
- package/template/.agent/skill-library/meta/brand-guidelines/SKILL.md +73 -0
- package/template/.agent/skill-library/meta/claude-code/README.md +9 -0
- package/template/.agent/skill-library/meta/claude-code/agent-development/SKILL.md +415 -0
- package/template/.agent/skill-library/meta/claude-code/hook-development/SKILL.md +712 -0
- package/template/.agent/skill-library/meta/claude-code/plugin-structure/SKILL.md +476 -0
- package/template/.agent/skill-library/meta/git-advanced/SKILL.md +972 -0
- package/template/.agent/skill-library/meta/mcp-builder/SKILL.md +236 -0
- package/template/.agent/skill-library/meta/product-marketing-context/SKILL.md +241 -0
- package/template/.agent/skill-library/meta/regex-patterns/SKILL.md +751 -0
- package/template/.agent/skill-library/meta/tmux-processes/SKILL.md +210 -0
- package/template/.agent/skill-library/meta/using-tmux-for-interactive-commands/SKILL.md +178 -0
- package/template/.agent/skill-library/stack/3d/threejs-pro/SKILL.md +300 -0
- package/template/.agent/skill-library/stack/ai/ai-sdk/SKILL.md +77 -0
- package/template/.agent/skill-library/stack/ai/langchain/SKILL.md +530 -0
- package/template/.agent/skill-library/stack/ai/ollama/SKILL.md +321 -0
- package/template/.agent/skill-library/stack/ai/openai-sdk/SKILL.md +549 -0
- package/template/.agent/skill-library/stack/analytics/google-analytics/SKILL.md +153 -0
- package/template/.agent/skill-library/stack/api/graphql/SKILL.md +1061 -0
- package/template/.agent/skill-library/stack/api/trpc/SKILL.md +576 -0
- package/template/.agent/skill-library/stack/auth/authjs/SKILL.md +569 -0
- package/template/.agent/skill-library/stack/auth/clerk/SKILL.md +590 -0
- package/template/.agent/skill-library/stack/auth/firebase-auth/SKILL.md +734 -0
- package/template/.agent/skill-library/stack/cms/payload-cms/SKILL.md +573 -0
- package/template/.agent/skill-library/stack/cms/shopify/SKILL.md +1193 -0
- package/template/.agent/skill-library/stack/cms/wordpress/SKILL.md +1104 -0
- package/template/.agent/skill-library/stack/css/sass-scss/SKILL.md +1121 -0
- package/template/.agent/skill-library/stack/css/tailwind-css-patterns/SKILL.md +863 -0
- package/template/.agent/skill-library/stack/css/tailwind-design-system/SKILL.md +490 -0
- package/template/.agent/skill-library/stack/css/vanilla-css/SKILL.md +1078 -0
- package/template/.agent/skill-library/stack/databases/clickhouse/SKILL.md +311 -0
- package/template/.agent/skill-library/stack/databases/influxdb/SKILL.md +280 -0
- package/template/.agent/skill-library/stack/databases/lancedb/SKILL.md +415 -0
- package/template/.agent/skill-library/stack/databases/mongodb/SKILL.md +1169 -0
- package/template/.agent/skill-library/stack/databases/neo4j/SKILL.md +839 -0
- package/template/.agent/skill-library/stack/databases/pgvector/SKILL.md +241 -0
- package/template/.agent/skill-library/stack/databases/pinecone/SKILL.md +212 -0
- package/template/.agent/skill-library/stack/databases/postgresql/SKILL.md +658 -0
- package/template/.agent/skill-library/stack/databases/qdrant/SKILL.md +312 -0
- package/template/.agent/skill-library/stack/databases/redis/SKILL.md +1079 -0
- package/template/.agent/skill-library/stack/databases/spacetimedb/SKILL.md +532 -0
- package/template/.agent/skill-library/stack/databases/sqlite/SKILL.md +1132 -0
- package/template/.agent/skill-library/stack/databases/supabase/SKILL.md +640 -0
- package/template/.agent/skill-library/stack/databases/surrealdb-expert/SKILL.md +945 -0
- package/template/.agent/skill-library/stack/databases/timescaledb/SKILL.md +745 -0
- package/template/.agent/skill-library/stack/databases/weaviate/SKILL.md +218 -0
- package/template/.agent/skill-library/stack/devops/github-actions/SKILL.md +554 -0
- package/template/.agent/skill-library/stack/devops/kubernetes/SKILL.md +950 -0
- package/template/.agent/skill-library/stack/devops/nginx/SKILL.md +841 -0
- package/template/.agent/skill-library/stack/devops/terraform/SKILL.md +860 -0
- package/template/.agent/skill-library/stack/email/resend/SKILL.md +391 -0
- package/template/.agent/skill-library/stack/engines/godot/SKILL.md +488 -0
- package/template/.agent/skill-library/stack/extensions/chrome-extension/SKILL.md +375 -0
- package/template/.agent/skill-library/stack/extensions/vscode-extension/SKILL.md +453 -0
- package/template/.agent/skill-library/stack/frameworks/astro-framework/SKILL.md +162 -0
- package/template/.agent/skill-library/stack/frameworks/electron/SKILL.md +1286 -0
- package/template/.agent/skill-library/stack/frameworks/fastapi/SKILL.md +650 -0
- package/template/.agent/skill-library/stack/frameworks/hono/SKILL.md +90 -0
- package/template/.agent/skill-library/stack/frameworks/nestjs/SKILL.md +878 -0
- package/template/.agent/skill-library/stack/frameworks/nextjs/SKILL.md +635 -0
- package/template/.agent/skill-library/stack/frameworks/nuxt/SKILL.md +564 -0
- package/template/.agent/skill-library/stack/frameworks/sveltekit/SKILL.md +614 -0
- package/template/.agent/skill-library/stack/frameworks/tauri/SKILL.md +920 -0
- package/template/.agent/skill-library/stack/gamedev/godot/SKILL.md +1032 -0
- package/template/.agent/skill-library/stack/gamedev/unity/SKILL.md +1175 -0
- package/template/.agent/skill-library/stack/hosting/aws/SKILL.md +467 -0
- package/template/.agent/skill-library/stack/hosting/cloudflare/SKILL.md +201 -0
- package/template/.agent/skill-library/stack/hosting/docker-expert/SKILL.md +409 -0
- package/template/.agent/skill-library/stack/hosting/vercel/SKILL.md +484 -0
- package/template/.agent/skill-library/stack/languages/bash-scripting/SKILL.md +773 -0
- package/template/.agent/skill-library/stack/languages/c-cpp/SKILL.md +712 -0
- package/template/.agent/skill-library/stack/languages/gdscript/SKILL.md +789 -0
- package/template/.agent/skill-library/stack/languages/go/SKILL.md +664 -0
- package/template/.agent/skill-library/stack/languages/java/SKILL.md +778 -0
- package/template/.agent/skill-library/stack/languages/kotlin/SKILL.md +665 -0
- package/template/.agent/skill-library/stack/languages/python/SKILL.md +678 -0
- package/template/.agent/skill-library/stack/languages/rust/SKILL.md +673 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/SKILL.md +141 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/advanced-generics.md +90 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/branded-types.md +57 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/builder-pattern.md +71 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/common-pitfalls.md +135 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/conditional-types.md +27 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/decorators.md +98 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/discriminated-unions.md +62 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/mapped-types.md +53 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/performance-best-practices.md +104 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/template-literal-types.md +49 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/testing-types.md +112 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/type-guards.md +70 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/type-inference.md +101 -0
- package/template/.agent/skill-library/stack/languages/typescript-advanced-patterns/references/utility-types.md +98 -0
- package/template/.agent/skill-library/stack/languages/vanilla-javascript/SKILL.md +803 -0
- package/template/.agent/skill-library/stack/messaging/kafka/SKILL.md +235 -0
- package/template/.agent/skill-library/stack/mobile/expo-react-native/SKILL.md +665 -0
- package/template/.agent/skill-library/stack/mobile/flutter/SKILL.md +316 -0
- package/template/.agent/skill-library/stack/mobile/react-native/SKILL.md +337 -0
- package/template/.agent/skill-library/stack/monitoring/posthog/SKILL.md +396 -0
- package/template/.agent/skill-library/stack/monitoring/sentry/SKILL.md +509 -0
- package/template/.agent/skill-library/stack/observability/datadog/SKILL.md +179 -0
- package/template/.agent/skill-library/stack/observability/distributed-tracing/SKILL.md +140 -0
- package/template/.agent/skill-library/stack/observability/logging-best-practices/SKILL.md +168 -0
- package/template/.agent/skill-library/stack/observability/opentelemetry/SKILL.md +164 -0
- package/template/.agent/skill-library/stack/observability/prometheus-grafana/SKILL.md +246 -0
- package/template/.agent/skill-library/stack/observability/python-observability/SKILL.md +158 -0
- package/template/.agent/skill-library/stack/orm/drizzle-orm/SKILL.md +613 -0
- package/template/.agent/skill-library/stack/orm/prisma/SKILL.md +744 -0
- package/template/.agent/skill-library/stack/payments/lemonsqueezy/SKILL.md +393 -0
- package/template/.agent/skill-library/stack/payments/stripe-integration/SKILL.md +457 -0
- package/template/.agent/skill-library/stack/queue/bullmq/SKILL.md +385 -0
- package/template/.agent/skill-library/stack/queue/inngest/SKILL.md +438 -0
- package/template/.agent/skill-library/stack/realtime/socketio/SKILL.md +595 -0
- package/template/.agent/skill-library/stack/search/elasticsearch/SKILL.md +248 -0
- package/template/.agent/skill-library/stack/search/meilisearch/SKILL.md +385 -0
- package/template/.agent/skill-library/stack/security/crypto-patterns/SKILL.md +437 -0
- package/template/.agent/skill-library/stack/security/csp-cors-headers/SKILL.md +588 -0
- package/template/.agent/skill-library/stack/security/dependency-auditing/SKILL.md +560 -0
- package/template/.agent/skill-library/stack/security/input-sanitization/SKILL.md +430 -0
- package/template/.agent/skill-library/stack/security/owasp-web-security/SKILL.md +421 -0
- package/template/.agent/skill-library/stack/state/tanstack-query/SKILL.md +637 -0
- package/template/.agent/skill-library/stack/state/zustand/SKILL.md +483 -0
- package/template/.agent/skill-library/stack/storage/aws-s3/SKILL.md +415 -0
- package/template/.agent/skill-library/stack/testing/playwright/SKILL.md +641 -0
- package/template/.agent/skill-library/stack/testing/storybook/SKILL.md +923 -0
- package/template/.agent/skill-library/stack/testing/testing-library/SKILL.md +872 -0
- package/template/.agent/skill-library/stack/testing/vitest/SKILL.md +714 -0
- package/template/.agent/skill-library/stack/ui/react-best-practices/SKILL.md +877 -0
- package/template/.agent/skill-library/stack/ui/react-composition-patterns/SKILL.md +1107 -0
- package/template/.agent/skill-library/stack/ui/react-flow/SKILL.md +425 -0
- package/template/.agent/skill-library/stack/ui/shadcn-ui/SKILL.md +703 -0
- package/template/.agent/skill-library/surface/api/api-caching/SKILL.md +458 -0
- package/template/.agent/skill-library/surface/api/api-documentation-openapi/SKILL.md +697 -0
- package/template/.agent/skill-library/surface/api/api-error-handling/SKILL.md +478 -0
- package/template/.agent/skill-library/surface/api/api-security-checklist/SKILL.md +147 -0
- package/template/.agent/skill-library/surface/api/api-versioning/SKILL.md +420 -0
- package/template/.agent/skill-library/surface/api/email-best-practices/SKILL.md +59 -0
- package/template/.agent/skill-library/surface/api/rate-limiting-abuse-protection/SKILL.md +147 -0
- package/template/.agent/skill-library/surface/api/rest-api-design/SKILL.md +478 -0
- package/template/.agent/skill-library/surface/api/webhook-design/SKILL.md +752 -0
- package/template/.agent/skill-library/surface/cli/cli-configuration-management/SKILL.md +445 -0
- package/template/.agent/skill-library/surface/cli/cli-error-diagnostics/SKILL.md +515 -0
- package/template/.agent/skill-library/surface/cli/cli-shell-integration/SKILL.md +479 -0
- package/template/.agent/skill-library/surface/cli/cli-ux-design/SKILL.md +477 -0
- package/template/.agent/skill-library/surface/desktop/desktop-app-distribution/SKILL.md +416 -0
- package/template/.agent/skill-library/surface/desktop/desktop-security-sandboxing/SKILL.md +407 -0
- package/template/.agent/skill-library/surface/desktop/desktop-ux-conventions/SKILL.md +361 -0
- package/template/.agent/skill-library/surface/desktop/native-os-integration/SKILL.md +563 -0
- package/template/.agent/skill-library/surface/extension/browser-extension-patterns/SKILL.md +482 -0
- package/template/.agent/skill-library/surface/extension/plugin-architecture-design/SKILL.md +632 -0
- package/template/.agent/skill-library/surface/extension/vscode-extension-development/SKILL.md +728 -0
- package/template/.agent/skill-library/surface/mobile/app-store-submission/SKILL.md +304 -0
- package/template/.agent/skill-library/surface/mobile/mobile-offline-sync/SKILL.md +443 -0
- package/template/.agent/skill-library/surface/mobile/mobile-responsive-patterns/SKILL.md +432 -0
- package/template/.agent/skill-library/surface/mobile/push-notifications/SKILL.md +495 -0
- package/template/.agent/skill-library/surface/web/accessibility-compliance/SKILL.md +827 -0
- package/template/.agent/skill-library/surface/web/ai-seo/SKILL.md +398 -0
- package/template/.agent/skill-library/surface/web/ai-seo/references/content-patterns.md +285 -0
- package/template/.agent/skill-library/surface/web/ai-seo/references/platform-ranking-factors.md +152 -0
- package/template/.agent/skill-library/surface/web/analytics-tracking/SKILL.md +309 -0
- package/template/.agent/skill-library/surface/web/analytics-tracking/references/event-library.md +260 -0
- package/template/.agent/skill-library/surface/web/analytics-tracking/references/ga4-implementation.md +300 -0
- package/template/.agent/skill-library/surface/web/analytics-tracking/references/gtm-implementation.md +390 -0
- package/template/.agent/skill-library/surface/web/authentication-ui-flows/SKILL.md +530 -0
- package/template/.agent/skill-library/surface/web/dark-mode-theming/SKILL.md +516 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/SKILL.md +105 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/data/charts.csv +26 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/data/colors.csv +97 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/data/landing.csv +31 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/data/styles.csv +59 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/data/typography.csv +58 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/data/ux-guidelines.csv +100 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/scripts/core.py +258 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/scripts/design_system.py +1067 -0
- package/template/.agent/skill-library/surface/web/design-reference-data/scripts/search.py +106 -0
- package/template/.agent/skill-library/surface/web/form-handling-validation/SKILL.md +675 -0
- package/template/.agent/skill-library/surface/web/frontend-design/SKILL.md +1393 -0
- package/template/.agent/skill-library/surface/web/frontend-design/templates/cppn-hero.tsx +299 -0
- package/template/.agent/skill-library/surface/web/frontend-design/templates/wave-hero.tsx +875 -0
- package/template/.agent/skill-library/surface/web/frontend-verification/SKILL.md +111 -0
- package/template/.agent/skill-library/surface/web/frontend-verification/scripts/ux_audit.py +739 -0
- package/template/.agent/skill-library/surface/web/i18n-localization/SKILL.md +154 -0
- package/template/.agent/skill-library/surface/web/offline-first-pwa/SKILL.md +657 -0
- package/template/.agent/skill-library/surface/web/page-cro/SKILL.md +182 -0
- package/template/.agent/skill-library/surface/web/page-cro/references/experiments.md +248 -0
- package/template/.agent/skill-library/surface/web/programmatic-seo/SKILL.md +238 -0
- package/template/.agent/skill-library/surface/web/programmatic-seo/references/playbooks.md +308 -0
- package/template/.agent/skill-library/surface/web/schema-markup/SKILL.md +179 -0
- package/template/.agent/skill-library/surface/web/schema-markup/references/schema-examples.md +398 -0
- package/template/.agent/skill-library/surface/web/seo-audit/SKILL.md +394 -0
- package/template/.agent/skill-library/surface/web/seo-audit/references/ai-writing-detection.md +200 -0
- package/template/.agent/skill-library/surface/web/web-performance-optimization/SKILL.md +646 -0
- package/template/.agent/skill-library/surface/web/web-scraping/SKILL.md +58 -0
- package/template/.agent/skills/accessibility/SKILL.md +522 -0
- package/template/.agent/skills/accessibility/references/WCAG.md +162 -0
- package/template/.agent/skills/adversarial-review/SKILL.md +90 -0
- package/template/.agent/skills/antigravity-workflows/SKILL.md +81 -0
- package/template/.agent/skills/antigravity-workflows/resources/implementation-playbook.md +36 -0
- package/template/.agent/skills/api-design-principles/SKILL.md +37 -0
- package/template/.agent/skills/api-design-principles/assets/api-design-checklist.md +155 -0
- package/template/.agent/skills/api-design-principles/assets/rest-api-template.py +182 -0
- package/template/.agent/skills/api-design-principles/references/graphql-schema-design.md +583 -0
- package/template/.agent/skills/api-design-principles/references/rest-best-practices.md +408 -0
- package/template/.agent/skills/api-design-principles/resources/implementation-playbook.md +513 -0
- package/template/.agent/skills/api-versioning/SKILL.md +420 -0
- package/template/.agent/skills/architecture-mapping/SKILL.md +219 -0
- package/template/.agent/skills/bootstrap-agents/SKILL.md +259 -0
- package/template/.agent/skills/brainstorming/SKILL.md +236 -0
- package/template/.agent/skills/brand-guidelines/SKILL.md +44 -0
- package/template/.agent/skills/clean-code/SKILL.md +94 -0
- package/template/.agent/skills/code-review-pro/SKILL.md +152 -0
- package/template/.agent/skills/concise-planning/SKILL.md +68 -0
- package/template/.agent/skills/cross-layer-consistency/SKILL.md +117 -0
- package/template/.agent/skills/database-schema-design/SKILL.md +429 -0
- package/template/.agent/skills/deployment-procedures/SKILL.md +241 -0
- package/template/.agent/skills/design-anti-cliche/SKILL.md +159 -0
- package/template/.agent/skills/design-direction/SKILL.md +45 -0
- package/template/.agent/skills/error-handling-patterns/SKILL.md +721 -0
- package/template/.agent/skills/find-skills/SKILL.md +145 -0
- package/template/.agent/skills/git-advanced/SKILL.md +972 -0
- package/template/.agent/skills/git-workflow/SKILL.md +420 -0
- package/template/.agent/skills/idea-extraction/SKILL.md +271 -0
- package/template/.agent/skills/logging-best-practices/SKILL.md +851 -0
- package/template/.agent/skills/migration-management/SKILL.md +384 -0
- package/template/.agent/skills/minimalist-surgical-development/SKILL.md +69 -0
- package/template/.agent/skills/parallel-agents/SKILL.md +165 -0
- package/template/.agent/skills/parallel-debugging/SKILL.md +135 -0
- package/template/.agent/skills/parallel-feature-development/SKILL.md +166 -0
- package/template/.agent/skills/performance-budgeting/SKILL.md +144 -0
- package/template/.agent/skills/pipeline-rubrics/SKILL.md +51 -0
- package/template/.agent/skills/pipeline-rubrics/references/architecture-rubric.md +19 -0
- package/template/.agent/skills/pipeline-rubrics/references/be-rubric.md +21 -0
- package/template/.agent/skills/pipeline-rubrics/references/fe-rubric.md +20 -0
- package/template/.agent/skills/pipeline-rubrics/references/ia-rubric.md +19 -0
- package/template/.agent/skills/pipeline-rubrics/references/scoring.md +28 -0
- package/template/.agent/skills/pipeline-rubrics/references/vision-rubric.md +11 -0
- package/template/.agent/skills/prd-templates/SKILL.md +88 -0
- package/template/.agent/skills/prd-templates/references/architecture-design-template.md +88 -0
- package/template/.agent/skills/prd-templates/references/be-spec-template.md +101 -0
- package/template/.agent/skills/prd-templates/references/data-placement-template.md +74 -0
- package/template/.agent/skills/prd-templates/references/decomposition-templates.md +211 -0
- package/template/.agent/skills/prd-templates/references/design-system-decisions.md +198 -0
- package/template/.agent/skills/prd-templates/references/engineering-standards-template.md +124 -0
- package/template/.agent/skills/prd-templates/references/fe-classification-procedures.md +47 -0
- package/template/.agent/skills/prd-templates/references/fe-spec-template.md +84 -0
- package/template/.agent/skills/prd-templates/references/infrastructure-report-template.md +71 -0
- package/template/.agent/skills/prd-templates/references/operational-templates.md +116 -0
- package/template/.agent/skills/prd-templates/references/placeholder-guard-template.md +21 -0
- package/template/.agent/skills/prd-templates/references/surface-model.md +61 -0
- package/template/.agent/skills/prd-templates/references/vision-template.md +66 -0
- package/template/.agent/skills/prompt-engineer/README.md +659 -0
- package/template/.agent/skills/prompt-engineer/SKILL.md +249 -0
- package/template/.agent/skills/regex-patterns/SKILL.md +751 -0
- package/template/.agent/skills/resolve-ambiguity/SKILL.md +278 -0
- package/template/.agent/skills/rest-api-design/SKILL.md +478 -0
- package/template/.agent/skills/security-scanning-security-hardening/SKILL.md +231 -0
- package/template/.agent/skills/session-continuity/SKILL.md +730 -0
- package/template/.agent/skills/session-continuity/protocols/01-session-resumption.md +38 -0
- package/template/.agent/skills/session-continuity/protocols/02-progress-generation.md +85 -0
- package/template/.agent/skills/session-continuity/protocols/03-progress-update.md +70 -0
- package/template/.agent/skills/session-continuity/protocols/04-pattern-extraction.md +60 -0
- package/template/.agent/skills/session-continuity/protocols/05-session-close.md +37 -0
- package/template/.agent/skills/session-continuity/protocols/06-decision-analysis.md +84 -0
- package/template/.agent/skills/session-continuity/protocols/07-spec-pipeline-generation.md +48 -0
- package/template/.agent/skills/session-continuity/protocols/08-spec-pipeline-update.md +43 -0
- package/template/.agent/skills/session-continuity/protocols/09-parallel-claim.md +122 -0
- package/template/.agent/skills/session-continuity/protocols/10-placeholder-verification-gate.md +104 -0
- package/template/.agent/skills/session-continuity/protocols/ambiguity-gates.md +48 -0
- package/template/.agent/skills/skill-creator/LICENSE.txt +202 -0
- package/template/.agent/skills/skill-creator/README.md +270 -0
- package/template/.agent/skills/skill-creator/SKILL.md +590 -0
- package/template/.agent/skills/skill-creator/references/output-patterns.md +82 -0
- package/template/.agent/skills/skill-creator/references/workflows.md +28 -0
- package/template/.agent/skills/skill-creator/scripts/init_skill.py +303 -0
- package/template/.agent/skills/skill-creator/scripts/package_skill.py +110 -0
- package/template/.agent/skills/skill-creator/scripts/quick_validate.py +95 -0
- package/template/.agent/skills/spec-writing/SKILL.md +110 -0
- package/template/.agent/skills/systematic-debugging/CREATION-LOG.md +119 -0
- package/template/.agent/skills/systematic-debugging/SKILL.md +297 -0
- package/template/.agent/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/template/.agent/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/template/.agent/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/template/.agent/skills/systematic-debugging/find-polluter.sh +63 -0
- package/template/.agent/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/template/.agent/skills/systematic-debugging/test-academic.md +14 -0
- package/template/.agent/skills/systematic-debugging/test-pressure-1.md +58 -0
- package/template/.agent/skills/systematic-debugging/test-pressure-2.md +68 -0
- package/template/.agent/skills/systematic-debugging/test-pressure-3.md +69 -0
- package/template/.agent/skills/tdd-workflow/SKILL.md +409 -0
- package/template/.agent/skills/tech-stack-catalog/SKILL.md +49 -0
- package/template/.agent/skills/tech-stack-catalog/references/constraint-questions.md +21 -0
- package/template/.agent/skills/tech-stack-catalog/references/dev-tooling-decisions.md +37 -0
- package/template/.agent/skills/tech-stack-catalog/references/surface-decision-tables.md +69 -0
- package/template/.agent/skills/technical-writer/SKILL.md +242 -0
- package/template/.agent/skills/testing-strategist/SKILL.md +932 -0
- package/template/.agent/skills/verification-before-completion/SKILL.md +145 -0
- package/template/.agent/skills/workflow-automation/SKILL.md +73 -0
- package/template/.agent/workflows/audit-ambiguity-execute.md +165 -0
- package/template/.agent/workflows/audit-ambiguity-rubrics.md +83 -0
- package/template/.agent/workflows/audit-ambiguity.md +64 -0
- package/template/.agent/workflows/bootstrap-agents-fill.md +201 -0
- package/template/.agent/workflows/bootstrap-agents-provision.md +197 -0
- package/template/.agent/workflows/bootstrap-agents.md +66 -0
- package/template/.agent/workflows/create-prd-architecture.md +119 -0
- package/template/.agent/workflows/create-prd-compile.md +138 -0
- package/template/.agent/workflows/create-prd-design-system.md +135 -0
- package/template/.agent/workflows/create-prd-security.md +113 -0
- package/template/.agent/workflows/create-prd-stack.md +91 -0
- package/template/.agent/workflows/create-prd.md +168 -0
- package/template/.agent/workflows/decompose-architecture-structure.md +82 -0
- package/template/.agent/workflows/decompose-architecture-validate.md +119 -0
- package/template/.agent/workflows/decompose-architecture.md +111 -0
- package/template/.agent/workflows/evolve-contract.md +98 -0
- package/template/.agent/workflows/evolve-feature-cascade.md +140 -0
- package/template/.agent/workflows/evolve-feature-classify.md +116 -0
- package/template/.agent/workflows/evolve-feature.md +56 -0
- package/template/.agent/workflows/ideate-discover.md +144 -0
- package/template/.agent/workflows/ideate-extract.md +129 -0
- package/template/.agent/workflows/ideate-validate.md +117 -0
- package/template/.agent/workflows/ideate.md +113 -0
- package/template/.agent/workflows/implement-slice-setup.md +113 -0
- package/template/.agent/workflows/implement-slice-tdd.md +198 -0
- package/template/.agent/workflows/implement-slice.md +50 -0
- package/template/.agent/workflows/plan-phase.md +202 -0
- package/template/.agent/workflows/propagate-decision-apply.md +135 -0
- package/template/.agent/workflows/propagate-decision-scan.md +147 -0
- package/template/.agent/workflows/propagate-decision.md +56 -0
- package/template/.agent/workflows/remediate-pipeline-assess.md +138 -0
- package/template/.agent/workflows/remediate-pipeline-execute.md +135 -0
- package/template/.agent/workflows/remediate-pipeline.md +55 -0
- package/template/.agent/workflows/resolve-ambiguity.md +82 -0
- package/template/.agent/workflows/sync-kit.md +209 -0
- package/template/.agent/workflows/update-architecture-map.md +74 -0
- package/template/.agent/workflows/validate-phase.md +219 -0
- package/template/.agent/workflows/verify-infrastructure.md +207 -0
- package/template/.agent/workflows/write-architecture-spec-deepen.md +139 -0
- package/template/.agent/workflows/write-architecture-spec-design.md +202 -0
- package/template/.agent/workflows/write-architecture-spec.md +63 -0
- package/template/.agent/workflows/write-be-spec-classify.md +165 -0
- package/template/.agent/workflows/write-be-spec-write.md +98 -0
- package/template/.agent/workflows/write-be-spec.md +76 -0
- package/template/.agent/workflows/write-fe-spec-classify.md +170 -0
- package/template/.agent/workflows/write-fe-spec-write.md +94 -0
- package/template/.agent/workflows/write-fe-spec.md +71 -0
- package/template/AGENTS.md +176 -0
- package/template/GEMINI.md +177 -0
- package/template/docs/README.md +187 -0
- package/template/docs/audits/.gitkeep +0 -0
- package/template/docs/audits/README.md +10 -0
- package/template/docs/plans/.gitkeep +0 -0
- package/template/docs/plans/README.md +21 -0
- package/template/docs/plans/be/.gitkeep +0 -0
- package/template/docs/plans/be/README.md +11 -0
- package/template/docs/plans/fe/.gitkeep +0 -0
- package/template/docs/plans/fe/README.md +11 -0
- package/template/docs/plans/ia/.gitkeep +0 -0
- package/template/docs/plans/ia/README.md +17 -0
- package/template/docs/plans/ia/deep-dives/.gitkeep +0 -0
- package/template/docs/plans/ia/deep-dives/README.md +5 -0
- package/template/docs/plans/phases/.gitkeep +0 -0
- package/template/docs/plans/phases/README.md +11 -0
|
@@ -0,0 +1,712 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: c-cpp
|
|
3
|
+
description: C and C++ development patterns for systems programming. Covers memory management (RAII, smart pointers), header organization, build systems (CMake), modern C++ features (17/20/23), templates, move semantics, const correctness, sanitizers, and safe interop.
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# C/C++ Development Patterns
|
|
8
|
+
|
|
9
|
+
Expert guidance for writing safe, performant C and C++ code. Covers memory management with RAII and smart pointers, modern C++ features, build system organization, undefined behavior avoidance, sanitizer usage, and the discipline required for production systems programming.
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
- Building performance-critical systems (game engines, databases, compilers)
|
|
14
|
+
- Writing operating system components, drivers, or embedded firmware
|
|
15
|
+
- Creating libraries with C ABI for cross-language interop
|
|
16
|
+
- Implementing real-time systems with deterministic performance
|
|
17
|
+
- Developing scientific computing or numerical analysis code
|
|
18
|
+
- Building WebAssembly modules from C/C++ source
|
|
19
|
+
|
|
20
|
+
## Core Concepts
|
|
21
|
+
|
|
22
|
+
### 1. Memory Management: RAII and Smart Pointers
|
|
23
|
+
|
|
24
|
+
Resource Acquisition Is Initialization -- the foundation of safe C++.
|
|
25
|
+
|
|
26
|
+
```cpp
|
|
27
|
+
// RAII: constructor acquires, destructor releases
|
|
28
|
+
class FileHandle {
|
|
29
|
+
public:
|
|
30
|
+
explicit FileHandle(const std::string& path)
|
|
31
|
+
: handle_(std::fopen(path.c_str(), "r")) {
|
|
32
|
+
if (!handle_) {
|
|
33
|
+
throw std::runtime_error("Failed to open: " + path);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
~FileHandle() {
|
|
38
|
+
if (handle_) {
|
|
39
|
+
std::fclose(handle_);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Delete copy (prevent double-free)
|
|
44
|
+
FileHandle(const FileHandle&) = delete;
|
|
45
|
+
FileHandle& operator=(const FileHandle&) = delete;
|
|
46
|
+
|
|
47
|
+
// Allow move
|
|
48
|
+
FileHandle(FileHandle&& other) noexcept : handle_(other.handle_) {
|
|
49
|
+
other.handle_ = nullptr;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
FileHandle& operator=(FileHandle&& other) noexcept {
|
|
53
|
+
if (this != &other) {
|
|
54
|
+
if (handle_) std::fclose(handle_);
|
|
55
|
+
handle_ = other.handle_;
|
|
56
|
+
other.handle_ = nullptr;
|
|
57
|
+
}
|
|
58
|
+
return *this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
FILE* get() const { return handle_; }
|
|
62
|
+
|
|
63
|
+
private:
|
|
64
|
+
FILE* handle_;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Smart pointers -- prefer these over raw new/delete
|
|
68
|
+
#include <memory>
|
|
69
|
+
|
|
70
|
+
// unique_ptr: single ownership (default choice)
|
|
71
|
+
auto widget = std::make_unique<Widget>(42);
|
|
72
|
+
// widget automatically freed when it goes out of scope
|
|
73
|
+
|
|
74
|
+
// shared_ptr: shared ownership (use when truly needed)
|
|
75
|
+
auto shared = std::make_shared<Config>();
|
|
76
|
+
auto copy = shared; // Reference count incremented
|
|
77
|
+
// Freed when last shared_ptr is destroyed
|
|
78
|
+
|
|
79
|
+
// weak_ptr: non-owning observer (breaks reference cycles)
|
|
80
|
+
std::weak_ptr<Config> observer = shared;
|
|
81
|
+
if (auto locked = observer.lock()) {
|
|
82
|
+
// Use locked -- it is a valid shared_ptr
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// NEVER use raw new/delete in modern C++
|
|
86
|
+
// WRONG:
|
|
87
|
+
Widget* w = new Widget(42);
|
|
88
|
+
delete w;
|
|
89
|
+
|
|
90
|
+
// RIGHT:
|
|
91
|
+
auto w = std::make_unique<Widget>(42);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Smart pointer decision matrix:**
|
|
95
|
+
|
|
96
|
+
| Situation | Use |
|
|
97
|
+
|-----------|-----|
|
|
98
|
+
| Single owner, clear lifetime | `std::unique_ptr` |
|
|
99
|
+
| Shared ownership needed | `std::shared_ptr` |
|
|
100
|
+
| Observer without ownership | `std::weak_ptr` |
|
|
101
|
+
| C API interop | Raw pointer (but wrap in RAII at boundary) |
|
|
102
|
+
| Stack allocation works | No pointer at all -- use value semantics |
|
|
103
|
+
|
|
104
|
+
### 2. Header Organization
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
project/
|
|
108
|
+
include/
|
|
109
|
+
mylib/
|
|
110
|
+
mylib.h # Public C API header
|
|
111
|
+
config.hpp # Public C++ header
|
|
112
|
+
src/
|
|
113
|
+
internal.hpp # Private headers
|
|
114
|
+
config.cpp
|
|
115
|
+
parser.cpp
|
|
116
|
+
tests/
|
|
117
|
+
test_config.cpp
|
|
118
|
+
CMakeLists.txt
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
```cpp
|
|
122
|
+
// include/mylib/config.hpp -- public header
|
|
123
|
+
#pragma once // Preferred over include guards for modern compilers
|
|
124
|
+
|
|
125
|
+
#include <string>
|
|
126
|
+
#include <vector>
|
|
127
|
+
#include <optional>
|
|
128
|
+
|
|
129
|
+
namespace mylib {
|
|
130
|
+
|
|
131
|
+
struct Config {
|
|
132
|
+
std::string host;
|
|
133
|
+
int port = 8080;
|
|
134
|
+
bool debug = false;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// Forward declare implementation details
|
|
138
|
+
class ConfigLoader;
|
|
139
|
+
|
|
140
|
+
[[nodiscard]] std::optional<Config> load_config(const std::string& path);
|
|
141
|
+
|
|
142
|
+
} // namespace mylib
|
|
143
|
+
|
|
144
|
+
// src/internal.hpp -- private header (not installed/exported)
|
|
145
|
+
#pragma once
|
|
146
|
+
|
|
147
|
+
#include "mylib/config.hpp"
|
|
148
|
+
#include <fstream>
|
|
149
|
+
|
|
150
|
+
namespace mylib::detail {
|
|
151
|
+
|
|
152
|
+
Config parse_toml(std::istream& stream);
|
|
153
|
+
void validate(const Config& cfg);
|
|
154
|
+
|
|
155
|
+
} // namespace mylib::detail
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Header rules:**
|
|
159
|
+
|
|
160
|
+
| Rule | Explanation |
|
|
161
|
+
|------|-------------|
|
|
162
|
+
| Use `#pragma once` | Simpler than traditional include guards |
|
|
163
|
+
| Forward declare when possible | Reduces compile time, breaks dependency cycles |
|
|
164
|
+
| Keep headers minimal | Only include what is needed for the declaration |
|
|
165
|
+
| Separate public and private headers | `include/` for public API, `src/` for internal |
|
|
166
|
+
| Use namespaces | Prevent name collisions across libraries |
|
|
167
|
+
|
|
168
|
+
### 3. Build Systems: CMake
|
|
169
|
+
|
|
170
|
+
```cmake
|
|
171
|
+
# CMakeLists.txt -- modern CMake (3.14+)
|
|
172
|
+
cmake_minimum_required(VERSION 3.14)
|
|
173
|
+
project(mylib VERSION 1.0.0 LANGUAGES CXX)
|
|
174
|
+
|
|
175
|
+
set(CMAKE_CXX_STANDARD 20)
|
|
176
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
177
|
+
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
178
|
+
|
|
179
|
+
# Library target
|
|
180
|
+
add_library(mylib
|
|
181
|
+
src/config.cpp
|
|
182
|
+
src/parser.cpp
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
target_include_directories(mylib
|
|
186
|
+
PUBLIC
|
|
187
|
+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
188
|
+
$<INSTALL_INTERFACE:include>
|
|
189
|
+
PRIVATE
|
|
190
|
+
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
# Compiler warnings (treat as errors in CI)
|
|
194
|
+
target_compile_options(mylib PRIVATE
|
|
195
|
+
$<$<CXX_COMPILER_ID:GNU,Clang>:-Wall -Wextra -Wpedantic -Werror>
|
|
196
|
+
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
# Testing
|
|
200
|
+
option(MYLIB_BUILD_TESTS "Build tests" ON)
|
|
201
|
+
if(MYLIB_BUILD_TESTS)
|
|
202
|
+
enable_testing()
|
|
203
|
+
add_subdirectory(tests)
|
|
204
|
+
endif()
|
|
205
|
+
|
|
206
|
+
# Sanitizers (debug builds)
|
|
207
|
+
option(MYLIB_SANITIZERS "Enable sanitizers" OFF)
|
|
208
|
+
if(MYLIB_SANITIZERS)
|
|
209
|
+
target_compile_options(mylib PUBLIC -fsanitize=address,undefined -fno-omit-frame-pointer)
|
|
210
|
+
target_link_options(mylib PUBLIC -fsanitize=address,undefined)
|
|
211
|
+
endif()
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
```cmake
|
|
215
|
+
# tests/CMakeLists.txt
|
|
216
|
+
find_package(Catch2 3 REQUIRED)
|
|
217
|
+
|
|
218
|
+
add_executable(tests
|
|
219
|
+
test_config.cpp
|
|
220
|
+
test_parser.cpp
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
target_link_libraries(tests PRIVATE mylib Catch2::Catch2WithMain)
|
|
224
|
+
|
|
225
|
+
include(Catch)
|
|
226
|
+
catch_discover_tests(tests)
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### 4. Modern C++ Features
|
|
230
|
+
|
|
231
|
+
#### C++17
|
|
232
|
+
|
|
233
|
+
```cpp
|
|
234
|
+
// Structured bindings
|
|
235
|
+
auto [name, age] = get_user(); // Decompose pair/tuple/struct
|
|
236
|
+
|
|
237
|
+
std::map<std::string, int> scores = {{"Alice", 95}, {"Bob", 87}};
|
|
238
|
+
for (const auto& [name, score] : scores) {
|
|
239
|
+
std::cout << name << ": " << score << "\n";
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// std::optional
|
|
243
|
+
std::optional<User> find_user(int id) {
|
|
244
|
+
if (auto it = users.find(id); it != users.end()) {
|
|
245
|
+
return it->second;
|
|
246
|
+
}
|
|
247
|
+
return std::nullopt;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Usage
|
|
251
|
+
if (auto user = find_user(42)) {
|
|
252
|
+
std::cout << user->name << "\n";
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// std::variant -- type-safe union
|
|
256
|
+
using Value = std::variant<int, double, std::string>;
|
|
257
|
+
|
|
258
|
+
void print_value(const Value& v) {
|
|
259
|
+
std::visit([](const auto& val) {
|
|
260
|
+
std::cout << val << "\n";
|
|
261
|
+
}, v);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// std::string_view -- non-owning string reference
|
|
265
|
+
void process(std::string_view sv) {
|
|
266
|
+
// No allocation, works with string, char*, string_view
|
|
267
|
+
std::cout << sv.substr(0, 10) << "\n";
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// if constexpr -- compile-time branching
|
|
271
|
+
template <typename T>
|
|
272
|
+
auto convert(T value) {
|
|
273
|
+
if constexpr (std::is_integral_v<T>) {
|
|
274
|
+
return static_cast<double>(value);
|
|
275
|
+
} else if constexpr (std::is_floating_point_v<T>) {
|
|
276
|
+
return static_cast<int>(value);
|
|
277
|
+
} else {
|
|
278
|
+
static_assert(false, "Unsupported type");
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Fold expressions
|
|
283
|
+
template <typename... Args>
|
|
284
|
+
auto sum(Args... args) {
|
|
285
|
+
return (args + ...);
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
#### C++20
|
|
290
|
+
|
|
291
|
+
```cpp
|
|
292
|
+
// Concepts -- constrain templates with readable syntax
|
|
293
|
+
template <typename T>
|
|
294
|
+
concept Arithmetic = std::is_arithmetic_v<T>;
|
|
295
|
+
|
|
296
|
+
template <typename T>
|
|
297
|
+
concept Printable = requires(T t) {
|
|
298
|
+
{ std::cout << t } -> std::same_as<std::ostream&>;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
template <Arithmetic T>
|
|
302
|
+
T add(T a, T b) {
|
|
303
|
+
return a + b;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Ranges
|
|
307
|
+
#include <ranges>
|
|
308
|
+
|
|
309
|
+
auto even_squares = std::views::iota(1, 100)
|
|
310
|
+
| std::views::filter([](int x) { return x % 2 == 0; })
|
|
311
|
+
| std::views::transform([](int x) { return x * x; })
|
|
312
|
+
| std::views::take(10);
|
|
313
|
+
|
|
314
|
+
for (int val : even_squares) {
|
|
315
|
+
std::cout << val << " ";
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Three-way comparison (spaceship operator)
|
|
319
|
+
struct Point {
|
|
320
|
+
int x, y;
|
|
321
|
+
auto operator<=>(const Point&) const = default;
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
// std::format (type-safe formatting)
|
|
325
|
+
#include <format>
|
|
326
|
+
std::string msg = std::format("Hello, {}! You are {} years old.", name, age);
|
|
327
|
+
|
|
328
|
+
// Coroutines (generator example)
|
|
329
|
+
#include <coroutine>
|
|
330
|
+
|
|
331
|
+
generator<int> fibonacci() {
|
|
332
|
+
int a = 0, b = 1;
|
|
333
|
+
while (true) {
|
|
334
|
+
co_yield a;
|
|
335
|
+
auto temp = a;
|
|
336
|
+
a = b;
|
|
337
|
+
b = temp + b;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
#### C++23
|
|
343
|
+
|
|
344
|
+
```cpp
|
|
345
|
+
// std::expected -- Result type (like Rust's Result)
|
|
346
|
+
#include <expected>
|
|
347
|
+
|
|
348
|
+
std::expected<Config, std::string> load_config(const std::string& path) {
|
|
349
|
+
auto data = read_file(path);
|
|
350
|
+
if (!data) {
|
|
351
|
+
return std::unexpected("File not found: " + path);
|
|
352
|
+
}
|
|
353
|
+
return parse(*data);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Usage
|
|
357
|
+
auto config = load_config("settings.toml");
|
|
358
|
+
if (config) {
|
|
359
|
+
use(*config);
|
|
360
|
+
} else {
|
|
361
|
+
std::cerr << config.error() << "\n";
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// std::print (replacing cout for formatted output)
|
|
365
|
+
#include <print>
|
|
366
|
+
std::println("Hello, {}!", name);
|
|
367
|
+
|
|
368
|
+
// Deducing this (explicit object parameter)
|
|
369
|
+
struct Widget {
|
|
370
|
+
template <typename Self>
|
|
371
|
+
auto&& get_name(this Self&& self) {
|
|
372
|
+
return std::forward<Self>(self).name_;
|
|
373
|
+
}
|
|
374
|
+
private:
|
|
375
|
+
std::string name_;
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
// Multidimensional subscript operator
|
|
379
|
+
struct Matrix {
|
|
380
|
+
double& operator[](size_t row, size_t col) {
|
|
381
|
+
return data_[row * cols_ + col];
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### 5. Templates
|
|
387
|
+
|
|
388
|
+
```cpp
|
|
389
|
+
// Function template
|
|
390
|
+
template <typename T>
|
|
391
|
+
T clamp(T value, T low, T high) {
|
|
392
|
+
if (value < low) return low;
|
|
393
|
+
if (value > high) return high;
|
|
394
|
+
return value;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Class template
|
|
398
|
+
template <typename T, size_t N>
|
|
399
|
+
class FixedArray {
|
|
400
|
+
public:
|
|
401
|
+
T& operator[](size_t i) {
|
|
402
|
+
if (i >= N) throw std::out_of_range("Index out of bounds");
|
|
403
|
+
return data_[i];
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const T& operator[](size_t i) const {
|
|
407
|
+
if (i >= N) throw std::out_of_range("Index out of bounds");
|
|
408
|
+
return data_[i];
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
constexpr size_t size() const { return N; }
|
|
412
|
+
|
|
413
|
+
private:
|
|
414
|
+
T data_[N]{};
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
// SFINAE replaced by concepts in C++20
|
|
418
|
+
// Old way (avoid):
|
|
419
|
+
template <typename T, std::enable_if_t<std::is_integral_v<T>, int> = 0>
|
|
420
|
+
T old_way(T x) { return x * 2; }
|
|
421
|
+
|
|
422
|
+
// New way (prefer):
|
|
423
|
+
template <std::integral T>
|
|
424
|
+
T new_way(T x) { return x * 2; }
|
|
425
|
+
|
|
426
|
+
// Variadic templates
|
|
427
|
+
template <typename... Args>
|
|
428
|
+
void log(const std::string& fmt, Args&&... args) {
|
|
429
|
+
std::cout << std::vformat(fmt, std::make_format_args(args...));
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// CRTP (Curiously Recurring Template Pattern)
|
|
433
|
+
template <typename Derived>
|
|
434
|
+
class Comparable {
|
|
435
|
+
public:
|
|
436
|
+
bool operator!=(const Derived& other) const {
|
|
437
|
+
return !(static_cast<const Derived&>(*this) == other);
|
|
438
|
+
}
|
|
439
|
+
bool operator>(const Derived& other) const {
|
|
440
|
+
return other < static_cast<const Derived&>(*this);
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
class Temperature : public Comparable<Temperature> {
|
|
445
|
+
public:
|
|
446
|
+
explicit Temperature(double celsius) : celsius_(celsius) {}
|
|
447
|
+
bool operator==(const Temperature& other) const { return celsius_ == other.celsius_; }
|
|
448
|
+
bool operator<(const Temperature& other) const { return celsius_ < other.celsius_; }
|
|
449
|
+
private:
|
|
450
|
+
double celsius_;
|
|
451
|
+
};
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
### 6. Move Semantics
|
|
455
|
+
|
|
456
|
+
```cpp
|
|
457
|
+
class Buffer {
|
|
458
|
+
public:
|
|
459
|
+
explicit Buffer(size_t size) : size_(size), data_(new char[size]) {}
|
|
460
|
+
|
|
461
|
+
// Copy constructor (expensive)
|
|
462
|
+
Buffer(const Buffer& other) : size_(other.size_), data_(new char[other.size_]) {
|
|
463
|
+
std::memcpy(data_, other.data_, size_);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// Move constructor (cheap -- steals resources)
|
|
467
|
+
Buffer(Buffer&& other) noexcept : size_(other.size_), data_(other.data_) {
|
|
468
|
+
other.size_ = 0;
|
|
469
|
+
other.data_ = nullptr;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// Copy assignment
|
|
473
|
+
Buffer& operator=(const Buffer& other) {
|
|
474
|
+
if (this != &other) {
|
|
475
|
+
Buffer temp(other);
|
|
476
|
+
swap(temp);
|
|
477
|
+
}
|
|
478
|
+
return *this;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// Move assignment
|
|
482
|
+
Buffer& operator=(Buffer&& other) noexcept {
|
|
483
|
+
if (this != &other) {
|
|
484
|
+
delete[] data_;
|
|
485
|
+
data_ = other.data_;
|
|
486
|
+
size_ = other.size_;
|
|
487
|
+
other.data_ = nullptr;
|
|
488
|
+
other.size_ = 0;
|
|
489
|
+
}
|
|
490
|
+
return *this;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
~Buffer() { delete[] data_; }
|
|
494
|
+
|
|
495
|
+
void swap(Buffer& other) noexcept {
|
|
496
|
+
std::swap(size_, other.size_);
|
|
497
|
+
std::swap(data_, other.data_);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
private:
|
|
501
|
+
size_t size_;
|
|
502
|
+
char* data_;
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
// Perfect forwarding
|
|
506
|
+
template <typename T, typename... Args>
|
|
507
|
+
std::unique_ptr<T> make_unique_wrapper(Args&&... args) {
|
|
508
|
+
return std::make_unique<T>(std::forward<Args>(args)...);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// Rule of Five: if you define any of destructor, copy/move constructor,
|
|
512
|
+
// copy/move assignment, you should define ALL of them (or = delete them).
|
|
513
|
+
// Rule of Zero: prefer classes that need NONE of them (use smart pointers).
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
### 7. Const Correctness
|
|
517
|
+
|
|
518
|
+
```cpp
|
|
519
|
+
class Database {
|
|
520
|
+
public:
|
|
521
|
+
// const member function -- does not modify the object
|
|
522
|
+
[[nodiscard]] size_t count() const { return records_.size(); }
|
|
523
|
+
|
|
524
|
+
// const reference return -- prevents modification of internal data
|
|
525
|
+
[[nodiscard]] const Record& get(size_t id) const {
|
|
526
|
+
return records_.at(id);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// Non-const version for modification
|
|
530
|
+
Record& get(size_t id) {
|
|
531
|
+
return records_.at(id);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// const parameter -- function will not modify the argument
|
|
535
|
+
void insert(const Record& record) {
|
|
536
|
+
records_.push_back(record);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// Move overload -- takes ownership efficiently
|
|
540
|
+
void insert(Record&& record) {
|
|
541
|
+
records_.push_back(std::move(record));
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
private:
|
|
545
|
+
std::vector<Record> records_;
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
// constexpr -- evaluated at compile time
|
|
549
|
+
constexpr int factorial(int n) {
|
|
550
|
+
if (n <= 1) return 1;
|
|
551
|
+
return n * factorial(n - 1);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
static_assert(factorial(5) == 120, "Factorial computation failed");
|
|
555
|
+
|
|
556
|
+
// consteval (C++20) -- MUST be evaluated at compile time
|
|
557
|
+
consteval int compile_time_only(int x) {
|
|
558
|
+
return x * x;
|
|
559
|
+
}
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
### 8. Undefined Behavior and Sanitizers
|
|
563
|
+
|
|
564
|
+
Common sources of undefined behavior:
|
|
565
|
+
|
|
566
|
+
| UB Source | Example | Safe Alternative |
|
|
567
|
+
|-----------|---------|-----------------|
|
|
568
|
+
| Null pointer dereference | `*nullptr` | Check before dereferencing, use `std::optional` |
|
|
569
|
+
| Buffer overflow | `arr[out_of_bounds]` | Use `std::vector::at()`, `std::span` |
|
|
570
|
+
| Signed integer overflow | `INT_MAX + 1` | Check before arithmetic, use unsigned |
|
|
571
|
+
| Use after free | `delete p; *p;` | Use smart pointers |
|
|
572
|
+
| Data race | Unsynchronized concurrent access | Use `std::mutex`, `std::atomic` |
|
|
573
|
+
| Uninitialized variable | `int x; use(x);` | Always initialize: `int x = 0;` |
|
|
574
|
+
|
|
575
|
+
```bash
|
|
576
|
+
# Compile with sanitizers during development and CI
|
|
577
|
+
|
|
578
|
+
# AddressSanitizer -- buffer overflows, use-after-free, leaks
|
|
579
|
+
g++ -fsanitize=address -fno-omit-frame-pointer -g main.cpp
|
|
580
|
+
|
|
581
|
+
# UndefinedBehaviorSanitizer -- signed overflow, null deref, etc.
|
|
582
|
+
g++ -fsanitize=undefined -g main.cpp
|
|
583
|
+
|
|
584
|
+
# MemorySanitizer (Clang only) -- uninitialized reads
|
|
585
|
+
clang++ -fsanitize=memory -fno-omit-frame-pointer -g main.cpp
|
|
586
|
+
|
|
587
|
+
# ThreadSanitizer -- data races
|
|
588
|
+
g++ -fsanitize=thread -g main.cpp
|
|
589
|
+
|
|
590
|
+
# Combine sanitizers (ASan + UBSan)
|
|
591
|
+
g++ -fsanitize=address,undefined -fno-omit-frame-pointer -g main.cpp
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
### 9. C Interop
|
|
595
|
+
|
|
596
|
+
```cpp
|
|
597
|
+
// C-compatible header (include from both C and C++)
|
|
598
|
+
#ifdef __cplusplus
|
|
599
|
+
extern "C" {
|
|
600
|
+
#endif
|
|
601
|
+
|
|
602
|
+
typedef struct MyHandle MyHandle;
|
|
603
|
+
|
|
604
|
+
MyHandle* mylib_create(const char* name);
|
|
605
|
+
void mylib_destroy(MyHandle* handle);
|
|
606
|
+
int mylib_process(MyHandle* handle, const char* input, char* output, size_t output_size);
|
|
607
|
+
const char* mylib_error(const MyHandle* handle);
|
|
608
|
+
|
|
609
|
+
#ifdef __cplusplus
|
|
610
|
+
}
|
|
611
|
+
#endif
|
|
612
|
+
|
|
613
|
+
// C++ implementation
|
|
614
|
+
extern "C" {
|
|
615
|
+
|
|
616
|
+
MyHandle* mylib_create(const char* name) {
|
|
617
|
+
try {
|
|
618
|
+
return reinterpret_cast<MyHandle*>(new MyLibImpl(name));
|
|
619
|
+
} catch (...) {
|
|
620
|
+
return nullptr;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
void mylib_destroy(MyHandle* handle) {
|
|
625
|
+
delete reinterpret_cast<MyLibImpl*>(handle);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
} // extern "C"
|
|
629
|
+
|
|
630
|
+
// C++ wrapper for C library
|
|
631
|
+
class CLibWrapper {
|
|
632
|
+
public:
|
|
633
|
+
CLibWrapper(const std::string& name)
|
|
634
|
+
: handle_(mylib_create(name.c_str()), &mylib_destroy) {
|
|
635
|
+
if (!handle_) {
|
|
636
|
+
throw std::runtime_error("Failed to create handle");
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// RAII -- destructor calls mylib_destroy via unique_ptr deleter
|
|
641
|
+
|
|
642
|
+
private:
|
|
643
|
+
std::unique_ptr<MyHandle, decltype(&mylib_destroy)> handle_;
|
|
644
|
+
};
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
### 10. STL Containers
|
|
648
|
+
|
|
649
|
+
| Container | Use Case | Lookup | Insert | Notes |
|
|
650
|
+
|-----------|----------|--------|--------|-------|
|
|
651
|
+
| `std::vector` | Default choice | O(n) | O(1) amortized | Cache-friendly, contiguous memory |
|
|
652
|
+
| `std::array` | Fixed size, stack | O(n) | N/A | No heap allocation |
|
|
653
|
+
| `std::unordered_map` | Key-value lookup | O(1) avg | O(1) avg | Hash table |
|
|
654
|
+
| `std::map` | Ordered key-value | O(log n) | O(log n) | Red-black tree |
|
|
655
|
+
| `std::string` | Text | O(n) | O(1) amortized | SSO for short strings |
|
|
656
|
+
| `std::span` (C++20) | Non-owning view | O(n) | N/A | Like string_view for arrays |
|
|
657
|
+
| `std::deque` | Front/back insert | O(n) | O(1) both ends | Not contiguous |
|
|
658
|
+
| `std::flat_map` (C++23) | Small ordered maps | O(log n) | O(n) | Sorted vector, cache-friendly |
|
|
659
|
+
|
|
660
|
+
```cpp
|
|
661
|
+
// Prefer vector unless you have a specific reason not to
|
|
662
|
+
std::vector<int> data;
|
|
663
|
+
data.reserve(1000); // Pre-allocate to avoid reallocations
|
|
664
|
+
|
|
665
|
+
// Use emplace_back to construct in-place
|
|
666
|
+
std::vector<std::string> names;
|
|
667
|
+
names.emplace_back("Alice"); // Constructs string directly in vector
|
|
668
|
+
|
|
669
|
+
// Range-based erase (C++20)
|
|
670
|
+
std::erase_if(data, [](int x) { return x < 0; });
|
|
671
|
+
```
|
|
672
|
+
|
|
673
|
+
## Anti-Patterns
|
|
674
|
+
|
|
675
|
+
| Anti-Pattern | Why It Is Bad | Do This Instead |
|
|
676
|
+
|-------------|--------------|----------------|
|
|
677
|
+
| Raw `new`/`delete` | Memory leaks, double-free | `std::make_unique`, `std::make_shared` |
|
|
678
|
+
| C-style casts `(int)x` | Hides dangerous conversions | `static_cast`, `dynamic_cast` |
|
|
679
|
+
| `#define` for constants | No type safety, no scope | `constexpr` variables |
|
|
680
|
+
| `using namespace std;` in headers | Pollutes all includers | Use qualified names or targeted `using` |
|
|
681
|
+
| Macro functions | No type checking, surprising behavior | `constexpr` functions or templates |
|
|
682
|
+
| `std::endl` everywhere | Flushes buffer unnecessarily | Use `"\n"` for newlines |
|
|
683
|
+
| Catching exceptions by value | Object slicing | Catch by `const&` |
|
|
684
|
+
|
|
685
|
+
## Common Commands
|
|
686
|
+
|
|
687
|
+
```bash
|
|
688
|
+
# CMake build
|
|
689
|
+
cmake -B build -DCMAKE_BUILD_TYPE=Debug
|
|
690
|
+
cmake --build build
|
|
691
|
+
ctest --test-dir build
|
|
692
|
+
|
|
693
|
+
# With sanitizers
|
|
694
|
+
cmake -B build-san -DCMAKE_BUILD_TYPE=Debug -DMYLIB_SANITIZERS=ON
|
|
695
|
+
cmake --build build-san
|
|
696
|
+
ctest --test-dir build-san
|
|
697
|
+
|
|
698
|
+
# Clang-tidy static analysis
|
|
699
|
+
clang-tidy src/*.cpp -- -std=c++20 -Iinclude
|
|
700
|
+
|
|
701
|
+
# Clang-format
|
|
702
|
+
clang-format -i src/*.cpp include/**/*.hpp
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
## Resources
|
|
706
|
+
|
|
707
|
+
- **C++ Core Guidelines**: https://isocpp.github.io/CppCoreGuidelines/
|
|
708
|
+
- **cppreference.com**: https://en.cppreference.com/
|
|
709
|
+
- **Compiler Explorer (Godbolt)**: https://godbolt.org/
|
|
710
|
+
- **C++ Weekly (Jason Turner)**: https://www.youtube.com/c/lefticus
|
|
711
|
+
- **Modern CMake**: https://cliutils.gitlab.io/modern-cmake/
|
|
712
|
+
- **Sanitizer Docs**: https://clang.llvm.org/docs/AddressSanitizer.html
|