@nerviq/cli 1.8.5 → 1.8.7

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/src/insights.js CHANGED
@@ -1,119 +1,119 @@
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 nerviq --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://insights.nerviq.net/v1/report';
25
- const TIMEOUT_MS = 3000;
26
-
27
- function shouldCollect() {
28
- // Opt-IN: only collect if user explicitly enables
29
- if (process.env.CLAUDEX_INSIGHTS === '1') return true;
30
- if (process.argv.includes('--insights')) return true;
31
- return false;
32
- }
33
-
34
- function buildPayload(auditResult) {
35
- // Only anonymous aggregate data - no PII, no file contents, no paths
36
- const failedChecks = auditResult.results
37
- .filter(r => !r.passed)
38
- .map(r => r.key);
39
-
40
- const passedChecks = auditResult.results
41
- .filter(r => r.passed)
42
- .map(r => r.key);
43
-
44
- return {
45
- v: 1,
46
- score: auditResult.score,
47
- passed: auditResult.passed,
48
- failed: auditResult.failed,
49
- stacks: (auditResult.stacks || []).map(s => s.label),
50
- failedChecks,
51
- passedChecks,
52
- platform: os.platform(),
53
- nodeVersion: process.version,
54
- toolVersion: require('../package.json').version,
55
- timestamp: new Date().toISOString(),
56
- };
57
- }
58
-
59
- function sendInsights(auditResult) {
60
- if (!shouldCollect()) return;
61
-
62
- try {
63
- const payload = JSON.stringify(buildPayload(auditResult));
64
- const url = new URL(INSIGHTS_ENDPOINT);
65
-
66
- const req = https.request({
67
- hostname: url.hostname,
68
- path: url.pathname,
69
- method: 'POST',
70
- headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) },
71
- timeout: TIMEOUT_MS,
72
- });
73
-
74
- // Fire and forget - never block the CLI
75
- req.on('error', () => {}); // silently ignore
76
- req.on('timeout', () => req.destroy());
77
- req.write(payload);
78
- req.end();
79
- } catch (e) {
80
- // Never let insights crash the CLI
81
- }
82
- }
83
-
84
- /**
85
- * Generate insights summary from local audit history.
86
- * This runs locally - no network needed.
87
- */
88
- function getLocalInsights(auditResult) {
89
- const { results } = auditResult;
90
- const applicable = results.filter(r => r.passed !== null);
91
- const failed = applicable.filter(r => r.passed === false);
92
-
93
- // Top 3 most impactful fixes
94
- const impactOrder = { critical: 3, high: 2, medium: 1 };
95
- const topFixes = [...failed]
96
- .sort((a, b) => (impactOrder[b.impact] || 0) - (impactOrder[a.impact] || 0))
97
- .slice(0, 3)
98
- .map(r => ({ name: r.name, impact: r.impact, fix: r.fix }));
99
-
100
- // Score breakdown by category
101
- const categories = {};
102
- for (const r of applicable) {
103
- const cat = r.category || 'other';
104
- if (!categories[cat]) categories[cat] = { passed: 0, total: 0 };
105
- categories[cat].total++;
106
- if (r.passed) categories[cat].passed++;
107
- }
108
-
109
- // Weakest categories
110
- const weakest = Object.entries(categories)
111
- .map(([name, data]) => ({ name, score: Math.round((data.passed / data.total) * 100), ...data }))
112
- .filter(c => c.score < 100)
113
- .sort((a, b) => a.score - b.score)
114
- .slice(0, 3);
115
-
116
- return { topFixes, categories, weakest, totalScore: auditResult.score };
117
- }
118
-
119
- module.exports = { sendInsights, getLocalInsights, shouldCollect };
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 nerviq --no-insights
18
+ * Or set env: NERVIQ_NO_INSIGHTS=1
19
+ */
20
+
21
+ const https = require('https');
22
+ const os = require('os');
23
+
24
+ const INSIGHTS_ENDPOINT = 'https://insights.nerviq.net/v1/report';
25
+ const TIMEOUT_MS = 3000;
26
+
27
+ function shouldCollect() {
28
+ // Opt-IN: only collect if user explicitly enables
29
+ if (process.env.NERVIQ_INSIGHTS === '1') return true;
30
+ if (process.argv.includes('--insights')) return true;
31
+ return false;
32
+ }
33
+
34
+ function buildPayload(auditResult) {
35
+ // Only anonymous aggregate data - no PII, no file contents, no paths
36
+ const failedChecks = auditResult.results
37
+ .filter(r => !r.passed)
38
+ .map(r => r.key);
39
+
40
+ const passedChecks = auditResult.results
41
+ .filter(r => r.passed)
42
+ .map(r => r.key);
43
+
44
+ return {
45
+ v: 1,
46
+ score: auditResult.score,
47
+ passed: auditResult.passed,
48
+ failed: auditResult.failed,
49
+ stacks: (auditResult.stacks || []).map(s => s.label),
50
+ failedChecks,
51
+ passedChecks,
52
+ platform: os.platform(),
53
+ nodeVersion: process.version,
54
+ toolVersion: require('../package.json').version,
55
+ timestamp: new Date().toISOString(),
56
+ };
57
+ }
58
+
59
+ function sendInsights(auditResult) {
60
+ if (!shouldCollect()) return;
61
+
62
+ try {
63
+ const payload = JSON.stringify(buildPayload(auditResult));
64
+ const url = new URL(INSIGHTS_ENDPOINT);
65
+
66
+ const req = https.request({
67
+ hostname: url.hostname,
68
+ path: url.pathname,
69
+ method: 'POST',
70
+ headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) },
71
+ timeout: TIMEOUT_MS,
72
+ });
73
+
74
+ // Fire and forget - never block the CLI
75
+ req.on('error', () => {}); // silently ignore
76
+ req.on('timeout', () => req.destroy());
77
+ req.write(payload);
78
+ req.end();
79
+ } catch (e) {
80
+ // Never let insights crash the CLI
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Generate insights summary from local audit history.
86
+ * This runs locally - no network needed.
87
+ */
88
+ function getLocalInsights(auditResult) {
89
+ const { results } = auditResult;
90
+ const applicable = results.filter(r => r.passed !== null);
91
+ const failed = applicable.filter(r => r.passed === false);
92
+
93
+ // Top 3 most impactful fixes
94
+ const impactOrder = { critical: 3, high: 2, medium: 1 };
95
+ const topFixes = [...failed]
96
+ .sort((a, b) => (impactOrder[b.impact] || 0) - (impactOrder[a.impact] || 0))
97
+ .slice(0, 3)
98
+ .map(r => ({ name: r.name, impact: r.impact, fix: r.fix }));
99
+
100
+ // Score breakdown by category
101
+ const categories = {};
102
+ for (const r of applicable) {
103
+ const cat = r.category || 'other';
104
+ if (!categories[cat]) categories[cat] = { passed: 0, total: 0 };
105
+ categories[cat].total++;
106
+ if (r.passed) categories[cat].passed++;
107
+ }
108
+
109
+ // Weakest categories
110
+ const weakest = Object.entries(categories)
111
+ .map(([name, data]) => ({ name, score: Math.round((data.passed / data.total) * 100), ...data }))
112
+ .filter(c => c.score < 100)
113
+ .sort((a, b) => a.score - b.score)
114
+ .slice(0, 3);
115
+
116
+ return { topFixes, categories, weakest, totalScore: auditResult.score };
117
+ }
118
+
119
+ module.exports = { sendInsights, getLocalInsights, shouldCollect };
@@ -1,5 +1,5 @@
1
1
  {
2
- "synced_from": "claudex",
2
+ "synced_from": "nerviq",
3
3
  "synced_at": "2026-04-06T12:45:38Z",
4
4
  "total_items": 1118,
5
5
  "tested": 948,