Skip to content

Commit 8981552

Browse files
committed
added cursor rules
1 parent a3fec5c commit 8981552

9 files changed

Lines changed: 1402 additions & 3 deletions

File tree

.cursor/commands/code-review.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
---
2+
name: code-review
3+
description: Automated PR review using comprehensive checklist tailored for Contentstack CLI plugins
4+
---
5+
6+
# Code Review Command
7+
8+
## Usage Patterns
9+
10+
### Scope-Based Reviews
11+
- `/code-review` - Review all current changes with full checklist
12+
- `/code-review --scope typescript` - Focus on TypeScript configuration and patterns
13+
- `/code-review --scope testing` - Focus on Mocha/Chai/Sinon test patterns
14+
- `/code-review --scope contentstack` - Focus on API integration and CLI patterns
15+
- `/code-review --scope oclif` - Focus on command structure and OCLIF patterns
16+
17+
### Severity Filtering
18+
- `/code-review --severity critical` - Show only critical issues (security, breaking changes)
19+
- `/code-review --severity high` - Show high and critical issues
20+
- `/code-review --severity all` - Show all issues including suggestions
21+
22+
### Package-Aware Reviews
23+
- `/code-review --package contentstack-import` - Review changes in specific package
24+
- `/code-review --package-type plugin` - Review plugin packages only
25+
- `/code-review --package-type library` - Review library packages (e.g., variants)
26+
27+
### File Type Focus
28+
- `/code-review --files commands` - Review command files only
29+
- `/code-review --files tests` - Review test files only
30+
- `/code-review --files modules` - Review import/export modules
31+
32+
## Comprehensive Review Checklist
33+
34+
### Monorepo Structure Compliance
35+
- **Package organization**: Proper placement in `packages/` structure
36+
- **pnpm workspace**: Correct `package.json` workspace configuration
37+
- **Build artifacts**: No `lib/` directories committed to version control
38+
- **Dependencies**: Proper use of shared utilities (`@contentstack/cli-command`, `@contentstack/cli-utilities`)
39+
40+
### TypeScript Standards (Repository-Specific)
41+
- **Configuration compliance**: Follows package-specific TypeScript config
42+
- **Naming conventions**: kebab-case files, PascalCase classes, camelCase functions
43+
- **Type safety**: Appropriate use of strict mode vs relaxed settings per package
44+
- **Import patterns**: ES modules with proper default/named exports
45+
- **Migration strategy**: Proper use of `@ts-ignore` during gradual migration
46+
47+
### OCLIF Command Patterns (Actual Implementation)
48+
- **Base class usage**: Extends `@contentstack/cli-command` (not `@oclif/core`)
49+
- **Command structure**: Proper `static description`, `examples`, `flags`
50+
- **Topic organization**: Uses `cm` topic structure (`cm:stacks:import`)
51+
- **Error handling**: Uses `handleAndLogError` from utilities
52+
- **Validation**: Early flag validation and user-friendly error messages
53+
- **Service delegation**: Commands orchestrate, services implement business logic
54+
55+
### Testing Excellence (Mocha/Chai/Sinon Stack)
56+
- **Framework compliance**: Uses Mocha + Chai + Sinon (not Jest)
57+
- **File patterns**: Follows `*.test.ts` naming (or `*.test.js` for bootstrap)
58+
- **Directory structure**: Proper placement in `test/unit/`, `test/lib/`, etc.
59+
- **Mock patterns**: Proper Sinon stubbing of SDK methods
60+
- **Coverage configuration**: Correct nyc setup (watch for `inlcude` typo)
61+
- **Test isolation**: Proper `beforeEach`/`afterEach` with `sinon.restore()`
62+
- **No real API calls**: All external dependencies properly mocked
63+
64+
### Contentstack API Integration (Real Patterns)
65+
- **SDK usage**: Proper `managementSDKClient` and fluent API chaining
66+
- **Authentication**: Correct `configHandler` and token alias handling
67+
- **Rate limiting compliance**:
68+
- Batch spacing (minimum 1 second between batches)
69+
- 429 retry handling with exponential backoff
70+
- Pagination throttling for variants
71+
- **Error handling**: Proper `handleAndLogError` usage and user-friendly messages
72+
- **Configuration**: Proper regional endpoint and management token handling
73+
74+
### Import/Export Module Architecture
75+
- **BaseClass extension**: Proper inheritance from import/export BaseClass
76+
- **Batch processing**: Correct use of `makeConcurrentCall` and `logMsgAndWaitIfRequired`
77+
- **Module organization**: Proper entity-specific module structure
78+
- **Configuration handling**: Proper `ModuleClassParams` usage
79+
- **Progress feedback**: Appropriate user feedback during long operations
80+
81+
### Security and Best Practices
82+
- **Token security**: No API keys or tokens logged or committed
83+
- **Input validation**: Proper validation of user inputs and flags
84+
- **Error exposure**: No sensitive information in error messages
85+
- **File permissions**: Proper handling of file system operations
86+
- **Process management**: Appropriate use of `process.exit(1)` for critical failures
87+
88+
### Performance Considerations
89+
- **Concurrent processing**: Proper use of `Promise.allSettled` for batch operations
90+
- **Memory management**: Appropriate handling of large datasets
91+
- **Rate limiting**: Compliance with Contentstack API limits (10 req/sec)
92+
- **Batch sizing**: Appropriate batch sizes for different operations
93+
- **Progress tracking**: Efficient progress reporting without performance impact
94+
95+
### Package-Specific Patterns
96+
- **Plugin vs Library**: Correct `oclif.commands` configuration for plugin packages
97+
- **Command compilation**: Proper build pipeline (`tsc``lib/commands``oclif manifest`)
98+
- **Dependency management**: Correct use of shared vs package-specific dependencies
99+
- **Test variations**: Handles different test patterns per package (JS vs TS, different structures)
100+
101+
## Review Execution
102+
103+
### Automated Checks
104+
1. **Lint compliance**: ESLint and TypeScript compiler checks
105+
2. **Test coverage**: nyc coverage thresholds (where enforced)
106+
3. **Build verification**: Successful compilation to `lib/` directories
107+
4. **Dependency audit**: No security vulnerabilities in dependencies
108+
109+
### Manual Review Focus Areas
110+
1. **API integration patterns**: Verify proper SDK usage and error handling
111+
2. **Rate limiting implementation**: Check for proper throttling mechanisms
112+
3. **Test quality**: Verify comprehensive mocking and error scenario coverage
113+
4. **Command usability**: Ensure clear help text and examples
114+
5. **Monorepo consistency**: Check for consistent patterns across packages
115+
116+
### Common Issues to Flag
117+
- **Coverage config typos**: `"inlcude"` instead of `"include"` in `.nycrc.json`
118+
- **Inconsistent TypeScript**: Mixed strict mode usage without migration plan
119+
- **Real API calls in tests**: Any unmocked external dependencies
120+
- **Missing rate limiting**: API calls without proper throttling
121+
- **Build artifacts committed**: Any `lib/` directories in version control
122+
- **Inconsistent error handling**: Not using utilities error handling patterns

