crackerjack 0.31.17__py3-none-any.whl → 0.32.0__py3-none-any.whl
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.
Potentially problematic release.
This version of crackerjack might be problematic. Click here for more details.
- crackerjack/CLAUDE.md +71 -452
- crackerjack/__main__.py +1 -1
- crackerjack/agents/refactoring_agent.py +67 -46
- crackerjack/cli/handlers.py +7 -7
- crackerjack/config/hooks.py +36 -6
- crackerjack/core/async_workflow_orchestrator.py +2 -2
- crackerjack/core/phase_coordinator.py +28 -0
- crackerjack/core/workflow_orchestrator.py +348 -18
- crackerjack/dynamic_config.py +1 -25
- crackerjack/managers/test_command_builder.py +15 -11
- crackerjack/mcp/tools/execution_tools.py +8 -0
- crackerjack/mcp/tools/workflow_executor.py +130 -40
- crackerjack/models/protocols.py +45 -0
- crackerjack/security/__init__.py +1 -0
- crackerjack/security/audit.py +212 -0
- crackerjack/services/git.py +88 -2
- crackerjack/services/performance_benchmarks.py +2 -2
- crackerjack/tools/validate_regex_patterns.py +14 -0
- {crackerjack-0.31.17.dist-info → crackerjack-0.32.0.dist-info}/METADATA +1 -1
- {crackerjack-0.31.17.dist-info → crackerjack-0.32.0.dist-info}/RECORD +23 -21
- {crackerjack-0.31.17.dist-info → crackerjack-0.32.0.dist-info}/WHEEL +0 -0
- {crackerjack-0.31.17.dist-info → crackerjack-0.32.0.dist-info}/entry_points.txt +0 -0
- {crackerjack-0.31.17.dist-info → crackerjack-0.32.0.dist-info}/licenses/LICENSE +0 -0
crackerjack/CLAUDE.md
CHANGED
|
@@ -2,345 +2,120 @@
|
|
|
2
2
|
|
|
3
3
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
4
|
|
|
5
|
-
## Clean Code Philosophy (READ FIRST)
|
|
6
|
-
|
|
7
|
-
**EVERY LINE OF CODE IS A LIABILITY. The best code is no code.**
|
|
8
|
-
|
|
9
|
-
- **DRY**: If you write it twice, you're doing it wrong
|
|
10
|
-
- **YAGNI**: Build only what's needed NOW
|
|
11
|
-
- **KISS**: Complexity is the enemy of maintainability
|
|
12
|
-
- **Less is More**: Prefer 10 clear lines over 100 clever ones
|
|
13
|
-
- **Code is Read 10x More Than Written**: Optimize for readability
|
|
14
|
-
- **Self-Documenting Code**: Variable names must be clear and descriptive, even in inline functions
|
|
15
|
-
|
|
16
|
-
## Design Philosophy
|
|
17
|
-
|
|
18
|
-
- **Auto-Discovery**: Prefer intelligent auto-discovery of configurations and settings over manual configuration whenever possible, reducing setup friction and configuration errors
|
|
19
|
-
|
|
20
5
|
## Project Overview
|
|
21
6
|
|
|
22
|
-
Crackerjack is an opinionated Python project management tool unifying UV, Ruff, pytest, and pre-commit into a single workflow
|
|
7
|
+
Crackerjack is an opinionated Python project management tool unifying UV, Ruff, pytest, and pre-commit into a single workflow with AI agent integration via MCP.
|
|
23
8
|
|
|
24
9
|
**Key Dependencies**: Python 3.13+, UV, pre-commit, pytest
|
|
25
10
|
|
|
26
|
-
|
|
11
|
+
**Clean Code Philosophy**: DRY/YAGNI/KISS - Every line is a liability. Optimize for readability with self-documenting code.
|
|
27
12
|
|
|
28
|
-
|
|
13
|
+
## AI Documentation References
|
|
29
14
|
|
|
30
|
-
- **[AI-REFERENCE.md](AI-REFERENCE.md)** -
|
|
31
|
-
- **[AGENT-CAPABILITIES.json](AGENT-CAPABILITIES.json)** - Structured agent data
|
|
32
|
-
- **[ERROR-PATTERNS.yaml](ERROR-PATTERNS.yaml)** -
|
|
15
|
+
- **[AI-REFERENCE.md](AI-REFERENCE.md)** - Command reference with decision trees
|
|
16
|
+
- **[AGENT-CAPABILITIES.json](AGENT-CAPABILITIES.json)** - Structured agent data
|
|
17
|
+
- **[ERROR-PATTERNS.yaml](ERROR-PATTERNS.yaml)** - Automated issue resolution patterns
|
|
33
18
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
## Quick Reference
|
|
37
|
-
|
|
38
|
-
### Most Used Commands
|
|
19
|
+
## Essential Commands
|
|
39
20
|
|
|
40
21
|
```bash
|
|
41
|
-
# Daily
|
|
42
|
-
python -m crackerjack
|
|
43
|
-
python -m crackerjack -t
|
|
44
|
-
python -m crackerjack --ai-agent -t
|
|
22
|
+
# Daily workflow
|
|
23
|
+
python -m crackerjack # Quality checks
|
|
24
|
+
python -m crackerjack -t # With tests
|
|
25
|
+
python -m crackerjack --ai-agent -t # AI auto-fixing (recommended)
|
|
45
26
|
|
|
46
|
-
#
|
|
47
|
-
python -m crackerjack --ai-debug -t
|
|
48
|
-
python -m crackerjack --
|
|
49
|
-
python -m crackerjack
|
|
27
|
+
# Development
|
|
28
|
+
python -m crackerjack --ai-debug -t # Debug AI issues
|
|
29
|
+
python -m crackerjack --skip-hooks # Skip hooks during iteration
|
|
30
|
+
python -m crackerjack -x # Code cleaning mode
|
|
50
31
|
|
|
51
32
|
# Server management
|
|
52
|
-
python -m crackerjack --start-mcp-server
|
|
53
|
-
python -m crackerjack --
|
|
54
|
-
python -m crackerjack --restart-mcp-server # Restart MCP server
|
|
55
|
-
|
|
56
|
-
# Release workflow
|
|
57
|
-
python -m crackerjack --bump patch # Version bump only
|
|
58
|
-
python -m crackerjack -a patch # Full release with publishing
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### Common Flags
|
|
62
|
-
|
|
63
|
-
| Flag | Purpose | When to Use |
|
|
64
|
-
|------|---------|-------------|
|
|
65
|
-
| `-t` | Include tests | Always for comprehensive validation |
|
|
66
|
-
| `--ai-agent` | Enable AI auto-fixing | Standard process for quality compliance |
|
|
67
|
-
| `--ai-debug` | Verbose AI debugging | When troubleshooting AI agent issues |
|
|
68
|
-
| `-x` | Code cleaning mode | When ready to resolve all TODOs |
|
|
69
|
-
| `-i` | Interactive mode | For step-by-step workflow control |
|
|
70
|
-
| `--skip-hooks` | Skip pre-commit hooks | During rapid development iterations |
|
|
71
|
-
| `--quick` | Quick mode (3 iterations) | CI/CD pipelines or rapid testing |
|
|
72
|
-
| `--thorough` | Thorough mode (8 iterations) | Complex refactoring or difficult issues |
|
|
73
|
-
| `--verbose` | Extra output | When diagnosing issues |
|
|
74
|
-
|
|
75
|
-
### Agent Selection Guide
|
|
76
|
-
|
|
77
|
-
**When to Use Which Specialist Agent:**
|
|
78
|
-
|
|
79
|
-
| Issue Type | Best Agent | Confidence | Use Case |
|
|
80
|
-
|------------|------------|------------|----------|
|
|
81
|
-
| **Documentation inconsistencies** | DocumentationAgent | 0.8 | Changelog updates, .md file consistency |
|
|
82
|
-
| **Cognitive complexity >15** | RefactoringAgent | 0.9 | Breaking down complex functions |
|
|
83
|
-
| **Unused imports/dead code** | RefactoringAgent | 0.8 | AST-based cleanup |
|
|
84
|
-
| **Performance bottlenecks** | PerformanceAgent | 0.85 | O(n²) loops, string concatenation |
|
|
85
|
-
| **Code duplication** | DRYAgent | 0.8 | Extract common patterns |
|
|
86
|
-
| **Import/formatting issues** | FormattingAgent | 0.8 | Code style violations |
|
|
87
|
-
| **Security vulnerabilities** | SecurityAgent | 0.8 | Hardcoded paths, unsafe operations |
|
|
88
|
-
| **Test failures** | TestCreationAgent | 0.8 | Missing fixtures, assertion issues |
|
|
89
|
-
| **Complex test scenarios** | TestSpecialistAgent | 0.8 | Advanced test frameworks |
|
|
90
|
-
|
|
91
|
-
**Decision Tree:**
|
|
92
|
-
|
|
93
|
-
1. **Type errors?** → Use AI agent auto-fixing (handles all types)
|
|
94
|
-
1. **Single issue type?** → Use specific agent with confidence ≥0.7
|
|
95
|
-
1. **Multiple issue types?** → Use AI agent batch fixing
|
|
96
|
-
1. **Documentation issues?** → Always use DocumentationAgent
|
|
97
|
-
1. **Performance issues?** → Always use PerformanceAgent (real code transformation)
|
|
98
|
-
|
|
99
|
-
## Core Development Commands
|
|
100
|
-
|
|
101
|
-
### Primary Workflows
|
|
102
|
-
|
|
103
|
-
```bash
|
|
104
|
-
# Quality checks only (most common during development)
|
|
105
|
-
python -m crackerjack
|
|
106
|
-
|
|
107
|
-
# With testing
|
|
108
|
-
python -m crackerjack -t
|
|
109
|
-
|
|
110
|
-
# Code cleaning with TODO detection (blocks if TODOs found)
|
|
111
|
-
# Note: Automatically creates backups in temp directory for safety
|
|
112
|
-
python -m crackerjack -x
|
|
113
|
-
|
|
114
|
-
# Full release workflow with version bump and publishing
|
|
115
|
-
python -m crackerjack -a patch
|
|
116
|
-
|
|
117
|
-
# Interactive mode with rich UI
|
|
118
|
-
python -m crackerjack -i
|
|
119
|
-
|
|
120
|
-
# Skip hooks during development iterations
|
|
121
|
-
python -m crackerjack --skip-hooks
|
|
122
|
-
|
|
123
|
-
# AI Agent mode with autonomous auto-fixing (STANDARD PROCESS)
|
|
124
|
-
python -m crackerjack --ai-agent -t
|
|
125
|
-
|
|
126
|
-
# AI Agent mode with full debugging and verbose output
|
|
127
|
-
python -m crackerjack --ai-debug -t
|
|
128
|
-
|
|
129
|
-
# Quick mode (3 iterations) - ideal for CI/CD
|
|
130
|
-
python -m crackerjack --quick --ai-agent -t
|
|
131
|
-
|
|
132
|
-
# Thorough mode (8 iterations) - for complex refactoring
|
|
133
|
-
python -m crackerjack --thorough --ai-agent -t
|
|
134
|
-
|
|
135
|
-
# Start MCP server for AI agent integration
|
|
136
|
-
python -m crackerjack --start-mcp-server
|
|
137
|
-
|
|
138
|
-
# Stop all running MCP servers
|
|
139
|
-
python -m crackerjack --stop-mcp-server
|
|
140
|
-
|
|
141
|
-
# Restart MCP server (stop and start again)
|
|
142
|
-
python -m crackerjack --restart-mcp-server
|
|
143
|
-
|
|
144
|
-
# Start dedicated WebSocket progress server (runs on localhost:8675)
|
|
145
|
-
python -m crackerjack --start-websocket-server
|
|
146
|
-
|
|
147
|
-
# Start multi-project progress monitor with Textual TUI
|
|
148
|
-
python -m crackerjack --monitor
|
|
33
|
+
python -m crackerjack --start-mcp-server # MCP server
|
|
34
|
+
python -m crackerjack --watchdog # Monitor/restart services
|
|
149
35
|
|
|
150
|
-
#
|
|
151
|
-
python -m crackerjack
|
|
152
|
-
|
|
153
|
-
# Start MCP server with custom WebSocket port
|
|
154
|
-
python -m crackerjack --start-mcp-server --websocket-port 8675
|
|
155
|
-
|
|
156
|
-
# Restart MCP server with custom WebSocket port
|
|
157
|
-
python -m crackerjack --restart-mcp-server --websocket-port 8675
|
|
158
|
-
|
|
159
|
-
# Start service watchdog to monitor and auto-restart MCP and WebSocket servers
|
|
160
|
-
python -m crackerjack --watchdog
|
|
36
|
+
# Release
|
|
37
|
+
python -m crackerjack -a patch # Full release workflow
|
|
161
38
|
```
|
|
162
39
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
**If your terminal gets stuck after quitting the monitor (no history, character input issues):**
|
|
166
|
-
|
|
167
|
-
```bash
|
|
168
|
-
# Option 1: Use the recovery script
|
|
169
|
-
./fix_terminal.sh
|
|
170
|
-
|
|
171
|
-
# Option 2: Manual recovery commands
|
|
172
|
-
stty sane; reset; exec $SHELL -l
|
|
173
|
-
|
|
174
|
-
# Option 3: Simple reset
|
|
175
|
-
reset
|
|
176
|
-
```
|
|
40
|
+
## AI Agent System
|
|
177
41
|
|
|
178
|
-
**
|
|
42
|
+
**9 Specialized Agents** handle domain-specific issues:
|
|
179
43
|
|
|
180
|
-
-
|
|
181
|
-
-
|
|
182
|
-
-
|
|
183
|
-
-
|
|
184
|
-
-
|
|
44
|
+
- **RefactoringAgent** (0.9): Complexity ≤15, dead code removal
|
|
45
|
+
- **PerformanceAgent** (0.85): O(n²) detection, optimization
|
|
46
|
+
- **SecurityAgent** (0.8): Hardcoded paths, unsafe operations
|
|
47
|
+
- **DocumentationAgent** (0.8): Changelog, .md consistency
|
|
48
|
+
- **TestCreationAgent** (0.8): Test failures, fixtures
|
|
49
|
+
- **DRYAgent** (0.8): Code duplication patterns
|
|
50
|
+
- **FormattingAgent** (0.8): Style violations, imports
|
|
51
|
+
- **ImportOptimizationAgent**: Import cleanup, reorganization
|
|
52
|
+
- **TestSpecialistAgent** (0.8): Advanced testing scenarios
|
|
185
53
|
|
|
186
|
-
|
|
54
|
+
**Usage**: `--ai-agent` enables batch fixing; confidence ≥0.7 uses specific agents
|
|
187
55
|
|
|
188
|
-
|
|
56
|
+
## Architecture
|
|
189
57
|
|
|
190
|
-
**
|
|
58
|
+
**Modular DI Architecture**: `__main__.py` → `WorkflowOrchestrator` → Coordinators → Managers → Services
|
|
191
59
|
|
|
192
|
-
**
|
|
60
|
+
**Critical Pattern**: Always import protocols from `models/protocols.py`, never concrete classes
|
|
193
61
|
|
|
194
|
-
|
|
62
|
+
```python
|
|
63
|
+
# ❌ Wrong
|
|
64
|
+
from ..managers.test_manager import TestManager
|
|
195
65
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
python -m crackerjack --ai-agent -t
|
|
199
|
-
|
|
200
|
-
# AI workflow per iteration:
|
|
201
|
-
# 1. Fast Hooks → Retry once if fail
|
|
202
|
-
# 2. Full Test Suite → Collect ALL failures
|
|
203
|
-
# 3. Comprehensive Hooks → Collect ALL issues
|
|
204
|
-
# 4. AI Batch Fixing → Fix ALL collected issues
|
|
205
|
-
# 5. Repeat until perfect (up to 5 iterations)
|
|
66
|
+
# ✅ Correct
|
|
67
|
+
from ..models.protocols import TestManagerProtocol
|
|
206
68
|
```
|
|
207
69
|
|
|
208
|
-
**
|
|
209
|
-
|
|
210
|
-
**Benefits**: Autonomous, intelligent, comprehensive, iterative, adaptive
|
|
211
|
-
|
|
212
|
-
#### Sub-Agent Architecture
|
|
213
|
-
|
|
214
|
-
**9 specialized agents handle domain-specific issues:**
|
|
215
|
-
|
|
216
|
-
- **DocumentationAgent** (0.8): Changelog generation, .md consistency, README updates
|
|
217
|
-
- **RefactoringAgent** (0.9): Complexity reduction ≤15, dead code removal, AST analysis
|
|
218
|
-
- **PerformanceAgent** (0.85): O(n²) detection, string optimization, real code transformation
|
|
219
|
-
- **DRYAgent** (0.8): Code duplication detection, pattern extraction, utility creation
|
|
220
|
-
- **FormattingAgent** (0.8): Style violations, import formatting, consistency
|
|
221
|
-
- **SecurityAgent** (0.8): Hardcoded paths, subprocess vulnerabilities, best practices
|
|
222
|
-
- **ImportOptimizationAgent**: Import cleanup, dead code removal, reorganization
|
|
223
|
-
- **TestCreationAgent** (0.8): Test failures, fixture management, dependencies
|
|
224
|
-
- **TestSpecialistAgent** (0.8): Advanced testing, framework integration
|
|
225
|
-
|
|
226
|
-
**Coordination**: AgentCoordinator routes by confidence (≥0.7 single-agent, \<0.7 collaborative), batch processing
|
|
70
|
+
**Core Layers**:
|
|
227
71
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
**
|
|
231
|
-
**
|
|
72
|
+
- **Orchestration**: `WorkflowOrchestrator`, DI containers, lifecycle management
|
|
73
|
+
- **Coordinators**: Session/phase coordination, async workflows, parallel execution
|
|
74
|
+
- **Managers**: Hook execution (fast→comprehensive), test management, publishing
|
|
75
|
+
- **Services**: Filesystem, git, config, security, health monitoring
|
|
232
76
|
|
|
233
|
-
|
|
77
|
+
## Testing & Development
|
|
234
78
|
|
|
235
79
|
```bash
|
|
236
|
-
#
|
|
237
|
-
python -m pytest tests/
|
|
80
|
+
# Specific test
|
|
81
|
+
python -m pytest tests/test_file.py::TestClass::test_method -v
|
|
238
82
|
|
|
239
|
-
#
|
|
83
|
+
# Coverage
|
|
240
84
|
python -m pytest --cov=crackerjack --cov-report=html
|
|
241
85
|
|
|
242
|
-
#
|
|
86
|
+
# Custom workers
|
|
243
87
|
python -m crackerjack -t --test-workers 4
|
|
244
88
|
|
|
245
|
-
#
|
|
246
|
-
python -m crackerjack --
|
|
247
|
-
|
|
248
|
-
# Progress monitoring for WebSocket MCP jobs
|
|
249
|
-
python -m crackerjack.mcp.progress_monitor <job_id> ws://localhost:8675
|
|
250
|
-
|
|
251
|
-
# Run with experimental hooks (pyrefly, ty)
|
|
252
|
-
python -m crackerjack --experimental-hooks
|
|
253
|
-
|
|
254
|
-
# Debug AI agent workflows with detailed logging
|
|
255
|
-
python -m crackerjack --ai-debug -t
|
|
256
|
-
|
|
257
|
-
# Enable verbose output for troubleshooting
|
|
258
|
-
python -m crackerjack --verbose -t
|
|
259
|
-
|
|
89
|
+
# Version bump
|
|
90
|
+
python -m crackerjack --bump patch
|
|
260
91
|
```
|
|
261
92
|
|
|
262
|
-
### Version Management
|
|
263
|
-
|
|
264
|
-
```bash
|
|
265
|
-
# Bump version without publishing
|
|
266
|
-
python -m crackerjack --bump patch # 0.30.3 -> 0.30.4
|
|
267
|
-
python -m crackerjack --bump minor # 0.30.3 -> 0.31.0
|
|
268
|
-
python -m crackerjack --bump major # 0.30.3 -> 1.0.0
|
|
269
|
-
|
|
270
|
-
# Bump version without git tags
|
|
271
|
-
python -m crackerjack --bump patch --no-git-tags
|
|
272
|
-
|
|
273
|
-
# Skip version consistency verification
|
|
274
|
-
python -m crackerjack --bump patch --skip-version-check
|
|
275
|
-
|
|
276
|
-
# Publish to PyPI (requires UV_PUBLISH_TOKEN or keyring)
|
|
277
|
-
python -m crackerjack -p patch
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
### UVX Integration
|
|
281
|
-
|
|
282
|
-
**Isolated execution**: `uvx crackerjack -t` (PyPI) or `uvx --from /path crackerjack -t` (local)
|
|
283
|
-
|
|
284
|
-
## Architecture Overview
|
|
285
|
-
|
|
286
|
-
**Modular architecture with dependency injection:**
|
|
287
|
-
|
|
288
|
-
### Core Layers
|
|
289
|
-
|
|
290
|
-
- **Orchestration**: `WorkflowOrchestrator`, DI containers with lifecycle management
|
|
291
|
-
- **Coordinators**: Session/phase coordination, async workflows with parallel execution
|
|
292
|
-
- **Managers**: Hook execution (fast→comprehensive), test management, publishing
|
|
293
|
-
- **Services**: Filesystem, git, config, security, health monitoring
|
|
294
|
-
|
|
295
|
-
### Key Patterns
|
|
296
|
-
|
|
297
|
-
**Dependency Flow**: `__main__.py` → `WorkflowOrchestrator` → Coordinators → Managers → Services
|
|
298
|
-
|
|
299
|
-
**Critical**: Always import protocols from `models/protocols.py`, never concrete classes
|
|
300
|
-
|
|
301
|
-
- ❌ `from ..managers.test_manager import TestManager`
|
|
302
|
-
- ✅ `from ..models.protocols import TestManagerProtocol`
|
|
303
|
-
|
|
304
|
-
### MCP Integration
|
|
305
|
-
|
|
306
|
-
**70% reduction**: 3,116 lines → modular architecture with tools, state management, rate limiting, monitoring
|
|
307
|
-
**WebSocket Server**: 35% reduction with FastAPI, job management, progress streaming
|
|
308
|
-
**Entry points**: `--start-mcp-server`, `--start-websocket-server`
|
|
309
|
-
|
|
310
93
|
## Quality Process
|
|
311
94
|
|
|
312
|
-
|
|
95
|
+
**Workflow Order**:
|
|
313
96
|
|
|
314
97
|
1. **Fast Hooks** (~5s): formatting, basic checks → retry once if fail
|
|
315
98
|
1. **Full Test Suite**: collect ALL failures, don't stop on first
|
|
316
99
|
1. **Comprehensive Hooks** (~30s): type checking, security, complexity → collect ALL issues
|
|
317
100
|
1. **AI Batch Fixing**: process all collected failures together
|
|
318
101
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
**Framework**: pytest with asyncio, 300s timeout, auto-detected workers
|
|
102
|
+
**Testing**: pytest with asyncio, 300s timeout, auto-detected workers
|
|
322
103
|
**Coverage**: Ratchet system targeting 100%, never decrease
|
|
323
104
|
|
|
324
105
|
## Code Standards
|
|
325
106
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
- **DRY/YAGNI/KISS**: Extract patterns, build only what's needed, choose simple solutions
|
|
329
|
-
- **Python 3.13+**: `|` unions, protocols, pathlib, `import typing as t`, Pydantic
|
|
330
|
-
|
|
331
|
-
### Quality Rules
|
|
107
|
+
**Quality Rules**:
|
|
332
108
|
|
|
333
109
|
- **Complexity ≤15** per function
|
|
334
110
|
- **No hardcoded paths** (use `tempfile`)
|
|
335
111
|
- **No shell=True** in subprocess
|
|
336
112
|
- **Type annotations required**
|
|
337
113
|
- **Protocol-based DI**
|
|
338
|
-
- **
|
|
114
|
+
- **Python 3.13+**: `|` unions, protocols, pathlib
|
|
339
115
|
|
|
340
|
-
|
|
116
|
+
**Refactoring Pattern**: Break complex methods into helpers
|
|
341
117
|
|
|
342
118
|
```python
|
|
343
|
-
# Break complex methods into helper methods
|
|
344
119
|
def complex_method(self, data: dict) -> bool:
|
|
345
120
|
if not self._validate_input(data):
|
|
346
121
|
return self._handle_invalid_input()
|
|
@@ -348,40 +123,7 @@ def complex_method(self, data: dict) -> bool:
|
|
|
348
123
|
return self._save_results(processed)
|
|
349
124
|
```
|
|
350
125
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
```python
|
|
354
|
-
# Use tempfile, not hardcoded paths
|
|
355
|
-
with tempfile.NamedTemporaryFile(suffix=".yaml") as f:
|
|
356
|
-
config_path = f.name
|
|
357
|
-
|
|
358
|
-
# Use contextlib.suppress, not try/except pass
|
|
359
|
-
from contextlib import suppress
|
|
360
|
-
|
|
361
|
-
with suppress(Exception):
|
|
362
|
-
risky_operation()
|
|
363
|
-
|
|
364
|
-
# Use tuples for membership tests
|
|
365
|
-
if status in ("error", "failed", "timeout"):
|
|
366
|
-
handle_error()
|
|
367
|
-
|
|
368
|
-
# Use comprehensions, not manual building
|
|
369
|
-
issues = [process(item) for item in data if condition(item)]
|
|
370
|
-
|
|
371
|
-
# Use dict.get with default
|
|
372
|
-
return AGENT_EMOJIS.get(agent_type, "🤖")
|
|
373
|
-
|
|
374
|
-
# Use operator functions, not lambdas
|
|
375
|
-
from operator import itemgetter
|
|
376
|
-
|
|
377
|
-
sorted_items = sorted(items, key=itemgetter("priority"))
|
|
378
|
-
```
|
|
379
|
-
|
|
380
|
-
### Regex Best Practices (CRITICAL)
|
|
381
|
-
|
|
382
|
-
**⚠️ WARNING: Bad regex caused security vulnerabilities. Always use centralized patterns.**
|
|
383
|
-
|
|
384
|
-
**NEVER write raw regex. Use centralized registry:**
|
|
126
|
+
**Critical Regex Safety**: NEVER write raw regex. Use centralized registry:
|
|
385
127
|
|
|
386
128
|
```python
|
|
387
129
|
# ❌ DANGEROUS
|
|
@@ -393,178 +135,55 @@ from crackerjack.services.regex_patterns import SAFE_PATTERNS
|
|
|
393
135
|
text = SAFE_PATTERNS["fix_hyphenated_names"].apply(text)
|
|
394
136
|
```
|
|
395
137
|
|
|
396
|
-
**Available patterns**: command spacing, token masking, hyphenation, security fixes (18+ validated patterns)
|
|
397
|
-
|
|
398
|
-
**FORBIDDEN patterns that cause vulnerabilities:**
|
|
399
|
-
|
|
400
|
-
- `r"\g < 1 >"` (spaces in replacement - SECURITY ISSUE)
|
|
401
|
-
- `r"\g< 1>"` or `r"\g<1 >"` (spacing bugs)
|
|
402
|
-
- `r".*"` (overly broad)
|
|
403
|
-
- Raw token masking
|
|
404
|
-
|
|
405
|
-
**Security token masking**: Use word boundaries, comprehensive tests, consistent application
|
|
406
|
-
**Emergency fix**: Find with `rg "pattern"`, replace with `SAFE_PATTERNS["pattern_name"].apply(text)`
|
|
407
|
-
|
|
408
138
|
## Common Issues & Solutions
|
|
409
139
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
- **Unresponsive terminal**: `./fix_terminal.sh` or `stty sane; reset; exec $SHELL -l`
|
|
413
|
-
- **No progress updates**: Start WebSocket server, verify at http://localhost:8675/
|
|
414
|
-
|
|
415
|
-
### Development Issues
|
|
140
|
+
**Development**:
|
|
416
141
|
|
|
417
142
|
- **AI agent ineffective**: Use `--ai-debug -t` for analysis
|
|
418
143
|
- **Import errors**: Always import protocols from `models/protocols.py`
|
|
419
144
|
- **Test hangs**: Avoid complex async tests, use simple synchronous config tests
|
|
420
|
-
|
|
421
|
-
### Quality Issues
|
|
422
|
-
|
|
423
145
|
- **Coverage failing**: Never reduce below baseline, add tests incrementally
|
|
424
146
|
- **Complexity >15**: Break into helper methods using RefactoringAgent approach
|
|
425
|
-
- **Security violations**: Use `SAFE_PATTERNS` for token masking
|
|
426
|
-
- **Regex issues**: Never use raw regex, use centralized patterns
|
|
427
147
|
|
|
428
|
-
|
|
148
|
+
**Server**:
|
|
429
149
|
|
|
430
150
|
- **MCP not starting**: `--restart-mcp-server` or `--watchdog`
|
|
431
|
-
- **
|
|
432
|
-
|
|
433
|
-
### Performance Issues
|
|
434
|
-
|
|
435
|
-
- **Slow tests**: Customize `--test-workers N` or `--benchmark`
|
|
436
|
-
- **Memory issues**: PerformanceAgent detects O(n²) patterns
|
|
437
|
-
- **Slow hooks**: Use `--skip-hooks` during rapid iteration
|
|
438
|
-
|
|
439
|
-
## Development Workflow
|
|
440
|
-
|
|
441
|
-
### Standard Process
|
|
442
|
-
|
|
443
|
-
1. Run quality checks: `python -m crackerjack`
|
|
444
|
-
1. Run with tests: `python -m crackerjack -t`
|
|
445
|
-
1. Address remaining issues manually
|
|
446
|
-
1. Optional AI review: `mcp__gemini-cli__ask-gemini`
|
|
447
|
-
1. Commit: `python -m crackerjack -c`
|
|
448
|
-
|
|
449
|
-
### Testing Components
|
|
450
|
-
|
|
451
|
-
- **Specific**: `python -m pytest tests/test_managers.py -v`
|
|
452
|
-
- **Isolated**: `python -m pytest tests/test_file.py::TestClass::test_method -v -s`
|
|
453
|
-
|
|
454
|
-
### Common Issues
|
|
455
|
-
|
|
456
|
-
- **Import errors**: Check `models/protocols.py` for interfaces
|
|
457
|
-
- **Type errors**: Use `t.cast()`, ensure annotations
|
|
458
|
-
- **Complexity**: Break into helper methods
|
|
151
|
+
- **Terminal stuck**: `stty sane; reset; exec $SHELL -l`
|
|
152
|
+
- **Slow tests**: Customize `--test-workers N` or use `--skip-hooks`
|
|
459
153
|
|
|
460
154
|
## MCP Server Integration
|
|
461
155
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
- **Dual Protocol**: MCP tools + WebSocket server on localhost:8675
|
|
465
|
-
- **Real-time Progress**: Live updates with Rich formatting
|
|
466
|
-
- **Job Tracking**: Comprehensive progress monitoring
|
|
467
|
-
|
|
468
|
-
### Usage
|
|
156
|
+
**Features**: Dual protocol (MCP + WebSocket), real-time progress, job tracking
|
|
469
157
|
|
|
470
158
|
```bash
|
|
471
|
-
# Start
|
|
472
|
-
python -m crackerjack --start-
|
|
473
|
-
|
|
474
|
-
# Use /crackerjack:run in Claude
|
|
475
|
-
# Progress at: http://localhost:8675/
|
|
159
|
+
# Start server
|
|
160
|
+
python -m crackerjack --start-mcp-server
|
|
476
161
|
|
|
477
|
-
# Monitor
|
|
162
|
+
# Monitor progress at http://localhost:8675/
|
|
478
163
|
python -m crackerjack.mcp.progress_monitor <job_id>
|
|
479
164
|
```
|
|
480
165
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
- `execute_crackerjack`: Start auto-fixing workflow
|
|
484
|
-
- `get_job_progress`: Get current job progress
|
|
485
|
-
- `get_comprehensive_status`: Complete system status
|
|
486
|
-
- `analyze_errors`: Error pattern analysis
|
|
487
|
-
- `session_management`: Track iterations
|
|
488
|
-
|
|
489
|
-
### Slash Commands
|
|
490
|
-
|
|
491
|
-
- **`/crackerjack:run`**: Full auto-fixing with progress tracking
|
|
492
|
-
- **`/crackerjack:status`**: System status and health
|
|
493
|
-
- **`/crackerjack:init`**: Initialize project configuration
|
|
494
|
-
|
|
495
|
-
## Configuration
|
|
496
|
-
|
|
497
|
-
- **Coverage**: Ratchet system targeting 100%
|
|
498
|
-
- **Complexity**: ≤15 per function
|
|
499
|
-
- **Python**: 3.13+ required
|
|
500
|
-
- **Test timeout**: 300s
|
|
501
|
-
- **Type checking**: Strict Pyright
|
|
502
|
-
- **Security**: Bandit scanning
|
|
503
|
-
|
|
504
|
-
## Service Watchdog
|
|
505
|
-
|
|
506
|
-
**Auto-restart system for servers**
|
|
507
|
-
|
|
508
|
-
### Usage
|
|
509
|
-
|
|
510
|
-
```bash
|
|
511
|
-
python -m crackerjack --watchdog
|
|
512
|
-
```
|
|
513
|
-
|
|
514
|
-
### Features
|
|
515
|
-
|
|
516
|
-
- **Real-time monitoring**: Process/health checks
|
|
517
|
-
- **Auto-restart**: Rate-limited with backoff (max 10/5min)
|
|
518
|
-
- **Dashboard**: Live status display
|
|
519
|
-
- **Health checks**: HTTP monitoring for WebSocket server
|
|
520
|
-
- **Graceful shutdown**: Ctrl+C cleanup
|
|
521
|
-
|
|
522
|
-
**Monitors**: MCP server (process), WebSocket server (process + HTTP health)
|
|
523
|
-
|
|
524
|
-
## Recent Achievements (January 2025)
|
|
525
|
-
|
|
526
|
-
**Refactoring Results:**
|
|
527
|
-
|
|
528
|
-
- **70% line reduction**: MCP server (3,116 → 921 lines)
|
|
529
|
-
- **35% line reduction**: WebSocket server (1,479 → 944 lines)
|
|
530
|
-
- **80% line reduction**: CLI entry point (601 → 122 lines)
|
|
531
|
-
|
|
532
|
-
**Quality Improvements:**
|
|
533
|
-
|
|
534
|
-
- Fixed all 31+ refurb violations
|
|
535
|
-
- Major complexity reductions: 34→3 (91%), 33→2 (94%)
|
|
536
|
-
- All 5 fast hooks passing consistently
|
|
537
|
-
- Protocol-based interfaces throughout
|
|
538
|
-
|
|
539
|
-
## Test Coverage Status
|
|
540
|
-
|
|
541
|
-
**Current**: 10.11% baseline targeting 100%
|
|
542
|
-
**Strategy**: Import-only tests, protocol compliance, async validation, integration testing
|
|
543
|
-
**Priority**: Fix existing failures first, then add tests incrementally
|
|
166
|
+
**Available Tools**: `execute_crackerjack`, `get_job_progress`, `get_comprehensive_status`, `analyze_errors`
|
|
544
167
|
|
|
545
|
-
**
|
|
168
|
+
**Slash Commands**: `/crackerjack:run`, `/crackerjack:status`, `/crackerjack:init`
|
|
546
169
|
|
|
547
170
|
## Critical Reminders
|
|
548
171
|
|
|
549
|
-
|
|
172
|
+
**Core Instructions**:
|
|
550
173
|
|
|
551
174
|
- Do only what's asked, nothing more
|
|
552
175
|
- NEVER create files unless absolutely necessary
|
|
553
176
|
- ALWAYS prefer editing existing files
|
|
554
|
-
- NEVER proactively create documentation
|
|
555
177
|
- MAINTAIN coverage ratchet
|
|
556
178
|
|
|
557
|
-
|
|
179
|
+
**Quality Standards**:
|
|
558
180
|
|
|
559
181
|
- **Test Quality**: Avoid async tests that hang, use synchronous config tests
|
|
560
|
-
- **Honest Reporting**: Report actual percentages (10.17%, not "approaching 15%")
|
|
561
182
|
- **Import Compliance**: Use protocols from `models/protocols.py`
|
|
562
183
|
- **Fix failures FIRST** before creating new tests
|
|
563
184
|
- Use IDE diagnostics after implementation
|
|
564
|
-
- Be critical/comprehensive in reviews
|
|
565
|
-
- Use crackerjack-architect agent for compliant code
|
|
566
185
|
|
|
567
|
-
|
|
186
|
+
**Failure Patterns to Avoid**:
|
|
568
187
|
|
|
569
188
|
```python
|
|
570
189
|
# ❌ Async tests that hang
|
|
@@ -585,4 +204,4 @@ from ..managers.test_manager import TestManager
|
|
|
585
204
|
from ..models.protocols import TestManagerProtocol
|
|
586
205
|
```
|
|
587
206
|
|
|
588
|
-
|
|
207
|
+
**Current Status**: 10.11% coverage baseline targeting 100% (ratchet system: 2% tolerance, never reduce)
|
crackerjack/__main__.py
CHANGED