cp-toolkit 2.2.1 → 2.2.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cp-toolkit",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "Copilot Toolkit - AI Agent framework for GitHub Copilot, Claude, Gemini CLI, and other AI assistants",
5
5
  "keywords": [
6
6
  "ai-agents",
@@ -147,6 +147,14 @@ export async function initCommand(directory, options) {
147
147
  ],
148
148
  "disabled": false,
149
149
  "autoApprove": []
150
+ },
151
+ "antigravity": {
152
+ "command": "node",
153
+ "args": [
154
+ "${workspaceFolder}/.github/scripts/mcp-server.js"
155
+ ],
156
+ "disabled": false,
157
+ "autoApprove": []
150
158
  }
151
159
  }
152
160
  };
@@ -167,14 +175,53 @@ export async function initCommand(directory, options) {
167
175
  }
168
176
  }
169
177
 
178
+ // 8. Copy scripts to .github/scripts/
179
+ spinner.text = 'Copying scripts...';
180
+ const scriptsSourceDir = path.join(templatesDir, 'scripts');
181
+ const scriptsTargetDir = path.join(targetDir, '.github', 'scripts');
182
+ if (fs.existsSync(scriptsSourceDir)) {
183
+ await fs.ensureDir(scriptsTargetDir);
184
+ await fs.copy(scriptsSourceDir, scriptsTargetDir, { overwrite: true });
185
+ }
186
+
187
+ // 9. Copy ARCHITECTURE.md to .github/
188
+ spinner.text = 'Copying architecture documentation...';
189
+ const architectureSource = path.join(templatesDir, 'ARCHITECTURE.md');
190
+ const architectureTarget = path.join(targetDir, '.github', 'ARCHITECTURE.md');
191
+ if (fs.existsSync(architectureSource)) {
192
+ await fs.copy(architectureSource, architectureTarget, { overwrite: true });
193
+ }
194
+
195
+ // 10. Copy rules to .github/rules/
196
+ spinner.text = 'Copying rules...';
197
+ const rulesSourceDir = path.join(templatesDir, 'rules');
198
+ const rulesTargetDir = path.join(targetDir, '.github', 'rules');
199
+ if (fs.existsSync(rulesSourceDir)) {
200
+ await fs.ensureDir(rulesTargetDir);
201
+ await fs.copy(rulesSourceDir, rulesTargetDir, { overwrite: true });
202
+ }
203
+
170
204
  spinner.succeed(chalk.green('✨ Copilot Kit initialized successfully!'));
171
205
 
172
206
  console.log(chalk.bold('\nšŸ“ Created structure:'));
173
207
  console.log(chalk.dim(' .github/'));
174
208
  console.log(chalk.dim(' ā”œā”€ā”€ agents/ ') + chalk.cyan('← 20 specialist agents'));
175
209
  console.log(chalk.dim(' ā”œā”€ā”€ skills/ ') + chalk.cyan('← Essential skills library'));
176
- console.log(chalk.dim(' ā”œā”€ā”€ instructions/ ') + chalk.cyan('← Language-specific rules'));
210
+ console.log(chalk.dim(' ā”œā”€ā”€ instructions/ ') + chalk.cyan('← 10 specialized instruction files'));
211
+ console.log(chalk.dim(' │ ā”œā”€ā”€ typescript-development.instructions.md'));
212
+ console.log(chalk.dim(' │ ā”œā”€ā”€ javascript-development.instructions.md'));
213
+ console.log(chalk.dim(' │ ā”œā”€ā”€ react-development.instructions.md'));
214
+ console.log(chalk.dim(' │ ā”œā”€ā”€ nextjs-development.instructions.md'));
215
+ console.log(chalk.dim(' │ ā”œā”€ā”€ python-development.instructions.md'));
216
+ console.log(chalk.dim(' │ ā”œā”€ā”€ security-development.instructions.md'));
217
+ console.log(chalk.dim(' │ ā”œā”€ā”€ database-development.instructions.md'));
218
+ console.log(chalk.dim(' │ ā”œā”€ā”€ testing-development.instructions.md'));
219
+ console.log(chalk.dim(' │ ā”œā”€ā”€ api-development.instructions.md'));
220
+ console.log(chalk.dim(' │ └── github-actions.instructions.md'));
177
221
  console.log(chalk.dim(' ā”œā”€ā”€ copilot-workflows/') + chalk.cyan('← Workflow templates'));
