prjct-cli 0.10.8 → 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 CHANGED
@@ -1,5 +1,42 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.10.9] - 2025-11-28
4
+
5
+ ### Added
6
+
7
+ - **Code Pattern Detection & Enforcement** - New system to detect and enforce code patterns
8
+ - `templates/analysis/patterns.md` - Template for detecting SOLID, DRY, naming conventions
9
+ - Detects design patterns: Factory, Singleton, Observer, Repository, Strategy
10
+ - Identifies anti-patterns: God classes, spaghetti code, copy-paste, magic numbers
11
+ - Extracts conventions: naming, style, async patterns, error handling
12
+ - Generates recommendations with specific file locations and fixes
13
+
14
+ ### Enhanced
15
+
16
+ - **`/p:sync` Command** - Now includes pattern analysis
17
+ - Samples 5-10 source files across directories
18
+ - Detects SOLID compliance with evidence
19
+ - Extracts naming and style conventions
20
+ - Flags anti-patterns with severity (HIGH/MEDIUM/LOW)
21
+ - Saves analysis to `analysis/patterns.md`
22
+ - Updates CLAUDE.md with patterns summary
23
+
24
+ - **Context Builder** - Added `codePatterns` path for pattern detection
25
+ - All code-modifying commands now load patterns automatically
26
+ - Commands: now, build, feature, design, cleanup, fix, test, spec, work
27
+
28
+ - **Prompt Builder** - Includes patterns in code generation prompts
29
+ - Full patterns file included for code-modifying commands
30
+ - Explicit instruction: "ALL new code MUST respect these patterns"
31
+ - Anti-pattern prevention: "NO anti-patterns allowed"
32
+
33
+ ### Impact
34
+
35
+ - New code automatically follows project conventions
36
+ - Anti-patterns detected and flagged before they're introduced
37
+ - Better code quality, performance, and scalability
38
+ - Reduced technical debt from day one
39
+
3
40
  ## [0.10.8] - 2025-11-28
4
41
 
5
42
  ### Added
@@ -67,6 +67,7 @@ class ContextBuilder {
67
67
  memory: pathManager.getFilePath(projectId, 'memory', 'context.jsonl'),
68
68
  patterns: pathManager.getFilePath(projectId, 'memory', 'patterns.json'),
69
69
  analysis: pathManager.getFilePath(projectId, 'analysis', 'repo-summary.md'),
70
+ codePatterns: pathManager.getFilePath(projectId, 'analysis', 'patterns.md'),
70
71
  },
71
72
 
72
73
  // Command parameters
