@nerviq/cli 1.26.0 → 1.27.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.
Files changed (59) hide show
  1. package/CHANGELOG.md +1407 -0
  2. package/README.md +4 -4
  3. package/SECURITY.md +82 -0
  4. package/bin/cli.js +13 -1
  5. package/contracts/audit-webhook-event.schema.json +138 -0
  6. package/contracts/pack-contract.schema.json +15 -0
  7. package/contracts/technique-contract.schema.json +18 -0
  8. package/docs/ARCHITECTURE.md +74 -0
  9. package/docs/api-reference.md +356 -0
  10. package/docs/autofix.md +64 -0
  11. package/docs/bitbucket-pipe.yml +57 -0
  12. package/docs/case-studies.md +149 -0
  13. package/docs/category-definition-kit.md +56 -0
  14. package/docs/ci-integration.md +127 -0
  15. package/docs/claude-code-style.md +24 -0
  16. package/docs/claude-maintainer-ops.md +19 -0
  17. package/docs/external-validation.md +78 -0
  18. package/docs/first-tier-integration-gate.md +59 -0
  19. package/docs/getting-started.md +119 -0
  20. package/docs/gitlab-ci-template.yml +54 -0
  21. package/docs/index.html +597 -0
  22. package/docs/integration-contracts.md +287 -0
  23. package/docs/license-faq.md +53 -0
  24. package/docs/maintenance.md +155 -0
  25. package/docs/methodology.md +236 -0
  26. package/docs/new-platform-guide.md +202 -0
  27. package/docs/open-vsx-publishing.md +46 -0
  28. package/docs/platform-change-ingestion.md +46 -0
  29. package/docs/plugins.md +101 -0
  30. package/docs/pre-commit.md +58 -0
  31. package/docs/security-model.md +63 -0
  32. package/docs/shallow-risk.md +246 -0
  33. package/docs/versioning-policy.md +63 -0
  34. package/docs/why-nerviq.md +82 -0
  35. package/package.json +7 -2
  36. package/sdk/README.md +190 -0
  37. package/src/audit/layers.js +180 -179
  38. package/src/audit.js +118 -48
  39. package/src/codex/setup.js +3 -2
  40. package/src/formatters/csv.js +86 -85
  41. package/src/formatters/junit.js +123 -103
  42. package/src/formatters/markdown.js +164 -135
  43. package/src/gemini/setup.js +3 -2
  44. package/src/init.js +4 -3
  45. package/src/opencode/context.js +42 -3
  46. package/src/opencode/techniques.js +198 -142
  47. package/src/output-icons.js +44 -0
  48. package/src/setup/runtime.js +6 -5
  49. package/src/setup.js +4 -3
  50. package/src/shallow-risk/index.js +56 -0
  51. package/src/shallow-risk/patterns/agent-config-cross-platform-drift.js +50 -0
  52. package/src/shallow-risk/patterns/agent-config-dangerous-autoapprove.js +46 -0
  53. package/src/shallow-risk/patterns/agent-config-deprecated-keys.js +46 -0
  54. package/src/shallow-risk/patterns/agent-config-missing-file.js +72 -0
  55. package/src/shallow-risk/patterns/agent-config-secret-literal.js +49 -0
  56. package/src/shallow-risk/patterns/agent-config-stack-contradiction.js +34 -0
  57. package/src/shallow-risk/patterns/hook-script-missing.js +70 -0
  58. package/src/shallow-risk/patterns/mcp-server-no-allowlist.js +52 -0
  59. package/src/shallow-risk/shared.js +520 -0
@@ -6,6 +6,7 @@ const { STACKS } = require('../techniques');
6
6
  const { writeActivityArtifact, writeRollbackArtifact } = require('../activity');
7
7
  const { CodexProjectContext } = require('./context');
8
8
  const { recommendCodexMcpPacks, packsToToml } = require('./mcp-packs');
9
+ const { icon } = require('../output-icons');
9
10
 
