pmat 3.11.0

PMAT - Zero-config AI context generation and code quality toolkit (CLI, MCP, HTTP)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# Revolutionary Features: Unified Quality System & AGENTS.md Integration

## Table of Contents
- [Unified Quality Enforcement System]#unified-quality-enforcement-system
- [AGENTS.md Integration]#agentsmd-integration
- [Quick Start]#quick-start
- [Architecture]#architecture
- [Implementation Details]#implementation-details

## Unified Quality Enforcement System

### Overview
The **Unified Quality Enforcement System** (v2.82.0) represents a revolutionary dual-track quality system that delivers immediate production value while providing a path to theoretical maximum automation. This system fundamentally transforms how teams approach code quality by combining real-time monitoring, ML-driven intelligence, and SRE-style error budgets.

### Key Components

#### 1. Real-time Quality Monitoring
- **Latency**: 5-10ms response time
- **Architecture**: Lock-free concurrent design using DashMap and crossbeam
- **File Watching**: FSEvents (macOS) / inotify (Linux) with intelligent debouncing
- **AST Parsing**: Incremental parsing with syn crate for instant feedback
- **Persistent Storage**: Metrics cached and stored for historical analysis

```rust
// Example: Real-time monitoring
let monitor = QualityMonitor::new()
    .with_debounce(Duration::from_millis(100))
    .with_incremental_parsing(true);

monitor.watch_path("src/").await?;
```

#### 2. ML-driven Intelligence
- **Context-aware Suggestions**: Refactoring recommendations with confidence scoring
- **Pattern Recognition**: Learns from codebase patterns over time
- **Adaptive Improvement**: Gets smarter with each interaction
- **Integration**: Seamlessly works with existing refactor engine

```rust
// Example: Getting intelligent suggestions
let intelligence = QualityIntelligence::new();
let suggestions = intelligence.analyze_file("src/complex.rs").await?;

for suggestion in suggestions {
    println!("Confidence: {}% - {}", suggestion.confidence, suggestion.description);
}
```

#### 3. SRE-style Error Budgets
- **Team-specific Budgets**: Each team gets quality budgets that regenerate over time
- **Progressive Modes**: 
  - **Observe**: Monitor without enforcement
  - **Advise**: Provide suggestions
  - **Guide**: Gentle nudges toward quality
  - **Enforce**: Block low-quality code
  - **Extreme**: Zero-tolerance mode
- **Grace Periods**: Configurable escalation policies
- **Budget Sharing**: Teams can share budgets for collaborative work

```rust
// Example: Error budget configuration
let enforcer = ErrorBudgetEnforcer::new()
    .with_team("backend", TeamBudget {
        complexity_budget: 100,
        satd_budget: 10,
        coverage_budget: 80.0,
        regeneration_rate: 10, // per day
    })
    .with_mode(QualityMode::Enforce);
```

#### 4. Conservative Automation
- **Safety Threshold**: 95%+ confidence required for automatic changes
- **Git Safety Net**: Automatic rollback on failures
- **Daily Limits**: Bounded number of automatic changes
- **Human Approval**: Complex changes require review

```rust
// Example: Conservative automation
let automator = ConservativeAutomator::new()
    .with_safety_threshold(0.95)
    .with_daily_limit(10)
    .with_git_rollback(true);

let result = automator.auto_fix("src/module.rs").await?;
```

#### 5. Comprehensive Observability
- **Web Dashboard**: Real-time metrics on port 8080
- **Prometheus Export**: Full metrics integration
- **Grafana Dashboards**: Beautiful visualizations
- **GitHub Actions**: Quality gate workflows

```bash
# Start the web dashboard
pmat unified-quality dashboard --port 8080

# Export Prometheus metrics
pmat unified-quality metrics --prometheus
```

#### 6. Progressive Team Onboarding
- **Phased Rollout**:
  1. **Introduction**: Learn the system
  2. **Monitoring**: Observe metrics
  3. **Metrics**: Understand measurements
  4. **Enforcement**: Apply quality gates
  5. **Automation**: Enable auto-fixes
  6. **Advanced**: Full automation
- **Gamification**: Achievements and progress tracking
- **Interactive Tutorials**: Learn by doing

### Production Impact

- **Immediate Value**: Teams see quality improvements within hours
- **Gradual Adoption**: No disruptive changes required
- **Measurable Results**: 60% reduction in complexity violations in Sprint 86
- **Developer Happiness**: Reduced cognitive load and faster reviews

## AGENTS.md Integration

### Overview
The **AGENTS.md Integration** (v2.83.0) bridges the simple, markdown-based AGENTS.md standard with PMAT's comprehensive quality enforcement and MCP capabilities. This groundbreaking integration enables AI agents to seamlessly understand and work with codebases while maintaining extreme quality standards.

### What is AGENTS.md?
AGENTS.md is a standardized markdown format for providing AI agents with project context, commands, and guidelines. It's like a README specifically designed for AI consumption.

### Key Features

