@nerviq/cli 1.18.0 → 1.20.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 (187) hide show
  1. package/LICENSE +23 -23
  2. package/README.md +2 -2
  3. package/bin/cli.js +131 -130
  4. package/package.json +2 -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 +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/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/sarif.js +115 -115
  78. package/src/freshness.js +74 -74
  79. package/src/gemini/config-parser.js +275 -275
  80. package/src/gemini/context.js +290 -221
  81. package/src/gemini/deep-review.js +559 -559
  82. package/src/gemini/domain-packs.js +393 -393
  83. package/src/gemini/freshness.js +66 -66
  84. package/src/gemini/governance.js +201 -201
  85. package/src/gemini/interactive.js +860 -860
  86. package/src/gemini/mcp-packs.js +915 -915
  87. package/src/gemini/plans.js +269 -269
  88. package/src/gemini/premium.js +760 -760
  89. package/src/gemini/setup.js +692 -692
  90. package/src/gemini/techniques.js +105 -33
  91. package/src/governance.js +72 -72
  92. package/src/harmony/add.js +68 -68
  93. package/src/harmony/advisor.js +333 -333
  94. package/src/harmony/canon.js +565 -565
  95. package/src/harmony/cli.js +591 -591
  96. package/src/harmony/drift.js +401 -401
  97. package/src/harmony/governance.js +313 -313
  98. package/src/harmony/memory.js +239 -239
  99. package/src/harmony/sync.js +475 -475
  100. package/src/harmony/watch.js +370 -370
  101. package/src/hook-validation.js +342 -342
  102. package/src/index.js +271 -271
  103. package/src/init.js +184 -184
  104. package/src/instruction-surfaces.js +185 -185
  105. package/src/integrations.js +144 -144
  106. package/src/interactive.js +118 -118
  107. package/src/locales/en.json +1 -1
  108. package/src/locales/es.json +1 -1
  109. package/src/mcp-packs.js +830 -830
  110. package/src/mcp-server.js +726 -726
  111. package/src/mcp-validation.js +337 -337
  112. package/src/nerviq-sync.json +7 -7
  113. package/src/opencode/config-parser.js +109 -109
  114. package/src/opencode/context.js +247 -247
  115. package/src/opencode/deep-review.js +313 -313
  116. package/src/opencode/domain-packs.js +262 -262
  117. package/src/opencode/freshness.js +66 -66
  118. package/src/opencode/governance.js +159 -159
  119. package/src/opencode/interactive.js +392 -392
  120. package/src/opencode/mcp-packs.js +705 -705
  121. package/src/opencode/patch.js +184 -184
  122. package/src/opencode/plans.js +231 -231
  123. package/src/opencode/premium.js +413 -413
  124. package/src/opencode/setup.js +449 -449
  125. package/src/opencode/techniques.js +27 -27
  126. package/src/operating-profile.js +574 -574
  127. package/src/org.js +152 -152
  128. package/src/permission-rules.js +218 -218
  129. package/src/plans.js +839 -839
  130. package/src/platform-change-manifest.js +86 -86
  131. package/src/plugins.js +110 -110
  132. package/src/policy-layers.js +210 -210
  133. package/src/profiles.js +124 -124
  134. package/src/prompt-injection.js +74 -74
  135. package/src/public-api.js +173 -173
  136. package/src/recommendation-rules.js +84 -84
  137. package/src/repo-archetype.js +386 -386
  138. package/src/secret-patterns.js +39 -39
  139. package/src/server.js +527 -527
  140. package/src/setup/analysis.js +607 -607
  141. package/src/setup/runtime.js +172 -172
  142. package/src/setup.js +677 -677
  143. package/src/shared/capabilities.js +194 -194
  144. package/src/source-urls.js +132 -132
  145. package/src/stack-checks.js +565 -565
  146. package/src/supplemental-checks.js +13 -13
  147. package/src/synergy/adaptive.js +261 -261
  148. package/src/synergy/compensation.js +137 -137
  149. package/src/synergy/evidence.js +193 -193
  150. package/src/synergy/learning.js +199 -199
  151. package/src/synergy/patterns.js +227 -227
  152. package/src/synergy/ranking.js +83 -83
  153. package/src/synergy/report.js +165 -165
  154. package/src/synergy/routing.js +146 -146
  155. package/src/techniques/api.js +407 -407
  156. package/src/techniques/automation.js +316 -316
  157. package/src/techniques/compliance.js +257 -257
  158. package/src/techniques/hygiene.js +294 -294
  159. package/src/techniques/instructions.js +243 -243
  160. package/src/techniques/observability.js +226 -226
  161. package/src/techniques/optimization.js +142 -142
  162. package/src/techniques/quality.js +318 -318
  163. package/src/techniques/security.js +237 -237
  164. package/src/techniques/shared.js +443 -443
  165. package/src/techniques/stacks.js +2294 -2294
  166. package/src/techniques/tools.js +106 -106
  167. package/src/techniques/workflow.js +413 -413
  168. package/src/techniques.js +81 -81
  169. package/src/terminology.js +73 -73
  170. package/src/token-estimate.js +35 -35
  171. package/src/usage-patterns.js +99 -99
  172. package/src/verification-metadata.js +145 -145
  173. package/src/watch.js +247 -247
  174. package/src/windsurf/activity.js +302 -302
  175. package/src/windsurf/config-parser.js +267 -267
  176. package/src/windsurf/context.js +249 -249
  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/windsurf/techniques.js +17 -17
  187. package/src/workspace.js +375 -375
