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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This is a fork of T3 Code that integrates a few additional features, including:
- **Display mode per thread:** Right-click a thread and set Display mode to "Chat mode" to hide the agent's work and keep the chat simple: you see just your messages and the replies the agent sends to you with its `send_to_user` tool, and the agent answers each message where you wrote it, so a question in the main list gets its answer in the main list. "Normal mode" shows everything again. The mode applies in the web and desktop apps, not in the mobile app.
- To follow up on one of the agent's messages without filling the main list, point at it and choose Reply. The replies show in a Replies tab in the right panel (+ → Replies, or the reply line under the message), which has its own reply box, and the agent answers you there. Under a message with replies you see how many it has, how many are new, and a few generated words on what they are about. The agent names the message it answers by its id, with `send_to_user`. A Cite in the main list on a message that already has replies opens those replies and puts the quote in their reply box, unless the main box or the open reply box already has text; then the quote goes there, the main box first. A Cite on any other message goes into the main box. An agent reads the thread as you see it with its `t3_thread_user_view` tool, and to brief another agent in your own words it passes on the result's last line, which shows that agent the same messages and says if they changed since.
- In Chat mode the agent sends one reply per message you type, and before a long task it may first send a short "on it" note; a thin line parts two agent messages in a row. To say more, it rewrites its reply in place with its `replace_send_to_user` tool. A rewritten reply shows a small "Edited" mark, and in a sub-thread it counts as new.
- While the agent works, Chat mode shows "Working for" and the time just above the message box, in the sub-thread where you last wrote to it in that run, or else in the main list.
- "Enable Dashboard", beside Display mode in the same menu, gives the thread a Dashboard in either mode: a Dashboard tab in the right panel (+ → Dashboard) with six status slots that the agent writes with its `dashboard_set` tool and reads with `dashboard_get`. Each slot shows how long ago it changed, and new text stays highlighted until you click the slot. Select text in a slot to quote it with Cite, as you would in a message. Agents can link to the Dashboard in their messages, and a click on the link opens it.
- Settings → Threads → New threads → Display mode picks the mode for threads you start from the message box in the web or desktop app. Threads that agents, scheduled tasks, side chats or the mobile app start open in Normal mode, and existing threads keep their mode.
- **Split the right panel in two:** drag a right-panel tab onto the left or right part of the panel's content and drop it to get two panes side by side, each with its own tabs, as with Windows Snap. Drag tabs between the panes, drag the line between them to resize (double-click resets it), and close or move away a pane's last tab to go back to one pane. The tab menu has Split right, Split left, Move to the other pane and Unsplit. New tabs open in the pane you last used. A narrow window shows all tabs in one strip and keeps the split for when there is room. A press anywhere on a tab now switches to it at once.
Expand Down
27 changes: 24 additions & 3 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ import { REPLY_BOX_QUEUE_EDIT_BLOCKED, subThreadDraftId } from "../fork/subThrea
import { useSubThreadCite } from "../fork/subThreads/subThreadCite";
import { SubThreadViewContext } from "../fork/subThreads/subThreadsState";
import { useThreadShownView } from "../fork/displayMode/threadView";
import { ChatWorkingIndicator } from "../fork/displayMode/ChatWorkingIndicator";
import {
scrollToEndBottom,
useChatWorkingReserve,
} from "../fork/displayMode/chatWorkingIndicator.logic";
import { timelineCitation } from "../fork/dashboard/dashboardCitation";
import { useDraftEnvironmentRouting } from "./chat/useDraftEnvironmentRouting";
import { branchMismatchBannerItem, extensionStatusBannerItem } from "./chat/ThreadActivityBanners";
Expand Down Expand Up @@ -2187,6 +2192,7 @@ export default function ChatView(props: ChatViewProps) {
return result;
};

