format.py python
27 lines 1.2 KB
Raw
sha256:c07f2f34a0db9f43fe866f157d1935322008545ff8940c06c7c921eb219c55ab NXP-b DONE: independent BV-r2 pass + ISR (SD-17) Human minor ⚠ breaking 18 hours ago
1 """Format spend-awareness lines for CLI surfaces (§PC.7)."""
2
3 from __future__ import annotations
4
5 from tools.cost_awareness.surface import CostAwarenessReport, CostSlice
6
7
8 def format_cost_awareness_lines(report: CostAwarenessReport) -> tuple[str, ...]:
9 """Human-readable spend-awareness lines for status and governance-sync."""
10 if not report.enabled:
11 return ()
12 if report.invalid:
13 return (f"cost_awareness: invalid — {report.violation}",)
14 if not report.slices:
15 return ("cost_awareness: no paid step in active slice",)
16 if not any(slice_.paid_step_before_spend for slice_ in report.slices):
17 return ("cost_awareness: no paid step in active slice",)
18 return tuple(_format_slice(slice_) for slice_ in report.slices if slice_.paid_step_before_spend)
19
20
21 def _format_slice(slice_: CostSlice) -> str:
22 tier = slice_.model_tier
23 band = slice_.cost_class
24 tier_label = f"{tier} ({band})" if band != "unknown" else tier
25 tier_hint = f"[{slice_.phase_tier}]" if slice_.phase_tier else "[*]"
26 paid = "paid step before spend" if slice_.paid_step_before_spend else "no metered spend"
27 return f"cost_awareness: {slice_.phase_id} {tier_hint} → {tier_label} — {paid}"
File History 1 commit
sha256:c07f2f34a0db9f43fe866f157d1935322008545ff8940c06c7c921eb219c55ab NXP-b DONE: independent BV-r2 pass + ISR (SD-17) Human minor 18 hours ago