@nerviq/cli 1.18.0 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/LICENSE +23 -23
  2. package/README.md +2 -2
  3. package/bin/cli.js +130 -130
  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 +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 +221 -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 +14 -14
  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
- * Copilot Setup Module
3
- *
4
- * 8 setup families:
5
- * 1. copilot-instructions.md
6
- * 2. *.instructions.md (scoped)
7
- * 3. *.prompt.md (prompt templates)
8
- * 4. .vscode/settings.json
9
- * 5. .vscode/mcp.json
10
- * 6. copilot-setup-steps.yml
11
- * 7. .github/workflows/copilot-review.yml
12
- * 8. Content exclusions 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 { CopilotProjectContext } = require('./context');
22
- const { recommendCopilotMcpPacks, 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 before refactors.');
74
- if (hasStack(stacks, 'python') || hasStack(stacks, 'fastapi') || hasStack(stacks, 'django')) lines.push('- Prefer explicit validation, typed schemas, and focused service functions over large route handlers.');
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 over broad rewrites.');
77
- if (hasStack(stacks, 'terraform') || hasStack(stacks, 'kubernetes')) lines.push('- Treat infrastructure changes as high-risk: prefer diffs that are easy to plan, review, 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 buildSecurityNotes(stacks) {
83
- const lines = [
84
- '- Never commit secrets, tokens, or `.env` values into tracked files.',
85
- '- Prefer the repo verification commands before handoff, and explain any command you could not run.',
86
- ];
87
- if (hasStack(stacks, 'python') || hasStack(stacks, 'fastapi') || hasStack(stacks, 'django')) {
88
- lines.push('- Validate auth, permissions, and data-handling changes carefully before touching production-sensitive paths.');
89
- }
90
- if (hasStack(stacks, 'terraform') || hasStack(stacks, 'kubernetes')) {
91
- lines.push('- Review blast radius before changing infra, deployment, or cluster configuration.');
92
- }
93
- return lines;
94
- }
95
-
96
- function buildCopilotInstructionsMd(ctx, stacks) {
97
- const stackLabels = stacks.map((item) => item.label).join(', ') || 'General repo';
98
- const verificationCommands = buildVerificationCommands(ctx);
99
- const codingConventions = buildCodingConventions(stacks);
100
- const securityNotes = buildSecurityNotes(stacks);
101
-
102
- return [
103
- `# ${detectProjectName(ctx)}`,
104
- '',
105
- '## Scope',
106
- '- Primary platform: GitHub Copilot',
107
- `- Detected stack: ${stackLabels}`,
108
- '- Keep this file focused on Copilot-specific guidance when the repo also uses Claude or other agents.',
109
- '',
110
- '## Architecture',
111
- buildMermaid(stacks),
112
- '- Replace the default diagram and bullets with the real entry points, boundaries, and high-risk subsystems for this repo.',
113
- '',
114
- '## Verification',
115
- ...verificationCommands,
116
- '',
117
- '## Coding Conventions',
118
- ...codingConventions,
119
- '',
120
- '## Code Review Instructions',
121
- '- When reviewing code, focus on security vulnerabilities, performance regressions, and test coverage gaps.',
122
- '- Keep review instructions within the 4,000 character limit for code review.',
123
- '',
124
- '## Security',
125
- ...securityNotes,
126
- '',
127
- '## Platform Awareness',
128
- '- **VS Code agent**: Terminal sandbox is macOS/Linux/WSL2 only. Not available on native Windows.',
129
- '- **Cloud agent**: Content exclusions are NOT enforced. Review PRs carefully for sensitive file access.',
130
- '- **Cloud agent**: Cold-boot takes ~90 seconds. Optimize copilot-setup-steps.yml to minimize re-spins.',
131
- '',
132
- '## Notes',
133
- '- If this repo also uses Claude, keep Claude-specific instructions in `CLAUDE.md` and use this file for Copilot-specific behavior.',
134
- '- Use `.github/instructions/*.instructions.md` for path-scoped instructions with `applyTo` frontmatter.',
135
- '- Use `.github/prompts/*.prompt.md` for reusable prompt templates invocable via `/name` in Chat.',
136
- '',
137
- `_Generated by nerviq v${version} for GitHub Copilot. Customize this file before relying on it in production flows._`,
138
- '',
139
- ].join('\n');
140
- }
141
-
142
- function buildVscodeSettings() {
143
- return JSON.stringify({
144
- "github.copilot.chat.agent.enabled": true,
145
- "chat.tools.terminal.sandbox.enabled": true,
146
- "chat.agent.autoApproval.terminalCommands": [],
147
- "github.copilot.chat.reviewSelection.instructions": [
148
- { "text": "Focus on security vulnerabilities, performance issues, and test coverage gaps." }
149
- ],
150
- "github.copilot.chat.commitMessageGeneration.instructions": [
151
- { "text": "Use conventional commit format. Keep subject under 72 chars." }
152
- ],
153
- }, null, 2) + '\n';
154
- }
155
-
156
- function buildMcpJson() {
157
- return JSON.stringify({
158
- "servers": {},
159
- }, null, 2) + '\n';
160
- }
161
-
162
- function buildCloudSetupSteps(ctx) {
163
- const scripts = detectScripts(ctx);
164
- const installCmd = scripts.install ? 'npm ci' : 'npm install';
165
- return [
166
- 'name: Copilot Setup Steps',
167
- '',
168
- 'on:',
169
- ' workflow_dispatch:',
170
- '',
171
- 'jobs:',
172
- ' setup:',
173
- ' runs-on: ubuntu-latest',
174
- ' steps:',
175
- ' - uses: actions/checkout@v4',
176
- ' - uses: actions/setup-node@v4',
177
- ' with:',
178
- ' node-version: 20',
179
- ` - run: ${installCmd}`,
180
- scripts.build ? ' - run: npm run build' : '',
181
- scripts.test ? ' - run: npm test' : '',
182
- '',
183
- '# Cloud agent environment configuration.',
184
- '# Dependencies installed here are available to the cloud agent.',
185
- '# Keep this workflow focused on setup — not CI/CD.',
186
- '',
187
- `# Generated by nerviq v${version} for GitHub Copilot cloud agent.`,
188
- '',
189
- ].filter(l => l !== undefined).join('\n');
190
- }
191
-
192
- function buildPromptStarter() {
193
- return [
194
- '---',
195
- 'description: Review code changes for security and quality',
196
- 'agent: copilot',
197
- 'mode: agent',
198
- '---',
199
- '',
200
- 'Review the following code changes for:',
201
- '- Security vulnerabilities',
202
- '- Performance regressions',
203
- '- Test coverage gaps',
204
- '- Naming consistency',
205
- '',
206
- 'Provide specific, actionable feedback.',
207
- '',
208
- `# Generated by nerviq v${version}`,
209
- '',
210
- ].join('\n');
211
- }
212
-
213
- function buildScopedInstructionStarter() {
214
- return [
215
- '---',
216
- 'applyTo: "**/*.ts"',
217
- '---',
218
- '',
219
- '# TypeScript Instructions',
220
- '',
221
- '- Use strict TypeScript mode',
222
- '- Prefer named exports over default exports',
223
- '- Use explicit return types on public functions',
224
- '- Avoid `any` — use `unknown` or proper types',
225
- '',
226
- `_Generated by nerviq v${version}_`,
227
- '',
228
- ].join('\n');
229
- }
230
-
231
- function buildCiReviewWorkflow() {
232
- return [
233
- 'name: Copilot Review',
234
- '',
235
- 'on:',
236
- ' pull_request:',
237
- ' types: [opened, synchronize]',
238
- '',
239
- 'permissions:',
240
- ' contents: read',
241
- ' pull-requests: write',
242
- '',
243
- 'jobs:',
244
- ' copilot-review:',
245
- ' runs-on: ubuntu-latest',
246
- ' steps:',
247
- ' - uses: actions/checkout@v4',
248
- ' - name: Copilot Review',
249
- ' uses: github/copilot-code-review@v1',
250
- ' with:',
251
- ' review-mode: comments',
252
- '',
253
- `# Generated by nerviq v${version} for GitHub Copilot.`,
254
- '',
255
- ].join('\n');
256
- }
257
-
258
- function buildContentExclusionsGuide() {
259
- return [
260
- '# Content Exclusions Guide',
261
- '',
262
- '## What are content exclusions?',
263
- 'Content exclusions prevent GitHub Copilot from reading specific files or directories.',
264
- '',
265
- '## How to configure',
266
- 'Content exclusions are configured at the **organization level** in GitHub.com admin settings,',
267
- 'or at the **repository level** using glob patterns.',
268
- '',
269
- '## Recommended exclusions',
270
- '```',
271
- '.env',
272
- '.env.*',
273
- 'secrets/',
274
- '*.pem',
275
- '*.key',
276
- 'credentials.*',
277
- 'config/production.*',
278
- '```',
279
- '',
280
- '## Important limitations',
281
- '- Content exclusions are **NOT enforced** on the cloud agent.',
282
- '- Changes can take up to **30 minutes** to propagate.',
283
- '- Exclusions apply to Copilot Chat and completions but not all surfaces equally.',
284
- '',
285
- `_Generated by nerviq v${version}_`,
286
- '',
287
- ].join('\n');
288
- }
289
-
290
- function buildCopilotSetupFiles(options = {}) {
291
- const ctx = new CopilotProjectContext(options.dir);
292
- const stacks = ctx.detectStacks(STACKS);
293
- const files = [];
294
-
295
- // 1. copilot-instructions.md
296
- const instrPath = path.join(options.dir, '.github', 'copilot-instructions.md');
297
- if (!fs.existsSync(instrPath)) {
298
- files.push({
299
- path: '.github/copilot-instructions.md',
300
- action: 'create',
301
- content: buildCopilotInstructionsMd(ctx, stacks),
302
- currentState: '.github/copilot-instructions.md is missing',
303
- proposedState: 'create a Copilot-native copilot-instructions.md baseline with verification, architecture, and trust guidance',
304
- });
305
- }
306
-
307
- // 2. .vscode/settings.json (Copilot settings)
308
- const settingsPath = path.join(options.dir, '.vscode', 'settings.json');
309
- if (!fs.existsSync(settingsPath)) {
310
- files.push({
311
- path: '.vscode/settings.json',
312
- action: 'create',
313
- content: buildVscodeSettings(),
314
- currentState: '.vscode/settings.json is missing',
315
- proposedState: 'create a safe Copilot settings baseline with sandbox enabled, agent mode, and review instructions',
316
- });
317
- }
318
-
319
- const modules = options.modules || 'all';
320
- const wantModule = (name) => modules === 'all' || (Array.isArray(modules) && modules.includes(name));
321
-
322
- // 3. Scoped instructions starter
323
- if (wantModule('scoped-instructions')) {
324
- const instrDir = path.join(options.dir, '.github', 'instructions');
325
- if (!fs.existsSync(instrDir)) {
326
- files.push({
327
- path: '.github/instructions/typescript.instructions.md',
328
- action: 'create',
329
- family: 'copilot-scoped-instructions',
330
- content: buildScopedInstructionStarter(),
331
- currentState: '.github/instructions/ directory is missing',
332
- proposedState: 'create a scoped instruction starter with applyTo frontmatter',
333
- });
334
- }
335
- }
336
-
337
- // 4. Prompt templates starter
338
- if (wantModule('prompts')) {
339
- const promptsDir = path.join(options.dir, '.github', 'prompts');
340
- if (!fs.existsSync(promptsDir)) {
341
- files.push({
342
- path: '.github/prompts/review.prompt.md',
343
- action: 'create',
344
- family: 'copilot-prompts',
345
- content: buildPromptStarter(),
346
- currentState: '.github/prompts/ directory is missing',
347
- proposedState: 'create a prompt template starter for Copilot Chat',
348
- });
349
- }
350
- }
351
-
352
- // 5. .vscode/mcp.json
353
- if (wantModule('mcp')) {
354
- const mcpPath = path.join(options.dir, '.vscode', 'mcp.json');
355
- if (!fs.existsSync(mcpPath)) {
356
- const domainPacks = options.domainPacks || [];
357
- const mcpRecs = recommendCopilotMcpPacks(stacks, domainPacks, { ctx });
358
- const servers = Object.assign({}, ...mcpRecs.map(p => packToJson(p)));
359
- files.push({
360
- path: '.vscode/mcp.json',
361
- action: 'create',
362
- family: 'copilot-mcp',
363
- content: JSON.stringify({ servers }, null, 2) + '\n',
364
- currentState: '.vscode/mcp.json is missing',
365
- proposedState: `create MCP config with ${mcpRecs.length} recommended packs: ${mcpRecs.map(p => p.label).join(', ')}`,
366
- });
367
- }
368
- }
369
-
370
- // 6. copilot-setup-steps.yml
371
- if (wantModule('cloud-setup')) {
372
- const cloudPath = path.join(options.dir, '.github', 'workflows', 'copilot-setup-steps.yml');
373
- if (!fs.existsSync(cloudPath)) {
374
- files.push({
375
- path: '.github/workflows/copilot-setup-steps.yml',
376
- action: 'create',
377
- family: 'copilot-cloud-setup',
378
- content: buildCloudSetupSteps(ctx),
379
- currentState: 'copilot-setup-steps.yml is missing',
380
- proposedState: 'create cloud agent setup workflow with dependency install and test configuration',
381
- });
382
- }
383
- }
384
-
385
- // 7. CI review workflow
386
- if (wantModule('ci')) {
387
- const ciPath = path.join(options.dir, '.github', 'workflows', 'copilot-review.yml');
388
- if (!fs.existsSync(ciPath)) {
389
- files.push({
390
- path: '.github/workflows/copilot-review.yml',
391
- action: 'create',
392
- family: 'copilot-ci-review',
393
- content: buildCiReviewWorkflow(),
394
- currentState: 'No Copilot CI review workflow exists',
395
- proposedState: 'create a GitHub Actions workflow for Copilot-based PR review',
396
- });
397
- }
398
- }
399
-
400
- // 8. Content exclusions guide
401
- if (wantModule('content-exclusions')) {
402
- const guidePath = path.join(options.dir, '.github', 'COPILOT-CONTENT-EXCLUSIONS.md');
403
- if (!fs.existsSync(guidePath)) {
404
- files.push({
405
- path: '.github/COPILOT-CONTENT-EXCLUSIONS.md',
406
- action: 'create',
407
- family: 'copilot-content-exclusions',
408
- content: buildContentExclusionsGuide(),
409
- currentState: 'No content exclusions guide exists',
410
- proposedState: 'create a content exclusions setup guide documenting known limitations',
411
- });
412
- }
413
- }
414
-
415
- return { ctx, stacks, files };
416
- }
417
-
418
- async function setupCopilot(options) {
419
- const silent = options.silent === true;
420
- const { ctx, stacks, files } = buildCopilotSetupFiles(options);
421
- const writtenFiles = [];
422
- const preservedFiles = [];
423
-
424
- function log(message = '') { if (!silent) console.log(message); }
425
-
426
- log('');
427
- log('\x1b[1m nerviq copilot setup\x1b[0m');
428
- log('\x1b[2m ═══════════════════════════════════════\x1b[0m');
429
- if (stacks.length > 0) log(`\x1b[36m Detected: ${stacks.map((s) => s.label).join(', ')}\x1b[0m`);
430
- log('');
431
-
432
- for (const file of files) {
433
- const fullPath = path.join(options.dir, file.path);
434
- if (fs.existsSync(fullPath)) {
435
- preservedFiles.push(file.path);
436
- log(` \x1b[2m Skipped ${file.path} (already exists)\x1b[0m`);
437
- continue;
438
- }
439
- fs.mkdirSync(path.dirname(fullPath), { recursive: true });
440
- fs.writeFileSync(fullPath, file.content, 'utf8');
441
- writtenFiles.push(file.path);
442
- log(` \x1b[32m Created ${file.path}\x1b[0m`);
443
- }
444
-
445
- let rollbackArtifact = null;
446
- let activityArtifact = null;
447
- if (writtenFiles.length > 0) {
448
- rollbackArtifact = writeRollbackArtifact(options.dir, {
449
- sourcePlan: 'copilot-setup',
450
- createdFiles: writtenFiles,
451
- patchedFiles: [],
452
- rollbackInstructions: writtenFiles.map((file) => `Delete ${file}`),
453
- });
454
- activityArtifact = writeActivityArtifact(options.dir, 'copilot-setup', {
455
- platform: 'copilot',
456
- createdFiles: writtenFiles,
457
- preservedFiles,
458
- stackLabels: stacks.map((item) => item.label),
459
- rollbackArtifact: rollbackArtifact.relativePath,
460
- });
461
- }
462
-
463
- log('');
464
- log(` \x1b[1m${writtenFiles.length} files created.\x1b[0m`);
465
- if (preservedFiles.length > 0) log(` \x1b[2m${preservedFiles.length} existing files preserved.\x1b[0m`);
466
- if (rollbackArtifact) log(` Rollback: \x1b[1m${rollbackArtifact.relativePath}\x1b[0m`);
467
- if (activityArtifact) log(` Activity log: \x1b[1m${activityArtifact.relativePath}\x1b[0m`);
468
- log('');
469
- log(' Run \x1b[1mnpx nerviq --platform copilot\x1b[0m to audit your Copilot setup.');
470
- log('');
471
-
472
- return {
473
- created: writtenFiles.length,
474
- skipped: preservedFiles.length,
475
- writtenFiles,
476
- preservedFiles,
477
- stacks,
478
- rollbackArtifact: rollbackArtifact ? rollbackArtifact.relativePath : null,
479
- activityArtifact: activityArtifact ? activityArtifact.relativePath : null,
480
- };
481
- }
482
-
483
- module.exports = {
484
- buildCopilotInstructionsMd,
485
- buildVscodeSettings,
486
- buildCopilotSetupFiles,
487
- setupCopilot,
488
- };
1
+ /**
2
+ * Copilot Setup Module
3
+ *
4
+ * 8 setup families:
5
+ * 1. copilot-instructions.md
6
+ * 2. *.instructions.md (scoped)
7
+ * 3. *.prompt.md (prompt templates)
8
+ * 4. .vscode/settings.json
9
+ * 5. .vscode/mcp.json
10
+ * 6. copilot-setup-steps.yml
11
+ * 7. .github/workflows/copilot-review.yml
12
+ * 8. Content exclusions 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 { CopilotProjectContext } = require('./context');
22
+ const { recommendCopilotMcpPacks, 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 before refactors.');
74
+ if (hasStack(stacks, 'python') || hasStack(stacks, 'fastapi') || hasStack(stacks, 'django')) lines.push('- Prefer explicit validation, typed schemas, and focused service functions over large route handlers.');
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 over broad rewrites.');
77
+ if (hasStack(stacks, 'terraform') || hasStack(stacks, 'kubernetes')) lines.push('- Treat infrastructure changes as high-risk: prefer diffs that are easy to plan, review, 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 buildSecurityNotes(stacks) {
83
+ const lines = [
84
+ '- Never commit secrets, tokens, or `.env` values into tracked files.',
85
+ '- Prefer the repo verification commands before handoff, and explain any command you could not run.',
86
+ ];
87
+ if (hasStack(stacks, 'python') || hasStack(stacks, 'fastapi') || hasStack(stacks, 'django')) {
88
+ lines.push('- Validate auth, permissions, and data-handling changes carefully before touching production-sensitive paths.');
89
+ }
90
+ if (hasStack(stacks, 'terraform') || hasStack(stacks, 'kubernetes')) {
91
+ lines.push('- Review blast radius before changing infra, deployment, or cluster configuration.');
92
+ }
93
+ return lines;
94
+ }
95
+
96
+ function buildCopilotInstructionsMd(ctx, stacks) {
97
+ const stackLabels = stacks.map((item) => item.label).join(', ') || 'General repo';
98
+ const verificationCommands = buildVerificationCommands(ctx);
99
+ const codingConventions = buildCodingConventions(stacks);
100
+ const securityNotes = buildSecurityNotes(stacks);
101
+
102
+ return [
103
+ `# ${detectProjectName(ctx)}`,
104
+ '',
105
+ '## Scope',
106
+ '- Primary platform: GitHub Copilot',
107
+ `- Detected stack: ${stackLabels}`,
108
+ '- Keep this file focused on Copilot-specific guidance when the repo also uses Claude or other agents.',
109
+ '',
110
+ '## Architecture',
111
+ buildMermaid(stacks),
112
+ '- Replace the default diagram and bullets with the real entry points, boundaries, and high-risk subsystems for this repo.',
113
+ '',
114
+ '## Verification',
115
+ ...verificationCommands,
116
+ '',
117
+ '## Coding Conventions',
118
+ ...codingConventions,
119
+ '',
120
+ '## Code Review Instructions',
121
+ '- When reviewing code, focus on security vulnerabilities, performance regressions, and test coverage gaps.',
122
+ '- Keep review instructions within the 4,000 character limit for code review.',
123
+ '',
124
+ '## Security',
125
+ ...securityNotes,
126
+ '',
127
+ '## Platform Awareness',
128
+ '- **VS Code agent**: Terminal sandbox is macOS/Linux/WSL2 only. Not available on native Windows.',
129
+ '- **Cloud agent**: Content exclusions are NOT enforced. Review PRs carefully for sensitive file access.',
130
+ '- **Cloud agent**: Cold-boot takes ~90 seconds. Optimize copilot-setup-steps.yml to minimize re-spins.',
131
+ '',
132
+ '## Notes',
133
+ '- If this repo also uses Claude, keep Claude-specific instructions in `CLAUDE.md` and use this file for Copilot-specific behavior.',
134
+ '- Use `.github/instructions/*.instructions.md` for path-scoped instructions with `applyTo` frontmatter.',
135
+ '- Use `.github/prompts/*.prompt.md` for reusable prompt templates invocable via `/name` in Chat.',
136
+ '',
137
+ `_Generated by nerviq v${version} for GitHub Copilot. Customize this file before relying on it in production flows._`,
138
+ '',
139
+ ].join('\n');
140
+ }
141
+
142
+ function buildVscodeSettings() {
143
+ return JSON.stringify({
144
+ "github.copilot.chat.agent.enabled": true,
145
+ "chat.tools.terminal.sandbox.enabled": true,
146
+ "chat.agent.autoApproval.terminalCommands": [],
147
+ "github.copilot.chat.reviewSelection.instructions": [
148
+ { "text": "Focus on security vulnerabilities, performance issues, and test coverage gaps." }
149
+ ],
150
+ "github.copilot.chat.commitMessageGeneration.instructions": [
151
+ { "text": "Use conventional commit format. Keep subject under 72 chars." }
152
+ ],
153
+ }, null, 2) + '\n';
154
+ }
155
+
156
+ function buildMcpJson() {
157
+ return JSON.stringify({
158
+ "servers": {},
159
+ }, null, 2) + '\n';
160
+ }
161
+
162
+ function buildCloudSetupSteps(ctx) {
163
+ const scripts = detectScripts(ctx);
164
+ const installCmd = scripts.install ? 'npm ci' : 'npm install';
165
+ return [
166
+ 'name: Copilot Setup Steps',
167
+ '',
168
+ 'on:',
169
+ ' workflow_dispatch:',
170
+ '',
171
+ 'jobs:',
172
+ ' setup:',
173
+ ' runs-on: ubuntu-latest',
174
+ ' steps:',
175
+ ' - uses: actions/checkout@v4',
176
+ ' - uses: actions/setup-node@v4',
177
+ ' with:',
178
+ ' node-version: 20',
179
+ ` - run: ${installCmd}`,
180
+ scripts.build ? ' - run: npm run build' : '',
181
+ scripts.test ? ' - run: npm test' : '',
182
+ '',
183
+ '# Cloud agent environment configuration.',
184
+ '# Dependencies installed here are available to the cloud agent.',
185
+ '# Keep this workflow focused on setup — not CI/CD.',
186
+ '',
187
+ `# Generated by nerviq v${version} for GitHub Copilot cloud agent.`,
188
+ '',
189
+ ].filter(l => l !== undefined).join('\n');
190
+ }
191
+
192
+ function buildPromptStarter() {
193
+ return [
194
+ '---',
195
+ 'description: Review code changes for security and quality',
196
+ 'agent: copilot',
197
+ 'mode: agent',
198
+ '---',
199
+ '',
200
+ 'Review the following code changes for:',
201
+ '- Security vulnerabilities',
202
+ '- Performance regressions',
203
+ '- Test coverage gaps',
204
+ '- Naming consistency',
205
+ '',
206
+ 'Provide specific, actionable feedback.',
207
+ '',
208
+ `# Generated by nerviq v${version}`,
209
+ '',
210
+ ].join('\n');
211
+ }
212
+
213
+ function buildScopedInstructionStarter() {
214
+ return [
215
+ '---',
216
+ 'applyTo: "**/*.ts"',
217
+ '---',
218
+ '',
219
+ '# TypeScript Instructions',
220
+ '',
221
+ '- Use strict TypeScript mode',
222
+ '- Prefer named exports over default exports',
223
+ '- Use explicit return types on public functions',
224
+ '- Avoid `any` — use `unknown` or proper types',
225
+ '',
226
+ `_Generated by nerviq v${version}_`,
227
+ '',
228
+ ].join('\n');
229
+ }
230
+
231
+ function buildCiReviewWorkflow() {
232
+ return [
233
+ 'name: Copilot Review',
234
+ '',
235
+ 'on:',
236
+ ' pull_request:',
237
+ ' types: [opened, synchronize]',
238
+ '',
239
+ 'permissions:',
240
+ ' contents: read',
241
+ ' pull-requests: write',
242
+ '',
243
+ 'jobs:',
244
+ ' copilot-review:',
245
+ ' runs-on: ubuntu-latest',
246
+ ' steps:',
247
+ ' - uses: actions/checkout@v4',
248
+ ' - name: Copilot Review',
249
+ ' uses: github/copilot-code-review@v1',
250
+ ' with:',
251
+ ' review-mode: comments',
252
+ '',
253
+ `# Generated by nerviq v${version} for GitHub Copilot.`,
254
+ '',
255
+ ].join('\n');
256
+ }
257
+
258
+ function buildContentExclusionsGuide() {
259
+ return [
260
+ '# Content Exclusions Guide',
261
+ '',
262
+ '## What are content exclusions?',
263
+ 'Content exclusions prevent GitHub Copilot from reading specific files or directories.',
264
+ '',
265
+ '## How to configure',
266
+ 'Content exclusions are configured at the **organization level** in GitHub.com admin settings,',
267
+ 'or at the **repository level** using glob patterns.',
268
+ '',
269
+ '## Recommended exclusions',
270
+ '```',
271
+ '.env',
272
+ '.env.*',
273
+ 'secrets/',
274
+ '*.pem',
275
+ '*.key',
276
+ 'credentials.*',
277
+ 'config/production.*',
278
+ '```',
279
+ '',
280
+ '## Important limitations',
281
+ '- Content exclusions are **NOT enforced** on the cloud agent.',
282
+ '- Changes can take up to **30 minutes** to propagate.',
283
+ '- Exclusions apply to Copilot Chat and completions but not all surfaces equally.',
284
+ '',
285
+ `_Generated by nerviq v${version}_`,
286
+ '',
287
+ ].join('\n');
288
+ }
289
+
290
+ function buildCopilotSetupFiles(options = {}) {
291
+ const ctx = new CopilotProjectContext(options.dir);
292
+ const stacks = ctx.detectStacks(STACKS);
293
+ const files = [];
294
+
295
+ // 1. copilot-instructions.md
296
+ const instrPath = path.join(options.dir, '.github', 'copilot-instructions.md');
297
+ if (!fs.existsSync(instrPath)) {
298
+ files.push({
299
+ path: '.github/copilot-instructions.md',
300
+ action: 'create',
301
+ content: buildCopilotInstructionsMd(ctx, stacks),
302
+ currentState: '.github/copilot-instructions.md is missing',
303
+ proposedState: 'create a Copilot-native copilot-instructions.md baseline with verification, architecture, and trust guidance',
304
+ });
305
+ }
306
+
307
+ // 2. .vscode/settings.json (Copilot settings)
308
+ const settingsPath = path.join(options.dir, '.vscode', 'settings.json');
309
+ if (!fs.existsSync(settingsPath)) {
310
+ files.push({
311
+ path: '.vscode/settings.json',
312
+ action: 'create',
313
+ content: buildVscodeSettings(),
314
+ currentState: '.vscode/settings.json is missing',
315
+ proposedState: 'create a safe Copilot settings baseline with sandbox enabled, agent mode, and review instructions',
316
+ });
317
+ }
318
+
319
+ const modules = options.modules || 'all';
320
+ const wantModule = (name) => modules === 'all' || (Array.isArray(modules) && modules.includes(name));
321
+
322
+ // 3. Scoped instructions starter
323
+ if (wantModule('scoped-instructions')) {
324
+ const instrDir = path.join(options.dir, '.github', 'instructions');
325
+ if (!fs.existsSync(instrDir)) {
326
+ files.push({
327
+ path: '.github/instructions/typescript.instructions.md',
328
+ action: 'create',
329
+ family: 'copilot-scoped-instructions',
330
+ content: buildScopedInstructionStarter(),
331
+ currentState: '.github/instructions/ directory is missing',
332
+ proposedState: 'create a scoped instruction starter with applyTo frontmatter',
333
+ });
334
+ }
335
+ }
336
+
337
+ // 4. Prompt templates starter
338
+ if (wantModule('prompts')) {
339
+ const promptsDir = path.join(options.dir, '.github', 'prompts');
340
+ if (!fs.existsSync(promptsDir)) {
341
+ files.push({
342
+ path: '.github/prompts/review.prompt.md',
343
+ action: 'create',
344
+ family: 'copilot-prompts',
345
+ content: buildPromptStarter(),
346
+ currentState: '.github/prompts/ directory is missing',
347
+ proposedState: 'create a prompt template starter for Copilot Chat',
348
+ });
349
+ }
350
+ }
351
+
352
+ // 5. .vscode/mcp.json
353
+ if (wantModule('mcp')) {
354
+ const mcpPath = path.join(options.dir, '.vscode', 'mcp.json');
355
+ if (!fs.existsSync(mcpPath)) {
356
+ const domainPacks = options.domainPacks || [];
357
+ const mcpRecs = recommendCopilotMcpPacks(stacks, domainPacks, { ctx });
358
+ const servers = Object.assign({}, ...mcpRecs.map(p => packToJson(p)));
359
+ files.push({
360
+ path: '.vscode/mcp.json',
361
+ action: 'create',
362
+ family: 'copilot-mcp',
363
+ content: JSON.stringify({ servers }, null, 2) + '\n',
364
+ currentState: '.vscode/mcp.json is missing',
365
+ proposedState: `create MCP config with ${mcpRecs.length} recommended packs: ${mcpRecs.map(p => p.label).join(', ')}`,
366
+ });
367
+ }
368
+ }
369
+
370
+ // 6. copilot-setup-steps.yml
371
+ if (wantModule('cloud-setup')) {
372
+ const cloudPath = path.join(options.dir, '.github', 'workflows', 'copilot-setup-steps.yml');
373
+ if (!fs.existsSync(cloudPath)) {
374
+ files.push({
375
+ path: '.github/workflows/copilot-setup-steps.yml',
376
+ action: 'create',
377
+ family: 'copilot-cloud-setup',
378
+ content: buildCloudSetupSteps(ctx),
379
+ currentState: 'copilot-setup-steps.yml is missing',
380
+ proposedState: 'create cloud agent setup workflow with dependency install and test configuration',
381
+ });
382
+ }
383
+ }
384
+
385
+ // 7. CI review workflow
386
+ if (wantModule('ci')) {
387
+ const ciPath = path.join(options.dir, '.github', 'workflows', 'copilot-review.yml');
388
+ if (!fs.existsSync(ciPath)) {
389
+ files.push({
390
+ path: '.github/workflows/copilot-review.yml',
391
+ action: 'create',
392
+ family: 'copilot-ci-review',
393
+ content: buildCiReviewWorkflow(),
394
+ currentState: 'No Copilot CI review workflow exists',
395
+ proposedState: 'create a GitHub Actions workflow for Copilot-based PR review',
396
+ });
397
+ }
398
+ }
399
+
400
+ // 8. Content exclusions guide
401
+ if (wantModule('content-exclusions')) {
402
+ const guidePath = path.join(options.dir, '.github', 'COPILOT-CONTENT-EXCLUSIONS.md');
403
+ if (!fs.existsSync(guidePath)) {
404
+ files.push({
405
+ path: '.github/COPILOT-CONTENT-EXCLUSIONS.md',
406
+ action: 'create',
407
+ family: 'copilot-content-exclusions',
408
+ content: buildContentExclusionsGuide(),
409
+ currentState: 'No content exclusions guide exists',
410
+ proposedState: 'create a content exclusions setup guide documenting known limitations',
411
+ });
412
+ }
413
+ }
414
+
415
+ return { ctx, stacks, files };
416
+ }
417
+
418
+ async function setupCopilot(options) {
419
+ const silent = options.silent === true;
420
+ const { ctx, stacks, files } = buildCopilotSetupFiles(options);
421
+ const writtenFiles = [];
422
+ const preservedFiles = [];
423
+
424
+ function log(message = '') { if (!silent) console.log(message); }
425
+
426
+ log('');
427
+ log('\x1b[1m nerviq copilot setup\x1b[0m');
428
+ log('\x1b[2m ═══════════════════════════════════════\x1b[0m');
429
+ if (stacks.length > 0) log(`\x1b[36m Detected: ${stacks.map((s) => s.label).join(', ')}\x1b[0m`);
430
+ log('');
431
+
432
+ for (const file of files) {
433
+ const fullPath = path.join(options.dir, file.path);
434
+ if (fs.existsSync(fullPath)) {
435
+ preservedFiles.push(file.path);
436
+ log(` \x1b[2m Skipped ${file.path} (already exists)\x1b[0m`);
437
+ continue;
438
+ }
439
+ fs.mkdirSync(path.dirname(fullPath), { recursive: true });
440
+ fs.writeFileSync(fullPath, file.content, 'utf8');
441
+ writtenFiles.push(file.path);
442
+ log(` \x1b[32m Created ${file.path}\x1b[0m`);
443
+ }
444
+
445
+ let rollbackArtifact = null;
446
+ let activityArtifact = null;
447
+ if (writtenFiles.length > 0) {
448
+ rollbackArtifact = writeRollbackArtifact(options.dir, {
449
+ sourcePlan: 'copilot-setup',
450
+ createdFiles: writtenFiles,
451
+ patchedFiles: [],
452
+ rollbackInstructions: writtenFiles.map((file) => `Delete ${file}`),
453
+ });
454
+ activityArtifact = writeActivityArtifact(options.dir, 'copilot-setup', {
455
+ platform: 'copilot',
456
+ createdFiles: writtenFiles,
457
+ preservedFiles,
458
+ stackLabels: stacks.map((item) => item.label),
459
+ rollbackArtifact: rollbackArtifact.relativePath,
460
+ });
461
+ }
462
+
463
+ log('');
464
+ log(` \x1b[1m${writtenFiles.length} files created.\x1b[0m`);
465
+ if (preservedFiles.length > 0) log(` \x1b[2m${preservedFiles.length} existing files preserved.\x1b[0m`);
466
+ if (rollbackArtifact) log(` Rollback: \x1b[1m${rollbackArtifact.relativePath}\x1b[0m`);
467
+ if (activityArtifact) log(` Activity log: \x1b[1m${activityArtifact.relativePath}\x1b[0m`);
468
+ log('');
469
+ log(' Run \x1b[1mnpx nerviq --platform copilot\x1b[0m to audit your Copilot setup.');
470
+ log('');
471
+
472
+ return {
473
+ created: writtenFiles.length,
474
+ skipped: preservedFiles.length,
475
+ writtenFiles,
476
+ preservedFiles,
477
+ stacks,
478
+ rollbackArtifact: rollbackArtifact ? rollbackArtifact.relativePath : null,
479
+ activityArtifact: activityArtifact ? activityArtifact.relativePath : null,
480
+ };
481
+ }
482
+
483
+ module.exports = {
484
+ buildCopilotInstructionsMd,
485
+ buildVscodeSettings,
486
+ buildCopilotSetupFiles,
487
+ setupCopilot,
488
+ };