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 @@ -3,6 +3,7 @@
This is a fork of T3 Code that integrates a few additional features, including:

- **Whiteboard:** A tldraw whiteboard that sits side-by-side with T3 Code, allowing users to interact with agents (or other users) by editing and pointing to the whiteboard. Both the user and the agents can conveniently write links that point to a rectangular region on the whiteboard. Agents can also draw Mermaid diagrams on it, such as flowcharts and statecharts.
- When the whiteboard's config maps T3 Code's hostname to `"app"`, that hostname opens T3 Code itself, and the project's board opens as a Whiteboard tab in its right panel (+ → Whiteboard). There, Settings → Right panel lets each browser hide items of the + menu or change their letters, over machine defaults set in the whiteboard's config.
- **Better support for manually switching accounts mid-session:**
- After hitting the usage limit of an account, the thread now retries after 2 minutes and 30 minutes in addition to the default retry behavior of T3 Code. This allows the thread to recover earlier if the user manually switches the account.
- New Codex/Antigravity logins are picked up mid-session without a full restart.
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/environment/ServerEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { databaseMigrationHead } from "../persistence/databaseMigrationHead.ts";
import * as ProcessRunner from "../processRunner.ts";
import { isSpeechPlatformSupported } from "../speech/platform.ts";
import { fastCheckoutCapabilities } from "../fork/reflinkWorktrees/fastCheckoutSetting.ts";
import { whiteboardPanelCapabilities } from "../fork/whiteboardPanel.ts";
import { resolveServerEnvironmentLabel } from "./ServerEnvironmentLabel.ts";
import { detectServerEnvironmentMachineKind } from "./ServerEnvironmentMachine.ts";

Expand Down Expand Up @@ -303,6 +304,7 @@ export const make = Effect.gen(function* () {
mcpHostedApproval: true,
shellThreadFamilies: true,
shellOlderSettled: true,
...(yield* whiteboardPanelCapabilities()),
},
};

Expand Down
53 changes: 53 additions & 0 deletions apps/server/src/fork/whiteboardPanel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { expect, it } from "@effect/vitest";
import * as HostProcess from "@t3tools/shared/HostProcess";
import * as Effect from "effect/Effect";

import { parseWhiteboardPanel, whiteboardPanelCapabilities } from "./whiteboardPanel.ts";

it.each([
{ raw: "not json", expected: undefined },
{ raw: "[]", expected: undefined },
{ raw: "null", expected: undefined },
{ raw: '"app"', expected: undefined },
{ raw: "{}", expected: { menu: {} } },
{ raw: '{"menu":"browser"}', expected: { menu: {} } },
{
raw: JSON.stringify({
menu: {
browser: { hidden: true, key: "x" },
files: { hidden: "yes", key: "" },
diff: { key: "DD" },
device: { key: "é" },
terminal: "hidden",
whiteboard: [],
"future-item": { key: "7", extra: 1 },
},
}),
expected: {
menu: {
browser: { hidden: true, key: "X" },
files: { key: "" },
diff: {},
device: {},
"future-item": { key: "7" },
},
},
},
])("parses $raw leniently", ({ raw, expected }) => {
expect(parseWhiteboardPanel(raw)).toEqual(expected);
});

it.effect("advertises the board host only while the variable holds an object", () =>
Effect.gen(function* () {
const capabilities = (environment: NodeJS.ProcessEnv) =>
whiteboardPanelCapabilities().pipe(
Effect.provideService(HostProcess.Environment, environment),
);

expect(yield* capabilities({})).toEqual({});
expect(yield* capabilities({ T3CODE_WHITEBOARD_PANEL: "{oops" })).toEqual({});
expect(
yield* capabilities({ T3CODE_WHITEBOARD_PANEL: '{"menu":{"files":{"hidden":true}}}' }),
).toEqual({ whiteboardPanel: { menu: { files: { hidden: true } } } });
}),
);
40 changes: 40 additions & 0 deletions apps/server/src/fork/whiteboardPanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { parseRightPanelMenuChoice, type WhiteboardPanelCapability } from "@t3tools/contracts";
import * as HostProcess from "@t3tools/shared/HostProcess";
import * as Effect from "effect/Effect";

