@nerviq/cli 1.20.1 → 1.22.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 (186) hide show
  1. package/LICENSE +23 -23
  2. package/README.md +20 -2
  3. package/bin/cli.js +3 -3
  4. package/package.json +1 -1
  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 +4 -1
  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 +312 -67
  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/audit.js +20 -0
  25. package/src/auto-suggest.js +154 -154
  26. package/src/badge.js +13 -13
  27. package/src/behavioral-drift.js +801 -801
  28. package/src/benchmark.js +67 -67
  29. package/src/catalog.js +103 -103
  30. package/src/certification.js +128 -128
  31. package/src/codex/config-parser.js +183 -183
  32. package/src/codex/context.js +223 -223
  33. package/src/codex/deep-review.js +493 -493
  34. package/src/codex/domain-packs.js +394 -394
  35. package/src/codex/freshness.js +84 -84
  36. package/src/codex/governance.js +192 -192
  37. package/src/codex/interactive.js +618 -618
  38. package/src/codex/mcp-packs.js +914 -914
  39. package/src/codex/patch.js +209 -209
  40. package/src/codex/plans.js +251 -251
  41. package/src/codex/premium.js +614 -614
  42. package/src/codex/setup.js +591 -591
  43. package/src/continuous-ops.js +681 -681
  44. package/src/copilot/activity.js +309 -309
  45. package/src/copilot/deep-review.js +346 -346
  46. package/src/copilot/domain-packs.js +372 -372
  47. package/src/copilot/freshness.js +57 -57
  48. package/src/copilot/governance.js +222 -222
  49. package/src/copilot/interactive.js +406 -406
  50. package/src/copilot/mcp-packs.js +826 -826
  51. package/src/copilot/plans.js +253 -253
  52. package/src/copilot/premium.js +451 -451
  53. package/src/copilot/setup.js +488 -488
  54. package/src/cost-tracking.js +61 -61
  55. package/src/cursor/activity.js +301 -301
  56. package/src/cursor/config-parser.js +265 -265
  57. package/src/cursor/context.js +256 -256
  58. package/src/cursor/deep-review.js +334 -334
  59. package/src/cursor/domain-packs.js +368 -368
  60. package/src/cursor/freshness.js +65 -65
  61. package/src/cursor/governance.js +229 -229
  62. package/src/cursor/interactive.js +391 -391
  63. package/src/cursor/mcp-packs.js +828 -828
  64. package/src/cursor/plans.js +254 -254
  65. package/src/cursor/premium.js +469 -469
  66. package/src/cursor/setup.js +488 -488
  67. package/src/dashboard.js +493 -493
  68. package/src/deep-review.js +428 -428
  69. package/src/deprecation.js +98 -98
  70. package/src/diff-only.js +280 -280
  71. package/src/doctor.js +119 -119
  72. package/src/domain-pack-expansion.js +1033 -1033
  73. package/src/domain-packs.js +387 -387
  74. package/src/feedback.js +178 -178
  75. package/src/fix-engine.js +783 -783
  76. package/src/fix-prompts.js +122 -122
  77. package/src/formatters/csv.js +69 -0
  78. package/src/formatters/junit.js +99 -0
  79. package/src/formatters/markdown.js +118 -0
  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/deep-review.js +559 -559
  84. package/src/gemini/domain-packs.js +393 -393
  85. package/src/gemini/freshness.js +66 -66
  86. package/src/gemini/governance.js +201 -201
  87. package/src/gemini/interactive.js +860 -860
  88. package/src/gemini/mcp-packs.js +915 -915
  89. package/src/gemini/plans.js +269 -269
  90. package/src/gemini/premium.js +760 -760
  91. package/src/gemini/setup.js +692 -692
  92. package/src/governance.js +72 -72
  93. package/src/harmony/add.js +68 -68
  94. package/src/harmony/advisor.js +333 -333
  95. package/src/harmony/canon.js +565 -565
  96. package/src/harmony/cli.js +591 -591
  97. package/src/harmony/drift.js +401 -401
  98. package/src/harmony/governance.js +313 -313
  99. package/src/harmony/memory.js +239 -239
  100. package/src/harmony/sync.js +475 -475
  101. package/src/harmony/watch.js +370 -370
  102. package/src/hook-validation.js +342 -342
  103. package/src/index.js +271 -271
  104. package/src/init.js +184 -184
  105. package/src/instruction-surfaces.js +185 -185
  106. package/src/integrations.js +144 -144
  107. package/src/interactive.js +118 -118
  108. package/src/locales/en.json +1 -1
  109. package/src/locales/es.json +1 -1
  110. package/src/mcp-packs.js +830 -830
  111. package/src/mcp-server.js +726 -726
  112. package/src/mcp-validation.js +337 -337
  113. package/src/nerviq-sync.json +7 -7
  114. package/src/opencode/config-parser.js +109 -109
  115. package/src/opencode/context.js +247 -247
  116. package/src/opencode/deep-review.js +313 -313
  117. package/src/opencode/domain-packs.js +262 -262
  118. package/src/opencode/freshness.js +66 -66
  119. package/src/opencode/governance.js +159 -159
  120. package/src/opencode/interactive.js +392 -392
  121. package/src/opencode/mcp-packs.js +705 -705
  122. package/src/opencode/patch.js +184 -184
  123. package/src/opencode/plans.js +231 -231
  124. package/src/opencode/premium.js +413 -413
  125. package/src/opencode/setup.js +449 -449
  126. package/src/opencode/techniques.js +27 -27
  127. package/src/operating-profile.js +574 -574
  128. package/src/org.js +152 -152
  129. package/src/permission-rules.js +218 -218
  130. package/src/plans.js +839 -839
  131. package/src/platform-change-manifest.js +86 -86
  132. package/src/plugins.js +110 -110
  133. package/src/policy-layers.js +210 -210
  134. package/src/profiles.js +124 -124
  135. package/src/prompt-injection.js +74 -74
  136. package/src/public-api.js +173 -173
  137. package/src/recommendation-rules.js +84 -84
  138. package/src/repo-archetype.js +386 -386
  139. package/src/secret-patterns.js +39 -39
  140. package/src/server.js +527 -527
  141. package/src/setup/analysis.js +607 -607
  142. package/src/setup/runtime.js +172 -172
  143. package/src/setup.js +677 -677
  144. package/src/shared/capabilities.js +194 -194
  145. package/src/source-urls.js +132 -132
  146. package/src/stack-checks.js +565 -565
  147. package/src/supplemental-checks.js +13 -13
  148. package/src/synergy/adaptive.js +261 -261
  149. package/src/synergy/compensation.js +137 -137
  150. package/src/synergy/evidence.js +193 -193
  151. package/src/synergy/learning.js +199 -199
  152. package/src/synergy/patterns.js +227 -227
  153. package/src/synergy/ranking.js +83 -83
  154. package/src/synergy/report.js +165 -165
  155. package/src/synergy/routing.js +146 -146
  156. package/src/techniques/api.js +407 -407
  157. package/src/techniques/automation.js +316 -316
  158. package/src/techniques/compliance.js +257 -257
  159. package/src/techniques/hygiene.js +294 -294
  160. package/src/techniques/instructions.js +243 -243
  161. package/src/techniques/observability.js +226 -226
  162. package/src/techniques/optimization.js +142 -142
  163. package/src/techniques/quality.js +318 -318
  164. package/src/techniques/security.js +237 -237
  165. package/src/techniques/shared.js +443 -443
  166. package/src/techniques/stacks.js +2294 -2294
  167. package/src/techniques/tools.js +106 -106
  168. package/src/techniques/workflow.js +413 -413
  169. package/src/techniques.js +81 -81
  170. package/src/terminology.js +73 -73
  171. package/src/token-estimate.js +35 -35
  172. package/src/usage-patterns.js +99 -99
  173. package/src/verification-metadata.js +145 -145
  174. package/src/watch.js +247 -247
  175. package/src/windsurf/activity.js +302 -302
  176. package/src/windsurf/config-parser.js +267 -267
  177. package/src/windsurf/deep-review.js +337 -337
  178. package/src/windsurf/domain-packs.js +370 -370
  179. package/src/windsurf/freshness.js +36 -36
  180. package/src/windsurf/governance.js +231 -231
  181. package/src/windsurf/interactive.js +388 -388
  182. package/src/windsurf/mcp-packs.js +792 -792
  183. package/src/windsurf/plans.js +247 -247
  184. package/src/windsurf/premium.js +468 -468
  185. package/src/windsurf/setup.js +471 -471
  186. package/src/workspace.js +375 -375
