@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
@@ -1,86 +1,86 @@
1
- /**
2
- * CSV Formatter (RFC 4180)
3
- *
4
- * One row per check in a nerviq audit result.
5
- * Columns: key,id,name,category,layer,rating,severity,passed,file,line,sourceUrl,fix
6
- *
7
- * The `layer` column (added in CTO-08) is one of 'governance',
8
- * 'drift', 'hygiene', or 'shallow-risk' — see docs/integration-contracts.md §8.
9
- *
10
- * Quoting rules (RFC 4180):
11
- * - Fields containing comma, double-quote, CR, or LF are wrapped in
12
- * double-quotes.
13
- * - Internal double-quotes are escaped by doubling them.
14
- * - Header row is emitted first.
15
- * - No UTF-8 BOM (some consumers mishandle it).
16
- * - Line separator: LF (consumers accept LF; JUnit/XLSX/csv parsers
17
- * normalize both).
18
- */
19
-
20
- 'use strict';
21
-
22
- const COLUMNS = [
23
- 'key',
24
- 'id',
25
- 'name',
26
- 'category',
27
- 'layer',
28
- 'rating',
29
- 'severity',
30
- 'passed',
31
- 'file',
32
- 'line',
33
- 'sourceUrl',
34
- 'fix',
35
- 'projectedScoreDelta',
36
- 'projectedScoreAfter',
37
- ];
38
-
39
- function csvEscape(value) {
40
- if (value === null || value === undefined) return '';
41
- const s = String(value);
42
- if (/[",\r\n]/.test(s)) {
43
- return `"${s.replace(/"/g, '""')}"`;
44
- }
45
- return s;
46
- }
47
-
48
- function rowFor(r, projections = null) {
49
- const severity = r.severity || r.impact || '';
50
- const proj = r.layer === 'shallow-risk' ? null : (projections && projections.get(r.key));
51
- const cells = [
52
- r.key ?? '',
53
- r.id ?? '',
54
- r.name ?? '',
55
- r.category ?? '',
56
- r.layer ?? '',
57
- r.rating ?? '',
58
- severity,
59
- r.passed === null || r.passed === undefined ? '' : String(r.passed),
60
- r.file ?? '',
61
- r.line ?? '',
62
- r.sourceUrl ?? '',
63
- r.fix ?? '',
64
- proj && Number.isFinite(proj.projectedScoreDelta) ? String(proj.projectedScoreDelta) : '',
65
- proj && Number.isFinite(proj.projectedScoreAfter) ? String(proj.projectedScoreAfter) : '',
66
- ];
67
- return cells.map(csvEscape).join(',');
68
- }
69
-
70
- function formatCsv(auditResult) {
71
- const results = Array.isArray(auditResult.results) ? auditResult.results : [];
72
- const shallowRiskHints = Array.isArray(auditResult.shallowRiskHints) ? auditResult.shallowRiskHints : [];
73
- const projections = new Map();
74
- if (Array.isArray(auditResult.topNextActions)) {
75
- for (const item of auditResult.topNextActions) {
76
- if (item && item.key) projections.set(item.key, item);
77
- }
78
- }
79
- const lines = [COLUMNS.join(',')];
80
- for (const r of [...results, ...shallowRiskHints]) {
81
- lines.push(rowFor(r, projections));
82
- }
83
- return lines.join('\n');
84
- }
85
-
86
- module.exports = { formatCsv, CSV_COLUMNS: COLUMNS };
1
+ /**
2
+ * CSV Formatter (RFC 4180)
3
+ *
4
+ * One row per check in a nerviq audit result.
5
+ * Columns: key,id,name,category,layer,rating,severity,passed,file,line,sourceUrl,fix
6
+ *
7
+ * The `layer` column (added in CTO-08) is one of 'governance',
8
+ * 'drift', 'hygiene', or 'shallow-risk' — see docs/integration-contracts.md §8.
9
+ *
10
+ * Quoting rules (RFC 4180):
11
+ * - Fields containing comma, double-quote, CR, or LF are wrapped in
12
+ * double-quotes.
13
+ * - Internal double-quotes are escaped by doubling them.
14
+ * - Header row is emitted first.
15
+ * - No UTF-8 BOM (some consumers mishandle it).
16
+ * - Line separator: LF (consumers accept LF; JUnit/XLSX/csv parsers
17
+ * normalize both).
18
+ */
19
+
20
+ 'use strict';
21
+
22
+ const COLUMNS = [
23
+ 'key',
24
+ 'id',
25
+ 'name',
26
+ 'category',
27
+ 'layer',
28
+ 'rating',
29
+ 'severity',
30
+ 'passed',
31
+ 'file',
32
+ 'line',
33
+ 'sourceUrl',
34
+ 'fix',
35
+ 'projectedScoreDelta',
36
+ 'projectedScoreAfter',
37
+ ];
38
+
39
+ function csvEscape(value) {
40
+ if (value === null || value === undefined) return '';
41
+ const s = String(value);
42
+ if (/[",\r\n]/.test(s)) {
43
+ return `"${s.replace(/"/g, '""')}"`;
44
+ }
45
+ return s;
46
+ }
47
+
48
+ function rowFor(r, projections = null) {
49
+ const severity = r.severity || r.impact || '';
50
+ const proj = r.layer === 'shallow-risk' ? null : (projections && projections.get(r.key));
51
+ const cells = [
52
+ r.key ?? '',
53
+ r.id ?? '',
54
+ r.name ?? '',
55
+ r.category ?? '',
56
+ r.layer ?? '',
57
+ r.rating ?? '',
58
+ severity,
59
+ r.passed === null || r.passed === undefined ? '' : String(r.passed),
60
+ r.file ?? '',
61
+ r.line ?? '',
62
+ r.sourceUrl ?? '',
63
+ r.fix ?? '',
64
+ proj && Number.isFinite(proj.projectedScoreDelta) ? String(proj.projectedScoreDelta) : '',
65
+ proj && Number.isFinite(proj.projectedScoreAfter) ? String(proj.projectedScoreAfter) : '',
66
+ ];
67
+ return cells.map(csvEscape).join(',');
68
+ }
69
+
70
+ function formatCsv(auditResult) {
71
+ const results = Array.isArray(auditResult.results) ? auditResult.results : [];
72
+ const shallowRiskHints = Array.isArray(auditResult.shallowRiskHints) ? auditResult.shallowRiskHints : [];
73
+ const projections = new Map();
74
+ if (Array.isArray(auditResult.topNextActions)) {
75
+ for (const item of auditResult.topNextActions) {
76
+ if (item && item.key) projections.set(item.key, item);
77
+ }
78
+ }
79
+ const lines = [COLUMNS.join(',')];
80
+ for (const r of [...results, ...shallowRiskHints]) {
81
+ lines.push(rowFor(r, projections));
82
+ }
83
+ return lines.join('\n');
84
+ }
85
+
86
+ module.exports = { formatCsv, CSV_COLUMNS: COLUMNS };
@@ -1,123 +1,123 @@
1
- /**
2
- * JUnit XML Formatter
3
- *
4
- * Converts a nerviq audit result into Jenkins-compatible JUnit XML.
5
- * Schema: <testsuites><testsuite><testcase><failure/></testcase></testsuite></testsuites>
6
- *
7
- * - One <testsuite> per check category.
8
- * - Each check becomes a <testcase> (classname = category, name = key).
9
- * - Failed checks emit a <failure message="..." type="..."/> where:
10
- * - message = check.fix || check.name
11
- * - type = severity (check.severity || check.impact)
12
- * - Skipped checks emit <skipped/>.
13
- *
14
- * Parses with any standard JUnit XML consumer (GitHub Actions test
15
- * reporter, Jenkins, GitLab CI, CircleCI).
16
- */
17
-
18
- 'use strict';
19
-
20
- const { version: nerviqVersion } = require('../../package.json');
21
-
22
- function escapeXml(value) {
23
- if (value === null || value === undefined) return '';
24
- return String(value)
25
- .replace(/&/g, '&amp;')
26
- .replace(/</g, '&lt;')
27
- .replace(/>/g, '&gt;')
28
- .replace(/"/g, '&quot;')
29
- .replace(/'/g, '&apos;');
30
- }
31
-
32
- function severityFor(r) {
33
- return r.severity || r.impact || 'medium';
34
- }
35
-
36
- function groupByCategory(results) {
37
- const map = new Map();
38
- for (const r of results) {
39
- const cat = r.category || 'uncategorized';
40
- if (!map.has(cat)) map.set(cat, []);
41
- map.get(cat).push(r);
42
- }
43
- return map;
44
- }
45
-
46
- function formatJUnit(auditResult) {
47
- const allResults = Array.isArray(auditResult.results) ? auditResult.results : [];
48
- const shallowRiskHints = Array.isArray(auditResult.shallowRiskHints) ? auditResult.shallowRiskHints : [];
49
- const timestamp = auditResult.timestamp || new Date().toISOString();
50
- const platform = auditResult.platform || 'claude';
51
-
52
- const totalTests = allResults.length + shallowRiskHints.length;
53
- const totalFailures = allResults.filter((r) => r.passed === false).length + shallowRiskHints.length;
54
- const totalSkipped = allResults.filter((r) => r.passed === null || r.skipped === true).length;
55
-
56
- const byCategory = groupByCategory(allResults);
57
-
58
- const lines = [];
59
- lines.push('<?xml version="1.0" encoding="UTF-8"?>');
60
- lines.push(
61
- `<testsuites name="nerviq" tests="${totalTests}" failures="${totalFailures}" skipped="${totalSkipped}" time="0">`,
62
- );
63
-
64
- for (const [category, checks] of byCategory) {
65
- const suiteFailures = checks.filter((r) => r.passed === false).length;
66
- const suiteSkipped = checks.filter((r) => r.passed === null || r.skipped === true).length;
67
- lines.push(
68
- ` <testsuite name="${escapeXml(category)}" tests="${checks.length}" failures="${suiteFailures}" skipped="${suiteSkipped}" time="0" timestamp="${escapeXml(timestamp)}" package="nerviq.${escapeXml(platform)}">`,
69
- );
70
-
71
- for (const r of checks) {
72
- const classname = escapeXml(r.category || 'uncategorized');
73
- const name = escapeXml(r.key || r.id || r.name || 'unknown');
74
- // CTO-08: surface scope layer as a testcase attribute so JUnit
75
- // consumers (GitHub Actions, Jenkins, GitLab) can filter/group.
76
- const layerAttr = r.layer ? ` layer="${escapeXml(r.layer)}"` : '';
77
- if (r.passed === false) {
78
- const msg = escapeXml(r.fix || r.name || r.key || 'check failed');
79
- const type = escapeXml(severityFor(r));
80
- let body = `${r.name || ''}`;
81
- if (r.file) body += ` at ${r.file}${r.line ? ':' + r.line : ''}`;
82
- if (r.sourceUrl) body += ` (${r.sourceUrl})`;
83
- if (r.snippet) body += `\n---\n${r.snippet}`;
84
- lines.push(` <testcase classname="${classname}" name="${name}"${layerAttr} time="0">`);
85
- lines.push(` <failure message="${msg}" type="${type}">${escapeXml(body)}</failure>`);
86
- lines.push(` </testcase>`);
87
- } else if (r.passed === null || r.skipped === true) {
88
- lines.push(` <testcase classname="${classname}" name="${name}"${layerAttr} time="0">`);
89
- lines.push(` <skipped/>`);
90
- lines.push(` </testcase>`);
91
- } else {
92
- lines.push(` <testcase classname="${classname}" name="${name}"${layerAttr} time="0"/>`);
93
- }
94
- }
95
-
96
- lines.push(' </testsuite>');
97
- }
98
-
99
- if (Array.isArray(auditResult.shallowRiskHints)) {
100
- lines.push(
101
- ` <testsuite name="shallow-risk" tests="${shallowRiskHints.length}" failures="${shallowRiskHints.length}" skipped="0" time="0" timestamp="${escapeXml(timestamp)}" package="nerviq.${escapeXml(platform)}.shallow-risk">`,
102
- );
103
- for (const hint of shallowRiskHints) {
104
- const name = escapeXml(hint.key || hint.name || 'shallow-risk');
105
- const msg = escapeXml(hint.fix || hint.name || hint.key || 'shallow risk hint');
106
- const type = escapeXml(severityFor(hint));
107
- let body = `${hint.name || hint.key || ''}`;
108
- if (hint.file) body += ` at ${hint.file}${hint.line ? ':' + hint.line : ''}`;
109
- if (hint.sourceUrl) body += ` (${hint.sourceUrl})`;
110
- if (hint.snippet) body += `\n---\n${hint.snippet}`;
111
- lines.push(` <testcase classname="shallow-risk" name="${name}" layer="shallow-risk" time="0">`);
112
- lines.push(` <failure message="${msg}" type="${type}">${escapeXml(body)}</failure>`);
113
- lines.push(' </testcase>');
114
- }
115
- lines.push(' </testsuite>');
116
- }
117
-
118
- lines.push('</testsuites>');
119
- lines.push(`<!-- nerviq v${escapeXml(auditResult.version || nerviqVersion)} -->`);
120
- return lines.join('\n');
121
- }
122
-
123
- module.exports = { formatJUnit };
1
+ /**
2
+ * JUnit XML Formatter
3
+ *
4
+ * Converts a nerviq audit result into Jenkins-compatible JUnit XML.
5
+ * Schema: <testsuites><testsuite><testcase><failure/></testcase></testsuite></testsuites>
6
+ *
7
+ * - One <testsuite> per check category.
8
+ * - Each check becomes a <testcase> (classname = category, name = key).
9
+ * - Failed checks emit a <failure message="..." type="..."/> where:
10
+ * - message = check.fix || check.name
11
+ * - type = severity (check.severity || check.impact)
12
+ * - Skipped checks emit <skipped/>.
13
+ *
14
+ * Parses with any standard JUnit XML consumer (GitHub Actions test
15
+ * reporter, Jenkins, GitLab CI, CircleCI).
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const { version: nerviqVersion } = require('../../package.json');
21
+
22
+ function escapeXml(value) {
23
+ if (value === null || value === undefined) return '';
24
+ return String(value)
25
+ .replace(/&/g, '&amp;')
26
+ .replace(/</g, '&lt;')
27
+ .replace(/>/g, '&gt;')
28
+ .replace(/"/g, '&quot;')
29
+ .replace(/'/g, '&apos;');
30
+ }
31
+
32
+ function severityFor(r) {
33
+ return r.severity || r.impact || 'medium';
34
+ }
35
+
36
+ function groupByCategory(results) {
37
+ const map = new Map();
38
+ for (const r of results) {
39
+ const cat = r.category || 'uncategorized';
40
+ if (!map.has(cat)) map.set(cat, []);
41
+ map.get(cat).push(r);
42
+ }
43
+ return map;
44
+ }
45
+
46
+ function formatJUnit(auditResult) {
47
+ const allResults = Array.isArray(auditResult.results) ? auditResult.results : [];
48
+ const shallowRiskHints = Array.isArray(auditResult.shallowRiskHints) ? auditResult.shallowRiskHints : [];
49
+ const timestamp = auditResult.timestamp || new Date().toISOString();
50
+ const platform = auditResult.platform || 'claude';
51
+
52
+ const totalTests = allResults.length + shallowRiskHints.length;
53
+ const totalFailures = allResults.filter((r) => r.passed === false).length + shallowRiskHints.length;
54
+ const totalSkipped = allResults.filter((r) => r.passed === null || r.skipped === true).length;
55
+
56
+ const byCategory = groupByCategory(allResults);
57
+
58
+ const lines = [];
59
+ lines.push('<?xml version="1.0" encoding="UTF-8"?>');
60
+ lines.push(
61
+ `<testsuites name="nerviq" tests="${totalTests}" failures="${totalFailures}" skipped="${totalSkipped}" time="0">`,
62
+ );
63
+
64
+ for (const [category, checks] of byCategory) {
65
+ const suiteFailures = checks.filter((r) => r.passed === false).length;
66
+ const suiteSkipped = checks.filter((r) => r.passed === null || r.skipped === true).length;
67
+ lines.push(
68
+ ` <testsuite name="${escapeXml(category)}" tests="${checks.length}" failures="${suiteFailures}" skipped="${suiteSkipped}" time="0" timestamp="${escapeXml(timestamp)}" package="nerviq.${escapeXml(platform)}">`,
69
+ );
70
+
71
+ for (const r of checks) {
72
+ const classname = escapeXml(r.category || 'uncategorized');
73
+ const name = escapeXml(r.key || r.id || r.name || 'unknown');
74
+ // CTO-08: surface scope layer as a testcase attribute so JUnit
75
+ // consumers (GitHub Actions, Jenkins, GitLab) can filter/group.
76
+ const layerAttr = r.layer ? ` layer="${escapeXml(r.layer)}"` : '';
77
+ if (r.passed === false) {
78
+ const msg = escapeXml(r.fix || r.name || r.key || 'check failed');
79
+ const type = escapeXml(severityFor(r));
80
+ let body = `${r.name || ''}`;
81
+ if (r.file) body += ` at ${r.file}${r.line ? ':' + r.line : ''}`;
82
+ if (r.sourceUrl) body += ` (${r.sourceUrl})`;
83
+ if (r.snippet) body += `\n---\n${r.snippet}`;
84
+ lines.push(` <testcase classname="${classname}" name="${name}"${layerAttr} time="0">`);
85
+ lines.push(` <failure message="${msg}" type="${type}">${escapeXml(body)}</failure>`);
86
+ lines.push(` </testcase>`);
87
+ } else if (r.passed === null || r.skipped === true) {
88
+ lines.push(` <testcase classname="${classname}" name="${name}"${layerAttr} time="0">`);
89
+ lines.push(` <skipped/>`);
90
+ lines.push(` </testcase>`);
91
+ } else {
92
+ lines.push(` <testcase classname="${classname}" name="${name}"${layerAttr} time="0"/>`);
93
+ }
94
+ }
95
+
96
+ lines.push(' </testsuite>');
97
+ }
98
+
99
+ if (Array.isArray(auditResult.shallowRiskHints)) {
100
+ lines.push(
101
+ ` <testsuite name="shallow-risk" tests="${shallowRiskHints.length}" failures="${shallowRiskHints.length}" skipped="0" time="0" timestamp="${escapeXml(timestamp)}" package="nerviq.${escapeXml(platform)}.shallow-risk">`,
102
+ );
103
+ for (const hint of shallowRiskHints) {
104
+ const name = escapeXml(hint.key || hint.name || 'shallow-risk');
105
+ const msg = escapeXml(hint.fix || hint.name || hint.key || 'shallow risk hint');
106
+ const type = escapeXml(severityFor(hint));
107
+ let body = `${hint.name || hint.key || ''}`;
108
+ if (hint.file) body += ` at ${hint.file}${hint.line ? ':' + hint.line : ''}`;
109
+ if (hint.sourceUrl) body += ` (${hint.sourceUrl})`;
110
+ if (hint.snippet) body += `\n---\n${hint.snippet}`;
111
+ lines.push(` <testcase classname="shallow-risk" name="${name}" layer="shallow-risk" time="0">`);
112
+ lines.push(` <failure message="${msg}" type="${type}">${escapeXml(body)}</failure>`);
113
+ lines.push(' </testcase>');
114
+ }
115
+ lines.push(' </testsuite>');
116
+ }
117
+
118
+ lines.push('</testsuites>');
119
+ lines.push(`<!-- nerviq v${escapeXml(auditResult.version || nerviqVersion)} -->`);
120
+ return lines.join('\n');
121
+ }
122
+
123
+ module.exports = { formatJUnit };