const chatWorkingReserve = useChatWorkingReserve(isServerThread ? routeThreadDetailRef : null);
const {
showScrollToBottom,
timelineLiveFollowEnabled,
Expand All @@ -2203,7 +2209,7 @@ export default function ChatView(props: ChatViewProps) {
attachComposerOverlay: attachFollowComposerOverlay,
} = useTimelineFollow({
legendListRef,
composerTimelineInset,
composerTimelineInset: composerTimelineInset + chatWorkingReserve,
routeThreadKey,
activeThreadKey,
isServerThread,
Expand Down Expand Up @@ -3638,7 +3644,7 @@ export default function ChatView(props: ChatViewProps) {
anchorMessageId={timelineAnchorMessageId}
onAnchorReady={onTimelineAnchorReadyStable}
onAnchorSizeChanged={onTimelineAnchorSizeChangedStable}
contentInsetEndAdjustment={composerTimelineInset}
contentInsetEndAdjustment={composerTimelineInset + chatWorkingReserve}
liveFollowEnabled={timelineLiveFollowEnabled}
onIsAtEndChange={onIsAtEndChangeStable}
onViewportAttach={attachTimelineViewport}
Expand All @@ -3654,11 +3660,26 @@ export default function ChatView(props: ChatViewProps) {

{showScrollToBottom && !isThreadFindActive && (
<ScrollToEndButton
bottom={scrollToEndClearance + 4}
bottom={scrollToEndBottom(
scrollToEndClearance,
composerTimelineInset,
chatWorkingReserve,
)}
summary={scrollToEndSummary}
onScrollToEnd={() => scrollToEnd(true)}
/>
)}
<ChatWorkingIndicator
chatMode={chatWorkingReserve > 0}
environmentId={environmentId}
entries={timelineEntries}
working={isWorking}
localSendPending={isSendBusy}
activityRun={activeActivityRun}
runtime={activeRuntime}
startedAt={activeWorkStartedAt}
composerInset={composerTimelineInset}
/>
</div>

<div
Expand Down
71 changes: 71 additions & 0 deletions apps/web/src/fork/displayMode/ChatWorkingIndicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import type { EnvironmentId } from "@t3tools/contracts";
import { memo, use } from "react";

import { tickTextContent } from "../../lib/tickTextContent";
import type { TimelineEntry } from "../../session-logic";
import { SubThreadViewContext } from "../subThreads/subThreadsState";
import {
type IndicatorRun,
type IndicatorRuntime,
showsWorkingIndicator,
workingForText,
} from "./chatWorkingIndicator.logic";
import { runPlaces } from "./displayModeTimeline";

/** Chat mode's working line, floating above the composer in the view where the live run answers. */
export function ChatWorkingIndicator(props: {
readonly chatMode: boolean;
readonly environmentId: EnvironmentId;
readonly entries: ReadonlyArray<TimelineEntry>;
readonly working: boolean;
readonly localSendPending: boolean;
readonly activityRun: IndicatorRun | null;
readonly runtime: IndicatorRuntime | null;
readonly startedAt: string | null;
readonly composerInset: number;
}) {
const view = use(SubThreadViewContext);
if (
!props.chatMode ||
!props.working ||
!showsWorkingIndicator({ ...props, places: runPlaces(props.entries), view })
)
return null;
return (
<WorkingIndicatorLayer
startedAt={props.startedAt}
environmentId={props.environmentId}
composerInset={props.composerInset}
/>
);
}

export const WorkingIndicatorLayer = memo(function WorkingIndicatorLayer(props: {
readonly startedAt: string | null;
readonly environmentId: EnvironmentId;
readonly composerInset: number;
}) {
const { startedAt, environmentId } = props;
return (
<div
data-chat-working-indicator="true"
className="chat-composer-lane pointer-events-none absolute inset-x-0 z-10"
style={{ bottom: props.composerInset + 2 }}
>
<div className="mx-auto w-full max-w-(--chat-content-max-width)">
<div className="flex h-6 w-fit items-baseline rounded-md bg-background px-1 text-sm leading-relaxed text-muted-foreground tabular-nums">
{startedAt === null ? (
"Working…"
) : (
<span
ref={tickTextContent(
(nowMs) => workingForText(startedAt, environmentId, nowMs),
true,
)}
/>
)}
</div>
</div>
</div>
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { EnvironmentId } from "@t3tools/contracts";
import { expect, it } from "vite-plus/test";
import { page } from "vite-plus/test/browser";

import "~/index.css";

import { render } from "../../../test/render";
import { ScrollToEndButton } from "../../components/chat/TimelineOverlays";
import { scrollToEndBottom, WORKING_INDICATOR_RESERVE_PX } from "./chatWorkingIndicator.logic";
import { WorkingIndicatorLayer } from "./ChatWorkingIndicator";

const environmentId = EnvironmentId.make("working-indicator-layout");
const COMPOSER_INSET = 120;
const LONG_SUMMARY =
"3 new messages from the agent about the deploy, the lint job and the flaky end-to-end suite";

const intersects = (a: DOMRect, b: DOMRect) =>
a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom;

it.each([
[361, 662],
[1280, 800],
])(
"keeps the working line clear of Scroll to end, aligned with the composer and click-through at %ix%i",
async (width, height) => {
const viewport = { width: window.innerWidth, height: window.innerHeight };
await page.viewport(width, height);
await using _viewport = {
[Symbol.asyncDispose]: () => page.viewport(viewport.width, viewport.height),
};
await using screen = await render(
<div className="relative h-dvh w-full">
<button type="button" data-under className="absolute inset-0" />
<ScrollToEndButton
bottom={scrollToEndBottom(COMPOSER_INSET, COMPOSER_INSET, WORKING_INDICATOR_RESERVE_PX)}
summary={LONG_SUMMARY}
onScrollToEnd={() => undefined}
/>
<WorkingIndicatorLayer
startedAt="2026-11-21T00:00:00.000Z"
environmentId={environmentId}
composerInset={COMPOSER_INSET}
/>
<div className="chat-composer-lane absolute inset-x-0 bottom-0">
<div
data-composer-stack
className="mx-auto w-full max-w-(--chat-content-max-width)"
style={{ height: COMPOSER_INSET }}
/>
</div>
</div>,
);
const query = (selector: string) => screen.container.querySelector(selector)!;
const layer = query("[data-chat-working-indicator]");
await expect.element(page.getByText(/^Working for /)).toBeVisible();
const pill = layer.firstElementChild!.firstElementChild!.getBoundingClientRect();

expect(
intersects(
layer.getBoundingClientRect(),
query("[data-scroll-to-end]").getBoundingClientRect(),
),
).toBe(false);
expect(getComputedStyle(layer).pointerEvents).toBe("none");
const hit = document.elementFromPoint(pill.left + pill.width / 2, pill.top + pill.height / 2);
expect(hit).toBe(query("[data-under]"));
expect(pill.left).toBe(query("[data-composer-stack]").getBoundingClientRect().left);
},
);
177 changes: 177 additions & 0 deletions apps/web/src/fork/displayMode/chatWorkingIndicator.logic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import {
EnvironmentId,
MessageId,
NodeId,
type OrchestrationV2ProjectedTurnItem,
type OrchestrationV2TurnItem,
RunId,
ScheduledTaskId,
ThreadId,
TurnItemId,
} from "@t3tools/contracts";
import { notificationTurnItem } from "@t3tools/provider-core/server/notification";
import { shortId } from "@t3tools/shared/displayModes";
import * as DateTime from "effect/DateTime";
import { describe, expect, it } from "vite-plus/test";

import { deriveTimelineEntriesFromVisibleTurnItems } from "../../session-logic";
import { withSubThreadRecord } from "../subThreads/subThreadReply";
import {
type IndicatorRun,
scrollToEndBottom,
showsWorkingIndicator,
workingForText,
} from "./chatWorkingIndicator.logic";
import { runPlaces } from "./displayModeTimeline";

const threadId = ThreadId.make("working-indicator-thread");
const time = (second: number) => new Date(Date.UTC(2026, 10, 21, 0, 0, second)).toISOString();
const base = (id: string, second: number, run: string) => ({
id: TurnItemId.make(id),
threadId,
runId: RunId.make(run),
nodeId: null,
providerThreadId: null,
providerTurnId: null,
nativeItemRef: null,
parentItemId: null,
ordinal: second,
status: "completed" as const,
title: null,
startedAt: DateTime.makeUnsafe(time(second)),
completedAt: DateTime.makeUnsafe(time(second)),
updatedAt: DateTime.makeUnsafe(time(second)),
});
const message = (id: string, second: number, run: string, under?: string, extra = {}) =>
({
...base(id, second, run),
type: "user_message",
messageId: MessageId.make(id),
text: id,
attachments: [],
inputIntent: "turn_start",
createdBy: "user",
creationSource: "web",
...(under === undefined ? {} : { context: withSubThreadRecord(under, "", undefined) }),
...extra,
}) as OrchestrationV2TurnItem;
const answer = (id: string, second: number, run: string, replyTo: string) =>
({
...base(id, second, run),
type: "dynamic_tool",
toolName: "mcp__t3-code__send_to_user",
input: { text: `answer ${id}`, reply_to: shortId(replyTo), user_message: "x" },
output: { ok: true },
}) satisfies OrchestrationV2TurnItem;
const wake = notificationTurnItem(
message("wake", 3, "wake-run"),
{
notification: {
source: { kind: "delegated_task", taskIds: [NodeId.make("task-1")] },
outcome: "completed",
summary: "Delegated task finished",
},
},
[],
);

const items = [
message("q1", 0, "main-run"),
answer("a1", 1, "main-run", "q1"),
message("f1", 2, "reply-run", "q1"),
wake,
message("task", 4, "task-run", "q1", { scheduledTaskId: ScheduledTaskId.make("daily") }),
message("bot", 5, "agent-run", "q1", { senderThreadId: ThreadId.make("other-thread") }),
message("to-f-main", 6, "to-reply-run"),
message("to-f-steer", 7, "to-reply-run", "q1"),
message("to-main-reply", 8, "to-main-run", "q1"),
message("to-main-steer", 9, "to-main-run"),
message("orphan", 10, "orphan-run", "not-loaded"),
];
const entries = deriveTimelineEntriesFromVisibleTurnItems({
visibleTurnItems: items.map((item, position): OrchestrationV2ProjectedTurnItem => ({
position,
visibility: "local",
sourceThreadId: threadId,
sourceItemId: item.id,
item,
})),
optimisticMessages: [],
});
const places = runPlaces(entries);

const live = (run: string, status: IndicatorRun["status"] = "running"): IndicatorRun => ({
runId: RunId.make(run),
status,
startedAt: time(0),
completedAt: null,
});
type Inputs = Omit<Parameters<typeof showsWorkingIndicator>[0], "places" | "view">;
const working: Inputs = {
working: true,
localSendPending: false,
activityRun: null,
runtime: null,
};
/** The views that show the line, given each view's own inputs. */
const shownIn = (main: Partial<Inputs>, reply: Partial<Inputs> = main) =>
[
showsWorkingIndicator({ ...working, ...main, places, view: null }) && "main",
showsWorkingIndicator({ ...working, ...reply, places, view: "q1" }) && "q1",
].filter(Boolean);

describe("showsWorkingIndicator", () => {
it("shows the line where the live run answers", () => {
expect(shownIn({ activityRun: live("reply-run") })).toEqual(["q1"]);
expect(shownIn({ activityRun: live("main-run") })).toEqual(["main"]);
// A wake has no typed message, so the run answers in the main list from its start.
expect(shownIn({ activityRun: live("wake-run", "starting") })).toEqual(["main"]);
expect(shownIn({ activityRun: live("task-run") })).toEqual(["main"]);
expect(shownIn({ activityRun: live("agent-run") })).toEqual(["main"]);
expect(shownIn({ activityRun: live("orphan-run") })).toEqual(["main"]);
});

it("moves with the latest message the user typed in the run", () => {
expect(shownIn({ activityRun: live("to-reply-run") })).toEqual(["q1"]);
expect(shownIn({ activityRun: live("to-main-run", "waiting") })).toEqual(["main"]);
});

it("shows a pending send in the view that sent it until the run has a place", () => {
expect(shownIn({ working: false }, { localSendPending: true })).toEqual(["q1"]);
// A steer from the sub-thread joins a run that answers in the main list until the server places it.
expect(
shownIn(
{ activityRun: live("main-run") },
{ activityRun: live("main-run"), localSendPending: true },
),
).toEqual(["main"]);
});

it("hides a queued run until its message lands, and shows any other unplaced run in main", () => {
expect(shownIn({ activityRun: live("next-run", "queued") })).toEqual([]);
expect(shownIn({ activityRun: live("next-run", "starting") })).toEqual(["main"]);
expect(shownIn({ activityRun: live("next-run") })).toEqual(["main"]);
expect(shownIn({ working: false, activityRun: live("reply-run") })).toEqual([]);
});
});

describe("scrollToEndBottom", () => {
it("keeps Normal's height and lifts Chat's button above the reserved row", () => {
expect(scrollToEndBottom(30, 120, 0)).toBe(34);
expect(scrollToEndBottom(30, 120, 28)).toBe(152);
});
});

describe("workingForText", () => {
it("counts whole seconds from the start in English units", () => {
const environmentId = EnvironmentId.make("working-indicator-environment");
const start = Date.UTC(2026, 10, 21, 0, 0, 0);
const at = (elapsedMs: number) =>
workingForText(new Date(start).toISOString(), environmentId, start + elapsedMs);
expect(at(0)).toBe("Working for 0s");
expect(at(-5_000)).toBe("Working for 0s");
expect(at(59_900)).toBe("Working for 59s");
expect(at(65_400)).toBe("Working for 1m 5s");
expect(workingForText("not a time", environmentId, start)).toBe("Working for 0s");
});
});
Loading
Loading