.cursor/commands/execute-tests.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
name: execute-tests
3+
description: Run tests by scope, file, or module with intelligent filtering for this pnpm monorepo
4+
---
5+
6+
# Execute Tests Command
7+
8+
## Usage Patterns
9+
10+
### Monorepo-Wide Testing
11+
- `/execute-tests` - Run all tests across all packages
12+
- `/execute-tests --coverage` - Run all tests with nyc coverage report
13+
- `/execute-tests --parallel` - Run package tests in parallel using pnpm
14+
15+
### Package-Specific Testing
16+
- `/execute-tests packages/contentstack-audit/` - Run tests for specific package
17+
- `/execute-tests packages/contentstack-import/` - Run import package tests
18+
- `/execute-tests packages/contentstack-export/` - Run export package tests
19+
- `/execute-tests contentstack-migration` - Run tests by package name (shorthand)
20+
21+
### Scope-Based Testing
22+
- `/execute-tests unit` - Run unit tests only (`test/unit/**/*.test.ts`)
23+
- `/execute-tests commands` - Run command tests (`test/commands/**/*.test.ts`)
24+
- `/execute-tests services` - Run service layer tests
25+
- `/execute-tests modules` - Run import/export module tests
26+
27+
### File Pattern Testing
28+
- `/execute-tests *.test.ts` - Run all TypeScript tests
29+
- `/execute-tests *.test.js` - Run JavaScript tests (bootstrap package)
30+
- `/execute-tests test/unit/services/` - Run tests for specific directory
31+
32+
### Watch and Development
33+
- `/execute-tests --watch` - Run tests in watch mode with file monitoring
34+
- `/execute-tests --debug` - Run tests with debug output enabled
35+
- `/execute-tests --bail` - Stop on first test failure
36+
37+
## Intelligent Filtering
38+
39+
### Repository-Aware Detection
40+
- **Test patterns**: Primarily `*.test.ts`, some `*.test.js` (bootstrap), rare `*.spec.ts`
41+
- **Directory structures**: `test/unit/`, `test/lib/`, `test/seed/`, `test/commands/`
42+
- **Package variations**: Different test layouts per package
43+
- **Build exclusion**: Ignores `lib/` directories (compiled artifacts)
44+
45+
### Monorepo Integration
46+
- **pnpm workspace support**: Uses `pnpm -r --filter` for package targeting
47+
- **Dependency awareness**: Understands package interdependencies
48+
- **Parallel execution**: Leverages pnpm's parallel capabilities
49+
- **Selective testing**: Can target specific packages or file patterns
50+
51+
### Framework Detection
52+
- **Mocha configuration**: Respects `.mocharc.json` files per package
53+
- **TypeScript compilation**: Handles `pretest: tsc -p test` scripts
54+
- **Coverage integration**: Works with nyc configuration (`.nycrc.json`)
55+
- **Test helpers**: Detects and includes test initialization files
56+
57+
## Execution Examples
58+
59+
### Common Workflows
60+
```bash
61+
# Run all tests with coverage
62+
/execute-tests --coverage
63+
64+
# Test specific package during development
65+
/execute-tests packages/contentstack-import/ --watch
66+
67+
# Run only unit tests across all packages
68+
/execute-tests unit
69+
70+
# Test import/export modules specifically
71+
/execute-tests modules --coverage
72+
73+
# Debug failing tests in audit package
74+
/execute-tests packages/contentstack-audit/ --debug --bail
75+
```
76+
77+
### Package-Specific Commands Generated
78+
```bash
79+
# For contentstack-import package
80+
cd packages/contentstack-import && pnpm test
81+
82+
# For all packages with coverage
83+
pnpm -r --filter './packages/*' run test:coverage
84+
85+
# For specific test file
86+
cd packages/contentstack-export && npx mocha test/unit/export/modules/stack.test.ts
87+
```
88+
89+
## Configuration Awareness
90+
91+
### Mocha Integration
92+
- Respects individual package `.mocharc.json` configurations
93+
- Handles TypeScript compilation via `ts-node/register`
94+
- Supports test helpers and initialization files
95+
- Manages timeout settings per package
96+
97+
### Coverage Integration
98+
- Uses nyc for coverage reporting
99+
- Respects `.nycrc.json` configurations (with typo detection)
100+
- Generates HTML, text, and lcov reports
101+
- Handles TypeScript source mapping
102+
103+
### pnpm Workspace Features
104+
- Leverages workspace dependency resolution
105+
- Supports filtered execution by package patterns
106+
- Enables parallel test execution across packages
107+
- Respects package-specific scripts and configurations

