Fit streamed markdown tables to their content, and test that replies don't jump
Replies already stream through <markdown streaming>; tables now size to their cells with the theme's border colour. Tests cover tables mid-stream and settled, the newest line staying in view, and a scrolled-up view staying still.
This commit is contained in:
1 parent
d87026a66b
commit
a9a4b47566
5 files changed
+78
-4
No files matched your search
+1
-1
@@ -96,7 +96,7 @@ Typing a trigger opens a list of suggestions above the box:
|
||||
The layout follows T3 Code's web app, and much of it uses the web app's own code.
|
||||
|
||||
- **Sidebar:** the same sections as the app (Pinned, Active, Working, then Snoozed and Settled folded to a count) and the same status words: `Working 2m`, `Waiting`, `Approval`, `Input`, `Request`, `Limited`, `Failed`, `Done`. Threads that need you are bold.
|
||||
- **Conversation:** each finished turn's work folds into one line (`Worked for 3m 12s`), your messages sit in a raised block with a bar down the left, and a running turn shows its live step and `Working for 12s`. Threads open scrolled to the bottom. Long threads load as a window of recent turns; press `o` for older ones.
|
||||
- **Conversation:** each finished turn's work folds into one line (`Worked for 3m 12s`), your messages sit in a raised block with a bar down the left, and a running turn shows its live step and `Working for 12s`. Replies render as markdown while they stream, tables included, and settle into their final form when done; at the bottom the newest line stays in view, and scrolled up the text you're reading stays put. Threads open scrolled to the bottom. Long threads load as a window of recent turns; press `o` for older ones.
|
||||
- **Turns:** `[`/`]` select a turn and mark its prompt. `R` or `Revert to this turn` asks `Edit from here?`, then rewinds the chat and returns the prompt to the message box, keeping file changes. `Revert files too` in the palette also restores files, including your own edits. Stop a running turn first. Rewinding messages with attachments still needs the app.
|
||||
- **Command output:** expand work with `e` / `Expand all work`, or click a command. Output streams while its expanded row is in view; collapsing it, scrolling away or opening another thread stops it.
|
||||
- **Thread details:** a column beside the conversation with the workspace, model and mode, the branch with ahead/behind and its pull request, uncommitted changes per file, lineage (forks and subagents), background work and the goal. It opens by itself on terminals 160 columns or wider; on narrow ones `d` shows it in place of the conversation.
|
||||
|
||||
@@ -179,7 +179,7 @@ const Row = memo(function Row(props: {
|
||||
if (message.role === "system") return <text marginTop={1} fg={colors.muted} onMouseDown={(event: MouseEvent) => isRightClick(event) && mouse.menu(menu)}>{message.text}</text>;
|
||||
return (
|
||||
<box marginTop={1} flexDirection="column" onMouseDown={(event: MouseEvent) => isRightClick(event) && mouse.menu(menu)}>
|
||||
<markdown content={message.text || "…"} syntaxStyle={markdownStyle} streaming={message.streaming} conceal />
|
||||
<markdown content={message.text || "…"} syntaxStyle={markdownStyle} streaming={message.streaming} conceal tableOptions={{ widthMode: "content", wrapMode: "word", cellPaddingX: 1, borderColor: colors.border }} />
|
||||
{summary && summary.files.length > 0 ? <ChangedFiles summary={summary} onOpenTurnDiff={mouse.openTurnDiff} /> : null}
|
||||
{props.footer ? <text marginTop={1} fg={colors.faint}>{props.footer}</text> : null}
|
||||
</box>
|
||||
|
||||
@@ -166,3 +166,11 @@ export function withOmittedOutput(): OrchestrationV2ThreadProjection {
|
||||
visibleTurnItems: [{ position: 0, visibility: "local", sourceThreadId: omittedCommand.threadId, sourceItemId: omittedCommand.id, item: omittedCommand }],
|
||||
} as unknown as OrchestrationV2ThreadProjection;
|
||||
}
|
||||
|
||||
/** The finished turn, its reply replaced by `text`, still streaming in if `streaming`. */
|
||||
export function withReply(text: string, streaming: boolean): OrchestrationV2ThreadProjection {
|
||||
const turn = structuredClone(withCompletedTurn()) as unknown as { turnItems: Record<string, unknown>[]; visibleTurnItems: { item: Record<string, unknown> }[] };
|
||||
for (const item of turn.turnItems) if (item.type === "assistant_message") Object.assign(item, { text, streaming, status: streaming ? "running" : "completed" });
|
||||
for (const visible of turn.visibleTurnItems) visible.item = turn.turnItems.find((item) => item.id === visible.item.id)!;
|
||||
return turn as unknown as OrchestrationV2ThreadProjection;
|
||||
}
|
||||
+11
-2
@@ -51,6 +51,7 @@ export function fakeSession(
|
||||
} = {},
|
||||
) {
|
||||
const calls: Call[] = [];
|
||||
const threadListeners = new Set<(value: unknown) => void>();
|
||||
const snapshot = state.snapshot ?? v2ShellSnapshot;
|
||||
const projection = state.projection ?? v2Projection;
|
||||
const live = <T,>(value: T) => (listener: (value: T) => void) => {
|
||||
@@ -60,7 +61,11 @@ export function fakeSession(
|
||||
const known: Record<string, unknown> = {
|
||||
getShell: () => ({ status: state.status ?? { type: "live" }, snapshot, serverUrl: "ws://test" }),
|
||||
onShell: () => () => {},
|
||||
watchThread: (_id: ThreadId, listener: (value: unknown) => void) => live({ status: "live", projection, history: { cursor: null, hasMore: false, loading: false } })(listener),
|
||||
watchThread: (_id: ThreadId, listener: (value: unknown) => void) => {
|
||||
threadListeners.add(listener);
|
||||
listener({ status: "live", projection, history: { cursor: null, hasMore: false, loading: false } });
|
||||
return () => threadListeners.delete(listener);
|
||||
},
|
||||
watchServerConfig: live(state.serverConfig ? { status: "live", config: state.serverConfig } : { status: "loading", config: null }),
|
||||
watchServers: live({ status: "live", items: [] }),
|
||||
watchAutomations: live({ status: "live", items: [] }),
|
||||
@@ -85,7 +90,11 @@ export function fakeSession(
|
||||
};
|
||||
},
|
||||
}) as unknown as T3Session;
|
||||
return { session, calls };
|
||||
/** Sends watchers of the thread a new projection, as the server does when it changes. */
|
||||
const updateThread = (next: OrchestrationV2ThreadProjection) => {
|
||||
for (const listener of threadListeners) listener({ status: "live", projection: next, history: { cursor: null, hasMore: false, loading: false } });
|
||||
};
|
||||
return { session, calls, updateThread };
|
||||
}
|
||||
|
||||
/** Renders the whole app against a fake session, with helpers to drive it by key and mouse. */
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { afterEach, describe, expect, test } from "bun:test";
|
||||
|
||||
import { withReply } from "./fixtures.ts";
|
||||
import { fakeSession, renderApp } from "./harness.tsx";
|
||||
|
||||
let app: Awaited<ReturnType<typeof renderApp>> | null = null;
|
||||
const open = async (...args: Parameters<typeof renderApp>) => (app = await renderApp(...args));
|
||||
afterEach(() => {
|
||||
app?.destroy();
|
||||
app = null;
|
||||
});
|
||||
|
||||
const table = "| Name | Value |\n| --- | --- |\n| alpha | 1 |\n| beta | a longer cell |\n";
|
||||
const paragraphs = (from: number, to: number) => Array.from({ length: to - from }, (_, index) => `Paragraph ${from + index} of the answer.\n\n`).join("");
|
||||
/** The frame without its scrollbar column, which moves as the content grows. */
|
||||
const content = (frame: string) => frame.split("\n").map((line) => line.slice(0, -3)).join("\n");
|
||||
|
||||
describe("streaming replies", () => {
|
||||
test("tables render as tables, while streaming and once settled", async () => {
|
||||
const fake = fakeSession({ projection: withReply(`Here:\n\n${table.slice(0, 40)}`, true) });
|
||||
const app = await open({ session: fake });
|
||||
expect(app.frame()).toContain("│ Name │ Value │");
|
||||
fake.updateThread(withReply(`Here:\n\n${table}\nAfter.`, false));
|
||||
await app.settle(50);
|
||||
expect(app.frame()).toContain("│ beta │ a longer cell │");
|
||||
expect(app.frame()).not.toContain("| --- |");
|
||||
});
|
||||
|
||||
test("at the bottom, a long answer keeps its newest line in view", async () => {
|
||||
const fake = fakeSession({ projection: withReply("", true) });
|
||||
const app = await open({ session: fake, height: 30 });
|
||||
for (let count = 10; count <= 60; count += 10) {
|
||||
fake.updateThread(withReply(paragraphs(0, count), true));
|
||||
await app.settle();
|
||||
expect(app.frame()).toContain(`Paragraph ${count - 1} of the answer.`);
|
||||
}
|
||||
});
|
||||
|
||||
test("scrolled up, the text in view stays put as the answer grows and settles", async () => {
|
||||
let text = paragraphs(0, 40);
|
||||
const fake = fakeSession({ projection: withReply(text, true) });
|
||||
const app = await open({ session: fake, height: 30 });
|
||||
await app.mockMouse.scroll(60, 10, "up");
|
||||
await app.mockMouse.scroll(60, 10, "up");
|
||||
await app.settle(30);
|
||||
const before = content(app.frame());
|
||||
for (let more = 40; more < 50; more++) {
|
||||
text += `Paragraph ${more} of the answer.\n\n`;
|
||||
fake.updateThread(withReply(text, true));
|
||||
await app.settle();
|
||||
expect(content(app.frame())).toBe(before);
|
||||
}
|
||||
fake.updateThread(withReply(`${text}${table}`, false));
|
||||
await app.settle(30);
|
||||
expect(content(app.frame())).toBe(before);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user