@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.
- package/CHANGELOG.md +181 -0
- package/LICENSE +21 -0
- package/README.md +447 -0
- package/bin/cli.js +749 -0
- package/content/case-study-template.md +91 -0
- package/content/claims-governance.md +37 -0
- package/content/claude-code/audit-repo/SKILL.md +20 -0
- package/content/claude-native-integration.md +60 -0
- package/content/devto-article.json +9 -0
- package/content/launch-posts.md +226 -0
- package/content/pilot-rollout-kit.md +30 -0
- package/content/release-checklist.md +31 -0
- package/package.json +53 -4
- package/src/activity.js +529 -0
- package/src/aider/activity.js +226 -0
- package/src/aider/config-parser.js +166 -0
- package/src/aider/context.js +158 -0
- package/src/aider/deep-review.js +316 -0
- package/src/aider/domain-packs.js +278 -0
- package/src/aider/freshness.js +168 -0
- package/src/aider/governance.js +253 -0
- package/src/aider/interactive.js +334 -0
- package/src/aider/mcp-packs.js +98 -0
- package/src/aider/patch.js +214 -0
- package/src/aider/plans.js +186 -0
- package/src/aider/premium.js +360 -0
- package/src/aider/setup.js +404 -0
- package/src/aider/techniques.js +1323 -0
- package/src/analyze.js +821 -0
- package/src/audit.js +1003 -0
- package/src/badge.js +13 -0
- package/src/benchmark.js +339 -0
- package/src/claudex-sync.json +7 -0
- package/src/codex/activity.js +324 -0
- package/src/codex/config-parser.js +183 -0
- package/src/codex/context.js +221 -0
- package/src/codex/deep-review.js +493 -0
- package/src/codex/domain-packs.js +372 -0
- package/src/codex/freshness.js +167 -0
- package/src/codex/governance.js +192 -0
- package/src/codex/interactive.js +618 -0
- package/src/codex/mcp-packs.js +660 -0
- package/src/codex/patch.js +209 -0
- package/src/codex/plans.js +251 -0
- package/src/codex/premium.js +614 -0
- package/src/codex/setup.js +603 -0
- package/src/codex/techniques.js +2649 -0
- package/src/context.js +272 -0
- package/src/copilot/activity.js +309 -0
- package/src/copilot/config-parser.js +226 -0
- package/src/copilot/context.js +197 -0
- package/src/copilot/deep-review.js +346 -0
- package/src/copilot/domain-packs.js +350 -0
- package/src/copilot/freshness.js +197 -0
- package/src/copilot/governance.js +222 -0
- package/src/copilot/interactive.js +406 -0
- package/src/copilot/mcp-packs.js +572 -0
- package/src/copilot/patch.js +238 -0
- package/src/copilot/plans.js +253 -0
- package/src/copilot/premium.js +450 -0
- package/src/copilot/setup.js +488 -0
- package/src/copilot/techniques.js +1822 -0
- package/src/cursor/activity.js +301 -0
- package/src/cursor/config-parser.js +265 -0
- package/src/cursor/context.js +236 -0
- package/src/cursor/deep-review.js +334 -0
- package/src/cursor/domain-packs.js +346 -0
- package/src/cursor/freshness.js +214 -0
- package/src/cursor/governance.js +229 -0
- package/src/cursor/interactive.js +391 -0
- package/src/cursor/mcp-packs.js +571 -0
- package/src/cursor/patch.js +243 -0
- package/src/cursor/plans.js +254 -0
- package/src/cursor/premium.js +468 -0
- package/src/cursor/setup.js +488 -0
- package/src/cursor/techniques.js +1786 -0
- package/src/deep-review.js +345 -0
- package/src/domain-packs.js +364 -0
- package/src/formatters/sarif.js +115 -0
- package/src/gemini/activity.js +402 -0
- package/src/gemini/config-parser.js +275 -0
- package/src/gemini/context.js +221 -0
- package/src/gemini/deep-review.js +559 -0
- package/src/gemini/domain-packs.js +371 -0
- package/src/gemini/freshness.js +204 -0
- package/src/gemini/governance.js +201 -0
- package/src/gemini/interactive.js +860 -0
- package/src/gemini/mcp-packs.js +658 -0
- package/src/gemini/patch.js +229 -0
- package/src/gemini/plans.js +269 -0
- package/src/gemini/premium.js +759 -0
- package/src/gemini/setup.js +692 -0
- package/src/gemini/techniques.js +2084 -0
- package/src/governance.js +523 -0
- package/src/harmony/advisor.js +383 -0
- package/src/harmony/audit.js +303 -0
- package/src/harmony/canon.js +444 -0
- package/src/harmony/cli.js +331 -0
- package/src/harmony/drift.js +401 -0
- package/src/harmony/governance.js +313 -0
- package/src/harmony/memory.js +238 -0
- package/src/harmony/sync.js +458 -0
- package/src/harmony/watch.js +336 -0
- package/src/index.js +256 -0
- package/src/insights.js +119 -0
- package/src/interactive.js +118 -0
- package/src/mcp-packs.js +597 -0
- package/src/opencode/activity.js +286 -0
- package/src/opencode/config-parser.js +109 -0
- package/src/opencode/context.js +247 -0
- package/src/opencode/deep-review.js +313 -0
- package/src/opencode/domain-packs.js +240 -0
- package/src/opencode/freshness.js +158 -0
- package/src/opencode/governance.js +159 -0
- package/src/opencode/interactive.js +392 -0
- package/src/opencode/mcp-packs.js +474 -0
- package/src/opencode/patch.js +184 -0
- package/src/opencode/plans.js +231 -0
- package/src/opencode/premium.js +413 -0
- package/src/opencode/setup.js +449 -0
- package/src/opencode/techniques.js +1713 -0
- package/src/plans.js +655 -0
- package/src/secret-patterns.js +30 -0
- package/src/setup.js +1274 -0
- package/src/synergy/adaptive.js +261 -0
- package/src/synergy/compensation.js +156 -0
- package/src/synergy/evidence.js +193 -0
- package/src/synergy/learning.js +184 -0
- package/src/synergy/patterns.js +227 -0
- package/src/synergy/ranking.js +83 -0
- package/src/synergy/report.js +163 -0
- package/src/synergy/routing.js +152 -0
- package/src/techniques.js +1354 -0
- package/src/watch.js +229 -0
- package/src/windsurf/activity.js +302 -0
- package/src/windsurf/config-parser.js +267 -0
- package/src/windsurf/context.js +249 -0
- package/src/windsurf/deep-review.js +337 -0
- package/src/windsurf/domain-packs.js +348 -0
- package/src/windsurf/freshness.js +215 -0
- package/src/windsurf/governance.js +231 -0
- package/src/windsurf/interactive.js +388 -0
- package/src/windsurf/mcp-packs.js +535 -0
- package/src/windsurf/patch.js +231 -0
- package/src/windsurf/plans.js +247 -0
- package/src/windsurf/premium.js +467 -0
- package/src/windsurf/setup.js +471 -0
- package/src/windsurf/techniques.js +1758 -0
|
@@ -0,0 +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
|
+
};
|