@nerviq/cli 1.29.0 → 1.30.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.
Files changed (93) hide show
  1. package/CHANGELOG.md +1764 -1493
  2. package/README.md +568 -538
  3. package/SECURITY.md +78 -82
  4. package/bin/cli.js +2838 -2558
  5. package/docs/api-reference.md +356 -356
  6. package/docs/audit-fix.md +109 -0
  7. package/docs/autofix.md +3 -62
  8. package/docs/getting-started.md +1 -1
  9. package/docs/index.html +592 -592
  10. package/docs/integration-contracts.md +287 -287
  11. package/docs/maintenance.md +128 -128
  12. package/docs/new-platform-guide.md +202 -202
  13. package/docs/release-process.md +63 -0
  14. package/docs/shallow-risk.md +244 -244
  15. package/docs/why-nerviq.md +82 -82
  16. package/package.json +75 -67
  17. package/sdk/README.md +12 -3
  18. package/sdk/examples/langchain-integration.md +128 -0
  19. package/sdk/examples/self-governing-agent.js +135 -0
  20. package/sdk/index.d.ts +115 -0
  21. package/sdk/index.js +94 -0
  22. package/sdk/package.json +11 -0
  23. package/src/activity.js +13 -0
  24. package/src/aider/activity.js +226 -226
  25. package/src/aider/context.js +162 -162
  26. package/src/aider/freshness.js +123 -123
  27. package/src/aider/techniques.js +3465 -3465
  28. package/src/audit/layers.js +180 -180
  29. package/src/audit.js +1133 -1032
  30. package/src/auto-suggest.js +9 -2
  31. package/src/behavioral-drift.js +37 -2
  32. package/src/benchmark.js +299 -299
  33. package/src/codex/activity.js +324 -324
  34. package/src/codex/freshness.js +149 -142
  35. package/src/codex/techniques.js +4895 -4895
  36. package/src/context.js +326 -326
  37. package/src/continuous-ops.js +11 -1
  38. package/src/convert.js +340 -340
  39. package/src/copilot/config-parser.js +280 -280
  40. package/src/copilot/context.js +218 -218
  41. package/src/copilot/freshness.js +184 -177
  42. package/src/copilot/patch.js +238 -238
  43. package/src/copilot/techniques.js +3578 -3578
  44. package/src/cursor/freshness.js +194 -194
  45. package/src/cursor/patch.js +243 -243
  46. package/src/cursor/techniques.js +3735 -3735
  47. package/src/doctor.js +201 -201
  48. package/src/fix-engine.js +511 -8
  49. package/src/formatters/csv.js +86 -86
  50. package/src/formatters/junit.js +123 -123
  51. package/src/formatters/markdown.js +164 -164
  52. package/src/formatters/otel.js +151 -151
  53. package/src/freshness.js +163 -156
  54. package/src/gemini/activity.js +402 -402
  55. package/src/gemini/context.js +290 -290
  56. package/src/gemini/freshness.js +188 -188
  57. package/src/gemini/patch.js +229 -229
  58. package/src/gemini/techniques.js +3811 -3811
  59. package/src/governance.js +533 -533
  60. package/src/harmony/audit.js +306 -306
  61. package/src/i18n.js +63 -63
  62. package/src/insights.js +119 -119
  63. package/src/integrations.js +134 -134
  64. package/src/locales/en.json +33 -33
  65. package/src/locales/es.json +33 -33
  66. package/src/migrate.js +354 -354
  67. package/src/opencode/activity.js +286 -286
  68. package/src/opencode/freshness.js +137 -137
  69. package/src/opencode/techniques.js +3450 -3450
  70. package/src/safe-glyph.js +97 -0
  71. package/src/setup/analysis.js +12 -12
  72. package/src/setup.js +13 -6
  73. package/src/shallow-risk/index.js +113 -56
  74. package/src/shallow-risk/patterns/agent-config-cross-platform-drift.js +51 -50
  75. package/src/shallow-risk/patterns/agent-config-dangerous-autoapprove.js +47 -46
  76. package/src/shallow-risk/patterns/agent-config-deprecated-keys.js +47 -46
  77. package/src/shallow-risk/patterns/agent-config-framework-version-mismatch.js +138 -0
  78. package/src/shallow-risk/patterns/agent-config-missing-file.js +318 -317
  79. package/src/shallow-risk/patterns/agent-config-script-not-in-package-json.js +108 -0
  80. package/src/shallow-risk/patterns/agent-config-secret-literal.js +52 -49
  81. package/src/shallow-risk/patterns/agent-config-stack-contradiction.js +35 -34
  82. package/src/shallow-risk/patterns/hook-script-missing.js +71 -70
  83. package/src/shallow-risk/patterns/mcp-server-no-allowlist.js +53 -52
  84. package/src/shallow-risk/shared.js +653 -648
  85. package/src/source-urls.js +295 -295
  86. package/src/state-paths.js +85 -85
  87. package/src/supplemental-checks.js +805 -805
  88. package/src/telemetry.js +160 -160
  89. package/src/watch.js +46 -0
  90. package/src/windsurf/context.js +359 -359
  91. package/src/windsurf/freshness.js +194 -194
  92. package/src/windsurf/patch.js +231 -231
  93. package/src/windsurf/techniques.js +3779 -3779
