Match T3 Code's sidebar, timeline and composer

Reuse the web app's timeline derivation (turn folds, work groups, live
work), its sidebar sections and status words, steer-by-default sending,
the question panel, decline-with-feedback, and visit/read marking.
This commit is contained in:
Callum Alpass committed 2026-11-02 17:35:56 +11:00
1 parent 4f42407099
commit 2dac4763d2
17 files changed
+988 -430

No files matched your search

+26 -3
View File
@@ -19,12 +19,35 @@ const isCommand = Schema.is(OrchestrationV2Command);
const threadId = ThreadId.make("thread-1");
describe("commands tui3 dispatches", () => {
test("a queued message is a valid message.dispatch", async () => {
test("messages dispatch like the web composer: auto, steer or queue", async () => {
const { session, sent } = capturingSession();
await session.sendMessage(threadId, "hello");
expect(sent).toHaveLength(1);
await session.sendMessage(threadId, "change course", "steer");
await session.sendMessage(threadId, "after that", "queue");
expect(sent.every(isCommand)).toBe(true);
expect(sent[0]).toMatchObject({ type: "message.dispatch", threadId, text: "hello", dispatchMode: { type: "start_immediately" }, deliveryIntent: "auto" });
expect(sent[1]).toMatchObject({ dispatchMode: { type: "start_immediately" }, deliveryIntent: "steer" });
expect(sent[2]).toMatchObject({ dispatchMode: { type: "queue_after_active" } });
expect(sent[2]).not.toHaveProperty("deliveryIntent");
});
test("declining with feedback, answering and dismissing questions are valid", async () => {
const { session, sent } = capturingSession();
const requestId = RuntimeRequestId.make("req-1");
await session.respond(threadId, requestId, "decline", "use the staging bucket");
await session.answer(threadId, requestId, { q1: "yes", q2: ["a", "b"] });
await session.dismissQuestion(threadId, requestId);
expect(sent.every(isCommand)).toBe(true);
expect(sent[0]).toMatchObject({ decision: "decline", feedback: "use the staging bucket" });
expect(sent[1]).toMatchObject({ type: "runtime-request.respond", answers: { q1: "yes", q2: ["a", "b"] } });
expect(sent[2]).toMatchObject({ type: "thread.user-input.dismiss" });
});
test("a visit is a valid thread.visit", async () => {
const { session, sent } = capturingSession();
await session.visit(threadId);
expect(isCommand(sent[0])).toBe(true);
expect(sent[0]).toMatchObject({ type: "message.dispatch", threadId, text: "hello", dispatchMode: { type: "queue_after_active" } });
expect(sent[0]).toMatchObject({ type: "thread.visit", threadId, opened: true });
});
test("an approval is a valid runtime-request.respond", async () => {
+41 -9
View File
@@ -2,7 +2,7 @@ import { describe, expect, test } from "bun:test";
import type { OrchestrationV2ShellSnapshot } from "@t3tools/contracts";
import * as DateTime from "effect/DateTime";
import { findThread, relativeTime, threadRows } from "../src/model/threads.ts";
import { findThread, relativeTime, statusLabel, threadRows } from "../src/model/threads.ts";
const at = (ms: number) => DateTime.makeUnsafe(ms);
const thread = (id: string, title: string, updated: number, extra: Record<string, unknown> = {}) => ({
@@ -11,7 +11,23 @@ const thread = (id: string, title: string, updated: number, extra: Record<string
projectId: "p1",
status: "completed",
activeRunId: null,
latestRunId: "run-1",
latestRunRequestedAt: at(updated - 100),
latestRunStartedAt: at(updated - 90),
latestRunCompletedAt: at(updated),
pendingRuntimeRequest: null,
latestUserMessageAt: null,
lineage: { relationshipToParent: null, parentThreadId: null },
modelSelection: { instanceId: "codex", model: "gpt" },
archivedAt: null,
deletedAt: null,
settledOverride: null,
settledAt: null,
pinnedAt: null,
lastVisitedAt: at(updated + 1),
hasActionableProposedPlan: false,
interactionMode: "default",
createdAt: at(0),
updatedAt: at(updated),
...extra,
});
@@ -19,21 +35,36 @@ const snapshot = {
projects: [{ id: "p1", title: "tasknotes", workspaceRoot: "/home/me/tasknotes" }],
threads: [
thread("mcp:launch:aaaa1111", "old finished", 1_000),
thread("t-running", "busy one", 2_000, { status: "running", activeRunId: "r1" }),
thread("t-waiting", "wants approval", 500, { status: "running", activeRunId: "r2", pendingRuntimeRequest: { id: "q", kind: "command", createdAt: at(0) } }),
thread("t-new", "newest finished", 3_000),
thread("t-running", "busy one", 2_000, { status: "running", activeRunId: "run-1", latestRunCompletedAt: null }),
thread("t-waiting", "wants approval", 500, { status: "running", activeRunId: "run-1", latestRunCompletedAt: null, pendingRuntimeRequest: { id: "q", kind: "command", createdAt: at(0) } }),
thread("t-new", "newest finished", 3_000, { lastVisitedAt: at(10) }),
thread("t-settled", "put away", 4_000, { settledOverride: "settled", settledAt: at(4_000) }),
thread("t-child", "a subagent", 5_000, { lineage: { relationshipToParent: "subagent", parentThreadId: "t-new" } }),
],
} as unknown as OrchestrationV2ShellSnapshot;
describe("threadRows", () => {
test("orders needs-you, then running, then recent by activity", () => {
expect(threadRows(snapshot).map((row) => row.thread.id as string)).toEqual(["t-waiting", "t-running", "t-new", "mcp:launch:aaaa1111"]);
test("uses the web sidebar's sections and leaves subagents under their parent", () => {
expect(threadRows(snapshot).map((row) => [row.thread.id as string, row.section])).toEqual([
["t-new", "active"],
["mcp:launch:aaaa1111", "active"],
["t-waiting", "active"],
["t-running", "working"],
["t-settled", "settled"],
]);
});
test("filters by title or project and caps recent rows", () => {
test("shows the sidebar's status words", () => {
const byId = new Map(threadRows(snapshot).map((row) => [row.thread.id as string, row]));
expect(statusLabel(byId.get("t-waiting")!)?.text).toBe("Approval");
expect(statusLabel(byId.get("t-new")!)?.text).toBe("Done");
expect(statusLabel(byId.get("mcp:launch:aaaa1111")!)).toBeNull();
expect(statusLabel(byId.get("t-running")!, 2_000 + 75_000)?.text).toBe("Working 1m");
});
test("filters by title or project", () => {
expect(threadRows(snapshot, { query: "BUSY" }).map((row) => row.thread.id as string)).toEqual(["t-running"]);
expect(threadRows(snapshot, { query: "tasknotes" })).toHaveLength(4);
expect(threadRows(snapshot, { recentLimit: 1 }).map((row) => row.group)).toEqual(["needs-you", "running", "recent"]);
expect(threadRows(snapshot, { query: "tasknotes" })).toHaveLength(5);
});
});
@@ -46,6 +77,7 @@ describe("findThread", () => {
});
test("relativeTime", () => {
expect(relativeTime(0, 2_000)).toBe("now");
expect(relativeTime(0, 45_000)).toBe("45s");
expect(relativeTime(0, 3 * 3600_000)).toBe("3h");
});
-49
View File
@@ -27,52 +27,3 @@ describe("blockFor", () => {
expect(blockFor(item({ type: "checkpoint" }), new Set())).toBeNull();
});
});
import type { OrchestrationV2ThreadProjection } from "@t3tools/contracts";
import { buildTranscript, summarizeWork } from "../src/model/transcript.ts";
const projectionOf = (items: OrchestrationV2TurnItem[], pendingIds: string[] = []) =>
({
runtimeRequests: pendingIds.map((id) => ({ id, status: "pending" })),
visibleTurnItems: items.map((entry, position) => ({ position, item: entry })),
}) as unknown as OrchestrationV2ThreadProjection;
let counter = 0;
const turn = (fields: Record<string, unknown>) => item({ id: `i${counter++}`, ...fields });
describe("buildTranscript", () => {
test("folds runs of work between messages into one segment", () => {
const transcript = buildTranscript(
projectionOf([
turn({ type: "user_message", text: "fix it" }),
turn({ type: "command_execution", input: "ls" }),
turn({ type: "reasoning", text: "thinking", streaming: false }),
turn({ type: "file_change", fileName: "a.ts" }),
turn({ type: "assistant_message", text: "done", streaming: false }),
]),
);
expect(transcript.segments.map((segment) => segment.kind)).toEqual(["user", "work", "assistant"]);
const work = transcript.segments[1];
expect(work?.kind === "work" && summarizeWork(work.steps)).toBe("1 command · 1 edit");
});
test("marks trailing work active while the thread runs", () => {
const transcript = buildTranscript(projectionOf([turn({ type: "command_execution", input: "make" })]), { running: true });
expect(transcript.segments[0]).toMatchObject({ kind: "work", active: true });
});
test("errors break out of folded work", () => {
const transcript = buildTranscript(projectionOf([turn({ type: "command_execution", input: "a" }), turn({ type: "error", failure: { message: "boom" } }), turn({ type: "command_execution", input: "b" })]));
expect(transcript.segments.map((segment) => segment.kind)).toEqual(["work", "alert", "work"]);
});
test("reuses unchanged segments so the view can skip them", () => {
const user = turn({ type: "user_message", text: "hi" });
const command = turn({ type: "command_execution", input: "ls" });
const first = buildTranscript(projectionOf([user, command, turn({ type: "assistant_message", text: "He", streaming: true })]));
const second = buildTranscript(projectionOf([user, command, turn({ type: "assistant_message", text: "Hello", streaming: true })]), { previous: first });
expect(second.segments[0]).toBe(first.segments[0]!);
expect(second.segments[1]).toBe(first.segments[1]!);
expect(second.segments[2]).not.toBe(first.segments[2]!);
});
});