empathy-framework 5.0.3__py3-none-any.whl → 5.1.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 (57) hide show
  1. {empathy_framework-5.0.3.dist-info → empathy_framework-5.1.0.dist-info}/METADATA +259 -142
  2. {empathy_framework-5.0.3.dist-info → empathy_framework-5.1.0.dist-info}/RECORD +56 -26
  3. empathy_framework-5.1.0.dist-info/licenses/LICENSE +201 -0
  4. empathy_framework-5.1.0.dist-info/licenses/LICENSE_CHANGE_ANNOUNCEMENT.md +101 -0
  5. empathy_os/__init__.py +1 -1
  6. empathy_os/cli/commands/batch.py +5 -5
  7. empathy_os/cli/commands/routing.py +1 -1
  8. empathy_os/cli/commands/workflow.py +2 -1
  9. empathy_os/cli/parsers/cache 2.py +65 -0
  10. empathy_os/cli_minimal.py +3 -3
  11. empathy_os/cli_router 2.py +416 -0
  12. empathy_os/dashboard/__init__.py +1 -2
  13. empathy_os/dashboard/app 2.py +512 -0
  14. empathy_os/dashboard/app.py +1 -1
  15. empathy_os/dashboard/simple_server 2.py +403 -0
  16. empathy_os/dashboard/standalone_server 2.py +536 -0
  17. empathy_os/memory/types 2.py +441 -0
  18. empathy_os/models/__init__.py +19 -0
  19. empathy_os/models/adaptive_routing 2.py +437 -0
  20. empathy_os/models/auth_cli.py +444 -0
  21. empathy_os/models/auth_strategy.py +450 -0
  22. empathy_os/project_index/scanner_parallel 2.py +291 -0
  23. empathy_os/telemetry/agent_coordination 2.py +478 -0
  24. empathy_os/telemetry/agent_coordination.py +3 -3
  25. empathy_os/telemetry/agent_tracking 2.py +350 -0
  26. empathy_os/telemetry/agent_tracking.py +1 -2
  27. empathy_os/telemetry/approval_gates 2.py +563 -0
  28. empathy_os/telemetry/event_streaming 2.py +405 -0
  29. empathy_os/telemetry/event_streaming.py +3 -3
  30. empathy_os/telemetry/feedback_loop 2.py +557 -0
  31. empathy_os/telemetry/feedback_loop.py +1 -1
  32. empathy_os/vscode_bridge 2.py +173 -0
  33. empathy_os/workflows/__init__.py +8 -0
  34. empathy_os/workflows/autonomous_test_gen.py +569 -0
  35. empathy_os/workflows/bug_predict.py +45 -0
  36. empathy_os/workflows/code_review.py +92 -22
  37. empathy_os/workflows/document_gen.py +594 -62
  38. empathy_os/workflows/llm_base.py +363 -0
  39. empathy_os/workflows/perf_audit.py +69 -0
  40. empathy_os/workflows/progressive/README 2.md +454 -0
  41. empathy_os/workflows/progressive/__init__ 2.py +92 -0
  42. empathy_os/workflows/progressive/cli 2.py +242 -0
  43. empathy_os/workflows/progressive/core 2.py +488 -0
  44. empathy_os/workflows/progressive/orchestrator 2.py +701 -0
  45. empathy_os/workflows/progressive/reports 2.py +528 -0
  46. empathy_os/workflows/progressive/telemetry 2.py +280 -0
  47. empathy_os/workflows/progressive/test_gen 2.py +514 -0
  48. empathy_os/workflows/progressive/workflow 2.py +628 -0
  49. empathy_os/workflows/release_prep.py +54 -0
  50. empathy_os/workflows/security_audit.py +154 -79
  51. empathy_os/workflows/test_gen.py +60 -0
  52. empathy_os/workflows/test_gen_behavioral.py +477 -0
  53. empathy_os/workflows/test_gen_parallel.py +341 -0
  54. empathy_framework-5.0.3.dist-info/licenses/LICENSE +0 -139
  55. {empathy_framework-5.0.3.dist-info → empathy_framework-5.1.0.dist-info}/WHEEL +0 -0
  56. {empathy_framework-5.0.3.dist-info → empathy_framework-5.1.0.dist-info}/entry_points.txt +0 -0
  57. {empathy_framework-5.0.3.dist-info → empathy_framework-5.1.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,65 @@
1
+ """Argument parser for cache commands.
2
+
3
+ Copyright 2025 Smart-AI-Memory
4
+ Licensed under Fair Source License 0.9
5
+ """
6
+
7
+
8
+ def register_parsers(subparsers):
9
+ """Register cache command parsers.
10
+
11
+ Args:
12
+ subparsers: Subparser object from main argument parser
13
+
14
+ Returns:
15
+ None: Adds cache subparser with stats and clear subcommands
16
+ """
17
+ from ..commands.cache import cmd_cache_clear, cmd_cache_stats
18
+ # Main cache command
19
+ cache_parser = subparsers.add_parser(
20
+ "cache",
21
+ help="Cache monitoring and management",
22
+ description="Monitor prompt caching performance and cost savings",
23
+ )
24
+
25
+ # Cache subcommands
26
+ cache_subparsers = cache_parser.add_subparsers(dest="cache_command", required=True)
27
+
28
+ # cache stats command
29
+ stats_parser = cache_subparsers.add_parser(
30
+ "stats",
31
+ help="Show cache performance statistics",
32
+ description="Display prompt caching metrics including hit rate and cost savings",
33
+ )
34
+
35
+ stats_parser.add_argument(
36
+ "--days",
37
+ type=int,
38
+ default=7,
39
+ help="Number of days to analyze (default: 7)",
40
+ )
41
+
42
+ stats_parser.add_argument(
43
+ "--format",
44
+ choices=["table", "json"],
45
+ default="table",
46
+ help="Output format (default: table)",
47
+ )
48
+
49
+ stats_parser.add_argument(
50
+ "--verbose",
51
+ "-v",
52
+ action="store_true",
53
+ help="Show detailed token metrics",
54
+ )
55
+
56
+ stats_parser.set_defaults(func=cmd_cache_stats)
57
+
58
+ # cache clear command (placeholder)
59
+ clear_parser = cache_subparsers.add_parser(
60
+ "clear",
61
+ help="Clear cache (note: Anthropic cache is server-side with 5min TTL)",
62
+ description="Information about cache clearing",
63
+ )
64
+
65
+ clear_parser.set_defaults(func=cmd_cache_clear)
empathy_os/cli_minimal.py CHANGED
@@ -497,11 +497,11 @@ def cmd_telemetry_routing_check(args: Namespace) -> int:
497
497
  print(f"\n Workflow: {workflow}")
498
498
 
499
499
  if should_upgrade:
500
- print(f" Status: ⚠️ UPGRADE RECOMMENDED")
500
+ print(" Status: ⚠️ UPGRADE RECOMMENDED")
501
501
  print(f" Reason: {reason}")
502
502
  print("\n Action: Consider upgrading from CHEAP → CAPABLE or CAPABLE → PREMIUM")
503
503
  else:
504
- print(f" Status: ✅ Performing well")
504
+ print(" Status: ✅ Performing well")
505
505
  print(f" Reason: {reason}")
506
506
 
507
507
  else:
@@ -818,7 +818,7 @@ def cmd_dashboard_start(args: Namespace) -> int:
818
818
  host = args.host
819
819
  port = args.port
820
820
 
821
- print(f"\n🚀 Starting Agent Coordination Dashboard...")
821
+ print("\n🚀 Starting Agent Coordination Dashboard...")
822
822
  print(f"📊 Dashboard will be available at: http://{host}:{port}\n")
823
823
  print("💡 Make sure Redis is populated with test data:")
824
824
  print(" python scripts/populate_redis_direct.py\n")
@@ -0,0 +1,416 @@
1
+ """Hybrid CLI Router - Skills + Natural Language
2
+
3
+ Routes keywords and natural language to Claude Code skill invocations:
4
+ - Skills: /dev, /testing, /workflows (Claude Code Skill tool)
5
+ - Keywords: commit, test, security (maps to skills)
6
+ - Natural language: "commit my changes" (SmartRouter classification)
7
+
8
+ Copyright 2025 Smart-AI-Memory
9
+ Licensed under Fair Source License 0.9
10
+ """
11
+
12
+ from dataclasses import dataclass
13
+ from pathlib import Path
14
+ from typing import Any
15
+
16
+ import yaml
17
+
18
+ from empathy_os.routing import SmartRouter
19
+
20
+
21
+ @dataclass
22
+ class RoutingPreference:
23
+ """User's learned routing preferences."""
24
+
25
+ keyword: str
26
+ skill: str
27
+ args: str = ""
28
+ usage_count: int = 0
29
+ confidence: float = 1.0
30
+
31
+
32
+ class HybridRouter:
33
+ """Routes user input to Claude Code skill invocations.
34
+
35
+ Supports three input modes:
36
+ 1. Skills: /dev, /testing (returns skill invocation metadata)
37
+ 2. Keywords: commit, test (maps to skill invocations)
38
+ 3. Natural language: "I need to commit" (uses SmartRouter)
39
+
40
+ Example:
41
+ router = HybridRouter()
42
+
43
+ # Skill invocation
44
+ result = await router.route("/dev")
45
+ # → {type: "skill", skill: "dev", args: "", instruction: "Use Skill tool..."}
46
+
47
+ # Keyword to skill
48
+ result = await router.route("commit")
49
+ # → {type: "skill", skill: "dev", args: "commit", instruction: "Use Skill tool..."}
50
+
51
+ # Natural language
52
+ result = await router.route("I want to commit my changes")
53
+ # → {type: "skill", skill: "dev", args: "commit", reasoning: "..."}
54
+ """
55
+
56
+ def __init__(self, preferences_path: str | None = None):
57
+ """Initialize hybrid router.
58
+
59
+ Args:
60
+ preferences_path: Path to user preferences YAML
61
+ Default: .empathy/routing_preferences.yaml
62
+ """
63
+ self.preferences_path = Path(
64
+ preferences_path or Path.home() / ".empathy" / "routing_preferences.yaml"
65
+ )
66
+ self.smart_router = SmartRouter()
67
+ self.preferences: dict[str, RoutingPreference] = {}
68
+
69
+ # Keyword to skill mapping: keyword → (skill_name, args)
70
+ self._keyword_to_skill = {
71
+ # Dev commands → /dev skill
72
+ "commit": ("dev", "commit"),
73
+ "review": ("dev", "review"),
74
+ "review-pr": ("dev", "review"),
75
+ "refactor": ("dev", "refactor"),
76
+ "perf": ("dev", "perf-audit"),
77
+ "perf-audit": ("dev", "perf-audit"),
78
+ "debug": ("dev", "debug"),
79
+ # Testing commands → /testing skill
80
+ "test": ("testing", "run"),
81
+ "tests": ("testing", "run"),
82
+ "coverage": ("testing", "coverage"),
83
+ "generate-tests": ("testing", "gen"),
84
+ "test-gen": ("testing", "gen"),
85
+ "benchmark": ("testing", "benchmark"),
86
+ # Learning commands → /learning skill
87
+ "evaluate": ("learning", "evaluate"),
88
+ "patterns": ("learning", "patterns"),
89
+ "improve": ("learning", "improve"),
90
+ # Workflow commands → /workflows skill
91
+ "security": ("workflows", "run security-audit"),
92
+ "security-audit": ("workflows", "run security-audit"),
93
+ "bug-predict": ("workflows", "run bug-predict"),
94
+ "bugs": ("workflows", "run bug-predict"),
95
+ "perf-workflow": ("workflows", "run perf-audit"),
96
+ # Context commands → /context skill
97
+ "status": ("context", "status"),
98
+ "memory": ("context", "memory"),
99
+ "state": ("context", "state"),
100
+ # Doc commands → /docs skill
101
+ "explain": ("docs", "explain"),
102
+ "document": ("docs", "generate"),
103
+ "overview": ("docs", "overview"),
104
+ # Plan commands → /plan skill
105
+ "plan": ("plan", ""),
106
+ "tdd": ("plan", "tdd"),
107
+ # Release commands → /release skill
108
+ "release": ("release", "prep"),
109
+ "ship": ("release", "prep"),
110
+ }
111
+
112
+ # Hub descriptions for disambiguation
113
+ self._hub_descriptions = {
114
+ "dev": "Development tools (commits, reviews, refactoring)",
115
+ "testing": "Test generation and coverage analysis",
116
+ "learning": "Session evaluation and pattern learning",
117
+ "workflows": "AI-powered workflows (security, bugs, performance)",
118
+ "context": "Memory and state management",
119
+ "docs": "Documentation generation",
120
+ "plan": "Development planning and architecture",
121
+ "release": "Release preparation and publishing",
122
+ "utilities": "Utility tools (profiling, dependencies)",
123
+ }
124
+
125
+ self._load_preferences()
126
+
127
+ def _load_preferences(self) -> None:
128
+ """Load user routing preferences from disk."""
129
+ if not self.preferences_path.exists():
130
+ return
131
+
132
+ try:
133
+ with open(self.preferences_path) as f:
134
+ data = yaml.safe_load(f) or {}
135
+
136
+ for keyword, pref_data in data.get("preferences", {}).items():
137
+ # Handle backward compatibility: old format had "slash_command"
138
+ if "slash_command" in pref_data:
139
+ # Migrate old format: "/dev commit" → skill="dev", args="commit"
140
+ slash_cmd = pref_data["slash_command"].lstrip("/")
141
+ parts = slash_cmd.split(maxsplit=1)
142
+ skill = parts[0] if parts else "help"
143
+ args = parts[1] if len(parts) > 1 else ""
144
+ else:
145
+ # New format
146
+ skill = pref_data["skill"]
147
+ args = pref_data.get("args", "")
148
+
149
+ self.preferences[keyword] = RoutingPreference(
150
+ keyword=keyword,
151
+ skill=skill,
152
+ args=args,
153
+ usage_count=pref_data.get("usage_count", 0),
154
+ confidence=pref_data.get("confidence", 1.0),
155
+ )
156
+ except Exception as e:
157
+ print(f"Warning: Could not load routing preferences: {e}")
158
+
159
+ def _save_preferences(self) -> None:
160
+ """Save user routing preferences to disk."""
161
+ self.preferences_path.parent.mkdir(parents=True, exist_ok=True)
162
+
163
+ data = {
164
+ "preferences": {
165
+ pref.keyword: {
166
+ "skill": pref.skill,
167
+ "args": pref.args,
168
+ "usage_count": pref.usage_count,
169
+ "confidence": pref.confidence,
170
+ }
171
+ for pref in self.preferences.values()
172
+ }
173
+ }
174
+
175
+ with open(self.preferences_path, "w") as f:
176
+ yaml.dump(data, f, default_flow_style=False)
177
+
178
+ async def route(
179
+ self, user_input: str, context: dict[str, Any] | None = None
180
+ ) -> dict[str, Any]:
181
+ """Route user input to appropriate command or workflow.
182
+
183
+ Args:
184
+ user_input: User's input (slash command, keyword, or natural language)
185
+ context: Optional context (current file, project info, etc.)
186
+
187
+ Returns:
188
+ Routing result with type, command/workflow, and metadata
189
+ """
190
+ user_input = user_input.strip()
191
+
192
+ # Level 1: Slash command (direct execution)
193
+ if user_input.startswith("/"):
194
+ return self._route_slash_command(user_input)
195
+
196
+ # Level 2: Single word or known command (inference)
197
+ words = user_input.split()
198
+ if len(words) <= 2:
199
+ inferred = self._infer_command(user_input)
200
+ if inferred:
201
+ return inferred
202
+
203
+ # Level 3: Natural language (SmartRouter)
204
+ return await self._route_natural_language(user_input, context)
205
+
206
+ def _route_slash_command(self, command: str) -> dict[str, Any]:
207
+ """Route slash command to skill invocation.
208
+
209
+ Args:
210
+ command: Slash command like "/dev" or "/dev commit"
211
+
212
+ Returns:
213
+ Skill invocation instructions
214
+ """
215
+ parts = command[1:].split(maxsplit=1) # Remove leading /
216
+ skill = parts[0] if parts else "help"
217
+ args = parts[1] if len(parts) > 1 else ""
218
+
219
+ return {
220
+ "type": "skill",
221
+ "skill": skill,
222
+ "args": args,
223
+ "original": command,
224
+ "confidence": 1.0,
225
+ "instruction": f"Use Skill tool with skill='{skill}'" + (f", args='{args}'" if args else ""),
226
+ }
227
+
228
+ def _infer_command(self, keyword: str) -> dict[str, Any] | None:
229
+ """Infer skill invocation from keyword or short phrase.
230
+
231
+ Args:
232
+ keyword: Single word or short phrase
233
+
234
+ Returns:
235
+ Skill invocation instructions if inference successful, None otherwise
236
+ """
237
+ keyword_lower = keyword.lower().strip()
238
+
239
+ # Check learned preferences first
240
+ if keyword_lower in self.preferences:
241
+ pref = self.preferences[keyword_lower]
242
+
243
+ # Update usage count
244
+ pref.usage_count += 1
245
+ self._save_preferences()
246
+
247
+ return {
248
+ "type": "skill",
249
+ "skill": pref.skill,
250
+ "args": pref.args,
251
+ "original": keyword,
252
+ "confidence": pref.confidence,
253
+ "source": "learned",
254
+ "instruction": f"Use Skill tool with skill='{pref.skill}'" + (f", args='{pref.args}'" if pref.args else ""),
255
+ }
256
+
257
+ # Check built-in keyword map
258
+ if keyword_lower in self._keyword_to_skill:
259
+ skill, args = self._keyword_to_skill[keyword_lower]
260
+ return {
261
+ "type": "skill",
262
+ "skill": skill,
263
+ "args": args,
264
+ "original": keyword,
265
+ "confidence": 0.9,
266
+ "source": "builtin",
267
+ "instruction": f"Use Skill tool with skill='{skill}'" + (f", args='{args}'" if args else ""),
268
+ }
269
+
270
+ # Check for hub names (show hub menu)
271
+ if keyword_lower in self._hub_descriptions:
272
+ return {
273
+ "type": "skill",
274
+ "skill": keyword_lower,
275
+ "args": "",
276
+ "original": keyword,
277
+ "confidence": 1.0,
278
+ "source": "hub",
279
+ "instruction": f"Use Skill tool with skill='{keyword_lower}'",
280
+ }
281
+
282
+ return None
283
+
284
+ async def _route_natural_language(
285
+ self, text: str, context: dict[str, Any] | None = None
286
+ ) -> dict[str, Any]:
287
+ """Route natural language input using SmartRouter.
288
+
289
+ Args:
290
+ text: Natural language input
291
+ context: Optional context
292
+
293
+ Returns:
294
+ Skill invocation instructions based on SmartRouter decision
295
+ """
296
+ # Use SmartRouter for classification
297
+ decision = await self.smart_router.route(text, context)
298
+
299
+ # Map workflow to skill invocation
300
+ skill, args = self._workflow_to_skill(decision.primary_workflow)
301
+
302
+ return {
303
+ "type": "skill",
304
+ "skill": skill,
305
+ "args": args,
306
+ "workflow": decision.primary_workflow,
307
+ "secondary_workflows": decision.secondary_workflows,
308
+ "confidence": decision.confidence,
309
+ "reasoning": decision.reasoning,
310
+ "original": text,
311
+ "source": "natural_language",
312
+ "instruction": f"Use Skill tool with skill='{skill}'" + (f", args='{args}'" if args else ""),
313
+ }
314
+
315
+ def _workflow_to_skill(self, workflow: str) -> tuple[str, str]:
316
+ """Map workflow name to skill invocation.
317
+
318
+ Args:
319
+ workflow: Workflow name (e.g., "security-audit")
320
+
321
+ Returns:
322
+ Tuple of (skill_name, args)
323
+ """
324
+ # Workflow to skill mapping
325
+ workflow_map = {
326
+ "security-audit": ("workflows", "run security-audit"),
327
+ "bug-predict": ("workflows", "run bug-predict"),
328
+ "code-review": ("dev", "review"),
329
+ "test-gen": ("testing", "gen"),
330
+ "perf-audit": ("workflows", "run perf-audit"),
331
+ "commit": ("dev", "commit"),
332
+ "refactor": ("dev", "refactor"),
333
+ "debug": ("dev", "debug"),
334
+ "explain": ("docs", "explain"),
335
+ "plan": ("plan", ""),
336
+ }
337
+
338
+ return workflow_map.get(workflow, ("workflows", f"run {workflow}"))
339
+
340
+ def learn_preference(self, keyword: str, skill: str, args: str = "") -> None:
341
+ """Learn user's routing preference.
342
+
343
+ Args:
344
+ keyword: Keyword user typed
345
+ skill: Skill name that was invoked
346
+ args: Arguments passed to skill
347
+ """
348
+ if keyword in self.preferences:
349
+ pref = self.preferences[keyword]
350
+ pref.usage_count += 1
351
+ # Increase confidence with repeated usage
352
+ pref.confidence = min(1.0, pref.confidence + 0.05)
353
+ else:
354
+ self.preferences[keyword] = RoutingPreference(
355
+ keyword=keyword,
356
+ skill=skill,
357
+ args=args,
358
+ usage_count=1,
359
+ confidence=0.8,
360
+ )
361
+
362
+ self._save_preferences()
363
+
364
+ def get_suggestions(self, partial: str) -> list[str]:
365
+ """Get command suggestions based on partial input.
366
+
367
+ Args:
368
+ partial: Partial command input
369
+
370
+ Returns:
371
+ List of suggested keywords and skills
372
+ """
373
+ suggestions = []
374
+ partial_lower = partial.lower()
375
+
376
+ # Suggest keywords
377
+ for keyword in self._keyword_to_skill.keys():
378
+ if partial_lower in keyword:
379
+ skill, args = self._keyword_to_skill[keyword]
380
+ suggestions.append(f"{keyword} → /{skill} {args}".strip())
381
+
382
+ # Suggest learned preferences
383
+ for pref in self.preferences.values():
384
+ if partial_lower in pref.keyword.lower():
385
+ suggestions.append(f"{pref.keyword} → /{pref.skill} {pref.args}".strip())
386
+
387
+ return suggestions[:5] # Top 5 suggestions
388
+
389
+
390
+ # Convenience functions
391
+ async def route_user_input(
392
+ user_input: str, context: dict[str, Any] | None = None
393
+ ) -> dict[str, Any]:
394
+ """Quick routing helper.
395
+
396
+ Args:
397
+ user_input: User's input
398
+ context: Optional context
399
+
400
+ Returns:
401
+ Routing result
402
+ """
403
+ router = HybridRouter()
404
+ return await router.route(user_input, context)
405
+
406
+
407
+ def is_slash_command(text: str) -> bool:
408
+ """Check if text is a slash command.
409
+
410
+ Args:
411
+ text: Input text
412
+
413
+ Returns:
414
+ True if slash command, False otherwise
415
+ """
416
+ return text.strip().startswith("/")
@@ -27,10 +27,9 @@ Licensed under Fair Source License 0.9
27
27
  """
28
28
 
29
29
  # Standalone server - reads directly from Redis
30
- from .standalone_server import run_standalone_dashboard
31
-
32
30
  # Simple server - uses telemetry API classes
33
31
  from .simple_server import run_simple_dashboard
32
+ from .standalone_server import run_standalone_dashboard
34
33
 
35
34
  # Optional FastAPI version (requires dependencies)
36
35
  try: