cp-toolkit 2.1.2 → 2.2.1
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/package.json +1 -1
- package/src/commands/init.js +238 -316
package/package.json
CHANGED
package/src/commands/init.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* cp-
|
|
2
|
+
* cp-toolkit init command
|
|
3
3
|
*
|
|
4
4
|
* Initializes Copilot Kit with GitHub Copilot 2026 standard structure.
|
|
5
|
-
*
|
|
5
|
+
* Creates:
|
|
6
|
+
* .github/agents/ - Specialist agent definitions
|
|
7
|
+
* .github/instructions/ - Language/context-specific instructions
|
|
8
|
+
* .github/copilot-instructions.md - Main Copilot config
|
|
9
|
+
* .vscode/mcp.json - MCP server configuration
|
|
6
10
|
*/
|
|
7
11
|
|
|
8
12
|
import fs from 'fs-extra';
|
|
@@ -10,258 +14,16 @@ import path from 'path';
|
|
|
10
14
|
import chalk from 'chalk';
|
|
11
15
|
import ora from 'ora';
|
|
12
16
|
import prompts from 'prompts';
|
|
17
|
+
import { fileURLToPath } from 'url';
|
|
13
18
|
|
|
14
|
-
//
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
name: 'orchestrator',
|
|
18
|
-
description: 'Multi-domain task coordinator',
|
|
19
|
-
skills: ['intelligent-routing', 'parallel-agents', 'plan-writing'],
|
|
20
|
-
triggers: ['complex', 'multi-file', 'architecture', 'coordinate']
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
name: 'frontend-specialist',
|
|
24
|
-
description: 'React, Next.js, CSS expert',
|
|
25
|
-
skills: ['nextjs-react', 'accessibility', 'tailwind'],
|
|
26
|
-
triggers: ['ui', 'component', 'react', 'css', 'frontend', 'styling']
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
name: 'backend-specialist',
|
|
30
|
-
description: 'Node.js, Python, APIs expert',
|
|
31
|
-
skills: ['api-patterns', 'error-handling', 'caching'],
|
|
32
|
-
triggers: ['api', 'server', 'backend', 'endpoint', 'node', 'express']
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
name: 'database-architect',
|
|
36
|
-
description: 'Schema design, SQL, Prisma expert',
|
|
37
|
-
skills: ['prisma', 'query-optimization', 'migrations'],
|
|
38
|
-
triggers: ['database', 'schema', 'sql', 'prisma', 'migration', 'query']
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: 'security-auditor',
|
|
42
|
-
description: 'Security analysis, OWASP expert',
|
|
43
|
-
skills: ['vulnerability-scanner', 'auth-patterns'],
|
|
44
|
-
triggers: ['security', 'auth', 'vulnerability', 'owasp', 'audit']
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
name: 'test-engineer',
|
|
48
|
-
description: 'Testing strategies, coverage expert',
|
|
49
|
-
skills: ['testing-patterns', 'e2e-testing'],
|
|
50
|
-
triggers: ['test', 'coverage', 'jest', 'playwright', 'vitest']
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
name: 'debugger',
|
|
54
|
-
description: 'Troubleshooting, root cause analysis',
|
|
55
|
-
skills: ['debugging-strategies', 'performance-profiling'],
|
|
56
|
-
triggers: ['bug', 'error', 'fix', 'debug', 'why', 'crash']
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
name: 'devops-engineer',
|
|
60
|
-
description: 'CI/CD, Docker, infrastructure expert',
|
|
61
|
-
skills: ['docker-patterns', 'ci-cd-pipelines'],
|
|
62
|
-
triggers: ['deploy', 'docker', 'ci', 'pipeline', 'kubernetes', 'infra']
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
name: 'project-planner',
|
|
66
|
-
description: 'Architecture decisions, task planning',
|
|
67
|
-
skills: ['plan-writing', 'brainstorming'],
|
|
68
|
-
triggers: ['plan', 'architecture', 'design', 'roadmap', 'breakdown']
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
name: 'performance-optimizer',
|
|
72
|
-
description: 'Web performance, Core Web Vitals expert',
|
|
73
|
-
skills: ['performance-profiling', 'bundle-optimization'],
|
|
74
|
-
triggers: ['performance', 'speed', 'optimize', 'lighthouse', 'bundle']
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
name: 'mobile-developer',
|
|
78
|
-
description: 'React Native, Flutter, iOS, Android expert',
|
|
79
|
-
skills: ['mobile-patterns', 'cross-platform'],
|
|
80
|
-
triggers: ['mobile', 'ios', 'android', 'react-native', 'flutter', 'app']
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
name: 'documentation-writer',
|
|
84
|
-
description: 'Technical docs, API documentation expert',
|
|
85
|
-
skills: ['technical-writing', 'api-docs'],
|
|
86
|
-
triggers: ['docs', 'documentation', 'readme', 'api-docs', 'jsdoc']
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
name: 'seo-specialist',
|
|
90
|
-
description: 'SEO optimization, meta tags expert',
|
|
91
|
-
skills: ['seo-patterns', 'structured-data'],
|
|
92
|
-
triggers: ['seo', 'meta', 'search', 'ranking', 'sitemap']
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
name: 'code-archaeologist',
|
|
96
|
-
description: 'Legacy code analysis, refactoring expert',
|
|
97
|
-
skills: ['refactoring', 'code-analysis'],
|
|
98
|
-
triggers: ['legacy', 'refactor', 'understand', 'cleanup', 'technical-debt']
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
name: 'explorer-agent',
|
|
102
|
-
description: 'Codebase exploration and analysis',
|
|
103
|
-
skills: ['code-navigation', 'pattern-recognition'],
|
|
104
|
-
triggers: ['explore', 'find', 'search', 'where', 'locate']
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
name: 'game-developer',
|
|
108
|
-
description: 'Game logic, mechanics, interactive experiences',
|
|
109
|
-
skills: ['game-patterns', 'physics', 'graphics'],
|
|
110
|
-
triggers: ['game', 'physics', 'animation', 'canvas', 'webgl']
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
name: 'penetration-tester',
|
|
114
|
-
description: 'Offensive security, vulnerability exploitation',
|
|
115
|
-
skills: ['pentesting', 'exploitation'],
|
|
116
|
-
triggers: ['pentest', 'exploit', 'hack', 'red-team', 'attack']
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
name: 'product-owner',
|
|
120
|
-
description: 'Product strategy, backlog management',
|
|
121
|
-
skills: ['product-management', 'prioritization'],
|
|
122
|
-
triggers: ['backlog', 'priority', 'mvp', 'feature', 'user-story']
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
name: 'product-manager',
|
|
126
|
-
description: 'Requirements gathering, user research',
|
|
127
|
-
skills: ['requirements', 'user-research'],
|
|
128
|
-
triggers: ['requirements', 'spec', 'user', 'stakeholder', 'prd']
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
name: 'qa-automation-engineer',
|
|
132
|
-
description: 'E2E testing, CI pipelines, quality automation',
|
|
133
|
-
skills: ['automation', 'ci-testing'],
|
|
134
|
-
triggers: ['qa', 'automation', 'e2e', 'regression', 'quality']
|
|
135
|
-
}
|
|
136
|
-
];
|
|
137
|
-
|
|
138
|
-
const TEMPLATE_INSTRUCTIONS = {
|
|
139
|
-
typescript: {
|
|
140
|
-
applyTo: '**/*.ts,**/*.tsx,**/*.mts,**/*.cts',
|
|
141
|
-
content: `## TypeScript Guidelines
|
|
142
|
-
|
|
143
|
-
### Strict Mode
|
|
144
|
-
- Enable \`strict: true\` in tsconfig.json
|
|
145
|
-
- No \`any\` types - use \`unknown\` and narrow
|
|
146
|
-
- Explicit return types for public functions
|
|
147
|
-
|
|
148
|
-
### Patterns
|
|
149
|
-
- Prefer \`interface\` over \`type\` for objects
|
|
150
|
-
- Use \`as const\` for literal types
|
|
151
|
-
- Leverage discriminated unions for state
|
|
152
|
-
|
|
153
|
-
### Imports
|
|
154
|
-
- Use path aliases (@/components, @/lib)
|
|
155
|
-
- Barrel exports for public APIs only
|
|
156
|
-
- Tree-shakeable imports
|
|
157
|
-
|
|
158
|
-
### Error Handling
|
|
159
|
-
- Use Result<T, E> pattern for expected errors
|
|
160
|
-
- Throw only for unexpected errors
|
|
161
|
-
- Custom error classes extend Error`
|
|
162
|
-
},
|
|
163
|
-
python: {
|
|
164
|
-
applyTo: '**/*.py',
|
|
165
|
-
content: `## Python Guidelines
|
|
166
|
-
|
|
167
|
-
### Style
|
|
168
|
-
- Black formatter, line length 88
|
|
169
|
-
- Type hints for all public functions
|
|
170
|
-
- PEP 8 naming conventions
|
|
171
|
-
|
|
172
|
-
### Patterns
|
|
173
|
-
- Pydantic for data validation
|
|
174
|
-
- FastAPI for APIs
|
|
175
|
-
- Async/await for I/O operations
|
|
176
|
-
|
|
177
|
-
### Imports
|
|
178
|
-
- isort for import ordering
|
|
179
|
-
- Absolute imports preferred
|
|
180
|
-
- TYPE_CHECKING for type-only imports
|
|
181
|
-
|
|
182
|
-
### Error Handling
|
|
183
|
-
- Custom exceptions inherit from base
|
|
184
|
-
- Use \`raise from\` for chained exceptions
|
|
185
|
-
- Context managers for resources`
|
|
186
|
-
},
|
|
187
|
-
react: {
|
|
188
|
-
applyTo: '**/*.jsx,**/*.tsx,**/components/**',
|
|
189
|
-
content: `## React Guidelines
|
|
190
|
-
|
|
191
|
-
### Components
|
|
192
|
-
- Functional components only
|
|
193
|
-
- Custom hooks for shared logic
|
|
194
|
-
- Props interface above component
|
|
195
|
-
|
|
196
|
-
### State
|
|
197
|
-
- useState for local state
|
|
198
|
-
- useReducer for complex state
|
|
199
|
-
- Context for global, Zustand for app state
|
|
200
|
-
|
|
201
|
-
### Performance
|
|
202
|
-
- React.memo for expensive renders
|
|
203
|
-
- useMemo/useCallback judiciously
|
|
204
|
-
- Lazy load routes and heavy components
|
|
205
|
-
|
|
206
|
-
### Testing
|
|
207
|
-
- React Testing Library
|
|
208
|
-
- Test behavior, not implementation
|
|
209
|
-
- Mock at network boundary`
|
|
210
|
-
},
|
|
211
|
-
database: {
|
|
212
|
-
applyTo: '**/prisma/**,**/*.sql,**/migrations/**,**/schema.*',
|
|
213
|
-
content: `## Database Guidelines
|
|
214
|
-
|
|
215
|
-
### Schema Design
|
|
216
|
-
- UUID for primary keys
|
|
217
|
-
- Timestamps: createdAt, updatedAt
|
|
218
|
-
- Soft delete with deletedAt
|
|
219
|
-
|
|
220
|
-
### Prisma
|
|
221
|
-
- Use transactions for multi-table ops
|
|
222
|
-
- Select only needed fields
|
|
223
|
-
- Paginate with cursor, not offset
|
|
224
|
-
|
|
225
|
-
### Migrations
|
|
226
|
-
- One migration per feature
|
|
227
|
-
- Never modify applied migrations
|
|
228
|
-
- Test migrations on copy of prod data
|
|
229
|
-
|
|
230
|
-
### Security
|
|
231
|
-
- Parameterized queries only
|
|
232
|
-
- Row-level security where needed
|
|
233
|
-
- Encrypt PII at rest`
|
|
234
|
-
},
|
|
235
|
-
security: {
|
|
236
|
-
applyTo: '**/auth/**,**/security/**,**/*auth*,**/*token*,**/*session*',
|
|
237
|
-
content: `## Security Guidelines
|
|
238
|
-
|
|
239
|
-
### Authentication
|
|
240
|
-
- JWT with short expiry + refresh tokens
|
|
241
|
-
- HttpOnly cookies for web
|
|
242
|
-
- Rate limit auth endpoints
|
|
243
|
-
|
|
244
|
-
### Authorization
|
|
245
|
-
- RBAC or ABAC patterns
|
|
246
|
-
- Check permissions server-side
|
|
247
|
-
- Deny by default
|
|
248
|
-
|
|
249
|
-
### Data Protection
|
|
250
|
-
- Sanitize all inputs
|
|
251
|
-
- Escape outputs by context
|
|
252
|
-
- Never log sensitive data
|
|
253
|
-
|
|
254
|
-
### OWASP Top 10
|
|
255
|
-
- Validate content types
|
|
256
|
-
- CSRF tokens for state changes
|
|
257
|
-
- Security headers (CSP, HSTS)`
|
|
258
|
-
}
|
|
259
|
-
};
|
|
19
|
+
// Get __dirname equivalent for ESM
|
|
20
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
+
const __dirname = path.dirname(__filename);
|
|
260
22
|
|
|
261
23
|
export async function initCommand(directory, options) {
|
|
262
24
|
const targetDir = directory ? path.resolve(directory) : process.cwd();
|
|
263
25
|
const dirName = path.basename(targetDir);
|
|
264
|
-
const templatesDir = path.join(
|
|
26
|
+
const templatesDir = path.join(__dirname, '../../templates');
|
|
265
27
|
|
|
266
28
|
console.log(chalk.bold.cyan('\n🚀 cp-toolkit - GitHub Copilot Agent Toolkit\n'));
|
|
267
29
|
|
|
@@ -272,12 +34,12 @@ export async function initCommand(directory, options) {
|
|
|
272
34
|
}
|
|
273
35
|
|
|
274
36
|
// Check for existing configuration
|
|
275
|
-
const
|
|
276
|
-
if (fs.existsSync(
|
|
37
|
+
const githubAgentsDir = path.join(targetDir, '.github', 'agents');
|
|
38
|
+
if (fs.existsSync(githubAgentsDir) && !options.force) {
|
|
277
39
|
const { overwrite } = await prompts({
|
|
278
40
|
type: 'confirm',
|
|
279
41
|
name: 'overwrite',
|
|
280
|
-
message: '
|
|
42
|
+
message: 'Copilot Kit (.github/agents) already exists. Overwrite?',
|
|
281
43
|
initial: false
|
|
282
44
|
});
|
|
283
45
|
|
|
@@ -304,51 +66,69 @@ export async function initCommand(directory, options) {
|
|
|
304
66
|
{
|
|
305
67
|
type: 'confirm',
|
|
306
68
|
name: 'installEverything',
|
|
307
|
-
message: 'Install full Copilot Kit (Agents,
|
|
69
|
+
message: 'Install full Copilot Kit (Agents, Instructions, Workflows)?',
|
|
308
70
|
initial: true
|
|
309
71
|
}
|
|
310
72
|
]);
|
|
311
|
-
|
|
73
|
+
config = { ...config, ...response };
|
|
312
74
|
}
|
|
313
75
|
|
|
314
76
|
const spinner = ora('Installing Copilot Kit...').start();
|
|
315
77
|
|
|
316
78
|
try {
|
|
317
|
-
// 1.
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
});
|
|
79
|
+
// 1. Setup .github/agents/
|
|
80
|
+
spinner.text = 'Copying agents...';
|
|
81
|
+
const agentsSourceDir = path.join(templatesDir, 'agents');
|
|
82
|
+
const agentsTargetDir = path.join(targetDir, '.github', 'agents');
|
|
83
|
+
await fs.ensureDir(agentsTargetDir);
|
|
84
|
+
await fs.copy(agentsSourceDir, agentsTargetDir, { overwrite: true });
|
|
323
85
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
86
|
+
// 2. Setup .github/instructions/ (from skills that have instruction content)
|
|
87
|
+
spinner.text = 'Copying instructions...';
|
|
88
|
+
const instructionsTargetDir = path.join(targetDir, '.github', 'instructions');
|
|
89
|
+
await fs.ensureDir(instructionsTargetDir);
|
|
90
|
+
|
|
91
|
+
// Create standard instruction files
|
|
92
|
+
await createInstructionFiles(instructionsTargetDir);
|
|
93
|
+
|
|
94
|
+
// 4. Setup .github/skills/ (essential skills referenced by agents)
|
|
95
|
+
spinner.text = 'Copying essential skills...';
|
|
96
|
+
const skillsTargetDir = path.join(targetDir, '.github', 'skills');
|
|
97
|
+
await fs.ensureDir(skillsTargetDir);
|
|
98
|
+
|
|
99
|
+
// Copy essential skills that agents reference
|
|
100
|
+
const essentialSkills = [
|
|
101
|
+
'mobile-design',
|
|
102
|
+
'frontend-design',
|
|
103
|
+
'api-patterns',
|
|
104
|
+
'database-design',
|
|
105
|
+
'testing-patterns',
|
|
106
|
+
'deployment-procedures',
|
|
107
|
+
'architecture'
|
|
108
|
+
];
|
|
109
|
+
|
|
110
|
+
for (const skill of essentialSkills) {
|
|
111
|
+
const skillSourceDir = path.join(templatesDir, 'skills', 'optional', skill);
|
|
112
|
+
if (fs.existsSync(skillSourceDir)) {
|
|
113
|
+
const skillTargetDir = path.join(skillsTargetDir, skill);
|
|
114
|
+
await fs.ensureDir(skillTargetDir);
|
|
115
|
+
await fs.copy(skillSourceDir, skillTargetDir, { overwrite: true });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
329
118
|
|
|
330
|
-
|
|
119
|
+
// 5. Setup .github/copilot-instructions.md
|
|
120
|
+
spinner.text = 'Creating copilot-instructions.md...';
|
|
121
|
+
const instructionsPath = path.join(targetDir, '.github', 'copilot-instructions.md');
|
|
331
122
|
const instructionsContent = generateCopilotInstructions(config);
|
|
332
123
|
await fs.writeFile(instructionsPath, instructionsContent);
|
|
333
124
|
|
|
334
|
-
//
|
|
125
|
+
// 6. Setup .vscode/mcp.json
|
|
335
126
|
spinner.text = 'Configuring MCP Server...';
|
|
336
127
|
const vscodeDir = path.join(targetDir, '.vscode');
|
|
337
128
|
await fs.ensureDir(vscodeDir);
|
|
338
129
|
|
|
339
130
|
const mcpConfig = {
|
|
340
131
|
"mcpServers": {
|
|
341
|
-
"antigravity-toolkit": {
|
|
342
|
-
"command": "node",
|
|
343
|
-
"args": [
|
|
344
|
-
"${workspaceFolder}/.agent/scripts/mcp-server.js"
|
|
345
|
-
],
|
|
346
|
-
"env": {
|
|
347
|
-
"AGENT_ROOT": "${workspaceFolder}/.agent"
|
|
348
|
-
},
|
|
349
|
-
"disabled": false,
|
|
350
|
-
"autoApprove": []
|
|
351
|
-
},
|
|
352
132
|
"filesystem": {
|
|
353
133
|
"command": "npx",
|
|
354
134
|
"args": [
|
|
@@ -376,65 +156,207 @@ export async function initCommand(directory, options) {
|
|
|
376
156
|
JSON.stringify(mcpConfig, null, 2)
|
|
377
157
|
);
|
|
378
158
|
|
|
379
|
-
//
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
159
|
+
// 7. Copy workflows to .github/workflows-copilot/ (optional reference)
|
|
160
|
+
if (config.installEverything) {
|
|
161
|
+
spinner.text = 'Copying workflows...';
|
|
162
|
+
const workflowsSourceDir = path.join(templatesDir, 'workflows');
|
|
163
|
+
const workflowsTargetDir = path.join(targetDir, '.github', 'copilot-workflows');
|
|
164
|
+
if (fs.existsSync(workflowsSourceDir)) {
|
|
165
|
+
await fs.ensureDir(workflowsTargetDir);
|
|
166
|
+
await fs.copy(workflowsSourceDir, workflowsTargetDir, { overwrite: true });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
spinner.succeed(chalk.green('✨ Copilot Kit initialized successfully!'));
|
|
385
171
|
|
|
386
|
-
|
|
172
|
+
console.log(chalk.bold('\n📁 Created structure:'));
|
|
173
|
+
console.log(chalk.dim(' .github/'));
|
|
174
|
+
console.log(chalk.dim(' ├── agents/ ') + chalk.cyan('← 20 specialist agents'));
|
|
175
|
+
console.log(chalk.dim(' ├── skills/ ') + chalk.cyan('← Essential skills library'));
|
|
176
|
+
console.log(chalk.dim(' ├── instructions/ ') + chalk.cyan('← Language-specific rules'));
|
|
177
|
+
console.log(chalk.dim(' ├── copilot-workflows/') + chalk.cyan('← Workflow templates'));
|
|
178
|
+
console.log(chalk.dim(' └── copilot-instructions.md'));
|
|
179
|
+
console.log(chalk.dim(' .vscode/'));
|
|
180
|
+
console.log(chalk.dim(' └── mcp.json ') + chalk.cyan('← MCP server config'));
|
|
387
181
|
|
|
388
|
-
console.log(chalk.bold('\
|
|
389
|
-
console.log(`1.
|
|
390
|
-
console.log(`2.
|
|
391
|
-
console.log(`3.
|
|
182
|
+
console.log(chalk.bold('\n🚀 Next Steps:'));
|
|
183
|
+
console.log(` 1. ${chalk.cyan('Reload VS Code window')} to activate MCP servers`);
|
|
184
|
+
console.log(` 2. Open Copilot Chat and try: ${chalk.yellow('@workspace use the orchestrator agent')}`);
|
|
185
|
+
console.log(` 3. Or try a workflow: ${chalk.yellow('/create a React component')}`);
|
|
392
186
|
|
|
393
187
|
} catch (error) {
|
|
394
|
-
spinner.fail('
|
|
395
|
-
console.error(error);
|
|
188
|
+
spinner.fail(chalk.red('❌ Failed to initialize Copilot Kit'));
|
|
189
|
+
console.error(chalk.dim(error.message));
|
|
190
|
+
if (options.verbose) {
|
|
191
|
+
console.error(error);
|
|
192
|
+
}
|
|
396
193
|
}
|
|
397
194
|
}
|
|
398
195
|
|
|
399
|
-
function
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
description: ${agent.description}
|
|
404
|
-
skills: [${agent.skills.join(', ')}]
|
|
196
|
+
async function createInstructionFiles(instructionsDir) {
|
|
197
|
+
const instructions = {
|
|
198
|
+
'typescript.instructions.md': `---
|
|
199
|
+
applyTo: "**/*.ts,**/*.tsx,**/*.mts,**/*.cts"
|
|
405
200
|
---
|
|
406
201
|
|
|
407
|
-
#
|
|
202
|
+
# TypeScript Guidelines
|
|
408
203
|
|
|
409
|
-
|
|
410
|
-
|
|
204
|
+
## Strict Mode
|
|
205
|
+
- Enable \`strict: true\` in tsconfig.json
|
|
206
|
+
- No \`any\` types - use \`unknown\` and narrow with type guards
|
|
207
|
+
- Explicit return types for public functions
|
|
208
|
+
|
|
209
|
+
## Patterns
|
|
210
|
+
- Prefer \`interface\` over \`type\` for object shapes
|
|
211
|
+
- Use \`as const\` for literal types
|
|
212
|
+
- Leverage discriminated unions for state
|
|
213
|
+
|
|
214
|
+
## Imports
|
|
215
|
+
- Use type-only imports: \`import type { X } from 'y'\`
|
|
216
|
+
- Barrel exports for public APIs only
|
|
217
|
+
`,
|
|
218
|
+
|
|
219
|
+
'python.instructions.md': `---
|
|
220
|
+
applyTo: "**/*.py"
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
# Python Guidelines
|
|
224
|
+
|
|
225
|
+
## Type Hints
|
|
226
|
+
- Use type hints for all function signatures
|
|
227
|
+
- Use \`from __future__ import annotations\` for forward refs
|
|
228
|
+
- Prefer \`typing.Optional\` over \`X | None\` for Python 3.9 compat
|
|
229
|
+
|
|
230
|
+
## Patterns
|
|
231
|
+
- Use dataclasses or Pydantic for data structures
|
|
232
|
+
- Async/await for I/O bound operations
|
|
233
|
+
- Context managers for resource management
|
|
234
|
+
|
|
235
|
+
## Style
|
|
236
|
+
- Follow PEP 8
|
|
237
|
+
- Use Black for formatting
|
|
238
|
+
- Docstrings in Google style
|
|
239
|
+
`,
|
|
240
|
+
|
|
241
|
+
'security.instructions.md': `---
|
|
242
|
+
applyTo: "**/auth/**,**/security/**,**/*auth*,**/*token*,**/*session*"
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
# Security Guidelines
|
|
246
|
+
|
|
247
|
+
## Authentication
|
|
248
|
+
- JWT with short expiry + refresh tokens
|
|
249
|
+
- HttpOnly cookies for web sessions
|
|
250
|
+
- Rate limit authentication endpoints
|
|
251
|
+
|
|
252
|
+
## Authorization
|
|
253
|
+
- RBAC or ABAC patterns
|
|
254
|
+
- Check permissions server-side always
|
|
255
|
+
- Deny by default, allow explicitly
|
|
256
|
+
|
|
257
|
+
## Data Protection
|
|
258
|
+
- Sanitize all user inputs
|
|
259
|
+
- Escape outputs by context (HTML, SQL, etc.)
|
|
260
|
+
- Never log sensitive data (passwords, tokens, PII)
|
|
261
|
+
|
|
262
|
+
## OWASP Top 10
|
|
263
|
+
- Validate content types
|
|
264
|
+
- CSRF tokens for state-changing operations
|
|
265
|
+
- Security headers (CSP, HSTS, X-Frame-Options)
|
|
266
|
+
`,
|
|
267
|
+
|
|
268
|
+
'database.instructions.md': `---
|
|
269
|
+
applyTo: "**/prisma/**,**/*.sql,**/migrations/**,**/schema.*,**/db/**"
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
# Database Guidelines
|
|
273
|
+
|
|
274
|
+
## Schema Design
|
|
275
|
+
- UUID or ULID for primary keys
|
|
276
|
+
- Timestamps: createdAt, updatedAt on all tables
|
|
277
|
+
- Soft delete with deletedAt when needed
|
|
278
|
+
|
|
279
|
+
## Queries
|
|
280
|
+
- Use parameterized queries only (never string concat)
|
|
281
|
+
- Select only needed fields
|
|
282
|
+
- Use cursor-based pagination for large datasets
|
|
283
|
+
|
|
284
|
+
## Prisma
|
|
285
|
+
- Use transactions for multi-table operations
|
|
286
|
+
- Define indexes for frequently queried fields
|
|
287
|
+
- Use \`@map\` and \`@@map\` for legacy schemas
|
|
288
|
+
|
|
289
|
+
## Migrations
|
|
290
|
+
- One migration per feature
|
|
291
|
+
- Never modify already-applied migrations
|
|
292
|
+
- Test migrations on copy of production data
|
|
293
|
+
`
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
for (const [filename, content] of Object.entries(instructions)) {
|
|
297
|
+
await fs.writeFile(path.join(instructionsDir, filename), content);
|
|
298
|
+
}
|
|
411
299
|
}
|
|
412
300
|
|
|
413
301
|
function generateCopilotInstructions(config) {
|
|
414
302
|
return `# GitHub Copilot Instructions
|
|
415
303
|
|
|
416
|
-
> **Copilot Kit
|
|
417
|
-
|
|
304
|
+
> **Copilot Kit v2** - Project: ${config.projectName}
|
|
305
|
+
|
|
306
|
+
## 🤖 Agent System
|
|
307
|
+
|
|
308
|
+
This project uses specialized AI agents located in \`.github/agents/\`.
|
|
309
|
+
|
|
310
|
+
### Available Agents
|
|
311
|
+
|
|
312
|
+
| Agent | Specialty |
|
|
313
|
+
|-------|-----------|
|
|
314
|
+
| orchestrator | Multi-agent coordination, complex tasks |
|
|
315
|
+
| frontend-specialist | React, Next.js, CSS, accessibility |
|
|
316
|
+
| backend-specialist | Node.js, Python, APIs, microservices |
|
|
317
|
+
| database-architect | Schema design, SQL, Prisma, migrations |
|
|
318
|
+
| security-auditor | OWASP, auth, vulnerability analysis |
|
|
319
|
+
| test-engineer | Testing strategies, coverage, TDD |
|
|
320
|
+
| debugger | Troubleshooting, root cause analysis |
|
|
321
|
+
| devops-engineer | CI/CD, Docker, Kubernetes, infrastructure |
|
|
322
|
+
| performance-optimizer | Web vitals, profiling, optimization |
|
|
323
|
+
| documentation-writer | Technical docs, API documentation |
|
|
324
|
+
|
|
325
|
+
### How to Use Agents
|
|
326
|
+
|
|
327
|
+
To invoke an agent, reference it in your prompt:
|
|
328
|
+
- "Use the **orchestrator** to plan this feature"
|
|
329
|
+
- "Ask the **security-auditor** to review this code"
|
|
330
|
+
- "Have the **debugger** analyze this error"
|
|
331
|
+
|
|
332
|
+
## 📋 Language Instructions
|
|
333
|
+
|
|
334
|
+
Context-specific rules are in \`.github/instructions/\`:
|
|
335
|
+
- \`typescript.instructions.md\` - TS/TSX files
|
|
336
|
+
- \`python.instructions.md\` - Python files
|
|
337
|
+
- \`security.instructions.md\` - Auth/security code
|
|
338
|
+
- \`database.instructions.md\` - Database/Prisma code
|
|
418
339
|
|
|
419
|
-
##
|
|
340
|
+
## 🔧 MCP Servers
|
|
420
341
|
|
|
421
|
-
|
|
422
|
-
|
|
342
|
+
Configured in \`.vscode/mcp.json\`:
|
|
343
|
+
- **filesystem** - File system access
|
|
344
|
+
- **memory** - Persistent memory across sessions
|
|
423
345
|
|
|
424
|
-
|
|
425
|
-
- **Agents:** \`.agent/agents/\` (Specialist personas)
|
|
426
|
-
- **Skills:** \`.agent/skills/\` (Capabilities)
|
|
427
|
-
- **Workflows:** \`.agent/workflows/\` (Procedures)
|
|
428
|
-
- **Scripts:** \`.agent/scripts/\` (Tools)
|
|
346
|
+
## 🚀 Workflows
|
|
429
347
|
|
|
430
|
-
|
|
348
|
+
Workflow templates in \`.github/copilot-workflows/\`:
|
|
349
|
+
- \`/create\` - Scaffold new features
|
|
350
|
+
- \`/debug\` - Systematic debugging
|
|
351
|
+
- \`/test\` - Generate test suites
|
|
352
|
+
- \`/plan\` - Architecture planning
|
|
431
353
|
|
|
432
|
-
|
|
433
|
-
Always read \`.agent/rules/GEMINI.md\` first.
|
|
354
|
+
## 📝 General Guidelines
|
|
434
355
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
356
|
+
1. **Read before writing** - Understand existing patterns
|
|
357
|
+
2. **Small, focused changes** - One concern per commit
|
|
358
|
+
3. **Test coverage** - Write tests for new features
|
|
359
|
+
4. **Security first** - Validate inputs, sanitize outputs
|
|
438
360
|
`;
|
|
439
361
|
}
|
|
440
362
|
|