cto-ai-cli 3.1.0 → 4.0.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/DOCS.md +352 -0
- package/README.md +192 -15
- package/dist/action/index.js +629 -83
- package/dist/api/dashboard.js +107 -23
- package/dist/api/dashboard.js.map +1 -1
- package/dist/api/server.js +108 -24
- package/dist/api/server.js.map +1 -1
- package/dist/cli/gateway.js +2925 -0
- package/dist/cli/score.js +3015 -237
- package/dist/cli/v2/index.js +133 -49
- package/dist/cli/v2/index.js.map +1 -1
- package/dist/engine/index.d.ts +85 -1
- package/dist/engine/index.js +665 -42
- package/dist/engine/index.js.map +1 -1
- package/dist/gateway/index.d.ts +281 -0
- package/dist/gateway/index.js +2803 -0
- package/dist/gateway/index.js.map +1 -0
- package/dist/govern/index.d.ts +67 -3
- package/dist/govern/index.js +462 -23
- package/dist/govern/index.js.map +1 -1
- package/dist/interact/index.js +108 -24
- package/dist/interact/index.js.map +1 -1
- package/dist/mcp/v2.js +130 -46
- package/dist/mcp/v2.js.map +1 -1
- package/package.json +3 -2
package/DOCS.md
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
## Table of Contents
|
|
6
6
|
|
|
7
7
|
- [CLI Commands](#cli-commands)
|
|
8
|
+
- [Security Audit](#security-audit---audit)
|
|
9
|
+
- [Context Gateway](#context-gateway)
|
|
8
10
|
- [MCP Server](#mcp-server)
|
|
9
11
|
- [API Server](#api-server)
|
|
10
12
|
- [Programmatic API](#programmatic-api)
|
|
@@ -83,6 +85,356 @@ cto2 policy validate
|
|
|
83
85
|
cto2 policy init
|
|
84
86
|
```
|
|
85
87
|
|
|
88
|
+
### `npx cto-ai-cli` (zero-install CLI)
|
|
89
|
+
|
|
90
|
+
The default binary. All flags work with zero install via `npx`.
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npx cto-ai-cli # Score your project
|
|
94
|
+
npx cto-ai-cli ./path # Score a specific project
|
|
95
|
+
npx cto-ai-cli --fix # Auto-generate .cto/context.md, config.json, .cteignore
|
|
96
|
+
npx cto-ai-cli --context "your task" # Task-specific context with file contents
|
|
97
|
+
npx cto-ai-cli --audit # Security audit: detect secrets & PII
|
|
98
|
+
npx cto-ai-cli --report # Shareable markdown report + shields.io badge
|
|
99
|
+
npx cto-ai-cli --compare # Compare your score vs popular open source projects
|
|
100
|
+
npx cto-ai-cli --benchmark # CTO vs naive vs random comparison
|
|
101
|
+
npx cto-ai-cli --json # Machine-readable JSON output
|
|
102
|
+
npx cto-ai-cli --help # Show all options
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Flags can be combined: `npx cto-ai-cli --fix --audit --report --compare`
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Security Audit (`--audit`)
|
|
110
|
+
|
|
111
|
+
Full-project secret and PII detection. Scans all source files for hardcoded credentials, tokens, keys, passwords, connection strings, and personally identifiable information.
|
|
112
|
+
|
|
113
|
+
### Usage
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
npx cto-ai-cli --audit # Full audit with terminal output
|
|
117
|
+
npx cto-ai-cli --audit --fix # Audit + auto-generate context files
|
|
118
|
+
CI=true npx cto-ai-cli --audit # CI mode: exit code 1 on critical/high findings
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Detection engine
|
|
122
|
+
|
|
123
|
+
CTO uses a **dual-strategy** detection approach:
|
|
124
|
+
|
|
125
|
+
**1. Pattern matching (30+ patterns)**
|
|
126
|
+
|
|
127
|
+
| Type | Pattern examples | Severity |
|
|
128
|
+
|------|-----------------|----------|
|
|
129
|
+
| `api-key` | OpenAI `sk-*`, Anthropic `sk-ant-*`, Stripe `sk_live_*`, Google `AIza*`, SendGrid `SG.*.*` | Critical |
|
|
130
|
+
| `aws-key` | `AKIA*` (Access Key ID), `aws_secret_access_key=*` | Critical |
|
|
131
|
+
| `token` | GitHub `ghp_*`/`gho_*`, GitLab `glpat-*`, Slack `xoxb-*`/`xoxp-*`, npm `npm_*`, JWT `eyJ*.*.*` | Critical/High |
|
|
132
|
+
| `private-key` | `-----BEGIN RSA PRIVATE KEY-----`, `-----BEGIN OPENSSH PRIVATE KEY-----` | Critical |
|
|
133
|
+
| `connection-string` | `mongodb://user:pass@host`, `postgres://`, `DATABASE_URL=` | Critical |
|
|
134
|
+
| `password` | `password=`, `DB_PASSWORD=`, `MYSQL_PASSWORD=` | High |
|
|
135
|
+
| `env-variable` | `SECRET_KEY=`, `PRIVATE_TOKEN=`, `ENCRYPTION_PASS=` | High |
|
|
136
|
+
| `pii` | Email addresses, possible SSNs | Medium |
|
|
137
|
+
|
|
138
|
+
**2. Shannon entropy analysis**
|
|
139
|
+
|
|
140
|
+
For strings that don't match a known pattern but look like secrets:
|
|
141
|
+
- Scans all quoted strings ≥40 characters
|
|
142
|
+
- Calculates Shannon entropy (randomness measure)
|
|
143
|
+
- Flags strings with entropy ≥5.0 bits (very random = likely a secret)
|
|
144
|
+
- Automatically skips: hex hashes, camelCase identifiers, base64 padding, integrity hashes, comments, test files
|
|
145
|
+
|
|
146
|
+
### Smart filtering (false positive reduction)
|
|
147
|
+
|
|
148
|
+
The scanner skips:
|
|
149
|
+
- **Placeholders**: `${API_KEY}`, `{{SECRET}}`, `YOUR_KEY_HERE`, `CHANGE_ME`, `example`, `TODO`, `dummy`, `sample`
|
|
150
|
+
- **Test files**: `*.test.ts`, `*.spec.ts`, `__tests__/*` (entropy analysis only — patterns still apply)
|
|
151
|
+
- **Declaration files**: `*.d.ts` (entropy analysis only)
|
|
152
|
+
- **Comments**: Lines starting with `//`, `#`, `*`
|
|
153
|
+
|
|
154
|
+
### Output artifacts
|
|
155
|
+
|
|
156
|
+
| File | Format | Purpose |
|
|
157
|
+
|------|--------|---------|
|
|
158
|
+
| `.cto/audit/YYYY-MM-DD.jsonl` | JSON Lines (append-only) | Audit log — one entry per run. Run daily to build history. |
|
|
159
|
+
| `.cto/audit/report.md` | Markdown | Full report with findings table — share with team or compliance. |
|
|
160
|
+
| `.cto/.env.example` | Text | Auto-generated `.env` template with all detected variable names. |
|
|
161
|
+
|
|
162
|
+
### Audit log format (`.jsonl`)
|
|
163
|
+
|
|
164
|
+
Each line is a JSON object:
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"timestamp": "2026-02-24T23:38:00.000Z",
|
|
169
|
+
"version": "3.2.0",
|
|
170
|
+
"summary": {
|
|
171
|
+
"filesScanned": 179,
|
|
172
|
+
"filesWithSecrets": 12,
|
|
173
|
+
"totalFindings": 51,
|
|
174
|
+
"bySeverity": { "critical": 34, "high": 5, "medium": 12, "low": 0 },
|
|
175
|
+
"byType": { "api-key": 21, "private-key": 5, "aws-key": 4, "token": 4, "connection-string": 3, "password": 2, "pii": 12 }
|
|
176
|
+
},
|
|
177
|
+
"findings": [
|
|
178
|
+
{ "type": "api-key", "file": "src/config/stripe.ts", "line": 8, "severity": "critical", "redacted": "sk_l********************yZ" }
|
|
179
|
+
]
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Programmatic API
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
import { auditProject, scanContentForSecrets, scanContentForHighEntropy } from 'cto-ai-cli/govern';
|
|
187
|
+
|
|
188
|
+
// Full project audit
|
|
189
|
+
const result = await auditProject('/path/to/project', filePaths, {
|
|
190
|
+
customPatterns: ['MY_INTERNAL_TOKEN=[a-z0-9]+'], // optional extra patterns
|
|
191
|
+
entropyThreshold: 5.0, // default: 5.0
|
|
192
|
+
includePII: true, // default: true
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
console.log(result.summary); // { totalFindings, bySeverity, byType, ... }
|
|
196
|
+
console.log(result.findings); // SecretFinding[]
|
|
197
|
+
console.log(result.recommendations); // string[]
|
|
198
|
+
|
|
199
|
+
// Scan a single string
|
|
200
|
+
const findings = scanContentForSecrets(code, 'file.ts');
|
|
201
|
+
|
|
202
|
+
// Entropy-only scan
|
|
203
|
+
const entropyFindings = scanContentForHighEntropy(code, 'file.ts', 5.0);
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### CI/CD integration
|
|
207
|
+
|
|
208
|
+
When `CI=true` is set, `--audit` exits with code 1 if any critical or high-severity findings are detected. Use this in:
|
|
209
|
+
|
|
210
|
+
**GitHub Actions:**
|
|
211
|
+
```yaml
|
|
212
|
+
- name: CTO Security Audit
|
|
213
|
+
run: npx cto-ai-cli --audit
|
|
214
|
+
env:
|
|
215
|
+
CI: true
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
**Pre-commit hook (`.husky/pre-commit`):**
|
|
219
|
+
```bash
|
|
220
|
+
CI=true npx cto-ai-cli --audit
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Recommendations engine
|
|
224
|
+
|
|
225
|
+
Based on findings, CTO generates actionable recommendations:
|
|
226
|
+
|
|
227
|
+
| Finding type | Recommendation |
|
|
228
|
+
|-------------|----------------|
|
|
229
|
+
| Any critical | "Rotate all detected credentials immediately" |
|
|
230
|
+
| `password` | "Move passwords to environment variables or a secrets manager" |
|
|
231
|
+
| `api-key` / `aws-key` | "Use environment variables. Never commit to source control" |
|
|
232
|
+
| `connection-string` | "Database connection strings should use environment variables" |
|
|
233
|
+
| `private-key` | "Private keys should NEVER be in source code. Use a key management service" |
|
|
234
|
+
| `pii` | "Review for GDPR/CCPA compliance. Consider data anonymization" |
|
|
235
|
+
| `high-entropy` | "High-entropy strings detected. Review manually" |
|
|
236
|
+
| Any finding | "Add .gitignore entry for .env files" + "Run --audit regularly or add to CI" |
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## Context Gateway
|
|
241
|
+
|
|
242
|
+
A transparent HTTP proxy that sits between your application and any LLM provider. It intercepts every request, scans for secrets, optimizes context, tracks costs, and enforces budgets — all with zero external dependencies.
|
|
243
|
+
|
|
244
|
+
### Quick start
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
npx cto-gateway # Start on port 8787
|
|
248
|
+
npx cto-gateway --port 9000 # Custom port
|
|
249
|
+
npx cto-gateway --block-secrets # Hard block on critical secrets
|
|
250
|
+
npx cto-gateway --budget-daily 10 # $10/day limit
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Then point your app:
|
|
254
|
+
```bash
|
|
255
|
+
export OPENAI_BASE_URL=http://localhost:8787
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Every request must include the target provider URL as a header:
|
|
259
|
+
```
|
|
260
|
+
x-cto-target: https://api.openai.com/v1/chat/completions
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Architecture
|
|
264
|
+
|
|
265
|
+
```
|
|
266
|
+
Your App → Gateway (localhost:8787) → Provider (api.openai.com)
|
|
267
|
+
│
|
|
268
|
+
├── Secret Scanner → redacts/blocks secrets in messages
|
|
269
|
+
├── Context Optimizer → injects CTO-selected context
|
|
270
|
+
├── Cost Tracker → logs per-request cost to JSONL
|
|
271
|
+
├── Budget Guard → rejects requests over limit (429)
|
|
272
|
+
└── Dashboard → live web UI at /__cto
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### CLI flags
|
|
276
|
+
|
|
277
|
+
| Flag | Default | Description |
|
|
278
|
+
|------|---------|-------------|
|
|
279
|
+
| `--port <n>` | `8787` | Port to listen on |
|
|
280
|
+
| `--host <addr>` | `127.0.0.1` | Host to bind to |
|
|
281
|
+
| `--project <path>` | `.` | Project to analyze for context optimization |
|
|
282
|
+
| `--block-secrets` | off | Hard block requests with critical secrets (403) |
|
|
283
|
+
| `--budget-daily <$>` | unlimited | Max cost per day — returns 429 when exceeded |
|
|
284
|
+
| `--budget-monthly <$>` | unlimited | Max cost per month |
|
|
285
|
+
| `--no-optimize` | on | Disable CTO context injection |
|
|
286
|
+
| `--no-redact` | on | Disable secret redaction |
|
|
287
|
+
| `--no-dashboard` | on | Disable web dashboard |
|
|
288
|
+
|
|
289
|
+
### Provider detection
|
|
290
|
+
|
|
291
|
+
The Gateway auto-detects providers from the `x-cto-target` URL and request headers:
|
|
292
|
+
|
|
293
|
+
| Provider | Detection | Auth header |
|
|
294
|
+
|----------|-----------|-------------|
|
|
295
|
+
| OpenAI | `api.openai.com` or `/v1/chat/completions` | `Authorization: Bearer sk-...` |
|
|
296
|
+
| Anthropic | `api.anthropic.com` or `anthropic-version` header | `x-api-key` |
|
|
297
|
+
| Google AI | `generativelanguage.googleapis.com` | `x-goog-api-key` |
|
|
298
|
+
| Azure OpenAI | `*.openai.azure.com` or `api-key` header | `api-key` |
|
|
299
|
+
| Custom | Fallback — assumes OpenAI-compatible | `Authorization` |
|
|
300
|
+
|
|
301
|
+
### Model pricing
|
|
302
|
+
|
|
303
|
+
Built-in pricing for accurate cost tracking:
|
|
304
|
+
|
|
305
|
+
| Model | Input ($/M tokens) | Output ($/M tokens) | Context window |
|
|
306
|
+
|-------|--------------------|--------------------|----------------|
|
|
307
|
+
| gpt-4o | $2.50 | $10.00 | 128K |
|
|
308
|
+
| gpt-4o-mini | $0.15 | $0.60 | 128K |
|
|
309
|
+
| o1 | $15.00 | $60.00 | 200K |
|
|
310
|
+
| o3-mini | $1.10 | $4.40 | 200K |
|
|
311
|
+
| claude-sonnet-4 | $3.00 | $15.00 | 200K |
|
|
312
|
+
| claude-3.5-haiku | $0.80 | $4.00 | 200K |
|
|
313
|
+
| gemini-2.5-pro | $1.25 | $10.00 | 1M |
|
|
314
|
+
| gemini-2.0-flash | $0.10 | $0.40 | 1M |
|
|
315
|
+
|
|
316
|
+
### Request lifecycle
|
|
317
|
+
|
|
318
|
+
1. **Receive** — Client sends POST request to Gateway
|
|
319
|
+
2. **Budget check** — If daily/monthly budget exceeded → 429
|
|
320
|
+
3. **Parse** — Detect provider, extract messages from provider-specific format
|
|
321
|
+
4. **Scan secrets** — Run 30+ patterns against all message content
|
|
322
|
+
5. **Redact or block** — Replace secrets with `***REDACTED***` or return 403
|
|
323
|
+
6. **Optimize context** — If analysis ready, inject CTO-selected files into system prompt
|
|
324
|
+
7. **Forward** — Proxy to provider (streaming SSE or buffered)
|
|
325
|
+
8. **Track** — Log cost, tokens, savings, latency to JSONL
|
|
326
|
+
9. **Respond** — Forward provider response to client (zero-copy for streams)
|
|
327
|
+
|
|
328
|
+
### Streaming support
|
|
329
|
+
|
|
330
|
+
The Gateway fully supports Server-Sent Events (SSE) streaming:
|
|
331
|
+
|
|
332
|
+
- Detects streaming from `Content-Type: text/event-stream`
|
|
333
|
+
- Zero-copy passthrough: chunks are forwarded to client as they arrive
|
|
334
|
+
- Async token tracking: parses SSE events in background without blocking the stream
|
|
335
|
+
- Usage data extracted from final SSE chunk (when provider includes it)
|
|
336
|
+
|
|
337
|
+
### Dashboard
|
|
338
|
+
|
|
339
|
+
Available at `http://localhost:8787/__cto` (configurable via `--dashboardPath`).
|
|
340
|
+
|
|
341
|
+
Shows:
|
|
342
|
+
- **Today**: requests, cost, tokens saved, secrets redacted
|
|
343
|
+
- **This month**: totals + budget progress
|
|
344
|
+
- **Feature status**: optimization, redaction, tracking, audit log
|
|
345
|
+
- **By model**: breakdown of requests, tokens, and cost per model
|
|
346
|
+
- **By provider**: requests and cost per provider
|
|
347
|
+
- Auto-refreshes every 30 seconds
|
|
348
|
+
|
|
349
|
+
### Usage storage
|
|
350
|
+
|
|
351
|
+
| File | Format | Description |
|
|
352
|
+
|------|--------|-------------|
|
|
353
|
+
| `.cto/gateway/usage/YYYY-MM.jsonl` | JSON Lines | One line per request. Monthly files. |
|
|
354
|
+
|
|
355
|
+
Each line:
|
|
356
|
+
```json
|
|
357
|
+
{
|
|
358
|
+
"id": "a1b2c3d4",
|
|
359
|
+
"timestamp": "2026-02-24T23:52:00.000Z",
|
|
360
|
+
"provider": "openai",
|
|
361
|
+
"model": "gpt-4o",
|
|
362
|
+
"inputTokens": 1200,
|
|
363
|
+
"outputTokens": 350,
|
|
364
|
+
"costUSD": 0.0065,
|
|
365
|
+
"originalTokens": 6200,
|
|
366
|
+
"optimizedTokens": 1200,
|
|
367
|
+
"savedTokens": 5000,
|
|
368
|
+
"savedUSD": 0.0130,
|
|
369
|
+
"secretsRedacted": 2,
|
|
370
|
+
"secretsBlocked": false,
|
|
371
|
+
"latencyMs": 152,
|
|
372
|
+
"stream": true
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### Budget enforcement
|
|
377
|
+
|
|
378
|
+
When a budget is set, the Gateway checks cost totals before every request:
|
|
379
|
+
|
|
380
|
+
| Condition | HTTP response |
|
|
381
|
+
|-----------|---------------|
|
|
382
|
+
| Daily budget exceeded | `429 Too Many Requests` + `{ "error": "Daily budget exceeded", "budget": 10, "current": 10.42 }` |
|
|
383
|
+
| Monthly budget exceeded | `429 Too Many Requests` + `{ "error": "Monthly budget exceeded" }` |
|
|
384
|
+
| Critical secrets + `--block-secrets` | `403 Forbidden` + `{ "error": "Request blocked: secrets detected" }` |
|
|
385
|
+
|
|
386
|
+
Budget alerts are emitted at 80% of limit (configurable via `alertThreshold`).
|
|
387
|
+
|
|
388
|
+
### Programmatic API
|
|
389
|
+
|
|
390
|
+
```typescript
|
|
391
|
+
import { ContextGateway, UsageTracker } from 'cto-ai-cli/gateway';
|
|
392
|
+
|
|
393
|
+
const gateway = new ContextGateway({
|
|
394
|
+
port: 8787,
|
|
395
|
+
projectPath: '/path/to/project',
|
|
396
|
+
redactSecrets: true,
|
|
397
|
+
blockOnSecrets: false,
|
|
398
|
+
budgetDaily: 20,
|
|
399
|
+
budgetMonthly: 500,
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
// Listen to events
|
|
403
|
+
gateway.onEvent((event) => {
|
|
404
|
+
if (event.type === 'request') console.log(`${event.record.model}: $${event.record.costUSD}`);
|
|
405
|
+
if (event.type === 'budget-alert') console.log(`Budget warning: ${event.period}`);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
await gateway.start();
|
|
409
|
+
|
|
410
|
+
// Get usage summary
|
|
411
|
+
const tracker = gateway.getTracker();
|
|
412
|
+
const summary = tracker.getSummary('month');
|
|
413
|
+
console.log(`This month: ${summary.totalRequests} requests, $${summary.totalCostUSD}`);
|
|
414
|
+
|
|
415
|
+
// Provider detection (standalone)
|
|
416
|
+
import { detectProvider, estimateCost } from 'cto-ai-cli/gateway';
|
|
417
|
+
|
|
418
|
+
const provider = detectProvider('https://api.openai.com/v1/chat/completions', {});
|
|
419
|
+
const cost = estimateCost(provider, 'gpt-4o', 5000, 1000);
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### Interceptor (standalone)
|
|
423
|
+
|
|
424
|
+
```typescript
|
|
425
|
+
import { interceptRequest } from 'cto-ai-cli/gateway';
|
|
426
|
+
import type { Message, GatewayConfig } from 'cto-ai-cli/gateway';
|
|
427
|
+
|
|
428
|
+
const messages: Message[] = [
|
|
429
|
+
{ role: 'user', content: 'Deploy with key sk-live_abc123...' },
|
|
430
|
+
];
|
|
431
|
+
|
|
432
|
+
const result = await interceptRequest(messages, config, analysis);
|
|
433
|
+
// result.secretsRedacted → 1
|
|
434
|
+
// result.messages[0].content → 'Deploy with key sk-l**********23...'
|
|
435
|
+
// result.decisions → ['Redacted 1 secret(s) in user message: api-key']
|
|
436
|
+
```
|
|
437
|
+
|
|
86
438
|
---
|
|
87
439
|
|
|
88
440
|
## MCP Server
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
> **Early access** — This is a test version. We'd love your feedback.
|
|
4
4
|
|
|
5
5
|
[](LICENSE)
|
|
6
|
-
[](#)
|
|
7
7
|
|
|
8
8
|
## Try it now (zero install)
|
|
9
9
|
|
|
@@ -77,10 +77,15 @@ Without type definitions, the AI invents interfaces — wrong property names, wr
|
|
|
77
77
|
### Option 1: Quick score (no install)
|
|
78
78
|
|
|
79
79
|
```bash
|
|
80
|
-
npx cto-ai-cli
|
|
81
|
-
npx cto-ai-cli ./my-project
|
|
82
|
-
npx cto-ai-cli --
|
|
83
|
-
npx cto-ai-cli --
|
|
80
|
+
npx cto-ai-cli # Score your project
|
|
81
|
+
npx cto-ai-cli ./my-project # Score a specific project
|
|
82
|
+
npx cto-ai-cli --fix # Auto-generate optimized context files
|
|
83
|
+
npx cto-ai-cli --context "your task" # Task-specific context for AI prompts
|
|
84
|
+
npx cto-ai-cli --audit # Security audit: detect secrets & PII
|
|
85
|
+
npx cto-ai-cli --report # Shareable report + README badge
|
|
86
|
+
npx cto-ai-cli --compare # Compare your score vs popular projects
|
|
87
|
+
npx cto-ai-cli --benchmark # CTO vs naive vs random comparison
|
|
88
|
+
npx cto-ai-cli --json # Machine-readable output (for CI)
|
|
84
89
|
```
|
|
85
90
|
|
|
86
91
|
### Option 2: Full install
|
|
@@ -197,17 +202,187 @@ Without these files, the AI has to guess the shape of `AnalyzedFile`, `ContextSe
|
|
|
197
202
|
|
|
198
203
|
---
|
|
199
204
|
|
|
205
|
+
## 🔒 Security Audit — detect secrets before AI sees them
|
|
206
|
+
|
|
207
|
+
Every time you send code to an AI, there's a risk: **API keys, tokens, passwords, and PII hiding in your codebase.**
|
|
208
|
+
|
|
209
|
+
CTO now scans your entire project for secrets — before they end up in an AI prompt.
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
npx cto-ai-cli --audit
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
🔍 Running security audit...
|
|
217
|
+
|
|
218
|
+
╔══════════════════════════════════════════════════╗
|
|
219
|
+
║ ║
|
|
220
|
+
║ 🔴 Security Audit: CRITICAL ISSUES FOUND ║
|
|
221
|
+
║ ║
|
|
222
|
+
║ Files scanned: 179 ║
|
|
223
|
+
║ Files affected: 12 ║
|
|
224
|
+
║ Total findings: 51 ║
|
|
225
|
+
║ ║
|
|
226
|
+
╠══════════════════════════════════════════════════╣
|
|
227
|
+
║ ║
|
|
228
|
+
║ 🔴 Critical: 34 ║
|
|
229
|
+
║ 🟠 High: 5 ║
|
|
230
|
+
║ 🟡 Medium: 12 ║
|
|
231
|
+
║ ║
|
|
232
|
+
╚══════════════════════════════════════════════════╝
|
|
233
|
+
|
|
234
|
+
Findings:
|
|
235
|
+
|
|
236
|
+
🔴 CRITICAL src/config/stripe.ts:8
|
|
237
|
+
api-key: sk_l********************yZ
|
|
238
|
+
🔴 CRITICAL src/config/database.ts:14
|
|
239
|
+
connection-string: post********************db
|
|
240
|
+
🟠 HIGH src/utils/email.ts:22
|
|
241
|
+
pii: admi**********om
|
|
242
|
+
|
|
243
|
+
Recommendations:
|
|
244
|
+
|
|
245
|
+
🚨 CRITICAL: Rotate all detected credentials immediately.
|
|
246
|
+
💡 Use environment variables for API keys.
|
|
247
|
+
💡 Add a .gitignore entry for .env files.
|
|
248
|
+
|
|
249
|
+
📁 Audit artifacts:
|
|
250
|
+
📋 .cto/audit/2026-02-24.jsonl Audit log (append-only)
|
|
251
|
+
📊 .cto/audit/report.md Full report
|
|
252
|
+
📝 .cto/.env.example Template for environment variables
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### What it detects
|
|
256
|
+
|
|
257
|
+
| Category | Examples | Severity |
|
|
258
|
+
|----------|----------|----------|
|
|
259
|
+
| **API Keys** | OpenAI, Anthropic, Stripe, Google, SendGrid, Azure | 🔴 Critical |
|
|
260
|
+
| **Cloud credentials** | AWS Access Keys, AWS Secrets | 🔴 Critical |
|
|
261
|
+
| **Tokens** | GitHub, GitLab, Slack, npm, JWT | 🔴 Critical |
|
|
262
|
+
| **Private keys** | RSA, SSH, EC private keys | 🔴 Critical |
|
|
263
|
+
| **Database** | Connection strings (Postgres, MongoDB, Redis, MySQL) | 🔴 Critical |
|
|
264
|
+
| **Passwords** | Hardcoded passwords, DB passwords | 🟠 High |
|
|
265
|
+
| **PII** | Email addresses, possible SSNs | 🟡 Medium |
|
|
266
|
+
| **High-entropy strings** | Random strings that look like secrets (Shannon entropy analysis) | 🟡 Medium |
|
|
267
|
+
|
|
268
|
+
### How it works
|
|
269
|
+
|
|
270
|
+
1. **30+ regex patterns** — battle-tested patterns for known secret formats (AWS, Stripe, Slack, GitHub, etc.)
|
|
271
|
+
2. **Shannon entropy analysis** — detects random-looking strings that may be secrets, even if they don't match a known pattern
|
|
272
|
+
3. **Smart filtering** — skips placeholders (`${API_KEY}`), test files, comments, and common false positives
|
|
273
|
+
4. **Auto-redaction** — secrets are NEVER shown in full. All output uses redacted values (`sk_l**********yZ`)
|
|
274
|
+
|
|
275
|
+
### What it generates
|
|
276
|
+
|
|
277
|
+
| File | Purpose |
|
|
278
|
+
|------|---------|
|
|
279
|
+
| `.cto/audit/YYYY-MM-DD.jsonl` | Append-only audit log (run it daily, keep history) |
|
|
280
|
+
| `.cto/audit/report.md` | Full markdown report — share with your team or compliance |
|
|
281
|
+
| `.cto/.env.example` | Auto-generated template with all detected env variable names |
|
|
282
|
+
|
|
283
|
+
### CI/CD integration
|
|
284
|
+
|
|
285
|
+
Set `CI=true` and the audit will **exit with code 1** if critical or high-severity secrets are found:
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
CI=true npx cto-ai-cli --audit
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Perfect for pre-commit hooks or CI pipelines — block PRs that contain secrets before they reach production or an AI prompt.
|
|
292
|
+
|
|
293
|
+
### Why this matters
|
|
294
|
+
|
|
295
|
+
Every day, developers accidentally send secrets to AI tools:
|
|
296
|
+
- Copilot autocompletes with your `.env` values in context
|
|
297
|
+
- You paste a file into ChatGPT that has a hardcoded API key
|
|
298
|
+
- Cursor reads your database config with connection strings
|
|
299
|
+
|
|
300
|
+
**CTO catches these before they leave your machine.** Zero external calls. Everything runs locally.
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## 🌐 Context Gateway — AI proxy for your entire team
|
|
305
|
+
|
|
306
|
+
Every AI API call from your team passes through the Gateway. It sits between your app and any LLM provider, automatically optimizing context, redacting secrets, and tracking costs.
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
npx cto-gateway
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
```
|
|
313
|
+
⚡ CTO Context Gateway v4.0.0
|
|
314
|
+
|
|
315
|
+
🌐 Proxy: http://127.0.0.1:8787
|
|
316
|
+
📊 Dashboard: http://127.0.0.1:8787/__cto
|
|
317
|
+
📁 Project: /your/project
|
|
318
|
+
|
|
319
|
+
✅ Context optimization
|
|
320
|
+
✅ Secret redaction
|
|
321
|
+
✅ Cost tracking
|
|
322
|
+
⬜ Daily budget (unlimited)
|
|
323
|
+
|
|
324
|
+
How to connect:
|
|
325
|
+
OPENAI_BASE_URL=http://127.0.0.1:8787
|
|
326
|
+
+ set header: x-cto-target: https://api.openai.com/v1/chat/completions
|
|
327
|
+
|
|
328
|
+
Waiting for requests...
|
|
329
|
+
|
|
330
|
+
18:52:34 openai/gpt-4o 1200 tokens $0.0075 (saved 5.2K tokens, $0.0130) [2 secrets redacted] 152ms
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### What it does
|
|
334
|
+
|
|
335
|
+
| Feature | Description |
|
|
336
|
+
|---------|-------------|
|
|
337
|
+
| **Secret redaction** | Scans every message for API keys, tokens, passwords → auto-redacts before sending to the LLM |
|
|
338
|
+
| **Secret blocking** | Optional hard block — reject requests that contain critical secrets |
|
|
339
|
+
| **Context optimization** | Injects CTO-selected files, type definitions, and hub modules into system prompts |
|
|
340
|
+
| **Cost tracking** | Tracks per-request cost by model and provider. Persistent JSONL logs. |
|
|
341
|
+
| **Budget enforcement** | Set daily/monthly limits. Gateway returns 429 when exceeded. |
|
|
342
|
+
| **Live dashboard** | Dark-theme web UI at `/__cto` — today's stats, monthly breakdown, model costs |
|
|
343
|
+
| **SSE streaming** | Full passthrough of streaming responses with zero-copy. No added latency. |
|
|
344
|
+
| **Multi-provider** | OpenAI, Anthropic, Google AI, Azure OpenAI, and any OpenAI-compatible API |
|
|
345
|
+
|
|
346
|
+
### Supported providers & models
|
|
347
|
+
|
|
348
|
+
| Provider | Models | Pricing tracked |
|
|
349
|
+
|----------|--------|----------------|
|
|
350
|
+
| **OpenAI** | GPT-4o, GPT-4o Mini, o1, o1-mini, o3-mini | ✅ |
|
|
351
|
+
| **Anthropic** | Claude Sonnet 4, Claude 3.5 Haiku, Claude 3 Opus | ✅ |
|
|
352
|
+
| **Google** | Gemini 2.5 Pro, Gemini 2.0 Flash, Gemini 1.5 Pro | ✅ |
|
|
353
|
+
| **Azure OpenAI** | Same as OpenAI (different hosting) | ✅ |
|
|
354
|
+
| **Custom** | Any OpenAI-compatible API (Ollama, LiteLLM, etc.) | Manual |
|
|
355
|
+
|
|
356
|
+
### Configuration
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
cto-gateway --port 9000 # Custom port
|
|
360
|
+
cto-gateway --block-secrets # Hard block on critical secrets
|
|
361
|
+
cto-gateway --budget-daily 10 # Max $10/day
|
|
362
|
+
cto-gateway --budget-monthly 200 # Max $200/month
|
|
363
|
+
cto-gateway --project ./my-app # Analyze a specific project
|
|
364
|
+
cto-gateway --no-optimize # Disable context injection
|
|
365
|
+
cto-gateway --no-redact # Disable secret redaction
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
200
370
|
## What you can do with CTO
|
|
201
371
|
|
|
202
372
|
| Use case | How |
|
|
203
373
|
|----------|-----|
|
|
204
374
|
| **Score your project** | `npx cto-ai-cli` |
|
|
205
|
-
| **
|
|
206
|
-
| **
|
|
207
|
-
| **
|
|
375
|
+
| **Auto-optimize context** | `npx cto-ai-cli --fix` → generates `.cto/context.md` to paste into AI |
|
|
376
|
+
| **Task-specific context** | `npx cto-ai-cli --context "refactor auth"` → optimized for your task |
|
|
377
|
+
| **Security audit** | `npx cto-ai-cli --audit` → detect secrets & PII before AI sees them |
|
|
378
|
+
| **AI proxy (Gateway)** | `npx cto-gateway` → proxy with secret redaction + cost tracking |
|
|
379
|
+
| **Shareable report** | `npx cto-ai-cli --report` → markdown report + README badge |
|
|
380
|
+
| **Compare vs open source** | `npx cto-ai-cli --compare` → your score vs Zod, Next.js, Express |
|
|
381
|
+
| **Compare strategies** | `npx cto-ai-cli --benchmark` → CTO vs naive vs random |
|
|
382
|
+
| **Get context for a task** | `cto2 interact "your task"` |
|
|
208
383
|
| **Use in your AI editor** | Add MCP server (see setup above) |
|
|
209
|
-
| **
|
|
210
|
-
| **
|
|
384
|
+
| **Block secrets in CI** | `CI=true npx cto-ai-cli --audit` |
|
|
385
|
+
| **Budget control** | `cto-gateway --budget-daily 10 --budget-monthly 200` |
|
|
211
386
|
| **JSON output (scripting)** | `npx cto-ai-cli --json` |
|
|
212
387
|
|
|
213
388
|
---
|
|
@@ -226,10 +401,12 @@ This is an early test version. Here's what we know:
|
|
|
226
401
|
## What's next
|
|
227
402
|
|
|
228
403
|
We're working on:
|
|
229
|
-
- **
|
|
230
|
-
- **
|
|
231
|
-
- **
|
|
232
|
-
- **
|
|
404
|
+
- **Context Gateway** — proxy between your team and any AI, with automatic context optimization and cost tracking
|
|
405
|
+
- **Monorepo intelligence** — package-aware selection for large monorepos (60-80% more token savings)
|
|
406
|
+
- **CI Quality Gate** — GitHub Action that posts context score and secret audit on every PR
|
|
407
|
+
- **VS Code extension** — live score, risk indicators, and context suggestions inline
|
|
408
|
+
- **Learning mode** — CTO improves based on which AI suggestions you accept/reject
|
|
409
|
+
- **More language support** — deeper analysis for Python, Go, and Rust
|
|
233
410
|
- **Your feedback** — [open an issue](https://github.com/cto-ai/cto-ai-cli/issues) or reach out
|
|
234
411
|
|
|
235
412
|
---
|
|
@@ -241,7 +418,7 @@ git clone <repo-url>
|
|
|
241
418
|
cd cto
|
|
242
419
|
npm install
|
|
243
420
|
npm run build
|
|
244
|
-
npm test #
|
|
421
|
+
npm test # 573 tests
|
|
245
422
|
npm run typecheck # strict TypeScript
|
|
246
423
|
```
|
|
247
424
|
|