@nerviq/cli 1.29.0 → 1.29.1
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/CHANGELOG.md +1527 -1493
- package/README.md +550 -538
- package/SECURITY.md +82 -82
- package/bin/cli.js +2562 -2558
- package/docs/api-reference.md +356 -356
- package/docs/audit-fix.md +109 -0
- package/docs/autofix.md +3 -62
- package/docs/getting-started.md +1 -1
- package/docs/index.html +592 -592
- package/docs/integration-contracts.md +287 -287
- package/docs/maintenance.md +128 -128
- package/docs/new-platform-guide.md +202 -202
- package/docs/release-process.md +63 -0
- package/docs/shallow-risk.md +244 -244
- package/docs/why-nerviq.md +82 -82
- package/package.json +67 -67
- package/src/aider/activity.js +226 -226
- package/src/aider/context.js +162 -162
- package/src/aider/freshness.js +123 -123
- package/src/aider/techniques.js +3465 -3465
- package/src/audit/layers.js +180 -180
- package/src/audit.js +1032 -1032
- package/src/benchmark.js +299 -299
- package/src/codex/activity.js +324 -324
- package/src/codex/freshness.js +142 -142
- package/src/codex/techniques.js +4895 -4895
- package/src/context.js +326 -326
- package/src/continuous-ops.js +11 -1
- package/src/convert.js +340 -340
- package/src/copilot/config-parser.js +280 -280
- package/src/copilot/context.js +218 -218
- package/src/copilot/freshness.js +177 -177
- package/src/copilot/patch.js +238 -238
- package/src/copilot/techniques.js +3578 -3578
- package/src/cursor/freshness.js +194 -194
- package/src/cursor/patch.js +243 -243
- package/src/cursor/techniques.js +3735 -3735
- package/src/doctor.js +201 -201
- package/src/fix-engine.js +511 -8
- package/src/formatters/csv.js +86 -86
- package/src/formatters/junit.js +123 -123
- package/src/formatters/markdown.js +164 -164
- package/src/formatters/otel.js +151 -151
- package/src/freshness.js +156 -156
- package/src/gemini/activity.js +402 -402
- package/src/gemini/context.js +290 -290
- package/src/gemini/freshness.js +183 -183
- package/src/gemini/patch.js +229 -229
- package/src/gemini/techniques.js +3811 -3811
- package/src/governance.js +533 -533
- package/src/harmony/audit.js +306 -306
- package/src/i18n.js +63 -63
- package/src/insights.js +119 -119
- package/src/integrations.js +134 -134
- package/src/locales/en.json +33 -33
- package/src/locales/es.json +33 -33
- package/src/migrate.js +354 -354
- package/src/opencode/activity.js +286 -286
- package/src/opencode/freshness.js +137 -137
- package/src/opencode/techniques.js +3450 -3450
- package/src/setup/analysis.js +12 -12
- package/src/setup.js +7 -6
- package/src/shallow-risk/index.js +56 -56
- package/src/shallow-risk/patterns/agent-config-cross-platform-drift.js +50 -50
- package/src/shallow-risk/patterns/agent-config-dangerous-autoapprove.js +46 -46
- package/src/shallow-risk/patterns/agent-config-deprecated-keys.js +46 -46
- package/src/shallow-risk/patterns/agent-config-missing-file.js +317 -317
- package/src/shallow-risk/patterns/agent-config-secret-literal.js +49 -49
- package/src/shallow-risk/patterns/agent-config-stack-contradiction.js +34 -34
- package/src/shallow-risk/patterns/hook-script-missing.js +70 -70
- package/src/shallow-risk/patterns/mcp-server-no-allowlist.js +52 -52
- package/src/shallow-risk/shared.js +648 -648
- package/src/source-urls.js +295 -295
- package/src/state-paths.js +85 -85
- package/src/supplemental-checks.js +805 -805
- package/src/telemetry.js +160 -160
- package/src/windsurf/context.js +359 -359
- package/src/windsurf/freshness.js +194 -194
- package/src/windsurf/patch.js +231 -231
- package/src/windsurf/techniques.js +3779 -3779
package/src/opencode/activity.js
CHANGED
|
@@ -1,286 +1,286 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenCode Repeat-Usage Surfaces — 6 repeat-usage surfaces
|
|
3
|
-
*
|
|
4
|
-
* Adapts the shared activity/snapshot backend for OpenCode platform.
|
|
5
|
-
* Provides: history, compare, trend, watch, feedback, insights.
|
|
6
|
-
*
|
|
7
|
-
* OpenCode snapshots are stored alongside Claude snapshots in
|
|
8
|
-
* .nerviq/snapshots/ (legacy: .claude/nerviq-cli/snapshots/) but filtered by platform='opencode'.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const path = require('path');
|
|
12
|
-
const {
|
|
13
|
-
readSnapshotIndex,
|
|
14
|
-
writeSnapshotArtifact,
|
|
15
|
-
exportTrendReport: sharedExportTrendReport,
|
|
16
|
-
recordRecommendationOutcome,
|
|
17
|
-
readOutcomeIndex,
|
|
18
|
-
summarizeOutcomeEntries,
|
|
19
|
-
} = require('../activity');
|
|
20
|
-
const { version } = require('../../package.json');
|
|
21
|
-
|
|
22
|
-
// --- History ---
|
|
23
|
-
|
|
24
|
-
function getOpenCodeHistory(dir, limit = 20) {
|
|
25
|
-
const entries = readSnapshotIndex(dir);
|
|
26
|
-
return entries
|
|
27
|
-
.filter(e => e.snapshotKind === 'audit' && (e.platform === 'opencode' || e.summary?.platform === 'opencode'))
|
|
28
|
-
.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
|
29
|
-
.slice(0, limit);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function formatOpenCodeHistory(dir) {
|
|
33
|
-
const history = getOpenCodeHistory(dir, 10);
|
|
34
|
-
if (history.length === 0) {
|
|
35
|
-
return 'No OpenCode snapshots found. Run `npx nerviq --platform opencode --snapshot` to save one.';
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const lines = ['OpenCode Score History (most recent first):', ''];
|
|
39
|
-
for (const entry of history) {
|
|
40
|
-
const date = entry.createdAt?.split('T')[0] || 'unknown';
|
|
41
|
-
const score = entry.summary?.score ?? '?';
|
|
42
|
-
const passed = entry.summary?.passed ?? '?';
|
|
43
|
-
const total = entry.summary?.checkCount ?? '?';
|
|
44
|
-
lines.push(` ${date} ${score}/100 (${passed}/${total} passing)`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const comparison = compareOpenCodeLatest(dir);
|
|
48
|
-
if (comparison) {
|
|
49
|
-
lines.push('');
|
|
50
|
-
const sign = comparison.delta.score >= 0 ? '+' : '';
|
|
51
|
-
lines.push(` Trend: ${comparison.trend} (${sign}${comparison.delta.score} since previous)`);
|
|
52
|
-
if (comparison.improvements.length > 0) lines.push(` Fixed: ${comparison.improvements.join(', ')}`);
|
|
53
|
-
if (comparison.regressions.length > 0) lines.push(` New gaps: ${comparison.regressions.join(', ')}`);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return lines.join('\n');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// --- Compare ---
|
|
60
|
-
|
|
61
|
-
function compareOpenCodeLatest(dir) {
|
|
62
|
-
const audits = getOpenCodeHistory(dir, 2);
|
|
63
|
-
if (audits.length < 2) return null;
|
|
64
|
-
|
|
65
|
-
const current = audits[0];
|
|
66
|
-
const previous = audits[1];
|
|
67
|
-
|
|
68
|
-
const delta = {
|
|
69
|
-
score: (current.summary?.score || 0) - (previous.summary?.score || 0),
|
|
70
|
-
organic: (current.summary?.organicScore || 0) - (previous.summary?.organicScore || 0),
|
|
71
|
-
passed: (current.summary?.passed || 0) - (previous.summary?.passed || 0),
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const regressions = [];
|
|
75
|
-
const improvements = [];
|
|
76
|
-
const prevKeys = new Set(previous.summary?.topActionKeys || []);
|
|
77
|
-
const currKeys = new Set(current.summary?.topActionKeys || []);
|
|
78
|
-
for (const key of currKeys) { if (!prevKeys.has(key)) regressions.push(key); }
|
|
79
|
-
for (const key of prevKeys) { if (!currKeys.has(key)) improvements.push(key); }
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
platform: 'opencode',
|
|
83
|
-
current: { date: current.createdAt, score: current.summary?.score, passed: current.summary?.passed },
|
|
84
|
-
previous: { date: previous.createdAt, score: previous.summary?.score, passed: previous.summary?.passed },
|
|
85
|
-
delta,
|
|
86
|
-
regressions,
|
|
87
|
-
improvements,
|
|
88
|
-
trend: delta.score > 0 ? 'improving' : delta.score < 0 ? 'regressing' : 'stable',
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// --- Trend ---
|
|
93
|
-
|
|
94
|
-
function exportOpenCodeTrendReport(dir) {
|
|
95
|
-
const history = getOpenCodeHistory(dir, 50);
|
|
96
|
-
if (history.length === 0) return null;
|
|
97
|
-
|
|
98
|
-
const comparison = compareOpenCodeLatest(dir);
|
|
99
|
-
const lines = [
|
|
100
|
-
'# OpenCode Setup Trend Report',
|
|
101
|
-
'',
|
|
102
|
-
`**Project:** ${path.basename(dir)}`,
|
|
103
|
-
'**Platform:** OpenCode',
|
|
104
|
-
`**Generated:** ${new Date().toISOString().split('T')[0]}`,
|
|
105
|
-
`**Snapshots:** ${history.length}`,
|
|
106
|
-
'',
|
|
107
|
-
'## Score History',
|
|
108
|
-
'',
|
|
109
|
-
'| Date | Score | Passed | Checks |',
|
|
110
|
-
'|------|-------|--------|--------|',
|
|
111
|
-
];
|
|
112
|
-
|
|
113
|
-
for (const entry of history) {
|
|
114
|
-
const date = entry.createdAt?.split('T')[0] || '?';
|
|
115
|
-
lines.push(`| ${date} | ${entry.summary?.score ?? '?'}/100 | ${entry.summary?.passed ?? '?'} | ${entry.summary?.checkCount ?? '?'} |`);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (comparison) {
|
|
119
|
-
lines.push('');
|
|
120
|
-
lines.push('## Latest Comparison');
|
|
121
|
-
lines.push('');
|
|
122
|
-
lines.push(`- **Previous:** ${comparison.previous.score}/100 (${comparison.previous.date?.split('T')[0]})`);
|
|
123
|
-
lines.push(`- **Current:** ${comparison.current.score}/100 (${comparison.current.date?.split('T')[0]})`);
|
|
124
|
-
lines.push(`- **Delta:** ${comparison.delta.score >= 0 ? '+' : ''}${comparison.delta.score} points`);
|
|
125
|
-
lines.push(`- **Trend:** ${comparison.trend}`);
|
|
126
|
-
if (comparison.improvements.length > 0) lines.push(`- **Fixed:** ${comparison.improvements.join(', ')}`);
|
|
127
|
-
if (comparison.regressions.length > 0) lines.push(`- **New gaps:** ${comparison.regressions.join(', ')}`);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (history.length >= 3) {
|
|
131
|
-
lines.push('');
|
|
132
|
-
lines.push('## Trend Chart');
|
|
133
|
-
lines.push('');
|
|
134
|
-
lines.push('```');
|
|
135
|
-
const scores = history.slice().reverse().map(e => e.summary?.score ?? 0);
|
|
136
|
-
const max = Math.max(...scores, 100);
|
|
137
|
-
const chartHeight = 10;
|
|
138
|
-
for (let row = chartHeight; row >= 0; row--) {
|
|
139
|
-
const threshold = (row / chartHeight) * max;
|
|
140
|
-
const rowLabel = String(Math.round(threshold)).padStart(3);
|
|
141
|
-
const bar = scores.map(s => s >= threshold ? '#' : ' ').join('');
|
|
142
|
-
lines.push(`${rowLabel} |${bar}`);
|
|
143
|
-
}
|
|
144
|
-
lines.push(` +${'─'.repeat(scores.length)}`);
|
|
145
|
-
lines.push('```');
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
lines.push('');
|
|
149
|
-
lines.push('---');
|
|
150
|
-
lines.push(`*Generated by nerviq v${version} for OpenCode*`);
|
|
151
|
-
return lines.join('\n');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// --- Feedback ---
|
|
155
|
-
|
|
156
|
-
function recordOpenCodeFeedback(dir, payload) {
|
|
157
|
-
return recordRecommendationOutcome(dir, {
|
|
158
|
-
...payload,
|
|
159
|
-
source: payload.source || 'opencode-cli',
|
|
160
|
-
platform: 'opencode',
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function getOpenCodeFeedbackSummary(dir) {
|
|
165
|
-
const entries = readOutcomeIndex(dir)
|
|
166
|
-
.filter(e => e.source === 'opencode-cli' || e.platform === 'opencode');
|
|
167
|
-
return summarizeOutcomeEntries(entries);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function formatOpenCodeFeedback(dir) {
|
|
171
|
-
const summary = getOpenCodeFeedbackSummary(dir);
|
|
172
|
-
if (!summary || Object.keys(summary).length === 0) {
|
|
173
|
-
return 'No OpenCode feedback recorded yet.';
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const lines = ['OpenCode Recommendation Feedback:', ''];
|
|
177
|
-
const entries = Array.isArray(summary) ? summary : Object.values(summary);
|
|
178
|
-
for (const entry of entries) {
|
|
179
|
-
const key = entry.key || 'unknown';
|
|
180
|
-
const accepted = entry.accepted || 0;
|
|
181
|
-
const rejected = entry.rejected || 0;
|
|
182
|
-
const total = entry.total || 0;
|
|
183
|
-
lines.push(` ${key}: ${accepted} accepted, ${rejected} rejected (${total} total)`);
|
|
184
|
-
}
|
|
185
|
-
return lines.join('\n');
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// --- Insights ---
|
|
189
|
-
|
|
190
|
-
function generateOpenCodeInsights(dir) {
|
|
191
|
-
const history = getOpenCodeHistory(dir, 50);
|
|
192
|
-
const feedback = getOpenCodeFeedbackSummary(dir);
|
|
193
|
-
const insights = [];
|
|
194
|
-
|
|
195
|
-
if (history.length >= 3) {
|
|
196
|
-
const recentFailKeys = new Map();
|
|
197
|
-
for (const entry of history.slice(0, 5)) {
|
|
198
|
-
for (const key of (entry.summary?.topActionKeys || [])) {
|
|
199
|
-
recentFailKeys.set(key, (recentFailKeys.get(key) || 0) + 1);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
for (const [key, count] of recentFailKeys) {
|
|
203
|
-
if (count >= 3) {
|
|
204
|
-
insights.push({
|
|
205
|
-
type: 'persistent-failure',
|
|
206
|
-
severity: 'high',
|
|
207
|
-
key,
|
|
208
|
-
message: `Check ${key} has failed in ${count} of the last ${Math.min(history.length, 5)} audits.`,
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (history.length >= 2) {
|
|
215
|
-
const scores = history.map(e => e.summary?.score ?? 0);
|
|
216
|
-
if (scores[0] < scores[1]) {
|
|
217
|
-
insights.push({
|
|
218
|
-
type: 'regression-pattern',
|
|
219
|
-
severity: 'medium',
|
|
220
|
-
message: `Score dropped from ${scores[1]} to ${scores[0]} in the most recent audit.`,
|
|
221
|
-
delta: scores[0] - scores[1],
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (history.length >= 5) {
|
|
227
|
-
const recentScores = history.slice(0, 5).map(e => e.summary?.score ?? 0);
|
|
228
|
-
const range = Math.max(...recentScores) - Math.min(...recentScores);
|
|
229
|
-
if (range <= 2) {
|
|
230
|
-
insights.push({
|
|
231
|
-
type: 'velocity-stall',
|
|
232
|
-
severity: 'low',
|
|
233
|
-
message: `Score has been flat (range: ${range} points) over the last 5 audits.`,
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const feedbackEntries = Array.isArray(feedback) ? feedback : Object.values(feedback || {});
|
|
239
|
-
for (const entry of feedbackEntries) {
|
|
240
|
-
if (entry.rejected > entry.accepted && entry.total >= 2) {
|
|
241
|
-
insights.push({
|
|
242
|
-
type: 'feedback-signal',
|
|
243
|
-
severity: 'medium',
|
|
244
|
-
key: entry.key,
|
|
245
|
-
message: `Recommendation ${entry.key} has been rejected more than accepted (${entry.rejected}/${entry.total}).`,
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return {
|
|
251
|
-
platform: 'opencode',
|
|
252
|
-
generatedAt: new Date().toISOString(),
|
|
253
|
-
snapshotCount: history.length,
|
|
254
|
-
feedbackCount: feedbackEntries.length,
|
|
255
|
-
insights,
|
|
256
|
-
summary: insights.length === 0
|
|
257
|
-
? 'No actionable insights detected. Keep running audits to build pattern data.'
|
|
258
|
-
: `${insights.length} insight(s) detected across ${history.length} snapshots.`,
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function formatOpenCodeInsights(dir) {
|
|
263
|
-
const result = generateOpenCodeInsights(dir);
|
|
264
|
-
if (result.insights.length === 0) return result.summary;
|
|
265
|
-
|
|
266
|
-
const lines = ['OpenCode Insights:', ''];
|
|
267
|
-
for (const insight of result.insights) {
|
|
268
|
-
const severity = insight.severity.toUpperCase();
|
|
269
|
-
lines.push(` [${severity}] ${insight.message}`);
|
|
270
|
-
}
|
|
271
|
-
lines.push('');
|
|
272
|
-
lines.push(result.summary);
|
|
273
|
-
return lines.join('\n');
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
module.exports = {
|
|
277
|
-
getOpenCodeHistory,
|
|
278
|
-
formatOpenCodeHistory,
|
|
279
|
-
compareOpenCodeLatest,
|
|
280
|
-
exportOpenCodeTrendReport,
|
|
281
|
-
recordOpenCodeFeedback,
|
|
282
|
-
getOpenCodeFeedbackSummary,
|
|
283
|
-
formatOpenCodeFeedback,
|
|
284
|
-
generateOpenCodeInsights,
|
|
285
|
-
formatOpenCodeInsights,
|
|
286
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode Repeat-Usage Surfaces — 6 repeat-usage surfaces
|
|
3
|
+
*
|
|
4
|
+
* Adapts the shared activity/snapshot backend for OpenCode platform.
|
|
5
|
+
* Provides: history, compare, trend, watch, feedback, insights.
|
|
6
|
+
*
|
|
7
|
+
* OpenCode snapshots are stored alongside Claude snapshots in
|
|
8
|
+
* .nerviq/snapshots/ (legacy: .claude/nerviq-cli/snapshots/) but filtered by platform='opencode'.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const {
|
|
13
|
+
readSnapshotIndex,
|
|
14
|
+
writeSnapshotArtifact,
|
|
15
|
+
exportTrendReport: sharedExportTrendReport,
|
|
16
|
+
recordRecommendationOutcome,
|
|
17
|
+
readOutcomeIndex,
|
|
18
|
+
summarizeOutcomeEntries,
|
|
19
|
+
} = require('../activity');
|
|
20
|
+
const { version } = require('../../package.json');
|
|
21
|
+
|
|
22
|
+
// --- History ---
|
|
23
|
+
|
|
24
|
+
function getOpenCodeHistory(dir, limit = 20) {
|
|
25
|
+
const entries = readSnapshotIndex(dir);
|
|
26
|
+
return entries
|
|
27
|
+
.filter(e => e.snapshotKind === 'audit' && (e.platform === 'opencode' || e.summary?.platform === 'opencode'))
|
|
28
|
+
.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
|
29
|
+
.slice(0, limit);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function formatOpenCodeHistory(dir) {
|
|
33
|
+
const history = getOpenCodeHistory(dir, 10);
|
|
34
|
+
if (history.length === 0) {
|
|
35
|
+
return 'No OpenCode snapshots found. Run `npx nerviq --platform opencode --snapshot` to save one.';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const lines = ['OpenCode Score History (most recent first):', ''];
|
|
39
|
+
for (const entry of history) {
|
|
40
|
+
const date = entry.createdAt?.split('T')[0] || 'unknown';
|
|
41
|
+
const score = entry.summary?.score ?? '?';
|
|
42
|
+
const passed = entry.summary?.passed ?? '?';
|
|
43
|
+
const total = entry.summary?.checkCount ?? '?';
|
|
44
|
+
lines.push(` ${date} ${score}/100 (${passed}/${total} passing)`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const comparison = compareOpenCodeLatest(dir);
|
|
48
|
+
if (comparison) {
|
|
49
|
+
lines.push('');
|
|
50
|
+
const sign = comparison.delta.score >= 0 ? '+' : '';
|
|
51
|
+
lines.push(` Trend: ${comparison.trend} (${sign}${comparison.delta.score} since previous)`);
|
|
52
|
+
if (comparison.improvements.length > 0) lines.push(` Fixed: ${comparison.improvements.join(', ')}`);
|
|
53
|
+
if (comparison.regressions.length > 0) lines.push(` New gaps: ${comparison.regressions.join(', ')}`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return lines.join('\n');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// --- Compare ---
|
|
60
|
+
|
|
61
|
+
function compareOpenCodeLatest(dir) {
|
|
62
|
+
const audits = getOpenCodeHistory(dir, 2);
|
|
63
|
+
if (audits.length < 2) return null;
|
|
64
|
+
|
|
65
|
+
const current = audits[0];
|
|
66
|
+
const previous = audits[1];
|
|
67
|
+
|
|
68
|
+
const delta = {
|
|
69
|
+
score: (current.summary?.score || 0) - (previous.summary?.score || 0),
|
|
70
|
+
organic: (current.summary?.organicScore || 0) - (previous.summary?.organicScore || 0),
|
|
71
|
+
passed: (current.summary?.passed || 0) - (previous.summary?.passed || 0),
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const regressions = [];
|
|
75
|
+
const improvements = [];
|
|
76
|
+
const prevKeys = new Set(previous.summary?.topActionKeys || []);
|
|
77
|
+
const currKeys = new Set(current.summary?.topActionKeys || []);
|
|
78
|
+
for (const key of currKeys) { if (!prevKeys.has(key)) regressions.push(key); }
|
|
79
|
+
for (const key of prevKeys) { if (!currKeys.has(key)) improvements.push(key); }
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
platform: 'opencode',
|
|
83
|
+
current: { date: current.createdAt, score: current.summary?.score, passed: current.summary?.passed },
|
|
84
|
+
previous: { date: previous.createdAt, score: previous.summary?.score, passed: previous.summary?.passed },
|
|
85
|
+
delta,
|
|
86
|
+
regressions,
|
|
87
|
+
improvements,
|
|
88
|
+
trend: delta.score > 0 ? 'improving' : delta.score < 0 ? 'regressing' : 'stable',
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// --- Trend ---
|
|
93
|
+
|
|
94
|
+
function exportOpenCodeTrendReport(dir) {
|
|
95
|
+
const history = getOpenCodeHistory(dir, 50);
|
|
96
|
+
if (history.length === 0) return null;
|
|
97
|
+
|
|
98
|
+
const comparison = compareOpenCodeLatest(dir);
|
|
99
|
+
const lines = [
|
|
100
|
+
'# OpenCode Setup Trend Report',
|
|
101
|
+
'',
|
|
102
|
+
`**Project:** ${path.basename(dir)}`,
|
|
103
|
+
'**Platform:** OpenCode',
|
|
104
|
+
`**Generated:** ${new Date().toISOString().split('T')[0]}`,
|
|
105
|
+
`**Snapshots:** ${history.length}`,
|
|
106
|
+
'',
|
|
107
|
+
'## Score History',
|
|
108
|
+
'',
|
|
109
|
+
'| Date | Score | Passed | Checks |',
|
|
110
|
+
'|------|-------|--------|--------|',
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
for (const entry of history) {
|
|
114
|
+
const date = entry.createdAt?.split('T')[0] || '?';
|
|
115
|
+
lines.push(`| ${date} | ${entry.summary?.score ?? '?'}/100 | ${entry.summary?.passed ?? '?'} | ${entry.summary?.checkCount ?? '?'} |`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (comparison) {
|
|
119
|
+
lines.push('');
|
|
120
|
+
lines.push('## Latest Comparison');
|
|
121
|
+
lines.push('');
|
|
122
|
+
lines.push(`- **Previous:** ${comparison.previous.score}/100 (${comparison.previous.date?.split('T')[0]})`);
|
|
123
|
+
lines.push(`- **Current:** ${comparison.current.score}/100 (${comparison.current.date?.split('T')[0]})`);
|
|
124
|
+
lines.push(`- **Delta:** ${comparison.delta.score >= 0 ? '+' : ''}${comparison.delta.score} points`);
|
|
125
|
+
lines.push(`- **Trend:** ${comparison.trend}`);
|
|
126
|
+
if (comparison.improvements.length > 0) lines.push(`- **Fixed:** ${comparison.improvements.join(', ')}`);
|
|
127
|
+
if (comparison.regressions.length > 0) lines.push(`- **New gaps:** ${comparison.regressions.join(', ')}`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (history.length >= 3) {
|
|
131
|
+
lines.push('');
|
|
132
|
+
lines.push('## Trend Chart');
|
|
133
|
+
lines.push('');
|
|
134
|
+
lines.push('```');
|
|
135
|
+
const scores = history.slice().reverse().map(e => e.summary?.score ?? 0);
|
|
136
|
+
const max = Math.max(...scores, 100);
|
|
137
|
+
const chartHeight = 10;
|
|
138
|
+
for (let row = chartHeight; row >= 0; row--) {
|
|
139
|
+
const threshold = (row / chartHeight) * max;
|
|
140
|
+
const rowLabel = String(Math.round(threshold)).padStart(3);
|
|
141
|
+
const bar = scores.map(s => s >= threshold ? '#' : ' ').join('');
|
|
142
|
+
lines.push(`${rowLabel} |${bar}`);
|
|
143
|
+
}
|
|
144
|
+
lines.push(` +${'─'.repeat(scores.length)}`);
|
|
145
|
+
lines.push('```');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
lines.push('');
|
|
149
|
+
lines.push('---');
|
|
150
|
+
lines.push(`*Generated by nerviq v${version} for OpenCode*`);
|
|
151
|
+
return lines.join('\n');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// --- Feedback ---
|
|
155
|
+
|
|
156
|
+
function recordOpenCodeFeedback(dir, payload) {
|
|
157
|
+
return recordRecommendationOutcome(dir, {
|
|
158
|
+
...payload,
|
|
159
|
+
source: payload.source || 'opencode-cli',
|
|
160
|
+
platform: 'opencode',
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function getOpenCodeFeedbackSummary(dir) {
|
|
165
|
+
const entries = readOutcomeIndex(dir)
|
|
166
|
+
.filter(e => e.source === 'opencode-cli' || e.platform === 'opencode');
|
|
167
|
+
return summarizeOutcomeEntries(entries);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function formatOpenCodeFeedback(dir) {
|
|
171
|
+
const summary = getOpenCodeFeedbackSummary(dir);
|
|
172
|
+
if (!summary || Object.keys(summary).length === 0) {
|
|
173
|
+
return 'No OpenCode feedback recorded yet.';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const lines = ['OpenCode Recommendation Feedback:', ''];
|
|
177
|
+
const entries = Array.isArray(summary) ? summary : Object.values(summary);
|
|
178
|
+
for (const entry of entries) {
|
|
179
|
+
const key = entry.key || 'unknown';
|
|
180
|
+
const accepted = entry.accepted || 0;
|
|
181
|
+
const rejected = entry.rejected || 0;
|
|
182
|
+
const total = entry.total || 0;
|
|
183
|
+
lines.push(` ${key}: ${accepted} accepted, ${rejected} rejected (${total} total)`);
|
|
184
|
+
}
|
|
185
|
+
return lines.join('\n');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// --- Insights ---
|
|
189
|
+
|
|
190
|
+
function generateOpenCodeInsights(dir) {
|
|
191
|
+
const history = getOpenCodeHistory(dir, 50);
|
|
192
|
+
const feedback = getOpenCodeFeedbackSummary(dir);
|
|
193
|
+
const insights = [];
|
|
194
|
+
|
|
195
|
+
if (history.length >= 3) {
|
|
196
|
+
const recentFailKeys = new Map();
|
|
197
|
+
for (const entry of history.slice(0, 5)) {
|
|
198
|
+
for (const key of (entry.summary?.topActionKeys || [])) {
|
|
199
|
+
recentFailKeys.set(key, (recentFailKeys.get(key) || 0) + 1);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
for (const [key, count] of recentFailKeys) {
|
|
203
|
+
if (count >= 3) {
|
|
204
|
+
insights.push({
|
|
205
|
+
type: 'persistent-failure',
|
|
206
|
+
severity: 'high',
|
|
207
|
+
key,
|
|
208
|
+
message: `Check ${key} has failed in ${count} of the last ${Math.min(history.length, 5)} audits.`,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (history.length >= 2) {
|
|
215
|
+
const scores = history.map(e => e.summary?.score ?? 0);
|
|
216
|
+
if (scores[0] < scores[1]) {
|
|
217
|
+
insights.push({
|
|
218
|
+
type: 'regression-pattern',
|
|
219
|
+
severity: 'medium',
|
|
220
|
+
message: `Score dropped from ${scores[1]} to ${scores[0]} in the most recent audit.`,
|
|
221
|
+
delta: scores[0] - scores[1],
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (history.length >= 5) {
|
|
227
|
+
const recentScores = history.slice(0, 5).map(e => e.summary?.score ?? 0);
|
|
228
|
+
const range = Math.max(...recentScores) - Math.min(...recentScores);
|
|
229
|
+
if (range <= 2) {
|
|
230
|
+
insights.push({
|
|
231
|
+
type: 'velocity-stall',
|
|
232
|
+
severity: 'low',
|
|
233
|
+
message: `Score has been flat (range: ${range} points) over the last 5 audits.`,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const feedbackEntries = Array.isArray(feedback) ? feedback : Object.values(feedback || {});
|
|
239
|
+
for (const entry of feedbackEntries) {
|
|
240
|
+
if (entry.rejected > entry.accepted && entry.total >= 2) {
|
|
241
|
+
insights.push({
|
|
242
|
+
type: 'feedback-signal',
|
|
243
|
+
severity: 'medium',
|
|
244
|
+
key: entry.key,
|
|
245
|
+
message: `Recommendation ${entry.key} has been rejected more than accepted (${entry.rejected}/${entry.total}).`,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
platform: 'opencode',
|
|
252
|
+
generatedAt: new Date().toISOString(),
|
|
253
|
+
snapshotCount: history.length,
|
|
254
|
+
feedbackCount: feedbackEntries.length,
|
|
255
|
+
insights,
|
|
256
|
+
summary: insights.length === 0
|
|
257
|
+
? 'No actionable insights detected. Keep running audits to build pattern data.'
|
|
258
|
+
: `${insights.length} insight(s) detected across ${history.length} snapshots.`,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function formatOpenCodeInsights(dir) {
|
|
263
|
+
const result = generateOpenCodeInsights(dir);
|
|
264
|
+
if (result.insights.length === 0) return result.summary;
|
|
265
|
+
|
|
266
|
+
const lines = ['OpenCode Insights:', ''];
|
|
267
|
+
for (const insight of result.insights) {
|
|
268
|
+
const severity = insight.severity.toUpperCase();
|
|
269
|
+
lines.push(` [${severity}] ${insight.message}`);
|
|
270
|
+
}
|
|
271
|
+
lines.push('');
|
|
272
|
+
lines.push(result.summary);
|
|
273
|
+
return lines.join('\n');
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
module.exports = {
|
|
277
|
+
getOpenCodeHistory,
|
|
278
|
+
formatOpenCodeHistory,
|
|
279
|
+
compareOpenCodeLatest,
|
|
280
|
+
exportOpenCodeTrendReport,
|
|
281
|
+
recordOpenCodeFeedback,
|
|
282
|
+
getOpenCodeFeedbackSummary,
|
|
283
|
+
formatOpenCodeFeedback,
|
|
284
|
+
generateOpenCodeInsights,
|
|
285
|
+
formatOpenCodeInsights,
|
|
286
|
+
};
|