Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions .claude/docs/mistdemo/configkeykit-strategy.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
# ConfigKeyKit Extension Strategy

This document outlines the configuration architecture for MistDemo using the Swift Configuration package with ConfigKeyKit-style patterns.
This document outlines the configuration architecture for MistDemo, combining Swift Configuration with a lightweight ConfigKeyKit module.

## Overview
## Current Implementation

MistDemo extends Swift Configuration to support:
1. Hierarchical configuration keys
2. Command-specific configuration
3. Configuration profiles
4. Dynamic resolution with priority
5. Type-safe configuration access
MistDemo uses a two-module approach:
1. **ConfigKeyKit** - Lightweight module containing only reusable configuration key types (no dependencies)
2. **MistDemoConfiguration** - Swift Configuration wrapper in the MistDemo module (requires macOS 15.0+)

## Architecture Decisions

### Module Separation
- ConfigKeyKit remains dependency-free for maximum reusability
- MistDemo module contains the Swift Configuration dependency
- This allows ConfigKeyKit to be used in other projects without forcing Swift Configuration

### Swift Configuration Integration
- Uses `ConfigReader` with provider hierarchy
- Currently supports: Environment variables → Defaults
- Planned: Command-line arguments → Files → Environment → Defaults

## Architecture

Expand Down
63 changes: 39 additions & 24 deletions .claude/docs/mistdemo/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,42 @@ MistDemo supports flexible configuration through files, profiles, environment va

Configuration is resolved from multiple sources with the following priority (highest to lowest):

1. **Command-line arguments** - Explicit flags like `--database private`
**Current Implementation:**
1. **Environment variables** - System environment (e.g., `CLOUDKIT_CONTAINER_ID`)
2. **Built-in defaults** - Hardcoded fallback values in `InMemoryProvider`

**Planned Additions:**
1. **Command-line arguments** - Explicit flags like `--database private` (requires CommandLineArgumentsProvider)
2. **Profile settings** - From `--profile` in configuration file
3. **Configuration file** - Default values in JSON/YAML file
4. **Environment variables** - System environment (e.g., `CLOUDKIT_CONTAINER_ID`)
5. **Built-in defaults** - Hardcoded fallback values
3. **Configuration file** - Default values in JSON/YAML file (requires FileProvider)

## Swift Configuration Package

