memindex 1.4.4 → 1.4.6
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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.qoder-plugin/plugin.json +1 -1
- package/README.md +9 -1
- package/dist/bug-report/index.js +94 -83
- package/dist/npx-cli/index.js +250 -249
- package/dist/pi-extension/TYPEBOX-PROVENANCE.json +4 -4
- package/dist/pi-extension/index.js +9 -9
- package/integrations/dsh/package.json +1 -1
- package/integrations/openclaw/openclaw.plugin.json +1 -5
- package/integrations/pi/TYPEBOX-PROVENANCE.json +4 -4
- package/package.json +5 -5
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.codex-plugin/plugin.json +1 -1
- package/plugin/.qoder-plugin/plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/plugin/scripts/context-generator.cjs +62 -61
- package/plugin/scripts/context-generator.cjs.map +3 -3
- package/plugin/scripts/mcp-server.cjs +2 -2
- package/plugin/scripts/transcript-watcher.cjs +2 -2
- package/plugin/scripts/transcript-watcher.cjs.map +1 -1
- package/plugin/scripts/worker-service.cjs +677 -669
- package/plugin/scripts/worker-service.cjs.map +3 -3
- package/plugin/skills/distill/SKILL.md +22 -0
- package/plugin/skills/how-it-works/SKILL.md +1 -1
- package/plugin/skills/how-it-works/onboarding-explainer.md +1 -1
- package/plugin/skills/import-chats/SKILL.md +22 -0
- package/plugin/skills/import-jira/SKILL.md +22 -0
- package/plugin/skills/import-reviews/SKILL.md +22 -0
- package/plugin/skills/pin/SKILL.md +26 -0
- package/plugin/skills/savings/SKILL.md +22 -0
- package/integrations/openclaw/skills/agent-cost-report/CHECKSUMS.txt +0 -50
- package/integrations/openclaw/skills/agent-cost-report/SKILL.md +0 -241
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/__init__.py +0 -1
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/behavior.py +0 -303
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/classify.py +0 -83
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/costs.py +0 -119
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/devices.py +0 -88
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/evidence.py +0 -160
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/labels.py +0 -115
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/measure.py +0 -89
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/mistakes.py +0 -310
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/patterns.py +0 -391
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/period.py +0 -98
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/prices.py +0 -95
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/render.py +0 -586
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/rollup.py +0 -355
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/rules.json +0 -4
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/rules.py +0 -76
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/sample.py +0 -45
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/snapshot.py +0 -53
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/sync.py +0 -79
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/transcripts.py +0 -126
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/wins.py +0 -341
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr.py +0 -219
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/_db.py +0 -49
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/_paths.py +0 -9
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/codex/sessions/2026/09/18/rollout-codex-1.jsonl +0 -4
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/make_report_fixtures.py +0 -46
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/prices_sample.json +0 -6
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/projects/-workspace-proj-a/sess-aaaa.jsonl +0 -8
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/projects/-workspace-proj-b/sess-bbbb.jsonl +0 -1
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/report-1day.json +0 -823
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/report-30day.json +0 -2213
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/report-7day.json +0 -1252
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/report-empty.json +0 -536
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/report-session.json +0 -662
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_behavior.py +0 -299
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_devices.py +0 -99
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_labels.py +0 -96
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_measure.py +0 -120
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_pdf_windows.py +0 -54
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_period.py +0 -137
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_prices.py +0 -126
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_render.py +0 -238
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_render_encoding.py +0 -70
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_rollup.py +0 -263
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_snapshot.py +0 -63
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_sync.py +0 -52
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_transcript_encoding.py +0 -109
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_transcripts.py +0 -151
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_wins.py +0 -222
- package/plugin/skills/agent-cost-report/CHECKSUMS.txt +0 -50
- package/plugin/skills/agent-cost-report/SKILL.md +0 -241
- package/plugin/skills/agent-cost-report/scripts/acr/__init__.py +0 -1
- package/plugin/skills/agent-cost-report/scripts/acr/behavior.py +0 -303
- package/plugin/skills/agent-cost-report/scripts/acr/classify.py +0 -83
- package/plugin/skills/agent-cost-report/scripts/acr/costs.py +0 -119
- package/plugin/skills/agent-cost-report/scripts/acr/devices.py +0 -88
- package/plugin/skills/agent-cost-report/scripts/acr/evidence.py +0 -160
- package/plugin/skills/agent-cost-report/scripts/acr/labels.py +0 -115
- package/plugin/skills/agent-cost-report/scripts/acr/measure.py +0 -89
- package/plugin/skills/agent-cost-report/scripts/acr/mistakes.py +0 -310
- package/plugin/skills/agent-cost-report/scripts/acr/patterns.py +0 -391
- package/plugin/skills/agent-cost-report/scripts/acr/period.py +0 -98
- package/plugin/skills/agent-cost-report/scripts/acr/prices.py +0 -95
- package/plugin/skills/agent-cost-report/scripts/acr/render.py +0 -586
- package/plugin/skills/agent-cost-report/scripts/acr/rollup.py +0 -355
- package/plugin/skills/agent-cost-report/scripts/acr/rules.json +0 -4
- package/plugin/skills/agent-cost-report/scripts/acr/rules.py +0 -76
- package/plugin/skills/agent-cost-report/scripts/acr/sample.py +0 -45
- package/plugin/skills/agent-cost-report/scripts/acr/snapshot.py +0 -53
- package/plugin/skills/agent-cost-report/scripts/acr/sync.py +0 -79
- package/plugin/skills/agent-cost-report/scripts/acr/transcripts.py +0 -126
- package/plugin/skills/agent-cost-report/scripts/acr/wins.py +0 -341
- package/plugin/skills/agent-cost-report/scripts/acr.py +0 -219
- package/plugin/skills/agent-cost-report/scripts/tests/_db.py +0 -49
- package/plugin/skills/agent-cost-report/scripts/tests/_paths.py +0 -9
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/codex/sessions/2026/09/18/rollout-codex-1.jsonl +0 -4
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/make_report_fixtures.py +0 -46
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/prices_sample.json +0 -6
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/projects/-workspace-proj-a/sess-aaaa.jsonl +0 -8
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/projects/-workspace-proj-b/sess-bbbb.jsonl +0 -1
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/report-1day.json +0 -823
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/report-30day.json +0 -2213
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/report-7day.json +0 -1252
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/report-empty.json +0 -536
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/report-session.json +0 -662
- package/plugin/skills/agent-cost-report/scripts/tests/test_behavior.py +0 -299
- package/plugin/skills/agent-cost-report/scripts/tests/test_devices.py +0 -99
- package/plugin/skills/agent-cost-report/scripts/tests/test_labels.py +0 -96
- package/plugin/skills/agent-cost-report/scripts/tests/test_measure.py +0 -120
- package/plugin/skills/agent-cost-report/scripts/tests/test_pdf_windows.py +0 -54
- package/plugin/skills/agent-cost-report/scripts/tests/test_period.py +0 -137
- package/plugin/skills/agent-cost-report/scripts/tests/test_prices.py +0 -126
- package/plugin/skills/agent-cost-report/scripts/tests/test_render.py +0 -238
- package/plugin/skills/agent-cost-report/scripts/tests/test_render_encoding.py +0 -70
- package/plugin/skills/agent-cost-report/scripts/tests/test_rollup.py +0 -263
- package/plugin/skills/agent-cost-report/scripts/tests/test_snapshot.py +0 -63
- package/plugin/skills/agent-cost-report/scripts/tests/test_sync.py +0 -52
- package/plugin/skills/agent-cost-report/scripts/tests/test_transcript_encoding.py +0 -109
- package/plugin/skills/agent-cost-report/scripts/tests/test_transcripts.py +0 -151
- package/plugin/skills/agent-cost-report/scripts/tests/test_wins.py +0 -222
- package/plugin/skills/babysit/SKILL.md +0 -87
- package/plugin/skills/design-is/SKILL.md +0 -312
- package/plugin/skills/do/SKILL.md +0 -45
- package/plugin/skills/learn-codebase/SKILL.md +0 -21
- package/plugin/skills/make-plan/SKILL.md +0 -67
- package/plugin/skills/oh-my-issues/SKILL.md +0 -226
- package/plugin/skills/pathfinder/SKILL.md +0 -111
- package/plugin/skills/screenpipe/SKILL.md +0 -78
- package/plugin/skills/screenpipe/screenpipe.mjs +0 -196
- package/plugin/skills/smart-explore/SKILL.md +0 -193
- package/plugin/skills/standup/SKILL.md +0 -142
- package/plugin/skills/standup/agent-brief.md +0 -47
- package/plugin/skills/standup/standup.mjs +0 -586
- package/plugin/skills/what-the/SKILL.md +0 -6
- package/plugin/skills/wowerpoint/SKILL.md +0 -205
|
@@ -1,586 +0,0 @@
|
|
|
1
|
-
"""Phase 3: Timing-style rendering of report.json into one self-contained report.html (plan 3.1-3.8).
|
|
2
|
-
|
|
3
|
-
CSS, body skeleton and every SVG follow one Timing-style mockup. Dollars everywhere (settled decision 1): one formatter `usd2`, every money figure labeled
|
|
4
|
-
ESTIMATE / MEASURED / EXTRAPOLATED with its basis. No <script>, no external fonts or URLs, no jinja2.
|
|
5
|
-
"""
|
|
6
|
-
import datetime as dt
|
|
7
|
-
import html
|
|
8
|
-
import math
|
|
9
|
-
import re
|
|
10
|
-
|
|
11
|
-
esc = html.escape
|
|
12
|
-
|
|
13
|
-
KINDS = ("Feature", "Bug fix", "Incident", "Maintenance", "Investigation", "Experiment")
|
|
14
|
-
COL = {"Feature": "#4FC3F7", "Bug fix": "#FFB14E", "Incident": "#FF8A80", "Maintenance": "#9CCC65", "Investigation": "#A78BFA", "Experiment": "#4DB6AC"}
|
|
15
|
-
WASTE, RECOV, GRAY = "#FF6B6B", "#FFD166", "#8e8e93"
|
|
16
|
-
STAT = {"shipped": ("Shipped", "ok"), "completed": ("Done", "ok"), "in_progress": ("In progress", "wip"), "abandoned": ("Abandoned", "bad"), "blocked": ("Blocked", "bad")}
|
|
17
|
-
TILE_NAMES = {"P1_invented_gates": "Invented gates / asking instead of doing", "tile2": "Made it up, or said done when it wasn't",
|
|
18
|
-
"P2_broke_things": "Broke working things", "P3_wrong_model": "Wrong or expensive model"}
|
|
19
|
-
PAT_SHORT = {"P1_invented_gates": "invented gates", "P2_broke_things": "broke things", "P3_wrong_model": "wrong model", "P4_over_engineering": "over-engineering",
|
|
20
|
-
"P5_not_asked": "not asked", "P6_fake_output": "fake output", "P7_false_done": "false done", "P8_wrong_tool": "wrong tool", "P9_bad_outbound": "bad outbound",
|
|
21
|
-
"P10_memory_loss": "rule loss", "P11_jargon": "jargon", "P12_unclear": "unclear", "S1_tool_errors": "tool errors", "S2_hedging": "hedging"}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def usd2(x):
|
|
25
|
-
"""The only money formatter in the codebase (plan 3.2): "$1,234.56"."""
|
|
26
|
-
return f"${x:,.2f}"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def tag(kind):
|
|
30
|
-
"""ESTIMATE (yellow) | MEASURED (green) | EXTRAPOLATED · low confidence (gray striped) | HEURISTIC | DRAFT."""
|
|
31
|
-
return {"est": '<span class="est">ESTIMATE</span>', "meas": '<span class="est meas">MEASURED</span>',
|
|
32
|
-
"extra": '<span class="est extra">EXTRAPOLATED · low confidence</span>', "heur": '<span class="est heur">heuristic</span>',
|
|
33
|
-
"draft": '<span class="est heur">draft label</span>'}[kind]
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def day_label(day, short=False):
|
|
37
|
-
d = dt.date.fromisoformat(day)
|
|
38
|
-
return f"{d:%b} {d.day}" if short else f"{d:%a %b} {d.day}"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def date_pill(window, scope):
|
|
42
|
-
""""Sep 18 – 25, 2026 (PT)"; cross-month "Sep 29 – Oct 2, 2026 (PT)"; one day "Sep 12, 2026 (PT)" (mapping #1)."""
|
|
43
|
-
if scope.get("kind") == "session" and not window.get("start_pt"): return "one session"
|
|
44
|
-
a = dt.date.fromisoformat(window["start_pt"]); b = dt.date.fromisoformat(window["end_exclusive_pt"]) - dt.timedelta(days=1)
|
|
45
|
-
if a == b: return f"{a:%b} {a.day}, {a.year} (PT)"
|
|
46
|
-
if a.month == b.month: return f"{a:%b} {a.day} – {b.day}, {b.year} (PT)"
|
|
47
|
-
return f"{a:%b} {a.day} – {b:%b} {b.day}, {b.year} (PT)"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def cat_sums(items):
|
|
51
|
-
"""Category totals in category order (by attributed dollars desc), all six kinds present."""
|
|
52
|
-
sums = {k: 0.0 for k in KINDS}
|
|
53
|
-
for li in items:
|
|
54
|
-
sums[li["category"] if li["category"] in sums else "Investigation"] = sums.get(li["category"], 0.0) + li["attributed_usd"]
|
|
55
|
-
active = {k: v for k, v in sorted(sums.items(), key=lambda kv: -kv[1]) if v > 0}
|
|
56
|
-
return sums, active
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
CSS = """
|
|
60
|
-
*{box-sizing:border-box} body{margin:0;background:#e9e9ee;font:14px/1.4 -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter","Helvetica Neue",Arial,sans-serif;color:#1d1d1f;padding:28px}
|
|
61
|
-
.win{width:1384px;margin:0 auto;background:#fff;border-radius:14px;box-shadow:0 20px 60px #0000002a,0 0 0 1px #0000000f;overflow:hidden;display:grid;grid-template-columns:230px 1fr}
|
|
62
|
-
.side{background:linear-gradient(#eef3f6,#e6ecef);border-right:1px solid #dcdfe3;padding:16px 14px}
|
|
63
|
-
.lights{display:flex;gap:8px;margin-bottom:22px} .lights i{width:12px;height:12px;border-radius:50%;display:block}
|
|
64
|
-
.nav a{display:block;padding:6px 10px;border-radius:7px;color:#333;font-size:13.5px;text-decoration:none} .nav .on{background:#d5dbe0;font-weight:600}
|
|
65
|
-
.sh{font-size:11px;color:#8a8f98;font-weight:600;margin:20px 6px 6px;text-transform:uppercase;letter-spacing:.04em}
|
|
66
|
-
.srow{display:flex;align-items:center;gap:8px;padding:5px 8px;font-size:13px} .srow .sv{margin-left:auto;background:#dde3e8;border-radius:9px;padding:0 7px;font-size:11.5px;color:#555;white-space:nowrap}
|
|
67
|
-
.srow.dim{color:#a3a8b0} .dot{width:11px;height:11px;border-radius:50%;display:inline-block;flex:none} .hollow{border:1.5px solid #c5cad1}
|
|
68
|
-
.main{padding:0 0 26px} .bar{display:flex;align-items:center;justify-content:center;gap:14px;height:52px;border-bottom:1px solid #ececf0;color:#555}
|
|
69
|
-
.range{background:#f2f2f5;border-radius:7px;padding:5px 60px;font-weight:500} .arrow{color:#b0b0b8;font-size:18px}
|
|
70
|
-
.content{padding:22px 28px 0}
|
|
71
|
-
.hero{display:grid;grid-template-columns:auto 1fr;gap:36px;align-items:end;margin-bottom:10px}
|
|
72
|
-
.big{font-size:64px;font-weight:700;letter-spacing:-.03em;color:#0a84ff;line-height:1}
|
|
73
|
-
.est{display:inline-block;font-size:11px;font-weight:700;letter-spacing:.06em;color:#8a5a00;background:#fff3d6;border:1px solid #f3dca0;border-radius:5px;padding:1px 6px;margin-left:8px;vertical-align:middle}
|
|
74
|
-
.est.meas{color:#1f7a3a;background:#eefaf1;border-color:#bfe6c8} .est.extra{color:#555;background:repeating-linear-gradient(45deg,#f2f2f5 0 3px,#e3e3e8 3px 6px);border-color:#d5d5da}
|
|
75
|
-
.est.heur{color:#555;background:#f2f2f5;border-color:#d5d5da;font-weight:600;letter-spacing:0;text-transform:none}
|
|
76
|
-
.herosub{font-size:17px;color:#333;margin-top:8px} .herosub b{color:#1d1d1f}
|
|
77
|
-
.meas{font-size:12.5px;color:#6e6e73;margin-top:6px} .basis{font-size:12px;color:#8e8e93;margin-top:4px}
|
|
78
|
-
.headline{font-size:21px;font-weight:600;line-height:1.35;color:#1d1d1f;max-width:720px} .headline em{font-style:normal;color:#0a84ff}
|
|
79
|
-
.wins-mistakes{border:1px solid #ececf0;border-radius:12px;padding:14px 18px;margin-top:14px;display:grid;grid-template-columns:1fr 1fr;gap:18px}
|
|
80
|
-
.wins-mistakes h3{margin:0 0 8px;font-size:13.5px;font-weight:600} .wins-mistakes h3 span{font-weight:400;color:#8e8e93}
|
|
81
|
-
.mline{font-size:16px;color:#1d1d1f} .mline b{color:#b3261e} .mnote{font-size:12px;color:#8e8e93;margin-top:4px} .mout{font-size:13px;color:#b3261e;margin-top:6px}
|
|
82
|
-
.wrow{display:grid;grid-template-columns:22px 1fr 70px 190px;gap:8px;align-items:center;padding:5px 0;border-bottom:1px solid #f2f2f5;font-size:13px} .wrow .wk{font-size:11px;color:#555;background:#f2f2f5;border-radius:4px;text-align:center}
|
|
83
|
-
.wrow .wc{color:#6e6e73;font-size:12px;text-align:right} .wrow a{color:#1d1d1f;text-decoration:none}
|
|
84
|
-
.tl{grid-column:1/3} .tlab{font:11px -apple-system,Inter,Arial;fill:#6e6e73} .tnum{font:600 11px -apple-system,Inter,Arial;fill:#1d1d1f} .tred{font:600 11px -apple-system,Inter,Arial;fill:#b3261e}
|
|
85
|
-
.ribbonwrap{margin:18px 0 6px} .scale{display:flex;flex-wrap:wrap;font-size:12.5px;color:#444;margin-top:8px;row-gap:4px} .seg{display:flex;align-items:center;gap:6px;padding-right:8px;white-space:nowrap;min-width:max-content}
|
|
86
|
-
.muted{color:#8e8e93} .ribbonnote{font-size:12px;color:#6e6e73;margin-top:6px;display:flex;gap:18px} .key{display:inline-block;width:14px;height:10px;border-radius:2px;vertical-align:-1px;margin-right:5px}
|
|
87
|
-
.grid{display:grid;grid-template-columns:1.05fr 1fr 1fr;gap:18px;margin-top:22px}
|
|
88
|
-
.card{border:1px solid #ececf0;border-radius:12px;padding:16px 18px} .card h3{margin:0 0 10px;font-size:13.5px;font-weight:600;color:#1d1d1f} .card h3 span{font-weight:400;color:#8e8e93}
|
|
89
|
-
.dn{display:flex;gap:16px;align-items:center} .dnum{font:700 26px -apple-system,Inter,Arial;fill:#1d1d1f} .dsub{font:12px -apple-system,Inter,Arial;fill:#8e8e93}
|
|
90
|
-
.lrow{display:flex;align-items:center;gap:9px;padding:7px 0;border-bottom:1px solid #f2f2f5;font-size:13.5px;min-width:170px} .lval{margin-left:auto;color:#555;font-variant-numeric:tabular-nums}
|
|
91
|
-
.ctop{font:600 12.5px -apple-system,Inter,Arial;fill:#333} .cnone{font:italic 11.5px -apple-system,Inter,Arial;fill:#a0a0a8} .cax{font:12px -apple-system,Inter,Arial;fill:#6e6e73}
|
|
92
|
-
.gwrap{display:flex;gap:14px;align-items:center} .gwrap svg{flex:none} .gnum{font:700 25px -apple-system,Inter,Arial}
|
|
93
|
-
.gtext{font-size:13.5px;color:#333} .gtext b{color:#1d1d1f} .chips{display:flex;gap:8px;margin-top:12px;flex-wrap:wrap}
|
|
94
|
-
.chip{font-size:12px;background:#eefaf1;color:#1f7a3a;border-radius:20px;padding:3px 10px} .chip.bad{background:#fdeceb;color:#b3261e}
|
|
95
|
-
.bstrip{display:grid;grid-template-columns:repeat(4,1fr);gap:8px;margin-top:12px} .behavior-tile{border:1px solid #ececf0;border-radius:9px;padding:8px 10px;font-size:12px;color:#333}
|
|
96
|
-
.behavior-tile b{display:block;font-size:12.5px;color:#1d1d1f} .behavior-tile .bn{font-size:20px;font-weight:700;color:#b3261e;margin-right:4px} .behavior-tile .bz{color:#1f7a3a;font-weight:600}
|
|
97
|
-
.wide{grid-column:1/3} .orow{display:grid;grid-template-columns:14px 14px 1fr 210px 72px 92px;align-items:center;gap:10px;padding:8px 2px;border-bottom:1px solid #f2f2f5;font-size:13.5px}
|
|
98
|
-
.orow summary{display:contents;cursor:pointer} .orow summary::-webkit-details-marker{display:none} .odet{grid-column:1/7;font-size:12.5px;color:#555;padding:4px 0 6px 28px}
|
|
99
|
-
.tri{color:#b0b0b8} .obar{height:9px;background:#f4f4f7;border-radius:5px;overflow:hidden} .obar i{display:block;height:100%;border-radius:5px}
|
|
100
|
-
.oval{text-align:right;font-variant-numeric:tabular-nums;color:#333;white-space:nowrap} .pill{font-size:11.5px;border-radius:20px;padding:2px 9px;text-align:center} .pill.ok{background:#eefaf1;color:#1f7a3a} .pill.wip{background:#eef4ff;color:#2458c5} .pill.bad{background:#fdeceb;color:#b3261e}
|
|
101
|
-
.flag{font-size:11.5px;color:#b3261e;background:#fdeceb;border-radius:5px;padding:1px 6px;margin-left:6px}
|
|
102
|
-
.attn ol{margin:0;padding-left:20px} .attn li{margin:0 0 10px;font-size:13.5px} .attn li b{display:block}
|
|
103
|
-
.foot{margin-top:18px;display:flex;justify-content:space-between;align-items:center;font-size:12.5px;color:#6e6e73;border-top:1px solid #ececf0;padding-top:12px;gap:16px}
|
|
104
|
-
.disc{border:1px solid #e5e5ea;border-radius:8px;padding:5px 12px;color:#444;text-decoration:none;white-space:nowrap}
|
|
105
|
-
#details{margin:22px 28px 0;font-size:12.5px} #details summary{cursor:pointer;font-weight:600;font-size:14px;padding:8px 0} #details h4{margin:18px 0 6px;font-size:13px}
|
|
106
|
-
#details table{border-collapse:collapse;width:100%;margin:4px 0 10px} #details th,#details td{text-align:left;padding:4px 6px;border-bottom:1px solid #f2f2f5;vertical-align:top;font-variant-numeric:tabular-nums} #details th{color:#6e6e73;font-weight:600}
|
|
107
|
-
#details .ex{color:#555;font-style:italic} #details .id{font-family:ui-monospace,Menlo,monospace;font-size:11.5px;color:#555} #details ul{margin:4px 0;padding-left:18px}
|
|
108
|
-
@page { size: 1440px 1300px; margin: 0; }
|
|
109
|
-
@media print {
|
|
110
|
-
html, body { background: #fff; padding: 0; }
|
|
111
|
-
body, .win, .side, .card, .chip, .pill, .est, .range, .srow .sv, .behavior-tile { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
|
|
112
|
-
.win { width: 1384px; margin: 28px auto; box-shadow: none; border: 1px solid #dcdfe3; }
|
|
113
|
-
.card, .orow, details, tr { break-inside: avoid; }
|
|
114
|
-
#details { break-before: page; }
|
|
115
|
-
#details > details > summary { list-style: none; }
|
|
116
|
-
.disc { display: none; }
|
|
117
|
-
}
|
|
118
|
-
"""
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
def hero(d):
|
|
122
|
-
s, t = d["spend"], d["totals"]
|
|
123
|
-
measured = s.get("agent_measured_usd")
|
|
124
|
-
ref = s.get("measured_reference")
|
|
125
|
-
if isinstance(measured, (int, float)):
|
|
126
|
-
big = f'{usd2(measured)}{tag("meas")}'; basis = esc((ref or {}).get("label") or "measured provider spend") + f' · estimate from tokens {usd2(s["headline_usd"])} for comparison'
|
|
127
|
-
meas = f'Estimate from measured tokens: {usd2(s["headline_usd"])} {tag("est")} · {esc((ref or {}).get("note_taker") or "")}'
|
|
128
|
-
else:
|
|
129
|
-
big = f'{usd2(s["headline_usd"])}{tag("est")}'; basis = esc(s["headline_label"]) + f' · prices fetched {esc((d["pricing"].get("fetched") or "")[:10])} PT'
|
|
130
|
-
if ref and ref.get("usd") is not None:
|
|
131
|
-
meas = f'{esc(ref["label"])}: {usd2(ref["usd"])} {tag("meas")} · {esc(ref.get("note") or "")} · {esc(ref.get("note_taker") or "")}'
|
|
132
|
-
else: meas = "Measured provider spend: unavailable" + (f' ({esc(s["measured_status"])})' if s.get("measured_status") not in (None, "unavailable") else "")
|
|
133
|
-
n = t["finished_outcomes"]; cpo = t.get("cost_per_completed_outcome")
|
|
134
|
-
sub = (f"<b>{n} thing{'s' if n != 1 else ''} finished</b>, about <b>{usd2(cpo)} each</b>" if n and cpo is not None else "<b>Nothing finished yet</b>")
|
|
135
|
-
ex = s.get("extrapolated_unmeasured_usd")
|
|
136
|
-
if ex: extra = f'<div class="meas">+ {usd2(ex)} extrapolated for sessions without transcripts {tag("extra")}</div>'
|
|
137
|
-
elif str(s.get("extrapolation_basis", "")).startswith("all sessions measured"): extra = '<div class="meas">All sessions measured; nothing extrapolated.</div>'
|
|
138
|
-
else: extra = ""
|
|
139
|
-
return (f'<div class="hero" id="overview"><div><div class="big">{big}</div><div class="basis">{basis}</div><div class="herosub">{sub}</div>'
|
|
140
|
-
f'{extra}<div class="meas">{meas}</div></div><div class="headline">{story(d)}</div></div>')
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
def story(d):
|
|
144
|
-
"""Story sentence from data fields only; the useful share is computed here (plan 3.3)."""
|
|
145
|
-
t, s = d["totals"], d["spend"]; w = t.get("waste_rate")
|
|
146
|
-
useful = f"<em>{round((1 - w) * 100, 1)}% of the money went into useful work.</em>" if w is not None else "<em>Useful share: not computed.</em>"
|
|
147
|
-
days = len(d["by_day"]); n = t["finished_outcomes"]; ships = t["ship_events"]; sess = t["real_work_sessions"]
|
|
148
|
-
lead = f"Over {days} day{'s' if days != 1 else ''}, {sess} working session{'s' if sess != 1 else ''} finished {n} thing{'s' if n != 1 else ''}" + (f" and shipped {ships}" if ships else "") + ". "
|
|
149
|
-
m = s.get("mistakes_estimated_usd")
|
|
150
|
-
tail = f" Mistakes cost about {usd2(m)} of that (estimated)." if m else ""
|
|
151
|
-
return lead + useful + tail
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
def wins_mistakes(d):
|
|
155
|
-
s, w = d["spend"], d["wins"]; b = d.get("behavior") or {}
|
|
156
|
-
m = s.get("mistakes_estimated_usd")
|
|
157
|
-
if m is None:
|
|
158
|
-
line = '<div class="mline">Cost of mistakes: not computed (behavior pass off)</div>'
|
|
159
|
-
else:
|
|
160
|
-
mins = s.get("mistakes_user_minutes"); known = s.get("mistakes_user_minutes_known_n", 0); k = s.get("mistakes_unmeasured_n", 0)
|
|
161
|
-
parts = [f'Cost of mistakes: <b>≈{usd2(m)}</b>{tag("est")}', f'{s.get("mistakes_episodes_n", 0)} episode{"s" if s.get("mistakes_episodes_n", 0) != 1 else ""}',
|
|
162
|
-
(f'{mins:g} min of your time' if known else 'your time: unknown')] + ([f'{k} unmeasured'] if k else [])
|
|
163
|
-
line = f'<div class="mline">{" · ".join(parts)}</div><div class="mnote">{esc(s.get("mistakes_basis", ""))}</div>'
|
|
164
|
-
ob = b.get("outbound") or {}
|
|
165
|
-
if ob.get("incidents"): line += f'<div class="mout">{ob["incidents"]} send{"s" if ob["incidents"] != 1 else ""} to {ob.get("recipients", 0)} recipient{"s" if ob.get("recipients", 0) != 1 else ""} without your approval</div>'
|
|
166
|
-
items = w.get("items", []); measured = w.get("cost_status") == "session_linked"
|
|
167
|
-
order = sorted(items, key=lambda i: -(i.get("usd") or 0)) if measured else sorted(items, key=lambda i: i.get("ts_pt") or "", reverse=True)
|
|
168
|
-
rows = []
|
|
169
|
-
for i in order[:5]:
|
|
170
|
-
if i.get("usd") is None: cost = esc(i.get("cost_label") or "unmeasured")
|
|
171
|
-
else: cost = f'≈{usd2(i["usd"])} {tag("extra") if i.get("cost_basis") == "extrapolated" else tag("est")} · session-linked'
|
|
172
|
-
title = f'<a href="#win-{esc(i["win_id"])}">{esc(i["title"][:80])}</a>'
|
|
173
|
-
rows.append(f'<div class="wrow"><span class="wk">{esc(i["kind"])}</span><span>{title}</span><span class="muted">{esc(day_label(i["day_pt"], True)) if i.get("day_pt") else ""}</span><span class="wc">{cost}</span></div>')
|
|
174
|
-
more = f'<div class="mnote">+{len(items) - 5} more in Details</div>' if len(items) > 5 else ""
|
|
175
|
-
if not items: rows.append('<div class="mnote">No merged PR or published version found in this window.</div>')
|
|
176
|
-
if measured and w.get("unattributed_usd") is not None: rows.append(f'<div class="wrow"><span></span><span>Not tied to a win</span><span></span><span class="wc">≈{usd2(w["unattributed_usd"])} {tag("est")}</span></div>')
|
|
177
|
-
elif items: rows.append('<div class="mnote">win costs unmeasured (G11: no fallback estimate)</div>')
|
|
178
|
-
return (f'<div class="wins-mistakes"><div><h3>Mistakes <span>· low, same-session figure</span></h3>{line}</div>'
|
|
179
|
-
f'<div><h3>Wins shipped <span>· {"most expensive first" if measured else "newest first"}</span></h3>{"".join(rows)}{more}</div>'
|
|
180
|
-
f'<div class="tl">{timelines(d)}</div></div>')
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
def timelines(d):
|
|
184
|
-
"""Two timelines on one PT-day axis (plan 3.8c): wins as dots above, mistakes as red bars below. Links to Details."""
|
|
185
|
-
days = [x["day_pt"] for x in d["by_day"]]; wbd = {x["day_pt"]: x for x in d["timeline"].get("wins_by_day", [])}; mbd = {x["day_pt"]: x for x in d["timeline"].get("mistakes_by_day", [])}
|
|
186
|
-
n = max(len(days), 1); colw = 90 if n <= 10 else max(30, int(900 / n)); W = 40 + n * colw; H = 196; axis = 96
|
|
187
|
-
maxm = max([x.get("usd") or 0 for x in mbd.values()] or [0]); maxw = max([x.get("count") or 0 for x in wbd.values()] or [0])
|
|
188
|
-
out = [f'<line x1="20" x2="{W - 10}" y1="{axis}" y2="{axis}" stroke="#e5e5ea"/>']
|
|
189
|
-
partial = d["window"].get("partial_last_day")
|
|
190
|
-
for i, day in enumerate(days):
|
|
191
|
-
cx = 40 + i * colw + colw / 2; wd = wbd.get(day, {}); md = mbd.get(day, {})
|
|
192
|
-
c = wd.get("count") or 0
|
|
193
|
-
if c:
|
|
194
|
-
r = 6 + (10 * c / maxw if maxw else 0)
|
|
195
|
-
val = usd2(wd["usd"]) if wd.get("usd") is not None else "unmeasured"
|
|
196
|
-
out.append(f'<a href="#win-{esc(wd["win_ids"][0])}"><circle cx="{cx:.1f}" cy="{axis - 30:.1f}" r="{r:.1f}" fill="#34C759"/><text x="{cx:.1f}" y="{axis - 26:.1f}" text-anchor="middle" class="tnum" fill="#fff">{c}</text>'
|
|
197
|
-
f'<text x="{cx:.1f}" y="{axis - 50:.1f}" text-anchor="middle" class="tlab">{esc(val)}</text></a>')
|
|
198
|
-
else: out.append(f'<line x1="{cx:.1f}" x2="{cx:.1f}" y1="{axis - 6}" y2="{axis}" stroke="#c5cad1"/>')
|
|
199
|
-
usd = md.get("usd") or 0
|
|
200
|
-
if usd:
|
|
201
|
-
h = max(4, 50 * usd / maxm) if maxm else 4
|
|
202
|
-
out.append(f'<a href="#mistakes-{esc(day)}"><rect x="{cx - 14:.1f}" y="{axis + 2}" width="28" height="{h:.1f}" rx="3" fill="{WASTE}"/><text x="{cx:.1f}" y="{axis + h + 14:.1f}" text-anchor="middle" class="tred">{usd2(usd)}</text></a>')
|
|
203
|
-
elif md.get("unmeasured_n"):
|
|
204
|
-
out.append(f'<a href="#mistakes-{esc(day)}"><rect x="{cx - 14:.1f}" y="{axis + 2}" width="28" height="12" rx="3" fill="none" stroke="{WASTE}" stroke-dasharray="3 2"/><text x="{cx:.1f}" y="{axis + 26}" text-anchor="middle" class="tlab">{md["unmeasured_n"]} unmeasured</text></a>')
|
|
205
|
-
else: out.append(f'<line x1="{cx:.1f}" x2="{cx:.1f}" y1="{axis}" y2="{axis + 6}" stroke="#c5cad1"/>')
|
|
206
|
-
if md.get("outbound_incidents"): out.append(f'<text x="{cx + 18:.1f}" y="{axis + 12}" class="tred">✉{md["outbound_incidents"]}</text>')
|
|
207
|
-
lab = day_label(day, True) + (" · partial" if (partial and i == n - 1) else "")
|
|
208
|
-
out.append(f'<text x="{cx:.1f}" y="{H - 4}" text-anchor="middle" class="cax">{esc(lab)}</text>')
|
|
209
|
-
out.append(f'<text x="20" y="14" class="tlab">wins above the line (count; cost unmeasured until sessions are linked) · mistakes below (low, estimated, per day)</text>')
|
|
210
|
-
return f'<svg viewBox="0 0 {W} {H}" width="100%" height="{H}" preserveAspectRatio="xMinYMid meet">{"".join(out)}</svg>'
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
def ribbon(d, cats):
|
|
214
|
-
items = [li for li in d["line_items"] if not li.get("trivial") and li["attributed_usd"] > 0]
|
|
215
|
-
total = sum(li["attributed_usd"] for li in items)
|
|
216
|
-
if not items or total <= 0: return '<div class="ribbonwrap"><div class="mnote">No priced work in this window.</div></div>'
|
|
217
|
-
order = list(cats); W = 1000; x = 0; blocks = []; stripes = set()
|
|
218
|
-
for li in sorted(items, key=lambda l: (order.index(l["category"]) if l["category"] in order else 99, -l["attributed_usd"])):
|
|
219
|
-
w = li["attributed_usd"] / total * W; c = COL.get(li["category"], GRAY)
|
|
220
|
-
ip = li["status"] == "in_progress"; key = li["category"].replace(" ", "")
|
|
221
|
-
if ip: stripes.add(key)
|
|
222
|
-
fill = f"url(#stripe-{key})" if ip else c
|
|
223
|
-
blocks.append(f'<rect x="{x + 1:.1f}" y="0" width="{max(w - 2, 0):.1f}" height="56" rx="7" fill="{fill}"><title>{esc(li["title"][:80])} · {usd2(li["attributed_usd"])}</title></rect>')
|
|
224
|
-
if li.get("wasted_cost"):
|
|
225
|
-
ww = min(li["wasted_cost"] / total * W, max(w - 2, 0))
|
|
226
|
-
blocks.append(f'<rect x="{x + w - 1 - ww:.1f}" y="0" width="{ww:.1f}" height="56" fill="url(#hatch)"/>')
|
|
227
|
-
x += w
|
|
228
|
-
defs = [f'<pattern id="hatch" width="7" height="7" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><rect width="7" height="7" fill="{WASTE}"/><rect width="3" height="7" fill="#ffffff66"/></pattern>']
|
|
229
|
-
for key in sorted(stripes):
|
|
230
|
-
c = COL.get(next(k for k in KINDS if k.replace(" ", "") == key), GRAY)
|
|
231
|
-
defs.append(f'<pattern id="stripe-{key}" width="8" height="8" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><rect width="8" height="8" fill="{c}"/><rect width="4" height="8" fill="#ffffff88"/></pattern>')
|
|
232
|
-
waste_total = d["spend"].get("mistakes_estimated_usd", d["totals"].get("wasted_usd", 0.0))
|
|
233
|
-
svg = f'<svg class="ribbon" viewBox="0 0 {W} 56" width="100%" height="56" preserveAspectRatio="none" data-waste-usd="{waste_total:.2f}"><defs>{"".join(defs)}</defs>{"".join(blocks)}</svg>'
|
|
234
|
-
scale = "".join(f'<div style="width:{v / total * 100:.2f}%" class="seg"><span class="dot" style="background:{COL.get(c, GRAY)}"></span><b>{esc(c)}</b> {usd2(v)} <span class="muted">· {v / total * 100:.0f}%</span></div>' for c, v in cats.items())
|
|
235
|
-
keys = ['<span>Each block is one piece of work, sized by estimated cost.</span>']
|
|
236
|
-
if any(li.get("wasted_cost") for li in items): keys.append(f'<span><i class="key" style="background:{WASTE}"></i>wasted turns ({usd2(waste_total)} {tag("est")})</span>')
|
|
237
|
-
if stripes: keys.append('<span><i class="key" style="background:repeating-linear-gradient(45deg,#4FC3F7 0 3px,#d6f1fd 3px 6px)"></i>still in progress</span>')
|
|
238
|
-
return f'<div class="ribbonwrap">{svg}<div class="scale">{scale}</div><div class="ribbonnote">{"".join(keys)}</div></div>'
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
def sidebar(d, sums, cats):
|
|
242
|
-
t = d["totals"]; total = d["spend"].get("total_estimate_usd") or sum(li["attributed_usd"] for li in d["line_items"])
|
|
243
|
-
rows = [f'<div class="srow"><span class="dot" style="background:{GRAY}"></span><b>All work</b><span class="sv">{usd2(total)}</span></div>']
|
|
244
|
-
for c, v in cats.items(): rows.append(f'<div class="srow"><span class="dot" style="background:{COL[c]}"></span>{esc(c)}<span class="sv">{usd2(v)}</span></div>')
|
|
245
|
-
for c in KINDS:
|
|
246
|
-
if c not in cats: rows.append(f'<div class="srow dim"><span class="dot hollow"></span>{esc(c)}<span class="sv">—</span></div>')
|
|
247
|
-
top = sorted((li for li in d["line_items"] if not li.get("trivial")), key=lambda l: -l["attributed_usd"])[:6]
|
|
248
|
-
sess = "".join(f'<div class="srow" title="{esc(li["content_session_id"])}">{esc(li["work_item_id"])} · {esc(day_label(li["date_pt"], True))}</div>' for li in top)
|
|
249
|
-
k = t["sessions"] - len(top)
|
|
250
|
-
if k > 0: sess += f'<div class="srow dim">+{k} more in Details</div>'
|
|
251
|
-
models = sorted(d["by_model"], key=lambda m: -m["agent_estimated_usd"])[:4]
|
|
252
|
-
mrows = "".join(f'<div class="srow" style="font-size:12px;color:#555;display:block">{esc(m["model"].split("/")[-1])}<br><span class="muted">{"list price" if m.get("priced") else "unpriced"} · {usd2(m["agent_estimated_usd"])}</span></div>' for m in models)
|
|
253
|
-
return (f'<aside class="side"><div class="lights"><i style="background:#ff5f57"></i><i style="background:#febc2e"></i><i style="background:#28c840"></i></div>'
|
|
254
|
-
f'<div class="nav"><a class="on" href="#overview">Overview</a><a href="#outcomes">Outcomes</a><a href="#details">Details & evidence</a></div>'
|
|
255
|
-
f'<div class="sh">Kinds of work</div>{"".join(rows)}<div class="sh">Sessions</div>{sess}<div class="sh">Models</div>{mrows}<div class="sh">Other seats</div><div class="srow dim" title="{esc((d["spend"].get("grok_bot_usage") or {}).get("reason") or "")}">Grok Bot usage: unavailable</div></aside>')
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
def donut(d, cats):
|
|
259
|
-
total = sum(cats.values())
|
|
260
|
-
if total <= 0: return '<div class="mnote">No priced work.</div>'
|
|
261
|
-
R, SW = 70, 34; C = 2 * math.pi * R; off = 0; arcs = []
|
|
262
|
-
for c, v in cats.items():
|
|
263
|
-
L = v / total * C
|
|
264
|
-
arcs.append(f'<circle r="{R}" cx="100" cy="100" fill="none" stroke="{COL[c]}" stroke-width="{SW}" stroke-dasharray="{max(L - 2, 0):.2f} {C - max(L - 2, 0):.2f}" stroke-dashoffset="{-off:.2f}" transform="rotate(-90 100 100)"/>')
|
|
265
|
-
off += L
|
|
266
|
-
word = "measured" if isinstance(d["spend"].get("agent_measured_usd"), (int, float)) else "estimated"
|
|
267
|
-
svg = f'<svg viewBox="0 0 200 200" width="190" height="190">{"".join(arcs)}<text x="100" y="96" text-anchor="middle" class="dnum">{usd2(total)}</text><text x="100" y="116" text-anchor="middle" class="dsub">{word}</text></svg>'
|
|
268
|
-
rows = "".join(f'<div class="lrow"><span class="dot" style="background:{COL[c]}"></span><span class="lname">{esc(c)}</span><span class="lval">{usd2(v)}</span></div>' for c, v in cats.items())
|
|
269
|
-
return f'<div class="dn">{svg}<div>{rows}</div></div>'
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
def day_chart(d, cats):
|
|
273
|
-
days = d["by_day"]; n = max(len(days), 1); colw = 95 if n <= 3 else max(22, min(60, int(330 / n))); bw = int(colw * 0.62); W = 40 + n * colw; H = 150
|
|
274
|
-
perday = {x["day_pt"]: {} for x in days}
|
|
275
|
-
for li in d["line_items"]:
|
|
276
|
-
if li.get("trivial") or li["date_pt"] not in perday: continue
|
|
277
|
-
perday[li["date_pt"]][li["category"]] = perday[li["date_pt"]].get(li["category"], 0.0) + li["attributed_usd"]
|
|
278
|
-
maxd = max([sum(v.values()) for v in perday.values()] or [0]); cols = [f'<line x1="20" x2="{W - 10}" y1="{H + 10}" y2="{H + 10}" stroke="#e5e5ea"/>']
|
|
279
|
-
partial = d["window"].get("partial_last_day")
|
|
280
|
-
for i, x in enumerate(days):
|
|
281
|
-
day = x["day_pt"]; cx = 30 + i * colw; y = H + 10; s = sum(perday[day].values())
|
|
282
|
-
for c in cats:
|
|
283
|
-
v = perday[day].get(c, 0)
|
|
284
|
-
if v and maxd:
|
|
285
|
-
h = v / maxd * H; y -= h
|
|
286
|
-
cols.append(f'<rect x="{cx}" y="{y:.1f}" width="{bw}" height="{max(h - 1.5, 0):.1f}" rx="3" fill="{COL[c]}"/>')
|
|
287
|
-
lab = usd2(s) if s else "no agent work"
|
|
288
|
-
if partial and i == n - 1: lab += " · partial"
|
|
289
|
-
if n <= 3 or s: cols.append(f'<text x="{cx + bw / 2:.1f}" y="{(y - 7) if s else H + 2:.1f}" text-anchor="middle" class="{"ctop" if s else "cnone"}" font-size="{12.5 if n <= 3 else 9}">{esc(lab if n <= 3 or s else "")}</text>')
|
|
290
|
-
else: cols.append(f'<text x="{cx + bw / 2:.1f}" y="{H + 2}" text-anchor="middle" class="cnone" font-size="7">no agent work</text>')
|
|
291
|
-
if n <= 12 or i % max(1, n // 8) == 0: cols.append(f'<text x="{cx + bw / 2:.1f}" y="{H + 30}" text-anchor="middle" class="cax" font-size="{12 if n <= 3 else 9}">{esc(day_label(day, True))}</text>')
|
|
292
|
-
return f'<svg viewBox="0 0 {W} {H + 40}" width="100%" height="{H + 40}">{"".join(cols)}</svg>'
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
def ring(d):
|
|
296
|
-
t = d["totals"]; w = t.get("waste_rate"); prod = 1 - w if w is not None else None
|
|
297
|
-
RR = 54; CC = 2 * math.pi * RR; pct = (prod or 0) * 100
|
|
298
|
-
color = "#34C759" if pct >= 90 else "#FFB14E" if pct >= 70 else "#FF6B6B"
|
|
299
|
-
num = f"{pct:.1f}%" if prod is not None else "n/a"
|
|
300
|
-
svg = (f'<svg viewBox="0 0 140 140" width="112" height="112"><circle r="{RR}" cx="70" cy="70" fill="none" stroke="#f0f0f3" stroke-width="14"/>'
|
|
301
|
-
f'<circle r="{RR}" cx="70" cy="70" fill="none" stroke="{color}" stroke-width="14" stroke-linecap="round" stroke-dasharray="{(prod or 0) * CC:.2f} {CC:.2f}" transform="rotate(-90 70 70)"/>'
|
|
302
|
-
f'<text x="70" y="78" text-anchor="middle" class="gnum" fill="{color}">{num}</text></svg>')
|
|
303
|
-
fe = d.get("failure_economics") or []
|
|
304
|
-
if fe:
|
|
305
|
-
top = max(fe, key=lambda f: f["wasted_usd"] + f["recovery_usd"])
|
|
306
|
-
sent = (f'<b>Useful work.</b> {esc(top["failure_type"])} touched {top["sessions"]} session{"s" if top["sessions"] != 1 else ""}: {usd2(top["wasted_usd"])} wasted, {usd2(top["recovery_usd"])} spent recovering {tag("est")}.')
|
|
307
|
-
others = [f["failure_type"] for f in fe if f is not top]
|
|
308
|
-
sent += f'<br><span class="muted">Also seen: {esc(", ".join(others[:4]))}.</span>' if others else '<br><span class="muted">No other failure signals.</span>'
|
|
309
|
-
else: sent = '<b>Useful work.</b> No failure signals in the drafted labels.<br><span class="muted">Labels are keyword drafts until reviewed.</span>'
|
|
310
|
-
blocked = sum(1 for li in d["line_items"] if li["status"] == "blocked"); unauth = sum(1 for f in fe if f["failure_type"] == "Unauthorized action" for _ in range(f["sessions"]))
|
|
311
|
-
chips = (f'<span class="chip{" bad" if blocked else ""}">{"✕" if blocked else "✓"} {blocked} blocked</span>'
|
|
312
|
-
f'<span class="chip{" bad" if unauth else ""}">{"✕" if unauth else "✓"} {unauth} unauthorized attempts</span>')
|
|
313
|
-
return f'<div class="gwrap">{svg}<div class="gtext">{sent}</div></div><div class="chips">{chips}</div>{behavior_strip(d)}'
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
def behavior_strip(d):
|
|
317
|
-
b = d.get("behavior")
|
|
318
|
-
if not b: return '<div class="mnote" style="margin-top:10px">Behavior pass not run.</div>'
|
|
319
|
-
pats = {p["key"]: p for p in b["patterns"]}
|
|
320
|
-
groups = [("P1_invented_gates", ["P1_invented_gates"]), ("tile2", ["P6_fake_output", "P7_false_done"]), ("P2_broke_things", ["P2_broke_things"]), ("P3_wrong_model", ["P3_wrong_model"])]
|
|
321
|
-
tiles = []
|
|
322
|
-
for key, members in groups:
|
|
323
|
-
ps = [pats[m] for m in members if m in pats and pats[m]["placement"] == "tile"]
|
|
324
|
-
if not ps: continue
|
|
325
|
-
count = sum(p["count"] for p in ps); low = sum(p["low_usd"] or 0 for p in ps); unm = sum(p["unmeasured_n"] for p in ps); mins = sum(p.get("user_minutes") or 0 for p in ps)
|
|
326
|
-
if count and not low and unm and not (key == "P3_wrong_model" and ps[0].get("delta_usd")): money = "unmeasured"
|
|
327
|
-
elif key == "P3_wrong_model": money = f'≈{usd2(ps[0].get("delta_usd") or 0)} more than the default model {tag("est")}' if count else ""
|
|
328
|
-
else: money = f'≈{usd2(low)} {tag("est")}' if count else ""
|
|
329
|
-
body = (f'<span class="bn">{count}</span>{money}' if count else '<span class="bz">none found</span>')
|
|
330
|
-
extra = (f' · {mins:g} min of your time' if mins else "") + (f' · +{unm} unmeasured' if unm else "")
|
|
331
|
-
tiles.append(f'<div class="behavior-tile"><b>{esc(TILE_NAMES[key])}</b>{body}{esc(extra)} {tag("heur") if count else ""}</div>')
|
|
332
|
-
return f'<div class="bstrip">{"".join(tiles[:4])}</div>'
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
def outcomes(d):
|
|
336
|
-
items = [li for li in d["line_items"] if not li.get("trivial")]
|
|
337
|
-
if not items: return '<div class="mnote">No work items.</div>'
|
|
338
|
-
maxc = max(li["attributed_usd"] for li in items) or 1; rows = []
|
|
339
|
-
for li in sorted(items, key=lambda l: -l["attributed_usd"]):
|
|
340
|
-
c = COL.get(li["category"], GRAY); st = STAT.get(li["status"], (li["status"], "wip")); bw = li["attributed_usd"] / maxc * 100
|
|
341
|
-
flag = ""
|
|
342
|
-
if li["failure_type"]: flag = '<span class="flag">⟲ recovery</span>' if li["failure_type"] == "Recovery after miss" else f'<span class="flag">⚠ {esc(li["failure_type"])}</span>'
|
|
343
|
-
draft = tag("draft") if li["label_source"] == "keyword" else ""
|
|
344
|
-
basis = tag("extra") if li["cost_basis"] == "extrapolated" else tag("meas") if li["cost_basis"] == "measured_provider" else tag("est")
|
|
345
|
-
if li["attributed_usd"] == 0 and li.get("unpriced_calls"): money = "unpriced (model not in price list)"
|
|
346
|
-
elif not li.get("has_transcript") and li.get("cost_extrapolated") is None: money = "unmeasured"; basis = ""
|
|
347
|
-
else: money = usd2(li["attributed_usd"]) + basis
|
|
348
|
-
bc = sorted(li.get("behavior_counts", {}).items(), key=lambda kv: -kv[1])
|
|
349
|
-
det = (f'{esc(li["notes"])} · evidence {", ".join(map(str, li["evidence_ids"][:12]))}{" …" if len(li["evidence_ids"]) > 12 else ""} · session <span class="id">{esc(li["content_session_id"])}</span>'
|
|
350
|
-
f' · confidence {esc(li["confidence"])} · risk {esc(li["risk_exposure"])}' + (f' · wasted {usd2(li["wasted_cost"])}' if li["wasted_cost"] else "")
|
|
351
|
-
+ (f' · behavior: {esc(", ".join(f"{PAT_SHORT.get(k, k)} ×{v}" for k, v in bc[:4]))}' if bc else ""))
|
|
352
|
-
rows.append(f'<details class="orow"><summary><span class="tri">›</span><span class="dot" style="background:{c}"></span><span class="otitle">{esc(li["title"][:90])} {flag}{draft}</span>'
|
|
353
|
-
f'<span class="obar"><i style="width:{bw:.1f}%;background:{c}{"80" if st[1] == "wip" else ""}"></i></span><span class="oval">{money}</span>'
|
|
354
|
-
f'<span class="pill {st[1]}">{esc(st[0])}</span></summary><div class="odet">{det}</div></details>')
|
|
355
|
-
return "".join(rows)
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
def attention(d):
|
|
359
|
-
att = (d.get("attention") or [])[:3]
|
|
360
|
-
if not att: return "<ol><li><b>Nothing flagged.</b><span class=\"muted\">No waste, unfinished work, or unpriced model stood out.</span></li></ol>"
|
|
361
|
-
return "<ol>" + "".join(f'<li><b>{esc(a["text"])}</b></li>' for a in att) + "</ol>"
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
def _table(headers, rows):
|
|
365
|
-
return "<table><tr>" + "".join(f"<th>{h}</th>" for h in headers) + "</tr>" + "".join("<tr>" + "".join(f"<td>{c}</td>" for c in r) + "</tr>" for r in rows) + "</table>"
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
def _unmeasured(li):
|
|
369
|
-
"""No transcript and no extrapolation ratio: the spend is unknown, never a measured zero (money-labeling rules)."""
|
|
370
|
-
return not li.get("has_transcript") and li.get("cost_extrapolated") is None
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
def _li_money(li):
|
|
374
|
-
return "unmeasured" if _unmeasured(li) else usd2(li["attributed_usd"])
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
def _li_basis(li):
|
|
378
|
-
return "unmeasured (no ratio)" if _unmeasured(li) else esc(li["cost_basis"])
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
def details(d, open_):
|
|
382
|
-
s, t, b = d["spend"], d["totals"], d.get("behavior") or {}
|
|
383
|
-
out = [f'<details id="details" {"open" if open_ else ""}><summary>Details & evidence</summary>']
|
|
384
|
-
out.append("<h4>Wins</h4>")
|
|
385
|
-
gs = (d["wins"].get("sources") or {}).get("github_merged_prs")
|
|
386
|
-
if gs:
|
|
387
|
-
rep = "; ".join(f'{esc(r)}: {esc(v["status"])}' + (f' ({v["found"]} found)' if v.get("found") is not None else "") for r, v in (gs.get("repos") or {}).items())
|
|
388
|
-
out.append(f'<div class="muted">GitHub merged PRs (read-only gh pr list): {esc(gs["status"])} · {rep}</div>')
|
|
389
|
-
for w in d["wins"].get("items", []):
|
|
390
|
-
cost = "unmeasured (session not linked to PR)" if w.get("usd") is None else f'≈{usd2(w["usd"])} {tag("extra") if w.get("cost_basis") == "extrapolated" else tag("est")} · {esc(w.get("cost_basis") or "")}'
|
|
391
|
-
tok = w.get("tokens"); tok_s = ", ".join(f"{k} {v:,}" for k, v in tok.items()) if tok else "—"
|
|
392
|
-
out.append(f'<div id="win-{esc(w["win_id"])}"><b>{esc(w["win_id"])}</b> · {esc(w["kind"])} · {esc(w["title"])} · {esc(w.get("ts_pt") or "")}'
|
|
393
|
-
+ (f' · <a href="{esc(w["url"])}">{esc(w["url"])}</a>' if w.get("url") else "")
|
|
394
|
-
+ f'<br><span class="muted">sources {esc(", ".join(w.get("sources") or []))} · cost {cost} · sessions {esc(", ".join(w.get("sessions") or []) or "—")} · tokens {tok_s} · attribution {esc(d["wins"].get("attribution_method") or "none")} · evidence {esc(", ".join(map(str, w.get("evidence_ids") or [])) or "—")}</span></div>')
|
|
395
|
-
if not d["wins"].get("items"): out.append('<div class="muted">No wins found (merged PR, published version, or praise).</div>')
|
|
396
|
-
if d["wins"].get("dropped"): out.append(f'<div class="muted">{len(d["wins"]["dropped"])} candidate(s) dropped: ' + esc("; ".join(str(x.get("reason")) for x in d["wins"]["dropped"][:6])) + "</div>")
|
|
397
|
-
out.append("<h4>Mistakes by day</h4>")
|
|
398
|
-
if s.get("mistakes_high_usd") is not None:
|
|
399
|
-
out.append(f'<div class="muted">Upper bound: ≈{usd2(s["mistakes_high_usd"])} (adds 60-minute redo windows and project-wide fallback; {esc(s.get("mistakes_high_label", ""))}). '
|
|
400
|
-
f'Low figure in the summary: {usd2(s["mistakes_estimated_usd"])} over {s.get("mistakes_turns_n", 0)} turns' + (f', {usd2(s["mistakes_unmatched_usd"])} of it in transcripts with no memindex session' if s.get("mistakes_unmatched_usd") else "") + ".</div>")
|
|
401
|
-
eps = {e["episode_id"]: e for e in b.get("episodes", [])}
|
|
402
|
-
for x in d["timeline"].get("mistakes_by_day", []):
|
|
403
|
-
pats = ", ".join(f"{PAT_SHORT.get(k, k)} {usd2(v)}" for k, v in sorted(x.get("by_pattern", {}).items(), key=lambda kv: -kv[1]))
|
|
404
|
-
top = x.get("top_examples", []); shown = {e.get("episode_id") for e in top if e.get("episode_id") in eps}
|
|
405
|
-
ex = "".join(f'<li>{esc(PAT_SHORT.get(e["pattern"], e["pattern"]))} · {esc(eps[e["episode_id"]]["cost_status"]) if e.get("episode_id") in eps else "top example"} · <span class="id">{esc(e["content_session_id"])}</span> · {esc(e["ts_pt"])}'
|
|
406
|
-
+ (f' · <span class="ex">{esc(eps[e["episode_id"]]["excerpt"])}</span>' if e.get("episode_id") in eps else "") + "</li>" for e in top)
|
|
407
|
-
day_eps = [e for e in b.get("episodes", []) if e["day_pt"] == x["day_pt"] and e["episode_id"] not in shown]
|
|
408
|
-
ex += "".join(f'<li>{esc(PAT_SHORT.get(e["pattern"], e["pattern"]))} · {esc(e["cost_status"])} · <span class="id">{esc(e["session"])}</span> · {esc(e["ts_pt"])} · <span class="ex">{esc(e["excerpt"])}</span></li>' for e in day_eps)
|
|
409
|
-
out.append(f'<div id="mistakes-{esc(x["day_pt"])}"><b>{esc(day_label(x["day_pt"]))}</b> · low {usd2(x["usd"])} · high {usd2(x["high_usd"])} · {x["turns_n"]} turns · {x["unmeasured_n"]} unmeasured episode(s) · {x["user_minutes"]:g} user-min · {x["outbound_incidents"]} outbound'
|
|
410
|
-
+ (f'<br><span class="muted">{esc(pats)}</span>' if pats else "") + (f"<ul>{ex}</ul>" if ex else "") + "</div>")
|
|
411
|
-
if b:
|
|
412
|
-
rows = [(esc(p["key"]), esc(p["name"]), p["count"], ("incidents × recipients: %s × %s" % (p.get("incidents", 0), p.get("recipients", 0))) if p["key"] == "P9_bad_outbound" else usd2(p["low_usd"] or 0),
|
|
413
|
-
"—" if p["high_usd"] is None else usd2(p["high_usd"]), f'{p.get("user_minutes") or 0:g}', p["unmeasured_n"], esc(p.get("detection", "H")), esc(p["failure_type"] or "—"), esc(p["placement"]), esc(p["count_basis"])) for p in b["patterns"]]
|
|
414
|
-
out.append("<h4>Behavior patterns</h4>" + _table(["key", "pattern", "count", "low (est.)", f"high ({esc(b['patterns'][0].get('high_label', ''))})", "user-min", "unmeasured", "basis", "failure type", "place", "count basis"], rows))
|
|
415
|
-
for p in b["patterns"]:
|
|
416
|
-
if p.get("examples"): out.append(f'<div><b>{esc(p["name"])}</b> examples<ul>' + "".join(f'<li><span class="id">{esc(e["content_session_id"] or "")}</span> {esc(e.get("ts_pt") or "")} · {esc(e["basis"])} · <span class="ex">{esc(e["excerpt"])}</span> · {esc(e["label_source"])}</li>' for e in p["examples"][:10]) + "</ul></div>")
|
|
417
|
-
out.append("<h4>Rule effectiveness</h4>")
|
|
418
|
-
rr = b.get("rule_effectiveness") or []
|
|
419
|
-
if rr: out.append(_table(["rule", "landed", "pattern", "before (eps / prompts / per 100)", "after", "verdict", "episodes after"],
|
|
420
|
-
[(esc(r.get("name") or r["rule_key"]), r["landed_pt"], esc(r.get("pattern") or "—"), _side(r.get("before")), _side(r.get("after")), esc(r["verdict"].replace("_", " ")), esc(", ".join(r.get("episode_ids_after") or []) or "—")) for r in rr]))
|
|
421
|
-
else: out.append('<div class="muted">No HARD rule landed inside or within 7 days before this window.</div>')
|
|
422
|
-
pd = b.get("permission_denials") or {}
|
|
423
|
-
at = b.get("author_tags"); at_s = esc(str(at)) if isinstance(at, str) else f'human {at.get("human", 0)}, bot {at.get("bot", 0)}, unknown {at.get("unknown", 0)}'
|
|
424
|
-
out.append(f'<div>Permission denials (blocked by a rule, not priced): {pd.get("count", 0)} · user turns tagged: {at_s} · label sources: {esc(str(dict(b.get("label_sources") or {})))} · '
|
|
425
|
-
f'classifier: {"ran, " + usd2(b["classifier"].get("spend_usd") or 0) + " (separate)" if b.get("classifier", {}).get("ran") else "off"} · coverage: {esc(str(b.get("coverage")))}</div>')
|
|
426
|
-
out.append("<h4>Spend</h4>" + _table(["field", "value"], [
|
|
427
|
-
("agent, estimated from measured tokens", f'{usd2(s["agent_estimated_usd"])} {tag("est")}'), ("agent, measured by provider", esc(str(s.get("agent_measured_usd") if s.get("agent_measured_usd") is not None else s.get("measured_status")))),
|
|
428
|
-
("extrapolated (sessions without transcripts)", (f'{usd2(s["extrapolated_unmeasured_usd"])} {tag("extra")}' if s.get("extrapolated_unmeasured_usd") is not None else "unavailable (no measured session to derive a ratio from)") + f' · {esc(s.get("extrapolation_basis") or "")}'),
|
|
429
|
-
("total estimate", f'{usd2(s["total_estimate_usd"])} = {usd2(s["agent_estimated_usd"])} + ' + (usd2(s["extrapolated_unmeasured_usd"]) if s.get("extrapolated_unmeasured_usd") is not None else "unavailable")),
|
|
430
|
-
("Note-taker (observer) cost, separate", f'{usd2(s["observer_note_taker_est_usd"])} {tag("est")} · never added to the agent figures'),
|
|
431
|
-
("Grok Bot usage", "unavailable (Cursor exposes seat usage only on the plan screen) · sources checked: " + esc(", ".join((s.get("grok_bot_usage") or {}).get("checked_sources") or []))), ("pricing", f'{esc(d["pricing"].get("source") or "")} fetched {esc(d["pricing"].get("fetched") or "")} · 1h rule: {esc(d["pricing"].get("rule_1h") or "")}')]))
|
|
432
|
-
out.append("<h4>Models</h4>" + _table(["source", "model", "calls", "input", "output", "cache write 5m", "cache write 1h", "cache read", "est. $", "$/MTok in/out/read/write/write1h"],
|
|
433
|
-
[(esc(m["source"]), esc(m["model"]), m["calls"], f'{m["input"]:,}', f'{m["output"]:,}', f'{m["cache_write_5m"]:,}', f'{m["cache_write_1h"]:,}', f'{m["cache_read"]:,}', usd2(m["agent_estimated_usd"]),
|
|
434
|
-
esc("/".join(str(m["prices_usd_per_mtok"].get(k)) for k in ("input", "output", "cache_read", "cache_write", "cache_write_1h")) if m.get("prices_usd_per_mtok") else "unpriced")) for m in d["by_model"]]))
|
|
435
|
-
out.append("<h4>Failure accounting</h4>" + (_table(["failure type", "sessions", "attributed", "wasted", "recovery", "items"], [(esc(f["failure_type"]), f["sessions"], usd2(f["attributed_usd"]), usd2(f["wasted_usd"]), usd2(f["recovery_usd"]), esc(", ".join(f["work_item_ids"][:12]))) for f in d.get("failure_economics") or []]) if d.get("failure_economics") else '<div class="muted">none</div>'))
|
|
436
|
-
out.append("<h4>Line items</h4>" + _table(["id", "title", "status", "category", "label", "attributed", "basis", "wasted", "tokens in/out/cw5/cw1h/read", "model", "device", "sessions", "evidence ids"],
|
|
437
|
-
[(esc(li["work_item_id"]), esc(li["title"][:70]), esc(li["status"]), esc(li["category"]), esc(li["label_source"]), _li_money(li), _li_basis(li), usd2(li["wasted_cost"]),
|
|
438
|
-
"/".join(f'{li["agent_tokens"][k]:,}' for k in ("input", "output", "cache_write_5m", "cache_write_1h", "cache_read")), esc(li["model"] or "—"), esc(", ".join(li["device"])),
|
|
439
|
-
f'<span class="id">{esc(li["content_session_id"])}<br>{esc(li["session_ids"][0])}</span>', esc(", ".join(map(str, li["evidence_ids"][:10])) + (" …" if len(li["evidence_ids"]) > 10 else ""))) for li in d["line_items"]]))
|
|
440
|
-
out.append("<h4>Devices</h4>" + _table(["device", "id (short hash)", "sessions", "est. $", "extrapolated $"], [(esc(x["device"]), esc(x["id_hash"]), x["sessions"], usd2(x["agent_estimated_usd"]), usd2(x["extrapolated_usd"])) for x in d["by_device"]]))
|
|
441
|
-
um = d["unmatched_transcripts"]
|
|
442
|
-
out.append(f'<h4>Unmatched transcripts</h4><div class="muted">{um["count"]} transcript session(s) on this box matched no memindex session: {usd2(um["usd"])} {tag("est")}, {um["tokens"]:,} tokens, counted in the totals. {esc(um.get("note") or "")}</div>')
|
|
443
|
-
out.append("<h4>Unpriced models</h4>" + (_table(["model", "role", "calls", "tokens", "reason"], [(esc(x["model"]), esc(x["role"]), x["calls"], f'{x["tokens"]:,}', esc(x["reason"])) for x in d["unpriced_models"]]) if d["unpriced_models"] else '<div class="muted">none</div>'))
|
|
444
|
-
out.append(f'<h4>Labels</h4><div>{d["labels"]["reviewed"]} of {d["labels"]["total"]} labels reviewed; the rest are keyword drafts marked "draft label". Trivial sessions (no observations, no transcript, under a minute): {t.get("trivial_sessions", 0)}.</div>')
|
|
445
|
-
out.append("<h4>Honesty rules</h4><ul><li>Every dollar figure is labeled ESTIMATE, MEASURED, or EXTRAPOLATED with its basis.</li><li>Measured provider spend is never shown as zero when it is unavailable.</li>"
|
|
446
|
-
"<li>Completed outcomes are the unit of work; Rework is a failure type, never a work kind.</li><li>The note-taker's own tokens are priced separately and never added to the agent headline.</li>"
|
|
447
|
-
"<li>Keyword labels are drafts until reviewed; behavior counts are heuristic until reviewed or classified.</li><li>Grok Bot usage and Mac transcripts show unavailable or extrapolated (low confidence), never zero.</li>"
|
|
448
|
-
"<li>The mistakes headline is the low, same-session figure; the upper bound stays in this section.</li></ul>")
|
|
449
|
-
out.append('<div class="muted">Files: <a href="line-items.csv">line-items.csv</a> · <a href="evidence.json">evidence.json</a> · <a href="report.json">report.json</a></div></details>')
|
|
450
|
-
return "".join(out)
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
def _side(x):
|
|
454
|
-
if not x: return "—"
|
|
455
|
-
return f'{x["episodes"]} / {x["human_prompts"]} / {x["per_100"] if x["per_100"] is not None else "not enough data"}'
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
def page(d, print_mode=False):
|
|
459
|
-
items = [li for li in d["line_items"] if not li.get("trivial")]
|
|
460
|
-
sums, cats = cat_sums(items)
|
|
461
|
-
foot = ("All dollar figures are estimates from measured token counts × OpenRouter list price unless tagged MEASURED. Provider-measured spend is unavailable for these sessions, so it is never shown as zero. "
|
|
462
|
-
"Behavior counts are heuristic until reviewed.")
|
|
463
|
-
body = (f'<div class="win">{sidebar(d, sums, cats)}<main class="main"><div class="bar"><span class="arrow">‹</span><span class="range">{esc(date_pill(d["window"], d["scope"]))}</span><span class="arrow">›</span></div>'
|
|
464
|
-
f'<div class="content">{hero(d)}{wins_mistakes(d)}{ribbon(d, cats)}'
|
|
465
|
-
f'<div class="grid"><div class="card"><h3>Where the money went <span>· by kind of work</span></h3>{donut(d, cats)}</div>'
|
|
466
|
-
f'<div class="card"><h3>Day by day <span>· estimated</span></h3>{day_chart(d, cats)}</div>'
|
|
467
|
-
f'<div class="card"><h3>How much was useful</h3>{ring(d)}</div>'
|
|
468
|
-
f'<div class="card wide" id="outcomes"><h3>What got done <span>· most expensive first</span></h3>{outcomes(d)}</div>'
|
|
469
|
-
f'<div class="card attn"><h3>Worth your attention</h3>{attention(d)}</div></div>'
|
|
470
|
-
f'<div class="foot"><span>{foot} Generated {esc(d.get("generated_at_pt") or "")}.</span><a class="disc" href="#details">› Details: evidence IDs, sessions, tokens, CSV</a></div>'
|
|
471
|
-
f'</div>{details(d, print_mode)}</main></div>')
|
|
472
|
-
return f'<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Agent Cost Report — {esc(date_pill(d["window"], d["scope"]))}</title><style>{CSS}</style></head><body>{body}</body></html>'
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
OTHER_MINUTES = {"active_minutes", "agent_minutes", "waiting_minutes"}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
def upgrade_minutes(o):
|
|
479
|
-
"""Reports saved before the minutes fields were renamed carry them under an older `<who>_minutes`
|
|
480
|
-
name. Copy that value into `user_minutes` (and the summary's `mistakes_user_minutes[_known_n]`) so an
|
|
481
|
-
old report.json renders with its numbers. Works in place; new reports pass through unchanged."""
|
|
482
|
-
if isinstance(o, dict):
|
|
483
|
-
for new, shape in (("user_minutes", r"[a-z]+_minutes"), ("mistakes_user_minutes", r"mistakes_[a-z]+_minutes"),
|
|
484
|
-
("mistakes_user_minutes_known_n", r"mistakes_[a-z]+_minutes_known_n")):
|
|
485
|
-
if new in o: continue
|
|
486
|
-
old = [k for k in o if re.fullmatch(shape, k) and k not in OTHER_MINUTES]
|
|
487
|
-
if len(old) == 1: o[new] = o[old[0]]
|
|
488
|
-
for v in o.values(): upgrade_minutes(v)
|
|
489
|
-
elif isinstance(o, list):
|
|
490
|
-
for v in o: upgrade_minutes(v)
|
|
491
|
-
return o
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
def render_file(inp, outdir, print_mode=False):
|
|
495
|
-
import json, os
|
|
496
|
-
with open(inp, encoding="utf-8") as fh: d = upgrade_minutes(json.load(fh))
|
|
497
|
-
os.makedirs(outdir, exist_ok=True)
|
|
498
|
-
name = "report.print.html" if print_mode else "report.html"
|
|
499
|
-
path = os.path.join(outdir, name)
|
|
500
|
-
html_bytes = page(d, print_mode).encode("utf-8")
|
|
501
|
-
with open(path, "wb") as fh: fh.write(html_bytes)
|
|
502
|
-
return path
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
CHROME_TIMEOUT_S = 150
|
|
506
|
-
CHROME_EXIT_GRACE_S = 5
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
def _default_chrome():
|
|
510
|
-
"""The browser behind the default `google-chrome`: that name on PATH, else Chrome where it is normally
|
|
511
|
-
installed off PATH. Windows: `chrome` on PATH, then Program Files and LocalAppData; macOS: the app
|
|
512
|
-
bundle in /Applications or ~/Applications. None when there is none."""
|
|
513
|
-
import os, shutil, sys
|
|
514
|
-
exe = shutil.which("google-chrome")
|
|
515
|
-
if exe: return exe
|
|
516
|
-
if sys.platform == "win32":
|
|
517
|
-
exe = shutil.which("chrome")
|
|
518
|
-
if exe: return exe
|
|
519
|
-
candidates = [os.path.join(os.environ[k], "Google", "Chrome", "Application", "chrome.exe")
|
|
520
|
-
for k in ("PROGRAMFILES", "PROGRAMFILES(X86)", "LOCALAPPDATA") if os.environ.get(k)]
|
|
521
|
-
elif sys.platform == "darwin":
|
|
522
|
-
app = os.path.join("Google Chrome.app", "Contents", "MacOS", "Google Chrome")
|
|
523
|
-
candidates = [os.path.join("/Applications", app), os.path.join(os.path.expanduser("~"), "Applications", app)]
|
|
524
|
-
else:
|
|
525
|
-
candidates = []
|
|
526
|
-
return next((c for c in candidates if os.path.isfile(c)), None)
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
def pdf(outdir, chrome="google-chrome"):
|
|
530
|
-
"""google-chrome --headless=new ... --print-to-pdf; if Chrome is missing: 'PDF skipped, HTML is canonical' (SKILL.md:165).
|
|
531
|
-
An explicit `chrome` is used as given; only the default also looks where Chrome is installed (_default_chrome)."""
|
|
532
|
-
import os, shutil
|
|
533
|
-
from pathlib import Path
|
|
534
|
-
src = os.path.join(outdir, "report.print.html")
|
|
535
|
-
if not os.path.exists(src):
|
|
536
|
-
rp = os.path.join(outdir, "report.json")
|
|
537
|
-
if not os.path.exists(rp): raise FileNotFoundError(f"{src} not found and no report.json to render it from")
|
|
538
|
-
render_file(rp, outdir, print_mode=True)
|
|
539
|
-
exe = _default_chrome() if chrome == "google-chrome" else shutil.which(chrome)
|
|
540
|
-
if not exe: return None, "PDF skipped, HTML is canonical (google-chrome not found)"
|
|
541
|
-
out = os.path.join(outdir, "report.pdf")
|
|
542
|
-
profile = os.path.join(os.path.abspath(outdir), ".chrome-profile")
|
|
543
|
-
printed = os.path.join(profile, "report.pdf")
|
|
544
|
-
shutil.rmtree(profile, ignore_errors=True); os.makedirs(profile, exist_ok=True)
|
|
545
|
-
cmd = [exe, "--headless=new", "--no-sandbox", "--disable-gpu", "--disable-dev-shm-usage", f"--user-data-dir={profile}", "--timeout=60000",
|
|
546
|
-
f"--print-to-pdf={printed}", "--no-pdf-header-footer", Path(src).resolve().as_uri()]
|
|
547
|
-
try:
|
|
548
|
-
rc, err = _print_pdf(cmd, printed)
|
|
549
|
-
if _pdf_complete(printed):
|
|
550
|
-
try: os.replace(printed, out)
|
|
551
|
-
except OSError as ex: return None, f"PDF skipped, HTML is canonical (could not write {out}: {ex})"
|
|
552
|
-
return out, f"pdf: {out}"
|
|
553
|
-
finally: shutil.rmtree(profile, ignore_errors=True)
|
|
554
|
-
if rc is None: return None, "PDF skipped, HTML is canonical (chrome timed out)"
|
|
555
|
-
return None, f"PDF skipped, HTML is canonical (chrome exit {rc}: {err.strip()[-200:]})"
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
def _pdf_complete(path):
|
|
559
|
-
"""True once `path` is a whole PDF: it starts with %PDF- and its last bytes hold the %%EOF marker."""
|
|
560
|
-
try:
|
|
561
|
-
with open(path, "rb") as fh:
|
|
562
|
-
head = fh.read(5); fh.seek(0, 2); fh.seek(max(0, fh.tell() - 64)); tail = fh.read()
|
|
563
|
-
except OSError: return False
|
|
564
|
-
return head == b"%PDF-" and b"%%EOF" in tail
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
def _print_pdf(cmd, printed):
|
|
568
|
-
"""Runs Chrome until it exits, or until CHROME_EXIT_GRACE_S after `printed` is a whole PDF (Chrome on macOS writes
|
|
569
|
-
the PDF, then keeps running), or until CHROME_TIMEOUT_S. Returns (exit code, or None when it timed out; stderr text).
|
|
570
|
-
stderr goes to an anonymous file, not a pipe: Chrome's helper processes can hold a pipe open after Chrome exits."""
|
|
571
|
-
import subprocess, tempfile, time
|
|
572
|
-
with tempfile.TemporaryFile() as err:
|
|
573
|
-
proc = subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=err)
|
|
574
|
-
start = time.monotonic(); done_at = None; timed_out = False
|
|
575
|
-
while proc.poll() is None:
|
|
576
|
-
now = time.monotonic()
|
|
577
|
-
if done_at is None and _pdf_complete(printed): done_at = now
|
|
578
|
-
timed_out = now - start > CHROME_TIMEOUT_S
|
|
579
|
-
if timed_out or (done_at is not None and now - done_at > CHROME_EXIT_GRACE_S):
|
|
580
|
-
proc.terminate()
|
|
581
|
-
try: proc.wait(timeout=10)
|
|
582
|
-
except subprocess.TimeoutExpired: proc.kill(); proc.wait()
|
|
583
|
-
break
|
|
584
|
-
time.sleep(0.2)
|
|
585
|
-
err.seek(0)
|
|
586
|
-
return (None if timed_out else proc.returncode), err.read().decode("utf-8", errors="replace")
|