Skip to content
Open
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 @@ -4,6 +4,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.
- **Zulip tab:** When the machine sets `T3CODE_ZULIP_PANEL_URL` to a Zulip page, the right panel offers that page as a Zulip tab (+ → Zulip). Each person signs in to Zulip in their own browser. The tab shows only when T3 Code is opened from a sibling hostname of that page (such as `t3.example.com` beside `zulip.example.com`), and the page must allow T3 Code to frame it, which a stock Zulip server does not.
- **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 @@ -25,6 +25,7 @@ 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 { zulipPanelCapabilities } from "../fork/zulipPanel.ts";
import { resolveServerEnvironmentLabel } from "./ServerEnvironmentLabel.ts";
import { detectServerEnvironmentMachineKind } from "./ServerEnvironmentMachine.ts";

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

Expand Down
17 changes: 17 additions & 0 deletions apps/server/src/fork/zulipPanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { parseZulipPanelUrl } from "@t3tools/contracts";
import * as HostProcess from "@t3tools/shared/HostProcess";
import * as Effect from "effect/Effect";

// The warning names the variable only, never its value.
export const zulipPanelCapabilities = Effect.fn("zulipPanel.capabilities")(function* () {
const raw = (yield* HostProcess.Environment).T3CODE_ZULIP_PANEL_URL;
if (raw === undefined) return {};
const url = parseZulipPanelUrl(raw);
if (url === undefined) {
yield* Effect.logWarning(
"T3CODE_ZULIP_PANEL_URL is not an https URL (or http on loopback); the Zulip tab is off",
);
return {};
}
return { zulipPanel: { url } };
});
1 change: 1 addition & 0 deletions apps/web/src/closedViewStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const isClosedViewEntry = (entry: unknown): entry is ClosedViewEntry => {
case "dashboard":
case "replies":
case "whiteboard":
case "zulip":
return surface.id === surface.kind;
case "preview":
return surface.resourceId === null || typeof surface.resourceId === "string";
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/components/RightPanelTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ function surfaceTitle(
case "dashboard":
case "replies":
case "whiteboard":
case "zulip":
return modeSurfaceLabel(surface.kind);
case "preview": {
const snapshot = surface.resourceId ? sessions[surface.resourceId] : null;
Expand Down Expand Up @@ -737,6 +738,7 @@ function SurfaceIcon({
case "dashboard":
case "replies":
case "whiteboard":
case "zulip":
return <ModeSurfaceIcon kind={surface.kind} />;
case "device":
return surface.target?.platform === "ios" ? (
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 @@ -17,6 +17,7 @@ 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 { ZulipPanel } from "../../fork/zulip/ZulipPanel";
import type { ComposerImageAttachment, DraftId } from "../../composerDraftStore";
import type { ShortcutMatchContext } from "../../keybindings";
import type { SideChatParentPanel } from "../../lib/sideChatPane";
Expand Down Expand Up @@ -236,6 +237,8 @@ export function RightPanelSurfaceContent(props: {
);
case "whiteboard":
return <WhiteboardPanel threadRef={threadRef} />;
case "zulip":
return <ZulipPanel />;
case "side-chat":
// Not lazy: revealing a suspended tiptap editor tears down its view and crashes the composer.
return (
Expand Down
11 changes: 8 additions & 3 deletions apps/web/src/fork/dashboard/dashboardSurface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ScopedThreadRef } from "@t3tools/contracts";
import { LayoutDashboard, MessageSquareReply, Presentation } from "lucide-react";
import { LayoutDashboard, MessageSquareReply, MessageSquareText, Presentation } from "lucide-react";
import { createElement } from "react";

import { useStableCallback } from "../../hooks/useStableCallback";
Expand All @@ -19,13 +19,15 @@ import {
useBoardOfferedFor,
useThreadProjectRoot,
} from "../whiteboard/role";
import { isZulipPanelOffered, readZulipPanelOffered, useZulipPanelRole } from "../zulip/zulipPanel";

/** The fork's right-panel tabs. `shortcut` is the built-in menu letter; "" is none. */
export const FORK_SURFACES = {
dashboard: { label: "Dashboard", icon: LayoutDashboard, shortcut: "" },
replies: { label: "Replies", icon: MessageSquareReply, shortcut: "" },
whiteboard: { label: "Whiteboard", icon: Presentation, shortcut: "W" },
} as const satisfies Record<ModeSurfaceKind | "whiteboard", unknown>;
zulip: { label: "Zulip", icon: MessageSquareText, shortcut: "Z" },
} as const satisfies Record<ModeSurfaceKind | "whiteboard" | "zulip", unknown>;

type ForkSurfaceKind = keyof typeof FORK_SURFACES;

Expand All @@ -50,18 +52,20 @@ export const ModeSurfaceIcon = (props: { readonly kind: ForkSurfaceKind }) =>
/** Whether the thread offers the tab `kind`, read outside React. Upstream tabs always pass. */
export function threadHasModeSurface(threadRef: ScopedThreadRef, kind: string): boolean {
if (kind === "whiteboard") return boardOfferedFor(threadRef, readThreadProjectRoot(threadRef));
if (kind === "zulip") return readZulipPanelOffered();
if (!(kind in FORK_SURFACES)) return true;
return modeSurfaces(readThreadDisplay(threadRef)).some((surface) => surface === kind);
}

/** The fork's "+" items: the display's Replies and Dashboard, then Whiteboard on a board host. */
/** The fork's "+" items: the display's Replies and Dashboard, then Whiteboard and Zulip where offered. */
export function useModeSurfaceActions(
threadRef: ScopedThreadRef | null,
): ReadonlyArray<ModeSurfaceAction> {
const display = useThreadDisplay(threadRef);
const boardPanel = isBoardHost(useBoardHostRole()) && isTopWindow();
const projectRoot = useThreadProjectRoot(boardPanel ? threadRef : null);
const boardOffered = useBoardOfferedFor(threadRef, projectRoot);
const zulipOffered = isZulipPanelOffered(useZulipPanelRole());
const open = useStableCallback((kind: ForkSurfaceKind) => {
if (threadRef !== null) useRightPanelStore.getState().open(threadRef, kind);
});
Expand All @@ -70,5 +74,6 @@ export function useModeSurfaceActions(
...(boardPanel
? [forkSurfaceAction("whiteboard", boardOffered, () => open("whiteboard"))]
: []),
...(zulipOffered ? [forkSurfaceAction("zulip", true, () => open("zulip"))] : []),
];
}
5 changes: 4 additions & 1 deletion apps/web/src/fork/rightPanelMenu/RightPanelMenuSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import { FORK_SURFACES } from "../dashboard/dashboardSurface";
import { RIGHT_PANEL_SETTINGS_COPY as COPY } from "../forkCopy";
import { isBoardHost, useBoardHostRole } from "../whiteboard/role";
import { isZulipPanelOffered, useZulipPanelRole } from "../zulip/zulipPanel";
import {
parseMenuLayer,
RIGHT_PANEL_MENU_ITEM_IDS,
Expand Down Expand Up @@ -60,6 +61,7 @@ const MENU_ITEM_ROWS = {
replies: forkRow("replies"),
dashboard: forkRow("dashboard"),
whiteboard: forkRow("whiteboard"),
zulip: forkRow("zulip"),
} satisfies Record<RightPanelMenuItemId, Omit<MenuItemRow, "id">>;

const MENU_ITEMS: ReadonlyArray<MenuItemRow> = RIGHT_PANEL_MENU_ITEM_IDS.map((id) => ({
Expand Down Expand Up @@ -174,6 +176,7 @@ function MenuItemSettingsRow(props: {

export function RightPanelMenuSettingsPanel() {
const role = useBoardHostRole();
const zulipOffered = isZulipPanelOffered(useZulipPanelRole());
const overrides = useClientSettings((settings) => settings.rightPanelMenuOverrides);
if (role === "unknown") return null;
if (!isBoardHost(role)) return <Navigate to="/settings/general" replace />;
Expand All @@ -196,7 +199,7 @@ export function RightPanelMenuSettingsPanel() {
</Button>
}
>
{MENU_ITEMS.map((item) => (
{MENU_ITEMS.filter((item) => item.id !== "zulip" || zulipOffered).map((item) => (
<MenuItemSettingsRow
key={item.id}
item={item}
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/fork/rightPanelMenu/menu.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const RIGHT_PANEL_MENU_ITEM_IDS = [
"replies",
"dashboard",
"whiteboard",
"zulip",
] as const;
export type RightPanelMenuItemId = (typeof RIGHT_PANEL_MENU_ITEM_IDS)[number];

Expand Down
76 changes: 76 additions & 0 deletions apps/web/src/fork/zulip/ZulipPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { ExternalLink } from "lucide-react";
import { useState } from "react";

import { Button } from "../../components/ui/button";
import { RefreshIcon } from "../../components/ui/refresh-icon";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../../components/ui/tooltip";
import { useZulipPanelRole } from "./zulipPanel";

// No allow-top-navigation: the framed page must never replace the T3 Code page. Scripts with
// same-origin storage (Zulip needs both) stay out of this page because the frame is another origin.
const ZULIP_FRAME_SANDBOX =
"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox allow-downloads allow-modals";

const RELOAD = "Reload Zulip";
const OPEN_IN_NEW_TAB = "Open Zulip in a new tab";

/** The right panel's Zulip tab: the machine's Zulip page in a frame, the same in every thread. */
export function ZulipPanel() {
const role = useZulipPanelRole();
if (role === "unknown") return null;
if (role === "off") {
return (
<p className="p-4 text-center text-muted-foreground text-sm">Zulip is not available here.</p>
);
}
return <ZulipFrame url={role.url} />;
}

function ZulipFrame(props: { readonly url: string }) {
const [generation, setGeneration] = useState(0);
return (
<div className="flex min-h-0 flex-1 flex-col">
<div className="flex h-8 shrink-0 items-center justify-end gap-1 border-b border-border/60 px-2">
<Tooltip>
<TooltipTrigger
render={
<Button
variant="ghost"
size="icon-xs"
aria-label={RELOAD}
onClick={() => setGeneration((current) => current + 1)}
/>
}
>
<RefreshIcon />
</TooltipTrigger>
<TooltipPopup>{RELOAD}</TooltipPopup>
</Tooltip>
<Tooltip>
<TooltipTrigger
render={
<Button
variant="ghost"
size="icon-xs"
aria-label={OPEN_IN_NEW_TAB}
render={<a href={props.url} target="_blank" rel="noreferrer" />}
/>
}
>
<ExternalLink />
</TooltipTrigger>
<TooltipPopup>{OPEN_IN_NEW_TAB}</TooltipPopup>
</Tooltip>
</div>
<iframe
key={generation}
title="Zulip"
src={props.url}
sandbox={ZULIP_FRAME_SANDBOX}
allow="clipboard-write; fullscreen; autoplay"
referrerPolicy="no-referrer"
className="min-h-0 w-full flex-1 border-0"
/>
</div>
);
}
30 changes: 30 additions & 0 deletions apps/web/src/fork/zulip/zulipPanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useAtomValue } from "@effect/atom-react";
import { zulipPanelFrameSource } from "@t3tools/contracts";
import { Atom } from "effect/reactivity";

import { appAtomRegistry } from "../../rpc/atomRegistry";
import { primaryServerConfigAtom } from "../../state/server";
import { isTopWindow } from "../whiteboard/role";

/**
* "unknown" until the primary server config arrives. `url` is the page this window may frame;
* "off" when the machine set none, or this page cannot frame it (see `zulipPanelFrameSource`).
*/
export type ZulipPanelRole = "unknown" | "off" | { readonly url: string };

const zulipPanelRoleAtom = Atom.make((get): ZulipPanelRole => {
const config = get(primaryServerConfigAtom);
if (config === null) return "unknown";
const raw = config.environment.capabilities.zulipPanel?.url;
if (raw === undefined || !isTopWindow()) return "off";
const url = zulipPanelFrameSource(raw, window.location.origin);
return url === undefined ? "off" : { url };
}).pipe(Atom.withLabel("fork-zulip-panel-role"));

export const useZulipPanelRole = (): ZulipPanelRole => useAtomValue(zulipPanelRoleAtom);

export const isZulipPanelOffered = (role: ZulipPanelRole): role is { readonly url: string } =>
typeof role === "object";

export const readZulipPanelOffered = (): boolean =>
isZulipPanelOffered(appAtomRegistry.get(zulipPanelRoleAtom));
6 changes: 5 additions & 1 deletion apps/web/src/rightPanelStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const RIGHT_PANEL_KINDS = [
"dashboard",
"replies",
"whiteboard",
"zulip",
] as const;
export type RightPanelKind = (typeof RIGHT_PANEL_KINDS)[number];

Expand Down Expand Up @@ -113,7 +114,8 @@ export type RightPanelSurface =
| { id: `side-chat:${string}`; kind: "side-chat"; threadId: ThreadId }
| { id: "dashboard"; kind: "dashboard" }
| { id: "replies"; kind: "replies" }
| { id: "whiteboard"; kind: "whiteboard" };
| { id: "whiteboard"; kind: "whiteboard" }
| { id: "zulip"; kind: "zulip" };

const RIGHT_PANEL_STORAGE_KEY = "t3code:right-panel-state:v2";
const RIGHT_PANEL_STORAGE_VERSION = 15;
Expand Down Expand Up @@ -284,6 +286,8 @@ const singletonSurface = (
return { id: "replies", kind };
case "whiteboard":
return { id: "whiteboard", kind };
case "zulip":
return { id: "zulip", kind };
}
};

Expand Down
3 changes: 3 additions & 0 deletions packages/contracts/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TrimmedNonEmptyString,
} from "./baseSchemas.ts";
import { WhiteboardPanelCapability } from "./fork/rightPanelMenu.ts";
import { ZulipPanelCapability } from "./fork/zulipPanel.ts";
import { SourceControlProviderKind } from "./sourceControl.ts";

export const ORCHESTRATION_PROTOCOL_VERSION = 2;
Expand Down Expand Up @@ -218,6 +219,8 @@ export const ExecutionEnvironmentCapabilities = Schema.Struct({
linkedThreadRefreshes: Schema.optionalKey(Schema.Boolean),
/** Sent only by a whiteboard board host: the panel board and the machine's menu defaults. */
whiteboardPanel: Schema.optionalKey(WhiteboardPanelCapability),
/** Sent only by a machine that sets a Zulip page for the right panel's Zulip tab. */
zulipPanel: Schema.optionalKey(ZulipPanelCapability),
});
export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;

Expand Down
57 changes: 57 additions & 0 deletions packages/contracts/src/fork/zulipPanel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { describe, expect, it } from "@effect/vitest";

import { parseZulipPanelUrl, zulipPanelFrameSource } from "./zulipPanel.ts";

describe("parseZulipPanelUrl", () => {
it.each<[raw: string, url: string | undefined]>([
["https://zulip.example.com/", "https://zulip.example.com/"],
["https://zulip.example.com", "https://zulip.example.com/"],
["http://localhost:6310/", "http://localhost:6310/"],
["http://127.0.0.1:6310/", "http://127.0.0.1:6310/"],
["http://[::1]:6310/", "http://[::1]:6310/"],
["http://zulip.example.com/", undefined],
["https://user:pw@zulip.example.com/", undefined],
["javascript:alert(1)", undefined],
["data:text/html,x", undefined],
["", undefined],
["zulip.example.com", undefined],
])("%j gives %j", (raw, url) => {
expect(parseZulipPanelUrl(raw)).toBe(url);
});
});

describe("zulipPanelFrameSource", () => {
const ZULIP = "https://zulip.example.com/";

it.each<[why: string, rawUrl: string, pageOrigin: string, source: string | undefined]>([
["sibling names under a two-label parent", ZULIP, "https://t3.example.com", ZULIP],
[
"sibling names under a longer parent",
"https://zulip.team.example.com/",
"https://t3.team.example.com",
"https://zulip.team.example.com/",
],
[
"one name on two ports",
"http://localhost:6310/",
"http://localhost:3773",
"http://localhost:6310/",
],
["the page's own origin", "https://t3.example.com/", "https://t3.example.com", undefined],
["another parent domain", ZULIP, "https://t3.example.org", undefined],
["a longer look-alike name", ZULIP, "https://t3.example.com.evil.example", undefined],
["names under a one-label parent", "https://b.com/", "https://a.com", undefined],
[
"names that end with the root dot",
"https://zulip.example.com./",
"https://t3.example.com.",
undefined,
],
["two addresses", "http://127.0.0.2:6310/", "http://127.0.0.1:3773", undefined],
["an https URL from an http page", ZULIP, "http://t3.example.com", undefined],
["the desktop app's page", ZULIP, "t3code://app", undefined],
["a URL the parser rejects", "http://zulip.example.com/", "http://t3.example.com", undefined],
])("%s: %j framed from %j gives %j", (_why, rawUrl, pageOrigin, source) => {
expect(zulipPanelFrameSource(rawUrl, pageOrigin)).toBe(source);
});
});
Loading
Loading