@@ -1,388 +1,388 @@
1
- /**
2
- * Windsurf Interactive Wizard — 10-stage guided setup.
3
- *
4
- * Adapted for Windsurf's architecture (foreground Cascade, memories, workflows).
5
- *
6
- * Stages:
7
- * 1. Project detection (stacks, existing .windsurf/, .windsurfrules)
8
- * 2. Rule type selection (Always, Auto, Agent-Requested, Manual)
9
- * 3. Legacy migration (.windsurfrules -> .windsurf/rules/)
10
- * 4. Cascadeignore setup
11
- * 5. Domain pack selection
12
- * 6. MCP pack selection
13
- * 7. Workflow config
14
- * 8. Memories config
15
- * 9. Team & 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 { WindsurfProjectContext } = require('./context');
25
- const { WINDSURF_TECHNIQUES } = require('./techniques');
26
- const { WINDSURF_DOMAIN_PACKS, detectWindsurfDomainPacks } = require('./domain-packs');
27
- const { recommendWindsurfMcpPacks, WINDSURF_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
- 'Cascadeignore Setup',
49
- 'Domain Pack Selection',
50
- 'MCP Pack Selection',
51
- 'Workflow Config',
52
- 'Memories Config',
53
- 'Team & 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.windsurfRules ? ctx.windsurfRules() : [];
68
- const hasLegacy = ctx.hasLegacyRules ? ctx.hasLegacyRules() : false;
69
- const hasMcpJson = ctx.mcpConfig().ok;
70
- const workflows = ctx.workflowFiles ? ctx.workflowFiles() : [];
71
- const memories = ctx.memoryFiles ? ctx.memoryFiles() : [];
72
- const hasCascadeignore = ctx.hasCascadeignore ? ctx.hasCascadeignore() : false;
73
- const surfaces = ctx.detectSurfaces();
74
-
75
- const auditResults = [];
76
- for (const [key, technique] of Object.entries(WINDSURF_TECHNIQUES)) {
77
- auditResults.push({ key, ...technique, passed: technique.check(ctx) });
78
- }
79
- const passed = auditResults.filter(r => r.passed === true);
80
- const failed = auditResults.filter(r => r.passed === false);
81
-
82
- return { stacks, rules, hasLegacy, hasMcpJson, workflows, memories, hasCascadeignore, surfaces, auditResults, passed, failed };
83
- }
84
-
85
- async function stageProjectDetection(rl, ctx, state) {
86
- printStageHeader(0);
87
- const det = runProjectDetection(ctx);
88
- Object.assign(state, det);
89
-
90
- if (det.stacks.length > 0) console.log(c(` Detected stacks: ${det.stacks.map(s => s.label).join(', ')}`, 'blue'));
91
- else console.log(c(' No specific stack detected — will use baseline defaults.', 'dim'));
92
-
93
- console.log(c(` Working directory: ${ctx.dir}`, 'dim'));
94
- console.log('');
95
- console.log(` ${c(`${det.passed.length}/${det.auditResults.length}`, 'bold')} Windsurf checks passing.`);
96
- console.log(` ${c(String(det.failed.length), 'yellow')} improvements available.`);
97
- console.log('');
98
- console.log(` Surfaces: FG ${det.surfaces.foreground ? c('Y', 'green') : c('N', 'red')} | WF ${det.surfaces.workflows ? c('Y', 'green') : c('N', 'red')} | Mem ${det.surfaces.memories ? c('Y', 'green') : c('N', 'red')} | CI ${det.hasCascadeignore ? c('Y', 'green') : c('N', 'red')}`);
99
- console.log(` Rules: ${det.rules.length} .md files${det.hasLegacy ? c(' + .windsurfrules (legacy!)', 'red') : ''}`);
100
-
101
- if (det.rules.length > 0 || det.hasLegacy) {
102
- console.log('');
103
- if (det.hasLegacy) console.log(c(' WARNING: .windsurfrules found — this is the legacy format!', 'red'));
104
- if (det.rules.length > 0) console.log(c(` ${det.rules.length} .md rule files in .windsurf/rules/`, 'dim'));
105
- if (det.hasMcpJson) console.log(c(' .windsurf/mcp.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 Windsurf 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(' Windsurf supports 4 rule activation modes. Which do you want to generate?');
127
- console.log('');
128
- console.log(` ${c('1', 'bold')}. ${c('Always only', 'blue')} — Core rules for every Cascade interaction.`);
129
- console.log(` ${c('2', 'bold')}. ${c('Always + Auto', 'blue')} — Core + file-type-specific rules.`);
130
- console.log(` ${c('3', 'bold')}. ${c('Full set', 'blue')} — Always + Auto + 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');
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(' WARNING: .windsurfrules file detected!', 'red'));
155
- console.log('');
156
- console.log(' The .windsurfrules file is the legacy format.');
157
- console.log(' Migrate to .windsurf/rules/*.md with YAML frontmatter for best results.');
158
- console.log('');
159
- console.log(` ${c('1', 'bold')}. ${c('Auto-migrate', 'blue')} — Convert .windsurfrules content to .md format.`);
160
- console.log(` ${c('2', 'bold')}. ${c('Keep both', 'yellow')} — Generate new .md rules alongside .windsurfrules.`);
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: Cascadeignore Setup ---
176
-
177
- async function stageCascadeignore(rl, _ctx, state) {
178
- printStageHeader(3);
179
-
180
- console.log(' Configure .cascadeignore for sensitive file exclusion?');
181
- console.log('');
182
- console.log(c(' .cascadeignore uses gitignore syntax to prevent Cascade from accessing files.', 'dim'));
183
- console.log(c(' Recommended patterns: .env, secrets/, credentials/, .aws/, .ssh/', 'dim'));
184
- console.log('');
185
-
186
- const answer = await ask(rl, c(' Generate .cascadeignore? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
187
- const trimmed = answer.trim().toLowerCase();
188
- if (trimmed === 'b') return 'back';
189
- if (trimmed === 'q') return 'quit';
190
-
191
- state.generateCascadeignore = trimmed !== 'n';
192
- console.log(c(` → Cascadeignore: ${state.generateCascadeignore ? 'will configure' : 'skip'}`, 'green'));
193
- return 'next';
194
- }
195
-
196
- // --- Stage 5: Domain Pack Selection ---
197
-
198
- async function stageDomainPacks(rl, ctx, state) {
199
- printStageHeader(4);
200
-
201
- const detected = detectWindsurfDomainPacks(ctx, state.stacks || []);
202
- state.domainPacks = detected;
203
-
204
- console.log(` Detected ${detected.length} domain pack(s):`);
205
- console.log('');
206
- detected.forEach((pack, i) => {
207
- console.log(` ${c(`${i + 1}`, 'bold')}. ${c(pack.label, 'blue')} — ${pack.matchReasons[0] || pack.useWhen}`);
208
- });
209
- console.log('');
210
-
211
- const answer = await ask(rl, c(' Accept detected packs? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
212
- const trimmed = answer.trim().toLowerCase();
213
- if (trimmed === 'b') return 'back';
214
- if (trimmed === 'q') return 'quit';
215
- if (trimmed === 'n') state.domainPacks = [];
216
-
217
- console.log(c(` → Domain packs: ${state.domainPacks.map(p => p.label).join(', ') || 'none'}`, 'green'));
218
- return 'next';
219
- }
220
-
221
- // --- Stage 6: MCP Pack Selection ---
222
-
223
- async function stageMcpPacks(rl, ctx, state) {
224
- printStageHeader(5);
225
-
226
- const recommended = recommendWindsurfMcpPacks(state.stacks || [], state.domainPacks || [], { ctx });
227
- state.mcpPacks = recommended;
228
-
229
- console.log(` Recommended ${recommended.length} MCP pack(s):`);
230
- console.log('');
231
- recommended.forEach((pack, i) => {
232
- console.log(` ${c(`${i + 1}`, 'bold')}. ${c(pack.label, 'blue')} — ${pack.description}`);
233
- });
234
- console.log('');
235
-
236
- const answer = await ask(rl, c(' Accept recommended packs? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
237
- const trimmed = answer.trim().toLowerCase();
238
- if (trimmed === 'b') return 'back';
239
- if (trimmed === 'q') return 'quit';
240
- if (trimmed === 'n') state.mcpPacks = [];
241
-
242
- console.log(c(` → MCP packs: ${state.mcpPacks.map(p => p.label).join(', ') || 'none'}`, 'green'));
243
- return 'next';
244
- }
245
-
246
- // --- Stage 7: Workflow Config ---
247
-
248
- async function stageWorkflowConfig(rl, _ctx, state) {
249
- printStageHeader(6);
250
-
251
- console.log(' Configure Windsurf workflows (slash commands)?');
252
- console.log('');
253
- console.log(c(' Workflows define reusable slash commands for Cascade.', 'dim'));
254
- console.log(c(' Stored in .windsurf/workflows/*.md', 'dim'));
255
- console.log('');
256
-
257
- const answer = await ask(rl, c(' Set up starter workflows? (y/n, or b=back, q=quit) [n]: ', 'magenta'));
258
- const trimmed = answer.trim().toLowerCase();
259
- if (trimmed === 'b') return 'back';
260
- if (trimmed === 'q') return 'quit';
261
-
262
- state.generateWorkflows = trimmed === 'y';
263
- console.log(c(` → Workflows: ${state.generateWorkflows ? 'will configure' : 'skip'}`, 'green'));
264
- return 'next';
265
- }
266
-
267
- // --- Stage 8: Memories Config ---
268
-
269
- async function stageMemoriesConfig(rl, _ctx, state) {
270
- printStageHeader(7);
271
-
272
- console.log(' Configure Windsurf memories (persistent context)?');
273
- console.log('');
274
- console.log(c(' Memories provide persistent context that syncs across team members.', 'dim'));
275
- console.log(c(' IMPORTANT: Never put secrets or PII in memories — they sync to all team members!', 'yellow'));
276
- console.log('');
277
-
278
- const answer = await ask(rl, c(' Generate starter memories? (y/n, or b=back, q=quit) [n]: ', 'magenta'));
279
- const trimmed = answer.trim().toLowerCase();
280
- if (trimmed === 'b') return 'back';
281
- if (trimmed === 'q') return 'quit';
282
-
283
- state.generateMemories = trimmed === 'y';
284
- console.log(c(` → Memories: ${state.generateMemories ? 'will configure' : 'skip'}`, 'green'));
285
- return 'next';
286
- }
287
-
288
- // --- Stage 9: Team & Security ---
289
-
290
- async function stageTeamSecurity(rl, _ctx, state) {
291
- printStageHeader(8);
292
-
293
- console.log(' Review team and security considerations:');
294
- console.log('');
295
- console.log(c(' 1. Memories sync across team — check for secrets/PII', 'yellow'));
296
- console.log(c(' 2. MCP servers can be whitelisted at team level', 'dim'));
297
- console.log(c(' 3. .cascadeignore protects sensitive files from Cascade', 'dim'));
298
- console.log(c(' 4. Each rule file has a 10K character limit', 'dim'));
299
- console.log('');
300
-
301
- const answer = await ask(rl, c(' Acknowledge team/security considerations? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
302
- const trimmed = answer.trim().toLowerCase();
303
- if (trimmed === 'b') return 'back';
304
- if (trimmed === 'q') return 'quit';
305
- if (trimmed === 'n') return 'quit';
306
-
307
- state.securityAcknowledged = true;
308
- console.log(c(' → Team/security considerations acknowledged.', 'yellow'));
309
- return 'next';
310
- }
311
-
312
- // --- Stage 10: Review & Generate ---
313
-
314
- async function stageReviewGenerate(rl, _ctx, state) {
315
- printStageHeader(9);
316
-
317
- console.log(' Summary of your Windsurf setup:');
318
- console.log('');
319
- console.log(` Rule types: ${(state.ruleTypes || []).join(', ')}`);
320
- console.log(` Legacy migration: ${state.legacyMigration || 'N/A'}`);
321
- console.log(` Cascadeignore: ${state.generateCascadeignore ? 'yes' : 'no'}`);
322
- console.log(` Domain packs: ${(state.domainPacks || []).map(p => p.label).join(', ') || 'none'}`);
323
- console.log(` MCP packs: ${(state.mcpPacks || []).map(p => p.label).join(', ') || 'none'}`);
324
- console.log(` Workflows: ${state.generateWorkflows ? 'yes' : 'no'}`);
325
- console.log(` Memories: ${state.generateMemories ? 'yes' : 'no'}`);
326
- console.log('');
327
-
328
- const answer = await ask(rl, c(' Generate files? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
329
- const trimmed = answer.trim().toLowerCase();
330
- if (trimmed === 'b') return 'back';
331
- if (trimmed === 'q') return 'quit';
332
- if (trimmed === 'n') return 'quit';
333
-
334
- state.confirmed = true;
335
- return 'done';
336
- }
337
-
338
- // --- Main Wizard ---
339
-
340
- const STAGES = [
341
- stageProjectDetection,
342
- stageRuleTypeSelection,
343
- stageLegacyMigration,
344
- stageCascadeignore,
345
- stageDomainPacks,
346
- stageMcpPacks,
347
- stageWorkflowConfig,
348
- stageMemoriesConfig,
349
- stageTeamSecurity,
350
- stageReviewGenerate,
351
- ];
352
-
353
- async function runWindsurfWizard(options) {
354
- if (!isTTY()) {
355
- console.log('Interactive wizard requires a TTY. Use --non-interactive or pipe mode instead.');
356
- return null;
357
- }
358
-
359
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
360
- const ctx = new WindsurfProjectContext(options.dir);
361
- const state = {};
362
-
363
- console.log('');
364
- console.log(c(' nerviq windsurf interactive wizard', 'bold'));
365
- console.log(c(' ═══════════════════════════════════════', 'dim'));
366
-
367
- let stageIndex = 0;
368
-
369
- try {
370
- while (stageIndex < STAGES.length) {
371
- const result = await STAGES[stageIndex](rl, ctx, state);
372
- if (result === 'quit') { rl.close(); return null; }
373
- if (result === 'back') { stageIndex = Math.max(0, stageIndex - 1); continue; }
374
- if (result === 'done') break;
375
- stageIndex++;
376
- }
377
- } finally {
378
- rl.close();
379
- }
380
-
381
- if (!state.confirmed) return null;
382
- return state;
383
- }
384
-
385
- module.exports = {
386
- runWindsurfWizard,
387
- runProjectDetection,
388
- };
1
+ /**
2
+ * Windsurf Interactive Wizard — 10-stage guided setup.
3
+ *
4
+ * Adapted for Windsurf's architecture (foreground Cascade, memories, workflows).
5
+ *
6
+ * Stages:
7
+ * 1. Project detection (stacks, existing .windsurf/, .windsurfrules)
8
+ * 2. Rule type selection (Always, Auto, Agent-Requested, Manual)
9
+ * 3. Legacy migration (.windsurfrules -> .windsurf/rules/)
10
+ * 4. Cascadeignore setup
11
+ * 5. Domain pack selection
12
+ * 6. MCP pack selection
13
+ * 7. Workflow config
14
+ * 8. Memories config
15
+ * 9. Team & 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 { WindsurfProjectContext } = require('./context');
25
+ const { WINDSURF_TECHNIQUES } = require('./techniques');
26
+ const { WINDSURF_DOMAIN_PACKS, detectWindsurfDomainPacks } = require('./domain-packs');
27
+ const { recommendWindsurfMcpPacks, WINDSURF_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
+ 'Cascadeignore Setup',
49
+ 'Domain Pack Selection',
50
+ 'MCP Pack Selection',
51
+ 'Workflow Config',
52
+ 'Memories Config',
53
+ 'Team & 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.windsurfRules ? ctx.windsurfRules() : [];
68
+ const hasLegacy = ctx.hasLegacyRules ? ctx.hasLegacyRules() : false;
69
+ const hasMcpJson = ctx.mcpConfig().ok;
70
+ const workflows = ctx.workflowFiles ? ctx.workflowFiles() : [];
71
+ const memories = ctx.memoryFiles ? ctx.memoryFiles() : [];
72
+ const hasCascadeignore = ctx.hasCascadeignore ? ctx.hasCascadeignore() : false;
73
+ const surfaces = ctx.detectSurfaces();
74
+
75
+ const auditResults = [];
76
+ for (const [key, technique] of Object.entries(WINDSURF_TECHNIQUES)) {
77
+ auditResults.push({ key, ...technique, passed: technique.check(ctx) });
78
+ }
79
+ const passed = auditResults.filter(r => r.passed === true);
80
+ const failed = auditResults.filter(r => r.passed === false);
81
+
82
+ return { stacks, rules, hasLegacy, hasMcpJson, workflows, memories, hasCascadeignore, surfaces, auditResults, passed, failed };
83
+ }
84
+
85
+ async function stageProjectDetection(rl, ctx, state) {
86
+ printStageHeader(0);
87
+ const det = runProjectDetection(ctx);
88
+ Object.assign(state, det);
89
+
90
+ if (det.stacks.length > 0) console.log(c(` Detected stacks: ${det.stacks.map(s => s.label).join(', ')}`, 'blue'));
91
+ else console.log(c(' No specific stack detected — will use baseline defaults.', 'dim'));
92
+
93
+ console.log(c(` Working directory: ${ctx.dir}`, 'dim'));
94
+ console.log('');
95
+ console.log(` ${c(`${det.passed.length}/${det.auditResults.length}`, 'bold')} Windsurf checks passing.`);
96
+ console.log(` ${c(String(det.failed.length), 'yellow')} improvements available.`);
97
+ console.log('');
98
+ console.log(` Surfaces: FG ${det.surfaces.foreground ? c('Y', 'green') : c('N', 'red')} | WF ${det.surfaces.workflows ? c('Y', 'green') : c('N', 'red')} | Mem ${det.surfaces.memories ? c('Y', 'green') : c('N', 'red')} | CI ${det.hasCascadeignore ? c('Y', 'green') : c('N', 'red')}`);
99
+ console.log(` Rules: ${det.rules.length} .md files${det.hasLegacy ? c(' + .windsurfrules (legacy!)', 'red') : ''}`);
100
+
101
+ if (det.rules.length > 0 || det.hasLegacy) {
102
+ console.log('');
103
+ if (det.hasLegacy) console.log(c(' WARNING: .windsurfrules found — this is the legacy format!', 'red'));
104
+ if (det.rules.length > 0) console.log(c(` ${det.rules.length} .md rule files in .windsurf/rules/`, 'dim'));
105
+ if (det.hasMcpJson) console.log(c(' .windsurf/mcp.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 Windsurf 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(' Windsurf supports 4 rule activation modes. Which do you want to generate?');
127
+ console.log('');
128
+ console.log(` ${c('1', 'bold')}. ${c('Always only', 'blue')} — Core rules for every Cascade interaction.`);
129
+ console.log(` ${c('2', 'bold')}. ${c('Always + Auto', 'blue')} — Core + file-type-specific rules.`);
130
+ console.log(` ${c('3', 'bold')}. ${c('Full set', 'blue')} — Always + Auto + 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');
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(' WARNING: .windsurfrules file detected!', 'red'));
155
+ console.log('');
156
+ console.log(' The .windsurfrules file is the legacy format.');
157
+ console.log(' Migrate to .windsurf/rules/*.md with YAML frontmatter for best results.');
158
+ console.log('');
159
+ console.log(` ${c('1', 'bold')}. ${c('Auto-migrate', 'blue')} — Convert .windsurfrules content to .md format.`);
160
+ console.log(` ${c('2', 'bold')}. ${c('Keep both', 'yellow')} — Generate new .md rules alongside .windsurfrules.`);
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: Cascadeignore Setup ---
176
+
177
+ async function stageCascadeignore(rl, _ctx, state) {
178
+ printStageHeader(3);
179
+
180
+ console.log(' Configure .cascadeignore for sensitive file exclusion?');
181
+ console.log('');
182
+ console.log(c(' .cascadeignore uses gitignore syntax to prevent Cascade from accessing files.', 'dim'));
183
+ console.log(c(' Recommended patterns: .env, secrets/, credentials/, .aws/, .ssh/', 'dim'));
184
+ console.log('');
185
+
186
+ const answer = await ask(rl, c(' Generate .cascadeignore? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
187
+ const trimmed = answer.trim().toLowerCase();
188
+ if (trimmed === 'b') return 'back';
189
+ if (trimmed === 'q') return 'quit';
190
+
191
+ state.generateCascadeignore = trimmed !== 'n';
192
+ console.log(c(` → Cascadeignore: ${state.generateCascadeignore ? 'will configure' : 'skip'}`, 'green'));
193
+ return 'next';
194
+ }
195
+
196
+ // --- Stage 5: Domain Pack Selection ---
197
+
198
+ async function stageDomainPacks(rl, ctx, state) {
199
+ printStageHeader(4);
200
+
201
+ const detected = detectWindsurfDomainPacks(ctx, state.stacks || []);
202
+ state.domainPacks = detected;
203
+
204
+ console.log(` Detected ${detected.length} domain pack(s):`);
205
+ console.log('');
206
+ detected.forEach((pack, i) => {
207
+ console.log(` ${c(`${i + 1}`, 'bold')}. ${c(pack.label, 'blue')} — ${pack.matchReasons[0] || pack.useWhen}`);
208
+ });
209
+ console.log('');
210
+
211
+ const answer = await ask(rl, c(' Accept detected packs? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
212
+ const trimmed = answer.trim().toLowerCase();
213
+ if (trimmed === 'b') return 'back';
214
+ if (trimmed === 'q') return 'quit';
215
+ if (trimmed === 'n') state.domainPacks = [];
216
+
217
+ console.log(c(` → Domain packs: ${state.domainPacks.map(p => p.label).join(', ') || 'none'}`, 'green'));
218
+ return 'next';
219
+ }
220
+
221
+ // --- Stage 6: MCP Pack Selection ---
222
+
223
+ async function stageMcpPacks(rl, ctx, state) {
224
+ printStageHeader(5);
225
+
226
+ const recommended = recommendWindsurfMcpPacks(state.stacks || [], state.domainPacks || [], { ctx });
227
+ state.mcpPacks = recommended;
228
+
229
+ console.log(` Recommended ${recommended.length} MCP pack(s):`);
230
+ console.log('');
231
+ recommended.forEach((pack, i) => {
232
+ console.log(` ${c(`${i + 1}`, 'bold')}. ${c(pack.label, 'blue')} — ${pack.description}`);
233
+ });
234
+ console.log('');
235
+
236
+ const answer = await ask(rl, c(' Accept recommended packs? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
237
+ const trimmed = answer.trim().toLowerCase();
238
+ if (trimmed === 'b') return 'back';
239
+ if (trimmed === 'q') return 'quit';
240
+ if (trimmed === 'n') state.mcpPacks = [];
241
+
242
+ console.log(c(` → MCP packs: ${state.mcpPacks.map(p => p.label).join(', ') || 'none'}`, 'green'));
243
+ return 'next';
244
+ }
245
+
246
+ // --- Stage 7: Workflow Config ---
247
+
248
+ async function stageWorkflowConfig(rl, _ctx, state) {
249
+ printStageHeader(6);
250
+
251
+ console.log(' Configure Windsurf workflows (slash commands)?');
252
+ console.log('');
253
+ console.log(c(' Workflows define reusable slash commands for Cascade.', 'dim'));
254
+ console.log(c(' Stored in .windsurf/workflows/*.md', 'dim'));
255
+ console.log('');
256
+
257
+ const answer = await ask(rl, c(' Set up starter workflows? (y/n, or b=back, q=quit) [n]: ', 'magenta'));
258
+ const trimmed = answer.trim().toLowerCase();
259
+ if (trimmed === 'b') return 'back';
260
+ if (trimmed === 'q') return 'quit';
261
+
262
+ state.generateWorkflows = trimmed === 'y';
263
+ console.log(c(` → Workflows: ${state.generateWorkflows ? 'will configure' : 'skip'}`, 'green'));
264
+ return 'next';
265
+ }
266
+
267
+ // --- Stage 8: Memories Config ---
268
+
269
+ async function stageMemoriesConfig(rl, _ctx, state) {
270
+ printStageHeader(7);
271
+
272
+ console.log(' Configure Windsurf memories (persistent context)?');
273
+ console.log('');
274
+ console.log(c(' Memories provide persistent context that syncs across team members.', 'dim'));
275
+ console.log(c(' IMPORTANT: Never put secrets or PII in memories — they sync to all team members!', 'yellow'));
276
+ console.log('');
277
+
278
+ const answer = await ask(rl, c(' Generate starter memories? (y/n, or b=back, q=quit) [n]: ', 'magenta'));
279
+ const trimmed = answer.trim().toLowerCase();
280
+ if (trimmed === 'b') return 'back';
281
+ if (trimmed === 'q') return 'quit';
282
+
283
+ state.generateMemories = trimmed === 'y';
284
+ console.log(c(` → Memories: ${state.generateMemories ? 'will configure' : 'skip'}`, 'green'));
285
+ return 'next';
286
+ }
287
+
288
+ // --- Stage 9: Team & Security ---
289
+
290
+ async function stageTeamSecurity(rl, _ctx, state) {
291
+ printStageHeader(8);
292
+
293
+ console.log(' Review team and security considerations:');
294
+ console.log('');
295
+ console.log(c(' 1. Memories sync across team — check for secrets/PII', 'yellow'));
296
+ console.log(c(' 2. MCP servers can be whitelisted at team level', 'dim'));
297
+ console.log(c(' 3. .cascadeignore protects sensitive files from Cascade', 'dim'));
298
+ console.log(c(' 4. Each rule file has a 10K character limit', 'dim'));
299
+ console.log('');
300
+
301
+ const answer = await ask(rl, c(' Acknowledge team/security considerations? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
302
+ const trimmed = answer.trim().toLowerCase();
303
+ if (trimmed === 'b') return 'back';
304
+ if (trimmed === 'q') return 'quit';
305
+ if (trimmed === 'n') return 'quit';
306
+
307
+ state.securityAcknowledged = true;
308
+ console.log(c(' → Team/security considerations acknowledged.', 'yellow'));
309
+ return 'next';
310
+ }
311
+
312
+ // --- Stage 10: Review & Generate ---
313
+
314
+ async function stageReviewGenerate(rl, _ctx, state) {
315
+ printStageHeader(9);
316
+
317
+ console.log(' Summary of your Windsurf setup:');
318
+ console.log('');
319
+ console.log(` Rule types: ${(state.ruleTypes || []).join(', ')}`);
320
+ console.log(` Legacy migration: ${state.legacyMigration || 'N/A'}`);
321
+ console.log(` Cascadeignore: ${state.generateCascadeignore ? 'yes' : 'no'}`);
322
+ console.log(` Domain packs: ${(state.domainPacks || []).map(p => p.label).join(', ') || 'none'}`);
323
+ console.log(` MCP packs: ${(state.mcpPacks || []).map(p => p.label).join(', ') || 'none'}`);
324
+ console.log(` Workflows: ${state.generateWorkflows ? 'yes' : 'no'}`);
325
+ console.log(` Memories: ${state.generateMemories ? 'yes' : 'no'}`);
326
+ console.log('');
327
+
328
+ const answer = await ask(rl, c(' Generate files? (y/n, or b=back, q=quit) [y]: ', 'magenta'));
329
+ const trimmed = answer.trim().toLowerCase();
330
+ if (trimmed === 'b') return 'back';
331
+ if (trimmed === 'q') return 'quit';
332
+ if (trimmed === 'n') return 'quit';
333
+
334
+ state.confirmed = true;
335
+ return 'done';
336
+ }
337
+
338
+ // --- Main Wizard ---
339
+
340
+ const STAGES = [
341
+ stageProjectDetection,
342
+ stageRuleTypeSelection,
343
+ stageLegacyMigration,
344
+ stageCascadeignore,
345
+ stageDomainPacks,
346
+ stageMcpPacks,
347
+ stageWorkflowConfig,
348
+ stageMemoriesConfig,
349
+ stageTeamSecurity,
350
+ stageReviewGenerate,
351
+ ];
352
+
353
+ async function runWindsurfWizard(options) {
354
+ if (!isTTY()) {
355
+ console.log('Interactive wizard requires a TTY. Use --non-interactive or pipe mode instead.');
356
+ return null;
357
+ }
358
+
359
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
360
+ const ctx = new WindsurfProjectContext(options.dir);
361
+ const state = {};
362
+
363
+ console.log('');
364
+ console.log(c(' nerviq windsurf interactive wizard', 'bold'));
365
+ console.log(c(' ═══════════════════════════════════════', 'dim'));
366
+
367
+ let stageIndex = 0;
368
+
369
+ try {
370
+ while (stageIndex < STAGES.length) {
371
+ const result = await STAGES[stageIndex](rl, ctx, state);
372
+ if (result === 'quit') { rl.close(); return null; }
373
+ if (result === 'back') { stageIndex = Math.max(0, stageIndex - 1); continue; }
374
+ if (result === 'done') break;
375
+ stageIndex++;
376
+ }
377
+ } finally {
378
+ rl.close();
379
+ }
380
+
381
+ if (!state.confirmed) return null;
382
+ return state;
383
+ }
384
+
385
+ module.exports = {
386
+ runWindsurfWizard,
387
+ runProjectDetection,
388
+ };