@@ -1,488 +1,488 @@
1
- /**
2
- * Cursor Setup Module
3
- *
4
- * 8 setup families:
5
- * 1. .cursor/rules/*.mdc (core + stack-specific)
6
- * 2. Legacy migration (.cursorrules -> .cursor/rules/)
7
- * 3. .cursor/mcp.json
8
- * 4. .cursor/environment.json
9
- * 5. .cursor/automations/ config
10
- * 6. BugBot config guide
11
- * 7. CI workflow (GitHub Actions)
12
- * 8. Design Mode 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 { CursorProjectContext } = require('./context');
22
- const { recommendCursorMcpPacks, 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 buildCoreRuleMdc(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
- 'description: "Core project rules — always active for all agents"',
90
- 'alwaysApply: true',
91
- '---',
92
- '',
93
- `# ${detectProjectName(ctx)} — Core Rules`,
94
- '',
95
- '## Scope',
96
- '- Primary platform: Cursor',
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
- '- Prefer the repo verification commands before handoff.',
117
- '',
118
- '## Platform Awareness',
119
- '- **Privacy Mode**: Verify it is enabled in Cursor Settings for zero data retention.',
120
- '- **Background agents**: Create branches and PRs, never push directly to main.',
121
- '- **MCP tool limit**: Stay under ~40 tools across all servers.',
122
- '- **Session drift**: Sessions >2h may lose context — start fresh if instructions are forgotten.',
123
- '',
124
- `_Generated by nerviq v${version} for Cursor. Customize before production use._`,
125
- '',
126
- ].join('\n');
127
- }
128
-
129
- function buildStackRuleMdc(stacks) {
130
- if (hasStack(stacks, 'typescript')) {
131
- return [
132
- '---',
133
- 'description: "TypeScript-specific conventions"',
134
- 'globs:',
135
- ' - "**/*.ts"',
136
- ' - "**/*.tsx"',
137
- 'alwaysApply: false',
138
- '---',
139
- '',
140
- '# TypeScript Rules',
141
- '',
142
- '- Use strict mode',
143
- '- Prefer named exports over default exports',
144
- '- Use explicit return types on public functions',
145
- '- Avoid `any` — use `unknown` or proper types',
146
- '- Prefer interfaces over types for public APIs',
147
- '',
148
- `_Generated by nerviq v${version}_`,
149
- '',
150
- ].join('\n');
151
- }
152
- return null;
153
- }
154
-
155
- function buildMcpJson(ctx, stacks, domainPacks) {
156
- const mcpRecs = recommendCursorMcpPacks(stacks, domainPacks || [], { ctx });
157
- const mcpServers = Object.assign({}, ...mcpRecs.map(p => packToJson(p)));
158
- return JSON.stringify({ mcpServers }, null, 2) + '\n';
159
- }
160
-
161
- function buildEnvironmentJson(ctx) {
162
- const scripts = detectScripts(ctx);
163
- const env = { baseImage: 'node:20', env: { NODE_ENV: 'test' }, persistedDirectories: ['node_modules'] };
164
- if (scripts.dev) {
165
- env.processes = { 'dev-server': { command: 'npm run dev', waitForPort: 3000 } };
166
- }
167
- return JSON.stringify(env, null, 2) + '\n';
168
- }
169
-
170
- function buildLegacyMigrationGuide() {
171
- return [
172
- '---',
173
- 'description: "Legacy .cursorrules migration guide"',
174
- 'alwaysApply: false',
175
- '---',
176
- '',
177
- '# Legacy Migration Guide',
178
- '',
179
- '## CRITICAL: .cursorrules is IGNORED by agent mode',
180
- '',
181
- 'If you had a `.cursorrules` file, its contents are completely invisible to Cursor agents.',
182
- 'Only `.cursor/rules/*.mdc` files with proper MDC frontmatter reach agents.',
183
- '',
184
- '## Migration steps',
185
- '',
186
- '1. Copy `.cursorrules` content to `.cursor/rules/core.mdc`',
187
- '2. Add MDC frontmatter with `alwaysApply: true`',
188
- '3. Delete `.cursorrules` (or rename to `.cursorrules.bak`)',
189
- '4. Verify agent mode sees the rules',
190
- '',
191
- '## Rule type reference',
192
- '',
193
- '| Type | alwaysApply | globs | description |',
194
- '|------|:-----------:|:-----:|:-----------:|',
195
- '| Always | true | any | any |',
196
- '| Auto Attached | false | set | optional |',
197
- '| Agent Requested | false | empty | set |',
198
- '| Manual | false | empty | empty |',
199
- '',
200
- `_Generated by nerviq v${version}_`,
201
- '',
202
- ].join('\n');
203
- }
204
-
205
- function buildCiReviewWorkflow() {
206
- return [
207
- 'name: Cursor Code Review',
208
- '',
209
- 'on:',
210
- ' pull_request:',
211
- ' types: [opened, synchronize]',
212
- '',
213
- 'permissions:',
214
- ' contents: read',
215
- ' pull-requests: write',
216
- '',
217
- 'jobs:',
218
- ' cursor-review:',
219
- ' runs-on: ubuntu-latest',
220
- ' steps:',
221
- ' - uses: actions/checkout@v4',
222
- ' - name: Run nerviq audit',
223
- ' run: npx nerviq --platform cursor --json > audit-report.json',
224
- ' - uses: actions/upload-artifact@v4',
225
- ' with:',
226
- ' name: cursor-audit-report',
227
- ' path: audit-report.json',
228
- ' retention-days: 30',
229
- '',
230
- `# Generated by nerviq v${version} for Cursor.`,
231
- '',
232
- ].join('\n');
233
- }
234
-
235
- function buildDesignModeGuide() {
236
- return [
237
- '---',
238
- 'description: "Design Mode usage guide for UI annotation"',
239
- 'alwaysApply: false',
240
- '---',
241
- '',
242
- '# Design Mode Guide',
243
- '',
244
- '## What is Design Mode?',
245
- 'Cursor 3.0 Design Mode allows annotating browser UI elements directly.',
246
- 'Click elements in the browser to create visual references for the agent.',
247
- '',
248
- '## When to use',
249
- '- UI bug reports with visual context',
250
- '- Component styling adjustments',
251
- '- Layout modifications',
252
- '',
253
- '## Tips',
254
- '- Use with @Files to reference the component source code',
255
- '- Combine with Auto Attached rules for CSS/styling conventions',
256
- '- Works best with running dev server',
257
- '',
258
- `_Generated by nerviq v${version}_`,
259
- '',
260
- ].join('\n');
261
- }
262
-
263
- function buildBugbotGuide() {
264
- return [
265
- '---',
266
- 'description: "BugBot configuration guide for automated PR review"',
267
- 'alwaysApply: false',
268
- '---',
269
- '',
270
- '# BugBot Configuration',
271
- '',
272
- '## Setup',
273
- '- Enable BugBot per-repo in Cursor settings',
274
- '- Configure autofix for auto-fixable issues',
275
- '- Set review scope (which files/patterns to review)',
276
- '',
277
- '## Best Practices',
278
- '- Use BugBot Rules for project-specific invariants',
279
- '- Review autofix PRs before merging',
280
- '- Combine with CI for comprehensive coverage',
281
- '',
282
- `_Generated by nerviq v${version}_`,
283
- '',
284
- ].join('\n');
285
- }
286
-
287
- function buildCursorSetupFiles(options = {}) {
288
- const ctx = new CursorProjectContext(options.dir);
289
- const stacks = ctx.detectStacks(STACKS);
290
- const files = [];
291
-
292
- // 1. Core rules (.cursor/rules/core.mdc)
293
- const coreRulePath = path.join(options.dir, '.cursor', 'rules', 'core.mdc');
294
- if (!fs.existsSync(coreRulePath)) {
295
- files.push({
296
- path: '.cursor/rules/core.mdc',
297
- action: 'create',
298
- family: 'cursor-rules',
299
- content: buildCoreRuleMdc(ctx, stacks),
300
- currentState: '.cursor/rules/core.mdc is missing',
301
- proposedState: 'create a core rules file with alwaysApply: true, verification, and architecture guidance',
302
- });
303
- }
304
-
305
- // Stack-specific rule
306
- const stackRule = buildStackRuleMdc(stacks);
307
- if (stackRule) {
308
- const stackRulePath = path.join(options.dir, '.cursor', 'rules', 'typescript.mdc');
309
- if (!fs.existsSync(stackRulePath)) {
310
- files.push({
311
- path: '.cursor/rules/typescript.mdc',
312
- action: 'create',
313
- family: 'cursor-rules',
314
- content: stackRule,
315
- currentState: '.cursor/rules/typescript.mdc is missing',
316
- proposedState: 'create Auto Attached TypeScript rules with glob pattern',
317
- });
318
- }
319
- }
320
-
321
- // 2. Legacy migration
322
- const legacyPath = path.join(options.dir, '.cursorrules');
323
- if (fs.existsSync(legacyPath)) {
324
- const migrationPath = path.join(options.dir, '.cursor', 'rules', 'migration-guide.mdc');
325
- if (!fs.existsSync(migrationPath)) {
326
- files.push({
327
- path: '.cursor/rules/migration-guide.mdc',
328
- action: 'create',
329
- family: 'cursor-legacy-migration',
330
- content: buildLegacyMigrationGuide(),
331
- currentState: '.cursorrules exists but is IGNORED by agent mode',
332
- proposedState: 'create migration guide to help move .cursorrules content to .mdc format',
333
- });
334
- }
335
- }
336
-
337
- const modules = options.modules || 'all';
338
- const wantModule = (name) => modules === 'all' || (Array.isArray(modules) && modules.includes(name));
339
-
340
- // 3. MCP config
341
- if (wantModule('mcp')) {
342
- const mcpPath = path.join(options.dir, '.cursor', 'mcp.json');
343
- if (!fs.existsSync(mcpPath)) {
344
- const domainPacks = options.domainPacks || [];
345
- files.push({
346
- path: '.cursor/mcp.json',
347
- action: 'create',
348
- family: 'cursor-mcp',
349
- content: buildMcpJson(ctx, stacks, domainPacks),
350
- currentState: '.cursor/mcp.json is missing',
351
- proposedState: 'create MCP config with recommended packs using ${env:VAR} syntax',
352
- });
353
- }
354
- }
355
-
356
- // 4. Environment config
357
- if (wantModule('environment')) {
358
- const envPath = path.join(options.dir, '.cursor', 'environment.json');
359
- if (!fs.existsSync(envPath)) {
360
- files.push({
361
- path: '.cursor/environment.json',
362
- action: 'create',
363
- family: 'cursor-environment',
364
- content: buildEnvironmentJson(ctx),
365
- currentState: '.cursor/environment.json is missing',
366
- proposedState: 'create background agent environment config with baseImage and persistedDirectories',
367
- });
368
- }
369
- }
370
-
371
- // 5. CI workflow
372
- if (wantModule('ci')) {
373
- const ciPath = path.join(options.dir, '.github', 'workflows', 'cursor-review.yml');
374
- if (!fs.existsSync(ciPath)) {
375
- files.push({
376
- path: '.github/workflows/cursor-review.yml',
377
- action: 'create',
378
- family: 'cursor-ci-review',
379
- content: buildCiReviewWorkflow(),
380
- currentState: 'No Cursor CI review workflow exists',
381
- proposedState: 'create a GitHub Actions workflow for Cursor-based audit on PRs',
382
- });
383
- }
384
- }
385
-
386
- // 6. BugBot guide
387
- if (wantModule('bugbot')) {
388
- const bugbotPath = path.join(options.dir, '.cursor', 'rules', 'bugbot-guide.mdc');
389
- if (!fs.existsSync(bugbotPath)) {
390
- files.push({
391
- path: '.cursor/rules/bugbot-guide.mdc',
392
- action: 'create',
393
- family: 'cursor-bugbot',
394
- content: buildBugbotGuide(),
395
- currentState: 'No BugBot configuration guide',
396
- proposedState: 'create BugBot configuration guide as an Agent Requested rule',
397
- });
398
- }
399
- }
400
-
401
- // 7. Design Mode guide
402
- if (wantModule('design-mode')) {
403
- const designPath = path.join(options.dir, '.cursor', 'rules', 'design-mode-guide.mdc');
404
- if (!fs.existsSync(designPath)) {
405
- files.push({
406
- path: '.cursor/rules/design-mode-guide.mdc',
407
- action: 'create',
408
- family: 'cursor-design-mode',
409
- content: buildDesignModeGuide(),
410
- currentState: 'No Design Mode guide',
411
- proposedState: 'create Design Mode usage guide as an Agent Requested rule',
412
- });
413
- }
414
- }
415
-
416
- return { ctx, stacks, files };
417
- }
418
-
419
- async function setupCursor(options) {
420
- const silent = options.silent === true;
421
- const { ctx, stacks, files } = buildCursorSetupFiles(options);
422
- const writtenFiles = [];
423
- const preservedFiles = [];
424
-
425
- function log(message = '') { if (!silent) console.log(message); }
426
-
427
- log('');
428
- log('\x1b[1m nerviq cursor setup\x1b[0m');
429
- log('\x1b[2m ═══════════════════════════════════════\x1b[0m');
430
- if (stacks.length > 0) log(`\x1b[36m Detected: ${stacks.map((s) => s.label).join(', ')}\x1b[0m`);
431
- log('');
432
-
433
- for (const file of files) {
434
- const fullPath = path.join(options.dir, file.path);
435
- if (fs.existsSync(fullPath)) {
436
- preservedFiles.push(file.path);
437
- log(` \x1b[2m Skipped ${file.path} (already exists)\x1b[0m`);
438
- continue;
439
- }
440
- fs.mkdirSync(path.dirname(fullPath), { recursive: true });
441
- fs.writeFileSync(fullPath, file.content, 'utf8');
442
- writtenFiles.push(file.path);
443
- log(` \x1b[32m Created ${file.path}\x1b[0m`);
444
- }
445
-
446
- let rollbackArtifact = null;
447
- let activityArtifact = null;
448
- if (writtenFiles.length > 0) {
449
- rollbackArtifact = writeRollbackArtifact(options.dir, {
450
- sourcePlan: 'cursor-setup',
451
- createdFiles: writtenFiles,
452
- patchedFiles: [],
453
- rollbackInstructions: writtenFiles.map((file) => `Delete ${file}`),
454
- });
455
- activityArtifact = writeActivityArtifact(options.dir, 'cursor-setup', {
456
- platform: 'cursor',
457
- createdFiles: writtenFiles,
458
- preservedFiles,
459
- stackLabels: stacks.map((item) => item.label),
460
- rollbackArtifact: rollbackArtifact.relativePath,
461
- });
462
- }
463
-
464
- log('');
465
- log(` \x1b[1m${writtenFiles.length} files created.\x1b[0m`);
466
- if (preservedFiles.length > 0) log(` \x1b[2m${preservedFiles.length} existing files preserved.\x1b[0m`);
467
- if (rollbackArtifact) log(` Rollback: \x1b[1m${rollbackArtifact.relativePath}\x1b[0m`);
468
- if (activityArtifact) log(` Activity log: \x1b[1m${activityArtifact.relativePath}\x1b[0m`);
469
- log('');
470
- log(' Run \x1b[1mnpx nerviq --platform cursor\x1b[0m to audit your Cursor setup.');
471
- log('');
472
-
473
- return {
474
- created: writtenFiles.length,
475
- skipped: preservedFiles.length,
476
- writtenFiles,
477
- preservedFiles,
478
- stacks,
479
- rollbackArtifact: rollbackArtifact ? rollbackArtifact.relativePath : null,
480
- activityArtifact: activityArtifact ? activityArtifact.relativePath : null,
481
- };
482
- }
483
-
484
- module.exports = {
485
- buildCoreRuleMdc,
486
- buildCursorSetupFiles,
487
- setupCursor,
488
- };
1
+ /**
2
+ * Cursor Setup Module
3
+ *
4
+ * 8 setup families:
5
+ * 1. .cursor/rules/*.mdc (core + stack-specific)
6
+ * 2. Legacy migration (.cursorrules -> .cursor/rules/)
7
+ * 3. .cursor/mcp.json
8
+ * 4. .cursor/environment.json
9
+ * 5. .cursor/automations/ config
10
+ * 6. BugBot config guide
11
+ * 7. CI workflow (GitHub Actions)
12
+ * 8. Design Mode 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 { CursorProjectContext } = require('./context');
22
+ const { recommendCursorMcpPacks, 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 buildCoreRuleMdc(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
+ 'description: "Core project rules — always active for all agents"',
90
+ 'alwaysApply: true',
91
+ '---',
92
+ '',
93
+ `# ${detectProjectName(ctx)} — Core Rules`,
94
+ '',
95
+ '## Scope',
96
+ '- Primary platform: Cursor',
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
+ '- Prefer the repo verification commands before handoff.',
117
+ '',
118
+ '## Platform Awareness',
119
+ '- **Privacy Mode**: Verify it is enabled in Cursor Settings for zero data retention.',
120
+ '- **Background agents**: Create branches and PRs, never push directly to main.',
121
+ '- **MCP tool limit**: Stay under ~40 tools across all servers.',
122
+ '- **Session drift**: Sessions >2h may lose context — start fresh if instructions are forgotten.',
123
+ '',
124
+ `_Generated by nerviq v${version} for Cursor. Customize before production use._`,
125
+ '',
126
+ ].join('\n');
127
+ }
128
+
129
+ function buildStackRuleMdc(stacks) {
130
+ if (hasStack(stacks, 'typescript')) {
131
+ return [
132
+ '---',
133
+ 'description: "TypeScript-specific conventions"',
134
+ 'globs:',
135
+ ' - "**/*.ts"',
136
+ ' - "**/*.tsx"',
137
+ 'alwaysApply: false',
138
+ '---',
139
+ '',
140
+ '# TypeScript Rules',
141
+ '',
142
+ '- Use strict mode',
143
+ '- Prefer named exports over default exports',
144
+ '- Use explicit return types on public functions',
145
+ '- Avoid `any` — use `unknown` or proper types',
146
+ '- Prefer interfaces over types for public APIs',
147
+ '',
148
+ `_Generated by nerviq v${version}_`,
149
+ '',
150
+ ].join('\n');
151
+ }
152
+ return null;
153
+ }
154
+
155
+ function buildMcpJson(ctx, stacks, domainPacks) {
156
+ const mcpRecs = recommendCursorMcpPacks(stacks, domainPacks || [], { ctx });
157
+ const mcpServers = Object.assign({}, ...mcpRecs.map(p => packToJson(p)));
158
+ return JSON.stringify({ mcpServers }, null, 2) + '\n';
159
+ }
160
+
161
+ function buildEnvironmentJson(ctx) {
162
+ const scripts = detectScripts(ctx);
163
+ const env = { baseImage: 'node:20', env: { NODE_ENV: 'test' }, persistedDirectories: ['node_modules'] };
164
+ if (scripts.dev) {
165
+ env.processes = { 'dev-server': { command: 'npm run dev', waitForPort: 3000 } };
166
+ }
167
+ return JSON.stringify(env, null, 2) + '\n';
168
+ }
169
+
170
+ function buildLegacyMigrationGuide() {
171
+ return [
172
+ '---',
173
+ 'description: "Legacy .cursorrules migration guide"',
174
+ 'alwaysApply: false',
175
+ '---',
176
+ '',
177
+ '# Legacy Migration Guide',
178
+ '',
179
+ '## CRITICAL: .cursorrules is IGNORED by agent mode',
180
+ '',
181
+ 'If you had a `.cursorrules` file, its contents are completely invisible to Cursor agents.',
182
+ 'Only `.cursor/rules/*.mdc` files with proper MDC frontmatter reach agents.',
183
+ '',
184
+ '## Migration steps',
185
+ '',
186
+ '1. Copy `.cursorrules` content to `.cursor/rules/core.mdc`',
187
+ '2. Add MDC frontmatter with `alwaysApply: true`',
188
+ '3. Delete `.cursorrules` (or rename to `.cursorrules.bak`)',
189
+ '4. Verify agent mode sees the rules',
190
+ '',
191
+ '## Rule type reference',
192
+ '',
193
+ '| Type | alwaysApply | globs | description |',
194
+ '|------|:-----------:|:-----:|:-----------:|',
195
+ '| Always | true | any | any |',
196
+ '| Auto Attached | false | set | optional |',
197
+ '| Agent Requested | false | empty | set |',
198
+ '| Manual | false | empty | empty |',
199
+ '',
200
+ `_Generated by nerviq v${version}_`,
201
+ '',
202
+ ].join('\n');
203
+ }
204
+
205
+ function buildCiReviewWorkflow() {
206
+ return [
207
+ 'name: Cursor Code Review',
208
+ '',
209
+ 'on:',
210
+ ' pull_request:',
211
+ ' types: [opened, synchronize]',
212
+ '',
213
+ 'permissions:',
214
+ ' contents: read',
215
+ ' pull-requests: write',
216
+ '',
217
+ 'jobs:',
218
+ ' cursor-review:',
219
+ ' runs-on: ubuntu-latest',
220
+ ' steps:',
221
+ ' - uses: actions/checkout@v4',
222
+ ' - name: Run nerviq audit',
223
+ ' run: npx nerviq --platform cursor --json > audit-report.json',
224
+ ' - uses: actions/upload-artifact@v4',
225
+ ' with:',
226
+ ' name: cursor-audit-report',
227
+ ' path: audit-report.json',
228
+ ' retention-days: 30',
229
+ '',
230
+ `# Generated by nerviq v${version} for Cursor.`,
231
+ '',
232
+ ].join('\n');
233
+ }
234
+
235
+ function buildDesignModeGuide() {
236
+ return [
237
+ '---',
238
+ 'description: "Design Mode usage guide for UI annotation"',
239
+ 'alwaysApply: false',
240
+ '---',
241
+ '',
242
+ '# Design Mode Guide',
243
+ '',
244
+ '## What is Design Mode?',
245
+ 'Cursor 3.0 Design Mode allows annotating browser UI elements directly.',
246
+ 'Click elements in the browser to create visual references for the agent.',
247
+ '',
248
+ '## When to use',
249
+ '- UI bug reports with visual context',
250
+ '- Component styling adjustments',
251
+ '- Layout modifications',
252
+ '',
253
+ '## Tips',
254
+ '- Use with @Files to reference the component source code',
255
+ '- Combine with Auto Attached rules for CSS/styling conventions',
256
+ '- Works best with running dev server',
257
+ '',
258
+ `_Generated by nerviq v${version}_`,
259
+ '',
260
+ ].join('\n');
261
+ }
262
+
263
+ function buildBugbotGuide() {
264
+ return [
265
+ '---',
266
+ 'description: "BugBot configuration guide for automated PR review"',
267
+ 'alwaysApply: false',
268
+ '---',
269
+ '',
270
+ '# BugBot Configuration',
271
+ '',
272
+ '## Setup',
273
+ '- Enable BugBot per-repo in Cursor settings',
274
+ '- Configure autofix for auto-fixable issues',
275
+ '- Set review scope (which files/patterns to review)',
276
+ '',
277
+ '## Best Practices',
278
+ '- Use BugBot Rules for project-specific invariants',
279
+ '- Review autofix PRs before merging',
280
+ '- Combine with CI for comprehensive coverage',
281
+ '',
282
+ `_Generated by nerviq v${version}_`,
283
+ '',
284
+ ].join('\n');
285
+ }
286
+
287
+ function buildCursorSetupFiles(options = {}) {
288
+ const ctx = new CursorProjectContext(options.dir);
289
+ const stacks = ctx.detectStacks(STACKS);
290
+ const files = [];
291
+
292
+ // 1. Core rules (.cursor/rules/core.mdc)
293
+ const coreRulePath = path.join(options.dir, '.cursor', 'rules', 'core.mdc');
294
+ if (!fs.existsSync(coreRulePath)) {
295
+ files.push({
296
+ path: '.cursor/rules/core.mdc',
297
+ action: 'create',
298
+ family: 'cursor-rules',
299
+ content: buildCoreRuleMdc(ctx, stacks),
300
+ currentState: '.cursor/rules/core.mdc is missing',
301
+ proposedState: 'create a core rules file with alwaysApply: true, verification, and architecture guidance',
302
+ });
303
+ }
304
+
305
+ // Stack-specific rule
306
+ const stackRule = buildStackRuleMdc(stacks);
307
+ if (stackRule) {
308
+ const stackRulePath = path.join(options.dir, '.cursor', 'rules', 'typescript.mdc');
309
+ if (!fs.existsSync(stackRulePath)) {
310
+ files.push({
311
+ path: '.cursor/rules/typescript.mdc',
312
+ action: 'create',
313
+ family: 'cursor-rules',
314
+ content: stackRule,
315
+ currentState: '.cursor/rules/typescript.mdc is missing',
316
+ proposedState: 'create Auto Attached TypeScript rules with glob pattern',
317
+ });
318
+ }
319
+ }
320
+
321
+ // 2. Legacy migration
322
+ const legacyPath = path.join(options.dir, '.cursorrules');
323
+ if (fs.existsSync(legacyPath)) {
324
+ const migrationPath = path.join(options.dir, '.cursor', 'rules', 'migration-guide.mdc');
325
+ if (!fs.existsSync(migrationPath)) {
326
+ files.push({
327
+ path: '.cursor/rules/migration-guide.mdc',
328
+ action: 'create',
329
+ family: 'cursor-legacy-migration',
330
+ content: buildLegacyMigrationGuide(),
331
+ currentState: '.cursorrules exists but is IGNORED by agent mode',
332
+ proposedState: 'create migration guide to help move .cursorrules content to .mdc format',
333
+ });
334
+ }
335
+ }
336
+
337
+ const modules = options.modules || 'all';
338
+ const wantModule = (name) => modules === 'all' || (Array.isArray(modules) && modules.includes(name));
339
+
340
+ // 3. MCP config
341
+ if (wantModule('mcp')) {
342
+ const mcpPath = path.join(options.dir, '.cursor', 'mcp.json');
343
+ if (!fs.existsSync(mcpPath)) {
344
+ const domainPacks = options.domainPacks || [];
345
+ files.push({
346
+ path: '.cursor/mcp.json',
347
+ action: 'create',
348
+ family: 'cursor-mcp',
349
+ content: buildMcpJson(ctx, stacks, domainPacks),
350
+ currentState: '.cursor/mcp.json is missing',
351
+ proposedState: 'create MCP config with recommended packs using ${env:VAR} syntax',
352
+ });
353
+ }
354
+ }
355
+
356
+ // 4. Environment config
357
+ if (wantModule('environment')) {
358
+ const envPath = path.join(options.dir, '.cursor', 'environment.json');
359
+ if (!fs.existsSync(envPath)) {
360
+ files.push({
361
+ path: '.cursor/environment.json',
362
+ action: 'create',
363
+ family: 'cursor-environment',
364
+ content: buildEnvironmentJson(ctx),
365
+ currentState: '.cursor/environment.json is missing',
366
+ proposedState: 'create background agent environment config with baseImage and persistedDirectories',
367
+ });
368
+ }
369
+ }
370
+
371
+ // 5. CI workflow
372
+ if (wantModule('ci')) {
373
+ const ciPath = path.join(options.dir, '.github', 'workflows', 'cursor-review.yml');
374
+ if (!fs.existsSync(ciPath)) {
375
+ files.push({
376
+ path: '.github/workflows/cursor-review.yml',
377
+ action: 'create',
378
+ family: 'cursor-ci-review',
379
+ content: buildCiReviewWorkflow(),
380
+ currentState: 'No Cursor CI review workflow exists',
381
+ proposedState: 'create a GitHub Actions workflow for Cursor-based audit on PRs',
382
+ });
383
+ }
384
+ }
385
+
386
+ // 6. BugBot guide
387
+ if (wantModule('bugbot')) {
388
+ const bugbotPath = path.join(options.dir, '.cursor', 'rules', 'bugbot-guide.mdc');
389
+ if (!fs.existsSync(bugbotPath)) {
390
+ files.push({
391
+ path: '.cursor/rules/bugbot-guide.mdc',
392
+ action: 'create',
393
+ family: 'cursor-bugbot',
394
+ content: buildBugbotGuide(),
395
+ currentState: 'No BugBot configuration guide',
396
+ proposedState: 'create BugBot configuration guide as an Agent Requested rule',
397
+ });
398
+ }
399
+ }
400
+
401
+ // 7. Design Mode guide
402
+ if (wantModule('design-mode')) {
403
+ const designPath = path.join(options.dir, '.cursor', 'rules', 'design-mode-guide.mdc');
404
+ if (!fs.existsSync(designPath)) {
405
+ files.push({
406
+ path: '.cursor/rules/design-mode-guide.mdc',
407
+ action: 'create',
408
+ family: 'cursor-design-mode',
409
+ content: buildDesignModeGuide(),
410
+ currentState: 'No Design Mode guide',
411
+ proposedState: 'create Design Mode usage guide as an Agent Requested rule',
412
+ });
413
+ }
414
+ }
415
+
416
+ return { ctx, stacks, files };
417
+ }
418
+
419
+ async function setupCursor(options) {
420
+ const silent = options.silent === true;
421
+ const { ctx, stacks, files } = buildCursorSetupFiles(options);
422
+ const writtenFiles = [];
423
+ const preservedFiles = [];
424
+
425
+ function log(message = '') { if (!silent) console.log(message); }
426
+
427
+ log('');
428
+ log('\x1b[1m nerviq cursor setup\x1b[0m');
429
+ log('\x1b[2m ═══════════════════════════════════════\x1b[0m');
430
+ if (stacks.length > 0) log(`\x1b[36m Detected: ${stacks.map((s) => s.label).join(', ')}\x1b[0m`);
431
+ log('');
432
+
433
+ for (const file of files) {
434
+ const fullPath = path.join(options.dir, file.path);
435
+ if (fs.existsSync(fullPath)) {
436
+ preservedFiles.push(file.path);
437
+ log(` \x1b[2m Skipped ${file.path} (already exists)\x1b[0m`);
438
+ continue;
439
+ }
440
+ fs.mkdirSync(path.dirname(fullPath), { recursive: true });
441
+ fs.writeFileSync(fullPath, file.content, 'utf8');
442
+ writtenFiles.push(file.path);
443
+ log(` \x1b[32m Created ${file.path}\x1b[0m`);
444
+ }
445
+
446
+ let rollbackArtifact = null;
447
+ let activityArtifact = null;
448
+ if (writtenFiles.length > 0) {
449
+ rollbackArtifact = writeRollbackArtifact(options.dir, {
450
+ sourcePlan: 'cursor-setup',
451
+ createdFiles: writtenFiles,
452
+ patchedFiles: [],
453
+ rollbackInstructions: writtenFiles.map((file) => `Delete ${file}`),
454
+ });
455
+ activityArtifact = writeActivityArtifact(options.dir, 'cursor-setup', {
456
+ platform: 'cursor',
457
+ createdFiles: writtenFiles,
458
+ preservedFiles,
459
+ stackLabels: stacks.map((item) => item.label),
460
+ rollbackArtifact: rollbackArtifact.relativePath,
461
+ });
462
+ }
463
+
464
+ log('');
465
+ log(` \x1b[1m${writtenFiles.length} files created.\x1b[0m`);
466
+ if (preservedFiles.length > 0) log(` \x1b[2m${preservedFiles.length} existing files preserved.\x1b[0m`);
467
+ if (rollbackArtifact) log(` Rollback: \x1b[1m${rollbackArtifact.relativePath}\x1b[0m`);
468
+ if (activityArtifact) log(` Activity log: \x1b[1m${activityArtifact.relativePath}\x1b[0m`);
469
+ log('');
470
+ log(' Run \x1b[1mnpx nerviq --platform cursor\x1b[0m to audit your Cursor setup.');
471
+ log('');
472
+
473
+ return {
474
+ created: writtenFiles.length,
475
+ skipped: preservedFiles.length,
476
+ writtenFiles,
477
+ preservedFiles,
478
+ stacks,
479
+ rollbackArtifact: rollbackArtifact ? rollbackArtifact.relativePath : null,
480
+ activityArtifact: activityArtifact ? activityArtifact.relativePath : null,
481
+ };
482
+ }
483
+
484
+ module.exports = {
485
+ buildCoreRuleMdc,
486
+ buildCursorSetupFiles,
487
+ setupCursor,
488
+ };