222
+ console.log(chalk.dim(' ā”œā”€ā”€ scripts/ ') + chalk.cyan('← MCP server & utilities'));
223
+ console.log(chalk.dim(' ā”œā”€ā”€ rules/ ') + chalk.cyan('← Global AI rules'));
224
+ console.log(chalk.dim(' ā”œā”€ā”€ ARCHITECTURE.md ') + chalk.cyan('← System documentation'));
178
225
  console.log(chalk.dim(' └── copilot-instructions.md'));
179
226
  console.log(chalk.dim(' .vscode/'));
180
227
  console.log(chalk.dim(' └── mcp.json ') + chalk.cyan('← MCP server config'));
@@ -195,101 +242,392 @@ export async function initCommand(directory, options) {
195
242
 
196
243
  async function createInstructionFiles(instructionsDir) {
197
244
  const instructions = {
198
- 'typescript.instructions.md': `---
245
+ 'typescript-development.instructions.md': `---
199
246
  applyTo: "**/*.ts,**/*.tsx,**/*.mts,**/*.cts"
200
247
  ---
201
248
 
202
- # TypeScript Guidelines
249
+ # TypeScript Development Guidelines
203
250
 
204
- ## Strict Mode
251
+ ## Strict Mode & Type Safety
205
252
  - Enable \`strict: true\` in tsconfig.json
206
253
  - No \`any\` types - use \`unknown\` and narrow with type guards
207
254
  - Explicit return types for public functions
255
+ - Use \`strictNullChecks\` and \`noImplicitAny\`
208
256
 
209
- ## Patterns
257
+ ## Code Patterns
210
258
  - Prefer \`interface\` over \`type\` for object shapes
211
- - Use \`as const\` for literal types
212
- - Leverage discriminated unions for state
259
+ - Use \`as const\` for literal types and enums
260
+ - Leverage discriminated unions for state management
261
+ - Use mapped types for transformations
262
+ - Prefer \`readonly\` for immutable data
213
263
 
214
- ## Imports
264
+ ## Imports & Modules
215
265
  - Use type-only imports: \`import type { X } from 'y'\`
216
266
  - Barrel exports for public APIs only
267
+ - Avoid relative imports with \`../\` - use absolute paths
268
+
269
+ ## Error Handling
270
+ - Use custom error classes extending \`Error\`
271
+ - Prefer Result types over throwing exceptions
272
+ - Use try/catch only for external operations
273
+ `,
274
+
275
+ 'javascript-development.instructions.md': `---
276
+ applyTo: "**/*.js,**/*.mjs,**/*.cjs"
277
+ ---
278
+
279
+ # JavaScript Development Guidelines
280
+
281
+ ## ES6+ Features
282
+ - Use \`const\` and \`let\` instead of \`var\`
283
+ - Arrow functions for callbacks and anonymous functions
284
+ - Template literals over string concatenation
285
+ - Destructuring for objects and arrays
286
+ - Spread/rest operators for manipulation
287
+
288
+ ## Code Patterns
289
+ - Prefer functional programming approaches
290
+ - Use async/await over Promises for readability
291
+ - Implement proper error handling with try/catch
292
+ - Use Map/Set for collections when appropriate
293
+ - Leverage object destructuring for configuration
294
+
295
+ ## Best Practices
296
+ - Strict mode: \`'use strict'\` at file/module level
297
+ - Consistent naming: camelCase for variables/functions
298
+ - Meaningful variable names over abbreviations
299
+ - Single responsibility principle for functions
300
+
301
+ ## Performance
302
+ - Avoid global variables
303
+ - Use efficient algorithms and data structures
304
+ - Minimize DOM manipulation
305
+ - Cache expensive operations
217
306
  `,
218
307
 
219
- 'python.instructions.md': `---
308
+ 'react-development.instructions.md': `---
309
+ applyTo: "**/*.jsx,**/*.tsx,**/*react*"
310
+ ---
311
+
312
+ # React Development Guidelines
313
+
314
+ ## Component Patterns
315
+ - Functional components with hooks over class components
316
+ - Custom hooks for reusable logic
317
+ - Compound components for complex UI patterns
318
+ - Container/Presentational separation when appropriate
319
+
320
+ ## State Management
321
+ - useState for local component state
322
+ - useReducer for complex state logic
323
+ - Context API for theme/configuration
324
+ - External libraries (Zustand, Redux) for app-wide state
325
+
326
+ ## Performance
327
+ - React.memo for expensive components
328
+ - useMemo for expensive calculations
329
+ - useCallback for event handlers
330
+ - Lazy loading with React.lazy and Suspense
331
+ - Code splitting for large applications
332
+
333
+ ## Hooks Best Practices
334
+ - Custom hooks for side effects
335
+ - useEffect cleanup functions
336
+ - Dependency arrays correctly specified
337
+ - Avoid conditional hook calls
338
+
339
+ ## Accessibility
340
+ - Semantic HTML elements
341
+ - ARIA attributes when needed
342
+ - Keyboard navigation support
343
+ - Screen reader compatibility
344
+ `,
345
+
346
+ 'nextjs-development.instructions.md': `---
347
+ applyTo: "**/pages/**,**/app/**,**/components/**,**/lib/**,**/utils/**"
348
+ ---
349
+
350
+ # Next.js Development Guidelines
351
+
352
+ ## App Router (App Directory)
353
+ - Server Components by default
354
+ - Client Components with 'use client' directive
355
+ - Server Actions for form handling
356
+ - Route Groups for organization: (auth), (dashboard)
357
+
358
+ ## File Structure
359
+ - \`app/\` for routing and layouts
360
+ - \`components/\` for reusable UI
361
+ - \`lib/\` for utilities and configurations
362
+ - \`utils/\` for helper functions
363
+ - \`types/\` for TypeScript definitions
364
+
365
+ ## Data Fetching
366
+ - Server Components for initial data
367
+ - Client Components for interactive data
368
+ - SWR or React Query for client-side fetching
369
+ - Server Actions for mutations
370
+
371
+ ## Performance
372
+ - Image optimization with next/image
373
+ - Font optimization with next/font
374
+ - Code splitting automatic
375
+ - Static generation when possible
376
+ - ISR for dynamic content
377
+
378
+ ## SEO & Metadata
379
+ - Metadata API for dynamic meta tags
380
+ - Static metadata exports
381
+ - Open Graph and Twitter cards
382
+ - Structured data with JSON-LD
383
+ `,
384
+
385
+ 'python-development.instructions.md': `---
220
386
  applyTo: "**/*.py"
221
387
  ---
222
388
 
223
- # Python Guidelines
389
+ # Python Development Guidelines
224
390
 
225
- ## Type Hints
391
+ ## Type Hints & Annotations
226
392
  - Use type hints for all function signatures
227
393
  - Use \`from __future__ import annotations\` for forward refs
228
394
  - Prefer \`typing.Optional\` over \`X | None\` for Python 3.9 compat
395
+ - Generic types with \`TypeVar\` when needed
229
396
 
230
- ## Patterns
397
+ ## Code Patterns
231
398
  - Use dataclasses or Pydantic for data structures
232
399
  - 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
400
+ - Context managers (\`with\` statements) for resource management
401
+ - List/dict comprehensions for transformations
402
+ - Generator functions for large datasets
403
+
404
+ ## Best Practices
405
+ - Follow PEP 8 style guidelines
406
+ - Use Black for code formatting
407
+ - Google/NumPy style docstrings
408
+ - Meaningful variable names
409
+ - Single responsibility principle
410
+
411
+ ## Error Handling
412
+ - Custom exception classes
413
+ - Specific exception types over generic Exception
414
+ - Proper exception chaining
415
+ - Logging with appropriate levels
416
+
417
+ ## Testing
418
+ - pytest framework preferred
419
+ - Unit tests for functions/classes
420
+ - Integration tests for workflows
421
+ - Mock external dependencies
239
422
  `,
240
423
 
241
- 'security.instructions.md': `---
242
- applyTo: "**/auth/**,**/security/**,**/*auth*,**/*token*,**/*session*"
424
+ 'security-development.instructions.md': `---
425
+ applyTo: "**/auth/**,**/security/**,**/*auth*,**/*token*,**/*session*,**/middleware/**"
243
426
  ---
244
427
 
245
- # Security Guidelines
428
+ # Security Development Guidelines
246
429
 
247
- ## Authentication
430
+ ## Authentication & Authorization
248
431
  - JWT with short expiry + refresh tokens
249
432
  - 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
433
+ - Rate limiting on authentication endpoints
434
+ - RBAC or ABAC patterns implemented
435
+ - Server-side permission checks always
256
436
 
257
437
  ## Data Protection
258
- - Sanitize all user inputs
259
- - Escape outputs by context (HTML, SQL, etc.)
438
+ - Input sanitization and validation
439
+ - Output encoding by context (HTML, SQL, JSON)
260
440
  - Never log sensitive data (passwords, tokens, PII)
441
+ - Encryption at rest and in transit
442
+ - Secure password hashing (bcrypt, Argon2)
261
443
 
262
- ## OWASP Top 10
263
- - Validate content types
444
+ ## Web Security
264
445
  - CSRF tokens for state-changing operations
265
- - Security headers (CSP, HSTS, X-Frame-Options)
446
+ - Content Security Policy (CSP) headers
447
+ - HTTPS enforcement (HSTS)
448
+ - Secure headers (X-Frame-Options, etc.)
449
+ - XSS prevention with proper escaping
450
+
451
+ ## API Security
452
+ - API versioning for breaking changes
453
+ - Request/response validation schemas
454
+ - CORS configuration for allowed origins
455
+ - API rate limiting and throttling
456
+ - Proper error messages (no sensitive info)
457
+
458
+ ## OWASP Top 10
459
+ - Injection prevention (parameterized queries)
460
+ - Broken authentication handling
461
+ - Sensitive data exposure protection
462
+ - XML external entity prevention
463
+ - Access control enforcement
266
464
  `,
267
465
 
268
- 'database.instructions.md': `---
269
- applyTo: "**/prisma/**,**/*.sql,**/migrations/**,**/schema.*,**/db/**"
466
+ 'database-development.instructions.md': `---
467
+ applyTo: "**/prisma/**,**/*.sql,**/migrations/**,**/schema.*,**/db/**,**/models/**"
270
468
  ---
271
469
 
272
- # Database Guidelines
470
+ # Database Development Guidelines
273
471
 
274
472
  ## Schema Design
275
- - UUID or ULID for primary keys
473
+ - UUID or ULID for primary keys (not auto-increment)
276
474
  - Timestamps: createdAt, updatedAt on all tables
277
475
  - Soft delete with deletedAt when needed
476
+ - Proper foreign key relationships
477
+ - Normalized schemas with good indexing
278
478
 
279
- ## Queries
479
+ ## Query Optimization
280
480
  - Use parameterized queries only (never string concat)
281
- - Select only needed fields
481
+ - Select only needed fields (avoid SELECT *)
282
482
  - Use cursor-based pagination for large datasets
483
+ - Proper indexing on frequently queried fields
484
+ - Query execution plan analysis
283
485
 
284
- ## Prisma
486
+ ## ORM Best Practices
285
487
  - Use transactions for multi-table operations
286
- - Define indexes for frequently queried fields
287
- - Use \`@map\` and \`@@map\` for legacy schemas
488
+ - N+1 query problem avoidance
489
+ - Proper eager/lazy loading
490
+ - Migration scripts for schema changes
491
+ - Database constraints and validations
288
492
 
289
- ## Migrations
290
- - One migration per feature
493
+ ## Migration Safety
494
+ - One migration per feature/change
291
495
  - Never modify already-applied migrations
292
- - Test migrations on copy of production data
496
+ - Test migrations on production-like data
497
+ - Rollback scripts for emergency recovery
498
+ - Version control for migration files
499
+
500
+ ## Performance
501
+ - Connection pooling configuration
502
+ - Query result caching strategies
503
+ - Database indexing strategy
504
+ - Read/write splitting when appropriate
505
+ - Monitoring and alerting setup
506
+ `,
507
+
508
+ 'testing-development.instructions.md': `---
509
+ applyTo: "**/*.test.*,**/*.spec.*,**/tests/**,**/__tests__/**"
510
+ ---
511
+
512
+ # Testing Development Guidelines
513
+
514
+ ## Test Structure
515
+ - Unit tests for individual functions/classes
516
+ - Integration tests for component interactions
517
+ - End-to-end tests for user workflows
518
+ - Performance tests for critical paths
519
+ - Accessibility tests for UI components
520
+
521
+ ## Testing Frameworks
522
+ - Jest for JavaScript/TypeScript
523
+ - pytest for Python
524
+ - RSpec for Ruby
525
+ - JUnit for Java
526
+ - Appropriate framework per language
527
+
528
+ ## Test Patterns
529
+ - Arrange-Act-Assert (AAA) pattern
530
+ - Descriptive test names (not test1, test2)
531
+ - One assertion per test when possible
532
+ - Mock external dependencies
533
+ - Test edge cases and error conditions
534
+
535
+ ## Code Coverage
536
+ - Aim for 80%+ coverage on critical code
537
+ - Focus on business logic over getters/setters
538
+ - Integration tests for coverage gaps
539
+ - Coverage reports in CI/CD pipeline
540
+
541
+ ## Best Practices
542
+ - Tests run independently (no shared state)
543
+ - Fast execution for developer experience
544
+ - CI/CD integration with quality gates
545
+ - Test data management and cleanup
546
+ - Documentation of test scenarios
547
+ `,
548
+
549
+ 'api-development.instructions.md': `---
550
+ applyTo: "**/api/**,**/routes/**,**/controllers/**,**/services/**,**/*api*,**/*endpoint*"
551
+ ---
552
+
553
+ # API Development Guidelines
554
+
555
+ ## RESTful Design
556
+ - Proper HTTP methods (GET, POST, PUT, DELETE)
557
+ - Resource-based URLs (/users, /users/{id})
558
+ - Status codes: 200, 201, 400, 401, 403, 404, 500
559
+ - Content-Type and Accept headers
560
+ - Idempotent operations where appropriate
561
+
562
+ ## API Versioning
563
+ - URL versioning: /api/v1/users
564
+ - Header versioning when needed
565
+ - Backward compatibility maintenance
566
+ - Deprecation notices for breaking changes
567
+ - Version documentation
568
+
569
+ ## Request/Response
570
+ - JSON as primary format
571
+ - Consistent response structure
572
+ - Pagination for list endpoints
573
+ - Filtering and sorting parameters
574
+ - Rate limiting headers
575
+
576
+ ## Error Handling
577
+ - Consistent error response format
578
+ - Appropriate HTTP status codes
579
+ - User-friendly error messages
580
+ - Error logging and monitoring
581
+ - Graceful degradation
582
+
583
+ ## Documentation
584
+ - OpenAPI/Swagger specifications
585
+ - Interactive API documentation
586
+ - Authentication examples
587
+ - Rate limiting information
588
+ - Changelog for API versions
589
+ `,
590
+
591
+ 'github-actions.instructions.md': `---
592
+ applyTo: ".github/workflows/**/*.yml,.github/workflows/**/*.yaml"
593
+ ---
594
+
595
+ # GitHub Actions Development Guidelines
596
+
597
+ ## Workflow Structure
598
+ - Descriptive workflow names and jobs
599
+ - Matrix builds for multiple environments
600
+ - Proper job dependencies with needs
601
+ - Conditional execution with if statements
602
+ - Timeout settings for long-running jobs
603
+
604
+ ## Security
605
+ - Use trusted actions from GitHub Marketplace
606
+ - Pin action versions to specific SHAs
607
+ - Use secrets for sensitive data
608
+ - CodeQL for security scanning
609
+ - Dependency review for PRs
610
+
611
+ ## Best Practices
612
+ - Cache dependencies for faster builds
613
+ - Use self-hosted runners when appropriate
614
+ - Proper artifact management
615
+ - Notification configuration
616
+ - Workflow reusability with composite actions
617
+
618
+ ## CI/CD Pipeline
619
+ - Build → Test → Deploy stages
620
+ - Parallel job execution
621
+ - Failure handling and notifications
622
+ - Rollback capabilities
623
+ - Environment-specific configurations
624
+
625
+ ## Performance
626
+ - Efficient caching strategies
627
+ - Minimal artifact sizes
628
+ - Parallel job execution
629
+ - Resource optimization
630
+ - Build time monitoring
293
631
  `
294
632
  };
295
633
 
@@ -332,10 +670,16 @@ To invoke an agent, reference it in your prompt:
332
670
  ## šŸ“‹ Language Instructions
333
671
 
334
672
  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
673
+ - \`typescript-development.instructions.md\` - TypeScript files
674
+ - \`javascript-development.instructions.md\` - JavaScript files
675
+ - \`react-development.instructions.md\` - React components
676
+ - \`nextjs-development.instructions.md\` - Next.js applications
677
+ - \`python-development.instructions.md\` - Python files
678
+ - \`security-development.instructions.md\` - Auth/security code
679
+ - \`database-development.instructions.md\` - Database/ORM code
680
+ - \`testing-development.instructions.md\` - Test files
681
+ - \`api-development.instructions.md\` - API endpoints
682
+ - \`github-actions.instructions.md\` - GitHub Actions workflows
339
683
 
340
684
  ## šŸ”§ MCP Servers
341
685
 
@@ -29,7 +29,7 @@ import {
29
29
  import * as fs from 'fs/promises';
30
30
  import * as path from 'path';
31
31
 
32
- const AGENT_ROOT = process.env.AGENT_ROOT || path.join(process.cwd(), '.agent');
32
+ const AGENT_ROOT = process.env.AGENT_ROOT || path.join(process.cwd(), '.github');
33
33
 
34
34
  // ============================================================================
35
35
  // HELPERS