package/src/activity.js CHANGED
@@ -683,6 +683,19 @@ function recordRecommendationOutcome(dir, payload) {
683
683
  relativePath: path.relative(dir, filePath),
684
684
  });
685
685
 
686
+ // BUG-07 fix: also bump the usage-patterns counter so suggest-rules
687
+ // sees the recorded outcome. Previously feedback wrote to outcomes/
688
+ // and suggest-rules read from feedback/patterns.json — two stores
689
+ // that never cross-fed. The map: accepted→accepted, rejected→rejected,
690
+ // deferred→skipped (matching usage-patterns vocabulary).
691
+ try {
692
+ const { recordPattern } = require('./usage-patterns');
693
+ const patternAction = status === 'deferred' ? 'skipped' : status;
694
+ recordPattern(dir, key, patternAction);
695
+ } catch {
696
+ // Non-fatal — outcomes file already written; pattern bump is additive.
697
+ }
698
+
686
699
  return {
687
700
  id,
688
701
  filePath,
@@ -1,226 +1,226 @@
1
- /**
2
- * Aider Repeat-Usage Surfaces — 6 activity surfaces
3
- *
4
- * Adapts the shared activity/snapshot backend for Aider platform.
5
- * Provides: history, compare, trend, watch, feedback, insights.
6
- *
7
- * Aider snapshots stored in .nerviq/snapshots/ (legacy: .claude/nerviq-cli/snapshots/) filtered by platform='aider'.
8
- */
9
-
10
- const path = require('path');
11
- const {
12
- getHistory: getSharedHistory,
13
- compareLatest: sharedCompareLatest,
14
- readSnapshotIndex,
15
- writeSnapshotArtifact,
16
- exportTrendReport: sharedExportTrendReport,
17
- recordRecommendationOutcome,
18
- readOutcomeIndex,
19
- summarizeOutcomeEntries,
20
- } = require('../activity');
21
- const { version } = require('../../package.json');
22
-
23
- // --- History ---
24
-
25
- function getAiderHistory(dir, limit = 20) {
26
- const entries = readSnapshotIndex(dir);
27
- return entries
28
- .filter(e => e.snapshotKind === 'audit' && (e.platform === 'aider' || e.summary?.platform === 'aider'))
29
- .sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
30
- .slice(0, limit);
31
- }
32
-
33
- function formatAiderHistory(dir) {
34
- const history = getAiderHistory(dir, 10);
35
- if (history.length === 0) {
36
- return 'No Aider snapshots found. Run `npx nerviq --platform aider --snapshot` to save one.';
37
- }
38
-
39
- const lines = ['Aider Score History (most recent first):', ''];
40
- for (const entry of history) {
41
- const date = entry.createdAt?.split('T')[0] || 'unknown';
42
- const score = entry.summary?.score ?? '?';
43
- const passed = entry.summary?.passed ?? '?';
44
- const total = entry.summary?.checkCount ?? '?';
45
- lines.push(` ${date} ${score}/100 (${passed}/${total} passing)`);
46
- }
47
-
48
- const comparison = compareAiderLatest(dir);
49
- if (comparison) {
50
- lines.push('');
51
- const sign = comparison.delta.score >= 0 ? '+' : '';
52
- lines.push(` Trend: ${comparison.trend} (${sign}${comparison.delta.score} since previous)`);
53
- if (comparison.improvements.length > 0) {
54
- lines.push(` Fixed: ${comparison.improvements.join(', ')}`);
55
- }
56
- if (comparison.regressions.length > 0) {
57
- lines.push(` New gaps: ${comparison.regressions.join(', ')}`);
58
- }
59
- }
60
-
61
- return lines.join('\n');
62
- }
63
-
64
- // --- Compare ---
65
-
66
- function compareAiderLatest(dir) {
67
- const audits = getAiderHistory(dir, 2);
68
- if (audits.length < 2) return null;
69
-
70
- const current = audits[0];
71
- const previous = audits[1];
72
-
73
- const currentPassed = new Set(current.summary?.passedIds || []);
74
- const previousPassed = new Set(previous.summary?.passedIds || []);
75
-
76
- const improvements = [];
77
- const regressions = [];
78
-
79
- for (const id of currentPassed) {
80
- if (!previousPassed.has(id)) improvements.push(id);
81
- }
82
- for (const id of previousPassed) {
83
- if (!currentPassed.has(id)) regressions.push(id);
84
- }
85
-
86
- const scoreDelta = (current.summary?.score ?? 0) - (previous.summary?.score ?? 0);
87
-
88
- return {
89
- trend: scoreDelta > 0 ? 'improving' : scoreDelta < 0 ? 'regressing' : 'stable',
90
- delta: { score: scoreDelta },
91
- improvements,
92
- regressions,
93
- currentSnapshot: current,
94
- previousSnapshot: previous,
95
- };
96
- }
97
-
98
- // --- Trend Export ---
99
-
100
- function exportAiderTrendReport(dir) {
101
- const history = getAiderHistory(dir, 50);
102
- if (history.length === 0) return null;
103
-
104
- return {
105
- platform: 'aider',
106
- generatedAt: new Date().toISOString(),
107
- nerviqVersion: version,
108
- snapshotCount: history.length,
109
- dataPoints: history.map(entry => ({
110
- date: entry.createdAt,
111
- score: entry.summary?.score ?? null,
112
- passed: entry.summary?.passed ?? null,
113
- checkCount: entry.summary?.checkCount ?? null,
114
- })),
115
- };
116
- }
117
-
118
- // --- Feedback ---
119
-
120
- function recordAiderFeedback(dir, recommendationId, outcome, notes = '') {
121
- return recordRecommendationOutcome(dir, {
122
- platform: 'aider',
123
- recommendationId,
124
- outcome,
125
- notes,
126
- });
127
- }
128
-
129
- function getAiderFeedbackSummary(dir) {
130
- const entries = readOutcomeIndex(dir);
131
- const aiderEntries = entries.filter(e => e.platform === 'aider');
132
- return summarizeOutcomeEntries(aiderEntries);
133
- }
134
-
135
- function formatAiderFeedback(dir) {
136
- const summary = getAiderFeedbackSummary(dir);
137
- if (summary.total === 0) {
138
- return 'No Aider recommendation feedback recorded yet.';
139
- }
140
-
141
- const lines = [
142
- 'Aider Recommendation Feedback:',
143
- '',
144
- ` Total: ${summary.total}`,
145
- ` Accepted: ${summary.accepted}`,
146
- ` Rejected: ${summary.rejected}`,
147
- ` Deferred: ${summary.deferred}`,
148
- ];
149
-
150
- if (summary.acceptanceRate !== null) {
151
- lines.push(` Acceptance rate: ${(summary.acceptanceRate * 100).toFixed(0)}%`);
152
- }
153
-
154
- return lines.join('\n');
155
- }
156
-
157
- // --- Insights ---
158
-
159
- function generateAiderInsights(dir) {
160
- const history = getAiderHistory(dir, 10);
161
- const feedback = getAiderFeedbackSummary(dir);
162
- const insights = [];
163
-
164
- if (history.length >= 3) {
165
- const recent = history.slice(0, 3);
166
- const avgScore = recent.reduce((sum, e) => sum + (e.summary?.score ?? 0), 0) / recent.length;
167
-
168
- if (avgScore < 40) {
169
- insights.push({
170
- severity: 'high',
171
- message: 'Aider setup score consistently low — prioritize .aider.conf.yml and CONVENTIONS.md.',
172
- });
173
- }
174
-
175
- const comparison = compareAiderLatest(dir);
176
- if (comparison && comparison.regressions.length > 2) {
177
- insights.push({
178
- severity: 'medium',
179
- message: `${comparison.regressions.length} checks regressed since last snapshot.`,
180
- });
181
- }
182
- }
183
-
184
- if (feedback.total > 5 && feedback.acceptanceRate !== null && feedback.acceptanceRate < 0.5) {
185
- insights.push({
186
- severity: 'medium',
187
- message: 'Low recommendation acceptance rate — review convention file relevance.',
188
- });
189
- }
190
-
191
- return {
192
- platform: 'aider',
193
- insights,
194
- summary: insights.length === 0
195
- ? 'No actionable Aider insights at this time.'
196
- : `${insights.length} Aider insight(s) found.`,
197
- };
198
- }
199
-
200
- function formatAiderInsights(dir) {
201
- const result = generateAiderInsights(dir);
202
- if (result.insights.length === 0) {
203
- return result.summary;
204
- }
205
-
206
- const lines = ['Aider Insights:', ''];
207
- for (const insight of result.insights) {
208
- const severity = insight.severity.toUpperCase();
209
- lines.push(` [${severity}] ${insight.message}`);
210
- }
211
- lines.push('');
212
- lines.push(result.summary);
213
- return lines.join('\n');
214
- }
215
-
216
- module.exports = {
217
- getAiderHistory,
218
- formatAiderHistory,
219
- compareAiderLatest,
220
- exportAiderTrendReport,
221
- recordAiderFeedback,
222
- getAiderFeedbackSummary,
223
- formatAiderFeedback,
224
- generateAiderInsights,
225
- formatAiderInsights,
226
- };
1
+ /**
2
+ * Aider Repeat-Usage Surfaces — 6 activity surfaces
3
+ *
4
+ * Adapts the shared activity/snapshot backend for Aider platform.
5
+ * Provides: history, compare, trend, watch, feedback, insights.
6
+ *
7
+ * Aider snapshots stored in .nerviq/snapshots/ (legacy: .claude/nerviq-cli/snapshots/) filtered by platform='aider'.
8
+ */
9
+
10
+ const path = require('path');
11
+ const {
12
+ getHistory: getSharedHistory,
13
+ compareLatest: sharedCompareLatest,
14
+ readSnapshotIndex,
15
+ writeSnapshotArtifact,
16
+ exportTrendReport: sharedExportTrendReport,
17
+ recordRecommendationOutcome,
18
+ readOutcomeIndex,
19
+ summarizeOutcomeEntries,
20
+ } = require('../activity');
21
+ const { version } = require('../../package.json');
22
+
23
+ // --- History ---
24
+
25
+ function getAiderHistory(dir, limit = 20) {
26
+ const entries = readSnapshotIndex(dir);
27
+ return entries
28
+ .filter(e => e.snapshotKind === 'audit' && (e.platform === 'aider' || e.summary?.platform === 'aider'))
29
+ .sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
30
+ .slice(0, limit);
31
+ }
32
+
33
+ function formatAiderHistory(dir) {
34
+ const history = getAiderHistory(dir, 10);
35
+ if (history.length === 0) {
36
+ return 'No Aider snapshots found. Run `npx nerviq --platform aider --snapshot` to save one.';
37
+ }
38
+
39
+ const lines = ['Aider Score History (most recent first):', ''];
40
+ for (const entry of history) {
41
+ const date = entry.createdAt?.split('T')[0] || 'unknown';
42
+ const score = entry.summary?.score ?? '?';
43
+ const passed = entry.summary?.passed ?? '?';
44
+ const total = entry.summary?.checkCount ?? '?';
45
+ lines.push(` ${date} ${score}/100 (${passed}/${total} passing)`);
46
+ }
47
+
48
+ const comparison = compareAiderLatest(dir);
49
+ if (comparison) {
50
+ lines.push('');
51
+ const sign = comparison.delta.score >= 0 ? '+' : '';
52
+ lines.push(` Trend: ${comparison.trend} (${sign}${comparison.delta.score} since previous)`);
53
+ if (comparison.improvements.length > 0) {
54
+ lines.push(` Fixed: ${comparison.improvements.join(', ')}`);
55
+ }
56
+ if (comparison.regressions.length > 0) {
57
+ lines.push(` New gaps: ${comparison.regressions.join(', ')}`);
58
+ }
59
+ }
60
+
61
+ return lines.join('\n');
62
+ }
63
+
64
+ // --- Compare ---
65
+
66
+ function compareAiderLatest(dir) {
67
+ const audits = getAiderHistory(dir, 2);
68
+ if (audits.length < 2) return null;
69
+
70
+ const current = audits[0];
71
+ const previous = audits[1];
72
+
73
+ const currentPassed = new Set(current.summary?.passedIds || []);
74
+ const previousPassed = new Set(previous.summary?.passedIds || []);
75
+
76
+ const improvements = [];
77
+ const regressions = [];
78
+
79
+ for (const id of currentPassed) {
80
+ if (!previousPassed.has(id)) improvements.push(id);
81
+ }
82
+ for (const id of previousPassed) {
83
+ if (!currentPassed.has(id)) regressions.push(id);
84
+ }
85
+
86
+ const scoreDelta = (current.summary?.score ?? 0) - (previous.summary?.score ?? 0);
87
+
88
+ return {
89
+ trend: scoreDelta > 0 ? 'improving' : scoreDelta < 0 ? 'regressing' : 'stable',
90
+ delta: { score: scoreDelta },
91
+ improvements,
92
+ regressions,
93
+ currentSnapshot: current,
94
+ previousSnapshot: previous,
95
+ };
96
+ }
97
+
98
+ // --- Trend Export ---
99
+
100
+ function exportAiderTrendReport(dir) {
101
+ const history = getAiderHistory(dir, 50);
102
+ if (history.length === 0) return null;
103
+
104
+ return {
105
+ platform: 'aider',
106
+ generatedAt: new Date().toISOString(),
107
+ nerviqVersion: version,
108
+ snapshotCount: history.length,
109
+ dataPoints: history.map(entry => ({
110
+ date: entry.createdAt,
111
+ score: entry.summary?.score ?? null,
112
+ passed: entry.summary?.passed ?? null,
113
+ checkCount: entry.summary?.checkCount ?? null,
114
+ })),
115
+ };
116
+ }
117
+
118
+ // --- Feedback ---
119
+
120
+ function recordAiderFeedback(dir, recommendationId, outcome, notes = '') {
121
+ return recordRecommendationOutcome(dir, {
122
+ platform: 'aider',
123
+ recommendationId,
124
+ outcome,
125
+ notes,
126
+ });
127
+ }
128
+
129
+ function getAiderFeedbackSummary(dir) {
130
+ const entries = readOutcomeIndex(dir);
131
+ const aiderEntries = entries.filter(e => e.platform === 'aider');
132
+ return summarizeOutcomeEntries(aiderEntries);
133
+ }
134
+
135
+ function formatAiderFeedback(dir) {
136
+ const summary = getAiderFeedbackSummary(dir);
137
+ if (summary.total === 0) {
138
+ return 'No Aider recommendation feedback recorded yet.';
139
+ }
140
+
141
+ const lines = [
142
+ 'Aider Recommendation Feedback:',
143
+ '',
144
+ ` Total: ${summary.total}`,
145
+ ` Accepted: ${summary.accepted}`,
146
+ ` Rejected: ${summary.rejected}`,
147
+ ` Deferred: ${summary.deferred}`,
148
+ ];
149
+
150
+ if (summary.acceptanceRate !== null) {
151
+ lines.push(` Acceptance rate: ${(summary.acceptanceRate * 100).toFixed(0)}%`);
152
+ }
153
+
154
+ return lines.join('\n');
155
+ }
156
+
157
+ // --- Insights ---
158
+
159
+ function generateAiderInsights(dir) {
160
+ const history = getAiderHistory(dir, 10);
161
+ const feedback = getAiderFeedbackSummary(dir);
162
+ const insights = [];
163
+
164
+ if (history.length >= 3) {
165
+ const recent = history.slice(0, 3);
166
+ const avgScore = recent.reduce((sum, e) => sum + (e.summary?.score ?? 0), 0) / recent.length;
167
+
168
+ if (avgScore < 40) {
169
+ insights.push({
170
+ severity: 'high',
171
+ message: 'Aider setup score consistently low — prioritize .aider.conf.yml and CONVENTIONS.md.',
172
+ });
173
+ }
174
+
175
+ const comparison = compareAiderLatest(dir);
176
+ if (comparison && comparison.regressions.length > 2) {
177
+ insights.push({
178
+ severity: 'medium',
179
+ message: `${comparison.regressions.length} checks regressed since last snapshot.`,
180
+ });
181
+ }
182
+ }
183
+
184
+ if (feedback.total > 5 && feedback.acceptanceRate !== null && feedback.acceptanceRate < 0.5) {
185
+ insights.push({
186
+ severity: 'medium',
187
+ message: 'Low recommendation acceptance rate — review convention file relevance.',
188
+ });
189
+ }
190
+
191
+ return {
192
+ platform: 'aider',
193
+ insights,
194
+ summary: insights.length === 0
195
+ ? 'No actionable Aider insights at this time.'
196
+ : `${insights.length} Aider insight(s) found.`,
197
+ };
198
+ }
199
+
200
+ function formatAiderInsights(dir) {
201
+ const result = generateAiderInsights(dir);
202
+ if (result.insights.length === 0) {
203
+ return result.summary;
204
+ }
205
+
206
+ const lines = ['Aider Insights:', ''];
207
+ for (const insight of result.insights) {
208
+ const severity = insight.severity.toUpperCase();
209
+ lines.push(` [${severity}] ${insight.message}`);
210
+ }
211
+ lines.push('');
212
+ lines.push(result.summary);
213
+ return lines.join('\n');
214
+ }
215
+
216
+ module.exports = {
217
+ getAiderHistory,
218
+ formatAiderHistory,
219
+ compareAiderLatest,
220
+ exportAiderTrendReport,
221
+ recordAiderFeedback,
222
+ getAiderFeedbackSummary,
223
+ formatAiderFeedback,
224
+ generateAiderInsights,
225
+ formatAiderInsights,
226
+ };