const isRecord = (value: unknown): value is Record<string, unknown> =>
typeof value === "object" && value !== null && !Array.isArray(value);

/** The value of `T3CODE_WHITEBOARD_PANEL`; undefined unless it is a JSON object. */
export function parseWhiteboardPanel(raw: string): WhiteboardPanelCapability | undefined {
let value: unknown;
try {
value = JSON.parse(raw);
} catch {
return undefined;
}
if (!isRecord(value)) return undefined;
const menu = isRecord(value.menu) ? value.menu : {};
return {
menu: Object.fromEntries(
Object.entries(menu).flatMap(([id, entry]) => {
const choice = parseRightPanelMenuChoice(entry);
return choice === undefined ? [] : [[id, choice]];
}),
),
};
}

// The whiteboard's run-t3.sh sets the variable only on a board host, from its deploy-time config.
export const whiteboardPanelCapabilities = Effect.fn("whiteboardPanel.capabilities")(function* () {
const raw = (yield* HostProcess.Environment).T3CODE_WHITEBOARD_PANEL;
if (raw === undefined) return {};
const whiteboardPanel = parseWhiteboardPanel(raw);
if (whiteboardPanel === undefined) {
yield* Effect.logWarning(
"T3CODE_WHITEBOARD_PANEL is not a JSON object; the board panel is off",
);
return {};
}
return { whiteboardPanel };
});
1 change: 1 addition & 0 deletions apps/web/src/closedViewStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const isClosedViewEntry = (entry: unknown): entry is ClosedViewEntry => {
case "pull-requests":
case "dashboard":
case "replies":
case "whiteboard":
return surface.id === surface.kind;
case "preview":
return surface.resourceId === null || typeof surface.resourceId === "string";
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/components/ChatMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import type {
} from "react-markdown";
import { createIncrementalMarkdownPlugin } from "../markdown-incremental";
import { postWhiteboardHover, remarkWhiteboardLinks } from "../fork/whiteboard/markdown-whiteboard";
import { showBoardRef } from "../fork/whiteboard/boardChannel";
import { remarkEndLinksAtCjkPunctuation } from "../fork/cjkLinkEnd";
import type { Pluggable, PluggableList } from "unified";
import { defaultUrlTransform } from "react-markdown";
Expand Down Expand Up @@ -1307,7 +1308,7 @@ const CHAT_MARKDOWN_COMPONENTS = {
onClick?.(event);
if (isWhiteboardLink && href) {
event.preventDefault();
window.parent.postMessage({ type: "wb-highlight", ref: href }, "*");
showBoardRef(href, threadRef);
return;
}
if (isSameDocumentLink && href) {
Expand Down
38 changes: 32 additions & 6 deletions apps/web/src/components/RightPanelTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import {
ModeSurfaceIcon,
modeSurfaceLabel,
} from "~/fork/dashboard/dashboardSurface";
import {
AllMenuItemsHidden,
useArrangedSurfaceActions,
} from "~/fork/rightPanelMenu/rightPanelMenu";
import type { SplitMenuAction } from "~/fork/rightPanelSplit/splitLayout.logic";
import {
SplitPaneFrame,
Expand Down Expand Up @@ -359,8 +363,9 @@ function RightPanelEmptyState(props: {
const messages = useMessages();
const [highlight, setHighlight] = useState(-1);

const actions = [
const actions = useArrangedSurfaceActions([
{
id: "browser",
label: msg("Browser"),
icon: Globe2,
shortcut: "B",
Expand All @@ -369,6 +374,7 @@ function RightPanelEmptyState(props: {
onClick: props.onAddBrowser,
},
{
id: "terminal",
label: msg("Terminal"),
icon: TerminalSquare,
shortcut: "T",
Expand All @@ -377,6 +383,7 @@ function RightPanelEmptyState(props: {
onClick: props.onAddTerminal,
},
{
id: "files",
label: msg("Files"),
icon: Files,
shortcut: "F",
Expand All @@ -385,6 +392,7 @@ function RightPanelEmptyState(props: {
onClick: props.onAddFiles,
},
{
id: "diff",
label: msg("Diff"),
icon: FileDiff,
shortcut: "D",
Expand All @@ -393,6 +401,7 @@ function RightPanelEmptyState(props: {
onClick: props.onAddDiff,
},
{
id: "pull-request",
label: msg("Pull request"),
icon: PullRequestGlyph.pullRequest,
shortcut: "P",
Expand All @@ -401,6 +410,7 @@ function RightPanelEmptyState(props: {
onClick: props.onAddPullRequest,
},
{
id: "pull-requests",
label: msg("Linked pull requests"),
icon: PullRequestGlyph.link,
shortcut: "L",
Expand All @@ -409,6 +419,7 @@ function RightPanelEmptyState(props: {
onClick: props.onAddPullRequests,
},
{
id: "device",
label: msg("Device"),
description: msg("Watch an iOS Simulator or Android Emulator."),
icon: Smartphone,
Expand All @@ -420,6 +431,7 @@ function RightPanelEmptyState(props: {
...(props.onAddSideChat
? [
{
id: "side-chat" as const,
label: msg("Side chat"),
description: msg("Ask a side question while this thread keeps working."),
icon: MessagesSquare,
Expand All @@ -432,7 +444,7 @@ function RightPanelEmptyState(props: {
]
: []),
...(props.modeSurfaceActions ?? []),
] as const;
] as const);

type SurfaceAction = (typeof actions)[number];

Expand Down Expand Up @@ -512,6 +524,7 @@ function RightPanelEmptyState(props: {
<T>Open a surface</T>
</h3>
<div className="flex flex-col gap-0.5">
{actions.length === 0 ? <AllMenuItemsHidden in="launcher" /> : null}
{actions.map((action) =>
action.available ? (
<div
Expand Down Expand Up @@ -627,6 +640,7 @@ function surfaceTitle(
return resolve(msg("Side chat"));
case "dashboard":
case "replies":
case "whiteboard":
return modeSurfaceLabel(surface.kind);
case "preview": {
const snapshot = surface.resourceId ? sessions[surface.resourceId] : null;
Expand Down Expand Up @@ -722,6 +736,7 @@ function SurfaceIcon({
return <SideChatTabIcon environmentId={environmentId} threadId={surface.threadId} />;
case "dashboard":
case "replies":
case "whiteboard":
return <ModeSurfaceIcon kind={surface.kind} />;
case "device":
return surface.target?.platform === "ios" ? (
Expand Down Expand Up @@ -1205,8 +1220,9 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
});
};

const addSurfaceActions = [
const addSurfaceActions = useArrangedSurfaceActions([
{
id: "browser",
label: msg("Browser"),
icon: Globe2,
shortcut: "B",
Expand All @@ -1215,6 +1231,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
onClick: props.onAddBrowser,
},
{
id: "terminal",
label: msg("Terminal"),
icon: TerminalSquare,
shortcut: "T",
Expand All @@ -1223,6 +1240,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
onClick: props.onAddTerminal,
},
{
id: "files",
label: msg("Files"),
icon: Files,
shortcut: "F",
Expand All @@ -1231,6 +1249,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
onClick: props.onAddFiles,
},
{
id: "diff",
label: msg("Diff"),
icon: FileDiff,
shortcut: "D",
Expand All @@ -1239,6 +1258,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
onClick: props.onAddDiff,
},
{
id: "pull-request",
label: msg("Pull request"),
icon: PullRequestGlyph.pullRequest,
shortcut: "P",
Expand All @@ -1247,6 +1267,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
onClick: props.onAddPullRequest,
},
{
id: "pull-requests",
label: msg("Linked pull requests"),
icon: PullRequestGlyph.link,
shortcut: "L",
Expand All @@ -1255,6 +1276,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
onClick: props.onAddPullRequests,
},
{
id: "device",
label: msg("Device"),
icon: Smartphone,
shortcut: "M",
Expand All @@ -1265,6 +1287,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
...(props.onAddSideChat
? [
{
id: "side-chat" as const,
label: msg("Side chat"),
icon: MessagesSquare,
shortcut: "S",
Expand All @@ -1276,7 +1299,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
]
: []),
...(props.modeSurfaceActions ?? []),
] as const;
] as const);

const handleAddSurfaceMenuKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {
const action = surfaceShortcutActionForKey(addSurfaceActions, event.nativeEvent);
Expand Down Expand Up @@ -1563,14 +1586,15 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
sideOffset={6}
onKeyDownCapture={handleAddSurfaceMenuKeyDown}
>
{addSurfaceActions.length === 0 ? <AllMenuItemsHidden in="menu" /> : null}
{addSurfaceActions.map((action) => {
const Icon = action.icon;
if (action.label === "Browser" && action.available) {
return (
<MenuSub key={action.label}>
<MenuSubTrigger
className="[&>svg:last-child]:ms-0"
aria-keyshortcuts={action.shortcut}
aria-keyshortcuts={action.shortcut || undefined}
onClick={(event) => {
const pointerType =
"pointerType" in event.nativeEvent &&
Expand All @@ -1585,7 +1609,9 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
>
<Icon />
{messages(action.label)}
<MenuShortcut>{action.shortcut}</MenuShortcut>
{action.shortcut ? (
<MenuShortcut>{action.shortcut}</MenuShortcut>
) : null}
</MenuSubTrigger>
<MenuSubPopup className="max-w-56">
{browserProfiles.map((profile) => (
Expand Down
8 changes: 7 additions & 1 deletion apps/web/src/components/chat/ChatComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,13 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
return true;
};
const applyPromptReplacementStable = useStableCallback(applyPromptReplacement);
useWhiteboardInsertRef(composerEditorRef, promptRef, applyPromptReplacementStable);
useWhiteboardInsertRef(
composerEditorRef,
promptRef,
applyPromptReplacementStable,
composerFormRef,
routeThreadRef,
);

const readComposerSnapshot = (): {
value: string;
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/components/chat/RightPanelSurfaceContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import SideChatPane from "./SideChatPane";
import { ThreadDashboardPanel } from "../../fork/dashboard/ThreadDashboardPanel";
import type { CiteAssistantText } from "../../fork/dashboard/dashboardCitation";
import { SubThreadsPanel } from "../../fork/subThreads/SubThreadsPanel";
import { WhiteboardPanel } from "../../fork/whiteboard/WhiteboardPanel";
import type { ComposerImageAttachment, DraftId } from "../../composerDraftStore";
import type { ShortcutMatchContext } from "../../keybindings";
import type { SideChatParentPanel } from "../../lib/sideChatPane";
Expand Down Expand Up @@ -233,6 +234,8 @@ export function RightPanelSurfaceContent(props: {
parentPanel={props.sideChatParentPanel}
/>
);
case "whiteboard":
return <WhiteboardPanel threadRef={threadRef} />;
case "side-chat":
// Not lazy: revealing a suspended tiptap editor tears down its view and crashes the composer.
return (
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/settings/SettingsScopeSentence.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const SETTINGS_DEVICE_ONLY_PATHS: ReadonlySet<string> = new Set([
"/settings/appearance",
"/settings/chat",
"/settings/diffs",
"/settings/right-panel",
"/settings/snap-shot",
"/settings/connections",
// Access picks its environment on the page itself.
Expand Down
Loading
Loading