@nerviq/cli 0.0.1 → 0.9.0-beta.2

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 (148) hide show
  1. package/CHANGELOG.md +181 -0
  2. package/LICENSE +21 -0
  3. package/README.md +447 -0
  4. package/bin/cli.js +749 -0
  5. package/content/case-study-template.md +91 -0
  6. package/content/claims-governance.md +37 -0
  7. package/content/claude-code/audit-repo/SKILL.md +20 -0
  8. package/content/claude-native-integration.md +60 -0
  9. package/content/devto-article.json +9 -0
  10. package/content/launch-posts.md +226 -0
  11. package/content/pilot-rollout-kit.md +30 -0
  12. package/content/release-checklist.md +31 -0
  13. package/package.json +53 -4
  14. package/src/activity.js +529 -0
  15. package/src/aider/activity.js +226 -0
  16. package/src/aider/config-parser.js +166 -0
  17. package/src/aider/context.js +158 -0
  18. package/src/aider/deep-review.js +316 -0
  19. package/src/aider/domain-packs.js +278 -0
  20. package/src/aider/freshness.js +168 -0
  21. package/src/aider/governance.js +253 -0
  22. package/src/aider/interactive.js +334 -0
  23. package/src/aider/mcp-packs.js +98 -0
  24. package/src/aider/patch.js +214 -0
  25. package/src/aider/plans.js +186 -0
  26. package/src/aider/premium.js +360 -0
  27. package/src/aider/setup.js +404 -0
  28. package/src/aider/techniques.js +1323 -0
  29. package/src/analyze.js +821 -0
  30. package/src/audit.js +1003 -0
  31. package/src/badge.js +13 -0
  32. package/src/benchmark.js +339 -0
  33. package/src/claudex-sync.json +7 -0
  34. package/src/codex/activity.js +324 -0
  35. package/src/codex/config-parser.js +183 -0
  36. package/src/codex/context.js +221 -0
  37. package/src/codex/deep-review.js +493 -0
  38. package/src/codex/domain-packs.js +372 -0
  39. package/src/codex/freshness.js +167 -0
  40. package/src/codex/governance.js +192 -0
  41. package/src/codex/interactive.js +618 -0
  42. package/src/codex/mcp-packs.js +660 -0
  43. package/src/codex/patch.js +209 -0
  44. package/src/codex/plans.js +251 -0
  45. package/src/codex/premium.js +614 -0
  46. package/src/codex/setup.js +603 -0
  47. package/src/codex/techniques.js +2649 -0
  48. package/src/context.js +272 -0
  49. package/src/copilot/activity.js +309 -0
  50. package/src/copilot/config-parser.js +226 -0
  51. package/src/copilot/context.js +197 -0
  52. package/src/copilot/deep-review.js +346 -0
  53. package/src/copilot/domain-packs.js +350 -0
  54. package/src/copilot/freshness.js +197 -0
  55. package/src/copilot/governance.js +222 -0
  56. package/src/copilot/interactive.js +406 -0
  57. package/src/copilot/mcp-packs.js +572 -0
  58. package/src/copilot/patch.js +238 -0
  59. package/src/copilot/plans.js +253 -0
  60. package/src/copilot/premium.js +450 -0
  61. package/src/copilot/setup.js +488 -0
  62. package/src/copilot/techniques.js +1822 -0
  63. package/src/cursor/activity.js +301 -0
  64. package/src/cursor/config-parser.js +265 -0
  65. package/src/cursor/context.js +236 -0
  66. package/src/cursor/deep-review.js +334 -0
  67. package/src/cursor/domain-packs.js +346 -0
  68. package/src/cursor/freshness.js +214 -0
  69. package/src/cursor/governance.js +229 -0
  70. package/src/cursor/interactive.js +391 -0
  71. package/src/cursor/mcp-packs.js +571 -0
  72. package/src/cursor/patch.js +243 -0
  73. package/src/cursor/plans.js +254 -0
  74. package/src/cursor/premium.js +468 -0
  75. package/src/cursor/setup.js +488 -0
  76. package/src/cursor/techniques.js +1786 -0
  77. package/src/deep-review.js +345 -0
  78. package/src/domain-packs.js +364 -0
  79. package/src/formatters/sarif.js +115 -0
  80. package/src/gemini/activity.js +402 -0
  81. package/src/gemini/config-parser.js +275 -0
  82. package/src/gemini/context.js +221 -0
  83. package/src/gemini/deep-review.js +559 -0
  84. package/src/gemini/domain-packs.js +371 -0
  85. package/src/gemini/freshness.js +204 -0
  86. package/src/gemini/governance.js +201 -0
  87. package/src/gemini/interactive.js +860 -0
  88. package/src/gemini/mcp-packs.js +658 -0
  89. package/src/gemini/patch.js +229 -0
  90. package/src/gemini/plans.js +269 -0
  91. package/src/gemini/premium.js +759 -0
  92. package/src/gemini/setup.js +692 -0
  93. package/src/gemini/techniques.js +2084 -0
  94. package/src/governance.js +523 -0
  95. package/src/harmony/advisor.js +383 -0
  96. package/src/harmony/audit.js +303 -0
  97. package/src/harmony/canon.js +444 -0
  98. package/src/harmony/cli.js +331 -0
  99. package/src/harmony/drift.js +401 -0
  100. package/src/harmony/governance.js +313 -0
  101. package/src/harmony/memory.js +238 -0
  102. package/src/harmony/sync.js +458 -0
  103. package/src/harmony/watch.js +336 -0
  104. package/src/index.js +256 -0
  105. package/src/insights.js +119 -0
  106. package/src/interactive.js +118 -0
  107. package/src/mcp-packs.js +597 -0
  108. package/src/opencode/activity.js +286 -0
  109. package/src/opencode/config-parser.js +109 -0
  110. package/src/opencode/context.js +247 -0
  111. package/src/opencode/deep-review.js +313 -0
  112. package/src/opencode/domain-packs.js +240 -0
  113. package/src/opencode/freshness.js +158 -0
  114. package/src/opencode/governance.js +159 -0
  115. package/src/opencode/interactive.js +392 -0
  116. package/src/opencode/mcp-packs.js +474 -0
  117. package/src/opencode/patch.js +184 -0
  118. package/src/opencode/plans.js +231 -0
  119. package/src/opencode/premium.js +413 -0
  120. package/src/opencode/setup.js +449 -0
  121. package/src/opencode/techniques.js +1713 -0
  122. package/src/plans.js +655 -0
  123. package/src/secret-patterns.js +30 -0
  124. package/src/setup.js +1274 -0
  125. package/src/synergy/adaptive.js +261 -0
  126. package/src/synergy/compensation.js +156 -0
  127. package/src/synergy/evidence.js +193 -0
  128. package/src/synergy/learning.js +184 -0
  129. package/src/synergy/patterns.js +227 -0
  130. package/src/synergy/ranking.js +83 -0
  131. package/src/synergy/report.js +163 -0
  132. package/src/synergy/routing.js +152 -0
  133. package/src/techniques.js +1354 -0
  134. package/src/watch.js +229 -0
  135. package/src/windsurf/activity.js +302 -0
  136. package/src/windsurf/config-parser.js +267 -0
  137. package/src/windsurf/context.js +249 -0
  138. package/src/windsurf/deep-review.js +337 -0
  139. package/src/windsurf/domain-packs.js +348 -0
  140. package/src/windsurf/freshness.js +215 -0
  141. package/src/windsurf/governance.js +231 -0
  142. package/src/windsurf/interactive.js +388 -0
  143. package/src/windsurf/mcp-packs.js +535 -0
  144. package/src/windsurf/patch.js +231 -0
  145. package/src/windsurf/plans.js +247 -0
  146. package/src/windsurf/premium.js +467 -0
  147. package/src/windsurf/setup.js +471 -0
  148. package/src/windsurf/techniques.js +1758 -0
