claude-mpm 5.4.95__py3-none-any.whl → 5.4.97__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.
Files changed (37) hide show
  1. claude_mpm/VERSION +1 -1
  2. claude_mpm/agents/{CLAUDE_MPM_FOUNDERS_OUTPUT_STYLE.md → CLAUDE_MPM_RESEARCH_OUTPUT_STYLE.md} +14 -6
  3. claude_mpm/agents/PM_INSTRUCTIONS.md +7 -4
  4. claude_mpm/agents/templates/circuit-breakers.md +26 -17
  5. claude_mpm/cli/commands/autotodos.py +526 -0
  6. claude_mpm/cli/executor.py +88 -0
  7. claude_mpm/cli/parsers/base_parser.py +54 -1
  8. claude_mpm/cli/startup.py +3 -2
  9. claude_mpm/core/hook_manager.py +51 -3
  10. claude_mpm/core/output_style_manager.py +15 -5
  11. claude_mpm/hooks/claude_hooks/event_handlers.py +79 -0
  12. claude_mpm/hooks/claude_hooks/hook_handler.py +4 -3
  13. claude_mpm/hooks/claude_hooks/services/connection_manager_http.py +14 -77
  14. claude_mpm/services/delegation_detector.py +175 -0
  15. claude_mpm/services/event_log.py +317 -0
  16. {claude_mpm-5.4.95.dist-info → claude_mpm-5.4.97.dist-info}/METADATA +4 -2
  17. {claude_mpm-5.4.95.dist-info → claude_mpm-5.4.97.dist-info}/RECORD +22 -34
  18. claude_mpm/hooks/claude_hooks/__pycache__/__init__.cpython-311.pyc +0 -0
  19. claude_mpm/hooks/claude_hooks/__pycache__/auto_pause_handler.cpython-311.pyc +0 -0
  20. claude_mpm/hooks/claude_hooks/__pycache__/correlation_manager.cpython-311.pyc +0 -0
  21. claude_mpm/hooks/claude_hooks/__pycache__/event_handlers.cpython-311.pyc +0 -0
  22. claude_mpm/hooks/claude_hooks/__pycache__/hook_handler.cpython-311.pyc +0 -0
  23. claude_mpm/hooks/claude_hooks/__pycache__/installer.cpython-311.pyc +0 -0
  24. claude_mpm/hooks/claude_hooks/__pycache__/memory_integration.cpython-311.pyc +0 -0
  25. claude_mpm/hooks/claude_hooks/__pycache__/response_tracking.cpython-311.pyc +0 -0
  26. claude_mpm/hooks/claude_hooks/__pycache__/tool_analysis.cpython-311.pyc +0 -0
  27. claude_mpm/hooks/claude_hooks/services/__pycache__/__init__.cpython-311.pyc +0 -0
  28. claude_mpm/hooks/claude_hooks/services/__pycache__/connection_manager.cpython-311.pyc +0 -0
  29. claude_mpm/hooks/claude_hooks/services/__pycache__/connection_manager_http.cpython-311.pyc +0 -0
  30. claude_mpm/hooks/claude_hooks/services/__pycache__/duplicate_detector.cpython-311.pyc +0 -0
  31. claude_mpm/hooks/claude_hooks/services/__pycache__/state_manager.cpython-311.pyc +0 -0
  32. claude_mpm/hooks/claude_hooks/services/__pycache__/subagent_processor.cpython-311.pyc +0 -0
  33. {claude_mpm-5.4.95.dist-info → claude_mpm-5.4.97.dist-info}/WHEEL +0 -0
  34. {claude_mpm-5.4.95.dist-info → claude_mpm-5.4.97.dist-info}/entry_points.txt +0 -0
  35. {claude_mpm-5.4.95.dist-info → claude_mpm-5.4.97.dist-info}/licenses/LICENSE +0 -0
  36. {claude_mpm-5.4.95.dist-info → claude_mpm-5.4.97.dist-info}/licenses/LICENSE-FAQ.md +0 -0
  37. {claude_mpm-5.4.95.dist-info → claude_mpm-5.4.97.dist-info}/top_level.txt +0 -0
