1- # Plan: SyntaxKit Analyzer CLI Tool
1+ # Plan: AiSTKit - AI-Powered AST Generation for SyntaxKit
22
33## Context
44
@@ -17,18 +17,62 @@ This addresses the problem of implementing missing SyntaxKit features. Instead o
1717
1818## Implementation Approach
1919
20- ### 1. Create New Executable Target: ` skit-analyze `
20+ ### 1. Create Three Targets with Clear Separation
2121
22- ** Location** : ` Sources/skit-analyze/ `
22+ This implementation uses three separate targets for better modularity and testability:
23+
24+ #### Target 1: ` ClaudeKit ` (OpenAPI Generated Code)
25+ ** Location** : ` Sources/ClaudeKit/ `
26+
27+ ** Purpose** : Contains the raw OpenAPI-generated client code for the Anthropic Claude API
2328
2429** Dependencies** :
25- - ` SyntaxParser ` (existing) - for parsing Swift code to AST
26- - ` ConfigKeyKit ` (existing in project) - for configuration key management
27- - ` swift-configuration ` - for CLI argument and environment variable handling
28- - ` swift-openapi-generator ` - for generating type-safe Claude API client from OpenAPI spec
2930- ` swift-openapi-runtime ` - runtime support for generated OpenAPI client
3031- ` swift-openapi-urlsession ` - URLSession transport for OpenAPI client
3132
33+ ** Build Plugin** : ` OpenAPIGenerator ` (generates client from ` openapi.json ` )
34+
35+ ** Contents** :
36+ - ` openapi.json ` - Anthropic OpenAPI specification
37+ - ` openapi-generator-config.yaml ` - Generator configuration
38+ - Generated code (types, client) created automatically at build time
39+
40+ #### Target 2: ` AiSTKit ` (SDK/Bridge Layer)
41+ ** Location** : ` Sources/AiSTKit/ `
42+
43+ ** Purpose** : Provides a clean, domain-specific interface between the command executable and the raw OpenAPI client. Handles prompt formatting, response parsing, and code generation logic.
44+
45+ ** Dependencies** :
46+ - ` ClaudeKit ` - the OpenAPI-generated client
47+ - ` SyntaxParser ` - for AST generation
48+ - Foundation
49+
50+ ** Key Responsibilities** :
51+ - Wraps ` ClaudeKit ` with domain-specific methods
52+ - Implements ` SyntaxKitAnalyzer ` orchestration logic
53+ - Handles prompt template creation
54+ - Parses Claude responses into ` LibraryUpdateResult `
55+ - Manages AST generation
56+ - Collects and writes library files
57+
58+ #### Target 3: ` skit-aist ` (Command Executable)
59+ ** Location** : ` Sources/skit-aist/ `
60+
61+ ** Purpose** : CLI executable that handles argument parsing, configuration, and user interaction
62+
63+ ** Dependencies** :
64+ - ` AiSTKit ` - the SDK/bridge layer
65+ - ` ConfigKeyKit ` (existing in project) - for configuration key management
66+ - ` swift-configuration ` - for CLI argument and environment variable handling
67+
68+ ** Key Responsibilities** :
69+ - Parse command-line arguments
70+ - Load configuration from environment variables
71+ - Display help text and usage information
72+ - Handle test mode execution
73+ - Provide verbose output and error messages
74+ - Entry point (` main.swift ` )
75+
3276### 2. Core Components
3377
3478#### A. Configuration Structure (` AnalyzerConfiguration.swift ` )
@@ -76,7 +120,7 @@ struct AnalyzerConfiguration: ConfigurationParseable {
76120
77121 guard positionalArgs.count >= 3 else {
78122 throw AnalyzerError.missingRequiredArguments (
79- " Usage: skit-analyze <input-folder> <syntaxkit-path> <output-folder> [options]"
123+ " Usage: skit-aist <input-folder> <syntaxkit-path> <output-folder> [options]"
80124 )
81125 }
82126
@@ -136,11 +180,11 @@ struct AnalyzeCommand: Command {
136180 typealias Config = AnalyzerConfiguration
137181
138182 static let commandName = " analyze"
139- static let abstract = " Generate updated SyntaxKit library with missing features "
183+ static let abstract = " AI-powered AST generation for SyntaxKit "
140184 static let helpText = """
141185 OVERVIEW: Automatically implement missing SyntaxKit features using Claude API
142186
143- USAGE: skit-analyze <input-folder> <syntaxkit-path> <output-folder> [options]
187+ USAGE: skit-aist <input-folder> <syntaxkit-path> <output-folder> [options]
144188
145189 ARGUMENTS:
146190 <input-folder> Folder containing:
@@ -164,7 +208,7 @@ struct AnalyzeCommand: Command {
164208 echo 'subscript(index: Int) -> Item { ... }' > examples/subscript-feature/expected.swift
165209
166210 export ANTHROPIC_API_KEY="sk-ant-..."
167- skit-analyze examples/subscript-feature Sources/SyntaxKit output/SyntaxKit
211+ skit-aist examples/subscript-feature Sources/SyntaxKit output/SyntaxKit
168212 """
169213
170214 let config: Config
@@ -254,7 +298,7 @@ struct SyntaxKitAnalyzer {
254298
255299 // 4. Call Claude API for analysis AND code generation
256300 if config.verbose { print (" Calling Claude API (\( config.model ) )..." ) }
257- let client = ClaudeAPIClient (apiKey : config.apiKey , model : config.model )
301+ let client = ClaudeKit (apiKey : config.apiKey , model : config.model )
258302 let result = try await client.generateUpdatedLibrary (
259303 syntaxKitLibrary : libraryCode,
260304 expectedSwift : inputs.expectedSwift ,
@@ -437,15 +481,15 @@ struct ASTGenerator {
437481- This is the same code path used by the ` skit ` executable
438482- No need for external AST generation - it's built-in!
439483
440- #### I. Claude API Client (` ClaudeAPIClient .swift` )
484+ #### I. Claude API Client (` ClaudeKit .swift` )
441485
442486Wraps the OpenAPI-generated client for code generation:
443487
444488``` swift
445489import OpenAPIRuntime
446490import OpenAPIURLSession
447491
448- struct ClaudeAPIClient {
492+ struct ClaudeKit {
449493 let apiKey: String
450494 let model: String
451495 private let client: Client // Generated from OpenAPI spec
@@ -607,12 +651,12 @@ struct FileReference: Codable {
607651** OpenAPI Specification Source** :
608652- Uses unofficial OpenAPI spec from [ laszukdawid/anthropic-openapi-spec] ( https://github.com/laszukdawid/anthropic-openapi-spec )
609653- Specifically the ` hosted_spec.json ` file (derived from Anthropic's TypeScript SDK)
610- - Download to ` Sources/skit-analyze /openapi.json ` or ` openapi.yaml `
654+ - Download to ` Sources/skit-aist /openapi.json ` or ` openapi.yaml `
611655- Swift OpenAPI Generator will create type-safe client code at build time
612656
613657** Setup Steps** :
614- 1 . Download OpenAPI spec: ` curl -o Sources/skit-analyze /openapi.json https://raw.githubusercontent.com/laszukdawid/anthropic-openapi-spec/main/hosted_spec.json `
615- 2 . Create ` Sources/skit-analyze /openapi-generator-config.yaml ` :
658+ 1 . Download OpenAPI spec: ` curl -o Sources/skit-aist /openapi.json https://raw.githubusercontent.com/laszukdawid/anthropic-openapi-spec/main/hosted_spec.json `
659+ 2 . Create ` Sources/skit-aist /openapi-generator-config.yaml ` :
616660 ``` yaml
617661 generate :
618662 - types
@@ -694,7 +738,7 @@ Include:
694738### 3. Workflow
695739
696740```
697- User runs: skit-analyze examples/subscript-feature Sources/SyntaxKit output/SyntaxKit
741+ User runs: skit-aist examples/subscript-feature Sources/SyntaxKit output/SyntaxKit
698742
6997431 . main.swift: Entry point
7007442 . AnalyzeCommand.createInstance():
@@ -761,7 +805,7 @@ Add ConfigKeyKit as a local target, integrate swift-configuration, and add OpenA
761805
762806// Add new executable target with OpenAPI Generator plugin:
763807.executableTarget(
764- name: "skit-analyze ",
808+ name: "skit-aist ",
765809 dependencies: [
766810 "SyntaxParser",
767811 "ConfigKeyKit",
@@ -777,19 +821,19 @@ Add ConfigKeyKit as a local target, integrate swift-configuration, and add OpenA
777821
778822// In products:
779823.executable(
780- name: "skit-analyze ",
781- targets: ["skit-analyze "]
824+ name: "skit-aist ",
825+ targets: ["skit-aist "]
782826),
783827```
784828
785829** Setup Requirements** :
786- 1 . Download OpenAPI spec to ` Sources/skit-analyze / ` :
830+ 1 . Download OpenAPI spec to ` Sources/skit-aist / ` :
787831 ``` bash
788- curl -o Sources/skit-analyze /openapi.json \
832+ curl -o Sources/skit-aist /openapi.json \
789833 https://raw.githubusercontent.com/laszukdawid/anthropic-openapi-spec/main/hosted_spec.json
790834 ```
791835
792- 2 . Create ` Sources/skit-analyze /openapi-generator-config.yaml ` :
836+ 2 . Create ` Sources/skit-aist /openapi-generator-config.yaml ` :
793837 ``` yaml
794838 generate :
795839 - types
@@ -844,7 +888,7 @@ Add ConfigKeyKit as a local target, integrate swift-configuration, and add OpenA
844888 3. Output folder path (where to write updated library)
845889- Parsed manually from `CommandLine.arguments` in configuration initializer
846890- More intuitive than using flags for required paths
847- - Example : ` skit-analyze examples/feature Sources/SyntaxKit output/updated`
891+ - Example : ` skit-aist examples/feature Sources/SyntaxKit output/updated`
848892
849893**Default Values**:
850894- SyntaxKit library path : ` Sources/SyntaxKit` (via `ConfigKey` default)
@@ -897,28 +941,28 @@ Include full API request/response, intermediate parsing steps, file collection d
897941## Critical Files to Create
898942
899943### Source Files
900- 1. **Sources/skit-analyze /main.swift** - Main entry point
901- 2. **Sources/skit-analyze /AnalyzeCommand.swift** - Command implementation using ConfigKeyKit
902- 3. **Sources/skit-analyze /AnalyzerConfiguration.swift** - Configuration structure using ConfigKeyKit
903- 4. **Sources/skit-analyze /SyntaxKitAnalyzer.swift** - Core analyzer orchestration
904- 5. **Sources/skit-analyze /InputFolderReader.swift** - Reads dsl.swift, expected.swift, ast files
905- 6. **Sources/skit-analyze /LibraryCollector.swift** - Collects SyntaxKit source files
906- 7. **Sources/skit-analyze /LibraryWriter.swift** - Writes updated library to output folder
907- 8. **Sources/skit-analyze /ASTGenerator.swift** - Wraps SyntaxParser for AST generation
908- 9. **Sources/skit-analyze/ClaudeAPIClient .swift** - Wraps OpenAPI-generated client for code generation
909- 10. **Sources/skit-analyze /PromptTemplate.swift** - Enhanced Workbench prompt with code generation
910- 11. **Sources/skit-analyze /Models.swift** - Data models (LibraryUpdateResult, UpdatedFile, NewFile, AnalyzerError)
944+ 1. **Sources/skit-aist /main.swift** - Main entry point
945+ 2. **Sources/skit-aist /AnalyzeCommand.swift** - Command implementation using ConfigKeyKit
946+ 3. **Sources/skit-aist /AnalyzerConfiguration.swift** - Configuration structure using ConfigKeyKit
947+ 4. **Sources/skit-aist /SyntaxKitAnalyzer.swift** - Core analyzer orchestration
948+ 5. **Sources/skit-aist /InputFolderReader.swift** - Reads dsl.swift, expected.swift, ast files
949+ 6. **Sources/skit-aist /LibraryCollector.swift** - Collects SyntaxKit source files
950+ 7. **Sources/skit-aist /LibraryWriter.swift** - Writes updated library to output folder
951+ 8. **Sources/skit-aist /ASTGenerator.swift** - Wraps SyntaxParser for AST generation
952+ 9. **Sources/skit-aist/ClaudeKit .swift** - Wraps OpenAPI-generated client for code generation
953+ 10. **Sources/skit-aist /PromptTemplate.swift** - Enhanced Workbench prompt with code generation
954+ 11. **Sources/skit-aist /Models.swift** - Data models (LibraryUpdateResult, UpdatedFile, NewFile, AnalyzerError)
911955
912956### Configuration Files
913- 12. **Sources/skit-analyze /openapi.json** - Anthropic OpenAPI specification (downloaded)
914- 13. **Sources/skit-analyze /openapi-generator-config.yaml** - OpenAPI Generator configuration
957+ 12. **Sources/skit-aist /openapi.json** - Anthropic OpenAPI specification (downloaded)
958+ 13. **Sources/skit-aist /openapi-generator-config.yaml** - OpenAPI Generator configuration
91595914. **Package.swift** (modify) - Add ConfigKeyKit target, dependencies, and OpenAPI plugin
916960
917961### Test Mode Files (Section 8)
918- 15. **Sources/skit-analyze /Testing/TestRunner.swift** - Orchestrates test execution
919- 16. **Sources/skit-analyze /Testing/TestCaseDiscoverer.swift** - Discovers and loads test cases
920- 17. **Sources/skit-analyze /Testing/TestValidator.swift** - Validates results against expectations
921- 18. **Sources/skit-analyze /Testing/TestModels.swift** - Test data structures
962+ 15. **Sources/skit-aist /Testing/TestRunner.swift** - Orchestrates test execution
963+ 16. **Sources/skit-aist /Testing/TestCaseDiscoverer.swift** - Discovers and loads test cases
964+ 17. **Sources/skit-aist /Testing/TestValidator.swift** - Validates results against expectations
965+ 18. **Sources/skit-aist /Testing/TestModels.swift** - Test data structures
922966
923967## Verification Steps
924968
@@ -948,7 +992,7 @@ Include full API request/response, intermediate parsing steps, file collection d
9489923. **Run Tool**:
949993 ```bash
950994 export ANTHROPIC_API_KEY="sk-ant-..."
951- .build/release/skit-analyze \
995+ .build/release/skit-aist \
952996 examples/simple-property \
953997 Sources/SyntaxKit \
954998 output/SyntaxKit-updated
@@ -975,16 +1019,16 @@ Include full API request/response, intermediate parsing steps, file collection d
97510196. **Error Handling Tests**:
9761020 ```bash
9771021 # Test missing API key
978- skit-analyze examples/test Sources/SyntaxKit output # Should error
1022+ skit-aist examples/test Sources/SyntaxKit output # Should error
9791023
9801024 # Test invalid input folder
981- skit-analyze nonexistent Sources/SyntaxKit output # Should error
1025+ skit-aist nonexistent Sources/SyntaxKit output # Should error
9821026
9831027 # Test missing required files
9841028 mkdir -p examples/incomplete
9851029 echo "test" > examples/incomplete/dsl.swift
9861030 # Missing expected.swift - should error
987- skit-analyze examples/incomplete Sources/SyntaxKit output
1031+ skit-aist examples/incomplete Sources/SyntaxKit output
9881032 ```
9891033
99010347. **Integration Test**: Use a real missing feature (e.g., subscript syntax) and verify:
@@ -1087,19 +1131,19 @@ See the full implementation plan in the main plan file for detailed component sp
10871131
10881132```bash
10891133# Run all test cases
1090- skit-analyze --test
1134+ skit-aist --test
10911135
10921136# Run with verbose output
1093- skit-analyze --test --verbose
1137+ skit-aist --test --verbose
10941138
10951139# Stop on first failure
1096- skit-analyze --test --test-stop-on-fail
1140+ skit-aist --test --test-stop-on-fail
10971141
10981142# Run only tests matching "subscript"
1099- skit-analyze --test --test-filter=subscript
1143+ skit-aist --test --test-filter=subscript
11001144
11011145# Run tests from custom path
1102- skit-analyze --test --test-cases=custom-tests/
1146+ skit-aist --test --test-cases=custom-tests/
11031147```
11041148
11051149### Benefits
@@ -1161,10 +1205,10 @@ skit-analyze --test --test-cases=custom-tests/
11611205swift build -c release
11621206
11631207# Install to system (optional)
1164- cp .build/release/skit-analyze /usr/local/bin/
1208+ cp .build/release/skit-aist /usr/local/bin/
11651209
11661210# Or run from build directory
1167- .build/release/skit-analyze <args>
1211+ .build/release/skit-aist <args>
11681212```
11691213
11701214## Example Usage
@@ -1196,7 +1240,7 @@ EOF
11961240# 4. Run the tool
11971241# Note: AST is automatically generated from expected.swift using SyntaxParser
11981242export ANTHROPIC_API_KEY=" sk-ant-..."
1199- skit-analyze \
1243+ skit-aist \
12001244 examples/subscript-feature \
12011245 Sources/SyntaxKit \
12021246 output/SyntaxKit-with-subscripts
@@ -1206,19 +1250,19 @@ skit-analyze \
12061250
12071251``` bash
12081252# With custom model
1209- skit-analyze examples/my-feature Sources/SyntaxKit output/updated \
1253+ skit-aist examples/my-feature Sources/SyntaxKit output/updated \
12101254 --model claude-sonnet-4-5
12111255
12121256# With verbose output to see what's happening
1213- skit-analyze examples/my-feature Sources/SyntaxKit output/updated \
1257+ skit-aist examples/my-feature Sources/SyntaxKit output/updated \
12141258 --verbose
12151259
12161260# Using CLI flag for API key instead of environment
1217- skit-analyze examples/my-feature Sources/SyntaxKit output/updated \
1261+ skit-aist examples/my-feature Sources/SyntaxKit output/updated \
12181262 --api-key sk-ant-...
12191263
12201264# Show help
1221- skit-analyze --help
1265+ skit-aist --help
12221266```
12231267
12241268### Full Workflow Example
@@ -1247,7 +1291,7 @@ EOF
12471291
12481292# Step 4: Generate updated SyntaxKit with defer support
12491293export ANTHROPIC_API_KEY=" sk-ant-..."
1250- skit-analyze \
1294+ skit-aist \
12511295 examples/defer-statement \
12521296 Sources/SyntaxKit \
12531297 output/SyntaxKit-with-defer \
0 commit comments