#### 1. AGENTS.md Parser
- **Full Markdown Support**: Parses all standard markdown elements
- **Command Extraction**: Automatically extracts executable commands from code blocks
- **Quality Rules**: Integrates quality requirements with PMAT gates
- **Validation**: Ensures AGENTS.md files follow the standard

```rust
// Example: Parsing AGENTS.md
let parser = AgentsMdParser::new();
let document = parser.parse(agents_md_content)?;

for command in document.commands {
    println!("Found command: {} - {}", command.name, command.command);
}
```

#### 2. Discovery System
- **Auto-detection**: Finds AGENTS.md files automatically
- **Hierarchy Support**: Works with monorepos
- **Real-time Updates**: Watches for changes
- **Caching**: DashMap-based caching for performance

```rust
// Example: Discovering AGENTS.md files
let discovery = AgentsMdDiscovery::new();
let agents_file = discovery.find_nearest(&current_path)?;

// Watch for updates
discovery.watch(agents_file, |event| {
    println!("AGENTS.md updated: {:?}", event);
})?;
```

#### 3. Command Executor
- **Sandboxed Execution**: Safe environment with resource limits
- **Safety Validation**: Whitelisted commands only
- **Risk Assessment**: Analyzes FileSystem, Network, System, Resource risks
- **Quality Gates**: Applies PMAT quality standards to output

```rust
// Example: Safe command execution
let executor = AgentsMdExecutor::new()
    .with_sandbox(true)
    .with_timeout(Duration::from_secs(60));

let output = executor.execute_command(&command).await?;
let quality_report = executor.apply_quality_gates(&output)?;
```

#### 4. AGENTS.md Generator
- **From Analysis**: Generate AGENTS.md from PMAT analysis
- **Language Templates**: Rust, JavaScript, Python, Go, Java
- **Update Existing**: Intelligently update existing files
- **Quality Metrics**: Include TDG scores and complexity metrics

```rust
// Example: Generating AGENTS.md
let generator = AgentsMdGenerator::new();
let analysis = pmat.analyze_project(".")?;
let agents_md = generator.generate_from_analysis(&analysis)?;

fs::write("AGENTS.md", agents_md)?;
```

#### 5. MCP-AGENTS.md Bridge
- **Bidirectional Translation**: Convert between AGENTS.md and MCP
- **Protocol Routing**: Route requests to appropriate handlers
- **Quality Enforcement**: Apply quality gates at protocol boundaries
- **Tool Mapping**: Map AGENTS.md commands to MCP tools

```rust
// Example: Bridging protocols
let bridge = McpAgentsMdBridge::new();

// Convert AGENTS.md to MCP tools
let mcp_tools = bridge.agents_to_mcp(&document);

// Convert MCP capabilities to AGENTS.md
let agents_md = bridge.mcp_to_agents(&mcp_tools);
```

### Example AGENTS.md File

```markdown
# AGENTS.md

## Project Overview
PMAT - Professional Project Analysis Toolkit
A zero-configuration AI context generation system with extreme quality enforcement.

## Development Setup
```bash
# Install dependencies
cargo build --all

# Run tests
make test

# Check quality
pmat quality-gate --all
```

## Testing Instructions
- Run `make test` before committing
- Ensure 80%+ coverage maintained
- All functions must have complexity ≀10

## Code Style
- Use `rustfmt` for formatting
- Follow PMAT quality standards
- Zero SATD tolerance

## PR Guidelines
- Squash commits with conventional format
- Must pass all quality gates
- Include property tests for new features

## Security Considerations
- No secrets in code
- Validate all external input
- Use sandboxed execution for commands
```

## Quick Start

### Using the Unified Quality System

```bash
# Start real-time monitoring
pmat unified-quality monitor --path src/

# Check team budgets
pmat unified-quality budgets --team backend

# Enable automation
pmat unified-quality auto --enable --threshold 0.95

# View dashboard
pmat unified-quality dashboard --open
```

### Using AGENTS.md Integration

```bash
# Parse existing AGENTS.md
pmat agents parse AGENTS.md

# Generate AGENTS.md from project
pmat agents generate --output AGENTS.md

# Execute commands from AGENTS.md
pmat agents exec --file AGENTS.md --command "Run tests"

# Bridge to MCP
pmat agents bridge --mcp-server localhost:3000
```

## Architecture

### Unified Quality System Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           Unified Quality System            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚Real-time β”‚  β”‚    ML    β”‚  β”‚   SRE    β”‚ β”‚
β”‚  β”‚ Monitor  β”‚  β”‚  Intel   β”‚  β”‚  Budgets β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β”‚
β”‚        β”‚             β”‚             β”‚        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β” β”‚
β”‚  β”‚       Quality Enforcement Core        β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                     β”‚                       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚   Auto   β”‚  β”‚Dashboard β”‚  β”‚  GitHub  β”‚ β”‚
β”‚  β”‚  Fixer   β”‚  β”‚   Web    β”‚  β”‚  Actions β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### AGENTS.md Integration Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         AGENTS.md Integration               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  Parser  β”‚  β”‚Discovery β”‚  β”‚ Executor β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β”‚
β”‚        β”‚             β”‚             β”‚        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β” β”‚
β”‚  β”‚         AGENTS.md Core                β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                  β”‚                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
β”‚  β”‚     MCP-AGENTS.md Bridge     β”‚          β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚
β”‚                  β”‚                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚  β”‚Generator │◄───┴───►│ Quality  β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚                                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

