@lssm/app.cli-contractspec 0.0.0-canary-20251221164004
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/.contractsrc.example.json +25 -0
- package/AGENTS.md +102 -0
- package/AGENT_MODES.md +247 -0
- package/CHANGELOG.md +277 -0
- package/LICENSE +21 -0
- package/QUICK_REFERENCE.md +209 -0
- package/QUICK_START.md +174 -0
- package/README.md +628 -0
- package/contractsrc.schema.json +208 -0
- package/dist/cli.js +7521 -0
- package/docs/ci-cd.md +598 -0
- package/package.json +72 -0
|
@@ -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
|
+
|