cto-ai-cli 3.2.0 → 5.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/README.md CHANGED
@@ -1,360 +1,332 @@
1
- # CTO — Your AI is reading too much code. We fix that.
2
-
3
- > **Early access** — This is a test version. We'd love your feedback.
1
+ # CTO — Stop sending your entire codebase to AI
4
2
 
5
3
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
- [![Tests](https://img.shields.io/badge/tests-449_passing-brightgreen.svg)](#)
4
+ [![Tests](https://img.shields.io/badge/tests-376_passing-brightgreen.svg)](#)
5
+ [![npm](https://img.shields.io/npm/v/cto-ai-cli.svg)](https://www.npmjs.com/package/cto-ai-cli)
7
6
 
8
- ## Try it now (zero install)
7
+ CTO analyzes your project and selects the **minimum set of files** your AI needs — saving tokens, reducing cost, and producing code that actually compiles.
9
8
 
10
9
  ```bash
11
10
  npx cto-ai-cli
12
11
  ```
13
12
 
14
- That's it. Run it on any project. You'll see something like this:
13
+ **Runs in <1 second.** No API keys. No data leaves your machine.
14
+
15
+ ---
16
+
17
+ ## The Problem
18
+
19
+ When you ask an AI to help with code, it needs context. Most approaches:
20
+
21
+ - **Send everything** — expensive, noisy, AI gets confused
22
+ - **Send open files** — misses types, dependencies, config
23
+ - **Let the AI pick** — it doesn't know your dependency graph
24
+
25
+ The result: AI generates code that **doesn't compile** because it never saw your type definitions.
15
26
 
27
+ ## The Fix
28
+
29
+ ```bash
30
+ $ npx cto-ai-cli ./my-project
31
+ ```
16
32
  ```
17
33
  ⚡ cto-score — analyzing your project...
18
34
 
19
35
  ╔══════════════════════════════════════════════════╗
20
36
  ║ ║
21
- ║ 🟢 Context Score™ 87 / 100 Grade: A-
37
+ ║ 🟢 Context Score™ 88 / 100 Grade: A-
22
38
  ║ ║
23
- ║ Efficiency ███████████████░░░░░ 74% ║
39
+ ║ Efficiency ████████████████░░░░ 80% ║
24
40
  ║ Coverage ████████████████████ 100% ║
25
41
  ║ Risk Control ████████████████████ 100% ║
42
+ ║ Structure █░░░░░░░░░░░░░░░░░░ 5% ║
43
+ ║ Governance ██████████████████░ 90% ║
26
44
  ║ ║
27
45
  ║ 💰 vs. Sending Everything: ║
28
- ║ Tokens saved: 289K (85%) ║
29
- ║ Monthly savings: ~$695
46
+ ║ Tokens saved: 392K (88%) ║
47
+ ║ Monthly savings: ~$943
30
48
  ║ ║
31
49
  ╚══════════════════════════════════════════════════╝
32
50
 
33
- Scanned in 11.7s · 177 files · 340K tokens
51
+ Scanned in 0.6s · 199 files · 443K tokens
34
52
  ```
35
53
 
36
- Run `npx cto-ai-cli --benchmark` to see how CTO compares to naive (alphabetical) and random file selection.
54
+ ### What each number means
37
55
 
38
- No data leaves your machine. No API keys. MIT licensed.
56
+ | Metric | What it measures | Why it matters |
57
+ |--------|-----------------|----------------|
58
+ | **Context Score (88/100)** | Overall AI-readiness of your project | Higher = AI tools produce better output with your code |
59
+ | **Efficiency (80%)** | How much CTO can compress without losing value | 80% means we send 20% of tokens for the same quality |
60
+ | **Coverage (100%)** | % of important files included in the selection | 100% = every dependency and type file is captured |
61
+ | **Risk Control (100%)** | Are high-risk files (hubs, complex code) prioritized? | Ensures AI sees the files most likely to cause bugs |
62
+ | **Structure (5%)** | How well-organized your codebase is for AI | Low = too many large files, poor modularity |
63
+ | **Governance (90%)** | Audit logging, policy enforcement, secret scanning | Enterprise readiness |
64
+ | **Tokens saved (88%)** | Reduction vs. sending every file | Directly reduces your API costs |
65
+ | **Monthly savings ($943)** | Estimated cost reduction at 800 interactions/month | Based on average GPT-4o pricing |
39
66
 
40
67
  ---
41
68
 
42
- ## What problem does CTO solve?
43
-
44
- When you ask an AI assistant to help with code, it needs context — your files. The question is: **which files?**
45
-
46
- **Most tools today** either send everything (expensive, noisy) or pick files based on what's open (misses dependencies). Neither approach is great.
47
-
48
- **CTO analyzes your project** — dependencies, file importance, risk of excluding each file — and picks the best subset that fits your token budget. It's like a smart assistant that knows which files matter for each task.
49
-
50
- ### A simple example
69
+ ## Quick Start
51
70
 
52
- You ask the AI: *"refactor the auth middleware"*
71
+ ### Score your project
53
72
 
54
- | Approach | What gets sent | Result |
55
- |----------|---------------|--------|
56
- | **Send everything** | 340K tokens (all 177 files) | Expensive. AI drowns in irrelevant code. |
57
- | **Send open files** | Whatever you have open | Might miss types, dependencies, config. |
58
- | **CTO** | 50K tokens (93 relevant files) | 85% cheaper. Includes types, deps, related files. |
59
-
60
- ### Why does it matter?
61
-
62
- We tested something specific: when the AI generates code, does it have the type definitions it needs?
63
-
64
- | | CTO | Without CTO |
65
- |--|-----|-------------|
66
- | **Type files included** | 5 out of 6 | **0 out of 6** |
67
- | **TypeScript compiler** | ✅ Compiles | ❌ 4 errors |
68
-
69
- We ran this on 5 different tasks. Same result every time. CTO context compiles. Naive context doesn't.
70
-
71
- Without type definitions, the AI invents interfaces — wrong property names, wrong shapes. The code doesn't compile. ([Details](#compile-proof))
72
-
73
- ---
74
-
75
- ## Getting started
73
+ ```bash
74
+ npx cto-ai-cli # Analyze current directory
75
+ npx cto-ai-cli ./my-project # Analyze a specific project
76
+ npx cto-ai-cli --json # Machine-readable JSON output
77
+ ```
76
78
 
77
- ### Option 1: Quick score (no install)
79
+ ### Generate optimized context for AI
78
80
 
79
81
  ```bash
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)
82
+ npx cto-ai-cli --fix
89
83
  ```
90
84
 
91
- ### Option 2: Full install
85
+ Creates `.cto/context.md` paste this into any AI chat for optimal context. Also generates `.cto/config.json` and `.cto/.cteignore`.
92
86
 
93
87
  ```bash
94
- npm install -g cto-ai-cli
95
-
96
- cto2 init # Set up for your project
97
- cto2 analyze # See structure + risk profile
98
- cto2 interact "refactor the auth middleware" # Get optimized context for a task
88
+ npx cto-ai-cli --context "refactor the auth middleware"
99
89
  ```
100
90
 
101
- ### Option 3: Use with your AI editor (MCP)
102
-
103
- CTO works as an [MCP server](https://modelcontextprotocol.io/) — plug it into Claude, Windsurf, or Cursor.
91
+ Generates **task-specific** context only files relevant to auth, including types, dependencies, and related tests.
104
92
 
105
- **Windsurf** — add to `~/.codeium/windsurf/mcp_config.json`:
106
- ```json
107
- {
108
- "mcpServers": {
109
- "cto": { "command": "cto2-mcp" }
110
- }
111
- }
93
+ Example output:
112
94
  ```
113
-
114
- **Claude Desktop** — add to your MCP config:
115
- ```json
116
- {
117
- "mcpServers": {
118
- "cto": { "command": "node", "args": ["/path/to/dist/mcp/v2.js"] }
119
- }
120
- }
95
+ 📋 Context for: "refactor the auth middleware"
96
+
97
+ Selected 12 files (8.2K tokens):
98
+
99
+ ┌─ Core (3 files) ─────────────────────────────
100
+ │ src/middleware/auth.ts 2,100 tokens
101
+ │ src/types/auth.ts 450 tokens
102
+ │ src/config/jwt.ts 320 tokens
103
+
104
+ ├─ Dependencies (5 files) ─────────────────────
105
+ │ src/models/user.ts 1,200 tokens
106
+ │ src/services/token.ts 890 tokens
107
+ │ ...
108
+
109
+ └─ Tests (2 files) ────────────────────────────
110
+ tests/auth.test.ts 1,800 tokens
111
+ tests/middleware.test.ts 940 tokens
112
+
113
+ Saved to .cto/context.md (8.2K tokens — 97% smaller than full project)
121
114
  ```
122
115
 
123
- Once connected, your AI editor can use tools like `cto_analyze`, `cto_select_context`, `cto_score`, and `cto_benchmark` automatically.
124
-
125
- ---
116
+ ### Security audit
126
117
 
127
- ## How it works (the short version)
118
+ ```bash
119
+ npx cto-ai-cli --audit
120
+ ```
128
121
 
129
- 1. **Scans** your project files, imports, dependencies, structure
130
- 2. **Scores** each file — how important is it? What breaks if we exclude it?
131
- 3. **Selects** the best files for your task — within your token budget
132
- 4. **Proves** the result — coverage score, benchmark comparison, cost savings
122
+ Scans for **API keys, tokens, passwords, and PII** before they end up in an AI prompt. 45+ patterns (AWS, Stripe, GitHub, OpenAI, etc.) plus Shannon entropy analysis for unknown formats.
133
123
 
134
- CTO doesn't use AI for selection. It uses dependency analysis, risk modeling, and optimization algorithms. Same input always produces the same output.
124
+ ```
125
+ 🔴 CRITICAL src/config/stripe.ts:8
126
+ api-key: sk_l********************yZ
127
+ 🔴 CRITICAL src/config/database.ts:14
128
+ connection-string: post********************db
129
+ 🟠 HIGH src/utils/email.ts:22
130
+ pii: admi**********om
135
131
 
136
- ---
132
+ 🚨 3 critical findings. Rotate credentials immediately.
133
+ ```
137
134
 
138
- ## Real numbers
135
+ Run in CI to block PRs with secrets: `CI=true npx cto-ai-cli --audit`
139
136
 
140
- We ran CTO on three open-source projects. No cherry-picking — you can reproduce these with `npx cto-ai-cli --benchmark`.
137
+ ### Code review intelligence
141
138
 
142
- | Project | Files | Score | What CTO does |
143
- |---------|-------|-------|---------------|
144
- | **Zod** | 441 files, 804K tokens | 92/100 (A) | Selects 64 files, 100% coverage, $1,809/mo savings |
145
- | **This project** | 177 files, 340K tokens | 87/100 (A-) | Selects 93 files, 100% coverage, $695/mo savings |
146
- | **Express.js** | 158 files, 171K tokens | 74/100 (B-) | Needs only 895 tokens for full coverage |
139
+ ```bash
140
+ npx cto-ai-cli --review
141
+ ```
147
142
 
148
- "Coverage" means: all the files that are important for your task are included. "Savings" is estimated based on 800 AI interactions per month.
143
+ Analyzes your git diff and generates a structured review:
149
144
 
150
- <details>
151
- <summary><b>Detailed comparison: CTO vs Naive vs Random</b></summary>
145
+ ```
146
+ 📊 Review Quality: 82/100 (B+)
152
147
 
153
- > Budget: 50K tokens · Task: "refactor the core module"
148
+ Breaking Changes:
149
+ 🔴 Removed export: UserService.findById (used by 4 files)
150
+ 🟡 Changed signature: authenticate(token) → authenticate(token, opts)
154
151
 
155
- | Project | Strategy | Files | Tokens | Coverage | High-Risk Included |
156
- |---------|----------|-------|--------|----------|-------------------|
157
- | **Zod** | **CTO** | 64 | 50.0K | **100%** | **6/6** |
158
- | | Naive (alphabetical) | 71 | 50.0K | 16% | 2/6 |
159
- | | Random | 45 | 50.0K | 10% | 1/6 |
160
- | **CTO** | **CTO** | 163 | 47.4K | **100%** | **11/11** |
161
- | | Naive | 25 | 50.0K | 15% | 0/11 |
162
- | | Random | 38 | 50.0K | 23% | 6/11 |
163
- | **Express** | **CTO** | 158 | 0.9K | **100%** | n/a |
164
- | | Naive | 64 | 50.0K | 41% | n/a |
165
- | | Random | 61 | 50.0K | 39% | n/a |
152
+ Missing Files:
153
+ ⚠️ No test file for src/services/auth.ts
154
+ ⚠️ src/types/user.ts changed but barrel index not updated
166
155
 
167
- **Note:** "Naive" means alphabetical file order (a common default). "Random" is random selection. These are simple baselines — real-world tools like Cursor use smarter heuristics, so we don't claim CTO beats them. We just show the difference between informed and uninformed selection.
156
+ Impact Radius:
157
+ Direct: 4 files | Transitive: 12 files | Tests: 3 files
168
158
 
169
- </details>
159
+ Saved review prompt to .cto/review-prompt.md
160
+ ```
170
161
 
171
- <details id="compile-proof">
172
- <summary><b>Compile Proof: real TypeScript compiler output</b></summary>
162
+ | What it detects | Example |
163
+ |-----------------|--------|
164
+ | **Breaking changes** | Removed exports, changed function signatures, deleted files |
165
+ | **Missing files** | Tests, type files, barrel exports, importers of changed code |
166
+ | **Impact radius** | How many files are affected (direct + transitive via BFS) |
167
+ | **Review quality** | Score based on PR size, focus, breaking changes, completeness |
173
168
 
174
- We ran the actual `tsc` compiler to verify this isn't just theory.
169
+ ### Learning mode
175
170
 
176
- **How it works:**
177
- 1. Copy only the selected files (CTO or naive) to a temp directory
178
- 2. Generate TypeScript code that imports and uses the project's types
179
- 3. Run `tsc --noEmit`
180
- 4. Count real compiler errors
171
+ ```bash
172
+ npx cto-ai-cli --learn # View feedback model & stats
173
+ npx cto-ai-cli --predict # Predict relevant files for a task
174
+ npx cto-ai-cli --learn --json # Export learning data for team sharing
175
+ ```
181
176
 
182
- | Task | CTO | Naive | Naive missing |
183
- |------|-----|-------|--------------|
184
- | Refactor selector | ✅ 0 errors | ❌ 4 errors | All type files |
185
- | Optimize risk scoring | ✅ 0 errors | ❌ 4 errors | All type files |
186
- | MCP error handling | ✅ 0 errors | ❌ 4 errors | All type files |
187
- | Cache invalidation | ✅ 0 errors | ❌ 4 errors | All type files |
188
- | Add semantic tool | ✅ 0 errors | ❌ 4 errors | All type files |
177
+ CTO learns from your usage patterns over time. Uses **EWMA temporal decay** (recent feedback weighs more) and **Bayesian confidence** (Wilson score — avoids over-trusting sparse data).
189
178
 
190
- The naive selection (alphabetical) consistently misses all type definition files. The compiler output:
179
+ ### Quality gate for CI/CD
191
180
 
192
- ```
193
- error TS2307: Cannot find module './src/types/engine.js'
194
- error TS2307: Cannot find module './src/types/config.js'
195
- error TS2307: Cannot find module './src/types/govern.js'
196
- error TS2307: Cannot find module './src/types/interact.js'
181
+ ```bash
182
+ npx cto-ai-cli --ci # Run quality gate (exits 1 on failure)
183
+ npx cto-ai-cli --ci --threshold 80 # Custom minimum score
184
+ npx cto-ai-cli --ci --json # JSON for pipeline parsing
197
185
  ```
198
186
 
199
- Without these files, the AI has to guess the shape of `AnalyzedFile`, `ContextSelection`, `TaskType`, etc. It will get them wrong.
187
+ Block merges when context quality drops below your threshold. Tracks baselines and detects regressions.
200
188
 
201
- </details>
189
+ ### Monorepo support
202
190
 
203
- ---
191
+ ```bash
192
+ npx cto-ai-cli --monorepo # Analyze all packages
193
+ npx cto-ai-cli --monorepo --package api # Focus on one package
194
+ ```
204
195
 
205
- ## 🔒 Security Audit detect secrets before AI sees them
196
+ Detects npm/yarn/pnpm workspaces, Turborepo, Nx, and Lerna. Shows cross-package dependencies, isolation scores, and shared package analysis.
206
197
 
207
- Every time you send code to an AI, there's a risk: **API keys, tokens, passwords, and PII hiding in your codebase.**
198
+ ---
208
199
 
209
- CTO now scans your entire project for secrets — before they end up in an AI prompt.
200
+ ## All CLI Flags
210
201
 
211
202
  ```bash
212
- npx cto-ai-cli --audit
213
- ```
214
-
203
+ # Analysis
204
+ npx cto-ai-cli [path] # Score a project
205
+ npx cto-ai-cli --json # JSON output
206
+ npx cto-ai-cli --benchmark # CTO vs naive vs random comparison
207
+ npx cto-ai-cli --compare # Compare vs popular OSS projects
208
+ npx cto-ai-cli --report # Markdown report + badge
209
+
210
+ # Context generation
211
+ npx cto-ai-cli --fix # Auto-generate .cto/context.md
212
+ npx cto-ai-cli --context "task" # Task-specific context
213
+
214
+ # Security
215
+ npx cto-ai-cli --audit # Secret & PII detection
216
+ npx cto-ai-cli --audit --full-scan # Scan all files (ignore cache)
217
+ npx cto-ai-cli --audit --init-hook # Install pre-commit hook
218
+
219
+ # Code review
220
+ npx cto-ai-cli --review # PR review analysis
221
+ npx cto-ai-cli --review --json # Review data as JSON
222
+
223
+ # Learning
224
+ npx cto-ai-cli --learn # Feedback model dashboard
225
+ npx cto-ai-cli --predict # File predictions for a task
226
+ npx cto-ai-cli --learn --json # Export learning data
227
+
228
+ # CI/CD
229
+ npx cto-ai-cli --ci # Quality gate
230
+ npx cto-ai-cli --ci --threshold 80 # Custom threshold
231
+
232
+ # Monorepo
233
+ npx cto-ai-cli --monorepo # Full monorepo analysis
234
+ npx cto-ai-cli --monorepo --package X # Single package
235
+
236
+ # Gateway (AI proxy)
237
+ npx cto-gateway # Start proxy server
238
+ npx cto-gateway --budget-daily 10 # With budget enforcement
215
239
  ```
216
- 🔍 Running security audit...
217
240
 
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
241
+ ---
242
242
 
243
- Recommendations:
243
+ ## MCP Server (for AI Editors)
244
244
 
245
- 🚨 CRITICAL: Rotate all detected credentials immediately.
246
- 💡 Use environment variables for API keys.
247
- 💡 Add a .gitignore entry for .env files.
245
+ CTO works as an [MCP server](https://modelcontextprotocol.io/) — plug it into Claude, Windsurf, or Cursor.
248
246
 
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
247
+ **Windsurf** add to `~/.codeium/windsurf/mcp_config.json`:
248
+ ```json
249
+ {
250
+ "mcpServers": {
251
+ "cto": { "command": "cto-mcp" }
252
+ }
253
+ }
253
254
  ```
254
255
 
255
- ### What it detects
256
+ **Claude Desktop:**
257
+ ```json
258
+ {
259
+ "mcpServers": {
260
+ "cto": { "command": "npx", "args": ["-y", "cto-ai-cli", "--mcp"] }
261
+ }
262
+ }
263
+ ```
256
264
 
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 |
265
+ Tools available: `cto_analyze`, `cto_select_context`, `cto_score`, `cto_benchmark`, `cto_risk`, and more.
267
266
 
268
- ### How it works
267
+ ---
269
268
 
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`)
269
+ ## Programmatic API
274
270
 
275
- ### What it generates
271
+ ```typescript
272
+ import { analyzeProject, computeContextScore, selectContext } from 'cto-ai-cli';
276
273
 
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 |
274
+ // Analyze a project
275
+ const analysis = await analyzeProject('./my-project');
282
276
 
283
- ### CI/CD integration
277
+ // Get the Context Score
278
+ const score = await computeContextScore(analysis);
279
+ console.log(`Score: ${score.overall}/100 (${score.grade})`);
280
+ console.log(`Tokens saved: ${score.comparison.savedPercent}%`);
284
281
 
285
- Set `CI=true` and the audit will **exit with code 1** if critical or high-severity secrets are found:
282
+ // Select optimal files for a task
283
+ const selection = await selectContext({
284
+ task: 'refactor the auth middleware',
285
+ analysis,
286
+ budget: 50_000, // 50K token budget
287
+ });
286
288
 
287
- ```bash
288
- CI=true npx cto-ai-cli --audit
289
+ console.log(`Selected ${selection.files.length} files`);
290
+ console.log(`Coverage: ${selection.coverage.score}%`);
291
+ for (const file of selection.files) {
292
+ console.log(` ${file.relativePath} (${file.tokens} tokens, risk: ${file.riskScore})`);
293
+ }
289
294
  ```
290
295
 
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
- ## What you can do with CTO
305
-
306
- | Use case | How |
307
- |----------|-----|
308
- | **Score your project** | `npx cto-ai-cli` |
309
- | **Auto-optimize context** | `npx cto-ai-cli --fix` → generates `.cto/context.md` to paste into AI |
310
- | **Task-specific context** | `npx cto-ai-cli --context "refactor auth"` → optimized for your task |
311
- | **Security audit** | `npx cto-ai-cli --audit` → detect secrets & PII before AI sees them |
312
- | **Shareable report** | `npx cto-ai-cli --report` → markdown report + README badge |
313
- | **Compare vs open source** | `npx cto-ai-cli --compare` → your score vs Zod, Next.js, Express |
314
- | **Compare strategies** | `npx cto-ai-cli --benchmark` → CTO vs naive vs random |
315
- | **Get context for a task** | `cto2 interact "your task"` |
316
- | **Use in your AI editor** | Add MCP server (see setup above) |
317
- | **Block secrets in CI** | `CI=true npx cto-ai-cli --audit` |
318
- | **JSON output (scripting)** | `npx cto-ai-cli --json` |
319
-
320
296
  ---
321
297
 
322
- ## Honest limitations
298
+ ## How It Works
323
299
 
324
- This is an early test version. Here's what we know:
300
+ 1. **Scan** walks your project, parses imports, builds a dependency graph
301
+ 2. **Score** — computes risk for each file (complexity, hub score, centrality, recency)
302
+ 3. **Select** — deterministic greedy algorithm: picks highest-risk files first within token budget
303
+ 4. **Prove** — measures coverage (% of important files included), compares vs naive strategies
325
304
 
326
- - **TypeScript/JavaScript projects work best.** We support other languages (Python, Go, Rust, Java) for basic analysis, but TypeScript gets the deepest understanding.
327
- - **Our benchmarks use simple baselines** (alphabetical, random). We haven't compared against Cursor's or Copilot's internal context selection.
328
- - **The savings numbers are estimates** based on average API pricing. Your actual savings depend on your model, pricing tier, and usage patterns.
329
- - **We need more projects to test on.** If you try it and share your score, that helps us a lot.
305
+ No AI is used for selection. Same input always produces the same output. Fully reproducible.
330
306
 
331
307
  ---
332
308
 
333
- ## What's next
309
+ ## Honest Limitations
334
310
 
335
- We're working on:
336
- - **Context Gateway** proxy between your team and any AI, with automatic context optimization and cost tracking
337
- - **Monorepo intelligence** package-aware selection for large monorepos (60-80% more token savings)
338
- - **CI Quality Gate** GitHub Action that posts context score and secret audit on every PR
339
- - **VS Code extension** — live score, risk indicators, and context suggestions inline
340
- - **Learning mode** — CTO improves based on which AI suggestions you accept/reject
341
- - **More language support** — deeper analysis for Python, Go, and Rust
342
- - **Your feedback** — [open an issue](https://github.com/cto-ai/cto-ai-cli/issues) or reach out
311
+ - **TypeScript/JavaScript gets the deepest analysis.** Other languages (Python, Go, Rust, Java) get basic file + import analysis.
312
+ - **Benchmarks use simple baselines** (alphabetical, random). We haven't compared against Cursor's or Copilot's internal context selection.
313
+ - **Savings are estimates** based on average API pricing. Actual savings depend on your model and usage.
314
+ - **Risk scoring uses a complexity proxy** instead of real git churn data (planned improvement).
343
315
 
344
316
  ---
345
317
 
346
- ## For contributors
318
+ ## Contributing
347
319
 
348
320
  ```bash
349
- git clone <repo-url>
350
- cd cto
321
+ git clone https://github.com/cto-ai/cto-ai-cli.git
322
+ cd cto-ai-cli
351
323
  npm install
352
324
  npm run build
353
- npm test # 449 tests
354
- npm run typecheck # strict TypeScript
325
+ npm test # 376 tests
326
+ npm run typecheck # strict TypeScript, zero errors
355
327
  ```
356
328
 
357
- Full CLI docs, MCP server setup, API server, and programmatic API are documented in [DOCS.md](DOCS.md).
329
+ Full API docs, MCP server reference, and architecture are in [DOCS.md](DOCS.md).
358
330
 
359
331
  ## License
360
332