Python
fix(observability): open a coworker's page from its name, the default's too (T3-12)
Devika Vermac730ce6dae50
diff --git a/surfaces/gui/src/App.tsx b/surfaces/gui/src/App.tsxindex 31d4158e..20506ae4 100644--- a/surfaces/gui/src/App.tsx+++ b/surfaces/gui/src/App.tsx@@ -405,13 +405,16 @@ export function App() {const [personaViewId, setPersonaViewId] = useState<string>("");// Where the persona page returns on "back": the active session, or Settings ▸ Personas when it// was opened from there (persona config now lives in Settings).- const [personaViewReturn, setPersonaViewReturn] = useState<"session" | "settings">("session");+ const [personaViewReturn, setPersonaViewReturn] = useState<"session" | "settings" | "activity">("session");+ const [personaViewFocus, setPersonaViewFocus] = useState<"doing" | undefined>(undefined);const openPersona = (id: string,- from: "session" | "settings" = "session",+ from: "session" | "settings" | "activity" = "session",machineId?: string | null,) => {setPersonaViewReturn(from);+ // T3-12: from Usage ▸ By coworker, the page opens at its history+ setPersonaViewFocus(from === "activity" ? "doing" : undefined);setPersonaViewId(id);setPersonaViewMachine(machineId ?? null);setSurface("persona");@@ -2188,15 +2191,18 @@ export function App() {}}/>) : surface === "audit" ? (- <AuditView callId={auditCallId} initialTab={activityTab} onTabChange={setActivityTab} onOpenTurn={openTurnSteps} />+ <AuditView callId={auditCallId} initialTab={activityTab} onTabChange={setActivityTab} onOpenTurn={openTurnSteps}+ onOpenPersona={(id) => openPersona(id, "activity")} />) : surface === "inbox" ? (<InboxView onOpenSession={openSessionFromInbox} />) : surface === "persona" ? (<PersonaViewmachine={machines.find((m) => m.id === personaViewMachine) ?? null}personaId={personaViewId || agent}+ focus={personaViewFocus}onBack={() =>- personaViewReturn === "settings" ? openSettings("personas") : setSurface("session")+ personaViewReturn === "settings" ? openSettings("personas")+ : personaViewReturn === "activity" ? setSurface("audit") : setSurface("session")}onOpenIntegrations={() => openSettings("connectors")}/>diff --git a/surfaces/gui/src/components/AuditView.tsx b/surfaces/gui/src/components/AuditView.tsxindex 74a6be94..c17b82dc 100644--- a/surfaces/gui/src/components/AuditView.tsx+++ b/surfaces/gui/src/components/AuditView.tsx@@ -14,12 +14,13 @@ const BTN_ACCENT = "text-ui px-3 py-1.5 rounded-lg bg-accent text-white shrink-0// `callId` (OPE-238): opened from the "changes made without asking" summary — show that one// tool call's rows, with the filter visible and clearable.// Phase 3 (OB-8): the page gains a tab bar, Log | Usage. A call filter always opens the Log.-export function AuditView({ callId, initialTab = "log", onTabChange, onOpenTurn }: {+export function AuditView({ callId, initialTab = "log", onTabChange, onOpenTurn, onOpenPersona }: {callId?: string;initialTab?: "log" | "usage";/** T3-11: the open tab, for the page's address */onTabChange?: (tab: "log" | "usage") => void;onOpenTurn?: (sessionId: string, turnId: string) => void;+ onOpenPersona?: (personaId: string) => void;} = {}) {const [tab, setTab] = useState<"log" | "usage">(callId ? "log" : initialTab);useEffect(() => {@@ -66,7 +67,7 @@ export function AuditView({ callId, initialTab = "log", onTabChange, onOpenTurn{t("p3.usage.tab_usage")}</button></div>- {tab === "usage" ? <UsagePage onOpenTurn={onOpenTurn} /> : (<>+ {tab === "usage" ? <UsagePage onOpenTurn={onOpenTurn} onOpenPersona={onOpenPersona} /> : (<><div className="flex items-center gap-2 flex-wrap mb-4"><input className={INPUT} placeholder={t("audit.placeholder_session")} value={sessionFilter} onChange={(e) => setSessionFilter(e.target.value)} />diff --git a/surfaces/gui/src/components/PersonaDoing.tsx b/surfaces/gui/src/components/PersonaDoing.tsxindex 2c99cc28..dc9304be 100644--- a/surfaces/gui/src/components/PersonaDoing.tsx+++ b/surfaces/gui/src/components/PersonaDoing.tsx@@ -12,7 +12,9 @@ import { shortDate } from "../obs3";type T = (k: string, o?: any) => string;-export function PersonaDoing({ personaId, machineId, secClass }: { personaId: string; machineId?: string | null; secClass?: string }) {+export function PersonaDoing({ personaId, machineId, secClass, scrollIntoView }: {+ personaId: string; machineId?: string | null; secClass?: string; scrollIntoView?: boolean;+}) {const { t } = useTranslation();const [doing, setDoing] = useState<Doing | null>(null);const [diff, setDiff] = useState<{ fp: string; files: (VersionFileChange & { diff: string })[] } | null>(null);@@ -27,9 +29,12 @@ export function PersonaDoing({ personaId, machineId, secClass }: { personaId: st};}, [personaId, machineId]);if (!doing || !Array.isArray(doing.rows)) return null; // an older engine answers something else+ const reveal = (el: HTMLElement | null) => {+ if (el && scrollIntoView && typeof el.scrollIntoView === "function") el.scrollIntoView({ block: "start" });+ };const newest = doing.rows[0];return (- <section data-testid="persona-doing">+ <section data-testid="persona-doing" ref={reveal}><div className={`${secClass || ""} mb-1.5`}>{t("p3.doing.title")}</div><div className="rounded-xl2 border border-line bg-panel p-3">{doing.rows.length === 0 ? (diff --git a/surfaces/gui/src/components/PersonaView.tsx b/surfaces/gui/src/components/PersonaView.tsxindex 20dee313..7b41cbe4 100644--- a/surfaces/gui/src/components/PersonaView.tsx+++ b/surfaces/gui/src/components/PersonaView.tsx@@ -48,8 +48,11 @@ export function PersonaView({onBack,onOpenIntegrations,machine,+ focus,}: {personaId: string;+ /** T3-12: "doing" scrolls to "How it's been doing" (opened from Usage ▸ By coworker) */+ focus?: "doing";onBack?: () => void;onOpenIntegrations?: () => void;// UX-046 machine scope: this coworker lives on a joined machine; every read@@ -355,7 +358,7 @@ export function PersonaView({)}{/* Phase 3 OB-15: how each version of this coworker has been doing */}- <PersonaDoing personaId={personaId} machineId={mid} secClass={SEC_H} />+ <PersonaDoing personaId={personaId} machineId={mid} secClass={SEC_H} scrollIntoView={focus === "doing"} />{/* defaults footer */}<section className="flex flex-wrap gap-x-8 gap-y-2 text-ui">diff --git a/surfaces/gui/src/components/PersonasTab.test.tsx b/surfaces/gui/src/components/PersonasTab.test.tsxnew file mode 100644index 00000000..f7c31eae--- /dev/null+++ b/surfaces/gui/src/components/PersonasTab.test.tsx@@ -0,0 +1,36 @@+// T3-12: in Settings ▸ Coworkers the name opens the coworker's page, the default coworker's too.+import { afterEach, describe, expect, it, vi } from "vitest";+import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";++vi.mock("../api", () => ({+ getPersonasIndex: vi.fn(async () => ({+ internal: false,+ personas: [+ { id: "cowork", name: "OpenWorker", tagline: "The default", enabled: true, default: true, surfaced: true },+ { id: "sec", name: "Security Coworker", tagline: "Finds risks", enabled: true, default: false, surfaced: true },+ ],+ })),+ getSessions: vi.fn(async () => []),+ getMachineSessionsList: vi.fn(async () => []),+ installPersona: vi.fn(),+ updatePersona: vi.fn(),+}));++import { PersonasTab } from "./PersonasTab";++afterEach(cleanup);++describe("PersonasTab", () => {+ it("opens a coworker's page from its name, the default one too (T3-12)", async () => {+ const open = vi.fn();+ render(<PersonasTab onOpenPersona={open} />);+ await waitFor(() => expect(screen.getByTestId("persona-open-cowork")).toBeTruthy());+ expect(screen.getByTestId("persona-default-tag")).toBeTruthy();+ fireEvent.click(screen.getByTestId("persona-open-cowork"));+ expect(open).toHaveBeenCalledWith("cowork");+ fireEvent.click(screen.getByTestId("persona-open-sec"));+ expect(open).toHaveBeenLastCalledWith("sec");+ // the sliders button is still there for the others+ expect(screen.getByTestId("persona-configure-sec")).toBeTruthy();+ });+});diff --git a/surfaces/gui/src/components/PersonasTab.tsx b/surfaces/gui/src/components/PersonasTab.tsxindex 27983dc2..34bc614a 100644--- a/surfaces/gui/src/components/PersonasTab.tsx+++ b/surfaces/gui/src/components/PersonasTab.tsx@@ -167,10 +167,24 @@ export function PersonasTab({{list.map((p) => (<div key={p.id} className="px-[18px] py-4"><div className="flex items-center gap-3">- <div className="min-w-0 flex-1">- <div className="text-body font-medium truncate">{p.name}</div>- <div className="text-meta text-faint truncate mt-0.5">{p.tagline}</div>- </div>+ {/* T3-12: the name opens the coworker's page (its settings and "How it's+ been doing"), the default coworker's too */}+ {onOpenPersona ? (+ <button+ className="min-w-0 flex-1 text-left cursor-pointer group"+ title={t("personas.open_title", { name: p.name })}+ data-testid={`persona-open-${p.id}`}+ onClick={() => onOpenPersona(p.id)}+ >+ <div className="text-body font-medium truncate group-hover:underline">{p.name}</div>+ <div className="text-meta text-faint truncate mt-0.5">{p.tagline}</div>+ </button>+ ) : (+ <div className="min-w-0 flex-1">+ <div className="text-body font-medium truncate">{p.name}</div>+ <div className="text-meta text-faint truncate mt-0.5">{p.tagline}</div>+ </div>+ )}{p.default ? (/* The default coworker cannot be disabled or hidden — no toggle, noconfigure; a quiet tag says why (owner 2026-08-21). It regains itsdiff --git a/surfaces/gui/src/components/UsagePage.test.tsx b/surfaces/gui/src/components/UsagePage.test.tsxindex 23128427..9cde72cc 100644--- a/surfaces/gui/src/components/UsagePage.test.tsx+++ b/surfaces/gui/src/components/UsagePage.test.tsx@@ -104,6 +104,15 @@ describe("UsageBody", () => {render(<UsageBody data={data()} period="7d" t={t} picked />);expect(screen.getByTestId("usage-coworkers-all").textContent).toBe("All coworkers, for comparison");});++ it("each coworker's name in By coworker opens its history (T3-12)", () => {+ const open = vi.fn();+ render(<UsageBody data={data()} period="7d" t={t} onOpenPersona={open} />);+ const links = screen.getAllByTestId("usage-coworker-open-cowork");+ expect(links).toHaveLength(2); // its own row and its automation row+ fireEvent.click(links[0]);+ expect(open).toHaveBeenCalledWith("cowork");+ });});describe("ApproverStripView", () => {diff --git a/surfaces/gui/src/components/UsagePage.tsx b/surfaces/gui/src/components/UsagePage.tsxindex 7502f35c..222843c7 100644--- a/surfaces/gui/src/components/UsagePage.tsx+++ b/surfaces/gui/src/components/UsagePage.tsx@@ -107,7 +107,11 @@ export async function loadUsage(period: Period, now = new Date(), personaId: strreturn { total, prev, dayPurpose, coworkers, heavy, approver, machines: [...machines, ...remote] };}-export function UsagePage({ onOpenTurn }: { onOpenTurn?: (sessionId: string, turnId: string) => void }) {+export function UsagePage({ onOpenTurn, onOpenPersona }: {+ onOpenTurn?: (sessionId: string, turnId: string) => void;+ /** T3-12: a coworker's page, at its "How it's been doing" */+ onOpenPersona?: (personaId: string) => void;+}) {const { t } = useTranslation();const [period, setPeriod] = useState<Period>("7d");const [persona, setPersona] = useState<string | null>(null);@@ -155,14 +159,15 @@ export function UsagePage({ onOpenTurn }: { onOpenTurn?: (sessionId: string, tur) : !data ? (<div className={CARD + " p-4 text-ui text-muted"}>{t("p3.usage.loading")}</div>) : (- <UsageBody data={data} period={period} t={t} onOpenTurn={onOpenTurn} picked={!!persona} />+ <UsageBody data={data} period={period} t={t} onOpenTurn={onOpenTurn} onOpenPersona={onOpenPersona} picked={!!persona} />)}</div>);}-export function UsageBody({ data, period, t, onOpenTurn, picked = false }: {+export function UsageBody({ data, period, t, onOpenTurn, onOpenPersona, picked = false }: {data: UsageData; period: Period; t: T; onOpenTurn?: (sessionId: string, turnId: string) => void;+ onOpenPersona?: (personaId: string) => void;/** a coworker is picked: everything narrows to it but By coworker (T3-11) */picked?: boolean;}) {@@ -224,7 +229,12 @@ export function UsageBody({ data, period, t, onOpenTurn, picked = false }: {<thead><tr><th>{t("p3.usage.coworker")}</th><th className="n">{t("p3.usage.tokens")}</th><th className="n">{t("p3.usage.with_issues")}</th></tr></thead><tbody>{coworkerRows.map((r) => (- <tr key={r.key}><td>{r.name}{r.automation && <span className="text-faint"> {t("p3.usage.automation")}</span>}</td>+ <tr key={r.key}><td>+ {r.personaId && onOpenPersona ? (+ <button className="p3-link" title={t("p3.usage.open_history", { name: r.name })}+ data-testid={`usage-coworker-open-${r.personaId}`} onClick={() => onOpenPersona(r.personaId!)}>{r.name}</button>+ ) : r.name}+ {r.automation && <span className="text-faint"> {t("p3.usage.automation")}</span>}</td><td className="n">{(r.atLeast ? "≥ " : "") + formatTokens(r.total)}</td><td className="n">{r.checked ? `${Math.round((r.withWarn / r.checked) * 100)}%` : "—"}</td></tr>))}@@ -355,12 +365,12 @@ function Tile({ label, value, sub, testid }: { label: string; value: string; sub/** By coworker, named from the installed coworkers or the kept versions (M3-R1); an* automation's turns get their own row under their coworker, "(automation)". */export function coworkerTable(groups: RollupGroup[], names: Record<string, string>, t: T) {- const rows = new Map<string, { key: string; name: string; automation: boolean; total: number; atLeast: boolean; checked: number; withWarn: number }>();+ const rows = new Map<string, { key: string; personaId: string | null; name: string; automation: boolean; total: number; atLeast: boolean; checked: number; withWarn: number }>();for (const g of groups) {const pid = g.key.persona_id as string | null;const auto = g.key.task_id != null;const key = `${pid ?? ""}|${auto ? "a" : ""}`;- const r = rows.get(key) || { key, name: pid ? names[pid] || pid : t("p3.usage.unknown_coworker"), automation: auto, total: 0, atLeast: false, checked: 0, withWarn: 0 };+ const r = rows.get(key) || { key, personaId: pid, name: pid ? names[pid] || pid : t("p3.usage.unknown_coworker"), automation: auto, total: 0, atLeast: false, checked: 0, withWarn: 0 };r.total += g.total;r.atLeast = r.atLeast || g.unreported > 0;r.checked += g.checked;diff --git a/surfaces/gui/src/locales/en.json b/surfaces/gui/src/locales/en.jsonindex 4e8c4769..58ce44bf 100644--- a/surfaces/gui/src/locales/en.json+++ b/surfaces/gui/src/locales/en.json@@ -1573,6 +1573,7 @@"add_section": "Add personas","builtin": "· built-in","configure_title": "Configure {{name}}",+ "open_title": "Open {{name}}: its settings and how it's been doing","connectors_tag": "connectors","default_for_new": "Default for new sessions","delete": "Delete",@@ -3940,6 +3941,7 @@"point_hint": "Point at a bar to see each part's tokens.","by_coworker": "By coworker","by_coworker_all": "All coworkers, for comparison",+ "open_history": "{{name}}: how it's been doing","coworker": "Coworker","automation": "(automation)","unknown_coworker": "unknown coworker",diff --git a/surfaces/gui/src/locales/zh.json b/surfaces/gui/src/locales/zh.jsonindex f0337eb5..a5f7f995 100644--- a/surfaces/gui/src/locales/zh.json+++ b/surfaces/gui/src/locales/zh.json@@ -1552,6 +1552,7 @@"add_section": "添加角色","builtin": "· 内置","configure_title": "配置 {{name}}",+ "open_title": "打开 {{name}}:设置和表现如何","connectors_tag": "连接器","default_for_new": "新会话默认角色","delete": "删除",@@ -3881,6 +3882,7 @@"point_hint": "指向柱形可查看每一部分的令牌数。","by_coworker": "按同事","by_coworker_all": "所有同事,供对比",+ "open_history": "{{name}}:表现如何","coworker": "同事","automation": "(自动化)","unknown_coworker": "未知同事",diff --git a/tests/test_observability_phase3_manual_fixes.py b/tests/test_observability_phase3_manual_fixes.pyindex 479e9a5e..1fc0f53f 100644--- a/tests/test_observability_phase3_manual_fixes.py+++ b/tests/test_observability_phase3_manual_fixes.py@@ -69,3 +69,42 @@ def test_overridden_is_counted_per_reviewer(tmp_path):assert rows["session_model"]["tokens"] == 320 and rows["openai_decisions"]["tokens"] == 55assert rows["typesafe_jev"]["tokens"] == 0store.close()+++# -- T3-12 ----------------------------------------------------------------------------------------+def test_the_default_coworkers_page_and_history_answer(tmp_path, monkeypatch):+ """Settings ▸ Coworkers now opens the default coworker's page too: its detail and its "How+ it's been doing" must answer for the default id, with its turns counted."""+ from fastapi.testclient import TestClient++ from coworker.personas.registry import DEFAULT_PERSONA_ID+ from coworker.providers import AssistantTurn, ModelCapabilities, ProviderClient+ from coworker.providers.base import TokenUsage+ from coworker.server import SessionManager, create_app+ from coworker.sessions import SessionRecord++ class _Scripted(ProviderClient):+ def complete(self, *, model, messages, tools=None, **settings):+ return AssistantTurn(text="Done.", finish_reason="stop", usage=TokenUsage(input=20, output=5))++ def capabilities(self, model):+ return ModelCapabilities()++ monkeypatch.setenv("COWORKER_STATE_DIR", str(tmp_path / "state"))+ manager = SessionManager(workspace=tmp_path, provider=_Scripted())+ client = TestClient(create_app(manager))+ manager.session_store.save(SessionRecord(session_id="s1", workspace=str(tmp_path), model="sample",+ mode="interactive", agent=DEFAULT_PERSONA_ID))+ with client.websocket_connect("/ws/session/s1") as ws:+ assert ws.receive_json()["type"] in ("ready", "export_notice")+ ws.send_json({"type": "user_message", "text": "hello"})+ while ws.receive_json()["type"] != "turn_done":+ pass+ detail = client.get(f"/v1/personas/{DEFAULT_PERSONA_ID}")+ assert detail.status_code == 200 and detail.json().get("default") is True+ doing = client.get(f"/v1/personas/{DEFAULT_PERSONA_ID}/doing", params={"days": 30})+ assert doing.status_code == 200, doing.text+ body = doing.json()+ assert body["persona_id"] == DEFAULT_PERSONA_ID and body["runs"] == 1, body+ assert sum(r["turns"] for r in body["rows"]) == 1+ manager.observability.close()