cto-ai-cli 5.1.0 → 6.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 +82 -261
- package/dist/cli/index.js +2573 -5977
- package/dist/engine/index.d.ts +182 -758
- package/dist/engine/index.js +728 -4710
- package/dist/mcp/index.js +1929 -15028
- package/package.json +9 -43
- package/DOCS.md +0 -902
- package/dist/action/index.js +0 -26395
- package/dist/api/dashboard.js +0 -2276
- package/dist/api/dashboard.js.map +0 -1
- package/dist/api/server.js +0 -3663
- package/dist/api/server.js.map +0 -1
- package/dist/cli/gateway.js +0 -3054
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/score.js +0 -6352
- package/dist/cli/v2/index.d.ts +0 -2
- package/dist/cli/v2/index.js +0 -3695
- package/dist/cli/v2/index.js.map +0 -1
- package/dist/engine/index.js.map +0 -1
- package/dist/fsevents-X6WP4TKM.node +0 -0
- package/dist/gateway/index.d.ts +0 -281
- package/dist/gateway/index.js +0 -2932
- package/dist/gateway/index.js.map +0 -1
- package/dist/govern/index.d.ts +0 -325
- package/dist/govern/index.js +0 -1101
- package/dist/govern/index.js.map +0 -1
- package/dist/interact/index.d.ts +0 -234
- package/dist/interact/index.js +0 -1542
- package/dist/interact/index.js.map +0 -1
- package/dist/mcp/index.d.ts +0 -2
- package/dist/mcp/index.js.map +0 -1
- package/dist/mcp/v2.d.ts +0 -2
- package/dist/mcp/v2.js +0 -18492
- package/dist/mcp/v2.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,334 +1,155 @@
|
|
|
1
|
-
# CTO —
|
|
1
|
+
# CTO — AI context selection done right
|
|
2
2
|
|
|
3
|
-
[](LICENSE)
|
|
4
|
-
[](#)
|
|
5
|
-
[](#)
|
|
6
3
|
[](https://www.npmjs.com/package/cto-ai-cli)
|
|
4
|
+
[](LICENSE)
|
|
7
5
|
|
|
8
|
-
|
|
6
|
+
Pick the right files for any AI task. Secrets auto-redacted. Learns from your feedback.
|
|
9
7
|
|
|
10
8
|
```bash
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
**Runs in <1 second.** No API keys. No data leaves your machine.
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## The Problem
|
|
19
|
-
|
|
20
|
-
When you ask an AI to help with code, it needs context. Most approaches:
|
|
9
|
+
# Select context, copy to clipboard
|
|
10
|
+
cto --context "fix the auth middleware" --stdout | pbcopy
|
|
21
11
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
- **Let the AI pick** — it doesn't know your dependency graph
|
|
12
|
+
# Generate a complete AI prompt
|
|
13
|
+
cto --context "fix the auth middleware" --prompt "Refactor this to use JWT"
|
|
25
14
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
## The Fix
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
$ npx cto-ai-cli ./my-project
|
|
32
|
-
```
|
|
15
|
+
# Was the AI output good? Tell CTO so it learns.
|
|
16
|
+
cto --accept
|
|
33
17
|
```
|
|
34
|
-
⚡ cto-score — analyzing your project...
|
|
35
|
-
|
|
36
|
-
╔══════════════════════════════════════════════════╗
|
|
37
|
-
║ ║
|
|
38
|
-
║ 🟢 Context Score™ 88 / 100 Grade: A- ║
|
|
39
|
-
║ ║
|
|
40
|
-
║ Efficiency ████████████████░░░░ 80% ║
|
|
41
|
-
║ Coverage ████████████████████ 100% ║
|
|
42
|
-
║ Risk Control ████████████████████ 100% ║
|
|
43
|
-
║ Structure █░░░░░░░░░░░░░░░░░░ 5% ║
|
|
44
|
-
║ Governance ██████████████████░ 90% ║
|
|
45
|
-
║ ║
|
|
46
|
-
║ 💰 vs. Sending Everything: ║
|
|
47
|
-
║ Tokens saved: 392K (88%) ║
|
|
48
|
-
║ Monthly savings: ~$943 ║
|
|
49
|
-
║ ║
|
|
50
|
-
╚══════════════════════════════════════════════════╝
|
|
51
|
-
|
|
52
|
-
Scanned in 0.6s · 199 files · 443K tokens
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### What each number means
|
|
56
18
|
|
|
57
|
-
|
|
58
|
-
|--------|-----------------|----------------|
|
|
59
|
-
| **Context Score (88/100)** | Overall AI-readiness of your project | Higher = AI tools produce better output with your code |
|
|
60
|
-
| **Efficiency (80%)** | How much CTO can compress without losing value | 80% means we send 20% of tokens for the same quality |
|
|
61
|
-
| **Coverage (100%)** | % of important files included in the selection | 100% = every dependency and type file is captured |
|
|
62
|
-
| **Risk Control (100%)** | Are high-risk files (hubs, complex code) prioritized? | Ensures AI sees the files most likely to cause bugs |
|
|
63
|
-
| **Structure (5%)** | How well-organized your codebase is for AI | Low = too many large files, poor modularity |
|
|
64
|
-
| **Governance (90%)** | Audit logging, policy enforcement, secret scanning | Enterprise readiness |
|
|
65
|
-
| **Tokens saved (88%)** | Reduction vs. sending every file | Directly reduces your API costs |
|
|
66
|
-
| **Monthly savings ($943)** | Estimated cost reduction at 800 interactions/month | Based on average GPT-4o pricing |
|
|
19
|
+
74KB package. Zero bloat.
|
|
67
20
|
|
|
68
21
|
---
|
|
69
22
|
|
|
70
|
-
##
|
|
23
|
+
## What it does
|
|
71
24
|
|
|
72
|
-
|
|
25
|
+
When you ask an AI to help with code, it needs the right files as context. Send too few and the AI hallucinates. Send too many and you waste tokens. CTO picks the right ones:
|
|
73
26
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
```
|
|
27
|
+
1. **Matches your task** — TF-IDF/BM25 semantic matching, not keyword guessing
|
|
28
|
+
2. **Ranks by composite score** — `risk × 0.4 + semantic × 0.4 + learner × 0.2`
|
|
29
|
+
3. **Sanitizes output** — API keys, tokens, passwords auto-redacted before they reach any AI
|
|
30
|
+
4. **Learns from feedback** — `--accept` / `--reject` teach it what you actually need
|
|
79
31
|
|
|
80
|
-
|
|
32
|
+
Different tasks → different files. `"fix auth"` and `"add database tests"` return **completely different selections**.
|
|
81
33
|
|
|
82
|
-
|
|
83
|
-
npx cto-ai-cli --fix
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
Creates `.cto/context.md` — paste this into any AI chat for optimal context. Also generates `.cto/config.json` and `.cto/.cteignore`.
|
|
34
|
+
## Install
|
|
87
35
|
|
|
88
36
|
```bash
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
Generates **task-specific** context — only files relevant to auth, including types, dependencies, and related tests.
|
|
93
|
-
|
|
94
|
-
Example output:
|
|
95
|
-
```
|
|
96
|
-
📋 Context for: "refactor the auth middleware"
|
|
97
|
-
|
|
98
|
-
Selected 12 files (8.2K tokens):
|
|
99
|
-
|
|
100
|
-
┌─ Core (3 files) ─────────────────────────────
|
|
101
|
-
│ src/middleware/auth.ts 2,100 tokens
|
|
102
|
-
│ src/types/auth.ts 450 tokens
|
|
103
|
-
│ src/config/jwt.ts 320 tokens
|
|
104
|
-
│
|
|
105
|
-
├─ Dependencies (5 files) ─────────────────────
|
|
106
|
-
│ src/models/user.ts 1,200 tokens
|
|
107
|
-
│ src/services/token.ts 890 tokens
|
|
108
|
-
│ ...
|
|
109
|
-
│
|
|
110
|
-
└─ Tests (2 files) ────────────────────────────
|
|
111
|
-
tests/auth.test.ts 1,800 tokens
|
|
112
|
-
tests/middleware.test.ts 940 tokens
|
|
113
|
-
|
|
114
|
-
Saved to .cto/context.md (8.2K tokens — 97% smaller than full project)
|
|
37
|
+
npm i -g cto-ai-cli # global
|
|
38
|
+
npx cto-ai-cli # or one-shot
|
|
115
39
|
```
|
|
116
40
|
|
|
117
|
-
|
|
41
|
+
## Context Selection
|
|
118
42
|
|
|
119
43
|
```bash
|
|
120
|
-
|
|
121
|
-
|
|
44
|
+
# Human-readable summary
|
|
45
|
+
cto --context "refactor the auth middleware"
|
|
122
46
|
|
|
123
|
-
|
|
47
|
+
# Pipe to clipboard (macOS)
|
|
48
|
+
cto --context "fix login bug" --stdout | pbcopy
|
|
124
49
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
api-key: sk_l********************yZ
|
|
128
|
-
🔴 CRITICAL src/config/database.ts:14
|
|
129
|
-
connection-string: post********************db
|
|
130
|
-
🟠 HIGH src/utils/email.ts:22
|
|
131
|
-
pii: admi**********om
|
|
132
|
-
|
|
133
|
-
🚨 3 critical findings. Rotate credentials immediately.
|
|
134
|
-
```
|
|
50
|
+
# Save to file (secrets auto-redacted)
|
|
51
|
+
cto --context "add tests" --output context.md
|
|
135
52
|
|
|
136
|
-
|
|
53
|
+
# Full AI prompt with instruction
|
|
54
|
+
cto --context "fix login" --prompt "Refactor to use async/await"
|
|
137
55
|
|
|
138
|
-
|
|
56
|
+
# JSON for tooling
|
|
57
|
+
cto --context "debug scoring" --json
|
|
139
58
|
|
|
140
|
-
|
|
141
|
-
|
|
59
|
+
# Custom token budget
|
|
60
|
+
cto --context "fix auth" --budget 30000
|
|
142
61
|
```
|
|
143
62
|
|
|
144
|
-
|
|
63
|
+
Output includes full file contents in markdown, ready to paste into Claude, ChatGPT, or any AI. **Secrets are automatically redacted** — API keys, tokens, passwords, PII are replaced with `****` before output.
|
|
145
64
|
|
|
146
|
-
|
|
147
|
-
📊 Review Quality: 82/100 (B+)
|
|
65
|
+
## Feedback Loop
|
|
148
66
|
|
|
149
|
-
|
|
150
|
-
🔴 Removed export: UserService.findById (used by 4 files)
|
|
151
|
-
🟡 Changed signature: authenticate(token) → authenticate(token, opts)
|
|
152
|
-
|
|
153
|
-
Missing Files:
|
|
154
|
-
⚠️ No test file for src/services/auth.ts
|
|
155
|
-
⚠️ src/types/user.ts changed but barrel index not updated
|
|
156
|
-
|
|
157
|
-
Impact Radius:
|
|
158
|
-
Direct: 4 files | Transitive: 12 files | Tests: 3 files
|
|
159
|
-
|
|
160
|
-
Saved review prompt to .cto/review-prompt.md
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
| What it detects | Example |
|
|
164
|
-
|-----------------|--------|
|
|
165
|
-
| **Breaking changes** | Removed exports, changed function signatures, deleted files |
|
|
166
|
-
| **Missing files** | Tests, type files, barrel exports, importers of changed code |
|
|
167
|
-
| **Impact radius** | How many files are affected (direct + transitive via BFS) |
|
|
168
|
-
| **Review quality** | Score based on PR size, focus, breaking changes, completeness |
|
|
169
|
-
|
|
170
|
-
### Learning mode
|
|
67
|
+
CTO learns from real feedback, not from itself:
|
|
171
68
|
|
|
172
69
|
```bash
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
npx cto-ai-cli --learn --json # Export learning data for team sharing
|
|
176
|
-
```
|
|
70
|
+
# After using the context and it worked:
|
|
71
|
+
cto --accept
|
|
177
72
|
|
|
178
|
-
|
|
73
|
+
# If the AI needed files CTO didn't include:
|
|
74
|
+
cto --reject
|
|
75
|
+
cto --reject --missing src/types/auth.ts
|
|
179
76
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
```bash
|
|
183
|
-
npx cto-ai-cli --ci # Run quality gate (exits 1 on failure)
|
|
184
|
-
npx cto-ai-cli --ci --threshold 80 # Custom minimum score
|
|
185
|
-
npx cto-ai-cli --ci --json # JSON for pipeline parsing
|
|
77
|
+
# See what CTO has learned:
|
|
78
|
+
cto --stats
|
|
186
79
|
```
|
|
187
80
|
|
|
188
|
-
|
|
81
|
+
On `--reject`, CTO also detects files you edited after the selection that weren't in the context — those get automatically boosted for next time.
|
|
189
82
|
|
|
190
|
-
|
|
83
|
+
## Secret Audit
|
|
191
84
|
|
|
192
85
|
```bash
|
|
193
|
-
|
|
194
|
-
|
|
86
|
+
cto --audit # scan all files
|
|
87
|
+
cto --audit --init-hook # install pre-commit hook
|
|
88
|
+
cto --audit --full-scan # ignore cache, scan everything
|
|
89
|
+
cto --audit --json # machine-readable output
|
|
195
90
|
```
|
|
196
91
|
|
|
197
|
-
|
|
92
|
+
45+ patterns (AWS, Stripe, GitHub, OpenAI, Slack, etc.) plus Shannon entropy analysis. But the real value is that **audit protects context**: every `--stdout`, `--output`, and `--prompt` command auto-sanitizes secrets before output.
|
|
198
93
|
|
|
199
|
-
|
|
94
|
+
## MCP Server
|
|
200
95
|
|
|
201
|
-
|
|
96
|
+
Works as an MCP server for AI editors (Windsurf, Claude Desktop, Cursor).
|
|
202
97
|
|
|
203
|
-
|
|
204
|
-
# Analysis
|
|
205
|
-
npx cto-ai-cli [path] # Score a project
|
|
206
|
-
npx cto-ai-cli --json # JSON output
|
|
207
|
-
npx cto-ai-cli --benchmark # CTO vs naive vs random comparison
|
|
208
|
-
npx cto-ai-cli --compare # Compare vs popular OSS projects
|
|
209
|
-
npx cto-ai-cli --report # Markdown report + badge
|
|
210
|
-
|
|
211
|
-
# Context generation
|
|
212
|
-
npx cto-ai-cli --fix # Auto-generate .cto/context.md
|
|
213
|
-
npx cto-ai-cli --context "task" # Task-specific context
|
|
214
|
-
|
|
215
|
-
# Security
|
|
216
|
-
npx cto-ai-cli --audit # Secret & PII detection
|
|
217
|
-
npx cto-ai-cli --audit --full-scan # Scan all files (ignore cache)
|
|
218
|
-
npx cto-ai-cli --audit --init-hook # Install pre-commit hook
|
|
219
|
-
|
|
220
|
-
# Code review
|
|
221
|
-
npx cto-ai-cli --review # PR review analysis
|
|
222
|
-
npx cto-ai-cli --review --json # Review data as JSON
|
|
223
|
-
|
|
224
|
-
# Learning
|
|
225
|
-
npx cto-ai-cli --learn # Feedback model dashboard
|
|
226
|
-
npx cto-ai-cli --predict # File predictions for a task
|
|
227
|
-
npx cto-ai-cli --learn --json # Export learning data
|
|
228
|
-
|
|
229
|
-
# CI/CD
|
|
230
|
-
npx cto-ai-cli --ci # Quality gate
|
|
231
|
-
npx cto-ai-cli --ci --threshold 80 # Custom threshold
|
|
232
|
-
|
|
233
|
-
# Monorepo
|
|
234
|
-
npx cto-ai-cli --monorepo # Full monorepo analysis
|
|
235
|
-
npx cto-ai-cli --monorepo --package X # Single package
|
|
236
|
-
|
|
237
|
-
# Gateway (AI proxy)
|
|
238
|
-
npx cto-gateway # Start proxy server
|
|
239
|
-
npx cto-gateway --budget-daily 10 # With budget enforcement
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
---
|
|
243
|
-
|
|
244
|
-
## MCP Server (for AI Editors)
|
|
98
|
+
**3 tools:** `cto_select_context`, `cto_audit_secrets`, `cto_explain`
|
|
245
99
|
|
|
246
|
-
CTO works as an [MCP server](https://modelcontextprotocol.io/) — plug it into Claude, Windsurf, or Cursor.
|
|
247
|
-
|
|
248
|
-
**Windsurf** — add to `~/.codeium/windsurf/mcp_config.json`:
|
|
249
100
|
```json
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
"cto": { "command": "cto-mcp" }
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
```
|
|
101
|
+
// Windsurf: ~/.codeium/windsurf/mcp_config.json
|
|
102
|
+
{ "mcpServers": { "cto": { "command": "cto-mcp" } } }
|
|
256
103
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
{
|
|
260
|
-
"mcpServers": {
|
|
261
|
-
"cto": { "command": "npx", "args": ["-y", "cto-ai-cli", "--mcp"] }
|
|
262
|
-
}
|
|
263
|
-
}
|
|
104
|
+
// Claude Desktop
|
|
105
|
+
{ "mcpServers": { "cto": { "command": "npx", "args": ["-y", "cto-ai-cli"] } } }
|
|
264
106
|
```
|
|
265
107
|
|
|
266
|
-
|
|
108
|
+
MCP output is also auto-sanitized when `includeContents: true`.
|
|
267
109
|
|
|
268
|
-
|
|
110
|
+
## How it works
|
|
111
|
+
|
|
112
|
+
1. **Dependency graph** — parses imports, builds adjacency list, identifies hubs
|
|
113
|
+
2. **Risk scoring** — complexity × centrality × recency (continuous, log-scaled)
|
|
114
|
+
3. **TF-IDF/BM25 semantic matching** — task description scored against all file contents + path boosting
|
|
115
|
+
4. **Composite ranking** — `finalScore = risk × 0.4 + semantic × 0.4 + learner × 0.2`
|
|
116
|
+
5. **Greedy allocation** — fills token budget top-down, cascading prune levels (full → signatures → skeleton)
|
|
117
|
+
6. **Bayesian learning** — exponential decay on priors, Wilson score confidence, per-task-type patterns
|
|
118
|
+
|
|
119
|
+
No AI is used for selection. Same input → same output. Deterministic.
|
|
269
120
|
|
|
270
121
|
## Programmatic API
|
|
271
122
|
|
|
272
123
|
```typescript
|
|
273
|
-
import { analyzeProject,
|
|
124
|
+
import { analyzeProject, selectContext, buildIndex, query } from 'cto-ai-cli';
|
|
274
125
|
|
|
275
|
-
// Analyze a project
|
|
276
126
|
const analysis = await analyzeProject('./my-project');
|
|
127
|
+
const index = buildIndex(files);
|
|
128
|
+
const semanticScores = query(index, 'fix auth', 50)
|
|
129
|
+
.map(m => ({ filePath: m.filePath, score: m.score }));
|
|
277
130
|
|
|
278
|
-
// Get the Context Score
|
|
279
|
-
const score = await computeContextScore(analysis);
|
|
280
|
-
console.log(`Score: ${score.overall}/100 (${score.grade})`);
|
|
281
|
-
console.log(`Tokens saved: ${score.comparison.savedPercent}%`);
|
|
282
|
-
|
|
283
|
-
// Select optimal files for a task
|
|
284
131
|
const selection = await selectContext({
|
|
285
|
-
task: '
|
|
132
|
+
task: 'fix auth',
|
|
286
133
|
analysis,
|
|
287
|
-
budget: 50_000,
|
|
134
|
+
budget: 50_000,
|
|
135
|
+
semanticScores, // wired into ranking
|
|
288
136
|
});
|
|
289
|
-
|
|
290
|
-
console.log(`Selected ${selection.files.length} files`);
|
|
291
|
-
console.log(`Coverage: ${selection.coverage.score}%`);
|
|
292
|
-
for (const file of selection.files) {
|
|
293
|
-
console.log(` ${file.relativePath} (${file.tokens} tokens, risk: ${file.riskScore})`);
|
|
294
|
-
}
|
|
295
137
|
```
|
|
296
138
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
## How It Works
|
|
300
|
-
|
|
301
|
-
1. **Scan** — walks your project, parses imports, builds a dependency graph
|
|
302
|
-
2. **Score** — computes risk for each file (complexity, hub score, centrality, recency)
|
|
303
|
-
3. **Select** — deterministic greedy algorithm: picks highest-risk files first within token budget
|
|
304
|
-
4. **Prove** — measures coverage (% of important files included), compares vs naive strategies
|
|
139
|
+
## Honest limitations
|
|
305
140
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
## Honest Limitations
|
|
311
|
-
|
|
312
|
-
- **TypeScript/JavaScript gets the deepest analysis.** Other languages (Python, Go, Rust, Java) get basic file + import analysis.
|
|
313
|
-
- **Benchmarks use simple baselines** (alphabetical, random). We haven't compared against Cursor's or Copilot's internal context selection.
|
|
314
|
-
- **Savings are estimates** based on average API pricing. Actual savings depend on your model and usage.
|
|
315
|
-
- **Risk scoring uses a complexity proxy** instead of real git churn data (planned improvement).
|
|
316
|
-
|
|
317
|
-
---
|
|
141
|
+
- **TypeScript/JavaScript gets deep analysis.** Other languages get basic file + import analysis.
|
|
142
|
+
- **TF-IDF, not embeddings.** Handles most tasks well but won't understand complex intent.
|
|
143
|
+
- **Learning needs ~5 feedback cycles** to start influencing selection. First runs are pure graph + risk + semantic.
|
|
144
|
+
- **Not compared against Cursor/Copilot internal context.** Our baselines are naive (alphabetical, random).
|
|
318
145
|
|
|
319
146
|
## Contributing
|
|
320
147
|
|
|
321
148
|
```bash
|
|
322
|
-
git clone https://github.com/cto-ai/cto-ai-cli.git
|
|
323
|
-
|
|
324
|
-
npm install
|
|
325
|
-
npm run build
|
|
326
|
-
npm test # 376 tests
|
|
327
|
-
npm run typecheck # strict TypeScript, zero errors
|
|
149
|
+
git clone https://github.com/cto-ai/cto-ai-cli.git && cd cto-ai-cli
|
|
150
|
+
npm install && npm run build && npm test # 597 tests
|
|
328
151
|
```
|
|
329
152
|
|
|
330
|
-
Full API docs, MCP server reference, and architecture are in [DOCS.md](DOCS.md).
|
|
331
|
-
|
|
332
153
|
## License
|
|
333
154
|
|
|
334
155
|
[MIT](LICENSE)
|