@cubis/foundry 0.3.71 → 0.3.72
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/CHANGELOG.md +15 -0
- package/dist/cli/core.js +4 -18
- package/dist/cli/core.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/core.ts +4 -18
- package/workflows/powers/accessibility/POWER.md +83 -94
- package/workflows/powers/accessibility/SKILL.md +82 -94
- package/workflows/powers/agent-design/POWER.md +201 -0
- package/workflows/powers/agent-design/SKILL.md +198 -0
- package/workflows/powers/agent-design/references/clarification-patterns.md +153 -0
- package/workflows/powers/agent-design/references/skill-testing.md +164 -0
- package/workflows/powers/agent-design/references/workflow-patterns.md +226 -0
- package/workflows/powers/agentic-eval/POWER.md +62 -0
- package/workflows/powers/agentic-eval/SKILL.md +59 -0
- package/workflows/powers/agentic-eval/references/rubric-and-regression-checklist.md +11 -0
- package/workflows/powers/api-designer/POWER.md +43 -71
- package/workflows/powers/api-designer/SKILL.md +43 -71
- package/workflows/powers/api-patterns/POWER.md +42 -56
- package/workflows/powers/api-patterns/SKILL.md +42 -57
- package/workflows/powers/architecture-designer/POWER.md +43 -60
- package/workflows/powers/architecture-designer/SKILL.md +43 -60
- package/workflows/powers/ask-questions-if-underspecified/POWER.md +51 -3
- package/workflows/powers/auth-architect/POWER.md +69 -0
- package/workflows/powers/auth-architect/SKILL.md +66 -0
- package/workflows/powers/auth-architect/references/session-token-policy-checklist.md +45 -0
- package/workflows/powers/behavioral-modes/POWER.md +100 -9
- package/workflows/powers/c-pro/POWER.md +105 -0
- package/workflows/powers/c-pro/SKILL.md +102 -0
- package/workflows/powers/c-pro/references/build-systems-and-toolchains.md +148 -0
- package/workflows/powers/c-pro/references/common-ub-and-portability.md +166 -0
- package/workflows/powers/c-pro/references/debugging-with-sanitizers.md +205 -0
- package/workflows/powers/c-pro/references/memory-safety-and-build-checklist.md +60 -0
- package/workflows/powers/c-pro/references/posix-and-platform-apis.md +244 -0
- package/workflows/powers/changelog-generator/POWER.md +127 -63
- package/workflows/powers/changelog-generator/SKILL.md +126 -63
- package/workflows/powers/ci-cd-pipelines/POWER.md +156 -0
- package/workflows/powers/ci-cd-pipelines/SKILL.md +153 -0
- package/workflows/powers/ci-cd-pipelines/references/github-actions-patterns.md +160 -0
- package/workflows/powers/ci-cd-pipelines/references/pipeline-security-checklist.md +57 -0
- package/workflows/powers/cli-developer/POWER.md +152 -95
- package/workflows/powers/cli-developer/SKILL.md +152 -95
- package/workflows/powers/cpp-pro/POWER.md +111 -0
- package/workflows/powers/cpp-pro/SKILL.md +108 -0
- package/workflows/powers/cpp-pro/references/concurrency-primitives.md +266 -0
- package/workflows/powers/cpp-pro/references/move-semantics-and-value-types.md +149 -0
- package/workflows/powers/cpp-pro/references/performance-and-profiling.md +191 -0
- package/workflows/powers/cpp-pro/references/raii-and-modern-cpp-checklist.md +87 -0
- package/workflows/powers/cpp-pro/references/template-and-concepts-patterns.md +205 -0
- package/workflows/powers/csharp-pro/POWER.md +47 -22
- package/workflows/powers/csharp-pro/SKILL.md +47 -22
- package/workflows/powers/dart-pro/POWER.md +68 -0
- package/workflows/powers/dart-pro/SKILL.md +65 -0
- package/workflows/powers/dart-pro/references/isolate-and-concurrency.md +180 -0
- package/workflows/powers/dart-pro/references/null-safety-and-async-patterns.md +133 -0
- package/workflows/powers/dart-pro/references/package-structure-and-linting.md +193 -0
- package/workflows/powers/dart-pro/references/sealed-records-patterns.md +173 -0
- package/workflows/powers/dart-pro/references/testing-and-mocking.md +235 -0
- package/workflows/powers/database-design/POWER.md +47 -33
- package/workflows/powers/database-design/SKILL.md +47 -33
- package/workflows/powers/database-optimizer/POWER.md +43 -64
- package/workflows/powers/database-optimizer/SKILL.md +43 -64
- package/workflows/powers/database-skills/POWER.md +59 -93
- package/workflows/powers/database-skills/SKILL.md +59 -93
- package/workflows/powers/debugging-strategies/POWER.md +69 -0
- package/workflows/powers/debugging-strategies/SKILL.md +66 -0
- package/workflows/powers/debugging-strategies/references/reproduce-isolate-verify-checklist.md +42 -0
- package/workflows/powers/deep-research/POWER.md +67 -0
- package/workflows/powers/deep-research/SKILL.md +64 -0
- package/workflows/powers/deep-research/references/multi-round-research-loop.md +80 -0
- package/workflows/powers/design-system-builder/POWER.md +130 -116
- package/workflows/powers/design-system-builder/SKILL.md +130 -116
- package/workflows/powers/devops-engineer/POWER.md +120 -57
- package/workflows/powers/devops-engineer/SKILL.md +120 -57
- package/workflows/powers/docker-kubernetes/POWER.md +94 -0
- package/workflows/powers/docker-kubernetes/SKILL.md +91 -0
- package/workflows/powers/docker-kubernetes/references/dockerfile-optimization-checklist.md +35 -0
- package/workflows/powers/docker-kubernetes/references/kubernetes-deployment-patterns.md +59 -0
- package/workflows/powers/documentation-templates/POWER.md +158 -127
- package/workflows/powers/documentation-templates/SKILL.md +158 -127
- package/workflows/powers/drizzle-expert/POWER.md +66 -0
- package/workflows/powers/drizzle-expert/SKILL.md +63 -0
- package/workflows/powers/drizzle-expert/references/runtime-pairing-matrix.md +16 -0
- package/workflows/powers/drizzle-expert/references/schema-and-migration-playbook.md +18 -0
- package/workflows/powers/error-ux-observability/POWER.md +144 -131
- package/workflows/powers/error-ux-observability/SKILL.md +143 -131
- package/workflows/powers/fastapi-expert/POWER.md +46 -60
- package/workflows/powers/fastapi-expert/SKILL.md +46 -60
- package/workflows/powers/firebase/POWER.md +65 -0
- package/workflows/powers/firebase/SKILL.md +62 -0
- package/workflows/powers/firebase/references/platform-routing.md +16 -0
- package/workflows/powers/firebase/references/rules-and-indexes-checklist.md +11 -0
- package/workflows/powers/flutter-design-system/POWER.md +63 -0
- package/workflows/powers/flutter-design-system/SKILL.md +60 -0
- package/workflows/powers/flutter-design-system/references/shared-widgets.md +29 -0
- package/workflows/powers/flutter-design-system/references/tokens-and-theme.md +34 -0
- package/workflows/powers/flutter-drift/POWER.md +65 -0
- package/workflows/powers/flutter-drift/SKILL.md +62 -0
- package/workflows/powers/flutter-drift/references/migrations.md +22 -0
- package/workflows/powers/flutter-drift/references/query-patterns.md +26 -0
- package/workflows/powers/flutter-feature/POWER.md +65 -0
- package/workflows/powers/flutter-feature/SKILL.md +62 -0
- package/workflows/powers/flutter-feature/references/architecture-rules.md +85 -0
- package/workflows/powers/flutter-feature/references/composite-provider.md +58 -0
- package/workflows/powers/flutter-feature/references/outbox-pattern.md +87 -0
- package/workflows/powers/flutter-feature/references/testing-patterns.md +218 -0
- package/workflows/powers/flutter-go-router/POWER.md +64 -0
- package/workflows/powers/flutter-go-router/SKILL.md +61 -0
- package/workflows/powers/flutter-go-router/references/guards-and-deeplinks.md +20 -0
- package/workflows/powers/flutter-go-router/references/typed-routes.md +27 -0
- package/workflows/powers/flutter-offline-sync/POWER.md +62 -0
- package/workflows/powers/flutter-offline-sync/SKILL.md +59 -0
- package/workflows/powers/flutter-offline-sync/references/outbox-full.md +44 -0
- package/workflows/powers/flutter-repository/POWER.md +64 -0
- package/workflows/powers/flutter-repository/SKILL.md +61 -0
- package/workflows/powers/flutter-repository/references/drift-patterns.md +21 -0
- package/workflows/powers/flutter-repository/references/retrofit-patterns.md +20 -0
- package/workflows/powers/flutter-riverpod/POWER.md +70 -0
- package/workflows/powers/flutter-riverpod/SKILL.md +67 -0
- package/workflows/powers/flutter-riverpod/references/async-and-mutations.md +19 -0
- package/workflows/powers/flutter-riverpod/references/async-lifecycle.md +19 -0
- package/workflows/powers/flutter-riverpod/references/provider-selection.md +20 -0
- package/workflows/powers/flutter-riverpod/references/testing.md +21 -0
- package/workflows/powers/flutter-riverpod/references/version-matrix.md +24 -0
- package/workflows/powers/flutter-state-machine/POWER.md +62 -0
- package/workflows/powers/flutter-state-machine/SKILL.md +59 -0
- package/workflows/powers/flutter-state-machine/references/app-state-contract.md +23 -0
- package/workflows/powers/flutter-state-machine/references/ui-rendering.md +14 -0
- package/workflows/powers/flutter-testing/POWER.md +64 -0
- package/workflows/powers/flutter-testing/SKILL.md +61 -0
- package/workflows/powers/flutter-testing/references/offline-sync-tests.md +16 -0
- package/workflows/powers/flutter-testing/references/test-layers.md +33 -0
- package/workflows/powers/frontend-code-review/POWER.md +137 -0
- package/workflows/powers/frontend-code-review/SKILL.md +134 -0
- package/workflows/powers/frontend-code-review/references/common-antipatterns.md +86 -0
- package/workflows/powers/frontend-code-review/references/performance-budgets.md +56 -0
- package/workflows/powers/frontend-code-review/references/review-checklists.md +47 -0
- package/workflows/powers/frontend-design/POWER.md +163 -362
- package/workflows/powers/frontend-design/SKILL.md +163 -362
- package/workflows/powers/game-development/POWER.md +57 -140
- package/workflows/powers/game-development/SKILL.md +57 -140
- package/workflows/powers/geo-fundamentals/POWER.md +64 -126
- package/workflows/powers/geo-fundamentals/SKILL.md +64 -127
- package/workflows/powers/git-workflow/POWER.md +135 -0
- package/workflows/powers/git-workflow/SKILL.md +132 -0
- package/workflows/powers/git-workflow/references/pr-review-checklist.md +63 -0
- package/workflows/powers/golang-pro/POWER.md +46 -35
- package/workflows/powers/golang-pro/SKILL.md +46 -35
- package/workflows/powers/graphql-architect/POWER.md +44 -62
- package/workflows/powers/graphql-architect/SKILL.md +44 -62
- package/workflows/powers/i18n-localization/POWER.md +118 -103
- package/workflows/powers/i18n-localization/SKILL.md +118 -103
- package/workflows/powers/java-pro/POWER.md +47 -22
- package/workflows/powers/java-pro/SKILL.md +47 -22
- package/workflows/powers/javascript-pro/POWER.md +47 -34
- package/workflows/powers/javascript-pro/SKILL.md +47 -34
- package/workflows/powers/kotlin-pro/POWER.md +46 -23
- package/workflows/powers/kotlin-pro/SKILL.md +46 -23
- package/workflows/powers/legacy-modernizer/POWER.md +43 -60
- package/workflows/powers/legacy-modernizer/SKILL.md +43 -60
- package/workflows/powers/mcp-builder/POWER.md +65 -0
- package/workflows/powers/mcp-builder/SKILL.md +62 -0
- package/workflows/powers/mcp-builder/references/testing-and-evals.md +17 -0
- package/workflows/powers/mcp-builder/references/transport-and-tool-design.md +17 -0
- package/workflows/powers/microservices-architect/POWER.md +43 -70
- package/workflows/powers/microservices-architect/SKILL.md +43 -70
- package/workflows/powers/mobile-design/POWER.md +110 -345
- package/workflows/powers/mobile-design/SKILL.md +110 -345
- package/workflows/powers/mongodb/POWER.md +67 -0
- package/workflows/powers/mongodb/SKILL.md +64 -0
- package/workflows/powers/mongodb/references/mongodb-checklist.md +20 -0
- package/workflows/powers/mysql/POWER.md +67 -0
- package/workflows/powers/mysql/SKILL.md +64 -0
- package/workflows/powers/mysql/references/mysql-checklist.md +20 -0
- package/workflows/powers/neki/POWER.md +67 -0
- package/workflows/powers/neki/SKILL.md +64 -0
- package/workflows/powers/neki/references/neki-checklist.md +18 -0
- package/workflows/powers/nestjs-expert/POWER.md +45 -91
- package/workflows/powers/nestjs-expert/SKILL.md +45 -91
- package/workflows/powers/nextjs-developer/POWER.md +51 -44
- package/workflows/powers/nextjs-developer/SKILL.md +51 -44
- package/workflows/powers/nodejs-best-practices/POWER.md +48 -29
- package/workflows/powers/nodejs-best-practices/SKILL.md +48 -29
- package/workflows/powers/observability/POWER.md +109 -0
- package/workflows/powers/observability/SKILL.md +106 -0
- package/workflows/powers/observability/references/alerting-and-slo-checklist.md +87 -0
- package/workflows/powers/observability/references/opentelemetry-setup-guide.md +121 -0
- package/workflows/powers/openai-docs/POWER.md +61 -0
- package/workflows/powers/openai-docs/SKILL.md +58 -0
- package/workflows/powers/openai-docs/references/official-source-playbook.md +10 -0
- package/workflows/powers/performance-profiling/POWER.md +61 -114
- package/workflows/powers/performance-profiling/SKILL.md +61 -114
- package/workflows/powers/php-pro/POWER.md +116 -0
- package/workflows/powers/php-pro/SKILL.md +113 -0
- package/workflows/powers/php-pro/references/architecture-and-di.md +239 -0
- package/workflows/powers/php-pro/references/modern-php-features.md +189 -0
- package/workflows/powers/php-pro/references/performance-and-deployment.md +197 -0
- package/workflows/powers/php-pro/references/php84-strict-typing-checklist.md +161 -0
- package/workflows/powers/php-pro/references/testing-and-static-analysis.md +235 -0
- package/workflows/powers/playwright-e2e/POWER.md +85 -0
- package/workflows/powers/playwright-e2e/SKILL.md +82 -0
- package/workflows/powers/playwright-e2e/references/locator-trace-flake-checklist.md +80 -0
- package/workflows/powers/postgres/POWER.md +67 -0
- package/workflows/powers/postgres/SKILL.md +64 -0
- package/workflows/powers/postgres/references/postgres-checklist.md +20 -0
- package/workflows/powers/prompt-engineer/POWER.md +47 -30
- package/workflows/powers/prompt-engineer/SKILL.md +47 -30
- package/workflows/powers/python-pro/POWER.md +47 -36
- package/workflows/powers/python-pro/SKILL.md +47 -36
- package/workflows/powers/react-best-practices/POWER.md +56 -33
- package/workflows/powers/react-best-practices/SKILL.md +56 -33
- package/workflows/powers/react-expert/POWER.md +47 -37
- package/workflows/powers/react-expert/SKILL.md +47 -37
- package/workflows/powers/redis/POWER.md +67 -0
- package/workflows/powers/redis/SKILL.md +64 -0
- package/workflows/powers/redis/references/redis-checklist.md +19 -0
- package/workflows/powers/ruby-pro/POWER.md +118 -0
- package/workflows/powers/ruby-pro/SKILL.md +115 -0
- package/workflows/powers/ruby-pro/references/modern-ruby-features.md +189 -0
- package/workflows/powers/ruby-pro/references/object-design-patterns.md +220 -0
- package/workflows/powers/ruby-pro/references/performance-and-profiling.md +224 -0
- package/workflows/powers/ruby-pro/references/ruby-concurrency-and-testing.md +190 -0
- package/workflows/powers/ruby-pro/references/testing-and-rspec.md +236 -0
- package/workflows/powers/rust-pro/POWER.md +45 -31
- package/workflows/powers/rust-pro/SKILL.md +45 -31
- package/workflows/powers/security-engineer/POWER.md +129 -0
- package/workflows/powers/security-engineer/SKILL.md +126 -0
- package/workflows/powers/seo-fundamentals/POWER.md +59 -102
- package/workflows/powers/seo-fundamentals/SKILL.md +59 -102
- package/workflows/powers/serverless-patterns/POWER.md +171 -0
- package/workflows/powers/serverless-patterns/SKILL.md +168 -0
- package/workflows/powers/skill-creator/POWER.md +90 -0
- package/workflows/powers/skill-creator/SKILL.md +87 -0
- package/workflows/powers/skill-creator/references/platform-formats.md +181 -0
- package/workflows/powers/skill-creator/references/schemas.md +430 -0
- package/workflows/powers/spec-miner/POWER.md +49 -57
- package/workflows/powers/spec-miner/SKILL.md +49 -57
- package/workflows/powers/sqlite/POWER.md +67 -0
- package/workflows/powers/sqlite/SKILL.md +64 -0
- package/workflows/powers/sqlite/references/sqlite-checklist.md +19 -0
- package/workflows/powers/sre-engineer/POWER.md +123 -64
- package/workflows/powers/sre-engineer/SKILL.md +123 -64
- package/workflows/powers/static-analysis/POWER.md +121 -77
- package/workflows/powers/static-analysis/SKILL.md +121 -77
- package/workflows/powers/stripe-best-practices/POWER.md +140 -17
- package/workflows/powers/stripe-best-practices/SKILL.md +139 -17
- package/workflows/powers/supabase/POWER.md +67 -0
- package/workflows/powers/supabase/SKILL.md +64 -0
- package/workflows/powers/supabase/references/supabase-checklist.md +19 -0
- package/workflows/powers/swift-pro/POWER.md +118 -0
- package/workflows/powers/swift-pro/SKILL.md +115 -0
- package/workflows/powers/swift-pro/references/concurrency-patterns.md +165 -0
- package/workflows/powers/swift-pro/references/protocol-and-generics.md +172 -0
- package/workflows/powers/swift-pro/references/sendable-and-isolation.md +116 -0
- package/workflows/powers/swift-pro/references/swift-concurrency-and-protocols.md +260 -0
- package/workflows/powers/swift-pro/references/testing-and-packages.md +192 -0
- package/workflows/powers/tailwind-patterns/POWER.md +71 -240
- package/workflows/powers/tailwind-patterns/SKILL.md +71 -240
- package/workflows/powers/testing-patterns/POWER.md +155 -10
- package/workflows/powers/testing-patterns/SKILL.md +155 -10
- package/workflows/powers/typescript-pro/POWER.md +47 -38
- package/workflows/powers/typescript-pro/SKILL.md +47 -38
- package/workflows/powers/vitess/POWER.md +67 -0
- package/workflows/powers/vitess/SKILL.md +64 -0
- package/workflows/powers/vitess/references/vitess-checklist.md +19 -0
- package/workflows/powers/vulnerability-scanner/POWER.md +146 -10
- package/workflows/powers/vulnerability-scanner/SKILL.md +146 -10
- package/workflows/powers/web-perf/POWER.md +43 -170
- package/workflows/powers/web-perf/SKILL.md +43 -170
- package/workflows/powers/webapp-testing/POWER.md +43 -164
- package/workflows/powers/webapp-testing/SKILL.md +43 -164
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
````markdown
|
|
2
|
+
---
|
|
3
|
+
inclusion: manual
|
|
4
|
+
name: supabase
|
|
5
|
+
description: "Use when the task is specifically Supabase: managed Postgres with RLS, auth, storage, edge functions, branching, and product decisions that depend on Supabase platform behavior."
|
|
6
|
+
license: MIT
|
|
7
|
+
metadata:
|
|
8
|
+
author: cubis-foundry
|
|
9
|
+
version: "3.0"
|
|
10
|
+
compatibility: Claude Code, Codex, GitHub Copilot
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Supabase
|
|
14
|
+
|
|
15
|
+
## Purpose
|
|
16
|
+
|
|
17
|
+
Use when the task is specifically Supabase: managed Postgres with RLS, auth, storage, edge functions, branching, and product decisions that depend on Supabase platform behavior.
|
|
18
|
+
|
|
19
|
+
## When to Use
|
|
20
|
+
|
|
21
|
+
- The stack is Supabase and platform features such as RLS, auth, storage, or edge functions affect the answer.
|
|
22
|
+
- The task depends on how managed Postgres behavior interacts with Supabase product surfaces.
|
|
23
|
+
- You need Supabase-specific migration, policy, or operational guidance.
|
|
24
|
+
|
|
25
|
+
## Instructions
|
|
26
|
+
|
|
27
|
+
1. Confirm which Supabase surfaces are in play: Postgres, RLS, Auth, Storage, Realtime, or Edge Functions.
|
|
28
|
+
2. Separate pure Postgres design from platform policy and developer-experience constraints.
|
|
29
|
+
3. Design schema, policies, and integration boundaries together so access control stays coherent.
|
|
30
|
+
4. Validate migrations, branching, and operational rollout against Supabase’s managed posture.
|
|
31
|
+
5. Report platform-specific limits, coupling, and rollback considerations explicitly.
|
|
32
|
+
|
|
33
|
+
### Baseline standards
|
|
34
|
+
|
|
35
|
+
- Treat RLS and auth flows as core design inputs, not afterthoughts.
|
|
36
|
+
- Keep database policy logic understandable and testable.
|
|
37
|
+
- Use plain Postgres reasoning first, then add Supabase-specific constraints.
|
|
38
|
+
- Make platform lock-in or coupling explicit when it affects long-term architecture.
|
|
39
|
+
|
|
40
|
+
### Constraints
|
|
41
|
+
|
|
42
|
+
- Avoid mixing product policy and schema logic without clear ownership.
|
|
43
|
+
- Avoid overcomplicating RLS rules with no test strategy.
|
|
44
|
+
- Avoid assuming Supabase convenience removes the need for migration discipline.
|
|
45
|
+
- Avoid treating Supabase as generic Postgres when platform behavior clearly matters.
|
|
46
|
+
|
|
47
|
+
## Output Format
|
|
48
|
+
|
|
49
|
+
Provide implementation guidance, code examples, and configuration as appropriate to the task.
|
|
50
|
+
|
|
51
|
+
## References
|
|
52
|
+
|
|
53
|
+
Load on demand. Do not preload all reference files.
|
|
54
|
+
|
|
55
|
+
| File | Load when |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `references/supabase-checklist.md` | You need deeper Supabase guidance for RLS, auth, storage, platform coupling, and managed rollout decisions. |
|
|
58
|
+
|
|
59
|
+
## Scripts
|
|
60
|
+
|
|
61
|
+
No helper scripts are required for this skill right now. Keep execution in `SKILL.md` and `references/` unless repeated automation becomes necessary.
|
|
62
|
+
|
|
63
|
+
## Examples
|
|
64
|
+
|
|
65
|
+
- "Help me with supabase best practices in this project"
|
|
66
|
+
- "Review my supabase implementation for issues"
|
|
67
|
+
````
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: supabase
|
|
3
|
+
description: "Use when the task is specifically Supabase: managed Postgres with RLS, auth, storage, edge functions, branching, and product decisions that depend on Supabase platform behavior."
|
|
4
|
+
license: MIT
|
|
5
|
+
metadata:
|
|
6
|
+
author: cubis-foundry
|
|
7
|
+
version: "3.0"
|
|
8
|
+
compatibility: Claude Code, Codex, GitHub Copilot
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Supabase
|
|
12
|
+
|
|
13
|
+
## Purpose
|
|
14
|
+
|
|
15
|
+
Use when the task is specifically Supabase: managed Postgres with RLS, auth, storage, edge functions, branching, and product decisions that depend on Supabase platform behavior.
|
|
16
|
+
|
|
17
|
+
## When to Use
|
|
18
|
+
|
|
19
|
+
- The stack is Supabase and platform features such as RLS, auth, storage, or edge functions affect the answer.
|
|
20
|
+
- The task depends on how managed Postgres behavior interacts with Supabase product surfaces.
|
|
21
|
+
- You need Supabase-specific migration, policy, or operational guidance.
|
|
22
|
+
|
|
23
|
+
## Instructions
|
|
24
|
+
|
|
25
|
+
1. Confirm which Supabase surfaces are in play: Postgres, RLS, Auth, Storage, Realtime, or Edge Functions.
|
|
26
|
+
2. Separate pure Postgres design from platform policy and developer-experience constraints.
|
|
27
|
+
3. Design schema, policies, and integration boundaries together so access control stays coherent.
|
|
28
|
+
4. Validate migrations, branching, and operational rollout against Supabase’s managed posture.
|
|
29
|
+
5. Report platform-specific limits, coupling, and rollback considerations explicitly.
|
|
30
|
+
|
|
31
|
+
### Baseline standards
|
|
32
|
+
|
|
33
|
+
- Treat RLS and auth flows as core design inputs, not afterthoughts.
|
|
34
|
+
- Keep database policy logic understandable and testable.
|
|
35
|
+
- Use plain Postgres reasoning first, then add Supabase-specific constraints.
|
|
36
|
+
- Make platform lock-in or coupling explicit when it affects long-term architecture.
|
|
37
|
+
|
|
38
|
+
### Constraints
|
|
39
|
+
|
|
40
|
+
- Avoid mixing product policy and schema logic without clear ownership.
|
|
41
|
+
- Avoid overcomplicating RLS rules with no test strategy.
|
|
42
|
+
- Avoid assuming Supabase convenience removes the need for migration discipline.
|
|
43
|
+
- Avoid treating Supabase as generic Postgres when platform behavior clearly matters.
|
|
44
|
+
|
|
45
|
+
## Output Format
|
|
46
|
+
|
|
47
|
+
Provide implementation guidance, code examples, and configuration as appropriate to the task.
|
|
48
|
+
|
|
49
|
+
## References
|
|
50
|
+
|
|
51
|
+
Load on demand. Do not preload all reference files.
|
|
52
|
+
|
|
53
|
+
| File | Load when |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| `references/supabase-checklist.md` | You need deeper Supabase guidance for RLS, auth, storage, platform coupling, and managed rollout decisions. |
|
|
56
|
+
|
|
57
|
+
## Scripts
|
|
58
|
+
|
|
59
|
+
No helper scripts are required for this skill right now. Keep execution in `SKILL.md` and `references/` unless repeated automation becomes necessary.
|
|
60
|
+
|
|
61
|
+
## Examples
|
|
62
|
+
|
|
63
|
+
- "Help me with supabase best practices in this project"
|
|
64
|
+
- "Review my supabase implementation for issues"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Supabase Checklist
|
|
2
|
+
|
|
3
|
+
Load this when Supabase platform behavior is more important than generic Postgres guidance.
|
|
4
|
+
|
|
5
|
+
## Surface identification
|
|
6
|
+
|
|
7
|
+
- Confirm whether the task is about Postgres, RLS, Auth, Storage, Realtime, or Edge Functions.
|
|
8
|
+
- Separate plain database design from product-surface coupling.
|
|
9
|
+
|
|
10
|
+
## Access control
|
|
11
|
+
|
|
12
|
+
- Treat RLS and auth rules as core design work.
|
|
13
|
+
- Keep policies understandable and testable.
|
|
14
|
+
- Re-check who is authorized at the database boundary, not only in app code.
|
|
15
|
+
|
|
16
|
+
## Rollout
|
|
17
|
+
|
|
18
|
+
- Make migration, branching, and rollback posture explicit.
|
|
19
|
+
- Note platform coupling and lock-in where it affects long-term architecture.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
````markdown
|
|
2
|
+
---
|
|
3
|
+
inclusion: manual
|
|
4
|
+
name: swift-pro
|
|
5
|
+
description: "Use for modern Swift 6.1-era application and systems engineering with strong concurrency, protocol boundaries, package structure, and Apple-platform correctness."
|
|
6
|
+
license: MIT
|
|
7
|
+
metadata:
|
|
8
|
+
author: cubis-foundry
|
|
9
|
+
version: "2.0"
|
|
10
|
+
compatibility: Claude Code, Codex, GitHub Copilot
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Swift Pro
|
|
14
|
+
|
|
15
|
+
## Purpose
|
|
16
|
+
|
|
17
|
+
Use for modern Swift 6.1-era application and systems engineering with strong concurrency, protocol boundaries, package structure, and Apple-platform correctness.
|
|
18
|
+
|
|
19
|
+
## When to Use
|
|
20
|
+
|
|
21
|
+
- Building or refactoring Swift application, package, or platform code.
|
|
22
|
+
- Tightening Swift concurrency, Sendable safety, and package structure.
|
|
23
|
+
- Improving protocol boundaries, async code, and testability.
|
|
24
|
+
|
|
25
|
+
## Instructions
|
|
26
|
+
|
|
27
|
+
1. Confirm platform targets and package boundaries.
|
|
28
|
+
2. Keep concurrency annotations and ownership rules explicit.
|
|
29
|
+
3. Prefer protocol-driven seams where they improve testing or substitution.
|
|
30
|
+
4. Reduce shared mutable state and actor-boundary confusion.
|
|
31
|
+
5. Validate with focused tests and compiler-clean concurrency output.
|
|
32
|
+
|
|
33
|
+
### Baseline standards
|
|
34
|
+
|
|
35
|
+
- Enable strict concurrency checking (`-strict-concurrency=complete`). Fix all diagnostics.
|
|
36
|
+
- Use `Sendable` conformance on all types that cross isolation boundaries.
|
|
37
|
+
- Prefer `let` over `var`. Mutable state must be justified and contained.
|
|
38
|
+
- Use access control (`public`, `internal`, `private`, `fileprivate`) deliberately. Default to `private`.
|
|
39
|
+
- Keep Swift Package Manager as the primary dependency manager. Pin exact versions in `Package.resolved`.
|
|
40
|
+
|
|
41
|
+
### Concurrency (Swift 6)
|
|
42
|
+
|
|
43
|
+
- Use `async`/`await` for all asynchronous work. Eliminate completion handler callbacks in new code.
|
|
44
|
+
- Use `actor` for mutable state that needs thread-safe access. Keep actor methods focused and fast.
|
|
45
|
+
- Use `@MainActor` for UI-bound state and methods. Never call `MainActor.run` from UI code — annotate instead.
|
|
46
|
+
- Use `Task` and `TaskGroup` for structured concurrency. Cancel child tasks explicitly when the parent scope ends.
|
|
47
|
+
- Use `AsyncSequence` and `AsyncStream` for event-driven data flow.
|
|
48
|
+
- Avoid `nonisolated(unsafe)` unless you can prove thread safety with external synchronization.
|
|
49
|
+
|
|
50
|
+
### Sendable safety
|
|
51
|
+
|
|
52
|
+
- Value types (`struct`, `enum`) are `Sendable` when all stored properties are `Sendable`.
|
|
53
|
+
- Reference types must explicitly conform to `Sendable` — use `@unchecked Sendable` only with audited manual synchronization.
|
|
54
|
+
- Use `sending` parameter annotation (Swift 6) when transferring ownership of a value into another isolation domain.
|
|
55
|
+
- Closures crossing isolation boundaries must capture only `Sendable` values.
|
|
56
|
+
|
|
57
|
+
### Protocol-oriented design
|
|
58
|
+
|
|
59
|
+
- Use protocols to define capability contracts at module boundaries.
|
|
60
|
+
- Prefer protocol extensions for default implementations over base classes.
|
|
61
|
+
- Use `some Protocol` (opaque types) for return types to hide concrete implementations.
|
|
62
|
+
- Use `any Protocol` (existential types) only when dynamic dispatch is genuinely needed — it has runtime cost.
|
|
63
|
+
- Keep protocol requirements minimal. Clients should not be forced to implement methods they don't need.
|
|
64
|
+
|
|
65
|
+
### Error handling
|
|
66
|
+
|
|
67
|
+
- Use `throws` for recoverable errors. Use typed throws (`throws(MyError)`) in Swift 6 when the error domain is closed.
|
|
68
|
+
- Define specific error enums per module. Include context (e.g., the ID that wasn't found).
|
|
69
|
+
- Use `Result` when errors must be stored or passed as values.
|
|
70
|
+
- Use `do`/`catch` at the boundary layer (view model, controller). Don't catch errors deep in business logic unless recovery is possible.
|
|
71
|
+
|
|
72
|
+
### Testing
|
|
73
|
+
|
|
74
|
+
- Use Swift Testing framework (`@Test`, `#expect`) for new test targets. XCTest for existing targets.
|
|
75
|
+
- Use protocol-based dependency injection for testable architecture. Avoid singletons.
|
|
76
|
+
- Test async code with `await` — Swift Testing supports async test functions natively.
|
|
77
|
+
- Use `confirmation()` for testing actor-isolated behavior.
|
|
78
|
+
- Keep tests fast: mock network and persistence. No real I/O in unit tests.
|
|
79
|
+
|
|
80
|
+
### Package structure
|
|
81
|
+
|
|
82
|
+
- Organize code into focused packages/modules with clear public APIs.
|
|
83
|
+
- Use `Package.swift` targets to enforce module boundaries. Keep target dependency graphs acyclic.
|
|
84
|
+
- Export only the public API. Use `internal` for implementation details.
|
|
85
|
+
- Use `@testable import` only in test targets — never in production code.
|
|
86
|
+
|
|
87
|
+
### Constraints
|
|
88
|
+
|
|
89
|
+
- Avoid force unwrapping (`!`) without a preceding guard or nil check.
|
|
90
|
+
- Avoid massive view controllers or view models — split into focused components.
|
|
91
|
+
- Avoid `class` when `struct` would suffice — value types are cheaper, safer, and `Sendable` by default.
|
|
92
|
+
- Avoid `DispatchQueue` for new concurrent code — use Swift concurrency instead.
|
|
93
|
+
- Avoid retain cycles from strong `self` captures in closures — use `[weak self]` or `[unowned self]` appropriately.
|
|
94
|
+
- Avoid global mutable state (`static var`) — use actor isolation or dependency injection.
|
|
95
|
+
|
|
96
|
+
## Output Format
|
|
97
|
+
|
|
98
|
+
Provide implementation guidance, code examples, and configuration as appropriate to the task.
|
|
99
|
+
|
|
100
|
+
## References
|
|
101
|
+
|
|
102
|
+
| File | Load when |
|
|
103
|
+
| ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
|
|
104
|
+
| `references/swift-concurrency-and-protocols.md` | Swift concurrency migration, Sendable audit, actor design, protocol-oriented architecture, or structured concurrency patterns are needed. |
|
|
105
|
+
| `references/concurrency-patterns.md` | You need actor design, TaskGroup usage, AsyncSequence/AsyncStream, or MainActor annotation strategies. |
|
|
106
|
+
| `references/sendable-and-isolation.md` | You need Sendable conformance patterns, isolation boundary crossing, or @unchecked Sendable audit guidance. |
|
|
107
|
+
| `references/protocol-and-generics.md` | You need protocol-oriented design, opaque types, existentials, associated types, or generic constraint patterns. |
|
|
108
|
+
| `references/testing-and-packages.md` | You need Swift Testing framework patterns, dependency injection for tests, or Package.swift module organization. |
|
|
109
|
+
|
|
110
|
+
## Scripts
|
|
111
|
+
|
|
112
|
+
No helper scripts are required for this skill right now. Keep execution in `SKILL.md` and `references/` unless repeated automation becomes necessary.
|
|
113
|
+
|
|
114
|
+
## Examples
|
|
115
|
+
|
|
116
|
+
- "Help me with swift pro best practices in this project"
|
|
117
|
+
- "Review my swift pro implementation for issues"
|
|
118
|
+
````
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: swift-pro
|
|
3
|
+
description: "Use for modern Swift 6.1-era application and systems engineering with strong concurrency, protocol boundaries, package structure, and Apple-platform correctness."
|
|
4
|
+
license: MIT
|
|
5
|
+
metadata:
|
|
6
|
+
author: cubis-foundry
|
|
7
|
+
version: "2.0"
|
|
8
|
+
compatibility: Claude Code, Codex, GitHub Copilot
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Swift Pro
|
|
12
|
+
|
|
13
|
+
## Purpose
|
|
14
|
+
|
|
15
|
+
Use for modern Swift 6.1-era application and systems engineering with strong concurrency, protocol boundaries, package structure, and Apple-platform correctness.
|
|
16
|
+
|
|
17
|
+
## When to Use
|
|
18
|
+
|
|
19
|
+
- Building or refactoring Swift application, package, or platform code.
|
|
20
|
+
- Tightening Swift concurrency, Sendable safety, and package structure.
|
|
21
|
+
- Improving protocol boundaries, async code, and testability.
|
|
22
|
+
|
|
23
|
+
## Instructions
|
|
24
|
+
|
|
25
|
+
1. Confirm platform targets and package boundaries.
|
|
26
|
+
2. Keep concurrency annotations and ownership rules explicit.
|
|
27
|
+
3. Prefer protocol-driven seams where they improve testing or substitution.
|
|
28
|
+
4. Reduce shared mutable state and actor-boundary confusion.
|
|
29
|
+
5. Validate with focused tests and compiler-clean concurrency output.
|
|
30
|
+
|
|
31
|
+
### Baseline standards
|
|
32
|
+
|
|
33
|
+
- Enable strict concurrency checking (`-strict-concurrency=complete`). Fix all diagnostics.
|
|
34
|
+
- Use `Sendable` conformance on all types that cross isolation boundaries.
|
|
35
|
+
- Prefer `let` over `var`. Mutable state must be justified and contained.
|
|
36
|
+
- Use access control (`public`, `internal`, `private`, `fileprivate`) deliberately. Default to `private`.
|
|
37
|
+
- Keep Swift Package Manager as the primary dependency manager. Pin exact versions in `Package.resolved`.
|
|
38
|
+
|
|
39
|
+
### Concurrency (Swift 6)
|
|
40
|
+
|
|
41
|
+
- Use `async`/`await` for all asynchronous work. Eliminate completion handler callbacks in new code.
|
|
42
|
+
- Use `actor` for mutable state that needs thread-safe access. Keep actor methods focused and fast.
|
|
43
|
+
- Use `@MainActor` for UI-bound state and methods. Never call `MainActor.run` from UI code — annotate instead.
|
|
44
|
+
- Use `Task` and `TaskGroup` for structured concurrency. Cancel child tasks explicitly when the parent scope ends.
|
|
45
|
+
- Use `AsyncSequence` and `AsyncStream` for event-driven data flow.
|
|
46
|
+
- Avoid `nonisolated(unsafe)` unless you can prove thread safety with external synchronization.
|
|
47
|
+
|
|
48
|
+
### Sendable safety
|
|
49
|
+
|
|
50
|
+
- Value types (`struct`, `enum`) are `Sendable` when all stored properties are `Sendable`.
|
|
51
|
+
- Reference types must explicitly conform to `Sendable` — use `@unchecked Sendable` only with audited manual synchronization.
|
|
52
|
+
- Use `sending` parameter annotation (Swift 6) when transferring ownership of a value into another isolation domain.
|
|
53
|
+
- Closures crossing isolation boundaries must capture only `Sendable` values.
|
|
54
|
+
|
|
55
|
+
### Protocol-oriented design
|
|
56
|
+
|
|
57
|
+
- Use protocols to define capability contracts at module boundaries.
|
|
58
|
+
- Prefer protocol extensions for default implementations over base classes.
|
|
59
|
+
- Use `some Protocol` (opaque types) for return types to hide concrete implementations.
|
|
60
|
+
- Use `any Protocol` (existential types) only when dynamic dispatch is genuinely needed — it has runtime cost.
|
|
61
|
+
- Keep protocol requirements minimal. Clients should not be forced to implement methods they don't need.
|
|
62
|
+
|
|
63
|
+
### Error handling
|
|
64
|
+
|
|
65
|
+
- Use `throws` for recoverable errors. Use typed throws (`throws(MyError)`) in Swift 6 when the error domain is closed.
|
|
66
|
+
- Define specific error enums per module. Include context (e.g., the ID that wasn't found).
|
|
67
|
+
- Use `Result` when errors must be stored or passed as values.
|
|
68
|
+
- Use `do`/`catch` at the boundary layer (view model, controller). Don't catch errors deep in business logic unless recovery is possible.
|
|
69
|
+
|
|
70
|
+
### Testing
|
|
71
|
+
|
|
72
|
+
- Use Swift Testing framework (`@Test`, `#expect`) for new test targets. XCTest for existing targets.
|
|
73
|
+
- Use protocol-based dependency injection for testable architecture. Avoid singletons.
|
|
74
|
+
- Test async code with `await` — Swift Testing supports async test functions natively.
|
|
75
|
+
- Use `confirmation()` for testing actor-isolated behavior.
|
|
76
|
+
- Keep tests fast: mock network and persistence. No real I/O in unit tests.
|
|
77
|
+
|
|
78
|
+
### Package structure
|
|
79
|
+
|
|
80
|
+
- Organize code into focused packages/modules with clear public APIs.
|
|
81
|
+
- Use `Package.swift` targets to enforce module boundaries. Keep target dependency graphs acyclic.
|
|
82
|
+
- Export only the public API. Use `internal` for implementation details.
|
|
83
|
+
- Use `@testable import` only in test targets — never in production code.
|
|
84
|
+
|
|
85
|
+
### Constraints
|
|
86
|
+
|
|
87
|
+
- Avoid force unwrapping (`!`) without a preceding guard or nil check.
|
|
88
|
+
- Avoid massive view controllers or view models — split into focused components.
|
|
89
|
+
- Avoid `class` when `struct` would suffice — value types are cheaper, safer, and `Sendable` by default.
|
|
90
|
+
- Avoid `DispatchQueue` for new concurrent code — use Swift concurrency instead.
|
|
91
|
+
- Avoid retain cycles from strong `self` captures in closures — use `[weak self]` or `[unowned self]` appropriately.
|
|
92
|
+
- Avoid global mutable state (`static var`) — use actor isolation or dependency injection.
|
|
93
|
+
|
|
94
|
+
## Output Format
|
|
95
|
+
|
|
96
|
+
Provide implementation guidance, code examples, and configuration as appropriate to the task.
|
|
97
|
+
|
|
98
|
+
## References
|
|
99
|
+
|
|
100
|
+
| File | Load when |
|
|
101
|
+
| ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
|
|
102
|
+
| `references/swift-concurrency-and-protocols.md` | Swift concurrency migration, Sendable audit, actor design, protocol-oriented architecture, or structured concurrency patterns are needed. |
|
|
103
|
+
| `references/concurrency-patterns.md` | You need actor design, TaskGroup usage, AsyncSequence/AsyncStream, or MainActor annotation strategies. |
|
|
104
|
+
| `references/sendable-and-isolation.md` | You need Sendable conformance patterns, isolation boundary crossing, or @unchecked Sendable audit guidance. |
|
|
105
|
+
| `references/protocol-and-generics.md` | You need protocol-oriented design, opaque types, existentials, associated types, or generic constraint patterns. |
|
|
106
|
+
| `references/testing-and-packages.md` | You need Swift Testing framework patterns, dependency injection for tests, or Package.swift module organization. |
|
|
107
|
+
|
|
108
|
+
## Scripts
|
|
109
|
+
|
|
110
|
+
No helper scripts are required for this skill right now. Keep execution in `SKILL.md` and `references/` unless repeated automation becomes necessary.
|
|
111
|
+
|
|
112
|
+
## Examples
|
|
113
|
+
|
|
114
|
+
- "Help me with swift pro best practices in this project"
|
|
115
|
+
- "Review my swift pro implementation for issues"
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# Concurrency Patterns
|
|
2
|
+
|
|
3
|
+
## Actor design
|
|
4
|
+
|
|
5
|
+
### Choosing between actor types
|
|
6
|
+
|
|
7
|
+
| Pattern | Use when |
|
|
8
|
+
| --------------------- | ---------------------------------------------------------------------- |
|
|
9
|
+
| `actor` | Mutable state needs thread-safe access from multiple callers. |
|
|
10
|
+
| `@MainActor` | State or methods are bound to the UI thread. |
|
|
11
|
+
| Custom `@globalActor` | A subsystem needs serial execution (database, file I/O). |
|
|
12
|
+
| No actor | The type is immutable or only accessed from a single isolation domain. |
|
|
13
|
+
|
|
14
|
+
### Actor reentrancy
|
|
15
|
+
|
|
16
|
+
```swift
|
|
17
|
+
actor ImageCache {
|
|
18
|
+
private var cache: [URL: Image] = [:]
|
|
19
|
+
private var inFlight: [URL: Task<Image, Error>] = [:]
|
|
20
|
+
|
|
21
|
+
func image(for url: URL) async throws -> Image {
|
|
22
|
+
if let cached = cache[url] { return cached }
|
|
23
|
+
|
|
24
|
+
// Coalesce concurrent requests for the same URL
|
|
25
|
+
if let existing = inFlight[url] {
|
|
26
|
+
return try await existing.value
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let task = Task {
|
|
30
|
+
try await downloadImage(url)
|
|
31
|
+
}
|
|
32
|
+
inFlight[url] = task
|
|
33
|
+
|
|
34
|
+
let image = try await task.value // suspension point — state may change
|
|
35
|
+
cache[url] = image
|
|
36
|
+
inFlight[url] = nil
|
|
37
|
+
return image
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- Actor methods can suspend and resume. State may change between suspension points.
|
|
43
|
+
- Guard against reentrancy by checking state again after `await` calls.
|
|
44
|
+
- Use `inFlight` dictionaries to coalesce duplicate concurrent requests.
|
|
45
|
+
|
|
46
|
+
## TaskGroup patterns
|
|
47
|
+
|
|
48
|
+
### Bounded concurrency with TaskGroup
|
|
49
|
+
|
|
50
|
+
```swift
|
|
51
|
+
func processAll(_ items: [Item], concurrency: Int = 10) async throws {
|
|
52
|
+
try await withThrowingTaskGroup(of: Void.self) { group in
|
|
53
|
+
var iterator = items.makeIterator()
|
|
54
|
+
|
|
55
|
+
// Seed the group with initial concurrent tasks
|
|
56
|
+
for _ in 0..<min(concurrency, items.count) {
|
|
57
|
+
if let item = iterator.next() {
|
|
58
|
+
group.addTask { try await process(item) }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// As each task completes, add the next one
|
|
63
|
+
for try await _ in group {
|
|
64
|
+
if let item = iterator.next() {
|
|
65
|
+
group.addTask { try await process(item) }
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Collecting ordered results
|
|
73
|
+
|
|
74
|
+
```swift
|
|
75
|
+
func fetchAll(ids: [Int]) async throws -> [User] {
|
|
76
|
+
try await withThrowingTaskGroup(of: (Int, User).self) { group in
|
|
77
|
+
for (index, id) in ids.enumerated() {
|
|
78
|
+
group.addTask { (index, try await fetchUser(id)) }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var results = Array<User?>(repeating: nil, count: ids.count)
|
|
82
|
+
for try await (index, user) in group {
|
|
83
|
+
results[index] = user
|
|
84
|
+
}
|
|
85
|
+
return results.compactMap { $0 }
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
- TaskGroup results arrive in completion order, not submission order.
|
|
91
|
+
- Use index-based collection when order matters.
|
|
92
|
+
|
|
93
|
+
## AsyncSequence and AsyncStream
|
|
94
|
+
|
|
95
|
+
### Building custom AsyncSequence
|
|
96
|
+
|
|
97
|
+
```swift
|
|
98
|
+
struct TickSequence: AsyncSequence {
|
|
99
|
+
typealias Element = Date
|
|
100
|
+
let interval: TimeInterval
|
|
101
|
+
|
|
102
|
+
struct AsyncIterator: AsyncIteratorProtocol {
|
|
103
|
+
let interval: TimeInterval
|
|
104
|
+
mutating func next() async -> Date? {
|
|
105
|
+
try? await Task.sleep(for: .seconds(interval))
|
|
106
|
+
return Task.isCancelled ? nil : Date()
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
func makeAsyncIterator() -> AsyncIterator {
|
|
111
|
+
AsyncIterator(interval: interval)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
for await tick in TickSequence(interval: 1.0) {
|
|
116
|
+
print("Tick: \(tick)")
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### AsyncStream with backpressure
|
|
121
|
+
|
|
122
|
+
```swift
|
|
123
|
+
let (stream, continuation) = AsyncStream.makeStream(of: Event.self, bufferingPolicy: .bufferingNewest(10))
|
|
124
|
+
|
|
125
|
+
// Producer
|
|
126
|
+
continuation.yield(.userAction("tap"))
|
|
127
|
+
continuation.finish()
|
|
128
|
+
|
|
129
|
+
// Consumer
|
|
130
|
+
for await event in stream {
|
|
131
|
+
await handle(event)
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
- Use `.bufferingNewest(n)` to drop old events under backpressure.
|
|
136
|
+
- Use `.bufferingOldest(n)` to drop new events (queue semantics).
|
|
137
|
+
- Always call `continuation.finish()` when the source completes.
|
|
138
|
+
- Set `continuation.onTermination` to clean up resources when the consumer stops.
|
|
139
|
+
|
|
140
|
+
## MainActor patterns
|
|
141
|
+
|
|
142
|
+
### Annotation strategies
|
|
143
|
+
|
|
144
|
+
```swift
|
|
145
|
+
// Annotate the entire class for UI-bound types
|
|
146
|
+
@MainActor
|
|
147
|
+
class ViewModel: ObservableObject {
|
|
148
|
+
@Published var items: [Item] = []
|
|
149
|
+
|
|
150
|
+
func load() async {
|
|
151
|
+
let data = await fetchFromNetwork() // suspends, runs off-main
|
|
152
|
+
items = data // back on MainActor
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Opt out for non-UI work
|
|
156
|
+
nonisolated func computeHash() -> String {
|
|
157
|
+
// runs on caller's isolation domain
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
- Prefer class-level `@MainActor` for view models and UI controllers.
|
|
163
|
+
- Use method-level `@MainActor` for specific entry points in otherwise non-UI types.
|
|
164
|
+
- Use `nonisolated` to opt specific methods out of the class-level annotation.
|
|
165
|
+
- Never use `DispatchQueue.main.async` in new code — use `@MainActor` instead.
|