@nerviq/cli 1.17.3 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/LICENSE +23 -23
  2. package/README.md +4 -4
  3. package/bin/cli.js +61 -274
  4. package/package.json +60 -60
  5. package/src/activity.js +1039 -1039
  6. package/src/adoption-advisor.js +299 -299
  7. package/src/aider/config-parser.js +166 -166
  8. package/src/aider/context.js +158 -158
  9. package/src/aider/deep-review.js +316 -316
  10. package/src/aider/domain-packs.js +303 -303
  11. package/src/aider/freshness.js +93 -93
  12. package/src/aider/governance.js +253 -253
  13. package/src/aider/interactive.js +334 -334
  14. package/src/aider/mcp-packs.js +329 -329
  15. package/src/aider/patch.js +214 -214
  16. package/src/aider/plans.js +186 -186
  17. package/src/aider/premium.js +360 -360
  18. package/src/aider/setup.js +404 -404
  19. package/src/aider/techniques.js +16 -16
  20. package/src/analyze.js +951 -951
  21. package/src/anti-patterns.js +485 -485
  22. package/src/audit/instruction-files.js +180 -180
  23. package/src/audit/recommendations.js +577 -577
  24. package/src/auto-suggest.js +154 -154
  25. package/src/badge.js +13 -13
  26. package/src/behavioral-drift.js +801 -801
  27. package/src/benchmark.js +67 -67
  28. package/src/catalog.js +103 -103
  29. package/src/certification.js +128 -128
  30. package/src/codex/config-parser.js +183 -183
  31. package/src/codex/context.js +223 -223
  32. package/src/codex/deep-review.js +493 -493
  33. package/src/codex/domain-packs.js +394 -394
  34. package/src/codex/freshness.js +84 -84
  35. package/src/codex/governance.js +192 -192
  36. package/src/codex/interactive.js +618 -618
  37. package/src/codex/mcp-packs.js +914 -914
  38. package/src/codex/patch.js +209 -209
  39. package/src/codex/plans.js +251 -251
  40. package/src/codex/premium.js +614 -614
  41. package/src/codex/setup.js +591 -591
  42. package/src/context.js +320 -320
  43. package/src/continuous-ops.js +681 -681
  44. package/src/copilot/activity.js +309 -309
  45. package/src/copilot/config-parser.js +280 -226
  46. package/src/copilot/context.js +218 -197
  47. package/src/copilot/deep-review.js +346 -346
  48. package/src/copilot/domain-packs.js +372 -372
  49. package/src/copilot/freshness.js +57 -57
  50. package/src/copilot/governance.js +222 -222
  51. package/src/copilot/interactive.js +406 -406
  52. package/src/copilot/mcp-packs.js +826 -826
  53. package/src/copilot/plans.js +253 -253
  54. package/src/copilot/premium.js +451 -451
  55. package/src/copilot/setup.js +488 -488
  56. package/src/copilot/techniques.js +219 -78
  57. package/src/cost-tracking.js +61 -61
  58. package/src/cursor/activity.js +301 -301
  59. package/src/cursor/config-parser.js +265 -265
  60. package/src/cursor/context.js +256 -256
  61. package/src/cursor/deep-review.js +334 -334
  62. package/src/cursor/domain-packs.js +368 -368
  63. package/src/cursor/freshness.js +65 -65
  64. package/src/cursor/governance.js +229 -229
  65. package/src/cursor/interactive.js +391 -391
  66. package/src/cursor/mcp-packs.js +828 -828
  67. package/src/cursor/plans.js +254 -254
  68. package/src/cursor/premium.js +469 -469
  69. package/src/cursor/setup.js +488 -488
  70. package/src/dashboard.js +493 -493
  71. package/src/deep-review.js +428 -428
  72. package/src/deprecation.js +98 -98
  73. package/src/diff-only.js +280 -280
  74. package/src/doctor.js +119 -119
  75. package/src/domain-pack-expansion.js +1033 -1033
  76. package/src/domain-packs.js +387 -387
  77. package/src/feedback.js +178 -178
  78. package/src/fix-engine.js +783 -0
  79. package/src/fix-prompts.js +122 -122
  80. package/src/formatters/sarif.js +115 -115
  81. package/src/freshness.js +74 -74
  82. package/src/gemini/config-parser.js +275 -275
  83. package/src/gemini/context.js +221 -221
  84. package/src/gemini/deep-review.js +559 -559
  85. package/src/gemini/domain-packs.js +393 -393
  86. package/src/gemini/freshness.js +66 -66
  87. package/src/gemini/governance.js +201 -201
  88. package/src/gemini/interactive.js +860 -860
  89. package/src/gemini/mcp-packs.js +915 -915
  90. package/src/gemini/plans.js +269 -269
  91. package/src/gemini/premium.js +760 -760
  92. package/src/gemini/setup.js +692 -692
  93. package/src/gemini/techniques.js +14 -14
  94. package/src/governance.js +72 -72
  95. package/src/harmony/add.js +68 -68
  96. package/src/harmony/advisor.js +333 -333
  97. package/src/harmony/canon.js +565 -565
  98. package/src/harmony/cli.js +591 -591
  99. package/src/harmony/drift.js +401 -401
  100. package/src/harmony/governance.js +313 -313
  101. package/src/harmony/memory.js +239 -239
  102. package/src/harmony/sync.js +475 -475
  103. package/src/harmony/watch.js +370 -370
  104. package/src/hook-validation.js +342 -342
  105. package/src/index.js +271 -271
  106. package/src/init.js +184 -184
  107. package/src/instruction-surfaces.js +185 -185
  108. package/src/integrations.js +144 -144
  109. package/src/interactive.js +118 -118
  110. package/src/locales/en.json +1 -1
  111. package/src/locales/es.json +1 -1
  112. package/src/mcp-packs.js +830 -830
  113. package/src/mcp-server.js +726 -726
  114. package/src/mcp-validation.js +337 -337
  115. package/src/nerviq-sync.json +7 -7
  116. package/src/opencode/config-parser.js +109 -109
  117. package/src/opencode/context.js +247 -247
  118. package/src/opencode/deep-review.js +313 -313
  119. package/src/opencode/domain-packs.js +262 -262
  120. package/src/opencode/freshness.js +66 -66
  121. package/src/opencode/governance.js +159 -159
  122. package/src/opencode/interactive.js +392 -392
  123. package/src/opencode/mcp-packs.js +705 -705
  124. package/src/opencode/patch.js +184 -184
  125. package/src/opencode/plans.js +231 -231
  126. package/src/opencode/premium.js +413 -413
  127. package/src/opencode/setup.js +449 -449
  128. package/src/opencode/techniques.js +27 -27
  129. package/src/operating-profile.js +574 -574
  130. package/src/org.js +152 -152
  131. package/src/permission-rules.js +218 -218
  132. package/src/plans.js +839 -839
  133. package/src/platform-change-manifest.js +86 -86
  134. package/src/plugins.js +110 -110
  135. package/src/policy-layers.js +210 -210
  136. package/src/profiles.js +124 -124
  137. package/src/prompt-injection.js +74 -74
  138. package/src/public-api.js +173 -173
  139. package/src/recommendation-rules.js +84 -84
  140. package/src/repo-archetype.js +386 -386
  141. package/src/secret-patterns.js +39 -39
  142. package/src/server.js +527 -527
  143. package/src/setup/analysis.js +607 -607
  144. package/src/setup/runtime.js +172 -172
  145. package/src/setup.js +677 -677
  146. package/src/shared/capabilities.js +194 -194
  147. package/src/source-urls.js +132 -132
  148. package/src/stack-checks.js +565 -565
  149. package/src/supplemental-checks.js +13 -13
  150. package/src/synergy/adaptive.js +261 -261
  151. package/src/synergy/compensation.js +137 -137
  152. package/src/synergy/evidence.js +193 -193
  153. package/src/synergy/learning.js +199 -199
  154. package/src/synergy/patterns.js +227 -227
  155. package/src/synergy/ranking.js +83 -83
  156. package/src/synergy/report.js +165 -165
  157. package/src/synergy/routing.js +146 -146
  158. package/src/techniques/api.js +407 -407
  159. package/src/techniques/automation.js +316 -316
  160. package/src/techniques/compliance.js +257 -257
  161. package/src/techniques/hygiene.js +294 -294
  162. package/src/techniques/instructions.js +243 -243
  163. package/src/techniques/observability.js +226 -226
  164. package/src/techniques/optimization.js +142 -142
  165. package/src/techniques/quality.js +318 -318
  166. package/src/techniques/security.js +237 -237
  167. package/src/techniques/shared.js +443 -443
  168. package/src/techniques/stacks.js +2294 -2294
  169. package/src/techniques/tools.js +106 -106
  170. package/src/techniques/workflow.js +413 -413
  171. package/src/techniques.js +81 -81
  172. package/src/terminology.js +73 -73
  173. package/src/token-estimate.js +35 -35
  174. package/src/usage-patterns.js +99 -99
  175. package/src/verification-metadata.js +145 -145
  176. package/src/watch.js +247 -247
  177. package/src/windsurf/activity.js +302 -302
  178. package/src/windsurf/config-parser.js +267 -267
  179. package/src/windsurf/context.js +249 -249
  180. package/src/windsurf/deep-review.js +337 -337
  181. package/src/windsurf/domain-packs.js +370 -370
  182. package/src/windsurf/freshness.js +36 -36
  183. package/src/windsurf/governance.js +231 -231
  184. package/src/windsurf/interactive.js +388 -388
  185. package/src/windsurf/mcp-packs.js +792 -792
  186. package/src/windsurf/plans.js +247 -247
  187. package/src/windsurf/premium.js +468 -468
  188. package/src/windsurf/setup.js +471 -471
  189. package/src/windsurf/techniques.js +17 -17
  190. package/src/workspace.js +375 -375
