- {props.triggerKind === "skill" ? (
+ {props.triggerKind === "skill" || props.triggerKind === "thread" ? (
- Skills
+ {props.triggerKind === "thread" ? "Threads" : "Skills"}
{props.isLoading
- ? "Searching workspace skills..."
+ ? props.triggerKind === "thread"
+ ? "Searching threads..."
+ : "Searching workspace skills..."
: (props.emptyStateText ??
- "No skills found. Try / to browse provider commands.")}
+ (props.triggerKind === "thread"
+ ? "No matching threads."
+ : "No skills found. Try / to browse provider commands."))}
) : (
@@ -247,6 +265,9 @@ const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: {
) : null}
+ {props.item.type === "thread" ? (
+
+ ) : null}
{props.item.label}
diff --git a/apps/web/src/composer-editor-mentions.test.ts b/apps/web/src/composer-editor-mentions.test.ts
index d79170769d..206558a041 100644
--- a/apps/web/src/composer-editor-mentions.test.ts
+++ b/apps/web/src/composer-editor-mentions.test.ts
@@ -71,6 +71,24 @@ describe("splitPromptIntoComposerSegments", () => {
).toEqual([{ type: "text", text: "Read [the docs](https://example.com/docs) first" }]);
});
+ it("splits T3 thread links into thread segments", () => {
+ expect(
+ splitPromptIntoComposerSegments(
+ "Continue from [Prior chat](t3-thread:///environment-1/thread-2) please",
+ ),
+ ).toEqual([
+ { type: "text", text: "Continue from " },
+ {
+ type: "thread",
+ environmentId: "environment-1",
+ threadId: "thread-2",
+ title: "Prior chat",
+ source: "[Prior chat](t3-thread:///environment-1/thread-2)",
+ },
+ { type: "text", text: " please" },
+ ]);
+ });
+
it("decodes reserved path characters from generated links", () => {
expect(
splitPromptIntoComposerSegments(
diff --git a/apps/web/src/composer-editor-mentions.ts b/apps/web/src/composer-editor-mentions.ts
index 8b9a53808f..78fed07196 100644
--- a/apps/web/src/composer-editor-mentions.ts
+++ b/apps/web/src/composer-editor-mentions.ts
@@ -21,6 +21,13 @@ export type ComposerPromptSegment =
type: "skill";
name: string;
}
+ | {
+ type: "thread";
+ environmentId: string;
+ threadId: string;
+ title: string;
+ source: string;
+ }
| {
type: "terminal-context";
context: TerminalContextDraft | null;
@@ -147,6 +154,14 @@ function splitPromptTextIntoComposerSegments(text: string): ComposerPromptSegmen
path: match.value,
source: match.source,
});
+ } else if (match.type === "thread") {
+ segments.push({
+ type: "thread",
+ environmentId: match.environmentId,
+ threadId: match.threadId,
+ title: match.title,
+ source: match.source,
+ });
} else {
segments.push({ type: "skill", name: match.value });
}
diff --git a/apps/web/src/composer-logic.test.ts b/apps/web/src/composer-logic.test.ts
index 99ac6bba71..bb71dec343 100644
--- a/apps/web/src/composer-logic.test.ts
+++ b/apps/web/src/composer-logic.test.ts
@@ -106,6 +106,17 @@ describe("detectComposerTrigger", () => {
});
});
+ it("detects #thread trigger at cursor", () => {
+ const text = "Continue from #auth";
+
+ expect(detectComposerTrigger(text, text.length)).toEqual({
+ kind: "thread",
+ query: "auth",
+ rangeStart: "Continue from ".length,
+ rangeEnd: text.length,
+ });
+ });
+
it("detects @path trigger in the middle of existing text", () => {
// User typed @ between "inspect " and "in this sentence"
const text = "Please inspect @in this sentence";
diff --git a/apps/web/src/composer-logic.ts b/apps/web/src/composer-logic.ts
index 2d1d3aed3b..ee453f2e59 100644
--- a/apps/web/src/composer-logic.ts
+++ b/apps/web/src/composer-logic.ts
@@ -1,7 +1,7 @@
import { splitPromptIntoComposerSegments } from "./composer-editor-mentions";
import { INLINE_TERMINAL_CONTEXT_PLACEHOLDER } from "./lib/terminalContext";
-export type ComposerTriggerKind = "path" | "slash-command" | "skill";
+export type ComposerTriggerKind = "path" | "slash-command" | "skill" | "thread";
export type ComposerSlashCommand = "model" | "plan" | "default";
export interface ComposerTrigger {
@@ -22,6 +22,7 @@ const isInlineTokenSegment = (
segment:
| { type: "text"; text: string }
| { type: "mention" }
+ | { type: "thread" }
| { type: "skill" }
| { type: "terminal-context" },
): boolean => segment.type !== "text";
@@ -60,7 +61,7 @@ export function expandCollapsedComposerCursor(text: string, cursorInput: number)
let expandedCursor = 0;
for (const segment of segments) {
- if (segment.type === "mention") {
+ if (segment.type === "mention" || segment.type === "thread") {
const expandedLength = segment.source.length;
if (remaining <= 1) {
return expandedCursor + (remaining === 0 ? 0 : expandedLength);
@@ -102,6 +103,7 @@ function collapsedSegmentLength(
segment:
| { type: "text"; text: string }
| { type: "mention" }
+ | { type: "thread" }
| { type: "skill" }
| { type: "terminal-context" },
): number {
@@ -115,6 +117,7 @@ function clampCollapsedComposerCursorForSegments(
segments: ReadonlyArray<
| { type: "text"; text: string }
| { type: "mention" }
+ | { type: "thread" }
| { type: "skill" }
| { type: "terminal-context" }
>,
@@ -148,7 +151,7 @@ export function collapseExpandedComposerCursor(text: string, cursorInput: number
let collapsedCursor = 0;
for (const segment of segments) {
- if (segment.type === "mention") {
+ if (segment.type === "mention" || segment.type === "thread") {
const expandedLength = segment.source.length;
if (remaining === 0) {
return collapsedCursor;
@@ -250,6 +253,14 @@ export function detectComposerTrigger(text: string, cursorInput: number): Compos
rangeEnd: cursor,
};
}
+ if (token.startsWith("#")) {
+ return {
+ kind: "thread",
+ query: token.slice(1),
+ rangeStart: tokenStart,
+ rangeEnd: cursor,
+ };
+ }
if (!token.startsWith("@")) {
return null;
}
diff --git a/apps/web/src/threadReferenceSearch.test.ts b/apps/web/src/threadReferenceSearch.test.ts
new file mode 100644
index 0000000000..23904b9756
--- /dev/null
+++ b/apps/web/src/threadReferenceSearch.test.ts
@@ -0,0 +1,32 @@
+import { describe, expect, it } from "vite-plus/test";
+
+import { searchThreadReferences } from "./threadReferenceSearch";
+
+const thread = (id: string, title: string, updatedAt: string, branch: string | null = null) =>
+ ({ id, title, updatedAt, branch }) as never;
+
+describe("searchThreadReferences", () => {
+ it("shows recently updated threads when the query is empty", () => {
+ const result = searchThreadReferences(
+ [
+ thread("one", "Older", "2026-01-01T00:00:00.000Z"),
+ thread("two", "Newer", "2026-02-01T00:00:00.000Z"),
+ ],
+ "",
+ );
+
+ expect(result.map(({ id }) => id)).toEqual(["two", "one"]);
+ });
+
+ it("ranks title, branch, and id matches", () => {
+ const threads = [
+ thread("thread-auth", "Authentication follow-up", "2026-01-01T00:00:00.000Z"),
+ thread("thread-two", "Unrelated", "2026-01-02T00:00:00.000Z", "feat/auth-flow"),
+ ];
+
+ expect(searchThreadReferences(threads, "auth").map(({ id }) => id)).toEqual([
+ "thread-auth",
+ "thread-two",
+ ]);
+ });
+});
diff --git a/apps/web/src/threadReferenceSearch.ts b/apps/web/src/threadReferenceSearch.ts
new file mode 100644
index 0000000000..a14db019da
--- /dev/null
+++ b/apps/web/src/threadReferenceSearch.ts
@@ -0,0 +1,53 @@
+import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
+import {
+ compareRankedSearchResults,
+ normalizeSearchQuery,
+ scoreQueryMatch,
+ type RankedSearchResult,
+} from "@t3tools/shared/searchRanking";
+
+const DEFAULT_THREAD_REFERENCE_LIMIT = 20;
+
+function scoreThread(thread: EnvironmentThreadShell, query: string): number | null {
+ const fields = [thread.title, thread.branch ?? "", thread.id];
+ let best: number | null = null;
+ for (const field of fields) {
+ const score = scoreQueryMatch({
+ value: field.toLowerCase(),
+ query,
+ exactBase: 0,
+ prefixBase: 10,
+ boundaryBase: 30,
+ includesBase: 50,
+ fuzzyBase: 100,
+ });
+ if (score !== null && (best === null || score < best)) {
+ best = score;
+ }
+ }
+ return best;
+}
+
+export function searchThreadReferences(
+ threads: ReadonlyArray,
+ queryInput: string,
+ limit = DEFAULT_THREAD_REFERENCE_LIMIT,
+): EnvironmentThreadShell[] {
+ const query = normalizeSearchQuery(queryInput, { trimLeadingPattern: /^#/ });
+ if (!query) {
+ return threads
+ .toSorted((left, right) => right.updatedAt.localeCompare(left.updatedAt))
+ .slice(0, limit);
+ }
+
+ const ranked: RankedSearchResult[] = [];
+ for (const thread of threads) {
+ const score = scoreThread(thread, query);
+ if (score === null) continue;
+ ranked.push({ item: thread, score, tieBreaker: `${thread.title}:${thread.id}` });
+ }
+ return ranked
+ .sort(compareRankedSearchResults)
+ .slice(0, limit)
+ .map(({ item }) => item);
+}
diff --git a/packages/contracts/src/index.ts b/packages/contracts/src/index.ts
index 43270efdec..4a86bab27c 100644
--- a/packages/contracts/src/index.ts
+++ b/packages/contracts/src/index.ts
@@ -25,4 +25,5 @@ export * from "./assets.ts";
export * from "./review.ts";
export * from "./preview.ts";
export * from "./previewAutomation.ts";
+export * from "./threadReference.ts";
export * from "./rpc.ts";
diff --git a/packages/contracts/src/threadReference.ts b/packages/contracts/src/threadReference.ts
new file mode 100644
index 0000000000..3658e0027d
--- /dev/null
+++ b/packages/contracts/src/threadReference.ts
@@ -0,0 +1,94 @@
+import * as Schema from "effect/Schema";
+
+import { ChatAttachment, OrchestrationMessageRole } from "./orchestration.ts";
+import {
+ IsoDateTime,
+ MessageId,
+ NonNegativeInt,
+ ProjectId,
+ ThreadId,
+ TrimmedNonEmptyString,
+} from "./baseSchemas.ts";
+
+export const THREAD_REFERENCE_DEFAULT_MAX_CHARS = 40_000;
+export const THREAD_REFERENCE_MAX_CHARS = 80_000;
+
+export const ThreadReferenceCursor = Schema.String.check(
+ Schema.isPattern(/^\d+:\d+$/, {
+ description: "Opaque transcript cursor returned by a previous thread_read call.",
+ }),
+);
+export type ThreadReferenceCursor = typeof ThreadReferenceCursor.Type;
+
+export const ThreadReferenceReadInput = Schema.Struct({
+ threadId: ThreadId.annotate({
+ description: "Thread id from a t3-thread reference in the user's message.",
+ }),
+ cursor: Schema.optional(ThreadReferenceCursor).annotate({
+ description: "nextCursor from the previous page. Omit for the first page.",
+ }),
+ maxChars: Schema.optional(
+ Schema.Int.check(Schema.isGreaterThanOrEqualTo(1_000))
+ .check(Schema.isLessThanOrEqualTo(THREAD_REFERENCE_MAX_CHARS))
+ .annotate({
+ description: `Maximum message-text characters to return. Defaults to ${THREAD_REFERENCE_DEFAULT_MAX_CHARS}; maximum ${THREAD_REFERENCE_MAX_CHARS}.`,
+ }),
+ ),
+});
+export type ThreadReferenceReadInput = typeof ThreadReferenceReadInput.Type;
+
+export const ThreadReferenceTranscriptMessage = Schema.Struct({
+ id: MessageId,
+ role: OrchestrationMessageRole,
+ text: Schema.String,
+ textStart: NonNegativeInt,
+ textEnd: NonNegativeInt,
+ textComplete: Schema.Boolean,
+ attachments: Schema.Array(ChatAttachment),
+ createdAt: IsoDateTime,
+});
+export type ThreadReferenceTranscriptMessage = typeof ThreadReferenceTranscriptMessage.Type;
+
+export const ThreadReferenceReadResult = Schema.Struct({
+ threadId: ThreadId,
+ projectId: ProjectId,
+ title: TrimmedNonEmptyString,
+ messages: Schema.Array(ThreadReferenceTranscriptMessage),
+ totalMessages: NonNegativeInt,
+ nextCursor: Schema.NullOr(ThreadReferenceCursor),
+});
+export type ThreadReferenceReadResult = typeof ThreadReferenceReadResult.Type;
+
+export class ThreadReferenceNotFoundError extends Schema.TaggedErrorClass()(
+ "ThreadReferenceNotFoundError",
+ { threadId: ThreadId },
+) {
+ override get message(): string {
+ return `Referenced thread '${this.threadId}' was not found.`;
+ }
+}
+
+export class ThreadReferenceInvalidCursorError extends Schema.TaggedErrorClass()(
+ "ThreadReferenceInvalidCursorError",
+ { threadId: ThreadId, cursor: Schema.String },
+) {
+ override get message(): string {
+ return `Cursor '${this.cursor}' is invalid for referenced thread '${this.threadId}'.`;
+ }
+}
+
+export class ThreadReferenceUnavailableError extends Schema.TaggedErrorClass()(
+ "ThreadReferenceUnavailableError",
+ { threadId: ThreadId },
+) {
+ override get message(): string {
+ return `Referenced thread '${this.threadId}' could not be read.`;
+ }
+}
+
+export const ThreadReferenceReadError = Schema.Union([
+ ThreadReferenceNotFoundError,
+ ThreadReferenceInvalidCursorError,
+ ThreadReferenceUnavailableError,
+]);
+export type ThreadReferenceReadError = typeof ThreadReferenceReadError.Type;
diff --git a/packages/shared/src/composerInlineTokens.test.ts b/packages/shared/src/composerInlineTokens.test.ts
index f99d0b6654..e6804a132d 100644
--- a/packages/shared/src/composerInlineTokens.test.ts
+++ b/packages/shared/src/composerInlineTokens.test.ts
@@ -3,8 +3,9 @@ import { describe, expect, it } from "vite-plus/test";
import { collectComposerInlineTokens } from "./composerInlineTokens.ts";
describe("collectComposerInlineTokens", () => {
- it("collects file links, mentions, and skills with source ranges", () => {
- const text = "Use $ui and inspect [Chat.tsx](src/Chat.tsx) with @AGENTS.md please";
+ it("collects file links, mentions, skills, and thread references with source ranges", () => {
+ const text =
+ "Use $ui and inspect [Chat.tsx](src/Chat.tsx) with @AGENTS.md then [Prior chat](t3-thread:///env-1/thread-2) please";
expect(collectComposerInlineTokens(text)).toEqual([
{
@@ -28,6 +29,16 @@ describe("collectComposerInlineTokens", () => {
start: 50,
end: 60,
},
+ {
+ type: "thread",
+ environmentId: "env-1",
+ threadId: "thread-2",
+ title: "Prior chat",
+ value: "Prior chat",
+ source: "[Prior chat](t3-thread:///env-1/thread-2)",
+ start: 66,
+ end: 107,
+ },
]);
});
@@ -81,4 +92,8 @@ describe("collectComposerInlineTokens", () => {
it("ignores normal web links", () => {
expect(collectComposerInlineTokens("Read [docs](https://example.com) first")).toEqual([]);
});
+
+ it("ignores malformed thread links", () => {
+ expect(collectComposerInlineTokens("Read [chat](t3-thread:///missing) first")).toEqual([]);
+ });
});
diff --git a/packages/shared/src/composerInlineTokens.ts b/packages/shared/src/composerInlineTokens.ts
index aa5e67d6fc..7cd180c414 100644
--- a/packages/shared/src/composerInlineTokens.ts
+++ b/packages/shared/src/composerInlineTokens.ts
@@ -1,3 +1,5 @@
+import { parseComposerThreadLink } from "./composerTrigger.ts";
+
export type ComposerInlineToken =
| {
readonly type: "mention";
@@ -12,6 +14,16 @@ export type ComposerInlineToken =
readonly source: string;
readonly start: number;
readonly end: number;
+ }
+ | {
+ readonly type: "thread";
+ readonly environmentId: string;
+ readonly threadId: string;
+ readonly title: string;
+ readonly value: string;
+ readonly source: string;
+ readonly start: number;
+ readonly end: number;
};
export interface CollectComposerInlineTokensOptions {
@@ -21,9 +33,38 @@ export interface CollectComposerInlineTokensOptions {
const SKILL_TOKEN_REGEX = /(^|\s)\$([a-zA-Z][a-zA-Z0-9:_-]*)(?=\s)/g;
const MENTION_TOKEN_REGEX = /(^|\s)@(?:"((?:\\.|[^"\\])*)"|([^\s@"]+))(?=\s)/g;
const FILE_LINK_TOKEN_REGEX = /(^|\s)\[((?:\\.|[^\]\\])*)\]\(([^)\s]+)\)(?=\s)/g;
+const THREAD_LINK_TOKEN_REGEX = /(^|\s)\[((?:\\.|[^\]\\])*)\]\((t3-thread:\/\/\/[^)\s]+)\)(?=\s)/g;
const URI_SCHEME_REGEX = /^[A-Za-z][A-Za-z0-9+.-]*:/;
const WINDOWS_DRIVE_PATH_REGEX = /^[A-Za-z]:[\\/]/;
+function collectThreadTokens(text: string): ComposerInlineToken[] {
+ const matches: ComposerInlineToken[] = [];
+
+ for (const match of text.matchAll(THREAD_LINK_TOKEN_REGEX)) {
+ const fullMatch = match[0];
+ const prefix = match[1] ?? "";
+ const title = (match[2] ?? "").replace(/\\(.)/g, "$1");
+ const destination = match[3] ?? "";
+ const reference = parseComposerThreadLink(destination);
+ if (reference && title) {
+ const start = (match.index ?? 0) + prefix.length;
+ const end = start + fullMatch.length - prefix.length;
+ matches.push({
+ type: "thread",
+ environmentId: reference.environmentId,
+ threadId: reference.threadId,
+ title,
+ value: title,
+ source: text.slice(start, end),
+ start,
+ end,
+ });
+ }
+ }
+
+ return matches;
+}
+
function collectMentionTokens(text: string): ComposerInlineToken[] {
const matches: ComposerInlineToken[] = [];
@@ -81,7 +122,7 @@ export function collectComposerInlineTokens(
text: string,
options: CollectComposerInlineTokensOptions = {},
): ReadonlyArray {
- const matches = collectMentionTokens(text);
+ const matches = [...collectMentionTokens(text), ...collectThreadTokens(text)];
for (const match of text.matchAll(SKILL_TOKEN_REGEX)) {
const fullMatch = match[0];
diff --git a/packages/shared/src/composerTrigger.ts b/packages/shared/src/composerTrigger.ts
index dcbdc78493..fe9f6ef1b3 100644
--- a/packages/shared/src/composerTrigger.ts
+++ b/packages/shared/src/composerTrigger.ts
@@ -1,4 +1,4 @@
-export type ComposerTriggerKind = "path" | "slash-command" | "slash-model" | "skill";
+export type ComposerTriggerKind = "path" | "slash-command" | "slash-model" | "skill" | "thread";
export type ComposerSlashCommand = "model" | "plan" | "default";
export interface ComposerTrigger {
@@ -35,6 +35,42 @@ function encodeMarkdownLinkDestination(path: string): string {
.replaceAll("\\", "%5C");
}
+export interface ComposerThreadReference {
+ readonly environmentId: string;
+ readonly threadId: string;
+ readonly title: string;
+}
+
+export const COMPOSER_THREAD_REFERENCE_SCHEME = "t3-thread:";
+
+export function parseComposerThreadLink(
+ destination: string,
+): Pick | null {
+ try {
+ const url = new URL(destination);
+ const segments = url.pathname.split("/").filter(Boolean).map(decodeURIComponent);
+ const [environmentId, threadId] = segments;
+ if (
+ url.protocol !== COMPOSER_THREAD_REFERENCE_SCHEME ||
+ !environmentId ||
+ !threadId ||
+ segments.length !== 2
+ ) {
+ return null;
+ }
+ return { environmentId, threadId };
+ } catch {
+ return null;
+ }
+}
+
+export function serializeComposerThreadLink(reference: ComposerThreadReference): string {
+ const label = escapeMarkdownLinkLabel(reference.title);
+ const environmentId = encodeURIComponent(reference.environmentId);
+ const threadId = encodeURIComponent(reference.threadId);
+ return `[${label}](${COMPOSER_THREAD_REFERENCE_SCHEME}///${environmentId}/${threadId})`;
+}
+
export function serializeComposerFileLink(path: string): string {
const label = escapeMarkdownLinkLabel(composerFileLinkBasename(path));
return `[${label}](${encodeMarkdownLinkDestination(path)})`;
@@ -112,6 +148,14 @@ export function detectComposerTrigger(
rangeEnd: cursor,
};
}
+ if (token.startsWith("#")) {
+ return {
+ kind: "thread",
+ query: token.slice(1),
+ rangeStart: tokenStart,
+ rangeEnd: cursor,
+ };
+ }
if (!token.startsWith("@")) {
return null;
}