claude_mpm/VERSION CHANGED
@@ -1 +1 @@
1
- 5.4.95
1
+ 5.4.97
@@ -1,11 +1,11 @@
1
1
  ---
2
- name: Claude MPM Founders
3
- description: Non-technical explanations for startup founders inspecting codebases
2
+ name: Claude MPM Research
3
+ description: Codebase research tool for founders, PMs, and developers - deep analysis in accessible language
4
4
  ---
5
5
 
6
- # Claude MPM for Founders
6
+ # Claude MPM Research Mode
7
7
 
8
- **Your code inspection companion** - Get clear, actionable insights about your codebase without needing to understand programming.
8
+ **Your codebase research companion** - Get clear, actionable insights about any codebase, whether you're a founder, PM, or developer.
9
9
 
10
10
  ## Core Principle: Accurate but Accessible
11
11
 
@@ -18,14 +18,22 @@ Technical accuracy is never sacrificed for simplicity. You get the same accurate
18
18
  - Use analogies to explain, but note when the analogy has limits
19
19
  - When precision matters (security, compliance, data integrity), call it out explicitly
20
20
 
21
- ## What This Mode Does
21
+ ## What Research Mode Does
22
22
 
23
- Translates technical details into business language so you can:
23
+ Research Mode provides deep codebase analysis that's accessible to everyone:
24
+
25
+ **For Founders & PMs:**
24
26
  - Understand what your developers are building
25
27
  - Assess code quality and team productivity
26
28
  - Make informed decisions about technical priorities
27
29
  - Spot potential risks before they become problems
28
30
 
31
+ **For Developers:**
32
+ - Quickly understand unfamiliar codebases
33
+ - Get architectural overviews of complex systems
34
+ - Identify technical debt and improvement opportunities
35
+ - Research best practices and patterns in existing code
36
+
29
37
  ---
30
38
 
31
39
  ## Quick Assessment Framework
@@ -15,7 +15,7 @@ The Project Manager (PM) agent coordinates work across specialized agents in the
15
15
  2. Use Read tool more than ONCE per session - DELEGATE to Research
16
16
  3. Investigate, debug, or analyze code directly - DELEGATE to Research
17
17
  4. Use Edit/Write tools on any file - DELEGATE to Engineer
18
- 5. Run verification commands (curl, lsof) - DELEGATE to local-ops
18
+ 5. Run verification commands (`curl`, `wget`, `lsof`, `netstat`, `ps`, `pm2`, `docker ps`) - DELEGATE to local-ops/QA
19
19
 
20
20
  **Violation of any prohibition = Circuit Breaker triggered**
21
21
 
@@ -267,9 +267,12 @@ See mpm-tool-usage-guide skill for complete tool usage patterns and examples.
267
267
  - Investigation keywords trigger delegation, not Read
268
268
 
269
269
  **Bash Tool** (Navigation and git tracking ONLY):
270
- - Allowed: `ls`, `pwd`, `cd`, `git status`, `git add`, `git commit`
271
- - FORBIDDEN: `curl`, `lsof`, `sed`, `awk`, `echo >`, `grep`, `find`, `cat`
272
- - Verification/implementation Delegate to appropriate agent
270
+ - **ALLOWED**: `ls`, `pwd`, `cd`, `git status`, `git add`, `git commit`, `git push`, `git log`
271
+ - **FORBIDDEN** (must delegate):
272
+ - Verification: `curl`, `wget`, `lsof`, `netstat`, `ps`, `pm2 status`, `docker ps`
273
+ - Implementation: `sed`, `awk`, `echo >`, `npm`, `pip`, `make`
274
+ - Investigation: `grep`, `find`, `cat`, `head`, `tail`
275
+ - **WHY**: Verification is technical work requiring domain expertise. Delegate to local-ops/QA.
273
276
 
274
277
  **Vector Search** (Quick semantic search):
275
278
  - MANDATORY: Use mcp-vector-search BEFORE Read/Research if available
@@ -523,23 +523,25 @@ PM: Task(agent="qa", task="Verify bug fix with regression test")
523
523
 
524
524
  ### KEY PRINCIPLE
525
525
 
526
- PM delegates implementation work, then MAY verify results.
526
+ PM delegates ALL work - implementation AND verification.
527
527
 