@@ -1,391 +1,391 @@
1
- /**
2
- * Cursor Interactive Wizard — 10-stage guided setup.
3
- *
4
- * Adapted for Cursor's 3-surface architecture (foreground, background, automations).
5
- *
6
- * Stages:
7
- * 1. Project detection (stacks, existing .cursor/, .cursorrules)
8
- * 2. Rule type selection (Always, Auto Attached, Agent Requested, Manual)
9
- * 3. Legacy migration (.cursorrules → .cursor/rules/)
10
- * 4. Background agent setup
11
- * 5. Domain pack selection
12
- * 6. MCP pack selection
13
- * 7. Automation config
14
- * 8. BugBot configuration
15
- * 9. Privacy & security
16
- * 10. Review & generate
17
- */
18
-
19
- const fs = require('fs');
20
- const os = require('os');
21
- const path = require('path');
22
- const readline = require('readline');
23
- const { STACKS } = require('../techniques');
24
- const { CursorProjectContext } = require('./context');
25
- const { CURSOR_TECHNIQUES } = require('./techniques');
26
- const { CURSOR_DOMAIN_PACKS, detectCursorDomainPacks } = require('./domain-packs');
27
- const { recommendCursorMcpPacks, CURSOR_MCP_PACKS } = require('./mcp-packs');
28
-
29
- const COLORS = {
30
- reset: '\x1b[0m', bold: '\x1b[1m', dim: '\x1b[2m',
31
- red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m',
32
- blue: '\x1b[36m', magenta: '\x1b[35m',
33
- };
34
- const c = (text, color) => `${COLORS[color] || ''}${text}${COLORS.reset}`;
35
-
36
- function ask(rl, question) {
37
- return new Promise(resolve => rl.question(question, resolve));
38
- }
39
-
40
- function isTTY() {
41
- return Boolean(process.stdin.isTTY && process.stdout.isTTY);
42
- }
43
-
44
- const STAGE_NAMES = [
45
- 'Project Detection',
46
- 'Rule Type Selection',
47
- 'Legacy Migration',
48
- 'Background Agent Setup',
49
- 'Domain Pack Selection',
50
- 'MCP Pack Selection',
51
- 'Automation Config',
52
- 'BugBot Configuration',
53
- 'Privacy & Security',
54
- 'Review & Generate',
55
- ];
56
-
57
- function printStageHeader(index) {
58
- console.log('');
59
- console.log(c(` ── Stage ${index + 1}/${STAGE_NAMES.length}: ${STAGE_NAMES[index]} ──`, 'magenta'));
60
- console.log('');
61
- }
62
-
63
- // --- Stage 1: Project Detection ---
64
-
65
- function runProjectDetection(ctx) {
66
- const stacks = ctx.detectStacks(STACKS);
67
- const rules = ctx.cursorRules ? ctx.cursorRules() : [];
68
- const hasLegacy = ctx.hasLegacyRules ? ctx.hasLegacyRules() : false;
69
- const hasMcpJson = ctx.mcpConfig().ok;
70
- const hasEnvJson = ctx.environmentJson().ok;
71
- const automations = ctx.automationsConfig ? ctx.automationsConfig() : [];
72
- const surfaces = ctx.detectSurfaces();
73
-
74
- const auditResults = [];
75
- for (const [key, technique] of Object.entries(CURSOR_TECHNIQUES)) {
76
- auditResults.push({ key, ...technique, passed: technique.check(ctx) });
77
- }
78
- const passed = auditResults.filter(r => r.passed === true);
79
- const failed = auditResults.filter(r => r.passed === false);
80
-
81
- return { stacks, rules, hasLegacy, hasMcpJson, hasEnvJson, automations, surfaces, auditResults, passed, failed };
82
- }
83
-
84
- async function stageProjectDetection(rl, ctx, state) {
85
- printStageHeader(0);
86
- const det = runProjectDetection(ctx);
87
- Object.assign(state, det);
88
-
89
- if (det.stacks.length > 0) console.log(c(` Detected stacks: ${det.stacks.map(s => s.label).join(', ')}`, 'blue'));
90
- else console.log(c(' No specific stack detected — will use baseline defaults.', 'dim'));
91
-
92
- console.log(c(` Working directory: ${ctx.dir}`, 'dim'));
93
- console.log('');
94
- console.log(` ${c(`${det.passed.length}/${det.auditResults.length}`, 'bold')} Cursor checks passing.`);
95
- console.log(` ${c(String(det.failed.length), 'yellow')} improvements available.`);
96
- console.log('');
97
- console.log(` Surfaces: FG ${det.surfaces.foreground ? c('Y', 'green') : c('N', 'red')} | BG ${det.surfaces.background ? c('Y', 'green') : c('N', 'red')} | Auto ${det.surfaces.automations ? c('Y', 'green') : c('N', 'red')}`);
98
- console.log(` Rules: ${det.rules.length} .mdc files${det.hasLegacy ? c(' + .cursorrules (IGNORED by agents!)', 'red') : ''}`);
99
-
100
- if (det.rules.length > 0 || det.hasLegacy) {
101
- console.log('');
102
- if (det.hasLegacy) console.log(c(' CRITICAL: .cursorrules found — this file is IGNORED by agent mode!', 'red'));
103
- if (det.rules.length > 0) console.log(c(` ${det.rules.length} .mdc rule files in .cursor/rules/`, 'dim'));
104
- if (det.hasMcpJson) console.log(c(' .cursor/mcp.json found', 'dim'));
105
- if (det.hasEnvJson) console.log(c(' .cursor/environment.json found', 'dim'));
106
- console.log('');
107
-
108
- const answer = await ask(rl, c(' Merge with existing config or replace? (merge/replace/quit) ', 'magenta'));
109
- const choice = answer.trim().toLowerCase();
110
- if (choice === 'quit' || choice === 'q') return 'quit';
111
- state.migrationMode = choice === 'replace' ? 'replace' : 'merge';
112
- } else {
113
- state.migrationMode = 'create';
114
- console.log('');
115
- console.log(c(' No existing Cursor rules — will create fresh setup.', 'dim'));
116
- }
117
-
118
- return 'next';
119
- }
120
-
121
- // --- Stage 2: Rule Type Selection ---
122
-
123
- async function stageRuleTypeSelection(rl, _ctx, state) {
124
- printStageHeader(1);
125
-
126
- console.log(' Cursor supports 4 rule types. Which do you want to generate?');
127
- console.log('');
128
- console.log(` ${c('1', 'bold')}. ${c('Always Apply only', 'blue')} — Core rules for every interaction.`);
129
- console.log(` ${c('2', 'bold')}. ${c('Always + Auto Attached', 'blue')} — Core + file-type-specific rules.`);
130
- console.log(` ${c('3', 'bold')}. ${c('Full set', 'blue')} — Always + Auto Attached + Agent Requested.`);
131
- console.log('');
132
-
133
- const answer = await ask(rl, c(' Choice (1-3, or b=back, q=quit) [2]: ', 'magenta'));
134
- const trimmed = answer.trim().toLowerCase();
135
- if (trimmed === 'b') return 'back';
136
- if (trimmed === 'q') return 'quit';
137
-
138
- const choice = parseInt(trimmed, 10);
139
- state.ruleTypes = ['always'];
140
- if (choice >= 2 || trimmed === '') state.ruleTypes.push('auto-attached');
141
- if (choice >= 3) state.ruleTypes.push('agent-requested');
142
-
143
- console.log(c(` → Rule types: ${state.ruleTypes.join(', ')}`, 'green'));
144
- return 'next';
145
- }
146
-
147
- // --- Stage 3: Legacy Migration ---
148
-
149
- async function stageLegacyMigration(rl, ctx, state) {
150
- if (!state.hasLegacy) return 'next';
151
-
152
- printStageHeader(2);
153
-
154
- console.log(c(' CRITICAL: .cursorrules file detected!', 'red'));
155
- console.log('');
156
- console.log(' Agent mode COMPLETELY IGNORES .cursorrules.');
157
- console.log(' Only .cursor/rules/*.mdc files with MDC frontmatter reach agents.');
158
- console.log('');
159
- console.log(` ${c('1', 'bold')}. ${c('Auto-migrate', 'blue')} — Convert .cursorrules content to .mdc format.`);
160
- console.log(` ${c('2', 'bold')}. ${c('Keep both', 'yellow')} — Generate new .mdc rules alongside .cursorrules.`);
161
- console.log(` ${c('3', 'bold')}. ${c('Skip', 'dim')} — Handle migration manually later.`);
162
- console.log('');
163
-
164
- const answer = await ask(rl, c(' Choice (1-3, or b=back, q=quit) [1]: ', 'magenta'));
165
- const trimmed = answer.trim().toLowerCase();
166
- if (trimmed === 'b') return 'back';
167
- if (trimmed === 'q') return 'quit';
168
-
169
- const choice = parseInt(trimmed, 10);
170
- state.legacyMigration = choice === 3 ? 'skip' : choice === 2 ? 'keep-both' : 'auto-migrate';
171
- console.log(c(` → Legacy migration: ${state.legacyMigration}`, 'green'));
172
- return 'next';
173
- }
174
-
175
- // --- Stage 4: Background Agent Setup ---
176
-
177
- async function stageBackgroundAgent(rl, _ctx, state) {
178
- printStageHeader(3);
179
-
180
- console.log(' Configure background agent environment?');
181
- console.log('');
182
- console.log(c(' Background agents run on ephemeral Ubuntu VMs.', 'dim'));
183
- console.log(c(' SECURITY: They have full home directory read access.', 'yellow'));
184
- console.log(c(' Privacy Mode must be DISABLED to use background agents.', 'yellow'));
185
- console.log('');
186
-
187
- const answer = await ask(rl, c(' Generate .cursor/environment.json? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
188
- const trimmed = answer.trim().toLowerCase();
189
- if (trimmed === 'b') return 'back';
190
- if (trimmed === 'q') return 'quit';
191
-
192
- state.generateEnvironment = trimmed !== 'n';
193
- console.log(c(` → Background agent: ${state.generateEnvironment ? 'will configure' : 'skip'}`, 'green'));
194
- return 'next';
195
- }
196
-
197
- // --- Stage 5: Domain Pack Selection ---
198
-
199
- async function stageDomainPacks(rl, ctx, state) {
200
- printStageHeader(4);
201
-
202
- const detected = detectCursorDomainPacks(ctx, state.stacks || []);
203
- state.domainPacks = detected;
204
-
205
- console.log(` Detected ${detected.length} domain pack(s):`);
206
- console.log('');
207
- detected.forEach((pack, i) => {
208
- console.log(` ${c(`${i + 1}`, 'bold')}. ${c(pack.label, 'blue')} — ${pack.matchReasons[0] || pack.useWhen}`);
209
- });
210
- console.log('');
211
-
212
- const answer = await ask(rl, c(' Accept detected packs? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
213
- const trimmed = answer.trim().toLowerCase();
214
- if (trimmed === 'b') return 'back';
215
- if (trimmed === 'q') return 'quit';
216
- if (trimmed === 'n') state.domainPacks = [];
217
-
218
- console.log(c(` → Domain packs: ${state.domainPacks.map(p => p.label).join(', ') || 'none'}`, 'green'));
219
- return 'next';
220
- }
221
-
222
- // --- Stage 6: MCP Pack Selection ---
223
-
224
- async function stageMcpPacks(rl, ctx, state) {
225
- printStageHeader(5);
226
-
227
- const backgroundOnly = state.generateEnvironment && !state.surfaces?.foreground;
228
- const recommended = recommendCursorMcpPacks(state.stacks || [], state.domainPacks || [], { ctx, backgroundOnly });
229
- state.mcpPacks = recommended;
230
-
231
- console.log(` Recommended ${recommended.length} MCP pack(s):`);
232
- console.log(c(` (Cursor hard limit: ~40 tools total — estimated: ~${recommended.length * 5} tools)`, 'yellow'));
233
- console.log('');
234
- recommended.forEach((pack, i) => {
235
- const bgIcon = pack.backgroundAgentCompatible === false ? c(' [FG only]', 'yellow') : '';
236
- console.log(` ${c(`${i + 1}`, 'bold')}. ${c(pack.label, 'blue')}${bgIcon} — ${pack.description}`);
237
- });
238
- console.log('');
239
-
240
- const answer = await ask(rl, c(' Accept recommended packs? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
241
- const trimmed = answer.trim().toLowerCase();
242
- if (trimmed === 'b') return 'back';
243
- if (trimmed === 'q') return 'quit';
244
- if (trimmed === 'n') state.mcpPacks = [];
245
-
246
- console.log(c(` → MCP packs: ${state.mcpPacks.map(p => p.label).join(', ') || 'none'}`, 'green'));
247
- return 'next';
248
- }
249
-
250
- // --- Stage 7: Automation Config ---
251
-
252
- async function stageAutomationConfig(rl, _ctx, state) {
253
- printStageHeader(6);
254
-
255
- console.log(' Configure event-driven automations?');
256
- console.log('');
257
- console.log(c(' Automations run WITHOUT human approval.', 'red'));
258
- console.log(c(' Supported triggers: cron, GitHub events, Slack, Linear, webhook, etc.', 'dim'));
259
- console.log(c(' Each run has a 30-minute cap and fresh container.', 'dim'));
260
- console.log('');
261
-
262
- const answer = await ask(rl, c(' Set up automations? (y/n, or b=back, q=quit) [n]: ', 'magenta'));
263
- const trimmed = answer.trim().toLowerCase();
264
- if (trimmed === 'b') return 'back';
265
- if (trimmed === 'q') return 'quit';
266
-
267
- state.generateAutomations = trimmed === 'y';
268
- console.log(c(` → Automations: ${state.generateAutomations ? 'will configure' : 'skip'}`, 'green'));
269
- return 'next';
270
- }
271
-
272
- // --- Stage 8: BugBot ---
273
-
274
- async function stageBugbot(rl, _ctx, state) {
275
- printStageHeader(7);
276
-
277
- console.log(' Configure BugBot for automated PR review?');
278
- console.log('');
279
- console.log(c(' BugBot processes 2M+ PRs/month. Can auto-fix >70% of issues.', 'dim'));
280
- console.log(c(' Pricing: $40/user/month for up to 200 PRs/month.', 'dim'));
281
- console.log('');
282
-
283
- const answer = await ask(rl, c(' Generate BugBot configuration guide? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
284
- const trimmed = answer.trim().toLowerCase();
285
- if (trimmed === 'b') return 'back';
286
- if (trimmed === 'q') return 'quit';
287
-
288
- state.generateBugbot = trimmed !== 'n';
289
- console.log(c(` → BugBot: ${state.generateBugbot ? 'will configure' : 'skip'}`, 'green'));
290
- return 'next';
291
- }
292
-
293
- // --- Stage 9: Privacy & Security ---
294
-
295
- async function stagePrivacySecurity(rl, _ctx, state) {
296
- printStageHeader(8);
297
-
298
- console.log(c(' IMPORTANT: Privacy Mode is OFF by default in Cursor!', 'red'));
299
- console.log('');
300
- console.log(' When Privacy Mode is off, your code is sent to model providers.');
301
- console.log(' Enable in: Cursor Settings > General > Privacy Mode');
302
- console.log('');
303
-
304
- const answer = await ask(rl, c(' Acknowledge privacy risk and continue? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
305
- const trimmed = answer.trim().toLowerCase();
306
- if (trimmed === 'b') return 'back';
307
- if (trimmed === 'q') return 'quit';
308
- if (trimmed === 'n') return 'quit';
309
-
310
- state.privacyAcknowledged = true;
311
- console.log(c(' → Privacy risk acknowledged. Remember to enable Privacy Mode for sensitive repos.', 'yellow'));
312
- return 'next';
313
- }
314
-
315
- // --- Stage 10: Review & Generate ---
316
-
317
- async function stageReviewGenerate(rl, _ctx, state) {
318
- printStageHeader(9);
319
-
320
- console.log(' Summary of your Cursor setup:');
321
- console.log('');
322
- console.log(` Rule types: ${(state.ruleTypes || []).join(', ')}`);
323
- console.log(` Legacy migration: ${state.legacyMigration || 'N/A'}`);
324
- console.log(` Background agent: ${state.generateEnvironment ? 'yes' : 'no'}`);
325
- console.log(` Domain packs: ${(state.domainPacks || []).map(p => p.label).join(', ') || 'none'}`);
326
- console.log(` MCP packs: ${(state.mcpPacks || []).map(p => p.label).join(', ') || 'none'}`);
327
- console.log(` Automations: ${state.generateAutomations ? 'yes' : 'no'}`);
328
- console.log(` BugBot: ${state.generateBugbot ? 'yes' : 'no'}`);
329
- console.log('');
330
-
331
- const answer = await ask(rl, c(' Generate files? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
332
- const trimmed = answer.trim().toLowerCase();
333
- if (trimmed === 'b') return 'back';
334
- if (trimmed === 'q') return 'quit';
335
- if (trimmed === 'n') return 'quit';
336
-
337
- state.confirmed = true;
338
- return 'done';
339
- }
340
-
341
- // --- Main Wizard ---
342
-
343
- const STAGES = [
344
- stageProjectDetection,
345
- stageRuleTypeSelection,
346
- stageLegacyMigration,
347
- stageBackgroundAgent,
348
- stageDomainPacks,
349
- stageMcpPacks,
350
- stageAutomationConfig,
351
- stageBugbot,
352
- stagePrivacySecurity,
353
- stageReviewGenerate,
354
- ];
355
-
356
- async function runCursorWizard(options) {
357
- if (!isTTY()) {
358
- console.log('Interactive wizard requires a TTY. Use --non-interactive or pipe mode instead.');
359
- return null;
360
- }
361
-
362
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
363
- const ctx = new CursorProjectContext(options.dir);
364
- const state = {};
365
-
366
- console.log('');
367
- console.log(c(' nerviq cursor interactive wizard', 'bold'));
368
- console.log(c(' ═══════════════════════════════════════', 'dim'));
369
-
370
- let stageIndex = 0;
371
-
372
- try {
373
- while (stageIndex < STAGES.length) {
374
- const result = await STAGES[stageIndex](rl, ctx, state);
375
- if (result === 'quit') { rl.close(); return null; }
376
- if (result === 'back') { stageIndex = Math.max(0, stageIndex - 1); continue; }
377
- if (result === 'done') break;
378
- stageIndex++;
379
- }
380
- } finally {
381
- rl.close();
382
- }
383
-
384
- if (!state.confirmed) return null;
385
- return state;
386
- }
387
-
388
- module.exports = {
389
- runCursorWizard,
390
- runProjectDetection,
391
- };
1
+ /**
2
+ * Cursor Interactive Wizard — 10-stage guided setup.
3
+ *
4
+ * Adapted for Cursor's 3-surface architecture (foreground, background, automations).
5
+ *
6
+ * Stages:
7
+ * 1. Project detection (stacks, existing .cursor/, .cursorrules)
8
+ * 2. Rule type selection (Always, Auto Attached, Agent Requested, Manual)
9
+ * 3. Legacy migration (.cursorrules → .cursor/rules/)
10
+ * 4. Background agent setup
11
+ * 5. Domain pack selection
12
+ * 6. MCP pack selection
13
+ * 7. Automation config
14
+ * 8. BugBot configuration
15
+ * 9. Privacy & security
16
+ * 10. Review & generate
17
+ */
18
+
19
+ const fs = require('fs');
20
+ const os = require('os');
21
+ const path = require('path');
22
+ const readline = require('readline');
23
+ const { STACKS } = require('../techniques');
24
+ const { CursorProjectContext } = require('./context');
25
+ const { CURSOR_TECHNIQUES } = require('./techniques');
26
+ const { CURSOR_DOMAIN_PACKS, detectCursorDomainPacks } = require('./domain-packs');
27
+ const { recommendCursorMcpPacks, CURSOR_MCP_PACKS } = require('./mcp-packs');
28
+
29
+ const COLORS = {
30
+ reset: '\x1b[0m', bold: '\x1b[1m', dim: '\x1b[2m',
31
+ red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m',
32
+ blue: '\x1b[36m', magenta: '\x1b[35m',
33
+ };
34
+ const c = (text, color) => `${COLORS[color] || ''}${text}${COLORS.reset}`;
35
+
36
+ function ask(rl, question) {
37
+ return new Promise(resolve => rl.question(question, resolve));
38
+ }
39
+
40
+ function isTTY() {
41
+ return Boolean(process.stdin.isTTY && process.stdout.isTTY);
42
+ }
43
+
44
+ const STAGE_NAMES = [
45
+ 'Project Detection',
46
+ 'Rule Type Selection',
47
+ 'Legacy Migration',
48
+ 'Background Agent Setup',
49
+ 'Domain Pack Selection',
50
+ 'MCP Pack Selection',
51
+ 'Automation Config',
52
+ 'BugBot Configuration',
53
+ 'Privacy & Security',
54
+ 'Review & Generate',
55
+ ];
56
+
57
+ function printStageHeader(index) {
58
+ console.log('');
59
+ console.log(c(` ── Stage ${index + 1}/${STAGE_NAMES.length}: ${STAGE_NAMES[index]} ──`, 'magenta'));
60
+ console.log('');
61
+ }
62
+
63
+ // --- Stage 1: Project Detection ---
64
+
65
+ function runProjectDetection(ctx) {
66
+ const stacks = ctx.detectStacks(STACKS);
67
+ const rules = ctx.cursorRules ? ctx.cursorRules() : [];
68
+ const hasLegacy = ctx.hasLegacyRules ? ctx.hasLegacyRules() : false;
69
+ const hasMcpJson = ctx.mcpConfig().ok;
70
+ const hasEnvJson = ctx.environmentJson().ok;
71
+ const automations = ctx.automationsConfig ? ctx.automationsConfig() : [];
72
+ const surfaces = ctx.detectSurfaces();
73
+
74
+ const auditResults = [];
75
+ for (const [key, technique] of Object.entries(CURSOR_TECHNIQUES)) {
76
+ auditResults.push({ key, ...technique, passed: technique.check(ctx) });
77
+ }
78
+ const passed = auditResults.filter(r => r.passed === true);
79
+ const failed = auditResults.filter(r => r.passed === false);
80
+
81
+ return { stacks, rules, hasLegacy, hasMcpJson, hasEnvJson, automations, surfaces, auditResults, passed, failed };
82
+ }
83
+
84
+ async function stageProjectDetection(rl, ctx, state) {
85
+ printStageHeader(0);
86
+ const det = runProjectDetection(ctx);
87
+ Object.assign(state, det);
88
+
89
+ if (det.stacks.length > 0) console.log(c(` Detected stacks: ${det.stacks.map(s => s.label).join(', ')}`, 'blue'));
90
+ else console.log(c(' No specific stack detected — will use baseline defaults.', 'dim'));
91
+
92
+ console.log(c(` Working directory: ${ctx.dir}`, 'dim'));
93
+ console.log('');
94
+ console.log(` ${c(`${det.passed.length}/${det.auditResults.length}`, 'bold')} Cursor checks passing.`);
95
+ console.log(` ${c(String(det.failed.length), 'yellow')} improvements available.`);
96
+ console.log('');
97
+ console.log(` Surfaces: FG ${det.surfaces.foreground ? c('Y', 'green') : c('N', 'red')} | BG ${det.surfaces.background ? c('Y', 'green') : c('N', 'red')} | Auto ${det.surfaces.automations ? c('Y', 'green') : c('N', 'red')}`);
98
+ console.log(` Rules: ${det.rules.length} .mdc files${det.hasLegacy ? c(' + .cursorrules (IGNORED by agents!)', 'red') : ''}`);
99
+
100
+ if (det.rules.length > 0 || det.hasLegacy) {
101
+ console.log('');
102
+ if (det.hasLegacy) console.log(c(' CRITICAL: .cursorrules found — this file is IGNORED by agent mode!', 'red'));
103
+ if (det.rules.length > 0) console.log(c(` ${det.rules.length} .mdc rule files in .cursor/rules/`, 'dim'));
104
+ if (det.hasMcpJson) console.log(c(' .cursor/mcp.json found', 'dim'));
105
+ if (det.hasEnvJson) console.log(c(' .cursor/environment.json found', 'dim'));
106
+ console.log('');
107
+
108
+ const answer = await ask(rl, c(' Merge with existing config or replace? (merge/replace/quit) ', 'magenta'));
109
+ const choice = answer.trim().toLowerCase();
110
+ if (choice === 'quit' || choice === 'q') return 'quit';
111
+ state.migrationMode = choice === 'replace' ? 'replace' : 'merge';
112
+ } else {
113
+ state.migrationMode = 'create';
114
+ console.log('');
115
+ console.log(c(' No existing Cursor rules — will create fresh setup.', 'dim'));
116
+ }
117
+
118
+ return 'next';
119
+ }
120
+
121
+ // --- Stage 2: Rule Type Selection ---
122
+
123
+ async function stageRuleTypeSelection(rl, _ctx, state) {
124
+ printStageHeader(1);
125
+
126
+ console.log(' Cursor supports 4 rule types. Which do you want to generate?');
127
+ console.log('');
128
+ console.log(` ${c('1', 'bold')}. ${c('Always Apply only', 'blue')} — Core rules for every interaction.`);
129
+ console.log(` ${c('2', 'bold')}. ${c('Always + Auto Attached', 'blue')} — Core + file-type-specific rules.`);
130
+ console.log(` ${c('3', 'bold')}. ${c('Full set', 'blue')} — Always + Auto Attached + Agent Requested.`);
131
+ console.log('');
132
+
133
+ const answer = await ask(rl, c(' Choice (1-3, or b=back, q=quit) [2]: ', 'magenta'));
134
+ const trimmed = answer.trim().toLowerCase();
135
+ if (trimmed === 'b') return 'back';
136
+ if (trimmed === 'q') return 'quit';
137
+
138
+ const choice = parseInt(trimmed, 10);
139
+ state.ruleTypes = ['always'];
140
+ if (choice >= 2 || trimmed === '') state.ruleTypes.push('auto-attached');
141
+ if (choice >= 3) state.ruleTypes.push('agent-requested');
142
+
143
+ console.log(c(` → Rule types: ${state.ruleTypes.join(', ')}`, 'green'));
144
+ return 'next';
145
+ }
146
+
147
+ // --- Stage 3: Legacy Migration ---
148
+
149
+ async function stageLegacyMigration(rl, ctx, state) {
150
+ if (!state.hasLegacy) return 'next';
151
+
152
+ printStageHeader(2);
153
+
154
+ console.log(c(' CRITICAL: .cursorrules file detected!', 'red'));
155
+ console.log('');
156
+ console.log(' Agent mode COMPLETELY IGNORES .cursorrules.');
157
+ console.log(' Only .cursor/rules/*.mdc files with MDC frontmatter reach agents.');
158
+ console.log('');
159
+ console.log(` ${c('1', 'bold')}. ${c('Auto-migrate', 'blue')} — Convert .cursorrules content to .mdc format.`);
160
+ console.log(` ${c('2', 'bold')}. ${c('Keep both', 'yellow')} — Generate new .mdc rules alongside .cursorrules.`);
161
+ console.log(` ${c('3', 'bold')}. ${c('Skip', 'dim')} — Handle migration manually later.`);
162
+ console.log('');
163
+
164
+ const answer = await ask(rl, c(' Choice (1-3, or b=back, q=quit) [1]: ', 'magenta'));
165
+ const trimmed = answer.trim().toLowerCase();
166
+ if (trimmed === 'b') return 'back';
167
+ if (trimmed === 'q') return 'quit';
168
+
169
+ const choice = parseInt(trimmed, 10);
170
+ state.legacyMigration = choice === 3 ? 'skip' : choice === 2 ? 'keep-both' : 'auto-migrate';
171
+ console.log(c(` → Legacy migration: ${state.legacyMigration}`, 'green'));
172
+ return 'next';
173
+ }
174
+
175
+ // --- Stage 4: Background Agent Setup ---
176
+
177
+ async function stageBackgroundAgent(rl, _ctx, state) {
178
+ printStageHeader(3);
179
+
180
+ console.log(' Configure background agent environment?');
181
+ console.log('');
182
+ console.log(c(' Background agents run on ephemeral Ubuntu VMs.', 'dim'));
183
+ console.log(c(' SECURITY: They have full home directory read access.', 'yellow'));
184
+ console.log(c(' Privacy Mode must be DISABLED to use background agents.', 'yellow'));
185
+ console.log('');
186
+
187
+ const answer = await ask(rl, c(' Generate .cursor/environment.json? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
188
+ const trimmed = answer.trim().toLowerCase();
189
+ if (trimmed === 'b') return 'back';
190
+ if (trimmed === 'q') return 'quit';
191
+
192
+ state.generateEnvironment = trimmed !== 'n';
193
+ console.log(c(` → Background agent: ${state.generateEnvironment ? 'will configure' : 'skip'}`, 'green'));
194
+ return 'next';
195
+ }
196
+
197
+ // --- Stage 5: Domain Pack Selection ---
198
+
199
+ async function stageDomainPacks(rl, ctx, state) {
200
+ printStageHeader(4);
201
+
202
+ const detected = detectCursorDomainPacks(ctx, state.stacks || []);
203
+ state.domainPacks = detected;
204
+
205
+ console.log(` Detected ${detected.length} domain pack(s):`);
206
+ console.log('');
207
+ detected.forEach((pack, i) => {
208
+ console.log(` ${c(`${i + 1}`, 'bold')}. ${c(pack.label, 'blue')} — ${pack.matchReasons[0] || pack.useWhen}`);
209
+ });
210
+ console.log('');
211
+
212
+ const answer = await ask(rl, c(' Accept detected packs? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
213
+ const trimmed = answer.trim().toLowerCase();
214
+ if (trimmed === 'b') return 'back';
215
+ if (trimmed === 'q') return 'quit';
216
+ if (trimmed === 'n') state.domainPacks = [];
217
+
218
+ console.log(c(` → Domain packs: ${state.domainPacks.map(p => p.label).join(', ') || 'none'}`, 'green'));
219
+ return 'next';
220
+ }
221
+
222
+ // --- Stage 6: MCP Pack Selection ---
223
+
224
+ async function stageMcpPacks(rl, ctx, state) {
225
+ printStageHeader(5);
226
+
227
+ const backgroundOnly = state.generateEnvironment && !state.surfaces?.foreground;
228
+ const recommended = recommendCursorMcpPacks(state.stacks || [], state.domainPacks || [], { ctx, backgroundOnly });
229
+ state.mcpPacks = recommended;
230
+
231
+ console.log(` Recommended ${recommended.length} MCP pack(s):`);
232
+ console.log(c(` (Cursor hard limit: ~40 tools total — estimated: ~${recommended.length * 5} tools)`, 'yellow'));
233
+ console.log('');
234
+ recommended.forEach((pack, i) => {
235
+ const bgIcon = pack.backgroundAgentCompatible === false ? c(' [FG only]', 'yellow') : '';
236
+ console.log(` ${c(`${i + 1}`, 'bold')}. ${c(pack.label, 'blue')}${bgIcon} — ${pack.description}`);
237
+ });
238
+ console.log('');
239
+
240
+ const answer = await ask(rl, c(' Accept recommended packs? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
241
+ const trimmed = answer.trim().toLowerCase();
242
+ if (trimmed === 'b') return 'back';
243
+ if (trimmed === 'q') return 'quit';
244
+ if (trimmed === 'n') state.mcpPacks = [];
245
+
246
+ console.log(c(` → MCP packs: ${state.mcpPacks.map(p => p.label).join(', ') || 'none'}`, 'green'));
247
+ return 'next';
248
+ }
249
+
250
+ // --- Stage 7: Automation Config ---
251
+
252
+ async function stageAutomationConfig(rl, _ctx, state) {
253
+ printStageHeader(6);
254
+
255
+ console.log(' Configure event-driven automations?');
256
+ console.log('');
257
+ console.log(c(' Automations run WITHOUT human approval.', 'red'));
258
+ console.log(c(' Supported triggers: cron, GitHub events, Slack, Linear, webhook, etc.', 'dim'));
259
+ console.log(c(' Each run has a 30-minute cap and fresh container.', 'dim'));
260
+ console.log('');
261
+
262
+ const answer = await ask(rl, c(' Set up automations? (y/n, or b=back, q=quit) [n]: ', 'magenta'));
263
+ const trimmed = answer.trim().toLowerCase();
264
+ if (trimmed === 'b') return 'back';
265
+ if (trimmed === 'q') return 'quit';
266
+
267
+ state.generateAutomations = trimmed === 'y';
268
+ console.log(c(` → Automations: ${state.generateAutomations ? 'will configure' : 'skip'}`, 'green'));
269
+ return 'next';
270
+ }
271
+
272
+ // --- Stage 8: BugBot ---
273
+
274
+ async function stageBugbot(rl, _ctx, state) {
275
+ printStageHeader(7);
276
+
277
+ console.log(' Configure BugBot for automated PR review?');
278
+ console.log('');
279
+ console.log(c(' BugBot processes 2M+ PRs/month. Can auto-fix >70% of issues.', 'dim'));
280
+ console.log(c(' Pricing: $40/user/month for up to 200 PRs/month.', 'dim'));
281
+ console.log('');
282
+
283
+ const answer = await ask(rl, c(' Generate BugBot configuration guide? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
284
+ const trimmed = answer.trim().toLowerCase();
285
+ if (trimmed === 'b') return 'back';
286
+ if (trimmed === 'q') return 'quit';
287
+
288
+ state.generateBugbot = trimmed !== 'n';
289
+ console.log(c(` → BugBot: ${state.generateBugbot ? 'will configure' : 'skip'}`, 'green'));
290
+ return 'next';
291
+ }
292
+
293
+ // --- Stage 9: Privacy & Security ---
294
+
295
+ async function stagePrivacySecurity(rl, _ctx, state) {
296
+ printStageHeader(8);
297
+
298
+ console.log(c(' IMPORTANT: Privacy Mode is OFF by default in Cursor!', 'red'));
299
+ console.log('');
300
+ console.log(' When Privacy Mode is off, your code is sent to model providers.');
301
+ console.log(' Enable in: Cursor Settings > General > Privacy Mode');
302
+ console.log('');
303
+
304
+ const answer = await ask(rl, c(' Acknowledge privacy risk and continue? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
305
+ const trimmed = answer.trim().toLowerCase();
306
+ if (trimmed === 'b') return 'back';
307
+ if (trimmed === 'q') return 'quit';
308
+ if (trimmed === 'n') return 'quit';
309
+
310
+ state.privacyAcknowledged = true;
311
+ console.log(c(' → Privacy risk acknowledged. Remember to enable Privacy Mode for sensitive repos.', 'yellow'));
312
+ return 'next';
313
+ }
314
+
315
+ // --- Stage 10: Review & Generate ---
316
+
317
+ async function stageReviewGenerate(rl, _ctx, state) {
318
+ printStageHeader(9);
319
+
320
+ console.log(' Summary of your Cursor setup:');
321
+ console.log('');
322
+ console.log(` Rule types: ${(state.ruleTypes || []).join(', ')}`);
323
+ console.log(` Legacy migration: ${state.legacyMigration || 'N/A'}`);
324
+ console.log(` Background agent: ${state.generateEnvironment ? 'yes' : 'no'}`);
325
+ console.log(` Domain packs: ${(state.domainPacks || []).map(p => p.label).join(', ') || 'none'}`);
326
+ console.log(` MCP packs: ${(state.mcpPacks || []).map(p => p.label).join(', ') || 'none'}`);
327
+ console.log(` Automations: ${state.generateAutomations ? 'yes' : 'no'}`);
328
+ console.log(` BugBot: ${state.generateBugbot ? 'yes' : 'no'}`);
329
+ console.log('');
330
+
331
+ const answer = await ask(rl, c(' Generate files? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
332
+ const trimmed = answer.trim().toLowerCase();
333
+ if (trimmed === 'b') return 'back';
334
+ if (trimmed === 'q') return 'quit';
335
+ if (trimmed === 'n') return 'quit';
336
+
337
+ state.confirmed = true;
338
+ return 'done';
339
+ }
340
+
341
+ // --- Main Wizard ---
342
+
343
+ const STAGES = [
344
+ stageProjectDetection,
345
+ stageRuleTypeSelection,
346
+ stageLegacyMigration,
347
+ stageBackgroundAgent,
348
+ stageDomainPacks,
349
+ stageMcpPacks,
350
+ stageAutomationConfig,
351
+ stageBugbot,
352
+ stagePrivacySecurity,
353
+ stageReviewGenerate,
354
+ ];
355
+
356
+ async function runCursorWizard(options) {
357
+ if (!isTTY()) {
358
+ console.log('Interactive wizard requires a TTY. Use --non-interactive or pipe mode instead.');
359
+ return null;
360
+ }
361
+
362
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
363
+ const ctx = new CursorProjectContext(options.dir);
364
+ const state = {};
365
+
366
+ console.log('');
367
+ console.log(c(' nerviq cursor interactive wizard', 'bold'));
368
+ console.log(c(' ═══════════════════════════════════════', 'dim'));
369
+
370
+ let stageIndex = 0;
371
+
372
+ try {
373
+ while (stageIndex < STAGES.length) {
374
+ const result = await STAGES[stageIndex](rl, ctx, state);
375
+ if (result === 'quit') { rl.close(); return null; }
376
+ if (result === 'back') { stageIndex = Math.max(0, stageIndex - 1); continue; }
377
+ if (result === 'done') break;
378
+ stageIndex++;
379
+ }
380
+ } finally {
381
+ rl.close();
382
+ }
383
+
384
+ if (!state.confirmed) return null;
385
+ return state;
386
+ }
387
+
388
+ module.exports = {
389
+ runCursorWizard,
390
+ runProjectDetection,
391
+ };