spec-driven-development 0.0.0-canary-20251223010757
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/AGENT_MODES.md +247 -0
- package/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/QUICK_REFERENCE.md +209 -0
- package/QUICK_START.md +174 -0
- package/README.md +628 -0
- package/bin/contractspec.mjs +3 -0
- package/package.json +33 -0
package/AGENT_MODES.md
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# AI Agent Modes
|
|
2
|
+
|
|
3
|
+
The contracts-cli supports multiple AI agent modes for code generation and validation. Each mode offers different capabilities and trade-offs.
|
|
4
|
+
|
|
5
|
+
## Available Agent Modes
|
|
6
|
+
|
|
7
|
+
### 1. Simple Mode (Default)
|
|
8
|
+
- **Mode**: `simple`
|
|
9
|
+
- **Description**: Direct LLM API calls for code generation
|
|
10
|
+
- **Best For**: Quick prototyping, basic implementations
|
|
11
|
+
- **Requirements**: API key for your chosen provider (Claude, OpenAI, Ollama)
|
|
12
|
+
- **Speed**: Fast
|
|
13
|
+
- **Quality**: Good baseline quality
|
|
14
|
+
|
|
15
|
+
**Example:**
|
|
16
|
+
```bash
|
|
17
|
+
contractspec build spec.contracts.ts --agent-mode simple
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### 2. Cursor Agent Mode
|
|
21
|
+
- **Mode**: `cursor`
|
|
22
|
+
- **Description**: Leverages Windsurf/Cursor's agentic capabilities
|
|
23
|
+
- **Best For**: Complex implementations, iterative development
|
|
24
|
+
- **Requirements**: Running in Windsurf/Cursor environment
|
|
25
|
+
- **Speed**: Moderate
|
|
26
|
+
- **Quality**: High quality with context awareness
|
|
27
|
+
|
|
28
|
+
**Example:**
|
|
29
|
+
```bash
|
|
30
|
+
contractspec build spec.contracts.ts --agent-mode cursor
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Note**: This mode requires Windsurf/Cursor CLI access. If not available, falls back to simple mode.
|
|
34
|
+
|
|
35
|
+
### 3. Claude Code Mode
|
|
36
|
+
- **Mode**: `claude-code`
|
|
37
|
+
- **Description**: Uses Anthropic's Claude with extended thinking for code generation
|
|
38
|
+
- **Best For**: Production-quality code, complex logic, thorough validation
|
|
39
|
+
- **Requirements**: `ANTHROPIC_API_KEY` environment variable
|
|
40
|
+
- **Speed**: Moderate to slow
|
|
41
|
+
- **Quality**: Very high quality, excellent for validation
|
|
42
|
+
|
|
43
|
+
**Features:**
|
|
44
|
+
- Extended context understanding
|
|
45
|
+
- Detailed code review capabilities
|
|
46
|
+
- Comprehensive validation reports
|
|
47
|
+
- Best for critical implementations
|
|
48
|
+
|
|
49
|
+
**Example:**
|
|
50
|
+
```bash
|
|
51
|
+
export ANTHROPIC_API_KEY=your_key
|
|
52
|
+
contractspec build spec.contracts.ts --agent-mode claude-code
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 4. OpenAI Codex Mode
|
|
56
|
+
- **Mode**: `openai-codex`
|
|
57
|
+
- **Description**: Uses OpenAI's GPT-4o and o1 models for code generation
|
|
58
|
+
- **Best For**: Complex algorithms, optimization tasks
|
|
59
|
+
- **Requirements**: `OPENAI_API_KEY` environment variable
|
|
60
|
+
- **Speed**: Fast (GPT-4o) to slow (o1 reasoning)
|
|
61
|
+
- **Quality**: High quality, excellent for algorithmic problems
|
|
62
|
+
|
|
63
|
+
**Features:**
|
|
64
|
+
- Automatically selects o1 for complex tasks
|
|
65
|
+
- Uses GPT-4o for standard generation
|
|
66
|
+
- Strong at optimization and algorithms
|
|
67
|
+
|
|
68
|
+
**Example:**
|
|
69
|
+
```bash
|
|
70
|
+
export OPENAI_API_KEY=your_key
|
|
71
|
+
contractspec build spec.contracts.ts --agent-mode openai-codex
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Configuring Agent Modes
|
|
75
|
+
|
|
76
|
+
### Via Configuration File
|
|
77
|
+
|
|
78
|
+
Add to `.contractsrc.json`:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"aiProvider": "claude",
|
|
83
|
+
"agentMode": "claude-code",
|
|
84
|
+
"aiModel": "claude-3-7-sonnet-20250219"
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Via Environment Variables
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
export CONTRACTSPEC_AGENT_MODE=claude-code
|
|
92
|
+
export CONTRACTSPEC_AI_PROVIDER=claude
|
|
93
|
+
export ANTHROPIC_API_KEY=your_key
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Via CLI Options
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
contractspec build spec.ts --agent-mode claude-code --provider claude
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Agent Mode Comparison
|
|
103
|
+
|
|
104
|
+
| Feature | Simple | Cursor | Claude Code | OpenAI Codex |
|
|
105
|
+
|---------|--------|--------|-------------|--------------|
|
|
106
|
+
| Speed | ⚡⚡⚡ | ⚡⚡ | ⚡⚡ | ⚡⚡⚡ |
|
|
107
|
+
| Quality | ⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
|
|
108
|
+
| Validation | Basic | Good | Excellent | Good |
|
|
109
|
+
| Setup | Easy | Moderate | Easy | Easy |
|
|
110
|
+
| Cost | Low | N/A | Moderate | Low-Moderate |
|
|
111
|
+
|
|
112
|
+
## Fallback Behavior
|
|
113
|
+
|
|
114
|
+
The CLI automatically falls back to simpler modes if the primary mode fails:
|
|
115
|
+
|
|
116
|
+
1. **cursor** → **claude-code** → **openai-codex** → **simple**
|
|
117
|
+
2. **claude-code** → **openai-codex** → **simple**
|
|
118
|
+
3. **openai-codex** → **simple**
|
|
119
|
+
4. **simple** → Basic templates (no AI)
|
|
120
|
+
|
|
121
|
+
## Usage Examples
|
|
122
|
+
|
|
123
|
+
### Build with Agent Mode
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Use Claude Code for high-quality generation
|
|
127
|
+
contractspec build user.contracts.ts --agent-mode claude-code
|
|
128
|
+
|
|
129
|
+
# Use OpenAI for algorithmic code
|
|
130
|
+
contractspec build optimizer.contracts.ts --agent-mode openai-codex
|
|
131
|
+
|
|
132
|
+
# Disable AI entirely
|
|
133
|
+
contractspec build simple.contracts.ts --no-agent
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Validate with Agent Mode
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# Validate implementation with AI
|
|
140
|
+
contractspec validate user.contracts.ts --check-implementation --agent-mode claude-code
|
|
141
|
+
|
|
142
|
+
# Interactive validation
|
|
143
|
+
contractspec validate user.contracts.ts -i --agent-mode claude-code
|
|
144
|
+
|
|
145
|
+
# Specify implementation path
|
|
146
|
+
contractspec validate user.contracts.ts \
|
|
147
|
+
--check-implementation \
|
|
148
|
+
--implementation-path ./handlers/user.handler.ts \
|
|
149
|
+
--agent-mode claude-code
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Best Practices
|
|
153
|
+
|
|
154
|
+
### For Development
|
|
155
|
+
- Use **simple** mode for rapid iteration
|
|
156
|
+
- Use **cursor** mode if working in Windsurf/Cursor
|
|
157
|
+
|
|
158
|
+
### For Production
|
|
159
|
+
- Use **claude-code** for critical implementations
|
|
160
|
+
- Always validate with `--check-implementation`
|
|
161
|
+
- Review AI-generated code before committing
|
|
162
|
+
|
|
163
|
+
### For Complex Logic
|
|
164
|
+
- Use **openai-codex** for algorithmic problems
|
|
165
|
+
- Use **claude-code** for comprehensive validation
|
|
166
|
+
|
|
167
|
+
### For CI/CD
|
|
168
|
+
- Use **simple** mode for speed
|
|
169
|
+
- Configure via environment variables
|
|
170
|
+
- Set up validation in pre-commit hooks
|
|
171
|
+
|
|
172
|
+
## Troubleshooting
|
|
173
|
+
|
|
174
|
+
### Agent Mode Not Working
|
|
175
|
+
|
|
176
|
+
Check:
|
|
177
|
+
1. API keys are set correctly
|
|
178
|
+
2. Network connectivity to AI providers
|
|
179
|
+
3. Provider quotas and rate limits
|
|
180
|
+
|
|
181
|
+
### Fallback to Simple Mode
|
|
182
|
+
|
|
183
|
+
This happens when:
|
|
184
|
+
- API key is missing
|
|
185
|
+
- Provider is unavailable
|
|
186
|
+
- Agent cannot handle the task
|
|
187
|
+
|
|
188
|
+
The CLI will show warnings explaining why.
|
|
189
|
+
|
|
190
|
+
### Poor Quality Output
|
|
191
|
+
|
|
192
|
+
Try:
|
|
193
|
+
1. Using a more powerful agent mode
|
|
194
|
+
2. Adding more context to your spec
|
|
195
|
+
3. Reviewing and refining the spec structure
|
|
196
|
+
|
|
197
|
+
## Environment Variables Reference
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
# Provider selection
|
|
201
|
+
CONTRACTSPEC_AI_PROVIDER=claude|openai|ollama|custom
|
|
202
|
+
|
|
203
|
+
# Agent mode
|
|
204
|
+
CONTRACTSPEC_AGENT_MODE=simple|cursor|claude-code|openai-codex
|
|
205
|
+
|
|
206
|
+
# Model selection
|
|
207
|
+
CONTRACTSPEC_AI_MODEL=claude-3-7-sonnet-20250219
|
|
208
|
+
|
|
209
|
+
# API Keys
|
|
210
|
+
ANTHROPIC_API_KEY=your_anthropic_key
|
|
211
|
+
OPENAI_API_KEY=your_openai_key
|
|
212
|
+
|
|
213
|
+
# Custom endpoints
|
|
214
|
+
CONTRACTSPEC_LLM_ENDPOINT=https://your-custom-endpoint
|
|
215
|
+
CONTRACTSPEC_LLM_API_KEY=your_custom_key
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Advanced Configuration
|
|
219
|
+
|
|
220
|
+
### Custom Agent Priorities
|
|
221
|
+
|
|
222
|
+
You can configure fallback priorities in `.contractsrc.json`:
|
|
223
|
+
|
|
224
|
+
```json
|
|
225
|
+
{
|
|
226
|
+
"agentMode": "claude-code",
|
|
227
|
+
"aiProvider": "claude",
|
|
228
|
+
"aiModel": "claude-3-7-sonnet-20250219",
|
|
229
|
+
"outputDir": "./src",
|
|
230
|
+
"defaultOwners": ["@team"],
|
|
231
|
+
"defaultTags": ["auto-generated"]
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Multi-Model Strategy
|
|
236
|
+
|
|
237
|
+
Use different models for different tasks:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
# Use Claude for generation
|
|
241
|
+
contractspec build spec.ts --agent-mode claude-code
|
|
242
|
+
|
|
243
|
+
# Use OpenAI for validation
|
|
244
|
+
contractspec validate spec.ts \
|
|
245
|
+
--check-implementation \
|
|
246
|
+
--agent-mode openai-codex
|
|
247
|
+
```
|
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chaman Ventures, SASU
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# Quick Reference Guide
|
|
2
|
+
|
|
3
|
+
## New Commands Overview
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# Discovery & Management
|
|
7
|
+
contractspec list # List all contracts
|
|
8
|
+
contractspec list --type operation # Filter contracts
|
|
9
|
+
contractspec list --pattern 'src/**/*.ts' # Custom discovery pattern
|
|
10
|
+
contractspec list --deep # Load spec modules (richer metadata)
|
|
11
|
+
contractspec deps # Analyze dependencies
|
|
12
|
+
contractspec deps --circular # Find circular deps
|
|
13
|
+
contractspec deps --format dot > deps.dot # GraphViz dot output
|
|
14
|
+
|
|
15
|
+
# Development Workflow
|
|
16
|
+
contractspec watch --build # Auto-build on changes
|
|
17
|
+
contractspec watch --validate # Auto-validate on changes
|
|
18
|
+
contractspec watch --on-start both # Run on startup too
|
|
19
|
+
contractspec watch --continue-on-error # Keep watching even on failures
|
|
20
|
+
|
|
21
|
+
# Maintenance & Comparison
|
|
22
|
+
contractspec clean # Clean generated files
|
|
23
|
+
contractspec clean --dry-run # Preview cleanup
|
|
24
|
+
contractspec diff spec1.ts spec2.ts # Compare specs
|
|
25
|
+
contractspec diff spec.ts spec.ts --baseline main # Compare with git baseline
|
|
26
|
+
contractspec sync # Build all discovered specs
|
|
27
|
+
contractspec sync --buckets api,ui # Repeat builds into ./generated/<bucket>/
|
|
28
|
+
|
|
29
|
+
# Validation & Testing
|
|
30
|
+
contractspec validate '**/*.ts' # Validate all specs
|
|
31
|
+
contractspec validate spec.ts --check-implementation
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Agent Modes at a Glance
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Simple (default) - Fast, basic quality
|
|
38
|
+
contractspec build spec.ts
|
|
39
|
+
|
|
40
|
+
# Claude Code - Best quality, production-ready
|
|
41
|
+
contractspec build spec.ts --agent-mode claude-code
|
|
42
|
+
|
|
43
|
+
# OpenAI Codex - Best for algorithms
|
|
44
|
+
contractspec build spec.ts --agent-mode openai-codex
|
|
45
|
+
|
|
46
|
+
# Cursor - IDE-integrated (Windsurf/Cursor)
|
|
47
|
+
contractspec build spec.ts --agent-mode cursor
|
|
48
|
+
|
|
49
|
+
# No AI - Templates only
|
|
50
|
+
contractspec build spec.ts --no-agent
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Build Examples
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Basic build
|
|
57
|
+
contractspec build user.contracts.ts
|
|
58
|
+
# (Falls back to templates automatically if the requested agent is unavailable)
|
|
59
|
+
|
|
60
|
+
# Production build with tests
|
|
61
|
+
contractspec build user.contracts.ts --agent-mode claude-code
|
|
62
|
+
|
|
63
|
+
# Fast build without tests
|
|
64
|
+
contractspec build user.contracts.ts --no-tests
|
|
65
|
+
|
|
66
|
+
# Custom output directory
|
|
67
|
+
contractspec build user.contracts.ts -o ./src/handlers
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Validation Examples
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Validate spec only
|
|
74
|
+
contractspec validate user.contracts.ts
|
|
75
|
+
|
|
76
|
+
# Validate implementation with AI
|
|
77
|
+
contractspec validate user.contracts.ts --check-implementation
|
|
78
|
+
|
|
79
|
+
# Interactive validation
|
|
80
|
+
contractspec validate user.contracts.ts -i
|
|
81
|
+
|
|
82
|
+
# Default prompt (no flags): choose spec-only vs spec+implementation
|
|
83
|
+
contractspec validate user.contracts.ts
|
|
84
|
+
|
|
85
|
+
# Validate with specific implementation
|
|
86
|
+
contractspec validate user.contracts.ts \
|
|
87
|
+
--check-implementation \
|
|
88
|
+
--implementation-path ./handlers/user.handler.ts \
|
|
89
|
+
--agent-mode claude-code
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Configuration
|
|
93
|
+
|
|
94
|
+
### Minimal .contractsrc.json
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"aiProvider": "claude",
|
|
98
|
+
"agentMode": "claude-code",
|
|
99
|
+
"outputDir": "./src"
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Environment Variables
|
|
104
|
+
```bash
|
|
105
|
+
# Required for Claude
|
|
106
|
+
export ANTHROPIC_API_KEY=sk-ant-...
|
|
107
|
+
|
|
108
|
+
# Required for OpenAI
|
|
109
|
+
export OPENAI_API_KEY=sk-...
|
|
110
|
+
|
|
111
|
+
# Agent mode (optional)
|
|
112
|
+
export CONTRACTSPEC_AGENT_MODE=claude-code
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Common Workflows
|
|
116
|
+
|
|
117
|
+
### Development Flow
|
|
118
|
+
```bash
|
|
119
|
+
# 1. Create spec
|
|
120
|
+
contractspec create --type operation --ai
|
|
121
|
+
|
|
122
|
+
# 2. Generate implementation
|
|
123
|
+
contractspec build spec.contracts.ts --agent-mode claude-code
|
|
124
|
+
|
|
125
|
+
# 3. Validate
|
|
126
|
+
contractspec validate spec.contracts.ts --check-implementation
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### CI/CD Flow
|
|
130
|
+
```bash
|
|
131
|
+
# Fast validation in CI
|
|
132
|
+
contractspec validate '**/*.contracts.ts' --agent-mode simple
|
|
133
|
+
|
|
134
|
+
# Validate implementations (skip prompt)
|
|
135
|
+
contractspec validate '**/*.contracts.ts' --check-implementation
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Multi-Provider Strategy
|
|
139
|
+
```bash
|
|
140
|
+
# Draft with local model (free)
|
|
141
|
+
contractspec create --ai --provider ollama
|
|
142
|
+
|
|
143
|
+
# Build with Claude (quality)
|
|
144
|
+
contractspec build spec.ts --agent-mode claude-code
|
|
145
|
+
|
|
146
|
+
# Validate with OpenAI (cost-effective)
|
|
147
|
+
contractspec validate spec.ts --check-implementation --agent-mode openai-codex
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Troubleshooting
|
|
151
|
+
|
|
152
|
+
### AI Not Working
|
|
153
|
+
```bash
|
|
154
|
+
# Check API key
|
|
155
|
+
echo $ANTHROPIC_API_KEY
|
|
156
|
+
|
|
157
|
+
# Use simple mode as fallback
|
|
158
|
+
contractspec build spec.ts --agent-mode simple
|
|
159
|
+
|
|
160
|
+
# Disable AI completely
|
|
161
|
+
contractspec build spec.ts --no-agent
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Wrong Implementation Path
|
|
165
|
+
```bash
|
|
166
|
+
# Specify path explicitly
|
|
167
|
+
contractspec validate spec.contracts.ts \
|
|
168
|
+
--check-implementation \
|
|
169
|
+
--implementation-path ./custom/path/handler.ts
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Slow Generation
|
|
173
|
+
```bash
|
|
174
|
+
# Use faster agent mode
|
|
175
|
+
contractspec build spec.ts --agent-mode simple
|
|
176
|
+
|
|
177
|
+
# Skip tests
|
|
178
|
+
contractspec build spec.ts --no-tests
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Best Practices
|
|
182
|
+
|
|
183
|
+
✅ **DO:**
|
|
184
|
+
- Use `claude-code` for production implementations
|
|
185
|
+
- Validate with `--check-implementation` before committing
|
|
186
|
+
- Set agent mode in `.contractsrc.json` for consistency
|
|
187
|
+
- Use environment variables for API keys
|
|
188
|
+
|
|
189
|
+
❌ **DON'T:**
|
|
190
|
+
- Commit AI-generated code without review
|
|
191
|
+
- Use expensive agents in CI/CD unnecessarily
|
|
192
|
+
- Store API keys in `.contractsrc.json`
|
|
193
|
+
- Skip validation for critical code
|
|
194
|
+
|
|
195
|
+
## Performance Tips
|
|
196
|
+
|
|
197
|
+
| Task | Recommended Agent | Speed | Quality |
|
|
198
|
+
|------|------------------|-------|---------|
|
|
199
|
+
| Prototyping | simple | ⚡⚡⚡ | ⭐⭐⭐ |
|
|
200
|
+
| Production | claude-code | ⚡⚡ | ⭐⭐⭐⭐⭐ |
|
|
201
|
+
| Algorithms | openai-codex | ⚡⚡⚡ | ⭐⭐⭐⭐ |
|
|
202
|
+
| CI/CD | simple | ⚡⚡⚡ | ⭐⭐⭐ |
|
|
203
|
+
| Validation | claude-code | ⚡⚡ | ⭐⭐⭐⭐⭐ |
|
|
204
|
+
|
|
205
|
+
## More Information
|
|
206
|
+
|
|
207
|
+
- Full documentation: [README.md](./README.md)
|
|
208
|
+
- Agent modes guide: [AGENT_MODES.md](./AGENT_MODES.md)
|
|
209
|
+
- Quick start: [QUICK_START.md](./QUICK_START.md)
|
package/QUICK_START.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Quick Start Guide
|
|
2
|
+
|
|
3
|
+
Get started with contracts-cli in 5 minutes.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
cd packages/lssm/tools/contracts-cli
|
|
9
|
+
pnpm install
|
|
10
|
+
pnpm build
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## First Spec
|
|
14
|
+
|
|
15
|
+
### 1. Create a spec interactively
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm exec contractspec create
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Follow the prompts:
|
|
22
|
+
- Choose "Operation (Command/Query)"
|
|
23
|
+
- Select "Command"
|
|
24
|
+
- Name: `user.signup`
|
|
25
|
+
- Fill in description, goal, context
|
|
26
|
+
- Set auth to `anonymous`
|
|
27
|
+
- Add owners: `@team`
|
|
28
|
+
|
|
29
|
+
This creates: `src/interactions/commands/user-signup.contracts.ts`
|
|
30
|
+
|
|
31
|
+
### 2. Or use AI assistance
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
export ANTHROPIC_API_KEY=your-key-here
|
|
35
|
+
pnpm exec contractspec create --ai
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Describe what you want:
|
|
39
|
+
> "Create a command for user signup that takes an email and sends a magic link"
|
|
40
|
+
|
|
41
|
+
Review and accept the AI-generated spec!
|
|
42
|
+
|
|
43
|
+
### 3. Generate handler
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pnpm exec contractspec build src/interactions/commands/user-signup.contracts.ts
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This generates:
|
|
50
|
+
- `src/handlers/user-signup.handler.ts` - Implementation stub
|
|
51
|
+
- `src/handlers/user-signup.handler.test.ts` - Tests
|
|
52
|
+
|
|
53
|
+
### 4. Validate
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pnpm exec contractspec validate src/interactions/commands/user-signup.contracts.ts
|
|
57
|
+
# You'll be prompted to validate the spec only or the implementation as well.
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Using Local Models (Free!)
|
|
61
|
+
|
|
62
|
+
### Install Ollama
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# macOS
|
|
66
|
+
brew install ollama
|
|
67
|
+
|
|
68
|
+
# Start Ollama
|
|
69
|
+
ollama serve
|
|
70
|
+
|
|
71
|
+
# Pull a model
|
|
72
|
+
ollama pull codellama
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Generate with Ollama
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pnpm exec contractspec create --ai --provider ollama --model codellama
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
No API keys needed! Everything runs locally.
|
|
82
|
+
|
|
83
|
+
## Configuration
|
|
84
|
+
|
|
85
|
+
Create `.contractsrc.json` in your project root:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"aiProvider": "claude",
|
|
90
|
+
"outputDir": "./src",
|
|
91
|
+
"defaultOwners": ["@my-team"],
|
|
92
|
+
"conventions": {
|
|
93
|
+
"operations": "interactions/commands|queries",
|
|
94
|
+
"events": "events"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Now commands use these defaults:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Uses Claude from config
|
|
103
|
+
pnpm exec contractspec create --ai
|
|
104
|
+
|
|
105
|
+
# Override with Ollama
|
|
106
|
+
pnpm exec contractspec create --ai --provider ollama
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Next Steps
|
|
110
|
+
|
|
111
|
+
1. **Complete the TODO items** in generated files
|
|
112
|
+
2. **Implement handler logic** with real business rules
|
|
113
|
+
3. **Run tests**: `pnpm test`
|
|
114
|
+
4. **Validate**: `pnpm exec contractspec validate src/**/*.contracts.ts`
|
|
115
|
+
5. **Register in registry** and mount REST/GraphQL adapters
|
|
116
|
+
|
|
117
|
+
## Common Workflows
|
|
118
|
+
|
|
119
|
+
### Create Event
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
pnpm exec contractspec create --type event
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Build Presentation Component
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
pnpm exec contractspec create --type presentation
|
|
129
|
+
pnpm exec contractspec build src/presentations/user-profile.presentation.ts
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Multi-Spec Workflow
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
# Create operation spec
|
|
136
|
+
pnpm exec contractspec create --type operation --ai
|
|
137
|
+
|
|
138
|
+
# Create related event spec
|
|
139
|
+
pnpm exec contractspec create --type event --ai
|
|
140
|
+
|
|
141
|
+
# Generate all implementations
|
|
142
|
+
pnpm exec contractspec build src/contracts/**/*.ts
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Tips
|
|
146
|
+
|
|
147
|
+
- Use `--ai` for faster spec creation
|
|
148
|
+
- Use Ollama for free local generation
|
|
149
|
+
- Use Claude/GPT-4 for production-quality code
|
|
150
|
+
- Always validate before committing
|
|
151
|
+
- Keep specs close to implementations
|
|
152
|
+
|
|
153
|
+
## Troubleshooting
|
|
154
|
+
|
|
155
|
+
**No AI provider?**
|
|
156
|
+
```bash
|
|
157
|
+
# Use interactive wizard instead
|
|
158
|
+
pnpm exec contractspec create
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Can't find contractspec?**
|
|
162
|
+
```bash
|
|
163
|
+
# Use pnpm exec
|
|
164
|
+
pnpm exec contractspec --help
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Import errors?**
|
|
168
|
+
```bash
|
|
169
|
+
# Install dependencies
|
|
170
|
+
pnpm add @lssm/lib.contracts @lssm/lib.schema
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Happy contract authoring! 🎉
|
|
174
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,628 @@
|
|
|
1
|
+
ContractSpec
|
|
2
|
+
|
|
3
|
+
**Stabilize your AI-generated code** — Define contracts once, generate consistent code across API, DB, UI, and events. Safe regeneration. No lock-in.
|
|
4
|
+
|
|
5
|
+
CLI tool for creating, building, and validating contract specifications.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add -D contractspec
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Create a new contract spec interactively
|
|
17
|
+
contractspec create
|
|
18
|
+
|
|
19
|
+
# Create with AI assistance
|
|
20
|
+
contractspec create --ai
|
|
21
|
+
|
|
22
|
+
# Build implementation from spec
|
|
23
|
+
contractspec build src/contracts/mySpec.ts
|
|
24
|
+
|
|
25
|
+
# Validate a spec
|
|
26
|
+
contractspec validate src/contracts/mySpec.ts
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Commands
|
|
30
|
+
|
|
31
|
+
### `contractspec list`
|
|
32
|
+
|
|
33
|
+
List all contract specifications in the project with filtering options.
|
|
34
|
+
|
|
35
|
+
**Options:**
|
|
36
|
+
- `--pattern <pattern>` - File pattern to search (glob)
|
|
37
|
+
- `--deep` - Load spec modules to extract richer metadata (executes spec modules)
|
|
38
|
+
- `--type <type>` - Filter by spec type (operation, event, presentation, etc.)
|
|
39
|
+
- `--owner <owner>` - Filter by owner
|
|
40
|
+
- `--tag <tag>` - Filter by tag
|
|
41
|
+
- `--stability <level>` - Filter by stability (experimental, beta, stable, deprecated)
|
|
42
|
+
- `--json` - Output as JSON for scripting
|
|
43
|
+
|
|
44
|
+
**Examples:**
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# List all specs
|
|
48
|
+
contractspec list
|
|
49
|
+
|
|
50
|
+
# Filter by type and stability
|
|
51
|
+
contractspec list --type operation --stability stable
|
|
52
|
+
|
|
53
|
+
# Find specs by owner
|
|
54
|
+
contractspec list --owner @team-platform
|
|
55
|
+
|
|
56
|
+
# JSON output for scripting
|
|
57
|
+
contractspec list --json
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### `contractspec watch`
|
|
61
|
+
|
|
62
|
+
Watch contract specifications and auto-regenerate on changes.
|
|
63
|
+
|
|
64
|
+
**Options:**
|
|
65
|
+
- `--pattern <pattern>` - File pattern to watch (default: `**/*.contracts.ts`)
|
|
66
|
+
- `--build` - Auto-run build command on changes
|
|
67
|
+
- `--validate` - Auto-run validate command on changes
|
|
68
|
+
- `--on-start <mode>` - Run action on startup: none|validate|build|both (default: none)
|
|
69
|
+
- `--continue-on-error` - Do not exit on build/validate errors
|
|
70
|
+
- `--debounce <ms>` - Debounce delay in milliseconds (default: 500)
|
|
71
|
+
|
|
72
|
+
**Examples:**
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Watch for changes and auto-build
|
|
76
|
+
contractspec watch --build
|
|
77
|
+
|
|
78
|
+
# Watch and auto-validate
|
|
79
|
+
contractspec watch --validate
|
|
80
|
+
|
|
81
|
+
# Custom pattern and debounce
|
|
82
|
+
contractspec watch --pattern 'src/**/*.ts' --debounce 1000
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### `contractspec sync`
|
|
86
|
+
|
|
87
|
+
Sync contracts by building all discovered specs.
|
|
88
|
+
|
|
89
|
+
**Options:**
|
|
90
|
+
- `--pattern <pattern>` - File pattern to search (glob)
|
|
91
|
+
- `--buckets <buckets>` - Optional output buckets (comma-separated). Builds repeat into `./generated/<bucket>/`
|
|
92
|
+
- `--surfaces <surfaces>` - (deprecated) Alias for `--buckets`
|
|
93
|
+
- `--validate` - Validate each spec before building (spec-only)
|
|
94
|
+
- `--dry-run` - Show what would be synced without making changes
|
|
95
|
+
|
|
96
|
+
**Examples:**
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# Sync all surfaces
|
|
100
|
+
contractspec sync
|
|
101
|
+
|
|
102
|
+
# Sync specific surfaces
|
|
103
|
+
contractspec sync --surfaces api,ui
|
|
104
|
+
|
|
105
|
+
# Preview changes
|
|
106
|
+
contractspec sync --dry-run
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### `contractspec clean`
|
|
110
|
+
|
|
111
|
+
Clean generated files and build artifacts.
|
|
112
|
+
|
|
113
|
+
**Options:**
|
|
114
|
+
- `--dry-run` - Show what would be deleted without deleting
|
|
115
|
+
- `--generated-only` - Only clean generated directories (generated/, dist/, .turbo/, outputDir artifacts)
|
|
116
|
+
- `--older-than <days>` - Only clean files older than specified days
|
|
117
|
+
- `--force` - Skip confirmation prompts
|
|
118
|
+
- `--git-clean` - Use `git clean -fdx` for comprehensive cleanup (requires confirmation or `--force`)
|
|
119
|
+
|
|
120
|
+
**Examples:**
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
# Clean all generated files
|
|
124
|
+
contractspec clean
|
|
125
|
+
|
|
126
|
+
# Preview cleanup
|
|
127
|
+
contractspec clean --dry-run
|
|
128
|
+
|
|
129
|
+
# Clean only old files
|
|
130
|
+
contractspec clean --older-than 30
|
|
131
|
+
|
|
132
|
+
# Use git clean
|
|
133
|
+
contractspec clean --git-clean
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### `contractspec deps`
|
|
137
|
+
|
|
138
|
+
Analyze contract dependencies and relationships.
|
|
139
|
+
|
|
140
|
+
**Options:**
|
|
141
|
+
- `--pattern <pattern>` - File pattern to search (glob)
|
|
142
|
+
- `--entry <name>` - Focus on a specific contract name
|
|
143
|
+
- `--format <format>` - text|json|dot (default: text)
|
|
144
|
+
- `--graph` - (deprecated) Same as `--format dot`
|
|
145
|
+
- `--circular` - Find circular dependencies
|
|
146
|
+
- `--missing` - Find missing dependencies
|
|
147
|
+
- `--json` - (deprecated) Same as `--format json`
|
|
148
|
+
|
|
149
|
+
**Examples:**
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# Show dependency overview
|
|
153
|
+
contractspec deps
|
|
154
|
+
|
|
155
|
+
# Analyze specific contract
|
|
156
|
+
contractspec deps --entry user.signup
|
|
157
|
+
|
|
158
|
+
# Find circular dependencies
|
|
159
|
+
contractspec deps --circular
|
|
160
|
+
|
|
161
|
+
# Generate graphviz graph
|
|
162
|
+
contractspec deps --format dot > deps.dot
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### `contractspec diff`
|
|
166
|
+
|
|
167
|
+
Compare contract specifications and show differences.
|
|
168
|
+
|
|
169
|
+
**Arguments:**
|
|
170
|
+
- `<spec1> <spec2>` - Two spec files to compare
|
|
171
|
+
|
|
172
|
+
**Options:**
|
|
173
|
+
- `--breaking` - Only show breaking changes
|
|
174
|
+
- `--semantic` - Show semantic differences (not just text)
|
|
175
|
+
- `--json` - Output as JSON for scripting
|
|
176
|
+
- `--baseline <ref>` - Compare with git reference (branch/commit)
|
|
177
|
+
|
|
178
|
+
**Examples:**
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
# Compare two specs
|
|
182
|
+
contractspec diff spec1.ts spec2.ts
|
|
183
|
+
|
|
184
|
+
# Compare with git branch
|
|
185
|
+
contractspec diff spec.ts spec.ts --baseline main
|
|
186
|
+
|
|
187
|
+
# Show only breaking changes
|
|
188
|
+
contractspec diff spec1.ts spec2.ts --breaking
|
|
189
|
+
|
|
190
|
+
# Semantic comparison
|
|
191
|
+
contractspec diff spec1.ts spec2.ts --semantic
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### `contractspec create`
|
|
195
|
+
|
|
196
|
+
Interactive wizard to create contract specifications.
|
|
197
|
+
|
|
198
|
+
**Options:**
|
|
199
|
+
- `--type <type>` - Spec type: operation, event, presentation, form, feature
|
|
200
|
+
- `--ai` - Use AI to generate spec from description
|
|
201
|
+
- `--provider <provider>` - AI provider: claude, openai, ollama, custom
|
|
202
|
+
- `--model <model>` - AI model to use
|
|
203
|
+
|
|
204
|
+
**Examples:**
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
# Interactive wizard
|
|
208
|
+
contractspec create
|
|
209
|
+
|
|
210
|
+
# Create operation spec with AI
|
|
211
|
+
contractspec create --type operation --ai
|
|
212
|
+
|
|
213
|
+
# Use local Ollama model
|
|
214
|
+
contractspec create --ai --provider ollama --model codellama
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### `contractspec build`
|
|
218
|
+
|
|
219
|
+
Generate implementation code from contract specs using AI agents with automatic fallbacks.
|
|
220
|
+
|
|
221
|
+
**Options:**
|
|
222
|
+
- `--output-dir <dir>` - Output directory (default: ./generated)
|
|
223
|
+
- `--provider <provider>` - AI provider: claude, openai, ollama, custom
|
|
224
|
+
- `--model <model>` - AI model to use
|
|
225
|
+
- `--agent-mode <mode>` - Agent mode: simple, cursor, claude-code, openai-codex
|
|
226
|
+
- `--no-tests` - Skip test generation
|
|
227
|
+
- `--no-agent` - Disable AI (use basic templates)
|
|
228
|
+
|
|
229
|
+
> ℹ️ The build command automatically orchestrates between the selected agent and lightweight templates. If an agent becomes unavailable (missing API key, Cursor not running, etc.) the CLI falls back to deterministic templates so the build never blocks.
|
|
230
|
+
|
|
231
|
+
**Examples:**
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
# Generate handler from operation spec (default: simple agent)
|
|
235
|
+
contractspec build src/contracts/signup.contracts.ts
|
|
236
|
+
|
|
237
|
+
# Use Claude Code agent for high-quality production code
|
|
238
|
+
contractspec build src/contracts/signup.contracts.ts --agent-mode claude-code
|
|
239
|
+
|
|
240
|
+
# Use OpenAI Codex for algorithmic implementations
|
|
241
|
+
contractspec build src/contracts/optimizer.contracts.ts --agent-mode openai-codex
|
|
242
|
+
|
|
243
|
+
# Generate without AI (basic templates only)
|
|
244
|
+
contractspec build src/contracts/simple.contracts.ts --no-agent
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### `contractspec validate`
|
|
248
|
+
|
|
249
|
+
Validate contract specifications and optionally verify implementations against specs using AI.
|
|
250
|
+
|
|
251
|
+
**Options:**
|
|
252
|
+
- `--check-implementation` - Validate implementation against spec using AI
|
|
253
|
+
- `--implementation-path <path>` - Path to implementation (auto-detected if not specified)
|
|
254
|
+
- `--agent-mode <mode>` - Agent mode for validation: simple, claude-code, openai-codex
|
|
255
|
+
- `--check-handlers` - Verify handler implementations exist
|
|
256
|
+
- `--check-tests` - Verify test coverage
|
|
257
|
+
- `-i, --interactive` - Interactive mode - prompt for what to validate
|
|
258
|
+
|
|
259
|
+
> ℹ️ When no validation scope is provided, the CLI prompts you to choose between spec-only validation or full spec + implementation validation. In non-interactive environments it defaults to spec-only. Use `--check-implementation` to skip the prompt.
|
|
260
|
+
|
|
261
|
+
**Examples:**
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
# Validate spec structure only
|
|
265
|
+
contractspec validate src/contracts/signup.contracts.ts
|
|
266
|
+
|
|
267
|
+
# Validate implementation against spec with AI
|
|
268
|
+
contractspec validate src/contracts/signup.contracts.ts --check-implementation
|
|
269
|
+
|
|
270
|
+
# Interactive validation with Claude Code agent
|
|
271
|
+
contractspec validate src/contracts/signup.contracts.ts -i --agent-mode claude-code
|
|
272
|
+
|
|
273
|
+
# Validate specific implementation file
|
|
274
|
+
contractspec validate src/contracts/signup.contracts.ts \
|
|
275
|
+
--check-implementation \
|
|
276
|
+
--implementation-path src/handlers/signup.handler.ts \
|
|
277
|
+
--agent-mode claude-code
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### `contractspec ci`
|
|
281
|
+
|
|
282
|
+
Run all validation checks for CI/CD pipelines with machine-readable output formats.
|
|
283
|
+
|
|
284
|
+
**Options:**
|
|
285
|
+
- `--pattern <glob>` - Glob pattern for spec discovery
|
|
286
|
+
- `--format <format>` - Output format: text, json, sarif (default: text)
|
|
287
|
+
- `--output <file>` - Write results to file
|
|
288
|
+
- `--fail-on-warnings` - Exit with code 2 on warnings
|
|
289
|
+
- `--skip <checks>` - Skip specific checks (comma-separated)
|
|
290
|
+
- `--checks <checks>` - Only run specific checks (comma-separated)
|
|
291
|
+
- `--check-handlers` - Include handler implementation checks
|
|
292
|
+
- `--check-tests` - Include test coverage checks
|
|
293
|
+
- `--verbose` - Verbose output
|
|
294
|
+
|
|
295
|
+
**Available Checks:**
|
|
296
|
+
- `structure` - Spec structure validation (meta, io, policy)
|
|
297
|
+
- `integrity` - Contract integrity (orphaned specs, broken refs)
|
|
298
|
+
- `deps` - Dependency analysis (circular deps, missing refs)
|
|
299
|
+
- `doctor` - Installation health (skips AI in CI)
|
|
300
|
+
- `handlers` - Handler implementation existence
|
|
301
|
+
- `tests` - Test file existence
|
|
302
|
+
|
|
303
|
+
**Exit Codes:**
|
|
304
|
+
- `0` - All checks passed
|
|
305
|
+
- `1` - Errors found
|
|
306
|
+
- `2` - Warnings found (with `--fail-on-warnings`)
|
|
307
|
+
|
|
308
|
+
**Examples:**
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
# Run all CI checks
|
|
312
|
+
contractspec ci
|
|
313
|
+
|
|
314
|
+
# Output as JSON for parsing
|
|
315
|
+
contractspec ci --format json
|
|
316
|
+
|
|
317
|
+
# Output SARIF for GitHub Code Scanning
|
|
318
|
+
contractspec ci --format sarif --output results.sarif
|
|
319
|
+
|
|
320
|
+
# Skip doctor checks
|
|
321
|
+
contractspec ci --skip doctor
|
|
322
|
+
|
|
323
|
+
# Run only structure and integrity checks
|
|
324
|
+
contractspec ci --checks structure,integrity
|
|
325
|
+
|
|
326
|
+
# Fail on warnings
|
|
327
|
+
contractspec ci --fail-on-warnings
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
For comprehensive CI/CD integration guides (GitHub Actions, GitLab CI, Jenkins, AWS CodeBuild, etc.), see [docs/ci-cd.md](./docs/ci-cd.md).
|
|
331
|
+
|
|
332
|
+
## Configuration
|
|
333
|
+
|
|
334
|
+
Create a `.contractsrc.json` file in your project root:
|
|
335
|
+
|
|
336
|
+
```json
|
|
337
|
+
{
|
|
338
|
+
"aiProvider": "claude",
|
|
339
|
+
"aiModel": "claude-3-7-sonnet-20250219",
|
|
340
|
+
"agentMode": "claude-code",
|
|
341
|
+
"outputDir": "./src",
|
|
342
|
+
"conventions": {
|
|
343
|
+
"operations": "interactions/commands|queries",
|
|
344
|
+
"events": "events",
|
|
345
|
+
"presentations": "presentations",
|
|
346
|
+
"forms": "forms"
|
|
347
|
+
},
|
|
348
|
+
"defaultOwners": ["@team"],
|
|
349
|
+
"defaultTags": ["auto-generated"]
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### Agent Modes
|
|
354
|
+
|
|
355
|
+
The CLI supports multiple AI agent modes for different use cases:
|
|
356
|
+
|
|
357
|
+
- **simple** (default) - Direct LLM API calls, fast and straightforward
|
|
358
|
+
- **cursor** - Leverages Windsurf/Cursor agentic capabilities (requires Cursor environment)
|
|
359
|
+
- **claude-code** - Uses Claude with extended thinking, best for production code and validation
|
|
360
|
+
- **openai-codex** - Uses GPT-4o/o1 models, excellent for algorithms and optimization
|
|
361
|
+
|
|
362
|
+
See [AGENT_MODES.md](./AGENT_MODES.md) for detailed comparison and usage guide.
|
|
363
|
+
|
|
364
|
+
### AI Providers
|
|
365
|
+
|
|
366
|
+
#### Claude (Anthropic)
|
|
367
|
+
|
|
368
|
+
```bash
|
|
369
|
+
export ANTHROPIC_API_KEY=your-key-here
|
|
370
|
+
contractspec create --ai --provider claude
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
#### OpenAI
|
|
374
|
+
|
|
375
|
+
```bash
|
|
376
|
+
export OPENAI_API_KEY=your-key-here
|
|
377
|
+
contractspec create --ai --provider openai --model gpt-4o
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
#### Ollama (Local)
|
|
381
|
+
|
|
382
|
+
Install Ollama and pull a model:
|
|
383
|
+
|
|
384
|
+
```bash
|
|
385
|
+
ollama pull codellama
|
|
386
|
+
contractspec create --ai --provider ollama --model codellama
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
#### Custom OpenAI-Compatible Endpoint
|
|
390
|
+
|
|
391
|
+
```bash
|
|
392
|
+
contractspec create --ai --provider custom \
|
|
393
|
+
--endpoint https://your-llm.com/v1 \
|
|
394
|
+
--model your-model-name
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
Set via environment:
|
|
398
|
+
|
|
399
|
+
```bash
|
|
400
|
+
export CONTRACTSPEC_LLM_ENDPOINT=https://your-llm.com/v1
|
|
401
|
+
export CONTRACTSPEC_LLM_API_KEY=your-key
|
|
402
|
+
export CONTRACTSPEC_LLM_MODEL=your-model
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
### Supported Local Models (Ollama)
|
|
406
|
+
|
|
407
|
+
- `codellama` - Code generation (recommended)
|
|
408
|
+
- `llama3.1` - General purpose
|
|
409
|
+
- `mistral` - Fast, good quality
|
|
410
|
+
- `deepseek-coder` - Specialized for code
|
|
411
|
+
|
|
412
|
+
## Examples
|
|
413
|
+
|
|
414
|
+
### Create a Command Spec
|
|
415
|
+
|
|
416
|
+
```bash
|
|
417
|
+
contractspec create --type operation
|
|
418
|
+
# Follow prompts:
|
|
419
|
+
# - Name: user.signup
|
|
420
|
+
# - Kind: command
|
|
421
|
+
# - Description: Start user signup flow
|
|
422
|
+
# etc.
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
### Build Handler from Spec
|
|
426
|
+
|
|
427
|
+
Given a spec file `src/contracts/signup.contracts.ts`:
|
|
428
|
+
|
|
429
|
+
```bash
|
|
430
|
+
contractspec build src/contracts/signup.contracts.ts
|
|
431
|
+
# Generates:
|
|
432
|
+
# - src/handlers/signup.handler.ts
|
|
433
|
+
# - src/handlers/signup.handler.test.ts
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### Multi-Provider Workflow
|
|
437
|
+
|
|
438
|
+
```bash
|
|
439
|
+
# Draft with free local model
|
|
440
|
+
contractspec create --ai --provider ollama
|
|
441
|
+
|
|
442
|
+
# Refine with Claude for production
|
|
443
|
+
contractspec build src/contracts/draft.ts --provider claude
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
## Advanced Usage
|
|
447
|
+
|
|
448
|
+
### Multi-Provider and Multi-Agent Workflows
|
|
449
|
+
|
|
450
|
+
Combine different providers and agents for optimal results:
|
|
451
|
+
|
|
452
|
+
```bash
|
|
453
|
+
# Draft specs with free local model
|
|
454
|
+
contractspec create --ai --provider ollama --model codellama
|
|
455
|
+
|
|
456
|
+
# Generate production code with Claude Code agent
|
|
457
|
+
contractspec build src/contracts/user-signup.contracts.ts \
|
|
458
|
+
--agent-mode claude-code
|
|
459
|
+
|
|
460
|
+
# Validate implementation with AI
|
|
461
|
+
contractspec validate src/contracts/user-signup.contracts.ts \
|
|
462
|
+
--check-implementation \
|
|
463
|
+
--agent-mode claude-code
|
|
464
|
+
|
|
465
|
+
# Use OpenAI for algorithmic code
|
|
466
|
+
contractspec build src/contracts/search-algorithm.contracts.ts \
|
|
467
|
+
--agent-mode openai-codex
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
### Environment Variables
|
|
471
|
+
|
|
472
|
+
```bash
|
|
473
|
+
# API Keys
|
|
474
|
+
export ANTHROPIC_API_KEY=your-key-here
|
|
475
|
+
export OPENAI_API_KEY=your-key-here
|
|
476
|
+
|
|
477
|
+
# Agent configuration
|
|
478
|
+
export CONTRACTSPEC_AGENT_MODE=claude-code
|
|
479
|
+
export CONTRACTSPEC_AI_PROVIDER=claude
|
|
480
|
+
export CONTRACTSPEC_AI_MODEL=claude-3-7-sonnet-20250219
|
|
481
|
+
|
|
482
|
+
# Custom provider
|
|
483
|
+
export CONTRACTSPEC_LLM_ENDPOINT=https://your-llm.com/v1
|
|
484
|
+
export CONTRACTSPEC_LLM_API_KEY=your-api-key
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
### CI/CD Integration
|
|
488
|
+
|
|
489
|
+
```yaml
|
|
490
|
+
# .github/workflows/contracts.yml
|
|
491
|
+
name: Validate Contracts
|
|
492
|
+
|
|
493
|
+
on: [push, pull_request]
|
|
494
|
+
|
|
495
|
+
jobs:
|
|
496
|
+
validate:
|
|
497
|
+
runs-on: ubuntu-latest
|
|
498
|
+
steps:
|
|
499
|
+
- uses: actions/checkout@v3
|
|
500
|
+
- uses: oven-sh/setup-bun@v1
|
|
501
|
+
- run: pnpm install
|
|
502
|
+
- run: contractspec validate 'src/contracts/**/*.ts'
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
### Project Structure
|
|
506
|
+
|
|
507
|
+
Recommended organization:
|
|
508
|
+
|
|
509
|
+
```
|
|
510
|
+
src/
|
|
511
|
+
├── contracts/ # Contract specs
|
|
512
|
+
│ ├── events/
|
|
513
|
+
│ │ └── user-created.event.ts
|
|
514
|
+
│ ├── interactions/
|
|
515
|
+
│ │ ├── commands/
|
|
516
|
+
│ │ │ └── user-signup.contracts.ts
|
|
517
|
+
│ │ └── queries/
|
|
518
|
+
│ │ └── user-get-profile.contracts.ts
|
|
519
|
+
│ └── presentations/
|
|
520
|
+
│ └── user-profile-card.presentation.ts
|
|
521
|
+
├── handlers/ # Generated handlers
|
|
522
|
+
├── components/ # Generated components
|
|
523
|
+
└── forms/ # Generated forms
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
## Troubleshooting
|
|
527
|
+
|
|
528
|
+
### "Provider not available" error
|
|
529
|
+
|
|
530
|
+
**Claude:**
|
|
531
|
+
```bash
|
|
532
|
+
export ANTHROPIC_API_KEY=sk-ant-...
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
**OpenAI:**
|
|
536
|
+
```bash
|
|
537
|
+
export OPENAI_API_KEY=sk-...
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
**Ollama:**
|
|
541
|
+
```bash
|
|
542
|
+
# Install Ollama from https://ollama.ai
|
|
543
|
+
ollama serve
|
|
544
|
+
ollama pull codellama
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
### Slow generation
|
|
548
|
+
|
|
549
|
+
For faster local generation, use smaller models:
|
|
550
|
+
```bash
|
|
551
|
+
contractspec create --ai --provider ollama --model codellama:7b
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
For cloud, use faster models:
|
|
555
|
+
```bash
|
|
556
|
+
contractspec build spec.ts --provider openai --model gpt-3.5-turbo
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
### Import errors in generated code
|
|
560
|
+
|
|
561
|
+
Make sure `@lssm/lib.contracts` and `@lssm/lib.schema` are installed:
|
|
562
|
+
```bash
|
|
563
|
+
pnpm add @lssm/lib.contracts @lssm/lib.schema
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
## Contributing
|
|
567
|
+
|
|
568
|
+
Contributions welcome! Please:
|
|
569
|
+
|
|
570
|
+
1. Follow existing code style
|
|
571
|
+
2. Add tests for new features
|
|
572
|
+
3. Update documentation
|
|
573
|
+
4. Ensure all tests pass: `pnpm test`
|
|
574
|
+
|
|
575
|
+
## Agent Modes Deep Dive
|
|
576
|
+
|
|
577
|
+
### When to Use Each Mode
|
|
578
|
+
|
|
579
|
+
**Simple Mode** - Default, good for:
|
|
580
|
+
- Rapid prototyping
|
|
581
|
+
- Basic implementations
|
|
582
|
+
- Quick iterations
|
|
583
|
+
- CI/CD pipelines (fast)
|
|
584
|
+
|
|
585
|
+
**Cursor Mode** - Best for:
|
|
586
|
+
- Working in Windsurf/Cursor IDE
|
|
587
|
+
- Complex, iterative development
|
|
588
|
+
- Context-aware code generation
|
|
589
|
+
|
|
590
|
+
**Claude Code Mode** - Best for:
|
|
591
|
+
- Production-quality implementations
|
|
592
|
+
- Critical business logic
|
|
593
|
+
- Comprehensive code validation
|
|
594
|
+
- Detailed code reviews
|
|
595
|
+
|
|
596
|
+
**OpenAI Codex Mode** - Best for:
|
|
597
|
+
- Algorithmic problems
|
|
598
|
+
- Performance optimization
|
|
599
|
+
- Mathematical computations
|
|
600
|
+
- Complex data transformations
|
|
601
|
+
|
|
602
|
+
For more details, see [AGENT_MODES.md](./AGENT_MODES.md).
|
|
603
|
+
|
|
604
|
+
## Roadmap
|
|
605
|
+
|
|
606
|
+
- [x] AI-powered code generation
|
|
607
|
+
- [x] Multiple agent modes (simple, cursor, claude-code, openai-codex)
|
|
608
|
+
- [x] AI-powered implementation validation
|
|
609
|
+
- [x] Contract listing and discovery (`contractspec list`)
|
|
610
|
+
- [x] Watch mode for auto-regeneration (`contractspec watch`)
|
|
611
|
+
- [x] Multi-surface synchronization (`contractspec sync`)
|
|
612
|
+
- [x] Cleanup utilities (`contractspec clean`)
|
|
613
|
+
- [x] Dependency analysis (`contractspec deps`)
|
|
614
|
+
- [x] Contract diffing and comparison (`contractspec diff`)
|
|
615
|
+
- [x] CI/CD integration (`contractspec ci`) with SARIF/JSON output
|
|
616
|
+
- [x] GitHub Action for CI/CD
|
|
617
|
+
- [ ] Form spec generation
|
|
618
|
+
- [ ] Feature spec bundling
|
|
619
|
+
- [ ] Handler signature checking in validation
|
|
620
|
+
- [ ] Test coverage validation
|
|
621
|
+
- [ ] Interactive spec editing
|
|
622
|
+
- [ ] GraphQL schema generation
|
|
623
|
+
- [ ] OpenAPI/Swagger export
|
|
624
|
+
|
|
625
|
+
## License
|
|
626
|
+
|
|
627
|
+
MIT
|
|
628
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "spec-driven-development",
|
|
3
|
+
"version": "0.0.0-canary-20251223010757",
|
|
4
|
+
"description": "CLI tool for creating, building, and validating contract specifications",
|
|
5
|
+
"bin": {
|
|
6
|
+
"sdd": "./bin/contractspec.mjs"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@lssm/app.cli-contractspec": "0.0.0-canary-20251223010757"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
|
|
13
|
+
"publish:pkg:canary": "bun publish:pkg --tag canary"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"cli",
|
|
17
|
+
"contracts",
|
|
18
|
+
"code-generation",
|
|
19
|
+
"ai",
|
|
20
|
+
"typescript"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"name": "contractspec",
|
|
24
|
+
"access": "public",
|
|
25
|
+
"registry": "https://registry.npmjs.org/"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/lssm-tech/contractspec.git",
|
|
31
|
+
"directory": "packages/apps/contractspec"
|
|
32
|
+
}
|
|
33
|
+
}
|