@nerviq/cli 0.0.1 → 0.9.0-beta.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 +181 -0
- package/LICENSE +21 -0
- package/README.md +447 -0
- package/bin/cli.js +749 -0
- package/content/case-study-template.md +91 -0
- package/content/claims-governance.md +37 -0
- package/content/claude-code/audit-repo/SKILL.md +20 -0
- package/content/claude-native-integration.md +60 -0
- package/content/devto-article.json +9 -0
- package/content/launch-posts.md +226 -0
- package/content/pilot-rollout-kit.md +30 -0
- package/content/release-checklist.md +31 -0
- package/package.json +53 -4
- package/src/activity.js +529 -0
- package/src/aider/activity.js +226 -0
- package/src/aider/config-parser.js +166 -0
- package/src/aider/context.js +158 -0
- package/src/aider/deep-review.js +316 -0
- package/src/aider/domain-packs.js +278 -0
- package/src/aider/freshness.js +168 -0
- package/src/aider/governance.js +253 -0
- package/src/aider/interactive.js +334 -0
- package/src/aider/mcp-packs.js +98 -0
- package/src/aider/patch.js +214 -0
- package/src/aider/plans.js +186 -0
- package/src/aider/premium.js +360 -0
- package/src/aider/setup.js +404 -0
- package/src/aider/techniques.js +1323 -0
- package/src/analyze.js +821 -0
- package/src/audit.js +1003 -0
- package/src/badge.js +13 -0
- package/src/benchmark.js +339 -0
- package/src/claudex-sync.json +7 -0
- package/src/codex/activity.js +324 -0
- package/src/codex/config-parser.js +183 -0
- package/src/codex/context.js +221 -0
- package/src/codex/deep-review.js +493 -0
- package/src/codex/domain-packs.js +372 -0
- package/src/codex/freshness.js +167 -0
- package/src/codex/governance.js +192 -0
- package/src/codex/interactive.js +618 -0
- package/src/codex/mcp-packs.js +660 -0
- package/src/codex/patch.js +209 -0
- package/src/codex/plans.js +251 -0
- package/src/codex/premium.js +614 -0
- package/src/codex/setup.js +603 -0
- package/src/codex/techniques.js +2649 -0
- package/src/context.js +272 -0
- package/src/copilot/activity.js +309 -0
- package/src/copilot/config-parser.js +226 -0
- package/src/copilot/context.js +197 -0
- package/src/copilot/deep-review.js +346 -0
- package/src/copilot/domain-packs.js +350 -0
- package/src/copilot/freshness.js +197 -0
- package/src/copilot/governance.js +222 -0
- package/src/copilot/interactive.js +406 -0
- package/src/copilot/mcp-packs.js +572 -0
- package/src/copilot/patch.js +238 -0
- package/src/copilot/plans.js +253 -0
- package/src/copilot/premium.js +450 -0
- package/src/copilot/setup.js +488 -0
- package/src/copilot/techniques.js +1822 -0
- package/src/cursor/activity.js +301 -0
- package/src/cursor/config-parser.js +265 -0
- package/src/cursor/context.js +236 -0
- package/src/cursor/deep-review.js +334 -0
- package/src/cursor/domain-packs.js +346 -0
- package/src/cursor/freshness.js +214 -0
- package/src/cursor/governance.js +229 -0
- package/src/cursor/interactive.js +391 -0
- package/src/cursor/mcp-packs.js +571 -0
- package/src/cursor/patch.js +243 -0
- package/src/cursor/plans.js +254 -0
- package/src/cursor/premium.js +468 -0
- package/src/cursor/setup.js +488 -0
- package/src/cursor/techniques.js +1786 -0
- package/src/deep-review.js +345 -0
- package/src/domain-packs.js +364 -0
- package/src/formatters/sarif.js +115 -0
- package/src/gemini/activity.js +402 -0
- package/src/gemini/config-parser.js +275 -0
- package/src/gemini/context.js +221 -0
- package/src/gemini/deep-review.js +559 -0
- package/src/gemini/domain-packs.js +371 -0
- package/src/gemini/freshness.js +204 -0
- package/src/gemini/governance.js +201 -0
- package/src/gemini/interactive.js +860 -0
- package/src/gemini/mcp-packs.js +658 -0
- package/src/gemini/patch.js +229 -0
- package/src/gemini/plans.js +269 -0
- package/src/gemini/premium.js +759 -0
- package/src/gemini/setup.js +692 -0
- package/src/gemini/techniques.js +2084 -0
- package/src/governance.js +523 -0
- package/src/harmony/advisor.js +383 -0
- package/src/harmony/audit.js +303 -0
- package/src/harmony/canon.js +444 -0
- package/src/harmony/cli.js +331 -0
- package/src/harmony/drift.js +401 -0
- package/src/harmony/governance.js +313 -0
- package/src/harmony/memory.js +238 -0
- package/src/harmony/sync.js +458 -0
- package/src/harmony/watch.js +336 -0
- package/src/index.js +256 -0
- package/src/insights.js +119 -0
- package/src/interactive.js +118 -0
- package/src/mcp-packs.js +597 -0
- package/src/opencode/activity.js +286 -0
- package/src/opencode/config-parser.js +109 -0
- package/src/opencode/context.js +247 -0
- package/src/opencode/deep-review.js +313 -0
- package/src/opencode/domain-packs.js +240 -0
- package/src/opencode/freshness.js +158 -0
- package/src/opencode/governance.js +159 -0
- package/src/opencode/interactive.js +392 -0
- package/src/opencode/mcp-packs.js +474 -0
- package/src/opencode/patch.js +184 -0
- package/src/opencode/plans.js +231 -0
- package/src/opencode/premium.js +413 -0
- package/src/opencode/setup.js +449 -0
- package/src/opencode/techniques.js +1713 -0
- package/src/plans.js +655 -0
- package/src/secret-patterns.js +30 -0
- package/src/setup.js +1274 -0
- package/src/synergy/adaptive.js +261 -0
- package/src/synergy/compensation.js +156 -0
- package/src/synergy/evidence.js +193 -0
- package/src/synergy/learning.js +184 -0
- package/src/synergy/patterns.js +227 -0
- package/src/synergy/ranking.js +83 -0
- package/src/synergy/report.js +163 -0
- package/src/synergy/routing.js +152 -0
- package/src/techniques.js +1354 -0
- package/src/watch.js +229 -0
- package/src/windsurf/activity.js +302 -0
- package/src/windsurf/config-parser.js +267 -0
- package/src/windsurf/context.js +249 -0
- package/src/windsurf/deep-review.js +337 -0
- package/src/windsurf/domain-packs.js +348 -0
- package/src/windsurf/freshness.js +215 -0
- package/src/windsurf/governance.js +231 -0
- package/src/windsurf/interactive.js +388 -0
- package/src/windsurf/mcp-packs.js +535 -0
- package/src/windsurf/patch.js +231 -0
- package/src/windsurf/plans.js +247 -0
- package/src/windsurf/premium.js +467 -0
- package/src/windsurf/setup.js +471 -0
- package/src/windsurf/techniques.js +1758 -0
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* H5. Strategic Project Advisor
|
|
3
|
+
*
|
|
4
|
+
* The strategic brain that understands a project holistically and recommends
|
|
5
|
+
* which platform to use for which task type, configuration improvements,
|
|
6
|
+
* and cross-platform update actions.
|
|
7
|
+
*
|
|
8
|
+
* Zero external dependencies - imports only from sibling/parent modules.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// ─── Platform Strength Matrix (from CLAUDEX research) ─────────────────────────
|
|
12
|
+
|
|
13
|
+
const PLATFORM_STRENGTHS = {
|
|
14
|
+
claude: {
|
|
15
|
+
label: 'Claude Code',
|
|
16
|
+
reasoning: 5,
|
|
17
|
+
refactoring: 5,
|
|
18
|
+
ci: 2,
|
|
19
|
+
ide: 2,
|
|
20
|
+
sandbox: 3,
|
|
21
|
+
inline: 3,
|
|
22
|
+
context: 4,
|
|
23
|
+
automation: 4,
|
|
24
|
+
},
|
|
25
|
+
codex: {
|
|
26
|
+
label: 'Codex',
|
|
27
|
+
reasoning: 4,
|
|
28
|
+
ci: 5,
|
|
29
|
+
cloud: 5,
|
|
30
|
+
ide: 3,
|
|
31
|
+
sandbox: 4,
|
|
32
|
+
refactoring: 4,
|
|
33
|
+
inline: 2,
|
|
34
|
+
context: 3,
|
|
35
|
+
automation: 4,
|
|
36
|
+
},
|
|
37
|
+
gemini: {
|
|
38
|
+
label: 'Gemini CLI',
|
|
39
|
+
reasoning: 4,
|
|
40
|
+
context: 5,
|
|
41
|
+
sandbox: 5,
|
|
42
|
+
ci: 3,
|
|
43
|
+
ide: 3,
|
|
44
|
+
refactoring: 3,
|
|
45
|
+
inline: 2,
|
|
46
|
+
cloud: 4,
|
|
47
|
+
automation: 3,
|
|
48
|
+
},
|
|
49
|
+
copilot: {
|
|
50
|
+
label: 'GitHub Copilot',
|
|
51
|
+
inline: 5,
|
|
52
|
+
'cloud-agent': 4,
|
|
53
|
+
ide: 4,
|
|
54
|
+
ci: 4,
|
|
55
|
+
governance: 3,
|
|
56
|
+
reasoning: 3,
|
|
57
|
+
refactoring: 3,
|
|
58
|
+
context: 3,
|
|
59
|
+
automation: 3,
|
|
60
|
+
},
|
|
61
|
+
cursor: {
|
|
62
|
+
label: 'Cursor',
|
|
63
|
+
ide: 5,
|
|
64
|
+
ui: 5,
|
|
65
|
+
background: 4,
|
|
66
|
+
automation: 4,
|
|
67
|
+
reasoning: 3,
|
|
68
|
+
refactoring: 3,
|
|
69
|
+
inline: 4,
|
|
70
|
+
context: 3,
|
|
71
|
+
ci: 2,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// ─── Task-type to platform-strength mapping ───────────────────────────────────
|
|
76
|
+
|
|
77
|
+
const TASK_TYPE_PROFILES = {
|
|
78
|
+
'bug-fix': {
|
|
79
|
+
label: 'Bug Fixing',
|
|
80
|
+
requiredStrengths: { reasoning: 0.5, refactoring: 0.3, context: 0.2 },
|
|
81
|
+
description: 'Deep reasoning and code understanding for root cause analysis.',
|
|
82
|
+
},
|
|
83
|
+
'ci-review': {
|
|
84
|
+
label: 'CI / Async Review',
|
|
85
|
+
requiredStrengths: { ci: 0.5, cloud: 0.3, automation: 0.2 },
|
|
86
|
+
description: 'Asynchronous code review and CI-integrated workflows.',
|
|
87
|
+
},
|
|
88
|
+
'ui-work': {
|
|
89
|
+
label: 'UI Development',
|
|
90
|
+
requiredStrengths: { ide: 0.4, ui: 0.3, inline: 0.3 },
|
|
91
|
+
description: 'Interactive UI work with live preview and visual feedback.',
|
|
92
|
+
},
|
|
93
|
+
'quick-edit': {
|
|
94
|
+
label: 'Quick Edits',
|
|
95
|
+
requiredStrengths: { inline: 0.5, ide: 0.3, automation: 0.2 },
|
|
96
|
+
description: 'Small, fast inline edits and completions.',
|
|
97
|
+
},
|
|
98
|
+
'infrastructure': {
|
|
99
|
+
label: 'Infrastructure',
|
|
100
|
+
requiredStrengths: { sandbox: 0.4, cloud: 0.3, reasoning: 0.3 },
|
|
101
|
+
description: 'Infrastructure, DevOps, and sandbox-heavy workflows.',
|
|
102
|
+
},
|
|
103
|
+
'refactoring': {
|
|
104
|
+
label: 'Large Refactoring',
|
|
105
|
+
requiredStrengths: { refactoring: 0.4, reasoning: 0.3, context: 0.3 },
|
|
106
|
+
description: 'Cross-file refactoring with deep codebase understanding.',
|
|
107
|
+
},
|
|
108
|
+
'code-review': {
|
|
109
|
+
label: 'Code Review',
|
|
110
|
+
requiredStrengths: { reasoning: 0.4, governance: 0.3, ci: 0.3 },
|
|
111
|
+
description: 'Thorough review with governance and standards enforcement.',
|
|
112
|
+
},
|
|
113
|
+
'greenfield': {
|
|
114
|
+
label: 'Greenfield / Scaffolding',
|
|
115
|
+
requiredStrengths: { reasoning: 0.3, automation: 0.3, ide: 0.2, refactoring: 0.2 },
|
|
116
|
+
description: 'Starting new projects or major new features from scratch.',
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// ─── Scoring ──────────────────────────────────────────────────────────────────
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Score a platform against a task type profile.
|
|
124
|
+
* Returns a 0-5 weighted score.
|
|
125
|
+
*/
|
|
126
|
+
function scorePlatformForTask(platformKey, taskProfile) {
|
|
127
|
+
const strengths = PLATFORM_STRENGTHS[platformKey];
|
|
128
|
+
if (!strengths) return 0;
|
|
129
|
+
|
|
130
|
+
let score = 0;
|
|
131
|
+
for (const [dimension, weight] of Object.entries(taskProfile.requiredStrengths)) {
|
|
132
|
+
const platformScore = strengths[dimension] || 0;
|
|
133
|
+
score += platformScore * weight;
|
|
134
|
+
}
|
|
135
|
+
return Math.round(score * 100) / 100;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Rank all platforms for a given task type.
|
|
140
|
+
*/
|
|
141
|
+
function rankPlatformsForTask(taskType) {
|
|
142
|
+
const profile = TASK_TYPE_PROFILES[taskType];
|
|
143
|
+
if (!profile) return [];
|
|
144
|
+
|
|
145
|
+
const rankings = Object.keys(PLATFORM_STRENGTHS).map(platformKey => ({
|
|
146
|
+
platform: platformKey,
|
|
147
|
+
label: PLATFORM_STRENGTHS[platformKey].label,
|
|
148
|
+
score: scorePlatformForTask(platformKey, profile),
|
|
149
|
+
}));
|
|
150
|
+
|
|
151
|
+
rankings.sort((a, b) => b.score - a.score);
|
|
152
|
+
return rankings;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Compute a confidence level from the score gap between #1 and #2.
|
|
157
|
+
*/
|
|
158
|
+
function computeConfidence(rankings) {
|
|
159
|
+
if (rankings.length < 2) return 'high';
|
|
160
|
+
const gap = rankings[0].score - rankings[1].score;
|
|
161
|
+
if (gap >= 1.0) return 'high';
|
|
162
|
+
if (gap >= 0.4) return 'medium';
|
|
163
|
+
return 'low';
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ─── Task Routing ─────────────────────────────────────────────────────────────
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Generate task routing recommendations for all known task types.
|
|
170
|
+
* Optionally filter to only platforms present in platformAudits.
|
|
171
|
+
*/
|
|
172
|
+
function generateTaskRouting(platformAudits) {
|
|
173
|
+
const availablePlatforms = platformAudits
|
|
174
|
+
? new Set(platformAudits.map(a => a.platform))
|
|
175
|
+
: null;
|
|
176
|
+
|
|
177
|
+
const routing = [];
|
|
178
|
+
|
|
179
|
+
for (const [taskType, profile] of Object.entries(TASK_TYPE_PROFILES)) {
|
|
180
|
+
let rankings = rankPlatformsForTask(taskType);
|
|
181
|
+
|
|
182
|
+
if (availablePlatforms) {
|
|
183
|
+
rankings = rankings.filter(r => availablePlatforms.has(r.platform));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (rankings.length === 0) continue;
|
|
187
|
+
|
|
188
|
+
const best = rankings[0];
|
|
189
|
+
routing.push({
|
|
190
|
+
taskType,
|
|
191
|
+
taskLabel: profile.label,
|
|
192
|
+
recommendedPlatform: best.platform,
|
|
193
|
+
recommendedLabel: best.label,
|
|
194
|
+
score: best.score,
|
|
195
|
+
confidence: computeConfidence(rankings),
|
|
196
|
+
reasoning: profile.description,
|
|
197
|
+
alternatives: rankings.slice(1, 3).map(r => ({
|
|
198
|
+
platform: r.platform,
|
|
199
|
+
label: r.label,
|
|
200
|
+
score: r.score,
|
|
201
|
+
})),
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return routing;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// ─── Config Recommendations ───────────────────────────────────────────────────
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Detect configuration improvement opportunities from platform audits.
|
|
212
|
+
*/
|
|
213
|
+
function generateConfigRecommendations(canonicalModel, platformAudits) {
|
|
214
|
+
const recommendations = [];
|
|
215
|
+
|
|
216
|
+
if (!platformAudits || platformAudits.length === 0) return recommendations;
|
|
217
|
+
|
|
218
|
+
for (const auditResult of platformAudits) {
|
|
219
|
+
const platform = auditResult.platform;
|
|
220
|
+
const score = auditResult.score || 0;
|
|
221
|
+
|
|
222
|
+
// Low score platforms need attention
|
|
223
|
+
if (score < 40) {
|
|
224
|
+
recommendations.push({
|
|
225
|
+
platform,
|
|
226
|
+
recommendation: `Platform "${platform}" scores ${score}/100. Run setup to bootstrap baseline configuration.`,
|
|
227
|
+
impact: 'high',
|
|
228
|
+
category: 'bootstrap',
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Missing canonical sections
|
|
233
|
+
if (canonicalModel && canonicalModel.sections) {
|
|
234
|
+
const auditSections = new Set((auditResult.sections || []).map(s => s.key || s));
|
|
235
|
+
for (const section of canonicalModel.sections) {
|
|
236
|
+
if (!auditSections.has(section.key)) {
|
|
237
|
+
recommendations.push({
|
|
238
|
+
platform,
|
|
239
|
+
recommendation: `Missing canonical section "${section.key}" (${section.label || section.key}). Add to align with cross-platform standard.`,
|
|
240
|
+
impact: 'medium',
|
|
241
|
+
category: 'alignment',
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Permission/governance gaps
|
|
248
|
+
if (auditResult.governance) {
|
|
249
|
+
const gov = auditResult.governance;
|
|
250
|
+
if (!gov.hasPermissions) {
|
|
251
|
+
recommendations.push({
|
|
252
|
+
platform,
|
|
253
|
+
recommendation: 'No explicit permission configuration detected. Add permission boundaries for safer operation.',
|
|
254
|
+
impact: 'high',
|
|
255
|
+
category: 'security',
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
if (!gov.hasSecretProtection) {
|
|
259
|
+
recommendations.push({
|
|
260
|
+
platform,
|
|
261
|
+
recommendation: 'No secret protection hook found. Add protection to prevent credential exposure.',
|
|
262
|
+
impact: 'high',
|
|
263
|
+
category: 'security',
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Sort by impact
|
|
270
|
+
const impactOrder = { high: 0, medium: 1, low: 2 };
|
|
271
|
+
recommendations.sort((a, b) => (impactOrder[a.impact] || 2) - (impactOrder[b.impact] || 2));
|
|
272
|
+
|
|
273
|
+
return recommendations;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// ─── Cross-Platform Actions ───────────────────────────────────────────────────
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Detect when project changes need cross-platform updates.
|
|
280
|
+
* Prioritize by how many platforms are affected.
|
|
281
|
+
*/
|
|
282
|
+
function generateCrossPlatformActions(canonicalModel, platformAudits) {
|
|
283
|
+
const actions = [];
|
|
284
|
+
|
|
285
|
+
if (!platformAudits || platformAudits.length < 2) return actions;
|
|
286
|
+
|
|
287
|
+
const platforms = platformAudits.map(a => a.platform);
|
|
288
|
+
|
|
289
|
+
// Detect instruction drift: if one platform has instructions another lacks
|
|
290
|
+
if (canonicalModel && canonicalModel.sections) {
|
|
291
|
+
const sectionCoverage = {};
|
|
292
|
+
for (const section of canonicalModel.sections) {
|
|
293
|
+
sectionCoverage[section.key] = [];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
for (const auditResult of platformAudits) {
|
|
297
|
+
for (const section of (auditResult.sections || [])) {
|
|
298
|
+
const key = section.key || section;
|
|
299
|
+
if (sectionCoverage[key]) {
|
|
300
|
+
sectionCoverage[key].push(auditResult.platform);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
for (const [sectionKey, coveredPlatforms] of Object.entries(sectionCoverage)) {
|
|
306
|
+
if (coveredPlatforms.length > 0 && coveredPlatforms.length < platforms.length) {
|
|
307
|
+
const missing = platforms.filter(p => !coveredPlatforms.includes(p));
|
|
308
|
+
actions.push({
|
|
309
|
+
action: `Sync section "${sectionKey}" to missing platforms`,
|
|
310
|
+
affectedPlatforms: missing,
|
|
311
|
+
sourcePlatforms: coveredPlatforms,
|
|
312
|
+
priority: missing.length >= platforms.length / 2 ? 'high' : 'medium',
|
|
313
|
+
type: 'instruction-sync',
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Detect MCP server alignment gaps
|
|
320
|
+
const mcpByPlatform = {};
|
|
321
|
+
for (const auditResult of platformAudits) {
|
|
322
|
+
mcpByPlatform[auditResult.platform] = new Set(auditResult.mcpServers || []);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const allMcpServers = new Set();
|
|
326
|
+
for (const servers of Object.values(mcpByPlatform)) {
|
|
327
|
+
for (const s of servers) allMcpServers.add(s);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
for (const server of allMcpServers) {
|
|
331
|
+
const hasPlatforms = platforms.filter(p => mcpByPlatform[p] && mcpByPlatform[p].has(server));
|
|
332
|
+
const missingPlatforms = platforms.filter(p => !mcpByPlatform[p] || !mcpByPlatform[p].has(server));
|
|
333
|
+
|
|
334
|
+
if (hasPlatforms.length > 0 && missingPlatforms.length > 0) {
|
|
335
|
+
actions.push({
|
|
336
|
+
action: `Add MCP server "${server}" to platforms that lack it`,
|
|
337
|
+
affectedPlatforms: missingPlatforms,
|
|
338
|
+
sourcePlatforms: hasPlatforms,
|
|
339
|
+
priority: missingPlatforms.length > hasPlatforms.length ? 'medium' : 'low',
|
|
340
|
+
type: 'mcp-sync',
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Sort by priority then by affected platform count
|
|
346
|
+
const priorityOrder = { high: 0, medium: 1, low: 2 };
|
|
347
|
+
actions.sort((a, b) => {
|
|
348
|
+
const pDiff = (priorityOrder[a.priority] || 2) - (priorityOrder[b.priority] || 2);
|
|
349
|
+
if (pDiff !== 0) return pDiff;
|
|
350
|
+
return b.affectedPlatforms.length - a.affectedPlatforms.length;
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
return actions;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// ─── Main Entry ───────────────────────────────────────────────────────────────
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Generate a complete strategic advice package.
|
|
360
|
+
*
|
|
361
|
+
* @param {Object|null} canonicalModel - The canonical model from canon.js
|
|
362
|
+
* @param {Array} platformAudits - Array of per-platform audit results
|
|
363
|
+
* @returns {Object} { taskRouting, configRecommendations, crossPlatformActions }
|
|
364
|
+
*/
|
|
365
|
+
function generateStrategicAdvice(canonicalModel, platformAudits) {
|
|
366
|
+
return {
|
|
367
|
+
taskRouting: generateTaskRouting(platformAudits),
|
|
368
|
+
configRecommendations: generateConfigRecommendations(canonicalModel, platformAudits),
|
|
369
|
+
crossPlatformActions: generateCrossPlatformActions(canonicalModel, platformAudits),
|
|
370
|
+
generatedAt: new Date().toISOString(),
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
module.exports = {
|
|
375
|
+
generateStrategicAdvice,
|
|
376
|
+
PLATFORM_STRENGTHS,
|
|
377
|
+
TASK_TYPE_PROFILES,
|
|
378
|
+
scorePlatformForTask,
|
|
379
|
+
rankPlatformsForTask,
|
|
380
|
+
generateTaskRouting,
|
|
381
|
+
generateConfigRecommendations,
|
|
382
|
+
generateCrossPlatformActions,
|
|
383
|
+
};
|
|
@@ -0,0 +1,303 @@
|
|
|
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
|
+
};
|
|
46
|
+
|
|
47
|
+
// ─── Cross-platform recommendations ────────────────────────────────────────
|
|
48
|
+
|
|
49
|
+
function generateRecommendations(model, drift, platformScores) {
|
|
50
|
+
const recommendations = [];
|
|
51
|
+
const platforms = model.activePlatforms.map(p => p.platform);
|
|
52
|
+
|
|
53
|
+
// 1. If only one platform detected, recommend adding another
|
|
54
|
+
if (platforms.length === 1) {
|
|
55
|
+
recommendations.push({
|
|
56
|
+
priority: 'medium',
|
|
57
|
+
category: 'expansion',
|
|
58
|
+
message: `Only ${platforms[0]} is configured. Consider adding a second platform for redundancy and team flexibility.`,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 2. If any platform scores below 40, flag it
|
|
63
|
+
for (const [platform, score] of Object.entries(platformScores)) {
|
|
64
|
+
if (score !== null && score < 40) {
|
|
65
|
+
recommendations.push({
|
|
66
|
+
priority: 'high',
|
|
67
|
+
category: 'quality',
|
|
68
|
+
message: `${platform} scores ${score}/100. Run \`nerviq audit --platform ${platform}\` and address critical gaps.`,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 3. If trust drift is critical, recommend alignment
|
|
74
|
+
const trustDrifts = drift.drifts.filter(d => d.type === 'trust-drift' && d.severity === 'critical');
|
|
75
|
+
if (trustDrifts.length > 0) {
|
|
76
|
+
recommendations.push({
|
|
77
|
+
priority: 'critical',
|
|
78
|
+
category: 'security',
|
|
79
|
+
message: 'Critical trust posture mismatch. One platform has full autonomy while another is restricted. Align before production use.',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 4. Recommend shared MCP servers
|
|
84
|
+
const mcpDrifts = drift.drifts.filter(d => d.type === 'mcp-drift');
|
|
85
|
+
if (mcpDrifts.length > 2) {
|
|
86
|
+
recommendations.push({
|
|
87
|
+
priority: 'medium',
|
|
88
|
+
category: 'tooling',
|
|
89
|
+
message: `${mcpDrifts.length} MCP alignment issues. Use \`nerviq harmony sync\` to propagate MCP servers across platforms.`,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 5. Coverage gap recommendations
|
|
94
|
+
const coverageGaps = drift.drifts.filter(d => d.type === 'coverage-gap' && d.severity === 'high');
|
|
95
|
+
for (const gap of coverageGaps) {
|
|
96
|
+
recommendations.push({
|
|
97
|
+
priority: 'high',
|
|
98
|
+
category: 'coverage',
|
|
99
|
+
message: gap.description + '. ' + gap.recommendation,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 6. If harmony score is high and all platforms score well, celebrate
|
|
104
|
+
if (drift.harmonyScore >= 90 && Object.values(platformScores).every(s => s === null || s >= 70)) {
|
|
105
|
+
recommendations.push({
|
|
106
|
+
priority: 'low',
|
|
107
|
+
category: 'status',
|
|
108
|
+
message: 'Excellent cross-platform alignment. All platforms are well-configured and consistent.',
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Sort: critical > high > medium > low
|
|
113
|
+
const priorityOrder = { critical: 3, high: 2, medium: 1, low: 0 };
|
|
114
|
+
recommendations.sort((a, b) => (priorityOrder[b.priority] || 0) - (priorityOrder[a.priority] || 0));
|
|
115
|
+
|
|
116
|
+
return recommendations;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ─── Main audit function ────────────────────────────────────────────────────
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Run a cross-platform harmony audit.
|
|
123
|
+
*
|
|
124
|
+
* Builds a canonical model, runs per-platform audits, detects drift,
|
|
125
|
+
* and generates cross-platform recommendations.
|
|
126
|
+
*
|
|
127
|
+
* @param {object} options - { dir: string, silent?: boolean, verbose?: boolean }
|
|
128
|
+
* @returns {object} Harmony audit result
|
|
129
|
+
*/
|
|
130
|
+
async function harmonyAudit(options) {
|
|
131
|
+
const { dir, silent = false, verbose = false } = options;
|
|
132
|
+
|
|
133
|
+
// 1. Build canonical model
|
|
134
|
+
const model = buildCanonicalModel(dir);
|
|
135
|
+
const platformKeys = model.activePlatforms.map(p => p.platform);
|
|
136
|
+
|
|
137
|
+
if (platformKeys.length === 0) {
|
|
138
|
+
return {
|
|
139
|
+
harmonyScore: 0,
|
|
140
|
+
platformScores: {},
|
|
141
|
+
drift: { drifts: [], summary: { total: 0, critical: 0, high: 0, medium: 0, low: 0 }, harmonyScore: 0 },
|
|
142
|
+
recommendations: [{
|
|
143
|
+
priority: 'high',
|
|
144
|
+
category: 'coverage',
|
|
145
|
+
message: 'No AI coding platforms detected. Run `nerviq init` to set up Claude, or add another platform.',
|
|
146
|
+
}],
|
|
147
|
+
activePlatforms: [],
|
|
148
|
+
model,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// 2. Run per-platform audits (silent mode to avoid console noise)
|
|
153
|
+
const platformScores = {};
|
|
154
|
+
const platformResults = {};
|
|
155
|
+
for (const key of platformKeys) {
|
|
156
|
+
const auditPlatform = PLATFORM_AUDIT_MAP[key];
|
|
157
|
+
if (auditPlatform) {
|
|
158
|
+
try {
|
|
159
|
+
const result = await platformAudit({ dir, platform: auditPlatform, silent: true });
|
|
160
|
+
platformScores[key] = result.score;
|
|
161
|
+
platformResults[key] = result;
|
|
162
|
+
} catch {
|
|
163
|
+
platformScores[key] = null;
|
|
164
|
+
platformResults[key] = null;
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
platformScores[key] = null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// 3. Detect drift
|
|
172
|
+
const drift = detectDrift(model);
|
|
173
|
+
|
|
174
|
+
// 4. Calculate overall harmony score
|
|
175
|
+
// Blend of drift harmony score and average platform scores
|
|
176
|
+
const validScores = Object.values(platformScores).filter(s => s !== null);
|
|
177
|
+
const avgPlatformScore = validScores.length > 0
|
|
178
|
+
? Math.round(validScores.reduce((a, b) => a + b, 0) / validScores.length)
|
|
179
|
+
: 0;
|
|
180
|
+
|
|
181
|
+
// Harmony = 60% drift alignment + 40% average platform quality
|
|
182
|
+
const harmonyScore = Math.round(drift.harmonyScore * 0.6 + avgPlatformScore * 0.4);
|
|
183
|
+
|
|
184
|
+
// 5. Generate recommendations
|
|
185
|
+
const recommendations = generateRecommendations(model, drift, platformScores);
|
|
186
|
+
|
|
187
|
+
const result = {
|
|
188
|
+
harmonyScore,
|
|
189
|
+
platformScores,
|
|
190
|
+
platformResults,
|
|
191
|
+
drift,
|
|
192
|
+
recommendations,
|
|
193
|
+
activePlatforms: model.activePlatforms,
|
|
194
|
+
model,
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// 6. Print report if not silent
|
|
198
|
+
if (!silent) {
|
|
199
|
+
printHarmonyReport(result, { verbose });
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// ─── Report printer ─────────────────────────────────────────────────────────
|
|
206
|
+
|
|
207
|
+
function printHarmonyReport(result, options = {}) {
|
|
208
|
+
const { verbose = false } = options;
|
|
209
|
+
const c = colorize;
|
|
210
|
+
|
|
211
|
+
console.log('');
|
|
212
|
+
console.log(c(' ══════════════════════════════════════════════════════', 'dim'));
|
|
213
|
+
console.log(c(' HARMONY AUDIT — Cross-Platform DX Report', 'bold'));
|
|
214
|
+
console.log(c(' ══════════════════════════════════════════════════════', 'dim'));
|
|
215
|
+
console.log('');
|
|
216
|
+
|
|
217
|
+
// Active platforms
|
|
218
|
+
console.log(c(' Active platforms:', 'bold'));
|
|
219
|
+
for (const ap of result.activePlatforms) {
|
|
220
|
+
const score = result.platformScores[ap.platform];
|
|
221
|
+
const scoreStr = score !== null ? `${score}/100` : 'n/a';
|
|
222
|
+
const scoreColor = score >= 70 ? 'green' : score >= 40 ? 'yellow' : 'red';
|
|
223
|
+
console.log(` ${ap.label}: ${c(scoreStr, score !== null ? scoreColor : 'dim')}`);
|
|
224
|
+
}
|
|
225
|
+
console.log('');
|
|
226
|
+
|
|
227
|
+
// Harmony score
|
|
228
|
+
const hs = result.harmonyScore;
|
|
229
|
+
const hsColor = hs >= 80 ? 'green' : hs >= 50 ? 'yellow' : 'red';
|
|
230
|
+
console.log(` Harmony Score: ${progressBar(hs)} ${c(hs + '/100', hsColor)}`);
|
|
231
|
+
console.log('');
|
|
232
|
+
|
|
233
|
+
// Drift summary
|
|
234
|
+
if (result.drift.drifts.length > 0) {
|
|
235
|
+
console.log(formatDriftReport(result.drift, { color: true, verbose }));
|
|
236
|
+
} else {
|
|
237
|
+
console.log(c(' No cross-platform drift detected.', 'green'));
|
|
238
|
+
console.log('');
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Recommendations
|
|
242
|
+
if (result.recommendations.length > 0) {
|
|
243
|
+
console.log(c(' Recommendations:', 'bold'));
|
|
244
|
+
const priorityIcons = { critical: '\u2718', high: '!', medium: '~', low: '\u2713' };
|
|
245
|
+
const priorityColors = { critical: 'red', high: 'yellow', medium: 'blue', low: 'green' };
|
|
246
|
+
|
|
247
|
+
for (const rec of result.recommendations) {
|
|
248
|
+
const icon = priorityIcons[rec.priority] || '-';
|
|
249
|
+
const pColor = priorityColors[rec.priority] || 'dim';
|
|
250
|
+
console.log(` ${c(icon, pColor)} [${rec.category}] ${rec.message}`);
|
|
251
|
+
}
|
|
252
|
+
console.log('');
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
console.log(c(' Powered by CLAUDEX cross-platform intelligence', 'dim'));
|
|
256
|
+
console.log(c(' https://github.com/nerviq/nerviq', 'dim'));
|
|
257
|
+
console.log('');
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Format the harmony audit result as a structured report string (no ANSI colors).
|
|
262
|
+
*
|
|
263
|
+
* @param {object} result - Output of harmonyAudit()
|
|
264
|
+
* @returns {string} Plain-text report
|
|
265
|
+
*/
|
|
266
|
+
function formatHarmonyAuditReport(result) {
|
|
267
|
+
const lines = [];
|
|
268
|
+
|
|
269
|
+
lines.push('HARMONY AUDIT — Cross-Platform DX Report');
|
|
270
|
+
lines.push('========================================');
|
|
271
|
+
lines.push('');
|
|
272
|
+
|
|
273
|
+
lines.push('Active platforms:');
|
|
274
|
+
for (const ap of result.activePlatforms) {
|
|
275
|
+
const score = result.platformScores[ap.platform];
|
|
276
|
+
lines.push(` ${ap.label}: ${score !== null ? score + '/100' : 'n/a'}`);
|
|
277
|
+
}
|
|
278
|
+
lines.push('');
|
|
279
|
+
|
|
280
|
+
lines.push(`Harmony Score: ${result.harmonyScore}/100`);
|
|
281
|
+
lines.push('');
|
|
282
|
+
|
|
283
|
+
if (result.drift.drifts.length > 0) {
|
|
284
|
+
lines.push(formatDriftReport(result.drift, { color: false, verbose: true }));
|
|
285
|
+
} else {
|
|
286
|
+
lines.push('No cross-platform drift detected.');
|
|
287
|
+
}
|
|
288
|
+
lines.push('');
|
|
289
|
+
|
|
290
|
+
if (result.recommendations.length > 0) {
|
|
291
|
+
lines.push('Recommendations:');
|
|
292
|
+
for (const rec of result.recommendations) {
|
|
293
|
+
lines.push(` [${rec.priority.toUpperCase()}] [${rec.category}] ${rec.message}`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return lines.join('\n');
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
module.exports = {
|
|
301
|
+
harmonyAudit,
|
|
302
|
+
formatHarmonyAuditReport,
|
|
303
|
+
};
|