"""Human-effort and builder-effort decomposition (table + figure). Sources: reports/interventions.csv (human), reports/phase_status.md timestamps and the builder's recorded subagent usage (reports/builder_effort.json, written by the builder from the client's task notifications).""" import os, sys, json, csv sys.path.insert(0, os.path.dirname(__file__)); from common import * import matplotlib; matplotlib.use("Agg"); import matplotlib.pyplot as plt def main(): inter = list(csv.DictReader(open(os.path.join(REPO, "reports", "interventions.csv")))) be = json.load(open(os.path.join(REPO, "reports", "builder_effort.json"))) runs = pd.read_csv(os.path.join(DATA, "runs.csv")) rows = [("Researcher: mandate preparation", "unknown", "not measured (historical)", "—"), ("Researcher: launch instruction", "< 1 min", "observed (one message)", "—"), ("Researcher: interventions in executor sessions", "0", "ledger (none recorded)", "—"), ("Researcher: final review of the manuscript", be.get("human_final_review", "not yet performed"), "ledger", "—")] for k, v in be["builder"].items(): rows.append((f"Builder session: {k}", v.get("wall", "—"), v.get("basis", ""), f"{v.get('tokens', '—')}")) for k, v in be["subagents"].items(): rows.append((f"Sub-session: {k}", f"{v['duration_min']:.0f} min", "client task notification", f"{v['tokens']:,}")) inf = runs.groupby("split").spent_usd.sum() L = [r"\begin{tabular}{p{2.6in}p{0.9in}p{1.6in}p{0.9in}}", r"\toprule", r"Component & Wall time & Measurement basis & Tokens \\", r"\midrule"] + [f"{a} & {b} & {c} & {d} \\\\" for a, b, c, d in rows] + [r"\midrule"] for s, v in inf.items(): L.append(f"Inference: {s} runs & — & client cost estimate & {v:.2f} USD \\\\") L += [r"\bottomrule", r"\end{tabular}"] os.makedirs(os.path.join(REPO, "results", "tables"), exist_ok=True); open(os.path.join(REPO, "results", "tables", "tab_effort.tex"), "w").write("\n".join(L) + "\n") # figure: stacked bars of sub-session tokens + builder; unknown shown as hatched placeholder labels = list(be["subagents"].keys()); toks = [be["subagents"][k]["tokens"] / 1e6 for k in labels] fig, ax = plt.subplots(figsize=(7.2, 2.6)); ax.barh(labels, toks, color="#4c72b0"); ax.set_xlabel("Tokens consumed by delegated sub-sessions (millions, client-reported)") ax.set_title("Builder-side effort: delegated sub-sessions (human preparation time unknown; builder session total in Table)", loc="left", fontsize=8); ax.invert_yaxis() fig.tight_layout(); fig.savefig(os.path.join(REPO, "results", "figures", "fig_effort.pdf")); print("\n".join(L[:8])) if __name__ == "__main__": main()