empathy-framework 4.9.0__py3-none-any.whl → 5.0.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.
- {empathy_framework-4.9.0.dist-info → empathy_framework-5.0.0.dist-info}/METADATA +64 -25
- {empathy_framework-4.9.0.dist-info → empathy_framework-5.0.0.dist-info}/RECORD +47 -26
- empathy_os/__init__.py +2 -2
- empathy_os/cache/hash_only.py +6 -3
- empathy_os/cache/hybrid.py +6 -3
- empathy_os/cli_legacy.py +27 -1
- empathy_os/cli_minimal.py +512 -15
- empathy_os/cli_router.py +145 -113
- empathy_os/cli_unified.py +25 -0
- empathy_os/dashboard/__init__.py +42 -0
- empathy_os/dashboard/app.py +512 -0
- empathy_os/dashboard/simple_server.py +403 -0
- empathy_os/dashboard/standalone_server.py +536 -0
- empathy_os/memory/__init__.py +19 -5
- empathy_os/memory/short_term.py +4 -70
- empathy_os/memory/types.py +2 -2
- empathy_os/models/__init__.py +3 -0
- empathy_os/models/adaptive_routing.py +437 -0
- empathy_os/models/registry.py +4 -4
- empathy_os/socratic/ab_testing.py +1 -1
- empathy_os/telemetry/__init__.py +29 -1
- empathy_os/telemetry/agent_coordination.py +478 -0
- empathy_os/telemetry/agent_tracking.py +350 -0
- empathy_os/telemetry/approval_gates.py +563 -0
- empathy_os/telemetry/event_streaming.py +405 -0
- empathy_os/telemetry/feedback_loop.py +557 -0
- empathy_os/vscode_bridge 2.py +173 -0
- empathy_os/workflows/__init__.py +4 -4
- empathy_os/workflows/base.py +495 -43
- empathy_os/workflows/history.py +3 -5
- empathy_os/workflows/output.py +410 -0
- empathy_os/workflows/progress.py +324 -22
- empathy_os/workflows/progressive/README 2.md +454 -0
- empathy_os/workflows/progressive/__init__ 2.py +92 -0
- empathy_os/workflows/progressive/cli 2.py +242 -0
- empathy_os/workflows/progressive/core 2.py +488 -0
- empathy_os/workflows/progressive/orchestrator 2.py +701 -0
- empathy_os/workflows/progressive/reports 2.py +528 -0
- empathy_os/workflows/progressive/telemetry 2.py +280 -0
- empathy_os/workflows/progressive/test_gen 2.py +514 -0
- empathy_os/workflows/progressive/workflow 2.py +628 -0
- empathy_os/workflows/routing.py +5 -0
- empathy_os/workflows/security_audit.py +189 -0
- {empathy_framework-4.9.0.dist-info → empathy_framework-5.0.0.dist-info}/WHEEL +0 -0
- {empathy_framework-4.9.0.dist-info → empathy_framework-5.0.0.dist-info}/entry_points.txt +0 -0
- {empathy_framework-4.9.0.dist-info → empathy_framework-5.0.0.dist-info}/licenses/LICENSE +0 -0
- {empathy_framework-4.9.0.dist-info → empathy_framework-5.0.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
"""Unified output formatting for workflows.
|
|
2
|
+
|
|
3
|
+
Provides consistent Rich-based output components for workflow results:
|
|
4
|
+
- WorkflowReport: Main report container with sections
|
|
5
|
+
- FindingsTable: Render findings as Rich Table or plain text
|
|
6
|
+
- MetricsPanel: Color-coded score display
|
|
7
|
+
- ReportSection: Individual report sections
|
|
8
|
+
|
|
9
|
+
Supports graceful fallback to plain text when Rich is unavailable.
|
|
10
|
+
|
|
11
|
+
Copyright 2025 Smart-AI-Memory
|
|
12
|
+
Licensed under Fair Source License 0.9
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from dataclasses import dataclass, field
|
|
18
|
+
from typing import TYPE_CHECKING, Any
|
|
19
|
+
|
|
20
|
+
# Rich imports with fallback
|
|
21
|
+
try:
|
|
22
|
+
from rich.console import Console
|
|
23
|
+
from rich.panel import Panel
|
|
24
|
+
from rich.table import Table
|
|
25
|
+
from rich.text import Text
|
|
26
|
+
|
|
27
|
+
RICH_AVAILABLE = True
|
|
28
|
+
except ImportError:
|
|
29
|
+
RICH_AVAILABLE = False
|
|
30
|
+
Console = None # type: ignore
|
|
31
|
+
Panel = None # type: ignore
|
|
32
|
+
Table = None # type: ignore
|
|
33
|
+
Text = None # type: ignore
|
|
34
|
+
|
|
35
|
+
if TYPE_CHECKING:
|
|
36
|
+
from rich.console import Console as ConsoleType
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# =============================================================================
|
|
40
|
+
# DATA CLASSES
|
|
41
|
+
# =============================================================================
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass
|
|
45
|
+
class Finding:
|
|
46
|
+
"""Individual finding from a workflow."""
|
|
47
|
+
|
|
48
|
+
severity: str # "high", "medium", "low", "info"
|
|
49
|
+
file: str
|
|
50
|
+
line: int | None = None
|
|
51
|
+
message: str = ""
|
|
52
|
+
code: str | None = None
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def severity_icon(self) -> str:
|
|
56
|
+
"""Get icon for severity level."""
|
|
57
|
+
icons = {
|
|
58
|
+
"high": "[red]:x:[/red]" if RICH_AVAILABLE else "X",
|
|
59
|
+
"medium": "[yellow]:warning:[/yellow]" if RICH_AVAILABLE else "!",
|
|
60
|
+
"low": "[blue]:information:[/blue]" if RICH_AVAILABLE else "i",
|
|
61
|
+
"info": "[dim]o[/dim]" if RICH_AVAILABLE else "o",
|
|
62
|
+
}
|
|
63
|
+
return icons.get(self.severity.lower(), "o")
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def location(self) -> str:
|
|
67
|
+
"""Get file:line location string."""
|
|
68
|
+
if self.line:
|
|
69
|
+
return f"{self.file}:{self.line}"
|
|
70
|
+
return self.file
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@dataclass
|
|
74
|
+
class ReportSection:
|
|
75
|
+
"""Individual section of a workflow report."""
|
|
76
|
+
|
|
77
|
+
title: str
|
|
78
|
+
content: Any # str, list[Finding], dict, or Rich renderable
|
|
79
|
+
collapsed: bool = False
|
|
80
|
+
style: str = "default" # "default", "success", "warning", "error"
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@dataclass
|
|
84
|
+
class WorkflowReport:
|
|
85
|
+
"""Main workflow report container."""
|
|
86
|
+
|
|
87
|
+
title: str
|
|
88
|
+
summary: str = ""
|
|
89
|
+
sections: list[ReportSection] = field(default_factory=list)
|
|
90
|
+
score: int | None = None
|
|
91
|
+
level: str = "info" # "info", "success", "warning", "error"
|
|
92
|
+
metadata: dict[str, Any] = field(default_factory=dict)
|
|
93
|
+
|
|
94
|
+
def add_section(
|
|
95
|
+
self,
|
|
96
|
+
title: str,
|
|
97
|
+
content: Any,
|
|
98
|
+
collapsed: bool = False,
|
|
99
|
+
style: str = "default",
|
|
100
|
+
) -> None:
|
|
101
|
+
"""Add a section to the report."""
|
|
102
|
+
self.sections.append(
|
|
103
|
+
ReportSection(title=title, content=content, collapsed=collapsed, style=style)
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
def render(self, console: ConsoleType | None = None, use_rich: bool = True) -> str:
|
|
107
|
+
"""Render the report.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
console: Rich Console instance (optional)
|
|
111
|
+
use_rich: Whether to use Rich formatting
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
Rendered report as string (for plain text) or prints to console (for Rich)
|
|
115
|
+
"""
|
|
116
|
+
if use_rich and RICH_AVAILABLE and console is not None:
|
|
117
|
+
self._render_rich(console)
|
|
118
|
+
return ""
|
|
119
|
+
return self._render_plain()
|
|
120
|
+
|
|
121
|
+
def _render_rich(self, console: ConsoleType) -> None:
|
|
122
|
+
"""Render report using Rich."""
|
|
123
|
+
# Header with score
|
|
124
|
+
header_parts = [f"[bold]{self.title}[/bold]"]
|
|
125
|
+
if self.score is not None:
|
|
126
|
+
score_panel = MetricsPanel.render_score(self.score)
|
|
127
|
+
console.print(score_panel)
|
|
128
|
+
|
|
129
|
+
if self.summary:
|
|
130
|
+
console.print(f"\n{self.summary}\n")
|
|
131
|
+
|
|
132
|
+
# Sections
|
|
133
|
+
for section in self.sections:
|
|
134
|
+
self._render_section_rich(console, section)
|
|
135
|
+
|
|
136
|
+
def _render_section_rich(self, console: ConsoleType, section: ReportSection) -> None:
|
|
137
|
+
"""Render a single section using Rich."""
|
|
138
|
+
border_style = {
|
|
139
|
+
"success": "green",
|
|
140
|
+
"warning": "yellow",
|
|
141
|
+
"error": "red",
|
|
142
|
+
"default": "blue",
|
|
143
|
+
}.get(section.style, "blue")
|
|
144
|
+
|
|
145
|
+
if isinstance(section.content, str):
|
|
146
|
+
console.print(
|
|
147
|
+
Panel(section.content, title=section.title, border_style=border_style)
|
|
148
|
+
)
|
|
149
|
+
elif isinstance(section.content, list) and all(
|
|
150
|
+
isinstance(f, Finding) for f in section.content
|
|
151
|
+
):
|
|
152
|
+
table = FindingsTable(section.content).to_rich_table()
|
|
153
|
+
console.print(Panel(table, title=section.title, border_style=border_style))
|
|
154
|
+
elif isinstance(section.content, dict):
|
|
155
|
+
# Render dict as key-value table
|
|
156
|
+
table = Table(show_header=False, box=None)
|
|
157
|
+
table.add_column("Key", style="cyan")
|
|
158
|
+
table.add_column("Value")
|
|
159
|
+
for key, value in section.content.items():
|
|
160
|
+
table.add_row(str(key), str(value))
|
|
161
|
+
console.print(Panel(table, title=section.title, border_style=border_style))
|
|
162
|
+
else:
|
|
163
|
+
# Try to print directly (might be a Rich renderable)
|
|
164
|
+
try:
|
|
165
|
+
console.print(
|
|
166
|
+
Panel(section.content, title=section.title, border_style=border_style)
|
|
167
|
+
)
|
|
168
|
+
except Exception: # noqa: BLE001
|
|
169
|
+
# INTENTIONAL: Graceful fallback for unknown content types
|
|
170
|
+
console.print(f"\n[bold]{section.title}[/bold]")
|
|
171
|
+
console.print(str(section.content))
|
|
172
|
+
|
|
173
|
+
def _render_plain(self) -> str:
|
|
174
|
+
"""Render report as plain text."""
|
|
175
|
+
lines = []
|
|
176
|
+
separator = "=" * 60
|
|
177
|
+
|
|
178
|
+
# Header
|
|
179
|
+
lines.append(separator)
|
|
180
|
+
lines.append(self.title.upper())
|
|
181
|
+
lines.append(separator)
|
|
182
|
+
|
|
183
|
+
if self.score is not None:
|
|
184
|
+
level = MetricsPanel.get_level(self.score)
|
|
185
|
+
lines.append(f"Score: {self.score}/100 ({level.upper()})")
|
|
186
|
+
lines.append("")
|
|
187
|
+
|
|
188
|
+
if self.summary:
|
|
189
|
+
lines.append(self.summary)
|
|
190
|
+
lines.append("")
|
|
191
|
+
|
|
192
|
+
# Sections
|
|
193
|
+
for section in self.sections:
|
|
194
|
+
lines.append("-" * 60)
|
|
195
|
+
lines.append(section.title.upper())
|
|
196
|
+
lines.append("-" * 60)
|
|
197
|
+
|
|
198
|
+
if isinstance(section.content, str):
|
|
199
|
+
lines.append(section.content)
|
|
200
|
+
elif isinstance(section.content, list) and all(
|
|
201
|
+
isinstance(f, Finding) for f in section.content
|
|
202
|
+
):
|
|
203
|
+
lines.append(FindingsTable(section.content).to_plain())
|
|
204
|
+
elif isinstance(section.content, dict):
|
|
205
|
+
for key, value in section.content.items():
|
|
206
|
+
lines.append(f" {key}: {value}")
|
|
207
|
+
else:
|
|
208
|
+
lines.append(str(section.content))
|
|
209
|
+
|
|
210
|
+
lines.append("")
|
|
211
|
+
|
|
212
|
+
lines.append(separator)
|
|
213
|
+
return "\n".join(lines)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
# =============================================================================
|
|
217
|
+
# FINDINGS TABLE
|
|
218
|
+
# =============================================================================
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
class FindingsTable:
|
|
222
|
+
"""Render findings as Rich Table or plain text."""
|
|
223
|
+
|
|
224
|
+
def __init__(self, findings: list[Finding]) -> None:
|
|
225
|
+
"""Initialize with list of findings."""
|
|
226
|
+
self.findings = findings
|
|
227
|
+
|
|
228
|
+
def to_rich_table(self) -> Table:
|
|
229
|
+
"""Convert findings to Rich Table."""
|
|
230
|
+
table = Table(show_header=True, header_style="bold magenta")
|
|
231
|
+
table.add_column("Severity", style="bold", width=8)
|
|
232
|
+
table.add_column("Location", style="cyan")
|
|
233
|
+
table.add_column("Message")
|
|
234
|
+
|
|
235
|
+
for finding in self.findings:
|
|
236
|
+
severity_style = {
|
|
237
|
+
"high": "red",
|
|
238
|
+
"medium": "yellow",
|
|
239
|
+
"low": "blue",
|
|
240
|
+
"info": "dim",
|
|
241
|
+
}.get(finding.severity.lower(), "white")
|
|
242
|
+
|
|
243
|
+
table.add_row(
|
|
244
|
+
Text(finding.severity.upper(), style=severity_style),
|
|
245
|
+
finding.location,
|
|
246
|
+
finding.message,
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
return table
|
|
250
|
+
|
|
251
|
+
def to_plain(self) -> str:
|
|
252
|
+
"""Convert findings to plain text."""
|
|
253
|
+
if not self.findings:
|
|
254
|
+
return " No findings."
|
|
255
|
+
|
|
256
|
+
lines = []
|
|
257
|
+
for finding in self.findings:
|
|
258
|
+
lines.append(f" [{finding.severity.upper()}] {finding.location}")
|
|
259
|
+
if finding.message:
|
|
260
|
+
lines.append(f" {finding.message}")
|
|
261
|
+
|
|
262
|
+
return "\n".join(lines)
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
# =============================================================================
|
|
266
|
+
# METRICS PANEL
|
|
267
|
+
# =============================================================================
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
class MetricsPanel:
|
|
271
|
+
"""Display score with color-coded indicator."""
|
|
272
|
+
|
|
273
|
+
@staticmethod
|
|
274
|
+
def get_level(score: int) -> str:
|
|
275
|
+
"""Get level name for score."""
|
|
276
|
+
if score >= 85:
|
|
277
|
+
return "excellent"
|
|
278
|
+
elif score >= 70:
|
|
279
|
+
return "good"
|
|
280
|
+
elif score >= 50:
|
|
281
|
+
return "needs work"
|
|
282
|
+
return "critical"
|
|
283
|
+
|
|
284
|
+
@staticmethod
|
|
285
|
+
def get_style(score: int) -> str:
|
|
286
|
+
"""Get Rich style for score."""
|
|
287
|
+
if score >= 85:
|
|
288
|
+
return "green"
|
|
289
|
+
elif score >= 70:
|
|
290
|
+
return "yellow"
|
|
291
|
+
elif score >= 50:
|
|
292
|
+
return "orange1"
|
|
293
|
+
return "red"
|
|
294
|
+
|
|
295
|
+
@staticmethod
|
|
296
|
+
def get_icon(score: int) -> str:
|
|
297
|
+
"""Get icon for score."""
|
|
298
|
+
if score >= 85:
|
|
299
|
+
return "[green]:heavy_check_mark:[/green]"
|
|
300
|
+
elif score >= 70:
|
|
301
|
+
return "[yellow]:large_yellow_circle:[/yellow]"
|
|
302
|
+
elif score >= 50:
|
|
303
|
+
return "[orange1]:warning:[/orange1]"
|
|
304
|
+
return "[red]:x:[/red]"
|
|
305
|
+
|
|
306
|
+
@staticmethod
|
|
307
|
+
def get_plain_icon(score: int) -> str:
|
|
308
|
+
"""Get plain text icon for score."""
|
|
309
|
+
if score >= 85:
|
|
310
|
+
return "[OK]"
|
|
311
|
+
elif score >= 70:
|
|
312
|
+
return "[--]"
|
|
313
|
+
elif score >= 50:
|
|
314
|
+
return "[!!]"
|
|
315
|
+
return "[XX]"
|
|
316
|
+
|
|
317
|
+
@classmethod
|
|
318
|
+
def render_score(cls, score: int, label: str = "Score") -> Panel:
|
|
319
|
+
"""Render score as Rich Panel.
|
|
320
|
+
|
|
321
|
+
Args:
|
|
322
|
+
score: Score value (0-100)
|
|
323
|
+
label: Label for the score
|
|
324
|
+
|
|
325
|
+
Returns:
|
|
326
|
+
Rich Panel with formatted score
|
|
327
|
+
"""
|
|
328
|
+
if not RICH_AVAILABLE or Panel is None:
|
|
329
|
+
raise RuntimeError("Rich is not available")
|
|
330
|
+
|
|
331
|
+
style = cls.get_style(score)
|
|
332
|
+
icon = cls.get_icon(score)
|
|
333
|
+
level = cls.get_level(score)
|
|
334
|
+
|
|
335
|
+
content = f"{icon} [bold]{score}[/bold]/100 ({level.upper()})"
|
|
336
|
+
return Panel(content, title=f"[bold]{label}[/bold]", border_style=style)
|
|
337
|
+
|
|
338
|
+
@classmethod
|
|
339
|
+
def render_plain(cls, score: int, label: str = "Score") -> str:
|
|
340
|
+
"""Render score as plain text.
|
|
341
|
+
|
|
342
|
+
Args:
|
|
343
|
+
score: Score value (0-100)
|
|
344
|
+
label: Label for the score
|
|
345
|
+
|
|
346
|
+
Returns:
|
|
347
|
+
Plain text score display
|
|
348
|
+
"""
|
|
349
|
+
icon = cls.get_plain_icon(score)
|
|
350
|
+
level = cls.get_level(score)
|
|
351
|
+
return f"{label}: {icon} {score}/100 ({level.upper()})"
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
# =============================================================================
|
|
355
|
+
# HELPER FUNCTIONS
|
|
356
|
+
# =============================================================================
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
def format_workflow_result(
|
|
360
|
+
title: str,
|
|
361
|
+
summary: str = "",
|
|
362
|
+
findings: list[dict] | None = None,
|
|
363
|
+
score: int | None = None,
|
|
364
|
+
recommendations: str = "",
|
|
365
|
+
metadata: dict[str, Any] | None = None,
|
|
366
|
+
) -> WorkflowReport:
|
|
367
|
+
"""Create a standardized workflow report.
|
|
368
|
+
|
|
369
|
+
Args:
|
|
370
|
+
title: Report title
|
|
371
|
+
summary: Brief summary text
|
|
372
|
+
findings: List of finding dicts with severity, file, line, message
|
|
373
|
+
score: Overall score (0-100)
|
|
374
|
+
recommendations: Recommendations text
|
|
375
|
+
metadata: Additional metadata
|
|
376
|
+
|
|
377
|
+
Returns:
|
|
378
|
+
WorkflowReport instance
|
|
379
|
+
"""
|
|
380
|
+
report = WorkflowReport(
|
|
381
|
+
title=title,
|
|
382
|
+
summary=summary,
|
|
383
|
+
score=score,
|
|
384
|
+
metadata=metadata or {},
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
if findings:
|
|
388
|
+
finding_objs = [
|
|
389
|
+
Finding(
|
|
390
|
+
severity=f.get("severity", "info"),
|
|
391
|
+
file=f.get("file", "unknown"),
|
|
392
|
+
line=f.get("line"),
|
|
393
|
+
message=f.get("message", ""),
|
|
394
|
+
code=f.get("code"),
|
|
395
|
+
)
|
|
396
|
+
for f in findings
|
|
397
|
+
]
|
|
398
|
+
report.add_section("Findings", finding_objs)
|
|
399
|
+
|
|
400
|
+
if recommendations:
|
|
401
|
+
report.add_section("Recommendations", recommendations)
|
|
402
|
+
|
|
403
|
+
return report
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
def get_console() -> Console | None:
|
|
407
|
+
"""Get Rich Console if available."""
|
|
408
|
+
if RICH_AVAILABLE and Console is not None:
|
|
409
|
+
return Console()
|
|
410
|
+
return None
|