@@ -168,10 +169,10 @@ class ContextBuilder {
168
169
  async loadStateForCommand(context, commandName) {
169
170
  // Command-specific file requirements
170
171
  // Minimizes context window usage
171
- // CRITICAL: Always include 'analysis' for pattern detection
172
+ // CRITICAL: Include 'codePatterns' for ALL code-modifying commands
172
173
  const commandFileMap = {
173
174
  // Core workflow
174
- 'now': ['now', 'next', 'analysis'],
175
+ 'now': ['now', 'next', 'analysis', 'codePatterns'],
175
176
  'done': ['now', 'next', 'metrics', 'analysis'],
176
177
  'next': ['next', 'analysis'],
177
178
 
@@ -182,24 +183,24 @@ class ContextBuilder {
182
183
 
183
184
  // Planning
184
185
  'idea': ['ideas', 'next', 'analysis'],
185
- 'feature': ['roadmap', 'next', 'ideas', 'analysis'],
186
+ 'feature': ['roadmap', 'next', 'ideas', 'analysis', 'codePatterns'],
186
187
  'roadmap': ['roadmap', 'analysis'],
187
- 'spec': ['roadmap', 'next', 'specs', 'analysis'],
188
+ 'spec': ['roadmap', 'next', 'specs', 'analysis', 'codePatterns'],
188
189
 
189
190
  // Analysis
190
- 'analyze': ['analysis', 'context'],
191
- 'sync': ['analysis', 'context', 'now'],
192
-
193
- // Code modification commands - ALWAYS need analysis for patterns
194
- 'work': ['now', 'next', 'analysis', 'context'],
195
- 'build': ['now', 'next', 'analysis', 'context'],
196
- 'design': ['analysis', 'context'],
197
- 'cleanup': ['analysis', 'context'],
198
- 'fix': ['analysis', 'context'],
199
- 'test': ['analysis', 'context'],
200
-
201
- // All files (fallback)
202
- 'default': ['analysis'] // Always include analysis even for unknown commands
191
+ 'analyze': ['analysis', 'context', 'codePatterns'],
192
+ 'sync': ['analysis', 'context', 'now', 'codePatterns'],
193
+
194
+ // Code modification commands - ALWAYS need codePatterns
195
+ 'work': ['now', 'next', 'analysis', 'context', 'codePatterns'],
196
+ 'build': ['now', 'next', 'analysis', 'context', 'codePatterns'],
197
+ 'design': ['analysis', 'context', 'codePatterns'],
198
+ 'cleanup': ['analysis', 'context', 'codePatterns'],
199
+ 'fix': ['analysis', 'context', 'codePatterns'],
200
+ 'test': ['analysis', 'context', 'codePatterns'],
201
+
202
+ // All files (fallback) - include codePatterns for any code work
203
+ 'default': ['analysis', 'codePatterns']
203
204
  }
204
205
 
205
206
  const requiredFiles = commandFileMap[commandName] || commandFileMap.default
@@ -113,11 +113,20 @@ class PromptBuilder {
113
113
  }
114
114
 
115
115
  // OPTIMIZED: Only include patterns for code-modifying commands
116
- // Commands like now, done, ship, recap, next don't need full patterns
117
- const codeCommands = ['build', 'feature', 'design', 'cleanup', 'fix', 'bug', 'test', 'init']
116
+ // Commands like done, ship, recap, next don't need full patterns
117
+ const codeCommands = ['now', 'build', 'feature', 'design', 'cleanup', 'fix', 'bug', 'test', 'init', 'spec', 'work']
118
118
  const commandName = template.frontmatter?.name?.replace('p:', '') || ''
119
119
  const needsPatterns = codeCommands.includes(commandName)
120
120
 
121
+ // Include code patterns analysis for code-modifying commands
122
+ const codePatternsContent = state?.codePatterns || ''
123
+ if (needsPatterns && codePatternsContent && codePatternsContent.trim()) {
124
+ parts.push('\n## CODE PATTERNS (MUST FOLLOW)\n')
125
+ // Include the full patterns file - it contains critical conventions
126
+ parts.push(codePatternsContent)
127
+ parts.push('\n**ALL new code MUST respect these patterns. NO anti-patterns allowed.**\n')
128
+ }
129
+
121
130
  const analysisContent = state?.analysis || ''
122
131
  if (needsPatterns && analysisContent && analysisContent.trim()) {
123
132
  // Extract stack info compactly
@@ -125,8 +134,10 @@ class PromptBuilder {
125
134
  analysisContent.match(/Technology[:\s]+([^\n]+)/i)
126
135
  const stack = stackMatch ? stackMatch[1].trim() : 'detected'
127
136
 
128
- parts.push(`\n## PATTERNS\nStack: ${stack}\n`)
129
- parts.push('Read analysis/repo-summary.md + similar files before coding. Match patterns exactly.\n')
137
+ parts.push(`\n## STACK\nStack: ${stack}\n`)
138
+ if (!codePatternsContent) {
139
+ parts.push('Read analysis/repo-summary.md + similar files before coding. Match patterns exactly.\n')
140
+ }
130
141
  }
131
142
 
132
143
  // CRITICAL: Compressed rules (replaces 78 lines with 12)
@@ -190,8 +201,8 @@ class PromptBuilder {
190
201
  const relevant = []
191
202
  for (const [key, content] of Object.entries(state)) {
192
203
  if (content && content.trim()) {
193
- // Include full content for critical files (now, next, context)
194
- const criticalFiles = ['now', 'next', 'context', 'analysis']
204
+ // Include full content for critical files (now, next, context, patterns)
205
+ const criticalFiles = ['now', 'next', 'context', 'analysis', 'codePatterns']
195
206
  if (criticalFiles.includes(key)) {
196
207
  // Include full content for critical files (up to 2000 chars)
197
208
  const display = content.length > 2000
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prjct-cli",
3
- "version": "0.10.8",
3
+ "version": "0.10.9",
4
4
  "description": "Built for Claude - Ship fast, track progress, stay focused. Developer momentum tool for indie hackers.",
5
5
  "main": "core/index.js",
6
6
  "bin": {
@@ -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.
@@ -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
- 1. Execute `/p:analyze`
10
- 2. Read `analysis/repo-summary.md`
11
- 3. Generate agents per technology → `agents/`
12
- 4. Log to memory
9
+
10
+ 1. Execute `/p:analyze` → generates `analysis/repo-summary.md`
11
+ 2. Execute pattern analysisgenerates `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
- `🔄 Synced | Generated: {agents} | Next: /p:context`
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
+ ```