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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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.
- **Folders on file links:** By default, file links in messages and Markdown previews show one folder before the file name, such as `docs/guide.md`. Settings → Appearance → File link folders lets you pick the file name alone or up to four folders. When you show folders, the prefix stops at the thread machine's home folder with `~/` or at filesystem root with `/`, as in `~/notes.md` and `/etc/hosts`. On Windows, when the prefix reaches a drive root, it shows the drive, such as `C:/`. A link written relative to the project without a leading `./` shows only the folders it names, because it may open a matching file in another folder. Each browser and the desktop app keeps its own choice. If a browser or the desktop app already saved its settings, it keeps the saved value. The setting's reset button gives the new default. 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
1 change: 1 addition & 0 deletions apps/server/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,7 @@ export const layerWsRpc = (
auth,
cwd: config.cwd,
hostname: yield* HostProcess.Hostname,
homeDirectory: yield* HostProcess.HomeDirectory,
keybindingsConfigPath: config.keybindingsConfigPath,
keybindings: keybindingsConfig.keybindings,
issues: keybindingsConfig.issues,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ChatMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ function useChatMarkdownState(
const fileLinksKey = `${fileLinkSourcesKey(text, cwd, imageBaseDir, isStreaming ? (streamingBlocks ?? splitMarkdownBlocks(text) ?? [text]) : null, fileLinkPeerPaths, hostFileOrigins)}`;
const { markdownFileLinkMetaByHref, inlineCodeFileLinkMetaByText, fileLinkParentSuffixByPath } =
resolveFileLinkSources(fileLinksKey, cwd, imageBaseDir);
const fileLinkPrefix = useFileLinkPrefix(fileLinkParentSuffixByPath);
const fileLinkPrefix = useFileLinkPrefix(fileLinkParentSuffixByPath, environmentId);
const resolveThreadPullRequest = (
href: string,
): (ThreadPullRequestKey & { readonly url: string }) | null => {
Expand Down
30 changes: 27 additions & 3 deletions apps/web/src/fork/FileLinkPathPrefix.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
import { useAtomValue } from "@effect/atom-react";
import type { EnvironmentId } from "@t3tools/contracts";
import { Atom } from "effect/reactivity";

import { useClientSettings } from "../hooks/useSettings";
import { type FileLinkPathMeta, fileLinkPathPrefix } from "./fileLinkPathDepth";
import { serverEnvironment } from "../state/server";
import { type FileLinkPathMeta, fileLinkPathPrefix, repeatedFileNames } from "./fileLinkPathDepth";

// Only the home string and the OS flag, so other config updates do not re-render every message.
const serverHomeAtom = Atom.family((environmentId: EnvironmentId | null) =>
Atom.make(
(get) => get(serverEnvironment.configValueAtom(environmentId))?.homeDirectory || null,
).pipe(Atom.withLabel(`file-link-server-home:${environmentId}`)),
);
const serverWindowsAtom = Atom.family((environmentId: EnvironmentId | null) =>
Atom.make(
(get) =>
get(serverEnvironment.configValueAtom(environmentId))?.environment.platform.os === "windows",
).pipe(Atom.withLabel(`file-link-server-windows:${environmentId}`)),
);

export function useFileLinkPrefix(parentSuffixByPath: ReadonlyMap<string, string>) {
export function useFileLinkPrefix(
parentSuffixByPath: ReadonlyMap<string, string>,
environmentId: EnvironmentId | null,
) {
const depth = useClientSettings((settings) => settings.fileLinkPathDepth);
return (meta: FileLinkPathMeta) => fileLinkPathPrefix(meta, parentSuffixByPath, depth);
const home = useAtomValue(serverHomeAtom(environmentId));
const windows = useAtomValue(serverWindowsAtom(environmentId));
const view = { depth, home, windows, repeatedNames: repeatedFileNames(parentSuffixByPath) };
return (meta: FileLinkPathMeta) => fileLinkPathPrefix(meta, view);
}

/**
Expand Down
104 changes: 85 additions & 19 deletions apps/web/src/fork/fileLinkPathDepth.browser.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts";
import { expect, it } from "vite-plus/test";
import {
DEFAULT_CLIENT_SETTINGS,
EnvironmentId,
type EditorId,
ThreadId,
} from "@t3tools/contracts";
import { expect, it, vi } from "vite-plus/test";
import { userEvent } from "vite-plus/test/browser";

import "~/index.css";
Expand All @@ -9,34 +14,67 @@ import ChatMarkdown from "../components/ChatMarkdown";
import { collectThreadFindRanges } from "../components/chat/threadFindHighlights";
import { __setClientSettingsForTests, persistClientSettingsPatch } from "../hooks/useSettings";

const SERVER_HOME_ENVIRONMENT = vi.hoisted(() => "server-home");

// One environment reports a home folder that its thread's cwd does not reveal.
vi.mock(import("../state/server"), async (original) => {
const actual = await original();
const { Atom } = await import("effect/reactivity");
const config = Atom.make({
availableEditors: [] as readonly EditorId[],
environment: { platform: { os: "linux" }, capabilities: {} },
homeDirectory: "/srv/me",
});
const configValueAtom = actual.serverEnvironment.configValueAtom;
return {
...actual,
serverEnvironment: {
...actual.serverEnvironment,
configValueAtom: ((environmentId: EnvironmentId | null) =>
environmentId === SERVER_HOME_ENVIRONMENT
? config
: configValueAtom(environmentId)) as never,
},
};
});

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

it("draws the chosen folders before file names, outside the label text", async () => {
function withDefaultSettings(): Disposable {
__setClientSettingsForTests(DEFAULT_CLIENT_SETTINGS);
using _settings = {
[Symbol.dispose]: () => __setClientSettingsForTests(DEFAULT_CLIENT_SETTINGS),
};
return { [Symbol.dispose]: () => __setClientSettingsForTests(DEFAULT_CLIENT_SETTINGS) };
}

function chipPrefixes(container: HTMLElement) {
return [...container.querySelectorAll(".chat-markdown-file-link")].map((chip) => {
const prefix = chip.querySelector("[data-file-link-prefix]");
return [prefix && getComputedStyle(prefix, "::after").content, chip.textContent];
});
}

it("draws the chosen folders before file names, outside the label text", async () => {
using _settings = withDefaultSettings();
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([
const labels = [
"glossary.md · L12",
"index.ts · src/web",
"index.ts · src/server",
"README.md",
"hosts",
];
expect(chipPrefixes(screen.container)).toEqual([
['"review-pipeline/"', labels[0]],
...labels.slice(1).map((label) => [null, label]),
[null, labels[1]],
[null, labels[2]],
[null, labels[3]],
['"/etc/"', labels[4]],
]);
await expect
.element(
Expand All @@ -60,4 +98,32 @@ it("draws the chosen folders before file names, outside the label text", async (
position: { x: word.left - box.left + 4, y: word.top - box.top + word.height / 2 },
});
expect(window.getSelection()?.toString().trim()).toBe(paragraph.textContent?.trim());

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

expect(chipPrefixes(screen.container)).toEqual(labels.map((label) => [null, label]));
});

it("draws ~/ at the home folder the thread's server reports", async () => {
using _settings = withDefaultSettings();
const text = "See [a](/srv/me/notes/a.md) and [b](/srv/other/notes/b.md).";
await using screen = await render(
<>
<ChatMarkdown
cwd="/srv/me/project"
threadRef={{
environmentId: EnvironmentId.make(SERVER_HOME_ENVIRONMENT),
threadId: ThreadId.make("thread"),
}}
text={text}
/>
<ChatMarkdown cwd="/srv/me/project" text={text} />
</>,
);
expect(chipPrefixes(screen.container)).toEqual([
['"~/notes/"', "a.md"],
['"notes/"', "b.md"],
['"notes/"', "a.md"],
['"notes/"', "b.md"],
]);
});
Loading
Loading