@@ -0,0 +1,243 @@
1
+ /**
2
+ * Cursor Patch Intelligence
3
+ *
4
+ * Safe patching of existing Cursor files using managed blocks.
5
+ * Supports .cursor/rules/*.mdc (MDC comment blocks) and
6
+ * .cursor/mcp.json + .cursor/environment.json (JSON merge).
7
+ *
8
+ * Managed blocks are sections that nerviq controls.
9
+ * Hand-authored content outside managed blocks is preserved.
10
+ */
11
+
12
+ const fs = require('fs');
13
+ const path = require('path');
14
+ const { writeRollbackArtifact, writeActivityArtifact } = require('../activity');
15
+
16
+ // Managed block markers for MDC files (HTML comments work in Markdown body)
17
+ const MANAGED_START_MDC = '<!-- nerviq:managed:start -->';
18
+ const MANAGED_END_MDC = '<!-- nerviq:managed:end -->';
19
+ const MANAGED_JSON_KEY = '_claudex_managed';
20
+
21
+ /**
22
+ * Extract managed blocks from a file.
23
+ */
24
+ function extractManagedBlock(content, startMarker, endMarker) {
25
+ const startIdx = content.indexOf(startMarker);
26
+ const endIdx = content.indexOf(endMarker);
27
+
28
+ if (startIdx === -1 || endIdx === -1 || endIdx <= startIdx) {
29
+ return { before: content, managed: null, after: '' };
30
+ }
31
+
32
+ return {
33
+ before: content.substring(0, startIdx),
34
+ managed: content.substring(startIdx + startMarker.length, endIdx).trim(),
35
+ after: content.substring(endIdx + endMarker.length),
36
+ };
37
+ }
38
+
39
+ /**
40
+ * Replace or insert a managed block in a file.
41
+ */
42
+ function upsertManagedBlock(content, newManaged, startMarker, endMarker) {
43
+ const { before, managed, after } = extractManagedBlock(content, startMarker, endMarker);
44
+
45
+ if (managed !== null) {
46
+ return `${before}${startMarker}\n${newManaged}\n${endMarker}${after}`;
47
+ }
48
+
49
+ const separator = content.endsWith('\n') ? '\n' : '\n\n';
50
+ return `${content}${separator}${startMarker}\n${newManaged}\n${endMarker}\n`;
51
+ }
52
+
53
+ /**
54
+ * Patch .cursor/rules/*.mdc with managed sections.
55
+ * Preserves MDC frontmatter and hand-authored content.
56
+ */
57
+ function patchCursorRuleMdc(existingContent, managedSections) {
58
+ const newManaged = Object.entries(managedSections)
59
+ .map(([section, content]) => `## ${section}\n${content}`)
60
+ .join('\n\n');
61
+
62
+ return upsertManagedBlock(existingContent, newManaged, MANAGED_START_MDC, MANAGED_END_MDC);
63
+ }
64
+
65
+ /**
66
+ * Patch .cursor/mcp.json by safely merging new servers.
67
+ * Cursor MCP uses the "mcpServers" wrapper format.
68
+ */
69
+ function patchMcpJson(existingContent, newServers) {
70
+ let existing;
71
+ try {
72
+ existing = JSON.parse(existingContent);
73
+ } catch {
74
+ existing = {};
75
+ }
76
+
77
+ if (!existing.mcpServers) existing.mcpServers = {};
78
+
79
+ const merged = { ...existing };
80
+ for (const [serverName, config] of Object.entries(newServers)) {
81
+ if (!(serverName in merged.mcpServers)) {
82
+ merged.mcpServers[serverName] = config;
83
+ }
84
+ }
85
+
86
+ if (!merged[MANAGED_JSON_KEY]) merged[MANAGED_JSON_KEY] = {};
87
+ merged[MANAGED_JSON_KEY]._updatedAt = new Date().toISOString();
88
+ merged[MANAGED_JSON_KEY]._generator = nerviq;
89
+ merged[MANAGED_JSON_KEY]._platform = 'cursor';
90
+
91
+ return JSON.stringify(merged, null, 2) + '\n';
92
+ }
93
+
94
+ /**
95
+ * Patch .cursor/environment.json by safely merging new fields.
96
+ */
97
+ function patchEnvironmentJson(existingContent, newFields) {
98
+ let existing;
99
+ try {
100
+ existing = JSON.parse(existingContent);
101
+ } catch {
102
+ existing = {};
103
+ }
104
+
105
+ const merged = { ...existing };
106
+
107
+ for (const [key, value] of Object.entries(newFields)) {
108
+ if (key === MANAGED_JSON_KEY) {
109
+ merged[MANAGED_JSON_KEY] = { ...(existing[MANAGED_JSON_KEY] || {}), ...value };
110
+ } else if (!(key in existing)) {
111
+ merged[key] = value;
112
+ }
113
+ }
114
+
115
+ if (!merged[MANAGED_JSON_KEY]) merged[MANAGED_JSON_KEY] = {};
116
+ merged[MANAGED_JSON_KEY]._updatedAt = new Date().toISOString();
117
+ merged[MANAGED_JSON_KEY]._generator = nerviq;
118
+ merged[MANAGED_JSON_KEY]._platform = 'cursor';
119
+
120
+ return JSON.stringify(merged, null, 2) + '\n';
121
+ }
122
+
123
+ /**
124
+ * Detect if a repo has multiple agent surfaces (Cursor + Claude + Codex + Gemini + Copilot coexistence).
125
+ */
126
+ function detectMixedAgentRepo(dir) {
127
+ const hasClaude = fs.existsSync(path.join(dir, 'CLAUDE.md')) || fs.existsSync(path.join(dir, '.claude'));
128
+ const hasCodex = fs.existsSync(path.join(dir, 'AGENTS.md')) || fs.existsSync(path.join(dir, '.codex'));
129
+ const hasGemini = fs.existsSync(path.join(dir, 'GEMINI.md')) || fs.existsSync(path.join(dir, '.gemini'));
130
+ const hasCopilot = fs.existsSync(path.join(dir, '.github', 'copilot-instructions.md')) ||
131
+ fs.existsSync(path.join(dir, '.vscode', 'mcp.json'));
132
+ const hasCursor = fs.existsSync(path.join(dir, '.cursor')) ||
133
+ fs.existsSync(path.join(dir, '.cursorrules'));
134
+
135
+ const platforms = [];
136
+ if (hasClaude) platforms.push('claude');
137
+ if (hasCodex) platforms.push('codex');
138
+ if (hasGemini) platforms.push('gemini');
139
+ if (hasCopilot) platforms.push('copilot');
140
+ if (hasCursor) platforms.push('cursor');
141
+
142
+ return {
143
+ isMixed: platforms.length >= 2,
144
+ hasClaude,
145
+ hasCodex,
146
+ hasGemini,
147
+ hasCopilot,
148
+ hasCursor,
149
+ platforms,
150
+ guidance: platforms.length >= 2
151
+ ? `This is a mixed-agent repo (${platforms.join(', ')}). Keep each platform's config in its own directory (.claude/, .cursor/, .gemini/, .github/). Do not merge them.`
152
+ : null,
153
+ };
154
+ }
155
+
156
+ /**
157
+ * Generate a diff preview for a patch operation.
158
+ */
159
+ function generatePatchPreview(originalContent, patchedContent, filePath) {
160
+ const origLines = originalContent.split('\n');
161
+ const patchLines = patchedContent.split('\n');
162
+ const lines = [`--- ${filePath} (original)`, `+++ ${filePath} (patched)`];
163
+
164
+ let inChange = false;
165
+ for (let i = 0; i < Math.max(origLines.length, patchLines.length); i++) {
166
+ const orig = origLines[i] || '';
167
+ const patched = patchLines[i] || '';
168
+ if (orig !== patched) {
169
+ if (!inChange) { lines.push(`@@ line ${i + 1} @@`); inChange = true; }
170
+ if (i < origLines.length) lines.push(`-${orig}`);
171
+ if (i < patchLines.length) lines.push(`+${patched}`);
172
+ } else {
173
+ inChange = false;
174
+ }
175
+ }
176
+
177
+ return lines.join('\n');
178
+ }
179
+
180
+ /**
181
+ * Apply a patch to a file with backup and rollback support.
182
+ */
183
+ function applyPatch(dir, filePath, patchFn, options = {}) {
184
+ const fullPath = path.join(dir, filePath);
185
+ const dryRun = options.dryRun === true;
186
+
187
+ if (!fs.existsSync(fullPath)) {
188
+ return { success: false, reason: `${filePath} does not exist`, preview: null };
189
+ }
190
+
191
+ const original = fs.readFileSync(fullPath, 'utf8');
192
+ const patched = patchFn(original);
193
+
194
+ if (patched === original) {
195
+ return { success: true, reason: 'no changes needed', preview: null, unchanged: true };
196
+ }
197
+
198
+ const preview = generatePatchPreview(original, patched, filePath);
199
+
200
+ if (dryRun) {
201
+ return { success: true, reason: 'dry run', preview, unchanged: false };
202
+ }
203
+
204
+ const backupPath = fullPath + '.claudex-backup';
205
+ fs.writeFileSync(backupPath, original, 'utf8');
206
+ fs.writeFileSync(fullPath, patched, 'utf8');
207
+
208
+ const rollback = writeRollbackArtifact(dir, {
209
+ sourcePlan: 'cursor-patch',
210
+ patchedFiles: [filePath],
211
+ backupFiles: [{ original: filePath, backup: path.relative(dir, backupPath) }],
212
+ rollbackInstructions: [`Restore ${filePath} from ${path.relative(dir, backupPath)}`],
213
+ });
214
+
215
+ const activity = writeActivityArtifact(dir, 'cursor-patch', {
216
+ platform: 'cursor',
217
+ patchedFiles: [filePath],
218
+ rollbackArtifact: rollback.relativePath,
219
+ });
220
+
221
+ return {
222
+ success: true,
223
+ reason: 'patched',
224
+ preview,
225
+ unchanged: false,
226
+ rollbackArtifact: rollback.relativePath,
227
+ activityArtifact: activity.relativePath,
228
+ };
229
+ }
230
+
231
+ module.exports = {
232
+ MANAGED_START_MDC,
233
+ MANAGED_END_MDC,
234
+ MANAGED_JSON_KEY,
235
+ extractManagedBlock,
236
+ upsertManagedBlock,
237
+ patchCursorRuleMdc,
238
+ patchMcpJson,
239
+ patchEnvironmentJson,
240
+ detectMixedAgentRepo,
241
+ generatePatchPreview,
242
+ applyPatch,
243
+ };
@@ -0,0 +1,254 @@
1
+ /**
2
+ * Cursor Proposal Bundle — 9 proposal families.
3
+ *
4
+ * cursor-rules, cursor-mcp, cursor-environment, cursor-automations,
5
+ * cursor-bugbot, cursor-legacy-migration, cursor-ci-review,
6
+ * cursor-design-mode, cursor-enterprise
7
+ */
8
+
9
+ const path = require('path');
10
+ const { version } = require('../../package.json');
11
+ const { audit } = require('../audit');
12
+ const { analyzeProject } = require('../analyze');
13
+ const { buildCursorSetupFiles } = require('./setup');
14
+ const { getCursorMcpPreflight } = require('./mcp-packs');
15
+
16
+ function maturityFromScore(score) {
17
+ if (score >= 81) return 'mature';
18
+ if (score >= 61) return 'solid';
19
+ if (score >= 41) return 'developing';
20
+ if (score >= 21) return 'weak';
21
+ return 'raw';
22
+ }
23
+
24
+ function triggerMatchesFile(result, filePath) {
25
+ if (filePath.startsWith('.cursor/rules/')) {
26
+ return result.file === '.cursor/rules/' || result.category === 'rules' ||
27
+ result.category === 'instructions-quality' || result.category === 'quality-deep';
28
+ }
29
+ if (filePath === '.cursor/mcp.json' || filePath.includes('MCP')) {
30
+ return result.category === 'mcp';
31
+ }
32
+ if (filePath === '.cursor/environment.json') {
33
+ return result.category === 'background-agents';
34
+ }
35
+ if (filePath.includes('automations')) {
36
+ return result.category === 'automations';
37
+ }
38
+ if (filePath.includes('cursor-review')) {
39
+ return result.category === 'cross-surface';
40
+ }
41
+ if (filePath.includes('bugbot')) {
42
+ return result.category === 'bugbot';
43
+ }
44
+ if (filePath.includes('design-mode')) {
45
+ return result.category === 'quality-deep';
46
+ }
47
+ if (filePath.includes('migration')) {
48
+ return result.id === 'CU-A02' || result.id === 'CU-L02';
49
+ }
50
+ return result.file === filePath;
51
+ }
52
+
53
+ function uniqueValues(items = []) {
54
+ return [...new Set(items.filter(Boolean))];
55
+ }
56
+
57
+ function buildDomainPackGuidance(report) {
58
+ return (report.recommendedDomainPacks || []).map((pack) => ({
59
+ key: pack.key,
60
+ label: pack.label,
61
+ useWhen: pack.useWhen,
62
+ matchReasons: pack.matchReasons || [],
63
+ recommendedModules: pack.recommendedModules || [],
64
+ recommendedProposalFamilies: pack.recommendedProposalFamilies || [],
65
+ recommendedSurfaces: pack.recommendedSurfaces || [],
66
+ benchmarkFocus: pack.benchmarkFocus || [],
67
+ }));
68
+ }
69
+
70
+ function selectPackContext(filePath, domainPackGuidance = []) {
71
+ return domainPackGuidance
72
+ .filter((pack) => {
73
+ if (!Array.isArray(pack.recommendedSurfaces) || pack.recommendedSurfaces.length === 0) return true;
74
+ return pack.recommendedSurfaces.some((surface) => filePath === surface || filePath.startsWith(surface));
75
+ })
76
+ .map((pack) => ({
77
+ key: pack.key,
78
+ label: pack.label,
79
+ why: pack.matchReasons[0] || pack.useWhen,
80
+ recommendedModules: (pack.recommendedModules || []).slice(0, 3),
81
+ recommendedProposalFamilies: (pack.recommendedProposalFamilies || []).slice(0, 3),
82
+ benchmarkFocus: (pack.benchmarkFocus || []).slice(0, 2),
83
+ }));
84
+ }
85
+
86
+ const PROPOSAL_FAMILIES = {
87
+ '.cursor/rules/core.mdc': {
88
+ id: 'cursor-rules',
89
+ title: 'Create Cursor core rules (.mdc)',
90
+ module: 'rules',
91
+ risk: 'low',
92
+ confidence: 'high',
93
+ },
94
+ '.cursor/mcp.json': {
95
+ id: 'cursor-mcp',
96
+ title: 'Create Cursor MCP configuration',
97
+ module: 'mcp',
98
+ risk: 'medium',
99
+ confidence: 'high',
100
+ },
101
+ '.cursor/environment.json': {
102
+ id: 'cursor-environment',
103
+ title: 'Create Cursor background agent environment config',
104
+ module: 'environment',
105
+ risk: 'medium',
106
+ confidence: 'medium',
107
+ },
108
+ '.cursor/rules/migration-guide.mdc': {
109
+ id: 'cursor-legacy-migration',
110
+ title: 'Create legacy .cursorrules migration guide',
111
+ module: 'legacy-migration',
112
+ risk: 'low',
113
+ confidence: 'high',
114
+ },
115
+ '.github/workflows/cursor-review.yml': {
116
+ id: 'cursor-ci-review',
117
+ title: 'Create Cursor CI review workflow',
118
+ module: 'ci',
119
+ risk: 'medium',
120
+ confidence: 'medium',
121
+ },
122
+ '.cursor/rules/bugbot-guide.mdc': {
123
+ id: 'cursor-bugbot',
124
+ title: 'Create BugBot configuration guide',
125
+ module: 'bugbot',
126
+ risk: 'low',
127
+ confidence: 'medium',
128
+ },
129
+ '.cursor/rules/design-mode-guide.mdc': {
130
+ id: 'cursor-design-mode',
131
+ title: 'Create Design Mode usage guide',
132
+ module: 'design-mode',
133
+ risk: 'low',
134
+ confidence: 'medium',
135
+ },
136
+ '.cursor/rules/typescript.mdc': {
137
+ id: 'cursor-rules',
138
+ title: 'Create Cursor TypeScript Auto Attached rule',
139
+ module: 'rules',
140
+ risk: 'low',
141
+ confidence: 'high',
142
+ },
143
+ };
144
+
145
+ function resolveProposalFamily(file) {
146
+ const familyFromFile = file.family
147
+ ? Object.values(PROPOSAL_FAMILIES).find(f => f.id === file.family)
148
+ : null;
149
+ return familyFromFile || PROPOSAL_FAMILIES[file.path] || {
150
+ id: 'cursor-unknown',
151
+ title: `Create ${file.path}`,
152
+ module: 'unknown',
153
+ risk: 'medium',
154
+ confidence: 'low',
155
+ };
156
+ }
157
+
158
+ function proposalForFile(file, auditResult, domainPackGuidance = []) {
159
+ const triggers = auditResult.results
160
+ .filter((result) => result.passed === false && triggerMatchesFile(result, file.path))
161
+ .sort((a, b) => {
162
+ const weight = { critical: 3, high: 2, medium: 1, low: 0 };
163
+ return (weight[b.impact] || 0) - (weight[a.impact] || 0);
164
+ })
165
+ .slice(0, 6)
166
+ .map((result) => ({ key: result.key, name: result.name, impact: result.impact, fix: result.fix }));
167
+ const packContext = selectPackContext(file.path, domainPackGuidance);
168
+ const familyMeta = resolveProposalFamily(file);
169
+
170
+ return {
171
+ id: familyMeta.id,
172
+ title: familyMeta.title,
173
+ module: familyMeta.module,
174
+ risk: familyMeta.risk,
175
+ confidence: familyMeta.confidence,
176
+ triggers,
177
+ rationale: uniqueValues([
178
+ ...triggers.map((item) => item.fix),
179
+ ...packContext.map((item) => `Supports ${item.label} rollout guidance: ${item.why}`),
180
+ ]),
181
+ packContext,
182
+ files: [{
183
+ path: file.path,
184
+ action: file.action,
185
+ currentState: file.currentState,
186
+ proposedState: file.proposedState,
187
+ content: file.content,
188
+ preview: file.content.split('\n').slice(0, 12).join('\n'),
189
+ diffPreview: [`--- missing`, `+++ ${file.path}`, ...file.content.split('\n').slice(0, 12).map((line) => `+${line}`)].join('\n'),
190
+ }],
191
+ readyToApply: true,
192
+ };
193
+ }
194
+
195
+ async function buildCursorProposalBundle(options) {
196
+ const auditResult = await audit({ ...options, platform: 'cursor', silent: true });
197
+ const analysisReport = await analyzeProject({ ...options, platform: 'cursor', mode: 'suggest-only' });
198
+ const domainPackGuidance = buildDomainPackGuidance(analysisReport);
199
+ const { files } = buildCursorSetupFiles(options);
200
+ const proposals = files.map((file) => proposalForFile(file, auditResult, domainPackGuidance));
201
+
202
+ // MCP preflight
203
+ const mcpProposal = proposals.find(p => p.id === 'cursor-mcp');
204
+ let mcpPreflightWarnings = [];
205
+ if (mcpProposal) {
206
+ const mcpFile = files.find(f => f.family === 'cursor-mcp');
207
+ if (mcpFile && mcpFile.content) {
208
+ let detectedKeys = [];
209
+ try {
210
+ const parsed = JSON.parse(mcpFile.content);
211
+ detectedKeys = Object.keys(parsed.mcpServers || parsed);
212
+ } catch {
213
+ const keyMatches = mcpFile.content.match(/"([^"]+)"\s*:/g) || [];
214
+ detectedKeys = keyMatches.map(m => m.replace(/[":]/g, '').trim());
215
+ }
216
+ mcpPreflightWarnings = getCursorMcpPreflight(detectedKeys)
217
+ .filter(p => !p.safe)
218
+ .map(p => ({ key: p.key, label: p.label, warning: p.warning }));
219
+ }
220
+ }
221
+
222
+ return {
223
+ schemaVersion: 2,
224
+ generatedBy: `nerviq@${version}`,
225
+ createdAt: new Date().toISOString(),
226
+ platform: 'cursor',
227
+ directory: options.dir,
228
+ projectSummary: {
229
+ name: path.basename(options.dir),
230
+ score: auditResult.score,
231
+ organicScore: auditResult.organicScore,
232
+ maturity: maturityFromScore(auditResult.score),
233
+ domains: analysisReport.projectSummary.domains || [],
234
+ },
235
+ strengthsPreserved: auditResult.results
236
+ .filter((item) => item.passed === true)
237
+ .slice(0, 5)
238
+ .map((item) => item.name),
239
+ topNextActions: auditResult.topNextActions,
240
+ recommendedDomainPacks: domainPackGuidance,
241
+ proposalFamilies: [...new Set(proposals.map(p => p.id))],
242
+ optionalModules: analysisReport.optionalModules || [],
243
+ riskNotes: uniqueValues([
244
+ ...(analysisReport.riskNotes || []),
245
+ ...((auditResult.platformCaveats || []).map((item) => item.message)),
246
+ ]),
247
+ mcpPreflightWarnings,
248
+ proposals,
249
+ };
250
+ }
251
+
252
+ module.exports = {
253
+ buildCursorProposalBundle,
254
+ };