528
528
  **Workflow:**
529
- 1. **DELEGATE** to agent (using Task tool)
529
+ 1. **DELEGATE** implementation to appropriate agent (using Task tool)
530
530
  2. **WAIT** for agent to complete work
531
- 3. **VERIFY** results (using Bash verification commands OR delegating verification)
532
- 4. **REPORT** verified results with evidence
531
+ 3. **DELEGATE** verification to appropriate agent (local-ops, QA, web-qa)
532
+ 4. **REPORT** verified results with evidence from verification agent
533
533
 
534
- ### Allowed Verification Commands (AFTER Delegation)
534
+ ### PM NEVER Uses Verification Commands
535
535
 
536
- These commands are ALLOWED for quality assurance AFTER delegating implementation:
536
+ **FORBIDDEN for PM** (must delegate to local-ops or QA):
537
537
 
538
- - `curl`, `wget` - HTTP endpoint testing
539
- - `lsof`, `netstat`, `ss` - Port and network checks
540
- - `ps`, `pgrep` - Process status checks
541
- - `pm2 status`, `docker ps` - Service status
542
- - Health check endpoints
538
+ - `curl`, `wget` - HTTP endpoint testing → Delegate to api-qa or local-ops
539
+ - `lsof`, `netstat`, `ss` - Port and network checks → Delegate to local-ops
540
+ - `ps`, `pgrep` - Process status checks → Delegate to local-ops
541
+ - `pm2 status`, `docker ps` - Service status → Delegate to local-ops
542
+ - Health check endpoints → Delegate to api-qa or web-qa
543
+
544
+ **Why PM doesn't verify**: Verification is technical work requiring domain expertise. local-ops and QA agents have the tools, context, and expertise to verify correctly.
543
545
 
544
546
  ### Examples
545
547
 
@@ -550,23 +552,29 @@ These commands are ALLOWED for quality assurance AFTER delegating implementation
550
552
  PM: Bash("npm start") # VIOLATION - implementing
551
553
  PM: "App running on localhost:3000" # VIOLATION - no delegation
552
554
 
555
+ # Wrong: PM using verification commands
556
+ PM: Bash("lsof -i :3000") # VIOLATION - should delegate to local-ops
557
+ PM: Bash("curl http://localhost:3000") # VIOLATION - should delegate to api-qa
558
+
553
559
  # Wrong: PM testing before delegating implementation
554
560
  PM: Bash("npm test") # VIOLATION - testing without implementation
555
561
 
556
562
  # Wrong: "Let me" thinking
557
563
  PM: "Let me check the code..." # VIOLATION - should delegate
558
564
  PM: "Let me fix this bug..." # VIOLATION - should delegate
565
+ PM: "Let me verify the deployment..." # VIOLATION - should delegate to local-ops
559
566
  ```
560
567
 
561
568
  #### ✅ CORRECT Examples
562
569
 
563
570
  ```
564
- # Correct: Delegate first, then verify
565
- PM: Task(agent="local-ops-agent", task="Start app on localhost:3000 using npm")
566
- [Agent starts app]
567
- PM: Bash("lsof -i :3000 | grep LISTEN") # ALLOWED - verifying after delegation
568
- PM: Bash("curl http://localhost:3000") # ALLOWED - confirming deployment
569
- PM: "App verified: Port 3000 listening, HTTP 200 response"
571
+ # Correct: Delegate implementation, then delegate verification
572
+ PM: Task(agent="local-ops", task="Start app on localhost:3000 using npm")
573
+ [local-ops starts app]
574
+ PM: Task(agent="local-ops", task="Verify app is running on port 3000")
575
+ [local-ops uses lsof and curl to verify]
576
+ [local-ops returns: "Port 3000 listening, HTTP 200 response"]
577
+ PM: "App verified by local-ops: Port 3000 listening, HTTP 200 response"
570
578
 
571
579
  # Correct: Delegate implementation, then delegate testing
572
580
  PM: Task(agent="engineer", task="Fix authentication bug")
@@ -578,6 +586,7 @@ PM: "Bug fix verified by QA: All tests passed"
578
586
  # Correct: Thinking in delegation terms
