@cregis-dev/cckit 0.6.6 → 0.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/bin/cckit.js +3 -3
- package/package.json +53 -53
- package/registry.json +145 -145
- package/src/cli.js +79 -79
- package/src/commands/init.js +174 -174
- package/src/commands/status.js +125 -125
- package/src/commands/update.js +192 -192
- package/src/core/config.js +82 -75
- package/src/core/orchestrator.js +79 -79
- package/src/core/registry.js +60 -60
- package/src/steps/add-plugin.js +148 -116
- package/src/steps/configure-user.js +181 -181
- package/src/steps/enable-plugins.js +97 -97
- package/src/steps/install-bmad.js +85 -85
- package/src/steps/install-mcp.js +70 -70
- package/src/steps/install-rules.js +69 -69
- package/src/steps/install-skills.js +56 -56
- package/src/utils/compare-versions.js +106 -106
- package/src/utils/fs.js +33 -33
- package/src/utils/logger.js +16 -16
- package/src/utils/manifest.js +101 -101
- package/src/utils/prompt.js +41 -41
- package/templates/mcp/claude-code/.mcp.json +40 -40
- package/templates/rules/README.md +103 -103
- package/templates/rules/common/agents.md +49 -49
- package/templates/rules/common/coding-style.md +48 -48
- package/templates/rules/common/development-workflow.md +37 -37
- package/templates/rules/common/git-workflow.md +24 -24
- package/templates/rules/common/hooks.md +30 -30
- package/templates/rules/common/patterns.md +31 -31
- package/templates/rules/common/performance.md +55 -55
- package/templates/rules/common/security.md +29 -29
- package/templates/rules/common/testing.md +29 -29
- package/templates/rules/golang/coding-style.md +32 -32
- package/templates/rules/golang/hooks.md +17 -17
- package/templates/rules/golang/patterns.md +45 -45
- package/templates/rules/golang/security.md +34 -34
- package/templates/rules/golang/testing.md +31 -31
- package/templates/rules/python/coding-style.md +42 -42
- package/templates/rules/python/hooks.md +19 -19
- package/templates/rules/python/patterns.md +39 -39
- package/templates/rules/python/security.md +30 -30
- package/templates/rules/python/testing.md +38 -38
- package/templates/rules/swift/coding-style.md +47 -47
- package/templates/rules/swift/hooks.md +20 -20
- package/templates/rules/swift/patterns.md +66 -66
- package/templates/rules/swift/security.md +33 -33
- package/templates/rules/swift/testing.md +45 -45
- package/templates/rules/typescript/coding-style.md +65 -65
- package/templates/rules/typescript/hooks.md +22 -22
- package/templates/rules/typescript/patterns.md +52 -52
- package/templates/rules/typescript/security.md +28 -28
- package/templates/rules/typescript/testing.md +18 -18
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
---
|
|
2
|
-
paths:
|
|
3
|
-
- "**/*.py"
|
|
4
|
-
- "**/*.pyi"
|
|
5
|
-
---
|
|
6
|
-
# Python Coding Style
|
|
7
|
-
|
|
8
|
-
> This file extends [common/coding-style.md](../common/coding-style.md) with Python specific content.
|
|
9
|
-
|
|
10
|
-
## Standards
|
|
11
|
-
|
|
12
|
-
- Follow **PEP 8** conventions
|
|
13
|
-
- Use **type annotations** on all function signatures
|
|
14
|
-
|
|
15
|
-
## Immutability
|
|
16
|
-
|
|
17
|
-
Prefer immutable data structures:
|
|
18
|
-
|
|
19
|
-
```python
|
|
20
|
-
from dataclasses import dataclass
|
|
21
|
-
|
|
22
|
-
@dataclass(frozen=True)
|
|
23
|
-
class User:
|
|
24
|
-
name: str
|
|
25
|
-
email: str
|
|
26
|
-
|
|
27
|
-
from typing import NamedTuple
|
|
28
|
-
|
|
29
|
-
class Point(NamedTuple):
|
|
30
|
-
x: float
|
|
31
|
-
y: float
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Formatting
|
|
35
|
-
|
|
36
|
-
- **black** for code formatting
|
|
37
|
-
- **isort** for import sorting
|
|
38
|
-
- **ruff** for linting
|
|
39
|
-
|
|
40
|
-
## Reference
|
|
41
|
-
|
|
42
|
-
See skill: `python-patterns` for comprehensive Python idioms and patterns.
|
|
1
|
+
---
|
|
2
|
+
paths:
|
|
3
|
+
- "**/*.py"
|
|
4
|
+
- "**/*.pyi"
|
|
5
|
+
---
|
|
6
|
+
# Python Coding Style
|
|
7
|
+
|
|
8
|
+
> This file extends [common/coding-style.md](../common/coding-style.md) with Python specific content.
|
|
9
|
+
|
|
10
|
+
## Standards
|
|
11
|
+
|
|
12
|
+
- Follow **PEP 8** conventions
|
|
13
|
+
- Use **type annotations** on all function signatures
|
|
14
|
+
|
|
15
|
+
## Immutability
|
|
16
|
+
|
|
17
|
+
Prefer immutable data structures:
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from dataclasses import dataclass
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True)
|
|
23
|
+
class User:
|
|
24
|
+
name: str
|
|
25
|
+
email: str
|
|
26
|
+
|
|
27
|
+
from typing import NamedTuple
|
|
28
|
+
|
|
29
|
+
class Point(NamedTuple):
|
|
30
|
+
x: float
|
|
31
|
+
y: float
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Formatting
|
|
35
|
+
|
|
36
|
+
- **black** for code formatting
|
|
37
|
+
- **isort** for import sorting
|
|
38
|
+
- **ruff** for linting
|
|
39
|
+
|
|
40
|
+
## Reference
|
|
41
|
+
|
|
42
|
+
See skill: `python-patterns` for comprehensive Python idioms and patterns.
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
---
|
|
2
|
-
paths:
|
|
3
|
-
- "**/*.py"
|
|
4
|
-
- "**/*.pyi"
|
|
5
|
-
---
|
|
6
|
-
# Python Hooks
|
|
7
|
-
|
|
8
|
-
> This file extends [common/hooks.md](../common/hooks.md) with Python specific content.
|
|
9
|
-
|
|
10
|
-
## PostToolUse Hooks
|
|
11
|
-
|
|
12
|
-
Configure in `~/.claude/settings.json`:
|
|
13
|
-
|
|
14
|
-
- **black/ruff**: Auto-format `.py` files after edit
|
|
15
|
-
- **mypy/pyright**: Run type checking after editing `.py` files
|
|
16
|
-
|
|
17
|
-
## Warnings
|
|
18
|
-
|
|
19
|
-
- Warn about `print()` statements in edited files (use `logging` module instead)
|
|
1
|
+
---
|
|
2
|
+
paths:
|
|
3
|
+
- "**/*.py"
|
|
4
|
+
- "**/*.pyi"
|
|
5
|
+
---
|
|
6
|
+
# Python Hooks
|
|
7
|
+
|
|
8
|
+
> This file extends [common/hooks.md](../common/hooks.md) with Python specific content.
|
|
9
|
+
|
|
10
|
+
## PostToolUse Hooks
|
|
11
|
+
|
|
12
|
+
Configure in `~/.claude/settings.json`:
|
|
13
|
+
|
|
14
|
+
- **black/ruff**: Auto-format `.py` files after edit
|
|
15
|
+
- **mypy/pyright**: Run type checking after editing `.py` files
|
|
16
|
+
|
|
17
|
+
## Warnings
|
|
18
|
+
|
|
19
|
+
- Warn about `print()` statements in edited files (use `logging` module instead)
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
---
|
|
2
|
-
paths:
|
|
3
|
-
- "**/*.py"
|
|
4
|
-
- "**/*.pyi"
|
|
5
|
-
---
|
|
6
|
-
# Python Patterns
|
|
7
|
-
|
|
8
|
-
> This file extends [common/patterns.md](../common/patterns.md) with Python specific content.
|
|
9
|
-
|
|
10
|
-
## Protocol (Duck Typing)
|
|
11
|
-
|
|
12
|
-
```python
|
|
13
|
-
from typing import Protocol
|
|
14
|
-
|
|
15
|
-
class Repository(Protocol):
|
|
16
|
-
def find_by_id(self, id: str) -> dict | None: ...
|
|
17
|
-
def save(self, entity: dict) -> dict: ...
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Dataclasses as DTOs
|
|
21
|
-
|
|
22
|
-
```python
|
|
23
|
-
from dataclasses import dataclass
|
|
24
|
-
|
|
25
|
-
@dataclass
|
|
26
|
-
class CreateUserRequest:
|
|
27
|
-
name: str
|
|
28
|
-
email: str
|
|
29
|
-
age: int | None = None
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Context Managers & Generators
|
|
33
|
-
|
|
34
|
-
- Use context managers (`with` statement) for resource management
|
|
35
|
-
- Use generators for lazy evaluation and memory-efficient iteration
|
|
36
|
-
|
|
37
|
-
## Reference
|
|
38
|
-
|
|
39
|
-
See skill: `python-patterns` for comprehensive patterns including decorators, concurrency, and package organization.
|
|
1
|
+
---
|
|
2
|
+
paths:
|
|
3
|
+
- "**/*.py"
|
|
4
|
+
- "**/*.pyi"
|
|
5
|
+
---
|
|
6
|
+
# Python Patterns
|
|
7
|
+
|
|
8
|
+
> This file extends [common/patterns.md](../common/patterns.md) with Python specific content.
|
|
9
|
+
|
|
10
|
+
## Protocol (Duck Typing)
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
from typing import Protocol
|
|
14
|
+
|
|
15
|
+
class Repository(Protocol):
|
|
16
|
+
def find_by_id(self, id: str) -> dict | None: ...
|
|
17
|
+
def save(self, entity: dict) -> dict: ...
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Dataclasses as DTOs
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from dataclasses import dataclass
|
|
24
|
+
|
|
25
|
+
@dataclass
|
|
26
|
+
class CreateUserRequest:
|
|
27
|
+
name: str
|
|
28
|
+
email: str
|
|
29
|
+
age: int | None = None
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Context Managers & Generators
|
|
33
|
+
|
|
34
|
+
- Use context managers (`with` statement) for resource management
|
|
35
|
+
- Use generators for lazy evaluation and memory-efficient iteration
|
|
36
|
+
|
|
37
|
+
## Reference
|
|
38
|
+
|
|
39
|
+
See skill: `python-patterns` for comprehensive patterns including decorators, concurrency, and package organization.
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
---
|
|
2
|
-
paths:
|
|
3
|
-
- "**/*.py"
|
|
4
|
-
- "**/*.pyi"
|
|
5
|
-
---
|
|
6
|
-
# Python Security
|
|
7
|
-
|
|
8
|
-
> This file extends [common/security.md](../common/security.md) with Python specific content.
|
|
9
|
-
|
|
10
|
-
## Secret Management
|
|
11
|
-
|
|
12
|
-
```python
|
|
13
|
-
import os
|
|
14
|
-
from dotenv import load_dotenv
|
|
15
|
-
|
|
16
|
-
load_dotenv()
|
|
17
|
-
|
|
18
|
-
api_key = os.environ["OPENAI_API_KEY"] # Raises KeyError if missing
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Security Scanning
|
|
22
|
-
|
|
23
|
-
- Use **bandit** for static security analysis:
|
|
24
|
-
```bash
|
|
25
|
-
bandit -r src/
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Reference
|
|
29
|
-
|
|
30
|
-
See skill: `django-security` for Django-specific security guidelines (if applicable).
|
|
1
|
+
---
|
|
2
|
+
paths:
|
|
3
|
+
- "**/*.py"
|
|
4
|
+
- "**/*.pyi"
|
|
5
|
+
---
|
|
6
|
+
# Python Security
|
|
7
|
+
|
|
8
|
+
> This file extends [common/security.md](../common/security.md) with Python specific content.
|
|
9
|
+
|
|
10
|
+
## Secret Management
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
import os
|
|
14
|
+
from dotenv import load_dotenv
|
|
15
|
+
|
|
16
|
+
load_dotenv()
|
|
17
|
+
|
|
18
|
+
api_key = os.environ["OPENAI_API_KEY"] # Raises KeyError if missing
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Security Scanning
|
|
22
|
+
|
|
23
|
+
- Use **bandit** for static security analysis:
|
|
24
|
+
```bash
|
|
25
|
+
bandit -r src/
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Reference
|
|
29
|
+
|
|
30
|
+
See skill: `django-security` for Django-specific security guidelines (if applicable).
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
---
|
|
2
|
-
paths:
|
|
3
|
-
- "**/*.py"
|
|
4
|
-
- "**/*.pyi"
|
|
5
|
-
---
|
|
6
|
-
# Python Testing
|
|
7
|
-
|
|
8
|
-
> This file extends [common/testing.md](../common/testing.md) with Python specific content.
|
|
9
|
-
|
|
10
|
-
## Framework
|
|
11
|
-
|
|
12
|
-
Use **pytest** as the testing framework.
|
|
13
|
-
|
|
14
|
-
## Coverage
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
pytest --cov=src --cov-report=term-missing
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Test Organization
|
|
21
|
-
|
|
22
|
-
Use `pytest.mark` for test categorization:
|
|
23
|
-
|
|
24
|
-
```python
|
|
25
|
-
import pytest
|
|
26
|
-
|
|
27
|
-
@pytest.mark.unit
|
|
28
|
-
def test_calculate_total():
|
|
29
|
-
...
|
|
30
|
-
|
|
31
|
-
@pytest.mark.integration
|
|
32
|
-
def test_database_connection():
|
|
33
|
-
...
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Reference
|
|
37
|
-
|
|
38
|
-
See skill: `python-testing` for detailed pytest patterns and fixtures.
|
|
1
|
+
---
|
|
2
|
+
paths:
|
|
3
|
+
- "**/*.py"
|
|
4
|
+
- "**/*.pyi"
|
|
5
|
+
---
|
|
6
|
+
# Python Testing
|
|
7
|
+
|
|
8
|
+
> This file extends [common/testing.md](../common/testing.md) with Python specific content.
|
|
9
|
+
|
|
10
|
+
## Framework
|
|
11
|
+
|
|
12
|
+
Use **pytest** as the testing framework.
|
|
13
|
+
|
|
14
|
+
## Coverage
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pytest --cov=src --cov-report=term-missing
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Test Organization
|
|
21
|
+
|
|
22
|
+
Use `pytest.mark` for test categorization:
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
import pytest
|
|
26
|
+
|
|
27
|
+
@pytest.mark.unit
|
|
28
|
+
def test_calculate_total():
|
|
29
|
+
...
|
|
30
|
+
|
|
31
|
+
@pytest.mark.integration
|
|
32
|
+
def test_database_connection():
|
|
33
|
+
...
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Reference
|
|
37
|
+
|
|
38
|
+
See skill: `python-testing` for detailed pytest patterns and fixtures.
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
---
|
|
2
|
-
paths:
|
|
3
|
-
- "**/*.swift"
|
|
4
|
-
- "**/Package.swift"
|
|
5
|
-
---
|
|
6
|
-
# Swift Coding Style
|
|
7
|
-
|
|
8
|
-
> This file extends [common/coding-style.md](../common/coding-style.md) with Swift specific content.
|
|
9
|
-
|
|
10
|
-
## Formatting
|
|
11
|
-
|
|
12
|
-
- **SwiftFormat** for auto-formatting, **SwiftLint** for style enforcement
|
|
13
|
-
- `swift-format` is bundled with Xcode 16+ as an alternative
|
|
14
|
-
|
|
15
|
-
## Immutability
|
|
16
|
-
|
|
17
|
-
- Prefer `let` over `var` — define everything as `let` and only change to `var` if the compiler requires it
|
|
18
|
-
- Use `struct` with value semantics by default; use `class` only when identity or reference semantics are needed
|
|
19
|
-
|
|
20
|
-
## Naming
|
|
21
|
-
|
|
22
|
-
Follow [Apple API Design Guidelines](https://www.swift.org/documentation/api-design-guidelines/):
|
|
23
|
-
|
|
24
|
-
- Clarity at the point of use — omit needless words
|
|
25
|
-
- Name methods and properties for their roles, not their types
|
|
26
|
-
- Use `static let` for constants over global constants
|
|
27
|
-
|
|
28
|
-
## Error Handling
|
|
29
|
-
|
|
30
|
-
Use typed throws (Swift 6+) and pattern matching:
|
|
31
|
-
|
|
32
|
-
```swift
|
|
33
|
-
func load(id: String) throws(LoadError) -> Item {
|
|
34
|
-
guard let data = try? read(from: path) else {
|
|
35
|
-
throw .fileNotFound(id)
|
|
36
|
-
}
|
|
37
|
-
return try decode(data)
|
|
38
|
-
}
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## Concurrency
|
|
42
|
-
|
|
43
|
-
Enable Swift 6 strict concurrency checking. Prefer:
|
|
44
|
-
|
|
45
|
-
- `Sendable` value types for data crossing isolation boundaries
|
|
46
|
-
- Actors for shared mutable state
|
|
47
|
-
- Structured concurrency (`async let`, `TaskGroup`) over unstructured `Task {}`
|
|
1
|
+
---
|
|
2
|
+
paths:
|
|
3
|
+
- "**/*.swift"
|
|
4
|
+
- "**/Package.swift"
|
|
5
|
+
---
|
|
6
|
+
# Swift Coding Style
|
|
7
|
+
|
|
8
|
+
> This file extends [common/coding-style.md](../common/coding-style.md) with Swift specific content.
|
|
9
|
+
|
|
10
|
+
## Formatting
|
|
11
|
+
|
|
12
|
+
- **SwiftFormat** for auto-formatting, **SwiftLint** for style enforcement
|
|
13
|
+
- `swift-format` is bundled with Xcode 16+ as an alternative
|
|
14
|
+
|
|
15
|
+
## Immutability
|
|
16
|
+
|
|
17
|
+
- Prefer `let` over `var` — define everything as `let` and only change to `var` if the compiler requires it
|
|
18
|
+
- Use `struct` with value semantics by default; use `class` only when identity or reference semantics are needed
|
|
19
|
+
|
|
20
|
+
## Naming
|
|
21
|
+
|
|
22
|
+
Follow [Apple API Design Guidelines](https://www.swift.org/documentation/api-design-guidelines/):
|
|
23
|
+
|
|
24
|
+
- Clarity at the point of use — omit needless words
|
|
25
|
+
- Name methods and properties for their roles, not their types
|
|
26
|
+
- Use `static let` for constants over global constants
|
|
27
|
+
|
|
28
|
+
## Error Handling
|
|
29
|
+
|
|
30
|
+
Use typed throws (Swift 6+) and pattern matching:
|
|
31
|
+
|
|
32
|
+
```swift
|
|
33
|
+
func load(id: String) throws(LoadError) -> Item {
|
|
34
|
+
guard let data = try? read(from: path) else {
|
|
35
|
+
throw .fileNotFound(id)
|
|
36
|
+
}
|
|
37
|
+
return try decode(data)
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Concurrency
|
|
42
|
+
|
|
43
|
+
Enable Swift 6 strict concurrency checking. Prefer:
|
|
44
|
+
|
|
45
|
+
- `Sendable` value types for data crossing isolation boundaries
|
|
46
|
+
- Actors for shared mutable state
|
|
47
|
+
- Structured concurrency (`async let`, `TaskGroup`) over unstructured `Task {}`
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
---
|
|
2
|
-
paths:
|
|
3
|
-
- "**/*.swift"
|
|
4
|
-
- "**/Package.swift"
|
|
5
|
-
---
|
|
6
|
-
# Swift Hooks
|
|
7
|
-
|
|
8
|
-
> This file extends [common/hooks.md](../common/hooks.md) with Swift specific content.
|
|
9
|
-
|
|
10
|
-
## PostToolUse Hooks
|
|
11
|
-
|
|
12
|
-
Configure in `~/.claude/settings.json`:
|
|
13
|
-
|
|
14
|
-
- **SwiftFormat**: Auto-format `.swift` files after edit
|
|
15
|
-
- **SwiftLint**: Run lint checks after editing `.swift` files
|
|
16
|
-
- **swift build**: Type-check modified packages after edit
|
|
17
|
-
|
|
18
|
-
## Warning
|
|
19
|
-
|
|
20
|
-
Flag `print()` statements — use `os.Logger` or structured logging instead for production code.
|
|
1
|
+
---
|
|
2
|
+
paths:
|
|
3
|
+
- "**/*.swift"
|
|
4
|
+
- "**/Package.swift"
|
|
5
|
+
---
|
|
6
|
+
# Swift Hooks
|
|
7
|
+
|
|
8
|
+
> This file extends [common/hooks.md](../common/hooks.md) with Swift specific content.
|
|
9
|
+
|
|
10
|
+
## PostToolUse Hooks
|
|
11
|
+
|
|
12
|
+
Configure in `~/.claude/settings.json`:
|
|
13
|
+
|
|
14
|
+
- **SwiftFormat**: Auto-format `.swift` files after edit
|
|
15
|
+
- **SwiftLint**: Run lint checks after editing `.swift` files
|
|
16
|
+
- **swift build**: Type-check modified packages after edit
|
|
17
|
+
|
|
18
|
+
## Warning
|
|
19
|
+
|
|
20
|
+
Flag `print()` statements — use `os.Logger` or structured logging instead for production code.
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
---
|
|
2
|
-
paths:
|
|
3
|
-
- "**/*.swift"
|
|
4
|
-
- "**/Package.swift"
|
|
5
|
-
---
|
|
6
|
-
# Swift Patterns
|
|
7
|
-
|
|
8
|
-
> This file extends [common/patterns.md](../common/patterns.md) with Swift specific content.
|
|
9
|
-
|
|
10
|
-
## Protocol-Oriented Design
|
|
11
|
-
|
|
12
|
-
Define small, focused protocols. Use protocol extensions for shared defaults:
|
|
13
|
-
|
|
14
|
-
```swift
|
|
15
|
-
protocol Repository: Sendable {
|
|
16
|
-
associatedtype Item: Identifiable & Sendable
|
|
17
|
-
func find(by id: Item.ID) async throws -> Item?
|
|
18
|
-
func save(_ item: Item) async throws
|
|
19
|
-
}
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Value Types
|
|
23
|
-
|
|
24
|
-
- Use structs for data transfer objects and models
|
|
25
|
-
- Use enums with associated values to model distinct states:
|
|
26
|
-
|
|
27
|
-
```swift
|
|
28
|
-
enum LoadState<T: Sendable>: Sendable {
|
|
29
|
-
case idle
|
|
30
|
-
case loading
|
|
31
|
-
case loaded(T)
|
|
32
|
-
case failed(Error)
|
|
33
|
-
}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Actor Pattern
|
|
37
|
-
|
|
38
|
-
Use actors for shared mutable state instead of locks or dispatch queues:
|
|
39
|
-
|
|
40
|
-
```swift
|
|
41
|
-
actor Cache<Key: Hashable & Sendable, Value: Sendable> {
|
|
42
|
-
private var storage: [Key: Value] = [:]
|
|
43
|
-
|
|
44
|
-
func get(_ key: Key) -> Value? { storage[key] }
|
|
45
|
-
func set(_ key: Key, value: Value) { storage[key] = value }
|
|
46
|
-
}
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Dependency Injection
|
|
50
|
-
|
|
51
|
-
Inject protocols with default parameters — production uses defaults, tests inject mocks:
|
|
52
|
-
|
|
53
|
-
```swift
|
|
54
|
-
struct UserService {
|
|
55
|
-
private let repository: any UserRepository
|
|
56
|
-
|
|
57
|
-
init(repository: any UserRepository = DefaultUserRepository()) {
|
|
58
|
-
self.repository = repository
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## References
|
|
64
|
-
|
|
65
|
-
See skill: `swift-actor-persistence` for actor-based persistence patterns.
|
|
66
|
-
See skill: `swift-protocol-di-testing` for protocol-based DI and testing.
|
|
1
|
+
---
|
|
2
|
+
paths:
|
|
3
|
+
- "**/*.swift"
|
|
4
|
+
- "**/Package.swift"
|
|
5
|
+
---
|
|
6
|
+
# Swift Patterns
|
|
7
|
+
|
|
8
|
+
> This file extends [common/patterns.md](../common/patterns.md) with Swift specific content.
|
|
9
|
+
|
|
10
|
+
## Protocol-Oriented Design
|
|
11
|
+
|
|
12
|
+
Define small, focused protocols. Use protocol extensions for shared defaults:
|
|
13
|
+
|
|
14
|
+
```swift
|
|
15
|
+
protocol Repository: Sendable {
|
|
16
|
+
associatedtype Item: Identifiable & Sendable
|
|
17
|
+
func find(by id: Item.ID) async throws -> Item?
|
|
18
|
+
func save(_ item: Item) async throws
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Value Types
|
|
23
|
+
|
|
24
|
+
- Use structs for data transfer objects and models
|
|
25
|
+
- Use enums with associated values to model distinct states:
|
|
26
|
+
|
|
27
|
+
```swift
|
|
28
|
+
enum LoadState<T: Sendable>: Sendable {
|
|
29
|
+
case idle
|
|
30
|
+
case loading
|
|
31
|
+
case loaded(T)
|
|
32
|
+
case failed(Error)
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Actor Pattern
|
|
37
|
+
|
|
38
|
+
Use actors for shared mutable state instead of locks or dispatch queues:
|
|
39
|
+
|
|
40
|
+
```swift
|
|
41
|
+
actor Cache<Key: Hashable & Sendable, Value: Sendable> {
|
|
42
|
+
private var storage: [Key: Value] = [:]
|
|
43
|
+
|
|
44
|
+
func get(_ key: Key) -> Value? { storage[key] }
|
|
45
|
+
func set(_ key: Key, value: Value) { storage[key] = value }
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Dependency Injection
|
|
50
|
+
|
|
51
|
+
Inject protocols with default parameters — production uses defaults, tests inject mocks:
|
|
52
|
+
|
|
53
|
+
```swift
|
|
54
|
+
struct UserService {
|
|
55
|
+
private let repository: any UserRepository
|
|
56
|
+
|
|
57
|
+
init(repository: any UserRepository = DefaultUserRepository()) {
|
|
58
|
+
self.repository = repository
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## References
|
|
64
|
+
|
|
65
|
+
See skill: `swift-actor-persistence` for actor-based persistence patterns.
|
|
66
|
+
See skill: `swift-protocol-di-testing` for protocol-based DI and testing.
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
---
|
|
2
|
-
paths:
|
|
3
|
-
- "**/*.swift"
|
|
4
|
-
- "**/Package.swift"
|
|
5
|
-
---
|
|
6
|
-
# Swift Security
|
|
7
|
-
|
|
8
|
-
> This file extends [common/security.md](../common/security.md) with Swift specific content.
|
|
9
|
-
|
|
10
|
-
## Secret Management
|
|
11
|
-
|
|
12
|
-
- Use **Keychain Services** for sensitive data (tokens, passwords, keys) — never `UserDefaults`
|
|
13
|
-
- Use environment variables or `.xcconfig` files for build-time secrets
|
|
14
|
-
- Never hardcode secrets in source — decompilation tools extract them trivially
|
|
15
|
-
|
|
16
|
-
```swift
|
|
17
|
-
let apiKey = ProcessInfo.processInfo.environment["API_KEY"]
|
|
18
|
-
guard let apiKey, !apiKey.isEmpty else {
|
|
19
|
-
fatalError("API_KEY not configured")
|
|
20
|
-
}
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Transport Security
|
|
24
|
-
|
|
25
|
-
- App Transport Security (ATS) is enforced by default — do not disable it
|
|
26
|
-
- Use certificate pinning for critical endpoints
|
|
27
|
-
- Validate all server certificates
|
|
28
|
-
|
|
29
|
-
## Input Validation
|
|
30
|
-
|
|
31
|
-
- Sanitize all user input before display to prevent injection
|
|
32
|
-
- Use `URL(string:)` with validation rather than force-unwrapping
|
|
33
|
-
- Validate data from external sources (APIs, deep links, pasteboard) before processing
|
|
1
|
+
---
|
|
2
|
+
paths:
|
|
3
|
+
- "**/*.swift"
|
|
4
|
+
- "**/Package.swift"
|
|
5
|
+
---
|
|
6
|
+
# Swift Security
|
|
7
|
+
|
|
8
|
+
> This file extends [common/security.md](../common/security.md) with Swift specific content.
|
|
9
|
+
|
|
10
|
+
## Secret Management
|
|
11
|
+
|
|
12
|
+
- Use **Keychain Services** for sensitive data (tokens, passwords, keys) — never `UserDefaults`
|
|
13
|
+
- Use environment variables or `.xcconfig` files for build-time secrets
|
|
14
|
+
- Never hardcode secrets in source — decompilation tools extract them trivially
|
|
15
|
+
|
|
16
|
+
```swift
|
|
17
|
+
let apiKey = ProcessInfo.processInfo.environment["API_KEY"]
|
|
18
|
+
guard let apiKey, !apiKey.isEmpty else {
|
|
19
|
+
fatalError("API_KEY not configured")
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Transport Security
|
|
24
|
+
|
|
25
|
+
- App Transport Security (ATS) is enforced by default — do not disable it
|
|
26
|
+
- Use certificate pinning for critical endpoints
|
|
27
|
+
- Validate all server certificates
|
|
28
|
+
|
|
29
|
+
## Input Validation
|
|
30
|
+
|
|
31
|
+
- Sanitize all user input before display to prevent injection
|
|
32
|
+
- Use `URL(string:)` with validation rather than force-unwrapping
|
|
33
|
+
- Validate data from external sources (APIs, deep links, pasteboard) before processing
|