@nerviq/cli 0.0.1 → 0.9.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/CHANGELOG.md +181 -0
  2. package/LICENSE +21 -0
  3. package/README.md +447 -0
  4. package/bin/cli.js +749 -0
  5. package/content/case-study-template.md +91 -0
  6. package/content/claims-governance.md +37 -0
  7. package/content/claude-code/audit-repo/SKILL.md +20 -0
  8. package/content/claude-native-integration.md +60 -0
  9. package/content/devto-article.json +9 -0
  10. package/content/launch-posts.md +226 -0
  11. package/content/pilot-rollout-kit.md +30 -0
  12. package/content/release-checklist.md +31 -0
  13. package/package.json +53 -4
  14. package/src/activity.js +529 -0
  15. package/src/aider/activity.js +226 -0
  16. package/src/aider/config-parser.js +166 -0
  17. package/src/aider/context.js +158 -0
  18. package/src/aider/deep-review.js +316 -0
  19. package/src/aider/domain-packs.js +278 -0
  20. package/src/aider/freshness.js +168 -0
  21. package/src/aider/governance.js +253 -0
  22. package/src/aider/interactive.js +334 -0
  23. package/src/aider/mcp-packs.js +98 -0
  24. package/src/aider/patch.js +214 -0
  25. package/src/aider/plans.js +186 -0
  26. package/src/aider/premium.js +360 -0
  27. package/src/aider/setup.js +404 -0
  28. package/src/aider/techniques.js +1323 -0
  29. package/src/analyze.js +821 -0
  30. package/src/audit.js +1003 -0
  31. package/src/badge.js +13 -0
  32. package/src/benchmark.js +339 -0
  33. package/src/claudex-sync.json +7 -0
  34. package/src/codex/activity.js +324 -0
  35. package/src/codex/config-parser.js +183 -0
  36. package/src/codex/context.js +221 -0
  37. package/src/codex/deep-review.js +493 -0
  38. package/src/codex/domain-packs.js +372 -0
  39. package/src/codex/freshness.js +167 -0
  40. package/src/codex/governance.js +192 -0
  41. package/src/codex/interactive.js +618 -0
  42. package/src/codex/mcp-packs.js +660 -0
  43. package/src/codex/patch.js +209 -0
  44. package/src/codex/plans.js +251 -0
  45. package/src/codex/premium.js +614 -0
  46. package/src/codex/setup.js +603 -0
  47. package/src/codex/techniques.js +2649 -0
  48. package/src/context.js +272 -0
  49. package/src/copilot/activity.js +309 -0
  50. package/src/copilot/config-parser.js +226 -0
  51. package/src/copilot/context.js +197 -0
  52. package/src/copilot/deep-review.js +346 -0
  53. package/src/copilot/domain-packs.js +350 -0
  54. package/src/copilot/freshness.js +197 -0
  55. package/src/copilot/governance.js +222 -0
  56. package/src/copilot/interactive.js +406 -0
  57. package/src/copilot/mcp-packs.js +572 -0
  58. package/src/copilot/patch.js +238 -0
  59. package/src/copilot/plans.js +253 -0
  60. package/src/copilot/premium.js +450 -0
  61. package/src/copilot/setup.js +488 -0
  62. package/src/copilot/techniques.js +1822 -0
  63. package/src/cursor/activity.js +301 -0
  64. package/src/cursor/config-parser.js +265 -0
  65. package/src/cursor/context.js +236 -0
  66. package/src/cursor/deep-review.js +334 -0
  67. package/src/cursor/domain-packs.js +346 -0
  68. package/src/cursor/freshness.js +214 -0
  69. package/src/cursor/governance.js +229 -0
  70. package/src/cursor/interactive.js +391 -0
  71. package/src/cursor/mcp-packs.js +571 -0
  72. package/src/cursor/patch.js +243 -0
  73. package/src/cursor/plans.js +254 -0
  74. package/src/cursor/premium.js +468 -0
  75. package/src/cursor/setup.js +488 -0
  76. package/src/cursor/techniques.js +1786 -0
  77. package/src/deep-review.js +345 -0
  78. package/src/domain-packs.js +364 -0
  79. package/src/formatters/sarif.js +115 -0
  80. package/src/gemini/activity.js +402 -0
  81. package/src/gemini/config-parser.js +275 -0
  82. package/src/gemini/context.js +221 -0
  83. package/src/gemini/deep-review.js +559 -0
  84. package/src/gemini/domain-packs.js +371 -0
  85. package/src/gemini/freshness.js +204 -0
  86. package/src/gemini/governance.js +201 -0
  87. package/src/gemini/interactive.js +860 -0
  88. package/src/gemini/mcp-packs.js +658 -0
  89. package/src/gemini/patch.js +229 -0
  90. package/src/gemini/plans.js +269 -0
  91. package/src/gemini/premium.js +759 -0
  92. package/src/gemini/setup.js +692 -0
  93. package/src/gemini/techniques.js +2084 -0
  94. package/src/governance.js +523 -0
  95. package/src/harmony/advisor.js +383 -0
  96. package/src/harmony/audit.js +303 -0
  97. package/src/harmony/canon.js +444 -0
  98. package/src/harmony/cli.js +331 -0
  99. package/src/harmony/drift.js +401 -0
  100. package/src/harmony/governance.js +313 -0
  101. package/src/harmony/memory.js +238 -0
  102. package/src/harmony/sync.js +458 -0
  103. package/src/harmony/watch.js +336 -0
  104. package/src/index.js +256 -0
  105. package/src/insights.js +119 -0
  106. package/src/interactive.js +118 -0
  107. package/src/mcp-packs.js +597 -0
  108. package/src/opencode/activity.js +286 -0
  109. package/src/opencode/config-parser.js +109 -0
  110. package/src/opencode/context.js +247 -0
  111. package/src/opencode/deep-review.js +313 -0
  112. package/src/opencode/domain-packs.js +240 -0
  113. package/src/opencode/freshness.js +158 -0
  114. package/src/opencode/governance.js +159 -0
  115. package/src/opencode/interactive.js +392 -0
  116. package/src/opencode/mcp-packs.js +474 -0
  117. package/src/opencode/patch.js +184 -0
  118. package/src/opencode/plans.js +231 -0
  119. package/src/opencode/premium.js +413 -0
  120. package/src/opencode/setup.js +449 -0
  121. package/src/opencode/techniques.js +1713 -0
  122. package/src/plans.js +655 -0
  123. package/src/secret-patterns.js +30 -0
  124. package/src/setup.js +1274 -0
  125. package/src/synergy/adaptive.js +261 -0
  126. package/src/synergy/compensation.js +156 -0
  127. package/src/synergy/evidence.js +193 -0
  128. package/src/synergy/learning.js +184 -0
  129. package/src/synergy/patterns.js +227 -0
  130. package/src/synergy/ranking.js +83 -0
  131. package/src/synergy/report.js +163 -0
  132. package/src/synergy/routing.js +152 -0
  133. package/src/techniques.js +1354 -0
  134. package/src/watch.js +229 -0
  135. package/src/windsurf/activity.js +302 -0
  136. package/src/windsurf/config-parser.js +267 -0
  137. package/src/windsurf/context.js +249 -0
  138. package/src/windsurf/deep-review.js +337 -0
  139. package/src/windsurf/domain-packs.js +348 -0
  140. package/src/windsurf/freshness.js +215 -0
  141. package/src/windsurf/governance.js +231 -0
  142. package/src/windsurf/interactive.js +388 -0
  143. package/src/windsurf/mcp-packs.js +535 -0
  144. package/src/windsurf/patch.js +231 -0
  145. package/src/windsurf/plans.js +247 -0
  146. package/src/windsurf/premium.js +467 -0
  147. package/src/windsurf/setup.js +471 -0
  148. package/src/windsurf/techniques.js +1758 -0
@@ -0,0 +1,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
+ };