MistDemo uses [swift-configuration](https://github.com/apple/swift-configuration) with these providers:
MistDemo uses [swift-configuration](https://github.com/apple/swift-configuration) for hierarchical configuration management.

### Requirements

### Required Package Traits
- **macOS 15.0+** required due to Swift Configuration dependency
- Swift 6.0 or later

### Package Configuration

Add to your `Package.swift`:
```swift
.package(
url: "https://github.com/apple/swift-configuration",
from: "1.0.0",
traits: [.defaults, "CommandLineArguments", "YAML"]
from: "1.0.0"
)
```

### Provider Support
### Current Implementation

| Provider | Trait Required | Purpose |
|----------|---------------|---------|
| `JSONSnapshot` | ✗ (included in `.defaults`) | JSON configuration files |
| `YAMLSnapshot` | ✓ (`"YAML"`) | YAML configuration files |
| `EnvironmentVariablesProvider` | ✗ (core functionality) | Environment variables |
| `CommandLineArgumentsProvider` | ✓ (`"CommandLineArguments"`) | CLI argument parsing |
| Provider | Status | Purpose |
|----------|--------|---------|
| `EnvironmentVariablesProvider` | ✅ Implemented | Environment variables with automatic key transformation |
| `InMemoryProvider` | ✅ Implemented | Default values |
| `CommandLineArgumentsProvider` | ⏳ Planned | CLI argument parsing |
| `FileProvider + JSONSnapshot` | ⏳ Planned | JSON configuration files |
| `FileProvider + YAMLSnapshot` | ⏳ Planned | YAML configuration files |

## Configuration File Formats

Expand Down Expand Up @@ -93,15 +100,23 @@ profiles:

### Configuration Keys

| Key | Type | Environment Variable | Default | Description |
**Note**: Swift Configuration automatically transforms keys:
- Dots (`.`) become underscores (`_`) for environment variables
- Example: `container.identifier` → `CONTAINER_IDENTIFIER` environment variable
- When CommandLineArgumentsProvider is added: dots become hyphens for CLI args (`container.identifier` → `--container-identifier`)

| Key | Type | Environment Variable (Auto-transformed) | Default | Description |
|-----|------|---------------------|---------|-------------|
| `container_id` | String | `CLOUDKIT_CONTAINER_ID` | Required | Container identifier |
| `api_token` | String | `CLOUDKIT_API_TOKEN` | Required | API token (secret) |
| `environment` | String | `CLOUDKIT_ENVIRONMENT` | `development` | CloudKit environment |
| `database` | String | `CLOUDKIT_DATABASE` | `public` | Database type |
| `web_auth_token` | String | `CLOUDKIT_WEBAUTH_TOKEN` | | Web auth token (secret) |
| `key_id` | String | `CLOUDKIT_KEY_ID` | | Server-to-server key ID |
| `private_key_file` | String | `CLOUDKIT_PRIVATE_KEY_FILE` | | Path to private key |
| `container.identifier` | String | `CONTAINER_IDENTIFIER` | `iCloud.com.brightdigit.MistDemo` | Container identifier |
| `api.token` | String | `API_TOKEN` | Empty string | API token (secret) |
| `environment` | String | `ENVIRONMENT` | `development` | CloudKit environment |
| `database` | String | `DATABASE` | Varies by auth method | Database type |
| `web.auth.token` | String | `WEB_AUTH_TOKEN` | | Web auth token (secret) |
| `key.id` | String | `KEY_ID` | | Server-to-server key ID |
| `private.key` | String | `PRIVATE_KEY` | | Private key content (secret) |
| `private.key.file` | String | `PRIVATE_KEY_FILE` | | Path to private key |
| `host` | String | `HOST` | `127.0.0.1` | Server host for authentication |
| `port` | Int | `PORT` | `8080` | Server port |
| `output` | String | `MISTDEMO_OUTPUT` | `json` | Output format |
| `pretty` | Boolean | `MISTDEMO_PRETTY` | `false` | Pretty print output |
| `verbose` | Boolean | `MISTDEMO_VERBOSE` | `false` | Verbose logging |
Expand Down
130 changes: 67 additions & 63 deletions .claude/docs/mistdemo/phases/phase-1-core-infrastructure.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,43 +34,42 @@ protocol MistDemoCommand: AsyncParsableCommand {
- [ ] Configuration loading hooks
- [ ] Unit tests for protocol conformance

### 2. ConfigKeyKit Extensions
### 2. Configuration Management with Swift Configuration

**File**: `Sources/MistDemo/Configuration/ConfigurationManager.swift`
**Implementation Status**: ✅ Partially Complete

Implement Swift Configuration integration:
Implemented Swift Configuration integration using Apple's official configuration library:

```swift
class ConfigurationManager {
static let shared = ConfigurationManager()
**Completed Features:**
- [x] Environment variable provider (EnvironmentVariablesProvider)
- [x] In-memory defaults provider (InMemoryProvider)
- [x] Hierarchical resolution (Environment > Defaults)
- [x] Type-safe configuration with ConfigReader
- [x] MistDemoConfiguration wrapper for clean API
- [x] Automatic key transformation (dots to underscores for env vars)
- [x] Secret handling for sensitive values

func loadConfiguration(
configFile: String?,
profile: String?
) throws -> ConfigReader
}
```
**Files Implemented:**
- `Sources/MistDemo/Configuration/MistDemoConfiguration.swift` - Swift Configuration wrapper
- `Sources/MistDemo/Configuration/MistDemoConfig.swift` - Configuration data model
- `Sources/ConfigKeyKit/` - Reusable configuration key types

**Features:**
- [x] JSON configuration file support (JSONSnapshot, default trait)
- [x] YAML configuration file support (YAMLSnapshot, requires "YAML" trait)
- [x] Environment variable provider (core functionality)
- [x] Command-line arguments provider (requires "CommandLineArguments" trait)
- [x] Profile merging
- [x] Priority resolution (CLI > Profile > File > Environment > Defaults)
**Pending Features:**
- [ ] Command-line arguments provider (requires CommandLineArgumentsProvider)
- [ ] JSON configuration file support (requires FileProvider with JSONSnapshot)
- [ ] YAML configuration file support (requires FileProvider with YAMLSnapshot)
- [ ] Profile merging and selection
- [ ] Full priority resolution (CLI > Profile > File > Environment > Defaults)

**Files:**
- `Sources/MistDemo/Configuration/ConfigurationManager.swift`
- `Sources/MistDemo/Configuration/MistDemoConfig.swift`
- `Sources/MistDemo/Configuration/ConfigError.swift`
**Note**: Requires macOS 15.0+ due to Swift Configuration dependency.

**Acceptance Criteria:**
- [ ] Load JSON configuration files
- [ ] Load YAML configuration files
- [ ] Read environment variables
- [x] Read environment variables
- [ ] Merge profiles with base configuration
- [ ] Resolve configuration priority correctly
- [ ] Handle missing configuration gracefully
- [x] Resolve configuration priority correctly (for implemented providers)
- [x] Handle missing configuration gracefully
- [ ] Unit tests for all configuration sources
- [ ] Integration tests for priority resolution

Expand Down Expand Up @@ -147,64 +146,69 @@ enum MistDemoError: Error {

## Package Dependencies

Update `Package.swift`:
Current `Package.swift` configuration:

```swift
platforms: [
.macOS(.v15) // Required for Swift Configuration
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"),
.package(
url: "https://github.com/apple/swift-configuration",
from: "1.0.0",
traits: [.defaults, "CommandLineArguments", "YAML"]
),
.package(url: "https://github.com/apple/swift-log", from: "1.5.0"),
.package(path: "../.."), // MistKit
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0"),
.package(url: "https://github.com/apple/swift-configuration", from: "1.0.0")
],
targets: [
.target(
name: "ConfigKeyKit",
dependencies: [] // Lightweight, no dependencies
),
.executableTarget(
name: "MistDemo",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "Configuration", package: "swift-configuration"),
.product(name: "Logging", package: "swift-log"),
"MistKit",
"ConfigKeyKit",
.product(name: "MistKit", package: "MistKit"),
.product(name: "Hummingbird", package: "hummingbird"),
.product(name: "Configuration", package: "swift-configuration")
]
),
)
]
```

**Note**: ArgumentParser was removed in favor of direct Swift Configuration usage.

## File Structure

**Current Implementation:**
```
Sources/MistDemo/
├── MistDemo.swift # Main entry point
├── Commands/
│ └── CommandProtocol.swift # Base command protocol
├── Configuration/
│ ├── ConfigurationManager.swift
│ ├── MistDemoConfig.swift
│ └── ConfigError.swift
├── Output/
│ ├── OutputFormatter.swift # Protocol
│ ├── JSONFormatter.swift
│ ├── TableFormatter.swift
│ ├── CSVFormatter.swift
│ └── YAMLFormatter.swift
└── Errors/
└── MistDemoError.swift
Sources/
├── ConfigKeyKit/ # Reusable configuration key types
│ ├── ConfigKey.swift
│ ├── ConfigurationKey.swift
│ └── OptionalConfigKey.swift
└── MistDemo/
├── MistDemo.swift # Main entry point
├── Configuration/
│ ├── MistDemoConfiguration.swift # Swift Configuration wrapper
│ └── MistDemoConfig.swift # Configuration data model
├── Utilities/
│ ├── AuthenticationHelper.swift # Authentication setup logic
│ └── AuthenticationResult.swift # Auth result model
└── Errors/
└── AuthenticationError.swift # Authentication errors

Tests/MistDemoTests/
├── Configuration/
│ ├── ConfigurationManagerTests.swift
│ ├── ProfileMergingTests.swift
│ └── PriorityResolutionTests.swift
└── Output/
├── JSONFormatterTests.swift
├── TableFormatterTests.swift
├── CSVFormatterTests.swift
└── YAMLFormatterTests.swift
│ └── (Tests pending)
└── Utilities/
└── (Tests pending)
```

**Pending Implementation:**
- Command protocol structure
- Output formatters (JSON, Table, CSV, YAML)
- Comprehensive error handling
- Test coverage

## Testing Requirements

### Unit Tests
Expand Down
Loading