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 @@ -23,6 +23,7 @@ This is a fork of T3 Code that integrates a few additional features, including:
- **FYI messages between agents:** an agent can send another thread an FYI, a note of at most 16,000 characters that needs no action and starts no turn. The receiving agent gets it with its next turn; a running Claude Code thread gets it at its next tool call. An FYI counts as delivered only when the turn that carries it finishes: a turn that fails, is stopped, restarts or is reverted gives it back, so the agent may see it twice. When a thread has an FYI waiting and has been idle for 6 hours, T3 Code wakes it to deliver its FYIs, unless the thread is settled, archived, waiting for your answer or holds queued messages; a snoozed thread waits until its snooze ends. The 6 hours count from the thread's last turn, or from the reset of a usage limit that stopped it on the provider it still uses (or from the end of a snooze that ends after that reset), so an FYI to a thread that has been idle longer wakes it within minutes. A thread whose usage limit has no known reset time, or whose provider fails every turn, gets a failed wake every 6 hours while an FYI waits. A wake carries up to 16,000 characters of FYIs. The rest, and any that a wake gives back because it failed or you stopped it, get another wake after 6 more idle hours. A wake is a new turn, so **Resume** no longer continues a turn that ended before it. Settle or archive a thread to stop its wakes. The timeline marks these messages "FYI · waiting", "FYI · sent" while the turn that carries them runs, and "FYI" once it finished.
- **Open server files by their path:** in a browser signed in to T3 Code at its own address, open `<T3 address>/<absolute path>` (such as `https://t3.example.com/home/ana/work/report.html`) to see that file read-only, for files under the server user's home folder and temp folder. A session needs the `filesystem:read` permission, and a signed-out browser gets a sign-in page. Text and code of any type show as plain text, and images, PDFs, audio and video show as themselves. A folder shows its `index.html`, or else a list of its files. Links ending in `:line` or `:line:col` open the file. Names that start with `.`, and T3 Code's own data folder, are not served. An HTML page runs in a sandboxed frame at the same address: its scripts run but cannot act as you in T3, and it loads files from its own folder and below for an hour, though its scripts cannot fetch them. A page directly in the home or temp folder loads no other files. An HTML page linked from another site, or any HTML page over plain HTTP, first shows an Open link.
- **HTML pages from disk block their own network calls:** an HTML file that the file viewer, "Open in browser" or a server file path shows from disk runs its own scripts and loads scripts, styles, fonts and images over HTTPS. It cannot use fetch, XHR, WebSocket, EventSource, beacons or form posts, its frames cannot load other addresses, and audio and video play only from its own files or inline data. A page that fetches its data while it runs needs that data inline. An allowed load can still carry data in its URL, so these limits do not make an untrusted page safe.
- **Folders on file links:** Settings → Appearance → File link folders shows up to four folders before the file name on file links in messages and Markdown previews, such as `review-pipeline/glossary.md`, so you need not hover a link to see where the file is. Each browser, and the desktop app, keeps its own choice. A file name that repeats in one message keeps its folder hint after the name.
- Enabling math rendering by default.
- Other small fixes.

Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/components/ChatMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ import {
} from "./chat/ChatMarkdownMedia";
import { MarkdownExternalLinkContent } from "./chat/MarkdownExternalLink";
import { MarkdownFileLink } from "./chat/MarkdownFileLink";
import { useFileLinkPrefix } from "../fork/FileLinkPathPrefix";
import { canUseMarkdownFileShellActions } from "./chat/MarkdownFileLink.logic";
import { rehypeChipPunctuation } from "./chat/markdownChipPunctuation";
import { handleMarkdownFragmentClick, rehypeHeadingIds } from "./chat/markdownFragments";
Expand Down Expand Up @@ -769,6 +770,7 @@ function useChatMarkdownState({
const fileLinksKey = `${fileLinkSourcesKey(text, cwd, imageBaseDir, fileLinkPeerPaths, hostFileOrigins)}`;
const { markdownFileLinkMetaByHref, inlineCodeFileLinkMetaByText, fileLinkParentSuffixByPath } =
resolveFileLinkSources(fileLinksKey, cwd, imageBaseDir);
const fileLinkPrefix = useFileLinkPrefix(fileLinkParentSuffixByPath);
const resolveThreadPullRequest = (
href: string,
): (ThreadPullRequestKey & { readonly url: string }) | null => {
Expand Down Expand Up @@ -993,6 +995,7 @@ function useChatMarkdownState({
},
fileLinkParentSuffixByPath,
)}
labelPrefix={fileLinkPrefix(fileLinkMeta)}
copyMarkdown={copyMarkdown}
theme={resolvedTheme}
threadRef={threadRef}
Expand Down
6 changes: 5 additions & 1 deletion apps/web/src/components/chat/FileTagChip.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { ReactNode } from "react";
import type { EnvironmentId } from "@t3tools/contracts";
import { ContextChipLabel } from "../ContextChip";
import { FileLinkPathLabel } from "../../fork/FileLinkPathPrefix";
import { WorkspaceEntryIcon } from "./WorkspaceEntryIcon";

export function FileTagChipContent(props: {
icon?: ReactNode;
path: string;
label: string;
labelPrefix?: string | undefined;
theme: "light" | "dark";
environmentId?: EnvironmentId | null | undefined;
cwd?: string | undefined;
Expand All @@ -21,7 +23,9 @@ export function FileTagChipContent(props: {
theme={props.theme}
/>
)}
<ContextChipLabel>{props.label}</ContextChipLabel>
<ContextChipLabel>
<FileLinkPathLabel prefix={props.labelPrefix} label={props.label} />
</ContextChipLabel>
</>
);
}
8 changes: 7 additions & 1 deletion apps/web/src/components/chat/MarkdownFileLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface MarkdownFileLinkProps {
panelPath: string | null;
line?: number | undefined;
label: string;
labelPrefix?: string | undefined;
copyMarkdown: string;
theme: "light" | "dark";
threadRef?: ScopedThreadRef | undefined;
Expand All @@ -70,6 +71,7 @@ export const MarkdownFileLink = memo(function MarkdownFileLink({
panelPath,
line,
label,
labelPrefix,
copyMarkdown,
theme,
threadRef,
Expand Down Expand Up @@ -349,6 +351,7 @@ export const MarkdownFileLink = memo(function MarkdownFileLink({
kind={chipKind}
dir="ltr"
render={<a href={href} />}
aria-label={labelPrefix === undefined ? undefined : `${labelPrefix}${label}`}
className={MARKDOWN_FILE_LINK_CLASS_NAME}
data-markdown-copy={copyMarkdown}
onClick={(event) => {
Expand Down Expand Up @@ -376,6 +379,7 @@ export const MarkdownFileLink = memo(function MarkdownFileLink({
path={iconPath}
environmentId={environmentId}
label={label}
labelPrefix={labelPrefix}
theme={theme}
/>
</ContextChip>
Expand All @@ -385,7 +389,7 @@ export const MarkdownFileLink = memo(function MarkdownFileLink({
kind={chipKind}
dir="ltr"
render={<button type="button" />}
aria-label={gt("File options for {label}", { label })}
aria-label={gt("File options for {label}", { label: `${labelPrefix ?? ""}${label}` })}
aria-haspopup="menu"
className={cn(MARKDOWN_FILE_LINK_CLASS_NAME, "select-text")}
data-markdown-copy={copyMarkdown}
Expand All @@ -401,6 +405,7 @@ export const MarkdownFileLink = memo(function MarkdownFileLink({
path={iconPath}
environmentId={environmentId}
label={label}
labelPrefix={labelPrefix}
theme={theme}
/>
</ContextChip>
Expand All @@ -427,6 +432,7 @@ function areMarkdownFileLinkPropsEqual(
previous.panelPath === next.panelPath &&
previous.line === next.line &&
previous.label === next.label &&
previous.labelPrefix === next.labelPrefix &&
previous.copyMarkdown === next.copyMarkdown &&
previous.theme === next.theme &&
previous.threadRef === next.threadRef &&
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/components/settings/AppearanceSettingsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { AdvancedSettings } from "./AdvancedSettings";
import { PanelAnimationsPreview } from "./PanelAnimationsPreview";
import { TypographySection } from "./TypographySettings";
import { ThreadDetailsItemsRow } from "./ThreadDetailsItemsRow";
import { FileLinkPathDepthSetting } from "../../fork/FileLinkPathDepthSetting";

const ENVIRONMENT_IDENTIFICATION_LABELS: Record<EnvironmentIdentificationMode, string> = {
artwork: msg("Artwork"),
Expand Down Expand Up @@ -361,6 +362,7 @@ export function AppearanceSettingsPanel() {
/>
}
/>
<FileLinkPathDepthSetting />
<AdvancedSettings
targetIds={[
searchableSetting("panel-animations").id,
Expand Down
10 changes: 9 additions & 1 deletion apps/web/src/components/settings/SettingsPanels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ import { useScopedModelDisabledReason } from "./useScopedModelAvailability";
import { useOptionalSettingsScope, useSettingsScope } from "./SettingsScopeContext";
import { scopedIdleCompaction } from "./scopedSettings";
import { CompactIdleValueRows } from "~/fork/CompactIdleValueRows";
import { COMPACT_IDLE_THREADS_DESCRIPTION, COMPACT_WHEN_IDLE_LABEL } from "~/fork/forkCopy";
import {
COMPACT_IDLE_THREADS_DESCRIPTION,
COMPACT_WHEN_IDLE_LABEL,
FORK_SETTING_TITLES,
} from "~/fork/forkCopy";
import { ProjectDefaultsSettings } from "./ProjectDefaultsSettings";
import { ThreadTitleInstructionsSettings } from "./ThreadTitleInstructionsSettings";
import { SnoozePresetsRow } from "./SnoozePresetsSettings";
Expand Down Expand Up @@ -509,6 +513,9 @@ export function useSettingsRestore(onRestored?: () => void) {
...(settings.mathRenderingEnabled !== DEFAULT_UNIFIED_SETTINGS.mathRenderingEnabled
? [gt("Render math")]
: []),
...(settings.fileLinkPathDepth !== DEFAULT_UNIFIED_SETTINGS.fileLinkPathDepth
? [FORK_SETTING_TITLES.fileLinkPathDepth]
: []),
...(settings.panelAnimationDurationMs !== DEFAULT_UNIFIED_SETTINGS.panelAnimationDurationMs
? [gt("Panel animations")]
: []),
Expand Down Expand Up @@ -702,6 +709,7 @@ export function useSettingsRestore(onRestored?: () => void) {
chatWidth: DEFAULT_UNIFIED_SETTINGS.chatWidth,
effortDisplay: DEFAULT_UNIFIED_SETTINGS.effortDisplay,
mathRenderingEnabled: DEFAULT_UNIFIED_SETTINGS.mathRenderingEnabled,
fileLinkPathDepth: DEFAULT_UNIFIED_SETTINGS.fileLinkPathDepth,
language: DEFAULT_UNIFIED_SETTINGS.language,
timestampFormat: DEFAULT_UNIFIED_SETTINGS.timestampFormat,
notificationMode: DEFAULT_UNIFIED_SETTINGS.notificationMode,
Expand Down
6 changes: 6 additions & 0 deletions apps/web/src/components/settings/settingsSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,12 @@ export const SETTINGS_SEARCH_ITEMS = [
to: "/settings/appearance",
searchTerms: [msg("latex tex katex equations formulas markdown")],
},
{
id: "file-link-path-depth",
title: FORK_SETTING_TITLES.fileLinkPathDepth,
to: "/settings/appearance",
searchTerms: ["file link path folder directory parent depth segments chip name"],
},
{
id: "panel-animations",
title: msg("Panel animations"),
Expand Down
64 changes: 64 additions & 0 deletions apps/web/src/fork/FileLinkPathDepthSetting.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { DEFAULT_CLIENT_SETTINGS, FileLinkPathDepth } from "@t3tools/contracts";

import { SettingResetButton, SettingsRow } from "~/components/settings/settingsLayout";
import { useSearchableSetting } from "~/components/settings/settingsSearch";
import {
Select,
SelectItem,
SelectPopup,
SelectTrigger,
SelectValue,
} from "~/components/ui/select";
import { updateClientSettings, useClientSettings } from "~/hooks/useSettings";

const LABELS: Record<FileLinkPathDepth, string> = {
1: "File name only",
2: "1 folder + file name",
3: "2 folders + file name",
4: "3 folders + file name",
5: "4 folders + file name",
};

export function FileLinkPathDepthSetting() {
const setting = useSearchableSetting();
const depth = useClientSettings((settings) => settings.fileLinkPathDepth);

return (
<SettingsRow
{...setting("file-link-path-depth")}
description="Folders that file links in messages and Markdown previews show before the file name, on this device. A file name that repeats in a message keeps its folder hint after the name."
resetAction={
depth !== DEFAULT_CLIENT_SETTINGS.fileLinkPathDepth ? (
<SettingResetButton
ariaLabel="Reset file link folders to default"
onClick={() =>
void updateClientSettings({
fileLinkPathDepth: DEFAULT_CLIENT_SETTINGS.fileLinkPathDepth,
})
}
/>
) : null
}
control={
<Select
value={depth}
onValueChange={(value) => {
const next = FileLinkPathDepth.literals.find((literal) => literal === value);
if (next !== undefined) void updateClientSettings({ fileLinkPathDepth: next });
}}
>
<SelectTrigger size="sm" className="w-full sm:w-48" aria-label="File link folders">
<SelectValue>{(value: FileLinkPathDepth) => LABELS[value]}</SelectValue>
</SelectTrigger>
<SelectPopup align="end" alignItemWithTrigger={false}>
{FileLinkPathDepth.literals.map((literal) => (
<SelectItem hideIndicator key={literal} value={literal}>
{LABELS[literal]}
</SelectItem>
))}
</SelectPopup>
</Select>
}
/>
);
}
32 changes: 32 additions & 0 deletions apps/web/src/fork/FileLinkPathPrefix.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useClientSettings } from "../hooks/useSettings";
import { type FileLinkPathMeta, fileLinkPathPrefix } from "./fileLinkPathDepth";

export function useFileLinkPrefix(parentSuffixByPath: ReadonlyMap<string, string>) {
const depth = useClientSettings((settings) => settings.fileLinkPathDepth);
return (meta: FileLinkPathMeta) => fileLinkPathPrefix(meta, parentSuffixByPath, depth);
}

/**
* A file link's label with its folders drawn before the name. The folders are generated
* content, so the label's text, which thread find and copy read, stays the same. In this
* right-to-left box they come after the name, so a narrow chip clips their start first.
*/
export function FileLinkPathLabel({
prefix,
label,
}: {
prefix: string | undefined;
label: string;
}) {
if (prefix === undefined) return label;
// 1.2em is the chip icon and its gap. Inline boxes only: a flex item would end a
// triple-click selection at the chip.
return (
<span
data-file-link-prefix={prefix}
className="inline-block max-w-[calc(100%-1.2em)] overflow-x-clip text-ellipsis whitespace-nowrap align-bottom [direction:rtl] after:text-muted-foreground after:content-[attr(data-file-link-prefix)] after:[direction:ltr] after:[unicode-bidi:isolate]"
>
<span dir="ltr">{label}</span>
</span>
);
}
63 changes: 63 additions & 0 deletions apps/web/src/fork/fileLinkPathDepth.browser.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts";
import { expect, it } from "vite-plus/test";
import { userEvent } from "vite-plus/test/browser";

import "~/index.css";

import { act, render } from "../../test/render";
import ChatMarkdown from "../components/ChatMarkdown";
import { collectThreadFindRanges } from "../components/chat/threadFindHighlights";
import { __setClientSettingsForTests, persistClientSettingsPatch } from "../hooks/useSettings";

const TEXT = [
"See [glossary](docs/review-pipeline/glossary.md#L12), [web](src/web/index.ts), [server](src/server/index.ts) and [readme](README.md).",
"The review is done.",
].join("\n\n");

it("draws the chosen folders before file names, outside the label text", async () => {
__setClientSettingsForTests(DEFAULT_CLIENT_SETTINGS);
using _settings = {
[Symbol.dispose]: () => __setClientSettingsForTests(DEFAULT_CLIENT_SETTINGS),
};
await using screen = await render(
<div data-timeline-row-id="row" data-thread-find-text="true">
<ChatMarkdown cwd="/home/me/project" text={TEXT} />
</div>,
);
const chips = () =>
[...screen.container.querySelectorAll(".chat-markdown-file-link")].map((chip) => {
const prefix = chip.querySelector("[data-file-link-prefix]");
return [prefix && getComputedStyle(prefix, "::after").content, chip.textContent];
});
const labels = ["glossary.md · L12", "index.ts · src/web", "index.ts · src/server", "README.md"];
expect(chips()).toEqual(labels.map((label) => [null, label]));

await act(() => persistClientSettingsPatch({ fileLinkPathDepth: 2 }, async () => {}));

expect(chips()).toEqual([
['"review-pipeline/"', labels[0]],
...labels.slice(1).map((label) => [null, label]),
]);
await expect
.element(
screen.getByRole("button", { name: "File options for review-pipeline/glossary.md · L12" }),
)
.toBeVisible();
const reviews = collectThreadFindRanges(screen.container, "review");
expect(reviews).toHaveLength(1);
expect(
reviews[0]!.range.startContainer.parentElement?.closest(".chat-markdown-file-link"),
).toBeNull();

const paragraph = screen.container.querySelector("p")!;
const see = paragraph.firstChild!;
const range = document.createRange();
range.setStart(see, 0);
range.setEnd(see, 3);
const word = range.getBoundingClientRect();
const box = paragraph.getBoundingClientRect();
await userEvent.tripleClick(paragraph, {
position: { x: word.left - box.left + 4, y: word.top - box.top + word.height / 2 },
});
expect(window.getSelection()?.toString().trim()).toBe(paragraph.textContent?.trim());
});
45 changes: 45 additions & 0 deletions apps/web/src/fork/fileLinkPathDepth.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { FileLinkPathDepth } from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";

import { fileLinkPathPrefix } from "./fileLinkPathDepth";

type Meta = Parameters<typeof fileLinkPathPrefix>[0];

const inWorkspace = (workspaceRelativePath: string): Meta => ({
filePath: `/home/me/project/${workspaceRelativePath}`,
workspaceRelativePath,
});
const outside = (filePath: string): Meta => ({ filePath, workspaceRelativePath: null });
const collisions = new Map([
["/home/me/project/src/web/index.ts", "src/web"],
["C:/repo/src/server/index.ts", "src/server"],
]);

describe("fileLinkPathPrefix", () => {
it.each<[string, Meta, FileLinkPathDepth, string | undefined]>([
["depth 1 shows no folder", inWorkspace("docs/review-pipeline/glossary.md"), 1, undefined],
["depth 2", inWorkspace("docs/review-pipeline/glossary.md"), 2, "review-pipeline/"],
["depth 3", inWorkspace("docs/review-pipeline/glossary.md"), 3, "docs/review-pipeline/"],
["a workspace root file", inWorkspace("README.md"), 3, undefined],
["fewer folders than the depth", inWorkspace("docs/glossary.md"), 5, "docs/"],
[
"an absolute path outside the workspace",
outside("/etc/nginx/sites/app.conf"),
3,
"nginx/sites/",
],
["a POSIX name with a backslash", outside("/tmp/notes/a\\b.md"), 2, undefined],
["a workspace folder named like a drive", inWorkspace("C:/docs/a.md"), 3, "C:/docs/"],
["a slash-prefixed Windows drive path", outside("/C:/Users/me/notes.md"), 3, "Users/me/"],
["a Windows drive path", outside("C:\\Users\\me\\notes.md"), 4, "Users/me/"],
["a UNC path", outside("\\\\server\\share\\docs\\a.md"), 3, "share/docs/"],
["folders after a leading ..", outside("../../shared/lib/util.ts"), 4, "shared/lib/"],
["a .. that names a parent", inWorkspace("docs/guides/../glossary.md"), 2, "docs/"],
["a .. past the folders", outside("/a/../../b/c.md"), 3, "b/"],
["a dot folder", outside("./src/./app.ts"), 3, "src/"],
["a colliding path", inWorkspace("src/web/index.ts"), 3, undefined],
["a colliding Windows path", outside("C:\\repo\\src\\server\\index.ts"), 3, undefined],
])("%s", (_name, meta, depth, expected) => {
expect(fileLinkPathPrefix(meta, collisions, depth)).toBe(expected);
});
});
Loading
Loading