## Implementation Details

### Technology Stack

#### Unified Quality System
- **Rust**: Core implementation language
- **FSEvents/inotify**: File system monitoring
- **syn**: AST parsing
- **DashMap**: Lock-free concurrent hashmap
- **crossbeam**: Concurrent data structures
- **Prometheus**: Metrics export
- **Axum**: Web dashboard server

#### AGENTS.md Integration
- **pulldown-cmark**: Markdown parsing
- **shell-words**: Command parsing
- **notify**: File watching
- **DashMap**: Caching layer
- **tokio**: Async runtime
- **serde**: Serialization

### Performance Characteristics

#### Unified Quality System
- **Monitoring Latency**: 5-10ms
- **AST Parsing**: <50ms for average file
- **Dashboard Update**: Real-time (WebSocket)
- **Automation Decision**: <100ms
- **Memory Usage**: ~50MB baseline

#### AGENTS.md Integration
- **Parse Time**: <10ms for typical AGENTS.md
- **Discovery**: <100ms for large monorepos
- **Command Validation**: <1s
- **Bridge Translation**: <10ms
- **Cache Hit Rate**: >90%

### Quality Standards

Both systems maintain PMAT's extreme quality standards:
- **Cyclomatic Complexity**: ≀10 for all functions
- **Test Coverage**: >80% with property tests
- **SATD**: Zero tolerance
- **Documentation**: 100% public API coverage
- **Performance**: Sub-second for all operations

## Integration with Existing Tools

### CI/CD Integration

```yaml
# GitHub Actions example
name: Quality Gates
on: [push, pull_request]

jobs:
  quality:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Run Unified Quality System
        run: |
          pmat unified-quality check --mode enforce
          pmat unified-quality budgets --verify
      
      - name: Check AGENTS.md
        run: |
          pmat agents validate AGENTS.md
          pmat agents exec --file AGENTS.md --command "Run tests"
```

### VSCode Extension

Both systems integrate with the PMAT VSCode extension:
- Real-time quality feedback
- AGENTS.md syntax highlighting
- Command palette integration
- Inline suggestions

### MCP Server

```bash
# Start MCP server with both systems
pmat mcp serve --unified-quality --agents-md

# Available tools:
# - unified_quality_monitor
# - unified_quality_budgets
# - agents_parse
# - agents_execute
# - agents_generate
```

## Best Practices

### Unified Quality System
1. **Start in Observe Mode**: Don't enforce immediately
2. **Set Realistic Budgets**: Based on current metrics
3. **Gradual Automation**: Enable auto-fix incrementally
4. **Monitor Dashboard**: Keep an eye on trends
5. **Celebrate Wins**: Use gamification features

### AGENTS.md Integration
1. **Keep It Simple**: Start with basic AGENTS.md
2. **Version Control**: Track AGENTS.md changes
3. **Security First**: Always validate commands
4. **Quality Gates**: Never bypass quality checks
5. **Progressive Enhancement**: Add features gradually

## Troubleshooting

### Common Issues

#### Unified Quality System
- **High CPU Usage**: Adjust debounce timing
- **Budget Depletion**: Review regeneration rates
- **False Positives**: Tune ML confidence thresholds
- **Dashboard Not Loading**: Check port 8080 availability

#### AGENTS.md Integration
- **Parse Errors**: Validate markdown syntax
- **Command Timeout**: Increase execution timeout
- **Discovery Fails**: Check file permissions
- **Bridge Errors**: Verify MCP server connection

## Future Roadmap

### Unified Quality System
- Cloud synchronization for distributed teams
- Advanced ML models for better suggestions
- Integration with more IDEs
- Custom quality metrics
- Team analytics dashboard

### AGENTS.md Integration
- Support for more agent platforms
- Advanced command orchestration
- Distributed execution
- AI-powered AGENTS.md generation
- Cross-repository AGENTS.md sharing

## Conclusion

These two revolutionary features represent the future of code quality management and AI-assisted development. The Unified Quality System provides unprecedented real-time quality enforcement with intelligent automation, while the AGENTS.md Integration bridges the gap between human-readable documentation and AI agent capabilities.

Together, they form a powerful combination that:
- **Reduces Technical Debt**: By preventing it at the source
- **Improves Developer Productivity**: Through intelligent automation
- **Enables AI Collaboration**: With standardized agent interfaces
- **Maintains Quality Standards**: Without sacrificing velocity

For more information, see:
- [Unified Quality Specification]specifications/pmat-spec.md
- [AGENTS.md Specification]specifications/components/agent-integration.md
- [Main README]../README.md