Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion goals/claude-code-style-lab/threads-mode-script/goal.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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` |
5 changes: 5 additions & 0 deletions goals/claude-code-style-lab/threads-mode-script/run.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment thread
jhoffner marked this conversation as resolved.
Resolved
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);
Expand Down
8 changes: 7 additions & 1 deletion labs/claude-code-style/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ 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. 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
never imports.

Expand Down Expand Up @@ -128,5 +134,5 @@ and on a flow over 200 lines; `--wired` also fails while a fixture is left in `s
| Configuration | 18 | 501 |
| React UI | 28 | 2685 |
| Small flows | 3 | 273 |
| Checks (not app code) | 9 | 1279 |
| Checks (not app code) | 10 | 1347 |
<!-- inventory:end -->
7 changes: 6 additions & 1 deletion labs/claude-code-style/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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 }),
}));
};

Expand Down Expand Up @@ -484,7 +488,8 @@ function createWiredLab(fsd: Client): LabAdapter {
listed.map(async (task): Promise<TaskRow> => {
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));
Comment thread
jhoffner marked this conversation as resolved.
Resolved
const review = harness !== undefined && row.status === "completed" ? await reviewOf(sessionId, task) : undefined;
return {
...row,
Expand Down
49 changes: 49 additions & 0 deletions labs/claude-code-style/src/components/Spend.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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.
*/
Comment thread
jhoffner marked this conversation as resolved.
Resolved

/** 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"; with `harness`, the harness's name first, for a view with no harness
Comment thread
jhoffner marked this conversation as resolved.
Resolved
* tag. Empty when the task never ran.
*/
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
Comment thread
jhoffner marked this conversation as resolved.
Resolved
? "no tokens reported yet"
: split
? `${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, harness = false, className }: { task: TaskRow; split?: boolean; harness?: boolean; className?: string }) {
const line = spendLine(task, { split, harness });
if (!line) return null;
return (
<span className={cn("block truncate font-mono text-[10px] text-muted-foreground", className)} data-spend={task.spend?.live ? "live" : "final"}>
{line}
</span>
);
}
5 changes: 4 additions & 1 deletion labs/claude-code-style/src/components/TaskCard.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -29,12 +30,13 @@ export function TaskCard({ task, selected, onOpen }: { task: TaskRow; selected:
{task.statusNote ? ` · "${task.statusNote}"` : ""}
</span>
{task.assignee ? <span className="block text-xs text-muted-foreground">{task.assignee}</span> : null}
<Spend task={task} harness />
</span>
</button>
);
}

/** 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 (
Expand All @@ -51,6 +53,7 @@ export function TaskDoneRow({ task, selected, onOpen }: { task: TaskRow; selecte
{task.title}
</span>
{task.assignee ? <span className="shrink-0 text-muted-foreground">{task.assignee}</span> : null}
<Spend task={task} className="shrink-0" />
</button>
);
}
8 changes: 7 additions & 1 deletion labs/claude-code-style/src/components/TasksPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -90,7 +91,12 @@ function TaskSheet({ adapter, sessionId, task, onClose }: { adapter: LabAdapter;
</span>
</span>
}
subtitle={task.goal}
subtitle={
<>
{task.goal}
<Spend task={task} split harness />
</>
}
onClose={onClose}
footer={READ_ONLY_NOTE}
>
Expand Down
2 changes: 2 additions & 0 deletions labs/claude-code-style/src/components/ThreadCard.tsx
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand Down Expand Up @@ -50,6 +51,7 @@ export function ThreadCard({
<HarnessTag task={task} />
</div>
<div className="truncate text-xs text-muted-foreground">{statusLine(task)}</div>
<Spend task={task} />
{column === "waiting" || column === "review" ? (
<div className="mt-1.5 flex gap-1.5">
{column === "waiting" && task.status !== "errored" ? (
Expand Down
2 changes: 1 addition & 1 deletion labs/claude-code-style/src/components/ThreadStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = { "claude-code": "Claude Code", codex: "Codex", cursor: "Cursor" };
export const HARNESS_LABEL: Record<string, string> = { "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);
Expand Down
2 changes: 2 additions & 0 deletions labs/claude-code-style/src/components/ThreadView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down Expand Up @@ -65,6 +66,7 @@ export function ThreadView({
</button>
</div>
<div className="px-4 pt-2 text-xs text-muted-foreground">{statusLine(task)}</div>
<Spend task={task} split className="px-4" />
<div className="flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto px-4 py-2">
{work?.entries.map((entry) => <Entry key={entry.id} entry={entry} />)}
</div>
Expand Down
2 changes: 2 additions & 0 deletions labs/claude-code-style/src/components/ThreadsBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -94,6 +95,7 @@ export function ThreadsBoard({
{task.steps ? `${task.steps.done}/${task.steps.total} · ` : ""}
{rowNote(task)}
</span>
<Spend task={task} />
</span>
{task.updatedAt !== undefined ? (
<span className="shrink-0 font-mono text-[10px] text-muted-foreground">{age(task.updatedAt, now)}</span>
Expand Down
23 changes: 18 additions & 5 deletions labs/claude-code-style/test/fake-lab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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` });
};
Expand All @@ -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",
Expand Down Expand Up @@ -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"],
];
};

Expand Down
5 changes: 5 additions & 0 deletions labs/claude-code-style/test/screen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
Loading
Loading