@nolans01/agent-validator 0.1.0
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/README.md +299 -0
- package/dist/cli.js +1899 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.js +1804 -0
- package/dist/index.js.map +1 -0
- package/package.json +72 -0
package/README.md
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
# agent-validator
|
|
2
|
+
|
|
3
|
+
Deterministic code quality validation orchestrator for TypeScript, Python, and Ruby projects. Designed for AI coding agents to validate their generated code against measurable metrics.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **5 Quality Gates**: type safety, complexity, security, architecture, test quality (mutation testing)
|
|
8
|
+
- **Multi-language**: TypeScript/JavaScript, Python, Ruby
|
|
9
|
+
- **Deterministic**: No LLM-based analysis — only measurable, reproducible metrics
|
|
10
|
+
- **Composable**: Use all gates or cherry-pick specific checks
|
|
11
|
+
- **Profiles**: Pre-configured thresholds (default, critical, prototype)
|
|
12
|
+
- **Fail-fast**: Gates ordered by speed; expensive checks run last
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g @nolans01/agent-validator
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or as a dev dependency in your project:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install --save-dev @nolans01/agent-validator
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## External Tools
|
|
27
|
+
|
|
28
|
+
agent-validator orchestrates external tools. Install the ones you need:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Type Safety
|
|
32
|
+
npm install -g typescript # for TypeScript projects
|
|
33
|
+
pip install mypy # for Python projects
|
|
34
|
+
|
|
35
|
+
# Complexity
|
|
36
|
+
pip install lizard
|
|
37
|
+
|
|
38
|
+
# Security
|
|
39
|
+
pip install semgrep
|
|
40
|
+
brew install gitleaks # or: https://github.com/gitleaks/gitleaks
|
|
41
|
+
|
|
42
|
+
# Architecture
|
|
43
|
+
npm install -g madge jscpd knip
|
|
44
|
+
|
|
45
|
+
# Test Quality (Mutation Testing)
|
|
46
|
+
npm install -D @stryker-mutator/core # for TypeScript/JavaScript
|
|
47
|
+
pip install mutmut # for Python
|
|
48
|
+
gem install mutant mutant-rspec # for Ruby
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Check which tools are available:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
validator doctor
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Quick Start
|
|
58
|
+
|
|
59
|
+
### CLI Usage
|
|
60
|
+
|
|
61
|
+
Scan entire project:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
validator scan
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Analyze specific files:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
validator files src/index.ts src/utils.ts
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Analyze git diff:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
validator diff --base main --head HEAD
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Run specific gates only:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
validator scan --gates complexity,security
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Use a stricter profile:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
validator scan --profile critical
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
JSON output for CI:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
validator scan --format json
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Fail on warnings (default: fail on blockers only):
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
validator scan --fail-on warning
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Programmatic API (TypeScript/JavaScript)
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { validate } from '@nolans01/agent-validator';
|
|
107
|
+
|
|
108
|
+
const report = await validate({
|
|
109
|
+
mode: 'scan',
|
|
110
|
+
profile: 'default',
|
|
111
|
+
gates: ['complexity', 'security'],
|
|
112
|
+
workdir: process.cwd(),
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
console.log(`Status: ${report.status}`);
|
|
116
|
+
console.log(`Blockers: ${report.blockers}`);
|
|
117
|
+
console.log(`Warnings: ${report.warnings}`);
|
|
118
|
+
|
|
119
|
+
// Access detailed results
|
|
120
|
+
for (const gate of report.gates) {
|
|
121
|
+
console.log(`${gate.gate}: ${gate.status} (${gate.score}%)`);
|
|
122
|
+
for (const finding of gate.findings) {
|
|
123
|
+
console.log(` ${finding.file}:${finding.line} [${finding.severity}] ${finding.message}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Python Integration
|
|
129
|
+
|
|
130
|
+
Create a shell wrapper or use subprocess:
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
import subprocess
|
|
134
|
+
import json
|
|
135
|
+
|
|
136
|
+
result = subprocess.run(
|
|
137
|
+
['validator', 'scan', '--format', 'json'],
|
|
138
|
+
capture_output=True,
|
|
139
|
+
text=True
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
report = json.loads(result.stdout)
|
|
143
|
+
if report['status'] == 'fail':
|
|
144
|
+
print(f"Validation failed: {report['blockers']} blockers")
|
|
145
|
+
exit(1)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Ruby Integration
|
|
149
|
+
|
|
150
|
+
```ruby
|
|
151
|
+
require 'json'
|
|
152
|
+
|
|
153
|
+
output = `validator scan --format json`
|
|
154
|
+
report = JSON.parse(output)
|
|
155
|
+
|
|
156
|
+
if report['status'] == 'fail'
|
|
157
|
+
puts "Validation failed: #{report['blockers']} blockers"
|
|
158
|
+
exit 1
|
|
159
|
+
end
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Quality Gates
|
|
163
|
+
|
|
164
|
+
### 1. Type Safety Gate
|
|
165
|
+
- **TypeScript**: `tsc --noEmit`
|
|
166
|
+
- **Python**: `mypy`
|
|
167
|
+
- **Scoring**: -10 per blocker, -5 per warning, -2 per info
|
|
168
|
+
- **Fail threshold**: score < 70
|
|
169
|
+
|
|
170
|
+
### 2. Complexity Gate
|
|
171
|
+
- **Tool**: `lizard`
|
|
172
|
+
- **Metrics**: cyclomatic complexity, function length, parameter count, nesting depth
|
|
173
|
+
- **Scoring**: ratio of clean functions to total functions
|
|
174
|
+
- **Fail threshold**: score < 70 OR any blocker (CCN > 1.5× threshold)
|
|
175
|
+
|
|
176
|
+
### 3. Security Gate
|
|
177
|
+
- **Tools**: `semgrep` (SAST), `gitleaks` (secret detection)
|
|
178
|
+
- **Scoring**: -25 per blocker, -10 per warning, -3 per info
|
|
179
|
+
- **Fail threshold**: score < 70 OR any blocker
|
|
180
|
+
|
|
181
|
+
### 4. Architecture Gate
|
|
182
|
+
- **Tools**: `madge` (circular deps), `jscpd` (duplication), `knip` (dead code)
|
|
183
|
+
- **Scoring**: -15 per blocker, -7 per warning, -3 per info
|
|
184
|
+
- **Fail threshold**: score < 70 OR any blocker
|
|
185
|
+
|
|
186
|
+
### 5. Test Quality Gate (Mutation Testing)
|
|
187
|
+
- **TypeScript/JavaScript**: `stryker`
|
|
188
|
+
- **Python**: `mutmut`
|
|
189
|
+
- **Ruby**: `mutant`
|
|
190
|
+
- **Scoring**: mutation score (% of killed mutants)
|
|
191
|
+
- **Fail threshold**: score < 70
|
|
192
|
+
|
|
193
|
+
## Profiles
|
|
194
|
+
|
|
195
|
+
### default
|
|
196
|
+
Balanced thresholds for production code:
|
|
197
|
+
- Cyclomatic: 10, Length: 40, Arguments: 4
|
|
198
|
+
- Mutation score: 80%
|
|
199
|
+
|
|
200
|
+
### critical
|
|
201
|
+
Strict thresholds for critical systems:
|
|
202
|
+
- Cyclomatic: 6, Length: 30, Arguments: 3
|
|
203
|
+
- Mutation score: 90%
|
|
204
|
+
- All gates enabled with stricter limits
|
|
205
|
+
|
|
206
|
+
### prototype
|
|
207
|
+
Relaxed thresholds for prototyping:
|
|
208
|
+
- Cyclomatic: 15, Length: 60, Arguments: 6
|
|
209
|
+
- Mutation score: 60%
|
|
210
|
+
- Mutation testing disabled (expensive)
|
|
211
|
+
|
|
212
|
+
## Configuration
|
|
213
|
+
|
|
214
|
+
Create a `validator.config.json` in your project root (future support planned):
|
|
215
|
+
|
|
216
|
+
```json
|
|
217
|
+
{
|
|
218
|
+
"profile": "default",
|
|
219
|
+
"gates": ["type_safety", "complexity", "security"],
|
|
220
|
+
"exclude": ["**/test/**", "**/fixtures/**"]
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Currently, use CLI flags or programmatic API to configure.
|
|
225
|
+
|
|
226
|
+
## CI Integration
|
|
227
|
+
|
|
228
|
+
### GitHub Actions
|
|
229
|
+
|
|
230
|
+
```yaml
|
|
231
|
+
- name: Validate Code Quality
|
|
232
|
+
run: |
|
|
233
|
+
npm install -g @nolans01/agent-validator
|
|
234
|
+
pip install lizard semgrep mypy
|
|
235
|
+
validator scan --format json --fail-on blocker
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### GitLab CI
|
|
239
|
+
|
|
240
|
+
```yaml
|
|
241
|
+
validate:
|
|
242
|
+
script:
|
|
243
|
+
- npm install -g @nolans01/agent-validator
|
|
244
|
+
- pip install lizard semgrep mypy
|
|
245
|
+
- validator scan --fail-on blocker
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Exit Codes
|
|
249
|
+
|
|
250
|
+
- `0`: Validation passed
|
|
251
|
+
- `1`: Validation failed (based on `--fail-on` level)
|
|
252
|
+
|
|
253
|
+
## Development
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
# Clone the repo
|
|
257
|
+
git clone https://github.com/NolanS-OMG/agent-validator
|
|
258
|
+
cd agent-validator
|
|
259
|
+
|
|
260
|
+
# Install dependencies
|
|
261
|
+
npm install
|
|
262
|
+
|
|
263
|
+
# Run tests
|
|
264
|
+
npm test
|
|
265
|
+
|
|
266
|
+
# Build
|
|
267
|
+
npm run build
|
|
268
|
+
|
|
269
|
+
# Test locally
|
|
270
|
+
npm link
|
|
271
|
+
validator doctor
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Why agent-validator?
|
|
275
|
+
|
|
276
|
+
AI coding agents generate code fast, but quality validation is still manual. This tool:
|
|
277
|
+
|
|
278
|
+
1. **Automates validation**: Run all quality checks in one command
|
|
279
|
+
2. **Deterministic**: Same code = same results (no LLM variance)
|
|
280
|
+
3. **Multi-language**: Works across TypeScript, Python, Ruby
|
|
281
|
+
4. **Fast feedback**: Fail-fast ordering saves time in CI
|
|
282
|
+
5. **Agent-friendly**: JSON output for programmatic parsing
|
|
283
|
+
|
|
284
|
+
## Roadmap
|
|
285
|
+
|
|
286
|
+
- [ ] Config file support (`validator.config.json`)
|
|
287
|
+
- [ ] Custom gate plugins
|
|
288
|
+
- [ ] More language support (Go, Rust, Java)
|
|
289
|
+
- [ ] Incremental mode (only changed functions)
|
|
290
|
+
- [ ] HTML report generation
|
|
291
|
+
- [ ] VSCode extension
|
|
292
|
+
|
|
293
|
+
## License
|
|
294
|
+
|
|
295
|
+
MIT
|
|
296
|
+
|
|
297
|
+
## Contributing
|
|
298
|
+
|
|
299
|
+
Contributions welcome! Please open an issue or PR.
|