@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,471 +1,471 @@
1
- /**
2
- * Windsurf Setup Module
3
- *
4
- * 8 setup families:
5
- * 1. .windsurf/rules/*.md (core + stack-specific)
6
- * 2. Legacy migration (.windsurfrules -> .windsurf/rules/)
7
- * 3. .windsurf/mcp.json
8
- * 4. .windsurf/workflows/ (slash commands)
9
- * 5. .windsurf/memories/ (team-syncable)
10
- * 6. .cascadeignore
11
- * 7. CI workflow (GitHub Actions)
12
- * 8. Cascade guide
13
- */
14
-
15
- const fs = require('fs');
16
- const path = require('path');
17
- const os = require('os');
18
- const { version } = require('../../package.json');
19
- const { STACKS } = require('../techniques');
20
- const { writeActivityArtifact, writeRollbackArtifact } = require('../activity');
21
- const { WindsurfProjectContext } = require('./context');
22
- const { recommendWindsurfMcpPacks, packToJson } = require('./mcp-packs');
23
-
24
- function detectScripts(ctx) {
25
- const pkg = ctx.jsonFile('package.json');
26
- if (!pkg || !pkg.scripts) return {};
27
- return pkg.scripts;
28
- }
29
-
30
- function detectProjectName(ctx) {
31
- const pkg = ctx.jsonFile('package.json');
32
- if (pkg && pkg.name) return pkg.name;
33
- return path.basename(ctx.dir);
34
- }
35
-
36
- function hasStack(stacks, key) {
37
- return stacks.some((item) => item.key === key);
38
- }
39
-
40
- function buildMermaid(stacks) {
41
- if (hasStack(stacks, 'nextjs')) {
42
- return ['```mermaid', 'graph TD', ' UI[App Router / Pages] --> Logic[Server Actions or API Routes]', ' Logic --> Data[Data Layer]', ' Data --> External[External Services / DB]', '```'].join('\n');
43
- }
44
- if (hasStack(stacks, 'fastapi') || hasStack(stacks, 'django') || hasStack(stacks, 'python')) {
45
- return ['```mermaid', 'graph TD', ' API[API / CLI Entry] --> Services[Service Layer]', ' Services --> Models[Models / Schemas]', ' Models --> Data[Database or External APIs]', '```'].join('\n');
46
- }
47
- if (hasStack(stacks, 'go')) {
48
- return ['```mermaid', 'graph TD', ' Cmd[cmd/ or main package] --> Internal[internal/ packages]', ' Internal --> Data[Storage / APIs]', '```'].join('\n');
49
- }
50
- if (hasStack(stacks, 'rust')) {
51
- return ['```mermaid', 'graph TD', ' Bin[src/main.rs] --> Core[src/lib.rs]', ' Core --> Modules[domain / adapters / services]', '```'].join('\n');
52
- }
53
- return ['```mermaid', 'graph TD', ' Entry[Entry Point] --> Core[Core Logic]', ' Core --> Data[Data / External Services]', '```'].join('\n');
54
- }
55
-
56
- function buildVerificationCommands(ctx) {
57
- const scripts = detectScripts(ctx);
58
- const commands = [];
59
- if (scripts.test) commands.push('- Test: `npm test`');
60
- if (scripts.lint) commands.push('- Lint: `npm run lint`');
61
- if (scripts.build) commands.push('- Build: `npm run build`');
62
- if (commands.length === 0 && ctx.fileContent('pyproject.toml')) commands.push('- Test: `python -m pytest`');
63
- if (commands.length === 0 && ctx.fileContent('requirements.txt')) commands.push('- Test: `python -m pytest`');
64
- if (commands.length === 0 && ctx.fileContent('go.mod')) { commands.push('- Test: `go test ./...`'); commands.push('- Build: `go build ./...`'); }
65
- if (commands.length === 0 && ctx.fileContent('Cargo.toml')) { commands.push('- Test: `cargo test`'); commands.push('- Build: `cargo build`'); }
66
- if (commands.length === 0) { commands.push('- Test: add the repo test command'); commands.push('- Lint: add the repo lint command'); commands.push('- Build: add the repo build command'); }
67
- return commands;
68
- }
69
-
70
- function buildCodingConventions(stacks) {
71
- const lines = [];
72
- if (hasStack(stacks, 'typescript')) lines.push('- Keep TypeScript strict and prefer typed boundaries over implicit `any`.');
73
- if (hasStack(stacks, 'react') || hasStack(stacks, 'nextjs')) lines.push('- Prefer small, reviewable component changes and document risky UI state assumptions.');
74
- if (hasStack(stacks, 'python') || hasStack(stacks, 'fastapi') || hasStack(stacks, 'django')) lines.push('- Prefer explicit validation, typed schemas, and focused service functions.');
75
- if (hasStack(stacks, 'go')) lines.push('- Keep packages small, avoid cross-package cycles, and prefer table-driven tests.');
76
- if (hasStack(stacks, 'rust')) lines.push('- Prefer explicit ownership-safe refactors and small module-scoped changes.');
77
- if (hasStack(stacks, 'terraform') || hasStack(stacks, 'kubernetes')) lines.push('- Treat infrastructure changes as high-risk: prefer diffs that are easy to plan and roll back.');
78
- if (lines.length === 0) lines.push('- Prefer small, reviewable diffs and explicit reasoning over broad rewrites.');
79
- return lines;
80
- }
81
-
82
- function buildCoreRuleMd(ctx, stacks) {
83
- const stackLabels = stacks.map((item) => item.label).join(', ') || 'General repo';
84
- const verificationCommands = buildVerificationCommands(ctx);
85
- const codingConventions = buildCodingConventions(stacks);
86
-
87
- return [
88
- '---',
89
- 'trigger: always',
90
- 'description: "Core project rules — always active for Cascade"',
91
- '---',
92
- '',
93
- `# ${detectProjectName(ctx)} — Core Rules`,
94
- '',
95
- '## Scope',
96
- '- Primary platform: Windsurf (Cascade agent)',
97
- `- Detected stack: ${stackLabels}`,
98
- '',
99
- '## Architecture',
100
- buildMermaid(stacks),
101
- '- Replace the default diagram with the real entry points and boundaries for this repo.',
102
- '',
103
- '## Verification',
104
- ...verificationCommands,
105
- '',
106
- 'Before completing any task:',
107
- '1. Run tests — all must pass',
108
- '2. Run lint — no errors',
109
- '3. Verify build succeeds',
110
- '',
111
- '## Coding Conventions',
112
- ...codingConventions,
113
- '',
114
- '## Security',
115
- '- Never commit secrets, tokens, or `.env` values into tracked files.',
116
- '- Use .cascadeignore to exclude sensitive files from Cascade access.',
117
- '- Prefer the repo verification commands before handoff.',
118
- '',
119
- '## Platform Awareness',
120
- '- **Cascade**: Autonomous agent with multi-file editing capabilities.',
121
- '- **Memories**: Team-syncable persistent context in .windsurf/memories/.',
122
- '- **Workflows**: Slash commands in .windsurf/workflows/.',
123
- '- **10K char limit**: Each rule file must be under 10,000 characters.',
124
- '- **Session drift**: Long sessions may lose context — start fresh if instructions are forgotten.',
125
- '',
126
- `_Generated by nerviq v${version} for Windsurf. Customize before production use._`,
127
- '',
128
- ].join('\n');
129
- }
130
-
131
- function buildStackRuleMd(stacks) {
132
- if (hasStack(stacks, 'typescript')) {
133
- return [
134
- '---',
135
- 'trigger: auto',
136
- 'description: "TypeScript-specific conventions"',
137
- 'globs:',
138
- ' - "**/*.ts"',
139
- ' - "**/*.tsx"',
140
- '---',
141
- '',
142
- '# TypeScript Rules',
143
- '',
144
- '- Use strict mode',
145
- '- Prefer named exports over default exports',
146
- '- Use explicit return types on public functions',
147
- '- Avoid `any` — use `unknown` or proper types',
148
- '- Prefer interfaces over types for public APIs',
149
- '',
150
- `_Generated by nerviq v${version}_`,
151
- '',
152
- ].join('\n');
153
- }
154
- return null;
155
- }
156
-
157
- function buildMcpJson(ctx, stacks, domainPacks) {
158
- const mcpRecs = recommendWindsurfMcpPacks(stacks, domainPacks || [], { ctx });
159
- const mcpServers = Object.assign({}, ...mcpRecs.map(p => packToJson(p)));
160
- return JSON.stringify({ mcpServers }, null, 2) + '\n';
161
- }
162
-
163
- function buildLegacyMigrationGuide() {
164
- return [
165
- '---',
166
- 'trigger: agent_requested',
167
- 'description: "Legacy .windsurfrules migration guide"',
168
- '---',
169
- '',
170
- '# Legacy Migration Guide',
171
- '',
172
- '## .windsurfrules Migration',
173
- '',
174
- 'The `.windsurfrules` file is the legacy format.',
175
- 'Migrate to `.windsurf/rules/*.md` files with proper YAML frontmatter.',
176
- '',
177
- '## Migration steps',
178
- '',
179
- '1. Copy `.windsurfrules` content to `.windsurf/rules/core.md`',
180
- '2. Add YAML frontmatter with `trigger: always`',
181
- '3. Delete `.windsurfrules` (or rename to `.windsurfrules.bak`)',
182
- '4. Verify Cascade sees the rules',
183
- '',
184
- '## Rule activation reference',
185
- '',
186
- '| Mode | trigger | globs | description |',
187
- '|------|:-------:|:-----:|:-----------:|',
188
- '| Always | always | any | any |',
189
- '| Auto | auto | set | optional |',
190
- '| Agent-Requested | agent_requested | empty | set |',
191
- '| Manual | manual | empty | empty |',
192
- '',
193
- `_Generated by nerviq v${version}_`,
194
- '',
195
- ].join('\n');
196
- }
197
-
198
- function buildCascadeignore() {
199
- return [
200
- '# Cascade agent file exclusions (gitignore syntax)',
201
- '# Files listed here will not be accessible to Cascade',
202
- '',
203
- '# Environment and secrets',
204
- '.env',
205
- '.env.*',
206
- '*.key',
207
- '*.pem',
208
- '',
209
- '# Credentials',
210
- '.aws/',
211
- '.ssh/',
212
- 'credentials/',
213
- 'secrets/',
214
- '',
215
- '# Build artifacts',
216
- 'node_modules/',
217
- 'dist/',
218
- '.next/',
219
- '',
220
- `# Generated by nerviq v${version} for Windsurf`,
221
- '',
222
- ].join('\n');
223
- }
224
-
225
- function buildCiReviewWorkflow() {
226
- return [
227
- 'name: Windsurf Code Review',
228
- '',
229
- 'on:',
230
- ' pull_request:',
231
- ' types: [opened, synchronize]',
232
- '',
233
- 'permissions:',
234
- ' contents: read',
235
- ' pull-requests: write',
236
- '',
237
- 'jobs:',
238
- ' windsurf-review:',
239
- ' runs-on: ubuntu-latest',
240
- ' steps:',
241
- ' - uses: actions/checkout@v4',
242
- ' - name: Run nerviq audit',
243
- ' run: npx nerviq --platform windsurf --json > audit-report.json',
244
- ' - uses: actions/upload-artifact@v4',
245
- ' with:',
246
- ' name: windsurf-audit-report',
247
- ' path: audit-report.json',
248
- ' retention-days: 30',
249
- '',
250
- `# Generated by nerviq v${version} for Windsurf.`,
251
- '',
252
- ].join('\n');
253
- }
254
-
255
- function buildCascadeGuide() {
256
- return [
257
- '---',
258
- 'trigger: agent_requested',
259
- 'description: "Cascade agent usage guide and best practices"',
260
- '---',
261
- '',
262
- '# Cascade Agent Guide',
263
- '',
264
- '## What is Cascade?',
265
- 'Cascade is Windsurf\'s autonomous AI agent with multi-file editing capabilities.',
266
- 'It can perform complex, multi-step tasks across your entire codebase.',
267
- '',
268
- '## Key Features',
269
- '- **Multi-file editing**: Cascade can edit multiple files in a single action.',
270
- '- **Steps**: Automated multi-step workflows for complex tasks.',
271
- '- **Skills**: Configurable capabilities (web search, terminal, etc.).',
272
- '- **Memories**: Persistent context that syncs across team members.',
273
- '',
274
- '## Best Practices',
275
- '- Use @-mentions to reference specific files or context.',
276
- '- Keep sessions focused — start fresh for unrelated tasks.',
277
- '- Review Cascade\'s multi-file changes before committing.',
278
- '- Use .cascadeignore to protect sensitive files.',
279
- '',
280
- `_Generated by nerviq v${version}_`,
281
- '',
282
- ].join('\n');
283
- }
284
-
285
- function buildWindsurfSetupFiles(options = {}) {
286
- const ctx = new WindsurfProjectContext(options.dir);
287
- const stacks = ctx.detectStacks(STACKS);
288
- const files = [];
289
-
290
- // 1. Core rules (.windsurf/rules/core.md)
291
- const coreRulePath = path.join(options.dir, '.windsurf', 'rules', 'core.md');
292
- if (!fs.existsSync(coreRulePath)) {
293
- files.push({
294
- path: '.windsurf/rules/core.md',
295
- action: 'create',
296
- family: 'windsurf-rules',
297
- content: buildCoreRuleMd(ctx, stacks),
298
- currentState: '.windsurf/rules/core.md is missing',
299
- proposedState: 'create a core rules file with trigger: always, verification, and architecture guidance',
300
- });
301
- }
302
-
303
- // Stack-specific rule
304
- const stackRule = buildStackRuleMd(stacks);
305
- if (stackRule) {
306
- const stackRulePath = path.join(options.dir, '.windsurf', 'rules', 'typescript.md');
307
- if (!fs.existsSync(stackRulePath)) {
308
- files.push({
309
- path: '.windsurf/rules/typescript.md',
310
- action: 'create',
311
- family: 'windsurf-rules',
312
- content: stackRule,
313
- currentState: '.windsurf/rules/typescript.md is missing',
314
- proposedState: 'create Auto TypeScript rules with glob pattern',
315
- });
316
- }
317
- }
318
-
319
- // 2. Legacy migration
320
- const legacyPath = path.join(options.dir, '.windsurfrules');
321
- if (fs.existsSync(legacyPath)) {
322
- const migrationPath = path.join(options.dir, '.windsurf', 'rules', 'migration-guide.md');
323
- if (!fs.existsSync(migrationPath)) {
324
- files.push({
325
- path: '.windsurf/rules/migration-guide.md',
326
- action: 'create',
327
- family: 'windsurf-legacy-migration',
328
- content: buildLegacyMigrationGuide(),
329
- currentState: '.windsurfrules exists — legacy format',
330
- proposedState: 'create migration guide to help move .windsurfrules content to .windsurf/rules/*.md',
331
- });
332
- }
333
- }
334
-
335
- const modules = options.modules || 'all';
336
- const wantModule = (name) => modules === 'all' || (Array.isArray(modules) && modules.includes(name));
337
-
338
- // 3. MCP config
339
- if (wantModule('mcp')) {
340
- const mcpPath = path.join(options.dir, '.windsurf', 'mcp.json');
341
- if (!fs.existsSync(mcpPath)) {
342
- const domainPacks = options.domainPacks || [];
343
- files.push({
344
- path: '.windsurf/mcp.json',
345
- action: 'create',
346
- family: 'windsurf-mcp',
347
- content: buildMcpJson(ctx, stacks, domainPacks),
348
- currentState: '.windsurf/mcp.json is missing',
349
- proposedState: 'create MCP config with recommended packs',
350
- });
351
- }
352
- }
353
-
354
- // 4. Cascadeignore
355
- if (wantModule('cascadeignore')) {
356
- const ignorePath = path.join(options.dir, '.cascadeignore');
357
- if (!fs.existsSync(ignorePath)) {
358
- files.push({
359
- path: '.cascadeignore',
360
- action: 'create',
361
- family: 'windsurf-cascadeignore',
362
- content: buildCascadeignore(),
363
- currentState: '.cascadeignore is missing',
364
- proposedState: 'create .cascadeignore for sensitive file exclusion from Cascade',
365
- });
366
- }
367
- }
368
-
369
- // 5. CI workflow
370
- if (wantModule('ci')) {
371
- const ciPath = path.join(options.dir, '.github', 'workflows', 'windsurf-review.yml');
372
- if (!fs.existsSync(ciPath)) {
373
- files.push({
374
- path: '.github/workflows/windsurf-review.yml',
375
- action: 'create',
376
- family: 'windsurf-ci-review',
377
- content: buildCiReviewWorkflow(),
378
- currentState: 'No Windsurf CI review workflow exists',
379
- proposedState: 'create a GitHub Actions workflow for Windsurf-based audit on PRs',
380
- });
381
- }
382
- }
383
-
384
- // 6. Cascade guide
385
- if (wantModule('cascade-guide')) {
386
- const guidePath = path.join(options.dir, '.windsurf', 'rules', 'cascade-guide.md');
387
- if (!fs.existsSync(guidePath)) {
388
- files.push({
389
- path: '.windsurf/rules/cascade-guide.md',
390
- action: 'create',
391
- family: 'windsurf-cascade-guide',
392
- content: buildCascadeGuide(),
393
- currentState: 'No Cascade guide',
394
- proposedState: 'create Cascade agent usage guide as an Agent-Requested rule',
395
- });
396
- }
397
- }
398
-
399
- return { ctx, stacks, files };
400
- }
401
-
402
- async function setupWindsurf(options) {
403
- const silent = options.silent === true;
404
- const { ctx, stacks, files } = buildWindsurfSetupFiles(options);
405
- const writtenFiles = [];
406
- const preservedFiles = [];
407
-
408
- function log(message = '') { if (!silent) console.log(message); }
409
-
410
- log('');
411
- log('\x1b[1m nerviq windsurf setup\x1b[0m');
412
- log('\x1b[2m ═══════════════════════════════════════\x1b[0m');
413
- if (stacks.length > 0) log(`\x1b[36m Detected: ${stacks.map((s) => s.label).join(', ')}\x1b[0m`);
414
- log('');
415
-
416
- for (const file of files) {
417
- const fullPath = path.join(options.dir, file.path);
418
- if (fs.existsSync(fullPath)) {
419
- preservedFiles.push(file.path);
420
- log(` \x1b[2m Skipped ${file.path} (already exists)\x1b[0m`);
421
- continue;
422
- }
423
- fs.mkdirSync(path.dirname(fullPath), { recursive: true });
424
- fs.writeFileSync(fullPath, file.content, 'utf8');
425
- writtenFiles.push(file.path);
426
- log(` \x1b[32m Created ${file.path}\x1b[0m`);
427
- }
428
-
429
- let rollbackArtifact = null;
430
- let activityArtifact = null;
431
- if (writtenFiles.length > 0) {
432
- rollbackArtifact = writeRollbackArtifact(options.dir, {
433
- sourcePlan: 'windsurf-setup',
434
- createdFiles: writtenFiles,
435
- patchedFiles: [],
436
- rollbackInstructions: writtenFiles.map((file) => `Delete ${file}`),
437
- });
438
- activityArtifact = writeActivityArtifact(options.dir, 'windsurf-setup', {
439
- platform: 'windsurf',
440
- createdFiles: writtenFiles,
441
- preservedFiles,
442
- stackLabels: stacks.map((item) => item.label),
443
- rollbackArtifact: rollbackArtifact.relativePath,
444
- });
445
- }
446
-
447
- log('');
448
- log(` \x1b[1m${writtenFiles.length} files created.\x1b[0m`);
449
- if (preservedFiles.length > 0) log(` \x1b[2m${preservedFiles.length} existing files preserved.\x1b[0m`);
450
- if (rollbackArtifact) log(` Rollback: \x1b[1m${rollbackArtifact.relativePath}\x1b[0m`);
451
- if (activityArtifact) log(` Activity log: \x1b[1m${activityArtifact.relativePath}\x1b[0m`);
452
- log('');
453
- log(' Run \x1b[1mnpx nerviq --platform windsurf\x1b[0m to audit your Windsurf setup.');
454
- log('');
455
-
456
- return {
457
- created: writtenFiles.length,
458
- skipped: preservedFiles.length,
459
- writtenFiles,
460
- preservedFiles,
461
- stacks,
462
- rollbackArtifact: rollbackArtifact ? rollbackArtifact.relativePath : null,
463
- activityArtifact: activityArtifact ? activityArtifact.relativePath : null,
464
- };
465
- }
466
-
467
- module.exports = {
468
- buildCoreRuleMd,
469
- buildWindsurfSetupFiles,
470
- setupWindsurf,
471
- };
1
+ /**
2
+ * Windsurf Setup Module
3
+ *
4
+ * 8 setup families:
5
+ * 1. .windsurf/rules/*.md (core + stack-specific)
6
+ * 2. Legacy migration (.windsurfrules -> .windsurf/rules/)
7
+ * 3. .windsurf/mcp.json
8
+ * 4. .windsurf/workflows/ (slash commands)
9
+ * 5. .windsurf/memories/ (team-syncable)
10
+ * 6. .cascadeignore
11
+ * 7. CI workflow (GitHub Actions)
12
+ * 8. Cascade guide
13
+ */
14
+
15
+ const fs = require('fs');
16
+ const path = require('path');
17
+ const os = require('os');
18
+ const { version } = require('../../package.json');
19
+ const { STACKS } = require('../techniques');
20
+ const { writeActivityArtifact, writeRollbackArtifact } = require('../activity');
21
+ const { WindsurfProjectContext } = require('./context');
22
+ const { recommendWindsurfMcpPacks, packToJson } = require('./mcp-packs');
23
+
24
+ function detectScripts(ctx) {
25
+ const pkg = ctx.jsonFile('package.json');
26
+ if (!pkg || !pkg.scripts) return {};
27
+ return pkg.scripts;
28
+ }
29
+
30
+ function detectProjectName(ctx) {
31
+ const pkg = ctx.jsonFile('package.json');
32
+ if (pkg && pkg.name) return pkg.name;
33
+ return path.basename(ctx.dir);
34
+ }
35
+
36
+ function hasStack(stacks, key) {
37
+ return stacks.some((item) => item.key === key);
38
+ }
39
+
40
+ function buildMermaid(stacks) {
41
+ if (hasStack(stacks, 'nextjs')) {
42
+ return ['```mermaid', 'graph TD', ' UI[App Router / Pages] --> Logic[Server Actions or API Routes]', ' Logic --> Data[Data Layer]', ' Data --> External[External Services / DB]', '```'].join('\n');
43
+ }
44
+ if (hasStack(stacks, 'fastapi') || hasStack(stacks, 'django') || hasStack(stacks, 'python')) {
45
+ return ['```mermaid', 'graph TD', ' API[API / CLI Entry] --> Services[Service Layer]', ' Services --> Models[Models / Schemas]', ' Models --> Data[Database or External APIs]', '```'].join('\n');
46
+ }
47
+ if (hasStack(stacks, 'go')) {
48
+ return ['```mermaid', 'graph TD', ' Cmd[cmd/ or main package] --> Internal[internal/ packages]', ' Internal --> Data[Storage / APIs]', '```'].join('\n');
49
+ }
50
+ if (hasStack(stacks, 'rust')) {
51
+ return ['```mermaid', 'graph TD', ' Bin[src/main.rs] --> Core[src/lib.rs]', ' Core --> Modules[domain / adapters / services]', '```'].join('\n');
52
+ }
53
+ return ['```mermaid', 'graph TD', ' Entry[Entry Point] --> Core[Core Logic]', ' Core --> Data[Data / External Services]', '```'].join('\n');
54
+ }
55
+
56
+ function buildVerificationCommands(ctx) {
57
+ const scripts = detectScripts(ctx);
58
+ const commands = [];
59
+ if (scripts.test) commands.push('- Test: `npm test`');
60
+ if (scripts.lint) commands.push('- Lint: `npm run lint`');
61
+ if (scripts.build) commands.push('- Build: `npm run build`');
62
+ if (commands.length === 0 && ctx.fileContent('pyproject.toml')) commands.push('- Test: `python -m pytest`');
63
+ if (commands.length === 0 && ctx.fileContent('requirements.txt')) commands.push('- Test: `python -m pytest`');
64
+ if (commands.length === 0 && ctx.fileContent('go.mod')) { commands.push('- Test: `go test ./...`'); commands.push('- Build: `go build ./...`'); }
65
+ if (commands.length === 0 && ctx.fileContent('Cargo.toml')) { commands.push('- Test: `cargo test`'); commands.push('- Build: `cargo build`'); }
66
+ if (commands.length === 0) { commands.push('- Test: add the repo test command'); commands.push('- Lint: add the repo lint command'); commands.push('- Build: add the repo build command'); }
67
+ return commands;
68
+ }
69
+
70
+ function buildCodingConventions(stacks) {
71
+ const lines = [];
72
+ if (hasStack(stacks, 'typescript')) lines.push('- Keep TypeScript strict and prefer typed boundaries over implicit `any`.');
73
+ if (hasStack(stacks, 'react') || hasStack(stacks, 'nextjs')) lines.push('- Prefer small, reviewable component changes and document risky UI state assumptions.');
74
+ if (hasStack(stacks, 'python') || hasStack(stacks, 'fastapi') || hasStack(stacks, 'django')) lines.push('- Prefer explicit validation, typed schemas, and focused service functions.');
75
+ if (hasStack(stacks, 'go')) lines.push('- Keep packages small, avoid cross-package cycles, and prefer table-driven tests.');
76
+ if (hasStack(stacks, 'rust')) lines.push('- Prefer explicit ownership-safe refactors and small module-scoped changes.');
77
+ if (hasStack(stacks, 'terraform') || hasStack(stacks, 'kubernetes')) lines.push('- Treat infrastructure changes as high-risk: prefer diffs that are easy to plan and roll back.');
78
+ if (lines.length === 0) lines.push('- Prefer small, reviewable diffs and explicit reasoning over broad rewrites.');
79
+ return lines;
80
+ }
81
+
82
+ function buildCoreRuleMd(ctx, stacks) {
83
+ const stackLabels = stacks.map((item) => item.label).join(', ') || 'General repo';
84
+ const verificationCommands = buildVerificationCommands(ctx);
85
+ const codingConventions = buildCodingConventions(stacks);
86
+
87
+ return [
88
+ '---',
89
+ 'trigger: always',
90
+ 'description: "Core project rules — always active for Cascade"',
91
+ '---',
92
+ '',
93
+ `# ${detectProjectName(ctx)} — Core Rules`,
94
+ '',
95
+ '## Scope',
96
+ '- Primary platform: Windsurf (Cascade agent)',
97
+ `- Detected stack: ${stackLabels}`,
98
+ '',
99
+ '## Architecture',
100
+ buildMermaid(stacks),
101
+ '- Replace the default diagram with the real entry points and boundaries for this repo.',
102
+ '',
103
+ '## Verification',
104
+ ...verificationCommands,
105
+ '',
106
+ 'Before completing any task:',
107
+ '1. Run tests — all must pass',
108
+ '2. Run lint — no errors',
109
+ '3. Verify build succeeds',
110
+ '',
111
+ '## Coding Conventions',
112
+ ...codingConventions,
113
+ '',
114
+ '## Security',
115
+ '- Never commit secrets, tokens, or `.env` values into tracked files.',
116
+ '- Use .cascadeignore to exclude sensitive files from Cascade access.',
117
+ '- Prefer the repo verification commands before handoff.',
118
+ '',
119
+ '## Platform Awareness',
120
+ '- **Cascade**: Autonomous agent with multi-file editing capabilities.',
121
+ '- **Memories**: Team-syncable persistent context in .windsurf/memories/.',
122
+ '- **Workflows**: Slash commands in .windsurf/workflows/.',
123
+ '- **10K char limit**: Each rule file must be under 10,000 characters.',
124
+ '- **Session drift**: Long sessions may lose context — start fresh if instructions are forgotten.',
125
+ '',
126
+ `_Generated by nerviq v${version} for Windsurf. Customize before production use._`,
127
+ '',
128
+ ].join('\n');
129
+ }
130
+
131
+ function buildStackRuleMd(stacks) {
132
+ if (hasStack(stacks, 'typescript')) {
133
+ return [
134
+ '---',
135
+ 'trigger: auto',
136
+ 'description: "TypeScript-specific conventions"',
137
+ 'globs:',
138
+ ' - "**/*.ts"',
139
+ ' - "**/*.tsx"',
140
+ '---',
141
+ '',
142
+ '# TypeScript Rules',
143
+ '',
144
+ '- Use strict mode',
145
+ '- Prefer named exports over default exports',
146
+ '- Use explicit return types on public functions',
147
+ '- Avoid `any` — use `unknown` or proper types',
148
+ '- Prefer interfaces over types for public APIs',
149
+ '',
150
+ `_Generated by nerviq v${version}_`,
151
+ '',
152
+ ].join('\n');
153
+ }
154
+ return null;
155
+ }
156
+
157
+ function buildMcpJson(ctx, stacks, domainPacks) {
158
+ const mcpRecs = recommendWindsurfMcpPacks(stacks, domainPacks || [], { ctx });
159
+ const mcpServers = Object.assign({}, ...mcpRecs.map(p => packToJson(p)));
160
+ return JSON.stringify({ mcpServers }, null, 2) + '\n';
161
+ }
162
+
163
+ function buildLegacyMigrationGuide() {
164
+ return [
165
+ '---',
166
+ 'trigger: agent_requested',
167
+ 'description: "Legacy .windsurfrules migration guide"',
168
+ '---',
169
+ '',
170
+ '# Legacy Migration Guide',
171
+ '',
172
+ '## .windsurfrules Migration',
173
+ '',
174
+ 'The `.windsurfrules` file is the legacy format.',
175
+ 'Migrate to `.windsurf/rules/*.md` files with proper YAML frontmatter.',
176
+ '',
177
+ '## Migration steps',
178
+ '',
179
+ '1. Copy `.windsurfrules` content to `.windsurf/rules/core.md`',
180
+ '2. Add YAML frontmatter with `trigger: always`',
181
+ '3. Delete `.windsurfrules` (or rename to `.windsurfrules.bak`)',
182
+ '4. Verify Cascade sees the rules',
183
+ '',
184
+ '## Rule activation reference',
185
+ '',
186
+ '| Mode | trigger | globs | description |',
187
+ '|------|:-------:|:-----:|:-----------:|',
188
+ '| Always | always | any | any |',
189
+ '| Auto | auto | set | optional |',
190
+ '| Agent-Requested | agent_requested | empty | set |',
191
+ '| Manual | manual | empty | empty |',
192
+ '',
193
+ `_Generated by nerviq v${version}_`,
194
+ '',
195
+ ].join('\n');
196
+ }
197
+
198
+ function buildCascadeignore() {
199
+ return [
200
+ '# Cascade agent file exclusions (gitignore syntax)',
201
+ '# Files listed here will not be accessible to Cascade',
202
+ '',
203
+ '# Environment and secrets',
204
+ '.env',
205
+ '.env.*',
206
+ '*.key',
207
+ '*.pem',
208
+ '',
209
+ '# Credentials',
210
+ '.aws/',
211
+ '.ssh/',
212
+ 'credentials/',
213
+ 'secrets/',
214
+ '',
215
+ '# Build artifacts',
216
+ 'node_modules/',
217
+ 'dist/',
218
+ '.next/',
219
+ '',
220
+ `# Generated by nerviq v${version} for Windsurf`,
221
+ '',
222
+ ].join('\n');
223
+ }
224
+
225
+ function buildCiReviewWorkflow() {
226
+ return [
227
+ 'name: Windsurf Code Review',
228
+ '',
229
+ 'on:',
230
+ ' pull_request:',
231
+ ' types: [opened, synchronize]',
232
+ '',
233
+ 'permissions:',
234
+ ' contents: read',
235
+ ' pull-requests: write',
236
+ '',
237
+ 'jobs:',
238
+ ' windsurf-review:',
239
+ ' runs-on: ubuntu-latest',
240
+ ' steps:',
241
+ ' - uses: actions/checkout@v4',
242
+ ' - name: Run nerviq audit',
243
+ ' run: npx nerviq --platform windsurf --json > audit-report.json',
244
+ ' - uses: actions/upload-artifact@v4',
245
+ ' with:',
246
+ ' name: windsurf-audit-report',
247
+ ' path: audit-report.json',
248
+ ' retention-days: 30',
249
+ '',
250
+ `# Generated by nerviq v${version} for Windsurf.`,
251
+ '',
252
+ ].join('\n');
253
+ }
254
+
255
+ function buildCascadeGuide() {
256
+ return [
257
+ '---',
258
+ 'trigger: agent_requested',
259
+ 'description: "Cascade agent usage guide and best practices"',
260
+ '---',
261
+ '',
262
+ '# Cascade Agent Guide',
263
+ '',
264
+ '## What is Cascade?',
265
+ 'Cascade is Windsurf\'s autonomous AI agent with multi-file editing capabilities.',
266
+ 'It can perform complex, multi-step tasks across your entire codebase.',
267
+ '',
268
+ '## Key Features',
269
+ '- **Multi-file editing**: Cascade can edit multiple files in a single action.',
270
+ '- **Steps**: Automated multi-step workflows for complex tasks.',
271
+ '- **Skills**: Configurable capabilities (web search, terminal, etc.).',
272
+ '- **Memories**: Persistent context that syncs across team members.',
273
+ '',
274
+ '## Best Practices',
275
+ '- Use @-mentions to reference specific files or context.',
276
+ '- Keep sessions focused — start fresh for unrelated tasks.',
277
+ '- Review Cascade\'s multi-file changes before committing.',
278
+ '- Use .cascadeignore to protect sensitive files.',
279
+ '',
280
+ `_Generated by nerviq v${version}_`,
281
+ '',
282
+ ].join('\n');
283
+ }
284
+
285
+ function buildWindsurfSetupFiles(options = {}) {
286
+ const ctx = new WindsurfProjectContext(options.dir);
287
+ const stacks = ctx.detectStacks(STACKS);
288
+ const files = [];
289
+
290
+ // 1. Core rules (.windsurf/rules/core.md)
291
+ const coreRulePath = path.join(options.dir, '.windsurf', 'rules', 'core.md');
292
+ if (!fs.existsSync(coreRulePath)) {
293
+ files.push({
294
+ path: '.windsurf/rules/core.md',
295
+ action: 'create',
296
+ family: 'windsurf-rules',
297
+ content: buildCoreRuleMd(ctx, stacks),
298
+ currentState: '.windsurf/rules/core.md is missing',
299
+ proposedState: 'create a core rules file with trigger: always, verification, and architecture guidance',
300
+ });
301
+ }
302
+
303
+ // Stack-specific rule
304
+ const stackRule = buildStackRuleMd(stacks);
305
+ if (stackRule) {
306
+ const stackRulePath = path.join(options.dir, '.windsurf', 'rules', 'typescript.md');
307
+ if (!fs.existsSync(stackRulePath)) {
308
+ files.push({
309
+ path: '.windsurf/rules/typescript.md',
310
+ action: 'create',
311
+ family: 'windsurf-rules',
312
+ content: stackRule,
313
+ currentState: '.windsurf/rules/typescript.md is missing',
314
+ proposedState: 'create Auto TypeScript rules with glob pattern',
315
+ });
316
+ }
317
+ }
318
+
319
+ // 2. Legacy migration
320
+ const legacyPath = path.join(options.dir, '.windsurfrules');
321
+ if (fs.existsSync(legacyPath)) {
322
+ const migrationPath = path.join(options.dir, '.windsurf', 'rules', 'migration-guide.md');
323
+ if (!fs.existsSync(migrationPath)) {
324
+ files.push({
325
+ path: '.windsurf/rules/migration-guide.md',
326
+ action: 'create',
327
+ family: 'windsurf-legacy-migration',
328
+ content: buildLegacyMigrationGuide(),
329
+ currentState: '.windsurfrules exists — legacy format',
330
+ proposedState: 'create migration guide to help move .windsurfrules content to .windsurf/rules/*.md',
331
+ });
332
+ }
333
+ }
334
+
335
+ const modules = options.modules || 'all';
336
+ const wantModule = (name) => modules === 'all' || (Array.isArray(modules) && modules.includes(name));
337
+
338
+ // 3. MCP config
339
+ if (wantModule('mcp')) {
340
+ const mcpPath = path.join(options.dir, '.windsurf', 'mcp.json');
341
+ if (!fs.existsSync(mcpPath)) {
342
+ const domainPacks = options.domainPacks || [];
343
+ files.push({
344
+ path: '.windsurf/mcp.json',
345
+ action: 'create',
346
+ family: 'windsurf-mcp',
347
+ content: buildMcpJson(ctx, stacks, domainPacks),
348
+ currentState: '.windsurf/mcp.json is missing',
349
+ proposedState: 'create MCP config with recommended packs',
350
+ });
351
+ }
352
+ }
353
+
354
+ // 4. Cascadeignore
355
+ if (wantModule('cascadeignore')) {
356
+ const ignorePath = path.join(options.dir, '.cascadeignore');
357
+ if (!fs.existsSync(ignorePath)) {
358
+ files.push({
359
+ path: '.cascadeignore',
360
+ action: 'create',
361
+ family: 'windsurf-cascadeignore',
362
+ content: buildCascadeignore(),
363
+ currentState: '.cascadeignore is missing',
364
+ proposedState: 'create .cascadeignore for sensitive file exclusion from Cascade',
365
+ });
366
+ }
367
+ }
368
+
369
+ // 5. CI workflow
370
+ if (wantModule('ci')) {
371
+ const ciPath = path.join(options.dir, '.github', 'workflows', 'windsurf-review.yml');
372
+ if (!fs.existsSync(ciPath)) {
373
+ files.push({
374
+ path: '.github/workflows/windsurf-review.yml',
375
+ action: 'create',
376
+ family: 'windsurf-ci-review',
377
+ content: buildCiReviewWorkflow(),
378
+ currentState: 'No Windsurf CI review workflow exists',
379
+ proposedState: 'create a GitHub Actions workflow for Windsurf-based audit on PRs',
380
+ });
381
+ }
382
+ }
383
+
384
+ // 6. Cascade guide
385
+ if (wantModule('cascade-guide')) {
386
+ const guidePath = path.join(options.dir, '.windsurf', 'rules', 'cascade-guide.md');
387
+ if (!fs.existsSync(guidePath)) {
388
+ files.push({
389
+ path: '.windsurf/rules/cascade-guide.md',
390
+ action: 'create',
391
+ family: 'windsurf-cascade-guide',
392
+ content: buildCascadeGuide(),
393
+ currentState: 'No Cascade guide',
394
+ proposedState: 'create Cascade agent usage guide as an Agent-Requested rule',
395
+ });
396
+ }
397
+ }
398
+
399
+ return { ctx, stacks, files };
400
+ }
401
+
402
+ async function setupWindsurf(options) {
403
+ const silent = options.silent === true;
404
+ const { ctx, stacks, files } = buildWindsurfSetupFiles(options);
405
+ const writtenFiles = [];
406
+ const preservedFiles = [];
407
+
408
+ function log(message = '') { if (!silent) console.log(message); }
409
+
410
+ log('');
411
+ log('\x1b[1m nerviq windsurf setup\x1b[0m');
412
+ log('\x1b[2m ═══════════════════════════════════════\x1b[0m');
413
+ if (stacks.length > 0) log(`\x1b[36m Detected: ${stacks.map((s) => s.label).join(', ')}\x1b[0m`);
414
+ log('');
415
+
416
+ for (const file of files) {
417
+ const fullPath = path.join(options.dir, file.path);
418
+ if (fs.existsSync(fullPath)) {
419
+ preservedFiles.push(file.path);
420
+ log(` \x1b[2m Skipped ${file.path} (already exists)\x1b[0m`);
421
+ continue;
422
+ }
423
+ fs.mkdirSync(path.dirname(fullPath), { recursive: true });
424
+ fs.writeFileSync(fullPath, file.content, 'utf8');
425
+ writtenFiles.push(file.path);
426
+ log(` \x1b[32m Created ${file.path}\x1b[0m`);
427
+ }
428
+
429
+ let rollbackArtifact = null;
430
+ let activityArtifact = null;
431
+ if (writtenFiles.length > 0) {
432
+ rollbackArtifact = writeRollbackArtifact(options.dir, {
433
+ sourcePlan: 'windsurf-setup',
434
+ createdFiles: writtenFiles,
435
+ patchedFiles: [],
436
+ rollbackInstructions: writtenFiles.map((file) => `Delete ${file}`),
437
+ });
438
+ activityArtifact = writeActivityArtifact(options.dir, 'windsurf-setup', {
439
+ platform: 'windsurf',
440
+ createdFiles: writtenFiles,
441
+ preservedFiles,
442
+ stackLabels: stacks.map((item) => item.label),
443
+ rollbackArtifact: rollbackArtifact.relativePath,
444
+ });
445
+ }
446
+
447
+ log('');
448
+ log(` \x1b[1m${writtenFiles.length} files created.\x1b[0m`);
449
+ if (preservedFiles.length > 0) log(` \x1b[2m${preservedFiles.length} existing files preserved.\x1b[0m`);
450
+ if (rollbackArtifact) log(` Rollback: \x1b[1m${rollbackArtifact.relativePath}\x1b[0m`);
451
+ if (activityArtifact) log(` Activity log: \x1b[1m${activityArtifact.relativePath}\x1b[0m`);
452
+ log('');
453
+ log(' Run \x1b[1mnpx nerviq --platform windsurf\x1b[0m to audit your Windsurf setup.');
454
+ log('');
455
+
456
+ return {
457
+ created: writtenFiles.length,
458
+ skipped: preservedFiles.length,
459
+ writtenFiles,
460
+ preservedFiles,
461
+ stacks,
462
+ rollbackArtifact: rollbackArtifact ? rollbackArtifact.relativePath : null,
463
+ activityArtifact: activityArtifact ? activityArtifact.relativePath : null,
464
+ };
465
+ }
466
+
467
+ module.exports = {
468
+ buildCoreRuleMd,
469
+ buildWindsurfSetupFiles,
470
+ setupWindsurf,
471
+ };