From c2bc98e36d56e20272ede44398dc7a6abc797326 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 19:04:47 +0000 Subject: [PATCH 1/2] FIX-2288: the Claude Code-style lab draws each task's model, harness and tokens listTasks rows now carry `spend` (taskSpendView). The lab passes it through on its task rows and draws it: the model and a token count on threads-mode cards, board rows and the thread view, and on session-mode cards, done rows and the task sheet; the sheet and thread view split input and output. A count no run has reported reads "no tokens reported yet", never 0. The harness tag prefers the harness the run reported, falling back to the worker's setting until then. The threads-mode goal now checks the coding card shows the model and token count its row carries. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01NczDiGf8XW5KXUhuTXYzh2 --- .../threads-mode-script/goal.md | 4 +- .../threads-mode-script/run.mts | 5 +++ labs/claude-code-style/README.md | 11 +++-- labs/claude-code-style/src/adapter.ts | 7 ++- .../src/components/Spend.tsx | 45 +++++++++++++++++++ .../src/components/TaskCard.tsx | 5 ++- .../src/components/TasksPane.tsx | 8 +++- .../src/components/ThreadCard.tsx | 2 + .../src/components/ThreadView.tsx | 2 + .../src/components/ThreadsBoard.tsx | 2 + labs/claude-code-style/test/fake-lab.ts | 23 +++++++--- labs/claude-code-style/test/screen.test.tsx | 5 +++ labs/claude-code-style/test/spend.test.ts | 38 ++++++++++++++++ .../test/threads-screen.test.tsx | 2 + 14 files changed, 147 insertions(+), 12 deletions(-) create mode 100644 labs/claude-code-style/src/components/Spend.tsx create mode 100644 labs/claude-code-style/test/spend.test.ts diff --git a/goals/claude-code-style-lab/threads-mode-script/goal.md b/goals/claude-code-style-lab/threads-mode-script/goal.md index 86f2a6de42..2b0d31a49a 100644 --- a/goals/claude-code-style-lab/threads-mode-script/goal.md +++ b/goals/claude-code-style-lab/threads-mode-script/goal.md @@ -33,7 +33,8 @@ worktrees from (`CLAUDE_CODE_STYLE_REPOSITORIES`). under *Resolved*. - **6** you ask for a code change: a task to `desk.thread-coder` is filed; its card and row are tagged *Claude Code*; it waits on your review (answering a question first, in its thread, if - the run asks), under *Ready for review*, with the judge's line on its card; *Resolve* completes + the run asks), under *Ready for review*, with the judge's line on its card and the model and + token count its row's `spend` carries (harness `claude-code`); *Resolve* completes it with output `review: "accepted"` and moves it under *Resolved*. The run worked in a worktree of the project's repository under the lab's data folder, whose branch, also in the repository, holds the CHANGELOG line; the repository's checked-out branch and files and the lab's checkout @@ -79,3 +80,4 @@ failed. | 2026-10-28 | 29bd1b9 | openai/gpt-5.4 | FAIL | Signal 6: the review column was read before the page's next 2s read; the worktree and its branch were right. The check now waits for the page (10ed30d) | | 2026-10-28 | 10ed30d | openai/gpt-5.4 | PASS | Attempt 1 of 3. Worktrees and the judge: the coding thread ran in a worktree of the project's repository under the data folder, its branch in the repository holding the CHANGELOG line, its card showed the judge's verdict, and *Resolve* completed it `review: "accepted"` | | 2026-10-28 | 10ed30d | openai/gpt-5.4 | FAIL (control `no-mapping`) | Signal 6: `the run didn't work in a worktree of the project's repository (1 clone(s) under the data folder)` | +| 2026-10-29 | (this change, on 9af8ce53) | openai/gpt-5.4 | PASS | Attempt 1 of 3. The coding card showed `claude-sonnet-5 · 291.2k tokens`, the model and count its row's `spend` carried; the run's harness read `claude-code` | diff --git a/goals/claude-code-style-lab/threads-mode-script/run.mts b/goals/claude-code-style-lab/threads-mode-script/run.mts index 30cc134984..e182b78292 100644 --- a/goals/claude-code-style-lab/threads-mode-script/run.mts +++ b/goals/claude-code-style-lab/threads-mode-script/run.mts @@ -329,6 +329,11 @@ async function attempt(n: number, failures: string[], notes: string[], tell: Tel if (shown === undefined) failures.push("6: the coding thread's row isn't under Ready for review"); const card = (await snapshot(page)).cards.find((c) => c.taskId === coding.id); if (!/judge/i.test(card?.text ?? "")) failures.push(`6: the card doesn't show the judge's verdict: ${JSON.stringify(card?.text ?? "")}`); + // What the run spent, read off the board's row: its model and a token count, never a 0 or a lab sum. + const spend = ((await board(sessionId, "listTasks_tasks", {}))?.tasks ?? []).find((t: any) => t.id === coding.id)?.spend; + if (spend?.harness !== "claude-code" || !spend.model) failures.push(`6: the board's row doesn't carry the run's harness and model: ${JSON.stringify(spend ?? null)}`); + else if (!card?.text.includes(spend.model) || !/\d(\.\d)?[kM]? tokens/.test(card.text)) failures.push(`6: the card doesn't show the run's model and tokens: ${JSON.stringify(card?.text ?? "")}`); + else notes.push(`6: the card shows ${spend.model}, ${(spend.inputTokens ?? 0) + (spend.outputTokens ?? 0)} tokens on the row`); await cardFor(coding.id).getByRole("button", { name: "Resolve" }).click(); const done = await until(async () => { const read = await taskOf(sessionId, coding.id); diff --git a/labs/claude-code-style/README.md b/labs/claude-code-style/README.md index 9633d57a7f..d952347ea1 100644 --- a/labs/claude-code-style/README.md +++ b/labs/claude-code-style/README.md @@ -83,6 +83,11 @@ under the data folder instead. Before a run settles, a judge (harness-manager's its answer and commits against the task's goal: it can send the run back, ask you a question, or let it through, and threads mode shows its verdict on the coding thread's card. +Every task card shows the model its run uses and a token count that rises while the run works, +and the harness tag names the harness the run reported. Finished rows keep the final total, and a +task's sheet or thread view splits it into input and output. All of it comes from the `spend` the +board's `listTasks` rows carry; the lab sums nothing itself. + Both modes are wired. The screen tests run on a test double, `test/fake-lab.ts`, which the app never imports. @@ -125,8 +130,8 @@ and on a flow over 200 lines; `--wired` also fails while a fixture is left in `s | Kind | Files | Lines | |---|---:|---:| -| Configuration | 18 | 494 | -| React UI | 28 | 2685 | +| Configuration | 18 | 499 | +| React UI | 29 | 2750 | | Small flows | 3 | 273 | -| Checks (not app code) | 9 | 1279 | +| Checks (not app code) | 10 | 1337 | diff --git a/labs/claude-code-style/src/adapter.ts b/labs/claude-code-style/src/adapter.ts index cb0c2015a1..3b47c0767d 100644 --- a/labs/claude-code-style/src/adapter.ts +++ b/labs/claude-code-style/src/adapter.ts @@ -23,6 +23,7 @@ import { createClient, type Client, type SessionSummary } from "@flow-state-dev/client"; import { readBearerToken, readUserId, withBearerToken } from "@flow-state-dev/devtool/react"; import { createInboxClient, inboxItems, type InboxAnswer, type InboxQuestion, type InboxRow, type TaskQuestion } from "@flow-state-dev/orchestration/inbox"; +import type { TaskSpendView } from "@flow-state-dev/orchestration/tasks"; import { createWorkforceClient, parseProjectRef, @@ -119,6 +120,8 @@ export interface TaskRow { steps?: { done: number; total: number }; /** When the task last changed, in ms. */ updatedAt?: number; + /** What its runs spent, as the board's `listTasks` reads it (`taskSpendView`): model, harness, tokens; none before it runs. */ + spend?: TaskSpendView; } /** The read-only work of one task. */ @@ -420,6 +423,7 @@ function createWiredLab(fsd: Client): LabAdapter { ...(typeof task.updatedAt === "number" ? { updatedAt: task.updatedAt } : {}), ...(task.run?.sessionId === undefined ? {} : { runSessionId: task.run.sessionId, run: task.run }), ...(Array.isArray(task.questions) ? { questions: task.questions } : {}), + ...(task.spend == null ? {} : { spend: task.spend }), })); }; @@ -484,7 +488,8 @@ function createWiredLab(fsd: Client): LabAdapter { listed.map(async (task): Promise => { const { runSessionId: _session, run: _run, questions: _questions, ...row } = task; const hold = holds.get(row.id)?.[0]; - const harness = await harnessOf(task); + // The harness its run reported; until one reports, the assignee's `harness` setting. + const harness = task.spend?.harness ?? (await harnessOf(task)); const review = harness !== undefined && row.status === "completed" ? await reviewOf(sessionId, task) : undefined; return { ...row, diff --git a/labs/claude-code-style/src/components/Spend.tsx b/labs/claude-code-style/src/components/Spend.tsx new file mode 100644 index 0000000000..78e006bec9 --- /dev/null +++ b/labs/claude-code-style/src/components/Spend.tsx @@ -0,0 +1,45 @@ +import type { TaskRow } from "../adapter"; +import { cn } from "../lib/utils"; + +/* + * What a task's runs spent, as its card, row and sheet show it: the model and + * a token count read from the board's row (`spend`), never summed here. The + * count rises while the run works, and stays as the final total once it ends. + */ + +/** 980, 12.4k, 1.2M. */ +export function tokenCount(n: number): string { + if (n < 1000) return String(n); + if (n < 1_000_000) return `${(n / 1000).toFixed(1)}k`; + return `${(n / 1_000_000).toFixed(1)}M`; +} + +/** + * "claude-sonnet-4-5 · 12.4k tokens", or with `split`, "… · 10.1k in · 2.3k + * out". Tokens nobody has reported yet read as such, never as 0. Empty when + * the task never ran. + */ +export function spendLine(task: TaskRow, split = false): string { + const spend = task.spend; + if (spend === undefined) return ""; + const tokens = + spend.inputTokens === null && spend.outputTokens === null + ? spend.unreported + ? "no tokens reported yet" + : "" + : split + ? `${tokenCount(spend.inputTokens ?? 0)} in · ${tokenCount(spend.outputTokens ?? 0)} out` + : `${tokenCount((spend.inputTokens ?? 0) + (spend.outputTokens ?? 0))} tokens`; + return [spend.model, tokens].filter(Boolean).join(" · "); +} + +/** The spend line under a card's status, or nothing for a task that never ran. */ +export function Spend({ task, split = false, className }: { task: TaskRow; split?: boolean; className?: string }) { + const line = spendLine(task, split); + if (!line) return null; + return ( + + {line} + + ); +} diff --git a/labs/claude-code-style/src/components/TaskCard.tsx b/labs/claude-code-style/src/components/TaskCard.tsx index 5b04cde693..bc6c7f8ce3 100644 --- a/labs/claude-code-style/src/components/TaskCard.tsx +++ b/labs/claude-code-style/src/components/TaskCard.tsx @@ -1,6 +1,7 @@ import type { TaskRow } from "../adapter"; import { TASK_STATUS } from "../lib/task-status"; import { cn } from "../lib/utils"; +import { Spend } from "./Spend"; /* * A background task as a list shows it: a full card while it runs or waits, @@ -29,12 +30,13 @@ export function TaskCard({ task, selected, onOpen }: { task: TaskRow; selected: {task.statusNote ? ` · "${task.statusNote}"` : ""} {task.assignee ? {task.assignee} : null} + ); } -/** A finished task, on one line: its mark, title and worker. */ +/** A finished task, on one line: its mark, title, worker and what it spent. */ export function TaskDoneRow({ task, selected, onOpen }: { task: TaskRow; selected: boolean; onOpen: () => void }) { const status = TASK_STATUS[task.status]; return ( @@ -51,6 +53,7 @@ export function TaskDoneRow({ task, selected, onOpen }: { task: TaskRow; selecte {task.title} {task.assignee ? {task.assignee} : null} + ); } diff --git a/labs/claude-code-style/src/components/TasksPane.tsx b/labs/claude-code-style/src/components/TasksPane.tsx index 181729f909..8919ecf89a 100644 --- a/labs/claude-code-style/src/components/TasksPane.tsx +++ b/labs/claude-code-style/src/components/TasksPane.tsx @@ -5,6 +5,7 @@ import { useWatch } from "../lib/use-watch"; import { cn } from "../lib/utils"; import { Entry } from "./Entry"; import { Sheet } from "./Sheet"; +import { Spend } from "./Spend"; import { TaskCard, TaskDoneRow } from "./TaskCard"; /** The endings a task stays in: these rows move to the pane's *Done* group. */ @@ -90,7 +91,12 @@ function TaskSheet({ adapter, sessionId, task, onClose }: { adapter: LabAdapter; } - subtitle={task.goal} + subtitle={ + <> + {task.goal} + + + } onClose={onClose} footer={READ_ONLY_NOTE} > diff --git a/labs/claude-code-style/src/components/ThreadCard.tsx b/labs/claude-code-style/src/components/ThreadCard.tsx index 808c61c841..7393fb3866 100644 --- a/labs/claude-code-style/src/components/ThreadCard.tsx +++ b/labs/claude-code-style/src/components/ThreadCard.tsx @@ -1,5 +1,6 @@ import type { LabAdapter, TaskRow } from "../adapter"; import { cn } from "../lib/utils"; +import { Spend } from "./Spend"; import { HarnessTag, statusColumn, statusLine, ThreadIcon } from "./ThreadStatus"; /** @@ -50,6 +51,7 @@ export function ThreadCard({
{statusLine(task)}
+ {column === "waiting" || column === "review" ? (
{column === "waiting" && task.status !== "errored" ? ( diff --git a/labs/claude-code-style/src/components/ThreadView.tsx b/labs/claude-code-style/src/components/ThreadView.tsx index 4fa4df9952..0af8af193e 100644 --- a/labs/claude-code-style/src/components/ThreadView.tsx +++ b/labs/claude-code-style/src/components/ThreadView.tsx @@ -2,6 +2,7 @@ import { useState, type FormEvent } from "react"; import type { LabAdapter, TaskRow } from "../adapter"; import { useWatch } from "../lib/use-watch"; import { Entry } from "./Entry"; +import { Spend } from "./Spend"; import { HarnessTag, statusColumn, statusLine, ThreadIcon } from "./ThreadStatus"; /** @@ -65,6 +66,7 @@ export function ThreadView({
{statusLine(task)}
+
{work?.entries.map((entry) => )}
diff --git a/labs/claude-code-style/src/components/ThreadsBoard.tsx b/labs/claude-code-style/src/components/ThreadsBoard.tsx index 95e724870b..2ea1ba6eff 100644 --- a/labs/claude-code-style/src/components/ThreadsBoard.tsx +++ b/labs/claude-code-style/src/components/ThreadsBoard.tsx @@ -3,6 +3,7 @@ import type { LabAdapter, TaskRow } from "../adapter"; import { COLUMNS, columnOf, type Column } from "../lib/columns"; import { age, useNow, useWatch } from "../lib/use-watch"; import { cn } from "../lib/utils"; +import { Spend } from "./Spend"; import { HarnessTag, statusLine, ThreadIcon } from "./ThreadStatus"; import { ThreadView } from "./ThreadView"; @@ -94,6 +95,7 @@ export function ThreadsBoard({ {task.steps ? `${task.steps.done}/${task.steps.total} · ` : ""} {rowNote(task)} + {task.updatedAt !== undefined ? ( {age(task.updatedAt, now)} diff --git a/labs/claude-code-style/test/fake-lab.ts b/labs/claude-code-style/test/fake-lab.ts index 1b11c7ded6..63a306b8b4 100644 --- a/labs/claude-code-style/test/fake-lab.ts +++ b/labs/claude-code-style/test/fake-lab.ts @@ -61,6 +61,9 @@ interface FixtureSession { type Step = [delayMs: number, run: () => void, background?: "background"]; const MINUTE = 60_000; +/** The models the fake's runs report: a researcher's, and Claude Code's. */ +const RESEARCH_MODEL = "openai/gpt-6-luna"; +const CODE_MODEL = "claude-sonnet-4-5"; /** fake: stands in for the whole package until wiring. */ export function createFakeLab(options: FakeOptions = {}): LabAdapter { @@ -151,8 +154,18 @@ export function createFakeLab(options: FakeOptions = {}): LabAdapter { setTask(s, task.id, { ...patch, work }); }; + /** A row's `spend`, as the board's `listTasks` reads it. */ + const spent = (model: string, inputTokens: number | null, outputTokens: number | null, live: boolean, harness: string | null = null): FixtureTask["spend"] => ({ + harness, + model, + inputTokens, + outputTokens, + unreported: inputTokens === null, + live, + }); + const file = (s: FixtureSession, title: string, goal: string, note: string): Step[1] => () => { - const task = startTask(title, goal, note, { assignee: "desk.researcher" }); + const task = startTask(title, goal, note, { assignee: "desk.researcher", spend: spent(RESEARCH_MODEL, 1200, 300, true) }); s.tasks = [...s.tasks, task]; push(s, { kind: "tool", id: nextId("tool"), name: "createTask", summary: `${title} → researcher` }); }; @@ -163,7 +176,7 @@ export function createFakeLab(options: FakeOptions = {}): LabAdapter { const settle = (s: FixtureSession, title: string, summary: string): Step[1] => () => { const task = s.tasks.find((t) => t.title === title); if (!task || task.status !== "in_progress") return; - writeStep(s, task, { status: "completed", statusNote: undefined }, summary); + writeStep(s, task, { status: "completed", statusNote: undefined, spend: spent(RESEARCH_MODEL, 5400, 900, false) }, summary); // fake: stands in for the main worker's `answerAgain: true` (FIX-2159): the take shows as an item in the running request. push(s, { kind: "result", @@ -250,11 +263,11 @@ export function createFakeLab(options: FakeOptions = {}): LabAdapter { const codeScript = (s: FixtureSession, text: string, origin: string): Step[] => { const ref: Ref = {}; return [ - [600, fileThread(s, origin, ref, text.split("\n")[0].slice(0, 60), text, "Editing CHANGELOG.md", { assignee: "desk.coder", harness: "claude-code" })], + [600, fileThread(s, origin, ref, text.split("\n")[0].slice(0, 60), text, "Editing CHANGELOG.md", { assignee: "desk.coder", harness: "claude-code", spend: spent(CODE_MODEL, null, null, true, "claude-code") })], [400, say(s, "I've started a Claude Code thread for it, in this session's project.")], [200, () => endTurn(s)], - [1200, advance(s, ref, { statusNote: "Committing" }, "Committing: docs: note the vendor pick"), "background"], - [800, advance(s, ref, review("Judge: pass · 1 commit · adds the vendor line to CHANGELOG.md"), "One commit, CHANGELOG.md only."), "background"], + [1200, advance(s, ref, { statusNote: "Committing", spend: spent(CODE_MODEL, 8200, 1100, true, "claude-code") }, "Committing: docs: note the vendor pick"), "background"], + [800, advance(s, ref, { ...review("Judge: pass · 1 commit · adds the vendor line to CHANGELOG.md"), spend: spent(CODE_MODEL, 12000, 1600, true, "claude-code") }, "One commit, CHANGELOG.md only."), "background"], ]; }; diff --git a/labs/claude-code-style/test/screen.test.tsx b/labs/claude-code-style/test/screen.test.tsx index 90581d5dde..06aa093f8c 100644 --- a/labs/claude-code-style/test/screen.test.tsx +++ b/labs/claude-code-style/test/screen.test.tsx @@ -162,6 +162,8 @@ describe("the session-mode screen", () => { expect(thread().parentElement!.contains(work)).toBe(true); expect(row("Research Globex").getAttribute("aria-expanded")).toBe("true"); expect(within(work).getByText(/Starting:/)).toBeTruthy(); + // What its run has spent so far, split as the board's row reports it. + expect(within(work).getByText("openai/gpt-6-luna · 1.2k in · 300 out")).toBeTruthy(); expect(within(work).getByText(/To stop or steer a task, ask the main session/)).toBeTruthy(); expect(within(work).queryByRole("button", { name: /stop|cancel/i })).toBeNull(); expect(within(work).queryByRole("textbox")).toBeNull(); @@ -203,6 +205,9 @@ describe("the session-mode screen", () => { expect(done.open).toBe(false); expect(within(done).getByRole("button", { name: /Research Acme/, hidden: true })).toBeTruthy(); expect(within(done).queryByText("Research Globex")).toBeNull(); + // The running card shows its live count; the done row, the final total its run reported. + expect(within(row("Research Globex")).getByText("openai/gpt-6-luna · 1.5k tokens").dataset.spend).toBe("live"); + expect(within(done).getByText("openai/gpt-6-luna · 6.3k tokens", { selector: "[data-spend]" }).dataset.spend).toBe("final"); // A finished row still opens like any task. done.open = true; diff --git a/labs/claude-code-style/test/spend.test.ts b/labs/claude-code-style/test/spend.test.ts new file mode 100644 index 0000000000..c3574abf2e --- /dev/null +++ b/labs/claude-code-style/test/spend.test.ts @@ -0,0 +1,38 @@ +/** + * The spend line a task's card, row and sheet draw from its row's `spend`: + * a count nobody has reported reads as such, never as 0, since a 0 would say + * the run spent nothing. + */ +import { describe, expect, it } from "vitest"; +import type { TaskRow } from "../src/adapter"; +import { spendLine, tokenCount } from "../src/components/Spend"; + +const task = (spend?: TaskRow["spend"]): TaskRow => ({ id: "t1", title: "t", goal: "g", status: "in_progress", ...(spend ? { spend } : {}) }); +const spend = (inputTokens: number | null, outputTokens: number | null, unreported = false): TaskRow["spend"] => ({ + harness: "claude-code", + model: "claude-sonnet-4-5", + inputTokens, + outputTokens, + unreported, + live: true, +}); + +describe("a task's spend line", () => { + it("is empty for a task that never ran", () => { + expect(spendLine(task())).toBe(""); + }); + + it("names the model and says no tokens are reported yet, never 0, before the run reports", () => { + expect(spendLine(task(spend(null, null, true)))).toBe("claude-sonnet-4-5 · no tokens reported yet"); + expect(spendLine(task(spend(null, null, true)), true)).not.toMatch(/\b0\b/); + }); + + it("sums input and output on a card, and splits them on the sheet", () => { + expect(spendLine(task(spend(10_100, 2_300)))).toBe("claude-sonnet-4-5 · 12.4k tokens"); + expect(spendLine(task(spend(10_100, 2_300)), true)).toBe("claude-sonnet-4-5 · 10.1k in · 2.3k out"); + }); + + it("shortens counts to k and M", () => { + expect([tokenCount(980), tokenCount(12_400), tokenCount(1_250_000)]).toEqual(["980", "12.4k", "1.3M"]); + }); +}); diff --git a/labs/claude-code-style/test/threads-screen.test.tsx b/labs/claude-code-style/test/threads-screen.test.tsx index 9d1cb86c28..6d3fb502ff 100644 --- a/labs/claude-code-style/test/threads-screen.test.tsx +++ b/labs/claude-code-style/test/threads-screen.test.tsx @@ -133,6 +133,8 @@ describe("the threads-mode screen", () => { expect(within(coder).getByText("Claude Code")).toBeTruthy(); await waitFor(() => expect(coder.dataset.column).toBe("review")); expect(coder.textContent).toMatch(/Ready for review · Judge: pass · 1 commit/); + // The model and tokens its Claude Code run reported, read off the board's row. + expect(within(coder).getByText("claude-sonnet-4-5 · 13.6k tokens")).toBeTruthy(); expect(rowsIn("Ready for review").join()).toMatch(/Claude Code/); fireEvent.click(within(coder).getByRole("button", { name: "Resolve" })); await waitFor(() => expect(coder.dataset.column).toBe("resolved")); From a9941464089c98bc74b47098ac9dfda89d76b67e Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 19:06:52 +0000 Subject: [PATCH 2/2] FIX-2288: fold #4181's spend wording into the lab's spend line From the duplicate session-mode change (#4181, FIX-2324): a count still missing a source is marked partial, a side of the split nobody reported reads "not reported", and session-mode cards and the task sheet, which have no harness tag, name the harness first. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01NczDiGf8XW5KXUhuTXYzh2 --- labs/claude-code-style/README.md | 9 ++++--- .../src/components/Spend.tsx | 26 +++++++++++-------- .../src/components/TaskCard.tsx | 2 +- .../src/components/TasksPane.tsx | 2 +- .../src/components/ThreadStatus.tsx | 2 +- labs/claude-code-style/test/spend.test.ts | 14 ++++++++-- 6 files changed, 35 insertions(+), 20 deletions(-) diff --git a/labs/claude-code-style/README.md b/labs/claude-code-style/README.md index d952347ea1..eecc5d5377 100644 --- a/labs/claude-code-style/README.md +++ b/labs/claude-code-style/README.md @@ -85,7 +85,8 @@ let it through, and threads mode shows its verdict on the coding thread's card. Every task card shows the model its run uses and a token count that rises while the run works, and the harness tag names the harness the run reported. Finished rows keep the final total, and a -task's sheet or thread view splits it into input and output. All of it comes from the `spend` the +task's sheet or thread view splits it into input and output. A count no run has reported reads +"no tokens reported yet", never 0, and one still missing a source is marked partial. All of it comes from the `spend` the board's `listTasks` rows carry; the lab sums nothing itself. Both modes are wired. The screen tests run on a test double, `test/fake-lab.ts`, which the app @@ -130,8 +131,8 @@ and on a flow over 200 lines; `--wired` also fails while a fixture is left in `s | Kind | Files | Lines | |---|---:|---:| -| Configuration | 18 | 499 | -| React UI | 29 | 2750 | +| Configuration | 18 | 500 | +| React UI | 29 | 2754 | | Small flows | 3 | 273 | -| Checks (not app code) | 10 | 1337 | +| Checks (not app code) | 10 | 1347 | diff --git a/labs/claude-code-style/src/components/Spend.tsx b/labs/claude-code-style/src/components/Spend.tsx index 78e006bec9..7a0f616cbe 100644 --- a/labs/claude-code-style/src/components/Spend.tsx +++ b/labs/claude-code-style/src/components/Spend.tsx @@ -1,10 +1,13 @@ import type { TaskRow } from "../adapter"; import { cn } from "../lib/utils"; +import { HARNESS_LABEL } from "./ThreadStatus"; /* * What a task's runs spent, as its card, row and sheet show it: the model and * a token count read from the board's row (`spend`), never summed here. The * count rises while the run works, and stays as the final total once it ends. + * A count nobody reported reads as such, never as 0; one still missing a + * source is marked partial. */ /** 980, 12.4k, 1.2M. */ @@ -16,26 +19,27 @@ export function tokenCount(n: number): string { /** * "claude-sonnet-4-5 · 12.4k tokens", or with `split`, "… · 10.1k in · 2.3k - * out". Tokens nobody has reported yet read as such, never as 0. Empty when - * the task never ran. + * out"; with `harness`, the harness's name first, for a view with no harness + * tag. Empty when the task never ran. */ -export function spendLine(task: TaskRow, split = false): string { +export function spendLine(task: TaskRow, { split = false, harness = false } = {}): string { const spend = task.spend; if (spend === undefined) return ""; + const partial = spend.unreported ? " (partial)" : ""; + const side = (n: number | null) => (n === null ? "not reported" : tokenCount(n)); const tokens = spend.inputTokens === null && spend.outputTokens === null - ? spend.unreported - ? "no tokens reported yet" - : "" + ? "no tokens reported yet" : split - ? `${tokenCount(spend.inputTokens ?? 0)} in · ${tokenCount(spend.outputTokens ?? 0)} out` - : `${tokenCount((spend.inputTokens ?? 0) + (spend.outputTokens ?? 0))} tokens`; - return [spend.model, tokens].filter(Boolean).join(" · "); + ? `${side(spend.inputTokens)} in · ${side(spend.outputTokens)} out${partial}` + : `${tokenCount((spend.inputTokens ?? 0) + (spend.outputTokens ?? 0))} tokens${partial}`; + const named = harness && spend.harness !== null ? (HARNESS_LABEL[spend.harness] ?? spend.harness) : null; + return [named, spend.model, tokens].filter(Boolean).join(" · "); } /** The spend line under a card's status, or nothing for a task that never ran. */ -export function Spend({ task, split = false, className }: { task: TaskRow; split?: boolean; className?: string }) { - const line = spendLine(task, split); +export function Spend({ task, split = false, harness = false, className }: { task: TaskRow; split?: boolean; harness?: boolean; className?: string }) { + const line = spendLine(task, { split, harness }); if (!line) return null; return ( diff --git a/labs/claude-code-style/src/components/TaskCard.tsx b/labs/claude-code-style/src/components/TaskCard.tsx index bc6c7f8ce3..27284a8bb7 100644 --- a/labs/claude-code-style/src/components/TaskCard.tsx +++ b/labs/claude-code-style/src/components/TaskCard.tsx @@ -30,7 +30,7 @@ export function TaskCard({ task, selected, onOpen }: { task: TaskRow; selected: {task.statusNote ? ` · "${task.statusNote}"` : ""} {task.assignee ? {task.assignee} : null} - + ); diff --git a/labs/claude-code-style/src/components/TasksPane.tsx b/labs/claude-code-style/src/components/TasksPane.tsx index 8919ecf89a..bbefbd1ee9 100644 --- a/labs/claude-code-style/src/components/TasksPane.tsx +++ b/labs/claude-code-style/src/components/TasksPane.tsx @@ -94,7 +94,7 @@ function TaskSheet({ adapter, sessionId, task, onClose }: { adapter: LabAdapter; subtitle={ <> {task.goal} - + } onClose={onClose} diff --git a/labs/claude-code-style/src/components/ThreadStatus.tsx b/labs/claude-code-style/src/components/ThreadStatus.tsx index c7b9011bfa..e5d302cb89 100644 --- a/labs/claude-code-style/src/components/ThreadStatus.tsx +++ b/labs/claude-code-style/src/components/ThreadStatus.tsx @@ -3,7 +3,7 @@ import { COLUMNS, columnOf } from "../lib/columns"; import { cn } from "../lib/utils"; /** A harness's name as a card and row tag it. */ -const HARNESS_LABEL: Record = { "claude-code": "Claude Code", codex: "Codex", cursor: "Cursor" }; +export const HARNESS_LABEL: Record = { "claude-code": "Claude Code", codex: "Codex", cursor: "Cursor" }; /** The thread's column, ignoring pins: a pinned thread keeps its status icon and line. */ export const statusColumn = (task: TaskRow) => columnOf(task, false); diff --git a/labs/claude-code-style/test/spend.test.ts b/labs/claude-code-style/test/spend.test.ts index c3574abf2e..bc4b1a605e 100644 --- a/labs/claude-code-style/test/spend.test.ts +++ b/labs/claude-code-style/test/spend.test.ts @@ -24,12 +24,22 @@ describe("a task's spend line", () => { it("names the model and says no tokens are reported yet, never 0, before the run reports", () => { expect(spendLine(task(spend(null, null, true)))).toBe("claude-sonnet-4-5 · no tokens reported yet"); - expect(spendLine(task(spend(null, null, true)), true)).not.toMatch(/\b0\b/); + expect(spendLine(task(spend(null, null, true)), { split: true })).toBe("claude-sonnet-4-5 · no tokens reported yet"); }); it("sums input and output on a card, and splits them on the sheet", () => { expect(spendLine(task(spend(10_100, 2_300)))).toBe("claude-sonnet-4-5 · 12.4k tokens"); - expect(spendLine(task(spend(10_100, 2_300)), true)).toBe("claude-sonnet-4-5 · 10.1k in · 2.3k out"); + expect(spendLine(task(spend(10_100, 2_300)), { split: true })).toBe("claude-sonnet-4-5 · 10.1k in · 2.3k out"); + }); + + it("marks a count still missing a source as partial, and a side nobody reported as not reported", () => { + expect(spendLine(task(spend(10_100, 2_300, true)))).toBe("claude-sonnet-4-5 · 12.4k tokens (partial)"); + expect(spendLine(task(spend(10_100, null, true)), { split: true })).toBe("claude-sonnet-4-5 · 10.1k in · not reported out (partial)"); + }); + + it("names the harness first where no harness tag shows it, and leaves out what nobody named", () => { + expect(spendLine(task(spend(10_100, 2_300)), { harness: true })).toBe("Claude Code · claude-sonnet-4-5 · 12.4k tokens"); + expect(spendLine(task({ ...spend(10_100, 2_300)!, harness: null, model: null }), { harness: true })).toBe("12.4k tokens"); }); it("shortens counts to k and M", () => {