empathy-framework 4.7.0__py3-none-any.whl → 4.8.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.
Files changed (86) hide show
  1. empathy_framework-4.8.0.dist-info/METADATA +753 -0
  2. {empathy_framework-4.7.0.dist-info → empathy_framework-4.8.0.dist-info}/RECORD +83 -37
  3. {empathy_framework-4.7.0.dist-info → empathy_framework-4.8.0.dist-info}/WHEEL +1 -1
  4. {empathy_framework-4.7.0.dist-info → empathy_framework-4.8.0.dist-info}/entry_points.txt +2 -1
  5. empathy_os/__init__.py +2 -0
  6. empathy_os/cache/hash_only.py +6 -3
  7. empathy_os/cache/hybrid.py +6 -3
  8. empathy_os/cli/__init__.py +128 -238
  9. empathy_os/cli/__main__.py +5 -33
  10. empathy_os/cli/commands/__init__.py +1 -8
  11. empathy_os/cli/commands/help.py +331 -0
  12. empathy_os/cli/commands/info.py +140 -0
  13. empathy_os/cli/commands/inspect.py +437 -0
  14. empathy_os/cli/commands/metrics.py +92 -0
  15. empathy_os/cli/commands/orchestrate.py +184 -0
  16. empathy_os/cli/commands/patterns.py +207 -0
  17. empathy_os/cli/commands/provider.py +93 -81
  18. empathy_os/cli/commands/setup.py +96 -0
  19. empathy_os/cli/commands/status.py +235 -0
  20. empathy_os/cli/commands/sync.py +166 -0
  21. empathy_os/cli/commands/tier.py +121 -0
  22. empathy_os/cli/commands/workflow.py +574 -0
  23. empathy_os/cli/parsers/__init__.py +62 -0
  24. empathy_os/cli/parsers/help.py +41 -0
  25. empathy_os/cli/parsers/info.py +26 -0
  26. empathy_os/cli/parsers/inspect.py +66 -0
  27. empathy_os/cli/parsers/metrics.py +42 -0
  28. empathy_os/cli/parsers/orchestrate.py +61 -0
  29. empathy_os/cli/parsers/patterns.py +54 -0
  30. empathy_os/cli/parsers/provider.py +40 -0
  31. empathy_os/cli/parsers/setup.py +42 -0
  32. empathy_os/cli/parsers/status.py +47 -0
  33. empathy_os/cli/parsers/sync.py +31 -0
  34. empathy_os/cli/parsers/tier.py +33 -0
  35. empathy_os/cli/parsers/workflow.py +77 -0
  36. empathy_os/cli/utils/__init__.py +1 -0
  37. empathy_os/cli/utils/data.py +242 -0
  38. empathy_os/cli/utils/helpers.py +68 -0
  39. empathy_os/{cli.py → cli_legacy.py} +27 -27
  40. empathy_os/cli_minimal.py +662 -0
  41. empathy_os/cli_router.py +384 -0
  42. empathy_os/cli_unified.py +38 -2
  43. empathy_os/memory/__init__.py +19 -5
  44. empathy_os/memory/short_term.py +14 -404
  45. empathy_os/memory/types.py +437 -0
  46. empathy_os/memory/unified.py +61 -48
  47. empathy_os/models/fallback.py +1 -1
  48. empathy_os/models/provider_config.py +59 -344
  49. empathy_os/models/registry.py +31 -180
  50. empathy_os/monitoring/alerts.py +14 -20
  51. empathy_os/monitoring/alerts_cli.py +24 -7
  52. empathy_os/project_index/__init__.py +2 -0
  53. empathy_os/project_index/index.py +210 -5
  54. empathy_os/project_index/scanner.py +45 -14
  55. empathy_os/project_index/scanner_parallel.py +291 -0
  56. empathy_os/socratic/ab_testing.py +1 -1
  57. empathy_os/vscode_bridge 2.py +173 -0
  58. empathy_os/workflows/__init__.py +31 -2
  59. empathy_os/workflows/base.py +349 -325
  60. empathy_os/workflows/bug_predict.py +8 -0
  61. empathy_os/workflows/builder.py +273 -0
  62. empathy_os/workflows/caching.py +253 -0
  63. empathy_os/workflows/code_review_pipeline.py +1 -0
  64. empathy_os/workflows/history.py +510 -0
  65. empathy_os/workflows/output.py +410 -0
  66. empathy_os/workflows/perf_audit.py +125 -19
  67. empathy_os/workflows/progress.py +324 -22
  68. empathy_os/workflows/progressive/README 2.md +454 -0
  69. empathy_os/workflows/progressive/__init__ 2.py +92 -0
  70. empathy_os/workflows/progressive/cli 2.py +242 -0
  71. empathy_os/workflows/progressive/core 2.py +488 -0
  72. empathy_os/workflows/progressive/orchestrator 2.py +701 -0
  73. empathy_os/workflows/progressive/reports 2.py +528 -0
  74. empathy_os/workflows/progressive/telemetry 2.py +280 -0
  75. empathy_os/workflows/progressive/test_gen 2.py +514 -0
  76. empathy_os/workflows/progressive/workflow 2.py +628 -0
  77. empathy_os/workflows/routing.py +168 -0
  78. empathy_os/workflows/secure_release.py +1 -0
  79. empathy_os/workflows/security_audit.py +190 -0
  80. empathy_os/workflows/security_audit_phase3.py +328 -0
  81. empathy_os/workflows/telemetry_mixin.py +269 -0
  82. empathy_framework-4.7.0.dist-info/METADATA +0 -1598
  83. empathy_os/dashboard/__init__.py +0 -15
  84. empathy_os/dashboard/server.py +0 -941
  85. {empathy_framework-4.7.0.dist-info → empathy_framework-4.8.0.dist-info}/licenses/LICENSE +0 -0
  86. {empathy_framework-4.7.0.dist-info → empathy_framework-4.8.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,437 @@
1
+ """Inspect commands for patterns, metrics, and interactive REPL.
2
+
3
+ Copyright 2025 Smart-AI-Memory
4
+ Licensed under Fair Source License 0.9
5
+ """
6
+
7
+ import heapq
8
+ import sys
9
+ import time
10
+
11
+ from empathy_os.config import EmpathyConfig, _validate_file_path, load_config
12
+ from empathy_os.core import EmpathyOS
13
+ from empathy_os.logging_config import get_logger
14
+ from empathy_os.metrics.collector import MetricsCollector
15
+ from empathy_os.pattern_library import PatternLibrary
16
+ from empathy_os.persistence import PatternPersistence
17
+ from empathy_os.state_manager import StateManager
18
+
19
+ logger = get_logger(__name__)
20
+
21
+
22
+ def cmd_run(args):
23
+ """Interactive REPL for testing empathy interactions.
24
+
25
+ Starts an interactive session for testing empathy levels and features.
26
+
27
+ Args:
28
+ args: Namespace object from argparse with attributes:
29
+ - config (str | None): Path to configuration file.
30
+ - user_id (str | None): User ID (default: cli_user).
31
+ - level (int): Target empathy level (1-5).
32
+
33
+ Returns:
34
+ None: Runs interactive REPL until user exits.
35
+ """
36
+ config_file = args.config
37
+ user_id = args.user_id or "cli_user"
38
+ level = args.level
39
+
40
+ print("🧠 Empathy Framework - Interactive Mode")
41
+ print("=" * 50)
42
+
43
+ # Load configuration
44
+ if config_file:
45
+ config = load_config(filepath=config_file)
46
+ print(f"✓ Loaded config from: {config_file}")
47
+ else:
48
+ config = EmpathyConfig(user_id=user_id, target_level=level)
49
+ print("✓ Using default configuration")
50
+
51
+ print(f"\nUser ID: {config.user_id}")
52
+ print(f"Target Level: {config.target_level}")
53
+ print(f"Confidence Threshold: {config.confidence_threshold:.0%}")
54
+
55
+ # Create EmpathyOS instance
56
+ try:
57
+ empathy = EmpathyOS(
58
+ user_id=config.user_id,
59
+ target_level=config.target_level,
60
+ confidence_threshold=config.confidence_threshold,
61
+ persistence_enabled=config.persistence_enabled,
62
+ )
63
+ print("✓ Empathy OS initialized")
64
+ except ValueError as e:
65
+ # Invalid configuration parameters
66
+ print(f"✗ Configuration error: {e}")
67
+ sys.exit(1)
68
+ except (OSError, FileNotFoundError, PermissionError) as e:
69
+ # Cannot access required files/directories
70
+ print(f"✗ File system error: {e}")
71
+ sys.exit(1)
72
+ except Exception as e:
73
+ # Unexpected initialization failure
74
+ logger.exception(f"Unexpected error initializing Empathy OS: {e}")
75
+ print(f"✗ Failed to initialize Empathy OS: {e}")
76
+ sys.exit(1)
77
+
78
+ print("\n" + "=" * 50)
79
+ print("Type your input (or 'exit'/'quit' to stop)")
80
+ print("Type 'help' for available commands")
81
+ print("=" * 50 + "\n")
82
+
83
+ # Interactive loop
84
+ while True:
85
+ try:
86
+ user_input = input("You: ").strip()
87
+
88
+ if not user_input:
89
+ continue
90
+
91
+ if user_input.lower() in ["exit", "quit", "q"]:
92
+ print("\n👋 Goodbye!")
93
+ break
94
+
95
+ if user_input.lower() == "help":
96
+ print("\nAvailable commands:")
97
+ print(" exit, quit, q - Exit the program")
98
+ print(" help - Show this help message")
99
+ print(" trust - Show current trust level")
100
+ print(" stats - Show session statistics")
101
+ print(" level - Show current empathy level")
102
+ print()
103
+ continue
104
+
105
+ if user_input.lower() == "trust":
106
+ trust = empathy.collaboration_state.trust_level
107
+ print(f"\n Current trust level: {trust:.0%}\n")
108
+ continue
109
+
110
+ if user_input.lower() == "level":
111
+ current_level = empathy.collaboration_state.current_level
112
+ print(f"\n Current empathy level: {current_level}\n")
113
+ continue
114
+
115
+ if user_input.lower() == "stats":
116
+ print("\n Session Statistics:")
117
+ print(f" Trust: {empathy.collaboration_state.trust_level:.0%}")
118
+ print(f" Current Level: {empathy.collaboration_state.current_level}")
119
+ print(f" Target Level: {config.target_level}")
120
+ print()
121
+ continue
122
+
123
+ # Process interaction
124
+ start_time = time.time()
125
+ response = empathy.interact(user_id=config.user_id, user_input=user_input, context={})
126
+ duration = (time.time() - start_time) * 1000
127
+
128
+ # Display response with level indicator
129
+ level_indicators = ["❌", "🔵", "🟢", "🟡", "🔮"]
130
+ level_indicator = level_indicators[response.level]
131
+
132
+ print(f"\nBot {level_indicator} [L{response.level}]: {response.response}")
133
+
134
+ # Show predictions if Level 4
135
+ if response.predictions:
136
+ print("\n🔮 Predictions:")
137
+ for pred in response.predictions:
138
+ print(f" • {pred}")
139
+
140
+ conf = f"{response.confidence:.0%}"
141
+ print(f"\n Level: {response.level} | Confidence: {conf} | Time: {duration:.0f}ms")
142
+ print()
143
+
144
+ # Ask for feedback
145
+ feedback = input("Was this helpful? (y/n/skip): ").strip().lower()
146
+ if feedback == "y":
147
+ empathy.record_success(success=True)
148
+ trust = empathy.collaboration_state.trust_level
149
+ print(f" ✓ Trust increased to {trust:.0%}\n")
150
+ elif feedback == "n":
151
+ empathy.record_success(success=False)
152
+ trust = empathy.collaboration_state.trust_level
153
+ print(f" ✗ Trust decreased to {trust:.0%}\n")
154
+
155
+ except KeyboardInterrupt:
156
+ print("\n\n👋 Goodbye!")
157
+ break
158
+ except (ValueError, KeyError) as e:
159
+ # Invalid input or response structure
160
+ print(f"\n✗ Input error: {e}\n")
161
+ except Exception as e:
162
+ # Unexpected errors in interactive loop - log and continue
163
+ logger.exception(f"Unexpected error in interactive loop: {e}")
164
+ print(f"\n✗ Error: {e}\n")
165
+
166
+
167
+ def cmd_inspect(args):
168
+ """Unified inspection command for patterns, metrics, and state.
169
+
170
+ Inspect various framework data including patterns, user metrics, and states.
171
+
172
+ Args:
173
+ args: Namespace object from argparse with attributes:
174
+ - type (str): What to inspect ('patterns', 'metrics', or 'state').
175
+ - user_id (str | None): Filter by user ID.
176
+ - db (str | None): Database path (default: .empathy/patterns.db).
177
+ - state_dir (str | None): State directory for state inspection.
178
+
179
+ Returns:
180
+ None: Prints inspection results. Exits with code 1 on failure.
181
+ """
182
+ inspect_type = args.type
183
+ user_id = args.user_id
184
+ db_path = args.db or ".empathy/patterns.db"
185
+
186
+ print(f"🔍 Inspecting: {inspect_type}")
187
+ print("=" * 50)
188
+
189
+ if inspect_type == "patterns":
190
+ try:
191
+ # Determine file format from extension
192
+ if db_path.endswith(".json"):
193
+ library = PatternPersistence.load_from_json(db_path)
194
+ else:
195
+ library = PatternPersistence.load_from_sqlite(db_path)
196
+
197
+ patterns = list(library.patterns.values())
198
+
199
+ # Filter by user_id if specified
200
+ if user_id:
201
+ patterns = [p for p in patterns if p.agent_id == user_id]
202
+
203
+ print(f"\nPatterns for {'user ' + user_id if user_id else 'all users'}:")
204
+ print(f" Total patterns: {len(patterns)}")
205
+
206
+ if patterns:
207
+ print("\n Top patterns:")
208
+ # Sort by confidence
209
+ top_patterns = heapq.nlargest(10, patterns, key=lambda p: p.confidence)
210
+ for i, pattern in enumerate(top_patterns, 1):
211
+ print(f"\n {i}. {pattern.name}")
212
+ print(f" Confidence: {pattern.confidence:.0%}")
213
+ print(f" Used: {pattern.usage_count} times")
214
+ print(f" Success rate: {pattern.success_rate:.0%}")
215
+ except FileNotFoundError:
216
+ print(f"✗ Pattern library not found: {db_path}")
217
+ print(" Tip: Use 'empathy-framework workflow' to set up your first project")
218
+ sys.exit(1)
219
+ except (ValueError, KeyError) as e:
220
+ # Invalid pattern data format
221
+ print(f"✗ Invalid pattern data: {e}")
222
+ sys.exit(1)
223
+ except Exception as e:
224
+ # Unexpected errors loading patterns
225
+ logger.exception(f"Unexpected error loading patterns: {e}")
226
+ print(f"✗ Failed to load patterns: {e}")
227
+ sys.exit(1)
228
+
229
+ elif inspect_type == "metrics":
230
+ if not user_id:
231
+ print("✗ User ID required for metrics inspection")
232
+ print(" Usage: empathy-framework inspect metrics --user-id USER_ID")
233
+ sys.exit(1)
234
+
235
+ try:
236
+ collector = MetricsCollector(db_path=db_path)
237
+ stats = collector.get_user_stats(user_id)
238
+
239
+ print(f"\nMetrics for user: {user_id}")
240
+ print(f" Total operations: {stats.get('total_operations', 0)}")
241
+ print(f" Success rate: {stats.get('success_rate', 0):.0%}")
242
+ print(f" Average response time: {stats.get('avg_response_time_ms', 0):.0f}ms")
243
+ print("\n Empathy level usage:")
244
+ for level in range(1, 6):
245
+ count = stats.get(f"level_{level}_count", 0)
246
+ print(f" Level {level}: {count} times")
247
+ except (OSError, FileNotFoundError) as e:
248
+ # Database file not found
249
+ print(f"✗ Metrics database not found: {e}")
250
+ sys.exit(1)
251
+ except KeyError as e:
252
+ # User not found
253
+ print(f"✗ User {user_id} not found: {e}")
254
+ sys.exit(1)
255
+ except Exception as e:
256
+ # Unexpected errors loading metrics
257
+ logger.exception(f"Unexpected error loading metrics: {e}")
258
+ print(f"✗ Failed to load metrics: {e}")
259
+ sys.exit(1)
260
+
261
+ elif inspect_type == "state":
262
+ state_dir = args.state_dir or ".empathy/state"
263
+ try:
264
+ manager = StateManager(state_dir)
265
+ users = manager.list_users()
266
+
267
+ print("\nSaved states:")
268
+ print(f" Total users: {len(users)}")
269
+
270
+ if users:
271
+ print("\n Users:")
272
+ for uid in users:
273
+ print(f" • {uid}")
274
+ except (OSError, FileNotFoundError) as e:
275
+ # State directory not found
276
+ print(f"✗ State directory not found: {e}")
277
+ sys.exit(1)
278
+ except Exception as e:
279
+ # Unexpected errors loading state
280
+ logger.exception(f"Unexpected error loading state: {e}")
281
+ print(f"✗ Failed to load state: {e}")
282
+ sys.exit(1)
283
+
284
+ print()
285
+
286
+
287
+ def cmd_export(args):
288
+ """Export patterns to file for sharing/backup.
289
+
290
+ Args:
291
+ args: Namespace object from argparse with attributes:
292
+ - output (str): Output file path.
293
+ - user_id (str | None): Filter patterns by user ID.
294
+ - db (str | None): Source database path.
295
+ - format (str): Output format ('json').
296
+
297
+ Returns:
298
+ None: Exports patterns to file. Exits with code 1 on failure.
299
+
300
+ Raises:
301
+ ValueError: If output path is invalid or unsafe.
302
+ """
303
+ output_file = args.output
304
+ user_id = args.user_id
305
+ db_path = args.db or ".empathy/patterns.db"
306
+ format_type = args.format
307
+
308
+ print(f"📦 Exporting patterns to: {output_file}")
309
+ print("=" * 50)
310
+
311
+ try:
312
+ # Load pattern library from source file
313
+ if db_path.endswith(".json"):
314
+ library = PatternPersistence.load_from_json(db_path)
315
+ else:
316
+ library = PatternPersistence.load_from_sqlite(db_path)
317
+
318
+ patterns = list(library.patterns.values())
319
+
320
+ # Filter by user_id if specified
321
+ if user_id:
322
+ patterns = [p for p in patterns if p.agent_id == user_id]
323
+
324
+ print(f" Found {len(patterns)} patterns")
325
+
326
+ # Validate output path
327
+ validated_output = _validate_file_path(output_file)
328
+
329
+ if format_type == "json":
330
+ # Create filtered library if user_id specified
331
+ if user_id:
332
+ filtered_library = PatternLibrary()
333
+ for pattern in patterns:
334
+ filtered_library.contribute_pattern(pattern.agent_id, pattern)
335
+ else:
336
+ filtered_library = library
337
+
338
+ # Export as JSON
339
+ PatternPersistence.save_to_json(filtered_library, str(validated_output))
340
+ print(f" ✓ Exported {len(patterns)} patterns to {output_file}")
341
+ else:
342
+ print(f"✗ Unsupported format: {format_type}")
343
+ sys.exit(1)
344
+
345
+ except FileNotFoundError:
346
+ print(f"✗ Source file not found: {db_path}")
347
+ print(" Tip: Patterns are saved automatically when using the framework")
348
+ sys.exit(1)
349
+ except (OSError, PermissionError) as e:
350
+ # Cannot write output file
351
+ print(f"✗ Cannot write to file: {e}")
352
+ sys.exit(1)
353
+ except (ValueError, KeyError) as e:
354
+ # Invalid pattern data
355
+ print(f"✗ Invalid pattern data: {e}")
356
+ sys.exit(1)
357
+ except Exception as e:
358
+ # Unexpected errors during export
359
+ logger.exception(f"Unexpected error exporting patterns: {e}")
360
+ print(f"✗ Export failed: {e}")
361
+ sys.exit(1)
362
+
363
+ print()
364
+
365
+
366
+ def cmd_import(args):
367
+ """Import patterns from file (local dev only - SQLite/JSON).
368
+
369
+ Merges imported patterns into existing pattern library.
370
+
371
+ Args:
372
+ args: Namespace object from argparse with attributes:
373
+ - input (str): Input file path.
374
+ - db (str | None): Target database path (default: .empathy/patterns.db).
375
+
376
+ Returns:
377
+ None: Imports and merges patterns. Exits with code 1 on failure.
378
+ """
379
+ input_file = args.input
380
+ db_path = args.db or ".empathy/patterns.db"
381
+
382
+ print(f"📥 Importing patterns from: {input_file}")
383
+ print("=" * 50)
384
+
385
+ try:
386
+ # Load patterns from input file
387
+ if input_file.endswith(".json"):
388
+ imported_library = PatternPersistence.load_from_json(input_file)
389
+ else:
390
+ imported_library = PatternPersistence.load_from_sqlite(input_file)
391
+
392
+ pattern_count = len(imported_library.patterns)
393
+ print(f" Found {pattern_count} patterns in file")
394
+
395
+ # Load existing library if it exists, otherwise create new one
396
+ try:
397
+ if db_path.endswith(".json"):
398
+ existing_library = PatternPersistence.load_from_json(db_path)
399
+ else:
400
+ existing_library = PatternPersistence.load_from_sqlite(db_path)
401
+
402
+ print(f" Existing library has {len(existing_library.patterns)} patterns")
403
+ except FileNotFoundError:
404
+ existing_library = PatternLibrary()
405
+ print(" Creating new pattern library")
406
+
407
+ # Merge imported patterns into existing library
408
+ for pattern in imported_library.patterns.values():
409
+ existing_library.contribute_pattern(pattern.agent_id, pattern)
410
+
411
+ # Save merged library (SQLite for local dev)
412
+ if db_path.endswith(".json"):
413
+ PatternPersistence.save_to_json(existing_library, db_path)
414
+ else:
415
+ PatternPersistence.save_to_sqlite(existing_library, db_path)
416
+
417
+ print(f" ✓ Imported {pattern_count} patterns")
418
+ print(f" ✓ Total patterns in library: {len(existing_library.patterns)}")
419
+
420
+ except FileNotFoundError:
421
+ print(f"✗ Input file not found: {input_file}")
422
+ sys.exit(1)
423
+ except (ValueError, KeyError) as e:
424
+ # Invalid pattern data format
425
+ print(f"✗ Invalid pattern data: {e}")
426
+ sys.exit(1)
427
+ except (OSError, PermissionError) as e:
428
+ # Cannot read input or write to database
429
+ print(f"✗ File access error: {e}")
430
+ sys.exit(1)
431
+ except Exception as e:
432
+ # Unexpected errors during import
433
+ logger.exception(f"Unexpected error importing patterns: {e}")
434
+ print(f"✗ Import failed: {e}")
435
+ sys.exit(1)
436
+
437
+ print()
@@ -0,0 +1,92 @@
1
+ """Metrics commands for user statistics.
2
+
3
+ Copyright 2025 Smart-AI-Memory
4
+ Licensed under Fair Source License 0.9
5
+ """
6
+
7
+ import sys
8
+
9
+ from empathy_os.logging_config import get_logger
10
+ from empathy_os.metrics.collector import MetricsCollector
11
+ from empathy_os.state_manager import StateManager
12
+
13
+ logger = get_logger(__name__)
14
+
15
+
16
+ def cmd_metrics_show(args):
17
+ """Display metrics for a user.
18
+
19
+ Args:
20
+ args: Namespace object from argparse with attributes:
21
+ - user (str): User ID to retrieve metrics for.
22
+ - db (str): Path to metrics database (default: ./metrics.db).
23
+
24
+ Returns:
25
+ None: Prints user metrics to stdout. Exits with code 1 on failure.
26
+ """
27
+ db_path = args.db
28
+ user_id = args.user
29
+
30
+ logger.info(f"Retrieving metrics for user: {user_id} from {db_path}")
31
+
32
+ collector = MetricsCollector(db_path)
33
+
34
+ try:
35
+ stats = collector.get_user_stats(user_id)
36
+
37
+ logger.info(f"Successfully retrieved metrics for user: {user_id}")
38
+ logger.info(f"=== Metrics for User: {user_id} ===\n")
39
+ logger.info(f"Total Operations: {stats['total_operations']}")
40
+ logger.info(f"Success Rate: {stats['success_rate']:.1%}")
41
+ logger.info(f"Average Response Time: {stats.get('avg_response_time_ms', 0):.0f} ms")
42
+ logger.info(f"\nFirst Use: {stats['first_use']}")
43
+ logger.info(f"Last Use: {stats['last_use']}")
44
+
45
+ logger.info("\nEmpathy Level Usage:")
46
+ logger.info(f" Level 1: {stats.get('level_1_count', 0)} uses")
47
+ logger.info(f" Level 2: {stats.get('level_2_count', 0)} uses")
48
+ logger.info(f" Level 3: {stats.get('level_3_count', 0)} uses")
49
+ logger.info(f" Level 4: {stats.get('level_4_count', 0)} uses")
50
+ logger.info(f" Level 5: {stats.get('level_5_count', 0)} uses")
51
+ except (OSError, FileNotFoundError) as e:
52
+ # Database file not found
53
+ logger.error(f"Metrics database error: {e}")
54
+ logger.error(f"✗ Cannot read metrics database: {e}")
55
+ sys.exit(1)
56
+ except KeyError as e:
57
+ # User not found in database
58
+ logger.error(f"User not found in metrics: {e}")
59
+ logger.error(f"✗ User {user_id} not found: {e}")
60
+ sys.exit(1)
61
+ except Exception as e:
62
+ # Unexpected errors retrieving metrics
63
+ logger.exception(f"Unexpected error retrieving metrics for user {user_id}: {e}")
64
+ logger.error(f"✗ Failed to retrieve metrics: {e}")
65
+ sys.exit(1)
66
+
67
+
68
+ def cmd_state_list(args):
69
+ """List saved user states.
70
+
71
+ Args:
72
+ args: Namespace object from argparse with attributes:
73
+ - state_dir (str): Directory containing state files.
74
+
75
+ Returns:
76
+ None: Prints list of users with saved states.
77
+ """
78
+ state_dir = args.state_dir
79
+
80
+ logger.info(f"Listing saved user states from: {state_dir}")
81
+
82
+ manager = StateManager(state_dir)
83
+ users = manager.list_users()
84
+
85
+ logger.info(f"Found {len(users)} saved user states")
86
+ logger.info(f"=== Saved User States: {state_dir} ===\n")
87
+ logger.info(f"Total users: {len(users)}")
88
+
89
+ if users:
90
+ logger.info("\nUsers:")
91
+ for user_id in users:
92
+ logger.info(f" - {user_id}")