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 @@ -18,7 +18,7 @@ This is a fork of T3 Code that integrates a few additional features, including:
- **Compact when idle for Claude threads:** a choice in Settings → Providers → Advanced → Compact idle threads. Besides compacting before the prompt cache expires, it compacts a large idle Claude thread (default 400K tokens or more) a set time (default 15 minutes) after the last message or answer from a user or a bot, so the compaction runs while no one waits for a reply. The token counts and the wait are set right under the choice.
- **Prune idle worker threads:** `t3 prune-worker-threads` deletes the messages, turn items, nodes, plans and runtime requests of idle worker threads. A worker thread is idle when it has no open run and, in the last 7 days, was not created, had no run requested or ended, and had no turn item or message updated. A worker thread is a subagent thread that an agent started. Subagent threads that a bot starts are workers too. Threads a person opens, bot threads themselves and a person's forks are never workers. An idle worker keeps its rows while recovery still needs the worker, or while a thread that keeps its own rows names the worker as parent or fork source. Pruned threads keep their thread row, runs, parent link and pull request links, so they still show up and open with no messages. The command runs only when you call it, so run it daily to keep worker transcripts from piling up. Other threads still grow the database. With `--dry-run`, the command only prints how many threads it would empty and how many rows it would delete. You can run the command while the server runs.
- **One way to start subagents in Claude and Codex threads:** T3 Code starts Claude and Codex sessions without the provider's own subagent tools: Claude's `Agent`, `Workflow`, `SendMessage` and `ListAgents`, and Codex's `spawn_agent` with its other collaboration tools. The agent starts every subagent, same provider and model included, with T3 Code's `delegate_task` tool, so each child is a T3 Code thread that you can open and follow.
- **Files remember where you stopped reading:** a code file or a rendered Markdown file in the file viewer opens where you left it when you switch back to its tab, close and reopen it, or reload the app; so does a PDF in the desktop app. Positions stay in this browser for 30 days. A link to a line still jumps to that line. Large text files, tables and HTML pages still open at the top.
- **Files remember where you stopped reading:** a file in the right panel opens where you left it when you switch back to its tab, close and reopen it, or reload the app. This covers code, Markdown, PDFs, large text files, CSV and TSV tables, HTML pages, Word and PowerPoint files, the first sheet of an Excel or ODS spreadsheet, notebooks, Mermaid diagrams and chat attachments; video and audio come back paused at the time you left. If the file changed, it opens at the same place, or at its start or end when that place is gone. Places stay in this browser for 30 days. A link to a line still jumps to that line once. PDFs in the right panel open in T3 Code's own PDF viewer, also in Chrome and Edge on the desktop. Image zoom, fonts, archives, SQLite files, ODT, ODP, RTF and EPUB files, HTML attachments and the other sheets of a spreadsheet still open at the top. A place in a notebook cell after the first 20 opens at the end of cell 20.
- **Reflink worktrees on Linux:** Settings → Worktrees → Reflink worktrees (on by default) clones new worktrees copy-on-write from a cache of recent checkouts on the worktree location's drive, so worktrees share disk space until files change. Drives that cannot clone, such as ext4, use Git's normal checkout.
- **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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,9 @@ it("toggles a Mermaid attachment between diagram and source through the lazy pre
it("keeps a workspace PDF open across URL renewals and reloads it when the file changes", async () => {
const { WorkspaceBrowserPreview } = await import("./FilePreviewPanel");
using _native = vi.spyOn(navigator, "pdfViewerEnabled", "get").mockReturnValue(true);
using fetches = vi.spyOn(window, "fetch");
const fetched = () =>
fetches.mock.calls.map(([input]) => String(input)).filter((url) => url.startsWith("blob:"));
const original = URL.createObjectURL(new Blob(["%PDF-1.4"], { type: "application/pdf" }));
const edited = URL.createObjectURL(new Blob(["%PDF-1.4 edited"], { type: "application/pdf" }));
const preview = (mutation: string) => (
Expand All @@ -1514,8 +1517,15 @@ it("keeps a workspace PDF open across URL renewals and reloads it when the file
});
try {
await using screen = await render(preview("first"));
const opened = screen.container.querySelector("iframe");
expect(opened?.src.startsWith(original)).toBe(true);
// A right-panel PDF keeps its place, so it opens in PDF.js even where the browser has a viewer.
const viewer = () =>
screen.container.querySelector('[role="region"][aria-label="Planning PDF"]');
// PDF.js loads lazily, which can take longer than waitFor's default on a busy machine.
await vi.waitFor(() => expect(viewer()).not.toBeNull(), { timeout: 10_000 });
const opened = viewer();
expect(screen.container.querySelector("iframe")).toBeNull();
await vi.waitFor(() => expect(fetched().at(-1)?.startsWith(original)).toBe(true));
const loads = fetched().length;

// An agent command renews the signed URL but leaves the file alone.
assetUrlState.mockReturnValue({
Expand All @@ -1526,7 +1536,8 @@ it("keeps a workspace PDF open across URL renewals and reloads it when the file
});
await screen.rerender(preview("second"));
expect(assetUrlState).toHaveBeenLastCalledWith(expect.anything(), expect.anything(), "second");
expect(screen.container.querySelector("iframe")).toBe(opened);
expect(viewer()).toBe(opened);
expect(fetched()).toHaveLength(loads);

assetUrlState.mockReturnValue({
_tag: "Success",
Expand All @@ -1535,9 +1546,9 @@ it("keeps a workspace PDF open across URL renewals and reloads it when the file
fileRevision: "two",
});
await screen.rerender(preview("third"));
const reloaded = screen.container.querySelector("iframe");
expect(reloaded).not.toBe(opened);
expect(reloaded?.src.startsWith(edited)).toBe(true);
await vi.waitFor(() => expect(viewer()).not.toBeNull());
expect(viewer()).not.toBe(opened);
await vi.waitFor(() => expect(fetched().at(-1)?.startsWith(edited)).toBe(true));

// Servers without revisions hold the preview back until a fresh grant arrives.
assetUrlState.mockReturnValue({
Expand All @@ -1547,10 +1558,11 @@ it("keeps a workspace PDF open across URL renewals and reloads it when the file
waiting: true,
});
await screen.rerender(preview("fourth"));
expect(screen.container.querySelector("iframe")).toBeNull();
expect(viewer()).toBeNull();
assetUrlState.mockReturnValue({ _tag: "Success", url: original, expiresAt: 0 });
await screen.rerender(preview("fourth"));
expect(screen.container.querySelector("iframe")?.src.startsWith(original)).toBe(true);
await vi.waitFor(() => expect(viewer()).not.toBeNull());
await vi.waitFor(() => expect(fetched().at(-1)?.startsWith(original)).toBe(true));
} finally {
URL.revokeObjectURL(original);
URL.revokeObjectURL(edited);
Expand Down
39 changes: 26 additions & 13 deletions apps/web/src/components/files/AttachmentFilePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { PreviewImage } from "./PreviewImage";
import { AudioPreview } from "./AudioPreview";
import { BrowserDocumentFrame } from "./BrowserDocumentFrame";
import { DelimitedTablePreview } from "./DelimitedTablePreview";
import type { FileReadingKey } from "./fileReadingStore";
import {
FILE_SURFACE_SUBHEADER_CLASS,
FileSurfaceAction,
Expand Down Expand Up @@ -113,6 +114,10 @@ export function AttachmentFilePreview(props: {
origin?: string;
onRemove?: () => void;
onClose?: () => void;
/** Keeps the PDF reading place across visits. */
readingKey?: FileReadingKey | undefined;
/** The row a table (true) or raw text (false) reveals, which keeps the reader's place. */
rowLine?: ((table: boolean) => number | null) | undefined;
}) {
const kind = filePreviewKind(props);
const officeKind = officePreviewKind(props);
Expand All @@ -134,19 +139,19 @@ export function AttachmentFilePreview(props: {
const { copyToClipboard, isCopied } = useCopyToClipboard({
target: namedClipboardTarget(props.name),
});
// useAssetUrlRefresh keys its callback on these objects, so they must stay cached.
// useAssetUrlRefresh keys its callback on these objects, so they must stay cached. A parent may
// rebuild `asset` on any render, so the attachment's own resource depends only on its fields.
const attachmentResource = attachmentId
? {
_tag: "attachment" as const,
attachmentId,
fileName: props.name,
mimeType: props.mimeType,
disposition: "inline" as const,
}
: null;
const resource =
props.asset && "resource" in props.asset
? props.asset.resource
: attachmentId
? {
_tag: "attachment" as const,
attachmentId,
fileName: props.name,
mimeType: props.mimeType,
disposition: "inline" as const,
}
: null;
props.asset && "resource" in props.asset ? props.asset.resource : attachmentResource;
const downloadResource = resource
? resource._tag === "draft-workspace-file"
? resource
Expand Down Expand Up @@ -303,13 +308,19 @@ export function AttachmentFilePreview(props: {
delimiter={rendered ? delimiter : null}
copyContents={copyContents}
wordWrap={wordWrap}
revealLine={props.rowLine?.(rendered && delimiter !== null) ?? null}
/>
</Suspense>
) : !url || (needsText && !content) ? (
<FileSurfaceLoading />
) : needsText && content ? (
delimiter && rendered ? (
<DelimitedTablePreview name={props.name} text={content.text} delimiter={delimiter} />
<DelimitedTablePreview
name={props.name}
text={content.text}
delimiter={delimiter}
revealLine={props.rowLine?.(true) ?? null}
/>
) : kind === "mermaid" && rendered ? (
<Suspense fallback={<FileSurfaceLoading />}>
<MermaidFilePreview text={content.text} />
Expand Down Expand Up @@ -344,6 +355,7 @@ export function AttachmentFilePreview(props: {
name={props.name}
kind={officeKind}
sizeBytes={props.sizeBytes}
revealLine={props.rowLine?.(true) ?? null}
/>
</Suspense>
) : kind === "pdf" || kind === "html" ? (
Expand All @@ -353,6 +365,7 @@ export function AttachmentFilePreview(props: {
pdf={kind === "pdf"}
htmlRender={props.htmlRender === true}
threadRef={props.threadRef}
readingKey={kind === "pdf" ? props.readingKey : undefined}
// Each mount signs or creates a new URL, so the URL cannot identify the file across visits.
// A draft keeps its Blob key after upload, so finishing the upload does not reload the PDF.
documentKey={
Expand Down
Loading
Loading