prjct-cli 0.10.6 → 0.10.9
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 +107 -0
- package/core/__tests__/agentic/prompt-builder.test.js +244 -0
- package/core/__tests__/utils/output.test.js +163 -0
- package/core/agentic/agent-router.js +45 -173
- package/core/agentic/context-builder.js +25 -15
- package/core/agentic/context-filter.js +118 -313
- package/core/agentic/prompt-builder.js +90 -46
- package/core/commands.js +121 -637
- package/core/domain/agent-generator.js +55 -4
- package/core/domain/analyzer.js +122 -0
- package/core/domain/context-estimator.js +32 -53
- package/core/domain/smart-cache.js +2 -1
- package/core/domain/task-analyzer.js +75 -146
- package/core/domain/task-stack.js +2 -1
- package/core/utils/logger.js +64 -0
- package/core/utils/output.js +54 -0
- package/package.json +1 -1
- package/templates/agentic/agent-routing.md +78 -0
- package/templates/agentic/context-filtering.md +77 -0
- package/templates/analysis/patterns.md +206 -0
- package/templates/analysis/project-analysis.md +78 -0
- package/templates/commands/sync.md +61 -7
- package/core/domain/tech-detector.js +0 -365
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
---
|
|
2
|
+
allowed-tools: [Read, Glob, Grep]
|
|
3
|
+
description: 'Analyze code patterns, conventions, and anti-patterns'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Code Pattern Analysis
|
|
7
|
+
|
|
8
|
+
## Objective
|
|
9
|
+
|
|
10
|
+
Detect code patterns, conventions, and anti-patterns to ensure ALL new code respects the project's established practices.
|
|
11
|
+
|
|
12
|
+
## Step 1: Analyze Code Structure
|
|
13
|
+
|
|
14
|
+
### File Organization
|
|
15
|
+
- Read 5-10 representative source files
|
|
16
|
+
- Identify: single vs multiple exports per file
|
|
17
|
+
- Check: file size patterns (small focused files vs large files)
|
|
18
|
+
- Note: directory organization (by feature, by layer, by type)
|
|
19
|
+
|
|
20
|
+
### Module Patterns
|
|
21
|
+
- ES Modules vs CommonJS
|
|
22
|
+
- Default exports vs named exports
|
|
23
|
+
- Barrel files (index.js re-exports)
|
|
24
|
+
- Circular dependency patterns
|
|
25
|
+
|
|
26
|
+
## Step 2: Detect Design Patterns
|
|
27
|
+
|
|
28
|
+
### SOLID Principles
|
|
29
|
+
Analyze for evidence of:
|
|
30
|
+
|
|
31
|
+
| Principle | Look For | Example |
|
|
32
|
+
|-----------|----------|---------|
|
|
33
|
+
| **S**ingle Responsibility | Small, focused files/functions | `validateUser()` not `validateAndSaveUser()` |
|
|
34
|
+
| **O**pen/Closed | Extension points, plugins | Base classes, strategy pattern |
|
|
35
|
+
| **L**iskov Substitution | Interface consistency | Subclasses behave like parents |
|
|
36
|
+
| **I**nterface Segregation | Small, specific interfaces | Multiple small interfaces vs one large |
|
|
37
|
+
| **D**ependency Inversion | Dependency injection | Constructor injection, factories |
|
|
38
|
+
|
|
39
|
+
### DRY (Don't Repeat Yourself)
|
|
40
|
+
- Check for utility/helper directories
|
|
41
|
+
- Look for shared constants
|
|
42
|
+
- Identify reusable components/functions
|
|
43
|
+
- Note any obvious duplication
|
|
44
|
+
|
|
45
|
+
### Other Patterns
|
|
46
|
+
- Factory pattern (createX functions)
|
|
47
|
+
- Singleton pattern (shared instances)
|
|
48
|
+
- Observer pattern (event emitters)
|
|
49
|
+
- Repository pattern (data access layer)
|
|
50
|
+
- Strategy pattern (interchangeable algorithms)
|
|
51
|
+
|
|
52
|
+
## Step 3: Identify Conventions
|
|
53
|
+
|
|
54
|
+
### Naming Conventions
|
|
55
|
+
```
|
|
56
|
+
Analyze actual code for:
|
|
57
|
+
- Functions: camelCase, snake_case, PascalCase?
|
|
58
|
+
- Classes: PascalCase?
|
|
59
|
+
- Constants: UPPER_SNAKE_CASE?
|
|
60
|
+
- Files: kebab-case, camelCase, PascalCase?
|
|
61
|
+
- Private members: _prefix, #private?
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Code Style
|
|
65
|
+
- Semicolons: yes/no
|
|
66
|
+
- Quotes: single/double
|
|
67
|
+
- Indentation: tabs/spaces (2/4)
|
|
68
|
+
- Trailing commas: yes/no
|
|
69
|
+
- Max line length observed
|
|
70
|
+
|
|
71
|
+
### Error Handling
|
|
72
|
+
- Try-catch patterns
|
|
73
|
+
- Custom error classes
|
|
74
|
+
- Error propagation (throw vs return)
|
|
75
|
+
- Logging patterns
|
|
76
|
+
|
|
77
|
+
### Async Patterns
|
|
78
|
+
- async/await vs Promises vs callbacks
|
|
79
|
+
- Error handling in async code
|
|
80
|
+
- Parallel execution patterns
|
|
81
|
+
|
|
82
|
+
## Step 4: Detect Anti-Patterns
|
|
83
|
+
|
|
84
|
+
### Code Smells (Flag These)
|
|
85
|
+
|
|
86
|
+
| Anti-Pattern | Detection | Severity |
|
|
87
|
+
|--------------|-----------|----------|
|
|
88
|
+
| **God Class/File** | File > 300 lines, too many responsibilities | HIGH |
|
|
89
|
+
| **Spaghetti Code** | Deep nesting > 4 levels, unclear flow | HIGH |
|
|
90
|
+
| **Copy-Paste Code** | Duplicate blocks across files | MEDIUM |
|
|
91
|
+
| **Magic Numbers** | Hardcoded values without constants | MEDIUM |
|
|
92
|
+
| **Long Functions** | Function > 50 lines | MEDIUM |
|
|
93
|
+
| **Too Many Parameters** | Function with > 4 params | LOW |
|
|
94
|
+
| **Dead Code** | Commented out code, unused exports | LOW |
|
|
95
|
+
| **Mixed Concerns** | I/O mixed with business logic | MEDIUM |
|
|
96
|
+
| **Callback Hell** | Nested callbacks > 3 levels | HIGH |
|
|
97
|
+
| **Mutable Global State** | Global variables modified everywhere | HIGH |
|
|
98
|
+
|
|
99
|
+
### Architecture Smells
|
|
100
|
+
|
|
101
|
+
| Anti-Pattern | Detection | Recommendation |
|
|
102
|
+
|--------------|-----------|----------------|
|
|
103
|
+
| **Circular Dependencies** | A imports B, B imports A | Extract shared module |
|
|
104
|
+
| **Feature Envy** | Function uses other module's data excessively | Move function to that module |
|
|
105
|
+
| **Inappropriate Intimacy** | Classes know too much about each other | Use interfaces/abstractions |
|
|
106
|
+
| **Lazy Class** | Class does almost nothing | Merge with related class |
|
|
107
|
+
| **Speculative Generality** | Unused abstractions "for future" | Remove until needed |
|
|
108
|
+
|
|
109
|
+
## Step 5: Performance Patterns
|
|
110
|
+
|
|
111
|
+
### Good Patterns to Note
|
|
112
|
+
- Memoization usage
|
|
113
|
+
- Lazy loading
|
|
114
|
+
- Caching strategies
|
|
115
|
+
- Batch operations
|
|
116
|
+
- Connection pooling
|
|
117
|
+
|
|
118
|
+
### Performance Anti-Patterns
|
|
119
|
+
- N+1 queries
|
|
120
|
+
- Synchronous I/O in loops
|
|
121
|
+
- Memory leaks (unclosed resources)
|
|
122
|
+
- Unbounded data structures
|
|
123
|
+
|
|
124
|
+
## Output Format
|
|
125
|
+
|
|
126
|
+
Generate `analysis/patterns.md` with:
|
|
127
|
+
|
|
128
|
+
```markdown
|
|
129
|
+
# Code Patterns - {Project Name}
|
|
130
|
+
|
|
131
|
+
> Auto-generated by /p:sync
|
|
132
|
+
> Last analyzed: {timestamp}
|
|
133
|
+
|
|
134
|
+
## Design Patterns Detected
|
|
135
|
+
|
|
136
|
+
### Applied Patterns ✅
|
|
137
|
+
- **{Pattern}**: {Where used} - {Example}
|
|
138
|
+
|
|
139
|
+
### SOLID Compliance
|
|
140
|
+
| Principle | Status | Evidence |
|
|
141
|
+
|-----------|--------|----------|
|
|
142
|
+
| Single Responsibility | ✅/⚠️/❌ | {evidence} |
|
|
143
|
+
| Open/Closed | ✅/⚠️/❌ | {evidence} |
|
|
144
|
+
| Liskov Substitution | ✅/⚠️/❌ | {evidence} |
|
|
145
|
+
| Interface Segregation | ✅/⚠️/❌ | {evidence} |
|
|
146
|
+
| Dependency Inversion | ✅/⚠️/❌ | {evidence} |
|
|
147
|
+
|
|
148
|
+
## Conventions (MUST FOLLOW)
|
|
149
|
+
|
|
150
|
+
### Naming
|
|
151
|
+
- Functions: {convention}
|
|
152
|
+
- Classes: {convention}
|
|
153
|
+
- Files: {convention}
|
|
154
|
+
- Constants: {convention}
|
|
155
|
+
|
|
156
|
+
### Style
|
|
157
|
+
- Semicolons: {yes/no}
|
|
158
|
+
- Quotes: {single/double}
|
|
159
|
+
- Async: {async-await/promises/callbacks}
|
|
160
|
+
|
|
161
|
+
### Structure
|
|
162
|
+
- Exports: {single/multiple per file}
|
|
163
|
+
- Max file size: {observed max}
|
|
164
|
+
- Directory organization: {pattern}
|
|
165
|
+
|
|
166
|
+
## Anti-Patterns Found ⚠️
|
|
167
|
+
|
|
168
|
+
### High Priority
|
|
169
|
+
1. **{Anti-pattern}**: {file:line}
|
|
170
|
+
- Problem: {description}
|
|
171
|
+
- Fix: {recommendation}
|
|
172
|
+
|
|
173
|
+
### Medium Priority
|
|
174
|
+
1. **{Anti-pattern}**: {file:line}
|
|
175
|
+
- Problem: {description}
|
|
176
|
+
- Fix: {recommendation}
|
|
177
|
+
|
|
178
|
+
## Recommendations
|
|
179
|
+
|
|
180
|
+
### Immediate Actions
|
|
181
|
+
1. {Action with specific file/location}
|
|
182
|
+
|
|
183
|
+
### Best Practices for New Code
|
|
184
|
+
1. {Practice based on detected patterns}
|
|
185
|
+
2. {Practice based on conventions}
|
|
186
|
+
3. {Practice to avoid anti-patterns}
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
**IMPORTANT**: All new code MUST follow these patterns and conventions.
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Integration Rules
|
|
194
|
+
|
|
195
|
+
When generating new code, Claude MUST:
|
|
196
|
+
|
|
197
|
+
1. **Check patterns.md FIRST** before writing any code
|
|
198
|
+
2. **Match naming conventions** exactly as detected
|
|
199
|
+
3. **Follow file structure** patterns (size, organization)
|
|
200
|
+
4. **Apply detected design patterns** where appropriate
|
|
201
|
+
5. **NEVER introduce anti-patterns** listed in the analysis
|
|
202
|
+
6. **Warn if asked to violate** established patterns
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
**Remember**: Quality > Speed. Anti-patterns create technical debt.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
allowed-tools: [Read, Glob, Bash]
|
|
3
|
+
description: 'Analyze project technology stack - Claude reads and decides'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Project Analysis Instructions
|
|
7
|
+
|
|
8
|
+
## Objective
|
|
9
|
+
|
|
10
|
+
Determine the technology stack by READING actual files, not assuming.
|
|
11
|
+
|
|
12
|
+
## Step 1: Read Dependency Files
|
|
13
|
+
|
|
14
|
+
Read these files if they exist:
|
|
15
|
+
|
|
16
|
+
- `package.json` → Node.js/JavaScript/TypeScript project
|
|
17
|
+
- `Cargo.toml` → Rust project
|
|
18
|
+
- `go.mod` → Go project
|
|
19
|
+
- `requirements.txt` or `pyproject.toml` → Python project
|
|
20
|
+
- `Gemfile` → Ruby project
|
|
21
|
+
- `mix.exs` → Elixir project
|
|
22
|
+
- `pom.xml` or `build.gradle` → Java project
|
|
23
|
+
- `composer.json` → PHP project
|
|
24
|
+
|
|
25
|
+
**Extract actual dependencies** - don't guess frameworks.
|
|
26
|
+
|
|
27
|
+
## Step 2: Examine Directory Structure
|
|
28
|
+
|
|
29
|
+
List the root directory to identify:
|
|
30
|
+
|
|
31
|
+
- Source directories (src/, lib/, app/, cmd/)
|
|
32
|
+
- Test directories (tests/, spec/, __tests__/)
|
|
33
|
+
- Config directories (.github/, .gitlab/, .vscode/)
|
|
34
|
+
- Build outputs (dist/, build/, target/)
|
|
35
|
+
|
|
36
|
+
## Step 3: Check Configuration Files
|
|
37
|
+
|
|
38
|
+
Look for:
|
|
39
|
+
|
|
40
|
+
- `tsconfig.json` → TypeScript configuration
|
|
41
|
+
- `Dockerfile` → Docker usage
|
|
42
|
+
- `docker-compose.yml` → Multi-container setup
|
|
43
|
+
- `.eslintrc`, `.prettierrc` → Linting/formatting
|
|
44
|
+
- `jest.config.js`, `vitest.config.ts` → Testing setup
|
|
45
|
+
- `.env*` files → Environment configuration
|
|
46
|
+
|
|
47
|
+
## Step 4: Determine Stack
|
|
48
|
+
|
|
49
|
+
Based on what you READ (not assumed):
|
|
50
|
+
|
|
51
|
+
1. **Languages**: Identify from file extensions and configs
|
|
52
|
+
2. **Frameworks**: Extract from actual dependencies
|
|
53
|
+
3. **Tools**: Identify from config files present
|
|
54
|
+
4. **Databases**: Look for DB clients in dependencies
|
|
55
|
+
5. **Testing**: Identify test frameworks from configs/deps
|
|
56
|
+
|
|
57
|
+
## Output Format
|
|
58
|
+
|
|
59
|
+
Provide analysis in this structure:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"languages": ["actual languages found"],
|
|
64
|
+
"frameworks": ["actual frameworks from deps"],
|
|
65
|
+
"tools": ["tools with config files present"],
|
|
66
|
+
"databases": ["database clients in deps"],
|
|
67
|
+
"testing": ["test frameworks found"],
|
|
68
|
+
"notes": "any observations about the project"
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Rules
|
|
73
|
+
|
|
74
|
+
- **NO hardcoded assumptions** - React doesn't mean "frontend"
|
|
75
|
+
- **READ before deciding** - Don't guess based on filenames
|
|
76
|
+
- **Any stack works** - Elixir, Rust, Go, Python, etc.
|
|
77
|
+
- **Be specific** - Include versions when available
|
|
78
|
+
- **Note uncertainty** - If unclear, say so
|
|
@@ -1,17 +1,71 @@
|
|
|
1
1
|
---
|
|
2
|
-
allowed-tools: [Read, Write, Bash, TodoWrite]
|
|
3
|
-
description: 'Sync state + generate agents'
|
|
2
|
+
allowed-tools: [Read, Write, Bash, Glob, Grep, TodoWrite]
|
|
3
|
+
description: 'Sync state + generate agents + detect patterns'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# /p:sync
|
|
7
7
|
|
|
8
8
|
## Flow
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
|
|
10
|
+
1. Execute `/p:analyze` → generates `analysis/repo-summary.md`
|
|
11
|
+
2. Execute pattern analysis → generates `analysis/patterns.md`
|
|
12
|
+
3. Read both analysis files
|
|
13
|
+
4. Generate agents per technology → `agents/`
|
|
14
|
+
5. Update `CLAUDE.md` with patterns summary
|
|
15
|
+
6. Log to memory
|
|
16
|
+
|
|
17
|
+
## Pattern Analysis (Step 2)
|
|
18
|
+
|
|
19
|
+
Read `templates/analysis/patterns.md` and execute:
|
|
20
|
+
|
|
21
|
+
1. **Sample 5-10 source files** across different directories
|
|
22
|
+
2. **Detect design patterns**: SOLID, DRY, factories, etc.
|
|
23
|
+
3. **Extract conventions**: naming, style, structure
|
|
24
|
+
4. **Flag anti-patterns**: god classes, duplication, mixed concerns
|
|
25
|
+
5. **Generate recommendations**: immediate fixes + best practices
|
|
26
|
+
|
|
27
|
+
### Key Files to Analyze
|
|
28
|
+
```
|
|
29
|
+
- Main entry point (bin/, src/index, main)
|
|
30
|
+
- Largest source files (potential god classes)
|
|
31
|
+
- Utility/helper directories (DRY evidence)
|
|
32
|
+
- Test files (testing patterns)
|
|
33
|
+
- Config files (tooling conventions)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Output
|
|
37
|
+
Save to `analysis/patterns.md` with:
|
|
38
|
+
- Detected patterns (what to follow)
|
|
39
|
+
- Conventions (MUST match in new code)
|
|
40
|
+
- Anti-patterns found (with fixes)
|
|
41
|
+
- Recommendations (for quality)
|
|
42
|
+
|
|
43
|
+
## Agent Generation (Step 4)
|
|
13
44
|
|
|
14
45
|
Use: `generateDynamicAgent(name, config)`
|
|
15
46
|
|
|
47
|
+
## CLAUDE.md Update (Step 5)
|
|
48
|
+
|
|
49
|
+
Add patterns summary section:
|
|
50
|
+
```markdown
|
|
51
|
+
## Code Patterns
|
|
52
|
+
|
|
53
|
+
**Follow these patterns in ALL new code:**
|
|
54
|
+
- {key conventions from patterns.md}
|
|
55
|
+
- {design patterns to apply}
|
|
56
|
+
|
|
57
|
+
**Avoid these anti-patterns:**
|
|
58
|
+
- {detected anti-patterns}
|
|
59
|
+
```
|
|
60
|
+
|
|
16
61
|
## Response
|
|
17
|
-
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
🔄 Synced
|
|
65
|
+
├── Stack: {languages/frameworks}
|
|
66
|
+
├── Agents: {count} generated
|
|
67
|
+
├── Patterns: {count} detected
|
|
68
|
+
└── Anti-patterns: {count} flagged
|
|
69
|
+
|
|
70
|
+
Next: /p:context or /p:now
|
|
71
|
+
```
|