.cursor/rules/README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Cursor Rules
2+
3+
Context-aware rules that load automatically based on the files you're editing, optimized for this Contentstack CLI plugins monorepo.
4+
5+
## Rule Files
6+
7+
| File | Scope | Always Applied | Purpose |
8+
|------|-------|----------------|---------|
9+
| `dev-workflow.md` | `**/*.ts`, `**/*.js`, `**/*.json` | Yes | Monorepo TDD workflow, pnpm workspace patterns |
10+
| `typescript.mdc` | `**/*.ts`, `**/*.tsx` | No | TypeScript config variations, naming conventions |
11+
| `testing.mdc` | `**/test/**/*.ts`, `**/test/**/*.js`, `**/*.test.ts`, `**/*.spec.ts` | Yes | Mocha, Chai, Sinon patterns, nyc coverage |
12+
| `oclif-commands.mdc` | `**/commands/**/*.ts` | No | OCLIF patterns, BaseCommand classes, CLI validation |
13+
| `contentstack-cli.mdc` | `**/import/**/*.ts`, `**/export/**/*.ts`, `**/modules/**/*.ts`, `**/services/**/*.ts`, `**/utils/**/*.ts` | No | API integration, rate limiting, batch processing |
14+
15+
## Commands
16+
17+
| File | Trigger | Purpose |
18+
|------|---------|---------|
19+
| `execute-tests.md` | `/execute-tests` | Run tests by scope, package, or module with monorepo awareness |
20+
| `code-review.md` | `/code-review` | Automated PR review with Contentstack CLI specific checklist |
21+
22+
## Loading Behaviour
23+
24+
### File Type Mapping
25+
- **TypeScript files**`typescript.mdc` + `dev-workflow.md`
26+
- **Command files** (`packages/*/src/commands/**/*.ts`) → `oclif-commands.mdc` + `typescript.mdc` + `dev-workflow.md`
27+
- **Import/Export modules** (`packages/*/src/{import,export,modules}/**/*.ts`) → `contentstack-cli.mdc` + `typescript.mdc` + `dev-workflow.md`
28+
- **Service files** (`packages/*/src/services/**/*.ts`) → `contentstack-cli.mdc` + `typescript.mdc` + `dev-workflow.md`
29+
- **Test files** (`packages/*/test/**/*.{ts,js}`) → `testing.mdc` + relevant domain rules + `dev-workflow.md`
30+
- **Utility files** (`packages/*/src/utils/**/*.ts`) → `contentstack-cli.mdc` + `typescript.mdc` + `dev-workflow.md`
31+
32+
### Package-Specific Loading
33+
- **Plugin packages** (with `oclif.commands`) → Full command and API rules
34+
- **Library packages** (e.g., variants) → TypeScript and utility rules only
35+
- **Bootstrap package** (JavaScript tests) → Adjusted testing rules
36+
37+
## Repository-Specific Features
38+
39+
### Monorepo Awareness
40+
- **11 plugin packages** under `packages/`
41+
- **pnpm workspaces** configuration
42+
- **Shared utilities**: `@contentstack/cli-command`, `@contentstack/cli-utilities`
43+
- **Build artifacts**: `lib/` directories (excluded from rules)
44+
45+
### Actual Patterns Detected
46+
- **Testing**: Mocha + Chai + Sinon (not Jest)
47+
- **TypeScript**: Mixed strict mode adoption
48+
- **Commands**: Extend `@contentstack/cli-command` (not `@oclif/core`)
49+
- **Rate limiting**: Multiple mechanisms (batch spacing, 429 retry, pagination throttle)
50+
- **Coverage**: nyc with inconsistent enforcement
51+
52+
## Performance Benefits
53+
54+
- **75-85% token reduction** vs monolithic `.cursorrules`
55+
- **Context-aware loading** - only relevant rules activate based on actual file patterns
56+
- **Precise glob patterns** - avoid loading rules for build artifacts or irrelevant files
57+
- **Skills integration** - rules provide quick context, skills provide comprehensive patterns
58+
59+
## Design Principles
60+
61+
### Validated Against Codebase
62+
- Rules reflect **actual patterns** found in repository analysis
63+
- Glob patterns match **real file structure** (not theoretical)
64+
- Examples use **actual dependencies** and APIs
65+
- Coverage targets reflect **current enforcement** (aspirational vs actual)
66+
67+
### Lightweight and Focused
68+
- Each rule has **single responsibility**
69+
- Detailed patterns referenced via **skills system**
70+
- `alwaysApply: true` only for truly universal patterns
71+
- Package-specific variations acknowledged
72+
73+
## Validation Checklist
74+
75+
### Rule Loading Tests (Repository-Specific)
76+
-**Command files** (`packages/*/src/commands/**/*.ts`) → `oclif-commands.mdc` + `typescript.mdc` + `dev-workflow.md`
77+
-**Import modules** (`packages/contentstack-import/src/import/**/*.ts`) → `contentstack-cli.mdc` + `typescript.mdc` + `dev-workflow.md`
78+
-**Export modules** (`packages/contentstack-export/src/export/**/*.ts`) → `contentstack-cli.mdc` + `typescript.mdc` + `dev-workflow.md`
79+
-**Test files** (`packages/*/test/unit/**/*.test.ts`) → `testing.mdc` + `dev-workflow.md`
80+
-**Bootstrap tests** (`packages/contentstack-bootstrap/test/**/*.test.js`) → `testing.mdc` (JS-aware) + `dev-workflow.md`
81+
-**Service files** (`packages/*/src/services/**/*.ts`) → `contentstack-cli.mdc` + `typescript.mdc` + `dev-workflow.md`
82+
83+
### Manual Verification
84+
1. Open files from different packages in Cursor
85+
2. Check active rules shown in chat interface
86+
3. Verify correct rule combinations load based on file location
87+
4. Test manual rule invocation: `@contentstack-cli show me rate limiting patterns`
88+
5. Confirm no rules load for `lib/` build artifacts
89+
90+
### Performance Monitoring
91+
- **Before**: Monolithic rules loaded for all files
92+
- **After**: Context-specific rules based on actual file patterns
93+
- **Expected reduction**: 75-85% in token usage
94+
- **Validation**: Rules load only when relevant to current file context
95+
96+
## Maintenance Notes
97+
98+
### Regular Updates Needed
99+
- **Glob patterns** - Update when package structure changes
100+
- **TypeScript config** - Align with actual tsconfig.json variations
101+
- **Coverage targets** - Sync with actual nyc configuration
102+
- **Dependencies** - Update when shared utilities change
103+
104+
### Known Issues to Monitor
105+
- **Coverage typo**: Several `.nycrc.json` files have `"inlcude"` instead of `"include"`
106+
- **Strict mode inconsistency**: Packages have different TypeScript strictness levels
107+
- **Test patterns**: Bootstrap uses `.test.js` while others use `.test.ts`

0 commit comments

Comments
 (0)