@nerviq/cli 1.8.5 → 1.8.7

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.
@@ -1,306 +1,306 @@
1
- /**
2
- * Harmony Audit — Cross-Platform DX Audit
3
- *
4
- * Runs AFTER per-platform audits and evaluates how well the project's
5
- * AI coding platforms are aligned with each other.
6
- *
7
- * Produces a harmony score (0-100), per-platform scores, drift analysis,
8
- * and cross-platform recommendations.
9
- */
10
-
11
- const { buildCanonicalModel, detectActivePlatforms } = require('./canon');
12
- const { detectDrift, formatDriftReport } = require('./drift');
13
- const { audit: platformAudit } = require('../audit');
14
-
15
- const COLORS = {
16
- reset: '\x1b[0m',
17
- bold: '\x1b[1m',
18
- dim: '\x1b[2m',
19
- red: '\x1b[31m',
20
- green: '\x1b[32m',
21
- yellow: '\x1b[33m',
22
- blue: '\x1b[36m',
23
- magenta: '\x1b[35m',
24
- };
25
-
26
- function colorize(text, color) {
27
- return `${COLORS[color] || ''}${text}${COLORS.reset}`;
28
- }
29
-
30
- function progressBar(score, max = 100, width = 20) {
31
- const filled = Math.round((score / max) * width);
32
- const empty = width - filled;
33
- const color = score >= 70 ? 'green' : score >= 40 ? 'yellow' : 'red';
34
- return colorize('\u2588'.repeat(filled), color) + colorize('\u2591'.repeat(empty), 'dim');
35
- }
36
-
37
- // ─── Platform key to audit platform name mapping ────────────────────────────
38
-
39
- const PLATFORM_AUDIT_MAP = {
40
- claude: 'claude',
41
- codex: 'codex',
42
- gemini: 'gemini',
43
- copilot: 'copilot',
44
- cursor: 'cursor',
45
- windsurf: 'windsurf',
46
- aider: 'aider',
47
- opencode: 'opencode',
48
- };
49
-
50
- // ─── Cross-platform recommendations ────────────────────────────────────────
51
-
52
- function generateRecommendations(model, drift, platformScores) {
53
- const recommendations = [];
54
- const platforms = model.activePlatforms.map(p => p.platform);
55
-
56
- // 1. If only one platform detected, recommend adding another
57
- if (platforms.length === 1) {
58
- recommendations.push({
59
- priority: 'medium',
60
- category: 'expansion',
61
- message: `Only ${platforms[0]} is configured. Consider adding a second platform for redundancy and team flexibility.`,
62
- });
63
- }
64
-
65
- // 2. If any platform scores below 40, flag it
66
- for (const [platform, score] of Object.entries(platformScores)) {
67
- if (score !== null && score < 40) {
68
- recommendations.push({
69
- priority: 'high',
70
- category: 'quality',
71
- message: `${platform} scores ${score}/100. Run \`nerviq audit --platform ${platform}\` and address critical gaps.`,
72
- });
73
- }
74
- }
75
-
76
- // 3. If trust drift is critical, recommend alignment
77
- const trustDrifts = drift.drifts.filter(d => d.type === 'trust-drift' && d.severity === 'critical');
78
- if (trustDrifts.length > 0) {
79
- recommendations.push({
80
- priority: 'critical',
81
- category: 'security',
82
- message: 'Critical trust posture mismatch. One platform has full autonomy while another is restricted. Align before production use.',
83
- });
84
- }
85
-
86
- // 4. Recommend shared MCP servers
87
- const mcpDrifts = drift.drifts.filter(d => d.type === 'mcp-drift');
88
- if (mcpDrifts.length > 2) {
89
- recommendations.push({
90
- priority: 'medium',
91
- category: 'tooling',
92
- message: `${mcpDrifts.length} MCP alignment issues. Use \`nerviq harmony sync\` to propagate MCP servers across platforms.`,
93
- });
94
- }
95
-
96
- // 5. Coverage gap recommendations
97
- const coverageGaps = drift.drifts.filter(d => d.type === 'coverage-gap' && d.severity === 'high');
98
- for (const gap of coverageGaps) {
99
- recommendations.push({
100
- priority: 'high',
101
- category: 'coverage',
102
- message: gap.description + '. ' + gap.recommendation,
103
- });
104
- }
105
-
106
- // 6. If harmony score is high and all platforms score well, celebrate
107
- if (drift.harmonyScore >= 90 && Object.values(platformScores).every(s => s === null || s >= 70)) {
108
- recommendations.push({
109
- priority: 'low',
110
- category: 'status',
111
- message: 'Excellent cross-platform alignment. All platforms are well-configured and consistent.',
112
- });
113
- }
114
-
115
- // Sort: critical > high > medium > low
116
- const priorityOrder = { critical: 3, high: 2, medium: 1, low: 0 };
117
- recommendations.sort((a, b) => (priorityOrder[b.priority] || 0) - (priorityOrder[a.priority] || 0));
118
-
119
- return recommendations;
120
- }
121
-
122
- // ─── Main audit function ────────────────────────────────────────────────────
123
-
124
- /**
125
- * Run a cross-platform harmony audit.
126
- *
127
- * Builds a canonical model, runs per-platform audits, detects drift,
128
- * and generates cross-platform recommendations.
129
- *
130
- * @param {object} options - { dir: string, silent?: boolean, verbose?: boolean }
131
- * @returns {object} Harmony audit result
132
- */
133
- async function harmonyAudit(options) {
134
- const { dir, silent = false, verbose = false } = options;
135
-
136
- // 1. Build canonical model
137
- const model = buildCanonicalModel(dir);
138
- const platformKeys = model.activePlatforms.map(p => p.platform);
139
-
140
- if (platformKeys.length === 0) {
141
- return {
142
- harmonyScore: 0,
143
- platformScores: {},
144
- drift: { drifts: [], summary: { total: 0, critical: 0, high: 0, medium: 0, low: 0 }, harmonyScore: 0 },
145
- recommendations: [{
146
- priority: 'high',
147
- category: 'coverage',
148
- message: 'No AI coding platforms detected. Run `nerviq init` to set up Claude, or add another platform.',
149
- }],
150
- activePlatforms: [],
151
- model,
152
- };
153
- }
154
-
155
- // 2. Run per-platform audits (silent mode to avoid console noise)
156
- const platformScores = {};
157
- const platformResults = {};
158
- for (const key of platformKeys) {
159
- const auditPlatform = PLATFORM_AUDIT_MAP[key];
160
- if (auditPlatform) {
161
- try {
162
- const result = await platformAudit({ dir, platform: auditPlatform, silent: true });
163
- platformScores[key] = result.score;
164
- platformResults[key] = result;
165
- } catch {
166
- platformScores[key] = null;
167
- platformResults[key] = null;
168
- }
169
- } else {
170
- platformScores[key] = null;
171
- }
172
- }
173
-
174
- // 3. Detect drift
175
- const drift = detectDrift(model);
176
-
177
- // 4. Calculate overall harmony score
178
- // Blend of drift harmony score and average platform scores
179
- const validScores = Object.values(platformScores).filter(s => s !== null);
180
- const avgPlatformScore = validScores.length > 0
181
- ? Math.round(validScores.reduce((a, b) => a + b, 0) / validScores.length)
182
- : 0;
183
-
184
- // Harmony = 60% drift alignment + 40% average platform quality
185
- const harmonyScore = Math.round(drift.harmonyScore * 0.6 + avgPlatformScore * 0.4);
186
-
187
- // 5. Generate recommendations
188
- const recommendations = generateRecommendations(model, drift, platformScores);
189
-
190
- const result = {
191
- harmonyScore,
192
- platformScores,
193
- platformResults,
194
- drift,
195
- recommendations,
196
- activePlatforms: model.activePlatforms,
197
- model,
198
- };
199
-
200
- // 6. Print report if not silent
201
- if (!silent) {
202
- printHarmonyReport(result, { verbose });
203
- }
204
-
205
- return result;
206
- }
207
-
208
- // ─── Report printer ─────────────────────────────────────────────────────────
209
-
210
- function printHarmonyReport(result, options = {}) {
211
- const { verbose = false } = options;
212
- const c = colorize;
213
-
214
- console.log('');
215
- console.log(c(' ══════════════════════════════════════════════════════', 'dim'));
216
- console.log(c(' HARMONY AUDIT — Cross-Platform DX Report', 'bold'));
217
- console.log(c(' ══════════════════════════════════════════════════════', 'dim'));
218
- console.log('');
219
-
220
- // Active platforms
221
- console.log(c(' Active platforms:', 'bold'));
222
- for (const ap of result.activePlatforms) {
223
- const score = result.platformScores[ap.platform];
224
- const scoreStr = score !== null ? `${score}/100` : 'n/a';
225
- const scoreColor = score >= 70 ? 'green' : score >= 40 ? 'yellow' : 'red';
226
- console.log(` ${ap.label}: ${c(scoreStr, score !== null ? scoreColor : 'dim')}`);
227
- }
228
- console.log('');
229
-
230
- // Harmony score
231
- const hs = result.harmonyScore;
232
- const hsColor = hs >= 80 ? 'green' : hs >= 50 ? 'yellow' : 'red';
233
- console.log(` Harmony Score: ${progressBar(hs)} ${c(hs + '/100', hsColor)}`);
234
- console.log('');
235
-
236
- // Drift summary
237
- if (result.drift.drifts.length > 0) {
238
- console.log(formatDriftReport(result.drift, { color: true, verbose }));
239
- } else {
240
- console.log(c(' No cross-platform drift detected.', 'green'));
241
- console.log('');
242
- }
243
-
244
- // Recommendations
245
- if (result.recommendations.length > 0) {
246
- console.log(c(' Recommendations:', 'bold'));
247
- const priorityIcons = { critical: '\u2718', high: '!', medium: '~', low: '\u2713' };
248
- const priorityColors = { critical: 'red', high: 'yellow', medium: 'blue', low: 'green' };
249
-
250
- for (const rec of result.recommendations) {
251
- const icon = priorityIcons[rec.priority] || '-';
252
- const pColor = priorityColors[rec.priority] || 'dim';
253
- console.log(` ${c(icon, pColor)} [${rec.category}] ${rec.message}`);
254
- }
255
- console.log('');
256
- }
257
-
258
- console.log(c(' Powered by CLAUDEX cross-platform intelligence', 'dim'));
259
- console.log(c(' https://github.com/nerviq/nerviq', 'dim'));
260
- console.log('');
261
- }
262
-
263
- /**
264
- * Format the harmony audit result as a structured report string (no ANSI colors).
265
- *
266
- * @param {object} result - Output of harmonyAudit()
267
- * @returns {string} Plain-text report
268
- */
269
- function formatHarmonyAuditReport(result) {
270
- const lines = [];
271
-
272
- lines.push('HARMONY AUDIT — Cross-Platform DX Report');
273
- lines.push('========================================');
274
- lines.push('');
275
-
276
- lines.push('Active platforms:');
277
- for (const ap of result.activePlatforms) {
278
- const score = result.platformScores[ap.platform];
279
- lines.push(` ${ap.label}: ${score !== null ? score + '/100' : 'n/a'}`);
280
- }
281
- lines.push('');
282
-
283
- lines.push(`Harmony Score: ${result.harmonyScore}/100`);
284
- lines.push('');
285
-
286
- if (result.drift.drifts.length > 0) {
287
- lines.push(formatDriftReport(result.drift, { color: false, verbose: true }));
288
- } else {
289
- lines.push('No cross-platform drift detected.');
290
- }
291
- lines.push('');
292
-
293
- if (result.recommendations.length > 0) {
294
- lines.push('Recommendations:');
295
- for (const rec of result.recommendations) {
296
- lines.push(` [${rec.priority.toUpperCase()}] [${rec.category}] ${rec.message}`);
297
- }
298
- }
299
-
300
- return lines.join('\n');
301
- }
302
-
303
- module.exports = {
304
- harmonyAudit,
305
- formatHarmonyAuditReport,
306
- };
1
+ /**
2
+ * Harmony Audit — Cross-Platform DX Audit
3
+ *
4
+ * Runs AFTER per-platform audits and evaluates how well the project's
5
+ * AI coding platforms are aligned with each other.
6
+ *
7
+ * Produces a harmony score (0-100), per-platform scores, drift analysis,
8
+ * and cross-platform recommendations.
9
+ */
10
+
11
+ const { buildCanonicalModel, detectActivePlatforms } = require('./canon');
12
+ const { detectDrift, formatDriftReport } = require('./drift');
13
+ const { audit: platformAudit } = require('../audit');
14
+
15
+ const COLORS = {
16
+ reset: '\x1b[0m',
17
+ bold: '\x1b[1m',
18
+ dim: '\x1b[2m',
19
+ red: '\x1b[31m',
20
+ green: '\x1b[32m',
21
+ yellow: '\x1b[33m',
22
+ blue: '\x1b[36m',
23
+ magenta: '\x1b[35m',
24
+ };
25
+
26
+ function colorize(text, color) {
27
+ return `${COLORS[color] || ''}${text}${COLORS.reset}`;
28
+ }
29
+
30
+ function progressBar(score, max = 100, width = 20) {
31
+ const filled = Math.round((score / max) * width);
32
+ const empty = width - filled;
33
+ const color = score >= 70 ? 'green' : score >= 40 ? 'yellow' : 'red';
34
+ return colorize('\u2588'.repeat(filled), color) + colorize('\u2591'.repeat(empty), 'dim');
35
+ }
36
+
37
+ // ─── Platform key to audit platform name mapping ────────────────────────────
38
+
39
+ const PLATFORM_AUDIT_MAP = {
40
+ claude: 'claude',
41
+ codex: 'codex',
42
+ gemini: 'gemini',
43
+ copilot: 'copilot',
44
+ cursor: 'cursor',
45
+ windsurf: 'windsurf',
46
+ aider: 'aider',
47
+ opencode: 'opencode',
48
+ };
49
+
50
+ // ─── Cross-platform recommendations ────────────────────────────────────────
51
+
52
+ function generateRecommendations(model, drift, platformScores) {
53
+ const recommendations = [];
54
+ const platforms = model.activePlatforms.map(p => p.platform);
55
+
56
+ // 1. If only one platform detected, recommend adding another
57
+ if (platforms.length === 1) {
58
+ recommendations.push({
59
+ priority: 'medium',
60
+ category: 'expansion',
61
+ message: `Only ${platforms[0]} is configured. Consider adding a second platform for redundancy and team flexibility.`,
62
+ });
63
+ }
64
+
65
+ // 2. If any platform scores below 40, flag it
66
+ for (const [platform, score] of Object.entries(platformScores)) {
67
+ if (score !== null && score < 40) {
68
+ recommendations.push({
69
+ priority: 'high',
70
+ category: 'quality',
71
+ message: `${platform} scores ${score}/100. Run \`nerviq audit --platform ${platform}\` and address critical gaps.`,
72
+ });
73
+ }
74
+ }
75
+
76
+ // 3. If trust drift is critical, recommend alignment
77
+ const trustDrifts = drift.drifts.filter(d => d.type === 'trust-drift' && d.severity === 'critical');
78
+ if (trustDrifts.length > 0) {
79
+ recommendations.push({
80
+ priority: 'critical',
81
+ category: 'security',
82
+ message: 'Critical trust posture mismatch. One platform has full autonomy while another is restricted. Align before production use.',
83
+ });
84
+ }
85
+
86
+ // 4. Recommend shared MCP servers
87
+ const mcpDrifts = drift.drifts.filter(d => d.type === 'mcp-drift');
88
+ if (mcpDrifts.length > 2) {
89
+ recommendations.push({
90
+ priority: 'medium',
91
+ category: 'tooling',
92
+ message: `${mcpDrifts.length} MCP alignment issues. Use \`nerviq harmony sync\` to propagate MCP servers across platforms.`,
93
+ });
94
+ }
95
+
96
+ // 5. Coverage gap recommendations
97
+ const coverageGaps = drift.drifts.filter(d => d.type === 'coverage-gap' && d.severity === 'high');
98
+ for (const gap of coverageGaps) {
99
+ recommendations.push({
100
+ priority: 'high',
101
+ category: 'coverage',
102
+ message: gap.description + '. ' + gap.recommendation,
103
+ });
104
+ }
105
+
106
+ // 6. If harmony score is high and all platforms score well, celebrate
107
+ if (drift.harmonyScore >= 90 && Object.values(platformScores).every(s => s === null || s >= 70)) {
108
+ recommendations.push({
109
+ priority: 'low',
110
+ category: 'status',
111
+ message: 'Excellent cross-platform alignment. All platforms are well-configured and consistent.',
112
+ });
113
+ }
114
+
115
+ // Sort: critical > high > medium > low
116
+ const priorityOrder = { critical: 3, high: 2, medium: 1, low: 0 };
117
+ recommendations.sort((a, b) => (priorityOrder[b.priority] || 0) - (priorityOrder[a.priority] || 0));
118
+
119
+ return recommendations;
120
+ }
121
+
122
+ // ─── Main audit function ────────────────────────────────────────────────────
123
+
124
+ /**
125
+ * Run a cross-platform harmony audit.
126
+ *
127
+ * Builds a canonical model, runs per-platform audits, detects drift,
128
+ * and generates cross-platform recommendations.
129
+ *
130
+ * @param {object} options - { dir: string, silent?: boolean, verbose?: boolean }
131
+ * @returns {object} Harmony audit result
132
+ */
133
+ async function harmonyAudit(options) {
134
+ const { dir, silent = false, verbose = false } = options;
135
+
136
+ // 1. Build canonical model
137
+ const model = buildCanonicalModel(dir);
138
+ const platformKeys = model.activePlatforms.map(p => p.platform);
139
+
140
+ if (platformKeys.length === 0) {
141
+ return {
142
+ harmonyScore: 0,
143
+ platformScores: {},
144
+ drift: { drifts: [], summary: { total: 0, critical: 0, high: 0, medium: 0, low: 0 }, harmonyScore: 0 },
145
+ recommendations: [{
146
+ priority: 'high',
147
+ category: 'coverage',
148
+ message: 'No AI coding platforms detected. Run `nerviq init` to set up Claude, or add another platform.',
149
+ }],
150
+ activePlatforms: [],
151
+ model,
152
+ };
153
+ }
154
+
155
+ // 2. Run per-platform audits (silent mode to avoid console noise)
156
+ const platformScores = {};
157
+ const platformResults = {};
158
+ for (const key of platformKeys) {
159
+ const auditPlatform = PLATFORM_AUDIT_MAP[key];
160
+ if (auditPlatform) {
161
+ try {
162
+ const result = await platformAudit({ dir, platform: auditPlatform, silent: true });
163
+ platformScores[key] = result.score;
164
+ platformResults[key] = result;
165
+ } catch {
166
+ platformScores[key] = null;
167
+ platformResults[key] = null;
168
+ }
169
+ } else {
170
+ platformScores[key] = null;
171
+ }
172
+ }
173
+
174
+ // 3. Detect drift
175
+ const drift = detectDrift(model);
176
+
177
+ // 4. Calculate overall harmony score
178
+ // Blend of drift harmony score and average platform scores
179
+ const validScores = Object.values(platformScores).filter(s => s !== null);
180
+ const avgPlatformScore = validScores.length > 0
181
+ ? Math.round(validScores.reduce((a, b) => a + b, 0) / validScores.length)
182
+ : 0;
183
+
184
+ // Harmony = 60% drift alignment + 40% average platform quality
185
+ const harmonyScore = Math.round(drift.harmonyScore * 0.6 + avgPlatformScore * 0.4);
186
+
187
+ // 5. Generate recommendations
188
+ const recommendations = generateRecommendations(model, drift, platformScores);
189
+
190
+ const result = {
191
+ harmonyScore,
192
+ platformScores,
193
+ platformResults,
194
+ drift,
195
+ recommendations,
196
+ activePlatforms: model.activePlatforms,
197
+ model,
198
+ };
199
+
200
+ // 6. Print report if not silent
201
+ if (!silent) {
202
+ printHarmonyReport(result, { verbose });
203
+ }
204
+
205
+ return result;
206
+ }
207
+
208
+ // ─── Report printer ─────────────────────────────────────────────────────────
209
+
210
+ function printHarmonyReport(result, options = {}) {
211
+ const { verbose = false } = options;
212
+ const c = colorize;
213
+
214
+ console.log('');
215
+ console.log(c(' ══════════════════════════════════════════════════════', 'dim'));
216
+ console.log(c(' HARMONY AUDIT — Cross-Platform DX Report', 'bold'));
217
+ console.log(c(' ══════════════════════════════════════════════════════', 'dim'));
218
+ console.log('');
219
+
220
+ // Active platforms
221
+ console.log(c(' Active platforms:', 'bold'));
222
+ for (const ap of result.activePlatforms) {
223
+ const score = result.platformScores[ap.platform];
224
+ const scoreStr = score !== null ? `${score}/100` : 'n/a';
225
+ const scoreColor = score >= 70 ? 'green' : score >= 40 ? 'yellow' : 'red';
226
+ console.log(` ${ap.label}: ${c(scoreStr, score !== null ? scoreColor : 'dim')}`);
227
+ }
228
+ console.log('');
229
+
230
+ // Harmony score
231
+ const hs = result.harmonyScore;
232
+ const hsColor = hs >= 80 ? 'green' : hs >= 50 ? 'yellow' : 'red';
233
+ console.log(` Harmony Score: ${progressBar(hs)} ${c(hs + '/100', hsColor)}`);
234
+ console.log('');
235
+
236
+ // Drift summary
237
+ if (result.drift.drifts.length > 0) {
238
+ console.log(formatDriftReport(result.drift, { color: true, verbose }));
239
+ } else {
240
+ console.log(c(' No cross-platform drift detected.', 'green'));
241
+ console.log('');
242
+ }
243
+
244
+ // Recommendations
245
+ if (result.recommendations.length > 0) {
246
+ console.log(c(' Recommendations:', 'bold'));
247
+ const priorityIcons = { critical: '\u2718', high: '!', medium: '~', low: '\u2713' };
248
+ const priorityColors = { critical: 'red', high: 'yellow', medium: 'blue', low: 'green' };
249
+
250
+ for (const rec of result.recommendations) {
251
+ const icon = priorityIcons[rec.priority] || '-';
252
+ const pColor = priorityColors[rec.priority] || 'dim';
253
+ console.log(` ${c(icon, pColor)} [${rec.category}] ${rec.message}`);
254
+ }
255
+ console.log('');
256
+ }
257
+
258
+ console.log(c(' Powered by NERVIQ cross-platform intelligence', 'dim'));
259
+ console.log(c(' https://github.com/nerviq/nerviq', 'dim'));
260
+ console.log('');
261
+ }
262
+
263
+ /**
264
+ * Format the harmony audit result as a structured report string (no ANSI colors).
265
+ *
266
+ * @param {object} result - Output of harmonyAudit()
267
+ * @returns {string} Plain-text report
268
+ */
269
+ function formatHarmonyAuditReport(result) {
270
+ const lines = [];
271
+
272
+ lines.push('HARMONY AUDIT — Cross-Platform DX Report');
273
+ lines.push('========================================');
274
+ lines.push('');
275
+
276
+ lines.push('Active platforms:');
277
+ for (const ap of result.activePlatforms) {
278
+ const score = result.platformScores[ap.platform];
279
+ lines.push(` ${ap.label}: ${score !== null ? score + '/100' : 'n/a'}`);
280
+ }
281
+ lines.push('');
282
+
283
+ lines.push(`Harmony Score: ${result.harmonyScore}/100`);
284
+ lines.push('');
285
+
286
+ if (result.drift.drifts.length > 0) {
287
+ lines.push(formatDriftReport(result.drift, { color: false, verbose: true }));
288
+ } else {
289
+ lines.push('No cross-platform drift detected.');
290
+ }
291
+ lines.push('');
292
+
293
+ if (result.recommendations.length > 0) {
294
+ lines.push('Recommendations:');
295
+ for (const rec of result.recommendations) {
296
+ lines.push(` [${rec.priority.toUpperCase()}] [${rec.category}] ${rec.message}`);
297
+ }
298
+ }
299
+
300
+ return lines.join('\n');
301
+ }
302
+
303
+ module.exports = {
304
+ harmonyAudit,
305
+ formatHarmonyAuditReport,
306
+ };