@codepulse-oss/core 3.1.4 → 3.1.6
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/dist/__tests__/v3.1.5-power.test.d.ts +2 -0
- package/dist/__tests__/v3.1.5-power.test.d.ts.map +1 -0
- package/dist/__tests__/v3.1.5-power.test.js +168 -0
- package/dist/__tests__/v3.1.5-power.test.js.map +1 -0
- package/dist/__tests__/v3.1.6-telemetry-crash.test.d.ts +2 -0
- package/dist/__tests__/v3.1.6-telemetry-crash.test.d.ts.map +1 -0
- package/dist/__tests__/v3.1.6-telemetry-crash.test.js +90 -0
- package/dist/__tests__/v3.1.6-telemetry-crash.test.js.map +1 -0
- package/dist/audit/explain-simple.d.ts +21 -0
- package/dist/audit/explain-simple.d.ts.map +1 -0
- package/dist/audit/explain-simple.js +91 -0
- package/dist/audit/explain-simple.js.map +1 -0
- package/dist/audit/ignore-manager.d.ts +10 -0
- package/dist/audit/ignore-manager.d.ts.map +1 -0
- package/dist/audit/ignore-manager.js +86 -0
- package/dist/audit/ignore-manager.js.map +1 -0
- package/dist/audit/live-accessibility.d.ts +101 -3
- package/dist/audit/live-accessibility.d.ts.map +1 -1
- package/dist/audit/live-accessibility.js +764 -257
- package/dist/audit/live-accessibility.js.map +1 -1
- package/dist/audit/seo-geo-scanner.d.ts +12 -0
- package/dist/audit/seo-geo-scanner.d.ts.map +1 -1
- package/dist/audit/seo-geo-scanner.js +150 -0
- package/dist/audit/seo-geo-scanner.js.map +1 -1
- package/dist/db/database.d.ts +93 -0
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/database.js +223 -0
- package/dist/db/database.js.map +1 -1
- package/dist/db/schema.d.ts +1 -1
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +31 -0
- package/dist/db/schema.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/output/html-report-writer.d.ts +38 -0
- package/dist/output/html-report-writer.d.ts.map +1 -0
- package/dist/output/html-report-writer.js +150 -0
- package/dist/output/html-report-writer.js.map +1 -0
- package/dist/output/sarif-writer.js +1 -1
- package/dist/sast/sbom-generator.js +2 -2
- package/dist/telemetry/crash-reporter.d.ts +48 -0
- package/dist/telemetry/crash-reporter.d.ts.map +1 -0
- package/dist/telemetry/crash-reporter.js +158 -0
- package/dist/telemetry/crash-reporter.js.map +1 -0
- package/dist/telemetry/optin-telemetry.d.ts +62 -2
- package/dist/telemetry/optin-telemetry.d.ts.map +1 -1
- package/dist/telemetry/optin-telemetry.js +95 -11
- package/dist/telemetry/optin-telemetry.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
function escHtml(val) {
|
|
2
|
+
return String(val ?? '')
|
|
3
|
+
.replace(/&/g, '&')
|
|
4
|
+
.replace(/</g, '<')
|
|
5
|
+
.replace(/>/g, '>')
|
|
6
|
+
.replace(/"/g, '"')
|
|
7
|
+
.replace(/'/g, ''');
|
|
8
|
+
}
|
|
9
|
+
function safeJsonScript(obj) {
|
|
10
|
+
return JSON.stringify(obj).replace(/</g, '\\u003c').replace(/>/g, '\\u003e').replace(/&/g, '\\u0026');
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Generates a 100% self-contained offline interactive HTML report (zero external CDN scripts/fonts).
|
|
14
|
+
*/
|
|
15
|
+
export function buildStandaloneHtmlReport(input) {
|
|
16
|
+
const isSeo = input.kind === 'seo-live';
|
|
17
|
+
const findings = isSeo ? input.result.findings : input.findings;
|
|
18
|
+
const title = input.title || (isSeo ? `CodePulse SEO, GEO & Page Vitals — ${input.result.url}` : `CodePulse Audit — ${input.repoName}`);
|
|
19
|
+
const payloadJson = safeJsonScript({
|
|
20
|
+
kind: input.kind,
|
|
21
|
+
findings: findings.map((f) => ({
|
|
22
|
+
id: f.id,
|
|
23
|
+
severity: f.severity,
|
|
24
|
+
category: f.category,
|
|
25
|
+
rule_id: f.rule_id || '',
|
|
26
|
+
title: f.title,
|
|
27
|
+
body: f.body,
|
|
28
|
+
file: f.file,
|
|
29
|
+
line: f.line_start,
|
|
30
|
+
recommendation: f.recommendation,
|
|
31
|
+
patch: f.patch_suggestion || '',
|
|
32
|
+
verified: f.evidence?.includes('Verified by Agent-2')
|
|
33
|
+
? 'Verified by Agent-2'
|
|
34
|
+
: f.status === 'verified_fixed'
|
|
35
|
+
? 'Fixed'
|
|
36
|
+
: ''
|
|
37
|
+
}))
|
|
38
|
+
});
|
|
39
|
+
const kpiBlock = isSeo
|
|
40
|
+
? `
|
|
41
|
+
<div class="kpis">
|
|
42
|
+
<div class="kpi"><span>Technical SEO</span><strong>${input.result.liveSeoScore}/100</strong></div>
|
|
43
|
+
<div class="kpi"><span>GEO AI Visibility</span><strong>${input.result.geoScore ?? input.result.liveSeoScore}/100</strong></div>
|
|
44
|
+
<div class="kpi"><span>Page Vitals</span><strong>${input.result.vitalsScore ?? 100}/100</strong></div>
|
|
45
|
+
<div class="kpi"><span>WCAG Accessibility</span><strong>${input.result.a11yScore}/100</strong></div>
|
|
46
|
+
</div>
|
|
47
|
+
${input.result.desktopVitals || input.result.mobileVitals
|
|
48
|
+
? `<div class="grid2">
|
|
49
|
+
<div class="card"><h3>Desktop Core Web Vitals (1440×900)</h3><pre>${escHtml(JSON.stringify(input.result.desktopVitals || {}, null, 2))}</pre></div>
|
|
50
|
+
<div class="card"><h3>Mobile Core Web Vitals (390×844)</h3><pre>${escHtml(JSON.stringify(input.result.mobileVitals || {}, null, 2))}</pre></div>
|
|
51
|
+
</div>`
|
|
52
|
+
: ''}`
|
|
53
|
+
: `
|
|
54
|
+
<div class="kpis">
|
|
55
|
+
<div class="kpi"><span>Verdict</span><strong>${escHtml(input.verdict.toUpperCase())}</strong></div>
|
|
56
|
+
<div class="kpi"><span>Pulse Score</span><strong>${input.pulseScore ?? '-'}</strong></div>
|
|
57
|
+
<div class="kpi"><span>Total Findings</span><strong>${findings.length}</strong></div>
|
|
58
|
+
<div class="kpi"><span>Critical / High</span><strong>${findings.filter((f) => f.severity === 'critical' || f.severity === 'high').length}</strong></div>
|
|
59
|
+
</div>
|
|
60
|
+
<div class="card">${escHtml(input.summary)}</div>
|
|
61
|
+
${input.mermaidSvg ? `<div class="card"><h3>Architecture Diagram</h3><div class="mmd-wrap">${input.mermaidSvg}</div></div>` : ''}`;
|
|
62
|
+
return `<!DOCTYPE html>
|
|
63
|
+
<html lang="en" data-theme="dark">
|
|
64
|
+
<head>
|
|
65
|
+
<meta charset="UTF-8" />
|
|
66
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
67
|
+
<title>${escHtml(title)}</title>
|
|
68
|
+
<style>
|
|
69
|
+
:root[data-theme="dark"]{--bg:#0b0d11;--surface:#11141a;--surface2:#171b23;--border:#252c38;--text:#eceff4;--muted:#8b95a5;--accent:#5e6ad2;--red:#f85149;--amber:#d29922;--green:#2ea043;}
|
|
70
|
+
:root[data-theme="light"]{--bg:#f8f9fb;--surface:#ffffff;--surface2:#f1f3f7;--border:#dce2ec;--text:#161922;--muted:#5b6475;--accent:#4f46e5;--red:#cf222e;--amber:#9a6700;--green:#1a7f37;}
|
|
71
|
+
*{box-sizing:border-box} body{margin:0;padding:24px;font-family:system-ui,-apple-system,sans-serif;background:var(--bg);color:var(--text);line-height:1.55;font-size:13.5px}
|
|
72
|
+
.wrap{max-width:1120px;margin:0 auto;display:flex;flex-direction:column;gap:16px}
|
|
73
|
+
header{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap;padding-bottom:12px;border-bottom:1px solid var(--border)}
|
|
74
|
+
h1{margin:0;font-size:20px} .muted{color:var(--muted);font-size:12px}
|
|
75
|
+
.kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:12px}
|
|
76
|
+
.kpi,.card{background:var(--surface);border:1px solid var(--border);border-radius:10px;padding:14px}
|
|
77
|
+
.kpi span{display:block;color:var(--muted);font-size:11.5px;text-transform:uppercase;letter-spacing:.04em}
|
|
78
|
+
.kpi strong{font-size:24px;display:block;margin-top:4px}
|
|
79
|
+
.grid2{display:grid;grid-template-columns:repeat(auto-fit,minmax(300px,1fr));gap:12px}
|
|
80
|
+
.toolbar{display:flex;gap:8px;flex-wrap:wrap;align-items:center}
|
|
81
|
+
input,select,button{font:inherit;color:var(--text);background:var(--surface2);border:1px solid var(--border);border-radius:7px;padding:7px 11px}
|
|
82
|
+
button{cursor:pointer} button.active{border-color:var(--accent);background:var(--accent);color:#fff}
|
|
83
|
+
details.finding{background:var(--surface);border:1px solid var(--border);border-radius:10px;padding:12px}
|
|
84
|
+
summary{cursor:pointer;display:flex;justify-content:space-between;align-items:center;gap:10px;font-weight:600}
|
|
85
|
+
.badge{font-size:11px;padding:2px 8px;border-radius:999px;font-weight:700;text-transform:uppercase}
|
|
86
|
+
.sev-critical,.sev-high{background:rgba(248,81,73,.16);color:var(--red)}
|
|
87
|
+
.sev-medium{background:rgba(210,153,34,.18);color:var(--amber)}
|
|
88
|
+
.sev-low{background:rgba(46,160,67,.16);color:var(--green)}
|
|
89
|
+
pre{background:var(--surface2);border:1px solid var(--border);padding:10px;border-radius:7px;overflow:auto;font-size:12px}
|
|
90
|
+
</style>
|
|
91
|
+
</head>
|
|
92
|
+
<body>
|
|
93
|
+
<div class="wrap">
|
|
94
|
+
<header>
|
|
95
|
+
<div>
|
|
96
|
+
<h1>${escHtml(title)}</h1>
|
|
97
|
+
<div class="muted">Offline Standalone Report generated by CodePulse v3.1.6 · ${new Date().toISOString()}</div>
|
|
98
|
+
</div>
|
|
99
|
+
<button type="button" id="themeBtn">Toggle Dark / Light</button>
|
|
100
|
+
</header>
|
|
101
|
+
${kpiBlock}
|
|
102
|
+
<div class="toolbar">
|
|
103
|
+
<input type="text" id="q" placeholder="Search findings by file, rule, or message..." style="flex:1;min-width:220px" />
|
|
104
|
+
<select id="sev">
|
|
105
|
+
<option value="all">All Severities</option>
|
|
106
|
+
<option value="critical">Critical</option>
|
|
107
|
+
<option value="high">High</option>
|
|
108
|
+
<option value="medium">Medium</option>
|
|
109
|
+
<option value="low">Low</option>
|
|
110
|
+
</select>
|
|
111
|
+
<span id="cnt" class="muted"></span>
|
|
112
|
+
</div>
|
|
113
|
+
<div id="list" style="display:flex;flex-direction:column;gap:10px"></div>
|
|
114
|
+
</div>
|
|
115
|
+
<script id="cp-data" type="application/json">${payloadJson}</script>
|
|
116
|
+
<script>
|
|
117
|
+
(function(){
|
|
118
|
+
const raw = JSON.parse(document.getElementById('cp-data').textContent || '{}');
|
|
119
|
+
const items = raw.findings || [];
|
|
120
|
+
const qEl = document.getElementById('q');
|
|
121
|
+
const sevEl = document.getElementById('sev');
|
|
122
|
+
const listEl = document.getElementById('list');
|
|
123
|
+
const cntEl = document.getElementById('cnt');
|
|
124
|
+
document.getElementById('themeBtn').onclick = () => {
|
|
125
|
+
const r = document.documentElement;
|
|
126
|
+
r.setAttribute('data-theme', r.getAttribute('data-theme') === 'dark' ? 'light' : 'dark');
|
|
127
|
+
};
|
|
128
|
+
function esc(s){return String(s||'').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');}
|
|
129
|
+
function render(){
|
|
130
|
+
const q = (qEl.value || '').toLowerCase();
|
|
131
|
+
const s = sevEl.value;
|
|
132
|
+
const filtered = items.filter(f => (s==='all' || f.severity===s) && (!q || (f.title+' '+f.file+' '+f.rule_id+' '+f.body).toLowerCase().includes(q)));
|
|
133
|
+
cntEl.textContent = filtered.length + ' / ' + items.length + ' shown';
|
|
134
|
+
listEl.innerHTML = filtered.length === 0 ? '<div class="card muted">No matching findings.</div>' : filtered.map((f, idx) =>
|
|
135
|
+
'<details class="finding"' + (idx < 5 ? ' open' : '') + '>' +
|
|
136
|
+
'<summary><span>' + esc(f.title) + '</span><span><span class="badge sev-' + esc(f.severity) + '">' + esc(f.severity) + '</span></span></summary>' +
|
|
137
|
+
'<div class="muted" style="margin-top:6px">' + esc(f.file) + ':' + esc(f.line) + (f.rule_id ? ' · ' + esc(f.rule_id) : '') + (f.verified ? ' · ' + esc(f.verified) : '') + '</div>' +
|
|
138
|
+
'<p>' + esc(f.body) + '</p>' +
|
|
139
|
+
'<p><strong>Fix:</strong> ' + esc(f.recommendation) + '</p>' +
|
|
140
|
+
(f.patch ? '<pre>' + esc(f.patch) + '</pre>' : '') +
|
|
141
|
+
'</details>'
|
|
142
|
+
).join('');
|
|
143
|
+
}
|
|
144
|
+
qEl.oninput = render; sevEl.onchange = render; render();
|
|
145
|
+
})();
|
|
146
|
+
</script>
|
|
147
|
+
</body>
|
|
148
|
+
</html>`;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=html-report-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-report-writer.js","sourceRoot":"","sources":["../../src/output/html-report-writer.ts"],"names":[],"mappings":"AAEA,SAAS,OAAO,CAAC,GAAY;IAC3B,OAAO,MAAM,CAAC,GAAG,IAAI,EAAE,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC5B,CAAC;AAED,SAAS,cAAc,CAAC,GAAY;IAClC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AACxG,CAAC;AAiCD;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,KAAqD;IAC7F,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC;IACxC,MAAM,QAAQ,GAAG,KAAK,C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36
36
|
export function renderSarifReport(output, options = {}) {
|
|
37
37
|
const toolName = options.toolName ?? 'CodePulse';
|
|
38
|
-
const toolVersion = options.toolVersion ?? '3.1.
|
|
38
|
+
const toolVersion = options.toolVersion ?? '3.1.6';
|
|
39
39
|
const infoUri = options.informationUri ?? 'https://github.com/ymorningstar/CodePulse';
|
|
40
40
|
const ruleMap = new Map();
|
|
41
41
|
const results = [];
|
|
@@ -134,7 +134,7 @@ export async function generateProjectSbom(options) {
|
|
|
134
134
|
documentNamespace: `https://github.com/ymorningstar/CodePulse/spdx/${crypto.randomUUID()}`,
|
|
135
135
|
creationInfo: {
|
|
136
136
|
created: timestamp,
|
|
137
|
-
creators: ['Tool: CodePulse-SBOM-Generator-3.1.
|
|
137
|
+
creators: ['Tool: CodePulse-SBOM-Generator-3.1.6']
|
|
138
138
|
},
|
|
139
139
|
packages: components.map((c, idx) => ({
|
|
140
140
|
name: c.name,
|
|
@@ -160,7 +160,7 @@ export async function generateProjectSbom(options) {
|
|
|
160
160
|
version: 1,
|
|
161
161
|
metadata: {
|
|
162
162
|
timestamp,
|
|
163
|
-
tools: [{ vendor: 'CodePulse', name: 'codepulse-sbom', version: '3.1.
|
|
163
|
+
tools: [{ vendor: 'CodePulse', name: 'codepulse-sbom', version: '3.1.6' }],
|
|
164
164
|
component: {
|
|
165
165
|
type: 'application',
|
|
166
166
|
name: repoName
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface SanitizedCrashSummary {
|
|
2
|
+
errorComponent: string;
|
|
3
|
+
errorCode: string;
|
|
4
|
+
errorFingerprint: string;
|
|
5
|
+
sanitizedMessage: string;
|
|
6
|
+
localStack: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Strip local filesystem paths, file URIs, HTTP(S) URLs, query strings,
|
|
10
|
+
* emails, and secrets from any runtime error before storing or transmitting.
|
|
11
|
+
*/
|
|
12
|
+
export declare function sanitizeCrashText(raw: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Normalize an arbitrary thrown value into a deterministic, zero-PII crash fingerprint
|
|
15
|
+
* suitable for privacy-first telemetry and local diagnostic logs.
|
|
16
|
+
*/
|
|
17
|
+
export declare function sanitizeCrashReport(err: unknown, component: string, explicitCode?: string): SanitizedCrashSummary;
|
|
18
|
+
/**
|
|
19
|
+
* Append a masked, rotated entry to `~/.codepulse/crash.log` (max 2 MB, rotated to `.log.1`).
|
|
20
|
+
* Always succeeds safely without throwing into caller error handlers.
|
|
21
|
+
*/
|
|
22
|
+
export declare function writeLocalCrashLog(input: {
|
|
23
|
+
component: string;
|
|
24
|
+
error: unknown;
|
|
25
|
+
detail?: string;
|
|
26
|
+
logPath?: string;
|
|
27
|
+
}): Promise<{
|
|
28
|
+
logPath: string;
|
|
29
|
+
summary: SanitizedCrashSummary;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Synchronous crash log writer for Electron `uncaughtException` / exit hooks.
|
|
33
|
+
*/
|
|
34
|
+
export declare function writeLocalCrashLogSync(input: {
|
|
35
|
+
component: string;
|
|
36
|
+
error: unknown;
|
|
37
|
+
detail?: string;
|
|
38
|
+
logPath?: string;
|
|
39
|
+
}): SanitizedCrashSummary;
|
|
40
|
+
export declare function testTelemetryHealth(endpoint: string, fetchImpl?: typeof fetch): Promise<{
|
|
41
|
+
ok: boolean;
|
|
42
|
+
endpoint: string;
|
|
43
|
+
status: number;
|
|
44
|
+
latencyMs: number;
|
|
45
|
+
service?: string;
|
|
46
|
+
error?: string;
|
|
47
|
+
}>;
|
|
48
|
+
//# sourceMappingURL=crash-reporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crash-reporter.d.ts","sourceRoot":"","sources":["../../src/telemetry/crash-reporter.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,qBAAqB;IACpC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAg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
|
+
import path from 'node:path';
|
|
6
|
+
import { maskSecrets } from '../utils/platform.js';
|
|
7
|
+
const MAX_CRASH_LOG_BYTES = 2 * 1024 * 1024; // 2 MB
|
|
8
|
+
/**
|
|
9
|
+
* Strip local filesystem paths, file URIs, HTTP(S) URLs, query strings,
|
|
10
|
+
* emails, and secrets from any runtime error before storing or transmitting.
|
|
11
|
+
*/
|
|
12
|
+
export function sanitizeCrashText(raw) {
|
|
13
|
+
const masked = maskSecrets(String(raw || ''));
|
|
14
|
+
return masked
|
|
15
|
+
.replace(/file:\/\/\/?[^\s)'"]+/gi, '<file-uri>')
|
|
16
|
+
.replace(/https?:\/\/[^\s?#"')]+(?:\?[^\s#"')]*)?/gi, '<url>')
|
|
17
|
+
.replace(/[A-Za-z]:\\(?:[^\\\s:'")]+\\)*[^\\\s:'")]+/g, '<win-path>')
|
|
18
|
+
.replace(/\/(?:Users|home|var|tmp|opt|etc|app|workspace|mnt|Volumes)\/[^\s:'")]+/g, '<unix-path>')
|
|
19
|
+
.replace(/[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}/gi, '<email>')
|
|
20
|
+
.slice(0, 600);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Normalize an arbitrary thrown value into a deterministic, zero-PII crash fingerprint
|
|
24
|
+
* suitable for privacy-first telemetry and local diagnostic logs.
|
|
25
|
+
*/
|
|
26
|
+
export function sanitizeCrashReport(err, component, explicitCode) {
|
|
27
|
+
const errorObj = err instanceof Error ? err : null;
|
|
28
|
+
const rawMessage = errorObj ? errorObj.message : typeof err === 'string' ? err : String(err ?? 'Unknown error');
|
|
29
|
+
const rawCode = explicitCode ||
|
|
30
|
+
(err && typeof err === 'object' && 'code' in err && typeof err.code === 'string'
|
|
31
|
+
? err.code
|
|
32
|
+
: errorObj?.name || 'UNHANDLED_ERROR');
|
|
33
|
+
const errorComponent = String(component || 'unknown')
|
|
34
|
+
.replace(/[^a-z0-9_-]/gi, '-')
|
|
35
|
+
.slice(0, 32) || 'unknown';
|
|
36
|
+
const errorCode = sanitizeCrashText(rawCode)
|
|
37
|
+
.replace(/[^a-z0-9_.:-]/gi, '_')
|
|
38
|
+
.slice(0, 64) || 'UNHANDLED_ERROR';
|
|
39
|
+
const sanitizedMessage = sanitizeCrashText(rawMessage);
|
|
40
|
+
const msgHead = sanitizedMessage.replace(/\d+/g, '#').slice(0, 140);
|
|
41
|
+
const errorFingerprint = crypto
|
|
42
|
+
.createHash('sha256')
|
|
43
|
+
.update(`${errorComponent}:${errorCode}:${msgHead}`)
|
|
44
|
+
.digest('hex')
|
|
45
|
+
.slice(0, 16);
|
|
46
|
+
const rawStack = errorObj?.stack ? errorObj.stack : sanitizedMessage;
|
|
47
|
+
const localStack = sanitizeCrashText(rawStack).slice(0, 1500);
|
|
48
|
+
return {
|
|
49
|
+
errorComponent,
|
|
50
|
+
errorCode,
|
|
51
|
+
errorFingerprint,
|
|
52
|
+
sanitizedMessage,
|
|
53
|
+
localStack
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Append a masked, rotated entry to `~/.codepulse/crash.log` (max 2 MB, rotated to `.log.1`).
|
|
58
|
+
* Always succeeds safely without throwing into caller error handlers.
|
|
59
|
+
*/
|
|
60
|
+
export async function writeLocalCrashLog(input) {
|
|
61
|
+
const targetPath = path.resolve(input.logPath || process.env.CODEPULSE_CRASH_LOG_PATH || path.join(os.homedir(), '.codepulse', 'crash.log'));
|
|
62
|
+
const summary = sanitizeCrashReport(input.error, input.component);
|
|
63
|
+
const safeDetail = input.detail ? sanitizeCrashText(input.detail) : '';
|
|
64
|
+
const entry = [
|
|
65
|
+
`[${new Date().toISOString()}] [${summary.errorComponent}] ${summary.errorCode} (${summary.errorFingerprint})`,
|
|
66
|
+
`Message: ${summary.sanitizedMessage}`,
|
|
67
|
+
safeDetail ? `Detail: ${safeDetail}` : null,
|
|
68
|
+
`Stack:\n${summary.localStack}`,
|
|
69
|
+
'---'
|
|
70
|
+
]
|
|
71
|
+
.filter(Boolean)
|
|
72
|
+
.join('\n') + '\n';
|
|
73
|
+
try {
|
|
74
|
+
await fs.mkdir(path.dirname(targetPath), { recursive: true });
|
|
75
|
+
try {
|
|
76
|
+
const st = await fs.stat(targetPath);
|
|
77
|
+
if (st.size + Buffer.byteLength(entry, 'utf8') > MAX_CRASH_LOG_BYTES) {
|
|
78
|
+
const rotated = `${targetPath}.1`;
|
|
79
|
+
await fs.unlink(rotated).catch(() => undefined);
|
|
80
|
+
await fs.rename(targetPath, rotated).catch(() => undefined);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// Log file does not exist yet
|
|
85
|
+
}
|
|
86
|
+
await fs.appendFile(targetPath, entry, 'utf8');
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// Logging must never mask original crash handling
|
|
90
|
+
}
|
|
91
|
+
return { logPath: targetPath, summary };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Synchronous crash log writer for Electron `uncaughtException` / exit hooks.
|
|
95
|
+
*/
|
|
96
|
+
export function writeLocalCrashLogSync(input) {
|
|
97
|
+
const targetPath = path.resolve(input.logPath || process.env.CODEPULSE_CRASH_LOG_PATH || path.join(os.homedir(), '.codepulse', 'crash.log'));
|
|
98
|
+
const summary = sanitizeCrashReport(input.error, input.component);
|
|
99
|
+
const safeDetail = input.detail ? sanitizeCrashText(input.detail) : '';
|
|
100
|
+
const entry = [
|
|
101
|
+
`[${new Date().toISOString()}] [${summary.errorComponent}] ${summary.errorCode} (${summary.errorFingerprint})`,
|
|
102
|
+
`Message: ${summary.sanitizedMessage}`,
|
|
103
|
+
safeDetail ? `Detail: ${safeDetail}` : null,
|
|
104
|
+
`Stack:\n${summary.localStack}`,
|
|
105
|
+
'---'
|
|
106
|
+
]
|
|
107
|
+
.filter(Boolean)
|
|
108
|
+
.join('\n') + '\n';
|
|
109
|
+
try {
|
|
110
|
+
fsSync.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
111
|
+
if (fsSync.existsSync(targetPath)) {
|
|
112
|
+
const st = fsSync.statSync(targetPath);
|
|
113
|
+
if (st.size + Buffer.byteLength(entry, 'utf8') > MAX_CRASH_LOG_BYTES) {
|
|
114
|
+
const rotated = `${targetPath}.1`;
|
|
115
|
+
if (fsSync.existsSync(rotated))
|
|
116
|
+
fsSync.unlinkSync(rotated);
|
|
117
|
+
fsSync.renameSync(targetPath, rotated);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
fsSync.appendFileSync(targetPath, entry, 'utf8');
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// Safe fallback
|
|
124
|
+
}
|
|
125
|
+
return summary;
|
|
126
|
+
}
|
|
127
|
+
export async function testTelemetryHealth(endpoint, fetchImpl = fetch) {
|
|
128
|
+
const base = endpoint.replace(/\/+$/, '');
|
|
129
|
+
const healthUrl = base.endsWith('/health') ? base : `${base}/health`;
|
|
130
|
+
const start = performance.now();
|
|
131
|
+
const controller = new AbortController();
|
|
132
|
+
const timer = setTimeout(() => controller.abort(), 3500);
|
|
133
|
+
try {
|
|
134
|
+
const res = await fetchImpl(healthUrl, { method: 'GET', signal: controller.signal });
|
|
135
|
+
const latencyMs = Math.round(performance.now() - start);
|
|
136
|
+
const json = (await res.json().catch(() => ({})));
|
|
137
|
+
return {
|
|
138
|
+
ok: res.ok && json.ok !== false,
|
|
139
|
+
endpoint: healthUrl,
|
|
140
|
+
status: res.status,
|
|
141
|
+
latencyMs,
|
|
142
|
+
service: json.service
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
return {
|
|
147
|
+
ok: false,
|
|
148
|
+
endpoint: healthUrl,
|
|
149
|
+
status: 0,
|
|
150
|
+
latencyMs: Math.round(performance.now() - start),
|
|
151
|
+
error: err.message
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
clearTimeout(timer);
|
|
156
|
+
}
|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|
|
1
1
|
import type { CodePulseDatabase } from '../db/database.js';
|
|
2
2
|
import type { ReviewOutput } from '../types/review.js';
|
|
3
|
+
import { testTelemetryHealth } from './crash-reporter.js';
|
|
4
|
+
export declare const DEFAULT_TELEMETRY_ENDPOINT = "https://codepulse-telemetry.codepulse-telemetry-ops.workers.dev";
|
|
5
|
+
export declare function resolveTelemetryEndpoint(explicit?: string): string | undefined;
|
|
6
|
+
export type TelemetryEventType = 'scan_completed' | 'scan_failed' | 'finding_dismissed' | 'app_heartbeat' | 'crash_report' | 'report_exported';
|
|
7
|
+
export type TelemetryVitalsGrade = 'good' | 'needs_improvement' | 'poor';
|
|
8
|
+
export type TelemetryReportFormat = 'html' | 'pdf' | 'sarif' | 'cyclonedx' | 'spdx' | 'md';
|
|
9
|
+
export type TelemetryLocalAiRuntime = 'ollama' | 'lmstudio' | 'cloud-byok' | 'none';
|
|
3
10
|
export interface OptInTelemetryPayload {
|
|
4
|
-
eventType:
|
|
11
|
+
eventType: TelemetryEventType;
|
|
5
12
|
installUuid: string;
|
|
6
13
|
appVersion: string;
|
|
7
14
|
osPlatform: string;
|
|
@@ -21,6 +28,14 @@ export interface OptInTelemetryPayload {
|
|
|
21
28
|
tokenSavingsPercent?: number;
|
|
22
29
|
seoScore?: number;
|
|
23
30
|
geoScore?: number;
|
|
31
|
+
a11yScore?: number;
|
|
32
|
+
vitalsGrade?: TelemetryVitalsGrade;
|
|
33
|
+
uiTheme?: string;
|
|
34
|
+
zenModeUsed?: boolean;
|
|
35
|
+
reportFormat?: TelemetryReportFormat;
|
|
36
|
+
localAiRuntime?: TelemetryLocalAiRuntime;
|
|
37
|
+
errorComponent?: string;
|
|
38
|
+
errorFingerprint?: string;
|
|
24
39
|
durationMs?: number;
|
|
25
40
|
errorCode?: string;
|
|
26
41
|
sentAt: string;
|
|
@@ -53,11 +68,12 @@ export declare class TelemetryManager {
|
|
|
53
68
|
setConsentCompleted(done?: boolean): void;
|
|
54
69
|
getOrCreateInstallUuid(): string;
|
|
55
70
|
getLocalStats(): LocalUsageSummary;
|
|
71
|
+
private resolveLocalAiRuntime;
|
|
56
72
|
/**
|
|
57
73
|
* Construct a strictly sanitized, zero-code/zero-PII telemetry payload.
|
|
58
74
|
*/
|
|
59
75
|
buildSanitizedPayload(input: {
|
|
60
|
-
eventType:
|
|
76
|
+
eventType: TelemetryEventType;
|
|
61
77
|
appVersion: string;
|
|
62
78
|
uiLanguage?: string;
|
|
63
79
|
aiProvider?: string;
|
|
@@ -66,6 +82,16 @@ export declare class TelemetryManager {
|
|
|
66
82
|
output?: ReviewOutput;
|
|
67
83
|
dismissedRuleIds?: string[];
|
|
68
84
|
tokenSavingsPercent?: number;
|
|
85
|
+
seoScore?: number;
|
|
86
|
+
geoScore?: number;
|
|
87
|
+
a11yScore?: number;
|
|
88
|
+
vitalsGrade?: TelemetryVitalsGrade;
|
|
89
|
+
uiTheme?: string;
|
|
90
|
+
zenModeUsed?: boolean;
|
|
91
|
+
reportFormat?: TelemetryReportFormat;
|
|
92
|
+
localAiRuntime?: TelemetryLocalAiRuntime;
|
|
93
|
+
errorComponent?: string;
|
|
94
|
+
errorFingerprint?: string;
|
|
69
95
|
durationMs?: number;
|
|
70
96
|
errorCode?: string;
|
|
71
97
|
}): OptInTelemetryPayload;
|
|
@@ -79,5 +105,39 @@ export declare class TelemetryManager {
|
|
|
79
105
|
payload: OptInTelemetryPayload;
|
|
80
106
|
sent: boolean;
|
|
81
107
|
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Send at most one anonymized `app_heartbeat` every 24h when telemetry opt-in is active.
|
|
110
|
+
*/
|
|
111
|
+
sendHeartbeatOncePerDay(appVersion: string, options?: {
|
|
112
|
+
endpoint?: string;
|
|
113
|
+
fetchImpl?: typeof fetch;
|
|
114
|
+
nowMs?: number;
|
|
115
|
+
}): Promise<{
|
|
116
|
+
sent: boolean;
|
|
117
|
+
skipped?: string;
|
|
118
|
+
}>;
|
|
119
|
+
/**
|
|
120
|
+
* Write a masked diagnostic log to `~/.codepulse/crash.log` (always), and emit a
|
|
121
|
+
* sanitized zero-path `crash_report` event ONLY if `telemetry.optIn === true`.
|
|
122
|
+
*/
|
|
123
|
+
reportSanitizedCrash(input: {
|
|
124
|
+
component: string;
|
|
125
|
+
error: unknown;
|
|
126
|
+
appVersion: string;
|
|
127
|
+
errorCode?: string;
|
|
128
|
+
detail?: string;
|
|
129
|
+
logPath?: string;
|
|
130
|
+
}, options?: {
|
|
131
|
+
endpoint?: string;
|
|
132
|
+
fetchImpl?: typeof fetch;
|
|
133
|
+
}): Promise<{
|
|
134
|
+
logPath: string;
|
|
135
|
+
sent: boolean;
|
|
136
|
+
fingerprint: string;
|
|
137
|
+
}>;
|
|
138
|
+
checkEndpointHealth(options?: {
|
|
139
|
+
endpoint?: string;
|
|
140
|
+
fetchImpl?: typeof fetch;
|
|
141
|
+
}): Promise<Awaited<ReturnType<typeof testTelemetryHealth>>>;
|
|
82
142
|
}
|
|
83
143
|
//# sourceMappingURL=optin-telemetry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optin-telemetry.d.ts","sourceRoot":"","sources":["../../src/telemetry/optin-telemetry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"optin-telemetry.d.ts","sourceRoot":"","sources":["../../src/telemetry/optin-telemetry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAuB,mBAAmB,EAAsB,MAAM,qBAAqB,CAAC;AAInG,eAAO,MAAM,0BAA0B,oEAAoE,CAAC;AAG5G,wBAAgB,wBAAwB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MA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