10
11
  function detectScripts(ctx) {
11
12
  const pkg = ctx.jsonFile('package.json');
@@ -521,14 +522,14 @@ async function setupCodex(options) {
521
522
  const fullPath = path.join(options.dir, file.path);
522
523
  if (fs.existsSync(fullPath)) {
523
524
  preservedFiles.push(file.path);
524
- log(` \x1b[2m⏭️ Skipped ${file.path} (already exists your version is kept)\x1b[0m`);
525
+ log(` \x1b[2m${icon('skip')} Skipped ${file.path} (already exists - your version is kept)\x1b[0m`);
525
526
  continue;
526
527
  }
527
528
 
528
529
  fs.mkdirSync(path.dirname(fullPath), { recursive: true });
529
530
  fs.writeFileSync(fullPath, file.content, 'utf8');
530
531
  writtenFiles.push(file.path);
531
- log(` \x1b[32m✅\x1b[0m Created ${file.path}`);
532
+ log(` \x1b[32m${icon('ok')}\x1b[0m Created ${file.path}`);
532
533
  }
533
534
 
534
535
  const skippedSet = new Set(preservedFiles);
@@ -1,85 +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 = 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 projections = new Map();
73
- if (Array.isArray(auditResult.topNextActions)) {
74
- for (const item of auditResult.topNextActions) {
75
- if (item && item.key) projections.set(item.key, item);
76
- }
77
- }
78
- const lines = [COLUMNS.join(',')];
79
- for (const r of results) {
80
- lines.push(rowFor(r, projections));
81
- }
82
- return lines.join('\n');
83
- }
84
-
85
- 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,103 +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 timestamp = auditResult.timestamp || new Date().toISOString();
49
- const platform = auditResult.platform || 'claude';
50
-
51
- const totalTests = allResults.length;
52
- const totalFailures = allResults.filter((r) => r.passed === false).length;
53
- const totalSkipped = allResults.filter((r) => r.passed === null || r.skipped === true).length;
54
-
55
- const byCategory = groupByCategory(allResults);
56
-
57
- const lines = [];
58
- lines.push('<?xml version="1.0" encoding="UTF-8"?>');
59
- lines.push(
60
- `<testsuites name="nerviq" tests="${totalTests}" failures="${totalFailures}" skipped="${totalSkipped}" time="0">`,
61
- );
62
-
63
- for (const [category, checks] of byCategory) {
64
- const suiteFailures = checks.filter((r) => r.passed === false).length;
65
- const suiteSkipped = checks.filter((r) => r.passed === null || r.skipped === true).length;
66
- lines.push(
67
- ` <testsuite name="${escapeXml(category)}" tests="${checks.length}" failures="${suiteFailures}" skipped="${suiteSkipped}" time="0" timestamp="${escapeXml(timestamp)}" package="nerviq.${escapeXml(platform)}">`,
68
- );
69
-
70
- for (const r of checks) {
71
- const classname = escapeXml(r.category || 'uncategorized');
72
- const name = escapeXml(r.key || r.id || r.name || 'unknown');
73
- // CTO-08: surface scope layer as a testcase attribute so JUnit
74
- // consumers (GitHub Actions, Jenkins, GitLab) can filter/group.
75
- const layerAttr = r.layer ? ` layer="${escapeXml(r.layer)}"` : '';
76
- if (r.passed === false) {
77
- const msg = escapeXml(r.fix || r.name || r.key || 'check failed');
78
- const type = escapeXml(severityFor(r));
79
- let body = `${r.name || ''}`;
80
- if (r.file) body += ` at ${r.file}${r.line ? ':' + r.line : ''}`;
81
- if (r.sourceUrl) body += ` (${r.sourceUrl})`;
82
- if (r.snippet) body += `\n---\n${r.snippet}`;
83
- lines.push(` <testcase classname="${classname}" name="${name}"${layerAttr} time="0">`);
84
- lines.push(` <failure message="${msg}" type="${type}">${escapeXml(body)}</failure>`);
85
- lines.push(` </testcase>`);
86
- } else if (r.passed === null || r.skipped === true) {
87
- lines.push(` <testcase classname="${classname}" name="${name}"${layerAttr} time="0">`);
88
- lines.push(` <skipped/>`);
89
- lines.push(` </testcase>`);
90
- } else {
91
- lines.push(` <testcase classname="${classname}" name="${name}"${layerAttr} time="0"/>`);
92
- }
93
- }
94
-
95
- lines.push(' </testsuite>');
96
- }
97
-
98
- lines.push('</testsuites>');
99
- lines.push(`<!-- nerviq v${escapeXml(auditResult.version || nerviqVersion)} -->`);
100
- return lines.join('\n');
101
- }
102
-
103
- 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 };