579
587
  PM: "I'll have Research check the code..."
580
588
  PM: "I'll delegate this fix to Engineer..."
589
+ PM: "I'll have local-ops verify the deployment..."
581
590
  ```
582
591
 
583
592
  ---
@@ -0,0 +1,526 @@
1
+ """CLI commands for auto-generating todos from hook errors.
2
+
3
+ WHY this is needed:
4
+ - Convert hook errors into actionable todos for the PM
5
+ - Enable PM to delegate error resolution to appropriate agents
6
+ - Reduce manual todo creation overhead
7
+ - Maintain error visibility in the PM's workflow
8
+
9
+ DESIGN DECISION: Event-driven architecture
10
+ - Read from event log instead of hook_errors.json
11
+ - Event log provides clean separation between detection and consumption
12
+ - Supports multiple consumers (CLI, dashboard, notifications)
13
+ - Persistent storage with pending/resolved status tracking
14
+ """
15
+
16
+ import json
17
+ from datetime import datetime, timezone
18
+ from pathlib import Path
19
+ from typing import Any, Dict, List
20
+
21
+ import click
22
+
23
+ from claude_mpm.services.delegation_detector import get_delegation_detector
24
+ from claude_mpm.services.event_log import get_event_log
25
+
26
+
27
+ def format_error_event_as_todo(event: Dict[str, Any]) -> Dict[str, str]:
28
+ """Convert event log error event to todo format compatible with PM TodoWrite.
29
+
30
+ Args:
31
+ event: Event from event log with payload containing error details
32
+
33
+ Returns:
34
+ Dictionary with todo fields (content, activeForm, status)
35
+ """
36
+ payload = event.get("payload", {})
37
+ error_type = payload.get("error_type", "unknown")
38
+ hook_type = payload.get("hook_type", "unknown")
39
+ details = payload.get("details", "")
40
+ full_message = payload.get("full_message", "")
41
+
42
+ # Create concise todo content
43
+ content = f"Fix {hook_type} hook error: {error_type}"
44
+ if details:
45
+ content += f" ({details[:50]}{'...' if len(details) > 50 else ''})"
46
+
47
+ # Active form for in-progress display
48
+ active_form = f"Fixing {hook_type} hook error"
49
+
50
+ return {
51
+ "content": content,
52
+ "activeForm": active_form,
53
+ "status": "pending",
54
+ "metadata": {
55
+ "event_id": event.get("id", ""),
56
+ "event_type": event.get("event_type", ""),
57
+ "error_type": error_type,
58
+ "hook_type": hook_type,
59
+ "details": details,
60
+ "full_message": full_message,
61
+ "suggested_fix": payload.get("suggested_fix", ""),
62
+ "timestamp": event.get("timestamp", ""),
63
+ },
64
+ }
65
+
66
+
67
+ def format_delegation_event_as_todo(event: Dict[str, Any]) -> Dict[str, str]:
68
+ """Convert event log delegation event to todo format compatible with PM TodoWrite.
69
+
70
+ Args:
71
+ event: Event from event log with payload containing delegation details
72
+
73
+ Returns:
74
+ Dictionary with todo fields (content, activeForm, status)
75
+ """
76
+ payload = event.get("payload", {})
77
+ pattern_type = payload.get("pattern_type", "Task")
78
+ suggested_todo = payload.get("suggested_todo", "")
79
+ action = payload.get("action", "")
80
+ original_text = payload.get("original_text", "")
81
+
82
+ # Create concise todo content
83
+ content = f"[Delegation] {suggested_todo}"
84
+
85
+ # Active form for in-progress display
86
+ active_form = f"Delegating: {action[:30]}..."
87
+
88
+ return {
89
+ "content": content,
90
+ "activeForm": active_form,
91
+ "status": "pending",
92
+ "metadata": {
93
+ "event_id": event.get("id", ""),
94
+ "event_type": event.get("event_type", ""),
95
+ "pattern_type": pattern_type,
96
+ "suggested_todo": suggested_todo,
97
+ "action": action,
98
+ "original_text": original_text,
99
+ "timestamp": event.get("timestamp", ""),
100
+ },
101
+ }
102
+
103
+
104
+ def get_autotodos() -> List[Dict[str, Any]]:
105
+ """Get all pending hook error events formatted as todos.
106
+
107
+ DESIGN DECISION: Only autotodo.error events are returned
108
+ - autotodo.error = Script/coding failures → PM should delegate fix
109
+ - pm.violation = Delegation anti-patterns → PM behavior error (not todo)
110
+
111
+ Returns:
112
+ List of todo dictionaries ready for PM injection
113
+ """
114
+ event_log = get_event_log()
115
+ todos = []
116
+
117
+ # Get all pending autotodo.error events (script failures)
118
+ pending_error_events = event_log.list_events(
119
+ event_type="autotodo.error", status="pending"
120
+ )
121
+
122
+ for event in pending_error_events:
123
+ todo = format_error_event_as_todo(event)
124
+ todos.append(todo)
125
+
126
+ return todos
127
+
128
+
129
+ @click.group(name="autotodos")
130
+ def autotodos_group():
131
+ """Auto-generate todos from hook errors.
132
+
133
+ This command converts hook errors into actionable todos that can be
134
+ injected into the PM's todo list for delegation and resolution.
135
+
136
+ Uses event-driven architecture - reads from event log instead of
137
+ directly from hook error memory.
138
+ """
139
+
140
+
141
+ @autotodos_group.command(name="status")
142
+ def show_autotodos_status():
143
+ """Show autotodos status and statistics.
144
+
145
+ Quick overview of pending hook errors, PM violations, and autotodos.
146
+
147
+ Example:
148
+ claude-mpm autotodos status
149
+ """
150
+ event_log = get_event_log()
151
+ stats = event_log.get_stats()
152
+ todos = get_autotodos()
153
+ violations = event_log.list_events(event_type="pm.violation", status="pending")
154
+
155
+ click.echo("\n📊 AutoTodos Status")
156
+ click.echo("=" * 80)
157
+
158
+ click.echo(f"Total Events: {stats['total_events']}")
159
+ click.echo(f"Pending Todos (script errors): {len(todos)}")
160
+ click.echo(f"Pending Violations (PM errors): {len(violations)}")
161
+ click.echo(f"Total Pending Events: {stats['by_status']['pending']}")
162
+ click.echo(f"Resolved Events: {stats['by_status']['resolved']}")
163
+
164
+ if stats.get("by_type"):
165
+ click.echo("\n📋 Events by Type:")
166
+ for event_type, count in stats["by_type"].items():
167
+ click.echo(f" {event_type}: {count}")
168
+
169
+ click.echo(f"\n📁 Event Log: {stats['log_file']}")
170
+
171
+ if todos or violations:
172
+ click.echo("\n⚠️ Action Required:")
173
+ if todos:
174
+ click.echo(f" {len(todos)} script error(s) need delegation")
175
+ if violations:
176
+ click.echo(f" {len(violations)} PM violation(s) need correction")
177
+ click.echo("\nCommands:")
178
+ click.echo(
179
+ " claude-mpm autotodos list # View pending todos (script errors)"
180
+ )
181
+ click.echo(" claude-mpm autotodos violations # View PM violations")
182
+ click.echo(" claude-mpm autotodos inject # Inject todos into PM session")
183
+ click.echo(" claude-mpm autotodos clear # Clear after resolution")
184
+ else:
185
+ click.echo("\n✅ No pending todos or violations. All clear!")
186
+
187
+
188
+ @autotodos_group.command(name="list")
189
+ @click.option(
190
+ "--format",
191
+ type=click.Choice(["table", "json"], case_sensitive=False),
192
+ default="table",
193
+ help="Output format (table or json)",
194
+ )
195
+ def list_autotodos(format):
196
+ """List all auto-generated todos from hook errors.
197
+
198
+ Shows pending hook errors formatted as todos that can be acted upon
199
+ by the PM.
200
+
201
+ Examples:
202
+ claude-mpm autotodos list
203
+ claude-mpm autotodos list --format json
204
+ """
205
+ todos = get_autotodos()
206
+
207
+ if not todos:
208
+ click.echo("✅ No pending hook errors. All clear!")
209
+ return
210
+
211
+ if format == "json":
212
+ # JSON output for programmatic use
213
+ click.echo(json.dumps(todos, indent=2))
214
+ else:
215
+ # Table output for human readability
216
+ click.echo("\n" + "=" * 80)
217
+ click.echo("Auto-Generated Todos from Hook Errors")
218
+ click.echo("=" * 80)
219
+
220
+ for i, todo in enumerate(todos, 1):
221
+ metadata = todo.get("metadata", {})
222
+ click.echo(f"\n{i}. {todo['content']}")
223
+ click.echo(f" Status: {todo['status']}")
224
+ click.echo(f" Hook: {metadata.get('hook_type', 'Unknown')}")
225
+ click.echo(f" Error Type: {metadata.get('error_type', 'Unknown')}")
226
+ click.echo(f" Timestamp: {metadata.get('timestamp', 'Unknown')}")
227
+
228
+ # Show suggested fix if available
229
+ suggested_fix = metadata.get("suggested_fix", "")
230
+ if suggested_fix:
231
+ # Show first line of suggestion
232
+ first_line = suggested_fix.split("\n")[0]
233
+ click.echo(f" Suggestion: {first_line}")
234
+
235
+ click.echo("\n" + "=" * 80)
236
+ click.echo(f"Total: {len(todos)} pending todo(s)")
237
+ click.echo("\nTo inject into PM session: claude-mpm autotodos inject")
238
+
239
+
240
+ @autotodos_group.command(name="inject")
241
+ @click.option(
242
+ "--output",
243
+ type=click.Path(),
244
+ help="Output file path (default: stdout)",
245
+ )
246
+ def inject_autotodos(output):
247
+ """Inject auto-generated todos in PM-compatible format.
248
+
249
+ Outputs todos in a format that can be injected into the PM's
250
+ session as system reminders.
251
+
252
+ Examples:
253
+ claude-mpm autotodos inject
254
+ claude-mpm autotodos inject --output todos.json
255
+ """
256
+ todos = get_autotodos()
257
+
258
+ if not todos:
259
+ click.echo("✅ No pending hook errors to inject.", err=True)
260
+ return
261
+
262
+ # Format as system reminder for PM
263
+ pm_message = {
264
+ "type": "autotodos",
265
+ "timestamp": datetime.now(timezone.utc).isoformat(),
266
+ "todos": todos,
267
+ "message": f"Found {len(todos)} hook error(s) requiring attention. "
268
+ "Consider delegating to appropriate agents for resolution.",
269
+ }
270
+
271
+ output_json = json.dumps(pm_message, indent=2)
272
+
273
+ if output:
274
+ # Write to file
275
+ output_path = Path(output)
276
+ output_path.write_text(output_json)
277
+ click.echo(f"✅ Injected {len(todos)} todo(s) to {output_path}", err=True)
278
+ else:
279
+ # Write to stdout for piping
280
+ click.echo(output_json)
281
+
282
+
283
+ @autotodos_group.command(name="clear")
284
+ @click.option(
285
+ "--event-id",
286
+ help="Clear specific event by ID",
287
+ )
288
+ @click.option(
289
+ "--event-type",
290
+ type=click.Choice(["error", "violation", "all"], case_sensitive=False),
291
+ default="all",
292
+ help="Type of events to clear (default: all)",
293
+ )
294
+ @click.option(
295
+ "--yes",
296
+ "-y",
297
+ is_flag=True,
298
+ help="Skip confirmation prompt",
299
+ )
300
+ def clear_autotodos(event_id, event_type, yes):
301
+ """Clear hook errors and PM violations after resolution.
302
+
303
+ This marks resolved events in the event log, removing them from
304
+ the autotodos and violations lists.
305
+
306
+ Examples:
307
+ claude-mpm autotodos clear # Clear all pending
308
+ claude-mpm autotodos clear --event-type error # Clear only errors
309
+ claude-mpm autotodos clear --event-type violation # Clear only violations
310
+ claude-mpm autotodos clear --event-id ID # Clear specific event
311
+ claude-mpm autotodos clear -y # Skip confirmation
312
+ """
313
+ event_log = get_event_log()
314
+
315
+ if event_id:
316
+ # Clear specific event
317
+ if not yes:
318
+ message = f"Clear event: {event_id}?"
319
+ if not click.confirm(message):
320
+ click.echo("Cancelled.")
321
+ return
322
+
323
+ # Mark as resolved
324
+ if event_log.mark_resolved(event_id):
325
+ click.echo(f"✅ Cleared event: {event_id}")
326
+ else:
327
+ click.echo(f"❌ Event not found: {event_id}")
328
+ else:
329
+ # Determine which event types to clear
330
+ if event_type == "error":
331
+ event_types = ["autotodo.error"]
332
+ elif event_type == "violation":
333
+ event_types = ["pm.violation"]
334
+ else: # all
335
+ event_types = ["autotodo.error", "pm.violation"]
336
+
337
+ # Count pending events
338
+ total_count = 0
339
+ for et in event_types:
340
+ pending = event_log.list_events(event_type=et, status="pending")
341
+ total_count += len(pending)
342
+
343
+ if total_count == 0:
344
+ click.echo("No pending events to clear.")
345
+ return
346
+
347
+ if not yes:
348
+ message = f"Clear all {total_count} pending event(s)?"
349
+ if not click.confirm(message):
350
+ click.echo("Cancelled.")
351
+ return
352
+
353
+ # Mark all as resolved
354
+ total_cleared = 0
355
+ for et in event_types:
356
+ cleared = event_log.mark_all_resolved(event_type=et)
357
+ total_cleared += cleared
358
+
359
+ click.echo(f"✅ Cleared {total_cleared} event(s).")
360
+
361
+
362
+ @autotodos_group.command(name="violations")
363
+ @click.option(
364
+ "--format",
365
+ type=click.Choice(["table", "json"], case_sensitive=False),
366
+ default="table",
367
+ help="Output format (table or json)",
368
+ )
369
+ def list_pm_violations(format):
370
+ """List PM delegation violations.
371
+
372
+ Shows instances where PM asked user to do something manually
373
+ instead of delegating to an agent. These are PM behavior errors
374
+ that should be corrected, not todos to delegate.
375
+
376
+ Examples:
377
+ claude-mpm autotodos violations
378
+ claude-mpm autotodos violations --format json
379
+ """
380
+ event_log = get_event_log()
381
+ violations = event_log.list_events(event_type="pm.violation", status="pending")
382
+
383
+ if not violations:
384
+ click.echo("✅ No PM violations detected. All delegation patterns are correct!")
385
+ return
386
+
387
+ if format == "json":
388
+ # JSON output for programmatic use
389
+ click.echo(json.dumps(violations, indent=2))
390
+ else:
391
+ # Table output for human readability
392
+ click.echo("\n" + "=" * 80)
393
+ click.echo("PM Delegation Violations")
394
+ click.echo("=" * 80)
395
+ click.echo("\n⚠️ PM asked user to do these manually instead of delegating:\n")
396
+
397
+ for i, violation in enumerate(violations, 1):
398
+ payload = violation.get("payload", {})
399
+ click.echo(f"{i}. Pattern: {payload.get('pattern_type', 'Unknown')}")
400
+ click.echo(f' Original: "{payload.get("original_text", "")}"')
401
+ click.echo(f" Should delegate: {payload.get('suggested_action', '')}")
402
+ click.echo(f" Severity: {payload.get('severity', 'unknown')}")
403
+ click.echo(f" Timestamp: {violation.get('timestamp', 'Unknown')}")
404
+ click.echo()
405
+
406
+ click.echo("=" * 80)
407
+ click.echo(f"Total: {len(violations)} violation(s) detected")
408
+ click.echo("\n💡 These are PM behavior errors - PM should delegate these tasks")
409
+ click.echo(" to appropriate agents instead of asking user to do them.")
410
+ click.echo("\nTo clear: claude-mpm autotodos clear --event-type violation")
411
+
412
+
413
+ @autotodos_group.command(name="scan")
414
+ @click.argument("text", required=False)
415
+ @click.option(
416
+ "--file",
417
+ "-f",
418
+ type=click.Path(exists=True),
419
+ help="Scan text from file instead of argument",
420
+ )
421
+ @click.option(
422
+ "--format",
423
+ type=click.Choice(["table", "json"], case_sensitive=False),
424
+ default="table",
425
+ help="Output format (table or json)",
426
+ )
427
+ @click.option(
428
+ "--save",
429
+ is_flag=True,
430
+ help="Save detections to event log as PM violations",
431
+ )
432
+ def scan_delegation_patterns(text, file, format, save):
433
+ """Scan text for delegation anti-patterns.
434
+
435
+ Detects when PM asks user to do something manually instead of
436
+ delegating to an agent. Helps enforce the delegation principle.
437
+
438
+ Examples:
439
+ claude-mpm autotodos scan "Make sure .env.local is in .gitignore"
440
+ claude-mpm autotodos scan -f response.txt
441
+ claude-mpm autotodos scan -f response.txt --save
442
+ echo "You'll need to run npm install" | claude-mpm autotodos scan
443
+ """
444
+ detector = get_delegation_detector()
445
+
446
+ # Read text from file, argument, or stdin
447
+ if file:
448
+ text = Path(file).read_text()
449
+ elif not text:
450
+ # Read from stdin
451
+ import sys
452
+
453
+ text = sys.stdin.read()
454
+
455
+ if not text or not text.strip():
456
+ click.echo("Error: No text provided to scan.", err=True)
457
+ click.echo("\nUsage:", err=True)
458
+ click.echo(" claude-mpm autotodos scan 'text to scan'", err=True)
459
+ click.echo(" claude-mpm autotodos scan -f file.txt", err=True)
460
+ click.echo(" echo 'text' | claude-mpm autotodos scan", err=True)
461
+ return
462
+
463
+ # Detect delegation patterns
464
+ detections = detector.detect_user_delegation(text)
465
+
466
+ if not detections:
467
+ click.echo("✅ No delegation anti-patterns detected!")
468
+ return
469
+
470
+ # Save to event log if requested
471
+ if save:
472
+ event_log = get_event_log()
473
+ for detection in detections:
474
+ # Format as PM violation payload
475
+ payload = {
476
+ "violation_type": "delegation_anti_pattern",
477
+ "pattern_type": detection["pattern_type"],
478
+ "original_text": detection["original_text"],
479
+ "suggested_action": detection["suggested_todo"],
480
+ "action": detection["action"],
481
+ "source": "delegation_detector",
482
+ "severity": "warning",
483
+ "message": f"PM asked user to do something manually: {detection['original_text'][:80]}...",
484
+ }
485
+ event_log.append_event(
486
+ event_type="pm.violation", payload=payload, status="pending"
487
+ )
488
+ click.echo(f"\n✅ Saved {len(detections)} violation(s) to event log")
489
+
490
+ # Output results
491
+ if format == "json":
492
+ # JSON output for programmatic use
493
+ click.echo(json.dumps(detections, indent=2))
494
+ else:
495
+ # Table output for human readability
496
+ click.echo("\n" + "=" * 80)
497
+ click.echo("Delegation Anti-Patterns Detected")
498
+ click.echo("=" * 80)
499
+ click.echo(
500
+ "\n⚠️ PM is asking user to do these manually instead of delegating:\n"
501
+ )
502
+
503
+ for i, detection in enumerate(detections, 1):
504
+ click.echo(f"{i}. Pattern: {detection['pattern_type']}")
505
+ click.echo(f' Original: "{detection["original_text"]}"')
506
+ click.echo(f" Suggested Todo: {detection['suggested_todo']}")
507
+ click.echo(f" Action: {detection['action']}")
508
+ click.echo()
509
+
510
+ click.echo("=" * 80)
511
+ click.echo(f"Total: {len(detections)} anti-pattern(s) detected")
512
+ click.echo("\n💡 Tip: PM should delegate these tasks to appropriate agents")
513
+ click.echo(" instead of asking the user to do them manually.")
514
+
515
+ if not save:
516
+ click.echo("\n Use --save to add these as autotodos for PM to see.")
517
+
518
+
519
+ # Register the command group
520
+ def register_commands(cli):
521
+ """Register autotodos commands with CLI.
522
+
523
+ Args:
524
+ cli: Click CLI group to register commands with
525
+ """
526
+ cli.add_command(autotodos_group)