claudex-setup 0.3.0 → 0.3.2
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 +128 -185
- package/bin/cli.js +40 -4
- package/package.json +1 -1
- package/src/audit.js +18 -1
- package/src/insights.js +122 -0
package/README.md
CHANGED
|
@@ -1,220 +1,163 @@
|
|
|
1
1
|
# claudex-setup
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Score your project 0-100 for Claude Code. Smart CLAUDE.md, 54 checks, wizard, watch mode, CI action. Powered by 1,107 verified techniques.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/claudex-setup)
|
|
6
|
+
[](https://www.npmjs.com/package/claudex-setup)
|
|
6
7
|
[](LICENSE)
|
|
7
8
|
|
|
8
|
-
One command to make your project Claude Code-ready. Detects your stack, scores your setup against 50+ checks, and auto-generates everything Claude Code needs to work at full capacity.
|
|
9
|
-
|
|
10
9
|
## Quick Start
|
|
11
10
|
|
|
12
11
|
```bash
|
|
13
|
-
# Audit your project
|
|
14
|
-
npx claudex-setup
|
|
15
|
-
|
|
16
|
-
# Apply recommended configuration
|
|
17
|
-
npx claudex-setup setup
|
|
12
|
+
npx claudex-setup # Audit your project (10 seconds)
|
|
13
|
+
npx claudex-setup setup # Auto-fix everything
|
|
18
14
|
```
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
## Example Output
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
claudex-setup v0.2.0
|
|
26
|
-
═══════════════════════════════════════════════════
|
|
27
|
-
|
|
28
|
-
Detected stack: React, TypeScript, Docker
|
|
29
|
-
|
|
30
|
-
██████████████░░░░░░░░░░░░ 54/100
|
|
31
|
-
|
|
32
|
-
┌─────────────────────────────────────────────────┐
|
|
33
|
-
│ CATEGORY SCORE CHECKS │
|
|
34
|
-
│ Memory 8/15 CLAUDE.md, rules │
|
|
35
|
-
│ Quality 6/15 verification, linting │
|
|
36
|
-
│ Git Safety 5/10 hooks, permissions │
|
|
37
|
-
│ Workflow 4/10 commands, skills │
|
|
38
|
-
│ Security 3/10 permissions, secrets │
|
|
39
|
-
│ Automation 5/10 hooks, agents │
|
|
40
|
-
│ Design 4/10 Mermaid, XML tags │
|
|
41
|
-
│ DevOps 3/5 Docker, CI │
|
|
42
|
-
│ Hygiene 4/5 .gitignore, cleanup │
|
|
43
|
-
│ Performance 4/5 context, compaction │
|
|
44
|
-
│ MCP 3/5 servers, tools │
|
|
45
|
-
│ Prompting 5/5 constraints, chains │
|
|
46
|
-
└─────────────────────────────────────────────────┘
|
|
47
|
-
|
|
48
|
-
✅ Passing (12)
|
|
49
|
-
CLAUDE.md exists with project instructions
|
|
50
|
-
Pre-commit hook configured
|
|
51
|
-
Custom slash commands defined
|
|
52
|
-
.gitignore tracks .claude/ correctly
|
|
53
|
-
Docker stack detected and configured
|
|
54
|
-
...
|
|
55
|
-
|
|
56
|
-
⚠️ Warnings (6)
|
|
57
|
-
No Mermaid architecture diagram in CLAUDE.md
|
|
58
|
-
→ Add a ```mermaid graph to visualize project structure
|
|
59
|
-
Missing XML constraint tags
|
|
60
|
-
→ Wrap critical rules in <constraints> tags for 30% better adherence
|
|
61
|
-
...
|
|
62
|
-
|
|
63
|
-
🔴 Critical (3)
|
|
64
|
-
No verification criteria in CLAUDE.md
|
|
65
|
-
→ Add test/lint commands so Claude can verify its own work
|
|
66
|
-
Example:
|
|
67
|
-
## Verification
|
|
68
|
-
- Run `npm test` before committing
|
|
69
|
-
- Run `npm run lint` to check style
|
|
70
|
-
|
|
71
|
-
No security permissions configured
|
|
72
|
-
→ Create .claude/settings.json with allowed commands
|
|
73
|
-
|
|
74
|
-
No self-correction workflow
|
|
75
|
-
→ Add review commands for generate → review → refine cycles
|
|
76
|
-
|
|
77
|
-
───────────────────────────────────────────────────
|
|
78
|
-
Run `npx claudex-setup setup` to fix 9 issues automatically
|
|
79
|
-
```
|
|
16
|
+
No install. No config. No dependencies.
|
|
80
17
|
|
|
81
|
-
## What
|
|
82
|
-
|
|
83
|
-
### 📋 Memory (8 checks)
|
|
84
|
-
- CLAUDE.md exists with project instructions
|
|
85
|
-
- CLAUDE.md includes stack-specific guidance
|
|
86
|
-
- Architecture section with Mermaid diagram
|
|
87
|
-
- Verification criteria (test/lint commands)
|
|
88
|
-
- Coding conventions documented
|
|
89
|
-
- Error handling patterns defined
|
|
90
|
-
- Session memory configured
|
|
91
|
-
- State tracking files present
|
|
92
|
-
|
|
93
|
-
### ✅ Quality (7 checks)
|
|
94
|
-
- Self-correction chains (generate → review → refine)
|
|
95
|
-
- Constraint-based validation blocks
|
|
96
|
-
- Verification loops for claims
|
|
97
|
-
- Quality gates before commits
|
|
98
|
-
- Duplicate detection rules
|
|
99
|
-
- Metadata sync requirements
|
|
100
|
-
- Iron Law enforcement (evidence for all claims)
|
|
101
|
-
|
|
102
|
-
### 🔒 Git Safety (5 checks)
|
|
103
|
-
- Pre-commit hooks configured
|
|
104
|
-
- Destructive command warnings
|
|
105
|
-
- Force-push protection
|
|
106
|
-
- Branch naming conventions
|
|
107
|
-
- Commit message standards
|
|
108
|
-
|
|
109
|
-
### 🔄 Workflow (6 checks)
|
|
110
|
-
- Custom slash commands defined
|
|
111
|
-
- Skills for domain workflows
|
|
112
|
-
- Rules for path-specific conventions
|
|
113
|
-
- Agents for specialized tasks
|
|
114
|
-
- Command templates present
|
|
115
|
-
- Workflow documentation
|
|
116
|
-
|
|
117
|
-
### 🛡️ Security (5 checks)
|
|
118
|
-
- Permissions configured in settings.json
|
|
119
|
-
- Secrets excluded from commits
|
|
120
|
-
- Allowed/denied command lists
|
|
121
|
-
- MCP server permissions
|
|
122
|
-
- Environment variable handling
|
|
123
|
-
|
|
124
|
-
### ⚙️ Automation (5 checks)
|
|
125
|
-
- Edit hooks for linting
|
|
126
|
-
- Save hooks for formatting
|
|
127
|
-
- Notification hooks
|
|
128
|
-
- Log rotation configured
|
|
129
|
-
- Auto-sync with knowledge base
|
|
130
|
-
|
|
131
|
-
### 🎨 Design (4 checks)
|
|
132
|
-
- Mermaid diagrams for architecture
|
|
133
|
-
- XML tags for structured prompts
|
|
134
|
-
- Documents at top of prompts
|
|
135
|
-
- Meta-prompting patterns
|
|
136
|
-
|
|
137
|
-
### 🚀 DevOps (3 checks)
|
|
138
|
-
- CI/CD pipeline detection
|
|
139
|
-
- Docker configuration
|
|
140
|
-
- Deployment instructions in CLAUDE.md
|
|
141
|
-
|
|
142
|
-
### 🧹 Hygiene (3 checks)
|
|
143
|
-
- .gitignore tracks .claude/ correctly
|
|
144
|
-
- No stale configuration files
|
|
145
|
-
- Clean project structure
|
|
146
|
-
|
|
147
|
-
### ⚡ Performance (3 checks)
|
|
148
|
-
- Context management strategy
|
|
149
|
-
- Compaction triggers documented
|
|
150
|
-
- Tool search over full loads
|
|
151
|
-
|
|
152
|
-
### 🔌 MCP (3 checks)
|
|
153
|
-
- MCP servers configured
|
|
154
|
-
- MCP tools documented
|
|
155
|
-
- Server permissions set
|
|
156
|
-
|
|
157
|
-
### 💬 Prompting (3 checks)
|
|
158
|
-
- Constraint tags used
|
|
159
|
-
- Self-validation blocks
|
|
160
|
-
- Research methodology defined
|
|
161
|
-
|
|
162
|
-
## Auto-Generated Setup
|
|
163
|
-
|
|
164
|
-
Running `npx claudex-setup setup` creates everything your project needs:
|
|
18
|
+
## What You Get
|
|
165
19
|
|
|
166
20
|
```
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
✅
|
|
174
|
-
|
|
175
|
-
|
|
21
|
+
claudex-setup audit
|
|
22
|
+
═══════════════════════════════════════
|
|
23
|
+
Detected: React, TypeScript, Docker
|
|
24
|
+
|
|
25
|
+
████████████████░░░░ 78/100
|
|
26
|
+
|
|
27
|
+
✅ Passing
|
|
28
|
+
CLAUDE.md project instructions
|
|
29
|
+
Mermaid architecture diagram
|
|
30
|
+
Hooks (PreToolUse + PostToolUse)
|
|
31
|
+
Custom slash commands (5 commands)
|
|
32
|
+
XML constraint blocks
|
|
33
|
+
Secrets protection configured
|
|
34
|
+
|
|
35
|
+
🟡 High Impact
|
|
36
|
+
CI pipeline configured
|
|
37
|
+
→ Add .github/workflows/ for automated testing
|
|
38
|
+
|
|
39
|
+
⚡ Quick wins
|
|
40
|
+
1. Add LICENSE file
|
|
41
|
+
2. Add CHANGELOG.md
|
|
42
|
+
|
|
43
|
+
Weakest areas:
|
|
44
|
+
design: none (0/2)
|
|
45
|
+
devops: none (0/4)
|
|
46
|
+
|
|
47
|
+
29/54 checks passing
|
|
48
|
+
Run npx claudex-setup setup to fix
|
|
176
49
|
```
|
|
177
50
|
|
|
178
|
-
All
|
|
51
|
+
## All Commands
|
|
52
|
+
|
|
53
|
+
| Command | What it does |
|
|
54
|
+
|---------|-------------|
|
|
55
|
+
| `npx claudex-setup` | **Audit** - Score 0-100 against 54 checks |
|
|
56
|
+
| `npx claudex-setup setup` | **Setup** - Smart CLAUDE.md + hooks + commands + agents |
|
|
57
|
+
| `npx claudex-setup setup --auto` | **Auto-setup** - No prompts, apply all |
|
|
58
|
+
| `npx claudex-setup interactive` | **Wizard** - Step-by-step guided tour |
|
|
59
|
+
| `npx claudex-setup watch` | **Watch** - Live monitoring with score delta |
|
|
60
|
+
| `npx claudex-setup badge` | **Badge** - Generate shields.io badge for README |
|
|
61
|
+
| `npx claudex-setup insights` | **Insights** - View community aggregate stats |
|
|
62
|
+
|
|
63
|
+
### Options
|
|
64
|
+
|
|
65
|
+
| Flag | Effect |
|
|
66
|
+
|------|--------|
|
|
67
|
+
| `--verbose` | Show all recommendations (not just critical/high) |
|
|
68
|
+
| `--json` | Machine-readable JSON output (for CI) |
|
|
69
|
+
| `--no-insights` | Disable anonymous usage insights |
|
|
70
|
+
|
|
71
|
+
## Smart CLAUDE.md Generation
|
|
72
|
+
|
|
73
|
+
Not a generic template. The `setup` command actually analyzes your project:
|
|
74
|
+
|
|
75
|
+
- **Reads package.json** - includes your actual test, build, lint, dev commands
|
|
76
|
+
- **Detects framework** - Next.js Server Components, Django models, FastAPI Pydantic, React hooks
|
|
77
|
+
- **TypeScript-aware** - detects strict mode, adds TS-specific rules
|
|
78
|
+
- **Auto Mermaid diagram** - scans directories and generates architecture visualization (73% token savings)
|
|
79
|
+
- **XML constraint blocks** - adds `<constraints>` and `<verification>` with context-aware rules
|
|
80
|
+
- **Verification criteria** - auto-generates checklist from your actual commands
|
|
81
|
+
|
|
82
|
+
## 54 Checks Across 13 Categories
|
|
83
|
+
|
|
84
|
+
| Category | Checks | Key items |
|
|
85
|
+
|----------|-------:|-----------|
|
|
86
|
+
| Memory | 8 | CLAUDE.md, architecture, conventions |
|
|
87
|
+
| Quality | 7 | verification loops, self-correction |
|
|
88
|
+
| Git Safety | 5 | hooks, force-push protection |
|
|
89
|
+
| Workflow | 6 | commands, skills, rules, agents |
|
|
90
|
+
| Security | 5 | permissions, secrets, deny rules |
|
|
91
|
+
| Automation | 5 | PreToolUse, PostToolUse, SessionStart |
|
|
92
|
+
| Design | 4 | Mermaid, XML tags, structured prompts |
|
|
93
|
+
| DevOps | 4 | Docker, CI, Terraform, K8s |
|
|
94
|
+
| Hygiene | 6 | .gitignore, cleanup, structure |
|
|
95
|
+
| Performance | 3 | context management, compaction |
|
|
96
|
+
| MCP | 3 | servers, Context7, integrations |
|
|
97
|
+
| Prompting | 3 | constraints, validation, patterns |
|
|
98
|
+
| Features | 2 | /security-review, Channels |
|
|
179
99
|
|
|
180
100
|
## Stack Detection
|
|
181
101
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
|
185
|
-
|
|
186
|
-
| Frontend | React, Vue, Angular, Next.js, Svelte |
|
|
187
|
-
| Backend | Node.js, Python, Django, FastAPI
|
|
188
|
-
| Mobile | Flutter, Swift, Kotlin |
|
|
189
|
-
| Systems | Rust, Go, Java |
|
|
190
|
-
| Language | TypeScript
|
|
191
|
-
| Infra | Docker
|
|
102
|
+
Auto-detects and tailors output for 18 stacks:
|
|
103
|
+
|
|
104
|
+
| | |
|
|
105
|
+
|--|--|
|
|
106
|
+
| **Frontend** | React, Vue, Angular, Next.js, Svelte |
|
|
107
|
+
| **Backend** | Node.js, Python, Django, FastAPI |
|
|
108
|
+
| **Mobile** | Flutter, Swift, Kotlin |
|
|
109
|
+
| **Systems** | Rust, Go, Java, Ruby |
|
|
110
|
+
| **Language** | TypeScript |
|
|
111
|
+
| **Infra** | Docker |
|
|
112
|
+
|
|
113
|
+
## GitHub Action
|
|
114
|
+
|
|
115
|
+
Add to `.github/workflows/claudex.yml`:
|
|
116
|
+
|
|
117
|
+
```yaml
|
|
118
|
+
name: CLAUDEX Audit
|
|
119
|
+
on: [pull_request]
|
|
120
|
+
jobs:
|
|
121
|
+
audit:
|
|
122
|
+
runs-on: ubuntu-latest
|
|
123
|
+
steps:
|
|
124
|
+
- uses: actions/checkout@v4
|
|
125
|
+
- uses: DnaFin/claudex-setup@main
|
|
126
|
+
with:
|
|
127
|
+
threshold: 50
|
|
128
|
+
```
|
|
192
129
|
|
|
193
|
-
|
|
130
|
+
## Badge
|
|
194
131
|
|
|
195
|
-
|
|
132
|
+
Add a readiness badge to your README:
|
|
196
133
|
|
|
197
134
|
```bash
|
|
198
|
-
npx claudex-setup
|
|
199
|
-
|
|
200
|
-
npx claudex-setup audit --verbose # Show all checks with details
|
|
201
|
-
npx claudex-setup audit --json # Machine-readable JSON output
|
|
202
|
-
npx claudex-setup setup # Auto-generate missing configs
|
|
203
|
-
npx claudex-setup setup --auto # Non-interactive, accept all defaults
|
|
204
|
-
npx claudex-setup --help # Show help
|
|
135
|
+
npx claudex-setup badge
|
|
136
|
+
# Output: [](...)
|
|
205
137
|
```
|
|
206
138
|
|
|
139
|
+
## Privacy
|
|
140
|
+
|
|
141
|
+
- **Zero dependencies** - nothing to audit
|
|
142
|
+
- **Runs 100% locally** - no cloud processing
|
|
143
|
+
- **Anonymous insights** - opt-in, no PII, no file contents (disable with `--no-insights`)
|
|
144
|
+
- **MIT Licensed** - use anywhere
|
|
145
|
+
|
|
207
146
|
## Backed by Research
|
|
208
147
|
|
|
209
|
-
Every check
|
|
148
|
+
Every check traces to a verified technique from a systematic audit of:
|
|
149
|
+
- All 73 official Claude Code documentation pages
|
|
150
|
+
- 100+ community MCP servers verified via GitHub API
|
|
151
|
+
- Anthropic blog posts and benchmark papers
|
|
152
|
+
- 194 hands-on experiments with real evidence
|
|
210
153
|
|
|
211
|
-
|
|
154
|
+
1,107 techniques cataloged. 954 tested. Continuously updated.
|
|
212
155
|
|
|
213
156
|
## Requirements
|
|
214
157
|
|
|
215
158
|
- Node.js 18+
|
|
216
|
-
-
|
|
217
|
-
- No global install
|
|
159
|
+
- macOS, Linux, Windows
|
|
160
|
+
- No global install (npx handles it)
|
|
218
161
|
|
|
219
162
|
## License
|
|
220
163
|
|
package/bin/cli.js
CHANGED
|
@@ -23,10 +23,11 @@ const HELP = `
|
|
|
23
23
|
npx claudex-setup badge Generate shields.io badge markdown
|
|
24
24
|
|
|
25
25
|
Options:
|
|
26
|
-
--verbose
|
|
27
|
-
--json
|
|
28
|
-
--
|
|
29
|
-
--
|
|
26
|
+
--verbose Show all recommendations (not just critical/high)
|
|
27
|
+
--json Output as JSON (for CI pipelines)
|
|
28
|
+
--no-insights Disable anonymous usage insights
|
|
29
|
+
--help Show this help
|
|
30
|
+
--version Show version
|
|
30
31
|
`;
|
|
31
32
|
|
|
32
33
|
async function main() {
|
|
@@ -55,6 +56,41 @@ async function main() {
|
|
|
55
56
|
console.log('');
|
|
56
57
|
console.log('Add this to your README.md');
|
|
57
58
|
process.exit(0);
|
|
59
|
+
} else if (command === 'insights' || command === 'learn') {
|
|
60
|
+
const https = require('https');
|
|
61
|
+
const url = 'https://claudex-insights.claudex.workers.dev/v1/stats';
|
|
62
|
+
https.get(url, (res) => {
|
|
63
|
+
let data = '';
|
|
64
|
+
res.on('data', chunk => data += chunk);
|
|
65
|
+
res.on('end', () => {
|
|
66
|
+
try {
|
|
67
|
+
const stats = JSON.parse(data);
|
|
68
|
+
console.log('');
|
|
69
|
+
console.log('\x1b[1m CLAUDEX Community Insights\x1b[0m');
|
|
70
|
+
console.log('\x1b[2m ═══════════════════════════════════════\x1b[0m');
|
|
71
|
+
console.log(` Total audits run: \x1b[1m${stats.totalRuns}\x1b[0m`);
|
|
72
|
+
console.log(` Average score: \x1b[1m${stats.averageScore}/100\x1b[0m`);
|
|
73
|
+
console.log('');
|
|
74
|
+
if (stats.topFailedChecks && stats.topFailedChecks.length > 0) {
|
|
75
|
+
console.log('\x1b[33m Most common gaps:\x1b[0m');
|
|
76
|
+
for (const f of stats.topFailedChecks.slice(0, 5)) {
|
|
77
|
+
console.log(` ${f.pct}% miss: \x1b[1m${f.check}\x1b[0m`);
|
|
78
|
+
}
|
|
79
|
+
console.log('');
|
|
80
|
+
}
|
|
81
|
+
if (stats.topStacks && stats.topStacks.length > 0) {
|
|
82
|
+
console.log('\x1b[36m Popular stacks:\x1b[0m');
|
|
83
|
+
console.log(` ${stats.topStacks.map(s => s.stack).join(', ')}`);
|
|
84
|
+
}
|
|
85
|
+
console.log('');
|
|
86
|
+
} catch (e) {
|
|
87
|
+
console.log(' No community data available yet. Be the first to run: npx claudex-setup');
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}).on('error', () => {
|
|
91
|
+
console.log(' Could not reach insights server. Run locally: npx claudex-setup');
|
|
92
|
+
});
|
|
93
|
+
return; // keep process alive for http
|
|
58
94
|
} else if (command === 'interactive' || command === 'wizard') {
|
|
59
95
|
const { interactive } = require('../src/interactive');
|
|
60
96
|
await interactive(options);
|
package/package.json
CHANGED
package/src/audit.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
const { TECHNIQUES, STACKS } = require('./techniques');
|
|
6
6
|
const { ProjectContext } = require('./context');
|
|
7
7
|
const { getBadgeMarkdown } = require('./badge');
|
|
8
|
+
const { sendInsights, getLocalInsights } = require('./insights');
|
|
8
9
|
|
|
9
10
|
const COLORS = {
|
|
10
11
|
reset: '\x1b[0m',
|
|
@@ -161,11 +162,27 @@ async function audit(options) {
|
|
|
161
162
|
console.log('');
|
|
162
163
|
console.log(` Add to README: ${getBadgeMarkdown(score)}`);
|
|
163
164
|
console.log('');
|
|
165
|
+
|
|
166
|
+
// Weakest categories insight
|
|
167
|
+
const insights = getLocalInsights({ score, results });
|
|
168
|
+
if (insights.weakest.length > 0) {
|
|
169
|
+
console.log(colorize(' Weakest areas:', 'dim'));
|
|
170
|
+
for (const w of insights.weakest) {
|
|
171
|
+
const bar = w.score === 0 ? colorize('none', 'red') : `${w.score}%`;
|
|
172
|
+
console.log(colorize(` ${w.name}: ${bar} (${w.passed}/${w.total})`, 'dim'));
|
|
173
|
+
}
|
|
174
|
+
console.log('');
|
|
175
|
+
}
|
|
176
|
+
|
|
164
177
|
console.log(colorize(' Powered by CLAUDEX - 1,107 verified Claude Code techniques', 'dim'));
|
|
165
178
|
console.log(colorize(' https://github.com/DnaFin/claudex-setup', 'dim'));
|
|
166
179
|
console.log('');
|
|
167
180
|
|
|
168
|
-
|
|
181
|
+
// Send anonymous insights (opt-in, privacy-first, fire-and-forget)
|
|
182
|
+
const result = { score, passed: passed.length, failed: failed.length, stacks, results };
|
|
183
|
+
sendInsights(result);
|
|
184
|
+
|
|
185
|
+
return result;
|
|
169
186
|
}
|
|
170
187
|
|
|
171
188
|
module.exports = { audit };
|
package/src/insights.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anonymous insights collection - opt-in, privacy-first.
|
|
3
|
+
*
|
|
4
|
+
* What we collect (anonymously, no PII):
|
|
5
|
+
* - Score distribution (10/100, 45/100, etc.)
|
|
6
|
+
* - Stack detection (React+TS, Python+Docker, etc.)
|
|
7
|
+
* - Which checks fail most
|
|
8
|
+
* - Which checks pass most
|
|
9
|
+
* - OS + Node version
|
|
10
|
+
*
|
|
11
|
+
* What we NEVER collect:
|
|
12
|
+
* - File contents, paths, or project names
|
|
13
|
+
* - IP addresses or user identity
|
|
14
|
+
* - API keys, tokens, or credentials
|
|
15
|
+
* - Any data if user opts out
|
|
16
|
+
*
|
|
17
|
+
* Users can opt out with: npx claudex-setup --no-insights
|
|
18
|
+
* Or set env: CLAUDEX_NO_INSIGHTS=1
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const https = require('https');
|
|
22
|
+
const os = require('os');
|
|
23
|
+
|
|
24
|
+
const INSIGHTS_ENDPOINT = 'https://claudex-insights.claudex.workers.dev/v1/report';
|
|
25
|
+
const TIMEOUT_MS = 3000;
|
|
26
|
+
|
|
27
|
+
function shouldCollect() {
|
|
28
|
+
// Respect opt-out
|
|
29
|
+
if (process.env.CLAUDEX_NO_INSIGHTS === '1') return false;
|
|
30
|
+
if (process.argv.includes('--no-insights')) return false;
|
|
31
|
+
|
|
32
|
+
// Don't collect in CI
|
|
33
|
+
if (process.env.CI || process.env.GITHUB_ACTIONS) return false;
|
|
34
|
+
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function buildPayload(auditResult) {
|
|
39
|
+
// Only anonymous aggregate data - no PII, no file contents, no paths
|
|
40
|
+
const failedChecks = auditResult.results
|
|
41
|
+
.filter(r => !r.passed)
|
|
42
|
+
.map(r => r.key);
|
|
43
|
+
|
|
44
|
+
const passedChecks = auditResult.results
|
|
45
|
+
.filter(r => r.passed)
|
|
46
|
+
.map(r => r.key);
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
v: 1,
|
|
50
|
+
score: auditResult.score,
|
|
51
|
+
passed: auditResult.passed,
|
|
52
|
+
failed: auditResult.failed,
|
|
53
|
+
stacks: (auditResult.stacks || []).map(s => s.label),
|
|
54
|
+
failedChecks,
|
|
55
|
+
passedChecks,
|
|
56
|
+
platform: os.platform(),
|
|
57
|
+
nodeVersion: process.version,
|
|
58
|
+
toolVersion: require('../package.json').version,
|
|
59
|
+
timestamp: new Date().toISOString(),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function sendInsights(auditResult) {
|
|
64
|
+
if (!shouldCollect()) return;
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const payload = JSON.stringify(buildPayload(auditResult));
|
|
68
|
+
const url = new URL(INSIGHTS_ENDPOINT);
|
|
69
|
+
|
|
70
|
+
const req = https.request({
|
|
71
|
+
hostname: url.hostname,
|
|
72
|
+
path: url.pathname,
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) },
|
|
75
|
+
timeout: TIMEOUT_MS,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Fire and forget - never block the CLI
|
|
79
|
+
req.on('error', () => {}); // silently ignore
|
|
80
|
+
req.on('timeout', () => req.destroy());
|
|
81
|
+
req.write(payload);
|
|
82
|
+
req.end();
|
|
83
|
+
} catch (e) {
|
|
84
|
+
// Never let insights crash the CLI
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Generate insights summary from local audit history.
|
|
90
|
+
* This runs locally - no network needed.
|
|
91
|
+
*/
|
|
92
|
+
function getLocalInsights(auditResult) {
|
|
93
|
+
const { results } = auditResult;
|
|
94
|
+
const failed = results.filter(r => !r.passed);
|
|
95
|
+
|
|
96
|
+
// Top 3 most impactful fixes
|
|
97
|
+
const impactOrder = { critical: 3, high: 2, medium: 1 };
|
|
98
|
+
const topFixes = [...failed]
|
|
99
|
+
.sort((a, b) => (impactOrder[b.impact] || 0) - (impactOrder[a.impact] || 0))
|
|
100
|
+
.slice(0, 3)
|
|
101
|
+
.map(r => ({ name: r.name, impact: r.impact, fix: r.fix }));
|
|
102
|
+
|
|
103
|
+
// Score breakdown by category
|
|
104
|
+
const categories = {};
|
|
105
|
+
for (const r of results) {
|
|
106
|
+
const cat = r.category || 'other';
|
|
107
|
+
if (!categories[cat]) categories[cat] = { passed: 0, total: 0 };
|
|
108
|
+
categories[cat].total++;
|
|
109
|
+
if (r.passed) categories[cat].passed++;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Weakest categories
|
|
113
|
+
const weakest = Object.entries(categories)
|
|
114
|
+
.map(([name, data]) => ({ name, score: Math.round((data.passed / data.total) * 100), ...data }))
|
|
115
|
+
.filter(c => c.score < 100)
|
|
116
|
+
.sort((a, b) => a.score - b.score)
|
|
117
|
+
.slice(0, 3);
|
|
118
|
+
|
|
119
|
+
return { topFixes, categories, weakest, totalScore: auditResult.score };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
module.exports = { sendInsights, getLocalInsights, shouldCollect };
|