cto-ai-cli 4.0.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/DOCS.md +201 -2
- package/README.md +216 -312
- package/dist/action/index.js +271 -156
- package/dist/api/dashboard.js +271 -156
- package/dist/api/dashboard.js.map +1 -1
- package/dist/api/server.js +276 -155
- package/dist/api/server.js.map +1 -1
- package/dist/cli/gateway.js +298 -183
- package/dist/cli/score.js +1396 -241
- package/dist/cli/v2/index.js +290 -175
- package/dist/cli/v2/index.js.map +1 -1
- package/dist/engine/index.d.ts +121 -1
- package/dist/engine/index.js +1035 -212
- package/dist/engine/index.js.map +1 -1
- package/dist/fsevents-X6WP4TKM.node +0 -0
- package/dist/gateway/index.js +298 -183
- package/dist/gateway/index.js.map +1 -1
- package/dist/interact/index.js +263 -148
- package/dist/interact/index.js.map +1 -1
- package/dist/mcp/v2.js +287 -172
- package/dist/mcp/v2.js.map +1 -1
- package/package.json +8 -22
package/DOCS.md
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
- [CLI Commands](#cli-commands)
|
|
8
8
|
- [Security Audit](#security-audit---audit)
|
|
9
9
|
- [Context Gateway](#context-gateway)
|
|
10
|
+
- [Learning Mode](#learning-mode)
|
|
11
|
+
- [Code Review](#code-review)
|
|
10
12
|
- [MCP Server](#mcp-server)
|
|
11
13
|
- [API Server](#api-server)
|
|
12
14
|
- [Programmatic API](#programmatic-api)
|
|
@@ -100,6 +102,21 @@ npx cto-ai-cli --compare # Compare your score vs popular open so
|
|
|
100
102
|
npx cto-ai-cli --benchmark # CTO vs naive vs random comparison
|
|
101
103
|
npx cto-ai-cli --json # Machine-readable JSON output
|
|
102
104
|
npx cto-ai-cli --help # Show all options
|
|
105
|
+
|
|
106
|
+
# Phase 5 — CI/CD Quality Gate
|
|
107
|
+
npx cto-ai-cli --ci # Run quality gate (exits 1 on failure)
|
|
108
|
+
npx cto-ai-cli --ci --threshold 80 # Set minimum score (default: 70)
|
|
109
|
+
npx cto-ai-cli --ci --json # JSON output for CI pipelines
|
|
110
|
+
|
|
111
|
+
# Phase 7 — Learning Mode
|
|
112
|
+
npx cto-ai-cli --learn # Show feedback model & cross-repo intelligence
|
|
113
|
+
npx cto-ai-cli --feedback # Alias for --learn
|
|
114
|
+
npx cto-ai-cli --predict # Predict relevant files for a task
|
|
115
|
+
npx cto-ai-cli --learn --json # Export learning data as JSON
|
|
116
|
+
|
|
117
|
+
# Phase 8 — Code Review
|
|
118
|
+
npx cto-ai-cli --review # Smart PR review analysis
|
|
119
|
+
npx cto-ai-cli --review --json # JSON output for CI
|
|
103
120
|
```
|
|
104
121
|
|
|
105
122
|
Flags can be combined: `npx cto-ai-cli --fix --audit --report --compare`
|
|
@@ -437,6 +454,185 @@ const result = await interceptRequest(messages, config, analysis);
|
|
|
437
454
|
|
|
438
455
|
---
|
|
439
456
|
|
|
457
|
+
## Learning Mode
|
|
458
|
+
|
|
459
|
+
CTO learns from your usage patterns to improve context selection over time. Three engines work together:
|
|
460
|
+
|
|
461
|
+
### Feedback Engine (`--learn` / `--feedback`)
|
|
462
|
+
|
|
463
|
+
Tracks which context selections lead to accepted AI output.
|
|
464
|
+
|
|
465
|
+
```bash
|
|
466
|
+
npx cto-ai-cli --learn # Full learning dashboard
|
|
467
|
+
npx cto-ai-cli --learn --json # Export for team sharing
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
**v2.0 Features:**
|
|
471
|
+
|
|
472
|
+
| Feature | Description |
|
|
473
|
+
|---------|-------------|
|
|
474
|
+
| **EWMA Temporal Decay** | Recent feedback weighs more (α=0.15). Old patterns fade naturally. |
|
|
475
|
+
| **Bayesian Confidence (Wilson Score)** | Avoids over-trusting sparse data. 1/1 ≠ 100% confidence. |
|
|
476
|
+
| **Session Tracking** | Groups related feedback for per-session analysis. |
|
|
477
|
+
| **A/B Strategy Comparison** | Compare different context strategies with statistical rigor. |
|
|
478
|
+
| **Team Export/Import** | Share learned models across teams with weighted merge (local 70%, team 30%). |
|
|
479
|
+
|
|
480
|
+
### Predictor Engine (`--predict`)
|
|
481
|
+
|
|
482
|
+
Predicts which files are relevant for a task based on historical patterns.
|
|
483
|
+
|
|
484
|
+
```bash
|
|
485
|
+
npx cto-ai-cli --predict --context "fix auth bug" # Predict files for a task
|
|
486
|
+
npx cto-ai-cli --predict --json # JSON predictions
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
The predictor uses:
|
|
490
|
+
- **Task type frequency** — which files were selected for similar task types (3× weight)
|
|
491
|
+
- **Keyword frequency** — which files correlate with task keywords (2× weight)
|
|
492
|
+
- **General selection frequency** — files selected in >30% of all observations
|
|
493
|
+
- **Co-selection patterns** — files that tend to be selected together
|
|
494
|
+
|
|
495
|
+
### Cross-Repo Intelligence
|
|
496
|
+
|
|
497
|
+
Learns patterns across repositories. Stored in `~/.cto/global-intelligence.json`.
|
|
498
|
+
|
|
499
|
+
- **Project fingerprinting** — stack, size class, structure pattern
|
|
500
|
+
- **Archetype matching** — "TypeScript medium-size projects with tests"
|
|
501
|
+
- **Universal patterns** — patterns that work across >50% of project types
|
|
502
|
+
|
|
503
|
+
### Programmatic API
|
|
504
|
+
|
|
505
|
+
```typescript
|
|
506
|
+
import {
|
|
507
|
+
recordFeedback,
|
|
508
|
+
loadFeedbackModel,
|
|
509
|
+
getFeedbackBoosts,
|
|
510
|
+
exportFeedbackForTeam,
|
|
511
|
+
importTeamFeedback,
|
|
512
|
+
wilsonLowerBound,
|
|
513
|
+
renderFeedbackReport,
|
|
514
|
+
renderCrossRepoReport,
|
|
515
|
+
} from 'cto-ai-cli/engine';
|
|
516
|
+
import {
|
|
517
|
+
recordSelection,
|
|
518
|
+
predictRelevantFiles,
|
|
519
|
+
getPredictorBoosts,
|
|
520
|
+
loadModel,
|
|
521
|
+
getModelStats,
|
|
522
|
+
} from 'cto-ai-cli/engine';
|
|
523
|
+
import {
|
|
524
|
+
recordCrossRepoSelection,
|
|
525
|
+
predictFromCrossRepo,
|
|
526
|
+
loadGlobalModel,
|
|
527
|
+
getCrossRepoStats,
|
|
528
|
+
computeFingerprint,
|
|
529
|
+
} from 'cto-ai-cli/engine';
|
|
530
|
+
|
|
531
|
+
// Record feedback
|
|
532
|
+
const model = await recordFeedback('/path/to/project', {
|
|
533
|
+
task: 'fix auth bug',
|
|
534
|
+
contextHash: 'abc123',
|
|
535
|
+
filesIncluded: ['src/auth.ts', 'src/types.ts'],
|
|
536
|
+
tokensUsed: 5000,
|
|
537
|
+
budget: 50000,
|
|
538
|
+
outcome: { accepted: true, compilable: true, timeToAcceptMs: 3000 },
|
|
539
|
+
sessionId: 'sess-1', // optional: group feedback
|
|
540
|
+
strategy: 'experimental', // optional: A/B testing
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
// Get boosts for context selection
|
|
544
|
+
const boosts = await getFeedbackBoosts('/path/to/project', 'fix auth');
|
|
545
|
+
// Map<string, number> — file path → boost value
|
|
546
|
+
|
|
547
|
+
// Wilson score for statistical confidence
|
|
548
|
+
const confidence = wilsonLowerBound(8, 10); // 8 successes out of 10
|
|
549
|
+
// ~0.49 — 95% confident the true rate is ≥49%
|
|
550
|
+
|
|
551
|
+
// Team sharing
|
|
552
|
+
const exported = await exportFeedbackForTeam('/path/to/project', 'my-project');
|
|
553
|
+
const merged = await importTeamFeedback('/other/project', exported);
|
|
554
|
+
|
|
555
|
+
// Predict relevant files
|
|
556
|
+
const predictions = await predictRelevantFiles('/path', 'fix auth', analysis);
|
|
557
|
+
// { filePath, predictedScore, reasons }[]
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
### Storage
|
|
561
|
+
|
|
562
|
+
| File | Scope | Description |
|
|
563
|
+
|------|-------|-------------|
|
|
564
|
+
| `.cto/feedback.json` | Per-project | Raw feedback entries (last 1000) |
|
|
565
|
+
| `.cto/feedback-model.json` | Per-project | Rebuilt model with EWMA, Bayesian, sessions |
|
|
566
|
+
| `.cto/predictor.json` | Per-project | ML predictor model |
|
|
567
|
+
| `~/.cto/global-intelligence.json` | Cross-repo | Global archetype and pattern data |
|
|
568
|
+
|
|
569
|
+
---
|
|
570
|
+
|
|
571
|
+
## Code Review
|
|
572
|
+
|
|
573
|
+
Context-aware PR review intelligence. Analyzes git diffs, detects breaking changes, finds missing files, and generates AI-ready review prompts.
|
|
574
|
+
|
|
575
|
+
### Usage
|
|
576
|
+
|
|
577
|
+
```bash
|
|
578
|
+
npx cto-ai-cli --review # Full review analysis
|
|
579
|
+
npx cto-ai-cli --review --json # JSON output for CI
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
Generates:
|
|
583
|
+
- **Terminal dashboard** — review quality score, breaking changes, missing files, impact radius
|
|
584
|
+
- **`.cto/review-prompt.md`** — AI-ready review prompt with full file contents
|
|
585
|
+
|
|
586
|
+
### Features
|
|
587
|
+
|
|
588
|
+
| Feature | Description |
|
|
589
|
+
|---------|-------------|
|
|
590
|
+
| **Diff Parsing** | Parses git diffs into structured DiffHunk[] with additions/deletions |
|
|
591
|
+
| **Breaking Change Detection** | Removed exports, type changes, function signature changes, deleted files with dependents |
|
|
592
|
+
| **Missing File Detection** | Sibling type files, test files, importers of changed exports, barrel index files |
|
|
593
|
+
| **Impact Radius** | BFS on dependency graph: direct dependents, transitive (2-hop), affected tests |
|
|
594
|
+
| **Review Quality Score** | 5-factor weighted score: PR size (25%), focus (20%), breaking changes (25%), completeness (15%), blast radius (15%) |
|
|
595
|
+
| **Review Prompt Generation** | Context-rich prompt with breaking changes, missing files, and file contents for top-risk files |
|
|
596
|
+
|
|
597
|
+
### Review Quality Score
|
|
598
|
+
|
|
599
|
+
| Grade | Score | Meaning |
|
|
600
|
+
|-------|-------|---------|
|
|
601
|
+
| A+/A/A- | 85-100 | Small, focused PR with no breaking changes |
|
|
602
|
+
| B+/B/B- | 70-84 | Manageable PR, some issues to review |
|
|
603
|
+
| C+/C/C- | 55-69 | Large or unfocused PR, needs careful review |
|
|
604
|
+
| D+/D/D- | 40-54 | Risky PR with breaking changes or missing files |
|
|
605
|
+
| F | <40 | Very large, unfocused, or highly risky PR |
|
|
606
|
+
|
|
607
|
+
### Breaking Change Severity
|
|
608
|
+
|
|
609
|
+
| Severity | Trigger |
|
|
610
|
+
|----------|--------|
|
|
611
|
+
| **Critical** | Deleted file with dependents, removed export with >3 dependents |
|
|
612
|
+
| **High** | Removed export, interface property removed, function signature changed |
|
|
613
|
+
| **Medium** | Export changed with no direct dependents |
|
|
614
|
+
|
|
615
|
+
### Programmatic API
|
|
616
|
+
|
|
617
|
+
```typescript
|
|
618
|
+
import { analyzeForReview, renderReviewSummary } from 'cto-ai-cli/engine';
|
|
619
|
+
import type { ReviewResult, ReviewOptions } from 'cto-ai-cli/engine';
|
|
620
|
+
|
|
621
|
+
const result: ReviewResult = await analyzeForReview(analysis, {
|
|
622
|
+
baseBranch: 'main', // default: 'main'
|
|
623
|
+
depth: 2, // dependency expansion depth
|
|
624
|
+
maxPromptFiles: 20, // max files in review prompt
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
console.log(result.breakingChanges); // BreakingChange[]
|
|
628
|
+
console.log(result.missingFiles); // MissingFile[]
|
|
629
|
+
console.log(result.impactRadius); // { directlyAffected, transitivelyAffected, riskScore }
|
|
630
|
+
console.log(result.reviewQuality); // { score, grade, factors }
|
|
631
|
+
console.log(result.reviewPrompt); // Full AI-ready review prompt
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
---
|
|
635
|
+
|
|
440
636
|
## MCP Server
|
|
441
637
|
|
|
442
638
|
CTO exposes 19 tools via the Model Context Protocol.
|
|
@@ -679,8 +875,11 @@ src/
|
|
|
679
875
|
│ ├── multi-model.ts # Per-model optimization
|
|
680
876
|
│ ├── predictor.ts # ML-based prediction (learns from usage)
|
|
681
877
|
│ ├── semantic.ts # Semantic domain analysis
|
|
682
|
-
│ ├── feedback.ts # Output feedback loop
|
|
683
|
-
│
|
|
878
|
+
│ ├── feedback.ts # Output feedback loop (v2: EWMA, Bayesian, A/B, team)
|
|
879
|
+
│ ├── cross-repo.ts # Cross-repo intelligence
|
|
880
|
+
│ ├── code-review.ts # Context-aware PR review engine
|
|
881
|
+
│ ├── monorepo.ts # Monorepo intelligence
|
|
882
|
+
│ └── quality-gate.ts # CI/CD quality gate
|
|
684
883
|
├── interact/ # Interaction Optimization
|
|
685
884
|
│ ├── orchestrator.ts # Full pipeline
|
|
686
885
|
│ ├── router.ts # Model routing
|